启动玩具内核时,我使用以下代码切换到用户模式:
mrs r1, CPSR @ Switch to System mode
orr r1, r1, #0xc
msr CPSR, r1
ldr sp, =gUsrStackBase @ Setup USR stack (shared with System mode)
mov r1, #0x10 @ Get user-mode CPSR into SPSR
msr SPSR, r1
movs pc, r0 @ Switch to USR mode and branch
但是关注了
movs
指令,而不是我设置的用户模式 CPSR 值(0x10),CPSR 中有随机垃圾。为什么会这样?
最佳答案
我在很长很长的时间里一直反对这个问题! [1] !最后我找到了问题的原因。在 ARM 体系结构引用手册(只有最新的 ARMv7A -R 版本!)[2] 中,是这样的:
An MSR (register) executed in System mode is UNPREDICTABLE if it attempts to update the SPSR.
(对于立即数
MSR
也是如此)。解决方案是在设置 SPSR 之前切换回主管(或其他特权)模式。
[1] 非常
[2] 您可以在此处获取 ARMv7-ARM(您需要注册):http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0406c/index.html
关于assembly - 当我切换到用户模式时,为什么我的 CPSR 中会出现垃圾?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26714913/