Shared pseudocode from the offline Arm documentation snapshot. Part 11 of 36.
assert size >= TAG_GRANULE; end; let vaddress : bits(64) = AlignDownSize{}(regval, size);let accdesc : AccessDescriptor = CreateAccDescDCZero(cachetype);
if cachetype != CacheType_Data then AArch64_WriteTagMem(regval, cachetype, accdesc, size); end;
if cachetype IN {CacheType_Data, CacheType_Data_Tag} then AArch64_DataMemZero(regval, vaddress, accdesc, size); end; return;
end;
## Library pseudocode for aarch64/functions/dc/AArch64\_TreatDCAsNOP
// AArch64_TreatDCAsNOP // ====================== // Determines whether the execution of the DC instruction is treated as a NOP.
func AArch64_TreatDCAsNOP(cachetype : CacheType, cacheop : CacheOp, opscope : CacheOpScope) => boolean begin // DC to PoU: IMPLEMENTATION DEFINED - treated as NOP if LoUU and LoUIS are 0 if opscope == CacheOpScope_PoU && CLIDR_EL1().LoUU == '000' && CLIDR_EL1().LoUIS == '000' then return ImpDefBool("DC to PoU is treated as a NOP"); end;
// DC to PoC: IMPLEMENTATION DEFINED - treated as NOP if LoC is 0 if opscope == CacheOpScope_PoC && CLIDR_EL1().LoC == '000' then return ImpDefBool("DC to PoC is treated as a NOP"); end;// DC to PoP: IMPLEMENTATION DEFINED - treated as NOP if LoC is 0 and PoP unsupported if (opscope == CacheOpScope_PoP && CLIDR_EL1().LoC == '000' && !ImpDefBool("Memory system supports PoP")) then return ImpDefBool("DC to PoP is treated as a NOP"); end;
// DC to PoDP: IMPLEMENTATION DEFINED - treated as NOP if LoC is 0 and PoP/PoDP unsupported if (opscope == CacheOpScope_PoDP && CLIDR_EL1().LoC == '000' && !ImpDefBool("Memory system supports PoP") && !ImpDefBool("Memory system supports PoDP")) then return ImpDefBool("DC to PoDP is treated as a NOP"); end;
// DC operating on Allocation tags: IMPLEMENTATION DEFINED - treated as NOP // if FEAT_MTE is implemented and FEAT_MTE2 is not implemented if cachetype == CacheType_Tag && !IsFeatureImplemented(FEAT_MTE2) then return ImpDefBool("DC on Allocation tags without FEAT_MTE2 is treated as a NOP"); end;
return FALSE;
end;
## Library pseudocode for aarch64/functions/dc/MemZero
// MemZero block size // ==================
constant MAX_ZERO_BLOCK_SIZE : integer = 2048;
## Library pseudocode for aarch64/functions/eret/AArch64\_ExceptionReturn
// AArch64_ExceptionReturn // =========================
func AArch64_ExceptionReturn(new_pc_in : bits(64), spsr : bits(64)) begin var new_pc : bits(64) = new_pc_in;
if IsFeatureImplemented(FEAT_IESB) then var sync_errors : boolean = SCTLR_ELx().IESB == '1'; if IsFeatureImplemented(FEAT_DoubleFault) then sync_errors = sync_errors || (SCR_EL3().[EA,NMEA] == '11' && PSTATE.EL == EL3); end; if sync_errors then SynchronizeErrors(); // If FEAT_IESBv1p1 is implemented and an implicit error synchronization barrier // on exception return generates an SError exception, the resulting ESR_ELx.IESB is // set to 0. Otherwise, the value is an IMPLEMENTATION DEFINED choice of 0 or 1. let iesb_req : boolean = (!IsFeatureImplemented(FEAT_IESBv1p1) && ImpDefBool( "ESR_ELx.IESB is 1 after Implicit Error Synchronization on exception return")); TakeUnmaskedPhysicalSErrorInterrupts(iesb_req); end; 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 = PC64(); end;
if !IsFeatureImplemented(FEAT_ExS) || SCTLR_ELx().EOS == '1' then SynchronizeContext(); end;
// Attempts to change to an illegal state will invoke the Illegal Execution state mechanism let source_el : bits(2) = PSTATE.EL; let illegal_psr_state : boolean = IllegalExceptionReturn{64}(spsr); SetPSTATEFromPSR{64}(spsr, illegal_psr_state); ClearExclusiveLocal(ProcessorID()); SendEventLocal();
if illegal_psr_state && spsr[4] == '1' then // If the exception return is illegal, PC[63:32,1:0] are UNKNOWN new_pc[63:32] = ARBITRARY : bits(32); new_pc[1:0] = ARBITRARY : bits(2); elsif UsingAArch32() then // Return to AArch32 // ELR_ELx[1:0] or ELR_ELx[0] are treated as being 0, depending on the // target instruction set state if PSTATE.T == '1' then new_pc[0] = '0'; // T32 else new_pc[1:0] = '00'; // A32 end; else // Return to AArch64 // ELR_ELx[63:56] might include a tag new_pc = AArch64_BranchAddr(new_pc, PSTATE.EL); end;
if IsFeatureImplemented(FEAT_BRBE) then BRBEExceptionReturn(new_pc, source_el, brbe_source_allowed, brbe_source_address); end;
if UsingAArch32() then if IsFeatureImplemented(FEAT_SME) && PSTATE.SM == '1' then ResetSVEState(); end;
// 32 most significant bits are ignored.let branch_conditional : boolean = FALSE;BranchTo{32}(new_pc[31:0], BranchType_ERET, branch_conditional);else BranchToAddr{64}(new_pc, BranchType_ERET); end;
CheckExceptionCatch(FALSE); // Check for debug event on exception return
end;
## Library pseudocode for aarch64/functions/exclusive/AArch64\_ExclusiveMonitorsPass
// AArch64_ExclusiveMonitorsPass // =============================== // Return TRUE if the Exclusives monitors for the current PE include all of the addresses // associated with the virtual address region of size bytes starting at address. // The immediately following memory write must be to the same addresses.
// It is IMPLEMENTATION DEFINED whether the detection of memory aborts happens // before or after the check on the local Exclusives monitor. As a result a failure // of the local monitor can occur on some implementations even if the memory // access would give a memory abort.
func AArch64_ExclusiveMonitorsPass(address : bits(64), size : integer{1, 2, 4, 8, 16, 32}, accdesc : AccessDescriptor) => boolean begin let aligned : boolean = IsAlignedSize(address, size);
if !aligned && AArch64_UnalignedAccessFaults(accdesc, address, size) then let fault : FaultRecord = AlignmentFault(accdesc, address); AArch64_Abort(fault); end;if (address, ProcessorID(), size) then return FALSE; end;
let memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(address, accdesc, aligned, size);
// Check for aborts or debug exceptions if IsFault(memaddrdesc) then AArch64_Abort(memaddrdesc.fault); end;
var passed : boolean = IsExclusiveLocal(memaddrdesc.paddress, ProcessorID(), size); ClearExclusiveLocal(ProcessorID());
if passed && memaddrdesc.memattrs.shareability != Shareability_NSH then passed = IsExclusiveGlobal(memaddrdesc.paddress, ProcessorID(), size); end;
return passed;
end;
## Library pseudocode for aarch64/functions/exclusive/AArch64\_IsExclusiveVA
// AArch64_IsExclusiveVA // ======================= // An optional IMPLEMENTATION DEFINED test for an exclusive access to a virtual // address region of size bytes starting at address. // // It is permitted (but not required) for this function to return FALSE and // cause a store exclusive to fail if the virtual address region is not // totally included within the region recorded by MarkExclusiveVA(). // // It is always safe to return TRUE which will check the physical address only.
impdef func AArch64_IsExclusiveVA(address : bits(64), processorid : integer, size : integer) => boolean begin return TRUE; end;
## Library pseudocode for aarch64/functions/exclusive/AArch64\_MarkExclusiveVA
// AArch64_MarkExclusiveVA // ========================= // Optionally record an exclusive access to the virtual address region of size bytes // starting at address for processorid.
func AArch64_MarkExclusiveVA(address : bits(64), processorid : integer, size : integer) begin return; end;
## Library pseudocode for aarch64/functions/exclusive/AArch64\_SetExclusiveMonitors
// AArch64_SetExclusiveMonitors // ============================== // Sets the Exclusives monitors for the current PE to record the addresses associated // with the virtual address region of size bytes starting at address.
func AArch64_SetExclusiveMonitors(address : bits(64), size : integer{1, 2, 4, 8, 16, 32}, accdesc : AccessDescriptor) begin let aligned : boolean = IsAlignedSize(address, size);
if !aligned && AArch64_UnalignedAccessFaults(accdesc, address, size) then let fault : FaultRecord = AlignmentFault(accdesc, address); AArch64_Abort(fault); end;let memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(address, accdesc, aligned, size);
// Check for aborts or debug exceptions if IsFault(memaddrdesc) then return; end;
if memaddrdesc.memattrs.shareability != Shareability_NSH then MarkExclusiveGlobal(memaddrdesc.paddress, ProcessorID(), size); end;
MarkExclusiveLocal(memaddrdesc.paddress, ProcessorID(), size);
AArch64_MarkExclusiveVA(address, ProcessorID(), size);
end;
## Library pseudocode for aarch64/functions/extendreg/DecodeRegExtend
// DecodeRegExtend // ================= // Decode a register extension option
func DecodeRegExtend(op : bits(3)) => ExtendType begin case op of when '000' => return ExtendType_UXTB; when '001' => return ExtendType_UXTH; when '010' => return ExtendType_UXTW; when '011' => return ExtendType_UXTX; when '100' => return ExtendType_SXTB; when '101' => return ExtendType_SXTH; when '110' => return ExtendType_SXTW; when '111' => return ExtendType_SXTX; end; end;
## Library pseudocode for aarch64/functions/extendreg/ExtendReg
// ExtendReg // =========== // Perform a register extension and shift
func ExtendReg{N}(reg : integer, exttype : ExtendType, shift : integer{0..4}) => bits(N) begin let val : bits(N) = X{}(reg); var unsigned : boolean; var len : ESize;
case exttype of when ExtendType_SXTB => unsigned = FALSE; len = 8; when ExtendType_SXTH => unsigned = FALSE; len = 16; when ExtendType_SXTW => unsigned = FALSE; len = 32; when ExtendType_SXTX => unsigned = FALSE; len = 64; when ExtendType_UXTB => unsigned = TRUE; len = 8; when ExtendType_UXTH => unsigned = TRUE; len = 16; when ExtendType_UXTW => unsigned = TRUE; len = 32; when ExtendType_UXTX => unsigned = TRUE; len = 64; end;
// Sign or zero extend bottom LEN bits of register and shift left by SHIFT let nbits : integer{} = Min(len, N) as integer{8..N}; let extval : bits(N) = Extend{}(val[nbits-1:0], unsigned); return LSL(extval, shift);
end;
## Library pseudocode for aarch64/functions/extendreg/ExtendType
// ExtendType // ========== // AArch64 register extend and shift.
type ExtendType of enumeration {ExtendType_SXTB, ExtendType_SXTH, ExtendType_SXTW, ExtendType_SXTX, ExtendType_UXTB, ExtendType_UXTH, ExtendType_UXTW, ExtendType_UXTX};
## Library pseudocode for aarch64/functions/fpconvop/FPConvOp
// FPConvOp // ======== // Floating-point convert/move instruction types.
type FPConvOp of enumeration {FPConvOp_CVT_FtoI, FPConvOp_CVT_ItoF, FPConvOp_MOV_FtoI, FPConvOp_MOV_ItoF, FPConvOp_CVT_FtoI_JS };
## Library pseudocode for aarch64/functions/fpmaxminop/FPMaxMinOp
// FPMaxMinOp // ========== // Floating-point min/max instruction types.
type FPMaxMinOp of enumeration {FPMaxMinOp_MAX, FPMaxMinOp_MIN, FPMaxMinOp_MAXNUM, FPMaxMinOp_MINNUM};
## Library pseudocode for aarch64/functions/fpmr/CheckFPMREnabled
// CheckFPMREnabled // ================== // Check for Undefined instruction exception on indirect FPMR accesses.
func CheckFPMREnabled begin assert IsFeatureImplemented(FEAT_FPMR);
if PSTATE.EL == EL0 then if () then if SCTLR_EL1().EnFPM == '0' then Undefined(); end; else if SCTLR_EL2().EnFPM == '0' then Undefined(); end; end; end;if PSTATE.EL IN {EL0, EL1} && EL2Enabled() && () then if () || HCRX_EL2().EnFPM == '0' then Undefined(); end; end;
if PSTATE.EL != EL3 && HaveEL(EL3) then if SCR_EL3().EnFPM == '0' then Undefined(); end; end;
end;
## Library pseudocode for aarch64/functions/fpscale/FPClampScale
// FPClampScale // ==============
func FPClampScale{N}(op : bits(N), scale_in : integer) => integer begin assert N IN {16,32,64}; var E : integer; var exp : integer; case N of when 16 => E = 5; exp = UInt(op[14:10]); when 32 => E = 8; exp = UInt(op[30:23]); when 64 => E = 11; exp = UInt(op[62:52]); otherwise => unreachable; end;
let F : integer = N - (E + 1); let emax : integer = (1 << E) - 1; let min_scale : integer = -(F + 1); let max_scale : integer = emax + (F + 1);
let scale : integer = Max(min_scale - exp, Min(scale_in, max_scale - exp)); return scale;
end;
## Library pseudocode for aarch64/functions/fpscale/FPScale
// FPScale // =========
func FPScale{N}(op : bits(N), scale : integer, fpcr : FPCR_Type) => bits(N) begin assert N IN {16,32,64}; var result : bits(N); let (fptype,sign,value) : (FPType, bit, real) = FPUnpack{N}(op, fpcr);
if fptype == FPType_SNaN || fptype == FPType_QNaN then result = FPProcessNaN{N}(fptype, op, fpcr);elsif fptype == FPType_Zero then result = FPZero{N}(sign);elsif fptype == FPType_Infinity then result = FPInfinity{N}(sign);else let clamped_scale : integer = FPClampScale{N}(op, scale); result = FPRound{N}(value * (2.0^clamped_scale), fpcr); FPProcessDenorm(fptype, N, fpcr);end;return result;
end;
## Library pseudocode for aarch64/functions/fpunaryop/FPUnaryOp
// FPUnaryOp // ========= // Floating-point unary instruction types.
type FPUnaryOp of enumeration {FPUnaryOp_ABS, FPUnaryOp_MOV, FPUnaryOp_NEG, FPUnaryOp_SQRT};
## Library pseudocode for aarch64/functions/fusedrstep/FPRSqrtStepFused
// FPRSqrtStepFused // ==================
func FPRSqrtStepFused{N}(op1_in : bits(N), op2 : bits(N), fpcr_in : FPCR_Type) => bits(N) begin assert N IN {16, 32, 64}; var fpcr : FPCR_Type = fpcr_in; var result : bits(N); var op1 : bits(N) = op1_in; var done : boolean; op1 = FPNeg{N}(op1, fpcr); let altfp : boolean = IsFeatureImplemented(FEAT_AFP) && fpcr.AH == '1'; let fpexc : boolean = !altfp; // Generate no floating-point exceptions if altfp then fpcr.[FIZ,FZ] = '11'; end; // Flush denormal input and output to zero if altfp then fpcr.RMode = '00'; end; // Use RNE rounding mode
let (type1,sign1,value1) : (FPType, bit, real) = FPUnpack{N}(op1, fpcr, fpexc); let (type2,sign2,value2) : (FPType, bit, real) = FPUnpack{N}(op2, fpcr, fpexc); (done,result) = FPProcessNaNs{N}(type1, type2, op1, op2, fpcr, fpexc); let rounding : FPRounding = FPRoundingMode(fpcr);if !done then let inf1 : boolean = (type1 == FPType_Infinity); let inf2 : boolean = (type2 == FPType_Infinity); let zero1 : boolean = (type1 == FPType_Zero); let zero2 : boolean = (type2 == FPType_Zero);
if (inf1 && zero2) || (zero1 && inf2) then result = FPOnePointFive{N}('0');elsif inf1 || inf2 then result = FPInfinity{N}(sign1 XOR sign2);else // Fully fused multiply-add and halve let result_value : real = (3.0 + (value1 * value2)) / 2.0; if result_value == 0.0 then // Sign of exact zero result depends on rounding mode let sign : bit = if rounding == FPRounding_NEGINF then '1' else '0'; result = FPZero{N}(sign); else result = FPRound{N}(result_value, fpcr, rounding, fpexc); end;end;end;
return result;
end;
## Library pseudocode for aarch64/functions/fusedrstep/FPRecipStepFused
// FPRecipStepFused // ==================
func FPRecipStepFused{N}(op1_in : bits(N), op2 : bits(N), fpcr_in : FPCR_Type) => bits(N) begin assert N IN {16, 32, 64}; var fpcr : FPCR_Type = fpcr_in; var op1 : bits(N) = op1_in; var result : bits(N); var done : boolean; op1 = FPNeg{N}(op1, fpcr);
let altfp : boolean = IsFeatureImplemented(FEAT_AFP) && fpcr.AH == '1'; let fpexc : boolean = !altfp; // Generate no floating-point exceptions if altfp then fpcr.[FIZ,FZ] = '11'; end; // Flush denormal input and output to zero if altfp then fpcr.RMode = '00'; end; // Use RNE rounding modelet (type1,sign1,value1) : (FPType, bit, real) = FPUnpack{N}(op1, fpcr, fpexc); let (type2,sign2,value2) : (FPType, bit, real) = FPUnpack{N}(op2, fpcr, fpexc); (done,result) = FPProcessNaNs{N}(type1, type2, op1, op2, fpcr, fpexc); let rounding : FPRounding = FPRoundingMode(fpcr);
if !done then let inf1 : boolean = (type1 == FPType_Infinity); let inf2 : boolean = (type2 == FPType_Infinity); let zero1 : boolean = (type1 == FPType_Zero); let zero2 : boolean = (type2 == FPType_Zero);
if (inf1 && zero2) || (zero1 && inf2) then result = FPTwo{N}('0');elsif inf1 || inf2 then result = FPInfinity{N}(sign1 XOR sign2);else // Fully fused multiply-add let result_value : real = 2.0 + (value1 * value2); if result_value == 0.0 then // Sign of exact zero result depends on rounding mode let sign : bit = if rounding == FPRounding_NEGINF then '1' else '0'; result = FPZero{N}(sign); else result = FPRound{N}(result_value, fpcr, rounding, fpexc); end;end;end;
return result;
end;
## Library pseudocode for aarch64/functions/gcs/AddGCSExRecord
// AddGCSExRecord // ================ // Generates and then writes an exception record to the // current Guarded Control Stack.
func AddGCSExRecord(elr : bits(64), spsr : bits(64), lr : bits(64)) begin var ptr : bits(64); let privileged : boolean = PSTATE.EL != EL0; let accdesc : AccessDescriptor = CreateAccDescGCS(MemOp_STORE, privileged);
ptr = GetCurrentGCSPointer();// Store the record Mem{64}(ptr-8, accdesc) = lr; Mem{64}(ptr-16, accdesc) = spsr; Mem{64}(ptr-24, accdesc) = elr; Mem{64}(ptr-32, accdesc) = Zeros{60}::'1001';
// Decrement the pointer value ptr = ptr - 32;
SetCurrentGCSPointer(ptr); return;
end;
## Library pseudocode for aarch64/functions/gcs/AddGCSRecord
// AddGCSRecord // ============== // Generates and then writes a record to the current Guarded // control stack.
func AddGCSRecord(vaddress : bits(64)) begin var ptr : bits(64); let privileged : boolean = PSTATE.EL != EL0; let accdesc : AccessDescriptor = CreateAccDescGCS(MemOp_STORE, privileged);
ptr = GetCurrentGCSPointer();// Store the record Mem{64}(ptr-8, accdesc) = vaddress;
// Decrement the pointer value ptr = ptr - 8;
SetCurrentGCSPointer(ptr); return;
end;
## Library pseudocode for aarch64/functions/gcs/CheckGCSExRecord
// CheckGCSExRecord // ================== // Validates the provided values against the top entry of the // current Guarded Control Stack.
func CheckGCSExRecord(elr : bits(64), spsr : bits(64), lr : bits(64), gcsinst_type : GCSInstruction) begin var ptr : bits(64); let privileged : boolean = PSTATE.EL != EL0; let accdesc : AccessDescriptor = CreateAccDescGCS(MemOp_LOAD, privileged); ptr = GetCurrentGCSPointer();
// Check the lowest doubleword is correctly formatted let recorded_first_dword : bits(64) = Mem{64}(ptr, accdesc); if recorded_first_dword != Zeros{60}::'1001' then GCSDataCheckException(gcsinst_type); end;// Check the ELR matches the recorded value let recorded_elr : bits(64) = Mem{64}(ptr+8, accdesc); if recorded_elr != elr then GCSDataCheckException(gcsinst_type); end;
// Check the SPSR matches the recorded value let recorded_spsr : bits(64) = Mem{64}(ptr+16, accdesc); if recorded_spsr != spsr then GCSDataCheckException(gcsinst_type); end;
// Check the LR matches the recorded value let recorded_lr : bits(64) = Mem{64}(ptr+24, accdesc); if recorded_lr != lr then GCSDataCheckException(gcsinst_type); end;
// Increment the pointer value ptr = ptr + 32;
SetCurrentGCSPointer(ptr); return;
end;
## Library pseudocode for aarch64/functions/gcs/CheckGCSSTREnabled
// CheckGCSSTREnabled // ==================== // Trap GCSSTR or GCSSTTR instruction if trapping is enabled.
func CheckGCSSTREnabled begin case PSTATE.EL of when EL0 => if GCSCRE0_EL1().STREn == '0' then if EL2Enabled() && HCR_EL2().TGE == '1' then GCSSTRTrapException(EL2); else GCSSTRTrapException(EL1); end; end; when EL1 => if GCSCR_EL1().STREn == '0' then GCSSTRTrapException(EL1); elsif (EL2Enabled() && ((EL3) || SCR_EL3().FGTEn == '1') && HFGITR_EL2().nGCSSTR_EL1 == '0') then GCSSTRTrapException(EL2); end; when EL2 => if GCSCR_EL2().STREn == '0' then GCSSTRTrapException(EL2); end; when EL3 => if GCSCR_EL3().STREn == '0' then GCSSTRTrapException(EL3); end; end; return; end;
## Library pseudocode for aarch64/functions/gcs/EXLOCKException
// EXLOCKException // ================= // Handle an EXLOCK exception condition.
func EXLOCKException begin let preferred_exception_return : bits(64) = ThisInstrAddr{}(); let vect_offset : integer = 0x0;
var except : ExceptionRecord = ExceptionSyndrome(Exception_GCSFail);except.syndrome.iss[24] = '0';except.syndrome.iss[23:20] = '0001';except.syndrome.iss[19:0] = Zeros{20};AArch64_TakeException(PSTATE.EL, except, preferred_exception_return, vect_offset);
end;
## Library pseudocode for aarch64/functions/gcs/GCSDataCheckException
// GCSDataCheckException // ======================= // Handle a GCS data check fault condition.
func GCSDataCheckException(gcsinst_type : GCSInstruction) begin var target_el : bits(2); let preferred_exception_return : bits(64) = ThisInstrAddr{}(); let vect_offset : integer = 0x0; var rn_unknown : boolean = FALSE; var is_ret : boolean = FALSE; var is_reta : boolean = FALSE;
if PSTATE.EL == EL0 then target_el = if (EL2Enabled() && HCR_EL2().TGE == '1') then EL2 else EL1;else target_el = PSTATE.EL;end;var except : ExceptionRecord = ExceptionSyndrome(Exception_GCSFail);case gcsinst_type of when GCSInstType_PRET => except.syndrome.iss[4:0] = '00000'; is_ret = TRUE; when GCSInstType_POPM => except.syndrome.iss[4:0] = '00001'; when GCSInstType_PRETAA => except.syndrome.iss[4:0] = '00010'; is_reta = TRUE; when GCSInstType_PRETAB => except.syndrome.iss[4:0] = '00011'; is_reta = TRUE; when GCSInstType_SS1 => except.syndrome.iss[4:0] = '00100'; when GCSInstType_SS2 => except.syndrome.iss[4:0] = '00101'; rn_unknown = TRUE; when GCSInstType_POPCX => rn_unknown = TRUE; except.syndrome.iss[4:0] = '01000'; when GCSInstType_POPX => except.syndrome.iss[4:0] = '01001';end;if rn_unknown == TRUE then except.syndrome.iss[9:5] = ARBITRARY : bits(5);elsif is_ret == TRUE then except.syndrome.iss[9:5] = ThisInstr()[9:5];elsif is_reta == TRUE then except.syndrome.iss[9:5] = '11110';else except.syndrome.iss[9:5] = ThisInstr()[4:0];end;except.syndrome.iss[24:10] = Zeros{15};except.vaddress = ARBITRARY : bits(64);AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;
## Library pseudocode for aarch64/functions/gcs/GCSEnabled
// GCSEnabled // ============ // Returns TRUE if the Guarded Control Stack is enabled at // the provided Exception level.
func GCSEnabled(el : bits(2)) => boolean begin if UsingAArch32() then return FALSE; end;
if HaveEL(EL3) && el != EL3 && SCR_EL3().GCSEn == '0' then return FALSE; end;if (el IN {EL0, EL1} && EL2Enabled() && (EL0) && (() || HCRX_EL2().GCSEn == '0')) then return FALSE; end;
return GCSPCRSelected(el);
end;
## Library pseudocode for aarch64/functions/gcs/GCSInstruction
// GCSInstruction // ==============
type GCSInstruction of enumeration { GCSInstType_PRET, // Procedure return without Pointer authentication GCSInstType_POPM, // GCSPOPM instruction GCSInstType_PRETAA, // Procedure return with Pointer authentication that used key A GCSInstType_PRETAB, // Procedure return with Pointer authentication that used key B GCSInstType_SS1, // GCSSS1 instruction GCSInstType_SS2, // GCSSS2 instruction GCSInstType_POPCX, // GCSPOPCX instruction GCSInstType_POPX // GCSPOPX instruction };
## Library pseudocode for aarch64/functions/gcs/GCSPCREnabled
// GCSPCREnabled // =============== // Returns TRUE if the Guarded Control Stack is PCR enabled // at the provided Exception level.
func GCSPCREnabled(el : bits(2)) => boolean begin return GCSPCRSelected(el) && GCSEnabled(el); end;
## Library pseudocode for aarch64/functions/gcs/GCSPCRSelected
// GCSPCRSelected // ================ // Returns TRUE if the Guarded Control Stack is PCR selected // at the provided Exception level.
func GCSPCRSelected(el : bits(2)) => boolean begin case el of when EL0 => return GCSCRE0_EL1().PCRSEL == '1'; when EL1 => return GCSCR_EL1().PCRSEL == '1'; when EL2 => return GCSCR_EL2().PCRSEL == '1'; when EL3 => return GCSCR_EL3().PCRSEL == '1'; end; unreachable; return TRUE; end;
## Library pseudocode for aarch64/functions/gcs/GCSPOPCX
// GCSPOPCX // ========== // Called to pop and compare a GCS exception return record.
func GCSPOPCX begin let spsr : bits(64) = SPSR_ELx(); CheckGCSExRecord(ELR_ELx(), spsr, X{64}(30), GCSInstType_POPCX); PSTATE.EXLOCK = if GetCurrentEXLOCKEN() then '1' else '0'; return; end;
## Library pseudocode for aarch64/functions/gcs/GCSPOPM
// GCSPOPM // ========= // Called to pop a GCS procedure return record.
func GCSPOPM() => bits(64) begin var ptr : bits(64); let privileged : boolean = PSTATE.EL != EL0; let accdesc : AccessDescriptor = CreateAccDescGCS(MemOp_LOAD, privileged);
ptr = GetCurrentGCSPointer(); let gcs_entry : bits(64) = Mem{64}(ptr, accdesc);if gcs_entry[1:0] != '00' then GCSDataCheckException(GCSInstType_POPM); end;
ptr = ptr + 8; SetCurrentGCSPointer(ptr); return gcs_entry;
end;
## Library pseudocode for aarch64/functions/gcs/GCSPOPX
// GCSPOPX // ========= // Called to pop a GCS exception return record.
func GCSPOPX begin var ptr : bits(64); let privileged : boolean = PSTATE.EL != EL0; let accdesc : AccessDescriptor = CreateAccDescGCS(MemOp_LOAD, privileged); ptr = GetCurrentGCSPointer();
// Check the lowest doubleword is correctly formatted let recorded_first_dword : bits(64) = Mem{64}(ptr, accdesc); if recorded_first_dword != Zeros{60}::'1001' then GCSDataCheckException(GCSInstType_POPX); end;// Ignore these loaded values, however they might have // faulted which is why we load them anyway let recorded_elr : bits(64) = Mem{64}(ptr+8, accdesc); let recorded_spsr : bits(64) = Mem{64}(ptr+16, accdesc); let recorded_lr : bits(64) = Mem{64}(ptr+24, accdesc);
// Increment the pointer value ptr = ptr + 32;
SetCurrentGCSPointer(ptr); return;
end;
## Library pseudocode for aarch64/functions/gcs/GCSPUSHM
// GCSPUSHM // ========== // Called to push a GCS procedure return record.
func GCSPUSHM(value : bits(64)) begin AddGCSRecord(value); return; end;
## Library pseudocode for aarch64/functions/gcs/GCSPUSHX
// GCSPUSHX // ========== // Called to push a GCS exception return record.
func GCSPUSHX begin let spsr : bits(64) = SPSR_ELx(); AddGCSExRecord(ELR_ELx(), spsr, X{64}(30)); PSTATE.EXLOCK = '0'; return; end;
## Library pseudocode for aarch64/functions/gcs/GCSReturnValueCheckEnabled
// GCSReturnValueCheckEnabled // ============================ // Returns TRUE if the Guarded Control Stack has return value // checking enabled at the current Exception level.
func GCSReturnValueCheckEnabled(el : bits(2)) => boolean begin if UsingAArch32() then return FALSE; end; case el of when EL0 => return GCSCRE0_EL1().RVCHKEN == '1'; when EL1 => return GCSCR_EL1().RVCHKEN == '1'; when EL2 => return GCSCR_EL2().RVCHKEN == '1'; when EL3 => return GCSCR_EL3().RVCHKEN == '1'; end; end;
## Library pseudocode for aarch64/functions/gcs/GCSSS1
// GCSSS1 // ======== // Operational pseudocode for GCSSS1 instruction.
func GCSSS1(incoming_pointer : bits(64)) begin var outgoing_pointer, cmpoperand, operand, data : bits(64); let privileged : boolean = PSTATE.EL != EL0; let accdesc : AccessDescriptor = CreateAccDescGCSSS1(privileged); outgoing_pointer = GetCurrentGCSPointer(); // Valid GCS cap record is expected cmpoperand = incoming_pointer[63:12]::'000000000001'; // In-progress GCS cap record should be stored if the comparison is successful operand = outgoing_pointer[63:3]::'101';
data = MemAtomic{64}(incoming_pointer, cmpoperand, operand, accdesc);if data == cmpoperand then SetCurrentGCSPointer(incoming_pointer[63:3]::'000');else GCSDataCheckException(GCSInstType_SS1);end;return;
end;
## Library pseudocode for aarch64/functions/gcs/GCSSS2
// GCSSS2 // ======== // Operational pseudocode for GCSSS2 instruction.
func GCSSS2() => bits(64) begin var outgoing_pointer, incoming_pointer, outgoing_value : bits(64); let privileged : boolean = PSTATE.EL != EL0; let accdesc_ld : AccessDescriptor = CreateAccDescGCS(MemOp_LOAD, privileged); let accdesc_st : AccessDescriptor = CreateAccDescGCS(MemOp_STORE, privileged); incoming_pointer = GetCurrentGCSPointer(); outgoing_value = Mem{64}(incoming_pointer, accdesc_ld);
if outgoing_value[2:0] == '101' then //in_progress token outgoing_pointer[63:3] = (outgoing_value[63:3]) - 1; outgoing_pointer[2:0] = '000'; outgoing_value = outgoing_pointer[63:12]::'000000000001'; Mem{64}(outgoing_pointer, accdesc_st) = outgoing_value; SetCurrentGCSPointer(incoming_pointer + 8); GCSSynchronizationBarrier();else GCSDataCheckException(GCSInstType_SS2);end;return outgoing_pointer;
end;
## Library pseudocode for aarch64/functions/gcs/GCSSTRTrapException
// GCSSTRTrapException // ===================== // Handle a trap on GCSSTR instruction condition.
func GCSSTRTrapException(target_el : bits(2)) begin let preferred_exception_return : bits(64) = ThisInstrAddr{}(); let vect_offset : integer = 0x0;
var except : ExceptionRecord = ExceptionSyndrome(Exception_GCSFail);except.syndrome.iss[24] = '0';except.syndrome.iss[23:20] = '0010';except.syndrome.iss[19:15] = '00000';except.syndrome.iss[14:10] = ThisInstr()[9:5];except.syndrome.iss[9:5] = ThisInstr()[4:0];except.syndrome.iss[4:0] = '00000';AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;
## Library pseudocode for aarch64/functions/gcs/GCSSynchronizationBarrier
// GCSSynchronizationBarrier // =========================== // Barrier instruction that synchronizes GCS accesses // in relation to other load and store accesses
impdef func GCSSynchronizationBarrier begin return; end;
## Library pseudocode for aarch64/functions/gcs/GetCurrentEXLOCKEN
// GetCurrentEXLOCKEN // ====================
readonly func GetCurrentEXLOCKEN() => boolean begin if Halted() || Restarting() then return FALSE; end;
case PSTATE.EL of when EL0 => unreachable; when EL1 => return GCSCR_EL1().EXLOCKEN == '1'; when EL2 => return GCSCR_EL2().EXLOCKEN == '1'; when EL3 => return GCSCR_EL3().EXLOCKEN == '1';end;
end;
## Library pseudocode for aarch64/functions/gcs/GetCurrentGCSPointer
// GetCurrentGCSPointer // ====================== // Returns the value of the current GCS pointer register.
func GetCurrentGCSPointer() => bits(64) begin var ptr : bits(64);
case PSTATE.EL of when EL0 => ptr = GCSPR_EL0().PTR::'000'; when EL1 => ptr = GCSPR_EL1().PTR::'000'; when EL2 => ptr = GCSPR_EL2().PTR::'000'; when EL3 => ptr = GCSPR_EL3().PTR::'000';end;return ptr;
end;
## Library pseudocode for aarch64/functions/gcs/LoadCheckGCSRecord
// LoadCheckGCSRecord // ==================== // Validates the provided address against the top entry of the // current Guarded Control Stack.
func LoadCheckGCSRecord(vaddress : bits(64), gcsinst_type : GCSInstruction) => bits(64) begin var ptr : bits(64); var recorded_va : bits(64); let privileged : boolean = PSTATE.EL != EL0; let accdesc : AccessDescriptor = CreateAccDescGCS(MemOp_LOAD, privileged);
ptr = GetCurrentGCSPointer(); recorded_va = Mem{64}(ptr, accdesc); if GCSReturnValueCheckEnabled(PSTATE.EL) && (recorded_va != vaddress) then GCSDataCheckException(gcsinst_type); end;
return recorded_va;
end;
## Library pseudocode for aarch64/functions/gcs/SetCurrentGCSPointer
// SetCurrentGCSPointer // ====================== // Writes a value to the current GCS pointer register.
func SetCurrentGCSPointer(ptr : bits(64)) begin case PSTATE.EL of when EL0 => GCSPR_EL0().PTR = ptr[63:3]; when EL1 => GCSPR_EL1().PTR = ptr[63:3]; when EL2 => GCSPR_EL2().PTR = ptr[63:3]; when EL3 => GCSPR_EL3().PTR = ptr[63:3]; end; return; end;
## Library pseudocode for aarch64/functions/gic/GetCurrentDomainPPIMask
// GetCurrentDomainPPIMask // ========================= // Returns a mask of PPIs assigned to the current domain.
func GetCurrentDomainPPIMask(n : integer) => bits(64) begin var mask : bits(64) = Zeros{64}; for x = 0 to 63 do if IsPPIAssignedToCurrentDomain((n * 64) + x) then mask[x] = '1'; end; end; return mask; end;
## Library pseudocode for aarch64/functions/gic/GetICCPendingWritablePPIMask
// GetICCPendingWritablePPIMask // ============================== // Returns the mask of PPIs writable through ICC_PPI_*PENDR_EL1(n).
func GetICCPendingWritablePPIMask(n : integer) => bits(64) begin return GetICCWritablePPIMask(n) AND NOT ICC_PPI_HMR_EL1(n); end;
## Library pseudocode for aarch64/functions/gic/GetICCWritablePPIMask
// GetICCWritablePPIMask // ======================= // Returns the mask of PPIs writable through ICC_PPI_*_EL1(n).
func GetICCWritablePPIMask(n : integer) => bits(64) begin var mask : bits(64) = GetImplementedPPIMask(n); if PSTATE.EL IN {EL2, EL1} then mask = mask AND GetCurrentDomainPPIMask(n); end; return mask; end;
## Library pseudocode for aarch64/functions/gic/GetICVPendingWritablePPIMask
// GetICVPendingWritablePPIMask // ============================== // Returns the mask of PPIs writable through ICV_PPI_*PENDR_EL1(n).
func GetICVPendingWritablePPIMask(n : integer) => bits(64) begin return GetImplementedPPIMask(n) AND NOT ICV_PPI_HMR_EL1(n); end;
## Library pseudocode for aarch64/functions/gic/GetImplementedPPIMask
// GetImplementedPPIMask // ======================= // Returns a mask of implemented PPIs for ICC_PPI_EL1(n) and ICV_PPI_EL1(n).
func GetImplementedPPIMask(n : integer) => bits(64) begin var mask : bits(64) = Zeros{64}; for x = 0 to 63 do if IsPPIImplemented((n * 64) + x) then mask[x] = '1'; end; end; return mask; end;
## Library pseudocode for aarch64/functions/gic/Write\_ICC\_PPI\_CACTIVER\_EL1
// Write_ICC_PPI_CACTIVER_EL1 // ============================ // System register write to ICC_PPI_CACTIVER_EL1(n).
func Write_ICC_PPI_CACTIVER_EL1(n : integer, value_in : bits(64)) begin ICC_PPI_SACTIVER_EL1(n) = (ICC_PPI_SACTIVER_EL1(n) AND NOT (value_in AND GetICCWritablePPIMask(n))); end;
## Library pseudocode for aarch64/functions/gic/Write\_ICC\_PPI\_CPENDR\_EL1
// Write_ICC_PPI_CPENDR_EL1 // ========================== // System register write to ICC_PPI_CPENDR_EL1(n).
func Write_ICC_PPI_CPENDR_EL1(n : integer, value_in : bits(64)) begin ICC_PPI_SPENDR_EL1(n) = (ICC_PPI_SPENDR_EL1(n) AND NOT (value_in AND GetICCPendingWritablePPIMask(n))); end;
## Library pseudocode for aarch64/functions/gic/Write\_ICC\_PPI\_SACTIVER\_EL1
// Write_ICC_PPI_SACTIVER_EL1 // ============================ // System register write to ICC_PPI_SACTIVER_EL1(n).
func Write_ICC_PPI_SACTIVER_EL1(n : integer, value_in : bits(64)) begin ICC_PPI_SACTIVER_EL1(n) = ICC_PPI_SACTIVER_EL1(n) OR (value_in AND GetICCWritablePPIMask(n)); end;
## Library pseudocode for aarch64/functions/gic/Write\_ICC\_PPI\_SPENDR\_EL1
// Write_ICC_PPI_SPENDR_EL1 // ========================== // System register write to ICC_PPI_SPENDR_EL1(n).
func Write_ICC_PPI_SPENDR_EL1(n : integer, value_in : bits(64)) begin ICC_PPI_SPENDR_EL1(n) = ICC_PPI_SPENDR_EL1(n) OR (value_in AND GetICCPendingWritablePPIMask(n)); end;
## Library pseudocode for aarch64/functions/gic/Write\_ICV\_PPI\_CACTIVER\_EL1
// Write_ICV_PPI_CACTIVER_EL1 // ============================ // System register write to ICV_PPI_CACTIVER_EL1(n).
func Write_ICV_PPI_CACTIVER_EL1(n : integer, value_in : bits(64)) begin ICH_PPI_ACTIVER_EL2(n) = ICH_PPI_ACTIVER_EL2(n) AND NOT (value_in AND GetImplementedPPIMask(n)); end;
## Library pseudocode for aarch64/functions/gic/Write\_ICV\_PPI\_CPENDR\_EL1
// Write_ICV_PPI_CPENDR_EL1 // ========================== // System register write to ICV_PPI_CPENDR_EL1(n).
func Write_ICV_PPI_CPENDR_EL1(n : integer, value_in : bits(64)) begin ICH_PPI_PENDR_EL2(n) = ICH_PPI_PENDR_EL2(n) AND NOT (value_in AND GetICVPendingWritablePPIMask(n)); end;
## Library pseudocode for aarch64/functions/gic/Write\_ICV\_PPI\_SACTIVER\_EL1
// Write_ICV_PPI_SACTIVER_EL1 // ============================ // System register write to ICV_PPI_SACTIVER_EL1(n).
func Write_ICV_PPI_SACTIVER_EL1(n : integer, value_in : bits(64)) begin ICH_PPI_ACTIVER_EL2(n) = ICH_PPI_ACTIVER_EL2(n) OR (value_in AND GetImplementedPPIMask(n)); end;
## Library pseudocode for aarch64/functions/gic/Write\_ICV\_PPI\_SPENDR\_EL1
// Write_ICV_PPI_SPENDR_EL1 // ========================== // System register write to ICV_PPI_SPENDR_EL1(n).
func Write_ICV_PPI_SPENDR_EL1(n : integer, value_in : bits(64)) begin ICH_PPI_PENDR_EL2(n) = ICH_PPI_PENDR_EL2(n) OR (value_in AND GetICVPendingWritablePPIMask(n)); end;
## Library pseudocode for aarch64/functions/hacdbs
constant HACDBS_ERR_REASON_STRUCTF : bits(2) = '01'; constant HACDBS_ERR_REASON_IPAF : bits(2) = '10'; constant HACDBS_ERR_REASON_IPHACF : bits(2) = '11';
## Library pseudocode for aarch64/functions/hacdbs/IsHACDBSIRQAsserted
// IsHACDBSIRQAsserted // ===================== // Returns TRUE if HACDBSIRQ is asserted, and FALSE otherwise.
impdef func IsHACDBSIRQAsserted() => boolean begin return FALSE; end;
## Library pseudocode for aarch64/functions/hacdbs/ProcessHACDBSEntry
// ProcessHACDBSEntry // ==================== // Process a single entry from the HACDBS.
func ProcessHACDBSEntry begin if !IsFeatureImplemented(FEAT_HACDBS) then return; end;
if (PSTATE.EL == EL3 || (HaveEL(EL3) && SCR_EL3().HACDBSEn == '0') || HACDBSBR_EL2().EN == '0') then SetInterruptRequestLevel(InterruptID_HACDBSIRQ, LOW); return; end;if HCR_EL2().VM == '0' then return; end;
if (UInt(HACDBSCONS_EL2().INDEX) >= (2 ^ (UInt(HACDBSBR_EL2().SZ) + 12)) DIVRM 8 || HACDBSCONS_EL2().ERR_REASON != '00') then SetInterruptRequestLevel(InterruptID_HACDBSIRQ, HIGH); return; elsif IsHACDBSIRQAsserted() then SetInterruptRequestLevel(InterruptID_HACDBSIRQ, LOW); end;
let hacdbs_size : integer{} = UInt(HACDBSBR_EL2().SZ); var baddr : bits(NUM_PABITS) = HACDBSBR_EL2().BADDR[NUM_PABITS-13 : 0] :: Zeros{12}; baddr[11 + hacdbs_size : 12] = Zeros{hacdbs_size};
var accdesc : AccessDescriptor = CreateAccDescHACDBS();
var addrdesc : AddressDescriptor; addrdesc.paddress.address = baddr + (8 * UInt(HACDBSCONS_EL2().INDEX)); let nse2 : bit = '0'; // NSE2 has the Effective value of 0 within a PE. addrdesc.paddress.paspace = DecodePASpace(nse2, EffectiveSCR_EL3_NSE(), EffectiveSCR_EL3_NS());
// Accesses to the HACDBS use the same memory attributes as used for stage 2 translation walks. addrdesc.memattrs = WalkMemAttrs(VTCR_EL2().SH0, VTCR_EL2().IRGN0, VTCR_EL2().ORGN0); let emec : bit = (if IsFeatureImplemented(FEAT_MEC) && IsSCTLR2EL2Enabled() then SCTLR2_EL2().EMEC else '0'); addrdesc.mecid = AArch64_S2TTWalkMECID(emec, accdesc.ss);
var fault : FaultRecord = NoFault(accdesc);
if IsFeatureImplemented(FEAT_RME) then fault.gpcf = GranuleProtectionCheck(addrdesc, accdesc);
if fault.gpcf.gpf != GPCF_None then HACDBSCONS_EL2().ERR_REASON = HACDBS_ERR_REASON_STRUCTF; return;end;end;
var memstatus : PhysMemRetStatus; var hacdbs_entry : bits(64); (memstatus, hacdbs_entry) = PhysMemRead{64}(addrdesc, accdesc);
if IsFault(memstatus) then HACDBSCONS_EL2().ERR_REASON = HACDBS_ERR_REASON_STRUCTF; return; end;
if BigEndian(accdesc.acctype) then hacdbs_entry = BigEndianReverse{64}(hacdbs_entry); end;
// If the Valid field is clear, do not perform any cleaning operation // and increment HACDBSCONS_EL2.INDEX. if hacdbs_entry[0] == '0' then HACDBSCONS_EL2().INDEX = HACDBSCONS_EL2().INDEX + 1; return; end;
accdesc = CreateAccDescTTEUpdate(accdesc); var ipa : AddressDescriptor; ipa.paddress.address = hacdbs_entry[NUM_PABITS-1:12] :: Zeros{12};
let nsipa : bit = hacdbs_entry[11]; let paspace : PASpace = DecodePASpace(nse2, EffectiveSCR_EL3_NSE(), EffectiveSCR_EL3_NS()); ipa.paddress.paspace = (if accdesc.ss == SS_Secure && nsipa == '1' then PAS_NonSecure else paspace);
let s1aarch64 : boolean = TRUE; let walkparams : S2TTWParams = AArch64_GetS2TTWParams(accdesc.ss, ipa.paddress.paspace, s1aarch64);
var descpaddr : AddressDescriptor; var walkstate : TTWState; var descriptor : bits(128); if walkparams.d128 == '1' then (fault, descpaddr, walkstate, descriptor) = AArch64_S2Walk{128}(fault, ipa, walkparams, accdesc); else (fault, descpaddr, walkstate, descriptor[63:0]) = AArch64_S2Walk{64}(fault, ipa, walkparams, accdesc); end;
// If the Access flag on the Block or Page descriptor is set to 0, this does not generate // an Access flag fault and the PE can still perform the cleaning operation on that descriptor. if fault.statuscode == Fault_AccessFlag then fault.statuscode = Fault_None; elsif fault.statuscode != Fault_None then HACDBSCONS_EL2().ERR_REASON = HACDBS_ERR_REASON_IPAF; return; end;
let hacdbs_level : integer = SInt(hacdbs_entry[3:1]); if walkstate.level != hacdbs_level || walkstate.contiguous == '1' then HACDBSCONS_EL2().ERR_REASON = HACDBS_ERR_REASON_IPHACF; return; end;
// For the purpose of cleaning HACDBS entries, it is not required that HW update of dirty bit // is enabled for a descriptor to be qualified as writable-clean or writable-dirty.
// Check if the descriptor is neither writable-clean nor writable-dirty. if walkparams.s2pie == '1' then let perms : S2AccessControls = AArch64_S2ComputePermissions(walkstate.permissions, walkparams, accdesc); if perms.w == '0' && perms.w_mmu == '0' then HACDBSCONS_EL2().ERR_REASON = HACDBS_ERR_REASON_IPHACF; return; end;
// If DBM is 0, the descriptor is not writable-clean or writable-dirty. elsif descriptor[51] == '0' then HACDBSCONS_EL2().ERR_REASON = HACDBS_ERR_REASON_IPHACF; return; end;
// If the descriptor is writable-clean, do not perform any cleaning // operation and increment HACDBSCONS_EL2.INDEX. if descriptor[7] == '0' then HACDBSCONS_EL2().INDEX = HACDBSCONS_EL2().INDEX + 1; return; end;
var new_descriptor : bits(128) = descriptor; new_descriptor[7] = '0';
let descaccess : AccessDescriptor = CreateAccDescTTEUpdate(accdesc); if walkparams.d128 == '1' then (fault, -) = AArch64_MemSwapTableDesc{128}(fault, descriptor, new_descriptor, walkparams.ee, descaccess, descpaddr); else (fault, -) = AArch64_MemSwapTableDesc{64}(fault, descriptor[63:0], new_descriptor[63:0], walkparams.ee, descaccess, descpaddr); end;
if fault.statuscode != Fault_None then HACDBSCONS_EL2().ERR_REASON = HACDBS_ERR_REASON_IPAF; else HACDBSCONS_EL2().INDEX = HACDBSCONS_EL2().INDEX + 1; end;
return;
end;
## Library pseudocode for aarch64/functions/ic/AArch64\_CanTrapIC
// AArch64_CanTrapIC // =================== // Determines whether the execution of the IC instruction can be trapped.
func AArch64_CanTrapIC(cachetype : CacheType, cacheop : CacheOp, opscope : CacheOpScope) => boolean begin return ((cachetype, cacheop, opscope) || ImpDefBool( "When IC is treated as NOP, data cache maintenance operations are trapped")); end;
## Library pseudocode for aarch64/functions/ic/AArch64\_EffectiveOpScope
// AArch64_EffectiveOpScope // ==========================
func AArch64_EffectiveOpScope(opscope_in : CacheOpScope) => CacheOpScope begin var opscope : CacheOpScope = opscope_in;
if PSTATE.EL != EL1 then return opscope; end;if IsFeatureImplemented(FEAT_TLBID) then let fnb : bit = if IsHCRXEL2Enabled() then HCRX_EL2().FNB else '0'; case fnb::HCR_EL2().FB of when '00' => pass; when '01' => if opscope == CacheOpScope_ALLU then // The operation is broadcast within the Inner Shareable shareability domain. opscope = CacheOpScope_ALLUIS; end; when '10' => if opscope == CacheOpScope_ALLUIS then // The operation only affects the PE on which the instruction is executed. opscope = CacheOpScope_ALLU; end; when '11' => if opscope == CacheOpScope_ALLUIS then // The operation is broadcast to PEs which would share TLB entries with the // current PE if CnP were 1. opscope = CacheOpScope_ALLUIS_CnP; end; end; else if opscope == CacheOpScope_ALLU && EL2Enabled() && HCR_EL2().FB == '1' then opscope = CacheOpScope_ALLUIS; end; end;
return opscope;
end;
## Library pseudocode for aarch64/functions/ic/AArch64\_IC
// AArch64_IC // ============ // Perform Instruction Cache Operation.
func AArch64_IC(opscope : CacheOpScope) begin let regval : bits(64) = ARBITRARY : bits(64); AArch64_IC(regval, opscope); end;
// AArch64_IC // ============ // Perform Instruction Cache Operation.
func AArch64_IC(regval : bits(64), opscope_in : CacheOpScope) begin var cache : CacheRecord; var opscope : CacheOpScope = opscope_in;
cache.acctype = AccessType_IC; cache.cachetype = CacheType_Instruction; cache.cacheop = CacheOp_Invalidate; cache.opscope = opscope;if opscope IN {CacheOpScope_ALLU, CacheOpScope_ALLUIS_CnP, CacheOpScope_ALLUIS} then let ss : SecurityState = SecurityStateAtEL(PSTATE.EL); cache.cpas = CPASAtSecurityState(ss); opscope = AArch64_EffectiveOpScope(opscope);
case opscope of when CacheOpScope_ALLU => cache.shareability = Shareability_NSH; when CacheOpScope_ALLUIS => cache.shareability = Shareability_ISH; // When executed at EL1, if the Effective value of HCRX_EL2.VTLBIDEn is '1', // then the operation is broadcast to the set of PEs selected by VTLBID0_EL2.TD0. // Otherwise, the operation is broadcast to all PEs in the Shareability domain. cache.domains = TLBIDomains(Broadcast_ISH, Zeros{16}); when CacheOpScope_ALLUIS_CnP => cache.shareability = Shareability_ISH; cache.domains = DEFAULT_TLBI_DOMAIN; otherwise => unreachable;end;cache.regval = regval;CACHE_OP(cache);else assert opscope == CacheOpScope_PoU;
if EL2Enabled() && () then if PSTATE.EL IN {EL0, EL1} then cache.is_vmid_valid = TRUE; cache.vmid = VMID(); else cache.is_vmid_valid = FALSE; end;else cache.is_vmid_valid = FALSE;end;if PSTATE.EL == EL0 then cache.is_asid_valid = TRUE; cache.asid = ASID();else cache.is_asid_valid = FALSE;end;let vaddress : bits(64) = regval;cache.vaddress = regval;let accdesc : AccessDescriptor = CreateAccDescIC(cache);let aligned : boolean = TRUE;let size : integer = 0;var memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(vaddress, accdesc, aligned, size);if IsFault(memaddrdesc) then memaddrdesc.fault.vaddress = regval; AArch64_Abort(memaddrdesc.fault);end;cache.cpas = CPASAtPAS(memaddrdesc.paddress.paspace);cache.paddress = memaddrdesc.paddress;cache.shareability = memaddrdesc.memattrs.shareability;if memaddrdesc.memattrs.shareability == Shareability_OSH then cache.shareability = Shareability_ISH;end;if memaddrdesc.memattrs.shareability != Shareability_NSH then // If the Effective value of HCRX_EL2().VTLBIDEn is '1', the invalidation is broadcast // to the set of PEs in the Inner shareable domain selected by VTLBID0_EL2().TD0 when // executed at EL1, or at EL0 when HCR_EL2().TGE is 0. cache.domains = TLBIDomains(Broadcast_ISH, Zeros{16});end;CACHE_OP(cache);
end; return;
end;
## Library pseudocode for aarch64/functions/ic/AArch64\_TreatICAsNOP
// AArch64_TreatICAsNOP // ====================== // Determines whether the execution of the IC instruction is treated as a NOP.
func AArch64_TreatICAsNOP(cachetype : CacheType, cacheop : CacheOp, opscope : CacheOpScope) => boolean begin if CTR_EL0().DIC == '1' then return ImpDefBool("IC is treated as NOP"); end;
return FALSE;
end;
## Library pseudocode for aarch64/functions/iesb/EIESB
// EIESB // ===== // Implementation options for the ID_AA64MMFR4_EL1.EIESB exception-entry behavior.
type EIESB of enumeration { EIESB_None, // 0b0000 EIESB_Before_EL3_Conditional, // 0b0001 EIESB_Before_All_Conditional, // 0b0010 EIESB_Before_All_NonSError, // 0b0011 EIESB_After_EL3_Conditional // 0b1111 };
## Library pseudocode for aarch64/functions/iesb/GetEIESB
// GetEIESB // ========== // Returns the EIESB implementation level.
impdef func GetEIESB() => EIESB begin return EIESB_Before_All_NonSError; end;
## Library pseudocode for aarch64/functions/iesb/InsertIESBBeforeException
// InsertIESBBeforeException // =========================== // Returns whether an implicit Error synchronization event is inserted before // taking an exception, according to the EIESB implementation behavior. //