This forum was built by humans, for humans. AI was used exclusively for security auditing. The forum officially launched on November 24, 2026. Read more

romdump.net
romdump.net › Forum › Silicon & Architectures › Shared pseudocode: part 1 of 36

Writeup Shared pseudocode: part 1 of 36

started by admin

admin admin admingod mode Posts 116
Rep 505
Joined Nov 2026
2d ago OP #113

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

Shared Pseudocode Functions

This page displays common pseudocode functions shared by many pages

Pseudocode

Library pseudocode for aarch32/at/AArch32_AT

// AArch32_AT
// ============
// Perform address translation as per AT instructions.

func AArch32_AT(vaddress : bits(32), stage_in : TranslationStage, el : bits(2), ataccess : ATAccess) begin var stage : TranslationStage = stage_in; var ss : SecurityState; var regime : Regime; var eae : boolean;

// ATS1Hx instructionsif el == EL2 then    regime = Regime_EL2;    eae = TRUE;    ss = SS_NonSecure;// ATS1Cxx instructionselsif stage == TranslationStage_1 || (stage == TranslationStage_12 && (EL2)) then    stage = TranslationStage_1;    ss = SecurityStateAtEL(PSTATE.EL);    regime = if ss == SS_Secure && ELUsingAArch32(EL3) then Regime_EL30 else Regime_EL10;    eae = TTBCR().EAE == '1';// ATS12NSOxx instructionselse    regime = Regime_EL10;    eae = (if HaveEL(EL3) && ELUsingAArch32(EL3) then TTBCR_NS().EAE == '1'                                                 else TTBCR().EAE == '1');    ss = SS_NonSecure;end;var addrdesc : AddressDescriptor;var sdftype : SDFType;let aligned : boolean = TRUE;var supersection : bit = '0';let accdesc : AccessDescriptor = CreateAccDescAT(ss, el, ataccess);// Prepare fault fields in case a fault is detectedvar fault : FaultRecord = NoFault(accdesc, ZeroExtend{64}(vaddress));if eae then    (fault, addrdesc) = AArch32_S1TranslateLD(fault, regime, vaddress, aligned, accdesc);else    (fault, addrdesc, sdftype) = AArch32_S1TranslateSD(fault, regime, vaddress, aligned,                                                       accdesc);    supersection = if sdftype == SDFType_Supersection then '1' else '0';end;// ATS12NSOxx instructionsif stage == TranslationStage_12 && fault.statuscode == Fault_None then    (fault, addrdesc) = AArch32_S2Translate(fault, addrdesc, aligned, accdesc);end;if fault.statuscode != Fault_None then    // Take exception on External abort or when a fault occurs on translation table walk    if IsExternalAbort(fault) || (PSTATE.EL == EL1 && EL2Enabled() && fault.s2fs1walk) then        PAR() = ARBITRARY : bits(64);        AArch32_Abort(fault);    end;end;addrdesc.fault = fault;if (eae || (stage == TranslationStage_12 && (HCR().VM == '1' || HCR().DC == '1')) ||      (stage == TranslationStage_1 && el != EL2 && PSTATE.EL == EL2)) then    AArch32_EncodePARLD(addrdesc, ss);else    AArch32_EncodePARSD(addrdesc, supersection, ss);end;return;

end;

Library pseudocode for aarch32/at/AArch32_EncodePARLD

// AArch32_EncodePARLD
// =====================
// Returns 64-bit format PAR on address translation instruction.

func AArch32_EncodePARLD(addrdesc : AddressDescriptor, ss : SecurityState) begin PAR()[63:0] = Zeros{64}; if !IsFault(addrdesc) then var ns : bit; if ss == SS_NonSecure then ns = ARBITRARY : bit; elsif addrdesc.paddress.paspace == PAS_Secure then ns = '0'; else ns = '1'; end; PAR().F = '0'; PAR().F0_64.SH = ReportedPARShareability(PAREncodeShareability(addrdesc.memattrs)); PAR().NS = ns; PAR()[10] = ImpDefBit("Non-Faulting PAR"); // IMPDEF PAR().LPAE = '1'; PAR().F0_64.PA = addrdesc.paddress.address[39:12]; PAR().ATTR = ReportedPARAttrs(EncodePARAttrs(addrdesc.memattrs)); else PAR().F = '1'; PAR().FST = AArch32_PARFaultStatusLD(addrdesc.fault); PAR().S2WLK = if addrdesc.fault.s2fs1walk then '1' else '0'; PAR().FSTAGE = if addrdesc.fault.secondstage then '1' else '0'; PAR().LPAE = '1'; PAR()[63:48] = ImpDefBits{16}("Faulting PAR"); // IMPDEF end; return; end;

Library pseudocode for aarch32/at/AArch32_EncodePARSD

// AArch32_EncodePARSD
// =====================
// Returns 32-bit format PAR on address translation instruction.

func AArch32_EncodePARSD(addrdesc_in : AddressDescriptor, supersection : bit, ss : SecurityState) begin PAR()[31:0] = Zeros{32}; var addrdesc : AddressDescriptor = addrdesc_in; if !IsFault(addrdesc) then if (addrdesc.memattrs.memtype == MemType_Device || (addrdesc.memattrs.inner.attrs == MemAttr_NC && addrdesc.memattrs.outer.attrs == MemAttr_NC)) then addrdesc.memattrs.shareability = Shareability_OSH; end; var ns : bit; if ss == SS_NonSecure then ns = ARBITRARY : bit; elsif addrdesc.paddress.paspace == PAS_Secure then ns = '0'; else ns = '1'; end; let sh : bits(2) = ReportedPARShareability(PAREncodeShareability(addrdesc.memattrs)); PAR().F = '0'; PAR().SS = supersection; PAR().Outer = AArch32_ReportedOuterAttrs(AArch32_PAROuterAttrs(addrdesc.memattrs)); PAR().Inner = AArch32_ReportedInnerAttrs(AArch32_PARInnerAttrs(addrdesc.memattrs)); PAR().F0_32.SH = sh[1]; PAR()[8] = ImpDefBit("Non-Faulting PAR"); // IMPDEF PAR().NS = ns; PAR().NOS = sh[0]; PAR().LPAE = '0'; PAR().F0_32.PA = addrdesc.paddress.address[31:12]; else PAR().F = '1'; PAR().FST = AArch32_PARFaultStatusSD(addrdesc.fault); PAR().LPAE = '0'; PAR()[31:16] = ImpDefBits{16}("Faulting PAR"); // IMPDEF end; return; end;

Library pseudocode for aarch32/at/AArch32_PARFaultStatusLD

// AArch32_PARFaultStatusLD
// ==========================
// Fault status field decoding of 64-bit PAR

func AArch32_PARFaultStatusLD(fault : FaultRecord) => bits(6) begin var syndrome : bits(6); if fault.statuscode == Fault_Domain then // Report Domain fault assert fault.level IN {1,2}; syndrome[1:0] = if fault.level == 1 then '01' else '10'; syndrome[5:2] = '1111'; else syndrome = EncodeLDFSC(fault.statuscode, fault.level); end; return syndrome; end;

Library pseudocode for aarch32/at/AArch32_PARFaultStatusSD

// AArch32_PARFaultStatusSD
// ==========================
// Fault status field decoding of 32-bit PAR.

