Forums

Bootloader - Vector Table redirection

Started by smileyakfg July 25, 2005
Hi,

I am building a Bootloader on a 9S12.

Since I want to enable the protection on the device, I would like to
do a redirection of the vector table.

I modified the following file generated by PE:

---------------------------------
vector.c:

typedef void (*near tIsrFunc)(void);
const tIsrFunc _vect[] @0xFF80 = { /* Interrupt table */
Cpu_Interrupt0, /* 0 Default (unused)
interrupt, address 0xFF80 */
... // SAME FOR ALL VECTORS BUT INCREMENTING COUNTER

---------------------------------

CPU.h
__interrupt void Cpu_Interrupt0(void);
... // SAME FOR ALL VECTORS BUT INCREMENTING COUNTER

---------------------------------

CPU.c
ISR(Cpu_Interrupt0)
{
JUMP_TO_USER_VECTOR_TABLE0
}
... // SAME FOR ALL VECTORS BUT INCREMENTING COUNTER

--------------------------------- I tried to define the following macro: JUMP_TO_USER_VECTOR_TABLE0

Attemp 1: #define JUMP_TO_USER_VECTOR_TABLE0 __asm PULX; __asm
LDX $5000; __asm JMP 0, X;

Attemp 2: #define JUMP_TO_USER_VECTOR_TABLE0 __asm LDD #36856;
__asm JMP [D, PC];

They both jump to the proper address!!!

The problem is when the RTI get called at the end of the interrupt.

It jumps to a improper location.

---------------------------------

If I compare the execution with and without using my bootloader to
load the application, I see some difference between the registers at
the beginning of the interrupt.
For example, the Stack Pointer is not the same.

---------------------------------

Can you suggest me a macro definition to properly do the vector
redirection please???

Thanks

Alex