View previous topic :: View next topic |
Author |
Message |
Josh_AB
Joined: 15 Jan 2004 Posts: 2
|
Placing code at location 0 |
Posted: Wed Feb 25, 2004 6:07 pm |
|
|
I'm working with an 18F6520 and it has a protected bootblock from 0x0000 to 0x0800 so I'm working at placing a boot loader in this region. I know this has been discussed repeatedly but so far I haven't seen this problem addressed. While I'm able to relocate the reset vector using the #build directive any code I try to put in it's place by #org 0x0000, 0x0007 does not generate code.
Here is simplified example code:
Code: |
#include <18F6520.h>
#build(reset=0x0800)
#org 0x0000, 0x0007 //RESET VECTOR---GOES TO BOOTLOADER
void MY_RESET(void)
{
#asm
goto 0x0018 //BOOTLOADER LOCATION
#endasm
}
#org 0x0018,0x07FF
void MY_BOOTLOADER(void)
{
#asm
goto 0x0800 //BOOTLOADER--STUB--FOR NOW ASSUME ALL
//IS GOOD AND JUST GO TO RELOCATED
//RESET VECTOR
#endasm
}
void main()
{
int i;
while(1)i++;
} |
Complied as above no code is generated for MY_RESET but all other functions generate code as expected. My compiler is version PCH 3.182.
If I change the code so that MY_RESET is org'ed to the range 0x0002 to 0x0007 it will generate code for the function but leaves address 0x0000 free. By default it places a nop there which would be fine except when I'm actually working on the project any function stub ends up being placed there so it then becomes a retlw 0 (very bad!).
Any help would be greatly appreciated. Thanks for your time.
Josh |
|
|
Paul Routlley Guest
|
Need a redundant call to generate code |
Posted: Mon Sep 13, 2004 9:11 am |
|
|
I had a similar problem.
Try adding a call to MY_RESET() and MT_BOOTLOADER() at the end of main
(The code does not have to be reachable).
Without this the optimiser removes the code it thinks is unused! |
|
|
Josh_AB
Joined: 15 Jan 2004 Posts: 2
|
|
Posted: Mon Sep 13, 2004 11:28 am |
|
|
Thanks for the suggestion but it doesn't seem to fix my problem (given my version of the compiler etc.) With or without the calls it works if I place the code at adress 2 and it fails(silently of course) if I place it at address 0.
Josh |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 13, 2004 12:25 pm |
|
|
In my notes on this topic, I have the following code.
It just shows how we worked around the problem.
Code: | // We can't org our reset_vector() function at 0x0000.
// So we org it at 0x0002 instead, and put a NOP at 0.
#org 0,1 {} // Reserve ROM word 0
#ROM 0 = {0} // Then put a NOP there
#org 2, NEW_RESET_VECTOR-1 // Reserve the entire 512-byte boot block
void reset_vector(void)
{
#asm
GOTO BOOT_SEGMENT_START // This code is at address 0x0002
NOP // The nop forces next line to be at 0x0008
GOTO NEW_INTERRUPT_VECTOR // This code is at address 0x0008
#endasm
} |
|
|
|
|