func AArch32_PARFaultStatusSD(fault : FaultRecord) => bits(6) begin var syndrome : bits(6);

syndrome[5] = if IsExternalAbort(fault) then fault.extflag else '0';syndrome[4:0] = EncodeSDFSC(fault.statuscode, fault.level);return syndrome;

end;

Library pseudocode for aarch32/at/AArch32_PARInnerAttrs

// AArch32_PARInnerAttrs
// =======================
// Convert orthogonal attributes and hints to 32-bit PAR Inner field.

func AArch32_PARInnerAttrs(memattrs : MemoryAttributes) => bits(3) begin var result : bits(3);

if memattrs.memtype == MemType_Device then    if memattrs.device == DeviceType_nGnRnE then        result = '001'; // Non-cacheable    elsif memattrs.device == DeviceType_nGnRE then        result = '011'; // Non-cacheable    end;else    let inner : MemAttrHints = memattrs.inner;    if inner.attrs == MemAttr_NC then        result = '000'; // Non-cacheable    elsif inner.attrs == MemAttr_WB && inner.hints[0] == '1' then        result = '101'; // Write-Back, Write-Allocate    elsif inner.attrs == MemAttr_WT then        result = '110'; // Write-Through    elsif inner.attrs == MemAttr_WB && inner.hints[0] == '0' then        result = '111'; // Write-Back, no Write-Allocate    end;end;return result;

end;

Library pseudocode for aarch32/at/AArch32_PAROuterAttrs

// AArch32_PAROuterAttrs
// =======================
// Convert orthogonal attributes and hints to 32-bit PAR Outer field.

func AArch32_PAROuterAttrs(memattrs : MemoryAttributes) => bits(2) begin var result : bits(2);

if memattrs.memtype == MemType_Device then    result = ARBITRARY : bits(2);else    let outer : MemAttrHints = memattrs.outer;    if outer.attrs == MemAttr_NC then        result = '00'; // Non-cacheable    elsif outer.attrs == MemAttr_WB && outer.hints[0] == '1' then        result = '01'; // Write-Back, Write-Allocate    elsif outer.attrs == MemAttr_WT && outer.hints[0] == '0' then        result = '10'; // Write-Through, no Write-Allocate    elsif outer.attrs == MemAttr_WB && outer.hints[0] == '0' then        result = '11'; // Write-Back, no Write-Allocate    end;end;return result;

end;

Library pseudocode for aarch32/at/AArch32_ReportedInnerAttrs

// AArch32_ReportedInnerAttrs
// ============================
// The value returned in this field can be the resulting attribute, as determined by any permitted
// implementation choices and any applicable configuration bits, instead of the value that appears
// in the translation table descriptor.

impdef func AArch32_ReportedInnerAttrs(attrs : bits(3)) => bits(3) begin return attrs; end;

Library pseudocode for aarch32/at/AArch32_ReportedOuterAttrs

// AArch32_ReportedOuterAttrs
// ============================
// The value returned in this field can be the resulting attribute, as determined by any permitted
// implementation choices and any applicable configuration bits, instead of the value that appears
// in the translation table descriptor.

impdef func AArch32_ReportedOuterAttrs(attrs : bits(2)) => bits(2) begin return attrs; end;

Library pseudocode for aarch32/at/GetPAR_F

// GetPAR_F
// ==========
// Query the PAR.F field.

func GetPAR_F() => bit begin return PAR().F; end;

Library pseudocode for aarch32/at/GetPAR_LPAE

// GetPAR_LPAE
// =============
// Query the PAR.LPAE field.

func GetPAR_LPAE() => bit begin return PAR().LPAE; end;

Library pseudocode for aarch32/dc/AArch32_CanTrapDC

// AArch32_CanTrapDC
// ===================
// Determines whether the execution of the DC instruction can be trapped.

func AArch32_CanTrapDC(cacheop : CacheOp, opscope : CacheOpScope) => boolean begin return ((cacheop, opscope) || ImpDefBool( "When DC is treated as NOP, data cache maintenance operations are trapped")); end;

Library pseudocode for aarch32/dc/AArch32_DC

// AArch32_DC
// ============
// Perform Data Cache Operation.

func AArch32_DC(regval : bits(32), cacheop : CacheOp, opscope : CacheOpScope) begin var cache : CacheRecord;

cache.acctype   = AccessType_DC;cache.cacheop   = cacheop;cache.opscope   = opscope;cache.cachetype = CacheType_Data;cache.security  = SecurityStateAtEL(PSTATE.EL);if opscope == CacheOpScope_SetWay then    cache.shareability = Shareability_NSH;    cache.(setnum, waynum, level) = DecodeSW(ZeroExtend{64}(regval),                                                         CacheType_Data);    if (cacheop == CacheOp_Invalidate && PSTATE.EL == EL1 && EL2Enabled() &&          (((EL2) && (HCR_EL2().SWIO == '1' || HCR_EL2().[DC,VM] != '00')) ||             (ELUsingAArch32(EL2) && (HCR().SWIO == '1' || HCR().[DC,VM] != '00')))) then        cache.cacheop = CacheOp_CleanInvalidate;    end;    CACHE_OP(cache);    return;end;if EL2Enabled() then    if PSTATE.EL IN {EL0, EL1} then        cache.is_vmid_valid = TRUE;        cache.vmid          = VMID();    else        cache.is_vmid_valid = FALSE;    end;else    cache.is_vmid_valid = FALSE;end;if PSTATE.EL == EL0 then    cache.is_asid_valid = TRUE;    cache.asid          = ASID();else    cache.is_asid_valid = FALSE;end;var vaddress : bits(32) = regval;var size : integer = 0;        // by default no watchpoint addressif cacheop == CacheOp_Invalidate then    size     = DataCacheWatchpointSize();    vaddress = AlignDownSize{32}(regval, size as AddressSize);end;cache.vaddress = ZeroExtend{64}(vaddress);let aligned : boolean               = TRUE;let accdesc : AccessDescriptor      = CreateAccDescDC(cache);var memaddrdesc : AddressDescriptor = AArch32_TranslateAddress(vaddress, accdesc,                                                               aligned, size);if IsFault(memaddrdesc) then    memaddrdesc.fault.vaddress = ZeroExtend{64}(regval);    AArch32_Abort(memaddrdesc.fault);end;cache.paddress = memaddrdesc.paddress;if opscope == CacheOpScope_PoC then    cache.shareability = memaddrdesc.memattrs.shareability;else    cache.shareability = Shareability_NSH;end;if (cacheop == CacheOp_Invalidate && PSTATE.EL == EL1 && EL2Enabled() &&      (((EL2) && HCR_EL2().[DC,VM] != '00') ||         (ELUsingAArch32(EL2) && HCR().[DC,VM] != '00'))) then    cache.cacheop = CacheOp_CleanInvalidate;end;CACHE_OP(cache);return;

end;

Library pseudocode for aarch32/dc/AArch32_TreatDCAsNOP

// AArch32_TreatDCAsNOP
// ======================
// Determines whether the execution of the DC instruction is treated as a NOP.

func AArch32_TreatDCAsNOP(cacheop : CacheOp, opscope : CacheOpScope) => boolean begin // DC to PoU: IMPLEMENTATION DEFINED - treated as NOP if LoUU and LoUIS are 0 if opscope == CacheOpScope_PoU && CLIDR().LoUU == '000' && CLIDR().LoUIS == '000' then return ImpDefBool("DC to PoU is treated as a NOP"); end;

