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

Writeup Shared pseudocode: part 6 of 36

started by admin

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

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

// Gather stage 1 translation table walk parameters for EL3&0 regime

func AArch32_S1TTWParamsEL30(va : bits(32)) => S1TTWParams begin assert TTBCR_S().EAE == '1'; var walkparams : S1TTWParams;

walkparams.t0sz   = TTBCR_S().T0SZ;
walkparams.t1sz   = TTBCR_S().T1SZ;
walkparams.ee     = SCTLR_S().EE;
walkparams.wxn    = SCTLR_S().WXN;
walkparams.uwxn   = SCTLR_S().UWXN;
walkparams.ntlsmd = if IsFeatureImplemented(FEAT_LSMAOC) then SCTLR_S().nTLSMD else '1';
walkparams.mair   = MAIR1_S()::MAIR0_S();
walkparams.sif    = SCR().SIF;

let varange : VARange = AArch32_GetVARange(va, walkparams.t0sz, walkparams.t1sz); if varange == VARange_LOWER then walkparams.sh = TTBCR_S().SH0; walkparams.irgn = TTBCR_S().IRGN0; walkparams.orgn = TTBCR_S().ORGN0; walkparams.hpd = (if IsFeatureImplemented(FEAT_AA32HPD) then TTBCR_S().T2E AND TTBCR2_S().HPD0 else '0'); else walkparams.sh = TTBCR_S().SH1; walkparams.irgn = TTBCR_S().IRGN1; walkparams.orgn = TTBCR_S().ORGN1; walkparams.hpd = (if IsFeatureImplemented(FEAT_AA32HPD) then TTBCR_S().T2E AND TTBCR2_S().HPD1 else '0'); end;

return walkparams;

end;


## Library pseudocode for aarch64/debug/brbe

// Contents of the Branch Record Buffer //=====================================

var Records_SRC : array [[64]] of BRBSRC_EL1_Type; var Records_TGT : array [[64]] of BRBTGT_EL1_Type; var Records_INF : array [[64]] of BRBINF_EL1_Type;

// Getter functions for branch records //==================================== // Functions used by MRS instructions that access branch records

func BRBSRC_EL1(n : integer) => BRBSRC_EL1_Type begin assert n IN {0..31}; let record_index : integer = UInt(BRBFCR_EL1().BANK::n[4:0]); if record_index < GetBRBENumRecords() then return Records_SRC[[record_index]]; else return Zeros{64}; end; end;

func BRBTGT_EL1(n : integer) => BRBTGT_EL1_Type begin assert n IN {0..31}; let record_index : integer = UInt(BRBFCR_EL1().BANK::n[4:0]); if record_index < GetBRBENumRecords() then return Records_TGT[[record_index]]; else return Zeros{64}; end; end;

func BRBINF_EL1(n : integer) => BRBINF_EL1_Type begin assert n IN {0..31}; let record_index : integer = UInt(BRBFCR_EL1().BANK::n[4:0]); if record_index < GetBRBENumRecords() then return Records_INF[[record_index]]; else return Zeros{64}; end; end;


## Library pseudocode for aarch64/debug/brbe/BRBCycleCountingEnabled

// BRBCycleCountingEnabled // ========================= // Returns TRUE if the recording of cycle counts is allowed, // FALSE otherwise.

func BRBCycleCountingEnabled() => boolean begin if HaveEL(EL2) && BRBCR_EL2().CC == '0' then return FALSE; end; if BRBCR_EL1().CC == '0' then return FALSE; end; return TRUE; end;


## Library pseudocode for aarch64/debug/brbe/BRBEBranch

// BRBEBranch // ============ // Called to write branch record for the following branches when BRBE is active: // direct branches, // indirect branches, // direct branches with link, // indirect branches with link, // returns from subroutines.

func BRBEBranch(br_type : BranchType, cond : boolean, target_address : bits(64)) begin if BranchRecordAllowed(PSTATE.EL) && FilterBranchRecord(br_type, cond) then var branch_type : bits(6); case br_type of when BranchType_DIR => branch_type = if cond then '001000' else '000000'; when BranchType_INDIR => branch_type = '000001'; when BranchType_DIRCALL => branch_type = '000010'; when BranchType_INDCALL => branch_type = '000011'; when BranchType_RET => branch_type = '000101'; otherwise => unreachable; end;

    var ccu : bit;
    var cc : bits(14);
    (ccu, cc) = BranchEncCycleCount();
    let el : bits(2) = PSTATE.EL;
    let mispredict : bit = (if BRBEMispredictAllowed() && BranchMispredict() then '1'
                            else '0');
UpdateBranchRecordBuffer(ccu, cc, branch_type, el, mispredict,                         '11', PC64(), target_address);PMUEvent(PMU_EVENT_BRB_FILTRATE);

end;

return;

end;


## Library pseudocode for aarch64/debug/brbe/BRBEBranchOnISB

// BRBEBranchOnISB // ================= // Returns TRUE if ISBs generate Branch records, and FALSE otherwise.

func BRBEBranchOnISB() => boolean begin return ImpDefBool("ISB generates Branch records"); end;


## Library pseudocode for aarch64/debug/brbe/BRBEDebugStateEntry

// BRBEDebugStateEntry // ===================== // Called to write Debug state entry branch record when BRBE is active.

func BRBEDebugStateEntry(source_address : bits(64)) begin if BranchRecordAllowed(PSTATE.EL) then let branch_type : bits(6) = '100001'; var ccu : bit; var cc : bits(14); (ccu, cc) = BranchEncCycleCount(); let el : bits(2) = '00'; let mispredict : bit = '0';

    // Debug state is a prohibited region, therefore target_address=0
    UpdateBranchRecordBuffer(ccu, cc, branch_type, el, mispredict,
                             '10', source_address, Zeros{64});
PMUEvent(PMU_EVENT_BRB_FILTRATE);

end;

return;

end;


## Library pseudocode for aarch64/debug/brbe/BRBEDebugStateExit

// BRBEDebugStateExit // ==================== // Called to write Debug state exit branch record when BRBE is active.

func BRBEDebugStateExit(target_address : bits(64)) begin if BranchRecordAllowed(PSTATE.EL) then // Debug state is a prohibited region, therefore ccu=1, cc=0, source_address=0 let branch_type : bits(6) = '111001'; let ccu : bit = '1'; let cc : bits(14) = Zeros{14}; let el : bits(2) = PSTATE.EL; let mispredict : bit = '0';

    UpdateBranchRecordBuffer(ccu, cc, branch_type, el, mispredict,
                             '01', Zeros{64}, target_address);
PMUEvent(PMU_EVENT_BRB_FILTRATE);

end;

return;

end;


## Library pseudocode for aarch64/debug/brbe/BRBEException

// BRBEException // =============== // Called to write exception branch record when BRBE is active.

func BRBEException(erec : ExceptionRecord, source_valid : boolean, source_address_in : bits(64), target_address_in : bits(64), target_el : bits(2), trappedsyscallinst : boolean) begin var target_address : bits(64) = target_address_in; let except : Exception = erec.exceptype; let iss : bits(25) = erec.syndrome.iss; case target_el of when EL3 => if !IsFeatureImplemented(FEAT_BRBEv1p1) || (MDCR_EL3().E3BREC == MDCR_EL3().E3BREW) then return; end; when EL2 => if BRBCR_EL2().EXCEPTION == '0' then return; end; when EL1 => if BRBCR_EL1().EXCEPTION == '0' then return; end; end;

let target_valid : boolean = BranchRecordAllowed(target_el);

if source_valid || target_valid then var branch_type : bits(6); case except of when Exception_Uncategorized => branch_type = '100011'; // Trap when Exception_WFxTrap => branch_type = '100011'; // Trap when Exception_CP15RTTrap => branch_type = '100011'; // Trap when Exception_CP15RRTTrap => branch_type = '100011'; // Trap when Exception_CP14RTTrap => branch_type = '100011'; // Trap when Exception_CP14DTTrap => branch_type = '100011'; // Trap when Exception_AdvSIMDFPAccessTrap => branch_type = '100011'; // Trap when Exception_FPIDTrap => branch_type = '100011'; // Trap when Exception_PACTrap => branch_type = '100011'; // Trap when Exception_CP14RRTTrap => branch_type = '100011'; // Trap when Exception_OtherTrap => branch_type = '100011'; // Trap when Exception_BranchTarget => branch_type = '101011'; // Inst Fault when Exception_IllegalState => branch_type = '100011'; // Trap when Exception_SupervisorCall => if !trappedsyscallinst then branch_type = '100010'; // Call else branch_type = '100011'; // Trap end; when Exception_HypervisorCall => branch_type = '100010'; // Call when Exception_MonitorCall => if !trappedsyscallinst then branch_type = '100010'; // Call else branch_type = '100011'; // Trap end; when Exception_SystemRegisterTrap => branch_type = '100011'; // Trap when Exception_SystemRegister128Trap => branch_type = '100011'; // Trap when Exception_SVEAccessTrap => branch_type = '100011'; // Trap when Exception_SMEAccessTrap => branch_type = '100011'; // Trap when Exception_ERetTrap => branch_type = '100011'; // Trap when Exception_PACFail => branch_type = '101100'; // Data Fault when Exception_InstructionAbort => branch_type = '101011'; // Inst Fault when Exception_PCAlignment => branch_type = '101010'; // Alignment when Exception_DataAbort => branch_type = '101100'; // Data Fault when Exception_NV2DataAbort => branch_type = '101100'; // Data Fault when Exception_SPAlignment => branch_type = '101010'; // Alignment when Exception_FPTrappedException => branch_type = '100011'; // Trap when Exception_SError => branch_type = '100100'; // System Error when Exception_Breakpoint => branch_type = '100110'; // Inst debug when Exception_SoftwareStep => branch_type = '100110'; // Inst debug when Exception_Watchpoint => branch_type = '100111'; // Data debug when Exception_NV2Watchpoint => branch_type = '100111'; // Data debug when Exception_SoftwareBreakpoint => branch_type = '100110'; // Inst debug when Exception_IRQ => branch_type = '101110'; // IRQ when Exception_FIQ => branch_type = '101111'; // FIQ when Exception_MemCpyMemSet => branch_type = '100011'; // Trap when Exception_GCSFail => if iss[23:20] == '0000' then branch_type = '101100'; // Data Fault elsif iss[23:20] == '0001' then branch_type = '101011'; // Inst Fault elsif iss[23:20] == '0010' then branch_type = '100011'; // Trap else unreachable; end; when Exception_Profiling => branch_type = '100110'; // Inst debug when Exception_GPC => if iss[20] == '1' then branch_type = '101011'; // Inst fault else branch_type = '101100'; // Data fault end; when Exception_ConditionalFault => branch_type = '100110'; // Inst debug otherwise => unreachable; end;

var ccu : bit;var cc : bits(14);(ccu, cc) = BranchEncCycleCount();let el : bits(2) = if target_valid then target_el else '00';let mispredict : bit = '0';let sv : bit = if source_valid then '1' else '0';let tv : bit = if target_valid then '1' else '0';let source_address : bits(64) = if source_valid then source_address_in else Zeros{64};if !target_valid then    target_address = Zeros{64};else    target_address = AArch64_BranchAddr(target_address, target_el);end;UpdateBranchRecordBuffer(ccu, cc, branch_type, el, mispredict,                         sv::tv, source_address, target_address);PMUEvent(PMU_EVENT_BRB_FILTRATE);

end;

return;

end;


## Library pseudocode for aarch64/debug/brbe/BRBEExceptionReturn

// BRBEExceptionReturn // ===================== // Called to write exception return branch record when BRBE is active.

func BRBEExceptionReturn(target_address_in : bits(64), source_el : bits(2), source_valid : boolean, source_address_in : bits(64)) begin var target_address : bits(64) = target_address_in; case source_el of when EL3 => if !IsFeatureImplemented(FEAT_BRBEv1p1) || (MDCR_EL3().E3BREC == MDCR_EL3().E3BREW) then return; end; when EL2 => if BRBCR_EL2().ERTN == '0' then return; end; when EL1 => if BRBCR_EL1().ERTN == '0' then return; end; end;

let target_valid : boolean = BranchRecordAllowed(PSTATE.EL);

if source_valid || target_valid then let branch_type : bits(6) = '000111'; var ccu : bit; var cc : bits(14); (ccu, cc) = BranchEncCycleCount(); let el : bits(2) = if target_valid then PSTATE.EL else '00'; let mispredict : bit = (if source_valid && BRBEMispredictAllowed() && BranchMispredict() then '1' else '0'); let sv : bit = if source_valid then '1' else '0'; let tv : bit = if target_valid then '1' else '0'; let source_address : bits(64) = if source_valid then source_address_in else Zeros{64}; if !target_valid then target_address = Zeros{64}; end;

UpdateBranchRecordBuffer(ccu, cc, branch_type, el, mispredict,                         sv::tv, source_address, target_address);PMUEvent(PMU_EVENT_BRB_FILTRATE);

end;

return;

end;


## Library pseudocode for aarch64/debug/brbe/BRBEFreeze

// BRBEFreeze // ============ // Generates BRBE freeze event.

func BRBEFreeze begin BRBFCR_EL1().PAUSED = '1'; BRBTS_EL1() = GetTimestamp(BRBETimeStamp()); end;


## Library pseudocode for aarch64/debug/brbe/BRBEISB

// BRBEISB // ========= // Handles ISB instruction for BRBE.

func BRBEISB begin let branch_conditional : boolean = FALSE; BRBEBranch(BranchType_DIR, branch_conditional, PC64() + 4); end;


## Library pseudocode for aarch64/debug/brbe/BRBEMispredictAllowed

// BRBEMispredictAllowed // ======================= // Returns TRUE if the recording of branch misprediction is allowed, // FALSE otherwise.

func BRBEMispredictAllowed() => boolean begin if HaveEL(EL2) && BRBCR_EL2().MPRED == '0' then return FALSE; end; if BRBCR_EL1().MPRED == '0' then return FALSE; end; return TRUE; end;


## Library pseudocode for aarch64/debug/brbe/BRBETimeStamp

// BRBETimeStamp // =============== // Returns captured timestamp.

func BRBETimeStamp() => TimeStamp begin if HaveEL(EL2) then var TS_el2 : bits(2) = BRBCR_EL2().TS; if !IsFeatureImplemented(FEAT_ECV) && TS_el2 == '10' then // Reserved value (-, TS_el2) = ConstrainUnpredictableBits{2}(Unpredictable_EL2TIMESTAMP); end; case TS_el2 of when '00' => // Falls out to check BRBCR_EL1.TS pass; when '01' => return TimeStamp_Virtual; when '10' => assert IsFeatureImplemented(FEAT_ECV); // Otherwise ConstrainUnpredictableBits // removes this case return TimeStamp_OffsetPhysical; when '11' => return TimeStamp_Physical; end; end;

var TS_el1 : bits(2) = BRBCR_EL1().TS;if TS_el1 == '00' || (!IsFeatureImplemented(FEAT_ECV) && TS_el1 == '10') then    // Reserved value    (-, TS_el1) = ConstrainUnpredictableBits{2}(Unpredictable_EL1TIMESTAMP);end;case TS_el1 of    when '01' =>        return TimeStamp_Virtual;    when '10' =>        return TimeStamp_OffsetPhysical;    when '11' =>        return TimeStamp_Physical;    otherwise =>        unreachable;           // ConstrainUnpredictableBits removes this caseend;

end;


## Library pseudocode for aarch64/debug/brbe/BRB\_IALL

// BRB_IALL // ========== // Called to perform invalidation of branch records

func BRB_IALL begin let nbrberecords : integer = GetBRBENumRecords(); for i = 0 to nbrberecords - 1 do Records_SRC

  • = Zeros{64}; Records_TGT
  • = Zeros{64}; Records_INF
  • = Zeros{64}; end; end;

## Library pseudocode for aarch64/debug/brbe/BRB\_INJ

// BRB_INJ // ========= // Called to perform manual injection of branch records.

func BRB_INJ begin UpdateBranchRecordBuffer(BRBINFINJ_EL1().CCU, BRBINFINJ_EL1().CC, BRBINFINJ_EL1().TYPE, BRBINFINJ_EL1().EL, BRBINFINJ_EL1().MPRED, BRBINFINJ_EL1().VALID, BRBSRCINJ_EL1().ADDRESS, BRBTGTINJ_EL1().ADDRESS); BRBINFINJ_EL1() = ARBITRARY : bits(64); BRBSRCINJ_EL1() = ARBITRARY : bits(64); BRBTGTINJ_EL1() = ARBITRARY : bits(64);

if ConstrainUnpredictableBool(Unpredictable_BRBFILTRATE) then    PMUEvent(PMU_EVENT_BRB_FILTRATE);end;

end;


## Library pseudocode for aarch64/debug/brbe/BranchEncCycleCount

// BranchEncCycleCount // =====================

// The first return result is '1' if either of the following is true, and '0' otherwise: // - This is the first Branch record after the PE exited a Prohibited Region. // - This is the first Branch record after cycle counting has been enabled. // If the first return is '0', the second return result is the encoded cycle count // since the last branch. // The format of this field uses a mantissa and exponent to express the cycle count value. // - bits[7:0] indicate the mantissa M. // - bits[13:8] indicate the exponent E. // The cycle count is expressed using the following function: // cycle_count = (if IsZero(E) then UInt(M) else UInt('1'::M::Zeros{UInt(E)-1})) // A value of all ones in both the mantissa and exponent indicates the cycle count value // exceeded the size of the cycle counter. // If the cycle count is not known, the second return result is zero.

func BranchEncCycleCount() => (bit, bits(14)) begin var cc : integer = BranchRawCycleCount(); if () || FirstBranchAfterProhibited() then return ('1', Zeros{14}); end;

// The format of this field uses a mantissa and exponent to express the cycle count value.
//  - bits[7:0] indicate the mantissa M.
//  - bits[13:8] indicate the exponent E.
// The cycle count is expressed using the following function:
//   cycle_count = (if IsZero(E) then UInt(M) else UInt('1'::M::Zeros{UInt(E)-1}))
// A value of all ones in both the mantissa and exponent indicates the cycle count value
// exceeded the size of the cycle counter.

var E : bits(6); var M : bits(8);

if cc < 2^8 then E = Zeros{6}; M = cc[7:0]; elsif cc >= 2^20 then E = Ones{6}; M = Ones{8}; else E = 1[5:0]; while cc >= 2^9 looplimit 11 do E = E + 1; cc = cc DIVRM 2; end; M = cc[7:0]; end;

return ('0', E::M);

end;


## Library pseudocode for aarch64/debug/brbe/BranchMispredict

// BranchMispredict // ================== // Returns TRUE if the branch being executed was mispredicted, FALSE otherwise.

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


## Library pseudocode for aarch64/debug/brbe/BranchRawCycleCount

// BranchRawCycleCount // ===================== // If the cycle count is known, the return result is the cycle count since the last branch.

impdef func BranchRawCycleCount() => integer begin return 0; end;


## Library pseudocode for aarch64/debug/brbe/BranchRecordAllowed

// BranchRecordAllowed // ===================== // Returns TRUE if branch recording is allowed, FALSE otherwise.

func BranchRecordAllowed(el : bits(2)) => boolean begin if ELUsingAArch32(el) then return FALSE; end;

if BRBFCR_EL1().PAUSED == '1' then
    return FALSE;
end;

if el == EL3 && IsFeatureImplemented(FEAT_BRBEv1p1) then return (MDCR_EL3().E3BREC != MDCR_EL3().E3BREW); end;

if HaveEL(EL3) && (MDCR_EL3().SBRBE == '00' || (CurrentSecurityState() == SS_Secure && MDCR_EL3().SBRBE == '01')) then return FALSE; end;

case el of when EL3 => return FALSE; // FEAT_BRBEv1p1 not implemented when EL2 => return BRBCR_EL2().E2BRE == '1'; when EL1 => return BRBCR_EL1().E1BRE == '1'; when EL0 => if EL2Enabled() && HCR_EL2().TGE == '1' then return BRBCR_EL2().E0HBRE == '1'; else return BRBCR_EL1().E0BRE == '1'; end; end;

end;


## Library pseudocode for aarch64/debug/brbe/FilterBranchRecord

// FilterBranchRecord // ==================== // Returns TRUE if the branch record is not filtered out, FALSE otherwise.

func FilterBranchRecord(br : BranchType, cond : boolean) => boolean begin case br of when BranchType_DIRCALL => return BRBFCR_EL1().DIRCALL != BRBFCR_EL1().EnI; when BranchType_INDCALL => return BRBFCR_EL1().INDCALL != BRBFCR_EL1().EnI; when BranchType_RET => return BRBFCR_EL1().RTN != BRBFCR_EL1().EnI; when BranchType_DIR => if cond then return BRBFCR_EL1().CONDDIR != BRBFCR_EL1().EnI; else return BRBFCR_EL1().DIRECT != BRBFCR_EL1().EnI; end; when BranchType_INDIR => return BRBFCR_EL1().INDIRECT != BRBFCR_EL1().EnI; otherwise => unreachable; end; return FALSE; end;


## Library pseudocode for aarch64/debug/brbe/FirstBranchAfterProhibited

// FirstBranchAfterProhibited // ============================ // Returns TRUE if branch recorded is the first branch after a prohibited region, // FALSE otherwise.

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


## Library pseudocode for aarch64/debug/brbe/GetBRBENumRecords

// GetBRBENumRecords // =================== // Returns the number of branch records implemented.

func GetBRBENumRecords() => integer begin assert UInt(BRBIDR0_EL1().NUMREC) IN {0x08, 0x10, 0x20, 0x40}; return ImpDefInt("Number of BRBE Branch records"); end;


## Library pseudocode for aarch64/debug/brbe/ShouldBRBEFreeze

// ShouldBRBEFreeze // ================== // Returns TRUE if the BRBE freeze event conditions have been met, and FALSE otherwise.

func ShouldBRBEFreeze() => boolean begin if (PSTATE.EL) then return FALSE; end;

var include_r1 : boolean;
var include_r2 : boolean;
let include_r3 : boolean = FALSE;

if HaveEL(EL2) then include_r1 = (BRBCR_EL1().FZP == '1'); include_r2 = (BRBCR_EL2().FZP == '1'); else include_r1 = TRUE; include_r2 = TRUE; end;

return CheckPMUOverflowCondition(PMUOverflowCondition_BRBEFreeze, include_r1, include_r2, include_r3);

end;


## Library pseudocode for aarch64/debug/brbe/UpdateBranchRecordBuffer

// UpdateBranchRecordBuffer // ========================== // Add a new Branch record to the buffer.

func UpdateBranchRecordBuffer(ccu : bit, cc : bits(14), branch_type : bits(6), el : bits(2), mispredict : bit, valid : bits(2), source_address : bits(64), target_address : bits(64)) begin // Shift the Branch Records in the buffer let nbrberecords : integer = GetBRBENumRecords(); for i = nbrberecords - 1 downto 1 do Records_SRC

  • = Records_SRC[[i - 1]]; Records_TGT

  • = Records_TGT[[i - 1]]; Records_INF

  • = Records_INF[[i - 1]]; end;

    Records_INF[[0]].CCU = ccu; Records_INF[[0]].CC = cc;

    Records_INF[[0]].EL = el; Records_INF[[0]].VALID = valid; Records_INF[[0]].MPRED = mispredict; Records_INF[[0]].TYPE = branch_type;

    Records_SRC[[0]] = source_address; Records_TGT[[0]] = target_address;

    return; end;


## Library pseudocode for aarch64/debug/breakpoint/AArch64\_BreakpointMatch

// AArch64_BreakpointMatch // ========================= // Breakpoint matching in an AArch64 translation regime. // Returns BreakpointInfo structure that contains breakpoint type, a boolean to indicate the // type of breakpoint, matched address and whether the breakpoint is active and matched // successfully. For Address Mismatch breakpoints, the returned boolean is the inverted result. func AArch64_BreakpointMatch(n : integer, vaddress : bits(64), accdesc : AccessDescriptor, size : integer) => BreakpointInfo begin assert (S1TranslationRegime()); assert n < NumBreakpointsImplemented(); var brkptinfo : BreakpointInfo;

let linking_enabled : boolean = (DBGBCR_EL1(n).BT IN {'0x11', '1xx1'} ||
                                 (IsFeatureImplemented(FEAT_ABLE) && DBGBCR_EL1(n).BT2 == '1'));

// A breakpoint that has linking enabled does not generate debug events in isolation if linking_enabled then brkptinfo.bptype = BreakpointType_Inactive; brkptinfo.match = FALSE; return brkptinfo; end;

let enabled : boolean = IsBreakpointEnabled(n); let linked : boolean = DBGBCR_EL1(n).BT == '0x01'; let isbreakpnt : boolean = TRUE; let linked_to : boolean = FALSE; let from_linking_enabled : boolean = FALSE; let lbnx : bits(2) = if IsFeatureImplemented(FEAT_Debugv8p9) then DBGBCR_EL1(n).LBNX else '00'; let linked_n : integer{} = UInt(lbnx :: DBGBCR_EL1(n).LBN); let ssce : bit = if IsFeatureImplemented(FEAT_RME) then DBGBCR_EL1(n).SSCE else '0'; let state_match = AArch64_StateMatch(DBGBCR_EL1(n).SSC, ssce, DBGBCR_EL1(n).HMC, DBGBCR_EL1(n).PMC, linked, linked_n, isbreakpnt, vaddress, accdesc);

var (bp_type, value_match) = AArch64_BreakpointValueMatch(n, vaddress, linked_to, isbreakpnt, from_linking_enabled);

if HaveAArch32() && size == 4 then // Check second halfword // If the breakpoint address and BAS of an Address breakpoint match the address of the // second halfword of an instruction, but not the address of the first halfword, it is // CONSTRAINED UNPREDICTABLE whether or not this breakpoint generates a Breakpoint debug // event. let (-, match_i) = AArch64_BreakpointValueMatch(n, vaddress + 2, linked_to, isbreakpnt, from_linking_enabled); if !value_match && match_i then value_match = ConstrainUnpredictableBool(Unpredictable_BPMATCHHALF); end; end;

if vaddress[1] == '1' && DBGBCR_EL1(n).BAS == '1111' then // The above notwithstanding, if DBGBCR_EL1(n).BAS == '1111', then it is CONSTRAINED // UNPREDICTABLE whether or not a Breakpoint debug event is generated for an instruction // at the address DBGBVR_EL1(n)+2. if value_match then value_match = ConstrainUnpredictableBool(Unpredictable_BPMATCHHALF); end; end;

if !(state_match && enabled) then brkptinfo.bptype = BreakpointType_Inactive; brkptinfo.match = FALSE; else brkptinfo.bptype = bp_type; brkptinfo.match = value_match; end; return brkptinfo;

end;


## Library pseudocode for aarch64/debug/breakpoint/AArch64\_BreakpointValueMatch

// AArch64_BreakpointValueMatch // ============================== // Returns breakpoint type to indicate the type of breakpoint and a boolean to indicate // whether the breakpoint matched successfully. For Address Mismatch breakpoints, the // returned boolean is the inverted result. If the breakpoint type return value is Inactive, // then the boolean result is FALSE.

func AArch64_BreakpointValueMatch(n_in : integer, vaddress : bits(64), linked_to : boolean, isbreakpnt : boolean, from_linking_enabled : boolean ) => (BreakpointType, boolean) recurselimit 2 begin

// "n_in" is the identity of the breakpoint unit to match against.
// "vaddress" is the current instruction address, ignored if linked_to is TRUE and for Context
//   matching breakpoints.
// "linked_to" is TRUE if this is a call from StateMatch for linking.
// "isbreakpnt"  TRUE is this is a call from BreakpointMatch or from StateMatch for a
// linked breakpoint or from BreakpointValueMatch for a linked breakpoint with linking enabled.
// "from_linking_enabled" is TRUE if this is a call from BreakpointValueMatch for a linked
// breakpoint with linking enabled.
var n : integer = n_in;
var c : Constraint;
var dbgtype : bits(5);

// If a non-existent breakpoint then it is CONSTRAINED UNPREDICTABLE whether this gives // no match or the breakpoint is mapped to another UNKNOWN implemented breakpoint. if n >= NumBreakpointsImplemented() then (c, n) = ConstrainUnpredictableInteger(0, NumBreakpointsImplemented() - 1, Unpredictable_BPNOTIMPL); assert c IN {Constraint_DISABLED, Constraint_UNKNOWN}; if c == Constraint_DISABLED then return (BreakpointType_Inactive, FALSE); end; end;

// If this breakpoint is not enabled, it cannot generate a match. // (This could also happen on a call from StateMatch for linking). if (n) then return (BreakpointType_Inactive, FALSE); end;

// If BT is set to a reserved type, behaves either as disabled or as a not-reserved type. if IsFeatureImplemented(FEAT_ABLE) then dbgtype = DBGBCR_EL1(n).[BT2,BT]; else dbgtype = '0' :: DBGBCR_EL1(n).BT; end;

(c, dbgtype) = AArch64_ReservedBreakpointType(n, dbgtype); if c == Constraint_DISABLED then return (BreakpointType_Inactive, FALSE); end; // Otherwise the value returned by ConstrainUnpredictableBits must be a not-reserved value

// Determine what to compare against. let match_addr : boolean = (dbgtype == 'x0x0x'); let mismatch : boolean = (dbgtype == 'x010x'); let match_vmid : boolean = (dbgtype == 'x10xx'); let match_cid : boolean = (dbgtype == 'x001x'); let match_cid1 : boolean = (dbgtype IN {'x101x', 'xx11x'}); let match_cid2 : boolean = (dbgtype == 'x11xx'); let linking_enabled : boolean = (dbgtype IN {'xxx11', 'x1xx1', '1xxxx'});

// If this is a call from StateMatch, return FALSE if the breakpoint is not // programmed with linking enabled. if linked_to && !linking_enabled then return (BreakpointType_Inactive, FALSE); end;

// If called from BreakpointMatch return FALSE for breakpoint with linking enabled. if !linked_to && linking_enabled then return (BreakpointType_Inactive, FALSE); end;

let linked : boolean = (dbgtype == 'x0x01'); if from_linking_enabled then // A breakpoint with linking enabled has called this function. assert linked_to && isbreakpnt; if linked then // A breakpoint with linking enabled is linked to a linked breakpoint. This is // architecturally UNPREDICTABLE, but treated as disabled in the pseudo code to // avoid potential recursion in BreakpointValueMatch(). return (BreakpointType_Inactive, FALSE); end; end;

// If a linked breakpoint is linked to an address matching breakpoint, // the behavior is CONSTRAINED UNPREDICTABLE. if linked_to && match_addr && isbreakpnt then if !ConstrainUnpredictableBool(Unpredictable_BPLINKEDADDRMATCH) then return (BreakpointType_Inactive, FALSE); end; end;

// A breakpoint programmed for address mismatch does not match in AArch32 state. if mismatch && UsingAArch32() then return (BreakpointType_Inactive, FALSE); end;

var bvr_match : boolean = FALSE; var bxvr_match : boolean = FALSE; var bp_type : BreakpointType; var mask : integer{0..31};

if IsFeatureImplemented(FEAT_BWE) then mask = UInt(DBGBCR_EL1(n).MASK);

// If the mask is set to a reserved value, the behavior is CONSTRAINED UNPREDICTABLE.if mask IN {1, 2} then    var unpred_mask : integer;    (c, unpred_mask) = ConstrainUnpredictableInteger(3, 31, Unpredictable_RESBPMASK);    assert c IN {Constraint_DISABLED, Constraint_NONE, Constraint_UNKNOWN};    case c of        when Constraint_DISABLED =&gt; return (BreakpointType_Inactive, FALSE);  // Disabled        when Constraint_NONE =&gt;     mask = 0;                                 // No masking        // Otherwise the value returned by ConstrainUnpredictableBits must        // be a not-reserved value.        otherwise =&gt; mask = unpred_mask as integer{3..31};    end;end;if mask != 0 then    // When DBGBCR_EL1(n).MASK is a valid nonzero value, the behavior is    // CONSTRAINED UNPREDICTABLE if any of the following are true:    //     - DBGBCR_EL1(n).[BT2,BT] is programmed for a Context matching breakpoint.    //     - DBGBCR_EL1(n).BAS is not '1111' and AArch32 is supported at EL0.    if ((match_cid || match_cid1 || match_cid2) ||        (DBGBCR_EL1(n).BAS != '1111' &amp;&amp; HaveAArch32())) then        if !ConstrainUnpredictableBool(Unpredictable_BPMASK) then            return (BreakpointType_Inactive, FALSE);        end;    end;else    // A stand-alone mismatch of a single address is not supported.    if mismatch then        return (BreakpointType_Inactive, FALSE);    end;end;

else mask = 0; end;

// Do the comparison. if match_addr then var byte_select_match : boolean; let byte : integer = UInt(vaddress[1:0]);

if HaveAArch32() then    // T32 instructions can be executed at EL0 in an AArch64 translation regime.    assert byte IN {0,2};                       // "vaddress" is halfword aligned    byte_select_match = (DBGBCR_EL1(n).BAS[byte] == '1');else    assert byte == 0;                           // "vaddress" is word aligned    byte_select_match = TRUE;                   // DBGBCR_EL1(n).BAS[byte] is RES1end;// When FEAT_LVA3 is not implemented, if the DBGBVR_EL1(n).RESS field bits are not a// sign extension of the MSB of DBGBVR_EL1(n).VA, it is UNPREDICTABLE whether they// appear to be included in the match.// If 'vaddress' is outside of the current virtual address space, then the access// generates a Translation fault.let dbgtop : AddressSize = DebugAddrTop();let unpredictable_ress : boolean = (dbgtop &lt; 55 &amp;&amp; !IsOnes(DBGBVR_EL1(n)[63:dbgtop]) &amp;&amp;                                    !IsZero(DBGBVR_EL1(n)[63:dbgtop]) &amp;&amp;                              ConstrainUnpredictableBool(Unpredictable_DBGxVR_RESS));let cmpmsb : integer{} = if unpredictable_ress then 63 else dbgtop;let cmplsb : integer{} = if mask &gt; 2 then mask else 2;bvr_match = ((vaddress[cmpmsb:cmplsb] == DBGBVR_EL1(n)[cmpmsb:cmplsb]) &amp;&amp;             byte_select_match);if mask &gt; 2 then    // If masked bits of DBGBVR_EL1(n) are not zero, the behavior    // is CONSTRAINED UNPREDICTABLE.    let masktop : integer{} = mask - 1;    if bvr_match &amp;&amp; !IsZero(DBGBVR_EL1(n)[masktop:2]) then        bvr_match = ConstrainUnpredictableBool(Unpredictable_BPMASKEDBITS);    end;end;

elsif match_cid then if IsInHost() then bvr_match = (CONTEXTIDR_EL2()[31:0] == DBGBVR_EL1(n)[31:0]); else bvr_match = (PSTATE.EL IN {EL0, EL1} && CONTEXTIDR_EL1()[31:0] == DBGBVR_EL1(n)[31:0]); end;

elsif match_cid1 then bvr_match = (PSTATE.EL IN {EL0, EL1} && () && CONTEXTIDR_EL1()[31:0] == DBGBVR_EL1(n)[31:0]); end;

if match_vmid then let vmid : bits(NUM_VMIDBITS) = VMID(); var bvr_vmid : bits(NUM_VMIDBITS);

if !IsFeatureImplemented(FEAT_VMID16) || VTCR_EL2().VS == '0' then    bvr_vmid = ZeroExtend{NUM_VMIDBITS}(DBGBVR_EL1(n)[39:32]);else    bvr_vmid = DBGBVR_EL1(n)[47:32];end;bxvr_match = (PSTATE.EL IN {EL0, EL1} &amp;&amp; EL2Enabled() &amp;&amp; () &amp;&amp; vmid == bvr_vmid);

elsif match_cid2 then bxvr_match = (PSTATE.EL != EL3 && EL2Enabled() && DBGBVR_EL1(n)[63:32] == CONTEXTIDR_EL2()[31:0]); end;

let bvr_match_valid : boolean = (match_addr || match_cid || match_cid1); let bxvr_match_valid : boolean = (match_vmid || match_cid2);

var value_match : boolean = ((!bxvr_match_valid || bxvr_match) && (!bvr_match_valid || bvr_match));

// A watchpoint might be linked to a linked address matching breakpoint with linking enabled, // which is in turn linked to a context matching breakpoint. if linked_to && linked then // If called from StateMatch and breakpoint is a linked breakpoint then it must be a // watchpoint that is linked to an address matching breakpoint which is linked to a // context matching breakpoint. assert !isbreakpnt && match_addr && IsFeatureImplemented(FEAT_ABLE); let lbnx : bits(2) = (if IsFeatureImplemented(FEAT_Debugv8p9) then DBGBCR_EL1(n).LBNX else '00'); let linked_linked_n : integer{} = UInt(lbnx :: DBGBCR_EL1(n).LBN); var linked_value_match : boolean; let linked_vaddress = ARBITRARY : bits(64); let linked_linked_to = TRUE; let linked_isbreakpnt = TRUE; let linked_from_linking_enabled = TRUE; (bp_type, linked_value_match) = AArch64_BreakpointValueMatch(linked_linked_n, linked_vaddress, linked_linked_to, linked_isbreakpnt, linked_from_linking_enabled); value_match = value_match && linked_value_match; end;

if match_addr && !mismatch then bp_type = BreakpointType_AddrMatch; elsif match_addr && mismatch then bp_type = BreakpointType_AddrMismatch; elsif match_vmid || match_cid || match_cid1 || match_cid2 then bp_type = BreakpointType_CtxtMatch; else unreachable; end;

return (bp_type, value_match);

end;


## Library pseudocode for aarch64/debug/breakpoint/AArch64\_ReservedBreakpointType

// AArch64_ReservedBreakpointType // ================================ // Checks if the given DBGBCR_EL1(n).[BT2,BT] values are reserved and will // generate Constrained Unpredictable behavior, otherwise returns Constraint_NONE.

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

if bt[4] == '0' then
    // Context matching
    if bt != '00x0x' && !context_aware then
        reserved = TRUE;
    end;
// EL2 extensionif bt == '01xxx' &amp;&amp; (EL2) then    reserved = TRUE;end;// Context matchingif (bt IN {'0011x','011xx'} &amp;&amp; !IsFeatureImplemented(FEAT_VHE) &amp;&amp;      !IsFeatureImplemented(FEAT_Debugv8p2)) then    reserved = TRUE;end;// Reservedif bt == '0010x' &amp;&amp; !IsFeatureImplemented(FEAT_BWE) &amp;&amp; (EL1) then    reserved = TRUE;end;

else // Reserved if bt != '10x0x' then reserved = TRUE; end; end;

if reserved then var c : Constraint; (c, bt) = ConstrainUnpredictableBits{5}(Unpredictable_RESBPTYPE); assert c IN {Constraint_DISABLED, Constraint_UNKNOWN}; if c == Constraint_DISABLED then return (c, ARBITRARY : bits(5)); // Otherwise the value returned by ConstrainUnpredictableBits must be a not-reserved value end; end;

return (Constraint_NONE, bt);

end;


## Library pseudocode for aarch64/debug/breakpoint/AArch64\_StateMatch

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

