[Writeup] Shared pseudocode: part 31 of 36 ========================================== Section: Silicon & Architectures Started: 2026-11-28 17:48 UTC by admin Replies: 0, last post 2026-11-28 17:48 UTC Page: 1 of 1 Web: https://romdump.net/t/123 ------------------------------------------------------------------------------ #143 admin, 2026-11-28 17:48 UTC [OP] Source: https://romdump.net/raw/143

Shared pseudocode from the offline Arm documentation snapshot. Part 31 of 36.

 tcma = if address[55] == '1' then TCR_EL1().TCMA1 else
TCR_EL1().TCMA0;
    when EL2 =>
        if IsFeatureImplemented(FEAT_VHE) && ELIsInHost(el) then
            tcma = if address[55] == '1' then TCR_EL2().TCMA1 else TCR_EL2().TCMA0;
        else
            tcma = TCR_EL2().TCMA;
        end;
    when EL3 =>
        tcma = TCR_EL3().TCMA;
end;

return tcma;

end;


## Library pseudocode for shared/functions/memory/ErrorState

// ErrorState // ========== // The allowed error states that can be returned by memory and used by the PE.

type ErrorState of enumeration { ErrorState_UC, // Uncontainable ErrorState_UEU, // Unrecoverable state ErrorState_UEO, // Restartable state ErrorState_UER, // Recoverable state ErrorState_CE}; // Corrected


## Library pseudocode for shared/functions/memory/Fault

// Fault // ===== // Fault types.

type Fault of enumeration { Fault_None, Fault_AccessFlag, Fault_Alignment, Fault_Background, Fault_Domain, Fault_Permission, Fault_Translation, Fault_AddressSize, Fault_SyncExternal, Fault_SyncExternalOnWalk, Fault_SyncParity, Fault_SyncParityOnWalk, Fault_GPCFOnWalk, Fault_GPCFOnOutput, Fault_AsyncParity, Fault_AsyncExternal, Fault_TagCheck, Fault_Debug, Fault_TLBConflict, Fault_BranchTarget, Fault_UnsupportedAtomicHWUpdate, Fault_Lockdown, Fault_Exclusive, Fault_ICacheMaint};


## Library pseudocode for shared/functions/memory/FaultRecord

// FaultRecord // =========== // Fields that relate only to Faults.

type FaultRecord of record { statuscode : Fault, // Fault Status accessdesc : AccessDescriptor, // Details of the faulting access vaddress : bits(64), // Faulting virtual address ipaddress : FullAddress, // Intermediate physical address paddress : FullAddress, // Physical address gpcf : GPCFRecord, // Granule Protection Check Fault record gpcfs2walk : boolean, // GPC for a stage 2 translation table walk s2fs1walk : boolean, // Is on a Stage 1 translation table walk write : boolean, // TRUE for a write, FALSE for a read s1tagnotdata : boolean, // TRUE for a fault due to tag not accessible at stage 1. tagaccess : boolean, // TRUE for a fault due to NoTagAccess permission. level : integer, // For translation, access flag and Permission faults extflag : bit, // IMPLEMENTATION DEFINED syndrome for External aborts secondstage : boolean, // Is a Stage 2 abort assuredonly : boolean, // Stage 2 Permission fault due to AssuredOnly attribute toplevel : boolean, // Stage 2 Permission fault due to TopLevel overlay : boolean, // Fault due to overlay permissions dirtybit : boolean, // Fault due to dirty state domain : bits(4), // Domain number, AArch32 only merrorstate : ErrorState, // Incoming error state from memory hdbssf : boolean, // Fault caused by HDBSS watchptinfo : WatchpointInfo, // Watchpoint related fields debugmoe : bits(4) // Debug method of entry, from AArch32 only };


## Library pseudocode for shared/functions/memory/FullAddress

// FullAddress // =========== // Physical or Intermediate Physical Address type. // Although AArch32 only has access to 40 bits of physical or intermediate physical address space, // the full address type has NUM_PABITS bits to allow interprocessing with AArch64. // The maximum physical or intermediate physical address size is IMPLEMENTATION DEFINED, // but never exceeds NUM_PABITS bits.

type FullAddress of record { paspace : PASpace, address : bits(NUM_PABITS) };


## Library pseudocode for shared/functions/memory/GPCF

// GPCF // ==== // Possible Granule Protection Check Fault reasons

type GPCF of enumeration { GPCF_None, // No fault GPCF_AddressSize, // GPT address size fault GPCF_Walk, // GPT walk fault GPCF_EABT, // Synchronous External abort on GPT fetch GPCF_Fail // Granule protection fault };


## Library pseudocode for shared/functions/memory/GPCFRecord

// GPCFRecord // ========== // Full details of a Granule Protection Check Fault

type GPCFRecord of record { gpf : GPCF, level : integer };


## Library pseudocode for shared/functions/memory/Hint\_Prefetch

// Hint_Prefetch // =============== // Signals the memory system that memory accesses of type HINT to or from the specified address are // likely in the near future. The memory system may take some action to speed up the memory // accesses when they do occur, such as pre-loading the specified address into one or more // caches as indicated by the innermost cache level target (0=L1, 1=L2, etc) and non-temporal hint // stream. Any or all prefetch hints may be treated as a NOP. A prefetch hint must not cause a // synchronous abort due to Alignment or Translation faults and the like. Its only effect on // software-visible state should be on caches and TLBs associated with address, which must be // accessible by reads, writes or execution, as defined in the translation regime of the current // Exception level. It is guaranteed not to access Device memory. // A Prefetch_EXEC hint must not result in an access that could not be performed by a speculative // instruction fetch, therefore if all associated MMUs are disabled, then it cannot access any // memory location that cannot be accessed by instruction fetches.

impdef func Hint_Prefetch(address : bits(64), hint : PrefetchHint, target : integer, stream : boolean) begin return; end;


## Library pseudocode for shared/functions/memory/Hint\_RangePrefetch

// Hint_RangePrefetch // ==================== // Signals the memory system that data memory accesses from a specified range // of addresses are likely to occur in the near future. The memory system can // respond by taking actions that are expected to speed up the memory accesses // when they do occur, such as preloading the locations within the specified // address ranges into one or more caches.

impdef func Hint_RangePrefetch(address : bits(64), length : integer, stride : integer, count : integer, reuse : integer, operation : bits(6)) begin return; end;


## Library pseudocode for shared/functions/memory/IsContiguousSVEAccess

// IsContiguousSVEAccess // ======================= // Return TRUE if memory access is contiguous load/stores in an SVE mode.

func IsContiguousSVEAccess(accdesc : AccessDescriptor) => boolean begin return accdesc.acctype == AccessType_SVE && accdesc.contiguous; end;


## Library pseudocode for shared/functions/memory/IsRelaxedWatchpointAccess

// IsRelaxedWatchpointAccess // =========================== // Return TRUE if memory access is one of - // - SIMD&FP load/store instruction when the PE is in Streaming SVE mode // - SVE contiguous vector load/store instruction. // - SME load/store instruction

func IsRelaxedWatchpointAccess(accdesc : AccessDescriptor) => boolean begin return (IsContiguousSVEAccess(accdesc) || IsSMEAccess(accdesc) || (IsSIMDFPAccess(accdesc) && InStreamingMode())); end;


## Library pseudocode for shared/functions/memory/IsSIMDFPAccess

// IsSIMDFPAccess // ================ // Return TRUE if access is SIMD&FP.

func IsSIMDFPAccess(accdesc : AccessDescriptor) => boolean begin return accdesc.acctype == AccessType_ASIMD; end;


## Library pseudocode for shared/functions/memory/IsSMEAccess

// IsSMEAccess // ============= // Return TRUE if access is of SME load/stores.

func IsSMEAccess(accdesc : AccessDescriptor) => boolean begin return accdesc.acctype == AccessType_SME; end;


## Library pseudocode for shared/functions/memory/IsWatchpointableAccess

// IsWatchpointableAccess // ======================== // Return TRUE if access should be checked for watchpoints.

func IsWatchpointableAccess(accdesc : AccessDescriptor) => boolean begin return (!(accdesc.acctype IN {AccessType_IFETCH, AccessType_TTW, AccessType_DC, AccessType_IC, AccessType_SPE, AccessType_TRBE, AccessType_AT}) || (accdesc.acctype == AccessType_DC && accdesc.cacheop == CacheOp_Invalidate && (() || (ImpDefBool("DCIMVAC generates watchpoint"))))); end;


## Library pseudocode for shared/functions/memory/MBMaintenanceScope

// MBMaintenanceScope // ================== // Memory barrier scope.

type MBMaintenanceScope of enumeration {MBMaintenanceScope_Nonshareable, MBMaintenanceScope_InnerShareable, MBMaintenanceScope_OuterShareable, MBMaintenanceScope_None};


## Library pseudocode for shared/functions/memory/MBReqTypes

// MBReqTypes // ========== // Memory barrier read/write.

type MBReqTypes of enumeration {MBReqTypes_Reads, MBReqTypes_Writes, MBReqTypes_All};


## Library pseudocode for shared/functions/memory/MemAtomicOp

// MemAtomicOp // =========== // Atomic data processing instruction types.

type MemAtomicOp of enumeration { MemAtomicOp_GCSSS1, MemAtomicOp_ADD, MemAtomicOp_BIC, MemAtomicOp_EOR, MemAtomicOp_ORR, MemAtomicOp_SMAX, MemAtomicOp_SMIN, MemAtomicOp_UMAX, MemAtomicOp_UMIN, MemAtomicOp_SWP, MemAtomicOp_CAS, MemAtomicOp_FPADD, MemAtomicOp_FPMAX, MemAtomicOp_FPMIN, MemAtomicOp_FPMAXNM, MemAtomicOp_FPMINNM, MemAtomicOp_BFADD, MemAtomicOp_BFMAX, MemAtomicOp_BFMIN, MemAtomicOp_BFMAXNM, MemAtomicOp_BFMINNM };


## Library pseudocode for shared/functions/memory/MemAttrHints

// MemAttrHints // ============ // Attributes and hints for Normal memory.

type MemAttrHints of record { attrs : bits(2), // See MemAttr_, Cacheability attributes hints : bits(2), // See MemHint_, Allocation hints transient : boolean };


## Library pseudocode for shared/functions/memory/MemOp

// MemOp // ===== // Memory access instruction types.

type MemOp of enumeration {MemOp_LOAD, MemOp_STORE, MemOp_PREFETCH};


## Library pseudocode for shared/functions/memory/MemType

// MemType // ======= // Basic memory types.

type MemType of enumeration {MemType_Normal, MemType_Device};


## Library pseudocode for shared/functions/memory/Memory

// Memory Tag type // ===============

type MemTagType of enumeration { MemTag_AllocationTagged, MemTag_CanonicallyTagged, MemTag_Untagged };


## Library pseudocode for shared/functions/memory/MemoryAttributes

// MemoryAttributes // ================ // Memory attributes descriptor

type MemoryAttributes of record { memtype : MemType, device : DeviceType, // For Device memory types inner : MemAttrHints, // Inner hints and attributes outer : MemAttrHints, // Outer hints and attributes shareability : Shareability, // Shareability attribute tags : MemTagType, // MTE tag type for this memory. notagaccess : boolean, // Allocation Tag access permission xs : bit // XS attribute };


## Library pseudocode for shared/functions/memory/NewAccDesc

// NewAccDesc // ============ // Create a new AccessDescriptor with initialized fields

func NewAccDesc(acctype : AccessType) => AccessDescriptor begin let mpaminfo : MPAMinfo = GenMPAMCurEL(acctype); return NewAccDesc(acctype, mpaminfo); end;

func NewAccDesc(acctype : AccessType, mpam : MPAMinfo) => AccessDescriptor begin var accdesc : AccessDescriptor;

accdesc.acctype             = acctype;
accdesc.el                  = PSTATE.EL;
accdesc.ss                  = SecurityStateAtEL(PSTATE.EL);
accdesc.acqsc               = FALSE;
accdesc.acqpc               = FALSE;
accdesc.relsc               = FALSE;
accdesc.limitedordered      = FALSE;
accdesc.exclusive           = FALSE;
accdesc.rcw                 = FALSE;
accdesc.rcws                = FALSE;
accdesc.atomicop            = FALSE;
accdesc.nontemporal         = FALSE;
accdesc.read                = FALSE;
accdesc.write               = FALSE;
accdesc.pan                 = FALSE;
accdesc.nonfault            = FALSE;
accdesc.firstfault          = FALSE;
accdesc.first               = FALSE;
accdesc.contiguous          = FALSE;
accdesc.predicated          = FALSE;
accdesc.streamingsve        = FALSE;
accdesc.ls64                = FALSE;
accdesc.withstatus          = FALSE;
accdesc.mops                = FALSE;
accdesc.a32lsmd             = FALSE;
accdesc.tagchecked          = FALSE;
accdesc.tagaccess           = FALSE;
accdesc.stzgm               = FALSE;
accdesc.mpam                = mpam;
accdesc.Rs                  = -1;
accdesc.Rs2                 = -1;
accdesc.Rt                  = -1;
accdesc.Rt2                 = -1;
accdesc.ispair              = FALSE;
accdesc.highestaddressfirst = FALSE;
accdesc.lowestaddress       = TRUE;

return accdesc;

end;


## Library pseudocode for shared/functions/memory/PASpace

// PASpace // ======= // Physical address spaces

type PASpace of enumeration { PAS_Root, PAS_SystemAgent, PAS_NonSecureProtected, PAS_NA6, // Reserved PAS_NA7, // Reserved PAS_Realm, PAS_Secure, PAS_NonSecure };


## Library pseudocode for shared/functions/memory/Permissions

// Permissions // =========== // Access Control bits in translation table descriptors

type Permissions of record { ap_table : bits(2), // Stage 1 hierarchical access permissions xn_table : bit, // Stage 1 hierarchical execute-never for single EL regimes pxn_table : bit, // Stage 1 hierarchical privileged execute-never uxn_table : bit, // Stage 1 hierarchical unprivileged execute-never ap : bits(3), // Stage 1 access permissions xn : bit, // Stage 1 execute-never for single EL regimes uxn : bit, // Stage 1 unprivileged execute-never pxn : bit, // Stage 1 privileged execute-never ppi : bits(4), // Stage 1 privileged indirect permissions upi : bits(4), // Stage 1 unprivileged indirect permissions ndirty : bit, // Stage 1 dirty state for indirect permissions scheme s2pi : bits(4), // Stage 2 indirect permissions s2dirty : bit, // Stage 2 dirty state po_index : bits(4), // Stage 1 overlay permissions index s2po_index : bits(4), // Stage 2 overlay permissions index s2ap : bits(2), // Stage 2 access permissions s2tag_na : bit, // Stage 2 tag access s2xnx : bit, // Stage 2 extended execute-never dbm : bit, // Dirty bit management s2xn : bit // Stage 2 execute-never };


## Library pseudocode for shared/functions/memory/PhysMemRead

// PhysMemRead // ============= // Returns the value read from memory, and a status. // Returned value is UNKNOWN if an External abort occurred while reading the // memory. // Otherwise the PhysMemRetStatus statuscode is Fault_None.

impdef func PhysMemRead{size : integer{8, 16, 32, 64, 128, 256, 512}}( desc : AddressDescriptor, accdesc : AccessDescriptor ) => (PhysMemRetStatus, bits(size)) begin return (ARBITRARY : PhysMemRetStatus, ARBITRARY : bits(size)); end;


## Library pseudocode for shared/functions/memory/PhysMemRetStatus

// PhysMemRetStatus // ================ // Fields that relate only to return values of PhysMem functions.

type PhysMemRetStatus of record { statuscode : Fault, // Fault Status extflag : bit, // IMPLEMENTATION DEFINED syndrome for External aborts merrorstate : ErrorState, // Optional error state returned on a physical memory access store64bstatus : bits(64) // Status of 64B store };


## Library pseudocode for shared/functions/memory/PhysMemWrite

// PhysMemWrite // ============== // Writes the value to memory, and returns the status of the write. // If there is an External abort on the write, the PhysMemRetStatus indicates this. // Otherwise the statuscode of PhysMemRetStatus is Fault_None.

impdef func PhysMemWrite{size : integer{8, 16, 32, 64, 128, 256, 512}}(desc : AddressDescriptor, accdesc : AccessDescriptor, value : bits(size)) => PhysMemRetStatus begin return ARBITRARY : PhysMemRetStatus; end;


## Library pseudocode for shared/functions/memory/PrefetchHint

// PrefetchHint // ============ // Prefetch hint types.

type PrefetchHint of enumeration { Prefetch_READ, Prefetch_WRITE, Prefetch_IR, Prefetch_EXEC };


## Library pseudocode for shared/functions/memory/S1AccessControls

// S1AccessControls // ================ // Effective access controls defined by stage 1 translation

type S1AccessControls of record { r : bit, // Stage 1 base read permission w : bit, // Stage 1 base write permission x : bit, // Stage 1 base execute permission gcs : bit, // Stage 1 GCS permission overlay : boolean, // Stage 1 FEAT_S1POE overlay applies or : bit, // Stage 1 FEAT_S1POE overlay read permission ow : bit, // Stage 1 FEAT_S1POE overlay write permission ox : bit, // Stage 1 FEAT_S1POE overlay execute permission wxn : bit // Stage 1 write permission implies execute-never

};


## Library pseudocode for shared/functions/memory/S2AccessControls

// S2AccessControls // ================ // Effective access controls defined by stage 2 translation

type S2AccessControls of record { r : bit, // Stage 2 read permission. w : bit, // Stage 2 write permission. x : bit, // Stage 2 execute permission. r_rcw : bit, // Stage 2 Read perms for RCW instruction. w_rcw : bit, // Stage 2 Write perms for RCW instruction. r_mmu : bit, // Stage 2 Read perms for TTW data. w_mmu : bit, // Stage 2 Write perms for TTW data. toplevel0 : bit, // IPA as top level table for TTBR0_EL1. toplevel1 : bit, // IPA as top level table for TTBR1_EL1. overlay : boolean, // Overlay enable or : bit, // Stage 2 overlay read permission. ow : bit, // Stage 2 overlay write permission. ox : bit, // Stage 2 overlay execute permission. or_rcw : bit, // Stage 2 overlay Read perms for RCW instruction. ow_rcw : bit, // Stage 2 overlay Write perms for RCW instruction. or_mmu : bit, // Stage 2 overlay Read perms for TTW data. ow_mmu : bit, // Stage 2 overlay Write perms for TTW data. };


## Library pseudocode for shared/functions/memory/Shareability

// Shareability // ============

type Shareability of enumeration { Shareability_NSH, Shareability_ISH, Shareability_OSH };


## Library pseudocode for
shared/functions/memory/SpeculativeStoreBypassBarrierToPA

// SpeculativeStoreBypassBarrierToPA // ===================================

impdef func SpeculativeStoreBypassBarrierToPA begin // Since there is no speculation in ASL model, this is a NOP. return; end;


## Library pseudocode for
shared/functions/memory/SpeculativeStoreBypassBarrierToVA

// SpeculativeStoreBypassBarrierToVA // ===================================

impdef func SpeculativeStoreBypassBarrierToVA begin // Since there is no speculation in ASL model, this is a NOP. return; end;


## Library pseudocode for shared/functions/memory/Tag

// Tag Granule size // ================

constant LOG2_TAG_GRANULE : integer{} = 4; constant TAG_GRANULE : integer{} = 1 << LOG2_TAG_GRANULE;


## Library pseudocode for shared/functions/memory/VARange

// VARange // ======= // Virtual address ranges

type VARange of enumeration { VARange_LOWER, VARange_UPPER };


## Library pseudocode for shared/functions/mpam/AltPARTIDSpace

// AltPARTIDSpace // ================ // From the Security state, EL and ALTSP configuration, determine // whether to primary space or the alt space is selected and which // PARTID space is the alternative space. Return that alternative // PARTID space if selected or the primary space if not.

func AltPARTIDSpace(el : bits(2), security : SecurityState, primaryPIDSpace : PARTIDSpaceType) => PARTIDSpaceType begin case security of when SS_NonSecure => assert el != EL3; return primaryPIDSpace; when SS_Secure => assert el != EL3; if primaryPIDSpace == PIDSpace_NonSecure then return primaryPIDSpace; end; return AltPIDSecure(el, primaryPIDSpace); when SS_Root => assert el == EL3; if MPAM3_EL3().ALTSP_EL3 == '1' then if MPAM3_EL3().RT_ALTSP_NS == '1' then return PIDSpace_NonSecure; else return PIDSpace_Secure; end; else return primaryPIDSpace; end; when SS_Realm => assert el != EL3; return AltPIDRealm(el, primaryPIDSpace); otherwise => unreachable; end; end;


## Library pseudocode for shared/functions/mpam/AltPIDRealm

// AltPIDRealm // ============= // Compute PARTID space as either the primary PARTID space or // alternative PARTID space in the Realm Security state. // Helper for AltPARTIDSpace.

func AltPIDRealm(el : bits(2), primaryPIDSpace : PARTIDSpaceType) => PARTIDSpaceType begin var PIDSpace : PARTIDSpaceType = primaryPIDSpace; case el of when EL0 => if ELIsInHost(EL0) then if () then PIDSpace = PIDSpace_NonSecure; end; elsif () then PIDSpace = PIDSpace_NonSecure; end; when EL1 => if () then PIDSpace = PIDSpace_NonSecure; end; when EL2 => if () then PIDSpace = PIDSpace_NonSecure; end; otherwise => unreachable; end; return PIDSpace; end;


## Library pseudocode for shared/functions/mpam/AltPIDSecure

// AltPIDSecure // ============== // Compute PARTID space as either the primary PARTID space or // alternative PARTID space in the Secure Security state. // Helper for AltPARTIDSpace.

func AltPIDSecure(el : bits(2), primaryPIDSpace : PARTIDSpaceType) => PARTIDSpaceType begin var PIDSpace : PARTIDSpaceType = primaryPIDSpace; case el of when EL0 => if EL2Enabled() then if ELIsInHost(EL0) then if () then PIDSpace = PIDSpace_NonSecure; end; elsif () then PIDSpace = PIDSpace_NonSecure; end; elsif MPAM3_EL3().ALTSP_HEN == '0' && MPAM3_EL3().ALTSP_HFC == '1' then PIDSpace = PIDSpace_NonSecure; end; when EL1 => if EL2Enabled() then if () then PIDSpace = PIDSpace_NonSecure; end; elsif MPAM3_EL3().ALTSP_HEN == '0' && MPAM3_EL3().ALTSP_HFC == '1' then PIDSpace = PIDSpace_NonSecure; end; when EL2 => if () then PIDSpace = PIDSpace_NonSecure; end; otherwise => unreachable; end; return PIDSpace; end;


## Library pseudocode for shared/functions/mpam/DefaultMPAMInfo

// DefaultMPAMInfo // ================= // Returns default MPAM info.

func DefaultMPAMInfo() => MPAMinfo begin assert IsFeatureImplemented(FEAT_MPAMv2);

var defaultinfo : MPAMinfo;
defaultinfo.partid = DEFAULT_PARTID;
defaultinfo.pmg    = DEFAULT_PMG;
return defaultinfo;

end;

// DefaultMPAMInfo // ================= // Returns default MPAM info. The partidspace argument sets // the PARTID space of the default MPAM information returned.

func DefaultMPAMInfo(partidspace : PARTIDSpaceType) => MPAMinfo begin assert !IsFeatureImplemented(FEAT_MPAMv2);

var defaultinfo : MPAMinfo;
defaultinfo.mpam_sp = partidspace;
defaultinfo.partid  = DEFAULT_PARTID;
defaultinfo.pmg     = DEFAULT_PMG;
return defaultinfo;

end;


## Library pseudocode for shared/functions/mpam/GenMPAM

// GenMPAM // ========= // Returns MPAMinfo for Exception level el. // If mpamdata.sm is TRUE returns MPAM information using MPAMSM_EL1. // If mpamdata.ind is TRUE and alternative ID is enabled returns MPAM information // using MPAMn_ELx.[altPARTID, altPMG]. // Otherwise returns MPAM information using MPAMn_ELx.

func GenMPAM(el_in : bits(2), mpamdata : MPAMdata) => MPAMinfo begin var returninfo : MPAMinfo; var partidel : PARTIDType; var perr : boolean; var el : bits(2) = el_in;

// Check if the guest OS application is locked by the EL2
hypervisor to
// only use the EL1 virtual machine's PARTIDs.
if (!IsFeatureImplemented(FEAT_MPAMv2) && el == EL0 &&
EL2Enabled() &&
      MPAMHCR_EL2().GSTAPP_PLK == '1' && HCR_EL2().TGE == '0') then
    el = EL1;
end;

(partidel, perr)      = GenPARTID(el, mpamdata);
let groupel : PMGType = GenPMG(el, mpamdata, perr);

returninfo.partid  = partidel;
returninfo.pmg     = groupel;
return returninfo;

end;


## Library pseudocode for shared/functions/mpam/GenMPAMAtEL

// GenMPAMAtEL // ============= // Returns MPAMinfo for the specified EL. // May be called if MPAM is not implemented (but in an version that supports // MPAM), MPAM is disabled, or in AArch32_ In AArch32, convert the mode to // EL if can and use that to drive MPAM information generation. If mode // cannot be converted, MPAM is not implemented, or MPAM is disabled return // default MPAM information for the current security state.

func GenMPAMAtEL(acctype : AccessType, el : bits(2)) => MPAMinfo begin let mpamEL : bits(2) = if acctype == AccessType_NV2 then EL2 else el;

var pspace : PARTIDSpaceType;
let security : SecurityState = SecurityStateAtEL(el);
var mpamdata : MPAMdata      = GenNewMPAMData();
if !IsFeatureImplemented(FEAT_MPAMv2) then
    pspace = PARTIDSpaceFromSS(security);
    if IsFeatureImplemented(FEAT_MPAMv0p1) && MPAMIDR_EL1().HAS_FORCE_NS == '1' then
        if MPAM3_EL3().FORCE_NS == '1' && security == SS_Secure then
            pspace = PIDSpace_NonSecure;
        end;
    end;

    if IsFeatureImplemented(FEAT_RME) && MPAMIDR_EL1().HAS_ALTSP == '1' then
        // Substitute alternative PARTID space if selected
        pspace = AltPARTIDSpace(mpamEL, security, pspace);
    end;
    if () then
        return DefaultMPAMInfo(pspace);
    end;
else
    if () then
        return DefaultMPAMInfo();
    end;
end;

case acctype of
    when AccessType_IFETCH, AccessType_IC =>
        mpamdata.ind = TRUE;
    when AccessType_SME =>
        mpamdata.sm = (ImpDefBool("Shared SMCU") ||
                       ImpDefBool("MPAMSM_EL1 label precedence"));
    when AccessType_FP, AccessType_ASIMD, AccessType_SVE =>
        mpamdata.sm = (IsFeatureImplemented(FEAT_SME) && PSTATE.SM == '1' &&
                       (ImpDefBool("Shared SMCU") ||
                        ImpDefBool("MPAMSM_EL1 label precedence")));
    when AccessType_TRBE =>
        // GenMPAMTRBE() is called when the Trace Buffer Unit is using External mode.
        assert SelfHostedTraceEnabled();
    otherwise =>
        // Other access types are DATA accesses
        mpamdata.ind = FALSE;
end;

if ((IsFeatureImplemented(FEAT_MPAMv0p1) ||
IsFeatureImplemented(FEAT_MPAMv1p1)) &&
      MPAMIDR_EL1().HAS_SDEFLT == '1') then
    if MPAM3_EL3().SDEFLT == '1' && security == SS_Secure then
        return DefaultMPAMInfo(pspace);
    end;
end;
var mpaminfo : MPAMinfo = GenMPAM(mpamEL, mpamdata);
if !IsFeatureImplemented(FEAT_MPAMv2) then
    mpaminfo.mpam_sp = pspace;
end;

return mpaminfo;

end;


## Library pseudocode for shared/functions/mpam/GenMPAMCurEL

// GenMPAMCurEL // ============== // Returns MPAMinfo for the current EL and security state. // May be called if MPAM is not implemented (but in an version that supports // MPAM), MPAM is disabled, or in AArch32_ In AArch32, convert the mode to // EL if can and use that to drive MPAM information generation. If mode // cannot be converted, MPAM is not implemented, or MPAM is disabled return // default MPAM information for the current security state.

func GenMPAMCurEL(acctype : AccessType) => MPAMinfo begin return GenMPAMAtEL(acctype, PSTATE.EL); end;


## Library pseudocode for shared/functions/mpam/GenMPAMTRBE

// GenMPAMTRBE // ============= // Returns MPAMinfo for Trace Buffer Unit in external mode.

func GenMPAMTRBE() => MPAMinfo begin assert (); var pspace : PARTIDSpaceType; if IsFeatureImplemented(FEAT_MPAMv2) then if !IsFeatureImplemented(FEAT_TRBE_MPAM) || TRBMPAM_EL1().EN == '0' then return DefaultMPAMInfo(); end; else case TRBMAR_EL1().PAS of when '00' => pspace = PIDSpace_Secure; when '01' => pspace = PIDSpace_NonSecure; when '10' => pspace = PIDSpace_Root; when '11' => pspace = PIDSpace_Realm; end;

 if !IsFeatureImplemented(FEAT_TRBE_MPAM) || TRBMPAM_EL1().EN ==
'0' then
        return DefaultMPAMInfo(pspace);
    end;
end;

assert IsFeatureImplemented(FEAT_TRBE_MPAM);

var mpaminfo : MPAMinfo;
if !IsFeatureImplemented(FEAT_MPAMv2) then mpaminfo.mpam_sp = pspace; end;
mpaminfo.partid = (if IsFeatureImplemented(FEAT_MPAMv2) then
                       TRBMPAM_EL1().MPAMv2.PARTID
                   else
                       TRBMPAM_EL1().MPAMv0or1px.PARTID);
var partid_out_of_range : boolean = FALSE;

// When the PARTID is out-of-range, the behavior is a CONSTRAINED
UNPREDICTABLE choice of:
//     - Replace the out-of-range PARTID with any in-range PARTID
//     - Replace the out-of-range PARTID with the default PARTID
let partid_max : integer = GetMPAM_PARTID_MAX();
if UInt(mpaminfo.partid) > partid_max then
    partid_out_of_range = TRUE;
    var c : Constraint;
    var partid : integer;
    (c, partid) = ConstrainUnpredictableInteger(0, partid_max,
                                                Unpredictable_OUT_OF_RANGE_ID);
    assert c IN {Constraint_DEFAULT_ID, Constraint_ANY_ID};
    case c of
        when Constraint_DEFAULT_ID => mpaminfo.partid = DEFAULT_PARTID;
        when Constraint_ANY_ID     => mpaminfo.partid = partid[15:0];
    end;
end;

if partid_out_of_range &&
ConstrainUnpredictableBool(Unpredictable_USE_DEFAULT_PMG) then
    mpaminfo.pmg = DEFAULT_PMG;
else
    mpaminfo.pmg = (if IsFeatureImplemented(FEAT_MPAMv2) then
                        TRBMPAM_EL1().MPAMv2.PMG
                    else
                        ZeroExtend{16}(TRBMPAM_EL1().MPAMv0or1px.PMG));
end;

let pmg_max : integer = GetMPAM_PMG_MAX();
if UInt(mpaminfo.pmg) > pmg_max then
    var c : Constraint;
    var pmg : integer;
    (c, pmg) = ConstrainUnpredictableInteger(0, pmg_max,
                                             Unpredictable_OUT_OF_RANGE_ID);
    assert c IN {Constraint_DEFAULT_ID, Constraint_ANY_ID};
    case c of
        when Constraint_DEFAULT_ID => mpaminfo.pmg = DEFAULT_PMG;
        when Constraint_ANY_ID     => mpaminfo.pmg = pmg[15:0];
    end;
end;

return mpaminfo;

end;


## Library pseudocode for shared/functions/mpam/GenNewMPAMData

// GenNewMPAMData // ================

func GenNewMPAMData() => MPAMdata begin var mpamdata : MPAMdata; mpamdata.ind = FALSE; mpamdata.sm = FALSE; return mpamdata; end;


## Library pseudocode for shared/functions/mpam/GenPARTID

// GenPARTID // =========== // Returns physical PARTID and error boolean for Exception level el. // If mpamdata.sm is TRUE then PARTID is from MPAMSM_EL1. // If mpamdata.ind is TRUE and alternative ID is enabled then PARTID is from MPAMn_ELx.altPARTID. // Otherwise, the PARTID is from MPAMn_ELx.

func GenPARTID(el : bits(2), mpamdata : MPAMdata) => (PARTIDType, boolean) begin var partidel : PARTIDType = GetMPAM_PARTID(el, mpamdata); var partid_err : boolean = FALSE;

// When the PARTID is out-of-range, the behavior is a CONSTRAINED
UNPREDICTABLE choice of:
//     - Replace the out-of-range PARTID with any in-range PARTID
//     - Replace the out-of-range PARTID with the default PARTID
if UInt(partidel) > GetMPAM_PARTID_MAX() then
    var c : Constraint;
    var partid : integer;
    partid_err = TRUE;
    (c, partid) = ConstrainUnpredictableInteger(0, GetMPAM_PARTID_MAX(),
                                                Unpredictable_OUT_OF_RANGE_ID);
    assert c IN {Constraint_DEFAULT_ID, Constraint_ANY_ID};
    case c of
        when Constraint_DEFAULT_ID => partidel = DEFAULT_PARTID;
        when Constraint_ANY_ID     => partidel = partid[15:0];
    end;
end;

if MPAMIsVirtual(el, mpamdata) then
    return MAP_vPARTID(partidel, partid_err);
else
    return (partidel, partid_err);
end;

end;


## Library pseudocode for shared/functions/mpam/GenPMG

// GenPMG // ======== // Returns PMG for Exception level el. // if mpamdata.sm is TRUE then PMG is from MPAMSM_EL1. // If mpamdata.ind is TRUE and alternative id is enabled, then the PMG is from MPAMn_ELx.altPMG. // Otherwise, PMG is from MPAMn_ELx. // If PARTID generation (GenPARTID) encountered an error, GenPMG() should be // called with partid_err as TRUE.

func GenPMG(el : bits(2), mpamdata : MPAMdata, partid_err : boolean) => PMGType begin if (!IsFeatureImplemented(FEAT_MPAMv2) && partid_err && ConstrainUnpredictableBool(Unpredictable_USE_DEFAULT_PMG)) then return DEFAULT_PMG; end;

let groupel : PMGType = GetMPAM_PMG(el, mpamdata);
let pmg_max : integer = GetMPAM_PMG_MAX();
if UInt(groupel) <= pmg_max then
    return groupel;
end;
return DEFAULT_PMG;

end;


## Library pseudocode for shared/functions/mpam/GetMPAM\_PARTID

// GetMPAM_PARTID // ================ // Returns a PARTID // If mpamdata.sm is TRUE then PARTID is from MPAMSM_EL1. // If mpamdata.ind is TRUE and alternative ID is enabled then PARTID is from MPAMn_ELx.altPARTID. // Otherwise, the PARTID is from MPAMn_ELx.

func GetMPAM_PARTID(MPAMn : bits(2), mpamdata : MPAMdata) => PARTIDType begin if mpamdata.sm then return (if IsFeatureImplemented(FEAT_MPAMv2) then MPAMSM_EL1().PARTID else MPAMSM_EL1().PARTID_D); end;

if (IsFeatureImplemented(FEAT_MPAMv2_ALT_ID) &&
mpamdata.ind &&
      MPAMIDR_EL1().HAS_INSTR_ALT_ID == '1') then
    case MPAMn of
        when '11' =>
            if MPAMCTL_EL3().EN_ALT_IPARTID == '1' then
                return MPAM3_EL3().altPARTID;
            else
                return MPAM3_EL3().PARTID;
            end;
        when '10' =>
            if () then
                return DEFAULT_PARTID;
            elsif MPAMCTL_EL2().EN_ALT_IPARTID == '1' then
                return MPAM2_EL2().altPARTID;
            else
                return MPAM2_EL2().PARTID;
            end;
        when '01' =>
            if MPAMCTL_EL1().EN_ALT_IPARTID == '1' then
                return MPAM1_EL1().altPARTID;
            else
                return MPAM1_EL1().PARTID;
            end;
        when '00' =>
            if ((ELIsInHost(EL0) && MPAMCTL_EL2().EN_ALT_IPARTID_EL0 == '1') ||
                  ((EL0) && MPAMCTL_EL1().EN_ALT_IPARTID_EL0 == '1')) then
                return MPAM0_EL1().altPARTID;
            else
                return MPAM0_EL1().PARTID;
            end;
    end;
end;

if IsFeatureImplemented(FEAT_MPAMv2) then
    case MPAMn of
        when '11' => return MPAM3_EL3().PARTID;
        when '10' => return (if EL2Enabled() then MPAM2_EL2().PARTID else DEFAULT_PARTID);
        when '01' => return MPAM1_EL1().PARTID;
        when '00' => return MPAM0_EL1().PARTID;
    end;
end;

if mpamdata.ind then
    case MPAMn of
        when '11' => return MPAM3_EL3().PARTID_I;
        when '10' => return (if EL2Enabled() then MPAM2_EL2().PARTID_I else DEFAULT_PARTID);
        when '01' => return MPAM1_EL1().PARTID_I;
        when '00' => return MPAM0_EL1().PARTID_I;
    end;
else
    case MPAMn of
        when '11' => return MPAM3_EL3().PARTID_D;
        when '10' => return (if EL2Enabled() then MPAM2_EL2().PARTID_D else DEFAULT_PARTID);
        when '01' => return MPAM1_EL1().PARTID_D;
        when '00' => return MPAM0_EL1().PARTID_D;
    end;
end;

end;


## Library pseudocode for shared/functions/mpam/GetMPAM\_PARTID\_MAX

// GetMPAM_PARTID_MAX // ==================== // Returns the maximum supported PARTID value for the implemented MPAM version.

func GetMPAM_PARTID_MAX() => integer begin if IsFeatureImplemented(FEAT_MPAMv2) then return UInt(MPAMIDR_EL1().MPAMv2.PARTID_MAX); end; return UInt(MPAMIDR_EL1().MPAMv0or1px.PARTID_MAX); end;


## Library pseudocode for shared/functions/mpam/GetMPAM\_PMG

// GetMPAM_PMG // ============= // Returns a PMG. // if mpamdata.sm is TRUE then PMG is from MPAMSM_EL1. // If mpamdata.ind is TRUE and alternative id is enabled, then the PMG is from MPAMn_ELx.altPMG. // Otherwise, PMG is from MPAMn_ELx.

func GetMPAM_PMG(MPAMn : bits(2), mpamdata : MPAMdata) => PMGType begin if mpamdata.sm then return (if IsFeatureImplemented(FEAT_MPAMv2) then MPAMSM_EL1().PMG else ZeroExtend{16}(MPAMSM_EL1().PMG_D)); end;

if (IsFeatureImplemented(FEAT_MPAMv2_ALT_ID) &&
mpamdata.ind &&
      MPAMIDR_EL1().HAS_INSTR_ALT_ID == '1') then
    case MPAMn of
        when '11' =>
            if MPAMCTL_EL3().EN_ALT_IPMG == '1' then
                return MPAM3_EL3().altPMG;
            else
                return MPAM3_EL3().PMG;
            end;
        when '10' =>
            if () then
                return DEFAULT_PMG;
            elsif MPAMCTL_EL2().EN_ALT_IPMG == '1' then
                return MPAM2_EL2().altPMG;
            else
                return MPAM2_EL2().PMG;
            end;
        when '01' =>
            if MPAMCTL_EL1().EN_ALT_IPMG == '1' then
                return MPAM1_EL1().altPMG;
            else
                return MPAM1_EL1().PMG;
            end;
        when '00' =>
            if ((ELIsInHost(EL0) && MPAMCTL_EL2().EN_ALT_IPMG_EL0 == '1') ||
                  ((EL0) && MPAMCTL_EL1().EN_ALT_IPMG_EL0 == '1')) then
                return MPAM0_EL1().altPMG;
            else
                return MPAM0_EL1().PMG;
            end;
    end;
end;

if IsFeatureImplemented(FEAT_MPAMv2) then
    case MPAMn of
        when '11' => return MPAM3_EL3().PMG;
        when '10' => return (if EL2Enabled() then MPAM2_EL2().PMG else DEFAULT_PMG);
        when '01' => return MPAM1_EL1().PMG;
        when '00' => return MPAM0_EL1().PMG;
    end;
end;

if mpamdata.ind then
    case MPAMn of
        when '11'=>
            return ZeroExtend{16}(MPAM3_EL3().PMG_I);
        when '10' =>
            return (if EL2Enabled() then ZeroExtend{16}(MPAM2_EL2().PMG_I) else DEFAULT_PMG);
        when '01' =>
            return ZeroExtend{16}(MPAM1_EL1().PMG_I);
        when '00' =>
            return ZeroExtend{16}(MPAM0_EL1().PMG_I);
    end;
else
    case MPAMn of
        when '11' =>
            return ZeroExtend{16}(MPAM3_EL3().PMG_D);
        when '10' =>
            return (if EL2Enabled() then ZeroExtend{16}(MPAM2_EL2().PMG_D) else DEFAULT_PMG);
        when '01' =>
            return ZeroExtend{16}(MPAM1_EL1().PMG_D);
        when '00' =>
            return ZeroExtend{16}(MPAM0_EL1().PMG_D);
    end;
end;

end;


## Library pseudocode for shared/functions/mpam/GetMPAM\_PMG\_MAX

// GetMPAM_PMG_MAX // ================= // Returns the maximum supported PMG value for the implemented MPAM version.

func GetMPAM_PMG_MAX() => integer begin if IsFeatureImplemented(FEAT_MPAMv2) then return UInt(MPAMIDR_EL1().MPAMv2.PMG_MAX); end; return UInt(MPAMIDR_EL1().MPAMv0or1px.PMG_MAX); end;


## Library pseudocode for shared/functions/mpam/MAP\_vPARTID

// MAP_vPARTID // ============= // Performs conversion of virtual PARTID into physical PARTID // Contains all of the error checking and implementation // choices for the conversion.

func MAP_vPARTID(vpartid : PARTIDType, partid_err : boolean) => (PARTIDType, boolean) begin // should not ever be called if EL2 is not implemented // or is implemented but not enabled in the current // security state. var ret : PARTIDType; var err : boolean = partid_err; var virt : integer = UInt(vpartid);

// The largest vpartid supported
let vpartid_max : integer = (UInt(MPAMIDR_EL1().VPMR_MAX) << 2) + 3;

if virt > vpartid_max then
    let (c, vid) = ConstrainUnpredictableInteger(0, vpartid_max,
                                                 Unpredictable_OUT_OF_RANGE_VID);
    assert c IN {Constraint_DEFAULT_ID, Constraint_ANY_ID};
    case c of
        when Constraint_DEFAULT_ID => virt = UInt(DEFAULT_PARTID);
        when Constraint_ANY_ID     => virt = vid;
    end;
end;

// Check for valid mapping entry.
if MPAMVPMV_EL2()[virt] == '1' then
    // vpartid has a valid mapping, access the map.
    ret = mapvpmw(virt);

// Check for default virtual PARTID valid
elsif MPAMVPMV_EL2()[0] == '1' then
    // Use default mapping for vpartid == 0.
    ret = MPAMVPM0_EL2()[0 +: 16];

// Neither is valid, use default physical PARTID.
else
    ret = DEFAULT_PARTID;
    err = TRUE;
end;

// Check that the physical PARTID is in-range.
// This physical PARTID came from a virtual mapping entry.
let partid_max : integer = GetMPAM_PARTID_MAX();
if UInt(ret) > partid_max then
    // Out of range, so return default physical PARTID
    ret = DEFAULT_PARTID;
    err = TRUE;
end;
return (ret, err);

end;


## Library pseudocode for shared/functions/mpam/MPAM

// MPAM Types // ==========

type PARTIDType of bits(16); type PMGType of bits(16);

type PARTIDSpaceType of enumeration { PIDSpace_Secure, PIDSpace_Root, PIDSpace_Realm, PIDSpace_NonSecure };

type MPAMinfo of record { mpam_sp : PARTIDSpaceType, partid : PARTIDType, pmg : PMGType }; constant DEFAULT_PARTID : PARTIDType = 0[15:0]; constant DEFAULT_PMG : PMGType = 0[15:0];

type MPAMdata of record { sm : boolean, // TRUE for SME, SVE, SIMD&FP access, and SVE prefetch // instructions, when the PE is in Streaming mode ind : boolean // Instruction not data, TRUE for instruction accesses };


## Library pseudocode for shared/functions/mpam/MPAMIsEnabled

// MPAMIsEnabled // =============== // Returns TRUE if MPAM is enabled.

func MPAMIsEnabled() => boolean begin let el : bits(2) = HighestEL(); if IsFeatureImplemented(FEAT_MPAMv2) then case el of when EL3 => return MPAMCTL_EL3().MPAMEN == '1'; when EL2 => return MPAMCTL_EL2().MPAMEN == '1'; when EL1 => return MPAMCTL_EL1().MPAMEN == '1'; end; end;

case el of
    when EL3 => return MPAM3_EL3().MPAMEN == '1';
    when EL2 => return MPAM2_EL2().MPAMEN == '1';
    when EL1 => return MPAM1_EL1().MPAMEN == '1';
end;

end;


## Library pseudocode for shared/functions/mpam/MPAMIsVirtual

// MPAMIsVirtual // =============== // If FEAT_MPAMv2 is not implemented, returns TRUE if MPAM is configured to be virtual // at the given el.

func MPAMIsVirtual(el : bits(2), mpamdata : MPAMdata) => boolean begin if IsFeatureImplemented(FEAT_MPAMv2) then return FALSE; end;

return (MPAMIDR_EL1().HAS_HCR == '1' && EL2Enabled()
&&
        ((el == EL0 && MPAMHCR_EL2().EL0_VPMEN == '1' && (EL0)) ||
         (el == EL1 && MPAMHCR_EL2().EL1_VPMEN == '1')));

end;


## Library pseudocode for shared/functions/mpam/PARTIDSpaceFromSS

// PARTIDSpaceFromSS // =================== // Returns the primary PARTID space from the Security State.

func PARTIDSpaceFromSS(security : SecurityState) => PARTIDSpaceType begin case security of when SS_NonSecure => return PIDSpace_NonSecure; when SS_Root => return PIDSpace_Root; when SS_Realm => return PIDSpace_Realm; when SS_Secure => return PIDSpace_Secure; otherwise => unreachable; end; end;


## Library pseudocode for shared/functions/mpam/UsePrimarySpaceEL10

// UsePrimarySpaceEL10 // ===================== // Checks whether Primary space is configured in the // MPAM3_EL3 and MPAM2_EL2 ALTSP control bits that affect // MPAM ALTSP use at EL1 and EL0.

func UsePrimarySpaceEL10() => boolean begin if MPAM3_EL3().ALTSP_HEN == '0' then return MPAM3_EL3().ALTSP_HFC == '0'; end; return () || () || MPAM2_EL2().ALTSP_HFC == '0'; end;


## Library pseudocode for shared/functions/mpam/UsePrimarySpaceEL2

// UsePrimarySpaceEL2 // ==================== // Checks whether Primary space is configured in the // MPAM3_EL3 and MPAM2_EL2 ALTSP control bits that affect // MPAM ALTSP use at EL2.

func UsePrimarySpaceEL2() => boolean begin if MPAM3_EL3().ALTSP_HEN == '0' then return MPAM3_EL3().ALTSP_HFC == '0'; end; return () || MPAM2_EL2().ALTSP_EL2 == '0'; end;


## Library pseudocode for shared/functions/mpam/mapvpmw

// mapvpmw // ========= // Map a virtual PARTID into a physical PARTID using // the MPAMVPMn_EL2 registers. // vpartid is now assumed in-range and valid (checked by caller) // returns physical PARTID from mapping entry.

func mapvpmw(vpartid : integer) => PARTIDType begin var vpmw : bits(64); let wd : integer = vpartid DIVRM 4; case wd of when 0 => vpmw = MPAMVPM0_EL2(); when 1 => vpmw = MPAMVPM1_EL2(); when 2 => vpmw = MPAMVPM2_EL2(); when 3 => vpmw = MPAMVPM3_EL2(); when 4 => vpmw = MPAMVPM4_EL2(); when 5 => vpmw = MPAMVPM5_EL2(); when 6 => vpmw = MPAMVPM6_EL2(); when 7 => vpmw = MPAMVPM7_EL2(); otherwise => vpmw = Zeros{64}; end; // vpme_lsb selects LSB of field within register let vpme_lsb : integer = (vpartid MOD 4) * 16; return vpmw[vpme_lsb +: 16]; end;


## Library pseudocode for shared/functions/predictionrestrict/ASID

// ASID // ==== // Effective ASID.

func ASID() => bits(NUM_ASIDBITS) begin if ELIsInHost(EL0) then var asid : bits(NUM_ASIDBITS); if TCR_EL2().A1 == '1' then asid = TTBR1_EL2().ASID; else asid = TTBR0_EL2().ASID; end; if IsFeatureImplemented(FEAT_ASID16) && TCR_EL2().AS == '1' then return asid; else return ZeroExtend{NUM_ASIDBITS}(asid[7:0]); end; end; if (EL1) then var asid : bits(NUM_ASIDBITS); if TCR_EL1().A1 == '1' then asid = TTBR1_EL1().ASID; else asid = TTBR0_EL1().ASID; end; if IsFeatureImplemented(FEAT_ASID16) && TCR_EL1().AS == '1' then return asid; else return ZeroExtend{NUM_ASIDBITS}(asid[7:0]); end; else if TTBCR().EAE == '0' then return ZeroExtend{NUM_ASIDBITS}(CONTEXTIDR().ASID); else if TTBCR().A1 == '1' then return ZeroExtend{NUM_ASIDBITS}(TTBR1().ASID); else return ZeroExtend{NUM_ASIDBITS}(TTBR0().ASID); end; end; end; end;


## Library pseudocode for shared/functions/predictionrestrict/ExecutionCntxt

// ExecutionCntxt // =============== // Context information for prediction restriction operation.

type ExecutionCntxt of record { is_vmid_valid : boolean, // is vmid valid for current context all_vmid : boolean, // should the operation be applied for all vmids vmid : bits(NUM_VMIDBITS), // if all_vmid = FALSE, vmid to which operation is applied is_asid_valid : boolean, // is asid valid for current context all_asid : boolean, // should the operation be applied for all asids asid : bits(NUM_ASIDBITS), // if all_asid = FALSE, ASID to which operation is applied software_context : bits(64), // SCXTNUM_ELx target_el : bits(2), // target EL at which operation is performed security : SecurityState, restriction : RestrictType // type of restriction operation };


## Library pseudocode for
shared/functions/predictionrestrict/RESTRICT\_PREDICTIONS

// RESTRICT_PREDICTIONS // ====================== // Clear all speculated values.

impdef func RESTRICT_PREDICTIONS(c : ExecutionCntxt) begin return; end;


## Library pseudocode for shared/functions/predictionrestrict/RestrictType

// RestrictType // ============ // Type of restriction on speculation.

type RestrictType of enumeration { RestrictType_DataValue, RestrictType_ControlFlow, RestrictType_CachePrefetch, RestrictType_Other // Any other trained speculation mechanisms than those above };


## Library pseudocode for
shared/functions/predictionrestrict/TargetSecurityState

// TargetSecurityState // ===================== // Decode the target security state for the prediction context.

func TargetSecurityState(NS : bit, NSE : bit) => SecurityState begin let curr_ss : SecurityState = SecurityStateAtEL(PSTATE.EL); if curr_ss == SS_NonSecure then return SS_NonSecure; elsif curr_ss == SS_Secure then case NS of when '0' => return SS_Secure; when '1' => return SS_NonSecure; end; elsif IsFeatureImplemented(FEAT_RME) then if curr_ss == SS_Root then case NSE::NS of when '00' => return SS_Secure; when '01' => return SS_NonSecure; when '11' => return SS_Realm; when '10' => return SS_Root; end; elsif curr_ss == SS_Realm then return SS_Realm; end; end; unreachable; end;


## Library pseudocode for shared/functions/registers/BranchTo

// BranchTo // ========== // Set program counter to a new address, with a branch type. // Parameter branch_conditional indicates whether the executed branch has a conditional encoding. // In AArch64 state the address might include a tag in the top eight bits.

func BranchTo{N}(target : bits(N), branch_type : BranchType, branch_conditional : boolean) begin Hint_Branch(branch_type); if N == 32 then assert UsingAArch32(); _PC = ZeroExtend{64}(target); else assert N == 64 && (); let target_vaddress : bits(64) = AArch64_BranchAddr(target[63:0], PSTATE.EL); if (IsFeatureImplemented(FEAT_BRBE) && branch_type IN {BranchType_DIR, BranchType_INDIR, BranchType_DIRCALL, BranchType_INDCALL, BranchType_RET}) then BRBEBranch(branch_type, branch_conditional, target_vaddress); end; let branch_taken : boolean = TRUE;

    if IsFeatureImplemented(FEAT_SPE) then
        SPEBranch{N}(target, branch_type, branch_conditional, branch_taken);
    end;

    _PC = target_vaddress;
end;
return;

end;


## Library pseudocode for shared/functions/registers/BranchToAddr

// BranchToAddr // ============== // Set program counter to a new address, with a branch type. // In AArch64 state the address does not include a tag in the top eight bits.

func BranchToAddr{N}(target : bits(N), branch_type : BranchType) begin Hint_Branch(branch_type); if N == 32 then assert UsingAArch32(); _PC = ZeroExtend{64}(target); else assert N == 64 && (); _PC = target[63:0]; end; return; end;

------------------------------------------------------------------------------ Page 1 of 1. End of thread.