// DC to PoC: IMPLEMENTATION DEFINED - treated as NOP if LoC is 0if opscope == CacheOpScope_PoC && CLIDR().LoC == '000' then    return ImpDefBool("DC to PoC is treated as a NOP");end;return FALSE;

end;

Library pseudocode for aarch32/debug/VCRMatch/AArch32_VCRMatch

// AArch32_VCRMatch
// ==================

func AArch32_VCRMatch(vaddress : bits(32)) => boolean begin

var match : boolean;if UsingAArch32() && ELUsingAArch32(EL1) && PSTATE.EL != EL2 then    // Each bit position in this string corresponds to a bit in DBGVCR and an exception vector.    var match_word : bits(32) = Zeros{};    let ss : SecurityState = CurrentSecurityState();    if vaddress[31:5] == ExcVectorBase()[31:5] then        if HaveEL(EL3) && ss == SS_NonSecure then            match_word[UInt(vaddress[4:2]) + 24] = '1';     // Non-secure vectors        else            match_word[UInt(vaddress[4:2]) + 0] = '1';      // Secure vectors (or no EL3)        end;    end;    if (HaveEL(EL3) && ELUsingAArch32(EL3) && vaddress[31:5] == MVBAR()[31:5] &&        ss == SS_Secure) then        match_word[UInt(vaddress[4:2]) + 8] = '1';          // Monitor vectors    end;    // Mask out bits not corresponding to vectors.    var mask : bits(32);    if (EL3) then        mask = '00000000'::'00000000'::'00000000'::'11011110'; // DBGVCR[31:8] are RES0    elsif (EL3) then        mask = '11011110'::'00000000'::'00000000'::'11011110'; // DBGVCR[15:8] are RES0    else        mask = '11011110'::'00000000'::'11011100'::'11011110';    end;    match_word = match_word AND DBGVCR() AND mask;    match = !IsZero(match_word);    // Check for UNPREDICTABLE case - match on Prefetch Abort and Data Abort vectors    if !IsZero(match_word[28:27,12:11,4:3]) && DebugTarget() == PSTATE.EL then        match = ConstrainUnpredictableBool(Unpredictable_VCMATCHDAPA);    end;    if !IsZero(vaddress[1:0]) && match then        match = ConstrainUnpredictableBool(Unpredictable_VCMATCHHALF);    end;else    match = FALSE;end;return match;

end;

Library pseudocode for aarch32/debug/authentication/AArch32_SelfHostedSecurePrivilegedInvasiveDebugEnabled

// AArch32_SelfHostedSecurePrivilegedInvasiveDebugEnabled
// ========================================================

func AArch32_SelfHostedSecurePrivilegedInvasiveDebugEnabled() => boolean begin // The definition of this function is IMPLEMENTATION DEFINED. // In the recommended interface, AArch32_SelfHostedSecurePrivilegedInvasiveDebugEnabled returns // the state of the (DBGEN AND SPIDEN) signal. if (EL3) && NonSecureOnlyImplementation() then return FALSE; end; return DBGEN == HIGH && SPIDEN == HIGH; end;

Library pseudocode for aarch32/debug/breakpoint/AArch32_BreakpointMatch

// AArch32_BreakpointMatch
// =========================
// Breakpoint matching in an AArch32 translation regime.

func AArch32_BreakpointMatch(n : integer, vaddress : bits(32), accdesc : AccessDescriptor, size : integer) => BreakpointInfo begin assert ELUsingAArch32(S1TranslationRegime()); assert n < NumBreakpointsImplemented();

var brkptinfo : BreakpointInfo;let enabled : boolean    = DBGBCR(n).E == '1';let isbreakpnt : boolean = TRUE;let linked : boolean     = DBGBCR(n).BT == '0x01';let linked_to : boolean  = FALSE;let linked_n : integer{} = UInt(DBGBCR(n).LBN);let state_match : boolean = AArch32_StateMatch(DBGBCR(n).SSC, DBGBCR(n).HMC, DBGBCR(n).PMC,                                               linked, linked_n, isbreakpnt,  accdesc);var (value_match, value_mismatch) = AArch32_BreakpointValueMatch(n,vaddress, linked_to);if size == 4 then                    // Check second halfword    // If the breakpoint address and BAS of an Address breakpoint match the address of the    // second halfword of an instruction, but not the address of the first halfword, it is    // CONSTRAINED UNPREDICTABLE whether this breakpoint generates a Breakpoint debug    // event.    let (match_i, mismatch_i) = AArch32_BreakpointValueMatch(n, vaddress + 2, linked_to);    if !value_match &amp;&amp; match_i then        value_match = ConstrainUnpredictableBool(Unpredictable_BPMATCHHALF);    end;    if value_mismatch &amp;&amp; !mismatch_i then        value_mismatch = ConstrainUnpredictableBool(Unpredictable_BPMISMATCHHALF);    end;end;if vaddress[1] == '1' &amp;&amp; DBGBCR(n).BAS == '1111' then    // The above notwithstanding, if DBGBCR(n).BAS == '1111', then it is CONSTRAINED    // UNPREDICTABLE whether or not a Breakpoint debug event is generated for an instruction    // at the address DBGBVR(n)+2.    if value_match then        value_match = ConstrainUnpredictableBool(Unpredictable_BPMATCHHALF);    end;    if !value_mismatch then        value_mismatch = ConstrainUnpredictableBool(Unpredictable_BPMISMATCHHALF);    end;end;brkptinfo.match    = value_match &amp;&amp; state_match &amp;&amp; enabled;brkptinfo.mismatch = value_mismatch &amp;&amp; state_match &amp;&amp; enabled;return brkptinfo;

end;

Library pseudocode for aarch32/debug/breakpoint/AArch32_BreakpointValueMatch

// AArch32_BreakpointValueMatch
// ==============================
// The first result is whether an Address Match or Context breakpoint is programmed on the
// instruction at "address". The second result is whether an Address Mismatch breakpoint is
// programmed on the instruction, that is, whether the instruction should be stepped.

func AArch32_BreakpointValueMatch(n_in : integer, vaddress : bits(32), linked_to : boolean) => (boolean, boolean) begin

