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 35 of 36

Writeup Shared pseudocode: part 35 of 36

started by admin

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

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

        if (!IsFault(addrdesc.fault.statuscode) && IsFeatureImplemented(FEAT_RME) &&
              ()) then
            let gpcf : GPCFRecord = GranuleProtectionCheck(addrdesc, accdesc);
            if gpcf.gpf == GPCF_None then
                memstatus = PhysMemWrite{8}(addrdesc, accdesc, datum);
            else
                addrdesc.fault.gpcf       = gpcf;
                addrdesc.fault.statuscode = Fault_GPCFOnOutput;
            end;
        end;
        if !IsFault(addrdesc.fault.statuscode) then
            memstatus = PhysMemWrite{8}(addrdesc, accdesc, datum);
        end;
else    // The Trace Buffer Unit is using Self-hosted mode.    var owning_ss : SecurityState;    var owning_el : bits(2);    (owning_ss, owning_el) = TraceBufferOwner();    let accdesc : AccessDescriptor = CreateAccDescTRBE(owning_ss, owning_el);    let aligned : boolean = TRUE;    (memstatus, addrdesc) = DebugMemWrite(address, accdesc, aligned, datum);    ttw_abort = addrdesc.fault.statuscode IN {Fault_SyncExternalOnWalk,                                              Fault_SyncParityOnWalk};end;if IsFault(addrdesc.fault.statuscode) && (!ttw_abort || ttw_abort_as_fault) then    DebugWriteFault(address, addrdesc.fault);    TryAssertTRBIRQ();    return TRUE;elsif IsFault(memstatus) || (ttw_abort && !ttw_abort_as_fault) then    DebugWriteExternalAbort(memstatus, addrdesc, address);    TryAssertTRBIRQ();    return TRUE;end;// Check for Trigger Eventlet target_el : bits(2) = DefaultTRBEEvent();let triggered : boolean = TRBSR_EL(target_el).TRG == '1';if triggered && !IsZero(TRBTRG_EL1().TRG) then    TRBTRG_EL1().TRG = (TRBTRG_EL1().TRG - 1)[31:0];    if IsZero(TRBTRG_EL1().TRG) && TRBLIMITR_EL1().TM != '11' then        TraceUnitFlush();        TraceUnitFlushOnTriggerComplete();    end;end;// Increment the pointervar next_address : bits(64) = TRBPTR_EL1() + 1;if next_address[63:12] == TRBLIMITR_EL1().LIMIT then    next_address = TRBBASER_EL1().BASE::Zeros{12};    TRBSR_EL(target_el).WRAP = '1';    CTI_SignalEvent(CrossTriggerIn_TRBEWrap);    if TRBLIMITR_EL1().FM == '00' then     // Fill mode        let bsc : bits(6) = '000001'; // Buffer full event        OtherTRBEManagementEvent(bsc);    elsif TRBLIMITR_EL1().FM != '11' then  // Not Circular Buffer mode        if TRBSR_EL(target_el).IRQ == '0' then            TRBSR_EL(target_el).IRQ = '1';   // Assert interrupt or exception            CTI_SignalEvent(CrossTriggerIn_TRBEMgmt);        end;    end;end;TRBPTR_EL1() = next_address[63:0];TryAssertTRBIRQ();

end; return TRUE;

end;


## Library pseudocode for shared/trace/TraceBuffer/DefaultTRBEEvent

// DefaultTRBEEvent // ================== // Return the target ELx for an indirect write to TRBSR_ELx for an Other buffer management // event or anything other than a buffer management event.

func DefaultTRBEEvent() => bits(2) begin return ReportTRBEEvent(Zeros{6}, ARBITRARY : bits(6)); end;


## Library pseudocode for shared/trace/TraceBuffer/DetectedTraceTrigger

// DetectedTraceTrigger // ====================== // Called when the trace unit detects a trace trigger

func DetectedTraceTrigger begin if TraceBufferRunning() then let target_el : bits(2) = DefaultTRBEEvent(); if TRBSR_EL(target_el).TRG == '0' then TRBSR_EL(target_el).TRG = '1'; if IsZero(TRBTRG_EL1().TRG) && TRBLIMITR_EL1().TM != '11' then TraceUnitFlush(); TraceUnitFlushOnTriggerComplete(); end; end; end; end;


## Library pseudocode for shared/trace/TraceBuffer/EffectiveMDCR\_EL3\_NSTB

// EffectiveMDCR_EL3_NSTB // ======================== // Return the Effective value of MDCR_EL3().[NSTBE, NSTB] field and whether it is a reserved value.

readonly func EffectiveMDCR_EL3_NSTB() => (bits(3), boolean) begin var state_bits : bits(3); var reserved : boolean = FALSE;

if IsFeatureImplemented(FEAT_RME) then
    state_bits = MDCR_EL3().[NSTBE, NSTB];
    if state_bits == '10x' || (!IsFeatureImplemented(FEAT_Secure) && state_bits == '00x') then
        // Reserved value
        reserved = TRUE;
        (-, state_bits) = ConstrainUnpredictableBits{3}(Unpredictable_RESERVEDNSxB);
    end;
else
    state_bits = '0' :: MDCR_EL3().NSTB;
end;

return (state_bits, reserved);

end;


## Library pseudocode for shared/trace/TraceBuffer/EffectiveTRBLIMITR\_EL1\_nVM

// EffectiveTRBLIMITR_EL1_nVM // ============================

readonly func EffectiveTRBLIMITR_EL1_nVM() => bit begin if () then // If SelfHostedTraceEnabled() is FALSE, then this function is only called when // FEAT_TRBE_EXT is implemented. assert IsFeatureImplemented(FEAT_TRBE_EXT); return '1'; end; if IsFeatureImplemented(FEAT_TRBEv1p1) && HaveEL(EL2) then let (owning_ss, owning_el) = TraceBufferOwner(); if ((owning_ss != SS_Secure || IsSecureEL2Enabled()) && owning_el == EL1 && TRFCR_EL2().DnVM == '1') then return '0'; end; end; return TRBLIMITR_EL1().nVM; end;


## Library pseudocode for shared/trace/TraceBuffer/EffectiveTRFCR\_EL1\_EE

// EffectiveTRFCR_EL1_EE // ======================= // Return the Effective value of TRFCR_EL1.EE for the purpose of controlling the // TRBE Profiling exception.

func EffectiveTRFCR_EL1_EE() => bits(2) begin if EffectiveTRFCR_EL2_EE() == '00' then return '00'; end;

var ee : bits(2) = TRFCR_EL1().EE;
if ee IN {'01', '10'} then            // Reserved value
    if IsFeatureImplemented(FEAT_NV) then
        ee[0] = ee[1];
    else
        var c : Constraint;
        (c, ee) = ConstrainUnpredictableBits{2}(Unpredictable_RESTRFEE);
        assert c IN {Constraint_DISABLED, Constraint_UNKNOWN};
        if c == Constraint_DISABLED then
            ee = '00';
        end;
        // Otherwise the value returned by ConstrainUnpredictableBits must be
        // a non-reserved value
    end;
end;

return ee;

