在华邦所给的bootloader中,SWI中断有一个功能用作去执行镜像文件。
swi_run(EXEC_SWI_NUM, pfooter->exec_address);
我知道EXEC_SWI_NUM=0x200,在__swi函数中传递给r0,pfooter->exec_address作为要执行的地址传递给r1.
在SWI中断服务函数中,
CMP r0, #0x200
BEQ sh_run_SWI
跳转至 sh_run_SWI,如下
sh_run_SWI
STMFD sp!, {r2-r12,lr}
; mask all interrupt from AIC controller
LDR r2, =AIC_IMR
LDR r2, [r2]
MRS r3, SPSR
STMFD sp!, {r2,r3} ; store the AIC_IMR,spsr for semihosted return
LDR r2, =AIC_MDCR
LDR r3, =0x7FFFE
STR r3, [r2] ; mask all interrupt source
MOV r2, sp
LDR sp, =semi_stack
LDR sp, [sp] ; set to semihosted stack
STMFD sp!, {r2} ; store the stack of boot loader
MOV pc, r1 ; run the program
ldr r1,=0xfff83000
mov r2,#0x31
strb r2,[r1,#0]
LDMFD sp!, {r2-r12,pc}
上面代码中,我清楚蓝色字是用于关中断、重新设置SP等,
红色代码是直接将PC值赋予r1,也就是传进的参数pfooter->exec_address,然后CPU就去执行镜像文件去了。
但不清楚的是,CPU在执行完一个镜像文件后,是怎么返回到bootloader中,去执行下一个镜像文件的?
而且,还发现 sh_return_SWI 一段代码:
sh_return_SWI
LDR sp, =semi_stack
LDR sp, [sp]
LDR sp, [sp,#-4]
LDMFD sp!, {r2,r3} ; restore the AIC_IMR, spsr
MSR SPSR_cxsf, r3 ; restore the SPSR
LDR r3, =AIC_MDCR
LDR r4, =0x7FFE
STR r4, [r3]
LDR r3, =AIC_MECR
STR r2, [r3] ; retore the AIC mask register
LDMFD sp!, {r2-r12,pc}^
也起了作用,但进入sh_return_SWI的条件是
CMP r0, #0x18
BEQ sh_return_SWI,请问,R0,在执行完镜像文件后是如何被赋予 0x18值的??
谢谢!!!!! |