// "n" is the identity of the breakpoint unit to match against.// "vaddress" is the current instruction address, ignored if linked_to is TRUE and for Context//   matching breakpoints.// "linked_to" is TRUE if this is a call from StateMatch for linking.var n : integer = n_in;var c : Constraint;// If a non-existent breakpoint then it is CONSTRAINED UNPREDICTABLE whether this gives// no match or the breakpoint is mapped to another UNKNOWN implemented breakpoint.if n &gt;= NumBreakpointsImplemented() then    (c, n) = ConstrainUnpredictableInteger(0, NumBreakpointsImplemented() - 1,                                           Unpredictable_BPNOTIMPL);    assert c IN {Constraint_DISABLED, Constraint_UNKNOWN};    if c == Constraint_DISABLED then return (FALSE, FALSE); end;end;// If this breakpoint is not enabled, it cannot generate a match.// (This could also happen on a call from StateMatch for linking).if DBGBCR(n).E == '0' then return (FALSE, FALSE); end;var dbgtype : bits(4) = DBGBCR(n).BT;(c, dbgtype) = AArch32_ReservedBreakpointType(n, dbgtype);if c == Constraint_DISABLED then return (FALSE, FALSE); end;// Otherwise the dbgtype value returned by AArch32_ReservedBreakpointType is valid.// Determine what to compare against.let match_addr : boolean      = (dbgtype == '0x0x');let mismatch : boolean        = (dbgtype == '010x');let match_vmid : boolean      = (dbgtype == '10xx');let match_cid1 : boolean      = (dbgtype == 'xx1x');let match_cid2 : boolean      = (dbgtype == '11xx');let linking_enabled : boolean = (dbgtype == 'xxx1');// If called from StateMatch, is CONSTRAINED UNPREDICTABLE if the// breakpoint is not programmed with linking enabled.if linked_to &amp;&amp; !linking_enabled then    if !ConstrainUnpredictableBool(Unpredictable_BPLINKINGDISABLED) then        return (FALSE, FALSE);    end;end;// If called from BreakpointMatch return FALSE for Linked context ID and/or VMID matches.if !linked_to &amp;&amp; linking_enabled &amp;&amp; !match_addr then    return (FALSE, FALSE);end;var bvr_match : boolean  = FALSE;var bxvr_match : boolean = FALSE;// Do the comparison.if match_addr then    let byte : integer = UInt(vaddress[1:0]);    assert byte IN {0,2};                     // "vaddress" is halfword aligned    let byte_select_match : boolean = (DBGBCR(n).BAS[byte] == '1');    bvr_match = (vaddress[31:2] == DBGBVR(n)[31:2]) &amp;&amp; byte_select_match;elsif match_cid1 then    bvr_match = (PSTATE.EL != EL2 &amp;&amp; CONTEXTIDR() == DBGBVR(n)[31:0]);end;if match_vmid then    let vmid : bits(NUM_VMIDBITS) = VMID();    var bvr_vmid : bits(NUM_VMIDBITS);    if ELUsingAArch32(EL2) then        bvr_vmid = ZeroExtend{NUM_VMIDBITS}(DBGBXVR(n)[7:0]);    elsif !IsFeatureImplemented(FEAT_VMID16) || VTCR_EL2().VS == '0' then        bvr_vmid = ZeroExtend{NUM_VMIDBITS}(DBGBXVR(n)[7:0]);    else        bvr_vmid = DBGBXVR(n)[15:0];    end;    bxvr_match = (PSTATE.EL IN {EL0, EL1} &amp;&amp; EL2Enabled() &amp;&amp; vmid == bvr_vmid);elsif match_cid2 then    bxvr_match = (PSTATE.EL != EL3 &amp;&amp; EL2Enabled() &amp;&amp; (EL2) &amp;&amp;                  DBGBXVR(n)[31:0] == CONTEXTIDR_EL2()[31:0]);end;let bvr_match_valid : boolean  = (match_addr || match_cid1);let bxvr_match_valid : boolean = (match_vmid || match_cid2);let match : boolean = (!bxvr_match_valid || bxvr_match) &amp;&amp; (!bvr_match_valid || bvr_match);return (match &amp;&amp; !mismatch, !match &amp;&amp; mismatch);

end;

Library pseudocode for aarch32/debug/breakpoint/AArch32_ReservedBreakpointType

// AArch32_ReservedBreakpointType
// ================================
// Checks if the given DBGBCR(n).BT value is reserved and will generate Constrained Unpredictable
// behavior, otherwise returns Constraint_NONE.

func AArch32_ReservedBreakpointType(n : integer, bt_in : bits(4)) => (Constraint, bits(4)) begin var bt : bits(4) = bt_in; var reserved : boolean = FALSE; let context_aware : boolean = IsContextAwareBreakpoint(n);

// Address mismatchif bt == '010x' &amp;&amp; HaltOnBreakpointOrWatchpoint() then    reserved = TRUE;end;// Context matchingif bt != '0x0x' &amp;&amp; !context_aware then    reserved = TRUE;end;// EL2 extensionif bt == '1xxx' &amp;&amp; (EL2) then    reserved = TRUE;end;// Context matchingif (bt IN {'011x','11xx'} &amp;&amp; !IsFeatureImplemented(FEAT_VHE) &amp;&amp;      !IsFeatureImplemented(FEAT_Debugv8p2)) then    reserved = TRUE;end;if reserved then    var c : Constraint;    (c, bt) = ConstrainUnpredictableBits{4}(Unpredictable_RESBPTYPE);    assert c IN {Constraint_DISABLED, Constraint_UNKNOWN};    if c == Constraint_DISABLED then        return (c, ARBITRARY : bits(4));    // Otherwise the value returned by ConstrainUnpredictableBits must be a not-reserved value    end;end;return (Constraint_NONE, bt);

end;

Library pseudocode for aarch32/debug/breakpoint/AArch32_StateMatch

// AArch32_StateMatch
// ====================
// Determine whether a breakpoint or watchpoint is enabled in the current mode and state.

func AArch32_StateMatch(ssc_in : bits(2), hmc_in : bit, pxc_in : bits(2), linked_in : boolean, linked_n_in : integer, isbreakpnt : boolean, accdesc : AccessDescriptor) => boolean begin

// "ssc_in","hmc_in","pxc_in" are the control fields from the DBGBCR(n) or DBGWCR(n) register.// "linked_in" is TRUE if this is a linked breakpoint/watchpoint type.// "linked_n_in" is the linked breakpoint number from the DBGBCR(n) or DBGWCR(n) register.// "isbreakpnt" is TRUE for breakpoints, FALSE for watchpoints.// "accdesc" describes the properties of the access being matched.var hmc : bit          = hmc_in;var ssc : bits(2)      = ssc_in;var pxc : bits(2)      = pxc_in;var linked : boolean   = linked_in;var linked_n : integer = linked_n_in;// If parameters are set to a reserved type, behaves as either disabled or a defined typevar c : Constraint;// SSCE value discarded as there is no SSCE bit in AArch32_(c, ssc, -, hmc, pxc) = CheckValidStateMatch(ssc, '0', hmc, pxc, isbreakpnt);if c == Constraint_DISABLED then return FALSE; end;// Otherwise the hmc,ssc,pxc values are either valid or the values returned by// CheckValidStateMatch are valid.let pl2_match : boolean = HaveEL(EL2) &amp;&amp; ((hmc == '1' &amp;&amp; (ssc::pxc != '1000')) || ssc == '11');let pl1_match : boolean = pxc[0] == '1';let pl0_match : boolean = pxc[1] == '1';let ssu_match : boolean = isbreakpnt &amp;&amp; hmc == '0' &amp;&amp; pxc == '00' &amp;&amp; ssc != '11';var priv_match : boolean;if ssu_match then    priv_match = PSTATE.M IN {M32_User,M32_Svc,M32_System};else    case accdesc.el of        when EL3 =&gt; priv_match = pl1_match;           // EL3 and EL1 are both PL1        when EL2 =&gt; priv_match = pl2_match;        when EL1 =&gt; priv_match = pl1_match;        when EL0 =&gt; priv_match = pl0_match;    end;end;// Security state matchvar ss_match : boolean;case ssc of    when '00' =&gt; ss_match = TRUE;                                     // Both    when '01' =&gt; ss_match = accdesc.ss == SS_NonSecure;               // Non-secure only    when '10' =&gt; ss_match = accdesc.ss == SS_Secure;                  // Secure only    when '11' =&gt; ss_match = (hmc == '1' || accdesc.ss == SS_Secure);  // HMC=1 -&gt; Both,                                                                      // HMC=0 -&gt; Secure onlyend;var linked_match : boolean = FALSE;if linked then    // "linked_n" must be an enabled context-aware breakpoint unit.    // If it is not context-aware then it is CONSTRAINED UNPREDICTABLE whether    // this gives no match, gives a match without linking, or linked_n is mapped to some    // UNKNOWN breakpoint that is context-aware.    if (linked_n) then        let (first_ctx_cmp, last_ctx_cmp) : (integer, integer) = ContextAwareBreakpointRange();        (c, linked_n) = ConstrainUnpredictableInteger(first_ctx_cmp, last_ctx_cmp,                                                      Unpredictable_BPNOTCTXCMP);        assert c IN {Constraint_DISABLED, Constraint_NONE, Constraint_UNKNOWN};        case c of            when Constraint_DISABLED =&gt;  return FALSE;      // Disabled            when Constraint_NONE =&gt;      linked = FALSE;    // No linking            // Otherwise ConstrainUnpredictableInteger returned a context-aware breakpoint        end;    end;    let vaddress : bits(32) = ARBITRARY : bits(32);    let linked_to : boolean = TRUE;    (linked_match,-) = AArch32_BreakpointValueMatch(linked_n, vaddress, linked_to);end;return priv_match &amp;&amp; ss_match &amp;&amp; (!linked || linked_match);