end;


## Library pseudocode for shared/trace/TraceBuffer/EffectiveTRFCR\_EL2\_EE

// EffectiveTRFCR_EL2_EE // ======================= // Return the Effective value of TRFCR_EL2.EE.

func EffectiveTRFCR_EL2_EE() => bits(2) begin if !IsFeatureImplemented(FEAT_TRBE_EXC) || () then return '00'; end;

if HaveEL(EL3) && MDCR_EL3().TRBEE == '00' then
    return '00';
end;

let check_el2 : boolean = HaveEL(EL2) && (EffectiveSCR_EL3_NS() == '1' || IsSecureEL2Enabled()); return if check_el2 then TRFCR_EL2().EE else '01';

end;


## Library pseudocode for shared/trace/TraceBuffer/ElementStreamSize

// ElementStreamSize // =================

config ElementStreamSize : integer{0..4096} = 4096;


## Library pseudocode for shared/trace/TraceBuffer/GetTRBSR\_EL1\_FSC

// GetTRBSR_EL1_FSC // ================== // Query the TRBSR_EL1.FSC field.

func GetTRBSR_EL1_FSC() => bits(6) begin var FSC : bits(6);

FSC = TRBSR_EL1()[5:0];return FSC;

end;


## Library pseudocode for shared/trace/TraceBuffer/GetTRBSR\_EL2\_FSC

// GetTRBSR_EL2_FSC // ================== // Query the TRBSR_EL2.FSC field.

func GetTRBSR_EL2_FSC() => bits(6) begin var FSC : bits(6);

FSC = TRBSR_EL2()[5:0];return FSC;

end;


## Library pseudocode for shared/trace/TraceBuffer/GetTRBSR\_EL3\_FSC

// GetTRBSR_EL3_FSC // ================== // Query the TRBSR_EL3.FSC field.

func GetTRBSR_EL3_FSC() => bits(6) begin var FSC : bits(6);

FSC = TRBSR_EL3()[5:0];return FSC;

end;


## Library pseudocode for shared/trace/TraceBuffer/HaveImpDefTraceOutput

// HaveImpDefTraceOutput // =======================

func HaveImpDefTraceOutput() => boolean begin return ImpDefBool("Has Enabled External Trace Port"); end;


## Library pseudocode for shared/trace/TraceBuffer/ImpDefTraceOutput

// ImpDefTraceOutput // ===================

func ImpDefTraceOutput(datum : bits(8)) => boolean begin // Send 'datum' to an IMPLEMENTATION DEFINED trace output port // return TRUE if the byte is sent return FALSE; end;


## Library pseudocode for shared/trace/TraceBuffer/OtherTRBEManagementEvent

// OtherTRBEManagementEvent // ========================== // Report an Other buffer management event, with the status code 'bsc'

func OtherTRBEManagementEvent(bsc : bits(6)) begin ReportTRBEManagementEvent('000000', bsc); end;


## Library pseudocode for shared/trace/TraceBuffer/ReportTRBEEvent

// ReportTRBEEvent // ================= // Return the target ELx for an indirect write to TRBSR_ELx. // When the indirect write is due to a buffer management event: // 'ec_bits' is the Event Class for the management event. // 'fsc_bits' is the Fault Status Code when this is a fault, ignored otherwise. // Otherwise, 'ec_bits' should be Zeros().

func ReportTRBEEvent(ec_bits : bits(6), fsc_bits : bits(6)) => bits(2) begin var target_el : bits(2); var route_to_el3 : boolean = FALSE; var route_to_el2 : boolean = FALSE;

if IsFeatureImplemented(FEAT_TRBE_EXC) && SelfHostedTraceEnabled() then
    if ec_bits == '011111' then                      // implementation defined fault
        return ImpDefBits{2}("target_el for TRBE ImpDef Fault");
    end;
let s1fault : boolean = (ec_bits == '100100');   // Stage 1 faultlet s2fault : boolean = (ec_bits == '100101');   // Stage 2 faultvar gpcfault, gpfault : boolean;if IsFeatureImplemented(FEAT_RME) then    // Granule Protection Check fault, other than GPF. That is, a GPT address size fault,    // GPT walk fault, or synchronous External abort on GPT fetch.    gpcfault = (ec_bits == '011110');    // Other Granule Protection Fault, reported as Stage 1 or Stage 2 fault.    gpfault  =  ((s1fault || s2fault) && fsc_bits IN {'10001x', '1001xx', '101000'});else    gpcfault = FALSE;    gpfault  = FALSE;end;let sync_ext_abort : boolean = ((s1fault || s2fault) &&                                   fsc_bits IN {'010000', '01001x', '0101xx', '011011'});var owning_ss : SecurityState;var owning_el : bits(2);(owning_ss, owning_el) = TraceBufferOwner();if HaveEL(EL3) && MDCR_EL3().TRBEE == '1x' then    route_to_el3 = (MDCR_EL3().TRBEE == '11' ||                    gpcfault || (gpfault && SCR_EL3().GPF == '1') ||                    (sync_ext_abort && EffectiveEA() == '1'));end;if EffectiveTRFCR_EL2_EE() == '1x' then    route_to_el2 = (TRFCR_EL2().EE == '11' || (s1fault && owning_el == EL2) || s2fault ||                    gpcfault || (gpfault && HCR_EL2().GPF == '1') ||                    (sync_ext_abort && EffectiveHCR_TEA() == '1'));end;

end;

if route_to_el3 then target_el = EL3; elsif route_to_el2 then target_el = EL2; else target_el = EL1; end;

return target_el;

end;


## Library pseudocode for shared/trace/TraceBuffer/ReportTRBEManagementEvent

// ReportTRBEManagementEvent // =========================== // Report a buffer management event with the event class 'ec' and status code 'bsc'

func ReportTRBEManagementEvent(ec : bits(6), bsc : bits(6)) begin let target_el : bits(2) = DefaultTRBEEvent(); if TRBSR_EL(target_el).S == '0' then TRBSR_EL(target_el).S = '1'; // Stop collection if TRBSR_EL(target_el).IRQ == '0' then TRBSR_EL(target_el).IRQ = '1'; // Assert interrupt or exception CTI_SignalEvent(CrossTriggerIn_TRBEMgmt); end; TRBSR_EL(target_el).EC = ec; TRBSR_EL(target_el).MSS = ZeroExtend{16}(bsc); TRBSR_EL(target_el).MSS2 = Zeros{24}; CTI_SignalEvent(CrossTriggerIn_TRBEStop); end; end;


## Library pseudocode for shared/trace/TraceBuffer/TRBEInternalBufferFull

// TRBEInternalBufferFull // ========================

func TRBEInternalBufferFull() => boolean begin // In the simple sequential model, the internal buffer never fills return FALSE; end;


## Library pseudocode for shared/trace/TraceBuffer/TRBEInterruptEnabled

// TRBEInterruptEnabled // ====================== // Return TRUE if the TRBE interrupt request (TRBIRQ) is enabled, FALSE otherwise.

func TRBEInterruptEnabled() => boolean begin return EffectiveTRFCR_EL1_EE() == '00'; end;


