[Writeup] Shared pseudocode: part 34 of 36 ========================================== Section: Silicon & Architectures Started: 2026-11-28 17:48 UTC by admin Replies: 0, last post 2026-11-28 17:48 UTC Page: 1 of 1 Web: https://romdump.net/t/126 ------------------------------------------------------------------------------ #146 admin, 2026-11-28 17:48 UTC [OP] Source: https://romdump.net/raw/146
Shared pseudocode from the offline Arm documentation snapshot. Part 34 of 36.
return Constraint_PMSCR_PCT_VIRT;
when Unpredictable_WFxTDEBUG =>
return Constraint_FALSE; // WFxT in Debug state does not execute as a NOP
// Accesses are not single-copy atomic above the byte level
when Unpredictable_LS64UNSUPPORTED =>
return Constraint_LIMITED_ATOMICITY;
// Unaligned exclusives, atomics, acquire/release
// to a region that is not to Normal inner write-back
// outer write-back shareable generate an Alignment fault.
when Unpredictable_LSE2_ALIGNMENT_FAULT =>
return Constraint_FALSE;
when Unpredictable_LSE128OVERLAP =>
return Constraint_UNDEF; // instruction is UNDEFINED
when Unpredictable_IGNORETRAPINDEBUG =>
return Constraint_FALSE; // Trap to register access in debug state is enabled
when Unpredictable_PMUEVENTCOUNTER =>
return Constraint_UNDEF; // Accesses to the register are UNDEFINED
when Unpredictable_RES_HPMN =>
return Constraint_UNKNOWN; // The counter is reserved for EL2 use
when Unpredictable_RES_EPMN =>
return Constraint_UNKNOWN; // The counter is reserved for external use
when Unpredictable_BRBFILTRATE =>
return Constraint_FALSE; // BRB_FILTRATE event not generated on BRB injection
when Unpredictable_PMUSNAPSHOTEVENT => // PMU_SNAPSHOT event not generated in Debug state
return Constraint_FALSE;
when Unpredictable_RESEPMSSAD =>
// External access to PMUv3 Snapshot extension allowed in Secure state
// when FEAT_RME is not implemented or Root state otherwise
return Constraint_UNKNOWN;
when Unpredictable_RESPMSSE =>
return Constraint_DISABLED; // PMU capture events disabled
when Unpredictable_RESPMEE =>
return Constraint_DISABLED; // PMU Profiling exception disabled, PMUIRQ enabled
when Unpredictable_RESPMSEE =>
return Constraint_DISABLED; // SPE Profiling exception disabled
when Unpredictable_RESTRFEE =>
return Constraint_DISABLED; // TRBE Profiling exception disabled
when Unpredictable_TRBPTR_Fault_AddressSize =>
return Constraint_TRUE; // TRBPTR_EL1[63:(OAMax)] NonZero causes Address Size fault
when Unpredictable_RESTC =>
return Constraint_DISABLED; // Threshold features disabled
when Unpredictable_MOPSOVERLAP => // Instruction is UNDEFINED
return Constraint_UNDEF;
when Unpredictable_MOPS_R31 => // Instruction is UNDEFINED
return Constraint_UNDEF;
when Unpredictable_CASRETURNOLDVALUE =>
return Constraint_TRUE;
when Unpredictable_WRITEFAILEDCAS =>
return Constraint_FALSE;
when Unpredictable_WRITEFAILEDRCWCAS =>
return Constraint_FALSE;
when Unpredictable_STRONLYTAGCHECKEDCAS =>
return Constraint_TRUE; // CAS with compare fail does a Tag Check
when Unpredictable_STRONLYTAGCHECKEDRCWSCAS =>
return Constraint_TRUE; // RCW(S)CAS with RCW(S) fail/compare fail does a Tag Check
when Unpredictable_RESERVEDNSxB =>
return Constraint_MAPTOALLOCATED;
when Unpredictable_RESERVEDNSxB_Trap =>
return Constraint_TRUE;
when Unpredictable_RES_ETBAD =>
// ExternalTracebufferaccess disabled for res values
return Constraint_DISABLED;
when Unpredictable_RESBPMASK =>
return Constraint_DISABLED; // Mask set to 0
when Unpredictable_BPMASK =>
return Constraint_FALSE; // Breakpoint match will fail
when Unpredictable_BPMASKEDBITS =>
return Constraint_FALSE; // Breakpoint match will fail
when Unpredictable_BPLINKEDADDRMATCH =>
return Constraint_FALSE; // Breakpoint match will fail
when Unpredictable_16BYTEROUNDEDUPACCESS =>
// Watchpoint match of 16 byte rounded range in case of SVE access
return Constraint_TRUE;
when Unpredictable_16BYTEROUNDEDDOWNACCESS =>
// Watchpoint match of 16 byte rounded range in case of SVE access
return Constraint_TRUE;
when Unpredictable_NODTRTAGCHK =>
// The load or store operation does not perform the Tag check in Debug state
return Constraint_TRUE;
when Unpredictable_CPACHECK => // Do not perform Checked Pointer Arithmetic
return Constraint_FALSE;
when Unpredictable_Atomic_SYNC_ABORT =>
return Constraint_FALSE;
when Unpredictable_Atomic_SERROR =>
return Constraint_FALSE;
when Unpredictable_Atomic_NOP =>
return Constraint_FALSE;
when Unpredictable_Atomic_MMU_IMPDEF_FAULT =>
return Constraint_FALSE;
when Unpredictable_MPAM_TRUNCATE_VID =>
return Constraint_TRUE;
when Unpredictable_USE_DEFAULT_PMG =>
return Constraint_TRUE;
when Unpredictable_OUT_OF_RANGE_ID =>
return Constraint_DEFAULT_ID;
when Unpredictable_OUT_OF_RANGE_VID =>
return Constraint_DEFAULT_ID;
when Unpredictable_BankedRegister =>
return Constraint_NOP;
when Unpredictable_UnimplementedRegister =>
return Constraint_NOP;
when Unpredictable_RES_RA =>
return Constraint_TRUE;
when Unpredictable_BPNOTLINKING =>
return Constraint_FALSE;
otherwise =>
unreachable;
end;
end;
## Library pseudocode for
shared/functions/unpredictable/ConstrainUnpredictableBits
// ConstrainUnpredictableBits // ============================
// This is a variant of ConstrainUnpredictable for when the result can be Constraint_UNKNOWN. // If the result is Constraint_UNKNOWN then the function also returns UNKNOWN value, but that // value is always an allocated value; that is, one for which the behavior is not itself // CONSTRAINED.
readonly impdef func ConstrainUnpredictableBits{width}(which : Unpredictable ) => (Constraint, bits(width)) begin let c : Constraint = ConstrainUnpredictable(which);
case c of
when Constraint_UNKNOWN =>
return (c, Zeros{width}); // See notes; this is an example implementation only
when Constraint_PMSCR_PCT_VIRT =>
return (c, Zeros{width});
when Constraint_NC where which == Unpredictable_S2RESMEMATTR =>
assert width == 4;
return (c, ZeroExtend{width}('0101'));
when Constraint_WT where which == Unpredictable_S2RESMEMATTR =>
assert width == 4;
return (c, ZeroExtend{width}('1010'));
when Constraint_WB where which == Unpredictable_S2RESMEMATTR =>
assert width == 4;
return (c, ZeroExtend{width}('1111'));
when Constraint_EL1TIMESTAMP =>
return (c, ZeroExtend{width}('01'));
when Constraint_EL2TIMESTAMP =>
return (c, ZeroExtend{width}('01'));
when Constraint_MAPTOALLOCATED =>
return (c, ZeroExtend{width}('010')); // return non-secure state_bits
otherwise =>
return (c, ARBITRARY : bits(width)); // bits result not used
end;
end;
## Library pseudocode for
shared/functions/unpredictable/ConstrainUnpredictableBool
// ConstrainUnpredictableBool // ============================ // This is a variant of the ConstrainUnpredictable function where the result is either // Constraint_TRUE or Constraint_FALSE.
readonly impdef func ConstrainUnpredictableBool(which : Unpredictable) => boolean begin let c : Constraint = ConstrainUnpredictable(which); assert c IN {Constraint_TRUE, Constraint_FALSE}; return (c == Constraint_TRUE); end;
## Library pseudocode for
shared/functions/unpredictable/ConstrainUnpredictableInteger
// ConstrainUnpredictableInteger // =============================== // This is a variant of ConstrainUnpredictable for when the result can be Constraint_UNKNOWN. // If the result is Constraint_UNKNOWN then the function also returns an UNKNOWN // value in the range low to high, inclusive.
impdef func ConstrainUnpredictableInteger(low : integer, high : integer, which : Unpredictable) => (Constraint,integer) begin let c : Constraint = ConstrainUnpredictable(which); if c == Constraint_UNKNOWN then return (c, low); // See notes; this is an example implementation only else return (c, ARBITRARY : integer); // integer result not used end; end;
## Library pseudocode for
shared/functions/unpredictable/ConstrainUnpredictableProcedure
// ConstrainUnpredictableProcedure // ================================= // This is a variant of ConstrainUnpredictable that implements a Constrained // Unpredictable behavior for a given Unpredictable situation. // The behavior is within permitted behaviors for a given Unpredictable situation, // these are documented in the textual part of the architecture specification. // // This function is expected to be refined in an IMPLEMENTATION DEFINED manner. // The details of possible outcomes may not be present in the code and must be interpreted // for each use with respect to the CONSTRAINED UNPREDICTABLE specifications // for the specific area.
impdef func ConstrainUnpredictableProcedure(which : Unpredictable) begin case which of when Unpredictable_PMUEVENTCOUNTER => Undefined(); when Unpredictable_MRC_APSR_TARGET => PSTATE.[N,Z,C,V] = DBGDSCRint()[31:28]; otherwise => ImpDef("IMPLEMENTATION_DEFINED"); end; return; end;
## Library pseudocode for shared/functions/unpredictable/Constraint
// Constraint // ========== // List of Constrained Unpredictable behaviors.
type Constraint of enumeration { // General Constraint_NONE, // Instruction executes with // no change or side-effect // to its described behavior Constraint_UNKNOWN, // Destination register // has UNKNOWN value Constraint_UNDEF, // Instruction is UNDEFINED Constraint_UNDEFEL0, // Instruction is UNDEFINED at EL0 only Constraint_NOP, // Instruction executes as NOP Constraint_TRUE, Constraint_FALSE, Constraint_DISABLED, Constraint_UNCOND, // Instruction executes unconditionally Constraint_COND, // Instruction executes conditionally Constraint_ADDITIONAL_DECODE, // Instruction executes // with additional decode // Load-store Constraint_WBSUPPRESS, Constraint_FAULT, Constraint_LIMITED_ATOMICITY, // Accesses are not // single-copy atomic // above the byte level Constraint_NVNV1_00, Constraint_NVNV1_01, Constraint_NVNV1_11, Constraint_EL1TIMESTAMP, // Constrain to Virtual Timestamp Constraint_EL2TIMESTAMP, // Constrain to Virtual Timestamp Constraint_DEFAULT_ID, // Use default PARTID/PM Constraint_ANY_ID, // Use any in-range PARTID/PMG Constraint_OSH, // Constrain to Outer Shareable Constraint_ISH, // Constrain to Inner Shareable Constraint_NSH, // Constrain to Nonshareable
Constraint_NC, // Constrain to Noncacheable
Constraint_WT, // Constrain to Writethrough
Constraint_WB, // Constrain to Writeback
Constraint_RESS, // Bits behave as RESS for all purposes
// other than reading back the register
Constraint_ALLRESS, // Bits behave as RESS for all purposes
// IPA too large
Constraint_FORCE, Constraint_FORCENOSLCHECK,
// An unallocated System register value maps onto an allocated value
Constraint_MAPTOALLOCATED,
// PMSCR_PCT reserved values select Virtual timestamp
Constraint_PMSCR_PCT_VIRT,
Constraint_ANYREG, // Any allocated register is chosen
};
## Library pseudocode for shared/functions/unpredictable/Unpredictable
// Unpredictable // ============= // List of Constrained Unpredictable situations.
type Unpredictable of enumeration { // VMSR on MVFR Unpredictable_VMSR, // Writeback/transfer register overlap (load) Unpredictable_WBOVERLAPLD, // Writeback/transfer register overlap (store) Unpredictable_WBOVERLAPST, // Load Pair transfer register overlap Unpredictable_LDPOVERLAP, // Store-exclusive base/status register overlap Unpredictable_BASEOVERLAP, // Store-exclusive data/status register overlap Unpredictable_DATAOVERLAP, // Load-store alignment checks Unpredictable_DEVPAGE2, // Instruction fetch from Device memory Unpredictable_INSTRDEVICE, // Reserved CPACR value Unpredictable_RESCPACR, // Reserved MAIR value Unpredictable_RESMAIR, // Effect of SCTLR_ELx.C on Tagged attribute Unpredictable_S1CTAGGED, // Reserved Stage 2 MemAttr value Unpredictable_S2RESMEMATTR, // Reserved TEX::C::B value Unpredictable_RESTEXCB, // Reserved PRRR value Unpredictable_RESPRRR, // Reserved DACR field Unpredictable_RESDACR, // Reserved VTCR.S value Unpredictable_RESVTCRS, // Reserved or out-of-range TCR.TnSZ value Unpredictable_RESTnSZ, // Reserved SCTLR_ELx.TCF value Unpredictable_RESTCF, // Tag stored to Device memory Unpredictable_DEVICETAGSTORE, // Syndrome for a known-passing conditional A32 instruction Unpredictable_ESRCONDPASS, // Illegal State exception: zero PSTATE.IT Unpredictable_ILZEROIT, // Illegal State exception: zero PSTATE.T Unpredictable_ILZEROT, // Debug: prioritization of Vector Catch Unpredictable_BPVECTORCATCHPRI, // Debug Vector Catch: match on 2nd halfword Unpredictable_VCMATCHHALF, // Debug Vector Catch: match on Data Abort // or Prefetch abort Unpredictable_VCMATCHDAPA, // Debug watchpoints: nonzero MASK and non-ones BAS Unpredictable_WPMASKANDBAS, // Debug watchpoints: non-contiguous BAS Unpredictable_WPBASCONTIGUOUS, // Debug watchpoints: reserved MASK Unpredictable_RESWPMASK, // Debug watchpoints: nonzero MASKed bits of address Unpredictable_WPMASKEDBITS, // Debug breakpoints and watchpoints: reserved control bits Unpredictable_RESBPWPCTRL, // Debug breakpoints: not implemented Unpredictable_BPNOTIMPL, // Debug breakpoints: reserved type Unpredictable_RESBPTYPE, // Debug breakpoints and watchpoints: reserved MDSELR_EL1.BANK Unpredictable_RESMDSELR, // Debug breakpoints: not-context-aware breakpoint Unpredictable_BPNOTCTXCMP, // Debug breakpoints: match on 2nd halfword of instruction Unpredictable_BPMATCHHALF, // Debug breakpoints: mismatch on 2nd halfword of instruction Unpredictable_BPMISMATCHHALF, // Debug breakpoints: a breakpoint is linked to that is not // programmed with linking enabled Unpredictable_BPLINKINGDISABLED, // Debug breakpoints: reserved MASK Unpredictable_RESBPMASK, // Debug breakpoints: MASK is set for a Context matching // breakpoint or when DBGBCR_EL1(n).BAS != '1111' Unpredictable_BPMASK, // Debug breakpoints: nonzero MASKed bits of address Unpredictable_BPMASKEDBITS, // Debug breakpoints: A linked breakpoint is // linked to an address matching breakpoint Unpredictable_BPLINKEDADDRMATCH, // Debug: restart to a misaligned AArch32 PC value Unpredictable_RESTARTALIGNPC, // Debug: restart to a not-zero-extended AArch32 PC value Unpredictable_RESTARTZEROUPPERPC, // Zero top 32 bits of X registers in AArch32 state Unpredictable_ZEROUPPER, // Zero top 32 bits of PC on illegal return to // AArch32 state Unpredictable_ERETZEROUPPERPC, // Force address to be aligned when interworking // branch to A32 state Unpredictable_A32FORCEALIGNPC, // SMC disabled Unpredictable_SMD, // FF speculation Unpredictable_NONFAULT, // Zero top bits of Z registers in EL change Unpredictable_SVEZEROUPPER, // Load mem data in NF loads Unpredictable_SVELDNFDATA, // Write zeros in NF loads Unpredictable_SVELDNFZERO, // SP alignment fault when predicate is all zero Unpredictable_CHECKSPNONEACTIVE, // Zero top bits of ZA registers in EL change Unpredictable_SMEZEROUPPER, // Watchpoint match of last rounded up memory access in case of // 16 byte rounding Unpredictable_16BYTEROUNDEDUPACCESS, // Watchpoint match of first rounded down memory access in case of // 16 byte rounding Unpredictable_16BYTEROUNDEDDOWNACCESS, // HCR_EL2.[NV,NV1] == '01' Unpredictable_NVNV1, // Upper bits of a BADDR are not RESS Unpredictable_BADDR_RESS, // Reserved shareability encoding Unpredictable_Shareability, // Access Flag Update by HW Unpredictable_AFUPDATE, // Dirty Bit State Update by HW Unpredictable_DBUPDATE, // Unsupported memory attributes for HW update Unpredictable_Unsupported_Atomic_HW_Update, // Consider SCTLR_ELx().IESB in Debug state Unpredictable_IESBinDebug, // Bad settings for PMSFCR_EL1/PMSEVFR_EL1/PMSLATFR_EL1 Unpredictable_BADPMSFCR, // Zero saved BType value in SPSR_ELx/DPSR_EL0 Unpredictable_ZEROBTYPE, // Timestamp constrained to virtual or physical Unpredictable_EL2TIMESTAMP, Unpredictable_EL1TIMESTAMP, // Reserved MDCR_EL3.[NSTBE,NSTB] or MDCR_EL3.[NSPBE,NSPB] value Unpredictable_RESERVEDNSxB, Unpredictable_RESERVEDNSxB_Trap, // WFET or WFIT instruction in Debug state Unpredictable_WFxTDEBUG, // Address does not support LS64 instructions Unpredictable_LS64UNSUPPORTED, // Unaligned exclusives, atomics, acquire/release // to a region that is not to Normal inner write-back // outer write-back shareable generate an Alignment fault. Unpredictable_LSE2_ALIGNMENT_FAULT, // 128-bit Atomic or 128-bit RCW{S} transfer register overlap Unpredictable_LSE128OVERLAP, // Clearing DCC/ITR sticky flags when instruction is in flight Unpredictable_CLEARERRITEZERO, // ALUEXCEPTIONRETURN when in user/system mode in // A32 instructions Unpredictable_ALUEXCEPTIONRETURN, // Trap to register in debug state are ignored Unpredictable_IGNORETRAPINDEBUG, // Compare DBGBVR.RESS for BP/WP Unpredictable_DBGxVR_RESS, // Inaccessible event counter Unpredictable_PMUEVENTCOUNTER, // Reserved PMSCR.PCT behavior Unpredictable_PMSCR_PCT, // MDCR_EL2.HPMN or HDCR.HPMN is larger than PMCR.N or // FEAT_HPMN0 is not implemented and HPMN is 0. Unpredictable_RES_HPMN, // Chained PMU counters idx and idx+1 are not in same range Unpredictable_COUNT_CHAIN, // PMCCR.EPMN is larger than PMCR.N Unpredictable_RES_EPMN, // Generate BRB_FILTRATE event on BRB injection Unpredictable_BRBFILTRATE, // Generate PMU_SNAPSHOT event in Debug state Unpredictable_PMUSNAPSHOTEVENT, // Reserved MDCR_EL3.EPMSSAD value Unpredictable_RESEPMSSAD, // Reserved PMECR_EL1.SSE value Unpredictable_RESPMSSE, // Enable for PMU Profiling exception and PMUIRQ Unpredictable_RESPMEE, // Enables for SPE Profiling exceptions and PMSIRQ Unpredictable_RESPMSEE, // Enables for TRBE Profiling exceptions and PMSIRQ Unpredictable_RESTRFEE, // NonZero TRBPTR_EL1[63:(OAMax)] Unpredictable_TRBPTR_Fault_AddressSize, // Operands for CPY*/SET* instructions overlap Unpredictable_MOPSOVERLAP, // Operands for CPY*/SET* instructions use 0b11111 // as a register specifier Unpredictable_MOPS_R31, // PMBPTR_EL1[63:(OAMax)] NonZero causes Address Size fault Unpredictable_PMBPTR_Fault_AddressSize, // Chooses which value to return in a non failed Atomic Compare and Swap Unpredictable_CASRETURNOLDVALUE, // Enables write of the newvalue in a failed Atomic Compare and Swap Unpredictable_WRITEFAILEDCAS, // Enables write of the newvalue in a failed Atomic Compare and Swap // or failed RCW{S} Unpredictable_WRITEFAILEDRCWCAS, // Store-only Tag checking on a failed Atomic Compare and Swap Unpredictable_STRONLYTAGCHECKEDCAS, // Store-only Tag checking on a failed RCW(S) checks // or RCW(S) Atomic Compare and Swap Unpredictable_STRONLYTAGCHECKEDRCWSCAS, // Reserved MDCR_EL3.ETBAD value Unpredictable_RES_ETBAD, // Invalid Streaming Mode filter bits Unpredictable_RES_PMU_VS, // Apply Checked Pointer Arithmetic on a sequential access to bytes // that cross the 0xXXFF_FFFF_FFFF_FFFF boundary. Unpredictable_CPACHECK, // Reserved PMEVTYPER_EL0(n).[TC,TE,TLC] values Unpredictable_RESTC, // When FEAT_MTE is implemented, if Memory access mode is enabled // and PSTATE.TCO is 0, Reads and writes to the external debug // interface DTR registers are CONSTRAINED UNPREDICTABLE for tagcheck Unpredictable_NODTRTAGCHK, // Use the default PMG when the default PARTID is generated // due to MPAM error Unpredictable_USE_DEFAULT_PMG, // MPAM PARTID/PMG exceeding PARTID_MAX/PMG_MAX Unpredictable_OUT_OF_RANGE_ID, // MPAM vPARTID exceeding (VPMR_MAX << 2) + 3 Unpredictable_OUT_OF_RANGE_VID, // If the atomic instructions are not atomic in regard to other // agents that access memory, then the instruction can have one or // more of the following effects Unpredictable_Atomic_SYNC_ABORT, Unpredictable_Atomic_SERROR, Unpredictable_Atomic_NOP, Unpredictable_Atomic_MMU_IMPDEF_FAULT, // Truncate virtual identifier to bottom 12 bits if it exceeds 2^12 Unpredictable_MPAM_TRUNCATE_VID, // Accessing DBGDSCRint via MRC in debug state Unpredictable_MRC_APSR_TARGET, // Accessing Banked register not accessible from the PE mode Unpredictable_BankedRegister, // Accessing unimplemented Banked register Unpredictable_UnimplementedRegister, // Reserved ERRACR.{RLRA,SRA,NSRA} values Unpredictable_RES_RA, // Linked target does not support linking Unpredictable_BPNOTLINKING };
## Library pseudocode for shared/functions/vector/AdvSIMDExpandImm
// AdvSIMDExpandImm // ==================
func AdvSIMDExpandImm(op : bit, cmode : bits(4), imm8 : bits(8)) => bits(64) begin var imm64 : bits(64); case cmode[3:1] of when '000' => imm64 = Replicate{64}(Zeros{24}::imm8); when '001' => imm64 = Replicate{64}(Zeros{16}::imm8::Zeros{8}); when '010' => imm64 = Replicate{64}(Zeros{8}::imm8::Zeros{16}); when '011' => imm64 = Replicate{64}(imm8::Zeros{24}); when '100' => imm64 = Replicate{64}(Zeros{8}::imm8); when '101' => imm64 = Replicate{64}(imm8::Zeros{8}); when '110' => if cmode[0] == '0' then imm64 = Replicate{64}(Zeros{16}::imm8::Ones{8}); else imm64 = Replicate{64}(Zeros{8}::imm8::Ones{16}); end; when '111' => if cmode[0] == '0' && op == '0' then imm64 = Replicate{64}(imm8); end; if cmode[0] == '0' && op == '1' then let imm8a : bits(8) = Replicate{}(imm8[7]); let imm8b : bits(8) = Replicate{}(imm8[6]); let imm8c : bits(8) = Replicate{}(imm8[5]); let imm8d : bits(8) = Replicate{}(imm8[4]); let imm8e : bits(8) = Replicate{}(imm8[3]); let imm8f : bits(8) = Replicate{}(imm8[2]); let imm8g : bits(8) = Replicate{}(imm8[1]); let imm8h : bits(8) = Replicate{}(imm8[0]); imm64 = imm8a::imm8b::imm8c::imm8d::imm8e::imm8f::imm8g::imm8h; end; if cmode[0] == '1' && op == '0' then let imm32 : bits(32) = (imm8[7]::NOT(imm8[6])::Replicate{5}(imm8[6]):: imm8[5:0]::Zeros{19}); imm64 = Replicate{64}(imm32); end; if cmode[0] == '1' && op == '1' then if UsingAArch32() then ReservedEncoding(); end; imm64 = imm8[7]::NOT(imm8[6])::Replicate{8}(imm8[6])::imm8[5:0]::Zeros{48}; end; end;
return imm64;
end;
## Library pseudocode for shared/functions/vector/MatMulAdd
// MatMulAdd // =========== // // Signed or unsigned 8-bit integer matrix multiply and add to 32-bit integer matrix // result[2, 2] = addend[2, 2] + (op1[2, 8] * op2[8, 2])
func MatMulAdd(addend : bits(128), op1 : bits(128), op2 : bits(128), op1_unsigned : boolean, op2_unsigned : boolean) => bits(128) begin
var result : bits(128);
var sum : bits(32);
var prod : integer;
for i = 0 to 1 do
for j = 0 to 1 do
sum = addend[(2*i + j)*:32];
for k = 0 to 7 do
let opelt1 : bits(8) = op1[(8*i + k)*:8];
let opelt2 : bits(8) = op2[(8*j + k)*:8];
let element1 : integer = if op1_unsigned then UInt(opelt1) else SInt(opelt1);
let element2 : integer = if op2_unsigned then UInt(opelt2) else SInt(opelt2);
prod = element1 * element2;
sum = sum + prod;
end;
result[(2*i + j)*:32] = sum;
end;
end;
return result;
end;
## Library pseudocode for shared/functions/vector/PolynomialMult
// PolynomialMult // ================
func PolynomialMult{M, N}(op1 : bits(M), op2 : bits(N)) => bits(M+N) begin var result : bits(N + M) = Zeros{M+N}; let extended_op2 : bits(N + M) = ZeroExtend{M+N}(op2); for i=0 to M-1 do if op1* == '1' then result = result XOR LSL(extended_op2, i); end; end; return result; end;
## Library pseudocode for shared/functions/vector/SatQ
// SatQ // ======
func SatQ{N}(i : integer, unsigned : boolean) => (bits(N), boolean) begin let (result, sat) : (bits(N), boolean) = (if unsigned then UnsignedSatQ{N}(i) else SignedSatQ{N}(i)); return (result, sat); end;
## Library pseudocode for shared/functions/vector/ShiftSat
// ShiftSat // ==========
func ShiftSat(shift : integer, esize : integer) => integer begin if shift > esize+1 then return esize+1; elsif shift < -(esize+1) then return -(esize+1); end; return shift; end;
## Library pseudocode for shared/functions/vector/SignedSat
// SignedSat // ===========
func SignedSat{N}(i : integer) => bits(N) begin let (result, -) = SignedSatQ{N}(i); return result; end;
## Library pseudocode for shared/functions/vector/SignedSatQ
// SignedSatQ // ============
func SignedSatQ{N}(i : integer) => (bits(N), boolean) begin var result : integer; var saturated : boolean; if i > 2^(N-1) - 1 then result = 2^(N-1) - 1; saturated = TRUE; elsif i < -(2^(N-1)) then result = -(2^(N-1)); saturated = TRUE; else result = i; saturated = FALSE; end; return (result[N-1:0], saturated); end;
## Library pseudocode for shared/functions/vector/UnsignedRSqrtEstimate
// UnsignedRSqrtEstimate // =======================
func UnsignedRSqrtEstimate{N}(operand : bits(N)) => bits(N) begin assert N == 32; var result : bits(N); if operand[N-1:N-2] == '00' then // Operands <= 0x3FFFFFFF produce 0xFFFFFFFF result = Ones{N}; else // input is in the range 0x40000000 .. 0xffffffff representing 0.25 .. 1.0) // estimate is in the range 256 .. 511 representing [1.0 .. 2.0) let increasedprecision : boolean = FALSE; let estimate : integer = [RecipSqrtEstimate(UInt(operand[31:23]), increasedprecision); // result is in the range 0x80000000 .. 0xff800000 representing [1.0 .. 2.0) result = estimate[8:0] :: Zeros{N-9}; end;
return result;
end;
## Library pseudocode for shared/functions/vector/UnsignedRecipEstimate
// UnsignedRecipEstimate // =======================
func UnsignedRecipEstimate{N}(operand : bits(N)) => bits(N) begin assert N == 32; var result : bits(N); if operand[N-1] == '0' then // Operands <= 0x7FFFFFFF produce 0xFFFFFFFF result = Ones{N}; else // input is in the range 0x80000000 .. 0xffffffff representing 0.5 .. 1.0)
// estimate is in the range 256 to 511 representing [1.0 .. 2.0)
let increasedprecision : boolean = FALSE;
let estimate : integer = [RecipEstimate(UInt(operand[31:23]), increasedprecision);
// result is in the range 0x80000000 .. 0xff800000 representing [1.0 .. 2.0)
result = estimate[8:0] :: Zeros{N-9};
end;
return result;
end;
## Library pseudocode for shared/functions/vector/UnsignedSat
// UnsignedSat // =============
func UnsignedSat{N}(i : integer) => bits(N) begin let (result, -) = UnsignedSatQ{N}(i); return result; end;
## Library pseudocode for shared/functions/vector/UnsignedSatQ
// UnsignedSatQ // ==============
func UnsignedSatQ{N}(i : integer) => (bits(N), boolean) begin var result : integer; var saturated : boolean; if i > 2^N - 1 then result = 2^N - 1; saturated = TRUE; elsif i < 0 then result = 0; saturated = TRUE; else result = i; saturated = FALSE; end; return (result[N-1:0], saturated); end;
## Library pseudocode for shared/trace/Common/DebugMemWrite
// DebugMemWrite // =============== // Write data to memory one byte at a time. Starting at the passed virtual address. // Used by SPE and TRBE.
func DebugMemWrite(vaddress : bits(64), accdesc : AccessDescriptor, aligned : boolean, data : bits(8)) => (PhysMemRetStatus, AddressDescriptor) begin
var memstatus : PhysMemRetStatus = ARBITRARY : PhysMemRetStatus;
// Translate virtual address
var addrdesc : AddressDescriptor;
let size : integer = 1;
addrdesc = AArch64_TranslateAddress(vaddress, accdesc, aligned, size);
if IsFault(addrdesc) then
return (memstatus, addrdesc);
end;
memstatus = PhysMemWrite{8}(addrdesc, accdesc, data);
return (memstatus, addrdesc);
end;
## Library pseudocode for shared/trace/Common/DebugWriteExternalAbort
// DebugWriteExternalAbort // ========================= // Populate the syndrome register for an External abort caused by a call of DebugMemWrite().
func DebugWriteExternalAbort(memstatus : PhysMemRetStatus, addrdesc : AddressDescriptor, start_vaddr : bits(64)) begin
let iswrite : boolean = TRUE;
var handle_as_SError : boolean = FALSE;
case addrdesc.fault.accessdesc.acctype of
when AccessType_SPE =>
handle_as_SError = ImpDefBool("Report SPE ExtAbort as SError");
when AccessType_TRBE =>
handle_as_SError = ImpDefBool("Report TRBE ExtAbort as SError");
otherwise =>
unreachable;
end;
let ttw_abort : boolean = addrdesc.fault.statuscode IN
{Fault_SyncExternalOnWalk,
Fault_SyncParityOnWalk};
let statuscode : Fault = (if ttw_abort then addrdesc.fault.statuscode
else memstatus.statuscode);
if statuscode IN {Fault_AsyncExternal, Fault_AsyncParity} || handle_as_SError
then
// Report the abort as an SError
var fault : FaultRecord = NoFault();
let parity : boolean = statuscode IN {Fault_SyncParity, Fault_AsyncParity,
Fault_SyncParityOnWalk};
fault.statuscode = if parity then Fault_AsyncParity else Fault_AsyncExternal;
if IsFeatureImplemented(FEAT_RAS) then
fault.merrorstate = memstatus.merrorstate;
end;
let extflag : bit = if ttw_abort then addrdesc.fault.extflag else memstatus.extflag;
fault.extflag = extflag;
fault.accessdesc.acctype = addrdesc.fault.accessdesc.acctype;
PendSErrorInterrupt(fault);
return;
end;
// Generate a buffer management event, modifying the existing syndrome.
var handle_async : boolean = FALSE;
var syndrome : bits(64);
case addrdesc.fault.accessdesc.acctype of
when AccessType_SPE =>
handle_async = ImpDefBool("Report SPE ExtAbort asynchronously");
assert !IsFeatureImplemented(FEAT_SPE_EXC);
syndrome = PMBSR_EL1();
when AccessType_TRBE =>
handle_async = ImpDefBool("Report TRBE ExtAbort asynchronously");
assert !IsFeatureImplemented(FEAT_TRBE_EXC);
syndrome = TRBSR_EL1();
otherwise =>
unreachable;
end;
var ec : bits(6);
if (IsFeatureImplemented(FEAT_RME) && addrdesc.fault.gpcf.gpf !=
GPCF_None &&
addrdesc.fault.gpcf.gpf != GPCF_Fail) then
ec = '011110';
else
ec = if addrdesc.fault.secondstage then '100101' else '100100';
end;
let mss2 : bits(24) = Zeros{};
var mss : bits(16) = Zeros{};
if handle_async then // FSC bits
mss[5:0] = '010001';
else
mss[5:0] = EncodeLDFSC(statuscode, addrdesc.fault.level);
end;
// The following values are always updated in the syndrome register.
if (addrdesc.fault.accessdesc.acctype == AccessType_SPE &&
(handle_async || start_vaddr != addrdesc.vaddress)) then
syndrome[19] = '1'; // DL bit (SPE only)
end;
syndrome[18] = '1'; // EA bit
// The following values are not modified if a previous buffer management event
// has not been handled. Note that in this simple sequential model, this test
// will never fail.
if syndrome[17] == '0' then // Check previous 'S' bit.
syndrome[55:32] = mss2; // MSS2 bits
syndrome[31:26] = ec; // EC bits
if addrdesc.fault.accessdesc.acctype == AccessType_TRBE then
syndrome[22] = '1'; // IRQ bit (TRBE only)
end;
syndrome[17] = '1'; // S bit
syndrome[15:0] = mss; // MSS bits
end;
case addrdesc.fault.accessdesc.acctype of
when AccessType_SPE =>
PMBSR_EL1() = syndrome;
when AccessType_TRBE =>
TRBSR_EL1() = syndrome;
otherwise =>
unreachable;
end;
end;
## Library pseudocode for shared/trace/Common/DebugWriteFault
// DebugWriteFault // ================= // Populate the syndrome register for a fault caused by a call of DebugMemWrite().
func DebugWriteFault(vaddress : bits(64), fault : FaultRecord) begin var ec : bits(6); if (IsFeatureImplemented(FEAT_RME) && fault.gpcf.gpf != GPCF_None && fault.gpcf.gpf != GPCF_Fail) then ec = '011110'; else ec = if fault.secondstage then '100101' else '100100'; end;
var mss2 : bits(24) = Zeros{};
var mss : bits(16) = Zeros{};
if fault.gpcf.gpf IN {GPCF_None, GPCF_Fail} then
mss2[11] = if fault.hdbssf then '1' else '0'; // HDBSSF
mss2[8] = if fault.toplevel then '1' else '0'; // TopLevel bit
mss2[7] = if fault.assuredonly then '1' else '0'; // AssuredOnly bit
mss2[6] = if fault.overlay then '1' else '0'; // Overlay bit
mss2[5] = if fault.dirtybit then '1' else '0'; // DirtyBit
mss[5:0] = EncodeLDFSC(fault.statuscode, fault.level); // FSC bits
if fault.s2fs1walk then
if (IsFeatureImplemented(FEAT_SPE_EXC) &&
fault.accessdesc.acctype == AccessType_SPE) then
mss[7] = '1'; // S1PTW bit
end;
if (IsFeatureImplemented(FEAT_TRBE_EXC) &&
fault.accessdesc.acctype == AccessType_TRBE) then
mss[7] = '1'; // S1PTW bit
end;
end;
end;
// Generate a buffer management event, modifying the existing syndrome.
var target_el : bits(2);
var syndrome : bits(64);
case fault.accessdesc.acctype of
when AccessType_SPE =>
target_el = ReportSPEEvent(ec, mss[5:0]);
syndrome = PMBSR_EL(target_el);
when AccessType_TRBE =>
target_el = ReportTRBEEvent(ec, mss[5:0]);
syndrome = TRBSR_EL(target_el);
otherwise =>
unreachable;
end;
// The following values are not modified if a previous buffer management event
// has not been handled. Note that in this simple sequential model, this test
// will never fail.
if syndrome[17] == '0' then // Check previous 'S' bit.
syndrome[55:32] = mss2; // MSS2 bits
syndrome[31:26] = ec; // EC bits
if fault.accessdesc.acctype == AccessType_TRBE then
syndrome[22] = '1'; // IRQ bit (TRBE only)
end;
syndrome[17] = '1'; // S bit
syndrome[15:0] = mss; // MSS bits
end;
// For SPE, PMBPTR_EL1 points to the address that generated the fault, and
writing
// to memory never started. Therefore, there isno data loss and DL is
unchanged.
case fault.accessdesc.acctype of
when AccessType_SPE =>
PMBSR_EL(target_el) = syndrome;
when AccessType_TRBE =>
TRBSR_EL(target_el) = syndrome;
otherwise =>
unreachable;
end;
return;
end;
## Library pseudocode for shared/trace/Common/GetTimestamp
// GetTimestamp // ============== // Returns the Timestamp depending on the type
func GetTimestamp(timeStampType : TimeStamp) => bits(64) begin case timeStampType of when TimeStamp_Physical => return PhysicalCountInt(); when TimeStamp_Virtual => return PhysicalCountInt() - CNTVOFF_EL2(); when TimeStamp_OffsetPhysical => let physoff : bits(64) = if PhysicalOffsetIsValid() then CNTPOFF_EL2() else Zeros{64}; return PhysicalCountInt() - physoff; when TimeStamp_None => return Zeros{64}; when TimeStamp_CoreSight => return ImpDefBits{64}("CoreSight timestamp"); otherwise => unreachable; end; end;
## Library pseudocode for shared/trace/Common/PhysicalOffsetIsValid
// PhysicalOffsetIsValid // ======================= // Returns whether the Physical offset for the timestamp is valid
func PhysicalOffsetIsValid() => boolean begin if () then return FALSE; elsif (EL2) || !IsFeatureImplemented(FEAT_ECV_POFF) then return FALSE; elsif HaveEL(EL3) && EffectiveSCR_EL3_NS() == '1' && EffectiveSCR_EL3_RW() == '0' then return FALSE; elsif HaveEL(EL3) && SCR_EL3().ECVEn == '0' then return FALSE; elsif CNTHCTL_EL2().ECV == '0' then return FALSE; else return TRUE; end; end;
## Library pseudocode for shared/trace/Common/TRBCRManStopWrite
// TRBCRManStopWrite // =================== // Called on a write of 1 to TRBCR.ManStop.
func TRBCRManStopWrite begin TraceUnitFlush(); OtherTRBEManagementEvent('000011'); TryAssertTRBIRQ(); end;
## Library pseudocode for shared/trace/TraceBranch/BranchNotTaken
// BranchNotTaken // ================ // Called when a branch is not taken.
func BranchNotTaken(branchtype : BranchType, branch_conditional : boolean) begin let branchtaken : boolean = FALSE; if IsFeatureImplemented(FEAT_SPE) then SPEBranch{64}(ARBITRARY : bits(64), branchtype, branch_conditional, branchtaken); end; return; end;
## Library pseudocode for
shared/trace/TraceBuffer/AllowExternalTraceBufferAccess
// AllowExternalTraceBufferAccess // ================================ // Returns TRUE if an external debug interface access to the Trace Buffer // registers is allowed for the given Security state, FALSE otherwise. // The access may also be subject to OS Lock, power-down, etc.
func AllowExternalTraceBufferAccess(addrdesc : AddressDescriptor) => boolean begin assert IsFeatureImplemented(FEAT_TRBE_EXT); // FEAT_Debugv8p4 is always implemented when FEAT_TRBE_EXT is implemented. assert IsFeatureImplemented(FEAT_Debugv8p4);
var etbad : bits(2) = if HaveEL(EL3) then MDCR_EL3().ETBAD else
'11';
// Check for reserved values
if !IsFeatureImplemented(FEAT_RME) && etbad IN {'01','10'} then
(-, etbad) = ConstrainUnpredictableBits{2}(Unpredictable_RES_ETBAD);
// The value returned by ConstrainUnpredictableBits must be a
// non-reserved value
assert etbad IN {'00', '11'};
end;
case etbad of
when '00' =>
if IsFeatureImplemented(FEAT_RME) then
return addrdesc.paddress.paspace == PAS_Root;
else
return addrdesc.paddress.paspace == PAS_Secure;
end;
when '01' =>
assert IsFeatureImplemented(FEAT_RME);
return addrdesc.paddress.paspace IN {PAS_Root, PAS_Realm};
when '10' =>
assert IsFeatureImplemented(FEAT_RME);
return addrdesc.paddress.paspace IN {PAS_Root, PAS_Secure};
when '11' =>
return TRUE;
end;
end;
## Library pseudocode for shared/trace/TraceBuffer/CheckForTRBEException
// CheckForTRBEException // ======================= // Take a TRBE Profiling exception if pending, permitted, and unmasked.
func CheckForTRBEException begin if !IsFeatureImplemented(FEAT_TRBE_EXC) || () then return; end;
if Halted() || Restarting() then
return;
end;
var route_to_el3 : boolean = FALSE;
var route_to_el2 : boolean = FALSE;
var route_to_el1 : boolean = FALSE;
if HaveEL(EL3) && MDCR_EL3().TRBEE == '1x' then
let pending : boolean = TRBSR_EL3().IRQ == '1';
let masked : boolean = PSTATE.EL == EL3;
route_to_el3 = pending && !masked;
end;
var owning_ss : SecurityState;
var owning_el : bits(2);
(owning_ss, owning_el) = TraceBufferOwner();
let in_owning_ss : boolean = IsCurrentSecurityState(owning_ss);
if EffectiveTRFCR_EL2_EE() IN {'1x'} then
let pending : boolean = TRBSR_EL2().IRQ == '1';
let masked : boolean = (!in_owning_ss || PSTATE.EL == EL3 ||
(PSTATE.EL == EL2 && (TRFCR_EL2().EE != '11' ||
TRFCR_EL2().KE == '0' ||
PSTATE.PM == '1')));
route_to_el2 = pending && !masked;
end;
if EffectiveTRFCR_EL1_EE() == '11' then
let pending : boolean = TRBSR_EL1().IRQ == '1';
let masked : boolean = (!in_owning_ss || PSTATE.EL IN {EL3, EL2} ||
(PSTATE.EL == EL1 && (TRFCR_EL1().KE == '0' ||
PSTATE.PM == '1')));
if EffectiveTGE() == '1' then
route_to_el2 = route_to_el2 || (pending && !masked);
else
route_to_el1 = pending && !masked;
end;
end;
let fsc : bits(5) = '00010'; // TRBE exception
let synchronous : boolean = FALSE;
// The relative priorities of the following checks is IMPLEMENTATION DEFINED
if route_to_el3 then
TakeProfilingException(EL3, fsc, synchronous);
end;
if route_to_el2 then
TakeProfilingException(EL2, fsc, synchronous);
end;
if route_to_el1 then
TakeProfilingException(EL1, fsc, synchronous);
end;
end;
## Library pseudocode for shared/trace/TraceBuffer/CheckMDCR\_EL3\_NSTBTrap
// CheckMDCR_EL3_NSTBTrap // ======================== // Check if the register access is trappable by MDCR_EL3.[NSTBE, NSTB]
func CheckMDCR_EL3_NSTBTrap() => boolean begin var state_bits : bits(3); var reserved : boolean; (state_bits, reserved) = EffectiveMDCR_EL3_NSTB(); return ((reserved && ConstrainUnpredictableBool(Unpredictable_RESERVEDNSxB_Trap)) || state_bits[0] == '0' || state_bits[1] != EffectiveSCR_EL3_NS() || (IsFeatureImplemented(FEAT_RME) && state_bits[2] != EffectiveSCR_EL3_NSE())); end;
## Library pseudocode for shared/trace/TraceBuffer/CollectTrace
// CollectTrace // ============== // Called for each byte generated by the trace unit. // Returns TRUE if the Trace Buffer Unit accepts or discards the trace // data, and FALSE if the Trace Buffer Unit rejects the trace data.
func CollectTrace(datum : bits(8)) => boolean recurselimit ElementStreamSize begin if () then // Trace buffer disabled // 'datum' is discarded if HaveImpDefTraceOutput() then return ImpDefTraceOutput(datum); else return TRUE; // Discard the trace byte end; end;
// If the TRBE cannot accept the trace data, it must return FALSE
if TRBEInternalBufferFull() then
return FALSE;
end;
if TraceBufferRunning() then // Accept the data
let address : bits(64) = TRBPTR_EL1();
var ttw_abort : boolean = FALSE;
let ttw_abort_as_fault: boolean = ImpDefBool("Report TRBE ExtAbort on TTW as fault");
var addrdesc : AddressDescriptor;
var memstatus : PhysMemRetStatus;
if () then
// The Trace Buffer Unit is using External mode.
if IsFeatureImplemented(FEAT_RME) && () then
if IsZero(GPCCR_EL3().[TBGPCD, GPC]) then
return FALSE;
end;
end;
let pas : bits(2) = TRBMAR_EL1().PAS;
let paspace : PASpace = DecodePASpace('0', pas[1], pas[0]);
if (pas) || (paspace) then
OtherTRBEManagementEvent('000000');
TryAssertTRBIRQ();
return TRUE;
end;
if IsFeatureImplemented(FEAT_TRBE_MPAM) && TRBMPAM_EL1().EN == '1' then
let mpam_sp : bits(2) = TRBMPAM_EL1().MPAM_SP;
let mpam_pas : PASpace = DecodePASpace('0', mpam_sp[1], mpam_sp[0]);
if (mpam_pas) then
OtherTRBEManagementEvent('000000');
TryAssertTRBIRQ();
return TRUE;
end;
end;
let el : bits(2) = ARBITRARY : bits(2);
let ss : SecurityState = ARBITRARY : SecurityState;
let accdesc : AccessDescriptor = CreateAccDescTRBE(ss, el);
var pa : FullAddress;
pa.address = address[NUM_PABITS-1:0];
pa.paspace = paspace;
let memattrs : MemoryAttributes = S1DecodeMemAttrs(TRBMAR_EL1().Attr,
TRBMAR_EL1().SH, TRUE);
addrdesc = CreateAddressDescriptor(pa, memattrs, accdesc);
addrdesc.mecid = DEFAULT_MECID;
let oamax : AddressSize = AArch64_OAMax();
if !IsZero(address[63:oamax]) then
if ConstrainUnpredictableBool(Unpredictable_TRBPTR_Fault_AddressSize) then
addrdesc.fault.statuscode = Fault_AddressSize;
else
pa.address = ZeroExtend{NUM_PABITS}(pa.address[oamax-1:0]);
end;
end;
------------------------------------------------------------------------------
Page 1 of 1.
End of thread.