微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > ARM的System Mode

ARM的System Mode

时间:11-10 来源:互联网 点击:
ARM v4以后的版本里,ARM核都有7中工作模式:User, FIQ, IRQ, Supervisor, Abort, Undefined,和System

7种processor mode又分为3类:

User mode

Privileged mode

system mode

对于System mode的作用一直有些模糊,今天在arm的网站上找到了一份说明文档,对这个问题的解析很到位,特记录如下:

The ARM Architecture defines a User mode that has 15 generalpurpose registers, a pc, and a CPSR.

除User Mode外,还有5种privileged modes

每一种Priviledged mode都有一个SPSRand a number of registers that replace some of the 15 User mode generalpurpose registers.

当exception发生时:

the current PC is copied into the link register for the exception mode,

theCPSR is copied into the SPSR for the exception mode.

The CPSR isthen altered in an exception-dependent way, and the program counteris set to an exception-defined address to start the

exception handler.

BL指令copiesthe return address into r14 before changing the PC,so the subroutine return instruction moves r14 to pc (MOV pc,lr).

Together these actions imply that ARM modes that handle exceptionsmust ensure that another exception of the same type cannot

occurif they call subroutines, because the subroutine return addresswill be overwritten with the exception return address.

(要防止lr被覆盖)

(In earlier versions of the ARM architecture, this problemhas been solved by either carefully avoiding subroutine calls inexception

code, or changing from the privileged mode to User mode.The first solution is often too restrictive, and the second meansthe task

may not have the privileged access it needs to run correctly.)

从ARMv4架构开始,提供了system mode来解决lr覆盖问题.

System mode is a privileged processormode that shares the User mode registers. (与User Mode共用registers)

Privileged mode taskscan run in this mode, and exceptions no longer overwrite the linkregister.

注意:

System modecannot be entered by an exception.

The exceptionhandlers modify the CPSR to enter System mode. See Reentrant interrupt handlersfor an example.

就不逐字翻译了,大体意思如下:

当处理器异常出现时,当前程序计数器(也就是 PC+offset,offset与异常种类相关)会被拷贝的相应异常模式的LR,CPSR也会被拷贝到

相应异常模式的SPSR。然后CPSR会被设置为相应的异常模式, PC被设置到对应异常的入口处执行其处理函数。

(上面这些都是ARM核自动操作的)

ARM的子程序转移指令BL会在改变PC前将返回地址放到LR中,所以从子程序返回时可以把r14放到PC来操作。如MOV pc, lr。

所有上面的动作都暗示了如果异常处理函数会调用子程序(使用 BL),那么各异常模式都必须保证异常处理函数执行的过程中不能出现

同样的异常,因为子函数的返回地址会被异常的返回地址覆盖掉。(在早期的ARM版本中,可以通过禁止异常处理函数调用子函数或者切

换处理模式到User模式来解决这个问题。第一种方式过于严格,而第二种方式可以会由于User模式缺少相应的权限而不能执行某些动

作)。

为此,ARM v4及之后的版本提供了system mode这样一种处理器模式来解决这个问题。System mode是一种privileged的模式,而且共用

User模式的所有寄存器。Privileged模式的程序可以运行在这个模式,而不用担心处理器异常会擦除LR。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top