## Library pseudocode for shared/trace/TraceBuffer/TRBE\_TRBIDR\_P\_Read

// TRBE_TRBIDR_P_Read // ==================== // Called when TRBIDR_EL1 is read, returns the value of TRBIDR_EL1.P

func TRBE_TRBIDR_P_Read() => bit begin var owning_ss : SecurityState; var owning_el : bits(2); (owning_ss, owning_el) = TraceBufferOwner();

// Reads as one if the Trace Buffer is owned by a higher Exception// Level or another Security state.if (UInt(owning_el) > UInt(PSTATE.EL) ||      (PSTATE.EL != EL3 && owning_ss != CurrentSecurityState())) then    return '1';else    return '0';end;

end;


## Library pseudocode for shared/trace/TraceBuffer/TRBSR\_EL

// TRBSR_EL - accessor // ===================

accessor TRBSR_EL(el : bits(2)) <=> value : TRBSRType begin getter var r : bits(64); case el of when EL1 => r = TRBSR_EL1(); when EL2 => r = TRBSR_EL2(); when EL3 => r = TRBSR_EL3(); otherwise => unreachable; end; return r; end;

setter    let r : bits(64) = value;    case el of        when EL1 =>   TRBSR_EL1() = r;        when EL2 =>   TRBSR_EL2() = r;        when EL3 =>   TRBSR_EL3() = r;        otherwise =>  unreachable;    end;    return;end;

end;


## Library pseudocode for shared/trace/TraceBuffer/TraceBufferEnabled

// TraceBufferEnabled // ====================

readonly func TraceBufferEnabled() => boolean begin if !IsFeatureImplemented(FEAT_TRBE) then return FALSE; elsif SelfHostedTraceEnabled() then if TRBLIMITR_EL1().E == '0' then return FALSE; end; var el : bits(2); (-, el) = TraceBufferOwner(); return (el); elsif IsFeatureImplemented(FEAT_TRBE_EXT) then return TRBLIMITR_EL1().XE == '1'; else return FALSE; end; end;


## Library pseudocode for shared/trace/TraceBuffer/TraceBufferOwner

// TraceBufferOwner // ================== // Return the owning Security state and Exception level. Must only be called // when SelfHostedTraceEnabled() is TRUE.

readonly func TraceBufferOwner() => (SecurityState, bits(2)) begin assert IsFeatureImplemented(FEAT_TRBE);

var owning_ss : SecurityState;
var state_bits :  bits(3);
if HaveEL(EL3) then
    (state_bits, -) = EffectiveMDCR_EL3_NSTB();
else
    state_bits = if SecureOnlyImplementation() then '001' else '011';
end;

case state_bits of when '00x' => owning_ss = SS_Secure; when '01x' => owning_ss = SS_NonSecure; when '11x' => owning_ss = SS_Realm; end; var owning_el : bits(2); if HaveEL(EL2) && (owning_ss != SS_Secure || IsSecureEL2Enabled()) then owning_el = if MDCR_EL2().E2TB == '00' then EL2 else EL1; else owning_el = EL1; end; return (owning_ss, owning_el);

end;


## Library pseudocode for shared/trace/TraceBuffer/TraceBufferRunning

// TraceBufferRunning // ====================

func TraceBufferRunning() => boolean begin if () then return FALSE; end;

var stopped : boolean = TRBSR_EL1().S == '1';if IsFeatureImplemented(FEAT_TRBE_EXC) && SelfHostedTraceEnabled() then    if HaveEL(EL3) && MDCR_EL3().TRBEE == '1x' then        stopped = stopped || (TRBSR_EL3().S == '1');    end;    if EffectiveTRFCR_EL2_EE() == '1x' then        stopped = stopped || (TRBSR_EL2().S == '1');    end;end;return !stopped;

end;


## Library pseudocode for shared/trace/TraceBuffer/TraceUnitFlushOnTriggerComplete

// TraceUnitFlushOnTriggerComplete // ================================= // Called when a trace unit flush completes following a call to // TraceUnitFlush() due to a trace trigger.

func TraceUnitFlushOnTriggerComplete begin if TRBLIMITR_EL1().TM == '00' then // Stop on trigger let bsc : bits(6) = '000010'; // Trigger event OtherTRBEManagementEvent(bsc); elsif TRBLIMITR_EL1().TM != '11' then // Not Ignore trigger let target_el : bits(2) = DefaultTRBEEvent(); TRBSR_EL(target_el).IRQ = '1'; // Assert interrupt or exception end; end;


## Library pseudocode for shared/trace/TraceBuffer/TryAssertTRBIRQ

// TryAssertTRBIRQ // ================= // Assert TRBIRQ pin when appropriate.

func TryAssertTRBIRQ begin if TRBEInterruptEnabled() && TRBSR_EL1().IRQ == '1' then SetInterruptRequestLevel(InterruptID_TRBIRQ, HIGH); else SetInterruptRequestLevel(InterruptID_TRBIRQ, LOW); end; return; end;


## Library pseudocode for shared/trace/TraceInstrumentationAllowed/TraceInstrumentationAllowed

// TraceInstrumentationAllowed // ============================= // Returns TRUE if Instrumentation Trace is allowed // in the given Exception level and Security state.

func TraceInstrumentationAllowed(ss : SecurityState, el : bits(2)) => boolean begin if !IsFeatureImplemented(FEAT_ITE) then return FALSE; end; if ELUsingAArch32(el) then return FALSE; end;

if TraceAllowed(el) then
    var ite_bit : bit;
    case el of
        when EL3 => ite_bit = '0';
        when EL2 => ite_bit = TRCITECR_EL2().E2E;
        when EL1 => ite_bit = TRCITECR_EL1().E1E;
        when EL0 =>
            if EffectiveTGE() == '1' then
                ite_bit = TRCITECR_EL2().E0HE;
            else
                ite_bit = TRCITECR_EL1().E0E;
            end;
    end;
if SelfHostedTraceEnabled() then    return ite_bit == '1';else    var el_bit : bit;    var ss_bit : bit;    case el of        when EL0 =&gt; el_bit = TRCITEEDCR().E0;        when EL1 =&gt; el_bit = TRCITEEDCR().E1;        when EL2 =&gt; el_bit = TRCITEEDCR().E2;        when EL3 =&gt; el_bit = TRCITEEDCR().E3;    end;    case ss of        when SS_Realm =&gt;     ss_bit = TRCITEEDCR().RL;        when SS_Secure =&gt;    ss_bit = TRCITEEDCR().S;        when SS_NonSecure =&gt; ss_bit = TRCITEEDCR().NS;        otherwise =&gt; ss_bit = '1';    end;    let ed_allowed : boolean = ss_bit == '1' &amp;&amp; el_bit == '1';    if TRCCONFIGR().ITO == '1' then        return ed_allowed;    else        return ed_allowed &amp;&amp; ite_bit == '1';    end;end;

else return FALSE; end;

end;


## Library pseudocode for shared/trace/TraceProcessElements/TraceUnitFlush

// TraceUnitFlush // ================ // Called when a trace unit flush is requested, to output previous recorded trace.

impdef func TraceUnitFlush begin return; end;


## Library pseudocode for shared/trace/claim

var TRCClaimTags : bits(32);


## Library pseudocode for shared/trace/claim/Write\_TRCCLAIMCLR

// Write_TRCCLAIMCLR // =================== // System register write to TRCCLAIMCLR.

func Write_TRCCLAIMCLR(value_in : bits(64)) begin assert NUM_TRC_CLAIM_TAGS <= 32;

TRCClaimTags = TRCClaimTags AND NOT ZeroExtend{32}(value_in[0 +: NUM_TRC_CLAIM_TAGS]);

end;


## Library pseudocode for shared/trace/claim/Write\_TRCCLAIMSET

// Write_TRCCLAIMSET // =================== // System register write to TRCCLAIMSET.

func Write_TRCCLAIMSET(value_in : bits(64)) begin assert NUM_TRC_CLAIM_TAGS <= 32;

TRCClaimTags = TRCClaimTags OR ZeroExtend{32}(value_in[0 +: NUM_TRC_CLAIM_TAGS]);

end;


## Library pseudocode for shared/trace/selfhosted/CheckTSBTrap

// CheckTSBTrap // ============== // Checks whether TSB should trap to EL2.

func CheckTSBTrap begin if (IsFeatureImplemented(FEAT_FGT2) && IsFeatureImplemented(FEAT_TRBEv1p1) && PSTATE.EL IN {EL0, EL1} && EL2Enabled() && () && ((EL3) || SCR_EL3().FGTEn2 == '1') && HFGITR2_EL2().TSBCSYNC == '1') then let target_el : bits(2) = EL2; let iss : bits(25) = 0x4[24:0]; AArch64_OtherInstrTrap(target_el, iss); end; end;

func TraceSynchronizationBarrier begin if IsFeatureImplemented(FEAT_TRBE) && (PSTATE.EL) then TraceUnitFlush(); end; return; end;


## Library pseudocode for shared/trace/selfhosted/EffectiveE0HTRE

// EffectiveE0HTRE // ================= // Returns effective E0HTRE value

func EffectiveE0HTRE() => bit begin return if ELUsingAArch32(EL2) then HTRFCR().E0HTRE else TRFCR_EL2().E0HTRE; end;


## Library pseudocode for shared/trace/selfhosted/EffectiveE0TRE

// EffectiveE0TRE // ================ // Returns effective E0TRE value

func EffectiveE0TRE() => bit begin return if ELUsingAArch32(EL1) then TRFCR().E0TRE else TRFCR_EL1().E0TRE; end;


## Library pseudocode for shared/trace/selfhosted/EffectiveE1TRE

// EffectiveE1TRE // ================ // Returns effective E1TRE value

func EffectiveE1TRE() => bit begin return if UsingAArch32() then TRFCR().E1TRE else TRFCR_EL1().E1TRE; end;


## Library pseudocode for shared/trace/selfhosted/EffectiveE2TRE

// EffectiveE2TRE // ================ // Returns effective E2TRE value

func EffectiveE2TRE() => bit begin return if UsingAArch32() then HTRFCR().E2TRE else TRFCR_EL2().E2TRE; end;


## Library pseudocode for shared/trace/selfhosted/SelfHostedTraceEnabled

// SelfHostedTraceEnabled // ======================== // Returns TRUE if Self-hosted Trace is enabled.

readonly func SelfHostedTraceEnabled() => boolean begin var secure_trace_enable : bit = '0'; if !(HaveTraceExt() && IsFeatureImplemented(FEAT_TRF)) then return FALSE; end; if EDSCR().TFO == '0' then return TRUE; end; if IsFeatureImplemented(FEAT_RME) then secure_trace_enable = if IsFeatureImplemented(FEAT_SEL2) then MDCR_EL3().STE else '0'; return ((secure_trace_enable == '1' && ()) || (MDCR_EL3().RLTE == '1' && ())); end; if HaveEL(EL3) then secure_trace_enable = if ELUsingAArch32(EL3) then SDCR().STE else MDCR_EL3().STE; else secure_trace_enable = if SecureOnlyImplementation() then '1' else '0'; end;

if secure_trace_enable == '1' && () then
    return TRUE;
end;

return FALSE;

end;


## Library pseudocode for shared/trace/selfhosted/TraceAllowed

// TraceAllowed // ============== // Returns TRUE if Self-hosted Trace is allowed in the given Exception level.

func TraceAllowed(el : bits(2)) => boolean begin if () then return FALSE; end; // If in Debug state then tracing is not allowed if Halted() && () then return FALSE; end; if SelfHostedTraceEnabled() then var trace_allowed : boolean; let ss : SecurityState = SecurityStateAtEL(el); // Detect scenarios where tracing in this Security state is never allowed. case ss of when SS_NonSecure => trace_allowed = TRUE; when SS_Secure => var trace_bit : bit; if HaveEL(EL3) then trace_bit = if ELUsingAArch32(EL3) then SDCR().STE else MDCR_EL3().STE; else trace_bit = '1'; end; trace_allowed = trace_bit == '1'; when SS_Realm => trace_allowed = MDCR_EL3().RLTE == '1'; when SS_Root => trace_allowed = FALSE; end;

    // Tracing is prohibited if the trace buffer owning security state is not the
    // current Security state or the owning Exception level is a lower Exception level.
    if IsFeatureImplemented(FEAT_TRBE) && TraceBufferEnabled() then
        let (owning_ss, owning_el) = TraceBufferOwner();
        if (ss != owning_ss || UInt(owning_el) < UInt(el) ||
            (EffectiveTGE() == '1' && owning_el == EL1)) then
            trace_allowed = FALSE;
        end;
    end;
var TRE_bit : bit;case el of    when EL3 =&gt;  TRE_bit = if () then TRFCR().E1TRE else '0';    when EL2 =&gt;  TRE_bit = EffectiveE2TRE();    when EL1 =&gt;  TRE_bit = EffectiveE1TRE();    when EL0 =&gt;        if EffectiveTGE() == '1' then            TRE_bit = EffectiveE0HTRE();        else            TRE_bit = EffectiveE0TRE();        end;end;return trace_allowed &amp;&amp; TRE_bit == '1';

else return ExternalNoninvasiveDebugAllowed(el); end;

end;


## Library pseudocode for shared/trace/selfhosted/TraceContextIDR2

// TraceContextIDR2 // ==================

func TraceContextIDR2() => boolean begin if (PSTATE.EL)|| (EL2) then return FALSE; end; return (() || TRFCR_EL2().CX == '1'); end;


## Library pseudocode for shared/trace/selfhosted/TraceTimeStamp

// TraceTimeStamp // ================

func TraceTimeStamp() => TimeStamp begin if SelfHostedTraceEnabled() then if HaveEL(EL2) then var TS_el2 : bits(2) = TRFCR_EL2().TS; if !IsFeatureImplemented(FEAT_ECV) && TS_el2 == '10' then // Reserved value (-, TS_el2) = ConstrainUnpredictableBits{2}(Unpredictable_EL2TIMESTAMP); end;

        case TS_el2 of
            when '00' =>
                // Falls out to check TRFCR_EL1.TS
                pass;
            when '01' =>
                return TimeStamp_Virtual;
            when '10' =>
                // Otherwise ConstrainUnpredictableBits removes this case
                assert IsFeatureImplemented(FEAT_ECV);
                return TimeStamp_OffsetPhysical;
            when '11' =>
                return TimeStamp_Physical;
        end;
    end;
var TS_el1 : bits(2) = TRFCR_EL1().TS;if TS_el1 == '00' || (!IsFeatureImplemented(FEAT_ECV) &amp;&amp; TS_el1 == '10') then    // Reserved value    (-, TS_el1) = ConstrainUnpredictableBits{2}(Unpredictable_EL1TIMESTAMP);end;case TS_el1 of    when '01' =&gt;        return TimeStamp_Virtual;    when '10' =&gt;        assert IsFeatureImplemented(FEAT_ECV);        return TimeStamp_OffsetPhysical;    when '11' =&gt;        return TimeStamp_Physical;    otherwise =&gt;        unreachable;         // ConstrainUnpredictableBits removes this caseend;

else return TimeStamp_CoreSight; end;

end;


## Library pseudocode for shared/trace/system/HaveTraceExt

// HaveTraceExt // ============== // Returns TRUE if Trace functionality as described by the Trace Architecture // is implemented.

readonly func HaveTraceExt() => boolean begin return IsFeatureImplemented(FEAT_ETE) || IsFeatureImplemented(FEAT_ETMv4); end;


## Library pseudocode for shared/trace/system/IsTraceCorePowered

// IsTraceCorePowered // ==================== // Returns TRUE if the trace unit Core power domain is powered up

impdef func IsTraceCorePowered() => boolean begin return TRUE; end;


## Library pseudocode for shared/translation/at

type TranslationStage of enumeration { TranslationStage_1, TranslationStage_12 };

type ATAccess of enumeration { ATAccess_Read, ATAccess_Write, ATAccess_Any, ATAccess_ReadPAN, ATAccess_WritePAN };


## Library pseudocode for shared/translation/at/EncodePARAttrs

// EncodePARAttrs // ================ // Convert orthogonal attributes and hints to 64-bit PAR ATTR field.

func EncodePARAttrs(memattrs : MemoryAttributes) => bits(8) begin var result : bits(8);

if IsFeatureImplemented(FEAT_MTE) && memattrs.tags == MemTag_AllocationTagged then
    if IsFeatureImplemented(FEAT_MTE_PERM) && memattrs.notagaccess then
        result[7:0] = '11100000';
    else
        result[7:0] = '11110000';
    end;
    return result;
end;

if memattrs.memtype == MemType_Device then result[7:4] = '0000'; case memattrs.device of when DeviceType_nGnRnE => result[3:0] = '0000'; when DeviceType_nGnRE => result[3:0] = '0100'; when DeviceType_nGRE => result[3:0] = '1000'; when DeviceType_GRE => result[3:0] = '1100'; otherwise => unreachable; end; result[0] = NOT memattrs.xs; else if memattrs.xs == '0' then if (memattrs.outer.attrs == MemAttr_WT && memattrs.inner.attrs == MemAttr_WT && !memattrs.outer.transient && memattrs.outer.hints == MemHint_RA) then return '10100000'; elsif memattrs.outer.attrs == MemAttr_NC && memattrs.inner.attrs == MemAttr_NC then return '01000000'; end; end;

if memattrs.outer.attrs == MemAttr_WT then    result[7:6] = if memattrs.outer.transient then '00' else '10';    result[5:4] = memattrs.outer.hints;elsif memattrs.outer.attrs == MemAttr_WB then    result[7:6] = if memattrs.outer.transient then '01' else '11';    result[5:4] = memattrs.outer.hints;else // MemAttr_NC    result[7:4] = '0100';end;if memattrs.inner.attrs == MemAttr_WT then    result[3:2] = if memattrs.inner.transient then '00' else '10';    result[1:0] = memattrs.inner.hints;elsif memattrs.inner.attrs == MemAttr_WB then    result[3:2] = if memattrs.inner.transient then '01' else '11';    result[1:0] = memattrs.inner.hints;else // MemAttr_NC    result[3:0] = '0100';end;

end;

return result;

end;


## Library pseudocode for shared/translation/at/PAREncodeShareability

// PAREncodeShareability // ======================= // Derive 64-bit PAR SH field.

func PAREncodeShareability(memattrs : MemoryAttributes) => bits(2) begin if (memattrs.memtype == MemType_Device || (memattrs.inner.attrs == MemAttr_NC && memattrs.outer.attrs == MemAttr_NC)) then // Force Outer-Shareable on Device and Normal Non-Cacheable memory return '10'; end;

case memattrs.shareability of    when Shareability_NSH => return '00';    when Shareability_ISH => return '11';    when Shareability_OSH => return '10';end;

end;


## Library pseudocode for shared/translation/at/ReportedPARAttrs

// ReportedPARAttrs // ================== // 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 ReportedPARAttrs(parattrs : bits(8)) => bits(8) begin return parattrs; end;


## Library pseudocode for shared/translation/at/ReportedPARShareability

// ReportedPARShareability // ========================= // The value returned in SH 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 ReportedPARShareability(sh : bits(2)) => bits(2) begin return sh; end;


## Library pseudocode for shared/translation/attrs/DecodeDevice

// DecodeDevice // ============== // Decode output Device type

readonly func DecodeDevice(device : bits(2)) => DeviceType begin case device of when '00' => return DeviceType_nGnRnE; when '01' => return DeviceType_nGnRE; when '10' => return DeviceType_nGRE; when '11' => return DeviceType_GRE; end; end;


## Library pseudocode for shared/translation/attrs/DecodeLDFAttr

// DecodeLDFAttr // =============== // Decode memory attributes using LDF (Long Descriptor Format) mapping

readonly func DecodeLDFAttr(attr : bits(4)) => MemAttrHints begin var ldfattr : MemAttrHints;

if    attr == 'x0xx' then ldfattr.attrs = MemAttr_WT; // Write-through
elsif attr == '0100' then ldfattr.attrs = MemAttr_NC; // Non-cacheable
elsif attr == 'x1xx' then ldfattr.attrs = MemAttr_WB; // Write-back
else                      unreachable;
end;

// Allocation hints are applicable only to cacheable memory. if ldfattr.attrs != MemAttr_NC then case attr[1:0] of when '00' => ldfattr.hints = MemHint_No; // No allocation hints when '01' => ldfattr.hints = MemHint_WA; // Write-allocate when '10' => ldfattr.hints = MemHint_RA; // Read-allocate when '11' => ldfattr.hints = MemHint_RWA; // Read/Write allocate end; end;

// The Transient hint applies only to cacheable memory with some allocation hints. if ldfattr.attrs != MemAttr_NC && ldfattr.hints != MemHint_No then ldfattr.transient = attr[3] == '0'; end;

return ldfattr;

end;


## Library pseudocode for shared/translation/attrs/DecodeSDFAttr

// DecodeSDFAttr // =============== // Decode memory attributes using SDF (Short Descriptor Format) mapping

func DecodeSDFAttr(rgn : bits(2)) => MemAttrHints begin var sdfattr : MemAttrHints;

case rgn of
    when '00' =>                   // Non-cacheable (no allocate)
        sdfattr.attrs = MemAttr_NC;
    when '01' =>                   // Write-back, Read and Write allocate
        sdfattr.attrs = MemAttr_WB;
        sdfattr.hints = MemHint_RWA;
    when '10' =>                   // Write-through, Read allocate
        sdfattr.attrs = MemAttr_WT;
        sdfattr.hints = MemHint_RA;
    when '11' =>                   // Write-back, Read allocate
        sdfattr.attrs = MemAttr_WB;
        sdfattr.hints = MemHint_RA;
end;

sdfattr.transient = FALSE;

return sdfattr;

end;


## Library pseudocode for shared/translation/attrs/DecodeShareability

// DecodeShareability // ==================== // Decode shareability of target memory region

readonly func DecodeShareability(sh : bits(2)) => Shareability begin case sh of when '10' => return Shareability_OSH; when '11' => return Shareability_ISH; when '00' => return Shareability_NSH; otherwise => case ConstrainUnpredictable(Unpredictable_Shareability) of when Constraint_OSH => return Shareability_OSH; when Constraint_ISH => return Shareability_ISH; when Constraint_NSH => return Shareability_NSH; end; end; end;


## Library pseudocode for shared/translation/attrs/EffectiveShareability

// EffectiveShareability // ======================= // Force Outer Shareability on Device and Normal iNCoNC memory

func EffectiveShareability(memattrs : MemoryAttributes) => Shareability begin if (memattrs.memtype == MemType_Device || (memattrs.inner.attrs == MemAttr_NC && memattrs.outer.attrs == MemAttr_NC)) then return Shareability_OSH; else return memattrs.shareability; end; end;


## Library pseudocode for shared/translation/attrs/IsTaggableMemAttr

// IsTaggableMemAttr // =================== // Determine whether the current memory attributes support MTE

pure func IsTaggableMemAttr(attrs : MemoryAttributes) => boolean begin return ((attrs.memtype == MemType_Normal) && (attrs.inner.attrs == MemAttr_WB) && (attrs.inner.hints == MemHint_RWA) && (!attrs.inner.transient) && (attrs.outer.attrs == MemAttr_WB) && (attrs.outer.hints == MemHint_RWA) && (!attrs.outer.transient)); end;


## Library pseudocode for shared/translation/attrs/IsWBShareable

// IsWBShareable // =============== // Determines whether the given memory attributes are iWBoWB Shareable

func IsWBShareable(memattrs : MemoryAttributes) => boolean begin

return (memattrs.memtype == MemType_Normal &&        memattrs.inner.attrs == MemAttr_WB &&        memattrs.outer.attrs == MemAttr_WB &&        memattrs.shareability IN {Shareability_ISH, Shareability_OSH});

end;


## Library pseudocode for shared/translation/attrs/NormalNCMemAttr

// NormalNCMemAttr // ================= // Normal Non-cacheable memory attributes

func NormalNCMemAttr() => MemoryAttributes begin var non_cacheable : MemAttrHints; non_cacheable.attrs = MemAttr_NC;

var nc_memattrs : MemoryAttributes;
nc_memattrs.memtype      = MemType_Normal;
nc_memattrs.outer        = non_cacheable;
nc_memattrs.inner        = non_cacheable;
nc_memattrs.shareability = Shareability_OSH;
nc_memattrs.tags         = MemTag_Untagged;
nc_memattrs.notagaccess  = FALSE;

return nc_memattrs;

end;


## Library pseudocode for shared/translation/attrs/S1ConstrainUnpredictableRESMAIR

// S1ConstrainUnpredictableRESMAIR // ================================= // Determine whether a reserved value occupies MAIR_ELx.AttrN

readonly func S1ConstrainUnpredictableRESMAIR(attr : bits(8), s1aarch64 : boolean) => boolean begin case attr of when '0000xx01' => return !(s1aarch64 && IsFeatureImplemented(FEAT_XS)); when '0000xxxx' => return attr[1:0] != '00'; when '01000000' => return !(s1aarch64 && IsFeatureImplemented(FEAT_XS)); when '10100000' => return !(s1aarch64 && IsFeatureImplemented(FEAT_XS)); when '11110000' => return !(s1aarch64 && IsFeatureImplemented(FEAT_MTE2)); when 'xxxx0000' => return TRUE; otherwise => return FALSE; end; end;


## Library pseudocode for shared/translation/attrs/S1DecodeMemAttrs

// S1DecodeMemAttrs // ================== // Decode MAIR-format memory attributes assigned in stage 1

readonly func S1DecodeMemAttrs(attr_in : bits(8), sh : bits(2), s1aarch64 : boolean) => MemoryAttributes begin var attr : bits(8) = attr_in; if S1ConstrainUnpredictableRESMAIR(attr, s1aarch64) then // Map reserved encodings to an allocated encoding (-, attr) = ConstrainUnpredictableBits{8}(Unpredictable_RESMAIR); end;

var memattrs : MemoryAttributes;
case attr of
    when '0000xxxx' => // Device memory
        memattrs.memtype = MemType_Device;
        memattrs.device  = DecodeDevice(attr[3:2]);
        memattrs.xs      = if s1aarch64 then NOT attr[0] else '1';
    when '01000000' =>
        assert s1aarch64 && IsFeatureImplemented(FEAT_XS);
        memattrs.memtype = MemType_Normal;
        memattrs.outer.attrs = MemAttr_NC;
        memattrs.inner.attrs = MemAttr_NC;
        memattrs.xs          = '0';
    when '10100000' =>
        assert s1aarch64 && IsFeatureImplemented(FEAT_XS);
        memattrs.memtype = MemType_Normal;
        memattrs.outer.attrs     = MemAttr_WT;
        memattrs.outer.hints     = MemHint_RA;
        memattrs.outer.transient = FALSE;
        memattrs.inner.attrs     = MemAttr_WT;
        memattrs.inner.hints     = MemHint_RA;
        memattrs.inner.transient = FALSE;
        memattrs.xs              = '0';
    when '11110000' => // Tagged memory
        assert s1aarch64 && IsFeatureImplemented(FEAT_MTE2);
        memattrs.memtype = MemType_Normal;
        memattrs.outer.attrs     = MemAttr_WB;
        memattrs.outer.hints     = MemHint_RWA;
        memattrs.outer.transient = FALSE;
        memattrs.inner.attrs     = MemAttr_WB;
        memattrs.inner.hints     = MemHint_RWA;
        memattrs.inner.transient = FALSE;
        memattrs.xs              = '0';
    otherwise =>
        memattrs.memtype = MemType_Normal;
        memattrs.outer   = DecodeLDFAttr(attr[7:4]);
        memattrs.inner   = DecodeLDFAttr(attr[3:0]);
    if (memattrs.inner.attrs == MemAttr_WB &amp;&amp;            memattrs.outer.attrs == MemAttr_WB) then        memattrs.xs = '0';    else        memattrs.xs = '1';    end;

end;

memattrs.shareability = DecodeShareability(sh); memattrs.tags = MemTag_Untagged; memattrs.notagaccess = FALSE;

return memattrs;

end;

// S1DecodeMemAttrs // ================== // Decode MAIR-format memory attributes assigned in stage 1

readonly func S1DecodeMemAttrs(attr_in : bits(8), sh : bits(2), s1aarch64 : boolean, walkparams : S1TTWParams, acctype : AccessType) => MemoryAttributes begin var memattrs : MemoryAttributes = S1DecodeMemAttrs(attr_in, sh, s1aarch64); if s1aarch64 && attr_in == '11110000' then memattrs.tags = MemTag_AllocationTagged; elsif IsFeatureImplemented(FEAT_MTE_CANONICAL_TAGS) && s1aarch64 && walkparams.mtx == '1' then memattrs.tags = MemTag_CanonicallyTagged; end;

return memattrs;

end;


## Library pseudocode for shared/translation/attrs/S2CombineS1AttrHints

// S2CombineS1AttrHints // ====================== // Determine resultant Normal memory cacheability and allocation hints from // combining stage 1 Normal memory attributes and stage 2 cacheability attributes.

func S2CombineS1AttrHints(s1_attrhints : MemAttrHints, s2_attrhints : MemAttrHints) => MemAttrHints begin var attrhints : MemAttrHints;

if s1_attrhints.attrs == MemAttr_NC || s2_attrhints.attrs == MemAttr_NC then
    attrhints.attrs = MemAttr_NC;
elsif s1_attrhints.attrs == MemAttr_WT || s2_attrhints.attrs == MemAttr_WT then
    attrhints.attrs = MemAttr_WT;
else
    attrhints.attrs = MemAttr_WB;
end;

// Stage 2 does not assign any allocation hints // Instead, they are inherited from stage 1 if attrhints.attrs != MemAttr_NC then attrhints.hints = s1_attrhints.hints; attrhints.transient = s1_attrhints.transient; end;

return attrhints;

end;


## Library pseudocode for shared/translation/attrs/S2CombineS1Device

// S2CombineS1Device // =================== // Determine resultant Device type from combining output memory attributes // in stage 1 and Device attributes in stage 2

func S2CombineS1Device(s1_device : DeviceType, s2_device : DeviceType) => DeviceType begin if s1_device == DeviceType_nGnRnE || s2_device == DeviceType_nGnRnE then return DeviceType_nGnRnE; elsif s1_device == DeviceType_nGnRE || s2_device == DeviceType_nGnRE then return DeviceType_nGnRE; elsif s1_device == DeviceType_nGRE || s2_device == DeviceType_nGRE then return DeviceType_nGRE; else return DeviceType_GRE; end; end;


## Library pseudocode for shared/translation/attrs/S2CombineS1MemAttrs

// S2CombineS1MemAttrs // ===================== // Combine stage 2 with stage 1 memory attributes

func S2CombineS1MemAttrs(s1_memattrs : MemoryAttributes, s2_memattrs : MemoryAttributes, s2aarch64 : boolean) => MemoryAttributes begin var memattrs : MemoryAttributes;

if s1_memattrs.memtype == MemType_Device && s2_memattrs.memtype == MemType_Device then
    memattrs.memtype = MemType_Device;
    memattrs.device  = S2CombineS1Device(s1_memattrs.device, s2_memattrs.device);
elsif s1_memattrs.memtype == MemType_Device then    // S2 Normal, S1 Device
    memattrs = s1_memattrs;
elsif s2_memattrs.memtype == MemType_Device then    // S2 Device, S1 Normal
    memattrs = s2_memattrs;
else                                                // S2 Normal, S1 Normal
    memattrs.memtype = MemType_Normal;
    memattrs.inner   = S2CombineS1AttrHints(s1_memattrs.inner, s2_memattrs.inner);
    memattrs.outer   = S2CombineS1AttrHints(s1_memattrs.outer, s2_memattrs.outer);
end;

memattrs.tags = S2MemTagType(memattrs, s1_memattrs.tags);

if !IsFeatureImplemented(FEAT_MTE_PERM) then memattrs.notagaccess = FALSE; else memattrs.notagaccess = (s2_memattrs.notagaccess && s1_memattrs.tags == MemTag_AllocationTagged); end; memattrs.shareability = S2CombineS1Shareability(s1_memattrs.shareability, s2_memattrs.shareability);

if (memattrs.memtype == MemType_Normal && memattrs.inner.attrs == MemAttr_WB && memattrs.outer.attrs == MemAttr_WB) then memattrs.xs = '0'; elsif s2aarch64 then memattrs.xs = s2_memattrs.xs AND s1_memattrs.xs; else memattrs.xs = s1_memattrs.xs; end;

memattrs.shareability = EffectiveShareability(memattrs); return memattrs;

end;


## Library pseudocode for shared/translation/attrs/S2CombineS1Shareability

// S2CombineS1Shareability // ========================= // Combine stage 2 shareability with stage 1

func S2CombineS1Shareability(s1_shareability : Shareability, s2_shareability : Shareability) => Shareability begin

if (s1_shareability == Shareability_OSH ||        s2_shareability == Shareability_OSH) then    return Shareability_OSH;elsif (s1_shareability == Shareability_ISH ||        s2_shareability == Shareability_ISH) then    return Shareability_ISH;else    return Shareability_NSH;end;

end;


## Library pseudocode for shared/translation/attrs/S2DecodeCacheability

// S2DecodeCacheability // ====================== // Determine the stage 2 cacheability for Normal memory

func S2DecodeCacheability(attr : bits(2)) => MemAttrHints begin var s2attr : MemAttrHints;

case attr of
    when '01' => s2attr.attrs = MemAttr_NC;  // Non-cacheable
    when '10' => s2attr.attrs = MemAttr_WT;  // Write-through
    when '11' => s2attr.attrs = MemAttr_WB;  // Write-back
    otherwise => unreachable;
end;

// Stage 2 does not assign hints or the transient property // They are inherited from stage 1 if the result of the combination allows it s2attr.hints = ARBITRARY : bits(2); s2attr.transient = ARBITRARY : boolean;

return s2attr;

end;


## Library pseudocode for shared/translation/attrs/S2DecodeMemAttrs

// S2DecodeMemAttrs // ================== // Decode stage 2 memory attributes when FWB is 0

func S2DecodeMemAttrs(attr_in : bits(4), sh : bits(2), s2aarch64 : boolean) => MemoryAttributes begin var memattrs : MemoryAttributes;

var attr : bits(4);
if S2ResMemAttr(s2aarch64, attr_in) then
    // Map reserved encodings to an allocated encoding
    (-, attr) = ConstrainUnpredictableBits{4}(Unpredictable_S2RESMEMATTR);
else
    attr = attr_in;
end;

case attr of when '00xx' => // Device memory memattrs.memtype = MemType_Device; memattrs.device = DecodeDevice(attr[1:0]); when '0100' => // Normal, Inner+Outer WB cacheable NoTagAccess memory assert s2aarch64 && IsFeatureImplemented(FEAT_MTE_PERM); memattrs.memtype = MemType_Normal; memattrs.outer = S2DecodeCacheability('11'); // Write-back memattrs.inner = S2DecodeCacheability('11'); // Write-back otherwise => // Normal memory memattrs.memtype = MemType_Normal; memattrs.outer = S2DecodeCacheability(attr[3:2]); memattrs.inner = S2DecodeCacheability(attr[1:0]); end;

memattrs.shareability = DecodeShareability(sh);

if s2aarch64 && IsFeatureImplemented(FEAT_MTE_PERM) then memattrs.notagaccess = attr == '0100'; else memattrs.notagaccess = FALSE; end;

return memattrs;

end;


## Library pseudocode for shared/translation/attrs/S2MemTagType

// S2MemTagType // ============== // Determine whether the combined output memory attributes of stage 1 and // stage 2 indicate tagged memory

readonly func S2MemTagType(s2_memattrs : MemoryAttributes, s1_tagtype : MemTagType) => MemTagType begin

if !IsFeatureImplemented(FEAT_MTE2) then
    return MemTag_Untagged;
end;

if s1_tagtype == MemTag_AllocationTagged && IsTaggableMemAttr(s2_memattrs) then return MemTag_AllocationTagged; end;

// Return what stage 1 asked for if we can, otherwise Untagged. if s1_tagtype != MemTag_AllocationTagged then return s1_tagtype; end;

return MemTag_Untagged;

end;


## Library pseudocode for shared/translation/attrs/S2ResMemAttr

// S2ResMemAttr // ============== // Determine whether a reserved value occupies stage 2 MemAttr field when FWB is 0

func S2ResMemAttr(s2aarch64 : boolean, attr : bits(4)) => boolean begin case attr of when '0100' => return !(s2aarch64 && IsFeatureImplemented(FEAT_MTE_PERM)); when '1x00' => return TRUE; otherwise => return FALSE; end; end;


## Library pseudocode for shared/translation/attrs/WalkMemAttrs

// WalkMemAttrs // ============== // Retrieve memory attributes of translation table walk

func WalkMemAttrs(sh : bits(2), irgn : bits(2), orgn : bits(2)) => MemoryAttributes begin var walkmemattrs : MemoryAttributes;

walkmemattrs.memtype      = MemType_Normal;
walkmemattrs.shareability = DecodeShareability(sh);
walkmemattrs.inner        = DecodeSDFAttr(irgn);
walkmemattrs.outer        = DecodeSDFAttr(orgn);
walkmemattrs.tags         = MemTag_Untagged;
if (walkmemattrs.inner.attrs == MemAttr_WB &&
        walkmemattrs.outer.attrs == MemAttr_WB) then
    walkmemattrs.xs = '0';
else
    walkmemattrs.xs = '1';
end;
walkmemattrs.notagaccess = FALSE;

return walkmemattrs;

end;


## Library pseudocode for shared/translation/faults/AlignmentFault

// AlignmentFault // ================ // Return a fault record indicating an Alignment fault not due to memory type has occurred // for a specific access

func AlignmentFault(accdesc : AccessDescriptor, vaddress : bits(64)) => FaultRecord begin var fault : FaultRecord = NoFault(accdesc, vaddress); fault.statuscode = Fault_Alignment;

return fault;

end;


## Library pseudocode for shared/translation/faults/ExclusiveFault

// ExclusiveFault // ================ // Return a fault record indicating a fault for an unsupported Exclusive access

func ExclusiveFault(accdesc : AccessDescriptor, vaddress : bits(64)) => FaultRecord begin var fault : FaultRecord = NoFault(accdesc, vaddress); fault.statuscode = Fault_Exclusive;

return fault;

end;


## Library pseudocode for shared/translation/faults/NoFault

// NoFault // ========= // Return a clear fault record indicating no faults have occurred

func NoFault() => FaultRecord begin var fault : FaultRecord;

fault.vaddress = ARBITRARY : bits(64);
fault.statuscode  = Fault_None;
fault.accessdesc  = ARBITRARY : AccessDescriptor;
fault.secondstage = FALSE;
fault.s2fs1walk   = FALSE;
fault.dirtybit    = FALSE;
fault.overlay     = FALSE;
fault.toplevel    = FALSE;
fault.assuredonly = FALSE;
fault.s1tagnotdata = FALSE;
fault.tagaccess    = FALSE;
fault.gpcfs2walk   = FALSE;
fault.gpcf         = GPCNoFault();
fault.hdbssf       = FALSE;

return fault;

end;

// NoFault // ========= // Return a clear fault record indicating no faults have occurred for a specific access

func NoFault(accdesc : AccessDescriptor) => FaultRecord begin var fault : FaultRecord;

fault.statuscode  = Fault_None;
fault.accessdesc  = accdesc;
fault.secondstage = FALSE;
fault.s2fs1walk   = FALSE;
fault.dirtybit    = FALSE;
fault.overlay     = FALSE;
fault.toplevel    = FALSE;
fault.assuredonly = FALSE;
fault.s1tagnotdata = FALSE;
fault.tagaccess   = FALSE;
fault.write       = !accdesc.read && accdesc.write;
fault.gpcfs2walk  = FALSE;
fault.gpcf        = GPCNoFault();
fault.hdbssf      = FALSE;

return fault;

end;

// NoFault // =========

func NoFault(accdesc : AccessDescriptor, vaddress : bits(64)) => FaultRecord begin var fault : FaultRecord = NoFault(); fault.accessdesc = accdesc; fault.write = !accdesc.read && accdesc.write; fault.vaddress = vaddress;

return fault;

end;


## Library pseudocode for shared/translation/gpc/AbovePPS

// AbovePPS // ========== // Returns TRUE if an address exceeds the range configured in GPCCR_EL3.PPS.

func AbovePPS(address : bits(NUM_PABITS)) => boolean begin let pps : integer{} = DecodePPS(); if pps >= NUM_PABITS then return FALSE; end;

return !IsZero(address[NUM_PABITS-1:pps]);

end;


## Library pseudocode for shared/translation/gpc/DecodeGPTBlock

// DecodeGPTBlock // ================ // Decode a GPT Block descriptor.

func DecodeGPTBlock(pgs : PGSe, gpt_entry : bits(64)) => GPTEntry begin assert gpt_entry[3:0] == GPT_Block; var result : GPTEntry; result.gpi = gpt_entry[7:4]; result.level = 0; result.istable = FALSE;

// GPT information from a level 0 GPT Block descriptor is permitted
// to be cached in a TLB as though the Block is a contiguous region
// of granules each of the size configured in GPCCR_EL3.PGS.
case pgs of
    when PGS_4KB =>  result.size = GPTRange_4KB;
    when PGS_16KB => result.size = GPTRange_16KB;
    when PGS_64KB => result.size = GPTRange_64KB;
    otherwise => unreachable;
end;
result.contig_size = GPTL0Size();

return result;

end;

## Library pseudocode for shared/translation/gpc/DecodeGPTContiguous

Log in to reply.