end;

Library pseudocode for aarch32/debug/enables/AArch32_GenerateDebugExceptions

// AArch32_GenerateDebugExceptions
// =================================

func AArch32_GenerateDebugExceptions() => boolean begin let ss : SecurityState = CurrentSecurityState(); return AArch32_GenerateDebugExceptionsFrom(PSTATE.EL, ss); end;

Library pseudocode for aarch32/debug/enables/AArch32_GenerateDebugExceptionsFrom

// AArch32_GenerateDebugExceptionsFrom
// =====================================

func AArch32_GenerateDebugExceptionsFrom(from_el : bits(2), from_state : SecurityState) => boolean begin if (DebugTargetFrom(from_state)) then let mask : bit = '0'; // No PSTATE.D in AArch32 state return AArch64_GenerateDebugExceptionsFrom(from_el, from_state, mask); end; if DBGOSLSR().OSLK == '1' || DoubleLockStatus() || Halted() then return FALSE; end;

var enabled : boolean;if HaveEL(EL3) &amp;&amp; from_state == SS_Secure then    assert from_el != EL2;    // Secure EL2 always uses AArch64    if IsSecureEL2Enabled() then        // Implies that EL3 and EL2 both using AArch64        enabled = MDCR_EL3().SDD == '0';    else        let spd : bits(2) = if ELUsingAArch32(EL3) then SDCR().SPD else MDCR_EL3().SPD32;        if spd[1] == '1' then            enabled = spd[0] == '1';        else            // SPD == 0b01 is reserved, but behaves the same as 0b00.            enabled = AArch32_SelfHostedSecurePrivilegedInvasiveDebugEnabled();        end;    end;    if from_el == EL0 then enabled = enabled || SDER().SUIDEN == '1'; end;else    enabled = from_el != EL2;end;return enabled;

end;

Library pseudocode for aarch32/debug/pmu/AArch32_IncrementCycleCounter

// AArch32_IncrementCycleCounter
// ===============================
// Increment the cycle counter and possibly set overflow bits.

func AArch32_IncrementCycleCounter begin if (CYCLE_COUNTER_ID) then return; end; var d : bit = PMCR().D; // Check divide-by-64 var lc : bit = PMCR().LC; // Effective value of 'D' bit is 0 when Effective value of LC is '1' if lc == '1' then d = '0'; end; if d == '1' && () then return; end;

let old_value : integer = UInt(PMCCNTR());let new_value : integer = old_value + 1;PMCCNTR() = new_value[63:0];let ovflw : integer{} = if lc == '1' then 64 else 32;if old_value[64:ovflw] != new_value[64:ovflw] then    PMOVSSET().C = '1';end;return;

end;

Library pseudocode for aarch32/debug/pmu/AArch32_IncrementEventCounter

// AArch32_IncrementEventCounter
// ===============================
// Increment the specified event counter 'idx' by the specified amount 'increment'.
// 'Vm' is the value event counter 'idx-1' is being incremented by if 'idx' is odd,
// zero otherwise.
// Returns the amount the counter was incremented by.

func AArch32_IncrementEventCounter(idx : integer, increment_in : integer, Vm : integer) => integer begin if HaveAArch64() then // Force the counter to be incremented as a 64-bit counter. return AArch64_IncrementEventCounter(idx, increment_in, Vm); end;

// In this model, event counters in an AArch32-only implementation are 32 bits and// the LP bits are RES0 in this model, even if FEAT_PMUv3p5 is implemented.var old_value : integer;var new_value : integer;old_value = UInt(PMEVCNTR(idx));let increment : integer = PMUCountValue(idx, increment_in, Vm);new_value = old_value + increment;PMEVCNTR(idx) = new_value[31:0];let ovflw : integer{} = 32;if old_value[64:ovflw] != new_value[64:ovflw] then    PMOVSSET()[idx] = '1';    // Check for the CHAIN event from an even counter    if (idx[0] == '0' &amp;&amp; idx + 1 &lt; NUM_PMU_COUNTERS &amp;&amp;          (GetPMUCounterRange(idx) == GetPMUCounterRange(idx+1) ||             ConstrainUnpredictableBool(Unpredictable_COUNT_CHAIN))) then        // If PMU counters idx and idx+1 are not in same range,        // it is CONSTRAINED UNPREDICTABLE if CHAIN event is counted        PMUEvent(PMU_EVENT_CHAIN, 1, idx + 1);    end;end;return increment;

end;

Library pseudocode for aarch32/debug/pmu/AArch32_PMUCycle

// AArch32_PMUCycle
// ==================
// Called at the end of each cycle to increment event counters and
// check for PMU overflow. In pseudocode, a cycle ends after the
// execution of the operational pseudocode.

func AArch32_PMUCycle begin if HaveAArch64() then AArch64_PMUCycle(); return; end;

if !IsFeatureImplemented(FEAT_PMUv3) then    return;end;if (( &amp;&amp; ) || (!IsFeatureImplemented(FEAT_PMUv3p9) &amp;&amp;                                    ImpDefBool("PMU counts cycles in WFI or WFE state"))) then    PMUEvent(PMU_EVENT_CPU_CYCLES);end;let counters : integer = NUM_PMU_COUNTERS;var Vm : integer = 0;if counters != 0 then    for idx = 0 to counters - 1 do        if CountPMUEvents(idx) then            let accumulated : integer = PMUEventAccumulator[[idx]];            if (idx MOD 2) == 0 then Vm = 0; end;            Vm = AArch32_IncrementEventCounter(idx, accumulated, Vm);        end;        PMUEventAccumulator[[idx]] = 0;    end;end;AArch32_IncrementCycleCounter();CheckForPMUOverflow();

end;

Library pseudocode for aarch32/debug/takeexceptiondbg/AArch32_EnterHypModeInDebugState

