[Writeup] Shared pseudocode: part 8 of 36 ========================================= Section: Silicon & Architectures Started: 2026-11-28 17:44 UTC by admin Replies: 0, last post 2026-11-28 17:44 UTC Page: 1 of 1 Web: https://romdump.net/t/100 ------------------------------------------------------------------------------ #120 admin, 2026-11-28 17:44 UTC [OP] Source: https://romdump.net/raw/120
Shared pseudocode from the offline Arm documentation snapshot. Part 8 of 36.
return (is_rejected_event, is_rejected_nevent);
end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPEFilterByLatency
// SPEFilterByLatency // ==================== // Carries out filtering by latency.
func SPEFilterByLatency(total_latency : integer) => boolean begin
let is_lat : boolean = (total_latency >=
UInt(PMSLATFR_EL1().MINLAT));
if is_lat then PMUEvent(PMU_EVENT_SAMPLE_FEED_LAT); end;
var is_rejected_latency : boolean = FALSE;
if PMSFCR_EL1().FL == '1' then
// Filtering by latency is enabled
if !IsZero(PMSLATFR_EL1().MINLAT) then
// Not a CONSTRAINED UNPREDICTABLE case
is_rejected_latency = is_rejected_latency || !is_lat;
else
is_rejected_latency = ConstrainUnpredictableBool(Unpredictable_BADPMSFCR);
end;
end;
return is_rejected_latency;
end;
## Library pseudocode for aarch64/debug/statisticalprofiling/SPEFilterByType
// SPEFilterByType // ================= // Returns TRUE if the operation is to be discarded because of its OpAttrs, and FALSE otherwise.
func SPEFilterByType(opattr : SPEOpAttr) => boolean begin // Bit positions in the PMSFCR_EL1().[TYPE, TYPEm] fields let B : integer = 0; let LD : integer = 1; let ST : integer = 2; let FP : integer = 3; let SIMD : integer = 4;
var flags : bits(5) = Zeros{};
var ctrl : bits(5) = Zeros{};
// With GCS, Branch Link and Procedure Return instructions write and read the
GCS.
// BL and RET instructions with GCS enabled call SPESampleLoadStore() before
// branch/packet construction, setting ldst_type to indicate a GCS access.
let is_gcs_ldst : boolean = (opattr.op_type == SPEOpType_Branch &&
opattr.ldst_type == SPELDSTType_GCS);
let is_load : boolean = (opattr.op_type IN {SPEOpType_Load,
SPEOpType_LoadAtomic} ||
(is_gcs_ldst && opattr.procedure_return));
let is_store : boolean = (opattr.op_type IN {SPEOpType_Store,
SPEOpType_LoadAtomic} ||
(is_gcs_ldst && opattr.branch_has_link));
flags** = (if opattr.op_type == SPEOpType_Branch then '1' else '0');
flags[LD] = (if is_load then '1' else '0');
flags[ST] = (if is_store then '1' else '0');
flags[FP] = (if opattr.is_floating_point then '1' else '0');
flags[SIMD] = (if opattr.is_simd then '1' else '0');
ctrl[2:0] = PMSFCR_EL1().TYPE[2:0];
var mask : bits(5) = Zeros{};
if IsFeatureImplemented(FEAT_SPE_EFT) then
ctrl[4:3] = PMSFCR_EL1().TYPE[4:3];
mask[4:0] = PMSFCR_EL1().TYPEm;
end;
let ctrl_or : bits(5) = (ctrl AND (NOT mask));
let ctrl_and : bits(5) = (ctrl AND mask);
let is_op : boolean = ((IsZero(ctrl_or) || !IsZero(flags AND ctrl_or))
&&
((flags AND mask) == ctrl_and));
if flags** == '1' then PMUEvent(PMU_EVENT_SAMPLE_FEED_BR); end;
if flags[LD] == '1' then PMUEvent(PMU_EVENT_SAMPLE_FEED_LD); end;
if flags[ST] == '1' then PMUEvent(PMU_EVENT_SAMPLE_FEED_ST); end;
if flags[FP] == '1' then PMUEvent(PMU_EVENT_SAMPLE_FEED_FP); end;
if flags[SIMD] == '1' then PMUEvent(PMU_EVENT_SAMPLE_FEED_SIMD); end;
var is_rejected_type : boolean = FALSE;
if PMSFCR_EL1().FT == '1' then
// Filtering by type is enabled
if IsFeatureImplemented(FEAT_SPE_EFT) || !IsZero(ctrl) then
is_rejected_type = !is_op;
else
is_rejected_type = ConstrainUnpredictableBool(Unpredictable_BADPMSFCR);
end;
end;
if is_op && (!IsZero(ctrl) || !IsZero(mask)) then
PMUEvent(PMU_EVENT_SAMPLE_FEED_OP); end;
return is_rejected_type;
end;
## Library pseudocode for aarch64/debug/statisticalprofiling/SPEFreezeOnEvent
// SPEFreezeOnEvent // ================== // Returns TRUE if PMU event counter idx should be frozen due to an SPE event, and FALSE otherwise.
func SPEFreezeOnEvent(idx : integer) => boolean begin let counters : integer = NUM_PMU_COUNTERS; assert (idx >= 0 && (idx < counters || idx == CYCLE_COUNTER_ID || (idx == INSTRUCTION_COUNTER_ID && IsFeatureImplemented(FEAT_PMUv3_ICNTR))));
if !IsFeatureImplemented(FEAT_SPEv1p2) ||
!IsFeatureImplemented(FEAT_PMUv3p7) then
return FALSE;
end;
if idx == CYCLE_COUNTER_ID && !IsFeatureImplemented(FEAT_SPE_DPFZS)
then
// FZS does not affect the cycle counter when FEAT_SPE_DPFZS is not implemented
return FALSE;
end;
let freeze_on_event : boolean = PMBLIMITR_EL1().[E,PMFZ] == '11';
let stopped : boolean = SPEProfilingStopped();
case GetPMUCounterRange(idx) of
when PMUCounterRange_R1 =>
return freeze_on_event && stopped && PMCR_EL0().FZS == '1';
when PMUCounterRange_R2 =>
return freeze_on_event && stopped && MDCR_EL2().HPMFZS == '1';
otherwise =>
return FALSE;
end;
end;
## Library pseudocode for aarch64/debug/statisticalprofiling/SPEGetDataSource
// SPEGetDataSource // ================== // Returns a tuple indicating the data source for an access passed to SPESampleLoadStore, and // whether the data source is valid.
impdef func SPEGetDataSource(is_load : boolean, accdesc : AccessDescriptor, addrdesc : AddressDescriptor) => (boolean, bits(16)) begin return (TRUE, Zeros{16}); end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPEGetDataSourcePayloadSize
// SPEGetDataSourcePayloadSize // ============================= // Returns the size of the Data Source payload in bytes.
func SPEGetDataSourcePayloadSize() => integer{1..2} begin return ImpDefInt("SPE Data Source packet payload size") as integer{1..2}; end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPEGetEventsPayloadSize
// SPEGetEventsPayloadSize // ========================= // Returns the size in bytes of the Events packet payload as an integer.
func SPEGetEventsPayloadSize() => integer{1..4} begin return ImpDefInt("SPE Events packet payload size") as integer{1..4}; end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPEGetRandomBoolean
// SPEGetRandomBoolean // ===================== // Returns a random or pseudo-random boolean value.
impdef func SPEGetRandomBoolean() => boolean begin return SPEGetRandomInterval()[0] == '1'; end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPEGetRandomInterval
// SPEGetRandomInterval // ====================== // Returns a random or pseudo-random byte for resetting COUNT or ECOUNT.
impdef func SPEGetRandomInterval() => bits(8) begin return _PC[0+:8]; end;
## Library pseudocode for aarch64/debug/statisticalprofiling/SPEISB
// SPEISB // ======== // Called by ISB instruction, correctly calls SPEBranch to save previous branches.
func SPEISB begin let address : bits(64) = PC64() + 4; let branch_type : BranchType = BranchType_DIR; let branch_conditional : boolean = FALSE; let taken : boolean = FALSE; let is_isb : boolean = TRUE;
SPEBranch{64}(address, branch_type, branch_conditional, taken,
is_isb);
end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPEInterruptEnabled
// SPEInterruptEnabled // ===================== // Return TRUE if the SPE interrupt request (PMBIRQ) is enabled, FALSE otherwise.
func SPEInterruptEnabled() => boolean begin return EffectivePMSCR_EL1_EE() == '00'; end;
## Library pseudocode for aarch64/debug/statisticalprofiling/SPELDSTType
// SPELDSTType // =========== // Type of a load or store operation.
type SPELDSTType of enumeration { SPELDSTType_NV2, SPELDSTType_Extended, SPELDSTType_General, SPELDSTType_SIMDFP, SPELDSTType_SVESME, SPELDSTType_Tags, SPELDSTType_MemCopy, SPELDSTType_MemSet, SPELDSTType_GCS, SPELDSTType_GCSSS2, SPELDSTType_Unspecified };
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPEMultiAccessSample
// SPEMultiAccessSample // ====================== // Called by instructions which make at least one store and one load access, where the configuration // of the operation type filter affects which access is sampled.
func SPEMultiAccessSample() => boolean begin // If loads or stores are filtered out, the other should be recorded. // If neither or both are filtered out, pick one in an unbiased way.
// Are loads allowed by filter?
let loads_pass_filter : boolean = PMSFCR_EL1().FT == '1' &&
PMSFCR_EL1().TYPE.LD == '1';
// Are stores allowed by filter?
let stores_pass_filter : boolean = PMSFCR_EL1().FT == '1' &&
PMSFCR_EL1().TYPE.ST == '1';
var record_load : boolean;
if loads_pass_filter && !stores_pass_filter then
// Only loads pass filter
record_load = TRUE;
elsif !loads_pass_filter && stores_pass_filter then
// Only stores pass filter
record_load = FALSE;
else
// Both loads and stores pass the filter or neither pass the filter.
// Pick between the load or the store access (pseudo-)randomly.
record_load = SPEGetRandomBoolean();
end;
return record_load;
end;
## Library pseudocode for aarch64/debug/statisticalprofiling/SPEOpAttr
// SPEOpAttr // ========= // Attributes of sampled operation filtered by SPECollectRecord().
type SPEOpAttr of record { op_type : SPEOpType, ldst_type : SPELDSTType, branch_is_direct : boolean, branch_has_link : boolean, procedure_return : boolean, is_conditional : boolean, is_floating_point : boolean, is_simd : boolean, cond_pass : boolean, at : boolean, is_acquire_release : boolean, is_predicated : boolean, evl : bits(3), is_gather_scatter : boolean, is_exclusive : boolean, ets : bits(4), addr_valid : boolean };
## Library pseudocode for aarch64/debug/statisticalprofiling/SPEOpType
// SPEOpType // ========= // Types of operation filtered by SPECollectRecord().
type SPEOpType of enumeration { SPEOpType_Load, // Any memory-read operation other than atomics, compare-and-swap, // and swap SPEOpType_Store, // Any memory-write operation, including atomics without return SPEOpType_LoadAtomic, // Atomics with return, compare-and-swap and swap SPEOpType_Branch, // Software write to the PC SPEOpType_OtherSVE, // Other SVE operation SPEOpType_OtherSME, // Other SME operation SPEOpType_Other, // Any other class of operation SPEOpType_Invalid };
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPEProfilingStopped
// SPEProfilingStopped // =====================
readonly func SPEProfilingStopped() => boolean begin var stopped : boolean = (PMBSR_EL1().S == '1'); if IsFeatureImplemented(FEAT_SPE_EXC) then if HaveEL(EL3) && MDCR_EL3().PMSEE == '1x' then stopped = stopped || (PMBSR_EL3().S == '1'); end; if EffectivePMSCR_EL2_EE() == '1x' then stopped = stopped || (PMBSR_EL2().S == '1'); end; end; return stopped; end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPEResetSampleCounter
// SPEResetSampleCounter // ======================= // Reset PMSICR_EL1.Counter
func SPEResetSampleCounter begin PMSICR_EL1().COUNT[31:8] = PMSIRR_EL1().INTERVAL; if PMSIRR_EL1().RND == '1' && !IsFeatureImplemented(FEAT_SPE_ERnd) then PMSICR_EL1().COUNT[7:0] = SPEGetRandomInterval(); else PMSICR_EL1().COUNT[7:0] = Zeros{8}; end; end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPEResetSampleStorage
// SPEResetSampleStorage // ======================= // Reset all variables inside sample storage.
func SPEResetSampleStorage begin // Context values SPESampleContextEL1 = Zeros{32}; SPESampleContextEL1Valid = FALSE; SPESampleContextEL2 = Zeros{32}; SPESampleContextEL2Valid = FALSE;
// Counter values
for i = 0 to (SPEMaxCounters - 1) do
SPESampleCounter
= 0; SPESampleCounterValid
= FALSE; SPESampleCounterPending
= FALSE; end;
// Address values for i = 0 to (SPEMaxAddrs - 1) do SPESampleAddressValid
= FALSE; SPESampleAddress
= Zeros{64}; end;
// Data source values SPESampleDataSource = Zeros{16}; SPESampleDataSourceValid = FALSE;
// Timestamp values SPESampleTimestamp = Zeros{64}; SPESampleTimestampValid = FALSE;
// Event values SPESampleEvents = Zeros{64};
// Operation attributes SPESampleOpAttr.op_type = SPEOpType_Invalid; SPESampleOpAttr.ldst_type = SPELDSTType_Unspecified; SPESampleOpAttr.branch_is_direct = FALSE; SPESampleOpAttr.branch_has_link = FALSE; SPESampleOpAttr.procedure_return = FALSE; SPESampleOpAttr.is_conditional = FALSE; SPESampleOpAttr.is_floating_point = FALSE; SPESampleOpAttr.is_simd = FALSE; SPESampleOpAttr.cond_pass = FALSE; SPESampleOpAttr.at = FALSE; SPESampleOpAttr.is_acquire_release = FALSE; SPESampleOpAttr.is_exclusive = FALSE; SPESampleOpAttr.is_predicated = FALSE; SPESampleOpAttr.evl = '000'; SPESampleOpAttr.is_gather_scatter = FALSE; SPESampleOpAttr.addr_valid = FALSE; end;
var SPERecordData : array [[SPEMaxRecordSize]] of bits(8); var SPERecordSize : integer;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPESampleAddAddressPCVirtual
// SPESampleAddAddressPCVirtual // ============================== // Save the current PC address to sample storage.
func SPESampleAddAddressPCVirtual begin var ns : bit; var nse : bit; case CurrentSecurityState() of when SS_Secure => ns = '0'; nse = '0'; when SS_NonSecure => ns = '1'; nse = '0'; when SS_Realm => ns = '1'; nse = '1'; otherwise => unreachable; end; let el : bits(2) = PSTATE.EL;
let pc : bits(64) = ThisInstrAddr{}();
SPESampleAddress[[SPEAddrPosPCVirtual]][55:0] = pc[55:0];
SPESampleAddress[[SPEAddrPosPCVirtual]][63:56] = ns::el::nse::Zeros{4};
SPESampleAddressValid[[SPEAddrPosPCVirtual]] = TRUE;
end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPESampleAddContext
// SPESampleAddContext // ===================== // Save contexts to sample storage if appropriate.
func SPESampleAddContext begin if CollectContextIDR1() then SPESampleContextEL1 = CONTEXTIDR_EL1()[31:0]; SPESampleContextEL1Valid = TRUE; end; if CollectContextIDR2() then SPESampleContextEL2 = CONTEXTIDR_EL2()[31:0]; SPESampleContextEL2Valid = TRUE; end; end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPESampleAddTimeStamp
// SPESampleAddTimeStamp // ======================= // Save the appropriate type of timestamp to sample storage.
func SPESampleAddTimeStamp begin let timestamp : TimeStamp = CollectTimeStamp(); case timestamp of when TimeStamp_None => SPESampleTimestampValid = FALSE; otherwise => SPESampleTimestampValid = TRUE; SPESampleTimestamp = GetTimestamp(timestamp); end; end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPESampleCollision
// SPESampleCollision // ==================== // Called when there is an SPE sample collision.
func SPESampleCollision begin // Sample collision with the previous sample PMUEvent(PMU_EVENT_SAMPLE_COLLISION); let target_el : bits(2) = DefaultSPEEvent(); PMBSR_EL(target_el).COLL = '1'; end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPESampleExtendedLoadStore
// SPESampleExtendedLoadStore // ============================ // Sets the subclass of the operation type packet for // extended load/store operations.
func SPESampleExtendedLoadStore(ar : boolean, excl : boolean, at : boolean, is_load : boolean) begin SPESampleOpAttr.is_acquire_release = ar; SPESampleOpAttr.is_exclusive = excl; SPESampleOpAttr.ldst_type = SPELDSTType_Extended; SPESampleOpAttr.at = at; if is_load then if at then SPESampleOpAttr.op_type = SPEOpType_LoadAtomic; else SPESampleOpAttr.op_type = SPEOpType_Load; end; else SPESampleOpAttr.op_type = SPEOpType_Store; end; end;
## Library pseudocode for aarch64/debug/statisticalprofiling/SPESampleGCSSS2
// SPESampleGCSSS2 // ================= // Sets the subclass of the operation type packet for GCSSS2 load/store operations.
func SPESampleGCSSS2 begin // GCSSS2 does a read and a write. let record_load : boolean = SPEMultiAccessSample(); SPESampleOpAttr.op_type = if record_load then SPEOpType_Load else SPEOpType_Store; SPESampleOpAttr.ldst_type = SPELDSTType_GCSSS2; end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPESampleGeneralPurposeLoadStore
// SPESampleGeneralPurposeLoadStore // ================================== // Sets the subclass of the operation type packet for general // purpose load/store operations.
func SPESampleGeneralPurposeLoadStore(is_load : boolean) begin SPESampleOpAttr.ldst_type = SPELDSTType_General; SPESampleOpAttr.op_type = if is_load then SPEOpType_Load else SPEOpType_Store; end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPESampleLoadStore
// SPESampleLoadStore // ==================== // Called if a sample is in flight when writing or reading memory, // indicating that the operation being sampled is in the Load, Store or atomic category.
func SPESampleLoadStore(is_load : boolean, accdesc : AccessDescriptor, addrdesc : AddressDescriptor) begin // Check if this access type is suitable to be sampled. // This implementation of SPE always samples the first access made by a suitable instruction. // FEAT_MOPS instructions are an exception, where the first load or first store access may be // selected based on the configuration of the sample filters. if accdesc.acctype IN {AccessType_SPE, AccessType_IFETCH, AccessType_TRBE, AccessType_DC, AccessType_TTW, AccessType_AT} then return; end;
var sample_access : boolean = FALSE;
// For FEAT_MOPS and FEAT_GCS GCSSS2 instructions which perform both loads and
stores, the
// filter configuration will influence which part of the access is chosen to
be sampled.
if (SPESampleOpAttr.ldst_type IN
{SPELDSTType_MemCopy, SPELDSTType_MemSet, SPELDSTType_GCSSS2}) then
// SPEMultiAccessSample() will have been called before this function,
// and chooses whether to sample a load or a store.
var sample_load : boolean;
sample_load = SPESampleOpAttr.op_type IN {SPEOpType_Load, SPEOpType_LoadAtomic};
// If no valid data has been collected, and this operation is acceptable for sampling.
if .addr_valid && (is_load == sample_load) then
sample_access = TRUE;
end;
else
if .addr_valid then
sample_access = TRUE;
end;
end;
if sample_access then
// Data access virtual address
SPESetDataVirtualAddress(addrdesc.vaddress);
// Data access physical address
if CollectPhysicalAddress() then
SPESetDataPhysicalAddress(addrdesc, accdesc);
end;
SPESampleOpAttr.addr_valid = TRUE;
end;
if SPESampleOpAttr.op_type == SPEOpType_Invalid then
// Set as unspecified load/store by default, instructions will overwrite this if it does not
// apply to them.
SPESampleOpAttr.op_type = if is_load then SPEOpType_Load else SPEOpType_Store;
if accdesc.acctype == AccessType_NV2 then
// NV2 register load/store
SPESampleOpAttr.ldst_type = SPELDSTType_NV2;
end;
end;
// Set SPELDSTType to GCS for all GCS instruction, overwriting type GCSSS2.
// After selection of which operation of a GCSSS2 instruction to sample,
GCSSS2 is treated the
// same as other GCS instructions.
if accdesc.acctype == AccessType_GCS then
SPESampleOpAttr.ldst_type = SPELDSTType_GCS;
// If the GCS access is from a BL or RET, this will get overwritten to SPEOpType_Branch.
SPESampleOpAttr.op_type = if is_load then SPEOpType_Load else SPEOpType_Store;
end;
(SPESampleDataSourceValid, SPESampleDataSource) = SPEGetDataSource(is_load,
accdesc, addrdesc);
end;
## Library pseudocode for aarch64/debug/statisticalprofiling/SPESampleMemCopy
// SPESampleMemCopy // ================== // Sets the subclass of the operation type packet for Memory Copy load/store // operations.
func SPESampleMemCopy begin // MemCopy does a read and a write. let record_load : boolean = SPEMultiAccessSample(); SPESampleOpAttr.op_type = if record_load then SPEOpType_Load else SPEOpType_Store; SPESampleOpAttr.ldst_type = SPELDSTType_MemCopy; end;
## Library pseudocode for aarch64/debug/statisticalprofiling/SPESampleMemSet
// SPESampleMemSet // ================= // Callback used by memory set instructions to pass data back to the SPU.
func SPESampleMemSet begin SPESampleOpAttr.op_type = SPEOpType_Store; SPESampleOpAttr.ldst_type = SPELDSTType_MemSet; end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPESampleOnSharedResource
// SPESampleOnSharedResource // =========================== // Called when the sampled instruction is executed on an SMCU or other shared resource, sets bit 25 // of the events packet to 0b1. func SPESampleOnSharedResource begin SPESampleEvents[25] = '1'; end;
## Library pseudocode for aarch64/debug/statisticalprofiling/SPESampleOpOther
// SPESampleOpOther // ================== // Add other operation to sample storage.
func SPESampleOpOther(conditional : boolean, cond_pass : boolean, is_fp : boolean, is_simd : boolean) begin SPESampleOpAttr.is_simd = is_simd; SPESampleOpOther(conditional, cond_pass, is_fp); end;
func SPESampleOpOther(conditional : boolean, cond_pass : boolean, is_fp : boolean) begin SPESampleOpAttr.cond_pass = cond_pass; SPESampleOpAttr.is_floating_point = is_fp; SPESampleOpOther(conditional); end;
func SPESampleOpOther(conditional : boolean) begin SPESampleOpAttr.is_conditional = conditional; SPESampleOpAttr.op_type = SPEOpType_Other; end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPESampleOpSMEArrayOther
// SPESampleOpSMEArrayOther // ========================== // Sets the subclass of the operation type packet to Other, SME array.
func SPESampleOpSMEArrayOther(floating_point : boolean, size : integer) begin // If the sampled effective vector or tile size is not a power of two, or is less than 128 bits, // the value is rounded up before it is encoded in the ets field.
SPESampleOpAttr.is_floating_point = floating_point;
SPESampleOpAttr.ets = SPEEncodeETS(size);
SPESampleOpAttr.op_type = SPEOpType_OtherSME;
SPESampleOpAttr.is_simd = TRUE;
end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPESampleOpSVEOther
// SPESampleOpSVEOther // ===================== // Callback used by SVE, Other operations to pass data back to the SPU.
func SPESampleOpSVEOther(vl : integer, predicated : boolean, floating_point : boolean) begin SPESampleOpAttr.is_predicated = predicated; SPESampleOpAttr.is_floating_point = floating_point; SPESampleOpAttr.evl = SPEEncodeEVL(vl); SPESampleOpAttr.op_type = SPEOpType_OtherSVE; end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPESampleOpSVESMELoadStore
// SPESampleOpSVESMELoadStore // ============================ // Callback used by SVE or SME loads and stores to pass data to SPE.
func SPESampleOpSVESMELoadStore(is_gather_scatter : boolean, vl : integer, predicated : boolean, is_load : boolean) begin SPESampleOpAttr.is_gather_scatter = is_gather_scatter; SPESampleOpAttr.is_predicated = predicated; SPESampleOpAttr.evl = SPEEncodeEVL(vl); assert SPESampleOpAttr.evl != '111'; SPESampleOpAttr.op_type = if is_load then SPEOpType_Load else SPEOpType_Store; SPESampleOpAttr.ldst_type = SPELDSTType_SVESME; end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPESampleSIMDFPLoadStore
// SPESampleSIMDFPLoadStore // ========================== // Sets the subclass of the operation type packet for SIMD & FP // load store operations.
func SPESampleSIMDFPLoadStore(is_load : boolean, scalar : boolean) begin SPESampleOpAttr.ldst_type = SPELDSTType_SIMDFP; SPESampleOpAttr.op_type = if is_load then SPEOpType_Load else SPEOpType_Store; SPESampleOpAttr.is_simd = !scalar; // Scalar operations in SIMD&FP are treated as floating point. SPESampleOpAttr.is_floating_point = scalar; end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPESetDataPhysicalAddress
// SPESetDataPhysicalAddress // =========================== // Called from SampleLoadStore() to save data physical packet.
func SPESetDataPhysicalAddress(addrdesc : AddressDescriptor, accdesc : AccessDescriptor) begin var ns : bit; var nse : bit; var ch : bit; var lat : bits(4); case addrdesc.paddress.paspace of when PAS_Secure => ns = '0'; nse = '0'; when PAS_NonSecure => ns = '1'; nse = '0'; when PAS_Realm => ns = '1'; nse = '1'; otherwise => unreachable; end;
if IsFeatureImplemented(FEAT_MTE2) then
if accdesc.tagchecked then
ch = '1';
lat = AArch64_LogicalAddressTag(addrdesc.vaddress);
else
ch = '0';
// If the access is Unchecked, this is an IMPLEMENTATION_DEFINED choice
// between 0b0000 and the Logical Address Tag
var zero_unchecked : boolean;
zero_unchecked = ImpDefBool("SPE PAT for tag unchecked access zero");
if !zero_unchecked then
lat = AArch64_LogicalAddressTag(addrdesc.vaddress);
else
lat = Zeros{4};
end;
end;
else
ch = '0';
lat = '0000';
end;
let paddr : bits(NUM_PABITS) = addrdesc.paddress.address;
SPESampleAddress[[SPEAddrPosDataPhysical]][55:0] = ZeroExtend{56}(paddr);
SPESampleAddress[[SPEAddrPosDataPhysical]][63:56] = ns::ch::'0'::nse::lat;
SPESampleAddressValid[[SPEAddrPosDataPhysical]] = TRUE;
end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPESetDataVirtualAddress
// SPESetDataVirtualAddress // ========================== // Called from SampleLoadStore() to save data virtual packet. // Also used by exclusive load/stores to save virtual addresses if exclusive monitor is lost // before a read/write is completed.
func SPESetDataVirtualAddress(vaddress : bits(64)) begin var tbi : bit; tbi = EffectiveTBI(vaddress, FALSE, PSTATE.EL); var non_tbi_is_zeros : boolean; non_tbi_is_zeros = ImpDefBool("SPE non-tbi tag is zero"); if tbi == '1' || !non_tbi_is_zeros then SPESampleAddress[[SPEAddrPosDataVirtual]][63:0] = vaddress[63:0]; else SPESampleAddress[[SPEAddrPosDataVirtual]][55:0] = vaddress[55:0]; SPESampleAddress[[SPEAddrPosDataVirtual]][63:56] = Zeros{8}; end; SPESampleAddressValid[[SPEAddrPosDataVirtual]] = TRUE; end;
## Library pseudocode for aarch64/debug/statisticalprofiling/SPEStartCounter
// SPEStartCounter // ================= // Enables incrementing of the counter at the passed index when SPECycle is called.
func SPEStartCounter(counter_index : integer) begin assert counter_index < SPEMaxCounters; SPESampleCounterPending[[counter_index]] = TRUE; end;
## Library pseudocode for aarch64/debug/statisticalprofiling/SPEStartSample
// SPEStartSample // ================ // Called to start the sampling process. Returns TRUE if a new sample is to be collected, and // FALSE otherwise.
func SPEStartSample() => boolean begin if () then return FALSE; end; PMUEvent(PMU_EVENT_SAMPLE_POP); if () then return FALSE; end;
if SPESampleInFlight then
SPESampleCollision();
return FALSE;
end;
SPESampleInFlight = TRUE;
SPEStartCounter(SPECounterPosTotalLatency);
SPEStartCounter(SPECounterPosIssueLatency);
SPESampleAddAddressPCVirtual();
// Many operations are type other and not conditional, can save footprint
// and overhead by having this as the default and not calling SPESampleOpOther
// if conditional == FALSE
SPESampleOpOther(FALSE);
SPESampleAddContext();
// Timestamp may be collected at any point in the sampling operation.
// Collecting prior to execution is one possible choice.
// This choice is IMPLEMENTATION DEFINED.
SPESampleAddTimeStamp();
return TRUE;
end;
## Library pseudocode for aarch64/debug/statisticalprofiling/SPEStopCounter
// SPEStopCounter // ================ // Disables incrementing of the counter at the passed index when SPECycle is called.
func SPEStopCounter(counter_index : integer) begin SPESampleCounterValid[[counter_index]] = TRUE; SPESampleCounterPending[[counter_index]] = FALSE; end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/SPEToCollectSample
// SPEToCollectSample // ==================== // Returns TRUE if the instruction which is about the executed should be sampled, and FALSE // otherwise.
func SPEToCollectSample() => boolean begin if IsZero(PMSICR_EL1().COUNT) then SPEResetSampleCounter(); else PMSICR_EL1().COUNT = PMSICR_EL1().COUNT - 1; if IsZero(PMSICR_EL1().COUNT) then if PMSIRR_EL1().RND == '1' && IsFeatureImplemented(FEAT_SPE_ERnd) then PMSICR_EL1().ECOUNT = SPEGetRandomInterval(); return IsZero(PMSICR_EL1().ECOUNT); else return TRUE; end; end; end; if (PMSIRR_EL1().RND == '1' && IsFeatureImplemented(FEAT_SPE_ERnd) && !IsZero(PMSICR_EL1().ECOUNT)) then PMSICR_EL1().ECOUNT = PMSICR_EL1().ECOUNT - 1; if IsZero(PMSICR_EL1().ECOUNT) then return TRUE; end; end; return FALSE; end;
## Library pseudocode for aarch64/debug/statisticalprofiling/SPEWriteToBuffer
// SPEWriteToBuffer // ================== // Write the active record to the Profiling Buffer.
func SPEWriteToBuffer begin assert ProfilingBufferEnabled() && ();
// Check alignment
let align : integer{} = UInt(PMBIDR_EL1().Align);
let aligned : boolean = IsAlignedP2(PMBPTR_EL1().PTR, align);
let ttw_abort_as_fault : boolean = (ImpDefBool(
"Report SPE ExtAbort on TTW as fault"));
var owning_ss : SecurityState;
var owning_el : bits(2);
(owning_ss, owning_el) = ProfilingBufferOwner();
let accdesc : AccessDescriptor = CreateAccDescSPE(owning_ss, owning_el);
let start_vaddr : bits(64) = PMBPTR_EL1();
for i = 0 to SPERecordSize - 1 do
// If a previous write did not cause an issue
if () then
let address : bits(64) = PMBPTR_EL1();
var memstatus : PhysMemRetStatus;
var addrdesc : AddressDescriptor;
(memstatus, addrdesc) = DebugMemWrite(address, accdesc, aligned,
SPERecordData
);
let fault : FaultRecord = addrdesc.fault;
let ttw_abort : boolean = fault.statuscode IN {Fault_SyncExternalOnWalk,
Fault_SyncParityOnWalk};
if IsFault(fault.statuscode) && (!ttw_abort || ttw_abort_as_fault) then
DebugWriteFault(address, fault);
elsif IsFault(memstatus) || (ttw_abort && !ttw_abort_as_fault) then
DebugWriteExternalAbort(memstatus, addrdesc, start_vaddr);
end;
// Move pointer if no Buffer Management Event has been caused.
if () then
PMBPTR_EL1() = PMBPTR_EL1() + 1;
end;
end;
end; end;
## Library pseudocode for
aarch64/debug/statisticalprofiling/StatisticalProfilingEnabled
// StatisticalProfilingEnabled // ============================= // Return TRUE if Statistical Profiling is Enabled in the current EL, FALSE otherwise.
func StatisticalProfilingEnabled() => boolean begin return StatisticalProfilingEnabled(PSTATE.EL); end;
// StatisticalProfilingEnabled // ============================= // Return TRUE if Statistical Profiling is Enabled in the specified EL, FALSE otherwise.
func StatisticalProfilingEnabled(el : bits(2)) => boolean begin if (!IsFeatureImplemented(FEAT_SPE) || UsingAArch32() || () || SPEProfilingStopped() || Halted()) then return FALSE; end;
let tge_set : boolean = EL2Enabled() && HCR_EL2().TGE ==
'1';
let (owning_ss, owning_el) : (SecurityState, bits(2)) =
ProfilingBufferOwner();
if (UInt(owning_el) < UInt(el) || (tge_set && owning_el == EL1) ||
owning_ss != SecurityStateAtEL(el)) then
return FALSE;
end;
var spe_bit : bit;
case el of
when EL3 => unreachable;
when EL2 => spe_bit = PMSCR_EL2().E2SPE;
when EL1 => spe_bit = PMSCR_EL1().E1SPE;
when EL0 => spe_bit = (if tge_set then PMSCR_EL2().E0HSPE else PMSCR_EL1().E0SPE);
end;
return spe_bit == '1';
end;
## Library pseudocode for aarch64/debug/statisticalprofiling/TimeStamp
// TimeStamp // =========
type TimeStamp of enumeration { TimeStamp_None, // No timestamp TimeStamp_CoreSight, // CoreSight time (IMPLEMENTATION DEFINED) TimeStamp_Physical, // Physical counter value with no offset TimeStamp_OffsetPhysical, // Physical counter value minus CNTPOFF_EL2 TimeStamp_Virtual }; // Physical counter value minus CNTVOFF_EL2
## Library pseudocode for
aarch64/debug/takeexceptiondbg/AArch64\_TakeExceptionInDebugState
// AArch64_TakeExceptionInDebugState // =================================== // Take an exception in Debug state to an Exception level using AArch64.
noreturn func AArch64_TakeExceptionInDebugState(target_el : bits(2), exception_in : ExceptionRecord) begin assert HaveEL(target_el) && (target_el) && UInt(target_el) >= UInt(PSTATE.EL); assert target_el != EL3 || EDSCR().SDD == '0'; var except : ExceptionRecord = exception_in;
if !IsFeatureImplemented(FEAT_ExS) || SCTLR_EL(target_el).EIS ==
'1' then
// Synchronize the context, including Instruction Fetch Barrier effect
SynchronizeContext();
end;
// If coming from AArch32 state, the top parts of the X() registers might be
set to zero
let from_32 : boolean = UsingAArch32();
if from_32 then AArch64_MaybeZeroRegisterUppers(); end;
if from_32 && IsFeatureImplemented(FEAT_SME) && PSTATE.SM ==
'1' then
ResetSVEState();
else
MaybeZeroSVEUppers(target_el);
end;
AArch64_ReportException(except, target_el);
if IsFeatureImplemented(FEAT_GCS) then
PSTATE.EXLOCK = '0'; // Effective value of GCSCR_ELx.EXLOCKEN is 0 in Debug state
end;
PSTATE.EL = target_el;
PSTATE.nRW = '0';
PSTATE.SP = '1';
SPSR_ELx() = ARBITRARY : bits(64);
ELR_ELx() = ARBITRARY : bits(64);
// PSTATE.[SS,D,A,I,F] are not observable and ignored in Debug state, so
behave as if UNKNOWN.
PSTATE.[SS,D,A,I,F] = ARBITRARY : bits(5);
if IsFeatureImplemented(FEAT_SSBS) then PSTATE.SSBS = ARBITRARY : bit; end;
if (IsFeatureImplemented(FEAT_EBEP) || IsFeatureImplemented(FEAT_SPE_EXC) ||
IsFeatureImplemented(FEAT_TRBE_EXC)) then
PSTATE.PM = ARBITRARY : bit;
end;
if IsFeatureImplemented(FEAT_MTE) then PSTATE.TCO = '1'; end;
PSTATE.IL = '0';
if IsFeatureImplemented(FEAT_UAO) then PSTATE.UAO = '0'; end;
if IsFeatureImplemented(FEAT_UINJ) then PSTATE.UINJ = '0'; end;
if IsFeatureImplemented(FEAT_PAuth_LR) then PSTATE.PACM = '0'; end;
if (IsFeatureImplemented(FEAT_PAN) && (PSTATE.EL == EL1 ||
(PSTATE.EL == EL2 && ELIsInHost(EL0))) &&
SCTLR_ELx().SPAN == '0') then
PSTATE.PAN = '1';
end;
if from_32 then // Coming from AArch32
PSTATE.IT = '00000000';
PSTATE.T = '0'; // PSTATE.J is RES0
end;
if IsFeatureImplemented(FEAT_BTI) then PSTATE.BTYPE = '00'; end;
DLR_EL0() = ARBITRARY : bits(64);
DSPSR_EL0() = ARBITRARY : bits(64);
EDSCR().ERR = '1';
UpdateEDSCRFields(); // Update EDSCR PE state flags.
EndOfInstruction(EndOfInstructionReason_Exception);
end;
## Library pseudocode for
aarch64/debug/watchpoint/AArch64\_WatchpointByteMatch
// AArch64_WatchpointByteMatch // =============================
func AArch64_WatchpointByteMatch(n : integer, vaddress : bits(64)) => boolean begin let dbgtop : AddressSize = DebugAddrTop(); let cmpbottom : integer{} = if DBGWVR_EL1(n)[2] == '1' then 2 else 3;// Word or doubleword var bottom : integer{} = cmpbottom; let select : integer{} = UInt(vaddress[cmpbottom-1:0]); var byte_select_match : boolean = (DBGWCR_EL1(n).BAS[select] != '0'); var mask : integer{} = UInt(DBGWCR_EL1(n).MASK);
// If DBGWCR_EL1(n).MASK is a nonzero value and DBGWCR_EL1(n).BAS
is not set to '11111111', or
// DBGWCR_EL1(n).BAS specifies a non-contiguous set of bytes behavior is
CONSTRAINED
// UNPREDICTABLE.
if mask > 0 && !IsOnes(DBGWCR_EL1(n).BAS) then
byte_select_match = ConstrainUnpredictableBool(Unpredictable_WPMASKANDBAS);
else
let LSB : bits(8) = (DBGWCR_EL1(n).BAS AND NOT(DBGWCR_EL1(n).BAS - 1));
let MSB : bits(8) = (DBGWCR_EL1(n).BAS + LSB);
if !IsZero(MSB AND (MSB - 1)) then // Not contiguous
byte_select_match = ConstrainUnpredictableBool(Unpredictable_WPBASCONTIGUOUS);
bottom = 3; // For the whole doubleword
end;
end;
// If the address mask is set to a reserved value, the behavior is CONSTRAINED
UNPREDICTABLE.
if mask > 0 && mask <= 2 then
var c : Constraint;
var unpred_mask : integer;
(c, unpred_mask) = ConstrainUnpredictableInteger(3, 31, Unpredictable_RESWPMASK);
assert c IN {Constraint_DISABLED, Constraint_NONE, Constraint_UNKNOWN};
case c of
when Constraint_DISABLED => return FALSE; // Disabled
when Constraint_NONE => mask = 0; // No masking
// Otherwise the value returned by ConstrainUnpredictableInteger is a not-reserved value
otherwise => mask = unpred_mask as integer{3..31};
end;
end;
// When FEAT_LVA3 is not implemented, if the DBGWVR_EL1(n).RESS field bits are
not a
// sign extension of the MSB of DBGWVR_EL1(n).VA, it is UNPREDICTABLE whether
they
// appear to be included in the match.
let unpredictable_ress : boolean = (dbgtop < 55 &&
!IsOnes(DBGWVR_EL1(n)[63:dbgtop]) &&
!IsZero(DBGWVR_EL1(n)[63:dbgtop]) &&
ConstrainUnpredictableBool(Unpredictable_DBGxVR_RESS));
let cmpmsb : integer{} = if unpredictable_ress then 63 else dbgtop;
let cmplsb : integer{} = if mask > bottom then mask else bottom;
let bottombit : integer{} = bottom;
var WVR_match : boolean = (vaddress[cmpmsb:cmplsb] ==
DBGWVR_EL1(n)[cmpmsb:cmplsb]);
if mask > bottom then
// If masked bits of DBGWVR_EL1(n) are not zero, the behavior is CONSTRAINED UNPREDICTABLE.
if WVR_match && !IsZero(DBGWVR_EL1(n)[cmplsb-1:bottombit]) then
WVR_match = ConstrainUnpredictableBool(Unpredictable_WPMASKEDBITS);
end;
end;
return (WVR_match && byte_select_match);
end;
## Library pseudocode for aarch64/debug/watchpoint/AArch64\_WatchpointMatch
// AArch64_WatchpointMatch // ========================= // Watchpoint matching in an AArch64 translation regime.
func AArch64_WatchpointMatch(n : integer, vaddress : bits(64), size : integer, accdesc : AccessDescriptor) => WatchpointInfo begin assert (S1TranslationRegime()); assert n < NumWatchpointsImplemented();
let enabled : boolean = IsWatchpointEnabled(n);
let linked : boolean = DBGWCR_EL1(n).WT == '1';
let isbreakpnt : boolean = FALSE;
let lbnx : bits(2) = if IsFeatureImplemented(FEAT_Debugv8p9) then
DBGWCR_EL1(n).LBNX else '00';
let linked_n : integer{} = UInt(lbnx :: DBGWCR_EL1(n).LBN);
let ssce : bit = if IsFeatureImplemented(FEAT_RME) then DBGWCR_EL1(n).SSCE
else '0';
let mismatch : boolean = IsFeatureImplemented(FEAT_BWE2) &&
DBGWCR_EL1(n).WT2 == '1';
let state_match : boolean = AArch64_StateMatch(DBGWCR_EL1(n).SSC, ssce,
DBGWCR_EL1(n).HMC,
DBGWCR_EL1(n).PAC,
linked, linked_n, isbreakpnt, PC64(), accdesc);
var watchptinfo : WatchpointInfo;
var ls_match : boolean;
case DBGWCR_EL1(n).LSC[1:0] of
when '00' => ls_match = FALSE;
when '01' => ls_match = accdesc.read;
when '10' => ls_match = accdesc.write || accdesc.acctype == AccessType_DC;
when '11' => ls_match = TRUE;
end;
var value_match : boolean = FALSE;
watchptinfo.vaddress = vaddress;
for byte = 0 to size - 1 do
if (!value_match &&
(watchptinfo.vaddress, vaddress + byte)) then
// Watchpoint should report an address which is in
// the naturally aligned block of the matched address.
watchptinfo.vaddress = vaddress + byte;
end;
value_match = value_match || AArch64_WatchpointByteMatch(n, vaddress + byte);
end;
watchptinfo.watchpt_num = n;
watchptinfo.value_match = value_match;
if !(state_match && ls_match && enabled) then
watchptinfo.wptype = WatchpointType_Inactive;
watchptinfo.value_match = FALSE;
elsif mismatch then
watchptinfo.wptype = WatchpointType_AddrMismatch;
else
watchptinfo.wptype = WatchpointType_AddrMatch;
end;
return watchptinfo;
end;
## Library pseudocode for aarch64/debug/watchpoint/IsWatchpointEnabled
// IsWatchpointEnabled // ===================== // Returns TRUE if the effective value of DBGWCR_EL1(n).E is '1', and FALSE otherwise.
func IsWatchpointEnabled(n : integer) => boolean begin if (n > 15 && ((() && ()) || (HaltOnBreakpointOrWatchpoint() && EDSCR2().EHBWE == '0'))) then return FALSE; end; return DBGWCR_EL1(n).E == '1'; end;
## Library pseudocode for aarch64/exceptions/aborts/AArch64\_Abort
// AArch64_Abort // =============== // Abort and Debug exception handling in an AArch64 translation regime.
func AArch64_Abort(fault : FaultRecord) begin if IsDebugException(fault) then if fault.accessdesc.acctype == AccessType_IFETCH then if UsingAArch32() && fault.debugmoe == DebugException_VectorCatch then AArch64_VectorCatchException(fault); else AArch64_BreakpointException(fault); end; else AArch64_WatchpointException(fault); end; elsif fault.gpcf.gpf != GPCF_None && ReportAsGPCException(fault) then TakeGPCException(fault); elsif fault.statuscode == Fault_TagCheck then AArch64_RaiseTagCheckFault(fault); elsif IsExternalAbort(fault) && (fault) then PendSErrorInterrupt(fault); elsif fault.accessdesc.acctype == AccessType_IFETCH then AArch64_InstructionAbort(fault); else AArch64_DataAbort(fault); end; end;
## Library pseudocode for aarch64/exceptions/aborts/AArch64\_AbortSyndrome
// AArch64_AbortSyndrome // ======================= // Creates an exception syndrome record for Abort and Watchpoint exceptions // from an AArch64 translation regime.
func AArch64_AbortSyndrome(exceptype : Exception, fault : FaultRecord, target_el : bits(2)) => ExceptionRecord begin var except : ExceptionRecord = ExceptionSyndrome(exceptype);
except.syndrome = AArch64_FaultSyndrome(exceptype, fault,
target_el);
if exceptype IN {Exception_NV2Watchpoint, Exception_Watchpoint} then
except.vaddress = fault.watchptinfo.vaddress;
elsif fault.statuscode == Fault_TagCheck then
if IsFeatureImplemented(FEAT_MTE_TAGGED_FAR) then
except.vaddress = ZeroExtend{64}(fault.vaddress);
else
except.vaddress = ARBITRARY : bits(4) :: fault.vaddress[59:0];
end;
else
except.vaddress = ZeroExtend{64}(fault.vaddress);
end;
if IPAValid(fault) then
except.ipavalid = TRUE;
except.NS = if fault.ipaddress.paspace == PAS_NonSecure then '1' else '0';
except.ipaddress = fault.ipaddress.address;
else
except.ipavalid = FALSE;
end;
if except.syndrome.iss[24,14] == '01' then
except.pavalid = TRUE;
except.paddress = fault.paddress;
else
except.pavalid = FALSE;
except.paddress = ARBITRARY : FullAddress;
end;
return except;
end;
## Library pseudocode for aarch64/exceptions/aborts/AArch64\_CheckPCAlignment
// AArch64_CheckPCAlignment // ==========================
func AArch64_CheckPCAlignment begin let pc : bits(64) = ThisInstrAddr{}();
if pc[1:0] != '00' then
AArch64_PCAlignmentFault();
end;
end;
## Library pseudocode for aarch64/exceptions/aborts/AArch64\_DataAbort
// AArch64_DataAbort // ===================
func AArch64_DataAbort(fault : FaultRecord) begin var target_el : bits(2); if IsExternalAbort(fault) then target_el = SyncExternalAbortTarget(fault); else let route_to_el2 = (EL2Enabled() && PSTATE.EL IN {EL0, EL1} && (HCR_EL2().TGE == '1' || (IsFeatureImplemented(FEAT_RME) && fault.gpcf.gpf != GPCF_None && HCR_EL2().GPF == '1') || (IsFeatureImplemented(FEAT_NV2) && fault.accessdesc.acctype == AccessType_NV2) || IsSecondStage(fault)));
if PSTATE.EL == EL3 then
target_el = EL3;
elsif PSTATE.EL == EL2 || route_to_el2 then
target_el = EL2;
else
target_el = EL1;
end;
end;
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let route_to_serr : boolean = (IsExternalAbort(fault) &&
AArch64_RouteToSErrorOffset(target_el));
let vect_offset : integer = if route_to_serr then 0x180 else 0x0;
var except : ExceptionRecord;
if IsFeatureImplemented(FEAT_NV2) && fault.accessdesc.acctype ==
AccessType_NV2 then
except = AArch64_AbortSyndrome(Exception_NV2DataAbort, fault, target_el);
else
except = AArch64_AbortSyndrome(Exception_DataAbort, fault, target_el);
end;
AArch64_TakeException(target_el, except, preferred_exception_return,
vect_offset);
end;
## Library pseudocode for aarch64/exceptions/aborts/AArch64\_EffectiveTCF
// AArch64_EffectiveTCF // ====================== // Indicate if a Tag Check Fault should cause a synchronous exception, // be asynchronously accumulated, or have no effect on the PE.
func AArch64_EffectiveTCF(el : bits(2), read : boolean) => TCFType begin var tcf : bits(2);
let regime : Regime = TranslationRegime(el);
case regime of
when Regime_EL3 => tcf = SCTLR_EL3().TCF;
when Regime_EL2 => tcf = SCTLR_EL2().TCF;
when Regime_EL20 => tcf = if el == EL0 then SCTLR_EL2().TCF0 else SCTLR_EL2().TCF;
when Regime_EL10 => tcf = if el == EL0 then SCTLR_EL1().TCF0 else SCTLR_EL1().TCF;
otherwise => unreachable;
end;
if tcf == '11' then // Reserved value
if !IsFeatureImplemented(FEAT_MTE_ASYM_FAULT) then
(-,tcf) = ConstrainUnpredictableBits{2}(Unpredictable_RESTCF);
end;
end;
case tcf of
when '00' => // Tag Check Faults have no effect on the PE
return TCFType_Ignore;
when '01' => // Tag Check Faults cause a synchronous exception
return TCFType_Sync;
when '10' =>
if IsFeatureImplemented(FEAT_MTE_ASYNC) then
// If asynchronous faults are implemented,
// Tag Check Faults are asynchronously accumulated
return TCFType_Async;
else
// Otherwise, Tag Check Faults have no effect on the PE
return TCFType_Ignore;
end;
when '11' =>
if IsFeatureImplemented(FEAT_MTE_ASYM_FAULT) then
// Tag Check Faults cause a synchronous exception on reads or on
// a read/write access, and are asynchronously accumulated on writes
if read then
return TCFType_Sync;
else
return TCFType_Async;
end;
else
// Otherwise, Tag Check Faults have no effect on the PE
return TCFType_Ignore;
end;
otherwise =>
unreachable;
end;
end;
## Library pseudocode for aarch64/exceptions/aborts/AArch64\_InstructionAbort
// AArch64_InstructionAbort // ==========================
func AArch64_InstructionAbort(fault : FaultRecord) begin // External aborts on instruction fetch must be taken synchronously if IsFeatureImplemented(FEAT_DoubleFault) then assert fault.statuscode != Fault_AsyncExternal; end;
var target_el : bits(2);
if IsExternalAbort(fault) then
target_el = SyncExternalAbortTarget(fault);
else
let route_to_el2 : boolean = (EL2Enabled() && PSTATE.EL IN {EL0, EL1} &&
(HCR_EL2().TGE == '1' ||
(IsFeatureImplemented(FEAT_RME) &&
fault.gpcf.gpf != GPCF_None &&
HCR_EL2().GPF == '1') ||
IsSecondStage(fault)));
if PSTATE.EL == EL3 then
target_el = EL3;
elsif PSTATE.EL == EL2 || route_to_el2 then
target_el = EL2;
else
target_el = EL1;
end;
end;
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
var vect_offset : integer;
if IsExternalAbort(fault) && AArch64_RouteToSErrorOffset(target_el)
then
vect_offset = 0x180;
else
vect_offset = 0x0;
end;
let except : ExceptionRecord =
AArch64_AbortSyndrome(Exception_InstructionAbort, fault,
target_el);
AArch64_TakeException(target_el, except, preferred_exception_return,
vect_offset);
end;
## Library pseudocode for aarch64/exceptions/aborts/AArch64\_PCAlignmentFault
// AArch64_PCAlignmentFault // ========================== // Called on unaligned program counter in AArch64 state.
func AArch64_PCAlignmentFault begin
let preferred_exception_return : bits(64) = ThisInstrAddr{}();
let vect_offset : integer = 0x0;
var except : ExceptionRecord = ExceptionSyndrome(Exception_PCAlignment);
except.vaddress = ThisInstrAddr{64}();
var target_el : bits(2) = EL1;
if UInt(PSTATE.EL) > UInt(EL1) then
target_el = PSTATE.EL;
elsif EL2Enabled() && HCR_EL2().TGE == '1' then
target_el = EL2;
end;
AArch64_TakeException(target_el, except, preferred_exception_return,
vect_offset);
end;
## Library pseudocode for
aarch64/exceptions/aborts/AArch64\_RaiseTagCheckFault
// AArch64_RaiseTagCheckFault // ============================ // Raise a Tag Check Fault exception.
func AArch64_RaiseTagCheckFault(fault : FaultRecord) begin let preferred_exception_return : bits(64) = ThisInstrAddr{}(); let vect_offset : integer = 0x0; var target_el : bits(2) = EL1; if UInt(PSTATE.EL) > UInt(EL1) then target_el = PSTATE.EL; elsif PSTATE.EL == EL0 && EL2Enabled() && HCR_EL2().TGE == '1' then target_el = EL2; end;
let except : ExceptionRecord =
AArch64_AbortSyndrome(Exception_DataAbort, fault, target_el);
AArch64_TakeException(target_el, except, preferred_exception_return,
vect_offset);
end;
## Library pseudocode for
aarch64/exceptions/aborts/AArch64\_ReportTagCheckFault
// AArch64_ReportTagCheckFault // ============================= // Records a Tag Check Fault exception into the appropriate TFSR_ELx.
func AArch64_ReportTagCheckFault(el : bits(2), ttbr : bit) begin case el of when EL3 => assert ttbr == '0'; TFSR_EL3().TF0 = '1'; when EL2 => if ttbr == '0' then TFSR_EL2().TF0 = '1'; else TFSR_EL2().TF1 = '1'; end; when EL1 => if ttbr == '0' then TFSR_EL1().TF0 = '1'; else TFSR_EL1().TF1 = '1'; end; when EL0 => if ttbr == '0' then TFSRE0_EL1().TF0 = '1'; else TFSRE0_EL1().TF1 = '1'; end; end; end;
## Library pseudocode for
aarch64/exceptions/aborts/AArch64\_RouteToSErrorOffset
// AArch64_RouteToSErrorOffset // ============================= // Returns TRUE if synchronous External abort exceptions are taken to the // appropriate SError vector offset, and FALSE otherwise.
func AArch64_RouteToSErrorOffset(target_el : bits(2)) => boolean begin
------------------------------------------------------------------------------ Page 1 of 1. End of thread.