[Writeup] Shared pseudocode: part 4 of 36 ========================================= Section: Silicon & Architectures Started: 2026-11-28 17:43 UTC by admin Replies: 0, last post 2026-11-28 17:43 UTC Page: 1 of 1 Web: https://romdump.net/t/96 ------------------------------------------------------------------------------ #116 admin, 2026-11-28 17:43 UTC [OP] Source: https://romdump.net/raw/116
Shared pseudocode from the offline Arm documentation snapshot. Part 4 of 36.
return (valid, c);
end;
## Library pseudocode for aarch32/functions/system/CP15DMB
// CP15DMB // ========= // Legacy AArch32 system instruction form of DMB SY.
func CP15DMB begin DataMemoryBarrier(MBReqTypes_All); return; end;
## Library pseudocode for aarch32/functions/system/CP15DSB
// CP15DSB // ========= // Legacy AArch32 system instruction form of DSB SY.
func CP15DSB begin DataSynchronizationBarrier(MBMaintenanceScope_OuterShareable, MBReqTypes_All, FALSE); return; end;
## Library pseudocode for aarch32/functions/system/CP15ISB
// CP15ISB // ========= // Legacy AArch32 system instruction form of ISB.
func CP15ISB begin InstructionSynchronizationBarrier(); return; end;
## Library pseudocode for aarch32/functions/system/CPSRWriteByInstr
// CPSRWriteByInstr // ================== // Update PSTATE.[N,Z,C,V,Q,GR,E,A,I,F,M] from a CPSR value written by an MSR instruction.
func CPSRWriteByInstr(value : bits(32), bytemask : bits(4)) begin let privileged : boolean = PSTATE.EL != EL0; // PSTATE.[A,I,F,M] are not writable at EL0
// Write PSTATE from 'value', ignoring bytes masked by 'bytemask'
if bytemask[3] == '1' then
PSTATE.[N,Z,C,V,Q] = value[31:27];
// Bits [26:24] are ignored
end;
if bytemask[2] == '1' then
if IsFeatureImplemented(FEAT_SSBS) then
PSTATE.SSBS = value[23];
end;
if privileged then
PSTATE.PAN = value[22];
end;
if IsFeatureImplemented(FEAT_DIT) then
PSTATE.DIT = value[21];
end;
// Bit [20] is RES0
PSTATE.GE = value[19:16];
end;
if bytemask[1] == '1' then
// Bits [15:10] are RES0
PSTATE.E = value[9]; // PSTATE.E is writable at EL0
if privileged then
PSTATE.A = value[8];
end;
end;
if bytemask[0] == '1' then
if privileged then
PSTATE.[I,F] = value[7:6];
// Bit [5] is RES0
// AArch32_WriteModeByInstr() sets PSTATE.IL to 1 if this is an illegal mode change.
AArch32_WriteModeByInstr(value[4:0]);
end;
end;
return;
end;
## Library pseudocode for aarch32/functions/system/ConditionPassed
// ConditionPassed // =================
func ConditionPassed() => boolean begin return ConditionHolds(CurrentCond()); end;
## Library pseudocode for aarch32/functions/system/CurrentCond
// CurrentCond // ============= // Returns the condition code that applies to the currently executing instruction
impdef func CurrentCond() => bits(4) begin return Zeros{4}; end;
## Library pseudocode for aarch32/functions/system/InITBlock
// InITBlock // ===========
func InITBlock() => boolean begin if CurrentInstrSet() == InstrSet_T32 then return PSTATE.IT[3:0] != '0000'; else return FALSE; end; end;
## Library pseudocode for aarch32/functions/system/LastInITBlock
// LastInITBlock // ===============
func LastInITBlock() => boolean begin return (PSTATE.IT[3:0] == '1000'); end;
## Library pseudocode for aarch32/functions/system/SPSRWriteByInstr
// SPSRWriteByInstr // ==================
func SPSRWriteByInstr(value : bits(32), bytemask : bits(4)) begin var new_spsr : bits(32) = SPSR_curr();
if bytemask[3] == '1' then
new_spsr[31:24] = value[31:24]; // N, Z, C, V, Q flags, IT[1:0],J bits
end;
if bytemask[2] == '1' then
new_spsr[23:16] = value[23:16]; // IL bit, GE[3:0] flags
end;
if bytemask[1] == '1' then
new_spsr[15:8] = value[15:8]; // IT[7:2] bits, E bit, A interrupt mask
end;
if bytemask[0] == '1' then
new_spsr[7:0] = value[7:0]; // I, F interrupt masks, T bit, Mode bits
end;
SPSR_curr() = new_spsr; // UNPREDICTABLE if User or System mode
return;
end;
## Library pseudocode for aarch32/functions/system/SPSRaccessValid
// SPSRaccessValid // ================= // Checks for MRS (Banked register) or MSR (Banked register) accesses to the SPSRs // that are UNPREDICTABLE
func SPSRaccessValid(SYSm : bits(5), mode : bits(5)) => (boolean, Constraint) begin var valid : boolean = TRUE; var c : Constraint = Constraint_NONE; var banked_unpred : boolean = FALSE; case SYSm of when '01110' => // SPSR_fiq banked_unpred = mode == M32_FIQ; when '10000' => // SPSR_irq banked_unpred = mode == M32_IRQ; when '10010' => // SPSR_svc banked_unpred = mode == M32_Svc; when '10100' => // SPSR_abt banked_unpred = mode == M32_Abort; when '10110' => // SPSR_und banked_unpred = mode == M32_Undef; when '11100' => // SPSR_mon banked_unpred = ((EL3) || mode == M32_Monitor || CurrentSecurityState() != SS_Secure); when '11110' => // SPSR_hyp banked_unpred = (EL2) || mode != M32_Monitor; otherwise => valid = FALSE; c = ConstrainUnpredictable(Unpredictable_UnimplementedRegister); assert c IN {Constraint_UNDEF, Constraint_NOP, Constraint_ANYREG}; end;
if banked_unpred then
valid = FALSE;
c = ConstrainUnpredictable(Unpredictable_BankedRegister);
assert c IN {Constraint_UNDEF, Constraint_NOP, Constraint_UNKNOWN};
end;
return (valid, c);
end;
## Library pseudocode for aarch32/functions/system/SelectInstrSet
// SelectInstrSet // ================
func SelectInstrSet(iset : InstrSet) begin assert CurrentInstrSet() IN {InstrSet_A32, InstrSet_T32}; assert iset IN {InstrSet_A32, InstrSet_T32};
PSTATE.T = if iset == InstrSet_A32 then '0' else '1';
return;
end;
## Library pseudocode for aarch32/functions/tlbi/AArch32\_DTLBI\_ALL
// AArch32_DTLBI_ALL // =================== // Invalidate all data TLB entries for the indicated translation regime with the // the indicated security state for all TLBs within the indicated broadcast domain. // Invalidation applies to all applicable stage 1 and stage 2 entries.
func AArch32_DTLBI_ALL(security : SecurityState, regime : Regime, vmid : bits(NUM_VMIDBITS), broadcast_in : Broadcast, attr_in : TLBIMemAttr) begin assert PSTATE.EL IN {EL3, EL2, EL1}; var attr : TLBIMemAttr = attr_in;
let broadcast : Broadcast =
AArch32_EffectiveBroadcast(broadcast_in);
if ExcludeXS() then
attr = TLBI_ExcludeXS;
end;
var r : TLBIRecord;
r.op = TLBIOp_DALL;
r.from_aarch64 = FALSE;
r.security = security;
r.regime = regime;
r.vmid = vmid;
r.use_vmid = UseVMID(regime);
r.level = TLBILevel_Any;
r.attr = attr;
TLBI(r);
if broadcast != Broadcast_NSH then BroadcastTLBI(broadcast, r); end;
return;
end;
## Library pseudocode for aarch32/functions/tlbi/AArch32\_DTLBI\_ASID
// AArch32_DTLBI_ASID // ==================== // Invalidate all data TLB stage 1 entries matching the indicated VMID (where regime supports) // and ASID in the parameter Rt in the indicated translation regime with the // indicated security state for all TLBs within the indicated broadcast domain. // Note: stage 1 and stage 2 combined entries are in the scope of this operation.
func AArch32_DTLBI_ASID(security : SecurityState, regime : Regime, vmid : bits(NUM_VMIDBITS), broadcast_in : Broadcast, attr_in : TLBIMemAttr, Rt : bits(32)) begin assert PSTATE.EL IN {EL3, EL2, EL1}; var attr : TLBIMemAttr = attr_in;
let broadcast : Broadcast =
AArch32_EffectiveBroadcast(broadcast_in);
if ExcludeXS() then
attr = TLBI_ExcludeXS;
end;
var r : TLBIRecord;
r.op = TLBIOp_DASID;
r.from_aarch64 = FALSE;
r.security = security;
r.regime = regime;
r.vmid = vmid;
r.use_vmid = UseVMID(regime);
r.level = TLBILevel_Any;
r.attr = attr;
r.asid = Zeros{8} :: Rt[7:0];
TLBI(r);
if broadcast != Broadcast_NSH then BroadcastTLBI(broadcast, r); end;
return;
end;
## Library pseudocode for aarch32/functions/tlbi/AArch32\_DTLBI\_VA
// AArch32_DTLBI_VA // ================== // Invalidate by VA all stage 1 data TLB entries in the indicated broadcast domain // matching the indicated VMID and ASID (where regime supports VMID, ASID) in the indicated regime // with the indicated security state. // ASID, VA and related parameters are derived from Rt. // Note: stage 1 and stage 2 combined entries are in the scope of this operation.
func AArch32_DTLBI_VA(security : SecurityState, regime : Regime, vmid : bits(NUM_VMIDBITS), broadcast_in : Broadcast, level : TLBILevel, attr_in : TLBIMemAttr, Rt : bits(32)) begin assert PSTATE.EL IN {EL3, EL2, EL1}; var attr : TLBIMemAttr = attr_in;
let broadcast : Broadcast =
AArch32_EffectiveBroadcast(broadcast_in);
if ExcludeXS() then
attr = TLBI_ExcludeXS;
end;
var r : TLBIRecord;
r.op = TLBIOp_DVA;
r.from_aarch64 = FALSE;
r.security = security;
r.regime = regime;
r.vmid = vmid;
r.use_vmid = UseVMID(regime);
r.level = level;
r.attr = attr;
r.asid = Zeros{8} :: Rt[7:0];
r.address = Zeros{32} :: Rt[31:12] :: Zeros{12};
TLBI(r);
if broadcast != Broadcast_NSH then BroadcastTLBI(broadcast, r); end;
return;
end;
## Library pseudocode for aarch32/functions/tlbi/AArch32\_EffectiveBroadcast
// AArch32_EffectiveBroadcast // ============================
func AArch32_EffectiveBroadcast(broadcast_in : Broadcast) => Broadcast begin var broadcast : Broadcast = broadcast_in;
if PSTATE.EL != EL1 then return broadcast; end;
if (broadcast == Broadcast_NSH && ((ELUsingAArch32(EL2) &&
HCR().FB == '1') ||
((EL2) && HCR_EL2().FB == '1'))) then
broadcast = Broadcast_ForcedISH;
end;
return broadcast;
end;
## Library pseudocode for aarch32/functions/tlbi/AArch32\_ITLBI\_ALL
// AArch32_ITLBI_ALL // =================== // Invalidate all instruction TLB entries for the indicated translation regime with the // the indicated security state for all TLBs within the indicated broadcast domain. // Invalidation applies to all applicable stage 1 and stage 2 entries.
func AArch32_ITLBI_ALL(security : SecurityState, regime : Regime, vmid : bits(NUM_VMIDBITS), broadcast_in : Broadcast, attr_in : TLBIMemAttr) begin assert PSTATE.EL IN {EL3, EL2, EL1}; var attr : TLBIMemAttr = attr_in;
let broadcast : Broadcast =
AArch32_EffectiveBroadcast(broadcast_in);
if ExcludeXS() then
attr = TLBI_ExcludeXS;
end;
var r : TLBIRecord;
r.op = TLBIOp_IALL;
r.from_aarch64 = FALSE;
r.security = security;
r.regime = regime;
r.vmid = vmid;
r.use_vmid = UseVMID(regime);
r.level = TLBILevel_Any;
r.attr = attr;
TLBI(r);
if broadcast != Broadcast_NSH then BroadcastTLBI(broadcast, r); end;
return;
end;
## Library pseudocode for aarch32/functions/tlbi/AArch32\_ITLBI\_ASID
// AArch32_ITLBI_ASID // ==================== // Invalidate all instruction TLB stage 1 entries matching the indicated VMID // (where regime supports) and ASID in the parameter Rt in the indicated translation // regime with the indicated security state for all TLBs within the indicated broadcast domain. // Note: stage 1 and stage 2 combined entries are in the scope of this operation.
func AArch32_ITLBI_ASID(security : SecurityState, regime : Regime, vmid : bits(NUM_VMIDBITS), broadcast_in : Broadcast, attr_in : TLBIMemAttr, Rt : bits(32)) begin assert PSTATE.EL IN {EL3, EL2, EL1}; var attr : TLBIMemAttr = attr_in;
let broadcast : Broadcast =
AArch32_EffectiveBroadcast(broadcast_in);
if ExcludeXS() then
attr = TLBI_ExcludeXS;
end;
var r : TLBIRecord;
r.op = TLBIOp_IASID;
r.from_aarch64 = FALSE;
r.security = security;
r.regime = regime;
r.vmid = vmid;
r.use_vmid = UseVMID(regime);
r.level = TLBILevel_Any;
r.attr = attr;
r.asid = Zeros{8} :: Rt[7:0];
TLBI(r);
if broadcast != Broadcast_NSH then BroadcastTLBI(broadcast, r); end;
return;
end;
## Library pseudocode for aarch32/functions/tlbi/AArch32\_ITLBI\_VA
// AArch32_ITLBI_VA // ================== // Invalidate by VA all stage 1 instruction TLB entries in the indicated broadcast domain // matching the indicated VMID and ASID (where regime supports VMID, ASID) in the indicated regime // with the indicated security state. // ASID, VA and related parameters are derived from Rt. // Note: stage 1 and stage 2 combined entries are in the scope of this operation.
func AArch32_ITLBI_VA(security : SecurityState, regime : Regime, vmid : bits(NUM_VMIDBITS), broadcast_in : Broadcast, level : TLBILevel, attr_in : TLBIMemAttr, Rt : bits(32)) begin assert PSTATE.EL IN {EL3, EL2, EL1}; var attr : TLBIMemAttr = attr_in;
let broadcast : Broadcast =
AArch32_EffectiveBroadcast(broadcast_in);
if ExcludeXS() then
attr = TLBI_ExcludeXS;
end;
var r : TLBIRecord;
r.op = TLBIOp_IVA;
r.from_aarch64 = FALSE;
r.security = security;
r.regime = regime;
r.vmid = vmid;
r.use_vmid = UseVMID(regime);
r.level = level;
r.attr = attr;
r.asid = Zeros{8} :: Rt[7:0];
r.address = Zeros{32} :: Rt[31:12] :: Zeros{12};
TLBI(r);
if broadcast != Broadcast_NSH then BroadcastTLBI(broadcast, r); end;
return;
end;
## Library pseudocode for aarch32/functions/tlbi/AArch32\_TLBI\_ALL
// AArch32_TLBI_ALL // ================== // Invalidate all entries for the indicated translation regime with the // the indicated security state for all TLBs within the indicated broadcast domain. // Invalidation applies to all applicable stage 1 and stage 2 entries.
func AArch32_TLBI_ALL(security : SecurityState, regime : Regime, broadcast : Broadcast, attr : TLBIMemAttr) begin assert PSTATE.EL IN {EL3, EL2};
var r : TLBIRecord;
r.op = TLBIOp_ALL;
r.from_aarch64 = FALSE;
r.security = security;
r.regime = regime;
r.level = TLBILevel_Any;
r.attr = attr;
TLBI(r);
if broadcast != Broadcast_NSH then BroadcastTLBI(broadcast, r); end;
return;
end;
## Library pseudocode for aarch32/functions/tlbi/AArch32\_TLBI\_ASID
// AArch32_TLBI_ASID // =================== // Invalidate all stage 1 entries matching the indicated VMID (where regime supports) // and ASID in the parameter Rt in the indicated translation regime with the // indicated security state for all TLBs within the indicated broadcast domain. // Note: stage 1 and stage 2 combined entries are in the scope of this operation.
func AArch32_TLBI_ASID(security : SecurityState, regime : Regime, vmid : bits(NUM_VMIDBITS), broadcast_in : Broadcast, attr_in : TLBIMemAttr, Rt : bits(32)) begin assert PSTATE.EL IN {EL3, EL2, EL1}; var attr : TLBIMemAttr = attr_in;
let broadcast : Broadcast =
AArch32_EffectiveBroadcast(broadcast_in);
if ExcludeXS() then
attr = TLBI_ExcludeXS;
end;
var r : TLBIRecord;
r.op = TLBIOp_ASID;
r.from_aarch64 = FALSE;
r.security = security;
r.regime = regime;
r.vmid = vmid;
r.use_vmid = UseVMID(regime);
r.level = TLBILevel_Any;
r.attr = attr;
r.asid = Zeros{8} :: Rt[7:0];
TLBI(r);
if broadcast != Broadcast_NSH then BroadcastTLBI(broadcast, r); end;
return;
end;
## Library pseudocode for aarch32/functions/tlbi/AArch32\_TLBI\_IPAS2
// AArch32_TLBI_IPAS2 // ==================== // Invalidate by IPA all stage 2 only TLB entries in the indicated broadcast // domain matching the indicated VMID in the indicated regime with the indicated security state. // Note: stage 1 and stage 2 combined entries are not in the scope of this operation. // IPA and related parameters of the are derived from Rt.
func AArch32_TLBI_IPAS2(security : SecurityState, regime : Regime, vmid : bits(NUM_VMIDBITS), broadcast : Broadcast, level : TLBILevel, attr : TLBIMemAttr, Rt : bits(32)) begin assert PSTATE.EL IN {EL3, EL2}; assert security == SS_NonSecure;
var r : TLBIRecord;
r.op = TLBIOp_IPAS2;
r.from_aarch64 = FALSE;
r.security = security;
r.regime = regime;
r.vmid = vmid;
r.use_vmid = TRUE;
r.level = level;
r.attr = attr;
r.address = Zeros{24} :: Rt[27:0] :: Zeros{12};
r.ipaspace = PAS_NonSecure;
TLBI(r);
if broadcast != Broadcast_NSH then BroadcastTLBI(broadcast, r); end;
return;
end;
## Library pseudocode for aarch32/functions/tlbi/AArch32\_TLBI\_VA
// AArch32_TLBI_VA // ================= // Invalidate by VA all stage 1 TLB entries in the indicated broadcast domain // matching the indicated VMID and ASID (where regime supports VMID, ASID) in the indicated regime // with the indicated security state. // ASID, VA and related parameters are derived from Rt. // Note: stage 1 and stage 2 combined entries are in the scope of this operation.
func AArch32_TLBI_VA(security : SecurityState, regime : Regime, vmid : bits(NUM_VMIDBITS), broadcast_in : Broadcast, level : TLBILevel, attr_in : TLBIMemAttr, Rt : bits(32)) begin assert PSTATE.EL IN {EL3, EL2, EL1}; var attr : TLBIMemAttr = attr_in;
let broadcast : Broadcast =
AArch32_EffectiveBroadcast(broadcast_in);
if ExcludeXS() then
attr = TLBI_ExcludeXS;
end;
var r : TLBIRecord;
r.op = TLBIOp_VA;
r.from_aarch64 = FALSE;
r.security = security;
r.regime = regime;
r.vmid = vmid;
r.use_vmid = UseVMID(regime);
r.level = level;
r.attr = attr;
r.asid = Zeros{8} :: Rt[7:0];
r.address = Zeros{32} :: Rt[31:12] :: Zeros{12};
TLBI(r);
if broadcast != Broadcast_NSH then BroadcastTLBI(broadcast, r); end;
return;
end;
## Library pseudocode for aarch32/functions/tlbi/AArch32\_TLBI\_VAA
// AArch32_TLBI_VAA // ================== // Invalidate by VA all stage 1 TLB entries in the indicated broadcast domain // matching the indicated VMID (where regime supports VMID) and all ASID in the indicated regime // with the indicated security state. // VA and related parameters are derived from Rt. // Note: stage 1 and stage 2 combined entries are in the scope of this operation.
func AArch32_TLBI_VAA(security : SecurityState, regime : Regime, vmid : bits(NUM_VMIDBITS), broadcast_in : Broadcast, level : TLBILevel, attr_in : TLBIMemAttr, Rt : bits(32)) begin assert PSTATE.EL IN {EL3, EL2, EL1}; var attr : TLBIMemAttr = attr_in;
let broadcast : Broadcast =
AArch32_EffectiveBroadcast(broadcast_in);
if ExcludeXS() then
attr = TLBI_ExcludeXS;
end;
var r : TLBIRecord;
r.op = TLBIOp_VAA;
r.from_aarch64 = FALSE;
r.security = security;
r.regime = regime;
r.vmid = vmid;
r.use_vmid = UseVMID(regime);
r.level = level;
r.attr = attr;
r.address = Zeros{32} :: Rt[31:12] :: Zeros{12};
TLBI(r);
if broadcast != Broadcast_NSH then BroadcastTLBI(broadcast, r); end;
return;
end;
## Library pseudocode for aarch32/functions/tlbi/AArch32\_TLBI\_VMALL
// AArch32_TLBI_VMALL // ==================== // Invalidate all stage 1 entries for the indicated translation regime with the // the indicated security state for all TLBs within the indicated broadcast // domain that match the indicated VMID (where applicable). // Note: stage 1 and stage 2 combined entries are in the scope of this operation. // Note: stage 2 only entries are not in the scope of this operation.
func AArch32_TLBI_VMALL(security : SecurityState, regime : Regime, vmid : bits(NUM_VMIDBITS), broadcast_in : Broadcast, attr_in : TLBIMemAttr) begin assert PSTATE.EL IN {EL3, EL2, EL1}; var attr : TLBIMemAttr = attr_in;
let broadcast : Broadcast =
AArch32_EffectiveBroadcast(broadcast_in);
if ExcludeXS() then
attr = TLBI_ExcludeXS;
end;
var r : TLBIRecord;
r.op = TLBIOp_VMALL;
r.from_aarch64 = FALSE;
r.security = security;
r.regime = regime;
r.level = TLBILevel_Any;
r.vmid = vmid;
r.use_vmid = UseVMID(regime);
r.attr = attr;
TLBI(r);
if broadcast != Broadcast_NSH then BroadcastTLBI(broadcast, r); end;
return;
end;
## Library pseudocode for aarch32/functions/tlbi/AArch32\_TLBI\_VMALLS12
// AArch32_TLBI_VMALLS12 // ======================= // Invalidate all stage 1 and stage 2 entries for the indicated translation // regime with the indicated security state for all TLBs within the indicated // broadcast domain that match the indicated VMID.
func AArch32_TLBI_VMALLS12(security : SecurityState, regime : Regime, vmid : bits(NUM_VMIDBITS), broadcast : Broadcast, attr : TLBIMemAttr) begin assert PSTATE.EL IN {EL3, EL2};
var r : TLBIRecord;
r.op = TLBIOp_VMALLS12;
r.from_aarch64 = FALSE;
r.security = security;
r.regime = regime;
r.level = TLBILevel_Any;
r.vmid = vmid;
r.use_vmid = TRUE;
r.attr = attr;
TLBI(r);
if broadcast != Broadcast_NSH then BroadcastTLBI(broadcast, r); end;
return;
end;
## Library pseudocode for aarch32/functions/v6simd/Sat
// Sat // =====
func Sat{N}(i : integer, unsigned : boolean) => bits(N) begin let result : bits(N) = if unsigned then UnsignedSat{N}(i) else SignedSat{N}(i); return result; end;
## Library pseudocode for aarch32/ic/AArch32\_CanTrapIC
// AArch32_CanTrapIC // =================== // Determines whether the execution of the IC instruction can be trapped.
func AArch32_CanTrapIC(cacheop : CacheOp, opscope : CacheOpScope) => boolean begin return ((cacheop, opscope) || ImpDefBool( "When IC is treated as NOP, data cache maintenance operations are trapped")); end;
## Library pseudocode for aarch32/ic/AArch32\_IC
// AArch32_IC // ============ // Perform Instruction Cache Operation.
func AArch32_IC(opscope : CacheOpScope) begin let regval : bits(32) = ARBITRARY : bits(32); AArch32_IC(regval, opscope); end;
// AArch32_IC // ============ // Perform Instruction Cache Operation.
func AArch32_IC(regval : bits(32), opscope : CacheOpScope) begin var cache : CacheRecord;
cache.acctype = AccessType_IC;
cache.cachetype = CacheType_Instruction;
cache.cacheop = CacheOp_Invalidate;
cache.opscope = opscope;
cache.security = SecurityStateAtEL(PSTATE.EL);
if opscope IN {CacheOpScope_ALLU, CacheOpScope_ALLUIS} then
if (opscope == CacheOpScope_ALLUIS ||
AArch32_EffectiveBroadcast(Broadcast_NSH) == Broadcast_ForcedISH) then
cache.shareability = Shareability_ISH;
else
cache.shareability = Shareability_NSH;
end;
cache.regval = ZeroExtend{64}(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;
cache.shareability = Shareability_NSH;
cache.vaddress = ZeroExtend{64}(regval);
let size : integer = 0;
let aligned : boolean = TRUE;
let accdesc : AccessDescriptor = CreateAccDescIC(cache);
let memaddrdesc : AddressDescriptor = AArch32_TranslateAddress(regval, accdesc, aligned,
size);
if IsFault(memaddrdesc) then
AArch32_Abort(memaddrdesc.fault);
end;
cache.paddress = memaddrdesc.paddress;
CACHE_OP(cache);
end;
return;
end;
## Library pseudocode for aarch32/ic/AArch32\_TreatICAsNOP
// AArch32_TreatICAsNOP // ====================== // Determines whether the execution of the IC instruction is treated as a NOP.
func AArch32_TreatICAsNOP(cacheop : CacheOp, opscope : CacheOpScope) => boolean begin if CTR().DIC == '1' then return ImpDefBool("IC is treated as NOP"); end;
return FALSE;
end;
## Library pseudocode for
aarch32/predictionrestrict/AArch32\_RestrictPrediction
// AArch32_RestrictPrediction // ============================ // Clear all predictions in the context.
func AArch32_RestrictPrediction(val : bits(32), restriction : RestrictType) begin
var c : ExecutionCntxt;
let target_el : bits(2) = val[25:24];
// If the target EL is not implemented or the instruction is executed at an
// EL lower than the specified level, the instruction is treated as a NOP.
if (target_el) || UInt(target_el) > UInt(PSTATE.EL) then ExecuteAsNOP();
end;
let ns : bit = val[26];
let nse : bit = ARBITRARY : bit;
let ss : SecurityState = TargetSecurityState(ns, nse);
c.security = ss;
c.target_el = target_el;
if EL2Enabled() then
if PSTATE.EL IN {EL0, EL1} then
c.is_vmid_valid = TRUE;
c.all_vmid = FALSE;
c.vmid = VMID();
elsif target_el IN {EL0, EL1} then
c.is_vmid_valid = TRUE;
c.all_vmid = val[27] == '1';
c.vmid = ZeroExtend{NUM_VMIDBITS}(val[23:16]);// Only valid if val[27] == '0'
else
c.is_vmid_valid = FALSE;
end;
else
c.is_vmid_valid = FALSE;
end;
if PSTATE.EL == EL0 then
c.is_asid_valid = TRUE;
c.all_asid = FALSE;
c.asid = ASID();
elsif target_el == EL0 then
c.is_asid_valid = TRUE;
c.all_asid = val[8] == '1';
c.asid = ZeroExtend{NUM_ASIDBITS}(val[7:0]); // Only valid if val[8] == '0'
else
c.is_asid_valid = FALSE;
end;
c.restriction = restriction;
RESTRICT_PREDICTIONS(c);
end;
## Library pseudocode for aarch32/translation/attrs/AArch32\_DefaultTEXDecode
// AArch32_DefaultTEXDecode // ========================== // Apply short-descriptor format memory region attributes, without TEX remap
func AArch32_DefaultTEXDecode(TEX_in : bits(3), c_in : bit, b_in : bit, s : bit) => MemoryAttributes begin var memattrs : MemoryAttributes; var TEX : bits(3) = TEX_in; var c : bit = c_in; var b : bit = b_in;
// Reserved values map to allocated values
if (TEX == '001' && c::b == '01') || (TEX == '010' && c::b !=
'00') || TEX == '011' then
var texcb : bits(5);
(-, texcb) = ConstrainUnpredictableBits{5}(Unpredictable_RESTEXCB);
TEX = texcb[4:2]; c = texcb[1]; b = texcb[0];
end;
// Distinction between Inner Shareable and Outer Shareable is not supported in
this format
// A memory region is either Non-shareable or Outer Shareable
case TEX::c::b of
when '00000' =>
// Device-nGnRnE
memattrs.memtype = MemType_Device;
memattrs.device = DeviceType_nGnRnE;
memattrs.shareability = Shareability_OSH;
when '00001', '01000' =>
// Device-nGnRE
memattrs.memtype = MemType_Device;
memattrs.device = DeviceType_nGnRE;
memattrs.shareability = Shareability_OSH;
when '00010' =>
// Write-through Read allocate
memattrs.memtype = MemType_Normal;
memattrs.inner.attrs = MemAttr_WT;
memattrs.inner.hints = MemHint_RA;
memattrs.outer.attrs = MemAttr_WT;
memattrs.outer.hints = MemHint_RA;
memattrs.shareability = if s == '1' then Shareability_OSH else Shareability_NSH;
when '00011' =>
// Write-back Read allocate
memattrs.memtype = MemType_Normal;
memattrs.inner.attrs = MemAttr_WB;
memattrs.inner.hints = MemHint_RA;
memattrs.outer.attrs = MemAttr_WB;
memattrs.outer.hints = MemHint_RA;
memattrs.shareability = if s == '1' then Shareability_OSH else Shareability_NSH;
when '00100' =>
// Non-cacheable
memattrs.memtype = MemType_Normal;
memattrs.inner.attrs = MemAttr_NC;
memattrs.outer.attrs = MemAttr_NC;
memattrs.shareability = Shareability_OSH;
when '00110' =>
memattrs = ImpDefMemoryAttributes("IMPLEMENTATION_DEFINED");
when '00111' =>
// Write-back Read and Write allocate
memattrs.memtype = MemType_Normal;
memattrs.inner.attrs = MemAttr_WB;
memattrs.inner.hints = MemHint_RWA;
memattrs.outer.attrs = MemAttr_WB;
memattrs.outer.hints = MemHint_RWA;
memattrs.shareability = if s == '1' then Shareability_OSH else Shareability_NSH;
when '1xxxx' =>
// Cacheable, TEX[1:0] = Outer attrs, {c,b} = Inner attrs
memattrs.memtype = MemType_Normal;
memattrs.inner = DecodeSDFAttr(c::b);
memattrs.outer = DecodeSDFAttr(TEX[1:0]);
if memattrs.inner.attrs == MemAttr_NC && memattrs.outer.attrs == MemAttr_NC then
memattrs.shareability = Shareability_OSH;
else
memattrs.shareability = if s == '1' then Shareability_OSH else Shareability_NSH;
end;
otherwise =>
// Reserved, handled above
unreachable;
end;
// The Transient hint is not supported in this format
memattrs.inner.transient = FALSE;
memattrs.outer.transient = FALSE;
memattrs.tags = MemTag_Untagged;
if memattrs.inner.attrs == MemAttr_WB && memattrs.outer.attrs ==
MemAttr_WB then
memattrs.xs = '0';
else
memattrs.xs = '1';
end;
return memattrs;
end;
## Library pseudocode for aarch32/translation/attrs/AArch32\_MAIRAttr
// AArch32_MAIRAttr // ================== // Retrieve the memory attribute encoding indexed in the given MAIR
func AArch32_MAIRAttr(index : integer, mair : bits(64)) => bits(8) begin assert (index < 8); return mair[index*:8]; end;
## Library pseudocode for aarch32/translation/attrs/AArch32\_RemappedTEXDecode
// AArch32_RemappedTEXDecode // =========================== // Apply short-descriptor format memory region attributes, with TEX remap
func AArch32_RemappedTEXDecode(regime : Regime, TEX : bits(3), c : bit, b : bit, s : bit) => MemoryAttributes begin
var memattrs : MemoryAttributes;
var prrr : PRRR_Type;
var nmrr : NMRR_Type;
let region : integer{} = UInt(TEX[0]::c::b); // TEX[2:1] are ignored in this
mapping scheme
if region == 6 then
return ImpDefMemoryAttributes("IMPLEMENTATION_DEFINED");
end;
if regime == Regime_EL30 then
prrr = PRRR_S();
nmrr = NMRR_S();
elsif HaveEL(EL3) && ELUsingAArch32(EL3) then
prrr = PRRR_NS();
nmrr = NMRR_NS();
else
prrr = PRRR();
nmrr = NMRR();
end;
let base : integer{} = 2 * region;
var attrfield : bits(2) = prrr[region*:2];
if attrfield == '11' then // Reserved, maps to allocated value
(-, attrfield) = ConstrainUnpredictableBits{2}(Unpredictable_RESPRRR);
end;
case attrfield of
when '00' => // Device-nGnRnE
memattrs.memtype = MemType_Device;
memattrs.device = DeviceType_nGnRnE;
memattrs.shareability = Shareability_OSH;
when '01' => // Device-nGnRE
memattrs.memtype = MemType_Device;
memattrs.device = DeviceType_nGnRE;
memattrs.shareability = Shareability_OSH;
when '10' =>
let NSn : bit = if s == '0' then prrr.NS0 else prrr.NS1;
let NOSm : bit = prrr[region+24] AND NSn;
let IRn : bits(2) = nmrr[base+1:base];
let ORn : bits(2) = nmrr[base+17:base+16];
memattrs.memtype = MemType_Normal;
memattrs.inner = DecodeSDFAttr(IRn);
memattrs.outer = DecodeSDFAttr(ORn);
if memattrs.inner.attrs == MemAttr_NC && memattrs.outer.attrs == MemAttr_NC then
memattrs.shareability = Shareability_OSH;
else
let sh : bits(2) = NSn::NOSm;
memattrs.shareability = DecodeShareability(sh);
end;
when '11' =>
unreachable;
end;
// The Transient hint is not supported in this format
memattrs.inner.transient = FALSE;
memattrs.outer.transient = FALSE;
memattrs.tags = MemTag_Untagged;
if memattrs.inner.attrs == MemAttr_WB && memattrs.outer.attrs ==
MemAttr_WB then
memattrs.xs = '0';
else
memattrs.xs = '1';
end;
return memattrs;
end;
## Library pseudocode for aarch32/translation/attrs/ImpDefMemoryAttributes
// ImpDefMemoryAttributes // ======================== // Return an IMPLEMENTATION DEFINED set of memory attributes identified by the string parameter.
impdef func ImpDefMemoryAttributes(x : string) => MemoryAttributes begin return ARBITRARY : MemoryAttributes; end;
## Library pseudocode for aarch32/translation/debug/AArch32\_CheckBreakpoint
// AArch32_CheckBreakpoint // ========================= // Called before executing the instruction of length "size" bytes at "vaddress" in an AArch32 // translation regime, when either debug exceptions are enabled, or halting debug is enabled // and halting is allowed.
func AArch32_CheckBreakpoint(fault_in : FaultRecord, vaddress : bits(32), accdesc : AccessDescriptor, size : integer) => FaultRecord begin assert ELUsingAArch32(S1TranslationRegime()); assert size IN {2,4};
var fault : FaultRecord = fault_in;
var match : boolean = FALSE;
var mismatch : boolean = FALSE;
var brkptinfo : BreakpointInfo;
for i = 0 to NumBreakpointsImplemented() - 1 do
brkptinfo = AArch32_BreakpointMatch(i, vaddress, accdesc, size);
match = match || brkptinfo.match;
mismatch = mismatch || brkptinfo.mismatch;
end;
if match && HaltOnBreakpointOrWatchpoint() then
let reason : bits(6) = DebugHalt_Breakpoint;
Halt(reason);
elsif (match || mismatch) then
fault.statuscode = Fault_Debug;
fault.debugmoe = DebugException_Breakpoint;
fault.vaddress = ZeroExtend{64}(vaddress);
end;
return fault;
end;
## Library pseudocode for aarch32/translation/debug/AArch32\_CheckDebug
// AArch32_CheckDebug // ==================== // Called on each access to check for a debug exception or entry to Debug state.
func AArch32_CheckDebug(vaddress : bits(32), accdesc : AccessDescriptor, size : integer) => FaultRecord begin
var fault : FaultRecord = NoFault(accdesc,
ZeroExtend{64}(vaddress));
let d_side : boolean = IsWatchpointableAccess(accdesc);
let i_side : boolean = (accdesc.acctype == AccessType_IFETCH);
let generate_exception : boolean = (AArch32_GenerateDebugExceptions()
&&
DBGDSCRext().MDBGen == '1');
let halt : boolean = HaltOnBreakpointOrWatchpoint();
// Relative priority of Vector Catch and Breakpoint exceptions not defined in
the architecture
let vector_catch_first : boolean =
ConstrainUnpredictableBool(Unpredictable_BPVECTORCATCHPRI);
if i_side && vector_catch_first && generate_exception then
fault = AArch32_CheckVectorCatch(fault, vaddress, size);
end;
if fault.statuscode == Fault_None && (generate_exception || halt) then
if d_side then
fault = AArch32_CheckWatchpoint(fault, vaddress, accdesc, size);
elsif i_side then
fault = AArch32_CheckBreakpoint(fault, vaddress, accdesc, size);
end;
end;
if fault.statuscode == Fault_None && i_side &&
!vector_catch_first && generate_exception then
return AArch32_CheckVectorCatch(fault, vaddress, size);
end;
return fault;
end;
## Library pseudocode for aarch32/translation/debug/AArch32\_CheckVectorCatch
// AArch32_CheckVectorCatch // ========================== // Called before executing the instruction of length "size" bytes at "vaddress" in an AArch32 // translation regime, when debug exceptions are enabled.
func AArch32_CheckVectorCatch(fault_in : FaultRecord, vaddress : bits(32), size : integer) => FaultRecord begin assert ELUsingAArch32(S1TranslationRegime());
var fault : FaultRecord = fault_in;
var match : boolean = AArch32_VCRMatch(vaddress);
if size == 4 && !match && AArch32_VCRMatch(vaddress + 2) then
match = ConstrainUnpredictableBool(Unpredictable_VCMATCHHALF);
end;
if match then
fault.statuscode = Fault_Debug;
fault.debugmoe = DebugException_VectorCatch;
end;
return fault;
end;
## Library pseudocode for aarch32/translation/debug/AArch32\_CheckWatchpoint
// AArch32_CheckWatchpoint // ========================= // Called before accessing the memory location of "size" bytes at "address", // when either debug exceptions are enabled for the access, or halting debug // is enabled and halting is allowed.
func AArch32_CheckWatchpoint(fault_in : FaultRecord, vaddress : bits(32), accdesc : AccessDescriptor, size : integer) => FaultRecord begin assert ELUsingAArch32(S1TranslationRegime()); var fault : FaultRecord = fault_in; var match : boolean = FALSE;
if (accdesc) then
return fault;
end;
for i = 0 to NumWatchpointsImplemented() - 1 do
let watchptinfo : WatchpointInfo = AArch32_WatchpointMatch(i, vaddress, size, accdesc);
match = match || watchptinfo.value_match;
end;
if match && HaltOnBreakpointOrWatchpoint() then
let reason : bits(6) = DebugHalt_Watchpoint;
EDWAR() = ZeroExtend{64}(vaddress);
Halt(reason);
elsif match then
fault.statuscode = Fault_Debug;
fault.debugmoe = DebugException_Watchpoint;
fault.vaddress = ZeroExtend{64}(vaddress);
end;
return fault;
end;
## Library pseudocode for aarch32/translation/faults/AArch32\_IPAIsOutOfRange
// AArch32_IPAIsOutOfRange // ========================= // Check intermediate physical address bits not resolved by translation are ZERO
func AArch32_IPAIsOutOfRange(walkparams : S2TTWParams, ipa : bits(40)) => boolean begin // Input Address size let iasize : integer{} = AArch32_S2IASize(walkparams.t0sz);
return iasize < 40 && !IsZero(ipa[39:iasize]);
end;
## Library pseudocode for
aarch32/translation/faults/AArch32\_S1HasAlignmentFaultDueToMemType
// AArch32_S1HasAlignmentFaultDueToMemType // ========================================= // Returns whether stage 1 output fails alignment requirement on data accesses to memory type
func AArch32_S1HasAlignmentFaultDueToMemType(accdesc : AccessDescriptor, aligned : boolean, ntlsmd : bit, memattrs : MemoryAttributes) => boolean begin if memattrs.memtype != MemType_Device then return FALSE; elsif accdesc.a32lsmd && ntlsmd == '0' then return memattrs.device != DeviceType_GRE; elsif accdesc.acctype == AccessType_DCZero then return TRUE; elsif !aligned then return !(ImpDefBool("Device location supports unaligned access")); else return FALSE; end; end;
## Library pseudocode for
aarch32/translation/faults/AArch32\_S1LDHasPermissionsFault
// AArch32_S1LDHasPermissionsFault // ================================= // Returns whether an access using stage 1 long-descriptor translation // violates permissions of target memory
func AArch32_S1LDHasPermissionsFault(regime : Regime, walkparams : S1TTWParams, perms : Permissions, memtype : MemType, paspace : PASpace, accdesc : AccessDescriptor) => boolean begin var r, w, x : bit; var pr, pw : bit; var ur, uw : bit; var xn : bit; if HasUnprivileged(regime) then // Apply leaf permissions case perms.ap[2:1] of when '00' => (pr,pw,ur,uw) = ('1','1','0','0'); // R/W at PL1 only when '01' => (pr,pw,ur,uw) = ('1','1','1','1'); // R/W at any PL when '10' => (pr,pw,ur,uw) = ('1','0','0','0'); // RO at PL1 only when '11' => (pr,pw,ur,uw) = ('1','0','1','0'); // RO at any PL end;
// Apply hierarchical permissions
case perms.ap_table of
when '00' => (pr,pw,ur,uw) = ( pr, pw, ur, uw); // No effect
when '01' => (pr,pw,ur,uw) = ( pr, pw,'0','0'); // Privileged access
when '10' => (pr,pw,ur,uw) = ( pr,'0', ur,'0'); // Read-only
when '11' => (pr,pw,ur,uw) = ( pr,'0','0','0'); // Read-only, privileged access
end;
xn = perms.xn OR perms.xn_table;
let pxn : bit = perms.pxn OR perms.pxn_table;
let ux : bit = ur AND NOT(xn OR (uw AND walkparams.wxn));
let px : bit = pr AND NOT(xn OR pxn OR (pw AND walkparams.wxn) OR (uw AND walkparams.uwxn));
if IsFeatureImplemented(FEAT_PAN) && accdesc.pan then
let pan : bit = PSTATE.PAN AND (ur OR uw);
pr = pr AND NOT(pan);
pw = pw AND NOT(pan);
end;
(r,w,x) = if accdesc.el == EL0 then (ur,uw,ux) else (pr,pw,px);
// Prevent execution from Non-secure space by PE in Secure state if SIF is set
if accdesc.ss == SS_Secure && paspace == PAS_NonSecure then
x = x AND NOT(walkparams.sif);
end;
else
// Apply leaf permissions
case perms.ap[2] of
when '0' => (r,w) = ('1','1'); // No effect
when '1' => (r,w) = ('1','0'); // Read-only
end;
// Apply hierarchical permissions
case perms.ap_table[1] of
when '0' => (r,w) = ( r, w ); // No effect
when '1' => (r,w) = ( r, '0'); // Read-only
end;
xn = perms.xn OR perms.xn_table;
x = NOT(xn OR (w AND walkparams.wxn));
end;
if accdesc.acctype == AccessType_IFETCH then
let constraint : Constraint = ConstrainUnpredictable(Unpredictable_INSTRDEVICE);
if constraint == Constraint_FAULT && memtype == MemType_Device then
return TRUE;
else
return x == '0';
end;
elsif accdesc.acctype IN {AccessType_IC, AccessType_DC} then
return FALSE;
elsif accdesc.write then
return w == '0';
else
return r == '0';
end;
end;
## Library pseudocode for
aarch32/translation/faults/AArch32\_S1SDHasPermissionsFault
// AArch32_S1SDHasPermissionsFault // ================================= // Returns whether an access using stage 1 short-descriptor translation // violates permissions of target memory
func AArch32_S1SDHasPermissionsFault(regime : Regime, perms_in : Permissions, memtype : MemType, paspace : PASpace, accdesc : AccessDescriptor) => boolean begin var perms : Permissions = perms_in; var pr, pw : bit; var ur, uw : bit; var sctlr : SCTLR_Type; if regime == Regime_EL30 then sctlr = SCTLR_S(); elsif HaveEL(EL3) && ELUsingAArch32(EL3) then sctlr = SCTLR_NS(); else sctlr = SCTLR(); end;
if sctlr.AFE == '0' then
// Map Reserved encoding '100'
if perms.ap == '100' then
perms.ap = ImpDefBits{3}("Reserved short descriptor AP encoding");
end;
case perms.ap of
when '000' => (pr,pw,ur,uw) = ('0','0','0','0'); // No access
when '001' => (pr,pw,ur,uw) = ('1','1','0','0'); // R/W at PL1 only
when '010' => (pr,pw,ur,uw) = ('1','1','1','0'); // R/W at PL1, RO at PL0
when '011' => (pr,pw,ur,uw) = ('1','1','1','1'); // R/W at any PL
// '100' is reserved
when '101' => (pr,pw,ur,uw) = ('1','0','0','0'); // RO at PL1 only
when '110' => (pr,pw,ur,uw) = ('1','0','1','0'); // RO at any PL (deprecated)
when '111' => (pr,pw,ur,uw) = ('1','0','1','0'); // RO at any PL
end;
else // Simplified access permissions model
case perms.ap[2:1] of
when '00' => (pr,pw,ur,uw) = ('1','1','0','0'); // R/W at PL1 only
when '01' => (pr,pw,ur,uw) = ('1','1','1','1'); // R/W at any PL
when '10' => (pr,pw,ur,uw) = ('1','0','0','0'); // RO at PL1 only
when '11' => (pr,pw,ur,uw) = ('1','0','1','0'); // RO at any PL
end;
end;
let ux : bit = ur AND NOT(perms.xn OR (uw AND sctlr.WXN));
let px : bit = pr AND NOT(perms.xn OR perms.pxn OR (pw AND sctlr.WXN) OR (uw
AND sctlr.UWXN));
if IsFeatureImplemented(FEAT_PAN) && accdesc.pan then
let pan : bit = PSTATE.PAN AND (ur OR uw);
pr = pr AND NOT(pan);
pw = pw AND NOT(pan);
end;
var (r,w,x) : (bit, bit, bit) = if accdesc.el == EL0 then (ur,uw,ux) else
(pr,pw,px);
// Prevent execution from Non-secure space by PE in Secure state if SIF is set
if accdesc.ss == SS_Secure && paspace == PAS_NonSecure then
x = x AND NOT(if ELUsingAArch32(EL3) then SCR().SIF else SCR_EL3().SIF);
end;
if accdesc.acctype == AccessType_IFETCH then
if (memtype == MemType_Device &&
ConstrainUnpredictable(Unpredictable_INSTRDEVICE) == Constraint_FAULT) then
return TRUE;
else
return x == '0';
end;
elsif accdesc.acctype IN {AccessType_IC, AccessType_DC} then
return FALSE;
elsif accdesc.write then
return w == '0';
else
return r == '0';
end;
end;
## Library pseudocode for
aarch32/translation/faults/AArch32\_S2HasAlignmentFaultDueToMemType
// AArch32_S2HasAlignmentFaultDueToMemType // ========================================= // Returns whether stage 2 output fails alignment requirement on data accesses due to memory type
func AArch32_S2HasAlignmentFaultDueToMemType(accdesc : AccessDescriptor, aligned : boolean, memattrs : MemoryAttributes) => boolean begin
if memattrs.memtype != MemType_Device then
return FALSE;
elsif accdesc.acctype == AccessType_DCZero then
return TRUE;
elsif !aligned then
return !(ImpDefBool("Device location supports unaligned access"));
else
return FALSE;
end;
end;
## Library pseudocode for
aarch32/translation/faults/AArch32\_S2HasPermissionsFault
// AArch32_S2HasPermissionsFault // =============================== // Returns whether stage 2 access violates permissions of target memory
func AArch32_S2HasPermissionsFault(walkparams : S2TTWParams, perms : Permissions, memtype : MemType, accdesc : AccessDescriptor) => boolean begin let r : bit = perms.s2ap[0]; let w : bit = perms.s2ap[1]; var x : bit; var ux : bit; var px : bit; if IsFeatureImplemented(FEAT_XNX) then case perms.s2xn::perms.s2xnx of when '00' => (px, ux) = ( r, r ); when '01' => (px, ux) = ('0', r ); when '10' => (px, ux) = ('0', '0'); when '11' => (px, ux) = ( r, '0'); end;
x = if accdesc.el == EL0 then ux else px;
else
x = r AND NOT(perms.s2xn);
end;
if accdesc.acctype == AccessType_TTW then
return (walkparams.ptw == '1' && memtype == MemType_Device) || r == '0';
elsif accdesc.acctype == AccessType_IFETCH then
let constraint : Constraint = ConstrainUnpredictable(Unpredictable_INSTRDEVICE);
return (constraint == Constraint_FAULT && memtype == MemType_Device) || x == '0';
elsif accdesc.acctype IN {AccessType_IC, AccessType_DC} then
return FALSE;
elsif accdesc.write then
return w == '0';
else
return r == '0';
end;
end;
## Library pseudocode for aarch32/translation/faults/AArch32\_S2InconsistentSL
// AArch32_S2InconsistentSL // ========================== // Detect inconsistent configuration of stage 2 T0SZ and SL fields
func AArch32_S2InconsistentSL(walkparams : S2TTWParams) => boolean begin let startlevel : integer = AArch32_S2StartLevel(walkparams.sl0); let levels : integer = FINAL_LEVEL - startlevel; let granulebits : AddressSize = TGxGranuleBits(walkparams.tgx); let stride : integer{} = granulebits - 3;
// Input address size must at least be large enough to be resolved
from the start level
let sl_min_iasize : integer = (
levels * stride // Bits resolved by table walk, except initial level
+ granulebits // Bits directly mapped to output address
+ 1); // At least 1 more bit to be decoded by initial level
// Can accommodate 1 more stride in the level + concatenation of up to 2^4
tables
let sl_max_iasize : integer = sl_min_iasize + (stride-1) + 4;
// Configured Input Address size
let iasize : AddressSize = AArch32_S2IASize(walkparams.t0sz);
return iasize < sl_min_iasize || iasize > sl_max_iasize;
end;
## Library pseudocode for aarch32/translation/faults/AArch32\_VAIsOutOfRange
// AArch32_VAIsOutOfRange // ======================== // Check virtual address bits not resolved by translation are identical // and of accepted value
func AArch32_VAIsOutOfRange(regime : Regime, walkparams : S1TTWParams, va : bits(32)) => boolean begin if regime == Regime_EL2 then // Input Address size let iasize : integer{} = AArch32_S1IASize(walkparams.t0sz); return walkparams.t0sz != '000' && !IsZero(va[31:iasize]); elsif walkparams.t1sz != '000' && walkparams.t0sz != '000' then // Lower range Input Address size let lo_iasize : integer{} = AArch32_S1IASize(walkparams.t0sz); // Upper range Input Address size let up_iasize : integer{} = AArch32_S1IASize(walkparams.t1sz); return !IsZero(va[31:lo_iasize]) && !IsOnes(va[31:up_iasize]); else return FALSE; end; end;
## Library pseudocode for
aarch32/translation/tlbcontext/AArch32\_GetS1TLBContext
// AArch32_GetS1TLBContext // ========================= // Gather translation context for accesses with VA to match against TLB entries
func AArch32_GetS1TLBContext(regime : Regime, ss : SecurityState, va : bits(32)) => TLBContext begin var tlbcontext : TLBContext;
case regime of
when Regime_EL2 => tlbcontext = AArch32_TLBContextEL2(va);
when Regime_EL10 => tlbcontext = AArch32_TLBContextEL10(ss, va);
when Regime_EL30 => tlbcontext = AArch32_TLBContextEL30(va);
end;
tlbcontext.includes_s1 = TRUE;
// The following may be amended for EL1&0 Regime if caching of stage 2 is
successful
tlbcontext.includes_s2 = FALSE;
return tlbcontext;
end;
## Library pseudocode for
aarch32/translation/tlbcontext/AArch32\_GetS2TLBContext
// AArch32_GetS2TLBContext // ========================= // Gather translation context for accesses with IPA to match against TLB entries
func AArch32_GetS2TLBContext(ipa : FullAddress) => TLBContext begin assert ipa.paspace == PAS_NonSecure;
var tlbcontext : TLBContext;
tlbcontext.ss = SS_NonSecure;
tlbcontext.regime = Regime_EL10;
tlbcontext.ipaspace = ipa.paspace;
tlbcontext.vmid = ZeroExtend{NUM_VMIDBITS}(VTTBR().VMID);
tlbcontext.tg = TGx_4KB;
tlbcontext.includes_s1 = FALSE;
tlbcontext.includes_s2 = TRUE;
tlbcontext.ia = ZeroExtend{64}(ipa.address);
tlbcontext.cnp = if IsFeatureImplemented(FEAT_TTCNP) then VTTBR().CnP else
'0';
return tlbcontext;
end;
## Library pseudocode for
aarch32/translation/tlbcontext/AArch32\_TLBContextEL10
// AArch32_TLBContextEL10 // ======================== // Gather translation context for accesses under EL10 regime // (PL10 when EL3 is A64) to match against TLB entries
func AArch32_TLBContextEL10(ss : SecurityState, va : bits(32)) => TLBContext begin var tlbcontext : TLBContext; var ttbcr : TTBCR_Type; var ttbr0 : TTBR0_Type; var ttbr1 : TTBR1_Type; var contextidr : CONTEXTIDR_Type;
if HaveEL(EL3) && ELUsingAArch32(EL3) then
ttbcr = TTBCR_NS();
ttbr0 = TTBR0_NS();
ttbr1 = TTBR1_NS();
contextidr = CONTEXTIDR_NS();
else
ttbcr = TTBCR();
ttbr0 = TTBR0();
ttbr1 = TTBR1();
contextidr = CONTEXTIDR();
end;
tlbcontext.ss = ss;
tlbcontext.regime = Regime_EL10;
if AArch32_EL2Enabled(ss) then
tlbcontext.vmid = ZeroExtend{NUM_VMIDBITS}(VTTBR().VMID);
end;
if ttbcr.EAE == '1' then
if ttbcr.A1 == '0' then
tlbcontext.asid = ZeroExtend{NUM_ASIDBITS}(ttbr0.ASID);
else
tlbcontext.asid = ZeroExtend{NUM_ASIDBITS}(ttbr1.ASID);
------------------------------------------------------------------------------
Page 1 of 1.
End of thread.