免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1895 | 回复: 1
打印 上一主题 下一主题

[驱动] 一段中断处理函数的安装代码有点迷惑,请教一下各位前辈 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-07-23 10:58 |只看该作者 |倒序浏览
void install_irqhandler(void * isr)
{
        /* ARM irq exception vector addr is 0x00000018  */
        unsigned int * irq_vec_addr = ( unsigned int * ) 0x18;

        /* this is isr entry address, could be another address like 0x3c, 0x58... */
        unsigned int * isr_entry_addr = ( unsigned int * ) 0x38;

        unsigned int instruction;
       
        /* set the ISR entry at 0x38  */
        *isr_entry_addr = (unsigned int)isr;
       
        /* make an instruction: it is machine-code for "ldr  pc, [pc, #(38-18-]"  */
/* pc是预取指令,会自动加8所以要得出中断处理函数地址的偏移量就后再减去pc事

  先自动加上的8才得到真正的偏移量 */
        instruction = ((unsigned int) isr_entry_addr  - (unsigned int)irq_vec_addr - 0x0 | 0xe59ff000;
       
        /* set this instruction at 0x18  */
        *irq_vec_addr = instruction;       
}
我的理解是当irq中断发生,从向量表0x18跳转到0x38去寻找中断处理函数。问题是0x38只是存放了isr的地址,没有使用ldr之类的指令pc指针怎么从0x38又跳转到isr的地址的呢?

论坛徽章:
0
2 [报告]
发表于 2013-07-25 23:37 |只看该作者
中断到来,pc首先到中断入口,也就是0x18,这个位置是条指令。这个指令的含义就是将0x38处的地址放入 pc 吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP