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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
"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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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.
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
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.