4
\$\begingroup\$

I have a bootloader residing at locations 0x0000 to 0x0fff on an 8-bit PIC18F. How do I tell the XC8 compiler to output a hex file which starts at 0x1000?

With a CCS compiler my friend is using, he's using the following code:

#define LOADER_SIZE                 (0xFFF)
#define LOADER_START                (0) 
#define LOADER_END                  (LOADER_SIZE) 
#define APPLICATION_START           (LOADER_SIZE+1) 
#define APPLICATION_END             (getenv("PROGRAM_MEMORY")-1) 
#define APPLICATION_ISR             (APPLICATION_START+8) 

#ifdef _BOOTLOADER
    //in the application, this moves the reset and isr vector out of the bootload 
    //space.  it then reserves the loader space from being used by the application. 
    #build(reset=APPLICATION_START, interrupt=APPLICATION_ISR) 
    #org 0, LOADER_END {} 
#endif

Digging around the Microchip Libraries for Applications (MLA), I found this for the C18 compiler, however the XC8 compiler does not recognise "#pragma code".

#define REMAPPED_RESET_VECTOR_ADDRESS               0x1000
#define REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS  0x1008
#define REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS   0x1018

extern void _startup (void);        // See c018i.c in your C18 compiler dir
#pragma code REMAPPED_RESET_VECTOR = REMAPPED_RESET_VECTOR_ADDRESS
void _reset (void) {
    _asm goto _startup _endasm
}
#pragma code REMAPPED_HIGH_INTERRUPT_VECTOR = REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS
void Remapped_High_ISR (void) {
     _asm goto YourHighPriorityISRCode _endasm
}
#pragma code REMAPPED_LOW_INTERRUPT_VECTOR = REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS
void Remapped_Low_ISR (void) {
     _asm goto YourLowPriorityISRCode _endasm
}
#pragma code HIGH_INTERRUPT_VECTOR = 0x08
void High_ISR (void) {
     _asm goto REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS _endasm
}
#pragma code LOW_INTERRUPT_VECTOR = 0x18
void Low_ISR (void) {
     _asm goto REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS _endasm
}
\$\endgroup\$
7
\$\begingroup\$

A quick search led me to this Microchip forum discussion where the solution appears to be specifying --CODEOFFSET as one of the linker arguments.

The forum also has a link to a webinar on the same topic.

Command line:

You can pass the offset when compiling with the command line by passing --codeoffset=<location> during linking (i.e. --codeoffset=0x1000).

MPLABX IDE

Specify the code offset by accessing project properties -> XC8 global options -> XC8 linker, changing the Option categories: to Additional options, and entering the offset in the Codeoffset field:

enter image description here

\$\endgroup\$
  • 1
    \$\begingroup\$ Inspecting the HEX file after using the --CODEOFFSET 0x1000 parameter shows it correctly starting at 0x1000. Thanks! \$\endgroup\$ – Daniel Dec 10 '12 at 14:47
  • \$\begingroup\$ Brilliant! This really helped me to understand how this was configured: github.com/luciodj/BlueBoot/issues/1 \$\endgroup\$ – Robert Massaioli Jan 8 '17 at 22:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.