// AArch32_EnterHypModeInDebugState
// ==================================
// Take an exception in Debug state to Hyp mode.

noreturn func AArch32_EnterHypModeInDebugState(except : ExceptionRecord) begin SynchronizeContext(); assert HaveEL(EL2) && CurrentSecurityState() == SS_NonSecure && ELUsingAArch32(EL2);

AArch32_ReportHypEntry(except);AArch32_WriteMode(M32_Hyp);SPSR_curr() = ARBITRARY : bits(32);ELR_hyp()   = ARBITRARY : bits(32);// In Debug state, the PE always execute T32 instructions when in AArch32 state, and// PSTATE.[SS,A,I,F] are not observable so behave as UNKNOWN.PSTATE.T = '1';                             // PSTATE.J is RES0PSTATE.[SS,A,I,F] = ARBITRARY : bits(4);DLR()   = ARBITRARY : bits(32);DSPSR() = ARBITRARY : bits(32);if IsFeatureImplemented(FEAT_Debugv8p9) then    DSPSR2() = ARBITRARY : bits(32);end;PSTATE.E  = HSCTLR().EE;PSTATE.IL = '0';PSTATE.IT = '00000000';if IsFeatureImplemented(FEAT_SSBS) then PSTATE.SSBS = ARBITRARY : bit; end;EDSCR().ERR = '1';UpdateEDSCRFields();EndOfInstruction(EndOfInstructionReason_Exception);

end;

Library pseudocode for aarch32/debug/takeexceptiondbg/AArch32_EnterModeInDebugState

// AArch32_EnterModeInDebugState
// ===============================
// Take an exception in Debug state to a mode other than Monitor and Hyp mode.

noreturn func AArch32_EnterModeInDebugState(target_mode : bits(5)) begin SynchronizeContext(); assert ELUsingAArch32(EL1) && PSTATE.EL != EL2;

if PSTATE.M == M32_Monitor then SCR().NS = '0'; end;AArch32_WriteMode(target_mode);SPSR_curr() = ARBITRARY : bits(32);R(14)       = ARBITRARY : bits(32);// In Debug state, the PE always execute T32 instructions when in AArch32 state, and// PSTATE.[SS,A,I,F] are not observable so behave as UNKNOWN.PSTATE.T = '1';                             // PSTATE.J is RES0PSTATE.[SS,A,I,F] = ARBITRARY : bits(4);DLR() = ARBITRARY : bits(32);DSPSR() = ARBITRARY : bits(32);if IsFeatureImplemented(FEAT_Debugv8p9) then    DSPSR2() = ARBITRARY : bits(32);end;PSTATE.E  = SCTLR().EE;PSTATE.IL = '0';PSTATE.IT = '00000000';if IsFeatureImplemented(FEAT_PAN) &amp;&amp; SCTLR().SPAN == '0' then PSTATE.PAN = '1'; end;if IsFeatureImplemented(FEAT_SSBS) then PSTATE.SSBS = ARBITRARY : bit; end;EDSCR().ERR = '1';UpdateEDSCRFields();                        // Update EDSCR PE state flags.EndOfInstruction(EndOfInstructionReason_Exception);

end;

Library pseudocode for aarch32/debug/takeexceptiondbg/AArch32_EnterMonitorModeInDebugState

// AArch32_EnterMonitorModeInDebugState
// ======================================
// Take an exception in Debug state to Monitor mode.

func AArch32_EnterMonitorModeInDebugState begin SynchronizeContext(); assert HaveEL(EL3) && ELUsingAArch32(EL3); let from_secure : boolean = CurrentSecurityState() == SS_Secure; if PSTATE.M == M32_Monitor then SCR().NS = '0'; end; AArch32_WriteMode(M32_Monitor); SPSR_curr() = ARBITRARY : bits(32); R(14) = ARBITRARY : bits(32); // In Debug state, the PE always execute T32 instructions when in AArch32 state, and // PSTATE.[SS,A,I,F] are not observable so behave as UNKNOWN. PSTATE.T = '1'; // PSTATE.J is RES0 PSTATE.[SS,A,I,F] = ARBITRARY : bits(4); PSTATE.E = SCTLR().EE; PSTATE.IL = '0'; PSTATE.IT = '00000000'; if IsFeatureImplemented(FEAT_PAN) then if !from_secure then PSTATE.PAN = '0'; elsif SCTLR().SPAN == '0' then PSTATE.PAN = '1'; end; end; if IsFeatureImplemented(FEAT_SSBS) then PSTATE.SSBS = ARBITRARY : bit; end; DLR() = ARBITRARY : bits(32); DSPSR() = ARBITRARY : bits(32); if IsFeatureImplemented(FEAT_Debugv8p9) then DSPSR2() = ARBITRARY : bits(32); end; EDSCR().ERR = '1'; UpdateEDSCRFields(); // Update EDSCR PE state flags.

EndOfInstruction(EndOfInstructionReason_Exception);

end;

Library pseudocode for aarch32/debug/watchpoint/AArch32_WatchpointByteMatch

// AArch32_WatchpointByteMatch
// =============================

func AArch32_WatchpointByteMatch(n : integer, vaddress : bits(32)) => boolean begin let dbgtop : integer{} = 31; let cmpbottom : integer{} = if DBGWVR(n)[2] == '1' then 2 else 3; // Word or doubleword var bottom = cmpbottom; let select : integer{} = UInt(vaddress[cmpbottom-1:0]); var byte_select_match : boolean = (DBGWCR(n).BAS[select] != '0'); var mask : integer{} = UInt(DBGWCR(n).MASK);

// If DBGWCR(n).MASK is a nonzero value and DBGWCR(n).BAS is not set to '11111111', or// DBGWCR(n).BAS specifies a non-contiguous set of bytes behavior is CONSTRAINED// UNPREDICTABLE.if mask &gt; 0 &amp;&amp; !IsOnes(DBGWCR(n).BAS) then    byte_select_match = ConstrainUnpredictableBool(Unpredictable_WPMASKANDBAS);else    let LSB : bits(8) = (DBGWCR(n).BAS AND NOT(DBGWCR(n).BAS - 1));    let MSB : bits(8) = (DBGWCR(n).BAS + LSB);    if !IsZero(MSB AND (MSB - 1)) then          // Not contiguous        byte_select_match = ConstrainUnpredictableBool(Unpredictable_WPBASCONTIGUOUS);        bottom = 3;                             // For the whole doubleword    end;end;// If the address mask is set to a reserved value, the behavior is CONSTRAINED UNPREDICTABLE.if mask &gt; 0 &amp;&amp; mask &lt;= 2 then    var c : Constraint;    var unpred_mask : integer;    (c, unpred_mask) = ConstrainUnpredictableInteger(3, 31, Unpredictable_RESWPMASK);    assert c IN {Constraint_DISABLED, Constraint_NONE, Constraint_UNKNOWN};    case c of        when Constraint_DISABLED =&gt; return FALSE; // Disabled        when Constraint_NONE     =&gt; mask = 0;     // No masking        // Otherwise the value returned by ConstrainUnpredictableInteger is a not-reserved value        otherwise                =&gt; mask = unpred_mask as integer{3..31};    end;end;let cmpmsb : integer{}    = dbgtop;let cmplsb : integer{}    = if mask &gt; bottom then mask else bottom;let bottombit : integer{} = bottom;var WVR_match : boolean   = (vaddress[cmpmsb:cmplsb] == DBGWVR(n)[cmpmsb:cmplsb]);if mask &gt; bottom then    // If masked bits of DBGWVR(n) are not zero, the behavior is CONSTRAINED UNPREDICTABLE.    if WVR_match &amp;&amp; !IsZero(DBGWVR(n)[cmplsb-1:bottombit]) then        WVR_match = ConstrainUnpredictableBool(Unpredictable_WPMASKEDBITS);    end;end;return (WVR_match &amp;&amp; byte_select_match);

