[Writeup] Shared pseudocode: part 9 of 36 ========================================= Section: Silicon & Architectures Started: 2026-11-28 17:44 UTC by admin Replies: 0, last post 2026-11-28 17:44 UTC Page: 1 of 1 Web: https://romdump.net/t/101 ------------------------------------------------------------------------------ #121 admin, 2026-11-28 17:44 UTC [OP] Source: https://romdump.net/raw/121
Shared pseudocode from the offline Arm documentation snapshot. Part 9 of 36.
if !IsFeatureImplemented(FEAT_DoubleFault) then return FALSE; end;
var ease_bit : bit;
case target_el of
when EL3 =>
ease_bit = SCR_EL3().EASE;
when EL2 =>
if IsFeatureImplemented(FEAT_DoubleFault2) && IsSCTLR2EL2Enabled() then
ease_bit = SCTLR2_EL2().EASE;
else
ease_bit = '0';
end;
when EL1 =>
if IsFeatureImplemented(FEAT_DoubleFault2) && IsSCTLR2EL1Enabled() then
ease_bit = SCTLR2_EL1().EASE;
else
ease_bit = '0';
end;
end;
return (ease_bit == '1');
end;
## Library pseudocode for aarch64/exceptions/aborts/AArch64\_SPAlignmentFault
// AArch64_SPAlignmentFault // ========================== // Called on an unaligned stack pointer in AArch64 state.
func AArch64_SPAlignmentFault begin
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let vect_offset : integer = 0x0;
let except : ExceptionRecord = ExceptionSyndrome(Exception_SPAlignment);
var target_el : bits(2) = EL1;
if UInt(PSTATE.EL) > UInt(EL1) then
target_el = PSTATE.EL;
elsif EL2Enabled() && HCR_EL2().TGE == '1' then
target_el = EL2;
end;
AArch64_TakeException(target_el, except, preferred_exception_return,
vect_offset);
end;
## Library pseudocode for aarch64/exceptions/aborts/BranchTargetException
// BranchTargetException // ======================= // Generate branch target exception.
func AArch64_BranchTargetException(vaddress : bits(52)) begin let preferred_exception_return : bits(64) = ThisInstrAddr{}(); let vect_offset : integer = 0x0;
var except : ExceptionRecord =
ExceptionSyndrome(Exception_BranchTarget);
except.syndrome.iss[1:0] = PSTATE.BTYPE;
except.syndrome.iss[24:2] = Zeros{23}; // RES0
var target_el : bits(2) = EL1;
if UInt(PSTATE.EL) > UInt(EL1) then
target_el = PSTATE.EL;
elsif PSTATE.EL == EL0 && EL2Enabled() && HCR_EL2().TGE == '1'
then
target_el = EL2;
end;
AArch64_TakeException(target_el, except, preferred_exception_return,
vect_offset);
end;
## Library pseudocode for aarch64/exceptions/aborts/TCFType
// TCFType // =======
type TCFType of enumeration { TCFType_Sync, TCFType_Async, TCFType_Ignore };
## Library pseudocode for aarch64/exceptions/aborts/TakeGPCException
// TakeGPCException // ================== // Report Granule Protection Exception faults
func TakeGPCException(fault : FaultRecord) begin assert IsFeatureImplemented(FEAT_RME);
var except : ExceptionRecord;
except.exceptype = Exception_GPC;
except.vaddress = ZeroExtend{64}(fault.vaddress);
except.paddress = fault.paddress;
except.pavalid = TRUE;
if IPAValid(fault) then
except.ipavalid = TRUE;
except.NS = if fault.ipaddress.paspace == PAS_NonSecure then '1' else '0';
except.ipaddress = fault.ipaddress.address;
else
except.ipavalid = FALSE;
end;
except.syndrome.iss2[11] = if fault.hdbssf then '1' else '0'; // HDBSSF
if fault.accessdesc.acctype == AccessType_GCS then
except.syndrome.iss2[8] = '1'; //GCS
end;
// Populate the fields grouped in ISS
except.syndrome.iss[24:22] = Zeros{3}; // RES0
except.syndrome.iss[21] = if fault.gpcfs2walk then '1' else '0'; // S2PTW
if fault.accessdesc.acctype == AccessType_IFETCH then
except.syndrome.iss[20] = '1'; // InD
else
except.syndrome.iss[20] = '0'; // InD
end;
except.syndrome.iss[19:14] = EncodeGPCSC(fault.gpcf); // GPCSC
if IsFeatureImplemented(FEAT_NV2) && fault.accessdesc.acctype ==
AccessType_NV2 then
except.syndrome.iss[13] = '1'; // VNCR
else
except.syndrome.iss[13] = '0'; // VNCR
end;
except.syndrome.iss[12:11] = '00'; // RES0
except.syndrome.iss[10:9] = '00'; // RES0
if fault.accessdesc.acctype IN {AccessType_DC, AccessType_IC, AccessType_AT}
then
except.syndrome.iss[8] = '1'; // CM
else
except.syndrome.iss[8] = '0'; // CM
end;
except.syndrome.iss[7] = if fault.s2fs1walk then '1' else '0'; // S1PTW
if fault.accessdesc.acctype IN {AccessType_DC, AccessType_IC, AccessType_AT}
then
except.syndrome.iss[6] = '1'; // WnR
elsif fault.statuscode IN {Fault_UnsupportedAtomicHWUpdate, Fault_Exclusive}
then
except.syndrome.iss[6] = ARBITRARY : bit; // WnR
elsif fault.accessdesc.atomicop && IsExternalAbort(fault) then
except.syndrome.iss[6] = ARBITRARY : bit; // WnR
else
except.syndrome.iss[6] = if fault.write then '1' else '0'; // WnR
end;
except.syndrome.iss[5:0] = EncodeLDFSC(fault.statuscode, fault.level); // xFSC
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let target_el : bits(2) = EL3;
var vect_offset : integer;
if IsExternalAbort(fault) && AArch64_RouteToSErrorOffset(target_el)
then
vect_offset = 0x180;
else
vect_offset = 0x0;
end;
AArch64_TakeException(target_el, except, preferred_exception_return,
vect_offset);
end;
## Library pseudocode for
aarch64/exceptions/async/AArch64\_TakeDelegatedSErrorException
// AArch64_TakeDelegatedSErrorException // ======================================
func AArch64_TakeDelegatedSErrorException begin assert (IsFeatureImplemented(FEAT_E3DSE) && PSTATE.EL != EL3 && EffectiveSCR_EL3_EnDSE() == '1' && SCR_EL3().DSE == '1');
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let vect_offset = 0x180;
var except : ExceptionRecord = ExceptionSyndrome(Exception_SError);
var target_el : bits(2);
var dsei_masked : boolean;
(dsei_masked, target_el) = AArch64_DelegatedSErrorTarget();
assert !dsei_masked;
except.syndrome.iss[24] = VSESR_EL3().IDS;
except.syndrome.iss[23:0] = VSESR_EL3().ISS;
ClearPendingDelegatedSError();
AArch64_TakeException(target_el, except, preferred_exception_return,
vect_offset);
end;
## Library pseudocode for
aarch64/exceptions/async/AArch64\_TakePhysicalFIQException
// AArch64_TakePhysicalFIQException // ==================================
func AArch64_TakePhysicalFIQException begin
let route_to_el3 : boolean = EffectiveSCR_EL3_FIQ() == '1';
let route_to_el2 : boolean = (PSTATE.EL IN {EL0, EL1} && EL2Enabled()
&&
(HCR_EL2().TGE == '1' || HCR_EL2().FMO == '1'));
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let vect_offset : integer = 0x100;
let except : ExceptionRecord = ExceptionSyndrome(Exception_FIQ);
if route_to_el3 then
AArch64_TakeException(EL3, except, preferred_exception_return, vect_offset);
elsif PSTATE.EL == EL2 || route_to_el2 then
assert PSTATE.EL != EL3;
AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset);
else
assert PSTATE.EL IN {EL0, EL1};
AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset);
end;
end;
## Library pseudocode for
aarch64/exceptions/async/AArch64\_TakePhysicalIRQException
// AArch64_TakePhysicalIRQException // ================================== // Take an enabled physical IRQ exception.
func AArch64_TakePhysicalIRQException begin
let route_to_el3 : boolean = EffectiveSCR_EL3_IRQ() == '1';
let route_to_el2 : boolean = (PSTATE.EL IN {EL0, EL1} && EL2Enabled()
&&
(HCR_EL2().TGE == '1' || HCR_EL2().IMO == '1'));
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let vect_offset : integer = 0x80;
let except : ExceptionRecord = ExceptionSyndrome(Exception_IRQ);
if route_to_el3 then
AArch64_TakeException(EL3, except, preferred_exception_return, vect_offset);
elsif PSTATE.EL == EL2 || route_to_el2 then
assert PSTATE.EL != EL3;
AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset);
else
assert PSTATE.EL IN {EL0, EL1};
AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset);
end;
end;
## Library pseudocode for
aarch64/exceptions/async/AArch64\_TakePhysicalSErrorException
// AArch64_TakePhysicalSErrorException // =====================================
func AArch64_TakePhysicalSErrorException(implicit_esb : boolean) begin var masked : boolean; var target_el : bits(2);
(masked, target_el) = PhysicalSErrorTarget();
assert !masked;
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let vect_offset : integer = 0x180;
let fault : FaultRecord = GetPendingPhysicalSError();
var except : ExceptionRecord = ExceptionSyndrome(Exception_SError);
let is_esb : boolean = FALSE;
let syndrome : bits(25) = AArch64_PhysicalSErrorSyndrome(is_esb,
implicit_esb);
if IsSErrorEdgeTriggered() then
ClearPendingPhysicalSError();
end;
if except.syndrome.iss[14] == '1' then
except.pavalid = TRUE;
except.paddress = fault.paddress;
else
except.pavalid = FALSE;
except.paddress = ARBITRARY : FullAddress;
end;
except.syndrome.iss = syndrome;
AArch64_TakeException(target_el, except, preferred_exception_return,
vect_offset);
end;
## Library pseudocode for
aarch64/exceptions/async/AArch64\_TakeVirtualFIQException
// AArch64_TakeVirtualFIQException // =================================
func AArch64_TakeVirtualFIQException begin assert PSTATE.EL IN {EL0, EL1} && EL2Enabled(); // Virtual IRQ enabled if TGE==0 and FMO==1 assert HCR_EL2().TGE == '0' && HCR_EL2().FMO == '1';
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let vect_offset : integer = 0x100;
let except : ExceptionRecord = ExceptionSyndrome(Exception_FIQ);
AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset);
end;
## Library pseudocode for
aarch64/exceptions/async/AArch64\_TakeVirtualIRQException
// AArch64_TakeVirtualIRQException // =================================
func AArch64_TakeVirtualIRQException begin assert PSTATE.EL IN {EL0, EL1} && EL2Enabled(); // Virtual IRQ enabled if TGE==0 and IMO==1 assert HCR_EL2().TGE == '0' && HCR_EL2().IMO == '1';
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let vect_offset : integer = 0x80;
let except : ExceptionRecord = ExceptionSyndrome(Exception_IRQ);
AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset);
end;
## Library pseudocode for
aarch64/exceptions/async/AArch64\_TakeVirtualSErrorException
// AArch64_TakeVirtualSErrorException // ====================================
func AArch64_TakeVirtualSErrorException begin
assert PSTATE.EL IN {EL0, EL1} && EL2Enabled();
// Virtual SError enabled if TGE==0 and AMO==1 or TMEA==1
assert (HCR_EL2().TGE == '0' &&
(HCR_EL2().AMO == '1' || (IsHCRXEL2Enabled() && HCRX_EL2().TMEA == '1')));
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let vect_offset : integer = 0x180;
var except : ExceptionRecord = ExceptionSyndrome(Exception_SError);
if IsFeatureImplemented(FEAT_RAS) then
except.syndrome.iss[24] = VSESR_EL2().IDS;
except.syndrome.iss[23:0] = VSESR_EL2().ISS;
else
let syndrome : bits(25) = ImpDefBits{}("Virtual SError syndrome");
let impdef_syndrome : boolean = syndrome[24] == '1';
if impdef_syndrome then except.syndrome.iss = syndrome; end;
end;
ClearPendingVirtualSError();
AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset);
end;
## Library pseudocode for
aarch64/exceptions/debug/AArch64\_BreakpointException
// AArch64_BreakpointException // =============================
func AArch64_BreakpointException(fault : FaultRecord) begin assert PSTATE.EL != EL3;
let route_to_el2 : boolean = (PSTATE.EL IN {EL0, EL1} &&
EL2Enabled() &&
(HCR_EL2().TGE == '1' || MDCR_EL2().TDE == '1'));
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
var target_el : bits(2);
let vect_offset : integer = 0x0;
target_el = if (PSTATE.EL == EL2 || route_to_el2) then EL2 else EL1;
let vaddress : bits(64) = ARBITRARY : bits(64);
let except : ExceptionRecord = AArch64_AbortSyndrome(Exception_Breakpoint,
fault, target_el);
AArch64_TakeException(target_el, except, preferred_exception_return,
vect_offset);
end;
## Library pseudocode for aarch64/exceptions/debug/AArch64\_SoftwareBreakpoint
// AArch64_SoftwareBreakpoint // ============================
func AArch64_SoftwareBreakpoint(immediate : bits(16)) begin
let route_to_el2 : boolean = (PSTATE.EL IN {EL0, EL1} &&
EL2Enabled() && (HCR_EL2().TGE == '1' || MDCR_EL2().TDE == '1'));
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let vect_offset : integer = 0x0;
var except : ExceptionRecord =
ExceptionSyndrome(Exception_SoftwareBreakpoint);
except.syndrome.iss[15:0] = immediate;
if UInt(PSTATE.EL) > UInt(EL1) then
AArch64_TakeException(PSTATE.EL, except, preferred_exception_return, vect_offset);
elsif route_to_el2 then
AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset);
else
AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset);
end;
end;
## Library pseudocode for
aarch64/exceptions/debug/AArch64\_SoftwareStepException
// AArch64_SoftwareStepException // ===============================
func AArch64_SoftwareStepException begin assert PSTATE.EL != EL3;
let route_to_el2 : boolean = (PSTATE.EL IN {EL0, EL1} &&
EL2Enabled() &&
(HCR_EL2().TGE == '1' || MDCR_EL2().TDE == '1'));
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let vect_offset : integer = 0x0;
var except : ExceptionRecord = ExceptionSyndrome(Exception_SoftwareStep);
except.syndrome.iss[5:0] = '100010'; // IFSC = Debug Exception
if PSTATE.EL == EL2 || route_to_el2 then
AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset);
else
AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset);
end;
end;
## Library pseudocode for
aarch64/exceptions/debug/AArch64\_VectorCatchException
// AArch64_VectorCatchException // ============================== // Vector Catch taken from EL0 or EL1 to EL2. This can only be called when debug exceptions are // being routed to EL2, as Vector Catch is a legacy debug event.
func AArch64_VectorCatchException(fault : FaultRecord) begin assert PSTATE.EL != EL2; assert EL2Enabled() && (HCR_EL2().TGE == '1' || MDCR_EL2().TDE == '1');
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let vect_offset : integer = 0x0;
let vaddress : bits(64) = ARBITRARY : bits(64);
let except : ExceptionRecord = AArch64_AbortSyndrome(Exception_VectorCatch,
fault, EL2);
AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset);
end;
## Library pseudocode for
aarch64/exceptions/debug/AArch64\_WatchpointException
// AArch64_WatchpointException // =============================
func AArch64_WatchpointException(fault : FaultRecord) begin assert PSTATE.EL != EL3;
let route_to_el2 : boolean = (PSTATE.EL IN {EL0, EL1} &&
EL2Enabled() &&
(HCR_EL2().TGE == '1' || MDCR_EL2().TDE == '1'));
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
var target_el : bits(2);
let vect_offset : integer = 0x0;
target_el = if (PSTATE.EL == EL2 || route_to_el2) then EL2 else EL1;
var except : ExceptionRecord;
if IsFeatureImplemented(FEAT_NV2) && fault.accessdesc.acctype ==
AccessType_NV2 then
except = AArch64_AbortSyndrome(Exception_NV2Watchpoint, fault, target_el);
else
except = AArch64_AbortSyndrome(Exception_Watchpoint, fault, target_el);
end;
AArch64_TakeException(target_el, except, preferred_exception_return,
vect_offset);
end;
## Library pseudocode for
aarch64/exceptions/exceptions/AArch64\_ExceptionClass
// AArch64_ExceptionClass // ======================== // Returns the Exception Class and Instruction Length fields to be reported in ESR
func AArch64_ExceptionClass(exceptype : Exception, target_el : bits(2)) => (integer,bit) begin
var il_is_valid : boolean = TRUE;
let from_32 : boolean = UsingAArch32();
var ec : integer;
case exceptype of
when Exception_Uncategorized => ec = 0x00; il_is_valid = FALSE;
when Exception_WFxTrap => ec = 0x01;
when Exception_CP15RTTrap => ec = 0x03; assert from_32;
when Exception_CP15RRTTrap => ec = 0x04; assert from_32;
when Exception_CP14RTTrap => ec = 0x05; assert from_32;
when Exception_CP14DTTrap => ec = 0x06; assert from_32;
when Exception_AdvSIMDFPAccessTrap => ec = 0x07;
when Exception_FPIDTrap => ec = 0x08;
when Exception_PACTrap => ec = 0x09;
when Exception_OtherTrap => ec = 0x0A;
when Exception_GPC => ec = 0x1E;
when Exception_ConditionalFault => ec = 0x0B;
when Exception_CP14RRTTrap => ec = 0x0C; assert from_32;
when Exception_BranchTarget => ec = 0x0D;
when Exception_IllegalState => ec = 0x0E; il_is_valid = FALSE;
when Exception_SupervisorCall => ec = if from_32 then 0x11 else 0x15;
when Exception_HypervisorCall => ec = if from_32 then 0x12 else 0x16;
when Exception_MonitorCall => ec = if from_32 then 0x13 else 0x17;
when Exception_SystemRegisterTrap => ec = 0x18; assert !from_32;
when Exception_SystemRegister128Trap => ec = 0x14; assert !from_32;
when Exception_SVEAccessTrap => ec = 0x19; assert !from_32;
when Exception_ERetTrap => ec = 0x1A; assert !from_32;
when Exception_PACFail => ec = 0x1C; assert !from_32;
when Exception_SMEAccessTrap => ec = 0x1D; assert !from_32;
when Exception_InstructionAbort =>
ec = if target_el == PSTATE.EL then 0x21 else 0x20;
il_is_valid = FALSE;
when Exception_PCAlignment => ec = 0x22; il_is_valid = FALSE;
when Exception_DataAbort => ec = if target_el == PSTATE.EL then 0x25 else 0x24;
when Exception_NV2DataAbort => ec = 0x25;
when Exception_SPAlignment => ec = 0x26; il_is_valid = FALSE; assert !from_32;
when Exception_MemCpyMemSet => ec = 0x27;
when Exception_GCSFail => ec = 0x2D; assert !from_32;
when Exception_FPTrappedException => ec = if from_32 then 0x28 else 0x2C;
when Exception_SError => ec = 0x2F; il_is_valid = FALSE;
when Exception_Breakpoint =>
ec = if target_el == PSTATE.EL then 0x31 else 0x30;
il_is_valid = FALSE;
when Exception_SoftwareStep =>
ec = if target_el == PSTATE.EL then 0x33 else 0x32;
il_is_valid = FALSE;
when Exception_Watchpoint =>
ec = if target_el == PSTATE.EL then 0x35 else 0x34;
il_is_valid = FALSE;
when Exception_NV2Watchpoint => ec = 0x35; il_is_valid = FALSE;
when Exception_SoftwareBreakpoint => ec = if from_32 then 0x38 else 0x3C;
when Exception_VectorCatch => ec = 0x3A; il_is_valid = FALSE; assert from_32;
when Exception_Profiling => ec = 0x3D;
otherwise => unreachable;
end;
var il : bit;
if il_is_valid then
il = if ThisInstrLength() == 32 then '1' else '0';
else
il = '1';
end;
assert from_32 || il == '1'; // AArch64 instructions always 32-bit
return (ec,il);
end;
## Library pseudocode for
aarch64/exceptions/exceptions/AArch64\_ReportException
// AArch64_ReportException // ========================= // Report syndrome information for exception taken to AArch64 state.
func AArch64_ReportException(except : ExceptionRecord, target_el : bits(2)) begin
let exceptype : Exception = except.exceptype;
var (ec,il) = AArch64_ExceptionClass(exceptype, target_el);
let iss : bits(25) = except.syndrome.iss;
let iss2 : bits(24) = except.syndrome.iss2;
// IL is not valid for Data Abort exceptions without valid instruction
syndrome information
if ec IN {0x24,0x25} && iss[24] == '0' then
il = '1';
end;
ESR_EL(target_el) = (Zeros{8} :: // [63:56]
iss2 :: // [55:32]
ec[5:0] :: // [31:26]
il :: // [25]
iss); // [24:0]
if exceptype IN {
Exception_InstructionAbort,
Exception_PCAlignment,
Exception_DataAbort,
Exception_NV2DataAbort,
Exception_NV2Watchpoint,
Exception_GPC,
Exception_Watchpoint
} then
FAR_EL(target_el) = except.vaddress;
else
FAR_EL(target_el) = ARBITRARY : bits(64);
end;
if except.ipavalid then
HPFAR_EL2()[NUM_PABITS-9:4] = except.ipaddress[NUM_PABITS-1:12];
if IsSecureEL2Enabled() && CurrentSecurityState() == SS_Secure then
HPFAR_EL2().NS = except.NS;
else
HPFAR_EL2().NS = '0';
end;
elsif target_el == EL2 then
HPFAR_EL2()[NUM_PABITS-9:4] = ARBITRARY : bits(NUM_PABITS-12);
end;
if except.pavalid then
var faultaddr : bits(64) = ZeroExtend{}(except.paddress.address);
if IsFeatureImplemented(FEAT_RME) then
case except.paddress.paspace of
when PAS_Secure => faultaddr[63:62] = '00';
when PAS_NonSecure => faultaddr[63:62] = '10';
when PAS_Root => faultaddr[63:62] = '01';
when PAS_Realm => faultaddr[63:62] = '11';
end;
if exceptype == Exception_GPC then
faultaddr[11:0] = Zeros{12};
end;
else
faultaddr[63] = if except.paddress.paspace == PAS_NonSecure then '1' else '0';
end;
PFAR_EL(target_el) = faultaddr;
elsif (IsFeatureImplemented(FEAT_PFAR) ||
(IsFeatureImplemented(FEAT_RME) && target_el == EL3)) then
PFAR_EL(target_el) = ARBITRARY : bits(64);
end;
return;
end;
## Library pseudocode for
aarch64/exceptions/exceptions/AArch64\_ResetControlRegisters
// AArch64_ResetControlRegisters // =============================== // Resets System registers and memory-mapped control registers that have architecturally-defined // reset values to those values.
impdef func AArch64_ResetControlRegisters(cold_reset : boolean) begin return; end;
## Library pseudocode for aarch64/exceptions/exceptions/AArch64\_TakeReset
// AArch64_TakeReset // =================== // Reset into AArch64 state
func AArch64_TakeReset(cold_reset : boolean) begin assert HaveAArch64();
// Enter the highest implemented Exception level in AArch64 state
PSTATE.nRW = '0';
if HaveEL(EL3) then
PSTATE.EL = EL3;
elsif HaveEL(EL2) then
PSTATE.EL = EL2;
else
PSTATE.EL = EL1;
end;
// Reset System registers and other system components
AArch64_ResetControlRegisters(cold_reset);
// Reset all other PSTATE fields
PSTATE.SP = '1'; // Select stack pointer
PSTATE.[D,A,I,F] = '1111'; // All asynchronous exceptions masked
PSTATE.SS = '0'; // Clear software step bit
PSTATE.DIT = '0'; // PSTATE.DIT is reset to 0 when resetting into AArch64
if IsFeatureImplemented(FEAT_PAuth_LR) then
PSTATE.PACM = '0'; // PAC modifier
end;
if IsFeatureImplemented(FEAT_SME) then
PSTATE.[SM,ZA] = '00'; // Disable Streaming SVE mode & ZA storage
ResetSMEState('0');
end;
if IsFeatureImplemented(FEAT_SSBS) then
PSTATE.SSBS = ImpDefBit("PSTATE.SSBS bit at reset");
end;
if IsFeatureImplemented(FEAT_GCS) then
PSTATE.EXLOCK = '0'; // PSTATE.EXLOCK is reset to 0 when resetting into AArch64
end;
if IsFeatureImplemented(FEAT_UINJ) then
PSTATE.UINJ = '0'; // PSTATE.UINJ is reset to 0 when resetting into AArch64
end;
PSTATE.IL = '0'; // Clear Illegal Execution state bit
// All registers, bits and fields not reset by the above pseudocode or by the
BranchTo() call
// below are UNKNOWN bitstrings after reset. In particular, the return
information registers
// ELR_ELx and SPSR_ELx have UNKNOWN values, so that it
// is impossible to return from a reset in an architecturally defined way.
AArch64_ResetGeneralRegisters();
if IsFeatureImplemented(FEAT_SME) || IsFeatureImplemented(FEAT_SVE) then
ResetSVERegisters();
else
AArch64_ResetSIMDFPRegisters();
end;
AArch64_ResetSpecialRegisters();
ResetExternalDebugRegisters(cold_reset);
var rv : bits(64); // IMPLEMENTATION DEFINED reset vector
if HaveEL(EL3) then
rv = RVBAR_EL3();
elsif HaveEL(EL2) then
rv = RVBAR_EL2();
else
rv = RVBAR_EL1();
end;
// The reset vector must be correctly aligned
let pamax : AddressSize = AArch64_PAMax();
assert IsZero(rv[63:pamax]) && IsZero(rv[1:0]);
let branch_conditional : boolean = FALSE;
EDPRSR().R = '0'; // Leaving Reset State.
BranchTo{64}(rv, BranchType_RESET, branch_conditional);
end;
## Library pseudocode for aarch64/exceptions/exceptions/GetESR\_ELx\_DFSC
// GetESR_ELx_DFSC // ================= // Query the ESR_ELx to get the DFSC field.
func GetESR_ELx_DFSC(el : bits(2)) => bits(6) begin let ec : bits(6) = ESR_EL(el).EC; assert ec IN {'10010x', '101111', '11010x'};
return ESR_EL(el)[5:0];
end;
## Library pseudocode for aarch64/exceptions/exceptions/GetESR\_ELx\_ExType
// GetESR_ELx_ExType // =================== // Query the ESR_ELx to get the ExType field.
func GetESR_ELx_ExType(el : bits(2)) => bits(4) begin let ec : bits(6) = ESR_EL(el).EC; assert ec == '101101';
return ESR_EL(el)[23:20];
end;
## Library pseudocode for aarch64/exceptions/exceptions/GetESR\_ELx\_IFSC
// GetESR_ELx_IFSC // ================= // Query the ESR_ELx to get the IFSC field.
func GetESR_ELx_IFSC(el : bits(2)) => bits(6) begin let ec : bits(6) = ESR_EL(el).EC; assert ec IN {'1100xx', '10000x'};
return ESR_EL(el)[5:0];
end;
## Library pseudocode for
aarch64/exceptions/ieeefp/AArch64\_FPTrappedException
// AArch64_FPTrappedException // ============================
func AArch64_FPTrappedException(is_ase : boolean, accumulated_exceptions : bits(8)) begin var except : ExceptionRecord = ExceptionSyndrome(Exception_FPTrappedException); if is_ase then if ImpDefBool("vector instructions set TFV to 1") then except.syndrome.iss[23] = '1'; // TFV else except.syndrome.iss[23] = '0'; // TFV end; else except.syndrome.iss[23] = '1'; // TFV end; except.syndrome.iss[10:8] = ARBITRARY : bits(3); // VECITR if except.syndrome.iss[23] == '1' then except.syndrome.iss[7,4:0] = accumulated_exceptions[7,4:0]; // IDF, IXF, UFF, OFF, DZF, IOF else except.syndrome.iss[7,4:0] = ARBITRARY : bits(6); end;
let route_to_el2 : boolean = PSTATE.EL == EL0 &&
EL2Enabled() && HCR_EL2().TGE == '1';
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let vect_offset : integer = 0x0;
if UInt(PSTATE.EL) > UInt(EL1) then
AArch64_TakeException(PSTATE.EL, except, preferred_exception_return, vect_offset);
elsif route_to_el2 then
AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset);
else
AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset);
end;
end;
## Library pseudocode for aarch64/exceptions/syscalls/AArch64\_CallHypervisor
// AArch64_CallHypervisor // ======================== // Performs a HVC call
func AArch64_CallHypervisor(immediate : bits(16)) begin assert HaveEL(EL2);
if UsingAArch32() then AArch32_ITAdvance(); end;
SSAdvance();
let preferred_exception_return : bits(64) = NextInstrAddr{}();
let vect_offset : integer{} = 0x0;
var except : ExceptionRecord = ExceptionSyndrome(Exception_HypervisorCall);
except.syndrome.iss[15:0] = immediate;
if IsFeatureImplemented(FEAT_PAuth_LR) then PSTATE.PACM = '0'; end;
if PSTATE.EL == EL3 then
AArch64_TakeException(EL3, except, preferred_exception_return, vect_offset);
else
AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset);
end;
end;
## Library pseudocode for
aarch64/exceptions/syscalls/AArch64\_CallSecureMonitor
// AArch64_CallSecureMonitor // ===========================
func AArch64_CallSecureMonitor(immediate : bits(16)) begin assert HaveEL(EL3) && (EL3); if UsingAArch32() then AArch32_ITAdvance(); end; HSAdvance(); SSAdvance(); let preferred_exception_return : bits(64) = NextInstrAddr{}(); let vect_offset : integer{} = 0x0;
var except : ExceptionRecord =
ExceptionSyndrome(Exception_MonitorCall);
except.syndrome.iss[15:0] = immediate;
if IsFeatureImplemented(FEAT_PAuth_LR) then PSTATE.PACM = '0'; end;
AArch64_TakeException(EL3, except, preferred_exception_return, vect_offset);
end;
## Library pseudocode for aarch64/exceptions/syscalls/AArch64\_CallSupervisor
// AArch64_CallSupervisor // ======================== // Calls the Supervisor
func AArch64_CallSupervisor(immediate : bits(16)) begin if UsingAArch32() then AArch32_ITAdvance(); end; SSAdvance(); let route_to_el2 : boolean = PSTATE.EL == EL0 && EL2Enabled() && HCR_EL2().TGE == '1';
let preferred_exception_return : bits(64) = NextInstrAddr{}();
let vect_offset : integer{} = 0x0;
var except : ExceptionRecord = ExceptionSyndrome(Exception_SupervisorCall);
except.syndrome.iss[15:0] = immediate;
if IsFeatureImplemented(FEAT_PAuth_LR) then PSTATE.PACM = '0'; end;
if UInt(PSTATE.EL) > UInt(EL1) then
AArch64_TakeException(PSTATE.EL, except, preferred_exception_return, vect_offset);
elsif route_to_el2 then
AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset);
else
AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset);
end;
end;
## Library pseudocode for
aarch64/exceptions/takeexception/AArch64\_TakeException
// AArch64_TakeException // ======================= // Take an exception to an Exception level using AArch64.
noreturn func AArch64_TakeException(target_el : bits(2), exception_in : ExceptionRecord, preferred_exception_return : bits(64), vect_offset_in : integer) begin assert HaveEL(target_el) && (target_el) && UInt(target_el) >= UInt(PSTATE.EL); if Halted() then AArch64_TakeExceptionInDebugState(target_el, exception_in); end; var except : ExceptionRecord = exception_in; var sync_errors : boolean; var iesb_req : boolean; if IsFeatureImplemented(FEAT_IESB) then sync_errors = EffectiveIESB(target_el) == '1' && except.exceptype != Exception_SError; if sync_errors && InsertIESBBeforeException(except.exceptype, target_el) then SynchronizeErrors(); iesb_req = FALSE; sync_errors = FALSE; TakeUnmaskedPhysicalSErrorInterrupts(iesb_req); end; else sync_errors = FALSE; end;
var brbe_source_allowed : boolean = FALSE;
var brbe_source_address : bits(64) = Zeros{};
if IsFeatureImplemented(FEAT_BRBE) then
brbe_source_allowed = BranchRecordAllowed(PSTATE.EL);
brbe_source_address = preferred_exception_return;
end;
if !IsFeatureImplemented(FEAT_ExS) || SCTLR_EL(target_el).EIS == '1' then
// Synchronize the context, including Instruction Fetch Barrier effect
SynchronizeContext();
elsif !(except.exceptype == Exception_SoftwareBreakpoint ||
(except.exceptype IN {Exception_SupervisorCall,
Exception_HypervisorCall,
Exception_MonitorCall} &&
!except.trappedsyscallinst)) then
InstructionFetchBarrier();
end;
// If coming from AArch32 state, the top parts of the X() registers might be
set to zero
let from_32 : boolean = UsingAArch32();
if from_32 then AArch64_MaybeZeroRegisterUppers(); end;
if from_32 && IsFeatureImplemented(FEAT_SME) && PSTATE.SM ==
'1' then
ResetSVEState();
else
MaybeZeroSVEUppers(target_el);
end;
var vect_offset : integer = vect_offset_in;
if UInt(target_el) > UInt(PSTATE.EL) then
var lower_32 : boolean;
if target_el == EL3 then
if EL2Enabled() then
lower_32 = ELUsingAArch32(EL2);
else
lower_32 = ELUsingAArch32(EL1);
end;
elsif IsInHost() && PSTATE.EL == EL0 && target_el == EL2 then
lower_32 = ELUsingAArch32(EL0);
else
lower_32 = ELUsingAArch32(target_el - 1);
end;
vect_offset = vect_offset + (if lower_32 then 0x600 else 0x400);
elsif PSTATE.SP == '1' then
vect_offset = vect_offset + 0x200;
end;
assert vect_offset < 2048;
let vect_base : bits(64) = VBAR_EL(target_el)[63:11]::Zeros{11};
let target_vector : bits(64) = vect_base + vect_offset;
var spsr : bits(64) = GetPSRFromPSTATE{}(AArch64_NonDebugState);
if PSTATE.EL == EL1 && target_el == EL1 && EL2Enabled() then
if EffectiveHCR_EL2_NVx() IN {'x01', '111'} then
spsr[3:2] = '10';
end;
end;
if IsFeatureImplemented(FEAT_BTI) && () then
var zero_btype : boolean;
// SPSR_ELx[].BTYPE is only guaranteed valid for these exception types
if except.exceptype IN {Exception_SError, Exception_IRQ, Exception_FIQ,
Exception_SoftwareStep, Exception_PCAlignment,
Exception_InstructionAbort, Exception_Breakpoint,
Exception_VectorCatch, Exception_SoftwareBreakpoint,
Exception_IllegalState, Exception_BranchTarget} then
zero_btype = FALSE;
else
zero_btype = ConstrainUnpredictableBool(Unpredictable_ZEROBTYPE);
end;
if zero_btype then spsr[11:10] = '00'; end;
end;
if (IsFeatureImplemented(FEAT_NV2) &&
except.exceptype == Exception_NV2DataAbort && target_el == EL3) then
// External aborts are configured to be taken to EL3
except.exceptype = Exception_DataAbort;
end;
if ! except.exceptype IN {Exception_IRQ, Exception_FIQ} then
AArch64_ReportException(except, target_el);
end;
if IsFeatureImplemented(FEAT_BRBE) then
BRBEException(except, brbe_source_allowed, brbe_source_address,
target_vector, target_el, except.trappedsyscallinst);
end;
if IsFeatureImplemented(FEAT_GCS) then
if PSTATE.EL == target_el then
if GetCurrentEXLOCKEN() then
PSTATE.EXLOCK = '1';
else
PSTATE.EXLOCK = '0';
end;
else
PSTATE.EXLOCK = '0';
end;
end;
PSTATE.EL = target_el;
PSTATE.nRW = '0';
PSTATE.SP = '1';
SPSR_ELx() = spsr;
ELR_ELx() = preferred_exception_return;
PSTATE.SS = '0';
if IsFeatureImplemented(FEAT_SSBS) then PSTATE.SSBS = SCTLR_ELx().DSSBS; end;
if (IsFeatureImplemented(FEAT_EBEP) || IsFeatureImplemented(FEAT_SPE_EXC) ||
IsFeatureImplemented(FEAT_TRBE_EXC)) then
PSTATE.PM = '1';
end;
if IsFeatureImplemented(FEAT_NMI) then
PSTATE.ALLINT = NOT SCTLR_ELx().SPINTMASK;
end;
PSTATE.[D,A,I,F] = '1111';
if IsFeatureImplemented(FEAT_MTE) then PSTATE.TCO = '1'; end;
PSTATE.IL = '0';
if IsFeatureImplemented(FEAT_UAO) then PSTATE.UAO = '0'; end;
if IsFeatureImplemented(FEAT_UINJ) then PSTATE.UINJ = '0'; end;
if IsFeatureImplemented(FEAT_PAuth_LR) then PSTATE.PACM = '0'; end;
if IsFeatureImplemented(FEAT_PAN) && SCTLR_ELx().SPAN == '0' then
if PSTATE.EL == EL1 then
PSTATE.PAN = '1';
elsif PSTATE.EL == EL2 && ELIsInHost(EL0) then
PSTATE.PAN = '1';
elsif (PSTATE.EL == EL2 && ELIsInHost(EL2) &&
(IsFeatureImplemented(FEAT_NV3) ||
ImpDefBool("Set PAN as 1 when E2H,TGE is '10'"))) then
PSTATE.PAN = '1';
end;
end;
if from_32 then // Coming from AArch32
PSTATE.IT = '00000000';
PSTATE.T = '0'; // PSTATE.J is RES0
end;
if IsFeatureImplemented(FEAT_BTI) then PSTATE.BTYPE = '00'; end;
let branch_conditional : boolean = FALSE;
BranchTo{64}(target_vector, BranchType_EXCEPTION, branch_conditional);
CheckExceptionCatch(TRUE); // Check for debug event on exception entry
if sync_errors then
SynchronizeErrors();
iesb_req = TRUE;
TakeUnmaskedPhysicalSErrorInterrupts(iesb_req);
end;
EndOfInstruction(EndOfInstructionReason_Exception);
end;
## Library pseudocode for
aarch64/exceptions/traps/AArch64\_AArch32SystemAccessTrap
// AArch64_AArch32SystemAccessTrap // ================================= // Trapped AArch32 System register access.
func AArch64_AArch32SystemAccessTrap(target_el : bits(2), ec : integer) begin assert HaveEL(target_el) && target_el != EL0 && UInt(target_el) >= UInt(PSTATE.EL);
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let vect_offset : integer = 0x0;
let except : ExceptionRecord =
AArch64_AArch32SystemAccessTrapSyndrome(ThisInstr(), ec);
AArch64_TakeException(target_el, except, preferred_exception_return,
vect_offset);
end;
## Library pseudocode for
aarch64/exceptions/traps/AArch64\_AArch32SystemAccessTrapSyndrome
// AArch64_AArch32SystemAccessTrapSyndrome // ========================================= // Returns the syndrome information for traps on AArch32 MCR, MCRR, MRC, MRRC, and VMRS, // VMSR instructions, other than traps that are due to HCPTR or CPACR.
func AArch64_AArch32SystemAccessTrapSyndrome(instr : bits(32), ec : integer) => ExceptionRecord begin var except : ExceptionRecord;
case ec of
when 0x0 => except = ExceptionSyndrome(Exception_Uncategorized);
when 0x3 => except = ExceptionSyndrome(Exception_CP15RTTrap);
when 0x4 => except = ExceptionSyndrome(Exception_CP15RRTTrap);
when 0x5 => except = ExceptionSyndrome(Exception_CP14RTTrap);
when 0x6 => except = ExceptionSyndrome(Exception_CP14DTTrap);
when 0x7 => except = ExceptionSyndrome(Exception_AdvSIMDFPAccessTrap);
when 0x8 => except = ExceptionSyndrome(Exception_FPIDTrap);
when 0xC => except = ExceptionSyndrome(Exception_CP14RRTTrap);
otherwise => unreachable;
end;
var iss : bits(20) = Zeros{};
if except.exceptype == Exception_Uncategorized then
return except;
elsif except.exceptype IN {Exception_FPIDTrap, Exception_CP14RTTrap,
Exception_CP15RTTrap} then
// Trapped MRC/MCR, VMRS on FPSID
if except.exceptype != Exception_FPIDTrap then // When trap is not for VMRS
iss[19:17] = instr[7:5]; // opc2
iss[16:14] = instr[23:21]; // opc1
iss[13:10] = instr[19:16]; // CRn
iss[4:1] = instr[3:0]; // CRm
else
iss[19:17] = '000';
iss[16:14] = '111';
iss[13:10] = instr[19:16]; // reg
iss[4:1] = '0000';
end;
if instr[20] == '1' && instr[15:12] == '1111' then // MRC, Rt==15
iss[9:5] = '11111';
elsif instr[20] == '0' && instr[15:12] == '1111' then // MCR, Rt==15
iss[9:5] = ARBITRARY : bits(5);
else
iss[9:5] = LookUpRIndex(UInt(instr[15:12]), PSTATE.M)[4:0];
end;
elsif except.exceptype IN {Exception_CP14RRTTrap,
Exception_AdvSIMDFPAccessTrap,
Exception_CP15RRTTrap} then
// Trapped MRRC/MCRR, VMRS/VMSR
iss[19:16] = instr[7:4]; // opc1
if instr[19:16] == '1111' then // Rt2==15
iss[14:10] = ARBITRARY : bits(5);
else
iss[14:10] = LookUpRIndex(UInt(instr[19:16]), PSTATE.M)[4:0];
end;
if instr[15:12] == '1111' then // Rt==15
iss[9:5] = ARBITRARY : bits(5);
else
iss[9:5] = LookUpRIndex(UInt(instr[15:12]), PSTATE.M)[4:0];
end;
iss[4:1] = instr[3:0]; // CRm
elsif except.exceptype == Exception_CP14DTTrap then
// Trapped LDC/STC
iss[19:12] = instr[7:0]; // imm8
iss[4] = instr[23]; // U
iss[2:1] = instr[24,21]; // P,W
if instr[19:16] == '1111' then // Rn==15, LDC(Literal addressing)/STC
iss[9:5] = ARBITRARY : bits(5);
iss[3] = '1';
end;
end;
iss[0] = instr[20]; // Direction
except.syndrome.iss[24:20] = ConditionSyndrome();
except.syndrome.iss[19:0] = iss;
return except;
end;
## Library pseudocode for
aarch64/exceptions/traps/AArch64\_AArch32SystemAccessTraptoEL1orEL2
// AArch64_AArch32SystemAccessTraptoEL1orEL2 // =========================================== // Trapped access to AArch32 System register or system instruction from EL0. // The trap is taken to EL1, or to EL2 if HCR_EL2().TGE is 1.
func AArch64_AArch32SystemAccessTraptoEL1orEL2(ec : integer) begin assert PSTATE.EL == EL0; let target_el : bits(2) = if EL2Enabled() && HCR_EL2().TGE == '1' then EL2 else EL1;
AArch64_AArch32SystemAccessTrap(target_el, ec);
end;
## Library pseudocode for
aarch64/exceptions/traps/AArch64\_AdvSIMDFPAccessTrap
// AArch64_AdvSIMDFPAccessTrap // ============================= // Trapped access to Advanced SIMD or FP registers due to CPACR.
func AArch64_AdvSIMDFPAccessTrap(target_el : bits(2)) begin let preferred_exception_return : bits(64) = ThisInstrAddr{}(); var except : ExceptionRecord; let vect_offset : integer = 0x0;
let route_to_el2 : boolean = (target_el == EL1 &&
EL2Enabled() && HCR_EL2().TGE == '1');
if route_to_el2 then
except = ExceptionSyndrome(Exception_Uncategorized);
AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset);
else
except = ExceptionSyndrome(Exception_AdvSIMDFPAccessTrap);
except.syndrome.iss[24:20] = ConditionSyndrome();
AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;
return;
end;
## Library pseudocode for
aarch64/exceptions/traps/AArch64\_CheckCP15InstrCoarseTraps
// AArch64_CheckCP15InstrCoarseTraps // =================================== // Check for coarse-grained AArch32 traps to System registers in the // coproc=0b1111 encoding space by HSTR_EL2, HCR_EL2, and SCTLR_ELx.
func AArch64_CheckCP15InstrCoarseTraps(CRn : integer, nreg : integer, CRm : integer) begin let trapped_encoding : boolean = ((CRn == 9 && CRm IN {0,1,2, 5,6,7,8 }) || (CRn == 10 && CRm IN {0,1, 4, 8 }) || (CRn == 11 && CRm IN {0,1,2,3,4,5,6,7,8,15}));
// Check for MRC and MCR disabled by SCTLR_EL1.TIDCP.
if (IsFeatureImplemented(FEAT_TIDCP1) && PSTATE.EL == EL0 &&
() &&
(EL1) && SCTLR_EL1().TIDCP == '1' && trapped_encoding) then
if EL2Enabled() && HCR_EL2().TGE == '1' then
AArch64_AArch32SystemAccessTrap(EL2, 0x3);
else
AArch64_AArch32SystemAccessTrap(EL1, 0x3);
end;
end;
// Check for coarse-grained Hyp traps
if PSTATE.EL IN {EL0, EL1} && EL2Enabled() then
// Check for MRC and MCR disabled by SCTLR_EL2.TIDCP.
if (IsFeatureImplemented(FEAT_TIDCP1) && PSTATE.EL == EL0 && IsInHost() &&
SCTLR_EL2().TIDCP == '1' && trapped_encoding) then
AArch64_AArch32SystemAccessTrap(EL2, 0x3);
end;
let major : integer = if nreg == 1 then CRn else CRm;
// Check for MCR, MRC, MCRR, and MRRC disabled by HSTR_EL2().CRn/HSTR().CRm
// and MRC and MCR disabled by HCR_EL2.TIDCP.
if ((() && ! major IN {4,14} && HSTR_EL2()[major] == '1') ||
(HCR_EL2().TIDCP == '1' && nreg == 1 && trapped_encoding)) then
if (PSTATE.EL == EL0 &&
ImpDefBool("UNDEF unallocated CP15 access at EL0")) then
Undefined();
end;
AArch64_AArch32SystemAccessTrap(EL2, 0x3);
end;
end;
end;
## Library pseudocode for
aarch64/exceptions/traps/AArch64\_CheckFPAdvSIMDEnabled
// AArch64_CheckFPAdvSIMDEnabled // ===============================
func AArch64_CheckFPAdvSIMDEnabled begin AArch64_CheckFPEnabled(); // Check for illegal use of Advanced // SIMD in Streaming SVE Mode if IsFeatureImplemented(FEAT_SME) && PSTATE.SM == '1' && () then SMEAccessTrap(SMEExceptionType_Streaming, PSTATE.EL); end; end;
## Library pseudocode for aarch64/exceptions/traps/AArch64\_CheckFPAdvSIMDTrap
// AArch64_CheckFPAdvSIMDTrap // ============================ // Check against CPTR_EL2 and CPTR_EL3.
func AArch64_CheckFPAdvSIMDTrap begin if HaveEL(EL3) && CPTR_EL3().TFP == '1' && EL3SDDUndefPriority() then Undefined(); end;
if PSTATE.EL IN {EL0, EL1, EL2} && EL2Enabled() then
// Check if access disabled in CPTR_EL2
if ELIsInHost(EL2) then
var disabled : boolean;
case CPTR_EL2().FPEN of
when 'x0' => disabled = TRUE;
when '01' => disabled = PSTATE.EL == EL0 && HCR_EL2().TGE == '1';
when '11' => disabled = FALSE;
end;
if disabled then AArch64_AdvSIMDFPAccessTrap(EL2); end;
else
if CPTR_EL2().TFP == '1' then AArch64_AdvSIMDFPAccessTrap(EL2); end;
end;
end;
if HaveEL(EL3) then
// Check if access disabled in CPTR_EL3
if CPTR_EL3().TFP == '1' then
if EL3SDDUndef() then
Undefined();
else
AArch64_AdvSIMDFPAccessTrap(EL3);
end;
end;
end;
end;
## Library pseudocode for aarch64/exceptions/traps/AArch64\_CheckFPEnabled
// AArch64_CheckFPEnabled // ======================== // Check against CPACR
func AArch64_CheckFPEnabled begin if PSTATE.EL IN {EL0, EL1} && () then // Check if access disabled in CPACR_EL1 var disabled : boolean; case CPACR_EL1().FPEN of when 'x0' => disabled = TRUE; when '01' => disabled = PSTATE.EL == EL0; when '11' => disabled = FALSE; end; if disabled then AArch64_AdvSIMDFPAccessTrap(EL1); end; end;
AArch64_CheckFPAdvSIMDTrap(); // Also check against CPTR_EL2 and
CPTR_EL3
end;
## Library pseudocode for aarch64/exceptions/traps/AArch64\_CheckForERetTrap
// AArch64_CheckForERetTrap // ========================== // Check for trap on ERET, ERETAA, ERETAB instruction
func AArch64_CheckForERetTrap(eret_with_pac : boolean, pac_uses_key_a : boolean) begin if PSTATE.EL == EL1 && EL2Enabled() then var route_to_el2 : boolean = FALSE;
// Check for a fine-grained trap by the hypervisor.
if (IsFeatureImplemented(FEAT_FGT) && ((EL3) || SCR_EL3().FGTEn == '1') &&
HFGITR_EL2().ERET == '1') then
route_to_el2 = TRUE;
// Check for a trap by the Effective value of the HCR_EL2.NV bit
elsif EffectiveHCR_EL2_NVx()[0] == '1' then
// Check for a trap by NVHCR_EL2.TGE based on the SPSR_EL1().M[3:2] value
if EffectiveHCRX_EL2_NVTGE() == '1' then
route_to_el2 = NVHCR_EL2().TGE == '0' && SPSR_EL1()[3:2] == '0x';
else
route_to_el2 = TRUE;
end;
end;
if route_to_el2 then
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let vect_offset : integer = 0x0;
var except : ExceptionRecord = ExceptionSyndrome(Exception_ERetTrap);
if !eret_with_pac then // ERET
except.syndrome.iss[1] = '0';
except.syndrome.iss[0] = '0'; // RES0
else
except.syndrome.iss[1] = '1';
except.syndrome.iss[0] = if pac_uses_key_a then '0' else '1';
end;
AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset);
end;
end;
return;
end;
## Library pseudocode for
aarch64/exceptions/traps/AArch64\_CheckForSMCUndefOrTrap
// AArch64_CheckForSMCUndefOrTrap // ================================ // Check for UNDEFINED or trap on SMC instruction
func AArch64_CheckForSMCUndefOrTrap(imm : bits(16)) begin if PSTATE.EL == EL0 then Undefined(); end; if (!(PSTATE.EL == EL1 && EL2Enabled() && HCR_EL2().TSC == '1') && HaveEL(EL3) && SCR_EL3().SMD == '1') then Undefined(); end; var route_to_el2 : boolean = FALSE; if (EL3) then if (PSTATE.EL == EL1 && EL2Enabled() && HCR_EL2().TSC == '1' && (EffectiveHCR_EL2_NVx() == 'xx1' || (ImpDefBool("Trap SMC execution at EL1 to EL2")))) then route_to_el2 = TRUE; else Undefined(); end; else route_to_el2 = PSTATE.EL == EL1 && EL2Enabled() && HCR_EL2().TSC == '1'; end; if route_to_el2 then let preferred_exception_return : bits(64) = ThisInstrAddr{}(); let vect_offset : integer = 0x0; var except : ExceptionRecord = ExceptionSyndrome(Exception_MonitorCall); except.syndrome.iss[15:0] = imm; except.trappedsyscallinst = TRUE; AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset); end; end;
## Library pseudocode for aarch64/exceptions/traps/AArch64\_CheckForSVCTrap
// AArch64_CheckForSVCTrap // ========================= // Check for trap on SVC instruction
func AArch64_CheckForSVCTrap(immediate : bits(16)) begin if IsFeatureImplemented(FEAT_FGT) then var route_to_el2 : boolean = FALSE; if PSTATE.EL == EL0 then route_to_el2 = (() && (EL1) && EL2Enabled() && HFGITR_EL2().SVC_EL0 == '1' && (() && ((EL3) || SCR_EL3().FGTEn == '1')));
elsif PSTATE.EL == EL1 then
route_to_el2 = (EL2Enabled() && HFGITR_EL2().SVC_EL1 == '1' &&
((EL3) || SCR_EL3().FGTEn == '1'));
end;
if route_to_el2 then
var except : ExceptionRecord = ExceptionSyndrome(Exception_SupervisorCall);
except.syndrome.iss[15:0] = immediate;
except.trappedsyscallinst = TRUE;
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let vect_offset : integer = 0x0;
AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset);
end;
end;
end;
## Library pseudocode for aarch64/exceptions/traps/AArch64\_CheckForWFxTrap
// AArch64_CheckForWFxTrap // ========================= // Checks for a trap on a WFE, WFET, WFI or WFIT instruction.
func AArch64_CheckForWFxTrap(wfxtype : WFxType) => (boolean, bits(2)) begin let is_wfe : boolean = wfxtype IN {WFxType_WFE, WFxType_WFET}; var target_el : bits(2); var trap : boolean = FALSE;
if HaveEL(EL3) && EL3SDDUndefPriority() &&
PSTATE.EL != EL3 then
// Check for traps described by the Secure Monitor.
// If the trap is enabled, the instruction will be UNDEFINED because EDSCR.SDD is 1.
trap = (if is_wfe then SCR_EL3().TWE else SCR_EL3().TWI) == '1';
target_el = EL3;
end;
if !trap && PSTATE.EL == EL0 then
// Check for traps described by the OS which may be EL1 or EL2.
trap = (if is_wfe then SCTLR_ELx().nTWE else SCTLR_ELx().nTWI) == '0';
target_el = EL1;
end;
if !trap && PSTATE.EL IN {EL0, EL1} && EL2Enabled() &&
() then
// Check for traps described by the Hypervisor.
trap = (if is_wfe then HCR_EL2().TWE else HCR_EL2().TWI) == '1';
target_el = EL2;
end;
if !trap && HaveEL(EL3) && PSTATE.EL != EL3 then
// Check for traps described by the Secure Monitor.
trap = (if is_wfe then SCR_EL3().TWE else SCR_EL3().TWI) == '1';
target_el = EL3;
end;
return (trap, target_el);
end;
## Library pseudocode for aarch64/exceptions/traps/AArch64\_CheckIllegalState
// AArch64_CheckIllegalState // =========================== // Check PSTATE.IL bit and generate Illegal Execution state exception if set.
func AArch64_CheckIllegalState begin if PSTATE.IL == '1' then let route_to_el2 : boolean = PSTATE.EL == EL0 && EL2Enabled() && HCR_EL2().TGE == '1';
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let vect_offset : integer = 0x0;
let except : ExceptionRecord = ExceptionSyndrome(Exception_IllegalState);
if UInt(PSTATE.EL) > UInt(EL1) then
------------------------------------------------------------------------------
Page 1 of 1.
End of thread.