Electronic – How to offset program location in memory with MPLABX XC8

bootloadermicrochippicprogrammingxc8

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
}

Best Answer

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