Menu

18Fcompatibility with Tinybld bootloader

Help
2009-09-08
2013-05-30
  • Nobody/Anonymous

    I've been using GCBasic quite successfully with 16F parts in combination with the Tinybld bootloader. Recently, I needed to re-compile my application to run on a 18F4455. After this change, the bootloader no longer works properly. If gives me an error message saying the first 4 bytes must contain a jump instruction.

    When I look at the assembly code generated by GCB for the 16F parts, the program does indeed start with  "goto BASPROGRAMSTART", but when I look at the generated code for the 18F part it begins with "bra BASPROGRAMSTART". The branch instruction apparently causes Tinybld to choke.

    Is there a simple mod I can make to to the compiler source so it will use a goto instruction instead of a bra instruction??

    Joe

     
    • Nobody/Anonymous

      more on this....

      I modified the .asm assembler file to change the "bra" instruction to a "goto" instruction, and the bootloader now works, so that IS the problem. What's puzzling me now is that I searched the "GCBasic.bas" compiler source and I can't find any instances of it using the "bra" instruction when setting up the start vector; the compiler source seems to use "goto" instructions, so I'm stumped about how the "bra"'s are getting put in.

       
    • Nobody/Anonymous

      I think I successfully modified the compiler code to eliminate this incompatibility with Tinybld bootloader. It appears that the compiler makes a second pass on the compiled code and modifies it to change some absolute jump instructions into relative branch instructions. This only happens if certain conditions are met, and I don't understand it exactly - maybe Hugh can explain.

      Anyway, my modification prevents the "goto BASPROGRAM" instruction at the beginning of the compiled code from being changed into "bra BASPROGRAMSTART", which chokes Tinybld bootloader. Here's the section of GCBasic source code I changed to accomplish this:

      'If using relative when shouldn't or not when should, change line
                  If IsRelative <> UseRelative Then
                      If ModeAVR Then
                          If UseRelative Then
                              ProperCmd = " r"
                          Else
                              ProperCmd = " "
                          End If
                          If IsJump = 1 Then
                              ProperCmd += "call "
                          Else
                              ProperCmd += "jmp "
                          End If
                     
                      ElseIf ChipFamily = 16 Then
                          If UseRelative Then
                              If IsJump = 1 Then
                                  ProperCmd = " rcall "
                              Else 'Here is where we force a "goto" BASPROGRAMSTART
                                  If JumpTarget <> "BASPROGRAMSTART" Then
                                      ProperCmd = " bra "
                                  Else
                                      ProperCmd = " goto "   
                                  End If                           
                              End If
                          Else
                              If IsJump = 1 Then
                                  ProperCmd = " call "
                              Else
                                  ProperCmd = " goto "
                              End If
                          End If
                      End If
                      CurrLine->Value = ProperCmd + JumpTarget
                  End If

       
    • joe rocci

      joe rocci - 2009-09-09

      typo correction on above.........

      "Anyway, my modification prevents the "goto BASPROGRAMSTART" instruction at the beginning of the compiled code from being changed into "bra BASPROGRAMSTART"...."

      Note that this mod only affects PIC18xxx parts. tinybld seems to work fine with PIC16xxx parts.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.