func AArch64_StateMatch(ssc_in : bits(2), ssce_in : bit, hmc_in : bit, pxc_in : bits(2), linked_in : boolean, linked_n_in : integer, isbreakpnt : boolean, vaddress : bits(64), accdesc : AccessDescriptor) => boolean begin if !IsFeatureImplemented(FEAT_RME) then assert ssce_in == '0'; end;

// "ssc_in","ssce_in","hmc_in","pxc_in" are the control fields from
// the DBGBCR_EL1(n) or DBGWCR_EL1(n) register.
// "linked_in" is TRUE if this is a linked breakpoint/watchpoint type.
// "linked_n_in" is the linked breakpoint number from the DBGBCR_EL1(n) or
// DBGWCR_EL1(n) register.
// "isbreakpnt" is TRUE for breakpoints, FALSE for watchpoints.
// "vaddress" is the program counter for a linked watchpoint or the same value passed to
// AArch64_CheckBreakpoint for a linked breakpoint.
// "accdesc" describes the properties of the access being matched.
var ssc : bits(2)      = ssc_in;
var ssce : bit         = ssce_in;
var hmc : bit          = hmc_in;
var pxc : bits(2)      = pxc_in;
let linked : boolean   = linked_in;
let linked_n : integer = linked_n_in;

// If parameters are set to a reserved type, behaves as either disabled or a defined type var c : Constraint; (c, ssc, ssce, hmc, pxc) = CheckValidStateMatch(ssc, ssce, hmc, pxc, isbreakpnt); if c == Constraint_DISABLED then return FALSE; end; // Otherwise the hmc,ssc,ssce,pxc values are either valid or the values returned by // CheckValidStateMatch are valid.

let EL3_match : boolean = HaveEL(EL3) && hmc == '1' && ssc[0] == '0'; let EL2_match : boolean = HaveEL(EL2) && ((hmc == '1' && (ssc::pxc != '1000')) || ssc == '11'); let EL1_match : boolean = pxc[0] == '1'; let EL0_match : boolean = pxc[1] == '1';

var priv_match : boolean; case accdesc.el of when EL3 => priv_match = EL3_match; when EL2 => priv_match = EL2_match; when EL1 => priv_match = EL1_match; when EL0 => priv_match = EL0_match; end;

// Security state match var ss_match : boolean; case ssce::ssc of when '000' => ss_match = hmc == '1' || accdesc.ss != SS_Root; when '001' => ss_match = accdesc.ss == SS_NonSecure; when '010' => ss_match = (hmc == '1' && accdesc.ss == SS_Root) || accdesc.ss == SS_Secure; when '011' => ss_match = (hmc == '1' && accdesc.ss != SS_Root) || accdesc.ss == SS_Secure; when '101' => ss_match = accdesc.ss == SS_Realm; end;

var linked_match : boolean = FALSE;

if linked then // "linked_n" must be an enabled context-aware breakpoint unit. If it is not context-aware // then it is CONSTRAINED UNPREDICTABLE whether this gives no match, gives a match without // linking, or linked_n is mapped to some UNKNOWN breakpoint that is context-aware. if ((linked_n) && (isbreakpnt || (linked_n))) then return ConstrainUnpredictableBool(Unpredictable_BPNOTLINKING); end; end;

if linked then let linked_to : boolean = TRUE; var bp_type : BreakpointType; let from_linking_enabled : boolean = FALSE; (bp_type, linked_match) = AArch64_BreakpointValueMatch(linked_n, vaddress, linked_to, isbreakpnt, from_linking_enabled); if bp_type == BreakpointType_AddrMismatch then linked_match = !linked_match; end; end;

return priv_match && ss_match && (!linked || linked_match);

end;


## Library pseudocode for aarch64/debug/breakpoint/DebugAddrTop

// DebugAddrTop // ============== // Returns the value for the top bit used in Breakpoint and Watchpoint address comparisons.

func DebugAddrTop() => AddressSize begin if IsFeatureImplemented(FEAT_LVA3) then return 55; elsif IsFeatureImplemented(FEAT_LVA) then return 52; else return 48; end; end;


## Library pseudocode for aarch64/debug/breakpoint/EffectiveMDSELR\_EL1\_BANK

// EffectiveMDSELR_EL1_BANK // ========================== // Return the effective value of MDSELR_EL1.BANK.

func EffectiveMDSELR_EL1_BANK() => bits(2) begin // If 16 or fewer breakpoints and 16 or fewer watchpoints are implemented, // then the field is RES0. let num_bp : integer = NumBreakpointsImplemented(); let num_wp : integer = NumWatchpointsImplemented(); if num_bp <= 16 && num_wp <= 16 then return '00'; end;

// At EL3, the Effective value of this field is zero if MDCR_EL3.EBWE is 0.
// At EL2, the Effective value is zero if the Effective value of MDCR_EL2.EBWE is 0.
// That is, if either MDCR_EL3.EBWE is 0 or MDCR_EL2.EBWE is 0.
// At EL1, the Effective value is zero if the Effective value of MDSCR_EL2.EMBWE is 0.
// That is, if any of MDCR_EL3.EBWE, MDCR_EL2.EBWE, or MDSCR_EL1.EMBWE is 0.
if ((HaveEL(EL3) && MDCR_EL3().EBWE == '0') ||
      (PSTATE.EL != EL3 && EL2Enabled() && MDCR_EL2().EBWE == '0') ||
      (PSTATE.EL == EL1 && MDSCR_EL1().EMBWE == '0')) then
    return '00';
end;

var bank : bits(2) = MDSELR_EL1().BANK;

// Values are reserved depending on the number of breakpoints or watchpoints // implemented. if ((bank == '11' && num_bp <= 48 && num_wp <= 48) || (bank == '10' && num_bp <= 32 && num_wp <= 32)) then // Reserved value (-, bank) = ConstrainUnpredictableBits{2}(Unpredictable_RESMDSELR); // The value returned by ConstrainUnpredictableBits must be a not-reserved value end;

return bank;

end;


## Library pseudocode for aarch64/debug/breakpoint/IsAddressLinkingBreakpoint

// IsAddressLinkingBreakpoint // ============================ // Returns TRUE if DBGBCR_EL1(n) supports being configured as an Address matching breakpoint with // linking enabled.

func IsAddressLinkingBreakpoint(n : integer) => boolean begin return n < NumAddressLinkingBreakpointsImplemented(); end;


## Library pseudocode for aarch64/debug/breakpoint/IsBreakpointEnabled

// IsBreakpointEnabled // ===================== // Returns TRUE if the effective value of DBGBCR_EL1(n).E is '1', and FALSE otherwise.

func IsBreakpointEnabled(n : integer) => boolean begin if (n > 15 && ((() && ()) || (HaltOnBreakpointOrWatchpoint() && EDSCR2().EHBWE == '0'))) then return FALSE; end;

