ARM Cortex Overview
ARM Architecture 从第七代开始,分为三种配置(Profile)
- Application:AXI,VMSA(MMU)
- Real-time:AXI,PMSA(MPU),TCM(Cache),多核
- Micocontroller:AHB(-Lite),APB,NIVC,Thumb Only,单核 补充:新架构有支援Variant PMSA(M4,M7,M23),Variant TCM(M7,M55)
Ref:ARM Cortex-M wiki
ARM Cortex-M3 架构介绍
- Cortex-M3 只支援 Thumb-1 和 Thumb-2 指令,而 32-bit ARM 指令则不支援
- Thumb 是由:16 bits 或是 16+16=32bit组成
- 下图为Cortex-M 的架构图,M系列有一个很特别的特就是Nested Vectored Interrupt Controller (NVIC)
- 什麽是Nested Interrupt?
- 带来甚麽好处?
- 透过 Interrupt with priority 达到 Deterministic
暂存器介绍
图片来自 Definitive Guide To the ARM Cortex-M3
- R0-12 为通用暂存器,16-bit Thumb instruction 只能 assess R0-R7(low registers)
- 有两个Stack Pointer:MSP PSP (使用哪个取决於在哪个模式底下)
- Main Stack Pointer (MSP):默认的 Stack Pointer,通常是OS Kernel 和 Exception handlers 使用
- Process Stack Pointer (PSP):User Application code 使用
- R14 Link Register:存放副函式返回位址
- R15 Program Cunter:存放下一行要执行的指令
- xPSR : 状态暂存器 负责储存目前Program的状态,由三个register组成
- Application Program Status register (APSR)
- Interrupt Program Status register (IPSR)
- Execution Program Status register (EPSR)
在读取这些 register 使用 MRS instruction,APSR 可更改, EPSR and IPSR read-only
MRS r0, APSR ; Read Flag state into R0
MRS r0, IPSR ; Read Exception/Interrupt state
MRS r0, EPSR ; Read Execution state
MSR APSR, r0 ; Write Flag state
- PRIMASK,FAULTMASK,BASEPRI : 处理 Interrupt Mask,在这个特权等级下才可以读取。
- CONTROL : 模式切换暂存器,在Thread mode 无法更改 CONTROL 这个暂存器
Operation Modes
图片来自 Definitive Guide To the ARM Cortex-M3
- User (non-privileged) mode
- 不能够直接access 某些特殊暂存器,也不能access 全部的Memory和system timer, NVIC, or system control block
- Privileged mode
- Thread mode
- 在跑 Main Program 时的 mode,可为Privileged Mode 和 User (non-privileged) mode
- Handler mode
- 只有在发生 exception发生时进入,且必为Privileged
参考资料
The Definitive Guide to the ARM Cortex M3
手机里的 ARM 处理器: 隐藏的精灵 Cortex-M