參考:Arm Architecture Reference Manual for A-profile architecture C5.2 Special-purpose registers
當前運行狀態
PSTATE不是一個寄存器,它表示的是保存當前 process 狀態信息的一組寄存器或者一些標志位信息的統稱
aarch64 狀態下,PSTATE 里面包含的 信息包括下面 字段。
type ProcState is ( bits (1) N, // Negative condition flag bits (1) Z, // Zero condition flag bits (1) C, // Carry condition flag bits (1) V, // Overflow condition flag bits (1) D, // Debug mask bit [AArch64 only] bits (1) A, // SError interrupt mask bit bits (1) I, // IRQ mask bit bits (1) F, // FIQ mask bit bits (1) PAN, // Privileged Access Never Bit [v8.1] bits (1) UAO, // User Access Override [v8.2] bits (1) DIT, // Data Independent Timing [v8.4] bits (1) TCO, // Tag Check Override [v8.5, AArch64 only] bits (2) BTYPE, // Branch Type [v8.5] bits (1) ZA, // Accumulation array enabled [SME] bits (1) SM, // Streaming SVE mode enabled [SME] bits (1) ALLINT, // Interrupt mask bit bits (1) SS, // Software step bit bits (1) IL, // Illegal Execution state bit bits (2) EL, // Exception level bits (1) nRW, // not Register Width: 0=64, 1=32 bits (1) SP, // Stack pointer select: 0=SP0, 1=SPx [AArch64 only] bits (1) SSBS, // Speculative Store Bypass Safe )
有些字段可以通過 特殊寄存器 讀寫
NZCV
DAIF
CurrentEL
spsel
PAN
UAO
DIT
ALLINT
SSBS
下面這些字段 可以使用 MSR 指令直接 寫入
PSTATE.{D, A, I, F, SP, PAN, UAO, SSBS, TCO}
下面這些字段,可以在 EL0 級別訪問
PSTATE.{N, Z, C, V, SSBS, DIT, TCO}.
如果 SCTLR_EL1.UMA 為 0, 這些也可以在 EL 0 訪問: PSTATE.{D, A, I, F}
異常發生時的狀態保存
SPSR_EL1 SPSR_EL2 SPSR_EL3
SPSR_EL1 Holds the saved process state when an exception is taken to EL1
異常目標等級
SPSR_EL1 寄存器 保存 異常切換目標等級為 EL1 的 ,程序切換前的狀態。
相應的,SPSR_EL2 SPSR_EL3 保存,異常切換目標等級位 EL2 EL3 的,程序切換前的狀態。
異常發生前程序運行狀態
在異常發生前,程序可能在 32 位模式 或者 64 位模式。 通過 SPSR_EL1 的 bit[4] 來確定, bit[4] == 1, 則異常發生前,程序是 32 位模式, bit[4]==0,則異常發生前,程序是 64位模式。
根據 bit[4] 為 0 或 1 的不同, SPSR_EL1 的其他 字段也有差異。
當 bit[4] == 0 時,之前的模式為 64 位模式,SPSR_EL1 包含字段
當 bit[4] == 1 時,之前模式位 32 位模式, SPSR_EL1 包含字段
SPSR_EL2 和 SPSR_EL3 也相同的邏輯。