end;

Library pseudocode for aarch32/debug/watchpoint/AArch32_WatchpointMatch

// AArch32_WatchpointMatch
// =========================
// Watchpoint matching in an AArch32 translation regime.

func AArch32_WatchpointMatch(n : integer, vaddress : bits(32), size : integer, accdesc : AccessDescriptor) => WatchpointInfo begin assert ELUsingAArch32(S1TranslationRegime()); assert n < NumWatchpointsImplemented();

let enabled : boolean     = DBGWCR(n).E == '1';let linked : boolean      = DBGWCR(n).WT == '1';let isbreakpnt : boolean  = FALSE;let linked_n : integer{}  = UInt(DBGWCR_EL1(n).LBN);let state_match : boolean = AArch32_StateMatch(DBGWCR(n).SSC, DBGWCR(n).HMC, DBGWCR(n).PAC,                                               linked, linked_n, isbreakpnt, accdesc);var watchptinfo : WatchpointInfo;var ls_match : boolean;case DBGWCR(n).LSC[1:0] of    when '00' =&gt; ls_match = FALSE;    when '01' =&gt; ls_match = accdesc.read;    when '10' =&gt; ls_match = accdesc.write || accdesc.acctype == AccessType_DC;    when '11' =&gt; ls_match = TRUE;end;var value_match : boolean = FALSE;watchptinfo.vaddress = ZeroExtend{64}(vaddress);for byte = 0 to size - 1 do    if (!value_match &amp;&amp;          (watchptinfo.vaddress,                                          ZeroExtend{64}(vaddress + byte))) then        // Watchpoint should report an address which is in        // the naturally aligned block of the matched address.        watchptinfo.vaddress = ZeroExtend{64}(vaddress + byte);    end;    value_match = value_match || AArch32_WatchpointByteMatch(n, vaddress + byte);end;watchptinfo.watchpt_num = n;watchptinfo.value_match = value_match &amp;&amp; state_match &amp;&amp; ls_match &amp;&amp; enabled;return watchptinfo;

end;

Library pseudocode for aarch32/exceptions/aborts/AArch32_Abort

// AArch32_Abort
// ===============
// Abort and Debug exception handling in an AArch32 translation regime.

func AArch32_Abort(fault : FaultRecord) begin // Check if routed to AArch64 state var route_to_aarch64 : boolean = ((IsExternalAbort(fault) && (SyncExternalAbortTarget(fault))) || (PSTATE.EL == EL0 && (EL1)));

if !route_to_aarch64 &amp;&amp; EL2Enabled() &amp;&amp; (EL2) then    route_to_aarch64 = (HCR_EL2().TGE == '1' || IsSecondStage(fault) ||                        (IsDebugException(fault) &amp;&amp; MDCR_EL2().TDE == '1'));end;if route_to_aarch64 then    AArch64_Abort(fault);end;if fault.accessdesc.acctype == AccessType_IFETCH then    AArch32_TakePrefetchAbortException(fault);else    AArch32_TakeDataAbortException(fault);end;

end;

Library pseudocode for aarch32/exceptions/aborts/AArch32_AbortSyndrome

// AArch32_AbortSyndrome
// =======================
// Creates an exception syndrome record for Abort exceptions
// taken to Hyp mode
// from an AArch32 translation regime.
func AArch32_AbortSyndrome(exceptype : Exception, fault : FaultRecord,
                           target_el : bits(2)) => ExceptionRecord
begin
    var except : ExceptionRecord = ExceptionSyndrome(exceptype);
except.syndrome.iss = AArch32_FaultSyndrome(exceptype, fault);if exceptype == Exception_Watchpoint then    except.vaddress = fault.watchptinfo.vaddress;else    except.vaddress = ZeroExtend{64}(fault.vaddress);end;if IPAValid(fault) then    except.ipavalid  = TRUE;    except.NS        = if fault.ipaddress.paspace == PAS_NonSecure then '1' else '0';    except.ipaddress = ZeroExtend{NUM_PABITS}(fault.ipaddress.address);else    except.ipavalid = FALSE;end;return except;

end;

Library pseudocode for aarch32/exceptions/aborts/AArch32_CheckPCAlignment

// AArch32_CheckPCAlignment
// ==========================

func AArch32_CheckPCAlignment begin let pc : bits(32) = ThisInstrAddr{}();

if (CurrentInstrSet() == InstrSet_A32 &amp;&amp; pc[1] == '1') || pc[0] == '1' then    if AArch32_GeneralExceptionsToAArch64() then AArch64_PCAlignmentFault(); end;    let accdesc : AccessDescriptor = CreateAccDescIFetch();    var fault : FaultRecord = NoFault(accdesc, ZeroExtend{64}(pc));    // Generate an Alignment fault Prefetch Abort exception    fault.statuscode = Fault_Alignment;    AArch32_Abort(fault);end;

end;

Library pseudocode for aarch32/exceptions/aborts/AArch32_CommonFaultStatus

// AArch32_CommonFaultStatus
// ===========================
// Return the common part of the fault status on reporting a Data
// or Prefetch Abort.

func AArch32_CommonFaultStatus(fault : FaultRecord, long_format : boolean) => bits(32) begin var target : bits(32) = Zeros{}; if IsFeatureImplemented(FEAT_RAS) && IsAsyncAbort(fault) then let errstate : ErrorState = PEErrorState(fault); target[15:14] = AArch32_EncodeAsyncErrorSyndrome(errstate); // AET end; if IsExternalAbort(fault) then target[12] = fault.extflag; end; // ExT target[9] = if long_format then '1' else '0'; // LPAE if long_format then // Long-descriptor format target[5:0] = EncodeLDFSC(fault.statuscode, fault.level); // STATUS else // Short-descriptor format target[10,3:0] = EncodeSDFSC(fault.statuscode, fault.level); // FS end; return target; end;

Library pseudocode for aarch32/exceptions/aborts/AArch32_ReportDataAbort

// AArch32_ReportDataAbort
// =========================
// Report syndrome information for aborts taken to modes other than Hyp mode.

func AArch32_ReportDataAbort(route_to_monitor : boolean, fault : FaultRecord) begin var long_format : boolean; if route_to_monitor && CurrentSecurityState() != SS_Secure then long_format = ((TTBCR_S().EAE == '1') || (IsExternalSyncAbort(fault) && ((PSTATE.EL == EL2 || TTBCR().EAE == '1') || (fault.secondstage && ImpDefBool( "Report abort using Long-descriptor format"))))); else long_format = TTBCR().EAE == '1'; end; var syndrome : bits(32) = AArch32_CommonFaultStatus(fault, long_format);

