2008年11月13日星期四

动态中断向量

ResetEntry
b ResetHandler
b Undefined_Handler
b SWI_Handler
b Prefetch_Handler
b Abort_Handler
nop
ldr pc, =0x300ffffc
b FIQ_Handler

//0x18 = jump to 0x300ffffc
//0x300ffffc = jump to IsrHandler
//b arm, ea000006 = 6 <<2 +8 + pc
//b code, (dst - src -8) >>2 +0xea000000
void RegInterrupteHandlerTable(void)
{
unsigned long dest_addr = (unsigned long)IsrHandler;
unsigned long offset_addr ;
unsigned long *pIrqHandler = (unsigned long *)0x300ffffc;

offset_addr = (((dest_addr - (unsigned long)pIrqHandler - 8)) >> 2)&0xffffff;

*pIrqHandler = 0xea000000+offset_addr;
}

以前把整个表做重新做动态了,没必要,现在就修改irq这一条,而且思路比以前清晰

0x18地址存放的指令是 pc=0x300ffffc
0x300ffffc地址存放的指令是 b IsrHandler,是做出来的指令

拿一般第一条指令的机器码来说,一般是b resethandler
0地址机器码 :0xea000006
resethandler函数地址 0x20

0 + 6 << 2 +8 = 0x20,这样就会跳转到resethandler函数的地址了

没有评论: