[Writeup] Shared pseudocode: part 22 of 36 ========================================== Section: Silicon & Architectures Started: 2026-11-28 17:46 UTC by admin Replies: 0, last post 2026-11-28 17:46 UTC Page: 1 of 1 Web: https://romdump.net/t/114 ------------------------------------------------------------------------------ #134 admin, 2026-11-28 17:46 UTC [OP] Source: https://romdump.net/raw/134
Shared pseudocode from the offline Arm documentation snapshot. Part 22 of 36.
if (regime == Regime_EL10 && EL2Enabled() &&
HCR_EL2().VM == '1' &&
!(ImpDefBool("Apply effective shareability at stage 1"))) then
walkaddress.memattrs.shareability = walkstate.memattrs.shareability;
else
walkaddress.memattrs.shareability = EffectiveShareability(walkaddress.memattrs);
end;
var s2fs1mro : boolean = FALSE;
var desctype : DescriptorType;
var descaddress : FullAddress = AArch64_S1SLTTEntryAddress(walkstate.level,
walkparams, va,
walkstate.baseaddress);
// Detect Address Size Fault by Descriptor Address
if AArch64_S1OAOutOfRange(descaddress.address, walkparams) then
fault.statuscode = Fault_AddressSize;
fault.level = 0;
return (fault, ARBITRARY : AddressDescriptor, ARBITRARY : TTWState, ARBITRARY : bits(N));
end;
repeat
fault.level = walkstate.level;
walkaddress.paddress = descaddress;
walkaddress.s1assured = walkstate.s1assured;
let toplevel : boolean = walkstate.level == startlevel;
let varange : VARange = AArch64_GetVARange(va);
let walkaccess : AccessDescriptor = CreateAccDescS1TTW(toplevel, varange, accdesc);
var s2fault : FaultRecord;
var s2walkaddress : AddressDescriptor;
if regime == Regime_EL10 && EL2Enabled() then
let s1aarch64 : boolean = TRUE;
aligned = TRUE;
(s2fault, s2walkaddress) = AArch64_S2Translate(fault, walkaddress, s1aarch64, aligned,
walkaccess);
if s2fault.statuscode != Fault_None then
return (s2fault, ARBITRARY : AddressDescriptor, ARBITRARY : TTWState,
ARBITRARY : bits(N));
end;
s2fs1mro = s2walkaddress.s2fs1mro;
(fault, descriptor) = FetchDescriptor{N}(walkparams.ee, s2walkaddress, walkaccess,
fault);
else
(fault, descriptor) = FetchDescriptor{N}(walkparams.ee, walkaddress, walkaccess,
fault);
end;
if fault.statuscode != Fault_None then
return (fault, ARBITRARY : AddressDescriptor, ARBITRARY : TTWState,
ARBITRARY : bits(N));
end;
var new_descriptor : bits(N);
repeat
new_descriptor = descriptor;
desctype = AArch64_DecodeDescriptorType{N}(descriptor, walkparams.d128, walkparams.ds,
walkparams.tgx, walkstate.level);
case desctype of
when DescriptorType_Table =>
walkstate = AArch64_S1NextWalkStateTable{N}(walkstate, s2fs1mro,
regime, walkparams, descriptor);
skl = if walkparams.d128 == '1' then descriptor[110:109] else '00';
descaddress = AArch64_S1TTEntryAddress{N}(walkstate.level, walkparams, skl, va,
walkstate.baseaddress, descriptor);
// Detect Address Size Fault by Descriptor Address
if AArch64_S1OAOutOfRange(descaddress.address, walkparams) then
fault.statuscode = Fault_AddressSize;
return (fault, ARBITRARY : AddressDescriptor, ARBITRARY : TTWState,
ARBITRARY : bits(N));
end;
if walkparams.haft == '1' then
new_descriptor[10] = '1';
end;
if (walkparams.d128 == '1' && skl != '00' &&
AArch64_nTFaults{N}(walkparams.d128, descriptor)) then
fault.statuscode = Fault_Translation;
return (fault, ARBITRARY : AddressDescriptor, ARBITRARY : TTWState,
ARBITRARY : bits(N));
end;
when DescriptorType_Leaf =>
walkstate = AArch64_S1NextWalkStateLeaf{N}(walkstate, s2fs1mro, regime, accdesc,
walkparams, descriptor);
when DescriptorType_Invalid =>
fault.statuscode = Fault_Translation;
return (fault, ARBITRARY : AddressDescriptor, ARBITRARY : TTWState,
ARBITRARY : bits(N));
otherwise =>
unreachable;
end;
if new_descriptor != descriptor then
if ((walkaddress.memattrs) &&
ConstrainUnpredictableBool(Unpredictable_Unsupported_Atomic_HW_Update)) then
fault.statuscode = Fault_UnsupportedAtomicHWUpdate;
return (fault, ARBITRARY : AddressDescriptor, ARBITRARY : TTWState,
ARBITRARY : bits(N));
end;
var descpaddr : AddressDescriptor;
let descaccess : AccessDescriptor = CreateAccDescTTEUpdate(accdesc);
if regime == Regime_EL10 && EL2Enabled() then
let s1aarch64 : boolean = TRUE;
aligned = TRUE;
(s2fault, descpaddr) = AArch64_S2Translate(fault, walkaddress,
s1aarch64, aligned,
descaccess);
if s2fault.statuscode != Fault_None then
return (s2fault, ARBITRARY : AddressDescriptor,
ARBITRARY : TTWState, ARBITRARY : bits(N));
end;
else
descpaddr = walkaddress;
end;
(fault, descriptor) = AArch64_MemSwapTableDesc{N}(fault, descriptor, new_descriptor,
walkparams.ee, descaccess,
descpaddr);
if fault.statuscode != Fault_None then
return (fault, ARBITRARY : AddressDescriptor,
ARBITRARY : TTWState, ARBITRARY : bits(N));
end;
end;
until new_descriptor == descriptor looplimit Unbounded_DescriptorUpdate;
until desctype == DescriptorType_Leaf looplimit MAX_WALK_LEVELS;
let oa : FullAddress = Stage1OA(va, walkparams, walkstate);
if walkstate.contiguous == '1' &&
AArch64_S1ContiguousBitFaults(walkparams, walkstate) then
fault.statuscode = Fault_Translation;
elsif walkstate.level < FINAL_LEVEL &&
AArch64_nTFaults{N}(walkparams.d128, descriptor) then
fault.statuscode = Fault_Translation;
elsif AArch64_S1AMECFault{N}(walkparams, walkstate.baseaddress.paspace,
regime, descriptor) then
fault.statuscode = Fault_Translation;
// Detect Address Size Fault by final output
elsif AArch64_S1OAOutOfRange(oa.address, walkparams) then
fault.statuscode = Fault_AddressSize;
// Check descriptor AF bit
elsif (descriptor[10] == '0' && walkparams.ha == '0' &&
(!accdesc.acctype IN {AccessType_DC, AccessType_IC} ||
ImpDefBool("Generate access flag fault on IC/DC operations"))) then
fault.statuscode = Fault_AccessFlag;
end;
if fault.statuscode != Fault_None then
return (fault, ARBITRARY : AddressDescriptor, ARBITRARY : TTWState, ARBITRARY : bits(N));
end;
return (fault, walkaddress, walkstate, descriptor);
end;
## Library pseudocode for
aarch64/translation/vmsa\_walk/AArch64\_S2InitialTTWState
// AArch64_S2InitialTTWState // =========================== // Set properties of first access to translation tables in stage 2
func AArch64_S2InitialTTWState(ss : SecurityState, walkparams : S2TTWParams) => TTWState begin var walkstate : TTWState; var tablebase : FullAddress; var ttbr : bits(128);
ttbr = ZeroExtend{128}(VTTBR_EL2());
case ss of
when SS_NonSecure => tablebase.paspace = PAS_NonSecure;
when SS_Realm => tablebase.paspace = PAS_Realm;
end;
tablebase.address = AArch64_S2TTBaseAddress{128}(walkparams,
tablebase.paspace, ttbr);
walkstate.baseaddress = tablebase;
walkstate.level = AArch64_S2StartLevel(walkparams);
walkstate.istable = TRUE;
walkstate.memattrs = WalkMemAttrs(walkparams.sh, walkparams.irgn,
walkparams.orgn);
return walkstate;
end;
## Library pseudocode for
aarch64/translation/vmsa\_walk/AArch64\_S2NextWalkStateLeaf
// AArch64_S2NextWalkStateLeaf // ============================= // Decode stage 2 page or block descriptor as output to this stage of translation
func AArch64_S2NextWalkStateLeaf{N}(currentstate : TTWState, ss : SecurityState, walkparams : S2TTWParams, ipa : AddressDescriptor, descriptor : bits(N)) => TTWState begin var nextstate : TTWState; var baseaddress : FullAddress;
if ss == SS_Secure then
baseaddress.paspace = AArch64_SS2OutputPASpace(walkparams, ipa.paddress.paspace);
elsif ss == SS_Realm then
var ns : bit;
ns = if walkparams.d128 == '1' then descriptor[127] else descriptor[55];
baseaddress.paspace = if ns == '1' then PAS_NonSecure else PAS_Realm;
else
baseaddress.paspace = PAS_NonSecure;
end;
baseaddress.address = AArch64_S2LeafBase{N}(descriptor, walkparams,
currentstate.level);
nextstate.istable = FALSE;
nextstate.level = currentstate.level;
nextstate.baseaddress = baseaddress;
nextstate.permissions = AArch64_S2ApplyOutputPerms{N}(descriptor, walkparams);
let s2_attr : bits(4) = descriptor[5:2];
let s2_sh : bits(2) = if walkparams.ds == '1' then walkparams.sh else
descriptor[9:8];
let s2_fnxs : bit = descriptor[11];
if walkparams.fwb == '1' then
nextstate.memattrs = AArch64_S2ApplyFWBMemAttrs{N}(ipa.memattrs, walkparams, descriptor);
if s2_attr[3:1] == '111' then
nextstate.permissions.s2tag_na = '1';
else
nextstate.permissions.s2tag_na = '0';
end;
else
let s2aarch64 : boolean = TRUE;
nextstate.memattrs = S2DecodeMemAttrs(s2_attr, s2_sh, s2aarch64);
// FnXS is used later to mask the XS value from stage 1
nextstate.memattrs.xs = NOT s2_fnxs;
if s2_attr == '0100' then
nextstate.permissions.s2tag_na = '1';
else
nextstate.permissions.s2tag_na = '0';
end;
end;
nextstate.contiguous = AArch64_ContiguousBit{N}(walkparams.tgx,
walkparams.d128,
currentstate.level, descriptor);
if walkparams.d128 == '1' then
nextstate.s2assuredonly = descriptor[114];
else
nextstate.s2assuredonly = if walkparams.assuredonly == '1' then descriptor[58] else '0';
end;
return nextstate;
end;
## Library pseudocode for
aarch64/translation/vmsa\_walk/AArch64\_S2NextWalkStateTable
// AArch64_S2NextWalkStateTable // ============================== // Decode stage 2 table descriptor to transition to the next level
func AArch64_S2NextWalkStateTable{N}(currentstate : TTWState, walkparams : S2TTWParams, descriptor : bits(N)) => TTWState begin var nextstate : TTWState; var tablebase : FullAddress; let skl : bits(2) = if walkparams.d128 == '1' then descriptor[110:109] else '00'; tablebase.address = AArch64_NextTableBase{N}(descriptor, walkparams.d128, skl, walkparams.ds, walkparams.tgx);
tablebase.paspace = currentstate.baseaddress.paspace;
nextstate.istable = TRUE;
if walkparams.d128 == '1' then
nextstate.level = currentstate.level + UInt(skl) + 1;
else
nextstate.level = currentstate.level + 1;
end;
nextstate.baseaddress = tablebase;
nextstate.memattrs = currentstate.memattrs;
return nextstate;
end;
## Library pseudocode for aarch64/translation/vmsa\_walk/AArch64\_S2Walk
// AArch64_S2Walk // ================ // Traverse stage 2 translation tables obtaining the final descriptor // as well as the address leading to that descriptor
func AArch64_S2Walk{N : integer{64, 128}}(fault_in : FaultRecord, ipa : AddressDescriptor, walkparams : S2TTWParams, accdesc : AccessDescriptor) => (FaultRecord, AddressDescriptor, TTWState, bits(N)) begin
var fault : FaultRecord = fault_in;
var walkstate : TTWState;
if accdesc.ss == SS_Secure then
walkstate = AArch64_SS2InitialTTWState(walkparams, ipa.paddress.paspace);
else
walkstate = AArch64_S2InitialTTWState(accdesc.ss, walkparams);
end;
let startlevel : integer = walkstate.level;
if startlevel > 3 then
fault.statuscode = Fault_Translation;
fault.level = 0;
return (fault, ARBITRARY : AddressDescriptor, ARBITRARY : TTWState, ARBITRARY : bits(N));
end;
var descriptor : bits(N);
let walkaccess : AccessDescriptor = CreateAccDescS2TTW(accdesc);
var walkaddress : AddressDescriptor;
var skl : bits(2) = '00';
walkaddress.vaddress = ipa.vaddress;
walkaddress.mecid = AArch64_S2TTWalkMECID(walkparams.emec, accdesc.ss);
if () then
walkaddress.memattrs = NormalNCMemAttr();
walkaddress.memattrs.xs = walkstate.memattrs.xs;
else
walkaddress.memattrs = walkstate.memattrs;
end;
walkaddress.memattrs.shareability =
EffectiveShareability(walkaddress.memattrs);
var desctype : DescriptorType;
// Initial lookup might index into concatenated tables
var descaddress : FullAddress = AArch64_S2SLTTEntryAddress(walkparams,
ipa.paddress.address,
walkstate.baseaddress);
// Detect Address Size Fault by Descriptor Address
if AArch64_S2OAOutOfRange(descaddress.address, walkparams) then
fault.statuscode = Fault_AddressSize;
fault.level = 0;
return (fault, ARBITRARY : AddressDescriptor, ARBITRARY : TTWState, ARBITRARY : bits(N));
end;
repeat
fault.level = walkstate.level;
walkaddress.paddress = descaddress;
(fault, descriptor) = FetchDescriptor{N}(walkparams.ee, walkaddress, walkaccess, fault);
if fault.statuscode != Fault_None then
return (fault, ARBITRARY : AddressDescriptor,
ARBITRARY : TTWState, ARBITRARY : bits(N));
end;
var new_descriptor : bits(N);
repeat
new_descriptor = descriptor;
desctype = AArch64_DecodeDescriptorType{N}(descriptor, walkparams.d128, walkparams.ds,
walkparams.tgx, walkstate.level);
case desctype of
when DescriptorType_Table =>
walkstate = AArch64_S2NextWalkStateTable{N}(walkstate, walkparams, descriptor);
skl = if walkparams.d128 == '1' then descriptor[110:109] else '00';
descaddress = AArch64_S2TTEntryAddress(walkstate.level, walkparams, skl,
ipa.paddress.address,
walkstate.baseaddress);
// Detect Address Size Fault by table descriptor
if AArch64_S2OAOutOfRange(descaddress.address, walkparams) then
fault.statuscode = Fault_AddressSize;
return (fault, ARBITRARY : AddressDescriptor, ARBITRARY : TTWState,
ARBITRARY : bits(N));
end;
if walkparams.haft == '1' then
new_descriptor[10] = '1';
end;
if (walkparams.d128 == '1' && skl != '00' &&
AArch64_nTFaults{N}(walkparams.d128, descriptor)) then
fault.statuscode = Fault_Translation;
return (fault, ARBITRARY : AddressDescriptor, ARBITRARY : TTWState,
ARBITRARY : bits(N));
end;
when DescriptorType_Leaf =>
walkstate = AArch64_S2NextWalkStateLeaf{N}(walkstate, accdesc.ss, walkparams,
ipa, descriptor);
when DescriptorType_Invalid =>
fault.statuscode = Fault_Translation;
return (fault, ARBITRARY : AddressDescriptor,
ARBITRARY : TTWState, ARBITRARY : bits(N));
otherwise =>
unreachable;
end;
if new_descriptor != descriptor then
if ((walkaddress.memattrs) &&
ConstrainUnpredictableBool(Unpredictable_Unsupported_Atomic_HW_Update)) then
fault.statuscode = Fault_UnsupportedAtomicHWUpdate;
return (fault, ARBITRARY : AddressDescriptor, ARBITRARY : TTWState,
ARBITRARY : bits(N));
end;
let descaccess : AccessDescriptor = CreateAccDescTTEUpdate(accdesc);
(fault, descriptor) = AArch64_MemSwapTableDesc{N}(fault, descriptor, new_descriptor,
walkparams.ee, descaccess,
walkaddress);
if fault.statuscode != Fault_None then
return (fault, ARBITRARY : AddressDescriptor,
ARBITRARY : TTWState, ARBITRARY : bits(N));
end;
end;
until new_descriptor == descriptor looplimit Unbounded_DescriptorUpdate;
until desctype == DescriptorType_Leaf looplimit MAX_WALK_LEVELS;
let oa : FullAddress = Stage2OA(ipa.paddress.address, walkparams, walkstate);
if walkstate.contiguous == '1' &&
AArch64_S2ContiguousBitFaults(walkparams, walkstate) then
fault.statuscode = Fault_Translation;
elsif walkstate.level < FINAL_LEVEL &&
AArch64_nTFaults{N}(walkparams.d128, descriptor) then
fault.statuscode = Fault_Translation;
// Detect Address Size Fault by final output
elsif AArch64_S2OAOutOfRange(oa.address, walkparams) then
fault.statuscode = Fault_AddressSize;
// Check descriptor AF bit
elsif (descriptor[10] == '0' && walkparams.ha == '0' &&
(!accdesc.acctype IN {AccessType_DC, AccessType_IC} ||
ImpDefBool("Generate access flag fault on IC/DC operations"))) then
fault.statuscode = Fault_AccessFlag;
end;
return (fault, walkaddress, walkstate, descriptor);
end;
## Library pseudocode for
aarch64/translation/vmsa\_walk/AArch64\_SS2InitialTTWState
// AArch64_SS2InitialTTWState // ============================ // Set properties of first access to translation tables in Secure stage 2
func AArch64_SS2InitialTTWState(walkparams : S2TTWParams, ipaspace : PASpace) => TTWState begin var walkstate : TTWState; var tablebase : FullAddress; var ttbr : bits(128);
if ipaspace == PAS_Secure then
ttbr = ZeroExtend{128}(VSTTBR_EL2());
else
ttbr = ZeroExtend{128}(VTTBR_EL2());
end;
if ipaspace == PAS_Secure then
if walkparams.sw == '0' then
tablebase.paspace = PAS_Secure;
else
tablebase.paspace = PAS_NonSecure;
end;
else
if walkparams.nsw == '0' then
tablebase.paspace = PAS_Secure;
else
tablebase.paspace = PAS_NonSecure;
end;
end;
tablebase.address = AArch64_S2TTBaseAddress{128}(walkparams,
tablebase.paspace, ttbr);
walkstate.baseaddress = tablebase;
walkstate.level = AArch64_S2StartLevel(walkparams);
walkstate.istable = TRUE;
walkstate.memattrs = WalkMemAttrs(walkparams.sh, walkparams.irgn,
walkparams.orgn);
return walkstate;
end;
## Library pseudocode for
aarch64/translation/vmsa\_walk/AArch64\_SS2OutputPASpace
// AArch64_SS2OutputPASpace // ========================== // Assign PA Space to output of Secure stage 2 translation
func AArch64_SS2OutputPASpace(walkparams : S2TTWParams, ipaspace : PASpace) => PASpace begin if ipaspace == PAS_Secure then if walkparams.[sw,sa] == '00' then return PAS_Secure; else return PAS_NonSecure; end; else if walkparams.[sw,sa,nsw,nsa] == '0000' then return PAS_Secure; else return PAS_NonSecure; end; end; end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_GetS1TTWParams
// AArch64_GetS1TTWParams // ======================== // Returns stage 1 translation table walk parameters from respective controlling // System registers.
readonly func AArch64_GetS1TTWParams(regime : Regime, el : bits(2), ss : SecurityState, va : bits(64)) => S1TTWParams begin var walkparams : S1TTWParams;
let varange : VARange = AArch64_GetVARange(va);
case regime of
when Regime_EL3 => walkparams = AArch64_S1TTWParamsEL3();
when Regime_EL2 => walkparams = AArch64_S1TTWParamsEL2(ss);
when Regime_EL20 => walkparams = AArch64_S1TTWParamsEL20(el, ss, varange);
when Regime_EL10 => walkparams = AArch64_S1TTWParamsEL10(el, varange);
end;
return walkparams;
end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_GetS2TTWParams
// AArch64_GetS2TTWParams // ======================== // Gather walk parameters for stage 2 translation
func AArch64_GetS2TTWParams(ss : SecurityState, ipaspace : PASpace, s1aarch64 : boolean) => S2TTWParams begin var walkparams : S2TTWParams;
if ss == SS_NonSecure then
walkparams = AArch64_NSS2TTWParams(s1aarch64);
elsif IsFeatureImplemented(FEAT_SEL2) && ss == SS_Secure then
walkparams = AArch64_SS2TTWParams(ipaspace, s1aarch64);
elsif ss == SS_Realm then
walkparams = AArch64_RLS2TTWParams(s1aarch64);
else
unreachable;
end;
return walkparams;
end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_GetVARange
// AArch64_GetVARange // ==================== // Determines if the VA that is to be translated lies in LOWER or UPPER address range.
readonly func AArch64_GetVARange(va : bits(64)) => VARange begin if va[55] == '0' then return VARange_LOWER; else return VARange_UPPER; end; end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_HaveS1TG
// AArch64_HaveS1TG // ================== // Determine whether the given translation granule is supported for stage 1
readonly func AArch64_HaveS1TG(tgx : TGx) => boolean begin case tgx of when TGx_4KB => return IsFeatureImplemented(FEAT_TGran4K); when TGx_16KB => return IsFeatureImplemented(FEAT_TGran16K); when TGx_64KB => return IsFeatureImplemented(FEAT_TGran64K); end; end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_HaveS2TG
// AArch64_HaveS2TG // ================== // Determine whether the given translation granule is supported for stage 2
func AArch64_HaveS2TG(tgx : TGx) => boolean begin assert HaveEL(EL2);
if IsFeatureImplemented(FEAT_GTG) then
case tgx of
when TGx_4KB => return IsFeatureImplemented(FEAT_S2TGran4K);
when TGx_16KB => return IsFeatureImplemented(FEAT_S2TGran16K);
when TGx_64KB => return IsFeatureImplemented(FEAT_S2TGran64K);
end;
else
return AArch64_HaveS1TG(tgx);
end;
end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_MaxTxSZ
// AArch64_MaxTxSZ // ================= // Retrieve the maximum value of TxSZ indicating minimum input address size for both // stages of translation
readonly func AArch64_MaxTxSZ(tgx : TGx) => integer begin if IsFeatureImplemented(FEAT_TTST) then case tgx of when TGx_4KB => return 48; when TGx_16KB => return 48; when TGx_64KB => return 47; end; end;
return 39;
end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_NSS2TTWParams
// AArch64_NSS2TTWParams // ======================= // Gather walk parameters specific for Non-secure stage 2 translation
func AArch64_NSS2TTWParams(s1aarch64 : boolean) => S2TTWParams begin var walkparams : S2TTWParams;
if IsFeatureImplemented(FEAT_HCRMAC) then
walkparams.vm = HCR_EL2().VM OR HCR_EL2().DC;
else
walkparams.vm = HCR_EL2().VM;
end;
walkparams.tgx = AArch64_S2DecodeTG0(VTCR_EL2().TG0);
walkparams.txsz = VTCR_EL2().T0SZ;
walkparams.ps = VTCR_EL2().PS;
walkparams.irgn = VTCR_EL2().IRGN0;
walkparams.orgn = VTCR_EL2().ORGN0;
walkparams.sh = VTCR_EL2().SH0;
walkparams.ee = SCTLR_EL2().EE;
walkparams.d128 = if IsFeatureImplemented(FEAT_D128) then VTCR_EL2().D128 else
'0';
if walkparams.d128 == '1' then
walkparams.skl = VTTBR_EL2().SKL;
else
walkparams.sl0 = VTCR_EL2().SL0;
end;
if HCR_EL2().TGE == '0' then
walkparams.ptw = if IsFeatureImplemented(FEAT_HCRMAC) then HCR_EL2().PTW else '1';
else
walkparams.ptw = '0';
end;
if IsFeatureImplemented(FEAT_S2FWB) then
walkparams.fwb = if IsFeatureImplemented(FEAT_HCRMAC) then HCR_EL2().FWB else '1';
else
walkparams.fwb = '0';
end;
walkparams.ha = if IsFeatureImplemented(FEAT_HAF) then VTCR_EL2().HA else '0';
if IsFeatureImplemented(FEAT_HAFDBS) && walkparams.ha == '1' then
walkparams.hd = VTCR_EL2().HD;
else
walkparams.hd = '0';
end;
if walkparams.tgx IN {TGx_4KB, TGx_16KB} &&
IsFeatureImplemented(FEAT_LPA2) then
walkparams.ds = VTCR_EL2().DS;
else
walkparams.ds = '0';
end;
if walkparams.tgx == TGx_4KB && IsFeatureImplemented(FEAT_LPA2) then
walkparams.sl2 = VTCR_EL2().SL2 AND VTCR_EL2().DS;
else
walkparams.sl2 = '0';
end;
walkparams.cmow = (if IsFeatureImplemented(FEAT_CMOW) &&
IsHCRXEL2Enabled() then HCRX_EL2().CMOW
else '0');
if walkparams.d128 == '1' then
walkparams.s2pie = '1';
else
walkparams.s2pie = if IsFeatureImplemented(FEAT_S2PIE) then VTCR_EL2().S2PIE else '0';
end;
if IsFeatureImplemented(FEAT_S2PIE) then
if !(HaveEL(EL3) && SCR_EL3().PIEn == '0' &&
ImpDefBool("SCR_EL3.PIEn forces PIR_ELx or POR_ELx to zero")) then
walkparams.s2pir = S2PIR_EL2() as S2PIRType;
else
walkparams.s2pir = Zeros{64} as S2PIRType;
end;
end;
if IsFeatureImplemented(FEAT_THE) && walkparams.d128 != '1' then
walkparams.assuredonly = VTCR_EL2().AssuredOnly;
else
walkparams.assuredonly = '0';
end;
walkparams.tl0 = if IsFeatureImplemented(FEAT_THE) then VTCR_EL2().TL0 else
'0';
walkparams.tl1 = if IsFeatureImplemented(FEAT_THE) then VTCR_EL2().TL1 else
'0';
if IsFeatureImplemented(FEAT_HAFT) && walkparams.ha == '1' then
walkparams.haft = VTCR_EL2().HAFT;
else
walkparams.haft = '0';
end;
if (IsFeatureImplemented(FEAT_HDBSS) && walkparams.hd == '1'
&&
((EL3) || SCR_EL3().HDBSSEn == '1')) then
walkparams.hdbss = VTCR_EL2().HDBSS;
else
walkparams.hdbss = '0';
end;
return walkparams;
end;
## Library pseudocode for aarch64/translation/vmsa\_walkparams/AArch64\_OAMax
// AArch64_OAMax // =============== // Returns the maximum number of bits capable of representing physical address // based on the implemented features.
func AArch64_OAMax() => AddressSize begin if IsFeatureImplemented(FEAT_D128) then return 56; end; if IsFeatureImplemented(FEAT_LPA2) then return 52; end; if IsFeatureImplemented(FEAT_LPA) then return 52; end; return 48; end;
## Library pseudocode for aarch64/translation/vmsa\_walkparams/AArch64\_PAMax
// AArch64_PAMax // =============== // Returns the IMPLEMENTATION DEFINED maximum number of bits capable of representing // physical address for this PE
readonly func AArch64_PAMax() => AddressSize begin return ImpDefInt("Maximum Physical Address Size") as AddressSize; end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_RLS2TTWParams
// AArch64_RLS2TTWParams // ======================= // Gather walk parameters specific for Realm stage 2 translation
func AArch64_RLS2TTWParams(s1aarch64 : boolean) => S2TTWParams begin // Realm stage 2 walk parameters are similar to Non-secure var walkparams : S2TTWParams = AArch64_NSS2TTWParams(s1aarch64); walkparams.emec = (if IsFeatureImplemented(FEAT_MEC) && IsSCTLR2EL2Enabled() then SCTLR2_EL2().EMEC else '0'); return walkparams; end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_S1DCacheEnabled
// AArch64_S1DCacheEnabled // ========================= // Determine cacheability of stage 1 data accesses
readonly func AArch64_S1DCacheEnabled(regime : Regime) => boolean begin case regime of when Regime_EL3 => return SCTLR_EL3().C == '1'; when Regime_EL2 => return SCTLR_EL2().C == '1'; when Regime_EL20 => return SCTLR_EL2().C == '1'; when Regime_EL10 => return SCTLR_EL1().C == '1'; end; end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_S1DecodeTG0
// AArch64_S1DecodeTG0 // ===================== // Decode stage 1 granule size configuration bits TG0
readonly func AArch64_S1DecodeTG0(tg0_in : bits(2)) => TGx begin var tg0 : bits(2) = tg0_in; var tgx : TGx;
if tg0 == '11' then
tg0 = ImpDefBits{2}("TG0 encoded granule size");
end;
case tg0 of
when '00' => tgx = TGx_4KB;
when '01' => tgx = TGx_64KB;
when '10' => tgx = TGx_16KB;
end;
if (tgx) then
case ImpDefBits{2}("TG0 encoded granule size") of
when '00' => tgx = TGx_4KB;
when '01' => tgx = TGx_64KB;
when '10' => tgx = TGx_16KB;
end;
end;
return tgx;
end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_S1DecodeTG1
// AArch64_S1DecodeTG1 // ===================== // Decode stage 1 granule size configuration bits TG1
readonly func AArch64_S1DecodeTG1(tg1_in : bits(2)) => TGx begin var tg1 : bits(2) = tg1_in; var tgx : TGx;
if tg1 == '00' then
tg1 = ImpDefBits{2}("TG1 encoded granule size");
end;
case tg1 of
when '10' => tgx = TGx_4KB;
when '11' => tgx = TGx_64KB;
when '01' => tgx = TGx_16KB;
end;
if (tgx) then
case ImpDefBits{2}("TG1 encoded granule size") of
when '10' => tgx = TGx_4KB;
when '11' => tgx = TGx_64KB;
when '01' => tgx = TGx_16KB;
end;
end;
return tgx;
end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_S1E0POEnabled
// AArch64_S1E0POEnabled // ======================= // Determine whether stage 1 unprivileged permission overlay is enabled
readonly func AArch64_S1E0POEnabled(regime : Regime, nv1 : bit) => boolean begin assert HasUnprivileged(regime);
if !IsFeatureImplemented(FEAT_S1POE) then
return FALSE;
end;
case regime of
when Regime_EL20 => return IsTCR2EL2Enabled() && TCR2_EL2().E0POE == '1';
when Regime_EL10 => return IsTCR2EL1Enabled() && nv1 == '0' && TCR2_EL1().E0POE == '1';
end;
end;
## Library pseudocode for aarch64/translation/vmsa\_walkparams/AArch64\_S1EPD
// AArch64_S1EPD // =============== // Determine whether stage 1 translation table walk is allowed for the VA range
func AArch64_S1EPD(regime : Regime, va : bits(64)) => bit begin assert HasUnprivileged(regime); let varange : VARange = AArch64_GetVARange(va);
case regime of
when Regime_EL20 => return (if varange == VARange_LOWER then TCR_EL2().EPD0
else TCR_EL2().EPD1);
when Regime_EL10 => return (if varange == VARange_LOWER then TCR_EL1().EPD0
else TCR_EL1().EPD1);
end;
end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_S1Enabled
// AArch64_S1Enabled // =================== // Determine if stage 1 is enabled for the access type for this translation regime
readonly func AArch64_S1Enabled(regime : Regime, acctype : AccessType) => boolean begin if acctype == AccessType_TRBE && EffectiveTRBLIMITR_EL1_nVM() == '1' then return FALSE; end; if acctype == AccessType_SPE && EffectivePMBLIMITR_EL1_nVM() == '1' then return FALSE; end; case regime of when Regime_EL3 => return SCTLR_EL3().M == '1'; when Regime_EL2 => return SCTLR_EL2().M == '1'; when Regime_EL20 => return SCTLR_EL2().M == '1'; when Regime_EL10 => return ((() || HCR_EL2().[DC,TGE] == '00') && SCTLR_EL1().M == '1'); end; end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_S1ICacheEnabled
// AArch64_S1ICacheEnabled // ========================= // Determine cacheability of stage 1 instruction fetches
readonly func AArch64_S1ICacheEnabled(regime : Regime) => boolean begin case regime of when Regime_EL3 => return SCTLR_EL3().I == '1'; when Regime_EL2 => return SCTLR_EL2().I == '1'; when Regime_EL20 => return SCTLR_EL2().I == '1'; when Regime_EL10 => return SCTLR_EL1().I == '1'; end; end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_S1MinTxSZ
// AArch64_S1MinTxSZ // =================== // Retrieve the minimum value of TxSZ indicating maximum input address size for stage 1
readonly func AArch64_S1MinTxSZ(regime : Regime, walkparams : S1TTWParams) => integer begin if IsFeatureImplemented(FEAT_LVA3) then if walkparams.d128 == '1' then if HasUnprivileged(regime) then return 9; else return 8; end; elsif walkparams.tgx == TGx_64KB || walkparams.ds == '1' then return 12; else return 16; end; end; if IsFeatureImplemented(FEAT_LVA) then if walkparams.tgx == TGx_64KB || walkparams.ds == '1' || walkparams.d128 == '1' then return 12; else return 16; end; end;
return 16;
end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_S1POEnabled
// AArch64_S1POEnabled // ===================== // Determine whether stage 1 privileged permission overlay is enabled
readonly func AArch64_S1POEnabled(regime : Regime) => boolean begin if !IsFeatureImplemented(FEAT_S1POE) then return FALSE; end;
case regime of
when Regime_EL3 => return TCR_EL3().POE == '1';
when Regime_EL2 => return IsTCR2EL2Enabled() && TCR2_EL2().POE == '1';
when Regime_EL20 => return IsTCR2EL2Enabled() && TCR2_EL2().POE == '1';
when Regime_EL10 => return IsTCR2EL1Enabled() && TCR2_EL1().POE == '1';
end;
end;
## Library pseudocode for aarch64/translation/vmsa\_walkparams/AArch64\_S1POR
// AArch64_S1POR // =============== // Identify stage 1 permissions overlay register for the acting translation regime
func AArch64_S1POR(regime : Regime) => S1PORType begin if (HaveEL(EL3) && SCR_EL3().PIEn == '0' && regime != Regime_EL3 && ImpDefBool("SCR_EL3.PIEn forces PIR_ELx or POR_ELx to zero")) then return Zeros{64} as S1PORType; end;
case regime of
when Regime_EL3 => return POR_EL3() as S1PORType;
when Regime_EL2 => return POR_EL2() as S1PORType;
when Regime_EL20 => return POR_EL2() as S1PORType;
when Regime_EL10 => return POR_EL1() as S1PORType;
end;
end;
## Library pseudocode for aarch64/translation/vmsa\_walkparams/AArch64\_S1TTBR
// AArch64_S1TTBR // ================ // Identify stage 1 table base register for the acting translation regime
func AArch64_S1TTBR(regime : Regime, va : bits(64)) => bits(128) begin let varange : VARange = AArch64_GetVARange(va);
case regime of
when Regime_EL3 => return ZeroExtend{128}(TTBR0_EL3());
when Regime_EL2 => return ZeroExtend{128}(TTBR0_EL2());
when Regime_EL20 =>
if varange == VARange_LOWER then
return ZeroExtend{128}(TTBR0_EL2());
else
return ZeroExtend{128}(TTBR1_EL2());
end;
when Regime_EL10 =>
if varange == VARange_LOWER then
return ZeroExtend{128}(TTBR0_EL1());
else
return ZeroExtend{128}(TTBR1_EL1());
end;
end;
end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_S1TTWParamsEL10
// AArch64_S1TTWParamsEL10 // ========================= // Gather stage 1 translation table walk parameters for EL1&0 regime // (with EL2 enabled or disabled)
readonly func AArch64_S1TTWParamsEL10(el : bits(2), varange : VARange) => S1TTWParams begin var walkparams : S1TTWParams;
if IsFeatureImplemented(FEAT_D128) && IsTCR2EL1Enabled()
then
walkparams.d128 = TCR2_EL1().D128;
else
walkparams.d128 = '0';
end;
let nvs : bits(3) = EffectiveHCR_EL2_NVx();
walkparams.nv1 = nvs[1] AND nvs[0];
if IsFeatureImplemented(FEAT_AIE) then
walkparams.mair2 = MAIR2_EL1() as MAIRType;
end;
walkparams.aie = (if IsFeatureImplemented(FEAT_AIE) &&
IsTCR2EL1Enabled() then TCR2_EL1().AIE
else '0');
if walkparams.d128 == '1' then
walkparams.pie = '1';
else
walkparams.pie = (if IsFeatureImplemented(FEAT_S1PIE) &&
IsTCR2EL1Enabled() then TCR2_EL1().PIE else '0');
end;
if IsFeatureImplemented(FEAT_S1PIE) then
if !(HaveEL(EL3) && SCR_EL3().PIEn == '0' &&
ImpDefBool("SCR_EL3.PIEn forces PIR_ELx or POR_ELx to zero")) then
walkparams.pir = PIR_EL1() as S1PIRType;
if walkparams.nv1 == '1' then
walkparams.pire0 = Zeros{64} as S1PIRType;
else
walkparams.pire0 = PIRE0_EL1() as S1PIRType;
end;
else
walkparams.pir = Zeros{64} as S1PIRType;
walkparams.pire0 = Zeros{64} as S1PIRType;
end;
end;
if varange == VARange_LOWER then
walkparams.tgx = AArch64_S1DecodeTG0(TCR_EL1().TG0);
walkparams.txsz = TCR_EL1().T0SZ;
walkparams.irgn = TCR_EL1().IRGN0;
walkparams.orgn = TCR_EL1().ORGN0;
walkparams.sh = TCR_EL1().SH0;
walkparams.tbi = TCR_EL1().TBI0;
walkparams.nfd = if IsFeatureImplemented(FEAT_SVE) then TCR_EL1().NFD0 else '0';
walkparams.tbid = if IsFeatureImplemented(FEAT_PAuth) then TCR_EL1().TBID0 else '0';
walkparams.e0pd = if IsFeatureImplemented(FEAT_E0PD) then TCR_EL1().E0PD0 else '0';
walkparams.hpd = if IsFeatureImplemented(FEAT_HPDS) then TCR_EL1().HPD0 else '0';
if walkparams.hpd == '0' then
if walkparams.aie == '1' then walkparams.hpd = '1'; end;
if walkparams.pie == '1' then walkparams.hpd = '1'; end;
if (AArch64_S1POEnabled(Regime_EL10) ||
AArch64_S1E0POEnabled(Regime_EL10, walkparams.nv1)) then walkparams.hpd = '1';
end;
end;
if (IsFeatureImplemented(FEAT_MTE_NO_ADDRESS_TAGS) ||
IsFeatureImplemented(FEAT_MTE_CANONICAL_TAGS)) then
walkparams.mtx = TCR_EL1().MTX0;
else
walkparams.mtx = '0';
end;
walkparams.skl = if walkparams.d128 == '1' then TTBR0_EL1().SKL else '00';
walkparams.disch = if walkparams.d128 == '1' then TCR2_EL1().DisCH0 else '0';
if IsFeatureImplemented(FEAT_ASID2) && IsTCR2EL1Enabled() then
walkparams.fng = TCR2_EL1().FNG0;
else
walkparams.fng = '0';
end;
if IsFeatureImplemented(FEAT_THE) && IsTCR2EL1Enabled() then
walkparams.fngna = TCR2_EL1().FNGNA0;
else
walkparams.fngna = '0';
end;
else
walkparams.tgx = AArch64_S1DecodeTG1(TCR_EL1().TG1);
walkparams.txsz = TCR_EL1().T1SZ;
walkparams.irgn = TCR_EL1().IRGN1;
walkparams.orgn = TCR_EL1().ORGN1;
walkparams.sh = TCR_EL1().SH1;
walkparams.tbi = TCR_EL1().TBI1;
walkparams.nfd = if IsFeatureImplemented(FEAT_SVE) then TCR_EL1().NFD1 else '0';
walkparams.tbid = if IsFeatureImplemented(FEAT_PAuth) then TCR_EL1().TBID1 else '0';
walkparams.e0pd = if IsFeatureImplemented(FEAT_E0PD) then TCR_EL1().E0PD1 else '0';
walkparams.hpd = if IsFeatureImplemented(FEAT_HPDS) then TCR_EL1().HPD1 else '0';
if walkparams.hpd == '0' then
if walkparams.aie == '1' then walkparams.hpd = '1'; end;
if walkparams.pie == '1' then walkparams.hpd = '1'; end;
if (AArch64_S1POEnabled(Regime_EL10) ||
AArch64_S1E0POEnabled(Regime_EL10, walkparams.nv1)) then walkparams.hpd = '1';
end;
end;
if (IsFeatureImplemented(FEAT_MTE_NO_ADDRESS_TAGS) ||
IsFeatureImplemented(FEAT_MTE_CANONICAL_TAGS)) then
walkparams.mtx = TCR_EL1().MTX1;
else
walkparams.mtx = '0';
end;
walkparams.skl = if walkparams.d128 == '1' then TTBR1_EL1().SKL else '00';
walkparams.disch = if walkparams.d128 == '1' then TCR2_EL1().DisCH1 else '0';
if IsFeatureImplemented(FEAT_ASID2) && IsTCR2EL1Enabled() then
walkparams.fng = TCR2_EL1().FNG1;
else
walkparams.fng = '0';
end;
if IsFeatureImplemented(FEAT_THE) && IsTCR2EL1Enabled() then
walkparams.fngna = TCR2_EL1().FNGNA1;
else
walkparams.fngna = '0';
end;
end;
walkparams.mair = MAIR_EL1() as MAIRType;
walkparams.wxn = SCTLR_EL1().WXN;
walkparams.ps = TCR_EL1().IPS;
walkparams.ee = SCTLR_EL1().EE;
if (HaveEL(EL3) && (!IsFeatureImplemented(FEAT_RME) ||
IsFeatureImplemented(FEAT_SEL2))) then
walkparams.sif = SCR_EL3().SIF;
else
walkparams.sif = '0';
end;
if EL2Enabled() then
walkparams.dc = if IsFeatureImplemented(FEAT_HCRMAC) then HCR_EL2().DC else '0';
if IsFeatureImplemented(FEAT_MTE2) && IsFeatureImplemented(FEAT_HCRMAC) then
walkparams.dct = HCR_EL2().DCT;
else
walkparams.dct = '0';
end;
end;
if IsFeatureImplemented(FEAT_LSMAOC) then
walkparams.ntlsmd = SCTLR_EL1().nTLSMD;
else
walkparams.ntlsmd = '1';
end;
walkparams.cmow = if IsFeatureImplemented(FEAT_CMOW) then SCTLR_EL1().CMOW
else '0';
walkparams.ha = if IsFeatureImplemented(FEAT_HAF) then TCR_EL1().HA else '0';
if IsFeatureImplemented(FEAT_HAFDBS) && walkparams.ha == '1' then
walkparams.hd = TCR_EL1().HD;
else
walkparams.hd = '0';
end;
if (walkparams.tgx IN {TGx_4KB, TGx_16KB} &&
IsFeatureImplemented(FEAT_LPA2) &&
walkparams.d128 == '0') then
walkparams.ds = TCR_EL1().DS;
else
walkparams.ds = '0';
end;
if IsFeatureImplemented(FEAT_PAN3) then
walkparams.epan = if walkparams.pie == '0' then SCTLR_EL1().EPAN else '1';
else
walkparams.epan = '0';
end;
if IsFeatureImplemented(FEAT_THE) && walkparams.d128 == '0' &&
IsTCR2EL1Enabled() then
walkparams.pnch = TCR2_EL1().PnCH;
else
walkparams.pnch = '0';
end;
if IsFeatureImplemented(FEAT_HAFT) && walkparams.ha == '1' &&
IsTCR2EL1Enabled() then
walkparams.haft = TCR2_EL1().HAFT;
else
walkparams.haft = '0';
end;
walkparams.emec = (if IsFeatureImplemented(FEAT_MEC) &&
IsSCTLR2EL2Enabled() then SCTLR2_EL2().EMEC else '0');
return walkparams;
end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_S1TTWParamsEL2
// AArch64_S1TTWParamsEL2 // ======================== // Gather stage 1 translation table walk parameters for EL2 regime
readonly func AArch64_S1TTWParamsEL2(ss : SecurityState) => S1TTWParams begin var walkparams : S1TTWParams;
walkparams.tgx = AArch64_S1DecodeTG0(TCR_EL2().TG0);
walkparams.txsz = TCR_EL2().T0SZ;
walkparams.ps = TCR_EL2().PS;
walkparams.irgn = TCR_EL2().IRGN0;
walkparams.orgn = TCR_EL2().ORGN0;
walkparams.sh = TCR_EL2().SH0;
walkparams.tbi = TCR_EL2().TBI;
walkparams.mair = MAIR_EL2() as MAIRType;
walkparams.pie = (if IsFeatureImplemented(FEAT_S1PIE) &&
IsTCR2EL2Enabled() then TCR2_EL2().PIE
else '0');
if IsFeatureImplemented(FEAT_S1PIE) then
if !(HaveEL(EL3) && SCR_EL3().PIEn == '0' &&
ImpDefBool("SCR_EL3.PIEn forces PIR_ELx or POR_ELx to zero")) then
walkparams.pir = PIR_EL2() as S1PIRType;
else
walkparams.pir = Zeros{64} as S1PIRType;
end;
end;
if IsFeatureImplemented(FEAT_AIE) then
walkparams.mair2 = MAIR2_EL2() as MAIRType;
end;
walkparams.aie = (if IsFeatureImplemented(FEAT_AIE) &&
IsTCR2EL2Enabled() then TCR2_EL2().AIE
else '0');
walkparams.wxn = SCTLR_EL2().WXN;
walkparams.ee = SCTLR_EL2().EE;
if (HaveEL(EL3) && (!IsFeatureImplemented(FEAT_RME) ||
IsFeatureImplemented(FEAT_SEL2))) then
walkparams.sif = SCR_EL3().SIF;
else
walkparams.sif = '0';
end;
walkparams.tbid = if IsFeatureImplemented(FEAT_PAuth) then TCR_EL2().TBID else
'0';
walkparams.hpd = if IsFeatureImplemented(FEAT_HPDS) then TCR_EL2().HPD else
'0';
if walkparams.hpd == '0' then
if walkparams.aie == '1' then walkparams.hpd = '1'; end;
if walkparams.pie == '1' then walkparams.hpd = '1'; end;
if AArch64_S1POEnabled(Regime_EL2) then walkparams.hpd = '1'; end;
end;
walkparams.ha = if IsFeatureImplemented(FEAT_HAF) then TCR_EL2().E2H0.HA else
'0';
if IsFeatureImplemented(FEAT_HAFDBS) && walkparams.ha == '1' then
walkparams.hd = TCR_EL2().E2H0.HD;
else
walkparams.hd = '0';
end;
if walkparams.tgx IN {TGx_4KB, TGx_16KB} &&
IsFeatureImplemented(FEAT_LPA2) then
walkparams.ds = TCR_EL2().E2H0.DS;
else
walkparams.ds = '0';
end;
if (IsFeatureImplemented(FEAT_MTE_NO_ADDRESS_TAGS) ||
IsFeatureImplemented(FEAT_MTE_CANONICAL_TAGS)) then
walkparams.mtx = TCR_EL2().MTX;
else
walkparams.mtx = '0';
end;
walkparams.pnch = (if IsFeatureImplemented(FEAT_THE) &&
IsTCR2EL2Enabled() then TCR2_EL2().PnCH
else '0');
if IsFeatureImplemented(FEAT_HAFT) && walkparams.ha == '1' &&
IsTCR2EL2Enabled() then
walkparams.haft = TCR2_EL2().HAFT;
else
walkparams.haft = '0';
end;
walkparams.emec = (if IsFeatureImplemented(FEAT_MEC) &&
IsSCTLR2EL2Enabled() then SCTLR2_EL2().EMEC else '0');
if IsFeatureImplemented(FEAT_MEC) && ss == SS_Realm &&
IsTCR2EL2Enabled() then
walkparams.amec = TCR2_EL2().AMEC0;
else
walkparams.amec = '0';
end;
return walkparams;
end;
## Library pseudocode for
aarch64/translation/vmsa\_walkparams/AArch64\_S1TTWParamsEL20
// AArch64_S1TTWParamsEL20 // ========================= // Gather stage 1 translation table walk parameters for EL2&0 regime
readonly func AArch64_S1TTWParamsEL20(el : bits(2), ss : SecurityState, varange : VARange) => S1TTWParams begin var walkparams : S1TTWParams;
if IsFeatureImplemented(FEAT_D128) && IsTCR2EL2Enabled()
then
walkparams.d128 = TCR2_EL2().D128;
else
walkparams.d128 = '0';
end;
if walkparams.d128 == '1' then
walkparams.pie = '1';
else
walkparams.pie = (if IsFeatureImplemented(FEAT_S1PIE) &&
IsTCR2EL2Enabled() then TCR2_EL2().PIE else '0');
end;
if IsFeatureImplemented(FEAT_S1PIE) then
if !(HaveEL(EL3) && SCR_EL3().PIEn == '0' &&
ImpDefBool("SCR_EL3.PIEn forces PIR_ELx or POR_ELx to zero")) then
walkparams.pir = PIR_EL2() as S1PIRType;
walkparams.pire0 = PIRE0_EL2() as S1PIRType;
else
walkparams.pir = Zeros{64} as S1PIRType;
walkparams.pire0 = Zeros{64} as S1PIRType;
end;
end;
if IsFeatureImplemented(FEAT_AIE) then
walkparams.mair2 = MAIR2_EL2() as MAIRType;
end;
walkparams.aie = (if IsFeatureImplemented(FEAT_AIE) &&
IsTCR2EL2Enabled() then TCR2_EL2().AIE
else '0');
if varange == VARange_LOWER then
walkparams.tgx = AArch64_S1DecodeTG0(TCR_EL2().TG0);
walkparams.txsz = TCR_EL2().T0SZ;
walkparams.irgn = TCR_EL2().IRGN0;
walkparams.orgn = TCR_EL2().ORGN0;
walkparams.sh = TCR_EL2().SH0;
walkparams.tbi = TCR_EL2().TBI0;
walkparams.nfd = if IsFeatureImplemented(FEAT_SVE) then TCR_EL2().NFD0 else '0';
walkparams.tbid = if IsFeatureImplemented(FEAT_PAuth) then TCR_EL2().TBID0 else '0';
walkparams.e0pd = if IsFeatureImplemented(FEAT_E0PD) then TCR_EL2().E0PD0 else '0';
walkparams.hpd = if IsFeatureImplemented(FEAT_HPDS) then TCR_EL2().HPD0 else '0';
if walkparams.hpd == '0' then
if walkparams.aie == '1' then walkparams.hpd = '1'; end;
if walkparams.pie == '1' then walkparams.hpd = '1'; end;
if AArch64_S1POEnabled(Regime_EL20) || AArch64_S1E0POEnabled(Regime_EL20, '0') then
walkparams.hpd = '1';
end;
end;
if (IsFeatureImplemented(FEAT_MTE_NO_ADDRESS_TAGS) ||
IsFeatureImplemented(FEAT_MTE_CANONICAL_TAGS)) then
walkparams.mtx = TCR_EL2().MTX0;
else
walkparams.mtx = '0';
end;
walkparams.skl = if walkparams.d128 == '1' then TTBR0_EL2().SKL else '00';
walkparams.disch = if walkparams.d128 == '1' then TCR2_EL2().DisCH0 else '0';
if IsFeatureImplemented(FEAT_ASID2) && IsTCR2EL2Enabled() then
walkparams.fng = TCR2_EL2().FNG0;
else
walkparams.fng = '0';
end;
else
walkparams.tgx = AArch64_S1DecodeTG1(TCR_EL2().TG1);
walkparams.txsz = TCR_EL2().T1SZ;
walkparams.irgn = TCR_EL2().IRGN1;
walkparams.orgn = TCR_EL2().ORGN1;
walkparams.sh = TCR_EL2().SH1;
walkparams.tbi = TCR_EL2().TBI1;
walkparams.nfd = if IsFeatureImplemented(FEAT_SVE) then TCR_EL2().NFD1 else '0';
walkparams.tbid = if IsFeatureImplemented(FEAT_PAuth) then TCR_EL2().TBID1 else '0';
walkparams.e0pd = if IsFeatureImplemented(FEAT_E0PD) then TCR_EL2().E0PD1 else '0';
walkparams.hpd = if IsFeatureImplemented(FEAT_HPDS) then TCR_EL2().HPD1 else '0';
if walkparams.hpd == '0' then
if walkparams.aie == '1' then walkparams.hpd = '1'; end;
if walkparams.pie == '1' then walkparams.hpd = '1'; end;
if AArch64_S1POEnabled(Regime_EL20) || AArch64_S1E0POEnabled(Regime_EL20, '0') then
walkparams.hpd = '1';
end;
end;
if (IsFeatureImplemented(FEAT_MTE_NO_ADDRESS_TAGS) ||
IsFeatureImplemented(FEAT_MTE_CANONICAL_TAGS)) then
walkparams.mtx = TCR_EL2().MTX1;
else
walkparams.mtx = '0';
end;
walkparams.skl = if walkparams.d128 == '1' then TTBR1_EL2().SKL else '00';
walkparams.disch = if walkparams.d128 == '1' then TCR2_EL2().DisCH1 else '0';
if IsFeatureImplemented(FEAT_ASID2) && IsTCR2EL2Enabled() then
walkparams.fng = TCR2_EL2().FNG1;
else
walkparams.fng = '0';
end;
end;
walkparams.mair = MAIR_EL2() as MAIRType;
walkparams.wxn = SCTLR_EL2().WXN;
walkparams.ps = TCR_EL2().IPS;
walkparams.ee = SCTLR_EL2().EE;
if (HaveEL(EL3) && (!IsFeatureImplemented(FEAT_RME) ||
IsFeatureImplemented(FEAT_SEL2))) then
walkparams.sif = SCR_EL3().SIF;
else
walkparams.sif = '0';
end;
if IsFeatureImplemented(FEAT_LSMAOC) then
walkparams.ntlsmd = SCTLR_EL2().nTLSMD;
else
walkparams.ntlsmd = '1';
end;
walkparams.cmow = if IsFeatureImplemented(FEAT_CMOW) then SCTLR_EL2().CMOW
else '0';
walkparams.ha = if IsFeatureImplemented(FEAT_HAF) then TCR_EL2().E2H1.HA else
'0';
if IsFeatureImplemented(FEAT_HAFDBS) && walkparams.ha == '1' then
walkparams.hd = TCR_EL2().E2H1.HD;
else
walkparams.hd = '0';
end;
if (walkparams.tgx IN {TGx_4KB, TGx_16KB} &&
IsFeatureImplemented(FEAT_LPA2) &&
walkparams.d128 == '0') then
walkparams.ds = TCR_EL2().E2H1.DS;
else
walkparams.ds = '0';
end;
if IsFeatureImplemented(FEAT_PAN3) then
walkparams.epan = if walkparams.pie == '0' then SCTLR_EL2().EPAN else '1';
else
walkparams.epan = '0';
end;
if IsFeatureImplemented(FEAT_THE) && walkparams.d128 == '0' &&
IsTCR2EL2Enabled() then
walkparams.pnch = TCR2_EL2().PnCH;
else
walkparams.pnch = '0';
end;
if IsFeatureImplemented(FEAT_HAFT) && walkparams.ha == '1' &&
IsTCR2EL2Enabled() then
walkparams.haft = TCR2_EL2().HAFT;
else
walkparams.haft = '0';
end;
------------------------------------------------------------------------------
Page 1 of 1.
End of thread.