This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

PIC startup code, making a section for relative addresses

I need to write a bootloader that can execute multiple images stored in Flash. Without wanting to recompile for every possible image address, I'd like to get PIC images working. The only issue is that startup file won't compile because of its heavy use of absolute addresses. Dealing with the vector table and handlers is trivial and I already have code for the bootloader to move everything into a predetermined spot in RAM, however, the labels (SystemInit, __main etc.) used in the startup file won't compile into relative addresses.

Here are my two strategies:

Compile the images without a startup just ensuring that the bootloader does what it needs to and jump to the images __main. This fails because the image tries to recreate a stack pointer which ultimately ends up with it accessing invalid memory - I wasn't super diligent stepping through so I may be wrong as to where/why it failed. Without the C code for rt_entry (is there C Code?) and related functions, creating my own sounds like a waste of time that could very easily only work in certain cases - like super simple POC code vs the full project.

Or I could carve out a place in the images binary to drop relative addresses of SystemInit, __main etc and construct global addresses from a passed in starting address via the bootloader. This seems pretty workable but I don't know how to tell the Keil Linker to create those relative addresses and put them say at the beginning of the binary.

Thanks for the help, and apologies for the rambling.