return DBGBCR_EL1(n).E == '1';

end;


## Library pseudocode for aarch64/debug/breakpoint/NumAddressLinkingBreakpointsImplemented

// NumAddressLinkingBreakpointsImplemented // ========================================= // Returns the number of breakpoints that support being configured as Address matching breakpoint // with linking enabled, as described by ID_AA64DFR1_EL1().ABL_CMPs.

func NumAddressLinkingBreakpointsImplemented() => integer begin if !IsFeatureImplemented(FEAT_ABLE) then return 0; else return ImpDefInt("Number of address-linking breakpoints"); end; end;


## Library pseudocode for aarch64/debug/breakpoint/SelfHostedExtendedBPWPEnabled

// SelfHostedExtendedBPWPEnabled // =============================== // Returns TRUE if the extended breakpoints and watchpoints are enabled, and FALSE otherwise // from a self-hosted debug perspective.

func SelfHostedExtendedBPWPEnabled() => boolean begin if NumBreakpointsImplemented() <= 16 && NumWatchpointsImplemented() <= 16 then return FALSE; end;

if ((HaveEL(EL3) && MDCR_EL3().EBWE == '0') ||
      (EL2Enabled() && MDCR_EL2().EBWE == '0')) then
    return FALSE;
end;

return MDSCR_EL1().EMBWE == '1';

end;


## Library pseudocode for aarch64/debug/ebep/CheckForPMUException

// CheckForPMUException // ====================== // Take a PMU exception if enabled, permitted, and unmasked.

func CheckForPMUException begin var enabled : boolean; var target_el : bits(2); var pmu_exception : boolean; var synchronous : boolean; (enabled, target_el) = PMUExceptionEnabled(); if !enabled || PMUExceptionMasked(target_el, PSTATE.EL, PSTATE.PM) then pmu_exception = FALSE; else let include_r1 : boolean = TRUE; let include_r2 : boolean = TRUE; let include_r3 : boolean = TRUE; pmu_exception = CheckPMUOverflowCondition(PMUOverflowCondition_PMUException, include_r1, include_r2, include_r3); synchronous = FALSE; end; if pmu_exception then let fsc : bits(5) = '00000'; TakeProfilingException(target_el, fsc, synchronous); end; end;


## Library pseudocode for aarch64/debug/ebep/EffectivePMEE

// EffectivePMEE // =============== // Return the Effective value of PMEE from MDCR_ELx or PMECR_EL1, handling reserved encodings: // '10' (MDCR_ELx), '10' and '01' (PMECR_EL1).

func EffectivePMEE(el : bits(2), for_interrupt : boolean) => bits(2) begin var val : bits(2); case el of when EL1 => val = PMECR_EL1().PMEE; when EL2 => val = MDCR_EL2().PMEE; when EL3 => val = MDCR_EL3().PMEE; otherwise => unreachable; end;

if (val == '10' || (el == EL1 && val == '01')) then    var c : Constraint;    (c, val) = ConstrainUnpredictableBits{2}(Unpredictable_RESPMEE);    assert c IN {Constraint_DISABLED, Constraint_UNKNOWN};    if c == Constraint_DISABLED then        val = if for_interrupt then '11' else '00';        // Otherwise the value returned by ConstrainUnpredictableBits must be        // a non-reserved value    end;end;return val;

end;


## Library pseudocode for aarch64/debug/ebep/PMUExceptionEnabled

// PMUExceptionEnabled // ===================== // The first return value is TRUE if the PMU exception is enabled, and FALSE otherwise. // The second return value is the target Exception level for an enabled PMU exception.

func PMUExceptionEnabled() => (boolean, bits(2)) begin

if !IsFeatureImplemented(FEAT_EBEP) then
    return (FALSE, ARBITRARY : bits(2));
end;

var enabled : boolean; var target : bits(2) = ARBITRARY : bits(2); let for_interrupt : boolean = FALSE; let pmee_el3 : bits(2) = EffectivePMEE(EL3, for_interrupt); let pmee_el2 : bits(2) = EffectivePMEE(EL2, for_interrupt); let pmee_el1 : bits(2) = EffectivePMEE(EL1, for_interrupt);

if HaveEL(EL3) && pmee_el3 != '01' then enabled = pmee_el3 == '11'; if enabled then target = EL3; end;

elsif EL2Enabled() && pmee_el2 != '01' then enabled = pmee_el2 == '11'; if enabled then target = EL2; end;

else enabled = pmee_el1 == '11'; if enabled then target = if EL2Enabled() && HCR_EL2().TGE == '1' then EL2 else EL1; end; end;

return (enabled, target);

end;


## Library pseudocode for aarch64/debug/ebep/PMUExceptionMasked

// PMUExceptionMasked // ==================== // Return TRUE if the PMU Exception is masked at the specified target Exception level // relative to the specified source Exception level, and by the value of PSTATE.PM, // and FALSE otherwise.

func PMUExceptionMasked(target_el : bits(2), from_el : bits(2), pm : bit) => boolean begin assert IsFeatureImplemented(FEAT_EBEP); let for_interrupt : boolean = FALSE;

if Halted() then
    return TRUE;
elsif UInt(target_el) < UInt(from_el) then
    return TRUE;
elsif (from_el == EL2 && target_el == EL2 &&
         EffectivePMEE(EL2, for_interrupt) != '11') then
    return TRUE;
elsif target_el == from_el && (PMECR_EL1().KPME == '0' || pm == '1') then
    return TRUE;
end;

return FALSE;

end;


## Library pseudocode for aarch64/debug/ebep/PMUInterruptEnabled

// PMUInterruptEnabled // ===================== // Return TRUE if the PMU interrupt request (PMUIRQ) is enabled, FALSE otherwise.

func PMUInterruptEnabled() => boolean begin if !IsFeatureImplemented(FEAT_EBEP) then return TRUE; end;

var enabled : boolean;
let for_interrupt : boolean = TRUE;
let pmee_el3 : bits(2) = EffectivePMEE(EL3, for_interrupt);
let pmee_el2 : bits(2) = EffectivePMEE(EL2, for_interrupt);
let pmee_el1 : bits(2) = EffectivePMEE(EL1, for_interrupt);

if HaveEL(EL3) && pmee_el3 != '01' then enabled = pmee_el3 == '00';

elsif EL2Enabled() && pmee_el2 != '01' then enabled = pmee_el2 == '00';

else enabled = pmee_el1 == '00'; end;

return enabled;

end;


## Library pseudocode for aarch64/debug/enables/AArch64\_GenerateDebugExceptions

// AArch64_GenerateDebugExceptions // =================================

func AArch64_GenerateDebugExceptions() => boolean begin

Log in to reply.