简体   繁体   English

Cortex-M0 + PSR,IEPSR,IAPSR和EAPSR寄存器

[英]Cortex-m0+ psr, iepsr, iapsr, and eapsr registers

In the cortex-m0+ processor, there is a register called the "program status register" (psr for short) that holds 3 important pieces of information: 在cortex-m0 +处理器中,有一个寄存器称为“程序状态寄存器”(简称PSR),其中包含3条重要信息:

  • The condition flags (zero, carry, etc...), in bits <31:28> <31:28>位中的条件标志(零,进位等)
  • The exception number, in bits <5:0> (tells you which interrupt is being serviced, == 0 for no interrupt) <5:0>位中的异常号(告诉您正在处理哪个中断,无中断时== 0)
  • The "Am I in thumb mode" flag, in bit <24>. <24>位中的“我处于拇指模式”标志。

As you'd expect, all of these bit fields can be accessed by just reading the psr with an mrs r0, psr instruction. 如您所料,只需使用mrs r0, psr指令读取psr即可访问所有这些位字段。 The thing I'm confused about is on page 16-17 of the m0+ User Manual . 我感到困惑的是《 m0 +用户手册》的第16-17页 The manual tells me that I can access, say, ONLY the exception number bits (with all other bits set to zero), by reading the "ipsr" instead of the "psr". 该手册告诉我,只能通过读取“ ipsr”而不是“ psr”来访问异常号位(所有其他位都设置为零)。 Essentially, 实质上,

    mrs r0, ipsr

and

    mrs r0, psr
    and r0, r0, #0x3f

are identical. 都是一样的

Why are these alternate methods of accessing bitfields in the psr offered? 为什么提供了这些访问psr中位域的替代方法?

My best guess is that context-switching or ISR code would want to read ONLY the bottom 6 bits, and this saves a (not very expensive, imo) bitmasking operation. 我最好的猜测是上下文切换或ISR代码只希望读取底部的6位,这样可以节省(不是很昂贵的imo)位掩码操作。

What I think you're missing is that the mrs / msr instructions have been around since ARMv 3 well over 20 years ago (when the PC grew from 24 to 32 bits so the other stuff got kicked out of r15 into a special status register). 我认为您缺少的是自20年前ARMv 3起就出现了mrs / msr指令(当PC从24位增长到32位时,其他内容从r15踢出了特殊的状态寄存器) 。 The ARM encodings have always had to differentiate between SPSR vs. CPSR vs. parts of CPSR. ARM编码始终必须区分SPSR,CPSR和CPSR的各个部分。 When Thumb-2 came along after ARMv6, the Thumb encodings thus also had to differentiate between SPSR vs. CPSR vs. parts of CPSR on ARM1156/Cortex-A. 当Thumb-2在ARMv6之后出现时,Thumb编码因此也必须区分ARM1156 / Cortex-A上的SPSR与CPSR与CPSR的某些部分。

The point is, then, that there are already bits in those encodings to encode more than one target status register in the classic/A-class architectures - as it happens, there are still a fair few reserved bits spare even after the ARMv7-A virtualisation extensions also added various banked registers to the mix. 关键是,在这些编码中已经有一些位可以对经典/ A类体系结构中的多个目标状态寄存器进行编码-碰巧的是,即使在ARMv7-A之后,仍然有很少的保留位可用虚拟化扩展还增加了各种存储寄存器。 Now imagine you're designing a new architecture to push your successful embedded ISA/design expertise/development ecosystem into the lower-end microcontroller space, where 8-bit parts dominate and code size and efficiency is critical . 现在,想象您正在设计一种新的体系结构,以将成功的嵌入式ISA /设计专业知识/开发生态系统推入低端微控制器领域,在该领域中8位组件占主导地位,代码大小和效率至关重要 The question then becomes why would you not press those otherwise-unused instruction encoding bits into action to make status register accesses as efficient as they possibly can be? 接下来的问题是,为什么你会不会那些否则未使用的指令编码位压制成行动,使状态寄存器的访问效率,因为他们可能可以吗?

If you only need the IPSR field, you can just use the corresponding (single) instruction. 如果只需要IPSR字段,则可以使用相应的(单个)指令。

I think that the second example is just to clarify the behaviour, as this is the CPU which is responsible for masking the data and set all the top bits to 0. 我认为第二个示例只是为了阐明行为,因为这是负责屏蔽数据并将所有高位设置为0的CPU。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM