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

Writeup Shared pseudocode: part 26 of 36

started by admin

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

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

    when Fault_SyncParityOnWalk =>    result = '0111'::level[1:0]; assert level IN {0,1,2,3};
    when Fault_AsyncParity   =>       result = '011001';
    when Fault_TagCheck =>            result = '010001'; assert IsFeatureImplemented(FEAT_MTE2);
    when Fault_Alignment =>           result = '100001';
    when Fault_Debug =>               result = '100010';
    when Fault_GPCFOnWalk =>          result = '1001'::level[1:0]; assert level IN {0,1,2,3};
    when Fault_GPCFOnOutput =>        result = '101000';
    when Fault_TLBConflict =>         result = '110000';
    when Fault_UnsupportedAtomicHWUpdate =>
                                      result = '110001';
    when Fault_Lockdown =>            result = '110100';  // IMPLEMENTATION DEFINED
    when Fault_Exclusive =>           result = '110101';  // IMPLEMENTATION DEFINED
    otherwise =>                      unreachable;
end;

return result;

end;


## Library pseudocode for shared/functions/aborts/IPAValid

// IPAValid // ========== // Return TRUE if the IPA is reported for the abort

readonly func IPAValid(fault : FaultRecord) => boolean begin assert fault.statuscode != Fault_None;

if fault.gpcf.gpf != GPCF_None then    return fault.secondstage;elsif fault.s2fs1walk then    return fault.statuscode IN {        Fault_AccessFlag,        Fault_Permission,        Fault_Translation,        Fault_AddressSize    };elsif fault.secondstage then    return fault.statuscode IN {        Fault_AccessFlag,        Fault_Translation,        Fault_AddressSize    } || (IsFeatureImplemented(FEAT_EAESR) && fault.statuscode == Fault_Permission);else    return FALSE;end;

end;


## Library pseudocode for shared/functions/aborts/IsAsyncAbort

// IsAsyncAbort // ============== // Returns TRUE if the abort currently being processed is an asynchronous abort, and FALSE // otherwise.

func IsAsyncAbort(statuscode : Fault) => boolean begin assert statuscode != Fault_None;

return (statuscode IN {Fault_AsyncExternal, Fault_AsyncParity});

end;

// IsAsyncAbort // ==============

func IsAsyncAbort(fault : FaultRecord) => boolean begin return IsAsyncAbort(fault.statuscode); end;


## Library pseudocode for shared/functions/aborts/IsDebugException

// IsDebugException // ==================

pure func IsDebugException(fault : FaultRecord) => boolean begin assert fault.statuscode != Fault_None; return fault.statuscode == Fault_Debug; end;


## Library pseudocode for shared/functions/aborts/IsExternalAbort

// IsExternalAbort // ================= // Returns TRUE if the abort currently being processed is an External abort and FALSE otherwise.

readonly func IsExternalAbort(statuscode : Fault) => boolean begin assert statuscode != Fault_None;

return (statuscode IN {          Fault_SyncExternal,          Fault_SyncParity,          Fault_SyncExternalOnWalk,          Fault_SyncParityOnWalk,          Fault_AsyncExternal,          Fault_AsyncParity});

end;

// IsExternalAbort // =================

readonly func IsExternalAbort(fault : FaultRecord) => boolean begin return IsExternalAbort(fault.statuscode) || fault.gpcf.gpf == GPCF_EABT; end;


## Library pseudocode for shared/functions/aborts/IsExternalAbortOnWalk

// IsExternalAbortOnWalk // =======================

pure func IsExternalAbortOnWalk(fault : FaultRecord) => boolean begin assert fault.statuscode != Fault_None; return fault.statuscode IN {Fault_SyncExternalOnWalk, Fault_SyncParityOnWalk}; end;


## Library pseudocode for shared/functions/aborts/IsExternalSyncAbort

// IsExternalSyncAbort // ===================== // Returns TRUE if the abort currently being processed is an external // synchronous abort and FALSE otherwise.

readonly func IsExternalSyncAbort(statuscode : Fault) => boolean begin assert statuscode != Fault_None; if IsFeatureImplemented(FEAT_RAS) then assert ! statuscode IN {Fault_SyncParity, Fault_SyncParityOnWalk}; end;

return (statuscode IN {          Fault_SyncExternal,          Fault_SyncParity,          Fault_SyncExternalOnWalk,          Fault_SyncParityOnWalk});

end;

// IsExternalSyncAbort // =====================

readonly func IsExternalSyncAbort(fault : FaultRecord) => boolean begin return IsExternalSyncAbort(fault.statuscode) || fault.gpcf.gpf == GPCF_EABT; end;


## Library pseudocode for shared/functions/aborts/IsFault

// IsFault // ========= // Return TRUE if a fault is associated with an address descriptor

pure func IsFault(addrdesc : AddressDescriptor) => boolean begin return addrdesc.fault.statuscode != Fault_None; end;

// IsFault // ========= // Return TRUE if a fault is associated with a memory access.

pure func IsFault(fault : Fault) => boolean begin return fault != Fault_None; end;

// IsFault // ========= // Return TRUE if a fault is associated with status returned by memory.

pure func IsFault(retstatus : PhysMemRetStatus) => boolean begin return retstatus.statuscode != Fault_None; end;


## Library pseudocode for shared/functions/aborts/IsSErrorInterrupt

// IsSErrorInterrupt // =================== // Returns TRUE if the abort currently being processed is an SError interrupt, and FALSE // otherwise.

func IsSErrorInterrupt(statuscode : Fault) => boolean begin assert statuscode != Fault_None;

return (statuscode IN {Fault_AsyncExternal, Fault_AsyncParity});

end;

// IsSErrorInterrupt // ===================

func IsSErrorInterrupt(fault : FaultRecord) => boolean begin return IsSErrorInterrupt(fault.statuscode); end;

// Add a specific type of return value for FaultSyndrome type IssType of record { iss : bits(25), iss2 : bits(24) };


## Library pseudocode for shared/functions/aborts/IsSecondStage

// IsSecondStage // ===============

pure func IsSecondStage(fault : FaultRecord) => boolean begin assert fault.statuscode != Fault_None;

return fault.secondstage;

end;


## Library pseudocode for shared/functions/aborts/LSInstructionSyndrome

// LSInstructionSyndrome // ======================= // Returns the extended syndrome information for a second stage fault. // [10] - Syndrome valid bit. The syndrome is valid only for certain types of access instruction. // [9:8] - Access size. // [7] - Sign extended (for loads). // [6:2] - Transfer register. // [1] - Transfer register is 64-bit. // [0] - Instruction has acquire/release semantics.

impdef func LSInstructionSyndrome() => bits(11) begin return ARBITRARY : bits(11); end;


## Library pseudocode for shared/functions/aborts/ReportAsGPCException

// ReportAsGPCException // ====================== // Determine whether the given GPCF is reported as a Granule Protection Check Exception // rather than a Data or Instruction Abort

func ReportAsGPCException(fault : FaultRecord) => boolean begin assert IsFeatureImplemented(FEAT_RME); assert fault.statuscode IN {Fault_GPCFOnWalk, Fault_GPCFOnOutput}; assert fault.gpcf.gpf != GPCF_None;

if Halted() && EDSCR().SDD == '1' then
    return FALSE;
end;

case fault.gpcf.gpf of when GPCF_Walk => return TRUE; when GPCF_AddressSize => return TRUE; when GPCF_EABT => return TRUE; when GPCF_Fail => return SCR_EL3().GPF == '1' && PSTATE.EL != EL3; end;

end;


## Library pseudocode for shared/functions/cache/CACHE\_OP

// CACHE_OP // ========== // Performs Cache maintenance operations as per CacheRecord.

impdef func CACHE_OP(cache : CacheRecord) begin return; end;


## Library pseudocode for shared/functions/cache/CPASAtPAS

// CPASAtPAS // =========== // Get cache PA space for given PA space.

readonly func CPASAtPAS(pas : PASpace) => CachePASpace begin case pas of when PAS_NonSecure => return CPAS_NonSecure; when PAS_Secure => return CPAS_Secure; when PAS_Root => return CPAS_Root; when PAS_Realm => return CPAS_Realm; when PAS_SystemAgent => return CPAS_SystemAgent; when PAS_NonSecureProtected => return CPAS_NonSecureProtected; when PAS_NA6 => return CPAS_NA6; when PAS_NA7 => return CPAS_NA7; otherwise => unreachable; end; end;


## Library pseudocode for shared/functions/cache/CPASAtSecurityState

// CPASAtSecurityState // ===================== // Get cache PA space for given security state.

func CPASAtSecurityState(ss : SecurityState) => CachePASpace begin case ss of when SS_NonSecure => return CPAS_NonSecure; when SS_Secure => return CPAS_SecureNonSecure; when SS_Root => return CPAS_Any; when SS_Realm => return CPAS_RealmNonSecure; end; end;


## Library pseudocode for shared/functions/cache/CacheRecord

// CacheRecord // =========== // Details related to a cache operation.

type CacheRecord of record { acctype : AccessType, // Access type cacheop : CacheOp, // Cache operation opscope : CacheOpScope, // Cache operation type cachetype : CacheType, // Cache type regval : bits(64), paddress : FullAddress, vaddress : bits(64), // For VA operations setnum : integer, // For SW operations waynum : integer, // For SW operations level : integer, // For SW operations shareability : Shareability, is_vmid_valid : boolean, // is vmid valid for current context vmid : bits(NUM_VMIDBITS), is_asid_valid : boolean, // is asid valid for current context asid : bits(NUM_ASIDBITS), security : SecurityState, // For inner shareable IC operations, the TLBI Domains the operation is broadcast to domains : bits(16), // For cache operations to full cache or by setnum/waynum // For operations by address, PA space in paddress cpas : CachePASpace };


## Library pseudocode for shared/functions/cache/DecodeSW

// DecodeSW // ========== // Decode input value into setnum, waynum and level for SW instructions.

func DecodeSW(regval : bits(64), cachetype : CacheType) => (integer, integer, integer) begin let level : integer = UInt(regval[3:1]); let (numsets, associativity, linesize) = GetCacheInfo(level, cachetype); // For the given level and cachetype, get the number of sets, associativity and // cache line size in terms of actual bytes.

let max_waybits : integer{} = if IsFeatureImplemented(FEAT_CCIDX) then 21 else 10;
let max_setbits : integer{} = if IsFeatureImplemented(FEAT_CCIDX) then 24 else 15;

let waybits : integer{} = CeilLog2(associativity) as integer{0..max_waybits}; let setbits : integer{} = CeilLog2(numsets) as integer{0..max_setbits}; let linebits : integer{} = FloorLog2(linesize) as integer{4..11};

let waynum : integer = if associativity == 1 then 0 else UInt(regval[31:32-waybits]); let setnum : integer = if numsets == 1 then 0 else UInt(regval[linebits +: setbits]);

return (setnum, waynum, level);

end;


## Library pseudocode for shared/functions/cache/GetCacheInfo

// GetCacheInfo // ============== // Returns numsets, associativity & linesize in terms of actual bytes.

impdef func GetCacheInfo(level : integer, cachetype : CacheType) => (integer, integer, integer) begin let numsets : integer = ImpDefInt("Numsets for DC SW instructions"); let associativity : integer = ImpDefInt("Associativity for DC SW instructions"); let linesize : integer = ImpDefInt("Linesize for DC SW instructions"); return (numsets, associativity, linesize); end;


## Library pseudocode for shared/functions/common/IsZeroBit

// IsZeroBit // ===========

pure func IsZeroBit{N}(x : bits(N)) => bit begin return if IsZero(x) then '1' else '0'; end;


## Library pseudocode for shared/functions/common/NormalizeReal

// NormalizeReal // ============= // Normalizes x to the form 1.xxx... x 2^y and returns (mantissa, exponent)

pure func NormalizeReal(x : real) => (real, integer) begin let exponent : integer = ILog2(x); let mantissa : real = x / (2.0 ^ exponent); return (mantissa, exponent); end;


## Library pseudocode for shared/functions/common/RShr

// RShr // ====== // Shift integer value right with rounding

pure func RShr(value : integer, shift : integer, round : boolean) => integer begin assert shift > 0; if round then return (value + (1 << (shift - 1))) >> shift; else return value >> shift; end; end;


## Library pseudocode for shared/functions/common/Reverse

// Reverse // ========= // Reverse subwords of M bits in an N-bit word

pure func Reverse{N}(word : bits(N), M : integer) => bits(N) begin assert N MOD M == 0; var result : bits(N); let swsize : integer{} = M as integer{1..N}; let sw : integer = N DIV swsize; for s = 0 to sw-1 do result[((sw - 1) - s):swsize] = word[s:swsize]; end; return result; end;


## Library pseudocode for shared/functions/common/Signal

// Signal // ====== // Available signal types

type Signal of enumeration {LOW, HIGH};


## Library pseudocode for shared/functions/counters

var PhysicalCount : bits(88);

var IsLocalTimeoutEventPending : boolean; var LocalTimeoutVal : bits(64); // Value to compare against the Virtual Counter Timer // to generate the local timeout event.


## Library pseudocode for shared/functions/counters/AArch32\_CheckTimerConditions

// AArch32_CheckTimerConditions // ============================== // Checking timer conditions for all A32 timer registers

func AArch32_CheckTimerConditions begin var status : boolean; var offset : bits(64); offset = Zeros{64}; assert (); if HaveEL(EL3) then if CNTP_CTL_S().ENABLE == '1' then status = IsTimerConditionMet(offset, CNTP_CVAL_S(), CNTP_CTL_S().IMASK, InterruptID_CNTPS); CNTP_CTL_S().ISTATUS = if status then '1' else '0'; end;

    if CNTP_CTL_NS().ENABLE == '1' then        status = IsTimerConditionMet(offset, CNTP_CVAL_NS(),                                     CNTP_CTL_NS().IMASK, InterruptID_CNTP);        CNTP_CTL_NS().ISTATUS = if status then '1' else '0';    end;else    if CNTP_CTL().ENABLE == '1' then        status = IsTimerConditionMet(offset, CNTP_CVAL(),                                     CNTP_CTL().IMASK, InterruptID_CNTP);        CNTP_CTL().ISTATUS = if status then '1' else '0';    end;end;if HaveEL(EL2) && CNTHP_CTL().ENABLE == '1' then    status = IsTimerConditionMet(offset, CNTHP_CVAL(),                                 CNTHP_CTL().IMASK, InterruptID_CNTHP);    CNTHP_CTL().ISTATUS = if status then '1' else '0';end;if CNTV_CTL_EL0().ENABLE == '1' then    status = IsTimerConditionMet(CNTVOFF_EL2(), CNTV_CVAL_EL0(),                                 CNTV_CTL_EL0().IMASK, InterruptID_CNTV);    CNTV_CTL_EL0().ISTATUS = if status then '1' else '0';end;return;

end;


## Library pseudocode for shared/functions/counters/AArch64\_CheckTimerConditions

// AArch64_CheckTimerConditions // ============================== // Checking timer conditions for all A64 timer registers

func AArch64_CheckTimerConditions begin var status : boolean; var offset : bits(64); var imask : bit; let ss : SecurityState = CurrentSecurityState(); if (IsFeatureImplemented(FEAT_ECV_POFF) && EL2Enabled() && (EL0) && CNTHCTL_EL2().ECV == '1' && SCR_EL3().ECVEn == '1') then offset = CNTPOFF_EL2(); else offset = Zeros{64}; end; if CNTP_CTL_EL0().ENABLE == '1' then imask = CNTP_CTL_EL0().IMASK; if (IsFeatureImplemented(FEAT_RME) && ss IN {SS_Root, SS_Realm} && CNTHCTL_EL2().CNTPMASK == '1') then imask = '1'; end; status = IsTimerConditionMet(offset, CNTP_CVAL_EL0(), imask, InterruptID_CNTP); CNTP_CTL_EL0().ISTATUS = if status then '1' else '0'; end; if ((HaveEL(EL3) || (HaveEL(EL2) && !IsFeatureImplemented(FEAT_SEL2))) && CNTHP_CTL_EL2().ENABLE == '1') then status = IsTimerConditionMet(Zeros{64}, CNTHP_CVAL_EL2(), CNTHP_CTL_EL2().IMASK, InterruptID_CNTHP); CNTHP_CTL_EL2().ISTATUS = if status then '1' else '0'; end; if HaveEL(EL2) && IsFeatureImplemented(FEAT_SEL2) && CNTHPS_CTL_EL2().ENABLE == '1' then status = IsTimerConditionMet(Zeros{64}, CNTHPS_CVAL_EL2(), CNTHPS_CTL_EL2().IMASK, InterruptID_CNTHPS); CNTHPS_CTL_EL2().ISTATUS = if status then '1' else '0'; end;

if CNTPS_CTL_EL1().ENABLE == '1' then
    status = IsTimerConditionMet(Zeros{64}, CNTPS_CVAL_EL1(),
                                 CNTPS_CTL_EL1().IMASK, InterruptID_CNTPS);
    CNTPS_CTL_EL1().ISTATUS = if status then '1' else '0';
end;

if CNTV_CTL_EL0().ENABLE == '1' then imask = CNTV_CTL_EL0().IMASK; if (IsFeatureImplemented(FEAT_RME) && ss IN {SS_Root, SS_Realm} && CNTHCTL_EL2().CNTVMASK == '1') then imask = '1'; end; status = IsTimerConditionMet(CNTVOFF_EL2(), CNTV_CVAL_EL0(), imask, InterruptID_CNTV); CNTV_CTL_EL0().ISTATUS = if status then '1' else '0'; end;

if ((IsFeatureImplemented(FEAT_VHE) && (HaveEL(EL3) || !IsFeatureImplemented(FEAT_SEL2))) && CNTHV_CTL_EL2().ENABLE == '1') then status = IsTimerConditionMet(Zeros{64}, CNTHV_CVAL_EL2(), CNTHV_CTL_EL2().IMASK, InterruptID_CNTHV); CNTHV_CTL_EL2().ISTATUS = if status then '1' else '0'; end;

if ((IsFeatureImplemented(FEAT_SEL2) && IsFeatureImplemented(FEAT_VHE)) && CNTHVS_CTL_EL2().ENABLE == '1') then status = IsTimerConditionMet(Zeros{64}, CNTHVS_CVAL_EL2(), CNTHVS_CTL_EL2().IMASK, InterruptID_CNTHVS); CNTHVS_CTL_EL2().ISTATUS = if status then '1' else '0'; end; return;

end;


## Library pseudocode for shared/functions/counters/CNTHCTL\_EL2\_VHE

// CNTHCTL_EL2_VHE // ================= // In the case where EL2 accesses the CNTKCTL_EL1 register, and the access // is redirected to CNTHCTL_EL2 as a result of HCR_EL2.E2H being 1, // then the bits of CNTHCTL_EL2 that are RES0 in CNTKCTL_EL1 are // treated as being UNKNOWN. This function applies the UNKNOWN behavior.

func CNTHCTL_EL2_VHE(original_value : bits(64)) => bits(64) begin assert PSTATE.EL == EL2; assert HCR_EL2().E2H == '1';

var return_value : bits(64) = original_value;if !IsFeatureImplemented(FEAT_NV2p1) then    return_value[19:18] = ARBITRARY : bits(2);    return_value[16:10] = ARBITRARY : bits(7);end;return return_value;

end;


## Library pseudocode for shared/functions/counters/GenericCounterTick

// GenericCounterTick // ==================== // Increments PhysicalCount value for every clock tick.

func GenericCounterTick begin var prev_physical_count : bits(64); if CNTCR().EN == '0' then if () then AArch32_CheckTimerConditions(); else AArch64_CheckTimerConditions(); end; return; end; prev_physical_count = PhysicalCountInt(); if IsFeatureImplemented(FEAT_CNTSC) && CNTCR().SCEN == '1' then PhysicalCount = PhysicalCount + ZeroExtend{88}(CNTSCR()); else PhysicalCount[87:24] = PhysicalCount[87:24] + 1; end; if () then AArch32_CheckTimerConditions(); else AArch64_CheckTimerConditions(); end; TestEventCNTP(prev_physical_count, PhysicalCountInt()); TestEventCNTV(prev_physical_count, PhysicalCountInt()); return; end;


## Library pseudocode for shared/functions/counters/IsTimerConditionMet

// IsTimerConditionMet // =====================

func IsTimerConditionMet(offset : bits(64), compare_value : bits(64), imask : bits(1), intid : InterruptID) => boolean begin var condition_met : boolean; var level : Signal; condition_met = (UInt(PhysicalCountInt() - offset) - UInt(compare_value)) >= 0; level = if condition_met && imask == '0' then HIGH else LOW; SetInterruptRequestLevel(intid, level); return condition_met; end;


## Library pseudocode for shared/functions/counters/SetEventRegister

// SetEventRegister // ================== // Sets the Event Register of this PE

func SetEventRegister begin EventRegister = '1'; return; end;


## Library pseudocode for shared/functions/counters/TestEventCNTP

// TestEventCNTP // =============== // Generate Event stream from the physical counter

func TestEventCNTP(prev_physical_count : bits(64), current_physical_count : bits(64)) begin var n : integer; if CNTHCTL_EL2().EVNTEN == '1' then n = UInt(CNTHCTL_EL2().EVNTI); if IsFeatureImplemented(FEAT_ECV) && CNTHCTL_EL2().EVNTIS == '1' then n = n + 8; end; if CNTHCTL_EL2().EVNTDIR == '0' then if prev_physical_count[n] == '0' && current_physical_count[n] == '1' then SetEventRegister(); end; else if prev_physical_count[n] == '1' && current_physical_count[n] == '0' then SetEventRegister(); end; end; end; return; end;


## Library pseudocode for shared/functions/counters/TestEventCNTV

// TestEventCNTV // =============== // Generate Event stream from the virtual counter

func TestEventCNTV(prev_physical_count : bits(64), current_physical_count : bits(64)) begin var offset : bits(64); var samplebit, previousbit : bit; var n : integer; if (EffectiveHCR_EL2_E2H()::EffectiveTGE() != '11' && CNTKCTL_EL1().EVNTEN == '1') then n = UInt(CNTKCTL_EL1().EVNTI); if IsFeatureImplemented(FEAT_ECV) && CNTKCTL_EL1().EVNTIS == '1' then n = n + 8; end; offset = if HaveEL(EL2) then CNTVOFF_EL2() else Zeros{64};

    samplebit   = (current_physical_count - offset)[n];    previousbit = (prev_physical_count - offset)[n];    if CNTKCTL_EL1().EVNTDIR == '0' then        if previousbit == '0' && samplebit == '1' then SetEventRegister(); end;    else        if previousbit == '1' && samplebit == '0' then SetEventRegister(); end;    end;end;return;

end;


## Library pseudocode for shared/functions/counters/VirtualCounterTimer

// VirtualCounterTimer // ===================== // Returns the Counter-Timer Virtual Count value, the value is as read by CurrentEL to CNTVCT_EL0.

func VirtualCounterTimer() => bits(64) begin var cntvct : bits(64);

if PSTATE.EL != EL3 then
    if HaveEL(EL2) && (PSTATE.EL) then
        cntvct = PhysicalCountInt() - CNTVOFF_EL2();
    else
        cntvct = PhysicalCountInt();
    end;
else
    if HaveEL(EL2) && (EL2) then
        cntvct = PhysicalCountInt() - CNTVOFF_EL2();
    elsif HaveEL(EL2) && ELUsingAArch32(EL2) then
        cntvct = PhysicalCountInt() - CNTVOFF();
    else
        cntvct = PhysicalCountInt();
    end;
end;

return cntvct;

end;


## Library pseudocode for shared/functions/crc/BitReverse

// BitReverse // ============

func BitReverse{N}(data : bits(N)) => bits(N) begin var result : bits(N); for i = 0 to N-1 do result[(N-i)-1] = data*; end; return result; end;


## Library pseudocode for shared/functions/crc/Poly32Mod2

// Poly32Mod2 // ============

// Poly32Mod2 on a bitstring does a polynomial Modulus over {0,1} operation

func Poly32Mod2{N}(data_in : bits(N), poly : bits(32)) => bits(32) begin assert N > 32; var data : bits(N) = data_in; for i = N-1 downto 32 do if data* == '1' then data[i-1:0] = data[i-1:0] XOR (poly::Zeros{i-32}); end; end; return data[31:0]; end;


## Library pseudocode for shared/functions/crypto/AESInvMixColumns

// AESInvMixColumns // ================== // Transformation in the Inverse Cipher that is the inverse of AESMixColumns.

func AESInvMixColumns(op : bits (128)) => bits(128) begin let in0 : bits(48) = op[ 96+:8] :: op[ 64+:8] :: op[ 32+:8] :: op[ 0+:8]; let in1 : bits(48) = op[104+:8] :: op[ 72+:8] :: op[ 40+:8] :: op[ 8+:8]; let in2 : bits(48) = op[112+:8] :: op[ 80+:8] :: op[ 48+:8] :: op[ 16+:8]; let in3 : bits(48) = op[120+:8] :: op[ 88+:8] :: op[ 56+:8] :: op[ 24+:8];

var out0 : bits(4*8);
var out1 : bits(4*8);
var out2 : bits(4*8);
var out3 : bits(4*8);

for c = 0 to 3 do out0[c8+:8] = (FFmul0E(in0[c8+:8]) XOR FFmul0B(in1[c8+:8]) XOR FFmul0D(in2[c8+:8]) XOR FFmul09(in3[c8+:8])); out1[c8+:8] = (FFmul09(in0[c8+:8]) XOR FFmul0E(in1[c8+:8]) XOR FFmul0B(in2[c8+:8]) XOR FFmul0D(in3[c8+:8])); out2[c8+:8] = (FFmul0D(in0[c8+:8]) XOR FFmul09(in1[c8+:8]) XOR FFmul0E(in2[c8+:8]) XOR FFmul0B(in3[c8+:8])); out3[c8+:8] = (FFmul0B(in0[c8+:8]) XOR FFmul0D(in1[c8+:8]) XOR FFmul09(in2[c8+:8]) XOR FFmul0E(in3[c8+:8])); end;

return ( out3[38+:8] :: out2[38+:8] :: out1[38+:8] :: out0[38+:8] :: out3[28+:8] :: out2[28+:8] :: out1[28+:8] :: out0[28+:8] :: out3[18+:8] :: out2[18+:8] :: out1[18+:8] :: out0[18+:8] :: out3[08+:8] :: out2[08+:8] :: out1[08+:8] :: out0[08+:8] );

end;


## Library pseudocode for shared/functions/crypto/AESInvShiftRows

// AESInvShiftRows // ================= // Transformation in the Inverse Cipher that is inverse of AESShiftRows.

func AESInvShiftRows(op : bits(128)) => bits(128) begin return ( op[ 31: 24] :: op[ 55: 48] :: op[ 79: 72] :: op[103: 96] :: op[127:120] :: op[ 23: 16] :: op[ 47: 40] :: op[ 71: 64] :: op[ 95: 88] :: op[119:112] :: op[ 15: 8] :: op[ 39: 32] :: op[ 63: 56] :: op[ 87: 80] :: op[111:104] :: op[ 7: 0] ); end;


## Library pseudocode for shared/functions/crypto/AESInvSubBytes

// AESInvSubBytes // ================ // Transformation in the Inverse Cipher that is the inverse of AESSubBytes.

func AESInvSubBytes(op : bits(128)) => bits(128) begin // Inverse S-box values let GF2_inv : bits(16168) = ( /* F E D C B A 9 8 7 6 5 4 3 2 1 0 / /F/ 0x7d0c2155631469e126d677ba7e042b17[127:0] :: /E/ 0x619953833cbbebc8b0f52aae4d3be0a0[127:0] :: /D/ 0xef9cc9939f7ae52d0d4ab519a97f5160[127:0] :: /C/ 0x5fec8027591012b131c7078833a8dd1f[127:0] :: /B/ 0xf45acd78fec0db9a2079d2c64b3e56fc[127:0] :: /A/ 0x1bbe18aa0e62b76f89c5291d711af147[127:0] :: /9/ 0x6edf751ce837f9e28535ade72274ac96[127:0] :: /8/ 0x73e6b4f0cecff297eadc674f4111913a[127:0] :: /7/ 0x6b8a130103bdafc1020f3fca8f1e2cd0[127:0] :: /6/ 0x0645b3b80558e4f70ad3bc8c00abd890[127:0] :: /5/ 0x849d8da75746155edab9edfd5048706c[127:0] :: /4/ 0x92b6655dcc5ca4d41698688664f6f872[127:0] :: /3/ 0x25d18b6d49a25b76b224d92866a12e08[127:0] :: /2/ 0x4ec3fa420b954cee3d23c2a632947b54[127:0] :: /1/ 0xcbe9dec444438e3487ff2f9b8239e37c[127:0] :: /0/ 0xfbd7f3819ea340bf38a53630d56a0952[127:0] ); var out : bits(128); for i = 0 to 15 do out[i8+:8] = GF2_inv[UInt(op[i*8+:8])*8+:8]; end; return out; end;


## Library pseudocode for shared/functions/crypto/AESMixColumns

// AESMixColumns // =============== // Transformation in the Cipher that takes all of the columns of the // State and mixes their data (independently of one another) to // produce new columns.

func AESMixColumns(op : bits (128)) => bits(128) begin let in0 : bits(48) = op[ 96+:8] :: op[ 64+:8] :: op[ 32+:8] :: op[ 0+:8]; let in1 : bits(48) = op[104+:8] :: op[ 72+:8] :: op[ 40+:8] :: op[ 8+:8]; let in2 : bits(48) = op[112+:8] :: op[ 80+:8] :: op[ 48+:8] :: op[ 16+:8]; let in3 : bits(48) = op[120+:8] :: op[ 88+:8] :: op[ 56+:8] :: op[ 24+:8];

var out0 : bits(4*8);
var out1 : bits(4*8);
var out2 : bits(4*8);
var out3 : bits(4*8);

for c = 0 to 3 do out0[c8+:8] = (FFmul02(in0[c8+:8]) XOR FFmul03(in1[c8+:8]) XOR in2[c8+:8] XOR in3[c8+:8]); out1[c8+:8] = (FFmul02(in1[c8+:8]) XOR FFmul03(in2[c8+:8]) XOR in3[c8+:8] XOR in0[c8+:8]); out2[c8+:8] = (FFmul02(in2[c8+:8]) XOR FFmul03(in3[c8+:8]) XOR in0[c8+:8] XOR in1[c8+:8]); out3[c8+:8] = (FFmul02(in3[c8+:8]) XOR FFmul03(in0[c8+:8]) XOR in1[c8+:8] XOR in2[c8+:8]); end;

return ( out3[38+:8] :: out2[38+:8] :: out1[38+:8] :: out0[38+:8] :: out3[28+:8] :: out2[28+:8] :: out1[28+:8] :: out0[28+:8] :: out3[18+:8] :: out2[18+:8] :: out1[18+:8] :: out0[18+:8] :: out3[08+:8] :: out2[08+:8] :: out1[08+:8] :: out0[08+:8] );

end;


## Library pseudocode for shared/functions/crypto/AESShiftRows

// AESShiftRows // ============== // Transformation in the Cipher that processes the State by cyclically // shifting the last three rows of the State by different offsets.

func AESShiftRows(op : bits(128)) => bits(128) begin return ( op[ 95: 88] :: op[ 55: 48] :: op[ 15: 8] :: op[103: 96] :: op[ 63: 56] :: op[ 23: 16] :: op[111:104] :: op[ 71: 64] :: op[ 31: 24] :: op[119:112] :: op[ 79: 72] :: op[ 39: 32] :: op[127:120] :: op[ 87: 80] :: op[ 47: 40] :: op[ 7: 0] ); end;


## Library pseudocode for shared/functions/crypto/AESSubBytes

// AESSubBytes // ============= // Transformation in the Cipher that processes the State using a nonlinear // byte substitution table (S-box) that operates on each of the State bytes // independently.

func AESSubBytes(op : bits(128)) => bits(128) begin // S-box values let GF2 : bits(16168) = ( /* F E D C B A 9 8 7 6 5 4 3 2 1 0 / /F/ 0x16bb54b00f2d99416842e6bf0d89a18c[127:0] :: /E/ 0xdf2855cee9871e9b948ed9691198f8e1[127:0] :: /D/ 0x9e1dc186b95735610ef6034866b53e70[127:0] :: /C/ 0x8a8bbd4b1f74dde8c6b4a61c2e2578ba[127:0] :: /B/ 0x08ae7a65eaf4566ca94ed58d6d37c8e7[127:0] :: /A/ 0x79e4959162acd3c25c2406490a3a32e0[127:0] :: /9/ 0xdb0b5ede14b8ee4688902a22dc4f8160[127:0] :: /8/ 0x73195d643d7ea7c41744975fec130ccd[127:0] :: /7/ 0xd2f3ff1021dab6bcf5389d928f40a351[127:0] :: /6/ 0xa89f3c507f02f94585334d43fbaaefd0[127:0] :: /5/ 0xcf584c4a39becb6a5bb1fc20ed00d153[127:0] :: /4/ 0x842fe329b3d63b52a05a6e1b1a2c8309[127:0] :: /3/ 0x75b227ebe28012079a059618c323c704[127:0] :: /2/ 0x1531d871f1e5a534ccf73f362693fdb7[127:0] :: /1/ 0xc072a49cafa2d4adf04759fa7dc982ca[127:0] :: /0/ 0x76abd7fe2b670130c56f6bf27b777c63[127:0] ); var out : bits(128); for i = 0 to 15 do out[i8+:8] = GF2[UInt(op[i*8+:8])*8+:8]; end; return out; end;


## Library pseudocode for shared/functions/crypto/FFmul02

// FFmul02 // =========

func FFmul02(b : bits(8)) => bits(8) begin let FFmul_02 : bits(2568) = ( / F E D C B A 9 8 7 6 5 4 3 2 1 0 */ /F/ 0xE5E7E1E3EDEFE9EBF5F7F1F3FDFFF9FB[127:0] :: /E/ 0xC5C7C1C3CDCFC9CBD5D7D1D3DDDFD9DB[127:0] :: /D/ 0xA5A7A1A3ADAFA9ABB5B7B1B3BDBFB9BB[127:0] :: /C/ 0x858781838D8F898B959791939D9F999B[127:0] :: /B/ 0x656761636D6F696B757771737D7F797B[127:0] :: /A/ 0x454741434D4F494B555751535D5F595B[127:0] :: /9/ 0x252721232D2F292B353731333D3F393B[127:0] :: /8/ 0x050701030D0F090B151711131D1F191B[127:0] :: /7/ 0xFEFCFAF8F6F4F2F0EEECEAE8E6E4E2E0[127:0] :: /6/ 0xDEDCDAD8D6D4D2D0CECCCAC8C6C4C2C0[127:0] :: /5/ 0xBEBCBAB8B6B4B2B0AEACAAA8A6A4A2A0[127:0] :: /4/ 0x9E9C9A98969492908E8C8A8886848280[127:0] :: /3/ 0x7E7C7A78767472706E6C6A6866646260[127:0] :: /2/ 0x5E5C5A58565452504E4C4A4846444240[127:0] :: /1/ 0x3E3C3A38363432302E2C2A2826242220[127:0] :: /0/ 0x1E1C1A18161412100E0C0A0806040200[127:0] ); return FFmul_02[UInt(b)*8+:8]; end;


## Library pseudocode for shared/functions/crypto/FFmul03

// FFmul03 // =========

func FFmul03(b : bits(8)) => bits(8) begin let FFmul_03 : bits(2568) = ( / F E D C B A 9 8 7 6 5 4 3 2 1 0 */ /F/ 0x1A191C1F16151013020104070E0D080B[127:0] :: /E/ 0x2A292C2F26252023323134373E3D383B[127:0] :: /D/ 0x7A797C7F76757073626164676E6D686B[127:0] :: /C/ 0x4A494C4F46454043525154575E5D585B[127:0] :: /B/ 0xDAD9DCDFD6D5D0D3C2C1C4C7CECDC8CB[127:0] :: /A/ 0xEAE9ECEFE6E5E0E3F2F1F4F7FEFDF8FB[127:0] :: /9/ 0xBAB9BCBFB6B5B0B3A2A1A4A7AEADA8AB[127:0] :: /8/ 0x8A898C8F86858083929194979E9D989B[127:0] :: /7/ 0x818287848D8E8B88999A9F9C95969390[127:0] :: /6/ 0xB1B2B7B4BDBEBBB8A9AAAFACA5A6A3A0[127:0] :: /5/ 0xE1E2E7E4EDEEEBE8F9FAFFFCF5F6F3F0[127:0] :: /4/ 0xD1D2D7D4DDDEDBD8C9CACFCCC5C6C3C0[127:0] :: /3/ 0x414247444D4E4B48595A5F5C55565350[127:0] :: /2/ 0x717277747D7E7B78696A6F6C65666360[127:0] :: /1/ 0x212227242D2E2B28393A3F3C35363330[127:0] :: /0/ 0x111217141D1E1B18090A0F0C05060300[127:0] ); return FFmul_03[UInt(b)*8+:8]; end;


## Library pseudocode for shared/functions/crypto/FFmul09

// FFmul09 // =========

func FFmul09(b : bits(8)) => bits(8) begin let FFmul_09 : bits(2568) = ( / F E D C B A 9 8 7 6 5 4 3 2 1 0 */ /F/ 0x464F545D626B70790E071C152A233831[127:0] :: /E/ 0xD6DFC4CDF2FBE0E99E978C85BAB3A8A1[127:0] :: /D/ 0x7D746F6659504B42353C272E1118030A[127:0] :: /C/ 0xEDE4FFF6C9C0DBD2A5ACB7BE8188939A[127:0] :: /B/ 0x3039222B141D060F78716A635C554E47[127:0] :: /A/ 0xA0A9B2BB848D969FE8E1FAF3CCC5DED7[127:0] :: /9/ 0x0B0219102F263D34434A5158676E757C[127:0] :: /8/ 0x9B928980BFB6ADA4D3DAC1C8F7FEE5EC[127:0] :: /7/ 0xAAA3B8B18E879C95E2EBF0F9C6CFD4DD[127:0] :: /6/ 0x3A3328211E170C05727B6069565F444D[127:0] :: /5/ 0x9198838AB5BCA7AED9D0CBC2FDF4EFE6[127:0] :: /4/ 0x0108131A252C373E49405B526D647F76[127:0] :: /3/ 0xDCD5CEC7F8F1EAE3949D868FB0B9A2AB[127:0] :: /2/ 0x4C455E5768617A73040D161F2029323B[127:0] :: /1/ 0xE7EEF5FCC3CAD1D8AFA6BDB48B829990[127:0] :: /0/ 0x777E656C535A41483F362D241B120900[127:0] ); return FFmul_09[UInt(b)*8+:8]; end;


## Library pseudocode for shared/functions/crypto/FFmul0B

// FFmul0B // =========

func FFmul0B(b : bits(8)) => bits(8) begin let FFmul_0B : bits(2568) = ( / F E D C B A 9 8 7 6 5 4 3 2 1 0 */ /F/ 0xA3A8B5BE8F849992FBF0EDE6D7DCC1CA[127:0] :: /E/ 0x1318050E3F3429224B405D56676C717A[127:0] :: /D/ 0xD8D3CEC5F4FFE2E9808B969DACA7BAB1[127:0] :: /C/ 0x68637E75444F5259303B262D1C170A01[127:0] :: /B/ 0x555E434879726F640D061B10212A373C[127:0] :: /A/ 0xE5EEF3F8C9C2DFD4BDB6ABA0919A878C[127:0] :: /9/ 0x2E2538330209141F767D606B5A514C47[127:0] :: /8/ 0x9E958883B2B9A4AFC6CDD0DBEAE1FCF7[127:0] :: /7/ 0x545F424978736E650C071A11202B363D[127:0] :: /6/ 0xE4EFF2F9C8C3DED5BCB7AAA1909B868D[127:0] :: /5/ 0x2F2439320308151E777C616A5B504D46[127:0] :: /4/ 0x9F948982B3B8A5AEC7CCD1DAEBE0FDF6[127:0] :: /3/ 0xA2A9B4BF8E859893FAF1ECE7D6DDC0CB[127:0] :: /2/ 0x1219040F3E3528234A415C57666D707B[127:0] :: /1/ 0xD9D2CFC4F5FEE3E8818A979CADA6BBB0[127:0] :: /0/ 0x69627F74454E5358313A272C1D160B00[127:0] ); return FFmul_0B[UInt(b)*8+:8]; end;


## Library pseudocode for shared/functions/crypto/FFmul0D

// FFmul0D // =========

func FFmul0D(b : bits(8)) => bits(8) begin let FFmul_0D : bits(2568) = ( / F E D C B A 9 8 7 6 5 4 3 2 1 0 */ /F/ 0x979A8D80A3AEB9B4FFF2E5E8CBC6D1DC[127:0] :: /E/ 0x474A5D50737E69642F2235381B16010C[127:0] :: /D/ 0x2C21363B1815020F44495E53707D6A67[127:0] :: /C/ 0xFCF1E6EBC8C5D2DF94998E83A0ADBAB7[127:0] :: /B/ 0xFAF7E0EDCEC3D4D9929F8885A6ABBCB1[127:0] :: /A/ 0x2A27303D1E130409424F5855767B6C61[127:0] :: /9/ 0x414C5B5675786F622924333E1D10070A[127:0] :: /8/ 0x919C8B86A5A8BFB2F9F4E3EECDC0D7DA[127:0] :: /7/ 0x4D40575A7974636E25283F32111C0B06[127:0] :: /6/ 0x9D90878AA9A4B3BEF5F8EFE2C1CCDBD6[127:0] :: /5/ 0xF6FBECE1C2CFD8D59E938489AAA7B0BD[127:0] :: /4/ 0x262B3C31121F08054E4354597A77606D[127:0] :: /3/ 0x202D3A3714190E034845525F7C71666B[127:0] :: /2/ 0xF0FDEAE7C4C9DED39895828FACA1B6BB[127:0] :: /1/ 0x9B96818CAFA2B5B8F3FEE9E4C7CADDD0[127:0] :: /0/ 0x4B46515C7F726568232E3934171A0D00[127:0] ); return FFmul_0D[UInt(b)*8+:8]; end;


## Library pseudocode for shared/functions/crypto/FFmul0E

// FFmul0E // =========

func FFmul0E(b : bits(8)) => bits(8) begin let FFmul_0E : bits(2568) = ( / F E D C B A 9 8 7 6 5 4 3 2 1 0 */ /F/ 0x8D83919FB5BBA9A7FDF3E1EFC5CBD9D7[127:0] :: /E/ 0x6D63717F555B49471D13010F252B3937[127:0] :: /D/ 0x56584A446E60727C26283A341E10020C[127:0] :: /C/ 0xB6B8AAA48E80929CC6C8DAD4FEF0E2EC[127:0] :: /B/ 0x202E3C321816040A505E4C426866747A[127:0] :: /A/ 0xC0CEDCD2F8F6E4EAB0BEACA28886949A[127:0] :: /9/ 0xFBF5E7E9C3CDDFD18B859799B3BDAFA1[127:0] :: /8/ 0x1B150709232D3F316B657779535D4F41[127:0] :: /7/ 0xCCC2D0DEF4FAE8E6BCB2A0AE848A9896[127:0] :: /6/ 0x2C22303E141A08065C52404E646A7876[127:0] :: /5/ 0x17190B052F21333D67697B755F51434D[127:0] :: /4/ 0xF7F9EBE5CFC1D3DD87899B95BFB1A3AD[127:0] :: /3/ 0x616F7D735957454B111F0D032927353B[127:0] :: /2/ 0x818F9D93B9B7A5ABF1FFEDE3C9C7D5DB[127:0] :: /1/ 0xBAB4A6A8828C9E90CAC4D6D8F2FCEEE0[127:0] :: /0/ 0x5A544648626C7E702A243638121C0E00[127:0] ); return FFmul_0E[UInt(b)*8+:8]; end;


## Library pseudocode for shared/functions/crypto/SHA256hash

// SHA256hash // ============

func SHA256hash(x_in : bits (128), y_in : bits(128), w : bits(128), part1 : boolean) => bits(128) begin var chs, maj, t : bits(32); var x : bits(128) = x_in; var y : bits(128) = y_in;

for e = 0 to 3 do    chs = SHAchoose(y[31:0], y[63:32], y[95:64]);    maj = SHAmajority{32}(x[31:0], x[63:32], x[95:64]);    t   = y[127:96] + SHA256hashSIGMA1(y[31:0]) + chs + w[e*:32];    x[127:96] = t + x[127:96];    y[127:96] = t + SHA256hashSIGMA0(x[31:0]) + maj;    let yx : bits(256) = ROL(y :: x, 32);    (y, x) = (yx[128+:128], yx[0+:128]);end;return (if part1 then x else y);

end;


## Library pseudocode for shared/functions/crypto/SHA256hashSIGMA0

// SHA256hashSIGMA0 // ==================

func SHA256hashSIGMA0(x : bits(32)) => bits(32) begin return ROR(x, 2) XOR ROR(x, 13) XOR ROR(x, 22); end;


## Library pseudocode for shared/functions/crypto/SHA256hashSIGMA1

// SHA256hashSIGMA1 // ==================

func SHA256hashSIGMA1(x : bits(32)) => bits(32) begin return ROR(x, 6) XOR ROR(x, 11) XOR ROR(x, 25); end;


## Library pseudocode for shared/functions/crypto/SHAchoose

// SHAchoose // =========== func SHAchoose(x : bits(32), y : bits(32), z : bits(32)) => bits(32) begin return (((y XOR z) AND x) XOR z); end;


## Library pseudocode for shared/functions/crypto/SHAmajority

// SHAmajority // =============

func SHAmajority{N}(x : bits(N), y : bits(N), z : bits(N)) => bits(N) begin assert N IN {32, 64}; return ((x AND y) OR ((x OR y) AND z)); end;


## Library pseudocode for shared/functions/crypto/SHAparity

// SHAparity // ===========

func SHAparity(x : bits(32), y : bits(32), z : bits(32)) => bits(32) begin return (x XOR y XOR z); end;


## Library pseudocode for shared/functions/crypto/Sbox

// Sbox // ====== // Used in SM4E crypto instruction

func Sbox(sboxin : bits(8)) => bits(8) begin var sboxout : bits(8); let sboxstring : bits(2048) = ( /* F E D C B A 9 8 7 6 5 4 3 2 1 0 / /F/ 0xd690e9fecce13db716b614c228fb2c05[127:0] :: /E/ 0x2b679a762abe04c3aa44132649860699[127:0] :: /D/ 0x9c4250f491ef987a33540b43edcfac62[127:0] :: /C/ 0xe4b31ca9c908e89580df94fa758f3fa6[127:0] :: /B/ 0x4707a7fcf37317ba83593c19e6854fa8[127:0] :: /A/ 0x686b81b27164da8bf8eb0f4b70569d35[127:0] :: /9/ 0x1e240e5e6358d1a225227c3b01217887[127:0] :: /8/ 0xd40046579fd327524c3602e7a0c4c89e[127:0] :: /7/ 0xeabf8ad240c738b5a3f7f2cef96115a1[127:0] :: /6/ 0xe0ae5da49b341a55ad933230f58cb1e3[127:0] :: /5/ 0x1df6e22e8266ca60c02923ab0d534e6f[127:0] :: /4/ 0xd5db3745defd8e2f03ff6a726d6c5b51[127:0] :: /3/ 0x8d1baf92bbddbc7f11d95c411f105ad8[127:0] :: /2/ 0x0ac13188a5cd7bbd2d74d012b8e5b4b0[127:0] :: /1/ 0x8969974a0c96777e65b9f109c56ec684[127:0] :: /0/ 0x18f07dec3adc4d2079ee5f3ed7cb3948[127:0] ); let sboxindex : integer = 255 - UInt(sboxin); sboxout = sboxstring[sboxindex:8]; return sboxout; end;


## Library pseudocode for shared/functions/decode/DecodeType

// DecodeType // ==========

type DecodeType of enumeration { Decode_UNDEF, Decode_NOP, Decode_OK };


## Library pseudocode for shared/functions/decode/EndOfDecode

// EndOfDecode // ============= // This function is invoked to end the Decode phase and performs Branch target Checks // before taking any UNDEFINED exceptions, NOPs, or continuing to execute.

func EndOfDecode(reason : DecodeType) begin if IsFeatureImplemented(FEAT_BTI) && () then BranchTargetCheck(); end; case reason of when Decode_NOP => ExecuteAsNOP(); when Decode_UNDEF => Undefined(); when Decode_OK => pass; // Continue to execute. end; return; end;


## Library pseudocode for shared/functions/exclusive/ClearExclusiveByAddress

// ClearExclusiveByAddress // ========================= // Clear the global Exclusives monitors for all PEs EXCEPT processorid if they // record any part of the physical address region of size bytes starting at paddress. // It is IMPLEMENTATION DEFINED whether the global Exclusives monitor for processorid // is also cleared if it records any part of the address region.

impdef func ClearExclusiveByAddress(paddress : FullAddress, processorid : integer, size : integer) begin return; end;


## Library pseudocode for shared/functions/exclusive/ClearExclusiveLocal

// ClearExclusiveLocal // ===================== // Clear the local Exclusives monitor for the specified processorid.

impdef func ClearExclusiveLocal(processorid : integer) begin return; end;


## Library pseudocode for shared/functions/exclusive/ExclusiveMonitorsStatus

// ExclusiveMonitorsStatus // ========================= // Returns '0' to indicate success if the last memory write by this PE was to // the same physical address region endorsed by ExclusiveMonitorsPass(). // Returns '1' to indicate failure if address translation resulted in a different // physical address.

impdef func ExclusiveMonitorsStatus() => bit begin return '0'; end;


## Library pseudocode for shared/functions/exclusive/IsExclusiveGlobal

// IsExclusiveGlobal // =================== // Return TRUE if the global Exclusives monitor for processorid includes all of // the physical address region of size bytes starting at paddress.

impdef func IsExclusiveGlobal(paddress : FullAddress, processorid : integer, size : integer) => boolean begin return TRUE; end;


## Library pseudocode for shared/functions/exclusive/IsExclusiveLocal

// IsExclusiveLocal // ================== // Return TRUE if the local Exclusives monitor for processorid includes all of // the physical address region of size bytes starting at paddress.

impdef func IsExclusiveLocal(paddress : FullAddress, processorid : integer, size : integer) => boolean begin return FALSE; end;


## Library pseudocode for shared/functions/exclusive/MarkExclusiveGlobal

// MarkExclusiveGlobal // ===================== // Record the physical address region of size bytes starting at paddress in // the global Exclusives monitor for processorid.

impdef func MarkExclusiveGlobal(paddress : FullAddress, processorid : integer, size : integer) begin return; end;


## Library pseudocode for shared/functions/exclusive/MarkExclusiveLocal

// MarkExclusiveLocal // ==================== // Record the physical address region of size bytes starting at paddress in // the local Exclusives monitor for processorid.

impdef func MarkExclusiveLocal(paddress : FullAddress, processorid : integer, size : integer) begin return; end;


## Library pseudocode for shared/functions/exclusive/ProcessorID

// ProcessorID // ============= // Return the ID of the currently executing PE.

impdef func ProcessorID() => integer begin if HaveAArch64() then return UInt(MPIDR_EL1().Aff3 :: MPIDR_EL1().Aff2 :: MPIDR_EL1().Aff1 :: MPIDR_EL1().Aff0); else return UInt(MPIDR().Aff2 :: MPIDR().Aff1 :: MPIDR().Aff0); end; end;


## Library pseudocode for shared/functions/externalaborts/ActionRequired

// ActionRequired // ================ // Return an implementation specific value: // returns TRUE if action is required, FALSE otherwise.

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


## Library pseudocode for shared/functions/externalaborts/ClearPendingDelegatedSError

// ClearPendingDelegatedSError // ============================= // Clear a pending delegated SError interrupt.

func ClearPendingDelegatedSError begin assert IsFeatureImplemented(FEAT_E3DSE); SCR_EL3().DSE = '0'; end;


## Library pseudocode for shared/functions/externalaborts/ClearPendingPhysicalSError

// ClearPendingPhysicalSError // ============================ // Clear a pending physical SError interrupt.

impdef func ClearPendingPhysicalSError begin return; end;


## Library pseudocode for shared/functions/externalaborts/ClearPendingVirtualSError

// ClearPendingVirtualSError // =========================== // Clear a pending virtual SError interrupt.

func ClearPendingVirtualSError begin if ELUsingAArch32(EL2) then HCR().VA = '0'; else HCR_EL2().VSE = '0'; end; end;


## Library pseudocode for shared/functions/externalaborts/ErrorIsContained

// ErrorIsContained // ================== // Return an implementation specific value: // TRUE if Error is contained by the PE, FALSE otherwise.

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


## Library pseudocode for shared/functions/externalaborts/ErrorIsSynchronized

// ErrorIsSynchronized // ===================== // Return an implementation specific value: // returns TRUE if Error is synchronized by any synchronization event // FALSE otherwise.

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


## Library pseudocode for shared/functions/externalaborts/ExtAbortToAArch64

// ExtAbortToAArch64 // =================== // Returns TRUE if synchronous exception is being taken to an Exception level using AArch64_

func ExtAbortToAArch64(fault : FaultRecord) => boolean begin assert IsExternalSyncAbort(fault.statuscode);

return (SyncExternalAbortTarget(fault));

end;


## Library pseudocode for shared/functions/externalaborts/ExternalAbort

// ExternalAbort // ===============

func ExternalAbort(fault : FaultRecord) recurselimit 1 begin if IsExternalSyncAbort(fault) then if UsingAArch32() then AArch32_Abort(fault); else AArch64_Abort(fault); end;

else    PendSErrorInterrupt(fault);end;

end;


## Library pseudocode for shared/functions/externalaborts/ExternalFault

// ExternalFault // =============== // Return a fault recording indicating a fault for a Synchronous/Asynchronous External abort.

func ExternalFault(memretstatus : PhysMemRetStatus, iswrite : boolean, memaddrdesc : AddressDescriptor, size : integer, accdesc : AccessDescriptor) => FaultRecord begin assert (memretstatus.statuscode IN {Fault_SyncExternal, Fault_AsyncExternal} || (!IsFeatureImplemented(FEAT_RAS) && memretstatus.statuscode IN {Fault_SyncParity, Fault_AsyncParity}));

var fault : FaultRecord = NoFault(accdesc, memaddrdesc.vaddress);
fault.statuscode = memretstatus.statuscode;
fault.write      = iswrite;
fault.extflag    = memretstatus.extflag;
// It is implementation specific whether External aborts signaled
// in-band synchronously are taken synchronously or asynchronously
if (IsExternalSyncAbort(fault) &&
      ((IsFeatureImplemented(FEAT_RASv2) && ExtAbortToAArch64(fault) &&
        PEErrorState(fault) IN {ErrorState_UC, ErrorState_UEU}) ||
       (memretstatus, iswrite, memaddrdesc,
                                          size, accdesc))) then
    if fault.statuscode == Fault_SyncParity then
        fault.statuscode = Fault_AsyncParity;
    else
        fault.statuscode = Fault_AsyncExternal;
    end;
end;

if IsFeatureImplemented(FEAT_RAS) then fault.merrorstate = memretstatus.merrorstate; end; fault.paddress = memaddrdesc.paddress; return fault;

end;


## Library pseudocode for shared/functions/externalaborts/FaultIsCorrected

// FaultIsCorrected // ================== // Return an implementation specific value: // TRUE if fault is corrected by the PE, FALSE otherwise.

readonly impdef func FaultIsCorrected() => boolean begin return FALSE; end;


## Library pseudocode for shared/functions/externalaborts/GetPendingPhysicalSError

// GetPendingPhysicalSError // ========================== // Returns the FaultRecord containing details of pending Physical SError // interrupt.

impdef func GetPendingPhysicalSError() => FaultRecord begin return ARBITRARY : FaultRecord; end;


## Library pseudocode for shared/functions/externalaborts/HandleExternalAbort

// HandleExternalAbort // ===================== // Takes a Synchronous/Asynchronous abort based on fault.

func HandleExternalAbort(memretstatus : PhysMemRetStatus, iswrite : boolean, memaddrdesc : AddressDescriptor, size : integer, accdesc : AccessDescriptor) begin assert (memretstatus.statuscode IN {Fault_SyncExternal, Fault_AsyncExternal} || (!IsFeatureImplemented(FEAT_RAS) && memretstatus.statuscode IN {Fault_SyncParity, Fault_AsyncParity}));

let fault : FaultRecord = ExternalFault(memretstatus, iswrite, memaddrdesc, size, accdesc);ExternalAbort(fault);

end;


## Library pseudocode for shared/functions/externalaborts/HandleExternalReadAbort

// HandleExternalReadAbort // ========================= // Wrapper function for HandleExternalAbort function in case of an External // Abort on memory read.

func HandleExternalReadAbort(memstatus : PhysMemRetStatus, memaddrdesc : AddressDescriptor, size : integer, accdesc : AccessDescriptor) begin let iswrite : boolean = FALSE; HandleExternalAbort(memstatus, iswrite, memaddrdesc, size, accdesc); end;


## Library pseudocode for shared/functions/externalaborts/HandleExternalTTWAbort

// HandleExternalTTWAbort // ======================== // Take Asynchronous abort or update FaultRecord for Translation Table Walk // based on PhysMemRetStatus.

func HandleExternalTTWAbort(memretstatus : PhysMemRetStatus, iswrite : boolean, memaddrdesc : AddressDescriptor, accdesc : AccessDescriptor, size : integer, input_fault : FaultRecord) => FaultRecord begin var output_fault : FaultRecord = input_fault; output_fault.extflag = memretstatus.extflag; output_fault.statuscode = memretstatus.statuscode; if (IsExternalSyncAbort(output_fault) && ((IsFeatureImplemented(FEAT_RASv2) && ExtAbortToAArch64(output_fault) && PEErrorState(output_fault) IN {ErrorState_UC, ErrorState_UEU}) || (memretstatus, iswrite, memaddrdesc, size, accdesc))) then if output_fault.statuscode == Fault_SyncParity then output_fault.statuscode = Fault_AsyncParity; else output_fault.statuscode = Fault_AsyncExternal; end; end;

// If a synchronous fault is on a translation table walk, then update the fault type.if IsExternalSyncAbort(output_fault) then    if output_fault.statuscode == Fault_SyncParity then        output_fault.statuscode = Fault_SyncParityOnWalk;    else

Log in to reply.