Guest code runs at EL0 alone, where the stack pointer is always SP_EL0 (PSTATE.SP is 0 there and EL0 can't set it), which the CPU keeps after X30, as GPR's last element
val SP_read : unit -> bits(64) function SP_read () = GPR[31]
val SP_read : unit -> bits(64)
function SP_read () = {
if PSTATE.SP == 0b0 then {
return(SP_EL0)
} else {
match PSTATE.EL {
? if ? == EL0 => {
return(SP_EL0)
},
? if ? == EL1 => {
return(SP_EL1)
},
? if ? == EL2 => {
return(SP_EL2)
},
? if ? == EL3 => {
return(SP_EL3)
},
_ => {
return(undefined : bits(64))
}
}
}
}
Made from ScarletNX's Sail at 166ad3910f80. sail-arm's definitions are Arm's ASL in Sail (BSD 3-Clause Clear, license); ScarletNX's fixups are GPL-3.0-or-later.