資源描述:
《arm linux 中斷分析》由會員上傳分享,免費在線閱讀,更多相關內(nèi)容在教育資源-天天文庫。
1、ARMLinux中斷分析???ARM體系結構中,把復位、中斷、快速中斷等都看作‘異?!?,當這些‘異常’發(fā)生時,CPU會到固定地址處去找指令,他們對應的地址如下:地址異常類型進入時的工作模式0x00000000ResetSupervisor0x00000004UndUndefined0x00000008SoftinteruptSupervisor0x0000000c?Abort(prefetch)?Abort0x00000010Abort(data)Abort0x00000014Reserved?Reserved0x00000018IRQIRQ0x0000001cFIQFIQ???
2、首先要明確的一點就是,無論內(nèi)存地址空間是如何映射的,以上這些地址都不會變,比如當有快速中斷發(fā)生時,ARM將鐵定到0X0000001C這個地址處取指令。這也是BOOTLOADER把操作系統(tǒng)引導以后,內(nèi)存必須重映射的原因!否則操作系統(tǒng)不能真正接管整套系統(tǒng)!???LINUX啟動以后要初始化這些區(qū)域,初始化代碼在main.c中的start_kernel()中,具體是調(diào)用函數(shù)trap_ini()來實現(xiàn)的。如下面所示(具體可參照entry-armv.S):.LCvectors:???swi?SYS_ERROR0?????????????b?????__real_stubs_start+(ve
3、ctor_undefinstr-__stubs_start)??????????ldr????pc,__real_stubs_start+(.LCvswi-__stubs_start)????????????b?????__real_stubs_start+(vector_prefetch-__stubs_start)????????????b?????__real_stubs_start+(vector_data-__stubs_start)????????????b?????__real_stubs_start+(vector_addrexcptn-__stubs_start
4、)????????????b?????__real_stubs_start+(vector_IRQ-__stubs_start)????????????b?????__real_stubs_start+(vector_FIQ-__stubs_start)ENTRY(__trap_init)??????????stmfd????????sp!,{r4-r6,lr}??????????adr???r1,.LCvectors???????????????????????@setupthevectors??????????ldmiar1,{r1,r2,r3,r4,r5,r6,ip,lr}
5、??????????stmiar0,{r1,r2,r3,r4,r5,r6,ip,lr}??????????add???r2,r0,#0x200??????????adr???r0,__stubs_start?????????@copystubsto0x200??????????adr???r1,__stubs_end1:????????????????ldr????r3,[r0],#4??????????str????r3,[r2],#4??????????cmp?r0,r1??????????blt????1b??????????LOADREGS(fd,sp!,{r4-r6,p
6、c})?以上可以看出這個函數(shù)初始化了中斷向量,實際上把相應的跳轉指令拷貝到了對應的地址。當發(fā)生中斷時,不管是從用戶模式還是管理模式調(diào)用的,最終都要調(diào)用do_IRQ():__irq_usr:???sub???sp,sp,#S_FRAME_SIZE??????????stmiasp,{r0-r12}????????????????????????@saver0-r12??????????ldr????r4,.LCirq??????????add???r8,sp,#S_PC??????????ldmiar4,{r5-r7}??????????????????????????@getsa
7、vedPC,SPSR??????????stmiar8,{r5-r7}??????????????????????????@savepc,psr,old_r0??????????stmdb????????r8,{sp,lr}^??????????alignment_trapr4,r7,__temp_irq??????????zero_fp1:????????????????get_irqnr_and_baser0,r6,r5,lr??????????movne???????r1,