// bits of syndrome that are not common to I and D sideif fault.accessdesc.acctype IN {AccessType_DC, AccessType_IC, AccessType_AT} then    syndrome[13] = '1';                              // CM    syndrome[11] = '1';                              // WnRelse    syndrome[11] = if fault.write then '1' else '0'; // WnRend;if !long_format then    syndrome[7:4] = fault.domain;                    // Domainend;if fault.accessdesc.acctype == AccessType_IC then    var i_syndrome : bits(32);    if (!long_format &amp;&amp;        ImpDefBool("Report I-cache maintenance fault in IFSR")) then        i_syndrome = syndrome;        syndrome[10,3:0] = EncodeSDFSC(Fault_ICacheMaint, 1);    else        i_syndrome = ARBITRARY : bits(32);    end;    if route_to_monitor then        IFSR_S() = i_syndrome;    else        IFSR() = i_syndrome;    end;end;if route_to_monitor then    DFSR_S() = syndrome;    DFAR_S() = fault.vaddress[31:0];else    DFSR()   = syndrome;    DFAR()   = fault.vaddress[31:0];end;

end;

Library pseudocode for aarch32/exceptions/aborts/AArch32_ReportPrefetchAbort

// AArch32_ReportPrefetchAbort
// =============================
// Report syndrome information for aborts taken to modes other than Hyp mode.

func AArch32_ReportPrefetchAbort(route_to_monitor : boolean, fault : FaultRecord) begin // The encoding used in the IFSR can be Long-descriptor format or Short-descriptor format. // Normally, the current translation table format determines the format. For an abort from // Non-secure state to Monitor mode, the IFSR uses the Long-descriptor format if any of the // following applies: // * The Secure TTBCR.EAE is set to 1. // * It is taken from Hyp mode. // * It is taken from EL1 or EL0, and the Non-secure TTBCR.EAE is set to 1. var long_format : boolean = FALSE; if route_to_monitor && CurrentSecurityState() != SS_Secure then long_format = TTBCR_S().EAE == '1' || PSTATE.EL == EL2 || TTBCR().EAE == '1'; else long_format = TTBCR().EAE == '1'; end;

let fsr : bits(32) = AArch32_CommonFaultStatus(fault, long_format);if route_to_monitor then    IFSR_S() = fsr;    IFAR_S() = fault.vaddress[31:0];else    IFSR() = fsr;    IFAR() = fault.vaddress[31:0];end;return;

end;

Library pseudocode for aarch32/exceptions/aborts/AArch32_TakeDataAbortException

// AArch32_TakeDataAbortException
// ================================

func AArch32_TakeDataAbortException(fault : FaultRecord) begin

var sea_target : bits(2);if IsExternalAbort(fault) then    sea_target = SyncExternalAbortTarget(fault);else    sea_target = ARBITRARY : bits(2);end;let route_to_monitor : boolean = IsExternalAbort(fault) &amp;&amp; sea_target == EL3;let route_to_hyp : boolean     = (EL2Enabled() &amp;&amp; PSTATE.EL IN {EL0, EL1} &amp;&amp;                                  (HCR().TGE == '1' ||                                  (IsExternalAbort(fault) &amp;&amp; sea_target == EL2) ||                                  (IsDebugException(fault) &amp;&amp; HDCR().TDE == '1') ||                                   IsSecondStage(fault)));let preferred_exception_return : bits(32) = ThisInstrAddr{}();let vect_offset : integer = 0x10;let lr_offset : integer = 8;if IsDebugException(fault) then DBGDSCRext().MOE = fault.debugmoe; end;if route_to_monitor then    AArch32_ReportDataAbort(route_to_monitor, fault);    AArch32_EnterMonitorMode(preferred_exception_return, lr_offset, vect_offset);elsif PSTATE.EL == EL2 || route_to_hyp then    let except : ExceptionRecord = AArch32_AbortSyndrome(Exception_DataAbort, fault, EL2);    if PSTATE.EL == EL2 then        AArch32_EnterHypMode(except, preferred_exception_return, vect_offset);    else        AArch32_EnterHypMode(except, preferred_exception_return, 0x14);    end;else    AArch32_ReportDataAbort(route_to_monitor, fault);    AArch32_EnterMode(M32_Abort, preferred_exception_return, lr_offset, vect_offset);end;

end;

Library pseudocode for aarch32/exceptions/aborts/AArch32_TakePrefetchAbortException

// AArch32_TakePrefetchAbortException
// ====================================

func AArch32_TakePrefetchAbortException(fault : FaultRecord) begin

var sea_target : bits(2);if IsExternalAbort(fault) then    sea_target = SyncExternalAbortTarget(fault);else    sea_target = ARBITRARY : bits(2);end;let route_to_monitor : boolean = IsExternalAbort(fault) &amp;&amp; sea_target == EL3;let route_to_hyp : boolean = (EL2Enabled() &amp;&amp; PSTATE.EL IN {EL0, EL1} &amp;&amp;                              (HCR().TGE == '1' ||                              (IsExternalAbort(fault) &amp;&amp; sea_target == EL2) ||                              (IsDebugException(fault) &amp;&amp; HDCR().TDE == '1') ||                               IsSecondStage(fault)));var except : ExceptionRecord;let preferred_exception_return : bits(32) = ThisInstrAddr{}();let vect_offset : integer = 0x0C;let lr_offset : integer = 4;if IsDebugException(fault) then DBGDSCRext().MOE = fault.debugmoe; end;if route_to_monitor then    AArch32_ReportPrefetchAbort(route_to_monitor, fault);    AArch32_EnterMonitorMode(preferred_exception_return, lr_offset, vect_offset);elsif PSTATE.EL == EL2 || route_to_hyp then    if fault.statuscode == Fault_Alignment then             // PC Alignment fault        except = ExceptionSyndrome(Exception_PCAlignment);        except.vaddress = ThisInstrAddr{64}();    else        except = AArch32_AbortSyndrome(Exception_InstructionAbort, fault, EL2);    end;    if PSTATE.EL == EL2 then        AArch32_EnterHypMode(except, preferred_exception_return, vect_offset);    else        AArch32_EnterHypMode(except, preferred_exception_return, 0x14);    end;else    AArch32_ReportPrefetchAbort(route_to_monitor, fault);    AArch32_EnterMode(M32_Abort, preferred_exception_return, lr_offset, vect_offset);end;

end;

Library pseudocode for aarch32/exceptions/async/AArch32_TakePhysicalFIQException

// AArch32_TakePhysicalFIQException
// ==================================

func AArch32_TakePhysicalFIQException begin

// Check if routed to AArch64 statevar route_to_aarch64 : boolean = PSTATE.EL == EL0 &amp;&amp; (EL1);if !route_to_aarch64 &amp;&amp; EL2Enabled() &amp;&amp; (EL2) then    route_to_aarch64 = HCR_EL2().TGE == '1' || (HCR_EL2().FMO == '1' &amp;&amp; ());end;if !route_to_aarch64 then    route_to_aarch64 = EffectiveSCR_EL3_FIQ() == '1';end;if route_to_aarch64 then AArch64_TakePhysicalFIQException(); end;let route_to_monitor : boolean = HaveEL(EL3) &amp;&amp; SCR().FIQ == '1';let route_to_hyp : boolean = (PSTATE.EL IN {EL0, EL1} &amp;&amp; EL2Enabled() &amp;&amp;                              (HCR().TGE == '1' || HCR().FMO == '1'));</code></pre>

Log in to reply.