- handle mode + privileged
- thread mode + privileged
- thread mode + unprivileged
雖然我英文不行, 但我實在被中文字困惑, 還是把這個術語的英文找出來, 閱讀整段英文對我來說並不容易, 但只記點單字倒還不是問題。
2.2 Privileged access and user access
Code can execute as privileged or unprivileged. Unprivileged execution limits or excludes access to some resources. Privileged execution has access to all resources.
Handler mode is always privileged. Thread mode can be privileged or unprivileged.
Thread mode is privileged out of reset, but you can change it to user or unprivileged by clearing the CONTROL[0] bit using the MSR instruction. User access prevents:
- use of some instructions such as CPS to set FAULTMASK and PRIMASK
- access to most registers in System Control Space (SCS).
When Thread mode has been changed from privileged to user, it cannot change itself back to privileged. Only a Handler can change the privilege of Thread mode. Handler mode is always privileged.
ref: Cortex-M3 TM Revision: r1p1 Technical Reference Manual 2.2
以上和本主題都無關, 我把主題放在這之後, 厲害吧!
這隻程式主要是使用 cm3 的 2 個 stack, 解釋使用 msp, psp 時, 這兩個 stack 如何變化。
34 ldr sp, =#msp_stack_top @ msp開機時就會設定 msp, 不過這裡再設定一次
38 ldr r0, =#psp_stack_top 39 msr psp, r0設定 psp
41 mov r0, #0x3 42 msr control, r0從這裡之後, 藉由設定 control register, 會使用 psp, 並進入 thread/unprivileged mode。
before svc 0 (current is user access (thread/unprivileged) & use psp)
control 0x3 3 '\003'
msp 0x200005fc 0x200005fc
psp 0x200001fc 0x200001fc
after svc 0
control 0x1 1 '\001'
msp 0x200005fc 0x200005fc
psp 0x200001d8 0x200001d8
觀察 stack 變化, 使用 svc 跳到中斷常式後, 會 push 暫存器到 psp, 而在中斷常式會使用 msp 操作 stack。
在 L58 離開中斷常式後, psp 也回到原來值。
control 0x3 3 '\003'
msp 0x200005f8 0x200005f8
psp 0x200001fc 0x200001fc
再來的 stack 操作也是以 psp 為主。
沒有留言:
張貼留言
使用 google 的 reCAPTCHA 驗證碼, 總算可以輕鬆留言了。
我實在受不了 spam 了, 又不想讓大家的眼睛花掉, 只好放棄匿名留言。這是沒辦法中的辦法了。留言的朋友需要有 google 帳號。