📄 saveregisters.s
字号:
PRESERVE8
;------------------------------
; nasty macro to save registers
;------------------------------
MACRO
SAVE_REGISTERS
;
; save the user registers below the user stackpointer
; pre: user r0-r2 are stored at sp, r0 can''t be used, r2 contains saved cpsr
; post: r1 points to user registers
;
STMFD sp, {r13}^ ;save user stackpointer into the supervisor stack
;MDM: (point k:)
NOP ;last instruction must not be followed by an instruction which accesses banked registers (a following NOP is a good way to ensure this)
LDR r1, [sp,#-4] ;load it into r1
SUB r1, r1, #4; ;leave a slot for the cpsr
STMFD r1, {r0 - r15}^ ;save all user registers into user stack
STR lr, [r1,#-4] ;update the saved user program counter with the banked link register
STR r2, [r1] ;put saved cpsr value onto user the stack
SUB r2, r1, #16*4 ;point r2 at the start of the saved registers
LDMFD sp!, {r3-r5} ;copy saved r0-r2 registers into registers
STMEA r2, {r3-r5} ;and into the user stack
LDR r1, =savedUserSP ;load address of savedUserSP
STR r2, [r1] ;save it for later
MOV r1, r2 ;and pass it to the handle_system_call function
MEND
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -