<?xml version="1.0" ?><?xml-stylesheet type="text/xsl" encoding="UTF-8" href="iform.xsl" version="1.0"?><!DOCTYPE instructionsection  PUBLIC '-//ARM//DTD instructionsection //EN'  'sharedps.dtd'><!-- Copyright (c) 2010-2026 Arm Limited or its affiliates. All rights reserved. --><!-- This document is Non-Confidential. This document may only be used and distributed in accordance with the terms of the agreement entered into by Arm and the party that Arm delivered this document to. --><instructionsection id="shared_pseudocode" title="Shared Pseudocode" type="pseudocode">
  <heading>Shared Pseudocode Functions</heading>
  <desc>
    <brief>This page displays common pseudocode functions shared by many pages</brief>
  </desc>
  <ps_section howmany="1741">
    <ps name="aarch32/at/AArch32_AT" mylink="aarch32.at.AArch32_AT" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_AT()
// ============
// Perform address translation as per AT instructions.

func <anchor link="func_AArch32_AT_4">AArch32_AT</anchor>(vaddress : bits(32), stage_in : <a link="type_TranslationStage" file="shared_pseudocode.xml">TranslationStage</a>, el : bits(2), ataccess : <a link="type_ATAccess" file="shared_pseudocode.xml">ATAccess</a>)
begin
    var stage : <a link="type_TranslationStage" file="shared_pseudocode.xml">TranslationStage</a> = stage_in;
    var ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>;
    var regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>;
    var eae : boolean;

    // ATS1Hx instructions
    if el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
        regime = <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a>;
        eae = TRUE;
        ss = <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a>;

    // ATS1Cxx instructions
    elsif stage == <a link="enum_TranslationStage_1" file="shared_pseudocode.xml">TranslationStage_1</a> || (stage == <a link="enum_TranslationStage_12" file="shared_pseudocode.xml">TranslationStage_12</a> &amp;&amp; !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>)) then
        stage = <a link="enum_TranslationStage_1" file="shared_pseudocode.xml">TranslationStage_1</a>;
        ss = <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
        regime = if ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a> else <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a>;
        eae = TTBCR().EAE == '1';

    // ATS12NSOxx instructions
    else
        regime = <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a>;
        eae = (if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then TTBCR_NS().EAE == '1'
                                                     else TTBCR().EAE == '1');
        ss = <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a>;
    end;

    var addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    var sdftype : <a link="type_SDFType" file="shared_pseudocode.xml">SDFType</a>;
    let aligned : boolean = TRUE;
    var supersection : bit = '0';

    let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescAT_3" file="shared_pseudocode.xml">CreateAccDescAT</a>(ss, el, ataccess);

    // Prepare fault fields in case a fault is detected
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_2" file="shared_pseudocode.xml">NoFault</a>(accdesc, ZeroExtend{64}(vaddress));

    if eae then
        (fault, addrdesc) = <a link="func_AArch32_S1TranslateLD_5" file="shared_pseudocode.xml">AArch32_S1TranslateLD</a>(fault, regime, vaddress, aligned, accdesc);
    else
        (fault, addrdesc, sdftype) = <a link="func_AArch32_S1TranslateSD_5" file="shared_pseudocode.xml">AArch32_S1TranslateSD</a>(fault, regime, vaddress, aligned,
                                                           accdesc);
        supersection = if sdftype == <a link="enum_SDFType_Supersection" file="shared_pseudocode.xml">SDFType_Supersection</a> then '1' else '0';
    end;

    // ATS12NSOxx instructions
    if stage == <a link="enum_TranslationStage_12" file="shared_pseudocode.xml">TranslationStage_12</a> &amp;&amp; fault.statuscode == <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        (fault, addrdesc) = <a link="func_AArch32_S2Translate_4" file="shared_pseudocode.xml">AArch32_S2Translate</a>(fault, addrdesc, aligned, accdesc);
    end;

    if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        // Take exception on External abort or when a fault occurs on translation table walk
        if <a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) || (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; fault.s2fs1walk) then
            PAR() = ARBITRARY : bits(64);
            <a link="func_AArch32_Abort_1" file="shared_pseudocode.xml">AArch32_Abort</a>(fault);
        end;
    end;

    addrdesc.fault = fault;

    if (eae || (stage == <a link="enum_TranslationStage_12" file="shared_pseudocode.xml">TranslationStage_12</a> &amp;&amp; (HCR().VM == '1' || HCR().DC == '1'))
            || (stage == <a link="enum_TranslationStage_1" file="shared_pseudocode.xml">TranslationStage_1</a> &amp;&amp; el != <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>)) then
        <a link="func_AArch32_EncodePARLD_2" file="shared_pseudocode.xml">AArch32_EncodePARLD</a>(addrdesc, ss);
    else
        <a link="func_AArch32_EncodePARSD_3" file="shared_pseudocode.xml">AArch32_EncodePARSD</a>(addrdesc, supersection, ss);
    end;
    return;
end;</pstext></ps>
    <ps name="aarch32/at/AArch32_EncodePARLD" mylink="aarch32.at.AArch32_EncodePARLD" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_EncodePARLD()
// =====================
// Returns 64-bit format PAR on address translation instruction.

func <anchor link="func_AArch32_EncodePARLD_2">AArch32_EncodePARLD</anchor>(addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>)
begin
    PAR()[63:0] = Zeros{64};
    if !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(addrdesc) then
        var ns : bit;
        if ss == <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> then
            ns = ARBITRARY : bit;
        elsif addrdesc.paddress.paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> then
            ns = '0';
        else
            ns = '1';
        end;
        PAR().F      = '0';
        PAR().SH     = <a link="func_ReportedPARShareability_1" file="shared_pseudocode.xml">ReportedPARShareability</a>(<a link="func_PAREncodeShareability_1" file="shared_pseudocode.xml">PAREncodeShareability</a>(addrdesc.memattrs));
        PAR().NS     = ns;
        PAR()[10]    = ImpDefBit(&quot;Non-Faulting PAR&quot;);               // IMPDEF
        PAR().LPAE   = '1';
        PAR().PA     = addrdesc.paddress.address[39:12];
        PAR().ATTR   = <a link="func_ReportedPARAttrs_1" file="shared_pseudocode.xml">ReportedPARAttrs</a>(<a link="func_EncodePARAttrs_1" file="shared_pseudocode.xml">EncodePARAttrs</a>(addrdesc.memattrs));
    else
        PAR().F      = '1';
        PAR().FST    = <a link="func_AArch32_PARFaultStatusLD_1" file="shared_pseudocode.xml">AArch32_PARFaultStatusLD</a>(addrdesc.fault);
        PAR().S2WLK  = if addrdesc.fault.s2fs1walk then '1' else '0';
        PAR().FSTAGE = if addrdesc.fault.secondstage then '1' else '0';
        PAR().LPAE   = '1';
        PAR()[63:48] = ImpDefBits{16}(&quot;Faulting PAR&quot;);             // IMPDEF
    end;
    return;
end;</pstext></ps>
    <ps name="aarch32/at/AArch32_EncodePARSD" mylink="aarch32.at.AArch32_EncodePARSD" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_EncodePARSD()
// =====================
// Returns 32-bit format PAR on address translation instruction.

func <anchor link="func_AArch32_EncodePARSD_3">AArch32_EncodePARSD</anchor>(addrdesc_in : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, supersection : bit, ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>)
begin
    PAR()[31:0] = Zeros{32};
    var addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = addrdesc_in;
    if !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(addrdesc) then
        if (addrdesc.memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> ||
                (addrdesc.memattrs.inner.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> &amp;&amp;
                 addrdesc.memattrs.outer.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>)) then
            addrdesc.memattrs.shareability = <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
        end;
        var ns : bit;
        if ss == <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> then
            ns = ARBITRARY : bit;
        elsif addrdesc.paddress.paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> then
            ns = '0';
        else
            ns = '1';
        end;
        let sh : bits(2) = (if addrdesc.memattrs.shareability != <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a> then '01'
                               else '00');
        PAR().F      = '0';
        PAR().SS     = supersection;
        PAR().Outer  = <a link="func_AArch32_ReportedOuterAttrs_1" file="shared_pseudocode.xml">AArch32_ReportedOuterAttrs</a>(<a link="func_AArch32_PAROuterAttrs_1" file="shared_pseudocode.xml">AArch32_PAROuterAttrs</a>(addrdesc.memattrs));
        PAR().Inner  = <a link="func_AArch32_ReportedInnerAttrs_1" file="shared_pseudocode.xml">AArch32_ReportedInnerAttrs</a>(<a link="func_AArch32_PARInnerAttrs_1" file="shared_pseudocode.xml">AArch32_PARInnerAttrs</a>(addrdesc.memattrs));
        PAR().SH     = <a link="func_ReportedPARShareability_1" file="shared_pseudocode.xml">ReportedPARShareability</a>(sh);
        PAR()[8]     = ImpDefBit(&quot;Non-Faulting PAR&quot;);               // IMPDEF
        PAR().NS     = ns;
        PAR().NOS    = if addrdesc.memattrs.shareability == <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a> then '0' else '1';
        PAR().LPAE   = '0';
        PAR().PA     = addrdesc.paddress.address[39:12];
    else
        PAR().F      = '1';
        PAR().FST    = <a link="func_AArch32_PARFaultStatusSD_1" file="shared_pseudocode.xml">AArch32_PARFaultStatusSD</a>(addrdesc.fault);
        PAR().LPAE   = '0';
        PAR()[31:16] = ImpDefBits{16}(&quot;Faulting PAR&quot;);              // IMPDEF
    end;
    return;
end;</pstext></ps>
    <ps name="aarch32/at/AArch32_PARFaultStatusLD" mylink="aarch32.at.AArch32_PARFaultStatusLD" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_PARFaultStatusLD()
// ==========================
// Fault status field decoding of 64-bit PAR

func <anchor link="func_AArch32_PARFaultStatusLD_1">AArch32_PARFaultStatusLD</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; bits(6)
begin
    var syndrome : bits(6);
    if fault.statuscode == <a link="enum_Fault_Domain" file="shared_pseudocode.xml">Fault_Domain</a> then
        // Report Domain fault
        assert fault.level IN {1,2};
        syndrome[1:0] = if fault.level == 1 then '01' else '10';
        syndrome[5:2] = '1111';
    else
        syndrome = <a link="func_EncodeLDFSC_2" file="shared_pseudocode.xml">EncodeLDFSC</a>(fault.statuscode, fault.level);
    end;
    return syndrome;
end;</pstext></ps>
    <ps name="aarch32/at/AArch32_PARFaultStatusSD" mylink="aarch32.at.AArch32_PARFaultStatusSD" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_PARFaultStatusSD()
// ==========================
// Fault status field decoding of 32-bit PAR.

func <anchor link="func_AArch32_PARFaultStatusSD_1">AArch32_PARFaultStatusSD</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; bits(6)
begin
    var syndrome : bits(6);

    syndrome[5] = if <a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) then fault.extflag else '0';
    syndrome[4:0] = <a link="func_EncodeSDFSC_2" file="shared_pseudocode.xml">EncodeSDFSC</a>(fault.statuscode, fault.level);
    return syndrome;
end;</pstext></ps>
    <ps name="aarch32/at/AArch32_PARInnerAttrs" mylink="aarch32.at.AArch32_PARInnerAttrs" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_PARInnerAttrs()
// =======================
// Convert orthogonal attributes and hints to 32-bit PAR Inner field.

func <anchor link="func_AArch32_PARInnerAttrs_1">AArch32_PARInnerAttrs</anchor>(memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>) =&gt; bits(3)
begin
    var result : bits(3);

    if memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> then
        if memattrs.device == <a link="enum_DeviceType_nGnRnE" file="shared_pseudocode.xml">DeviceType_nGnRnE</a> then
            result = '001'; // Non-cacheable
        elsif memattrs.device == <a link="enum_DeviceType_nGnRE" file="shared_pseudocode.xml">DeviceType_nGnRE</a> then
            result = '011'; // Non-cacheable
        end;
    else
        let inner : <a link="type_MemAttrHints" file="shared_pseudocode.xml">MemAttrHints</a> = memattrs.inner;
        if inner.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> then
            result = '000'; // Non-cacheable
        elsif inner.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a> &amp;&amp; inner.hints[0] == '1' then
            result = '101'; // Write-Back, Write-Allocate
        elsif inner.attrs == <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a> then
            result = '110'; // Write-Through
        elsif inner.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a> &amp;&amp; inner.hints[0] == '0' then
            result = '111'; // Write-Back, no Write-Allocate
        end;
    end;
    return result;
end;</pstext></ps>
    <ps name="aarch32/at/AArch32_PAROuterAttrs" mylink="aarch32.at.AArch32_PAROuterAttrs" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_PAROuterAttrs()
// =======================
// Convert orthogonal attributes and hints to 32-bit PAR Outer field.

func <anchor link="func_AArch32_PAROuterAttrs_1">AArch32_PAROuterAttrs</anchor>(memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>) =&gt; bits(2)
begin
    var result : bits(2);

    if memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> then
        result = ARBITRARY : bits(2);
    else
        let outer : <a link="type_MemAttrHints" file="shared_pseudocode.xml">MemAttrHints</a> = memattrs.outer;
        if outer.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> then
            result = '00'; // Non-cacheable
        elsif outer.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a> &amp;&amp; outer.hints[0] == '1' then
            result = '01'; // Write-Back, Write-Allocate
        elsif outer.attrs == <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a> &amp;&amp; outer.hints[0] == '0' then
            result = '10'; // Write-Through, no Write-Allocate
        elsif outer.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a> &amp;&amp; outer.hints[0] == '0' then
            result = '11'; // Write-Back, no Write-Allocate
        end;
    end;
    return result;
end;</pstext></ps>
    <ps name="aarch32/at/AArch32_ReportedInnerAttrs" mylink="aarch32.at.AArch32_ReportedInnerAttrs" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ReportedInnerAttrs()
// ============================
// The value returned in this field can be the resulting attribute, as determined by any permitted
// implementation choices and any applicable configuration bits, instead of the value that appears
// in the translation table descriptor.

impdef func <anchor link="func_AArch32_ReportedInnerAttrs_1">AArch32_ReportedInnerAttrs</anchor>(attrs : bits(3)) =&gt; bits(3)
begin
    return attrs;
end;</pstext></ps>
    <ps name="aarch32/at/AArch32_ReportedOuterAttrs" mylink="aarch32.at.AArch32_ReportedOuterAttrs" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ReportedOuterAttrs()
// ============================
// The value returned in this field can be the resulting attribute, as determined by any permitted
// implementation choices and any applicable configuration bits, instead of the value that appears
// in the translation table descriptor.

impdef func <anchor link="func_AArch32_ReportedOuterAttrs_1">AArch32_ReportedOuterAttrs</anchor>(attrs : bits(2)) =&gt; bits(2)
begin
    return attrs;
end;</pstext></ps>
    <ps name="aarch32/dc/AArch32_CanTrapDC" mylink="aarch32.dc.AArch32_CanTrapDC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CanTrapDC()
// ===================
// Determines whether the execution of the DC instruction can be trapped.

func <anchor link="func_AArch32_CanTrapDC_2">AArch32_CanTrapDC</anchor>(cacheop : <a link="type_CacheOp" file="shared_pseudocode.xml">CacheOp</a>, opscope : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a>) =&gt; boolean
begin
    return (!<a link="func_AArch32_TreatDCAsNOP_2" file="shared_pseudocode.xml">AArch32_TreatDCAsNOP</a>(cacheop, opscope) || ImpDefBool(
            &quot;When DC is treated as NOP, data cache maintenance operations are trapped&quot;));
end;</pstext></ps>
    <ps name="aarch32/dc/AArch32_DC" mylink="aarch32.dc.AArch32_DC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_DC()
// ============
// Perform Data Cache Operation.

func <anchor link="func_AArch32_DC_3">AArch32_DC</anchor>(regval : bits(32), cacheop : <a link="type_CacheOp" file="shared_pseudocode.xml">CacheOp</a>, opscope : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a>)
begin
    var cache : <a link="type_CacheRecord" file="shared_pseudocode.xml">CacheRecord</a>;

    cache.acctype   = <a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>;
    cache.cacheop   = cacheop;
    cache.opscope   = opscope;
    cache.cachetype = <a link="enum_CacheType_Data" file="shared_pseudocode.xml">CacheType_Data</a>;
    cache.security  = <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);

    if opscope == <a link="enum_CacheOpScope_SetWay" file="shared_pseudocode.xml">CacheOpScope_SetWay</a> then
        cache.shareability = <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a>;
        cache.(setnum, waynum, level) = <a link="func_DecodeSW_2" file="shared_pseudocode.xml">DecodeSW</a>(ZeroExtend{64}(regval),
                                                             <a link="enum_CacheType_Data" file="shared_pseudocode.xml">CacheType_Data</a>);

        if (cacheop == <a link="enum_CacheOp_Invalidate" file="shared_pseudocode.xml">CacheOp_Invalidate</a> &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
              ((!<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; (HCR_EL2().SWIO == '1' || HCR_EL2().[DC,VM] != '00')) ||
                 (<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; (HCR().SWIO == '1' || HCR().[DC,VM] != '00')))) then
            cache.cacheop = <a link="enum_CacheOp_CleanInvalidate" file="shared_pseudocode.xml">CacheOp_CleanInvalidate</a>;
        end;
        CACHE_OP(cache);
        return;
    end;

    if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} then
            cache.is_vmid_valid = TRUE;
            cache.vmid          = <a link="func_VMID_0" file="shared_pseudocode.xml">VMID</a>();
        else
            cache.is_vmid_valid = FALSE;
        end;
    else
        cache.is_vmid_valid = FALSE;
    end;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        cache.is_asid_valid = TRUE;
        cache.asid          = <a link="func_ASID_0" file="shared_pseudocode.xml">ASID</a>();
    else
        cache.is_asid_valid = FALSE;
    end;

    var vaddress : bits(32) = regval;

    var size : integer = 0;        // by default no watchpoint address
    if cacheop == <a link="enum_CacheOp_Invalidate" file="shared_pseudocode.xml">CacheOp_Invalidate</a> then
        size     = <a link="func_DataCacheWatchpointSize_0" file="shared_pseudocode.xml">DataCacheWatchpointSize</a>();
        vaddress = AlignDownSize{32}(regval, size as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>);
    end;

    cache.vaddress = ZeroExtend{64}(vaddress);

    let aligned : boolean               = TRUE;
    let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>      = <a link="func_CreateAccDescDC_1" file="shared_pseudocode.xml">CreateAccDescDC</a>(cache);
    var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_AArch32_TranslateAddress_4" file="shared_pseudocode.xml">AArch32_TranslateAddress</a>(vaddress, accdesc,
                                                                   aligned, size);
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        memaddrdesc.fault.vaddress = ZeroExtend{64}(regval);
        <a link="func_AArch32_Abort_1" file="shared_pseudocode.xml">AArch32_Abort</a>(memaddrdesc.fault);
    end;

    cache.paddress = memaddrdesc.paddress;
    if opscope == <a link="enum_CacheOpScope_PoC" file="shared_pseudocode.xml">CacheOpScope_PoC</a> then
        cache.shareability = memaddrdesc.memattrs.shareability;
    else
        cache.shareability = <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a>;
    end;

    if (cacheop == <a link="enum_CacheOp_Invalidate" file="shared_pseudocode.xml">CacheOp_Invalidate</a> &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
          ((!<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; HCR_EL2().[DC,VM] != '00') ||
             (<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; HCR().[DC,VM] != '00'))) then
        cache.cacheop = <a link="enum_CacheOp_CleanInvalidate" file="shared_pseudocode.xml">CacheOp_CleanInvalidate</a>;
    end;

    CACHE_OP(cache);
    return;
end;</pstext></ps>
    <ps name="aarch32/dc/AArch32_TreatDCAsNOP" mylink="aarch32.dc.AArch32_TreatDCAsNOP" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TreatDCAsNOP()
// ======================
// Determines whether the execution of the DC instruction is treated as a NOP.

func <anchor link="func_AArch32_TreatDCAsNOP_2">AArch32_TreatDCAsNOP</anchor>(cacheop : <a link="type_CacheOp" file="shared_pseudocode.xml">CacheOp</a>, opscope : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a>) =&gt; boolean
begin
    // DC to PoU: IMPLEMENTATION DEFINED - treated as NOP if LoUU and LoUIS are 0
    if opscope == <a link="enum_CacheOpScope_PoU" file="shared_pseudocode.xml">CacheOpScope_PoU</a> &amp;&amp; CLIDR().LoUU == '000' &amp;&amp; CLIDR().LoUIS == '000' then
        return ImpDefBool(&quot;DC to PoU is treated as a NOP&quot;);
    end;

    // DC to PoC: IMPLEMENTATION DEFINED - treated as NOP if LoC is 0
    if opscope == <a link="enum_CacheOpScope_PoC" file="shared_pseudocode.xml">CacheOpScope_PoC</a> &amp;&amp; CLIDR().LoC == '000' then
        return ImpDefBool(&quot;DC to PoC is treated as a NOP&quot;);
    end;

    return FALSE;
end;</pstext></ps>
    <ps name="aarch32/debug/VCRMatch/AArch32_VCRMatch" mylink="aarch32.debug.VCRMatch.AArch32_VCRMatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_VCRMatch()
// ==================

func <anchor link="func_AArch32_VCRMatch_1">AArch32_VCRMatch</anchor>(vaddress : bits(32)) =&gt; boolean
begin

    var match : boolean;
    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
        // Each bit position in this string corresponds to a bit in DBGVCR and an exception vector.
        var match_word : bits(32) = Zeros{};

        let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>();
        if vaddress[31:5] == <a link="func_ExcVectorBase_0" file="shared_pseudocode.xml">ExcVectorBase</a>()[31:5] then
            if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; ss == <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> then
                match_word[UInt(vaddress[4:2]) + 24] = '1';     // Non-secure vectors
            else
                match_word[UInt(vaddress[4:2]) + 0] = '1';      // Secure vectors (or no EL3)
            end;
        end;
        if (<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; vaddress[31:5] == MVBAR()[31:5] &amp;&amp;
            ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>) then
            match_word[UInt(vaddress[4:2]) + 8] = '1';          // Monitor vectors
        end;
        // Mask out bits not corresponding to vectors.
        var mask : bits(32);
        if !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
            mask = '00000000'::'00000000'::'00000000'::'11011110'; // DBGVCR[31:8] are RES0
        elsif !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
            mask = '11011110'::'00000000'::'00000000'::'11011110'; // DBGVCR[15:8] are RES0
        else
            mask = '11011110'::'00000000'::'11011100'::'11011110';
        end;

        match_word = match_word AND DBGVCR() AND mask;
        match = !IsZero(match_word);

        // Check for UNPREDICTABLE case - match on Prefetch Abort and Data Abort vectors
        if !IsZero(match_word[28:27,12:11,4:3]) &amp;&amp; <a link="func_DebugTarget_0" file="shared_pseudocode.xml">DebugTarget</a>() == <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL then
            match = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_VCMATCHDAPA" file="shared_pseudocode.xml">Unpredictable_VCMATCHDAPA</a>);
        end;

        if !IsZero(vaddress[1:0]) &amp;&amp; match then
            match = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_VCMATCHHALF" file="shared_pseudocode.xml">Unpredictable_VCMATCHHALF</a>);
        end;
    else
        match = FALSE;
    end;

    return match;
end;</pstext></ps>
    <ps name="aarch32/debug/authentication/AArch32_SelfHostedSecurePrivilegedInvasiveDebugEnabled" mylink="aarch32.debug.authentication.AArch32_SelfHostedSecurePrivilegedInvasiveDebugEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_SelfHostedSecurePrivilegedInvasiveDebugEnabled()
// ========================================================

func <anchor link="func_AArch32_SelfHostedSecurePrivilegedInvasiveDebugEnabled_0">AArch32_SelfHostedSecurePrivilegedInvasiveDebugEnabled</anchor>() =&gt; boolean
begin
    // The definition of this function is IMPLEMENTATION DEFINED.
    // In the recommended interface, AArch32_SelfHostedSecurePrivilegedInvasiveDebugEnabled returns
    // the state of the (DBGEN AND SPIDEN) signal.
    if !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_NonSecureOnlyImplementation_0" file="shared_pseudocode.xml">NonSecureOnlyImplementation</a>() then return FALSE; end;
    return <a link="global_DBGEN" file="shared_pseudocode.xml">DBGEN</a> == <a link="enum_HIGH" file="shared_pseudocode.xml">HIGH</a> &amp;&amp; <a link="global_SPIDEN" file="shared_pseudocode.xml">SPIDEN</a> == <a link="enum_HIGH" file="shared_pseudocode.xml">HIGH</a>;
end;</pstext></ps>
    <ps name="aarch32/debug/breakpoint/AArch32_BreakpointMatch" mylink="aarch32.debug.breakpoint.AArch32_BreakpointMatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_BreakpointMatch()
// =========================
// Breakpoint matching in an AArch32 translation regime.

func <anchor link="func_AArch32_BreakpointMatch_4">AArch32_BreakpointMatch</anchor>(n : integer, vaddress : bits(32), accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                             size : integer) =&gt; <a link="type_BreakpointInfo" file="shared_pseudocode.xml">BreakpointInfo</a>
begin
    assert <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>());
    assert n &lt; <a link="func_NumBreakpointsImplemented_0" file="shared_pseudocode.xml">NumBreakpointsImplemented</a>();

    var brkptinfo : <a link="type_BreakpointInfo" file="shared_pseudocode.xml">BreakpointInfo</a>;
    let enabled : boolean    = DBGBCR(n).E == '1';
    let isbreakpnt : boolean = TRUE;
    let linked : boolean     = DBGBCR(n).BT == '0x01';
    let linked_to : boolean  = FALSE;
    let linked_n : integer{} = UInt(DBGBCR(n).LBN);

    let state_match : boolean = <a link="func_AArch32_StateMatch_7" file="shared_pseudocode.xml">AArch32_StateMatch</a>(DBGBCR(n).SSC, DBGBCR(n).HMC, DBGBCR(n).PMC,
                                                   linked, linked_n, isbreakpnt,  accdesc);
    var (value_match, value_mismatch) = <a link="func_AArch32_BreakpointValueMatch_3" file="shared_pseudocode.xml">AArch32_BreakpointValueMatch</a>(n,vaddress, linked_to);

    if 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 this breakpoint generates a Breakpoint debug
        // event.
        let (match_i, mismatch_i) = <a link="func_AArch32_BreakpointValueMatch_3" file="shared_pseudocode.xml">AArch32_BreakpointValueMatch</a>(n, vaddress + 2, linked_to);

        if !value_match &amp;&amp; match_i then
            value_match = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BPMATCHHALF" file="shared_pseudocode.xml">Unpredictable_BPMATCHHALF</a>);
        end;

        if value_mismatch &amp;&amp; !mismatch_i then
            value_mismatch = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BPMISMATCHHALF" file="shared_pseudocode.xml">Unpredictable_BPMISMATCHHALF</a>);
        end;
    end;

    if vaddress[1] == '1' &amp;&amp; DBGBCR(n).BAS == '1111' then
        // The above notwithstanding, if DBGBCR(n).BAS == '1111', then it is CONSTRAINED
        // UNPREDICTABLE whether or not a Breakpoint debug event is generated for an instruction
        // at the address DBGBVR(n)+2.
        if value_match then
            value_match = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BPMATCHHALF" file="shared_pseudocode.xml">Unpredictable_BPMATCHHALF</a>);
        end;

        if !value_mismatch then
            value_mismatch = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BPMISMATCHHALF" file="shared_pseudocode.xml">Unpredictable_BPMISMATCHHALF</a>);
        end;
    end;

    brkptinfo.match    = value_match &amp;&amp; state_match &amp;&amp; enabled;
    brkptinfo.mismatch = value_mismatch &amp;&amp; state_match &amp;&amp; enabled;

    return brkptinfo;
end;</pstext></ps>
    <ps name="aarch32/debug/breakpoint/AArch32_BreakpointValueMatch" mylink="aarch32.debug.breakpoint.AArch32_BreakpointValueMatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_BreakpointValueMatch()
// ==============================
// The first result is whether an Address Match or Context breakpoint is programmed on the
// instruction at &quot;address&quot;. The second result is whether an Address Mismatch breakpoint is
// programmed on the instruction, that is, whether the instruction should be stepped.

func <anchor link="func_AArch32_BreakpointValueMatch_3">AArch32_BreakpointValueMatch</anchor>(n_in : integer, vaddress : bits(32),
                                  linked_to : boolean) =&gt; (boolean, boolean)
begin

    // &quot;n&quot; is the identity of the breakpoint unit to match against.
    // &quot;vaddress&quot; is the current instruction address, ignored if linked_to is TRUE and for Context
    //   matching breakpoints.
    // &quot;linked_to&quot; is TRUE if this is a call from StateMatch for linking.
    var n : integer = n_in;
    var c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>;

    // 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 &gt;= <a link="func_NumBreakpointsImplemented_0" file="shared_pseudocode.xml">NumBreakpointsImplemented</a>() then
        (c, n) = <a link="func_ConstrainUnpredictableInteger_3" file="shared_pseudocode.xml">ConstrainUnpredictableInteger</a>(0, <a link="func_NumBreakpointsImplemented_0" file="shared_pseudocode.xml">NumBreakpointsImplemented</a>() - 1,
                                               <a link="enum_Unpredictable_BPNOTIMPL" file="shared_pseudocode.xml">Unpredictable_BPNOTIMPL</a>);
        assert c IN {<a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>, <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>};
        if c == <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a> then return (FALSE, 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 DBGBCR(n).E == '0' then return (FALSE, FALSE); end;

    var dbgtype : bits(4) = DBGBCR(n).BT;

    (c, dbgtype) = <a link="func_AArch32_ReservedBreakpointType_2" file="shared_pseudocode.xml">AArch32_ReservedBreakpointType</a>(n, dbgtype);
    if c == <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a> then return (FALSE, FALSE); end;
    // Otherwise the dbgtype value returned by AArch32_ReservedBreakpointType is valid.

    // Determine what to compare against.
    let match_addr : boolean      = (dbgtype == '0x0x');
    let mismatch : boolean        = (dbgtype == '010x');
    let match_vmid : boolean      = (dbgtype == '10xx');
    let match_cid1 : boolean      = (dbgtype == 'xx1x');
    let match_cid2 : boolean      = (dbgtype == '11xx');
    let linking_enabled : boolean = (dbgtype == 'xxx1');

    // If called from StateMatch, is CONSTRAINED UNPREDICTABLE if the
    // breakpoint is not programmed with linking enabled.
    if linked_to &amp;&amp; !linking_enabled then
        if !<a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BPLINKINGDISABLED" file="shared_pseudocode.xml">Unpredictable_BPLINKINGDISABLED</a>) then
            return (FALSE, FALSE);
        end;
    end;

    // If called from BreakpointMatch return FALSE for Linked context ID and/or VMID matches.
    if !linked_to &amp;&amp; linking_enabled &amp;&amp; !match_addr then
        return (FALSE, FALSE);
    end;

    var bvr_match : boolean  = FALSE;
    var bxvr_match : boolean = FALSE;

    // Do the comparison.
    if match_addr then
        let byte : integer = UInt(vaddress[1:0]);
        assert byte IN {0,2};                     // &quot;vaddress&quot; is halfword aligned

        let byte_select_match : boolean = (DBGBCR(n).BAS[byte] == '1');
        bvr_match = (vaddress[31:2] == DBGBVR(n)[31:2]) &amp;&amp; byte_select_match;

    elsif match_cid1 then
        bvr_match = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> &amp;&amp; CONTEXTIDR() == DBGBVR(n)[31:0]);
    end;

    if match_vmid then
        let vmid : bits(NUM_VMIDBITS) = <a link="func_VMID_0" file="shared_pseudocode.xml">VMID</a>();
        var bvr_vmid : bits(NUM_VMIDBITS);

        if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
            bvr_vmid = ZeroExtend{NUM_VMIDBITS}(DBGBXVR(n)[7:0]);
        elsif !IsFeatureImplemented(FEAT_VMID16) || VTCR_EL2().VS == '0' then
            bvr_vmid = ZeroExtend{NUM_VMIDBITS}(DBGBXVR(n)[7:0]);
        else
            bvr_vmid = DBGBXVR(n)[15:0];
        end;

        bxvr_match = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; vmid == bvr_vmid);

    elsif match_cid2 then
        bxvr_match = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp;
                      DBGBXVR(n)[31:0] == CONTEXTIDR_EL2()[31:0]);
    end;

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

    let match : boolean = (!bxvr_match_valid || bxvr_match) &amp;&amp; (!bvr_match_valid || bvr_match);

    return (match &amp;&amp; !mismatch, !match &amp;&amp; mismatch);
end;</pstext></ps>
    <ps name="aarch32/debug/breakpoint/AArch32_ReservedBreakpointType" mylink="aarch32.debug.breakpoint.AArch32_ReservedBreakpointType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ReservedBreakpointType()
// ================================
// Checks if the given DBGBCR(n).BT value is reserved and will generate Constrained Unpredictable
// behavior, otherwise returns Constraint_NONE.

func <anchor link="func_AArch32_ReservedBreakpointType_2">AArch32_ReservedBreakpointType</anchor>(n : integer, bt_in : bits(4)) =&gt; (<a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>, bits(4))
begin
    var bt : bits(4)       = bt_in;
    var reserved : boolean = FALSE;
    let context_aware : boolean = <a link="func_IsContextAwareBreakpoint_1" file="shared_pseudocode.xml">IsContextAwareBreakpoint</a>(n);

    // Address mismatch
    if bt == '010x' &amp;&amp; <a link="func_HaltOnBreakpointOrWatchpoint_0" file="shared_pseudocode.xml">HaltOnBreakpointOrWatchpoint</a>() then
        reserved = TRUE;
    end;

    // Context matching
    if bt != '0x0x' &amp;&amp; !context_aware then
        reserved = TRUE;
    end;

    // EL2 extension
    if bt == '1xxx' &amp;&amp; !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        reserved = TRUE;
    end;

    // Context matching
    if (bt IN {'011x','11xx'} &amp;&amp; !IsFeatureImplemented(FEAT_VHE) &amp;&amp;
          !IsFeatureImplemented(FEAT_Debugv8p2)) then
        reserved = TRUE;
    end;

    if reserved then
        var c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>;
        (c, bt) = ConstrainUnpredictableBits{4}(<a link="enum_Unpredictable_RESBPTYPE" file="shared_pseudocode.xml">Unpredictable_RESBPTYPE</a>);
        assert c IN {<a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>, <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>};
        if c == <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a> then
            return (c, ARBITRARY : bits(4));
        // Otherwise the value returned by ConstrainUnpredictableBits must be a not-reserved value
        end;
    end;

    return (<a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>, bt);
end;</pstext></ps>
    <ps name="aarch32/debug/breakpoint/AArch32_StateMatch" mylink="aarch32.debug.breakpoint.AArch32_StateMatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_StateMatch()
// ====================
// Determine whether a breakpoint or watchpoint is enabled in the current mode and state.

func <anchor link="func_AArch32_StateMatch_7">AArch32_StateMatch</anchor>(ssc_in : bits(2),  hmc_in : bit, pxc_in : bits(2), linked_in : boolean,
                        linked_n_in : integer, isbreakpnt : boolean,
                        accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; boolean
begin

    // &quot;ssc_in&quot;,&quot;hmc_in&quot;,&quot;pxc_in&quot; are the control fields from the DBGBCR(n) or DBGWCR(n) register.
    // &quot;linked_in&quot; is TRUE if this is a linked breakpoint/watchpoint type.
    // &quot;linked_n_in&quot; is the linked breakpoint number from the DBGBCR(n) or DBGWCR(n) register.
    // &quot;isbreakpnt&quot; is TRUE for breakpoints, FALSE for watchpoints.
    // &quot;accdesc&quot; describes the properties of the access being matched.
    var hmc : bit          = hmc_in;
    var ssc : bits(2)      = ssc_in;
    var pxc : bits(2)      = pxc_in;
    var linked : boolean   = linked_in;
    var linked_n : integer = linked_n_in;

    // If parameters are set to a reserved type, behaves as either disabled or a defined type
    var c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>;
    // SSCE value discarded as there is no SSCE bit in AArch32_
    (c, ssc, -, hmc, pxc) = <a link="func_CheckValidStateMatch_5" file="shared_pseudocode.xml">CheckValidStateMatch</a>(ssc, '0', hmc, pxc, isbreakpnt);
    if c == <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a> then return FALSE; end;
    // Otherwise the hmc,ssc,pxc values are either valid or the values returned by
    // CheckValidStateMatch are valid.

    let pl2_match : boolean = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; ((hmc == '1' &amp;&amp; (ssc::pxc != '1000')) || ssc == '11');
    let pl1_match : boolean = pxc[0] == '1';
    let pl0_match : boolean = pxc[1] == '1';
    let ssu_match : boolean = isbreakpnt &amp;&amp; hmc == '0' &amp;&amp; pxc == '00' &amp;&amp; ssc != '11';

    var priv_match : boolean;
    if ssu_match then
        priv_match = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M IN {<a link="global_M32_User" file="shared_pseudocode.xml">M32_User</a>,<a link="global_M32_Svc" file="shared_pseudocode.xml">M32_Svc</a>,<a link="global_M32_System" file="shared_pseudocode.xml">M32_System</a>};
    else
        case accdesc.el of
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt; priv_match = pl1_match;           // EL3 and EL1 are both PL1
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt; priv_match = pl2_match;
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt; priv_match = pl1_match;
            when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt; priv_match = pl0_match;
        end;
    end;

    // Security state match
    var ss_match : boolean;
    case ssc of
        when '00' =&gt; ss_match = TRUE;                                     // Both
        when '01' =&gt; ss_match = accdesc.ss == <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a>;               // Non-secure only
        when '10' =&gt; ss_match = accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>;                  // Secure only
        when '11' =&gt; ss_match = (hmc == '1' || accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>);  // HMC=1 -&gt; Both,
                                                                          // HMC=0 -&gt; Secure only
    end;

    var linked_match : boolean = FALSE;

    if linked then
        // &quot;linked_n&quot; 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 !<a link="func_IsContextAwareBreakpoint_1" file="shared_pseudocode.xml">IsContextAwareBreakpoint</a>(linked_n) then
            let (first_ctx_cmp, last_ctx_cmp) : (integer, integer) = <a link="func_ContextAwareBreakpointRange_0" file="shared_pseudocode.xml">ContextAwareBreakpointRange</a>();
            (c, linked_n) = <a link="func_ConstrainUnpredictableInteger_3" file="shared_pseudocode.xml">ConstrainUnpredictableInteger</a>(first_ctx_cmp, last_ctx_cmp,
                                                          <a link="enum_Unpredictable_BPNOTCTXCMP" file="shared_pseudocode.xml">Unpredictable_BPNOTCTXCMP</a>);
            assert c IN {<a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>, <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>, <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>};

            case c of
                when <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a> =&gt;  return FALSE;      // Disabled
                when <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a> =&gt;      linked = FALSE;    // No linking
                // Otherwise ConstrainUnpredictableInteger returned a context-aware breakpoint
            end;
        end;

        let vaddress : bits(32) = ARBITRARY : bits(32);
        let linked_to : boolean = TRUE;
        (linked_match,-) = <a link="func_AArch32_BreakpointValueMatch_3" file="shared_pseudocode.xml">AArch32_BreakpointValueMatch</a>(linked_n, vaddress, linked_to);
    end;

    return priv_match &amp;&amp; ss_match &amp;&amp; (!linked || linked_match);
end;</pstext></ps>
    <ps name="aarch32/debug/enables/AArch32_GenerateDebugExceptions" mylink="aarch32.debug.enables.AArch32_GenerateDebugExceptions" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_GenerateDebugExceptions()
// =================================

func <anchor link="func_AArch32_GenerateDebugExceptions_0">AArch32_GenerateDebugExceptions</anchor>() =&gt; boolean
begin
    let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>();
    return <a link="func_AArch32_GenerateDebugExceptionsFrom_2" file="shared_pseudocode.xml">AArch32_GenerateDebugExceptionsFrom</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL, ss);
end;</pstext></ps>
    <ps name="aarch32/debug/enables/AArch32_GenerateDebugExceptionsFrom" mylink="aarch32.debug.enables.AArch32_GenerateDebugExceptionsFrom" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_GenerateDebugExceptionsFrom()
// =====================================

func <anchor link="func_AArch32_GenerateDebugExceptionsFrom_2">AArch32_GenerateDebugExceptionsFrom</anchor>(from_el : bits(2), from_state : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>) =&gt; boolean
begin
    if !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="func_DebugTargetFrom_1" file="shared_pseudocode.xml">DebugTargetFrom</a>(from_state)) then
        let mask : bit = '0';    // No PSTATE.D in AArch32 state
        return <a link="func_AArch64_GenerateDebugExceptionsFrom_3" file="shared_pseudocode.xml">AArch64_GenerateDebugExceptionsFrom</a>(from_el, from_state, mask);
    end;
    if DBGOSLSR().OSLK == '1' || <a link="func_DoubleLockStatus_0" file="shared_pseudocode.xml">DoubleLockStatus</a>() || <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then
        return FALSE;
    end;

    var enabled : boolean;
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; from_state == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
        assert from_el != <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;    // Secure EL2 always uses AArch64
        if <a link="func_IsSecureEL2Enabled_0" file="shared_pseudocode.xml">IsSecureEL2Enabled</a>() then
            // Implies that EL3 and EL2 both using AArch64
            enabled = MDCR_EL3().SDD == '0';
        else
            let spd : bits(2) = if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then SDCR().SPD else MDCR_EL3().SPD32;
            if spd[1] == '1' then
                enabled = spd[0] == '1';
            else
                // SPD == 0b01 is reserved, but behaves the same as 0b00.
                enabled = <a link="func_AArch32_SelfHostedSecurePrivilegedInvasiveDebugEnabled_0" file="shared_pseudocode.xml">AArch32_SelfHostedSecurePrivilegedInvasiveDebugEnabled</a>();
            end;
        end;
        if from_el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then enabled = enabled || SDER().SUIDEN == '1'; end;
    else
        enabled = from_el != <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    end;

    return enabled;
end;</pstext></ps>
    <ps name="aarch32/debug/pmu/AArch32_IncrementCycleCounter" mylink="aarch32.debug.pmu.AArch32_IncrementCycleCounter" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_IncrementCycleCounter()
// ===============================
// Increment the cycle counter and possibly set overflow bits.

func <anchor link="func_AArch32_IncrementCycleCounter_0">AArch32_IncrementCycleCounter</anchor>()
begin
    if !<a link="func_CountPMUEvents_1" file="shared_pseudocode.xml">CountPMUEvents</a>(<a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a>) then return; end;
    var d : bit = PMCR().D;   // Check divide-by-64
    var lc : bit = PMCR().LC;
    // Effective value of 'D' bit is 0 when Effective value of LC is '1'
    if lc == '1' then d = '0'; end;
    if d == '1' &amp;&amp; !<a link="func_HasElapsed64Cycles_0" file="shared_pseudocode.xml">HasElapsed64Cycles</a>() then return; end;

    let old_value : integer = UInt(PMCCNTR());
    let new_value : integer = old_value + 1;
    PMCCNTR() = new_value[63:0];

    let ovflw : integer{} = if lc == '1' then 64 else 32;

    if old_value[64:ovflw] != new_value[64:ovflw] then
        PMOVSSET().C = '1';
    end;

    return;
end;</pstext></ps>
    <ps name="aarch32/debug/pmu/AArch32_IncrementEventCounter" mylink="aarch32.debug.pmu.AArch32_IncrementEventCounter" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_IncrementEventCounter()
// ===============================
// Increment the specified event counter 'idx' by the specified amount 'increment'.
// 'Vm' is the value event counter 'idx-1' is being incremented by if 'idx' is odd,
// zero otherwise.
// Returns the amount the counter was incremented by.

func <anchor link="func_AArch32_IncrementEventCounter_3">AArch32_IncrementEventCounter</anchor>(idx : integer, increment_in : integer, Vm : integer) =&gt; integer
begin
    if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then
        // Force the counter to be incremented as a 64-bit counter.
        return <a link="func_AArch64_IncrementEventCounter_3" file="shared_pseudocode.xml">AArch64_IncrementEventCounter</a>(idx, increment_in, Vm);
    end;

    // In this model, event counters in an AArch32-only implementation are 32 bits and
    // the LP bits are RES0 in this model, even if FEAT_PMUv3p5 is implemented.
    var old_value : integer;
    var new_value : integer;

    old_value = UInt(PMEVCNTR(idx));
    let increment : integer = <a link="func_PMUCountValue_3" file="shared_pseudocode.xml">PMUCountValue</a>(idx, increment_in, Vm);
    new_value = old_value + increment;

    PMEVCNTR(idx) = new_value[31:0];
    let ovflw : integer{} = 32;
    if old_value[64:ovflw] != new_value[64:ovflw] then
        PMOVSSET()[idx] = '1';
        // Check for the CHAIN event from an even counter
        if (idx[0] == '0' &amp;&amp; idx + 1 &lt; NUM_PMU_COUNTERS &amp;&amp;
              (<a link="func_GetPMUCounterRange_1" file="shared_pseudocode.xml">GetPMUCounterRange</a>(idx) == <a link="func_GetPMUCounterRange_1" file="shared_pseudocode.xml">GetPMUCounterRange</a>(idx+1) ||
                 <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_COUNT_CHAIN" file="shared_pseudocode.xml">Unpredictable_COUNT_CHAIN</a>))) then
            // If PMU counters idx and idx+1 are not in same range,
            // it is CONSTRAINED UNPREDICTABLE if CHAIN event is counted
            <a link="func_PMUEvent_3" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_CHAIN, 1, idx + 1);
        end;
    end;

    return increment;
end;</pstext></ps>
    <ps name="aarch32/debug/pmu/AArch32_PMUCycle" mylink="aarch32.debug.pmu.AArch32_PMUCycle" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_PMUCycle()
// ==================
// Called at the end of each cycle to increment event counters and
// check for PMU overflow. In pseudocode, a cycle ends after the
// execution of the operational pseudocode.

func <anchor link="func_AArch32_PMUCycle_0">AArch32_PMUCycle</anchor>()
begin
    if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then
        <a link="func_AArch64_PMUCycle_0" file="shared_pseudocode.xml">AArch64_PMUCycle</a>();
        return;
    end;

    if !IsFeatureImplemented(FEAT_PMUv3) then
        return;
    end;
    <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_CPU_CYCLES);
    let counters : integer = NUM_PMU_COUNTERS;
    var Vm : integer = 0;
    if counters != 0 then
        for idx = 0 to counters - 1 do
            if <a link="func_CountPMUEvents_1" file="shared_pseudocode.xml">CountPMUEvents</a>(idx) then
                let accumulated : integer = <a link="global_PMUEventAccumulator" file="shared_pseudocode.xml">PMUEventAccumulator</a>[[idx]];
                if (idx MOD 2) == 0 then Vm = 0; end;
                Vm = <a link="func_AArch32_IncrementEventCounter_3" file="shared_pseudocode.xml">AArch32_IncrementEventCounter</a>(idx, accumulated, Vm);
            end;
            <a link="global_PMUEventAccumulator" file="shared_pseudocode.xml">PMUEventAccumulator</a>[[idx]] = 0;
        end;
    end;
    <a link="func_AArch32_IncrementCycleCounter_0" file="shared_pseudocode.xml">AArch32_IncrementCycleCounter</a>();
    <a link="func_CheckForPMUOverflow_0" file="shared_pseudocode.xml">CheckForPMUOverflow</a>();
end;</pstext></ps>
    <ps name="aarch32/debug/takeexceptiondbg/AArch32_EnterHypModeInDebugState" mylink="aarch32.debug.takeexceptiondbg.AArch32_EnterHypModeInDebugState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_EnterHypModeInDebugState()
// ==================================
// Take an exception in Debug state to Hyp mode.

noreturn func AArch32_EnterHypModeInDebugState(except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>)
begin
    SynchronizeContext();
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() == <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);

    <a link="func_AArch32_ReportHypEntry_1" file="shared_pseudocode.xml">AArch32_ReportHypEntry</a>(except);
    <a link="func_AArch32_WriteMode_1" file="shared_pseudocode.xml">AArch32_WriteMode</a>(<a link="global_M32_Hyp" file="shared_pseudocode.xml">M32_Hyp</a>);
    <a link="accessor_SPSR_curr_0" file="shared_pseudocode.xml">SPSR_curr</a>() = ARBITRARY : bits(32);
    ELR_hyp()   = ARBITRARY : bits(32);
    // In Debug state, the PE always execute T32 instructions when in AArch32 state, and
    // PSTATE.[SS,A,I,F] are not observable so behave as UNKNOWN.
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T = '1';                             // PSTATE.J is RES0
    PSTATE.[SS,A,I,F] = ARBITRARY : bits(4);
    DLR()   = ARBITRARY : bits(32);
    DSPSR() = ARBITRARY : bits(32);
    if IsFeatureImplemented(FEAT_Debugv8p9) then
        DSPSR2() = ARBITRARY : bits(32);
    end;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.E  = HSCTLR().EE;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL = '0';
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT = '00000000';
    if IsFeatureImplemented(FEAT_SSBS) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SSBS = ARBITRARY : bit; end;
    EDSCR().ERR = '1';
    <a link="func_UpdateEDSCRFields_0" file="shared_pseudocode.xml">UpdateEDSCRFields</a>();

    EndOfInstruction(<a link="enum_EndOfInstructionReason_Exception" file="shared_pseudocode.xml">EndOfInstructionReason_Exception</a>);
end;</pstext></ps>
    <ps name="aarch32/debug/takeexceptiondbg/AArch32_EnterModeInDebugState" mylink="aarch32.debug.takeexceptiondbg.AArch32_EnterModeInDebugState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_EnterModeInDebugState()
// ===============================
// Take an exception in Debug state to a mode other than Monitor and Hyp mode.

noreturn func AArch32_EnterModeInDebugState(target_mode : bits(5))
begin
    SynchronizeContext();
    assert <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M == <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a> then SCR().NS = '0'; end;
    <a link="func_AArch32_WriteMode_1" file="shared_pseudocode.xml">AArch32_WriteMode</a>(target_mode);
    <a link="accessor_SPSR_curr_0" file="shared_pseudocode.xml">SPSR_curr</a>() = ARBITRARY : bits(32);
    <a link="accessor_R_1" file="shared_pseudocode.xml">R</a>(14)       = ARBITRARY : bits(32);
    // In Debug state, the PE always execute T32 instructions when in AArch32 state, and
    // PSTATE.[SS,A,I,F] are not observable so behave as UNKNOWN.
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T = '1';                             // PSTATE.J is RES0
    PSTATE.[SS,A,I,F] = ARBITRARY : bits(4);
    DLR() = ARBITRARY : bits(32);
    DSPSR() = ARBITRARY : bits(32);
    if IsFeatureImplemented(FEAT_Debugv8p9) then
        DSPSR2() = ARBITRARY : bits(32);
    end;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.E  = SCTLR().EE;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL = '0';
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT = '00000000';
    if IsFeatureImplemented(FEAT_PAN) &amp;&amp; SCTLR().SPAN == '0' then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN = '1'; end;
    if IsFeatureImplemented(FEAT_SSBS) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SSBS = ARBITRARY : bit; end;
    EDSCR().ERR = '1';
    <a link="func_UpdateEDSCRFields_0" file="shared_pseudocode.xml">UpdateEDSCRFields</a>();                        // Update EDSCR PE state flags.

    EndOfInstruction(<a link="enum_EndOfInstructionReason_Exception" file="shared_pseudocode.xml">EndOfInstructionReason_Exception</a>);
end;</pstext></ps>
    <ps name="aarch32/debug/takeexceptiondbg/AArch32_EnterMonitorModeInDebugState" mylink="aarch32.debug.takeexceptiondbg.AArch32_EnterMonitorModeInDebugState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_EnterMonitorModeInDebugState()
// ======================================
// Take an exception in Debug state to Monitor mode.

func <anchor link="func_AArch32_EnterMonitorModeInDebugState_0">AArch32_EnterMonitorModeInDebugState</anchor>()
begin
    SynchronizeContext();
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
    let from_secure : boolean = <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>;
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M == <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a> then SCR().NS = '0'; end;
    <a link="func_AArch32_WriteMode_1" file="shared_pseudocode.xml">AArch32_WriteMode</a>(<a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a>);
    <a link="accessor_SPSR_curr_0" file="shared_pseudocode.xml">SPSR_curr</a>() = ARBITRARY : bits(32);
    <a link="accessor_R_1" file="shared_pseudocode.xml">R</a>(14) = ARBITRARY : bits(32);
    // In Debug state, the PE always execute T32 instructions when in AArch32 state, and
    // PSTATE.[SS,A,I,F] are not observable so behave as UNKNOWN.
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T = '1';                             // PSTATE.J is RES0
    PSTATE.[SS,A,I,F] = ARBITRARY : bits(4);
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.E = SCTLR().EE;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL = '0';
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT = '00000000';
    if IsFeatureImplemented(FEAT_PAN) then
        if !from_secure then
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN = '0';
        elsif SCTLR().SPAN == '0' then
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN = '1';
        end;
    end;
    if IsFeatureImplemented(FEAT_SSBS) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SSBS = ARBITRARY : bit; end;
    DLR() = ARBITRARY : bits(32);
    DSPSR() = ARBITRARY : bits(32);
    if IsFeatureImplemented(FEAT_Debugv8p9) then
        DSPSR2() = ARBITRARY : bits(32);
    end;
    EDSCR().ERR = '1';
    <a link="func_UpdateEDSCRFields_0" file="shared_pseudocode.xml">UpdateEDSCRFields</a>();                        // Update EDSCR PE state flags.

    EndOfInstruction(<a link="enum_EndOfInstructionReason_Exception" file="shared_pseudocode.xml">EndOfInstructionReason_Exception</a>);
end;</pstext></ps>
    <ps name="aarch32/debug/watchpoint/AArch32_WatchpointByteMatch" mylink="aarch32.debug.watchpoint.AArch32_WatchpointByteMatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_WatchpointByteMatch()
// =============================

func <anchor link="func_AArch32_WatchpointByteMatch_2">AArch32_WatchpointByteMatch</anchor>(n : integer, vaddress : bits(32)) =&gt; boolean
begin
    let dbgtop : integer{} = 31;
    let cmpbottom : integer{} = if DBGWVR(n)[2] == '1' then 2 else 3; // Word or doubleword
    var bottom = cmpbottom;
    let select : integer{} = UInt(vaddress[cmpbottom-1:0]);
    var byte_select_match : boolean = (DBGWCR(n).BAS[select] != '0');
    var mask : integer{} = UInt(DBGWCR(n).MASK);

    // If DBGWCR(n).MASK is a nonzero value and DBGWCR(n).BAS is not set to '11111111', or
    // DBGWCR(n).BAS specifies a non-contiguous set of bytes behavior is CONSTRAINED
    // UNPREDICTABLE.
    if mask &gt; 0 &amp;&amp; !IsOnes(DBGWCR(n).BAS) then
        byte_select_match = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_WPMASKANDBAS" file="shared_pseudocode.xml">Unpredictable_WPMASKANDBAS</a>);
    else
        let LSB : bits(8) = (DBGWCR(n).BAS AND NOT(DBGWCR(n).BAS - 1));
        let MSB : bits(8) = (DBGWCR(n).BAS + LSB);
        if !IsZero(MSB AND (MSB - 1)) then          // Not contiguous
            byte_select_match = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_WPBASCONTIGUOUS" file="shared_pseudocode.xml">Unpredictable_WPBASCONTIGUOUS</a>);
            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 &gt; 0 &amp;&amp; mask &lt;= 2 then
        var c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>;
        var unpred_mask : integer;
        (c, unpred_mask) = <a link="func_ConstrainUnpredictableInteger_3" file="shared_pseudocode.xml">ConstrainUnpredictableInteger</a>(3, 31, <a link="enum_Unpredictable_RESWPMASK" file="shared_pseudocode.xml">Unpredictable_RESWPMASK</a>);
        assert c IN {<a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>, <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>, <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>};
        case c of
            when <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a> =&gt; return FALSE; // Disabled
            when <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>     =&gt; mask = 0;     // No masking
            // Otherwise the value returned by ConstrainUnpredictableInteger is a not-reserved value
            otherwise                =&gt; mask = unpred_mask as integer{3..31};
        end;
    end;

    let cmpmsb : integer{}    = dbgtop;
    let cmplsb : integer{}    = if mask &gt; bottom then mask else bottom;
    let bottombit : integer{} = bottom;
    var WVR_match : boolean   = (vaddress[cmpmsb:cmplsb] == DBGWVR(n)[cmpmsb:cmplsb]);
    if mask &gt; bottom then
        // If masked bits of DBGWVR(n) are not zero, the behavior is CONSTRAINED UNPREDICTABLE.
        if WVR_match &amp;&amp; !IsZero(DBGWVR(n)[cmplsb-1:bottombit]) then
            WVR_match = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_WPMASKEDBITS" file="shared_pseudocode.xml">Unpredictable_WPMASKEDBITS</a>);
        end;
    end;

    return (WVR_match &amp;&amp; byte_select_match);
end;</pstext></ps>
    <ps name="aarch32/debug/watchpoint/AArch32_WatchpointMatch" mylink="aarch32.debug.watchpoint.AArch32_WatchpointMatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_WatchpointMatch()
// =========================
// Watchpoint matching in an AArch32 translation regime.

func <anchor link="func_AArch32_WatchpointMatch_4">AArch32_WatchpointMatch</anchor>(n : integer, vaddress : bits(32), size : integer,
                             accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_WatchpointInfo" file="shared_pseudocode.xml">WatchpointInfo</a>
begin
    assert <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>());
    assert n &lt; <a link="func_NumWatchpointsImplemented_0" file="shared_pseudocode.xml">NumWatchpointsImplemented</a>();

    let enabled : boolean     = DBGWCR(n).E == '1';
    let linked : boolean      = DBGWCR(n).WT == '1';
    let isbreakpnt : boolean  = FALSE;
    let linked_n : integer{}  = UInt(DBGWCR_EL1(n).LBN);
    let state_match : boolean = <a link="func_AArch32_StateMatch_7" file="shared_pseudocode.xml">AArch32_StateMatch</a>(DBGWCR(n).SSC, DBGWCR(n).HMC, DBGWCR(n).PAC,
                                                   linked, linked_n, isbreakpnt, accdesc);

    var watchptinfo : <a link="type_WatchpointInfo" file="shared_pseudocode.xml">WatchpointInfo</a>;
    var ls_match : boolean;
    case DBGWCR(n).LSC[1:0] of
        when '00' =&gt; ls_match = FALSE;
        when '01' =&gt; ls_match = accdesc.read;
        when '10' =&gt; ls_match = accdesc.write || accdesc.acctype == <a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>;
        when '11' =&gt; ls_match = TRUE;
    end;

    var value_match : boolean = FALSE;
    watchptinfo.vaddress = ZeroExtend{64}(vaddress);
    for byte = 0 to size - 1 do
        if (!value_match &amp;&amp;
              !<a link="func_AddressInNaturallyAlignedBlock_2" file="shared_pseudocode.xml">AddressInNaturallyAlignedBlock</a>(watchptinfo.vaddress,
                                              ZeroExtend{64}(vaddress + byte))) then
            // Watchpoint should report an address which is in
            // the naturally aligned block of the matched address.
            watchptinfo.vaddress = ZeroExtend{64}(vaddress + byte);
        end;
        value_match = value_match || <a link="func_AArch32_WatchpointByteMatch_2" file="shared_pseudocode.xml">AArch32_WatchpointByteMatch</a>(n, vaddress + byte);
    end;

    watchptinfo.watchpt_num = n;
    watchptinfo.value_match = value_match &amp;&amp; state_match &amp;&amp; ls_match &amp;&amp; enabled;
    return watchptinfo;
end;</pstext></ps>
    <ps name="aarch32/exceptions/aborts/AArch32_Abort" mylink="aarch32.exceptions.aborts.AArch32_Abort" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_Abort()
// ===============
// Abort and Debug exception handling in an AArch32 translation regime.

func <anchor link="func_AArch32_Abort_1">AArch32_Abort</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>)
begin
    // Check if routed to AArch64 state
    var route_to_aarch64 : boolean = ((<a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) &amp;&amp;
                                      !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="func_SyncExternalAbortTarget_1" file="shared_pseudocode.xml">SyncExternalAbortTarget</a>(fault))) ||
                                      (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>)));

    if !route_to_aarch64 &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        route_to_aarch64 = (HCR_EL2().TGE == '1' || <a link="func_IsSecondStage_1" file="shared_pseudocode.xml">IsSecondStage</a>(fault) ||
                            (<a link="func_IsDebugException_1" file="shared_pseudocode.xml">IsDebugException</a>(fault) &amp;&amp; MDCR_EL2().TDE == '1'));
    end;

    if route_to_aarch64 then
        <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
    end;
    if fault.accessdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> then
        <a link="func_AArch32_TakePrefetchAbortException_1" file="shared_pseudocode.xml">AArch32_TakePrefetchAbortException</a>(fault);
    else
        <a link="func_AArch32_TakeDataAbortException_1" file="shared_pseudocode.xml">AArch32_TakeDataAbortException</a>(fault);
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/aborts/AArch32_AbortSyndrome" mylink="aarch32.exceptions.aborts.AArch32_AbortSyndrome" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_AbortSyndrome()
// =======================
// Creates an exception syndrome record for Abort exceptions
// taken to Hyp mode
// from an AArch32 translation regime.
func <anchor link="func_AArch32_AbortSyndrome_3">AArch32_AbortSyndrome</anchor>(exceptype : <a link="type_Exception" file="shared_pseudocode.xml">Exception</a>, fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>,
                           target_el : bits(2)) =&gt; <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>
begin
    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(exceptype);

    except.syndrome.iss = <a link="func_AArch32_FaultSyndrome_2" file="shared_pseudocode.xml">AArch32_FaultSyndrome</a>(exceptype, fault);
    if exceptype == <a link="enum_Exception_Watchpoint" file="shared_pseudocode.xml">Exception_Watchpoint</a> then
        except.vaddress = fault.watchptinfo.vaddress;
    else
        except.vaddress = ZeroExtend{64}(fault.vaddress);
    end;

    if <a link="func_IPAValid_1" file="shared_pseudocode.xml">IPAValid</a>(fault) then
        except.ipavalid  = TRUE;
        except.NS        = if fault.ipaddress.paspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> then '1' else '0';
        except.ipaddress = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(fault.ipaddress.address);
    else
        except.ipavalid = FALSE;
    end;

    return except;
end;</pstext></ps>
    <ps name="aarch32/exceptions/aborts/AArch32_CheckPCAlignment" mylink="aarch32.exceptions.aborts.AArch32_CheckPCAlignment" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CheckPCAlignment()
// ==========================

func <anchor link="func_AArch32_CheckPCAlignment_0">AArch32_CheckPCAlignment</anchor>()
begin
    let pc : bits(32) = ThisInstrAddr{}();

    if (<a link="func_CurrentInstrSet_0" file="shared_pseudocode.xml">CurrentInstrSet</a>() == <a link="enum_InstrSet_A32" file="shared_pseudocode.xml">InstrSet_A32</a> &amp;&amp; pc[1] == '1') || pc[0] == '1' then
        if <a link="func_AArch32_GeneralExceptionsToAArch64_0" file="shared_pseudocode.xml">AArch32_GeneralExceptionsToAArch64</a>() then <a link="func_AArch64_PCAlignmentFault_0" file="shared_pseudocode.xml">AArch64_PCAlignmentFault</a>(); end;
        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescIFetch_0" file="shared_pseudocode.xml">CreateAccDescIFetch</a>();
        var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_2" file="shared_pseudocode.xml">NoFault</a>(accdesc, ZeroExtend{64}(pc));
        // Generate an Alignment fault Prefetch Abort exception
        fault.statuscode = <a link="enum_Fault_Alignment" file="shared_pseudocode.xml">Fault_Alignment</a>;
        <a link="func_AArch32_Abort_1" file="shared_pseudocode.xml">AArch32_Abort</a>(fault);
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/aborts/AArch32_CommonFaultStatus" mylink="aarch32.exceptions.aborts.AArch32_CommonFaultStatus" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CommonFaultStatus()
// ===========================
// Return the common part of the fault status on reporting a Data
// or Prefetch Abort.

func <anchor link="func_AArch32_CommonFaultStatus_2">AArch32_CommonFaultStatus</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, long_format : boolean) =&gt; bits(32)
begin
    var target : bits(32) = Zeros{};
    if IsFeatureImplemented(FEAT_RAS) &amp;&amp; <a link="func_IsAsyncAbort_1" file="shared_pseudocode.xml">IsAsyncAbort</a>(fault) then
        let errstate : <a link="type_ErrorState" file="shared_pseudocode.xml">ErrorState</a> = <a link="func_PEErrorState_1" file="shared_pseudocode.xml">PEErrorState</a>(fault);
        target[15:14] = <a link="func_AArch32_EncodeAsyncErrorSyndrome_1" file="shared_pseudocode.xml">AArch32_EncodeAsyncErrorSyndrome</a>(errstate);   // AET
    end;
    if <a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) then target[12] = fault.extflag; end;   // ExT
    target[9] = if long_format then '1' else '0';                     // LPAE
    if long_format then                                               // Long-descriptor format
        target[5:0]    = <a link="func_EncodeLDFSC_2" file="shared_pseudocode.xml">EncodeLDFSC</a>(fault.statuscode, fault.level);  // STATUS
    else                                                              // Short-descriptor format
        target[10,3:0] = <a link="func_EncodeSDFSC_2" file="shared_pseudocode.xml">EncodeSDFSC</a>(fault.statuscode, fault.level);  // FS
    end;
    return target;
end;</pstext></ps>
    <ps name="aarch32/exceptions/aborts/AArch32_ReportDataAbort" mylink="aarch32.exceptions.aborts.AArch32_ReportDataAbort" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ReportDataAbort()
// =========================
// Report syndrome information for aborts taken to modes other than Hyp mode.

func <anchor link="func_AArch32_ReportDataAbort_2">AArch32_ReportDataAbort</anchor>(route_to_monitor : boolean, fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>)
begin
    var long_format : boolean;
    if route_to_monitor &amp;&amp; <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() != <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
        long_format = ((TTBCR_S().EAE == '1') ||
                       (<a link="func_IsExternalSyncAbort_1" file="shared_pseudocode.xml">IsExternalSyncAbort</a>(fault) &amp;&amp; ((<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || TTBCR().EAE == '1') ||
                        (fault.secondstage &amp;&amp; ImpDefBool(
                                               &quot;Report abort using Long-descriptor format&quot;)))));
    else
        long_format = TTBCR().EAE == '1';
    end;
    var syndrome : bits(32) = <a link="func_AArch32_CommonFaultStatus_2" file="shared_pseudocode.xml">AArch32_CommonFaultStatus</a>(fault, long_format);

    // bits of syndrome that are not common to I and D side
    if fault.accessdesc.acctype IN {<a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>, <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>, <a link="enum_AccessType_AT" file="shared_pseudocode.xml">AccessType_AT</a>} then
        syndrome[13] = '1';                              // CM
        syndrome[11] = '1';                              // WnR
    else
        syndrome[11] = if fault.write then '1' else '0'; // WnR
    end;

    if !long_format then
        syndrome[7:4] = fault.domain;                    // Domain
    end;

    if fault.accessdesc.acctype == <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a> then
        var i_syndrome : bits(32);
        if (!long_format &amp;&amp;
            ImpDefBool(&quot;Report I-cache maintenance fault in IFSR&quot;)) then
            i_syndrome = syndrome;
            syndrome[10,3:0] = <a link="func_EncodeSDFSC_2" file="shared_pseudocode.xml">EncodeSDFSC</a>(<a link="enum_Fault_ICacheMaint" file="shared_pseudocode.xml">Fault_ICacheMaint</a>, 1);
        else
            i_syndrome = ARBITRARY : bits(32);
        end;
        if route_to_monitor then
            IFSR_S() = i_syndrome;
        else
            IFSR() = i_syndrome;
        end;
    end;

    if route_to_monitor then
        DFSR_S() = syndrome;
        DFAR_S() = fault.vaddress[31:0];
    else
        DFSR()   = syndrome;
        DFAR()   = fault.vaddress[31:0];
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/aborts/AArch32_ReportPrefetchAbort" mylink="aarch32.exceptions.aborts.AArch32_ReportPrefetchAbort" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ReportPrefetchAbort()
// =============================
// Report syndrome information for aborts taken to modes other than Hyp mode.

func <anchor link="func_AArch32_ReportPrefetchAbort_2">AArch32_ReportPrefetchAbort</anchor>(route_to_monitor : boolean, fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>)
begin
    // The encoding used in the IFSR can be Long-descriptor format or Short-descriptor format.
    // Normally, the current translation table format determines the format. For an abort from
    // Non-secure state to Monitor mode, the IFSR uses the Long-descriptor format if any of the
    // following applies:
    // * The Secure TTBCR.EAE is set to 1.
    // * It is taken from Hyp mode.
    // * It is taken from EL1 or EL0, and the Non-secure TTBCR.EAE is set to 1.
    var long_format : boolean = FALSE;
    if route_to_monitor &amp;&amp; <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() != <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
        long_format = TTBCR_S().EAE == '1' || <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || TTBCR().EAE == '1';
    else
        long_format = TTBCR().EAE == '1';
    end;

    let fsr : bits(32) = <a link="func_AArch32_CommonFaultStatus_2" file="shared_pseudocode.xml">AArch32_CommonFaultStatus</a>(fault, long_format);
    if route_to_monitor then
        IFSR_S() = fsr;
        IFAR_S() = fault.vaddress[31:0];
    else
        IFSR() = fsr;
        IFAR() = fault.vaddress[31:0];
    end;
    return;
end;</pstext></ps>
    <ps name="aarch32/exceptions/aborts/AArch32_TakeDataAbortException" mylink="aarch32.exceptions.aborts.AArch32_TakeDataAbortException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TakeDataAbortException()
// ================================

func <anchor link="func_AArch32_TakeDataAbortException_1">AArch32_TakeDataAbortException</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>)
begin

    var sea_target : bits(2);
    if <a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) then
        sea_target = <a link="func_SyncExternalAbortTarget_1" file="shared_pseudocode.xml">SyncExternalAbortTarget</a>(fault);
    else
        sea_target = ARBITRARY : bits(2);
    end;

    let route_to_monitor : boolean = <a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) &amp;&amp; sea_target == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
    let route_to_hyp : boolean     = (<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp;
                                      (HCR().TGE == '1' ||
                                      (<a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) &amp;&amp; sea_target == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) ||
                                      (<a link="func_IsDebugException_1" file="shared_pseudocode.xml">IsDebugException</a>(fault) &amp;&amp; HDCR().TDE == '1') ||
                                       <a link="func_IsSecondStage_1" file="shared_pseudocode.xml">IsSecondStage</a>(fault)));

    let preferred_exception_return : bits(32) = ThisInstrAddr{}();
    let vect_offset : integer = 0x10;
    let lr_offset : integer = 8;

    if <a link="func_IsDebugException_1" file="shared_pseudocode.xml">IsDebugException</a>(fault) then DBGDSCRext().MOE = fault.debugmoe; end;
    if route_to_monitor then
        <a link="func_AArch32_ReportDataAbort_2" file="shared_pseudocode.xml">AArch32_ReportDataAbort</a>(route_to_monitor, fault);
        <a link="func_AArch32_EnterMonitorMode_3" file="shared_pseudocode.xml">AArch32_EnterMonitorMode</a>(preferred_exception_return, lr_offset, vect_offset);
    elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || route_to_hyp then
        let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_AArch32_AbortSyndrome_3" file="shared_pseudocode.xml">AArch32_AbortSyndrome</a>(<a link="enum_Exception_DataAbort" file="shared_pseudocode.xml">Exception_DataAbort</a>, fault, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
            AArch32_EnterHypMode(except, preferred_exception_return, vect_offset);
        else
            AArch32_EnterHypMode(except, preferred_exception_return, 0x14);
        end;
    else
        <a link="func_AArch32_ReportDataAbort_2" file="shared_pseudocode.xml">AArch32_ReportDataAbort</a>(route_to_monitor, fault);
        AArch32_EnterMode(<a link="global_M32_Abort" file="shared_pseudocode.xml">M32_Abort</a>, preferred_exception_return, lr_offset, vect_offset);
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/aborts/AArch32_TakePrefetchAbortException" mylink="aarch32.exceptions.aborts.AArch32_TakePrefetchAbortException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TakePrefetchAbortException()
// ====================================

func <anchor link="func_AArch32_TakePrefetchAbortException_1">AArch32_TakePrefetchAbortException</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>)
begin

    var sea_target : bits(2);
    if <a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) then
        sea_target = <a link="func_SyncExternalAbortTarget_1" file="shared_pseudocode.xml">SyncExternalAbortTarget</a>(fault);
    else
        sea_target = ARBITRARY : bits(2);
    end;

    let route_to_monitor : boolean = <a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) &amp;&amp; sea_target == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
    let route_to_hyp : boolean = (<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp;
                                  (HCR().TGE == '1' ||
                                  (<a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) &amp;&amp; sea_target == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) ||
                                  (<a link="func_IsDebugException_1" file="shared_pseudocode.xml">IsDebugException</a>(fault) &amp;&amp; HDCR().TDE == '1') ||
                                   <a link="func_IsSecondStage_1" file="shared_pseudocode.xml">IsSecondStage</a>(fault)));

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>;
    let preferred_exception_return : bits(32) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0C;
    let lr_offset : integer = 4;

    if <a link="func_IsDebugException_1" file="shared_pseudocode.xml">IsDebugException</a>(fault) then DBGDSCRext().MOE = fault.debugmoe; end;
    if route_to_monitor then
        <a link="func_AArch32_ReportPrefetchAbort_2" file="shared_pseudocode.xml">AArch32_ReportPrefetchAbort</a>(route_to_monitor, fault);
        <a link="func_AArch32_EnterMonitorMode_3" file="shared_pseudocode.xml">AArch32_EnterMonitorMode</a>(preferred_exception_return, lr_offset, vect_offset);
    elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || route_to_hyp then
        if fault.statuscode == <a link="enum_Fault_Alignment" file="shared_pseudocode.xml">Fault_Alignment</a> then             // PC Alignment fault
            except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_PCAlignment" file="shared_pseudocode.xml">Exception_PCAlignment</a>);
            except.vaddress = <a link="func_ThisInstrAddr_1" file="shared_pseudocode.xml">ThisInstrAddr</a>{64}();
        else
            except = <a link="func_AArch32_AbortSyndrome_3" file="shared_pseudocode.xml">AArch32_AbortSyndrome</a>(<a link="enum_Exception_InstructionAbort" file="shared_pseudocode.xml">Exception_InstructionAbort</a>, fault, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
        end;
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
            AArch32_EnterHypMode(except, preferred_exception_return, vect_offset);
        else
            AArch32_EnterHypMode(except, preferred_exception_return, 0x14);
        end;
    else
        <a link="func_AArch32_ReportPrefetchAbort_2" file="shared_pseudocode.xml">AArch32_ReportPrefetchAbort</a>(route_to_monitor, fault);
        AArch32_EnterMode(<a link="global_M32_Abort" file="shared_pseudocode.xml">M32_Abort</a>, preferred_exception_return, lr_offset, vect_offset);
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/async/AArch32_TakePhysicalFIQException" mylink="aarch32.exceptions.async.AArch32_TakePhysicalFIQException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TakePhysicalFIQException()
// ==================================

func <anchor link="func_AArch32_TakePhysicalFIQException_0">AArch32_TakePhysicalFIQException</anchor>()
begin

    // Check if routed to AArch64 state
    var route_to_aarch64 : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>);
    if !route_to_aarch64 &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        route_to_aarch64 = HCR_EL2().TGE == '1' || (HCR_EL2().FMO == '1' &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>());
    end;

    if !route_to_aarch64 then
        route_to_aarch64 = <a link="func_EffectiveSCR_EL3_FIQ_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_FIQ</a>() == '1';
    end;

    if route_to_aarch64 then <a link="func_AArch64_TakePhysicalFIQException_0" file="shared_pseudocode.xml">AArch64_TakePhysicalFIQException</a>(); end;
    let route_to_monitor : boolean = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR().FIQ == '1';
    let route_to_hyp : boolean = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
                                  (HCR().TGE == '1' || HCR().FMO == '1'));
    let preferred_exception_return : bits(32) = ThisInstrAddr{}();
    let vect_offset : integer = 0x1C;
    let lr_offset : integer   = 4;
    if route_to_monitor then
        <a link="func_AArch32_EnterMonitorMode_3" file="shared_pseudocode.xml">AArch32_EnterMonitorMode</a>(preferred_exception_return, lr_offset, vect_offset);
    elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || route_to_hyp then
        let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_FIQ" file="shared_pseudocode.xml">Exception_FIQ</a>);
        AArch32_EnterHypMode(except, preferred_exception_return, vect_offset);
    else
        AArch32_EnterMode(<a link="global_M32_FIQ" file="shared_pseudocode.xml">M32_FIQ</a>, preferred_exception_return, lr_offset, vect_offset);
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/async/AArch32_TakePhysicalIRQException" mylink="aarch32.exceptions.async.AArch32_TakePhysicalIRQException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TakePhysicalIRQException()
// ==================================
// Take an enabled physical IRQ exception.

func <anchor link="func_AArch32_TakePhysicalIRQException_0">AArch32_TakePhysicalIRQException</anchor>()
begin

    // Check if routed to AArch64 state
    var route_to_aarch64 : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>);
    if !route_to_aarch64 &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        route_to_aarch64 = HCR_EL2().TGE == '1' || (HCR_EL2().IMO == '1' &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>());
    end;
    if !route_to_aarch64 then
        route_to_aarch64 = <a link="func_EffectiveSCR_EL3_IRQ_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_IRQ</a>() == '1';
    end;

    if route_to_aarch64 then <a link="func_AArch64_TakePhysicalIRQException_0" file="shared_pseudocode.xml">AArch64_TakePhysicalIRQException</a>(); end;

    let route_to_monitor : boolean = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR().IRQ == '1';
    let route_to_hyp : boolean = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
                                  (HCR().TGE == '1' || HCR().IMO == '1'));
    let preferred_exception_return : bits(32) = ThisInstrAddr{}();
    let vect_offset : integer = 0x18;
    let lr_offset : integer   = 4;
    if route_to_monitor then
        <a link="func_AArch32_EnterMonitorMode_3" file="shared_pseudocode.xml">AArch32_EnterMonitorMode</a>(preferred_exception_return, lr_offset, vect_offset);
    elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || route_to_hyp then
        let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_IRQ" file="shared_pseudocode.xml">Exception_IRQ</a>);
        AArch32_EnterHypMode(except, preferred_exception_return, vect_offset);
    else
        AArch32_EnterMode(<a link="global_M32_IRQ" file="shared_pseudocode.xml">M32_IRQ</a>, preferred_exception_return, lr_offset, vect_offset);
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/async/AArch32_TakePhysicalSErrorException" mylink="aarch32.exceptions.async.AArch32_TakePhysicalSErrorException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TakePhysicalSErrorException()
// =====================================

func <anchor link="func_AArch32_TakePhysicalSErrorException_1">AArch32_TakePhysicalSErrorException</anchor>(implicit_esb : boolean)
begin
    var masked : boolean;
    var target_el : bits(2);

    (masked, target_el) = <a link="func_PhysicalSErrorTarget_0" file="shared_pseudocode.xml">PhysicalSErrorTarget</a>();
    assert !masked;

    // Check if routed to AArch64 state
    if !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(target_el) then
        <a link="func_AArch64_TakePhysicalSErrorException_1" file="shared_pseudocode.xml">AArch64_TakePhysicalSErrorException</a>(implicit_esb);
    end;

    let preferred_exception_return : bits(32) = ThisInstrAddr{}();
    let vect_offset : integer = 0x10;
    let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>   = <a link="func_GetPendingPhysicalSError_0" file="shared_pseudocode.xml">GetPendingPhysicalSError</a>();
    let lr_offset : integer   = 8;

    let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>   = <a link="func_AArch32_AbortSyndrome_3" file="shared_pseudocode.xml">AArch32_AbortSyndrome</a>(<a link="enum_Exception_DataAbort" file="shared_pseudocode.xml">Exception_DataAbort</a>, fault, target_el);
    let route_to_monitor : boolean = (target_el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);

    if <a link="func_IsSErrorEdgeTriggered_0" file="shared_pseudocode.xml">IsSErrorEdgeTriggered</a>() then
        ClearPendingPhysicalSError();
    end;

    case target_el of
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            <a link="func_AArch32_ReportDataAbort_2" file="shared_pseudocode.xml">AArch32_ReportDataAbort</a>(route_to_monitor, fault);
            <a link="func_AArch32_EnterMonitorMode_3" file="shared_pseudocode.xml">AArch32_EnterMonitorMode</a>(preferred_exception_return, lr_offset, vect_offset);
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
                AArch32_EnterHypMode(except, preferred_exception_return, vect_offset);
            else
                AArch32_EnterHypMode(except, preferred_exception_return, 0x14);
            end;
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            <a link="func_AArch32_ReportDataAbort_2" file="shared_pseudocode.xml">AArch32_ReportDataAbort</a>(route_to_monitor, fault);
            AArch32_EnterMode(<a link="global_M32_Abort" file="shared_pseudocode.xml">M32_Abort</a>, preferred_exception_return, lr_offset, vect_offset);
        otherwise =&gt;
            unreachable;
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/async/AArch32_TakeVirtualFIQException" mylink="aarch32.exceptions.async.AArch32_TakeVirtualFIQException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TakeVirtualFIQException()
// =================================

func <anchor link="func_AArch32_TakeVirtualFIQException_0">AArch32_TakeVirtualFIQException</anchor>()
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>();
    if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then  // Virtual IRQ enabled if TGE==0 and FMO==1
        assert HCR().TGE == '0' &amp;&amp; HCR().FMO == '1';
    else
        assert HCR_EL2().TGE == '0' &amp;&amp; HCR_EL2().FMO == '1';
    end;
    // Check if routed to AArch64 state
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then <a link="func_AArch64_TakeVirtualFIQException_0" file="shared_pseudocode.xml">AArch64_TakeVirtualFIQException</a>(); end;

    let preferred_exception_return : bits(32)= ThisInstrAddr{}();
    let vect_offset : integer = 0x1C;
    let lr_offset : integer   = 4;

    AArch32_EnterMode(<a link="global_M32_FIQ" file="shared_pseudocode.xml">M32_FIQ</a>, preferred_exception_return, lr_offset, vect_offset);
end;</pstext></ps>
    <ps name="aarch32/exceptions/async/AArch32_TakeVirtualIRQException" mylink="aarch32.exceptions.async.AArch32_TakeVirtualIRQException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TakeVirtualIRQException()
// =================================

func <anchor link="func_AArch32_TakeVirtualIRQException_0">AArch32_TakeVirtualIRQException</anchor>()
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>();

    if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then   // Virtual IRQs enabled if TGE==0 and IMO==1
        assert HCR().TGE == '0' &amp;&amp; HCR().IMO == '1';
    else
        assert HCR_EL2().TGE == '0' &amp;&amp; HCR_EL2().IMO == '1';
    end;

    // Check if routed to AArch64 state
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then <a link="func_AArch64_TakeVirtualIRQException_0" file="shared_pseudocode.xml">AArch64_TakeVirtualIRQException</a>(); end;

    let preferred_exception_return :  bits(32) = ThisInstrAddr{}();
    let vect_offset : integer = 0x18;
    let lr_offset : integer   = 4;

    AArch32_EnterMode(<a link="global_M32_IRQ" file="shared_pseudocode.xml">M32_IRQ</a>, preferred_exception_return, lr_offset, vect_offset);
end;</pstext></ps>
    <ps name="aarch32/exceptions/async/AArch32_TakeVirtualSErrorException" mylink="aarch32.exceptions.async.AArch32_TakeVirtualSErrorException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TakeVirtualSErrorException()
// ====================================

func <anchor link="func_AArch32_TakeVirtualSErrorException_0">AArch32_TakeVirtualSErrorException</anchor>()
begin

    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>();
    if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then   // Virtual SError enabled if TGE==0 and AMO==1
        assert HCR().TGE == '0' &amp;&amp; HCR().AMO == '1';
    else
        assert HCR_EL2().TGE == '0' &amp;&amp; HCR_EL2().AMO == '1';
    end;
    // Check if routed to AArch64 state
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then <a link="func_AArch64_TakeVirtualSErrorException_0" file="shared_pseudocode.xml">AArch64_TakeVirtualSErrorException</a>(); end;
    let route_to_monitor : boolean = FALSE;

    let preferred_exception_return : bits(32) = ThisInstrAddr{}();
    let vect_offset : integer = 0x10;
    let lr_offset : integer   = 8;

    let vaddress : bits(32)   = ARBITRARY : bits(32);
    let parity : boolean      = FALSE;
    let fault : <a link="type_Fault" file="shared_pseudocode.xml">Fault</a>         = <a link="enum_Fault_AsyncExternal" file="shared_pseudocode.xml">Fault_AsyncExternal</a>;
    let level : integer       = ARBITRARY : integer;
    var fsr : bits(32)        = Zeros{};
    if IsFeatureImplemented(FEAT_RAS) then
        if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
            fsr[15:14] =  VDFSR().AET;
            fsr[12] =  VDFSR().ExT;
        else
            fsr[15:14] =  VSESR_EL2().AET;
            fsr[12] =  VSESR_EL2().ExT;
        end;
    else
        fsr[12] = ImpDefBit(&quot;Virtual External abort type&quot;);
    end;
    if TTBCR().EAE == '1' then // Long-descriptor format
        fsr[9] = '1';
        fsr[5:0] = <a link="func_EncodeLDFSC_2" file="shared_pseudocode.xml">EncodeLDFSC</a>(fault, level);
    else                       // Short-descriptor format
        fsr[9] = '0';
        fsr[10,3:0] = <a link="func_EncodeSDFSC_2" file="shared_pseudocode.xml">EncodeSDFSC</a>(fault, level);
    end;
    DFSR() = fsr;
    DFAR() = ARBITRARY : bits(32);
    <a link="func_ClearPendingVirtualSError_0" file="shared_pseudocode.xml">ClearPendingVirtualSError</a>();
    AArch32_EnterMode(<a link="global_M32_Abort" file="shared_pseudocode.xml">M32_Abort</a>, preferred_exception_return, lr_offset, vect_offset);
end;</pstext></ps>
    <ps name="aarch32/exceptions/debug/AArch32_SoftwareBreakpoint" mylink="aarch32.exceptions.debug.AArch32_SoftwareBreakpoint" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_SoftwareBreakpoint()
// ============================

func <anchor link="func_AArch32_SoftwareBreakpoint_1">AArch32_SoftwareBreakpoint</anchor>(immediate : bits(16))
begin

    if (<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp;
        (HCR_EL2().TGE == '1' || MDCR_EL2().TDE == '1')) || !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        <a link="func_AArch64_SoftwareBreakpoint_1" file="shared_pseudocode.xml">AArch64_SoftwareBreakpoint</a>(immediate);
    end;

    let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescIFetch_0" file="shared_pseudocode.xml">CreateAccDescIFetch</a>();
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_2" file="shared_pseudocode.xml">NoFault</a>(accdesc, ARBITRARY : bits(64));

    fault.statuscode = <a link="enum_Fault_Debug" file="shared_pseudocode.xml">Fault_Debug</a>;
    fault.debugmoe   = <a link="global_DebugException_BKPT" file="shared_pseudocode.xml">DebugException_BKPT</a>;

    <a link="func_AArch32_Abort_1" file="shared_pseudocode.xml">AArch32_Abort</a>(fault);
end;</pstext></ps>
    <ps name="aarch32/exceptions/debug/DebugException" mylink="aarch32.exceptions.debug.DebugException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DebugException
// ==============
// Reason codes for debug exceptions, taken to AArch32

constant <anchor link="global_DebugException_Breakpoint">DebugException_Breakpoint</anchor> : bits(4)  = '0001';
constant <anchor link="global_DebugException_BKPT">DebugException_BKPT</anchor> : bits(4)        = '0011';
constant <anchor link="global_DebugException_VectorCatch">DebugException_VectorCatch</anchor> : bits(4) = '0101';
constant <anchor link="global_DebugException_Watchpoint">DebugException_Watchpoint</anchor> : bits(4)  = '1010';</pstext></ps>
    <ps name="aarch32/exceptions/exceptions/AArch32_CheckAdvSIMDOrFPRegisterTraps" mylink="aarch32.exceptions.exceptions.AArch32_CheckAdvSIMDOrFPRegisterTraps" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CheckAdvSIMDOrFPRegisterTraps()
// =======================================
// Check if an instruction that accesses an Advanced SIMD and
// floating-point System register is trapped by an appropriate HCR.TIDx
// ID group trap control.

func <anchor link="func_AArch32_CheckAdvSIMDOrFPRegisterTraps_1">AArch32_CheckAdvSIMDOrFPRegisterTraps</anchor>(reg : bits(4))
begin
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        let tid0 : bit = if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then HCR().TID0 else HCR_EL2().TID0;
        let tid3 : bit = if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then HCR().TID3 else HCR_EL2().TID3;
        if ((tid0 == '1' &amp;&amp; reg == '0000') ||                            // FPSID
              (tid3 == '1' &amp;&amp; reg IN {'0101', '0110', '0111'})) then     // MVFRx
            if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
                <a link="func_AArch32_SystemAccessTrap_2" file="shared_pseudocode.xml">AArch32_SystemAccessTrap</a>(<a link="global_M32_Hyp" file="shared_pseudocode.xml">M32_Hyp</a>, 0x8);
            else
                <a link="func_AArch64_AArch32SystemAccessTrap_2" file="shared_pseudocode.xml">AArch64_AArch32SystemAccessTrap</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, 0x8);
            end;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/exceptions/AArch32_ExceptionClass" mylink="aarch32.exceptions.exceptions.AArch32_ExceptionClass" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ExceptionClass()
// ========================
// Returns the Exception Class and Instruction Length fields to be reported in HSR

func <anchor link="func_AArch32_ExceptionClass_1">AArch32_ExceptionClass</anchor>(exceptype : <a link="type_Exception" file="shared_pseudocode.xml">Exception</a>) =&gt; (integer,bit)
begin
    var il_is_valid : boolean = TRUE;
    var ec : integer;
    case exceptype of
        when <a link="enum_Exception_Uncategorized" file="shared_pseudocode.xml">Exception_Uncategorized</a> =&gt;        ec = 0x00; il_is_valid = FALSE;
        when <a link="enum_Exception_WFxTrap" file="shared_pseudocode.xml">Exception_WFxTrap</a> =&gt;              ec = 0x01;
        when <a link="enum_Exception_CP15RTTrap" file="shared_pseudocode.xml">Exception_CP15RTTrap</a> =&gt;           ec = 0x03;
        when <a link="enum_Exception_CP15RRTTrap" file="shared_pseudocode.xml">Exception_CP15RRTTrap</a> =&gt;          ec = 0x04;
        when <a link="enum_Exception_CP14RTTrap" file="shared_pseudocode.xml">Exception_CP14RTTrap</a> =&gt;           ec = 0x05;
        when <a link="enum_Exception_CP14DTTrap" file="shared_pseudocode.xml">Exception_CP14DTTrap</a> =&gt;           ec = 0x06;
        when <a link="enum_Exception_AdvSIMDFPAccessTrap" file="shared_pseudocode.xml">Exception_AdvSIMDFPAccessTrap</a> =&gt;  ec = 0x07;
        when <a link="enum_Exception_FPIDTrap" file="shared_pseudocode.xml">Exception_FPIDTrap</a> =&gt;             ec = 0x08;
        when <a link="enum_Exception_CP14RRTTrap" file="shared_pseudocode.xml">Exception_CP14RRTTrap</a> =&gt;          ec = 0x0C;
        when <a link="enum_Exception_IllegalState" file="shared_pseudocode.xml">Exception_IllegalState</a> =&gt;         ec = 0x0E; il_is_valid = FALSE;
        when <a link="enum_Exception_SupervisorCall" file="shared_pseudocode.xml">Exception_SupervisorCall</a> =&gt;       ec = 0x11;
        when <a link="enum_Exception_HypervisorCall" file="shared_pseudocode.xml">Exception_HypervisorCall</a> =&gt;       ec = 0x12;
        when <a link="enum_Exception_MonitorCall" file="shared_pseudocode.xml">Exception_MonitorCall</a> =&gt;          ec = 0x13;
        when <a link="enum_Exception_InstructionAbort" file="shared_pseudocode.xml">Exception_InstructionAbort</a> =&gt;
            ec = if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then 0x21 else 0x20;
            il_is_valid = FALSE;
        when <a link="enum_Exception_PCAlignment" file="shared_pseudocode.xml">Exception_PCAlignment</a> =&gt;          ec = 0x22; il_is_valid = FALSE;
        when <a link="enum_Exception_DataAbort" file="shared_pseudocode.xml">Exception_DataAbort</a> =&gt;            ec = if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then 0x25 else 0x24;
        when <a link="enum_Exception_FPTrappedException" file="shared_pseudocode.xml">Exception_FPTrappedException</a> =&gt;   ec = 0x28;
        when <a link="enum_Exception_Profiling" file="shared_pseudocode.xml">Exception_Profiling</a> =&gt;            ec = 0x3D;
        otherwise =&gt;                           unreachable;
    end;

    var il : bit;
    if il_is_valid then
        il = if <a link="func_ThisInstrLength_0" file="shared_pseudocode.xml">ThisInstrLength</a>() == 32 then '1' else '0';
    else
        il = '1';
    end;

    return (ec,il);
end;</pstext></ps>
    <ps name="aarch32/exceptions/exceptions/AArch32_GeneralExceptionsToAArch64" mylink="aarch32.exceptions.exceptions.AArch32_GeneralExceptionsToAArch64" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_GeneralExceptionsToAArch64()
// ====================================
// Returns TRUE if exceptions normally routed to EL1 are being handled at an Exception
// level using AArch64, because either EL1 is using AArch64 or TGE is in force and EL2
// is using AArch64.

func <anchor link="func_AArch32_GeneralExceptionsToAArch64_0">AArch32_GeneralExceptionsToAArch64</anchor>() =&gt; boolean
begin
    return ((<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>)) ||
            (<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; HCR_EL2().TGE == '1'));
end;</pstext></ps>
    <ps name="aarch32/exceptions/exceptions/AArch32_ReportHypEntry" mylink="aarch32.exceptions.exceptions.AArch32_ReportHypEntry" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ReportHypEntry()
// ========================
// Report syndrome information to Hyp mode registers.

func <anchor link="func_AArch32_ReportHypEntry_1">AArch32_ReportHypEntry</anchor>(except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>)
begin

    let exceptype : <a link="type_Exception" file="shared_pseudocode.xml">Exception</a> = except.exceptype;

    var (ec,il) : (integer, bit) = <a link="func_AArch32_ExceptionClass_1" file="shared_pseudocode.xml">AArch32_ExceptionClass</a>(exceptype);
    let iss  : bits(25)= except.syndrome.iss;
    let iss2 : bits(24)= except.syndrome.iss2;

    // IL is not valid for Data Abort exceptions without valid instruction syndrome information
    if ec IN {0x24,0x25} &amp;&amp; iss[24] == '0' then
        il = '1';
    end;

    HSR() = ec[5:0]::il::iss;

    if exceptype IN {<a link="enum_Exception_InstructionAbort" file="shared_pseudocode.xml">Exception_InstructionAbort</a>, <a link="enum_Exception_PCAlignment" file="shared_pseudocode.xml">Exception_PCAlignment</a>} then
        HIFAR() = except.vaddress[31:0];
        HDFAR() = ARBITRARY : bits(32);
    elsif exceptype == <a link="enum_Exception_DataAbort" file="shared_pseudocode.xml">Exception_DataAbort</a> then
        HIFAR() = ARBITRARY : bits(32);
        HDFAR() = except.vaddress[31:0];
    end;

    if except.ipavalid then
        HPFAR()[31:4] = except.ipaddress[39:12];
    else
        HPFAR()[31:4] = ARBITRARY : bits(28);
    end;

    return;
end;</pstext></ps>
    <ps name="aarch32/exceptions/exceptions/AArch32_ResetControlRegisters" mylink="aarch32.exceptions.exceptions.AArch32_ResetControlRegisters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ResetControlRegisters()
// ===============================
// Resets System registers and memory-mapped control registers that have architecturally-defined
// reset values to those values.

impdef func AArch32_ResetControlRegisters(cold_reset : boolean)
begin
    return;
end;</pstext></ps>
    <ps name="aarch32/exceptions/exceptions/AArch32_TakeReset" mylink="aarch32.exceptions.exceptions.AArch32_TakeReset" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TakeReset()
// ===================
// Reset into AArch32 state

func <anchor link="func_AArch32_TakeReset_1">AArch32_TakeReset</anchor>(cold_reset : boolean)
begin
    assert !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>();

    // Enter the highest implemented Exception level in AArch32 state
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        <a link="func_AArch32_WriteMode_1" file="shared_pseudocode.xml">AArch32_WriteMode</a>(<a link="global_M32_Svc" file="shared_pseudocode.xml">M32_Svc</a>);
        SCR().NS = '0';                                 // Secure state
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        <a link="func_AArch32_WriteMode_1" file="shared_pseudocode.xml">AArch32_WriteMode</a>(<a link="global_M32_Hyp" file="shared_pseudocode.xml">M32_Hyp</a>);
    else
        <a link="func_AArch32_WriteMode_1" file="shared_pseudocode.xml">AArch32_WriteMode</a>(<a link="global_M32_Svc" file="shared_pseudocode.xml">M32_Svc</a>);
    end;

    // Reset System registers in the coproc=0b111x encoding space
    // and other system components
    AArch32_ResetControlRegisters(cold_reset);
    FPEXC().EN = '0';

    // Reset all other PSTATE fields, including instruction set and endianness according to the
    // SCTLR values produced by the above call to ResetControlRegisters()
    PSTATE.[A,I,F] = '111';             // All asynchronous exceptions masked
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT = '00000000';             // IT block state reset
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T = HSCTLR().TE;           // Instruction set: TE=0:A32, TE=1:T32. PSTATE.J is RES0.
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.E = HSCTLR().EE;           // Endianness: EE=0: little-endian, EE=1: big-endian.
    else
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T = SCTLR().TE;            // Instruction set: TE=0:A32, TE=1:T32. PSTATE.J is RES0.
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.E = SCTLR().EE;            // Endianness: EE=0: little-endian, EE=1: big-endian.
    end;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL = '0';                    // Clear Illegal Execution state bit

    // All registers, bits and fields not reset by the above pseudocode or by the BranchTo() call
    // below are UNKNOWN bitstrings after reset. In particular, the return information registers
    // R14 or ELR_hyp and SPSR have UNKNOWN values, so that it
    // is impossible to return from a reset in an architecturally defined way.
    <a link="func_AArch32_ResetGeneralRegisters_0" file="shared_pseudocode.xml">AArch32_ResetGeneralRegisters</a>();
    if IsFeatureImplemented(FEAT_SME) || IsFeatureImplemented(FEAT_SVE) then
        <a link="func_ResetSVERegisters_0" file="shared_pseudocode.xml">ResetSVERegisters</a>();
    else
        <a link="func_AArch32_ResetSIMDFPRegisters_0" file="shared_pseudocode.xml">AArch32_ResetSIMDFPRegisters</a>();
    end;
    <a link="func_AArch32_ResetSpecialRegisters_0" file="shared_pseudocode.xml">AArch32_ResetSpecialRegisters</a>();
    ResetExternalDebugRegisters(cold_reset);


    var rv : bits(32);                      // IMPLEMENTATION DEFINED reset vector
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        if MVBAR()[0] == '1' then           // Reset vector in MVBAR
            rv = MVBAR()[31:1]::'0';
        else
            rv = ImpDefBits{32}(&quot;reset vector address&quot;);
        end;
    else
        rv = RVBAR()[31:1]::'0';
    end;

    // The reset vector must be correctly aligned
    assert rv[0] == '0' &amp;&amp; (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T == '1' || rv[1] == '0');

    let branch_conditional : boolean = FALSE;
    EDPRSR().R = '0';                 // Leaving Reset State.
    <a link="func_BranchTo_4" file="shared_pseudocode.xml">BranchTo</a>{32}(rv, <a link="enum_BranchType_RESET" file="shared_pseudocode.xml">BranchType_RESET</a>, branch_conditional);
end;</pstext></ps>
    <ps name="aarch32/exceptions/exceptions/ExcVectorBase" mylink="aarch32.exceptions.exceptions.ExcVectorBase" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExcVectorBase()
// ===============

func <anchor link="func_ExcVectorBase_0">ExcVectorBase</anchor>() =&gt; bits(32)
begin
    if SCTLR().V == '1' then  // Hivecs selected, base = 0xFFFF0000
        return Ones{16}::Zeros{16};
    else
        return VBAR()[31:5]::Zeros{5};
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/ieeefp/AArch32_FPTrappedException" mylink="aarch32.exceptions.ieeefp.AArch32_FPTrappedException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_FPTrappedException()
// ============================

func <anchor link="func_AArch32_FPTrappedException_1">AArch32_FPTrappedException</anchor>(accumulated_exceptions : bits(8))
begin
    if <a link="func_AArch32_GeneralExceptionsToAArch64_0" file="shared_pseudocode.xml">AArch32_GeneralExceptionsToAArch64</a>() then
        let is_ase : boolean = FALSE;
        let element : integer = 0;
        <a link="func_AArch64_FPTrappedException_2" file="shared_pseudocode.xml">AArch64_FPTrappedException</a>(is_ase, accumulated_exceptions);
    end;
    FPEXC().DEX    = '1';
    FPEXC().TFV    = '1';
    FPEXC()[7,4:0] = accumulated_exceptions[7,4:0];                  // IDF,IXF,UFF,OFF,DZF,IOF
    FPEXC()[10:8]  = '111';                                          // VECITR is RES1

    AArch32_TakeUndefInstrException();
end;</pstext></ps>
    <ps name="aarch32/exceptions/syscalls/AArch32_CallHypervisor" mylink="aarch32.exceptions.syscalls.AArch32_CallHypervisor" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CallHypervisor()
// ========================
// Performs a HVC call

func <anchor link="func_AArch32_CallHypervisor_1">AArch32_CallHypervisor</anchor>(immediate : bits(16))
begin
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);

    if !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        <a link="func_AArch64_CallHypervisor_1" file="shared_pseudocode.xml">AArch64_CallHypervisor</a>(immediate);
    else
        <a link="func_AArch32_TakeHVCException_1" file="shared_pseudocode.xml">AArch32_TakeHVCException</a>(immediate);
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/syscalls/AArch32_CallSupervisor" mylink="aarch32.exceptions.syscalls.AArch32_CallSupervisor" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CallSupervisor()
// ========================
// Calls the Supervisor

func <anchor link="func_AArch32_CallSupervisor_1">AArch32_CallSupervisor</anchor>(immediate_in : bits(16))
begin
    var immediate : bits(16) = immediate_in;
    if <a link="func_CurrentCond_0" file="shared_pseudocode.xml">CurrentCond</a>() != '1110' then
        immediate = ARBITRARY : bits(16);
    end;
    if <a link="func_AArch32_GeneralExceptionsToAArch64_0" file="shared_pseudocode.xml">AArch32_GeneralExceptionsToAArch64</a>() then
        <a link="func_AArch64_CallSupervisor_1" file="shared_pseudocode.xml">AArch64_CallSupervisor</a>(immediate);
    else
        <a link="func_AArch32_TakeSVCException_1" file="shared_pseudocode.xml">AArch32_TakeSVCException</a>(immediate);
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/syscalls/AArch32_TakeHVCException" mylink="aarch32.exceptions.syscalls.AArch32_TakeHVCException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TakeHVCException()
// ==========================

func <anchor link="func_AArch32_TakeHVCException_1">AArch32_TakeHVCException</anchor>(immediate : bits(16))
begin
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);

    <a link="func_AArch32_ITAdvance_0" file="shared_pseudocode.xml">AArch32_ITAdvance</a>();
    <a link="func_SSAdvance_0" file="shared_pseudocode.xml">SSAdvance</a>();
    let preferred_exception_return : bits(32) = NextInstrAddr{}();
    let vect_offset : integer{} = 0x08;

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_HypervisorCall" file="shared_pseudocode.xml">Exception_HypervisorCall</a>);
    except.syndrome.iss[15:0] = immediate;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
        AArch32_EnterHypMode(except, preferred_exception_return, vect_offset);
    else
        AArch32_EnterHypMode(except, preferred_exception_return, 0x14);
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/syscalls/AArch32_TakeSMCException" mylink="aarch32.exceptions.syscalls.AArch32_TakeSMCException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TakeSMCException()
// ==========================

func <anchor link="func_AArch32_TakeSMCException_0">AArch32_TakeSMCException</anchor>()
begin
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
    <a link="func_AArch32_ITAdvance_0" file="shared_pseudocode.xml">AArch32_ITAdvance</a>();
    <a link="func_HSAdvance_0" file="shared_pseudocode.xml">HSAdvance</a>();
    <a link="func_SSAdvance_0" file="shared_pseudocode.xml">SSAdvance</a>();
    let preferred_exception_return : bits(32) = NextInstrAddr{}();
    let vect_offset : integer = 0x08;
    let lr_offset : integer = 0;
    <a link="func_AArch32_EnterMonitorMode_3" file="shared_pseudocode.xml">AArch32_EnterMonitorMode</a>(preferred_exception_return, lr_offset, vect_offset);
end;</pstext></ps>
    <ps name="aarch32/exceptions/syscalls/AArch32_TakeSVCException" mylink="aarch32.exceptions.syscalls.AArch32_TakeSVCException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TakeSVCException()
// ==========================

func <anchor link="func_AArch32_TakeSVCException_1">AArch32_TakeSVCException</anchor>(immediate : bits(16))
begin

    <a link="func_AArch32_ITAdvance_0" file="shared_pseudocode.xml">AArch32_ITAdvance</a>();
    <a link="func_SSAdvance_0" file="shared_pseudocode.xml">SSAdvance</a>();
    let route_to_hyp : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR().TGE == '1';

    let preferred_exception_return : bits(32) = NextInstrAddr{}();
    let vect_offset : integer{} = 0x08;
    let lr_offset : integer{} = 0;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || route_to_hyp then
        var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_SupervisorCall" file="shared_pseudocode.xml">Exception_SupervisorCall</a>);
        except.syndrome.iss[15:0] = immediate;
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
            AArch32_EnterHypMode(except, preferred_exception_return, vect_offset);
        else
            AArch32_EnterHypMode(except, preferred_exception_return, 0x14);
        end;
    else
        AArch32_EnterMode(<a link="global_M32_Svc" file="shared_pseudocode.xml">M32_Svc</a>, preferred_exception_return, lr_offset, vect_offset);
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/takeexception/AArch32_EnterHypMode" mylink="aarch32.exceptions.takeexception.AArch32_EnterHypMode" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_EnterHypMode()
// ======================
// Take an exception to Hyp mode.

noreturn func AArch32_EnterHypMode(except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>, preferred_exception_return : bits(32),
                                   vect_offset : integer)
begin
    SynchronizeContext();
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() == <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);

    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then
        AArch32_EnterHypModeInDebugState(except);
    end;
    let spsr : bits(32) = GetPSRFromPSTATE{}(<a link="enum_AArch32_NonDebugState" file="shared_pseudocode.xml">AArch32_NonDebugState</a>);
    if ! except.exceptype IN {<a link="enum_Exception_IRQ" file="shared_pseudocode.xml">Exception_IRQ</a>, <a link="enum_Exception_FIQ" file="shared_pseudocode.xml">Exception_FIQ</a>} then
        <a link="func_AArch32_ReportHypEntry_1" file="shared_pseudocode.xml">AArch32_ReportHypEntry</a>(except);
    end;
    <a link="func_AArch32_WriteMode_1" file="shared_pseudocode.xml">AArch32_WriteMode</a>(<a link="global_M32_Hyp" file="shared_pseudocode.xml">M32_Hyp</a>);
    <a link="accessor_SPSR_curr_0" file="shared_pseudocode.xml">SPSR_curr</a>() = spsr;
    ELR_hyp() = preferred_exception_return;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T  = HSCTLR().TE;                       // PSTATE.J is RES0
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SS = '0';
    if !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.A = '1';
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.I = '1';
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.F = '1';
    else
        if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
            if SCR().EA  == '0' then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.A = '1'; end;
            if SCR().IRQ == '0' then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.I = '1'; end;
            if SCR().FIQ == '0' then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.F = '1'; end;
        else
            if SCR_EL3().EA  == '0' then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.A = '1'; end;
            if <a link="func_EffectiveSCR_EL3_IRQ_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_IRQ</a>() == '0' then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.I = '1'; end;
            if <a link="func_EffectiveSCR_EL3_FIQ_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_FIQ</a>() == '0' then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.F = '1'; end;
        end;
    end;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.E  = HSCTLR().EE;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL = '0';
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT = '00000000';
    if IsFeatureImplemented(FEAT_SSBS) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SSBS = HSCTLR().DSSBS; end;
    let branch_conditional : boolean = FALSE;
    <a link="func_BranchTo_4" file="shared_pseudocode.xml">BranchTo</a>{32}(HVBAR()[31:5]::vect_offset[4:0], <a link="enum_BranchType_EXCEPTION" file="shared_pseudocode.xml">BranchType_EXCEPTION</a>, branch_conditional);

    <a link="func_CheckExceptionCatch_1" file="shared_pseudocode.xml">CheckExceptionCatch</a>(TRUE);                  // Check for debug event on exception entry

    EndOfInstruction(<a link="enum_EndOfInstructionReason_Exception" file="shared_pseudocode.xml">EndOfInstructionReason_Exception</a>);
end;</pstext></ps>
    <ps name="aarch32/exceptions/takeexception/AArch32_EnterMode" mylink="aarch32.exceptions.takeexception.AArch32_EnterMode" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_EnterMode()
// ===================
// Take an exception to a mode other than Monitor and Hyp mode.

noreturn func AArch32_EnterMode(target_mode : bits(5),
                                preferred_exception_return : bits(32),
                                lr_offset : integer,
                                vect_offset : integer)
begin
    SynchronizeContext();
    assert <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;

    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then
        AArch32_EnterModeInDebugState(target_mode);
    end;
    let spsr : bits(32) = GetPSRFromPSTATE{}(<a link="enum_AArch32_NonDebugState" file="shared_pseudocode.xml">AArch32_NonDebugState</a>);
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M == <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a> then SCR().NS = '0'; end;
    <a link="func_AArch32_WriteMode_1" file="shared_pseudocode.xml">AArch32_WriteMode</a>(target_mode);
    <a link="accessor_SPSR_curr_0" file="shared_pseudocode.xml">SPSR_curr</a>() = spsr;
    <a link="accessor_R_1" file="shared_pseudocode.xml">R</a>(14) = preferred_exception_return + lr_offset;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T = SCTLR().TE;                        // PSTATE.J is RES0
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SS = '0';
    if target_mode == <a link="global_M32_FIQ" file="shared_pseudocode.xml">M32_FIQ</a> then
        PSTATE.[A,I,F] = '111';
    elsif target_mode IN {<a link="global_M32_Abort" file="shared_pseudocode.xml">M32_Abort</a>, <a link="global_M32_IRQ" file="shared_pseudocode.xml">M32_IRQ</a>} then
        PSTATE.[A,I] = '11';
    else
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.I = '1';
    end;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.E = SCTLR().EE;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL = '0';
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT = '00000000';
    if IsFeatureImplemented(FEAT_PAN) &amp;&amp; SCTLR().SPAN == '0' then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN = '1'; end;
    if IsFeatureImplemented(FEAT_SSBS) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SSBS = SCTLR().DSSBS; end;
    let branch_conditional : boolean = FALSE;
    <a link="func_BranchTo_4" file="shared_pseudocode.xml">BranchTo</a>{32}(<a link="func_ExcVectorBase_0" file="shared_pseudocode.xml">ExcVectorBase</a>()[31:5]::vect_offset[4:0], <a link="enum_BranchType_EXCEPTION" file="shared_pseudocode.xml">BranchType_EXCEPTION</a>, branch_conditional);

    <a link="func_CheckExceptionCatch_1" file="shared_pseudocode.xml">CheckExceptionCatch</a>(TRUE);                  // Check for debug event on exception entry

    EndOfInstruction(<a link="enum_EndOfInstructionReason_Exception" file="shared_pseudocode.xml">EndOfInstructionReason_Exception</a>);
end;</pstext></ps>
    <ps name="aarch32/exceptions/takeexception/AArch32_EnterMonitorMode" mylink="aarch32.exceptions.takeexception.AArch32_EnterMonitorMode" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_EnterMonitorMode()
// ==========================
// Take an exception to Monitor mode.

func <anchor link="func_AArch32_EnterMonitorMode_3">AArch32_EnterMonitorMode</anchor>(preferred_exception_return : bits(32), lr_offset : integer,
                              vect_offset : integer)
begin
    SynchronizeContext();
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
    let from_secure : boolean = <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>;
    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then
        <a link="func_AArch32_EnterMonitorModeInDebugState_0" file="shared_pseudocode.xml">AArch32_EnterMonitorModeInDebugState</a>();
    end;
    let spsr : bits(32) = GetPSRFromPSTATE{}(<a link="enum_AArch32_NonDebugState" file="shared_pseudocode.xml">AArch32_NonDebugState</a>);
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M == <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a> then SCR().NS = '0'; end;
    <a link="func_AArch32_WriteMode_1" file="shared_pseudocode.xml">AArch32_WriteMode</a>(<a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a>);
    <a link="accessor_SPSR_curr_0" file="shared_pseudocode.xml">SPSR_curr</a>() = spsr;
    <a link="accessor_R_1" file="shared_pseudocode.xml">R</a>(14) = preferred_exception_return + lr_offset;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T       = SCTLR().TE;                        // PSTATE.J is RES0
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SS      = '0';
    PSTATE.[A,I,F] = '111';
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.E       = SCTLR().EE;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL      = '0';
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT      = '00000000';
    if IsFeatureImplemented(FEAT_PAN) then
        if !from_secure then
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN = '0';
        elsif SCTLR().SPAN == '0' then
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN = '1';
        end;
    end;
    if IsFeatureImplemented(FEAT_SSBS) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SSBS = SCTLR().DSSBS; end;
    let branch_conditional : boolean = FALSE;
    <a link="func_BranchTo_4" file="shared_pseudocode.xml">BranchTo</a>{32}(MVBAR()[31:5]::vect_offset[4:0], <a link="enum_BranchType_EXCEPTION" file="shared_pseudocode.xml">BranchType_EXCEPTION</a>, branch_conditional);

    <a link="func_CheckExceptionCatch_1" file="shared_pseudocode.xml">CheckExceptionCatch</a>(TRUE);                  // Check for debug event on exception entry

    EndOfInstruction(<a link="enum_EndOfInstructionReason_Exception" file="shared_pseudocode.xml">EndOfInstructionReason_Exception</a>);
end;</pstext></ps>
    <ps name="aarch32/exceptions/traps/AArch32_CheckAdvSIMDOrFPEnabled" mylink="aarch32.exceptions.traps.AArch32_CheckAdvSIMDOrFPEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CheckAdvSIMDOrFPEnabled()
// =================================
// Check against CPACR, FPEXC, HCPTR, NSACR, and CPTR_EL3.

func <anchor link="func_AArch32_CheckAdvSIMDOrFPEnabled_2">AArch32_CheckAdvSIMDOrFPEnabled</anchor>(fpexc_check_in : boolean, advsimd : boolean)
begin
    var fpexc_check : boolean = fpexc_check_in;
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        // When executing at EL0 using AArch32, if EL1 is using AArch64 then the Effective value of
        // FPEXC.EN is 1. This includes when EL2 is using AArch64 and enabled in the current
        // Security state, HCR_EL2.TGE is 1, and the Effective value of HCR_EL2.RW is 1.
        <a link="func_AArch64_CheckFPAdvSIMDEnabled_0" file="shared_pseudocode.xml">AArch64_CheckFPAdvSIMDEnabled</a>();
    else
        var cpacr_asedis = CPACR().ASEDIS;
        var cpacr_cp10 = CPACR().cp10;

        if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() == <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> then
            // Check if access disabled in NSACR
            if NSACR().NSASEDIS == '1' then cpacr_asedis = '1'; end;
            if NSACR().cp10 == '0' then cpacr_cp10 = '00'; end;
        end;

        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
            // Check if Advanced SIMD disabled in CPACR
            if advsimd &amp;&amp; cpacr_asedis == '1' then AArch32_Undefined(); end;

            // Check if access disabled in CPACR
            var disabled : boolean;
            case cpacr_cp10 of
                when '00' =&gt; disabled = TRUE;
                when '01' =&gt; disabled = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
                when '10' =&gt; disabled = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_RESCPACR" file="shared_pseudocode.xml">Unpredictable_RESCPACR</a>);
                when '11' =&gt; disabled = FALSE;
            end;
            if disabled then AArch32_Undefined(); end;
        end;

        // If required, check FPEXC enabled bit.
        if (fpexc_check &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp;
              HCR_EL2().TGE == '1') then
            // When executing at EL0 using AArch32, if EL2 is using AArch64 and enabled in the
            // current Security state, HCR_EL2.TGE is 1, and the Effective value of HCR_EL2.RW is 0
            // then it is IMPLEMENTATION DEFINED whether the Effective value of FPEXC.EN is 1
            // or the value of FPEXC32_EL2.EN.
            fpexc_check = ImpDefBool(&quot;Use FPEXC32_EL2.EN value when {TGE,RW} == {1,0}&quot;);
        end;

        if fpexc_check &amp;&amp; FPEXC().EN == '0' then
            AArch32_Undefined();
        end;

        <a link="func_AArch32_CheckFPAdvSIMDTrap_1" file="shared_pseudocode.xml">AArch32_CheckFPAdvSIMDTrap</a>(advsimd);    // Also check against HCPTR and CPTR_EL3
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/traps/AArch32_CheckFPAdvSIMDTrap" mylink="aarch32.exceptions.traps.AArch32_CheckFPAdvSIMDTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CheckFPAdvSIMDTrap()
// ============================
// Check against CPTR_EL2 and CPTR_EL3.

func <anchor link="func_AArch32_CheckFPAdvSIMDTrap_1">AArch32_CheckFPAdvSIMDTrap</anchor>(advsimd : boolean)
begin
    if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        <a link="func_AArch64_CheckFPAdvSIMDTrap_0" file="shared_pseudocode.xml">AArch64_CheckFPAdvSIMDTrap</a>();
    else
        if (<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp;
            CPTR_EL3().TFP == '1' &amp;&amp; <a link="func_EL3SDDUndefPriority_0" file="shared_pseudocode.xml">EL3SDDUndefPriority</a>()) then
            Undefined();
        end;

        let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>();
        if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; ss != <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
            var hcptr_tase = HCPTR().TASE;
            var hcptr_cp10 = HCPTR().TCP10;

            if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
                // Check if access disabled in NSACR
                if NSACR().NSASEDIS == '1' then hcptr_tase = '1'; end;
                if NSACR().cp10 == '0' then hcptr_cp10 = '1'; end;
            end;

            // Check if access disabled in HCPTR
            if (advsimd &amp;&amp; hcptr_tase == '1') || hcptr_cp10 == '1' then
                var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_AdvSIMDFPAccessTrap" file="shared_pseudocode.xml">Exception_AdvSIMDFPAccessTrap</a>);
                except.syndrome.iss[24:20] = <a link="func_ConditionSyndrome_0" file="shared_pseudocode.xml">ConditionSyndrome</a>();

                if advsimd then
                    except.syndrome.iss[5] = '1';
                else
                    except.syndrome.iss[5]   = '0';
                    except.syndrome.iss[3:0] = '1010';         // coproc field, always 0xA
                end;

                if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
                    AArch32_TakeUndefInstrException(except);
                else
                    <a link="func_AArch32_TakeHypTrapException_1" file="shared_pseudocode.xml">AArch32_TakeHypTrapException</a>(except);
                end;
            end;
        end;

        if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
            // Check if access disabled in CPTR_EL3
            if CPTR_EL3().TFP == '1' then
                if <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then
                    Undefined();
                else
                    <a link="func_AArch64_AdvSIMDFPAccessTrap_1" file="shared_pseudocode.xml">AArch64_AdvSIMDFPAccessTrap</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
                end;
            end;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/traps/AArch32_CheckForSMCUndefOrTrap" mylink="aarch32.exceptions.traps.AArch32_CheckForSMCUndefOrTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CheckForSMCUndefOrTrap()
// ================================
// Check for UNDEFINED or trap on SMC instruction

func <anchor link="func_AArch32_CheckForSMCUndefOrTrap_0">AArch32_CheckForSMCUndefOrTrap</anchor>()
begin
    if !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        Undefined();
    end;

    if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        <a link="func_AArch64_CheckForSMCUndefOrTrap_1" file="shared_pseudocode.xml">AArch64_CheckForSMCUndefOrTrap</a>(Zeros{16});
    else
        let route_to_hyp : boolean = <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; HCR().TSC == '1';
        if route_to_hyp then
            let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_MonitorCall" file="shared_pseudocode.xml">Exception_MonitorCall</a>);
            <a link="func_AArch32_TakeHypTrapException_1" file="shared_pseudocode.xml">AArch32_TakeHypTrapException</a>(except);
        end;
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/traps/AArch32_CheckForSVCTrap" mylink="aarch32.exceptions.traps.AArch32_CheckForSVCTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CheckForSVCTrap()
// =========================
// Check for trap on SVC instruction

func <anchor link="func_AArch32_CheckForSVCTrap_1">AArch32_CheckForSVCTrap</anchor>(immediate : bits(16))
begin
    if IsFeatureImplemented(FEAT_FGT) then
        let route_to_el2 : boolean = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
                                      HFGITR_EL2().SVC_EL0 == '1' &amp;&amp;
                                      (!<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() &amp;&amp; (!<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || SCR_EL3().FGTEn == '1')));

        if route_to_el2 then
            var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_SupervisorCall" file="shared_pseudocode.xml">Exception_SupervisorCall</a>);
            except.syndrome.iss[15:0] = immediate;
            except.trappedsyscallinst = TRUE;
            let preferred_exception_return : bits(64) = ThisInstrAddr{}();
            let vect_offset : integer = 0x0;

            AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
        end;
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/traps/AArch32_CheckForWFxTrap" mylink="aarch32.exceptions.traps.AArch32_CheckForWFxTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CheckForWFxTrap()
// =========================
// Check for trap on WFE or WFI instruction

func <anchor link="func_AArch32_CheckForWFxTrap_2">AArch32_CheckForWFxTrap</anchor>(target_el : bits(2), wfxtype : <a link="type_WFxType" file="shared_pseudocode.xml">WFxType</a>)
begin
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(target_el);

    // Check for routing to AArch64
    if !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(target_el) then
        var trap : boolean;
        let is_wfe : boolean = wfxtype == <a link="enum_WFxType_WFE" file="shared_pseudocode.xml">WFxType_WFE</a>;
        case target_el of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
                trap = (if is_wfe then <a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>().nTWE else <a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>().nTWI) == '0';
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
                trap = (if is_wfe then HCR_EL2().TWE else HCR_EL2().TWI) == '1';
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
                trap = (if is_wfe then SCR_EL3().TWE else SCR_EL3().TWI) == '1';
        end;

        if trap then
            if target_el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then
                Undefined();
            else
                <a link="func_AArch64_WFxTrap_2" file="shared_pseudocode.xml">AArch64_WFxTrap</a>(wfxtype, target_el);
            end;
        end;
        return;
    end;

    let is_wfe : boolean = wfxtype == <a link="enum_WFxType_WFE" file="shared_pseudocode.xml">WFxType_WFE</a>;
    var trap : boolean;
    case target_el of
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            trap = (if is_wfe then SCTLR().nTWE else SCTLR().nTWI) == '0';
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            trap = (if is_wfe then HCR().TWE else HCR().TWI) == '1';
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            trap = (if is_wfe then SCR().TWE else SCR().TWI) == '1';
    end;

    if trap then
        if target_el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; HCR_EL2().TGE == '1' then
            <a link="func_AArch64_WFxTrap_2" file="shared_pseudocode.xml">AArch64_WFxTrap</a>(wfxtype, target_el);
        end;

        if target_el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; !<a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then
            <a link="func_AArch32_TakeMonitorTrapException_0" file="shared_pseudocode.xml">AArch32_TakeMonitorTrapException</a>();
        elsif target_el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
            var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_WFxTrap" file="shared_pseudocode.xml">Exception_WFxTrap</a>);
            except.syndrome.iss[24:20]   = <a link="func_ConditionSyndrome_0" file="shared_pseudocode.xml">ConditionSyndrome</a>();
            except.syndrome.iss[0]       = if wfxtype == <a link="enum_WFxType_WFI" file="shared_pseudocode.xml">WFxType_WFI</a> then '0' else '1';
            <a link="func_AArch32_TakeHypTrapException_1" file="shared_pseudocode.xml">AArch32_TakeHypTrapException</a>(except);
        else
            AArch32_TakeUndefInstrException();
        end;
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/traps/AArch32_CheckITEnabled" mylink="aarch32.exceptions.traps.AArch32_CheckITEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CheckITEnabled()
// ========================
// Check whether the T32 IT instruction is disabled.

func <anchor link="func_AArch32_CheckITEnabled_1">AArch32_CheckITEnabled</anchor>(mask : bits(4))
begin
    var it_disabled : bit;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
        it_disabled = HSCTLR().ITD;
    else
        it_disabled = (if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then SCTLR().ITD else <a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>().ITD);
    end;
    if it_disabled == '1' then
        if mask != '1000' then Undefined(); end;

        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescIFetch_0" file="shared_pseudocode.xml">CreateAccDescIFetch</a>();
        let aligned = TRUE;
        // Otherwise whether the IT block is allowed depends on hw1 of the next instruction.
        let next_instr = <a link="accessor_AArch32_MemSingle_4" file="shared_pseudocode.xml">AArch32_MemSingle</a>{16}(<a link="func_NextInstrAddr_1" file="shared_pseudocode.xml">NextInstrAddr</a>{32}(), accdesc, aligned);

        if next_instr IN {'11xxxxxxxxxxxxxx', '1011xxxxxxxxxxxx', '10100xxxxxxxxxxx',
                          '01001xxxxxxxxxxx', '010001xxx1111xxx', '010001xx1xxxx111'} then
            // It is IMPLEMENTATION DEFINED whether the Undefined Instruction exception is
            // taken on the IT instruction or the next instruction. This is not reflected in
            // the pseudocode, which always takes the exception on the IT instruction. This
            // also does not take into account cases where the next instruction is UNPREDICTABLE.
            Undefined();
        end;
    end;

    return;
end;</pstext></ps>
    <ps name="aarch32/exceptions/traps/AArch32_CheckIllegalState" mylink="aarch32.exceptions.traps.AArch32_CheckIllegalState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CheckIllegalState()
// ===========================
// Check PSTATE.IL bit and generate Illegal Execution state exception if set.

func <anchor link="func_AArch32_CheckIllegalState_0">AArch32_CheckIllegalState</anchor>()
begin
    if <a link="func_AArch32_GeneralExceptionsToAArch64_0" file="shared_pseudocode.xml">AArch32_GeneralExceptionsToAArch64</a>() then
        <a link="func_AArch64_CheckIllegalState_0" file="shared_pseudocode.xml">AArch64_CheckIllegalState</a>();
    elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL == '1' then
        let route_to_hyp = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR().TGE == '1';

        let preferred_exception_return : bits(32) = ThisInstrAddr{}();
        let vect_offset : integer = 0x04;

        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || route_to_hyp then
            let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_IllegalState" file="shared_pseudocode.xml">Exception_IllegalState</a>);
            if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
                AArch32_EnterHypMode(except, preferred_exception_return, vect_offset);
            else
                AArch32_EnterHypMode(except, preferred_exception_return, 0x14);
            end;
        else
            AArch32_TakeUndefInstrException();
        end;
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/traps/AArch32_CheckSETENDEnabled" mylink="aarch32.exceptions.traps.AArch32_CheckSETENDEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CheckSETENDEnabled()
// ============================
// Check whether the AArch32 SETEND instruction is disabled.

func <anchor link="func_AArch32_CheckSETENDEnabled_0">AArch32_CheckSETENDEnabled</anchor>()
begin
    var setend_disabled : bit;
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
        setend_disabled = HSCTLR().SED;
    else
        setend_disabled = (if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then SCTLR().SED else <a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>().SED);
    end;
    if setend_disabled == '1' then
        Undefined();
    end;

    return;
end;</pstext></ps>
    <ps name="aarch32/exceptions/traps/AArch32_SystemAccessTrap" mylink="aarch32.exceptions.traps.AArch32_SystemAccessTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_SystemAccessTrap()
// ==========================
// Trapped AArch32 System register access.

func <anchor link="func_AArch32_SystemAccessTrap_2">AArch32_SystemAccessTrap</anchor>(mode : bits(5), ec : integer)
begin
    let (valid, target_el) = <a link="func_ELFromM32_1" file="shared_pseudocode.xml">ELFromM32</a>(mode);
    assert valid &amp;&amp; <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(target_el) &amp;&amp; target_el != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; UInt(target_el) &gt;= UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);

    if target_el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
        let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_AArch32_SystemAccessTrapSyndrome_2" file="shared_pseudocode.xml">AArch32_SystemAccessTrapSyndrome</a>(<a link="func_ThisInstr_0" file="shared_pseudocode.xml">ThisInstr</a>(), ec);
        <a link="func_AArch32_TakeHypTrapException_1" file="shared_pseudocode.xml">AArch32_TakeHypTrapException</a>(except);
    else
        AArch32_TakeUndefInstrException();
    end;
end;</pstext></ps>
    <ps name="aarch32/exceptions/traps/AArch32_SystemAccessTrapSyndrome" mylink="aarch32.exceptions.traps.AArch32_SystemAccessTrapSyndrome" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_SystemAccessTrapSyndrome()
// ==================================
// Returns the syndrome information for traps on AArch32 MCR, MCRR, MRC, MRRC, and VMRS,
// VMSR instructions, other than traps that are due to HCPTR or CPACR.

func <anchor link="func_AArch32_SystemAccessTrapSyndrome_2">AArch32_SystemAccessTrapSyndrome</anchor>(instr : bits(32), ec : integer) =&gt; <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>
begin
    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>;

    case ec of
        when 0x0  =&gt;   except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_Uncategorized" file="shared_pseudocode.xml">Exception_Uncategorized</a>);
        when 0x3  =&gt;   except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_CP15RTTrap" file="shared_pseudocode.xml">Exception_CP15RTTrap</a>);
        when 0x4  =&gt;   except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_CP15RRTTrap" file="shared_pseudocode.xml">Exception_CP15RRTTrap</a>);
        when 0x5  =&gt;   except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_CP14RTTrap" file="shared_pseudocode.xml">Exception_CP14RTTrap</a>);
        when 0x6  =&gt;   except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_CP14DTTrap" file="shared_pseudocode.xml">Exception_CP14DTTrap</a>);
        when 0x7  =&gt;   except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_AdvSIMDFPAccessTrap" file="shared_pseudocode.xml">Exception_AdvSIMDFPAccessTrap</a>);
        when 0x8  =&gt;   except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_FPIDTrap" file="shared_pseudocode.xml">Exception_FPIDTrap</a>);
        when 0xC  =&gt;   except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_CP14RRTTrap" file="shared_pseudocode.xml">Exception_CP14RRTTrap</a>);
        otherwise =&gt;   unreachable;
    end;

    var iss : bits(20) = Zeros{};

    if except.exceptype == <a link="enum_Exception_Uncategorized" file="shared_pseudocode.xml">Exception_Uncategorized</a> then
        return except;
    elsif except.exceptype IN {<a link="enum_Exception_FPIDTrap" file="shared_pseudocode.xml">Exception_FPIDTrap</a>, <a link="enum_Exception_CP14RTTrap" file="shared_pseudocode.xml">Exception_CP14RTTrap</a>,
                               <a link="enum_Exception_CP15RTTrap" file="shared_pseudocode.xml">Exception_CP15RTTrap</a>} then
        // Trapped MRC/MCR, VMRS on FPSID
        iss[13:10] = instr[19:16];       // CRn, Reg in case of VMRS
        iss[8:5]   = instr[15:12];       // Rt
        iss[9]     = '0';                // RES0

        if except.exceptype != <a link="enum_Exception_FPIDTrap" file="shared_pseudocode.xml">Exception_FPIDTrap</a> then    // When trap is not for VMRS
            iss[19:17] = instr[7:5];     // opc2
            iss[16:14] = instr[23:21];   // opc1
            iss[4:1]   = instr[3:0];     // CRm
        else //VMRS Access
            iss[19:17] = '000';          // opc2 - Hardcoded for VMRS
            iss[16:14] = '111';          // opc1 - Hardcoded for VMRS
            iss[4:1]   = '0000';         // CRm  - Hardcoded for VMRS
        end;
    elsif except.exceptype IN {<a link="enum_Exception_CP14RRTTrap" file="shared_pseudocode.xml">Exception_CP14RRTTrap</a>, <a link="enum_Exception_AdvSIMDFPAccessTrap" file="shared_pseudocode.xml">Exception_AdvSIMDFPAccessTrap</a>,
                               <a link="enum_Exception_CP15RRTTrap" file="shared_pseudocode.xml">Exception_CP15RRTTrap</a>} then
        // Trapped MRRC/MCRR, VMRS/VMSR
        iss[19:16] = instr[7:4];         // opc1
        iss[13:10] = instr[19:16];       // Rt2
        iss[8:5]   = instr[15:12];       // Rt
        iss[4:1]   = instr[3:0];         // CRm
    elsif except.exceptype == <a link="enum_Exception_CP14DTTrap" file="shared_pseudocode.xml">Exception_CP14DTTrap</a> then
        // Trapped LDC/STC
        iss[19:12] = instr[7:0];         // imm8
        iss[4]     = instr[23];          // U
        iss[2:1]   = instr[24,21];       // P, W
        if instr[19:16] == '1111' then   // Rn==15, LDC(Literal addressing)/STC
            iss[8:5] = ARBITRARY : bits(4);
            iss[3]   = '1';
        end;
    end;
    iss[0] = instr[20];                  // Direction

    except.syndrome.iss[24:20] = <a link="func_ConditionSyndrome_0" file="shared_pseudocode.xml">ConditionSyndrome</a>();
    except.syndrome.iss[19:0]  = iss;

    return except;
end;</pstext></ps>
    <ps name="aarch32/exceptions/traps/AArch32_TakeHypTrapException" mylink="aarch32.exceptions.traps.AArch32_TakeHypTrapException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TakeHypTrapException()
// ==============================
// Exceptions routed to Hyp mode as a Hyp Trap exception.

func <anchor link="func_AArch32_TakeHypTrapException_1">AArch32_TakeHypTrapException</anchor>(ec : integer)
begin
    let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_AArch32_SystemAccessTrapSyndrome_2" file="shared_pseudocode.xml">AArch32_SystemAccessTrapSyndrome</a>(<a link="func_ThisInstr_0" file="shared_pseudocode.xml">ThisInstr</a>(), ec);
    <a link="func_AArch32_TakeHypTrapException_1" file="shared_pseudocode.xml">AArch32_TakeHypTrapException</a>(except);
end;

// AArch32_TakeHypTrapException()
// ==============================
// Exceptions routed to Hyp mode as a Hyp Trap exception.

func <anchor link="func_AArch32_TakeHypTrapException_1">AArch32_TakeHypTrapException</anchor>(except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>)
begin
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() == <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);

    let preferred_exception_return : bits(32) = ThisInstrAddr{}();
    let vect_offset : integer = 0x14;

    AArch32_EnterHypMode(except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch32/exceptions/traps/AArch32_TakeMonitorTrapException" mylink="aarch32.exceptions.traps.AArch32_TakeMonitorTrapException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TakeMonitorTrapException()
// ==================================
// Exceptions routed to Monitor mode as a Monitor Trap exception.

func <anchor link="func_AArch32_TakeMonitorTrapException_0">AArch32_TakeMonitorTrapException</anchor>()
begin
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);

    let preferred_exception_return :  bits(32) = ThisInstrAddr{}();
    let vect_offset : integer = 0x04;
    let lr_offset : integer = if <a link="func_CurrentInstrSet_0" file="shared_pseudocode.xml">CurrentInstrSet</a>() == <a link="enum_InstrSet_A32" file="shared_pseudocode.xml">InstrSet_A32</a> then 4 else 2;
    <a link="func_AArch32_EnterMonitorMode_3" file="shared_pseudocode.xml">AArch32_EnterMonitorMode</a>(preferred_exception_return, lr_offset, vect_offset);
end;</pstext></ps>
    <ps name="aarch32/exceptions/traps/AArch32_TakeUndefInstrException" mylink="aarch32.exceptions.traps.AArch32_TakeUndefInstrException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TakeUndefInstrException()
// =================================

noreturn func AArch32_TakeUndefInstrException(except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>)
begin

    let route_to_hyp : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR().TGE == '1';
    let preferred_exception_return : bits(32) = ThisInstrAddr{}();
    let vect_offset : integer = 0x04;
    let lr_offset : integer = if <a link="func_CurrentInstrSet_0" file="shared_pseudocode.xml">CurrentInstrSet</a>() == <a link="enum_InstrSet_A32" file="shared_pseudocode.xml">InstrSet_A32</a> then 4 else 2;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
        AArch32_EnterHypMode(except, preferred_exception_return, vect_offset);
    elsif route_to_hyp then
        AArch32_EnterHypMode(except, preferred_exception_return, 0x14);
    else
        AArch32_EnterMode(<a link="global_M32_Undef" file="shared_pseudocode.xml">M32_Undef</a>, preferred_exception_return, lr_offset, vect_offset);
    end;
end;

// AArch32_TakeUndefInstrException()
// =================================

noreturn func AArch32_TakeUndefInstrException()
begin
    let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_Uncategorized" file="shared_pseudocode.xml">Exception_Uncategorized</a>);
    AArch32_TakeUndefInstrException(except);
end;</pstext></ps>
    <ps name="aarch32/exceptions/traps/AArch32_Undefined" mylink="aarch32.exceptions.traps.AArch32_Undefined" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_Undefined()
// ===================

noreturn func AArch32_Undefined()
begin

    if <a link="func_AArch32_GeneralExceptionsToAArch64_0" file="shared_pseudocode.xml">AArch32_GeneralExceptionsToAArch64</a>() then AArch64_Undefined(); end;
    AArch32_TakeUndefInstrException();
end;</pstext></ps>
    <ps name="aarch32/functions/aborts/AArch32_DomainValid" mylink="aarch32.functions.aborts.AArch32_DomainValid" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_DomainValid()
// =====================
// Returns TRUE if the Domain is valid for a Short-descriptor translation scheme.

func <anchor link="func_AArch32_DomainValid_2">AArch32_DomainValid</anchor>(statuscode : <a link="type_Fault" file="shared_pseudocode.xml">Fault</a>, level : integer) =&gt; boolean
begin
    assert statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;

    case statuscode of
        when <a link="enum_Fault_Domain" file="shared_pseudocode.xml">Fault_Domain</a> =&gt;
            return TRUE;
        when <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>,<a link="enum_Fault_AccessFlag" file="shared_pseudocode.xml">Fault_AccessFlag</a>, <a link="enum_Fault_SyncExternalOnWalk" file="shared_pseudocode.xml">Fault_SyncExternalOnWalk</a>, <a link="enum_Fault_SyncParityOnWalk" file="shared_pseudocode.xml">Fault_SyncParityOnWalk</a> =&gt;
            return level == 2;
        otherwise =&gt;
            return FALSE;
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/aborts/AArch32_FaultSyndrome" mylink="aarch32.functions.aborts.AArch32_FaultSyndrome" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_FaultSyndrome()
// =======================
// Creates an exception syndrome value and updates the virtual address for Abort and Watchpoint
// exceptions taken to AArch32 Hyp mode.

func <anchor link="func_AArch32_FaultSyndrome_2">AArch32_FaultSyndrome</anchor>(exceptype : <a link="type_Exception" file="shared_pseudocode.xml">Exception</a>, fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; bits(25)
begin
    assert fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;

    var isstype : <a link="type_IssType" file="shared_pseudocode.xml">IssType</a>;
    isstype.iss  = Zeros{25};

    let d_side : boolean = exceptype == <a link="enum_Exception_DataAbort" file="shared_pseudocode.xml">Exception_DataAbort</a>;
    if IsFeatureImplemented(FEAT_RAS) &amp;&amp; <a link="func_IsAsyncAbort_1" file="shared_pseudocode.xml">IsAsyncAbort</a>(fault) then
        let errstate : <a link="type_ErrorState" file="shared_pseudocode.xml">ErrorState</a> = <a link="func_PEErrorState_1" file="shared_pseudocode.xml">PEErrorState</a>(fault);
        isstype.iss[11:10] = <a link="func_AArch32_EncodeAsyncErrorSyndrome_1" file="shared_pseudocode.xml">AArch32_EncodeAsyncErrorSyndrome</a>(errstate); // AET
    end;

    if d_side then

        if <a link="func_AArch32_InstructionSyndromeValid_1" file="shared_pseudocode.xml">AArch32_InstructionSyndromeValid</a>(fault) then
            isstype.iss[24:14] = <a link="func_LSInstructionSyndrome_0" file="shared_pseudocode.xml">LSInstructionSyndrome</a>();
        end;

        if fault.accessdesc.acctype IN {<a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>, <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>, <a link="enum_AccessType_AT" file="shared_pseudocode.xml">AccessType_AT</a>} then
            isstype.iss[8] = '1';
        end;

        if fault.accessdesc.acctype IN {<a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>, <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>, <a link="enum_AccessType_AT" file="shared_pseudocode.xml">AccessType_AT</a>} then
            isstype.iss[6] = '1';
        elsif fault.statuscode == <a link="enum_Fault_Exclusive" file="shared_pseudocode.xml">Fault_Exclusive</a> then
            isstype.iss[6] = ARBITRARY : bit;
        else
            isstype.iss[6] = if fault.write then '1' else '0';
        end;

    end;
    if <a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) then isstype.iss[9] = fault.extflag; end;
    isstype.iss[7] = if fault.s2fs1walk then '1' else '0';
    isstype.iss[5:0] = <a link="func_EncodeLDFSC_2" file="shared_pseudocode.xml">EncodeLDFSC</a>(fault.statuscode, fault.level);

    return isstype.iss;
end;</pstext></ps>
    <ps name="aarch32/functions/aborts/AArch32_InstructionSyndromeValid" mylink="aarch32.functions.aborts.AArch32_InstructionSyndromeValid" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_InstructionSyndromeValid()
// ==================================
// Returns TRUE if ESR_ELx.ISV is '1' for the given Fault.

func <anchor link="func_AArch32_InstructionSyndromeValid_1">AArch32_InstructionSyndromeValid</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; boolean
begin
    if <a link="func_IsSecondStage_1" file="shared_pseudocode.xml">IsSecondStage</a>(fault) &amp;&amp; !fault.s2fs1walk then
        return (!<a link="func_IsExternalSyncAbort_1" file="shared_pseudocode.xml">IsExternalSyncAbort</a>(fault) ||
               (!IsFeatureImplemented(FEAT_RAS) &amp;&amp; <a link="func_IsExternalAbortOnWalk_1" file="shared_pseudocode.xml">IsExternalAbortOnWalk</a>(fault) &amp;&amp;
                  ImpDefBool(&quot;ISV on second stage translation table walk&quot;)));
    end;

    return FALSE;
end;</pstext></ps>
    <ps name="aarch32/functions/aborts/EncodeSDFSC" mylink="aarch32.functions.aborts.EncodeSDFSC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EncodeSDFSC()
// =============
// Function that gives the Short-descriptor FSR code for different types of Fault

func <anchor link="func_EncodeSDFSC_2">EncodeSDFSC</anchor>(statuscode : <a link="type_Fault" file="shared_pseudocode.xml">Fault</a>, level : integer) =&gt; bits(5)
begin
    var result : bits(5);
    case statuscode of
        when <a link="enum_Fault_AccessFlag" file="shared_pseudocode.xml">Fault_AccessFlag</a> =&gt;
            assert level IN {1,2};
            result = if level == 1 then '00011' else '00110';
        when <a link="enum_Fault_Alignment" file="shared_pseudocode.xml">Fault_Alignment</a> =&gt;
            result = '00001';
        when <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a> =&gt;
            assert level IN {1,2};
            result = if level == 1 then '01101' else '01111';
        when <a link="enum_Fault_Domain" file="shared_pseudocode.xml">Fault_Domain</a> =&gt;
            assert level IN {1,2};
            result = if level == 1 then '01001' else '01011';
        when <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a> =&gt;
            assert level IN {1,2};
            result = if level == 1 then '00101' else '00111';
        when <a link="enum_Fault_SyncExternal" file="shared_pseudocode.xml">Fault_SyncExternal</a> =&gt;
            result = '01000';
        when <a link="enum_Fault_SyncExternalOnWalk" file="shared_pseudocode.xml">Fault_SyncExternalOnWalk</a> =&gt;
            assert level IN {1,2};
            result = if level == 1 then '01100' else '01110';
        when <a link="enum_Fault_SyncParity" file="shared_pseudocode.xml">Fault_SyncParity</a> =&gt;
            result = '11001';
        when <a link="enum_Fault_SyncParityOnWalk" file="shared_pseudocode.xml">Fault_SyncParityOnWalk</a> =&gt;
            assert level IN {1,2};
            result = if level == 1 then '11100' else '11110';
        when <a link="enum_Fault_AsyncParity" file="shared_pseudocode.xml">Fault_AsyncParity</a> =&gt;
            result = '11000';
        when <a link="enum_Fault_AsyncExternal" file="shared_pseudocode.xml">Fault_AsyncExternal</a> =&gt;
            result = '10110';
        when <a link="enum_Fault_Debug" file="shared_pseudocode.xml">Fault_Debug</a> =&gt;
            result = '00010';
        when <a link="enum_Fault_TLBConflict" file="shared_pseudocode.xml">Fault_TLBConflict</a> =&gt;
            result = '10000';
        when <a link="enum_Fault_Lockdown" file="shared_pseudocode.xml">Fault_Lockdown</a> =&gt;
            result = '10100';   // IMPLEMENTATION DEFINED
        when <a link="enum_Fault_Exclusive" file="shared_pseudocode.xml">Fault_Exclusive</a> =&gt;
            result = '10101';   // IMPLEMENTATION DEFINED
        when <a link="enum_Fault_ICacheMaint" file="shared_pseudocode.xml">Fault_ICacheMaint</a> =&gt;
            result = '00100';
        otherwise =&gt;
            unreachable;
    end;

    return result;
end;</pstext></ps>
    <ps name="aarch32/functions/common/A32ExpandImm" mylink="aarch32.functions.common.A32ExpandImm" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// A32ExpandImm()
// ==============

func <anchor link="func_A32ExpandImm_1">A32ExpandImm</anchor>(imm12 : bits(12)) =&gt; bits(32)
begin
    // PSTATE.C argument to following function call does not affect the imm32 result.
    let (imm32, -) = <a link="func_A32ExpandImm_C_2" file="shared_pseudocode.xml">A32ExpandImm_C</a>(imm12, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.C);

    return imm32;
end;</pstext></ps>
    <ps name="aarch32/functions/common/A32ExpandImm_C" mylink="aarch32.functions.common.A32ExpandImm_C" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// A32ExpandImm_C()
// ================

func <anchor link="func_A32ExpandImm_C_2">A32ExpandImm_C</anchor>(imm12 : bits(12), carry_in : bit) =&gt; (bits(32), bit)
begin
    let unrotated_value : bits(32) = ZeroExtend{}(imm12[7:0]);
    let (imm32, carry_out) : (bits(32), bit) = <a link="func_Shift_C_5" file="shared_pseudocode.xml">Shift_C</a>{32}(unrotated_value, <a link="enum_SRType_ROR" file="shared_pseudocode.xml">SRType_ROR</a>,
                                                           2*UInt(imm12[11:8]), carry_in);

    return (imm32, carry_out);
end;</pstext></ps>
    <ps name="aarch32/functions/common/DecodeImmShift" mylink="aarch32.functions.common.DecodeImmShift" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodeImmShift()
// ================

func <anchor link="func_DecodeImmShift_2">DecodeImmShift</anchor>(srtype : bits(2), imm5 : bits(5)) =&gt; (<a link="type_SRType" file="shared_pseudocode.xml">SRType</a>, integer{0..32})
begin
    var shift_t : <a link="type_SRType" file="shared_pseudocode.xml">SRType</a>;
    var shift_n : integer{0..32};
    case srtype of
        when '00' =&gt;
            shift_t = <a link="enum_SRType_LSL" file="shared_pseudocode.xml">SRType_LSL</a>;  shift_n = UInt(imm5);
        when '01' =&gt;
            shift_t = <a link="enum_SRType_LSR" file="shared_pseudocode.xml">SRType_LSR</a>;  shift_n = if imm5 == '00000' then 32 else UInt(imm5);
        when '10' =&gt;
            shift_t = <a link="enum_SRType_ASR" file="shared_pseudocode.xml">SRType_ASR</a>;  shift_n = if imm5 == '00000' then 32 else UInt(imm5);
        when '11' =&gt;
            if imm5 == '00000' then
                shift_t = <a link="enum_SRType_RRX" file="shared_pseudocode.xml">SRType_RRX</a>;  shift_n = 1;
            else
                shift_t = <a link="enum_SRType_ROR" file="shared_pseudocode.xml">SRType_ROR</a>;  shift_n = UInt(imm5);
            end;
    end;

    return (shift_t, shift_n);
end;</pstext></ps>
    <ps name="aarch32/functions/common/DecodeRegShift" mylink="aarch32.functions.common.DecodeRegShift" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodeRegShift()
// ================

func <anchor link="func_DecodeRegShift_1">DecodeRegShift</anchor>(srtype : bits(2)) =&gt; <a link="type_SRType" file="shared_pseudocode.xml">SRType</a>
begin
    var shift_t : <a link="type_SRType" file="shared_pseudocode.xml">SRType</a>;
    case srtype of
        when '00' =&gt;  shift_t = <a link="enum_SRType_LSL" file="shared_pseudocode.xml">SRType_LSL</a>;
        when '01' =&gt;  shift_t = <a link="enum_SRType_LSR" file="shared_pseudocode.xml">SRType_LSR</a>;
        when '10' =&gt;  shift_t = <a link="enum_SRType_ASR" file="shared_pseudocode.xml">SRType_ASR</a>;
        when '11' =&gt;  shift_t = <a link="enum_SRType_ROR" file="shared_pseudocode.xml">SRType_ROR</a>;
    end;
    return shift_t;
end;</pstext></ps>
    <ps name="aarch32/functions/common/RRX" mylink="aarch32.functions.common.RRX" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// RRX()
// =====

func <anchor link="func_RRX_3">RRX</anchor>{N}(x : bits(N), carry_in : bit) =&gt; bits(N)
begin
    let (result, -) = <a link="func_RRX_C_3" file="shared_pseudocode.xml">RRX_C</a>{N}(x, carry_in);
    return result;
end;</pstext></ps>
    <ps name="aarch32/functions/common/RRX_C" mylink="aarch32.functions.common.RRX_C" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// RRX_C()
// =======

func <anchor link="func_RRX_C_3">RRX_C</anchor>{N}(x : bits(N), carry_in : bit) =&gt; (bits(N), bit)
begin
    let result : bits(N) = carry_in :: x[N-1:1];
    let carry_out : bit = x[0];
    return (result, carry_out);
end;</pstext></ps>
    <ps name="aarch32/functions/common/SRType" mylink="aarch32.functions.common.SRType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SRType
// ======

type <anchor link="type_SRType">SRType</anchor> of enumeration {<anchor link="enum_SRType_LSL">SRType_LSL</anchor>, <anchor link="enum_SRType_LSR">SRType_LSR</anchor>, <anchor link="enum_SRType_ASR">SRType_ASR</anchor>, <anchor link="enum_SRType_ROR">SRType_ROR</anchor>, <anchor link="enum_SRType_RRX">SRType_RRX</anchor>};</pstext></ps>
    <ps name="aarch32/functions/common/Shift" mylink="aarch32.functions.common.Shift" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Shift()
// =======

func <anchor link="func_Shift_5">Shift</anchor>{N}(value : bits(N), srtype : <a link="type_SRType" file="shared_pseudocode.xml">SRType</a>, amount : integer, carry_in : bit) =&gt; bits(N)
begin
    let (result, -) = <a link="func_Shift_C_5" file="shared_pseudocode.xml">Shift_C</a>{N}(value, srtype, amount, carry_in);
    return result;
end;</pstext></ps>
    <ps name="aarch32/functions/common/Shift_C" mylink="aarch32.functions.common.Shift_C" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Shift_C()
// =========

func <anchor link="func_Shift_C_5">Shift_C</anchor>{N}(value : bits(N), srtype : <a link="type_SRType" file="shared_pseudocode.xml">SRType</a>, amount : integer,
                carry_in : bit) =&gt; (bits(N), bit)
begin
    assert !(srtype == <a link="enum_SRType_RRX" file="shared_pseudocode.xml">SRType_RRX</a> &amp;&amp; amount != 1);

    var result : bits(N);
    var carry_out : bit;
    if amount == 0 then
        (result, carry_out) = (value, carry_in);
    else
        case srtype of
            when <a link="enum_SRType_LSL" file="shared_pseudocode.xml">SRType_LSL</a> =&gt;
                (result, carry_out) = LSL_C(value, amount);
            when <a link="enum_SRType_LSR" file="shared_pseudocode.xml">SRType_LSR</a> =&gt;
                (result, carry_out) = LSR_C(value, amount);
            when <a link="enum_SRType_ASR" file="shared_pseudocode.xml">SRType_ASR</a> =&gt;
                (result, carry_out) = ASR_C(value, amount);
            when <a link="enum_SRType_ROR" file="shared_pseudocode.xml">SRType_ROR</a> =&gt;
                (result, carry_out) = ROR_C(value, amount);
            when <a link="enum_SRType_RRX" file="shared_pseudocode.xml">SRType_RRX</a> =&gt;
                (result, carry_out) = <a link="func_RRX_C_3" file="shared_pseudocode.xml">RRX_C</a>{N}(value, carry_in);
        end;
    end;

    return (result, carry_out);
end;</pstext></ps>
    <ps name="aarch32/functions/common/T32ExpandImm" mylink="aarch32.functions.common.T32ExpandImm" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// T32ExpandImm()
// ==============

func <anchor link="func_T32ExpandImm_1">T32ExpandImm</anchor>(imm12 : bits(12)) =&gt; bits(32)
begin
    // PSTATE.C argument to following function call does not affect the imm32 result.
    let (imm32, -) = <a link="func_T32ExpandImm_C_2" file="shared_pseudocode.xml">T32ExpandImm_C</a>(imm12, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.C);

    return imm32;
end;</pstext></ps>
    <ps name="aarch32/functions/common/T32ExpandImm_C" mylink="aarch32.functions.common.T32ExpandImm_C" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// T32ExpandImm_C()
// ================

func <anchor link="func_T32ExpandImm_C_2">T32ExpandImm_C</anchor>(imm12 : bits(12), carry_in : bit) =&gt; (bits(32), bit)
begin
    var imm32 : bits(32);
    var carry_out : bit;
    if imm12[11:10] == '00' then
        case imm12[9:8] of
            when '00' =&gt;
                imm32 = ZeroExtend{32}(imm12[7:0]);
            when '01' =&gt;
                imm32 = '00000000' :: imm12[7:0] :: '00000000' :: imm12[7:0];
            when '10' =&gt;
                imm32 = imm12[7:0] :: '00000000' :: imm12[7:0] :: '00000000';
            when '11' =&gt;
                imm32 = imm12[7:0] :: imm12[7:0] :: imm12[7:0] :: imm12[7:0];
        end;
        carry_out = carry_in;
    else
        let unrotated_value : bits(32) = ZeroExtend{}('1'::imm12[6:0]);
        (imm32, carry_out) = ROR_C(unrotated_value, UInt(imm12[11:7]));
    end;

    return (imm32, carry_out);
end;</pstext></ps>
    <ps name="aarch32/functions/common/VBitOps" mylink="aarch32.functions.common.VBitOps" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// VBitOps
// =======

type <anchor link="type_VBitOps">VBitOps</anchor> of enumeration {<anchor link="enum_VBitOps_VBIF">VBitOps_VBIF</anchor>, <anchor link="enum_VBitOps_VBIT">VBitOps_VBIT</anchor>, <anchor link="enum_VBitOps_VBSL">VBitOps_VBSL</anchor>};</pstext></ps>
    <ps name="aarch32/functions/common/VCGEType" mylink="aarch32.functions.common.VCGEType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// VCGEType
// ========

type <anchor link="type_VCGEType">VCGEType</anchor> of enumeration {<anchor link="enum_VCGEType_signed">VCGEType_signed</anchor>, <anchor link="enum_VCGEType_unsigned">VCGEType_unsigned</anchor>, <anchor link="enum_VCGEType_fp">VCGEType_fp</anchor>};</pstext></ps>
    <ps name="aarch32/functions/common/VCGTtype" mylink="aarch32.functions.common.VCGTtype" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// VCGTtype
// ========

type <anchor link="type_VCGTtype">VCGTtype</anchor> of enumeration {<anchor link="enum_VCGTtype_signed">VCGTtype_signed</anchor>, <anchor link="enum_VCGTtype_unsigned">VCGTtype_unsigned</anchor>, <anchor link="enum_VCGTtype_fp">VCGTtype_fp</anchor>};</pstext></ps>
    <ps name="aarch32/functions/common/VFPNegMul" mylink="aarch32.functions.common.VFPNegMul" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// VFPNegMul
// =========

type <anchor link="type_VFPNegMul">VFPNegMul</anchor> of enumeration {<anchor link="enum_VFPNegMul_VNMLA">VFPNegMul_VNMLA</anchor>, <anchor link="enum_VFPNegMul_VNMLS">VFPNegMul_VNMLS</anchor>, <anchor link="enum_VFPNegMul_VNMUL">VFPNegMul_VNMUL</anchor>};</pstext></ps>
    <ps name="aarch32/functions/coproc/AArch32_CheckCP15InstrCoarseTraps" mylink="aarch32.functions.coproc.AArch32_CheckCP15InstrCoarseTraps" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CheckCP15InstrCoarseTraps()
// ===================================
// Check for coarse-grained traps to System registers in the
// coproc=0b1111 encoding space by HSTR and HCR.

func <anchor link="func_AArch32_CheckCP15InstrCoarseTraps_3">AArch32_CheckCP15InstrCoarseTraps</anchor>(CRn : integer, nreg : integer, CRm : integer)
begin
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; (!<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) ||
            (<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>))) then
        <a link="func_AArch64_CheckCP15InstrCoarseTraps_3" file="shared_pseudocode.xml">AArch64_CheckCP15InstrCoarseTraps</a>(CRn, nreg, CRm);
    end;

    let trapped_encoding = ((CRn == 9  &amp;&amp; CRm IN {0,1,2,    5,6,7,8   }) ||
                            (CRn == 10 &amp;&amp; CRm IN {0,1,    4,      8   }) ||
                            (CRn == 11 &amp;&amp; CRm IN {0,1,2,3,4,5,6,7,8,15}));

    // Check for coarse-grained Hyp traps
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        let major : integer = if nreg == 1 then CRn else CRm;
        // Check for MCR, MRC, MCRR, and MRRC disabled by HSTR().CRn/HSTR().CRm
        // and MRC and MCR disabled by HCR.TIDCP.
        if ((! major IN {4,14} &amp;&amp; HSTR()[major] == '1') ||
              (HCR().TIDCP == '1' &amp;&amp; nreg == 1 &amp;&amp; trapped_encoding)) then
            if (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp;
                  ImpDefBool(&quot;UNDEF unallocated CP15 access at EL0&quot;)) then
                Undefined();
            end;
            if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
                <a link="func_AArch32_SystemAccessTrap_2" file="shared_pseudocode.xml">AArch32_SystemAccessTrap</a>(<a link="global_M32_Hyp" file="shared_pseudocode.xml">M32_Hyp</a>, 0x3);
            else
                <a link="func_AArch64_AArch32SystemAccessTrap_2" file="shared_pseudocode.xml">AArch64_AArch32SystemAccessTrap</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, 0x3);
            end;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/exclusive/AArch32_ExclusiveMonitorsPass" mylink="aarch32.functions.exclusive.AArch32_ExclusiveMonitorsPass" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ExclusiveMonitorsPass()
// ===============================
// Return TRUE if the Exclusives monitors for the current PE include all of the addresses
// associated with the virtual address region of size bytes starting at address.
// The immediately following memory write must be to the same addresses.

// It is IMPLEMENTATION DEFINED whether the detection of memory aborts happens
// before or after the check on the local Exclusives monitor. As a result a failure
// of the local monitor can occur on some implementations even if the memory
// access would give a memory abort.


func <anchor link="func_AArch32_ExclusiveMonitorsPass_2">AArch32_ExclusiveMonitorsPass</anchor>(address : bits(32),
                                   size : integer{1, 2, 4, 8, 16, 32}) =&gt; boolean
begin
    let acqrel : boolean = FALSE;
    let privileged : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
    let tagchecked : boolean = FALSE;
    let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescExLDST_4" file="shared_pseudocode.xml">CreateAccDescExLDST</a>(<a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>, acqrel,
                                                            tagchecked, privileged);
    let aligned : boolean = IsAlignedSize(address, size);

    if !aligned then
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AlignmentFault_2" file="shared_pseudocode.xml">AlignmentFault</a>(accdesc, ZeroExtend{64}(address));
        <a link="func_AArch32_Abort_1" file="shared_pseudocode.xml">AArch32_Abort</a>(fault);
    end;

    if !<a link="func_AArch32_IsExclusiveVA_3" file="shared_pseudocode.xml">AArch32_IsExclusiveVA</a>(address, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), size) then
        return FALSE;
    end;

    let memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_AArch32_TranslateAddress_4" file="shared_pseudocode.xml">AArch32_TranslateAddress</a>(address, accdesc, aligned, size);

    // Check for aborts or debug exceptions
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        <a link="func_AArch32_Abort_1" file="shared_pseudocode.xml">AArch32_Abort</a>(memaddrdesc.fault);
    end;

    var passed : boolean = <a link="func_IsExclusiveLocal_3" file="shared_pseudocode.xml">IsExclusiveLocal</a>(memaddrdesc.paddress, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), size);
    ClearExclusiveLocal(<a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>());

    if passed &amp;&amp; memaddrdesc.memattrs.shareability != <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a> then
        passed = <a link="func_IsExclusiveGlobal_3" file="shared_pseudocode.xml">IsExclusiveGlobal</a>(memaddrdesc.paddress, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), size);
    end;

    return passed;
end;</pstext></ps>
    <ps name="aarch32/functions/exclusive/AArch32_IsExclusiveVA" mylink="aarch32.functions.exclusive.AArch32_IsExclusiveVA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_IsExclusiveVA()
// =======================
// An optional IMPLEMENTATION DEFINED test for an exclusive access to a virtual
// address region of size bytes starting at address.
//
// It is permitted (but not required) for this function to return FALSE and
// cause a store exclusive to fail if the virtual address region is not
// totally included within the region recorded by MarkExclusiveVA().
//
// It is always safe to return TRUE which will check the physical address only.

impdef func <anchor link="func_AArch32_IsExclusiveVA_3">AArch32_IsExclusiveVA</anchor>(address : bits(32),
                                  processorid : integer,
                                  size : integer) =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="aarch32/functions/exclusive/AArch32_MarkExclusiveVA" mylink="aarch32.functions.exclusive.AArch32_MarkExclusiveVA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_MarkExclusiveVA()
// =========================
// Optionally record an exclusive access to the virtual address region of size bytes
// starting at address for processorid.

func <anchor link="func_AArch32_MarkExclusiveVA_3">AArch32_MarkExclusiveVA</anchor>(address : bits(32), processorid : integer, size : integer)
begin
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/exclusive/AArch32_SetExclusiveMonitors" mylink="aarch32.functions.exclusive.AArch32_SetExclusiveMonitors" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_SetExclusiveMonitors()
// ==============================
// Sets the Exclusives monitors for the current PE to record the addresses associated
// with the virtual address region of size bytes starting at address.

func <anchor link="func_AArch32_SetExclusiveMonitors_2">AArch32_SetExclusiveMonitors</anchor>(address : bits(32), size : integer{1, 2, 4, 8, 16, 32})
begin
    let acqrel : boolean = FALSE;
    let privileged : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
    let tagchecked : boolean = FALSE;
    let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescExLDST_4" file="shared_pseudocode.xml">CreateAccDescExLDST</a>(<a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>, acqrel,
                                                            tagchecked, privileged);
    let aligned : boolean = IsAlignedSize(address, size);

    if !aligned then
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AlignmentFault_2" file="shared_pseudocode.xml">AlignmentFault</a>(accdesc, ZeroExtend{64}(address));
        <a link="func_AArch32_Abort_1" file="shared_pseudocode.xml">AArch32_Abort</a>(fault);
    end;

    let memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_AArch32_TranslateAddress_4" file="shared_pseudocode.xml">AArch32_TranslateAddress</a>(address, accdesc, aligned, size);

    // Check for aborts or debug exceptions
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        return;
    end;

    if memaddrdesc.memattrs.shareability != <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a> then
        MarkExclusiveGlobal(memaddrdesc.paddress, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), size);
    end;

    MarkExclusiveLocal(memaddrdesc.paddress, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), size);

    <a link="func_AArch32_MarkExclusiveVA_3" file="shared_pseudocode.xml">AArch32_MarkExclusiveVA</a>(address, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), size);
end;</pstext></ps>
    <ps name="aarch32/functions/float/CheckAdvSIMDEnabled" mylink="aarch32.functions.float.CheckAdvSIMDEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckAdvSIMDEnabled()
// =====================

func <anchor link="func_CheckAdvSIMDEnabled_0">CheckAdvSIMDEnabled</anchor>()
begin
    let fpexc_check : boolean = TRUE;
    let advsimd : boolean = TRUE;

    <a link="func_AArch32_CheckAdvSIMDOrFPEnabled_2" file="shared_pseudocode.xml">AArch32_CheckAdvSIMDOrFPEnabled</a>(fpexc_check, advsimd);
    // Return from CheckAdvSIMDOrFPEnabled() occurs only if Advanced SIMD access is permitted

    // Make temporary copy of D registers
    // _Dclone[] is used as input data for instruction pseudocode
    for i = 0 to 31 do
        <a link="global__Dclone" file="shared_pseudocode.xml">_Dclone</a>[[i]] = <a link="accessor_D_1" file="shared_pseudocode.xml">D</a>(i);
    end;

    return;
end;</pstext></ps>
    <ps name="aarch32/functions/float/CheckAdvSIMDOrVFPEnabled" mylink="aarch32.functions.float.CheckAdvSIMDOrVFPEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckAdvSIMDOrVFPEnabled()
// ==========================

func <anchor link="func_CheckAdvSIMDOrVFPEnabled_2">CheckAdvSIMDOrVFPEnabled</anchor>(include_fpexc_check : boolean, advsimd : boolean)
begin
    <a link="func_AArch32_CheckAdvSIMDOrFPEnabled_2" file="shared_pseudocode.xml">AArch32_CheckAdvSIMDOrFPEnabled</a>(include_fpexc_check, advsimd);
    // Return from CheckAdvSIMDOrFPEnabled() occurs only if VFP access is permitted
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/float/CheckCryptoEnabled32" mylink="aarch32.functions.float.CheckCryptoEnabled32" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckCryptoEnabled32()
// ======================

func <anchor link="func_CheckCryptoEnabled32_0">CheckCryptoEnabled32</anchor>()
begin
    <a link="func_CheckAdvSIMDEnabled_0" file="shared_pseudocode.xml">CheckAdvSIMDEnabled</a>();
    // Return from CheckAdvSIMDEnabled() occurs only if access is permitted
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/float/CheckVFPEnabled" mylink="aarch32.functions.float.CheckVFPEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckVFPEnabled()
// =================

func <anchor link="func_CheckVFPEnabled_1">CheckVFPEnabled</anchor>(include_fpexc_check : boolean)
begin
    let advsimd : boolean = FALSE;
    <a link="func_AArch32_CheckAdvSIMDOrFPEnabled_2" file="shared_pseudocode.xml">AArch32_CheckAdvSIMDOrFPEnabled</a>(include_fpexc_check, advsimd);
    // Return from CheckAdvSIMDOrFPEnabled() occurs only if VFP access is permitted
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/float/FPHalvedSub" mylink="aarch32.functions.float.FPHalvedSub" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPHalvedSub()
// =============

func <anchor link="func_FPHalvedSub_4">FPHalvedSub</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    let rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a> = <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr);
    let (type1,sign1,value1) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr);
    let (type2,sign2,value2) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr);
    var (done,result) : (boolean, bits(N)) = <a link="func_FPProcessNaNs_6" file="shared_pseudocode.xml">FPProcessNaNs</a>{N}(type1, type2, op1, op2, fpcr);
    if !done then
        let inf1 : boolean  = (type1 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let inf2 : boolean  = (type2 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let zero1 : boolean = (type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        let zero2 : boolean = (type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        if inf1 &amp;&amp; inf2 &amp;&amp; sign1 == sign2 then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{N}(fpcr);
            <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
        elsif (inf1 &amp;&amp; sign1 == '0') || (inf2 &amp;&amp; sign2 == '1') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}('0');
        elsif (inf1 &amp;&amp; sign1 == '1') || (inf2 &amp;&amp; sign2 == '0') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}('1');
        elsif zero1 &amp;&amp; zero2 &amp;&amp; sign1 != sign2 then
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign1);
        else
            let result_value : real = (value1 - value2) / 2.0;
            if result_value == 0.0 then  // Sign of exact zero result depends on rounding mode
                let result_sign : bit = if rounding == <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a> then '1' else '0';
                result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(result_sign);
            else
                result = <a link="func_FPRound_3" file="shared_pseudocode.xml">FPRound</a>{N}(result_value, fpcr);
            end;
        end;
    end;
    return result;
end;</pstext></ps>
    <ps name="aarch32/functions/float/FPRSqrtStep" mylink="aarch32.functions.float.FPRSqrtStep" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPRSqrtStep()
// =============

func <anchor link="func_FPRSqrtStep_3">FPRSqrtStep</anchor>{N}(op1 : bits(N), op2 : bits(N)) =&gt; bits(N)
begin
    assert N IN {16,32};
    let fpcr : FPCR_Type = <a link="func_StandardFPCR_0" file="shared_pseudocode.xml">StandardFPCR</a>();
    let (type1,sign1,value1) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr);
    let (type2,sign2,value2) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr);
    var (done,result) : (boolean, bits(N)) = <a link="func_FPProcessNaNs_6" file="shared_pseudocode.xml">FPProcessNaNs</a>{N}(type1, type2, op1, op2, fpcr);
    if !done then
        let inf1 : boolean  = (type1 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let inf2 : boolean  = (type2 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let zero1 : boolean = (type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        let zero2 : boolean = (type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        var product : bits(N);
        if (inf1 &amp;&amp; zero2) || (zero1 &amp;&amp; inf2) then
            product = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}('0');
        else
            product = <a link="func_FPMul_4" file="shared_pseudocode.xml">FPMul</a>{N}(op1, op2, fpcr);
        end;
        let three : bits(N) = FPThree{}('0');
        result = <a link="func_FPHalvedSub_4" file="shared_pseudocode.xml">FPHalvedSub</a>{N}(three, product, fpcr);
    end;
    return result;
end;</pstext></ps>
    <ps name="aarch32/functions/float/FPRecipStep" mylink="aarch32.functions.float.FPRecipStep" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPRecipStep()
// =============

func <anchor link="func_FPRecipStep_3">FPRecipStep</anchor>{N}(op1 : bits(N), op2 : bits(N)) =&gt; bits(N)
begin
    assert N IN {16,32};
    let fpcr : FPCR_Type = <a link="func_StandardFPCR_0" file="shared_pseudocode.xml">StandardFPCR</a>();
    let (type1,sign1,value1) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr);
    let (type2,sign2,value2) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr);
    var (done,result) : (boolean, bits(N)) = <a link="func_FPProcessNaNs_6" file="shared_pseudocode.xml">FPProcessNaNs</a>{N}(type1, type2, op1, op2, fpcr);
    if !done then
        let inf1 : boolean  = (type1 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let inf2 : boolean  = (type2 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let zero1 : boolean = (type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        let zero2 : boolean = (type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        var product : bits(N);
        if (inf1 &amp;&amp; zero2) || (zero1 &amp;&amp; inf2) then
            product = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}('0');
        else
            product = <a link="func_FPMul_4" file="shared_pseudocode.xml">FPMul</a>{N}(op1, op2, fpcr);
        end;
        let two : bits(N) = FPTwo{}('0');
        result = <a link="func_FPSub_4" file="shared_pseudocode.xml">FPSub</a>{N}(two, product, fpcr);
    end;
    return result;
end;</pstext></ps>
    <ps name="aarch32/functions/float/StandardFPCR" mylink="aarch32.functions.float.StandardFPCR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// StandardFPCR()
// ==============

func <anchor link="func_StandardFPCR_0">StandardFPCR</anchor>() =&gt; FPCR_Type
begin
    let value : bits(32) = ('00000' :: FPSCR().AHP :: '110000' ::
                            FPSCR().FZ16 :: '0000000000000000000');
    return ZeroExtend{64}(value);
end;</pstext></ps>
    <ps name="aarch32/functions/memory/AArch32_MemSingle" mylink="aarch32.functions.memory.AArch32_MemSingle" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_MemSingle
// =================

accessor <anchor link="accessor_AArch32_MemSingle_4">AArch32_MemSingle</anchor>{size : integer{8, 16, 32, 64}}(address : bits(32),
                                                          accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                                                          aligned : boolean) &lt;=&gt; value : bits(size)
begin
    // Perform an atomic, little-endian read of 'size' bits.
    getter
        let bytes : integer{} = size DIV 8;
        var value : bits(size);
        var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
        var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;

        (value, memaddrdesc, memstatus) = <a link="func_AArch32_MemSingleRead_4" file="shared_pseudocode.xml">AArch32_MemSingleRead</a>{size}(address, accdesc, aligned);

        // Check for a fault from translation or the output of translation.
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
            <a link="func_AArch32_Abort_1" file="shared_pseudocode.xml">AArch32_Abort</a>(memaddrdesc.fault);
        end;

        // Check for external aborts.
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            <a link="func_HandleExternalAbort_5" file="shared_pseudocode.xml">HandleExternalAbort</a>(memstatus, accdesc.write, memaddrdesc, bytes, accdesc);
        end;

        return value;
    end;

    // Perform an atomic, little-endian write of 'size' bits.
    setter
        let bytes : integer{} = size DIV 8;
        var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
        var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;

        (memaddrdesc, memstatus) = <a link="func_AArch32_MemSingleWrite_5" file="shared_pseudocode.xml">AArch32_MemSingleWrite</a>{size}(address, accdesc, aligned, value);

        // Check for a fault from translation or the output of translation.
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
            <a link="func_AArch32_Abort_1" file="shared_pseudocode.xml">AArch32_Abort</a>(memaddrdesc.fault);
        end;

        // Check for external aborts.
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            <a link="func_HandleExternalWriteAbort_4" file="shared_pseudocode.xml">HandleExternalWriteAbort</a>(memstatus, memaddrdesc, bytes, accdesc);
        end;

        return;
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/memory/AArch32_MemSingleRead" mylink="aarch32.functions.memory.AArch32_MemSingleRead" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_MemSingleRead()
// =======================
// Perform an atomic, little-endian read of 'size' bits.

func <anchor link="func_AArch32_MemSingleRead_4">AArch32_MemSingleRead</anchor>{size : integer{8, 16, 32, 64}}(address : bits(32),
                                                          accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                                                          aligned : boolean
                                                          ) =&gt; (bits(size), <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                                                                <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>)
begin
    let bytes : integer{}            = size DIV 8;
    var value : bits(size)           = ARBITRARY : bits(size);
    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a> = ARBITRARY : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = accdesc_in;
    assert IsAlignedSize(address, bytes);

    var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    memaddrdesc = <a link="func_AArch32_TranslateAddress_4" file="shared_pseudocode.xml">AArch32_TranslateAddress</a>(address, accdesc, aligned, bytes);

    // Check for aborts or debug exceptions
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        return (value, memaddrdesc, memstatus);
    end;

    // Memory array access
    (memstatus, value) = <a link="func_PhysMemRead_3" file="shared_pseudocode.xml">PhysMemRead</a>{size}(memaddrdesc, accdesc);
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
        return (value, memaddrdesc, memstatus);
    end;

    if accdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> then
        if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>()) then
            memaddrdesc.fault = <a link="func_AArch32_CheckDebug_3" file="shared_pseudocode.xml">AArch32_CheckDebug</a>(address, accdesc, bytes);
        else
            memaddrdesc.fault = <a link="func_AArch64_CheckDebug_3" file="shared_pseudocode.xml">AArch64_CheckDebug</a>(ZeroExtend{64}(address), accdesc, bytes);
        end;
    end;

    return (value, memaddrdesc, memstatus);
end;</pstext></ps>
    <ps name="aarch32/functions/memory/AArch32_MemSingleWrite" mylink="aarch32.functions.memory.AArch32_MemSingleWrite" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_MemSingleWrite()
// ========================
// Perform an atomic, little-endian write of 'size' bits.

func <anchor link="func_AArch32_MemSingleWrite_5">AArch32_MemSingleWrite</anchor>{size : integer{8, 16, 32, 64}}(address : bits(32),
                                                           accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                                                           aligned : boolean,
                                                           value : bits(size)
                                                          ) =&gt; (<a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>)
begin
    let bytes : integer{} = size DIV 8;
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = accdesc_in;
    assert IsAlignedSize(address, bytes);

    var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a> = ARBITRARY : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
    memaddrdesc = <a link="func_AArch32_TranslateAddress_4" file="shared_pseudocode.xml">AArch32_TranslateAddress</a>(address, accdesc, aligned, bytes);

    // Check for aborts or debug exceptions
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        return (memaddrdesc, memstatus);
    end;

    // Effect on exclusives
    if memaddrdesc.memattrs.shareability != <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a> then
        ClearExclusiveByAddress(memaddrdesc.paddress, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), bytes);
    end;

    memstatus = <a link="func_PhysMemWrite_4" file="shared_pseudocode.xml">PhysMemWrite</a>{size}(memaddrdesc, accdesc, value);
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
        return (memaddrdesc, memstatus);
    end;

    return (memaddrdesc, memstatus);
end;</pstext></ps>
    <ps name="aarch32/functions/memory/AArch32_UnalignedAccessFaults" mylink="aarch32.functions.memory.AArch32_UnalignedAccessFaults" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_UnalignedAccessFaults()
// ===============================
// Determine whether the unaligned access generates an Alignment fault

func <anchor link="func_AArch32_UnalignedAccessFaults_1">AArch32_UnalignedAccessFaults</anchor>(accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; boolean
begin
    return (<a link="func_AlignmentEnforced_0" file="shared_pseudocode.xml">AlignmentEnforced</a>() ||
            accdesc.a32lsmd     ||
            accdesc.exclusive   ||
            accdesc.acqsc       ||
            accdesc.relsc);
end;</pstext></ps>
    <ps name="aarch32/functions/memory/Hint_PreloadData" mylink="aarch32.functions.memory.Hint_PreloadData" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Hint_PreloadData()
// ==================
// Perform a preload data hint.

impdef func Hint_PreloadData(address : bits(32))
begin
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/memory/Hint_PreloadDataForWrite" mylink="aarch32.functions.memory.Hint_PreloadDataForWrite" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Hint_PreloadDataForWrite()
// ==========================
// Perform a preload data hint with a probability that the use will be for a write.

impdef func Hint_PreloadDataForWrite(address : bits(32))
begin
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/memory/Hint_PreloadInstr" mylink="aarch32.functions.memory.Hint_PreloadInstr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Hint_PreloadInstr()
// ===================
// Perform a preload instruction hint.

impdef func Hint_PreloadInstr(address : bits(32))
begin
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/memory/MemA" mylink="aarch32.functions.memory.MemA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemA - accessor
// ===============

accessor <anchor link="accessor_MemA_2">MemA</anchor>{size : integer{8, 16, 32, 64}}(address : bits(32)) &lt;=&gt; value : bits(size)
begin
    getter
        let acqrel : boolean = FALSE;
        let privileged : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
        let tagchecked : boolean = FALSE;
        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescExLDST_4" file="shared_pseudocode.xml">CreateAccDescExLDST</a>(<a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>, acqrel, tagchecked,
                                                                privileged);
        return <a link="accessor_Mem_with_type_3" file="shared_pseudocode.xml">Mem_with_type</a>{size}(address, accdesc);
    end;

    setter
        let acqrel : boolean = FALSE;
        let privileged : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
        let tagchecked : boolean = FALSE;
        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescExLDST_4" file="shared_pseudocode.xml">CreateAccDescExLDST</a>(<a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>, acqrel, tagchecked,
                                                                privileged);
        <a link="accessor_Mem_with_type_3" file="shared_pseudocode.xml">Mem_with_type</a>{size}(address, accdesc) = value;
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/memory/MemO" mylink="aarch32.functions.memory.MemO" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemO
// ====

accessor <anchor link="accessor_MemO_2">MemO</anchor>{size : integer{8, 16, 32, 64} }(address : bits(32)) &lt;=&gt; value : bits(size)
begin
    getter
        let acquire : boolean = TRUE;
        let tagchecked : boolean = FALSE;
        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescAcqRel_3" file="shared_pseudocode.xml">CreateAccDescAcqRel</a>(<a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>, tagchecked, acquire);
        return <a link="accessor_Mem_with_type_3" file="shared_pseudocode.xml">Mem_with_type</a>{size}(address, accdesc);
    end;

    setter
        let acquire : boolean = FALSE;
        let tagchecked : boolean = FALSE;
        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescAcqRel_3" file="shared_pseudocode.xml">CreateAccDescAcqRel</a>(<a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>, tagchecked, acquire);
        <a link="accessor_Mem_with_type_3" file="shared_pseudocode.xml">Mem_with_type</a>{size}(address, accdesc) = value;
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/memory/MemS" mylink="aarch32.functions.memory.MemS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemS - accessor
// ===============

accessor <anchor link="accessor_MemS_2">MemS</anchor>{size : integer{8, 16, 32, 64}}(address : bits(32)) &lt;=&gt; value : bits(size)
begin
    // Memory accessor for streaming load multiple instructions
    getter
        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescA32LSMD_1" file="shared_pseudocode.xml">CreateAccDescA32LSMD</a>(<a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>);
        return <a link="accessor_Mem_with_type_3" file="shared_pseudocode.xml">Mem_with_type</a>{size}(address, accdesc);
    end;

    // Memory accessor for streaming store multiple instructions
    setter
        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescA32LSMD_1" file="shared_pseudocode.xml">CreateAccDescA32LSMD</a>(<a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>);
        <a link="accessor_Mem_with_type_3" file="shared_pseudocode.xml">Mem_with_type</a>{size}(address, accdesc) = value;
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/memory/MemU" mylink="aarch32.functions.memory.MemU" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemU - accessor
// ===============

accessor <anchor link="accessor_MemU_2">MemU</anchor>{size : integer{8, 16, 32, 64} }(address : bits(32) ) &lt;=&gt; value: bits(size)
begin
    getter
        let nontemporal : boolean = FALSE;
        let privileged : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
        let tagchecked : boolean = FALSE;
        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescGPR_4" file="shared_pseudocode.xml">CreateAccDescGPR</a>(<a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>, nontemporal, privileged,
                                                             tagchecked);
        return <a link="accessor_Mem_with_type_3" file="shared_pseudocode.xml">Mem_with_type</a>{size}(address, accdesc);
    end;

    setter
        let nontemporal : boolean = FALSE;
        let privileged : boolean  = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
        let tagchecked : boolean  = FALSE;
        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescGPR_4" file="shared_pseudocode.xml">CreateAccDescGPR</a>(<a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>, nontemporal, privileged,
                                                            tagchecked);
        <a link="accessor_Mem_with_type_3" file="shared_pseudocode.xml">Mem_with_type</a>{size}(address, accdesc) = value;
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/memory/MemU_unpriv" mylink="aarch32.functions.memory.MemU_unpriv" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemU_unpriv
// ===========

accessor <anchor link="accessor_MemU_unpriv_2">MemU_unpriv</anchor>{size : integer{8, 16, 32, 64}}(address : bits(32)) &lt;=&gt; value : bits(size)
begin
    getter
        let nontemporal : boolean = FALSE;
        let privileged : boolean  = FALSE;
        let tagchecked : boolean  = FALSE;
        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescGPR_4" file="shared_pseudocode.xml">CreateAccDescGPR</a>(<a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>, nontemporal, privileged,
                                                            tagchecked);
        return <a link="accessor_Mem_with_type_3" file="shared_pseudocode.xml">Mem_with_type</a>{size}(address, accdesc);
    end;

    setter
        let nontemporal : boolean = FALSE;
        let privileged : boolean  = FALSE;
        let tagchecked : boolean  = FALSE;
        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescGPR_4" file="shared_pseudocode.xml">CreateAccDescGPR</a>(<a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>, nontemporal, privileged,
                                                          tagchecked);
        <a link="accessor_Mem_with_type_3" file="shared_pseudocode.xml">Mem_with_type</a>{size}(address, accdesc) = value;
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/memory/Mem_with_type" mylink="aarch32.functions.memory.Mem_with_type" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Mem_with_type
// =============

accessor <anchor link="accessor_Mem_with_type_3">Mem_with_type</anchor>{size : integer{8, 16, 32, 64}}(address : bits(32),
                                                      accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
                                                     ) &lt;=&gt; value_in : bits(size)
begin
    // Perform a read of 'size' bits. The access byte order is reversed for a big-endian access.
    // Instruction fetches would call AArch32_MemSingle directly.
    getter
        let bytes : integer{} = size DIV 8;
        var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = accdesc_in;
        var value : bits(size);

        // Check alignment on size of element accessed, not overall access size
        var aligned : boolean;
        if accdesc.ispair then
            let half : integer{} = (size DIV 2) as integer{32};
            aligned = IsAlignedSize(address, half DIV 8);
        else
            aligned = IsAlignedSize(address, bytes);
        end;

        if !aligned &amp;&amp; <a link="func_AArch32_UnalignedAccessFaults_1" file="shared_pseudocode.xml">AArch32_UnalignedAccessFaults</a>(accdesc) then
            let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AlignmentFault_2" file="shared_pseudocode.xml">AlignmentFault</a>(accdesc, ZeroExtend{64}(address));
            <a link="func_AArch32_Abort_1" file="shared_pseudocode.xml">AArch32_Abort</a>(fault);
        end;
        if aligned then
            value = <a link="accessor_AArch32_MemSingle_4" file="shared_pseudocode.xml">AArch32_MemSingle</a>{size}(address, accdesc, aligned);
        else
            assert bytes &gt; 1;
            value[7:0] = <a link="accessor_AArch32_MemSingle_4" file="shared_pseudocode.xml">AArch32_MemSingle</a>{8}(address, accdesc, aligned);

            // For subsequent bytes, if they cross to a new translation page which assigns
            // Device memory type, it is CONSTRAINED UNPREDICTABLE whether an unaligned access
            // will generate an Alignment Fault.
            let c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = ConstrainUnpredictable(<a link="enum_Unpredictable_DEVPAGE2" file="shared_pseudocode.xml">Unpredictable_DEVPAGE2</a>);
            assert c IN {<a link="enum_Constraint_FAULT" file="shared_pseudocode.xml">Constraint_FAULT</a>, <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>};
            if c == <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a> then aligned = TRUE; end;

            for i = 1 to bytes-1 do
                value[i*:8] = <a link="accessor_AArch32_MemSingle_4" file="shared_pseudocode.xml">AArch32_MemSingle</a>{8}(address+i, accdesc, aligned);
            end;
        end;

        if <a link="func_BigEndian_1" file="shared_pseudocode.xml">BigEndian</a>(accdesc.acctype) then
            value = <a link="func_BigEndianReverse_2" file="shared_pseudocode.xml">BigEndianReverse</a>{size}(value);
        end;

        return value;
    end;

    // Perform a write of 'size' bits. The byte order is reversed for a big-endian access.
    setter
        let bytes : integer{}          = size DIV 8;
        var value :  bits(size)        = value_in;
        var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = accdesc_in;

        // Check alignment on size of element accessed, not overall access size
        var aligned : boolean;
        if accdesc.ispair then
            let half : integer{} = (size DIV 2) as integer{32};
            aligned = IsAlignedSize(address, half DIV 8);
        else
            aligned = IsAlignedSize(address, bytes);
        end;

        if !aligned &amp;&amp; <a link="func_AArch32_UnalignedAccessFaults_1" file="shared_pseudocode.xml">AArch32_UnalignedAccessFaults</a>(accdesc) then
            let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AlignmentFault_2" file="shared_pseudocode.xml">AlignmentFault</a>(accdesc, ZeroExtend{64}(address));
            <a link="func_AArch32_Abort_1" file="shared_pseudocode.xml">AArch32_Abort</a>(fault);
        end;

        if <a link="func_BigEndian_1" file="shared_pseudocode.xml">BigEndian</a>(accdesc.acctype) then
            value = <a link="func_BigEndianReverse_2" file="shared_pseudocode.xml">BigEndianReverse</a>{size}(value);
        end;
        if aligned then
            <a link="accessor_AArch32_MemSingle_4" file="shared_pseudocode.xml">AArch32_MemSingle</a>{size}(address, accdesc, aligned) = value;
        else
            assert bytes &gt; 1;
            <a link="accessor_AArch32_MemSingle_4" file="shared_pseudocode.xml">AArch32_MemSingle</a>{8}(address, accdesc, aligned) = value[7:0];

            // For subsequent bytes, if they cross to a new translation page which assigns
            // Device memory type, it is CONSTRAINED UNPREDICTABLE whether an unaligned access
            // will generate an Alignment Fault.

            let c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = ConstrainUnpredictable(<a link="enum_Unpredictable_DEVPAGE2" file="shared_pseudocode.xml">Unpredictable_DEVPAGE2</a>);
            assert c IN {<a link="enum_Constraint_FAULT" file="shared_pseudocode.xml">Constraint_FAULT</a>, <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>};
            if c == <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a> then aligned = TRUE; end;

            for i = 1 to bytes-1 do
                <a link="accessor_AArch32_MemSingle_4" file="shared_pseudocode.xml">AArch32_MemSingle</a>{8}(address+i, accdesc, aligned) = value[i*:8];
            end;
        end;
        return;
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/ras/AArch32_ESBOperation" mylink="aarch32.functions.ras.AArch32_ESBOperation" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ESBOperation()
// ======================
// Perform the AArch32 ESB operation for ESB executed in AArch32 state.

func <anchor link="func_AArch32_ESBOperation_0">AArch32_ESBOperation</anchor>()
begin
    var masked : boolean;
    var target_el : bits(2);

    (masked, target_el) = <a link="func_PhysicalSErrorTarget_0" file="shared_pseudocode.xml">PhysicalSErrorTarget</a>();

    // Check if routed to AArch64 state
    if !masked &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(target_el) then
        <a link="func_AArch64_ESBOperation_0" file="shared_pseudocode.xml">AArch64_ESBOperation</a>();
        return;
    end;

    // Check for a masked Physical SError pending that can be synchronized
    // by an Error synchronization event.
    if masked &amp;&amp; <a link="func_IsSynchronizablePhysicalSErrorPending_0" file="shared_pseudocode.xml">IsSynchronizablePhysicalSErrorPending</a>() then
        var syndrome : bits(32) = Zeros{};
        syndrome[31] = '1';  // A
        syndrome[15:0] = <a link="func_AArch32_PhysicalSErrorSyndrome_0" file="shared_pseudocode.xml">AArch32_PhysicalSErrorSyndrome</a>();
        DISR() = syndrome;
        ClearPendingPhysicalSError();
    end;

    return;
end;</pstext></ps>
    <ps name="aarch32/functions/ras/AArch32_EncodeAsyncErrorSyndrome" mylink="aarch32.functions.ras.AArch32_EncodeAsyncErrorSyndrome" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_EncodeAsyncErrorSyndrome()
// ==================================
// Return the encoding for specified  ErrorState for an SError exception taken
// to AArch32 state.

func <anchor link="func_AArch32_EncodeAsyncErrorSyndrome_1">AArch32_EncodeAsyncErrorSyndrome</anchor>(errorstate : <a link="type_ErrorState" file="shared_pseudocode.xml">ErrorState</a>) =&gt; bits(2)
begin
    case errorstate of
        when <a link="enum_ErrorState_UC" file="shared_pseudocode.xml">ErrorState_UC</a> =&gt;   return '00';
        when <a link="enum_ErrorState_UEU" file="shared_pseudocode.xml">ErrorState_UEU</a> =&gt;  return '01';
        when <a link="enum_ErrorState_UEO" file="shared_pseudocode.xml">ErrorState_UEO</a> =&gt;  return '10';
        when <a link="enum_ErrorState_UER" file="shared_pseudocode.xml">ErrorState_UER</a> =&gt;  return '11';
        otherwise =&gt; unreachable;
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/ras/AArch32_PhysicalSErrorSyndrome" mylink="aarch32.functions.ras.AArch32_PhysicalSErrorSyndrome" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_PhysicalSErrorSyndrome()
// ================================
// Generate SError syndrome.

func <anchor link="func_AArch32_PhysicalSErrorSyndrome_0">AArch32_PhysicalSErrorSyndrome</anchor>() =&gt; bits(16)
begin
    var syndrome : bits(32) = Zeros{};
    let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_GetPendingPhysicalSError_0" file="shared_pseudocode.xml">GetPendingPhysicalSError</a>();
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
        let errstate : <a link="type_ErrorState" file="shared_pseudocode.xml">ErrorState</a> = <a link="func_PEErrorState_1" file="shared_pseudocode.xml">PEErrorState</a>(fault);
        syndrome[11:10] = <a link="func_AArch32_EncodeAsyncErrorSyndrome_1" file="shared_pseudocode.xml">AArch32_EncodeAsyncErrorSyndrome</a>(errstate);   // AET
        syndrome[9]     = fault.extflag;                                // EA
        syndrome[5:0]   = '010001';                                     // DFSC
    else
        let long_format : boolean = TTBCR().EAE == '1';
        syndrome = <a link="func_AArch32_CommonFaultStatus_2" file="shared_pseudocode.xml">AArch32_CommonFaultStatus</a>(fault, long_format);
    end;
    return syndrome[15:0];
end;</pstext></ps>
    <ps name="aarch32/functions/ras/AArch32_vESBOperation" mylink="aarch32.functions.ras.AArch32_vESBOperation" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_vESBOperation()
// =======================
// Perform the ESB operation for virtual SError interrupts executed in AArch32 state.
// If FEAT_E3DSE is implemented and there is no unmasked virtual SError exception
// pending, then AArch64_dESBOperation() is called to perform the AArch64 ESB operation
// for a pending delegated SError exception.

func <anchor link="func_AArch32_vESBOperation_0">AArch32_vESBOperation</anchor>()
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>();

    // Check for EL2 using AArch64 state
    if !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        <a link="func_AArch64_vESBOperation_0" file="shared_pseudocode.xml">AArch64_vESBOperation</a>();
        return;
    end;

    // If physical SError interrupts are routed to Hyp mode, and TGE is not set, then a virtual
    // SError interrupt might be pending.
    let vsei_pending : boolean = <a link="func_IsVirtualSErrorPending_0" file="shared_pseudocode.xml">IsVirtualSErrorPending</a>() &amp;&amp; HCR().TGE == '0' &amp;&amp; HCR().AMO == '1';
    let vsei_masked : boolean  = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.A == '1' || <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() ||
                                  <a link="func_ExternalDebugInterruptsDisabled_1" file="shared_pseudocode.xml">ExternalDebugInterruptsDisabled</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>));

    // Check for a masked virtual SError pending
    if vsei_pending &amp;&amp; vsei_masked then
        var syndrome : bits(32) = Zeros{};
        syndrome[31]    = '1';           // A
        syndrome[15:14] = VDFSR()[15:14];  // AET
        syndrome[12]    = VDFSR()[12];     // ExT
        syndrome[9]     = TTBCR().EAE;     // LPAE
        if TTBCR().EAE == '1' then         // Long-descriptor format
            syndrome[5:0]    = '010001'; // STATUS
        else                             // Short-descriptor format
            syndrome[10,3:0] = '10110';  // FS
        end;
        VDISR() = syndrome;
        <a link="func_ClearPendingVirtualSError_0" file="shared_pseudocode.xml">ClearPendingVirtualSError</a>();
    elsif IsFeatureImplemented(FEAT_E3DSE) &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        <a link="func_AArch64_dESBOperation_0" file="shared_pseudocode.xml">AArch64_dESBOperation</a>();
    end;

    return;
end;</pstext></ps>
    <ps name="aarch32/functions/registers/AArch32_ResetGeneralRegisters" mylink="aarch32.functions.registers.AArch32_ResetGeneralRegisters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ResetGeneralRegisters()
// ===============================

func <anchor link="func_AArch32_ResetGeneralRegisters_0">AArch32_ResetGeneralRegisters</anchor>()
begin

    for i = 0 to 7 do
        <a link="accessor_R_1" file="shared_pseudocode.xml">R</a>(i) = ARBITRARY : bits(32);
    end;
    for i = 8 to 12 do
        <a link="accessor_Rmode_2" file="shared_pseudocode.xml">Rmode</a>(i, <a link="global_M32_User" file="shared_pseudocode.xml">M32_User</a>) = ARBITRARY : bits(32);
        <a link="accessor_Rmode_2" file="shared_pseudocode.xml">Rmode</a>(i, <a link="global_M32_FIQ" file="shared_pseudocode.xml">M32_FIQ</a>)  = ARBITRARY : bits(32);
    end;
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then <a link="accessor_Rmode_2" file="shared_pseudocode.xml">Rmode</a>(13, <a link="global_M32_Hyp" file="shared_pseudocode.xml">M32_Hyp</a>) = ARBITRARY : bits(32); end;   // No R14_hyp
    for i = 13 to 14 do
        <a link="accessor_Rmode_2" file="shared_pseudocode.xml">Rmode</a>(i, <a link="global_M32_User" file="shared_pseudocode.xml">M32_User</a>)  = ARBITRARY : bits(32);
        <a link="accessor_Rmode_2" file="shared_pseudocode.xml">Rmode</a>(i, <a link="global_M32_FIQ" file="shared_pseudocode.xml">M32_FIQ</a>)   = ARBITRARY : bits(32);
        <a link="accessor_Rmode_2" file="shared_pseudocode.xml">Rmode</a>(i, <a link="global_M32_IRQ" file="shared_pseudocode.xml">M32_IRQ</a>)   = ARBITRARY : bits(32);
        <a link="accessor_Rmode_2" file="shared_pseudocode.xml">Rmode</a>(i, <a link="global_M32_Svc" file="shared_pseudocode.xml">M32_Svc</a>)   = ARBITRARY : bits(32);
        <a link="accessor_Rmode_2" file="shared_pseudocode.xml">Rmode</a>(i, <a link="global_M32_Abort" file="shared_pseudocode.xml">M32_Abort</a>) = ARBITRARY : bits(32);
        <a link="accessor_Rmode_2" file="shared_pseudocode.xml">Rmode</a>(i, <a link="global_M32_Undef" file="shared_pseudocode.xml">M32_Undef</a>) = ARBITRARY : bits(32);
        if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then <a link="accessor_Rmode_2" file="shared_pseudocode.xml">Rmode</a>(i, <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a>) = ARBITRARY : bits(32); end;
    end;

    return;
end;</pstext></ps>
    <ps name="aarch32/functions/registers/AArch32_ResetSIMDFPRegisters" mylink="aarch32.functions.registers.AArch32_ResetSIMDFPRegisters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ResetSIMDFPRegisters()
// ==============================

func <anchor link="func_AArch32_ResetSIMDFPRegisters_0">AArch32_ResetSIMDFPRegisters</anchor>()
begin

    for i = 0 to 15 do
        <a link="accessor_Q_1" file="shared_pseudocode.xml">Q</a>(i) = ARBITRARY : bits(128);
    end;

    return;
end;</pstext></ps>
    <ps name="aarch32/functions/registers/AArch32_ResetSpecialRegisters" mylink="aarch32.functions.registers.AArch32_ResetSpecialRegisters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ResetSpecialRegisters()
// ===============================

func <anchor link="func_AArch32_ResetSpecialRegisters_0">AArch32_ResetSpecialRegisters</anchor>()
begin

    // AArch32 special registers
    SPSR_fiq()[31:0] = ARBITRARY : bits(32);
    SPSR_irq()[31:0] = ARBITRARY : bits(32);
    SPSR_svc()[31:0] = ARBITRARY : bits(32);
    SPSR_abt()[31:0] = ARBITRARY : bits(32);
    SPSR_und()[31:0] = ARBITRARY : bits(32);
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        SPSR_hyp() = ARBITRARY : bits(32);
        ELR_hyp()  = ARBITRARY : bits(32);
    end;
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        SPSR_mon() = ARBITRARY : bits(32);
    end;

    // External debug special registers
    DLR()   = ARBITRARY : bits(32);
    DSPSR() = ARBITRARY : bits(32);

    return;
end;</pstext></ps>
    <ps name="aarch32/functions/registers/AArch32_ResetSystemRegisters" mylink="aarch32.functions.registers.AArch32_ResetSystemRegisters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ResetSystemRegisters()
// ==============================

impdef func AArch32_ResetSystemRegisters(cold_reset : boolean)
begin
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/registers/ALUExceptionReturn" mylink="aarch32.functions.registers.ALUExceptionReturn" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ALUExceptionReturn()
// ====================

func <anchor link="func_ALUExceptionReturn_1">ALUExceptionReturn</anchor>(address : bits(32))
begin
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
        Undefined();
    elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M IN {<a link="global_M32_User" file="shared_pseudocode.xml">M32_User</a>,<a link="global_M32_System" file="shared_pseudocode.xml">M32_System</a>} then
        let c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = ConstrainUnpredictable(<a link="enum_Unpredictable_ALUEXCEPTIONRETURN" file="shared_pseudocode.xml">Unpredictable_ALUEXCEPTIONRETURN</a>);
        assert c IN {<a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a>, <a link="enum_Constraint_NOP" file="shared_pseudocode.xml">Constraint_NOP</a>};
        case c of
            when <a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a> =&gt;
                Undefined();
            when <a link="enum_Constraint_NOP" file="shared_pseudocode.xml">Constraint_NOP</a> =&gt;
                <a link="func_ExecuteAsNOP_0" file="shared_pseudocode.xml">ExecuteAsNOP</a>();
        end;
    else
        <a link="func_AArch32_ExceptionReturn_2" file="shared_pseudocode.xml">AArch32_ExceptionReturn</a>(address, <a link="accessor_SPSR_curr_0" file="shared_pseudocode.xml">SPSR_curr</a>());
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/registers/ALUWritePC" mylink="aarch32.functions.registers.ALUWritePC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ALUWritePC()
// ============

func <anchor link="func_ALUWritePC_1">ALUWritePC</anchor>(address : bits(32))
begin
    if <a link="func_CurrentInstrSet_0" file="shared_pseudocode.xml">CurrentInstrSet</a>() == <a link="enum_InstrSet_A32" file="shared_pseudocode.xml">InstrSet_A32</a> then
        <a link="func_BXWritePC_2" file="shared_pseudocode.xml">BXWritePC</a>(address, <a link="enum_BranchType_INDIR" file="shared_pseudocode.xml">BranchType_INDIR</a>);
    else
        <a link="func_BranchWritePC_2" file="shared_pseudocode.xml">BranchWritePC</a>(address, <a link="enum_BranchType_INDIR" file="shared_pseudocode.xml">BranchType_INDIR</a>);
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/registers/BXWritePC" mylink="aarch32.functions.registers.BXWritePC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BXWritePC()
// ===========

func <anchor link="func_BXWritePC_2">BXWritePC</anchor>(address_in : bits(32), branch_type : <a link="type_BranchType" file="shared_pseudocode.xml">BranchType</a>)
begin
    var address : bits(32) = address_in;
    if address[0] == '1' then
        <a link="func_SelectInstrSet_1" file="shared_pseudocode.xml">SelectInstrSet</a>(<a link="enum_InstrSet_T32" file="shared_pseudocode.xml">InstrSet_T32</a>);
        address[0] = '0';
    else
        <a link="func_SelectInstrSet_1" file="shared_pseudocode.xml">SelectInstrSet</a>(<a link="enum_InstrSet_A32" file="shared_pseudocode.xml">InstrSet_A32</a>);
        // For branches to an unaligned PC counter in A32 state, the PE takes the branch
        // and does one of:
        // * Forces the address to be aligned
        // * Leaves the PC unaligned, meaning the target generates a PC Alignment fault.
        if address[1] == '1' &amp;&amp; <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_A32FORCEALIGNPC" file="shared_pseudocode.xml">Unpredictable_A32FORCEALIGNPC</a>) then
            address[1] = '0';
        end;
    end;
    let branch_conditional : boolean = <a link="func_CurrentCond_0" file="shared_pseudocode.xml">CurrentCond</a>() != '111x';
    <a link="func_BranchTo_4" file="shared_pseudocode.xml">BranchTo</a>{32}(address, branch_type, branch_conditional);
end;</pstext></ps>
    <ps name="aarch32/functions/registers/BranchWritePC" mylink="aarch32.functions.registers.BranchWritePC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BranchWritePC()
// ===============

func <anchor link="func_BranchWritePC_2">BranchWritePC</anchor>(address_in : bits(32), branch_type : <a link="type_BranchType" file="shared_pseudocode.xml">BranchType</a>)
begin
    var address : bits(32) = address_in;
    if <a link="func_CurrentInstrSet_0" file="shared_pseudocode.xml">CurrentInstrSet</a>() == <a link="enum_InstrSet_A32" file="shared_pseudocode.xml">InstrSet_A32</a> then
        address[1:0] = '00';
    else
        address[0] = '0';
    end;
    let branch_conditional : boolean = <a link="func_CurrentCond_0" file="shared_pseudocode.xml">CurrentCond</a>() != '111x';
    <a link="func_BranchTo_4" file="shared_pseudocode.xml">BranchTo</a>{32}(address, branch_type, branch_conditional);
end;</pstext></ps>
    <ps name="aarch32/functions/registers/CBWritePC" mylink="aarch32.functions.registers.CBWritePC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CBWritePC()
// ===========
// Takes a branch from a CBNZ/CBZ instruction.

func <anchor link="func_CBWritePC_1">CBWritePC</anchor>(address_in : bits(32))
begin
    var address : bits(32) = address_in;
    assert <a link="func_CurrentInstrSet_0" file="shared_pseudocode.xml">CurrentInstrSet</a>() == <a link="enum_InstrSet_T32" file="shared_pseudocode.xml">InstrSet_T32</a>;
    address[0] = '0';
    let branch_conditional : boolean = TRUE;
    <a link="func_BranchTo_4" file="shared_pseudocode.xml">BranchTo</a>{32}(address, <a link="enum_BranchType_DIR" file="shared_pseudocode.xml">BranchType_DIR</a>, branch_conditional);
end;</pstext></ps>
    <ps name="aarch32/functions/registers/D" mylink="aarch32.functions.registers.D" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// D - accessor
// ============

accessor <anchor link="accessor_D_1">D</anchor>(n : integer) &lt;=&gt; value : bits(64)
begin
    getter
        assert n &gt;= 0 &amp;&amp; n &lt;= 31;
        let vreg : bits(128) = V{}(n DIVRM 2);
        return vreg[(n MOD 2)*:64];
    end;
    setter
        assert n &gt;= 0 &amp;&amp; n &lt;= 31;
        var vreg : bits(128) = V{}(n DIVRM 2);
        vreg[(n MOD 2)*:64] = value;
        <a link="accessor_V_2" file="shared_pseudocode.xml">V</a>{128}(n DIVRM 2) = vreg;
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/registers/Din" mylink="aarch32.functions.registers.Din" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Din
// ===
// Return the initial value of D input

func <anchor link="func_Din_1">Din</anchor>(n : integer) =&gt; bits(64)
begin
    assert n &gt;= 0 &amp;&amp; n &lt;= 31;
    return <a link="global__Dclone" file="shared_pseudocode.xml">_Dclone</a>[[n]];
end;</pstext></ps>
    <ps name="aarch32/functions/registers/H" mylink="aarch32.functions.registers.H" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// H - accessor
// ============

accessor <anchor link="accessor_H_1">H</anchor>(n : integer) &lt;=&gt; value : bits(16)
begin
    getter
        assert n &gt;= 0 &amp;&amp; n &lt;= 31;
        return <a link="accessor_S_1" file="shared_pseudocode.xml">S</a>(n)[15:0];
    end;
    setter
        <a link="accessor_S_1" file="shared_pseudocode.xml">S</a>(n) = ZeroExtend{32}(value);
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/registers/LR" mylink="aarch32.functions.registers.LR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// LR - accessor
// =============

accessor <anchor link="accessor_LR_0">LR</anchor>() &lt;=&gt; value : bits(32)
begin
    getter
        return <a link="accessor_R_1" file="shared_pseudocode.xml">R</a>(14);
    end;
    setter
        <a link="accessor_R_1" file="shared_pseudocode.xml">R</a>(14) = value;
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/registers/LoadWritePC" mylink="aarch32.functions.registers.LoadWritePC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// LoadWritePC()
// =============

func <anchor link="func_LoadWritePC_1">LoadWritePC</anchor>(address : bits(32))
begin
    <a link="func_BXWritePC_2" file="shared_pseudocode.xml">BXWritePC</a>(address, <a link="enum_BranchType_INDIR" file="shared_pseudocode.xml">BranchType_INDIR</a>);
end;</pstext></ps>
    <ps name="aarch32/functions/registers/LookUpRIndex" mylink="aarch32.functions.registers.LookUpRIndex" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// LookUpRIndex()
// ==============

func <anchor link="func_LookUpRIndex_2">LookUpRIndex</anchor>(n : integer, mode : bits(5)) =&gt; integer
begin
    assert n &gt;= 0 &amp;&amp; n &lt;= 14;

    var result : integer;
    case n of  // Select  index by mode:     usr fiq irq svc abt und hyp
        when 8    =&gt;  result = <a link="func_RBankSelect_8" file="shared_pseudocode.xml">RBankSelect</a>(mode,  8, 24,  8,  8,  8,  8,  8);
        when 9    =&gt;  result = <a link="func_RBankSelect_8" file="shared_pseudocode.xml">RBankSelect</a>(mode,  9, 25,  9,  9,  9,  9,  9);
        when 10   =&gt;  result = <a link="func_RBankSelect_8" file="shared_pseudocode.xml">RBankSelect</a>(mode, 10, 26, 10, 10, 10, 10, 10);
        when 11   =&gt;  result = <a link="func_RBankSelect_8" file="shared_pseudocode.xml">RBankSelect</a>(mode, 11, 27, 11, 11, 11, 11, 11);
        when 12   =&gt;  result = <a link="func_RBankSelect_8" file="shared_pseudocode.xml">RBankSelect</a>(mode, 12, 28, 12, 12, 12, 12, 12);
        when 13   =&gt;  result = <a link="func_RBankSelect_8" file="shared_pseudocode.xml">RBankSelect</a>(mode, 13, 29, 17, 19, 21, 23, 15);
        when 14   =&gt;  result = <a link="func_RBankSelect_8" file="shared_pseudocode.xml">RBankSelect</a>(mode, 14, 30, 16, 18, 20, 22, 14);
        otherwise =&gt;  result = n;
    end;

    return result;
end;</pstext></ps>
    <ps name="aarch32/functions/registers/Monitor" mylink="aarch32.functions.registers.Monitor" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Monitor mode registers
// ======================
// The Monitor mode registers do not map to X registers, so must be defined separately

var <anchor link="global_SP_mon">SP_mon</anchor> : bits(32);

var <anchor link="global_LR_mon">LR_mon</anchor> : bits(32);</pstext></ps>
    <ps name="aarch32/functions/registers/PC32" mylink="aarch32.functions.registers.PC32" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PC32
// ====
// Read 32-bit program counter

func <anchor link="func_PC32_0">PC32</anchor>() =&gt; bits(32)
begin
    return <a link="accessor_R_1" file="shared_pseudocode.xml">R</a>(15);               // This includes the offset from AArch32 state
end;</pstext></ps>
    <ps name="aarch32/functions/registers/PCStoreValue" mylink="aarch32.functions.registers.PCStoreValue" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PCStoreValue()
// ==============

func <anchor link="func_PCStoreValue_0">PCStoreValue</anchor>() =&gt; bits(32)
begin
    // This function returns the PC value. On architecture versions before Armv7, it
    // is permitted to instead return PC+4, provided it does so consistently. It is
    // used only to describe A32 instructions, so it returns the address of the current
    // instruction plus 8 (normally) or 12 (when the alternative is permitted).
    return <a link="func_PC32_0" file="shared_pseudocode.xml">PC32</a>();
end;</pstext></ps>
    <ps name="aarch32/functions/registers/Q" mylink="aarch32.functions.registers.Q" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Q - accessor
// ============

accessor <anchor link="accessor_Q_1">Q</anchor>(n : integer) &lt;=&gt; value : bits(128)
begin
    getter
        assert n &gt;= 0 &amp;&amp; n &lt;= 15;
        return <a link="accessor_V_2" file="shared_pseudocode.xml">V</a>{128}(n);
    end;
    setter
        assert n &gt;= 0 &amp;&amp; n &lt;= 15;
        <a link="accessor_V_2" file="shared_pseudocode.xml">V</a>{128}(n) = value;
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/registers/Qin" mylink="aarch32.functions.registers.Qin" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Qin
// ===
// Return the initial value of Q input

func <anchor link="func_Qin_1">Qin</anchor>(n : integer) =&gt; bits(128)
begin
    assert n &gt;= 0 &amp;&amp; n &lt;= 15;
    return <a link="func_Din_1" file="shared_pseudocode.xml">Din</a>(2*n+1)::<a link="func_Din_1" file="shared_pseudocode.xml">Din</a>(2*n);
end;</pstext></ps>
    <ps name="aarch32/functions/registers/R" mylink="aarch32.functions.registers.R" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// R - accessor
// ============

accessor <anchor link="accessor_R_1">R</anchor>(n : integer) &lt;=&gt; value : bits(32)
begin
    getter
        if n == 15 then
            let offset : integer{} = (if <a link="func_CurrentInstrSet_0" file="shared_pseudocode.xml">CurrentInstrSet</a>() == <a link="enum_InstrSet_A32" file="shared_pseudocode.xml">InstrSet_A32</a> then 8 else 4);
            return <a link="global__PC" file="shared_pseudocode.xml">_PC</a>[31:0] + offset;
        else
            return <a link="accessor_Rmode_2" file="shared_pseudocode.xml">Rmode</a>(n, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M);
        end;
    end;
    setter
        <a link="accessor_Rmode_2" file="shared_pseudocode.xml">Rmode</a>(n, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M) = value;
        return;
    end;
end;

// R - accessor
// ============

accessor <anchor link="accessor_R_2">R</anchor>(lr : integer, hr : integer) &lt;=&gt; value : bits(64)
begin
    getter
        return <a link="accessor_R_1" file="shared_pseudocode.xml">R</a>(hr) :: <a link="accessor_R_1" file="shared_pseudocode.xml">R</a>(lr);
    end;

    setter
        <a link="accessor_R_1" file="shared_pseudocode.xml">R</a>(lr) = value[0+:32];
        <a link="accessor_R_1" file="shared_pseudocode.xml">R</a>(hr) = value[32+:32];
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/registers/RBankSelect" mylink="aarch32.functions.registers.RBankSelect" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// RBankSelect()
// =============

func <anchor link="func_RBankSelect_8">RBankSelect</anchor>(mode : bits(5), usr : integer, fiq : integer, irq : integer,
                 svc : integer, abt : integer, und : integer, hyp : integer) =&gt; integer
begin

    var result : integer;
    case mode of
        when <a link="global_M32_User" file="shared_pseudocode.xml">M32_User</a>   =&gt; result = usr;  // User mode
        when <a link="global_M32_FIQ" file="shared_pseudocode.xml">M32_FIQ</a>    =&gt; result = fiq;  // FIQ mode
        when <a link="global_M32_IRQ" file="shared_pseudocode.xml">M32_IRQ</a>    =&gt; result = irq;  // IRQ mode
        when <a link="global_M32_Svc" file="shared_pseudocode.xml">M32_Svc</a>    =&gt; result = svc;  // Supervisor mode
        when <a link="global_M32_Abort" file="shared_pseudocode.xml">M32_Abort</a>  =&gt; result = abt;  // Abort mode
        when <a link="global_M32_Hyp" file="shared_pseudocode.xml">M32_Hyp</a>    =&gt; result = hyp;  // Hyp mode
        when <a link="global_M32_Undef" file="shared_pseudocode.xml">M32_Undef</a>  =&gt; result = und;  // Undefined mode
        when <a link="global_M32_System" file="shared_pseudocode.xml">M32_System</a> =&gt; result = usr;  // System mode uses User mode registers
        otherwise       =&gt; unreachable;   // Monitor mode
    end;

    return result;
end;</pstext></ps>
    <ps name="aarch32/functions/registers/ReadAnyAllocatedRegister" mylink="aarch32.functions.registers.ReadAnyAllocatedRegister" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ReadAnyAllocatedRegister()
// ==========================

impdef func <anchor link="func_ReadAnyAllocatedRegister_0">ReadAnyAllocatedRegister</anchor>() =&gt; bits(32)
begin
    return Zeros{32};
end;</pstext></ps>
    <ps name="aarch32/functions/registers/ReadAnyAllocatedSPSR" mylink="aarch32.functions.registers.ReadAnyAllocatedSPSR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ReadAnyAllocatedSPSR()
// ======================

impdef func <anchor link="func_ReadAnyAllocatedSPSR_0">ReadAnyAllocatedSPSR</anchor>() =&gt; bits(32)
begin
    return Zeros{32};
end;</pstext></ps>
    <ps name="aarch32/functions/registers/Rmode" mylink="aarch32.functions.registers.Rmode" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Rmode - accessor
// ================

accessor <anchor link="accessor_Rmode_2">Rmode</anchor>(n : integer, mode : bits(5)) &lt;=&gt; value : bits(32)
begin
    getter
        assert n &gt;= 0 &amp;&amp; n &lt;= 14;

        // Check for attempted use of Monitor mode in Non-secure state.
        if <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() != <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then assert mode != <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a>; end;
        assert !<a link="func_BadMode_1" file="shared_pseudocode.xml">BadMode</a>(mode);

        if mode == <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a> then
            if n == 13 then return <a link="global_SP_mon" file="shared_pseudocode.xml">SP_mon</a>;
            elsif n == 14 then return <a link="global_LR_mon" file="shared_pseudocode.xml">LR_mon</a>;
            else return <a link="global__R" file="shared_pseudocode.xml">_R</a>[[n]][31:0];
            end;
        else
            return <a link="global__R" file="shared_pseudocode.xml">_R</a>[[<a link="func_LookUpRIndex_2" file="shared_pseudocode.xml">LookUpRIndex</a>(n, mode)]][31:0];
        end;
    end;

    setter
        assert n &gt;= 0 &amp;&amp; n &lt;= 14;

        // Check for attempted use of Monitor mode in Non-secure state.
        if <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() != <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then assert mode != <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a>; end;
        assert !<a link="func_BadMode_1" file="shared_pseudocode.xml">BadMode</a>(mode);

        if mode == <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a> then
            if n == 13 then <a link="global_SP_mon" file="shared_pseudocode.xml">SP_mon</a> = value;
            elsif n == 14 then <a link="global_LR_mon" file="shared_pseudocode.xml">LR_mon</a> = value;
            else <a link="global__R" file="shared_pseudocode.xml">_R</a>[[n]][31:0] = value;
            end;
        else
            // It is CONSTRAINED UNPREDICTABLE whether the upper 32 bits of the X
            // register are unchanged or set to zero. This is also tested for on
            // exception entry, as this applies to all AArch32 registers.
            if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() &amp;&amp; <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_ZEROUPPER" file="shared_pseudocode.xml">Unpredictable_ZEROUPPER</a>) then
                <a link="global__R" file="shared_pseudocode.xml">_R</a>[[<a link="func_LookUpRIndex_2" file="shared_pseudocode.xml">LookUpRIndex</a>(n, mode)]] = ZeroExtend{64}(value);
            else
                <a link="global__R" file="shared_pseudocode.xml">_R</a>[[<a link="func_LookUpRIndex_2" file="shared_pseudocode.xml">LookUpRIndex</a>(n, mode)]][31:0] = value;
            end;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/registers/S" mylink="aarch32.functions.registers.S" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// S - accessor
// ============

accessor <anchor link="accessor_S_1">S</anchor>(n : integer) &lt;=&gt; value : bits(32)
begin
    getter
        assert n &gt;= 0 &amp;&amp; n &lt;= 31;
        let vreg : bits(128) = V{}(n DIVRM 4);
        return vreg[(n MOD 4)*:32];
    end;

    setter
        assert n &gt;= 0 &amp;&amp; n &lt;= 31;
        var vreg : bits(128) = V{}(n DIVRM 4);
        vreg[(n MOD 4)*:32] = value;
        <a link="accessor_V_2" file="shared_pseudocode.xml">V</a>{128}(n DIVRM 4) = vreg;
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/registers/WriteAnyAllocatedRegister" mylink="aarch32.functions.registers.WriteAnyAllocatedRegister" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// WriteAnyAllocatedRegister()
// ===========================

impdef func WriteAnyAllocatedRegister(value : bits(32))
begin
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/registers/WriteAnyAllocatedSPSR" mylink="aarch32.functions.registers.WriteAnyAllocatedSPSR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// WriteAnyAllocatedSPSR()
// =======================

impdef func WriteAnyAllocatedSPSR(value : bits(32))
begin
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/registers/_Dclone" mylink="aarch32.functions.registers._Dclone" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// _Dclone[]
// =========
// Clone the 64-bit Advanced SIMD and VFP extension register bank for use as input to
// instruction pseudocode, to avoid read-after-write for Advanced SIMD and VFP operations.

var <anchor link="global__Dclone">_Dclone</anchor> : array [[32]] of bits(64);</pstext></ps>
    <ps name="aarch32/functions/system/AArch32_ExceptionReturn" mylink="aarch32.functions.system.AArch32_ExceptionReturn" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ExceptionReturn()
// =========================

func <anchor link="func_AArch32_ExceptionReturn_2">AArch32_ExceptionReturn</anchor>(new_pc_in : bits(32), spsr : bits(32))
begin
    var new_pc : bits(32) = new_pc_in;
    SynchronizeContext();
    // Attempts to change to an illegal mode or state will invoke the Illegal Execution state
    // mechanism
    <a link="func_SetPSTATEFromPSR_2" file="shared_pseudocode.xml">SetPSTATEFromPSR</a>{32}(spsr);
    ClearExclusiveLocal(<a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>());
    <a link="func_SendEventLocal_0" file="shared_pseudocode.xml">SendEventLocal</a>();

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL == '1' then
        // If the exception return is illegal, PC[1:0] are UNKNOWN
        new_pc[1:0] = ARBITRARY : bits(2);
    else
        // LR[1:0] or LR[0] are treated as being 0, depending on the target instruction set state
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T == '1' then
            new_pc[0] = '0';                 // T32
        else
            new_pc[1:0] = '00';              // A32
        end;
    end;

    let branch_conditional : boolean = <a link="func_CurrentCond_0" file="shared_pseudocode.xml">CurrentCond</a>() != '111x';
    <a link="func_BranchTo_4" file="shared_pseudocode.xml">BranchTo</a>{32}(new_pc, <a link="enum_BranchType_ERET" file="shared_pseudocode.xml">BranchType_ERET</a>, branch_conditional);
    <a link="func_CheckExceptionCatch_1" file="shared_pseudocode.xml">CheckExceptionCatch</a>(FALSE);              // Check for debug event on exception return
end;</pstext></ps>
    <ps name="aarch32/functions/system/AArch32_ExecutingCP10or11Instr" mylink="aarch32.functions.system.AArch32_ExecutingCP10or11Instr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ExecutingCP10or11Instr()
// ================================

func <anchor link="func_AArch32_ExecutingCP10or11Instr_0">AArch32_ExecutingCP10or11Instr</anchor>() =&gt; boolean
begin
    let instr : bits(32) =  <a link="func_ThisInstr_0" file="shared_pseudocode.xml">ThisInstr</a>();
    let instr_set : <a link="type_InstrSet" file="shared_pseudocode.xml">InstrSet</a> = <a link="func_CurrentInstrSet_0" file="shared_pseudocode.xml">CurrentInstrSet</a>();
    assert instr_set IN {<a link="enum_InstrSet_A32" file="shared_pseudocode.xml">InstrSet_A32</a>, <a link="enum_InstrSet_T32" file="shared_pseudocode.xml">InstrSet_T32</a>};

    if instr_set == <a link="enum_InstrSet_A32" file="shared_pseudocode.xml">InstrSet_A32</a> then
        return ((instr[27:24] == '1110' || instr[27:25] == '110') &amp;&amp; instr[11:8] == '101x');
    else // InstrSet_T32
        return (instr[31:28] == '111x' &amp;&amp; (instr[27:24] == '1110' || instr[27:25] == '110') &amp;&amp;
                instr[11:8] == '101x');
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/system/AArch32_ITAdvance" mylink="aarch32.functions.system.AArch32_ITAdvance" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ITAdvance()
// ===================

func <anchor link="func_AArch32_ITAdvance_0">AArch32_ITAdvance</anchor>()
begin
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT[2:0] == '000' then
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT = '00000000';
    else
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT[4:0] = LSL(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT[4:0], 1);
    end;
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/system/AArch32_InterruptPending" mylink="aarch32.functions.system.AArch32_InterruptPending" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_InterruptPending()
// ==========================
// Returns TRUE if there are any pending physical or virtual interrupts, and FALSE otherwise.

func <anchor link="func_AArch32_InterruptPending_0">AArch32_InterruptPending</anchor>() =&gt; boolean
begin
    if !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        return <a link="func_AArch64_InterruptPending_0" file="shared_pseudocode.xml">AArch64_InterruptPending</a>();
    end;

    let (irq_pending, -) = <a link="func_IRQPending_0" file="shared_pseudocode.xml">IRQPending</a>();
    let (fiq_pending, -) = <a link="func_FIQPending_0" file="shared_pseudocode.xml">FIQPending</a>();
    let pending_physical_interrupt : boolean = (irq_pending || fiq_pending ||
                                                <a link="func_IsPhysicalSErrorPending_0" file="shared_pseudocode.xml">IsPhysicalSErrorPending</a>());

    var pending_virtual_interrupt : boolean = FALSE;
    if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; HCR().TGE == '0' then
        let virq_pending : boolean = (HCR().IMO == '1' &amp;&amp; (<a link="func_VirtualIRQPending_0" file="shared_pseudocode.xml">VirtualIRQPending</a>() || HCR().VI == '1'));
        let vfiq_pending : boolean = (HCR().FMO == '1' &amp;&amp; (<a link="func_VirtualFIQPending_0" file="shared_pseudocode.xml">VirtualFIQPending</a>() || HCR().VF == '1'));
        let vsei_pending : boolean = (HCR().AMO == '1' &amp;&amp;
                                      (<a link="func_IsVirtualSErrorPending_0" file="shared_pseudocode.xml">IsVirtualSErrorPending</a>() || HCR().VA == '1'));

        pending_virtual_interrupt = vsei_pending || virq_pending || vfiq_pending;
    end;

    return pending_physical_interrupt || pending_virtual_interrupt;
end;</pstext></ps>
    <ps name="aarch32/functions/system/AArch32_SysRegRead" mylink="aarch32.functions.system.AArch32_SysRegRead" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_SysRegRead()
// ====================
// Read from a 32-bit AArch32 System register and write the register's contents to R[t].

impdef func AArch32_SysRegRead(cp_num : integer, instr : bits(32), t : integer)
begin
    let (-, el) = <a link="func_ELFromM32_1" file="shared_pseudocode.xml">ELFromM32</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M);
    let opc1 = instr[21+:3];
    let CRn  = instr[16+:4];
    let CRm  = instr[0+:4];
    let opc2 = instr[5+:3];
end;</pstext></ps>
    <ps name="aarch32/functions/system/AArch32_SysRegRead64" mylink="aarch32.functions.system.AArch32_SysRegRead64" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_SysRegRead64()
// ======================
// Read from a 64-bit AArch32 System register and write the register's contents to R[t] and R[t2].

impdef func AArch32_SysRegRead64(cp_num : integer, instr : bits(32), t : integer, t2 : integer)
begin
    let (-, el) = <a link="func_ELFromM32_1" file="shared_pseudocode.xml">ELFromM32</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M);
    let opc1 = instr[4+:4];
    let CRm  = instr[0+:4];
end;</pstext></ps>
    <ps name="aarch32/functions/system/AArch32_SysRegReadCanWriteAPSR" mylink="aarch32.functions.system.AArch32_SysRegReadCanWriteAPSR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_SysRegReadCanWriteAPSR()
// ================================
// Determines whether the AArch32 System register read instruction can write to APSR flags.

func <anchor link="func_AArch32_SysRegReadCanWriteAPSR_2">AArch32_SysRegReadCanWriteAPSR</anchor>(cp_num : integer, instr : bits(32)) =&gt; boolean
begin
    assert <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>();
    assert (cp_num IN {14,15});
    assert cp_num == UInt(instr[11:8]);

    let opc1 : integer{} = UInt(instr[23:21]);
    let opc2 : integer{} = UInt(instr[7:5]);
    let CRn : integer{}  = UInt(instr[19:16]);
    let CRm : integer{}  = UInt(instr[3:0]);

    if cp_num == 14 &amp;&amp; opc1 == 0 &amp;&amp; CRn == 0 &amp;&amp; CRm == 1 &amp;&amp; opc2 == 0 then // DBGDSCRint
        return TRUE;
    end;

    return FALSE;
end;</pstext></ps>
    <ps name="aarch32/functions/system/AArch32_SysRegWrite" mylink="aarch32.functions.system.AArch32_SysRegWrite" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_SysRegWrite()
// =====================
// Read the contents of R[t] and write to a 32-bit AArch32 System register.

impdef func AArch32_SysRegWrite(cp_num : integer, instr : bits(32), t : integer)
begin
    let (-, el) = <a link="func_ELFromM32_1" file="shared_pseudocode.xml">ELFromM32</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M);
    let opc1 = instr[21+:3];
    let CRn  = instr[16+:4];
    let CRm  = instr[ 0+:4];
    let opc2 = instr[ 5+:3];
end;</pstext></ps>
    <ps name="aarch32/functions/system/AArch32_SysRegWrite64" mylink="aarch32.functions.system.AArch32_SysRegWrite64" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_SysRegWrite64()
// =======================
// Read the contents of R[t] and R[t2] and write to a 64-bit AArch32 System register.

impdef func AArch32_SysRegWrite64(cp_num : integer,
                                  instr : bits(32),
                                  t : integer,
                                  t2 : integer)
begin
    let (-, el) = <a link="func_ELFromM32_1" file="shared_pseudocode.xml">ELFromM32</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M);
    let opc1 = instr[4+:4];
    let CRm  = instr[0+:4];
end;</pstext></ps>
    <ps name="aarch32/functions/system/AArch32_SysRegWriteM" mylink="aarch32.functions.system.AArch32_SysRegWriteM" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_SysRegWriteM()
// ======================
// Read a value from a virtual address and write it to an AArch32 System register.

impdef func AArch32_SysRegWriteM(cp_num : integer, instr : bits(32), address : bits(32))
begin
    let CRd : bits(4) = instr[15:12];
end;</pstext></ps>
    <ps name="aarch32/functions/system/AArch32_WriteMode" mylink="aarch32.functions.system.AArch32_WriteMode" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_WriteMode()
// ===================
// Function for dealing with writes to PSTATE.M from AArch32 state only.
// This ensures that PSTATE.EL and PSTATE.SP are always valid.

func <anchor link="func_AArch32_WriteMode_1">AArch32_WriteMode</anchor>(mode : bits(5))
begin
    let (valid,el) : (boolean, bits(2)) = <a link="func_ELFromM32_1" file="shared_pseudocode.xml">ELFromM32</a>(mode);
    assert valid;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M   = mode;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL  = el;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.nRW = '1';
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SP  = (if mode IN {<a link="global_M32_User" file="shared_pseudocode.xml">M32_User</a>,<a link="global_M32_System" file="shared_pseudocode.xml">M32_System</a>} then '0' else '1');
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/system/AArch32_WriteModeByInstr" mylink="aarch32.functions.system.AArch32_WriteModeByInstr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_WriteModeByInstr()
// ==========================
// Function for dealing with writes to PSTATE.M from an AArch32 instruction, and ensuring that
// illegal state changes are correctly flagged in PSTATE.IL.

func <anchor link="func_AArch32_WriteModeByInstr_1">AArch32_WriteModeByInstr</anchor>(mode : bits(5))
begin
    var (valid,el) : (boolean, bits(2)) = <a link="func_ELFromM32_1" file="shared_pseudocode.xml">ELFromM32</a>(mode);

    // 'valid' is set to FALSE if' mode' is invalid for this implementation or the current value
    // of SCR.NS/SCR_EL3.NS. Additionally, it is illegal for an instruction to write 'mode' to
    // PSTATE.EL if it would result in any of:
    // * A change to a mode that would cause entry to a higher Exception level.
    if UInt(el) &gt; UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) then
        valid = FALSE;
    end;

    // * A change to or from Hyp mode.
    if (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M == <a link="global_M32_Hyp" file="shared_pseudocode.xml">M32_Hyp</a> || mode == <a link="global_M32_Hyp" file="shared_pseudocode.xml">M32_Hyp</a>) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M != mode then
        valid = FALSE;
    end;
    // * When EL2 is implemented, the value of HCR.TGE is '1', a change to a Non-secure EL1 mode.
    if (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M == <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a> &amp;&amp; <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; SCR().NS == '1'
            &amp;&amp; HCR().TGE == '1') then
        valid = FALSE;
    end;

    if !valid then
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL = '1';
    else
        <a link="func_AArch32_WriteMode_1" file="shared_pseudocode.xml">AArch32_WriteMode</a>(mode);
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/system/BadMode" mylink="aarch32.functions.system.BadMode" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BadMode()
// =========

readonly func <anchor link="func_BadMode_1">BadMode</anchor>(mode : bits(5)) =&gt; boolean
begin
    // Return TRUE if 'mode' encodes a mode that is not valid for this implementation
    var valid : boolean;
    case mode of
        when <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a> =&gt;
            valid = <a link="func_HaveAArch32EL_1" file="shared_pseudocode.xml">HaveAArch32EL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
        when <a link="global_M32_Hyp" file="shared_pseudocode.xml">M32_Hyp</a> =&gt;
            valid = <a link="func_HaveAArch32EL_1" file="shared_pseudocode.xml">HaveAArch32EL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
        when <a link="global_M32_FIQ" file="shared_pseudocode.xml">M32_FIQ</a>, <a link="global_M32_IRQ" file="shared_pseudocode.xml">M32_IRQ</a>, <a link="global_M32_Svc" file="shared_pseudocode.xml">M32_Svc</a>, <a link="global_M32_Abort" file="shared_pseudocode.xml">M32_Abort</a>, <a link="global_M32_Undef" file="shared_pseudocode.xml">M32_Undef</a>, <a link="global_M32_System" file="shared_pseudocode.xml">M32_System</a> =&gt;
            // If EL3 is implemented and using AArch32, then these modes are EL3 modes in Secure
            // state, and EL1 modes in Non-secure state. If EL3 is not implemented or is using
            // AArch64, then these modes are EL1 modes.
            // Therefore it is sufficient to test this implementation supports EL1 using AArch32
            valid = <a link="func_HaveAArch32EL_1" file="shared_pseudocode.xml">HaveAArch32EL</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>);
        when <a link="global_M32_User" file="shared_pseudocode.xml">M32_User</a> =&gt;
            valid = <a link="func_HaveAArch32EL_1" file="shared_pseudocode.xml">HaveAArch32EL</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>);
        otherwise =&gt;
            valid = FALSE;           // Passed an illegal mode value
    end;
    return !valid;
end;</pstext></ps>
    <ps name="aarch32/functions/system/BankedRegisterAccessValid" mylink="aarch32.functions.system.BankedRegisterAccessValid" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BankedRegisterAccessValid()
// ===========================
// Checks for MRS (Banked register) or MSR (Banked register) accesses to registers
// other than the SPSRs that are invalid. This includes ELR_hyp accesses.

func <anchor link="func_BankedRegisterAccessValid_2">BankedRegisterAccessValid</anchor>(SYSm : bits(5), mode : bits(5)) =&gt; (boolean, <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>)
begin
    var valid : boolean = TRUE;
    var c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>;
    var banked_unpred : boolean = FALSE;
    case SYSm of
        when '000xx', '00100' =&gt;                          // R8_usr to R12_usr
            banked_unpred = mode != <a link="global_M32_FIQ" file="shared_pseudocode.xml">M32_FIQ</a>;
        when '00101' =&gt;                                   // SP_usr
            banked_unpred = mode == <a link="global_M32_System" file="shared_pseudocode.xml">M32_System</a>;
        when '00110' =&gt;                                   // LR_usr
            banked_unpred = mode IN {<a link="global_M32_Hyp" file="shared_pseudocode.xml">M32_Hyp</a>,<a link="global_M32_System" file="shared_pseudocode.xml">M32_System</a>};
        when '010xx', '0110x', '01110' =&gt;                 // R8_fiq to R12_fiq, SP_fiq, LR_fiq
            banked_unpred = mode == <a link="global_M32_FIQ" file="shared_pseudocode.xml">M32_FIQ</a>;
        when '1000x' =&gt;                                   // LR_irq, SP_irq
            banked_unpred = mode == <a link="global_M32_IRQ" file="shared_pseudocode.xml">M32_IRQ</a>;
        when '1001x' =&gt;                                   // LR_svc, SP_svc
            banked_unpred = mode == <a link="global_M32_Svc" file="shared_pseudocode.xml">M32_Svc</a>;
        when '1010x' =&gt;                                   // LR_abt, SP_abt
            banked_unpred = mode == <a link="global_M32_Abort" file="shared_pseudocode.xml">M32_Abort</a>;
        when '1011x' =&gt;                                   // LR_und, SP_und
            banked_unpred = mode == <a link="global_M32_Undef" file="shared_pseudocode.xml">M32_Undef</a>;
        when '1110x' =&gt;                                   // LR_mon, SP_mon
            banked_unpred = (!<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() != <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> ||
                               mode == <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a>);
        when '11110' =&gt;                                   // ELR_hyp, only from Monitor or Hyp mode
            banked_unpred = !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) || ! mode IN {<a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a>,<a link="global_M32_Hyp" file="shared_pseudocode.xml">M32_Hyp</a>};
        when '11111' =&gt;                                   // SP_hyp, only from Monitor mode
            banked_unpred = !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) || mode != <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a>;
        otherwise =&gt;
            valid = FALSE;
            c     = ConstrainUnpredictable(<a link="enum_Unpredictable_UnimplementedRegister" file="shared_pseudocode.xml">Unpredictable_UnimplementedRegister</a>);
            assert c IN {<a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a>, <a link="enum_Constraint_NOP" file="shared_pseudocode.xml">Constraint_NOP</a>, <a link="enum_Constraint_ANYREG" file="shared_pseudocode.xml">Constraint_ANYREG</a>};
    end;

    if banked_unpred then
        valid = FALSE;
        c     = ConstrainUnpredictable(<a link="enum_Unpredictable_BankedRegister" file="shared_pseudocode.xml">Unpredictable_BankedRegister</a>);
        assert c IN {<a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a>, <a link="enum_Constraint_NOP" file="shared_pseudocode.xml">Constraint_NOP</a>, <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>};
    end;

    return (valid, c);
end;</pstext></ps>
    <ps name="aarch32/functions/system/CPSRWriteByInstr" mylink="aarch32.functions.system.CPSRWriteByInstr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CPSRWriteByInstr()
// ==================
// Update PSTATE.[N,Z,C,V,Q,GR,E,A,I,F,M] from a CPSR value written by an MSR instruction.

func <anchor link="func_CPSRWriteByInstr_2">CPSRWriteByInstr</anchor>(value : bits(32), bytemask : bits(4))
begin
    let privileged : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;        // PSTATE.[A,I,F,M] are not writable at EL0

    // Write PSTATE from 'value', ignoring bytes masked by 'bytemask'
    if bytemask[3] == '1' then
        PSTATE.[N,Z,C,V,Q] = value[31:27];
        // Bits [26:24] are ignored
    end;

    if bytemask[2] == '1' then
        if IsFeatureImplemented(FEAT_SSBS) then
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SSBS = value[23];
        end;
        if privileged then
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN = value[22];
        end;
        if IsFeatureImplemented(FEAT_DIT) then
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.DIT = value[21];
        end;
        // Bit [20] is RES0
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.GE = value[19:16];
    end;

    if bytemask[1] == '1' then
        // Bits [15:10] are RES0
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.E = value[9];                    // PSTATE.E is writable at EL0
        if privileged then
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.A = value[8];
        end;
    end;

    if bytemask[0] == '1' then
        if privileged then
            PSTATE.[I,F] = value[7:6];
            // Bit [5] is RES0
            // AArch32_WriteModeByInstr() sets PSTATE.IL to 1 if this is an illegal mode change.
            <a link="func_AArch32_WriteModeByInstr_1" file="shared_pseudocode.xml">AArch32_WriteModeByInstr</a>(value[4:0]);
        end;
    end;
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/system/ConditionPassed" mylink="aarch32.functions.system.ConditionPassed" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ConditionPassed()
// =================

func <anchor link="func_ConditionPassed_0">ConditionPassed</anchor>() =&gt; boolean
begin
    return <a link="func_ConditionHolds_1" file="shared_pseudocode.xml">ConditionHolds</a>(<a link="func_CurrentCond_0" file="shared_pseudocode.xml">CurrentCond</a>());
end;</pstext></ps>
    <ps name="aarch32/functions/system/CurrentCond" mylink="aarch32.functions.system.CurrentCond" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CurrentCond()
// =============
// Returns the condition code that applies to the currently executing instruction

impdef func <anchor link="func_CurrentCond_0">CurrentCond</anchor>() =&gt; bits(4)
begin
    return Zeros{4};
end;</pstext></ps>
    <ps name="aarch32/functions/system/InITBlock" mylink="aarch32.functions.system.InITBlock" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// InITBlock()
// ===========

func <anchor link="func_InITBlock_0">InITBlock</anchor>() =&gt; boolean
begin
    if <a link="func_CurrentInstrSet_0" file="shared_pseudocode.xml">CurrentInstrSet</a>() == <a link="enum_InstrSet_T32" file="shared_pseudocode.xml">InstrSet_T32</a> then
        return <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT[3:0] != '0000';
    else
        return FALSE;
    end;
end;</pstext></ps>
    <ps name="aarch32/functions/system/LastInITBlock" mylink="aarch32.functions.system.LastInITBlock" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// LastInITBlock()
// ===============

func <anchor link="func_LastInITBlock_0">LastInITBlock</anchor>() =&gt; boolean
begin
    return (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT[3:0] == '1000');
end;</pstext></ps>
    <ps name="aarch32/functions/system/SPSRWriteByInstr" mylink="aarch32.functions.system.SPSRWriteByInstr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPSRWriteByInstr()
// ==================

func <anchor link="func_SPSRWriteByInstr_2">SPSRWriteByInstr</anchor>(value : bits(32), bytemask : bits(4))
begin
    var new_spsr : bits(32) = <a link="accessor_SPSR_curr_0" file="shared_pseudocode.xml">SPSR_curr</a>();

    if bytemask[3] == '1' then
        new_spsr[31:24] = value[31:24];  // N, Z, C, V, Q flags, IT[1:0],J bits
    end;

    if bytemask[2] == '1' then
        new_spsr[23:16] = value[23:16];  // IL bit, GE[3:0] flags
    end;

    if bytemask[1] == '1' then
        new_spsr[15:8] = value[15:8];    // IT[7:2] bits, E bit, A interrupt mask
    end;

    if bytemask[0] == '1' then
        new_spsr[7:0] = value[7:0];      // I, F interrupt masks, T bit, Mode bits
    end;

    <a link="accessor_SPSR_curr_0" file="shared_pseudocode.xml">SPSR_curr</a>() = new_spsr;              // UNPREDICTABLE if User or System mode

    return;
end;</pstext></ps>
    <ps name="aarch32/functions/system/SPSRaccessValid" mylink="aarch32.functions.system.SPSRaccessValid" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPSRaccessValid()
// =================
// Checks for MRS (Banked register) or MSR (Banked register) accesses to the SPSRs
// that are UNPREDICTABLE

func <anchor link="func_SPSRaccessValid_2">SPSRaccessValid</anchor>(SYSm : bits(5), mode : bits(5)) =&gt; (boolean, <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>)
begin
    var valid : boolean = TRUE;
    var c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>;
    var banked_unpred : boolean = FALSE;
    case SYSm of
        when '01110' =&gt;                                                   // SPSR_fiq
            banked_unpred = mode == <a link="global_M32_FIQ" file="shared_pseudocode.xml">M32_FIQ</a>;
        when '10000' =&gt;                                                   // SPSR_irq
            banked_unpred = mode == <a link="global_M32_IRQ" file="shared_pseudocode.xml">M32_IRQ</a>;
        when '10010' =&gt;                                                   // SPSR_svc
            banked_unpred = mode == <a link="global_M32_Svc" file="shared_pseudocode.xml">M32_Svc</a>;
        when '10100' =&gt;                                                   // SPSR_abt
            banked_unpred = mode == <a link="global_M32_Abort" file="shared_pseudocode.xml">M32_Abort</a>;
        when '10110' =&gt;                                                   // SPSR_und
            banked_unpred = mode == <a link="global_M32_Undef" file="shared_pseudocode.xml">M32_Undef</a>;
        when '11100' =&gt;                                                   // SPSR_mon
            banked_unpred = (!<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || mode == <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a> ||
                               <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() != <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>);
        when '11110' =&gt;                                                   // SPSR_hyp
            banked_unpred = !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) || mode != <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a>;
        otherwise =&gt;
            valid = FALSE;
            c = ConstrainUnpredictable(<a link="enum_Unpredictable_UnimplementedRegister" file="shared_pseudocode.xml">Unpredictable_UnimplementedRegister</a>);
            assert c IN {<a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a>, <a link="enum_Constraint_NOP" file="shared_pseudocode.xml">Constraint_NOP</a>, <a link="enum_Constraint_ANYREG" file="shared_pseudocode.xml">Constraint_ANYREG</a>};
    end;

    if banked_unpred then
        valid = FALSE;
        c     = ConstrainUnpredictable(<a link="enum_Unpredictable_BankedRegister" file="shared_pseudocode.xml">Unpredictable_BankedRegister</a>);
        assert c IN {<a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a>, <a link="enum_Constraint_NOP" file="shared_pseudocode.xml">Constraint_NOP</a>, <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>};
    end;

    return (valid, c);
end;</pstext></ps>
    <ps name="aarch32/functions/system/SelectInstrSet" mylink="aarch32.functions.system.SelectInstrSet" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SelectInstrSet()
// ================

func <anchor link="func_SelectInstrSet_1">SelectInstrSet</anchor>(iset : <a link="type_InstrSet" file="shared_pseudocode.xml">InstrSet</a>)
begin
    assert <a link="func_CurrentInstrSet_0" file="shared_pseudocode.xml">CurrentInstrSet</a>() IN {<a link="enum_InstrSet_A32" file="shared_pseudocode.xml">InstrSet_A32</a>, <a link="enum_InstrSet_T32" file="shared_pseudocode.xml">InstrSet_T32</a>};
    assert iset IN {<a link="enum_InstrSet_A32" file="shared_pseudocode.xml">InstrSet_A32</a>, <a link="enum_InstrSet_T32" file="shared_pseudocode.xml">InstrSet_T32</a>};

    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T = if iset == <a link="enum_InstrSet_A32" file="shared_pseudocode.xml">InstrSet_A32</a> then '0' else '1';

    return;
end;</pstext></ps>
    <ps name="aarch32/functions/tlbi/AArch32_DTLBI_ALL" mylink="aarch32.functions.tlbi.AArch32_DTLBI_ALL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_DTLBI_ALL()
// ===================
// Invalidate all data TLB entries for the indicated translation regime with the
// the indicated security state for all TLBs within the indicated broadcast domain.
// Invalidation applies to all applicable stage 1 and stage 2 entries.

func <anchor link="func_AArch32_DTLBI_ALL_5">AArch32_DTLBI_ALL</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid : bits(NUM_VMIDBITS),
                       broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>)
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    let broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = <a link="func_AArch32_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch32_EffectiveBroadcast</a>(broadcast_in);
    if <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_DALL" file="shared_pseudocode.xml">TLBIOp_DALL</a>;
    r.from_aarch64 = FALSE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.level        = <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a>;
    r.attr         = attr;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/tlbi/AArch32_DTLBI_ASID" mylink="aarch32.functions.tlbi.AArch32_DTLBI_ASID" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_DTLBI_ASID()
// ====================
// Invalidate all data TLB stage 1 entries matching the indicated VMID (where regime supports)
// and ASID in the parameter Rt in the indicated translation regime with the
// indicated security state for all TLBs within the indicated broadcast domain.
// Note: stage 1 and stage 2 combined entries are in the scope of this operation.

func <anchor link="func_AArch32_DTLBI_ASID_6">AArch32_DTLBI_ASID</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid : bits(NUM_VMIDBITS),
                        broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>, Rt : bits(32))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    let broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = <a link="func_AArch32_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch32_EffectiveBroadcast</a>(broadcast_in);
    if <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_DASID" file="shared_pseudocode.xml">TLBIOp_DASID</a>;
    r.from_aarch64 = FALSE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.level        = <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a>;
    r.attr         = attr;
    r.asid         = Zeros{8} :: Rt[7:0];

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/tlbi/AArch32_DTLBI_VA" mylink="aarch32.functions.tlbi.AArch32_DTLBI_VA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_DTLBI_VA()
// ==================
// Invalidate by VA all stage 1 data TLB entries in the indicated broadcast domain
// matching the indicated VMID and ASID (where regime supports VMID, ASID) in the indicated regime
// with the indicated security state.
// ASID, VA and related parameters are derived from Rt.
// Note: stage 1 and stage 2 combined entries are in the scope of this operation.

func <anchor link="func_AArch32_DTLBI_VA_7">AArch32_DTLBI_VA</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid : bits(NUM_VMIDBITS),
                      broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>,  attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
                      Rt : bits(32))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    let broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = <a link="func_AArch32_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch32_EffectiveBroadcast</a>(broadcast_in);
    if <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_DVA" file="shared_pseudocode.xml">TLBIOp_DVA</a>;
    r.from_aarch64 = FALSE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.level        = level;
    r.attr         = attr;
    r.asid         = Zeros{8} :: Rt[7:0];
    r.address      = Zeros{32} :: Rt[31:12] :: Zeros{12};

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/tlbi/AArch32_EffectiveBroadcast" mylink="aarch32.functions.tlbi.AArch32_EffectiveBroadcast" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_EffectiveBroadcast()
// ============================

func <anchor link="func_AArch32_EffectiveBroadcast_1">AArch32_EffectiveBroadcast</anchor>(broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>) =&gt; <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>
begin
    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = broadcast_in;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> then return broadcast; end;

    if (broadcast == <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> &amp;&amp; ((<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; HCR().FB == '1') ||
          (!<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; HCR_EL2().FB == '1'))) then
        broadcast = <a link="enum_Broadcast_ForcedISH" file="shared_pseudocode.xml">Broadcast_ForcedISH</a>;
    end;

    return broadcast;
end;</pstext></ps>
    <ps name="aarch32/functions/tlbi/AArch32_ITLBI_ALL" mylink="aarch32.functions.tlbi.AArch32_ITLBI_ALL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ITLBI_ALL()
// ===================
// Invalidate all instruction TLB entries for the indicated translation regime with the
// the indicated security state for all TLBs within the indicated broadcast domain.
// Invalidation applies to all applicable stage 1 and stage 2 entries.

func <anchor link="func_AArch32_ITLBI_ALL_5">AArch32_ITLBI_ALL</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid : bits(NUM_VMIDBITS),
                       broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>)
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    let broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = <a link="func_AArch32_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch32_EffectiveBroadcast</a>(broadcast_in);
    if <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_IALL" file="shared_pseudocode.xml">TLBIOp_IALL</a>;
    r.from_aarch64 = FALSE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.level        = <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a>;
    r.attr         = attr;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/tlbi/AArch32_ITLBI_ASID" mylink="aarch32.functions.tlbi.AArch32_ITLBI_ASID" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ITLBI_ASID()
// ====================
// Invalidate all instruction TLB stage 1 entries matching the indicated VMID
// (where regime supports) and ASID in the parameter Rt in the indicated translation
// regime with the indicated security state for all TLBs within the indicated broadcast domain.
// Note: stage 1 and stage 2 combined entries are in the scope of this operation.

func <anchor link="func_AArch32_ITLBI_ASID_6">AArch32_ITLBI_ASID</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid : bits(NUM_VMIDBITS),
                        broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>, Rt : bits(32))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    let broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = <a link="func_AArch32_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch32_EffectiveBroadcast</a>(broadcast_in);
    if <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_IASID" file="shared_pseudocode.xml">TLBIOp_IASID</a>;
    r.from_aarch64 = FALSE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.level        = <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a>;
    r.attr         = attr;
    r.asid         = Zeros{8} :: Rt[7:0];

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/tlbi/AArch32_ITLBI_VA" mylink="aarch32.functions.tlbi.AArch32_ITLBI_VA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_ITLBI_VA()
// ==================
// Invalidate by VA all stage 1 instruction TLB entries in the indicated broadcast domain
// matching the indicated VMID and ASID (where regime supports VMID, ASID) in the indicated regime
// with the indicated security state.
// ASID, VA and related parameters are derived from Rt.
// Note: stage 1 and stage 2 combined entries are in the scope of this operation.

func <anchor link="func_AArch32_ITLBI_VA_7">AArch32_ITLBI_VA</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid : bits(NUM_VMIDBITS),
                      broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>,  attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
                      Rt : bits(32))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    let broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = <a link="func_AArch32_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch32_EffectiveBroadcast</a>(broadcast_in);
    if <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_IVA" file="shared_pseudocode.xml">TLBIOp_IVA</a>;
    r.from_aarch64 = FALSE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.level        = level;
    r.attr         = attr;
    r.asid         = Zeros{8} :: Rt[7:0];
    r.address      = Zeros{32} :: Rt[31:12] :: Zeros{12};

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/tlbi/AArch32_TLBI_ALL" mylink="aarch32.functions.tlbi.AArch32_TLBI_ALL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TLBI_ALL()
// ==================
// Invalidate all entries for the indicated translation regime with the
// the indicated security state for all TLBs within the indicated broadcast domain.
// Invalidation applies to all applicable stage 1 and stage 2 entries.

func <anchor link="func_AArch32_TLBI_ALL_4">AArch32_TLBI_ALL</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
                      broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>)
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>};

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_ALL" file="shared_pseudocode.xml">TLBIOp_ALL</a>;
    r.from_aarch64 = FALSE;
    r.security     = security;
    r.regime       = regime;
    r.level        = <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a>;
    r.attr         = attr;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/tlbi/AArch32_TLBI_ASID" mylink="aarch32.functions.tlbi.AArch32_TLBI_ASID" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TLBI_ASID()
// ===================
// Invalidate all stage 1 entries matching the indicated VMID (where regime supports)
// and ASID in the parameter Rt in the indicated translation regime with the
// indicated security state for all TLBs within the indicated broadcast domain.
// Note: stage 1 and stage 2 combined entries are in the scope of this operation.

func <anchor link="func_AArch32_TLBI_ASID_6">AArch32_TLBI_ASID</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid : bits(NUM_VMIDBITS),
                       broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>, Rt : bits(32))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    let broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = <a link="func_AArch32_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch32_EffectiveBroadcast</a>(broadcast_in);
    if <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_ASID" file="shared_pseudocode.xml">TLBIOp_ASID</a>;
    r.from_aarch64 = FALSE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.level        = <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a>;
    r.attr         = attr;
    r.asid         = Zeros{8} :: Rt[7:0];

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/tlbi/AArch32_TLBI_IPAS2" mylink="aarch32.functions.tlbi.AArch32_TLBI_IPAS2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TLBI_IPAS2()
// ====================
// Invalidate by IPA all stage 2 only TLB entries in the indicated broadcast
// domain matching the indicated VMID in the indicated regime with the indicated security state.
// Note: stage 1 and stage 2 combined entries are not in the scope of this operation.
// IPA and related parameters of the are derived from Rt.

func <anchor link="func_AArch32_TLBI_IPAS2_7">AArch32_TLBI_IPAS2</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid : bits(NUM_VMIDBITS),
                        broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>, attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>, Rt : bits(32))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>};
    assert security == <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a>;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_IPAS2" file="shared_pseudocode.xml">TLBIOp_IPAS2</a>;
    r.from_aarch64 = FALSE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = TRUE;
    r.level        = level;
    r.attr         = attr;
    r.address      = Zeros{24} :: Rt[27:0] :: Zeros{12};
    r.ipaspace     = <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/tlbi/AArch32_TLBI_VA" mylink="aarch32.functions.tlbi.AArch32_TLBI_VA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TLBI_VA()
// =================
// Invalidate by VA all stage 1 TLB entries in the indicated broadcast domain
// matching the indicated VMID and ASID (where regime supports VMID, ASID) in the indicated regime
// with the indicated security state.
// ASID, VA and related parameters are derived from Rt.
// Note: stage 1 and stage 2 combined entries are in the scope of this operation.

func <anchor link="func_AArch32_TLBI_VA_7">AArch32_TLBI_VA</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid : bits(NUM_VMIDBITS),
                     broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>,  attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
                     Rt : bits(32))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    let broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = <a link="func_AArch32_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch32_EffectiveBroadcast</a>(broadcast_in);
    if <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_VA" file="shared_pseudocode.xml">TLBIOp_VA</a>;
    r.from_aarch64 = FALSE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.level        = level;
    r.attr         = attr;
    r.asid         = Zeros{8} :: Rt[7:0];
    r.address      = Zeros{32} :: Rt[31:12] :: Zeros{12};

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/tlbi/AArch32_TLBI_VAA" mylink="aarch32.functions.tlbi.AArch32_TLBI_VAA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TLBI_VAA()
// ==================
// Invalidate by VA all stage 1 TLB entries in the indicated broadcast domain
// matching the indicated VMID (where regime supports VMID) and all ASID in the indicated regime
// with the indicated security state.
// VA and related parameters are derived from Rt.
// Note: stage 1 and stage 2 combined entries are in the scope of this operation.

func <anchor link="func_AArch32_TLBI_VAA_7">AArch32_TLBI_VAA</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid : bits(NUM_VMIDBITS),
                      broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>, attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
                      Rt : bits(32))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    let broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = <a link="func_AArch32_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch32_EffectiveBroadcast</a>(broadcast_in);
    if <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_VAA" file="shared_pseudocode.xml">TLBIOp_VAA</a>;
    r.from_aarch64 = FALSE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.level        = level;
    r.attr         = attr;
    r.address      = Zeros{32} :: Rt[31:12] :: Zeros{12};

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/tlbi/AArch32_TLBI_VMALL" mylink="aarch32.functions.tlbi.AArch32_TLBI_VMALL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TLBI_VMALL()
// ====================
// Invalidate all stage 1 entries for the indicated translation regime with the
// the indicated security state for all TLBs within the indicated broadcast
// domain that match the indicated VMID (where applicable).
// Note: stage 1 and stage 2 combined entries are in the scope of this operation.
// Note: stage 2 only entries are not in the scope of this operation.

func <anchor link="func_AArch32_TLBI_VMALL_5">AArch32_TLBI_VMALL</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid : bits(NUM_VMIDBITS),
                        broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>)
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    let broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = <a link="func_AArch32_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch32_EffectiveBroadcast</a>(broadcast_in);
    if <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_VMALL" file="shared_pseudocode.xml">TLBIOp_VMALL</a>;
    r.from_aarch64 = FALSE;
    r.security     = security;
    r.regime       = regime;
    r.level        = <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a>;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.attr         = attr;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/tlbi/AArch32_TLBI_VMALLS12" mylink="aarch32.functions.tlbi.AArch32_TLBI_VMALLS12" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TLBI_VMALLS12()
// =======================
// Invalidate all stage 1 and stage 2 entries for the indicated translation
// regime with the indicated security state for all TLBs within the indicated
// broadcast domain that match the indicated VMID.

func <anchor link="func_AArch32_TLBI_VMALLS12_5">AArch32_TLBI_VMALLS12</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid : bits(NUM_VMIDBITS),
                           broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>)
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>};

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_VMALLS12" file="shared_pseudocode.xml">TLBIOp_VMALLS12</a>;
    r.from_aarch64 = FALSE;
    r.security     = security;
    r.regime       = regime;
    r.level        = <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a>;
    r.vmid         = vmid;
    r.use_vmid     = TRUE;
    r.attr         = attr;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch32/functions/v6simd/Sat" mylink="aarch32.functions.v6simd.Sat" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Sat()
// =====

func <anchor link="func_Sat_3">Sat</anchor>{N}(i : integer, unsigned : boolean) =&gt; bits(N)
begin
    let result : bits(N) = if unsigned then <a link="func_UnsignedSat_2" file="shared_pseudocode.xml">UnsignedSat</a>{N}(i) else <a link="func_SignedSat_2" file="shared_pseudocode.xml">SignedSat</a>{N}(i);
    return result;
end;</pstext></ps>
    <ps name="aarch32/ic/AArch32_CanTrapIC" mylink="aarch32.ic.AArch32_CanTrapIC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CanTrapIC()
// ===================
// Determines whether the execution of the IC instruction can be trapped.

func <anchor link="func_AArch32_CanTrapIC_2">AArch32_CanTrapIC</anchor>(cacheop : <a link="type_CacheOp" file="shared_pseudocode.xml">CacheOp</a>, opscope : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a>) =&gt; boolean
begin
    return (!<a link="func_AArch32_TreatICAsNOP_2" file="shared_pseudocode.xml">AArch32_TreatICAsNOP</a>(cacheop, opscope) || ImpDefBool(
            &quot;When IC is treated as NOP, data cache maintenance operations are trapped&quot;));
end;</pstext></ps>
    <ps name="aarch32/ic/AArch32_IC" mylink="aarch32.ic.AArch32_IC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_IC()
// ============
// Perform Instruction Cache Operation.

func <anchor link="func_AArch32_IC_1">AArch32_IC</anchor>(opscope : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a>)
begin
    let regval : bits(32) = ARBITRARY : bits(32);
    <a link="func_AArch32_IC_2" file="shared_pseudocode.xml">AArch32_IC</a>(regval, opscope);
end;

// AArch32_IC()
// ============
// Perform Instruction Cache Operation.

func <anchor link="func_AArch32_IC_2">AArch32_IC</anchor>(regval : bits(32), opscope : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a>)
begin
    var cache : <a link="type_CacheRecord" file="shared_pseudocode.xml">CacheRecord</a>;

    cache.acctype   = <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>;
    cache.cachetype = <a link="enum_CacheType_Instruction" file="shared_pseudocode.xml">CacheType_Instruction</a>;
    cache.cacheop   = <a link="enum_CacheOp_Invalidate" file="shared_pseudocode.xml">CacheOp_Invalidate</a>;
    cache.opscope   = opscope;
    cache.security  = <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);

    if opscope IN {<a link="enum_CacheOpScope_ALLU" file="shared_pseudocode.xml">CacheOpScope_ALLU</a>, <a link="enum_CacheOpScope_ALLUIS" file="shared_pseudocode.xml">CacheOpScope_ALLUIS</a>} then
        if (opscope == <a link="enum_CacheOpScope_ALLUIS" file="shared_pseudocode.xml">CacheOpScope_ALLUIS</a> ||
              <a link="func_AArch32_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch32_EffectiveBroadcast</a>(<a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a>) == <a link="enum_Broadcast_ForcedISH" file="shared_pseudocode.xml">Broadcast_ForcedISH</a>) then
            cache.shareability = <a link="enum_Shareability_ISH" file="shared_pseudocode.xml">Shareability_ISH</a>;
        else
            cache.shareability = <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a>;
        end;
        cache.regval = ZeroExtend{64}(regval);
        CACHE_OP(cache);
    else
        assert opscope == <a link="enum_CacheOpScope_PoU" file="shared_pseudocode.xml">CacheOpScope_PoU</a>;

        if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
            if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} then
                cache.is_vmid_valid = TRUE;
                cache.vmid          = <a link="func_VMID_0" file="shared_pseudocode.xml">VMID</a>();
            else
                cache.is_vmid_valid = FALSE;
            end;
        else
            cache.is_vmid_valid = FALSE;
        end;

        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
            cache.is_asid_valid = TRUE;
            cache.asid          = <a link="func_ASID_0" file="shared_pseudocode.xml">ASID</a>();
        else
            cache.is_asid_valid = FALSE;
        end;

        cache.shareability = <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a>;
        cache.vaddress     = ZeroExtend{64}(regval);

        let size : integer    = 0;
        let aligned : boolean = TRUE;
        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescIC_1" file="shared_pseudocode.xml">CreateAccDescIC</a>(cache);
        let memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_AArch32_TranslateAddress_4" file="shared_pseudocode.xml">AArch32_TranslateAddress</a>(regval, accdesc, aligned,
                                                                          size);
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
            <a link="func_AArch32_Abort_1" file="shared_pseudocode.xml">AArch32_Abort</a>(memaddrdesc.fault);
        end;

        cache.paddress = memaddrdesc.paddress;
        CACHE_OP(cache);
    end;
    return;
end;</pstext></ps>
    <ps name="aarch32/ic/AArch32_TreatICAsNOP" mylink="aarch32.ic.AArch32_TreatICAsNOP" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TreatICAsNOP()
// ======================
// Determines whether the execution of the IC instruction is treated as a NOP.

func <anchor link="func_AArch32_TreatICAsNOP_2">AArch32_TreatICAsNOP</anchor>(cacheop : <a link="type_CacheOp" file="shared_pseudocode.xml">CacheOp</a>, opscope : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a>) =&gt; boolean
begin
    if CTR().DIC == '1' then
        return ImpDefBool(&quot;IC is treated as NOP&quot;);
    end;

    return FALSE;
end;</pstext></ps>
    <ps name="aarch32/predictionrestrict/AArch32_RestrictPrediction" mylink="aarch32.predictionrestrict.AArch32_RestrictPrediction" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_RestrictPrediction()
// ============================
// Clear all predictions in the context.

func <anchor link="func_AArch32_RestrictPrediction_2">AArch32_RestrictPrediction</anchor>(val : bits(32), restriction : <a link="type_RestrictType" file="shared_pseudocode.xml">RestrictType</a>)
begin

    var c : <a link="type_ExecutionCntxt" file="shared_pseudocode.xml">ExecutionCntxt</a>;
    let target_el : bits(2) = val[25:24];

    // If the target EL is not implemented or the instruction is executed at an
    // EL lower than the specified level, the instruction is treated as a NOP.
    if !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(target_el) || UInt(target_el) &gt; UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) then <a link="func_ExecuteAsNOP_0" file="shared_pseudocode.xml">ExecuteAsNOP</a>(); end;

    let ns : bit  = val[26];
    let nse : bit = ARBITRARY : bit;
    let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_TargetSecurityState_2" file="shared_pseudocode.xml">TargetSecurityState</a>(ns, nse);

    c.security  = ss;
    c.target_el = target_el;

    if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} then
            c.is_vmid_valid = TRUE;
            c.all_vmid      = FALSE;
            c.vmid          = <a link="func_VMID_0" file="shared_pseudocode.xml">VMID</a>();

        elsif target_el IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} then
            c.is_vmid_valid = TRUE;
            c.all_vmid      = val[27] == '1';
            c.vmid          = ZeroExtend{NUM_VMIDBITS}(val[23:16]);// Only valid if  val[27] == '0'
        else
            c.is_vmid_valid = FALSE;
        end;
    else
        c.is_vmid_valid = FALSE;
    end;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        c.is_asid_valid = TRUE;
        c.all_asid      = FALSE;
        c.asid          = <a link="func_ASID_0" file="shared_pseudocode.xml">ASID</a>();

    elsif target_el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        c.is_asid_valid = TRUE;
        c.all_asid      = val[8] == '1';
        c.asid          = ZeroExtend{NUM_ASIDBITS}(val[7:0]);      // Only valid if  val[8] == '0'

    else
        c.is_asid_valid = FALSE;
    end;

    c.restriction = restriction;
    RESTRICT_PREDICTIONS(c);
end;</pstext></ps>
    <ps name="aarch32/translation/attrs/AArch32_DefaultTEXDecode" mylink="aarch32.translation.attrs.AArch32_DefaultTEXDecode" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_DefaultTEXDecode()
// ==========================
// Apply short-descriptor format memory region attributes, without TEX remap

func <anchor link="func_AArch32_DefaultTEXDecode_4">AArch32_DefaultTEXDecode</anchor>(TEX_in : bits(3), c_in : bit, b_in : bit, s : bit) =&gt; <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>
begin
    var memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>;
    var TEX : bits(3) = TEX_in;
    var c : bit = c_in;
    var b : bit = b_in;

    // Reserved values map to allocated values
    if (TEX == '001' &amp;&amp; c::b == '01') || (TEX == '010' &amp;&amp; c::b != '00') || TEX == '011' then
        var texcb : bits(5);
        (-, texcb) = ConstrainUnpredictableBits{5}(<a link="enum_Unpredictable_RESTEXCB" file="shared_pseudocode.xml">Unpredictable_RESTEXCB</a>);
        TEX = texcb[4:2];  c = texcb[1];  b = texcb[0];
    end;

    // Distinction between Inner Shareable and Outer Shareable is not supported in this format
    // A memory region is either Non-shareable or Outer Shareable
    case TEX::c::b of
        when '00000' =&gt;
            // Device-nGnRnE
            memattrs.memtype      = <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a>;
            memattrs.device       = <a link="enum_DeviceType_nGnRnE" file="shared_pseudocode.xml">DeviceType_nGnRnE</a>;
            memattrs.shareability = <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
        when '00001', '01000' =&gt;
            // Device-nGnRE
            memattrs.memtype      = <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a>;
            memattrs.device       = <a link="enum_DeviceType_nGnRE" file="shared_pseudocode.xml">DeviceType_nGnRE</a>;
            memattrs.shareability = <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
        when '00010' =&gt;
            // Write-through Read allocate
            memattrs.memtype      = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
            memattrs.inner.attrs  = <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a>;
            memattrs.inner.hints  = <a link="global_MemHint_RA" file="shared_pseudocode.xml">MemHint_RA</a>;
            memattrs.outer.attrs  = <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a>;
            memattrs.outer.hints  = <a link="global_MemHint_RA" file="shared_pseudocode.xml">MemHint_RA</a>;
            memattrs.shareability = if s == '1' then <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a> else <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a>;
        when '00011' =&gt;
            // Write-back Read allocate
            memattrs.memtype      = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
            memattrs.inner.attrs  = <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>;
            memattrs.inner.hints  = <a link="global_MemHint_RA" file="shared_pseudocode.xml">MemHint_RA</a>;
            memattrs.outer.attrs  = <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>;
            memattrs.outer.hints  = <a link="global_MemHint_RA" file="shared_pseudocode.xml">MemHint_RA</a>;
            memattrs.shareability = if s == '1' then <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a> else <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a>;
        when '00100' =&gt;
            // Non-cacheable
            memattrs.memtype      = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
            memattrs.inner.attrs  = <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>;
            memattrs.outer.attrs  = <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>;
            memattrs.shareability = <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
        when '00110' =&gt;
            memattrs = ImpDefMemoryAttributes(&quot;IMPLEMENTATION_DEFINED&quot;);
        when '00111' =&gt;
            // Write-back Read and Write allocate
            memattrs.memtype      = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
            memattrs.inner.attrs  = <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>;
            memattrs.inner.hints  = <a link="global_MemHint_RWA" file="shared_pseudocode.xml">MemHint_RWA</a>;
            memattrs.outer.attrs  = <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>;
            memattrs.outer.hints  = <a link="global_MemHint_RWA" file="shared_pseudocode.xml">MemHint_RWA</a>;
            memattrs.shareability = if s == '1' then <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a> else <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a>;
        when '1xxxx' =&gt;
            // Cacheable, TEX[1:0] = Outer attrs, {c,b} = Inner attrs
            memattrs.memtype = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
            memattrs.inner   = <a link="func_DecodeSDFAttr_1" file="shared_pseudocode.xml">DecodeSDFAttr</a>(c::b);
            memattrs.outer   = <a link="func_DecodeSDFAttr_1" file="shared_pseudocode.xml">DecodeSDFAttr</a>(TEX[1:0]);

            if memattrs.inner.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> &amp;&amp; memattrs.outer.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> then
                memattrs.shareability = <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
            else
                memattrs.shareability = if s == '1' then <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a> else <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a>;
            end;
        otherwise =&gt;
            // Reserved, handled above
            unreachable;
    end;

    // The Transient hint is not supported in this format
    memattrs.inner.transient = FALSE;
    memattrs.outer.transient = FALSE;
    memattrs.tags            = <a link="enum_MemTag_Untagged" file="shared_pseudocode.xml">MemTag_Untagged</a>;

    if memattrs.inner.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a> &amp;&amp; memattrs.outer.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a> then
        memattrs.xs = '0';
    else
        memattrs.xs = '1';
    end;

    return memattrs;
end;</pstext></ps>
    <ps name="aarch32/translation/attrs/AArch32_MAIRAttr" mylink="aarch32.translation.attrs.AArch32_MAIRAttr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_MAIRAttr()
// ==================
// Retrieve the memory attribute encoding indexed in the given MAIR

func <anchor link="func_AArch32_MAIRAttr_2">AArch32_MAIRAttr</anchor>(index : integer, mair : bits(64)) =&gt; bits(8)
begin
    assert (index &lt; 8);
    return mair[index*:8];
end;</pstext></ps>
    <ps name="aarch32/translation/attrs/AArch32_RemappedTEXDecode" mylink="aarch32.translation.attrs.AArch32_RemappedTEXDecode" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_RemappedTEXDecode()
// ===========================
// Apply short-descriptor format memory region attributes, with TEX remap

func <anchor link="func_AArch32_RemappedTEXDecode_5">AArch32_RemappedTEXDecode</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, TEX : bits(3),
                               c : bit, b : bit, s : bit) =&gt; <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>
begin

    var memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>;
    var prrr : PRRR_Type;
    var nmrr : NMRR_Type;

    let region : integer{} = UInt(TEX[0]::c::b);   // TEX[2:1] are ignored in this mapping scheme
    if region == 6 then
        return ImpDefMemoryAttributes(&quot;IMPLEMENTATION_DEFINED&quot;);
    end;

    if regime == <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a> then
        prrr = PRRR_S();
        nmrr = NMRR_S();
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        prrr = PRRR_NS();
        nmrr = NMRR_NS();
    else
        prrr = PRRR();
        nmrr = NMRR();
    end;

    let base : integer{} = 2 * region;
    var attrfield : bits(2) = prrr[region*:2];

    if attrfield == '11' then      // Reserved, maps to allocated value
        (-, attrfield) = ConstrainUnpredictableBits{2}(<a link="enum_Unpredictable_RESPRRR" file="shared_pseudocode.xml">Unpredictable_RESPRRR</a>);
    end;

    case attrfield of
        when '00' =&gt;                  // Device-nGnRnE
            memattrs.memtype      = <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a>;
            memattrs.device       = <a link="enum_DeviceType_nGnRnE" file="shared_pseudocode.xml">DeviceType_nGnRnE</a>;
            memattrs.shareability = <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
        when '01' =&gt;                  // Device-nGnRE
            memattrs.memtype      = <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a>;
            memattrs.device       = <a link="enum_DeviceType_nGnRE" file="shared_pseudocode.xml">DeviceType_nGnRE</a>;
            memattrs.shareability = <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
        when '10' =&gt;
            let NSn : bit  = if s == '0' then prrr.NS0 else prrr.NS1;
            let NOSm : bit = prrr[region+24] AND NSn;
            let IRn : bits(2)  = nmrr[base+1:base];
            let ORn : bits(2)  = nmrr[base+17:base+16];

            memattrs.memtype = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
            memattrs.inner   = <a link="func_DecodeSDFAttr_1" file="shared_pseudocode.xml">DecodeSDFAttr</a>(IRn);
            memattrs.outer   = <a link="func_DecodeSDFAttr_1" file="shared_pseudocode.xml">DecodeSDFAttr</a>(ORn);
            if memattrs.inner.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> &amp;&amp; memattrs.outer.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> then
                memattrs.shareability = <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
            else
                let sh : bits(2) = NSn::NOSm;
                memattrs.shareability = <a link="func_DecodeShareability_1" file="shared_pseudocode.xml">DecodeShareability</a>(sh);
            end;
        when '11' =&gt;
            unreachable;
    end;

    // The Transient hint is not supported in this format
    memattrs.inner.transient = FALSE;
    memattrs.outer.transient = FALSE;
    memattrs.tags            = <a link="enum_MemTag_Untagged" file="shared_pseudocode.xml">MemTag_Untagged</a>;

    if memattrs.inner.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a> &amp;&amp; memattrs.outer.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a> then
        memattrs.xs = '0';
    else
        memattrs.xs = '1';
    end;

    return memattrs;
end;</pstext></ps>
    <ps name="aarch32/translation/debug/AArch32_CheckBreakpoint" mylink="aarch32.translation.debug.AArch32_CheckBreakpoint" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CheckBreakpoint()
// =========================
// Called before executing the instruction of length &quot;size&quot; bytes at &quot;vaddress&quot; in an AArch32
// translation regime, when either debug exceptions are enabled, or halting debug is enabled
// and halting is allowed.

func <anchor link="func_AArch32_CheckBreakpoint_4">AArch32_CheckBreakpoint</anchor>(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, vaddress : bits(32),
                             accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>, size : integer) =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin
    assert <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>());
    assert size IN {2,4};

    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;
    var match : boolean = FALSE;
    var mismatch : boolean = FALSE;
    var brkptinfo : <a link="type_BreakpointInfo" file="shared_pseudocode.xml">BreakpointInfo</a>;

    for i = 0 to <a link="func_NumBreakpointsImplemented_0" file="shared_pseudocode.xml">NumBreakpointsImplemented</a>() - 1 do
        brkptinfo = <a link="func_AArch32_BreakpointMatch_4" file="shared_pseudocode.xml">AArch32_BreakpointMatch</a>(i, vaddress, accdesc, size);
        match = match || brkptinfo.match;
        mismatch = mismatch || brkptinfo.mismatch;
    end;

    if match &amp;&amp; <a link="func_HaltOnBreakpointOrWatchpoint_0" file="shared_pseudocode.xml">HaltOnBreakpointOrWatchpoint</a>() then
        let reason : bits(6) = <a link="global_DebugHalt_Breakpoint" file="shared_pseudocode.xml">DebugHalt_Breakpoint</a>;
        <a link="func_Halt_1" file="shared_pseudocode.xml">Halt</a>(reason);
    elsif (match || mismatch) then
        fault.statuscode = <a link="enum_Fault_Debug" file="shared_pseudocode.xml">Fault_Debug</a>;
        fault.debugmoe   = <a link="global_DebugException_Breakpoint" file="shared_pseudocode.xml">DebugException_Breakpoint</a>;
        fault.vaddress   = ZeroExtend{64}(vaddress);
    end;

    return fault;
end;</pstext></ps>
    <ps name="aarch32/translation/debug/AArch32_CheckDebug" mylink="aarch32.translation.debug.AArch32_CheckDebug" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CheckDebug()
// ====================
// Called on each access to check for a debug exception or entry to Debug state.

func <anchor link="func_AArch32_CheckDebug_3">AArch32_CheckDebug</anchor>(vaddress : bits(32), accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                        size : integer) =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin

    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_2" file="shared_pseudocode.xml">NoFault</a>(accdesc, ZeroExtend{64}(vaddress));

    let d_side : boolean = <a link="func_IsWatchpointableAccess_1" file="shared_pseudocode.xml">IsWatchpointableAccess</a>(accdesc);
    let i_side : boolean = (accdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a>);
    let generate_exception : boolean = (<a link="func_AArch32_GenerateDebugExceptions_0" file="shared_pseudocode.xml">AArch32_GenerateDebugExceptions</a>() &amp;&amp;
                                            DBGDSCRext().MDBGen == '1');
    let halt : boolean = <a link="func_HaltOnBreakpointOrWatchpoint_0" file="shared_pseudocode.xml">HaltOnBreakpointOrWatchpoint</a>();
    // Relative priority of Vector Catch and Breakpoint exceptions not defined in the architecture
    let vector_catch_first : boolean = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BPVECTORCATCHPRI" file="shared_pseudocode.xml">Unpredictable_BPVECTORCATCHPRI</a>);

    if i_side &amp;&amp; vector_catch_first &amp;&amp; generate_exception then
        fault = <a link="func_AArch32_CheckVectorCatch_3" file="shared_pseudocode.xml">AArch32_CheckVectorCatch</a>(fault, vaddress, size);
    end;

    if fault.statuscode == <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> &amp;&amp; (generate_exception || halt) then
        if d_side then
            fault = <a link="func_AArch32_CheckWatchpoint_4" file="shared_pseudocode.xml">AArch32_CheckWatchpoint</a>(fault, vaddress, accdesc, size);
        elsif i_side then
            fault = <a link="func_AArch32_CheckBreakpoint_4" file="shared_pseudocode.xml">AArch32_CheckBreakpoint</a>(fault, vaddress, accdesc, size);
        end;
    end;

    if fault.statuscode == <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> &amp;&amp; i_side &amp;&amp; !vector_catch_first &amp;&amp; generate_exception then
        return <a link="func_AArch32_CheckVectorCatch_3" file="shared_pseudocode.xml">AArch32_CheckVectorCatch</a>(fault, vaddress, size);
    end;

    return fault;
end;</pstext></ps>
    <ps name="aarch32/translation/debug/AArch32_CheckVectorCatch" mylink="aarch32.translation.debug.AArch32_CheckVectorCatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CheckVectorCatch()
// ==========================
// Called before executing the instruction of length &quot;size&quot; bytes at &quot;vaddress&quot; in an AArch32
// translation regime, when debug exceptions are enabled.

func <anchor link="func_AArch32_CheckVectorCatch_3">AArch32_CheckVectorCatch</anchor>(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, vaddress : bits(32),
                              size : integer) =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin
    assert <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>());

    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;
    var match : boolean = <a link="func_AArch32_VCRMatch_1" file="shared_pseudocode.xml">AArch32_VCRMatch</a>(vaddress);
    if size == 4 &amp;&amp; !match &amp;&amp; <a link="func_AArch32_VCRMatch_1" file="shared_pseudocode.xml">AArch32_VCRMatch</a>(vaddress + 2) then
        match = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_VCMATCHHALF" file="shared_pseudocode.xml">Unpredictable_VCMATCHHALF</a>);
    end;

    if match then
        fault.statuscode = <a link="enum_Fault_Debug" file="shared_pseudocode.xml">Fault_Debug</a>;
        fault.debugmoe   = <a link="global_DebugException_VectorCatch" file="shared_pseudocode.xml">DebugException_VectorCatch</a>;
    end;

    return fault;
end;</pstext></ps>
    <ps name="aarch32/translation/debug/AArch32_CheckWatchpoint" mylink="aarch32.translation.debug.AArch32_CheckWatchpoint" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CheckWatchpoint()
// =========================
// Called before accessing the memory location of &quot;size&quot; bytes at &quot;address&quot;,
// when either debug exceptions are enabled for the access, or halting debug
// is enabled and halting is allowed.

func <anchor link="func_AArch32_CheckWatchpoint_4">AArch32_CheckWatchpoint</anchor>(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, vaddress : bits(32),
                             accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>, size : integer) =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin
    assert <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>());
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;
    var match : boolean = FALSE;

    if !<a link="func_IsWatchpointableAccess_1" file="shared_pseudocode.xml">IsWatchpointableAccess</a>(accdesc) then
        return fault;
    end;

    for i = 0 to <a link="func_NumWatchpointsImplemented_0" file="shared_pseudocode.xml">NumWatchpointsImplemented</a>() - 1 do
        let watchptinfo : <a link="type_WatchpointInfo" file="shared_pseudocode.xml">WatchpointInfo</a> = <a link="func_AArch32_WatchpointMatch_4" file="shared_pseudocode.xml">AArch32_WatchpointMatch</a>(i, vaddress, size, accdesc);
        match = match || watchptinfo.value_match;
    end;

    if match &amp;&amp; <a link="func_HaltOnBreakpointOrWatchpoint_0" file="shared_pseudocode.xml">HaltOnBreakpointOrWatchpoint</a>() then
        let reason : bits(6) = <a link="global_DebugHalt_Watchpoint" file="shared_pseudocode.xml">DebugHalt_Watchpoint</a>;
        EDWAR()  = ZeroExtend{64}(vaddress);
        <a link="func_Halt_1" file="shared_pseudocode.xml">Halt</a>(reason);
    elsif match then
        fault.statuscode = <a link="enum_Fault_Debug" file="shared_pseudocode.xml">Fault_Debug</a>;
        fault.debugmoe   = <a link="global_DebugException_Watchpoint" file="shared_pseudocode.xml">DebugException_Watchpoint</a>;
        fault.vaddress   = ZeroExtend{64}(vaddress);
    end;

    return fault;
end;</pstext></ps>
    <ps name="aarch32/translation/faults/AArch32_IPAIsOutOfRange" mylink="aarch32.translation.faults.AArch32_IPAIsOutOfRange" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_IPAIsOutOfRange()
// =========================
// Check intermediate physical address bits not resolved by translation are ZERO

func <anchor link="func_AArch32_IPAIsOutOfRange_2">AArch32_IPAIsOutOfRange</anchor>(walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>, ipa : bits(40)) =&gt; boolean
begin
    // Input Address size
    let iasize : integer{} = <a link="func_AArch32_S2IASize_1" file="shared_pseudocode.xml">AArch32_S2IASize</a>(walkparams.t0sz);

    return iasize &lt; 40 &amp;&amp; !IsZero(ipa[39:iasize]);
end;</pstext></ps>
    <ps name="aarch32/translation/faults/AArch32_S1HasAlignmentFaultDueToMemType" mylink="aarch32.translation.faults.AArch32_S1HasAlignmentFaultDueToMemType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S1HasAlignmentFaultDueToMemType()
// =========================================
// Returns whether stage 1 output fails alignment requirement on data accesses to memory type

func <anchor link="func_AArch32_S1HasAlignmentFaultDueToMemType_4">AArch32_S1HasAlignmentFaultDueToMemType</anchor>(accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>, aligned : boolean,
                                             ntlsmd : bit, memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>) =&gt; boolean
begin
    if memattrs.memtype != <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> then
        return FALSE;
    elsif accdesc.a32lsmd &amp;&amp; ntlsmd == '0' then
        return memattrs.device != <a link="enum_DeviceType_GRE" file="shared_pseudocode.xml">DeviceType_GRE</a>;
    elsif accdesc.acctype == <a link="enum_AccessType_DCZero" file="shared_pseudocode.xml">AccessType_DCZero</a> then
        return TRUE;
    elsif !aligned then
        return !(ImpDefBool(&quot;Device location supports unaligned access&quot;));
    else
        return FALSE;
    end;
end;</pstext></ps>
    <ps name="aarch32/translation/faults/AArch32_S1LDHasPermissionsFault" mylink="aarch32.translation.faults.AArch32_S1LDHasPermissionsFault" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S1LDHasPermissionsFault()
// =================================
// Returns whether an access using stage 1 long-descriptor translation
// violates permissions of target memory

func <anchor link="func_AArch32_S1LDHasPermissionsFault_6">AArch32_S1LDHasPermissionsFault</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>, perms : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a>,
                                     memtype : <a link="type_MemType" file="shared_pseudocode.xml">MemType</a>, paspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>,
                                     accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; boolean
begin
    var r,  w,  x : bit;
    var pr, pw : bit;
    var ur, uw : bit;
    var xn : bit;
    if <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) then
        // Apply leaf permissions
        case perms.ap[2:1] of
            when '00' =&gt; (pr,pw,ur,uw) = ('1','1','0','0'); // R/W at PL1 only
            when '01' =&gt; (pr,pw,ur,uw) = ('1','1','1','1'); // R/W at any PL
            when '10' =&gt; (pr,pw,ur,uw) = ('1','0','0','0'); // RO at PL1 only
            when '11' =&gt; (pr,pw,ur,uw) = ('1','0','1','0'); // RO at any PL
        end;

        // Apply hierarchical permissions
        case perms.ap_table of
            when '00' =&gt; (pr,pw,ur,uw) = ( pr, pw, ur, uw); // No effect
            when '01' =&gt; (pr,pw,ur,uw) = ( pr, pw,'0','0'); // Privileged access
            when '10' =&gt; (pr,pw,ur,uw) = ( pr,'0', ur,'0'); // Read-only
            when '11' =&gt; (pr,pw,ur,uw) = ( pr,'0','0','0'); // Read-only, privileged access
        end;

        xn   = perms.xn OR perms.xn_table;
        let pxn : bit  = perms.pxn OR perms.pxn_table;

        let ux : bit = ur AND NOT(xn OR (uw AND walkparams.wxn));
        let px : bit = pr AND NOT(xn OR pxn OR (pw AND walkparams.wxn) OR (uw AND walkparams.uwxn));

        if IsFeatureImplemented(FEAT_PAN) &amp;&amp; accdesc.pan then
            let pan : bit = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN AND (ur OR uw);
            pr  = pr AND NOT(pan);
            pw  = pw AND NOT(pan);
        end;

        (r,w,x) = if accdesc.el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then (ur,uw,ux) else (pr,pw,px);

        // Prevent execution from Non-secure space by PE in Secure state if SIF is set
        if accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> &amp;&amp; paspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> then
            x = x AND NOT(walkparams.sif);
        end;
    else
        // Apply leaf permissions
        case perms.ap[2] of
            when '0' =&gt; (r,w) = ('1','1'); // No effect
            when '1' =&gt; (r,w) = ('1','0'); // Read-only
        end;

        // Apply hierarchical permissions
        case perms.ap_table[1] of
            when '0' =&gt; (r,w) = ( r, w );  // No effect
            when '1' =&gt; (r,w) = ( r, '0'); // Read-only
        end;

        xn = perms.xn OR perms.xn_table;
        x  = NOT(xn OR (w AND walkparams.wxn));
    end;

    if accdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> then
        let constraint : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = ConstrainUnpredictable(<a link="enum_Unpredictable_INSTRDEVICE" file="shared_pseudocode.xml">Unpredictable_INSTRDEVICE</a>);
        if constraint == <a link="enum_Constraint_FAULT" file="shared_pseudocode.xml">Constraint_FAULT</a> &amp;&amp; memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> then
            return TRUE;
        else
            return x == '0';
        end;
    elsif accdesc.acctype IN {<a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>, <a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>} then
        return FALSE;
    elsif accdesc.write then
        return w == '0';
    else
        return r == '0';
    end;
end;</pstext></ps>
    <ps name="aarch32/translation/faults/AArch32_S1SDHasPermissionsFault" mylink="aarch32.translation.faults.AArch32_S1SDHasPermissionsFault" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S1SDHasPermissionsFault()
// =================================
// Returns whether an access using stage 1 short-descriptor translation
// violates permissions of target memory

func <anchor link="func_AArch32_S1SDHasPermissionsFault_5">AArch32_S1SDHasPermissionsFault</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, perms_in : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a>, memtype : <a link="type_MemType" file="shared_pseudocode.xml">MemType</a>,
                                     paspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>, accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; boolean
begin
    var perms : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a> = perms_in;
    var pr, pw : bit;
    var ur, uw : bit;
    var sctlr : SCTLR_Type;
    if regime == <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a> then
        sctlr = SCTLR_S();
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        sctlr = SCTLR_NS();
    else
        sctlr = SCTLR();
    end;

    if sctlr.AFE == '0' then
        // Map Reserved encoding '100'
        if perms.ap == '100' then
            perms.ap = ImpDefBits{3}(&quot;Reserved short descriptor AP encoding&quot;);
        end;

        case perms.ap of
            when '000' =&gt; (pr,pw,ur,uw) = ('0','0','0','0'); // No access
            when '001' =&gt; (pr,pw,ur,uw) = ('1','1','0','0'); // R/W at PL1 only
            when '010' =&gt; (pr,pw,ur,uw) = ('1','1','1','0'); // R/W at PL1, RO at PL0
            when '011' =&gt; (pr,pw,ur,uw) = ('1','1','1','1'); // R/W at any PL
            //   '100' is reserved
            when '101' =&gt; (pr,pw,ur,uw) = ('1','0','0','0'); // RO at PL1 only
            when '110' =&gt; (pr,pw,ur,uw) = ('1','0','1','0'); // RO at any PL (deprecated)
            when '111' =&gt; (pr,pw,ur,uw) = ('1','0','1','0'); // RO at any PL
        end;
    else // Simplified access permissions model
        case perms.ap[2:1] of
            when '00' =&gt; (pr,pw,ur,uw) = ('1','1','0','0'); // R/W at PL1 only
            when '01' =&gt; (pr,pw,ur,uw) = ('1','1','1','1'); // R/W at any PL
            when '10' =&gt; (pr,pw,ur,uw) = ('1','0','0','0'); // RO at PL1 only
            when '11' =&gt; (pr,pw,ur,uw) = ('1','0','1','0'); // RO at any PL
        end;
    end;

    let ux : bit = ur AND NOT(perms.xn OR (uw AND sctlr.WXN));
    let px : bit = pr AND NOT(perms.xn OR perms.pxn OR (pw AND sctlr.WXN) OR (uw AND sctlr.UWXN));

    if IsFeatureImplemented(FEAT_PAN) &amp;&amp; accdesc.pan then
        let pan : bit = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN AND (ur OR uw);
        pr  = pr AND NOT(pan);
        pw  = pw AND NOT(pan);
    end;

    var (r,w,x) : (bit, bit, bit) = if accdesc.el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then (ur,uw,ux) else (pr,pw,px);

    // Prevent execution from Non-secure space by PE in Secure state if SIF is set
    if accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> &amp;&amp; paspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> then
        x = x AND NOT(if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then SCR().SIF else SCR_EL3().SIF);
    end;

    if accdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> then
        if (memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> &amp;&amp;
                ConstrainUnpredictable(<a link="enum_Unpredictable_INSTRDEVICE" file="shared_pseudocode.xml">Unpredictable_INSTRDEVICE</a>) == <a link="enum_Constraint_FAULT" file="shared_pseudocode.xml">Constraint_FAULT</a>) then
            return TRUE;
        else
            return x == '0';
        end;
    elsif accdesc.acctype IN {<a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>, <a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>} then
        return FALSE;
    elsif accdesc.write then
        return w == '0';
    else
        return r == '0';
    end;
end;</pstext></ps>
    <ps name="aarch32/translation/faults/AArch32_S2HasAlignmentFaultDueToMemType" mylink="aarch32.translation.faults.AArch32_S2HasAlignmentFaultDueToMemType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S2HasAlignmentFaultDueToMemType()
// =========================================
// Returns whether stage 2 output fails alignment requirement on data accesses due to memory type

func <anchor link="func_AArch32_S2HasAlignmentFaultDueToMemType_3">AArch32_S2HasAlignmentFaultDueToMemType</anchor>(accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>, aligned : boolean,
                                             memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>) =&gt; boolean
begin

    if memattrs.memtype != <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> then
        return FALSE;
    elsif accdesc.acctype == <a link="enum_AccessType_DCZero" file="shared_pseudocode.xml">AccessType_DCZero</a> then
        return TRUE;
    elsif !aligned then
        return !(ImpDefBool(&quot;Device location supports unaligned access&quot;));
    else
        return FALSE;
    end;
end;</pstext></ps>
    <ps name="aarch32/translation/faults/AArch32_S2HasPermissionsFault" mylink="aarch32.translation.faults.AArch32_S2HasPermissionsFault" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S2HasPermissionsFault()
// ===============================
// Returns whether stage 2 access violates permissions of target memory

func <anchor link="func_AArch32_S2HasPermissionsFault_4">AArch32_S2HasPermissionsFault</anchor>(walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>, perms : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a>, memtype : <a link="type_MemType" file="shared_pseudocode.xml">MemType</a>,
                                   accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; boolean
begin
    let r : bit = perms.s2ap[0];
    let w : bit = perms.s2ap[1];
    var x : bit;
    var ux : bit;
    var px : bit;
    if IsFeatureImplemented(FEAT_XNX) then
        case perms.s2xn::perms.s2xnx of
            when '00' =&gt;  (px, ux) = ( r, r );
            when '01' =&gt;  (px, ux) = ('0', r );
            when '10' =&gt;  (px, ux) = ('0', '0');
            when '11' =&gt;  (px, ux) = ( r, '0');
        end;

        x = if accdesc.el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then ux else px;
    else
        x = r AND NOT(perms.s2xn);
    end;

    if accdesc.acctype == <a link="enum_AccessType_TTW" file="shared_pseudocode.xml">AccessType_TTW</a> then
        return (walkparams.ptw == '1' &amp;&amp; memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a>) || r == '0';

    elsif accdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> then
        let constraint : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = ConstrainUnpredictable(<a link="enum_Unpredictable_INSTRDEVICE" file="shared_pseudocode.xml">Unpredictable_INSTRDEVICE</a>);
        return (constraint == <a link="enum_Constraint_FAULT" file="shared_pseudocode.xml">Constraint_FAULT</a> &amp;&amp; memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a>) || x == '0';

    elsif accdesc.acctype IN {<a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>, <a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>} then
        return FALSE;

    elsif accdesc.write then
        return w == '0';

    else
        return r == '0';
    end;
end;</pstext></ps>
    <ps name="aarch32/translation/faults/AArch32_S2InconsistentSL" mylink="aarch32.translation.faults.AArch32_S2InconsistentSL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S2InconsistentSL()
// ==========================
// Detect inconsistent configuration of stage 2 T0SZ and SL fields

func <anchor link="func_AArch32_S2InconsistentSL_1">AArch32_S2InconsistentSL</anchor>(walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>) =&gt; boolean
begin
    let startlevel : integer  = <a link="func_AArch32_S2StartLevel_1" file="shared_pseudocode.xml">AArch32_S2StartLevel</a>(walkparams.sl0);
    let levels : integer      = <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - startlevel;
    let granulebits : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_TGxGranuleBits_1" file="shared_pseudocode.xml">TGxGranuleBits</a>(walkparams.tgx);
    let stride : integer{}      = granulebits - 3;

    // Input address size must at least be large enough to be resolved from the start level
    let sl_min_iasize : integer = (
        levels * stride // Bits resolved by table walk, except initial level
        + granulebits   // Bits directly mapped to output address
        + 1);           // At least 1 more bit to be decoded by initial level

    // Can accommodate 1 more stride in the level + concatenation of up to 2^4 tables
    let sl_max_iasize : integer = sl_min_iasize + (stride-1) + 4;
    // Configured Input Address size
    let iasize : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>        = <a link="func_AArch32_S2IASize_1" file="shared_pseudocode.xml">AArch32_S2IASize</a>(walkparams.t0sz);

    return iasize &lt; sl_min_iasize || iasize &gt; sl_max_iasize;
end;</pstext></ps>
    <ps name="aarch32/translation/faults/AArch32_VAIsOutOfRange" mylink="aarch32.translation.faults.AArch32_VAIsOutOfRange" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_VAIsOutOfRange()
// ========================
// Check virtual address bits not resolved by translation are identical
// and of accepted value

func <anchor link="func_AArch32_VAIsOutOfRange_3">AArch32_VAIsOutOfRange</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>, va : bits(32)) =&gt; boolean
begin
    if regime == <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> then
        // Input Address size
        let iasize : integer{} = <a link="func_AArch32_S1IASize_1" file="shared_pseudocode.xml">AArch32_S1IASize</a>(walkparams.t0sz);
        return walkparams.t0sz != '000' &amp;&amp; !IsZero(va[31:iasize]);
    elsif walkparams.t1sz != '000' &amp;&amp; walkparams.t0sz != '000' then
        // Lower range Input Address size
        let lo_iasize : integer{} = <a link="func_AArch32_S1IASize_1" file="shared_pseudocode.xml">AArch32_S1IASize</a>(walkparams.t0sz);
        // Upper range Input Address size
        let up_iasize : integer{} = <a link="func_AArch32_S1IASize_1" file="shared_pseudocode.xml">AArch32_S1IASize</a>(walkparams.t1sz);
        return !IsZero(va[31:lo_iasize]) &amp;&amp; !IsOnes(va[31:up_iasize]);
    else
        return FALSE;
    end;
end;</pstext></ps>
    <ps name="aarch32/translation/tlbcontext/AArch32_GetS1TLBContext" mylink="aarch32.translation.tlbcontext.AArch32_GetS1TLBContext" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_GetS1TLBContext()
// =========================
// Gather translation context for accesses with VA to match against TLB entries

func <anchor link="func_AArch32_GetS1TLBContext_3">AArch32_GetS1TLBContext</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, va : bits(32)) =&gt; <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>
begin
    var tlbcontext : <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>;

    case regime of
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a>  =&gt; tlbcontext = <a link="func_AArch32_TLBContextEL2_1" file="shared_pseudocode.xml">AArch32_TLBContextEL2</a>(va);
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt; tlbcontext = <a link="func_AArch32_TLBContextEL10_2" file="shared_pseudocode.xml">AArch32_TLBContextEL10</a>(ss, va);
        when <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a> =&gt; tlbcontext = <a link="func_AArch32_TLBContextEL30_1" file="shared_pseudocode.xml">AArch32_TLBContextEL30</a>(va);
    end;

    tlbcontext.includes_s1 = TRUE;
    // The following may be amended for EL1&amp;0 Regime if caching of stage 2 is successful
    tlbcontext.includes_s2 = FALSE;
    return tlbcontext;
end;</pstext></ps>
    <ps name="aarch32/translation/tlbcontext/AArch32_GetS2TLBContext" mylink="aarch32.translation.tlbcontext.AArch32_GetS2TLBContext" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_GetS2TLBContext()
// =========================
// Gather translation context for accesses with IPA to match against TLB entries

func <anchor link="func_AArch32_GetS2TLBContext_1">AArch32_GetS2TLBContext</anchor>(ipa : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>) =&gt; <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>
begin
    assert ipa.paspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;

    var tlbcontext : <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>;

    tlbcontext.ss          = <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a>;
    tlbcontext.regime      = <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a>;
    tlbcontext.ipaspace    = ipa.paspace;
    tlbcontext.vmid        = ZeroExtend{NUM_VMIDBITS}(VTTBR().VMID);
    tlbcontext.tg          = <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>;
    tlbcontext.includes_s1 = FALSE;
    tlbcontext.includes_s2 = TRUE;
    tlbcontext.ia          = ZeroExtend{64}(ipa.address);
    tlbcontext.cnp         = if IsFeatureImplemented(FEAT_TTCNP) then VTTBR().CnP else '0';

    return tlbcontext;
end;</pstext></ps>
    <ps name="aarch32/translation/tlbcontext/AArch32_TLBContextEL10" mylink="aarch32.translation.tlbcontext.AArch32_TLBContextEL10" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TLBContextEL10()
// ========================
// Gather translation context for accesses under EL10 regime
// (PL10 when EL3 is A64) to match against TLB entries

func <anchor link="func_AArch32_TLBContextEL10_2">AArch32_TLBContextEL10</anchor>(ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, va : bits(32)) =&gt; <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>
begin
    var tlbcontext : <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>;
    var ttbcr : TTBCR_Type;
    var ttbr0 : TTBR0_Type;
    var ttbr1 : TTBR1_Type;
    var contextidr : CONTEXTIDR_Type;

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        ttbcr      = TTBCR_NS();
        ttbr0      = TTBR0_NS();
        ttbr1      = TTBR1_NS();
        contextidr = CONTEXTIDR_NS();
    else
        ttbcr      = TTBCR();
        ttbr0      = TTBR0();
        ttbr1      = TTBR1();
        contextidr = CONTEXTIDR();
    end;

    tlbcontext.ss     = ss;
    tlbcontext.regime = <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a>;

    if <a link="func_AArch32_EL2Enabled_1" file="shared_pseudocode.xml">AArch32_EL2Enabled</a>(ss) then
        tlbcontext.vmid = ZeroExtend{NUM_VMIDBITS}(VTTBR().VMID);
    end;

    if ttbcr.EAE == '1' then
        if ttbcr.A1 == '0' then
            tlbcontext.asid = ZeroExtend{NUM_ASIDBITS}(ttbr0.ASID);
        else
            tlbcontext.asid = ZeroExtend{NUM_ASIDBITS}(ttbr1.ASID);
        end;
    else
        tlbcontext.asid = ZeroExtend{NUM_ASIDBITS}(contextidr.ASID);
    end;

    tlbcontext.tg = <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>;
    tlbcontext.ia = ZeroExtend{64}(va);

    if IsFeatureImplemented(FEAT_TTCNP) &amp;&amp; ttbcr.EAE == '1' then
        if <a link="func_AArch32_GetVARange_3" file="shared_pseudocode.xml">AArch32_GetVARange</a>(va, ttbcr.T0SZ, ttbcr.T1SZ) == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then
            tlbcontext.cnp = ttbr0.CnP;
        else
            tlbcontext.cnp = ttbr1.CnP;
        end;
    else
        tlbcontext.cnp = '0';
    end;

    return tlbcontext;
end;</pstext></ps>
    <ps name="aarch32/translation/tlbcontext/AArch32_TLBContextEL2" mylink="aarch32.translation.tlbcontext.AArch32_TLBContextEL2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TLBContextEL2()
// =======================
// Gather translation context for accesses under EL2 regime to match against TLB entries

func <anchor link="func_AArch32_TLBContextEL2_1">AArch32_TLBContextEL2</anchor>(va : bits(32)) =&gt; <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>
begin
    var tlbcontext : <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>;

    tlbcontext.ss     = <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a>;
    tlbcontext.regime = <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a>;
    tlbcontext.ia     = ZeroExtend{64}(va);
    tlbcontext.tg     = <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>;
    tlbcontext.cnp    = if IsFeatureImplemented(FEAT_TTCNP) then HTTBR().CnP else '0';

    return tlbcontext;
end;</pstext></ps>
    <ps name="aarch32/translation/tlbcontext/AArch32_TLBContextEL30" mylink="aarch32.translation.tlbcontext.AArch32_TLBContextEL30" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TLBContextEL30()
// ========================
// Gather translation context for accesses under EL30 regime
// (PL10 in Secure state and EL3 is A32) to match against TLB entries

func <anchor link="func_AArch32_TLBContextEL30_1">AArch32_TLBContextEL30</anchor>(va : bits(32)) =&gt; <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>
begin
    var tlbcontext : <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>;

    tlbcontext.ss     = <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>;
    tlbcontext.regime = <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a>;
    if TTBCR_S().EAE == '1' then
        tlbcontext.asid = ZeroExtend{NUM_ASIDBITS}(if TTBCR_S().A1 == '0' then TTBR0_S().ASID
                                                                      else TTBR1_S().ASID);
    else
        tlbcontext.asid = ZeroExtend{NUM_ASIDBITS}(CONTEXTIDR_S().ASID);
    end;

    tlbcontext.tg = <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>;
    tlbcontext.ia = ZeroExtend{64}(va);

    if IsFeatureImplemented(FEAT_TTCNP) &amp;&amp; TTBCR_S().EAE == '1' then
        if <a link="func_AArch32_GetVARange_3" file="shared_pseudocode.xml">AArch32_GetVARange</a>(va, TTBCR_S().T0SZ, TTBCR_S().T1SZ) == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then
            tlbcontext.cnp = TTBR0_S().CnP;
        else
            tlbcontext.cnp = TTBR1_S().CnP;
        end;
    else
        tlbcontext.cnp = '0';
    end;

    return tlbcontext;
end;</pstext></ps>
    <ps name="aarch32/translation/translation/AArch32_EL2Enabled" mylink="aarch32.translation.translation.AArch32_EL2Enabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_EL2Enabled()
// ====================
// Returns whether EL2 is enabled for the given Security State

func <anchor link="func_AArch32_EL2Enabled_1">AArch32_EL2Enabled</anchor>(ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>) =&gt; boolean
begin
    if ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
        if !(<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; IsFeatureImplemented(FEAT_SEL2)) then
            return FALSE;
        elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
            return SCR_EL3().EEL2 == '1';
        else
            return ImpDefBool(&quot;Secure-only implementation&quot;);
        end;
    else
        return <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
    end;
end;</pstext></ps>
    <ps name="aarch32/translation/translation/AArch32_FullTranslate" mylink="aarch32.translation.translation.AArch32_FullTranslate" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_FullTranslate()
// =======================
// Perform address translation as specified by VMSA-A32

func <anchor link="func_AArch32_FullTranslate_3">AArch32_FullTranslate</anchor>(va : bits(32), accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                           aligned : boolean) =&gt; <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>
begin

    // Prepare fault fields in case a fault is detected
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_2" file="shared_pseudocode.xml">NoFault</a>(accdesc, ZeroExtend{64}(va));
    let regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a> = <a link="func_TranslationRegime_1" file="shared_pseudocode.xml">TranslationRegime</a>(accdesc.el);

    // First Stage Translation
    var ipa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    if regime == <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> || TTBCR().EAE == '1' then
        (fault, ipa)    = <a link="func_AArch32_S1TranslateLD_5" file="shared_pseudocode.xml">AArch32_S1TranslateLD</a>(fault, regime, va, aligned, accdesc);
    else
        (fault, ipa, -) = <a link="func_AArch32_S1TranslateSD_5" file="shared_pseudocode.xml">AArch32_S1TranslateSD</a>(fault, regime, va, aligned, accdesc);
    end;

    if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        return <a link="func_CreateFaultyAddressDescriptor_1" file="shared_pseudocode.xml">CreateFaultyAddressDescriptor</a>(fault);
    end;

    if regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        ipa.vaddress = ZeroExtend{64}(va);
        var pa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
        (fault, pa) = <a link="func_AArch32_S2Translate_4" file="shared_pseudocode.xml">AArch32_S2Translate</a>(fault, ipa, aligned, accdesc);

        if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
            return <a link="func_CreateFaultyAddressDescriptor_1" file="shared_pseudocode.xml">CreateFaultyAddressDescriptor</a>(fault);
        else
            return pa;
        end;
    else
        return ipa;
    end;
end;</pstext></ps>
    <ps name="aarch32/translation/translation/AArch32_OutputDomain" mylink="aarch32.translation.translation.AArch32_OutputDomain" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_OutputDomain()
// ======================
// Determine the domain the translated output address

func <anchor link="func_AArch32_OutputDomain_2">AArch32_OutputDomain</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, domain : bits(4)) =&gt; bits(2)
begin
    var Dn : bits(2);
    if regime == <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a> then
        Dn = DACR_S()[UInt(domain)*:2];
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        Dn = DACR_NS()[UInt(domain)*:2];
    else
        Dn = DACR()[UInt(domain)*:2];
    end;

    if Dn == '10' then
        // Reserved value maps to an allocated value
        (-, Dn) = ConstrainUnpredictableBits{2}(<a link="enum_Unpredictable_RESDACR" file="shared_pseudocode.xml">Unpredictable_RESDACR</a>);
    end;

    return Dn;
end;</pstext></ps>
    <ps name="aarch32/translation/translation/AArch32_S1DisabledOutput" mylink="aarch32.translation.translation.AArch32_S1DisabledOutput" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S1DisabledOutput()
// ==========================
// Flat map the VA to IPA/PA, depending on the regime, assigning default memory attributes

func <anchor link="func_AArch32_S1DisabledOutput_5">AArch32_S1DisabledOutput</anchor>(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
                              va : bits(32), aligned : boolean,
                              accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; (<a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>)
begin

    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;
    // No memory page is guarded when stage 1 address translation is disabled
    <a link="func_SetInGuardedPage_1" file="shared_pseudocode.xml">SetInGuardedPage</a>(FALSE);

    var memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>;
    var default_cacheable : bit;
    if regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_AArch32_EL2Enabled_1" file="shared_pseudocode.xml">AArch32_EL2Enabled</a>(accdesc.ss) then
        if <a link="func_ELStateUsingAArch32_2" file="shared_pseudocode.xml">ELStateUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>) then
            default_cacheable = HCR().DC;
        else
            default_cacheable = HCR_EL2().DC;
        end;
    else
        default_cacheable = '0';
    end;

    if default_cacheable == '1' then
        // Use default cacheable settings
        memattrs.memtype      = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
        memattrs.inner.attrs  = <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>;
        memattrs.inner.hints  = <a link="global_MemHint_RWA" file="shared_pseudocode.xml">MemHint_RWA</a>;
        memattrs.outer.attrs  = <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>;
        memattrs.outer.hints  = <a link="global_MemHint_RWA" file="shared_pseudocode.xml">MemHint_RWA</a>;
        memattrs.shareability = <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a>;
        if (<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELStateUsingAArch32_2" file="shared_pseudocode.xml">ELStateUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>) &amp;&amp;
              IsFeatureImplemented(FEAT_MTE2) &amp;&amp; HCR_EL2().DCT == '1') then
            memattrs.tags     = <a link="enum_MemTag_AllocationTagged" file="shared_pseudocode.xml">MemTag_AllocationTagged</a>;
        else
            memattrs.tags     = <a link="enum_MemTag_Untagged" file="shared_pseudocode.xml">MemTag_Untagged</a>;
        end;
        memattrs.xs           = '0';
    elsif accdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> then
        memattrs.memtype      = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
        memattrs.shareability = <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
        memattrs.tags         = <a link="enum_MemTag_Untagged" file="shared_pseudocode.xml">MemTag_Untagged</a>;
        if <a link="func_AArch32_S1ICacheEnabled_1" file="shared_pseudocode.xml">AArch32_S1ICacheEnabled</a>(regime) then
            memattrs.inner.attrs = <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a>;
            memattrs.inner.hints = <a link="global_MemHint_RA" file="shared_pseudocode.xml">MemHint_RA</a>;
            memattrs.outer.attrs = <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a>;
            memattrs.outer.hints = <a link="global_MemHint_RA" file="shared_pseudocode.xml">MemHint_RA</a>;
        else
            memattrs.inner.attrs = <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>;
            memattrs.outer.attrs = <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>;
        end;
        memattrs.xs           = '1';
    else
        // Treat memory region as Device
        memattrs.memtype      = <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a>;
        memattrs.device       = <a link="enum_DeviceType_nGnRnE" file="shared_pseudocode.xml">DeviceType_nGnRnE</a>;
        memattrs.shareability = <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
        memattrs.tags         = <a link="enum_MemTag_Untagged" file="shared_pseudocode.xml">MemTag_Untagged</a>;
        memattrs.xs           = '1';
    end;

    var ntlsmd : bit;
    if IsFeatureImplemented(FEAT_LSMAOC) then
        case regime of
            when <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a> =&gt; ntlsmd = SCTLR_S().nTLSMD;
            when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a>  =&gt; ntlsmd = HSCTLR().nTLSMD;
            when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt;
                if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
                    ntlsmd = SCTLR_NS().nTLSMD;
                else
                    ntlsmd = SCTLR().nTLSMD;
                end;
        end;
    else
        ntlsmd = '1';
    end;

    if <a link="func_AArch32_S1HasAlignmentFaultDueToMemType_4" file="shared_pseudocode.xml">AArch32_S1HasAlignmentFaultDueToMemType</a>(accdesc, aligned, ntlsmd, memattrs) then
        fault.statuscode  = <a link="enum_Fault_Alignment" file="shared_pseudocode.xml">Fault_Alignment</a>;
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
    elsif (accdesc.exclusive &amp;&amp;
            !(regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
               ((!<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; HCR_EL2().DC == '1') ||
                  (<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; HCR().DC == '1'))) &amp;&amp;
            <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_Atomic_MMU_IMPDEF_FAULT" file="shared_pseudocode.xml">Unpredictable_Atomic_MMU_IMPDEF_FAULT</a>)) then
        fault.statuscode = <a link="enum_Fault_Exclusive" file="shared_pseudocode.xml">Fault_Exclusive</a>;
    end;

    var oa : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    oa.address = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(va);
    oa.paspace = if accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> else <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
    let ipa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_CreateAddressDescriptor_4" file="shared_pseudocode.xml">CreateAddressDescriptor</a>(ZeroExtend{64}(va),
                                                          oa,
                                                          memattrs,
                                                          accdesc);

    return (fault, ipa);
end;</pstext></ps>
    <ps name="aarch32/translation/translation/AArch32_S1Enabled" mylink="aarch32.translation.translation.AArch32_S1Enabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S1Enabled()
// ===================
// Returns whether stage 1 translation is enabled for the active translation regime

func <anchor link="func_AArch32_S1Enabled_2">AArch32_S1Enabled</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>) =&gt; boolean
begin
    if regime == <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> then
        return HSCTLR().M == '1';
    elsif regime == <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a> then
        return SCTLR_S().M == '1';
    elsif !<a link="func_AArch32_EL2Enabled_1" file="shared_pseudocode.xml">AArch32_EL2Enabled</a>(ss) then
        return (if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then SCTLR_NS().M else SCTLR().M) == '1';
    elsif <a link="func_ELStateUsingAArch32_2" file="shared_pseudocode.xml">ELStateUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>) then
        if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
            return HCR().[TGE,DC] == '00' &amp;&amp; SCTLR_NS().M == '1';
        else
            return HCR().[TGE,DC] == '00' &amp;&amp; SCTLR().M == '1';
        end;
    else
        return <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().[TGE,DC] == '00' &amp;&amp; SCTLR().M == '1';
    end;
end;</pstext></ps>
    <ps name="aarch32/translation/translation/AArch32_S1TranslateLD" mylink="aarch32.translation.translation.AArch32_S1TranslateLD" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S1TranslateLD()
// =======================
// Perform a stage 1 translation using long-descriptor format mapping VA to IPA/PA
// depending on the regime

func <anchor link="func_AArch32_S1TranslateLD_5">AArch32_S1TranslateLD</anchor>(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
                           va : bits(32), aligned : boolean,
                           accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; (<a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>)
begin
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;

    if !<a link="func_AArch32_S1Enabled_2" file="shared_pseudocode.xml">AArch32_S1Enabled</a>(regime, accdesc.ss) then
        return <a link="func_AArch32_S1DisabledOutput_5" file="shared_pseudocode.xml">AArch32_S1DisabledOutput</a>(fault, regime, va, aligned, accdesc);
    end;

    let walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a> = <a link="func_AArch32_GetS1TTWParams_2" file="shared_pseudocode.xml">AArch32_GetS1TTWParams</a>(regime, va);

    if <a link="func_AArch32_VAIsOutOfRange_3" file="shared_pseudocode.xml">AArch32_VAIsOutOfRange</a>(regime, walkparams, va) then
        fault.level      = 1;
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
    end;

    var walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>;
    (fault, walkstate) = <a link="func_AArch32_S1WalkLD_5" file="shared_pseudocode.xml">AArch32_S1WalkLD</a>(fault, regime, walkparams, accdesc, va);

    if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
    end;

    <a link="func_SetInGuardedPage_1" file="shared_pseudocode.xml">SetInGuardedPage</a>(FALSE);  // AArch32-VMSA does not guard any pages

    if <a link="func_AArch32_S1HasAlignmentFaultDueToMemType_4" file="shared_pseudocode.xml">AArch32_S1HasAlignmentFaultDueToMemType</a>(accdesc, aligned, walkparams.ntlsmd,
                                               walkstate.memattrs) then
        fault.statuscode = <a link="enum_Fault_Alignment" file="shared_pseudocode.xml">Fault_Alignment</a>;
    elsif <a link="func_AArch32_S1LDHasPermissionsFault_6" file="shared_pseudocode.xml">AArch32_S1LDHasPermissionsFault</a>(regime, walkparams,
                                          walkstate.permissions,
                                          walkstate.memattrs.memtype,
                                          walkstate.baseaddress.paspace,
                                          accdesc) then
        fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
    end;

    if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
    end;

    var memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>;
    if ((accdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> &amp;&amp;
            (walkstate.memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> || !<a link="func_AArch32_S1ICacheEnabled_1" file="shared_pseudocode.xml">AArch32_S1ICacheEnabled</a>(regime))) ||
        (accdesc.acctype != <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> &amp;&amp;
             walkstate.memattrs.memtype == <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a> &amp;&amp; !<a link="func_AArch32_S1DCacheEnabled_1" file="shared_pseudocode.xml">AArch32_S1DCacheEnabled</a>(regime))) then
        // Treat memory attributes as Normal Non-Cacheable
        memattrs = <a link="func_NormalNCMemAttr_0" file="shared_pseudocode.xml">NormalNCMemAttr</a>();
        memattrs.xs = walkstate.memattrs.xs;
    else
        memattrs = walkstate.memattrs;
    end;

    // Shareability value of stage 1 translation subject to stage 2 is IMPLEMENTATION DEFINED
    // to be either effective value or descriptor value
    if (regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_AArch32_EL2Enabled_1" file="shared_pseudocode.xml">AArch32_EL2Enabled</a>(accdesc.ss) &amp;&amp;
        (if <a link="func_ELStateUsingAArch32_2" file="shared_pseudocode.xml">ELStateUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, accdesc.ss==<a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>) then HCR().VM
                                                            else HCR_EL2().VM) == '1' &amp;&amp;
        !(ImpDefBool(&quot;Apply effective shareability at stage 1&quot;))) then
        memattrs.shareability = walkstate.memattrs.shareability;
    else
        memattrs.shareability = <a link="func_EffectiveShareability_1" file="shared_pseudocode.xml">EffectiveShareability</a>(memattrs);
    end;

    // Output Address
    let oa : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a> = <a link="func_StageOA_4" file="shared_pseudocode.xml">StageOA</a>(ZeroExtend{64}(va), walkparams.d128, walkparams.tgx, walkstate);
    let ipa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_CreateAddressDescriptor_4" file="shared_pseudocode.xml">CreateAddressDescriptor</a>(ZeroExtend{64}(va),
                                                          oa, memattrs, accdesc);

    return (fault, ipa);
end;</pstext></ps>
    <ps name="aarch32/translation/translation/AArch32_S1TranslateSD" mylink="aarch32.translation.translation.AArch32_S1TranslateSD" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S1TranslateSD()
// =======================
// Perform a stage 1 translation using short-descriptor format mapping VA to IPA/PA
// depending on the regime

func <anchor link="func_AArch32_S1TranslateSD_5">AArch32_S1TranslateSD</anchor>(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
                           va : bits(32), aligned : boolean,
                           accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; (<a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, <a link="type_SDFType" file="shared_pseudocode.xml">SDFType</a>)
begin

    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;

    if !<a link="func_AArch32_S1Enabled_2" file="shared_pseudocode.xml">AArch32_S1Enabled</a>(regime, accdesc.ss) then
        var ipa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
        (fault, ipa) = <a link="func_AArch32_S1DisabledOutput_5" file="shared_pseudocode.xml">AArch32_S1DisabledOutput</a>(fault, regime, va, aligned, accdesc);
        return (fault, ipa, ARBITRARY : <a link="type_SDFType" file="shared_pseudocode.xml">SDFType</a>);
    end;

    var walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>;
    (fault, walkstate) = <a link="func_AArch32_S1WalkSD_4" file="shared_pseudocode.xml">AArch32_S1WalkSD</a>(fault, regime, accdesc, va);

    if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, ARBITRARY : <a link="type_SDFType" file="shared_pseudocode.xml">SDFType</a>);
    end;

    let domain : bits(2) = <a link="func_AArch32_OutputDomain_2" file="shared_pseudocode.xml">AArch32_OutputDomain</a>(regime, walkstate.domain);
    <a link="func_SetInGuardedPage_1" file="shared_pseudocode.xml">SetInGuardedPage</a>(FALSE);  // AArch32-VMSA does not guard any pages

    var ntlsmd : bit;
    if IsFeatureImplemented(FEAT_LSMAOC) then
        case regime of
            when <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a> =&gt; ntlsmd = SCTLR_S().nTLSMD;
            when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt;
                if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
                    ntlsmd = SCTLR_NS().nTLSMD;
                else
                    ntlsmd = SCTLR().nTLSMD;
                end;
        end;
    else
        ntlsmd = '1';
    end;

    if <a link="func_AArch32_S1HasAlignmentFaultDueToMemType_4" file="shared_pseudocode.xml">AArch32_S1HasAlignmentFaultDueToMemType</a>(accdesc, aligned, ntlsmd, walkstate.memattrs) then
        fault.statuscode = <a link="enum_Fault_Alignment" file="shared_pseudocode.xml">Fault_Alignment</a>;
    elsif (! accdesc.acctype IN {<a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>, <a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>} &amp;&amp;
           domain == <a link="global_Domain_NoAccess" file="shared_pseudocode.xml">Domain_NoAccess</a>) then
        fault.statuscode = <a link="enum_Fault_Domain" file="shared_pseudocode.xml">Fault_Domain</a>;
    elsif domain == <a link="global_Domain_Client" file="shared_pseudocode.xml">Domain_Client</a> then
        if <a link="func_AArch32_S1SDHasPermissionsFault_5" file="shared_pseudocode.xml">AArch32_S1SDHasPermissionsFault</a>(regime, walkstate.permissions,
                                           walkstate.memattrs.memtype,
                                           walkstate.baseaddress.paspace,
                                           accdesc) then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        end;
    end;

    if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        fault.domain = walkstate.domain;
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, walkstate.sdftype);
    end;

    var memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>;
    if ((accdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> &amp;&amp;
            (walkstate.memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> || !<a link="func_AArch32_S1ICacheEnabled_1" file="shared_pseudocode.xml">AArch32_S1ICacheEnabled</a>(regime))) ||
        (accdesc.acctype != <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> &amp;&amp;
             walkstate.memattrs.memtype == <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a> &amp;&amp; !<a link="func_AArch32_S1DCacheEnabled_1" file="shared_pseudocode.xml">AArch32_S1DCacheEnabled</a>(regime))) then
        // Treat memory attributes as Normal Non-Cacheable
        memattrs = <a link="func_NormalNCMemAttr_0" file="shared_pseudocode.xml">NormalNCMemAttr</a>();
        memattrs.xs = walkstate.memattrs.xs;
    else
        memattrs = walkstate.memattrs;
    end;
    // Shareability value of stage 1 translation subject to stage 2 is IMPLEMENTATION DEFINED
    // to be either effective value or descriptor value
    if (regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_AArch32_EL2Enabled_1" file="shared_pseudocode.xml">AArch32_EL2Enabled</a>(accdesc.ss) &amp;&amp;
        (if <a link="func_ELStateUsingAArch32_2" file="shared_pseudocode.xml">ELStateUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, accdesc.ss==<a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>) then HCR().VM
                                                            else HCR_EL2().VM) == '1' &amp;&amp;
        !(ImpDefBool(&quot;Apply effective shareability at stage 1&quot;))) then
        memattrs.shareability = walkstate.memattrs.shareability;
    else
        memattrs.shareability = <a link="func_EffectiveShareability_1" file="shared_pseudocode.xml">EffectiveShareability</a>(memattrs);
    end;
    // Output Address
    let oa : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a> = <a link="func_AArch32_SDStageOA_3" file="shared_pseudocode.xml">AArch32_SDStageOA</a>(walkstate.baseaddress, va, walkstate.sdftype);
    let ipa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_CreateAddressDescriptor_4" file="shared_pseudocode.xml">CreateAddressDescriptor</a>(ZeroExtend{64}(va),
                                                          oa, memattrs, accdesc);

    return (fault, ipa, walkstate.sdftype);
end;</pstext></ps>
    <ps name="aarch32/translation/translation/AArch32_S2Translate" mylink="aarch32.translation.translation.AArch32_S2Translate" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S2Translate()
// =====================
// Perform a stage 2 translation mapping an IPA to a PA

func <anchor link="func_AArch32_S2Translate_4">AArch32_S2Translate</anchor>(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, ipa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                         aligned : boolean, accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
                        ) =&gt; (<a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>)
begin

    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;
    assert IsZero(ipa.paddress.address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:40]);
    if !<a link="func_ELStateUsingAArch32_2" file="shared_pseudocode.xml">ELStateUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>) then
        let s1aarch64 : boolean = FALSE;
        return <a link="func_AArch64_S2Translate_5" file="shared_pseudocode.xml">AArch64_S2Translate</a>(fault, ipa, s1aarch64, aligned, accdesc);
    end;
    // Prepare fault fields in case a fault is detected
    fault.statuscode  = <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;
    fault.secondstage = TRUE;
    fault.s2fs1walk   = accdesc.acctype == <a link="enum_AccessType_TTW" file="shared_pseudocode.xml">AccessType_TTW</a>;
    fault.ipaddress   = ipa.paddress;

    let walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a> = <a link="func_AArch32_GetS2TTWParams_0" file="shared_pseudocode.xml">AArch32_GetS2TTWParams</a>();

    if walkparams.vm == '0' then
        // Stage 2 is disabled
        return (fault, ipa);
    end;

    if <a link="func_AArch32_IPAIsOutOfRange_2" file="shared_pseudocode.xml">AArch32_IPAIsOutOfRange</a>(walkparams, ipa.paddress.address[39:0]) then
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
        fault.level      = 1;
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
    end;

    var walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>;
    (fault, walkstate) = <a link="func_AArch32_S2Walk_4" file="shared_pseudocode.xml">AArch32_S2Walk</a>(fault, walkparams, accdesc, ipa);

    if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
    end;

    if <a link="func_AArch32_S2HasAlignmentFaultDueToMemType_3" file="shared_pseudocode.xml">AArch32_S2HasAlignmentFaultDueToMemType</a>(accdesc, aligned, walkstate.memattrs) then
        fault.statuscode = <a link="enum_Fault_Alignment" file="shared_pseudocode.xml">Fault_Alignment</a>;
    elsif <a link="func_AArch32_S2HasPermissionsFault_4" file="shared_pseudocode.xml">AArch32_S2HasPermissionsFault</a>(walkparams,
                                        walkstate.permissions,
                                        walkstate.memattrs.memtype,
                                        accdesc) then
        fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
    end;
    var s2_memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>;
    if ((accdesc.acctype == <a link="enum_AccessType_TTW" file="shared_pseudocode.xml">AccessType_TTW</a> &amp;&amp;
             walkstate.memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a>) ||
        (accdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> &amp;&amp;
            (walkstate.memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> || HCR2().ID == '1')) ||
        (accdesc.acctype != <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> &amp;&amp;
             walkstate.memattrs.memtype == <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a> &amp;&amp; HCR2().CD == '1')) then
        // Treat memory attributes as Normal Non-Cacheable
        s2_memattrs = <a link="func_NormalNCMemAttr_0" file="shared_pseudocode.xml">NormalNCMemAttr</a>();
        s2_memattrs.xs = walkstate.memattrs.xs;
    else
        s2_memattrs = walkstate.memattrs;
    end;

    let s2aarch64 : boolean = FALSE;
    let memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a> = <a link="func_S2CombineS1MemAttrs_3" file="shared_pseudocode.xml">S2CombineS1MemAttrs</a>(ipa.memattrs, s2_memattrs, s2aarch64);
    let ipa_64 : bits(64) = ZeroExtend{}(ipa.paddress.address[39:0]);
    // Output Address
    let oa : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a> = <a link="func_StageOA_4" file="shared_pseudocode.xml">StageOA</a>(ipa_64, walkparams.d128, walkparams.tgx, walkstate);
    let pa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_CreateAddressDescriptor_4" file="shared_pseudocode.xml">CreateAddressDescriptor</a>(ipa.vaddress, oa, memattrs, accdesc);

    return (fault, pa);
end;</pstext></ps>
    <ps name="aarch32/translation/translation/AArch32_SDStageOA" mylink="aarch32.translation.translation.AArch32_SDStageOA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_SDStageOA()
// ===================
// Given the final walk state of a short-descriptor translation walk,
// map the untranslated input address bits to the base output address

func <anchor link="func_AArch32_SDStageOA_3">AArch32_SDStageOA</anchor>(baseaddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>, va : bits(32), sdftype : <a link="type_SDFType" file="shared_pseudocode.xml">SDFType</a>) =&gt; <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>
begin
    let tsize : integer{} = <a link="func_SDFSize_1" file="shared_pseudocode.xml">SDFSize</a>(sdftype);

    // Output Address
    var oa : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    oa.address = baseaddress.address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:tsize] :: va[tsize-1:0];
    oa.paspace = baseaddress.paspace;
    return oa;
end;</pstext></ps>
    <ps name="aarch32/translation/translation/AArch32_TranslateAddress" mylink="aarch32.translation.translation.AArch32_TranslateAddress" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_TranslateAddress()
// ==========================
// Main entry point for translating an address

func <anchor link="func_AArch32_TranslateAddress_4">AArch32_TranslateAddress</anchor>(va : bits(32), accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                              aligned : boolean, size : integer) =&gt; <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>
begin

    let regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a> = <a link="func_TranslationRegime_1" file="shared_pseudocode.xml">TranslationRegime</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    if !<a link="func_RegimeUsingAArch32_1" file="shared_pseudocode.xml">RegimeUsingAArch32</a>(regime) then
        return <a link="func_AArch64_TranslateAddress_4" file="shared_pseudocode.xml">AArch64_TranslateAddress</a>(ZeroExtend{64}(va), accdesc, aligned, size);
    end;

    var result : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_AArch32_FullTranslate_3" file="shared_pseudocode.xml">AArch32_FullTranslate</a>(va, accdesc, aligned);

    if !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(result) &amp;&amp; accdesc.acctype != <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> then
        // For an instruction fetch, CheckDebug will be called
        // after the instruction is read from memory
        result.fault = <a link="func_AArch32_CheckDebug_3" file="shared_pseudocode.xml">AArch32_CheckDebug</a>(va, accdesc, size);
    end;

    // Update virtual address for abort functions
    result.vaddress = ZeroExtend{64}(va);

    return result;
end;</pstext></ps>
    <ps name="aarch32/translation/translation/SDFSize" mylink="aarch32.translation.translation.SDFSize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SDFSize()
// =========
// Returns the short-descriptor format translation granule size

func <anchor link="func_SDFSize_1">SDFSize</anchor>(sdftype : <a link="type_SDFType" file="shared_pseudocode.xml">SDFType</a>) =&gt; <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>
begin
    case sdftype of
        when <a link="enum_SDFType_SmallPage" file="shared_pseudocode.xml">SDFType_SmallPage</a> =&gt;    return 12;
        when <a link="enum_SDFType_LargePage" file="shared_pseudocode.xml">SDFType_LargePage</a> =&gt;    return 16;
        when <a link="enum_SDFType_Section" file="shared_pseudocode.xml">SDFType_Section</a> =&gt;      return 20;
        when <a link="enum_SDFType_Supersection" file="shared_pseudocode.xml">SDFType_Supersection</a> =&gt; return 24;
        otherwise =&gt; unreachable;
    end;
end;</pstext></ps>
    <ps name="aarch32/translation/walk/AArch32_DecodeDescriptorTypeLD" mylink="aarch32.translation.walk.AArch32_DecodeDescriptorTypeLD" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_DecodeDescriptorTypeLD()
// ================================
// Determine whether the long-descriptor is a page, block or table

func <anchor link="func_AArch32_DecodeDescriptorTypeLD_2">AArch32_DecodeDescriptorTypeLD</anchor>(descriptor : bits(64), level : integer) =&gt; <a link="type_DescriptorType" file="shared_pseudocode.xml">DescriptorType</a>
begin
    if descriptor[1:0] == '11' &amp;&amp; level == <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> then
        return <a link="enum_DescriptorType_Leaf" file="shared_pseudocode.xml">DescriptorType_Leaf</a>;
    elsif descriptor[1:0] == '11' then
        return <a link="enum_DescriptorType_Table" file="shared_pseudocode.xml">DescriptorType_Table</a>;
    elsif descriptor[1:0] == '01' &amp;&amp; level != <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> then
        return <a link="enum_DescriptorType_Leaf" file="shared_pseudocode.xml">DescriptorType_Leaf</a>;
    else
        return <a link="enum_DescriptorType_Invalid" file="shared_pseudocode.xml">DescriptorType_Invalid</a>;
    end;
end;</pstext></ps>
    <ps name="aarch32/translation/walk/AArch32_DecodeDescriptorTypeSD" mylink="aarch32.translation.walk.AArch32_DecodeDescriptorTypeSD" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_DecodeDescriptorTypeSD()
// ================================
// Determine the type of the short-descriptor

func <anchor link="func_AArch32_DecodeDescriptorTypeSD_2">AArch32_DecodeDescriptorTypeSD</anchor>(descriptor : bits(32), level : integer) =&gt; <a link="type_SDFType" file="shared_pseudocode.xml">SDFType</a>
begin
    if level == 1 &amp;&amp; descriptor[1:0] == '01' then
        return <a link="enum_SDFType_Table" file="shared_pseudocode.xml">SDFType_Table</a>;
    elsif level == 1 &amp;&amp; descriptor[18,1] == '01' then
        return <a link="enum_SDFType_Section" file="shared_pseudocode.xml">SDFType_Section</a>;
    elsif level == 1 &amp;&amp; descriptor[18,1] == '11' then
        return <a link="enum_SDFType_Supersection" file="shared_pseudocode.xml">SDFType_Supersection</a>;
    elsif level == 2 &amp;&amp; descriptor[1:0] == '01' then
        return <a link="enum_SDFType_LargePage" file="shared_pseudocode.xml">SDFType_LargePage</a>;
    elsif level == 2 &amp;&amp; descriptor[1:0] == '1x' then
        return <a link="enum_SDFType_SmallPage" file="shared_pseudocode.xml">SDFType_SmallPage</a>;
    else
        return <a link="enum_SDFType_Invalid" file="shared_pseudocode.xml">SDFType_Invalid</a>;
    end;
end;</pstext></ps>
    <ps name="aarch32/translation/walk/AArch32_S1IASize" mylink="aarch32.translation.walk.AArch32_S1IASize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S1IASize()
// ==================
// Retrieve the number of bits containing the input address for stage 1 translation

func <anchor link="func_AArch32_S1IASize_1">AArch32_S1IASize</anchor>(txsz : bits(3)) =&gt; <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>
begin
    return 32 - UInt(txsz);
end;</pstext></ps>
    <ps name="aarch32/translation/walk/AArch32_S1WalkLD" mylink="aarch32.translation.walk.AArch32_S1WalkLD" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S1WalkLD()
// ==================
// Traverse stage 1 translation tables in long format to obtain the final descriptor

func <anchor link="func_AArch32_S1WalkLD_5">AArch32_S1WalkLD</anchor>(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
                      walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>, accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                      va : bits(32)) =&gt; (<a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>)
begin
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;
    var txsz : bits(3);
    var ttbr : bits(64);
    var epd : bit;
    var varange : <a link="type_VARange" file="shared_pseudocode.xml">VARange</a>;
    if regime == <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> then
        ttbr = HTTBR();
        txsz = walkparams.t0sz;
        varange = <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a>;
    else
        varange = <a link="func_AArch32_GetVARange_3" file="shared_pseudocode.xml">AArch32_GetVARange</a>(va, walkparams.t0sz, walkparams.t1sz);
        var ttbr0 : bits(64);
        var ttbr1 : bits(64);
        var ttbcr : TTBCR_Type;
        if regime == <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a> then
            ttbcr = TTBCR_S();
            ttbr0 = TTBR0_S();
            ttbr1 = TTBR1_S();
        elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
            ttbcr = TTBCR_NS();
            ttbr0 = TTBR0_NS();
            ttbr1 = TTBR1_NS();
        else
            ttbcr = TTBCR();
            ttbr0 = TTBR0();
            ttbr1 = TTBR1();
        end;

        assert ttbcr.EAE == '1';
        if varange == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then
            txsz = walkparams.t0sz;
            ttbr = ttbr0;
            epd  = ttbcr.EPD0;
        else
            txsz = walkparams.t1sz;
            ttbr = ttbr1;
            epd  = ttbcr.EPD1;
        end;
    end;

    if regime != <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> &amp;&amp; epd == '1' then
        fault.level      = 1;
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
        return (fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);
    end;

    // Input Address size
    let iasize : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>      = <a link="func_AArch32_S1IASize_1" file="shared_pseudocode.xml">AArch32_S1IASize</a>(txsz);
    let granulebits : integer{} = <a link="func_TGxGranuleBits_1" file="shared_pseudocode.xml">TGxGranuleBits</a>(walkparams.tgx) as integer{12, 14, 16};
    let stride : integer{}      = granulebits - 3;
    let startlevel : integer  = <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - (((iasize-1) - granulebits) DIVRM stride);
    let levels : integer      = <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - startlevel;

    if !IsZero(ttbr[47:40]) then
        fault.statuscode = <a link="enum_Fault_AddressSize" file="shared_pseudocode.xml">Fault_AddressSize</a>;
        fault.level      = 0;
        return (fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);
    end;

    var baseaddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    let baselsb = ((iasize - (levels*stride + granulebits)) + 3) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
    baseaddress.paspace = if accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> else <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
    baseaddress.address = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(ttbr[39:baselsb]::Zeros{baselsb});

    var walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>;
    walkstate.baseaddress = baseaddress;
    walkstate.level       = startlevel;
    walkstate.istable     = TRUE;
    // In regimes that support global and non-global translations, translation
    // table entries from lookup levels other than the final level of lookup
    // are treated as being non-global
    walkstate.nG          = if <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) then '1' else '0';
    walkstate.memattrs    = <a link="func_WalkMemAttrs_3" file="shared_pseudocode.xml">WalkMemAttrs</a>(walkparams.sh, walkparams.irgn, walkparams.orgn);
    walkstate.permissions.ap_table  = '00';
    walkstate.permissions.xn_table  = '0';
    walkstate.permissions.pxn_table = '0';

    var descriptor : bits(64);
    var walkaddress : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;

    walkaddress.vaddress = ZeroExtend{64}(va);

    if !<a link="func_AArch32_S1DCacheEnabled_1" file="shared_pseudocode.xml">AArch32_S1DCacheEnabled</a>(regime) then
        walkaddress.memattrs = <a link="func_NormalNCMemAttr_0" file="shared_pseudocode.xml">NormalNCMemAttr</a>();
        walkaddress.memattrs.xs = walkstate.memattrs.xs;
    else
        walkaddress.memattrs = walkstate.memattrs;
    end;

    // Shareability value of stage 1 translation subject to stage 2 is IMPLEMENTATION DEFINED
    // to be either effective value or descriptor value
    if (regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_AArch32_EL2Enabled_1" file="shared_pseudocode.xml">AArch32_EL2Enabled</a>(accdesc.ss) &amp;&amp;
        (if <a link="func_ELStateUsingAArch32_2" file="shared_pseudocode.xml">ELStateUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, accdesc.ss==<a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>) then HCR().VM
                                                            else HCR_EL2().VM) == '1' &amp;&amp;
        !(ImpDefBool(&quot;Apply effective shareability at stage 1&quot;))) then
        walkaddress.memattrs.shareability = walkstate.memattrs.shareability;
    else
        walkaddress.memattrs.shareability = <a link="func_EffectiveShareability_1" file="shared_pseudocode.xml">EffectiveShareability</a>(walkaddress.memattrs);
    end;

    var desctype : <a link="type_DescriptorType" file="shared_pseudocode.xml">DescriptorType</a>;
    var msb_residual : integer = iasize - 1;
    repeat
        fault.level = walkstate.level;
        let indexlsb = ((<a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - walkstate.level)*stride + granulebits) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
        let indexmsb = msb_residual as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
        let index : bits(40) = ZeroExtend{}(va[indexmsb:indexlsb]::'000');

        walkaddress.paddress.address = (walkstate.baseaddress.address OR
                                            ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(index));
        walkaddress.paddress.paspace = walkstate.baseaddress.paspace;

        let toplevel : boolean = walkstate.level == startlevel;
        let walkaccess : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescS1TTW_3" file="shared_pseudocode.xml">CreateAccDescS1TTW</a>(toplevel, varange, accdesc);
        // If there are two stages of translation, then the first stage table walk addresses
        // are themselves subject to translation
        if regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_AArch32_EL2Enabled_1" file="shared_pseudocode.xml">AArch32_EL2Enabled</a>(accdesc.ss) then
            let s2aligned : boolean = TRUE;
            let (s2fault, s2walkaddress) = <a link="func_AArch32_S2Translate_4" file="shared_pseudocode.xml">AArch32_S2Translate</a>(fault, walkaddress, s2aligned,
                                                               walkaccess);
            // Check for a fault on the stage 2 walk
            if s2fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
                return (s2fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);
            end;

            (fault, descriptor) = <a link="func_FetchDescriptor_5" file="shared_pseudocode.xml">FetchDescriptor</a>{64}(walkparams.ee, s2walkaddress, walkaccess,
                                                      fault);
        else
            (fault, descriptor) = <a link="func_FetchDescriptor_5" file="shared_pseudocode.xml">FetchDescriptor</a>{64}(walkparams.ee, walkaddress, walkaccess,
                                                      fault);
        end;

        if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
            return (fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);
        end;

        desctype = <a link="func_AArch32_DecodeDescriptorTypeLD_2" file="shared_pseudocode.xml">AArch32_DecodeDescriptorTypeLD</a>(descriptor, walkstate.level);

        case desctype of
            when <a link="enum_DescriptorType_Table" file="shared_pseudocode.xml">DescriptorType_Table</a> =&gt;
                if !IsZero(descriptor[47:40]) then
                    fault.statuscode = <a link="enum_Fault_AddressSize" file="shared_pseudocode.xml">Fault_AddressSize</a>;
                    return (fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);
                end;

                walkstate.baseaddress.address = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(descriptor[39:12]::
                                                                       Zeros{12});
                if walkstate.baseaddress.paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> &amp;&amp; descriptor[63] == '1' then
                    walkstate.baseaddress.paspace = <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
                end;
                if walkparams.hpd == '0' then
                    walkstate.permissions.xn_table  = (walkstate.permissions.xn_table  OR
                                                        descriptor[60]);
                    walkstate.permissions.ap_table  = (walkstate.permissions.ap_table  OR
                                                        descriptor[62:61]);
                    walkstate.permissions.pxn_table = (walkstate.permissions.pxn_table OR
                                                        descriptor[59]);
                end;
                walkstate.level = walkstate.level + 1;
                msb_residual = indexlsb - 1;

            when <a link="enum_DescriptorType_Invalid" file="shared_pseudocode.xml">DescriptorType_Invalid</a> =&gt;
                fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
                return (fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);

            when <a link="enum_DescriptorType_Leaf" file="shared_pseudocode.xml">DescriptorType_Leaf</a> =&gt;
                walkstate.istable = FALSE;
        end;

    until desctype == <a link="enum_DescriptorType_Leaf" file="shared_pseudocode.xml">DescriptorType_Leaf</a> looplimit 3;

    // Check the output address is inside the supported range
    if !IsZero(descriptor[47:40]) then
        fault.statuscode = <a link="enum_Fault_AddressSize" file="shared_pseudocode.xml">Fault_AddressSize</a>;
        return (fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);
    end;

    // Check the access flag
    if descriptor[10] == '0' then
        fault.statuscode = <a link="enum_Fault_AccessFlag" file="shared_pseudocode.xml">Fault_AccessFlag</a>;
        return (fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);
    end;

    walkstate.permissions.xn  = descriptor[54];
    walkstate.permissions.pxn = descriptor[53];
    walkstate.permissions.ap  = descriptor[7:6]::'1';
    walkstate.contiguous      = descriptor[52];
    if regime == <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> then
        // All EL2 regime accesses are treated as Global
        walkstate.nG = '0';
    elsif accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> &amp;&amp; walkstate.baseaddress.paspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> then
        // When a PE is using the Long-descriptor translation table format,
        // and is in Secure state, a translation must be treated as non-global,
        // regardless of the value of the nG bit,
        // if NSTable is set to 1 at any level of the translation table walk.
        walkstate.nG = '1';
    else
        walkstate.nG = descriptor[11];
    end;

    let indexlsb = ((<a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - walkstate.level)*stride + granulebits) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
    walkstate.baseaddress.address = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(descriptor[39:indexlsb]::
                                                           Zeros{indexlsb});
    if walkstate.baseaddress.paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> &amp;&amp; descriptor[5] == '1' then
        walkstate.baseaddress.paspace = <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
    end;

    let memattr : bits(3) = descriptor[4:2];
    let sh : bits(2)      = descriptor[9:8];
    let attr : bits(8)    = <a link="func_AArch32_MAIRAttr_2" file="shared_pseudocode.xml">AArch32_MAIRAttr</a>(UInt(memattr), walkparams.mair);
    let s1aarch64 : boolean = FALSE;
    walkstate.memattrs = <a link="func_S1DecodeMemAttrs_3" file="shared_pseudocode.xml">S1DecodeMemAttrs</a>(attr, sh, s1aarch64);

    return (fault, walkstate);
end;</pstext></ps>
    <ps name="aarch32/translation/walk/AArch32_S1WalkSD" mylink="aarch32.translation.walk.AArch32_S1WalkSD" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S1WalkSD()
// ==================
// Traverse stage 1 translation tables in short format to obtain the final descriptor

func <anchor link="func_AArch32_S1WalkSD_4">AArch32_S1WalkSD</anchor>(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
                      accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>, va : bits(32)) =&gt; (<a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>)
begin
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;
    var sctlr : SCTLR_Type;
    var ttbcr : TTBCR_Type;
    var ttbr0 : TTBR0_Type;
    var ttbr1 : TTBR1_Type;
    // Determine correct translation control registers to use.
    if regime == <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a> then
        sctlr = SCTLR_S();
        ttbcr = TTBCR_S();
        ttbr0 = TTBR0_S();
        ttbr1 = TTBR1_S();
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        sctlr = SCTLR_NS();
        ttbcr = TTBCR_NS();
        ttbr0 = TTBR0_NS();
        ttbr1 = TTBR1_NS();
    else
        sctlr = SCTLR();
        ttbcr = TTBCR();
        ttbr0 = TTBR0();
        ttbr1 = TTBR1();
    end;

    assert ttbcr.EAE == '0';
    let ee : bit  = sctlr.EE;
    let afe : bit = sctlr.AFE;
    let tre : bit = sctlr.TRE;
    let ttbcr_n : integer{} = UInt(ttbcr.N);
    let varange : <a link="type_VARange" file="shared_pseudocode.xml">VARange</a> = (if ttbcr_n == 0 || IsZero(va[31:(32-ttbcr_n)]) then <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a>
                                else <a link="enum_VARange_UPPER" file="shared_pseudocode.xml">VARange_UPPER</a>);
    let n : integer{} = if varange == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then ttbcr_n else 0;
    var ttb : bits(32);
    var pd : bits(1);
    var irgn : bits(2);
    var rgn : bits(2);
    var s : bits(1);
    var nos : bits(1);
    if varange == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then
        ttb  = ttbr0.TTB0::Zeros{7};
        pd   = ttbcr.PD0;
        irgn = ttbr0.IRGN;
        rgn  = ttbr0.RGN;
        s    = ttbr0.S;
        nos  = ttbr0.NOS;
    else
        ttb  = ttbr1.TTB1::Zeros{7};
        pd   = ttbcr.PD1;
        irgn = ttbr1.IRGN;
        rgn  = ttbr1.RGN;
        s    = ttbr1.S;
        nos  = ttbr1.NOS;
    end;

    // Check if Translation table walk disabled for translations with this Base register.
    if pd == '1' then
        fault.level      = 1;
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
        return (fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);
    end;

    var baseaddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    baseaddress.paspace = if accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> else <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
    baseaddress.address = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(ttb[31:14-n]::Zeros{14-n});

    let startlevel : integer = 1;
    var walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>;
    walkstate.baseaddress = baseaddress;
    // In regimes that support global and non-global translations, translation
    // table entries from lookup levels other than the final level of lookup
    // are treated as being non-global. Translations in Short-Descriptor Format
    // always support global &amp; non-global translations.
    walkstate.nG          = '1';
    walkstate.memattrs    = <a link="func_WalkMemAttrs_3" file="shared_pseudocode.xml">WalkMemAttrs</a>(s::nos, irgn, rgn);
    walkstate.level       = startlevel;
    walkstate.istable     = TRUE;

    var domain : bits(4);
    var descriptor : bits(32);
    var walkaddress : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;

    walkaddress.vaddress = ZeroExtend{64}(va);

    if !<a link="func_AArch32_S1DCacheEnabled_1" file="shared_pseudocode.xml">AArch32_S1DCacheEnabled</a>(regime) then
        walkaddress.memattrs = <a link="func_NormalNCMemAttr_0" file="shared_pseudocode.xml">NormalNCMemAttr</a>();
        walkaddress.memattrs.xs = walkstate.memattrs.xs;
    else
        walkaddress.memattrs = walkstate.memattrs;
    end;

    // Shareability value of stage 1 translation subject to stage 2 is IMPLEMENTATION DEFINED
    // to be either effective value or descriptor value
    if (regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_AArch32_EL2Enabled_1" file="shared_pseudocode.xml">AArch32_EL2Enabled</a>(accdesc.ss) &amp;&amp;
        (if <a link="func_ELStateUsingAArch32_2" file="shared_pseudocode.xml">ELStateUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, accdesc.ss==<a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>) then HCR().VM
                                                            else HCR_EL2().VM) == '1' &amp;&amp;
        !(ImpDefBool(&quot;Apply effective shareability at stage 1&quot;))) then
        walkaddress.memattrs.shareability = walkstate.memattrs.shareability;
    else
        walkaddress.memattrs.shareability = <a link="func_EffectiveShareability_1" file="shared_pseudocode.xml">EffectiveShareability</a>(walkaddress.memattrs);
    end;

    var nG : bit;
    var ns : bit;
    var pxn : bit;
    var ap : bits(3);
    var tex : bits(3);
    var c : bit;
    var b : bit;
    var xn : bit;
    repeat
        fault.level = walkstate.level;

        var index : bits(32);
        if walkstate.level == 1 then
            index = ZeroExtend{32}(va[31-n:20]::'00');
        else
            index = ZeroExtend{32}(va[19:12]::'00');
        end;

        walkaddress.paddress.address = (walkstate.baseaddress.address OR
                                            ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(index));
        walkaddress.paddress.paspace = walkstate.baseaddress.paspace;

        let toplevel : boolean = walkstate.level == startlevel;
        let walkaccess : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescS1TTW_3" file="shared_pseudocode.xml">CreateAccDescS1TTW</a>(toplevel, varange, accdesc);
        if regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_AArch32_EL2Enabled_1" file="shared_pseudocode.xml">AArch32_EL2Enabled</a>(accdesc.ss) then
            let s2aligned : boolean = TRUE;
            let (s2fault, s2walkaddress) = <a link="func_AArch32_S2Translate_4" file="shared_pseudocode.xml">AArch32_S2Translate</a>(fault, walkaddress, s2aligned,
                                                               walkaccess);

            if s2fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
                return (s2fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);
            end;

            (fault, descriptor) = <a link="func_FetchDescriptor_5" file="shared_pseudocode.xml">FetchDescriptor</a>{32}(ee, s2walkaddress, walkaccess, fault);
        else
            (fault, descriptor) = <a link="func_FetchDescriptor_5" file="shared_pseudocode.xml">FetchDescriptor</a>{32}(ee, walkaddress, walkaccess, fault);
        end;

        if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
            return (fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);
        end;

        walkstate.sdftype = <a link="func_AArch32_DecodeDescriptorTypeSD_2" file="shared_pseudocode.xml">AArch32_DecodeDescriptorTypeSD</a>(descriptor, walkstate.level);

        case walkstate.sdftype of
            when <a link="enum_SDFType_Invalid" file="shared_pseudocode.xml">SDFType_Invalid</a> =&gt;
                fault.domain     = domain;
                fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
                return (fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);

            when <a link="enum_SDFType_Table" file="shared_pseudocode.xml">SDFType_Table</a> =&gt;
                domain = descriptor[8:5];
                ns     = descriptor[3];
                pxn    = descriptor[2];

                walkstate.baseaddress.address = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(descriptor[31:10]::
                                                                       Zeros{10});
                walkstate.level = 2;

            when <a link="enum_SDFType_SmallPage" file="shared_pseudocode.xml">SDFType_SmallPage</a> =&gt;
                nG  = descriptor[11];
                s   = descriptor[10];
                ap  = descriptor[9,5:4];
                tex = descriptor[8:6];
                c   = descriptor[3];
                b   = descriptor[2];
                xn  = descriptor[0];

                walkstate.baseaddress.address = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(descriptor[31:12]::
                                                                       Zeros{12});
                walkstate.istable = FALSE;

            when <a link="enum_SDFType_LargePage" file="shared_pseudocode.xml">SDFType_LargePage</a> =&gt;
                xn  = descriptor[15];
                tex = descriptor[14:12];
                nG  = descriptor[11];
                s   = descriptor[10];
                ap  = descriptor[9,5:4];
                c   = descriptor[3];
                b   = descriptor[2];

                walkstate.baseaddress.address = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(descriptor[31:16]::
                                                                       Zeros{16});
                walkstate.istable = FALSE;

            when <a link="enum_SDFType_Section" file="shared_pseudocode.xml">SDFType_Section</a> =&gt;
                ns     = descriptor[19];
                nG     = descriptor[17];
                s      = descriptor[16];
                ap     = descriptor[15,11:10];
                tex    = descriptor[14:12];
                domain = descriptor[8:5];
                xn     = descriptor[4];
                c      = descriptor[3];
                b      = descriptor[2];
                pxn    = descriptor[0];

                walkstate.baseaddress.address = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(descriptor[31:20]::
                                                                       Zeros{20});
                walkstate.istable = FALSE;

            when <a link="enum_SDFType_Supersection" file="shared_pseudocode.xml">SDFType_Supersection</a> =&gt;
                ns     = descriptor[19];
                nG     = descriptor[17];
                s      = descriptor[16];
                ap     = descriptor[15,11:10];
                tex    = descriptor[14:12];
                xn     = descriptor[4];
                c      = descriptor[3];
                b      = descriptor[2];
                pxn    = descriptor[0];
                domain = '0000';

                walkstate.baseaddress.address = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(descriptor[8:5,23:20,31:24]::
                                                                       Zeros{24});

                walkstate.istable = FALSE;
        end;

    until walkstate.sdftype != <a link="enum_SDFType_Table" file="shared_pseudocode.xml">SDFType_Table</a> looplimit 2;

    if afe == '1' &amp;&amp; ap[0] == '0' then
        fault.domain     = domain;
        fault.statuscode = <a link="enum_Fault_AccessFlag" file="shared_pseudocode.xml">Fault_AccessFlag</a>;
        return (fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);
    end;

    // Decode the TEX, C, B and S bits to produce target memory attributes
    if tre == '1' then
        walkstate.memattrs = <a link="func_AArch32_RemappedTEXDecode_5" file="shared_pseudocode.xml">AArch32_RemappedTEXDecode</a>(regime, tex, c, b, s);
    elsif <a link="func_RemapRegsHaveResetValues_0" file="shared_pseudocode.xml">RemapRegsHaveResetValues</a>() then
        walkstate.memattrs = <a link="func_AArch32_DefaultTEXDecode_4" file="shared_pseudocode.xml">AArch32_DefaultTEXDecode</a>(tex, c, b, s);
    else
        walkstate.memattrs = ImpDefMemoryAttributes(&quot;IMPLEMENTATION_DEFINED&quot;);
    end;

    walkstate.permissions.ap  = ap;
    walkstate.permissions.xn  = xn;
    walkstate.permissions.pxn = pxn;
    walkstate.domain = domain;
    walkstate.nG     = nG;

    if accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> &amp;&amp; ns == '0' then
        walkstate.baseaddress.paspace = <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>;
    else
        walkstate.baseaddress.paspace = <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
    end;


    return (fault, walkstate);
end;</pstext></ps>
    <ps name="aarch32/translation/walk/AArch32_S2IASize" mylink="aarch32.translation.walk.AArch32_S2IASize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S2IASize()
// ==================
// Retrieve the number of bits containing the input address for stage 2 translation

func <anchor link="func_AArch32_S2IASize_1">AArch32_S2IASize</anchor>(t0sz : bits(4)) =&gt; <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>
begin
    return 32 - SInt(t0sz);
end;</pstext></ps>
    <ps name="aarch32/translation/walk/AArch32_S2StartLevel" mylink="aarch32.translation.walk.AArch32_S2StartLevel" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S2StartLevel()
// ======================
// Determine the initial lookup level when performing a stage 2 translation
// table walk

func <anchor link="func_AArch32_S2StartLevel_1">AArch32_S2StartLevel</anchor>(sl0 : bits(2)) =&gt; integer
begin
    return 2 - UInt(sl0);
end;</pstext></ps>
    <ps name="aarch32/translation/walk/AArch32_S2Walk" mylink="aarch32.translation.walk.AArch32_S2Walk" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S2Walk()
// ================
// Traverse stage 2 translation tables in long format to obtain the final descriptor

func <anchor link="func_AArch32_S2Walk_4">AArch32_S2Walk</anchor>(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>,
                    accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>, ipa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>) =&gt; (<a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>)
begin
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;

    if walkparams.sl0 == '1x' || <a link="func_AArch32_S2InconsistentSL_1" file="shared_pseudocode.xml">AArch32_S2InconsistentSL</a>(walkparams) then
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
        fault.level      = 1;
        return (fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);
    end;

    // Input Address size
    let iasize : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>      = <a link="func_AArch32_S2IASize_1" file="shared_pseudocode.xml">AArch32_S2IASize</a>(walkparams.t0sz);
    let startlevel : integer  = <a link="func_AArch32_S2StartLevel_1" file="shared_pseudocode.xml">AArch32_S2StartLevel</a>(walkparams.sl0);
    let levels : integer      = <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - startlevel;
    let granulebits : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_TGxGranuleBits_1" file="shared_pseudocode.xml">TGxGranuleBits</a>(walkparams.tgx);
    let stride : integer{}      = granulebits - 3;

    if !IsZero(VTTBR()[47:40]) then
        fault.statuscode = <a link="enum_Fault_AddressSize" file="shared_pseudocode.xml">Fault_AddressSize</a>;
        fault.level      = 0;
        return (fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);
    end;

    var baseaddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    let baselsb = ((iasize - (levels*stride + granulebits)) + 3) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
    baseaddress.paspace = <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
    baseaddress.address = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(VTTBR()[39:baselsb]::Zeros{baselsb});

    var walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>;
    walkstate.baseaddress = baseaddress;
    walkstate.level       = startlevel;
    walkstate.istable     = TRUE;
    walkstate.memattrs    = <a link="func_WalkMemAttrs_3" file="shared_pseudocode.xml">WalkMemAttrs</a>(walkparams.sh, walkparams.irgn,
                                         walkparams.orgn);

    var descriptor : bits(64);
    let walkaccess : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescS2TTW_1" file="shared_pseudocode.xml">CreateAccDescS2TTW</a>(accdesc);
    var walkaddress : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;

    walkaddress.vaddress = ipa.vaddress;

    if HCR2().CD == '1' then
        walkaddress.memattrs = <a link="func_NormalNCMemAttr_0" file="shared_pseudocode.xml">NormalNCMemAttr</a>();
        walkaddress.memattrs.xs = walkstate.memattrs.xs;
    else
        walkaddress.memattrs = walkstate.memattrs;
    end;

    walkaddress.memattrs.shareability = <a link="func_EffectiveShareability_1" file="shared_pseudocode.xml">EffectiveShareability</a>(walkaddress.memattrs);

    var msb_residual : integer = iasize - 1;
    var desctype : <a link="type_DescriptorType" file="shared_pseudocode.xml">DescriptorType</a>;
    repeat
        fault.level = walkstate.level;

        let indexlsb = ((<a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - walkstate.level)*stride + granulebits) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
        let indexmsb = msb_residual as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
        let index : bits(40) = ZeroExtend{}(ipa.paddress.address[indexmsb:indexlsb]::'000');

        walkaddress.paddress.address = (walkstate.baseaddress.address OR
                                        ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(index));
        walkaddress.paddress.paspace = walkstate.baseaddress.paspace;

        (fault, descriptor) = <a link="func_FetchDescriptor_5" file="shared_pseudocode.xml">FetchDescriptor</a>{64}(walkparams.ee, walkaddress, walkaccess, fault);

        if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
            return (fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);
        end;

        desctype = <a link="func_AArch32_DecodeDescriptorTypeLD_2" file="shared_pseudocode.xml">AArch32_DecodeDescriptorTypeLD</a>(descriptor, walkstate.level);

        case desctype of
            when <a link="enum_DescriptorType_Table" file="shared_pseudocode.xml">DescriptorType_Table</a> =&gt;
                if !IsZero(descriptor[47:40]) then
                    fault.statuscode = <a link="enum_Fault_AddressSize" file="shared_pseudocode.xml">Fault_AddressSize</a>;
                    return (fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);
                end;

                walkstate.baseaddress.address = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(descriptor[39:12]::
                                                                       Zeros{12});
                walkstate.level = walkstate.level + 1;
                msb_residual = indexlsb - 1;

            when <a link="enum_DescriptorType_Invalid" file="shared_pseudocode.xml">DescriptorType_Invalid</a> =&gt;
                fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
                return (fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);

            when <a link="enum_DescriptorType_Leaf" file="shared_pseudocode.xml">DescriptorType_Leaf</a> =&gt;
                walkstate.istable = FALSE;
        end;

    until desctype == <a link="enum_DescriptorType_Leaf" file="shared_pseudocode.xml">DescriptorType_Leaf</a> looplimit 3;

    // Check the output address is inside the supported range
    if !IsZero(descriptor[47:40]) then
        fault.statuscode = <a link="enum_Fault_AddressSize" file="shared_pseudocode.xml">Fault_AddressSize</a>;
        return (fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);
    end;

    // Check the access flag
    if descriptor[10] == '0' then
        fault.statuscode = <a link="enum_Fault_AccessFlag" file="shared_pseudocode.xml">Fault_AccessFlag</a>;
        return (fault, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>);
    end;

    // Unpack the descriptor into address and upper and lower block attributes
    let indexlsb = ((<a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - walkstate.level)*stride + granulebits) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
    walkstate.baseaddress.address = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(descriptor[39:indexlsb]::
                                                           Zeros{indexlsb});

    walkstate.permissions.s2ap = descriptor[7:6];
    walkstate.permissions.s2xn = descriptor[54];
    if IsFeatureImplemented(FEAT_XNX) then
        walkstate.permissions.s2xnx = descriptor[53];
    else
        walkstate.permissions.s2xnx = '0';
    end;

    let memattr : bits(4) = descriptor[5:2];
    let sh : bits(2)      = descriptor[9:8];
    let s2aarch64 : boolean = FALSE;
    walkstate.memattrs   = <a link="func_S2DecodeMemAttrs_3" file="shared_pseudocode.xml">S2DecodeMemAttrs</a>(memattr, sh, s2aarch64);
    walkstate.contiguous = descriptor[52];


    return (fault, walkstate);
end;</pstext></ps>
    <ps name="aarch32/translation/walk/RemapRegsHaveResetValues" mylink="aarch32.translation.walk.RemapRegsHaveResetValues" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// RemapRegsHaveResetValues()
// ==========================

impdef func <anchor link="func_RemapRegsHaveResetValues_0">RemapRegsHaveResetValues</anchor>() =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="aarch32/translation/walkparams/AArch32_GetS1TTWParams" mylink="aarch32.translation.walkparams.AArch32_GetS1TTWParams" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_GetS1TTWParams()
// ========================
// Returns stage 1 translation table walk parameters from respective controlling
// System registers.

func <anchor link="func_AArch32_GetS1TTWParams_2">AArch32_GetS1TTWParams</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, va : bits(32)) =&gt; <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>
begin
    var walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>;

    case regime of
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a>  =&gt; walkparams = <a link="func_AArch32_S1TTWParamsEL2_0" file="shared_pseudocode.xml">AArch32_S1TTWParamsEL2</a>();
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt; walkparams = <a link="func_AArch32_S1TTWParamsEL10_1" file="shared_pseudocode.xml">AArch32_S1TTWParamsEL10</a>(va);
        when <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a> =&gt; walkparams = <a link="func_AArch32_S1TTWParamsEL30_1" file="shared_pseudocode.xml">AArch32_S1TTWParamsEL30</a>(va);
    end;

    return walkparams;
end;</pstext></ps>
    <ps name="aarch32/translation/walkparams/AArch32_GetS2TTWParams" mylink="aarch32.translation.walkparams.AArch32_GetS2TTWParams" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_GetS2TTWParams()
// ========================
// Gather walk parameters for stage 2 translation

func <anchor link="func_AArch32_GetS2TTWParams_0">AArch32_GetS2TTWParams</anchor>() =&gt; <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>
begin
    var walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>;

    walkparams.tgx  = <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>;
    walkparams.s    = VTCR().S;
    walkparams.t0sz = VTCR().T0SZ;
    walkparams.sl0  = VTCR().SL0;
    walkparams.irgn = VTCR().IRGN0;
    walkparams.orgn = VTCR().ORGN0;
    walkparams.sh   = VTCR().SH0;
    walkparams.ee   = HSCTLR().EE;
    walkparams.ptw  = HCR().PTW;
    walkparams.vm   = HCR().VM OR HCR().DC;

    // VTCR.S must match VTCR.T0SZ[3]
    if walkparams.s != walkparams.t0sz[3] then
        (-, walkparams.t0sz) = ConstrainUnpredictableBits{4}(<a link="enum_Unpredictable_RESVTCRS" file="shared_pseudocode.xml">Unpredictable_RESVTCRS</a>);
    end;

    return walkparams;
end;</pstext></ps>
    <ps name="aarch32/translation/walkparams/AArch32_GetVARange" mylink="aarch32.translation.walkparams.AArch32_GetVARange" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_GetVARange()
// ====================
// Select the translation base address for stage 1 long-descriptor walks

func <anchor link="func_AArch32_GetVARange_3">AArch32_GetVARange</anchor>(va : bits(32), t0sz : bits(3), t1sz : bits(3)) =&gt; <a link="type_VARange" file="shared_pseudocode.xml">VARange</a>
begin
    // Lower range Input Address size
    let lo_iasize : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_AArch32_S1IASize_1" file="shared_pseudocode.xml">AArch32_S1IASize</a>(t0sz);
    // Upper range Input Address size
    let up_iasize : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_AArch32_S1IASize_1" file="shared_pseudocode.xml">AArch32_S1IASize</a>(t1sz);

    if t1sz == '000' &amp;&amp; t0sz == '000' then
        return <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a>;
    elsif t1sz == '000' then
        return if IsZero(va[31:lo_iasize]) then <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> else <a link="enum_VARange_UPPER" file="shared_pseudocode.xml">VARange_UPPER</a>;
    elsif t0sz == '000' then
        return if IsOnes(va[31:up_iasize]) then <a link="enum_VARange_UPPER" file="shared_pseudocode.xml">VARange_UPPER</a> else <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a>;
    elsif IsZero(va[31:lo_iasize]) then
        return <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a>;
    elsif IsOnes(va[31:up_iasize]) then
        return <a link="enum_VARange_UPPER" file="shared_pseudocode.xml">VARange_UPPER</a>;
    else
        // Will be reported as a Translation Fault
        return ARBITRARY : <a link="type_VARange" file="shared_pseudocode.xml">VARange</a>;
    end;
end;</pstext></ps>
    <ps name="aarch32/translation/walkparams/AArch32_S1DCacheEnabled" mylink="aarch32.translation.walkparams.AArch32_S1DCacheEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S1DCacheEnabled()
// =========================
// Determine cacheability of stage 1 data accesses

func <anchor link="func_AArch32_S1DCacheEnabled_1">AArch32_S1DCacheEnabled</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>) =&gt; boolean
begin
    case regime of
        when <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a> =&gt; return SCTLR_S().C == '1';
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a>  =&gt; return HSCTLR().C == '1';
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt;
            return (if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then SCTLR_NS().C else SCTLR().C) == '1';
    end;
end;</pstext></ps>
    <ps name="aarch32/translation/walkparams/AArch32_S1ICacheEnabled" mylink="aarch32.translation.walkparams.AArch32_S1ICacheEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S1ICacheEnabled()
// =========================
// Determine cacheability of stage 1 instruction fetches

func <anchor link="func_AArch32_S1ICacheEnabled_1">AArch32_S1ICacheEnabled</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>) =&gt; boolean
begin
    case regime of
        when <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a> =&gt; return SCTLR_S().I == '1';
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a>  =&gt; return HSCTLR().I == '1';
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt;
            return (if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then SCTLR_NS().I else SCTLR().I) == '1';
    end;
end;</pstext></ps>
    <ps name="aarch32/translation/walkparams/AArch32_S1TTWParamsEL10" mylink="aarch32.translation.walkparams.AArch32_S1TTWParamsEL10" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S1TTWParamsEL10()
// =========================
// Gather stage 1 translation table walk parameters for EL1&amp;0 regime
// (with EL2 enabled or disabled).

func <anchor link="func_AArch32_S1TTWParamsEL10_1">AArch32_S1TTWParamsEL10</anchor>(va : bits(32)) =&gt; <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>
begin
    var mair : bits(64);
    var sif : bit;
    var ttbcr : TTBCR_Type;
    var ttbcr2 : TTBCR2_Type;
    var sctlr : SCTLR_Type;

    if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        ttbcr  = TTBCR_NS();
        ttbcr2 = TTBCR2_NS();
        sctlr  = SCTLR_NS();
        mair   = MAIR1_NS()::MAIR0_NS();
        sif    = SCR().SIF;
    else
        ttbcr  = TTBCR();
        ttbcr2 = TTBCR2();
        sctlr  = SCTLR();
        mair   = MAIR1()::MAIR0();
        sif    = if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then SCR_EL3().SIF else '0';
    end;

    assert ttbcr.EAE == '1';
    var walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>;

    walkparams.t0sz   = ttbcr.T0SZ;
    walkparams.t1sz   = ttbcr.T1SZ;
    walkparams.ee     = sctlr.EE;
    walkparams.wxn    = sctlr.WXN;
    walkparams.uwxn   = sctlr.UWXN;
    walkparams.ntlsmd = if IsFeatureImplemented(FEAT_LSMAOC) then sctlr.nTLSMD else '1';
    walkparams.mair   = mair;
    walkparams.sif    = sif;

    let varange : <a link="type_VARange" file="shared_pseudocode.xml">VARange</a> = <a link="func_AArch32_GetVARange_3" file="shared_pseudocode.xml">AArch32_GetVARange</a>(va, walkparams.t0sz, walkparams.t1sz);
    if varange == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then
        walkparams.sh   = ttbcr.SH0;
        walkparams.irgn = ttbcr.IRGN0;
        walkparams.orgn = ttbcr.ORGN0;
        walkparams.hpd  = (if IsFeatureImplemented(FEAT_AA32HPD) then ttbcr.T2E AND ttbcr2.HPD0
                           else '0');
    else
        walkparams.sh   = ttbcr.SH1;
        walkparams.irgn = ttbcr.IRGN1;
        walkparams.orgn = ttbcr.ORGN1;
        walkparams.hpd  = (if IsFeatureImplemented(FEAT_AA32HPD) then ttbcr.T2E AND ttbcr2.HPD1
                           else '0');
    end;

    return walkparams;
end;</pstext></ps>
    <ps name="aarch32/translation/walkparams/AArch32_S1TTWParamsEL2" mylink="aarch32.translation.walkparams.AArch32_S1TTWParamsEL2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S1TTWParamsEL2()
// ========================
// Gather stage 1 translation table walk parameters for EL2 regime

func <anchor link="func_AArch32_S1TTWParamsEL2_0">AArch32_S1TTWParamsEL2</anchor>() =&gt; <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>
begin
    var walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>;

    walkparams.tgx  = <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>;
    walkparams.t0sz = HTCR().T0SZ;
    walkparams.irgn = HTCR().IRGN0;
    walkparams.orgn = HTCR().ORGN0;
    walkparams.sh   = HTCR().SH0;
    walkparams.hpd  = if IsFeatureImplemented(FEAT_AA32HPD) then HTCR().HPD else '0';
    walkparams.ee   = HSCTLR().EE;
    walkparams.wxn  = HSCTLR().WXN;
    if IsFeatureImplemented(FEAT_LSMAOC) then
        walkparams.ntlsmd = HSCTLR().nTLSMD;
    else
        walkparams.ntlsmd = '1';
    end;

    walkparams.mair = HMAIR1()::HMAIR0();

    return walkparams;
end;</pstext></ps>
    <ps name="aarch32/translation/walkparams/AArch32_S1TTWParamsEL30" mylink="aarch32.translation.walkparams.AArch32_S1TTWParamsEL30" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_S1TTWParamsEL30()
// =========================
// Gather stage 1 translation table walk parameters for EL3&amp;0 regime

func <anchor link="func_AArch32_S1TTWParamsEL30_1">AArch32_S1TTWParamsEL30</anchor>(va : bits(32)) =&gt; <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>
begin
    assert TTBCR_S().EAE == '1';
    var walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>;

    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 : <a link="type_VARange" file="shared_pseudocode.xml">VARange</a> = <a link="func_AArch32_GetVARange_3" file="shared_pseudocode.xml">AArch32_GetVARange</a>(va, walkparams.t0sz, walkparams.t1sz);
    if varange == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> 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;</pstext></ps>
    <ps name="aarch64/debug/brbe" mylink="aarch64.debug.brbe" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Contents of the Branch Record Buffer
//=====================================

var <anchor link="global_Records_SRC">Records_SRC</anchor> : array [[64]] of BRBSRC_EL1_Type;
var <anchor link="global_Records_TGT">Records_TGT</anchor> : array [[64]] of BRBTGT_EL1_Type;
var <anchor link="global_Records_INF">Records_INF</anchor> : array [[64]] of BRBINF_EL1_Type;



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

func <anchor link="func_BRBSRC_EL1_1">BRBSRC_EL1</anchor>(n : integer) =&gt; BRBSRC_EL1_Type
begin
    assert n IN {0..31};
    let record_index : integer = UInt(BRBFCR_EL1().BANK::n[4:0]);
    if record_index &lt; <a link="func_GetBRBENumRecords_0" file="shared_pseudocode.xml">GetBRBENumRecords</a>() then
        return <a link="global_Records_SRC" file="shared_pseudocode.xml">Records_SRC</a>[[record_index]];
    else
        return Zeros{64};
    end;
end;

func <anchor link="func_BRBTGT_EL1_1">BRBTGT_EL1</anchor>(n : integer) =&gt; BRBTGT_EL1_Type
begin
    assert n IN {0..31};
    let record_index : integer = UInt(BRBFCR_EL1().BANK::n[4:0]);
    if record_index &lt; <a link="func_GetBRBENumRecords_0" file="shared_pseudocode.xml">GetBRBENumRecords</a>() then
        return <a link="global_Records_TGT" file="shared_pseudocode.xml">Records_TGT</a>[[record_index]];
    else
        return Zeros{64};
    end;
end;

func <anchor link="func_BRBINF_EL1_1">BRBINF_EL1</anchor>(n : integer) =&gt; BRBINF_EL1_Type
begin
    assert n IN {0..31};
    let record_index : integer = UInt(BRBFCR_EL1().BANK::n[4:0]);
    if record_index &lt; <a link="func_GetBRBENumRecords_0" file="shared_pseudocode.xml">GetBRBENumRecords</a>() then
        return <a link="global_Records_INF" file="shared_pseudocode.xml">Records_INF</a>[[record_index]];
    else
        return Zeros{64};
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/BRBCycleCountingEnabled" mylink="aarch64.debug.brbe.BRBCycleCountingEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BRBCycleCountingEnabled()
// =========================
// Returns TRUE if the recording of cycle counts is allowed,
// FALSE otherwise.

func <anchor link="func_BRBCycleCountingEnabled_0">BRBCycleCountingEnabled</anchor>() =&gt; boolean
begin
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; BRBCR_EL2().CC == '0' then return FALSE; end;
    if BRBCR_EL1().CC == '0' then return FALSE; end;
    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/BRBEBranch" mylink="aarch64.debug.brbe.BRBEBranch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// 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 <anchor link="func_BRBEBranch_3">BRBEBranch</anchor>(br_type : <a link="type_BranchType" file="shared_pseudocode.xml">BranchType</a>, cond : boolean, target_address : bits(64))
begin
    if <a link="func_BranchRecordAllowed_1" file="shared_pseudocode.xml">BranchRecordAllowed</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) &amp;&amp; <a link="func_FilterBranchRecord_2" file="shared_pseudocode.xml">FilterBranchRecord</a>(br_type, cond) then
        var branch_type : bits(6);
        case br_type of
            when <a link="enum_BranchType_DIR" file="shared_pseudocode.xml">BranchType_DIR</a> =&gt;
                branch_type = if cond then '001000' else '000000';
            when <a link="enum_BranchType_INDIR" file="shared_pseudocode.xml">BranchType_INDIR</a>   =&gt; branch_type = '000001';
            when <a link="enum_BranchType_DIRCALL" file="shared_pseudocode.xml">BranchType_DIRCALL</a> =&gt; branch_type = '000010';
            when <a link="enum_BranchType_INDCALL" file="shared_pseudocode.xml">BranchType_INDCALL</a> =&gt; branch_type = '000011';
            when <a link="enum_BranchType_RET" file="shared_pseudocode.xml">BranchType_RET</a>     =&gt; branch_type = '000101';
            otherwise               =&gt; unreachable;
        end;

        var ccu : bit;
        var cc : bits(14);
        (ccu, cc) = <a link="func_BranchEncCycleCount_0" file="shared_pseudocode.xml">BranchEncCycleCount</a>();
        let el : bits(2) = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
        let mispredict : bit = (if <a link="func_BRBEMispredictAllowed_0" file="shared_pseudocode.xml">BRBEMispredictAllowed</a>() &amp;&amp; <a link="func_BranchMispredict_0" file="shared_pseudocode.xml">BranchMispredict</a>() then '1'
                                else '0');

        <a link="func_UpdateBranchRecordBuffer_8" file="shared_pseudocode.xml">UpdateBranchRecordBuffer</a>(ccu, cc, branch_type, el, mispredict,
                                 '11', <a link="func_PC64_0" file="shared_pseudocode.xml">PC64</a>(), target_address);

        <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_BRB_FILTRATE);
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/BRBEBranchOnISB" mylink="aarch64.debug.brbe.BRBEBranchOnISB" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BRBEBranchOnISB()
// =================
// Returns TRUE if ISBs generate Branch records, and FALSE otherwise.

func <anchor link="func_BRBEBranchOnISB_0">BRBEBranchOnISB</anchor>() =&gt; boolean
begin
    return ImpDefBool(&quot;ISB generates Branch records&quot;);
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/BRBEDebugStateEntry" mylink="aarch64.debug.brbe.BRBEDebugStateEntry" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BRBEDebugStateEntry()
// =====================
// Called to write Debug state entry branch record when BRBE is active.

func <anchor link="func_BRBEDebugStateEntry_1">BRBEDebugStateEntry</anchor>(source_address : bits(64))
begin
    if <a link="func_BranchRecordAllowed_1" file="shared_pseudocode.xml">BranchRecordAllowed</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) then
        let branch_type : bits(6) = '100001';
        var ccu : bit;
        var cc : bits(14);
        (ccu, cc)            = <a link="func_BranchEncCycleCount_0" file="shared_pseudocode.xml">BranchEncCycleCount</a>();
        let el : bits(2)     = '00';
        let mispredict : bit = '0';

        // Debug state is a prohibited region, therefore target_address=0
        <a link="func_UpdateBranchRecordBuffer_8" file="shared_pseudocode.xml">UpdateBranchRecordBuffer</a>(ccu, cc, branch_type, el, mispredict,
                                 '10', source_address, Zeros{64});

        <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_BRB_FILTRATE);
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/BRBEDebugStateExit" mylink="aarch64.debug.brbe.BRBEDebugStateExit" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BRBEDebugStateExit()
// ====================
// Called to write Debug state exit branch record when BRBE is active.

func <anchor link="func_BRBEDebugStateExit_1">BRBEDebugStateExit</anchor>(target_address : bits(64))
begin
    if <a link="func_BranchRecordAllowed_1" file="shared_pseudocode.xml">BranchRecordAllowed</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.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)          = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
        let mispredict : bit      = '0';

        <a link="func_UpdateBranchRecordBuffer_8" file="shared_pseudocode.xml">UpdateBranchRecordBuffer</a>(ccu, cc, branch_type, el, mispredict,
                                 '01', Zeros{64}, target_address);

        <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_BRB_FILTRATE);
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/BRBEException" mylink="aarch64.debug.brbe.BRBEException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BRBEException()
// ===============
// Called to write exception branch record when BRBE is active.

func <anchor link="func_BRBEException_6">BRBEException</anchor>(erec : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>, 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 : <a link="type_Exception" file="shared_pseudocode.xml">Exception</a> = erec.exceptype;
    let iss : bits(25)     = erec.syndrome.iss;
    case target_el of
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            if !IsFeatureImplemented(FEAT_BRBEv1p1) || (MDCR_EL3().E3BREC == MDCR_EL3().E3BREW) then
                return;
            end;
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt; if BRBCR_EL2().EXCEPTION == '0' then return; end;
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt; if BRBCR_EL1().EXCEPTION == '0' then return; end;
    end;

    let target_valid : boolean = <a link="func_BranchRecordAllowed_1" file="shared_pseudocode.xml">BranchRecordAllowed</a>(target_el);

    if source_valid || target_valid then
        var branch_type : bits(6);
        case except of
            when <a link="enum_Exception_Uncategorized" file="shared_pseudocode.xml">Exception_Uncategorized</a>         =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_WFxTrap" file="shared_pseudocode.xml">Exception_WFxTrap</a>               =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_CP15RTTrap" file="shared_pseudocode.xml">Exception_CP15RTTrap</a>            =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_CP15RRTTrap" file="shared_pseudocode.xml">Exception_CP15RRTTrap</a>           =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_CP14RTTrap" file="shared_pseudocode.xml">Exception_CP14RTTrap</a>            =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_CP14DTTrap" file="shared_pseudocode.xml">Exception_CP14DTTrap</a>            =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_AdvSIMDFPAccessTrap" file="shared_pseudocode.xml">Exception_AdvSIMDFPAccessTrap</a>   =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_FPIDTrap" file="shared_pseudocode.xml">Exception_FPIDTrap</a>              =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_PACTrap" file="shared_pseudocode.xml">Exception_PACTrap</a>               =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_CP14RRTTrap" file="shared_pseudocode.xml">Exception_CP14RRTTrap</a>           =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_OtherTrap" file="shared_pseudocode.xml">Exception_OtherTrap</a>             =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_BranchTarget" file="shared_pseudocode.xml">Exception_BranchTarget</a>          =&gt; branch_type = '101011'; // Inst Fault
            when <a link="enum_Exception_IllegalState" file="shared_pseudocode.xml">Exception_IllegalState</a>          =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_SupervisorCall" file="shared_pseudocode.xml">Exception_SupervisorCall</a>        =&gt;
                if !trappedsyscallinst then      branch_type = '100010';    // Call
                else                             branch_type = '100011';    // Trap
                end;
            when <a link="enum_Exception_HypervisorCall" file="shared_pseudocode.xml">Exception_HypervisorCall</a>        =&gt; branch_type = '100010'; // Call
            when <a link="enum_Exception_MonitorCall" file="shared_pseudocode.xml">Exception_MonitorCall</a>           =&gt;
                if !trappedsyscallinst then      branch_type = '100010';    // Call
                else                             branch_type = '100011';    // Trap
                end;
            when <a link="enum_Exception_SystemRegisterTrap" file="shared_pseudocode.xml">Exception_SystemRegisterTrap</a>    =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_SystemRegister128Trap" file="shared_pseudocode.xml">Exception_SystemRegister128Trap</a> =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_SVEAccessTrap" file="shared_pseudocode.xml">Exception_SVEAccessTrap</a>         =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_SMEAccessTrap" file="shared_pseudocode.xml">Exception_SMEAccessTrap</a>         =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_ERetTrap" file="shared_pseudocode.xml">Exception_ERetTrap</a>              =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_PACFail" file="shared_pseudocode.xml">Exception_PACFail</a>               =&gt; branch_type = '101100'; // Data Fault
            when <a link="enum_Exception_InstructionAbort" file="shared_pseudocode.xml">Exception_InstructionAbort</a>      =&gt; branch_type = '101011'; // Inst Fault
            when <a link="enum_Exception_PCAlignment" file="shared_pseudocode.xml">Exception_PCAlignment</a>           =&gt; branch_type = '101010'; // Alignment
            when <a link="enum_Exception_DataAbort" file="shared_pseudocode.xml">Exception_DataAbort</a>             =&gt; branch_type = '101100'; // Data Fault
            when <a link="enum_Exception_NV2DataAbort" file="shared_pseudocode.xml">Exception_NV2DataAbort</a>          =&gt; branch_type = '101100'; // Data Fault
            when <a link="enum_Exception_SPAlignment" file="shared_pseudocode.xml">Exception_SPAlignment</a>           =&gt; branch_type = '101010'; // Alignment
            when <a link="enum_Exception_FPTrappedException" file="shared_pseudocode.xml">Exception_FPTrappedException</a>    =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_SError" file="shared_pseudocode.xml">Exception_SError</a>                =&gt; branch_type = '100100'; // System Error
            when <a link="enum_Exception_Breakpoint" file="shared_pseudocode.xml">Exception_Breakpoint</a>            =&gt; branch_type = '100110'; // Inst debug
            when <a link="enum_Exception_SoftwareStep" file="shared_pseudocode.xml">Exception_SoftwareStep</a>          =&gt; branch_type = '100110'; // Inst debug
            when <a link="enum_Exception_Watchpoint" file="shared_pseudocode.xml">Exception_Watchpoint</a>            =&gt; branch_type = '100111'; // Data debug
            when <a link="enum_Exception_NV2Watchpoint" file="shared_pseudocode.xml">Exception_NV2Watchpoint</a>         =&gt; branch_type = '100111'; // Data debug
            when <a link="enum_Exception_SoftwareBreakpoint" file="shared_pseudocode.xml">Exception_SoftwareBreakpoint</a>    =&gt; branch_type = '100110'; // Inst debug
            when <a link="enum_Exception_IRQ" file="shared_pseudocode.xml">Exception_IRQ</a>                   =&gt; branch_type = '101110'; // IRQ
            when <a link="enum_Exception_FIQ" file="shared_pseudocode.xml">Exception_FIQ</a>                   =&gt; branch_type = '101111'; // FIQ
            when <a link="enum_Exception_MemCpyMemSet" file="shared_pseudocode.xml">Exception_MemCpyMemSet</a>          =&gt; branch_type = '100011'; // Trap
            when <a link="enum_Exception_GCSFail" file="shared_pseudocode.xml">Exception_GCSFail</a>               =&gt;
                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 <a link="enum_Exception_Profiling" file="shared_pseudocode.xml">Exception_Profiling</a>             =&gt; branch_type = '100110'; // Inst debug
            when <a link="enum_Exception_GPC" file="shared_pseudocode.xml">Exception_GPC</a>                   =&gt;
                if iss[20] == '1' then              branch_type = '101011'; // Inst fault
                else                                branch_type = '101100'; // Data fault
                end;
            otherwise                            =&gt; unreachable;
        end;

        var ccu : bit;
        var cc : bits(14);
        (ccu, cc) = <a link="func_BranchEncCycleCount_0" file="shared_pseudocode.xml">BranchEncCycleCount</a>();
        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 = <a link="func_AArch64_BranchAddr_2" file="shared_pseudocode.xml">AArch64_BranchAddr</a>(target_address, target_el);
        end;

        <a link="func_UpdateBranchRecordBuffer_8" file="shared_pseudocode.xml">UpdateBranchRecordBuffer</a>(ccu, cc, branch_type, el, mispredict,
                                 sv::tv, source_address, target_address);

        <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_BRB_FILTRATE);
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/BRBEExceptionReturn" mylink="aarch64.debug.brbe.BRBEExceptionReturn" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BRBEExceptionReturn()
// =====================
// Called to write exception return branch record when BRBE is active.

func <anchor link="func_BRBEExceptionReturn_4">BRBEExceptionReturn</anchor>(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 <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            if !IsFeatureImplemented(FEAT_BRBEv1p1) || (MDCR_EL3().E3BREC == MDCR_EL3().E3BREW) then
                return;
            end;
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt; if BRBCR_EL2().ERTN == '0' then return; end;
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt; if BRBCR_EL1().ERTN == '0' then return; end;
    end;

    let target_valid : boolean = <a link="func_BranchRecordAllowed_1" file="shared_pseudocode.xml">BranchRecordAllowed</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);

    if source_valid || target_valid then
        let branch_type : bits(6) = '000111';
        var ccu : bit;
        var cc : bits(14);
        (ccu, cc) = <a link="func_BranchEncCycleCount_0" file="shared_pseudocode.xml">BranchEncCycleCount</a>();
        let el : bits(2)     = if target_valid then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL else '00';
        let mispredict : bit = (if source_valid &amp;&amp; <a link="func_BRBEMispredictAllowed_0" file="shared_pseudocode.xml">BRBEMispredictAllowed</a>() &amp;&amp;
                                <a link="func_BranchMispredict_0" file="shared_pseudocode.xml">BranchMispredict</a>() 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;

        <a link="func_UpdateBranchRecordBuffer_8" file="shared_pseudocode.xml">UpdateBranchRecordBuffer</a>(ccu, cc, branch_type, el, mispredict,
                                 sv::tv, source_address, target_address);

        <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_BRB_FILTRATE);
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/BRBEFreeze" mylink="aarch64.debug.brbe.BRBEFreeze" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BRBEFreeze()
// ============
// Generates BRBE freeze event.

func <anchor link="func_BRBEFreeze_0">BRBEFreeze</anchor>()
begin
    BRBFCR_EL1().PAUSED = '1';
    BRBTS_EL1() = <a link="func_GetTimestamp_1" file="shared_pseudocode.xml">GetTimestamp</a>(<a link="func_BRBETimeStamp_0" file="shared_pseudocode.xml">BRBETimeStamp</a>());
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/BRBEISB" mylink="aarch64.debug.brbe.BRBEISB" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BRBEISB()
// =========
// Handles ISB instruction for BRBE.

func <anchor link="func_BRBEISB_0">BRBEISB</anchor>()
begin
    let branch_conditional : boolean = FALSE;
    <a link="func_BRBEBranch_3" file="shared_pseudocode.xml">BRBEBranch</a>(<a link="enum_BranchType_DIR" file="shared_pseudocode.xml">BranchType_DIR</a>, branch_conditional, <a link="func_PC64_0" file="shared_pseudocode.xml">PC64</a>() + 4);
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/BRBEMispredictAllowed" mylink="aarch64.debug.brbe.BRBEMispredictAllowed" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BRBEMispredictAllowed()
// =======================
// Returns TRUE if the recording of branch misprediction is allowed,
// FALSE otherwise.

func <anchor link="func_BRBEMispredictAllowed_0">BRBEMispredictAllowed</anchor>() =&gt; boolean
begin
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; BRBCR_EL2().MPRED == '0' then return FALSE; end;
    if BRBCR_EL1().MPRED == '0' then return FALSE; end;
    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/BRBETimeStamp" mylink="aarch64.debug.brbe.BRBETimeStamp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BRBETimeStamp()
// ===============
// Returns captured timestamp.

func <anchor link="func_BRBETimeStamp_0">BRBETimeStamp</anchor>() =&gt; <a link="type_TimeStamp" file="shared_pseudocode.xml">TimeStamp</a>
begin
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        var TS_el2 : bits(2) = BRBCR_EL2().TS;
        if !IsFeatureImplemented(FEAT_ECV) &amp;&amp; TS_el2 == '10' then
            // Reserved value
            (-, TS_el2) = ConstrainUnpredictableBits{2}(<a link="enum_Unpredictable_EL2TIMESTAMP" file="shared_pseudocode.xml">Unpredictable_EL2TIMESTAMP</a>);
        end;
        case TS_el2 of
            when '00' =&gt;
                // Falls out to check BRBCR_EL1.TS
                pass;
            when '01' =&gt;
                return <a link="enum_TimeStamp_Virtual" file="shared_pseudocode.xml">TimeStamp_Virtual</a>;
            when '10' =&gt;
                assert IsFeatureImplemented(FEAT_ECV); // Otherwise ConstrainUnpredictableBits
                                                       // removes this case
                return <a link="enum_TimeStamp_OffsetPhysical" file="shared_pseudocode.xml">TimeStamp_OffsetPhysical</a>;
            when '11' =&gt;
                return <a link="enum_TimeStamp_Physical" file="shared_pseudocode.xml">TimeStamp_Physical</a>;
        end;
    end;

    var TS_el1 : bits(2) = BRBCR_EL1().TS;
    if TS_el1 == '00' || (!IsFeatureImplemented(FEAT_ECV) &amp;&amp; TS_el1 == '10') then
        // Reserved value
        (-, TS_el1) = ConstrainUnpredictableBits{2}(<a link="enum_Unpredictable_EL1TIMESTAMP" file="shared_pseudocode.xml">Unpredictable_EL1TIMESTAMP</a>);
    end;
    case TS_el1 of
        when '01' =&gt;
            return <a link="enum_TimeStamp_Virtual" file="shared_pseudocode.xml">TimeStamp_Virtual</a>;
        when '10' =&gt;
            return <a link="enum_TimeStamp_OffsetPhysical" file="shared_pseudocode.xml">TimeStamp_OffsetPhysical</a>;
        when '11' =&gt;
            return <a link="enum_TimeStamp_Physical" file="shared_pseudocode.xml">TimeStamp_Physical</a>;
        otherwise =&gt;
            unreachable;           // ConstrainUnpredictableBits removes this case
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/BRB_IALL" mylink="aarch64.debug.brbe.BRB_IALL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BRB_IALL()
// ==========
// Called to perform invalidation of branch records

func <anchor link="func_BRB_IALL_0">BRB_IALL</anchor>()
begin
    let nbrberecords : integer = <a link="func_GetBRBENumRecords_0" file="shared_pseudocode.xml">GetBRBENumRecords</a>();
    for i = 0 to nbrberecords - 1 do
        <a link="global_Records_SRC" file="shared_pseudocode.xml">Records_SRC</a>[[i]] = Zeros{64};
        <a link="global_Records_TGT" file="shared_pseudocode.xml">Records_TGT</a>[[i]] = Zeros{64};
        <a link="global_Records_INF" file="shared_pseudocode.xml">Records_INF</a>[[i]] = Zeros{64};
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/BRB_INJ" mylink="aarch64.debug.brbe.BRB_INJ" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BRB_INJ()
// =========
// Called to perform manual injection of branch records.

func <anchor link="func_BRB_INJ_0">BRB_INJ</anchor>()
begin
    <a link="func_UpdateBranchRecordBuffer_8" file="shared_pseudocode.xml">UpdateBranchRecordBuffer</a>(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 <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BRBFILTRATE" file="shared_pseudocode.xml">Unpredictable_BRBFILTRATE</a>) then
        <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_BRB_FILTRATE);
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/BranchEncCycleCount" mylink="aarch64.debug.brbe.BranchEncCycleCount" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// 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 <anchor link="func_BranchEncCycleCount_0">BranchEncCycleCount</anchor>() =&gt; (bit, bits(14))
begin
    var cc : integer = <a link="func_BranchRawCycleCount_0" file="shared_pseudocode.xml">BranchRawCycleCount</a>();
    if !<a link="func_BRBCycleCountingEnabled_0" file="shared_pseudocode.xml">BRBCycleCountingEnabled</a>() || <a link="func_FirstBranchAfterProhibited_0" file="shared_pseudocode.xml">FirstBranchAfterProhibited</a>() 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 &lt; 2^8 then
        E = Zeros{6};
        M = cc[7:0];
    elsif cc &gt;= 2^20 then
        E = Ones{6};
        M = Ones{8};
    else
        E = 1[5:0];
        while cc &gt;= 2^9 looplimit 11 do
            E = E + 1;
            cc = cc DIVRM 2;
        end;
        M = cc[7:0];
    end;

    return ('0', E::M);
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/BranchMispredict" mylink="aarch64.debug.brbe.BranchMispredict" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BranchMispredict()
// ==================
// Returns TRUE if the branch being executed was mispredicted, FALSE otherwise.

impdef func <anchor link="func_BranchMispredict_0">BranchMispredict</anchor>() =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/BranchRawCycleCount" mylink="aarch64.debug.brbe.BranchRawCycleCount" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BranchRawCycleCount()
// =====================
// If the cycle count is known, the return result is the cycle count since the last branch.

impdef func <anchor link="func_BranchRawCycleCount_0">BranchRawCycleCount</anchor>() =&gt; integer
begin
    return 0;
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/BranchRecordAllowed" mylink="aarch64.debug.brbe.BranchRecordAllowed" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BranchRecordAllowed()
// =====================
// Returns TRUE if branch recording is allowed, FALSE otherwise.

func <anchor link="func_BranchRecordAllowed_1">BranchRecordAllowed</anchor>(el : bits(2)) =&gt; boolean
begin
    if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(el) then
        return FALSE;
    end;

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

    if el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; IsFeatureImplemented(FEAT_BRBEv1p1) then
        return (MDCR_EL3().E3BREC != MDCR_EL3().E3BREW);
    end;

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; (MDCR_EL3().SBRBE == '00' ||
        (<a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> &amp;&amp; MDCR_EL3().SBRBE == '01')) then
        return FALSE;
    end;

    case el of
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;  return FALSE;                // FEAT_BRBEv1p1 not implemented
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;  return BRBCR_EL2().E2BRE == '1';
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;  return BRBCR_EL1().E1BRE == '1';
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1' then
                return BRBCR_EL2().E0HBRE == '1';
            else
                return BRBCR_EL1().E0BRE == '1';
            end;
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/FilterBranchRecord" mylink="aarch64.debug.brbe.FilterBranchRecord" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FilterBranchRecord()
// ====================
// Returns TRUE if the branch record is not filtered out, FALSE otherwise.

func <anchor link="func_FilterBranchRecord_2">FilterBranchRecord</anchor>(br : <a link="type_BranchType" file="shared_pseudocode.xml">BranchType</a>, cond : boolean) =&gt; boolean
begin
    case br of
        when <a link="enum_BranchType_DIRCALL" file="shared_pseudocode.xml">BranchType_DIRCALL</a> =&gt;
            return BRBFCR_EL1().DIRCALL != BRBFCR_EL1().EnI;
        when <a link="enum_BranchType_INDCALL" file="shared_pseudocode.xml">BranchType_INDCALL</a> =&gt;
            return BRBFCR_EL1().INDCALL != BRBFCR_EL1().EnI;
        when <a link="enum_BranchType_RET" file="shared_pseudocode.xml">BranchType_RET</a> =&gt;
            return BRBFCR_EL1().RTN != BRBFCR_EL1().EnI;
        when <a link="enum_BranchType_DIR" file="shared_pseudocode.xml">BranchType_DIR</a> =&gt;
            if cond then
                return BRBFCR_EL1().CONDDIR != BRBFCR_EL1().EnI;
            else
                return BRBFCR_EL1().DIRECT != BRBFCR_EL1().EnI;
            end;
        when <a link="enum_BranchType_INDIR" file="shared_pseudocode.xml">BranchType_INDIR</a> =&gt;
            return BRBFCR_EL1().INDIRECT != BRBFCR_EL1().EnI;
        otherwise =&gt;  unreachable;
    end;
    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/FirstBranchAfterProhibited" mylink="aarch64.debug.brbe.FirstBranchAfterProhibited" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FirstBranchAfterProhibited()
// ============================
// Returns TRUE if branch recorded is the first branch after a prohibited region,
// FALSE otherwise.

impdef func <anchor link="func_FirstBranchAfterProhibited_0">FirstBranchAfterProhibited</anchor>() =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/GetBRBENumRecords" mylink="aarch64.debug.brbe.GetBRBENumRecords" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetBRBENumRecords()
// ===================
// Returns the number of branch records implemented.

func <anchor link="func_GetBRBENumRecords_0">GetBRBENumRecords</anchor>() =&gt; integer
begin
    assert UInt(BRBIDR0_EL1().NUMREC) IN {0x08, 0x10, 0x20, 0x40};
    return ImpDefInt(&quot;Number of BRBE Branch records&quot;);
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/ShouldBRBEFreeze" mylink="aarch64.debug.brbe.ShouldBRBEFreeze" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ShouldBRBEFreeze()
// ==================
// Returns TRUE if the BRBE freeze event conditions have been met, and FALSE otherwise.

func <anchor link="func_ShouldBRBEFreeze_0">ShouldBRBEFreeze</anchor>() =&gt; boolean
begin
    if !<a link="func_BranchRecordAllowed_1" file="shared_pseudocode.xml">BranchRecordAllowed</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) then
        return FALSE;
    end;

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

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        include_r1 = (BRBCR_EL1().FZP == '1');
        include_r2 = (BRBCR_EL2().FZP == '1');
    else
        include_r1 = TRUE;
        include_r2 = TRUE;
    end;

    return <a link="func_CheckPMUOverflowCondition_4" file="shared_pseudocode.xml">CheckPMUOverflowCondition</a>(<a link="enum_PMUOverflowCondition_BRBEFreeze" file="shared_pseudocode.xml">PMUOverflowCondition_BRBEFreeze</a>,
                                     include_r1, include_r2, include_r3);
end;</pstext></ps>
    <ps name="aarch64/debug/brbe/UpdateBranchRecordBuffer" mylink="aarch64.debug.brbe.UpdateBranchRecordBuffer" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// UpdateBranchRecordBuffer()
// ==========================
// Add a new Branch record to the buffer.

func <anchor link="func_UpdateBranchRecordBuffer_8">UpdateBranchRecordBuffer</anchor>(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 = <a link="func_GetBRBENumRecords_0" file="shared_pseudocode.xml">GetBRBENumRecords</a>();
    for i = nbrberecords - 1 downto 1 do
        <a link="global_Records_SRC" file="shared_pseudocode.xml">Records_SRC</a>[[i]] = <a link="global_Records_SRC" file="shared_pseudocode.xml">Records_SRC</a>[[i - 1]];
        <a link="global_Records_TGT" file="shared_pseudocode.xml">Records_TGT</a>[[i]] = <a link="global_Records_TGT" file="shared_pseudocode.xml">Records_TGT</a>[[i - 1]];
        <a link="global_Records_INF" file="shared_pseudocode.xml">Records_INF</a>[[i]] = <a link="global_Records_INF" file="shared_pseudocode.xml">Records_INF</a>[[i - 1]];
    end;

    <a link="global_Records_INF" file="shared_pseudocode.xml">Records_INF</a>[[0]].CCU   = ccu;
    <a link="global_Records_INF" file="shared_pseudocode.xml">Records_INF</a>[[0]].CC    = cc;

    <a link="global_Records_INF" file="shared_pseudocode.xml">Records_INF</a>[[0]].EL    = el;
    <a link="global_Records_INF" file="shared_pseudocode.xml">Records_INF</a>[[0]].VALID = valid;
    <a link="global_Records_INF" file="shared_pseudocode.xml">Records_INF</a>[[0]].MPRED = mispredict;
    <a link="global_Records_INF" file="shared_pseudocode.xml">Records_INF</a>[[0]].TYPE  = branch_type;

    <a link="global_Records_SRC" file="shared_pseudocode.xml">Records_SRC</a>[[0]]       = source_address;
    <a link="global_Records_TGT" file="shared_pseudocode.xml">Records_TGT</a>[[0]]       = target_address;

    return;
end;</pstext></ps>
    <ps name="aarch64/debug/breakpoint/AArch64_BreakpointMatch" mylink="aarch64.debug.breakpoint.AArch64_BreakpointMatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// 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 <anchor link="func_AArch64_BreakpointMatch_4">AArch64_BreakpointMatch</anchor>(n : integer, vaddress : bits(64), accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                             size : integer) =&gt; <a link="type_BreakpointInfo" file="shared_pseudocode.xml">BreakpointInfo</a>
begin
    assert !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>());
    assert n &lt; <a link="func_NumBreakpointsImplemented_0" file="shared_pseudocode.xml">NumBreakpointsImplemented</a>();
    var brkptinfo : <a link="type_BreakpointInfo" file="shared_pseudocode.xml">BreakpointInfo</a>;

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

    // A breakpoint that has linking enabled does not generate debug events in isolation
    if linking_enabled then
        brkptinfo.bptype = <a link="enum_BreakpointType_Inactive" file="shared_pseudocode.xml">BreakpointType_Inactive</a>;
        brkptinfo.match = FALSE;
        return brkptinfo;
    end;

    let enabled : boolean    = <a link="func_IsBreakpointEnabled_1" file="shared_pseudocode.xml">IsBreakpointEnabled</a>(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 = <a link="func_AArch64_StateMatch_9" file="shared_pseudocode.xml">AArch64_StateMatch</a>(DBGBCR_EL1(n).SSC, ssce, DBGBCR_EL1(n).HMC,
                                         DBGBCR_EL1(n).PMC, linked, linked_n, isbreakpnt,
                                         vaddress, accdesc);

    var (bp_type, value_match) = <a link="func_AArch64_BreakpointValueMatch_5" file="shared_pseudocode.xml">AArch64_BreakpointValueMatch</a>(n, vaddress, linked_to, isbreakpnt,
                                                              from_linking_enabled);

    if <a link="func_HaveAArch32_0" file="shared_pseudocode.xml">HaveAArch32</a>() &amp;&amp; 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) = <a link="func_AArch64_BreakpointValueMatch_5" file="shared_pseudocode.xml">AArch64_BreakpointValueMatch</a>(n, vaddress + 2, linked_to, isbreakpnt,
                                                        from_linking_enabled);
        if !value_match &amp;&amp; match_i then
            value_match = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BPMATCHHALF" file="shared_pseudocode.xml">Unpredictable_BPMATCHHALF</a>);
        end;
    end;

    if vaddress[1] == '1' &amp;&amp; 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 = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BPMATCHHALF" file="shared_pseudocode.xml">Unpredictable_BPMATCHHALF</a>);
        end;
    end;

    if !(state_match &amp;&amp; enabled) then
        brkptinfo.bptype = <a link="enum_BreakpointType_Inactive" file="shared_pseudocode.xml">BreakpointType_Inactive</a>;
        brkptinfo.match = FALSE;
    else
        brkptinfo.bptype = bp_type;
        brkptinfo.match = value_match;
    end;
    return brkptinfo;
end;</pstext></ps>
    <ps name="aarch64/debug/breakpoint/AArch64_BreakpointValueMatch" mylink="aarch64.debug.breakpoint.AArch64_BreakpointValueMatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// 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 <anchor link="func_AArch64_BreakpointValueMatch_5">AArch64_BreakpointValueMatch</anchor>(n_in : integer, vaddress : bits(64),
                                  linked_to : boolean, isbreakpnt : boolean,
                                  from_linking_enabled : boolean
                                 ) =&gt; (<a link="type_BreakpointType" file="shared_pseudocode.xml">BreakpointType</a>, boolean) recurselimit 2
begin

    // &quot;n_in&quot; is the identity of the breakpoint unit to match against.
    // &quot;vaddress&quot; is the current instruction address, ignored if linked_to is TRUE and for Context
    //   matching breakpoints.
    // &quot;linked_to&quot; is TRUE if this is a call from StateMatch for linking.
    // &quot;isbreakpnt&quot;  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.
    // &quot;from_linking_enabled&quot; is TRUE if this is a call from BreakpointValueMatch for a linked
    // breakpoint with linking enabled.
    var n : integer = n_in;
    var c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>;
    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 &gt;= <a link="func_NumBreakpointsImplemented_0" file="shared_pseudocode.xml">NumBreakpointsImplemented</a>() then
        (c, n) = <a link="func_ConstrainUnpredictableInteger_3" file="shared_pseudocode.xml">ConstrainUnpredictableInteger</a>(0, <a link="func_NumBreakpointsImplemented_0" file="shared_pseudocode.xml">NumBreakpointsImplemented</a>() - 1,
                                               <a link="enum_Unpredictable_BPNOTIMPL" file="shared_pseudocode.xml">Unpredictable_BPNOTIMPL</a>);
        assert c IN {<a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>, <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>};
        if c == <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a> then return (<a link="enum_BreakpointType_Inactive" file="shared_pseudocode.xml">BreakpointType_Inactive</a>, 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 !<a link="func_IsBreakpointEnabled_1" file="shared_pseudocode.xml">IsBreakpointEnabled</a>(n) then return (<a link="enum_BreakpointType_Inactive" file="shared_pseudocode.xml">BreakpointType_Inactive</a>, 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) = <a link="func_AArch64_ReservedBreakpointType_2" file="shared_pseudocode.xml">AArch64_ReservedBreakpointType</a>(n, dbgtype);
    if c == <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a> then return (<a link="enum_BreakpointType_Inactive" file="shared_pseudocode.xml">BreakpointType_Inactive</a>, 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 &amp;&amp; !linking_enabled then
        return (<a link="enum_BreakpointType_Inactive" file="shared_pseudocode.xml">BreakpointType_Inactive</a>, FALSE);
    end;

    // If called from BreakpointMatch return FALSE for breakpoint with linking enabled.
    if !linked_to &amp;&amp; linking_enabled then
        return (<a link="enum_BreakpointType_Inactive" file="shared_pseudocode.xml">BreakpointType_Inactive</a>, FALSE);
    end;

    let linked : boolean = (dbgtype == 'x0x01');
    if from_linking_enabled then  // A breakpoint with linking enabled has called this function.
        assert linked_to &amp;&amp; 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 (<a link="enum_BreakpointType_Inactive" file="shared_pseudocode.xml">BreakpointType_Inactive</a>, FALSE);
        end;
    end;

    // If a linked breakpoint is linked to an address matching breakpoint,
    // the behavior is CONSTRAINED UNPREDICTABLE.
    if linked_to &amp;&amp; match_addr &amp;&amp; isbreakpnt then
        if !<a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BPLINKEDADDRMATCH" file="shared_pseudocode.xml">Unpredictable_BPLINKEDADDRMATCH</a>) then
            return (<a link="enum_BreakpointType_Inactive" file="shared_pseudocode.xml">BreakpointType_Inactive</a>, FALSE);
        end;
    end;

    // A breakpoint programmed for address mismatch does not match in AArch32 state.
    if mismatch &amp;&amp; <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        return (<a link="enum_BreakpointType_Inactive" file="shared_pseudocode.xml">BreakpointType_Inactive</a>, FALSE);
    end;

    var bvr_match : boolean  = FALSE;
    var bxvr_match : boolean = FALSE;
    var bp_type : <a link="type_BreakpointType" file="shared_pseudocode.xml">BreakpointType</a>;
    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) = <a link="func_ConstrainUnpredictableInteger_3" file="shared_pseudocode.xml">ConstrainUnpredictableInteger</a>(3, 31, <a link="enum_Unpredictable_RESBPMASK" file="shared_pseudocode.xml">Unpredictable_RESBPMASK</a>);
            assert c IN {<a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>, <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>, <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>};
            case c of
                when <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a> =&gt; return (<a link="enum_BreakpointType_Inactive" file="shared_pseudocode.xml">BreakpointType_Inactive</a>, FALSE);  // Disabled
                when <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a> =&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; <a link="func_HaveAArch32_0" file="shared_pseudocode.xml">HaveAArch32</a>())) then
                if !<a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BPMASK" file="shared_pseudocode.xml">Unpredictable_BPMASK</a>) then
                    return (<a link="enum_BreakpointType_Inactive" file="shared_pseudocode.xml">BreakpointType_Inactive</a>, FALSE);
                end;
            end;
        else
            // A stand-alone mismatch of a single address is not supported.
            if mismatch then
                return (<a link="enum_BreakpointType_Inactive" file="shared_pseudocode.xml">BreakpointType_Inactive</a>, 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 <a link="func_HaveAArch32_0" file="shared_pseudocode.xml">HaveAArch32</a>() then
            // T32 instructions can be executed at EL0 in an AArch64 translation regime.
            assert byte IN {0,2};                       // &quot;vaddress&quot; is halfword aligned
            byte_select_match = (DBGBCR_EL1(n).BAS[byte] == '1');
        else
            assert byte == 0;                           // &quot;vaddress&quot; is word aligned
            byte_select_match = TRUE;                   // DBGBCR_EL1(n).BAS[byte] is RES1
        end;

        // 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 : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_DebugAddrTop_0" file="shared_pseudocode.xml">DebugAddrTop</a>();
        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;
                                      <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_DBGxVR_RESS" file="shared_pseudocode.xml">Unpredictable_DBGxVR_RESS</a>));
        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 = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BPMASKEDBITS" file="shared_pseudocode.xml">Unpredictable_BPMASKEDBITS</a>);
            end;
        end;

    elsif match_cid then
        if <a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
            bvr_match = (CONTEXTIDR_EL2()[31:0] == DBGBVR_EL1(n)[31:0]);
        else
            bvr_match = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; CONTEXTIDR_EL1()[31:0] == DBGBVR_EL1(n)[31:0]);
        end;

    elsif match_cid1 then
        bvr_match = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() &amp;&amp;
                     CONTEXTIDR_EL1()[31:0] == DBGBVR_EL1(n)[31:0]);
    end;

    if match_vmid then
        let vmid : bits(NUM_VMIDBITS) = <a link="func_VMID_0" file="shared_pseudocode.xml">VMID</a>();
        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 = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() &amp;&amp; vmid == bvr_vmid);

    elsif match_cid2 then
        bxvr_match = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
                      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) &amp;&amp;
                                 (!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 &amp;&amp; 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 &amp;&amp; match_addr &amp;&amp; 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) = <a link="func_AArch64_BreakpointValueMatch_5" file="shared_pseudocode.xml">AArch64_BreakpointValueMatch</a>(linked_linked_n,
                                                                     linked_vaddress,
                                                                     linked_linked_to,
                                                                     linked_isbreakpnt,
                                                                     linked_from_linking_enabled);
        value_match = value_match &amp;&amp; linked_value_match;
    end;

    if match_addr &amp;&amp; !mismatch then
        bp_type = <a link="enum_BreakpointType_AddrMatch" file="shared_pseudocode.xml">BreakpointType_AddrMatch</a>;
    elsif match_addr &amp;&amp; mismatch then
        bp_type = <a link="enum_BreakpointType_AddrMismatch" file="shared_pseudocode.xml">BreakpointType_AddrMismatch</a>;
    elsif match_vmid || match_cid || match_cid1 || match_cid2 then
        bp_type = <a link="enum_BreakpointType_CtxtMatch" file="shared_pseudocode.xml">BreakpointType_CtxtMatch</a>;
    else
        unreachable;
    end;

    return (bp_type, value_match);
end;</pstext></ps>
    <ps name="aarch64/debug/breakpoint/AArch64_ReservedBreakpointType" mylink="aarch64.debug.breakpoint.AArch64_ReservedBreakpointType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// 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 <anchor link="func_AArch64_ReservedBreakpointType_2">AArch64_ReservedBreakpointType</anchor>(n : integer, bt_in : bits(5)) =&gt; (<a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>, bits(5))
begin
    var bt : bits(5)            = bt_in;
    var reserved : boolean      = FALSE;
    let context_aware : boolean = <a link="func_IsContextAwareBreakpoint_1" file="shared_pseudocode.xml">IsContextAwareBreakpoint</a>(n);

    if bt[4] == '0' then
        // Context matching
        if bt != '00x0x' &amp;&amp; !context_aware then
            reserved = TRUE;
        end;

        // EL2 extension
        if bt == '01xxx' &amp;&amp; !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
            reserved = TRUE;
        end;

        // Context matching
        if (bt IN {'0011x','011xx'} &amp;&amp; !IsFeatureImplemented(FEAT_VHE) &amp;&amp;
              !IsFeatureImplemented(FEAT_Debugv8p2)) then
            reserved = TRUE;
        end;

        // Reserved
        if bt == '0010x' &amp;&amp; !IsFeatureImplemented(FEAT_BWE) &amp;&amp; !<a link="func_HaveAArch32EL_1" file="shared_pseudocode.xml">HaveAArch32EL</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
            reserved = TRUE;
        end;
    else
        // Reserved
        if bt != '10x0x' then
            reserved = TRUE;
        end;
    end;

    if reserved then
        var c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>;
        (c, bt) = ConstrainUnpredictableBits{5}(<a link="enum_Unpredictable_RESBPTYPE" file="shared_pseudocode.xml">Unpredictable_RESBPTYPE</a>);
        assert c IN {<a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>, <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>};
        if c == <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a> then
            return (c, ARBITRARY : bits(5));
        // Otherwise the value returned by ConstrainUnpredictableBits must be a not-reserved value
        end;
    end;

    return (<a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>, bt);
end;</pstext></ps>
    <ps name="aarch64/debug/breakpoint/AArch64_StateMatch" mylink="aarch64.debug.breakpoint.AArch64_StateMatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_StateMatch()
// ====================
// Determine whether a breakpoint or watchpoint is enabled in the current mode and state.

func <anchor link="func_AArch64_StateMatch_9">AArch64_StateMatch</anchor>(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 : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_RME) then assert ssce_in == '0'; end;

    // &quot;ssc_in&quot;,&quot;ssce_in&quot;,&quot;hmc_in&quot;,&quot;pxc_in&quot; are the control fields from
    // the DBGBCR_EL1(n) or DBGWCR_EL1(n) register.
    // &quot;linked_in&quot; is TRUE if this is a linked breakpoint/watchpoint type.
    // &quot;linked_n_in&quot; is the linked breakpoint number from the DBGBCR_EL1(n) or
    // DBGWCR_EL1(n) register.
    // &quot;isbreakpnt&quot; is TRUE for breakpoints, FALSE for watchpoints.
    // &quot;vaddress&quot; is the program counter for a linked watchpoint or the same value passed to
    // AArch64_CheckBreakpoint for a linked breakpoint.
    // &quot;accdesc&quot; 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 : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>;
    (c, ssc, ssce, hmc, pxc) = <a link="func_CheckValidStateMatch_5" file="shared_pseudocode.xml">CheckValidStateMatch</a>(ssc, ssce, hmc, pxc, isbreakpnt);
    if c == <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a> 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 = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; hmc == '1' &amp;&amp; ssc[0] == '0';
    let EL2_match : boolean = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; ((hmc == '1' &amp;&amp; (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 <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;  priv_match = EL3_match;
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;  priv_match = EL2_match;
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;  priv_match = EL1_match;
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;  priv_match = EL0_match;
    end;

    // Security state match
    var ss_match : boolean;
    case ssce::ssc of
        when '000' =&gt; ss_match = hmc == '1' || accdesc.ss != <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a>;
        when '001' =&gt; ss_match = accdesc.ss == <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a>;
        when '010' =&gt; ss_match = (hmc == '1' &amp;&amp; accdesc.ss == <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a>) || accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>;
        when '011' =&gt; ss_match = (hmc == '1' &amp;&amp; accdesc.ss != <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a>) || accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>;
        when '101' =&gt; ss_match = accdesc.ss == <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a>;
    end;

    var linked_match : boolean = FALSE;

    if linked then
        // &quot;linked_n&quot; 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 (!<a link="func_IsContextAwareBreakpoint_1" file="shared_pseudocode.xml">IsContextAwareBreakpoint</a>(linked_n) &amp;&amp;
            (isbreakpnt || !<a link="func_IsAddressLinkingBreakpoint_1" file="shared_pseudocode.xml">IsAddressLinkingBreakpoint</a>(linked_n))) then
            return <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BPNOTLINKING" file="shared_pseudocode.xml">Unpredictable_BPNOTLINKING</a>);
        end;
    end;

    if linked then
        let linked_to : boolean = TRUE;
        var bp_type : <a link="type_BreakpointType" file="shared_pseudocode.xml">BreakpointType</a>;
        let from_linking_enabled : boolean = FALSE;
        (bp_type, linked_match) = <a link="func_AArch64_BreakpointValueMatch_5" file="shared_pseudocode.xml">AArch64_BreakpointValueMatch</a>(linked_n, vaddress,
                                                               linked_to, isbreakpnt,
                                                               from_linking_enabled);
        if bp_type == <a link="enum_BreakpointType_AddrMismatch" file="shared_pseudocode.xml">BreakpointType_AddrMismatch</a> then
            linked_match = !linked_match;
        end;
    end;

    return priv_match &amp;&amp; ss_match &amp;&amp; (!linked || linked_match);
end;</pstext></ps>
    <ps name="aarch64/debug/breakpoint/DebugAddrTop" mylink="aarch64.debug.breakpoint.DebugAddrTop" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DebugAddrTop()
// ==============
// Returns the value for the top bit used in Breakpoint and Watchpoint address comparisons.

func <anchor link="func_DebugAddrTop_0">DebugAddrTop</anchor>() =&gt; <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>
begin
    if IsFeatureImplemented(FEAT_LVA3) then
        return 55;
    elsif IsFeatureImplemented(FEAT_LVA) then
        return 52;
    else
        return 48;
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/breakpoint/EffectiveMDSELR_EL1_BANK" mylink="aarch64.debug.breakpoint.EffectiveMDSELR_EL1_BANK" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveMDSELR_EL1_BANK()
// ==========================
// Return the effective value of MDSELR_EL1.BANK.

func <anchor link="func_EffectiveMDSELR_EL1_BANK_0">EffectiveMDSELR_EL1_BANK</anchor>() =&gt; bits(2)
begin
    // If 16 or fewer breakpoints and 16 or fewer watchpoints are implemented,
    // then the field is RES0.
    let num_bp : integer = <a link="func_NumBreakpointsImplemented_0" file="shared_pseudocode.xml">NumBreakpointsImplemented</a>();
    let num_wp : integer = <a link="func_NumWatchpointsImplemented_0" file="shared_pseudocode.xml">NumWatchpointsImplemented</a>();
    if num_bp &lt;= 16 &amp;&amp; num_wp &lt;= 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 ((<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; MDCR_EL3().EBWE == '0') ||
          (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; MDCR_EL2().EBWE == '0') ||
          (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; 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' &amp;&amp; num_bp &lt;= 48 &amp;&amp; num_wp &lt;= 48) ||
          (bank == '10' &amp;&amp; num_bp &lt;= 32 &amp;&amp; num_wp &lt;= 32)) then
        // Reserved value
        (-, bank) = ConstrainUnpredictableBits{2}(<a link="enum_Unpredictable_RESMDSELR" file="shared_pseudocode.xml">Unpredictable_RESMDSELR</a>);
        // The value returned by ConstrainUnpredictableBits must be a not-reserved value
    end;

    return bank;
end;</pstext></ps>
    <ps name="aarch64/debug/breakpoint/IsAddressLinkingBreakpoint" mylink="aarch64.debug.breakpoint.IsAddressLinkingBreakpoint" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsAddressLinkingBreakpoint()
// ============================
// Returns TRUE if DBGBCR_EL1(n) supports being configured as an Address matching breakpoint with
// linking enabled.

func <anchor link="func_IsAddressLinkingBreakpoint_1">IsAddressLinkingBreakpoint</anchor>(n : integer) =&gt; boolean
begin
    return n &lt; <a link="func_NumAddressLinkingBreakpointsImplemented_0" file="shared_pseudocode.xml">NumAddressLinkingBreakpointsImplemented</a>();
end;</pstext></ps>
    <ps name="aarch64/debug/breakpoint/IsBreakpointEnabled" mylink="aarch64.debug.breakpoint.IsBreakpointEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsBreakpointEnabled()
// =====================
// Returns TRUE if the effective value of DBGBCR_EL1(n).E is '1', and FALSE otherwise.

func <anchor link="func_IsBreakpointEnabled_1">IsBreakpointEnabled</anchor>(n : integer) =&gt; boolean
begin
    if (n &gt; 15 &amp;&amp;
          ((!<a link="func_HaltOnBreakpointOrWatchpoint_0" file="shared_pseudocode.xml">HaltOnBreakpointOrWatchpoint</a>() &amp;&amp; !<a link="func_SelfHostedExtendedBPWPEnabled_0" file="shared_pseudocode.xml">SelfHostedExtendedBPWPEnabled</a>()) ||
          (<a link="func_HaltOnBreakpointOrWatchpoint_0" file="shared_pseudocode.xml">HaltOnBreakpointOrWatchpoint</a>() &amp;&amp; EDSCR2().EHBWE == '0'))) then
        return FALSE;
    end;

    return DBGBCR_EL1(n).E == '1';
end;</pstext></ps>
    <ps name="aarch64/debug/breakpoint/NumAddressLinkingBreakpointsImplemented" mylink="aarch64.debug.breakpoint.NumAddressLinkingBreakpointsImplemented" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// 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 <anchor link="func_NumAddressLinkingBreakpointsImplemented_0">NumAddressLinkingBreakpointsImplemented</anchor>() =&gt; integer
begin
    if !IsFeatureImplemented(FEAT_ABLE) then
        return 0;
    else
        return ImpDefInt(&quot;Number of address-linking breakpoints&quot;);
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/breakpoint/SelfHostedExtendedBPWPEnabled" mylink="aarch64.debug.breakpoint.SelfHostedExtendedBPWPEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SelfHostedExtendedBPWPEnabled()
// ===============================
// Returns TRUE if the extended breakpoints and watchpoints are enabled, and FALSE otherwise
// from a self-hosted debug perspective.

func <anchor link="func_SelfHostedExtendedBPWPEnabled_0">SelfHostedExtendedBPWPEnabled</anchor>() =&gt; boolean
begin
    if <a link="func_NumBreakpointsImplemented_0" file="shared_pseudocode.xml">NumBreakpointsImplemented</a>() &lt;= 16 &amp;&amp; <a link="func_NumWatchpointsImplemented_0" file="shared_pseudocode.xml">NumWatchpointsImplemented</a>() &lt;= 16 then
        return FALSE;
    end;

    if ((<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; MDCR_EL3().EBWE == '0') ||
          (<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; MDCR_EL2().EBWE == '0')) then
        return FALSE;
    end;

    return MDSCR_EL1().EMBWE == '1';
end;</pstext></ps>
    <ps name="aarch64/debug/ebep/CheckForPMUException" mylink="aarch64.debug.ebep.CheckForPMUException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckForPMUException()
// ======================
// Take a PMU exception if enabled, permitted, and unmasked.

func <anchor link="func_CheckForPMUException_0">CheckForPMUException</anchor>()
begin
    var enabled : boolean;
    var target_el : bits(2);
    var pmu_exception : boolean;
    var synchronous : boolean;
    (enabled, target_el) = <a link="func_PMUExceptionEnabled_0" file="shared_pseudocode.xml">PMUExceptionEnabled</a>();
    if !enabled || <a link="func_PMUExceptionMasked_3" file="shared_pseudocode.xml">PMUExceptionMasked</a>(target_el, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PM) then
        pmu_exception = FALSE;
    else
        let include_r1 : boolean = TRUE;
        let include_r2 : boolean = TRUE;
        let include_r3 : boolean = TRUE;
        pmu_exception = <a link="func_CheckPMUOverflowCondition_4" file="shared_pseudocode.xml">CheckPMUOverflowCondition</a>(<a link="enum_PMUOverflowCondition_PMUException" file="shared_pseudocode.xml">PMUOverflowCondition_PMUException</a>,
                                                  include_r1, include_r2, include_r3);
        synchronous = FALSE;
    end;
    if pmu_exception then
        let fsc : bits(5) = '00000';
        <a link="func_TakeProfilingException_3" file="shared_pseudocode.xml">TakeProfilingException</a>(target_el, fsc, synchronous);
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/ebep/EffectivePMEE" mylink="aarch64.debug.ebep.EffectivePMEE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// 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 <anchor link="func_EffectivePMEE_2">EffectivePMEE</anchor>(el : bits(2), for_interrupt : boolean) =&gt; bits(2)
begin
    var val : bits(2);
    case el of
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>  =&gt; val = PMECR_EL1().PMEE;
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>  =&gt; val = MDCR_EL2().PMEE;
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>  =&gt; val = MDCR_EL3().PMEE;
        otherwise =&gt; unreachable;
    end;

    if (val == '10' || (el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; val == '01')) then
        var c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>;
        (c, val) = ConstrainUnpredictableBits{2}(<a link="enum_Unpredictable_RESPMEE" file="shared_pseudocode.xml">Unpredictable_RESPMEE</a>);
        assert c IN {<a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>, <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>};
        if c == <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a> 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;</pstext></ps>
    <ps name="aarch64/debug/ebep/PMUExceptionEnabled" mylink="aarch64.debug.ebep.PMUExceptionEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// 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 <anchor link="func_PMUExceptionEnabled_0">PMUExceptionEnabled</anchor>() =&gt; (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) = <a link="func_EffectivePMEE_2" file="shared_pseudocode.xml">EffectivePMEE</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, for_interrupt);
    let pmee_el2 : bits(2) = <a link="func_EffectivePMEE_2" file="shared_pseudocode.xml">EffectivePMEE</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, for_interrupt);
    let pmee_el1 : bits(2) = <a link="func_EffectivePMEE_2" file="shared_pseudocode.xml">EffectivePMEE</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, for_interrupt);

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; pmee_el3 != '01' then
        enabled = pmee_el3 == '11';
        if enabled then target = <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>; end;

    elsif <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; pmee_el2 != '01' then
        enabled = pmee_el2 == '11';
        if enabled then target = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>; end;

    else
        enabled = pmee_el1 == '11';
        if enabled then
            target = if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1' then <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> else <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
        end;
    end;

    return (enabled, target);
end;</pstext></ps>
    <ps name="aarch64/debug/ebep/PMUExceptionMasked" mylink="aarch64.debug.ebep.PMUExceptionMasked" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// 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 <anchor link="func_PMUExceptionMasked_3">PMUExceptionMasked</anchor>(target_el : bits(2), from_el : bits(2), pm : bit) =&gt; boolean
begin
    assert IsFeatureImplemented(FEAT_EBEP);
    let for_interrupt : boolean = FALSE;

    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then
        return TRUE;
    elsif UInt(target_el) &lt; UInt(from_el) then
        return TRUE;
    elsif (from_el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> &amp;&amp; target_el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> &amp;&amp;
             <a link="func_EffectivePMEE_2" file="shared_pseudocode.xml">EffectivePMEE</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, for_interrupt) != '11') then
        return TRUE;
    elsif target_el == from_el &amp;&amp; (PMECR_EL1().KPME == '0' || pm == '1') then
        return TRUE;
    end;

    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/debug/ebep/PMUInterruptEnabled" mylink="aarch64.debug.ebep.PMUInterruptEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PMUInterruptEnabled()
// =====================
// Return TRUE if the PMU interrupt request (PMUIRQ) is enabled, FALSE otherwise.

func <anchor link="func_PMUInterruptEnabled_0">PMUInterruptEnabled</anchor>() =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_EBEP) then
        return TRUE;
    end;

    var enabled : boolean;
    let for_interrupt : boolean = TRUE;
    let pmee_el3 : bits(2) = <a link="func_EffectivePMEE_2" file="shared_pseudocode.xml">EffectivePMEE</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, for_interrupt);
    let pmee_el2 : bits(2) = <a link="func_EffectivePMEE_2" file="shared_pseudocode.xml">EffectivePMEE</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, for_interrupt);
    let pmee_el1 : bits(2) = <a link="func_EffectivePMEE_2" file="shared_pseudocode.xml">EffectivePMEE</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, for_interrupt);

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; pmee_el3 != '01' then
        enabled = pmee_el3 == '00';

    elsif <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; pmee_el2 != '01' then
        enabled = pmee_el2 == '00';

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

    return enabled;
end;</pstext></ps>
    <ps name="aarch64/debug/enables/AArch64_GenerateDebugExceptions" mylink="aarch64.debug.enables.AArch64_GenerateDebugExceptions" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_GenerateDebugExceptions()
// =================================

func <anchor link="func_AArch64_GenerateDebugExceptions_0">AArch64_GenerateDebugExceptions</anchor>() =&gt; boolean
begin
    let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>();
    return <a link="func_AArch64_GenerateDebugExceptionsFrom_3" file="shared_pseudocode.xml">AArch64_GenerateDebugExceptionsFrom</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL, ss, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.D);
end;</pstext></ps>
    <ps name="aarch64/debug/enables/AArch64_GenerateDebugExceptionsFrom" mylink="aarch64.debug.enables.AArch64_GenerateDebugExceptionsFrom" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_GenerateDebugExceptionsFrom()
// =====================================

func <anchor link="func_AArch64_GenerateDebugExceptionsFrom_3">AArch64_GenerateDebugExceptionsFrom</anchor>(from_el : bits(2), from_state : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>,
                                         mask : bit) =&gt; boolean
begin

    if OSLSR_EL1().OSLK == '1' || <a link="func_DoubleLockStatus_0" file="shared_pseudocode.xml">DoubleLockStatus</a>() || <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then
        return FALSE;
    end;

    let route_to_el2 : boolean = (<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp;
                                  (from_state != <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> || <a link="func_IsSecureEL2Enabled_0" file="shared_pseudocode.xml">IsSecureEL2Enabled</a>()) &amp;&amp;
                                  (HCR_EL2().TGE == '1' || MDCR_EL2().TDE == '1'));
    let target : bits(2) = (if route_to_el2 then <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> else <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>);
    var enabled : boolean;
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; from_state == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
        enabled = MDCR_EL3().SDD == '0';
        if from_el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
            enabled = enabled || SDER32_EL3().SUIDEN == '1';
        end;
    else
        enabled = TRUE;
    end;

    if from_el == target then
        enabled = enabled &amp;&amp; MDSCR_EL1().KDE == '1' &amp;&amp; mask == '0';
    else
        enabled = enabled &amp;&amp; UInt(target) &gt; UInt(from_el);
    end;

    return enabled;
end;</pstext></ps>
    <ps name="aarch64/debug/ite/AArch64_TRCIT" mylink="aarch64.debug.ite.AArch64_TRCIT" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TRCIT()
// ===============
// Determines whether an Instrumentation trace packet should
// be generated and then generates an instrumentation trace packet
// containing the value of the register passed as an argument

func <anchor link="func_AArch64_TRCIT_1">AArch64_TRCIT</anchor>(Xt : bits(64))
begin
    let ss = <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>();
    if <a link="func_TraceInstrumentationAllowed_2" file="shared_pseudocode.xml">TraceInstrumentationAllowed</a>(ss, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) then
        TraceInstrumentation(Xt);
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/ite/TraceInstrumentation" mylink="aarch64.debug.ite.TraceInstrumentation" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TraceInstrumentation()
// ======================
// Generates an instrumentation trace packet
// containing the value of the register passed as an argument

impdef func TraceInstrumentation(Xt : bits(64))
begin
    return;
end;</pstext></ps>
    <ps name="aarch64/debug/pmu/AArch64_IncrementCycleCounter" mylink="aarch64.debug.pmu.AArch64_IncrementCycleCounter" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_IncrementCycleCounter()
// ===============================
// Increment the cycle counter and possibly set overflow bits.

func <anchor link="func_AArch64_IncrementCycleCounter_0">AArch64_IncrementCycleCounter</anchor>()
begin
    if !<a link="func_CountPMUEvents_1" file="shared_pseudocode.xml">CountPMUEvents</a>(<a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a>) then return; end;
    var d : bit = PMCR_EL0().D;   // Check divide-by-64
    var lc : bit = PMCR_EL0().LC;
    var lc_enabled : boolean;
    (lc_enabled, -) = <a link="func_PMUExceptionEnabled_0" file="shared_pseudocode.xml">PMUExceptionEnabled</a>();
    lc = if lc_enabled then '1' else lc;
    // Effective value of 'D' bit is 0 when Effective value of LC is '1'
    if lc == '1' then d = '0'; end;
    if d == '1' &amp;&amp; !<a link="func_HasElapsed64Cycles_0" file="shared_pseudocode.xml">HasElapsed64Cycles</a>() then return; end;

    let old_value : integer = UInt(PMCCNTR_EL0());
    let new_value : integer = old_value + 1;
    PMCCNTR_EL0() = new_value[63:0];

    let ovflw : integer{} = if <a link="func_HaveAArch32_0" file="shared_pseudocode.xml">HaveAArch32</a>() &amp;&amp; lc == '0' then 32 else 64;

    if old_value[64:ovflw] != new_value[64:ovflw] then
        PMOVSSET_EL0().C = '1';
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/debug/pmu/AArch64_IncrementEventCounter" mylink="aarch64.debug.pmu.AArch64_IncrementEventCounter" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_IncrementEventCounter()
// ===============================
// Increment the specified event counter 'idx' by the specified amount 'increment'.
// 'Vm' is the value event counter 'idx-1' is being incremented by if 'idx' is odd,
// zero otherwise.
// Returns the amount the counter was incremented by.

func <anchor link="func_AArch64_IncrementEventCounter_3">AArch64_IncrementEventCounter</anchor>(idx : integer, increment_in : integer, Vm : integer) =&gt; integer
begin
    var old_value : integer;
    var new_value : integer;

    old_value = UInt(PMEVCNTR_EL0(idx));
    let increment : integer = <a link="func_PMUCountValue_3" file="shared_pseudocode.xml">PMUCountValue</a>(idx, increment_in, Vm);
    new_value = old_value + increment;

    var lp : bit;
    if IsFeatureImplemented(FEAT_PMUv3p5) then
        PMEVCNTR_EL0(idx) = new_value[63:0];
        var pmuexception_enabled : boolean;
        (pmuexception_enabled, -) = <a link="func_PMUExceptionEnabled_0" file="shared_pseudocode.xml">PMUExceptionEnabled</a>();
        if pmuexception_enabled then
            lp = '1';
        else
            case <a link="func_GetPMUCounterRange_1" file="shared_pseudocode.xml">GetPMUCounterRange</a>(idx) of
                when <a link="enum_PMUCounterRange_R1" file="shared_pseudocode.xml">PMUCounterRange_R1</a> =&gt;
                    lp = PMCR_EL0().LP;
                when <a link="enum_PMUCounterRange_R2" file="shared_pseudocode.xml">PMUCounterRange_R2</a> =&gt;
                    lp = MDCR_EL2().HLP;
                when <a link="enum_PMUCounterRange_R3" file="shared_pseudocode.xml">PMUCounterRange_R3</a> =&gt;
                    lp = '1';
                otherwise =&gt;
                    unreachable;
            end;
        end;
    else
        lp = '0';
        PMEVCNTR_EL0(idx) = ZeroExtend{64}(new_value[31:0]);
    end;
    let ovflw : integer{} = if lp == '1' then 64 else 32;
    if old_value[64:ovflw] != new_value[64:ovflw] then
        PMOVSSET_EL0()[idx] = '1';
        // Check for the CHAIN event from an even counter
        if (idx[0] == '0' &amp;&amp; idx + 1 &lt; NUM_PMU_COUNTERS &amp;&amp; lp == '0' &amp;&amp;
              (<a link="func_GetPMUCounterRange_1" file="shared_pseudocode.xml">GetPMUCounterRange</a>(idx) == <a link="func_GetPMUCounterRange_1" file="shared_pseudocode.xml">GetPMUCounterRange</a>(idx+1) ||
                 <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_COUNT_CHAIN" file="shared_pseudocode.xml">Unpredictable_COUNT_CHAIN</a>))) then
            // If PMU counters idx and idx+1 are not in same range,
            // it is CONSTRAINED UNPREDICTABLE if CHAIN event is counted
            <a link="func_PMUEvent_3" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_CHAIN, 1, idx + 1);
        end;
    end;

    return increment;
end;</pstext></ps>
    <ps name="aarch64/debug/pmu/AArch64_PMUCycle" mylink="aarch64.debug.pmu.AArch64_PMUCycle" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_PMUCycle()
// ==================
// Called at the end of each cycle to increment event counters and
// check for PMU overflow. In pseudocode, a cycle ends after the
// execution of the operational pseudocode.

func <anchor link="func_AArch64_PMUCycle_0">AArch64_PMUCycle</anchor>()
begin
    if !IsFeatureImplemented(FEAT_PMUv3) then
        return;
    end;
    <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_CPU_CYCLES);
    let counters : integer = NUM_PMU_COUNTERS;
    var Vm : integer = 0;
    if counters != 0 then
        for idx = 0 to counters - 1 do
            if <a link="func_CountPMUEvents_1" file="shared_pseudocode.xml">CountPMUEvents</a>(idx) then
                let accumulated : integer = <a link="global_PMUEventAccumulator" file="shared_pseudocode.xml">PMUEventAccumulator</a>[[idx]];
                if (idx MOD 2) == 0 then Vm = 0; end;
                Vm = <a link="func_AArch64_IncrementEventCounter_3" file="shared_pseudocode.xml">AArch64_IncrementEventCounter</a>(idx, accumulated, Vm);
            end;
            <a link="global_PMUEventAccumulator" file="shared_pseudocode.xml">PMUEventAccumulator</a>[[idx]] = 0;
        end;
    end;
    <a link="func_AArch64_IncrementCycleCounter_0" file="shared_pseudocode.xml">AArch64_IncrementCycleCounter</a>();
    <a link="func_CheckForPMUOverflow_0" file="shared_pseudocode.xml">CheckForPMUOverflow</a>();
end;</pstext></ps>
    <ps name="aarch64/debug/profilingexception/TakeProfilingException" mylink="aarch64.debug.profilingexception.TakeProfilingException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TakeProfilingException()
// ========================
// Takes a Profiling exception.

func <anchor link="func_TakeProfilingException_3">TakeProfilingException</anchor>(target_el : bits(2), fsc : bits(5), synchronous : boolean)
begin
    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_Profiling" file="shared_pseudocode.xml">Exception_Profiling</a>);
    except.syndrome.iss[5:1] = fsc;
    if synchronous then
        except.syndrome.iss[0] = '1';
    end;

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;
    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/CheckForSPEException" mylink="aarch64.debug.statisticalprofiling.CheckForSPEException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckForSPEException()
// ======================
// Take an SPE Profiling exception if pending, permitted, and unmasked.

func <anchor link="func_CheckForSPEException_0">CheckForSPEException</anchor>()
begin
    if !IsFeatureImplemented(FEAT_SPE_EXC) then
        return;
    end;

    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() || <a link="func_Restarting_0" file="shared_pseudocode.xml">Restarting</a>() then
        return;
    end;

    var route_to_el3 : boolean = FALSE;
    var route_to_el2 : boolean = FALSE;
    var route_to_el1 : boolean = FALSE;

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; MDCR_EL3().PMSEE == '1x' then
        let pending : boolean = PMBSR_EL3().S == '1';
        let masked : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
        route_to_el3 = pending &amp;&amp; !masked;
    end;

    var owning_ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>;
    var owning_el : bits(2);
    (owning_ss, owning_el) = <a link="func_ProfilingBufferOwner_0" file="shared_pseudocode.xml">ProfilingBufferOwner</a>();
    let in_owning_ss : boolean = <a link="func_IsCurrentSecurityState_1" file="shared_pseudocode.xml">IsCurrentSecurityState</a>(owning_ss);

    if <a link="func_EffectivePMSCR_EL2_EE_0" file="shared_pseudocode.xml">EffectivePMSCR_EL2_EE</a>() == '1x' then
        let pending : boolean = PMBSR_EL2().S == '1';
        let masked : boolean = (!in_owning_ss || <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> ||
                                (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> &amp;&amp; (PMSCR_EL2().EE != '11' ||
                                 PMSCR_EL2().KE == '0' || <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PM == '1'))
                                );
        route_to_el2 = pending &amp;&amp; !masked;
    end;

    if <a link="func_EffectivePMSCR_EL1_EE_0" file="shared_pseudocode.xml">EffectivePMSCR_EL1_EE</a>() == '11' then
        let pending : boolean = PMBSR_EL1().S == '1';
        let masked : boolean = (!in_owning_ss || <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>} ||
                                (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; (PMSCR_EL1().KE == '0' || <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PM == '1'))
                                );
        if <a link="func_EffectiveTGE_0" file="shared_pseudocode.xml">EffectiveTGE</a>() == '1' then
            route_to_el2 = route_to_el2 || (pending &amp;&amp; !masked);
        else
            route_to_el1 = pending &amp;&amp; !masked;
        end;
    end;

    let fsc : bits(5) = '00001';        // SPE exception
    let synchronous : boolean = FALSE;

    // The relative priorities of the following checks is IMPLEMENTATION DEFINED
    if route_to_el3 then
        <a link="func_TakeProfilingException_3" file="shared_pseudocode.xml">TakeProfilingException</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, fsc, synchronous);
    end;
    if route_to_el2 then
        <a link="func_TakeProfilingException_3" file="shared_pseudocode.xml">TakeProfilingException</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, fsc, synchronous);
    end;
    if route_to_el1 then
        <a link="func_TakeProfilingException_3" file="shared_pseudocode.xml">TakeProfilingException</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, fsc, synchronous);
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/CheckMDCR_EL3_NSPBTrap" mylink="aarch64.debug.statisticalprofiling.CheckMDCR_EL3_NSPBTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckMDCR_EL3_NSPBTrap()
// ========================
// Check if the register access is trappable by MDCR_EL3.[NSPBE, NSPB]

func <anchor link="func_CheckMDCR_EL3_NSPBTrap_0">CheckMDCR_EL3_NSPBTrap</anchor>() =&gt; boolean
begin
    var state_bits : bits(3);
    var reserved : boolean;
    (state_bits, reserved) = <a link="func_EffectiveMDCR_EL3_NSPB_0" file="shared_pseudocode.xml">EffectiveMDCR_EL3_NSPB</a>();
    return ((reserved &amp;&amp; <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_RESERVEDNSxB_Trap" file="shared_pseudocode.xml">Unpredictable_RESERVEDNSxB_Trap</a>)) ||
             state_bits[0] == '0' || state_bits[1] != <a link="func_EffectiveSCR_EL3_NS_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NS</a>() ||
             (IsFeatureImplemented(FEAT_RME) &amp;&amp; state_bits[2] != <a link="func_EffectiveSCR_EL3_NSE_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NSE</a>()));
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/CollectContextIDR1" mylink="aarch64.debug.statisticalprofiling.CollectContextIDR1" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CollectContextIDR1()
// ====================
func <anchor link="func_CollectContextIDR1_0">CollectContextIDR1</anchor>() =&gt; boolean
begin
    if !<a link="func_StatisticalProfilingEnabled_0" file="shared_pseudocode.xml">StatisticalProfilingEnabled</a>() then return FALSE; end;
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then return FALSE; end;
    if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1' then return FALSE; end;
    return PMSCR_EL1().CX == '1';
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/CollectContextIDR2" mylink="aarch64.debug.statisticalprofiling.CollectContextIDR2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CollectContextIDR2()
// ====================

func <anchor link="func_CollectContextIDR2_0">CollectContextIDR2</anchor>() =&gt; boolean
begin
    if !<a link="func_StatisticalProfilingEnabled_0" file="shared_pseudocode.xml">StatisticalProfilingEnabled</a>() then return FALSE; end;
    if !<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then return FALSE; end;
    return PMSCR_EL2().CX == '1';
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/CollectPhysicalAddress" mylink="aarch64.debug.statisticalprofiling.CollectPhysicalAddress" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CollectPhysicalAddress()
// ========================

func <anchor link="func_CollectPhysicalAddress_0">CollectPhysicalAddress</anchor>() =&gt; boolean
begin
    if !<a link="func_StatisticalProfilingEnabled_0" file="shared_pseudocode.xml">StatisticalProfilingEnabled</a>() then return FALSE; end;
    let (owning_ss, owning_el) : (<a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, bits(2)) = <a link="func_ProfilingBufferOwner_0" file="shared_pseudocode.xml">ProfilingBufferOwner</a>();
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; (owning_ss != <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> || <a link="func_IsSecureEL2Enabled_0" file="shared_pseudocode.xml">IsSecureEL2Enabled</a>()) then
        return PMSCR_EL2().PA == '1' &amp;&amp; (owning_el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || PMSCR_EL1().PA == '1');
    else
        return PMSCR_EL1().PA == '1';
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/CollectTimeStamp" mylink="aarch64.debug.statisticalprofiling.CollectTimeStamp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CollectTimeStamp()
// ==================
func <anchor link="func_CollectTimeStamp_0">CollectTimeStamp</anchor>() =&gt; <a link="type_TimeStamp" file="shared_pseudocode.xml">TimeStamp</a>
begin
    if !<a link="func_StatisticalProfilingEnabled_0" file="shared_pseudocode.xml">StatisticalProfilingEnabled</a>() then return <a link="enum_TimeStamp_None" file="shared_pseudocode.xml">TimeStamp_None</a>; end;
    let (-, owning_el) = <a link="func_ProfilingBufferOwner_0" file="shared_pseudocode.xml">ProfilingBufferOwner</a>();

    if owning_el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
        if PMSCR_EL2().TS == '0' then return <a link="enum_TimeStamp_None" file="shared_pseudocode.xml">TimeStamp_None</a>; end;
    else
        if PMSCR_EL1().TS == '0' then return <a link="enum_TimeStamp_None" file="shared_pseudocode.xml">TimeStamp_None</a>; end;
    end;

    var PCT_el1 : bits(2);
    if !IsFeatureImplemented(FEAT_ECV) then
        PCT_el1 = '0'::PMSCR_EL1().PCT[0];                         // PCT[1] is RES0
    else
        PCT_el1 = PMSCR_EL1().PCT;
        if PCT_el1 == '10' then
            // Reserved value
            (-, PCT_el1) = ConstrainUnpredictableBits{2}(<a link="enum_Unpredictable_PMSCR_PCT" file="shared_pseudocode.xml">Unpredictable_PMSCR_PCT</a>);
        end;
    end;
    if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        var PCT_el2 : bits(2);
        if !IsFeatureImplemented(FEAT_ECV) then
            PCT_el2 = '0'::PMSCR_EL2().PCT[0];                     // PCT[1] is RES0
        else
            PCT_el2 = PMSCR_EL2().PCT;
            if PCT_el2 == '10' then
                // Reserved value
                (-, PCT_el2) = ConstrainUnpredictableBits{2}(<a link="enum_Unpredictable_PMSCR_PCT" file="shared_pseudocode.xml">Unpredictable_PMSCR_PCT</a>);
            end;
        end;
        case PCT_el2 of
            when '00' =&gt;
                return if <a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then <a link="enum_TimeStamp_Physical" file="shared_pseudocode.xml">TimeStamp_Physical</a> else <a link="enum_TimeStamp_Virtual" file="shared_pseudocode.xml">TimeStamp_Virtual</a>;
            when '01' =&gt;
                if owning_el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then return <a link="enum_TimeStamp_Physical" file="shared_pseudocode.xml">TimeStamp_Physical</a>; end;
            when '11' =&gt;
                assert IsFeatureImplemented(FEAT_ECV);          // FEAT_ECV must be implemented
                if owning_el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; PCT_el1 == '00' then
                    return if <a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then <a link="enum_TimeStamp_Physical" file="shared_pseudocode.xml">TimeStamp_Physical</a> else <a link="enum_TimeStamp_Virtual" file="shared_pseudocode.xml">TimeStamp_Virtual</a>;
                else
                    return <a link="enum_TimeStamp_OffsetPhysical" file="shared_pseudocode.xml">TimeStamp_OffsetPhysical</a>;
                end;
            otherwise =&gt;
                unreachable;
        end;
    end;

    case PCT_el1 of
        when '00' =&gt; return if <a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then <a link="enum_TimeStamp_Physical" file="shared_pseudocode.xml">TimeStamp_Physical</a> else <a link="enum_TimeStamp_Virtual" file="shared_pseudocode.xml">TimeStamp_Virtual</a>;
        when '01' =&gt; return <a link="enum_TimeStamp_Physical" file="shared_pseudocode.xml">TimeStamp_Physical</a>;
        when '11' =&gt;
            assert IsFeatureImplemented(FEAT_ECV);              // FEAT_ECV must be implemented
            return <a link="enum_TimeStamp_OffsetPhysical" file="shared_pseudocode.xml">TimeStamp_OffsetPhysical</a>;
        otherwise =&gt; unreachable;
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/DefaultSPEEvent" mylink="aarch64.debug.statisticalprofiling.DefaultSPEEvent" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DefaultSPEEvent()
// =================
// Return the target ELx for an indirect write to PMBSR_ELx for an Other buffer management
// event or anything other than a buffer management event.

func <anchor link="func_DefaultSPEEvent_0">DefaultSPEEvent</anchor>() =&gt; bits(2)
begin
    return <a link="func_ReportSPEEvent_2" file="shared_pseudocode.xml">ReportSPEEvent</a>(Zeros{6}, ARBITRARY : bits(6));
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/EffectiveMDCR_EL3_NSPB" mylink="aarch64.debug.statisticalprofiling.EffectiveMDCR_EL3_NSPB" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveMDCR_EL3_NSPB()
// ========================
// Return the Effective value of MDCR_EL3.[NSPBE, NSPB] field and whether it is a reserved value.

readonly func <anchor link="func_EffectiveMDCR_EL3_NSPB_0">EffectiveMDCR_EL3_NSPB</anchor>() =&gt; (bits(3), boolean)
begin
    var state_bits : bits(3);
    var reserved : boolean = FALSE;

    if IsFeatureImplemented(FEAT_RME) then
        state_bits = MDCR_EL3().[NSPBE, NSPB];
        if state_bits == '10x' || (!IsFeatureImplemented(FEAT_Secure) &amp;&amp; state_bits == '00x') then
            // Reserved value
            reserved = TRUE;
            (-, state_bits) = ConstrainUnpredictableBits{3}(<a link="enum_Unpredictable_RESERVEDNSxB" file="shared_pseudocode.xml">Unpredictable_RESERVEDNSxB</a>);
        end;
    else
        state_bits = '0' :: MDCR_EL3().NSPB;
    end;

    return (state_bits, reserved);
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/EffectivePMBLIMITR_EL1_nVM" mylink="aarch64.debug.statisticalprofiling.EffectivePMBLIMITR_EL1_nVM" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectivePMBLIMITR_EL1_nVM()
// ============================

func <anchor link="func_EffectivePMBLIMITR_EL1_nVM_0">EffectivePMBLIMITR_EL1_nVM</anchor>() =&gt; bit
begin
    if !IsFeatureImplemented(FEAT_SPE_nVM) then
        return '0';
    end;
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        let (owning_ss, owning_el) : (<a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, bits(2)) = <a link="func_ProfilingBufferOwner_0" file="shared_pseudocode.xml">ProfilingBufferOwner</a>();
        if ((owning_ss != <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> || <a link="func_IsSecureEL2Enabled_0" file="shared_pseudocode.xml">IsSecureEL2Enabled</a>()) &amp;&amp; owning_el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp;
              PMSCR_EL2().EnVM == '0') then
            return '0';
        end;
    end;
    return PMBLIMITR_EL1().nVM;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/EffectivePMSCR_EL1_EE" mylink="aarch64.debug.statisticalprofiling.EffectivePMSCR_EL1_EE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectivePMSCR_EL1_EE()
// =======================
// Return the Effective value of PMSCR_EL1.EE for the purpose of controlling the
// SPE Profiling exception.

func <anchor link="func_EffectivePMSCR_EL1_EE_0">EffectivePMSCR_EL1_EE</anchor>() =&gt; bits(2)
begin
    if <a link="func_EffectivePMSCR_EL2_EE_0" file="shared_pseudocode.xml">EffectivePMSCR_EL2_EE</a>() == '00' then
        return '00';
    end;

    var ee : bits(2) = PMSCR_EL1().EE;
    if ee IN {'01', '10'} then            // Reserved value
        if IsFeatureImplemented(FEAT_NV) then
            ee[0] = ee[1];
        else
            var c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>;
            (c, ee) = ConstrainUnpredictableBits{2}(<a link="enum_Unpredictable_RESPMSEE" file="shared_pseudocode.xml">Unpredictable_RESPMSEE</a>);
            assert c IN {<a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>, <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>};
            if c == <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a> then
                ee = '00';
            end;
            // Otherwise the value returned by ConstrainUnpredictableBits must be
            // a non-reserved value
        end;
    end;

    return ee;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/EffectivePMSCR_EL2_EE" mylink="aarch64.debug.statisticalprofiling.EffectivePMSCR_EL2_EE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectivePMSCR_EL2_EE()
// =======================
// Return the Effective value of PMSCR_EL2.EE.

readonly func <anchor link="func_EffectivePMSCR_EL2_EE_0">EffectivePMSCR_EL2_EE</anchor>() =&gt; bits(2)
begin
    if !IsFeatureImplemented(FEAT_SPE_EXC) then
        return '00';
    end;

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; MDCR_EL3().PMSEE == '00' then
        return '00';
    end;

    let check_el2 : boolean = (<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp;
                               (<a link="func_EffectiveSCR_EL3_NS_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NS</a>() == '1' || <a link="func_IsSecureEL2Enabled_0" file="shared_pseudocode.xml">IsSecureEL2Enabled</a>()));
    return if check_el2 then PMSCR_EL2().EE else '01';
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/GetPMBSR_EL1_FSC" mylink="aarch64.debug.statisticalprofiling.GetPMBSR_EL1_FSC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetPMBSR_EL1_FSC()
// ==================
// Query the PMBSR_EL1.FSC field.

func <anchor link="func_GetPMBSR_EL1_FSC_0">GetPMBSR_EL1_FSC</anchor>() =&gt; bits(6)
begin
    var FSC : bits(6);

    FSC = PMBSR_EL1()[5:0];
    return FSC;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/GetPMBSR_EL2_FSC" mylink="aarch64.debug.statisticalprofiling.GetPMBSR_EL2_FSC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetPMBSR_EL2_FSC()
// ==================
// Query the PMBSR_EL2.FSC field.

func <anchor link="func_GetPMBSR_EL2_FSC_0">GetPMBSR_EL2_FSC</anchor>() =&gt; bits(6)
begin
    var FSC : bits(6);

    FSC = PMBSR_EL2()[5:0];
    return FSC;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/GetPMBSR_EL3_FSC" mylink="aarch64.debug.statisticalprofiling.GetPMBSR_EL3_FSC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetPMBSR_EL3_FSC()
// ==================
// Query the PMBSR_EL3.FSC field.

func <anchor link="func_GetPMBSR_EL3_FSC_0">GetPMBSR_EL3_FSC</anchor>() =&gt; bits(6)
begin
    var FSC : bits(6);

    FSC = PMBSR_EL3()[5:0];
    return FSC;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/OtherSPEManagementEvent" mylink="aarch64.debug.statisticalprofiling.OtherSPEManagementEvent" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// OtherSPEManagementEvent()
// =========================
// Report an Other buffer management event, with the status code 'bsc'

func <anchor link="func_OtherSPEManagementEvent_1">OtherSPEManagementEvent</anchor>(bsc : bits(6))
begin
    let target_el : bits(2) = <a link="func_DefaultSPEEvent_0" file="shared_pseudocode.xml">DefaultSPEEvent</a>();
    if <a link="accessor_PMBSR_EL_1" file="shared_pseudocode.xml">PMBSR_EL</a>(target_el).S == '0' then
        <a link="accessor_PMBSR_EL_1" file="shared_pseudocode.xml">PMBSR_EL</a>(target_el).S   = '1';       // Assert interrupt or exception
        <a link="accessor_PMBSR_EL_1" file="shared_pseudocode.xml">PMBSR_EL</a>(target_el).EC  = '000000';  // Other buffer management event
        <a link="accessor_PMBSR_EL_1" file="shared_pseudocode.xml">PMBSR_EL</a>(target_el).MSS = ZeroExtend{16}(bsc);
        <a link="accessor_PMBSR_EL_1" file="shared_pseudocode.xml">PMBSR_EL</a>(target_el).MSS2 = Zeros{24};
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/PMBSR_EL" mylink="aarch64.debug.statisticalprofiling.PMBSR_EL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PMBSR_EL - accessor
// ===================

accessor <anchor link="accessor_PMBSR_EL_1">PMBSR_EL</anchor>(el : bits(2)) &lt;=&gt; value : PMBSRType
begin
    getter
        var r : bits(64);
        case el of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>  =&gt; r = PMBSR_EL1();
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>  =&gt; r = PMBSR_EL2();
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>  =&gt; r = PMBSR_EL3();
            otherwise =&gt; unreachable;
        end;
        return r;
    end;
    setter
        let r : bits(64) = value;
        case el of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>  =&gt; PMBSR_EL1() = r;
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>  =&gt; PMBSR_EL2() = r;
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>  =&gt; PMBSR_EL3() = r;
            otherwise =&gt; unreachable;
        end;
        return;
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/ProfilingBufferEnabled" mylink="aarch64.debug.statisticalprofiling.ProfilingBufferEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ProfilingBufferEnabled()
// ========================

readonly func <anchor link="func_ProfilingBufferEnabled_0">ProfilingBufferEnabled</anchor>() =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_SPE) then
        return FALSE;
    end;

    let (-, owning_el) : (<a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, bits(2)) = <a link="func_ProfilingBufferOwner_0" file="shared_pseudocode.xml">ProfilingBufferOwner</a>();

    return !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(owning_el) &amp;&amp; PMBLIMITR_EL1().E == '1';
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/ProfilingBufferOwner" mylink="aarch64.debug.statisticalprofiling.ProfilingBufferOwner" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ProfilingBufferOwner()
// ======================

readonly func <anchor link="func_ProfilingBufferOwner_0">ProfilingBufferOwner</anchor>() =&gt; (<a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, bits(2))
begin
    var owning_ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>;

    var state_bits : bits(3);
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        (state_bits, -) = <a link="func_EffectiveMDCR_EL3_NSPB_0" file="shared_pseudocode.xml">EffectiveMDCR_EL3_NSPB</a>();
    else
        state_bits = if <a link="func_SecureOnlyImplementation_0" file="shared_pseudocode.xml">SecureOnlyImplementation</a>() then '001' else '011';
    end;

    case state_bits of
        when '00x' =&gt; owning_ss = <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>;
        when '01x' =&gt; owning_ss = <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a>;
        when '11x' =&gt; owning_ss = <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a>;
    end;

    var owning_el : bits(2);
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; (owning_ss != <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> || <a link="func_IsSecureEL2Enabled_0" file="shared_pseudocode.xml">IsSecureEL2Enabled</a>()) then
        owning_el = if MDCR_EL2().E2PB == '00' then <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> else <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    else
        owning_el = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    end;

    return (owning_ss, owning_el);
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/ProfilingSynchronizationBarrier" mylink="aarch64.debug.statisticalprofiling.ProfilingSynchronizationBarrier" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ProfilingSynchronizationBarrier()
// =================================
// Barrier to ensure that all existing profiling data has been formatted, and profiling buffer
// addresses have been translated such that writes to the profiling buffer have been initiated.
// A following DSB completes when writes to the profiling buffer have completed.

impdef func ProfilingSynchronizationBarrier()
begin
    return;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/ReportSPEEvent" mylink="aarch64.debug.statisticalprofiling.ReportSPEEvent" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ReportSPEEvent()
// ================
// Return the target ELx for an indirect write to PMBSR_ELx.
// When the indirect write is due to a buffer management event:
// 'ec_bits' is the Event Class for the management event.
// 'fsc_bits' is the Fault Status Code when this is a fault, ignored otherwise.
// Otherwise, 'ec_bits' should be Zeros().

func <anchor link="func_ReportSPEEvent_2">ReportSPEEvent</anchor>(ec_bits : bits(6), fsc_bits : bits(6)) =&gt; bits(2)
begin
    var target_el : bits(2);
    var route_to_el3 : boolean = FALSE;
    var route_to_el2 : boolean = FALSE;

    if IsFeatureImplemented(FEAT_SPE_EXC) then
        if ec_bits == '011111' then                      // implementation defined fault
            return ImpDefBits{2}(&quot;target_el for SPE ImpDef Fault&quot;);
        end;

        let s1fault : boolean = (ec_bits == '100100');   // Stage 1 fault
        let s2fault : boolean = (ec_bits == '100101');   // Stage 2 fault

        var gpcfault, gpfault : boolean;
        if IsFeatureImplemented(FEAT_RME) then
            // Granule Protection Check fault, other than GPF. That is, a GPT address size fault,
            // GPT walk fault, or synchronous External abort on GPT fetch.
            gpcfault = (ec_bits == '011110');
            // Other Granule Protection Fault, reported as Stage 1 or Stage 2 fault.
            gpfault  =  ((s1fault || s2fault) &amp;&amp; fsc_bits IN {'10001x', '1001xx', '101000'});
        else
            gpcfault = FALSE;
            gpfault  = FALSE;
        end;
        let sync_ext_abort : boolean = ((s1fault || s2fault) &amp;&amp;
                                           fsc_bits IN {'010000', '01001x', '0101xx', '011011'});

        var owning_ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>;
        var owning_el : bits(2);
        (owning_ss, owning_el) = <a link="func_ProfilingBufferOwner_0" file="shared_pseudocode.xml">ProfilingBufferOwner</a>();

        if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; MDCR_EL3().PMSEE == '1x' then
            route_to_el3 = (MDCR_EL3().PMSEE == '11' ||
                            gpcfault || (gpfault &amp;&amp; SCR_EL3().GPF == '1') ||
                            (sync_ext_abort &amp;&amp; <a link="func_EffectiveEA_0" file="shared_pseudocode.xml">EffectiveEA</a>() == '1'));
        end;

        if <a link="func_EffectivePMSCR_EL2_EE_0" file="shared_pseudocode.xml">EffectivePMSCR_EL2_EE</a>() == '1x' then
            route_to_el2 = (PMSCR_EL2().EE == '11' || (s1fault &amp;&amp; owning_el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) || s2fault ||
                            gpcfault || (gpfault &amp;&amp; HCR_EL2().GPF == '1') ||
                            (sync_ext_abort &amp;&amp; <a link="func_EffectiveHCR_TEA_0" file="shared_pseudocode.xml">EffectiveHCR_TEA</a>() == '1'));
        end;
    end;

    if route_to_el3 then
        target_el = <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
    elsif route_to_el2 then
        target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    else
        target_el = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    end;

    return target_el;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPE" mylink="aarch64.debug.statisticalprofiling.SPE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPE Implementation Constants
// ============================

constant <anchor link="global_SPEMaxAddrs">SPEMaxAddrs</anchor> : integer{}      = 32;
constant <anchor link="global_SPEMaxCounters">SPEMaxCounters</anchor> : integer{}   = 32;
constant <anchor link="global_SPEMaxRecordSize">SPEMaxRecordSize</anchor> : integer{} = 2048;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEAddByteToRecord" mylink="aarch64.debug.statisticalprofiling.SPEAddByteToRecord" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEAddByteToRecord()
// ====================
// Add one byte to a record and increase size property appropriately.

func <anchor link="func_SPEAddByteToRecord_1">SPEAddByteToRecord</anchor>(b : bits(8))
begin
    assert <a link="global_SPERecordSize" file="shared_pseudocode.xml">SPERecordSize</a> &lt; <a link="global_SPEMaxRecordSize" file="shared_pseudocode.xml">SPEMaxRecordSize</a>;
    <a link="global_SPERecordData" file="shared_pseudocode.xml">SPERecordData</a>[[<a link="global_SPERecordSize" file="shared_pseudocode.xml">SPERecordSize</a>]] = b;
    <a link="global_SPERecordSize" file="shared_pseudocode.xml">SPERecordSize</a> = <a link="global_SPERecordSize" file="shared_pseudocode.xml">SPERecordSize</a> + 1;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEAddPacketToRecord" mylink="aarch64.debug.statisticalprofiling.SPEAddPacketToRecord" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEAddPacketToRecord()
// ======================
// Add passed header and payload data to the record.
// Payload must be a multiple of 8.

func <anchor link="func_SPEAddPacketToRecord_4">SPEAddPacketToRecord</anchor>{N}(header_hi : bits(2), header_lo : bits(4),
                             payload : bits(N))
begin
    assert N MOD 8 == 0;
    var sz : bits(2);
    case N of
        when 8  =&gt; sz = '00';
        when 16 =&gt; sz = '01';
        when 32 =&gt; sz = '10';
        when 64 =&gt; sz = '11';
        otherwise =&gt; unreachable;
    end;

    let header : bits(8) = header_hi::sz::header_lo;
    <a link="func_SPEAddByteToRecord_1" file="shared_pseudocode.xml">SPEAddByteToRecord</a>(header);
    for i = 0 to (N DIV 8)-1 do
        <a link="func_SPEAddByteToRecord_1" file="shared_pseudocode.xml">SPEAddByteToRecord</a>(payload[i*:8]);
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEBranch" mylink="aarch64.debug.statisticalprofiling.SPEBranch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEBranch()
// ===========
// Called on every branch if SPE is present. Maintains previous branch target
// and branch related SPE functionality.

func <anchor link="func_SPEBranch_5">SPEBranch</anchor>{N}(target : bits(N), branch_type : <a link="type_BranchType" file="shared_pseudocode.xml">BranchType</a>, conditional : boolean,
                  taken_flag : boolean)
begin
    let is_isb : boolean = FALSE;
    <a link="func_SPEBranch_6" file="shared_pseudocode.xml">SPEBranch</a>{N}(target, branch_type, conditional, taken_flag, is_isb);
end;

func <anchor link="func_SPEBranch_6">SPEBranch</anchor>{N}(target : bits(N), branch_type : <a link="type_BranchType" file="shared_pseudocode.xml">BranchType</a>, conditional : boolean,
                  taken_flag : boolean, is_isb : boolean)
begin
    // If the PE implements branch prediction, data about (mis)prediction is collected
    // through the PMU events.

    var collect_prev_br : boolean;
    let collect_prev_br_eret : boolean = ImpDefBool(&quot;SPE prev br on eret&quot;);
    let collect_prev_br_exception : boolean = (ImpDefBool(
                                                  &quot;SPE prev br on exception&quot;));
    let collect_prev_br_isb : boolean = ImpDefBool(&quot;SPE prev br on isb&quot;);
    case branch_type of
        when <a link="enum_BranchType_EXCEPTION" file="shared_pseudocode.xml">BranchType_EXCEPTION</a> =&gt; collect_prev_br = collect_prev_br_exception;
        when <a link="enum_BranchType_ERET" file="shared_pseudocode.xml">BranchType_ERET</a>      =&gt; collect_prev_br = collect_prev_br_eret;
        otherwise                 =&gt; collect_prev_br = !is_isb || collect_prev_br_isb;
    end;

    // Implements previous branch target functionality
    if (taken_flag &amp;&amp; IsFeatureImplemented(FEAT_SPE_PBT) &amp;&amp; <a link="func_StatisticalProfilingEnabled_0" file="shared_pseudocode.xml">StatisticalProfilingEnabled</a>() &amp;&amp;
            collect_prev_br) then

        if <a link="global_SPESampleInFlight" file="shared_pseudocode.xml">SPESampleInFlight</a> then
            let previous_target : bits(64) = <a link="global_SPESamplePreviousBranchAddress" file="shared_pseudocode.xml">SPESamplePreviousBranchAddress</a>;
            <a link="global_SPESampleAddress" file="shared_pseudocode.xml">SPESampleAddress</a>[[<a link="global_SPEAddrPosPrevBranchTarget" file="shared_pseudocode.xml">SPEAddrPosPrevBranchTarget</a>]][63:0] = previous_target[63:0];
            let previous_branch_valid : boolean = <a link="global_SPESamplePreviousBranchAddressValid" file="shared_pseudocode.xml">SPESamplePreviousBranchAddressValid</a>;
            <a link="global_SPESampleAddressValid" file="shared_pseudocode.xml">SPESampleAddressValid</a>[[<a link="global_SPEAddrPosPrevBranchTarget" file="shared_pseudocode.xml">SPEAddrPosPrevBranchTarget</a>]] = previous_branch_valid;
        end;
        // Save the target address for it to be added to a future record.
        <a link="global_SPESamplePreviousBranchAddress" file="shared_pseudocode.xml">SPESamplePreviousBranchAddress</a>[55:0] = target[55:0];

        var ns : bit;
        var nse : bit;
        case <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() of
            when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;
                ns = '0';
                nse = '0';
            when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt;
                ns = '1';
                nse = '0';
            when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;
                ns  = '1';
                nse = '1';
            otherwise =&gt; unreachable;
        end;

        <a link="global_SPESamplePreviousBranchAddress" file="shared_pseudocode.xml">SPESamplePreviousBranchAddress</a>[63] = ns;
        <a link="global_SPESamplePreviousBranchAddress" file="shared_pseudocode.xml">SPESamplePreviousBranchAddress</a>[60] = nse;
        <a link="global_SPESamplePreviousBranchAddress" file="shared_pseudocode.xml">SPESamplePreviousBranchAddress</a>[62:61] = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
        <a link="global_SPESamplePreviousBranchAddressValid" file="shared_pseudocode.xml">SPESamplePreviousBranchAddressValid</a>   = TRUE;
    end;

    if !<a link="func_StatisticalProfilingEnabled_0" file="shared_pseudocode.xml">StatisticalProfilingEnabled</a>() then
        if taken_flag then
            // Invalidate previous branch address, if profiling is disabled
            // or prohibited.
            <a link="global_SPESamplePreviousBranchAddressValid" file="shared_pseudocode.xml">SPESamplePreviousBranchAddressValid</a> = FALSE;
        end;
        return;
    end;

    if <a link="global_SPESampleInFlight" file="shared_pseudocode.xml">SPESampleInFlight</a> then
        <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.branch_is_direct = branch_type IN {<a link="enum_BranchType_DIR" file="shared_pseudocode.xml">BranchType_DIR</a>, <a link="enum_BranchType_DIRCALL" file="shared_pseudocode.xml">BranchType_DIRCALL</a>};
        <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.branch_has_link  = branch_type IN {<a link="enum_BranchType_DIRCALL" file="shared_pseudocode.xml">BranchType_DIRCALL</a>, <a link="enum_BranchType_INDCALL" file="shared_pseudocode.xml">BranchType_INDCALL</a>};
        <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.procedure_return = branch_type == <a link="enum_BranchType_RET" file="shared_pseudocode.xml">BranchType_RET</a>;
        <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type          = <a link="enum_SPEOpType_Branch" file="shared_pseudocode.xml">SPEOpType_Branch</a>;
        <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_conditional   = conditional;
        <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.cond_pass        = taken_flag;

        // Save the target address.
        if taken_flag then
            var ns : bit;
            var nse : bit;
            case <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() of
                when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;
                    ns = '0';
                    nse = '0';
                when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt;
                    ns = '1';
                    nse = '0';
                when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;
                    ns  = '1';
                    nse = '1';
                otherwise =&gt; unreachable;
            end;
            let el : bits(2) = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;

            <a link="global_SPESampleAddress" file="shared_pseudocode.xml">SPESampleAddress</a>[[<a link="global_SPEAddrPosBranchTarget" file="shared_pseudocode.xml">SPEAddrPosBranchTarget</a>]][55:0]  = target[55:0];
            <a link="global_SPESampleAddress" file="shared_pseudocode.xml">SPESampleAddress</a>[[<a link="global_SPEAddrPosBranchTarget" file="shared_pseudocode.xml">SPEAddrPosBranchTarget</a>]][63:56] = ns::el::nse::Zeros{4};
            <a link="global_SPESampleAddressValid" file="shared_pseudocode.xml">SPESampleAddressValid</a>[[<a link="global_SPEAddrPosBranchTarget" file="shared_pseudocode.xml">SPEAddrPosBranchTarget</a>]]   = TRUE;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEBufferIsFull" mylink="aarch64.debug.statisticalprofiling.SPEBufferIsFull" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEBufferIsFull()
// =================
// Return true if another full size sample record would not fit in the
// profiling buffer.

func <anchor link="func_SPEBufferIsFull_0">SPEBufferIsFull</anchor>() =&gt; boolean
begin
    let write_pointer_limit : integer   = UInt(PMBLIMITR_EL1().LIMIT::Zeros{12});
    let current_write_pointer : integer = UInt(PMBPTR_EL1());
    let record_max_size : integer       = 1 &lt;&lt; UInt(PMSIDR_EL1().MaxSize);
    return current_write_pointer &gt; (write_pointer_limit - record_max_size);
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPECollectRecord" mylink="aarch64.debug.statisticalprofiling.SPECollectRecord" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPECollectRecord()
// ==================
// Returns TRUE if the sampled class of instructions or operations, as
// determined by PMSFCR_EL1, are recorded and FALSE otherwise.

func <anchor link="func_SPECollectRecord_3">SPECollectRecord</anchor>(events : bits(64), total_latency : integer, optype : <a link="type_SPEOpType" file="shared_pseudocode.xml">SPEOpType</a>) =&gt; boolean
begin
    // Filtering by events
    var is_rejected_event : boolean;
    var is_rejected_nevent : boolean;
    (is_rejected_event, is_rejected_nevent) = <a link="func_SPEFilterByEvents_1" file="shared_pseudocode.xml">SPEFilterByEvents</a>(events);

    // Filtering by type
    let is_rejected_type : boolean = <a link="func_SPEFilterByType_1" file="shared_pseudocode.xml">SPEFilterByType</a>(<a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>);

    // Filtering by latency
    let is_rejected_latency : boolean = <a link="func_SPEFilterByLatency_1" file="shared_pseudocode.xml">SPEFilterByLatency</a>(total_latency);

    let is_rejected_data_source : boolean = <a link="func_SPEFilterByDataSource_1" file="shared_pseudocode.xml">SPEFilterByDataSource</a>(optype);

    var return_value : boolean;
    return_value = !(is_rejected_nevent || is_rejected_event ||
                     is_rejected_type || is_rejected_latency ||
                     is_rejected_data_source);

    if return_value then
        <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SAMPLE_FILTRATE);
    end;

    return return_value;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPECompleteSample" mylink="aarch64.debug.statisticalprofiling.SPECompleteSample" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPECompleteSample()
// ===================
// Called to complete the sampling process.

func <anchor link="func_SPECompleteSample_0">SPECompleteSample</anchor>()
begin
    assert <a link="global_SPESampleInFlight" file="shared_pseudocode.xml">SPESampleInFlight</a>;

    <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SAMPLE_FEED);

    // Stop any pending counters
    for counter_index = 0 to (<a link="global_SPEMaxCounters" file="shared_pseudocode.xml">SPEMaxCounters</a> - 1) do
        if <a link="global_SPESampleCounterPending" file="shared_pseudocode.xml">SPESampleCounterPending</a>[[counter_index]] then
            <a link="func_SPEStopCounter_1" file="shared_pseudocode.xml">SPEStopCounter</a>(counter_index);
        end;
    end;

    // Record any IMPLEMENTATION DEFINED events
    let impdef_events : bits(64) = ImpDefBits{}(&quot;SPE EVENTS&quot;);
    <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[63:48] = impdef_events[63:48];
    // The number of bits available for IMPLEMENTATION DEFINED events
    // is reduced by FEAT_SPEv1p4
    if !IsFeatureImplemented(FEAT_SPEv1p4) then
        <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[31:24] = impdef_events[31:24];
    end;
    <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[15:12] = impdef_events[15:12];
    // Bit 24 encodes whether the sample was collected in Streaming SVE mode.
    if IsFeatureImplemented(FEAT_SPE_SME) then
        <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[24] = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM;
    end;
    <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[6] = if (<a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_conditional &amp;&amp;
                               !<a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.cond_pass) then '1' else '0';

    var collect_record : boolean;
    collect_record = <a link="func_SPECollectRecord_3" file="shared_pseudocode.xml">SPECollectRecord</a>(<a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>,
                                      <a link="global_SPESampleCounter" file="shared_pseudocode.xml">SPESampleCounter</a>[[<a link="global_SPECounterPosTotalLatency" file="shared_pseudocode.xml">SPECounterPosTotalLatency</a>]],
                                      <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type);
    var discard : boolean = FALSE;
    if IsFeatureImplemented(FEAT_SPEv1p2) then
        discard = PMBLIMITR_EL1().FM == '10';
    end;
    if collect_record &amp;&amp; !discard then
        <a link="func_SPEConstructRecord_0" file="shared_pseudocode.xml">SPEConstructRecord</a>();
        if <a link="func_SPEBufferIsFull_0" file="shared_pseudocode.xml">SPEBufferIsFull</a>() then
            let bsc : bits(6) = '000001';     // Buffer full event
            <a link="func_OtherSPEManagementEvent_1" file="shared_pseudocode.xml">OtherSPEManagementEvent</a>(bsc);
            <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SAMPLE_BUFFER_FULL);
        end;
    end;

    <a link="global_SPESampleInFlight" file="shared_pseudocode.xml">SPESampleInFlight</a> = FALSE;

    <a link="func_SPEResetSampleStorage_0" file="shared_pseudocode.xml">SPEResetSampleStorage</a>();
end;

// Order of addresses in sample storage and architectural index values
constant <anchor link="global_SPEAddrPosPCVirtual">SPEAddrPosPCVirtual</anchor> : integer    = 0;
constant <anchor link="global_SPEAddrPosBranchTarget">SPEAddrPosBranchTarget</anchor> : integer = 1;
constant <anchor link="global_SPEAddrPosDataVirtual">SPEAddrPosDataVirtual</anchor> : integer  = 2;
constant <anchor link="global_SPEAddrPosDataPhysical">SPEAddrPosDataPhysical</anchor> : integer = 3;
constant <anchor link="global_SPEAddrPosPrevBranchTarget">SPEAddrPosPrevBranchTarget</anchor> : integer = 4;
// Order of counters in sample storage and architectural index values
constant <anchor link="global_SPECounterPosTotalLatency">SPECounterPosTotalLatency</anchor> : integer = 0;
constant <anchor link="global_SPECounterPosIssueLatency">SPECounterPosIssueLatency</anchor> : integer = 1;
constant <anchor link="global_SPECounterPosTranslationLatency">SPECounterPosTranslationLatency</anchor> : integer = 2;
constant <anchor link="global_SPECounterPosAltIssueLatency">SPECounterPosAltIssueLatency</anchor> : integer = 4;
// Sample in-flight flag
var <anchor link="global_SPESampleInFlight">SPESampleInFlight</anchor> : boolean = FALSE;

// Globally declared variables which store data about the sample.

// Context storage
var <anchor link="global_SPESampleContextEL1">SPESampleContextEL1</anchor> : bits(32);
var <anchor link="global_SPESampleContextEL1Valid">SPESampleContextEL1Valid</anchor> : boolean;
var <anchor link="global_SPESampleContextEL2">SPESampleContextEL2</anchor> : bits(32);
var <anchor link="global_SPESampleContextEL2Valid">SPESampleContextEL2Valid</anchor> : boolean;

// Counter storage
var <anchor link="global_SPESampleCounter">SPESampleCounter</anchor> : array [[<a link="global_SPEMaxCounters" file="shared_pseudocode.xml">SPEMaxCounters</a>]] of integer;
var <anchor link="global_SPESampleCounterValid">SPESampleCounterValid</anchor> : array [[<a link="global_SPEMaxCounters" file="shared_pseudocode.xml">SPEMaxCounters</a>]] of boolean;
var <anchor link="global_SPESampleCounterPending">SPESampleCounterPending</anchor> : array [[<a link="global_SPEMaxCounters" file="shared_pseudocode.xml">SPEMaxCounters</a>]] of boolean;

// Address storage
var <anchor link="global_SPESampleAddress">SPESampleAddress</anchor> : array [[<a link="global_SPEMaxAddrs" file="shared_pseudocode.xml">SPEMaxAddrs</a>]] of bits(64);
var <anchor link="global_SPESampleAddressValid">SPESampleAddressValid</anchor> : array [[<a link="global_SPEMaxAddrs" file="shared_pseudocode.xml">SPEMaxAddrs</a>]] of boolean;
var <anchor link="global_SPESamplePreviousBranchAddress">SPESamplePreviousBranchAddress</anchor> : bits(64);
var <anchor link="global_SPESamplePreviousBranchAddressValid">SPESamplePreviousBranchAddressValid</anchor> : boolean;

// Data source storage
var <anchor link="global_SPESampleDataSource">SPESampleDataSource</anchor> : bits(16);
var <anchor link="global_SPESampleDataSourceValid">SPESampleDataSourceValid</anchor> : boolean;

// OpAttr storage
var <anchor link="global_SPESampleOpAttr">SPESampleOpAttr</anchor> : <a link="type_SPEOpAttr" file="shared_pseudocode.xml">SPEOpAttr</a>;

// Timestamp storage
var <anchor link="global_SPESampleTimestamp">SPESampleTimestamp</anchor> : bits(64);
var <anchor link="global_SPESampleTimestampValid">SPESampleTimestampValid</anchor> : boolean;

// Event storage
var <anchor link="global_SPESampleEvents">SPESampleEvents</anchor> : bits(64);</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEConstructClass" mylink="aarch64.debug.statisticalprofiling.SPEConstructClass" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEConstructClass()
// ===================
// Constructs the encodings for the class and subclass fields.

func <anchor link="func_SPEConstructClass_0">SPEConstructClass</anchor>() =&gt; (bits(2), bits(8))
begin
    var op_class : bits(2);
    var op_subclass : bits(8);
    let cond : bit     = if <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_conditional then '1' else '0';
    let fp : bit       = if <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_floating_point then '1' else '0';
    let ldst : bit     = if <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type == <a link="enum_SPEOpType_Store" file="shared_pseudocode.xml">SPEOpType_Store</a> then '1' else '0';
    let ar : bit       = if <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_acquire_release then '1' else '0';
    let excl : bit     = if <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_exclusive then '1' else '0';
    let at : bit       = if <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.at then '1' else '0';
    let indirect : bit = if <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.branch_is_direct then '0' else '1';
    let pred : bit = if <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_predicated then '1' else '0';
    let sg : bit   = if <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_gather_scatter then '1' else '0';
    let evl : bits(3) = <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.evl;
    let simd : bit = if <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_simd then '1' else '0';
    let ets : bits(4) = <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.ets;
    // Since this implementation of SPE samples instruction instead of micro-operations, a
    // Branch with link or Procedure return instruction will never be recorded as a &quot;Load/store,
    // GCS&quot; format Operation Type packet. Therefore the COMMON bit is hard-wired to '1'.
    let common : bit = '1';
    if <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type == <a link="enum_SPEOpType_Other" file="shared_pseudocode.xml">SPEOpType_Other</a> then
        op_class = '00';
        op_subclass = Zeros{5}::simd::fp::cond;
    elsif <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type == <a link="enum_SPEOpType_OtherSVE" file="shared_pseudocode.xml">SPEOpType_OtherSVE</a> then
        op_class = '00';
        op_subclass = '0'::evl::'1'::pred::fp::'0';
    elsif <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type == <a link="enum_SPEOpType_OtherSME" file="shared_pseudocode.xml">SPEOpType_OtherSME</a> then
        op_class = '00';
        op_subclass = '1'::ets[3:1]::'1'::ets[0]::fp::'0';
    elsif <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type == <a link="enum_SPEOpType_Branch" file="shared_pseudocode.xml">SPEOpType_Branch</a> then
        op_class = '10';
        var cr : bits(2) = '00';
        var gcs : bit = '0';
        if IsFeatureImplemented(FEAT_SPE_CRR) then
            if <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.branch_has_link then
                cr = '01';
            elsif <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.procedure_return then
                cr = '10';
            else
                cr = '11';
            end;
        end;
        if IsFeatureImplemented(FEAT_GCS) then
            if (<a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.ldst_type == <a link="enum_SPELDSTType_GCS" file="shared_pseudocode.xml">SPELDSTType_GCS</a> &amp;&amp;
                 (<a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.branch_has_link || <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.procedure_return)) then
                gcs = '1';
            end;
        end;
        op_subclass = Zeros{3}::cr::gcs::indirect::cond;
    elsif <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type IN {<a link="enum_SPEOpType_Load" file="shared_pseudocode.xml">SPEOpType_Load</a>, <a link="enum_SPEOpType_Store" file="shared_pseudocode.xml">SPEOpType_Store</a>, <a link="enum_SPEOpType_LoadAtomic" file="shared_pseudocode.xml">SPEOpType_LoadAtomic</a>} then
        op_class = '01';
        case <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.ldst_type of
            when <a link="enum_SPELDSTType_NV2" file="shared_pseudocode.xml">SPELDSTType_NV2</a>         =&gt; op_subclass = '0011000'::ldst;
            when <a link="enum_SPELDSTType_Extended" file="shared_pseudocode.xml">SPELDSTType_Extended</a>    =&gt; op_subclass = '000'::ar::excl::at::'1'::ldst;
            when <a link="enum_SPELDSTType_General" file="shared_pseudocode.xml">SPELDSTType_General</a>     =&gt; op_subclass = Zeros{7}::ldst;
            when <a link="enum_SPELDSTType_SIMDFP" file="shared_pseudocode.xml">SPELDSTType_SIMDFP</a>      =&gt; op_subclass = '0000010'::ldst;
            when <a link="enum_SPELDSTType_SVESME" file="shared_pseudocode.xml">SPELDSTType_SVESME</a>      =&gt; op_subclass = sg::evl::'1'::pred::'0'::ldst;
            when <a link="enum_SPELDSTType_Unspecified" file="shared_pseudocode.xml">SPELDSTType_Unspecified</a> =&gt; op_subclass = '0001000'::ldst;
            when <a link="enum_SPELDSTType_Tags" file="shared_pseudocode.xml">SPELDSTType_Tags</a>        =&gt; op_subclass = '0001010'::ldst;
            when <a link="enum_SPELDSTType_MemCopy" file="shared_pseudocode.xml">SPELDSTType_MemCopy</a>     =&gt; op_subclass = '0010000'::ldst;
            when <a link="enum_SPELDSTType_MemSet" file="shared_pseudocode.xml">SPELDSTType_MemSet</a>      =&gt; op_subclass = '00100101';
            when <a link="enum_SPELDSTType_GCS" file="shared_pseudocode.xml">SPELDSTType_GCS</a>         =&gt; op_subclass = '01000'::common::'0'::ldst;
            when <a link="enum_SPELDSTType_GCSSS2" file="shared_pseudocode.xml">SPELDSTType_GCSSS2</a>      =&gt; unreachable;
                // GCSSS2 is converted to GCS, should not appear here
            otherwise                    =&gt; unreachable;
        end;
    else
        unreachable;
    end;
    return (op_class, op_subclass);
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEConstructRecord" mylink="aarch64.debug.statisticalprofiling.SPEConstructRecord" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEConstructRecord()
// ====================
// Create new record and populate it with packets using sample storage data.
// This is an example implementation, packets may appear in
// any order as long as the record ends with an End or Timestamp packet.

func <anchor link="func_SPEConstructRecord_0">SPEConstructRecord</anchor>()
begin
    // Empty the record.
    <a link="func_SPEEmptyRecord_0" file="shared_pseudocode.xml">SPEEmptyRecord</a>();

    var op_class : bits(2);
    var op_subclass : bits(8);
    (op_class, op_subclass) = <a link="func_SPEConstructClass_0" file="shared_pseudocode.xml">SPEConstructClass</a>();
    // Add operation details
    <a link="func_SPEAddPacketToRecord_4" file="shared_pseudocode.xml">SPEAddPacketToRecord</a>{8}('01', '10'::op_class, op_subclass);


    // Add contextEL1 if available
    if <a link="global_SPESampleContextEL1Valid" file="shared_pseudocode.xml">SPESampleContextEL1Valid</a> then
        <a link="func_SPEAddPacketToRecord_4" file="shared_pseudocode.xml">SPEAddPacketToRecord</a>{32}('01', '0100', <a link="global_SPESampleContextEL1" file="shared_pseudocode.xml">SPESampleContextEL1</a>);
    end;

     // Add contextEL2 if available
    if <a link="global_SPESampleContextEL2Valid" file="shared_pseudocode.xml">SPESampleContextEL2Valid</a> then
        <a link="func_SPEAddPacketToRecord_4" file="shared_pseudocode.xml">SPEAddPacketToRecord</a>{32}('01', '0101', <a link="global_SPESampleContextEL2" file="shared_pseudocode.xml">SPESampleContextEL2</a>);
    end;

    // Add valid counters
    for counter_index = 0 to (<a link="global_SPEMaxCounters" file="shared_pseudocode.xml">SPEMaxCounters</a> - 1) do
        if <a link="global_SPESampleCounterValid" file="shared_pseudocode.xml">SPESampleCounterValid</a>[[counter_index]] then
            if counter_index &gt;= 8 then
                // Need extended format
                <a link="func_SPEAddByteToRecord_1" file="shared_pseudocode.xml">SPEAddByteToRecord</a>('001000'::counter_index[4:3]);
            end;
            // Check for overflow
            let large_counters : boolean = ImpDefBool(&quot;SPE 16bit counters&quot;);
            if large_counters then
                if <a link="global_SPESampleCounter" file="shared_pseudocode.xml">SPESampleCounter</a>[[counter_index]] &gt; 0xFFFF then
                    <a link="global_SPESampleCounter" file="shared_pseudocode.xml">SPESampleCounter</a>[[counter_index]] = 0xFFFF;
                end;
            else
                if <a link="global_SPESampleCounter" file="shared_pseudocode.xml">SPESampleCounter</a>[[counter_index]] &gt; 0xFFF then
                    <a link="global_SPESampleCounter" file="shared_pseudocode.xml">SPESampleCounter</a>[[counter_index]] = 0xFFF;
                end;
            end;

            // Add byte0 for short format (byte1 for extended format)
            <a link="func_SPEAddPacketToRecord_4" file="shared_pseudocode.xml">SPEAddPacketToRecord</a>{16}('10', '1'::counter_index[2:0],
                                     <a link="global_SPESampleCounter" file="shared_pseudocode.xml">SPESampleCounter</a>[[counter_index]][15:0]);
        end;
    end;

    // Add valid addresses
    if IsFeatureImplemented(FEAT_SPE_PBT) then
        // Under the some conditions, it is IMPLEMENTATION_DEFINED whether
        // previous branch packet is present.
        let include_prev_br : boolean = (ImpDefBool(
                                            &quot;SPE get prev br if not br&quot;));
        if <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type != <a link="enum_SPEOpType_Branch" file="shared_pseudocode.xml">SPEOpType_Branch</a> &amp;&amp; !include_prev_br then
            <a link="global_SPESampleAddressValid" file="shared_pseudocode.xml">SPESampleAddressValid</a>[[<a link="global_SPEAddrPosPrevBranchTarget" file="shared_pseudocode.xml">SPEAddrPosPrevBranchTarget</a>]] = FALSE;
        end;
    end;

    // Data Virtual address should not be collected if this was an NV2 access and Statistical
    // Profiling is disabled at EL2.
    if !<a link="func_StatisticalProfilingEnabled_1" file="shared_pseudocode.xml">StatisticalProfilingEnabled</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.ldst_type == <a link="enum_SPELDSTType_NV2" file="shared_pseudocode.xml">SPELDSTType_NV2</a> then
        <a link="global_SPESampleAddressValid" file="shared_pseudocode.xml">SPESampleAddressValid</a>[[<a link="global_SPEAddrPosDataVirtual" file="shared_pseudocode.xml">SPEAddrPosDataVirtual</a>]] = FALSE;
    end;

    for address_index = 0 to (<a link="global_SPEMaxAddrs" file="shared_pseudocode.xml">SPEMaxAddrs</a> - 1) do
        if <a link="global_SPESampleAddressValid" file="shared_pseudocode.xml">SPESampleAddressValid</a>[[address_index]] then
            if address_index &gt;= 8 then
                // Need extended format
                <a link="func_SPEAddByteToRecord_1" file="shared_pseudocode.xml">SPEAddByteToRecord</a>('001000'::address_index[4:3]);
            end;
            // Add byte0 for short format (byte1 for extended format)
            <a link="func_SPEAddPacketToRecord_4" file="shared_pseudocode.xml">SPEAddPacketToRecord</a>{64}('10', '0'::address_index[2:0],
                                     <a link="global_SPESampleAddress" file="shared_pseudocode.xml">SPESampleAddress</a>[[address_index]]);
        end;
    end;

    // Add Data Source
    if <a link="global_SPESampleDataSourceValid" file="shared_pseudocode.xml">SPESampleDataSourceValid</a> then
        let ds_payload_size : integer{} = <a link="func_SPEGetDataSourcePayloadSize_0" file="shared_pseudocode.xml">SPEGetDataSourcePayloadSize</a>();
        <a link="func_SPEAddPacketToRecord_4" file="shared_pseudocode.xml">SPEAddPacketToRecord</a>{8 * ds_payload_size}('01', '0011',
                                                  <a link="global_SPESampleDataSource" file="shared_pseudocode.xml">SPESampleDataSource</a>[8*ds_payload_size-1:0]);
    end;

    // Add events
    // Get size of payload in bytes.
    let payload_size : integer{} = <a link="func_SPEGetEventsPayloadSize_0" file="shared_pseudocode.xml">SPEGetEventsPayloadSize</a>();
    <a link="func_SPEAddPacketToRecord_4" file="shared_pseudocode.xml">SPEAddPacketToRecord</a>{8 * payload_size}('01', '0010', <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[8*payload_size-1:0]);

    // Add Timestamp to end the record if one is available.
    // Otherwise end with an End packet.
    if <a link="global_SPESampleTimestampValid" file="shared_pseudocode.xml">SPESampleTimestampValid</a> then
        <a link="func_SPEAddPacketToRecord_4" file="shared_pseudocode.xml">SPEAddPacketToRecord</a>{64}('01', '0001', <a link="global_SPESampleTimestamp" file="shared_pseudocode.xml">SPESampleTimestamp</a>);
    else
        <a link="func_SPEAddByteToRecord_1" file="shared_pseudocode.xml">SPEAddByteToRecord</a>('00000001');
    end;

    // Add padding
    while <a link="global_SPERecordSize" file="shared_pseudocode.xml">SPERecordSize</a> MOD (1&lt;&lt;UInt(PMBIDR_EL1().Align)) != 0 looplimit 2048 do
        <a link="func_SPEAddByteToRecord_1" file="shared_pseudocode.xml">SPEAddByteToRecord</a>(Zeros{8});
    end;
    <a link="func_SPEWriteToBuffer_0" file="shared_pseudocode.xml">SPEWriteToBuffer</a>();
    CTI_SignalEvent(<a link="enum_CrossTriggerIn_SPESample" file="shared_pseudocode.xml">CrossTriggerIn_SPESample</a>);
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPECycle" mylink="aarch64.debug.statisticalprofiling.SPECycle" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPECycle()
// ==========
// Function called at the end of every cycle. Responsible for asserting interrupts
// and advancing counters.

func <anchor link="func_SPECycle_0">SPECycle</anchor>()
begin
    if !IsFeatureImplemented(FEAT_SPE) then
        return;
    end;

    // Increment pending counters
    if <a link="global_SPESampleInFlight" file="shared_pseudocode.xml">SPESampleInFlight</a> then
        for i = 0 to (<a link="global_SPEMaxCounters" file="shared_pseudocode.xml">SPEMaxCounters</a> - 1) do
            if <a link="global_SPESampleCounterPending" file="shared_pseudocode.xml">SPESampleCounterPending</a>[[i]] then
                <a link="global_SPESampleCounter" file="shared_pseudocode.xml">SPESampleCounter</a>[[i]] = <a link="global_SPESampleCounter" file="shared_pseudocode.xml">SPESampleCounter</a>[[i]] + 1;
            end;
        end;
    end;

    // Assert PMBIRQ if appropriate.
    if <a link="func_SPEInterruptEnabled_0" file="shared_pseudocode.xml">SPEInterruptEnabled</a>() &amp;&amp; PMBSR_EL1().S == '1' then
        SetInterruptRequestLevel(<a link="enum_InterruptID_PMBIRQ" file="shared_pseudocode.xml">InterruptID_PMBIRQ</a>, <a link="enum_HIGH" file="shared_pseudocode.xml">HIGH</a>);
    else
        SetInterruptRequestLevel(<a link="enum_InterruptID_PMBIRQ" file="shared_pseudocode.xml">InterruptID_PMBIRQ</a>, <a link="enum_LOW" file="shared_pseudocode.xml">LOW</a>);
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEEmptyRecord" mylink="aarch64.debug.statisticalprofiling.SPEEmptyRecord" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEEmptyRecord()
// ================
// Reset record data.

func <anchor link="func_SPEEmptyRecord_0">SPEEmptyRecord</anchor>()
begin
    <a link="global_SPERecordSize" file="shared_pseudocode.xml">SPERecordSize</a> = 0;
    for i = 0 to (<a link="global_SPEMaxRecordSize" file="shared_pseudocode.xml">SPEMaxRecordSize</a> - 1) do
        <a link="global_SPERecordData" file="shared_pseudocode.xml">SPERecordData</a>[[i]] = Zeros{8};
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEEncodeETS" mylink="aarch64.debug.statisticalprofiling.SPEEncodeETS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEEncodeETS()
// ==============
// Encodes an integer tile size length into the ets field for the SPE operation type packet.

func <anchor link="func_SPEEncodeETS_1">SPEEncodeETS</anchor>(size : integer) =&gt; bits(4)
begin
    var ets : bits(4);
    if size &lt;= 128 then
        ets = '0000';
    elsif size &lt;= 256 then
        ets = '0001';
    elsif size &lt;= 512 then
        ets = '0010';
    elsif size &lt;= 1024 then
        ets = '0011';
    elsif size &lt;= 2048 then
        ets = '0100';
    elsif size &lt;= 4096 then
        ets = '0101';
    elsif size &lt;= 8192 then
        ets = '0110';
    elsif size &lt;= 16384 then
        ets = '0111';
    elsif size &lt;= 32768 then
        ets = '1000';
    elsif size &lt;= 65536 then
        ets = '1001';
    elsif size &lt;= 131072 then
        ets = '1010';
    elsif size &lt;= 262144 then
        ets = '1011';
    else
        ets = '1111';
    end;
    return ets;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEEncodeEVL" mylink="aarch64.debug.statisticalprofiling.SPEEncodeEVL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEEncodeEVL()
// ==============
// Encodes an integer vector length into the evl field for the SPE operation type packet.

func <anchor link="func_SPEEncodeEVL_1">SPEEncodeEVL</anchor>(vl : integer) =&gt; bits(3)
begin
    var evl : bits(3);
    if vl &lt;= 32 then
        evl = '000';
    elsif vl &lt;= 64 then
        evl = '001';
    elsif vl &lt;= 128 then
        evl = '010';
    elsif vl &lt;= 256 then
        evl = '011';
    elsif vl &lt;= 512 then
        evl = '100';
    elsif vl &lt;= 1024 then
        evl = '101';
    elsif vl &lt;= 2048 then
        evl = '110';
    else
        if IsFeatureImplemented(FEAT_SPE_SME) then
            evl = '111';
        else
            unreachable;
        end;
    end;
    return evl;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEEvent" mylink="aarch64.debug.statisticalprofiling.SPEEvent" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEEvent()
// ==========
// Called when a PMU event is generated by the sampled structure.
// Sets appropriate bit in SPESampleStorage.events.

func <anchor link="func_SPEEvent_1">SPEEvent</anchor>(pmuevent : bits(16))
begin
    if !<a link="global_SPESampleInFlight" file="shared_pseudocode.xml">SPESampleInFlight</a> then
        return;
    end;
    case pmuevent of
        when PMU_EVENT_DSNP_HIT_RD =&gt;
            if IsFeatureImplemented(FEAT_SPEv1p4) then
                <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[23] = '1';                                  // Snoop hit
            end;
        when {PMU_EVENT_L1D_LFB_HIT_RD, PMU_EVENT_L2D_LFB_HIT_RD,
              PMU_EVENT_L3D_LFB_HIT_RD, PMU_EVENT_LL_LFB_HIT_RD} =&gt;
            if IsFeatureImplemented(FEAT_SPEv1p4) then
                <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[22] = '1';                                  // Recent fetch
            end;
        when {PMU_EVENT_L1D_CACHE_HITM_RD, PMU_EVENT_L2D_CACHE_HITM_RD,
              PMU_EVENT_L3D_CACHE_HITM_RD, PMU_EVENT_LL_CACHE_HITM_RD} =&gt;
            if IsFeatureImplemented(FEAT_SPEv1p4) then
                <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[21] = '1';                                  // Modified
            end;
        when PMU_EVENT_L2D_CACHE_LMISS_RD =&gt;
            if IsFeatureImplemented(FEAT_SPEv1p4) then
                <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[20] = '1';                                  // L2 miss
            end;
        when PMU_EVENT_L2D_CACHE_RD =&gt;
            if IsFeatureImplemented(FEAT_SPEv1p4) then
                <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[19] = '1';                                  // L2 access
            end;
        when PMU_EVENT_SVE_PRED_EMPTY_SPEC =&gt;
            if IsFeatureImplemented(FEAT_SPEv1p1) then
                <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[18] = '1';                                  // Empty predicate
            end;
        when PMU_EVENT_SVE_PRED_NOT_FULL_SPEC =&gt;
            if IsFeatureImplemented(FEAT_SPEv1p1) then
                <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[17] = '1';                                  // Partial predicate
            end;
        when PMU_EVENT_LDST_ALIGN_LAT =&gt;
            if IsFeatureImplemented(FEAT_SPEv1p1) then
                <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[11] = '1';                                  // Misaligned
            end;
        when PMU_EVENT_REMOTE_ACCESS =&gt;         <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[10]  = '1';    // Remote access
        when PMU_EVENT_LL_CACHE_MISS =&gt;         <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[9]   = '1';    // LLC miss
        when PMU_EVENT_LL_CACHE =&gt;              <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[8]   = '1';    // LLC access
        when PMU_EVENT_BR_MIS_PRED =&gt;           <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[7]   = '1';    // Mispredicted
        when PMU_EVENT_BR_MIS_PRED_RETIRED =&gt;   <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[7]   = '1';    // Not taken
        when PMU_EVENT_DTLB_WALK =&gt;             <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[5]   = '1';    // TLB walk
        when PMU_EVENT_L1D_TLB =&gt;               <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[4]   = '1';    // TLB access
        when PMU_EVENT_L1D_CACHE_REFILL =&gt;
            if !IsFeatureImplemented(FEAT_SPEv1p4) then
                <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[3] = '1';                                   // L1 refill
            end;
        when PMU_EVENT_L1D_CACHE_LMISS_RD =&gt;
            if IsFeatureImplemented(FEAT_SPEv1p4) then
                <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[3] = '1';                                   // L1 miss
            end;
        when PMU_EVENT_L1D_CACHE =&gt;             <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[2]   = '1';    // L1 access
        when PMU_EVENT_INST_RETIRED =&gt;          <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[1]   = '1';    // Retire
        when PMU_EVENT_EXC_TAKEN =&gt;             <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[0]   = '1';    // Exception
        otherwise =&gt; return;
    end;
    return;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEFilterByDataSource" mylink="aarch64.debug.statisticalprofiling.SPEFilterByDataSource" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEFilterByDataSource()
// =======================
// Carry out filtering by data source.

func <anchor link="func_SPEFilterByDataSource_1">SPEFilterByDataSource</anchor>(optype : <a link="type_SPEOpType" file="shared_pseudocode.xml">SPEOpType</a>) =&gt; boolean
begin
    // Filtering by Data Source
    var is_rejected_data_source : boolean = FALSE;
    if (IsFeatureImplemented(FEAT_SPE_FDS) &amp;&amp; <a link="global_SPESampleDataSourceValid" file="shared_pseudocode.xml">SPESampleDataSourceValid</a> &amp;&amp;
         (optype IN {<a link="enum_SPEOpType_Load" file="shared_pseudocode.xml">SPEOpType_Load</a>, <a link="enum_SPEOpType_LoadAtomic" file="shared_pseudocode.xml">SPEOpType_LoadAtomic</a>})) then
        let data_source : bits(16) = <a link="global_SPESampleDataSource" file="shared_pseudocode.xml">SPESampleDataSource</a>;
        let index : integer        = UInt(data_source[5:0]);
        let is_ds : boolean        = PMSDSFR_EL1()[index] == '1';
        if is_ds then <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SAMPLE_FEED_DS); end;
        if PMSFCR_EL1().FDS == '1' then
            // Filtering by Data Source is enabled
            is_rejected_data_source = !is_ds;
        end;
    end;
    return is_rejected_data_source;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEFilterByEvents" mylink="aarch64.debug.statisticalprofiling.SPEFilterByEvents" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEFilterByEvents()
// ===================
// Carries out filtering by the event bits.

func <anchor link="func_SPEFilterByEvents_1">SPEFilterByEvents</anchor>(events : bits(64)) =&gt; (boolean, boolean)
begin
    // &quot;mask&quot; defines which Events packet bits are checked by the filter
    var mask : bits(64) = Zeros{};
    let impdef_mask : bits(64) = ImpDefBits{}(&quot;SPE mask&quot;);

    mask[63:48] = impdef_mask[63:48];
    if IsFeatureImplemented(FEAT_SPE_SME) &amp;&amp; IsFeatureImplemented(FEAT_SPEv1p4) then
        mask[25:24] = '11';                 // Streaming mode, SMCU
    end;
    if IsFeatureImplemented(FEAT_SPEv1p4) then
        mask[23:19] = '11111';              // Snoop hit, recent fetch, modified,
                                            // L2 miss, L2 access
    else
        mask[31:24] = impdef_mask[31:24];
    end;
    if IsFeatureImplemented(FEAT_SPEv1p1) &amp;&amp; IsFeatureImplemented(FEAT_SVE) then
        mask[18:17] = '11';                 // Predicates
    end;
    mask[15:12] = impdef_mask[15:12];
    if IsFeatureImplemented(FEAT_SPEv1p1) then
        mask[11] = '1';                     // Data alignment
    end;
    if IsFeatureImplemented(FEAT_SPEv1p4) then
        mask[10:8] = '111';                 // Remote access, LLC access, LLC miss
    else
        mask[10:8] = impdef_mask[10:8];
    end;
    mask[7] = '1';                          // Mispredicted
    if IsFeatureImplemented(FEAT_SPE_FnE) then
        mask[6] = '1';                      // Not taken
    end;
    mask[5,3,1] = '111';                    // TLB walk, L1 miss, retired
    if IsFeatureImplemented(FEAT_SPEv1p4) then
        mask[4,2] = '11';                   // TLB access, L1 access
    else
        mask[4,2] = impdef_mask[4,2];
    end;

    let e : bits(64) = events AND mask;

    // Filtering by event
    let evfr : bits(64) = PMSEVFR_EL1() AND mask;
    var is_rejected_event : boolean = FALSE;
    let is_evt : boolean = IsZero(NOT(e) AND evfr);
    if PMSFCR_EL1().FE == '1' then
        // Filtering by event is enabled
        if !IsZero(evfr) then
            // Not a CONSTRAINED UNPREDICTABLE case
            is_rejected_event = !is_evt;
        else
            is_rejected_event = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BADPMSFCR" file="shared_pseudocode.xml">Unpredictable_BADPMSFCR</a>);
        end;
    end;

    // Filtering by inverse event
    var is_rejected_nevent : boolean = FALSE;
    var is_nevt : boolean;
    if IsFeatureImplemented(FEAT_SPE_FnE) then
        let nevfr : bits(64) = PMSNEVFR_EL1() AND mask;
        is_nevt = IsZero(e AND nevfr);
        if PMSFCR_EL1().FnE == '1' then
            // Inverse filtering by event is enabled
            if !IsZero(nevfr) then
                // Not a CONSTRAINED UNPREDICTABLE case
                is_rejected_nevent = !is_nevt;
            else
                is_rejected_nevent = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BADPMSFCR" file="shared_pseudocode.xml">Unpredictable_BADPMSFCR</a>);
            end;
        end;
    else
        is_nevt = TRUE; // not implemented
    end;
    if is_evt &amp;&amp; is_nevt then
        <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SAMPLE_FEED_EVENT);
    end;
    if (IsFeatureImplemented(FEAT_SPE_FnE) &amp;&amp; PMSFCR_EL1().[FnE,FE]== '11' &amp;&amp;
          !IsZero(PMSEVFR_EL1() AND PMSNEVFR_EL1() AND mask)) then
        // CONSTRAINED UNPREDICTABLE case due to combination of filter and inverse filter
        is_rejected_nevent = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BADPMSFCR" file="shared_pseudocode.xml">Unpredictable_BADPMSFCR</a>);
        is_rejected_event = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BADPMSFCR" file="shared_pseudocode.xml">Unpredictable_BADPMSFCR</a>);
    end;

    return (is_rejected_event, is_rejected_nevent);
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEFilterByLatency" mylink="aarch64.debug.statisticalprofiling.SPEFilterByLatency" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEFilterByLatency()
// ====================
// Carries out filtering by latency.

func <anchor link="func_SPEFilterByLatency_1">SPEFilterByLatency</anchor>(total_latency : integer) =&gt; boolean
begin

    let is_lat : boolean = (total_latency &gt;= UInt(PMSLATFR_EL1().MINLAT));
    if is_lat then <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(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 = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BADPMSFCR" file="shared_pseudocode.xml">Unpredictable_BADPMSFCR</a>);
        end;
    end;

    return is_rejected_latency;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEFilterByType" mylink="aarch64.debug.statisticalprofiling.SPEFilterByType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEFilterByType()
// =================
// Returns TRUE if the operation is to be discarded because of its OpAttrs, and FALSE otherwise.

func <anchor link="func_SPEFilterByType_1">SPEFilterByType</anchor>(opattr : <a link="type_SPEOpAttr" file="shared_pseudocode.xml">SPEOpAttr</a>) =&gt; 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 == <a link="enum_SPEOpType_Branch" file="shared_pseudocode.xml">SPEOpType_Branch</a> &amp;&amp;
                                 opattr.ldst_type == <a link="enum_SPELDSTType_GCS" file="shared_pseudocode.xml">SPELDSTType_GCS</a>);
    let is_load : boolean     = (opattr.op_type IN {<a link="enum_SPEOpType_Load" file="shared_pseudocode.xml">SPEOpType_Load</a>, <a link="enum_SPEOpType_LoadAtomic" file="shared_pseudocode.xml">SPEOpType_LoadAtomic</a>} ||
                                   (is_gcs_ldst &amp;&amp; opattr.procedure_return));
    let is_store : boolean    = (opattr.op_type IN {<a link="enum_SPEOpType_Store" file="shared_pseudocode.xml">SPEOpType_Store</a>, <a link="enum_SPEOpType_LoadAtomic" file="shared_pseudocode.xml">SPEOpType_LoadAtomic</a>} ||
                                   (is_gcs_ldst &amp;&amp; opattr.branch_has_link));
    flags[B]    = (if opattr.op_type == <a link="enum_SPEOpType_Branch" file="shared_pseudocode.xml">SPEOpType_Branch</a> 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)) &amp;&amp;
                               ((flags AND mask) == ctrl_and));

    if flags[B]    == '1' then <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SAMPLE_FEED_BR); end;
    if flags[LD]   == '1' then <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SAMPLE_FEED_LD); end;
    if flags[ST]   == '1' then <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SAMPLE_FEED_ST); end;
    if flags[FP]   == '1' then <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SAMPLE_FEED_FP); end;
    if flags[SIMD] == '1' then <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(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 = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_BADPMSFCR" file="shared_pseudocode.xml">Unpredictable_BADPMSFCR</a>);
        end;
    end;
    if is_op &amp;&amp; (!IsZero(ctrl) || !IsZero(mask)) then <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SAMPLE_FEED_OP); end;

    return is_rejected_type;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEFreezeOnEvent" mylink="aarch64.debug.statisticalprofiling.SPEFreezeOnEvent" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEFreezeOnEvent()
// ==================
// Returns TRUE if PMU event counter idx should be frozen due to an SPE event, and FALSE otherwise.

func <anchor link="func_SPEFreezeOnEvent_1">SPEFreezeOnEvent</anchor>(idx : integer) =&gt; boolean
begin
    let counters : integer = NUM_PMU_COUNTERS;
    assert (idx &gt;= 0 &amp;&amp;
            (idx &lt; counters || idx == <a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a> ||
             (idx == <a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a> &amp;&amp; IsFeatureImplemented(FEAT_PMUv3_ICNTR))));

    if !IsFeatureImplemented(FEAT_SPEv1p2) || !IsFeatureImplemented(FEAT_PMUv3p7) then
        return FALSE;
    end;
    if idx == <a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a> &amp;&amp; !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 = <a link="func_SPEProfilingStopped_0" file="shared_pseudocode.xml">SPEProfilingStopped</a>();

    case <a link="func_GetPMUCounterRange_1" file="shared_pseudocode.xml">GetPMUCounterRange</a>(idx) of
        when <a link="enum_PMUCounterRange_R1" file="shared_pseudocode.xml">PMUCounterRange_R1</a> =&gt;
            return freeze_on_event &amp;&amp; stopped &amp;&amp; PMCR_EL0().FZS == '1';
        when <a link="enum_PMUCounterRange_R2" file="shared_pseudocode.xml">PMUCounterRange_R2</a> =&gt;
            return freeze_on_event &amp;&amp; stopped &amp;&amp; MDCR_EL2().HPMFZS == '1';
        otherwise =&gt;
            return FALSE;
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEGetDataSource" mylink="aarch64.debug.statisticalprofiling.SPEGetDataSource" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEGetDataSource()
// ==================
// Returns a tuple indicating the data source for an access passed to SPESampleLoadStore, and
// whether the data source is valid.

impdef func <anchor link="func_SPEGetDataSource_3">SPEGetDataSource</anchor>(is_load : boolean,
                             accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                             addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>) =&gt; (boolean, bits(16))
begin
    return (TRUE, Zeros{16});
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEGetDataSourcePayloadSize" mylink="aarch64.debug.statisticalprofiling.SPEGetDataSourcePayloadSize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEGetDataSourcePayloadSize()
// =============================
// Returns the size of the Data Source payload in bytes.

func <anchor link="func_SPEGetDataSourcePayloadSize_0">SPEGetDataSourcePayloadSize</anchor>() =&gt; integer{1..2}
begin
    return ImpDefInt(&quot;SPE Data Source packet payload size&quot;) as integer{1..2};
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEGetEventsPayloadSize" mylink="aarch64.debug.statisticalprofiling.SPEGetEventsPayloadSize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEGetEventsPayloadSize()
// =========================
// Returns the size in bytes of the Events packet payload as an integer.

func <anchor link="func_SPEGetEventsPayloadSize_0">SPEGetEventsPayloadSize</anchor>() =&gt; integer{1..4}
begin
    return ImpDefInt(&quot;SPE Events packet payload size&quot;) as integer{1..4};
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEGetRandomBoolean" mylink="aarch64.debug.statisticalprofiling.SPEGetRandomBoolean" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEGetRandomBoolean()
// =====================
// Returns a random or pseudo-random boolean value.

impdef func <anchor link="func_SPEGetRandomBoolean_0">SPEGetRandomBoolean</anchor>() =&gt; boolean
begin
    return <a link="func_SPEGetRandomInterval_0" file="shared_pseudocode.xml">SPEGetRandomInterval</a>()[0] == '1';
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEGetRandomInterval" mylink="aarch64.debug.statisticalprofiling.SPEGetRandomInterval" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEGetRandomInterval()
// ======================
// Returns a random or pseudo-random byte for resetting COUNT or ECOUNT.

impdef func <anchor link="func_SPEGetRandomInterval_0">SPEGetRandomInterval</anchor>() =&gt; bits(8)
begin
    return <a link="global__PC" file="shared_pseudocode.xml">_PC</a>[0+:8];
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEISB" mylink="aarch64.debug.statisticalprofiling.SPEISB" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEISB()
// ========
// Called by ISB instruction, correctly calls SPEBranch to save previous branches.

func <anchor link="func_SPEISB_0">SPEISB</anchor>()
begin
    let address : bits(64)           = <a link="func_PC64_0" file="shared_pseudocode.xml">PC64</a>() + 4;
    let branch_type : <a link="type_BranchType" file="shared_pseudocode.xml">BranchType</a>     = <a link="enum_BranchType_DIR" file="shared_pseudocode.xml">BranchType_DIR</a>;
    let branch_conditional : boolean = FALSE;
    let taken : boolean              = FALSE;
    let is_isb : boolean             = TRUE;

    <a link="func_SPEBranch_6" file="shared_pseudocode.xml">SPEBranch</a>{64}(address, branch_type, branch_conditional, taken, is_isb);
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEInterruptEnabled" mylink="aarch64.debug.statisticalprofiling.SPEInterruptEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEInterruptEnabled()
// =====================
// Return TRUE if the SPE interrupt request (PMBIRQ) is enabled, FALSE otherwise.

func <anchor link="func_SPEInterruptEnabled_0">SPEInterruptEnabled</anchor>() =&gt; boolean
begin
    return <a link="func_EffectivePMSCR_EL1_EE_0" file="shared_pseudocode.xml">EffectivePMSCR_EL1_EE</a>() == '00';
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPELDSTType" mylink="aarch64.debug.statisticalprofiling.SPELDSTType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPELDSTType
// ===========
// Type of a load or store operation.

type <anchor link="type_SPELDSTType">SPELDSTType</anchor> of enumeration {
    <anchor link="enum_SPELDSTType_NV2">SPELDSTType_NV2</anchor>,
    <anchor link="enum_SPELDSTType_Extended">SPELDSTType_Extended</anchor>,
    <anchor link="enum_SPELDSTType_General">SPELDSTType_General</anchor>,
    <anchor link="enum_SPELDSTType_SIMDFP">SPELDSTType_SIMDFP</anchor>,
    <anchor link="enum_SPELDSTType_SVESME">SPELDSTType_SVESME</anchor>,
    <anchor link="enum_SPELDSTType_Tags">SPELDSTType_Tags</anchor>,
    <anchor link="enum_SPELDSTType_MemCopy">SPELDSTType_MemCopy</anchor>,
    <anchor link="enum_SPELDSTType_MemSet">SPELDSTType_MemSet</anchor>,
    <anchor link="enum_SPELDSTType_GCS">SPELDSTType_GCS</anchor>,
    <anchor link="enum_SPELDSTType_GCSSS2">SPELDSTType_GCSSS2</anchor>,
    <anchor link="enum_SPELDSTType_Unspecified">SPELDSTType_Unspecified</anchor>
};</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEMultiAccessSample" mylink="aarch64.debug.statisticalprofiling.SPEMultiAccessSample" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// 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 <anchor link="func_SPEMultiAccessSample_0">SPEMultiAccessSample</anchor>() =&gt; 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.

    // Bit positions in the PMSFCR_EL1().[TYPE, TYPEm] fields.
    let LD : integer = 1;
    let ST : integer = 2;

    // Are loads allowed by filter?
    let loads_pass_filter : boolean  = PMSFCR_EL1().FT == '1' &amp;&amp; PMSFCR_EL1().TYPE[LD] == '1';
    // Are stores allowed by filter?
    let stores_pass_filter : boolean = PMSFCR_EL1().FT == '1' &amp;&amp; PMSFCR_EL1().TYPE[ST] == '1';

    var record_load : boolean;
    if loads_pass_filter &amp;&amp; !stores_pass_filter then
        // Only loads pass filter
        record_load = TRUE;
    elsif !loads_pass_filter &amp;&amp; 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 = <a link="func_SPEGetRandomBoolean_0" file="shared_pseudocode.xml">SPEGetRandomBoolean</a>();
    end;
    return record_load;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEOpAttr" mylink="aarch64.debug.statisticalprofiling.SPEOpAttr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEOpAttr
// =========
// Attributes of sampled operation filtered by SPECollectRecord().

type <anchor link="type_SPEOpAttr">SPEOpAttr</anchor> of record {
    op_type : <a link="type_SPEOpType" file="shared_pseudocode.xml">SPEOpType</a>,
    ldst_type : <a link="type_SPELDSTType" file="shared_pseudocode.xml">SPELDSTType</a>,
    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
};</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEOpType" mylink="aarch64.debug.statisticalprofiling.SPEOpType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEOpType
// =========
// Types of operation filtered by SPECollectRecord().

type <anchor link="type_SPEOpType">SPEOpType</anchor> of enumeration {
    <anchor link="enum_SPEOpType_Load">SPEOpType_Load</anchor>,        // Any memory-read operation other than atomics, compare-and-swap,
                           // and swap
    <anchor link="enum_SPEOpType_Store">SPEOpType_Store</anchor>,       // Any memory-write operation, including atomics without return
    <anchor link="enum_SPEOpType_LoadAtomic">SPEOpType_LoadAtomic</anchor>,  // Atomics with return, compare-and-swap and swap
    <anchor link="enum_SPEOpType_Branch">SPEOpType_Branch</anchor>,      // Software write to the PC
    <anchor link="enum_SPEOpType_OtherSVE">SPEOpType_OtherSVE</anchor>,    // Other SVE operation
    <anchor link="enum_SPEOpType_OtherSME">SPEOpType_OtherSME</anchor>,    // Other SME operation
    <anchor link="enum_SPEOpType_Other">SPEOpType_Other</anchor>,       // Any other class of operation
    <anchor link="enum_SPEOpType_Invalid">SPEOpType_Invalid</anchor>
};</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEProfilingStopped" mylink="aarch64.debug.statisticalprofiling.SPEProfilingStopped" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEProfilingStopped()
// =====================

readonly func <anchor link="func_SPEProfilingStopped_0">SPEProfilingStopped</anchor>() =&gt; boolean
begin
    var stopped : boolean = (PMBSR_EL1().S == '1');
    if IsFeatureImplemented(FEAT_SPE_EXC) then
        if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; MDCR_EL3().PMSEE == '1x' then
            stopped = stopped || (PMBSR_EL3().S == '1');
        end;
        if <a link="func_EffectivePMSCR_EL2_EE_0" file="shared_pseudocode.xml">EffectivePMSCR_EL2_EE</a>() == '1x' then
            stopped = stopped || (PMBSR_EL2().S == '1');
        end;
    end;
    return stopped;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEResetSampleCounter" mylink="aarch64.debug.statisticalprofiling.SPEResetSampleCounter" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEResetSampleCounter()
// =======================
// Reset PMSICR_EL1.Counter

func <anchor link="func_SPEResetSampleCounter_0">SPEResetSampleCounter</anchor>()
begin
    PMSICR_EL1().COUNT[31:8] = PMSIRR_EL1().INTERVAL;
    if PMSIRR_EL1().RND == '1' &amp;&amp; !IsFeatureImplemented(FEAT_SPE_ERnd) then
        PMSICR_EL1().COUNT[7:0] = <a link="func_SPEGetRandomInterval_0" file="shared_pseudocode.xml">SPEGetRandomInterval</a>();
    else
        PMSICR_EL1().COUNT[7:0] = Zeros{8};
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEResetSampleStorage" mylink="aarch64.debug.statisticalprofiling.SPEResetSampleStorage" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEResetSampleStorage()
// =======================
// Reset all variables inside sample storage.

func <anchor link="func_SPEResetSampleStorage_0">SPEResetSampleStorage</anchor>()
begin
    // Context values
    <a link="global_SPESampleContextEL1" file="shared_pseudocode.xml">SPESampleContextEL1</a>      = Zeros{32};
    <a link="global_SPESampleContextEL1Valid" file="shared_pseudocode.xml">SPESampleContextEL1Valid</a> = FALSE;
    <a link="global_SPESampleContextEL2" file="shared_pseudocode.xml">SPESampleContextEL2</a>      = Zeros{32};
    <a link="global_SPESampleContextEL2Valid" file="shared_pseudocode.xml">SPESampleContextEL2Valid</a> = FALSE;

    // Counter values
    for i = 0 to (<a link="global_SPEMaxCounters" file="shared_pseudocode.xml">SPEMaxCounters</a> - 1) do
        <a link="global_SPESampleCounter" file="shared_pseudocode.xml">SPESampleCounter</a>[[i]] = 0;
        <a link="global_SPESampleCounterValid" file="shared_pseudocode.xml">SPESampleCounterValid</a>[[i]] = FALSE;
        <a link="global_SPESampleCounterPending" file="shared_pseudocode.xml">SPESampleCounterPending</a>[[i]] = FALSE;
    end;

    // Address values
    for i = 0 to (<a link="global_SPEMaxAddrs" file="shared_pseudocode.xml">SPEMaxAddrs</a> - 1) do
        <a link="global_SPESampleAddressValid" file="shared_pseudocode.xml">SPESampleAddressValid</a>[[i]] = FALSE;
        <a link="global_SPESampleAddress" file="shared_pseudocode.xml">SPESampleAddress</a>[[i]] = Zeros{64};
    end;

    // Data source values
    <a link="global_SPESampleDataSource" file="shared_pseudocode.xml">SPESampleDataSource</a>      = Zeros{16};
    <a link="global_SPESampleDataSourceValid" file="shared_pseudocode.xml">SPESampleDataSourceValid</a> = FALSE;

    // Timestamp values
    <a link="global_SPESampleTimestamp" file="shared_pseudocode.xml">SPESampleTimestamp</a>      = Zeros{64};
    <a link="global_SPESampleTimestampValid" file="shared_pseudocode.xml">SPESampleTimestampValid</a> = FALSE;

    // Event values
    <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a> = Zeros{64};

    // Operation attributes
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type = <a link="enum_SPEOpType_Invalid" file="shared_pseudocode.xml">SPEOpType_Invalid</a>;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.ldst_type          = <a link="enum_SPELDSTType_Unspecified" file="shared_pseudocode.xml">SPELDSTType_Unspecified</a>;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.branch_is_direct   = FALSE;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.branch_has_link    = FALSE;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.procedure_return   = FALSE;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_conditional     = FALSE;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_floating_point  = FALSE;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_simd            = FALSE;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.cond_pass          = FALSE;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.at                 = FALSE;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_acquire_release = FALSE;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_exclusive       = FALSE;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_predicated      = FALSE;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.evl                = '000';
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_gather_scatter  = FALSE;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.addr_valid         = FALSE;
end;

var <anchor link="global_SPERecordData">SPERecordData</anchor> : array [[<a link="global_SPEMaxRecordSize" file="shared_pseudocode.xml">SPEMaxRecordSize</a>]] of bits(8);
var <anchor link="global_SPERecordSize">SPERecordSize</anchor> : integer;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPESampleAddAddressPCVirtual" mylink="aarch64.debug.statisticalprofiling.SPESampleAddAddressPCVirtual" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPESampleAddAddressPCVirtual()
// ==============================
// Save the current PC address to sample storage.

func <anchor link="func_SPESampleAddAddressPCVirtual_0">SPESampleAddAddressPCVirtual</anchor>()
begin
    var ns : bit;
    var nse : bit;
    case <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() of
        when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;
            ns = '0';
            nse = '0';
        when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt;
            ns = '1';
            nse = '0';
        when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;
            ns = '1';
            nse = '1';
        otherwise =&gt; unreachable;
    end;
    let el : bits(2) = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;

    let pc : bits(64) = ThisInstrAddr{}();
    <a link="global_SPESampleAddress" file="shared_pseudocode.xml">SPESampleAddress</a>[[<a link="global_SPEAddrPosPCVirtual" file="shared_pseudocode.xml">SPEAddrPosPCVirtual</a>]][55:0] = pc[55:0];
    <a link="global_SPESampleAddress" file="shared_pseudocode.xml">SPESampleAddress</a>[[<a link="global_SPEAddrPosPCVirtual" file="shared_pseudocode.xml">SPEAddrPosPCVirtual</a>]][63:56] = ns::el::nse::Zeros{4};
    <a link="global_SPESampleAddressValid" file="shared_pseudocode.xml">SPESampleAddressValid</a>[[<a link="global_SPEAddrPosPCVirtual" file="shared_pseudocode.xml">SPEAddrPosPCVirtual</a>]]   = TRUE;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPESampleAddContext" mylink="aarch64.debug.statisticalprofiling.SPESampleAddContext" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPESampleAddContext()
// =====================
// Save contexts to sample storage if appropriate.

func <anchor link="func_SPESampleAddContext_0">SPESampleAddContext</anchor>()
begin
    if <a link="func_CollectContextIDR1_0" file="shared_pseudocode.xml">CollectContextIDR1</a>() then
        <a link="global_SPESampleContextEL1" file="shared_pseudocode.xml">SPESampleContextEL1</a>      = CONTEXTIDR_EL1()[31:0];
        <a link="global_SPESampleContextEL1Valid" file="shared_pseudocode.xml">SPESampleContextEL1Valid</a> = TRUE;
    end;
    if <a link="func_CollectContextIDR2_0" file="shared_pseudocode.xml">CollectContextIDR2</a>() then
        <a link="global_SPESampleContextEL2" file="shared_pseudocode.xml">SPESampleContextEL2</a>      = CONTEXTIDR_EL2()[31:0];
        <a link="global_SPESampleContextEL2Valid" file="shared_pseudocode.xml">SPESampleContextEL2Valid</a> = TRUE;
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPESampleAddTimeStamp" mylink="aarch64.debug.statisticalprofiling.SPESampleAddTimeStamp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPESampleAddTimeStamp()
// =======================
// Save the appropriate type of timestamp to sample storage.

func <anchor link="func_SPESampleAddTimeStamp_0">SPESampleAddTimeStamp</anchor>()
begin
    let timestamp : <a link="type_TimeStamp" file="shared_pseudocode.xml">TimeStamp</a> = <a link="func_CollectTimeStamp_0" file="shared_pseudocode.xml">CollectTimeStamp</a>();
    case timestamp of
        when <a link="enum_TimeStamp_None" file="shared_pseudocode.xml">TimeStamp_None</a> =&gt;
            <a link="global_SPESampleTimestampValid" file="shared_pseudocode.xml">SPESampleTimestampValid</a> = FALSE;
        otherwise =&gt;
            <a link="global_SPESampleTimestampValid" file="shared_pseudocode.xml">SPESampleTimestampValid</a> = TRUE;
            <a link="global_SPESampleTimestamp" file="shared_pseudocode.xml">SPESampleTimestamp</a> = <a link="func_GetTimestamp_1" file="shared_pseudocode.xml">GetTimestamp</a>(timestamp);
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPESampleCollision" mylink="aarch64.debug.statisticalprofiling.SPESampleCollision" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPESampleCollision()
// ====================
// Called when there is an SPE sample collision.

func <anchor link="func_SPESampleCollision_0">SPESampleCollision</anchor>()
begin
    // Sample collision with the previous sample
    <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SAMPLE_COLLISION);
    let target_el : bits(2)  = <a link="func_DefaultSPEEvent_0" file="shared_pseudocode.xml">DefaultSPEEvent</a>();
    <a link="accessor_PMBSR_EL_1" file="shared_pseudocode.xml">PMBSR_EL</a>(target_el).COLL = '1';
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPESampleExtendedLoadStore" mylink="aarch64.debug.statisticalprofiling.SPESampleExtendedLoadStore" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPESampleExtendedLoadStore()
// ============================
// Sets the subclass of the operation type packet for
// extended load/store operations.

func <anchor link="func_SPESampleExtendedLoadStore_4">SPESampleExtendedLoadStore</anchor>(ar : boolean, excl : boolean, at : boolean, is_load : boolean)
begin
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_acquire_release = ar;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_exclusive       = excl;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.ldst_type          = <a link="enum_SPELDSTType_Extended" file="shared_pseudocode.xml">SPELDSTType_Extended</a>;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.at                 = at;
    if is_load then
        if at then
            <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type = <a link="enum_SPEOpType_LoadAtomic" file="shared_pseudocode.xml">SPEOpType_LoadAtomic</a>;
        else
            <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type = <a link="enum_SPEOpType_Load" file="shared_pseudocode.xml">SPEOpType_Load</a>;
        end;
    else
        <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type = <a link="enum_SPEOpType_Store" file="shared_pseudocode.xml">SPEOpType_Store</a>;
    end;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPESampleGCSSS2" mylink="aarch64.debug.statisticalprofiling.SPESampleGCSSS2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPESampleGCSSS2()
// =================
// Sets the subclass of the operation type packet for GCSSS2 load/store operations.

func <anchor link="func_SPESampleGCSSS2_0">SPESampleGCSSS2</anchor>()
begin
    // GCSSS2 does a read and a write.
    let record_load : boolean = <a link="func_SPEMultiAccessSample_0" file="shared_pseudocode.xml">SPEMultiAccessSample</a>();
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type   = if record_load then <a link="enum_SPEOpType_Load" file="shared_pseudocode.xml">SPEOpType_Load</a> else <a link="enum_SPEOpType_Store" file="shared_pseudocode.xml">SPEOpType_Store</a>;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.ldst_type = <a link="enum_SPELDSTType_GCSSS2" file="shared_pseudocode.xml">SPELDSTType_GCSSS2</a>;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPESampleGeneralPurposeLoadStore" mylink="aarch64.debug.statisticalprofiling.SPESampleGeneralPurposeLoadStore" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPESampleGeneralPurposeLoadStore()
// ==================================
// Sets the subclass of the operation type packet for general
// purpose load/store operations.

func <anchor link="func_SPESampleGeneralPurposeLoadStore_1">SPESampleGeneralPurposeLoadStore</anchor>(is_load : boolean)
begin
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.ldst_type = <a link="enum_SPELDSTType_General" file="shared_pseudocode.xml">SPELDSTType_General</a>;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type = if is_load then <a link="enum_SPEOpType_Load" file="shared_pseudocode.xml">SPEOpType_Load</a> else <a link="enum_SPEOpType_Store" file="shared_pseudocode.xml">SPEOpType_Store</a>;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPESampleLoadStore" mylink="aarch64.debug.statisticalprofiling.SPESampleLoadStore" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// 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 <anchor link="func_SPESampleLoadStore_3">SPESampleLoadStore</anchor>(is_load : boolean, accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                        addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>)
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 {<a link="enum_AccessType_SPE" file="shared_pseudocode.xml">AccessType_SPE</a>,
                           <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a>,
                           <a link="enum_AccessType_TRBE" file="shared_pseudocode.xml">AccessType_TRBE</a>,
                           <a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>,
                           <a link="enum_AccessType_TTW" file="shared_pseudocode.xml">AccessType_TTW</a>,
                           <a link="enum_AccessType_AT" file="shared_pseudocode.xml">AccessType_AT</a>} 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 (<a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.ldst_type IN
          {<a link="enum_SPELDSTType_MemCopy" file="shared_pseudocode.xml">SPELDSTType_MemCopy</a>, <a link="enum_SPELDSTType_MemSet" file="shared_pseudocode.xml">SPELDSTType_MemSet</a>, <a link="enum_SPELDSTType_GCSSS2" file="shared_pseudocode.xml">SPELDSTType_GCSSS2</a>}) 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 = <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type IN {<a link="enum_SPEOpType_Load" file="shared_pseudocode.xml">SPEOpType_Load</a>, <a link="enum_SPEOpType_LoadAtomic" file="shared_pseudocode.xml">SPEOpType_LoadAtomic</a>};

        // If no valid data has been collected, and this operation is acceptable for sampling.
        if !<a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.addr_valid &amp;&amp; (is_load == sample_load) then
            sample_access = TRUE;
        end;
    else
        if !<a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.addr_valid then
            sample_access = TRUE;
        end;
    end;

    if sample_access then
        // Data access virtual address
        <a link="func_SPESetDataVirtualAddress_1" file="shared_pseudocode.xml">SPESetDataVirtualAddress</a>(addrdesc.vaddress);

        // Data access physical address
        if <a link="func_CollectPhysicalAddress_0" file="shared_pseudocode.xml">CollectPhysicalAddress</a>() then
            <a link="func_SPESetDataPhysicalAddress_2" file="shared_pseudocode.xml">SPESetDataPhysicalAddress</a>(addrdesc, accdesc);
        end;

        <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.addr_valid = TRUE;
    end;

    if <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type == <a link="enum_SPEOpType_Invalid" file="shared_pseudocode.xml">SPEOpType_Invalid</a> then
        // Set as unspecified load/store by default, instructions will overwrite this if it does not
        // apply to them.
        <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type = if is_load then <a link="enum_SPEOpType_Load" file="shared_pseudocode.xml">SPEOpType_Load</a> else <a link="enum_SPEOpType_Store" file="shared_pseudocode.xml">SPEOpType_Store</a>;

        if accdesc.acctype == <a link="enum_AccessType_NV2" file="shared_pseudocode.xml">AccessType_NV2</a> then
            // NV2 register load/store
            <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.ldst_type = <a link="enum_SPELDSTType_NV2" file="shared_pseudocode.xml">SPELDSTType_NV2</a>;
        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 == <a link="enum_AccessType_GCS" file="shared_pseudocode.xml">AccessType_GCS</a> then
        <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.ldst_type = <a link="enum_SPELDSTType_GCS" file="shared_pseudocode.xml">SPELDSTType_GCS</a>;
        // If the GCS access is from a BL or RET, this will get overwritten to SPEOpType_Branch.
        <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type = if is_load then <a link="enum_SPEOpType_Load" file="shared_pseudocode.xml">SPEOpType_Load</a> else <a link="enum_SPEOpType_Store" file="shared_pseudocode.xml">SPEOpType_Store</a>;
    end;
    (<a link="global_SPESampleDataSourceValid" file="shared_pseudocode.xml">SPESampleDataSourceValid</a>, <a link="global_SPESampleDataSource" file="shared_pseudocode.xml">SPESampleDataSource</a>) = <a link="func_SPEGetDataSource_3" file="shared_pseudocode.xml">SPEGetDataSource</a>(is_load, accdesc, addrdesc);
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPESampleMemCopy" mylink="aarch64.debug.statisticalprofiling.SPESampleMemCopy" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPESampleMemCopy()
// ==================
// Sets the subclass of the operation type packet for Memory Copy load/store
// operations.

func <anchor link="func_SPESampleMemCopy_0">SPESampleMemCopy</anchor>()
begin
    // MemCopy does a read and a write.
    let record_load : boolean = <a link="func_SPEMultiAccessSample_0" file="shared_pseudocode.xml">SPEMultiAccessSample</a>();
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type   = if record_load then <a link="enum_SPEOpType_Load" file="shared_pseudocode.xml">SPEOpType_Load</a> else <a link="enum_SPEOpType_Store" file="shared_pseudocode.xml">SPEOpType_Store</a>;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.ldst_type = <a link="enum_SPELDSTType_MemCopy" file="shared_pseudocode.xml">SPELDSTType_MemCopy</a>;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPESampleMemSet" mylink="aarch64.debug.statisticalprofiling.SPESampleMemSet" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPESampleMemSet()
// =================
// Callback used by memory set instructions to pass data back to the SPU.

func <anchor link="func_SPESampleMemSet_0">SPESampleMemSet</anchor>()
begin
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type   = <a link="enum_SPEOpType_Store" file="shared_pseudocode.xml">SPEOpType_Store</a>;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.ldst_type = <a link="enum_SPELDSTType_MemSet" file="shared_pseudocode.xml">SPELDSTType_MemSet</a>;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPESampleOnSharedResource" mylink="aarch64.debug.statisticalprofiling.SPESampleOnSharedResource" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// 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 <anchor link="func_SPESampleOnSharedResource_0">SPESampleOnSharedResource</anchor>()
begin
    <a link="global_SPESampleEvents" file="shared_pseudocode.xml">SPESampleEvents</a>[25] = '1';
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPESampleOpOther" mylink="aarch64.debug.statisticalprofiling.SPESampleOpOther" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPESampleOpOther()
// ==================
// Add other operation to sample storage.

func <anchor link="func_SPESampleOpOther_4">SPESampleOpOther</anchor>(conditional : boolean, cond_pass : boolean,
                      is_fp : boolean, is_simd : boolean)
begin
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_simd = is_simd;
    <a link="func_SPESampleOpOther_3" file="shared_pseudocode.xml">SPESampleOpOther</a>(conditional, cond_pass, is_fp);
end;

func <anchor link="func_SPESampleOpOther_3">SPESampleOpOther</anchor>(conditional : boolean, cond_pass : boolean, is_fp : boolean)
begin
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.cond_pass = cond_pass;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_floating_point = is_fp;
    <a link="func_SPESampleOpOther_1" file="shared_pseudocode.xml">SPESampleOpOther</a>(conditional);
end;

func <anchor link="func_SPESampleOpOther_1">SPESampleOpOther</anchor>(conditional : boolean)
begin
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_conditional = conditional;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type = <a link="enum_SPEOpType_Other" file="shared_pseudocode.xml">SPEOpType_Other</a>;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPESampleOpSMEArrayOther" mylink="aarch64.debug.statisticalprofiling.SPESampleOpSMEArrayOther" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPESampleOpSMEArrayOther()
// ==========================
// Sets the subclass of the operation type packet to Other, SME array.

func <anchor link="func_SPESampleOpSMEArrayOther_2">SPESampleOpSMEArrayOther</anchor>(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.

    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_floating_point = floating_point;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.ets               = <a link="func_SPEEncodeETS_1" file="shared_pseudocode.xml">SPEEncodeETS</a>(size);
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type           = <a link="enum_SPEOpType_OtherSME" file="shared_pseudocode.xml">SPEOpType_OtherSME</a>;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_simd           = TRUE;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPESampleOpSVEOther" mylink="aarch64.debug.statisticalprofiling.SPESampleOpSVEOther" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPESampleOpSVEOther()
// =====================
// Callback used by SVE, Other operations to pass data back to the SPU.

func <anchor link="func_SPESampleOpSVEOther_3">SPESampleOpSVEOther</anchor>(vl : integer, predicated : boolean, floating_point : boolean)
begin
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_predicated     = predicated;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_floating_point = floating_point;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.evl               = <a link="func_SPEEncodeEVL_1" file="shared_pseudocode.xml">SPEEncodeEVL</a>(vl);
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type           = <a link="enum_SPEOpType_OtherSVE" file="shared_pseudocode.xml">SPEOpType_OtherSVE</a>;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPESampleOpSVESMELoadStore" mylink="aarch64.debug.statisticalprofiling.SPESampleOpSVESMELoadStore" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPESampleOpSVESMELoadStore()
// ============================
// Callback used by SVE or SME loads and stores to pass data to SPE.

func <anchor link="func_SPESampleOpSVESMELoadStore_4">SPESampleOpSVESMELoadStore</anchor>(is_gather_scatter : boolean, vl : integer, predicated : boolean,
                                is_load : boolean)
begin
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_gather_scatter = is_gather_scatter;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_predicated     = predicated;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.evl               = <a link="func_SPEEncodeEVL_1" file="shared_pseudocode.xml">SPEEncodeEVL</a>(vl);
    assert <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.evl != '111';
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type = if is_load then <a link="enum_SPEOpType_Load" file="shared_pseudocode.xml">SPEOpType_Load</a> else <a link="enum_SPEOpType_Store" file="shared_pseudocode.xml">SPEOpType_Store</a>;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.ldst_type = <a link="enum_SPELDSTType_SVESME" file="shared_pseudocode.xml">SPELDSTType_SVESME</a>;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPESampleSIMDFPLoadStore" mylink="aarch64.debug.statisticalprofiling.SPESampleSIMDFPLoadStore" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPESampleSIMDFPLoadStore()
// ==========================
// Sets the subclass of the operation type packet for SIMD &amp; FP
// load store operations.

func <anchor link="func_SPESampleSIMDFPLoadStore_2">SPESampleSIMDFPLoadStore</anchor>(is_load : boolean, scalar : boolean)
begin
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.ldst_type = <a link="enum_SPELDSTType_SIMDFP" file="shared_pseudocode.xml">SPELDSTType_SIMDFP</a>;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.op_type   = if is_load then <a link="enum_SPEOpType_Load" file="shared_pseudocode.xml">SPEOpType_Load</a> else <a link="enum_SPEOpType_Store" file="shared_pseudocode.xml">SPEOpType_Store</a>;
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_simd   = !scalar;
    // Scalar operations in SIMD&amp;FP are treated as floating point.
    <a link="global_SPESampleOpAttr" file="shared_pseudocode.xml">SPESampleOpAttr</a>.is_floating_point = scalar;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPESetDataPhysicalAddress" mylink="aarch64.debug.statisticalprofiling.SPESetDataPhysicalAddress" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPESetDataPhysicalAddress()
// ===========================
// Called from SampleLoadStore() to save data physical packet.

func <anchor link="func_SPESetDataPhysicalAddress_2">SPESetDataPhysicalAddress</anchor>(addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>)
begin
    var ns : bit;
    var nse : bit;
    var ch : bit;
    var lat : bits(4);
    case addrdesc.paddress.paspace of
        when <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> =&gt;
            ns = '0';
            nse = '0';
        when <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> =&gt;
            ns = '1';
            nse = '0';
        when <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a> =&gt;
            ns  = '1';
            nse = '1';
        otherwise =&gt; unreachable;
    end;

    if IsFeatureImplemented(FEAT_MTE2) then
        if accdesc.tagchecked then
            ch = '1';
            lat = <a link="func_AArch64_LogicalAddressTag_1" file="shared_pseudocode.xml">AArch64_LogicalAddressTag</a>(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(&quot;SPE PAT for tag unchecked access zero&quot;);
            if !zero_unchecked then
                lat = <a link="func_AArch64_LogicalAddressTag_1" file="shared_pseudocode.xml">AArch64_LogicalAddressTag</a>(addrdesc.vaddress);
            else
                lat = Zeros{4};
            end;
        end;
    else
        ch = '0';
        lat = '0000';
    end;

    let paddr : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>) = addrdesc.paddress.address;
    <a link="global_SPESampleAddress" file="shared_pseudocode.xml">SPESampleAddress</a>[[<a link="global_SPEAddrPosDataPhysical" file="shared_pseudocode.xml">SPEAddrPosDataPhysical</a>]][55:0] = ZeroExtend{56}(paddr);
    <a link="global_SPESampleAddress" file="shared_pseudocode.xml">SPESampleAddress</a>[[<a link="global_SPEAddrPosDataPhysical" file="shared_pseudocode.xml">SPEAddrPosDataPhysical</a>]][63:56] = ns::ch::'0'::nse::lat;
    <a link="global_SPESampleAddressValid" file="shared_pseudocode.xml">SPESampleAddressValid</a>[[<a link="global_SPEAddrPosDataPhysical" file="shared_pseudocode.xml">SPEAddrPosDataPhysical</a>]] = TRUE;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPESetDataVirtualAddress" mylink="aarch64.debug.statisticalprofiling.SPESetDataVirtualAddress" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// 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 <anchor link="func_SPESetDataVirtualAddress_1">SPESetDataVirtualAddress</anchor>(vaddress : bits(64))
begin
    var tbi : bit;
    tbi = <a link="func_EffectiveTBI_3" file="shared_pseudocode.xml">EffectiveTBI</a>(vaddress, FALSE, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    var non_tbi_is_zeros : boolean;
    non_tbi_is_zeros = ImpDefBool(&quot;SPE non-tbi tag is zero&quot;);
    if tbi == '1' || !non_tbi_is_zeros then
        <a link="global_SPESampleAddress" file="shared_pseudocode.xml">SPESampleAddress</a>[[<a link="global_SPEAddrPosDataVirtual" file="shared_pseudocode.xml">SPEAddrPosDataVirtual</a>]][63:0]  = vaddress[63:0];
    else
        <a link="global_SPESampleAddress" file="shared_pseudocode.xml">SPESampleAddress</a>[[<a link="global_SPEAddrPosDataVirtual" file="shared_pseudocode.xml">SPEAddrPosDataVirtual</a>]][55:0]  = vaddress[55:0];
        <a link="global_SPESampleAddress" file="shared_pseudocode.xml">SPESampleAddress</a>[[<a link="global_SPEAddrPosDataVirtual" file="shared_pseudocode.xml">SPEAddrPosDataVirtual</a>]][63:56] = Zeros{8};
    end;
    <a link="global_SPESampleAddressValid" file="shared_pseudocode.xml">SPESampleAddressValid</a>[[<a link="global_SPEAddrPosDataVirtual" file="shared_pseudocode.xml">SPEAddrPosDataVirtual</a>]]       = TRUE;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEStartCounter" mylink="aarch64.debug.statisticalprofiling.SPEStartCounter" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEStartCounter()
// =================
// Enables incrementing of the counter at the passed index when SPECycle is called.

func <anchor link="func_SPEStartCounter_1">SPEStartCounter</anchor>(counter_index : integer)
begin
    assert counter_index &lt; <a link="global_SPEMaxCounters" file="shared_pseudocode.xml">SPEMaxCounters</a>;
    <a link="global_SPESampleCounterPending" file="shared_pseudocode.xml">SPESampleCounterPending</a>[[counter_index]] = TRUE;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEStartSample" mylink="aarch64.debug.statisticalprofiling.SPEStartSample" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEStartSample()
// ================
// Called to start the sampling process. Returns TRUE if a new sample is to be collected, and
// FALSE otherwise.

func <anchor link="func_SPEStartSample_0">SPEStartSample</anchor>() =&gt; boolean
begin
    if !<a link="func_StatisticalProfilingEnabled_0" file="shared_pseudocode.xml">StatisticalProfilingEnabled</a>() then
        return FALSE;
    end;
    <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SAMPLE_POP);
    if !<a link="func_SPEToCollectSample_0" file="shared_pseudocode.xml">SPEToCollectSample</a>() then
        return FALSE;
    end;

    if <a link="global_SPESampleInFlight" file="shared_pseudocode.xml">SPESampleInFlight</a> then
        <a link="func_SPESampleCollision_0" file="shared_pseudocode.xml">SPESampleCollision</a>();
        return FALSE;
    end;

    <a link="global_SPESampleInFlight" file="shared_pseudocode.xml">SPESampleInFlight</a> = TRUE;

    <a link="func_SPEStartCounter_1" file="shared_pseudocode.xml">SPEStartCounter</a>(<a link="global_SPECounterPosTotalLatency" file="shared_pseudocode.xml">SPECounterPosTotalLatency</a>);
    <a link="func_SPEStartCounter_1" file="shared_pseudocode.xml">SPEStartCounter</a>(<a link="global_SPECounterPosIssueLatency" file="shared_pseudocode.xml">SPECounterPosIssueLatency</a>);
    <a link="func_SPESampleAddAddressPCVirtual_0" file="shared_pseudocode.xml">SPESampleAddAddressPCVirtual</a>();

    // 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
    <a link="func_SPESampleOpOther_1" file="shared_pseudocode.xml">SPESampleOpOther</a>(FALSE);

    <a link="func_SPESampleAddContext_0" file="shared_pseudocode.xml">SPESampleAddContext</a>();

    // Timestamp may be collected at any point in the sampling operation.
    // Collecting prior to execution is one possible choice.
    // This choice is IMPLEMENTATION DEFINED.
    <a link="func_SPESampleAddTimeStamp_0" file="shared_pseudocode.xml">SPESampleAddTimeStamp</a>();

    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEStopCounter" mylink="aarch64.debug.statisticalprofiling.SPEStopCounter" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEStopCounter()
// ================
// Disables incrementing of the counter at the passed index when SPECycle is called.

func <anchor link="func_SPEStopCounter_1">SPEStopCounter</anchor>(counter_index : integer)
begin
    <a link="global_SPESampleCounterValid" file="shared_pseudocode.xml">SPESampleCounterValid</a>[[counter_index]] = TRUE;
    <a link="global_SPESampleCounterPending" file="shared_pseudocode.xml">SPESampleCounterPending</a>[[counter_index]] = FALSE;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEToCollectSample" mylink="aarch64.debug.statisticalprofiling.SPEToCollectSample" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEToCollectSample()
// ====================
// Returns TRUE if the instruction which is about the executed should be sampled, and FALSE
// otherwise.

func <anchor link="func_SPEToCollectSample_0">SPEToCollectSample</anchor>() =&gt; boolean
begin
    if IsZero(PMSICR_EL1().COUNT) then
        <a link="func_SPEResetSampleCounter_0" file="shared_pseudocode.xml">SPEResetSampleCounter</a>();
    else
        PMSICR_EL1().COUNT = PMSICR_EL1().COUNT - 1;
        if IsZero(PMSICR_EL1().COUNT) then
            if PMSIRR_EL1().RND == '1' &amp;&amp; IsFeatureImplemented(FEAT_SPE_ERnd) then
                PMSICR_EL1().ECOUNT = <a link="func_SPEGetRandomInterval_0" file="shared_pseudocode.xml">SPEGetRandomInterval</a>();
                return IsZero(PMSICR_EL1().ECOUNT);
            else
                return TRUE;
            end;
        end;
    end;
    if (PMSIRR_EL1().RND == '1' &amp;&amp; IsFeatureImplemented(FEAT_SPE_ERnd) &amp;&amp;
          !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;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/SPEWriteToBuffer" mylink="aarch64.debug.statisticalprofiling.SPEWriteToBuffer" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPEWriteToBuffer()
// ==================
// Write the active record to the Profiling Buffer.

func <anchor link="func_SPEWriteToBuffer_0">SPEWriteToBuffer</anchor>()
begin
    assert <a link="func_ProfilingBufferEnabled_0" file="shared_pseudocode.xml">ProfilingBufferEnabled</a>() &amp;&amp; !<a link="func_SPEProfilingStopped_0" file="shared_pseudocode.xml">SPEProfilingStopped</a>();

    // Check alignment
    let align : integer{} = UInt(PMBIDR_EL1().Align);
    let aligned : boolean = IsAlignedP2(PMBPTR_EL1().PTR, align);

    let ttw_abort_as_fault : boolean = (ImpDefBool(
                                           &quot;Report SPE ExtAbort on TTW as fault&quot;));

    var owning_ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>;
    var owning_el : bits(2);
    (owning_ss, owning_el) = <a link="func_ProfilingBufferOwner_0" file="shared_pseudocode.xml">ProfilingBufferOwner</a>();
    let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescSPE_2" file="shared_pseudocode.xml">CreateAccDescSPE</a>(owning_ss, owning_el);

    let start_vaddr : bits(64) = PMBPTR_EL1();
    for i = 0 to <a link="global_SPERecordSize" file="shared_pseudocode.xml">SPERecordSize</a> - 1 do
        // If a previous write did not cause an issue
        if !<a link="func_SPEProfilingStopped_0" file="shared_pseudocode.xml">SPEProfilingStopped</a>() then
            let address : bits(64) = PMBPTR_EL1();
            var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
            var addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
            (memstatus, addrdesc) = <a link="func_DebugMemWrite_4" file="shared_pseudocode.xml">DebugMemWrite</a>(address, accdesc, aligned,
                                                  <a link="global_SPERecordData" file="shared_pseudocode.xml">SPERecordData</a>[[i]]);

            let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = addrdesc.fault;
            let ttw_abort : boolean = fault.statuscode IN {<a link="enum_Fault_SyncExternalOnWalk" file="shared_pseudocode.xml">Fault_SyncExternalOnWalk</a>,
                                                           <a link="enum_Fault_SyncParityOnWalk" file="shared_pseudocode.xml">Fault_SyncParityOnWalk</a>};

            if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(fault.statuscode) &amp;&amp; (!ttw_abort || ttw_abort_as_fault) then
                <a link="func_DebugWriteFault_2" file="shared_pseudocode.xml">DebugWriteFault</a>(address, fault);
            elsif <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) || (ttw_abort &amp;&amp; !ttw_abort_as_fault) then
                <a link="func_DebugWriteExternalAbort_3" file="shared_pseudocode.xml">DebugWriteExternalAbort</a>(memstatus, addrdesc, start_vaddr);
            end;

            // Move pointer if no Buffer Management Event has been caused.
            if !<a link="func_SPEProfilingStopped_0" file="shared_pseudocode.xml">SPEProfilingStopped</a>() then
                PMBPTR_EL1() = PMBPTR_EL1() + 1;
            end;
        end;
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/StatisticalProfilingEnabled" mylink="aarch64.debug.statisticalprofiling.StatisticalProfilingEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// StatisticalProfilingEnabled()
// =============================
// Return TRUE if Statistical Profiling is Enabled in the current EL, FALSE otherwise.

func <anchor link="func_StatisticalProfilingEnabled_0">StatisticalProfilingEnabled</anchor>() =&gt; boolean
begin
    return <a link="func_StatisticalProfilingEnabled_1" file="shared_pseudocode.xml">StatisticalProfilingEnabled</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
end;

// StatisticalProfilingEnabled()
// =============================
// Return TRUE if Statistical Profiling is Enabled in the specified EL, FALSE otherwise.

func <anchor link="func_StatisticalProfilingEnabled_1">StatisticalProfilingEnabled</anchor>(el : bits(2)) =&gt; boolean
begin
    if (!IsFeatureImplemented(FEAT_SPE) || <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() ||
          !<a link="func_ProfilingBufferEnabled_0" file="shared_pseudocode.xml">ProfilingBufferEnabled</a>() || <a link="func_SPEProfilingStopped_0" file="shared_pseudocode.xml">SPEProfilingStopped</a>() || <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>()) then
        return FALSE;
    end;

    let tge_set : boolean = <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1';
    let (owning_ss, owning_el) : (<a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, bits(2)) = <a link="func_ProfilingBufferOwner_0" file="shared_pseudocode.xml">ProfilingBufferOwner</a>();
    if (UInt(owning_el) &lt;  UInt(el) || (tge_set &amp;&amp; owning_el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) ||
          owning_ss != <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(el))  then
        return FALSE;
    end;
    var spe_bit : bit;
    case el of
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;  unreachable;
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;  spe_bit = PMSCR_EL2().E2SPE;
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;  spe_bit = PMSCR_EL1().E1SPE;
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;  spe_bit = (if tge_set then PMSCR_EL2().E0HSPE else PMSCR_EL1().E0SPE);
    end;

    return spe_bit == '1';
end;</pstext></ps>
    <ps name="aarch64/debug/statisticalprofiling/TimeStamp" mylink="aarch64.debug.statisticalprofiling.TimeStamp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TimeStamp
// =========

type <anchor link="type_TimeStamp">TimeStamp</anchor> of enumeration {
    <anchor link="enum_TimeStamp_None">TimeStamp_None</anchor>,              // No timestamp
    <anchor link="enum_TimeStamp_CoreSight">TimeStamp_CoreSight</anchor>,         // CoreSight time (IMPLEMENTATION DEFINED)
    <anchor link="enum_TimeStamp_Physical">TimeStamp_Physical</anchor>,          // Physical counter value with no offset
    <anchor link="enum_TimeStamp_OffsetPhysical">TimeStamp_OffsetPhysical</anchor>,    // Physical counter value minus CNTPOFF_EL2
    <anchor link="enum_TimeStamp_Virtual">TimeStamp_Virtual</anchor>  };        // Physical counter value minus CNTVOFF_EL2</pstext></ps>
    <ps name="aarch64/debug/takeexceptiondbg/AArch64_TakeExceptionInDebugState" mylink="aarch64.debug.takeexceptiondbg.AArch64_TakeExceptionInDebugState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TakeExceptionInDebugState()
// ===================================
// Take an exception in Debug state to an Exception level using AArch64.

noreturn func AArch64_TakeExceptionInDebugState(target_el : bits(2), exception_in : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>)
begin
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(target_el) &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(target_el) &amp;&amp; UInt(target_el) &gt;= UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    assert target_el != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> || EDSCR().SDD == '0';
    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = exception_in;

    if !IsFeatureImplemented(FEAT_ExS) || <a link="accessor_SCTLR_EL_1" file="shared_pseudocode.xml">SCTLR_EL</a>(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 = <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>();
    if from_32 then <a link="func_AArch64_MaybeZeroRegisterUppers_0" file="shared_pseudocode.xml">AArch64_MaybeZeroRegisterUppers</a>(); end;
    if from_32 &amp;&amp; IsFeatureImplemented(FEAT_SME) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM == '1' then
        <a link="func_ResetSVEState_0" file="shared_pseudocode.xml">ResetSVEState</a>();
    else
        <a link="func_MaybeZeroSVEUppers_1" file="shared_pseudocode.xml">MaybeZeroSVEUppers</a>(target_el);
    end;

    <a link="func_AArch64_ReportException_2" file="shared_pseudocode.xml">AArch64_ReportException</a>(except, target_el);

    if IsFeatureImplemented(FEAT_GCS) then
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EXLOCK = '0';  // Effective value of GCSCR_ELx.EXLOCKEN is 0 in Debug state
    end;

    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL  = target_el;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.nRW = '0';
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SP  = '1';

    <a link="accessor_SPSR_ELx_0" file="shared_pseudocode.xml">SPSR_ELx</a>() = ARBITRARY : bits(64);
    <a link="accessor_ELR_ELx_0" file="shared_pseudocode.xml">ELR_ELx</a>() = 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 <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SSBS = ARBITRARY : bit; end;
    if IsFeatureImplemented(FEAT_EBEP) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PM = ARBITRARY : bit; end;
    if IsFeatureImplemented(FEAT_MTE) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.TCO = '1'; end;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL = '0';
    if IsFeatureImplemented(FEAT_UAO) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.UAO = '0'; end;
    if IsFeatureImplemented(FEAT_UINJ) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.UINJ = '0'; end;
    if IsFeatureImplemented(FEAT_PAuth_LR) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PACM = '0'; end;
    if (IsFeatureImplemented(FEAT_PAN) &amp;&amp; (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> ||
          (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> &amp;&amp; <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>))) &amp;&amp;
          <a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>().SPAN == '0') then
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN = '1';
    end;
    if from_32 then                             // Coming from AArch32
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT = '00000000';
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T = '0';                         // PSTATE.J is RES0
    end;
    if IsFeatureImplemented(FEAT_BTI) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.BTYPE = '00'; end;
    DLR_EL0() = ARBITRARY : bits(64);
    DSPSR_EL0() = ARBITRARY : bits(64);

    EDSCR().ERR = '1';
    <a link="func_UpdateEDSCRFields_0" file="shared_pseudocode.xml">UpdateEDSCRFields</a>();                        // Update EDSCR PE state flags.

    EndOfInstruction(<a link="enum_EndOfInstructionReason_Exception" file="shared_pseudocode.xml">EndOfInstructionReason_Exception</a>);
end;</pstext></ps>
    <ps name="aarch64/debug/watchpoint/AArch64_WatchpointByteMatch" mylink="aarch64.debug.watchpoint.AArch64_WatchpointByteMatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_WatchpointByteMatch()
// =============================

func <anchor link="func_AArch64_WatchpointByteMatch_2">AArch64_WatchpointByteMatch</anchor>(n : integer, vaddress : bits(64)) =&gt; boolean
begin
    let dbgtop : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>        = <a link="func_DebugAddrTop_0" file="shared_pseudocode.xml">DebugAddrTop</a>();
    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 &gt; 0 &amp;&amp; !IsOnes(DBGWCR_EL1(n).BAS) then
        byte_select_match = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_WPMASKANDBAS" file="shared_pseudocode.xml">Unpredictable_WPMASKANDBAS</a>);
    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 = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_WPBASCONTIGUOUS" file="shared_pseudocode.xml">Unpredictable_WPBASCONTIGUOUS</a>);
            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 &gt; 0 &amp;&amp; mask &lt;= 2 then
        var c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>;
        var unpred_mask : integer;
        (c, unpred_mask) = <a link="func_ConstrainUnpredictableInteger_3" file="shared_pseudocode.xml">ConstrainUnpredictableInteger</a>(3, 31, <a link="enum_Unpredictable_RESWPMASK" file="shared_pseudocode.xml">Unpredictable_RESWPMASK</a>);
        assert c IN {<a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>, <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>, <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>};
        case c of
            when <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a> =&gt; return FALSE; // Disabled
            when <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>     =&gt; mask = 0;     // No masking
            // Otherwise the value returned by ConstrainUnpredictableInteger is a not-reserved value
            otherwise                =&gt; 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 &lt; 55 &amp;&amp; !IsOnes(DBGWVR_EL1(n)[63:dbgtop]) &amp;&amp;
                                        !IsZero(DBGWVR_EL1(n)[63:dbgtop]) &amp;&amp;
                                        <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_DBGxVR_RESS" file="shared_pseudocode.xml">Unpredictable_DBGxVR_RESS</a>));
    let cmpmsb : integer{}    = if unpredictable_ress then 63 else dbgtop;
    let cmplsb : integer{}    = if mask &gt; bottom then mask else bottom;
    let bottombit : integer{} = bottom;
    var WVR_match : boolean   = (vaddress[cmpmsb:cmplsb] == DBGWVR_EL1(n)[cmpmsb:cmplsb]);
    if mask &gt; bottom then
        // If masked bits of DBGWVR_EL1(n) are not zero, the behavior is CONSTRAINED UNPREDICTABLE.
        if WVR_match &amp;&amp; !IsZero(DBGWVR_EL1(n)[cmplsb-1:bottombit]) then
            WVR_match = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_WPMASKEDBITS" file="shared_pseudocode.xml">Unpredictable_WPMASKEDBITS</a>);
        end;
    end;

    return (WVR_match &amp;&amp; byte_select_match);
end;</pstext></ps>
    <ps name="aarch64/debug/watchpoint/AArch64_WatchpointMatch" mylink="aarch64.debug.watchpoint.AArch64_WatchpointMatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_WatchpointMatch()
// =========================
// Watchpoint matching in an AArch64 translation regime.

func <anchor link="func_AArch64_WatchpointMatch_4">AArch64_WatchpointMatch</anchor>(n : integer, vaddress : bits(64), size : integer,
                             accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_WatchpointInfo" file="shared_pseudocode.xml">WatchpointInfo</a>
begin
    assert !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>());
    assert n &lt; <a link="func_NumWatchpointsImplemented_0" file="shared_pseudocode.xml">NumWatchpointsImplemented</a>();

    let enabled : boolean     = <a link="func_IsWatchpointEnabled_1" file="shared_pseudocode.xml">IsWatchpointEnabled</a>(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) &amp;&amp; DBGWCR_EL1(n).WT2 == '1';
    let state_match : boolean = <a link="func_AArch64_StateMatch_9" file="shared_pseudocode.xml">AArch64_StateMatch</a>(DBGWCR_EL1(n).SSC, ssce, DBGWCR_EL1(n).HMC,
                                                   DBGWCR_EL1(n).PAC,
                                                   linked, linked_n, isbreakpnt, <a link="func_PC64_0" file="shared_pseudocode.xml">PC64</a>(), accdesc);

    var watchptinfo : <a link="type_WatchpointInfo" file="shared_pseudocode.xml">WatchpointInfo</a>;
    var ls_match : boolean;
    case DBGWCR_EL1(n).LSC[1:0] of
        when '00' =&gt; ls_match = FALSE;
        when '01' =&gt; ls_match = accdesc.read;
        when '10' =&gt; ls_match = accdesc.write || accdesc.acctype == <a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>;
        when '11' =&gt; ls_match = TRUE;
    end;

    var value_match : boolean = FALSE;
    watchptinfo.vaddress = vaddress;
    for byte = 0 to size - 1 do
        if (!value_match &amp;&amp;
              !<a link="func_AddressInNaturallyAlignedBlock_2" file="shared_pseudocode.xml">AddressInNaturallyAlignedBlock</a>(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 || <a link="func_AArch64_WatchpointByteMatch_2" file="shared_pseudocode.xml">AArch64_WatchpointByteMatch</a>(n, vaddress + byte);
    end;

    watchptinfo.watchpt_num = n;
    watchptinfo.value_match = value_match;
    if !(state_match &amp;&amp; ls_match &amp;&amp; enabled) then
        watchptinfo.wptype = <a link="enum_WatchpointType_Inactive" file="shared_pseudocode.xml">WatchpointType_Inactive</a>;
        watchptinfo.value_match = FALSE;
    elsif mismatch then
        watchptinfo.wptype = <a link="enum_WatchpointType_AddrMismatch" file="shared_pseudocode.xml">WatchpointType_AddrMismatch</a>;
    else
        watchptinfo.wptype = <a link="enum_WatchpointType_AddrMatch" file="shared_pseudocode.xml">WatchpointType_AddrMatch</a>;
    end;
    return watchptinfo;
end;</pstext></ps>
    <ps name="aarch64/debug/watchpoint/IsWatchpointEnabled" mylink="aarch64.debug.watchpoint.IsWatchpointEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsWatchpointEnabled()
// =====================
// Returns TRUE if the effective value of DBGWCR_EL1(n).E is '1', and FALSE otherwise.

func <anchor link="func_IsWatchpointEnabled_1">IsWatchpointEnabled</anchor>(n : integer) =&gt; boolean
begin
    if (n &gt; 15 &amp;&amp;
          ((!<a link="func_HaltOnBreakpointOrWatchpoint_0" file="shared_pseudocode.xml">HaltOnBreakpointOrWatchpoint</a>() &amp;&amp; !<a link="func_SelfHostedExtendedBPWPEnabled_0" file="shared_pseudocode.xml">SelfHostedExtendedBPWPEnabled</a>()) ||
           (<a link="func_HaltOnBreakpointOrWatchpoint_0" file="shared_pseudocode.xml">HaltOnBreakpointOrWatchpoint</a>() &amp;&amp; EDSCR2().EHBWE == '0'))) then
        return FALSE;
    end;
    return DBGWCR_EL1(n).E == '1';
end;</pstext></ps>
    <ps name="aarch64/exceptions/aborts/AArch64_Abort" mylink="aarch64.exceptions.aborts.AArch64_Abort" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_Abort()
// ===============
// Abort and Debug exception handling in an AArch64 translation regime.

func <anchor link="func_AArch64_Abort_1">AArch64_Abort</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>)
begin
    if <a link="func_IsDebugException_1" file="shared_pseudocode.xml">IsDebugException</a>(fault) then
        if fault.accessdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> then
            if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fault.debugmoe == <a link="global_DebugException_VectorCatch" file="shared_pseudocode.xml">DebugException_VectorCatch</a> then
                <a link="func_AArch64_VectorCatchException_1" file="shared_pseudocode.xml">AArch64_VectorCatchException</a>(fault);
            else
                <a link="func_AArch64_BreakpointException_1" file="shared_pseudocode.xml">AArch64_BreakpointException</a>(fault);
            end;
        else
            <a link="func_AArch64_WatchpointException_1" file="shared_pseudocode.xml">AArch64_WatchpointException</a>(fault);
        end;
    elsif fault.gpcf.gpf != <a link="enum_GPCF_None" file="shared_pseudocode.xml">GPCF_None</a> &amp;&amp; <a link="func_ReportAsGPCException_1" file="shared_pseudocode.xml">ReportAsGPCException</a>(fault) then
        <a link="func_TakeGPCException_1" file="shared_pseudocode.xml">TakeGPCException</a>(fault);
    elsif fault.statuscode == <a link="enum_Fault_TagCheck" file="shared_pseudocode.xml">Fault_TagCheck</a> then
        <a link="func_AArch64_RaiseTagCheckFault_1" file="shared_pseudocode.xml">AArch64_RaiseTagCheckFault</a>(fault);
    elsif <a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) &amp;&amp; !<a link="func_IsExternalSyncAbort_1" file="shared_pseudocode.xml">IsExternalSyncAbort</a>(fault) then
        PendSErrorInterrupt(fault);
    elsif fault.accessdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> then
        <a link="func_AArch64_InstructionAbort_1" file="shared_pseudocode.xml">AArch64_InstructionAbort</a>(fault);
    else
        <a link="func_AArch64_DataAbort_1" file="shared_pseudocode.xml">AArch64_DataAbort</a>(fault);
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/aborts/AArch64_AbortSyndrome" mylink="aarch64.exceptions.aborts.AArch64_AbortSyndrome" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_AbortSyndrome()
// =======================
// Creates an exception syndrome record for Abort and Watchpoint exceptions
// from an AArch64 translation regime.
func <anchor link="func_AArch64_AbortSyndrome_3">AArch64_AbortSyndrome</anchor>(exceptype : <a link="type_Exception" file="shared_pseudocode.xml">Exception</a>, fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>,
                           target_el : bits(2)) =&gt; <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>
begin
    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(exceptype);

    except.syndrome = <a link="func_AArch64_FaultSyndrome_3" file="shared_pseudocode.xml">AArch64_FaultSyndrome</a>(exceptype, fault, target_el);
    if exceptype IN {<a link="enum_Exception_NV2Watchpoint" file="shared_pseudocode.xml">Exception_NV2Watchpoint</a>, <a link="enum_Exception_Watchpoint" file="shared_pseudocode.xml">Exception_Watchpoint</a>} then
        except.vaddress = fault.watchptinfo.vaddress;
    elsif fault.statuscode == <a link="enum_Fault_TagCheck" file="shared_pseudocode.xml">Fault_TagCheck</a> 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 <a link="func_IPAValid_1" file="shared_pseudocode.xml">IPAValid</a>(fault) then
        except.ipavalid = TRUE;
        except.NS = if fault.ipaddress.paspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> then '1' else '0';
        except.ipaddress = fault.ipaddress.address;
    else
        except.ipavalid = FALSE;
    end;

    if except.syndrome.iss[14] == '1' then
        except.pavalid  = TRUE;
        except.paddress = fault.paddress;
    else
        except.pavalid  = FALSE;
        except.paddress = ARBITRARY : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    end;

    return except;
end;</pstext></ps>
    <ps name="aarch64/exceptions/aborts/AArch64_CheckPCAlignment" mylink="aarch64.exceptions.aborts.AArch64_CheckPCAlignment" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CheckPCAlignment()
// ==========================

func <anchor link="func_AArch64_CheckPCAlignment_0">AArch64_CheckPCAlignment</anchor>()
begin
    let pc : bits(64) = ThisInstrAddr{}();

    if pc[1:0] != '00' then
        <a link="func_AArch64_PCAlignmentFault_0" file="shared_pseudocode.xml">AArch64_PCAlignmentFault</a>();
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/aborts/AArch64_DataAbort" mylink="aarch64.exceptions.aborts.AArch64_DataAbort" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_DataAbort()
// ===================

func <anchor link="func_AArch64_DataAbort_1">AArch64_DataAbort</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>)
begin
    var target_el : bits(2);
    if <a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) then
        target_el = <a link="func_SyncExternalAbortTarget_1" file="shared_pseudocode.xml">SyncExternalAbortTarget</a>(fault);
    else
        let route_to_el2 = (<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp;
                            (HCR_EL2().TGE == '1' ||
                            (IsFeatureImplemented(FEAT_RME) &amp;&amp; fault.gpcf.gpf != <a link="enum_GPCF_None" file="shared_pseudocode.xml">GPCF_None</a> &amp;&amp;
                             HCR_EL2().GPF == '1') ||
                             (IsFeatureImplemented(FEAT_NV2) &amp;&amp;
                              fault.accessdesc.acctype == <a link="enum_AccessType_NV2" file="shared_pseudocode.xml">AccessType_NV2</a>) ||
                             <a link="func_IsSecondStage_1" file="shared_pseudocode.xml">IsSecondStage</a>(fault)));

        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then
            target_el = <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
        elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || route_to_el2 then
            target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
        else
            target_el = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
        end;
    end;

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let route_to_serr : boolean = (<a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) &amp;&amp;
                                      <a link="func_AArch64_RouteToSErrorOffset_1" file="shared_pseudocode.xml">AArch64_RouteToSErrorOffset</a>(target_el));
    let vect_offset : integer = if route_to_serr then 0x180 else 0x0;

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>;
    if IsFeatureImplemented(FEAT_NV2) &amp;&amp; fault.accessdesc.acctype == <a link="enum_AccessType_NV2" file="shared_pseudocode.xml">AccessType_NV2</a> then
        except = <a link="func_AArch64_AbortSyndrome_3" file="shared_pseudocode.xml">AArch64_AbortSyndrome</a>(<a link="enum_Exception_NV2DataAbort" file="shared_pseudocode.xml">Exception_NV2DataAbort</a>, fault, target_el);
    else
        except = <a link="func_AArch64_AbortSyndrome_3" file="shared_pseudocode.xml">AArch64_AbortSyndrome</a>(<a link="enum_Exception_DataAbort" file="shared_pseudocode.xml">Exception_DataAbort</a>, fault, target_el);
    end;
    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/aborts/AArch64_EffectiveTCF" mylink="aarch64.exceptions.aborts.AArch64_EffectiveTCF" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_EffectiveTCF()
// ======================
// Indicate if a Tag Check Fault should cause a synchronous exception,
// be asynchronously accumulated, or have no effect on the PE.

func <anchor link="func_AArch64_EffectiveTCF_2">AArch64_EffectiveTCF</anchor>(el : bits(2), read : boolean) =&gt; <a link="type_TCFType" file="shared_pseudocode.xml">TCFType</a>
begin
    var tcf : bits(2);

    let regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a> = <a link="func_TranslationRegime_1" file="shared_pseudocode.xml">TranslationRegime</a>(el);

    case regime of
        when <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> =&gt;  tcf = SCTLR_EL3().TCF;
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> =&gt;  tcf = SCTLR_EL2().TCF;
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt; tcf = if el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then SCTLR_EL2().TCF0 else SCTLR_EL2().TCF;
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt; tcf = if el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then SCTLR_EL1().TCF0 else SCTLR_EL1().TCF;
        otherwise =&gt;        unreachable;
    end;

    if tcf == '11' then        // Reserved value
        if !IsFeatureImplemented(FEAT_MTE_ASYM_FAULT) then
            (-,tcf) = ConstrainUnpredictableBits{2}(<a link="enum_Unpredictable_RESTCF" file="shared_pseudocode.xml">Unpredictable_RESTCF</a>);
        end;
    end;

    case tcf of
        when '00' =&gt;   // Tag Check Faults have no effect on the PE
            return <a link="enum_TCFType_Ignore" file="shared_pseudocode.xml">TCFType_Ignore</a>;
        when '01' =&gt;   // Tag Check Faults cause a synchronous exception
            return <a link="enum_TCFType_Sync" file="shared_pseudocode.xml">TCFType_Sync</a>;
        when '10' =&gt;
            if IsFeatureImplemented(FEAT_MTE_ASYNC) then
                // If asynchronous faults are implemented,
                // Tag Check Faults are asynchronously accumulated
                return <a link="enum_TCFType_Async" file="shared_pseudocode.xml">TCFType_Async</a>;
            else
                // Otherwise, Tag Check Faults have no effect on the PE
                return <a link="enum_TCFType_Ignore" file="shared_pseudocode.xml">TCFType_Ignore</a>;
            end;
        when '11' =&gt;
            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 <a link="enum_TCFType_Sync" file="shared_pseudocode.xml">TCFType_Sync</a>;
                else
                    return <a link="enum_TCFType_Async" file="shared_pseudocode.xml">TCFType_Async</a>;
                end;
            else
                // Otherwise, Tag Check Faults have no effect on the PE
                return <a link="enum_TCFType_Ignore" file="shared_pseudocode.xml">TCFType_Ignore</a>;
            end;
        otherwise =&gt;
            unreachable;
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/aborts/AArch64_InstructionAbort" mylink="aarch64.exceptions.aborts.AArch64_InstructionAbort" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_InstructionAbort()
// ==========================

func <anchor link="func_AArch64_InstructionAbort_1">AArch64_InstructionAbort</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>)
begin
    // External aborts on instruction fetch must be taken synchronously
    if IsFeatureImplemented(FEAT_DoubleFault) then
        assert fault.statuscode != <a link="enum_Fault_AsyncExternal" file="shared_pseudocode.xml">Fault_AsyncExternal</a>;
    end;

    var target_el : bits(2);
    if <a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) then
        target_el = <a link="func_SyncExternalAbortTarget_1" file="shared_pseudocode.xml">SyncExternalAbortTarget</a>(fault);
    else
        let route_to_el2 : boolean = (<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp;
                                      (HCR_EL2().TGE == '1' ||
                                      (IsFeatureImplemented(FEAT_RME) &amp;&amp;
                                       fault.gpcf.gpf != <a link="enum_GPCF_None" file="shared_pseudocode.xml">GPCF_None</a> &amp;&amp;
                                       HCR_EL2().GPF == '1') ||
                                       <a link="func_IsSecondStage_1" file="shared_pseudocode.xml">IsSecondStage</a>(fault)));

        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then
            target_el = <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
        elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || route_to_el2 then
            target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
        else
            target_el = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
        end;
    end;

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    var vect_offset : integer;

    if <a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) &amp;&amp; <a link="func_AArch64_RouteToSErrorOffset_1" file="shared_pseudocode.xml">AArch64_RouteToSErrorOffset</a>(target_el) then
        vect_offset = 0x180;
    else
        vect_offset = 0x0;
    end;

    let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_AArch64_AbortSyndrome_3" file="shared_pseudocode.xml">AArch64_AbortSyndrome</a>(<a link="enum_Exception_InstructionAbort" file="shared_pseudocode.xml">Exception_InstructionAbort</a>, fault,
                                                            target_el);
    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/aborts/AArch64_PCAlignmentFault" mylink="aarch64.exceptions.aborts.AArch64_PCAlignmentFault" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_PCAlignmentFault()
// ==========================
// Called on unaligned program counter in AArch64 state.

func <anchor link="func_AArch64_PCAlignmentFault_0">AArch64_PCAlignmentFault</anchor>()
begin

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_PCAlignment" file="shared_pseudocode.xml">Exception_PCAlignment</a>);
    except.vaddress = <a link="func_ThisInstrAddr_1" file="shared_pseudocode.xml">ThisInstrAddr</a>{64}();
    var target_el : bits(2) = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    if UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) &gt; UInt(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        target_el = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
    elsif <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1' then
        target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    end;
    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/aborts/AArch64_RaiseTagCheckFault" mylink="aarch64.exceptions.aborts.AArch64_RaiseTagCheckFault" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_RaiseTagCheckFault()
// ============================
// Raise a Tag Check Fault exception.

func <anchor link="func_AArch64_RaiseTagCheckFault_1">AArch64_RaiseTagCheckFault</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>)
begin
    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;
    var target_el : bits(2) = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    if UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) &gt; UInt(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        target_el = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
    elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1' then
        target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    end;

    let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_AArch64_AbortSyndrome_3" file="shared_pseudocode.xml">AArch64_AbortSyndrome</a>(<a link="enum_Exception_DataAbort" file="shared_pseudocode.xml">Exception_DataAbort</a>, fault, target_el);
    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/aborts/AArch64_ReportTagCheckFault" mylink="aarch64.exceptions.aborts.AArch64_ReportTagCheckFault" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ReportTagCheckFault()
// =============================
// Records a Tag Check Fault exception into the appropriate TFSR_ELx.

func <anchor link="func_AArch64_ReportTagCheckFault_2">AArch64_ReportTagCheckFault</anchor>(el : bits(2), ttbr : bit)
begin
    case el of
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt; assert ttbr == '0'; TFSR_EL3().TF0   = '1';
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt; if ttbr == '0' then TFSR_EL2().TF0   = '1'; else TFSR_EL2().TF1   = '1'; end;
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt; if ttbr == '0' then TFSR_EL1().TF0   = '1'; else TFSR_EL1().TF1   = '1'; end;
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt; if ttbr == '0' then TFSRE0_EL1().TF0 = '1'; else TFSRE0_EL1().TF1 = '1'; end;
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/aborts/AArch64_RouteToSErrorOffset" mylink="aarch64.exceptions.aborts.AArch64_RouteToSErrorOffset" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_RouteToSErrorOffset()
// =============================
// Returns TRUE if synchronous External abort exceptions are taken to the
// appropriate SError vector offset, and FALSE otherwise.

func <anchor link="func_AArch64_RouteToSErrorOffset_1">AArch64_RouteToSErrorOffset</anchor>(target_el : bits(2)) =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_DoubleFault) then return FALSE; end;

    var ease_bit : bit;
    case target_el of
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            ease_bit = SCR_EL3().EASE;
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            if IsFeatureImplemented(FEAT_DoubleFault2) &amp;&amp; <a link="func_IsSCTLR2EL2Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL2Enabled</a>() then
                ease_bit = SCTLR2_EL2().EASE;
            else
                ease_bit = '0';
            end;
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            if IsFeatureImplemented(FEAT_DoubleFault2) &amp;&amp; <a link="func_IsSCTLR2EL1Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL1Enabled</a>() then
                ease_bit = SCTLR2_EL1().EASE;
            else
                ease_bit = '0';
            end;
    end;
    return (ease_bit == '1');
end;</pstext></ps>
    <ps name="aarch64/exceptions/aborts/AArch64_SPAlignmentFault" mylink="aarch64.exceptions.aborts.AArch64_SPAlignmentFault" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SPAlignmentFault()
// ==========================
// Called on an unaligned stack pointer in AArch64 state.

func <anchor link="func_AArch64_SPAlignmentFault_0">AArch64_SPAlignmentFault</anchor>()
begin

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;

    let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_SPAlignment" file="shared_pseudocode.xml">Exception_SPAlignment</a>);

    var target_el : bits(2) = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    if UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) &gt; UInt(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        target_el = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
    elsif <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1' then
        target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    end;
    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/aborts/BranchTargetException" mylink="aarch64.exceptions.aborts.BranchTargetException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BranchTargetException()
// =======================
// Raise branch target exception.

func <anchor link="func_AArch64_BranchTargetException_1">AArch64_BranchTargetException</anchor>(vaddress : bits(52))
begin
    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_BranchTarget" file="shared_pseudocode.xml">Exception_BranchTarget</a>);
    except.syndrome.iss[1:0]   = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.BTYPE;
    except.syndrome.iss[24:2]  = Zeros{23};         // RES0

    var target_el : bits(2) = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    if UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) &gt; UInt(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        target_el = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
    elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1' then
        target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    end;
    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/aborts/TCFType" mylink="aarch64.exceptions.aborts.TCFType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TCFType
// =======

type <anchor link="type_TCFType">TCFType</anchor> of enumeration { <anchor link="enum_TCFType_Sync">TCFType_Sync</anchor>, <anchor link="enum_TCFType_Async">TCFType_Async</anchor>, <anchor link="enum_TCFType_Ignore">TCFType_Ignore</anchor> };</pstext></ps>
    <ps name="aarch64/exceptions/aborts/TakeGPCException" mylink="aarch64.exceptions.aborts.TakeGPCException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TakeGPCException()
// ==================
// Report Granule Protection Exception faults

func <anchor link="func_TakeGPCException_1">TakeGPCException</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>)
begin
    assert IsFeatureImplemented(FEAT_RME);
    assert IsFeatureImplemented(FEAT_LSE);
    assert IsFeatureImplemented(FEAT_HAFDBS);
    assert IsFeatureImplemented(FEAT_DoubleFault);

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>;

    except.exceptype = <a link="enum_Exception_GPC" file="shared_pseudocode.xml">Exception_GPC</a>;
    except.vaddress  = ZeroExtend{64}(fault.vaddress);
    except.paddress  = fault.paddress;
    except.pavalid   = TRUE;

    if <a link="func_IPAValid_1" file="shared_pseudocode.xml">IPAValid</a>(fault) then
        except.ipavalid  = TRUE;
        except.NS        = if fault.ipaddress.paspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> then '1' else '0';
        except.ipaddress = fault.ipaddress.address;
    else
        except.ipavalid  = FALSE;
    end;

    except.syndrome.iss2[11] = if fault.hdbssf then '1' else '0';   // HDBSSF
    if fault.accessdesc.acctype == <a link="enum_AccessType_GCS" file="shared_pseudocode.xml">AccessType_GCS</a> then
        except.syndrome.iss2[8] = '1'; //GCS
    end;

    // Populate the fields grouped in ISS
    except.syndrome.iss[24:22] = Zeros{3}; // RES0
    except.syndrome.iss[21]    = if fault.gpcfs2walk then '1' else '0';  // S2PTW
    if fault.accessdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> then
        except.syndrome.iss[20] = '1';     // InD
    else
        except.syndrome.iss[20] = '0';     // InD
    end;
    except.syndrome.iss[19:14] = <a link="func_EncodeGPCSC_1" file="shared_pseudocode.xml">EncodeGPCSC</a>(fault.gpcf); // GPCSC
    if IsFeatureImplemented(FEAT_NV2) &amp;&amp; fault.accessdesc.acctype == <a link="enum_AccessType_NV2" file="shared_pseudocode.xml">AccessType_NV2</a> then
        except.syndrome.iss[13] = '1';     // VNCR
    else
        except.syndrome.iss[13] = '0';     // VNCR
    end;
    except.syndrome.iss[12:11]  = '00';     // RES0
    except.syndrome.iss[10:9]   = '00';     // RES0

    if fault.accessdesc.acctype IN {<a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>, <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>, <a link="enum_AccessType_AT" file="shared_pseudocode.xml">AccessType_AT</a>} then
        except.syndrome.iss[8] = '1'; // CM
    else
        except.syndrome.iss[8] = '0'; // CM
    end;

    except.syndrome.iss[7] = if fault.s2fs1walk then '1' else '0'; // S1PTW

    if fault.accessdesc.acctype IN {<a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>, <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>, <a link="enum_AccessType_AT" file="shared_pseudocode.xml">AccessType_AT</a>} then
        except.syndrome.iss[6] = '1';                              // WnR
    elsif fault.statuscode IN {<a link="enum_Fault_UnsupportedAtomicHWUpdate" file="shared_pseudocode.xml">Fault_UnsupportedAtomicHWUpdate</a>, <a link="enum_Fault_Exclusive" file="shared_pseudocode.xml">Fault_Exclusive</a>} then
        except.syndrome.iss[6] = ARBITRARY : bit;                  // WnR
    elsif fault.accessdesc.atomicop &amp;&amp; <a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) then
        except.syndrome.iss[6] = ARBITRARY : bit;                  // WnR
    else
        except.syndrome.iss[6] = if fault.write then '1' else '0'; // WnR
    end;

    except.syndrome.iss[5:0] = <a link="func_EncodeLDFSC_2" file="shared_pseudocode.xml">EncodeLDFSC</a>(fault.statuscode, fault.level); // xFSC

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let target_el : bits(2) = <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;

    var vect_offset : integer;
    if <a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) &amp;&amp; <a link="func_AArch64_RouteToSErrorOffset_1" file="shared_pseudocode.xml">AArch64_RouteToSErrorOffset</a>(target_el) then
        vect_offset = 0x180;
    else
        vect_offset = 0x0;
    end;

    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/async/AArch64_TakeDelegatedSErrorException" mylink="aarch64.exceptions.async.AArch64_TakeDelegatedSErrorException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TakeDelegatedSErrorException()
// ======================================

func <anchor link="func_AArch64_TakeDelegatedSErrorException_0">AArch64_TakeDelegatedSErrorException</anchor>()
begin
    assert IsFeatureImplemented(FEAT_E3DSE) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; SCR_EL3().[EnDSE,DSE] == '11';

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset = 0x180;
    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_SError" file="shared_pseudocode.xml">Exception_SError</a>);

    var target_el : bits(2);
    var dsei_masked : boolean;
    (dsei_masked, target_el)  = <a link="func_AArch64_DelegatedSErrorTarget_0" file="shared_pseudocode.xml">AArch64_DelegatedSErrorTarget</a>();
    assert !dsei_masked;
    except.syndrome.iss[24]   = VSESR_EL3().IDS;
    except.syndrome.iss[23:0] = VSESR_EL3().ISS;
    <a link="func_ClearPendingDelegatedSError_0" file="shared_pseudocode.xml">ClearPendingDelegatedSError</a>();

    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/async/AArch64_TakePhysicalFIQException" mylink="aarch64.exceptions.async.AArch64_TakePhysicalFIQException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TakePhysicalFIQException()
// ==================================

func <anchor link="func_AArch64_TakePhysicalFIQException_0">AArch64_TakePhysicalFIQException</anchor>()
begin

    let route_to_el3 : boolean = <a link="func_EffectiveSCR_EL3_FIQ_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_FIQ</a>() == '1';
    let route_to_el2 : boolean = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
                                  (HCR_EL2().TGE == '1' || HCR_EL2().FMO == '1'));
    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x100;
    let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_FIQ" file="shared_pseudocode.xml">Exception_FIQ</a>);

    if route_to_el3 then
        AArch64_TakeException(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, except, preferred_exception_return, vect_offset);
    elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || route_to_el2 then
        assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
        AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
    else
        assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
        AArch64_TakeException(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, except, preferred_exception_return, vect_offset);
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/async/AArch64_TakePhysicalIRQException" mylink="aarch64.exceptions.async.AArch64_TakePhysicalIRQException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TakePhysicalIRQException()
// ==================================
// Take an enabled physical IRQ exception.

func <anchor link="func_AArch64_TakePhysicalIRQException_0">AArch64_TakePhysicalIRQException</anchor>()
begin

    let route_to_el3 : boolean = <a link="func_EffectiveSCR_EL3_IRQ_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_IRQ</a>() == '1';
    let route_to_el2 : boolean = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
                                 (HCR_EL2().TGE == '1' || HCR_EL2().IMO == '1'));
    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x80;

    let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_IRQ" file="shared_pseudocode.xml">Exception_IRQ</a>);

    if route_to_el3 then
        AArch64_TakeException(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, except, preferred_exception_return, vect_offset);
    elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || route_to_el2 then
        assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
        AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
    else
        assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
        AArch64_TakeException(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, except, preferred_exception_return, vect_offset);
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/async/AArch64_TakePhysicalSErrorException" mylink="aarch64.exceptions.async.AArch64_TakePhysicalSErrorException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TakePhysicalSErrorException()
// =====================================

func <anchor link="func_AArch64_TakePhysicalSErrorException_1">AArch64_TakePhysicalSErrorException</anchor>(implicit_esb : boolean)
begin
    var masked : boolean;
    var target_el : bits(2);

    (masked, target_el) = <a link="func_PhysicalSErrorTarget_0" file="shared_pseudocode.xml">PhysicalSErrorTarget</a>();
    assert !masked;

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer    = 0x180;
    let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>      = <a link="func_GetPendingPhysicalSError_0" file="shared_pseudocode.xml">GetPendingPhysicalSError</a>();
    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_SError" file="shared_pseudocode.xml">Exception_SError</a>);
    let is_esb : boolean         = FALSE;
    let syndrome : bits(25)      = <a link="func_AArch64_PhysicalSErrorSyndrome_2" file="shared_pseudocode.xml">AArch64_PhysicalSErrorSyndrome</a>(is_esb, implicit_esb);

    if <a link="func_IsSErrorEdgeTriggered_0" file="shared_pseudocode.xml">IsSErrorEdgeTriggered</a>() then
        ClearPendingPhysicalSError();
    end;

    if except.syndrome.iss[14] == '1' then
        except.pavalid  = TRUE;
        except.paddress = fault.paddress;
    else
        except.pavalid  = FALSE;
        except.paddress = ARBITRARY : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    end;
    except.syndrome.iss = syndrome;
    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/async/AArch64_TakeVirtualFIQException" mylink="aarch64.exceptions.async.AArch64_TakeVirtualFIQException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TakeVirtualFIQException()
// =================================

func <anchor link="func_AArch64_TakeVirtualFIQException_0">AArch64_TakeVirtualFIQException</anchor>()
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>();
    // Virtual IRQ enabled if TGE==0 and FMO==1
    assert HCR_EL2().TGE == '0' &amp;&amp; HCR_EL2().FMO == '1';

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x100;

    let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_FIQ" file="shared_pseudocode.xml">Exception_FIQ</a>);

    AArch64_TakeException(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/async/AArch64_TakeVirtualIRQException" mylink="aarch64.exceptions.async.AArch64_TakeVirtualIRQException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TakeVirtualIRQException()
// =================================

func <anchor link="func_AArch64_TakeVirtualIRQException_0">AArch64_TakeVirtualIRQException</anchor>()
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>();
    // Virtual IRQ enabled if TGE==0 and IMO==1
    assert HCR_EL2().TGE == '0' &amp;&amp; HCR_EL2().IMO == '1';

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x80;

    let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_IRQ" file="shared_pseudocode.xml">Exception_IRQ</a>);

    AArch64_TakeException(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/async/AArch64_TakeVirtualSErrorException" mylink="aarch64.exceptions.async.AArch64_TakeVirtualSErrorException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TakeVirtualSErrorException()
// ====================================

func <anchor link="func_AArch64_TakeVirtualSErrorException_0">AArch64_TakeVirtualSErrorException</anchor>()
begin

    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>();
    // Virtual SError enabled if TGE==0 and AMO==1 or TMEA==1
    assert (HCR_EL2().TGE == '0' &amp;&amp;
            (HCR_EL2().AMO == '1' || (<a link="func_IsHCRXEL2Enabled_0" file="shared_pseudocode.xml">IsHCRXEL2Enabled</a>() &amp;&amp; HCRX_EL2().TMEA == '1')));

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer                 = 0x180;
    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>              = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_SError" file="shared_pseudocode.xml">Exception_SError</a>);

    if IsFeatureImplemented(FEAT_RAS) then
        except.syndrome.iss[24]   = VSESR_EL2().IDS;
        except.syndrome.iss[23:0] = VSESR_EL2().ISS;
    else
        let syndrome : bits(25)       = ImpDefBits{}(&quot;Virtual SError syndrome&quot;);
        let impdef_syndrome : boolean = syndrome[24] == '1';
        if impdef_syndrome then except.syndrome.iss = syndrome; end;
    end;

    <a link="func_ClearPendingVirtualSError_0" file="shared_pseudocode.xml">ClearPendingVirtualSError</a>();
    AArch64_TakeException(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/debug/AArch64_BreakpointException" mylink="aarch64.exceptions.debug.AArch64_BreakpointException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_BreakpointException()
// =============================

func <anchor link="func_AArch64_BreakpointException_1">AArch64_BreakpointException</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>)
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;

    let route_to_el2 : boolean = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
                                  (HCR_EL2().TGE == '1' || MDCR_EL2().TDE == '1'));

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    var target_el : bits(2);
    let vect_offset : integer = 0x0;
    target_el = if (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || route_to_el2) then <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> else <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;

    let vaddress : bits(64)      = ARBITRARY : bits(64);
    let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_AArch64_AbortSyndrome_3" file="shared_pseudocode.xml">AArch64_AbortSyndrome</a>(<a link="enum_Exception_Breakpoint" file="shared_pseudocode.xml">Exception_Breakpoint</a>, fault, target_el);
    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/debug/AArch64_SoftwareBreakpoint" mylink="aarch64.exceptions.debug.AArch64_SoftwareBreakpoint" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SoftwareBreakpoint()
// ============================

func <anchor link="func_AArch64_SoftwareBreakpoint_1">AArch64_SoftwareBreakpoint</anchor>(immediate : bits(16))
begin

    let route_to_el2 : boolean = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp;
                                  <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; (HCR_EL2().TGE == '1' || MDCR_EL2().TDE == '1'));

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_SoftwareBreakpoint" file="shared_pseudocode.xml">Exception_SoftwareBreakpoint</a>);
    except.syndrome.iss[15:0]    = immediate;

    if UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) &gt; UInt(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        AArch64_TakeException(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL, except, preferred_exception_return, vect_offset);
    elsif route_to_el2 then
        AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
    else
        AArch64_TakeException(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, except, preferred_exception_return, vect_offset);
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/debug/AArch64_SoftwareStepException" mylink="aarch64.exceptions.debug.AArch64_SoftwareStepException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SoftwareStepException()
// ===============================

func <anchor link="func_AArch64_SoftwareStepException_0">AArch64_SoftwareStepException</anchor>()
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;

    let route_to_el2 : boolean = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
                                  (HCR_EL2().TGE == '1' || MDCR_EL2().TDE == '1'));

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_SoftwareStep" file="shared_pseudocode.xml">Exception_SoftwareStep</a>);
    if <a link="func_SoftwareStep_DidNotStep_0" file="shared_pseudocode.xml">SoftwareStep_DidNotStep</a>() then
        except.syndrome.iss[24] = '0';
    else
        except.syndrome.iss[24] = '1';
        except.syndrome.iss[6] = if <a link="func_SoftwareStep_SteppedEX_0" file="shared_pseudocode.xml">SoftwareStep_SteppedEX</a>() then '1' else '0';
    end;
    except.syndrome.iss[5:0] = '100010';                // IFSC = Debug Exception

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || route_to_el2 then
        AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
    else
        AArch64_TakeException(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, except, preferred_exception_return, vect_offset);
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/debug/AArch64_VectorCatchException" mylink="aarch64.exceptions.debug.AArch64_VectorCatchException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_VectorCatchException()
// ==============================
// Vector Catch taken from EL0 or EL1 to EL2. This can only be called when debug exceptions are
// being routed to EL2, as Vector Catch is a legacy debug event.

func <anchor link="func_AArch64_VectorCatchException_1">AArch64_VectorCatchException</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>)
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    assert <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; (HCR_EL2().TGE == '1' || MDCR_EL2().TDE == '1');

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;

    let vaddress : bits(64)      = ARBITRARY : bits(64);
    let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_AArch64_AbortSyndrome_3" file="shared_pseudocode.xml">AArch64_AbortSyndrome</a>(<a link="enum_Exception_VectorCatch" file="shared_pseudocode.xml">Exception_VectorCatch</a>, fault, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);

    AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/debug/AArch64_WatchpointException" mylink="aarch64.exceptions.debug.AArch64_WatchpointException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_WatchpointException()
// =============================

func <anchor link="func_AArch64_WatchpointException_1">AArch64_WatchpointException</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>)
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;

    let route_to_el2 : boolean = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
                                  (HCR_EL2().TGE == '1' || MDCR_EL2().TDE == '1'));

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    var target_el : bits(2);
    let vect_offset : integer = 0x0;
    target_el = if (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || route_to_el2) then <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> else <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>;
    if IsFeatureImplemented(FEAT_NV2) &amp;&amp; fault.accessdesc.acctype == <a link="enum_AccessType_NV2" file="shared_pseudocode.xml">AccessType_NV2</a> then
        except = <a link="func_AArch64_AbortSyndrome_3" file="shared_pseudocode.xml">AArch64_AbortSyndrome</a>(<a link="enum_Exception_NV2Watchpoint" file="shared_pseudocode.xml">Exception_NV2Watchpoint</a>, fault, target_el);
    else
        except = <a link="func_AArch64_AbortSyndrome_3" file="shared_pseudocode.xml">AArch64_AbortSyndrome</a>(<a link="enum_Exception_Watchpoint" file="shared_pseudocode.xml">Exception_Watchpoint</a>, fault, target_el);
    end;
    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/exceptions/AArch64_ExceptionClass" mylink="aarch64.exceptions.exceptions.AArch64_ExceptionClass" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ExceptionClass()
// ========================
// Returns the Exception Class and Instruction Length fields to be reported in ESR

func <anchor link="func_AArch64_ExceptionClass_2">AArch64_ExceptionClass</anchor>(exceptype : <a link="type_Exception" file="shared_pseudocode.xml">Exception</a>, target_el : bits(2)) =&gt; (integer,bit)
begin

    var il_is_valid : boolean = TRUE;
    let from_32 : boolean = <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>();
    var ec : integer;
    case exceptype of
        when <a link="enum_Exception_Uncategorized" file="shared_pseudocode.xml">Exception_Uncategorized</a>         =&gt;  ec = 0x00; il_is_valid = FALSE;
        when <a link="enum_Exception_WFxTrap" file="shared_pseudocode.xml">Exception_WFxTrap</a>               =&gt;  ec = 0x01;
        when <a link="enum_Exception_CP15RTTrap" file="shared_pseudocode.xml">Exception_CP15RTTrap</a>            =&gt;  ec = 0x03; assert from_32;
        when <a link="enum_Exception_CP15RRTTrap" file="shared_pseudocode.xml">Exception_CP15RRTTrap</a>           =&gt;  ec = 0x04; assert from_32;
        when <a link="enum_Exception_CP14RTTrap" file="shared_pseudocode.xml">Exception_CP14RTTrap</a>            =&gt;  ec = 0x05; assert from_32;
        when <a link="enum_Exception_CP14DTTrap" file="shared_pseudocode.xml">Exception_CP14DTTrap</a>            =&gt;  ec = 0x06; assert from_32;
        when <a link="enum_Exception_AdvSIMDFPAccessTrap" file="shared_pseudocode.xml">Exception_AdvSIMDFPAccessTrap</a>   =&gt;  ec = 0x07;
        when <a link="enum_Exception_FPIDTrap" file="shared_pseudocode.xml">Exception_FPIDTrap</a>              =&gt;  ec = 0x08;
        when <a link="enum_Exception_PACTrap" file="shared_pseudocode.xml">Exception_PACTrap</a>               =&gt;  ec = 0x09;
        when <a link="enum_Exception_OtherTrap" file="shared_pseudocode.xml">Exception_OtherTrap</a>             =&gt;  ec = 0x0A;
        when <a link="enum_Exception_GPC" file="shared_pseudocode.xml">Exception_GPC</a>                   =&gt;  ec = 0x1E;
        when <a link="enum_Exception_CP14RRTTrap" file="shared_pseudocode.xml">Exception_CP14RRTTrap</a>           =&gt;  ec = 0x0C; assert from_32;
        when <a link="enum_Exception_BranchTarget" file="shared_pseudocode.xml">Exception_BranchTarget</a>          =&gt;  ec = 0x0D;
        when <a link="enum_Exception_IllegalState" file="shared_pseudocode.xml">Exception_IllegalState</a>          =&gt;  ec = 0x0E; il_is_valid = FALSE;
        when <a link="enum_Exception_SupervisorCall" file="shared_pseudocode.xml">Exception_SupervisorCall</a>        =&gt;  ec = if from_32 then 0x11 else 0x15;
        when <a link="enum_Exception_HypervisorCall" file="shared_pseudocode.xml">Exception_HypervisorCall</a>        =&gt;  ec = if from_32 then 0x12 else 0x16;
        when <a link="enum_Exception_MonitorCall" file="shared_pseudocode.xml">Exception_MonitorCall</a>           =&gt;  ec = if from_32 then 0x13 else 0x17;
        when <a link="enum_Exception_SystemRegisterTrap" file="shared_pseudocode.xml">Exception_SystemRegisterTrap</a>    =&gt;  ec = 0x18; assert !from_32;
        when <a link="enum_Exception_SystemRegister128Trap" file="shared_pseudocode.xml">Exception_SystemRegister128Trap</a> =&gt;  ec = 0x14; assert !from_32;
        when <a link="enum_Exception_SVEAccessTrap" file="shared_pseudocode.xml">Exception_SVEAccessTrap</a>         =&gt;  ec = 0x19; assert !from_32;
        when <a link="enum_Exception_ERetTrap" file="shared_pseudocode.xml">Exception_ERetTrap</a>              =&gt;  ec = 0x1A; assert !from_32;
        when <a link="enum_Exception_PACFail" file="shared_pseudocode.xml">Exception_PACFail</a>               =&gt;  ec = 0x1C; assert !from_32;
        when <a link="enum_Exception_SMEAccessTrap" file="shared_pseudocode.xml">Exception_SMEAccessTrap</a>         =&gt;  ec = 0x1D; assert !from_32;
        when <a link="enum_Exception_InstructionAbort" file="shared_pseudocode.xml">Exception_InstructionAbort</a>      =&gt;
            ec = if target_el == <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL then 0x21 else 0x20;
            il_is_valid = FALSE;
        when <a link="enum_Exception_PCAlignment" file="shared_pseudocode.xml">Exception_PCAlignment</a>           =&gt;  ec = 0x22; il_is_valid = FALSE;
        when <a link="enum_Exception_DataAbort" file="shared_pseudocode.xml">Exception_DataAbort</a>             =&gt;  ec = if target_el == <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL then 0x25 else 0x24;
        when <a link="enum_Exception_NV2DataAbort" file="shared_pseudocode.xml">Exception_NV2DataAbort</a>          =&gt;  ec = 0x25;
        when <a link="enum_Exception_SPAlignment" file="shared_pseudocode.xml">Exception_SPAlignment</a>           =&gt;  ec = 0x26; il_is_valid = FALSE; assert !from_32;
        when <a link="enum_Exception_MemCpyMemSet" file="shared_pseudocode.xml">Exception_MemCpyMemSet</a>          =&gt;  ec = 0x27;
        when <a link="enum_Exception_GCSFail" file="shared_pseudocode.xml">Exception_GCSFail</a>               =&gt;  ec = 0x2D; assert !from_32;
        when <a link="enum_Exception_FPTrappedException" file="shared_pseudocode.xml">Exception_FPTrappedException</a>    =&gt;  ec = if from_32 then 0x28 else 0x2C;
        when <a link="enum_Exception_SError" file="shared_pseudocode.xml">Exception_SError</a>                =&gt;  ec = 0x2F; il_is_valid = FALSE;
        when <a link="enum_Exception_Breakpoint" file="shared_pseudocode.xml">Exception_Breakpoint</a> =&gt;
            ec = if target_el == <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL then 0x31 else 0x30;
            il_is_valid = FALSE;
        when <a link="enum_Exception_SoftwareStep" file="shared_pseudocode.xml">Exception_SoftwareStep</a> =&gt;
            ec = if target_el == <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL then 0x33 else 0x32;
            il_is_valid = FALSE;
        when <a link="enum_Exception_Watchpoint" file="shared_pseudocode.xml">Exception_Watchpoint</a> =&gt;
            ec = if target_el == <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL then 0x35 else 0x34;
            il_is_valid = FALSE;
        when <a link="enum_Exception_NV2Watchpoint" file="shared_pseudocode.xml">Exception_NV2Watchpoint</a>         =&gt;  ec = 0x35; il_is_valid = FALSE;
        when <a link="enum_Exception_SoftwareBreakpoint" file="shared_pseudocode.xml">Exception_SoftwareBreakpoint</a>    =&gt;  ec = if from_32 then 0x38 else 0x3C;
        when <a link="enum_Exception_VectorCatch" file="shared_pseudocode.xml">Exception_VectorCatch</a>           =&gt;  ec = 0x3A; il_is_valid = FALSE; assert from_32;
        when <a link="enum_Exception_Profiling" file="shared_pseudocode.xml">Exception_Profiling</a>             =&gt;  ec = 0x3D;
        otherwise                            =&gt;  unreachable;
    end;

    var il : bit;
    if il_is_valid then
        il = if <a link="func_ThisInstrLength_0" file="shared_pseudocode.xml">ThisInstrLength</a>() == 32 then '1' else '0';
    else
        il = '1';
    end;
    assert from_32 || il == '1';            // AArch64 instructions always 32-bit

    return (ec,il);
end;</pstext></ps>
    <ps name="aarch64/exceptions/exceptions/AArch64_ReportException" mylink="aarch64.exceptions.exceptions.AArch64_ReportException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ReportException()
// =========================
// Report syndrome information for exception taken to AArch64 state.

func <anchor link="func_AArch64_ReportException_2">AArch64_ReportException</anchor>(except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>, target_el : bits(2))
begin

    let exceptype : <a link="type_Exception" file="shared_pseudocode.xml">Exception</a> = except.exceptype;

    var (ec,il) = <a link="func_AArch64_ExceptionClass_2" file="shared_pseudocode.xml">AArch64_ExceptionClass</a>(exceptype, target_el);
    let iss : bits(25)  = except.syndrome.iss;
    let iss2 : bits(24) = except.syndrome.iss2;

    // IL is not valid for Data Abort exceptions without valid instruction syndrome information
    if ec IN {0x24,0x25} &amp;&amp; iss[24] == '0' then
        il = '1';
    end;

    <a link="accessor_ESR_EL_1" file="shared_pseudocode.xml">ESR_EL</a>(target_el) = (Zeros{8}  ::   // [63:56]
                         iss2      ::   // [55:32]
                         ec[5:0]   ::   // [31:26]
                         il        ::   // [25]
                         iss);          // [24:0]

    if exceptype IN {
        <a link="enum_Exception_InstructionAbort" file="shared_pseudocode.xml">Exception_InstructionAbort</a>,
        <a link="enum_Exception_PCAlignment" file="shared_pseudocode.xml">Exception_PCAlignment</a>,
        <a link="enum_Exception_DataAbort" file="shared_pseudocode.xml">Exception_DataAbort</a>,
        <a link="enum_Exception_NV2DataAbort" file="shared_pseudocode.xml">Exception_NV2DataAbort</a>,
        <a link="enum_Exception_NV2Watchpoint" file="shared_pseudocode.xml">Exception_NV2Watchpoint</a>,
        <a link="enum_Exception_GPC" file="shared_pseudocode.xml">Exception_GPC</a>,
        <a link="enum_Exception_Watchpoint" file="shared_pseudocode.xml">Exception_Watchpoint</a>
    } then
        <a link="accessor_FAR_EL_1" file="shared_pseudocode.xml">FAR_EL</a>(target_el) = except.vaddress;
    else
        <a link="accessor_FAR_EL_1" file="shared_pseudocode.xml">FAR_EL</a>(target_el) = ARBITRARY : bits(64);
    end;

    if except.ipavalid then
        HPFAR_EL2()[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-9:4] = except.ipaddress[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:12];
        if <a link="func_IsSecureEL2Enabled_0" file="shared_pseudocode.xml">IsSecureEL2Enabled</a>() &amp;&amp; <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
            HPFAR_EL2().NS = except.NS;
        else
            HPFAR_EL2().NS = '0';
        end;
    elsif target_el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
        HPFAR_EL2()[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-9:4] = ARBITRARY : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-12);
    end;

    if except.pavalid then
        var faultaddr : bits(64) = ZeroExtend{}(except.paddress.address);
        if IsFeatureImplemented(FEAT_RME) then
            case except.paddress.paspace of
                when <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> =&gt;     faultaddr[63:62] = '00';
                when <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> =&gt;  faultaddr[63:62] = '10';
                when <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a> =&gt;       faultaddr[63:62] = '01';
                when <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a> =&gt;      faultaddr[63:62] = '11';
            end;
            if exceptype == <a link="enum_Exception_GPC" file="shared_pseudocode.xml">Exception_GPC</a> then
                faultaddr[11:0] = Zeros{12};
            end;
        else
            faultaddr[63] = if except.paddress.paspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> then '1' else '0';
        end;
        <a link="accessor_PFAR_EL_1" file="shared_pseudocode.xml">PFAR_EL</a>(target_el) = faultaddr;
    elsif (IsFeatureImplemented(FEAT_PFAR) ||
             (IsFeatureImplemented(FEAT_RME) &amp;&amp; target_el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>)) then
        <a link="accessor_PFAR_EL_1" file="shared_pseudocode.xml">PFAR_EL</a>(target_el) = ARBITRARY : bits(64);
    end;
    return;
end;</pstext></ps>
    <ps name="aarch64/exceptions/exceptions/AArch64_ResetControlRegisters" mylink="aarch64.exceptions.exceptions.AArch64_ResetControlRegisters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ResetControlRegisters()
// ===============================
// Resets System registers and memory-mapped control registers that have architecturally-defined
// reset values to those values.

impdef func AArch64_ResetControlRegisters(cold_reset : boolean)
begin
    return;
end;</pstext></ps>
    <ps name="aarch64/exceptions/exceptions/AArch64_TakeReset" mylink="aarch64.exceptions.exceptions.AArch64_TakeReset" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TakeReset()
// ===================
// Reset into AArch64 state

func <anchor link="func_AArch64_TakeReset_1">AArch64_TakeReset</anchor>(cold_reset : boolean)
begin
    assert <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>();

    // Enter the highest implemented Exception level in AArch64 state
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.nRW = '0';
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL = <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    else
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    end;

    // Reset System registers and other system components
    AArch64_ResetControlRegisters(cold_reset);

    // Reset all other PSTATE fields
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SP = '1';                    // Select stack pointer
    PSTATE.[D,A,I,F]  = '1111';         // All asynchronous exceptions masked
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SS = '0';                    // Clear software step bit
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.DIT = '0';                   // PSTATE.DIT is reset to 0 when resetting into AArch64
    if IsFeatureImplemented(FEAT_PAuth_LR) then
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PACM = '0';              // PAC modifier
    end;
    if IsFeatureImplemented(FEAT_SME) then
        PSTATE.[SM,ZA] = '00';          // Disable Streaming SVE mode &amp; ZA storage
        <a link="func_ResetSMEState_1" file="shared_pseudocode.xml">ResetSMEState</a>('0');
    end;
    if IsFeatureImplemented(FEAT_SSBS) then
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SSBS = ImpDefBit(&quot;PSTATE.SSBS bit at reset&quot;);
    end;
    if IsFeatureImplemented(FEAT_GCS) then
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EXLOCK = '0';            // PSTATE.EXLOCK is reset to 0 when resetting into AArch64
    end;
    if IsFeatureImplemented(FEAT_UINJ) then
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.UINJ = '0';              // PSTATE.UINJ is reset to 0 when resetting into AArch64
    end;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL = '0';                    // Clear Illegal Execution state bit

    // All registers, bits and fields not reset by the above pseudocode or by the BranchTo() call
    // below are UNKNOWN bitstrings after reset. In particular, the return information registers
    // ELR_ELx and SPSR_ELx have UNKNOWN values, so that it
    // is impossible to return from a reset in an architecturally defined way.
    <a link="func_AArch64_ResetGeneralRegisters_0" file="shared_pseudocode.xml">AArch64_ResetGeneralRegisters</a>();
    if IsFeatureImplemented(FEAT_SME) || IsFeatureImplemented(FEAT_SVE) then
        <a link="func_ResetSVERegisters_0" file="shared_pseudocode.xml">ResetSVERegisters</a>();
    else
        <a link="func_AArch64_ResetSIMDFPRegisters_0" file="shared_pseudocode.xml">AArch64_ResetSIMDFPRegisters</a>();
    end;
    <a link="func_AArch64_ResetSpecialRegisters_0" file="shared_pseudocode.xml">AArch64_ResetSpecialRegisters</a>();
    ResetExternalDebugRegisters(cold_reset);

    var rv : bits(64);                      // IMPLEMENTATION DEFINED reset vector

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        rv = RVBAR_EL3();
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        rv = RVBAR_EL2();
    else
        rv = RVBAR_EL1();
    end;

    // The reset vector must be correctly aligned
    let pamax : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>();
    assert IsZero(rv[63:pamax]) &amp;&amp; IsZero(rv[1:0]);

    let branch_conditional : boolean = FALSE;
    EDPRSR().R = '0';                 // Leaving Reset State.
    <a link="func_BranchTo_4" file="shared_pseudocode.xml">BranchTo</a>{64}(rv, <a link="enum_BranchType_RESET" file="shared_pseudocode.xml">BranchType_RESET</a>, branch_conditional);
end;</pstext></ps>
    <ps name="aarch64/exceptions/exceptions/GetESR_ELx_DFSC" mylink="aarch64.exceptions.exceptions.GetESR_ELx_DFSC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetESR_ELx_DFSC()
// =================
// Query the ESR_ELx to get the DFSC field.

func <anchor link="func_GetESR_ELx_DFSC_1">GetESR_ELx_DFSC</anchor>(el : bits(2)) =&gt;  bits(6)
begin
    let ec : bits(6) = <a link="accessor_ESR_EL_1" file="shared_pseudocode.xml">ESR_EL</a>(el).EC;
    assert ec IN {'10010x', '101111', '11010x'};

    return <a link="accessor_ESR_EL_1" file="shared_pseudocode.xml">ESR_EL</a>(el)[5:0];
end;</pstext></ps>
    <ps name="aarch64/exceptions/exceptions/GetESR_ELx_ExType" mylink="aarch64.exceptions.exceptions.GetESR_ELx_ExType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetESR_ELx_ExType()
// ===================
// Query the ESR_ELx to get the ExType field.

func <anchor link="func_GetESR_ELx_ExType_1">GetESR_ELx_ExType</anchor>(el : bits(2)) =&gt;  bits(4)
begin
    let ec : bits(6) = <a link="accessor_ESR_EL_1" file="shared_pseudocode.xml">ESR_EL</a>(el).EC;
    assert ec == '101101';

    return <a link="accessor_ESR_EL_1" file="shared_pseudocode.xml">ESR_EL</a>(el)[23:20];
end;</pstext></ps>
    <ps name="aarch64/exceptions/exceptions/GetESR_ELx_IFSC" mylink="aarch64.exceptions.exceptions.GetESR_ELx_IFSC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetESR_ELx_IFSC()
// =================
// Query the ESR_ELx to get the IFSC field.

func <anchor link="func_GetESR_ELx_IFSC_1">GetESR_ELx_IFSC</anchor>(el : bits(2)) =&gt;  bits(6)
begin
    let ec : bits(6) = <a link="accessor_ESR_EL_1" file="shared_pseudocode.xml">ESR_EL</a>(el).EC;
    assert ec IN {'1100xx', '10000x'};

    return <a link="accessor_ESR_EL_1" file="shared_pseudocode.xml">ESR_EL</a>(el)[5:0];
end;</pstext></ps>
    <ps name="aarch64/exceptions/ieeefp/AArch64_FPTrappedException" mylink="aarch64.exceptions.ieeefp.AArch64_FPTrappedException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_FPTrappedException()
// ============================

func <anchor link="func_AArch64_FPTrappedException_2">AArch64_FPTrappedException</anchor>(is_ase : boolean, accumulated_exceptions : bits(8))
begin
    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_FPTrappedException" file="shared_pseudocode.xml">Exception_FPTrappedException</a>);
    if is_ase then
        if ImpDefBool(&quot;vector instructions set TFV to 1&quot;) then
            except.syndrome.iss[23] = '1';                          // TFV
        else
            except.syndrome.iss[23] = '0';                          // TFV
        end;
    else
        except.syndrome.iss[23]     = '1';                          // TFV
    end;
    except.syndrome.iss[10:8] = ARBITRARY : bits(3);                // VECITR
    if except.syndrome.iss[23] == '1' then
        except.syndrome.iss[7,4:0] = accumulated_exceptions[7,4:0]; // IDF, IXF, UFF, OFF, DZF, IOF
    else
        except.syndrome.iss[7,4:0] = ARBITRARY : bits(6);
    end;

    let route_to_el2 : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1';

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;

    if UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) &gt; UInt(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        AArch64_TakeException(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL, except, preferred_exception_return, vect_offset);
    elsif route_to_el2 then
        AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
    else
        AArch64_TakeException(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, except, preferred_exception_return, vect_offset);
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/syscalls/AArch64_CallHypervisor" mylink="aarch64.exceptions.syscalls.AArch64_CallHypervisor" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CallHypervisor()
// ========================
// Performs a HVC call

func <anchor link="func_AArch64_CallHypervisor_1">AArch64_CallHypervisor</anchor>(immediate : bits(16))
begin
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);

    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then <a link="func_AArch32_ITAdvance_0" file="shared_pseudocode.xml">AArch32_ITAdvance</a>(); end;
    <a link="func_SSAdvance_0" file="shared_pseudocode.xml">SSAdvance</a>();
    let preferred_exception_return : bits(64) = NextInstrAddr{}();
    let vect_offset : integer{} = 0x0;

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_HypervisorCall" file="shared_pseudocode.xml">Exception_HypervisorCall</a>);
    except.syndrome.iss[15:0] = immediate;

    if IsFeatureImplemented(FEAT_PAuth_LR) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PACM = '0'; end;
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then
        AArch64_TakeException(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, except, preferred_exception_return, vect_offset);
    else
        AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/syscalls/AArch64_CallSecureMonitor" mylink="aarch64.exceptions.syscalls.AArch64_CallSecureMonitor" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CallSecureMonitor()
// ===========================

func <anchor link="func_AArch64_CallSecureMonitor_1">AArch64_CallSecureMonitor</anchor>(immediate : bits(16))
begin
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then <a link="func_AArch32_ITAdvance_0" file="shared_pseudocode.xml">AArch32_ITAdvance</a>(); end;
    <a link="func_HSAdvance_0" file="shared_pseudocode.xml">HSAdvance</a>();
    <a link="func_SSAdvance_0" file="shared_pseudocode.xml">SSAdvance</a>();
    let preferred_exception_return : bits(64) = NextInstrAddr{}();
    let vect_offset : integer{} = 0x0;

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_MonitorCall" file="shared_pseudocode.xml">Exception_MonitorCall</a>);
    except.syndrome.iss[15:0] = immediate;
    if IsFeatureImplemented(FEAT_PAuth_LR) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PACM = '0'; end;
    AArch64_TakeException(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/syscalls/AArch64_CallSupervisor" mylink="aarch64.exceptions.syscalls.AArch64_CallSupervisor" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CallSupervisor()
// ========================
// Calls the Supervisor

func <anchor link="func_AArch64_CallSupervisor_1">AArch64_CallSupervisor</anchor>(immediate : bits(16))
begin
    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then <a link="func_AArch32_ITAdvance_0" file="shared_pseudocode.xml">AArch32_ITAdvance</a>(); end;
    <a link="func_SSAdvance_0" file="shared_pseudocode.xml">SSAdvance</a>();
    let route_to_el2 : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1';

    let preferred_exception_return : bits(64) = NextInstrAddr{}();
    let vect_offset : integer{} = 0x0;

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_SupervisorCall" file="shared_pseudocode.xml">Exception_SupervisorCall</a>);
    except.syndrome.iss[15:0] = immediate;
    if IsFeatureImplemented(FEAT_PAuth_LR) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PACM = '0'; end;
    if UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) &gt; UInt(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        AArch64_TakeException(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL, except, preferred_exception_return, vect_offset);
    elsif route_to_el2 then
        AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
    else
        AArch64_TakeException(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, except, preferred_exception_return, vect_offset);
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/takeexception/AArch64_TakeException" mylink="aarch64.exceptions.takeexception.AArch64_TakeException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TakeException()
// =======================
// Take an exception to an Exception level using AArch64.

noreturn func AArch64_TakeException(target_el : bits(2), exception_in : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>,
                                    preferred_exception_return : bits(64), vect_offset_in : integer)
begin
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(target_el) &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(target_el) &amp;&amp; UInt(target_el) &gt;= UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then
        AArch64_TakeExceptionInDebugState(target_el, exception_in);
    end;
    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = exception_in;
    var sync_errors : boolean;
    var iesb_req : boolean;
    if IsFeatureImplemented(FEAT_IESB) then
        sync_errors = <a link="accessor_SCTLR_EL_1" file="shared_pseudocode.xml">SCTLR_EL</a>(target_el).IESB == '1';
        if IsFeatureImplemented(FEAT_DoubleFault) then
            sync_errors = sync_errors || (SCR_EL3().[EA,NMEA] == '11' &amp;&amp; target_el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
        end;
        if sync_errors &amp;&amp; <a link="func_InsertIESBBeforeException_1" file="shared_pseudocode.xml">InsertIESBBeforeException</a>(target_el) then
            SynchronizeErrors();
            if except.exceptype != <a link="enum_Exception_SError" file="shared_pseudocode.xml">Exception_SError</a> then
                iesb_req = FALSE;
                sync_errors = FALSE;
                TakeUnmaskedPhysicalSErrorInterrupts(iesb_req);
            end;
        end;
    else
        sync_errors = FALSE;
    end;

    var brbe_source_allowed : boolean = FALSE;
    var brbe_source_address : bits(64) = Zeros{};
    if IsFeatureImplemented(FEAT_BRBE) then
        brbe_source_allowed = <a link="func_BranchRecordAllowed_1" file="shared_pseudocode.xml">BranchRecordAllowed</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
        brbe_source_address = preferred_exception_return;
    end;

    if !IsFeatureImplemented(FEAT_ExS) || <a link="accessor_SCTLR_EL_1" file="shared_pseudocode.xml">SCTLR_EL</a>(target_el).EIS == '1' then
        // Synchronize the context, including Instruction Fetch Barrier effect
        SynchronizeContext();
    elsif !(except.exceptype == <a link="enum_Exception_SoftwareBreakpoint" file="shared_pseudocode.xml">Exception_SoftwareBreakpoint</a> ||
             (except.exceptype IN {<a link="enum_Exception_SupervisorCall" file="shared_pseudocode.xml">Exception_SupervisorCall</a>,
                                   <a link="enum_Exception_HypervisorCall" file="shared_pseudocode.xml">Exception_HypervisorCall</a>,
                                   <a link="enum_Exception_MonitorCall" file="shared_pseudocode.xml">Exception_MonitorCall</a>} &amp;&amp;
              !except.trappedsyscallinst)) then
        InstructionFetchBarrier();
    end;

    // If coming from AArch32 state, the top parts of the X() registers might be set to zero
    let from_32 : boolean = <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>();
    if from_32 then <a link="func_AArch64_MaybeZeroRegisterUppers_0" file="shared_pseudocode.xml">AArch64_MaybeZeroRegisterUppers</a>(); end;
    if from_32 &amp;&amp; IsFeatureImplemented(FEAT_SME) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM == '1' then
        <a link="func_ResetSVEState_0" file="shared_pseudocode.xml">ResetSVEState</a>();
    else
        <a link="func_MaybeZeroSVEUppers_1" file="shared_pseudocode.xml">MaybeZeroSVEUppers</a>(target_el);
    end;

    var vect_offset : integer = vect_offset_in;
    if UInt(target_el) &gt; UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) then
        var lower_32 : boolean;
        if target_el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then
            if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
                lower_32 = <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
            else
                lower_32 = <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>);
            end;
        elsif <a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; target_el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
            lower_32 = <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>);
        else
            lower_32 = <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(target_el - 1);
        end;
        vect_offset = vect_offset + (if lower_32 then 0x600 else 0x400);

    elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SP == '1' then
        vect_offset = vect_offset + 0x200;
    end;

    assert vect_offset &lt; 2048;
    let vect_base : bits(64) = <a link="accessor_VBAR_EL_1" file="shared_pseudocode.xml">VBAR_EL</a>(target_el)[63:11]::Zeros{11};
    let target_vector : bits(64) = vect_base + vect_offset;

    var spsr : bits(64) = GetPSRFromPSTATE{}(<a link="enum_AArch64_NonDebugState" file="shared_pseudocode.xml">AArch64_NonDebugState</a>);

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; target_el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        if <a link="func_EffectiveHCR_EL2_NVx_0" file="shared_pseudocode.xml">EffectiveHCR_EL2_NVx</a>() IN {'x01', '111'} then
            spsr[3:2] = '10';
        end;
    end;

    if IsFeatureImplemented(FEAT_BTI) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        var zero_btype : boolean;
        // SPSR_ELx[].BTYPE is only guaranteed valid for these exception types
        if except.exceptype IN {<a link="enum_Exception_SError" file="shared_pseudocode.xml">Exception_SError</a>, <a link="enum_Exception_IRQ" file="shared_pseudocode.xml">Exception_IRQ</a>, <a link="enum_Exception_FIQ" file="shared_pseudocode.xml">Exception_FIQ</a>,
                                <a link="enum_Exception_SoftwareStep" file="shared_pseudocode.xml">Exception_SoftwareStep</a>, <a link="enum_Exception_PCAlignment" file="shared_pseudocode.xml">Exception_PCAlignment</a>,
                                <a link="enum_Exception_InstructionAbort" file="shared_pseudocode.xml">Exception_InstructionAbort</a>, <a link="enum_Exception_Breakpoint" file="shared_pseudocode.xml">Exception_Breakpoint</a>,
                                <a link="enum_Exception_VectorCatch" file="shared_pseudocode.xml">Exception_VectorCatch</a>, <a link="enum_Exception_SoftwareBreakpoint" file="shared_pseudocode.xml">Exception_SoftwareBreakpoint</a>,
                                <a link="enum_Exception_IllegalState" file="shared_pseudocode.xml">Exception_IllegalState</a>, <a link="enum_Exception_BranchTarget" file="shared_pseudocode.xml">Exception_BranchTarget</a>} then
            zero_btype = FALSE;
        else
            zero_btype = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_ZEROBTYPE" file="shared_pseudocode.xml">Unpredictable_ZEROBTYPE</a>);
        end;
        if zero_btype then spsr[11:10] = '00'; end;
    end;

    if (IsFeatureImplemented(FEAT_NV2) &amp;&amp;
          except.exceptype == <a link="enum_Exception_NV2DataAbort" file="shared_pseudocode.xml">Exception_NV2DataAbort</a> &amp;&amp; target_el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        // External aborts are configured to be taken to EL3
        except.exceptype = <a link="enum_Exception_DataAbort" file="shared_pseudocode.xml">Exception_DataAbort</a>;
    end;
    if ! except.exceptype IN {<a link="enum_Exception_IRQ" file="shared_pseudocode.xml">Exception_IRQ</a>, <a link="enum_Exception_FIQ" file="shared_pseudocode.xml">Exception_FIQ</a>} then
        <a link="func_AArch64_ReportException_2" file="shared_pseudocode.xml">AArch64_ReportException</a>(except, target_el);
    end;

    if IsFeatureImplemented(FEAT_BRBE) then
        <a link="func_BRBEException_6" file="shared_pseudocode.xml">BRBEException</a>(except, brbe_source_allowed, brbe_source_address,
                      target_vector, target_el, except.trappedsyscallinst);
    end;

    if IsFeatureImplemented(FEAT_GCS) then
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == target_el then
            if <a link="func_GetCurrentEXLOCKEN_0" file="shared_pseudocode.xml">GetCurrentEXLOCKEN</a>() then
                <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EXLOCK = '1';
            else
                <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EXLOCK = '0';
            end;
        else
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EXLOCK = '0';
        end;
    end;

    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL = target_el;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.nRW = '0';
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SP = '1';

    <a link="accessor_SPSR_ELx_0" file="shared_pseudocode.xml">SPSR_ELx</a>() = spsr;
    <a link="accessor_ELR_ELx_0" file="shared_pseudocode.xml">ELR_ELx</a>() = preferred_exception_return;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SS = '0';
    if IsFeatureImplemented(FEAT_SSBS) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SSBS = <a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>().DSSBS; end;
    if IsFeatureImplemented(FEAT_EBEP) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PM = '1'; end;
    if IsFeatureImplemented(FEAT_NMI) then
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.ALLINT = NOT <a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>().SPINTMASK;
    end;
    PSTATE.[D,A,I,F] = '1111';
    if IsFeatureImplemented(FEAT_MTE) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.TCO = '1'; end;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL = '0';
    if IsFeatureImplemented(FEAT_UAO) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.UAO = '0'; end;
    if IsFeatureImplemented(FEAT_UINJ) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.UINJ = '0'; end;
    if IsFeatureImplemented(FEAT_PAuth_LR) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PACM = '0'; end;
    if IsFeatureImplemented(FEAT_PAN) &amp;&amp; <a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>().SPAN == '0' then
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> then
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN = '1';
        elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> &amp;&amp; <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN = '1';
        elsif (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> &amp;&amp; <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp;
                ImpDefBool(&quot;Set PAN as 1 when E2H,TGE is '10'&quot;)) then
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN = '1';
        end;
    end;
    if from_32 then                             // Coming from AArch32
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT = '00000000';
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T = '0';                         // PSTATE.J is RES0
    end;
    if IsFeatureImplemented(FEAT_BTI) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.BTYPE = '00'; end;
    let branch_conditional : boolean = FALSE;
    <a link="func_BranchTo_4" file="shared_pseudocode.xml">BranchTo</a>{64}(target_vector, <a link="enum_BranchType_EXCEPTION" file="shared_pseudocode.xml">BranchType_EXCEPTION</a>, branch_conditional);
    <a link="func_CheckExceptionCatch_1" file="shared_pseudocode.xml">CheckExceptionCatch</a>(TRUE);                  // Check for debug event on exception entry

    if sync_errors then
        SynchronizeErrors();
        iesb_req = TRUE;
        TakeUnmaskedPhysicalSErrorInterrupts(iesb_req);
    end;

    EndOfInstruction(<a link="enum_EndOfInstructionReason_Exception" file="shared_pseudocode.xml">EndOfInstructionReason_Exception</a>);
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/AArch64_AArch32SystemAccessTrap" mylink="aarch64.exceptions.traps.AArch64_AArch32SystemAccessTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_AArch32SystemAccessTrap()
// =================================
// Trapped AArch32 System register access.

func <anchor link="func_AArch64_AArch32SystemAccessTrap_2">AArch64_AArch32SystemAccessTrap</anchor>(target_el : bits(2), ec : integer)
begin
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(target_el) &amp;&amp; target_el != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; UInt(target_el) &gt;= UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;

    let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_AArch64_AArch32SystemAccessTrapSyndrome_2" file="shared_pseudocode.xml">AArch64_AArch32SystemAccessTrapSyndrome</a>(<a link="func_ThisInstr_0" file="shared_pseudocode.xml">ThisInstr</a>(), ec);
    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/AArch64_AArch32SystemAccessTrapSyndrome" mylink="aarch64.exceptions.traps.AArch64_AArch32SystemAccessTrapSyndrome" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_AArch32SystemAccessTrapSyndrome()
// =========================================
// Returns the syndrome information for traps on AArch32 MCR, MCRR, MRC, MRRC, and VMRS,
// VMSR instructions, other than traps that are due to HCPTR or CPACR.

func <anchor link="func_AArch64_AArch32SystemAccessTrapSyndrome_2">AArch64_AArch32SystemAccessTrapSyndrome</anchor>(instr : bits(32), ec : integer) =&gt; <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>
begin
    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>;

    case ec of
        when 0x0 =&gt;    except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_Uncategorized" file="shared_pseudocode.xml">Exception_Uncategorized</a>);
        when 0x3 =&gt;    except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_CP15RTTrap" file="shared_pseudocode.xml">Exception_CP15RTTrap</a>);
        when 0x4 =&gt;    except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_CP15RRTTrap" file="shared_pseudocode.xml">Exception_CP15RRTTrap</a>);
        when 0x5 =&gt;    except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_CP14RTTrap" file="shared_pseudocode.xml">Exception_CP14RTTrap</a>);
        when 0x6 =&gt;    except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_CP14DTTrap" file="shared_pseudocode.xml">Exception_CP14DTTrap</a>);
        when 0x7 =&gt;    except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_AdvSIMDFPAccessTrap" file="shared_pseudocode.xml">Exception_AdvSIMDFPAccessTrap</a>);
        when 0x8 =&gt;    except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_FPIDTrap" file="shared_pseudocode.xml">Exception_FPIDTrap</a>);
        when 0xC =&gt;    except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_CP14RRTTrap" file="shared_pseudocode.xml">Exception_CP14RRTTrap</a>);
        otherwise =&gt;   unreachable;
    end;

    var iss : bits(20) = Zeros{};

    if except.exceptype == <a link="enum_Exception_Uncategorized" file="shared_pseudocode.xml">Exception_Uncategorized</a> then
        return except;
    elsif except.exceptype IN {<a link="enum_Exception_FPIDTrap" file="shared_pseudocode.xml">Exception_FPIDTrap</a>, <a link="enum_Exception_CP14RTTrap" file="shared_pseudocode.xml">Exception_CP14RTTrap</a>,
                               <a link="enum_Exception_CP15RTTrap" file="shared_pseudocode.xml">Exception_CP15RTTrap</a>} then
        // Trapped MRC/MCR, VMRS on FPSID
        if except.exceptype != <a link="enum_Exception_FPIDTrap" file="shared_pseudocode.xml">Exception_FPIDTrap</a> then    // When trap is not for VMRS
            iss[19:17] = instr[7:5];           // opc2
            iss[16:14] = instr[23:21];         // opc1
            iss[13:10] = instr[19:16];         // CRn
            iss[4:1]   = instr[3:0];           // CRm
        else
            iss[19:17] = '000';
            iss[16:14] = '111';
            iss[13:10] = instr[19:16];         // reg
            iss[4:1]   = '0000';
        end;

        if instr[20] == '1' &amp;&amp; instr[15:12] == '1111' then    // MRC, Rt==15
            iss[9:5] = '11111';
        elsif instr[20] == '0' &amp;&amp; instr[15:12] == '1111' then // MCR, Rt==15
            iss[9:5] = ARBITRARY : bits(5);
        else
            iss[9:5] = <a link="func_LookUpRIndex_2" file="shared_pseudocode.xml">LookUpRIndex</a>(UInt(instr[15:12]), <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M)[4:0];
        end;
    elsif except.exceptype IN {<a link="enum_Exception_CP14RRTTrap" file="shared_pseudocode.xml">Exception_CP14RRTTrap</a>, <a link="enum_Exception_AdvSIMDFPAccessTrap" file="shared_pseudocode.xml">Exception_AdvSIMDFPAccessTrap</a>,
                               <a link="enum_Exception_CP15RRTTrap" file="shared_pseudocode.xml">Exception_CP15RRTTrap</a>} then
        // Trapped MRRC/MCRR, VMRS/VMSR
        iss[19:16] = instr[7:4];          // opc1
        if instr[19:16] == '1111' then    // Rt2==15
            iss[14:10] = ARBITRARY : bits(5);
        else
            iss[14:10] = <a link="func_LookUpRIndex_2" file="shared_pseudocode.xml">LookUpRIndex</a>(UInt(instr[19:16]), <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M)[4:0];
        end;

        if instr[15:12] == '1111' then    // Rt==15
            iss[9:5] = ARBITRARY : bits(5);
        else
            iss[9:5] = <a link="func_LookUpRIndex_2" file="shared_pseudocode.xml">LookUpRIndex</a>(UInt(instr[15:12]), <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M)[4:0];
        end;
        iss[4:1]   = instr[3:0];         // CRm
    elsif except.exceptype == <a link="enum_Exception_CP14DTTrap" file="shared_pseudocode.xml">Exception_CP14DTTrap</a> then
        // Trapped LDC/STC
        iss[19:12] = instr[7:0];         // imm8
        iss[4]     = instr[23];          // U
        iss[2:1]   = instr[24,21];       // P,W
        if instr[19:16] == '1111' then   // Rn==15, LDC(Literal addressing)/STC
            iss[9:5] = ARBITRARY : bits(5);
            iss[3]   = '1';
        end;
    end;
    iss[0] = instr[20];                  // Direction

    except.syndrome.iss[24:20] = <a link="func_ConditionSyndrome_0" file="shared_pseudocode.xml">ConditionSyndrome</a>();
    except.syndrome.iss[19:0]  = iss;

    return except;
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/AArch64_AdvSIMDFPAccessTrap" mylink="aarch64.exceptions.traps.AArch64_AdvSIMDFPAccessTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_AdvSIMDFPAccessTrap()
// =============================
// Trapped access to Advanced SIMD or FP registers due to CPACR.

func <anchor link="func_AArch64_AdvSIMDFPAccessTrap_1">AArch64_AdvSIMDFPAccessTrap</anchor>(target_el : bits(2))
begin
    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>;
    let vect_offset : integer = 0x0;

    let route_to_el2 : boolean = (target_el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1');

    if route_to_el2 then
        except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_Uncategorized" file="shared_pseudocode.xml">Exception_Uncategorized</a>);
        AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
    else
        except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_AdvSIMDFPAccessTrap" file="shared_pseudocode.xml">Exception_AdvSIMDFPAccessTrap</a>);
        except.syndrome.iss[24:20] = <a link="func_ConditionSyndrome_0" file="shared_pseudocode.xml">ConditionSyndrome</a>();
        AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/AArch64_CheckCP15InstrCoarseTraps" mylink="aarch64.exceptions.traps.AArch64_CheckCP15InstrCoarseTraps" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CheckCP15InstrCoarseTraps()
// ===================================
// Check for coarse-grained AArch32 traps to System registers in the
// coproc=0b1111 encoding space by HSTR_EL2, HCR_EL2, and SCTLR_ELx.

func <anchor link="func_AArch64_CheckCP15InstrCoarseTraps_3">AArch64_CheckCP15InstrCoarseTraps</anchor>(CRn : integer, nreg : integer, CRm : integer)
begin
    let trapped_encoding : boolean = ((CRn == 9  &amp;&amp; CRm IN {0,1,2,    5,6,7,8   }) ||
                                      (CRn == 10 &amp;&amp; CRm IN {0,1,    4,      8   }) ||
                                      (CRn == 11 &amp;&amp; CRm IN {0,1,2,3,4,5,6,7,8,15}));

    // Check for MRC and MCR disabled by SCTLR_EL1.TIDCP.
    if (IsFeatureImplemented(FEAT_TIDCP1) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() &amp;&amp;
           !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) &amp;&amp; SCTLR_EL1().TIDCP == '1' &amp;&amp; trapped_encoding) then
        if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1' then
            <a link="func_AArch64_AArch32SystemAccessTrap_2" file="shared_pseudocode.xml">AArch64_AArch32SystemAccessTrap</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, 0x3);
        else
            <a link="func_AArch64_AArch32SystemAccessTrap_2" file="shared_pseudocode.xml">AArch64_AArch32SystemAccessTrap</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, 0x3);
        end;
    end;

    // Check for coarse-grained Hyp traps
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        // Check for MRC and MCR disabled by SCTLR_EL2.TIDCP.
        if (IsFeatureImplemented(FEAT_TIDCP1) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() &amp;&amp;
              SCTLR_EL2().TIDCP == '1' &amp;&amp; trapped_encoding) then
            <a link="func_AArch64_AArch32SystemAccessTrap_2" file="shared_pseudocode.xml">AArch64_AArch32SystemAccessTrap</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, 0x3);
        end;

        let major : integer = if nreg == 1 then CRn else CRm;
        // Check for MCR, MRC, MCRR, and MRRC disabled by HSTR_EL2().CRn/HSTR().CRm
        // and MRC and MCR disabled by HCR_EL2.TIDCP.
        if ((!<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() &amp;&amp; ! major IN {4,14} &amp;&amp; HSTR_EL2()[major] == '1') ||
                (HCR_EL2().TIDCP == '1' &amp;&amp; nreg == 1 &amp;&amp; trapped_encoding)) then
            if (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp;
                    ImpDefBool(&quot;UNDEF unallocated CP15 access at EL0&quot;)) then
                Undefined();
            end;
            <a link="func_AArch64_AArch32SystemAccessTrap_2" file="shared_pseudocode.xml">AArch64_AArch32SystemAccessTrap</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, 0x3);
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/AArch64_CheckFPAdvSIMDEnabled" mylink="aarch64.exceptions.traps.AArch64_CheckFPAdvSIMDEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CheckFPAdvSIMDEnabled()
// ===============================

func <anchor link="func_AArch64_CheckFPAdvSIMDEnabled_0">AArch64_CheckFPAdvSIMDEnabled</anchor>()
begin
    <a link="func_AArch64_CheckFPEnabled_0" file="shared_pseudocode.xml">AArch64_CheckFPEnabled</a>();
    // Check for illegal use of Advanced
    // SIMD in Streaming SVE Mode
    if IsFeatureImplemented(FEAT_SME) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM == '1' &amp;&amp; !<a link="func_IsFullA64Enabled_0" file="shared_pseudocode.xml">IsFullA64Enabled</a>() then
        <a link="func_SMEAccessTrap_2" file="shared_pseudocode.xml">SMEAccessTrap</a>(<a link="enum_SMEExceptionType_Streaming" file="shared_pseudocode.xml">SMEExceptionType_Streaming</a>, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/AArch64_CheckFPAdvSIMDTrap" mylink="aarch64.exceptions.traps.AArch64_CheckFPAdvSIMDTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CheckFPAdvSIMDTrap()
// ============================
// Check against CPTR_EL2 and CPTR_EL3.

func <anchor link="func_AArch64_CheckFPAdvSIMDTrap_0">AArch64_CheckFPAdvSIMDTrap</anchor>()
begin
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; CPTR_EL3().TFP == '1' &amp;&amp; <a link="func_EL3SDDUndefPriority_0" file="shared_pseudocode.xml">EL3SDDUndefPriority</a>() then
        Undefined();
    end;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        // Check if access disabled in CPTR_EL2
        if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
            var disabled : boolean;
            case CPTR_EL2().FPEN of
                when 'x0' =&gt; disabled = TRUE;
                when '01' =&gt; disabled = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; HCR_EL2().TGE == '1';
                when '11' =&gt; disabled = FALSE;
            end;
            if disabled then <a link="func_AArch64_AdvSIMDFPAccessTrap_1" file="shared_pseudocode.xml">AArch64_AdvSIMDFPAccessTrap</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>); end;
        else
            if CPTR_EL2().TFP == '1' then <a link="func_AArch64_AdvSIMDFPAccessTrap_1" file="shared_pseudocode.xml">AArch64_AdvSIMDFPAccessTrap</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>); end;
        end;
    end;

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        // Check if access disabled in CPTR_EL3
        if CPTR_EL3().TFP == '1' then
            if <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then
                Undefined();
            else
                <a link="func_AArch64_AdvSIMDFPAccessTrap_1" file="shared_pseudocode.xml">AArch64_AdvSIMDFPAccessTrap</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
            end;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/AArch64_CheckFPEnabled" mylink="aarch64.exceptions.traps.AArch64_CheckFPEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CheckFPEnabled()
// ========================
// Check against CPACR

func <anchor link="func_AArch64_CheckFPEnabled_0">AArch64_CheckFPEnabled</anchor>()
begin
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
        // Check if access disabled in CPACR_EL1
        var disabled : boolean;
        case CPACR_EL1().FPEN of
            when 'x0' =&gt; disabled = TRUE;
            when '01' =&gt; disabled = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
            when '11' =&gt; disabled = FALSE;
        end;
        if disabled then <a link="func_AArch64_AdvSIMDFPAccessTrap_1" file="shared_pseudocode.xml">AArch64_AdvSIMDFPAccessTrap</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>); end;
    end;

    <a link="func_AArch64_CheckFPAdvSIMDTrap_0" file="shared_pseudocode.xml">AArch64_CheckFPAdvSIMDTrap</a>();               // Also check against CPTR_EL2 and CPTR_EL3
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/AArch64_CheckForERetTrap" mylink="aarch64.exceptions.traps.AArch64_CheckForERetTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CheckForERetTrap()
// ==========================
// Check for trap on ERET, ERETAA, ERETAB instruction

func <anchor link="func_AArch64_CheckForERetTrap_2">AArch64_CheckForERetTrap</anchor>(eret_with_pac : boolean, pac_uses_key_a : boolean)
begin
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        var route_to_el2 : boolean = FALSE;

        // Check for a fine-grained trap by the hypervisor.
        if (IsFeatureImplemented(FEAT_FGT) &amp;&amp; (!<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || SCR_EL3().FGTEn == '1') &amp;&amp;
              HFGITR_EL2().ERET == '1') then
            route_to_el2 = TRUE;
        // Check for a trap by the Effective value of the HCR_EL2.NV bit
        elsif <a link="func_EffectiveHCR_EL2_NVx_0" file="shared_pseudocode.xml">EffectiveHCR_EL2_NVx</a>()[0] == '1' then
            route_to_el2 = TRUE;
        end;

        if route_to_el2 then
            let preferred_exception_return : bits(64) = ThisInstrAddr{}();
            let vect_offset : integer = 0x0;
            var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_ERetTrap" file="shared_pseudocode.xml">Exception_ERetTrap</a>);

            if !eret_with_pac then                             // ERET
                except.syndrome.iss[1] = '0';
                except.syndrome.iss[0] = '0';                  // RES0
            else
                except.syndrome.iss[1] = '1';
                except.syndrome.iss[0] = if pac_uses_key_a then '0' else '1';
            end;

            AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
        end;
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/AArch64_CheckForSMCUndefOrTrap" mylink="aarch64.exceptions.traps.AArch64_CheckForSMCUndefOrTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CheckForSMCUndefOrTrap()
// ================================
// Check for UNDEFINED or trap on SMC instruction

func <anchor link="func_AArch64_CheckForSMCUndefOrTrap_1">AArch64_CheckForSMCUndefOrTrap</anchor>(imm : bits(16))
begin
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then Undefined(); end;
    if (!(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TSC == '1') &amp;&amp;
        <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().SMD == '1') then
        Undefined();
    end;
    var route_to_el2 : boolean = FALSE;
    if !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        if (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TSC == '1' &amp;&amp;
              (<a link="func_EffectiveHCR_EL2_NVx_0" file="shared_pseudocode.xml">EffectiveHCR_EL2_NVx</a>() == 'xx1' ||
              (ImpDefBool(&quot;Trap SMC execution at EL1 to EL2&quot;)))) then
            route_to_el2 = TRUE;
        else
            Undefined();
        end;
    else
        route_to_el2 = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TSC == '1';
    end;
    if route_to_el2 then
        let preferred_exception_return : bits(64) = ThisInstrAddr{}();
        let vect_offset : integer = 0x0;
        var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_MonitorCall" file="shared_pseudocode.xml">Exception_MonitorCall</a>);
        except.syndrome.iss[15:0] = imm;
        except.trappedsyscallinst = TRUE;
        AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/AArch64_CheckForSVCTrap" mylink="aarch64.exceptions.traps.AArch64_CheckForSVCTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CheckForSVCTrap()
// =========================
// Check for trap on SVC instruction

func <anchor link="func_AArch64_CheckForSVCTrap_1">AArch64_CheckForSVCTrap</anchor>(immediate : bits(16))
begin
    if IsFeatureImplemented(FEAT_FGT) then
        var route_to_el2 : boolean = FALSE;
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
            route_to_el2 = (!<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) &amp;&amp;
                           <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HFGITR_EL2().SVC_EL0 == '1' &amp;&amp;
                           (!<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() &amp;&amp; (!<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || SCR_EL3().FGTEn == '1')));

        elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> then
            route_to_el2 = (<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HFGITR_EL2().SVC_EL1 == '1' &amp;&amp;
                           (!<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || SCR_EL3().FGTEn == '1'));
        end;

        if route_to_el2 then
            var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_SupervisorCall" file="shared_pseudocode.xml">Exception_SupervisorCall</a>);
            except.syndrome.iss[15:0] = immediate;
            except.trappedsyscallinst = TRUE;
            let preferred_exception_return : bits(64) = ThisInstrAddr{}();
            let vect_offset : integer = 0x0;

            AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/AArch64_CheckForWFxTrap" mylink="aarch64.exceptions.traps.AArch64_CheckForWFxTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CheckForWFxTrap()
// =========================
// Checks for a trap on a WFE, WFET, WFI or WFIT instruction.

func <anchor link="func_AArch64_CheckForWFxTrap_1">AArch64_CheckForWFxTrap</anchor>(wfxtype : <a link="type_WFxType" file="shared_pseudocode.xml">WFxType</a>) =&gt; (boolean, bits(2))
begin
    let is_wfe : boolean = wfxtype IN {<a link="enum_WFxType_WFE" file="shared_pseudocode.xml">WFxType_WFE</a>, <a link="enum_WFxType_WFET" file="shared_pseudocode.xml">WFxType_WFET</a>};
    var target_el : bits(2);
    var trap : boolean = FALSE;

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_EL3SDDUndefPriority_0" file="shared_pseudocode.xml">EL3SDDUndefPriority</a>() &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then
        // Check for traps described by the Secure Monitor.
        // If the trap is enabled, the instruction will be UNDEFINED because EDSCR.SDD is 1.
        trap      = (if is_wfe then SCR_EL3().TWE else SCR_EL3().TWI) == '1';
        target_el = <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
    end;

    if !trap &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        // Check for traps described by the OS which may be EL1 or EL2.
        trap      = (if is_wfe then <a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>().nTWE else <a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>().nTWI) == '0';
        target_el = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    end;

    if !trap &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
        // Check for traps described by the Hypervisor.
        trap      = (if is_wfe then HCR_EL2().TWE else HCR_EL2().TWI) == '1';
        target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    end;

    if !trap &amp;&amp; <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then
        // Check for traps described by the Secure Monitor.
        trap      = (if is_wfe then SCR_EL3().TWE else SCR_EL3().TWI) == '1';
        target_el = <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
    end;
    return (trap, target_el);
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/AArch64_CheckIllegalState" mylink="aarch64.exceptions.traps.AArch64_CheckIllegalState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CheckIllegalState()
// ===========================
// Check PSTATE.IL bit and generate Illegal Execution state exception if set.

func <anchor link="func_AArch64_CheckIllegalState_0">AArch64_CheckIllegalState</anchor>()
begin
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL == '1' then
        let route_to_el2 : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1';

        let preferred_exception_return : bits(64) = ThisInstrAddr{}();
        let vect_offset : integer = 0x0;

        let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_IllegalState" file="shared_pseudocode.xml">Exception_IllegalState</a>);

        if UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) &gt; UInt(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
            AArch64_TakeException(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL, except, preferred_exception_return, vect_offset);
        elsif route_to_el2 then
            AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
        else
            AArch64_TakeException(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, except, preferred_exception_return, vect_offset);
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/AArch64_MonitorModeTrap" mylink="aarch64.exceptions.traps.AArch64_MonitorModeTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_MonitorModeTrap()
// =========================
// Trapped use of Monitor mode features in a Secure EL1 AArch32 mode

func <anchor link="func_AArch64_MonitorModeTrap_0">AArch64_MonitorModeTrap</anchor>()
begin
    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer                 = 0x0;

    let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>              = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_Uncategorized" file="shared_pseudocode.xml">Exception_Uncategorized</a>);

    if <a link="func_IsSecureEL2Enabled_0" file="shared_pseudocode.xml">IsSecureEL2Enabled</a>() then
        AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
    end;
    AArch64_TakeException(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/AArch64_OtherInstrTrap" mylink="aarch64.exceptions.traps.AArch64_OtherInstrTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_OtherInstrTrap()
// ========================
// Trapped access to the following instructions:
// - LD64B
// - ST64B
// - ST64BV
// - ST64BV0
// - PSB
// - TSB

func <anchor link="func_AArch64_OtherInstrTrap_2">AArch64_OtherInstrTrap</anchor>(target_el : bits(2), iss : bits(25))
begin
    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_OtherTrap" file="shared_pseudocode.xml">Exception_OtherTrap</a>);
    except.syndrome.iss = iss;
    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/AArch64_SystemAccessTrap" mylink="aarch64.exceptions.traps.AArch64_SystemAccessTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SystemAccessTrap()
// ==========================
// Trapped access to AArch64 System register or system instruction.

func <anchor link="func_AArch64_SystemAccessTrap_2">AArch64_SystemAccessTrap</anchor>(target_el : bits(2), ec : integer)
begin
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(target_el) &amp;&amp; target_el != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; UInt(target_el) &gt;= UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;

    let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_AArch64_SystemAccessTrapSyndrome_2" file="shared_pseudocode.xml">AArch64_SystemAccessTrapSyndrome</a>(<a link="func_ThisInstr_0" file="shared_pseudocode.xml">ThisInstr</a>(), ec);
    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/AArch64_SystemAccessTrapSyndrome" mylink="aarch64.exceptions.traps.AArch64_SystemAccessTrapSyndrome" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SystemAccessTrapSyndrome()
// ==================================
// Returns the syndrome information for traps on AArch64 MSR/MRS instructions.

func <anchor link="func_AArch64_SystemAccessTrapSyndrome_2">AArch64_SystemAccessTrapSyndrome</anchor>(instr_in : bits(32), ec : integer) =&gt; <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>
begin
    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>;
    var instr : bits(32) = instr_in;
    case ec of
        when 0x0 =&gt;                      // Trapped access due to unknown reason.
            except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_Uncategorized" file="shared_pseudocode.xml">Exception_Uncategorized</a>);
        when 0x7 =&gt;                      // Trapped access to SVE, Advance SIMD&amp;FP System register.
            except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_AdvSIMDFPAccessTrap" file="shared_pseudocode.xml">Exception_AdvSIMDFPAccessTrap</a>);
            except.syndrome.iss[24:20] = <a link="func_ConditionSyndrome_0" file="shared_pseudocode.xml">ConditionSyndrome</a>();
        when 0x14 =&gt;                     // Trapped access to 128-bit System register or
                                         // 128-bit System instruction.
            except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_SystemRegister128Trap" file="shared_pseudocode.xml">Exception_SystemRegister128Trap</a>);
            instr = <a link="func_ThisInstr_0" file="shared_pseudocode.xml">ThisInstr</a>();
            except.syndrome.iss[21:20] = instr[20:19]; // Op0
            except.syndrome.iss[19:17] = instr[7:5];   // Op2
            except.syndrome.iss[16:14] = instr[18:16]; // Op1
            except.syndrome.iss[13:10] = instr[15:12]; // CRn
            except.syndrome.iss[9:6]   = instr[4:1];   // Rt
            except.syndrome.iss[4:1]   = instr[11:8];  // CRm
            except.syndrome.iss[0]     = instr[21];    // Direction
        when 0x18 =&gt;                     // Trapped access to System register or system instruction.
            except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_SystemRegisterTrap" file="shared_pseudocode.xml">Exception_SystemRegisterTrap</a>);
            instr = <a link="func_ThisInstr_0" file="shared_pseudocode.xml">ThisInstr</a>();
            except.syndrome.iss[21:20] = instr[20:19]; // Op0
            except.syndrome.iss[19:17] = instr[7:5];   // Op2
            except.syndrome.iss[16:14] = instr[18:16]; // Op1
            except.syndrome.iss[13:10] = instr[15:12]; // CRn
            except.syndrome.iss[9:5]   = instr[4:0];   // Rt
            except.syndrome.iss[4:1]   = instr[11:8];  // CRm
            except.syndrome.iss[0]     = instr[21];    // Direction
        when 0x19 =&gt;                        // Trapped access to SVE System register
            except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_SVEAccessTrap" file="shared_pseudocode.xml">Exception_SVEAccessTrap</a>);
        when 0x1D =&gt;                        // Trapped access to SME System register
            except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_SMEAccessTrap" file="shared_pseudocode.xml">Exception_SMEAccessTrap</a>);
        otherwise =&gt;
            unreachable;
    end;

    return except;
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/AArch64_Undefined" mylink="aarch64.exceptions.traps.AArch64_Undefined" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_Undefined()
// ===================

noreturn func AArch64_Undefined()
begin

    let route_to_el2 : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1';
    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;

    let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_Uncategorized" file="shared_pseudocode.xml">Exception_Uncategorized</a>);

    if UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) &gt; UInt(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        AArch64_TakeException(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL, except, preferred_exception_return, vect_offset);
    elsif route_to_el2 then
        AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
    else
        AArch64_TakeException(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, except, preferred_exception_return, vect_offset);
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/AArch64_WFxTrap" mylink="aarch64.exceptions.traps.AArch64_WFxTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_WFxTrap()
// =================
// Generate an exception for a trapped WFE, WFI, WFET or WFIT instruction.

func <anchor link="func_AArch64_WFxTrap_2">AArch64_WFxTrap</anchor>(wfxtype : <a link="type_WFxType" file="shared_pseudocode.xml">WFxType</a>, target_el : bits(2))
begin
    assert UInt(target_el) &gt; UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;
    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_WFxTrap" file="shared_pseudocode.xml">Exception_WFxTrap</a>);
    except.syndrome.iss[24:20] = <a link="func_ConditionSyndrome_0" file="shared_pseudocode.xml">ConditionSyndrome</a>();
    case wfxtype of
        when <a link="enum_WFxType_WFI" file="shared_pseudocode.xml">WFxType_WFI</a> =&gt;
            except.syndrome.iss[1:0] = '00';
        when <a link="enum_WFxType_WFE" file="shared_pseudocode.xml">WFxType_WFE</a> =&gt;
            except.syndrome.iss[1:0] = '01';
        when <a link="enum_WFxType_WFIT" file="shared_pseudocode.xml">WFxType_WFIT</a> =&gt;
            except.syndrome.iss[1:0] = '10';
            except.syndrome.iss[2]   = '1';   // Register field is valid
            except.syndrome.iss[9:5] = <a link="func_ThisInstr_0" file="shared_pseudocode.xml">ThisInstr</a>()[4:0];
        when <a link="enum_WFxType_WFET" file="shared_pseudocode.xml">WFxType_WFET</a> =&gt;
            except.syndrome.iss[1:0] = '11';
            except.syndrome.iss[2]   = '1';   // Register field is valid
            except.syndrome.iss[9:5] = <a link="func_ThisInstr_0" file="shared_pseudocode.xml">ThisInstr</a>()[4:0];
    end;

    if target_el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1' then
        AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
    else
        AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/CheckLDST64BEnabled" mylink="aarch64.exceptions.traps.CheckLDST64BEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckLDST64BEnabled()
// =====================
// Checks for trap on ST64B and LD64B instructions

func <anchor link="func_CheckLDST64BEnabled_0">CheckLDST64BEnabled</anchor>()
begin
    var trap : boolean = FALSE;
    let iss : bits(25) = 0x2[24:0];
    var target_el : bits(2);

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        if !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
            trap = SCTLR_EL1().EnALS == '0';
            target_el = if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1' then <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> else <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
        else
            trap = SCTLR_EL2().EnALS == '0';
            target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
        end;
    else
        target_el = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    end;

    if (!trap &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
        ((<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>()) || <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>)) then
        trap = !<a link="func_IsHCRXEL2Enabled_0" file="shared_pseudocode.xml">IsHCRXEL2Enabled</a>() || HCRX_EL2().EnALS == '0';
        target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    end;

    if trap then <a link="func_AArch64_OtherInstrTrap_2" file="shared_pseudocode.xml">AArch64_OtherInstrTrap</a>(target_el, iss); end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/CheckST64BV0Enabled" mylink="aarch64.exceptions.traps.CheckST64BV0Enabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckST64BV0Enabled()
// =====================
// Checks for trap on ST64BV0 instruction

func <anchor link="func_CheckST64BV0Enabled_0">CheckST64BV0Enabled</anchor>()
begin
    var trap : boolean = FALSE;
    let iss : bits(25) = 0x1[24:0];
    var target_el : bits(2);

    if (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp;
        SCR_EL3().EnAS0 == '0' &amp;&amp; <a link="func_EL3SDDUndefPriority_0" file="shared_pseudocode.xml">EL3SDDUndefPriority</a>()) then
        Undefined();
    end;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        if !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
            trap = SCTLR_EL1().EnAS0 == '0';
            target_el = if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1' then <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> else <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
        else
            trap = SCTLR_EL2().EnAS0 == '0';
            target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
        end;
    end;

    if (!trap &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
        ((<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>()) || <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>)) then
        trap = !<a link="func_IsHCRXEL2Enabled_0" file="shared_pseudocode.xml">IsHCRXEL2Enabled</a>() || HCRX_EL2().EnAS0 == '0';
        target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    end;

    if !trap &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then
        trap = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().EnAS0 == '0';
        target_el = <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
    end;

    if trap then
        if target_el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then
            Undefined();
        else
            <a link="func_AArch64_OtherInstrTrap_2" file="shared_pseudocode.xml">AArch64_OtherInstrTrap</a>(target_el, iss);
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/CheckST64BVEnabled" mylink="aarch64.exceptions.traps.CheckST64BVEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckST64BVEnabled()
// ====================
// Checks for trap on ST64BV instruction

func <anchor link="func_CheckST64BVEnabled_0">CheckST64BVEnabled</anchor>()
begin
    var trap : boolean = FALSE;
    let iss : bits(25) = 0x0[24:0];
    var target_el : bits(2);

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        if !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
            trap = SCTLR_EL1().EnASR == '0';
            target_el = if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1' then <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> else <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
        else
            trap = SCTLR_EL2().EnASR == '0';
            target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
        end;
    end;

    if (!trap &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
        ((<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>()) || <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>)) then
        trap = !<a link="func_IsHCRXEL2Enabled_0" file="shared_pseudocode.xml">IsHCRXEL2Enabled</a>() || HCRX_EL2().EnASR == '0';
        target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    end;

    if trap then <a link="func_AArch64_OtherInstrTrap_2" file="shared_pseudocode.xml">AArch64_OtherInstrTrap</a>(target_el, iss); end;
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/WFETrapDelay" mylink="aarch64.exceptions.traps.WFETrapDelay" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// WFETrapDelay()
// ==============
// Returns TRUE when delay in trap to WFE is enabled with value to amount of delay,
// FALSE otherwise.

func <anchor link="func_WFETrapDelay_1">WFETrapDelay</anchor>(target_el : bits(2)) =&gt; (boolean, integer)
begin
    var delay_enabled : boolean;
    var delay : integer;
    case target_el of
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            if !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
                delay_enabled = SCTLR_EL1().TWEDEn == '1';
                delay         = 1 &lt;&lt; (UInt(SCTLR_EL1().TWEDEL) + 8);
            else
                delay_enabled = SCTLR_EL2().TWEDEn == '1';
                delay         = 1 &lt;&lt; (UInt(SCTLR_EL2().TWEDEL) + 8);
            end;
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            assert <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>();
            delay_enabled = HCR_EL2().TWEDEn == '1';
            delay         = 1 &lt;&lt; (UInt(HCR_EL2().TWEDEL) + 8);
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            delay_enabled = SCR_EL3().TWEDEn == '1';
            delay         = 1 &lt;&lt; (UInt(SCR_EL3().TWEDEL) + 8);
    end;
    return (delay_enabled, delay);
end;</pstext></ps>
    <ps name="aarch64/exceptions/traps/WaitForEventUntilDelay" mylink="aarch64.exceptions.traps.WaitForEventUntilDelay" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// WaitForEventUntilDelay()
// ========================
// Returns TRUE if WaitForEvent() returns before WFE trap delay expires, including potentially
// some IMPLEMENTATION SPECIFIC additional delay, FALSE otherwise.

impdef func <anchor link="func_WaitForEventUntilDelay_2">WaitForEventUntilDelay</anchor>(delay_enabled : boolean, delay : integer) =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/functions/aborts/AArch64_FaultSyndrome" mylink="aarch64.functions.aborts.AArch64_FaultSyndrome" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_FaultSyndrome()
// =======================
// Creates an exception syndrome value and updates the virtual address for Abort and Watchpoint
// exceptions taken to an Exception level using AArch64.

func <anchor link="func_AArch64_FaultSyndrome_3">AArch64_FaultSyndrome</anchor>(exceptype : <a link="type_Exception" file="shared_pseudocode.xml">Exception</a>, fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>,
                           target_el : bits(2)) =&gt; <a link="type_IssType" file="shared_pseudocode.xml">IssType</a>
begin
    assert fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;

    var isstype : <a link="type_IssType" file="shared_pseudocode.xml">IssType</a>;
    isstype.iss  = Zeros{25};
    isstype.iss2 = Zeros{24};

    let d_side : boolean = exceptype IN {<a link="enum_Exception_DataAbort" file="shared_pseudocode.xml">Exception_DataAbort</a>, <a link="enum_Exception_NV2DataAbort" file="shared_pseudocode.xml">Exception_NV2DataAbort</a>,
                                         <a link="enum_Exception_Watchpoint" file="shared_pseudocode.xml">Exception_Watchpoint</a>, <a link="enum_Exception_NV2Watchpoint" file="shared_pseudocode.xml">Exception_NV2Watchpoint</a>};
    if IsFeatureImplemented(FEAT_RAS) &amp;&amp; fault.statuscode == <a link="enum_Fault_SyncExternal" file="shared_pseudocode.xml">Fault_SyncExternal</a> then
        let errstate : <a link="type_ErrorState" file="shared_pseudocode.xml">ErrorState</a> = <a link="func_PEErrorState_1" file="shared_pseudocode.xml">PEErrorState</a>(fault);
        isstype.iss[12:11] = <a link="func_AArch64_EncodeSyncErrorSyndrome_1" file="shared_pseudocode.xml">AArch64_EncodeSyncErrorSyndrome</a>(errstate);  // SET
    end;

    if d_side then
        if fault.accessdesc.acctype == <a link="enum_AccessType_GCS" file="shared_pseudocode.xml">AccessType_GCS</a> then
            isstype.iss2[8] = '1';
        end;
        if exceptype IN {<a link="enum_Exception_Watchpoint" file="shared_pseudocode.xml">Exception_Watchpoint</a>, <a link="enum_Exception_NV2Watchpoint" file="shared_pseudocode.xml">Exception_NV2Watchpoint</a>} then
            isstype.iss[23:0] = <a link="func_WatchpointRelatedSyndrome_1" file="shared_pseudocode.xml">WatchpointRelatedSyndrome</a>(fault);
        end;

        if <a link="func_AArch64_InstructionSyndromeValid_1" file="shared_pseudocode.xml">AArch64_InstructionSyndromeValid</a>(fault) then
            if fault.accessdesc.ls64 then
                (isstype.iss2, isstype.iss[24:14]) = <a link="func_LS64InstructionSyndrome_0" file="shared_pseudocode.xml">LS64InstructionSyndrome</a>();
            else
                isstype.iss[24:14] = <a link="func_LSInstructionSyndrome_0" file="shared_pseudocode.xml">LSInstructionSyndrome</a>();
            end;
        end;

        if IsFeatureImplemented(FEAT_NV2) &amp;&amp; fault.accessdesc.acctype == <a link="enum_AccessType_NV2" file="shared_pseudocode.xml">AccessType_NV2</a> then
            isstype.iss[13] = '1';   // Fault is generated by use of VNCR_EL2
        end;

        if (IsFeatureImplemented(FEAT_LS64) &amp;&amp;
              fault.statuscode IN {<a link="enum_Fault_AccessFlag" file="shared_pseudocode.xml">Fault_AccessFlag</a>, <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>, <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>}) then
            isstype.iss[12:11] = <a link="func_GetLoadStoreType_0" file="shared_pseudocode.xml">GetLoadStoreType</a>();
        end;

        if fault.accessdesc.acctype IN {<a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>, <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>, <a link="enum_AccessType_AT" file="shared_pseudocode.xml">AccessType_AT</a>} then
            isstype.iss[8] = '1';
        end;

        if fault.accessdesc.acctype IN {<a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>, <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>, <a link="enum_AccessType_AT" file="shared_pseudocode.xml">AccessType_AT</a>} then
            isstype.iss[6] = '1';
        elsif fault.statuscode IN {<a link="enum_Fault_UnsupportedAtomicHWUpdate" file="shared_pseudocode.xml">Fault_UnsupportedAtomicHWUpdate</a>, <a link="enum_Fault_Exclusive" file="shared_pseudocode.xml">Fault_Exclusive</a>} then
            isstype.iss[6] = ARBITRARY : bit;
        elsif fault.accessdesc.atomicop &amp;&amp; <a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) then
            isstype.iss[6] = ARBITRARY : bit;
        else
            isstype.iss[6] = if fault.write then '1' else '0';
        end;
        isstype.iss2[9] = if fault.tagaccess then '1' else '0';
        if fault.statuscode == <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a> then
            isstype.iss2[5] = if fault.dirtybit then '1' else '0';
            isstype.iss2[6] = if fault.overlay then '1' else '0';
            if isstype.iss[24] == '0' then
                isstype.iss[21] = if fault.toplevel then '1' else '0';
            end;
            isstype.iss2[7] = if fault.assuredonly then '1' else '0';
            isstype.iss2[10] = if fault.s1tagnotdata then '1' else '0';
        end;

    else
        if (fault.accessdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> &amp;&amp;
              fault.statuscode == <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>) then
            isstype.iss2[5] = if fault.dirtybit then '1' else '0';
            isstype.iss[21] = if fault.toplevel then '1' else '0';
            isstype.iss2[7] = if fault.assuredonly then '1' else '0';
            isstype.iss2[6] = if fault.overlay then '1' else '0';
        end;
    end;
    if fault.hdbssf then
        isstype.iss2[11] = '1';
    end;

    if (IsFeatureImplemented(FEAT_PFAR) &amp;&amp; <a link="func_IsExternalSyncAbort_1" file="shared_pseudocode.xml">IsExternalSyncAbort</a>(fault) &amp;&amp;
          !(<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; (HCR_EL2().VM == '1' || HCR_EL2().DC == '1') &amp;&amp; target_el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>)) then
        isstype.iss[14] = if <a link="func_IsPFARValid_1" file="shared_pseudocode.xml">IsPFARValid</a>(fault) then '1' else '0';
    end;

    if <a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) then isstype.iss[9] = fault.extflag; end;
    isstype.iss[7] = if fault.s2fs1walk then '1' else '0';
    isstype.iss[5:0] = <a link="func_EncodeLDFSC_2" file="shared_pseudocode.xml">EncodeLDFSC</a>(fault.statuscode, fault.level);

    return isstype;
end;</pstext></ps>
    <ps name="aarch64/functions/aborts/AArch64_InstructionSyndromeValid" mylink="aarch64.functions.aborts.AArch64_InstructionSyndromeValid" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_InstructionSyndromeValid()
// ==================================
// Returns TRUE if ESR_ELx.ISV is '1' for the given Fault.

func <anchor link="func_AArch64_InstructionSyndromeValid_1">AArch64_InstructionSyndromeValid</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; boolean
begin
    if !fault.accessdesc.lowestaddress then
        return FALSE;
    end;

    if fault.accessdesc.ls64 then
        return fault.statuscode IN {<a link="enum_Fault_AccessFlag" file="shared_pseudocode.xml">Fault_AccessFlag</a>, <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>, <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>};
    end;

    if fault.accessdesc.acctype == <a link="enum_AccessType_GCS" file="shared_pseudocode.xml">AccessType_GCS</a> then
        return FALSE;
    end;

    if <a link="func_IsSecondStage_1" file="shared_pseudocode.xml">IsSecondStage</a>(fault) &amp;&amp; !fault.s2fs1walk then
        return (!<a link="func_IsExternalSyncAbort_1" file="shared_pseudocode.xml">IsExternalSyncAbort</a>(fault) ||
                (!IsFeatureImplemented(FEAT_RAS) &amp;&amp; <a link="func_IsExternalAbortOnWalk_1" file="shared_pseudocode.xml">IsExternalAbortOnWalk</a>(fault) &amp;&amp;
                  ImpDefBool(&quot;ISV on second stage translation table walk&quot;)));
    end;

    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/functions/aborts/EncodeGPCSC" mylink="aarch64.functions.aborts.EncodeGPCSC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EncodeGPCSC()
// =============
// Function that gives the GPCSC code for types of GPT Fault

func <anchor link="func_EncodeGPCSC_1">EncodeGPCSC</anchor>(gpcf : <a link="type_GPCFRecord" file="shared_pseudocode.xml">GPCFRecord</a>) =&gt; bits(6)
begin
    assert gpcf.level IN {0,1};

    case gpcf.gpf of
        when <a link="enum_GPCF_AddressSize" file="shared_pseudocode.xml">GPCF_AddressSize</a> =&gt; return '00000'::gpcf.level[0];
        when <a link="enum_GPCF_Walk" file="shared_pseudocode.xml">GPCF_Walk</a> =&gt;        return '00010'::gpcf.level[0];
        when <a link="enum_GPCF_Fail" file="shared_pseudocode.xml">GPCF_Fail</a> =&gt;        return '00110'::gpcf.level[0];
        when <a link="enum_GPCF_EABT" file="shared_pseudocode.xml">GPCF_EABT</a> =&gt;        return '01010'::gpcf.level[0];
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/aborts/LS64InstructionSyndrome" mylink="aarch64.functions.aborts.LS64InstructionSyndrome" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// LS64InstructionSyndrome()
// =========================
// Returns the syndrome information and LST for a Data Abort by a
// ST64B, ST64BV, ST64BV0, or LD64B instruction. The syndrome information
// includes the ISS2, extended syndrome field.

impdef func <anchor link="func_LS64InstructionSyndrome_0">LS64InstructionSyndrome</anchor>() =&gt; (bits(24), bits(11))
begin
    return (Zeros{24}, <a link="func_LSInstructionSyndrome_0" file="shared_pseudocode.xml">LSInstructionSyndrome</a>());
end;</pstext></ps>
    <ps name="aarch64/functions/aborts/WatchpointFARNotPrecise" mylink="aarch64.functions.aborts.WatchpointFARNotPrecise" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// WatchpointFARNotPrecise()
// =========================
// Returns TRUE If the lowest watchpointed address that is higher than or equal to the address
// recorded in EDWAR might not have been accessed by the instruction, other than the CONSTRAINED
// UNPREDICTABLE condition of watchpoint matching a range of addresses with lowest address 16 bytes
// rounded down and upper address rounded up to nearest 16 byte multiple,
// FALSE otherwise.

impdef func <anchor link="func_WatchpointFARNotPrecise_1">WatchpointFARNotPrecise</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; boolean
begin
    if IsFeatureImplemented(FEAT_SVE) || IsFeatureImplemented(FEAT_SME) then
        return fault.watchptinfo.maybe_false_match;
    end;
    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/functions/apas/AArch64_APAS" mylink="aarch64.functions.apas.AArch64_APAS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_APAS()
// ==============
// Decode Xt and perform an APAS operation for the decoded record.

func <anchor link="func_AArch64_APAS_1">AArch64_APAS</anchor>(Xt : bits(64))
begin
    var apas : <a link="type_APASRecord" file="shared_pseudocode.xml">APASRecord</a>;
    let nse2 : bit = '0';
    apas.paspace = <a link="func_DecodePASpace_3" file="shared_pseudocode.xml">DecodePASpace</a>(nse2, Xt[62], Xt[63]);

    apas.pa = Xt[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:6] :: '000000';
    apas.target_attributes = Xt[2:0];

    if <a link="func_AArch64_LocationSupportsAPAS_1" file="shared_pseudocode.xml">AArch64_LocationSupportsAPAS</a>(apas) then
        APAS_OP(apas);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/apas/AArch64_LocationSupportsAPAS" mylink="aarch64.functions.apas.AArch64_LocationSupportsAPAS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_LocationSupportsAPAS()
// ==============================
// Returns TRUE if the given memory location supports the APAS instruction.

impdef func <anchor link="func_AArch64_LocationSupportsAPAS_1">AArch64_LocationSupportsAPAS</anchor>(apas : <a link="type_APASRecord" file="shared_pseudocode.xml">APASRecord</a>) =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/apas/APASRecord" mylink="aarch64.functions.apas.APASRecord" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// APASRecord
// ==========
// Details related to an APAS operation.

type <anchor link="type_APASRecord">APASRecord</anchor> of record {
    pa : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>),
    paspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>,
    target_attributes : bits(3)
};</pstext></ps>
    <ps name="aarch64/functions/apas/APAS_OP" mylink="aarch64.functions.apas.APAS_OP" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// APAS_OP()
// =========
// Sets the PA Space of the address in the APASRecord to the target PA space. If the location
// does not support the APAS instruction or cannot be associated with the indicated PASpace,
// then the instruction has no effect on the location and does not generate an External abort.

impdef func APAS_OP(apas : <a link="type_APASRecord" file="shared_pseudocode.xml">APASRecord</a>)
begin
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/at/AArch64_AT" mylink="aarch64.functions.at.AArch64_AT" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_AT()
// ============
// Perform address translation as per AT instructions.

func <anchor link="func_AArch64_AT_4">AArch64_AT</anchor>(address : bits(64), stage : <a link="type_TranslationStage" file="shared_pseudocode.xml">TranslationStage</a>, el_in : bits(2), ataccess : <a link="type_ATAccess" file="shared_pseudocode.xml">ATAccess</a>)
begin
    var el : bits(2) = el_in;
    // For stage 1 translation, when HCR_EL2().[E2H, TGE] is {1,1} and requested EL is EL1,
    // the EL2&amp;0 translation regime is used.
    if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) &amp;&amp; el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; stage == <a link="enum_TranslationStage_1" file="shared_pseudocode.xml">TranslationStage_1</a> then
        el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    end;

    let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(el);

    let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescAT_3" file="shared_pseudocode.xml">CreateAccDescAT</a>(ss, el, ataccess);
    let aligned : boolean = TRUE;

    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_2" file="shared_pseudocode.xml">NoFault</a>(accdesc, address);
    let regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a> = <a link="func_TranslationRegime_1" file="shared_pseudocode.xml">TranslationRegime</a>(el);

    var addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    if (el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>)) || (el != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(el)) then
        if regime == <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> || TTBCR().EAE == '1' then
            (fault, addrdesc) = <a link="func_AArch32_S1TranslateLD_5" file="shared_pseudocode.xml">AArch32_S1TranslateLD</a>(fault, regime, address[31:0], aligned,
                                                      accdesc);
        else
            (fault, addrdesc, -) = <a link="func_AArch32_S1TranslateSD_5" file="shared_pseudocode.xml">AArch32_S1TranslateSD</a>(fault, regime, address[31:0], aligned,
                                                         accdesc);
        end;
    else
        let size : integer = 1;
        (fault, addrdesc) = <a link="func_AArch64_S1Translate_6" file="shared_pseudocode.xml">AArch64_S1Translate</a>(fault, regime, address, size, aligned, accdesc);
    end;

    if stage == <a link="enum_TranslationStage_12" file="shared_pseudocode.xml">TranslationStage_12</a> &amp;&amp; fault.statuscode == <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        let s1aarch64 : boolean = TRUE;
        if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) &amp;&amp; regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
            addrdesc.vaddress = ZeroExtend{64}(address);
            (fault, addrdesc) = <a link="func_AArch32_S2Translate_4" file="shared_pseudocode.xml">AArch32_S2Translate</a>(fault, addrdesc, aligned, accdesc);
        elsif regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
            (fault, addrdesc) = <a link="func_AArch64_S2Translate_5" file="shared_pseudocode.xml">AArch64_S2Translate</a>(fault, addrdesc, s1aarch64, aligned, accdesc);
        end;
    end;

    let is_ATS1Ex : boolean = stage != <a link="enum_TranslationStage_12" file="shared_pseudocode.xml">TranslationStage_12</a>;
    if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        addrdesc = <a link="func_CreateFaultyAddressDescriptor_1" file="shared_pseudocode.xml">CreateFaultyAddressDescriptor</a>(fault);
        // Take an exception on:
        // * A Synchronous External abort occurs on translation table walk
        // * A stage 2 fault occurs on a stage 1 walk
        // * A GPC Exception (FEAT_RME)
        // * A GPF from ATS1E{1,0}* when executed from EL1 and HCR_EL2.GPF == '1' (FEAT_RME)
        if (<a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault) ||
              (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; fault.s2fs1walk) ||
               (IsFeatureImplemented(FEAT_RME) &amp;&amp; fault.gpcf.gpf != <a link="enum_GPCF_None" file="shared_pseudocode.xml">GPCF_None</a> &amp;&amp; (
                <a link="func_ReportAsGPCException_1" file="shared_pseudocode.xml">ReportAsGPCException</a>(fault) ||
                (<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().GPF == '1' &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; el IN {<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>} &amp;&amp;
                 is_ATS1Ex)
                ))) then
            if IsFeatureImplemented(FEAT_D128) then
                PAR_EL1()       = ARBITRARY : bits(128);
            else
                PAR_EL1()[63:0] = ARBITRARY : bits(64);
            end;
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(addrdesc.fault);
        end;
    end;

    <a link="func_AArch64_EncodePAR_4" file="shared_pseudocode.xml">AArch64_EncodePAR</a>(regime, el, is_ATS1Ex, addrdesc);
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/at/AArch64_EncodePAR" mylink="aarch64.functions.at.AArch64_EncodePAR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_EncodePAR()
// ===================
// Encode PAR register with result of translation.

func <anchor link="func_AArch64_EncodePAR_4">AArch64_EncodePAR</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, el : bits(2), is_ATS1Ex : boolean,
                       addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>)
begin
    let paspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a> = addrdesc.paddress.paspace;
    if IsFeatureImplemented(FEAT_D128) then
        PAR_EL1() = Zeros{128};
        if <a link="func_AArch64_isPARFormatD128_2" file="shared_pseudocode.xml">AArch64_isPARFormatD128</a>(regime, is_ATS1Ex) then
            PAR_EL1().D128 = '1';
        else
            PAR_EL1().D128 = '0';
        end;
    else
        PAR_EL1()[63:0] = Zeros{64};
    end;

    if !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(addrdesc) then
        PAR_EL1().F = '0';
        if IsFeatureImplemented(FEAT_RME) then
            if regime == <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> then
                case paspace of
                    when <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> =&gt;     PAR_EL1().[NSE,NS] = '00';
                    when <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> =&gt;  PAR_EL1().[NSE,NS] = '01';
                    when <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a> =&gt;       PAR_EL1().[NSE,NS] = '10';
                    when <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a> =&gt;      PAR_EL1().[NSE,NS] = '11';
                end;

            elsif <a link="func_SecurityStateForRegime_1" file="shared_pseudocode.xml">SecurityStateForRegime</a>(regime) == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>  then
                PAR_EL1().NSE = ARBITRARY : bit;
                PAR_EL1().NS = if paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> then '0' else '1';

            elsif <a link="func_SecurityStateForRegime_1" file="shared_pseudocode.xml">SecurityStateForRegime</a>(regime) == <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> then
                if regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; is_ATS1Ex then
                    PAR_EL1().NSE = ARBITRARY : bit;
                    PAR_EL1().NS  = ARBITRARY : bit;
                else
                    PAR_EL1().NSE = ARBITRARY : bit;
                    PAR_EL1().NS  = if paspace == <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a> then '0' else '1';
                end;

            else
                PAR_EL1().NSE = ARBITRARY : bit;
                PAR_EL1().NS  = ARBITRARY : bit;
            end;
        else
            PAR_EL1()[11] = '1'; // RES1
            if <a link="func_SecurityStateForRegime_1" file="shared_pseudocode.xml">SecurityStateForRegime</a>(regime) == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
                PAR_EL1().NS = if paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> then '0' else '1';
            else
                PAR_EL1().NS = ARBITRARY : bit;
            end;
        end;
        PAR_EL1().SH   = <a link="func_ReportedPARShareability_1" file="shared_pseudocode.xml">ReportedPARShareability</a>(<a link="func_PAREncodeShareability_1" file="shared_pseudocode.xml">PAREncodeShareability</a>(addrdesc.memattrs));
        if IsFeatureImplemented(FEAT_D128) &amp;&amp; PAR_EL1().D128 == '1' then
            PAR_EL1()[119:76] = addrdesc.paddress.address[55:12];
        else
            PAR_EL1()[55:12] = addrdesc.paddress.address[55:12];
        end;
        PAR_EL1().ATTR = <a link="func_ReportedPARAttrs_1" file="shared_pseudocode.xml">ReportedPARAttrs</a>(<a link="func_EncodePARAttrs_1" file="shared_pseudocode.xml">EncodePARAttrs</a>(addrdesc.memattrs));
        PAR_EL1()[10] = ImpDefBit(&quot;Non-Faulting PAR&quot;);
    else
        PAR_EL1().F   = '1';
        PAR_EL1().DirtyBit    = if addrdesc.fault.dirtybit then '1' else '0';
        PAR_EL1().Overlay     = if addrdesc.fault.overlay then '1' else '0';
        PAR_EL1().TopLevel    = if addrdesc.fault.toplevel then '1' else '0';
        PAR_EL1().AssuredOnly = if addrdesc.fault.assuredonly then '1' else '0';
        PAR_EL1().FST = <a link="func_AArch64_PARFaultStatus_1" file="shared_pseudocode.xml">AArch64_PARFaultStatus</a>(addrdesc.fault);
        PAR_EL1().PTW = if addrdesc.fault.s2fs1walk then '1' else '0';
        PAR_EL1().S   = if addrdesc.fault.secondstage then '1' else '0';
        PAR_EL1()[11] = '1'; // RES1
        PAR_EL1()[63:48] = ImpDefBits{16}(&quot;Faulting PAR&quot;);
    end;
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/at/AArch64_PARFaultStatus" mylink="aarch64.functions.at.AArch64_PARFaultStatus" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_PARFaultStatus()
// ========================
// Fault status field decoding of 64-bit PAR.

func <anchor link="func_AArch64_PARFaultStatus_1">AArch64_PARFaultStatus</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; bits(6)
begin
    var fst : bits(6);

    if fault.statuscode == <a link="enum_Fault_Domain" file="shared_pseudocode.xml">Fault_Domain</a> then
        // Report Domain fault
        assert fault.level IN {1,2};
        fst[1:0] = if fault.level == 1 then '01' else '10';
        fst[5:2] = '1111';
    else
        fst = <a link="func_EncodeLDFSC_2" file="shared_pseudocode.xml">EncodeLDFSC</a>(fault.statuscode, fault.level);
    end;
    return fst;
end;</pstext></ps>
    <ps name="aarch64/functions/at/AArch64_isPARFormatD128" mylink="aarch64.functions.at.AArch64_isPARFormatD128" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_isPARFormatD128()
// =========================
// Check if last stage of translation uses VMSAv9-128.
// Last stage of translation is stage 2 if enabled, else it is stage 1.

func <anchor link="func_AArch64_isPARFormatD128_2">AArch64_isPARFormatD128</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, is_ATS1Ex : boolean) =&gt; boolean
begin
    var isPARFormatD128 : boolean;
    // Regime_EL2 does not support VMSAv9-128
    if regime == <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> || !IsFeatureImplemented(FEAT_D128) then
        isPARFormatD128 = FALSE;
    else
        isPARFormatD128 = FALSE;
        case regime of
            when <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> =&gt;
                isPARFormatD128 = TCR_EL3().D128 == '1';
            when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt;
                isPARFormatD128 = <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() &amp;&amp; TCR2_EL2().D128 == '1';
            when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt;
                if is_ATS1Ex || !<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() || HCR_EL2().[VM,DC] == '00' then
                    isPARFormatD128 = <a link="func_IsTCR2EL1Enabled_0" file="shared_pseudocode.xml">IsTCR2EL1Enabled</a>() &amp;&amp; TCR2_EL1().D128 == '1';
                else
                    isPARFormatD128 = VTCR_EL2().D128 == '1';
                end;
        end;
    end;

    return isPARFormatD128;
end;</pstext></ps>
    <ps name="aarch64/functions/at/GetPAR_EL1_D128" mylink="aarch64.functions.at.GetPAR_EL1_D128" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetPAR_EL1_D128()
// =================
// Query the PAR_EL1.D128 field

func <anchor link="func_GetPAR_EL1_D128_0">GetPAR_EL1_D128</anchor>() =&gt; bit
begin
    return if IsFeatureImplemented(FEAT_D128) then PAR_EL1().D128 else '0';
end;</pstext></ps>
    <ps name="aarch64/functions/at/GetPAR_EL1_F" mylink="aarch64.functions.at.GetPAR_EL1_F" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetPAR_EL1_F()
// ==============
// Query the PAR_EL1.F field.

func <anchor link="func_GetPAR_EL1_F_0">GetPAR_EL1_F</anchor>() =&gt; bit
begin
    var F : bit;

    F = PAR_EL1().F;
    return F;
end;</pstext></ps>
    <ps name="aarch64/functions/barrierop/MemBarrierOp" mylink="aarch64.functions.barrierop.MemBarrierOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemBarrierOp
// ============
// Memory barrier instruction types.

type <anchor link="type_MemBarrierOp">MemBarrierOp</anchor> of enumeration {
                                  <anchor link="enum_MemBarrierOp_DSB">MemBarrierOp_DSB</anchor>,     // Data Synchronization Barrier
                                  <anchor link="enum_MemBarrierOp_DMB">MemBarrierOp_DMB</anchor>,     // Data Memory Barrier
                                  <anchor link="enum_MemBarrierOp_ISB">MemBarrierOp_ISB</anchor>,     // Instruction Synchronization Barrier
                                  <anchor link="enum_MemBarrierOp_SSBB">MemBarrierOp_SSBB</anchor>,    // Speculative Synchronization Barrier to VA
                                  <anchor link="enum_MemBarrierOp_PSSBB">MemBarrierOp_PSSBB</anchor>,   // Speculative Synchronization Barrier to PA
                                  <anchor link="enum_MemBarrierOp_SB">MemBarrierOp_SB</anchor>       // Speculation Barrier
                           };</pstext></ps>
    <ps name="aarch64/functions/bfxpreferred/BFXPreferred" mylink="aarch64.functions.bfxpreferred.BFXPreferred" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFXPreferred()
// ==============
//
// Return TRUE if UBFX or SBFX is the preferred disassembly of a
// UBFM or SBFM bitfield instruction. Must exclude more specific
// aliases UBFIZ, SBFIZ, UXT[BH], SXT[BHW], LSL, LSR and ASR.

func <anchor link="func_BFXPreferred_4">BFXPreferred</anchor>(sf : bit, uns : bit, imms : bits(6), immr : bits(6)) =&gt; boolean
begin

    // must not match UBFIZ/SBFIX alias
    if UInt(imms) &lt; UInt(immr) then
        return FALSE;
    end;

    // must not match LSR/ASR/LSL alias (imms == 31 or 63)
    if imms == sf::'11111' then
        return FALSE;
    end;

    // must not match UXTx/SXTx alias
    if immr == '000000' then
        // must not match 32-bit UXT[BH] or SXT[BH]
        if sf == '0' &amp;&amp; imms IN {'000111', '001111'} then
            return FALSE;
        end;
        // must not match 64-bit SXT[BHW]
        if sf::uns == '10' &amp;&amp; imms IN {'000111', '001111', '011111'} then
            return FALSE;
        end;
    end;

    // must be UBFX/SBFX alias
    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/bitmasks/AltDecodeBitMasks" mylink="aarch64.functions.bitmasks.AltDecodeBitMasks" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AltDecodeBitMasks()
// ===================
// Alternative but logically equivalent implementation of DecodeBitMasks() that
// uses simpler primitives to compute tmask and wmask.

func <anchor link="func_AltDecodeBitMasks_5">AltDecodeBitMasks</anchor>{M}(immN : bit, imms : bits(6), immr : bits(6),
                          immediate : boolean) =&gt; (bits(M), bits(M))
begin
    var tmask, wmask : bits(64);
    var tmask_and, wmask_and : bits(6);
    var tmask_or, wmask_or : bits(6);
    var levels : bits(6);

    // Compute log2 of element size
    // 2^len must be in range [2, M]
    if immN::NOT(imms) == '000000x' then Undefined(); end;
    let len : integer{} = HighestSetBitNZ(immN::NOT(imms));
    assert 2 &lt;= (2^len) &amp;&amp; (2^len) &lt;= M;

    // Determine s, r and s - r parameters
    levels = ZeroExtend{6}(Ones{len});

    // For logical immediates an all-ones value of s is reserved
    // since it would generate a useless all-ones result (many times)
    if immediate &amp;&amp; (imms AND levels) == levels then Undefined(); end;

    let s : integer{} = UInt(imms AND levels);
    let r : integer{} = UInt(immr AND levels);
    let diff : integer{} = s - r;    // 6-bit subtract with borrow

    // Compute &quot;top mask&quot;
    tmask_and = diff[5:0] OR NOT(levels);
    tmask_or  = diff[5:0] AND levels;

    tmask = Ones{64};
    tmask = ((tmask
              AND Replicate{64, 2}(Replicate{1}(tmask_and[0]) :: Ones{1}))
               OR  Replicate{64, 2}(Zeros{1} :: Replicate{1}(tmask_or[0])));
    // optimization of first step:
    // tmask = Replicate{64}(tmask_and[0] :: '1');
    tmask = ((tmask
              AND Replicate{64, 4}(Replicate{2}(tmask_and[1]) :: Ones{2}))
               OR  Replicate{64, 4}(Zeros{2} :: Replicate{2}(tmask_or[1])));
    tmask = ((tmask
              AND Replicate{64, 8}(Replicate{4}(tmask_and[2]) :: Ones{4}))
               OR  Replicate{64, 8}(Zeros{4} :: Replicate{4}(tmask_or[2])));
    tmask = ((tmask
              AND Replicate{64, 16}(Replicate{8}(tmask_and[3]) :: Ones{8}))
               OR  Replicate{64, 16}(Zeros{8} :: Replicate{8}(tmask_or[3])));
    tmask = ((tmask
              AND Replicate{64, 32}(Replicate{16}(tmask_and[4]) :: Ones{16}))
               OR  Replicate{64, 32}(Zeros{16} :: Replicate{16}(tmask_or[4])));
    tmask = ((tmask
              AND Replicate{64, 64}(Replicate{32}(tmask_and[5]) :: Ones{32}))
               OR  Replicate{64, 64}(Zeros{32} :: Replicate{32}(tmask_or[5])));

    // Compute &quot;wraparound mask&quot;
    wmask_and = immr OR NOT(levels);
    wmask_or  = immr AND levels;

    wmask = Zeros{64};
    wmask = ((wmask
              AND Replicate{64, 2}(Ones{1} :: Replicate{1}(wmask_and[0])))
               OR  Replicate{64, 2}(Replicate{1}(wmask_or[0]) :: Zeros{1}));
    // wmask = Replicate{64}(wmask_or[0] :: '0');
    wmask = ((wmask
              AND Replicate{64, 4}(Ones{2} :: Replicate{2}(wmask_and[1])))
               OR  Replicate{64, 4}(Replicate{2}(wmask_or[1]) :: Zeros{2}));
    wmask = ((wmask
              AND Replicate{64, 8}(Ones{4} :: Replicate{4}(wmask_and[2])))
               OR  Replicate{64, 8}(Replicate{4}(wmask_or[2]) :: Zeros{4}));
    wmask = ((wmask
              AND Replicate{64, 16}(Ones{8} :: Replicate{8}(wmask_and[3])))
               OR  Replicate{64, 16}(Replicate{8}(wmask_or[3]) :: Zeros{8}));
    wmask = ((wmask
              AND Replicate{64, 32}(Ones{16} :: Replicate{16}(wmask_and[4])))
               OR  Replicate{64, 32}(Replicate{16}(wmask_or[4]) :: Zeros{16}));
    wmask = ((wmask
              AND Replicate{64, 64}(Ones{32} :: Replicate{32}(wmask_and[5])))
               OR  Replicate{64, 64}(Replicate{32}(wmask_or[5]) :: Zeros{32}));

    if diff[6] != '0' then // borrow from s - r
        wmask = wmask AND tmask;
    else
        wmask = wmask OR tmask;
    end;

    return (wmask[M-1:0], tmask[M-1:0]);
end;</pstext></ps>
    <ps name="aarch64/functions/bitmasks/DecodeBitMasks" mylink="aarch64.functions.bitmasks.DecodeBitMasks" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodeBitMasks()
// ================
// Decode AArch64 bitfield and logical immediate masks which use a similar encoding structure

func <anchor link="func_DecodeBitMasks_5">DecodeBitMasks</anchor>{M}(immN : bit, imms : bits(6), immr : bits(6),
                       immediate : boolean) =&gt; (bits(M), bits(M))
begin
    var levels : bits(6);

    // Compute log2 of element size
    // 2^len must be in range [2, M]
    if immN::NOT(imms) == '000000x' then Undefined(); end;
    let len : integer{} = HighestSetBitNZ(immN::NOT(imms));
    assert 2 &lt;= (2^len) &amp;&amp; (2^len) &lt;= M;

    // Determine s, r and s - r parameters
    levels = ZeroExtend{6}(Ones{len});

    // For logical immediates an all-ones value of s is reserved
    // since it would generate a useless all-ones result (many times)
    if immediate &amp;&amp; (imms AND levels) == levels then Undefined(); end;

    let s : integer{} = UInt(imms AND levels);
    let r : integer{} = UInt(immr AND levels);
    let diff : integer{} = s - r;    // 6-bit subtract with borrow

    let esize : integer{} = 1 &lt;&lt; len;
    let d : integer{}     = UInt(diff[len-1:0]);
    let welem : bits(esize) = ZeroExtend{}(Ones{s + 1});
    let telem : bits(esize) = ZeroExtend{}(Ones{d + 1});
    let wmask : bits(M) = Replicate{}(ROR(welem, r));
    let tmask : bits(M) = Replicate{}(telem);
    return (wmask, tmask);
end;</pstext></ps>
    <ps name="aarch64/functions/cache/AArch64_DataMemZero" mylink="aarch64.functions.cache.AArch64_DataMemZero" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_DataMemZero()
// =====================
// Write Zero to data memory.

func <anchor link="func_AArch64_DataMemZero_4">AArch64_DataMemZero</anchor>(regval : bits(64), vaddress : bits(64),
                         accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>, size : integer)
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = accdesc_in;

    // If the instruction targets tags as a payload, confer with system register configuration
    // which may override this.
    if accdesc.tagaccess then
        accdesc.tagaccess = <a link="func_IsMTEEnabled_1" file="shared_pseudocode.xml">IsMTEEnabled</a>(accdesc.el);
    end;

    // If the instruction encoding permits tag checking, confer with system register configuration
    // which may override this.
    if accdesc.tagchecked then
        accdesc.tagchecked = <a link="func_AArch64_AccessIsTagChecked_2" file="shared_pseudocode.xml">AArch64_AccessIsTagChecked</a>(vaddress, accdesc);
    end;

    let aligned : boolean = TRUE;
    var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_AArch64_TranslateAddress_4" file="shared_pseudocode.xml">AArch64_TranslateAddress</a>(vaddress,
                                                                   accdesc, aligned, size);

    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        if !<a link="func_IsDebugException_1" file="shared_pseudocode.xml">IsDebugException</a>(memaddrdesc.fault) then
            memaddrdesc.fault.vaddress = regval;
        end;
        <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(memaddrdesc.fault);
    end;

    for i = 0 to size-1 do
        if accdesc.tagchecked then
            let ltag : bits(4)      = <a link="func_AArch64_LogicalAddressTag_1" file="shared_pseudocode.xml">AArch64_LogicalAddressTag</a>(vaddress);
            let bytes : integer = 1;
            let readcheck : boolean = FALSE;
            var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AArch64_CheckTag_5" file="shared_pseudocode.xml">AArch64_CheckTag</a>(memaddrdesc, accdesc, readcheck,
                                                       bytes, ltag);
            if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
                if ImpDefBool(
                      &quot;DC_ZVA tag fault reported with lowest faulting address&quot;) then
                    <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
                else
                    fault.vaddress = regval;
                    <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
                end;
            end;
        end;
        let memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a> = <a link="func_PhysMemWrite_4" file="shared_pseudocode.xml">PhysMemWrite</a>{8}(memaddrdesc, accdesc, Zeros{8});
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            <a link="func_HandleExternalWriteAbort_4" file="shared_pseudocode.xml">HandleExternalWriteAbort</a>(memstatus, memaddrdesc, 1, accdesc);
        end;

        memaddrdesc.paddress.address = memaddrdesc.paddress.address + 1;
    end;
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/cache/AArch64_WriteTagMem" mylink="aarch64.functions.cache.AArch64_WriteTagMem" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_WriteTagMem()
// =====================
// Write to tag memory.

func <anchor link="func_AArch64_WriteTagMem_4">AArch64_WriteTagMem</anchor>(regval : bits(64), cachetype : <a link="type_CacheType" file="shared_pseudocode.xml">CacheType</a>,
                         accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>, size : integer)
begin
    assert accdesc_in.tagaccess &amp;&amp; !accdesc_in.tagchecked;

    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = accdesc_in;
    let vaddress : bits(64) = AlignDownSize{64}(regval, size as integer{16..2048});
    let count : integer     = size &gt;&gt; <a link="global_LOG2_TAG_GRANULE" file="shared_pseudocode.xml">LOG2_TAG_GRANULE</a>;
    let tag : bits(4) = <a link="func_AArch64_AllocationTagFromAddress_1" file="shared_pseudocode.xml">AArch64_AllocationTagFromAddress</a>(vaddress);
    let aligned : boolean   = IsAlignedSize{64}(vaddress, <a link="global_TAG_GRANULE" file="shared_pseudocode.xml">TAG_GRANULE</a>);
    assert aligned;

    accdesc.tagaccess = <a link="func_IsMTEEnabled_1" file="shared_pseudocode.xml">IsMTEEnabled</a>(accdesc.el);

    var (memtagtype, memaddrdesc) = <a link="func_AArch64_TranslateTagAddress_4" file="shared_pseudocode.xml">AArch64_TranslateTagAddress</a>(vaddress, accdesc, aligned, size);

    // Check for aborts or debug exceptions
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        if <a link="func_IsDebugException_1" file="shared_pseudocode.xml">IsDebugException</a>(memaddrdesc.fault) then
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(memaddrdesc.fault);
        else
            memaddrdesc.fault.vaddress = regval;
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(memaddrdesc.fault);
        end;
    end;

    if !accdesc.tagaccess || memtagtype != <a link="enum_MemTag_AllocationTagged" file="shared_pseudocode.xml">MemTag_AllocationTagged</a> then
        return;
    end;

    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;

    for i = 0 to count-1 do
        memstatus = <a link="func_PhysMemTagWrite_3" file="shared_pseudocode.xml">PhysMemTagWrite</a>(memaddrdesc, accdesc, tag);
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            <a link="func_HandleExternalWriteAbort_4" file="shared_pseudocode.xml">HandleExternalWriteAbort</a>(memstatus, memaddrdesc, 1, accdesc);
        end;

        memaddrdesc.paddress.address = memaddrdesc.paddress.address + <a link="global_TAG_GRANULE" file="shared_pseudocode.xml">TAG_GRANULE</a>;
        memaddrdesc.vaddress         = memaddrdesc.vaddress + <a link="global_TAG_GRANULE" file="shared_pseudocode.xml">TAG_GRANULE</a>;
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/compareop/CompareOp" mylink="aarch64.functions.compareop.CompareOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CompareOp
// =========
// Vector compare instruction types.

type <anchor link="type_CompareOp">CompareOp</anchor> of enumeration {<anchor link="enum_CompareOp_GT">CompareOp_GT</anchor>, <anchor link="enum_CompareOp_GE">CompareOp_GE</anchor>, <anchor link="enum_CompareOp_EQ">CompareOp_EQ</anchor>,
                               <anchor link="enum_CompareOp_LE">CompareOp_LE</anchor>, <anchor link="enum_CompareOp_LT">CompareOp_LT</anchor>};</pstext></ps>
    <ps name="aarch64/functions/countop/CountOp" mylink="aarch64.functions.countop.CountOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CountOp
// =======
// Bit counting instruction types.

type <anchor link="type_CountOp">CountOp</anchor> of enumeration {<anchor link="enum_CountOp_CLZ">CountOp_CLZ</anchor>, <anchor link="enum_CountOp_CLS">CountOp_CLS</anchor>, <anchor link="enum_CountOp_CNT">CountOp_CNT</anchor>};</pstext></ps>
    <ps name="aarch64/functions/cpa/EffectiveCPTA" mylink="aarch64.functions.cpa.EffectiveCPTA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveCPTA()
// ===============
// Returns the CPTA bit applied to Checked Pointer Arithmetic for Addition in the given EL.

func <anchor link="func_EffectiveCPTA_1">EffectiveCPTA</anchor>(el : bits(2)) =&gt; bit
begin
    if !IsFeatureImplemented(FEAT_CPA2) then
        return '0';
    end;

    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then
        return '0';
    end;

    var cpta : bits(1);
    let regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a> = <a link="func_TranslationRegime_1" file="shared_pseudocode.xml">TranslationRegime</a>(el);

    case regime of
        when <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> =&gt;
            cpta = SCTLR2_EL3().CPTA;
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> =&gt;
            if <a link="func_IsSCTLR2EL2Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL2Enabled</a>() then
                cpta = SCTLR2_EL2().CPTA;
            else
                cpta = '0';
            end;
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt;
            if <a link="func_IsSCTLR2EL2Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL2Enabled</a>() then
                cpta = if el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then SCTLR2_EL2().CPTA0 else SCTLR2_EL2().CPTA;
            else
                cpta = '0';
            end;
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt;
            if <a link="func_IsSCTLR2EL1Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL1Enabled</a>() then
                cpta = if el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then SCTLR2_EL1().CPTA0 else SCTLR2_EL1().CPTA;
            else
                cpta = '0';
            end;
        otherwise =&gt;
            unreachable;
    end;

    return cpta;
end;</pstext></ps>
    <ps name="aarch64/functions/cpa/EffectiveCPTM" mylink="aarch64.functions.cpa.EffectiveCPTM" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveCPTM()
// ===============
// Returns the CPTM bit applied to Checked Pointer Arithmetic for Multiplication in the given EL.

func <anchor link="func_EffectiveCPTM_1">EffectiveCPTM</anchor>(el : bits(2)) =&gt; bit
begin
    if !IsFeatureImplemented(FEAT_CPA2) then
        return '0';
    end;

    if <a link="func_EffectiveCPTA_1" file="shared_pseudocode.xml">EffectiveCPTA</a>(el) == '0' then
        return '0';
    end;

    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then
        return '0';
    end;

    var cptm : bits(1);
    let regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a> = <a link="func_TranslationRegime_1" file="shared_pseudocode.xml">TranslationRegime</a>(el);

    case regime of
        when <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> =&gt;
            cptm = SCTLR2_EL3().CPTM;
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> =&gt;
            if <a link="func_IsSCTLR2EL2Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL2Enabled</a>() then
                cptm = SCTLR2_EL2().CPTM;
            else
                cptm = '0';
            end;
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt;
            if <a link="func_IsSCTLR2EL2Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL2Enabled</a>() then
                cptm = if el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then SCTLR2_EL2().CPTM0 else SCTLR2_EL2().CPTM;
            else
                cptm = '0';
            end;
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt;
            if <a link="func_IsSCTLR2EL1Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL1Enabled</a>() then
                cptm = if el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then SCTLR2_EL1().CPTM0 else SCTLR2_EL1().CPTM;
            else
                cptm = '0';
            end;
        otherwise =&gt;
            unreachable;
    end;

    return cptm;
end;</pstext></ps>
    <ps name="aarch64/functions/cpa/PointerAddCheck" mylink="aarch64.functions.cpa.PointerAddCheck" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PointerAddCheck()
// =================
// Apply Checked Pointer Arithmetic for addition.

func <anchor link="func_PointerAddCheck_2">PointerAddCheck</anchor>(result : bits(64), base : bits(64)) =&gt; bits(64)
begin
    return <a link="func_PointerCheckAtEL_4" file="shared_pseudocode.xml">PointerCheckAtEL</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL, result, base, FALSE);
end;</pstext></ps>
    <ps name="aarch64/functions/cpa/PointerAddCheckAtEL" mylink="aarch64.functions.cpa.PointerAddCheckAtEL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PointerAddCheckAtEL()
// =====================
// Apply Checked Pointer Arithmetic for addition at the specified EL.

func <anchor link="func_PointerAddCheckAtEL_3">PointerAddCheckAtEL</anchor>(el : bits(2), result : bits(64), base : bits(64)) =&gt; bits(64)
begin
    return <a link="func_PointerCheckAtEL_4" file="shared_pseudocode.xml">PointerCheckAtEL</a>(el, result, base, FALSE);
end;</pstext></ps>
    <ps name="aarch64/functions/cpa/PointerCheckAtEL" mylink="aarch64.functions.cpa.PointerCheckAtEL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PointerCheckAtEL()
// ==================
// Apply Checked Pointer Arithmetic at the specified EL.

func <anchor link="func_PointerCheckAtEL_4">PointerCheckAtEL</anchor>(el : bits(2), result : bits(64), base : bits(64),
                      cptm_detected : boolean) =&gt; bits(64)
begin
    var rv : bits(64)  = result;

    let previous_detection : boolean = (base[55] != base[54]);
    let cpta_detected : boolean = (result[63:56] != base[63:56] || previous_detection);

    if ((cpta_detected &amp;&amp; <a link="func_EffectiveCPTA_1" file="shared_pseudocode.xml">EffectiveCPTA</a>(el) == '1') ||
          (cptm_detected &amp;&amp; <a link="func_EffectiveCPTM_1" file="shared_pseudocode.xml">EffectiveCPTM</a>(el) == '1')) then
        rv[63:55] = base[63:55];
        rv[54] = NOT(rv[55]);
    end;

    return rv;
end;</pstext></ps>
    <ps name="aarch64/functions/cpa/PointerMultiplyAddCheck" mylink="aarch64.functions.cpa.PointerMultiplyAddCheck" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PointerMultiplyAddCheck()
// =========================
// Apply Checked Pointer Arithmetic for multiplication.

func <anchor link="func_PointerMultiplyAddCheck_3">PointerMultiplyAddCheck</anchor>(result : bits(64), base : bits(64),
                             cptm_detected : boolean) =&gt; bits(64)
begin
    return <a link="func_PointerCheckAtEL_4" file="shared_pseudocode.xml">PointerCheckAtEL</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL, result, base, cptm_detected);
end;</pstext></ps>
    <ps name="aarch64/functions/d128/IsD128Enabled" mylink="aarch64.functions.d128.IsD128Enabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsD128Enabled()
// ===============
// Returns true if 128-bit page descriptor is enabled

func <anchor link="func_IsD128Enabled_1">IsD128Enabled</anchor>(el : bits(2)) =&gt; boolean
begin
    var d128enabled : boolean;
    if IsFeatureImplemented(FEAT_D128) then
        case el of
            when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
                if !<a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
                    d128enabled = <a link="func_IsTCR2EL1Enabled_0" file="shared_pseudocode.xml">IsTCR2EL1Enabled</a>() &amp;&amp; TCR2_EL1().D128 == '1';
                else
                    d128enabled = <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() &amp;&amp; TCR2_EL2().D128 == '1';
                end;
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
                d128enabled = <a link="func_IsTCR2EL1Enabled_0" file="shared_pseudocode.xml">IsTCR2EL1Enabled</a>() &amp;&amp; TCR2_EL1().D128 == '1';
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
                d128enabled = <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() &amp;&amp; <a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() &amp;&amp; TCR2_EL2().D128 == '1';
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
                d128enabled = TCR_EL3().D128 == '1';
        end;
    else
        d128enabled = FALSE;
    end;

    return d128enabled;
end;</pstext></ps>
    <ps name="aarch64/functions/dc/AArch64_CanTrapDC" mylink="aarch64.functions.dc.AArch64_CanTrapDC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CanTrapDC()
// ===================
// Determines whether the execution of the DC instruction can be trapped.

func <anchor link="func_AArch64_CanTrapDC_3">AArch64_CanTrapDC</anchor>(cachetype : <a link="type_CacheType" file="shared_pseudocode.xml">CacheType</a>, cacheop : <a link="type_CacheOp" file="shared_pseudocode.xml">CacheOp</a>, opscope : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a>) =&gt; boolean
begin
    return (!<a link="func_AArch64_TreatDCAsNOP_3" file="shared_pseudocode.xml">AArch64_TreatDCAsNOP</a>(cachetype, cacheop, opscope) || ImpDefBool(
            &quot;When DC is treated as NOP, data cache maintenance operations are trapped&quot;));
end;</pstext></ps>
    <ps name="aarch64/functions/dc/AArch64_DC" mylink="aarch64.functions.dc.AArch64_DC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_DC()
// ============
// Perform Data Cache Operation.

func <anchor link="func_AArch64_DC_4">AArch64_DC</anchor>(regval : bits(64), cachetype : <a link="type_CacheType" file="shared_pseudocode.xml">CacheType</a>,
                cacheop : <a link="type_CacheOp" file="shared_pseudocode.xml">CacheOp</a>, opscope_in : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a>)
begin
    var opscope : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a> = opscope_in;
    var cache : <a link="type_CacheRecord" file="shared_pseudocode.xml">CacheRecord</a>;

    cache.acctype   = <a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>;
    cache.cachetype = cachetype;
    cache.cacheop   = cacheop;
    cache.opscope   = opscope;

    if opscope == <a link="enum_CacheOpScope_SetWay" file="shared_pseudocode.xml">CacheOpScope_SetWay</a> then
        let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
        cache.cpas = <a link="func_CPASAtSecurityState_1" file="shared_pseudocode.xml">CPASAtSecurityState</a>(ss);
        cache.shareability = <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a>;
        cache.(setnum, waynum, level) = <a link="func_DecodeSW_2" file="shared_pseudocode.xml">DecodeSW</a>(regval, cachetype);
        if (cacheop == <a link="enum_CacheOp_Invalidate" file="shared_pseudocode.xml">CacheOp_Invalidate</a> &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
          (HCR_EL2().SWIO == '1' || HCR_EL2().[DC,VM] != '00')) then
            cache.cacheop = <a link="enum_CacheOp_CleanInvalidate" file="shared_pseudocode.xml">CacheOp_CleanInvalidate</a>;
        end;

        CACHE_OP(cache);
        return;
    end;

    if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} then
            cache.is_vmid_valid = TRUE;
            cache.vmid          = <a link="func_VMID_0" file="shared_pseudocode.xml">VMID</a>();
        else
            cache.is_vmid_valid = FALSE;
        end;
    else
        cache.is_vmid_valid = FALSE;
    end;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        cache.is_asid_valid = TRUE;
        cache.asid          = <a link="func_ASID_0" file="shared_pseudocode.xml">ASID</a>();
    else
        cache.is_asid_valid = FALSE;
    end;

    if (opscope == <a link="enum_CacheOpScope_PoPS" file="shared_pseudocode.xml">CacheOpScope_PoPS</a> &amp;&amp;
          ImpDefBool(&quot;Memory system does not support PoPS&quot;)) then
        opscope = <a link="enum_CacheOpScope_PoC" file="shared_pseudocode.xml">CacheOpScope_PoC</a>;
    end;
    if (opscope == <a link="enum_CacheOpScope_PoDP" file="shared_pseudocode.xml">CacheOpScope_PoDP</a> &amp;&amp;
          ImpDefBool(&quot;Memory system does not support PoDP&quot;)) then
        opscope = <a link="enum_CacheOpScope_PoP" file="shared_pseudocode.xml">CacheOpScope_PoP</a>;
    end;
    if (opscope == <a link="enum_CacheOpScope_PoP" file="shared_pseudocode.xml">CacheOpScope_PoP</a> &amp;&amp;
          ImpDefBool(&quot;Memory system does not support PoP&quot;)) then
        opscope = <a link="enum_CacheOpScope_PoC" file="shared_pseudocode.xml">CacheOpScope_PoC</a>;
    end;
    var vaddress : bits(64) = regval;

    var size : integer = 0;        // by default no watchpoint address
    if cacheop == <a link="enum_CacheOp_Invalidate" file="shared_pseudocode.xml">CacheOp_Invalidate</a> then
        size = <a link="func_DataCacheWatchpointSize_0" file="shared_pseudocode.xml">DataCacheWatchpointSize</a>();
        vaddress = AlignDownSize{64}(regval, size as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>);
    end;

    if opscope == <a link="enum_CacheOpScope_PoE" file="shared_pseudocode.xml">CacheOpScope_PoE</a> then
        cache.shareability     = <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
        cache.paddress.address = regval[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0];
        let nse2 : bit = if IsFeatureImplemented(FEAT_RME_GDI) then regval[61] else '0';
        cache.paddress.paspace = <a link="func_DecodePASpace_3" file="shared_pseudocode.xml">DecodePASpace</a>(nse2, regval[62], regval[63]);
        cache.cpas             = <a link="func_CPASAtPAS_1" file="shared_pseudocode.xml">CPASAtPAS</a>(cache.paddress.paspace);

        // If a Reserved encoding is selected, the instruction is permitted to be treated as a NOP.
        if cache.paddress.paspace != <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a> then
            <a link="func_ExecuteAsNOP_0" file="shared_pseudocode.xml">ExecuteAsNOP</a>();
        end;

        if ImpDefBool(&quot;Apply granule protection check on DC to PoE&quot;) then
            var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
            let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescDC_1" file="shared_pseudocode.xml">CreateAccDescDC</a>(cache);
            memaddrdesc.paddress     = cache.paddress;
            memaddrdesc.fault.gpcf   = <a link="func_GranuleProtectionCheck_2" file="shared_pseudocode.xml">GranuleProtectionCheck</a>(memaddrdesc, accdesc);

            if memaddrdesc.fault.gpcf.gpf != <a link="enum_GPCF_None" file="shared_pseudocode.xml">GPCF_None</a> then
                memaddrdesc.fault.statuscode = <a link="enum_Fault_GPCFOnOutput" file="shared_pseudocode.xml">Fault_GPCFOnOutput</a>;
                memaddrdesc.fault.paddress   = memaddrdesc.paddress;
                memaddrdesc.fault.vaddress   = ARBITRARY : bits(64);
                <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(memaddrdesc.fault);
            end;
        end;
    elsif opscope == <a link="enum_CacheOpScope_PoPA" file="shared_pseudocode.xml">CacheOpScope_PoPA</a> then
        cache.shareability = <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
        cache.paddress.address = regval[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0];
        let nse2 : bit = if IsFeatureImplemented(FEAT_RME_GDI) then regval[61] else '0';
        cache.paddress.paspace = <a link="func_DecodePASpace_3" file="shared_pseudocode.xml">DecodePASpace</a>(nse2, regval[62], regval[63]);

        // If {NSE2, NSE, NS} is reserved, then no cache entries are required
        // to be cleaned or invalidated.
        if cache.paddress.paspace IN {<a link="enum_PAS_NA6" file="shared_pseudocode.xml">PAS_NA6</a>, <a link="enum_PAS_NA7" file="shared_pseudocode.xml">PAS_NA7</a>} then
            <a link="func_ExecuteAsNOP_0" file="shared_pseudocode.xml">ExecuteAsNOP</a>();
        end;
        cache.cpas = <a link="func_CPASAtPAS_1" file="shared_pseudocode.xml">CPASAtPAS</a>(cache.paddress.paspace);
    else
        cache.vaddress  = vaddress;
        let aligned : boolean = TRUE;
        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescDC_1" file="shared_pseudocode.xml">CreateAccDescDC</a>(cache);
        var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_AArch64_TranslateAddress_4" file="shared_pseudocode.xml">AArch64_TranslateAddress</a>(vaddress, accdesc,
                                                                       aligned, size);
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
            memaddrdesc.fault.vaddress = regval;
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(memaddrdesc.fault);
        end;

        cache.paddress   = memaddrdesc.paddress;
        cache.cpas       = <a link="func_CPASAtPAS_1" file="shared_pseudocode.xml">CPASAtPAS</a>(memaddrdesc.paddress.paspace);

        if (opscope IN {
                         <a link="enum_CacheOpScope_PoDP" file="shared_pseudocode.xml">CacheOpScope_PoDP</a>,
                         <a link="enum_CacheOpScope_PoP" file="shared_pseudocode.xml">CacheOpScope_PoP</a>,
                         <a link="enum_CacheOpScope_PoC" file="shared_pseudocode.xml">CacheOpScope_PoC</a>,
                         <a link="enum_CacheOpScope_PoU" file="shared_pseudocode.xml">CacheOpScope_PoU</a>
                      }) then
            cache.shareability = memaddrdesc.memattrs.shareability;
        else
            cache.shareability = <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a>;
        end;
    end;

    if (cacheop == <a link="enum_CacheOp_Invalidate" file="shared_pseudocode.xml">CacheOp_Invalidate</a> &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
            HCR_EL2().[DC,VM] != '00') then
        cache.cacheop = <a link="enum_CacheOp_CleanInvalidate" file="shared_pseudocode.xml">CacheOp_CleanInvalidate</a>;
    end;

    // If Secure state is not implemented, but RME is, the instruction acts as a NOP
    if cache.cpas == <a link="enum_CPAS_Secure" file="shared_pseudocode.xml">CPAS_Secure</a> &amp;&amp; !<a link="func_HaveSecureState_0" file="shared_pseudocode.xml">HaveSecureState</a>() then
        return;
    end;

    CACHE_OP(cache);
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/dc/AArch64_MemZero" mylink="aarch64.functions.dc.AArch64_MemZero" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_MemZero()
// =================

func <anchor link="func_AArch64_MemZero_2">AArch64_MemZero</anchor>(regval : bits(64), cachetype : <a link="type_CacheType" file="shared_pseudocode.xml">CacheType</a>)
begin
    let size : integer{} = 4*(2^(UInt(DCZID_EL0().BS)));
    assert size &lt;= <a link="global_MAX_ZERO_BLOCK_SIZE" file="shared_pseudocode.xml">MAX_ZERO_BLOCK_SIZE</a>;
    if IsFeatureImplemented(FEAT_MTE2) then
        assert size &gt;= <a link="global_TAG_GRANULE" file="shared_pseudocode.xml">TAG_GRANULE</a>;
    end;
    let vaddress : bits(64) = AlignDownSize{}(regval, size);

    let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescDCZero_1" file="shared_pseudocode.xml">CreateAccDescDCZero</a>(cachetype);

    if cachetype != <a link="enum_CacheType_Data" file="shared_pseudocode.xml">CacheType_Data</a> then
        <a link="func_AArch64_WriteTagMem_4" file="shared_pseudocode.xml">AArch64_WriteTagMem</a>(regval, cachetype, accdesc, size);
    end;

    if cachetype IN {<a link="enum_CacheType_Data" file="shared_pseudocode.xml">CacheType_Data</a>, <a link="enum_CacheType_Data_Tag" file="shared_pseudocode.xml">CacheType_Data_Tag</a>} then
        <a link="func_AArch64_DataMemZero_4" file="shared_pseudocode.xml">AArch64_DataMemZero</a>(regval, vaddress, accdesc, size);
    end;
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/dc/AArch64_TreatDCAsNOP" mylink="aarch64.functions.dc.AArch64_TreatDCAsNOP" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TreatDCAsNOP()
// ======================
// Determines whether the execution of the DC instruction is treated as a NOP.

func <anchor link="func_AArch64_TreatDCAsNOP_3">AArch64_TreatDCAsNOP</anchor>(cachetype : <a link="type_CacheType" file="shared_pseudocode.xml">CacheType</a>, cacheop : <a link="type_CacheOp" file="shared_pseudocode.xml">CacheOp</a>,
                          opscope : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a>) =&gt; boolean
begin
    // DC to PoU: IMPLEMENTATION DEFINED - treated as NOP if LoUU and LoUIS are 0
    if opscope == <a link="enum_CacheOpScope_PoU" file="shared_pseudocode.xml">CacheOpScope_PoU</a> &amp;&amp; CLIDR_EL1().LoUU == '000' &amp;&amp; CLIDR_EL1().LoUIS == '000' then
        return ImpDefBool(&quot;DC to PoU is treated as a NOP&quot;);
    end;

    // DC to PoC: IMPLEMENTATION DEFINED - treated as NOP if LoC is 0
    if opscope == <a link="enum_CacheOpScope_PoC" file="shared_pseudocode.xml">CacheOpScope_PoC</a> &amp;&amp; CLIDR_EL1().LoC == '000' then
        return ImpDefBool(&quot;DC to PoC is treated as a NOP&quot;);
    end;

    // DC to PoP: IMPLEMENTATION DEFINED - treated as NOP if LoC is 0 and PoP unsupported
    if (opscope == <a link="enum_CacheOpScope_PoP" file="shared_pseudocode.xml">CacheOpScope_PoP</a> &amp;&amp; CLIDR_EL1().LoC == '000' &amp;&amp;
          !ImpDefBool(&quot;Memory system supports PoP&quot;)) then
        return ImpDefBool(&quot;DC to PoP is treated as a NOP&quot;);
    end;

    // DC to PoDP: IMPLEMENTATION DEFINED - treated as NOP if LoC is 0 and PoP/PoDP unsupported
    if (opscope == <a link="enum_CacheOpScope_PoDP" file="shared_pseudocode.xml">CacheOpScope_PoDP</a> &amp;&amp; CLIDR_EL1().LoC == '000' &amp;&amp;
          !ImpDefBool(&quot;Memory system supports PoP&quot;) &amp;&amp;
          !ImpDefBool(&quot;Memory system supports PoDP&quot;)) then
        return ImpDefBool(&quot;DC to PoDP is treated as a NOP&quot;);
    end;

    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/functions/dc/MemZero" mylink="aarch64.functions.dc.MemZero" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemZero block size
// ==================

constant <anchor link="global_MAX_ZERO_BLOCK_SIZE">MAX_ZERO_BLOCK_SIZE</anchor> : integer = 2048;</pstext></ps>
    <ps name="aarch64/functions/eret/AArch64_ExceptionReturn" mylink="aarch64.functions.eret.AArch64_ExceptionReturn" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ExceptionReturn()
// =========================

func <anchor link="func_AArch64_ExceptionReturn_2">AArch64_ExceptionReturn</anchor>(new_pc_in : bits(64), spsr : bits(64))
begin
    var new_pc : bits(64) = new_pc_in;

    if IsFeatureImplemented(FEAT_IESB) then
        var sync_errors : boolean = <a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>().IESB == '1';
        if IsFeatureImplemented(FEAT_DoubleFault) then
            sync_errors = sync_errors || (SCR_EL3().[EA,NMEA] == '11' &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
        end;
        if sync_errors then
            SynchronizeErrors();
            let iesb_req : boolean = TRUE;
            TakeUnmaskedPhysicalSErrorInterrupts(iesb_req);
        end;
    end;

    var brbe_source_allowed : boolean = FALSE;
    var brbe_source_address : bits(64) = Zeros{};
    if IsFeatureImplemented(FEAT_BRBE) then
        brbe_source_allowed = <a link="func_BranchRecordAllowed_1" file="shared_pseudocode.xml">BranchRecordAllowed</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
        brbe_source_address = <a link="func_PC64_0" file="shared_pseudocode.xml">PC64</a>();
    end;


    if !IsFeatureImplemented(FEAT_ExS) || <a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>().EOS == '1' then
        SynchronizeContext();
    end;

    // Attempts to change to an illegal state will invoke the Illegal Execution state mechanism
    let source_el : bits(2) = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
    let illegal_psr_state : boolean = <a link="func_IllegalExceptionReturn_2" file="shared_pseudocode.xml">IllegalExceptionReturn</a>{64}(spsr);
    <a link="func_SetPSTATEFromPSR_3" file="shared_pseudocode.xml">SetPSTATEFromPSR</a>{64}(spsr, illegal_psr_state);
    ClearExclusiveLocal(<a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>());
    <a link="func_SendEventLocal_0" file="shared_pseudocode.xml">SendEventLocal</a>();

    if illegal_psr_state &amp;&amp; spsr[4] == '1' then
        // If the exception return is illegal, PC[63:32,1:0] are UNKNOWN
        new_pc[63:32] = ARBITRARY : bits(32);
        new_pc[1:0] = ARBITRARY : bits(2);
    elsif <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then                // Return to AArch32
        // ELR_ELx[1:0] or ELR_ELx[0] are treated as being 0, depending on the
        // target instruction set state
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T == '1' then
            new_pc[0] = '0';                 // T32
        else
            new_pc[1:0] = '00';              // A32
        end;
    else                                     // Return to AArch64
        // ELR_ELx[63:56] might include a tag
        new_pc = <a link="func_AArch64_BranchAddr_2" file="shared_pseudocode.xml">AArch64_BranchAddr</a>(new_pc, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    end;

    if IsFeatureImplemented(FEAT_BRBE) then
        <a link="func_BRBEExceptionReturn_4" file="shared_pseudocode.xml">BRBEExceptionReturn</a>(new_pc, source_el,
                            brbe_source_allowed, brbe_source_address);
    end;


    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        if IsFeatureImplemented(FEAT_SME) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM == '1' then <a link="func_ResetSVEState_0" file="shared_pseudocode.xml">ResetSVEState</a>(); end;

        // 32 most significant bits are ignored.
        let branch_conditional : boolean = FALSE;
        <a link="func_BranchTo_4" file="shared_pseudocode.xml">BranchTo</a>{32}(new_pc[31:0], <a link="enum_BranchType_ERET" file="shared_pseudocode.xml">BranchType_ERET</a>, branch_conditional);
    else
        <a link="func_BranchToAddr_3" file="shared_pseudocode.xml">BranchToAddr</a>{64}(new_pc, <a link="enum_BranchType_ERET" file="shared_pseudocode.xml">BranchType_ERET</a>);
    end;

    <a link="func_CheckExceptionCatch_1" file="shared_pseudocode.xml">CheckExceptionCatch</a>(FALSE);              // Check for debug event on exception return
end;</pstext></ps>
    <ps name="aarch64/functions/exclusive/AArch64_ExclusiveMonitorsPass" mylink="aarch64.functions.exclusive.AArch64_ExclusiveMonitorsPass" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ExclusiveMonitorsPass()
// ===============================
// Return TRUE if the Exclusives monitors for the current PE include all of the addresses
// associated with the virtual address region of size bytes starting at address.
// The immediately following memory write must be to the same addresses.

// It is IMPLEMENTATION DEFINED whether the detection of memory aborts happens
// before or after the check on the local Exclusives monitor. As a result a failure
// of the local monitor can occur on some implementations even if the memory
// access would give a memory abort.


func <anchor link="func_AArch64_ExclusiveMonitorsPass_3">AArch64_ExclusiveMonitorsPass</anchor>(address : bits(64), size : integer{1, 2, 4, 8, 16, 32},
                                   accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; boolean
begin
    let aligned : boolean = IsAlignedSize(address, size);

    if !aligned &amp;&amp; <a link="func_AArch64_UnalignedAccessFaults_3" file="shared_pseudocode.xml">AArch64_UnalignedAccessFaults</a>(accdesc, address, size) then
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AlignmentFault_2" file="shared_pseudocode.xml">AlignmentFault</a>(accdesc, address);
        <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
    end;

    if !<a link="func_AArch64_IsExclusiveVA_3" file="shared_pseudocode.xml">AArch64_IsExclusiveVA</a>(address, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), size) then
        return FALSE;
    end;

    let memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_AArch64_TranslateAddress_4" file="shared_pseudocode.xml">AArch64_TranslateAddress</a>(address, accdesc, aligned, size);

    // Check for aborts or debug exceptions
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(memaddrdesc.fault);
    end;

    var passed : boolean = <a link="func_IsExclusiveLocal_3" file="shared_pseudocode.xml">IsExclusiveLocal</a>(memaddrdesc.paddress, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), size);
    ClearExclusiveLocal(<a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>());

    if passed &amp;&amp; memaddrdesc.memattrs.shareability != <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a> then
        passed = <a link="func_IsExclusiveGlobal_3" file="shared_pseudocode.xml">IsExclusiveGlobal</a>(memaddrdesc.paddress, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), size);
    end;

    return passed;
end;</pstext></ps>
    <ps name="aarch64/functions/exclusive/AArch64_IsExclusiveVA" mylink="aarch64.functions.exclusive.AArch64_IsExclusiveVA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_IsExclusiveVA()
// =======================
// An optional IMPLEMENTATION DEFINED test for an exclusive access to a virtual
// address region of size bytes starting at address.
//
// It is permitted (but not required) for this function to return FALSE and
// cause a store exclusive to fail if the virtual address region is not
// totally included within the region recorded by MarkExclusiveVA().
//
// It is always safe to return TRUE which will check the physical address only.


impdef func <anchor link="func_AArch64_IsExclusiveVA_3">AArch64_IsExclusiveVA</anchor>(address : bits(64),
                                  processorid : integer,
                                  size : integer) =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/exclusive/AArch64_MarkExclusiveVA" mylink="aarch64.functions.exclusive.AArch64_MarkExclusiveVA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_MarkExclusiveVA()
// =========================
// Optionally record an exclusive access to the virtual address region of size bytes
// starting at address for processorid.

func <anchor link="func_AArch64_MarkExclusiveVA_3">AArch64_MarkExclusiveVA</anchor>(address : bits(64), processorid : integer, size : integer)
begin
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/exclusive/AArch64_SetExclusiveMonitors" mylink="aarch64.functions.exclusive.AArch64_SetExclusiveMonitors" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SetExclusiveMonitors()
// ==============================
// Sets the Exclusives monitors for the current PE to record the addresses associated
// with the virtual address region of size bytes starting at address.

func <anchor link="func_AArch64_SetExclusiveMonitors_3">AArch64_SetExclusiveMonitors</anchor>(address : bits(64), size : integer{1, 2, 4, 8, 16, 32},
                                  accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>)
begin
    let aligned : boolean = IsAlignedSize(address, size);

    if !aligned &amp;&amp; <a link="func_AArch64_UnalignedAccessFaults_3" file="shared_pseudocode.xml">AArch64_UnalignedAccessFaults</a>(accdesc, address, size) then
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AlignmentFault_2" file="shared_pseudocode.xml">AlignmentFault</a>(accdesc, address);
        <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
    end;

    let memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_AArch64_TranslateAddress_4" file="shared_pseudocode.xml">AArch64_TranslateAddress</a>(address, accdesc, aligned, size);

    // Check for aborts or debug exceptions
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        return;
    end;

    if memaddrdesc.memattrs.shareability != <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a> then
        MarkExclusiveGlobal(memaddrdesc.paddress, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), size);
    end;

    MarkExclusiveLocal(memaddrdesc.paddress, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), size);

    <a link="func_AArch64_MarkExclusiveVA_3" file="shared_pseudocode.xml">AArch64_MarkExclusiveVA</a>(address, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), size);
end;</pstext></ps>
    <ps name="aarch64/functions/extendreg/DecodeRegExtend" mylink="aarch64.functions.extendreg.DecodeRegExtend" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodeRegExtend()
// =================
// Decode a register extension option

func <anchor link="func_DecodeRegExtend_1">DecodeRegExtend</anchor>(op : bits(3)) =&gt; <a link="type_ExtendType" file="shared_pseudocode.xml">ExtendType</a>
begin
    case op of
        when '000' =&gt; return <a link="enum_ExtendType_UXTB" file="shared_pseudocode.xml">ExtendType_UXTB</a>;
        when '001' =&gt; return <a link="enum_ExtendType_UXTH" file="shared_pseudocode.xml">ExtendType_UXTH</a>;
        when '010' =&gt; return <a link="enum_ExtendType_UXTW" file="shared_pseudocode.xml">ExtendType_UXTW</a>;
        when '011' =&gt; return <a link="enum_ExtendType_UXTX" file="shared_pseudocode.xml">ExtendType_UXTX</a>;
        when '100' =&gt; return <a link="enum_ExtendType_SXTB" file="shared_pseudocode.xml">ExtendType_SXTB</a>;
        when '101' =&gt; return <a link="enum_ExtendType_SXTH" file="shared_pseudocode.xml">ExtendType_SXTH</a>;
        when '110' =&gt; return <a link="enum_ExtendType_SXTW" file="shared_pseudocode.xml">ExtendType_SXTW</a>;
        when '111' =&gt; return <a link="enum_ExtendType_SXTX" file="shared_pseudocode.xml">ExtendType_SXTX</a>;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/extendreg/ExtendReg" mylink="aarch64.functions.extendreg.ExtendReg" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExtendReg()
// ===========
// Perform a register extension and shift

func <anchor link="func_ExtendReg_4">ExtendReg</anchor>{N}(reg : integer, exttype : <a link="type_ExtendType" file="shared_pseudocode.xml">ExtendType</a>, shift : integer{0..4}) =&gt; bits(N)
begin
    let val : bits(N) = X{}(reg);
    var unsigned : boolean;
    var len : <a link="type_ESize" file="shared_pseudocode.xml">ESize</a>;

    case exttype of
        when <a link="enum_ExtendType_SXTB" file="shared_pseudocode.xml">ExtendType_SXTB</a> =&gt; unsigned = FALSE; len = 8;
        when <a link="enum_ExtendType_SXTH" file="shared_pseudocode.xml">ExtendType_SXTH</a> =&gt; unsigned = FALSE; len = 16;
        when <a link="enum_ExtendType_SXTW" file="shared_pseudocode.xml">ExtendType_SXTW</a> =&gt; unsigned = FALSE; len = 32;
        when <a link="enum_ExtendType_SXTX" file="shared_pseudocode.xml">ExtendType_SXTX</a> =&gt; unsigned = FALSE; len = 64;
        when <a link="enum_ExtendType_UXTB" file="shared_pseudocode.xml">ExtendType_UXTB</a> =&gt; unsigned = TRUE;  len = 8;
        when <a link="enum_ExtendType_UXTH" file="shared_pseudocode.xml">ExtendType_UXTH</a> =&gt; unsigned = TRUE;  len = 16;
        when <a link="enum_ExtendType_UXTW" file="shared_pseudocode.xml">ExtendType_UXTW</a> =&gt; unsigned = TRUE;  len = 32;
        when <a link="enum_ExtendType_UXTX" file="shared_pseudocode.xml">ExtendType_UXTX</a> =&gt; unsigned = TRUE;  len = 64;
    end;

    // Sign or zero extend bottom LEN bits of register and shift left by SHIFT
    let nbits : integer{} = Min(len, N) as integer{8..N};
    let extval : bits(N) = Extend{}(val[nbits-1:0], unsigned);
    return LSL(extval, shift);
end;</pstext></ps>
    <ps name="aarch64/functions/extendreg/ExtendType" mylink="aarch64.functions.extendreg.ExtendType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExtendType
// ==========
// AArch64 register extend and shift.

type <anchor link="type_ExtendType">ExtendType</anchor> of enumeration {<anchor link="enum_ExtendType_SXTB">ExtendType_SXTB</anchor>, <anchor link="enum_ExtendType_SXTH">ExtendType_SXTH</anchor>, <anchor link="enum_ExtendType_SXTW">ExtendType_SXTW</anchor>, <anchor link="enum_ExtendType_SXTX">ExtendType_SXTX</anchor>,
                                <anchor link="enum_ExtendType_UXTB">ExtendType_UXTB</anchor>, <anchor link="enum_ExtendType_UXTH">ExtendType_UXTH</anchor>, <anchor link="enum_ExtendType_UXTW">ExtendType_UXTW</anchor>, <anchor link="enum_ExtendType_UXTX">ExtendType_UXTX</anchor>};</pstext></ps>
    <ps name="aarch64/functions/fpconvop/FPConvOp" mylink="aarch64.functions.fpconvop.FPConvOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPConvOp
// ========
// Floating-point convert/move instruction types.

type <anchor link="type_FPConvOp">FPConvOp</anchor> of enumeration {<anchor link="enum_FPConvOp_CVT_FtoI">FPConvOp_CVT_FtoI</anchor>, <anchor link="enum_FPConvOp_CVT_ItoF">FPConvOp_CVT_ItoF</anchor>,
                              <anchor link="enum_FPConvOp_MOV_FtoI">FPConvOp_MOV_FtoI</anchor>, <anchor link="enum_FPConvOp_MOV_ItoF">FPConvOp_MOV_ItoF</anchor>,
                              <anchor link="enum_FPConvOp_CVT_FtoI_JS">FPConvOp_CVT_FtoI_JS</anchor>
};</pstext></ps>
    <ps name="aarch64/functions/fpmaxminop/FPMaxMinOp" mylink="aarch64.functions.fpmaxminop.FPMaxMinOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPMaxMinOp
// ==========
// Floating-point min/max instruction types.

type <anchor link="type_FPMaxMinOp">FPMaxMinOp</anchor> of enumeration {<anchor link="enum_FPMaxMinOp_MAX">FPMaxMinOp_MAX</anchor>, <anchor link="enum_FPMaxMinOp_MIN">FPMaxMinOp_MIN</anchor>,
                                <anchor link="enum_FPMaxMinOp_MAXNUM">FPMaxMinOp_MAXNUM</anchor>, <anchor link="enum_FPMaxMinOp_MINNUM">FPMaxMinOp_MINNUM</anchor>};</pstext></ps>
    <ps name="aarch64/functions/fpmr/CheckFPMREnabled" mylink="aarch64.functions.fpmr.CheckFPMREnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckFPMREnabled()
// ==================
// Check for Undefined instruction exception on indirect FPMR accesses.

func <anchor link="func_CheckFPMREnabled_0">CheckFPMREnabled</anchor>()
begin
    assert IsFeatureImplemented(FEAT_FPMR);

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        if !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
            if SCTLR_EL1().EnFPM == '0' then Undefined(); end;
        else
            if SCTLR_EL2().EnFPM == '0' then Undefined(); end;
        end;
    end;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
        if !<a link="func_IsHCRXEL2Enabled_0" file="shared_pseudocode.xml">IsHCRXEL2Enabled</a>() || HCRX_EL2().EnFPM == '0' then Undefined(); end;
    end;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        if SCR_EL3().EnFPM == '0' then Undefined(); end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/fpscale/FPClampScale" mylink="aarch64.functions.fpscale.FPClampScale" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPClampScale()
// ==============

func <anchor link="func_FPClampScale_3">FPClampScale</anchor>{N}(op : bits(N), scale_in : integer) =&gt; integer
begin
    assert N IN {16,32,64};
    var E : integer;
    var exp : integer;
    case N of
        when 16 =&gt;
            E = 5;
            exp = UInt(op[14:10]);
        when 32 =&gt;
            E = 8;
            exp = UInt(op[30:23]);
        when 64 =&gt;
            E = 11;
            exp = UInt(op[62:52]);
        otherwise =&gt; unreachable;
    end;

    let F : integer = N - (E + 1);
    let emax : integer = (1 &lt;&lt; E) - 1;
    let min_scale : integer = -(F + 1);
    let max_scale : integer = emax + (F + 1);

    let scale : integer = Max(min_scale - exp, Min(scale_in, max_scale - exp));
    return scale;
end;</pstext></ps>
    <ps name="aarch64/functions/fpscale/FPScale" mylink="aarch64.functions.fpscale.FPScale" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPScale()
// =========

func <anchor link="func_FPScale_4">FPScale</anchor>{N}(op : bits(N), scale : integer, fpcr : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var result : bits(N);
    let (fptype,sign,value) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op, fpcr);

    if fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || fptype == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        result = <a link="func_FPProcessNaN_4" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(fptype, op, fpcr);
    elsif fptype == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then
        result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign);
    elsif fptype == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a> then
        result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}(sign);
    else
        let clamped_scale : integer = <a link="func_FPClampScale_3" file="shared_pseudocode.xml">FPClampScale</a>{N}(op, scale);
        result = <a link="func_FPRound_3" file="shared_pseudocode.xml">FPRound</a>{N}(value * (2.0^clamped_scale), fpcr);
        <a link="func_FPProcessDenorm_3" file="shared_pseudocode.xml">FPProcessDenorm</a>(fptype, N, fpcr);
    end;
    return result;
end;</pstext></ps>
    <ps name="aarch64/functions/fpunaryop/FPUnaryOp" mylink="aarch64.functions.fpunaryop.FPUnaryOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPUnaryOp
// =========
// Floating-point unary instruction types.

type <anchor link="type_FPUnaryOp">FPUnaryOp</anchor> of enumeration {<anchor link="enum_FPUnaryOp_ABS">FPUnaryOp_ABS</anchor>, <anchor link="enum_FPUnaryOp_MOV">FPUnaryOp_MOV</anchor>,
                               <anchor link="enum_FPUnaryOp_NEG">FPUnaryOp_NEG</anchor>, <anchor link="enum_FPUnaryOp_SQRT">FPUnaryOp_SQRT</anchor>};</pstext></ps>
    <ps name="aarch64/functions/fusedrstep/FPRSqrtStepFused" mylink="aarch64.functions.fusedrstep.FPRSqrtStepFused" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPRSqrtStepFused()
// ==================

func <anchor link="func_FPRSqrtStepFused_4">FPRSqrtStepFused</anchor>{N}(op1_in : bits(N), op2 : bits(N), fpcr_in : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16, 32, 64};
    var fpcr : FPCR_Type = fpcr_in;
    var result : bits(N);
    var op1 : bits(N) = op1_in;
    var done : boolean;
    op1 = <a link="func_FPNeg_3" file="shared_pseudocode.xml">FPNeg</a>{N}(op1, fpcr);
    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; fpcr.AH == '1';
    let fpexc : boolean = !altfp;                    // Generate no floating-point exceptions
    if altfp then fpcr.[FIZ,FZ] = '11'; end;         // Flush denormal input and output to zero
    if altfp then fpcr.RMode = '00'; end;            // Use RNE rounding mode

    let (type1,sign1,value1) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr, fpexc);
    let (type2,sign2,value2) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr, fpexc);
    (done,result) = <a link="func_FPProcessNaNs_7" file="shared_pseudocode.xml">FPProcessNaNs</a>{N}(type1, type2, op1, op2, fpcr, fpexc);
    let rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a> = <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr);

    if !done then
        let inf1 : boolean = (type1 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let inf2 : boolean = (type2 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let zero1 : boolean = (type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        let zero2 : boolean = (type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);

        if (inf1 &amp;&amp; zero2) || (zero1 &amp;&amp; inf2) then
            result = <a link="func_FPOnePointFive_2" file="shared_pseudocode.xml">FPOnePointFive</a>{N}('0');
        elsif inf1 || inf2 then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}(sign1 XOR sign2);
        else
            // Fully fused multiply-add and halve
            let result_value : real = (3.0 + (value1 * value2)) / 2.0;
            if result_value == 0.0 then
                // Sign of exact zero result depends on rounding mode
                let sign : bit = if rounding == <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a> then '1' else '0';
                result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign);
            else
                result = <a link="func_FPRound_5" file="shared_pseudocode.xml">FPRound</a>{N}(result_value, fpcr, rounding, fpexc);
            end;
        end;
    end;

    return result;
end;</pstext></ps>
    <ps name="aarch64/functions/fusedrstep/FPRecipStepFused" mylink="aarch64.functions.fusedrstep.FPRecipStepFused" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPRecipStepFused()
// ==================

func <anchor link="func_FPRecipStepFused_4">FPRecipStepFused</anchor>{N}(op1_in : bits(N), op2 : bits(N), fpcr_in : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16, 32, 64};
    var fpcr : FPCR_Type = fpcr_in;
    var op1 : bits(N)    = op1_in;
    var result : bits(N);
    var done : boolean;
    op1 = <a link="func_FPNeg_3" file="shared_pseudocode.xml">FPNeg</a>{N}(op1, fpcr);

    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; fpcr.AH == '1';
    let fpexc : boolean = !altfp;                    // Generate no floating-point exceptions
    if altfp then fpcr.[FIZ,FZ] = '11'; end;         // Flush denormal input and output to zero
    if altfp then fpcr.RMode    = '00'; end;         // Use RNE rounding mode

    let (type1,sign1,value1) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr, fpexc);
    let (type2,sign2,value2) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr, fpexc);
    (done,result) = <a link="func_FPProcessNaNs_7" file="shared_pseudocode.xml">FPProcessNaNs</a>{N}(type1, type2, op1, op2, fpcr, fpexc);
    let rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a> = <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr);

    if !done then
        let inf1 : boolean  = (type1 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let inf2 : boolean  = (type2 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let zero1 : boolean = (type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        let zero2 : boolean = (type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);

        if (inf1 &amp;&amp; zero2) || (zero1 &amp;&amp; inf2) then
            result = <a link="func_FPTwo_2" file="shared_pseudocode.xml">FPTwo</a>{N}('0');
        elsif inf1 || inf2 then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}(sign1 XOR sign2);
        else
            // Fully fused multiply-add
            let result_value : real = 2.0 + (value1 * value2);
            if result_value == 0.0 then
                // Sign of exact zero result depends on rounding mode
                let sign : bit = if rounding == <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a> then '1' else '0';
                result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign);
            else
                result = <a link="func_FPRound_5" file="shared_pseudocode.xml">FPRound</a>{N}(result_value, fpcr, rounding, fpexc);
            end;
        end;
    end;

    return result;
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/AddGCSExRecord" mylink="aarch64.functions.gcs.AddGCSExRecord" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddGCSExRecord()
// ================
// Generates and then writes an exception record to the
// current Guarded Control Stack.

func <anchor link="func_AddGCSExRecord_3">AddGCSExRecord</anchor>(elr : bits(64), spsr : bits(64), lr : bits(64))
begin
    var ptr : bits(64);
    let privileged : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
    let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescGCS_2" file="shared_pseudocode.xml">CreateAccDescGCS</a>(<a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>, privileged);

    ptr = <a link="func_GetCurrentGCSPointer_0" file="shared_pseudocode.xml">GetCurrentGCSPointer</a>();

    // Store the record
    <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(ptr-8, accdesc) = lr;
    <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(ptr-16, accdesc) = spsr;
    <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(ptr-24, accdesc) = elr;
    <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(ptr-32, accdesc) = Zeros{60}::'1001';

    // Decrement the pointer value
    ptr = ptr - 32;

    <a link="func_SetCurrentGCSPointer_1" file="shared_pseudocode.xml">SetCurrentGCSPointer</a>(ptr);
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/AddGCSRecord" mylink="aarch64.functions.gcs.AddGCSRecord" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddGCSRecord()
// ==============
// Generates and then writes a record to the current Guarded
// control stack.

func <anchor link="func_AddGCSRecord_1">AddGCSRecord</anchor>(vaddress : bits(64))
begin
    var ptr : bits(64);
    let privileged : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
    let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescGCS_2" file="shared_pseudocode.xml">CreateAccDescGCS</a>(<a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>, privileged);

    ptr = <a link="func_GetCurrentGCSPointer_0" file="shared_pseudocode.xml">GetCurrentGCSPointer</a>();

    // Store the record
    <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(ptr-8, accdesc) = vaddress;

    // Decrement the pointer value
    ptr = ptr - 8;

    <a link="func_SetCurrentGCSPointer_1" file="shared_pseudocode.xml">SetCurrentGCSPointer</a>(ptr);
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/CheckGCSExRecord" mylink="aarch64.functions.gcs.CheckGCSExRecord" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckGCSExRecord()
// ==================
// Validates the provided values against the top entry of the
// current Guarded Control Stack.

func <anchor link="func_CheckGCSExRecord_4">CheckGCSExRecord</anchor>(elr : bits(64), spsr : bits(64), lr : bits(64), gcsinst_type : <a link="type_GCSInstruction" file="shared_pseudocode.xml">GCSInstruction</a>)
begin
    var ptr : bits(64);
    let privileged : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
    let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescGCS_2" file="shared_pseudocode.xml">CreateAccDescGCS</a>(<a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>, privileged);
    ptr = <a link="func_GetCurrentGCSPointer_0" file="shared_pseudocode.xml">GetCurrentGCSPointer</a>();

    // Check the lowest doubleword is correctly formatted
    let recorded_first_dword : bits(64) = <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(ptr, accdesc);
    if recorded_first_dword != Zeros{60}::'1001' then
        <a link="func_GCSDataCheckException_1" file="shared_pseudocode.xml">GCSDataCheckException</a>(gcsinst_type);
    end;

    // Check the ELR matches the recorded value
    let recorded_elr : bits(64) = <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(ptr+8, accdesc);
    if recorded_elr != elr then
        <a link="func_GCSDataCheckException_1" file="shared_pseudocode.xml">GCSDataCheckException</a>(gcsinst_type);
    end;

    // Check the SPSR matches the recorded value
    let recorded_spsr : bits(64) = <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(ptr+16, accdesc);
    if recorded_spsr != spsr then
        <a link="func_GCSDataCheckException_1" file="shared_pseudocode.xml">GCSDataCheckException</a>(gcsinst_type);
    end;

    // Check the LR matches the recorded value
    let recorded_lr : bits(64) = <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(ptr+24, accdesc);
    if recorded_lr != lr then
        <a link="func_GCSDataCheckException_1" file="shared_pseudocode.xml">GCSDataCheckException</a>(gcsinst_type);
    end;

    // Increment the pointer value
    ptr = ptr + 32;

    <a link="func_SetCurrentGCSPointer_1" file="shared_pseudocode.xml">SetCurrentGCSPointer</a>(ptr);
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/CheckGCSSTREnabled" mylink="aarch64.functions.gcs.CheckGCSSTREnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckGCSSTREnabled()
// ====================
// Trap GCSSTR or GCSSTTR instruction if trapping is enabled.

func <anchor link="func_CheckGCSSTREnabled_0">CheckGCSSTREnabled</anchor>()
begin
    case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL of
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            if GCSCRE0_EL1().STREn == '0' then
                if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1' then
                    <a link="func_GCSSTRTrapException_1" file="shared_pseudocode.xml">GCSSTRTrapException</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
                else
                    <a link="func_GCSSTRTrapException_1" file="shared_pseudocode.xml">GCSSTRTrapException</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>);
                end;
            end;
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            if GCSCR_EL1().STREn == '0' then
                <a link="func_GCSSTRTrapException_1" file="shared_pseudocode.xml">GCSSTRTrapException</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>);
            elsif (<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; (!<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || SCR_EL3().FGTEn == '1') &amp;&amp;
                    HFGITR_EL2().nGCSSTR_EL1 == '0') then
                <a link="func_GCSSTRTrapException_1" file="shared_pseudocode.xml">GCSSTRTrapException</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
            end;
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            if GCSCR_EL2().STREn == '0' then
                <a link="func_GCSSTRTrapException_1" file="shared_pseudocode.xml">GCSSTRTrapException</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
            end;
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            if GCSCR_EL3().STREn == '0' then
                <a link="func_GCSSTRTrapException_1" file="shared_pseudocode.xml">GCSSTRTrapException</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
            end;
    end;
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/EXLOCKException" mylink="aarch64.functions.gcs.EXLOCKException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EXLOCKException()
// =================
// Handle an EXLOCK exception condition.

func <anchor link="func_EXLOCKException_0">EXLOCKException</anchor>()
begin
    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_GCSFail" file="shared_pseudocode.xml">Exception_GCSFail</a>);
    except.syndrome.iss[24] = '0';
    except.syndrome.iss[23:20] = '0001';
    except.syndrome.iss[19:0] = Zeros{20};
    AArch64_TakeException(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/GCSDataCheckException" mylink="aarch64.functions.gcs.GCSDataCheckException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GCSDataCheckException()
// =======================
// Handle a GCS data check fault condition.

func <anchor link="func_GCSDataCheckException_1">GCSDataCheckException</anchor>(gcsinst_type : <a link="type_GCSInstruction" file="shared_pseudocode.xml">GCSInstruction</a>)
begin
    var target_el : bits(2);
    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;
    var rn_unknown : boolean  = FALSE;
    var is_ret : boolean      = FALSE;
    var is_reta : boolean     = FALSE;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        target_el = if (<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1') then <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> else <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    else
        target_el = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
    end;
    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_GCSFail" file="shared_pseudocode.xml">Exception_GCSFail</a>);
    case gcsinst_type of
        when <a link="enum_GCSInstType_PRET" file="shared_pseudocode.xml">GCSInstType_PRET</a> =&gt;
            except.syndrome.iss[4:0] = '00000';
            is_ret = TRUE;
        when <a link="enum_GCSInstType_POPM" file="shared_pseudocode.xml">GCSInstType_POPM</a> =&gt;
            except.syndrome.iss[4:0] = '00001';
        when <a link="enum_GCSInstType_PRETAA" file="shared_pseudocode.xml">GCSInstType_PRETAA</a> =&gt;
            except.syndrome.iss[4:0] = '00010';
            is_reta = TRUE;
        when <a link="enum_GCSInstType_PRETAB" file="shared_pseudocode.xml">GCSInstType_PRETAB</a> =&gt;
            except.syndrome.iss[4:0] = '00011';
            is_reta = TRUE;
        when <a link="enum_GCSInstType_SS1" file="shared_pseudocode.xml">GCSInstType_SS1</a> =&gt;
            except.syndrome.iss[4:0] = '00100';
        when <a link="enum_GCSInstType_SS2" file="shared_pseudocode.xml">GCSInstType_SS2</a> =&gt;
            except.syndrome.iss[4:0] = '00101';
            rn_unknown = TRUE;
        when <a link="enum_GCSInstType_POPCX" file="shared_pseudocode.xml">GCSInstType_POPCX</a> =&gt;
            rn_unknown = TRUE;
            except.syndrome.iss[4:0] = '01000';
        when <a link="enum_GCSInstType_POPX" file="shared_pseudocode.xml">GCSInstType_POPX</a> =&gt;
            except.syndrome.iss[4:0] = '01001';
    end;
    if rn_unknown == TRUE then
        except.syndrome.iss[9:5] = ARBITRARY : bits(5);
    elsif is_ret == TRUE then
        except.syndrome.iss[9:5] = <a link="func_ThisInstr_0" file="shared_pseudocode.xml">ThisInstr</a>()[9:5];
    elsif is_reta == TRUE then
        except.syndrome.iss[9:5] = '11110';
    else
        except.syndrome.iss[9:5] = <a link="func_ThisInstr_0" file="shared_pseudocode.xml">ThisInstr</a>()[4:0];
    end;
    except.syndrome.iss[24:10] = Zeros{15};
    except.vaddress = ARBITRARY : bits(64);
    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/GCSEnabled" mylink="aarch64.functions.gcs.GCSEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GCSEnabled()
// ============
// Returns TRUE if the Guarded Control Stack is enabled at
// the provided Exception level.

func <anchor link="func_GCSEnabled_1">GCSEnabled</anchor>(el : bits(2)) =&gt; boolean
begin
    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        return FALSE;
    end;

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; el != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; SCR_EL3().GCSEn == '0' then
        return FALSE;
    end;

    if (el IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) &amp;&amp;
        (!<a link="func_IsHCRXEL2Enabled_0" file="shared_pseudocode.xml">IsHCRXEL2Enabled</a>() || HCRX_EL2().GCSEn == '0')) then
        return FALSE;
    end;

    return <a link="func_GCSPCRSelected_1" file="shared_pseudocode.xml">GCSPCRSelected</a>(el);
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/GCSInstruction" mylink="aarch64.functions.gcs.GCSInstruction" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GCSInstruction
// ==============

type <anchor link="type_GCSInstruction">GCSInstruction</anchor> of enumeration {
    <anchor link="enum_GCSInstType_PRET">GCSInstType_PRET</anchor>,    // Procedure return without Pointer authentication
    <anchor link="enum_GCSInstType_POPM">GCSInstType_POPM</anchor>,    // GCSPOPM instruction
    <anchor link="enum_GCSInstType_PRETAA">GCSInstType_PRETAA</anchor>,  // Procedure return with Pointer authentication that used key A
    <anchor link="enum_GCSInstType_PRETAB">GCSInstType_PRETAB</anchor>,  // Procedure return with Pointer authentication that used key B
    <anchor link="enum_GCSInstType_SS1">GCSInstType_SS1</anchor>,     // GCSSS1 instruction
    <anchor link="enum_GCSInstType_SS2">GCSInstType_SS2</anchor>,     // GCSSS2 instruction
    <anchor link="enum_GCSInstType_POPCX">GCSInstType_POPCX</anchor>,   // GCSPOPCX instruction
    <anchor link="enum_GCSInstType_POPX">GCSInstType_POPX</anchor>     // GCSPOPX instruction
};</pstext></ps>
    <ps name="aarch64/functions/gcs/GCSPCREnabled" mylink="aarch64.functions.gcs.GCSPCREnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GCSPCREnabled()
// ===============
// Returns TRUE if the Guarded Control Stack is PCR enabled
// at the provided Exception level.

func <anchor link="func_GCSPCREnabled_1">GCSPCREnabled</anchor>(el : bits(2)) =&gt; boolean
begin
    return <a link="func_GCSPCRSelected_1" file="shared_pseudocode.xml">GCSPCRSelected</a>(el) &amp;&amp; <a link="func_GCSEnabled_1" file="shared_pseudocode.xml">GCSEnabled</a>(el);
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/GCSPCRSelected" mylink="aarch64.functions.gcs.GCSPCRSelected" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GCSPCRSelected()
// ================
// Returns TRUE if the Guarded Control Stack is PCR selected
// at the provided Exception level.

func <anchor link="func_GCSPCRSelected_1">GCSPCRSelected</anchor>(el : bits(2)) =&gt; boolean
begin
    case el of
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt; return GCSCRE0_EL1().PCRSEL == '1';
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt; return GCSCR_EL1().PCRSEL == '1';
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt; return GCSCR_EL2().PCRSEL == '1';
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt; return GCSCR_EL3().PCRSEL == '1';
    end;
    unreachable;
    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/GCSPOPCX" mylink="aarch64.functions.gcs.GCSPOPCX" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GCSPOPCX()
// ==========
// Called to pop and compare a GCS exception return record.

func <anchor link="func_GCSPOPCX_0">GCSPOPCX</anchor>()
begin
    let spsr : bits(64) = <a link="accessor_SPSR_ELx_0" file="shared_pseudocode.xml">SPSR_ELx</a>();
    <a link="func_CheckGCSExRecord_4" file="shared_pseudocode.xml">CheckGCSExRecord</a>(<a link="accessor_ELR_ELx_0" file="shared_pseudocode.xml">ELR_ELx</a>(), spsr, <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(30), <a link="enum_GCSInstType_POPCX" file="shared_pseudocode.xml">GCSInstType_POPCX</a>);
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EXLOCK = if <a link="func_GetCurrentEXLOCKEN_0" file="shared_pseudocode.xml">GetCurrentEXLOCKEN</a>() then '1' else '0';
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/GCSPOPM" mylink="aarch64.functions.gcs.GCSPOPM" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GCSPOPM()
// =========
// Called to pop a GCS procedure return record.

func <anchor link="func_GCSPOPM_0">GCSPOPM</anchor>() =&gt; bits(64)
begin
    var ptr : bits(64);
    let privileged : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
    let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescGCS_2" file="shared_pseudocode.xml">CreateAccDescGCS</a>(<a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>, privileged);

    ptr = <a link="func_GetCurrentGCSPointer_0" file="shared_pseudocode.xml">GetCurrentGCSPointer</a>();
    let gcs_entry : bits(64) = <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(ptr, accdesc);

    if gcs_entry[1:0] != '00' then
        <a link="func_GCSDataCheckException_1" file="shared_pseudocode.xml">GCSDataCheckException</a>(<a link="enum_GCSInstType_POPM" file="shared_pseudocode.xml">GCSInstType_POPM</a>);
    end;

    ptr = ptr + 8;
    <a link="func_SetCurrentGCSPointer_1" file="shared_pseudocode.xml">SetCurrentGCSPointer</a>(ptr);
    return gcs_entry;
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/GCSPOPX" mylink="aarch64.functions.gcs.GCSPOPX" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GCSPOPX()
// =========
// Called to pop a GCS exception return record.

func <anchor link="func_GCSPOPX_0">GCSPOPX</anchor>()
begin
    var ptr : bits(64);
    let privileged : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
    let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescGCS_2" file="shared_pseudocode.xml">CreateAccDescGCS</a>(<a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>, privileged);
    ptr = <a link="func_GetCurrentGCSPointer_0" file="shared_pseudocode.xml">GetCurrentGCSPointer</a>();

    // Check the lowest doubleword is correctly formatted
    let recorded_first_dword : bits(64) = <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(ptr, accdesc);
    if recorded_first_dword != Zeros{60}::'1001' then
        <a link="func_GCSDataCheckException_1" file="shared_pseudocode.xml">GCSDataCheckException</a>(<a link="enum_GCSInstType_POPX" file="shared_pseudocode.xml">GCSInstType_POPX</a>);
    end;

    // Ignore these loaded values, however they might have
    // faulted which is why we load them anyway
    let recorded_elr : bits(64) = <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(ptr+8, accdesc);
    let recorded_spsr : bits(64) = <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(ptr+16, accdesc);
    let recorded_lr : bits(64) = <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(ptr+24, accdesc);

    // Increment the pointer value
    ptr = ptr + 32;

    <a link="func_SetCurrentGCSPointer_1" file="shared_pseudocode.xml">SetCurrentGCSPointer</a>(ptr);
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/GCSPUSHM" mylink="aarch64.functions.gcs.GCSPUSHM" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GCSPUSHM()
// ==========
// Called to push a GCS procedure return record.

func <anchor link="func_GCSPUSHM_1">GCSPUSHM</anchor>(value : bits(64))
begin
    <a link="func_AddGCSRecord_1" file="shared_pseudocode.xml">AddGCSRecord</a>(value);
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/GCSPUSHX" mylink="aarch64.functions.gcs.GCSPUSHX" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GCSPUSHX()
// ==========
// Called to push a GCS exception return record.

func <anchor link="func_GCSPUSHX_0">GCSPUSHX</anchor>()
begin
    let spsr : bits(64) = <a link="accessor_SPSR_ELx_0" file="shared_pseudocode.xml">SPSR_ELx</a>();
    <a link="func_AddGCSExRecord_3" file="shared_pseudocode.xml">AddGCSExRecord</a>(<a link="accessor_ELR_ELx_0" file="shared_pseudocode.xml">ELR_ELx</a>(), spsr, <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(30));
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EXLOCK = '0';
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/GCSReturnValueCheckEnabled" mylink="aarch64.functions.gcs.GCSReturnValueCheckEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GCSReturnValueCheckEnabled()
// ============================
// Returns TRUE if the Guarded Control Stack has return value
// checking enabled at the current Exception level.

func <anchor link="func_GCSReturnValueCheckEnabled_1">GCSReturnValueCheckEnabled</anchor>(el : bits(2)) =&gt; boolean
begin
    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        return FALSE;
    end;
    case el of
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt; return GCSCRE0_EL1().RVCHKEN == '1';
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt; return GCSCR_EL1().RVCHKEN == '1';
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt; return GCSCR_EL2().RVCHKEN == '1';
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt; return GCSCR_EL3().RVCHKEN == '1';
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/GCSSS1" mylink="aarch64.functions.gcs.GCSSS1" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GCSSS1()
// ========
// Operational pseudocode for GCSSS1 instruction.

func <anchor link="func_GCSSS1_1">GCSSS1</anchor>(incoming_pointer : bits(64))
begin
    var outgoing_pointer, cmpoperand, operand, data : bits(64);
    let privileged : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
    let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescGCSSS1_1" file="shared_pseudocode.xml">CreateAccDescGCSSS1</a>(privileged);
    outgoing_pointer = <a link="func_GetCurrentGCSPointer_0" file="shared_pseudocode.xml">GetCurrentGCSPointer</a>();
    // Valid GCS cap record is expected
    cmpoperand = incoming_pointer[63:12]::'000000000001';
    // In-progress GCS cap record should be stored if the comparison is successful
    operand = outgoing_pointer[63:3]::'101';

    data = <a link="func_MemAtomic_5" file="shared_pseudocode.xml">MemAtomic</a>{64}(incoming_pointer, cmpoperand, operand, accdesc);
    if data == cmpoperand then
        <a link="func_SetCurrentGCSPointer_1" file="shared_pseudocode.xml">SetCurrentGCSPointer</a>(incoming_pointer[63:3]::'000');
    else
        <a link="func_GCSDataCheckException_1" file="shared_pseudocode.xml">GCSDataCheckException</a>(<a link="enum_GCSInstType_SS1" file="shared_pseudocode.xml">GCSInstType_SS1</a>);
    end;
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/GCSSS2" mylink="aarch64.functions.gcs.GCSSS2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GCSSS2()
// ========
// Operational pseudocode for GCSSS2 instruction.

func <anchor link="func_GCSSS2_0">GCSSS2</anchor>() =&gt; bits(64)
begin
    var outgoing_pointer, incoming_pointer, outgoing_value : bits(64);
    let privileged : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
    let accdesc_ld : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescGCS_2" file="shared_pseudocode.xml">CreateAccDescGCS</a>(<a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>, privileged);
    let accdesc_st : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescGCS_2" file="shared_pseudocode.xml">CreateAccDescGCS</a>(<a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>, privileged);
    incoming_pointer = <a link="func_GetCurrentGCSPointer_0" file="shared_pseudocode.xml">GetCurrentGCSPointer</a>();
    outgoing_value = <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(incoming_pointer, accdesc_ld);

    if outgoing_value[2:0] == '101' then  //in_progress token
        outgoing_pointer[63:3] = (outgoing_value[63:3]) - 1;
        outgoing_pointer[2:0] = '000';
        outgoing_value = outgoing_pointer[63:12]::'000000000001';
        <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(outgoing_pointer, accdesc_st) = outgoing_value;
        <a link="func_SetCurrentGCSPointer_1" file="shared_pseudocode.xml">SetCurrentGCSPointer</a>(incoming_pointer + 8);
        GCSSynchronizationBarrier();
    else
        <a link="func_GCSDataCheckException_1" file="shared_pseudocode.xml">GCSDataCheckException</a>(<a link="enum_GCSInstType_SS2" file="shared_pseudocode.xml">GCSInstType_SS2</a>);
    end;
    return outgoing_pointer;
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/GCSSTRTrapException" mylink="aarch64.functions.gcs.GCSSTRTrapException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GCSSTRTrapException()
// =====================
// Handle a trap on GCSSTR instruction condition.

func <anchor link="func_GCSSTRTrapException_1">GCSSTRTrapException</anchor>(target_el : bits(2))
begin
    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_GCSFail" file="shared_pseudocode.xml">Exception_GCSFail</a>);
    except.syndrome.iss[24]      = '0';
    except.syndrome.iss[23:20]   = '0010';
    except.syndrome.iss[19:15]   = '00000';
    except.syndrome.iss[14:10]   = <a link="func_ThisInstr_0" file="shared_pseudocode.xml">ThisInstr</a>()[9:5];
    except.syndrome.iss[9:5]     = <a link="func_ThisInstr_0" file="shared_pseudocode.xml">ThisInstr</a>()[4:0];
    except.syndrome.iss[4:0]     = '00000';
    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/GCSSynchronizationBarrier" mylink="aarch64.functions.gcs.GCSSynchronizationBarrier" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GCSSynchronizationBarrier()
// ===========================
// Barrier instruction that synchronizes GCS accesses
// in relation to other load and store accesses

impdef func GCSSynchronizationBarrier()
begin
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/GetCurrentEXLOCKEN" mylink="aarch64.functions.gcs.GetCurrentEXLOCKEN" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetCurrentEXLOCKEN()
// ====================

func <anchor link="func_GetCurrentEXLOCKEN_0">GetCurrentEXLOCKEN</anchor>() =&gt; boolean
begin
    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() || <a link="func_Restarting_0" file="shared_pseudocode.xml">Restarting</a>() then
        return FALSE;
    end;

    case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL of
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            unreachable;
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            return GCSCR_EL1().EXLOCKEN == '1';
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            return GCSCR_EL2().EXLOCKEN == '1';
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            return GCSCR_EL3().EXLOCKEN == '1';
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/GetCurrentGCSPointer" mylink="aarch64.functions.gcs.GetCurrentGCSPointer" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetCurrentGCSPointer()
// ======================
// Returns the value of the current GCS pointer register.

func <anchor link="func_GetCurrentGCSPointer_0">GetCurrentGCSPointer</anchor>() =&gt; bits(64)
begin
    var ptr : bits(64);

    case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL of
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            ptr = GCSPR_EL0().PTR::'000';
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            ptr = GCSPR_EL1().PTR::'000';
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            ptr = GCSPR_EL2().PTR::'000';
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            ptr = GCSPR_EL3().PTR::'000';
    end;
    return ptr;
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/LoadCheckGCSRecord" mylink="aarch64.functions.gcs.LoadCheckGCSRecord" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// LoadCheckGCSRecord()
// ====================
// Validates the provided address against the top entry of the
// current Guarded Control Stack.

func <anchor link="func_LoadCheckGCSRecord_2">LoadCheckGCSRecord</anchor>(vaddress : bits(64), gcsinst_type : <a link="type_GCSInstruction" file="shared_pseudocode.xml">GCSInstruction</a>) =&gt; bits(64)
begin
    var ptr : bits(64);
    var recorded_va : bits(64);
    let privileged : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
    let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescGCS_2" file="shared_pseudocode.xml">CreateAccDescGCS</a>(<a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>, privileged);

    ptr = <a link="func_GetCurrentGCSPointer_0" file="shared_pseudocode.xml">GetCurrentGCSPointer</a>();
    recorded_va = <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(ptr, accdesc);
    if <a link="func_GCSReturnValueCheckEnabled_1" file="shared_pseudocode.xml">GCSReturnValueCheckEnabled</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) &amp;&amp; (recorded_va != vaddress) then
        <a link="func_GCSDataCheckException_1" file="shared_pseudocode.xml">GCSDataCheckException</a>(gcsinst_type);
    end;

    return recorded_va;
end;</pstext></ps>
    <ps name="aarch64/functions/gcs/SetCurrentGCSPointer" mylink="aarch64.functions.gcs.SetCurrentGCSPointer" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SetCurrentGCSPointer()
// ======================
// Writes a value to the current GCS pointer register.

func <anchor link="func_SetCurrentGCSPointer_1">SetCurrentGCSPointer</anchor>(ptr : bits(64))
begin
    case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL of
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            GCSPR_EL0().PTR = ptr[63:3];
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            GCSPR_EL1().PTR = ptr[63:3];
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            GCSPR_EL2().PTR = ptr[63:3];
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            GCSPR_EL3().PTR = ptr[63:3];
    end;
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/hacdbs" mylink="aarch64.functions.hacdbs" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">constant <anchor link="global_HACDBS_ERR_REASON_STRUCTF">HACDBS_ERR_REASON_STRUCTF</anchor> : bits(2) = '01';
constant <anchor link="global_HACDBS_ERR_REASON_IPAF">HACDBS_ERR_REASON_IPAF</anchor> : bits(2)    = '10';
constant <anchor link="global_HACDBS_ERR_REASON_IPHACF">HACDBS_ERR_REASON_IPHACF</anchor> : bits(2)  = '11';</pstext></ps>
    <ps name="aarch64/functions/hacdbs/IsHACDBSIRQAsserted" mylink="aarch64.functions.hacdbs.IsHACDBSIRQAsserted" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsHACDBSIRQAsserted()
// =====================
// Returns TRUE if HACDBSIRQ is asserted, and FALSE otherwise.

impdef func <anchor link="func_IsHACDBSIRQAsserted_0">IsHACDBSIRQAsserted</anchor>() =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/functions/hacdbs/ProcessHACDBSEntry" mylink="aarch64.functions.hacdbs.ProcessHACDBSEntry" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ProcessHACDBSEntry()
// ====================
// Process a single entry entry from the HACDBS.

func <anchor link="func_ProcessHACDBSEntry_0">ProcessHACDBSEntry</anchor>()
begin
    if !IsFeatureImplemented(FEAT_HACDBS) then return; end;

    if (<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().HACDBSEn == '0') || HACDBSBR_EL2().EN == '0' then
        SetInterruptRequestLevel(<a link="enum_InterruptID_HACDBSIRQ" file="shared_pseudocode.xml">InterruptID_HACDBSIRQ</a>, <a link="enum_LOW" file="shared_pseudocode.xml">LOW</a>);
        return;
    end;

    if HCR_EL2().VM == '0' then return; end;

    if (UInt(HACDBSCONS_EL2().INDEX) &gt;= (2 ^ (UInt(HACDBSBR_EL2().SZ) + 12)) DIVRM 8 ||
          HACDBSCONS_EL2().ERR_REASON != '00') then
        SetInterruptRequestLevel(<a link="enum_InterruptID_HACDBSIRQ" file="shared_pseudocode.xml">InterruptID_HACDBSIRQ</a>, <a link="enum_HIGH" file="shared_pseudocode.xml">HIGH</a>);
        return;
    elsif <a link="func_IsHACDBSIRQAsserted_0" file="shared_pseudocode.xml">IsHACDBSIRQAsserted</a>() then
        SetInterruptRequestLevel(<a link="enum_InterruptID_HACDBSIRQ" file="shared_pseudocode.xml">InterruptID_HACDBSIRQ</a>, <a link="enum_LOW" file="shared_pseudocode.xml">LOW</a>);
    end;

    let hacdbs_size : integer{} = UInt(HACDBSBR_EL2().SZ);
    var baddr : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>) = HACDBSBR_EL2().BADDR[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-13 : 0] :: Zeros{12};
    baddr[11 + hacdbs_size : 12] = Zeros{hacdbs_size};

    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescHACDBS_0" file="shared_pseudocode.xml">CreateAccDescHACDBS</a>();

    var addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    addrdesc.paddress.address = baddr + (8 * UInt(HACDBSCONS_EL2().INDEX));
    let nse2 : bit = '0';     // NSE2 has the Effective value of 0 within a PE.
    addrdesc.paddress.paspace = <a link="func_DecodePASpace_3" file="shared_pseudocode.xml">DecodePASpace</a>(nse2, <a link="func_EffectiveSCR_EL3_NSE_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NSE</a>(), <a link="func_EffectiveSCR_EL3_NS_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NS</a>());

    // Accesses to the HACDBS use the same memory attributes as used for stage 2 translation walks.
    addrdesc.memattrs = <a link="func_WalkMemAttrs_3" file="shared_pseudocode.xml">WalkMemAttrs</a>(VTCR_EL2().SH0, VTCR_EL2().IRGN0, VTCR_EL2().ORGN0);
    let emec : bit = (if IsFeatureImplemented(FEAT_MEC) &amp;&amp;
                         <a link="func_IsSCTLR2EL2Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL2Enabled</a>() then SCTLR2_EL2().EMEC else '0');
    addrdesc.mecid = <a link="func_AArch64_S2TTWalkMECID_2" file="shared_pseudocode.xml">AArch64_S2TTWalkMECID</a>(emec, accdesc.ss);

    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_1" file="shared_pseudocode.xml">NoFault</a>(accdesc);

    if IsFeatureImplemented(FEAT_RME) then
        fault.gpcf = <a link="func_GranuleProtectionCheck_2" file="shared_pseudocode.xml">GranuleProtectionCheck</a>(addrdesc, accdesc);

        if fault.gpcf.gpf != <a link="enum_GPCF_None" file="shared_pseudocode.xml">GPCF_None</a> then
            HACDBSCONS_EL2().ERR_REASON = <a link="global_HACDBS_ERR_REASON_STRUCTF" file="shared_pseudocode.xml">HACDBS_ERR_REASON_STRUCTF</a>;
            return;
        end;
    end;

    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
    var hacdbs_entry : bits(64);
    (memstatus, hacdbs_entry) = <a link="func_PhysMemRead_3" file="shared_pseudocode.xml">PhysMemRead</a>{64}(addrdesc, accdesc);

    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
        HACDBSCONS_EL2().ERR_REASON = <a link="global_HACDBS_ERR_REASON_STRUCTF" file="shared_pseudocode.xml">HACDBS_ERR_REASON_STRUCTF</a>;
        return;
    end;

    if <a link="func_BigEndian_1" file="shared_pseudocode.xml">BigEndian</a>(accdesc.acctype) then
        hacdbs_entry = <a link="func_BigEndianReverse_2" file="shared_pseudocode.xml">BigEndianReverse</a>{64}(hacdbs_entry);
    end;

    // If the Valid field is clear, do not perform any cleaning operation
    // and increment HACDBSCONS_EL2.INDEX.
    if hacdbs_entry[0] == '0' then
        HACDBSCONS_EL2().INDEX = HACDBSCONS_EL2().INDEX + 1;
        return;
    end;

    accdesc = <a link="func_CreateAccDescTTEUpdate_1" file="shared_pseudocode.xml">CreateAccDescTTEUpdate</a>(accdesc);
    var ipa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    ipa.paddress.address = hacdbs_entry[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:12] :: Zeros{12};

    let nsipa : bit       = hacdbs_entry[11];
    let paspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a> = <a link="func_DecodePASpace_3" file="shared_pseudocode.xml">DecodePASpace</a>(nse2, <a link="func_EffectiveSCR_EL3_NSE_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NSE</a>(), <a link="func_EffectiveSCR_EL3_NS_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NS</a>());
    ipa.paddress.paspace = (if accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> &amp;&amp; nsipa == '1' then <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>
                                                                       else paspace);

    let s1aarch64 : boolean = TRUE;
    let walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a> = <a link="func_AArch64_GetS2TTWParams_3" file="shared_pseudocode.xml">AArch64_GetS2TTWParams</a>(accdesc.ss, ipa.paddress.paspace,
                                                             s1aarch64);

    var descpaddr : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    var walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>;
    var descriptor : bits(128);
    if walkparams.d128 == '1' then
        (fault, descpaddr, walkstate, descriptor) = <a link="func_AArch64_S2Walk_5" file="shared_pseudocode.xml">AArch64_S2Walk</a>{128}(fault, ipa, walkparams,
                                                                        accdesc);
    else
        (fault, descpaddr, walkstate, descriptor[63:0]) = <a link="func_AArch64_S2Walk_5" file="shared_pseudocode.xml">AArch64_S2Walk</a>{64}(fault, ipa, walkparams,
                                                                             accdesc);
    end;

    // If the Access flag on the Block or Page descriptor is set to 0, this does not generate
    // an Access flag fault and the PE can still perform the cleaning operation on that descriptor.
    if fault.statuscode == <a link="enum_Fault_AccessFlag" file="shared_pseudocode.xml">Fault_AccessFlag</a> then
        fault.statuscode = <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;
    elsif fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        HACDBSCONS_EL2().ERR_REASON = <a link="global_HACDBS_ERR_REASON_IPAF" file="shared_pseudocode.xml">HACDBS_ERR_REASON_IPAF</a>;
        return;
    end;

    let hacdbs_level : integer = SInt(hacdbs_entry[3:1]);
    if walkstate.level != hacdbs_level || walkstate.contiguous == '1' then
        HACDBSCONS_EL2().ERR_REASON = <a link="global_HACDBS_ERR_REASON_IPHACF" file="shared_pseudocode.xml">HACDBS_ERR_REASON_IPHACF</a>;
        return;
    end;

    // For the purpose of cleaning HACDBS entries, it is not required that HW update of dirty bit
    // is enabled for a descriptor to be qualified as writable-clean or writable-dirty.

    // Check if the descriptor is neither writable-clean nor writable-dirty.
    if walkparams.s2pie == '1' then
        let perms : <a link="type_S2AccessControls" file="shared_pseudocode.xml">S2AccessControls</a> = <a link="func_AArch64_S2ComputePermissions_3" file="shared_pseudocode.xml">AArch64_S2ComputePermissions</a>(walkstate.permissions,
                                                                       walkparams, accdesc);
        if perms.w == '0' &amp;&amp; perms.w_mmu == '0' then
            HACDBSCONS_EL2().ERR_REASON = <a link="global_HACDBS_ERR_REASON_IPHACF" file="shared_pseudocode.xml">HACDBS_ERR_REASON_IPHACF</a>;
            return;
        end;

    // If DBM is 0, the descriptor is not writable-clean or writable-dirty.
    elsif descriptor[51] == '0' then
        HACDBSCONS_EL2().ERR_REASON = <a link="global_HACDBS_ERR_REASON_IPHACF" file="shared_pseudocode.xml">HACDBS_ERR_REASON_IPHACF</a>;
        return;
    end;

    // If the descriptor is writable-clean, do not perform any cleaning
    // operation and increment HACDBSCONS_EL2.INDEX.
    if descriptor[7] == '0' then
        HACDBSCONS_EL2().INDEX = HACDBSCONS_EL2().INDEX + 1;
        return;
    end;

    var new_descriptor : bits(128) = descriptor;
    new_descriptor[7] = '0';

    let descaccess : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescTTEUpdate_1" file="shared_pseudocode.xml">CreateAccDescTTEUpdate</a>(accdesc);
    if walkparams.d128 == '1' then
        (fault, -) = <a link="func_AArch64_MemSwapTableDesc_7" file="shared_pseudocode.xml">AArch64_MemSwapTableDesc</a>{128}(fault, descriptor, new_descriptor, walkparams.ee,
                                                   descaccess, descpaddr);
    else
        (fault, -) = <a link="func_AArch64_MemSwapTableDesc_7" file="shared_pseudocode.xml">AArch64_MemSwapTableDesc</a>{64}(fault, descriptor[63:0], new_descriptor[63:0],
                                                  walkparams.ee, descaccess, descpaddr);
    end;

    if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        HACDBSCONS_EL2().ERR_REASON = <a link="global_HACDBS_ERR_REASON_IPAF" file="shared_pseudocode.xml">HACDBS_ERR_REASON_IPAF</a>;
    else
        HACDBSCONS_EL2().INDEX = HACDBSCONS_EL2().INDEX + 1;
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/ic/AArch64_CanTrapIC" mylink="aarch64.functions.ic.AArch64_CanTrapIC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CanTrapIC()
// ===================
// Determines whether the execution of the IC instruction can be trapped.

func <anchor link="func_AArch64_CanTrapIC_3">AArch64_CanTrapIC</anchor>(cachetype : <a link="type_CacheType" file="shared_pseudocode.xml">CacheType</a>, cacheop : <a link="type_CacheOp" file="shared_pseudocode.xml">CacheOp</a>, opscope : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a>) =&gt; boolean
begin
    return (!<a link="func_AArch64_TreatICAsNOP_3" file="shared_pseudocode.xml">AArch64_TreatICAsNOP</a>(cachetype, cacheop, opscope) || ImpDefBool(
            &quot;When IC is treated as NOP, data cache maintenance operations are trapped&quot;));
end;</pstext></ps>
    <ps name="aarch64/functions/ic/AArch64_EffectiveOpScope" mylink="aarch64.functions.ic.AArch64_EffectiveOpScope" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_EffectiveOpScope()
// ==========================

func <anchor link="func_AArch64_EffectiveOpScope_1">AArch64_EffectiveOpScope</anchor>(opscope_in : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a>) =&gt; <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a>
begin
    var opscope : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a> = opscope_in;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> then return opscope; end;

    if opscope == <a link="enum_CacheOpScope_ALLU" file="shared_pseudocode.xml">CacheOpScope_ALLU</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().FB == '1' then
        opscope = <a link="enum_CacheOpScope_ALLUIS" file="shared_pseudocode.xml">CacheOpScope_ALLUIS</a>;
    end;

    return opscope;
end;</pstext></ps>
    <ps name="aarch64/functions/ic/AArch64_IC" mylink="aarch64.functions.ic.AArch64_IC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_IC()
// ============
// Perform Instruction Cache Operation.

func <anchor link="func_AArch64_IC_1">AArch64_IC</anchor>(opscope : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a>)
begin
    let regval : bits(64) = ARBITRARY : bits(64);
    <a link="func_AArch64_IC_2" file="shared_pseudocode.xml">AArch64_IC</a>(regval, opscope);
end;

// AArch64_IC()
// ============
// Perform Instruction Cache Operation.

func <anchor link="func_AArch64_IC_2">AArch64_IC</anchor>(regval : bits(64), opscope_in : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a>)
begin
    var cache : <a link="type_CacheRecord" file="shared_pseudocode.xml">CacheRecord</a>;
    var opscope : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a> = opscope_in;

    cache.acctype   = <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>;
    cache.cachetype = <a link="enum_CacheType_Instruction" file="shared_pseudocode.xml">CacheType_Instruction</a>;
    cache.cacheop   = <a link="enum_CacheOp_Invalidate" file="shared_pseudocode.xml">CacheOp_Invalidate</a>;
    cache.opscope   = opscope;

    if opscope IN {<a link="enum_CacheOpScope_ALLU" file="shared_pseudocode.xml">CacheOpScope_ALLU</a>,
                   <a link="enum_CacheOpScope_ALLUIS" file="shared_pseudocode.xml">CacheOpScope_ALLUIS</a>} then
        let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
        cache.cpas = <a link="func_CPASAtSecurityState_1" file="shared_pseudocode.xml">CPASAtSecurityState</a>(ss);
        opscope = <a link="func_AArch64_EffectiveOpScope_1" file="shared_pseudocode.xml">AArch64_EffectiveOpScope</a>(opscope);

        case opscope of
            when <a link="enum_CacheOpScope_ALLU" file="shared_pseudocode.xml">CacheOpScope_ALLU</a> =&gt;
                cache.shareability = <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a>;
            when <a link="enum_CacheOpScope_ALLUIS" file="shared_pseudocode.xml">CacheOpScope_ALLUIS</a> =&gt;
                cache.shareability = <a link="enum_Shareability_ISH" file="shared_pseudocode.xml">Shareability_ISH</a>;
            otherwise =&gt;
                unreachable;
        end;

        cache.regval = regval;
        CACHE_OP(cache);
    else
        assert opscope == <a link="enum_CacheOpScope_PoU" file="shared_pseudocode.xml">CacheOpScope_PoU</a>;

        if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
            if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} then
                cache.is_vmid_valid = TRUE;
                cache.vmid          = <a link="func_VMID_0" file="shared_pseudocode.xml">VMID</a>();
            else
                cache.is_vmid_valid = FALSE;
            end;
        else
            cache.is_vmid_valid = FALSE;
        end;

        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
            cache.is_asid_valid = TRUE;
            cache.asid          = <a link="func_ASID_0" file="shared_pseudocode.xml">ASID</a>();
        else
            cache.is_asid_valid = FALSE;
        end;

        let vaddress : bits(64) = regval;
        cache.vaddress = regval;

        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescIC_1" file="shared_pseudocode.xml">CreateAccDescIC</a>(cache);
        let aligned : boolean = TRUE;
        let size : integer = 0;
        var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_AArch64_TranslateAddress_4" file="shared_pseudocode.xml">AArch64_TranslateAddress</a>(vaddress, accdesc,
                                                                       aligned, size);

        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
            memaddrdesc.fault.vaddress = regval;
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(memaddrdesc.fault);
        end;

        cache.cpas         = <a link="func_CPASAtPAS_1" file="shared_pseudocode.xml">CPASAtPAS</a>(memaddrdesc.paddress.paspace);
        cache.paddress     = memaddrdesc.paddress;
        cache.shareability = memaddrdesc.memattrs.shareability;
        if memaddrdesc.memattrs.shareability == <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a> then
            cache.shareability = <a link="enum_Shareability_ISH" file="shared_pseudocode.xml">Shareability_ISH</a>;
        end;

        CACHE_OP(cache);
    end;
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/ic/AArch64_TreatICAsNOP" mylink="aarch64.functions.ic.AArch64_TreatICAsNOP" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TreatICAsNOP()
// ======================
// Determines whether the execution of the IC instruction is treated as a NOP.

func <anchor link="func_AArch64_TreatICAsNOP_3">AArch64_TreatICAsNOP</anchor>(cachetype : <a link="type_CacheType" file="shared_pseudocode.xml">CacheType</a>, cacheop : <a link="type_CacheOp" file="shared_pseudocode.xml">CacheOp</a>,
                          opscope : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a>) =&gt; boolean
begin
    if CTR_EL0().DIC == '1' then
        return ImpDefBool(&quot;IC is treated as NOP&quot;);
    end;

    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/functions/immediateop/ImmediateOp" mylink="aarch64.functions.immediateop.ImmediateOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ImmediateOp
// ===========
// Vector logical immediate instruction types.

type <anchor link="type_ImmediateOp">ImmediateOp</anchor> of enumeration {<anchor link="enum_ImmediateOp_MOVI">ImmediateOp_MOVI</anchor>, <anchor link="enum_ImmediateOp_MVNI">ImmediateOp_MVNI</anchor>,
                                 <anchor link="enum_ImmediateOp_ORR">ImmediateOp_ORR</anchor>, <anchor link="enum_ImmediateOp_BIC">ImmediateOp_BIC</anchor>};</pstext></ps>
    <ps name="aarch64/functions/logicalop/LogicalOp" mylink="aarch64.functions.logicalop.LogicalOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// LogicalOp
// =========
// Logical instruction types.

type <anchor link="type_LogicalOp">LogicalOp</anchor> of enumeration {<anchor link="enum_LogicalOp_AND">LogicalOp_AND</anchor>, <anchor link="enum_LogicalOp_EOR">LogicalOp_EOR</anchor>, <anchor link="enum_LogicalOp_ORR">LogicalOp_ORR</anchor>};</pstext></ps>
    <ps name="aarch64/functions/mec" mylink="aarch64.functions.mec" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">constant <anchor link="global_DEFAULT_MECID">DEFAULT_MECID</anchor> : bits(16) = Zeros{};</pstext></ps>
    <ps name="aarch64/functions/mec/AArch64_S1AMECFault" mylink="aarch64.functions.mec.AArch64_S1AMECFault" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1AMECFault()
// =====================
// Returns TRUE if a Translation fault should occur for Realm EL2 and Realm EL2&amp;0
// stage 1 translated addresses to Realm PA space.

func <anchor link="func_AArch64_S1AMECFault_5">AArch64_S1AMECFault</anchor>{N}(walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>, paspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
                            descriptor : bits(N)) =&gt; boolean
begin
    assert N IN {64,128};
    let descriptor_amec : bit = (if walkparams.d128 == '1' then descriptor[108]
                                    else descriptor[63]);

    return (walkparams.[emec,amec] == '10' &amp;&amp;
            regime IN {<a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a>, <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>} &amp;&amp;
            paspace == <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a> &amp;&amp;
            descriptor_amec == '1');
end;</pstext></ps>
    <ps name="aarch64/functions/mec/AArch64_S1DisabledOutputMECID" mylink="aarch64.functions.mec.AArch64_S1DisabledOutputMECID" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1DisabledOutputMECID()
// ===============================
// Returns the output MECID when stage 1 address translation is disabled.

func <anchor link="func_AArch64_S1DisabledOutputMECID_3">AArch64_S1DisabledOutputMECID</anchor>(walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
                                   paspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>) =&gt; bits(16)
begin
    if walkparams.emec == '0' then
        return <a link="global_DEFAULT_MECID" file="shared_pseudocode.xml">DEFAULT_MECID</a>;
    end;

    if ! regime IN {<a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a>, <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>, <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a>} then
        return <a link="global_DEFAULT_MECID" file="shared_pseudocode.xml">DEFAULT_MECID</a>;
    end;

    if paspace != <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a> then
        return <a link="global_DEFAULT_MECID" file="shared_pseudocode.xml">DEFAULT_MECID</a>;
    end;

    if regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> then
        return VMECID_P_EL2().MECID;
    else
        return MECID_P0_EL2().MECID;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/mec/AArch64_S1OutputMECID" mylink="aarch64.functions.mec.AArch64_S1OutputMECID" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1OutputMECID()
// =======================
// Returns the output MECID when stage 1 address translation is enabled.

func <anchor link="func_AArch64_S1OutputMECID_6">AArch64_S1OutputMECID</anchor>{N}(walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, varange : <a link="type_VARange" file="shared_pseudocode.xml">VARange</a>,
                              paspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>, descriptor : bits(N)) =&gt; bits(16)
begin
    assert N IN {64,128};

    if walkparams.emec == '0' then
        return <a link="global_DEFAULT_MECID" file="shared_pseudocode.xml">DEFAULT_MECID</a>;
    end;

    if paspace != <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a> then
        return <a link="global_DEFAULT_MECID" file="shared_pseudocode.xml">DEFAULT_MECID</a>;
    end;

    let descriptor_amec : bit = (if walkparams.d128 == '1' then descriptor[108]
                                    else descriptor[63]);
    case regime of
        when <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> =&gt;
            return MECID_RL_A_EL3().MECID;
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> =&gt;
            if descriptor_amec == '0' then
                return MECID_P0_EL2().MECID;
            else
                return MECID_A0_EL2().MECID;
            end;
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt;
            if varange == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then
                if descriptor_amec == '0' then
                    return MECID_P0_EL2().MECID;
                else
                    return MECID_A0_EL2().MECID;
                end;
            else
                if descriptor_amec == '0' then
                    return MECID_P1_EL2().MECID;
                else
                    return MECID_A1_EL2().MECID;
                end;
            end;
        // Stage 2 translation might later override the MECID according to AMEC configuration.
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt;
            return VMECID_P_EL2().MECID;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/mec/AArch64_S1TTWalkMECID" mylink="aarch64.functions.mec.AArch64_S1TTWalkMECID" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1TTWalkMECID()
// =======================
// Returns the associated MECID for the stage 1 translation table walk of the given
// translation regime and Security state.

func <anchor link="func_AArch64_S1TTWalkMECID_3">AArch64_S1TTWalkMECID</anchor>(emec : bit, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>) =&gt; bits(16)
begin
    if emec == '0' then
        return <a link="global_DEFAULT_MECID" file="shared_pseudocode.xml">DEFAULT_MECID</a>;
    end;

    if ss != <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> then
        return <a link="global_DEFAULT_MECID" file="shared_pseudocode.xml">DEFAULT_MECID</a>;
    end;

    case regime of
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> =&gt;
            return MECID_P0_EL2().MECID;
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt;
            if TCR_EL2().A1 == '0' then
                return MECID_P1_EL2().MECID;
            else
                return MECID_P0_EL2().MECID;
            end;
        // Stage 2 translation for a stage 1 walk might later override the
        // MECID according to AMEC configuration.
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt;
            return VMECID_P_EL2().MECID;
        otherwise =&gt;
            unreachable;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/mec/AArch64_S2OutputMECID" mylink="aarch64.functions.mec.AArch64_S2OutputMECID" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2OutputMECID()
// =======================
// Returns the output MECID for stage 2 address translation.

func <anchor link="func_AArch64_S2OutputMECID_4">AArch64_S2OutputMECID</anchor>{N}(walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>, paspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>,
                              descriptor : bits(N)) =&gt; bits(16)
begin
    assert N IN {64,128};

    if walkparams.emec == '0' then
        return <a link="global_DEFAULT_MECID" file="shared_pseudocode.xml">DEFAULT_MECID</a>;
    end;

    if paspace != <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a> then
        return <a link="global_DEFAULT_MECID" file="shared_pseudocode.xml">DEFAULT_MECID</a>;
    end;

    let descriptor_amec : bit = (if walkparams.d128 == '1' then descriptor[108]
                                    else descriptor[63]);
    if descriptor_amec == '0' then
        return VMECID_P_EL2().MECID;
    else
        return VMECID_A_EL2().MECID;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/mec/AArch64_S2TTWalkMECID" mylink="aarch64.functions.mec.AArch64_S2TTWalkMECID" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2TTWalkMECID()
// =======================
// Returns the associated MECID for the stage 2 translation table walk of the
// given Security state.

func <anchor link="func_AArch64_S2TTWalkMECID_2">AArch64_S2TTWalkMECID</anchor>(emec : bit, ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>) =&gt; bits(16)
begin
    if emec == '0' then
        return <a link="global_DEFAULT_MECID" file="shared_pseudocode.xml">DEFAULT_MECID</a>;
    end;

    if ss != <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> then
        return <a link="global_DEFAULT_MECID" file="shared_pseudocode.xml">DEFAULT_MECID</a>;
    end;

    //Stage 2 translation might later override the MECID according to AMEC configuration
    return VMECID_P_EL2().MECID;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/AArch64_AccessIsTagChecked" mylink="aarch64.functions.memory.AArch64_AccessIsTagChecked" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_AccessIsTagChecked()
// ============================
// TRUE if a given access is tag-checked, FALSE otherwise.

func <anchor link="func_AArch64_AccessIsTagChecked_2">AArch64_AccessIsTagChecked</anchor>(vaddr : bits(64), accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; boolean
begin
    assert accdesc.tagchecked;

    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        return FALSE;
    end;

    if !<a link="func_IsMTEEnabled_1" file="shared_pseudocode.xml">IsMTEEnabled</a>(accdesc.el) then
        return FALSE;
    end;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.TCO == '1' then
        return FALSE;
    end;

    if (<a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() &amp;&amp; EDSCR().MA == '1' &amp;&amp;
          <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_NODTRTAGCHK" file="shared_pseudocode.xml">Unpredictable_NODTRTAGCHK</a>)) then
        return FALSE;
    end;

    if (IsFeatureImplemented(FEAT_MTE_STORE_ONLY) &amp;&amp; !accdesc.write &amp;&amp;
          <a link="func_StoreOnlyTagCheckingEnabled_1" file="shared_pseudocode.xml">StoreOnlyTagCheckingEnabled</a>(accdesc.el)) then
        return FALSE;
    end;

    let is_instr : boolean = FALSE;
    if (<a link="func_EffectiveMTX_3" file="shared_pseudocode.xml">EffectiveMTX</a>(vaddr, is_instr, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) == '0' &amp;&amp;
          <a link="func_EffectiveTBI_3" file="shared_pseudocode.xml">EffectiveTBI</a>(vaddr, is_instr, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) == '0') then
        return FALSE;
    end;

    if (<a link="func_EffectiveTCMA_2" file="shared_pseudocode.xml">EffectiveTCMA</a>(vaddr, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) == '1' &amp;&amp;
          (vaddr[59:55] == '00000' || vaddr[59:55] == '11111')) then
        return FALSE;
    end;

    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/AArch64_AddressWithAllocationTag" mylink="aarch64.functions.memory.AArch64_AddressWithAllocationTag" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_AddressWithAllocationTag()
// ==================================
// Generate a 64-bit value containing a Logical Address Tag from a 64-bit
// virtual address and an Allocation Tag.

func <anchor link="func_AArch64_AddressWithAllocationTag_2">AArch64_AddressWithAllocationTag</anchor>(address : bits(64), allocation_tag : bits(4)) =&gt; bits(64)
begin
    return address[63:60]::allocation_tag::address[55:0];
end;</pstext></ps>
    <ps name="aarch64/functions/memory/AArch64_AllocationTagCheck" mylink="aarch64.functions.memory.AArch64_AllocationTagCheck" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_AllocationTagCheck()
// ============================
// Performs an Allocation Tag Check operation for a memory access and
// returns whether the check passed.

func <anchor link="func_AArch64_AllocationTagCheck_3">AArch64_AllocationTagCheck</anchor>(memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                                ltag : bits(4)) =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_2" file="shared_pseudocode.xml">NoFault</a>(accdesc, memaddrdesc.vaddress);
    if memaddrdesc.memattrs.tags == <a link="enum_MemTag_AllocationTagged" file="shared_pseudocode.xml">MemTag_AllocationTagged</a> then
        var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
        var readtag : bits(4);

        // Physical tagging needs no further translation, use the data PA to read the tag
        (memstatus, readtag) = <a link="func_PhysMemTagRead_2" file="shared_pseudocode.xml">PhysMemTagRead</a>(memaddrdesc, accdesc);
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            let iswrite : boolean = FALSE;
            return <a link="func_ExternalFault_5" file="shared_pseudocode.xml">ExternalFault</a>(memstatus, iswrite, memaddrdesc, 1, accdesc);
        end;

        if ltag != readtag then
            fault.statuscode = <a link="enum_Fault_TagCheck" file="shared_pseudocode.xml">Fault_TagCheck</a>;
        end;
    end;

    return fault;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/AArch64_AllocationTagFromAddress" mylink="aarch64.functions.memory.AArch64_AllocationTagFromAddress" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_AllocationTagFromAddress()
// ==================================
// Generate an Allocation Tag from a 64-bit value containing a Logical Address Tag.

func <anchor link="func_AArch64_AllocationTagFromAddress_1">AArch64_AllocationTagFromAddress</anchor>(tagged_address : bits(64)) =&gt; bits(4)
begin
    return tagged_address[59:56];
end;</pstext></ps>
    <ps name="aarch64/functions/memory/AArch64_CanonicalTagCheck" mylink="aarch64.functions.memory.AArch64_CanonicalTagCheck" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CanonicalTagCheck()
// ===========================
// Performs a Canonical Tag Check operation for a memory access and
// returns whether the check passed.

func <anchor link="func_AArch64_CanonicalTagCheck_2">AArch64_CanonicalTagCheck</anchor>(memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, ltag : bits(4)) =&gt; boolean
begin
    let expected_tag : bits(4) = if memaddrdesc.vaddress[55] == '0' then '0000' else '1111';
    return ltag == expected_tag;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/AArch64_CheckTag" mylink="aarch64.functions.memory.AArch64_CheckTag" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CheckTag()
// ==================
// Performs a Tag Check operation for a memory access and returns a FaultRecord indicating if
// the check passed. If Tag Check Faults are asynchronously accumulated, a Tag Check Fault
// exception is recorded in TFSR_ELx.

func <anchor link="func_AArch64_CheckTag_5">AArch64_CheckTag</anchor>(memaddrdesc_in : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                      readcheck : boolean, size : integer, ltag : bits(4)) =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin
    var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = memaddrdesc_in;
    // NoFault() will set fault.write to FALSE to accesses that perform both a read and a write.
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>            = <a link="func_NoFault_2" file="shared_pseudocode.xml">NoFault</a>(accdesc, memaddrdesc.vaddress);
    let granules : integer             = Max(size DIVRM <a link="global_TAG_GRANULE" file="shared_pseudocode.xml">TAG_GRANULE</a>, 1);
    let forcesync : boolean            = accdesc.nonfault || (accdesc.firstfault &amp;&amp; !accdesc.first);
    let tcf : <a link="type_TCFType" file="shared_pseudocode.xml">TCFType</a>                  = <a link="func_AArch64_EffectiveTCF_2" file="shared_pseudocode.xml">AArch64_EffectiveTCF</a>(accdesc.el, readcheck);

    for i = 0 to granules - 1 do
        case memaddrdesc.memattrs.tags of
            when <a link="enum_MemTag_AllocationTagged" file="shared_pseudocode.xml">MemTag_AllocationTagged</a> =&gt;
                fault = <a link="func_AArch64_AllocationTagCheck_3" file="shared_pseudocode.xml">AArch64_AllocationTagCheck</a>(memaddrdesc, accdesc, ltag);
                if fault.statuscode == <a link="enum_Fault_TagCheck" file="shared_pseudocode.xml">Fault_TagCheck</a> then
                    if tcf == <a link="enum_TCFType_Sync" file="shared_pseudocode.xml">TCFType_Sync</a> || forcesync then
                        fault.statuscode = <a link="enum_Fault_TagCheck" file="shared_pseudocode.xml">Fault_TagCheck</a>;
                        return fault;
                    elsif tcf == <a link="enum_TCFType_Async" file="shared_pseudocode.xml">TCFType_Async</a> then
                        <a link="func_AArch64_ReportTagCheckFault_2" file="shared_pseudocode.xml">AArch64_ReportTagCheckFault</a>(accdesc.el, memaddrdesc.vaddress[55]);
                        fault.statuscode = <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;
                        return fault;
                    else
                        // Tag Check Faults have no effect on the PE.
                        fault.statuscode = <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;
                    end;
                elsif fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
                    return fault;
                end;
            when <a link="enum_MemTag_CanonicallyTagged" file="shared_pseudocode.xml">MemTag_CanonicallyTagged</a> =&gt;
                if !<a link="func_AArch64_CanonicalTagCheck_2" file="shared_pseudocode.xml">AArch64_CanonicalTagCheck</a>(memaddrdesc, ltag) then
                    if tcf == <a link="enum_TCFType_Sync" file="shared_pseudocode.xml">TCFType_Sync</a> || forcesync then
                        fault.statuscode = <a link="enum_Fault_TagCheck" file="shared_pseudocode.xml">Fault_TagCheck</a>;
                        return fault;
                    elsif tcf == <a link="enum_TCFType_Async" file="shared_pseudocode.xml">TCFType_Async</a> then
                        <a link="func_AArch64_ReportTagCheckFault_2" file="shared_pseudocode.xml">AArch64_ReportTagCheckFault</a>(accdesc.el, memaddrdesc.vaddress[55]);
                        return fault;
                    else
                        // Tag Check Faults have no effect on the PE.
                        pass;
                    end;
                end;
            when <a link="enum_MemTag_Untagged" file="shared_pseudocode.xml">MemTag_Untagged</a> =&gt;
                pass;
            otherwise =&gt;
                unreachable;
        end;

        memaddrdesc.paddress.address = memaddrdesc.paddress.address + <a link="global_TAG_GRANULE" file="shared_pseudocode.xml">TAG_GRANULE</a>;
        memaddrdesc.vaddress         = memaddrdesc.vaddress + <a link="global_TAG_GRANULE" file="shared_pseudocode.xml">TAG_GRANULE</a>;
    end;

    return fault;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/AArch64_IsUnprivAccessPriv" mylink="aarch64.functions.memory.AArch64_IsUnprivAccessPriv" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_IsUnprivAccessPriv()
// ============================
// Returns TRUE if an unprivileged access is privileged, and FALSE otherwise.

func <anchor link="func_AArch64_IsUnprivAccessPriv_0">AArch64_IsUnprivAccessPriv</anchor>() =&gt; boolean
begin
    var privileged : boolean;

    case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL of
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            privileged = FALSE;
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt; privileged = <a link="func_EffectiveHCR_EL2_NVx_0" file="shared_pseudocode.xml">EffectiveHCR_EL2_NVx</a>()[1:0] == '11';
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt; privileged = !<a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>);
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            privileged = TRUE;
    end;

    if IsFeatureImplemented(FEAT_UAO) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.UAO == '1' then
        privileged = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
    end;

    return privileged;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/AArch64_LogicalAddressTag" mylink="aarch64.functions.memory.AArch64_LogicalAddressTag" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_LogicalAddressTag()
// ===========================
// Extract the Logical Address Tag from an address

func <anchor link="func_AArch64_LogicalAddressTag_1">AArch64_LogicalAddressTag</anchor>(vaddr : bits(64)) =&gt; bits(4)
begin
    return vaddr[59:56];
end;</pstext></ps>
    <ps name="aarch64/functions/memory/AArch64_MemSingle" mylink="aarch64.functions.memory.AArch64_MemSingle" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_MemSingle - accessor
// ============================

accessor <anchor link="accessor_AArch64_MemSingle_4">AArch64_MemSingle</anchor>{size : integer{8, 16, 32, 64, 128, 256}}(address : bits(64),
                                                                    accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                                                                    aligned : boolean
                                                                   ) &lt;=&gt; value : bits(size)
begin
    // Perform an atomic, little-endian read of 'size' bits.
    getter
        let bytes : integer{} = size DIV 8;
        var value : bits(size);
        var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
        var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;

        (value, memaddrdesc, memstatus) = <a link="func_AArch64_MemSingleRead_4" file="shared_pseudocode.xml">AArch64_MemSingleRead</a>{size}(address, accdesc, aligned);

        // Check for a fault from translation or the output of translation.
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(memaddrdesc.fault);
        end;

        // Check for external aborts.
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            <a link="func_HandleExternalAbort_5" file="shared_pseudocode.xml">HandleExternalAbort</a>(memstatus, accdesc.write, memaddrdesc, bytes, accdesc);
        end;

        return value;
    end;

    // Perform an atomic, little-endian write of 'size' bits.
    setter
        let bytes : integer{} = size DIV 8;
        var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
        var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;

        (memaddrdesc, memstatus) = <a link="func_AArch64_MemSingleWrite_5" file="shared_pseudocode.xml">AArch64_MemSingleWrite</a>{size}(address, accdesc, aligned, value);

        // Check for a fault from translation or the output of translation.
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(memaddrdesc.fault);
        end;

        // Check for external aborts.
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            <a link="func_HandleExternalWriteAbort_4" file="shared_pseudocode.xml">HandleExternalWriteAbort</a>(memstatus, memaddrdesc, bytes, accdesc);
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/AArch64_MemSingleRead" mylink="aarch64.functions.memory.AArch64_MemSingleRead" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_MemSingleRead()
// =======================
// Perform an atomic, little-endian read of 'size' bits.

func <anchor link="func_AArch64_MemSingleRead_4">AArch64_MemSingleRead</anchor>{size : integer{8, 16, 32, 64, 128, 256}}(address : bits(64),
                                                                    accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                                                                    aligned : boolean
                                                                   ) =&gt; (bits(size),
                                                                         <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                                                                         <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>)
begin
    var value : bits(size) = ARBITRARY : bits(size);
    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a> = ARBITRARY : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
    let bytes : integer{} = size DIV 8;
    memstatus.statuscode = <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = accdesc_in;
    if IsFeatureImplemented(FEAT_LSE2) then
        let quantity : integer = <a link="func_MemSingleGranule_0" file="shared_pseudocode.xml">MemSingleGranule</a>();
        assert ((IsFeatureImplemented(FEAT_LS64WB) &amp;&amp;
                 bytes == 32 &amp;&amp; accdesc.acctype == <a link="enum_AccessType_ASIMD" file="shared_pseudocode.xml">AccessType_ASIMD</a>) ||
                 <a link="func_AllInAlignedQuantity_4" file="shared_pseudocode.xml">AllInAlignedQuantity</a>{64}(address, bytes, quantity));
    else
        assert IsAlignedSize(address, bytes);
    end;

    // If the instruction encoding permits tag checking, confer with system register configuration
    // which may override this.
    if accdesc.tagchecked then
        accdesc.tagchecked = <a link="func_AArch64_AccessIsTagChecked_2" file="shared_pseudocode.xml">AArch64_AccessIsTagChecked</a>(address, accdesc);
    end;

    var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    memaddrdesc = <a link="func_AArch64_TranslateAddress_4" file="shared_pseudocode.xml">AArch64_TranslateAddress</a>(address, accdesc, aligned, bytes);

    // Check for aborts or debug exceptions
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        return (value, memaddrdesc, memstatus);
    end;

    // Memory array access
    if accdesc.tagchecked then
        let ltag : bits(4) = <a link="func_AArch64_LogicalAddressTag_1" file="shared_pseudocode.xml">AArch64_LogicalAddressTag</a>(address);
        let readcheck : boolean = TRUE;
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AArch64_CheckTag_5" file="shared_pseudocode.xml">AArch64_CheckTag</a>(memaddrdesc, accdesc, readcheck, bytes, ltag);
        if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
            memaddrdesc.fault = fault;
            return (value, memaddrdesc, memstatus);
        end;
    end;

    if accdesc.acctype != <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> &amp;&amp; <a link="global_SPESampleInFlight" file="shared_pseudocode.xml">SPESampleInFlight</a> then
        let is_load : boolean = TRUE;
        <a link="func_SPESampleLoadStore_3" file="shared_pseudocode.xml">SPESampleLoadStore</a>(is_load, accdesc, memaddrdesc);
    end;
    var atomic : boolean;
    if <a link="func_IsWBShareable_1" file="shared_pseudocode.xml">IsWBShareable</a>(memaddrdesc.memattrs) then
        atomic = TRUE;
    elsif accdesc.exclusive then
        atomic = TRUE;
    elsif (accdesc.acctype == <a link="enum_AccessType_SVE" file="shared_pseudocode.xml">AccessType_SVE</a> &amp;&amp; accdesc.predicated &amp;&amp;
            bytes == 8 &amp;&amp; IsAlignedSize(address, 8)) then
        // An SVE predicated load of a 128-bit element that is 64-bit aligned
        // is treated as a pair of 64-bit single-copy atomic accesses.
        // This is one of the 64-bit single-copy atomic access.
        atomic = TRUE;
    elsif aligned then
        atomic = !accdesc.ispair;
    else
        // Misaligned accesses within MemSingleGranule() byte aligned memory but
        // not Normal Cacheable Writeback are Atomic
        atomic = ImpDefBool(&quot;FEAT_LSE2: access is atomic&quot;);
    end;

    if atomic then
        (memstatus, value) = <a link="func_PhysMemRead_3" file="shared_pseudocode.xml">PhysMemRead</a>{size}(memaddrdesc, accdesc);

    elsif accdesc.acctype == <a link="enum_AccessType_ASIMD" file="shared_pseudocode.xml">AccessType_ASIMD</a> &amp;&amp; bytes == 32 &amp;&amp; accdesc.ispair then
        // A 32 byte LDP (SIMD&amp;FP) that does not target Normal Inner Write-Back, Outer
        // Write-Back cacheable, Shareable memory is treated as four 8 byte atomic accesses.
        // As this access was not split in Mem(), it must be aligned to 32 bytes.
        assert IsAlignedSize(address, 32);
        accdesc.ispair = FALSE;
        for i = 0 to 3 do
            if !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then     // Do not continue past a fault
                (memstatus, value[i*64+:64]) = <a link="func_PhysMemRead_3" file="shared_pseudocode.xml">PhysMemRead</a>{64}(memaddrdesc, accdesc);
            end;

            if !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
                memaddrdesc.paddress.address = memaddrdesc.paddress.address + 8;
                memaddrdesc.vaddress         = memaddrdesc.vaddress + 8;
            end;
        end;

    elsif aligned &amp;&amp; accdesc.ispair then
        let half : integer{} = (size DIV 2) as integer{32, 64, 128};
        (memstatus, value[0*:half]) = <a link="func_PhysMemRead_3" file="shared_pseudocode.xml">PhysMemRead</a>{half}(memaddrdesc, accdesc);

        if !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            memaddrdesc.paddress.address = memaddrdesc.paddress.address + (half DIV 8);
            memaddrdesc.vaddress         = memaddrdesc.vaddress + (half DIV 8);
            (memstatus, value[1*:half]) = <a link="func_PhysMemRead_3" file="shared_pseudocode.xml">PhysMemRead</a>{half}(memaddrdesc, accdesc);
        end;

    else
        for i = 0 to bytes-1 do
            if !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then     // Do not continue past a fault
                (memstatus, value[i*:8]) = <a link="func_PhysMemRead_3" file="shared_pseudocode.xml">PhysMemRead</a>{8}(memaddrdesc, accdesc);
            end;

            if !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
                memaddrdesc.paddress.address = memaddrdesc.paddress.address + 1;
                memaddrdesc.vaddress         = memaddrdesc.vaddress + 1;
            end;

        end;
    end;

    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
        return (value, memaddrdesc, memstatus);
    end;

    if accdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> then
        memaddrdesc.fault = <a link="func_AArch64_CheckDebug_3" file="shared_pseudocode.xml">AArch64_CheckDebug</a>(address, accdesc, bytes);
    end;

    return (value, memaddrdesc, memstatus);
end;</pstext></ps>
    <ps name="aarch64/functions/memory/AArch64_MemSingleWrite" mylink="aarch64.functions.memory.AArch64_MemSingleWrite" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_MemSingleWrite()
// ========================
// Perform an atomic, little-endian write of 'size' bits.

func <anchor link="func_AArch64_MemSingleWrite_5">AArch64_MemSingleWrite</anchor>{size : integer{8, 16, 32, 64, 128, 256}}(address : bits(64),
                                                                     accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                                                                     aligned : boolean,
                                                                     value : bits(size)
                                                         ) =&gt; (<a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>)
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = accdesc_in;
    let bytes : integer{} = size DIV 8;
    if IsFeatureImplemented(FEAT_LSE2) then
        let quantity : integer = <a link="func_MemSingleGranule_0" file="shared_pseudocode.xml">MemSingleGranule</a>();
        assert ((IsFeatureImplemented(FEAT_LS64WB) &amp;&amp;
                 bytes == 32 &amp;&amp; accdesc.acctype == <a link="enum_AccessType_ASIMD" file="shared_pseudocode.xml">AccessType_ASIMD</a>) ||
                 <a link="func_AllInAlignedQuantity_4" file="shared_pseudocode.xml">AllInAlignedQuantity</a>{64}(address, bytes, quantity));
    else
        assert IsAlignedSize(address, bytes);
    end;

    // If the instruction encoding permits tag checking, confer with system register configuration
    // which may override this.
    if accdesc.tagchecked then
        accdesc.tagchecked = <a link="func_AArch64_AccessIsTagChecked_2" file="shared_pseudocode.xml">AArch64_AccessIsTagChecked</a>(address, accdesc);
    end;

    var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a> = ARBITRARY : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
    memaddrdesc = <a link="func_AArch64_TranslateAddress_4" file="shared_pseudocode.xml">AArch64_TranslateAddress</a>(address, accdesc, aligned, bytes);

    // Check for aborts or debug exceptions
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        return (memaddrdesc, memstatus);
    end;

    // Effect on exclusives
    if memaddrdesc.memattrs.shareability != <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a> then
        ClearExclusiveByAddress(memaddrdesc.paddress, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), bytes);
    end;

    if accdesc.tagchecked then
        let ltag : bits(4) = <a link="func_AArch64_LogicalAddressTag_1" file="shared_pseudocode.xml">AArch64_LogicalAddressTag</a>(address);
        let readcheck : boolean = FALSE;
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AArch64_CheckTag_5" file="shared_pseudocode.xml">AArch64_CheckTag</a>(memaddrdesc, accdesc, readcheck, bytes, ltag);
        if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
            memaddrdesc.fault = fault;
            return (memaddrdesc, memstatus);
        end;
    end;

    if <a link="global_SPESampleInFlight" file="shared_pseudocode.xml">SPESampleInFlight</a> then
        let is_load : boolean = FALSE;
        <a link="func_SPESampleLoadStore_3" file="shared_pseudocode.xml">SPESampleLoadStore</a>(is_load, accdesc, memaddrdesc);
    end;

    var atomic : boolean;
    if <a link="func_IsWBShareable_1" file="shared_pseudocode.xml">IsWBShareable</a>(memaddrdesc.memattrs) then
        atomic = TRUE;
    elsif accdesc.exclusive then
        atomic = TRUE;
    elsif (accdesc.acctype == <a link="enum_AccessType_SVE" file="shared_pseudocode.xml">AccessType_SVE</a> &amp;&amp; accdesc.predicated &amp;&amp;
            bytes == 8 &amp;&amp; IsAlignedSize(address, 8)) then
        // An SVE predicated load of a 128-bit element that is 64-bit aligned
        // is treated as a pair of 64-bit single-copy atomic accesses.
        // This is one of the 64-bit single-copy atomic access.
        atomic = TRUE;
    elsif aligned then
        atomic = !accdesc.ispair;
    else
        // Misaligned accesses within MemSingleGranule() byte aligned memory but
        // not Normal Cacheable Writeback are Atomic
        atomic = ImpDefBool(&quot;FEAT_LSE2: access is atomic&quot;);
    end;
    if atomic then
        memstatus = <a link="func_PhysMemWrite_4" file="shared_pseudocode.xml">PhysMemWrite</a>{size}(memaddrdesc, accdesc, value);
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            return (memaddrdesc, memstatus);
        end;

    elsif accdesc.acctype == <a link="enum_AccessType_ASIMD" file="shared_pseudocode.xml">AccessType_ASIMD</a> &amp;&amp; bytes == 32 &amp;&amp; accdesc.ispair then
        // A 32 byte STP (SIMD&amp;FP) that does not target Normal Inner Write-Back, Outer
        // Write-Back cacheable, Shareable memory is treated as four 8 byte atomic accesses.
        // As this access was not split in Mem(), it must be aligned to 32 bytes.
        assert IsAlignedSize(address, 32);
        accdesc.ispair = FALSE;
        for i = 0 to 3 do
            memstatus = <a link="func_PhysMemWrite_4" file="shared_pseudocode.xml">PhysMemWrite</a>{64}(memaddrdesc, accdesc, value[64*i+:64]);
            if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
                return (memaddrdesc, memstatus);
            end;
            memaddrdesc.paddress.address = memaddrdesc.paddress.address + 8;
            memaddrdesc.vaddress         = memaddrdesc.vaddress + 8;
        end;

    elsif aligned &amp;&amp; accdesc.ispair then
        let half : integer{} = (size DIV 2) as integer{32, 64};
        memstatus = <a link="func_PhysMemWrite_4" file="shared_pseudocode.xml">PhysMemWrite</a>{half}(memaddrdesc, accdesc, value[0*:half]);
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            return (memaddrdesc, memstatus);
        end;

        memaddrdesc.paddress.address = memaddrdesc.paddress.address + (half DIV 8);
        memaddrdesc.vaddress         = memaddrdesc.vaddress + (half DIV 8);
        memstatus = <a link="func_PhysMemWrite_4" file="shared_pseudocode.xml">PhysMemWrite</a>{half}(memaddrdesc, accdesc, value[1*:half]);
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            return (memaddrdesc, memstatus);
        end;

    else
        for i = 0 to bytes-1 do
            memstatus = <a link="func_PhysMemWrite_4" file="shared_pseudocode.xml">PhysMemWrite</a>{8}(memaddrdesc, accdesc, value[i*:8]);
            if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
                return (memaddrdesc, memstatus);
            end;
            memaddrdesc.paddress.address = memaddrdesc.paddress.address + 1;
            memaddrdesc.vaddress         = memaddrdesc.vaddress + 1;
        end;
    end;

    return (memaddrdesc, memstatus);
end;</pstext></ps>
    <ps name="aarch64/functions/memory/AArch64_MemTag" mylink="aarch64.functions.memory.AArch64_MemTag" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_MemTag - accessor
// =========================

accessor <anchor link="accessor_AArch64_MemTag_2">AArch64_MemTag</anchor>(address : bits(64), accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) &lt;=&gt; value : bits(4)
begin
    // Load an Allocation Tag from memory.
    getter
        var value : bits(4);
        var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
        var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
        (value, memaddrdesc, memstatus) = <a link="func_AArch64_MemTagRead_2" file="shared_pseudocode.xml">AArch64_MemTagRead</a>(address, accdesc);

        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(memaddrdesc.fault);
        end;

        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            <a link="func_HandleExternalReadAbort_4" file="shared_pseudocode.xml">HandleExternalReadAbort</a>(memstatus, memaddrdesc, 1, accdesc);
        end;

        return value;
    end;

    // Store an Allocation Tag to memory.
    setter
        var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
        var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
        (memaddrdesc, memstatus) = <a link="func_AArch64_MemTagWrite_3" file="shared_pseudocode.xml">AArch64_MemTagWrite</a>(address, accdesc, value);

        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(memaddrdesc.fault);
        end;

        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            <a link="func_HandleExternalWriteAbort_4" file="shared_pseudocode.xml">HandleExternalWriteAbort</a>(memstatus, memaddrdesc, 1, accdesc);
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/AArch64_MemTagRead" mylink="aarch64.functions.memory.AArch64_MemTagRead" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_MemTagRead()
// ====================
// Load an Allocation Tag from memory.

func <anchor link="func_AArch64_MemTagRead_2">AArch64_MemTagRead</anchor>(address : bits(64),
                        accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
                        ) =&gt; (bits(4), <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>)
begin
    assert accdesc_in.tagaccess &amp;&amp; !accdesc_in.tagchecked;

    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>      = accdesc_in;
    var tag : bits(4)                   = ARBITRARY : bits(4);
    var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    var memtagtype : <a link="type_MemTagType" file="shared_pseudocode.xml">MemTagType</a>         = ARBITRARY : <a link="type_MemTagType" file="shared_pseudocode.xml">MemTagType</a>;
    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>    = ARBITRARY : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;

    let aligned : boolean = TRUE;

    accdesc.tagaccess = <a link="func_IsMTEEnabled_1" file="shared_pseudocode.xml">IsMTEEnabled</a>(accdesc.el);

    (memtagtype, memaddrdesc) = <a link="func_AArch64_TranslateTagAddress_4" file="shared_pseudocode.xml">AArch64_TranslateTagAddress</a>(address, accdesc, aligned, <a link="global_TAG_GRANULE" file="shared_pseudocode.xml">TAG_GRANULE</a>);

    // Check for aborts or debug exceptions
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        return (tag, memaddrdesc, memstatus);
    end;

    if accdesc.tagaccess &amp;&amp; memtagtype == <a link="enum_MemTag_AllocationTagged" file="shared_pseudocode.xml">MemTag_AllocationTagged</a> then
        (memstatus, tag) = <a link="func_PhysMemTagRead_2" file="shared_pseudocode.xml">PhysMemTagRead</a>(memaddrdesc, accdesc);
        return (tag, memaddrdesc, memstatus);
    elsif (IsFeatureImplemented(FEAT_MTE_CANONICAL_TAGS) &amp;&amp;
             accdesc.tagaccess &amp;&amp; memtagtype == <a link="enum_MemTag_CanonicallyTagged" file="shared_pseudocode.xml">MemTag_CanonicallyTagged</a>) then
        tag = if address[55] == '0' then '0000' else '1111';
        return (tag, memaddrdesc, memstatus);
    else
        // Otherwise read the tag as zero
        tag = '0000';
        return (tag, memaddrdesc, memstatus);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/AArch64_MemTagWrite" mylink="aarch64.functions.memory.AArch64_MemTagWrite" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_MemTagWrite()
// =====================
// Store an Allocation Tag to memory.

func <anchor link="func_AArch64_MemTagWrite_3">AArch64_MemTagWrite</anchor>(address : bits(64),
                         accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                         value : bits(4)) =&gt; (<a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>)
begin
    assert accdesc_in.tagaccess &amp;&amp; !accdesc_in.tagchecked;

    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>      = accdesc_in;
    var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    var memtagtype : <a link="type_MemTagType" file="shared_pseudocode.xml">MemTagType</a>         = ARBITRARY : <a link="type_MemTagType" file="shared_pseudocode.xml">MemTagType</a>;
    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>    = ARBITRARY : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;

    let aligned : boolean = IsAlignedSize(address, <a link="global_TAG_GRANULE" file="shared_pseudocode.xml">TAG_GRANULE</a>);

    // Stores of allocation tags must be aligned
    if !aligned then
        memaddrdesc.fault = <a link="func_AlignmentFault_2" file="shared_pseudocode.xml">AlignmentFault</a>(accdesc, address);
        return (memaddrdesc, memstatus);
    end;

    accdesc.tagaccess = <a link="func_IsMTEEnabled_1" file="shared_pseudocode.xml">IsMTEEnabled</a>(accdesc.el);

    (memtagtype, memaddrdesc) = <a link="func_AArch64_TranslateTagAddress_4" file="shared_pseudocode.xml">AArch64_TranslateTagAddress</a>(address, accdesc, aligned, <a link="global_TAG_GRANULE" file="shared_pseudocode.xml">TAG_GRANULE</a>);

    // Check for aborts or debug exceptions
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        return (memaddrdesc, memstatus);
    end;

    if accdesc.tagaccess &amp;&amp; memtagtype == <a link="enum_MemTag_AllocationTagged" file="shared_pseudocode.xml">MemTag_AllocationTagged</a> then
        memstatus = <a link="func_PhysMemTagWrite_3" file="shared_pseudocode.xml">PhysMemTagWrite</a>(memaddrdesc, accdesc, value);
    end;
    return (memaddrdesc, memstatus);
end;</pstext></ps>
    <ps name="aarch64/functions/memory/AArch64_UnalignedAccessFaults" mylink="aarch64.functions.memory.AArch64_UnalignedAccessFaults" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_UnalignedAccessFaults()
// ===============================
// Determine whether the unaligned access generates an Alignment fault

func <anchor link="func_AArch64_UnalignedAccessFaults_3">AArch64_UnalignedAccessFaults</anchor>(accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                                   address : bits(64),
                                   size : integer) =&gt; boolean
begin
    if <a link="func_AlignmentEnforced_0" file="shared_pseudocode.xml">AlignmentEnforced</a>() then
        return TRUE;
    elsif accdesc.acctype == <a link="enum_AccessType_GCS" file="shared_pseudocode.xml">AccessType_GCS</a> then
        return TRUE;
    elsif accdesc.rcw then
        return TRUE;
    elsif accdesc.ls64 then
        return TRUE;
    elsif (accdesc.exclusive || accdesc.atomicop)  then
        let quantity : integer = <a link="func_MemSingleGranule_0" file="shared_pseudocode.xml">MemSingleGranule</a>();
        return (!IsFeatureImplemented(FEAT_LSE2) ||
                  !<a link="func_AllInAlignedQuantity_4" file="shared_pseudocode.xml">AllInAlignedQuantity</a>{64}(address, size, quantity));
    elsif (accdesc.acqsc || accdesc.acqpc || accdesc.relsc) then
        // If nAA is 0, the address accessed by each register in the pair
        // must lie within a single 16-byte aligned block
        if accdesc.ispair then
            return  (<a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>().nAA == '0' &amp;&amp;
                       (!<a link="func_AllInAlignedQuantity_4" file="shared_pseudocode.xml">AllInAlignedQuantity</a>{64}(address, size DIV 2, 16) ||
                        !<a link="func_AllInAlignedQuantity_4" file="shared_pseudocode.xml">AllInAlignedQuantity</a>{64}(address + size DIV 2, size DIV 2, 16)));
        else
            return  (<a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>().nAA == '0' &amp;&amp;
                       !<a link="func_AllInAlignedQuantity_4" file="shared_pseudocode.xml">AllInAlignedQuantity</a>{64}(address, size, 16));
        end;
    else
        return FALSE;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/AddressSupportsLS64" mylink="aarch64.functions.memory.AddressSupportsLS64" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddressSupportsLS64()
// =====================
// Returns TRUE if the 64-byte block following the given address supports the
// LD64B and ST64B instructions, and FALSE otherwise.

impdef func <anchor link="func_AddressSupportsLS64_1">AddressSupportsLS64</anchor>(paddress : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>)) =&gt; boolean
begin
    return ImpDefBool(&quot;Memory location supports ST64B and LD64B&quot;);
end;</pstext></ps>
    <ps name="aarch64/functions/memory/CASCompare" mylink="aarch64.functions.memory.CASCompare" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CASCompare()
// ============
// Performs a comparison for CAS

func <anchor link="func_CASCompare_4">CASCompare</anchor>{N}(oldvalue : bits(N),
                   comparevalue : bits(N),
                   newvalue : bits(N)) =&gt; (bits(N), boolean, bits(N))
begin
    var memresult : bits(N);
    var cmpfail : boolean;
    var regresult : bits(N) = oldvalue;

    if oldvalue == comparevalue then
        cmpfail = FALSE;
        memresult = newvalue;
        if !<a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_CASRETURNOLDVALUE" file="shared_pseudocode.xml">Unpredictable_CASRETURNOLDVALUE</a>) then
            regresult = comparevalue;
        end;
    else
        cmpfail = TRUE;
        memresult = oldvalue;
    end;

    return (memresult, cmpfail, regresult);
end;</pstext></ps>
    <ps name="aarch64/functions/memory/CheckSPAlignment" mylink="aarch64.functions.memory.CheckSPAlignment" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckSPAlignment()
// ==================
// Check correct stack pointer alignment for AArch64 state.

func <anchor link="func_CheckSPAlignment_0">CheckSPAlignment</anchor>()
begin
    let sp : bits(64) = SP{}();
    var stack_align_check : boolean;
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        stack_align_check = (<a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>().SA0 != '0');
    else
        stack_align_check = (<a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>().SA != '0');
    end;

    if stack_align_check &amp;&amp; sp != AlignDownSize(sp, 16) then
        <a link="func_AArch64_SPAlignmentFault_0" file="shared_pseudocode.xml">AArch64_SPAlignmentFault</a>();
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/IsConventionalMemory" mylink="aarch64.functions.memory.IsConventionalMemory" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsConventionalMemory()
// ======================
// Returns TRUE if the memory location is in Conventional memory, and FALSE otherwise.

impdef func <anchor link="func_IsConventionalMemory_1">IsConventionalMemory</anchor>(addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>) =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/Mem" mylink="aarch64.functions.memory.Mem" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Mem - accessor
// ==============

accessor <anchor link="accessor_Mem_3">Mem</anchor>{size : integer{8, 16, 32, 64, 128, 256}}(address : bits(64),
                                                      accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
                                                ) &lt;=&gt;  value_in : bits(size)
begin
    // Perform a read of 'size' bits. The access byte order is reversed for a big-endian access.
    // Instruction fetches would call AArch64_MemSingle directly.
    getter
        var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = accdesc_in;
        let bytes : integer{} = size DIV 8;
        var value : bits(size);

        // Check alignment on size of element accessed, not overall access size
        var aligned : boolean;
        if accdesc.ispair &amp;&amp; !accdesc.exclusive then
            let half : integer{} = (size DIV 2) as integer{32, 64, 128};
            aligned = IsAlignedSize(address, half DIV 8);
        else
            aligned = IsAlignedSize(address, bytes);
        end;

        let quantity : integer = <a link="func_MemSingleGranule_0" file="shared_pseudocode.xml">MemSingleGranule</a>();

        if !aligned &amp;&amp; <a link="func_AArch64_UnalignedAccessFaults_3" file="shared_pseudocode.xml">AArch64_UnalignedAccessFaults</a>(accdesc, address, bytes) then
            let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AlignmentFault_2" file="shared_pseudocode.xml">AlignmentFault</a>(accdesc, address);
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
        end;
        if accdesc.acctype == <a link="enum_AccessType_ASIMD" file="shared_pseudocode.xml">AccessType_ASIMD</a> &amp;&amp; bytes == 16 &amp;&amp; IsAlignedSize(address, 8) then
            // If 128-bit SIMD&amp;FP ordered access are treated as a pair of
            // 64-bit single-copy atomic accesses, then these single copy atomic
            // access can be observed in any order.
            let half : integer{} = (size DIV 2) as integer{64};
            let highaddress : bits(64) = <a link="func_AddressIncrement_3" file="shared_pseudocode.xml">AddressIncrement</a>(address, half DIV 8, accdesc);
            value[0*:half] = <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{half}(address, accdesc, aligned);
            value[1*:half] = <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{half}(highaddress, accdesc, aligned);
        elsif (IsFeatureImplemented(FEAT_LS64WB) &amp;&amp; accdesc.acctype == <a link="enum_AccessType_ASIMD" file="shared_pseudocode.xml">AccessType_ASIMD</a> &amp;&amp;
                bytes == 32 &amp;&amp; accdesc.ispair &amp;&amp; IsAlignedSize(address, 32)) then
            value = <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{size}(address, accdesc, aligned);
        elsif accdesc.acctype == <a link="enum_AccessType_ASIMD" file="shared_pseudocode.xml">AccessType_ASIMD</a> &amp;&amp; bytes == 32 &amp;&amp; IsAlignedSize(address, 8) then
            // If a 32 byte LDP (SIMD&amp;FP) access is not aligned to 32 bytes but aligned to
            // 8 bytes, it is treated as four 8 byte single-copy atomic accesses.
            accdesc.ispair = FALSE;
            aligned        = TRUE;
            for i = 0 to 3 do
                let blockaddress : bits(64) = <a link="func_AddressIncrement_3" file="shared_pseudocode.xml">AddressIncrement</a>(address, i*8, accdesc);
                value[64*i+:64] = <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{64}(blockaddress, accdesc, aligned);
            end;
        elsif (IsFeatureImplemented(FEAT_LSE2) &amp;&amp;
            <a link="func_AllInAlignedQuantity_4" file="shared_pseudocode.xml">AllInAlignedQuantity</a>{64}(address, bytes, quantity)) then
            value = <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{size}(address, accdesc, aligned);
        elsif ((aligned &amp;&amp; accdesc.ispair) ||
                  (accdesc.acctype == <a link="enum_AccessType_SVE" file="shared_pseudocode.xml">AccessType_SVE</a> &amp;&amp; accdesc.predicated &amp;&amp;
                     bytes == 16 &amp;&amp; IsAlignedSize(address, 8))) then
            // Either: an aligned pair access, OR
            // an SVE predicated load of a 128-bit element that is 64-bit aligned,
            // which is treated as two 64-bit single-copy atomic accesses.
            accdesc.ispair = FALSE;
            let half : integer{} = (size DIV 2) as integer{32, 64, 128};
            let highaddress : bits(64) = <a link="func_AddressIncrement_3" file="shared_pseudocode.xml">AddressIncrement</a>(address, half DIV 8, accdesc);
            if IsFeatureImplemented(FEAT_LRCPC3) &amp;&amp; accdesc.highestaddressfirst then
                value[1*:half] = <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{half}(highaddress, accdesc, aligned);
                value[0*:half] = <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{half}(address, accdesc, aligned);
            else
                value[0*:half] = <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{half}(address, accdesc, aligned);
                value[1*:half] = <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{half}(highaddress, accdesc, aligned);
            end;
        elsif aligned then
            value = <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{size}(address, accdesc, aligned);
        else
            assert bytes &gt; 1;
            if (IsFeatureImplemented(FEAT_LRCPC3) &amp;&amp; accdesc.ispair &amp;&amp;
                    accdesc.highestaddressfirst) then
                let half : integer{} = (size DIV 2) as integer{32, 64, 128};
                var lowhalf, highhalf : bits(half);

                for i = 0 to (half DIV 8)-1 do
                    let byteaddress : bits(64) = <a link="func_AddressIncrement_3" file="shared_pseudocode.xml">AddressIncrement</a>(address,
                                                                  (half DIV 8) + i, accdesc);
                    // Individual byte access can be observed in any order
                    highhalf[i*:8] = <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{8}(byteaddress, accdesc, aligned);
                end;
                for i = 0 to (half DIV 8)-1 do
                    let byteaddress : bits(64) = <a link="func_AddressIncrement_3" file="shared_pseudocode.xml">AddressIncrement</a>(address, i, accdesc);
                    // Individual byte access can be observed in any order
                    lowhalf[i*:8] = <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{8}(byteaddress, accdesc, aligned);
                end;

                value = highhalf::lowhalf;

            else
                value[7:0] = <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{8}(address, accdesc, aligned);
                accdesc.lowestaddress = FALSE;

                // For subsequent bytes, if they cross to a new translation page which assigns
                // Device memory type, it is CONSTRAINED UNPREDICTABLE whether an unaligned access
                // will generate an Alignment Fault.
                let c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = ConstrainUnpredictable(<a link="enum_Unpredictable_DEVPAGE2" file="shared_pseudocode.xml">Unpredictable_DEVPAGE2</a>);
                assert c IN {<a link="enum_Constraint_FAULT" file="shared_pseudocode.xml">Constraint_FAULT</a>, <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>};
                if c == <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a> then aligned = TRUE; end;

                for i = 1 to bytes-1 do
                    let byteaddress : bits(64) = <a link="func_AddressIncrement_3" file="shared_pseudocode.xml">AddressIncrement</a>(address, i, accdesc);
                    value[i*:8] = <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{8}(byteaddress, accdesc, aligned);
                end;
            end;
        end;

        if <a link="func_BigEndian_1" file="shared_pseudocode.xml">BigEndian</a>(accdesc.acctype) then
            value = <a link="func_BigEndianReverse_2" file="shared_pseudocode.xml">BigEndianReverse</a>{size}(value);
        end;

        return value;
    end;

    // Perform a write of 'size' bits. The byte order is reversed for a big-endian access.
    setter
        var value : bits(size) = value_in;
        let bytes : integer{} = size DIV 8;
        var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = accdesc_in;

        // Check alignment on size of element accessed, not overall access size
        var aligned : boolean;
        if accdesc.ispair &amp;&amp; !accdesc.exclusive then
            let half : integer{} = (size DIV 2) as integer{32, 64, 128};
            aligned = IsAlignedSize(address, half DIV 8);
        else
            aligned = IsAlignedSize(address, bytes);
        end;
        let quantity : integer = <a link="func_MemSingleGranule_0" file="shared_pseudocode.xml">MemSingleGranule</a>();

        if !aligned &amp;&amp; <a link="func_AArch64_UnalignedAccessFaults_3" file="shared_pseudocode.xml">AArch64_UnalignedAccessFaults</a>(accdesc, address, bytes) then
            let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AlignmentFault_2" file="shared_pseudocode.xml">AlignmentFault</a>(accdesc, address);
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
        end;

        if <a link="func_BigEndian_1" file="shared_pseudocode.xml">BigEndian</a>(accdesc.acctype) then
            value = <a link="func_BigEndianReverse_2" file="shared_pseudocode.xml">BigEndianReverse</a>{size}(value);
        end;
        if accdesc.acctype == <a link="enum_AccessType_ASIMD" file="shared_pseudocode.xml">AccessType_ASIMD</a> &amp;&amp; bytes == 16 &amp;&amp; IsAlignedSize(address, 8) then
            let half : integer{} = (size DIV 2) as integer{64};
            // 128-bit SIMD&amp;FP stores are treated as a pair of 64-bit single-copy atomic accesses
            // 64-bit aligned.
            let highaddress : bits(64) = <a link="func_AddressIncrement_3" file="shared_pseudocode.xml">AddressIncrement</a>(address, half DIV 8, accdesc);
            <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{half}(address, accdesc, aligned) = value[0+:half];
            <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{half}(highaddress, accdesc, aligned) = value[half+:half];
        elsif (IsFeatureImplemented(FEAT_LS64WB) &amp;&amp; accdesc.acctype == <a link="enum_AccessType_ASIMD" file="shared_pseudocode.xml">AccessType_ASIMD</a> &amp;&amp;
                bytes == 32 &amp;&amp; accdesc.ispair &amp;&amp; IsAlignedSize(address, 32)) then
            <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{size}(address, accdesc, aligned) = value;
        elsif accdesc.acctype == <a link="enum_AccessType_ASIMD" file="shared_pseudocode.xml">AccessType_ASIMD</a> &amp;&amp; bytes == 32 &amp;&amp; IsAlignedSize(address, 8) then
            // If a 32 byte STP (SIMD&amp;FP) access is not aligned to 32 bytes but aligned to
            // 8 bytes, it is treated as four 8 byte single-copy atomic accesses.
            accdesc.ispair = FALSE;
            aligned        = TRUE;
            for i = 0 to 3 do
                let blockaddress : bits(64) = <a link="func_AddressIncrement_3" file="shared_pseudocode.xml">AddressIncrement</a>(address, i*8, accdesc);
                <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{64}(blockaddress, accdesc, aligned) = value[64*i+:64];
            end;
        elsif (IsFeatureImplemented(FEAT_LSE2) &amp;&amp;
            <a link="func_AllInAlignedQuantity_4" file="shared_pseudocode.xml">AllInAlignedQuantity</a>{64}(address, bytes, quantity)) then
            <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{size}(address, accdesc, aligned) = value;
        elsif ((aligned &amp;&amp; accdesc.ispair) ||
                  (accdesc.acctype == <a link="enum_AccessType_SVE" file="shared_pseudocode.xml">AccessType_SVE</a> &amp;&amp; accdesc.predicated &amp;&amp;
                     bytes == 16 &amp;&amp; IsAlignedSize(address, 8))) then
            // Either: an aligned pair access, OR
            // an SVE predicated load of a 128-bit element that is 64-bit aligned,
            // which is treated as two 64-bit single-copy atomic accesses.
            let half : integer{} = (size DIV 2) as integer{32, 64, 128};
            accdesc.ispair = FALSE;
            let highaddress : bits(64) = <a link="func_AddressIncrement_3" file="shared_pseudocode.xml">AddressIncrement</a>(address, half DIV 8, accdesc);
            if IsFeatureImplemented(FEAT_LRCPC3) &amp;&amp; accdesc.highestaddressfirst then
                <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{half}(highaddress, accdesc, aligned) = value[half+:half];
                <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{half}(address, accdesc, aligned) = value[0+:half];
            else
                <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{half}(address, accdesc, aligned) = value[0+:half];
                <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{half}(highaddress, accdesc, aligned) = value[half+:half];
            end;
        elsif aligned then
            <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{size}(address, accdesc, aligned) = value;
        else
            assert bytes &gt; 1;
            if (IsFeatureImplemented(FEAT_LRCPC3) &amp;&amp; accdesc.ispair &amp;&amp;
                    accdesc.highestaddressfirst) then
                let half : integer{} = (size DIV 2) as integer{32, 64};
                var lowhalf, highhalf : bits(half);
                (highhalf, lowhalf) = (value[half+:half], value[0+:half]);
                for i = 0 to (half DIV 8)-1 do
                    let byteaddress : bits(64) = <a link="func_AddressIncrement_3" file="shared_pseudocode.xml">AddressIncrement</a>(address,
                                                                  (half DIV 8) + i, accdesc);
                    // Individual byte access can be observed in any order
                    <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{8}(byteaddress, accdesc, aligned) = highhalf[i*:8];
                end;
                for i = 0 to (half DIV 8)-1 do
                    let byteaddress : bits(64) = <a link="func_AddressIncrement_3" file="shared_pseudocode.xml">AddressIncrement</a>(address,
                                                                  (half DIV 8) + i, accdesc);
                    // Individual byte access can be observed in any order,
                    // but implies observability of highhalf
                    <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{8}(byteaddress, accdesc, aligned) = lowhalf[i*:8];
                end;
            else
                <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{8}(address, accdesc, aligned) = value[7:0];
                accdesc.lowestaddress = FALSE;

                // For subsequent bytes, if they cross to a new translation page which assigns
                // Device memory type, it is CONSTRAINED UNPREDICTABLE whether an unaligned access
                // will generate an Alignment Fault.

                let c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = ConstrainUnpredictable(<a link="enum_Unpredictable_DEVPAGE2" file="shared_pseudocode.xml">Unpredictable_DEVPAGE2</a>);
                assert c IN {<a link="enum_Constraint_FAULT" file="shared_pseudocode.xml">Constraint_FAULT</a>, <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>};
                if c == <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a> then aligned = TRUE; end;

                for i = 1 to bytes-1 do
                    let byteaddress : bits(64) = <a link="func_AddressIncrement_3" file="shared_pseudocode.xml">AddressIncrement</a>(address, i, accdesc);
                    <a link="accessor_AArch64_MemSingle_4" file="shared_pseudocode.xml">AArch64_MemSingle</a>{8}(byteaddress, accdesc, aligned) = value[i*:8];
                end;
            end;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/MemAtomic" mylink="aarch64.functions.memory.MemAtomic" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemAtomic()
// ===========
// Performs load and store memory operations for a given virtual address.

func <anchor link="func_MemAtomic_5">MemAtomic</anchor>{size : integer{8, 16, 32, 64, 128}}(address : bits(64),
                                                   cmpoperand : bits(size),
                                                   operand : bits(size),
                                                   accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
                                                  ) =&gt; bits(size)
begin
    assert accdesc_in.atomicop;

    let bytes : integer{} = (size DIV 8) as integer{1, 2, 4, 8, 16};

    var newvalue : bits(size);
    var oldvalue : bits(size);
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = accdesc_in;
    let aligned : boolean = IsAlignedSize(address, bytes);

    // If the instruction encoding permits tag checking, confer with system register configuration
    // which may override this.
    if accdesc.tagchecked then
        accdesc.tagchecked = <a link="func_AArch64_AccessIsTagChecked_2" file="shared_pseudocode.xml">AArch64_AccessIsTagChecked</a>(address, accdesc);
    end;

    if !aligned &amp;&amp; <a link="func_AArch64_UnalignedAccessFaults_3" file="shared_pseudocode.xml">AArch64_UnalignedAccessFaults</a>(accdesc, address, bytes) then
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AlignmentFault_2" file="shared_pseudocode.xml">AlignmentFault</a>(accdesc, address);
        <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
    end;

    // MMU or MPU lookup
    let memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_AArch64_TranslateAddress_4" file="shared_pseudocode.xml">AArch64_TranslateAddress</a>(address, accdesc,
                                                                      aligned, bytes);

    // Check for aborts or debug exceptions
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(memaddrdesc.fault);
    end;

    if (!<a link="func_IsWBShareable_1" file="shared_pseudocode.xml">IsWBShareable</a>(memaddrdesc.memattrs) &amp;&amp;
            <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_Atomic_NOP" file="shared_pseudocode.xml">Unpredictable_Atomic_NOP</a>)) then
        return ARBITRARY : bits(size);
    end;

    // Effect on exclusives
    if memaddrdesc.memattrs.shareability != <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a> then
        ClearExclusiveByAddress(memaddrdesc.paddress, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), bytes);
    end;

    // For Store-only Tag checking, the tag check is performed on the store.
    if (accdesc.tagchecked &amp;&amp;
          (!IsFeatureImplemented(FEAT_MTE_STORE_ONLY) ||
           !<a link="func_StoreOnlyTagCheckingEnabled_1" file="shared_pseudocode.xml">StoreOnlyTagCheckingEnabled</a>(accdesc.el))) then
        let ltag : bits(4) = <a link="func_AArch64_LogicalAddressTag_1" file="shared_pseudocode.xml">AArch64_LogicalAddressTag</a>(address);
        let readcheck : boolean = TRUE;
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AArch64_CheckTag_5" file="shared_pseudocode.xml">AArch64_CheckTag</a>(memaddrdesc, accdesc, readcheck, bytes, ltag);
        if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
        end;
    end;

    // All observers in the shareability domain observe the following load and store atomically.
    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
    (memstatus, oldvalue) = <a link="func_PhysMemRead_3" file="shared_pseudocode.xml">PhysMemRead</a>{size}(memaddrdesc, accdesc);
    // Depending on the memory type of the physical address, the access might generate
    // either a synchronous External abort or an SError exception
    // among other CONSTRAINED UNPREDICTABLE choices.

    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
        <a link="func_HandleExternalReadAbort_4" file="shared_pseudocode.xml">HandleExternalReadAbort</a>(memstatus, memaddrdesc, bytes, accdesc);
    end;
    if <a link="func_BigEndian_1" file="shared_pseudocode.xml">BigEndian</a>(accdesc.acctype) then
        oldvalue = <a link="func_BigEndianReverse_2" file="shared_pseudocode.xml">BigEndianReverse</a>{size}(oldvalue);
    end;

    var cmpfail : boolean = FALSE;
    var retvalue : bits(size) = oldvalue;
    if accdesc.acctype == <a link="enum_AccessType_FP" file="shared_pseudocode.xml">AccessType_FP</a> then
        newvalue = <a link="func_MemAtomicFP_4" file="shared_pseudocode.xml">MemAtomicFP</a>{size}(accdesc.modop, oldvalue, operand);
    else
        (newvalue, cmpfail, retvalue) = <a link="func_MemAtomicInt_5" file="shared_pseudocode.xml">MemAtomicInt</a>{size}(accdesc.modop, oldvalue,
                                                           operand, cmpoperand);
    end;

    let requirewrite : boolean = (!cmpfail ||
                                  <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_WRITEFAILEDCAS" file="shared_pseudocode.xml">Unpredictable_WRITEFAILEDCAS</a>));

    if IsFeatureImplemented(FEAT_MTE_STORE_ONLY) &amp;&amp; <a link="func_StoreOnlyTagCheckingEnabled_1" file="shared_pseudocode.xml">StoreOnlyTagCheckingEnabled</a>(accdesc.el) then
        // If the compare on a CAS fails, then it is CONSTRAINED UNPREDICTABLE whether the
        // Tag check is performed.
        if accdesc.tagchecked &amp;&amp; !requirewrite then
            accdesc.tagchecked = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_STRONLYTAGCHECKEDCAS" file="shared_pseudocode.xml">Unpredictable_STRONLYTAGCHECKEDCAS</a>);
        end;

        if accdesc.tagchecked then
            let ltag : bits(4) = <a link="func_AArch64_LogicalAddressTag_1" file="shared_pseudocode.xml">AArch64_LogicalAddressTag</a>(address);
            let readcheck : boolean = FALSE;
            var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AArch64_CheckTag_5" file="shared_pseudocode.xml">AArch64_CheckTag</a>(memaddrdesc, accdesc, readcheck,
                                                       bytes, ltag);
            if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
                // For a synchronous Tag Check Fault due to FEAT_MTE_STORE_ONLY, set WnR.
                fault.write = TRUE;
                <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
            end;
        end;
    end;

    if requirewrite then
        if <a link="func_BigEndian_1" file="shared_pseudocode.xml">BigEndian</a>(accdesc.acctype) then
            newvalue = <a link="func_BigEndianReverse_2" file="shared_pseudocode.xml">BigEndianReverse</a>{size}(newvalue);
        end;
        memstatus = <a link="func_PhysMemWrite_4" file="shared_pseudocode.xml">PhysMemWrite</a>{size}(memaddrdesc, accdesc, newvalue);
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            <a link="func_HandleExternalWriteAbort_4" file="shared_pseudocode.xml">HandleExternalWriteAbort</a>(memstatus, memaddrdesc, bytes, accdesc);
        end;
    end;

    if <a link="global_SPESampleInFlight" file="shared_pseudocode.xml">SPESampleInFlight</a> then
        let is_load : boolean = FALSE;
        <a link="func_SPESampleLoadStore_3" file="shared_pseudocode.xml">SPESampleLoadStore</a>(is_load, accdesc, memaddrdesc);
    end;

    // Load operations return the old (pre-operation) value.
    // Compare and Swap operations return the old (pre-operation) value. For a successful CAS,
    // this might be the value from the compare operand or from memory.
    return retvalue;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/MemAtomicFP" mylink="aarch64.functions.memory.MemAtomicFP" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemAtomicFP()
// =============
// Performs FP Atomic operation

func <anchor link="func_MemAtomicFP_4">MemAtomicFP</anchor>{N}(modop : <a link="type_MemAtomicOp" file="shared_pseudocode.xml">MemAtomicOp</a>, op1 : bits(N), op2 : bits(N)) =&gt; bits(N)
begin
    var fpcr : FPCR_Type = FPCR();
    let altfp : boolean  = FALSE;
    let fpexc : boolean  = FALSE;
    fpcr.[AH,DN]   = '01';
    fpcr.FZ        = fpcr.FZ OR fpcr.FIZ; // Treat FPCR.FIZ as equivalent to FPCR.FZ
    var result : bits(N);

    case modop of
        when <a link="enum_MemAtomicOp_FPADD" file="shared_pseudocode.xml">MemAtomicOp_FPADD</a> =&gt;    result = <a link="func_FPAdd_5" file="shared_pseudocode.xml">FPAdd</a>{N}(op1, op2, fpcr, fpexc);
        when <a link="enum_MemAtomicOp_FPMAX" file="shared_pseudocode.xml">MemAtomicOp_FPMAX</a> =&gt;    result = <a link="func_FPMax_6" file="shared_pseudocode.xml">FPMax</a>{N}(op1, op2, fpcr, altfp, fpexc);
        when <a link="enum_MemAtomicOp_FPMIN" file="shared_pseudocode.xml">MemAtomicOp_FPMIN</a> =&gt;    result = <a link="func_FPMin_6" file="shared_pseudocode.xml">FPMin</a>{N}(op1, op2, fpcr, altfp, fpexc);
        when <a link="enum_MemAtomicOp_FPMAXNM" file="shared_pseudocode.xml">MemAtomicOp_FPMAXNM</a> =&gt;  result = <a link="func_FPMaxNum_5" file="shared_pseudocode.xml">FPMaxNum</a>{N}(op1, op2, fpcr, fpexc);
        when <a link="enum_MemAtomicOp_FPMINNM" file="shared_pseudocode.xml">MemAtomicOp_FPMINNM</a> =&gt;  result = <a link="func_FPMinNum_5" file="shared_pseudocode.xml">FPMinNum</a>{N}(op1, op2, fpcr, fpexc);
        when <a link="enum_MemAtomicOp_BFADD" file="shared_pseudocode.xml">MemAtomicOp_BFADD</a> =&gt;    result = <a link="func_BFAdd_5" file="shared_pseudocode.xml">BFAdd</a>{N}(op1, op2, fpcr, fpexc);
        when <a link="enum_MemAtomicOp_BFMAX" file="shared_pseudocode.xml">MemAtomicOp_BFMAX</a> =&gt;    result = <a link="func_BFMax_6" file="shared_pseudocode.xml">BFMax</a>{N}(op1, op2, fpcr, altfp, fpexc);
        when <a link="enum_MemAtomicOp_BFMIN" file="shared_pseudocode.xml">MemAtomicOp_BFMIN</a> =&gt;    result = <a link="func_BFMin_6" file="shared_pseudocode.xml">BFMin</a>{N}(op1, op2, fpcr, altfp, fpexc);
        when <a link="enum_MemAtomicOp_BFMAXNM" file="shared_pseudocode.xml">MemAtomicOp_BFMAXNM</a> =&gt;  result = <a link="func_BFMaxNum_5" file="shared_pseudocode.xml">BFMaxNum</a>{N}(op1, op2, fpcr, fpexc);
        when <a link="enum_MemAtomicOp_BFMINNM" file="shared_pseudocode.xml">MemAtomicOp_BFMINNM</a> =&gt;  result = <a link="func_BFMinNum_5" file="shared_pseudocode.xml">BFMinNum</a>{N}(op1, op2, fpcr, fpexc);
    end;
    return result;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/MemAtomicInt" mylink="aarch64.functions.memory.MemAtomicInt" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemAtomicInt()
// ==============
// Performs Integer Atomic operation

func <anchor link="func_MemAtomicInt_5">MemAtomicInt</anchor>{N}(modop : <a link="type_MemAtomicOp" file="shared_pseudocode.xml">MemAtomicOp</a>, op1 : bits(N), op2 : bits(N), cmpop : bits(N)
                    ) =&gt; (bits(N), boolean, bits(N))
begin
    var result : bits(N);
    var cmpfail : boolean = FALSE;
    var retvalue : bits(N) = op1;

    case modop of
        when <a link="enum_MemAtomicOp_ADD" file="shared_pseudocode.xml">MemAtomicOp_ADD</a> =&gt;      result = op1 + op2;
        when <a link="enum_MemAtomicOp_BIC" file="shared_pseudocode.xml">MemAtomicOp_BIC</a> =&gt;      result = op1 AND NOT(op2);
        when <a link="enum_MemAtomicOp_EOR" file="shared_pseudocode.xml">MemAtomicOp_EOR</a> =&gt;      result = op1 XOR op2;
        when <a link="enum_MemAtomicOp_ORR" file="shared_pseudocode.xml">MemAtomicOp_ORR</a> =&gt;      result = op1 OR op2;
        when <a link="enum_MemAtomicOp_SMAX" file="shared_pseudocode.xml">MemAtomicOp_SMAX</a> =&gt;     result = Max(SInt(op1), SInt(op2))[N-1:0];
        when <a link="enum_MemAtomicOp_SMIN" file="shared_pseudocode.xml">MemAtomicOp_SMIN</a> =&gt;     result = Min(SInt(op1), SInt(op2))[N-1:0];
        when <a link="enum_MemAtomicOp_UMAX" file="shared_pseudocode.xml">MemAtomicOp_UMAX</a> =&gt;     result = Max(UInt(op1), UInt(op2))[N-1:0];
        when <a link="enum_MemAtomicOp_UMIN" file="shared_pseudocode.xml">MemAtomicOp_UMIN</a> =&gt;     result = Min(UInt(op1), UInt(op2))[N-1:0];
        when <a link="enum_MemAtomicOp_SWP" file="shared_pseudocode.xml">MemAtomicOp_SWP</a> =&gt;      result = op2;
        when <a link="enum_MemAtomicOp_CAS" file="shared_pseudocode.xml">MemAtomicOp_CAS</a> =&gt;      (result, cmpfail, retvalue) = <a link="func_CASCompare_4" file="shared_pseudocode.xml">CASCompare</a>{N}(op1, cmpop, op2);
        when <a link="enum_MemAtomicOp_GCSSS1" file="shared_pseudocode.xml">MemAtomicOp_GCSSS1</a> =&gt;   (result, cmpfail, retvalue) = <a link="func_CASCompare_4" file="shared_pseudocode.xml">CASCompare</a>{N}(op1, cmpop, op2);
    end;
    return (result, cmpfail, retvalue);
end;</pstext></ps>
    <ps name="aarch64/functions/memory/MemAtomicRCW" mylink="aarch64.functions.memory.MemAtomicRCW" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemAtomicRCW()
// ==============
// Perform a single-copy-atomic access with Read-Check-Write operation

func <anchor link="func_MemAtomicRCW_5">MemAtomicRCW</anchor>{size : integer{64, 128}}(address : bits(64), cmpoperand : bits(size),
                                           operand : bits(size), accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
                                  ) =&gt; (bits(4), bits(size))
begin
    assert accdesc_in.atomicop;
    assert accdesc_in.rcw;

    let bytes : integer{} = (size DIV 8) as integer{8, 16};

    var nzcv : bits(4);
    var oldvalue : bits(size);
    var newvalue : bits(size);
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = accdesc_in;
    let aligned : boolean = IsAlignedSize(address, bytes);

    // If the instruction encoding permits tag checking, confer with system register configuration
    // which may override this.
    if accdesc.tagchecked then
        accdesc.tagchecked = <a link="func_AArch64_AccessIsTagChecked_2" file="shared_pseudocode.xml">AArch64_AccessIsTagChecked</a>(address, accdesc);
    end;

    if !aligned &amp;&amp; <a link="func_AArch64_UnalignedAccessFaults_3" file="shared_pseudocode.xml">AArch64_UnalignedAccessFaults</a>(accdesc, address, bytes) then
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AlignmentFault_2" file="shared_pseudocode.xml">AlignmentFault</a>(accdesc, address);
        <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
    end;

    // MMU or MPU lookup
    let memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_AArch64_TranslateAddress_4" file="shared_pseudocode.xml">AArch64_TranslateAddress</a>(address, accdesc,
                                                                      aligned, bytes);

    // Check for aborts or debug exceptions
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(memaddrdesc.fault);
    end;

    if (!<a link="func_IsWBShareable_1" file="shared_pseudocode.xml">IsWBShareable</a>(memaddrdesc.memattrs) &amp;&amp;
            <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_Atomic_NOP" file="shared_pseudocode.xml">Unpredictable_Atomic_NOP</a>)) then
        return (ARBITRARY : bits(4), ARBITRARY : bits(size));
    end;

    // Effect on exclusives
    if memaddrdesc.memattrs.shareability != <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a> then
        ClearExclusiveByAddress(memaddrdesc.paddress, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), bytes);
    end;

    // For Store-only Tag checking, the tag check is performed on the store.
    if (accdesc.tagchecked &amp;&amp;
          (!IsFeatureImplemented(FEAT_MTE_STORE_ONLY) ||
           !<a link="func_StoreOnlyTagCheckingEnabled_1" file="shared_pseudocode.xml">StoreOnlyTagCheckingEnabled</a>(accdesc.el))) then
        let ltag : bits(4) = <a link="func_AArch64_LogicalAddressTag_1" file="shared_pseudocode.xml">AArch64_LogicalAddressTag</a>(address);
        let readcheck : boolean = TRUE;
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AArch64_CheckTag_5" file="shared_pseudocode.xml">AArch64_CheckTag</a>(memaddrdesc, accdesc, readcheck, bytes, ltag);
        if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
        end;
    end;

    // All observers in the shareability domain observe the following load and store atomically.
    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
    (memstatus, oldvalue) = <a link="func_PhysMemRead_3" file="shared_pseudocode.xml">PhysMemRead</a>{size}(memaddrdesc, accdesc);
    // Depending on the memory type of the physical address, the access might generate
    // either a synchronous External abort or an SError exception
    // among other CONSTRAINED UNPREDICTABLE choices.

    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
        <a link="func_HandleExternalReadAbort_4" file="shared_pseudocode.xml">HandleExternalReadAbort</a>(memstatus, memaddrdesc, bytes, accdesc);
    end;
    if <a link="func_BigEndian_1" file="shared_pseudocode.xml">BigEndian</a>(accdesc.acctype) then
        oldvalue = <a link="func_BigEndianReverse_2" file="shared_pseudocode.xml">BigEndianReverse</a>{size}(oldvalue);
    end;

    var cmpfail : boolean = FALSE;
    var retvalue : bits(size) = oldvalue;
    case accdesc.modop of
        when <a link="enum_MemAtomicOp_BIC" file="shared_pseudocode.xml">MemAtomicOp_BIC</a> =&gt; newvalue = oldvalue AND NOT(operand);
        when <a link="enum_MemAtomicOp_ORR" file="shared_pseudocode.xml">MemAtomicOp_ORR</a> =&gt; newvalue = oldvalue OR operand;
        when <a link="enum_MemAtomicOp_SWP" file="shared_pseudocode.xml">MemAtomicOp_SWP</a> =&gt; newvalue = operand;
        when <a link="enum_MemAtomicOp_CAS" file="shared_pseudocode.xml">MemAtomicOp_CAS</a> =&gt;
            (newvalue, cmpfail, retvalue) = <a link="func_CASCompare_4" file="shared_pseudocode.xml">CASCompare</a>{size}(oldvalue, cmpoperand, operand);
    end;

    if cmpfail then
        nzcv = '1010'; // N = 1 indicates compare failure
    else
        nzcv = <a link="func_RCWCheck_4" file="shared_pseudocode.xml">RCWCheck</a>{size}(retvalue, newvalue, accdesc.rcws);
    end;

    // If RCWCheck() passes, it returns nzcv == '0010'
    let requirewrite : boolean = (nzcv == '0010' ||
                                  <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_WRITEFAILEDRCWCAS" file="shared_pseudocode.xml">Unpredictable_WRITEFAILEDRCWCAS</a>));

    if IsFeatureImplemented(FEAT_MTE_STORE_ONLY) &amp;&amp; <a link="func_StoreOnlyTagCheckingEnabled_1" file="shared_pseudocode.xml">StoreOnlyTagCheckingEnabled</a>(accdesc.el) then
        // If the RCW(S) check fails, or if the compare on a RCW(S)CAS fails,
        // then it is CONSTRAINED UNPREDICTABLE whether the Tag check is performed.
        if accdesc.tagchecked &amp;&amp; !requirewrite then
            accdesc.tagchecked = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_STRONLYTAGCHECKEDRCWSCAS" file="shared_pseudocode.xml">Unpredictable_STRONLYTAGCHECKEDRCWSCAS</a>);
        end;

        if accdesc.tagchecked then
            let ltag : bits(4) = <a link="func_AArch64_LogicalAddressTag_1" file="shared_pseudocode.xml">AArch64_LogicalAddressTag</a>(address);
            let readcheck : boolean = FALSE;
            var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AArch64_CheckTag_5" file="shared_pseudocode.xml">AArch64_CheckTag</a>(memaddrdesc, accdesc, readcheck,
                                                       bytes, ltag);
            if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
                // For a synchronous Tag Check Fault due to FEAT_MTE_STORE_ONLY, set WnR.
                fault.write = TRUE;
                <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
            end;
        end;
    end;

    if requirewrite then
        if <a link="func_BigEndian_1" file="shared_pseudocode.xml">BigEndian</a>(accdesc.acctype) then
            newvalue = <a link="func_BigEndianReverse_2" file="shared_pseudocode.xml">BigEndianReverse</a>{size}(newvalue);
        end;

        memstatus = <a link="func_PhysMemWrite_4" file="shared_pseudocode.xml">PhysMemWrite</a>{size}(memaddrdesc, accdesc, newvalue);

        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            <a link="func_HandleExternalWriteAbort_4" file="shared_pseudocode.xml">HandleExternalWriteAbort</a>(memstatus, memaddrdesc, bytes, accdesc);
        end;
    end;

    if <a link="global_SPESampleInFlight" file="shared_pseudocode.xml">SPESampleInFlight</a> then
        let is_load : boolean = TRUE;
        <a link="func_SPESampleLoadStore_3" file="shared_pseudocode.xml">SPESampleLoadStore</a>(is_load, accdesc, memaddrdesc);
    end;

    // Load operations return the old (pre-operation) value.
    // Compare and Swap operations return the old (pre-operation) value. For a successful CAS,
    // this might be the value from the compare operand or from memory.
    return (nzcv, retvalue);
end;</pstext></ps>
    <ps name="aarch64/functions/memory/MemLoad64B" mylink="aarch64.functions.memory.MemLoad64B" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemLoad64B()
// ============
// Performs an atomic 64-byte read from a given virtual address.

func <anchor link="func_MemLoad64B_2">MemLoad64B</anchor>(address : bits(64), accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; bits(512)
begin
    let size : integer{} = 512;
    let bytes : integer{} = size DIV 8;
    var data : bits(size);
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = accdesc_in;
    let aligned : boolean = IsAlignedSize(address, bytes);

    if !aligned &amp;&amp; <a link="func_AArch64_UnalignedAccessFaults_3" file="shared_pseudocode.xml">AArch64_UnalignedAccessFaults</a>(accdesc, address, bytes) then
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AlignmentFault_2" file="shared_pseudocode.xml">AlignmentFault</a>(accdesc, address);
        <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
    end;

    // If the instruction encoding permits tag checking, confer with system register configuration
    // which may override this.
    if accdesc.tagchecked then
        accdesc.tagchecked = <a link="func_AArch64_AccessIsTagChecked_2" file="shared_pseudocode.xml">AArch64_AccessIsTagChecked</a>(address, accdesc);
    end;

    var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_AArch64_TranslateAddress_4" file="shared_pseudocode.xml">AArch64_TranslateAddress</a>(address, accdesc,
                                                                   aligned, bytes);

    // Check for aborts or debug exceptions
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(memaddrdesc.fault);
    end;

    // Effect on exclusives
    if memaddrdesc.memattrs.shareability != <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a> then
        ClearExclusiveByAddress(memaddrdesc.paddress, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), bytes);
    end;

    if accdesc.tagchecked then
        let ltag : bits(4)      = <a link="func_AArch64_LogicalAddressTag_1" file="shared_pseudocode.xml">AArch64_LogicalAddressTag</a>(address);
        let readcheck : boolean = TRUE;
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AArch64_CheckTag_5" file="shared_pseudocode.xml">AArch64_CheckTag</a>(memaddrdesc, accdesc, readcheck, bytes, ltag);
        if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
        end;
    end;

    var byte_atomic : boolean = FALSE;
    if ((memaddrdesc.memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> ||
          (memaddrdesc.memattrs.inner.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> &amp;&amp;
             memaddrdesc.memattrs.outer.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>)) &amp;&amp;
          !<a link="func_AddressSupportsLS64_1" file="shared_pseudocode.xml">AddressSupportsLS64</a>(memaddrdesc.paddress.address)) then
        let c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = ConstrainUnpredictable(<a link="enum_Unpredictable_LS64UNSUPPORTED" file="shared_pseudocode.xml">Unpredictable_LS64UNSUPPORTED</a>);
        assert c IN {<a link="enum_Constraint_LIMITED_ATOMICITY" file="shared_pseudocode.xml">Constraint_LIMITED_ATOMICITY</a>, <a link="enum_Constraint_FAULT" file="shared_pseudocode.xml">Constraint_FAULT</a>};
        if c == <a link="enum_Constraint_FAULT" file="shared_pseudocode.xml">Constraint_FAULT</a> then
            // Generate a stage 1 Data Abort reported using the DFSC code of 110101.
            let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_ExclusiveFault_2" file="shared_pseudocode.xml">ExclusiveFault</a>(accdesc, address);
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
        else
            byte_atomic = TRUE;
        end;
    elsif <a link="func_IsWBShareable_1" file="shared_pseudocode.xml">IsWBShareable</a>(memaddrdesc.memattrs) &amp;&amp; !<a link="func_IsConventionalMemory_1" file="shared_pseudocode.xml">IsConventionalMemory</a>(memaddrdesc) then
        if ImpDefBool(&quot;LD64B faults to iWBoWB non-Conventional memory&quot;) then
            // Generate a Data Abort reported using the DFSC code of 110101.
            let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_ExclusiveFault_2" file="shared_pseudocode.xml">ExclusiveFault</a>(accdesc, address);
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
        else
            byte_atomic = TRUE;
        end;
    end;

    if <a link="global_SPESampleInFlight" file="shared_pseudocode.xml">SPESampleInFlight</a> then
        let is_load : boolean = TRUE;
        <a link="func_SPESampleLoadStore_3" file="shared_pseudocode.xml">SPESampleLoadStore</a>(is_load, accdesc, memaddrdesc);
    end;

    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
    if byte_atomic then
        // Accesses are not single-copy atomic above the byte level.
        for i = 0 to bytes-1 do
            (memstatus, data[i*:8]) = <a link="func_PhysMemRead_3" file="shared_pseudocode.xml">PhysMemRead</a>{8}(memaddrdesc, accdesc);
            if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
                <a link="func_HandleExternalReadAbort_4" file="shared_pseudocode.xml">HandleExternalReadAbort</a>(memstatus, memaddrdesc, 1, accdesc);
            end;
            memaddrdesc.paddress.address = memaddrdesc.paddress.address + 1;
            memaddrdesc.vaddress         = memaddrdesc.vaddress + 1;
        end;
    else
        (memstatus, data) = <a link="func_PhysMemRead_3" file="shared_pseudocode.xml">PhysMemRead</a>{size}(memaddrdesc, accdesc);
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            <a link="func_HandleExternalReadAbort_4" file="shared_pseudocode.xml">HandleExternalReadAbort</a>(memstatus, memaddrdesc, bytes, accdesc);
        end;
    end;

    return data;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/MemSingleGranule" mylink="aarch64.functions.memory.MemSingleGranule" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemSingleGranule()
// ==================
// When FEAT_LSE2 is implemented, for some memory accesses if all bytes
// of the accesses are within 16-byte quantity aligned to 16-bytes and
// satisfy additional requirements - then the access is guaranteed to
// be single copy atomic.
// However, when the accesses do not all lie within such a boundary, it
// is CONSTRAINED UNPREDICTABLE if the access is single copy atomic.
// In the pseudocode, this CONSTRAINED UNPREDICTABLE aspect is modeled via
// MemSingleGranule() which is IMPLEMENTATION DEFINED and, is at least 16 bytes
// and at most 4096 bytes.
// This is a limitation of the pseudocode.

func <anchor link="func_MemSingleGranule_0">MemSingleGranule</anchor>() =&gt; integer
begin
    let size : integer = ImpDefInt(&quot;Aligned quantity for atomic access&quot;);
    // access is assumed to be within 4096 byte aligned quantity to
    // avoid multiple translations for a single copy atomic access.
    assert (size &gt;= 16) &amp;&amp; (size &lt;= 4096);
    return size;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/MemStore64B" mylink="aarch64.functions.memory.MemStore64B" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemStore64B()
// =============
// Performs an atomic 64-byte store to a given virtual address. Function does
// not return the status of the store.

func <anchor link="func_MemStore64B_3">MemStore64B</anchor>(address : bits(64), value : bits(512), accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>)
begin
    let size : integer{} = 512;
    let bytes : integer{} = size DIV 8;
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = accdesc_in;
    let aligned : boolean = IsAlignedSize(address, bytes);

    if !aligned &amp;&amp; <a link="func_AArch64_UnalignedAccessFaults_3" file="shared_pseudocode.xml">AArch64_UnalignedAccessFaults</a>(accdesc, address, bytes) then
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AlignmentFault_2" file="shared_pseudocode.xml">AlignmentFault</a>(accdesc, address);
        <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
    end;

    // If the instruction encoding permits tag checking, confer with system register configuration
    // which may override this.
    if accdesc.tagchecked then
        accdesc.tagchecked = <a link="func_AArch64_AccessIsTagChecked_2" file="shared_pseudocode.xml">AArch64_AccessIsTagChecked</a>(address, accdesc);
    end;

    var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_AArch64_TranslateAddress_4" file="shared_pseudocode.xml">AArch64_TranslateAddress</a>(address, accdesc,
                                                                   aligned, bytes);

    // Check for aborts or debug exceptions
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(memaddrdesc.fault);
    end;

    // Effect on exclusives
    if memaddrdesc.memattrs.shareability != <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a> then
        ClearExclusiveByAddress(memaddrdesc.paddress, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), 64);
    end;

    if accdesc.tagchecked then
        let ltag : bits(4)      = <a link="func_AArch64_LogicalAddressTag_1" file="shared_pseudocode.xml">AArch64_LogicalAddressTag</a>(address);
        let readcheck : boolean = FALSE;
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AArch64_CheckTag_5" file="shared_pseudocode.xml">AArch64_CheckTag</a>(memaddrdesc, accdesc, readcheck, bytes, ltag);
        if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
        end;
    end;

    var byte_atomic : boolean = FALSE;
    if ((memaddrdesc.memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> ||
          (memaddrdesc.memattrs.inner.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> &amp;&amp;
             memaddrdesc.memattrs.outer.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>)) &amp;&amp;
          !<a link="func_AddressSupportsLS64_1" file="shared_pseudocode.xml">AddressSupportsLS64</a>(memaddrdesc.paddress.address)) then
        let c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = ConstrainUnpredictable(<a link="enum_Unpredictable_LS64UNSUPPORTED" file="shared_pseudocode.xml">Unpredictable_LS64UNSUPPORTED</a>);
        assert c IN {<a link="enum_Constraint_LIMITED_ATOMICITY" file="shared_pseudocode.xml">Constraint_LIMITED_ATOMICITY</a>, <a link="enum_Constraint_FAULT" file="shared_pseudocode.xml">Constraint_FAULT</a>};
        if c == <a link="enum_Constraint_FAULT" file="shared_pseudocode.xml">Constraint_FAULT</a> then
            // Generate a Data Abort reported using the DFSC code of 110101.
            let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_ExclusiveFault_2" file="shared_pseudocode.xml">ExclusiveFault</a>(accdesc, address);
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
        else
            byte_atomic = TRUE;
        end;
    elsif <a link="func_IsWBShareable_1" file="shared_pseudocode.xml">IsWBShareable</a>(memaddrdesc.memattrs) &amp;&amp; !<a link="func_IsConventionalMemory_1" file="shared_pseudocode.xml">IsConventionalMemory</a>(memaddrdesc) then
        if ImpDefBool(&quot;ST64B faults to iWBoWB non-Conventional memory&quot;) then
            // Generate a Data Abort reported using the DFSC code of 110101.
            let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_ExclusiveFault_2" file="shared_pseudocode.xml">ExclusiveFault</a>(accdesc, address);
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
        else
            byte_atomic = TRUE;
        end;
    end;

    if <a link="global_SPESampleInFlight" file="shared_pseudocode.xml">SPESampleInFlight</a> then
        let is_load : boolean = FALSE;
        <a link="func_SPESampleLoadStore_3" file="shared_pseudocode.xml">SPESampleLoadStore</a>(is_load, accdesc, memaddrdesc);
    end;

    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
    if byte_atomic then
        // Accesses are not single-copy atomic above the byte level.
        for i = 0 to bytes-1 do
            memstatus = <a link="func_PhysMemWrite_4" file="shared_pseudocode.xml">PhysMemWrite</a>{8}(memaddrdesc, accdesc, value[i*:8]);
            if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
                <a link="func_HandleExternalWriteAbort_4" file="shared_pseudocode.xml">HandleExternalWriteAbort</a>(memstatus, memaddrdesc, 1, accdesc);
            end;
            memaddrdesc.paddress.address = memaddrdesc.paddress.address + 1;
            memaddrdesc.vaddress         = memaddrdesc.vaddress + 1;
        end;
    else
        memstatus = <a link="func_PhysMemWrite_4" file="shared_pseudocode.xml">PhysMemWrite</a>{size}(memaddrdesc, accdesc, value);
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            <a link="func_HandleExternalWriteAbort_4" file="shared_pseudocode.xml">HandleExternalWriteAbort</a>(memstatus, memaddrdesc, bytes, accdesc);
        end;
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/MemStore64BWithRet" mylink="aarch64.functions.memory.MemStore64BWithRet" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemStore64BWithRet()
// ====================
// Performs an atomic 64-byte store to a given virtual address returning
// the status value of the operation.

func <anchor link="func_MemStore64BWithRet_3">MemStore64BWithRet</anchor>(address : bits(64), value : bits(512),
                        accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; bits(64)
begin
    let size : integer{} = 512;
    let bytes : integer{} = size DIV 8;
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = accdesc_in;
    let aligned : boolean = IsAlignedSize(address, bytes);

    if !aligned &amp;&amp; <a link="func_AArch64_UnalignedAccessFaults_3" file="shared_pseudocode.xml">AArch64_UnalignedAccessFaults</a>(accdesc, address, bytes) then
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AlignmentFault_2" file="shared_pseudocode.xml">AlignmentFault</a>(accdesc, address);
        <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
    end;

    // If the instruction encoding permits tag checking, confer with system register configuration
    // which may override this.
    if accdesc.tagchecked then
        accdesc.tagchecked = <a link="func_AArch64_AccessIsTagChecked_2" file="shared_pseudocode.xml">AArch64_AccessIsTagChecked</a>(address, accdesc);
    end;

    let memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_AArch64_TranslateAddress_4" file="shared_pseudocode.xml">AArch64_TranslateAddress</a>(address, accdesc,
                                                                    aligned, bytes);

    // Check for aborts or debug exceptions
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(memaddrdesc.fault);
    end;

    // Effect on exclusives
    if memaddrdesc.memattrs.shareability != <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a> then
        ClearExclusiveByAddress(memaddrdesc.paddress, <a link="func_ProcessorID_0" file="shared_pseudocode.xml">ProcessorID</a>(), 64);
    end;

    if accdesc.tagchecked then
        let ltag : bits(4)      = <a link="func_AArch64_LogicalAddressTag_1" file="shared_pseudocode.xml">AArch64_LogicalAddressTag</a>(address);
        let readcheck : boolean = FALSE;
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AArch64_CheckTag_5" file="shared_pseudocode.xml">AArch64_CheckTag</a>(memaddrdesc, accdesc, readcheck, bytes, ltag);
        if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
        end;
    end;

    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
    memstatus = <a link="func_PhysMemWrite_4" file="shared_pseudocode.xml">PhysMemWrite</a>{size}(memaddrdesc, accdesc, value);

    // If an access generated by ST64BV or ST64BV0 fails solely because the memory location
    // does not support 64-byte access, then memstatus does not indicate a fault,
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
        <a link="func_HandleExternalWriteAbort_4" file="shared_pseudocode.xml">HandleExternalWriteAbort</a>(memstatus, memaddrdesc, bytes, accdesc);
    end;

    if <a link="global_SPESampleInFlight" file="shared_pseudocode.xml">SPESampleInFlight</a> then
        let is_load : boolean = FALSE;
        <a link="func_SPESampleLoadStore_3" file="shared_pseudocode.xml">SPESampleLoadStore</a>(is_load, accdesc, memaddrdesc);
    end;

    return memstatus.store64bstatus;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/MemStore64BWithRetStatus" mylink="aarch64.functions.memory.MemStore64BWithRetStatus" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemStore64BWithRetStatus()
// ==========================
// Generates the return status of memory write with ST64BV or ST64BV0
// instructions. The status indicates if the operation succeeded, failed,
// or was not supported at this memory location.

impdef func <anchor link="func_MemStore64BWithRetStatus_0">MemStore64BWithRetStatus</anchor>() =&gt; bits(64)
begin
    return Zeros{64};
end;</pstext></ps>
    <ps name="aarch64/functions/memory/NVMem" mylink="aarch64.functions.memory.NVMem" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// NVMem - accessor
// ================

accessor <anchor link="accessor_NVMem_1">NVMem</anchor>(offset : integer) &lt;=&gt; value : bits(64)
begin
    // This function is the load memory access for the transformed System register read access
    // when Enhanced Nested Virtualization is enabled with HCR_EL2.NV2 = 1.
    // The address for the load memory access is calculated using
    // the formula SignExtend{64}(VNCR_EL2.BADDR :: Offset[11:0]) where,
    //  * VNCR_EL2.BADDR holds the base address of the memory location, and
    //  * Offset is the unique offset value defined architecturally for each System register that
    //    supports transformation of register access to memory access.
    getter
        assert offset &gt; 0 &amp;&amp; offset MOD 8 == 0;
        let directread : boolean = FALSE;
        let baddr : bits(64)     = <a link="func_EffectiveBADDR_2" file="shared_pseudocode.xml">EffectiveBADDR</a>(VNCR_EL2().BADDR :: Zeros{12}, directread);
        let address : bits(64)   = baddr + offset;
        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescNV2_1" file="shared_pseudocode.xml">CreateAccDescNV2</a>(<a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>);
        return <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(address, accdesc);
    end;

    // This function is the store memory access for the transformed System register write access
    // when Enhanced Nested Virtualization is enabled with HCR_EL2.NV2 = 1.
    // The address for the store memory access is calculated using
    // the formula SignExtend{64}(VNCR_EL2.BADDR :: Offset[11:0]) where,
    //  * VNCR_EL2.BADDR holds the base address of the memory location, and
    //  * Offset is the unique offset value defined architecturally for each System register that
    //    supports transformation of register access to memory access.
    setter
        assert offset &gt; 0 &amp;&amp; offset MOD 8 == 0;
        let directread : boolean = FALSE;
        let baddr : bits(64)     = <a link="func_EffectiveBADDR_2" file="shared_pseudocode.xml">EffectiveBADDR</a>(VNCR_EL2().BADDR :: Zeros{12}, directread);
        let address : bits(64)   = baddr + offset;
        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescNV2_1" file="shared_pseudocode.xml">CreateAccDescNV2</a>(<a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>);
        <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{64}(address, accdesc) = value;
        return;
    end;
end;

accessor <anchor link="accessor_NVMem128_1">NVMem128</anchor>(offset : integer) &lt;=&gt; value : bits(128)
begin
    getter
        assert offset &gt; 0 &amp;&amp; offset MOD 16 == 0;
        let directread : boolean = FALSE;
        let baddr : bits(64)     = <a link="func_EffectiveBADDR_2" file="shared_pseudocode.xml">EffectiveBADDR</a>(VNCR_EL2().BADDR :: Zeros{12}, directread);
        let address : bits(64)   = baddr + offset;
        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescNV2_1" file="shared_pseudocode.xml">CreateAccDescNV2</a>(<a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>);
        return <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{128}(address, accdesc);
    end;

    setter
        assert offset &gt; 0 &amp;&amp; offset MOD 16 == 0;
        let directread : boolean = FALSE;
        let baddr : bits(64)     = <a link="func_EffectiveBADDR_2" file="shared_pseudocode.xml">EffectiveBADDR</a>(VNCR_EL2().BADDR :: Zeros{12}, directread);
        let address : bits(64)   = baddr + offset;
        let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescNV2_1" file="shared_pseudocode.xml">CreateAccDescNV2</a>(<a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>);
        <a link="accessor_Mem_3" file="shared_pseudocode.xml">Mem</a>{128}(address, accdesc) = value;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/PhysMemTagRead" mylink="aarch64.functions.memory.PhysMemTagRead" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PhysMemTagRead()
// ================
// This is the hardware operation which perform a single-copy atomic,
// Allocation Tag granule aligned, memory access from the tag in PA space.
//
// The function address the array using desc.paddress which supplies:
// * A 52-bit physical address
// * A single NS bit to select between Secure and Non-secure parts of the array.
//
// The accdesc descriptor describes the access type: normal, exclusive, ordered, streaming,
// etc and other parameters required to access the physical memory or for setting syndrome
// register in the event of an External abort.

impdef func <anchor link="func_PhysMemTagRead_2">PhysMemTagRead</anchor>(desc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                           accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; (<a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>, bits(4))
begin
    return (ARBITRARY : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>, Zeros{4});
end;</pstext></ps>
    <ps name="aarch64/functions/memory/PhysMemTagWrite" mylink="aarch64.functions.memory.PhysMemTagWrite" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PhysMemTagWrite()
// =================
// This is the hardware operation which perform a single-copy atomic,
// Allocation Tag granule aligned, memory access to the tag in PA space.
//
// The function address the array using desc.paddress which supplies:
// * A 52-bit physical address
// * A single NS bit to select between Secure and Non-secure parts of the array.
//
// The accdesc descriptor describes the access type: normal, exclusive, ordered, streaming,
// etc and other parameters required to access the physical memory or for setting syndrome
// register in the event of an External abort.

impdef func <anchor link="func_PhysMemTagWrite_3">PhysMemTagWrite</anchor>(desc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                            accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                            value : bits(4)) =&gt; <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>
begin
    return ARBITRARY : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
end;</pstext></ps>
    <ps name="aarch64/functions/memory/StoreOnlyTagCheckingEnabled" mylink="aarch64.functions.memory.StoreOnlyTagCheckingEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// StoreOnlyTagCheckingEnabled()
// =============================
// Returns TRUE if loads executed at the given Exception level are Tag unchecked.

func <anchor link="func_StoreOnlyTagCheckingEnabled_1">StoreOnlyTagCheckingEnabled</anchor>(el : bits(2)) =&gt; boolean
begin
    assert IsFeatureImplemented(FEAT_MTE_STORE_ONLY);
    var tcso : bit;

    case el of
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            if !<a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(el) then
                tcso = SCTLR_EL1().TCSO0;
            else
                tcso = SCTLR_EL2().TCSO0;
            end;
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            tcso = SCTLR_EL1().TCSO;
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            tcso = SCTLR_EL2().TCSO;
        otherwise =&gt;
            tcso = SCTLR_EL3().TCSO;
    end;

    return tcso == '1';
end;</pstext></ps>
    <ps name="aarch64/functions/mops/ArchMaxMOPSBlockSize" mylink="aarch64.functions.mops.ArchMaxMOPSBlockSize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ArchMaxMOPSBlockSize
// ====================
// Maximum number of bytes CPY/SET instructions can use

constant <anchor link="global_ArchMaxMOPSBlockSize">ArchMaxMOPSBlockSize</anchor> : integer{} = 0x7FFF_FFFF_FFFF_FFFF;</pstext></ps>
    <ps name="aarch64/functions/mops/ArchMaxMOPSCPYSize" mylink="aarch64.functions.mops.ArchMaxMOPSCPYSize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ArchMaxMOPSCPYSize
// ==================
// Maximum number of bytes CPY instructions can use

constant <anchor link="global_ArchMaxMOPSCPYSize">ArchMaxMOPSCPYSize</anchor> : integer{} = 0x007F_FFFF_FFFF_FFFF;</pstext></ps>
    <ps name="aarch64/functions/mops/ArchMaxMOPSSETGSize" mylink="aarch64.functions.mops.ArchMaxMOPSSETGSize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ArchMaxMOPSSETGSize
// ===================
// Maximum number of bytes SETG instructions can use

constant <anchor link="global_ArchMaxMOPSSETGSize">ArchMaxMOPSSETGSize</anchor> : integer{} = 0x7FFF_FFFF_FFFF_FFF0;</pstext></ps>
    <ps name="aarch64/functions/mops/CPYFOptionA" mylink="aarch64.functions.mops.CPYFOptionA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CPYFOptionA()
// =============
// Returns TRUE if the implementation uses Option A for the
// CPYF* instructions, and FALSE otherwise.

func <anchor link="func_CPYFOptionA_0">CPYFOptionA</anchor>() =&gt; boolean
begin
    return ImpDefBool(&quot;CPYF* instructions use Option A&quot;);
end;</pstext></ps>
    <ps name="aarch64/functions/mops/CPYOptionA" mylink="aarch64.functions.mops.CPYOptionA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CPYOptionA()
// ============
// Returns TRUE if the implementation uses Option A for the
// CPY* instructions, and FALSE otherwise.

func <anchor link="func_CPYOptionA_0">CPYOptionA</anchor>() =&gt; boolean
begin
    return ImpDefBool(&quot;CPY* instructions use Option A&quot;);
end;</pstext></ps>
    <ps name="aarch64/functions/mops/CPYParams" mylink="aarch64.functions.mops.CPYParams" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CPYParams
// =========

type <anchor link="type_CPYParams">CPYParams</anchor> of record {
    stage : <a link="type_MOPSStage" file="shared_pseudocode.xml">MOPSStage</a>,
    implements_option_a : boolean,
    forward : boolean,
    cpysize : integer,
    stagecpysize : integer,
    toaddress : bits(64),
    fromaddress : bits(64),
    nzcv : bits(4),
    n : integer,
    d : integer,
    s : integer
};</pstext></ps>
    <ps name="aarch64/functions/mops/CPYPostSizeChoice" mylink="aarch64.functions.mops.CPYPostSizeChoice" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CPYPostSizeChoice()
// ===================
// Returns the size of the copy that is performed by the CPYE* instructions for this
// implementation given the parameters of the destination, source and size of the copy.

impdef func <anchor link="func_CPYPostSizeChoice_1">CPYPostSizeChoice</anchor>(memcpy : <a link="type_CPYParams" file="shared_pseudocode.xml">CPYParams</a>) =&gt; integer
begin
    return ARBITRARY : integer;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/CPYPreSizeChoice" mylink="aarch64.functions.mops.CPYPreSizeChoice" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CPYPreSizeChoice()
// ==================
// Returns the size of the copy that is performed by the CPYP* instructions for this
// implementation given the parameters of the destination, source and size of the copy.

impdef func <anchor link="func_CPYPreSizeChoice_1">CPYPreSizeChoice</anchor>(memcpy : <a link="type_CPYParams" file="shared_pseudocode.xml">CPYParams</a>) =&gt; integer
begin
    return ARBITRARY : integer;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/CPYSizeChoice" mylink="aarch64.functions.mops.CPYSizeChoice" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CPYSizeChoice()
// ===============
// Returns the size of the block this performed for an iteration of the copy given the
// parameters of the destination, source and size of the copy.

impdef func <anchor link="func_CPYSizeChoice_1">CPYSizeChoice</anchor>(memcpy : <a link="type_CPYParams" file="shared_pseudocode.xml">CPYParams</a>) =&gt; <a link="type_MOPSBlockSize" file="shared_pseudocode.xml">MOPSBlockSize</a>
begin
    return ARBITRARY : <a link="type_MOPSBlockSize" file="shared_pseudocode.xml">MOPSBlockSize</a>;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/CheckCPYConstrainedUnpredictable" mylink="aarch64.functions.mops.CheckCPYConstrainedUnpredictable" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckCPYConstrainedUnpredictable()
// ==================================
// Check for CONSTRAINED UNPREDICTABLE behavior in the CPY* and CPYF* instructions.

func <anchor link="func_CheckCPYConstrainedUnpredictable_3">CheckCPYConstrainedUnpredictable</anchor>(n : integer, d : integer, s : integer)
begin
    if (s == n || s == d || n == d) then
        let c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = ConstrainUnpredictable(<a link="enum_Unpredictable_MOPSOVERLAP" file="shared_pseudocode.xml">Unpredictable_MOPSOVERLAP</a>);
        assert c IN {<a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a>, <a link="enum_Constraint_NOP" file="shared_pseudocode.xml">Constraint_NOP</a>};
        case c of
            when <a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a> =&gt;      Undefined();
            when <a link="enum_Constraint_NOP" file="shared_pseudocode.xml">Constraint_NOP</a> =&gt;        <a link="func_ExecuteAsNOP_0" file="shared_pseudocode.xml">ExecuteAsNOP</a>();
        end;
    end;

    if (d == 31 || s == 31 || n == 31) then
        let c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = ConstrainUnpredictable(<a link="enum_Unpredictable_MOPS_R31" file="shared_pseudocode.xml">Unpredictable_MOPS_R31</a>);
        assert c IN {<a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a>, <a link="enum_Constraint_NOP" file="shared_pseudocode.xml">Constraint_NOP</a>};
        case c of
            when <a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a> =&gt;      Undefined();
            when <a link="enum_Constraint_NOP" file="shared_pseudocode.xml">Constraint_NOP</a> =&gt;        <a link="func_ExecuteAsNOP_0" file="shared_pseudocode.xml">ExecuteAsNOP</a>();
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/CheckMOPSEnabled" mylink="aarch64.functions.mops.CheckMOPSEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckMOPSEnabled()
// ==================
// Check for EL0 and EL1 access to the CPY* and SET* instructions.

func <anchor link="func_CheckMOPSEnabled_0">CheckMOPSEnabled</anchor>()
begin
    if (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) &amp;&amp;
        (!<a link="func_IsHCRXEL2Enabled_0" file="shared_pseudocode.xml">IsHCRXEL2Enabled</a>() || HCRX_EL2().MSCEn == '0')) then
        Undefined();
    end;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() &amp;&amp; SCTLR_EL1().MSCEn == '0' then
        Undefined();
    end;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() &amp;&amp; SCTLR_EL2().MSCEn == '0' then
        Undefined();
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/CheckMemCpyParams" mylink="aarch64.functions.mops.CheckMemCpyParams" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckMemCpyParams()
// ===================
// Check if the parameters to a CPY* or CPYF* instruction are consistent with the
// PE state and well-formed.

func <anchor link="func_CheckMemCpyParams_2">CheckMemCpyParams</anchor>(memcpy : <a link="type_CPYParams" file="shared_pseudocode.xml">CPYParams</a>, options : bits(4))
begin
    let from_epilogue : boolean = memcpy.stage == <a link="enum_MOPSStage_Epilogue" file="shared_pseudocode.xml">MOPSStage_Epilogue</a>;

    // Check if this version is consistent with the state of the call.
    if ((memcpy.stagecpysize != 0 || <a link="func_MemStageCpyZeroSizeCheck_0" file="shared_pseudocode.xml">MemStageCpyZeroSizeCheck</a>()) &amp;&amp;
          (memcpy.cpysize != 0 || <a link="func_MemCpyZeroSizeCheck_0" file="shared_pseudocode.xml">MemCpyZeroSizeCheck</a>())) then
        let using_option_a : boolean = memcpy.nzcv[1] == '0';
        if memcpy.implements_option_a != using_option_a then
            let formatoption : bits(2) = '1':: (if memcpy.implements_option_a then '1' else '0');
            <a link="func_MismatchedMemCpyException_3" file="shared_pseudocode.xml">MismatchedMemCpyException</a>(memcpy, options, formatoption);
        end;
    end;

    // Check if the parameters to this instruction are valid.
    if memcpy.stage == <a link="enum_MOPSStage_Main" file="shared_pseudocode.xml">MOPSStage_Main</a> then
        if <a link="func_MemCpyParametersIllformedM_1" file="shared_pseudocode.xml">MemCpyParametersIllformedM</a>(memcpy) then
            let formatoption : bits(2) = '0':: (if memcpy.implements_option_a then '1' else '0');
            <a link="func_MismatchedMemCpyException_3" file="shared_pseudocode.xml">MismatchedMemCpyException</a>(memcpy, options, formatoption);
        end;
    else
        let postsize : integer = <a link="func_CPYPostSizeChoice_1" file="shared_pseudocode.xml">CPYPostSizeChoice</a>(memcpy);
        if memcpy.cpysize != postsize || <a link="func_MemCpyParametersIllformedE_1" file="shared_pseudocode.xml">MemCpyParametersIllformedE</a>(memcpy) then
            let formatoption : bits(2) = '0':: (if memcpy.implements_option_a then '1' else '0');
            <a link="func_MismatchedMemCpyException_3" file="shared_pseudocode.xml">MismatchedMemCpyException</a>(memcpy, options, formatoption);
        end;
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/CheckMemSetParams" mylink="aarch64.functions.mops.CheckMemSetParams" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckMemSetParams()
// ===================
// Check if the parameters to a SET* or SETG* instruction are consistent with the
// PE state and well-formed.

func <anchor link="func_CheckMemSetParams_2">CheckMemSetParams</anchor>(memset : <a link="type_SETParams" file="shared_pseudocode.xml">SETParams</a>, options : bits(2))
begin
    let from_epilogue : boolean = memset.stage == <a link="enum_MOPSStage_Epilogue" file="shared_pseudocode.xml">MOPSStage_Epilogue</a>;

    // Check if this version is consistent with the state of the call.
    if ((memset.stagesetsize != 0 || <a link="func_MemStageSetZeroSizeCheck_0" file="shared_pseudocode.xml">MemStageSetZeroSizeCheck</a>()) &amp;&amp;
          (memset.setsize != 0 || <a link="func_MemSetZeroSizeCheck_0" file="shared_pseudocode.xml">MemSetZeroSizeCheck</a>())) then
        let using_option_a : boolean = memset.nzcv[1] == '0';
        if memset.implements_option_a != using_option_a then
            let formatoption : bits(2) = '1':: (if memset.implements_option_a then '1' else '0');
            <a link="func_MismatchedMemSetException_3" file="shared_pseudocode.xml">MismatchedMemSetException</a>(memset, options, formatoption);
        end;
    end;

    // Check if the parameters to this instruction are valid.
    if memset.stage == <a link="enum_MOPSStage_Main" file="shared_pseudocode.xml">MOPSStage_Main</a> then
        if <a link="func_MemSetParametersIllformedM_1" file="shared_pseudocode.xml">MemSetParametersIllformedM</a>(memset) then
            let formatoption : bits(2) = '0':: (if memset.implements_option_a then '1' else '0');
            <a link="func_MismatchedMemSetException_3" file="shared_pseudocode.xml">MismatchedMemSetException</a>(memset, options, formatoption);
        end;
    else
        let postsize : integer = <a link="func_SETPostSizeChoice_1" file="shared_pseudocode.xml">SETPostSizeChoice</a>(memset);
        if memset.setsize != postsize || <a link="func_MemSetParametersIllformedE_1" file="shared_pseudocode.xml">MemSetParametersIllformedE</a>(memset) then
            let formatoption : bits(2) = '0':: (if memset.implements_option_a then '1' else '0');
            <a link="func_MismatchedMemSetException_3" file="shared_pseudocode.xml">MismatchedMemSetException</a>(memset, options, formatoption);
        end;
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/CheckSETConstrainedUnpredictable" mylink="aarch64.functions.mops.CheckSETConstrainedUnpredictable" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckSETConstrainedUnpredictable()
// ==================================
// Check for CONSTRAINED UNPREDICTABLE behavior in the SET* and SETG* instructions.

func <anchor link="func_CheckSETConstrainedUnpredictable_1">CheckSETConstrainedUnpredictable</anchor>(memset : <a link="type_SETParams" file="shared_pseudocode.xml">SETParams</a>)
begin
    if (memset.s == memset.n || memset.s == memset.d || memset.n == memset.d) then
        let c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = ConstrainUnpredictable(<a link="enum_Unpredictable_MOPSOVERLAP" file="shared_pseudocode.xml">Unpredictable_MOPSOVERLAP</a>);
        assert c IN {<a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a>, <a link="enum_Constraint_NOP" file="shared_pseudocode.xml">Constraint_NOP</a>};
        case c of
            when <a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a> =&gt; Undefined();
            when <a link="enum_Constraint_NOP" file="shared_pseudocode.xml">Constraint_NOP</a>   =&gt; <a link="func_ExecuteAsNOP_0" file="shared_pseudocode.xml">ExecuteAsNOP</a>();
        end;
    end;

    if (memset.d == 31 || memset.n == 31) then
        let c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = ConstrainUnpredictable(<a link="enum_Unpredictable_MOPS_R31" file="shared_pseudocode.xml">Unpredictable_MOPS_R31</a>);
        assert c IN {<a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a>, <a link="enum_Constraint_NOP" file="shared_pseudocode.xml">Constraint_NOP</a>};
        case c of
            when <a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a> =&gt; Undefined();
            when <a link="enum_Constraint_NOP" file="shared_pseudocode.xml">Constraint_NOP</a>   =&gt; <a link="func_ExecuteAsNOP_0" file="shared_pseudocode.xml">ExecuteAsNOP</a>();
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/IsMemCpyForward" mylink="aarch64.functions.mops.IsMemCpyForward" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsMemCpyForward()
// =================
// Returns TRUE if in a memcpy of size cpysize bytes from the source address fromaddress
// to destination address toaddress is done in the forward direction on this implementation.

func <anchor link="func_IsMemCpyForward_1">IsMemCpyForward</anchor>(memcpy : <a link="type_CPYParams" file="shared_pseudocode.xml">CPYParams</a>) =&gt; boolean
begin
    var forward : boolean;

    // Check for overlapping cases
    if ((UInt(memcpy.fromaddress[55:0]) &gt; UInt(memcpy.toaddress[55:0])) &amp;&amp;
          (UInt(memcpy.fromaddress[55:0]) &lt; UInt(ZeroExtend{64}(memcpy.toaddress[55:0]) +
             memcpy.cpysize))) then
        forward = TRUE;

    elsif ((UInt(memcpy.fromaddress[55:0]) &lt; UInt(memcpy.toaddress[55:0])) &amp;&amp;
             (UInt(ZeroExtend{64}(memcpy.fromaddress[55:0]) + memcpy.cpysize) &gt;
                UInt(memcpy.toaddress[55:0]))) then
        forward = FALSE;

    // Non-overlapping case
    else
        forward = ImpDefBool(&quot;CPY in the forward direction&quot;);
    end;

    return forward;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/MOPSBlockSize" mylink="aarch64.functions.mops.MOPSBlockSize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MOPSBlockSize
// ================

type <anchor link="type_MOPSBlockSize">MOPSBlockSize</anchor> of integer{0..MaxMOPSBlockSize};</pstext></ps>
    <ps name="aarch64/functions/mops/MOPSStage" mylink="aarch64.functions.mops.MOPSStage" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MOPSStage
// =========

type <anchor link="type_MOPSStage">MOPSStage</anchor> of enumeration { <anchor link="enum_MOPSStage_Prologue">MOPSStage_Prologue</anchor>, <anchor link="enum_MOPSStage_Main">MOPSStage_Main</anchor>, <anchor link="enum_MOPSStage_Epilogue">MOPSStage_Epilogue</anchor> };</pstext></ps>
    <ps name="aarch64/functions/mops/MaxBlockSizeCopiedBytes" mylink="aarch64.functions.mops.MaxBlockSizeCopiedBytes" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MaxBlockSizeCopiedBytes()
// =========================
// Returns the maximum number of bytes that can used in a single block of the copy.

func <anchor link="func_MaxBlockSizeCopiedBytes_0">MaxBlockSizeCopiedBytes</anchor>() =&gt; integer
begin
    return ImpDefInt(&quot;Maximum bytes used in a single block of a copy&quot;);
end;</pstext></ps>
    <ps name="aarch64/functions/mops/MaxMOPSBlockSize" mylink="aarch64.functions.mops.MaxMOPSBlockSize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MaxMOPSBlockSize
// ================
// Maximum number of bytes CPY/SET instructions can use

config MaxMOPSBlockSize : integer{1..<a link="global_ArchMaxMOPSBlockSize" file="shared_pseudocode.xml">ArchMaxMOPSBlockSize</a>} = 64;</pstext></ps>
    <ps name="aarch64/functions/mops/MemCpyBytes" mylink="aarch64.functions.mops.MemCpyBytes" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemCpyBytes()
// =============
// Copies 'bytes' bytes of memory from fromaddress to toaddress.
// The integer return parameter indicates the number of bytes copied. The boolean return parameter
// indicates if a Fault or Abort occurred on the write. The AddressDescriptor and PhysMemRetStatus
// parameters contain Fault or Abort information for the caller to handle.

func <anchor link="func_MemCpyBytes_6">MemCpyBytes</anchor>(toaddress : bits(64),
                 fromaddress : bits(64),
                 forward : boolean,
                 bytes : <a link="type_MOPSBlockSize" file="shared_pseudocode.xml">MOPSBlockSize</a>,
                 raccdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                 waccdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
                ) =&gt; (integer, boolean, <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>)
begin
    var rmemaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;                 // AddressDescriptor for reads
    var rmemstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;                   // PhysMemRetStatus  for writes
    rmemaddrdesc.fault    = <a link="func_NoFault_0" file="shared_pseudocode.xml">NoFault</a>();
    rmemstatus.statuscode = <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;

    var wmemaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;                 // AddressDescriptor for writes
    var wmemstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;                   // PhysMemRetStatus  for writes
    wmemaddrdesc.fault    = <a link="func_NoFault_0" file="shared_pseudocode.xml">NoFault</a>();
    wmemstatus.statuscode = <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;

    var value : bits(8*bytes);
    let aligned : boolean = TRUE;

    if forward then
        var read : integer  = 0;                          // Bytes read
        var write : integer = 0;                          // Bytes written

        // Read until all bytes are read or until a fault is encountered.
        while (read &lt; bytes &amp;&amp; !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(rmemaddrdesc) &amp;&amp; !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(rmemstatus))
                                            looplimit MaxMOPSBlockSize do
            (value[8 * read +:8], rmemaddrdesc, rmemstatus) = <a link="func_AArch64_MemSingleRead_4" file="shared_pseudocode.xml">AArch64_MemSingleRead</a>{8}(
                                                                            fromaddress + read,
                                                                            raccdesc, aligned);
            read = read + 1;
        end;

        // Ensure no UNKNOWN data is written.
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(rmemaddrdesc) || <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(rmemstatus) then
            read = read - 1;
        end;

        // Write all bytes that were read or until a fault is encountered.
        while write &lt; read &amp;&amp; !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(wmemaddrdesc) &amp;&amp; !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(wmemstatus)
                                        looplimit MaxMOPSBlockSize  do
            (wmemaddrdesc, wmemstatus) = <a link="func_AArch64_MemSingleWrite_5" file="shared_pseudocode.xml">AArch64_MemSingleWrite</a>{8}(toaddress + write,
                                                                waccdesc, aligned,
                                                                value[8 * write +:8]);
            write = write + 1;
        end;

        // Check all bytes were written.
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(wmemaddrdesc) || <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(wmemstatus) then
            let fault_on_write : boolean = TRUE;
            return (write - 1, fault_on_write, wmemaddrdesc, wmemstatus);
        end;

        // Check all bytes were read.
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(rmemaddrdesc) || <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(rmemstatus) then
            let fault_on_write : boolean = FALSE;
            return (read, fault_on_write, rmemaddrdesc, rmemstatus);
        end;

    else
        var read : integer  = bytes;                      // Bytes to read
        var write : integer = bytes;                      // Bytes to write

        // Read until all bytes are read or until a fault is encountered.
        while read &gt; 0 &amp;&amp; !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(rmemaddrdesc) &amp;&amp; !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(rmemstatus)
                                            looplimit MaxMOPSBlockSize do
            read = read - 1;
            (value[8 * read +:8], rmemaddrdesc, rmemstatus) = <a link="func_AArch64_MemSingleRead_4" file="shared_pseudocode.xml">AArch64_MemSingleRead</a>{8}(
                                                                            fromaddress + read,
                                                                            raccdesc, aligned);
        end;

        // Ensure no UNKNOWN data is written.
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(rmemaddrdesc) || <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(rmemstatus) then
            read = read + 1;
        end;

        // Write all bytes that were read or until a fault is encountered.
        while write &gt; read &amp;&amp; !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(wmemaddrdesc) &amp;&amp; !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(wmemstatus)
                                                looplimit MaxMOPSBlockSize do
            write = write - 1;
            (wmemaddrdesc, wmemstatus) = <a link="func_AArch64_MemSingleWrite_5" file="shared_pseudocode.xml">AArch64_MemSingleWrite</a>{8}(toaddress + write,
                                                                waccdesc, aligned,
                                                                value[8 * write +:8]);
        end;

        // Check all bytes were written.
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(wmemaddrdesc) || <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(wmemstatus) then
            let fault_on_write : boolean = TRUE;
            return (bytes - (write + 1), fault_on_write, wmemaddrdesc, wmemstatus);
        end;

        // Check all bytes were read.
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(rmemaddrdesc) || <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(rmemstatus) then
            let fault_on_write : boolean = FALSE;
            return (bytes - read, fault_on_write, rmemaddrdesc, rmemstatus);
        end;
    end;

    // Return any AddressDescriptor and PhysMemRetStatus.
    return (bytes, FALSE, wmemaddrdesc, wmemstatus);
end;</pstext></ps>
    <ps name="aarch64/functions/mops/MemCpyParametersIllformedE" mylink="aarch64.functions.mops.MemCpyParametersIllformedE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemCpyParametersIllformedE()
// ============================
// Returns TRUE if the inputs are not well formed (in terms of their size and/or alignment)
// for a CPYE* instruction for this implementation given the parameters of the destination,
// source and size of the copy.

impdef func <anchor link="func_MemCpyParametersIllformedE_1">MemCpyParametersIllformedE</anchor>(memcpy : <a link="type_CPYParams" file="shared_pseudocode.xml">CPYParams</a>) =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/MemCpyParametersIllformedM" mylink="aarch64.functions.mops.MemCpyParametersIllformedM" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemCpyParametersIllformedM()
// ============================
// Returns TRUE if the inputs are not well formed (in terms of their size and/or alignment)
// for a CPYM* instruction for this implementation given the parameters of the destination,
// source and size of the copy.

impdef func <anchor link="func_MemCpyParametersIllformedM_1">MemCpyParametersIllformedM</anchor>(memcpy : <a link="type_CPYParams" file="shared_pseudocode.xml">CPYParams</a>) =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/MemCpyStageSize" mylink="aarch64.functions.mops.MemCpyStageSize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemCpyStageSize()
// =================
// Returns the number of bytes copied by the given stage of a CPY* or CPYF* instruction.

func <anchor link="func_MemCpyStageSize_1">MemCpyStageSize</anchor>(memcpy : <a link="type_CPYParams" file="shared_pseudocode.xml">CPYParams</a>) =&gt; integer
begin
    var stagecpysize : integer;

    if memcpy.stage == <a link="enum_MOPSStage_Prologue" file="shared_pseudocode.xml">MOPSStage_Prologue</a> then
        // IMP DEF selection of the amount covered by pre-processing.
        stagecpysize = <a link="func_CPYPreSizeChoice_1" file="shared_pseudocode.xml">CPYPreSizeChoice</a>(memcpy);
        assert stagecpysize == 0 || (stagecpysize &lt; 0) == (memcpy.cpysize &lt; 0);

        if memcpy.cpysize &gt; 0 then
            assert stagecpysize &lt;= memcpy.cpysize;
        else
            assert stagecpysize &gt;= memcpy.cpysize;
        end;

    else
        let postsize : integer = <a link="func_CPYPostSizeChoice_1" file="shared_pseudocode.xml">CPYPostSizeChoice</a>(memcpy);
        assert postsize == 0 || (postsize &lt; 0) == (memcpy.cpysize &lt; 0);

        if memcpy.stage == <a link="enum_MOPSStage_Main" file="shared_pseudocode.xml">MOPSStage_Main</a> then
            stagecpysize = memcpy.cpysize - postsize;
        else
            stagecpysize = postsize;
        end;
    end;

    return stagecpysize;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/MemCpyZeroSizeCheck" mylink="aarch64.functions.mops.MemCpyZeroSizeCheck" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemCpyZeroSizeCheck()
// =====================
// Returns TRUE if the implementation option is checked on a copy of size zero remaining.

func <anchor link="func_MemCpyZeroSizeCheck_0">MemCpyZeroSizeCheck</anchor>() =&gt; boolean
begin
    return ImpDefBool(&quot;Implementation option is checked with a cpysize of 0&quot;);
end;</pstext></ps>
    <ps name="aarch64/functions/mops/MemSetBytes" mylink="aarch64.functions.mops.MemSetBytes" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemSetBytes()
// =============
// Writes a byte of data to the given address 'bytes' times.
// The integer return parameter indicates the number of bytes set. The AddressDescriptor and
// PhysMemRetStatus parameters contain Fault or Abort information for the caller to handle.

func <anchor link="func_MemSetBytes_4">MemSetBytes</anchor>(toaddress : bits(64), data : bits(8),
                 bytes : <a link="type_MOPSBlockSize" file="shared_pseudocode.xml">MOPSBlockSize</a>,
                 accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; (integer, <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>)
begin
    var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
    memaddrdesc.fault    = <a link="func_NoFault_0" file="shared_pseudocode.xml">NoFault</a>();
    memstatus.statuscode = <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;

    let aligned : boolean = TRUE;
    var write : integer   = 0;                            // Bytes written

    // Write until all bytes are written or a fault is encountered.
    while write &lt; bytes &amp;&amp; !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) &amp;&amp; !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus)
                                                looplimit MaxMOPSBlockSize do
        (memaddrdesc, memstatus) = <a link="func_AArch64_MemSingleWrite_5" file="shared_pseudocode.xml">AArch64_MemSingleWrite</a>{8}(toaddress + write, accdesc,
                                                             aligned, data);
        write = write + 1;
    end;

    // Check all bytes were written.
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) || <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
        return (write - 1, memaddrdesc, memstatus);
    end;

    return (bytes, memaddrdesc, memstatus);
end;</pstext></ps>
    <ps name="aarch64/functions/mops/MemSetParametersIllformedE" mylink="aarch64.functions.mops.MemSetParametersIllformedE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemSetParametersIllformedE()
// ============================
// Returns TRUE if the inputs are not well formed (in terms of their size and/or
// alignment) for a SETE* or SETGE* instruction for this implementation given the
// parameters of the destination and size of the set.

impdef func <anchor link="func_MemSetParametersIllformedE_1">MemSetParametersIllformedE</anchor>(memset : <a link="type_SETParams" file="shared_pseudocode.xml">SETParams</a>) =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/MemSetParametersIllformedM" mylink="aarch64.functions.mops.MemSetParametersIllformedM" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemSetParametersIllformedM()
// ============================
// Returns TRUE if the inputs are not well formed (in terms of their size and/or
// alignment) for a SETM* or SETGM* instruction for this implementation given the
// parameters of the destination and size of the copy.

impdef func <anchor link="func_MemSetParametersIllformedM_1">MemSetParametersIllformedM</anchor>(memset : <a link="type_SETParams" file="shared_pseudocode.xml">SETParams</a>) =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/MemSetStageSize" mylink="aarch64.functions.mops.MemSetStageSize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemSetStageSize()
// =================
// Returns the number of bytes set by the given stage of a SET* or SETG* instruction.

func <anchor link="func_MemSetStageSize_1">MemSetStageSize</anchor>(memset : <a link="type_SETParams" file="shared_pseudocode.xml">SETParams</a>) =&gt; integer
begin
    var stagesetsize : integer;

    if memset.stage == <a link="enum_MOPSStage_Prologue" file="shared_pseudocode.xml">MOPSStage_Prologue</a> then
        // IMP DEF selection of the amount covered by pre-processing.
        stagesetsize = <a link="func_SETPreSizeChoice_1" file="shared_pseudocode.xml">SETPreSizeChoice</a>(memset);
        assert stagesetsize == 0 || (stagesetsize &lt; 0) == (memset.setsize &lt; 0);

        if memset.is_setg then assert stagesetsize[3:0] == '0000'; end;

        if memset.setsize &gt; 0 then
            assert stagesetsize &lt;= memset.setsize;
        else
            assert stagesetsize &gt;= memset.setsize;
        end;

    else
        let postsize : integer = <a link="func_SETPostSizeChoice_1" file="shared_pseudocode.xml">SETPostSizeChoice</a>(memset);
        assert postsize == 0 || (postsize &lt; 0) == (memset.setsize &lt; 0);
        if memset.is_setg then assert postsize[3:0] == '0000'; end;

        if memset.stage == <a link="enum_MOPSStage_Main" file="shared_pseudocode.xml">MOPSStage_Main</a> then
            stagesetsize = memset.setsize - postsize;
        else
            stagesetsize = postsize;
        end;
    end;

    return stagesetsize;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/MemSetTags" mylink="aarch64.functions.mops.MemSetTags" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemSetTags()
// ============
// Write Allocation Tags for each Tag Granule in 'size'.
// The integer return parameter indicates the number of Tag Granules written. The
// AddressDescriptor and PhysMemRetStatus parameters contain Fault or Abort information for
// the caller to handle.

func <anchor link="func_MemSetTags_4">MemSetTags</anchor>(toaddress : bits(64), tag : bits(4),
                size : integer, accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
            ) =&gt; (integer, <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>)
begin
    assert IsAlignedSize{64}(toaddress, <a link="global_TAG_GRANULE" file="shared_pseudocode.xml">TAG_GRANULE</a>) &amp;&amp; size MOD <a link="global_TAG_GRANULE" file="shared_pseudocode.xml">TAG_GRANULE</a> == 0;

    var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
    memaddrdesc.fault     = <a link="func_NoFault_0" file="shared_pseudocode.xml">NoFault</a>();
    memstatus.statuscode  = <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;
    var tagstep : integer = size DIV <a link="global_TAG_GRANULE" file="shared_pseudocode.xml">TAG_GRANULE</a>;

    // Write until all tags are written or a fault is encountered.
    while tagstep &gt; 0 &amp;&amp; !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) &amp;&amp; !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus)
                                                looplimit <a link="global_ArchMaxMOPSSETGSize" file="shared_pseudocode.xml">ArchMaxMOPSSETGSize</a> DIV <a link="global_TAG_GRANULE" file="shared_pseudocode.xml">TAG_GRANULE</a> do
        let tagaddr : bits(64) = toaddress + (tagstep - 1) * <a link="global_TAG_GRANULE" file="shared_pseudocode.xml">TAG_GRANULE</a>;
        (memaddrdesc, memstatus) = <a link="func_AArch64_MemTagWrite_3" file="shared_pseudocode.xml">AArch64_MemTagWrite</a>(tagaddr, accdesc, tag);
        tagstep = tagstep - 1;
    end;

    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) || <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
        tagstep = tagstep + 1;
    end;

    let tags_written : integer = (size DIV <a link="global_TAG_GRANULE" file="shared_pseudocode.xml">TAG_GRANULE</a>) - tagstep;
    return (tags_written, memaddrdesc, memstatus);
end;</pstext></ps>
    <ps name="aarch64/functions/mops/MemSetZeroSizeCheck" mylink="aarch64.functions.mops.MemSetZeroSizeCheck" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemSetZeroSizeCheck()
// =====================
// Returns TRUE if the implementation option is checked on a set of size zero remaining.

func <anchor link="func_MemSetZeroSizeCheck_0">MemSetZeroSizeCheck</anchor>() =&gt; boolean
begin
    return ImpDefBool(&quot;Implementation option is checked with a setsize of 0&quot;);
end;</pstext></ps>
    <ps name="aarch64/functions/mops/MemStageCpyZeroSizeCheck" mylink="aarch64.functions.mops.MemStageCpyZeroSizeCheck" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemStageCpyZeroSizeCheck()
// ==========================
// Returns TRUE if the implementation option is checked on a stage copy of size zero remaining.

func <anchor link="func_MemStageCpyZeroSizeCheck_0">MemStageCpyZeroSizeCheck</anchor>() =&gt; boolean
begin
    return (ImpDefBool(
            &quot;Implementation option is checked with a stage cpysize of 0&quot;));
end;</pstext></ps>
    <ps name="aarch64/functions/mops/MemStageSetZeroSizeCheck" mylink="aarch64.functions.mops.MemStageSetZeroSizeCheck" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemStageSetZeroSizeCheck()
// ==========================
// Returns TRUE if the implementation option is checked on a stage set of size zero remaining.

func <anchor link="func_MemStageSetZeroSizeCheck_0">MemStageSetZeroSizeCheck</anchor>() =&gt; boolean
begin
    return (ImpDefBool(
            &quot;Implementation option is checked with a stage setsize of 0&quot;));
end;</pstext></ps>
    <ps name="aarch64/functions/mops/MismatchedCpySetTargetEL" mylink="aarch64.functions.mops.MismatchedCpySetTargetEL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MismatchedCpySetTargetEL()
// ==========================
// Return the target exception level for an Exception_MemCpyMemSet.

func <anchor link="func_MismatchedCpySetTargetEL_0">MismatchedCpySetTargetEL</anchor>() =&gt; bits(2)
begin
    var target_el : bits(2);

    if UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) &gt; UInt(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        target_el = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
    elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1' then
        target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    elsif (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
        <a link="func_IsHCRXEL2Enabled_0" file="shared_pseudocode.xml">IsHCRXEL2Enabled</a>() &amp;&amp; HCRX_EL2().MCE2 == '1') then
        target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    else
        target_el = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    end;

    return target_el;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/MismatchedMemCpyException" mylink="aarch64.functions.mops.MismatchedMemCpyException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MismatchedMemCpyException()
// ===========================
// Generates an exception for a CPY* instruction if the version
// is inconsistent with the state of the call.

func <anchor link="func_MismatchedMemCpyException_3">MismatchedMemCpyException</anchor>(memcpy : <a link="type_CPYParams" file="shared_pseudocode.xml">CPYParams</a>, options : bits(4), formatoption : bits(2))
begin
    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer                 = 0x0;
    let target_el : bits(2)                   = <a link="func_MismatchedCpySetTargetEL_0" file="shared_pseudocode.xml">MismatchedCpySetTargetEL</a>();

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_MemCpyMemSet" file="shared_pseudocode.xml">Exception_MemCpyMemSet</a>);
    except.syndrome.iss[24]    = '0';
    except.syndrome.iss[23]    = '0';
    except.syndrome.iss[22:19] = options;
    except.syndrome.iss[18]    = if memcpy.stage == <a link="enum_MOPSStage_Epilogue" file="shared_pseudocode.xml">MOPSStage_Epilogue</a> then '1' else '0';
    except.syndrome.iss[17:16] = formatoption;
    // exception.syndrome[15] is RES0.
    except.syndrome.iss[14:10] = memcpy.d[4:0];
    except.syndrome.iss[9:5]   = memcpy.s[4:0];
    except.syndrome.iss[4:0]   = memcpy.n[4:0];

    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/functions/mops/MismatchedMemSetException" mylink="aarch64.functions.mops.MismatchedMemSetException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MismatchedMemSetException()
// ===========================
// Generates an exception for a SET* instruction if the version
// is inconsistent with the state of the call.

func <anchor link="func_MismatchedMemSetException_3">MismatchedMemSetException</anchor>(memset : <a link="type_SETParams" file="shared_pseudocode.xml">SETParams</a>, options : bits(2), formatoption : bits(2))
begin
    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;
    let target_el : bits(2) = <a link="func_MismatchedCpySetTargetEL_0" file="shared_pseudocode.xml">MismatchedCpySetTargetEL</a>();

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_MemCpyMemSet" file="shared_pseudocode.xml">Exception_MemCpyMemSet</a>);
    except.syndrome.iss[24]    = '1';
    except.syndrome.iss[23]    = if memset.is_setg then '1' else '0';
    // exception.syndrome[22:21] is RES0.
    except.syndrome.iss[20:19] = options;
    except.syndrome.iss[18]    = if memset.stage == <a link="enum_MOPSStage_Epilogue" file="shared_pseudocode.xml">MOPSStage_Epilogue</a> then '1' else '0';
    except.syndrome.iss[17:16] = formatoption;
    // exception.syndrome[15] is RES0.
    except.syndrome.iss[14:10] = memset.d[4:0];
    except.syndrome.iss[9:5]   = memset.s[4:0];
    except.syndrome.iss[4:0]   = memset.n[4:0];

    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/functions/mops/SETGOptionA" mylink="aarch64.functions.mops.SETGOptionA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SETGOptionA()
// =============
// Returns TRUE if the implementation uses Option A for the
// SETG* instructions, and FALSE otherwise.

func <anchor link="func_SETGOptionA_0">SETGOptionA</anchor>() =&gt; boolean
begin
    return ImpDefBool(&quot;SETG* instructions use Option A&quot;);
end;</pstext></ps>
    <ps name="aarch64/functions/mops/SETOptionA" mylink="aarch64.functions.mops.SETOptionA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SETOptionA()
// ============
// Returns TRUE if the implementation uses Option A for the
// SET* instructions, and FALSE otherwise.

func <anchor link="func_SETOptionA_0">SETOptionA</anchor>() =&gt; boolean
begin
    return ImpDefBool(&quot;SET* instructions use Option A&quot;);
end;</pstext></ps>
    <ps name="aarch64/functions/mops/SETParams" mylink="aarch64.functions.mops.SETParams" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SETParams
// =========

type <anchor link="type_SETParams">SETParams</anchor> of record {
    stage : <a link="type_MOPSStage" file="shared_pseudocode.xml">MOPSStage</a>,
    implements_option_a : boolean,
    is_setg : boolean,
    setsize : integer,
    stagesetsize : integer,
    toaddress : bits(64),
    nzcv : bits(4),
    n : integer,
    d : integer,
    s : integer
};</pstext></ps>
    <ps name="aarch64/functions/mops/SETPostSizeChoice" mylink="aarch64.functions.mops.SETPostSizeChoice" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SETPostSizeChoice()
// ===================
// Returns the size of the set that is performed by the SETE* or SETGE* instructions
// for this implementation, given the parameters of the destination and size of the set.

impdef func <anchor link="func_SETPostSizeChoice_1">SETPostSizeChoice</anchor>(memset : <a link="type_SETParams" file="shared_pseudocode.xml">SETParams</a>) =&gt; integer
begin
    return ARBITRARY : integer;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/SETPreSizeChoice" mylink="aarch64.functions.mops.SETPreSizeChoice" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SETPreSizeChoice()
// ==================
// Returns the size of the set that is performed by the SETP* or SETGP* instructions
// for this implementation, given the parameters of the destination and size of the set.

impdef func <anchor link="func_SETPreSizeChoice_1">SETPreSizeChoice</anchor>(memset : <a link="type_SETParams" file="shared_pseudocode.xml">SETParams</a>) =&gt; integer
begin
    return ARBITRARY : integer;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/SETSizeChoice" mylink="aarch64.functions.mops.SETSizeChoice" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SETSizeChoice()
// ===============
// Returns the size of the block this performed for an iteration of the set given
// the parameters of the destination and size of the set. The size of the block
// is an integer multiple of alignsize.

impdef func <anchor link="func_SETSizeChoice_2">SETSizeChoice</anchor>(memset : <a link="type_SETParams" file="shared_pseudocode.xml">SETParams</a>, alignsize : integer) =&gt; <a link="type_MOPSBlockSize" file="shared_pseudocode.xml">MOPSBlockSize</a>
begin
    return ARBITRARY : <a link="type_MOPSBlockSize" file="shared_pseudocode.xml">MOPSBlockSize</a>;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/UpdateCpyRegisters" mylink="aarch64.functions.mops.UpdateCpyRegisters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// UpdateCpyRegisters()
// ====================
// Performs updates to the X[n], X[d], and X[s] registers, as appropriate, for the CPY* and CPYF*
// instructions. When fault is TRUE, the values correspond to the first element not copied,
// such that a return to the instruction will enable a resumption of the copy.

func <anchor link="func_UpdateCpyRegisters_3">UpdateCpyRegisters</anchor>(memcpy : <a link="type_CPYParams" file="shared_pseudocode.xml">CPYParams</a>, fault : boolean, copied : integer)
begin
    if fault then
        if memcpy.stage == <a link="enum_MOPSStage_Prologue" file="shared_pseudocode.xml">MOPSStage_Prologue</a> then
            // Undo any formatting of the input parameters performed in the prologue.
            if memcpy.implements_option_a then
                if memcpy.forward then
                    // cpysize is negative.
                    let cpysize : integer  = memcpy.cpysize + copied;
                    <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memcpy.n)  = (0 - cpysize)[63:0];
                    <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memcpy.d)  = memcpy.toaddress   + cpysize;
                    <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memcpy.s)  = memcpy.fromaddress + cpysize;

                else
                    <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memcpy.n) = (memcpy.cpysize - copied)[63:0];
                end;

            else
                if memcpy.forward then
                    <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memcpy.n) = (memcpy.cpysize - copied)[63:0];
                    <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memcpy.d) = memcpy.toaddress   + copied;
                    <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memcpy.s) = memcpy.fromaddress + copied;

                else
                    <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memcpy.n)  = (memcpy.cpysize - copied)[63:0];
                end;
            end;

        else
            if memcpy.implements_option_a then
                if memcpy.forward then
                    <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memcpy.n) = (memcpy.cpysize + copied)[63:0];
                else
                    <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memcpy.n) = (memcpy.cpysize - copied)[63:0];
                end;

            else
                <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memcpy.n) = (memcpy.cpysize - copied)[63:0];

                if memcpy.forward then
                    <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memcpy.d) = memcpy.toaddress   + copied;
                    <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memcpy.s) = memcpy.fromaddress + copied;
                else
                    <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memcpy.d) = memcpy.toaddress   - copied;
                    <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memcpy.s) = memcpy.fromaddress - copied;
                end;
            end;
        end;
    else
        <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memcpy.n) = memcpy.cpysize[63:0];
        if memcpy.stage == <a link="enum_MOPSStage_Prologue" file="shared_pseudocode.xml">MOPSStage_Prologue</a> || !memcpy.implements_option_a then
            <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memcpy.d) = memcpy.toaddress;
            <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memcpy.s) = memcpy.fromaddress;
        end;
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/mops/UpdateSetRegisters" mylink="aarch64.functions.mops.UpdateSetRegisters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// UpdateSetRegisters()
// ====================
// Performs updates to the X[n] and X[d] registers, as appropriate, for the SET* and SETG*
// instructions. When fault is TRUE, the values correspond to the first element not set, such
// that a return to the instruction will enable a resumption of the memory set.

func <anchor link="func_UpdateSetRegisters_3">UpdateSetRegisters</anchor>(memset : <a link="type_SETParams" file="shared_pseudocode.xml">SETParams</a>, fault : boolean, memory_set : integer)
begin
    if fault then
        // Undo any formatting of the input parameters performed in the prologue.
        if memset.stage == <a link="enum_MOPSStage_Prologue" file="shared_pseudocode.xml">MOPSStage_Prologue</a> then
            if memset.implements_option_a then
                // setsize is negative.
                let setsize : integer = memset.setsize   + memory_set;
                <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memset.n) = (0 - setsize)[63:0];
                <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memset.d) = memset.toaddress + setsize;
            else
                <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memset.n) = (memset.setsize - memory_set)[63:0];
                <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memset.d) = memset.toaddress + memory_set;
            end;

        else
            if memset.implements_option_a then
                <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memset.n) = (memset.setsize + memory_set)[63:0];
            else
                <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memset.n) = (memset.setsize - memory_set)[63:0];
                <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memset.d) = memset.toaddress + memory_set;
            end;
        end;
    else
        <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memset.n) = memset.setsize[63:0];
        if memset.stage == <a link="enum_MOPSStage_Prologue" file="shared_pseudocode.xml">MOPSStage_Prologue</a> || !memset.implements_option_a then
            <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(memset.d) = memset.toaddress;
        end;
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/movewideop/MoveWideOp" mylink="aarch64.functions.movewideop.MoveWideOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MoveWideOp
// ==========
// Move wide 16-bit immediate instruction types.

type <anchor link="type_MoveWideOp">MoveWideOp</anchor> of enumeration {<anchor link="enum_MoveWideOp_N">MoveWideOp_N</anchor>, <anchor link="enum_MoveWideOp_Z">MoveWideOp_Z</anchor>, <anchor link="enum_MoveWideOp_K">MoveWideOp_K</anchor>};</pstext></ps>
    <ps name="aarch64/functions/movwpreferred/MoveWidePreferred" mylink="aarch64.functions.movwpreferred.MoveWidePreferred" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MoveWidePreferred()
// ===================
//
// Return TRUE if a bitmask immediate encoding would generate an immediate
// value that could also be represented by a single MOVZ or MOVN instruction.
// Used as a condition for the preferred MOV&lt;-ORR alias.

func <anchor link="func_MoveWidePreferred_4">MoveWidePreferred</anchor>(sf : bit, immN : bit, imms : bits(6), immr : bits(6)) =&gt; boolean
begin
    let s : integer = UInt(imms);
    let r : integer = UInt(immr);
    let width : integer = if sf == '1' then 64 else 32;

    // element size must equal total immediate size
    if sf == '1' &amp;&amp; (immN::imms) != '1xxxxxx' then
        return FALSE;
    end;
    if sf == '0' &amp;&amp; (immN::imms) != '00xxxxx' then
        return FALSE;
    end;

    // for MOVZ must contain no more than 16 ones
    if s &lt; 16 then
        // ones must not span halfword boundary when rotated
        return (-r MOD 16) &lt;= (15 - s);
    end;

    // for MOVN must contain no more than 16 zeros
    if s &gt;= width - 15 then
        // zeros must not span halfword boundary when rotated
        return (r MOD 16) &lt;= (s - (width - 15));
    end;

    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/addpac/AddPAC" mylink="aarch64.functions.pac.addpac.AddPAC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddPAC()
// ========
// Calculates the pointer authentication code for a 64-bit quantity and then
// inserts that into pointer authentication code field of that 64-bit quantity.

func <anchor link="func_AddPAC_4">AddPAC</anchor>(ptr : bits(64), modifier : bits(64), K : bits(128), data : boolean) =&gt; bits(64)
begin
    let use_modifier2 : boolean = FALSE;
    return <a link="func_InsertPAC_6" file="shared_pseudocode.xml">InsertPAC</a>(ptr, modifier, Zeros{64}, use_modifier2, K, data);
end;</pstext></ps>
    <ps name="aarch64/functions/pac/addpac/AddPAC2" mylink="aarch64.functions.pac.addpac.AddPAC2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddPAC2()
// =========
// Calculates the pointer authentication code for a 64-bit quantity and then
// inserts that into pointer authentication code field of that 64-bit quantity.

func <anchor link="func_AddPAC2_5">AddPAC2</anchor>(ptr : bits(64), modifier1 : bits(64), modifier2 : bits(64),
             K : bits(128), data : boolean) =&gt; bits(64)
begin
    let use_modifier2 : boolean = TRUE;
    return <a link="func_InsertPAC_6" file="shared_pseudocode.xml">InsertPAC</a>(ptr, modifier1, modifier2, use_modifier2, K, data);
end;</pstext></ps>
    <ps name="aarch64/functions/pac/addpac/InsertPAC" mylink="aarch64.functions.pac.addpac.InsertPAC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// InsertPAC()
// ===========
// Calculates the pointer authentication code for a 64-bit quantity and then
// inserts that into pointer authentication code field of that 64-bit quantity.

func <anchor link="func_InsertPAC_6">InsertPAC</anchor>(ptr : bits(64), modifier : bits(64), modifier2 : bits(64), use_modifier2 : boolean,
               K : bits(128), data : boolean) =&gt; bits(64)
begin
    var PAC : bits(64);
    var result : bits(64);
    var ext_ptr : bits(64);
    var extfield : bits(64);
    var selbit : bit;
    let tbi : boolean = <a link="func_EffectiveTBI_3" file="shared_pseudocode.xml">EffectiveTBI</a>(ptr, !data, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) == '1';
    let mtx : boolean = (IsFeatureImplemented(FEAT_MTE_NO_ADDRESS_TAGS) &amp;&amp;
                         <a link="func_EffectiveMTX_3" file="shared_pseudocode.xml">EffectiveMTX</a>(ptr, !data, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) == '1');
    let top_bit : integer{} = if tbi then 55 else 63;
    let EL3_using_lva3 : boolean = (IsFeatureImplemented(FEAT_LVA3) &amp;&amp;
                                    <a link="func_TranslationRegime_1" file="shared_pseudocode.xml">TranslationRegime</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) == <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> &amp;&amp;
                                    <a link="func_AArch64_IASize_1" file="shared_pseudocode.xml">AArch64_IASize</a>(TCR_EL3().T0SZ) &gt; 52);
    let is_VA_56bit : boolean = (<a link="func_TranslationRegime_1" file="shared_pseudocode.xml">TranslationRegime</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) == <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> &amp;&amp;
                                 <a link="func_AArch64_IASize_1" file="shared_pseudocode.xml">AArch64_IASize</a>(TCR_EL3().T0SZ) == 56);

    // If tagged pointers are in use for a regime with two TTBRs, use bit[55] of
    // the pointer to select between upper and lower ranges, and preserve this.
    // This handles the awkward case where there is apparently no correct choice between
    // the upper and lower address range - ie an addr of 1xxxxxxx0... with TBI0=0 and TBI1=1
    // and 0xxxxxxx1 with TBI1=0 and TBI0=1:
    if <a link="func_PtrHasUpperAndLowerAddRanges_0" file="shared_pseudocode.xml">PtrHasUpperAndLowerAddRanges</a>() then
        assert <a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>() IN {<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>};
        if <a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>() == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> then
            // EL1 translation regime registers
            if data then
                if TCR_EL1().TBI1 == '1' || TCR_EL1().TBI0 == '1' then
                    selbit = ptr[55];
                else
                    selbit = ptr[63];
                end;
            else
                if ((TCR_EL1().TBI1 == '1' &amp;&amp; TCR_EL1().TBID1 == '0') ||
                    (TCR_EL1().TBI0 == '1' &amp;&amp; TCR_EL1().TBID0 == '0')) then
                    selbit = ptr[55];
                else
                    selbit = ptr[63];
                end;
            end;
        else
            // EL2 translation regime registers
            if data then
                if TCR_EL2().TBI1 == '1' || TCR_EL2().TBI0 == '1' then
                    selbit = ptr[55];
                else
                    selbit = ptr[63];
                end;
            else
                if ((TCR_EL2().TBI1 == '1' &amp;&amp; TCR_EL2().TBID1 == '0') ||
                    (TCR_EL2().TBI0 == '1' &amp;&amp; TCR_EL2().TBID0 == '0')) then
                    selbit = ptr[55];
                else
                    selbit = ptr[63];
                end;
            end;
        end;
    else
        selbit = if tbi then ptr[55] else ptr[63];
    end;

    if IsFeatureImplemented(FEAT_PAuth2) &amp;&amp; IsFeatureImplemented(FEAT_CONSTPACFIELD) then
        selbit = ptr[55];
    end;
    let bottom_PAC_bit : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_CalculateBottomPACBit_1" file="shared_pseudocode.xml">CalculateBottomPACBit</a>(selbit);

    if EL3_using_lva3 then
        extfield = Replicate{64}('0');
    else
        extfield = Replicate{64}(selbit);
    end;

    // Compute the pointer authentication code for a ptr with good extension bits
    if tbi then
        if bottom_PAC_bit &lt;= 55 then
            ext_ptr = (ptr[63:56] ::
                   extfield[55:bottom_PAC_bit] :: ptr[bottom_PAC_bit-1:0]);
        else
            ext_ptr = ptr[63:56] :: ptr[55:0];
        end;
    elsif mtx then
        if bottom_PAC_bit &lt;= 55 then
            ext_ptr = (extfield[63:60] :: ptr[59:56] ::
                       extfield[55:bottom_PAC_bit] :: ptr[bottom_PAC_bit-1:0]);
        else
            ext_ptr = extfield[63:60] :: ptr[59:56] :: ptr[55:0];
        end;
    else
        ext_ptr =  extfield[63:bottom_PAC_bit] :: ptr[bottom_PAC_bit-1:0];
    end;

    if use_modifier2 then
        assert IsFeatureImplemented(FEAT_PAuth_LR);
        PAC = <a link="func_ComputePAC2_5" file="shared_pseudocode.xml">ComputePAC2</a>(ext_ptr, modifier, modifier2, K[127:64], K[63:0]);
    else
        PAC = <a link="func_ComputePAC_4" file="shared_pseudocode.xml">ComputePAC</a>(ext_ptr, modifier, K[127:64], K[63:0]);
    end;

    if !IsFeatureImplemented(FEAT_PAuth2) then
        // If FEAT_PAuth2 is not implemented, the PAC is corrupted if the pointer does not have
        // a canonical VA.
        assert bottom_PAC_bit &lt;= 52;
        if !IsZero(ptr[top_bit:bottom_PAC_bit]) &amp;&amp; !IsOnes(ptr[top_bit:bottom_PAC_bit]) then
            PAC[top_bit-1] = NOT(PAC[top_bit-1]);
        end;
    end;

    // Preserve the determination between upper and lower address at bit[55] and insert PAC into
    // bits that are not used for the address or the tag(s).
    if !IsFeatureImplemented(FEAT_PAuth2) then
        assert (bottom_PAC_bit &lt;= 52);
        if tbi then
            result = ptr[63:56]::selbit::PAC[54:bottom_PAC_bit]::ptr[bottom_PAC_bit-1:0];
        else
            result = PAC[63:56]::selbit::PAC[54:bottom_PAC_bit]::ptr[bottom_PAC_bit-1:0];
        end;
    else
        var bit55 : bit;
        if EL3_using_lva3 then
            // Bit 55 is an address bit (when VA size is 56-bits) or
            // used to store PAC (when VA size is less than 56-bits)
            if is_VA_56bit then
                bit55 = ptr[55];
            else
                bit55 = ptr[55] XOR PAC[55];
            end;
        else
            bit55 = selbit;
        end;
        if tbi then
            if bottom_PAC_bit &lt; 55 then
                result = (ptr[63:56]                               :: bit55 ::
                          (ptr[54:bottom_PAC_bit] XOR PAC[54:bottom_PAC_bit]) ::
                          ptr[bottom_PAC_bit-1:0]);
            else
                result = (ptr[63:56] :: bit55 :: ptr[54:0]);
            end;
        elsif mtx then
            if bottom_PAC_bit &lt; 55 then
                result = ((ptr[63:60] XOR PAC[63:60]) :: ptr[59:56] :: bit55 ::
                          (ptr[54:bottom_PAC_bit] XOR PAC[54:bottom_PAC_bit]) ::
                          ptr[bottom_PAC_bit-1:0]);
            else
                result = ((ptr[63:60] XOR PAC[63:60]) :: ptr[59:56] :: bit55 ::
                           ptr[54:0]);
            end;
        else
            if bottom_PAC_bit &lt; 55 then
                result = ((ptr[63:56] XOR PAC[63:56])              :: bit55 ::
                          (ptr[54:bottom_PAC_bit] XOR PAC[54:bottom_PAC_bit]) ::
                          ptr[bottom_PAC_bit-1:0]);
            else
                result = ((ptr[63:56] XOR PAC[63:56])              :: bit55 ::
                           ptr[54:0]);
            end;
        end;
    end;
    return result;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/addpacda/AddPACDA" mylink="aarch64.functions.pac.addpacda.AddPACDA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddPACDA()
// ==========
// Returns a 64-bit value containing x, but replacing the pointer authentication code
// field bits with a pointer authentication code, where the pointer authentication
// code is derived using a cryptographic algorithm as a combination of x, y and the
// APDAKey_EL1.

func <anchor link="func_AddPACDA_2">AddPACDA</anchor>(x : bits(64), y : bits(64)) =&gt; bits(64)
begin
    let APDAKey_EL1 : bits(128) = APDAKeyHi_EL1()[63:0] :: APDAKeyLo_EL1()[63:0];
    if !<a link="func_IsAPDAKeyEnabled_0" file="shared_pseudocode.xml">IsAPDAKeyEnabled</a>() then
        return x;
    else
        return <a link="func_AddPAC_4" file="shared_pseudocode.xml">AddPAC</a>(x, y, APDAKey_EL1, TRUE);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/addpacdb/AddPACDB" mylink="aarch64.functions.pac.addpacdb.AddPACDB" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddPACDB()
// ==========
// Returns a 64-bit value containing x, but replacing the pointer authentication code
// field bits with a pointer authentication code, where the pointer authentication
// code is derived using a cryptographic algorithm as a combination of x, y and the
// APDBKey_EL1.

func <anchor link="func_AddPACDB_2">AddPACDB</anchor>(x : bits(64), y : bits(64)) =&gt; bits(64)
begin
    let APDBKey_EL1 : bits(128) = APDBKeyHi_EL1()[63:0] :: APDBKeyLo_EL1()[63:0];
    if !<a link="func_IsAPDBKeyEnabled_0" file="shared_pseudocode.xml">IsAPDBKeyEnabled</a>() then
        return x;
    else
        return <a link="func_AddPAC_4" file="shared_pseudocode.xml">AddPAC</a>(x, y, APDBKey_EL1, TRUE);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/addpacga/AddPACGA" mylink="aarch64.functions.pac.addpacga.AddPACGA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddPACGA()
// ==========
// Returns a 64-bit value where the lower 32 bits are 0, and the upper 32 bits contain
// a 32-bit pointer authentication code which is derived using a cryptographic
// algorithm as a combination of x, y and the APGAKey_EL1.

func <anchor link="func_AddPACGA_2">AddPACGA</anchor>(x : bits(64), y : bits(64)) =&gt; bits(64)
begin
    var TrapEL2 : boolean;
    let APGAKey_EL1 : bits(128) = APGAKeyHi_EL1()[63:0] :: APGAKeyLo_EL1()[63:0];

    var TrapEL3 : boolean;
    case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL of
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            TrapEL2 = <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().API == '0' &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>();
            TrapEL3 = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().API == '0';
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            TrapEL2 = <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().API == '0';
            TrapEL3 = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().API == '0';
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            TrapEL2 = FALSE;
            TrapEL3 = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().API == '0';
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            TrapEL2 = FALSE;
            TrapEL3 = FALSE;
    end;

    if TrapEL3 &amp;&amp; <a link="func_EL3SDDUndefPriority_0" file="shared_pseudocode.xml">EL3SDDUndefPriority</a>() then
        Undefined();
    elsif TrapEL2 then
        TrapPACUse(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
    elsif TrapEL3 then
        if <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then
            Undefined();
        else
            TrapPACUse(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
        end;
    else
        return <a link="func_ComputePAC_4" file="shared_pseudocode.xml">ComputePAC</a>(x, y, APGAKey_EL1[127:64], APGAKey_EL1[63:0])[63:32]::Zeros{32};
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/addpacia/AddPACIA" mylink="aarch64.functions.pac.addpacia.AddPACIA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddPACIA()
// ==========
// Returns a 64-bit value containing x, but replacing the pointer authentication code
// field bits with a pointer authentication code, where the pointer authentication
// code is derived using a cryptographic algorithm as a combination of x, y, and the
// APIAKey_EL1.

func <anchor link="func_AddPACIA_2">AddPACIA</anchor>(x : bits(64), y : bits(64)) =&gt; bits(64)
begin
    let APIAKey_EL1 : bits(128) = APIAKeyHi_EL1()[63:0]::APIAKeyLo_EL1()[63:0];
    if !<a link="func_IsAPIAKeyEnabled_0" file="shared_pseudocode.xml">IsAPIAKeyEnabled</a>() then
        return x;
    else
        return <a link="func_AddPAC_4" file="shared_pseudocode.xml">AddPAC</a>(x, y, APIAKey_EL1, FALSE);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/addpacia/AddPACIA2" mylink="aarch64.functions.pac.addpacia.AddPACIA2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddPACIA2()
// ===========
// Returns a 64-bit value containing x, but replacing the pointer authentication code
// field bits with a pointer authentication code, where the pointer authentication
// code is derived using a cryptographic algorithm as a combination of x, y, z, and
// the APIAKey_EL1.

func <anchor link="func_AddPACIA2_3">AddPACIA2</anchor>(x : bits(64), y : bits(64), z : bits(64)) =&gt; bits(64)
begin
    let APIAKey_EL1 : bits(128) = APIAKeyHi_EL1()[63:0]::APIAKeyLo_EL1()[63:0];
    if !<a link="func_IsAPIAKeyEnabled_0" file="shared_pseudocode.xml">IsAPIAKeyEnabled</a>() then
        return x;
    else
        return <a link="func_AddPAC2_5" file="shared_pseudocode.xml">AddPAC2</a>(x, y, z, APIAKey_EL1, FALSE);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/addpacib/AddPACIB" mylink="aarch64.functions.pac.addpacib.AddPACIB" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddPACIB()
// ==========
// Returns a 64-bit value containing x, but replacing the pointer authentication code
// field bits with a pointer authentication code, where the pointer authentication
// code is derived using a cryptographic algorithm as a combination of x, y and the
// APIBKey_EL1.

func <anchor link="func_AddPACIB_2">AddPACIB</anchor>(x : bits(64), y : bits(64)) =&gt; bits(64)
begin
    let APIBKey_EL1 : bits(128) = APIBKeyHi_EL1()[63:0] :: APIBKeyLo_EL1()[63:0];
    if !<a link="func_IsAPIBKeyEnabled_0" file="shared_pseudocode.xml">IsAPIBKeyEnabled</a>() then
        return x;
    else
        return <a link="func_AddPAC_4" file="shared_pseudocode.xml">AddPAC</a>(x, y, APIBKey_EL1, FALSE);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/addpacib/AddPACIB2" mylink="aarch64.functions.pac.addpacib.AddPACIB2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddPACIB2()
// ===========
// Returns a 64-bit value containing x, but replacing the pointer authentication code
// field bits with a pointer authentication code, where the pointer authentication
// code is derived using a cryptographic algorithm as a combination of x, y, z, and
// the APIBKey_EL1.

func <anchor link="func_AddPACIB2_3">AddPACIB2</anchor>(x : bits(64), y : bits(64), z : bits(64)) =&gt; bits(64)
begin
    let APIBKey_EL1 : bits(128) = APIBKeyHi_EL1()[63:0] :: APIBKeyLo_EL1()[63:0];
    if !<a link="func_IsAPIBKeyEnabled_0" file="shared_pseudocode.xml">IsAPIBKeyEnabled</a>() then
        return x;
    else
        return <a link="func_AddPAC2_5" file="shared_pseudocode.xml">AddPAC2</a>(x, y, z, APIBKey_EL1, FALSE);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/auth/AArch64_PACFailException" mylink="aarch64.functions.pac.auth.AArch64_PACFailException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_PACFailException()
// ==========================
// Generates a PAC Fail Exception

func <anchor link="func_AArch64_PACFailException_1">AArch64_PACFailException</anchor>(syndrome : bits(2))
begin
    let route_to_el2 : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1';
    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer = 0x0;

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a> = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_PACFail" file="shared_pseudocode.xml">Exception_PACFail</a>);
    except.syndrome.iss[1:0]     = syndrome;
    except.syndrome.iss[24:2]    = Zeros{23};                // RES0

    if UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) &gt; UInt(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
        AArch64_TakeException(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL, except, preferred_exception_return, vect_offset);
    elsif route_to_el2 then
        AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
    else
        AArch64_TakeException(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, except, preferred_exception_return, vect_offset);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/auth/Auth" mylink="aarch64.functions.pac.auth.Auth" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Auth()
// ======
// Restores the upper bits of the address to be all zeros or all ones (based on the
// value of bit[55]) and computes and checks the pointer authentication code. If the
// check passes, then the restored address is returned. If the check fails, the
// second-top and third-top bits of the extension bits in the pointer authentication code
// field are corrupted to ensure that accessing the address will give a translation fault.

func <anchor link="func_Auth_6">Auth</anchor>(ptr : bits(64), modifier : bits(64), K : bits(128), data : boolean, key_number : bit,
          is_combined : boolean) =&gt; bits(64)
begin
    let use_modifier2 : boolean = FALSE;
    return <a link="func_Authenticate_8" file="shared_pseudocode.xml">Authenticate</a>(ptr, modifier, Zeros{64}, use_modifier2,
                        K, data, key_number, is_combined);
end;</pstext></ps>
    <ps name="aarch64/functions/pac/auth/Auth2" mylink="aarch64.functions.pac.auth.Auth2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Auth2()
// =======
// Restores the upper bits of the address to be all zeros or all ones (based on the
// value of bit[55]) and computes and checks the pointer authentication code. If the
// check passes, then the restored address is returned. If the check fails, the
// second-top and third-top bits of the extension bits in the pointer authentication code
// field are corrupted to ensure that accessing the address will give a translation fault.

func <anchor link="func_Auth2_7">Auth2</anchor>(ptr : bits(64), modifier1 : bits(64), modifier2 : bits(64), K : bits(128),
           data : boolean, key_number : bit, is_combined : boolean) =&gt; bits(64)
begin
    let use_modifier2 : boolean = TRUE;
    return <a link="func_Authenticate_8" file="shared_pseudocode.xml">Authenticate</a>(ptr, modifier1, modifier2, use_modifier2, K, data, key_number, is_combined);
end;</pstext></ps>
    <ps name="aarch64/functions/pac/auth/Authenticate" mylink="aarch64.functions.pac.auth.Authenticate" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Authenticate()
// ==============
// Restores the upper bits of the address to be all zeros or all ones (based on the
// value of bit[55]) and computes and checks the pointer authentication code. If the
// check passes, then the restored address is returned. If the check fails, the
// second-top and third-top bits of the extension bits in the pointer authentication code
// field are corrupted to ensure that accessing the address will give a translation fault.

func <anchor link="func_Authenticate_8">Authenticate</anchor>(ptr : bits(64), modifier : bits(64), modifier2 : bits(64),
                  use_modifier2 : boolean, K : bits(128), data : boolean, key_number : bit,
                  is_combined : boolean) =&gt; bits(64)
begin
    var PAC : bits(64);
    var result : bits(64);
    var original_ptr : bits(64);
    var error_code : bits(2);
    var extfield : bits(64);

    // Reconstruct the extension field used of adding the PAC to the pointer
    let tbi : boolean = <a link="func_EffectiveTBI_3" file="shared_pseudocode.xml">EffectiveTBI</a>(ptr, !data, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) == '1';
    let mtx : boolean = (IsFeatureImplemented(FEAT_MTE_NO_ADDRESS_TAGS) &amp;&amp;
                         <a link="func_EffectiveMTX_3" file="shared_pseudocode.xml">EffectiveMTX</a>(ptr, !data, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) == '1');
    let bottom_PAC_bit : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_CalculateBottomPACBit_1" file="shared_pseudocode.xml">CalculateBottomPACBit</a>(ptr[55]);
    let EL3_using_lva3 : boolean = (IsFeatureImplemented(FEAT_LVA3) &amp;&amp;
                                    <a link="func_TranslationRegime_1" file="shared_pseudocode.xml">TranslationRegime</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) == <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> &amp;&amp;
                                    <a link="func_AArch64_IASize_1" file="shared_pseudocode.xml">AArch64_IASize</a>(TCR_EL3().T0SZ) &gt; 52);
    let is_VA_56bit : boolean = (<a link="func_TranslationRegime_1" file="shared_pseudocode.xml">TranslationRegime</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) == <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> &amp;&amp;
                                 <a link="func_AArch64_IASize_1" file="shared_pseudocode.xml">AArch64_IASize</a>(TCR_EL3().T0SZ) == 56);
    if EL3_using_lva3 then
        extfield = Replicate{64}('0');
    else
        extfield = Replicate{64}(ptr[55]);
    end;

    if tbi then
        if bottom_PAC_bit &lt;= 55 then
            original_ptr = (ptr[63:56] ::
                            extfield[55:bottom_PAC_bit] :: ptr[bottom_PAC_bit-1:0]);
        else
            original_ptr = ptr[63:56] :: ptr[55:0];
        end;
    elsif mtx then
        if bottom_PAC_bit &lt;= 55 then
            original_ptr = (extfield[63:60] :: ptr[59:56] ::
                            extfield[55:bottom_PAC_bit] :: ptr[bottom_PAC_bit-1:0]);
        else
            original_ptr = extfield[63:60] :: ptr[59:56] :: ptr[55:0];
        end;
    else
        original_ptr =  extfield[63:bottom_PAC_bit] :: ptr[bottom_PAC_bit-1:0];
    end;

    if use_modifier2 then
        assert IsFeatureImplemented(FEAT_PAuth_LR);
        PAC = <a link="func_ComputePAC2_5" file="shared_pseudocode.xml">ComputePAC2</a>(original_ptr, modifier, modifier2, K[127:64], K[63:0]);
    else
        PAC = <a link="func_ComputePAC_4" file="shared_pseudocode.xml">ComputePAC</a>(original_ptr, modifier, K[127:64], K[63:0]);
    end;
    // Check pointer authentication code
    if tbi then
        if !IsFeatureImplemented(FEAT_PAuth2) then
            assert (bottom_PAC_bit &lt;= 52);
            if PAC[54:bottom_PAC_bit] == ptr[54:bottom_PAC_bit] then
                result = original_ptr;
            else
                error_code = key_number::NOT(key_number);
                result = original_ptr[63:55]::error_code::original_ptr[52:0];
            end;
        else
            result = ptr;
            if EL3_using_lva3 &amp;&amp; !is_VA_56bit then
                result[55] = result[55] XOR PAC[55];
            end;
            if (bottom_PAC_bit &lt; 55) then
                result[54:bottom_PAC_bit] = result[54:bottom_PAC_bit] XOR PAC[54:bottom_PAC_bit];
            end;
            if (IsFeatureImplemented(FEAT_FPACCOMBINE) ||
                  (IsFeatureImplemented(FEAT_FPAC) &amp;&amp; !is_combined)) then
                if (EL3_using_lva3 &amp;&amp; !is_VA_56bit &amp;&amp; !IsZero(result[55:bottom_PAC_bit])) then
                    error_code = (if data then '1' else '0')::key_number;
                    <a link="func_AArch64_PACFailException_1" file="shared_pseudocode.xml">AArch64_PACFailException</a>(error_code);
                elsif (!EL3_using_lva3 &amp;&amp; (bottom_PAC_bit &lt; 55) &amp;&amp;
                         result[54:bottom_PAC_bit] !=
                         Replicate{55-bottom_PAC_bit}(result[55])) then
                    error_code = (if data then '1' else '0')::key_number;
                    <a link="func_AArch64_PACFailException_1" file="shared_pseudocode.xml">AArch64_PACFailException</a>(error_code);
                end;
            end;
        end;
    elsif mtx then
        assert IsFeatureImplemented(FEAT_PAuth2);
        result = ptr;
        if EL3_using_lva3 &amp;&amp; !is_VA_56bit then
            result[55] = result[55] XOR PAC[55];
        end;
        if (bottom_PAC_bit &lt; 55) then
            result[54:bottom_PAC_bit] = result[54:bottom_PAC_bit] XOR PAC[54:bottom_PAC_bit];
        end;
        result[63:60] = result[63:60] XOR PAC[63:60];
        if (IsFeatureImplemented(FEAT_FPACCOMBINE) ||
              (IsFeatureImplemented(FEAT_FPAC) &amp;&amp; !is_combined)) then
            if (EL3_using_lva3 &amp;&amp; !is_VA_56bit &amp;&amp;
                  (!IsZero(result[55:bottom_PAC_bit]) || !IsZero(result[63:60]))) then
                error_code = (if data then '1' else '0')::key_number;
                <a link="func_AArch64_PACFailException_1" file="shared_pseudocode.xml">AArch64_PACFailException</a>(error_code);
            elsif (!EL3_using_lva3 &amp;&amp; (bottom_PAC_bit &lt; 55) &amp;&amp;
                     (((result[54:bottom_PAC_bit] !=
                        Replicate{55-bottom_PAC_bit}(result[55]))) ||
                      (result[63:60] != Replicate{4}(result[55])))) then
                error_code = (if data then '1' else '0')::key_number;
                <a link="func_AArch64_PACFailException_1" file="shared_pseudocode.xml">AArch64_PACFailException</a>(error_code);
            end;
        end;
    else
        if !IsFeatureImplemented(FEAT_PAuth2) then
            assert (bottom_PAC_bit &lt;= 52);
            if PAC[54:bottom_PAC_bit] == ptr[54:bottom_PAC_bit] &amp;&amp; PAC[63:56] == ptr[63:56] then
                result = original_ptr;
            else
                error_code = key_number::NOT(key_number);
                result     = original_ptr[63]::error_code::original_ptr[60:0];
            end;
        else
            result = ptr;
            if EL3_using_lva3 &amp;&amp; !is_VA_56bit then
                result[55] = result[55] XOR PAC[55];
            end;
            if bottom_PAC_bit &lt; 55 then
                result[54:bottom_PAC_bit] = result[54:bottom_PAC_bit] XOR PAC[54:bottom_PAC_bit];
            end;
            result[63:56] = result[63:56] XOR PAC[63:56];
            if (IsFeatureImplemented(FEAT_FPACCOMBINE) ||
                  (IsFeatureImplemented(FEAT_FPAC) &amp;&amp; !is_combined)) then
                if (EL3_using_lva3 &amp;&amp; !IsZero(result[63:bottom_PAC_bit])) then
                    error_code = (if data then '1' else '0')::key_number;
                    <a link="func_AArch64_PACFailException_1" file="shared_pseudocode.xml">AArch64_PACFailException</a>(error_code);
                elsif (!EL3_using_lva3 &amp;&amp;
                         result[63:bottom_PAC_bit] !=
                         Replicate{64-bottom_PAC_bit}(result[55])) then
                    error_code = (if data then '1' else '0')::key_number;
                    <a link="func_AArch64_PACFailException_1" file="shared_pseudocode.xml">AArch64_PACFailException</a>(error_code);
                end;
            end;
        end;
    end;
    return result;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/authda/AuthDA" mylink="aarch64.functions.pac.authda.AuthDA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AuthDA()
// ========
// Returns a 64-bit value containing x, but replacing the pointer authentication code
// field bits with the extension of the address bits. The instruction checks a pointer
// authentication code in the pointer authentication code field bits of x, using the same
// algorithm and key as AddPACDA().

func <anchor link="func_AuthDA_3">AuthDA</anchor>(x : bits(64), y : bits(64), is_combined : boolean) =&gt; bits(64)
begin
    let APDAKey_EL1 : bits(128) = APDAKeyHi_EL1()[63:0] :: APDAKeyLo_EL1()[63:0];
    if !<a link="func_IsAPDAKeyEnabled_0" file="shared_pseudocode.xml">IsAPDAKeyEnabled</a>() then
        return x;
    else
        return <a link="func_Auth_6" file="shared_pseudocode.xml">Auth</a>(x, y, APDAKey_EL1, TRUE, '0', is_combined);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/authdb/AuthDB" mylink="aarch64.functions.pac.authdb.AuthDB" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AuthDB()
// ========
// Returns a 64-bit value containing x, but replacing the pointer authentication code
// field bits with the extension of the address bits. The instruction checks a
// pointer authentication code in the pointer authentication code field bits of x, using
// the same algorithm and key as AddPACDB().

func <anchor link="func_AuthDB_3">AuthDB</anchor>(x : bits(64), y : bits(64), is_combined : boolean) =&gt; bits(64)
begin
    let APDBKey_EL1 : bits(128) = APDBKeyHi_EL1()[63:0] :: APDBKeyLo_EL1()[63:0];
    if !<a link="func_IsAPDBKeyEnabled_0" file="shared_pseudocode.xml">IsAPDBKeyEnabled</a>() then
        return x;
    else
        return <a link="func_Auth_6" file="shared_pseudocode.xml">Auth</a>(x, y, APDBKey_EL1, TRUE, '1', is_combined);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/authia/AuthIA" mylink="aarch64.functions.pac.authia.AuthIA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AuthIA()
// ========
// Returns a 64-bit value containing x, but replacing the pointer authentication code
// field bits with the extension of the address bits. The instruction checks a pointer
// authentication code in the pointer authentication code field bits of x, using the same
// algorithm and key as AddPACIA().

func <anchor link="func_AuthIA_3">AuthIA</anchor>(x : bits(64), y : bits(64), is_combined : boolean) =&gt; bits(64)
begin
    let APIAKey_EL1 : bits(128) = APIAKeyHi_EL1()[63:0] :: APIAKeyLo_EL1()[63:0];
    if !<a link="func_IsAPIAKeyEnabled_0" file="shared_pseudocode.xml">IsAPIAKeyEnabled</a>() then
        return x;
    else
        return <a link="func_Auth_6" file="shared_pseudocode.xml">Auth</a>(x, y, APIAKey_EL1, FALSE, '0', is_combined);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/authia/AuthIA2" mylink="aarch64.functions.pac.authia.AuthIA2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AuthIA2()
// =========
// Returns a 64-bit value containing x, but replacing the pointer authentication code
// field bits with the extension of the address bits. The instruction checks a pointer
// authentication code in the pointer authentication code field bits of x, using the same
// algorithm and key as AddPACIA2().

func <anchor link="func_AuthIA2_4">AuthIA2</anchor>(x : bits(64), y : bits(64), z : bits(64), is_combined : boolean) =&gt; bits(64)
begin
    let APIAKey_EL1 : bits(128) = APIAKeyHi_EL1()[63:0] :: APIAKeyLo_EL1()[63:0];
    if !<a link="func_IsAPIAKeyEnabled_0" file="shared_pseudocode.xml">IsAPIAKeyEnabled</a>() then
        return x;
    else
        return <a link="func_Auth2_7" file="shared_pseudocode.xml">Auth2</a>(x, y, z, APIAKey_EL1, FALSE, '0', is_combined);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/authib/AuthIB" mylink="aarch64.functions.pac.authib.AuthIB" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AuthIB()
// ========
// Returns a 64-bit value containing x, but replacing the pointer authentication code
// field bits with the extension of the address bits. The instruction checks a pointer
// authentication code in the pointer authentication code field bits of x, using the same
// algorithm and key as AddPACIB().

func <anchor link="func_AuthIB_3">AuthIB</anchor>(x : bits(64), y : bits(64), is_combined : boolean) =&gt; bits(64)
begin
    let APIBKey_EL1 : bits(128) = APIBKeyHi_EL1()[63:0] :: APIBKeyLo_EL1()[63:0];
    if !<a link="func_IsAPIBKeyEnabled_0" file="shared_pseudocode.xml">IsAPIBKeyEnabled</a>() then
        return x;
    else
        return <a link="func_Auth_6" file="shared_pseudocode.xml">Auth</a>(x, y, APIBKey_EL1, FALSE, '1', is_combined);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/authib/AuthIB2" mylink="aarch64.functions.pac.authib.AuthIB2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AuthIB2()
// =========
// Returns a 64-bit value containing x, but replacing the pointer authentication code
// field bits with the extension of the address bits. The instruction checks a pointer
// authentication code in the pointer authentication code field bits of x, using the same
// algorithm and key as AddPACIB2().

func <anchor link="func_AuthIB2_4">AuthIB2</anchor>(x : bits(64), y : bits(64), z : bits(64), is_combined : boolean) =&gt; bits(64)
begin
    let APIBKey_EL1 : bits(128) = APIBKeyHi_EL1()[63:0] :: APIBKeyLo_EL1()[63:0];
    if !<a link="func_IsAPIBKeyEnabled_0" file="shared_pseudocode.xml">IsAPIBKeyEnabled</a>() then
        return x;
    else
        return <a link="func_Auth2_7" file="shared_pseudocode.xml">Auth2</a>(x, y, z, APIBKey_EL1, FALSE, '1', is_combined);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/calcbottompacbit/AArch64_PACEffectiveTxSZ" mylink="aarch64.functions.pac.calcbottompacbit.AArch64_PACEffectiveTxSZ" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_PACEffectiveTxSZ()
// ==========================
// Compute the effective value for TxSZ used to determine the placement of the PAC field

func <anchor link="func_AArch64_PACEffectiveTxSZ_2">AArch64_PACEffectiveTxSZ</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>) =&gt; bits(6)
begin
    let s1maxtxsz : integer = <a link="func_AArch64_MaxTxSZ_1" file="shared_pseudocode.xml">AArch64_MaxTxSZ</a>(walkparams.tgx);
    let s1mintxsz : integer = <a link="func_AArch64_S1MinTxSZ_2" file="shared_pseudocode.xml">AArch64_S1MinTxSZ</a>(regime, walkparams);

    if <a link="func_AArch64_S1TxSZFaults_2" file="shared_pseudocode.xml">AArch64_S1TxSZFaults</a>(regime, walkparams) then
        if ConstrainUnpredictable(<a link="enum_Unpredictable_RESTnSZ" file="shared_pseudocode.xml">Unpredictable_RESTnSZ</a>) == <a link="enum_Constraint_FORCE" file="shared_pseudocode.xml">Constraint_FORCE</a> then
            if UInt(walkparams.txsz) &lt; s1mintxsz then
                return s1mintxsz[5:0];
            end;
            if UInt(walkparams.txsz) &gt; s1maxtxsz then
                return s1maxtxsz[5:0];
            end;
        end;
    elsif UInt(walkparams.txsz) &lt; s1mintxsz then
        return s1mintxsz[5:0];
    elsif UInt(walkparams.txsz) &gt; s1maxtxsz then
        return s1maxtxsz[5:0];
    end;

    return walkparams.txsz;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/calcbottompacbit/CalculateBottomPACBit" mylink="aarch64.functions.pac.calcbottompacbit.CalculateBottomPACBit" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CalculateBottomPACBit()
// =======================

func <anchor link="func_CalculateBottomPACBit_1">CalculateBottomPACBit</anchor>(top_bit : bit) =&gt; <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>
begin
    var regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>;
    var walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>;
    var bottom_PAC_bit : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;

    regime = <a link="func_TranslationRegime_1" file="shared_pseudocode.xml">TranslationRegime</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>();
    walkparams             = <a link="func_AArch64_GetS1TTWParams_4" file="shared_pseudocode.xml">AArch64_GetS1TTWParams</a>(regime, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL, ss, Replicate{64}(top_bit));
    bottom_PAC_bit         = ((64 - UInt(<a link="func_AArch64_PACEffectiveTxSZ_2" file="shared_pseudocode.xml">AArch64_PACEffectiveTxSZ</a>(regime, walkparams)))
                               as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>);

    return bottom_PAC_bit;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/computepac/ComputePAC" mylink="aarch64.functions.pac.computepac.ComputePAC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ComputePAC()
// ============

func <anchor link="func_ComputePAC_4">ComputePAC</anchor>(data : bits(64), modifier : bits(64), key0 : bits(64), key1 : bits(64)) =&gt; bits(64)
begin
    if IsFeatureImplemented(FEAT_PACIMP) then
        return <a link="func_ComputePACIMPDEF_4" file="shared_pseudocode.xml">ComputePACIMPDEF</a>(data, modifier, key0, key1);
    end;
    if IsFeatureImplemented(FEAT_PACQARMA3) then
        let isqarma3 : boolean = TRUE;
        return <a link="func_ComputePACQARMA_5" file="shared_pseudocode.xml">ComputePACQARMA</a>(data, modifier, key0, key1, isqarma3);
    end;
    if IsFeatureImplemented(FEAT_PACQARMA5) then
        let isqarma3 : boolean = FALSE;
        return <a link="func_ComputePACQARMA_5" file="shared_pseudocode.xml">ComputePACQARMA</a>(data, modifier, key0, key1, isqarma3);
    end;
    unreachable;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/computepac/ComputePAC2" mylink="aarch64.functions.pac.computepac.ComputePAC2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ComputePAC2()
// =============

func <anchor link="func_ComputePAC2_5">ComputePAC2</anchor>(data : bits(64), modifier1 : bits(64), modifier2 : bits(64),
                 key0 : bits(64), key1 : bits(64)) =&gt; bits(64)
begin
    if IsFeatureImplemented(FEAT_PACIMP) then
        return <a link="func_ComputePAC2IMPDEF_5" file="shared_pseudocode.xml">ComputePAC2IMPDEF</a>(data, modifier1, modifier2, key0, key1);
    end;
    if IsFeatureImplemented(FEAT_PACQARMA3) then
        let isqarma3 : boolean = TRUE;
        return <a link="func_ComputePAC2QARMA_6" file="shared_pseudocode.xml">ComputePAC2QARMA</a>(data, modifier1, modifier2, key0, key1, isqarma3);
    end;
    if IsFeatureImplemented(FEAT_PACQARMA5) then
        let isqarma3 : boolean = FALSE;
        return <a link="func_ComputePAC2QARMA_6" file="shared_pseudocode.xml">ComputePAC2QARMA</a>(data, modifier1, modifier2, key0, key1, isqarma3);
    end;
    unreachable;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/computepac/ComputePAC2IMPDEF" mylink="aarch64.functions.pac.computepac.ComputePAC2IMPDEF" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ComputePAC2IMPDEF()
// ===================
// Compute IMPLEMENTATION DEFINED cryptographic algorithm to be used for PAC calculation.

impdef func <anchor link="func_ComputePAC2IMPDEF_5">ComputePAC2IMPDEF</anchor>(data : bits(64),
                              modifier1 : bits(64),
                              modifier2 : bits(64),
                              key0 : bits(64),
                              key1 : bits(64)) =&gt; bits(64)
begin
    Unimplemented();
end;</pstext></ps>
    <ps name="aarch64/functions/pac/computepac/ComputePAC2QARMA" mylink="aarch64.functions.pac.computepac.ComputePAC2QARMA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ComputePAC2QARMA()
// ==================

func <anchor link="func_ComputePAC2QARMA_6">ComputePAC2QARMA</anchor>(data : bits(64),
                      modifier1 : bits(64),
                      modifier2 : bits(64),
                      key0 : bits(64),
                      key1 : bits(64),
                      isqarma3 : boolean) =&gt; bits(64)
begin
    let concat_modifiers : bits(64) = modifier2[36:5]::modifier1[35:4];
    return <a link="func_ComputePACQARMA_5" file="shared_pseudocode.xml">ComputePACQARMA</a>(data, concat_modifiers, key0, key1, isqarma3);
end;</pstext></ps>
    <ps name="aarch64/functions/pac/computepac/ComputePACIMPDEF" mylink="aarch64.functions.pac.computepac.ComputePACIMPDEF" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ComputePACIMPDEF()
// ==================
// Compute IMPLEMENTATION DEFINED cryptographic algorithm to be used for PAC calculation.

impdef func <anchor link="func_ComputePACIMPDEF_4">ComputePACIMPDEF</anchor>(data : bits(64), modifier : bits(64),
                             key0 : bits(64), key1 : bits(64)) =&gt; bits(64)
begin
    Unimplemented();
end;</pstext></ps>
    <ps name="aarch64/functions/pac/computepac/ComputePACQARMA" mylink="aarch64.functions.pac.computepac.ComputePACQARMA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ComputePACQARMA()
// =================
// Compute QARMA3 or QARMA5 cryptographic algorithm for PAC calculation

func <anchor link="func_ComputePACQARMA_5">ComputePACQARMA</anchor>(data : bits(64),
                     modifier : bits(64),
                     key0 : bits(64),
                     key1 : bits(64),
                     isqarma3 : boolean) =&gt; bits(64)
begin
    var workingval : bits(64);
    var runningmod : bits(64);
    var roundkey : bits(64);
    var modk0 : bits(64);
    let Alpha : bits(64) = 0xC0AC29B7C97C50DD[63:0];

    var iterations : integer;
    <a link="global_RC" file="shared_pseudocode.xml">RC</a>[[0]] = 0x0000000000000000[63:0];
    <a link="global_RC" file="shared_pseudocode.xml">RC</a>[[1]] = 0x13198A2E03707344[63:0];
    <a link="global_RC" file="shared_pseudocode.xml">RC</a>[[2]] = 0xA4093822299F31D0[63:0];

    if isqarma3 then
        iterations = 2;
    else // QARMA5
        iterations = 4;
        <a link="global_RC" file="shared_pseudocode.xml">RC</a>[[3]] = 0x082EFA98EC4E6C89[63:0];
        <a link="global_RC" file="shared_pseudocode.xml">RC</a>[[4]] = 0x452821E638D01377[63:0];
    end;

    modk0 = key0[0]::key0[63:2]::(key0[63] XOR key0[1]);
    runningmod = modifier;
    workingval = data XOR key0;

    for i = 0 to iterations do
        roundkey   = key1 XOR runningmod;
        workingval = workingval XOR roundkey;
        workingval = workingval XOR <a link="global_RC" file="shared_pseudocode.xml">RC</a>[[i]];
        if i &gt; 0 then
            workingval = <a link="func_PACCellShuffle_1" file="shared_pseudocode.xml">PACCellShuffle</a>(workingval);
            workingval = <a link="func_PACMult_1" file="shared_pseudocode.xml">PACMult</a>(workingval);
        end;
        if isqarma3 then
            workingval = <a link="func_PACSub1_1" file="shared_pseudocode.xml">PACSub1</a>(workingval);
        else
            workingval = <a link="func_PACSub_1" file="shared_pseudocode.xml">PACSub</a>(workingval);
        end;
        runningmod = <a link="func_TweakShuffle_1" file="shared_pseudocode.xml">TweakShuffle</a>(runningmod[63:0]);
    end;
    roundkey   = modk0 XOR runningmod;
    workingval = workingval XOR roundkey;
    workingval = <a link="func_PACCellShuffle_1" file="shared_pseudocode.xml">PACCellShuffle</a>(workingval);
    workingval = <a link="func_PACMult_1" file="shared_pseudocode.xml">PACMult</a>(workingval);
    if isqarma3 then
        workingval = <a link="func_PACSub1_1" file="shared_pseudocode.xml">PACSub1</a>(workingval);
    else
        workingval = <a link="func_PACSub_1" file="shared_pseudocode.xml">PACSub</a>(workingval);
    end;
    workingval = <a link="func_PACCellShuffle_1" file="shared_pseudocode.xml">PACCellShuffle</a>(workingval);
    workingval = <a link="func_PACMult_1" file="shared_pseudocode.xml">PACMult</a>(workingval);
    workingval = key1 XOR workingval;
    workingval = <a link="func_PACCellInvShuffle_1" file="shared_pseudocode.xml">PACCellInvShuffle</a>(workingval);
    if isqarma3 then
        workingval = <a link="func_PACSub1_1" file="shared_pseudocode.xml">PACSub1</a>(workingval);
    else
        workingval = <a link="func_PACInvSub_1" file="shared_pseudocode.xml">PACInvSub</a>(workingval);
    end;
    workingval = <a link="func_PACMult_1" file="shared_pseudocode.xml">PACMult</a>(workingval);
    workingval = <a link="func_PACCellInvShuffle_1" file="shared_pseudocode.xml">PACCellInvShuffle</a>(workingval);
    workingval = workingval XOR key0;
    workingval = workingval XOR runningmod;
    for i = 0 to iterations do
        if isqarma3 then
            workingval = <a link="func_PACSub1_1" file="shared_pseudocode.xml">PACSub1</a>(workingval);
        else
            workingval = <a link="func_PACInvSub_1" file="shared_pseudocode.xml">PACInvSub</a>(workingval);
        end;
        if i &lt; iterations then
            workingval = <a link="func_PACMult_1" file="shared_pseudocode.xml">PACMult</a>(workingval);
            workingval = <a link="func_PACCellInvShuffle_1" file="shared_pseudocode.xml">PACCellInvShuffle</a>(workingval);
        end;
        runningmod = <a link="func_TweakInvShuffle_1" file="shared_pseudocode.xml">TweakInvShuffle</a>(runningmod[63:0]);
        roundkey = key1 XOR runningmod;
        workingval = workingval XOR <a link="global_RC" file="shared_pseudocode.xml">RC</a>[[iterations-i]];
        workingval = workingval XOR roundkey;
        workingval = workingval XOR Alpha;
    end;
    workingval = workingval XOR modk0;

    return workingval;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/computepac/PACCellInvShuffle" mylink="aarch64.functions.pac.computepac.PACCellInvShuffle" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PACCellInvShuffle()
// ===================

func <anchor link="func_PACCellInvShuffle_1">PACCellInvShuffle</anchor>(indata : bits(64)) =&gt; bits(64)
begin
    var outdata : bits(64);
    outdata[3:0]   = indata[15:12];
    outdata[7:4]   = indata[27:24];
    outdata[11:8]  = indata[51:48];
    outdata[15:12] = indata[39:36];
    outdata[19:16] = indata[59:56];
    outdata[23:20] = indata[47:44];
    outdata[27:24] = indata[7:4];
    outdata[31:28] = indata[19:16];
    outdata[35:32] = indata[35:32];
    outdata[39:36] = indata[55:52];
    outdata[43:40] = indata[31:28];
    outdata[47:44] = indata[11:8];
    outdata[51:48] = indata[23:20];
    outdata[55:52] = indata[3:0];
    outdata[59:56] = indata[43:40];
    outdata[63:60] = indata[63:60];
    return outdata;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/computepac/PACCellShuffle" mylink="aarch64.functions.pac.computepac.PACCellShuffle" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PACCellShuffle()
// ================

func <anchor link="func_PACCellShuffle_1">PACCellShuffle</anchor>(indata : bits(64)) =&gt; bits(64)
begin
    var outdata : bits(64);
    outdata[3:0]   = indata[55:52];
    outdata[7:4]   = indata[27:24];
    outdata[11:8]  = indata[47:44];
    outdata[15:12] = indata[3:0];
    outdata[19:16] = indata[31:28];
    outdata[23:20] = indata[51:48];
    outdata[27:24] = indata[7:4];
    outdata[31:28] = indata[43:40];
    outdata[35:32] = indata[35:32];
    outdata[39:36] = indata[15:12];
    outdata[43:40] = indata[59:56];
    outdata[47:44] = indata[23:20];
    outdata[51:48] = indata[11:8];
    outdata[55:52] = indata[39:36];
    outdata[59:56] = indata[19:16];
    outdata[63:60] = indata[63:60];
    return outdata;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/computepac/PACInvSub" mylink="aarch64.functions.pac.computepac.PACInvSub" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PACInvSub()
// ===========

func <anchor link="func_PACInvSub_1">PACInvSub</anchor>(Tinput : bits(64)) =&gt; bits(64)
begin
    // This is a 4-bit substitution from the PRINCE-family cipher
    var Toutput : bits(64);
    for i = 0 to 15 do
        case Tinput[i*:4] of
            when '0000' =&gt;  Toutput[i*:4] = '0101';
            when '0001' =&gt;  Toutput[i*:4] = '1110';
            when '0010' =&gt;  Toutput[i*:4] = '1101';
            when '0011' =&gt;  Toutput[i*:4] = '1000';
            when '0100' =&gt;  Toutput[i*:4] = '1010';
            when '0101' =&gt;  Toutput[i*:4] = '1011';
            when '0110' =&gt;  Toutput[i*:4] = '0001';
            when '0111' =&gt;  Toutput[i*:4] = '1001';
            when '1000' =&gt;  Toutput[i*:4] = '0010';
            when '1001' =&gt;  Toutput[i*:4] = '0110';
            when '1010' =&gt;  Toutput[i*:4] = '1111';
            when '1011' =&gt;  Toutput[i*:4] = '0000';
            when '1100' =&gt;  Toutput[i*:4] = '0100';
            when '1101' =&gt;  Toutput[i*:4] = '1100';
            when '1110' =&gt;  Toutput[i*:4] = '0111';
            when '1111' =&gt;  Toutput[i*:4] = '0011';
        end;
    end;
    return Toutput;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/computepac/PACMult" mylink="aarch64.functions.pac.computepac.PACMult" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PACMult()
// =========

func <anchor link="func_PACMult_1">PACMult</anchor>(Sinput : bits(64)) =&gt; bits(64)
begin
    var t0 : bits(4);
    var t1 : bits(4);
    var t2 : bits(4);
    var t3 : bits(4);
    var Soutput : bits(64);

    for i = 0 to 3 do
        t0[3:0] = ROL(Sinput[((i+8))*:4], 1) XOR ROL(Sinput[((i+4))*:4], 2);
        t0[3:0] = t0[3:0] XOR ROL(Sinput[i*:4], 1);
        t1[3:0] = ROL(Sinput[((i+12))*:4], 1) XOR ROL(Sinput[((i+4))*:4], 1);
        t1[3:0] = t1[3:0] XOR ROL(Sinput[i*:4], 2);
        t2[3:0] = ROL(Sinput[((i+12))*:4], 2) XOR ROL(Sinput[((i+8))*:4], 1);
        t2[3:0] = t2[3:0] XOR ROL(Sinput[i*:4], 1);
        t3[3:0] = ROL(Sinput[((i+12))*:4], 1) XOR ROL(Sinput[((i+8))*:4], 2);
        t3[3:0] = t3[3:0] XOR ROL(Sinput[((i+4))*:4], 1);
        Soutput[i*:4] = t3[3:0];
        Soutput[((i+4))*:4] = t2[3:0];
        Soutput[((i+8))*:4] = t1[3:0];
        Soutput[((i+12))*:4] = t0[3:0];
    end;
    return Soutput;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/computepac/PACSub" mylink="aarch64.functions.pac.computepac.PACSub" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PACSub()
// ========

func <anchor link="func_PACSub_1">PACSub</anchor>(Tinput : bits(64)) =&gt; bits(64)
begin
    // This is a 4-bit substitution from the PRINCE-family cipher
    var Toutput : bits(64);
    for i = 0 to 15 do
        case Tinput[i*:4] of
            when '0000' =&gt;  Toutput[i*:4] = '1011';
            when '0001' =&gt;  Toutput[i*:4] = '0110';
            when '0010' =&gt;  Toutput[i*:4] = '1000';
            when '0011' =&gt;  Toutput[i*:4] = '1111';
            when '0100' =&gt;  Toutput[i*:4] = '1100';
            when '0101' =&gt;  Toutput[i*:4] = '0000';
            when '0110' =&gt;  Toutput[i*:4] = '1001';
            when '0111' =&gt;  Toutput[i*:4] = '1110';
            when '1000' =&gt;  Toutput[i*:4] = '0011';
            when '1001' =&gt;  Toutput[i*:4] = '0111';
            when '1010' =&gt;  Toutput[i*:4] = '0100';
            when '1011' =&gt;  Toutput[i*:4] = '0101';
            when '1100' =&gt;  Toutput[i*:4] = '1101';
            when '1101' =&gt;  Toutput[i*:4] = '0010';
            when '1110' =&gt;  Toutput[i*:4] = '0001';
            when '1111' =&gt;  Toutput[i*:4] = '1010';
        end;
    end;
    return Toutput;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/computepac/PacSub1" mylink="aarch64.functions.pac.computepac.PacSub1" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PacSub1()
// =========

func <anchor link="func_PACSub1_1">PACSub1</anchor>(Tinput : bits(64)) =&gt; bits(64)
begin
    // This is a 4-bit substitution from Qarma sigma1
    var Toutput : bits(64);
    for i = 0 to 15 do
        case Tinput[i*:4] of
            when '0000' =&gt; Toutput[i*:4] = '1010';
            when '0001' =&gt; Toutput[i*:4] = '1101';
            when '0010' =&gt; Toutput[i*:4] = '1110';
            when '0011' =&gt; Toutput[i*:4] = '0110';
            when '0100' =&gt; Toutput[i*:4] = '1111';
            when '0101' =&gt; Toutput[i*:4] = '0111';
            when '0110' =&gt; Toutput[i*:4] = '0011';
            when '0111' =&gt; Toutput[i*:4] = '0101';
            when '1000' =&gt; Toutput[i*:4] = '1001';
            when '1001' =&gt; Toutput[i*:4] = '1000';
            when '1010' =&gt; Toutput[i*:4] = '0000';
            when '1011' =&gt; Toutput[i*:4] = '1100';
            when '1100' =&gt; Toutput[i*:4] = '1011';
            when '1101' =&gt; Toutput[i*:4] = '0001';
            when '1110' =&gt; Toutput[i*:4] = '0010';
            when '1111' =&gt; Toutput[i*:4] = '0100';
        end;
    end;
    return Toutput;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/computepac/RC" mylink="aarch64.functions.pac.computepac.RC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// RC[]
// ====

var <anchor link="global_RC">RC</anchor> : array [[5]] of bits(64);</pstext></ps>
    <ps name="aarch64/functions/pac/computepac/TweakCellInvRot" mylink="aarch64.functions.pac.computepac.TweakCellInvRot" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TweakCellInvRot()
// =================

func <anchor link="func_TweakCellInvRot_1">TweakCellInvRot</anchor>(incell : bits(4)) =&gt; bits(4)
begin
    var outcell : bits(4);
    outcell[3] = incell[2];
    outcell[2] = incell[1];
    outcell[1] = incell[0];
    outcell[0] = incell[0] XOR incell[3];
    return outcell;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/computepac/TweakCellRot" mylink="aarch64.functions.pac.computepac.TweakCellRot" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TweakCellRot()
// ==============

func <anchor link="func_TweakCellRot_1">TweakCellRot</anchor>(incell : bits(4)) =&gt; bits(4)
begin
    var outcell : bits(4);
    outcell[3] = incell[0] XOR incell[1];
    outcell[2] = incell[3];
    outcell[1] = incell[2];
    outcell[0] = incell[1];
    return outcell;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/computepac/TweakInvShuffle" mylink="aarch64.functions.pac.computepac.TweakInvShuffle" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TweakInvShuffle()
// =================

func <anchor link="func_TweakInvShuffle_1">TweakInvShuffle</anchor>(indata : bits(64)) =&gt; bits(64)
begin
    var outdata : bits(64);
    outdata[3:0]   = <a link="func_TweakCellInvRot_1" file="shared_pseudocode.xml">TweakCellInvRot</a>(indata[51:48]);
    outdata[7:4]   = indata[55:52];
    outdata[11:8]  = indata[23:20];
    outdata[15:12] = indata[27:24];
    outdata[19:16] = indata[3:0];
    outdata[23:20] = indata[7:4];
    outdata[27:24] = <a link="func_TweakCellInvRot_1" file="shared_pseudocode.xml">TweakCellInvRot</a>(indata[11:8]);
    outdata[31:28] = indata[15:12];
    outdata[35:32] = <a link="func_TweakCellInvRot_1" file="shared_pseudocode.xml">TweakCellInvRot</a>(indata[31:28]);
    outdata[39:36] = <a link="func_TweakCellInvRot_1" file="shared_pseudocode.xml">TweakCellInvRot</a>(indata[63:60]);
    outdata[43:40] = <a link="func_TweakCellInvRot_1" file="shared_pseudocode.xml">TweakCellInvRot</a>(indata[59:56]);
    outdata[47:44] = <a link="func_TweakCellInvRot_1" file="shared_pseudocode.xml">TweakCellInvRot</a>(indata[19:16]);
    outdata[51:48] = indata[35:32];
    outdata[55:52] = indata[39:36];
    outdata[59:56] = indata[43:40];
    outdata[63:60] = <a link="func_TweakCellInvRot_1" file="shared_pseudocode.xml">TweakCellInvRot</a>(indata[47:44]);
    return outdata;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/computepac/TweakShuffle" mylink="aarch64.functions.pac.computepac.TweakShuffle" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TweakShuffle()
// ==============

func <anchor link="func_TweakShuffle_1">TweakShuffle</anchor>(indata : bits(64)) =&gt; bits(64)
begin
    var outdata : bits(64);
    outdata[3:0]   = indata[19:16];
    outdata[7:4]   = indata[23:20];
    outdata[11:8]  = <a link="func_TweakCellRot_1" file="shared_pseudocode.xml">TweakCellRot</a>(indata[27:24]);
    outdata[15:12] = indata[31:28];
    outdata[19:16] = <a link="func_TweakCellRot_1" file="shared_pseudocode.xml">TweakCellRot</a>(indata[47:44]);
    outdata[23:20] = indata[11:8];
    outdata[27:24] = indata[15:12];
    outdata[31:28] = <a link="func_TweakCellRot_1" file="shared_pseudocode.xml">TweakCellRot</a>(indata[35:32]);
    outdata[35:32] = indata[51:48];
    outdata[39:36] = indata[55:52];
    outdata[43:40] = indata[59:56];
    outdata[47:44] = <a link="func_TweakCellRot_1" file="shared_pseudocode.xml">TweakCellRot</a>(indata[63:60]);
    outdata[51:48] = <a link="func_TweakCellRot_1" file="shared_pseudocode.xml">TweakCellRot</a>(indata[3:0]);
    outdata[55:52] = indata[7:4];
    outdata[59:56] = <a link="func_TweakCellRot_1" file="shared_pseudocode.xml">TweakCellRot</a>(indata[43:40]);
    outdata[63:60] = <a link="func_TweakCellRot_1" file="shared_pseudocode.xml">TweakCellRot</a>(indata[39:36]);
    return outdata;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/pac/IsAPDAKeyEnabled" mylink="aarch64.functions.pac.pac.IsAPDAKeyEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsAPDAKeyEnabled()
// ==================
// Returns TRUE if authentication using the APDAKey_EL1 key is enabled.
// Otherwise, depending on the state of the PE, generate a trap, or return FALSE.

func <anchor link="func_IsAPDAKeyEnabled_0">IsAPDAKeyEnabled</anchor>() =&gt; boolean
begin
    var TrapEL2 : boolean;
    var TrapEL3 : boolean;
    var Enable : bits(1);

    case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL of
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            let IsEL1Regime : boolean = <a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>() == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
            Enable = if IsEL1Regime then SCTLR_EL1().EnDA else SCTLR_EL2().EnDA;
            TrapEL2 = <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().API == '0' &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>();
            TrapEL3 = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().API == '0';
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            Enable  = SCTLR_EL1().EnDA;
            TrapEL2 = <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().API == '0';
            TrapEL3 = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().API == '0';
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            Enable  = SCTLR_EL2().EnDA;
            TrapEL2 = FALSE;
            TrapEL3 = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().API == '0';
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            Enable  = SCTLR_EL3().EnDA;
            TrapEL2 = FALSE;
            TrapEL3 = FALSE;
    end;

    if Enable == '0' then
        return FALSE;
    elsif TrapEL3 &amp;&amp; <a link="func_EL3SDDUndefPriority_0" file="shared_pseudocode.xml">EL3SDDUndefPriority</a>() then
        Undefined();
    elsif TrapEL2 then
        TrapPACUse(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
    elsif TrapEL3 then
        if <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then
            Undefined();
        else
            TrapPACUse(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
        end;
    else
        return TRUE;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/pac/IsAPDBKeyEnabled" mylink="aarch64.functions.pac.pac.IsAPDBKeyEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsAPDBKeyEnabled()
// ==================
// Returns TRUE if authentication using the APDBKey_EL1 key is enabled.
// Otherwise, depending on the state of the PE, generate a trap, or return FALSE.

func <anchor link="func_IsAPDBKeyEnabled_0">IsAPDBKeyEnabled</anchor>() =&gt; boolean
begin
    var TrapEL2 : boolean;
    var TrapEL3 : boolean;
    var Enable : bits(1);

    case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL of
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            let IsEL1Regime : boolean = <a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>() == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
            Enable = if IsEL1Regime then SCTLR_EL1().EnDB else SCTLR_EL2().EnDB;
            TrapEL2 = <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().API == '0' &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>();
            TrapEL3 = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().API == '0';
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            Enable  = SCTLR_EL1().EnDB;
            TrapEL2 = <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().API == '0';
            TrapEL3 = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().API == '0';
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            Enable  = SCTLR_EL2().EnDB;
            TrapEL2 = FALSE;
            TrapEL3 = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().API == '0';
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            Enable  = SCTLR_EL3().EnDB;
            TrapEL2 = FALSE;
            TrapEL3 = FALSE;
    end;

    if Enable == '0' then
        return FALSE;
    elsif TrapEL3 &amp;&amp; <a link="func_EL3SDDUndefPriority_0" file="shared_pseudocode.xml">EL3SDDUndefPriority</a>() then
        Undefined();
    elsif TrapEL2 then
        TrapPACUse(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
    elsif TrapEL3 then
        if <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then
            Undefined();
        else
            TrapPACUse(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
        end;
    else
        return TRUE;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/pac/IsAPIAKeyEnabled" mylink="aarch64.functions.pac.pac.IsAPIAKeyEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsAPIAKeyEnabled()
// ==================
// Returns TRUE if authentication using the APIAKey_EL1 key is enabled.
// Otherwise, depending on the state of the PE, generate a trap, or return FALSE.

func <anchor link="func_IsAPIAKeyEnabled_0">IsAPIAKeyEnabled</anchor>() =&gt; boolean
begin
    var TrapEL2 : boolean;
    var TrapEL3 : boolean;
    var Enable : bits(1);

    case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL of
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            let IsEL1Regime : boolean = <a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>() == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
            Enable = if IsEL1Regime then SCTLR_EL1().EnIA else SCTLR_EL2().EnIA;
            TrapEL2 = <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().API == '0' &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>();
            TrapEL3 = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().API == '0';
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            Enable  = SCTLR_EL1().EnIA;
            TrapEL2 = <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().API == '0';
            TrapEL3 = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().API == '0';
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            Enable  = SCTLR_EL2().EnIA;
            TrapEL2 = FALSE;
            TrapEL3 = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().API == '0';
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            Enable  = SCTLR_EL3().EnIA;
            TrapEL2 = FALSE;
            TrapEL3 = FALSE;
    end;

    if Enable == '0' then
        return FALSE;
    elsif TrapEL3 &amp;&amp; <a link="func_EL3SDDUndefPriority_0" file="shared_pseudocode.xml">EL3SDDUndefPriority</a>() then
        Undefined();
    elsif TrapEL2 then
        TrapPACUse(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
    elsif TrapEL3 then
        if <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then
            Undefined();
        else
            TrapPACUse(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
        end;
    else
        return TRUE;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/pac/IsAPIBKeyEnabled" mylink="aarch64.functions.pac.pac.IsAPIBKeyEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsAPIBKeyEnabled()
// ==================
// Returns TRUE if authentication using the APIBKey_EL1 key is enabled.
// Otherwise, depending on the state of the PE, generate a trap, or return FALSE.

func <anchor link="func_IsAPIBKeyEnabled_0">IsAPIBKeyEnabled</anchor>() =&gt; boolean
begin
    var TrapEL2 : boolean;
    var TrapEL3 : boolean;
    var Enable : bits(1);

    case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL of
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            let IsEL1Regime : boolean = <a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>() == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
            Enable = if IsEL1Regime then SCTLR_EL1().EnIB else SCTLR_EL2().EnIB;
            TrapEL2 = <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().API == '0' &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>();
            TrapEL3 = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().API == '0';
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            Enable  = SCTLR_EL1().EnIB;
            TrapEL2 = <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().API == '0';
            TrapEL3 = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().API == '0';
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            Enable  = SCTLR_EL2().EnIB;
            TrapEL2 = FALSE;
            TrapEL3 = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().API == '0';
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            Enable  = SCTLR_EL3().EnIB;
            TrapEL2 = FALSE;
            TrapEL3 = FALSE;
    end;

    if Enable == '0' then
        return FALSE;
    elsif TrapEL3 &amp;&amp; <a link="func_EL3SDDUndefPriority_0" file="shared_pseudocode.xml">EL3SDDUndefPriority</a>() then
        Undefined();
    elsif TrapEL2 then
        TrapPACUse(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
    elsif TrapEL3 then
        if <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then
            Undefined();
        else
            TrapPACUse(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
        end;
    else
        return TRUE;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/pac/IsPACMEnabled" mylink="aarch64.functions.pac.pac.IsPACMEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsPACMEnabled()
// ===============
// Returns TRUE if the effects of the PACM instruction are enabled, otherwise FALSE.

func <anchor link="func_IsPACMEnabled_0">IsPACMEnabled</anchor>() =&gt; boolean
begin
    assert IsFeatureImplemented(FEAT_PAuth) &amp;&amp; IsFeatureImplemented(FEAT_PAuth_LR);

    if <a link="func_IsTrivialPACMImplementation_0" file="shared_pseudocode.xml">IsTrivialPACMImplementation</a>() then
        return FALSE;
    end;

    var enabled : boolean;

    // EL2 could force the behavior at EL1 and EL0 to NOP.
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
        enabled = <a link="func_IsHCRXEL2Enabled_0" file="shared_pseudocode.xml">IsHCRXEL2Enabled</a>() &amp;&amp; HCRX_EL2().PACMEn == '1';
    else
        enabled = TRUE;
    end;

    // Otherwise, the SCTLR2_ELx bit determines the behavior.
    if enabled then
        var enpacm_bit : bit;
        case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL of
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
                enpacm_bit = SCTLR2_EL3().EnPACM;
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
                enpacm_bit = if <a link="func_IsSCTLR2EL2Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL2Enabled</a>() then SCTLR2_EL2().EnPACM else '0';
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
                enpacm_bit = if <a link="func_IsSCTLR2EL1Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL1Enabled</a>() then SCTLR2_EL1().EnPACM else '0';
            when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
                if <a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
                    enpacm_bit = if <a link="func_IsSCTLR2EL2Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL2Enabled</a>() then SCTLR2_EL2().EnPACM0 else '0';
                else
                    enpacm_bit = if <a link="func_IsSCTLR2EL1Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL1Enabled</a>() then SCTLR2_EL1().EnPACM0 else '0';
                end;
        end;
        enabled = enpacm_bit == '1';
    end;

    return enabled;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/pac/IsTrivialPACMImplementation" mylink="aarch64.functions.pac.pac.IsTrivialPACMImplementation" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsTrivialPACMImplementation()
// =============================
// Returns TRUE if the PE has a trivial implementation of PACM.

func <anchor link="func_IsTrivialPACMImplementation_0">IsTrivialPACMImplementation</anchor>() =&gt; boolean
begin
    return (IsFeatureImplemented(FEAT_PACIMP) &amp;&amp;
              ImpDefBool(&quot;Trivial PSTATE.PACM implementation&quot;));
end;</pstext></ps>
    <ps name="aarch64/functions/pac/pac/PtrHasUpperAndLowerAddRanges" mylink="aarch64.functions.pac.pac.PtrHasUpperAndLowerAddRanges" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PtrHasUpperAndLowerAddRanges()
// ==============================
// Returns TRUE if the pointer has upper and lower address ranges, FALSE otherwise.

func <anchor link="func_PtrHasUpperAndLowerAddRanges_0">PtrHasUpperAndLowerAddRanges</anchor>() =&gt; boolean
begin
    let regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a> = <a link="func_TranslationRegime_1" file="shared_pseudocode.xml">TranslationRegime</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);

    return <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime);
end;</pstext></ps>
    <ps name="aarch64/functions/pac/strip/Strip" mylink="aarch64.functions.pac.strip.Strip" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Strip()
// =======
// Strip() returns a 64-bit value containing A, but replacing the pointer authentication
// code field bits with the extension of the address bits. This can apply to either
// instructions or data, where, as the use of tagged pointers is distinct, it might be
// handled differently.

func <anchor link="func_Strip_2">Strip</anchor>(A : bits(64), data : boolean) =&gt; bits(64)
begin
    var original_ptr : bits(64);
    var extfield : bits(64);
    let tbi : boolean = <a link="func_EffectiveTBI_3" file="shared_pseudocode.xml">EffectiveTBI</a>(A, !data, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) == '1';
    let mtx : boolean = (IsFeatureImplemented(FEAT_MTE_NO_ADDRESS_TAGS) &amp;&amp;
                            <a link="func_EffectiveMTX_3" file="shared_pseudocode.xml">EffectiveMTX</a>(A, !data, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) == '1');
    let bottom_PAC_bit : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_CalculateBottomPACBit_1" file="shared_pseudocode.xml">CalculateBottomPACBit</a>(A[55]);
    let EL3_using_lva3 : boolean = (IsFeatureImplemented(FEAT_LVA3) &amp;&amp;
                                       <a link="func_TranslationRegime_1" file="shared_pseudocode.xml">TranslationRegime</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) == <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> &amp;&amp;
                                       <a link="func_AArch64_IASize_1" file="shared_pseudocode.xml">AArch64_IASize</a>(TCR_EL3().T0SZ) &gt; 52);
    if EL3_using_lva3 then
        extfield = Replicate{64}('0');
    else
        extfield = Replicate{64}(A[55]);
    end;

    if tbi then
        if (bottom_PAC_bit &lt;= 55) then
            original_ptr = (A[63:56] ::
                            extfield[55:bottom_PAC_bit] :: A[bottom_PAC_bit-1:0]);
        else
            original_ptr = A[63:56] :: A[55:0];
        end;
    elsif mtx then
        if (bottom_PAC_bit &lt;= 55) then
            original_ptr = (extfield[63:60] :: A[59:56] ::
                            extfield[55:bottom_PAC_bit] :: A[bottom_PAC_bit-1:0]);
        else
            original_ptr = extfield[63:60] :: A[59:56] :: A[55:0];
        end;
    else
        original_ptr =  extfield[63:bottom_PAC_bit] :: A[bottom_PAC_bit-1:0];
    end;

    return original_ptr;
end;</pstext></ps>
    <ps name="aarch64/functions/pac/trappacuse/TrapPACUse" mylink="aarch64.functions.pac.trappacuse.TrapPACUse" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TrapPACUse()
// ============
// Used for the trapping of the pointer authentication functions by higher exception
// levels.

noreturn func TrapPACUse(target_el : bits(2))
begin
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(target_el) &amp;&amp; target_el !=  <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; UInt(target_el) &gt;= UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);

    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>;
    let vect_offset : integer = 0;
    except = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_PACTrap" file="shared_pseudocode.xml">Exception_PACTrap</a>);
    AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
end;</pstext></ps>
    <ps name="aarch64/functions/predictionrestrict/AArch64_RestrictPrediction" mylink="aarch64.functions.predictionrestrict.AArch64_RestrictPrediction" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_RestrictPrediction()
// ============================
// Clear all predictions in the context.

func <anchor link="func_AArch64_RestrictPrediction_2">AArch64_RestrictPrediction</anchor>(val : bits(64), restriction : <a link="type_RestrictType" file="shared_pseudocode.xml">RestrictType</a>)
begin

    var c : <a link="type_ExecutionCntxt" file="shared_pseudocode.xml">ExecutionCntxt</a>;
    let target_el : bits(2)    = val[25:24];

    // If the target EL is not implemented or the instruction is executed at an
    // EL lower than the specified level, the instruction is treated as a NOP.
    if !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(target_el) || UInt(target_el) &gt; UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) then <a link="func_ExecuteAsNOP_0" file="shared_pseudocode.xml">ExecuteAsNOP</a>(); end;

    let ns : bit  = val[26];
    let nse : bit = val[27];
    let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_TargetSecurityState_2" file="shared_pseudocode.xml">TargetSecurityState</a>(ns, nse);

    // If the combination of Security state and Exception level is not implemented,
    // the instruction is treated as a NOP.
    if ss == <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a> &amp;&amp; target_el != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then <a link="func_ExecuteAsNOP_0" file="shared_pseudocode.xml">ExecuteAsNOP</a>(); end;
    if !IsFeatureImplemented(FEAT_RME) &amp;&amp; target_el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; ss != <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
        <a link="func_ExecuteAsNOP_0" file="shared_pseudocode.xml">ExecuteAsNOP</a>();
    end;

    c.security  = ss;
    c.target_el = target_el;

    if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        if (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>()) || <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> then
            c.is_vmid_valid = TRUE;
            c.all_vmid      = FALSE;
            c.vmid          = <a link="func_VMID_0" file="shared_pseudocode.xml">VMID</a>();

        elsif (target_el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(target_el)) || target_el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> then
            c.is_vmid_valid = TRUE;
            c.all_vmid      = val[48] == '1';
            c.vmid          = val[47:32];       // Only valid if  val[48] == '0';

        else
            c.is_vmid_valid = FALSE;
        end;
    else
        c.is_vmid_valid = FALSE;
    end;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        c.is_asid_valid = TRUE;
        c.all_asid      = FALSE;
        c.asid          = <a link="func_ASID_0" file="shared_pseudocode.xml">ASID</a>();

    elsif target_el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        c.is_asid_valid = TRUE;
        c.all_asid      = val[16] == '1';
        c.asid          = val[15:0];            // Only valid if  val[16] == '0';

    else
        c.is_asid_valid = FALSE;
    end;

    c.restriction = restriction;
    RESTRICT_PREDICTIONS(c);
end;</pstext></ps>
    <ps name="aarch64/functions/prefetch/Prefetch" mylink="aarch64.functions.prefetch.Prefetch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Prefetch()
// ==========

// Decode and execute the prefetch hint on ADDRESS specified by PRFOP

func <anchor link="func_Prefetch_3">Prefetch</anchor>(address : bits(64), prfop : bits(5), supports_ir : boolean)
begin
    var hint : <a link="type_PrefetchHint" file="shared_pseudocode.xml">PrefetchHint</a>;
    var target : integer;
    var stream : boolean;

    case prfop of
        when '00xxx'                   =&gt; hint = <a link="enum_Prefetch_READ" file="shared_pseudocode.xml">Prefetch_READ</a>;      // PLD: prefetch for load
        when '01xxx'                   =&gt; hint = <a link="enum_Prefetch_EXEC" file="shared_pseudocode.xml">Prefetch_EXEC</a>;      // PLI: preload instructions
        when '10xxx'                   =&gt; hint = <a link="enum_Prefetch_WRITE" file="shared_pseudocode.xml">Prefetch_WRITE</a>;     // PST: prepare for store
        when '11000' where supports_ir =&gt; hint = <a link="enum_Prefetch_IR" file="shared_pseudocode.xml">Prefetch_IR</a>;        // IR: intent to read
        otherwise                      =&gt; return;                    // unallocated hint
    end;

    // If &lt;type&gt; is IR, then &lt;target&gt; and &lt;policy&gt; are not specified and Rt[2:0] are '000'.
    if hint != <a link="enum_Prefetch_IR" file="shared_pseudocode.xml">Prefetch_IR</a> then
        target = UInt(prfop[2:1]);                 // target cache level
        stream = (prfop[0] != '0');                // streaming (non-temporal)
    else
        target = ARBITRARY: integer;
        stream = ARBITRARY: boolean;
    end;
    Hint_Prefetch(address, hint, target, stream);
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/pstatefield/PSTATEField" mylink="aarch64.functions.pstatefield.PSTATEField" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PSTATEField
// ===========
// MSR (immediate) instruction destinations.

type <anchor link="type_PSTATEField">PSTATEField</anchor> of enumeration {
                         <anchor link="enum_PSTATEField_DAIFSet">PSTATEField_DAIFSet</anchor>, <anchor link="enum_PSTATEField_DAIFClr">PSTATEField_DAIFClr</anchor>,
                         <anchor link="enum_PSTATEField_PAN">PSTATEField_PAN</anchor>, // Armv8.1
                         <anchor link="enum_PSTATEField_UAO">PSTATEField_UAO</anchor>, // Armv8.2
                         <anchor link="enum_PSTATEField_DIT">PSTATEField_DIT</anchor>, // Armv8.4
                         <anchor link="enum_PSTATEField_SSBS">PSTATEField_SSBS</anchor>,
                         <anchor link="enum_PSTATEField_TCO">PSTATEField_TCO</anchor>, // Armv8.5
                         <anchor link="enum_PSTATEField_SVCRSM">PSTATEField_SVCRSM</anchor>,
                         <anchor link="enum_PSTATEField_SVCRZA">PSTATEField_SVCRZA</anchor>,
                         <anchor link="enum_PSTATEField_SVCRSMZA">PSTATEField_SVCRSMZA</anchor>,
                         <anchor link="enum_PSTATEField_ALLINT">PSTATEField_ALLINT</anchor>,
                         <anchor link="enum_PSTATEField_PM">PSTATEField_PM</anchor>,
                         <anchor link="enum_PSTATEField_SP">PSTATEField_SP</anchor>
                         };</pstext></ps>
    <ps name="aarch64/functions/ras/AArch64_DelegatedSErrorTarget" mylink="aarch64.functions.ras.AArch64_DelegatedSErrorTarget" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_DelegatedSErrorTarget()
// ===============================
// Returns whether a delegated SError exception pended by SCR_EL3.VSE is masked,
// and the target Exception level of the delegated SError exception.

func <anchor link="func_AArch64_DelegatedSErrorTarget_0">AArch64_DelegatedSErrorTarget</anchor>() =&gt; (boolean, bits(2))
begin
    assert IsFeatureImplemented(FEAT_E3DSE);
    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() || <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then
        return (TRUE, ARBITRARY : bits(2));
    end;

    let effective_amo : bit = <a link="func_EffectiveHCR_AMO_0" file="shared_pseudocode.xml">EffectiveHCR_AMO</a>();
    let effective_tge : bit = <a link="func_EffectiveTGE_0" file="shared_pseudocode.xml">EffectiveTGE</a>();

    // The exception is masked by software.
    var masked : boolean;
    case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL of
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            masked = ((effective_tge == '0' &amp;&amp; effective_amo == '0') || <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.A == '1');
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            masked = (effective_amo == '0' &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.A == '1');
        otherwise =&gt;
            unreachable;
    end;

    // The exception might be disabled debug in the Security state indicated by
    // SCR_EL3().[NS, NSE] by external debug.
    let intdis : boolean = <a link="func_ExternalDebugInterruptsDisabled_1" file="shared_pseudocode.xml">ExternalDebugInterruptsDisabled</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>);

    var target_el : bits(2) = ARBITRARY : bits(2);
    if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; effective_amo == '1' &amp;&amp; !intdis &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} then
        target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
        masked = FALSE;

    elsif (<a link="func_EffectiveHCRX_EL2_TMEA_0" file="shared_pseudocode.xml">EffectiveHCRX_EL2_TMEA</a>() == '1' &amp;&amp; !intdis &amp;&amp;
             ((<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.A == '1') ||
              (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; masked &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>()))) then
        target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
        masked = FALSE;

    elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || <a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
        if !masked then target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>; end;

    else
        assert (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> || (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>()));
        if !masked then target_el = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>; end;
    end;

    // External debug might disable the delegated exception for the target Exception level.
    if <a link="func_ExternalDebugInterruptsDisabled_1" file="shared_pseudocode.xml">ExternalDebugInterruptsDisabled</a>(target_el) then
        masked = TRUE;
        target_el = ARBITRARY : bits(2);
    end;

    return (masked, target_el);
end;</pstext></ps>
    <ps name="aarch64/functions/ras/AArch64_ESBOperation" mylink="aarch64.functions.ras.AArch64_ESBOperation" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ESBOperation()
// ======================
// Perform the AArch64 ESB operation, either for ESB executed in AArch64 state, or for
// ESB in AArch32 state when SError interrupts are routed to an Exception level using
// AArch64

func <anchor link="func_AArch64_ESBOperation_0">AArch64_ESBOperation</anchor>()
begin
    var target_el : bits(2);
    var masked : boolean;

    (masked, target_el) = <a link="func_PhysicalSErrorTarget_0" file="shared_pseudocode.xml">PhysicalSErrorTarget</a>();

    // Check for a masked Physical SError pending that can be synchronized
    // by an Error synchronization event.
    if masked &amp;&amp; <a link="func_IsSynchronizablePhysicalSErrorPending_0" file="shared_pseudocode.xml">IsSynchronizablePhysicalSErrorPending</a>() then
        // This function might be called for an interprocessing case, and INTdis is masking
        // the SError interrupt.
        if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>()) then
            var syndrome : bits(32) = Zeros{};
            syndrome[31]      = '1';    // A
            syndrome[15:0]    = <a link="func_AArch32_PhysicalSErrorSyndrome_0" file="shared_pseudocode.xml">AArch32_PhysicalSErrorSyndrome</a>();
            DISR()            = syndrome;
        else
            let implicit_esb : boolean = FALSE;
            let is_esb : boolean       = TRUE;
            var syndrome : bits(64)    = Zeros{};

            syndrome[31]   = '1';       // A
            syndrome[24:0] = <a link="func_AArch64_PhysicalSErrorSyndrome_2" file="shared_pseudocode.xml">AArch64_PhysicalSErrorSyndrome</a>(is_esb, implicit_esb);
            DISR_EL1()     = syndrome;
        end;
        ClearPendingPhysicalSError();   // Set ISR_EL1.A to 0
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/ras/AArch64_EncodeAsyncErrorSyndrome" mylink="aarch64.functions.ras.AArch64_EncodeAsyncErrorSyndrome" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_EncodeAsyncErrorSyndrome()
// ==================================
// Return the encoding for specified ErrorState for an SError exception taken
// to AArch64 state.

func <anchor link="func_AArch64_EncodeAsyncErrorSyndrome_1">AArch64_EncodeAsyncErrorSyndrome</anchor>(errorstate : <a link="type_ErrorState" file="shared_pseudocode.xml">ErrorState</a>) =&gt; bits(3)
begin
    case errorstate of
        when <a link="enum_ErrorState_UC" file="shared_pseudocode.xml">ErrorState_UC</a>  =&gt; return '000';
        when <a link="enum_ErrorState_UEU" file="shared_pseudocode.xml">ErrorState_UEU</a> =&gt; return '001';
        when <a link="enum_ErrorState_UEO" file="shared_pseudocode.xml">ErrorState_UEO</a> =&gt; return '010';
        when <a link="enum_ErrorState_UER" file="shared_pseudocode.xml">ErrorState_UER</a> =&gt; return '011';
        when <a link="enum_ErrorState_CE" file="shared_pseudocode.xml">ErrorState_CE</a>  =&gt; return '110';
        otherwise =&gt; unreachable;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/ras/AArch64_EncodeSyncErrorSyndrome" mylink="aarch64.functions.ras.AArch64_EncodeSyncErrorSyndrome" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_EncodeSyncErrorSyndrome()
// =================================
// Return the encoding for specified ErrorState for a synchronous Abort
// exception taken to AArch64 state.

func <anchor link="func_AArch64_EncodeSyncErrorSyndrome_1">AArch64_EncodeSyncErrorSyndrome</anchor>(errorstate : <a link="type_ErrorState" file="shared_pseudocode.xml">ErrorState</a>) =&gt; bits(2)
begin
    case errorstate of
        when <a link="enum_ErrorState_UC" file="shared_pseudocode.xml">ErrorState_UC</a>  =&gt; return '10';
        when <a link="enum_ErrorState_UEU" file="shared_pseudocode.xml">ErrorState_UEU</a> =&gt; return '10';    // UEU is reported as UC
        when <a link="enum_ErrorState_UEO" file="shared_pseudocode.xml">ErrorState_UEO</a> =&gt; return '11';
        when <a link="enum_ErrorState_UER" file="shared_pseudocode.xml">ErrorState_UER</a> =&gt; return '00';
        otherwise =&gt; unreachable;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/ras/AArch64_PhysicalSErrorSyndrome" mylink="aarch64.functions.ras.AArch64_PhysicalSErrorSyndrome" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_PhysicalSErrorSyndrome()
// ================================
// Generate SError syndrome.

func <anchor link="func_AArch64_PhysicalSErrorSyndrome_2">AArch64_PhysicalSErrorSyndrome</anchor>(is_esb : boolean, implicit_esb : boolean) =&gt; bits(25)
begin
    var syndrome : bits(25) = Zeros{};
    var target_el : bits(2);
    (-, target_el) = <a link="func_PhysicalSErrorTarget_0" file="shared_pseudocode.xml">PhysicalSErrorTarget</a>();

    if <a link="func_ReportErrorAsUncategorized_0" file="shared_pseudocode.xml">ReportErrorAsUncategorized</a>() then
        syndrome = Zeros{25};
    elsif <a link="func_ReportErrorAsIMPDEF_0" file="shared_pseudocode.xml">ReportErrorAsIMPDEF</a>() then
        syndrome[24]   = '1';                                             // IDS
        syndrome[23:0] = ImpDefBits{24}(&quot;IMPDEF ErrorState&quot;);
    else
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_GetPendingPhysicalSError_0" file="shared_pseudocode.xml">GetPendingPhysicalSError</a>();
        let errorstate : <a link="type_ErrorState" file="shared_pseudocode.xml">ErrorState</a> = <a link="func_PEErrorState_1" file="shared_pseudocode.xml">PEErrorState</a>(fault);
        syndrome[24]    = '0';                                            // IDS
        if (!is_esb &amp;&amp; IsFeatureImplemented(FEAT_PFAR) &amp;&amp;
              !(<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
              (HCR_EL2().VM == '1' || HCR_EL2().DC == '1') &amp;&amp; target_el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>)) then
            syndrome[14] = if <a link="func_IsPFARValid_1" file="shared_pseudocode.xml">IsPFARValid</a>(fault) then '1' else '0';
        end;
        syndrome[13]    = if implicit_esb then '1' else '0';              // IESB
        syndrome[12:10] = <a link="func_AArch64_EncodeAsyncErrorSyndrome_1" file="shared_pseudocode.xml">AArch64_EncodeAsyncErrorSyndrome</a>(errorstate);   // AET
        syndrome[9]     = fault.extflag;                                  // EA
        syndrome[5:0]   = '010001';                                       // DFSC
    end;

    return syndrome;
end;</pstext></ps>
    <ps name="aarch64/functions/ras/AArch64_dESBOperation" mylink="aarch64.functions.ras.AArch64_dESBOperation" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_dESBOperation()
// =======================
// Perform the AArch64 ESB operation for a pending delegated SError exception.

func <anchor link="func_AArch64_dESBOperation_0">AArch64_dESBOperation</anchor>()
begin
    assert (IsFeatureImplemented(FEAT_E3DSE) &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
    // When FEAT_E3DSE is implemented, SCR_EL3.DSE might inject a delegated SError exception.
    var dsei_pending, dsei_masked : boolean;
    dsei_pending = <a link="func_EffectiveSCR_EL3_EnDSE_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_EnDSE</a>() == '1' &amp;&amp; SCR_EL3().DSE == '1';
    (dsei_masked, -) = <a link="func_AArch64_DelegatedSErrorTarget_0" file="shared_pseudocode.xml">AArch64_DelegatedSErrorTarget</a>();
    if dsei_pending &amp;&amp; dsei_masked then
        var target : bits(64) = Zeros{};
        target[31] = '1';                  // A
        target[24:0] = VSESR_EL3()[24:0];
        VDISR_EL3() = target;
        <a link="func_ClearPendingDelegatedSError_0" file="shared_pseudocode.xml">ClearPendingDelegatedSError</a>();
    end;
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/ras/AArch64_vESBOperation" mylink="aarch64.functions.ras.AArch64_vESBOperation" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_vESBOperation()
// =======================
// Perform the AArch64 ESB operation for an unmasked pending virtual SError exception.
// If FEAT_E3DSE is implemented and there is no unmasked virtual SError exception
// pending, then AArch64_dESBOperation() is called to perform the AArch64 ESB operation
// for a pending delegated SError exception.

func <anchor link="func_AArch64_vESBOperation_0">AArch64_vESBOperation</anchor>()
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);

    // If physical SError exceptions are routed to EL2, and TGE is not set, then a virtual
    // SError exception might be pending.
    let vsei_pending : boolean = (<a link="func_IsVirtualSErrorPending_0" file="shared_pseudocode.xml">IsVirtualSErrorPending</a>() &amp;&amp; <a link="func_EffectiveTGE_0" file="shared_pseudocode.xml">EffectiveTGE</a>() == '0' &amp;&amp;
                                  (<a link="func_EffectiveHCR_AMO_0" file="shared_pseudocode.xml">EffectiveHCR_AMO</a>() == '1' || <a link="func_EffectiveHCRX_EL2_TMEA_0" file="shared_pseudocode.xml">EffectiveHCRX_EL2_TMEA</a>() == '1'));
    let vsei_masked : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.A == '1' || <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() || <a link="func_ExternalDebugInterruptsDisabled_1" file="shared_pseudocode.xml">ExternalDebugInterruptsDisabled</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>);

    // Check for a masked virtual SError pending
    if vsei_pending &amp;&amp; vsei_masked then
        // This function might be called for the interprocessing case, and INTdis is masking
        // the virtual SError exception.
        if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
            var target : bits(32) = Zeros{};
            target[31]    = '1';             // A
            target[15:14] = VDFSR()[15:14];  // AET
            target[12]    = VDFSR()[12];     // ExT
            target[9]     = TTBCR().EAE;     // LPAE
            if TTBCR().EAE == '1' then       // Long-descriptor format
                target[5:0]    = '010001';   // STATUS
            else                             // Short-descriptor format
                target[10,3:0] = '10110';    // FS
            end;
            VDISR() = target;
        else
            var target : bits(64) = Zeros{};
            target[31]   = '1';              // A
            target[24:0] = VSESR_EL2()[24:0];
            VDISR_EL2() = target;
        end;
        <a link="func_ClearPendingVirtualSError_0" file="shared_pseudocode.xml">ClearPendingVirtualSError</a>();
    elsif IsFeatureImplemented(FEAT_E3DSE) then
        <a link="func_AArch64_dESBOperation_0" file="shared_pseudocode.xml">AArch64_dESBOperation</a>();
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/ras/EffectiveSCR_EL3_EnDSE" mylink="aarch64.functions.ras.EffectiveSCR_EL3_EnDSE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveSCR_EL3_EnDSE()
// ========================
// Return the Effective value of SCR_EL3().EnDSE.

func <anchor link="func_EffectiveSCR_EL3_EnDSE_0">EffectiveSCR_EL3_EnDSE</anchor>() =&gt; bit
begin
    if !IsFeatureImplemented(FEAT_E3DSE) then
        return '0';
    end;
    if SCR_EL3().EA == '0' &amp;&amp; <a link="func_EffectiveSCR_EL3_TMEA_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_TMEA</a>() == '0' then
        return '0';
    end;
    return SCR_EL3().EnDSE;
end;</pstext></ps>
    <ps name="aarch64/functions/ras/FirstRecordOfNode" mylink="aarch64.functions.ras.FirstRecordOfNode" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FirstRecordOfNode()
// ===================
// Return the first record in the node that contains the record n.

func <anchor link="func_FirstRecordOfNode_1">FirstRecordOfNode</anchor>(n : integer) =&gt; integer
begin
    for q = n downto 0 do
        if <a link="func_IsFirstRecordOfNode_1" file="shared_pseudocode.xml">IsFirstRecordOfNode</a>(q) then return q; end;
    end;
    unreachable;
end;</pstext></ps>
    <ps name="aarch64/functions/ras/IsCommonFaultInjectionImplemented" mylink="aarch64.functions.ras.IsCommonFaultInjectionImplemented" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsCommonFaultInjectionImplemented()
// ===================================
// Check if the Common Fault Injection Model Extension is implemented by the node that owns this
// error record.

impdef func <anchor link="func_IsCommonFaultInjectionImplemented_1">IsCommonFaultInjectionImplemented</anchor>(n : integer) =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/ras/IsCountableErrorsRecorded" mylink="aarch64.functions.ras.IsCountableErrorsRecorded" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsCountableErrorsRecorded()
// ===========================
// Check whether Error record n records countable errors.

impdef func <anchor link="func_IsCountableErrorsRecorded_1">IsCountableErrorsRecorded</anchor>(n : integer) =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/ras/IsErrorAddressIncluded" mylink="aarch64.functions.ras.IsErrorAddressIncluded" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsErrorAddressIncluded()
// ========================
// Check whether Error record n includes an address associated with an error.

impdef func <anchor link="func_IsErrorAddressIncluded_1">IsErrorAddressIncluded</anchor>(n : integer) =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/ras/IsErrorRecordImplemented" mylink="aarch64.functions.ras.IsErrorRecordImplemented" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsErrorRecordImplemented()
// ==========================
// Is the error record n implemented

impdef func <anchor link="func_IsErrorRecordImplemented_1">IsErrorRecordImplemented</anchor>(n : integer) =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/ras/IsFirstRecordOfNode" mylink="aarch64.functions.ras.IsFirstRecordOfNode" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsFirstRecordOfNode()
// =====================
// Check if the record q is the first error record in its node.

impdef func <anchor link="func_IsFirstRecordOfNode_1">IsFirstRecordOfNode</anchor>(q : integer) =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/ras/IsPFARValid" mylink="aarch64.functions.ras.IsPFARValid" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsPFARValid()
// =============
// Determine if faulting PA can be reported.

impdef func <anchor link="func_IsPFARValid_1">IsPFARValid</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; boolean
begin
    return !<a link="func_IsAsyncAbort_1" file="shared_pseudocode.xml">IsAsyncAbort</a>(fault);
end;</pstext></ps>
    <ps name="aarch64/functions/ras/IsSPMUCounterImplemented" mylink="aarch64.functions.ras.IsSPMUCounterImplemented" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsSPMUCounterImplemented()
// ==========================
// Does the System PMU s implement the counter n.

impdef func <anchor link="func_IsSPMUCounterImplemented_2">IsSPMUCounterImplemented</anchor>(s : integer, n : integer) =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/rcw" mylink="aarch64.functions.rcw" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">constant <anchor link="global_RCW64_PROTECTED_BIT">RCW64_PROTECTED_BIT</anchor> : integer = 52;
constant <anchor link="global_RCW128_PROTECTED_BIT">RCW128_PROTECTED_BIT</anchor> : integer = 114;</pstext></ps>
    <ps name="aarch64/functions/rcw/ProtectionEnabled" mylink="aarch64.functions.rcw.ProtectionEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ProtectionEnabled()
// ===================
// Returns TRUE if the ProtectedBit is
// enabled in the current Exception level.

func <anchor link="func_ProtectionEnabled_1">ProtectionEnabled</anchor>(el : bits(2)) =&gt; boolean
begin
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(el);
    let regime : bits(2) = <a link="func_S1TranslationRegime_1" file="shared_pseudocode.xml">S1TranslationRegime</a>(el);
    assert(!<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(regime));
    if (!<a link="func_IsD128Enabled_1" file="shared_pseudocode.xml">IsD128Enabled</a>(el)) then
        case regime of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
                return <a link="func_IsTCR2EL1Enabled_0" file="shared_pseudocode.xml">IsTCR2EL1Enabled</a>() &amp;&amp; TCR2_EL1().PnCH == '1';
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
                return <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() &amp;&amp; TCR2_EL2().PnCH == '1';
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
                return TCR_EL3().PnCH == '1';
        end;
    else
        return TRUE;
    end;
    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/functions/rcw/RCWCheck" mylink="aarch64.functions.rcw.RCWCheck" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// RCWCheck()
// ==========
// Returns nzcv based on : if the new value for RCW/RCWS instructions satisfy RCW and/or RCWS checks
// Z is set to 1 if RCW checks fail
// C is set to 0 if RCWS checks fail

func <anchor link="func_RCWCheck_4">RCWCheck</anchor>{N}(old : bits(N), new : bits(N), soft : boolean) =&gt; bits(4)
begin
    assert N IN {64,128};
    let protectedbit : integer = if N == 128 then <a link="global_RCW128_PROTECTED_BIT" file="shared_pseudocode.xml">RCW128_PROTECTED_BIT</a> else <a link="global_RCW64_PROTECTED_BIT" file="shared_pseudocode.xml">RCW64_PROTECTED_BIT</a>;
    var rcw_fail : boolean        = FALSE;
    var rcws_fail : boolean       = FALSE;
    var rcw_state_fail : boolean  = FALSE;
    var rcws_state_fail : boolean = FALSE;
    var rcw_mask_fail : boolean   = FALSE;
    var rcws_mask_fail : boolean  = FALSE;

    //Effective RCWMask calculation
    var rcwmask : bits(N) = RCWMASK_EL1()[N-1:0];
    if N == 64 then
        rcwmask[49:18] = Replicate{32}(rcwmask[17]);
        rcwmask[0] = '0';
    else
        rcwmask[55:17] = Replicate{39}(rcwmask[16]);
        rcwmask[126:125,120:119,107:101,90:56,1:0] = Zeros{48};
    end;

    //Effective RCWSMask calculation
    var rcwsoftmask : bits(N) = RCWSMASK_EL1()[N-1:0];
    if N == 64 then
        rcwsoftmask[49:18] = Replicate{32}(rcwsoftmask[17]);
        rcwsoftmask[0] = '0';
        if(<a link="func_ProtectionEnabled_1" file="shared_pseudocode.xml">ProtectionEnabled</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL)) then
            rcwsoftmask[52] = '0';
        end;
    else
        rcwsoftmask[55:17] = Replicate{39}(rcwsoftmask[16]);
        rcwsoftmask[126:125,120:119,107:101,90:56,1:0] = Zeros{48};
        rcwsoftmask[114] = '0';
    end;

    //RCW Checks
    //State Check
    if (<a link="func_ProtectionEnabled_1" file="shared_pseudocode.xml">ProtectionEnabled</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL)) then
        if old[protectedbit] == '1' then
            rcw_state_fail = new[protectedbit,0] != old[protectedbit,0];
        elsif old[protectedbit] == '0' then
            rcw_state_fail = new[protectedbit] != old[protectedbit];
        end;
    end;

    //Mask Check
    if (<a link="func_ProtectionEnabled_1" file="shared_pseudocode.xml">ProtectionEnabled</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL)) then
        if old[protectedbit,0] == '11' then
            rcw_mask_fail = !IsZero((new XOR old) AND NOT(rcwmask));
        end;
    end;

    //RCWS Checks
    if soft then
        //State Check
        if old[0] == '1' then
            rcws_state_fail = new[0] != old[0];
        elsif (!<a link="func_ProtectionEnabled_1" file="shared_pseudocode.xml">ProtectionEnabled</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) ||
              (<a link="func_ProtectionEnabled_1" file="shared_pseudocode.xml">ProtectionEnabled</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) &amp;&amp; old[protectedbit] == '0')) then
            rcws_state_fail = new[0] != old[0] ;
        end;
        //Mask Check
        if old[0] == '1' then
            rcws_mask_fail = !IsZero((new XOR old) AND NOT(rcwsoftmask));
        end;
    end;

    rcw_fail = rcw_state_fail  || rcw_mask_fail ;
    rcws_fail = rcws_state_fail || rcws_mask_fail;

    let n : bit = '0';
    let z : bit = if rcw_fail then '1' else '0';
    let c : bit = if rcws_fail then '0' else '1';
    let v : bit = '0';
    return n::z::c::v;
end;</pstext></ps>
    <ps name="aarch64/functions/reduceop/FPReduce" mylink="aarch64.functions.reduceop.FPReduce" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPReduce()
// ==========
// Perform the floating-point operation 'op' on pairs of elements from the input vector,
// reducing the vector to a scalar result.

func <anchor link="func_FPReduce_5">FPReduce</anchor>{esize, N}(op : <a link="type_ReduceOp" file="shared_pseudocode.xml">ReduceOp</a>, input : bits(N),
                        fpcr : FPCR_Type) =&gt; bits(esize) recurselimit 8
begin
    var hi : bits(esize);
    var lo : bits(esize);
    var result : bits(esize);
    let half : integer{} = N DIV 2;

    if N == esize then
        return input[esize-1:0];
    end;

    hi = <a link="func_FPReduce_5" file="shared_pseudocode.xml">FPReduce</a>{esize, (N - N DIV 2)}(op, input[N-1:half], fpcr);
    lo = <a link="func_FPReduce_5" file="shared_pseudocode.xml">FPReduce</a>{esize, N DIV 2}(op, input[half-1:0], fpcr);
    case op of
        when <a link="enum_ReduceOp_FMINNUM" file="shared_pseudocode.xml">ReduceOp_FMINNUM</a> =&gt;
            result = <a link="func_FPMinNum_4" file="shared_pseudocode.xml">FPMinNum</a>{esize}(lo, hi, fpcr);
        when <a link="enum_ReduceOp_FMAXNUM" file="shared_pseudocode.xml">ReduceOp_FMAXNUM</a> =&gt;
            result = <a link="func_FPMaxNum_4" file="shared_pseudocode.xml">FPMaxNum</a>{esize}(lo, hi, fpcr);
        when <a link="enum_ReduceOp_FMIN" file="shared_pseudocode.xml">ReduceOp_FMIN</a> =&gt;
            result = <a link="func_FPMin_4" file="shared_pseudocode.xml">FPMin</a>{esize}(lo, hi, fpcr);
        when <a link="enum_ReduceOp_FMAX" file="shared_pseudocode.xml">ReduceOp_FMAX</a> =&gt;
            result = <a link="func_FPMax_4" file="shared_pseudocode.xml">FPMax</a>{esize}(lo, hi, fpcr);
        when <a link="enum_ReduceOp_FADD" file="shared_pseudocode.xml">ReduceOp_FADD</a> =&gt;
            result = <a link="func_FPAdd_4" file="shared_pseudocode.xml">FPAdd</a>{esize}(lo, hi, fpcr);
    end;

    return result;
end;</pstext></ps>
    <ps name="aarch64/functions/reduceop/IntReduce" mylink="aarch64.functions.reduceop.IntReduce" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IntReduce()
// ===========
// Perform the integer operation 'op' on pairs of elements from the input vector,
// reducing the vector to a scalar result.

func <anchor link="func_IntReduce_4">IntReduce</anchor>{esize, N}(op : <a link="type_ReduceOp" file="shared_pseudocode.xml">ReduceOp</a>, input : bits(N)) =&gt; bits(esize) recurselimit 8
begin
    var hi : bits(esize);
    var lo : bits(esize);
    var result : bits(esize);
    let half : integer{} = N DIV 2;
    if N == esize then
        return input[esize-1:0];
    end;

    hi = <a link="func_IntReduce_4" file="shared_pseudocode.xml">IntReduce</a>{esize, (N - N DIV 2)}(op, input[N-1:half]);
    lo = <a link="func_IntReduce_4" file="shared_pseudocode.xml">IntReduce</a>{esize, N DIV 2}(op, input[half-1:0]);
    case op of
        when <a link="enum_ReduceOp_ADD" file="shared_pseudocode.xml">ReduceOp_ADD</a> =&gt;
            result = lo + hi;
    end;

    return result;
end;</pstext></ps>
    <ps name="aarch64/functions/reduceop/ReduceOp" mylink="aarch64.functions.reduceop.ReduceOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ReduceOp
// ========
// Vector reduce instruction types.

type <anchor link="type_ReduceOp">ReduceOp</anchor> of enumeration {<anchor link="enum_ReduceOp_FMINNUM">ReduceOp_FMINNUM</anchor>, <anchor link="enum_ReduceOp_FMAXNUM">ReduceOp_FMAXNUM</anchor>,
                              <anchor link="enum_ReduceOp_FMIN">ReduceOp_FMIN</anchor>, <anchor link="enum_ReduceOp_FMAX">ReduceOp_FMAX</anchor>,
                              <anchor link="enum_ReduceOp_FADD">ReduceOp_FADD</anchor>, <anchor link="enum_ReduceOp_ADD">ReduceOp_ADD</anchor>};</pstext></ps>
    <ps name="aarch64/functions/registers/AArch64_MaybeZeroRegisterUppers" mylink="aarch64.functions.registers.AArch64_MaybeZeroRegisterUppers" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_MaybeZeroRegisterUppers()
// =================================
// On taking an exception to  AArch64 from AArch32, it is CONSTRAINED UNPREDICTABLE whether the top
// 32 bits of registers visible at any lower Exception level using AArch32 are set to zero.

func <anchor link="func_AArch64_MaybeZeroRegisterUppers_0">AArch64_MaybeZeroRegisterUppers</anchor>()
begin
    assert <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>();         // Always called from AArch32 state before entering AArch64 state

    var first : integer;
    var last : integer;
    var include_R15 : boolean;
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        first = 0;  last = 14;  include_R15 = FALSE;
    elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        first = 0;  last = 30;  include_R15 = FALSE;
    else
        first = 0;  last = 30;  include_R15 = TRUE;
    end;

    for n = first to last do
        if (n != 15 || include_R15) &amp;&amp; <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_ZEROUPPER" file="shared_pseudocode.xml">Unpredictable_ZEROUPPER</a>) then
            <a link="global__R" file="shared_pseudocode.xml">_R</a>[[n]][63:32] = Zeros{32};
        end;
    end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/registers/AArch64_ResetGeneralRegisters" mylink="aarch64.functions.registers.AArch64_ResetGeneralRegisters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ResetGeneralRegisters()
// ===============================

func <anchor link="func_AArch64_ResetGeneralRegisters_0">AArch64_ResetGeneralRegisters</anchor>()
begin

    for i = 0 to 30 do
        <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(i) = ARBITRARY : bits(64);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/registers/AArch64_ResetSIMDFPRegisters" mylink="aarch64.functions.registers.AArch64_ResetSIMDFPRegisters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ResetSIMDFPRegisters()
// ==============================

func <anchor link="func_AArch64_ResetSIMDFPRegisters_0">AArch64_ResetSIMDFPRegisters</anchor>()
begin

    for i = 0 to 31 do
        <a link="accessor_V_2" file="shared_pseudocode.xml">V</a>{128}(i) = ARBITRARY : bits(128);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/registers/AArch64_ResetSpecialRegisters" mylink="aarch64.functions.registers.AArch64_ResetSpecialRegisters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ResetSpecialRegisters()
// ===============================

func <anchor link="func_AArch64_ResetSpecialRegisters_0">AArch64_ResetSpecialRegisters</anchor>()
begin

    // AArch64 special registers
    SP_EL0()       = ARBITRARY : bits(64);
    SP_EL1()       = ARBITRARY : bits(64);

    SPSR_EL1()     = ARBITRARY : bits(64);
    ELR_EL1()      = ARBITRARY : bits(64);
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        SP_EL2()   = ARBITRARY : bits(64);
        SPSR_EL2() = ARBITRARY : bits(64);
        ELR_EL2()  = ARBITRARY : bits(64);
    end;


    // AArch32 special registers that are not architecturally mapped to AArch64 registers
    if <a link="func_HaveAArch32EL_1" file="shared_pseudocode.xml">HaveAArch32EL</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        SPSR_fiq()[31:0] = ARBITRARY : bits(32);
        SPSR_irq()[31:0] = ARBITRARY : bits(32);
        SPSR_abt()[31:0] = ARBITRARY : bits(32);
        SPSR_und()[31:0] = ARBITRARY : bits(32);
    end;

    // External debug special registers
    DLR_EL0()   = ARBITRARY : bits(64);
    DSPSR_EL0() = ARBITRARY : bits(64);

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/registers/AArch64_ResetSystemRegisters" mylink="aarch64.functions.registers.AArch64_ResetSystemRegisters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ResetSystemRegisters()
// ==============================

impdef func AArch64_ResetSystemRegisters(cold_reset : boolean)
begin
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/registers/PC64" mylink="aarch64.functions.registers.PC64" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PC64 - getter
// =============
// Read 64-bit program counter.

func <anchor link="func_PC64_0">PC64</anchor>() =&gt; bits(64)
begin
    return <a link="global__PC" file="shared_pseudocode.xml">_PC</a>;
end;</pstext></ps>
    <ps name="aarch64/functions/registers/SP" mylink="aarch64.functions.registers.SP" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SP - accessor
// =============

accessor <anchor link="accessor_SP_1">SP</anchor>{width}() &lt;=&gt; value : bits(width)
begin
    // Write a 32-bit or 64-bit value to the current stack pointer.
    setter
        assert width IN {64, 32};
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SP == '0' then
            SP_EL0() = ZeroExtend{64}(value);
        else
            case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL of
                when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;  SP_EL0() = ZeroExtend{64}(value);
                when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;  SP_EL1() = ZeroExtend{64}(value);
                when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;  SP_EL2() = ZeroExtend{64}(value);
                when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;  SP_EL3() = ZeroExtend{64}(value);
            end;
        end;
    end;

    // Read the least-significant 32 or 64 bits from the current stack pointer.
    getter
        assert width IN {64, 32};
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SP == '0' then
            return SP_EL0()[width-1:0];
        else
            case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL of
                when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;  return SP_EL0()[width-1:0];
                when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;  return SP_EL1()[width-1:0];
                when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;  return SP_EL2()[width-1:0];
                when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;  return SP_EL3()[width-1:0];
            end;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/registers/X" mylink="aarch64.functions.registers.X" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// X - accessor
// ============

accessor <anchor link="accessor_X_2">X</anchor>{width}(n : integer) &lt;=&gt; value : bits(width)
begin
    // Write a 32-bit or 64-bit value to a general-purpose register.
    setter
        assert n &gt;= 0 &amp;&amp; n &lt;= 31;
        assert width IN {32,64};
        if n != 31 then
            <a link="global__R" file="shared_pseudocode.xml">_R</a>[[n]] = ZeroExtend{64}(value);
        end;
        return;
    end;

    // Read the least-significant 8, 16, 32, or 64 bits from a general-purpose register.
    getter
        assert n &gt;= 0 &amp;&amp; n &lt;= 31;
        let rw : integer{} = width as integer{8, 16, 32, 64};
        if n != 31 then
            return <a link="global__R" file="shared_pseudocode.xml">_R</a>[[n]][rw-1:0];
        else
            return Zeros{rw};
        end;
    end;
end;

// X - accessor
// ============

accessor <anchor link="accessor_X_3">X</anchor>{width}(lr : integer, hr : integer) &lt;=&gt; value : bits(width)
begin
    // Write a 128-bit value to two general-purpose registers.
    setter
        assert width == 128;
        let half : integer{} = width DIV 2;
        <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{half}(lr)          = value[0+:half];
        <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{half}(hr)          = value[half+:half];
        return;
    end;

    // Read 128 bits from two separate general-purpose registers.
    getter
        assert width == 128;
        let half : integer{} = width DIV 2;
        return <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{half}(hr) :: <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{half}(lr);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/shiftreg/DecodeShift" mylink="aarch64.functions.shiftreg.DecodeShift" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodeShift()
// =============
// Decode shift encodings

func <anchor link="func_DecodeShift_1">DecodeShift</anchor>(op : bits(2)) =&gt; <a link="type_ShiftType" file="shared_pseudocode.xml">ShiftType</a>
begin
    case op of
        when '00' =&gt;  return <a link="enum_ShiftType_LSL" file="shared_pseudocode.xml">ShiftType_LSL</a>;
        when '01' =&gt;  return <a link="enum_ShiftType_LSR" file="shared_pseudocode.xml">ShiftType_LSR</a>;
        when '10' =&gt;  return <a link="enum_ShiftType_ASR" file="shared_pseudocode.xml">ShiftType_ASR</a>;
        when '11' =&gt;  return <a link="enum_ShiftType_ROR" file="shared_pseudocode.xml">ShiftType_ROR</a>;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/shiftreg/ShiftReg" mylink="aarch64.functions.shiftreg.ShiftReg" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ShiftReg()
// ==========
// Perform shift of a register operand

func <anchor link="func_ShiftReg_4">ShiftReg</anchor>{N}(reg : integer, shiftype : <a link="type_ShiftType" file="shared_pseudocode.xml">ShiftType</a>, amount : integer) =&gt; bits(N)
begin
    var result : bits(N) = X{}(reg);
    case shiftype of
        when <a link="enum_ShiftType_LSL" file="shared_pseudocode.xml">ShiftType_LSL</a> =&gt; result = LSL(result, amount);
        when <a link="enum_ShiftType_LSR" file="shared_pseudocode.xml">ShiftType_LSR</a> =&gt; result = LSR(result, amount);
        when <a link="enum_ShiftType_ASR" file="shared_pseudocode.xml">ShiftType_ASR</a> =&gt; result = ASR(result, amount);
        when <a link="enum_ShiftType_ROR" file="shared_pseudocode.xml">ShiftType_ROR</a> =&gt; result = ROR(result, amount);
    end;
    return result;
end;</pstext></ps>
    <ps name="aarch64/functions/shiftreg/ShiftType" mylink="aarch64.functions.shiftreg.ShiftType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ShiftType
// =========
// AArch64 register shifts.

type <anchor link="type_ShiftType">ShiftType</anchor> of enumeration {<anchor link="enum_ShiftType_LSL">ShiftType_LSL</anchor>, <anchor link="enum_ShiftType_LSR">ShiftType_LSR</anchor>, <anchor link="enum_ShiftType_ASR">ShiftType_ASR</anchor>, <anchor link="enum_ShiftType_ROR">ShiftType_ROR</anchor>};</pstext></ps>
    <ps name="aarch64/functions/sme/CounterToPredicate" mylink="aarch64.functions.sme.CounterToPredicate" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CounterToPredicate()
// ====================

func <anchor link="func_CounterToPredicate_2">CounterToPredicate</anchor>{width}(pred : bits(16)) =&gt; bits(width)
begin
    var count : integer;
    var esize : <a link="type_ESize" file="shared_pseudocode.xml">ESize</a>;
    var elements : integer;
    let VL : <a link="type_VecLen" file="shared_pseudocode.xml">VecLen</a>  = <a link="func_CurrentVL_0" file="shared_pseudocode.xml">CurrentVL</a>();
    let PL : <a link="type_PredLen" file="shared_pseudocode.xml">PredLen</a> = VL DIV 8;
    let maxbit : integer{} = FloorLog2(PL * 4) as integer{0..14};
    var result : bits(PL*4);
    let invert : boolean = pred[15] == '1';

    assert width == PL || width == PL*2 || width == PL*3 || width == PL*4;

    case pred[3:0] of
        when '0000' =&gt;
            return Zeros{width};
        when 'xxx1' =&gt;
            count = UInt(pred[maxbit:1]);
            esize = 8;
        when 'xx10' =&gt;
            count = UInt(pred[maxbit:2]);
            esize = 16;
        when 'x100' =&gt;
            count = UInt(pred[maxbit:3]);
            esize = 32;
        when '1000' =&gt;
            count = UInt(pred[maxbit:4]);
            esize = 64;
    end;

    elements = (VL * 4) DIV esize;
    result = Zeros{PL*4};
    let psize : integer{} = esize DIV 8;
    for e = 0 to elements-1 do
        var pbit : bit = if e &lt; count then '1' else '0';
        if invert then
            pbit = NOT(pbit);
        end;
        result[e*:psize] = ZeroExtend{psize}(pbit);
    end;

    return result[width-1:0];
end;</pstext></ps>
    <ps name="aarch64/functions/sme/EncodePredCount" mylink="aarch64.functions.sme.EncodePredCount" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EncodePredCount()
// =================

func <anchor link="func_EncodePredCount_5">EncodePredCount</anchor>{width}(esize : <a link="type_ESize" file="shared_pseudocode.xml">ESize</a>, elements : integer,
                            count_in : integer, invert_in : boolean) =&gt; bits(width)
begin
    var count : integer  = count_in;
    var invert : boolean = invert_in;
    let PL : <a link="type_PredLen" file="shared_pseudocode.xml">PredLen</a> = <a link="func_CurrentVL_0" file="shared_pseudocode.xml">CurrentVL</a>() DIV 8;
    assert width == PL;
    assert count &gt;=0 &amp;&amp; count &lt;= elements;
    var pred : bits(16);

    if count == 0 then
        return Zeros{width};
    end;

    if invert then
        count = elements - count;
    elsif count == elements then
        count = 0;
        invert = TRUE;
    end;

    let inv : bit = (if invert then '1' else '0');
    case esize of
        when 8 =&gt;  pred = inv :: count[13:0] ::    '1';
        when 16 =&gt; pred = inv :: count[12:0] ::   '10';
        when 32 =&gt; pred = inv :: count[11:0] ::  '100';
        when 64 =&gt; pred = inv :: count[10:0] :: '1000';
    end;

    return ZeroExtend{width}(pred);
end;</pstext></ps>
    <ps name="aarch64/functions/sme/Lookup" mylink="aarch64.functions.sme.Lookup" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Lookup Table
// ============

var <anchor link="global__ZT0">_ZT0</anchor> : bits(<a link="global_ZT0_LEN" file="shared_pseudocode.xml">ZT0_LEN</a>);</pstext></ps>
    <ps name="aarch64/functions/sme/PredCountTest" mylink="aarch64.functions.sme.PredCountTest" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PredCountTest()
// ===============

func <anchor link="func_PredCountTest_3">PredCountTest</anchor>(elements : integer, count : integer, invert : boolean) =&gt; bits(4)
begin
    var n, z, c, v : bit;
    z = (if count == 0 then '1' else '0');              // none active
    if !invert then
        n = (if count != 0 then '1' else '0');          // first active
        c = (if count == elements then '0' else '1');   // NOT last active
    else
        n = (if count == elements then '1' else '0');   // first active
        c = (if count != 0 then '0' else '1');          // NOT last active
    end;
    v = '0';

    return n::z::c::v;
end;</pstext></ps>
    <ps name="aarch64/functions/sme/System" mylink="aarch64.functions.sme.System" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// System Registers
// ================

var <anchor link="global__ZA">_ZA</anchor> : array [[256]] of bits(<a link="global_MAX_VL" file="shared_pseudocode.xml">MAX_VL</a>);</pstext></ps>
    <ps name="aarch64/functions/sme/ZAhslice" mylink="aarch64.functions.sme.ZAhslice" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ZAhslice - accessor
// ===================

accessor <anchor link="accessor_ZAhslice_4">ZAhslice</anchor>{width}(tile : integer, esize : <a link="type_ESize" file="shared_pseudocode.xml">ESize</a>, slice : integer) &lt;=&gt; value : bits(width)
begin
    getter
        let tiles : integer = esize DIV 8;
        assert tile &gt;= 0 &amp;&amp; tile &lt; tiles;
        let slices : integer = <a link="func_CurrentSVL_0" file="shared_pseudocode.xml">CurrentSVL</a>() DIV esize;
        assert slice &gt;= 0 &amp;&amp; slice &lt; slices;

        return <a link="accessor_ZAvector_2" file="shared_pseudocode.xml">ZAvector</a>{width}(tile + slice * tiles);
    end;
    setter
        let tiles : integer = esize DIV 8;
        assert tile &gt;= 0 &amp;&amp; tile &lt; tiles;
        let slices : integer = <a link="func_CurrentSVL_0" file="shared_pseudocode.xml">CurrentSVL</a>() DIV esize;
        assert slice &gt;= 0 &amp;&amp; slice &lt; slices;

        <a link="accessor_ZAvector_2" file="shared_pseudocode.xml">ZAvector</a>{width}(tile + slice * tiles) = value;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sme/ZAslice" mylink="aarch64.functions.sme.ZAslice" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ZAslice - accessor
// ==================

accessor <anchor link="accessor_ZAslice_5">ZAslice</anchor>{width}(tile : integer, esize : <a link="type_ESize" file="shared_pseudocode.xml">ESize</a>,
                        vertical : boolean, slice : integer) &lt;=&gt; value : bits(width)
begin
    getter
        var result : bits(width);

        if vertical then
            result = <a link="accessor_ZAvslice_4" file="shared_pseudocode.xml">ZAvslice</a>{width}(tile, esize, slice);
        else
            result = <a link="accessor_ZAhslice_4" file="shared_pseudocode.xml">ZAhslice</a>{width}(tile, esize, slice);
        end;

        return result;
    end;
    setter
        if vertical then
            <a link="accessor_ZAvslice_4" file="shared_pseudocode.xml">ZAvslice</a>{width}(tile, esize, slice) = value;
        else
            <a link="accessor_ZAhslice_4" file="shared_pseudocode.xml">ZAhslice</a>{width}(tile, esize, slice) = value;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sme/ZAtile" mylink="aarch64.functions.sme.ZAtile" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ZAtile - accessor
// =================

accessor <anchor link="accessor_ZAtile_3">ZAtile</anchor>{width}(tile : integer, esize : <a link="type_ESize" file="shared_pseudocode.xml">ESize</a>) &lt;=&gt; value : bits(width)
begin
    getter
        let SVL : <a link="type_VecLen" file="shared_pseudocode.xml">VecLen</a> = <a link="func_CurrentSVL_0" file="shared_pseudocode.xml">CurrentSVL</a>();
        let slices : integer = SVL DIV esize;
        assert width == SVL * slices;
        var result : bits(width);

        for slice = 0 to slices-1 do
            result[slice*:SVL] = <a link="accessor_ZAhslice_4" file="shared_pseudocode.xml">ZAhslice</a>{SVL}(tile, esize, slice);
        end;

        return result;
    end;
    setter
        let SVL : <a link="type_VecLen" file="shared_pseudocode.xml">VecLen</a> = <a link="func_CurrentSVL_0" file="shared_pseudocode.xml">CurrentSVL</a>();
        let slices : integer = SVL DIV esize;
        assert width == SVL * slices;

        for slice = 0 to slices-1 do
            <a link="accessor_ZAhslice_4" file="shared_pseudocode.xml">ZAhslice</a>{SVL}(tile, esize, slice) = value[slice*:SVL];
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sme/ZAvector" mylink="aarch64.functions.sme.ZAvector" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ZAvector - accessor
// ===================

accessor <anchor link="accessor_ZAvector_2">ZAvector</anchor>{width}(index : integer) &lt;=&gt; value : bits(width)
begin
    getter
        assert width == <a link="func_CurrentSVL_0" file="shared_pseudocode.xml">CurrentSVL</a>();
        assert index &gt;= 0 &amp;&amp; index &lt; (width DIV 8);

        return <a link="global__ZA" file="shared_pseudocode.xml">_ZA</a>[[index]][width-1:0];
    end;

    setter
        assert width == <a link="func_CurrentSVL_0" file="shared_pseudocode.xml">CurrentSVL</a>();
        assert index &gt;= 0 &amp;&amp; index &lt; (width DIV 8);

        if <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_SMEZEROUPPER" file="shared_pseudocode.xml">Unpredictable_SMEZEROUPPER</a>) then
            <a link="global__ZA" file="shared_pseudocode.xml">_ZA</a>[[index]] = ZeroExtend{<a link="global_MAX_VL" file="shared_pseudocode.xml">MAX_VL</a>}(value);
        else
            <a link="global__ZA" file="shared_pseudocode.xml">_ZA</a>[[index]][width-1:0] = value;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sme/ZAvslice" mylink="aarch64.functions.sme.ZAvslice" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ZAvslice - accessor
// ===================

accessor <anchor link="accessor_ZAvslice_4">ZAvslice</anchor>{width}(tile : integer, esize : <a link="type_ESize" file="shared_pseudocode.xml">ESize</a>, slice : integer) &lt;=&gt; value : bits(width)
begin
    getter
        let slices : integer = <a link="func_CurrentSVL_0" file="shared_pseudocode.xml">CurrentSVL</a>() DIV esize;
        var result : bits(width);

        for s = 0 to slices-1 do
            let hslice : bits(width) = ZAhslice{}(tile, esize, s);
            result[s*:esize] = hslice[slice*:esize];
        end;

        return result;
    end;

    setter
        let slices : integer = <a link="func_CurrentSVL_0" file="shared_pseudocode.xml">CurrentSVL</a>() DIV esize;

        for s = 0 to slices-1 do
            var hslice : bits(width) = ZAhslice{}(tile, esize, s);
            hslice[slice*:esize] = value[s*:esize];
            <a link="accessor_ZAhslice_4" file="shared_pseudocode.xml">ZAhslice</a>{width}(tile, esize, s) = hslice;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sme/ZT0" mylink="aarch64.functions.sme.ZT0" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ZT0 - accessor
// ==============

accessor <anchor link="accessor_ZT0_1">ZT0</anchor>{width}() &lt;=&gt; value : bits(width)
begin
    getter
        assert width == <a link="global_ZT0_LEN" file="shared_pseudocode.xml">ZT0_LEN</a>;
        return <a link="global__ZT0" file="shared_pseudocode.xml">_ZT0</a>[width-1:0];
    end;
    setter
        assert width == <a link="global_ZT0_LEN" file="shared_pseudocode.xml">ZT0_LEN</a>;
        <a link="global__ZT0" file="shared_pseudocode.xml">_ZT0</a>[width-1:0] = value;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/AArch32_IsFPEnabled" mylink="aarch64.functions.sve.AArch32_IsFPEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_IsFPEnabled()
// =====================
// Returns TRUE if access to the SIMD&amp;FP instructions or System registers are
// enabled at the target exception level in AArch32 state and FALSE otherwise.

func <anchor link="func_AArch32_IsFPEnabled_1">AArch32_IsFPEnabled</anchor>(el : bits(2)) =&gt; boolean
begin
    if el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        return <a link="func_AArch64_IsFPEnabled_1" file="shared_pseudocode.xml">AArch64_IsFPEnabled</a>(el);
    end;

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() == <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> then
        // Check if access disabled in NSACR
        if NSACR().cp10 == '0' then return FALSE; end;
    end;

    if el IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} then
        // Check if access disabled in CPACR
        var disabled : boolean;
        case CPACR().cp10 of
            when '00' =&gt; disabled = TRUE;
            when '01' =&gt; disabled = el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
            when '10' =&gt; disabled = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_RESCPACR" file="shared_pseudocode.xml">Unpredictable_RESCPACR</a>);
            when '11' =&gt; disabled = FALSE;
        end;
        if disabled then return FALSE; end;
    end;

    if el IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        if !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
            return <a link="func_AArch64_IsFPEnabled_1" file="shared_pseudocode.xml">AArch64_IsFPEnabled</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
        end;
        if HCPTR().TCP10 == '1' then return FALSE; end;
    end;

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        // Check if access disabled in CPTR_EL3
        if CPTR_EL3().TFP == '1' then return FALSE; end;
    end;

    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/AArch64_IsFPEnabled" mylink="aarch64.functions.sve.AArch64_IsFPEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_IsFPEnabled()
// =====================
// Returns TRUE if access to the SIMD&amp;FP instructions or System registers are
// enabled at the target exception level in AArch64 state and FALSE otherwise.

func <anchor link="func_AArch64_IsFPEnabled_1">AArch64_IsFPEnabled</anchor>(el : bits(2)) =&gt; boolean
begin
    // Check if access disabled in CPACR_EL1
    if el IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
        // Check SIMD&amp;FP at EL0/EL1
        var disabled : boolean;
        case CPACR_EL1().FPEN of
            when 'x0' =&gt; disabled = TRUE;
            when '01' =&gt; disabled = el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
            when '11' =&gt; disabled = FALSE;
        end;
        if disabled then return FALSE; end;
    end;

    // Check if access disabled in CPTR_EL2
    if el IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
            var disabled : boolean;
            case CPTR_EL2().FPEN of
                when 'x0' =&gt; disabled = TRUE;
                when '01' =&gt; disabled = el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; HCR_EL2().TGE == '1';
                when '11' =&gt; disabled = FALSE;
            end;
            if disabled then return FALSE; end;
        else
            if CPTR_EL2().TFP == '1' then return FALSE; end;
        end;
    end;

    // Check if access disabled in CPTR_EL3
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        if CPTR_EL3().TFP == '1' then return FALSE; end;
    end;

    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/ActivePredicateElement" mylink="aarch64.functions.sve.ActivePredicateElement" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ActivePredicateElement()
// ========================
// Returns TRUE if the predicate bit is 1 and FALSE otherwise

func <anchor link="func_ActivePredicateElement_4">ActivePredicateElement</anchor>{N}(pred : bits(N), e : integer, esize : integer) =&gt; boolean
begin
    assert esize IN {8, 16, 32, 64, 128};
    let n : integer = e * (esize DIV 8);
    assert n &gt;= 0 &amp;&amp; n &lt; N;
    return pred[n] == '1';
end;</pstext></ps>
    <ps name="aarch64/functions/sve/AllElementsActive" mylink="aarch64.functions.sve.AllElementsActive" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AllElementsActive()
// ===================
// Return TRUE if all the elements are active in the mask. Otherwise,
// return FALSE.

func <anchor link="func_AllElementsActive_3">AllElementsActive</anchor>{N}(mask : bits(N), esize : integer) =&gt; boolean
begin
    let elements : integer = N DIV (esize DIV 8);
    var active : integer = 0;
    for e = 0 to elements-1 do
        if <a link="func_ActivePredicateElement_4" file="shared_pseudocode.xml">ActivePredicateElement</a>{N}(mask, e, esize) then active = active + 1; end;
    end;
    return active == elements;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/AnyActiveElement" mylink="aarch64.functions.sve.AnyActiveElement" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AnyActiveElement()
// ==================
// Return TRUE if there is at least one active element in mask. Otherwise,
// return FALSE.

func <anchor link="func_AnyActiveElement_3">AnyActiveElement</anchor>{N}(mask : bits(N), esize : integer) =&gt; boolean
begin
    return <a link="func_LastActiveElement_3" file="shared_pseudocode.xml">LastActiveElement</a>{N}(mask, esize) &gt;= 0;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/BitDeposit" mylink="aarch64.functions.sve.BitDeposit" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BitDeposit()
// ============
// Deposit the least significant bits from DATA into result positions
// selected by nonzero bits in MASK, setting other result bits to zero.

func <anchor link="func_BitDeposit_3">BitDeposit</anchor>{N}(data : bits(N), mask : bits(N)) =&gt; bits(N)
begin
    var res : bits(N) = Zeros{};
    var db : integer = 0;
    for rb = 0 to N-1 do
        if mask[rb] == '1' then
            res[rb] = data[db];
            db      = db + 1;
        end;
    end;
    return res;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/BitExtract" mylink="aarch64.functions.sve.BitExtract" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BitExtract()
// ============
// Extract and pack DATA bits selected by the nonzero bits in MASK into
// the least significant result bits, setting other result bits to zero.

func <anchor link="func_BitExtract_3">BitExtract</anchor>{N}(data : bits(N), mask : bits(N)) =&gt; bits(N)
begin
    var res : bits(N) = Zeros{};
    var rb : integer = 0;
    for db = 0 to N-1 do
        if mask[db] == '1' then
            res[rb] = data[db];
            rb      = rb + 1;
        end;
    end;
    return res;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/BitGroup" mylink="aarch64.functions.sve.BitGroup" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BitGroup()
// ==========
// Extract and pack DATA bits selected by the nonzero bits in MASK into
// the least significant result bits, and pack unselected bits into the
// most significant result bits.

func <anchor link="func_BitGroup_3">BitGroup</anchor>{N}(data : bits(N), mask : bits(N)) =&gt; bits(N)
begin
    var res : bits(N);
    var rb : integer = 0;

    // compress masked bits to right
    for db = 0 to N-1 do
        if mask[db] == '1' then
            res[rb] = data[db];
            rb      = rb + 1;
        end;
    end;
    // compress unmasked bits to left
    for db = 0 to N-1 do
        if mask[db] == '0' then
            res[rb] = data[db];
            rb      = rb + 1;
        end;
    end;
    return res;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/CheckNonStreamingSVEEnabled" mylink="aarch64.functions.sve.CheckNonStreamingSVEEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckNonStreamingSVEEnabled()
// =============================
// Checks for traps on SVE instructions that are not legal when executed in Streaming mode.

func <anchor link="func_CheckNonStreamingSVEEnabled_0">CheckNonStreamingSVEEnabled</anchor>()
begin
    <a link="func_CheckSVEEnabled_0" file="shared_pseudocode.xml">CheckSVEEnabled</a>();

    if IsFeatureImplemented(FEAT_SME) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM == '1' &amp;&amp; !<a link="func_IsFullA64Enabled_0" file="shared_pseudocode.xml">IsFullA64Enabled</a>() then
        <a link="func_SMEAccessTrap_2" file="shared_pseudocode.xml">SMEAccessTrap</a>(<a link="enum_SMEExceptionType_Streaming" file="shared_pseudocode.xml">SMEExceptionType_Streaming</a>, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/CheckOriginalSVEEnabled" mylink="aarch64.functions.sve.CheckOriginalSVEEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckOriginalSVEEnabled()
// =========================
// Checks for traps on SVE instructions and instructions that access SVE System
// registers.

func <anchor link="func_CheckOriginalSVEEnabled_0">CheckOriginalSVEEnabled</anchor>()
begin
    assert IsFeatureImplemented(FEAT_SVE);
    var disabled : boolean;

    if (<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; (CPTR_EL3().EZ == '0' || CPTR_EL3().TFP == '1') &amp;&amp;
          <a link="func_EL3SDDUndefPriority_0" file="shared_pseudocode.xml">EL3SDDUndefPriority</a>()) then
        Undefined();
    end;

    // Check if access disabled in CPACR_EL1
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
        // Check SVE at EL0/EL1
        case CPACR_EL1().ZEN of
            when 'x0' =&gt; disabled = TRUE;
            when '01' =&gt; disabled = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
            when '11' =&gt; disabled = FALSE;
        end;
        if disabled then <a link="func_SVEAccessTrap_1" file="shared_pseudocode.xml">SVEAccessTrap</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>); end;

        // Check SIMD&amp;FP at EL0/EL1
        case CPACR_EL1().FPEN of
            when 'x0' =&gt; disabled = TRUE;
            when '01' =&gt; disabled = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
            when '11' =&gt; disabled = FALSE;
        end;
        if disabled then <a link="func_AArch64_AdvSIMDFPAccessTrap_1" file="shared_pseudocode.xml">AArch64_AdvSIMDFPAccessTrap</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>); end;
    end;

    // Check if access disabled in CPTR_EL2
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
            // Check SVE at EL2
            case CPTR_EL2().ZEN of
                when 'x0' =&gt; disabled = TRUE;
                when '01' =&gt; disabled = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; HCR_EL2().TGE == '1';
                when '11' =&gt; disabled = FALSE;
            end;
            if disabled then <a link="func_SVEAccessTrap_1" file="shared_pseudocode.xml">SVEAccessTrap</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>); end;

            // Check SIMD&amp;FP at EL2
            case CPTR_EL2().FPEN of
                when 'x0' =&gt; disabled = TRUE;
                when '01' =&gt; disabled = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; HCR_EL2().TGE == '1';
                when '11' =&gt; disabled = FALSE;
            end;
            if disabled then <a link="func_AArch64_AdvSIMDFPAccessTrap_1" file="shared_pseudocode.xml">AArch64_AdvSIMDFPAccessTrap</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>); end;
        else
            if CPTR_EL2().TZ == '1'  then <a link="func_SVEAccessTrap_1" file="shared_pseudocode.xml">SVEAccessTrap</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>); end;
            if CPTR_EL2().TFP == '1' then <a link="func_AArch64_AdvSIMDFPAccessTrap_1" file="shared_pseudocode.xml">AArch64_AdvSIMDFPAccessTrap</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>); end;
        end;
    end;

    // Check if access disabled in CPTR_EL3
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        if CPTR_EL3().EZ == '0' then
            if <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then Undefined(); end;
            <a link="func_SVEAccessTrap_1" file="shared_pseudocode.xml">SVEAccessTrap</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
        end;

        if CPTR_EL3().TFP == '1' then
            if <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then Undefined(); end;
            <a link="func_AArch64_AdvSIMDFPAccessTrap_1" file="shared_pseudocode.xml">AArch64_AdvSIMDFPAccessTrap</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/CheckSMEAccess" mylink="aarch64.functions.sve.CheckSMEAccess" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckSMEAccess()
// ================
// Check that access to SME System registers is enabled.

func <anchor link="func_CheckSMEAccess_0">CheckSMEAccess</anchor>()
begin
    var disabled : boolean;

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; CPTR_EL3().ESM == '0' &amp;&amp; <a link="func_EL3SDDUndefPriority_0" file="shared_pseudocode.xml">EL3SDDUndefPriority</a>() then
        Undefined();
    end;

    // Check if access disabled in CPACR_EL1
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
        // Check SME at EL0/EL1
        case CPACR_EL1().SMEN of
            when 'x0' =&gt; disabled = TRUE;
            when '01' =&gt; disabled = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
            when '11' =&gt; disabled = FALSE;
        end;
        if disabled then <a link="func_SMEAccessTrap_2" file="shared_pseudocode.xml">SMEAccessTrap</a>(<a link="enum_SMEExceptionType_AccessTrap" file="shared_pseudocode.xml">SMEExceptionType_AccessTrap</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>); end;
    end;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
            // Check SME at EL2
            case CPTR_EL2().SMEN of
                when 'x0' =&gt; disabled = TRUE;
                when '01' =&gt; disabled = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; HCR_EL2().TGE == '1';
                when '11' =&gt; disabled = FALSE;
            end;
            if disabled then <a link="func_SMEAccessTrap_2" file="shared_pseudocode.xml">SMEAccessTrap</a>(<a link="enum_SMEExceptionType_AccessTrap" file="shared_pseudocode.xml">SMEExceptionType_AccessTrap</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>); end;
        else
            if CPTR_EL2().TSM == '1' then <a link="func_SMEAccessTrap_2" file="shared_pseudocode.xml">SMEAccessTrap</a>(<a link="enum_SMEExceptionType_AccessTrap" file="shared_pseudocode.xml">SMEExceptionType_AccessTrap</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>); end;
        end;
    end;

    // Check if access disabled in CPTR_EL3
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        if CPTR_EL3().ESM == '0' then
            if <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then Undefined(); end;
            <a link="func_SMEAccessTrap_2" file="shared_pseudocode.xml">SMEAccessTrap</a>(<a link="enum_SMEExceptionType_AccessTrap" file="shared_pseudocode.xml">SMEExceptionType_AccessTrap</a>, <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/CheckSMEAndZAEnabled" mylink="aarch64.functions.sve.CheckSMEAndZAEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckSMEAndZAEnabled()
// ======================

func <anchor link="func_CheckSMEAndZAEnabled_0">CheckSMEAndZAEnabled</anchor>()
begin
    <a link="func_CheckSMEEnabled_0" file="shared_pseudocode.xml">CheckSMEEnabled</a>();

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.ZA == '0' then
        <a link="func_SMEAccessTrap_2" file="shared_pseudocode.xml">SMEAccessTrap</a>(<a link="enum_SMEExceptionType_InactiveZA" file="shared_pseudocode.xml">SMEExceptionType_InactiveZA</a>, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/CheckSMEEnabled" mylink="aarch64.functions.sve.CheckSMEEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckSMEEnabled()
// =================

func <anchor link="func_CheckSMEEnabled_0">CheckSMEEnabled</anchor>()
begin
    var disabled : boolean;

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; CPTR_EL3().[ESM,TFP] != '10' &amp;&amp; <a link="func_EL3SDDUndefPriority_0" file="shared_pseudocode.xml">EL3SDDUndefPriority</a>() then
        Undefined();
    end;

    // Check if access disabled in CPACR_EL1
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
        // Check SME at EL0/EL1
        case CPACR_EL1().SMEN of
            when 'x0' =&gt; disabled = TRUE;
            when '01' =&gt; disabled = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
            when '11' =&gt; disabled = FALSE;
        end;
        if disabled then <a link="func_SMEAccessTrap_2" file="shared_pseudocode.xml">SMEAccessTrap</a>(<a link="enum_SMEExceptionType_AccessTrap" file="shared_pseudocode.xml">SMEExceptionType_AccessTrap</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>); end;

        // Check SIMD&amp;FP at EL0/EL1
        case CPACR_EL1().FPEN of
            when 'x0' =&gt; disabled = TRUE;
            when '01' =&gt; disabled = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
            when '11' =&gt; disabled = FALSE;
        end;
        if disabled then <a link="func_AArch64_AdvSIMDFPAccessTrap_1" file="shared_pseudocode.xml">AArch64_AdvSIMDFPAccessTrap</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>); end;
    end;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
            // Check SME at EL2
            case CPTR_EL2().SMEN of
                when 'x0' =&gt; disabled = TRUE;
                when '01' =&gt; disabled = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; HCR_EL2().TGE == '1';
                when '11' =&gt; disabled = FALSE;
            end;
            if disabled then <a link="func_SMEAccessTrap_2" file="shared_pseudocode.xml">SMEAccessTrap</a>(<a link="enum_SMEExceptionType_AccessTrap" file="shared_pseudocode.xml">SMEExceptionType_AccessTrap</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>); end;

            // Check SIMD&amp;FP at EL2
            case CPTR_EL2().FPEN of
                when 'x0' =&gt; disabled = TRUE;
                when '01' =&gt; disabled = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; HCR_EL2().TGE == '1';
                when '11' =&gt; disabled = FALSE;
            end;
            if disabled then <a link="func_AArch64_AdvSIMDFPAccessTrap_1" file="shared_pseudocode.xml">AArch64_AdvSIMDFPAccessTrap</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>); end;
        else
            if CPTR_EL2().TSM == '1' then <a link="func_SMEAccessTrap_2" file="shared_pseudocode.xml">SMEAccessTrap</a>(<a link="enum_SMEExceptionType_AccessTrap" file="shared_pseudocode.xml">SMEExceptionType_AccessTrap</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>); end;
            if CPTR_EL2().TFP == '1' then <a link="func_AArch64_AdvSIMDFPAccessTrap_1" file="shared_pseudocode.xml">AArch64_AdvSIMDFPAccessTrap</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>); end;
        end;
    end;

    // Check if access disabled in CPTR_EL3
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        if CPTR_EL3().ESM == '0' then
            if <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then Undefined(); end;
            <a link="func_SMEAccessTrap_2" file="shared_pseudocode.xml">SMEAccessTrap</a>(<a link="enum_SMEExceptionType_AccessTrap" file="shared_pseudocode.xml">SMEExceptionType_AccessTrap</a>, <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
        end;

        if CPTR_EL3().TFP == '1' then
            if <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then Undefined(); end;
            <a link="func_AArch64_AdvSIMDFPAccessTrap_1" file="shared_pseudocode.xml">AArch64_AdvSIMDFPAccessTrap</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/CheckSMEZT0Enabled" mylink="aarch64.functions.sve.CheckSMEZT0Enabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckSMEZT0Enabled()
// ====================
// Checks for ZT0 enabled.

func <anchor link="func_CheckSMEZT0Enabled_0">CheckSMEZT0Enabled</anchor>()
begin
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SMCR_EL3().EZT0 == '0' &amp;&amp; <a link="func_EL3SDDUndefPriority_0" file="shared_pseudocode.xml">EL3SDDUndefPriority</a>() then
        Undefined();
    end;

    // Check if ZA and ZT0 are inactive in PSTATE
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.ZA == '0' then
        <a link="func_SMEAccessTrap_2" file="shared_pseudocode.xml">SMEAccessTrap</a>(<a link="enum_SMEExceptionType_InactiveZA" file="shared_pseudocode.xml">SMEExceptionType_InactiveZA</a>, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    end;

    // Check if EL0/EL1 accesses to ZT0 are disabled in SMCR_EL1
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
        if SMCR_EL1().EZT0 == '0' then
            <a link="func_SMEAccessTrap_2" file="shared_pseudocode.xml">SMEAccessTrap</a>(<a link="enum_SMEExceptionType_InaccessibleZT0" file="shared_pseudocode.xml">SMEExceptionType_InaccessibleZT0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>);
        end;
    end;

    // Check if EL0/EL1/EL2 accesses to ZT0 are disabled in SMCR_EL2
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        if SMCR_EL2().EZT0 == '0' then
            <a link="func_SMEAccessTrap_2" file="shared_pseudocode.xml">SMEAccessTrap</a>(<a link="enum_SMEExceptionType_InaccessibleZT0" file="shared_pseudocode.xml">SMEExceptionType_InaccessibleZT0</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
        end;
    end;

    // Check if all accesses to ZT0 are disabled in SMCR_EL3
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        if SMCR_EL3().EZT0 == '0' then
            if <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then Undefined(); end;
            <a link="func_SMEAccessTrap_2" file="shared_pseudocode.xml">SMEAccessTrap</a>(<a link="enum_SMEExceptionType_InaccessibleZT0" file="shared_pseudocode.xml">SMEExceptionType_InaccessibleZT0</a>, <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/CheckSVEEnabled" mylink="aarch64.functions.sve.CheckSVEEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckSVEEnabled()
// =================
// Checks for traps on SVE instructions and instructions that
// access SVE System registers.

func <anchor link="func_CheckSVEEnabled_0">CheckSVEEnabled</anchor>()
begin
    if IsFeatureImplemented(FEAT_SME) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM == '1' then
        <a link="func_CheckSMEEnabled_0" file="shared_pseudocode.xml">CheckSMEEnabled</a>();
    elsif IsFeatureImplemented(FEAT_SME) &amp;&amp; !IsFeatureImplemented(FEAT_SVE) then
        <a link="func_CheckStreamingSVEEnabled_0" file="shared_pseudocode.xml">CheckStreamingSVEEnabled</a>();
    else
        <a link="func_CheckOriginalSVEEnabled_0" file="shared_pseudocode.xml">CheckOriginalSVEEnabled</a>();
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/CheckStreamingSVEAndZAEnabled" mylink="aarch64.functions.sve.CheckStreamingSVEAndZAEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckStreamingSVEAndZAEnabled()
// ===============================

func <anchor link="func_CheckStreamingSVEAndZAEnabled_0">CheckStreamingSVEAndZAEnabled</anchor>()
begin
    <a link="func_CheckStreamingSVEEnabled_0" file="shared_pseudocode.xml">CheckStreamingSVEEnabled</a>();

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.ZA == '0' then
        <a link="func_SMEAccessTrap_2" file="shared_pseudocode.xml">SMEAccessTrap</a>(<a link="enum_SMEExceptionType_InactiveZA" file="shared_pseudocode.xml">SMEExceptionType_InactiveZA</a>, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/CheckStreamingSVEEnabled" mylink="aarch64.functions.sve.CheckStreamingSVEEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckStreamingSVEEnabled()
// ==========================

func <anchor link="func_CheckStreamingSVEEnabled_0">CheckStreamingSVEEnabled</anchor>()
begin
    <a link="func_CheckSMEEnabled_0" file="shared_pseudocode.xml">CheckSMEEnabled</a>();

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM == '0' then
        <a link="func_SMEAccessTrap_2" file="shared_pseudocode.xml">SMEAccessTrap</a>(<a link="enum_SMEExceptionType_NotStreaming" file="shared_pseudocode.xml">SMEExceptionType_NotStreaming</a>, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/CmpOp" mylink="aarch64.functions.sve.CmpOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CmpOp
// =====

type <anchor link="type_CmpOp">CmpOp</anchor> of enumeration { <anchor link="enum_Cmp_EQ">Cmp_EQ</anchor>, <anchor link="enum_Cmp_NE">Cmp_NE</anchor>, <anchor link="enum_Cmp_GE">Cmp_GE</anchor>, <anchor link="enum_Cmp_GT">Cmp_GT</anchor>, <anchor link="enum_Cmp_LT">Cmp_LT</anchor>, <anchor link="enum_Cmp_LE">Cmp_LE</anchor>, <anchor link="enum_Cmp_UN">Cmp_UN</anchor> };</pstext></ps>
    <ps name="aarch64/functions/sve/CurrentNSVL" mylink="aarch64.functions.sve.CurrentNSVL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CurrentNSVL
// ===========
// Non-Streaming VL

readonly func <anchor link="func_CurrentNSVL_0">CurrentNSVL</anchor>() =&gt; <a link="type_VecLen" file="shared_pseudocode.xml">VecLen</a>
begin
    var vl : integer;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> || (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>()) then
        vl = UInt(ZCR_EL1().LEN);
    end;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>()) then
        vl = UInt(ZCR_EL2().LEN);
    elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        vl = Min(vl, UInt(ZCR_EL2().LEN));
    end;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then
        vl = UInt(ZCR_EL3().LEN);
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        vl = Min(vl, UInt(ZCR_EL3().LEN));
    end;

    return <a link="func_ImplementedSVEVectorLength_1" file="shared_pseudocode.xml">ImplementedSVEVectorLength</a>((vl + 1) * 128);
end;</pstext></ps>
    <ps name="aarch64/functions/sve/CurrentSVL" mylink="aarch64.functions.sve.CurrentSVL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CurrentSVL
// ==========
// Streaming SVL

readonly func <anchor link="func_CurrentSVL_0">CurrentSVL</anchor>() =&gt; <a link="type_VecLen" file="shared_pseudocode.xml">VecLen</a>
begin
    var vl : integer;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> || (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>()) then
        vl = UInt(SMCR_EL1().LEN);
    end;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>()) then
        vl = UInt(SMCR_EL2().LEN);
    elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        vl = Min(vl, UInt(SMCR_EL2().LEN));
    end;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then
        vl = UInt(SMCR_EL3().LEN);
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        vl = Min(vl, UInt(SMCR_EL3().LEN));
    end;

    return <a link="func_ImplementedSMEVectorLength_1" file="shared_pseudocode.xml">ImplementedSMEVectorLength</a>((vl + 1) * 128);
end;</pstext></ps>
    <ps name="aarch64/functions/sve/CurrentVL" mylink="aarch64.functions.sve.CurrentVL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CurrentVL
// =========

readonly func <anchor link="func_CurrentVL_0">CurrentVL</anchor>() =&gt; <a link="type_VecLen" file="shared_pseudocode.xml">VecLen</a>
begin
    return (if IsFeatureImplemented(FEAT_SME) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM == '1' then <a link="func_CurrentSVL_0" file="shared_pseudocode.xml">CurrentSVL</a>()
                                                                  else <a link="func_CurrentNSVL_0" file="shared_pseudocode.xml">CurrentNSVL</a>());
end;</pstext></ps>
    <ps name="aarch64/functions/sve/DecodePredCount" mylink="aarch64.functions.sve.DecodePredCount" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodePredCount()
// =================

func <anchor link="func_DecodePredCount_2">DecodePredCount</anchor>(bitpattern : bits(5), esize : integer) =&gt; integer
begin
    let elements : integer = <a link="func_CurrentVL_0" file="shared_pseudocode.xml">CurrentVL</a>() DIV esize;
    var numElem : integer;
    case bitpattern of
        when '00000' =&gt; numElem = FloorPow2(elements);
        when '00001' =&gt; numElem = if elements &gt;= 1 then 1 else 0;
        when '00010' =&gt; numElem = if elements &gt;= 2 then 2 else 0;
        when '00011' =&gt; numElem = if elements &gt;= 3 then 3 else 0;
        when '00100' =&gt; numElem = if elements &gt;= 4 then 4 else 0;
        when '00101' =&gt; numElem = if elements &gt;= 5 then 5 else 0;
        when '00110' =&gt; numElem = if elements &gt;= 6 then 6 else 0;
        when '00111' =&gt; numElem = if elements &gt;= 7 then 7 else 0;
        when '01000' =&gt; numElem = if elements &gt;= 8 then 8 else 0;
        when '01001' =&gt; numElem = if elements &gt;= 16 then 16 else 0;
        when '01010' =&gt; numElem = if elements &gt;= 32 then 32 else 0;
        when '01011' =&gt; numElem = if elements &gt;= 64 then 64 else 0;
        when '01100' =&gt; numElem = if elements &gt;= 128 then 128 else 0;
        when '01101' =&gt; numElem = if elements &gt;= 256 then 256 else 0;
        when '11101' =&gt; numElem = elements - (elements MOD 4);
        when '11110' =&gt; numElem = elements - (elements MOD 3);
        when '11111' =&gt; numElem = elements;
        otherwise    =&gt; numElem = 0;
    end;
    return numElem;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/ElemFFR" mylink="aarch64.functions.sve.ElemFFR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ElemFFR - accessor
// ==================

accessor <anchor link="accessor_ElemFFR_2">ElemFFR</anchor>(e : integer, esize : <a link="type_ESize" file="shared_pseudocode.xml">ESize</a>) &lt;=&gt; value : bit
begin
    getter
        return <a link="func_PredicateElement_4" file="shared_pseudocode.xml">PredicateElement</a>{<a link="global_MAX_PL" file="shared_pseudocode.xml">MAX_PL</a>}(<a link="global__FFR" file="shared_pseudocode.xml">_FFR</a>, e, esize);
    end;
    setter
        let psize : integer{} = esize DIV 8;
        <a link="global__FFR" file="shared_pseudocode.xml">_FFR</a>[e*:psize] = ZeroExtend{psize}(value);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/FFR" mylink="aarch64.functions.sve.FFR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FFR - accessor
// ==============

accessor <anchor link="accessor_FFR_1">FFR</anchor>{width}() &lt;=&gt; value : bits(width)
begin
    getter
        assert width == <a link="func_CurrentVL_0" file="shared_pseudocode.xml">CurrentVL</a>() DIV 8;
        return <a link="global__FFR" file="shared_pseudocode.xml">_FFR</a>[width-1:0];
    end;

    setter
        assert width == <a link="func_CurrentVL_0" file="shared_pseudocode.xml">CurrentVL</a>() DIV 8;
        if <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_SVEZEROUPPER" file="shared_pseudocode.xml">Unpredictable_SVEZEROUPPER</a>) then
            <a link="global__FFR" file="shared_pseudocode.xml">_FFR</a> = ZeroExtend{<a link="global_MAX_PL" file="shared_pseudocode.xml">MAX_PL</a>}(value);
        else
            <a link="global__FFR" file="shared_pseudocode.xml">_FFR</a>[width-1:0] = value;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/FPCompareNE" mylink="aarch64.functions.sve.FPCompareNE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPCompareNE()
// =============

func <anchor link="func_FPCompareNE_4">FPCompareNE</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; boolean
begin
    assert N IN {16,32,64};
    var result : boolean;
    let (type1,sign1,value1) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr);
    let (type2,sign2,value2) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr);
    let op1_nan : boolean = type1 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>};
    let op2_nan : boolean = type2 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>};

    if op1_nan || op2_nan then
        result = TRUE;
        if type1 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || type2 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
            <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
        end;
    else // All non-NaN cases can be evaluated on the values produced by FPUnpack()
        result = (value1 != value2);
        <a link="func_FPProcessDenorms_4" file="shared_pseudocode.xml">FPProcessDenorms</a>(type1, type2, N, fpcr);
    end;
    return result;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/FPCompareUN" mylink="aarch64.functions.sve.FPCompareUN" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPCompareUN()
// =============

func <anchor link="func_FPCompareUN_4">FPCompareUN</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; boolean
begin
    assert N IN {16,32,64};
    let (type1,sign1,value1) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr);
    let (type2,sign2,value2) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr);

    if type1 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || type2 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
    end;

    let result : boolean = (type1 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>} ||
                                type2 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>});
    if !result then
        <a link="func_FPProcessDenorms_4" file="shared_pseudocode.xml">FPProcessDenorms</a>(type1, type2, N, fpcr);
    end;

    return result;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/FPConvertSVE" mylink="aarch64.functions.sve.FPConvertSVE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPConvertSVE()
// ==============

func <anchor link="func_FPConvertSVE_5">FPConvertSVE</anchor>{M, N}(op : bits(N), fpcr_in : FPCR_Type, rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>) =&gt; bits(M)
begin
    var fpcr : FPCR_Type = fpcr_in;
    fpcr.AHP = '0';
    return <a link="func_FPConvert_5" file="shared_pseudocode.xml">FPConvert</a>{M, N}(op, fpcr, rounding);
end;

// FPConvertSVE()
// ==============

func <anchor link="func_FPConvertSVE_4">FPConvertSVE</anchor>{M, N}(op : bits(N), fpcr_in : FPCR_Type) =&gt; bits(M)
begin
    var fpcr : FPCR_Type = fpcr_in;
    fpcr.AHP = '0';
    return <a link="func_FPConvert_5" file="shared_pseudocode.xml">FPConvert</a>{M, N}(op, fpcr, <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr));
end;</pstext></ps>
    <ps name="aarch64/functions/sve/FPExpA" mylink="aarch64.functions.sve.FPExpA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPExpA()
// ========

func <anchor link="func_FPExpA_2">FPExpA</anchor>{N}(op : bits(N)) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var result : bits(N);
    var coeff : bits(N);
    let idx : integer = if N == 16 then UInt(op[4:0]) else UInt(op[5:0]);
    coeff = <a link="func_FPExpCoefficient_2" file="shared_pseudocode.xml">FPExpCoefficient</a>{N}(idx);
    if N == 16 then
        result[15:0] = '0'::op[9:5]::coeff[9:0];
    elsif N == 32 then
        result[31:0] = '0'::op[13:6]::coeff[22:0];
    else // N == 64
        result[63:0] = '0'::op[16:6]::coeff[51:0];
    end;

    return result;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/FPExpCoefficient" mylink="aarch64.functions.sve.FPExpCoefficient" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPExpCoefficient()
// ==================

func <anchor link="func_FPExpCoefficient_2">FPExpCoefficient</anchor>{N}(index : integer) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var result : integer;

    if N == 16 then
        case index of
            when  0 =&gt; result = 0x000;
            when  1 =&gt; result = 0x016;
            when  2 =&gt; result = 0x02d;
            when  3 =&gt; result = 0x045;
            when  4 =&gt; result = 0x05d;
            when  5 =&gt; result = 0x075;
            when  6 =&gt; result = 0x08e;
            when  7 =&gt; result = 0x0a8;
            when  8 =&gt; result = 0x0c2;
            when  9 =&gt; result = 0x0dc;
            when 10 =&gt; result = 0x0f8;
            when 11 =&gt; result = 0x114;
            when 12 =&gt; result = 0x130;
            when 13 =&gt; result = 0x14d;
            when 14 =&gt; result = 0x16b;
            when 15 =&gt; result = 0x189;
            when 16 =&gt; result = 0x1a8;
            when 17 =&gt; result = 0x1c8;
            when 18 =&gt; result = 0x1e8;
            when 19 =&gt; result = 0x209;
            when 20 =&gt; result = 0x22b;
            when 21 =&gt; result = 0x24e;
            when 22 =&gt; result = 0x271;
            when 23 =&gt; result = 0x295;
            when 24 =&gt; result = 0x2ba;
            when 25 =&gt; result = 0x2e0;
            when 26 =&gt; result = 0x306;
            when 27 =&gt; result = 0x32e;
            when 28 =&gt; result = 0x356;
            when 29 =&gt; result = 0x37f;
            when 30 =&gt; result = 0x3a9;
            when 31 =&gt; result = 0x3d4;
        end;

    elsif N == 32 then
        case index of
            when  0 =&gt; result = 0x000000;
            when  1 =&gt; result = 0x0164d2;
            when  2 =&gt; result = 0x02cd87;
            when  3 =&gt; result = 0x043a29;
            when  4 =&gt; result = 0x05aac3;
            when  5 =&gt; result = 0x071f62;
            when  6 =&gt; result = 0x08980f;
            when  7 =&gt; result = 0x0a14d5;
            when  8 =&gt; result = 0x0b95c2;
            when  9 =&gt; result = 0x0d1adf;
            when 10 =&gt; result = 0x0ea43a;
            when 11 =&gt; result = 0x1031dc;
            when 12 =&gt; result = 0x11c3d3;
            when 13 =&gt; result = 0x135a2b;
            when 14 =&gt; result = 0x14f4f0;
            when 15 =&gt; result = 0x16942d;
            when 16 =&gt; result = 0x1837f0;
            when 17 =&gt; result = 0x19e046;
            when 18 =&gt; result = 0x1b8d3a;
            when 19 =&gt; result = 0x1d3eda;
            when 20 =&gt; result = 0x1ef532;
            when 21 =&gt; result = 0x20b051;
            when 22 =&gt; result = 0x227043;
            when 23 =&gt; result = 0x243516;
            when 24 =&gt; result = 0x25fed7;
            when 25 =&gt; result = 0x27cd94;
            when 26 =&gt; result = 0x29a15b;
            when 27 =&gt; result = 0x2b7a3a;
            when 28 =&gt; result = 0x2d583f;
            when 29 =&gt; result = 0x2f3b79;
            when 30 =&gt; result = 0x3123f6;
            when 31 =&gt; result = 0x3311c4;
            when 32 =&gt; result = 0x3504f3;
            when 33 =&gt; result = 0x36fd92;
            when 34 =&gt; result = 0x38fbaf;
            when 35 =&gt; result = 0x3aff5b;
            when 36 =&gt; result = 0x3d08a4;
            when 37 =&gt; result = 0x3f179a;
            when 38 =&gt; result = 0x412c4d;
            when 39 =&gt; result = 0x4346cd;
            when 40 =&gt; result = 0x45672a;
            when 41 =&gt; result = 0x478d75;
            when 42 =&gt; result = 0x49b9be;
            when 43 =&gt; result = 0x4bec15;
            when 44 =&gt; result = 0x4e248c;
            when 45 =&gt; result = 0x506334;
            when 46 =&gt; result = 0x52a81e;
            when 47 =&gt; result = 0x54f35b;
            when 48 =&gt; result = 0x5744fd;
            when 49 =&gt; result = 0x599d16;
            when 50 =&gt; result = 0x5bfbb8;
            when 51 =&gt; result = 0x5e60f5;
            when 52 =&gt; result = 0x60ccdf;
            when 53 =&gt; result = 0x633f89;
            when 54 =&gt; result = 0x65b907;
            when 55 =&gt; result = 0x68396a;
            when 56 =&gt; result = 0x6ac0c7;
            when 57 =&gt; result = 0x6d4f30;
            when 58 =&gt; result = 0x6fe4ba;
            when 59 =&gt; result = 0x728177;
            when 60 =&gt; result = 0x75257d;
            when 61 =&gt; result = 0x77d0df;
            when 62 =&gt; result = 0x7a83b3;
            when 63 =&gt; result = 0x7d3e0c;
        end;

    else // N == 64
        case index of
            when  0 =&gt; result = 0x0000000000000;
            when  1 =&gt; result = 0x02C9A3E778061;
            when  2 =&gt; result = 0x059B0D3158574;
            when  3 =&gt; result = 0x0874518759BC8;
            when  4 =&gt; result = 0x0B5586CF9890F;
            when  5 =&gt; result = 0x0E3EC32D3D1A2;
            when  6 =&gt; result = 0x11301D0125B51;
            when  7 =&gt; result = 0x1429AAEA92DE0;
            when  8 =&gt; result = 0x172B83C7D517B;
            when  9 =&gt; result = 0x1A35BEB6FCB75;
            when 10 =&gt; result = 0x1D4873168B9AA;
            when 11 =&gt; result = 0x2063B88628CD6;
            when 12 =&gt; result = 0x2387A6E756238;
            when 13 =&gt; result = 0x26B4565E27CDD;
            when 14 =&gt; result = 0x29E9DF51FDEE1;
            when 15 =&gt; result = 0x2D285A6E4030B;
            when 16 =&gt; result = 0x306FE0A31B715;
            when 17 =&gt; result = 0x33C08B26416FF;
            when 18 =&gt; result = 0x371A7373AA9CB;
            when 19 =&gt; result = 0x3A7DB34E59FF7;
            when 20 =&gt; result = 0x3DEA64C123422;
            when 21 =&gt; result = 0x4160A21F72E2A;
            when 22 =&gt; result = 0x44E086061892D;
            when 23 =&gt; result = 0x486A2B5C13CD0;
            when 24 =&gt; result = 0x4BFDAD5362A27;
            when 25 =&gt; result = 0x4F9B2769D2CA7;
            when 26 =&gt; result = 0x5342B569D4F82;
            when 27 =&gt; result = 0x56F4736B527DA;
            when 28 =&gt; result = 0x5AB07DD485429;
            when 29 =&gt; result = 0x5E76F15AD2148;
            when 30 =&gt; result = 0x6247EB03A5585;
            when 31 =&gt; result = 0x6623882552225;
            when 32 =&gt; result = 0x6A09E667F3BCD;
            when 33 =&gt; result = 0x6DFB23C651A2F;
            when 34 =&gt; result = 0x71F75E8EC5F74;
            when 35 =&gt; result = 0x75FEB564267C9;
            when 36 =&gt; result = 0x7A11473EB0187;
            when 37 =&gt; result = 0x7E2F336CF4E62;
            when 38 =&gt; result = 0x82589994CCE13;
            when 39 =&gt; result = 0x868D99B4492ED;
            when 40 =&gt; result = 0x8ACE5422AA0DB;
            when 41 =&gt; result = 0x8F1AE99157736;
            when 42 =&gt; result = 0x93737B0CDC5E5;
            when 43 =&gt; result = 0x97D829FDE4E50;
            when 44 =&gt; result = 0x9C49182A3F090;
            when 45 =&gt; result = 0xA0C667B5DE565;
            when 46 =&gt; result = 0xA5503B23E255D;
            when 47 =&gt; result = 0xA9E6B5579FDBF;
            when 48 =&gt; result = 0xAE89F995AD3AD;
            when 49 =&gt; result = 0xB33A2B84F15FB;
            when 50 =&gt; result = 0xB7F76F2FB5E47;
            when 51 =&gt; result = 0xBCC1E904BC1D2;
            when 52 =&gt; result = 0xC199BDD85529C;
            when 53 =&gt; result = 0xC67F12E57D14B;
            when 54 =&gt; result = 0xCB720DCEF9069;
            when 55 =&gt; result = 0xD072D4A07897C;
            when 56 =&gt; result = 0xD5818DCFBA487;
            when 57 =&gt; result = 0xDA9E603DB3285;
            when 58 =&gt; result = 0xDFC97337B9B5F;
            when 59 =&gt; result = 0xE502EE78B3FF6;
            when 60 =&gt; result = 0xEA4AFA2A490DA;
            when 61 =&gt; result = 0xEFA1BEE615A27;
            when 62 =&gt; result = 0xF50765B6E4540;
            when 63 =&gt; result = 0xFA7C1819E90D8;
        end;
    end;

    return result[N-1:0];
end;</pstext></ps>
    <ps name="aarch64/functions/sve/FPLogB" mylink="aarch64.functions.sve.FPLogB" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPLogB()
// ========

func <anchor link="func_FPLogB_3">FPLogB</anchor>{N}(op : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var result : integer;
    var (fptype,sign,value) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op, fpcr);

    if fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || fptype == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> || fptype == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
        result = -(2^(N-1));            // MinInt, 100..00
    elsif fptype == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a> then
        result = 2^(N-1) - 1;           // MaxInt, 011..11
    else
        // FPUnpack has already scaled a subnormal input
        value = Abs(value);
        (value, result) = <a link="func_NormalizeReal_1" file="shared_pseudocode.xml">NormalizeReal</a>(value);

        <a link="func_FPProcessDenorm_3" file="shared_pseudocode.xml">FPProcessDenorm</a>(fptype, N, fpcr);
    end;
    return result[N-1:0];
end;</pstext></ps>
    <ps name="aarch64/functions/sve/FPMinNormal" mylink="aarch64.functions.sve.FPMinNormal" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPMinNormal()
// =============

func <anchor link="func_FPMinNormal_2">FPMinNormal</anchor>{N}(sign : bit) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    let E : integer{}  = (if N == 16 then 5 else (if N == 32 then 8 else 11));
    let F : integer{}  = N - (E + 1);
    let exp : bits(E)  = Zeros{E-1}::'1';
    let frac : bits(F) = Zeros{};
    return sign :: exp :: frac;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/FPOne" mylink="aarch64.functions.sve.FPOne" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPOne()
// =======

func <anchor link="func_FPOne_2">FPOne</anchor>{N}(sign : bit) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    let E : integer{}  = (if N == 16 then 5 else (if N == 32 then 8 else 11));
    let F : integer{}  = N - (E + 1);
    let exp : bits(E)  = '0'::Ones{E-1};
    let frac : bits(F) = Zeros{};
    return sign :: exp :: frac;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/FPPointFive" mylink="aarch64.functions.sve.FPPointFive" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPPointFive()
// =============

func <anchor link="func_FPPointFive_2">FPPointFive</anchor>{N}(sign : bit) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    let E : integer{}  = (if N == 16 then 5 else (if N == 32 then 8 else 11));
    let F : integer{}  = N - (E + 1);
    let exp : bits(E)  = '0'::Ones{E-2}::'0';
    let frac : bits(F) = Zeros{};
    return sign :: exp :: frac;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/FPReducePredicated" mylink="aarch64.functions.sve.FPReducePredicated" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPReducePredicated()
// ====================
func <anchor link="func_FPReducePredicated_8">FPReducePredicated</anchor>{esize, N, M}(op : <a link="type_ReduceOp" file="shared_pseudocode.xml">ReduceOp</a>, input : bits(N), mask : bits(M),
                                     identity : bits(esize), fpcr : FPCR_Type) =&gt; bits(esize)
begin
    assert(N == M * 8);
    assert IsPow2(N);
    var operand : bits(N);
    let elements : integer = N DIV esize;

    for e = 0 to elements-1 do
        if e * esize &lt; N &amp;&amp; <a link="func_ActivePredicateElement_4" file="shared_pseudocode.xml">ActivePredicateElement</a>{M}(mask, e, esize) then
            operand[e*:esize] = input[e*:esize];
        else
            operand[e*:esize] = identity;
        end;
    end;

    return <a link="func_FPReduce_5" file="shared_pseudocode.xml">FPReduce</a>{esize, N}(op, operand, fpcr);
end;</pstext></ps>
    <ps name="aarch64/functions/sve/FPTrigMAdd" mylink="aarch64.functions.sve.FPTrigMAdd" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPTrigMAdd()
// ============

func <anchor link="func_FPTrigMAdd_5">FPTrigMAdd</anchor>{N}(x_in : integer, op1 : bits(N), op2_in : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var coeff : bits(N);
    var op2 : bits(N) = op2_in;
    var x : integer = x_in;
    assert x &gt;= 0;
    assert x &lt; 8;

    if op2[N-1] == '1' then
        x = x + 8;
    end;

    coeff = <a link="func_FPTrigMAddCoefficient_2" file="shared_pseudocode.xml">FPTrigMAddCoefficient</a>{N}(x);
    // Safer to use EffectiveFPCR() in case the input fpcr argument
    // is modified as opposed to actual value of FPCR

    op2                    = <a link="func_FPAbs_3" file="shared_pseudocode.xml">FPAbs</a>{N}(op2, <a link="func_EffectiveFPCR_0" file="shared_pseudocode.xml">EffectiveFPCR</a>());
    let result : bits(N)   = FPMulAdd{}(coeff, op1, op2, fpcr);
    return result;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/FPTrigMAddCoefficient" mylink="aarch64.functions.sve.FPTrigMAddCoefficient" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPTrigMAddCoefficient()
// =======================

func <anchor link="func_FPTrigMAddCoefficient_2">FPTrigMAddCoefficient</anchor>{N}(index : integer) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var result : integer;

    if N == 16 then
        case index of
            when  0 =&gt; result = 0x3c00;
            when  1 =&gt; result = 0xb155;
            when  2 =&gt; result = 0x2030;
            when  3 =&gt; result = 0x0000;
            when  4 =&gt; result = 0x0000;
            when  5 =&gt; result = 0x0000;
            when  6 =&gt; result = 0x0000;
            when  7 =&gt; result = 0x0000;
            when  8 =&gt; result = 0x3c00;
            when  9 =&gt; result = 0xb800;
            when 10 =&gt; result = 0x293a;
            when 11 =&gt; result = 0x0000;
            when 12 =&gt; result = 0x0000;
            when 13 =&gt; result = 0x0000;
            when 14 =&gt; result = 0x0000;
            when 15 =&gt; result = 0x0000;
        end;
    elsif N == 32 then
        case index of
            when  0 =&gt; result = 0x3f800000;
            when  1 =&gt; result = 0xbe2aaaab;
            when  2 =&gt; result = 0x3c088886;
            when  3 =&gt; result = 0xb95008b9;
            when  4 =&gt; result = 0x36369d6d;
            when  5 =&gt; result = 0x00000000;
            when  6 =&gt; result = 0x00000000;
            when  7 =&gt; result = 0x00000000;
            when  8 =&gt; result = 0x3f800000;
            when  9 =&gt; result = 0xbf000000;
            when 10 =&gt; result = 0x3d2aaaa6;
            when 11 =&gt; result = 0xbab60705;
            when 12 =&gt; result = 0x37cd37cc;
            when 13 =&gt; result = 0x00000000;
            when 14 =&gt; result = 0x00000000;
            when 15 =&gt; result = 0x00000000;
        end;
    else // N == 64
        case index of
            when  0 =&gt; result = 0x3ff0000000000000;
            when  1 =&gt; result = 0xbfc5555555555543;
            when  2 =&gt; result = 0x3f8111111110f30c;
            when  3 =&gt; result = 0xbf2a01a019b92fc6;
            when  4 =&gt; result = 0x3ec71de351f3d22b;
            when  5 =&gt; result = 0xbe5ae5e2b60f7b91;
            when  6 =&gt; result = 0x3de5d8408868552f;
            when  7 =&gt; result = 0x0000000000000000;
            when  8 =&gt; result = 0x3ff0000000000000;
            when  9 =&gt; result = 0xbfe0000000000000;
            when 10 =&gt; result = 0x3fa5555555555536;
            when 11 =&gt; result = 0xbf56c16c16c13a0b;
            when 12 =&gt; result = 0x3efa01a019b1e8d8;
            when 13 =&gt; result = 0xbe927e4f7282f468;
            when 14 =&gt; result = 0x3e21ee96d2641b13;
            when 15 =&gt; result = 0xbda8f76380fbb401;
        end;
    end;

    return result[N-1:0];
end;</pstext></ps>
    <ps name="aarch64/functions/sve/FPTrigSMul" mylink="aarch64.functions.sve.FPTrigSMul" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPTrigSMul()
// ============

func <anchor link="func_FPTrigSMul_4">FPTrigSMul</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var result : bits(N) = FPMul{}(op1, op1, fpcr);
    let fpexc = FALSE;
    let (fptype, sign, value) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(result, fpcr, fpexc);

    if ! fptype IN {<a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>, <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>} then
        result[N-1] = op2[0];
    end;

    return result;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/FPTrigSSel" mylink="aarch64.functions.sve.FPTrigSSel" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPTrigSSel()
// ============

func <anchor link="func_FPTrigSSel_3">FPTrigSSel</anchor>{N}(op1 : bits(N), op2 : bits(N)) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var result : bits(N);

    if op2[0] == '1' then
        result = <a link="func_FPOne_2" file="shared_pseudocode.xml">FPOne</a>{N}(op2[1]);
    elsif op2[1] == '1' then
        result = <a link="func_FPNeg_3" file="shared_pseudocode.xml">FPNeg</a>{N}(op1, <a link="func_EffectiveFPCR_0" file="shared_pseudocode.xml">EffectiveFPCR</a>());
    else
        result = op1;
    end;

    return result;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/FirstActive" mylink="aarch64.functions.sve.FirstActive" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FirstActive()
// =============

func <anchor link="func_FirstActive_4">FirstActive</anchor>{N}(mask : bits(N), x : bits(N), esize : integer) =&gt; bit
begin
    let elements : integer = N DIV (esize DIV 8);
    for e = 0 to elements-1 do
        if <a link="func_ActivePredicateElement_4" file="shared_pseudocode.xml">ActivePredicateElement</a>{N}(mask, e, esize) then
            return <a link="func_PredicateElement_4" file="shared_pseudocode.xml">PredicateElement</a>{N}(x, e, esize);
        end;
    end;
    return '0';
end;</pstext></ps>
    <ps name="aarch64/functions/sve/HaveSVE2FP8DOT2" mylink="aarch64.functions.sve.HaveSVE2FP8DOT2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HaveSVE2FP8DOT2()
// =================
// Returns TRUE if SVE2 FP8 dot product to half-precision instructions
// are implemented, FALSE otherwise.

func <anchor link="func_HaveSVE2FP8DOT2_0">HaveSVE2FP8DOT2</anchor>() =&gt; boolean
begin
    return ((IsFeatureImplemented(FEAT_SVE2) &amp;&amp; IsFeatureImplemented(FEAT_FP8DOT2)) ||
            IsFeatureImplemented(FEAT_SSVE_FP8DOT2));
end;</pstext></ps>
    <ps name="aarch64/functions/sve/HaveSVE2FP8DOT4" mylink="aarch64.functions.sve.HaveSVE2FP8DOT4" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HaveSVE2FP8DOT4()
// =================
// Returns TRUE if SVE2 FP8 dot product to single-precision instructions
// are implemented, FALSE otherwise.

func <anchor link="func_HaveSVE2FP8DOT4_0">HaveSVE2FP8DOT4</anchor>() =&gt; boolean
begin
    return ((IsFeatureImplemented(FEAT_SVE2) &amp;&amp; IsFeatureImplemented(FEAT_FP8DOT4)) ||
            IsFeatureImplemented(FEAT_SSVE_FP8DOT4));
end;</pstext></ps>
    <ps name="aarch64/functions/sve/HaveSVE2FP8FMA" mylink="aarch64.functions.sve.HaveSVE2FP8FMA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HaveSVE2FP8FMA()
// ================
// Returns TRUE if SVE2 FP8 multiply-accumulate to half-precision and single-precision
// instructions are implemented, FALSE otherwise.

func <anchor link="func_HaveSVE2FP8FMA_0">HaveSVE2FP8FMA</anchor>() =&gt; boolean
begin
    return ((IsFeatureImplemented(FEAT_SVE2) &amp;&amp; IsFeatureImplemented(FEAT_FP8FMA)) ||
            IsFeatureImplemented(FEAT_SSVE_FP8FMA));
end;</pstext></ps>
    <ps name="aarch64/functions/sve/ImplementedSMEVectorLength" mylink="aarch64.functions.sve.ImplementedSMEVectorLength" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ImplementedSMEVectorLength()
// ============================
// Reduce SVE/SME vector length to a supported value (power of two)

readonly func <anchor link="func_ImplementedSMEVectorLength_1">ImplementedSMEVectorLength</anchor>(nbits_in : integer) =&gt; <a link="type_VecLen" file="shared_pseudocode.xml">VecLen</a>
begin
    let maxbits : <a link="type_VecLen" file="shared_pseudocode.xml">VecLen</a> = <a link="func_MaxImplementedSVL_0" file="shared_pseudocode.xml">MaxImplementedSVL</a>();
    assert 128 &lt;= maxbits &amp;&amp; maxbits &lt;= 2048 &amp;&amp; IsPow2(maxbits);
    var nbits : integer = Min(nbits_in, maxbits);
    assert 128 &lt;= nbits &amp;&amp; nbits &lt;= 2048 &amp;&amp; AlignDownSize(nbits, 128) == nbits;

    // Search for a supported power-of-two VL less than or equal to nbits
    while nbits &gt; 128 &amp;&amp; !SupportedPowerTwoSVL(nbits) looplimit 7 do
        nbits = nbits - 128;
    end;

    // Return the smallest supported power-of-two VL
    while nbits &lt; maxbits &amp;&amp; !SupportedPowerTwoSVL(nbits) looplimit 7 do
        nbits = nbits * 2;
    end;

    return nbits as <a link="type_VecLen" file="shared_pseudocode.xml">VecLen</a>;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/ImplementedSVEVectorLength" mylink="aarch64.functions.sve.ImplementedSVEVectorLength" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ImplementedSVEVectorLength()
// ============================
// Reduce SVE vector length to a supported value (power of two)

readonly func <anchor link="func_ImplementedSVEVectorLength_1">ImplementedSVEVectorLength</anchor>(nbits_in : integer) =&gt; <a link="type_VecLen" file="shared_pseudocode.xml">VecLen</a>
begin
    let maxbits : integer = <a link="func_MaxImplementedVL_0" file="shared_pseudocode.xml">MaxImplementedVL</a>();
    assert 128 &lt;= maxbits &amp;&amp; maxbits &lt;= 2048 &amp;&amp; IsPow2(maxbits);
    var nbits : integer = Min(nbits_in, maxbits);
    assert 128 &lt;= nbits &amp;&amp; nbits &lt;= 2048 &amp;&amp; AlignDownSize(nbits, 128) == nbits;

    while !IsPow2(nbits) looplimit 7 do
        nbits = nbits - 128;
    end;
    return nbits as <a link="type_VecLen" file="shared_pseudocode.xml">VecLen</a>;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/InStreamingMode" mylink="aarch64.functions.sve.InStreamingMode" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// InStreamingMode()
// =================

func <anchor link="func_InStreamingMode_0">InStreamingMode</anchor>() =&gt; boolean
begin
    return IsFeatureImplemented(FEAT_SME) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM == '1';
end;</pstext></ps>
    <ps name="aarch64/functions/sve/IntReducePredicated" mylink="aarch64.functions.sve.IntReducePredicated" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IntReducePredicated()
// =====================
func <anchor link="func_IntReducePredicated_7">IntReducePredicated</anchor>{esize, N, M}(op : <a link="type_ReduceOp" file="shared_pseudocode.xml">ReduceOp</a>, input : bits(N),
                                      mask : bits(M), identity : bits(esize)) =&gt; bits(esize)
begin
    assert(N == M * 8);
    assert IsPow2(N);
    var operand : bits(N);
    let elements : integer = N DIV esize;

    for e = 0 to elements-1 do
        if e * esize &lt; N &amp;&amp; <a link="func_ActivePredicateElement_4" file="shared_pseudocode.xml">ActivePredicateElement</a>{M}(mask, e, esize) then
            operand[e*:esize] = input[e*:esize];
        else
            operand[e*:esize] = identity;
        end;
    end;

    return <a link="func_IntReduce_4" file="shared_pseudocode.xml">IntReduce</a>{esize, N}(op, operand);
end;</pstext></ps>
    <ps name="aarch64/functions/sve/IsFPEnabled" mylink="aarch64.functions.sve.IsFPEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsFPEnabled()
// =============
// Returns TRUE if accesses to the Advanced SIMD and floating-point
// registers are enabled at the target exception level in the current
// execution state and FALSE otherwise.

func <anchor link="func_IsFPEnabled_1">IsFPEnabled</anchor>(el : bits(2)) =&gt; boolean
begin
    if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(el) then
        return <a link="func_AArch32_IsFPEnabled_1" file="shared_pseudocode.xml">AArch32_IsFPEnabled</a>(el);
    else
        return <a link="func_AArch64_IsFPEnabled_1" file="shared_pseudocode.xml">AArch64_IsFPEnabled</a>(el);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/IsFullA64Enabled" mylink="aarch64.functions.sve.IsFullA64Enabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsFullA64Enabled()
// ==================
// Returns TRUE if full A64 is enabled in Streaming mode and FALSE otherwise.

func <anchor link="func_IsFullA64Enabled_0">IsFullA64Enabled</anchor>() =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_SME_FA64) then return FALSE; end;

    // Check if full A64 disabled in SMCR_EL1
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
        // Check full A64 at EL0/EL1
        if SMCR_EL1().FA64 == '0' then return FALSE; end;
    end;

    // Check if full A64 disabled in SMCR_EL2
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        if SMCR_EL2().FA64 == '0' then return FALSE; end;
    end;

    // Check if full A64 disabled in SMCR_EL3
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        if SMCR_EL3().FA64 == '0' then return FALSE; end;
    end;

    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/IsOriginalSVEEnabled" mylink="aarch64.functions.sve.IsOriginalSVEEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsOriginalSVEEnabled()
// ======================
// Returns TRUE if access to SVE functionality is enabled at the target
// exception level and FALSE otherwise.

func <anchor link="func_IsOriginalSVEEnabled_1">IsOriginalSVEEnabled</anchor>(el : bits(2)) =&gt; boolean
begin
    var disabled : boolean;
    if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(el) then
        return FALSE;
    end;

    // Check if access disabled in CPACR_EL1
    if el IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
        // Check SVE at EL0/EL1
        case CPACR_EL1().ZEN of
            when 'x0' =&gt; disabled = TRUE;
            when '01' =&gt; disabled = el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
            when '11' =&gt; disabled = FALSE;
        end;
        if disabled then return FALSE; end;
    end;

    // Check if access disabled in CPTR_EL2
    if el IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
            case CPTR_EL2().ZEN of
                when 'x0' =&gt; disabled = TRUE;
                when '01' =&gt; disabled = el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; HCR_EL2().TGE == '1';
                when '11' =&gt; disabled = FALSE;
            end;
            if disabled then return FALSE; end;
        else
            if CPTR_EL2().TZ == '1' then return FALSE; end;
        end;
    end;

    // Check if access disabled in CPTR_EL3
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        if CPTR_EL3().EZ == '0' then return FALSE; end;
    end;

    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/IsSMEEnabled" mylink="aarch64.functions.sve.IsSMEEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsSMEEnabled()
// ==============
// Returns TRUE if access to SME functionality is enabled at the target
// exception level and FALSE otherwise.

func <anchor link="func_IsSMEEnabled_1">IsSMEEnabled</anchor>(el : bits(2)) =&gt; boolean
begin
    var disabled : boolean;
    if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(el) then
        return FALSE;
    end;

    // Check if access disabled in CPACR_EL1
    if el IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
        // Check SME at EL0/EL1
        case CPACR_EL1().SMEN of
            when 'x0' =&gt; disabled = TRUE;
            when '01' =&gt; disabled = el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
            when '11' =&gt; disabled = FALSE;
        end;
        if disabled then return FALSE; end;
    end;

    // Check if access disabled in CPTR_EL2
    if el IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
            case CPTR_EL2().SMEN of
                when 'x0' =&gt; disabled = TRUE;
                when '01' =&gt; disabled = el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; HCR_EL2().TGE == '1';
                when '11' =&gt; disabled = FALSE;
            end;
            if disabled then return FALSE; end;
        else
            if CPTR_EL2().TSM == '1' then return FALSE; end;
        end;
    end;

    // Check if access disabled in CPTR_EL3
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        if CPTR_EL3().ESM == '0' then return FALSE; end;
    end;

    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/IsSVEEnabled" mylink="aarch64.functions.sve.IsSVEEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsSVEEnabled()
// ==============
// Returns TRUE if access to SVE registers is enabled at the target exception
// level and FALSE otherwise.

func <anchor link="func_IsSVEEnabled_1">IsSVEEnabled</anchor>(el : bits(2)) =&gt; boolean
begin
    if IsFeatureImplemented(FEAT_SME) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM == '1' then
        return <a link="func_IsSMEEnabled_1" file="shared_pseudocode.xml">IsSMEEnabled</a>(el);
    elsif IsFeatureImplemented(FEAT_SVE) then
        return <a link="func_IsOriginalSVEEnabled_1" file="shared_pseudocode.xml">IsOriginalSVEEnabled</a>(el);
    else
        return FALSE;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/LastActive" mylink="aarch64.functions.sve.LastActive" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// LastActive()
// ============

func <anchor link="func_LastActive_4">LastActive</anchor>{N}(mask : bits(N), x : bits(N), esize : integer) =&gt; bit
begin
    let elements : integer = N DIV (esize DIV 8);
    for e = elements-1 downto 0 do
        if <a link="func_ActivePredicateElement_4" file="shared_pseudocode.xml">ActivePredicateElement</a>{N}(mask, e, esize) then
            return <a link="func_PredicateElement_4" file="shared_pseudocode.xml">PredicateElement</a>{N}(x, e, esize);
        end;
    end;
    return '0';
end;</pstext></ps>
    <ps name="aarch64/functions/sve/LastActiveElement" mylink="aarch64.functions.sve.LastActiveElement" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// LastActiveElement()
// ===================

func <anchor link="func_LastActiveElement_3">LastActiveElement</anchor>{N}(mask : bits(N), esize : integer) =&gt; integer
begin
    let elements : integer = N DIV (esize DIV 8);
    for e = elements-1 downto 0 do
        if <a link="func_ActivePredicateElement_4" file="shared_pseudocode.xml">ActivePredicateElement</a>{N}(mask, e, esize) then return e; end;
    end;
    return -1;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/MaxImplementedAnyVL" mylink="aarch64.functions.sve.MaxImplementedAnyVL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MaxImplementedAnyVL()
// =====================

readonly func <anchor link="func_MaxImplementedAnyVL_0">MaxImplementedAnyVL</anchor>() =&gt; integer
begin
    if IsFeatureImplemented(FEAT_SME) &amp;&amp; IsFeatureImplemented(FEAT_SVE) then
        return Max(<a link="func_MaxImplementedVL_0" file="shared_pseudocode.xml">MaxImplementedVL</a>(), <a link="func_MaxImplementedSVL_0" file="shared_pseudocode.xml">MaxImplementedSVL</a>());
    end;
    if IsFeatureImplemented(FEAT_SME) then
        return <a link="func_MaxImplementedSVL_0" file="shared_pseudocode.xml">MaxImplementedSVL</a>();
    end;
    return <a link="func_MaxImplementedVL_0" file="shared_pseudocode.xml">MaxImplementedVL</a>();
end;</pstext></ps>
    <ps name="aarch64/functions/sve/MaxImplementedSVL" mylink="aarch64.functions.sve.MaxImplementedSVL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MaxImplementedSVL()
// ===================

readonly func <anchor link="func_MaxImplementedSVL_0">MaxImplementedSVL</anchor>() =&gt; <a link="type_VecLen" file="shared_pseudocode.xml">VecLen</a>
begin
    return ImpDefInt(&quot;Max implemented SVL&quot;) as <a link="type_VecLen" file="shared_pseudocode.xml">VecLen</a>;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/MaxImplementedVL" mylink="aarch64.functions.sve.MaxImplementedVL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MaxImplementedVL()
// ==================

readonly func <anchor link="func_MaxImplementedVL_0">MaxImplementedVL</anchor>() =&gt; integer
begin
    return ImpDefInt(&quot;Max implemented VL&quot;);
end;</pstext></ps>
    <ps name="aarch64/functions/sve/MaybeZeroSVEUppers" mylink="aarch64.functions.sve.MaybeZeroSVEUppers" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MaybeZeroSVEUppers()
// ====================

func <anchor link="func_MaybeZeroSVEUppers_1">MaybeZeroSVEUppers</anchor>(target_el : bits(2))
begin
    var lower_enabled : boolean;

    if UInt(target_el) &lt;= UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) || !<a link="func_IsSVEEnabled_1" file="shared_pseudocode.xml">IsSVEEnabled</a>(target_el) then
        return;
    end;

    if target_el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then
        if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
            lower_enabled = <a link="func_IsFPEnabled_1" file="shared_pseudocode.xml">IsFPEnabled</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
        else
            lower_enabled = <a link="func_IsFPEnabled_1" file="shared_pseudocode.xml">IsFPEnabled</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>);
        end;
    elsif target_el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
        assert <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
        if HCR_EL2().TGE == '0' then
            lower_enabled = <a link="func_IsFPEnabled_1" file="shared_pseudocode.xml">IsFPEnabled</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>);
        else
            lower_enabled = <a link="func_IsFPEnabled_1" file="shared_pseudocode.xml">IsFPEnabled</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>);
        end;
    else
        assert target_el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>);
        lower_enabled = <a link="func_IsFPEnabled_1" file="shared_pseudocode.xml">IsFPEnabled</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>);
    end;

    if lower_enabled then
        let VL : integer{} = if <a link="func_IsSVEEnabled_1" file="shared_pseudocode.xml">IsSVEEnabled</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) then <a link="func_CurrentVL_0" file="shared_pseudocode.xml">CurrentVL</a>() else 128;
        let PL : integer{} = VL DIV 8;
        for n = 0 to 31 do
            if <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_SVEZEROUPPER" file="shared_pseudocode.xml">Unpredictable_SVEZEROUPPER</a>) then
                <a link="global__Z" file="shared_pseudocode.xml">_Z</a>[[n]] = ZeroExtend{<a link="global_MAX_VL" file="shared_pseudocode.xml">MAX_VL</a>}(<a link="global__Z" file="shared_pseudocode.xml">_Z</a>[[n]][VL-1:0]);
            end;
        end;
        for n = 0 to 15 do
            if <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_SVEZEROUPPER" file="shared_pseudocode.xml">Unpredictable_SVEZEROUPPER</a>) then
                <a link="global__P" file="shared_pseudocode.xml">_P</a>[[n]] = ZeroExtend{<a link="global_MAX_PL" file="shared_pseudocode.xml">MAX_PL</a>}(<a link="global__P" file="shared_pseudocode.xml">_P</a>[[n]][PL-1:0]);
            end;
        end;
        if <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_SVEZEROUPPER" file="shared_pseudocode.xml">Unpredictable_SVEZEROUPPER</a>) then
            <a link="global__FFR" file="shared_pseudocode.xml">_FFR</a> = ZeroExtend{<a link="global_MAX_PL" file="shared_pseudocode.xml">MAX_PL</a>}(<a link="global__FFR" file="shared_pseudocode.xml">_FFR</a>[PL-1:0]);
        end;
        if IsFeatureImplemented(FEAT_SME) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.ZA == '1' then
            let SVL : integer{}          = <a link="func_CurrentSVL_0" file="shared_pseudocode.xml">CurrentSVL</a>();
            let accessiblevecs : integer = SVL DIV 8;
            let allvecs : integer        = <a link="func_MaxImplementedSVL_0" file="shared_pseudocode.xml">MaxImplementedSVL</a>() DIV 8;

            for n = 0 to accessiblevecs - 1 do
                if <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_SMEZEROUPPER" file="shared_pseudocode.xml">Unpredictable_SMEZEROUPPER</a>) then
                    <a link="global__ZA" file="shared_pseudocode.xml">_ZA</a>[[n]] = ZeroExtend{<a link="global_MAX_VL" file="shared_pseudocode.xml">MAX_VL</a>}(<a link="global__ZA" file="shared_pseudocode.xml">_ZA</a>[[n]][SVL-1:0]);
                end;
            end;
            for n = accessiblevecs to allvecs - 1 do
                if <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_SMEZEROUPPER" file="shared_pseudocode.xml">Unpredictable_SMEZEROUPPER</a>) then
                    <a link="global__ZA" file="shared_pseudocode.xml">_ZA</a>[[n]] = Zeros{<a link="global_MAX_VL" file="shared_pseudocode.xml">MAX_VL</a>};
                end;
            end;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/MemNF" mylink="aarch64.functions.sve.MemNF" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemNF
// =====

func <anchor link="func_MemNF_3">MemNF</anchor>{size : integer{8, 16, 32, 64, 128}}(address : bits(64),
                                               accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
                                              ) =&gt; (bits(size), boolean)
begin
    let bytes : integer{} = size DIV 8;
    var value : bits(size);
    var bad : boolean;

    var aligned : boolean = IsAlignedSize{64}(address, bytes);

    if !aligned &amp;&amp; <a link="func_AlignmentEnforced_0" file="shared_pseudocode.xml">AlignmentEnforced</a>() then
        return (ARBITRARY : bits(size), TRUE);
    end;

    let atomic : boolean = aligned || bytes == 1;

    if !atomic then
        (value[7:0], bad) = <a link="func_MemSingleNF_4" file="shared_pseudocode.xml">MemSingleNF</a>{8}(address, accdesc, aligned);

        if bad then
            return (ARBITRARY : bits(size), TRUE);
        end;

        // For subsequent bytes, if they cross to a new translation page which assigns
        // Device memory type, it is CONSTRAINED UNPREDICTABLE whether an unaligned access
        // will generate an Alignment Fault.
        if !aligned then
            let c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = ConstrainUnpredictable(<a link="enum_Unpredictable_DEVPAGE2" file="shared_pseudocode.xml">Unpredictable_DEVPAGE2</a>);
            assert c IN {<a link="enum_Constraint_FAULT" file="shared_pseudocode.xml">Constraint_FAULT</a>, <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>};
            if c == <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a> then aligned = TRUE; end;
        end;

        for i = 1 to bytes-1 do
            (value[i*:8], bad) = <a link="func_MemSingleNF_4" file="shared_pseudocode.xml">MemSingleNF</a>{8}(address+i, accdesc, aligned);

            if bad then
                return (ARBITRARY : bits(size), TRUE);
            end;
        end;
    else
        (value, bad) = <a link="func_MemSingleNF_4" file="shared_pseudocode.xml">MemSingleNF</a>{size}(address, accdesc, aligned);
        if bad then
            return (ARBITRARY : bits(size), TRUE);
        end;
    end;

    if <a link="func_BigEndian_1" file="shared_pseudocode.xml">BigEndian</a>(accdesc.acctype) then
        value = <a link="func_BigEndianReverse_2" file="shared_pseudocode.xml">BigEndianReverse</a>{size}(value);
    end;

    return (value, FALSE);
end;</pstext></ps>
    <ps name="aarch64/functions/sve/MemSingleNF" mylink="aarch64.functions.sve.MemSingleNF" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemSingleNF
// ===========

func <anchor link="func_MemSingleNF_4">MemSingleNF</anchor>{size : integer{8, 16, 32, 64, 128}}(address : bits(64),
                                                     accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                                                     aligned : boolean) =&gt; (bits(size), boolean)
begin
    assert accdesc_in.acctype == <a link="enum_AccessType_SVE" file="shared_pseudocode.xml">AccessType_SVE</a>;
    assert accdesc_in.nonfault || (accdesc_in.firstfault &amp;&amp; !accdesc_in.first);

    let bytes : integer{} = size DIV 8;
    var value : bits(size);
    var memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = accdesc_in;
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_2" file="shared_pseudocode.xml">NoFault</a>(accdesc, address);

    // Implementation may suppress NF load for any reason
    if <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_NONFAULT" file="shared_pseudocode.xml">Unpredictable_NONFAULT</a>) then
        return (ARBITRARY : bits(size), TRUE);
    end;

    // If the instruction encoding permits tag checking, confer with system register configuration
    // which may override this.
    if accdesc.tagchecked then
        accdesc.tagchecked = <a link="func_AArch64_AccessIsTagChecked_2" file="shared_pseudocode.xml">AArch64_AccessIsTagChecked</a>(address, accdesc);
    end;

    // MMU or MPU
    memaddrdesc = <a link="func_AArch64_TranslateAddress_4" file="shared_pseudocode.xml">AArch64_TranslateAddress</a>(address, accdesc, aligned, bytes);

    // Non-fault load from Device memory must not be performed externally
    if memaddrdesc.memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> then
        return (ARBITRARY : bits(size), TRUE);
    end;

    // Check for aborts or debug exceptions
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memaddrdesc) then
        return (ARBITRARY : bits(size), TRUE);
    end;

    if accdesc.tagchecked then
        let ltag : bits(4) = <a link="func_AArch64_LogicalAddressTag_1" file="shared_pseudocode.xml">AArch64_LogicalAddressTag</a>(address);
        let readcheck : boolean = TRUE;
        fault = <a link="func_AArch64_CheckTag_5" file="shared_pseudocode.xml">AArch64_CheckTag</a>(memaddrdesc, accdesc, readcheck, bytes, ltag);
        if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
            return (ARBITRARY : bits(size), TRUE);
        end;
    end;

    (memstatus, value) = <a link="func_PhysMemRead_3" file="shared_pseudocode.xml">PhysMemRead</a>{size}(memaddrdesc, accdesc);
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
        let iswrite : boolean = FALSE;
        if <a link="func_IsExternalAbortTakenSynchronously_5" file="shared_pseudocode.xml">IsExternalAbortTakenSynchronously</a>(memstatus, iswrite, memaddrdesc, bytes, accdesc) then
            return (ARBITRARY : bits(size), TRUE);
        end;
        fault.merrorstate = memstatus.merrorstate;
        fault.extflag    = memstatus.extflag;
        fault.statuscode = memstatus.statuscode;
        PendSErrorInterrupt(fault);
    end;

    return (value, FALSE);
end;</pstext></ps>
    <ps name="aarch64/functions/sve/NoneActive" mylink="aarch64.functions.sve.NoneActive" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// NoneActive()
// ============

func <anchor link="func_NoneActive_4">NoneActive</anchor>{N}(mask : bits(N), x : bits(N), esize : integer) =&gt; bit
begin
    let elements : integer = N DIV (esize DIV 8);
    for e = 0 to elements-1 do
        if <a link="func_ActivePredicateElement_4" file="shared_pseudocode.xml">ActivePredicateElement</a>{N}(mask, e, esize) &amp;&amp; <a link="func_ActivePredicateElement_4" file="shared_pseudocode.xml">ActivePredicateElement</a>{N}(x, e, esize) then
            return '0';
        end;
    end;
    return '1';
end;</pstext></ps>
    <ps name="aarch64/functions/sve/P" mylink="aarch64.functions.sve.P" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// P - accessor
// ============

accessor <anchor link="accessor_P_2">P</anchor>{width}(n : integer) &lt;=&gt; value : bits(width)
begin
    getter
        assert n &gt;= 0 &amp;&amp; n &lt;= 31;
        assert width == <a link="func_CurrentVL_0" file="shared_pseudocode.xml">CurrentVL</a>() DIV 8;
        return <a link="global__P" file="shared_pseudocode.xml">_P</a>[[n]][width-1:0];
    end;

    setter
        assert n &gt;= 0 &amp;&amp; n &lt;= 31;
        assert width == <a link="func_CurrentVL_0" file="shared_pseudocode.xml">CurrentVL</a>() DIV 8;
        if <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_SVEZEROUPPER" file="shared_pseudocode.xml">Unpredictable_SVEZEROUPPER</a>) then
            <a link="global__P" file="shared_pseudocode.xml">_P</a>[[n]] = ZeroExtend{<a link="global_MAX_PL" file="shared_pseudocode.xml">MAX_PL</a>}(value);
        else
            <a link="global__P" file="shared_pseudocode.xml">_P</a>[[n]][width-1:0] = value;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/PredLen" mylink="aarch64.functions.sve.PredLen" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PredLen
// =======

type <anchor link="type_PredLen">PredLen</anchor> of integer{16, 32, 64, 128, 256};</pstext></ps>
    <ps name="aarch64/functions/sve/PredTest" mylink="aarch64.functions.sve.PredTest" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PredTest()
// ==========

func <anchor link="func_PredTest_4">PredTest</anchor>{N}(mask : bits(N), result : bits(N), esize : integer) =&gt; bits(4)
begin
    let n : bit = <a link="func_FirstActive_4" file="shared_pseudocode.xml">FirstActive</a>{N}(mask, result, esize);
    let z : bit = <a link="func_NoneActive_4" file="shared_pseudocode.xml">NoneActive</a>{N}(mask, result, esize);
    let c : bit = NOT <a link="func_LastActive_4" file="shared_pseudocode.xml">LastActive</a>{N}(mask, result, esize);
    let v : bit = '0';
    return n::z::c::v;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/PredicateElement" mylink="aarch64.functions.sve.PredicateElement" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PredicateElement()
// ==================
// Returns the predicate bit

func <anchor link="func_PredicateElement_4">PredicateElement</anchor>{N}(pred : bits(N), e : integer, esize : integer) =&gt; bit
begin
    assert esize IN {8, 16, 32, 64, 128};
    let n : integer = e * (esize DIV 8);
    assert n &gt;= 0 &amp;&amp; n &lt; N;
    return pred[n];
end;</pstext></ps>
    <ps name="aarch64/functions/sve/ResetSMEState" mylink="aarch64.functions.sve.ResetSMEState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ResetSMEState()
// ===============

func <anchor link="func_ResetSMEState_1">ResetSMEState</anchor>(newenable : bit)
begin
    let vectors : integer = <a link="global_MAX_VL" file="shared_pseudocode.xml">MAX_VL</a> DIV 8;
    if newenable == '1' then
        for n = 0 to vectors - 1 do
            <a link="global__ZA" file="shared_pseudocode.xml">_ZA</a>[[n]] = Zeros{<a link="global_MAX_VL" file="shared_pseudocode.xml">MAX_VL</a>};
        end;
        if IsFeatureImplemented(FEAT_SME2) then
            <a link="global__ZT0" file="shared_pseudocode.xml">_ZT0</a> = Zeros{<a link="global_ZT0_LEN" file="shared_pseudocode.xml">ZT0_LEN</a>};
        end;
    else
        for n = 0 to vectors - 1 do
            <a link="global__ZA" file="shared_pseudocode.xml">_ZA</a>[[n]] = ARBITRARY : bits(<a link="global_MAX_VL" file="shared_pseudocode.xml">MAX_VL</a>);
        end;
        if IsFeatureImplemented(FEAT_SME2) then
            <a link="global__ZT0" file="shared_pseudocode.xml">_ZT0</a> = ARBITRARY : bits(<a link="global_ZT0_LEN" file="shared_pseudocode.xml">ZT0_LEN</a>);
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/ResetSVERegisters" mylink="aarch64.functions.sve.ResetSVERegisters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ResetSVERegisters()
// ===================

func <anchor link="func_ResetSVERegisters_0">ResetSVERegisters</anchor>()
begin
    for n = 0 to 31 do
        <a link="global__Z" file="shared_pseudocode.xml">_Z</a>[[n]] = ARBITRARY : bits(<a link="global_MAX_VL" file="shared_pseudocode.xml">MAX_VL</a>);
    end;
    for n = 0 to 15 do
        <a link="global__P" file="shared_pseudocode.xml">_P</a>[[n]] = ARBITRARY : bits(<a link="global_MAX_PL" file="shared_pseudocode.xml">MAX_PL</a>);
    end;
    <a link="global__FFR" file="shared_pseudocode.xml">_FFR</a> = ARBITRARY : bits(<a link="global_MAX_PL" file="shared_pseudocode.xml">MAX_PL</a>);
end;</pstext></ps>
    <ps name="aarch64/functions/sve/ResetSVEState" mylink="aarch64.functions.sve.ResetSVEState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ResetSVEState()
// ===============

func <anchor link="func_ResetSVEState_0">ResetSVEState</anchor>()
begin
    for n = 0 to 31 do
        <a link="global__Z" file="shared_pseudocode.xml">_Z</a>[[n]] = Zeros{<a link="global_MAX_VL" file="shared_pseudocode.xml">MAX_VL</a>};
    end;
    for n = 0 to 15 do
        <a link="global__P" file="shared_pseudocode.xml">_P</a>[[n]] = Zeros{<a link="global_MAX_PL" file="shared_pseudocode.xml">MAX_PL</a>};
    end;
    <a link="global__FFR" file="shared_pseudocode.xml">_FFR</a> = Zeros{<a link="global_MAX_PL" file="shared_pseudocode.xml">MAX_PL</a>};
    FPSR() = ZeroExtend{64}(0x0800009f[31:0]);
    FPMR() = Zeros{64};
end;</pstext></ps>
    <ps name="aarch64/functions/sve/SMEAccessTrap" mylink="aarch64.functions.sve.SMEAccessTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SMEAccessTrap()
// ===============
// Trapped access to SME registers due to CPACR_EL1, CPTR_EL2, or CPTR_EL3.

func <anchor link="func_SMEAccessTrap_2">SMEAccessTrap</anchor>(etype : <a link="type_SMEExceptionType" file="shared_pseudocode.xml">SMEExceptionType</a>, target_el_in : bits(2))
begin
    var target_el : bits(2) = target_el_in;
    assert UInt(target_el) &gt;= UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    if target_el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        target_el = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    end;
    let route_to_el2 : boolean = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; target_el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp;
                                  <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1');

    var except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>              = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_SMEAccessTrap" file="shared_pseudocode.xml">Exception_SMEAccessTrap</a>);
    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer                 = 0x0;

    case etype of
        when <a link="enum_SMEExceptionType_AccessTrap" file="shared_pseudocode.xml">SMEExceptionType_AccessTrap</a> =&gt;
            except.syndrome.iss[2:0] = '000';
        when <a link="enum_SMEExceptionType_Streaming" file="shared_pseudocode.xml">SMEExceptionType_Streaming</a> =&gt;
            except.syndrome.iss[2:0] = '001';
        when <a link="enum_SMEExceptionType_NotStreaming" file="shared_pseudocode.xml">SMEExceptionType_NotStreaming</a> =&gt;
            except.syndrome.iss[2:0] = '010';
        when <a link="enum_SMEExceptionType_InactiveZA" file="shared_pseudocode.xml">SMEExceptionType_InactiveZA</a> =&gt;
            except.syndrome.iss[2:0] = '011';
        when <a link="enum_SMEExceptionType_InaccessibleZT0" file="shared_pseudocode.xml">SMEExceptionType_InaccessibleZT0</a> =&gt;
            except.syndrome.iss[2:0] = '100';
    end;

    if route_to_el2 then
        AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
    else
        AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/SMEExceptionType" mylink="aarch64.functions.sve.SMEExceptionType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SMEExceptionType
// ================
type <anchor link="type_SMEExceptionType">SMEExceptionType</anchor> of enumeration {
    <anchor link="enum_SMEExceptionType_AccessTrap">SMEExceptionType_AccessTrap</anchor>,        // SME functionality trapped or disabled
    <anchor link="enum_SMEExceptionType_Streaming">SMEExceptionType_Streaming</anchor>,         // Illegal instruction in Streaming SVE mode
    <anchor link="enum_SMEExceptionType_NotStreaming">SMEExceptionType_NotStreaming</anchor>,      // Illegal instruction not in Streaming SVE mode
    <anchor link="enum_SMEExceptionType_InactiveZA">SMEExceptionType_InactiveZA</anchor>,        // Illegal instruction when ZA is inactive
    <anchor link="enum_SMEExceptionType_InaccessibleZT0">SMEExceptionType_InaccessibleZT0</anchor>,   // Access to ZT0 is disabled
};</pstext></ps>
    <ps name="aarch64/functions/sve/SVCR" mylink="aarch64.functions.sve.SVCR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SVCR
// ====

accessor <anchor link="accessor_SVCR_0">SVCR</anchor>() &lt;=&gt; value : SVCR_Type
begin
    // Returns PSTATE.[ZA, SM]
    getter
        let value : SVCR_Type = Zeros{62} :: <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.ZA :: <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM;
        return value;
    end;

    // Sets PSTATE.[ZA, SM]
    setter
        <a link="func_SetPSTATE_SM_1" file="shared_pseudocode.xml">SetPSTATE_SM</a>(value[0]);
        <a link="func_SetPSTATE_ZA_1" file="shared_pseudocode.xml">SetPSTATE_ZA</a>(value[1]);
        return;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/SVEAccessTrap" mylink="aarch64.functions.sve.SVEAccessTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SVEAccessTrap()
// ===============
// Trapped access to SVE registers due to CPACR_EL1, CPTR_EL2, or CPTR_EL3.

func <anchor link="func_SVEAccessTrap_1">SVEAccessTrap</anchor>(target_el : bits(2))
begin
    assert UInt(target_el) &gt;= UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) &amp;&amp; target_el != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(target_el);
    let route_to_el2 : boolean = target_el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1';

    let except : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>              = <a link="func_ExceptionSyndrome_1" file="shared_pseudocode.xml">ExceptionSyndrome</a>(<a link="enum_Exception_SVEAccessTrap" file="shared_pseudocode.xml">Exception_SVEAccessTrap</a>);
    let preferred_exception_return : bits(64) = ThisInstrAddr{}();
    let vect_offset : integer{}               = 0x0;

    if route_to_el2 then
        AArch64_TakeException(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, except, preferred_exception_return, vect_offset);
    else
        AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/SVEMoveMaskPreferred" mylink="aarch64.functions.sve.SVEMoveMaskPreferred" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SVEMoveMaskPreferred()
// ======================
// Return FALSE if a bitmask immediate encoding would generate an immediate
// value that could also be represented by a single DUP instruction.
// Used as a condition for the preferred MOV&lt;-DUPM alias.

func <anchor link="func_SVEMoveMaskPreferred_1">SVEMoveMaskPreferred</anchor>(imm13 : bits(13)) =&gt; boolean
begin
    var imm : bits(64);
    (imm, -) = <a link="func_DecodeBitMasks_5" file="shared_pseudocode.xml">DecodeBitMasks</a>{64}(imm13[12], imm13[5:0], imm13[11:6], TRUE);

    // Check for 8 bit immediates
    if !IsZero(imm[7:0]) then
        // Check for 'ffffffffffffffxy' or '00000000000000xy'
        if IsZero(imm[63:7]) || IsOnes(imm[63:7]) then
            return FALSE;
        end;

        // Check for 'ffffffxyffffffxy' or '000000xy000000xy'
        if imm[63:32] == imm[31:0] &amp;&amp; (IsZero(imm[31:7]) || IsOnes(imm[31:7])) then
            return FALSE;
        end;

        // Check for 'ffxyffxyffxyffxy' or '00xy00xy00xy00xy'
        if (imm[63:32] == imm[31:0] &amp;&amp; imm[31:16] == imm[15:0] &amp;&amp;
              (IsZero(imm[15:7]) || IsOnes(imm[15:7]))) then
            return FALSE;
        end;

        // Check for 'xyxyxyxyxyxyxyxy'
        if imm[63:32] == imm[31:0] &amp;&amp; imm[31:16] == imm[15:0] &amp;&amp; (imm[15:8] == imm[7:0]) then
            return FALSE;
        end;

    // Check for 16 bit immediates
    else
        // Check for 'ffffffffffffxy00' or '000000000000xy00'
        if IsZero(imm[63:15]) || IsOnes(imm[63:15]) then
            return FALSE;
        end;

        // Check for 'ffffxy00ffffxy00' or '0000xy000000xy00'
        if imm[63:32] == imm[31:0] &amp;&amp; (IsZero(imm[31:7]) || IsOnes(imm[31:7])) then
            return FALSE;
        end;

        // Check for 'xy00xy00xy00xy00'
        if imm[63:32] == imm[31:0] &amp;&amp; imm[31:16] == imm[15:0] then
            return FALSE;
        end;
    end;

    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/SetPSTATE_SM" mylink="aarch64.functions.sve.SetPSTATE_SM" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SetPSTATE_SM()
// ==============

func <anchor link="func_SetPSTATE_SM_1">SetPSTATE_SM</anchor>(value : bit)
begin
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM != value then
        <a link="func_ResetSVEState_0" file="shared_pseudocode.xml">ResetSVEState</a>();
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM = value;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/SetPSTATE_ZA" mylink="aarch64.functions.sve.SetPSTATE_ZA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SetPSTATE_ZA()
// ==============

func <anchor link="func_SetPSTATE_ZA_1">SetPSTATE_ZA</anchor>(value : bit)
begin
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.ZA != value then
        <a link="func_ResetSMEState_1" file="shared_pseudocode.xml">ResetSMEState</a>(value);
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.ZA = value;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sve/SupportedPowerTwoSVL" mylink="aarch64.functions.sve.SupportedPowerTwoSVL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SupportedPowerTwoSVL()
// ======================
// Return an IMPLEMENTATION DEFINED specific value
// returns TRUE if SVL is supported and is a power of two, FALSE otherwise

readonly impdef func <anchor link="func_SupportedPowerTwoSVL_0">SupportedPowerTwoSVL</anchor>(nbits : integer) =&gt; boolean
begin
    return IsPow2(nbits) &amp;&amp; (nbits &lt;= <a link="global_MAX_VL" file="shared_pseudocode.xml">MAX_VL</a>);
end;</pstext></ps>
    <ps name="aarch64/functions/sve/System" mylink="aarch64.functions.sve.System" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// System Registers
// ================

constant <anchor link="global_MAX_VL">MAX_VL</anchor> : <a link="type_VecLen" file="shared_pseudocode.xml">VecLen</a> = 2048;
constant <anchor link="global_MAX_PL">MAX_PL</anchor> : <a link="type_PredLen" file="shared_pseudocode.xml">PredLen</a> = 256;
constant <anchor link="global_ZT0_LEN">ZT0_LEN</anchor> : integer{} = 512;
var <anchor link="global__Z">_Z</anchor> : array [[32]] of bits(<a link="global_MAX_VL" file="shared_pseudocode.xml">MAX_VL</a>);
var <anchor link="global__P">_P</anchor> : array [[16]] of bits(<a link="global_MAX_PL" file="shared_pseudocode.xml">MAX_PL</a>);
var <anchor link="global__FFR">_FFR</anchor> : bits(<a link="global_MAX_PL" file="shared_pseudocode.xml">MAX_PL</a>);</pstext></ps>
    <ps name="aarch64/functions/sve/VecLen" mylink="aarch64.functions.sve.VecLen" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// VecLen
// ======

type <anchor link="type_VecLen">VecLen</anchor> of integer{128, 256, 512, 1024, 2048};</pstext></ps>
    <ps name="aarch64/functions/sve/Z" mylink="aarch64.functions.sve.Z" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Z - accessor
// ============

accessor <anchor link="accessor_Z_2">Z</anchor>{width}(n : integer) &lt;=&gt; value : bits(width)
begin
    getter
        assert n &gt;= 0 &amp;&amp; n &lt;= 31;
        assert width == <a link="func_CurrentVL_0" file="shared_pseudocode.xml">CurrentVL</a>();
        return <a link="global__Z" file="shared_pseudocode.xml">_Z</a>[[n]][width-1:0];
    end;
    setter
        assert n &gt;= 0 &amp;&amp; n &lt;= 31;
        assert width == <a link="func_CurrentVL_0" file="shared_pseudocode.xml">CurrentVL</a>();
        if <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_SVEZEROUPPER" file="shared_pseudocode.xml">Unpredictable_SVEZEROUPPER</a>) then
            <a link="global__Z" file="shared_pseudocode.xml">_Z</a>[[n]] = ZeroExtend{<a link="global_MAX_VL" file="shared_pseudocode.xml">MAX_VL</a>}(value);
        else
            <a link="global__Z" file="shared_pseudocode.xml">_Z</a>[[n]][width-1:0] = value;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/syshintop/SystemHintOp" mylink="aarch64.functions.syshintop.SystemHintOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SystemHintOp
// ============
// System Hint instruction types.

type <anchor link="type_SystemHintOp">SystemHintOp</anchor> of enumeration {
    <anchor link="enum_SystemHintOp_NOP">SystemHintOp_NOP</anchor>,
    <anchor link="enum_SystemHintOp_YIELD">SystemHintOp_YIELD</anchor>,
    <anchor link="enum_SystemHintOp_WFE">SystemHintOp_WFE</anchor>,
    <anchor link="enum_SystemHintOp_WFI">SystemHintOp_WFI</anchor>,
    <anchor link="enum_SystemHintOp_SEV">SystemHintOp_SEV</anchor>,
    <anchor link="enum_SystemHintOp_SEVL">SystemHintOp_SEVL</anchor>,
    <anchor link="enum_SystemHintOp_DGH">SystemHintOp_DGH</anchor>,
    <anchor link="enum_SystemHintOp_ESB">SystemHintOp_ESB</anchor>,
    <anchor link="enum_SystemHintOp_PSB">SystemHintOp_PSB</anchor>,
    <anchor link="enum_SystemHintOp_TSB">SystemHintOp_TSB</anchor>,
    <anchor link="enum_SystemHintOp_BTI">SystemHintOp_BTI</anchor>,
    <anchor link="enum_SystemHintOp_WFET">SystemHintOp_WFET</anchor>,
    <anchor link="enum_SystemHintOp_WFIT">SystemHintOp_WFIT</anchor>,
    <anchor link="enum_SystemHintOp_CLRBHB">SystemHintOp_CLRBHB</anchor>,
    <anchor link="enum_SystemHintOp_GCSB">SystemHintOp_GCSB</anchor>,
    <anchor link="enum_SystemHintOp_CHKFEAT">SystemHintOp_CHKFEAT</anchor>,
    <anchor link="enum_SystemHintOp_STSHH">SystemHintOp_STSHH</anchor>,
    <anchor link="enum_SystemHintOp_CSDB">SystemHintOp_CSDB</anchor>
};</pstext></ps>
    <ps name="aarch64/functions/syslop/SysLOp" mylink="aarch64.functions.syslop.SysLOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SysLOp()
// ========

func <anchor link="func_SysLOp_4">SysLOp</anchor>(op1 : bits(3), CRn : bits(4), CRm : bits(4), op2 : bits(3)) =&gt; <a link="type_SystemLOp" file="shared_pseudocode.xml">SystemLOp</a>
begin
    return <a link="enum_Sysl_SYSL" file="shared_pseudocode.xml">Sysl_SYSL</a>;
end;</pstext></ps>
    <ps name="aarch64/functions/syslop/SystemLOp" mylink="aarch64.functions.syslop.SystemLOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SystemLOp
// =========
// System instruction with result types.

type <anchor link="type_SystemLOp">SystemLOp</anchor> of enumeration {
    <anchor link="enum_Sysl_SYSL">Sysl_SYSL</anchor>
};</pstext></ps>
    <ps name="aarch64/functions/sysop/SysOp" mylink="aarch64.functions.sysop.SysOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SysOp()
// =======

func <anchor link="func_SysOp_4">SysOp</anchor>(op1 : bits(3), CRn : bits(4), CRm : bits(4), op2 : bits(3)) =&gt; <a link="type_SystemOp" file="shared_pseudocode.xml">SystemOp</a>
begin
    case op1::CRn::CRm::op2 of
        when '000 0111 1000 000' =&gt; return <a link="enum_Sys_AT" file="shared_pseudocode.xml">Sys_AT</a>;    // S1E1R
        when '000 0111 1000 001' =&gt; return <a link="enum_Sys_AT" file="shared_pseudocode.xml">Sys_AT</a>;    // S1E1W
        when '000 0111 1000 010' =&gt; return <a link="enum_Sys_AT" file="shared_pseudocode.xml">Sys_AT</a>;    // S1E0R
        when '000 0111 1000 011' =&gt; return <a link="enum_Sys_AT" file="shared_pseudocode.xml">Sys_AT</a>;    // S1E0W
        when '000 0111 1001 000' =&gt; return <a link="enum_Sys_AT" file="shared_pseudocode.xml">Sys_AT</a>;    // S1E1RP
        when '000 0111 1001 001' =&gt; return <a link="enum_Sys_AT" file="shared_pseudocode.xml">Sys_AT</a>;    // S1E1WP
        when '000 0111 1001 010' =&gt; return <a link="enum_Sys_AT" file="shared_pseudocode.xml">Sys_AT</a>;    // S1E1A
        when '100 0111 1000 000' =&gt; return <a link="enum_Sys_AT" file="shared_pseudocode.xml">Sys_AT</a>;    // S1E2R
        when '100 0111 1000 001' =&gt; return <a link="enum_Sys_AT" file="shared_pseudocode.xml">Sys_AT</a>;    // S1E2W
        when '100 0111 1001 010' =&gt; return <a link="enum_Sys_AT" file="shared_pseudocode.xml">Sys_AT</a>;    // S1E2A
        when '100 0111 1000 100' =&gt; return <a link="enum_Sys_AT" file="shared_pseudocode.xml">Sys_AT</a>;    // S12E1R
        when '100 0111 1000 101' =&gt; return <a link="enum_Sys_AT" file="shared_pseudocode.xml">Sys_AT</a>;    // S12E1W
        when '100 0111 1000 110' =&gt; return <a link="enum_Sys_AT" file="shared_pseudocode.xml">Sys_AT</a>;    // S12E0R
        when '100 0111 1000 111' =&gt; return <a link="enum_Sys_AT" file="shared_pseudocode.xml">Sys_AT</a>;    // S12E0W
        when '110 0111 1000 000' =&gt; return <a link="enum_Sys_AT" file="shared_pseudocode.xml">Sys_AT</a>;    // S1E3R
        when '110 0111 1000 001' =&gt; return <a link="enum_Sys_AT" file="shared_pseudocode.xml">Sys_AT</a>;    // S1E3W
        when '110 0111 1001 010' =&gt; return <a link="enum_Sys_AT" file="shared_pseudocode.xml">Sys_AT</a>;    // S1E3A
        when '001 0111 0010 100' =&gt; return <a link="enum_Sys_BRB" file="shared_pseudocode.xml">Sys_BRB</a>;   // IALL
        when '001 0111 0010 101' =&gt; return <a link="enum_Sys_BRB" file="shared_pseudocode.xml">Sys_BRB</a>;   // INJ
        when '000 0111 0110 001' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // IVAC
        when '000 0111 0110 010' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // ISW
        when '000 0111 0110 011' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // IGVAC
        when '000 0111 0110 100' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // IGSW
        when '000 0111 0110 101' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // IGDVAC
        when '000 0111 0110 110' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // IGDSW
        when '000 0111 1010 010' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CSW
        when '000 0111 1010 100' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CGSW
        when '000 0111 1010 110' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CGDSW
        when '000 0111 1110 010' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CISW
        when '000 0111 1110 100' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CIGSW
        when '000 0111 1110 110' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CIGDSW
        when '011 0111 0100 001' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // ZVA
        when '011 0111 0100 011' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // GVA
        when '011 0111 0100 100' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // GZVA
        when '011 0111 1010 001' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CVAC
        when '011 0111 1010 011' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CGVAC
        when '011 0111 1010 101' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CGDVAC
        when '011 0111 1011 001' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CVAU
        when '011 0111 1100 001' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CVAP
        when '011 0111 1100 011' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CGVAP
        when '011 0111 1100 101' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CGDVAP
        when '011 0111 1101 001' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CVADP
        when '011 0111 1101 011' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CGVADP
        when '011 0111 1101 101' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CGDVADP
        when '011 0111 1110 001' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CIVAC
        when '011 0111 1110 011' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CIGVAC
        when '011 0111 1110 101' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CIGDVAC
        when '100 0111 1110 000' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CIPAE
        when '100 0111 1110 111' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CIGDPAE
        when '110 0111 1110 001' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CIPAPA
        when '110 0111 1110 101' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CIGDPAPA
        when '000 0111 1111 001' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CIVAPS
        when '000 0111 1111 101' =&gt; return <a link="enum_Sys_DC" file="shared_pseudocode.xml">Sys_DC</a>;    // CIGDVAPS
        when '000 0111 0001 000' =&gt; return <a link="enum_Sys_IC" file="shared_pseudocode.xml">Sys_IC</a>;    // IALLUIS
        when '000 0111 0101 000' =&gt; return <a link="enum_Sys_IC" file="shared_pseudocode.xml">Sys_IC</a>;    // IALLU
        when '011 0111 0101 001' =&gt; return <a link="enum_Sys_IC" file="shared_pseudocode.xml">Sys_IC</a>;    // IVAU
        when '000 1000 0001 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VMALLE1OS
        when '000 1000 0001 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAE1OS
        when '000 1000 0001 010' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ASIDE1OS
        when '000 1000 0001 011' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAAE1OS
        when '000 1000 0001 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VALE1OS
        when '000 1000 0001 111' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAALE1OS
        when '000 1000 0010 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAE1IS
        when '000 1000 0010 011' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAAE1IS
        when '000 1000 0010 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVALE1IS
        when '000 1000 0010 111' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAALE1IS
        when '000 1000 0011 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VMALLE1IS
        when '000 1000 0011 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAE1IS
        when '000 1000 0011 010' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ASIDE1IS
        when '000 1000 0011 011' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAAE1IS
        when '000 1000 0011 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VALE1IS
        when '000 1000 0011 111' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAALE1IS
        when '000 1000 0101 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAE1OS
        when '000 1000 0101 011' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAAE1OS
        when '000 1000 0101 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVALE1OS
        when '000 1000 0101 111' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAALE1OS
        when '000 1000 0110 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAE1
        when '000 1000 0110 011' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAAE1
        when '000 1000 0110 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVALE1
        when '000 1000 0110 111' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAALE1
        when '000 1000 0111 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VMALLE1
        when '000 1000 0111 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAE1
        when '000 1000 0111 010' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ASIDE1
        when '000 1000 0111 011' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAAE1
        when '000 1000 0111 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VALE1
        when '000 1000 0111 111' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAALE1
        when '000 1001 0001 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VMALLE1OSNXS
        when '000 1001 0001 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAE1OSNXS
        when '000 1001 0001 010' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ASIDE1OSNXS
        when '000 1001 0001 011' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAAE1OSNXS
        when '000 1001 0001 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VALE1OSNXS
        when '000 1001 0001 111' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAALE1OSNXS
        when '000 1001 0010 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAE1ISNXS
        when '000 1001 0010 011' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAAE1ISNXS
        when '000 1001 0010 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVALE1ISNXS
        when '000 1001 0010 111' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAALE1ISNXS
        when '000 1001 0011 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VMALLE1ISNXS
        when '000 1001 0011 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAE1ISNXS
        when '000 1001 0011 010' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ASIDE1ISNXS
        when '000 1001 0011 011' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAAE1ISNXS
        when '000 1001 0011 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VALE1ISNXS
        when '000 1001 0011 111' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAALE1ISNXS
        when '000 1001 0101 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAE1OSNXS
        when '000 1001 0101 011' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAAE1OSNXS
        when '000 1001 0101 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVALE1OSNXS
        when '000 1001 0101 111' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAALE1OSNXS
        when '000 1001 0110 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAE1NXS
        when '000 1001 0110 011' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAAE1NXS
        when '000 1001 0110 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVALE1NXS
        when '000 1001 0110 111' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAALE1NXS
        when '000 1001 0111 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VMALLE1NXS
        when '000 1001 0111 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAE1NXS
        when '000 1001 0111 010' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ASIDE1NXS
        when '000 1001 0111 011' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAAE1NXS
        when '000 1001 0111 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VALE1NXS
        when '000 1001 0111 111' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAALE1NXS
        when '100 1000 0000 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // IPAS2E1IS
        when '100 1000 0000 010' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RIPAS2E1IS
        when '100 1000 0000 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // IPAS2LE1IS
        when '100 1000 0000 110' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RIPAS2LE1IS
        when '100 1000 0001 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ALLE2OS
        when '100 1000 0001 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAE2OS
        when '100 1000 0001 100' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ALLE1OS
        when '100 1000 0001 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VALE2OS
        when '100 1000 0001 110' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VMALLS12E1OS
        when '100 1000 0010 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAE2IS
        when '100 1000 0010 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVALE2IS
        when '100 1000 0011 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ALLE2IS
        when '100 1000 0011 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAE2IS
        when '100 1000 0011 100' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ALLE1IS
        when '100 1000 0011 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VALE2IS
        when '100 1000 0011 110' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VMALLS12E1IS
        when '100 1000 0100 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // IPAS2E1OS
        when '100 1000 0100 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // IPAS2E1
        when '100 1000 0100 010' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RIPAS2E1
        when '100 1000 0100 011' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RIPAS2E1OS
        when '100 1000 0100 100' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // IPAS2LE1OS
        when '100 1000 0100 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // IPAS2LE1
        when '100 1000 0100 110' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RIPAS2LE1
        when '100 1000 0100 111' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RIPAS2LE1OS
        when '100 1000 0101 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAE2OS
        when '100 1000 0101 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVALE2OS
        when '100 1000 0110 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAE2
        when '100 1000 0110 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVALE2
        when '100 1000 0111 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ALLE2
        when '100 1000 0111 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAE2
        when '100 1000 0111 100' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ALLE1
        when '100 1000 0111 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VALE2
        when '100 1000 0111 110' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VMALLS12E1
        when '100 1001 0000 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // IPAS2E1ISNXS
        when '100 1001 0000 010' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RIPAS2E1ISNXS
        when '100 1001 0000 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // IPAS2LE1ISNXS
        when '100 1001 0000 110' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RIPAS2LE1ISNXS
        when '100 1001 0001 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ALLE2OSNXS
        when '100 1001 0001 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAE2OSNXS
        when '100 1001 0001 100' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ALLE1OSNXS
        when '100 1001 0001 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VALE2OSNXS
        when '100 1001 0001 110' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VMALLS12E1OSNXS
        when '100 1001 0010 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAE2ISNXS
        when '100 1001 0010 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVALE2ISNXS
        when '100 1001 0011 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ALLE2ISNXS
        when '100 1001 0011 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAE2ISNXS
        when '100 1001 0011 100' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ALLE1ISNXS
        when '100 1001 0011 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VALE2ISNXS
        when '100 1001 0011 110' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VMALLS12E1ISNXS
        when '100 1001 0100 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // IPAS2E1OSNXS
        when '100 1001 0100 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // IPAS2E1NXS
        when '100 1001 0100 010' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RIPAS2E1NXS
        when '100 1001 0100 011' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RIPAS2E1OSNXS
        when '100 1001 0100 100' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // IPAS2LE1OSNXS
        when '100 1001 0100 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // IPAS2LE1NXS
        when '100 1001 0100 110' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RIPAS2LE1NXS
        when '100 1001 0100 111' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RIPAS2LE1OSNXS
        when '100 1001 0101 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAE2OSNXS
        when '100 1001 0101 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVALE2OSNXS
        when '100 1001 0110 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAE2NXS
        when '100 1001 0110 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVALE2NXS
        when '100 1001 0111 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ALLE2NXS
        when '100 1001 0111 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAE2NXS
        when '100 1001 0111 100' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ALLE1NXS
        when '100 1001 0111 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VALE2NXS
        when '100 1001 0111 110' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VMALLS12E1NXS
        when '110 1000 0001 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ALLE3OS
        when '110 1000 0001 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAE3OS
        when '110 1000 0001 100' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // PAALLOS
        when '110 1000 0001 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VALE3OS
        when '110 1000 0010 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAE3IS
        when '110 1000 0010 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVALE3IS
        when '110 1000 0011 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ALLE3IS
        when '110 1000 0011 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAE3IS
        when '110 1000 0011 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VALE3IS
        when '110 1000 0100 011' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RPAOS
        when '110 1000 0100 111' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RPALOS
        when '110 1000 0101 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAE3OS
        when '110 1000 0101 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVALE3OS
        when '110 1000 0110 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAE3
        when '110 1000 0110 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVALE3
        when '110 1000 0111 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ALLE3
        when '110 1000 0111 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAE3
        when '110 1000 0111 100' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // PAALL
        when '110 1000 0111 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VALE3
        when '110 1001 0001 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ALLE3OSNXS
        when '110 1001 0001 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAE3OSNXS
        when '110 1001 0001 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VALE3OSNXS
        when '110 1001 0010 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAE3ISNXS
        when '110 1001 0010 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVALE3ISNXS
        when '110 1001 0011 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ALLE3ISNXS
        when '110 1001 0011 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAE3ISNXS
        when '110 1001 0011 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VALE3ISNXS
        when '110 1001 0101 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAE3OSNXS
        when '110 1001 0101 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVALE3OSNXS
        when '110 1001 0110 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVAE3NXS
        when '110 1001 0110 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // RVALE3NXS
        when '110 1001 0111 000' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // ALLE3NXS
        when '110 1001 0111 001' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VAE3NXS
        when '110 1001 0111 101' =&gt; return <a link="enum_Sys_TLBI" file="shared_pseudocode.xml">Sys_TLBI</a>;  // VALE3NXS
        otherwise =&gt;                return <a link="enum_Sys_SYS" file="shared_pseudocode.xml">Sys_SYS</a>;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sysop/SystemOp" mylink="aarch64.functions.sysop.SystemOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SystemOp
// ========
// System instruction types.

type <anchor link="type_SystemOp">SystemOp</anchor> of enumeration {
    <anchor link="enum_Sys_AT">Sys_AT</anchor>,
    <anchor link="enum_Sys_BRB">Sys_BRB</anchor>,
    <anchor link="enum_Sys_DC">Sys_DC</anchor>,
    <anchor link="enum_Sys_IC">Sys_IC</anchor>,
    <anchor link="enum_Sys_TLBI">Sys_TLBI</anchor>,
    <anchor link="enum_Sys_SYS">Sys_SYS</anchor>
};</pstext></ps>
    <ps name="aarch64/functions/sysop_128/SysOp128" mylink="aarch64.functions.sysop_128.SysOp128" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SysOp128()
// ==========

func <anchor link="func_SysOp128_4">SysOp128</anchor>(op1 : bits(3), CRn : bits(4), CRm : bits(4), op2 : bits(3)) =&gt; <a link="type_SystemOp128" file="shared_pseudocode.xml">SystemOp128</a>
begin
    case op1::CRn::CRm::op2 of
        when '000 1000 0001 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAE1OS
        when '000 1000 0001 011' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAAE1OS
        when '000 1000 0001 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VALE1OS
        when '000 1000 0001 111' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAALE1OS
        when '000 1000 0011 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAE1IS
        when '000 1000 0011 011' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAAE1IS
        when '000 1000 0011 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VALE1IS
        when '000 1000 0011 111' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAALE1IS
        when '000 1000 0111 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAE1
        when '000 1000 0111 011' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAAE1
        when '000 1000 0111 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VALE1
        when '000 1000 0111 111' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAALE1
        when '000 1001 0001 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAE1OSNXS
        when '000 1001 0001 011' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAAE1OSNXS
        when '000 1001 0001 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VALE1OSNXS
        when '000 1001 0001 111' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAALE1OSNXS
        when '000 1001 0011 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAE1ISNXS
        when '000 1001 0011 011' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAAE1ISNXS
        when '000 1001 0011 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VALE1ISNXS
        when '000 1001 0011 111' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAALE1ISNXS
        when '000 1001 0111 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAE1NXS
        when '000 1001 0111 011' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAAE1NXS
        when '000 1001 0111 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VALE1NXS
        when '000 1001 0111 111' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAALE1NXS
        when '100 1000 0001 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAE2OS
        when '100 1000 0001 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VALE2OS
        when '100 1000 0011 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAE2IS
        when '100 1000 0011 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VALE2IS
        when '100 1000 0111 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAE2
        when '100 1000 0111 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VALE2
        when '100 1001 0001 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAE2OSNXS
        when '100 1001 0001 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VALE2OSNXS
        when '100 1001 0011 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAE2ISNXS
        when '100 1001 0011 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VALE2ISNXS
        when '100 1001 0111 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAE2NXS
        when '100 1001 0111 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VALE2NXS
        when '110 1000 0001 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAE3OS
        when '110 1000 0001 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VALE3OS
        when '110 1000 0011 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAE3IS
        when '110 1000 0011 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VALE3IS
        when '110 1000 0111 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAE3
        when '110 1000 0111 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VALE3
        when '110 1001 0001 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAE3OSNXS
        when '110 1001 0001 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VALE3OSNXS
        when '110 1001 0011 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAE3ISNXS
        when '110 1001 0011 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VALE3ISNXS
        when '110 1001 0111 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VAE3NXS
        when '110 1001 0111 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // VALE3NXS
        when '100 1000 0000 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // IPAS2E1IS
        when '100 1000 0000 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // IPAS2LE1IS
        when '100 1000 0100 000' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // IPAS2E1OS
        when '100 1000 0100 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // IPAS2E1
        when '100 1000 0100 100' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // IPAS2LE1OS
        when '100 1000 0100 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // IPAS2LE1
        when '100 1001 0000 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // IPAS2E1ISNXS
        when '100 1001 0000 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // IPAS2LE1ISNXS
        when '100 1001 0100 000' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // IPAS2E1OSNXS
        when '100 1001 0100 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // IPAS2E1NXS
        when '100 1001 0100 100' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // IPAS2LE1OSNXS
        when '100 1001 0100 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // IPAS2LE1NXS
        when '000 1000 0010 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAE1IS
        when '000 1000 0010 011' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAAE1IS
        when '000 1000 0010 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVALE1IS
        when '000 1000 0010 111' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAALE1IS
        when '000 1000 0101 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAE1OS
        when '000 1000 0101 011' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAAE1OS
        when '000 1000 0101 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVALE1OS
        when '000 1000 0101 111' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAALE1OS
        when '000 1000 0110 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAE1
        when '000 1000 0110 011' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAAE1
        when '000 1000 0110 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVALE1
        when '000 1000 0110 111' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAALE1
        when '000 1001 0010 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAE1ISNXS
        when '000 1001 0010 011' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAAE1ISNXS
        when '000 1001 0010 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVALE1ISNXS
        when '000 1001 0010 111' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAALE1ISNXS
        when '000 1001 0101 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAE1OSNXS
        when '000 1001 0101 011' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAAE1OSNXS
        when '000 1001 0101 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVALE1OSNXS
        when '000 1001 0101 111' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAALE1OSNXS
        when '000 1001 0110 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAE1NXS
        when '000 1001 0110 011' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAAE1NXS
        when '000 1001 0110 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVALE1NXS
        when '000 1001 0110 111' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAALE1NXS
        when '100 1000 0010 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAE2IS
        when '100 1000 0010 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVALE2IS
        when '100 1000 0101 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAE2OS
        when '100 1000 0101 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVALE2OS
        when '100 1000 0110 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAE2
        when '100 1000 0110 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVALE2
        when '100 1001 0010 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAE2ISNXS
        when '100 1001 0010 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVALE2ISNXS
        when '100 1001 0101 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAE2OSNXS
        when '100 1001 0101 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVALE2OSNXS
        when '100 1001 0110 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAE2NXS
        when '100 1001 0110 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVALE2NXS
        when '110 1000 0010 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAE3IS
        when '110 1000 0010 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVALE3IS
        when '110 1000 0101 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAE3OS
        when '110 1000 0101 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVALE3OS
        when '110 1000 0110 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAE3
        when '110 1000 0110 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVALE3
        when '110 1001 0010 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAE3ISNXS
        when '110 1001 0010 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVALE3ISNXS
        when '110 1001 0101 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAE3OSNXS
        when '110 1001 0101 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVALE3OSNXS
        when '110 1001 0110 001' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVAE3NXS
        when '110 1001 0110 101' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RVALE3NXS
        when '100 1000 0000 010' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RIPAS2E1IS
        when '100 1000 0000 110' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RIPAS2LE1IS
        when '100 1000 0100 010' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RIPAS2E1
        when '100 1000 0100 011' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RIPAS2E1OS
        when '100 1000 0100 110' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RIPAS2LE1
        when '100 1000 0100 111' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RIPAS2LE1OS
        when '100 1001 0000 010' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RIPAS2E1ISNXS
        when '100 1001 0000 110' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RIPAS2LE1ISNXS
        when '100 1001 0100 010' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RIPAS2E1NXS
        when '100 1001 0100 011' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RIPAS2E1OSNXS
        when '100 1001 0100 110' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RIPAS2LE1NXS
        when '100 1001 0100 111' =&gt; return <a link="enum_Sys_TLBIP" file="shared_pseudocode.xml">Sys_TLBIP</a>;  // RIPAS2LE1OSNXS
        otherwise                =&gt; return <a link="enum_Sys_SYSP" file="shared_pseudocode.xml">Sys_SYSP</a>;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sysop_128/SystemOp128" mylink="aarch64.functions.sysop_128.SystemOp128" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SystemOp128()
// =============
// System instruction types.

type <anchor link="type_SystemOp128">SystemOp128</anchor> of enumeration {<anchor link="enum_Sys_TLBIP">Sys_TLBIP</anchor>, <anchor link="enum_Sys_SYSP">Sys_SYSP</anchor>};</pstext></ps>
    <ps name="aarch64/functions/sysregisters/ELR_EL" mylink="aarch64.functions.sysregisters.ELR_EL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ELR_EL - accessor
// =================

accessor <anchor link="accessor_ELR_EL_1">ELR_EL</anchor>(el : bits(2)) &lt;=&gt; value : bits(64)
begin
    getter
        var r : bits(64);
        case el of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;  r = ELR_EL1();
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;  r = ELR_EL2();
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;  r = ELR_EL3();
            otherwise =&gt; unreachable;
        end;
        return r;
    end;
    setter
        let r : bits(64) = value;
        case el of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;  ELR_EL1() = r;
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;  ELR_EL2() = r;
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;  ELR_EL3() = r;
            otherwise =&gt; unreachable;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sysregisters/ELR_ELx" mylink="aarch64.functions.sysregisters.ELR_ELx" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ELR_ELx - accessor
// ==================

accessor <anchor link="accessor_ELR_ELx_0">ELR_ELx</anchor>() &lt;=&gt; value : bits(64)
begin
    getter
        assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
        return <a link="accessor_ELR_EL_1" file="shared_pseudocode.xml">ELR_EL</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    end;
    setter
        assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
        <a link="accessor_ELR_EL_1" file="shared_pseudocode.xml">ELR_EL</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) = value;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sysregisters/ESR_EL" mylink="aarch64.functions.sysregisters.ESR_EL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ESR_EL - accessor
// =================

accessor <anchor link="accessor_ESR_EL_1">ESR_EL</anchor>(regime : bits(2)) &lt;=&gt; value : ESRType
begin
    getter
        var r : bits(64);
        case regime of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;  r = ESR_EL1();
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;  r = ESR_EL2();
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;  r = ESR_EL3();
            otherwise =&gt; unreachable;
        end;
        return r;
    end;
    setter
        let r : bits(64) = value;
        case regime of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;  ESR_EL1() = r;
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;  ESR_EL2() = r;
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;  ESR_EL3() = r;
            otherwise =&gt; unreachable;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sysregisters/ESR_ELx" mylink="aarch64.functions.sysregisters.ESR_ELx" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ESR_ELx - accessor
// ==================

accessor <anchor link="accessor_ESR_ELx_0">ESR_ELx</anchor>() &lt;=&gt; value : ESRType
begin
    getter
        return <a link="accessor_ESR_EL_1" file="shared_pseudocode.xml">ESR_EL</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>());
    end;

    setter
        <a link="accessor_ESR_EL_1" file="shared_pseudocode.xml">ESR_EL</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>()) = value;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sysregisters/FAR_EL" mylink="aarch64.functions.sysregisters.FAR_EL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FAR_EL - accessor
// =================

accessor <anchor link="accessor_FAR_EL_1">FAR_EL</anchor>(regime : bits(2)) &lt;=&gt; value : bits(64)
begin
    getter
        var r : bits(64);
        case regime of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;  r = FAR_EL1();
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;  r = FAR_EL2();
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;  r = FAR_EL3();
            otherwise =&gt; unreachable;
        end;
        return r;
    end;
    setter
        let r : bits(64) = value;
        case regime of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;  FAR_EL1() = r;
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;  FAR_EL2() = r;
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;  FAR_EL3() = r;
            otherwise =&gt; unreachable;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sysregisters/FAR_ELx" mylink="aarch64.functions.sysregisters.FAR_ELx" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FAR_ELx - accessor
// ==================

accessor <anchor link="accessor_FAR_ELx_0">FAR_ELx</anchor>() &lt;=&gt; value : bits(64)
begin
    getter
        return <a link="accessor_FAR_EL_1" file="shared_pseudocode.xml">FAR_EL</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>());
    end;

    setter
        <a link="accessor_FAR_EL_1" file="shared_pseudocode.xml">FAR_EL</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>()) = value;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sysregisters/PFAR_EL" mylink="aarch64.functions.sysregisters.PFAR_EL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PFAR_EL - accessor
// ==================

accessor <anchor link="accessor_PFAR_EL_1">PFAR_EL</anchor>(regime : bits(2)) &lt;=&gt; value : bits(64)
begin
    getter
        assert (IsFeatureImplemented(FEAT_PFAR) ||
                 (regime == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; IsFeatureImplemented(FEAT_RME)));
        var r : bits(64);
        case regime of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt; r = PFAR_EL1();
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt; r = PFAR_EL2();
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt; r = MFAR_EL3();
            otherwise =&gt; unreachable;
        end;
        return r;
    end;
    setter
        let r : bits(64) = value;
        assert (IsFeatureImplemented(FEAT_PFAR) ||
                   (IsFeatureImplemented(FEAT_RME) &amp;&amp; regime == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>));
        case regime of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt; PFAR_EL1() = r;
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt; PFAR_EL2() = r;
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt; MFAR_EL3() = r;
            otherwise =&gt; unreachable;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sysregisters/PFAR_ELx" mylink="aarch64.functions.sysregisters.PFAR_ELx" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PFAR_ELx - accessor
// ===================

accessor <anchor link="accessor_PFAR_ELx_0">PFAR_ELx</anchor>() &lt;=&gt; value : bits(64)
begin
    getter
        return <a link="accessor_PFAR_EL_1" file="shared_pseudocode.xml">PFAR_EL</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>());
    end;

    setter
        <a link="accessor_PFAR_EL_1" file="shared_pseudocode.xml">PFAR_EL</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>()) = value;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sysregisters/SCTLR_EL" mylink="aarch64.functions.sysregisters.SCTLR_EL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SCTLR_EL - accessor
// ===================

accessor <anchor link="accessor_SCTLR_EL_1">SCTLR_EL</anchor>(regime : bits(2)) &lt;=&gt; value : SCTLRType
begin
    getter
        var r : bits(64);
        case regime of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;  r = SCTLR_EL1();
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;  r = SCTLR_EL2();
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;  r = SCTLR_EL3();
            otherwise =&gt; unreachable;
        end;
        return r;
    end;
    setter
        let r : bits(64) = value;
        case regime of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt; SCTLR_EL1() = r;
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt; SCTLR_EL2() = r;
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt; SCTLR_EL3() = r;
            otherwise =&gt; unreachable;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sysregisters/SCTLR_ELx" mylink="aarch64.functions.sysregisters.SCTLR_ELx" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SCTLR_ELx - accessor
// ====================

accessor <anchor link="accessor_SCTLR_ELx_0">SCTLR_ELx</anchor>() &lt;=&gt; value : SCTLRType
begin
    getter
        return <a link="accessor_SCTLR_EL_1" file="shared_pseudocode.xml">SCTLR_EL</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>());
    end;
    setter
        <a link="accessor_SCTLR_EL_1" file="shared_pseudocode.xml">SCTLR_EL</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>()) = value;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sysregisters/VBAR_EL" mylink="aarch64.functions.sysregisters.VBAR_EL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// VBAR_EL - accessor
// ==================

accessor <anchor link="accessor_VBAR_EL_1">VBAR_EL</anchor>(regime : bits(2)) &lt;=&gt; value : bits(64)
begin
    getter
        var r : bits(64);
        case regime of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;  r = VBAR_EL1();
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;  r = VBAR_EL2();
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;  r = VBAR_EL3();
            otherwise =&gt; unreachable;
        end;
        return r;
    end;
    setter
        pass;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/sysregisters/VBAR_ELx" mylink="aarch64.functions.sysregisters.VBAR_ELx" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// VBAR_ELx - accessor
// ===================

accessor <anchor link="accessor_VBAR_ELx_0">VBAR_ELx</anchor>() &lt;=&gt; value : bits(64)
begin
    getter
        return <a link="accessor_VBAR_EL_1" file="shared_pseudocode.xml">VBAR_EL</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>());
    end;
    setter
        <a link="accessor_VBAR_EL_1" file="shared_pseudocode.xml">VBAR_EL</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>())[63:0] = value;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_CheckDAIFAccess" mylink="aarch64.functions.system.AArch64_CheckDAIFAccess" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CheckDAIFAccess()
// =========================
// Check that an AArch64 MSR/MRS access to the DAIF flags is permitted.

func <anchor link="func_AArch64_CheckDAIFAccess_1">AArch64_CheckDAIFAccess</anchor>(field : <a link="type_PSTATEField" file="shared_pseudocode.xml">PSTATEField</a>)
begin
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; field IN {<a link="enum_PSTATEField_DAIFSet" file="shared_pseudocode.xml">PSTATEField_DAIFSet</a>, <a link="enum_PSTATEField_DAIFClr" file="shared_pseudocode.xml">PSTATEField_DAIFClr</a>} then
        if <a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() || SCTLR_EL1().UMA == '0' then
            if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1' then
                <a link="func_AArch64_SystemAccessTrap_2" file="shared_pseudocode.xml">AArch64_SystemAccessTrap</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, 0x18);
            else
                <a link="func_AArch64_SystemAccessTrap_2" file="shared_pseudocode.xml">AArch64_SystemAccessTrap</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, 0x18);
            end;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_ChooseNonExcludedTag" mylink="aarch64.functions.system.AArch64_ChooseNonExcludedTag" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ChooseNonExcludedTag()
// ==============================
// Return a tag derived from the start and the offset values, excluding
// any tags in the given mask.

func <anchor link="func_AArch64_ChooseNonExcludedTag_3">AArch64_ChooseNonExcludedTag</anchor>(tag_in : bits(4), offset_in : bits(4),
                                  exclude : bits(16)) =&gt; bits(4)
begin
    var tag : bits(4) = tag_in;
    var offset : bits(4) = offset_in;

    if IsOnes(exclude) then
        return '0000';
    end;

    if offset == '0000' then
        while exclude[UInt(tag)] == '1' looplimit 16 do
            tag = tag + '0001';
        end;
    end;

    while offset != '0000' looplimit 16 do
        offset = offset - '0001';
        tag = tag + '0001';
        while exclude[UInt(tag)] == '1' looplimit 16 do
            tag = tag + '0001';
        end;
    end;

    return tag;
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_ChooseNonExludedTagOrZero" mylink="aarch64.functions.system.AArch64_ChooseNonExludedTagOrZero" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ChooseNonExludedTagOrZero()
// ===================================
// Return a tag derived from the start and the offset values, excluding any
// tags in the given mask, or zero if Allocation Tag access is not enabled.

func <anchor link="func_AArch64_ChooseNonExcludedTagOrZero_3">AArch64_ChooseNonExcludedTagOrZero</anchor>(tag : bits(4), offset : bits(4),
                                        exclude : bits(16)) =&gt; bits(4)
begin
    if <a link="func_IsMTEEnabled_1" file="shared_pseudocode.xml">IsMTEEnabled</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) then
        return <a link="func_AArch64_ChooseNonExcludedTag_3" file="shared_pseudocode.xml">AArch64_ChooseNonExcludedTag</a>(tag, offset, exclude);
    else
        return '0000';
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_ChooseTagOrZero" mylink="aarch64.functions.system.AArch64_ChooseTagOrZero" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ChooseTagOrZero()
// =========================
// Return a tag, excluding any tags in the given mask, , or zero if Allocation
// Tag access is not enabled.

func <anchor link="func_AArch64_ChooseTagOrZero_1">AArch64_ChooseTagOrZero</anchor>(exclude : bits(16)) =&gt; bits(4)
begin
    if <a link="func_IsMTEEnabled_1" file="shared_pseudocode.xml">IsMTEEnabled</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) then
        if GCR_EL1().RRND == '1' then
            if IsOnes(exclude) then
                return '0000';
            else
                return <a link="func_ChooseRandomNonExcludedTag_1" file="shared_pseudocode.xml">ChooseRandomNonExcludedTag</a>(exclude);
            end;
        else
            let start_tag : bits(4) = RGSR_EL1().TAG;
            let offset : bits(4)    = <a link="func_AArch64_RandomTag_0" file="shared_pseudocode.xml">AArch64_RandomTag</a>();

            RGSR_EL1().TAG = <a link="func_AArch64_ChooseNonExcludedTag_3" file="shared_pseudocode.xml">AArch64_ChooseNonExcludedTag</a>(start_tag, offset, exclude);

            return RGSR_EL1().TAG;
        end;
    else
        return '0000';
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_ExecutingERETInstr" mylink="aarch64.functions.system.AArch64_ExecutingERETInstr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ExecutingERETInstr()
// ============================
// Returns TRUE if current instruction is ERET.

func <anchor link="func_AArch64_ExecutingERETInstr_0">AArch64_ExecutingERETInstr</anchor>() =&gt; boolean
begin
    let instr : bits(32) = <a link="func_ThisInstr_0" file="shared_pseudocode.xml">ThisInstr</a>();
    return instr[31:12] == '11010110100111110000';
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_ImpDefSysInstr" mylink="aarch64.functions.system.AArch64_ImpDefSysInstr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ImpDefSysInstr()
// ========================
// Execute an implementation-defined system instruction with write (source operand).

impdef func AArch64_ImpDefSysInstr(op0 : bits(2), op1 : bits(3), crn : bits(4),
                                   crm : bits(4), op2 : bits(3), t : integer)
begin
    Undefined();
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_ImpDefSysInstr128" mylink="aarch64.functions.system.AArch64_ImpDefSysInstr128" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ImpDefSysInstr128()
// ===========================
// Execute an implementation-defined system instruction with write (128-bit source operand).

impdef func AArch64_ImpDefSysInstr128(op0 : bits(2), op1 : bits(3), crn : bits(4),
                                      crm : bits(4), op2 : bits(3),
                                      t : integer, t2 : integer)
begin
    Undefined();
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_ImpDefSysInstrWithResult" mylink="aarch64.functions.system.AArch64_ImpDefSysInstrWithResult" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ImpDefSysInstrWithResult()
// ==================================
// Execute an implementation-defined system instruction with read (result operand).

impdef func AArch64_ImpDefSysInstrWithResult(op0 : bits(2),
                                             op1 : bits(3),
                                             crn : bits(4),
                                             crm : bits(4),
                                             op2 : bits(3),
                                             t : integer)
begin
    Undefined();
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_ImpDefSysRegRead" mylink="aarch64.functions.system.AArch64_ImpDefSysRegRead" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ImpDefSysRegRead()
// ==========================
// Read from an implementation-defined System register and write the contents of the register
// to X[t].

impdef func AArch64_ImpDefSysRegRead(op0 : bits(2), op1 : bits(3),
                                     crn : bits(4), crm : bits(4),
                                     op2 : bits(3), t : integer)
begin
    Undefined();
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_ImpDefSysRegRead128" mylink="aarch64.functions.system.AArch64_ImpDefSysRegRead128" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ImpDefSysRegRead128()
// =============================
// Read from an 128-bit implementation-defined System register
// and write the contents of the register to X[t], X[t+1].

impdef func AArch64_ImpDefSysRegRead128(op0 : bits(2),
                                        op1 : bits(3), crn : bits(4),
                                        crm : bits(4), op2 : bits(3),
                                        t : integer, t2 : integer)
begin
    Undefined();
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_ImpDefSysRegWrite" mylink="aarch64.functions.system.AArch64_ImpDefSysRegWrite" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ImpDefSysRegWrite()
// ===========================
// Write to an implementation-defined System register.

impdef func AArch64_ImpDefSysRegWrite(op0 : bits(2), op1 : bits(3), crn : bits(4),
                                      crm : bits(4), op2 : bits(3), t : integer)
begin
    Undefined();
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_ImpDefSysRegWrite128" mylink="aarch64.functions.system.AArch64_ImpDefSysRegWrite128" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ImpDefSysRegWrite128()
// ==============================
// Write the contents of X[t], X[t+1] to an 128-bit implementation-defined System register.

impdef func AArch64_ImpDefSysRegWrite128(op0 : bits(2), op1 : bits(3), crn : bits(4),
                                         crm : bits(4), op2 : bits(3),
                                         t : integer, t2 : integer)
begin
    Undefined();
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_InterruptPending" mylink="aarch64.functions.system.AArch64_InterruptPending" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_InterruptPending()
// ==========================
// Returns TRUE if there are any pending physical, virtual, or delegated
// interrupts, and FALSE otherwise.

func <anchor link="func_AArch64_InterruptPending_0">AArch64_InterruptPending</anchor>() =&gt; boolean
begin
    let (irq_pending, -) = <a link="func_IRQPending_0" file="shared_pseudocode.xml">IRQPending</a>();
    let (fiq_pending, -) = <a link="func_FIQPending_0" file="shared_pseudocode.xml">FIQPending</a>();
    let pending_physical_interrupt : boolean = (irq_pending || fiq_pending ||
                                                   <a link="func_IsPhysicalSErrorPending_0" file="shared_pseudocode.xml">IsPhysicalSErrorPending</a>());

    var pending_virtual_interrupt : boolean = FALSE;
    if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; HCR_EL2().TGE == '0' then
        let virq_pending : boolean = (HCR_EL2().IMO == '1' &amp;&amp; (<a link="func_VirtualIRQPending_0" file="shared_pseudocode.xml">VirtualIRQPending</a>() ||
                                         HCR_EL2().VI == '1'));
        let vfiq_pending : boolean = (HCR_EL2().FMO == '1' &amp;&amp; (<a link="func_VirtualFIQPending_0" file="shared_pseudocode.xml">VirtualFIQPending</a>() ||
                                         HCR_EL2().VF == '1'));
        let vsei_pending : boolean = ((HCR_EL2().AMO == '1' ||
                                       (IsFeatureImplemented(FEAT_DoubleFault2) &amp;&amp;
                                         <a link="func_IsHCRXEL2Enabled_0" file="shared_pseudocode.xml">IsHCRXEL2Enabled</a>() &amp;&amp; HCRX_EL2().TMEA == '1')) &amp;&amp;
                                       (<a link="func_IsVirtualSErrorPending_0" file="shared_pseudocode.xml">IsVirtualSErrorPending</a>() || HCR_EL2().VSE == '1'));

        pending_virtual_interrupt = vsei_pending || virq_pending || vfiq_pending;
    end;

    let pending_delegated_interrupt : boolean = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp;
                                                 <a link="func_EffectiveSCR_EL3_EnDSE_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_EnDSE</a>() == '1' &amp;&amp;
                                                 SCR_EL3().DSE == '1');

    return pending_physical_interrupt || pending_virtual_interrupt || pending_delegated_interrupt;
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_NextRandomTagBit" mylink="aarch64.functions.system.AArch64_NextRandomTagBit" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_NextRandomTagBit()
// ==========================
// Generate a random bit suitable for generating a random Allocation Tag.

func <anchor link="func_AArch64_NextRandomTagBit_0">AArch64_NextRandomTagBit</anchor>() =&gt; bit
begin
    assert GCR_EL1().RRND == '0';
    let lfsr : bits(16) = RGSR_EL1().SEED[15:0];
    let top : bit = lfsr[5] XOR lfsr[3] XOR lfsr[2] XOR lfsr[0];
    RGSR_EL1().SEED[15:0] = top::lfsr[15:1];
    return top;
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_RandomTag" mylink="aarch64.functions.system.AArch64_RandomTag" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_RandomTag()
// ===================
// Generate a random Allocation Tag.

func <anchor link="func_AArch64_RandomTag_0">AArch64_RandomTag</anchor>() =&gt; bits(4)
begin
    var tag : bits(4);
    for i = 0 to 3 do
        tag[i] = <a link="func_AArch64_NextRandomTagBit_0" file="shared_pseudocode.xml">AArch64_NextRandomTagBit</a>();
    end;
    return tag;
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_SysInstr" mylink="aarch64.functions.system.AArch64_SysInstr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SysInstr()
// ==================
// Execute a system instruction with write (source operand).

impdef func AArch64_SysInstr(op0 : bits(2), op1 : bits(3),
                             crn : bits(4), crm : bits(4), op2 : bits(3), t : integer)
begin
    Unimplemented();
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_SysInstrWithResult" mylink="aarch64.functions.system.AArch64_SysInstrWithResult" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SysInstrWithResult()
// ============================
// Execute a system instruction with read (result operand).
// Writes the result of the instruction to X[t].

impdef func AArch64_SysInstrWithResult(op0 : bits(2), op1 : bits(3),
                                       crn : bits(4), crm : bits(4),
                                       op2 : bits(3), t : integer)
begin
    Unimplemented();
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_SysRegRead" mylink="aarch64.functions.system.AArch64_SysRegRead" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SysRegRead()
// ====================
// Read from a System register and write the contents of the register to X[t].

impdef func AArch64_SysRegRead(op0 : bits(2), op1 : bits(3), crn : bits(4),
                               crm : bits(4), op2 : bits(3), t : integer)
begin
    Unimplemented();
end;</pstext></ps>
    <ps name="aarch64/functions/system/AArch64_SysRegWrite" mylink="aarch64.functions.system.AArch64_SysRegWrite" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SysRegWrite()
// =====================
// Write to a System register.

impdef func AArch64_SysRegWrite(op0 : bits(2), op1 : bits(3), crn : bits(4),
                                crm : bits(4), op2 : bits(3), t : integer)
begin
    Unimplemented();
end;</pstext></ps>
    <ps name="aarch64/functions/system/BTypeCompatible" mylink="aarch64.functions.system.BTypeCompatible" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BTypeCompatible
// ===============
// Records the branch target compatibility.
// Returns TRUE if the branch target is compatible with PSTATE.BTYPE, else FALSE.

var <anchor link="global_BTypeCompatible">BTypeCompatible</anchor> : boolean;</pstext></ps>
    <ps name="aarch64/functions/system/BTypeCompatible_BTI" mylink="aarch64.functions.system.BTypeCompatible_BTI" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BTypeCompatible_BTI
// ===================
// This function determines whether a given hint encoding is compatible with the current value of
// PSTATE.BTYPE. A value of TRUE here indicates a valid Branch Target Identification instruction.

func <anchor link="func_BTypeCompatible_BTI_1">BTypeCompatible_BTI</anchor>(hintcode : bits(2)) =&gt; boolean
begin
    case hintcode of
        when '00' =&gt;
            return <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.BTYPE == '00';
        when '01' =&gt;
            return <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.BTYPE != '11';
        when '10' =&gt;
            return <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.BTYPE != '10';
        when '11' =&gt;
            return TRUE;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/system/BTypeCompatible_PAC" mylink="aarch64.functions.system.BTypeCompatible_PAC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BTypeCompatible_PAC()
// =====================
// Returns TRUE if PACIxSP or PACIxSPPC instructions are implicitly compatible with PSTATE.BTYPE,
// FALSE otherwise.

func <anchor link="func_BTypeCompatible_PAC_1">BTypeCompatible_PAC</anchor>(pacinst : <a link="type_PACInstType" file="shared_pseudocode.xml">PACInstType</a>) =&gt; boolean
begin
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.BTYPE != '11' then
        return TRUE;
    else
        let index : integer = if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then 35 else 36;
        return <a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>()[index] == '0';
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/system/BTypeCompatible_PACIXSP" mylink="aarch64.functions.system.BTypeCompatible_PACIXSP" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BTypeCompatible_PACIXSP()
// =========================
// Returns TRUE if PACIASP or PACIBSP instructions are implicitly compatible with PSTATE.BTYPE,
// FALSE otherwise.

func <anchor link="func_BTypeCompatible_PACIXSP_0">BTypeCompatible_PACIXSP</anchor>() =&gt; boolean
begin
    let pacinst : <a link="type_PACInstType" file="shared_pseudocode.xml">PACInstType</a> = <a link="enum_PACIxSP" file="shared_pseudocode.xml">PACIxSP</a>;
    return <a link="func_BTypeCompatible_PAC_1" file="shared_pseudocode.xml">BTypeCompatible_PAC</a>(pacinst);
end;</pstext></ps>
    <ps name="aarch64/functions/system/BTypeNext" mylink="aarch64.functions.system.BTypeNext" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BTypeNext
// =========
// Updated every cycle with a value that depends upon the instruction being executed. Assigned to
// PSTATE.BTYPE at the end of each cycle and then cleared to zero. Allows SPSR save/restore of
// BTYPE for the current instruction being executed.

var <anchor link="global_BTypeNext">BTypeNext</anchor> : bits(2);</pstext></ps>
    <ps name="aarch64/functions/system/ChooseRandomNonExcludedTag" mylink="aarch64.functions.system.ChooseRandomNonExcludedTag" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ChooseRandomNonExcludedTag()
// ============================
// The ChooseRandomNonExcludedTag function is used when GCR_EL1.RRND == '1' to generate random
// Allocation Tags.
//
// The resulting Allocation Tag is selected from the set [0,15], excluding any Allocation Tag where
// exclude[tag_value] == 1. If 'exclude' is all Ones, the returned Allocation Tag is '0000'.
//
// This function is permitted to generate a non-deterministic selection from the set of non-excluded
// Allocation Tags. A reasonable implementation should select a tag from a uniform distribution and
// avoid common pitfalls such as modulo bias.
//
// This function can read RGSR_EL1 and/or write RGSR_EL1 to an IMPLEMENTATION DEFINED value.
// If it is not capable of writing RGSR_EL1.SEED[15:0] to zero from a previous nonzero
// RGSR_EL1.SEED value, it is IMPLEMENTATION DEFINED whether the randomness is significantly
// impacted if RGSR_EL1.SEED[15:0] is set to zero.

impdef func <anchor link="func_ChooseRandomNonExcludedTag_1">ChooseRandomNonExcludedTag</anchor>(exclude_in : bits(16)) =&gt; bits(4)
begin
    return ARBITRARY : bits(4);
end;</pstext></ps>
    <ps name="aarch64/functions/system/EffectiveBADDR" mylink="aarch64.functions.system.EffectiveBADDR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveBADDR()
// ================
// Check if the given VA, held in a register BADDR field, is RESS and apply
// CONSTRAINED UNPREDICTABLE behavior if it is not.

func <anchor link="func_EffectiveBADDR_2">EffectiveBADDR</anchor>(baddr_in : bits(64), directread : boolean) =&gt; bits(64)
begin
    var baddr : bits(64) = baddr_in;
    // Determine top bit position based on feature support.
    let n : integer{} = (if IsFeatureImplemented(FEAT_LVA3) then 57
                         else (if IsFeatureImplemented(FEAT_LVA) then 53
                         else 49));

    // Check if the upper bits of the base address form a valid sign extension.
    if baddr[63:n] != Replicate{64-n}(baddr[n-1]) then
        let c = ConstrainUnpredictable(<a link="enum_Unpredictable_BADDR_RESS" file="shared_pseudocode.xml">Unpredictable_BADDR_RESS</a>);
        assert c IN {<a link="enum_Constraint_RESS" file="shared_pseudocode.xml">Constraint_RESS</a>, <a link="enum_Constraint_ALLRESS" file="shared_pseudocode.xml">Constraint_ALLRESS</a>, <a link="enum_Constraint_FAULT" file="shared_pseudocode.xml">Constraint_FAULT</a>};
        if c == <a link="enum_Constraint_ALLRESS" file="shared_pseudocode.xml">Constraint_ALLRESS</a> || (!directread &amp;&amp; c == <a link="enum_Constraint_RESS" file="shared_pseudocode.xml">Constraint_RESS</a>) then
            baddr[63:n] = Replicate{64-n}(baddr[n-1]);
        end;
        // If c == Constraint_FAULT, baddr will cause an Address Size fault when used.
    end;

    return baddr;
end;</pstext></ps>
    <ps name="aarch64/functions/system/EffectiveICC_SRE_EL2_Enable" mylink="aarch64.functions.system.EffectiveICC_SRE_EL2_Enable" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveICC_SRE_EL2_Enable()
// =============================
// Returns the Effective value of ICC_SRE_EL2.Enable

func <anchor link="func_EffectiveICC_SRE_EL2_Enable_0">EffectiveICC_SRE_EL2_Enable</anchor>() =&gt; bit
begin
    if (ImpDefBool(&quot;Treat ICC_SRE_EL2.SRE as RAO/WI&quot;) &amp;&amp;
          ImpDefBool(&quot;Treat ICC_SRE_EL2.Enable as RAO/WI&quot;)) then
        return '1';
    end;
    if ICC_SRE_EL2().SRE == '0' then
        return '1';
    end;

    return ICC_SRE_EL2().Enable;
end;</pstext></ps>
    <ps name="aarch64/functions/system/EffectiveICC_SRE_EL3_Enable" mylink="aarch64.functions.system.EffectiveICC_SRE_EL3_Enable" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveICC_SRE_EL3_Enable()
// =============================
// Returns the Effective value of ICC_SRE_EL3.Enable

func <anchor link="func_EffectiveICC_SRE_EL3_Enable_0">EffectiveICC_SRE_EL3_Enable</anchor>() =&gt; bit
begin

    return ICC_SRE_EL3().Enable;
end;</pstext></ps>
    <ps name="aarch64/functions/system/InGuardedPage" mylink="aarch64.functions.system.InGuardedPage" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// InGuardedPage
// =============
// Records whether the currently fetched instruction was retrieved from a guarded page, will be
// TRUE if the GP bit in the page or block descriptor for the current instruction fetch was equal
// to one.

var <anchor link="global_InGuardedPage">InGuardedPage</anchor> : boolean;</pstext></ps>
    <ps name="aarch64/functions/system/IsHCRXEL2Enabled" mylink="aarch64.functions.system.IsHCRXEL2Enabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsHCRXEL2Enabled()
// ==================
// Returns TRUE if access to HCRX_EL2 register is enabled, and FALSE otherwise.
// Indirect read of HCRX_EL2 returns 0 when access is not enabled.

readonly func <anchor link="func_IsHCRXEL2Enabled_0">IsHCRXEL2Enabled</anchor>() =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_HCX) then return FALSE; end;
    if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then return FALSE; end;
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().HXEn == '0' then
        return FALSE;
    end;

    return <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>();
end;</pstext></ps>
    <ps name="aarch64/functions/system/IsMTEEnabled" mylink="aarch64.functions.system.IsMTEEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsMTEEnabled()
// ==============
// Returns TRUE if the currently selected MTE mechanism is enabled, and FALSE otherwise.

func <anchor link="func_IsMTEEnabled_1">IsMTEEnabled</anchor>(el : bits(2)) =&gt; boolean
begin
    let regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a> = <a link="func_TranslationRegime_1" file="shared_pseudocode.xml">TranslationRegime</a>(el);
    var selected : boolean = FALSE;

    if <a link="func_IsPMTESelected_1" file="shared_pseudocode.xml">IsPMTESelected</a>(el) then
        if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().ATA == '0' &amp;&amp; el IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>} then
            return FALSE;
        end;

        if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) &amp;&amp; HCR_EL2().ATA == '0' &amp;&amp; el IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} then
            return FALSE;
        end;

        selected = TRUE;
    end;

    if selected then
        case regime of
            when <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> =&gt;
                return SCTLR_EL3().ATA == '1';
            when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> =&gt;
                return SCTLR_EL2().ATA == '1';
            when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt;
                return if el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then SCTLR_EL2().ATA0 == '1' else SCTLR_EL2().ATA == '1';
            when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt;
                return if el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then SCTLR_EL1().ATA0 == '1' else SCTLR_EL1().ATA == '1';
            otherwise =&gt; unreachable;
        end;
    end;

    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/functions/system/IsPMTESelected" mylink="aarch64.functions.system.IsPMTESelected" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsPMTESelected()
// ================
// Returns TRUE if Physical MTE is selected for the translation regime
// associated with the EL, and FALSE otherwise

func <anchor link="func_IsPMTESelected_1">IsPMTESelected</anchor>(el : bits(2)) =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_MTE2) then
        return FALSE;
    end;

    return TRUE;
end;</pstext></ps>
    <ps name="aarch64/functions/system/IsSCTLR2EL1Enabled" mylink="aarch64.functions.system.IsSCTLR2EL1Enabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsSCTLR2EL1Enabled()
// ====================
// Returns TRUE if access to SCTLR2_EL1 register is enabled, and FALSE otherwise.
// Indirect read of SCTLR2_EL1 returns 0 when access is not enabled.

func <anchor link="func_IsSCTLR2EL1Enabled_0">IsSCTLR2EL1Enabled</anchor>() =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_SCTLR2) then return FALSE; end;
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().SCTLR2En == '0' then
        return FALSE;
    elsif (<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; (!<a link="func_IsHCRXEL2Enabled_0" file="shared_pseudocode.xml">IsHCRXEL2Enabled</a>() || HCRX_EL2().SCTLR2En == '0')) then
        return FALSE;
    else
        return TRUE;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/system/IsSCTLR2EL2Enabled" mylink="aarch64.functions.system.IsSCTLR2EL2Enabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsSCTLR2EL2Enabled()
// ====================
// Returns TRUE if access to SCTLR2_EL2 register is enabled, and FALSE otherwise.
// Indirect read of SCTLR2_EL2 returns 0 when access is not enabled.

func <anchor link="func_IsSCTLR2EL2Enabled_0">IsSCTLR2EL2Enabled</anchor>() =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_SCTLR2) then return FALSE; end;
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().SCTLR2En == '0' then
        return FALSE;
    end;

    return <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>();
end;</pstext></ps>
    <ps name="aarch64/functions/system/IsSystemRegisterMaskingEnabled" mylink="aarch64.functions.system.IsSystemRegisterMaskingEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsSystemRegisterMaskingEnabled()
// ================================
// Returns TRUE if access to the MASK registers introduced by FEAT_SRMASK is enabled and the
// values in the register are not treated as 0.

func <anchor link="func_IsSystemRegisterMaskingEnabled_1">IsSystemRegisterMaskingEnabled</anchor>(el : bits(2)) =&gt; boolean
begin
    assert IsFeatureImplemented(FEAT_SRMASK) &amp;&amp; el IN {<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>};

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().SRMASKEn == '0' then
        return FALSE;
    end;

    return el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || !<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() || (<a link="func_IsHCRXEL2Enabled_0" file="shared_pseudocode.xml">IsHCRXEL2Enabled</a>() &amp;&amp; HCRX_EL2().SRMASKEn == '1');
end;</pstext></ps>
    <ps name="aarch64/functions/system/IsTCR2EL1Enabled" mylink="aarch64.functions.system.IsTCR2EL1Enabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsTCR2EL1Enabled()
// ==================
// Returns TRUE if access to TCR2_EL1 register is enabled, and FALSE otherwise.
// Indirect read of TCR2_EL1 returns 0 when access is not enabled.

func <anchor link="func_IsTCR2EL1Enabled_0">IsTCR2EL1Enabled</anchor>() =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_TCR2) then return FALSE; end;
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().TCR2En == '0' then
        return FALSE;
    elsif (<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; (!<a link="func_IsHCRXEL2Enabled_0" file="shared_pseudocode.xml">IsHCRXEL2Enabled</a>() || HCRX_EL2().TCR2En == '0')) then
        return FALSE;
    else
        return TRUE;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/system/IsTCR2EL2Enabled" mylink="aarch64.functions.system.IsTCR2EL2Enabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsTCR2EL2Enabled()
// ==================
// Returns TRUE if access to TCR2_EL2 register is enabled, and FALSE otherwise.
// Indirect read of TCR2_EL2 returns 0 when access is not enabled.

func <anchor link="func_IsTCR2EL2Enabled_0">IsTCR2EL2Enabled</anchor>() =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_TCR2) then return FALSE; end;
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().TCR2En == '0' then
        return FALSE;
    end;

    return <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>();
end;</pstext></ps>
    <ps name="aarch64/functions/system/PACInstType" mylink="aarch64.functions.system.PACInstType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PACInstType
// ===========
type <anchor link="type_PACInstType">PACInstType</anchor> of enumeration {
    <anchor link="enum_PACIxSP">PACIxSP</anchor>,
    <anchor link="enum_PACIxSPPC">PACIxSPPC</anchor>,
};</pstext></ps>
    <ps name="aarch64/functions/system/SetBTypeCompatible" mylink="aarch64.functions.system.SetBTypeCompatible" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SetBTypeCompatible()
// ====================
// Sets the value of BTypeCompatible global variable used by BTI

func <anchor link="func_SetBTypeCompatible_1">SetBTypeCompatible</anchor>(x : boolean)
begin
    <a link="global_BTypeCompatible" file="shared_pseudocode.xml">BTypeCompatible</a> = x;
end;</pstext></ps>
    <ps name="aarch64/functions/system/SetBTypeNext" mylink="aarch64.functions.system.SetBTypeNext" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SetBTypeNext()
// ==============
// Set the value of BTypeNext global variable used by BTI

func <anchor link="func_SetBTypeNext_1">SetBTypeNext</anchor>(x : bits(2))
begin
    <a link="global_BTypeNext" file="shared_pseudocode.xml">BTypeNext</a> = x;
end;</pstext></ps>
    <ps name="aarch64/functions/system/SetInGuardedPage" mylink="aarch64.functions.system.SetInGuardedPage" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SetInGuardedPage()
// ==================
// Global state updated to denote if memory access is from a guarded page.

func <anchor link="func_SetInGuardedPage_1">SetInGuardedPage</anchor>(guardedpage : boolean)
begin
    <a link="global_InGuardedPage" file="shared_pseudocode.xml">InGuardedPage</a> = guardedpage;
end;</pstext></ps>
    <ps name="aarch64/functions/system128/AArch64_SysInstr128" mylink="aarch64.functions.system128.AArch64_SysInstr128" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SysInstr128()
// =====================
// Execute a system instruction with write (2 64-bit source operands).

impdef func AArch64_SysInstr128(op0 : bits(2), op1 : bits(3), crn : bits(4),
                                crm : bits(4), op2 : bits(3), t : integer, t2 : integer)
begin
    Unimplemented();
end;</pstext></ps>
    <ps name="aarch64/functions/system128/AArch64_SysRegRead128" mylink="aarch64.functions.system128.AArch64_SysRegRead128" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SysRegRead128()
// =======================
// Read from a 128-bit System register and write the contents of the register to X[t] and X[t2].

impdef func AArch64_SysRegRead128(op0 : bits(2), op1 : bits(3),
                                  crn : bits(4), crm : bits(4),
                                  op2 : bits(3), t : integer, t2 : integer)
begin
    Unimplemented();
end;</pstext></ps>
    <ps name="aarch64/functions/system128/AArch64_SysRegWrite128" mylink="aarch64.functions.system128.AArch64_SysRegWrite128" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SysRegWrite128()
// ========================
// Read the contents of X[t] and X[t2] and write the contents to a 128-bit System register.

impdef func AArch64_SysRegWrite128(op0 : bits(2), op1 : bits(3),
                                   crn : bits(4), crm : bits(4),
                                   op2 : bits(3), t : integer, t2 : integer)
begin
    Unimplemented();
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_EffectiveBroadcast" mylink="aarch64.functions.tlbi.AArch64_EffectiveBroadcast" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_EffectiveBroadcast()
// ============================

func <anchor link="func_AArch64_EffectiveBroadcast_1">AArch64_EffectiveBroadcast</anchor>(broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>) =&gt; <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>
begin
    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = broadcast_in;

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> then return broadcast; end;

    if broadcast == <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().FB == '1' then
        broadcast = <a link="enum_Broadcast_ForcedISH" file="shared_pseudocode.xml">Broadcast_ForcedISH</a>;
    end;

    return broadcast;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBIP_IPAS2" mylink="aarch64.functions.tlbi.AArch64_TLBIP_IPAS2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBIP_IPAS2()
// =====================
// Invalidate by IPA all stage 2 only TLB entries in the indicated broadcast
// domain matching the indicated VMID in the indicated regime with the indicated security state.
// Note: stage 1 and stage 2 combined entries are not in the scope of this operation.
// IPA and related parameters of the are derived from Xt.

func <anchor link="func_AArch64_TLBIP_IPAS2_7">AArch64_TLBIP_IPAS2</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid : bits(NUM_VMIDBITS),
                         broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>, attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
                         Xt : bits(128))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>};
    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = broadcast_in;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_IPAS2" file="shared_pseudocode.xml">TLBIOp_IPAS2</a>;
    r.from_aarch64 = TRUE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = TRUE;
    r.level        = level;
    r.attr         = attr;
    r.ttl          = Xt[47:44];
    r.address      = ZeroExtend{64}(Xt[107:64] :: Zeros{12});
    r.d64          = r.ttl == '00xx';
    r.d128         = TRUE;

    case security of
        when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt;
            r.ipaspace = <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
        when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;
            r.ipaspace = if Xt[63] == '1' then <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> else <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>;
        when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;
            r.ipaspace = <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>;
        otherwise =&gt;
            // Root security state does not have stage 2 translation
            unreachable;
    end;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBIP_RIPAS2" mylink="aarch64.functions.tlbi.AArch64_TLBIP_RIPAS2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBIP_RIPAS2()
// ======================
// Range invalidate by IPA all stage 2 only TLB entries in the indicated
// broadcast domain matching the indicated VMID in the indicated regime with the indicated
// security state.
// Note: stage 1 and stage 2 combined entries are not in the scope of this operation.
// The range of IPA and related parameters of the are derived from Xt.

func <anchor link="func_AArch64_TLBIP_RIPAS2_7">AArch64_TLBIP_RIPAS2</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid : bits(NUM_VMIDBITS),
                          broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>, attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
                          Xt : bits(128))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>};
    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = broadcast_in;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_RIPAS2" file="shared_pseudocode.xml">TLBIOp_RIPAS2</a>;
    r.from_aarch64 = TRUE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = TRUE;
    r.level        = level;
    r.attr         = attr;
    r.ttl[1:0]     = Xt[38:37];
    r.d64          = r.ttl[1:0] == '00';
    r.d128         = TRUE;

    var valid : boolean;
    (valid, r.tg, r.address, r.end_address) = <a link="func_TLBIPRange_2" file="shared_pseudocode.xml">TLBIPRange</a>(regime, Xt);

    if !valid then return; end;

    case security of
        when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt;
            r.ipaspace = <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
        when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;
            r.ipaspace = if Xt[63] == '1' then <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> else <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>;
        when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;
            r.ipaspace = <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>;
        otherwise =&gt;
            // Root security state does not have stage 2 translation
            unreachable;
    end;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBIP_RVA" mylink="aarch64.functions.tlbi.AArch64_TLBIP_RVA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBIP_RVA()
// ===================
// Range invalidate by VA range all stage 1 TLB entries in the indicated
// broadcast domain matching the indicated VMID and ASID (where regime
// supports VMID, ASID) in the indicated regime with the indicated security state.
// ASID, and range related parameters are derived from Xt.
// Note: stage 1 and stage 2 combined entries are in the scope of this operation.

func <anchor link="func_AArch64_TLBIP_RVA_7">AArch64_TLBIP_RVA</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime_in : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid_in : bits(NUM_VMIDBITS),
                       broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>, attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
                       Xt : bits(128))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>   = <a link="func_AArch64_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch64_EffectiveBroadcast</a>(broadcast_in);
    var attr      : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    if attr == <a link="enum_TLBI_AllAttr" file="shared_pseudocode.xml">TLBI_AllAttr</a> &amp;&amp; <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>   = regime_in;
    var vmid   : bits(NUM_VMIDBITS) = vmid_in;

    if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
        regime = <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>;
        vmid   = <a link="global_VMID_NONE" file="shared_pseudocode.xml">VMID_NONE</a>;
    elsif regime == <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> &amp;&amp; <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        regime = <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_RVA" file="shared_pseudocode.xml">TLBIOp_RVA</a>;
    r.from_aarch64 = TRUE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.level        = level;
    r.attr         = attr;
    r.asid         = Xt[63:48];
    r.ttl[1:0]     = Xt[38:37];
    r.d64          = r.ttl[1:0] == '00';
    r.d128         = TRUE;

    var valid : boolean;
    (valid, r.tg, r.address, r.end_address) = <a link="func_TLBIPRange_2" file="shared_pseudocode.xml">TLBIPRange</a>(regime, Xt);

    if !valid then return; end;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBIP_RVAA" mylink="aarch64.functions.tlbi.AArch64_TLBIP_RVAA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBIP_RVAA()
// ====================
// Range invalidate by VA range all stage 1 TLB entries in the indicated
// broadcast domain matching the indicated VMID (where regimesupports VMID)
// and all ASID in the indicated regime with the indicated security state.
// VA range related parameters are derived from Xt.
// Note: stage 1 and stage 2 combined entries are in the scope of this operation.

func <anchor link="func_AArch64_TLBIP_RVAA_7">AArch64_TLBIP_RVAA</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime_in : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid_in : bits(NUM_VMIDBITS),
                        broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>, attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
                        Xt : bits(128))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>   = <a link="func_AArch64_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch64_EffectiveBroadcast</a>(broadcast_in);
    var attr      : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    if attr == <a link="enum_TLBI_AllAttr" file="shared_pseudocode.xml">TLBI_AllAttr</a> &amp;&amp; <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>   = regime_in;
    var vmid   : bits(NUM_VMIDBITS) = vmid_in;

    if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
        regime = <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>;
        vmid   = <a link="global_VMID_NONE" file="shared_pseudocode.xml">VMID_NONE</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_RVAA" file="shared_pseudocode.xml">TLBIOp_RVAA</a>;
    r.from_aarch64 = TRUE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.level        = level;
    r.attr         = attr;
    r.ttl[1:0]     = Xt[38:37];
    r.d64          = r.ttl[1:0] == '00';
    r.d128         = TRUE;

    var valid : boolean;
    (valid, r.tg, r.address, r.end_address) = <a link="func_TLBIPRange_2" file="shared_pseudocode.xml">TLBIPRange</a>(regime, Xt);

    if !valid then return; end;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBIP_VA" mylink="aarch64.functions.tlbi.AArch64_TLBIP_VA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBIP_VA()
// ==================
// Invalidate by VA all stage 1 TLB entries in the indicated broadcast domain
// matching the indicated VMID and ASID (where regime supports VMID, ASID) in the indicated regime
// with the indicated security state.
// ASID, VA and related parameters are derived from Xt.
// Note: stage 1 and stage 2 combined entries are in the scope of this operation.

func <anchor link="func_AArch64_TLBIP_VA_7">AArch64_TLBIP_VA</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime_in : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid_in : bits(NUM_VMIDBITS),
                      broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>, attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
                      Xt : bits(128))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>   = <a link="func_AArch64_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch64_EffectiveBroadcast</a>(broadcast_in);
    var attr      : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    if attr == <a link="enum_TLBI_AllAttr" file="shared_pseudocode.xml">TLBI_AllAttr</a> &amp;&amp; <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>   = regime_in;
    var vmid   : bits(NUM_VMIDBITS) = vmid_in;

    if regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
        regime = <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>;
        vmid   = <a link="global_VMID_NONE" file="shared_pseudocode.xml">VMID_NONE</a>;
    elsif regime == <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> &amp;&amp; <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        regime = <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_VA" file="shared_pseudocode.xml">TLBIOp_VA</a>;
    r.from_aarch64 = TRUE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.level        = level;
    r.attr         = attr;
    r.asid         = Xt[63:48];
    r.ttl          = Xt[47:44];
    r.address      = ZeroExtend{64}(Xt[107:64] :: Zeros{12});
    r.d64          = r.ttl == '00xx';
    r.d128         = TRUE;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBIP_VAA" mylink="aarch64.functions.tlbi.AArch64_TLBIP_VAA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBIP_VAA()
// ===================
// Invalidate by VA all stage 1 TLB entries in the indicated broadcast domain
// matching the indicated VMID (where regime supports VMID) and all ASID in the indicated regime
// with the indicated security state.
// VA and related parameters are derived from Xt.
// Note: stage 1 and stage 2 combined entries are in the scope of this operation.

func <anchor link="func_AArch64_TLBIP_VAA_7">AArch64_TLBIP_VAA</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime_in : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid_in : bits(NUM_VMIDBITS),
                       broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>, attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
                       Xt : bits(128))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>   = <a link="func_AArch64_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch64_EffectiveBroadcast</a>(broadcast_in);
    var attr      : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    if attr == <a link="enum_TLBI_AllAttr" file="shared_pseudocode.xml">TLBI_AllAttr</a> &amp;&amp; <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>   = regime_in;
    var vmid   : bits(NUM_VMIDBITS) = vmid_in;
    if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
        regime = <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>;
        vmid   = <a link="global_VMID_NONE" file="shared_pseudocode.xml">VMID_NONE</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_VAA" file="shared_pseudocode.xml">TLBIOp_VAA</a>;
    r.from_aarch64 = TRUE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.level        = level;
    r.attr         = attr;
    r.ttl          = Xt[47:44];
    r.address      = ZeroExtend{64}(Xt[107:64] :: Zeros{12});
    r.d64          = r.ttl == '00xx';
    r.d128         = TRUE;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBI_ALL" mylink="aarch64.functions.tlbi.AArch64_TLBI_ALL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBI_ALL()
// ==================
// Invalidate all entries for the indicated translation regime with the
// the indicated security state for all TLBs within the indicated broadcast domain.
// Invalidation applies to all applicable stage 1 and stage 2 entries.

func <anchor link="func_AArch64_TLBI_ALL_5">AArch64_TLBI_ALL</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
                      broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>, Xt : bits(64))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>};
    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = broadcast_in;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_ALL" file="shared_pseudocode.xml">TLBIOp_ALL</a>;
    r.from_aarch64 = TRUE;
    r.security     = security;
    r.regime       = regime;
    r.level        = <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a>;
    r.attr         = attr;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBI_ASID" mylink="aarch64.functions.tlbi.AArch64_TLBI_ASID" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBI_ASID()
// ===================
// Invalidate all stage 1 entries matching the indicated VMID (where regime supports)
// and ASID in the parameter Xt in the indicated translation regime with the
// indicated security state for all TLBs within the indicated broadcast domain.
// Note: stage 1 and stage 2 combined entries are in the scope of this operation.

func <anchor link="func_AArch64_TLBI_ASID_6">AArch64_TLBI_ASID</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime_in : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid_in : bits(NUM_VMIDBITS),
                       broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
                       Xt :  bits(64))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>   = <a link="func_AArch64_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch64_EffectiveBroadcast</a>(broadcast_in);
    var attr      : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    if attr == <a link="enum_TLBI_AllAttr" file="shared_pseudocode.xml">TLBI_AllAttr</a> &amp;&amp; <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>   = regime_in;
    var vmid   : bits(NUM_VMIDBITS) = vmid_in;

    if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
        regime = <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>;
        vmid   = <a link="global_VMID_NONE" file="shared_pseudocode.xml">VMID_NONE</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_ASID" file="shared_pseudocode.xml">TLBIOp_ASID</a>;
    r.from_aarch64 = TRUE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.level        = <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a>;
    r.attr         = attr;
    r.asid         = Xt[63:48];

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBI_IPAS2" mylink="aarch64.functions.tlbi.AArch64_TLBI_IPAS2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBI_IPAS2()
// ====================
// Invalidate by IPA all stage 2 only TLB entries in the indicated broadcast
// domain matching the indicated VMID in the indicated regime with the indicated security state.
// Note: stage 1 and stage 2 combined entries are not in the scope of this operation.
// IPA and related parameters of the are derived from Xt.

func <anchor link="func_AArch64_TLBI_IPAS2_7">AArch64_TLBI_IPAS2</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid : bits(NUM_VMIDBITS),
                        broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>, attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
                        Xt : bits(64))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>};
    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = broadcast_in;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_IPAS2" file="shared_pseudocode.xml">TLBIOp_IPAS2</a>;
    r.from_aarch64 = TRUE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = TRUE;
    r.level        = level;
    r.attr         = attr;
    r.ttl          = Xt[47:44];
    r.address      = ZeroExtend{64}(Xt[39:0] :: Zeros{12});
    r.d64          = TRUE;
    r.d128         = r.ttl == '00xx';

    case security of
        when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt;
            r.ipaspace = <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
        when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;
            r.ipaspace = if Xt[63] == '1' then <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> else <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>;
        when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;
            r.ipaspace = <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>;
        otherwise =&gt;
            // Root security state does not have stage 2 translation
            unreachable;
    end;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBI_PAALL" mylink="aarch64.functions.tlbi.AArch64_TLBI_PAALL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBI_PAALL()
// ====================
// TLB Invalidate ALL GPT Information.
// Invalidates cached copies of GPT entries from TLBs in the indicated
// Shareabilty domain.
// The invalidation applies to all TLB entries containing GPT information.

func <anchor link="func_AArch64_TLBI_PAALL_1">AArch64_TLBI_PAALL</anchor>(broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>)
begin
    assert IsFeatureImplemented(FEAT_RME) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;

    // r.security and r.regime do not apply for TLBI by PA operations
    r.op    = <a link="enum_TLBIOp_PAALL" file="shared_pseudocode.xml">TLBIOp_PAALL</a>;
    r.level = <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a>;
    r.attr  = <a link="enum_TLBI_AllAttr" file="shared_pseudocode.xml">TLBI_AllAttr</a>;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBI_RIPAS2" mylink="aarch64.functions.tlbi.AArch64_TLBI_RIPAS2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBI_RIPAS2()
// =====================
// Range invalidate by IPA all stage 2 only TLB entries in the indicated
// broadcast domain matching the indicated VMID in the indicated regime with the indicated
// security state.
// Note: stage 1 and stage 2 combined entries are not in the scope of this operation.
// The range of IPA and related parameters of the are derived from Xt.

func <anchor link="func_AArch64_TLBI_RIPAS2_7">AArch64_TLBI_RIPAS2</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid : bits(NUM_VMIDBITS),
                         broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>, attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
                         Xt : bits(64))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>};
    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = broadcast_in;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_RIPAS2" file="shared_pseudocode.xml">TLBIOp_RIPAS2</a>;
    r.from_aarch64 = TRUE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = TRUE;
    r.level        = level;
    r.attr         = attr;
    r.ttl[1:0]     = Xt[38:37];
    r.d64          = TRUE;
    r.d128         = r.ttl[1:0] == '00';

    var valid : boolean;
    (valid, r.tg, r.address, r.end_address) = <a link="func_TLBIRange_2" file="shared_pseudocode.xml">TLBIRange</a>(regime, Xt);

    if !valid then return; end;

    case security of
        when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt;
            r.ipaspace = <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
        when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;
            r.ipaspace = if Xt[63] == '1' then <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> else <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>;
        when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;
            r.ipaspace = <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>;
        otherwise =&gt;
            // Root security state does not have stage 2 translation
            unreachable;
    end;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBI_RPA" mylink="aarch64.functions.tlbi.AArch64_TLBI_RPA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBI_RPA()
// ==================
// TLB Range Invalidate GPT Information by PA.
// Invalidates cached copies of GPT entries from TLBs in the indicated
// Shareabilty domain.
// The invalidation applies to TLB entries containing GPT information relating
// to the indicated physical address range.
// When the indicated level is
//     TLBILevel_Any  : this applies to TLB entries containing GPT information
//                      from all levels of the GPT walk
//     TLBILevel_Last : this applies to TLB entries containing GPT information
//                      from the last level of the GPT walk

func <anchor link="func_AArch64_TLBI_RPA_3">AArch64_TLBI_RPA</anchor>(level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>, Xt : bits(64), broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>)
begin
    assert IsFeatureImplemented(FEAT_RME) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    var range_bits : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
    var p : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;

    // r.security and r.regime do not apply for TLBI by PA operations
    r.op    = <a link="enum_TLBIOp_RPA" file="shared_pseudocode.xml">TLBIOp_RPA</a>;
    r.level = level;
    r.attr  = <a link="enum_TLBI_AllAttr" file="shared_pseudocode.xml">TLBI_AllAttr</a>;

    // SIZE field
    case Xt[47:44] of
        when '0000' =&gt; range_bits = 12; // 4KB
        when '0001' =&gt; range_bits = 14; // 16KB
        when '0010' =&gt; range_bits = 16; // 64KB
        when '0011' =&gt; range_bits = 21; // 2MB
        when '0100' =&gt; range_bits = 25; // 32MB
        when '0101' =&gt; range_bits = 29; // 512MB
        when '0110' =&gt; range_bits = 30; // 1GB
        when '0111' =&gt; range_bits = 34; // 16GB
        when '1000' =&gt; range_bits = 36; // 64GB
        when '1001' =&gt; range_bits = 39; // 512GB
        otherwise =&gt;   return;  // Reserved encoding, no TLB entries are required to be invalidated
    end;

    // If SIZE selects a range smaller than PGS, then PGS is used instead
    case <a link="func_DecodePGS_1" file="shared_pseudocode.xml">DecodePGS</a>(GPCCR_EL3().PGS) of
        when <a link="enum_PGS_4KB" file="shared_pseudocode.xml">PGS_4KB</a> =&gt;  p = 12;
        when <a link="enum_PGS_16KB" file="shared_pseudocode.xml">PGS_16KB</a> =&gt; p = 14;
        when <a link="enum_PGS_64KB" file="shared_pseudocode.xml">PGS_64KB</a> =&gt; p = 16;
        otherwise =&gt; return;    // Reserved encoding, no TLB entries are required to be invalidated
    end;

    if range_bits &lt; p then
        range_bits = p;
    end;

    var BaseADDR : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>) = Zeros{};
    case GPCCR_EL3().PGS of
        when '00' =&gt; BaseADDR[51:12] = Xt[39:0];   // 4KB
        when '10' =&gt; BaseADDR[51:14] = Xt[39:2];   // 16KB
        when '01' =&gt; BaseADDR[51:16] = Xt[39:4];   // 64KB
    end;

    if IsFeatureImplemented(FEAT_D128) &amp;&amp; <a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>() == 56 then
        BaseADDR[55:52] = Xt[43:40]; // Extension to Address
    end;

    // The calculation here automatically aligns BaseADDR to the size of
    // the region specified in SIZE. However, the architecture does not
    // require this alignment and if BaseADDR is not aligned to the region
    // specified by SIZE then no entries are required to be invalidated.
    let range_pbits : integer{} = range_bits;
    let start_addr : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>) = BaseADDR AND NOT ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(Ones{range_pbits});
    let end_addr : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>)   = start_addr + ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(Ones{range_pbits});

    // PASpace is not considered in TLBI by PA operations
    r.address     = ZeroExtend{64}(start_addr);
    r.end_address = ZeroExtend{64}(end_addr);

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBI_RVA" mylink="aarch64.functions.tlbi.AArch64_TLBI_RVA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBI_RVA()
// ==================
// Range invalidate by VA range all stage 1 TLB entries in the indicated
// broadcast domain matching the indicated VMID and ASID (where regime
// supports VMID, ASID) in the indicated regime with the indicated security state.
// ASID, and range related parameters are derived from Xt.
// Note: stage 1 and stage 2 combined entries are in the scope of this operation.

func <anchor link="func_AArch64_TLBI_RVA_7">AArch64_TLBI_RVA</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime_in : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid_in : bits(NUM_VMIDBITS),
                      broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>, attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
                      Xt : bits(64))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>   = <a link="func_AArch64_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch64_EffectiveBroadcast</a>(broadcast_in);
    var attr      : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    if attr == <a link="enum_TLBI_AllAttr" file="shared_pseudocode.xml">TLBI_AllAttr</a> &amp;&amp; <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>   = regime_in;
    var vmid   : bits(NUM_VMIDBITS) = vmid_in;

    if regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
        regime = <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>;
        vmid   = <a link="global_VMID_NONE" file="shared_pseudocode.xml">VMID_NONE</a>;
    elsif regime == <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> &amp;&amp; <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        regime = <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_RVA" file="shared_pseudocode.xml">TLBIOp_RVA</a>;
    r.from_aarch64 = TRUE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.level        = level;
    r.attr         = attr;
    r.asid         = Xt[63:48];
    r.ttl[1:0]     = Xt[38:37];
    r.d64          = TRUE;
    r.d128         = r.ttl[1:0] == '00';

    var valid : boolean;
    (valid, r.tg, r.address, r.end_address) = <a link="func_TLBIRange_2" file="shared_pseudocode.xml">TLBIRange</a>(regime, Xt);

    if !valid then return; end;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBI_RVAA" mylink="aarch64.functions.tlbi.AArch64_TLBI_RVAA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBI_RVAA()
// ===================
// Range invalidate by VA range all stage 1 TLB entries in the indicated
// broadcast domain matching the indicated VMID (where regimesupports VMID)
// and all ASID in the indicated regime with the indicated security state.
// VA range related parameters are derived from Xt.
// Note: stage 1 and stage 2 combined entries are in the scope of this operation.

func <anchor link="func_AArch64_TLBI_RVAA_7">AArch64_TLBI_RVAA</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime_in : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid_in : bits(NUM_VMIDBITS),
                       broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>, attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
                       Xt : bits(64))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>   = <a link="func_AArch64_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch64_EffectiveBroadcast</a>(broadcast_in);
    var attr      : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    if attr == <a link="enum_TLBI_AllAttr" file="shared_pseudocode.xml">TLBI_AllAttr</a> &amp;&amp; <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>   = regime_in;
    var vmid   : bits(NUM_VMIDBITS) = vmid_in;

    if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
        regime = <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>;
        vmid   = <a link="global_VMID_NONE" file="shared_pseudocode.xml">VMID_NONE</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_RVAA" file="shared_pseudocode.xml">TLBIOp_RVAA</a>;
    r.from_aarch64 = TRUE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.level        = level;
    r.attr         = attr;
    r.ttl[1:0]     = Xt[38:37];
    r.d64          = TRUE;
    r.d128         = r.ttl[1:0] == '00';

    var valid : boolean;
    (valid, r.tg, r.address, r.end_address) = <a link="func_TLBIRange_2" file="shared_pseudocode.xml">TLBIRange</a>(regime, Xt);

    if !valid then return; end;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;
    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBI_VA" mylink="aarch64.functions.tlbi.AArch64_TLBI_VA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBI_VA()
// =================
// Invalidate by VA all stage 1 TLB entries in the indicated broadcast domain
// matching the indicated VMID and ASID (where regime supports VMID, ASID) in the indicated regime
// with the indicated security state.
// ASID, VA and related parameters are derived from Xt.
// Note: stage 1 and stage 2 combined entries are in the scope of this operation.

func <anchor link="func_AArch64_TLBI_VA_7">AArch64_TLBI_VA</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime_in : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid_in : bits(NUM_VMIDBITS),
                     broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>, attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
                     Xt : bits(64))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>   = <a link="func_AArch64_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch64_EffectiveBroadcast</a>(broadcast_in);
    var attr      : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    if attr == <a link="enum_TLBI_AllAttr" file="shared_pseudocode.xml">TLBI_AllAttr</a> &amp;&amp; <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>   = regime_in;
    var vmid   : bits(NUM_VMIDBITS) = vmid_in;
    if regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
        regime = <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>;
        vmid   = <a link="global_VMID_NONE" file="shared_pseudocode.xml">VMID_NONE</a>;
    elsif regime == <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> &amp;&amp; <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        regime = <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_VA" file="shared_pseudocode.xml">TLBIOp_VA</a>;
    r.from_aarch64 = TRUE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.level        = level;
    r.attr         = attr;
    r.asid         = Xt[63:48];
    r.ttl          = Xt[47:44];
    r.address      = ZeroExtend{64}(Xt[43:0] :: Zeros{12});
    r.d64          = TRUE;
    r.d128         = r.ttl == '00xx';

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBI_VAA" mylink="aarch64.functions.tlbi.AArch64_TLBI_VAA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBI_VAA()
// ==================
// Invalidate by VA all stage 1 TLB entries in the indicated broadcast domain
// matching the indicated VMID (where regime supports VMID) and all ASID in the indicated regime
// with the indicated security state.
// VA and related parameters are derived from Xt.
// Note: stage 1 and stage 2 combined entries are in the scope of this operation.

func <anchor link="func_AArch64_TLBI_VAA_7">AArch64_TLBI_VAA</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime_in : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid_in : bits(NUM_VMIDBITS),
                      broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>, attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
                      Xt : bits(64))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>   = <a link="func_AArch64_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch64_EffectiveBroadcast</a>(broadcast_in);
    var attr      : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    if attr == <a link="enum_TLBI_AllAttr" file="shared_pseudocode.xml">TLBI_AllAttr</a> &amp;&amp; <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>   = regime_in;
    var vmid   : bits(NUM_VMIDBITS) = vmid_in;
    if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
        regime = <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>;
        vmid   = <a link="global_VMID_NONE" file="shared_pseudocode.xml">VMID_NONE</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_VAA" file="shared_pseudocode.xml">TLBIOp_VAA</a>;
    r.from_aarch64 = TRUE;
    r.security     = security;
    r.regime       = regime;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.level        = level;
    r.attr         = attr;
    r.ttl          = Xt[47:44];
    r.address      = ZeroExtend{64}(Xt[43:0] :: Zeros{12});
    r.d64          = TRUE;
    r.d128         = r.ttl == '00xx';

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBI_VMALL" mylink="aarch64.functions.tlbi.AArch64_TLBI_VMALL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBI_VMALL()
// ====================
// Invalidate all stage 1 entries for the indicated translation regime with the
// the indicated security state for all TLBs within the indicated broadcast
// domain that match the indicated VMID (where applicable).
// Note: stage 1 and stage 2 combined entries are in the scope of this operation.
// Note: stage 2 only entries are not in the scope of this operation.

func <anchor link="func_AArch64_TLBI_VMALL_6">AArch64_TLBI_VMALL</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime_in : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
                        vmid_in : bits(NUM_VMIDBITS), broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>,
                        attr_in : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>, Xt : bits(64))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>};
    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>   = <a link="func_AArch64_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch64_EffectiveBroadcast</a>(broadcast_in);
    var attr      : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a> = attr_in;

    if attr == <a link="enum_TLBI_AllAttr" file="shared_pseudocode.xml">TLBI_AllAttr</a> &amp;&amp; <a link="func_ExcludeXS_0" file="shared_pseudocode.xml">ExcludeXS</a>() then
        attr = <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a>;
    end;

    var regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>   = regime_in;
    var vmid   : bits(NUM_VMIDBITS) = vmid_in;

    if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
        regime = <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>;
        vmid   = <a link="global_VMID_NONE" file="shared_pseudocode.xml">VMID_NONE</a>;
    end;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_VMALL" file="shared_pseudocode.xml">TLBIOp_VMALL</a>;
    r.from_aarch64 = TRUE;
    r.security     = security;
    r.regime       = regime;
    r.level        = <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a>;
    r.vmid         = vmid;
    r.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    r.attr         = attr;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBI_VMALLS12" mylink="aarch64.functions.tlbi.AArch64_TLBI_VMALLS12" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBI_VMALLS12()
// =======================
// Invalidate all stage 1 and stage 2 entries for the indicated translation
// regime with the indicated security state for all TLBs within the indicated
// broadcast domain that match the indicated VMID.

func <anchor link="func_AArch64_TLBI_VMALLS12_6">AArch64_TLBI_VMALLS12</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
                           vmid : bits(NUM_VMIDBITS), broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>,
                           attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>, Xt : bits(64))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>};
    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = <a link="func_AArch64_EffectiveBroadcast_1" file="shared_pseudocode.xml">AArch64_EffectiveBroadcast</a>(broadcast_in);

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_VMALLS12" file="shared_pseudocode.xml">TLBIOp_VMALLS12</a>;
    r.from_aarch64 = TRUE;
    r.security     = security;
    r.regime       = regime;
    r.level        = <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a>;
    r.vmid         = vmid;
    r.use_vmid     = TRUE;
    r.attr         = attr;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/AArch64_TLBI_VMALLWS2" mylink="aarch64.functions.tlbi.AArch64_TLBI_VMALLWS2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBI_VMALLWS2()
// =======================
// Remove stage 2 dirty state from entries for the indicated translation regime
// with the indicated security state for all TLBs within the indicated broadcast
// domain that match the indicated VMID.

func <anchor link="func_AArch64_TLBI_VMALLWS2_6">AArch64_TLBI_VMALLWS2</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, vmid : bits(16),
                           broadcast_in : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
                           Xt : bits(64))
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>};
    assert regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a>;

    if security == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> &amp;&amp; <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().EEL2 == '0' then
        return;
    end;

    var broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a> = broadcast_in;

    var r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>;
    r.op           = <a link="enum_TLBIOp_VMALLWS2" file="shared_pseudocode.xml">TLBIOp_VMALLWS2</a>;
    r.from_aarch64 = TRUE;
    r.security     = security;
    r.regime       = regime;
    r.level        = <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a>;
    r.vmid         = vmid;
    r.use_vmid     = TRUE;
    r.attr         = attr;

    TLBI(r);
    if broadcast != <a link="enum_Broadcast_NSH" file="shared_pseudocode.xml">Broadcast_NSH</a> then BroadcastTLBI(broadcast, r); end;

    return;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/DecodeTLBITG" mylink="aarch64.functions.tlbi.DecodeTLBITG" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodeTLBITG()
// ==============
// Decode translation granule size in TLBI range instructions

func <anchor link="func_DecodeTLBITG_1">DecodeTLBITG</anchor>(tg : bits(2)) =&gt; <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>
begin
    case tg of
        when '01' =&gt;   return <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>;
        when '10' =&gt;   return <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a>;
        when '11' =&gt;   return <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a>;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/GPTTLBIMatch" mylink="aarch64.functions.tlbi.GPTTLBIMatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPTTLBIMatch()
// ==============
// Determine whether the GPT TLB entry lies within the scope of invalidation

func <anchor link="func_GPTTLBIMatch_2">GPTTLBIMatch</anchor>(tlbi : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>, gpt_entry : <a link="type_GPTEntry" file="shared_pseudocode.xml">GPTEntry</a>) =&gt; boolean
begin
    assert tlbi.op IN {<a link="enum_TLBIOp_RPA" file="shared_pseudocode.xml">TLBIOp_RPA</a>, <a link="enum_TLBIOp_PAALL" file="shared_pseudocode.xml">TLBIOp_PAALL</a>};

    var match : boolean;
    let entry_size_mask : bits(64)     = ZeroExtend{}(Ones{gpt_entry.size});
    let entry_end_address : bits(64)   = (ZeroExtend{64}(gpt_entry.pa[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0] OR
                                             entry_size_mask[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0]));
    let entry_start_address : bits(64) = (ZeroExtend{64}(gpt_entry.pa[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0] AND NOT
                                             entry_size_mask[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0]));

    case tlbi.op of
        when <a link="enum_TLBIOp_RPA" file="shared_pseudocode.xml">TLBIOp_RPA</a> =&gt;
            match = ((UInt(tlbi.address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0]) &lt;=
                       UInt(entry_end_address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0])) &amp;&amp;
                     (UInt(tlbi.end_address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0]) &gt;
                        UInt(entry_start_address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0])) &amp;&amp;
                     (tlbi.level == <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a> || !gpt_entry.istable));
        when <a link="enum_TLBIOp_PAALL" file="shared_pseudocode.xml">TLBIOp_PAALL</a> =&gt;
            match = TRUE;
    end;

    return match;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/HasLargeAddress" mylink="aarch64.functions.tlbi.HasLargeAddress" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HasLargeAddress()
// =================
// Returns TRUE if the regime is configured for 52 bit addresses, FALSE otherwise.

func <anchor link="func_HasLargeAddress_1">HasLargeAddress</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>) =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_LPA2) then
        return FALSE;
    end;
    case regime of
        when <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> =&gt;
            return TCR_EL3().DS == '1';
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> =&gt;
            return TCR_EL2().DS == '1';
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt;
            return TCR_EL2().DS == '1';
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt;
            return TCR_EL1().DS == '1';
        otherwise =&gt;
            unreachable;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/ResTLBIRTTL" mylink="aarch64.functions.tlbi.ResTLBIRTTL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ResTLBIRTTL()
// =============
// Determine whether the TTL field in TLBI instructions that do apply
// to a range of addresses contains a reserved value

func <anchor link="func_ResTLBIRTTL_2">ResTLBIRTTL</anchor>(tg : bits(2), ttl : bits(2)) =&gt; boolean
begin
    case ttl of
        when '00' =&gt; return TRUE;
        when '01' =&gt; return <a link="func_DecodeTLBITG_1" file="shared_pseudocode.xml">DecodeTLBITG</a>(tg) == <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a> &amp;&amp; !IsFeatureImplemented(FEAT_LPA2);
        otherwise =&gt; return FALSE;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/ResTLBITTL" mylink="aarch64.functions.tlbi.ResTLBITTL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ResTLBITTL()
// ============
// Determine whether the TTL field in TLBI instructions that do not apply
// to a range of addresses contains a reserved value

func <anchor link="func_ResTLBITTL_1">ResTLBITTL</anchor>(ttl : bits(4)) =&gt; boolean
begin
    case ttl of
        when '00xx' =&gt; return TRUE;
        when '0100' =&gt; return !IsFeatureImplemented(FEAT_LPA2);
        when '1000' =&gt; return TRUE;
        when '1001' =&gt; return !IsFeatureImplemented(FEAT_LPA2);
        when '1100' =&gt; return TRUE;
        otherwise =&gt;   return FALSE;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/TGBits" mylink="aarch64.functions.tlbi.TGBits" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TGBits()
// ========
// Return the number of least-significant address bits within a single Translation Granule.

func <anchor link="func_TGBits_1">TGBits</anchor>(tg : bits(2)) =&gt; <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>
begin
    case tg of
        when '01' =&gt; return 12; // 4KB
        when '10' =&gt; return 14; // 16KB
        when '11' =&gt; return 16; // 64KB
        otherwise =&gt;
            unreachable;
    end;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/TLBIMatch" mylink="aarch64.functions.tlbi.TLBIMatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TLBIMatch()
// ===========
// Determine whether the TLB entry lies within the scope of invalidation

func <anchor link="func_TLBIMatch_2">TLBIMatch</anchor>(tlbi : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>, tlb_entry : <a link="type_TLBRecord" file="shared_pseudocode.xml">TLBRecord</a>) =&gt; boolean
begin
    var match : boolean;
    let entry_block_mask : bits(64)    = ZeroExtend{}(Ones{tlb_entry.blocksize});
    var entry_end_address : bits(64)   = tlb_entry.context.ia OR entry_block_mask;
    var entry_start_address : bits(64) = tlb_entry.context.ia AND NOT entry_block_mask;
    case tlbi.op of
        when <a link="enum_TLBIOp_DALL" file="shared_pseudocode.xml">TLBIOp_DALL</a>, <a link="enum_TLBIOp_IALL" file="shared_pseudocode.xml">TLBIOp_IALL</a> =&gt;
            match = (tlbi.security == tlb_entry.context.ss &amp;&amp;
                     tlbi.regime   == tlb_entry.context.regime &amp;&amp;
                     tlbi.use_vmid == tlb_entry.context.use_vmid &amp;&amp;
                     (!tlb_entry.context.use_vmid || tlbi.vmid == tlb_entry.context.vmid));
        when <a link="enum_TLBIOp_DASID" file="shared_pseudocode.xml">TLBIOp_DASID</a>, <a link="enum_TLBIOp_IASID" file="shared_pseudocode.xml">TLBIOp_IASID</a> =&gt;
            match = (tlb_entry.context.includes_s1 &amp;&amp;
                     tlbi.security == tlb_entry.context.ss &amp;&amp;
                     tlbi.regime   == tlb_entry.context.regime &amp;&amp;
                     tlbi.use_vmid == tlb_entry.context.use_vmid &amp;&amp;
                     (!tlb_entry.context.use_vmid || tlbi.vmid == tlb_entry.context.vmid) &amp;&amp;
                     (<a link="func_UseASID_1" file="shared_pseudocode.xml">UseASID</a>(tlb_entry.context) &amp;&amp; tlb_entry.context.nG == '1' &amp;&amp;
                        tlbi.asid  == tlb_entry.context.asid));
        when <a link="enum_TLBIOp_DVA" file="shared_pseudocode.xml">TLBIOp_DVA</a>, <a link="enum_TLBIOp_IVA" file="shared_pseudocode.xml">TLBIOp_IVA</a> =&gt;
            var regime_match : boolean;
            var context_match : boolean;
            var address_match : boolean;
            var level_match : boolean;
            regime_match = (tlb_entry.context.includes_s1 &amp;&amp;
                            tlbi.security == tlb_entry.context.ss &amp;&amp;
                            tlbi.regime   == tlb_entry.context.regime);
            context_match = (tlbi.use_vmid == tlb_entry.context.use_vmid &amp;&amp;
                             (!tlb_entry.context.use_vmid || tlbi.vmid == tlb_entry.context.vmid) &amp;&amp;
                             (!<a link="func_UseASID_1" file="shared_pseudocode.xml">UseASID</a>(tlb_entry.context) || tlbi.asid == tlb_entry.context.asid ||
                                tlb_entry.context.nG == '0'));
            let addr_lsb : integer{} = tlb_entry.blocksize;
            address_match = tlbi.address[55:addr_lsb] == tlb_entry.context.ia[55:addr_lsb];
            level_match = (tlbi.level == <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a> || !tlb_entry.walkstate.istable);
            match = regime_match &amp;&amp; context_match  &amp;&amp; address_match  &amp;&amp; level_match;
        when <a link="enum_TLBIOp_ALL" file="shared_pseudocode.xml">TLBIOp_ALL</a> =&gt;
            let relax_regime : boolean = (tlbi.from_aarch64 &amp;&amp;
                            tlbi.regime IN {<a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>, <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a>} &amp;&amp;
                            tlb_entry.context.regime IN {<a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>, <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a>});
            match = (tlbi.security == tlb_entry.context.ss &amp;&amp;
                     (tlbi.regime  == tlb_entry.context.regime || relax_regime));
        when <a link="enum_TLBIOp_ASID" file="shared_pseudocode.xml">TLBIOp_ASID</a> =&gt;
            match = (tlb_entry.context.includes_s1 &amp;&amp;
                     tlbi.security == tlb_entry.context.ss &amp;&amp;
                     tlbi.regime   == tlb_entry.context.regime &amp;&amp;
                     tlbi.use_vmid == tlb_entry.context.use_vmid &amp;&amp;
                     (!tlb_entry.context.use_vmid || tlbi.vmid == tlb_entry.context.vmid) &amp;&amp;
                     (<a link="func_UseASID_1" file="shared_pseudocode.xml">UseASID</a>(tlb_entry.context) &amp;&amp; tlb_entry.context.nG == '1' &amp;&amp;
                        tlbi.asid  == tlb_entry.context.asid));
        when <a link="enum_TLBIOp_IPAS2" file="shared_pseudocode.xml">TLBIOp_IPAS2</a>, <a link="enum_TLBIPOp_IPAS2" file="shared_pseudocode.xml">TLBIPOp_IPAS2</a> =&gt;
            let addr_lsb : integer{} = tlb_entry.blocksize;
            match = (!tlb_entry.context.includes_s1 &amp;&amp; tlb_entry.context.includes_s2 &amp;&amp;
                     tlbi.security == tlb_entry.context.ss &amp;&amp;
                     tlbi.regime   == tlb_entry.context.regime &amp;&amp;
                     (!tlb_entry.context.use_vmid || tlbi.vmid == tlb_entry.context.vmid) &amp;&amp;
                     tlbi.ipaspace == tlb_entry.context.ipaspace &amp;&amp;
                     (tlbi.address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:addr_lsb] ==
                        tlb_entry.context.ia[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:addr_lsb]) &amp;&amp;
                     (!tlbi.from_aarch64 || <a link="func_ResTLBITTL_1" file="shared_pseudocode.xml">ResTLBITTL</a>(tlbi.ttl) || (
                         <a link="func_DecodeTLBITG_1" file="shared_pseudocode.xml">DecodeTLBITG</a>(tlbi.ttl[3:2]) == tlb_entry.context.tg &amp;&amp;
                         UInt(tlbi.ttl[1:0]) == tlb_entry.walkstate.level)
                     ) &amp;&amp;
                     ((tlbi.d128  &amp;&amp; tlb_entry.context.isd128) ||
                      (tlbi.d64  &amp;&amp; !tlb_entry.context.isd128) ||
                      (tlbi.d64 &amp;&amp; tlbi.d128)) &amp;&amp;
                     (tlbi.level == <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a> || !tlb_entry.walkstate.istable));
        when <a link="enum_TLBIOp_VAA" file="shared_pseudocode.xml">TLBIOp_VAA</a>, <a link="enum_TLBIPOp_VAA" file="shared_pseudocode.xml">TLBIPOp_VAA</a> =&gt;
            let addr_lsb : integer{} = tlb_entry.blocksize;
            match = (tlb_entry.context.includes_s1 &amp;&amp;
                     tlbi.security == tlb_entry.context.ss &amp;&amp;
                     tlbi.regime   == tlb_entry.context.regime &amp;&amp;
                     tlbi.use_vmid == tlb_entry.context.use_vmid &amp;&amp;
                     (!tlb_entry.context.use_vmid || tlbi.vmid == tlb_entry.context.vmid) &amp;&amp;
                     tlbi.address[55:addr_lsb] == tlb_entry.context.ia[55:addr_lsb] &amp;&amp;
                     (!tlbi.from_aarch64 || <a link="func_ResTLBITTL_1" file="shared_pseudocode.xml">ResTLBITTL</a>(tlbi.ttl) || (
                         <a link="func_DecodeTLBITG_1" file="shared_pseudocode.xml">DecodeTLBITG</a>(tlbi.ttl[3:2]) == tlb_entry.context.tg &amp;&amp;
                         UInt(tlbi.ttl[1:0]) == tlb_entry.walkstate.level)
                     ) &amp;&amp;
                     ((tlbi.d128  &amp;&amp; tlb_entry.context.isd128) ||
                      (tlbi.d64  &amp;&amp; !tlb_entry.context.isd128) ||
                      (tlbi.d64 &amp;&amp; tlbi.d128)) &amp;&amp;
                     (tlbi.level == <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a> || !tlb_entry.walkstate.istable));
        when <a link="enum_TLBIOp_VA" file="shared_pseudocode.xml">TLBIOp_VA</a>, <a link="enum_TLBIPOp_VA" file="shared_pseudocode.xml">TLBIPOp_VA</a> =&gt;
            let addr_lsb : integer{} = tlb_entry.blocksize;
            match = (tlb_entry.context.includes_s1 &amp;&amp;
                     tlbi.security == tlb_entry.context.ss &amp;&amp;
                     tlbi.regime   == tlb_entry.context.regime &amp;&amp;
                     tlbi.use_vmid == tlb_entry.context.use_vmid &amp;&amp;
                     (!tlb_entry.context.use_vmid || tlbi.vmid == tlb_entry.context.vmid) &amp;&amp;
                     (!<a link="func_UseASID_1" file="shared_pseudocode.xml">UseASID</a>(tlb_entry.context) || tlbi.asid == tlb_entry.context.asid ||
                        tlb_entry.context.nG == '0') &amp;&amp;
                     tlbi.address[55:addr_lsb] == tlb_entry.context.ia[55:addr_lsb] &amp;&amp;
                     (!tlbi.from_aarch64 || <a link="func_ResTLBITTL_1" file="shared_pseudocode.xml">ResTLBITTL</a>(tlbi.ttl) || (
                         <a link="func_DecodeTLBITG_1" file="shared_pseudocode.xml">DecodeTLBITG</a>(tlbi.ttl[3:2]) == tlb_entry.context.tg &amp;&amp;
                         UInt(tlbi.ttl[1:0]) == tlb_entry.walkstate.level)
                     ) &amp;&amp;
                     ((tlbi.d128  &amp;&amp; tlb_entry.context.isd128) ||
                      (tlbi.d64  &amp;&amp; !tlb_entry.context.isd128) ||
                      (tlbi.d64 &amp;&amp; tlbi.d128)) &amp;&amp;
                     (tlbi.level == <a link="enum_TLBILevel_Any" file="shared_pseudocode.xml">TLBILevel_Any</a> || !tlb_entry.walkstate.istable));
        when <a link="enum_TLBIOp_VMALL" file="shared_pseudocode.xml">TLBIOp_VMALL</a> =&gt;
            match = (tlb_entry.context.includes_s1 &amp;&amp;
                     tlbi.security == tlb_entry.context.ss &amp;&amp;
                     tlbi.regime   == tlb_entry.context.regime &amp;&amp;
                     tlbi.use_vmid == tlb_entry.context.use_vmid &amp;&amp;
                     (!tlb_entry.context.use_vmid || tlbi.vmid == tlb_entry.context.vmid));
        when <a link="enum_TLBIOp_VMALLS12" file="shared_pseudocode.xml">TLBIOp_VMALLS12</a> =&gt;
            match = (tlbi.security == tlb_entry.context.ss &amp;&amp;
                     tlbi.regime   == tlb_entry.context.regime &amp;&amp;
                     (!tlb_entry.context.use_vmid || tlbi.vmid == tlb_entry.context.vmid));
        when <a link="enum_TLBIOp_RIPAS2" file="shared_pseudocode.xml">TLBIOp_RIPAS2</a>, <a link="enum_TLBIPOp_RIPAS2" file="shared_pseudocode.xml">TLBIPOp_RIPAS2</a> =&gt;
            match = (!tlb_entry.context.includes_s1 &amp;&amp; tlb_entry.context.includes_s2 &amp;&amp;
                     tlbi.security == tlb_entry.context.ss &amp;&amp;
                     tlbi.regime   == tlb_entry.context.regime &amp;&amp;
                     (!tlb_entry.context.use_vmid || tlbi.vmid == tlb_entry.context.vmid) &amp;&amp;
                     tlbi.ipaspace == tlb_entry.context.ipaspace &amp;&amp;
                     (tlbi.tg != '00' &amp;&amp; <a link="func_DecodeTLBITG_1" file="shared_pseudocode.xml">DecodeTLBITG</a>(tlbi.tg) == tlb_entry.context.tg) &amp;&amp;
                     (!tlbi.from_aarch64 || <a link="func_ResTLBIRTTL_2" file="shared_pseudocode.xml">ResTLBIRTTL</a>(tlbi.tg, tlbi.ttl[1:0]) ||
                        UInt(tlbi.ttl[1:0]) == tlb_entry.walkstate.level) &amp;&amp;
                     ((tlbi.d128  &amp;&amp; tlb_entry.context.isd128) ||
                      (tlbi.d64  &amp;&amp; !tlb_entry.context.isd128) ||
                      (tlbi.d64 &amp;&amp; tlbi.d128)) &amp;&amp;
                     (UInt(tlbi.address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0]) &lt;=
                        UInt(entry_end_address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0])) &amp;&amp;
                     (UInt(tlbi.end_address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0]) &gt;
                        UInt(entry_start_address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0])));
        when <a link="enum_TLBIOp_RVAA" file="shared_pseudocode.xml">TLBIOp_RVAA</a>, <a link="enum_TLBIPOp_RVAA" file="shared_pseudocode.xml">TLBIPOp_RVAA</a> =&gt;
            match = (tlb_entry.context.includes_s1 &amp;&amp;
                     tlbi.security == tlb_entry.context.ss &amp;&amp;
                     tlbi.regime   == tlb_entry.context.regime &amp;&amp;
                     tlbi.use_vmid == tlb_entry.context.use_vmid &amp;&amp;
                     (!tlb_entry.context.use_vmid || tlbi.vmid == tlb_entry.context.vmid) &amp;&amp;
                     (tlbi.tg != '00' &amp;&amp; <a link="func_DecodeTLBITG_1" file="shared_pseudocode.xml">DecodeTLBITG</a>(tlbi.tg) == tlb_entry.context.tg) &amp;&amp;
                     (!tlbi.from_aarch64 || <a link="func_ResTLBIRTTL_2" file="shared_pseudocode.xml">ResTLBIRTTL</a>(tlbi.tg, tlbi.ttl[1:0]) ||
                        UInt(tlbi.ttl[1:0]) == tlb_entry.walkstate.level) &amp;&amp;
                     ((tlbi.d128  &amp;&amp; tlb_entry.context.isd128) ||
                      (tlbi.d64  &amp;&amp; !tlb_entry.context.isd128) ||
                      (tlbi.d64 &amp;&amp; tlbi.d128)) &amp;&amp;
                     UInt(tlbi.address[55:0]) &lt;= UInt(entry_end_address[55:0]) &amp;&amp;
                     UInt(tlbi.end_address[55:0]) &gt; UInt(entry_start_address[55:0]));
        when <a link="enum_TLBIOp_RVA" file="shared_pseudocode.xml">TLBIOp_RVA</a>, <a link="enum_TLBIPOp_RVA" file="shared_pseudocode.xml">TLBIPOp_RVA</a> =&gt;
            match = (tlb_entry.context.includes_s1 &amp;&amp;
                     tlbi.security == tlb_entry.context.ss &amp;&amp;
                     tlbi.regime   == tlb_entry.context.regime &amp;&amp;
                     tlbi.use_vmid == tlb_entry.context.use_vmid &amp;&amp;
                     (!tlb_entry.context.use_vmid || tlbi.vmid == tlb_entry.context.vmid) &amp;&amp;
                     (!<a link="func_UseASID_1" file="shared_pseudocode.xml">UseASID</a>(tlb_entry.context) || tlbi.asid == tlb_entry.context.asid ||
                        tlb_entry.context.nG == '0') &amp;&amp;
                     (tlbi.tg != '00' &amp;&amp; <a link="func_DecodeTLBITG_1" file="shared_pseudocode.xml">DecodeTLBITG</a>(tlbi.tg) == tlb_entry.context.tg) &amp;&amp;
                     (!tlbi.from_aarch64 || <a link="func_ResTLBIRTTL_2" file="shared_pseudocode.xml">ResTLBIRTTL</a>(tlbi.tg, tlbi.ttl[1:0]) ||
                        UInt(tlbi.ttl[1:0]) == tlb_entry.walkstate.level) &amp;&amp;
                     ((tlbi.d128  &amp;&amp; tlb_entry.context.isd128) ||
                      (tlbi.d64  &amp;&amp; !tlb_entry.context.isd128) ||
                      (tlbi.d64 &amp;&amp; tlbi.d128)) &amp;&amp;
                     UInt(tlbi.address[55:0]) &lt;= UInt(entry_end_address[55:0]) &amp;&amp;
                     UInt(tlbi.end_address[55:0]) &gt; UInt(entry_start_address[55:0]));
        when <a link="enum_TLBIOp_RPA" file="shared_pseudocode.xml">TLBIOp_RPA</a> =&gt;
            let addr = tlb_entry.walkstate.baseaddress.address;
            entry_end_address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0] = (addr[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0] OR
                                                 entry_block_mask[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0]);
            entry_start_address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0] = (addr[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0] AND
                                                   NOT entry_block_mask[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0]);
            match = (tlb_entry.context.includes_gpt &amp;&amp;
                     (UInt(tlbi.address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0]) &lt;=
                        UInt(entry_end_address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0])) &amp;&amp;
                     (UInt(tlbi.end_address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0]) &gt;
                        UInt(entry_start_address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0])));
        when <a link="enum_TLBIOp_PAALL" file="shared_pseudocode.xml">TLBIOp_PAALL</a> =&gt;
            match = tlb_entry.context.includes_gpt;
    end;

    if tlbi.attr == <a link="enum_TLBI_ExcludeXS" file="shared_pseudocode.xml">TLBI_ExcludeXS</a> &amp;&amp; tlb_entry.context.xs == '1' then
        match = FALSE;
    end;

    return match;
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/TLBIPRange" mylink="aarch64.functions.tlbi.TLBIPRange" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TLBIPRange()
// ============
// Extract the input address range information from encoded Xt.

func <anchor link="func_TLBIPRange_2">TLBIPRange</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, Xt : bits(128)) =&gt; (boolean, bits(2), bits(64), bits(64))
begin
    let valid : boolean = TRUE;
    var start_address : bits(64) = Zeros{};
    var end_address : bits(64)   = Zeros{};

    let tg : bits(2)    = Xt[47:46];
    let scale : integer = UInt(Xt[45:44]);
    let num : integer   = UInt(Xt[43:39]);

    if tg == '00' then
        return (FALSE, tg, start_address, end_address);
    end;

    let tg_bits : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_TGBits_1" file="shared_pseudocode.xml">TGBits</a>(tg);
    // The more-significant bits of the start_address is not updated,
    // as they are not used when performing address matching in TLB
    start_address[55:tg_bits] = Xt[107:64+(tg_bits-12)];

    let range : integer = (num+1) &lt;&lt; (5*scale + 1 + tg_bits);
    end_address   = start_address + range[63:0];

    if end_address[55] != start_address[55] then
        // overflow, saturate it
        end_address = Replicate{9}(start_address[55]) :: Ones{55};
    end;

    return (valid, tg, start_address, end_address);
end;</pstext></ps>
    <ps name="aarch64/functions/tlbi/TLBIRange" mylink="aarch64.functions.tlbi.TLBIRange" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TLBIRange()
// ===========
// Extract the input address range information from encoded Xt.

func <anchor link="func_TLBIRange_2">TLBIRange</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, Xt : bits(64)) =&gt; (boolean, bits(2), bits(64), bits(64))
begin
    let valid : boolean = TRUE;
    var start_address : bits(64) = Zeros{};
    var end_address : bits(64)   = Zeros{};

    let tg : bits(2)    = Xt[47:46];
    let scale : integer = UInt(Xt[45:44]);
    let num : integer   = UInt(Xt[43:39]);
    var tg_bits : integer;

    if tg == '00' then
        return (FALSE, tg, start_address, end_address);
    end;

    case tg of
        when '01' =&gt; // 4KB
            tg_bits = 12;
            if <a link="func_HasLargeAddress_1" file="shared_pseudocode.xml">HasLargeAddress</a>(regime) then
                start_address[52:16] = Xt[36:0];
                start_address[63:53] = Replicate{11}(Xt[36]);
            else
                start_address[48:12] = Xt[36:0];
                start_address[63:49] = Replicate{15}(Xt[36]);
            end;
        when '10' =&gt; // 16KB
            tg_bits = 14;
            if <a link="func_HasLargeAddress_1" file="shared_pseudocode.xml">HasLargeAddress</a>(regime) then
                start_address[52:16] = Xt[36:0];
                start_address[63:53] = Replicate{11}(Xt[36]);
            else
                start_address[50:14] = Xt[36:0];
                start_address[63:51] = Replicate{13}(Xt[36]);
            end;
        when '11' =&gt; // 64KB
            tg_bits = 16;
            start_address[52:16] = Xt[36:0];
            start_address[63:53] = Replicate{11}(Xt[36]);
        otherwise =&gt;
            unreachable;
    end;

    let range : integer = (num+1) &lt;&lt; (5*scale + 1 + tg_bits);
    end_address   = start_address + range[63:0];

    if IsFeatureImplemented(FEAT_LVA3) &amp;&amp; end_address[56] != start_address[56] then
        // overflow, saturate it
        end_address = Replicate{8}(start_address[56]) :: Ones{56};
    elsif end_address[52] != start_address[52] then
        // overflow, saturate it
        end_address = Replicate{12}(start_address[52]) :: Ones{52};
    end;

    return (valid, tg, start_address, end_address);
end;</pstext></ps>
    <ps name="aarch64/functions/vbitop/VBitOp" mylink="aarch64.functions.vbitop.VBitOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// VBitOp
// ======
// Vector bit select instruction types.

type <anchor link="type_VBitOp">VBitOp</anchor> of enumeration {<anchor link="enum_VBitOp_VBIF">VBitOp_VBIF</anchor>, <anchor link="enum_VBitOp_VBIT">VBitOp_VBIT</anchor>, <anchor link="enum_VBitOp_VBSL">VBitOp_VBSL</anchor>, <anchor link="enum_VBitOp_VEOR">VBitOp_VEOR</anchor>};</pstext></ps>
    <ps name="aarch64/translation/attrs/AArch64_MAIRAttr" mylink="aarch64.translation.attrs.AArch64_MAIRAttr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_MAIRAttr()
// ==================
// Retrieve the memory attribute encoding indexed in the given MAIR

func <anchor link="func_AArch64_MAIRAttr_3">AArch64_MAIRAttr</anchor>(index : integer, mair2 : MAIRType, mair : MAIRType) =&gt; bits(8)
begin
    assert (index &lt; 8 || (IsFeatureImplemented(FEAT_AIE) &amp;&amp; (index &lt; 16)));
    if (index &gt; 7) then
        return mair2[(index-8)*:8]; // Read from LSB at MAIR2
    else
        return mair[index*:8];
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/debug/AArch64_CheckBreakpoint" mylink="aarch64.translation.debug.AArch64_CheckBreakpoint" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CheckBreakpoint()
// =========================
// Called before executing the instruction of length &quot;size&quot; bytes at &quot;vaddress&quot; in an AArch64
// translation regime, when either debug exceptions are enabled, or halting debug is enabled
// and halting is allowed.

func <anchor link="func_AArch64_CheckBreakpoint_4">AArch64_CheckBreakpoint</anchor>(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, vaddress : bits(64),
                             accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>, size : integer) =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin
    assert !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>());
    assert (<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; size IN {2,4}) || size == 4;

    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;
    var match : boolean     = FALSE;
    var addr_match_bp : boolean     = FALSE; // Default assumption that all address match
                                             // breakpoints are inactive or disabled.
    var addr_mismatch_bp : boolean  = FALSE; // Default assumption that all address mismatch
                                             // breakpoints are inactive or disabled.
    var addr_match : boolean        = FALSE;
    var addr_mismatch : boolean     = TRUE;  // Default assumption that the given virtual address
                                             // is outside the range of all address mismatch
                                             // breakpoints.
    var ctxt_match : boolean        = FALSE;

    for i = 0 to <a link="func_NumBreakpointsImplemented_0" file="shared_pseudocode.xml">NumBreakpointsImplemented</a>() - 1 do
        let brkptinfo : <a link="type_BreakpointInfo" file="shared_pseudocode.xml">BreakpointInfo</a> = <a link="func_AArch64_BreakpointMatch_4" file="shared_pseudocode.xml">AArch64_BreakpointMatch</a>(i, vaddress, accdesc, size);
        if brkptinfo.bptype == <a link="enum_BreakpointType_AddrMatch" file="shared_pseudocode.xml">BreakpointType_AddrMatch</a> then
            addr_match_bp = TRUE;
            addr_match = addr_match || brkptinfo.match;
        elsif brkptinfo.bptype == <a link="enum_BreakpointType_AddrMismatch" file="shared_pseudocode.xml">BreakpointType_AddrMismatch</a> then
            addr_mismatch_bp = TRUE;
            addr_mismatch = addr_mismatch &amp;&amp; !brkptinfo.match;
        elsif brkptinfo.bptype == <a link="enum_BreakpointType_CtxtMatch" file="shared_pseudocode.xml">BreakpointType_CtxtMatch</a> then
            ctxt_match = ctxt_match || brkptinfo.match;
        end;
    end;
    if addr_match_bp &amp;&amp; addr_mismatch_bp then
        match = addr_match &amp;&amp; addr_mismatch;
    else
        match = (addr_match_bp &amp;&amp; addr_match) || (addr_mismatch_bp &amp;&amp; addr_mismatch);
    end;

    match = match || ctxt_match;

    if match then
        fault.statuscode = <a link="enum_Fault_Debug" file="shared_pseudocode.xml">Fault_Debug</a>;
        fault.vaddress   = vaddress;
        if <a link="func_HaltOnBreakpointOrWatchpoint_0" file="shared_pseudocode.xml">HaltOnBreakpointOrWatchpoint</a>() then
            let reason : bits(6) = <a link="global_DebugHalt_Breakpoint" file="shared_pseudocode.xml">DebugHalt_Breakpoint</a>;
            <a link="func_Halt_1" file="shared_pseudocode.xml">Halt</a>(reason);
        end;
    end;

    return fault;
end;</pstext></ps>
    <ps name="aarch64/translation/debug/AArch64_CheckDebug" mylink="aarch64.translation.debug.AArch64_CheckDebug" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CheckDebug()
// ====================
// Called on each access to check for a debug exception or entry to Debug state.

func <anchor link="func_AArch64_CheckDebug_3">AArch64_CheckDebug</anchor>(vaddress : bits(64), accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                        size : integer) =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin

    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_2" file="shared_pseudocode.xml">NoFault</a>(accdesc, vaddress);
    var generate_exception : boolean;

    let d_side : boolean = <a link="func_IsWatchpointableAccess_1" file="shared_pseudocode.xml">IsWatchpointableAccess</a>(accdesc);
    let i_side : boolean = (accdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a>);
    if accdesc.acctype == <a link="enum_AccessType_NV2" file="shared_pseudocode.xml">AccessType_NV2</a> then
        let mask : bit = '0';
        let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>();
        generate_exception = (<a link="func_AArch64_GenerateDebugExceptionsFrom_3" file="shared_pseudocode.xml">AArch64_GenerateDebugExceptionsFrom</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, ss, mask) &amp;&amp;
                              MDSCR_EL1().MDE == '1');
    else
        generate_exception = <a link="func_AArch64_GenerateDebugExceptions_0" file="shared_pseudocode.xml">AArch64_GenerateDebugExceptions</a>() &amp;&amp; MDSCR_EL1().MDE == '1';
    end;
    let halt : boolean = <a link="func_HaltOnBreakpointOrWatchpoint_0" file="shared_pseudocode.xml">HaltOnBreakpointOrWatchpoint</a>();

    if generate_exception || halt then
        if d_side then
            fault = <a link="func_AArch64_CheckWatchpoint_4" file="shared_pseudocode.xml">AArch64_CheckWatchpoint</a>(fault, vaddress, accdesc, size);
        elsif i_side then
            fault = <a link="func_AArch64_CheckBreakpoint_4" file="shared_pseudocode.xml">AArch64_CheckBreakpoint</a>(fault, vaddress, accdesc, size);
        end;
    end;

    return fault;
end;</pstext></ps>
    <ps name="aarch64/translation/debug/AArch64_CheckWatchpoint" mylink="aarch64.translation.debug.AArch64_CheckWatchpoint" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CheckWatchpoint()
// =========================
// Called before accessing the memory location of &quot;size&quot; bytes at &quot;address&quot;,
// when either debug exceptions are enabled for the access, or halting debug
// is enabled and halting is allowed.

func <anchor link="func_AArch64_CheckWatchpoint_4">AArch64_CheckWatchpoint</anchor>(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, vaddress_in : bits(64),
                             accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>, size_in : integer) =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin
    assert !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="func_S1TranslationRegime_0" file="shared_pseudocode.xml">S1TranslationRegime</a>());
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>          = fault_in;
    var fault_match : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>    = fault_in;
    var fault_mismatch : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;
    var vaddress : bits(64)          = vaddress_in;
    var size : integer               = size_in;
    var rounded_match : boolean      = FALSE;
    let original_vaddress : bits(64) = vaddress;
    let original_size : integer = size;
    var addr_match_wp : boolean      = FALSE;// Default assumption that all address
                                             //  match watchpoints are inactive or disabled.
    var addr_mismatch_wp : boolean   = FALSE; // Default assumption that all address mismatch
                                              // watchpoints are inactive or disabled.
    var addr_match : boolean         = FALSE;
    var addr_mismatch : boolean      = TRUE;// Default assumption that the given virtual address is
                                            // outside the range of all address mismatch watchpoints

    // For memory accesses of below type
    // - Contiguous SVE access
    // - SME access
    // - SIMD&amp;FP access when the PE is in Streaming SVE mode
    // each call to this function is such that:
    // - the lowest accessed address is rounded down to the nearest multiple of 16 bytes
    // - the highest accessed address is rounded up to the nearest multiple of 16 bytes
    // Since the WPF field is set if the implementation does rounding, regardless of true or
    // false match, it would be acceptable to return TRUE for either/both of the first and last
    // access.
    if <a link="func_IsRelaxedWatchpointAccess_1" file="shared_pseudocode.xml">IsRelaxedWatchpointAccess</a>(accdesc) then
        var upper_vaddress : integer = UInt(original_vaddress) + original_size;
        if <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_16BYTEROUNDEDDOWNACCESS" file="shared_pseudocode.xml">Unpredictable_16BYTEROUNDEDDOWNACCESS</a>) then
            vaddress = AlignDownSize{64}(vaddress, 16);
            rounded_match = TRUE;
        end;
        if <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_16BYTEROUNDEDUPACCESS" file="shared_pseudocode.xml">Unpredictable_16BYTEROUNDEDUPACCESS</a>) then
            upper_vaddress = AlignUpSize(upper_vaddress,16);
            rounded_match = TRUE;
        end;
        size = upper_vaddress - UInt(vaddress);
    end;

    for i = 0 to <a link="func_NumWatchpointsImplemented_0" file="shared_pseudocode.xml">NumWatchpointsImplemented</a>() - 1 do
        let watchptinfo : <a link="type_WatchpointInfo" file="shared_pseudocode.xml">WatchpointInfo</a> = <a link="func_AArch64_WatchpointMatch_4" file="shared_pseudocode.xml">AArch64_WatchpointMatch</a>(i, vaddress, size, accdesc);
        if watchptinfo.wptype == <a link="enum_WatchpointType_AddrMatch" file="shared_pseudocode.xml">WatchpointType_AddrMatch</a> then
            addr_match_wp = TRUE;
            addr_match = addr_match || watchptinfo.value_match;
            if watchptinfo.value_match then
                fault_match.statuscode = <a link="enum_Fault_Debug" file="shared_pseudocode.xml">Fault_Debug</a>;
                if DBGWCR_EL1(i).LSC[0] == '1' &amp;&amp; accdesc.read then
                    fault_match.write = FALSE;
                elsif DBGWCR_EL1(i).LSC[1] == '1' &amp;&amp; accdesc.write then
                    fault_match.write = TRUE;
                end;
                fault_match.watchptinfo = watchptinfo;
            end;
        elsif watchptinfo.wptype == <a link="enum_WatchpointType_AddrMismatch" file="shared_pseudocode.xml">WatchpointType_AddrMismatch</a> then
            addr_mismatch_wp = TRUE;
            addr_mismatch = addr_mismatch &amp;&amp; !watchptinfo.value_match;
            if !watchptinfo.value_match then
                fault_mismatch.statuscode = <a link="enum_Fault_Debug" file="shared_pseudocode.xml">Fault_Debug</a>;
                if DBGWCR_EL1(i).LSC[0] == '1' &amp;&amp; accdesc.read then
                    fault_mismatch.write = FALSE;
                elsif DBGWCR_EL1(i).LSC[1] == '1' &amp;&amp; accdesc.write then
                    fault_mismatch.write = TRUE;
                end;
                fault_mismatch.watchptinfo = watchptinfo;
            end;
        end;
    end;
    if ((addr_match_wp &amp;&amp; addr_mismatch_wp &amp;&amp; addr_match &amp;&amp; addr_mismatch) ||
        (addr_match_wp &amp;&amp; !addr_mismatch_wp &amp;&amp; addr_match)) then
        fault = fault_match;
    elsif !addr_match_wp &amp;&amp; addr_mismatch_wp &amp;&amp; addr_mismatch then
        fault = fault_mismatch;
    end;
    fault.vaddress = vaddress;
    fault.watchptinfo.maybe_false_match = rounded_match;
    if (fault.statuscode == <a link="enum_Fault_Debug" file="shared_pseudocode.xml">Fault_Debug</a> &amp;&amp; <a link="func_HaltOnBreakpointOrWatchpoint_0" file="shared_pseudocode.xml">HaltOnBreakpointOrWatchpoint</a>() &amp;&amp;
            !accdesc.nonfault &amp;&amp; !(accdesc.firstfault &amp;&amp; !accdesc.first)) then
        let reason : bits(6) = <a link="global_DebugHalt_Watchpoint" file="shared_pseudocode.xml">DebugHalt_Watchpoint</a>;
        EDWAR() = fault.vaddress;
        let is_async : boolean = FALSE;
        <a link="func_Halt_3" file="shared_pseudocode.xml">Halt</a>(reason, is_async, fault);
    end;
    return fault;
end;</pstext></ps>
    <ps name="aarch64/translation/hdbss/AppendToHDBSS" mylink="aarch64.translation.hdbss.AppendToHDBSS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AppendToHDBSS()
// ===============
// Appends an entry to the HDBSS when the dirty state of a stage 2 descriptor is updated
// from writable-clean to writable-dirty by hardware.

func <anchor link="func_AppendToHDBSS_5">AppendToHDBSS</anchor>(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, ipa_in : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>, accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                   walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>, level : integer) =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin
    assert <a link="func_CanAppendToHDBSS_0" file="shared_pseudocode.xml">CanAppendToHDBSS</a>();

    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>  = fault_in;
    var ipa : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>    = ipa_in;
    let hdbss_size : integer{} = UInt(HDBSSBR_EL2().SZ) as integer{0..9};

    var hdbss_addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;

    var baddr : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>) = HDBSSBR_EL2().BADDR[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-13 : 0] :: Zeros{12};
    baddr[11 + hdbss_size : 12]  = Zeros{hdbss_size};

    hdbss_addrdesc.paddress.address = baddr + (8 * UInt(HDBSSPROD_EL2().INDEX));
    let nse2 : bit = '0';     // NSE2 has the Effective value of 0 within a PE.
    hdbss_addrdesc.paddress.paspace = <a link="func_DecodePASpace_3" file="shared_pseudocode.xml">DecodePASpace</a>(nse2, <a link="func_EffectiveSCR_EL3_NSE_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NSE</a>(),
                                                    <a link="func_EffectiveSCR_EL3_NS_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NS</a>());

    // Accesses to the HDBSS use the same memory attributes as used for stage 2 translation walks.
    hdbss_addrdesc.memattrs         = <a link="func_WalkMemAttrs_3" file="shared_pseudocode.xml">WalkMemAttrs</a>(walkparams.sh, walkparams.irgn, walkparams.orgn);
    let hdbss_access : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescHDBSS_1" file="shared_pseudocode.xml">CreateAccDescHDBSS</a>(accdesc);
    hdbss_addrdesc.mecid            = <a link="func_AArch64_S2TTWalkMECID_2" file="shared_pseudocode.xml">AArch64_S2TTWalkMECID</a>(walkparams.emec, accdesc.ss);

    if IsFeatureImplemented(FEAT_RME) then
        fault.gpcf = <a link="func_GranuleProtectionCheck_2" file="shared_pseudocode.xml">GranuleProtectionCheck</a>(hdbss_addrdesc, hdbss_access);

        if fault.gpcf.gpf != <a link="enum_GPCF_None" file="shared_pseudocode.xml">GPCF_None</a> then
            if (ImpDefBool(
                  &quot;GPC fault on HDBSSS write reported in HDBSSPROD_EL2&quot;)) then
                HDBSSPROD_EL2().FSC = '101000';
            else
                fault.statuscode = <a link="enum_Fault_GPCFOnWalk" file="shared_pseudocode.xml">Fault_GPCFOnWalk</a>;
                fault.paddress   = hdbss_addrdesc.paddress;
                fault.level      = level;
                fault.gpcfs2walk = TRUE;
                fault.hdbssf     = TRUE;
            end;

            return fault;
        end;
    end;

    // The reported IPA must be aligned to the size of the translation.
    let lsb : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_TranslationSize_3" file="shared_pseudocode.xml">TranslationSize</a>(walkparams.d128, walkparams.tgx, level);
    ipa.address           = ipa.address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:lsb] :: Zeros{lsb};
    var hdbss_entry : bits(64) = <a link="func_CreateHDBSSEntry_3" file="shared_pseudocode.xml">CreateHDBSSEntry</a>(ipa, hdbss_access.ss, level);

    if walkparams.ee == '1' then
        hdbss_entry = <a link="func_BigEndianReverse_2" file="shared_pseudocode.xml">BigEndianReverse</a>{64}(hdbss_entry);
    end;

    let memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a> = <a link="func_PhysMemWrite_4" file="shared_pseudocode.xml">PhysMemWrite</a>{64}(hdbss_addrdesc, hdbss_access,
                                                        hdbss_entry);

    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
        if (ImpDefBool(
              &quot;External Abort on HDBSS write reported in HDBSSPROD_EL2&quot;)) then
            HDBSSPROD_EL2().FSC = '010000';
        else
            let iswrite : boolean = TRUE;
            fault = <a link="func_HandleExternalTTWAbort_6" file="shared_pseudocode.xml">HandleExternalTTWAbort</a>(memstatus, iswrite, hdbss_addrdesc,
                                           hdbss_access, 8, fault);
            fault.level  = level;
            fault.hdbssf = TRUE;
        end;
    else
        HDBSSPROD_EL2().INDEX = HDBSSPROD_EL2().INDEX + 1;
    end;

    return fault;
end;</pstext></ps>
    <ps name="aarch64/translation/hdbss/CanAppendToHDBSS" mylink="aarch64.translation.hdbss.CanAppendToHDBSS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CanAppendToHDBSS()
// ==================
// Return TRUE if HDBSS can be appended.

readonly func <anchor link="func_CanAppendToHDBSS_0">CanAppendToHDBSS</anchor>() =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_HDBSS) then
        return FALSE;
    end;
    assert <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>();
    // The PE cannot append entries to the HDBSS if HDBSSPROD_EL2.FSC is
    // any other value than 0b000000, or HDBSS buffer is full.

    if ((UInt(HDBSSPROD_EL2().INDEX) &gt;= ((2 ^ (UInt(HDBSSBR_EL2().SZ) + 12)) DIV 8)) ||
         (HDBSSPROD_EL2().FSC != '000000')) then
        return FALSE;
    else
        return TRUE;
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/hdbss/CreateHDBSSEntry" mylink="aarch64.translation.hdbss.CreateHDBSSEntry" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateHDBSSEntry()
// ==================
// Returns a HDBSS entry.

func <anchor link="func_CreateHDBSSEntry_3">CreateHDBSSEntry</anchor>(ipa : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>, ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, level : integer) =&gt; bits(64)
begin
    let ns_ipa : bit = if ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> &amp;&amp; ipa.paspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> then '1' else '0';
    return ZeroExtend{64}(ipa.address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:12] ::
                          ns_ipa :: Zeros{7} :: level[2:0] :: '1');
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_addrcalc/AArch64_IASize" mylink="aarch64.translation.vmsa_addrcalc.AArch64_IASize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_IASize()
// ================
// Retrieve the number of bits containing the input address

func <anchor link="func_AArch64_IASize_1">AArch64_IASize</anchor>(txsz : bits(6)) =&gt; <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>
begin
    return (64 - UInt(txsz)) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_addrcalc/AArch64_NextTableBase" mylink="aarch64.translation.vmsa_addrcalc.AArch64_NextTableBase" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_NextTableBase()
// =======================
// Extract the address embedded in a table descriptor pointing to the base of
// the next level table of descriptors

func <anchor link="func_AArch64_NextTableBase_6">AArch64_NextTableBase</anchor>{N}(descriptor : bits(N), d128 : bit, skl : bits(2),
                              ds : bit, tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>) =&gt; bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>)
begin
    var tablebase : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>) = Zeros{};
    let granulebits : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_TGxGranuleBits_1" file="shared_pseudocode.xml">TGxGranuleBits</a>(tgx);
    var tablesize : integer;

    if d128 == '1' then
        let descsizelog2 : integer = 4;
        let stride : integer = granulebits - descsizelog2;
        tablesize = stride*(1 + UInt(skl)) + descsizelog2;
    else
        tablesize = granulebits;
    end;

    case tgx of
        when <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a> =&gt;  tablebase[47:12] = descriptor[47:12];
        when <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a> =&gt; tablebase[47:14] = descriptor[47:14];
        when <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> =&gt; tablebase[47:16] = descriptor[47:16];
    end;

    tablebase = AlignDownP2{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(tablebase, tablesize as integer{0..<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>});

    if d128 == '1' then
        tablebase[55:48] = descriptor[55:48];
    elsif tgx == <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> &amp;&amp; (<a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>() &gt;= 52 ||
            ImpDefBool(&quot;descriptor[15:12] for 64KB granule are OA[51:48]&quot;)) then
        tablebase[51:48] = descriptor[15:12];
    elsif ds == '1' then
        tablebase[51:48] = descriptor[9:8]::descriptor[49:48];
    end;

    return tablebase;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_addrcalc/AArch64_PhysicalAddressSize" mylink="aarch64.translation.vmsa_addrcalc.AArch64_PhysicalAddressSize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_PhysicalAddressSize()
// =============================
// Retrieve the number of bits bounding the physical address

func <anchor link="func_AArch64_PhysicalAddressSize_4">AArch64_PhysicalAddressSize</anchor>(d128 : bit, ds : bit, encoded_ps : bits(3),
                                 tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>) =&gt; <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>
begin
    var ps : integer;
    var max_ps : integer;

    case encoded_ps of
        when '000' =&gt;  ps = 32;
        when '001' =&gt;  ps = 36;
        when '010' =&gt;  ps = 40;
        when '011' =&gt;  ps = 42;
        when '100' =&gt;  ps = 44;
        when '101' =&gt;  ps = 48;
        when '110' =&gt;  ps = 52;
        when '111' =&gt;  ps = 56;
    end;

    if d128 == '1' then
        max_ps = <a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>();
    elsif IsFeatureImplemented(FEAT_LPA) &amp;&amp; (tgx == <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> || ds == '1') then
        max_ps = Min(52, <a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>());
    else
        max_ps = Min(48, <a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>());
    end;

    return Min(ps, max_ps) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_addrcalc/AArch64_S1LeafBase" mylink="aarch64.translation.vmsa_addrcalc.AArch64_S1LeafBase" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1LeafBase()
// ====================
// Extract the address embedded in a block and page descriptor pointing to the
// base of a memory block

func <anchor link="func_AArch64_S1LeafBase_4">AArch64_S1LeafBase</anchor>{N}(descriptor : bits(N), walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>,
                           level : integer) =&gt; bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>)
begin
    var leafbase : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>) = Zeros{};

    let granulebits : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>  = <a link="func_TGxGranuleBits_1" file="shared_pseudocode.xml">TGxGranuleBits</a>(walkparams.tgx);
    let descsizelog2 : integer{}   = if walkparams.d128 == '1' then 4 else 3;
    let stride : integer = granulebits - descsizelog2;
    let leafsize : integer = granulebits + stride * (<a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - level);

    leafbase[47:0] = AlignDownP2{48}(descriptor[47:0], leafsize as integer{0..48});

    if walkparams.d128 == '1' then
        leafbase[55:48] = descriptor[55:48];
    elsif walkparams.tgx == <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> &amp;&amp; (<a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>() &gt;= 52 ||
            ImpDefBool(&quot;descriptor[15:12] for 64KB granule are OA[51:48]&quot;)) then
        leafbase[51:48] = descriptor[15:12];
    elsif walkparams.ds == '1' then
        leafbase[51:48] = descriptor[9:8,49:48];
    end;

    return leafbase;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_addrcalc/AArch64_S1SLTTEntryAddress" mylink="aarch64.translation.vmsa_addrcalc.AArch64_S1SLTTEntryAddress" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1SLTTEntryAddress()
// ============================
// Compute the first stage 1 translation table descriptor address within the
// table pointed to by the base at the start level

func <anchor link="func_AArch64_S1SLTTEntryAddress_4">AArch64_S1SLTTEntryAddress</anchor>(level : integer, walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>,
                                ia : bits(64), tablebase : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>) =&gt; <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>
begin
    // Input Address size
    let iasize : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>       = <a link="func_AArch64_IASize_1" file="shared_pseudocode.xml">AArch64_IASize</a>(walkparams.txsz);
    let granulebits : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>  = <a link="func_TGxGranuleBits_1" file="shared_pseudocode.xml">TGxGranuleBits</a>(walkparams.tgx);
    let descsizelog2 : integer{} = if walkparams.d128 == '1' then 4 else 3;
    let stride : integer{}       = granulebits - descsizelog2;
    let levels : integer         = <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - level;

    var index : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>);
    let lsb : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = (levels*stride + granulebits) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
    let msb : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = (iasize - 1) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
    index = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(ia[msb:lsb]::Zeros{descsizelog2});

    var descaddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    descaddress.address = tablebase.address OR index;
    descaddress.paspace = tablebase.paspace;

    return descaddress;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_addrcalc/AArch64_S1StartLevel" mylink="aarch64.translation.vmsa_addrcalc.AArch64_S1StartLevel" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1StartLevel()
// ======================
// Compute the initial lookup level when performing a stage 1 translation
// table walk

func <anchor link="func_AArch64_S1StartLevel_1">AArch64_S1StartLevel</anchor>(walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>) =&gt; integer
begin
    // Input Address size
    let iasize : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>       = <a link="func_AArch64_IASize_1" file="shared_pseudocode.xml">AArch64_IASize</a>(walkparams.txsz);
    let granulebits : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>  = <a link="func_TGxGranuleBits_1" file="shared_pseudocode.xml">TGxGranuleBits</a>(walkparams.tgx);
    let descsizelog2 : integer = if walkparams.d128 == '1' then 4 else 3;
    let stride : integer       = granulebits - descsizelog2;
    var s1startlevel : integer = <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - (((iasize-1) - granulebits) DIVRM stride);
    if walkparams.d128 == '1' then
        s1startlevel = s1startlevel + UInt(walkparams.skl);
    end;
    return s1startlevel;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_addrcalc/AArch64_S1TTBaseAddress" mylink="aarch64.translation.vmsa_addrcalc.AArch64_S1TTBaseAddress" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1TTBaseAddress()
// =========================
// Retrieve the PA/IPA pointing to the base of the initial translation table of stage 1

func <anchor link="func_AArch64_S1TTBaseAddress_4">AArch64_S1TTBaseAddress</anchor>{N}(walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>,
                                regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, ttbr : bits(N)) =&gt; bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>)
begin
    var tablebase : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>) = Zeros{};

    // Input Address size
    let iasize : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>      = <a link="func_AArch64_IASize_1" file="shared_pseudocode.xml">AArch64_IASize</a>(walkparams.txsz);
    let granulebits : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_TGxGranuleBits_1" file="shared_pseudocode.xml">TGxGranuleBits</a>(walkparams.tgx);
    let descsizelog2 : integer{} = if walkparams.d128 == '1' then 4 else 3;
    let stride : integer{}    = granulebits - descsizelog2;
    let startlevel : integer  = <a link="func_AArch64_S1StartLevel_1" file="shared_pseudocode.xml">AArch64_S1StartLevel</a>(walkparams);
    let levels : integer      = <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - startlevel;

    // Base address is aligned to size of the initial translation table in bytes
    var tsize : integer = (iasize - (levels*stride + granulebits)) + descsizelog2;

    if walkparams.d128 == '1' then
        tsize = Max(tsize, 5);
        if regime == <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> then
            tablebase[55:5] = ttbr[55:5];
        else
            tablebase[55:5] = ttbr[87:80]::ttbr[47:5];
        end;
    elsif walkparams.ds == '1' || (walkparams.tgx == <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> &amp;&amp; walkparams.ps == '110' &amp;&amp;
            (IsFeatureImplemented(FEAT_LPA) ||
             ImpDefBool(&quot;BADDR expresses 52 bits for 64KB granule&quot;))) then
        tsize = Max(tsize, 6);
        tablebase[51:6] = ttbr[5:2]::ttbr[47:6];
    else
        tablebase[47:1] = ttbr[47:1];
    end;
    tablebase = AlignDownP2{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(tablebase,tsize as integer{0..<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>});
    return tablebase;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_addrcalc/AArch64_S1TTEntryAddress" mylink="aarch64.translation.vmsa_addrcalc.AArch64_S1TTEntryAddress" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1TTEntryAddress()
// ==========================
// Compute translation table descriptor address within the table pointed to by
// the table base

func <anchor link="func_AArch64_S1TTEntryAddress_7">AArch64_S1TTEntryAddress</anchor>{N}(level : integer, walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>, skl : bits(2),
                                 ia : bits(64), tablebase : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>,
                                 descriptor : bits(N)) =&gt; <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>
begin
    // Input Address size
    let iasize : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>      = <a link="func_AArch64_IASize_1" file="shared_pseudocode.xml">AArch64_IASize</a>(walkparams.txsz);
    let granulebits : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_TGxGranuleBits_1" file="shared_pseudocode.xml">TGxGranuleBits</a>(walkparams.tgx);
    let descsizelog2 : integer{} = if walkparams.d128 == '1' then 4 else 3;
    let stride : integer{}      = granulebits - descsizelog2;
    let levels : integer        = <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - level;

    var index : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>);

    let lsb : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = (levels*stride + granulebits) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
    let nstride : integer = if walkparams.d128 == '1' then UInt(skl) + 1 else 1;
    let msb : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = ((lsb + (stride * nstride)) - 1) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
    index = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(ia[msb:lsb]::Zeros{descsizelog2});

    var descaddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    descaddress.address = tablebase.address OR index;
    descaddress.paspace = tablebase.paspace;

    return descaddress;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_addrcalc/AArch64_S2LeafBase" mylink="aarch64.translation.vmsa_addrcalc.AArch64_S2LeafBase" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2LeafBase()
// ====================
// Extract the address embedded in a block and page descriptor pointing to the
// base of a memory block

func <anchor link="func_AArch64_S2LeafBase_4">AArch64_S2LeafBase</anchor>{N}(descriptor : bits(N), walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>,
                           level : integer) =&gt; bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>)
begin
    var leafbase : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>) = Zeros{};

    let granulebits : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>  = <a link="func_TGxGranuleBits_1" file="shared_pseudocode.xml">TGxGranuleBits</a>(walkparams.tgx);
    let descsizelog2 : integer{} = if walkparams.d128 == '1' then 4 else 3;
    let stride : integer   = granulebits - descsizelog2;
    let leafsize : integer = granulebits + stride * (<a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - level);

    leafbase[47:0] = AlignDownP2{48}(descriptor[47:0], leafsize as integer{0..48});

    if walkparams.d128 == '1' then
        leafbase[55:48] = descriptor[55:48];
    elsif walkparams.tgx == <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> &amp;&amp; (<a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>() &gt;= 52 ||
            (ImpDefBool(
               &quot;descriptor[15:12] for 64KB granule are OA[51:48]&quot;))) then
        leafbase[51:48] = descriptor[15:12];
    elsif walkparams.ds == '1' then
        leafbase[51:48] = descriptor[9:8]::descriptor[49:48];
    end;

    return leafbase;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_addrcalc/AArch64_S2SLTTEntryAddress" mylink="aarch64.translation.vmsa_addrcalc.AArch64_S2SLTTEntryAddress" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2SLTTEntryAddress()
// ============================
// Compute the first stage 2 translation table descriptor address within the
// table pointed to by the base at the start level

func <anchor link="func_AArch64_S2SLTTEntryAddress_3">AArch64_S2SLTTEntryAddress</anchor>(walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>, ipa : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>),
                                tablebase : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>) =&gt; <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>
begin
    let startlevel   = <a link="func_AArch64_S2StartLevel_1" file="shared_pseudocode.xml">AArch64_S2StartLevel</a>(walkparams);
    let iasize       = <a link="func_AArch64_IASize_1" file="shared_pseudocode.xml">AArch64_IASize</a>(walkparams.txsz);
    let granulebits  = <a link="func_TGxGranuleBits_1" file="shared_pseudocode.xml">TGxGranuleBits</a>(walkparams.tgx);
    let descsizelog2 : integer{} = if walkparams.d128 == '1' then 4 else 3;
    let stride : integer{}       = granulebits - descsizelog2;
    let levels : integer         = <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - startlevel;

    var index : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>);
    let lsb : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = (levels*stride + granulebits) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
    let msb : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = (iasize - 1) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
    index = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(ipa[msb:lsb]::Zeros{descsizelog2});

    var descaddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    descaddress.address = tablebase.address OR index;
    descaddress.paspace = tablebase.paspace;

    return descaddress;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_addrcalc/AArch64_S2StartLevel" mylink="aarch64.translation.vmsa_addrcalc.AArch64_S2StartLevel" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2StartLevel()
// ======================
// Determine the initial lookup level when performing a stage 2 translation
// table walk

func <anchor link="func_AArch64_S2StartLevel_1">AArch64_S2StartLevel</anchor>(walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>) =&gt; integer
begin
    if walkparams.d128 == '1' then
        let iasize       : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_AArch64_IASize_1" file="shared_pseudocode.xml">AArch64_IASize</a>(walkparams.txsz);
        let granulebits  : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_TGxGranuleBits_1" file="shared_pseudocode.xml">TGxGranuleBits</a>(walkparams.tgx);
        let descsizelog2 : integer{} = 4;
        let stride : integer = granulebits - descsizelog2;
        var s2startlevel : integer = <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - (((iasize-1) - granulebits) DIVRM stride);
        s2startlevel = s2startlevel + UInt(walkparams.skl);

        return s2startlevel;
    end;

    case walkparams.tgx of
        when <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a> =&gt;
            case walkparams.sl2::walkparams.sl0 of
                when '000' =&gt; return 2;
                when '001' =&gt; return 1;
                when '010' =&gt; return 0;
                when '011' =&gt; return 3;
                when '100' =&gt; return -1;
            end;
        when <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a> =&gt;
            case walkparams.sl0 of
                when '00' =&gt; return 3;
                when '01' =&gt; return 2;
                when '10' =&gt; return 1;
                when '11' =&gt; return 0;
            end;
        when <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> =&gt;
            case walkparams.sl0 of
                when '00' =&gt; return 3;
                when '01' =&gt; return 2;
                when '10' =&gt; return 1;
            end;
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_addrcalc/AArch64_S2TTBaseAddress" mylink="aarch64.translation.vmsa_addrcalc.AArch64_S2TTBaseAddress" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2TTBaseAddress()
// =========================
// Retrieve the PA/IPA pointing to the base of the initial translation table of stage 2

func <anchor link="func_AArch64_S2TTBaseAddress_4">AArch64_S2TTBaseAddress</anchor>{N}(walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>, paspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>,
                                ttbr : bits(N)) =&gt; bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>)
begin
    var tablebase : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>) = Zeros{};

    // Input Address size
    let iasize : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>      = <a link="func_AArch64_IASize_1" file="shared_pseudocode.xml">AArch64_IASize</a>(walkparams.txsz);
    let granulebits : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_TGxGranuleBits_1" file="shared_pseudocode.xml">TGxGranuleBits</a>(walkparams.tgx);
    let descsizelog2 : integer{}  = if walkparams.d128 == '1' then 4 else 3;
    let stride : integer{}        = granulebits - descsizelog2;
    let startlevel : integer      = <a link="func_AArch64_S2StartLevel_1" file="shared_pseudocode.xml">AArch64_S2StartLevel</a>(walkparams);
    let levels : integer          = <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - startlevel;

    // Base address is aligned to size of the initial translation table in bytes
    var tsize : integer = (iasize - (levels*stride + granulebits)) + descsizelog2;

    if walkparams.d128 == '1' then
        tsize = Max(tsize, 5);
        if paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> then
            tablebase[55:5] = ttbr[55:5];
        else
            tablebase[55:5] = ttbr[87:80]::ttbr[47:5];
        end;
    elsif walkparams.ds == '1' || (walkparams.tgx == <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> &amp;&amp; walkparams.ps == '110' &amp;&amp;
            (IsFeatureImplemented(FEAT_LPA) ||
             ImpDefBool(&quot;BADDR expresses 52 bits for 64KB granule&quot;))) then
        tsize = Max(tsize, 6);
        tablebase[51:6] = ttbr[5:2]::ttbr[47:6];
    else
        tablebase[47:1] = ttbr[47:1];
    end;
    tablebase = AlignDownP2{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(tablebase, tsize as integer{0..<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>});
    return tablebase;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_addrcalc/AArch64_S2TTEntryAddress" mylink="aarch64.translation.vmsa_addrcalc.AArch64_S2TTEntryAddress" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2TTEntryAddress()
// ==========================
// Compute translation table descriptor address within the table pointed to by
// the table base

func <anchor link="func_AArch64_S2TTEntryAddress_5">AArch64_S2TTEntryAddress</anchor>(level : integer, walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>, skl :  bits(2),
                              ipa :  bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>), tablebase : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>) =&gt; <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>
begin
    let ipasize : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>     = <a link="func_AArch64_IASize_1" file="shared_pseudocode.xml">AArch64_IASize</a>(walkparams.txsz);
    let granulebits : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_TGxGranuleBits_1" file="shared_pseudocode.xml">TGxGranuleBits</a>(walkparams.tgx);
    let descsizelog2 : integer{} = if walkparams.d128 == '1' then 4 else 3;
    let stride : integer{}      = granulebits - descsizelog2;
    let levels : integer        = <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - level;

    var index : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>);

    let lsb : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = (levels*stride + granulebits) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
    let nstride : integer = if walkparams.d128 == '1' then UInt(skl) + 1 else 1;
    let msb : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = ((lsb + (stride * nstride)) - 1) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
    index = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(ipa[msb:lsb]::Zeros{descsizelog2});

    var descaddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    descaddress.address = tablebase.address OR index;
    descaddress.paspace = tablebase.paspace;

    return descaddress;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_AddrTop" mylink="aarch64.translation.vmsa_faults.AArch64_AddrTop" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_AddrTop()
// =================
// Get the top bit position of the virtual address.
// Bits above are not accounted as part of the translation process.

func <anchor link="func_AArch64_AddrTop_3">AArch64_AddrTop</anchor>(tbid : bit, acctype : <a link="type_AccessType" file="shared_pseudocode.xml">AccessType</a>, tbi : bit) =&gt; <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>
begin
    if tbid == '1' &amp;&amp; acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> then
        return 63;
    end;

    if tbi == '1' then
        return 55;
    else
        return 63;
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_ContiguousBitFaults" mylink="aarch64.translation.vmsa_faults.AArch64_ContiguousBitFaults" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ContiguousBitFaults()
// =============================
// If contiguous bit is set, returns whether the translation size exceeds the
// input address size and if the implementation generates a fault

func <anchor link="func_AArch64_ContiguousBitFaults_4">AArch64_ContiguousBitFaults</anchor>(d128 : bit, txsz : bits(6), tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>, level : integer) =&gt; boolean
begin
    // Input Address size
    let iasize : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_AArch64_IASize_1" file="shared_pseudocode.xml">AArch64_IASize</a>(txsz);
    // Translation size
    let tsize : integer = <a link="func_TranslationSize_3" file="shared_pseudocode.xml">TranslationSize</a>(d128, tgx, level) + <a link="func_ContiguousSize_3" file="shared_pseudocode.xml">ContiguousSize</a>(d128, tgx, level);

    return (tsize &gt; iasize &amp;&amp;
            ImpDefBool(&quot;Translation fault on misprogrammed contiguous bit&quot;));
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_IPAIsOutOfRange" mylink="aarch64.translation.vmsa_faults.AArch64_IPAIsOutOfRange" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_IPAIsOutOfRange()
// =========================
// Check bits not resolved by translation are ZERO

func <anchor link="func_AArch64_IPAIsOutOfRange_2">AArch64_IPAIsOutOfRange</anchor>(ipa : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>), walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>) =&gt; boolean
begin
    //Input Address size
    let iasize : integer{} = <a link="func_AArch64_IASize_1" file="shared_pseudocode.xml">AArch64_IASize</a>(walkparams.txsz);

    if iasize &lt; <a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a> then
        return !IsZero(ipa[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:iasize]);
    else
        return FALSE;
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_OAOutOfRange" mylink="aarch64.translation.vmsa_faults.AArch64_OAOutOfRange" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_OAOutOfRange()
// ======================
// Returns whether output address is expressed in the configured size number of bits

func <anchor link="func_AArch64_OAOutOfRange_5">AArch64_OAOutOfRange</anchor>(address : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>), d128 : bit,
                          ds : bit, ps : bits(3), tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>) =&gt; boolean
begin
    // Output Address size
    let oasize : integer{} = <a link="func_AArch64_PhysicalAddressSize_4" file="shared_pseudocode.xml">AArch64_PhysicalAddressSize</a>(d128, ds, ps, tgx);

    if oasize &lt; <a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a> then
        return !IsZero(address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:oasize]);
    else
        return FALSE;
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_PermissionOverlaysApplied" mylink="aarch64.translation.vmsa_faults.AArch64_PermissionOverlaysApplied" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_PermissionOverlaysApplied()
// ===================================
// Returns TRUE if Permission overlays are applied for the given access type.

func <anchor link="func_AArch64_PermissionsOverlaysApplied_1">AArch64_PermissionsOverlaysApplied</anchor>(acctype : <a link="type_AccessType" file="shared_pseudocode.xml">AccessType</a>) =&gt; boolean
begin
    case acctype of
        when <a link="enum_AccessType_SPE" file="shared_pseudocode.xml">AccessType_SPE</a>        =&gt; return FALSE;
        when <a link="enum_AccessType_TRBE" file="shared_pseudocode.xml">AccessType_TRBE</a>       =&gt; return FALSE;
        otherwise                  =&gt; return TRUE;
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_S1CheckPermissions" mylink="aarch64.translation.vmsa_faults.AArch64_S1CheckPermissions" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1CheckPermissions()
// ============================
// Checks whether stage 1 access violates permissions of target memory
// and returns a fault record

func <anchor link="func_AArch64_S1CheckPermissions_7">AArch64_S1CheckPermissions</anchor>(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, va : bits(64), size : integer,
                                regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>,
                                accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;
    let permissions : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a> = walkstate.permissions;
    var s1perms : <a link="type_S1AccessControls" file="shared_pseudocode.xml">S1AccessControls</a> = <a link="func_AArch64_S1ComputePermissions_4" file="shared_pseudocode.xml">AArch64_S1ComputePermissions</a>(regime, walkstate,
                                                                  walkparams, accdesc);

    if accdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> then
        // Flag the access is from a guarded page
        <a link="func_SetInGuardedPage_1" file="shared_pseudocode.xml">SetInGuardedPage</a>(walkstate.guardedpage == '1' &amp;&amp; s1perms.x == '1');

        if s1perms.overlay &amp;&amp; s1perms.ox == '0' then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            fault.overlay    = TRUE;
        elsif (walkstate.memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> &amp;&amp;
                ConstrainUnpredictable(<a link="enum_Unpredictable_INSTRDEVICE" file="shared_pseudocode.xml">Unpredictable_INSTRDEVICE</a>) == <a link="enum_Constraint_FAULT" file="shared_pseudocode.xml">Constraint_FAULT</a>) then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        elsif s1perms.x == '0' then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        end;
    elsif accdesc.acctype == <a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a> then
        if accdesc.cacheop == <a link="enum_CacheOp_Invalidate" file="shared_pseudocode.xml">CacheOp_Invalidate</a> then
            if s1perms.overlay &amp;&amp; s1perms.ow == '0' then
                fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
                fault.overlay    = TRUE;
            elsif s1perms.w == '0' then
                fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            elsif (walkparams.hd != '1' &amp;&amp; walkparams.pie == '1' &amp;&amp;
                     permissions.ndirty == '1') then
                fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
                fault.dirtybit   = TRUE;
            end;
        // DC from privileged context which clean cannot generate a Permission fault
        elsif accdesc.el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
            if s1perms.overlay &amp;&amp; s1perms.or == '0' then
                fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
                fault.overlay    = TRUE;
            elsif (walkparams.cmow == '1' &amp;&amp;
                    accdesc.cacheop == <a link="enum_CacheOp_CleanInvalidate" file="shared_pseudocode.xml">CacheOp_CleanInvalidate</a> &amp;&amp;
                    s1perms.overlay &amp;&amp; s1perms.ow == '0') then
                fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
                fault.overlay    = TRUE;
            elsif s1perms.r == '0' then
                fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            elsif (walkparams.cmow == '1' &amp;&amp;
                    accdesc.cacheop == <a link="enum_CacheOp_CleanInvalidate" file="shared_pseudocode.xml">CacheOp_CleanInvalidate</a> &amp;&amp;
                    s1perms.w == '0') then
                fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            elsif (walkparams.cmow == '1' &amp;&amp; walkparams.hd != '1' &amp;&amp; walkparams.pie == '1' &amp;&amp;
                     permissions.ndirty == '1' &amp;&amp; accdesc.cacheop == <a link="enum_CacheOp_CleanInvalidate" file="shared_pseudocode.xml">CacheOp_CleanInvalidate</a>) then
                fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
                fault.dirtybit   = TRUE;
            end;
        end;
    elsif accdesc.acctype == <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a> then
        // IC from privileged context cannot generate Permission fault
        if accdesc.el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
            if (s1perms.overlay &amp;&amp; s1perms.or == '0' &amp;&amp;
                  ImpDefBool(&quot;Permission fault on EL0 IC_IVAU execution&quot;)) then
                fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
                fault.overlay    = TRUE;
            elsif walkparams.cmow == '1' &amp;&amp; s1perms.overlay &amp;&amp; s1perms.ow == '0' then
                fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
                fault.overlay    = TRUE;
            elsif (s1perms.r == '0' &amp;&amp;
                  ImpDefBool(&quot;Permission fault on EL0 IC_IVAU execution&quot;)) then
                fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            elsif walkparams.cmow == '1' &amp;&amp; s1perms.w == '0' then
                fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            elsif (walkparams.cmow == '1' &amp;&amp; walkparams.hd != '1' &amp;&amp; walkparams.pie == '1' &amp;&amp;
                     permissions.ndirty == '1') then
                fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
                fault.dirtybit   = TRUE;
            end;
        end;
    elsif IsFeatureImplemented(FEAT_GCS) &amp;&amp; accdesc.acctype == <a link="enum_AccessType_GCS" file="shared_pseudocode.xml">AccessType_GCS</a> then
        if s1perms.gcs == '0' then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        elsif accdesc.write &amp;&amp; walkparams.hd != '1' &amp;&amp; permissions.ndirty == '1' then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            fault.dirtybit   = TRUE;
            fault.write      = TRUE;
        end;
    elsif accdesc.read &amp;&amp; s1perms.overlay &amp;&amp; s1perms.or == '0' then
        fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        fault.overlay    = TRUE;
        fault.write      = FALSE;
    elsif accdesc.write &amp;&amp; s1perms.overlay &amp;&amp; s1perms.ow == '0' then
        fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        fault.overlay    = TRUE;
        fault.write      = TRUE;
    elsif accdesc.read &amp;&amp; s1perms.r == '0' then
        fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        fault.write      = FALSE;
    elsif accdesc.write &amp;&amp; s1perms.w == '0' then
        fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        fault.write      = TRUE;
    elsif (accdesc.write &amp;&amp; accdesc.tagaccess &amp;&amp;
             walkstate.memattrs.tags == <a link="enum_MemTag_CanonicallyTagged" file="shared_pseudocode.xml">MemTag_CanonicallyTagged</a>) then
        fault.statuscode   = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        fault.write        = TRUE;
        fault.s1tagnotdata = TRUE;
    elsif (accdesc.write &amp;&amp; walkparams.hd != '1' &amp;&amp; walkparams.pie == '1' &amp;&amp;
             permissions.ndirty == '1') then
        fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        fault.dirtybit   = TRUE;
        fault.write      = TRUE;
    end;

    return fault;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_S1ComputePermissions" mylink="aarch64.translation.vmsa_faults.AArch64_S1ComputePermissions" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1ComputePermissions()
// ==============================
// Computes the overall stage 1 permissions

func <anchor link="func_AArch64_S1ComputePermissions_4">AArch64_S1ComputePermissions</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>,
                                  walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>,
                                  accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_S1AccessControls" file="shared_pseudocode.xml">S1AccessControls</a>
begin
    let permissions : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a> = walkstate.permissions;
    var s1perms : <a link="type_S1AccessControls" file="shared_pseudocode.xml">S1AccessControls</a>;

    if walkparams.pie == '1' then
        s1perms = <a link="func_AArch64_S1IndirectBasePermissions_4" file="shared_pseudocode.xml">AArch64_S1IndirectBasePermissions</a>(regime, walkstate, walkparams, accdesc);
    else
        s1perms = <a link="func_AArch64_S1DirectBasePermissions_4" file="shared_pseudocode.xml">AArch64_S1DirectBasePermissions</a>(regime, walkstate, walkparams, accdesc);
    end;

    if accdesc.el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_AArch64_S1E0POEnabled_2" file="shared_pseudocode.xml">AArch64_S1E0POEnabled</a>(regime, walkparams.nv1) then
        s1perms.overlay = FALSE;
    elsif accdesc.el != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_AArch64_S1POEnabled_1" file="shared_pseudocode.xml">AArch64_S1POEnabled</a>(regime) then
        s1perms.overlay = FALSE;
    end;

    if s1perms.overlay then
        let s1overlay_perms : <a link="type_S1AccessControls" file="shared_pseudocode.xml">S1AccessControls</a> = <a link="func_AArch64_S1OverlayPermissions_3" file="shared_pseudocode.xml">AArch64_S1OverlayPermissions</a>(regime,
                                                                              walkstate,
                                                                              accdesc);
        s1perms.or = s1overlay_perms.or;
        s1perms.ow = s1overlay_perms.ow;
        s1perms.ox = s1overlay_perms.ox;
    end;

    if s1perms.overlay then
        // If WXN and the overlay X permission is present, the overlay W permission is removed.
        s1perms.ow = s1perms.ow AND NOT(s1perms.wxn AND s1perms.ox);
    else
        // If WXN and the W and X permissions are present, the X permission is removed.
        // The W and X permissions are factored into the WXN computation.
        s1perms.x  = s1perms.x AND NOT(s1perms.wxn);
    end;

    return s1perms;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_S1DirectBasePermissions" mylink="aarch64.translation.vmsa_faults.AArch64_S1DirectBasePermissions" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1DirectBasePermissions()
// =================================
// Computes the stage 1 direct base permissions

func <anchor link="func_AArch64_S1DirectBasePermissions_4">AArch64_S1DirectBasePermissions</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>,
                                     walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>,
                                     accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_S1AccessControls" file="shared_pseudocode.xml">S1AccessControls</a>
begin
    var r,  w,  x,  wxn  : bit;
    var pr, pw, px, pwxn : bit;
    var ur, uw, ux, uwxn : bit;
    var permissions : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a> = walkstate.permissions;
    var s1perms : <a link="type_S1AccessControls" file="shared_pseudocode.xml">S1AccessControls</a>;
    // Descriptors marked with DBM set have the effective value of AP[2] cleared.
    // This implies no Permission faults caused by lack of write permissions are
    // reported, and the Dirty bit can be set.
    if permissions.dbm == '1' &amp;&amp; walkparams.hd == '1' then
        permissions.ap[2] = '0';
    end;

    if <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) then
        // Apply leaf permissions
        case permissions.ap[2:1] of
            when '00' =&gt; (pr,pw,ur,uw) = ('1','1','0','0'); // Privileged access
            when '01' =&gt; (pr,pw,ur,uw) = ('1','1','1','1'); // No effect
            when '10' =&gt; (pr,pw,ur,uw) = ('1','0','0','0'); // Read-only, privileged access
            when '11' =&gt; (pr,pw,ur,uw) = ('1','0','1','0'); // Read-only
        end;

        // Apply hierarchical permissions
        case permissions.ap_table of
            when '00' =&gt; (pr,pw,ur,uw) = (pr, pw, ur, uw);  // No effect
            when '01' =&gt; (pr,pw,ur,uw) = (pr, pw,'0','0');  // Privileged access
            when '10' =&gt; (pr,pw,ur,uw) = (pr,'0', ur,'0');  // Read-only
            when '11' =&gt; (pr,pw,ur,uw) = (pr,'0','0','0');  // Read-only, privileged access
        end;

        // Locations writable by unprivileged cannot be executed by privileged
        px = NOT(permissions.pxn OR permissions.pxn_table OR uw);
        ux = NOT(permissions.uxn OR permissions.uxn_table);
        pwxn = walkparams.wxn AND pw AND px;
        uwxn = walkparams.wxn AND uw AND ux;

        if (IsFeatureImplemented(FEAT_PAN) &amp;&amp; accdesc.pan &amp;&amp; !(regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp;
              walkparams.nv1 == '1')) then
            if (ImpDefBool(&quot;SCR_EL3.SIF affects EPAN&quot;) &amp;&amp; accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> &amp;&amp;
                  walkstate.baseaddress.paspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> &amp;&amp; walkparams.sif == '1') then
                ux = '0';
            end;

            if (ImpDefBool(&quot;Realm EL2&amp;0 regime affects EPAN&quot;) &amp;&amp; accdesc.ss == <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> &amp;&amp;
                  regime == <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> &amp;&amp; walkstate.baseaddress.paspace != <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>) then
                ux = '0';
            end;

            let pan : bit = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN AND (ur OR uw OR (walkparams.epan AND ux));
            pr = pr AND NOT(pan);
            pw = pw AND NOT(pan);
        end;

    else
        // Apply leaf permissions
        case permissions.ap[2] of
            when '0' =&gt; (pr,pw) = ('1','1'); // No effect
            when '1' =&gt; (pr,pw) = ('1','0'); // Read-only
        end;

        // Apply hierarchical permissions
        case permissions.ap_table[1] of
            when '0' =&gt; (pr,pw) = (pr, pw);  // No effect
            when '1' =&gt; (pr,pw) = (pr,'0');  // Read-only
        end;

        px   = NOT(permissions.xn OR permissions.xn_table);
        pwxn = walkparams.wxn AND pw AND px;
    end;

    (r,w,x,wxn) = if accdesc.el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then (ur,uw,ux,uwxn) else (pr,pw,px,pwxn);

    // Prevent execution from Non-secure space by PE in secure state if SIF is set
    if accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> &amp;&amp; walkstate.baseaddress.paspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> then
        x = x AND NOT(walkparams.sif);
    end;
    // Prevent execution from non-Root space by Root
    if accdesc.ss == <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a> &amp;&amp; walkstate.baseaddress.paspace != <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a> then
        x = '0';
    end;
    // Prevent execution from non-Realm space by Realm EL2 and Realm EL2&amp;0
    if (accdesc.ss == <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> &amp;&amp; regime IN {<a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a>, <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>} &amp;&amp;
            walkstate.baseaddress.paspace != <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>) then
        x = '0';
    end;


    s1perms.r   = r;
    s1perms.w   = w;
    s1perms.x   = x;
    s1perms.gcs = '0';
    s1perms.wxn = wxn;
    s1perms.overlay = TRUE;

    return s1perms;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_S1HasAlignmentFaultDueToMemType" mylink="aarch64.translation.vmsa_faults.AArch64_S1HasAlignmentFaultDueToMemType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1HasAlignmentFaultDueToMemType()
// =========================================
// Returns whether stage 1 output fails alignment requirement on data accesses due to memory type

func <anchor link="func_AArch64_S1HasAlignmentFaultDueToMemType_5">AArch64_S1HasAlignmentFaultDueToMemType</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                                             aligned : boolean, ntlsmd : bit,
                                             memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>) =&gt; boolean
begin
    if accdesc.exclusive || accdesc.atomicop || accdesc.acqsc || accdesc.acqpc || accdesc.relsc then
        if (!aligned &amp;&amp; !(<a link="func_IsWBShareable_1" file="shared_pseudocode.xml">IsWBShareable</a>(memattrs) &amp;&amp; <a link="func_AArch64_S1DCacheEnabled_1" file="shared_pseudocode.xml">AArch64_S1DCacheEnabled</a>(regime)) &amp;&amp;
              <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_LSE2_ALIGNMENT_FAULT" file="shared_pseudocode.xml">Unpredictable_LSE2_ALIGNMENT_FAULT</a>)) then
            return TRUE;
        end;
    end;

    if memattrs.memtype != <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> then
        return FALSE;
    elsif ((accdesc.acctype == <a link="enum_AccessType_DCZero" file="shared_pseudocode.xml">AccessType_DCZero</a> &amp;&amp; accdesc.cachetype == <a link="enum_CacheType_Tag" file="shared_pseudocode.xml">CacheType_Tag</a>) ||
             accdesc.stzgm) then
        return ConstrainUnpredictable(<a link="enum_Unpredictable_DEVICETAGSTORE" file="shared_pseudocode.xml">Unpredictable_DEVICETAGSTORE</a>) == <a link="enum_Constraint_FAULT" file="shared_pseudocode.xml">Constraint_FAULT</a>;
    elsif accdesc.a32lsmd &amp;&amp; ntlsmd == '0' then
        return memattrs.device != <a link="enum_DeviceType_GRE" file="shared_pseudocode.xml">DeviceType_GRE</a>;
    elsif accdesc.acctype == <a link="enum_AccessType_DCZero" file="shared_pseudocode.xml">AccessType_DCZero</a> then
        return TRUE;
    elsif !aligned then
        return !(ImpDefBool(&quot;Device location supports unaligned access&quot;));
    else
        return FALSE;
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_S1IndirectBasePermissions" mylink="aarch64.translation.vmsa_faults.AArch64_S1IndirectBasePermissions" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1IndirectBasePermissions()
// ===================================
// Computes the stage 1 indirect base permissions

func <anchor link="func_AArch64_S1IndirectBasePermissions_4">AArch64_S1IndirectBasePermissions</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>,
                                       walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>,
                                       accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_S1AccessControls" file="shared_pseudocode.xml">S1AccessControls</a>
begin

    var r,  w,  x,  gcs,  wxn,   overlay : bit;
    var pr, pw, px, pgcs, pwxn, p_overlay : bit;
    var ur, uw, ux, ugcs, uwxn, u_overlay : bit;
    let permissions : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a> = walkstate.permissions;
    var s1perms : <a link="type_S1AccessControls" file="shared_pseudocode.xml">S1AccessControls</a>;

    // Apply privileged indirect permissions
    case permissions.ppi of
        when '0000' =&gt; (pr,pw,px,pgcs) = ('0','0','0','0'); // No access
        when '0001' =&gt; (pr,pw,px,pgcs) = ('1','0','0','0'); // Privileged read
        when '0010' =&gt; (pr,pw,px,pgcs) = ('0','0','1','0'); // Privileged execute
        when '0011' =&gt; (pr,pw,px,pgcs) = ('1','0','1','0'); // Privileged read and execute
        when '0100' =&gt; (pr,pw,px,pgcs) = ('0','0','0','0'); // Reserved
        when '0101' =&gt; (pr,pw,px,pgcs) = ('1','1','0','0'); // Privileged read and write
        when '0110' =&gt; (pr,pw,px,pgcs) = ('1','1','1','0'); // Privileged read, write and execute
        when '0111' =&gt; (pr,pw,px,pgcs) = ('1','1','1','0'); // Privileged read, write and execute
        when '1000' =&gt; (pr,pw,px,pgcs) = ('1','0','0','0'); // Privileged read
        when '1001' =&gt; (pr,pw,px,pgcs) = ('1','0','0','1'); // Privileged read and gcs
        when '1010' =&gt; (pr,pw,px,pgcs) = ('1','0','1','0'); // Privileged read and execute
        when '1011' =&gt; (pr,pw,px,pgcs) = ('0','0','0','0'); // Reserved
        when '1100' =&gt; (pr,pw,px,pgcs) = ('1','1','0','0'); // Privileged read and write
        when '1101' =&gt; (pr,pw,px,pgcs) = ('0','0','0','0'); // Reserved
        when '1110' =&gt; (pr,pw,px,pgcs) = ('1','1','1','0'); // Privileged read, write and execute
        when '1111' =&gt; (pr,pw,px,pgcs) = ('0','0','0','0'); // Reserved
    end;

    p_overlay = NOT(permissions.ppi[3]);
    pwxn = if permissions.ppi == '0110' then '1' else '0';
    var reserved_upi : boolean = FALSE;

    if <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) then
        // Apply unprivileged indirect permissions
        case permissions.upi of
            when '0000' =&gt; (ur,uw,ux,ugcs) = ('0','0','0','0'); // No access
            when '0001' =&gt; (ur,uw,ux,ugcs) = ('1','0','0','0'); // Unprivileged read
            when '0010' =&gt; (ur,uw,ux,ugcs) = ('0','0','1','0'); // Unprivileged execute
            when '0011' =&gt; (ur,uw,ux,ugcs) = ('1','0','1','0'); // Unprivileged read and execute
            when '0100' =&gt;
                (ur,uw,ux,ugcs) = ('0','0','0','0');         // Reserved
                reserved_upi    = TRUE;
            when '0101' =&gt; (ur,uw,ux,ugcs)=('1','1','0','0');// Unprivileged read and write
            when '0110' =&gt; (ur,uw,ux,ugcs)=('1','1','1','0');// Unprivileged read, write and execute
            when '0111' =&gt; (ur,uw,ux,ugcs)=('1','1','1','0');// Unprivileged read, write and execute
            when '1000' =&gt; (ur,uw,ux,ugcs)=('1','0','0','0');// Unprivileged read
            when '1001' =&gt; (ur,uw,ux,ugcs)=('1','0','0','1');// Unprivileged read and gcs
            when '1010' =&gt; (ur,uw,ux,ugcs)=('1','0','1','0');// Unprivileged read and execute
            when '1011' =&gt;
                (ur,uw,ux,ugcs) = ('0','0','0','0');          // Reserved
                reserved_upi    = TRUE;
            when '1100' =&gt; (ur,uw,ux,ugcs) =('1','1','0','0');// Unprivileged read and write
            when '1101' =&gt;
                (ur,uw,ux,ugcs) =('0','0','0','0');           // Reserved
                reserved_upi    = TRUE;
            when '1110' =&gt; (ur,uw,ux,ugcs) =('1','1','1','0');// Unprivileged read, write
                                                              // and execute
            when '1111' =&gt;
                (ur,uw,ux,ugcs) = ('0','0','0','0');          // Reserved
                reserved_upi    = TRUE;

        end;

        u_overlay = NOT(permissions.upi[3]);
        uwxn = if permissions.upi == '0110' then '1' else '0';

        // If the decoded permissions has either px or pgcs along with either uw or ugcs,
        // then all effective Stage 1 Base Permissions are set to 0
        if ((px == '1' || pgcs == '1') &amp;&amp; (uw == '1' || ugcs == '1')) then
            (pr,pw,px,pgcs) = ('0','0','0','0');
            (ur,uw,ux,ugcs) = ('0','0','0','0');
        end;
    end;

    // Prevent execution from Non-secure space by PE in secure state
    if accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> &amp;&amp; walkstate.baseaddress.paspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> then
        pgcs = '0';
        if <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) then ugcs = '0'; end;

        if walkparams.sif == '1' then
            px = '0';
            if <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) then ux = '0'; end;
        end;
    end;

    // Prevent execution from non-Root space by Root
    if accdesc.ss == <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a> &amp;&amp; walkstate.baseaddress.paspace != <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a> then
        (px, pgcs)   = ('0','0');
        if <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) then
            (ux, ugcs)   = ('0','0');
        end;
    end;

    // Prevent execution from non-Realm space by Realm EL2 and Realm EL2&amp;0
    if (accdesc.ss == <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> &amp;&amp; regime IN {<a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a>, <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>} &amp;&amp;
          walkstate.baseaddress.paspace != <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>) then
        (px, pgcs)   = ('0','0');
        if <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) then
            (ux, ugcs)   = ('0','0');
        end;
    end;

    if (<a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) &amp;&amp; IsFeatureImplemented(FEAT_PAN) &amp;&amp; accdesc.pan &amp;&amp;
          !(regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; walkparams.nv1 == '1') &amp;&amp;
          <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN == '1' &amp;&amp; !IsZero(permissions.upi)) then
        if reserved_upi then
            if ImpDefBool(&quot;PAN applies when S1UnprivBasePerm is reserved&quot;) then
                (pr,pw) = ('0','0');
            end;
        elsif (!IsZero(ur::uw::ux::ugcs) ||
                 ImpDefBool(&quot;PAN applies when S1UnprivBasePerms are removed&quot;)) then
            (pr,pw) = ('0','0');
        end;
    end;

    if accdesc.el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        (r,w,x,gcs,wxn,overlay) = (ur,uw,ux,ugcs,uwxn,u_overlay);
    else
        (r,w,x,gcs,wxn,overlay) = (pr,pw,px,pgcs,pwxn,p_overlay);
    end;

    s1perms.r       = r;
    s1perms.w       = w;
    s1perms.x       = x;
    s1perms.gcs     = gcs;
    s1perms.wxn     = wxn;
    s1perms.overlay = overlay == '1';

    return s1perms;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_S1OAOutOfRange" mylink="aarch64.translation.vmsa_faults.AArch64_S1OAOutOfRange" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1OAOutOfRange()
// ========================
// Returns whether stage 1 output address is expressed in the configured size number of bits

func <anchor link="func_AArch64_S1OAOutOfRange_2">AArch64_S1OAOutOfRange</anchor>(address : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>), walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>) =&gt; boolean
begin
    return <a link="func_AArch64_OAOutOfRange_5" file="shared_pseudocode.xml">AArch64_OAOutOfRange</a>(address, walkparams.d128, walkparams.ds, walkparams.ps,
                                walkparams.tgx);
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_S1OverlayPermissions" mylink="aarch64.translation.vmsa_faults.AArch64_S1OverlayPermissions" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1OverlayPermissions()
// ==============================
// Computes the stage 1 overlay permissions

func <anchor link="func_AArch64_S1OverlayPermissions_3">AArch64_S1OverlayPermissions</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>,
                                  accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_S1AccessControls" file="shared_pseudocode.xml">S1AccessControls</a>
begin

    var r,  w,  x : bit;
    var pr, pw, px : bit;
    var ur, uw, ux : bit;
    let permissions : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a> = walkstate.permissions;
    var s1overlay_perms : <a link="type_S1AccessControls" file="shared_pseudocode.xml">S1AccessControls</a>;

    let por : S1PORType = <a link="func_AArch64_S1POR_1" file="shared_pseudocode.xml">AArch64_S1POR</a>(regime);
    let bit_index : integer{} = 4 * UInt(permissions.po_index);

    let ppo : bits(4) = por[bit_index+3:bit_index];

    // Apply privileged overlay permissions
    case ppo of
        when '0000' =&gt; (pr,pw,px) = ('0','0','0'); // No access
        when '0001' =&gt; (pr,pw,px) = ('1','0','0'); // Privileged read
        when '0010' =&gt; (pr,pw,px) = ('0','0','1'); // Privileged execute
        when '0011' =&gt; (pr,pw,px) = ('1','0','1'); // Privileged read and execute
        when '0100' =&gt; (pr,pw,px) = ('0','1','0'); // Privileged write
        when '0101' =&gt; (pr,pw,px) = ('1','1','0'); // Privileged read and write
        when '0110' =&gt; (pr,pw,px) = ('0','1','1'); // Privileged write and execute
        when '0111' =&gt; (pr,pw,px) = ('1','1','1'); // Privileged read, write and execute
        when '1xxx' =&gt; (pr,pw,px) = ('0','0','0'); // Reserved
    end;

    if <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) then
        var upo : bits(4) = '0000';
        if !(<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().PIEn == '0' &amp;&amp;
               ImpDefBool(&quot;SCR_EL3.PIEn forces PIR_ELx or POR_ELx to zero&quot;)) then
            upo = POR_EL0()[bit_index+3:bit_index];
        end;

        // Apply unprivileged overlay permissions
        case upo of
            when '0000' =&gt; (ur,uw,ux) = ('0','0','0'); // No access
            when '0001' =&gt; (ur,uw,ux) = ('1','0','0'); // Unprivileged read
            when '0010' =&gt; (ur,uw,ux) = ('0','0','1'); // Unprivileged execute
            when '0011' =&gt; (ur,uw,ux) = ('1','0','1'); // Unprivileged read and execute
            when '0100' =&gt; (ur,uw,ux) = ('0','1','0'); // Unprivileged write
            when '0101' =&gt; (ur,uw,ux) = ('1','1','0'); // Unprivileged read and write
            when '0110' =&gt; (ur,uw,ux) = ('0','1','1'); // Unprivileged write and execute
            when '0111' =&gt; (ur,uw,ux) = ('1','1','1'); // Unprivileged read, write and execute
            when '1xxx' =&gt; (ur,uw,ux) = ('0','0','0'); // Reserved
        end;
    end;

    (r,w,x) = if accdesc.el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then (ur,uw,ux) else (pr,pw,px);

    s1overlay_perms.or = r;
    s1overlay_perms.ow = w;
    s1overlay_perms.ox = x;

    return s1overlay_perms;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_S1TxSZFaults" mylink="aarch64.translation.vmsa_faults.AArch64_S1TxSZFaults" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1TxSZFaults()
// ======================
// Detect whether configuration of stage 1 TxSZ field generates a fault

func <anchor link="func_AArch64_S1TxSZFaults_2">AArch64_S1TxSZFaults</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>) =&gt; boolean
begin
    let mintxsz : integer = <a link="func_AArch64_S1MinTxSZ_2" file="shared_pseudocode.xml">AArch64_S1MinTxSZ</a>(regime, walkparams);
    let maxtxsz : integer = <a link="func_AArch64_MaxTxSZ_1" file="shared_pseudocode.xml">AArch64_MaxTxSZ</a>(walkparams.tgx);

    if UInt(walkparams.txsz) &lt; mintxsz then
        return (IsFeatureImplemented(FEAT_LVA) ||
                ImpDefBool(&quot;Fault on TxSZ value below minimum&quot;));
    end;
    if UInt(walkparams.txsz) &gt; maxtxsz then
        return ImpDefBool(&quot;Fault on TxSZ value above maximum&quot;);
    end;

    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_S2CheckPermissions" mylink="aarch64.translation.vmsa_faults.AArch64_S2CheckPermissions" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2CheckPermissions()
// ============================
// Verifies memory access with available permissions.

func <anchor link="func_AArch64_S2CheckPermissions_5">AArch64_S2CheckPermissions</anchor>(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>,
                                walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>, ipa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                                accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; (<a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, boolean)
begin
    let memtype : <a link="type_MemType" file="shared_pseudocode.xml">MemType</a> = walkstate.memattrs.memtype;
    let permissions : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a> = walkstate.permissions;
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;
    let s2perms : <a link="type_S2AccessControls" file="shared_pseudocode.xml">S2AccessControls</a> = <a link="func_AArch64_S2ComputePermissions_3" file="shared_pseudocode.xml">AArch64_S2ComputePermissions</a>(permissions, walkparams,
                                                                   accdesc);

    var r,  w : bit;
    var or, ow : bit;

    if accdesc.acctype == <a link="enum_AccessType_TTW" file="shared_pseudocode.xml">AccessType_TTW</a> then
        r = s2perms.r_mmu;
        w = s2perms.w_mmu;
        or = s2perms.or_mmu;
        ow = s2perms.ow_mmu;
    elsif accdesc.rcw then
        r = s2perms.r_rcw;
        w = s2perms.w_rcw;
        or = s2perms.or_rcw;
        ow = s2perms.ow_rcw;
    else
        r = s2perms.r;
        w = s2perms.w;
        or = s2perms.or;
        ow = s2perms.ow;
    end;

    if accdesc.acctype == <a link="enum_AccessType_TTW" file="shared_pseudocode.xml">AccessType_TTW</a> then
        if (accdesc.toplevel &amp;&amp; accdesc.varange == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> &amp;&amp;
              ((walkparams.tl0 == '1' &amp;&amp; s2perms.toplevel0 == '0') ||
              (walkparams.tl1 == '1' &amp;&amp; s2perms.[toplevel1,toplevel0] == '10'))) then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            fault.toplevel   = TRUE;
        elsif (accdesc.toplevel &amp;&amp; accdesc.varange == <a link="enum_VARange_UPPER" file="shared_pseudocode.xml">VARange_UPPER</a> &amp;&amp;
                ((walkparams.tl1 == '1' &amp;&amp; s2perms.toplevel1 == '0') ||
                (walkparams.tl0 == '1' &amp;&amp; s2perms.[toplevel1,toplevel0] == '01'))) then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            fault.toplevel   = TRUE;
        // Stage 2 Permission fault due to AssuredOnly check
        elsif (walkstate.s2assuredonly == '1' &amp;&amp; !ipa.s1assured) then
                fault.statuscode  = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
                fault.assuredonly = TRUE;

        elsif s2perms.overlay &amp;&amp; or == '0' then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            fault.overlay    = TRUE;
        elsif accdesc.write &amp;&amp; s2perms.overlay &amp;&amp; ow == '0' then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            fault.overlay    = TRUE;

        elsif walkparams.ptw == '1' &amp;&amp; memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        // Prevent translation table walks in Non-secure space by Realm state
        elsif accdesc.ss == <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> &amp;&amp; walkstate.baseaddress.paspace != <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a> then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        elsif r == '0' then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        elsif accdesc.write &amp;&amp; w == '0' then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            fault.hdbssf = walkparams.hdbss == '1' &amp;&amp; !<a link="func_CanAppendToHDBSS_0" file="shared_pseudocode.xml">CanAppendToHDBSS</a>() &amp;&amp; permissions.dbm == '1';
        elsif (accdesc.write &amp;&amp; walkparams.s2pie == '1' &amp;&amp; permissions.s2dirty == '0' &amp;&amp;
                 (walkparams.hd != '1' ||
                 (accdesc.acctype != <a link="enum_AccessType_AT" file="shared_pseudocode.xml">AccessType_AT</a> &amp;&amp;
                  walkparams.hdbss == '1' &amp;&amp; !<a link="func_CanAppendToHDBSS_0" file="shared_pseudocode.xml">CanAppendToHDBSS</a>()))) then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            fault.dirtybit   = TRUE;
            fault.hdbssf = walkparams.hdbss == '1' &amp;&amp; !<a link="func_CanAppendToHDBSS_0" file="shared_pseudocode.xml">CanAppendToHDBSS</a>();

        end;

    // Stage 2 Permission fault due to AssuredOnly check
    elsif ((walkstate.s2assuredonly == '1' &amp;&amp; !ipa.s1assured) ||
            (walkstate.s2assuredonly != '1' &amp;&amp; IsFeatureImplemented(FEAT_GCS) &amp;&amp;
             VTCR_EL2().GCSH == '1' &amp;&amp; accdesc.acctype == <a link="enum_AccessType_GCS" file="shared_pseudocode.xml">AccessType_GCS</a> &amp;&amp; accdesc.el != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>)) then
        fault.statuscode  = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        fault.assuredonly = TRUE;

    elsif accdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> then
        if s2perms.overlay &amp;&amp; s2perms.ox == '0' then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            fault.overlay    = TRUE;
        elsif (memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> &amp;&amp;
              ConstrainUnpredictable(<a link="enum_Unpredictable_INSTRDEVICE" file="shared_pseudocode.xml">Unpredictable_INSTRDEVICE</a>) == <a link="enum_Constraint_FAULT" file="shared_pseudocode.xml">Constraint_FAULT</a>) then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;

        // Prevent execution from Non-secure space by Realm state
        elsif accdesc.ss == <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> &amp;&amp; walkstate.baseaddress.paspace != <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a> then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        elsif s2perms.x == '0' then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        end;

    elsif accdesc.acctype == <a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a> then
        if accdesc.cacheop == <a link="enum_CacheOp_Invalidate" file="shared_pseudocode.xml">CacheOp_Invalidate</a> then
            if !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) &amp;&amp; s2perms.overlay &amp;&amp; ow == '0' then
                fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
                fault.overlay    = TRUE;
            elsif !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) &amp;&amp; w == '0' then
                fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            elsif (walkparams.hd != '1' &amp;&amp; walkparams.s2pie == '1' &amp;&amp;
                     permissions.s2dirty == '0') then
                fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
                fault.dirtybit   = TRUE;
            end;
        elsif !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) &amp;&amp; accdesc.el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; s2perms.overlay &amp;&amp; or == '0' then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            fault.overlay    = TRUE;
        elsif (walkparams.cmow == '1' &amp;&amp; accdesc.cacheop == <a link="enum_CacheOp_CleanInvalidate" file="shared_pseudocode.xml">CacheOp_CleanInvalidate</a> &amp;&amp;
                s2perms.overlay &amp;&amp; ow == '0') then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            fault.overlay    = TRUE;
        elsif !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) &amp;&amp; accdesc.el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; r == '0' then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        elsif (walkparams.cmow == '1' &amp;&amp; accdesc.cacheop == <a link="enum_CacheOp_CleanInvalidate" file="shared_pseudocode.xml">CacheOp_CleanInvalidate</a> &amp;&amp;
                w == '0') then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        elsif (walkparams.cmow == '1' &amp;&amp; accdesc.cacheop == <a link="enum_CacheOp_CleanInvalidate" file="shared_pseudocode.xml">CacheOp_CleanInvalidate</a> &amp;&amp;
                 walkparams.hd != '1' &amp;&amp; walkparams.s2pie == '1' &amp;&amp; permissions.s2dirty == '0') then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            fault.dirtybit   = TRUE;
        end;

    elsif accdesc.acctype == <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a> then
        if (!<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) &amp;&amp; accdesc.el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; s2perms.overlay &amp;&amp; or == '0' &amp;&amp;
                ImpDefBool(&quot;Permission fault on EL0 IC_IVAU execution&quot;)) then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            fault.overlay    = TRUE;
        elsif walkparams.cmow == '1' &amp;&amp; s2perms.overlay &amp;&amp; ow == '0' then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            fault.overlay    = TRUE;
        elsif (!<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) &amp;&amp; accdesc.el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp;  r == '0' &amp;&amp;
              ImpDefBool(&quot;Permission fault on EL0 IC_IVAU execution&quot;)) then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        elsif walkparams.cmow == '1' &amp;&amp; w == '0' then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        elsif (walkparams.cmow == '1' &amp;&amp; walkparams.hd != '1' &amp;&amp; walkparams.s2pie == '1' &amp;&amp;
                 permissions.s2dirty == '0') then
            fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
            fault.dirtybit   = TRUE;
        end;

    elsif accdesc.read &amp;&amp; s2perms.overlay &amp;&amp; or == '0' then
        fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        fault.overlay    = TRUE;
        fault.write      = FALSE;
    elsif accdesc.write &amp;&amp; s2perms.overlay &amp;&amp; ow == '0' then
        fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        fault.overlay    = TRUE;
        fault.write      = TRUE;
    elsif accdesc.read &amp;&amp; r == '0' then
        fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        fault.write      = FALSE;
    elsif accdesc.write &amp;&amp; w == '0' then
        fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        fault.write      = TRUE;
        fault.hdbssf = walkparams.hdbss == '1' &amp;&amp; !<a link="func_CanAppendToHDBSS_0" file="shared_pseudocode.xml">CanAppendToHDBSS</a>() &amp;&amp; permissions.dbm == '1';
    elsif (IsFeatureImplemented(FEAT_MTE_PERM) &amp;&amp;
             ((accdesc.tagchecked &amp;&amp;
               <a link="func_AArch64_EffectiveTCF_2" file="shared_pseudocode.xml">AArch64_EffectiveTCF</a>(accdesc.el, accdesc.read) != <a link="enum_TCFType_Ignore" file="shared_pseudocode.xml">TCFType_Ignore</a>) ||
              accdesc.tagaccess) &amp;&amp;
             ipa.memattrs.tags == <a link="enum_MemTag_AllocationTagged" file="shared_pseudocode.xml">MemTag_AllocationTagged</a> &amp;&amp;
             permissions.s2tag_na == '1' &amp;&amp; <a link="func_S2DCacheEnabled_0" file="shared_pseudocode.xml">S2DCacheEnabled</a>()) then
        fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        fault.tagaccess  = TRUE;
        fault.write      = accdesc.tagaccess &amp;&amp; accdesc.write;
    elsif (accdesc.write &amp;&amp;
             (walkparams.hd != '1' || (walkparams.hdbss == '1' &amp;&amp; !<a link="func_CanAppendToHDBSS_0" file="shared_pseudocode.xml">CanAppendToHDBSS</a>())) &amp;&amp;
              walkparams.s2pie == '1' &amp;&amp; permissions.s2dirty == '0') then
        fault.statuscode = <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>;
        fault.dirtybit   = TRUE;
        fault.write      = TRUE;
        fault.hdbssf     = walkparams.hdbss == '1' &amp;&amp; !<a link="func_CanAppendToHDBSS_0" file="shared_pseudocode.xml">CanAppendToHDBSS</a>();
    end;
    // MRO* allows only RCW and MMU writes
    var mro : boolean;
    if s2perms.overlay then
        mro = (s2perms.[w,w_rcw,w_mmu] AND s2perms.[ow,ow_rcw,ow_mmu]) == '011';
    else
        mro = s2perms.[w,w_rcw,w_mmu] == '011';
    end;

    return (fault, mro);
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_S2ComputePermissions" mylink="aarch64.translation.vmsa_faults.AArch64_S2ComputePermissions" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2ComputePermissions()
// ==============================
// Compute the overall stage 2 permissions.

func <anchor link="func_AArch64_S2ComputePermissions_3">AArch64_S2ComputePermissions</anchor>(permissions : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a>, walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>,
                                  accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_S2AccessControls" file="shared_pseudocode.xml">S2AccessControls</a>
begin

    var s2perms : <a link="type_S2AccessControls" file="shared_pseudocode.xml">S2AccessControls</a>;

    if walkparams.s2pie == '1' then
        s2perms = <a link="func_AArch64_S2IndirectBasePermissions_2" file="shared_pseudocode.xml">AArch64_S2IndirectBasePermissions</a>(permissions, accdesc);
        s2perms.overlay = IsFeatureImplemented(FEAT_S2POE) &amp;&amp; VTCR_EL2().S2POE == '1';
        if s2perms.overlay then
            let s2overlay_perms : <a link="type_S2AccessControls" file="shared_pseudocode.xml">S2AccessControls</a> = <a link="func_AArch64_S2OverlayPermissions_2" file="shared_pseudocode.xml">AArch64_S2OverlayPermissions</a>(permissions,
                                                                                  accdesc);
            s2perms.or          = s2overlay_perms.or;
            s2perms.ow          = s2overlay_perms.ow;
            s2perms.ox          = s2overlay_perms.ox;
            s2perms.or_rcw      = s2overlay_perms.or_rcw;
            s2perms.ow_rcw      = s2overlay_perms.ow_rcw;
            s2perms.or_mmu      = s2overlay_perms.or_mmu;
            s2perms.ow_mmu      = s2overlay_perms.ow_mmu;

            // Toplevel is applicable only when the effective S2 permissions is MRO
            if ((s2perms.[w,w_rcw,w_mmu] AND s2perms.[ow,ow_rcw,ow_mmu]) == '011') then
                s2perms.toplevel0 = s2perms.toplevel0 OR s2overlay_perms.toplevel0;
                s2perms.toplevel1 = s2perms.toplevel1 OR s2overlay_perms.toplevel1;

            else
                s2perms.toplevel0 = '0';
                s2perms.toplevel1 = '0';
            end;
        end;
    else
        s2perms = <a link="func_AArch64_S2DirectBasePermissions_3" file="shared_pseudocode.xml">AArch64_S2DirectBasePermissions</a>(permissions, accdesc, walkparams);
    end;

    return s2perms;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_S2DirectBasePermissions" mylink="aarch64.translation.vmsa_faults.AArch64_S2DirectBasePermissions" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2DirectBasePermissions()
// =================================
// Computes the stage 2 direct base permissions.

func <anchor link="func_AArch64_S2DirectBasePermissions_3">AArch64_S2DirectBasePermissions</anchor>(permissions : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a>,
                                     accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                                     walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>) =&gt; <a link="type_S2AccessControls" file="shared_pseudocode.xml">S2AccessControls</a>
begin
    var s2perms : <a link="type_S2AccessControls" file="shared_pseudocode.xml">S2AccessControls</a>;
    var w : bit;
    let r : bit = permissions.s2ap[0];
    if permissions.s2ap[1] == '1' then
        w = '1';
    // Descriptors marked with DBM set have the effective value of S2AP[1] set.
    // This implies no Permission faults caused by lack of write permissions are
    // reported, and the Dirty bit can be set.
    elsif permissions.dbm == '1' &amp;&amp; walkparams.hd == '1' then
        // An update occurs here, conditional to being able to append to HDBSS
        if walkparams.hdbss == '1' then
            w = if <a link="func_CanAppendToHDBSS_0" file="shared_pseudocode.xml">CanAppendToHDBSS</a>() then '1' else '0';
        else
            w = '1';
        end;
    else
        w = '0';
    end;

    var px, ux : bit;
    case (permissions.s2xn::permissions.s2xnx) of
        when '00' =&gt; (px,ux) = ('1','1');
        when '01' =&gt; (px,ux) = ('0','1');
        when '10' =&gt; (px,ux) = ('0','0');
        when '11' =&gt; (px,ux) = ('1','0');
    end;

    let x : bit = if accdesc.el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then ux else px;
    s2perms.r = r;
    s2perms.w = w;
    s2perms.x = x;
    s2perms.r_rcw = r;
    s2perms.w_rcw = w;
    s2perms.r_mmu = r;
    s2perms.w_mmu = w;
    s2perms.toplevel0 = '0';
    s2perms.toplevel1 = '0';
    s2perms.overlay = FALSE;

    return s2perms;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_S2HasAlignmentFaultDueToMemType" mylink="aarch64.translation.vmsa_faults.AArch64_S2HasAlignmentFaultDueToMemType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2HasAlignmentFaultDueToMemType()
// =========================================
// Returns whether stage 2 output fails alignment requirement on data accesses due to memory type

func <anchor link="func_AArch64_S2HasAlignmentFaultDueToMemType_3">AArch64_S2HasAlignmentFaultDueToMemType</anchor>(accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>, aligned : boolean,
                                             memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>) =&gt; boolean
begin

    if accdesc.exclusive || accdesc.atomicop || accdesc.acqsc || accdesc.acqpc || accdesc.relsc then
        if (!aligned &amp;&amp; !(<a link="func_IsWBShareable_1" file="shared_pseudocode.xml">IsWBShareable</a>(memattrs) &amp;&amp; <a link="func_S2DCacheEnabled_0" file="shared_pseudocode.xml">S2DCacheEnabled</a>()) &amp;&amp;
                <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_LSE2_ALIGNMENT_FAULT" file="shared_pseudocode.xml">Unpredictable_LSE2_ALIGNMENT_FAULT</a>)) then
            return TRUE;
        end;
    end;

    if memattrs.memtype != <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> then
        return FALSE;
    elsif ((accdesc.acctype == <a link="enum_AccessType_DCZero" file="shared_pseudocode.xml">AccessType_DCZero</a> &amp;&amp; accdesc.cachetype == <a link="enum_CacheType_Tag" file="shared_pseudocode.xml">CacheType_Tag</a>) ||
             accdesc.stzgm) then
        return ConstrainUnpredictable(<a link="enum_Unpredictable_DEVICETAGSTORE" file="shared_pseudocode.xml">Unpredictable_DEVICETAGSTORE</a>) == <a link="enum_Constraint_FAULT" file="shared_pseudocode.xml">Constraint_FAULT</a>;
    elsif accdesc.acctype == <a link="enum_AccessType_DCZero" file="shared_pseudocode.xml">AccessType_DCZero</a> then
        return TRUE;
    elsif !aligned then
        return !(ImpDefBool(&quot;Device location supports unaligned access&quot;));
    else
        return FALSE;
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_S2InconsistentSL" mylink="aarch64.translation.vmsa_faults.AArch64_S2InconsistentSL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2InconsistentSL()
// ==========================
// Detect inconsistent configuration of stage 2 TxSZ and SL fields

func <anchor link="func_AArch64_S2InconsistentSL_1">AArch64_S2InconsistentSL</anchor>(walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>) =&gt; boolean
begin
    let startlevel : integer      = <a link="func_AArch64_S2StartLevel_1" file="shared_pseudocode.xml">AArch64_S2StartLevel</a>(walkparams);
    let levels : integer          = <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - startlevel;
    let granulebits : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_TGxGranuleBits_1" file="shared_pseudocode.xml">TGxGranuleBits</a>(walkparams.tgx);
    let descsizelog2 : integer{}  = 3;
    let stride : integer{}        = granulebits - descsizelog2;

    // Input address size must at least be large enough to be resolved from the start level
    let sl_min_iasize : integer = (
        levels * stride // Bits resolved by table walk, except initial level
        + granulebits   // Bits directly mapped to output address
        + 1);           // At least 1 more bit to be decoded by initial level

    // Can accommodate 1 more stride in the level + concatenation of up to 2^4 tables
    let sl_max_iasize : integer = sl_min_iasize + (stride-1) + 4;
    // Configured Input Address size
    let iasize : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>    = <a link="func_AArch64_IASize_1" file="shared_pseudocode.xml">AArch64_IASize</a>(walkparams.txsz);

    return iasize &lt; sl_min_iasize || iasize &gt; sl_max_iasize;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_S2IndirectBasePermissions" mylink="aarch64.translation.vmsa_faults.AArch64_S2IndirectBasePermissions" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2IndirectBasePermissions()
// ===================================
// Computes the stage 2 indirect base permissions.

func <anchor link="func_AArch64_S2IndirectBasePermissions_2">AArch64_S2IndirectBasePermissions</anchor>(permissions : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a>,
                                       accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_S2AccessControls" file="shared_pseudocode.xml">S2AccessControls</a>
begin
    var r, w : bit;
    var r_rcw, w_rcw : bit;
    var r_mmu, w_mmu : bit;
    var px, ux : bit;
    var toplevel0, toplevel1 : bit;
    var s2perms : <a link="type_S2AccessControls" file="shared_pseudocode.xml">S2AccessControls</a>;

    let s2pi : bits(4) = permissions.s2pi;
    case s2pi of
        when '0000' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('0','0','0','0','0','0');  // No Access
        when '0001' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('0','0','0','0','0','0');  // Reserved
        when '0010' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','0','0','0','1','1');  // MRO
        when '0011' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','0','0','0','1','1');  // MRO-TL1
        when '0100' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('0','1','0','0','0','0');  // Write Only
        when '0101' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('0','0','0','0','0','0');  // Reserved
        when '0110' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','0','0','0','1','1');  // MRO-TL0
        when '0111' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','0','0','0','1','1');  // MRO-TL01
        when '1000' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','0','0','0','0','0');  // Read Only
        when '1001' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','0','0','1','0','0');  // Read, Unpriv Execute
        when '1010' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','0','1','0','0','0');  // Read, Priv Execute
        when '1011' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','0','1','1','0','0');  // Read, All Execute
        when '1100' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','1','0','0','1','1');  // RW
        when '1101' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','1','0','1','1','1');  // RW, Unpriv Execute
        when '1110' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','1','1','0','1','1');  // RW, Priv Execute
        when '1111' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','1','1','1','1','1');  // RW, All Execute
    end;

    let x : bit = if accdesc.el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then ux else px;

    // RCW and MMU read permissions.
    (r_rcw, r_mmu) = (r, r);

    // Stage 2 Top Level Permission Attributes.
    case s2pi of
        when '0110' =&gt; (toplevel0,toplevel1) = ('1','0');
        when '0011' =&gt; (toplevel0,toplevel1) = ('0','1');
        when '0111' =&gt; (toplevel0,toplevel1) = ('1','1');
        otherwise =&gt;   (toplevel0,toplevel1) = ('0','0');
    end;

    s2perms.r = r;
    s2perms.w = w;
    s2perms.x = x;
    s2perms.r_rcw = r_rcw;
    s2perms.r_mmu = r_mmu;
    s2perms.w_rcw = w_rcw;
    s2perms.w_mmu = w_mmu;
    s2perms.toplevel0 = toplevel0;
    s2perms.toplevel1 = toplevel1;

    return s2perms;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_S2InvalidSL" mylink="aarch64.translation.vmsa_faults.AArch64_S2InvalidSL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2InvalidSL()
// =====================
// Detect invalid configuration of SL field

func <anchor link="func_AArch64_S2InvalidSL_1">AArch64_S2InvalidSL</anchor>(walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>) =&gt; boolean
begin
    case walkparams.tgx of
        when <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a> =&gt;
            case walkparams.sl2::walkparams.sl0 of
                when '1x1' =&gt; return TRUE;
                when '11x' =&gt; return TRUE;
                when '100' =&gt; return <a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>() &lt; 52;
                when '010' =&gt; return <a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>() &lt; 44;
                when '011' =&gt; return !IsFeatureImplemented(FEAT_TTST);
                otherwise  =&gt;  return FALSE;
            end;
        when <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a> =&gt;
            case walkparams.sl0 of
                when '11' =&gt; return walkparams.ds == '0' || <a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>() &lt; 52;
                when '10' =&gt; return <a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>() &lt; 42;
                otherwise =&gt;  return FALSE;
            end;
        when <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> =&gt;
            case walkparams.sl0 of
                when '11' =&gt;  return TRUE;
                when '10' =&gt;  return <a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>() &lt; 44;
                otherwise =&gt;  return FALSE;
            end;
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_S2OAOutOfRange" mylink="aarch64.translation.vmsa_faults.AArch64_S2OAOutOfRange" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2OAOutOfRange()
// ========================
// Returns whether stage 2 output address is expressed in the configured size number of bits

func <anchor link="func_AArch64_S2OAOutOfRange_2">AArch64_S2OAOutOfRange</anchor>(address : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>), walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>) =&gt; boolean
begin
    return <a link="func_AArch64_OAOutOfRange_5" file="shared_pseudocode.xml">AArch64_OAOutOfRange</a>(address, walkparams.d128, walkparams.ds, walkparams.ps,
                                walkparams.tgx);
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_S2OverlayPermissions" mylink="aarch64.translation.vmsa_faults.AArch64_S2OverlayPermissions" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2OverlayPermissions()
// ==============================
// Computes the stage 2 overlay permissions.

func <anchor link="func_AArch64_S2OverlayPermissions_2">AArch64_S2OverlayPermissions</anchor>(permissions : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a>,
                                  accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_S2AccessControls" file="shared_pseudocode.xml">S2AccessControls</a>
begin
    var r, w : bit;
    var r_rcw, w_rcw : bit;
    var r_mmu, w_mmu : bit;
    var px, ux : bit;
    var toplevel0, toplevel1 : bit;
    var s2overlay_perms : <a link="type_S2AccessControls" file="shared_pseudocode.xml">S2AccessControls</a>;

    let index : integer{} = 4 * UInt(permissions.s2po_index);
    var s2po : bits(4) = '0000';
    if !(<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().PIEn == '0' &amp;&amp;
          ImpDefBool(&quot;SCR_EL3.PIEn forces PIR_ELx or POR_ELx to zero&quot;)) then
        s2po = S2POR_EL1()[index+3:index];
    end;
    case s2po of
        when '0000' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('0','0','0','0','0','0');  // No Access
        when '0001' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('0','0','0','0','0','0');  // Reserved
        when '0010' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','0','0','0','1','1');  // MRO
        when '0011' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','0','0','0','1','1');  // MRO-TL1
        when '0100' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('0','1','0','0','0','0');  // Write Only
        when '0101' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('0','0','0','0','0','0');  // Reserved
        when '0110' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','0','0','0','1','1');  // MRO-TL0
        when '0111' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','0','0','0','1','1');  // MRO-TL01
        when '1000' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','0','0','0','0','0');  // Read Only
        when '1001' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','0','0','1','0','0');  // Read, Unpriv Execute
        when '1010' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','0','1','0','0','0');  // Read, Priv Execute
        when '1011' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','0','1','1','0','0');  // Read, All Execute
        when '1100' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','1','0','0','1','1');  // RW
        when '1101' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','1','0','1','1','1');  // RW, Unpriv Execute
        when '1110' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','1','1','0','1','1');  // RW, Priv Execute
        when '1111' =&gt; (r,w,px,ux,w_rcw,w_mmu) = ('1','1','1','1','1','1');  // RW, All Execute
    end;

    let x : bit = if accdesc.el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then ux else px;

    // RCW and MMU read permissions.
    (r_rcw, r_mmu) = (r, r);

    // Stage 2 Top Level Permission Attributes.
    case s2po of
        when '0110' =&gt; (toplevel0,toplevel1) = ('1','0');
        when '0011' =&gt; (toplevel0,toplevel1) = ('0','1');
        when '0111' =&gt; (toplevel0,toplevel1) = ('1','1');
        otherwise =&gt;   (toplevel0,toplevel1) = ('0','0');
    end;

    s2overlay_perms.or = r;
    s2overlay_perms.ow = w;
    s2overlay_perms.ox = x;
    s2overlay_perms.or_rcw = r_rcw;
    s2overlay_perms.ow_rcw = w_rcw;
    s2overlay_perms.or_mmu = r_mmu;
    s2overlay_perms.ow_mmu = w_mmu;
    s2overlay_perms.toplevel0 = toplevel0;
    s2overlay_perms.toplevel1 = toplevel1;

    return s2overlay_perms;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_S2TxSZFaults" mylink="aarch64.translation.vmsa_faults.AArch64_S2TxSZFaults" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2TxSZFaults()
// ======================
// Detect whether configuration of stage 2 TxSZ field generates a fault

func <anchor link="func_AArch64_S2TxSZFaults_2">AArch64_S2TxSZFaults</anchor>(walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>, s1aarch64 : boolean) =&gt; boolean
begin
    let mintxsz : integer = <a link="func_AArch64_S2MinTxSZ_2" file="shared_pseudocode.xml">AArch64_S2MinTxSZ</a>(walkparams, s1aarch64);
    let maxtxsz : integer = <a link="func_AArch64_MaxTxSZ_1" file="shared_pseudocode.xml">AArch64_MaxTxSZ</a>(walkparams.tgx);

    if UInt(walkparams.txsz) &lt; mintxsz then
        return (IsFeatureImplemented(FEAT_LPA) ||
                ImpDefBool(&quot;Fault on TxSZ value below minimum&quot;));
    end;
    if UInt(walkparams.txsz) &gt; maxtxsz then
        return ImpDefBool(&quot;Fault on TxSZ value above maximum&quot;);
    end;

    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_faults/AArch64_VAIsOutOfRange" mylink="aarch64.translation.vmsa_faults.AArch64_VAIsOutOfRange" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_VAIsOutOfRange()
// ========================
// Check bits not resolved by translation are identical and of accepted value

func <anchor link="func_AArch64_VAIsOutOfRange_4">AArch64_VAIsOutOfRange</anchor>(va_in : bits(64), acctype : <a link="type_AccessType" file="shared_pseudocode.xml">AccessType</a>,
                            regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>) =&gt; boolean
begin
    var va : bits(64) = va_in;

    let addrtop : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_AArch64_AddrTop_3" file="shared_pseudocode.xml">AArch64_AddrTop</a>(walkparams.tbid, acctype, walkparams.tbi);

    // If the VA has a Logical Address Tag then the bits holding the Logical Address Tag are
    // ignored when checking if the address is out of range.
    if walkparams.mtx == '1' &amp;&amp; acctype != <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> then
        va[59:56] = if <a link="func_AArch64_GetVARange_1" file="shared_pseudocode.xml">AArch64_GetVARange</a>(va) == <a link="enum_VARange_UPPER" file="shared_pseudocode.xml">VARange_UPPER</a> then '1111' else '0000';
    end;

    // Input Address size
    let iasize : integer{} = <a link="func_AArch64_IASize_1" file="shared_pseudocode.xml">AArch64_IASize</a>(walkparams.txsz);

    // The min value of TxSZ can be 8, with LVA3 implemented.
    // If TxSZ is set to 8 iasize becomes 64 - 8 = 56
    // If tbi is also set, addrtop becomes 55
    // Then the return statements check va[56:55]
    // The check here is to guard against this corner case.
    if addrtop &lt; iasize then
        return FALSE;
    end;

    if <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) then
        if <a link="func_AArch64_GetVARange_1" file="shared_pseudocode.xml">AArch64_GetVARange</a>(va) == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then
            return !IsZero(va[addrtop:iasize]);
        else
            return !IsOnes(va[addrtop:iasize]);
        end;
    else
        return !IsZero(va[addrtop:iasize]);
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_memattr/AArch64_S2ApplyFWBMemAttrs" mylink="aarch64.translation.vmsa_memattr.AArch64_S2ApplyFWBMemAttrs" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2ApplyFWBMemAttrs()
// ============================
// Apply stage 2 forced Write-Back on stage 1 memory attributes.

func <anchor link="func_AArch64_S2ApplyFWBMemAttrs_4">AArch64_S2ApplyFWBMemAttrs</anchor>{N}(s1_memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>, walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>,
                                   descriptor : bits(N)) =&gt; <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>
begin
    var memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>;
    let s2_attr : bits(4) = descriptor[5:2];
    let s2_sh : bits(2)   = if walkparams.ds == '1' then walkparams.sh else descriptor[9:8];
    let s2_fnxs : bit     = descriptor[11];

    if s2_attr[2] == '0' then          // S2 Device, S1 any
        let s2_device : <a link="type_DeviceType" file="shared_pseudocode.xml">DeviceType</a> = <a link="func_DecodeDevice_1" file="shared_pseudocode.xml">DecodeDevice</a>(s2_attr[1:0]);
        memattrs.memtype = <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a>;
        if s1_memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> then
            memattrs.device = <a link="func_S2CombineS1Device_2" file="shared_pseudocode.xml">S2CombineS1Device</a>(s1_memattrs.device, s2_device);
        else
            memattrs.device = s2_device;
        end;

        memattrs.xs = s1_memattrs.xs;

    elsif s2_attr[1:0] == '11' then    // S2 attr = S1 attr
        memattrs = s1_memattrs;

    elsif s2_attr[1:0] == '10' then    // Force writeback
        memattrs.memtype = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
        memattrs.inner.attrs = <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>;
        memattrs.outer.attrs = <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>;

        if (s1_memattrs.memtype == <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a> &amp;&amp;
                s1_memattrs.inner.attrs != <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>) then
            memattrs.inner.hints     = s1_memattrs.inner.hints;
            memattrs.inner.transient = s1_memattrs.inner.transient;
        else
            memattrs.inner.hints     = <a link="global_MemHint_RWA" file="shared_pseudocode.xml">MemHint_RWA</a>;
            memattrs.inner.transient = FALSE;
        end;

        if (s1_memattrs.memtype == <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a> &amp;&amp;
                s1_memattrs.outer.attrs != <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>) then
            memattrs.outer.hints     = s1_memattrs.outer.hints;
            memattrs.outer.transient = s1_memattrs.outer.transient;
        else
            memattrs.outer.hints     = <a link="global_MemHint_RWA" file="shared_pseudocode.xml">MemHint_RWA</a>;
            memattrs.outer.transient = FALSE;
        end;

        memattrs.xs = '0';

    else                               // Non-cacheable unless S1 is device
        if s1_memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> then
            memattrs = s1_memattrs;
        else
            var cacheability_attr : <a link="type_MemAttrHints" file="shared_pseudocode.xml">MemAttrHints</a>;
            cacheability_attr.attrs = <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>;

            memattrs.memtype = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
            memattrs.inner   = cacheability_attr;
            memattrs.outer   = cacheability_attr;

            memattrs.xs = s1_memattrs.xs;
        end;
    end;

    let s2_shareability : <a link="type_Shareability" file="shared_pseudocode.xml">Shareability</a> = <a link="func_DecodeShareability_1" file="shared_pseudocode.xml">DecodeShareability</a>(s2_sh);
    memattrs.shareability = <a link="func_S2CombineS1Shareability_2" file="shared_pseudocode.xml">S2CombineS1Shareability</a>(s1_memattrs.shareability, s2_shareability);
    memattrs.tags         = <a link="func_S2MemTagType_2" file="shared_pseudocode.xml">S2MemTagType</a>(memattrs, s1_memattrs.tags);
    memattrs.notagaccess  = (s2_attr[3:1] == '111' &amp;&amp; memattrs.tags == <a link="enum_MemTag_AllocationTagged" file="shared_pseudocode.xml">MemTag_AllocationTagged</a>);

    if s2_fnxs == '1' then
        memattrs.xs = '0';
    end;

    memattrs.shareability = <a link="func_EffectiveShareability_1" file="shared_pseudocode.xml">EffectiveShareability</a>(memattrs);
    return memattrs;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_tlbcontext/AArch64_GetS1TLBContext" mylink="aarch64.translation.vmsa_tlbcontext.AArch64_GetS1TLBContext" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_GetS1TLBContext()
// =========================
// Gather translation context for accesses with VA to match against TLB entries

func <anchor link="func_AArch64_GetS1TLBContext_4">AArch64_GetS1TLBContext</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>,
                             va : bits(64), tg : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>) =&gt; <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>
begin
    var tlbcontext : <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>;

    case regime of
        when <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> =&gt;  tlbcontext = <a link="func_AArch64_TLBContextEL3_3" file="shared_pseudocode.xml">AArch64_TLBContextEL3</a>(ss, va, tg);
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> =&gt;  tlbcontext = <a link="func_AArch64_TLBContextEL2_3" file="shared_pseudocode.xml">AArch64_TLBContextEL2</a>(ss, va, tg);
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt; tlbcontext = <a link="func_AArch64_TLBContextEL20_3" file="shared_pseudocode.xml">AArch64_TLBContextEL20</a>(ss, va, tg);
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt; tlbcontext = <a link="func_AArch64_TLBContextEL10_3" file="shared_pseudocode.xml">AArch64_TLBContextEL10</a>(ss, va, tg);
        otherwise =&gt;
            unreachable;

    end;

    tlbcontext.includes_s1  = TRUE;
    // The following may be amended for EL1&amp;0 Regime if caching of stage 2 is successful
    tlbcontext.includes_s2  = FALSE;
    tlbcontext.use_vmid     = <a link="func_UseVMID_1" file="shared_pseudocode.xml">UseVMID</a>(regime);
    // The following may be amended if Granule Protection Check passes
    tlbcontext.includes_gpt = FALSE;
    return tlbcontext;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_tlbcontext/AArch64_GetS2TLBContext" mylink="aarch64.translation.vmsa_tlbcontext.AArch64_GetS2TLBContext" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_GetS2TLBContext()
// =========================
// Gather translation context for accesses with IPA to match against TLB entries

func <anchor link="func_AArch64_GetS2TLBContext_3">AArch64_GetS2TLBContext</anchor>(ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, ipa : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>, tg : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>) =&gt; <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>
begin
    assert <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>();

    var tlbcontext : <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>;

    tlbcontext.ss       = ss;
    tlbcontext.regime   = <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a>;
    tlbcontext.ipaspace = ipa.paspace;
    tlbcontext.vmid     = <a link="func_VMID_0" file="shared_pseudocode.xml">VMID</a>();
    tlbcontext.tg       = tg;
    tlbcontext.ia       = ZeroExtend{64}(ipa.address);
    if IsFeatureImplemented(FEAT_TTCNP) then
        tlbcontext.cnp = if ipa.paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> then VSTTBR_EL2().CnP else VTTBR_EL2().CnP;
    else
        tlbcontext.cnp = '0';
    end;


    tlbcontext.includes_s1  = FALSE;
    tlbcontext.includes_s2  = TRUE;
    tlbcontext.use_vmid     = TRUE;
    // This may be amended if Granule Protection Check passes
    tlbcontext.includes_gpt = FALSE;
    return tlbcontext;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_tlbcontext/AArch64_TLBContextEL10" mylink="aarch64.translation.vmsa_tlbcontext.AArch64_TLBContextEL10" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBContextEL10()
// ========================
// Gather translation context for accesses under EL10 regime to match against TLB entries

func <anchor link="func_AArch64_TLBContextEL10_3">AArch64_TLBContextEL10</anchor>(ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, va : bits(64), tg : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>) =&gt; <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>
begin
    var tlbcontext : <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>;

    tlbcontext.ss     = ss;
    tlbcontext.regime = <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a>;
    tlbcontext.vmid   = <a link="func_VMID_0" file="shared_pseudocode.xml">VMID</a>();

    if IsFeatureImplemented(FEAT_ASID2) &amp;&amp; <a link="func_IsTCR2EL1Enabled_0" file="shared_pseudocode.xml">IsTCR2EL1Enabled</a>() &amp;&amp; TCR2_EL1().A2 == '1' then
        let varange : <a link="type_VARange" file="shared_pseudocode.xml">VARange</a> = <a link="func_AArch64_GetVARange_1" file="shared_pseudocode.xml">AArch64_GetVARange</a>(va);
        tlbcontext.asid = if varange == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then TTBR0_EL1().ASID else TTBR1_EL1().ASID;
    else
        tlbcontext.asid = if TCR_EL1().A1 == '0' then TTBR0_EL1().ASID else TTBR1_EL1().ASID;
    end;

    if TCR_EL1().AS == '0' then
        tlbcontext.asid[15:8] = Zeros{8};
    end;
    tlbcontext.tg     = tg;
    tlbcontext.ia     = va;

    if IsFeatureImplemented(FEAT_TTCNP) then
        if <a link="func_AArch64_GetVARange_1" file="shared_pseudocode.xml">AArch64_GetVARange</a>(va) == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then
            tlbcontext.cnp = TTBR0_EL1().CnP;
        else
            tlbcontext.cnp = TTBR1_EL1().CnP;
        end;
    else
        tlbcontext.cnp = '0';
    end;

    return tlbcontext;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_tlbcontext/AArch64_TLBContextEL2" mylink="aarch64.translation.vmsa_tlbcontext.AArch64_TLBContextEL2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBContextEL2()
// =======================
// Gather translation context for accesses under EL2 regime to match against TLB entries

func <anchor link="func_AArch64_TLBContextEL2_3">AArch64_TLBContextEL2</anchor>(ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, va : bits(64), tg : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>) =&gt; <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>
begin
    var tlbcontext : <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>;

    tlbcontext.ss     = ss;
    tlbcontext.regime = <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a>;
    tlbcontext.tg     = tg;
    tlbcontext.ia     = va;
    tlbcontext.cnp    = if IsFeatureImplemented(FEAT_TTCNP) then TTBR0_EL2().CnP else '0';

    return tlbcontext;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_tlbcontext/AArch64_TLBContextEL20" mylink="aarch64.translation.vmsa_tlbcontext.AArch64_TLBContextEL20" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBContextEL20()
// ========================
// Gather translation context for accesses under EL20 regime to match against TLB entries

func <anchor link="func_AArch64_TLBContextEL20_3">AArch64_TLBContextEL20</anchor>(ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, va : bits(64), tg : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>) =&gt; <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>
begin
    var tlbcontext : <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>;

    tlbcontext.ss     = ss;
    tlbcontext.regime = <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>;

    if IsFeatureImplemented(FEAT_ASID2) &amp;&amp; <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() &amp;&amp; TCR2_EL2().A2 == '1' then
        let varange : <a link="type_VARange" file="shared_pseudocode.xml">VARange</a> = <a link="func_AArch64_GetVARange_1" file="shared_pseudocode.xml">AArch64_GetVARange</a>(va);
        tlbcontext.asid = if varange == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then TTBR0_EL2().ASID else TTBR1_EL2().ASID;
    else
        tlbcontext.asid = if TCR_EL2().A1 == '0' then TTBR0_EL2().ASID else TTBR1_EL2().ASID;
    end;

    if TCR_EL2().AS == '0' then
        tlbcontext.asid[15:8] = Zeros{8};
    end;
    tlbcontext.tg     = tg;
    tlbcontext.ia     = va;

    if IsFeatureImplemented(FEAT_TTCNP) then
        if <a link="func_AArch64_GetVARange_1" file="shared_pseudocode.xml">AArch64_GetVARange</a>(va) == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then
            tlbcontext.cnp = TTBR0_EL2().CnP;
        else
            tlbcontext.cnp = TTBR1_EL2().CnP;
        end;
    else
        tlbcontext.cnp = '0';
    end;

    return tlbcontext;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_tlbcontext/AArch64_TLBContextEL3" mylink="aarch64.translation.vmsa_tlbcontext.AArch64_TLBContextEL3" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TLBContextEL3()
// =======================
// Gather translation context for accesses under EL3 regime to match against TLB entries

func <anchor link="func_AArch64_TLBContextEL3_3">AArch64_TLBContextEL3</anchor>(ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, va : bits(64), tg : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>) =&gt; <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>
begin
    var tlbcontext : <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>;

    tlbcontext.ss     = ss;
    tlbcontext.regime = <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a>;
    tlbcontext.tg     = tg;
    tlbcontext.ia     = va;
    tlbcontext.cnp    = if IsFeatureImplemented(FEAT_TTCNP) then TTBR0_EL3().CnP else '0';

    return tlbcontext;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_translation/AArch64_FullTranslate" mylink="aarch64.translation.vmsa_translation.AArch64_FullTranslate" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_FullTranslate()
// =======================
// Address translation as specified by VMSA
// Alignment check NOT due to memory type is expected to be done before translation


func <anchor link="func_AArch64_FullTranslate_4">AArch64_FullTranslate</anchor>(va : bits(64), size : integer, accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                           aligned : boolean) =&gt; <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>
begin
    let regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a> = <a link="func_TranslationRegime_1" file="shared_pseudocode.xml">TranslationRegime</a>(accdesc.el);
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_2" file="shared_pseudocode.xml">NoFault</a>(accdesc, va);

    var ipa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    (fault, ipa) = <a link="func_AArch64_S1Translate_6" file="shared_pseudocode.xml">AArch64_S1Translate</a>(fault, regime, va, size, aligned, accdesc);

    if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        return <a link="func_CreateFaultyAddressDescriptor_1" file="shared_pseudocode.xml">CreateFaultyAddressDescriptor</a>(fault);
    end;

    if accdesc.ss == <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> then
        assert <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>();
    end;
    if regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        let s1aarch64 : boolean = TRUE;
        var pa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
        (fault, pa) = <a link="func_AArch64_S2Translate_5" file="shared_pseudocode.xml">AArch64_S2Translate</a>(fault, ipa, s1aarch64, aligned, accdesc);

        if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
            return <a link="func_CreateFaultyAddressDescriptor_1" file="shared_pseudocode.xml">CreateFaultyAddressDescriptor</a>(fault);
        else
            return pa;
        end;
    else
        return ipa;
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_translation/AArch64_MemSwapTableDesc" mylink="aarch64.translation.vmsa_translation.AArch64_MemSwapTableDesc" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_MemSwapTableDesc()
// ==========================
// Perform HW update of table descriptor as an atomic operation

func <anchor link="func_AArch64_MemSwapTableDesc_7">AArch64_MemSwapTableDesc</anchor>{N : integer{64, 128}}(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, prev_desc : bits(N),
                                                    new_desc : bits(N), ee : bit,
                                                    descaccess : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                                                    descpaddr : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>
                                                ) =&gt; (<a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, bits(N))
begin
    assert descaccess.acctype == <a link="enum_AccessType_TTW" file="shared_pseudocode.xml">AccessType_TTW</a>;
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;
    var iswrite : boolean;

    if IsFeatureImplemented(FEAT_RME) then
        fault.gpcf = <a link="func_GranuleProtectionCheck_2" file="shared_pseudocode.xml">GranuleProtectionCheck</a>(descpaddr, descaccess);
        if fault.gpcf.gpf != <a link="enum_GPCF_None" file="shared_pseudocode.xml">GPCF_None</a> then
            fault.statuscode = <a link="enum_Fault_GPCFOnWalk" file="shared_pseudocode.xml">Fault_GPCFOnWalk</a>;
            fault.paddress   = descpaddr.paddress;
            fault.gpcfs2walk = fault.secondstage;
            return (fault, ARBITRARY : bits(N));
        end;
    end;

    // All observers in the shareability domain observe the
    // following memory read and write accesses atomically.
    var mem_desc : bits(N);
    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
    (memstatus, mem_desc) = <a link="func_PhysMemRead_3" file="shared_pseudocode.xml">PhysMemRead</a>{N}(descpaddr, descaccess);

    if ee == '1' then
        mem_desc = <a link="func_BigEndianReverse_2" file="shared_pseudocode.xml">BigEndianReverse</a>{N}(mem_desc);
    end;

    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
        iswrite = FALSE;
        fault = <a link="func_HandleExternalTTWAbort_6" file="shared_pseudocode.xml">HandleExternalTTWAbort</a>(memstatus, iswrite, descpaddr, descaccess, N DIV 8, fault);
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(fault.statuscode) then
            return (fault, ARBITRARY : bits(N));
        end;
    end;

    if mem_desc == prev_desc  then
        let ordered_new_desc : bits(N) = (if ee == '1' then <a link="func_BigEndianReverse_2" file="shared_pseudocode.xml">BigEndianReverse</a>{N}(new_desc)
                                                       else new_desc);
        memstatus = <a link="func_PhysMemWrite_4" file="shared_pseudocode.xml">PhysMemWrite</a>{N}(descpaddr, descaccess, ordered_new_desc);

        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            iswrite = TRUE;
            fault = <a link="func_HandleExternalTTWAbort_6" file="shared_pseudocode.xml">HandleExternalTTWAbort</a>(memstatus, iswrite, descpaddr, descaccess, N DIV 8,
                                           fault);

            if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(fault.statuscode) then
                return (fault, ARBITRARY : bits(N));
            end;
        end;

        // Reflect what is now in memory (in little endian format)
        mem_desc = new_desc;
    end;

    return (fault, mem_desc);
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_translation/AArch64_S1DisabledOutput" mylink="aarch64.translation.vmsa_translation.AArch64_S1DisabledOutput" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1DisabledOutput()
// ==========================
// Map the VA to IPA/PA and assign default memory attributes

func <anchor link="func_AArch64_S1DisabledOutput_5">AArch64_S1DisabledOutput</anchor>(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
                              va_in :  bits(64), accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                              aligned : boolean) =&gt; (<a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>)
begin
    var va : bits(64) = va_in;
    let walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a> = <a link="func_AArch64_GetS1TTWParams_4" file="shared_pseudocode.xml">AArch64_GetS1TTWParams</a>(regime, accdesc.el, accdesc.ss, va);
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;

    // No memory page is guarded when stage 1 address translation is disabled
    <a link="func_SetInGuardedPage_1" file="shared_pseudocode.xml">SetInGuardedPage</a>(FALSE);

    // Output Address
    var oa : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    oa.address = va[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0];
    case accdesc.ss of
        when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;    oa.paspace = <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>;
        when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt; oa.paspace = <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
        when <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a> =&gt;      oa.paspace = <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>;
        when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;     oa.paspace = <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>;
    end;

    var memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>;
    if regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; walkparams.dc == '1' then
        var default_cacheability : <a link="type_MemAttrHints" file="shared_pseudocode.xml">MemAttrHints</a>;
        default_cacheability.attrs     = <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>;
        default_cacheability.hints     = <a link="global_MemHint_RWA" file="shared_pseudocode.xml">MemHint_RWA</a>;
        default_cacheability.transient = FALSE;

        memattrs.memtype      = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
        memattrs.outer        = default_cacheability;
        memattrs.inner        = default_cacheability;
        memattrs.shareability = <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a>;
        if walkparams.dct == '1' then
            memattrs.tags     = <a link="enum_MemTag_AllocationTagged" file="shared_pseudocode.xml">MemTag_AllocationTagged</a>;
        elsif IsFeatureImplemented(FEAT_MTE_CANONICAL_TAGS) &amp;&amp; walkparams.mtx == '1' then
            memattrs.tags     = <a link="enum_MemTag_CanonicallyTagged" file="shared_pseudocode.xml">MemTag_CanonicallyTagged</a>;
        else
            memattrs.tags     = <a link="enum_MemTag_Untagged" file="shared_pseudocode.xml">MemTag_Untagged</a>;
        end;
        memattrs.xs           = '0';
    elsif accdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> then
        var i_cache_attr : <a link="type_MemAttrHints" file="shared_pseudocode.xml">MemAttrHints</a>;
        if <a link="func_AArch64_S1ICacheEnabled_1" file="shared_pseudocode.xml">AArch64_S1ICacheEnabled</a>(regime) then
            i_cache_attr.attrs     = <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a>;
            i_cache_attr.hints     = <a link="global_MemHint_RA" file="shared_pseudocode.xml">MemHint_RA</a>;
            i_cache_attr.transient = FALSE;
        else
            i_cache_attr.attrs     = <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>;
        end;

        memattrs.memtype      = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
        memattrs.outer        = i_cache_attr;
        memattrs.inner        = i_cache_attr;
        memattrs.shareability = <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
        memattrs.tags         = <a link="enum_MemTag_Untagged" file="shared_pseudocode.xml">MemTag_Untagged</a>;
        memattrs.xs           = '1';
    elsif accdesc.acctype == <a link="enum_AccessType_SPE" file="shared_pseudocode.xml">AccessType_SPE</a> &amp;&amp; <a link="func_EffectivePMBLIMITR_EL1_nVM_0" file="shared_pseudocode.xml">EffectivePMBLIMITR_EL1_nVM</a>() == '1' then
        memattrs = <a link="func_S1DecodeMemAttrs_5" file="shared_pseudocode.xml">S1DecodeMemAttrs</a>(PMBMAR_EL1().Attr, PMBMAR_EL1().SH, TRUE,
                                    walkparams, accdesc.acctype);
    elsif accdesc.acctype == <a link="enum_AccessType_TRBE" file="shared_pseudocode.xml">AccessType_TRBE</a> &amp;&amp; <a link="func_EffectiveTRBLIMITR_EL1_nVM_0" file="shared_pseudocode.xml">EffectiveTRBLIMITR_EL1_nVM</a>() == '1' then
        memattrs = <a link="func_S1DecodeMemAttrs_5" file="shared_pseudocode.xml">S1DecodeMemAttrs</a>(TRBMAR_EL1().Attr, TRBMAR_EL1().SH, TRUE,
                                    walkparams, accdesc.acctype);
    else
        memattrs.memtype      = <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a>;
        memattrs.device       = <a link="enum_DeviceType_nGnRnE" file="shared_pseudocode.xml">DeviceType_nGnRnE</a>;
        memattrs.shareability = <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
        if IsFeatureImplemented(FEAT_MTE_CANONICAL_TAGS) &amp;&amp; walkparams.mtx == '1' then
            memattrs.tags = <a link="enum_MemTag_CanonicallyTagged" file="shared_pseudocode.xml">MemTag_CanonicallyTagged</a>;
        else
            memattrs.tags = <a link="enum_MemTag_Untagged" file="shared_pseudocode.xml">MemTag_Untagged</a>;
        end;
        memattrs.xs           = '1';
    end;
    memattrs.notagaccess = FALSE;

    if walkparams.mtx == '1' &amp;&amp; walkparams.tbi == '0' &amp;&amp; accdesc.acctype != <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> then
        // For the purpose of the checks in this function, the MTE tag bits are ignored.
        va[59:56] = if <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) then Replicate{4}(va[55]) else '0000';
    end;

    fault.level = 0;
    let addrtop : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_AArch64_AddrTop_3" file="shared_pseudocode.xml">AArch64_AddrTop</a>(walkparams.tbid, accdesc.acctype,
                                                   walkparams.tbi);
    let pamax : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>();

    if !IsZero(va[addrtop:pamax]) then
        fault.statuscode = <a link="enum_Fault_AddressSize" file="shared_pseudocode.xml">Fault_AddressSize</a>;
    elsif <a link="func_AArch64_S1HasAlignmentFaultDueToMemType_5" file="shared_pseudocode.xml">AArch64_S1HasAlignmentFaultDueToMemType</a>(regime, accdesc, aligned, walkparams.ntlsmd,
                                                  memattrs) then
        fault.statuscode = <a link="enum_Fault_Alignment" file="shared_pseudocode.xml">Fault_Alignment</a>;
    elsif ((accdesc.exclusive || accdesc.atomicop) &amp;&amp;
            !(regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().DC == '1') &amp;&amp;
            <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_Atomic_MMU_IMPDEF_FAULT" file="shared_pseudocode.xml">Unpredictable_Atomic_MMU_IMPDEF_FAULT</a>)) then
        fault.statuscode = <a link="enum_Fault_Exclusive" file="shared_pseudocode.xml">Fault_Exclusive</a>;
    end;

    if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
    else
        var ipa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_CreateAddressDescriptor_4" file="shared_pseudocode.xml">CreateAddressDescriptor</a>(va_in, oa, memattrs, accdesc);
        ipa.mecid = <a link="func_AArch64_S1DisabledOutputMECID_3" file="shared_pseudocode.xml">AArch64_S1DisabledOutputMECID</a>(walkparams, regime, ipa.paddress.paspace);
        return (fault, ipa);
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_translation/AArch64_S1Translate" mylink="aarch64.translation.vmsa_translation.AArch64_S1Translate" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1Translate()
// =====================
// Translate VA to IPA/PA depending on the regime

func <anchor link="func_AArch64_S1Translate_6">AArch64_S1Translate</anchor>(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
                         va : bits(64), size : integer, aligned : boolean,
                         accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; (<a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>)
                         recurselimit Unbounded_DescriptorUpdate
begin
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;
    // Prepare fault fields in case a fault is detected
    fault.secondstage = FALSE;
    fault.s2fs1walk   = FALSE;

    if !<a link="func_AArch64_S1Enabled_2" file="shared_pseudocode.xml">AArch64_S1Enabled</a>(regime, accdesc.acctype) then
        return <a link="func_AArch64_S1DisabledOutput_5" file="shared_pseudocode.xml">AArch64_S1DisabledOutput</a>(fault, regime, va, accdesc, aligned);
    end;

    var walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a> = <a link="func_AArch64_GetS1TTWParams_4" file="shared_pseudocode.xml">AArch64_GetS1TTWParams</a>(regime, accdesc.el, accdesc.ss, va);
    let s1mintxsz : integer = <a link="func_AArch64_S1MinTxSZ_2" file="shared_pseudocode.xml">AArch64_S1MinTxSZ</a>(regime, walkparams);
    let s1maxtxsz : integer = <a link="func_AArch64_MaxTxSZ_1" file="shared_pseudocode.xml">AArch64_MaxTxSZ</a>(walkparams.tgx);
    if <a link="func_AArch64_S1TxSZFaults_2" file="shared_pseudocode.xml">AArch64_S1TxSZFaults</a>(regime, walkparams) then
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
        fault.level      = 0;
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
    elsif UInt(walkparams.txsz) &lt; s1mintxsz then
        walkparams.txsz = s1mintxsz[5:0];
    elsif UInt(walkparams.txsz) &gt; s1maxtxsz then
        walkparams.txsz = s1maxtxsz[5:0];
    end;

    if <a link="func_AArch64_VAIsOutOfRange_4" file="shared_pseudocode.xml">AArch64_VAIsOutOfRange</a>(va, accdesc.acctype, regime, walkparams) then
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
        fault.level      = 0;
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
    end;

    if accdesc.el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; walkparams.e0pd == '1' then
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
        fault.level      = 0;
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
    end;

    if (IsFeatureImplemented(FEAT_SVE) &amp;&amp; accdesc.el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; walkparams.nfd == '1' &amp;&amp;
          ((accdesc.nonfault &amp;&amp; accdesc.contiguous) ||
           (accdesc.firstfault &amp;&amp; !accdesc.first &amp;&amp; !accdesc.contiguous))) then
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
        fault.level      = 0;
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
    end;

    var descipaddr : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    var walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>;
    var descriptor : bits(128);
    if walkparams.d128 == '1' then
        (fault, descipaddr, walkstate, descriptor) = <a link="func_AArch64_S1Walk_6" file="shared_pseudocode.xml">AArch64_S1Walk</a>{128}(fault, walkparams, va,
                                                                         regime, accdesc);
    else
        (fault, descipaddr, walkstate, descriptor[63:0]) = <a link="func_AArch64_S1Walk_6" file="shared_pseudocode.xml">AArch64_S1Walk</a>{64}(fault, walkparams, va,
                                                                              regime, accdesc);
        descriptor[127:64] = Zeros{64};
    end;
    if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
    end;
    if <a link="func_AArch64_S1HasAlignmentFaultDueToMemType_5" file="shared_pseudocode.xml">AArch64_S1HasAlignmentFaultDueToMemType</a>(regime, accdesc, aligned, walkparams.ntlsmd,
                                               walkstate.memattrs) then
        fault.statuscode = <a link="enum_Fault_Alignment" file="shared_pseudocode.xml">Fault_Alignment</a>;
    end;

    let fault_perm : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_AArch64_S1CheckPermissions_7" file="shared_pseudocode.xml">AArch64_S1CheckPermissions</a>(fault, va, size, regime,
                                                                 walkstate, walkparams, accdesc);

    var mem_desc : bits(128);
    var new_desc : bits(128) = descriptor;

    if <a link="func_AArch64_SetAccessFlag_4" file="shared_pseudocode.xml">AArch64_SetAccessFlag</a>(walkparams.ha, accdesc, fault, fault_perm) then
        // Set descriptor AF bit
        new_desc[10] = '1';
    end;

    // If HW update of dirty bit is enabled, the walk state permissions
    // will already reflect a configuration permitting writes.
    // The update of the descriptor occurs only if the descriptor bits in
    // memory do not reflect that and the access instigates a write.

    if <a link="func_AArch64_SetDirtyState_5" file="shared_pseudocode.xml">AArch64_SetDirtyState</a>(walkparams.hd, (walkparams.pie OR descriptor[51]),
                             accdesc, fault, fault_perm) then
        // Clear descriptor AP[2]/nDirty bit permitting stage 1 writes
        new_desc[7] = '0';
    end;

    if fault.statuscode == <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> &amp;&amp; fault_perm.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        fault = fault_perm;
    end;

    // Either the access flag was clear or AP[2]/nDirty was set
    if new_desc != descriptor then
        if (!<a link="func_IsWBShareable_1" file="shared_pseudocode.xml">IsWBShareable</a>(descipaddr.memattrs) &amp;&amp;
              <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_Unsupported_Atomic_HW_Update" file="shared_pseudocode.xml">Unpredictable_Unsupported_Atomic_HW_Update</a>)) then
            fault.statuscode = <a link="enum_Fault_UnsupportedAtomicHWUpdate" file="shared_pseudocode.xml">Fault_UnsupportedAtomicHWUpdate</a>;
            return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
        end;

        var descpaddr : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
        let descaccess : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescTTEUpdate_1" file="shared_pseudocode.xml">CreateAccDescTTEUpdate</a>(accdesc);

        if regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
            var s2fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>;
            let s1aarch64 : boolean = TRUE;
            let s2aligned : boolean = TRUE;
            (s2fault, descpaddr) = <a link="func_AArch64_S2Translate_5" file="shared_pseudocode.xml">AArch64_S2Translate</a>(fault, descipaddr, s1aarch64, s2aligned,
                                                       descaccess);
            if s2fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
                return (s2fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
            end;

        else
            descpaddr = descipaddr;
        end;
        if walkparams.d128 == '1' then
            (fault, mem_desc) = <a link="func_AArch64_MemSwapTableDesc_7" file="shared_pseudocode.xml">AArch64_MemSwapTableDesc</a>{128}(fault, descriptor,
                                                              new_desc, walkparams.ee,
                                                              descaccess, descpaddr);
        else
            (fault, mem_desc[63:0]) = <a link="func_AArch64_MemSwapTableDesc_7" file="shared_pseudocode.xml">AArch64_MemSwapTableDesc</a>{64}(fault, descriptor[63:0],
                                                                   new_desc[63:0], walkparams.ee,
                                                                   descaccess, descpaddr);
            mem_desc[127:64] = Zeros{64};
        end;

        if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
            if (accdesc.acctype == <a link="enum_AccessType_AT" file="shared_pseudocode.xml">AccessType_AT</a> &amp;&amp;
                    !(ImpDefBool(&quot;AT reports the HW update fault&quot;))) then
                // Mask the fault
                fault.statuscode = <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;
            else
                return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
            end;
        elsif new_desc != descriptor &amp;&amp; mem_desc != new_desc then
            // HW update of Dirty state or AF was not successful due to the descriptor being updated
            // not matching the descriptor used for translation. Due to this, the walk is restarted.
            return <a link="func_AArch64_S1Translate_6" file="shared_pseudocode.xml">AArch64_S1Translate</a>(fault_in, regime, va, size, aligned, accdesc);
        end;
    end;

    if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
    end;

    // Output Address
    let oa : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a> = <a link="func_StageOA_4" file="shared_pseudocode.xml">StageOA</a>(va, walkparams.d128, walkparams.tgx, walkstate);
    var memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>;
    if <a link="func_AArch64_S1TreatAsNormalNC_3" file="shared_pseudocode.xml">AArch64_S1TreatAsNormalNC</a>(walkstate, regime, accdesc) then
       // Treat memory attributes as Normal Non-Cacheable
        memattrs = <a link="func_NormalNCMemAttr_0" file="shared_pseudocode.xml">NormalNCMemAttr</a>();
        memattrs.xs = walkstate.memattrs.xs;

        // The effect of SCTLR_ELx.C when '0' is Constrained UNPREDICTABLE on the Tagged attribute
        // when the memory region is Allocation Tagged.
        if (IsFeatureImplemented(FEAT_MTE2) &amp;&amp;
              walkstate.memattrs.tags == <a link="enum_MemTag_AllocationTagged" file="shared_pseudocode.xml">MemTag_AllocationTagged</a> &amp;&amp;
              <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_S1CTAGGED" file="shared_pseudocode.xml">Unpredictable_S1CTAGGED</a>)) then
            memattrs.tags = <a link="enum_MemTag_AllocationTagged" file="shared_pseudocode.xml">MemTag_AllocationTagged</a>;
        // SCTLR_ELx.C has no effect on whether the memory region is treated as Canonically Tagged.
        elsif (IsFeatureImplemented(FEAT_MTE_CANONICAL_TAGS) &amp;&amp;
                 walkstate.memattrs.tags == <a link="enum_MemTag_CanonicallyTagged" file="shared_pseudocode.xml">MemTag_CanonicallyTagged</a>) then
            memattrs.tags = <a link="enum_MemTag_CanonicallyTagged" file="shared_pseudocode.xml">MemTag_CanonicallyTagged</a>;
        end;
    else
        memattrs = walkstate.memattrs;
    end;

    // Shareability value of stage 1 translation subject to stage 2 is IMPLEMENTATION DEFINED
    // to be either effective value or descriptor value
    if (regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().VM == '1' &amp;&amp;
            !(ImpDefBool(&quot;Apply effective shareability at stage 1&quot;))) then
        memattrs.shareability = walkstate.memattrs.shareability;
    else
        memattrs.shareability = <a link="func_EffectiveShareability_1" file="shared_pseudocode.xml">EffectiveShareability</a>(memattrs);
    end;

    var ipa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_CreateAddressDescriptor_4" file="shared_pseudocode.xml">CreateAddressDescriptor</a>(va, oa, memattrs, accdesc);
    ipa.s1assured = walkstate.s1assured;
    let varange : <a link="type_VARange" file="shared_pseudocode.xml">VARange</a> = <a link="func_AArch64_GetVARange_1" file="shared_pseudocode.xml">AArch64_GetVARange</a>(va);
    ipa.mecid = <a link="func_AArch64_S1OutputMECID_6" file="shared_pseudocode.xml">AArch64_S1OutputMECID</a>{128}(walkparams, regime, varange, ipa.paddress.paspace,
                                          descriptor);

    if (accdesc.atomicop &amp;&amp; !<a link="func_IsWBShareable_1" file="shared_pseudocode.xml">IsWBShareable</a>(memattrs) &amp;&amp;
          <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_Atomic_MMU_IMPDEF_FAULT" file="shared_pseudocode.xml">Unpredictable_Atomic_MMU_IMPDEF_FAULT</a>)) then
        fault.statuscode = <a link="enum_Fault_Exclusive" file="shared_pseudocode.xml">Fault_Exclusive</a>;
        return (fault, ipa);
    end;

    if accdesc.ls64 &amp;&amp; memattrs.memtype == <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a> then
        if IsFeatureImplemented(FEAT_LS64WB) &amp;&amp; !accdesc.withstatus then
            if (!<a link="func_IsWBShareable_1" file="shared_pseudocode.xml">IsWBShareable</a>(memattrs) &amp;&amp;
                  !(memattrs.inner.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> &amp;&amp;
                    memattrs.outer.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>) &amp;&amp;
                  (ImpDefBool(
                     &quot;LD64B or ST64B faults to cacheable non-iWBoWB memory&quot;))) then
                fault.statuscode = <a link="enum_Fault_Exclusive" file="shared_pseudocode.xml">Fault_Exclusive</a>;
                return (fault, ipa);
            end;
        elsif !(memattrs.inner.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> &amp;&amp; memattrs.outer.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>) then
            fault.statuscode = <a link="enum_Fault_Exclusive" file="shared_pseudocode.xml">Fault_Exclusive</a>;
            return (fault, ipa);
        end;
    end;

    return (fault, ipa);
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_translation/AArch64_S1TreatAsNormalNC" mylink="aarch64.translation.vmsa_translation.AArch64_S1TreatAsNormalNC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1TreatAsNormalNC()
// ===========================
// Returns TRUE if stage 1 memory attributes should be treated as Normal Non-Cacheable

func <anchor link="func_AArch64_S1TreatAsNormalNC_3">AArch64_S1TreatAsNormalNC</anchor>(walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
                               accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; boolean
begin
    return ((accdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> &amp;&amp;
              (walkstate.memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> || !<a link="func_AArch64_S1ICacheEnabled_1" file="shared_pseudocode.xml">AArch64_S1ICacheEnabled</a>(regime))) ||
           (accdesc.acctype != <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> &amp;&amp;
              !<a link="func_AArch64_S1DCacheEnabled_1" file="shared_pseudocode.xml">AArch64_S1DCacheEnabled</a>(regime) &amp;&amp; walkstate.memattrs.memtype == <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>));
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_translation/AArch64_S2Translate" mylink="aarch64.translation.vmsa_translation.AArch64_S2Translate" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2Translate()
// =====================
// Translate stage 1 IPA to PA and combine memory attributes

func <anchor link="func_AArch64_S2Translate_5">AArch64_S2Translate</anchor>(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, ipa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                         s1aarch64 : boolean, aligned : boolean,
                         accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; (<a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>)
                         recurselimit Unbounded_DescriptorUpdate
begin
    var walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a> = <a link="func_AArch64_GetS2TTWParams_3" file="shared_pseudocode.xml">AArch64_GetS2TTWParams</a>(accdesc.ss, ipa.paddress.paspace,
                                                          s1aarch64);
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;
    var s2fs1mro : boolean;
    // Prepare fault fields in case a fault is detected
    fault.statuscode = <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>; // Ignore any faults from stage 1
    fault.dirtybit     = FALSE;
    fault.overlay      = FALSE;
    fault.tagaccess    = FALSE;
    fault.s1tagnotdata = FALSE;
    fault.secondstage  = TRUE;
    fault.s2fs1walk    = accdesc.acctype == <a link="enum_AccessType_TTW" file="shared_pseudocode.xml">AccessType_TTW</a>;
    fault.ipaddress    = ipa.paddress;

    if walkparams.vm != '1' then
        // Stage 2 translation is disabled
        return (fault, ipa);
    end;

    let s2mintxsz : integer = <a link="func_AArch64_S2MinTxSZ_2" file="shared_pseudocode.xml">AArch64_S2MinTxSZ</a>(walkparams, s1aarch64);
    let s2maxtxsz : integer = <a link="func_AArch64_MaxTxSZ_1" file="shared_pseudocode.xml">AArch64_MaxTxSZ</a>(walkparams.tgx);
    if <a link="func_AArch64_S2TxSZFaults_2" file="shared_pseudocode.xml">AArch64_S2TxSZFaults</a>(walkparams, s1aarch64) then
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
        fault.level      = 0;
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
    elsif UInt(walkparams.txsz) &lt; s2mintxsz then
        walkparams.txsz = s2mintxsz[5:0];
    elsif UInt(walkparams.txsz) &gt; s2maxtxsz then
        walkparams.txsz = s2maxtxsz[5:0];
    end;

    if (walkparams.d128 == '0' &amp;&amp;
        (<a link="func_AArch64_S2InvalidSL_1" file="shared_pseudocode.xml">AArch64_S2InvalidSL</a>(walkparams) || <a link="func_AArch64_S2InconsistentSL_1" file="shared_pseudocode.xml">AArch64_S2InconsistentSL</a>(walkparams))) then
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
        fault.level      = 0;
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
    end;

    if <a link="func_AArch64_IPAIsOutOfRange_2" file="shared_pseudocode.xml">AArch64_IPAIsOutOfRange</a>(ipa.paddress.address, walkparams) then
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
        fault.level      = 0;
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
    end;

    var descpaddr : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    var walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>;
    var descriptor : bits(128);
    if walkparams.d128 == '1' then
        (fault, descpaddr, walkstate, descriptor) = <a link="func_AArch64_S2Walk_5" file="shared_pseudocode.xml">AArch64_S2Walk</a>{128}(fault, ipa, walkparams,
                                                                        accdesc);
    else
        (fault, descpaddr, walkstate, descriptor[63:0]) = <a link="func_AArch64_S2Walk_5" file="shared_pseudocode.xml">AArch64_S2Walk</a>{64}(fault, ipa, walkparams,
                                                                             accdesc);
        descriptor[127:64] = Zeros{64};
    end;
    if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
    end;

    if <a link="func_AArch64_S2HasAlignmentFaultDueToMemType_3" file="shared_pseudocode.xml">AArch64_S2HasAlignmentFaultDueToMemType</a>(accdesc, aligned, walkstate.memattrs) then
        fault.statuscode = <a link="enum_Fault_Alignment" file="shared_pseudocode.xml">Fault_Alignment</a>;
    end;

    var fault_perm : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>;
    (fault_perm, s2fs1mro) = <a link="func_AArch64_S2CheckPermissions_5" file="shared_pseudocode.xml">AArch64_S2CheckPermissions</a>(fault, walkstate, walkparams, ipa, accdesc);

    var mem_desc : bits(128);
    var new_desc : bits(128) = descriptor;

    if <a link="func_AArch64_SetAccessFlag_4" file="shared_pseudocode.xml">AArch64_SetAccessFlag</a>(walkparams.ha, accdesc, fault, fault_perm) then
        // Set descriptor AF bit
        new_desc[10] = '1';
    end;

    // If HW update of dirty bit is enabled, the walk state permissions
    // will already reflect a configuration permitting writes.
    // The update of the descriptor occurs only if the descriptor bits in
    // memory do not reflect that and the access instigates a write.

    if <a link="func_AArch64_SetDirtyState_5" file="shared_pseudocode.xml">AArch64_SetDirtyState</a>(walkparams.hd, (walkparams.s2pie OR descriptor[51]),
                             accdesc, fault, fault_perm) then
        // Set descriptor S2AP[1]/Dirty bit permitting stage 2 writes
        new_desc[7] = '1';
    end;

    if fault.statuscode == <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> &amp;&amp; fault_perm.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        fault = fault_perm;
    end;

    // Either the access flag was clear or S2AP[1]/Dirty was clear
    if new_desc != descriptor then
        if (!<a link="func_IsWBShareable_1" file="shared_pseudocode.xml">IsWBShareable</a>(descpaddr.memattrs) &amp;&amp;
              <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_Unsupported_Atomic_HW_Update" file="shared_pseudocode.xml">Unpredictable_Unsupported_Atomic_HW_Update</a>)) then
            fault.statuscode = <a link="enum_Fault_UnsupportedAtomicHWUpdate" file="shared_pseudocode.xml">Fault_UnsupportedAtomicHWUpdate</a>;
            return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
        end;

        if walkparams.hdbss == '1' &amp;&amp; descriptor[7] == '0' &amp;&amp; new_desc[7] == '1' then
            fault = <a link="func_AppendToHDBSS_5" file="shared_pseudocode.xml">AppendToHDBSS</a>(fault, ipa.paddress, accdesc, walkparams, walkstate.level);
        end;

        // If an error, other than a synchronous External abort, occurred on the HDBSS update,
        // stage 2 hardware update of dirty state is not permitted.
        if (!(walkparams.hdbss == '1' &amp;&amp; descriptor[7] != new_desc[7]) ||
              (HDBSSPROD_EL2().FSC != '101000' &amp;&amp;
              (!fault.hdbssf || <a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault.statuscode)))) then
            let descaccess : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescTTEUpdate_1" file="shared_pseudocode.xml">CreateAccDescTTEUpdate</a>(accdesc);
            if walkparams.d128 == '1' then
                (fault, mem_desc) = <a link="func_AArch64_MemSwapTableDesc_7" file="shared_pseudocode.xml">AArch64_MemSwapTableDesc</a>{128}(fault, descriptor, new_desc,
                                                             walkparams.ee, descaccess,
                                                             descpaddr);
            else
                (fault, mem_desc[63:0]) = <a link="func_AArch64_MemSwapTableDesc_7" file="shared_pseudocode.xml">AArch64_MemSwapTableDesc</a>{64}(fault, descriptor[63:0],
                                                                   new_desc[63:0], walkparams.ee,
                                                                   descaccess, descpaddr);
                mem_desc[127:64] = Zeros{64};
            end;
        end;

        if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
            if (accdesc.acctype == <a link="enum_AccessType_AT" file="shared_pseudocode.xml">AccessType_AT</a> &amp;&amp;
                    !(ImpDefBool(&quot;AT reports the HW update fault&quot;))) then
                // Mask the fault
                fault.statuscode = <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;
            else
                return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
            end;
        elsif new_desc != descriptor &amp;&amp; mem_desc != new_desc then
            // HW update of Dirty state or AF was not successful due to the descriptor being updated
            // not matching the descriptor used for translation. Due to this, the walk is restarted.
            return <a link="func_AArch64_S2Translate_5" file="shared_pseudocode.xml">AArch64_S2Translate</a>(fault_in, ipa, s1aarch64, aligned, accdesc);
        end;
    end;

    if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>);
    end;

    let ipa_64 : bits(64) = ZeroExtend{}(ipa.paddress.address);
    // Output Address
    let oa : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a> = <a link="func_StageOA_4" file="shared_pseudocode.xml">StageOA</a>(ipa_64, walkparams.d128, walkparams.tgx, walkstate);
    var s2_memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>;

    if <a link="func_AArch64_S2TreatAsNormalNC_3" file="shared_pseudocode.xml">AArch64_S2TreatAsNormalNC</a>(walkstate, walkparams, accdesc) then
        // Treat memory attributes as Normal Non-Cacheable
        s2_memattrs = <a link="func_NormalNCMemAttr_0" file="shared_pseudocode.xml">NormalNCMemAttr</a>();
        s2_memattrs.xs = walkstate.memattrs.xs;
        if walkstate.memattrs.tags == <a link="enum_MemTag_CanonicallyTagged" file="shared_pseudocode.xml">MemTag_CanonicallyTagged</a> then
            s2_memattrs.tags = <a link="enum_MemTag_CanonicallyTagged" file="shared_pseudocode.xml">MemTag_CanonicallyTagged</a>;
        end;
    else
        s2_memattrs = walkstate.memattrs;
    end;

    let s2aarch64 : boolean = TRUE;
    var memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>;
    if walkparams.fwb == '0' then
        memattrs = <a link="func_S2CombineS1MemAttrs_3" file="shared_pseudocode.xml">S2CombineS1MemAttrs</a>(ipa.memattrs, s2_memattrs, s2aarch64);
    else
        memattrs = s2_memattrs;
    end;

    var pa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_CreateAddressDescriptor_4" file="shared_pseudocode.xml">CreateAddressDescriptor</a>(ipa.vaddress, oa, memattrs, accdesc);
    pa.s2fs1mro = s2fs1mro;
    pa.mecid = <a link="func_AArch64_S2OutputMECID_4" file="shared_pseudocode.xml">AArch64_S2OutputMECID</a>{128}(walkparams, pa.paddress.paspace, descriptor);

    if (accdesc.acctype == <a link="enum_AccessType_TTW" file="shared_pseudocode.xml">AccessType_TTW</a> &amp;&amp; accdesc.atomicop &amp;&amp; !<a link="func_IsWBShareable_1" file="shared_pseudocode.xml">IsWBShareable</a>(pa.memattrs) &amp;&amp;
          <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_Unsupported_Atomic_HW_Update" file="shared_pseudocode.xml">Unpredictable_Unsupported_Atomic_HW_Update</a>)) then
        fault.statuscode = <a link="enum_Fault_UnsupportedAtomicHWUpdate" file="shared_pseudocode.xml">Fault_UnsupportedAtomicHWUpdate</a>;
        return (fault, pa);
    end;

    if (accdesc.acctype != <a link="enum_AccessType_TTW" file="shared_pseudocode.xml">AccessType_TTW</a> &amp;&amp; accdesc.atomicop &amp;&amp; !<a link="func_IsWBShareable_1" file="shared_pseudocode.xml">IsWBShareable</a>(pa.memattrs) &amp;&amp;
          <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_Atomic_MMU_IMPDEF_FAULT" file="shared_pseudocode.xml">Unpredictable_Atomic_MMU_IMPDEF_FAULT</a>)) then
        fault.statuscode = <a link="enum_Fault_Exclusive" file="shared_pseudocode.xml">Fault_Exclusive</a>;
        return (fault, pa);
    end;

    if accdesc.ls64 &amp;&amp; s2_memattrs.memtype == <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a> then
        if IsFeatureImplemented(FEAT_LS64WB) &amp;&amp; !accdesc.withstatus then
            if (!<a link="func_IsWBShareable_1" file="shared_pseudocode.xml">IsWBShareable</a>(s2_memattrs) &amp;&amp;
                  !(s2_memattrs.inner.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> &amp;&amp;
                    s2_memattrs.outer.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>) &amp;&amp;
                  (ImpDefBool(
                     &quot;LD64B or ST64B faults to cacheable non-iWBoWB memory&quot;))) then
                fault.statuscode = <a link="enum_Fault_Exclusive" file="shared_pseudocode.xml">Fault_Exclusive</a>;
                return (fault, pa);
            end;
        elsif !(s2_memattrs.inner.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> &amp;&amp; s2_memattrs.outer.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>) then
            fault.statuscode = <a link="enum_Fault_Exclusive" file="shared_pseudocode.xml">Fault_Exclusive</a>;
            return (fault, pa);
        end;
    end;

    return (fault, pa);
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_translation/AArch64_S2TreatAsNormalNC" mylink="aarch64.translation.vmsa_translation.AArch64_S2TreatAsNormalNC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2TreatAsNormalNC()
// ===========================
// Returns TRUE if stage 2 memory attributes should be treated as Normal Non-cacheable

func <anchor link="func_AArch64_S2TreatAsNormalNC_3">AArch64_S2TreatAsNormalNC</anchor>(walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>,
                               accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; boolean
begin
    return ((accdesc.acctype == <a link="enum_AccessType_TTW" file="shared_pseudocode.xml">AccessType_TTW</a> &amp;&amp;
               walkstate.memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> &amp;&amp; walkparams.ptw == '0') ||
            (accdesc.acctype == <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> &amp;&amp;
               (walkstate.memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> || HCR_EL2().ID == '1')) ||
            (accdesc.acctype != <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> &amp;&amp;
               walkstate.memattrs.memtype == <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a> &amp;&amp; !<a link="func_S2DCacheEnabled_0" file="shared_pseudocode.xml">S2DCacheEnabled</a>()));
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_translation/AArch64_SetAccessFlag" mylink="aarch64.translation.vmsa_translation.AArch64_SetAccessFlag" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SetAccessFlag()
// =======================
// Determine whether the access flag could be set by HW given the fault status

func <anchor link="func_AArch64_SetAccessFlag_4">AArch64_SetAccessFlag</anchor>(ha : bit, accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>, fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>,
                           fault_perm : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; boolean
begin
    if ha == '0' || !<a link="func_AArch64_SettingAccessFlagPermitted_2" file="shared_pseudocode.xml">AArch64_SettingAccessFlagPermitted</a>(fault, fault_perm) then
        return FALSE;
    elsif accdesc.acctype == <a link="enum_AccessType_AT" file="shared_pseudocode.xml">AccessType_AT</a> then
        return ImpDefBool(&quot;AT updates AF&quot;);
    elsif accdesc.acctype IN {<a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>, <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>} then
        return ImpDefBool(&quot;Generate access flag fault on IC/DC operations&quot;);
    else
        // Set descriptor AF bit
        return TRUE;
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_translation/AArch64_SetDirtyState" mylink="aarch64.translation.vmsa_translation.AArch64_SetDirtyState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SetDirtyState()
// =======================
// Determine whether dirty state is required to be updated by HW given the fault status

func <anchor link="func_AArch64_SetDirtyState_5">AArch64_SetDirtyState</anchor>(hd : bits(1), dbm : bits(1),
                           accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                           fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>,
                           fault_perm : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; boolean
begin
    if hd == '0' then
        return FALSE;
    elsif !<a link="func_AArch64_SettingDirtyStatePermitted_2" file="shared_pseudocode.xml">AArch64_SettingDirtyStatePermitted</a>(fault, fault_perm) then
        return FALSE;
    elsif accdesc.acctype IN {<a link="enum_AccessType_AT" file="shared_pseudocode.xml">AccessType_AT</a>, <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>, <a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>} then
        return FALSE;
    elsif !accdesc.write then
        return FALSE;
    else
        return dbm == '1';
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_translation/AArch64_SettingAccessFlagPermitted" mylink="aarch64.translation.vmsa_translation.AArch64_SettingAccessFlagPermitted" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SettingAccessFlagPermitted()
// ====================================
// Determine whether the access flag could be set by HW given the fault status

func <anchor link="func_AArch64_SettingAccessFlagPermitted_2">AArch64_SettingAccessFlagPermitted</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, fault_perm : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; boolean
begin
    if fault.statuscode == <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> &amp;&amp; fault_perm.statuscode == <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        return TRUE;
    elsif fault.statuscode == <a link="enum_Fault_Alignment" file="shared_pseudocode.xml">Fault_Alignment</a> || fault_perm.statuscode == <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a> then
        return <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_AFUPDATE" file="shared_pseudocode.xml">Unpredictable_AFUPDATE</a>);
    else
        return FALSE;
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_translation/AArch64_SettingDirtyStatePermitted" mylink="aarch64.translation.vmsa_translation.AArch64_SettingDirtyStatePermitted" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SettingDirtyStatePermitted()
// ====================================
// Determine whether the dirty state could be set by HW given the fault status

func <anchor link="func_AArch64_SettingDirtyStatePermitted_2">AArch64_SettingDirtyStatePermitted</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, fault_perm : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; boolean
begin
    if fault_perm.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        return FALSE;
    elsif fault.statuscode == <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        return TRUE;
    elsif fault.statuscode == <a link="enum_Fault_Alignment" file="shared_pseudocode.xml">Fault_Alignment</a> then
        return <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_DBUPDATE" file="shared_pseudocode.xml">Unpredictable_DBUPDATE</a>);
    else
        return FALSE;
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_translation/AArch64_TranslateAddress" mylink="aarch64.translation.vmsa_translation.AArch64_TranslateAddress" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TranslateAddress()
// ==========================
// Main entry point for translating an address

func <anchor link="func_AArch64_TranslateAddress_4">AArch64_TranslateAddress</anchor>(va : bits(64), accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                              aligned : boolean, size : integer) =&gt; <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>
begin
    if (<a link="global_SPESampleInFlight" file="shared_pseudocode.xml">SPESampleInFlight</a> &amp;&amp;
        !(accdesc.acctype IN {<a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a>, <a link="enum_AccessType_SPE" file="shared_pseudocode.xml">AccessType_SPE</a>, <a link="enum_AccessType_TRBE" file="shared_pseudocode.xml">AccessType_TRBE</a>})) then
        <a link="func_SPEStartCounter_1" file="shared_pseudocode.xml">SPEStartCounter</a>(<a link="global_SPECounterPosTranslationLatency" file="shared_pseudocode.xml">SPECounterPosTranslationLatency</a>);
    end;

    var result : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_AArch64_FullTranslate_4" file="shared_pseudocode.xml">AArch64_FullTranslate</a>(va, size, accdesc, aligned);

    if !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(result) &amp;&amp; accdesc.acctype != <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a> then
        // For an instruction fetch, CheckDebug will be called
        // after the instruction is read from memory
        result.fault = <a link="func_AArch64_CheckDebug_3" file="shared_pseudocode.xml">AArch64_CheckDebug</a>(va, accdesc, size);
    end;

    if (IsFeatureImplemented(FEAT_RME) &amp;&amp; !<a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(result) &amp;&amp;
          <a link="func_IsGranuleProtectionCheckedAccess_1" file="shared_pseudocode.xml">IsGranuleProtectionCheckedAccess</a>(accdesc)) then
        result.fault.gpcf = <a link="func_GranuleProtectionCheck_2" file="shared_pseudocode.xml">GranuleProtectionCheck</a>(result, accdesc);

        if result.fault.gpcf.gpf != <a link="enum_GPCF_None" file="shared_pseudocode.xml">GPCF_None</a> then
            result.fault.statuscode = <a link="enum_Fault_GPCFOnOutput" file="shared_pseudocode.xml">Fault_GPCFOnOutput</a>;
            result.fault.paddress   = result.paddress;
            result.fault.vaddress   = result.vaddress;
        end;
    end;
    if <a link="global_SPESampleInFlight" file="shared_pseudocode.xml">SPESampleInFlight</a> &amp;&amp;
        !(accdesc.acctype IN {<a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a>, <a link="enum_AccessType_TRBE" file="shared_pseudocode.xml">AccessType_TRBE</a>, <a link="enum_AccessType_SPE" file="shared_pseudocode.xml">AccessType_SPE</a>}) then
        <a link="func_SPEStopCounter_1" file="shared_pseudocode.xml">SPEStopCounter</a>(<a link="global_SPECounterPosTranslationLatency" file="shared_pseudocode.xml">SPECounterPosTranslationLatency</a>);
    end;

    // Update virtual address for abort functions
    result.vaddress = ZeroExtend{64}(va);

    return result;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_translation/AArch64_TranslateTagAddress" mylink="aarch64.translation.vmsa_translation.AArch64_TranslateTagAddress" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_TranslateTagAddress()
// =============================
// Translate an address for accessing an Allocation Tag.

func <anchor link="func_AArch64_TranslateTagAddress_4">AArch64_TranslateTagAddress</anchor>(va : bits(64),
                                 accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                                 aligned : boolean,
                                 size : integer) =&gt; (<a link="type_MemTagType" file="shared_pseudocode.xml">MemTagType</a>, <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>)
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = accdesc_in;
    let taddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a> = <a link="func_AArch64_TranslateAddress_4" file="shared_pseudocode.xml">AArch64_TranslateAddress</a>(va, accdesc, aligned, size);

    return (taddrdesc.memattrs.tags, taddrdesc);
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_ttentry/AArch64_BlockDescSupported" mylink="aarch64.translation.vmsa_ttentry.AArch64_BlockDescSupported" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_BlockDescSupported()
// ============================
// Determine whether a block descriptor is valid for the given granule size
// and level

func <anchor link="func_AArch64_BlockDescSupported_4">AArch64_BlockDescSupported</anchor>(d128 : bit, ds : bit, tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>, level : integer) =&gt; boolean
begin
    case tgx of
        when <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a> =&gt; return ((level == 0 &amp;&amp; (ds == '1' || d128 == '1')) ||
                                level == 1 ||
                                level == 2);
        when <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a> =&gt; return ((level == 1 &amp;&amp; (ds == '1' || d128 == '1')) ||
                                  level == 2);
        when <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> =&gt; return ((level == 1 &amp;&amp; (d128 == '1' || <a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>() &gt;= 52)) ||
                                  level == 2);
    end;
    return FALSE;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_ttentry/AArch64_ContiguousBit" mylink="aarch64.translation.vmsa_ttentry.AArch64_ContiguousBit" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ContiguousBit()
// =======================
// Get the value of the contiguous bit

func <anchor link="func_AArch64_ContiguousBit_5">AArch64_ContiguousBit</anchor>{N}(tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>, d128 : bit, level : integer, descriptor : bits(N)) =&gt; bit
begin
    if ImpDefBool(&quot;Treat Contiguous bit as 0&quot;) then
        return '0';
    end;

    if d128 == '1' then
        if (tgx == <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> &amp;&amp; level == 1) || (tgx == <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a> &amp;&amp; level == 0) then
            return '0'; // RES0
        else
            return descriptor[111];
        end;
    end;
    // When using TGx 64KB then the Contiguous bit is RES0 for Block
    // descriptors at level 1. For VMSAv8-64, level 1 Block descriptors
    // can exist only if FEAT_LPA is implemented.

    if tgx == <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> &amp;&amp; level == 1 then
        return '0'; // RES0
    end;

    // When the Effective value of TCR_ELx.DS is '1',
    // the Contiguous bit is RES0 for all the following:
    //      * For TGx 4KB, Block descriptors at level 0
    //      * For TGx 16KB, Block descriptors at level 1
    // For VMSAv8-64, the above Block descriptors at the specified
    // levels can exist only if the Effective value of TCR_ELx.DS is 1.

    if tgx == <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a> &amp;&amp; level == 1 then
        return '0'; // RES0
    end;

    if tgx == <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>  &amp;&amp; level == 0 then
        return '0'; // RES0
    end;

    return descriptor[52];
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_ttentry/AArch64_DecodeDescriptorType" mylink="aarch64.translation.vmsa_ttentry.AArch64_DecodeDescriptorType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_DecodeDescriptorType()
// ==============================
// Determine whether the descriptor is a page, block or table

func <anchor link="func_AArch64_DecodeDescriptorType_6">AArch64_DecodeDescriptorType</anchor>{N}(descriptor : bits(N), d128 : bit, ds : bit,
                                     tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>, level : integer) =&gt; <a link="type_DescriptorType" file="shared_pseudocode.xml">DescriptorType</a>
begin
    if descriptor[0] == '0' then
        return <a link="enum_DescriptorType_Invalid" file="shared_pseudocode.xml">DescriptorType_Invalid</a>;
    elsif d128 == '1' then
        let skl : bits(2) = descriptor[110:109];
        if tgx IN {<a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a>, <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a>} &amp;&amp; UInt(skl) == 3 then
            return <a link="enum_DescriptorType_Invalid" file="shared_pseudocode.xml">DescriptorType_Invalid</a>;
        end;

        let effective_level : integer = level + UInt(skl);
        if effective_level &gt; <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> then
            return <a link="enum_DescriptorType_Invalid" file="shared_pseudocode.xml">DescriptorType_Invalid</a>;
        elsif effective_level == <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> then
            return <a link="enum_DescriptorType_Leaf" file="shared_pseudocode.xml">DescriptorType_Leaf</a>;
        else
            return <a link="enum_DescriptorType_Table" file="shared_pseudocode.xml">DescriptorType_Table</a>;
        end;
    else
        if descriptor[1] == '1' then
            if level == <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> then
                return <a link="enum_DescriptorType_Leaf" file="shared_pseudocode.xml">DescriptorType_Leaf</a>;
            else
                return <a link="enum_DescriptorType_Table" file="shared_pseudocode.xml">DescriptorType_Table</a>;
            end;
        elsif descriptor[1] == '0' then
            if <a link="func_AArch64_BlockDescSupported_4" file="shared_pseudocode.xml">AArch64_BlockDescSupported</a>(d128, ds, tgx, level) then
                return <a link="enum_DescriptorType_Leaf" file="shared_pseudocode.xml">DescriptorType_Leaf</a>;
            else
                return <a link="enum_DescriptorType_Invalid" file="shared_pseudocode.xml">DescriptorType_Invalid</a>;
            end;
        end;
        unreachable;
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_ttentry/AArch64_S1ApplyOutputPerms" mylink="aarch64.translation.vmsa_ttentry.AArch64_S1ApplyOutputPerms" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1ApplyOutputPerms()
// ============================
// Apply output permissions encoded in stage 1 page/block descriptors

func <anchor link="func_AArch64_S1ApplyOutputPerms_5">AArch64_S1ApplyOutputPerms</anchor>{N}(permissions_in : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a>, descriptor : bits(N),
                                   regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>) =&gt; <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a>
begin
    var permissions : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a> = permissions_in;

    var pi_index : bits (4);
    if walkparams.pie == '1' then
        if walkparams.d128 == '1' then
            pi_index = descriptor[118:115];
        else
            pi_index = descriptor[54:53]::descriptor[51]::descriptor[6];
        end;
        permissions.ppi    = walkparams.pir[UInt(pi_index)*:4];
        permissions.upi    = walkparams.pire0[UInt(pi_index)*:4];
        permissions.ndirty = descriptor[7];
    else
        if regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; walkparams.nv1 == '1' then
            permissions.ap[2:1] = descriptor[7]::'0';
            permissions.pxn     = descriptor[54];
        elsif <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) then
            permissions.ap[2:1] = descriptor[7:6];
            permissions.uxn     = descriptor[54];
            permissions.pxn     = descriptor[53];
        else
            permissions.ap[2:1] = descriptor[7]::'1';
            permissions.xn      = descriptor[54];
        end;
        permissions.dbm = descriptor[51];
    end;
    if IsFeatureImplemented(FEAT_S1POE) then
        if walkparams.d128 == '1' then
            permissions.po_index[3:0] = descriptor[124:121];
        else
            permissions.po_index[3:0] = '0'::descriptor[62:60];
        end;
    end;

    return permissions;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_ttentry/AArch64_S1ApplyTablePerms" mylink="aarch64.translation.vmsa_ttentry.AArch64_S1ApplyTablePerms" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1ApplyTablePerms()
// ===========================
// Apply hierarchical permissions encoded in stage 1 table descriptors

func <anchor link="func_AArch64_S1ApplyTablePerms_4">AArch64_S1ApplyTablePerms</anchor>(permissions_in : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a>, descriptor : bits(64),
                               regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>) =&gt; <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a>
begin
    var permissions : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a> = permissions_in;
    var ap_table : bits(2);
    var pxn_table : bit;
    var uxn_table : bit;
    var xn_table : bit;
    if regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; walkparams.nv1 == '1' then
        ap_table  = descriptor[62]::'0';
        pxn_table = descriptor[60];
        permissions.ap_table  = permissions.ap_table  OR ap_table;
        permissions.pxn_table = permissions.pxn_table OR pxn_table;

    elsif <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) then
        ap_table  = descriptor[62:61];
        uxn_table = descriptor[60];
        pxn_table = descriptor[59];
        permissions.ap_table  = permissions.ap_table  OR ap_table;
        permissions.uxn_table = permissions.uxn_table OR uxn_table;
        permissions.pxn_table = permissions.pxn_table OR pxn_table;
    else
        ap_table = descriptor[62]::'0';
        xn_table = descriptor[60];
        permissions.ap_table = permissions.ap_table OR ap_table;
        permissions.xn_table = permissions.xn_table OR xn_table;
    end;

    return permissions;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_ttentry/AArch64_S2ApplyOutputPerms" mylink="aarch64.translation.vmsa_ttentry.AArch64_S2ApplyOutputPerms" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2ApplyOutputPerms()
// ============================
// Apply output permissions encoded in stage 2 page/block descriptors

func <anchor link="func_AArch64_S2ApplyOutputPerms_3">AArch64_S2ApplyOutputPerms</anchor>{N}(descriptor : bits(N), walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>) =&gt; <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a>
begin
    var permissions : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a>;
    var s2pi_index : bits(4);
    if walkparams.s2pie == '1' then
        if walkparams.d128 == '1' then
            s2pi_index = descriptor[118:115];
        else
            s2pi_index = descriptor[54:53,51,6];
        end;
        permissions.s2pi = walkparams.s2pir[UInt(s2pi_index)*:4];
        permissions.s2dirty = descriptor[7];
    else
        permissions.s2ap = descriptor[7:6];
        if walkparams.d128 == '1' then
            permissions.s2xn = descriptor[118];
        else
            permissions.s2xn = descriptor[54];
        end;

        if IsFeatureImplemented(FEAT_XNX) then
            if walkparams.d128 == '1' then
                permissions.s2xnx = descriptor[117];
            else
                permissions.s2xnx = descriptor[53];
            end;
        else
            permissions.s2xnx = '0';
        end;

        permissions.dbm = descriptor[51];
    end;
    if IsFeatureImplemented(FEAT_S2POE) then
        if walkparams.d128 == '1' then
            permissions.s2po_index = descriptor[124:121];
        else
            permissions.s2po_index = descriptor[62:59];
        end;
    end;
    return permissions;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_ttentry/AArch64_nTFaults" mylink="aarch64.translation.vmsa_ttentry.AArch64_nTFaults" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_nTFaults()
// ==================
// Identify whether the nT bit in a block or table descriptor is effectively set
// causing a translation fault

func <anchor link="func_AArch64_nTFaults_3">AArch64_nTFaults</anchor>{N}(d128 : bit, descriptor : bits(N)) =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_BBML1) then
        return FALSE;
    end;
    let nT : bit = if d128 == '1' then descriptor[6] else descriptor[16];

    return nT == '1' &amp;&amp; ImpDefBool(&quot;nT bit causes Translation Fault&quot;);
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walk/AArch64_S1InitialTTWState" mylink="aarch64.translation.vmsa_walk.AArch64_S1InitialTTWState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1InitialTTWState()
// ===========================
// Set properties of first access to translation tables in stage 1

func <anchor link="func_AArch64_S1InitialTTWState_4">AArch64_S1InitialTTWState</anchor>(walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>, va : bits(64), regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
                               ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>) =&gt; <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>
begin
    var walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>;
    var tablebase : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    var permissions : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a>;
    var ttbr : bits(128);

    ttbr              = <a link="func_AArch64_S1TTBR_2" file="shared_pseudocode.xml">AArch64_S1TTBR</a>(regime, va);
    case ss of
        when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;    tablebase.paspace = <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>;
        when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt; tablebase.paspace = <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
        when <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a> =&gt;      tablebase.paspace = <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>;
        when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;     tablebase.paspace = <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>;
    end;

    tablebase.address = <a link="func_AArch64_S1TTBaseAddress_4" file="shared_pseudocode.xml">AArch64_S1TTBaseAddress</a>{128}(walkparams, regime, ttbr);

    permissions.ap_table = '00';
    if <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) then
        permissions.uxn_table = '0';
        permissions.pxn_table = '0';
    else
        permissions.xn_table  = '0';
    end;

    walkstate.baseaddress = tablebase;
    walkstate.level       = <a link="func_AArch64_S1StartLevel_1" file="shared_pseudocode.xml">AArch64_S1StartLevel</a>(walkparams);
    walkstate.istable     = TRUE;
    // In regimes that support global and non-global translations, translation
    // table entries from lookup levels other than the final level of lookup
    // are treated as being non-global
    walkstate.nG          = if <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) then '1' else '0';
    walkstate.memattrs    = <a link="func_WalkMemAttrs_3" file="shared_pseudocode.xml">WalkMemAttrs</a>(walkparams.sh, walkparams.irgn, walkparams.orgn);
    walkstate.permissions = permissions;
    if regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().VM == '1' then
        if ((<a link="func_AArch64_GetVARange_1" file="shared_pseudocode.xml">AArch64_GetVARange</a>(va) == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> &amp;&amp; VTCR_EL2().TL0 == '1') ||
            (<a link="func_AArch64_GetVARange_1" file="shared_pseudocode.xml">AArch64_GetVARange</a>(va) == <a link="enum_VARange_UPPER" file="shared_pseudocode.xml">VARange_UPPER</a> &amp;&amp; VTCR_EL2().TL1 == '1')) then
            walkstate.s1assured = TRUE;
        else
            walkstate.s1assured = FALSE;
        end;
    else
        walkstate.s1assured = FALSE;
    end;
    walkstate.disch = walkparams.disch;

    return walkstate;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walk/AArch64_S1NextWalkStateLeaf" mylink="aarch64.translation.vmsa_walk.AArch64_S1NextWalkStateLeaf" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1NextWalkStateLeaf()
// =============================
// Decode stage 1 page or block descriptor as output to this stage of translation

func <anchor link="func_AArch64_S1NextWalkStateLeaf_7">AArch64_S1NextWalkStateLeaf</anchor>{N}(currentstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, s2fs1mro : boolean, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
                                    accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>, walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>,
                                    descriptor : bits(N)) =&gt; <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>
begin
    var nextstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>;
    var baseaddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    baseaddress.address = <a link="func_AArch64_S1LeafBase_4" file="shared_pseudocode.xml">AArch64_S1LeafBase</a>{N}(descriptor, walkparams, currentstate.level);

    if currentstate.baseaddress.paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> then
        // Determine PA space of the block from NS bit
        let ns : bit = if walkparams.d128 == '1' then descriptor[127] else descriptor[5];
        baseaddress.paspace = if ns == '0' then <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> else <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
    elsif currentstate.baseaddress.paspace == <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a> then
        // Determine PA space of the block from NSE and NS bits
        let ns : bit = if walkparams.d128 == '1' then descriptor[127] else descriptor[5];
        let nse : bit = descriptor[11];
        let nse2 : bit = '0';     // NSE2 has the Effective value of 0 within a PE.
        baseaddress.paspace = <a link="func_DecodePASpace_3" file="shared_pseudocode.xml">DecodePASpace</a>(nse2, nse, ns);

        // If Secure state is not implemented, but RME is,
        // force Secure space accesses to Non-secure space
        if baseaddress.paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> &amp;&amp; !<a link="func_HaveSecureState_0" file="shared_pseudocode.xml">HaveSecureState</a>() then
            baseaddress.paspace = <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
        end;

    elsif (currentstate.baseaddress.paspace == <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a> &amp;&amp;
            regime IN {<a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a>, <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>}) then
        // Realm EL2 and EL2&amp;0 regimes have a stage 1 NS bit
        let ns : bit = if walkparams.d128 == '1' then descriptor[127] else descriptor[5];
        baseaddress.paspace = if ns == '0' then <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a> else <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
    elsif currentstate.baseaddress.paspace == <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a> then
        // Realm EL1&amp;0 regime does not have a stage 1 NS bit
        baseaddress.paspace = <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>;
    else
        baseaddress.paspace = <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
    end;

    nextstate.istable     = FALSE;
    nextstate.level       = currentstate.level;
    nextstate.baseaddress = baseaddress;

    var attrindx : bits(4);
    if walkparams.aie == '1' then
        if walkparams.d128 == '1' then
            attrindx = descriptor[5:2];
        else
            attrindx = descriptor[59,4:2];
        end;
    else
        attrindx = '0'::descriptor[4:2];
    end;

    var sh : bits(2);
    if walkparams.d128 == '1' then
        sh = descriptor[9:8];
    elsif walkparams.ds == '1' then
        sh = walkparams.sh;
    else
        sh = descriptor[9:8];
    end;
    let attr : bits(8) = <a link="func_AArch64_MAIRAttr_3" file="shared_pseudocode.xml">AArch64_MAIRAttr</a>(UInt(attrindx), walkparams.mair2, walkparams.mair);
    let s1aarch64 : boolean = TRUE;

    nextstate.memattrs = <a link="func_S1DecodeMemAttrs_5" file="shared_pseudocode.xml">S1DecodeMemAttrs</a>(attr, sh, s1aarch64, walkparams, accdesc.acctype);
    nextstate.permissions = <a link="func_AArch64_S1ApplyOutputPerms_5" file="shared_pseudocode.xml">AArch64_S1ApplyOutputPerms</a>{N}(currentstate.permissions,
                                                       descriptor, regime, walkparams);
    var protectedbit : bit;
    if walkparams.d128 == '1' then
        protectedbit = descriptor[114];
    else
        protectedbit = if walkparams.pnch == '1' then descriptor[52] else '0';
    end;
    if (currentstate.s1assured &amp;&amp; s2fs1mro &amp;&amp; protectedbit == '1') then
        nextstate.s1assured = TRUE;
    else
        nextstate.s1assured = FALSE;
    end;

    if walkparams.pnch == '1' || currentstate.disch == '1' then
        nextstate.contiguous = '0';
    else
        nextstate.contiguous = <a link="func_AArch64_ContiguousBit_5" file="shared_pseudocode.xml">AArch64_ContiguousBit</a>{N}(walkparams.tgx, walkparams.d128,
                                                        currentstate.level, descriptor);
    end;
    if !<a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) then
        nextstate.nG = '0';
    elsif accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> &amp;&amp; currentstate.baseaddress.paspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> then
        // In Secure state, a translation must be treated as non-global,
        // regardless of the value of the nG bit,
        // if NSTable is set to 1 at any level of the translation table walk
        nextstate.nG = '1';
    elsif walkparams.fng == '1' then
        // Translations are treated as non-global regardless of the value of the nG bit.
        nextstate.nG = '1';
    elsif (regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().VM == '1' &amp;&amp;
            (walkparams.d128 == '1' || walkparams.pnch == '1') &amp;&amp;
            !nextstate.s1assured &amp;&amp; walkparams.fngna == '1') then
        // Translations are treated as non-global regardless of the value of the nG bit.
        nextstate.nG = '1';
    else
        nextstate.nG = descriptor[11];
    end;

    if walkparams.d128 == '1' then
        nextstate.guardedpage = descriptor[113];
    else
        nextstate.guardedpage = descriptor[50];
    end;

    return nextstate;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walk/AArch64_S1NextWalkStateTable" mylink="aarch64.translation.vmsa_walk.AArch64_S1NextWalkStateTable" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1NextWalkStateTable()
// ==============================
// Decode stage 1 table descriptor to transition to the next level

func <anchor link="func_AArch64_S1NextWalkStateTable_6">AArch64_S1NextWalkStateTable</anchor>{N}(currentstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, s2fs1mro : boolean, regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
                                     walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>, descriptor : bits(N)) =&gt; <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>
begin
    var nextstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>;
    var tablebase : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    let skl : bits(2) = if walkparams.d128 == '1' then descriptor[110:109] else '00';
    tablebase.address = <a link="func_AArch64_NextTableBase_6" file="shared_pseudocode.xml">AArch64_NextTableBase</a>{N}(descriptor, walkparams.d128, skl, walkparams.ds,
                                                 walkparams.tgx);

    if currentstate.baseaddress.paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> then
        // Determine PA space of the next table from NSTable bit
        var nstable : bit;
        nstable = if walkparams.d128 == '1' then descriptor[127] else descriptor[63];
        tablebase.paspace = if nstable == '0' then <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> else <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
    else
        // Otherwise bit 63 is RES0 and there is no NSTable bit
        tablebase.paspace = currentstate.baseaddress.paspace;
    end;

    nextstate.istable     = TRUE;
    nextstate.nG          = currentstate.nG;
    if walkparams.d128 == '1' then
        nextstate.level   = currentstate.level + UInt(skl) + 1;
    else
        nextstate.level   = currentstate.level + 1;
    end;
    nextstate.baseaddress = tablebase;
    nextstate.memattrs    = currentstate.memattrs;
    if walkparams.hpd == '0' &amp;&amp; walkparams.pie == '0' then
        nextstate.permissions = <a link="func_AArch64_S1ApplyTablePerms_4" file="shared_pseudocode.xml">AArch64_S1ApplyTablePerms</a>(currentstate.permissions,
                                                          descriptor[63:0], regime, walkparams);
    else
        nextstate.permissions = currentstate.permissions;
    end;
    var protectedbit : bit;
    if walkparams.d128 == '1' then
        protectedbit = descriptor[114];
    else
        protectedbit = if walkparams.pnch == '1' then descriptor[52] else '0';
    end;
    if (currentstate.s1assured &amp;&amp; s2fs1mro &amp;&amp; protectedbit == '1') then
        nextstate.s1assured = TRUE;
    else
        nextstate.s1assured = FALSE;
    end;
    nextstate.disch = if walkparams.d128 == '1' then descriptor[112] else '0';

    return nextstate;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walk/AArch64_S1Walk" mylink="aarch64.translation.vmsa_walk.AArch64_S1Walk" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1Walk()
// ================
// Traverse stage 1 translation tables obtaining the final descriptor
// as well as the address leading to that descriptor

func <anchor link="func_AArch64_S1Walk_6">AArch64_S1Walk</anchor>{N : integer{64, 128}}(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>,
                                          walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>,
                                          va : bits(64), regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
                                          accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
                                         ) =&gt; (<a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, bits(N))
begin
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;
    var aligned : boolean;

    if <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) &amp;&amp; <a link="func_AArch64_S1EPD_2" file="shared_pseudocode.xml">AArch64_S1EPD</a>(regime, va) == '1' then
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
        fault.level      = 0;
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, ARBITRARY : bits(N));
    end;

    var walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a> = <a link="func_AArch64_S1InitialTTWState_4" file="shared_pseudocode.xml">AArch64_S1InitialTTWState</a>(walkparams, va, regime, accdesc.ss);
    let startlevel : integer = walkstate.level;

    if startlevel &gt; 3 then
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
        fault.level      = 0;
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, ARBITRARY : bits(N));
    end;

    var descriptor : bits(N);
    var walkaddress : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    var skl : bits(2) = '00';
    walkaddress.vaddress = va;
    walkaddress.mecid = <a link="func_AArch64_S1TTWalkMECID_3" file="shared_pseudocode.xml">AArch64_S1TTWalkMECID</a>(walkparams.emec, regime, accdesc.ss);

    if !<a link="func_AArch64_S1DCacheEnabled_1" file="shared_pseudocode.xml">AArch64_S1DCacheEnabled</a>(regime) then
        walkaddress.memattrs = <a link="func_NormalNCMemAttr_0" file="shared_pseudocode.xml">NormalNCMemAttr</a>();
        walkaddress.memattrs.xs = walkstate.memattrs.xs;
    else
        walkaddress.memattrs = walkstate.memattrs;
    end;

    // Shareability value of stage 1 translation subject to stage 2 is IMPLEMENTATION DEFINED
    // to be either effective value or descriptor value
    if (regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().VM == '1' &amp;&amp;
            !(ImpDefBool(&quot;Apply effective shareability at stage 1&quot;))) then
        walkaddress.memattrs.shareability = walkstate.memattrs.shareability;
    else
        walkaddress.memattrs.shareability = <a link="func_EffectiveShareability_1" file="shared_pseudocode.xml">EffectiveShareability</a>(walkaddress.memattrs);
    end;

    var s2fs1mro : boolean = FALSE;

    var desctype : <a link="type_DescriptorType" file="shared_pseudocode.xml">DescriptorType</a>;
    var descaddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a> = <a link="func_AArch64_S1SLTTEntryAddress_4" file="shared_pseudocode.xml">AArch64_S1SLTTEntryAddress</a>(walkstate.level, walkparams, va,
                                                         walkstate.baseaddress);

    // Detect Address Size Fault by Descriptor Address
    if <a link="func_AArch64_S1OAOutOfRange_2" file="shared_pseudocode.xml">AArch64_S1OAOutOfRange</a>(descaddress.address, walkparams) then
        fault.statuscode = <a link="enum_Fault_AddressSize" file="shared_pseudocode.xml">Fault_AddressSize</a>;
        fault.level      = 0;
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, ARBITRARY : bits(N));
    end;

    repeat
        fault.level = walkstate.level;
        walkaddress.paddress = descaddress;
        walkaddress.s1assured = walkstate.s1assured;

        let toplevel : boolean = walkstate.level == startlevel;
        let varange : <a link="type_VARange" file="shared_pseudocode.xml">VARange</a>  = <a link="func_AArch64_GetVARange_1" file="shared_pseudocode.xml">AArch64_GetVARange</a>(va);
        let walkaccess : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescS1TTW_3" file="shared_pseudocode.xml">CreateAccDescS1TTW</a>(toplevel, varange, accdesc);
        var s2fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>;
        var s2walkaddress : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
        if regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
            let s1aarch64 : boolean = TRUE;
            aligned   = TRUE;
            (s2fault, s2walkaddress) = <a link="func_AArch64_S2Translate_5" file="shared_pseudocode.xml">AArch64_S2Translate</a>(fault, walkaddress, s1aarch64, aligned,
                                                           walkaccess);

            if s2fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
                return (s2fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>,
                        ARBITRARY : bits(N));
            end;

            s2fs1mro = s2walkaddress.s2fs1mro;
            (fault, descriptor) = <a link="func_FetchDescriptor_5" file="shared_pseudocode.xml">FetchDescriptor</a>{N}(walkparams.ee, s2walkaddress, walkaccess,
                                                    fault);
        else
            (fault, descriptor) = <a link="func_FetchDescriptor_5" file="shared_pseudocode.xml">FetchDescriptor</a>{N}(walkparams.ee, walkaddress, walkaccess,
                                                     fault);
        end;

        if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
            return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>,
                    ARBITRARY : bits(N));
        end;

        var new_descriptor : bits(N);
        repeat
            new_descriptor = descriptor;
            desctype = <a link="func_AArch64_DecodeDescriptorType_6" file="shared_pseudocode.xml">AArch64_DecodeDescriptorType</a>{N}(descriptor, walkparams.d128, walkparams.ds,
                                                       walkparams.tgx, walkstate.level);
            case desctype of
                when <a link="enum_DescriptorType_Table" file="shared_pseudocode.xml">DescriptorType_Table</a> =&gt;
                    walkstate = <a link="func_AArch64_S1NextWalkStateTable_6" file="shared_pseudocode.xml">AArch64_S1NextWalkStateTable</a>{N}(walkstate, s2fs1mro,
                                                                regime, walkparams, descriptor);
                    skl = if walkparams.d128 == '1' then descriptor[110:109] else '00';
                    descaddress = <a link="func_AArch64_S1TTEntryAddress_7" file="shared_pseudocode.xml">AArch64_S1TTEntryAddress</a>{N}(walkstate.level, walkparams, skl, va,
                                                              walkstate.baseaddress, descriptor);

                    // Detect Address Size Fault by Descriptor Address
                    if <a link="func_AArch64_S1OAOutOfRange_2" file="shared_pseudocode.xml">AArch64_S1OAOutOfRange</a>(descaddress.address, walkparams) then
                        fault.statuscode = <a link="enum_Fault_AddressSize" file="shared_pseudocode.xml">Fault_AddressSize</a>;
                        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>,
                                ARBITRARY : bits(N));
                    end;

                    if walkparams.haft == '1' then
                        new_descriptor[10] = '1';
                    end;
                    if (walkparams.d128 == '1' &amp;&amp; skl != '00' &amp;&amp;
                          <a link="func_AArch64_nTFaults_3" file="shared_pseudocode.xml">AArch64_nTFaults</a>{N}(walkparams.d128, descriptor)) then
                        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
                        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>,
                                ARBITRARY : bits(N));
                    end;
                when <a link="enum_DescriptorType_Leaf" file="shared_pseudocode.xml">DescriptorType_Leaf</a> =&gt;
                    walkstate = <a link="func_AArch64_S1NextWalkStateLeaf_7" file="shared_pseudocode.xml">AArch64_S1NextWalkStateLeaf</a>{N}(walkstate, s2fs1mro, regime, accdesc,
                                                               walkparams, descriptor);
                when <a link="enum_DescriptorType_Invalid" file="shared_pseudocode.xml">DescriptorType_Invalid</a> =&gt;
                    fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
                    return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>,
                            ARBITRARY : bits(N));
                otherwise =&gt;
                    unreachable;
            end;

            if new_descriptor != descriptor then

                if (!<a link="func_IsWBShareable_1" file="shared_pseudocode.xml">IsWBShareable</a>(walkaddress.memattrs) &amp;&amp;
                      <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_Unsupported_Atomic_HW_Update" file="shared_pseudocode.xml">Unpredictable_Unsupported_Atomic_HW_Update</a>)) then
                    fault.statuscode = <a link="enum_Fault_UnsupportedAtomicHWUpdate" file="shared_pseudocode.xml">Fault_UnsupportedAtomicHWUpdate</a>;
                    return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>,
                            ARBITRARY : bits(N));
                end;

                var descpaddr : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
                let descaccess : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescTTEUpdate_1" file="shared_pseudocode.xml">CreateAccDescTTEUpdate</a>(accdesc);
                if regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
                    let s1aarch64 : boolean = TRUE;
                    aligned   = TRUE;
                    (s2fault, descpaddr) = <a link="func_AArch64_S2Translate_5" file="shared_pseudocode.xml">AArch64_S2Translate</a>(fault, walkaddress,
                                                               s1aarch64, aligned,
                                                               descaccess);

                    if s2fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
                        return (s2fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                                ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, ARBITRARY : bits(N));
                    end;
                else
                    descpaddr = walkaddress;
                end;

                (fault, descriptor) = <a link="func_AArch64_MemSwapTableDesc_7" file="shared_pseudocode.xml">AArch64_MemSwapTableDesc</a>{N}(fault, descriptor, new_descriptor,
                                                                  walkparams.ee, descaccess,
                                                                  descpaddr);
                if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
                    return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                            ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, ARBITRARY : bits(N));
                end;
            end;
        until new_descriptor == descriptor looplimit Unbounded_DescriptorUpdate;
    until desctype == <a link="enum_DescriptorType_Leaf" file="shared_pseudocode.xml">DescriptorType_Leaf</a> looplimit MAX_WALK_LEVELS;

    let oa : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a> = <a link="func_StageOA_4" file="shared_pseudocode.xml">StageOA</a>(va, walkparams.d128, walkparams.tgx, walkstate);
    if (walkstate.contiguous == '1' &amp;&amp;
        <a link="func_AArch64_ContiguousBitFaults_4" file="shared_pseudocode.xml">AArch64_ContiguousBitFaults</a>(walkparams.d128, walkparams.txsz, walkparams.tgx,
                                    walkstate.level)) then
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
    elsif walkstate.level &lt; <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> &amp;&amp; <a link="func_AArch64_nTFaults_3" file="shared_pseudocode.xml">AArch64_nTFaults</a>{N}(walkparams.d128, descriptor) then
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
    elsif <a link="func_AArch64_S1AMECFault_5" file="shared_pseudocode.xml">AArch64_S1AMECFault</a>{N}(walkparams, walkstate.baseaddress.paspace, regime, descriptor) then
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
    // Detect Address Size Fault by final output
    elsif <a link="func_AArch64_S1OAOutOfRange_2" file="shared_pseudocode.xml">AArch64_S1OAOutOfRange</a>(oa.address, walkparams) then
        fault.statuscode = <a link="enum_Fault_AddressSize" file="shared_pseudocode.xml">Fault_AddressSize</a>;
    // Check descriptor AF bit
    elsif (descriptor[10] == '0' &amp;&amp; walkparams.ha == '0' &amp;&amp;
            (!accdesc.acctype IN {<a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>, <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>} ||
             ImpDefBool(&quot;Generate access flag fault on IC/DC operations&quot;))) then
        fault.statuscode = <a link="enum_Fault_AccessFlag" file="shared_pseudocode.xml">Fault_AccessFlag</a>;
    end;

    if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, ARBITRARY : bits(N));
    end;

    return (fault, walkaddress, walkstate, descriptor);
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walk/AArch64_S2InitialTTWState" mylink="aarch64.translation.vmsa_walk.AArch64_S2InitialTTWState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2InitialTTWState()
// ===========================
// Set properties of first access to translation tables in stage 2

func <anchor link="func_AArch64_S2InitialTTWState_2">AArch64_S2InitialTTWState</anchor>(ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>) =&gt; <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>
begin
    var walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>;
    var tablebase : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    var ttbr : bits(128);

    ttbr = ZeroExtend{128}(VTTBR_EL2());
    case ss of
        when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt; tablebase.paspace = <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
        when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a>     =&gt; tablebase.paspace = <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>;
    end;
    tablebase.address = <a link="func_AArch64_S2TTBaseAddress_4" file="shared_pseudocode.xml">AArch64_S2TTBaseAddress</a>{128}(walkparams, tablebase.paspace, ttbr);

    walkstate.baseaddress = tablebase;
    walkstate.level       = <a link="func_AArch64_S2StartLevel_1" file="shared_pseudocode.xml">AArch64_S2StartLevel</a>(walkparams);
    walkstate.istable     = TRUE;
    walkstate.memattrs    = <a link="func_WalkMemAttrs_3" file="shared_pseudocode.xml">WalkMemAttrs</a>(walkparams.sh, walkparams.irgn, walkparams.orgn);

    return walkstate;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walk/AArch64_S2NextWalkStateLeaf" mylink="aarch64.translation.vmsa_walk.AArch64_S2NextWalkStateLeaf" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2NextWalkStateLeaf()
// =============================
// Decode stage 2 page or block descriptor as output to this stage of translation

func <anchor link="func_AArch64_S2NextWalkStateLeaf_6">AArch64_S2NextWalkStateLeaf</anchor>{N}(currentstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>,
                                    walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>, ipa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                                    descriptor : bits(N)) =&gt; <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>
begin
    var nextstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>;
    var baseaddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;

    if ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
        baseaddress.paspace = <a link="func_AArch64_SS2OutputPASpace_2" file="shared_pseudocode.xml">AArch64_SS2OutputPASpace</a>(walkparams, ipa.paddress.paspace);
    elsif ss == <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> then
        var ns : bit;
        ns = if walkparams.d128 == '1' then descriptor[127] else descriptor[55];
        baseaddress.paspace = if ns == '1' then <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> else <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>;
    else
        baseaddress.paspace = <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
    end;
    baseaddress.address   = <a link="func_AArch64_S2LeafBase_4" file="shared_pseudocode.xml">AArch64_S2LeafBase</a>{N}(descriptor, walkparams, currentstate.level);

    nextstate.istable     = FALSE;
    nextstate.level       = currentstate.level;
    nextstate.baseaddress = baseaddress;
    nextstate.permissions = <a link="func_AArch64_S2ApplyOutputPerms_3" file="shared_pseudocode.xml">AArch64_S2ApplyOutputPerms</a>{N}(descriptor, walkparams);

    let s2_attr : bits(4) = descriptor[5:2];
    let s2_sh : bits(2)   = if walkparams.ds == '1' then walkparams.sh else descriptor[9:8];
    let s2_fnxs : bit     = descriptor[11];
    if walkparams.fwb == '1' then
        nextstate.memattrs = <a link="func_AArch64_S2ApplyFWBMemAttrs_4" file="shared_pseudocode.xml">AArch64_S2ApplyFWBMemAttrs</a>{N}(ipa.memattrs, walkparams, descriptor);
        if s2_attr[3:1] == '111' then
            nextstate.permissions.s2tag_na = '1';
        else
            nextstate.permissions.s2tag_na = '0';
        end;
    else
        let s2aarch64 : boolean = TRUE;
        nextstate.memattrs = <a link="func_S2DecodeMemAttrs_3" file="shared_pseudocode.xml">S2DecodeMemAttrs</a>(s2_attr, s2_sh, s2aarch64);
        // FnXS is used later to mask the XS value from stage 1
        nextstate.memattrs.xs = NOT s2_fnxs;
        if s2_attr == '0100' then
            nextstate.permissions.s2tag_na = '1';
        else
            nextstate.permissions.s2tag_na = '0';
        end;
    end;
    nextstate.contiguous = <a link="func_AArch64_ContiguousBit_5" file="shared_pseudocode.xml">AArch64_ContiguousBit</a>{N}(walkparams.tgx, walkparams.d128,
                                                    currentstate.level, descriptor);
    if walkparams.d128 == '1' then
        nextstate.s2assuredonly = descriptor[114];
    else
        nextstate.s2assuredonly = if walkparams.assuredonly == '1' then descriptor[58] else '0';
    end;

    return nextstate;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walk/AArch64_S2NextWalkStateTable" mylink="aarch64.translation.vmsa_walk.AArch64_S2NextWalkStateTable" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2NextWalkStateTable()
// ==============================
// Decode stage 2 table descriptor to transition to the next level

func <anchor link="func_AArch64_S2NextWalkStateTable_4">AArch64_S2NextWalkStateTable</anchor>{N}(currentstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>,
                                     descriptor : bits(N)) =&gt; <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>
begin
    var nextstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>;
    var tablebase : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    let skl : bits(2) = if walkparams.d128 == '1' then descriptor[110:109] else '00';
    tablebase.address = <a link="func_AArch64_NextTableBase_6" file="shared_pseudocode.xml">AArch64_NextTableBase</a>{N}(descriptor, walkparams.d128, skl, walkparams.ds,
                                                 walkparams.tgx);

    tablebase.paspace = currentstate.baseaddress.paspace;

    nextstate.istable     = TRUE;
    if walkparams.d128 == '1' then
        nextstate.level   = currentstate.level + UInt(skl) + 1;
    else
        nextstate.level   = currentstate.level + 1;
    end;
    nextstate.baseaddress = tablebase;
    nextstate.memattrs    = currentstate.memattrs;

    return nextstate;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walk/AArch64_S2Walk" mylink="aarch64.translation.vmsa_walk.AArch64_S2Walk" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2Walk()
// ================
// Traverse stage 2 translation tables obtaining the final descriptor
// as well as the address leading to that descriptor

func <anchor link="func_AArch64_S2Walk_5">AArch64_S2Walk</anchor>{N : integer{64, 128}}(fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>,
                                          ipa : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                                          walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>,
                                          accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; (<a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>,
                                                                          <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                                                                          <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>,
                                                                          bits(N))
begin

    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;
    let ipa_64 : bits(64) = ZeroExtend{}(ipa.paddress.address);

    var walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>;
    if accdesc.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
        walkstate = <a link="func_AArch64_SS2InitialTTWState_2" file="shared_pseudocode.xml">AArch64_SS2InitialTTWState</a>(walkparams, ipa.paddress.paspace);
    else
        walkstate = <a link="func_AArch64_S2InitialTTWState_2" file="shared_pseudocode.xml">AArch64_S2InitialTTWState</a>(accdesc.ss, walkparams);
    end;
    let startlevel : integer = walkstate.level;

    if startlevel &gt; 3 then
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
        fault.level      = 0;
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, ARBITRARY : bits(N));
    end;

    var descriptor : bits(N);
    let walkaccess : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescS2TTW_1" file="shared_pseudocode.xml">CreateAccDescS2TTW</a>(accdesc);
    var walkaddress : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    var skl : bits(2) = '00';

    walkaddress.vaddress = ipa.vaddress;
    walkaddress.mecid = <a link="func_AArch64_S2TTWalkMECID_2" file="shared_pseudocode.xml">AArch64_S2TTWalkMECID</a>(walkparams.emec, accdesc.ss);

    if !<a link="func_S2DCacheEnabled_0" file="shared_pseudocode.xml">S2DCacheEnabled</a>() then
        walkaddress.memattrs = <a link="func_NormalNCMemAttr_0" file="shared_pseudocode.xml">NormalNCMemAttr</a>();
        walkaddress.memattrs.xs = walkstate.memattrs.xs;
    else
        walkaddress.memattrs = walkstate.memattrs;
    end;

    walkaddress.memattrs.shareability = <a link="func_EffectiveShareability_1" file="shared_pseudocode.xml">EffectiveShareability</a>(walkaddress.memattrs);

    var desctype : <a link="type_DescriptorType" file="shared_pseudocode.xml">DescriptorType</a>;

    // Initial lookup might index into concatenated tables
    var descaddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a> = <a link="func_AArch64_S2SLTTEntryAddress_3" file="shared_pseudocode.xml">AArch64_S2SLTTEntryAddress</a>(walkparams, ipa.paddress.address,
                                                               walkstate.baseaddress);

    // Detect Address Size Fault by Descriptor Address
    if <a link="func_AArch64_S2OAOutOfRange_2" file="shared_pseudocode.xml">AArch64_S2OAOutOfRange</a>(descaddress.address, walkparams) then
        fault.statuscode = <a link="enum_Fault_AddressSize" file="shared_pseudocode.xml">Fault_AddressSize</a>;
        fault.level      = 0;
        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, ARBITRARY : bits(N));
    end;

    repeat
        fault.level = walkstate.level;
        walkaddress.paddress = descaddress;
        (fault, descriptor) = <a link="func_FetchDescriptor_5" file="shared_pseudocode.xml">FetchDescriptor</a>{N}(walkparams.ee, walkaddress, walkaccess, fault);

        if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
            return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                    ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, ARBITRARY : bits(N));
        end;

        var new_descriptor : bits(N);
        repeat
            new_descriptor = descriptor;
            desctype = <a link="func_AArch64_DecodeDescriptorType_6" file="shared_pseudocode.xml">AArch64_DecodeDescriptorType</a>{N}(descriptor, walkparams.d128, walkparams.ds,
                                                       walkparams.tgx, walkstate.level);
            case desctype of
                when <a link="enum_DescriptorType_Table" file="shared_pseudocode.xml">DescriptorType_Table</a> =&gt;
                    walkstate = <a link="func_AArch64_S2NextWalkStateTable_4" file="shared_pseudocode.xml">AArch64_S2NextWalkStateTable</a>{N}(walkstate, walkparams, descriptor);
                    skl = if walkparams.d128 == '1' then descriptor[110:109] else '00';
                    descaddress = <a link="func_AArch64_S2TTEntryAddress_5" file="shared_pseudocode.xml">AArch64_S2TTEntryAddress</a>(walkstate.level, walkparams, skl,
                                                           ipa.paddress.address,
                                                           walkstate.baseaddress);

                    // Detect Address Size Fault by table descriptor
                    if <a link="func_AArch64_S2OAOutOfRange_2" file="shared_pseudocode.xml">AArch64_S2OAOutOfRange</a>(descaddress.address, walkparams) then
                        fault.statuscode = <a link="enum_Fault_AddressSize" file="shared_pseudocode.xml">Fault_AddressSize</a>;
                        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>,
                                ARBITRARY : bits(N));
                    end;

                    if walkparams.haft == '1' then
                        new_descriptor[10] = '1';
                    end;

                    if (walkparams.d128 == '1' &amp;&amp; skl != '00' &amp;&amp;
                          <a link="func_AArch64_nTFaults_3" file="shared_pseudocode.xml">AArch64_nTFaults</a>{N}(walkparams.d128, descriptor)) then
                        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
                        return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>,
                                ARBITRARY : bits(N));
                    end;

                when <a link="enum_DescriptorType_Leaf" file="shared_pseudocode.xml">DescriptorType_Leaf</a> =&gt;
                    walkstate = <a link="func_AArch64_S2NextWalkStateLeaf_6" file="shared_pseudocode.xml">AArch64_S2NextWalkStateLeaf</a>{N}(walkstate, accdesc.ss, walkparams,
                                                               ipa, descriptor);
                when <a link="enum_DescriptorType_Invalid" file="shared_pseudocode.xml">DescriptorType_Invalid</a> =&gt;
                    fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
                    return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                            ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, ARBITRARY : bits(N));

                otherwise =&gt;
                    unreachable;
            end;

            if new_descriptor != descriptor then

                if (!<a link="func_IsWBShareable_1" file="shared_pseudocode.xml">IsWBShareable</a>(walkaddress.memattrs) &amp;&amp;
                      <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_Unsupported_Atomic_HW_Update" file="shared_pseudocode.xml">Unpredictable_Unsupported_Atomic_HW_Update</a>)) then
                    fault.statuscode = <a link="enum_Fault_UnsupportedAtomicHWUpdate" file="shared_pseudocode.xml">Fault_UnsupportedAtomicHWUpdate</a>;
                    return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>,
                            ARBITRARY : bits(N));
                end;

                let descaccess : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescTTEUpdate_1" file="shared_pseudocode.xml">CreateAccDescTTEUpdate</a>(accdesc);
                (fault, descriptor) = <a link="func_AArch64_MemSwapTableDesc_7" file="shared_pseudocode.xml">AArch64_MemSwapTableDesc</a>{N}(fault, descriptor, new_descriptor,
                                                                  walkparams.ee, descaccess,
                                                                  walkaddress);
                if fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a> then
                    return (fault, ARBITRARY : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                            ARBITRARY : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>, ARBITRARY : bits(N));
                end;
            end;
        until new_descriptor == descriptor looplimit Unbounded_DescriptorUpdate;
    until desctype == <a link="enum_DescriptorType_Leaf" file="shared_pseudocode.xml">DescriptorType_Leaf</a> looplimit MAX_WALK_LEVELS;

    let oa : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a> = <a link="func_StageOA_4" file="shared_pseudocode.xml">StageOA</a>(ipa_64, walkparams.d128, walkparams.tgx, walkstate);
    if (walkstate.contiguous == '1' &amp;&amp;
        <a link="func_AArch64_ContiguousBitFaults_4" file="shared_pseudocode.xml">AArch64_ContiguousBitFaults</a>(walkparams.d128, walkparams.txsz, walkparams.tgx,
                                    walkstate.level)) then
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
    elsif walkstate.level &lt; <a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> &amp;&amp; <a link="func_AArch64_nTFaults_3" file="shared_pseudocode.xml">AArch64_nTFaults</a>{N}(walkparams.d128, descriptor) then
        fault.statuscode = <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>;
    // Detect Address Size Fault by final output
    elsif <a link="func_AArch64_S2OAOutOfRange_2" file="shared_pseudocode.xml">AArch64_S2OAOutOfRange</a>(oa.address, walkparams) then
        fault.statuscode = <a link="enum_Fault_AddressSize" file="shared_pseudocode.xml">Fault_AddressSize</a>;
    // Check descriptor AF bit
    elsif (descriptor[10] == '0' &amp;&amp; walkparams.ha == '0' &amp;&amp;
            (!accdesc.acctype IN {<a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>, <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>} ||
             ImpDefBool(&quot;Generate access flag fault on IC/DC operations&quot;))) then
        fault.statuscode = <a link="enum_Fault_AccessFlag" file="shared_pseudocode.xml">Fault_AccessFlag</a>;
    end;

    return (fault, walkaddress, walkstate, descriptor);
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walk/AArch64_SS2InitialTTWState" mylink="aarch64.translation.vmsa_walk.AArch64_SS2InitialTTWState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SS2InitialTTWState()
// ============================
// Set properties of first access to translation tables in Secure stage 2

func <anchor link="func_AArch64_SS2InitialTTWState_2">AArch64_SS2InitialTTWState</anchor>(walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>, ipaspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>) =&gt; <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>
begin
    var walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>;
    var tablebase : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    var ttbr : bits(128);

    if ipaspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> then
        ttbr = ZeroExtend{128}(VSTTBR_EL2());
    else
        ttbr = ZeroExtend{128}(VTTBR_EL2());
    end;

    if ipaspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> then
        if walkparams.sw == '0' then
            tablebase.paspace = <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>;
        else
            tablebase.paspace = <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
        end;
    else
        if walkparams.nsw == '0' then
            tablebase.paspace = <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>;
        else
            tablebase.paspace = <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
        end;
    end;
    tablebase.address = <a link="func_AArch64_S2TTBaseAddress_4" file="shared_pseudocode.xml">AArch64_S2TTBaseAddress</a>{128}(walkparams, tablebase.paspace, ttbr);

    walkstate.baseaddress = tablebase;
    walkstate.level       = <a link="func_AArch64_S2StartLevel_1" file="shared_pseudocode.xml">AArch64_S2StartLevel</a>(walkparams);
    walkstate.istable     = TRUE;
    walkstate.memattrs    = <a link="func_WalkMemAttrs_3" file="shared_pseudocode.xml">WalkMemAttrs</a>(walkparams.sh, walkparams.irgn, walkparams.orgn);

    return walkstate;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walk/AArch64_SS2OutputPASpace" mylink="aarch64.translation.vmsa_walk.AArch64_SS2OutputPASpace" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SS2OutputPASpace()
// ==========================
// Assign PA Space to output of Secure stage 2 translation

func <anchor link="func_AArch64_SS2OutputPASpace_2">AArch64_SS2OutputPASpace</anchor>(walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>, ipaspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>) =&gt; <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>
begin
    if ipaspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> then
        if walkparams.[sw,sa] == '00' then
            return <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>;
        else
            return <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
        end;
    else
        if walkparams.[sw,sa,nsw,nsa] == '0000' then
            return <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>;
        else
            return <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
        end;
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_GetS1TTWParams" mylink="aarch64.translation.vmsa_walkparams.AArch64_GetS1TTWParams" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_GetS1TTWParams()
// ========================
// Returns stage 1 translation table walk parameters from respective controlling
// System registers.


func <anchor link="func_AArch64_GetS1TTWParams_4">AArch64_GetS1TTWParams</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, el : bits(2),
                            ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, va : bits(64)) =&gt; <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>
begin
    var walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>;

    let varange : <a link="type_VARange" file="shared_pseudocode.xml">VARange</a> = <a link="func_AArch64_GetVARange_1" file="shared_pseudocode.xml">AArch64_GetVARange</a>(va);

    case regime of
        when <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> =&gt;  walkparams = <a link="func_AArch64_S1TTWParamsEL3_0" file="shared_pseudocode.xml">AArch64_S1TTWParamsEL3</a>();
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> =&gt;  walkparams = <a link="func_AArch64_S1TTWParamsEL2_1" file="shared_pseudocode.xml">AArch64_S1TTWParamsEL2</a>(ss);
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt; walkparams = <a link="func_AArch64_S1TTWParamsEL20_3" file="shared_pseudocode.xml">AArch64_S1TTWParamsEL20</a>(el, ss, varange);
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt; walkparams = <a link="func_AArch64_S1TTWParamsEL10_2" file="shared_pseudocode.xml">AArch64_S1TTWParamsEL10</a>(el, varange);
    end;

    return walkparams;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_GetS2TTWParams" mylink="aarch64.translation.vmsa_walkparams.AArch64_GetS2TTWParams" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_GetS2TTWParams()
// ========================
// Gather walk parameters for stage 2 translation

func <anchor link="func_AArch64_GetS2TTWParams_3">AArch64_GetS2TTWParams</anchor>(ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, ipaspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>,
                            s1aarch64 : boolean) =&gt; <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>
begin
    var walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>;

    if ss == <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> then
        walkparams = <a link="func_AArch64_NSS2TTWParams_1" file="shared_pseudocode.xml">AArch64_NSS2TTWParams</a>(s1aarch64);
    elsif IsFeatureImplemented(FEAT_SEL2) &amp;&amp; ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
        walkparams = <a link="func_AArch64_SS2TTWParams_2" file="shared_pseudocode.xml">AArch64_SS2TTWParams</a>(ipaspace, s1aarch64);
    elsif ss == <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> then
        walkparams = <a link="func_AArch64_RLS2TTWParams_1" file="shared_pseudocode.xml">AArch64_RLS2TTWParams</a>(s1aarch64);
    else
        unreachable;
    end;

    return walkparams;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_GetVARange" mylink="aarch64.translation.vmsa_walkparams.AArch64_GetVARange" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_GetVARange()
// ====================
// Determines if the VA that is to be translated lies in LOWER or UPPER address range.

func <anchor link="func_AArch64_GetVARange_1">AArch64_GetVARange</anchor>(va : bits(64)) =&gt; <a link="type_VARange" file="shared_pseudocode.xml">VARange</a>
begin
    if va[55] == '0' then
        return <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a>;
    else
        return <a link="enum_VARange_UPPER" file="shared_pseudocode.xml">VARange_UPPER</a>;
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_HaveS1TG" mylink="aarch64.translation.vmsa_walkparams.AArch64_HaveS1TG" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_HaveS1TG()
// ==================
// Determine whether the given translation granule is supported for stage 1

func <anchor link="func_AArch64_HaveS1TG_1">AArch64_HaveS1TG</anchor>(tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>) =&gt; boolean
begin
    case tgx of
        when <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a> =&gt;  return IsFeatureImplemented(FEAT_TGran4K);
        when <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a> =&gt; return IsFeatureImplemented(FEAT_TGran16K);
        when <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> =&gt; return IsFeatureImplemented(FEAT_TGran64K);
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_HaveS2TG" mylink="aarch64.translation.vmsa_walkparams.AArch64_HaveS2TG" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_HaveS2TG()
// ==================
// Determine whether the given translation granule is supported for stage 2

func <anchor link="func_AArch64_HaveS2TG_1">AArch64_HaveS2TG</anchor>(tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>) =&gt; boolean
begin
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);

    if IsFeatureImplemented(FEAT_GTG) then
        case tgx of
            when <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a> =&gt;  return IsFeatureImplemented(FEAT_S2TGran4K);
            when <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a> =&gt; return IsFeatureImplemented(FEAT_S2TGran16K);
            when <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> =&gt; return IsFeatureImplemented(FEAT_S2TGran64K);
        end;
    else
        return <a link="func_AArch64_HaveS1TG_1" file="shared_pseudocode.xml">AArch64_HaveS1TG</a>(tgx);
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_MaxTxSZ" mylink="aarch64.translation.vmsa_walkparams.AArch64_MaxTxSZ" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_MaxTxSZ()
// =================
// Retrieve the maximum value of TxSZ indicating minimum input address size for both
// stages of translation

func <anchor link="func_AArch64_MaxTxSZ_1">AArch64_MaxTxSZ</anchor>(tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>) =&gt; integer
begin
    if IsFeatureImplemented(FEAT_TTST) then
        case tgx of
            when <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a> =&gt;   return 48;
            when <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a> =&gt;  return 48;
            when <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> =&gt;  return 47;
        end;
    end;

    return 39;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_NSS2TTWParams" mylink="aarch64.translation.vmsa_walkparams.AArch64_NSS2TTWParams" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_NSS2TTWParams()
// =======================
// Gather walk parameters specific for Non-secure stage 2 translation

func <anchor link="func_AArch64_NSS2TTWParams_1">AArch64_NSS2TTWParams</anchor>(s1aarch64 : boolean) =&gt; <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>
begin
    var walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>;

    walkparams.vm   = HCR_EL2().VM OR HCR_EL2().DC;
    walkparams.tgx  = <a link="func_AArch64_S2DecodeTG0_1" file="shared_pseudocode.xml">AArch64_S2DecodeTG0</a>(VTCR_EL2().TG0);
    walkparams.txsz = VTCR_EL2().T0SZ;
    walkparams.ps   = VTCR_EL2().PS;
    walkparams.irgn = VTCR_EL2().IRGN0;
    walkparams.orgn = VTCR_EL2().ORGN0;
    walkparams.sh   = VTCR_EL2().SH0;
    walkparams.ee   = SCTLR_EL2().EE;
    walkparams.d128 = if IsFeatureImplemented(FEAT_D128)  then VTCR_EL2().D128 else '0';
    if walkparams.d128 == '1' then
        walkparams.skl = VTTBR_EL2().SKL;
    else
        walkparams.sl0 = VTCR_EL2().SL0;
    end;

    walkparams.ptw = if HCR_EL2().TGE == '0'                then HCR_EL2().PTW else '0';
    walkparams.fwb = if IsFeatureImplemented(FEAT_S2FWB)  then HCR_EL2().FWB else '0';
    walkparams.ha = if IsFeatureImplemented(FEAT_HAF) then VTCR_EL2().HA else '0';
    if IsFeatureImplemented(FEAT_HAFDBS) &amp;&amp; walkparams.ha == '1' then
        walkparams.hd = VTCR_EL2().HD;
    else
        walkparams.hd = '0';
    end;
    if walkparams.tgx IN {<a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>, <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a>} &amp;&amp; IsFeatureImplemented(FEAT_LPA2) then
        walkparams.ds = VTCR_EL2().DS;
    else
        walkparams.ds = '0';
    end;
    if walkparams.tgx == <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a> &amp;&amp; IsFeatureImplemented(FEAT_LPA2) then
        walkparams.sl2 = VTCR_EL2().SL2 AND VTCR_EL2().DS;
    else
        walkparams.sl2 = '0';
    end;
    walkparams.cmow = (if IsFeatureImplemented(FEAT_CMOW) &amp;&amp; <a link="func_IsHCRXEL2Enabled_0" file="shared_pseudocode.xml">IsHCRXEL2Enabled</a>() then HCRX_EL2().CMOW
                       else '0');
    if walkparams.d128 == '1' then
        walkparams.s2pie = '1';
    else
        walkparams.s2pie = if IsFeatureImplemented(FEAT_S2PIE) then VTCR_EL2().S2PIE else '0';
    end;
    if IsFeatureImplemented(FEAT_S2PIE) then
        if !(<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().PIEn == '0' &amp;&amp;
              ImpDefBool(&quot;SCR_EL3.PIEn forces PIR_ELx or POR_ELx to zero&quot;)) then
            walkparams.s2pir = S2PIR_EL2() as S2PIRType;
        else
            walkparams.s2pir = Zeros{64} as S2PIRType;
        end;
    end;
    if IsFeatureImplemented(FEAT_THE) &amp;&amp; walkparams.d128 != '1' then
        walkparams.assuredonly = VTCR_EL2().AssuredOnly;
    else
        walkparams.assuredonly = '0';
    end;
    walkparams.tl0   = if IsFeatureImplemented(FEAT_THE) then VTCR_EL2().TL0 else '0';
    walkparams.tl1   = if IsFeatureImplemented(FEAT_THE) then VTCR_EL2().TL1 else '0';
    if IsFeatureImplemented(FEAT_HAFT) &amp;&amp; walkparams.ha == '1' then
        walkparams.haft = VTCR_EL2().HAFT;
    else
        walkparams.haft = '0';
    end;
    if (IsFeatureImplemented(FEAT_HDBSS) &amp;&amp; walkparams.hd == '1' &amp;&amp;
          (!<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || SCR_EL3().HDBSSEn == '1')) then
        walkparams.hdbss = VTCR_EL2().HDBSS;
    else
        walkparams.hdbss = '0';
    end;

    return walkparams;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_PAMax" mylink="aarch64.translation.vmsa_walkparams.AArch64_PAMax" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_PAMax()
// ===============
// Returns the IMPLEMENTATION DEFINED maximum number of bits capable of representing
// physical address for this PE

func <anchor link="func_AArch64_PAMax_0">AArch64_PAMax</anchor>() =&gt; <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>
begin
    return ImpDefInt(&quot;Maximum Physical Address Size&quot;) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_RLS2TTWParams" mylink="aarch64.translation.vmsa_walkparams.AArch64_RLS2TTWParams" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_RLS2TTWParams()
// =======================
// Gather walk parameters specific for Realm stage 2 translation

func <anchor link="func_AArch64_RLS2TTWParams_1">AArch64_RLS2TTWParams</anchor>(s1aarch64 : boolean) =&gt; <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>
begin
    // Realm stage 2 walk parameters are similar to Non-secure
    var walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a> = <a link="func_AArch64_NSS2TTWParams_1" file="shared_pseudocode.xml">AArch64_NSS2TTWParams</a>(s1aarch64);
    walkparams.emec = (if IsFeatureImplemented(FEAT_MEC) &amp;&amp;
                       <a link="func_IsSCTLR2EL2Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL2Enabled</a>() then SCTLR2_EL2().EMEC else '0');
    return walkparams;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_S1DCacheEnabled" mylink="aarch64.translation.vmsa_walkparams.AArch64_S1DCacheEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1DCacheEnabled()
// =========================
// Determine cacheability of stage 1 data accesses

func <anchor link="func_AArch64_S1DCacheEnabled_1">AArch64_S1DCacheEnabled</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>) =&gt; boolean
begin
    case regime of
        when <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> =&gt;  return SCTLR_EL3().C == '1';
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> =&gt;  return SCTLR_EL2().C == '1';
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt; return SCTLR_EL2().C == '1';
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt; return SCTLR_EL1().C == '1';
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_S1DecodeTG0" mylink="aarch64.translation.vmsa_walkparams.AArch64_S1DecodeTG0" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1DecodeTG0()
// =====================
// Decode stage 1 granule size configuration bits TG0

func <anchor link="func_AArch64_S1DecodeTG0_1">AArch64_S1DecodeTG0</anchor>(tg0_in : bits(2)) =&gt; <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>
begin
    var tg0 : bits(2) = tg0_in;
    var tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>;

    if tg0 == '11' then
        tg0 = ImpDefBits{2}(&quot;TG0 encoded granule size&quot;);
    end;

    case tg0 of
        when '00' =&gt;   tgx = <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>;
        when '01' =&gt;   tgx = <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a>;
        when '10' =&gt;   tgx = <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a>;
    end;

    if !<a link="func_AArch64_HaveS1TG_1" file="shared_pseudocode.xml">AArch64_HaveS1TG</a>(tgx) then
        case ImpDefBits{2}(&quot;TG0 encoded granule size&quot;) of
            when '00' =&gt;   tgx = <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>;
            when '01' =&gt;   tgx = <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a>;
            when '10' =&gt;   tgx = <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a>;
        end;
    end;

    return tgx;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_S1DecodeTG1" mylink="aarch64.translation.vmsa_walkparams.AArch64_S1DecodeTG1" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1DecodeTG1()
// =====================
// Decode stage 1 granule size configuration bits TG1

func <anchor link="func_AArch64_S1DecodeTG1_1">AArch64_S1DecodeTG1</anchor>(tg1_in : bits(2)) =&gt; <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>
begin
    var tg1 : bits(2) = tg1_in;
    var tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>;

    if tg1 == '00' then
        tg1 = ImpDefBits{2}(&quot;TG1 encoded granule size&quot;);
    end;

    case tg1 of
        when '10' =&gt;   tgx = <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>;
        when '11' =&gt;   tgx = <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a>;
        when '01' =&gt;   tgx = <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a>;
    end;

    if !<a link="func_AArch64_HaveS1TG_1" file="shared_pseudocode.xml">AArch64_HaveS1TG</a>(tgx) then
        case ImpDefBits{2}(&quot;TG1 encoded granule size&quot;) of
            when '10' =&gt;   tgx = <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>;
            when '11' =&gt;   tgx = <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a>;
            when '01' =&gt;   tgx = <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a>;
        end;
    end;

    return tgx;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_S1E0POEnabled" mylink="aarch64.translation.vmsa_walkparams.AArch64_S1E0POEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1E0POEnabled()
// =======================
// Determine whether stage 1 unprivileged permission overlay is enabled

func <anchor link="func_AArch64_S1E0POEnabled_2">AArch64_S1E0POEnabled</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, nv1 : bit) =&gt; boolean
begin
    assert <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime);

    if !IsFeatureImplemented(FEAT_S1POE) then
        return FALSE;
    end;

    case regime of
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt; return <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() &amp;&amp; TCR2_EL2().E0POE == '1';
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt; return <a link="func_IsTCR2EL1Enabled_0" file="shared_pseudocode.xml">IsTCR2EL1Enabled</a>() &amp;&amp; nv1 == '0' &amp;&amp; TCR2_EL1().E0POE == '1';
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_S1EPD" mylink="aarch64.translation.vmsa_walkparams.AArch64_S1EPD" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1EPD()
// ===============
// Determine whether stage 1 translation table walk is allowed for the VA range

func <anchor link="func_AArch64_S1EPD_2">AArch64_S1EPD</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, va : bits(64)) =&gt; bit
begin
    assert <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime);
    let varange : <a link="type_VARange" file="shared_pseudocode.xml">VARange</a> = <a link="func_AArch64_GetVARange_1" file="shared_pseudocode.xml">AArch64_GetVARange</a>(va);

    case regime of
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt; return (if varange == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then TCR_EL2().EPD0
                                                                else TCR_EL2().EPD1);
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt; return (if varange == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then TCR_EL1().EPD0
                                                                else TCR_EL1().EPD1);
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_S1Enabled" mylink="aarch64.translation.vmsa_walkparams.AArch64_S1Enabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1Enabled()
// ===================
// Determine if stage 1 is enabled for the access type for this translation regime

func <anchor link="func_AArch64_S1Enabled_2">AArch64_S1Enabled</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, acctype : <a link="type_AccessType" file="shared_pseudocode.xml">AccessType</a>) =&gt; boolean
begin
    if acctype == <a link="enum_AccessType_TRBE" file="shared_pseudocode.xml">AccessType_TRBE</a> &amp;&amp; <a link="func_EffectiveTRBLIMITR_EL1_nVM_0" file="shared_pseudocode.xml">EffectiveTRBLIMITR_EL1_nVM</a>()  == '1' then
        return FALSE;
    end;
    if acctype == <a link="enum_AccessType_SPE" file="shared_pseudocode.xml">AccessType_SPE</a> &amp;&amp; <a link="func_EffectivePMBLIMITR_EL1_nVM_0" file="shared_pseudocode.xml">EffectivePMBLIMITR_EL1_nVM</a>() == '1' then
        return FALSE;
    end;
    case regime of
        when <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> =&gt;  return SCTLR_EL3().M == '1';
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> =&gt;  return SCTLR_EL2().M == '1';
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt; return SCTLR_EL2().M == '1';
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt; return ((!<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() || HCR_EL2().[DC,TGE] == '00') &amp;&amp;
                                        SCTLR_EL1().M == '1');
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_S1ICacheEnabled" mylink="aarch64.translation.vmsa_walkparams.AArch64_S1ICacheEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1ICacheEnabled()
// =========================
// Determine cacheability of stage 1 instruction fetches

func <anchor link="func_AArch64_S1ICacheEnabled_1">AArch64_S1ICacheEnabled</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>) =&gt; boolean
begin
    case regime of
        when <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> =&gt;  return SCTLR_EL3().I == '1';
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> =&gt;  return SCTLR_EL2().I == '1';
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt; return SCTLR_EL2().I == '1';
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt; return SCTLR_EL1().I == '1';
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_S1MinTxSZ" mylink="aarch64.translation.vmsa_walkparams.AArch64_S1MinTxSZ" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1MinTxSZ()
// ===================
// Retrieve the minimum value of TxSZ indicating maximum input address size for stage 1

func <anchor link="func_AArch64_S1MinTxSZ_2">AArch64_S1MinTxSZ</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>) =&gt; integer
begin
    if IsFeatureImplemented(FEAT_LVA3) then
        if walkparams.d128 == '1' then
            if <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(regime) then
                return 9;
            else
                return 8;
            end;
        elsif walkparams.tgx == <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> || walkparams.ds == '1' then
            return 12;
        else
            return 16;
        end;
    end;
    if IsFeatureImplemented(FEAT_LVA) then
        if walkparams.tgx == <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> || walkparams.ds == '1' || walkparams.d128 == '1' then
            return 12;
        else
            return 16;
        end;
    end;

    return 16;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_S1POEnabled" mylink="aarch64.translation.vmsa_walkparams.AArch64_S1POEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1POEnabled()
// =====================
// Determine whether stage 1 privileged permission overlay is enabled

func <anchor link="func_AArch64_S1POEnabled_1">AArch64_S1POEnabled</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>) =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_S1POE) then
        return FALSE;
    end;

    case regime of
        when <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> =&gt;  return TCR_EL3().POE == '1';
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> =&gt;  return <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() &amp;&amp; TCR2_EL2().POE == '1';
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt; return <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() &amp;&amp; TCR2_EL2().POE == '1';
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt; return <a link="func_IsTCR2EL1Enabled_0" file="shared_pseudocode.xml">IsTCR2EL1Enabled</a>() &amp;&amp; TCR2_EL1().POE == '1';
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_S1POR" mylink="aarch64.translation.vmsa_walkparams.AArch64_S1POR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1POR()
// ===============
// Identify stage 1 permissions overlay register for the acting translation regime

func <anchor link="func_AArch64_S1POR_1">AArch64_S1POR</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>) =&gt; S1PORType
begin
    if (<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().PIEn == '0' &amp;&amp; regime != <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> &amp;&amp;
          ImpDefBool(&quot;SCR_EL3.PIEn forces PIR_ELx or POR_ELx to zero&quot;)) then
        return Zeros{64} as S1PORType;
    end;

    case regime of
        when <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> =&gt;  return POR_EL3() as S1PORType;
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> =&gt;  return POR_EL2() as S1PORType;
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt; return POR_EL2() as S1PORType;
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt; return POR_EL1() as S1PORType;
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_S1TTBR" mylink="aarch64.translation.vmsa_walkparams.AArch64_S1TTBR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1TTBR()
// ================
// Identify stage 1 table base register for the acting translation regime

func <anchor link="func_AArch64_S1TTBR_2">AArch64_S1TTBR</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>, va : bits(64)) =&gt; bits(128)
begin
    let varange : <a link="type_VARange" file="shared_pseudocode.xml">VARange</a> = <a link="func_AArch64_GetVARange_1" file="shared_pseudocode.xml">AArch64_GetVARange</a>(va);

    case regime of
        when <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> =&gt;  return ZeroExtend{128}(TTBR0_EL3());
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> =&gt;  return ZeroExtend{128}(TTBR0_EL2());
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt;
            if varange == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then
                return ZeroExtend{128}(TTBR0_EL2());
            else
                return ZeroExtend{128}(TTBR1_EL2());
            end;
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt;
            if varange == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then
                return ZeroExtend{128}(TTBR0_EL1());
            else
                return ZeroExtend{128}(TTBR1_EL1());
            end;
    end;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_S1TTWParamsEL10" mylink="aarch64.translation.vmsa_walkparams.AArch64_S1TTWParamsEL10" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1TTWParamsEL10()
// =========================
// Gather stage 1 translation table walk parameters for EL1&amp;0 regime
// (with EL2 enabled or disabled)

func <anchor link="func_AArch64_S1TTWParamsEL10_2">AArch64_S1TTWParamsEL10</anchor>(el : bits(2), varange : <a link="type_VARange" file="shared_pseudocode.xml">VARange</a>) =&gt; <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>
begin
    var walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>;

    if IsFeatureImplemented(FEAT_D128) &amp;&amp; <a link="func_IsTCR2EL1Enabled_0" file="shared_pseudocode.xml">IsTCR2EL1Enabled</a>() then
        walkparams.d128 = TCR2_EL1().D128;
    else
        walkparams.d128 = '0';
    end;
    let nvs : bits(3) = <a link="func_EffectiveHCR_EL2_NVx_0" file="shared_pseudocode.xml">EffectiveHCR_EL2_NVx</a>();
    walkparams.nv1 = nvs[1];

    if IsFeatureImplemented(FEAT_AIE) then
        walkparams.mair2 = MAIR2_EL1() as MAIRType;
    end;
    walkparams.aie  = (if IsFeatureImplemented(FEAT_AIE) &amp;&amp; <a link="func_IsTCR2EL1Enabled_0" file="shared_pseudocode.xml">IsTCR2EL1Enabled</a>() then TCR2_EL1().AIE
                       else '0');
    if walkparams.d128 == '1' then
        walkparams.pie = '1';
    else
        walkparams.pie = (if IsFeatureImplemented(FEAT_S1PIE) &amp;&amp;
                          <a link="func_IsTCR2EL1Enabled_0" file="shared_pseudocode.xml">IsTCR2EL1Enabled</a>() then TCR2_EL1().PIE else '0');
    end;
    if IsFeatureImplemented(FEAT_S1PIE) then
        if !(<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().PIEn == '0' &amp;&amp;
               ImpDefBool(&quot;SCR_EL3.PIEn forces PIR_ELx or POR_ELx to zero&quot;)) then
            walkparams.pir = PIR_EL1() as S1PIRType;
            if walkparams.nv1 == '1' then
                walkparams.pire0 = Zeros{64} as S1PIRType;
            else
                walkparams.pire0 = PIRE0_EL1() as S1PIRType;
            end;
        else
            walkparams.pir   = Zeros{64} as S1PIRType;
            walkparams.pire0 = Zeros{64} as S1PIRType;
        end;
    end;

    if varange == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then
        walkparams.tgx   = <a link="func_AArch64_S1DecodeTG0_1" file="shared_pseudocode.xml">AArch64_S1DecodeTG0</a>(TCR_EL1().TG0);
        walkparams.txsz  = TCR_EL1().T0SZ;
        walkparams.irgn  = TCR_EL1().IRGN0;
        walkparams.orgn  = TCR_EL1().ORGN0;
        walkparams.sh    = TCR_EL1().SH0;
        walkparams.tbi   = TCR_EL1().TBI0;

        walkparams.nfd   = if IsFeatureImplemented(FEAT_SVE)   then TCR_EL1().NFD0  else '0';
        walkparams.tbid  = if IsFeatureImplemented(FEAT_PAuth) then TCR_EL1().TBID0 else '0';
        walkparams.e0pd  = if IsFeatureImplemented(FEAT_E0PD)  then TCR_EL1().E0PD0 else '0';
        walkparams.hpd   = if IsFeatureImplemented(FEAT_HPDS)  then TCR_EL1().HPD0  else '0';
        if walkparams.hpd == '0' then
            if walkparams.aie == '1' then walkparams.hpd = '1'; end;
            if walkparams.pie == '1' then walkparams.hpd = '1'; end;
            if (<a link="func_AArch64_S1POEnabled_1" file="shared_pseudocode.xml">AArch64_S1POEnabled</a>(<a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a>) ||
                  <a link="func_AArch64_S1E0POEnabled_2" file="shared_pseudocode.xml">AArch64_S1E0POEnabled</a>(<a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a>, walkparams.nv1)) then walkparams.hpd = '1';
            end;
        end;
        if (IsFeatureImplemented(FEAT_MTE_NO_ADDRESS_TAGS) ||
              IsFeatureImplemented(FEAT_MTE_CANONICAL_TAGS)) then
            walkparams.mtx  = TCR_EL1().MTX0;
        else
            walkparams.mtx  = '0';
        end;
        walkparams.skl   = if walkparams.d128 == '1' then TTBR0_EL1().SKL else '00';
        walkparams.disch = if walkparams.d128 == '1' then TCR2_EL1().DisCH0 else '0';
        if IsFeatureImplemented(FEAT_ASID2) &amp;&amp; <a link="func_IsTCR2EL1Enabled_0" file="shared_pseudocode.xml">IsTCR2EL1Enabled</a>() then
            walkparams.fng = TCR2_EL1().FNG0;
        else
            walkparams.fng = '0';
        end;
        if IsFeatureImplemented(FEAT_THE) &amp;&amp; <a link="func_IsTCR2EL1Enabled_0" file="shared_pseudocode.xml">IsTCR2EL1Enabled</a>() then
            walkparams.fngna = TCR2_EL1().FNGNA0;
        else
            walkparams.fngna = '0';
        end;
    else
        walkparams.tgx   = <a link="func_AArch64_S1DecodeTG1_1" file="shared_pseudocode.xml">AArch64_S1DecodeTG1</a>(TCR_EL1().TG1);
        walkparams.txsz  = TCR_EL1().T1SZ;
        walkparams.irgn  = TCR_EL1().IRGN1;
        walkparams.orgn  = TCR_EL1().ORGN1;
        walkparams.sh    = TCR_EL1().SH1;
        walkparams.tbi   = TCR_EL1().TBI1;

        walkparams.nfd   = if IsFeatureImplemented(FEAT_SVE)   then TCR_EL1().NFD1  else '0';
        walkparams.tbid  = if IsFeatureImplemented(FEAT_PAuth) then TCR_EL1().TBID1 else '0';
        walkparams.e0pd  = if IsFeatureImplemented(FEAT_E0PD)  then TCR_EL1().E0PD1 else '0';
        walkparams.hpd   = if IsFeatureImplemented(FEAT_HPDS)  then TCR_EL1().HPD1  else '0';
        if walkparams.hpd == '0' then
            if walkparams.aie == '1' then walkparams.hpd = '1'; end;
            if walkparams.pie == '1' then walkparams.hpd = '1'; end;
            if (<a link="func_AArch64_S1POEnabled_1" file="shared_pseudocode.xml">AArch64_S1POEnabled</a>(<a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a>) ||
                  <a link="func_AArch64_S1E0POEnabled_2" file="shared_pseudocode.xml">AArch64_S1E0POEnabled</a>(<a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a>, walkparams.nv1)) then walkparams.hpd = '1';
            end;
        end;
        if (IsFeatureImplemented(FEAT_MTE_NO_ADDRESS_TAGS) ||
              IsFeatureImplemented(FEAT_MTE_CANONICAL_TAGS)) then
            walkparams.mtx  = TCR_EL1().MTX1;
        else
            walkparams.mtx  = '0';
        end;
        walkparams.skl   = if walkparams.d128 == '1' then TTBR1_EL1().SKL else '00';
        walkparams.disch = if walkparams.d128 == '1' then TCR2_EL1().DisCH1 else '0';
        if IsFeatureImplemented(FEAT_ASID2) &amp;&amp; <a link="func_IsTCR2EL1Enabled_0" file="shared_pseudocode.xml">IsTCR2EL1Enabled</a>() then
            walkparams.fng = TCR2_EL1().FNG1;
        else
            walkparams.fng = '0';
        end;
        if IsFeatureImplemented(FEAT_THE) &amp;&amp; <a link="func_IsTCR2EL1Enabled_0" file="shared_pseudocode.xml">IsTCR2EL1Enabled</a>() then
            walkparams.fngna = TCR2_EL1().FNGNA1;
        else
            walkparams.fngna = '0';
        end;
    end;

    walkparams.mair = MAIR_EL1() as MAIRType;
    walkparams.wxn  = SCTLR_EL1().WXN;
    walkparams.ps   = TCR_EL1().IPS;
    walkparams.ee   = SCTLR_EL1().EE;
    if (<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; (!IsFeatureImplemented(FEAT_RME) || IsFeatureImplemented(FEAT_SEL2))) then
        walkparams.sif = SCR_EL3().SIF;
    else
        walkparams.sif = '0';
    end;

    if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        walkparams.dc  = HCR_EL2().DC;
        walkparams.dct = if IsFeatureImplemented(FEAT_MTE2) then HCR_EL2().DCT else '0';
    end;

    if IsFeatureImplemented(FEAT_LSMAOC) then
        walkparams.ntlsmd = SCTLR_EL1().nTLSMD;
    else
        walkparams.ntlsmd = '1';
    end;

    walkparams.cmow = if IsFeatureImplemented(FEAT_CMOW)   then SCTLR_EL1().CMOW else '0';
    walkparams.ha = if IsFeatureImplemented(FEAT_HAF) then TCR_EL1().HA else '0';
    if IsFeatureImplemented(FEAT_HAFDBS) &amp;&amp; walkparams.ha == '1' then
        walkparams.hd = TCR_EL1().HD;
    else
        walkparams.hd = '0';
    end;
    if (walkparams.tgx IN {<a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>, <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a>} &amp;&amp; IsFeatureImplemented(FEAT_LPA2) &amp;&amp;
          walkparams.d128 == '0') then
        walkparams.ds = TCR_EL1().DS;
    else
        walkparams.ds = '0';
    end;
    if IsFeatureImplemented(FEAT_PAN3) then
        walkparams.epan = if walkparams.pie == '0' then SCTLR_EL1().EPAN else '1';
    else
        walkparams.epan = '0';
    end;
    if IsFeatureImplemented(FEAT_THE) &amp;&amp; walkparams.d128 == '0' &amp;&amp; <a link="func_IsTCR2EL1Enabled_0" file="shared_pseudocode.xml">IsTCR2EL1Enabled</a>() then
        walkparams.pnch = TCR2_EL1().PnCH;
    else
        walkparams.pnch = '0';
    end;
    if IsFeatureImplemented(FEAT_HAFT) &amp;&amp; walkparams.ha == '1' &amp;&amp; <a link="func_IsTCR2EL1Enabled_0" file="shared_pseudocode.xml">IsTCR2EL1Enabled</a>() then
        walkparams.haft = TCR2_EL1().HAFT;
    else
        walkparams.haft = '0';
    end;
    walkparams.emec = (if IsFeatureImplemented(FEAT_MEC) &amp;&amp;
                       <a link="func_IsSCTLR2EL2Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL2Enabled</a>() then SCTLR2_EL2().EMEC else '0');

    return walkparams;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_S1TTWParamsEL2" mylink="aarch64.translation.vmsa_walkparams.AArch64_S1TTWParamsEL2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1TTWParamsEL2()
// ========================
// Gather stage 1 translation table walk parameters for EL2 regime

func <anchor link="func_AArch64_S1TTWParamsEL2_1">AArch64_S1TTWParamsEL2</anchor>(ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>) =&gt; <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>
begin
    var walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>;

    walkparams.tgx  = <a link="func_AArch64_S1DecodeTG0_1" file="shared_pseudocode.xml">AArch64_S1DecodeTG0</a>(TCR_EL2().TG0);
    walkparams.txsz = TCR_EL2().T0SZ;
    walkparams.ps   = TCR_EL2().PS;
    walkparams.irgn = TCR_EL2().IRGN0;
    walkparams.orgn = TCR_EL2().ORGN0;
    walkparams.sh   = TCR_EL2().SH0;
    walkparams.tbi  = TCR_EL2().TBI;
    walkparams.mair = MAIR_EL2() as MAIRType;

    walkparams.pie = (if IsFeatureImplemented(FEAT_S1PIE) &amp;&amp; <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() then TCR2_EL2().PIE
                      else '0');

    if IsFeatureImplemented(FEAT_S1PIE) then
        if !(<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().PIEn == '0' &amp;&amp;
               ImpDefBool(&quot;SCR_EL3.PIEn forces PIR_ELx or POR_ELx to zero&quot;)) then
            walkparams.pir = PIR_EL2() as S1PIRType;
        else
            walkparams.pir = Zeros{64} as S1PIRType;
        end;
    end;
    if IsFeatureImplemented(FEAT_AIE) then
        walkparams.mair2 = MAIR2_EL2() as MAIRType;
    end;
    walkparams.aie  = (if IsFeatureImplemented(FEAT_AIE) &amp;&amp; <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() then TCR2_EL2().AIE
                       else '0');
    walkparams.wxn  = SCTLR_EL2().WXN;
    walkparams.ee   = SCTLR_EL2().EE;
    if (<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; (!IsFeatureImplemented(FEAT_RME) || IsFeatureImplemented(FEAT_SEL2))) then
        walkparams.sif = SCR_EL3().SIF;
    else
        walkparams.sif = '0';
    end;

    walkparams.tbid = if IsFeatureImplemented(FEAT_PAuth)  then TCR_EL2().TBID else '0';
    walkparams.hpd  = if IsFeatureImplemented(FEAT_HPDS)   then TCR_EL2().HPD  else '0';
    if walkparams.hpd == '0' then
        if walkparams.aie == '1' then walkparams.hpd = '1'; end;
        if walkparams.pie == '1' then walkparams.hpd = '1'; end;
        if <a link="func_AArch64_S1POEnabled_1" file="shared_pseudocode.xml">AArch64_S1POEnabled</a>(<a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a>) then walkparams.hpd = '1'; end;
    end;
    walkparams.ha = if IsFeatureImplemented(FEAT_HAF) then TCR_EL2().HA else '0';
    if IsFeatureImplemented(FEAT_HAFDBS) &amp;&amp; walkparams.ha == '1' then
        walkparams.hd = TCR_EL2().HD;
    else
        walkparams.hd = '0';
    end;
    if walkparams.tgx IN {<a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>, <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a>} &amp;&amp; IsFeatureImplemented(FEAT_LPA2) then
        walkparams.ds = TCR_EL2().DS;
    else
        walkparams.ds = '0';
    end;
    if (IsFeatureImplemented(FEAT_MTE_NO_ADDRESS_TAGS) ||
          IsFeatureImplemented(FEAT_MTE_CANONICAL_TAGS)) then
        walkparams.mtx  = TCR_EL2().MTX;
    else
        walkparams.mtx  = '0';
    end;
    walkparams.pnch = (if IsFeatureImplemented(FEAT_THE) &amp;&amp; <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() then TCR2_EL2().PnCH
                       else '0');
    if IsFeatureImplemented(FEAT_HAFT) &amp;&amp; walkparams.ha == '1' &amp;&amp; <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() then
        walkparams.haft = TCR2_EL2().HAFT;
    else
        walkparams.haft = '0';
    end;
    walkparams.emec = (if IsFeatureImplemented(FEAT_MEC) &amp;&amp;
                       <a link="func_IsSCTLR2EL2Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL2Enabled</a>() then SCTLR2_EL2().EMEC else '0');
    if IsFeatureImplemented(FEAT_MEC) &amp;&amp; ss == <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> &amp;&amp; <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() then
        walkparams.amec = TCR2_EL2().AMEC0;
    else
        walkparams.amec = '0';
    end;

    return walkparams;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_S1TTWParamsEL20" mylink="aarch64.translation.vmsa_walkparams.AArch64_S1TTWParamsEL20" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1TTWParamsEL20()
// =========================
// Gather stage 1 translation table walk parameters for EL2&amp;0 regime

func <anchor link="func_AArch64_S1TTWParamsEL20_3">AArch64_S1TTWParamsEL20</anchor>(el : bits(2), ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, varange : <a link="type_VARange" file="shared_pseudocode.xml">VARange</a>) =&gt; <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>
begin
    var walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>;

    if IsFeatureImplemented(FEAT_D128) &amp;&amp; <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() then
        walkparams.d128 = TCR2_EL2().D128;
    else
        walkparams.d128 = '0';
    end;

    if walkparams.d128 == '1' then
        walkparams.pie = '1';
    else
        walkparams.pie = (if IsFeatureImplemented(FEAT_S1PIE) &amp;&amp;
                          <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() then TCR2_EL2().PIE else '0');
    end;
    if IsFeatureImplemented(FEAT_S1PIE) then
        if !(<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().PIEn == '0' &amp;&amp;
               ImpDefBool(&quot;SCR_EL3.PIEn forces PIR_ELx or POR_ELx to zero&quot;)) then
            walkparams.pir   = PIR_EL2() as S1PIRType;
            walkparams.pire0 = PIRE0_EL2() as S1PIRType;
        else
            walkparams.pir   = Zeros{64} as S1PIRType;
            walkparams.pire0 = Zeros{64} as S1PIRType;
        end;
    end;

    if IsFeatureImplemented(FEAT_AIE) then
        walkparams.mair2 = MAIR2_EL2() as MAIRType;
    end;
    walkparams.aie  = (if IsFeatureImplemented(FEAT_AIE) &amp;&amp; <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() then TCR2_EL2().AIE
                       else '0');
    if varange == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then
        walkparams.tgx   = <a link="func_AArch64_S1DecodeTG0_1" file="shared_pseudocode.xml">AArch64_S1DecodeTG0</a>(TCR_EL2().TG0);
        walkparams.txsz  = TCR_EL2().T0SZ;
        walkparams.irgn  = TCR_EL2().IRGN0;
        walkparams.orgn  = TCR_EL2().ORGN0;
        walkparams.sh    = TCR_EL2().SH0;
        walkparams.tbi   = TCR_EL2().TBI0;

        walkparams.nfd   = if IsFeatureImplemented(FEAT_SVE)   then TCR_EL2().NFD0  else '0';
        walkparams.tbid  = if IsFeatureImplemented(FEAT_PAuth) then TCR_EL2().TBID0 else '0';
        walkparams.e0pd  = if IsFeatureImplemented(FEAT_E0PD)  then TCR_EL2().E0PD0 else '0';
        walkparams.hpd   = if IsFeatureImplemented(FEAT_HPDS)  then TCR_EL2().HPD0  else '0';
        if walkparams.hpd == '0' then
            if walkparams.aie == '1' then walkparams.hpd = '1'; end;
            if walkparams.pie == '1' then walkparams.hpd = '1'; end;
            if <a link="func_AArch64_S1POEnabled_1" file="shared_pseudocode.xml">AArch64_S1POEnabled</a>(<a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>) || <a link="func_AArch64_S1E0POEnabled_2" file="shared_pseudocode.xml">AArch64_S1E0POEnabled</a>(<a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>, '0') then
                walkparams.hpd = '1';
            end;
        end;
        if (IsFeatureImplemented(FEAT_MTE_NO_ADDRESS_TAGS) ||
              IsFeatureImplemented(FEAT_MTE_CANONICAL_TAGS)) then
            walkparams.mtx  = TCR_EL2().MTX0;
        else
            walkparams.mtx  = '0';
        end;
        walkparams.skl   = if walkparams.d128 == '1' then TTBR0_EL2().SKL else '00';
        walkparams.disch = if walkparams.d128 == '1' then TCR2_EL2().DisCH0 else '0';
        if IsFeatureImplemented(FEAT_ASID2) &amp;&amp; <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() then
            walkparams.fng = TCR2_EL2().FNG0;
        else
            walkparams.fng = '0';
        end;
    else
        walkparams.tgx   = <a link="func_AArch64_S1DecodeTG1_1" file="shared_pseudocode.xml">AArch64_S1DecodeTG1</a>(TCR_EL2().TG1);
        walkparams.txsz  = TCR_EL2().T1SZ;
        walkparams.irgn  = TCR_EL2().IRGN1;
        walkparams.orgn  = TCR_EL2().ORGN1;
        walkparams.sh    = TCR_EL2().SH1;
        walkparams.tbi   = TCR_EL2().TBI1;

        walkparams.nfd   = if IsFeatureImplemented(FEAT_SVE)   then TCR_EL2().NFD1  else '0';
        walkparams.tbid  = if IsFeatureImplemented(FEAT_PAuth) then TCR_EL2().TBID1 else '0';
        walkparams.e0pd  = if IsFeatureImplemented(FEAT_E0PD)  then TCR_EL2().E0PD1 else '0';
        walkparams.hpd   = if IsFeatureImplemented(FEAT_HPDS)  then TCR_EL2().HPD1  else '0';
        if walkparams.hpd == '0' then
            if walkparams.aie == '1' then walkparams.hpd = '1'; end;
            if walkparams.pie == '1' then walkparams.hpd = '1'; end;
            if <a link="func_AArch64_S1POEnabled_1" file="shared_pseudocode.xml">AArch64_S1POEnabled</a>(<a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>) || <a link="func_AArch64_S1E0POEnabled_2" file="shared_pseudocode.xml">AArch64_S1E0POEnabled</a>(<a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>, '0') then
                walkparams.hpd = '1';
            end;
        end;
        if (IsFeatureImplemented(FEAT_MTE_NO_ADDRESS_TAGS) ||
              IsFeatureImplemented(FEAT_MTE_CANONICAL_TAGS)) then
            walkparams.mtx  = TCR_EL2().MTX1;
        else
            walkparams.mtx  = '0';
        end;
        walkparams.skl   = if walkparams.d128 == '1' then TTBR1_EL2().SKL else '00';
        walkparams.disch = if walkparams.d128 == '1' then TCR2_EL2().DisCH1 else '0';
        if IsFeatureImplemented(FEAT_ASID2) &amp;&amp; <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() then
            walkparams.fng = TCR2_EL2().FNG1;
        else
            walkparams.fng = '0';
        end;
    end;

    walkparams.mair = MAIR_EL2() as MAIRType;
    walkparams.wxn  = SCTLR_EL2().WXN;
    walkparams.ps   = TCR_EL2().IPS;
    walkparams.ee   = SCTLR_EL2().EE;
    if (<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; (!IsFeatureImplemented(FEAT_RME) || IsFeatureImplemented(FEAT_SEL2))) then
        walkparams.sif = SCR_EL3().SIF;
    else
        walkparams.sif = '0';
    end;

    if IsFeatureImplemented(FEAT_LSMAOC) then
        walkparams.ntlsmd = SCTLR_EL2().nTLSMD;
    else
        walkparams.ntlsmd = '1';
    end;

    walkparams.cmow = if IsFeatureImplemented(FEAT_CMOW)   then SCTLR_EL2().CMOW else '0';
    walkparams.ha = if IsFeatureImplemented(FEAT_HAF) then TCR_EL2().HA else '0';
    if IsFeatureImplemented(FEAT_HAFDBS) &amp;&amp; walkparams.ha == '1' then
        walkparams.hd = TCR_EL2().HD;
    else
        walkparams.hd = '0';
    end;
    if (walkparams.tgx IN {<a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>, <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a>} &amp;&amp; IsFeatureImplemented(FEAT_LPA2) &amp;&amp;
          walkparams.d128 == '0') then
        walkparams.ds = TCR_EL2().DS;
    else
        walkparams.ds = '0';
    end;
    if IsFeatureImplemented(FEAT_PAN3) then
        walkparams.epan = if walkparams.pie == '0' then SCTLR_EL2().EPAN else '1';
    else
        walkparams.epan = '0';
    end;
    if IsFeatureImplemented(FEAT_THE) &amp;&amp; walkparams.d128 == '0' &amp;&amp; <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() then
        walkparams.pnch = TCR2_EL2().PnCH;
    else
        walkparams.pnch = '0';
    end;
    if IsFeatureImplemented(FEAT_HAFT) &amp;&amp; walkparams.ha == '1' &amp;&amp; <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() then
        walkparams.haft = TCR2_EL2().HAFT;
    else
        walkparams.haft = '0';
    end;
    walkparams.emec = (if IsFeatureImplemented(FEAT_MEC) &amp;&amp; <a link="func_IsSCTLR2EL2Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL2Enabled</a>()
                       then SCTLR2_EL2().EMEC else '0');
    if IsFeatureImplemented(FEAT_MEC) &amp;&amp; ss == <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> &amp;&amp; <a link="func_IsTCR2EL2Enabled_0" file="shared_pseudocode.xml">IsTCR2EL2Enabled</a>() then
        walkparams.amec = if varange == <a link="enum_VARange_LOWER" file="shared_pseudocode.xml">VARange_LOWER</a> then TCR2_EL2().AMEC0 else TCR2_EL2().AMEC1;
    else
        walkparams.amec = '0';
    end;

    return walkparams;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_S1TTWParamsEL3" mylink="aarch64.translation.vmsa_walkparams.AArch64_S1TTWParamsEL3" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S1TTWParamsEL3()
// ========================
// Gather stage 1 translation table walk parameters for EL3 regime

func <anchor link="func_AArch64_S1TTWParamsEL3_0">AArch64_S1TTWParamsEL3</anchor>() =&gt; <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>
begin
    var walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>;

    walkparams.tgx  = <a link="func_AArch64_S1DecodeTG0_1" file="shared_pseudocode.xml">AArch64_S1DecodeTG0</a>(TCR_EL3().TG0);
    walkparams.txsz = TCR_EL3().T0SZ;
    walkparams.ps   = TCR_EL3().PS;
    walkparams.irgn = TCR_EL3().IRGN0;
    walkparams.orgn = TCR_EL3().ORGN0;
    walkparams.sh   = TCR_EL3().SH0;
    walkparams.tbi  = TCR_EL3().TBI;
    walkparams.mair = MAIR_EL3() as MAIRType;
    walkparams.d128  = if IsFeatureImplemented(FEAT_D128)  then TCR_EL3().D128 else '0';
    walkparams.skl   = if walkparams.d128 == '1' then TTBR0_EL3().SKL else '00';
    walkparams.disch = if walkparams.d128 == '1' then TCR_EL3().DisCH0 else '0';

    if walkparams.d128 == '1' then
        walkparams.pie = '1';
    else
        walkparams.pie = if IsFeatureImplemented(FEAT_S1PIE) then TCR_EL3().PIE else '0';
    end;
    if IsFeatureImplemented(FEAT_S1PIE) then
        walkparams.pir = PIR_EL3() as S1PIRType;
    end;

    if IsFeatureImplemented(FEAT_AIE) then
        walkparams.mair2 = MAIR2_EL3() as MAIRType;
    end;
    walkparams.aie  = if IsFeatureImplemented(FEAT_AIE) then TCR_EL3().AIE else '0';
    walkparams.wxn  = SCTLR_EL3().WXN;
    walkparams.ee   = SCTLR_EL3().EE;
    walkparams.sif = (if !IsFeatureImplemented(FEAT_RME) || IsFeatureImplemented(FEAT_SEL2)
                      then SCR_EL3().SIF else '0');

    walkparams.tbid = if IsFeatureImplemented(FEAT_PAuth)  then TCR_EL3().TBID else '0';
    walkparams.hpd  = if IsFeatureImplemented(FEAT_HPDS)   then TCR_EL3().HPD else '0';
    if walkparams.hpd == '0' then
        if walkparams.aie == '1' then walkparams.hpd = '1'; end;
        if walkparams.pie == '1' then walkparams.hpd = '1'; end;
        if <a link="func_AArch64_S1POEnabled_1" file="shared_pseudocode.xml">AArch64_S1POEnabled</a>(<a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a>) then walkparams.hpd = '1'; end;
    end;
    walkparams.ha = if IsFeatureImplemented(FEAT_HAF) then TCR_EL3().HA else '0';
    if IsFeatureImplemented(FEAT_HAFDBS) &amp;&amp; walkparams.ha == '1' then
        walkparams.hd = TCR_EL3().HD;
    else
        walkparams.hd = '0';
    end;
    if (walkparams.tgx IN {<a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>, <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a>} &amp;&amp; IsFeatureImplemented(FEAT_LPA2) &amp;&amp;
          walkparams.d128 == '0') then
        walkparams.ds = TCR_EL3().DS;
    else
        walkparams.ds = '0';
    end;
    if (IsFeatureImplemented(FEAT_MTE_NO_ADDRESS_TAGS) ||
          IsFeatureImplemented(FEAT_MTE_CANONICAL_TAGS)) then
        walkparams.mtx  = TCR_EL3().MTX;
    else
        walkparams.mtx  = '0';
    end;
    if IsFeatureImplemented(FEAT_THE) &amp;&amp; walkparams.d128 == '0' then
        walkparams.pnch = TCR_EL3().PnCH;
    else
        walkparams.pnch = '0';
    end;
    if IsFeatureImplemented(FEAT_HAFT) &amp;&amp; walkparams.ha == '1' then
        walkparams.haft = TCR_EL3().HAFT;
    else
        walkparams.haft = '0';
    end;
    walkparams.emec = if IsFeatureImplemented(FEAT_MEC) then SCTLR2_EL3().EMEC else '0';

    return walkparams;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_S2DecodeTG0" mylink="aarch64.translation.vmsa_walkparams.AArch64_S2DecodeTG0" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2DecodeTG0()
// =====================
// Decode stage 2 granule size configuration bits TG0

func <anchor link="func_AArch64_S2DecodeTG0_1">AArch64_S2DecodeTG0</anchor>(tg0_in : bits(2)) =&gt; <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>
begin
    var tg0 : bits(2) = tg0_in;
    var tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>;

    if tg0 == '11' then
        tg0 = ImpDefBits{2}(&quot;TG0 encoded granule size&quot;);
    end;

    case tg0 of
        when '00' =&gt;   tgx = <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>;
        when '01' =&gt;   tgx = <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a>;
        when '10' =&gt;   tgx = <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a>;
    end;

    if !<a link="func_AArch64_HaveS2TG_1" file="shared_pseudocode.xml">AArch64_HaveS2TG</a>(tgx) then
        case ImpDefBits{2}(&quot;TG0 encoded granule size&quot;) of
            when '00' =&gt;   tgx = <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>;
            when '01' =&gt;   tgx = <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a>;
            when '10' =&gt;   tgx = <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a>;
        end;
    end;

    return tgx;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_S2MinTxSZ" mylink="aarch64.translation.vmsa_walkparams.AArch64_S2MinTxSZ" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_S2MinTxSZ()
// ===================
// Retrieve the minimum value of TxSZ indicating maximum input address size for stage 2

func <anchor link="func_AArch64_S2MinTxSZ_2">AArch64_S2MinTxSZ</anchor>(walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>, s1aarch64 : boolean) =&gt; integer
begin
    var ips : integer;

    if <a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>() == 56 then
        if walkparams.d128 == '1' then
            ips = 56;
        elsif walkparams.tgx == <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> || walkparams.ds == '1' then
            ips = 52;
        else
            ips = 48;
        end;
    elsif <a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>() == 52 then
        if walkparams.tgx == <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> || walkparams.ds == '1' then
            ips = 52;
        else
            ips = 48;
        end;
    else
        ips = <a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>();
    end;

    var min_txsz : integer = 64 - ips;
    if !s1aarch64 then
        // EL1 is AArch32
        min_txsz = Min(min_txsz, 24);
    end;

    return min_txsz;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/AArch64_SS2TTWParams" mylink="aarch64.translation.vmsa_walkparams.AArch64_SS2TTWParams" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_SS2TTWParams()
// ======================
// Gather walk parameters specific for secure stage 2 translation

func <anchor link="func_AArch64_SS2TTWParams_2">AArch64_SS2TTWParams</anchor>(ipaspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>, s1aarch64 : boolean) =&gt; <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>
begin
    var walkparams : <a link="type_S2TTWParams" file="shared_pseudocode.xml">S2TTWParams</a>;

    walkparams.d128 = if IsFeatureImplemented(FEAT_D128) then VTCR_EL2().D128 else '0';
    if ipaspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> then
        walkparams.tgx  = <a link="func_AArch64_S2DecodeTG0_1" file="shared_pseudocode.xml">AArch64_S2DecodeTG0</a>(VSTCR_EL2().TG0);
        walkparams.txsz = VSTCR_EL2().T0SZ;
        if walkparams.d128 == '1' then
            walkparams.skl = VSTTBR_EL2().SKL;
        else
            walkparams.sl0 = VSTCR_EL2().SL0;
        end;
        if walkparams.tgx == <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a> &amp;&amp; IsFeatureImplemented(FEAT_LPA2) then
            walkparams.sl2 = VSTCR_EL2().SL2 AND VTCR_EL2().DS;
        else
            walkparams.sl2 = '0';
        end;
    elsif ipaspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> then
        walkparams.tgx  = <a link="func_AArch64_S2DecodeTG0_1" file="shared_pseudocode.xml">AArch64_S2DecodeTG0</a>(VTCR_EL2().TG0);
        walkparams.txsz = VTCR_EL2().T0SZ;
        if walkparams.d128 == '1' then
            walkparams.skl = VTTBR_EL2().SKL;
        else
            walkparams.sl0 = VTCR_EL2().SL0;
        end;
        if walkparams.tgx == <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a> &amp;&amp; IsFeatureImplemented(FEAT_LPA2) then
            walkparams.sl2 = VTCR_EL2().SL2 AND VTCR_EL2().DS;
        else
            walkparams.sl2 = '0';
        end;
    else
        unreachable;
    end;

    walkparams.sw   = VSTCR_EL2().SW;
    walkparams.nsw  = VTCR_EL2().NSW;
    walkparams.sa   = VSTCR_EL2().SA;
    walkparams.nsa  = VTCR_EL2().NSA;
    walkparams.vm   = HCR_EL2().VM OR HCR_EL2().DC;
    walkparams.ps   = VTCR_EL2().PS;
    walkparams.irgn = VTCR_EL2().IRGN0;
    walkparams.orgn = VTCR_EL2().ORGN0;
    walkparams.sh   = VTCR_EL2().SH0;
    walkparams.ee   = SCTLR_EL2().EE;

    walkparams.ptw = if HCR_EL2().TGE == '0'                then HCR_EL2().PTW else '0';
    walkparams.fwb = if IsFeatureImplemented(FEAT_S2FWB)  then HCR_EL2().FWB else '0';
    walkparams.ha = if IsFeatureImplemented(FEAT_HAF) then VTCR_EL2().HA else '0';
    if IsFeatureImplemented(FEAT_HAFDBS) &amp;&amp; walkparams.ha == '1' then
        walkparams.hd = VTCR_EL2().HD;
    else
        walkparams.hd = '0';
    end;
    if walkparams.tgx IN {<a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a>, <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a>} &amp;&amp; IsFeatureImplemented(FEAT_LPA2) then
        walkparams.ds = VTCR_EL2().DS;
    else
        walkparams.ds = '0';
    end;
    walkparams.cmow = (if IsFeatureImplemented(FEAT_CMOW) &amp;&amp; <a link="func_IsHCRXEL2Enabled_0" file="shared_pseudocode.xml">IsHCRXEL2Enabled</a>() then HCRX_EL2().CMOW
                       else '0');
    if walkparams.d128 == '1' then
        walkparams.s2pie = '1';
    else
        walkparams.s2pie = if IsFeatureImplemented(FEAT_S2PIE) then VTCR_EL2().S2PIE else '0';
    end;
    if IsFeatureImplemented(FEAT_S2PIE) then
        if !(<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().PIEn == '0' &amp;&amp;
               ImpDefBool(&quot;SCR_EL3.PIEn forces PIR_ELx or POR_ELx to zero&quot;)) then
            walkparams.s2pir = S2PIR_EL2() as S2PIRType;
        else
            walkparams.s2pir = Zeros{64} as S2PIRType;
        end;
    end;
    if IsFeatureImplemented(FEAT_THE) &amp;&amp; walkparams.d128 != '1' then
        walkparams.assuredonly = VTCR_EL2().AssuredOnly;
    else
        walkparams.assuredonly = '0';
    end;
    walkparams.tl0   = if IsFeatureImplemented(FEAT_THE) then VTCR_EL2().TL0 else '0';
    walkparams.tl1   = if IsFeatureImplemented(FEAT_THE) then VTCR_EL2().TL1 else '0';
    if IsFeatureImplemented(FEAT_HAFT) &amp;&amp; walkparams.ha == '1' then
        walkparams.haft = VTCR_EL2().HAFT;
    else
        walkparams.haft = '0';
    end;
    walkparams.emec = '0';
    if (IsFeatureImplemented(FEAT_HDBSS) &amp;&amp; walkparams.hd == '1' &amp;&amp;
          (!<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || SCR_EL3().HDBSSEn == '1')) then
        walkparams.hdbss = VTCR_EL2().HDBSS;
    else
        walkparams.hdbss = '0';
    end;

    return walkparams;
end;</pstext></ps>
    <ps name="aarch64/translation/vmsa_walkparams/S2DCacheEnabled" mylink="aarch64.translation.vmsa_walkparams.S2DCacheEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// S2DCacheEnabled()
// =================
// Returns TRUE if Stage 2 Data access cacheability is enabled

func <anchor link="func_S2DCacheEnabled_0">S2DCacheEnabled</anchor>() =&gt; boolean
begin
    return HCR_EL2().CD == '0';
end;</pstext></ps>
    <ps name="parameters" mylink="parameters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">constant integer{} NUM_ASIDBITS = 16;
constant integer{} NUM_VMIDBITS = 16;</pstext></ps>
    <ps name="shared/debug/ClearStickyErrors/ClearStickyErrors" mylink="shared.debug.ClearStickyErrors.ClearStickyErrors" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ClearStickyErrors()
// ===================

func <anchor link="func_ClearStickyErrors_0">ClearStickyErrors</anchor>()
begin
    EDSCR().TXU = '0';            // Clear TX underrun flag
    EDSCR().RXO = '0';            // Clear RX overrun flag

    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then            // in Debug state
        EDSCR().ITO = '0';        // Clear ITR overrun flag
    end;

    // If halted and the ITR is not empty then it is UNPREDICTABLE whether the EDSCR.ERR is cleared.
    // The UNPREDICTABLE behavior also affects the instructions in flight, but this is not described
    // in the pseudocode.
    if (<a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() &amp;&amp; EDSCR().ITE == '0' &amp;&amp;
          <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_CLEARERRITEZERO" file="shared_pseudocode.xml">Unpredictable_CLEARERRITEZERO</a>)) then
        return;
    end;
    EDSCR().ERR = '0';            // Clear cumulative error flag

    return;
end;</pstext></ps>
    <ps name="shared/debug/DebugTarget/DebugTarget" mylink="shared.debug.DebugTarget.DebugTarget" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DebugTarget()
// =============
// Returns the debug exception target Exception level

func <anchor link="func_DebugTarget_0">DebugTarget</anchor>() =&gt; bits(2)
begin
    let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>();
    return <a link="func_DebugTargetFrom_1" file="shared_pseudocode.xml">DebugTargetFrom</a>(ss);
end;</pstext></ps>
    <ps name="shared/debug/DebugTarget/DebugTargetFrom" mylink="shared.debug.DebugTarget.DebugTargetFrom" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DebugTargetFrom()
// =================

func <anchor link="func_DebugTargetFrom_1">DebugTargetFrom</anchor>(from_state : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>) =&gt; bits(2)
begin
    var route_to_el2 : boolean;
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; (from_state != <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> ||
        (IsFeatureImplemented(FEAT_SEL2) &amp;&amp; (!<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || SCR_EL3().EEL2 == '1'))) then
        if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
            route_to_el2 = (HDCR().TDE == '1' || HCR().TGE == '1');
        else
            route_to_el2 = (MDCR_EL2().TDE == '1' || HCR_EL2().TGE == '1');
        end;
    else
        route_to_el2 = FALSE;
    end;

    var target : bits(2);
    if route_to_el2 then
        target = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() &amp;&amp; from_state == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
        target = <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
    else
        target = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    end;

    return target;
end;</pstext></ps>
    <ps name="shared/debug/DoubleLockStatus/DoubleLockStatus" mylink="shared.debug.DoubleLockStatus.DoubleLockStatus" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DoubleLockStatus()
// ==================
// Returns the state of the OS Double Lock.
//    FALSE if OSDLR_EL1.DLK == 0 or DBGPRCR_EL1.CORENPDRQ == 1 or the PE is in Debug state.
//    TRUE if OSDLR_EL1.DLK == 1 and DBGPRCR_EL1.CORENPDRQ == 0 and the PE is in Non-debug state.

func <anchor link="func_DoubleLockStatus_0">DoubleLockStatus</anchor>() =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_DoubleLock) then
        return FALSE;
    end;
    if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        return DBGOSDLR().DLK == '1' &amp;&amp; DBGPRCR().CORENPDRQ == '0' &amp;&amp; !<a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>();
    else
        return OSDLR_EL1().DLK == '1' &amp;&amp; DBGPRCR_EL1().CORENPDRQ == '0' &amp;&amp; !<a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>();
    end;
end;</pstext></ps>
    <ps name="shared/debug/OSLockStatus/OSLockStatus" mylink="shared.debug.OSLockStatus.OSLockStatus" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// OSLockStatus()
// ==============
// Returns the state of the OS Lock.

readonly func <anchor link="func_OSLockStatus_0">OSLockStatus</anchor>() =&gt; boolean
begin
    return (if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then DBGOSLSR().OSLK else OSLSR_EL1().OSLK) == '1';
end;</pstext></ps>
    <ps name="shared/debug/SoftwareLockStatus/Component" mylink="shared.debug.SoftwareLockStatus.Component" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Component
// =========
// Component Types.

type <anchor link="type_Component">Component</anchor> of enumeration {
        <anchor link="enum_Component_AMU">Component_AMU</anchor>,
        <anchor link="enum_Component_ETE">Component_ETE</anchor>,
        <anchor link="enum_Component_TRBE">Component_TRBE</anchor>,
        <anchor link="enum_Component_RAS">Component_RAS</anchor>,
        <anchor link="enum_Component_GIC">Component_GIC</anchor>,
        <anchor link="enum_Component_PMU">Component_PMU</anchor>,
        <anchor link="enum_Component_Debug">Component_Debug</anchor>,
        <anchor link="enum_Component_CTI">Component_CTI</anchor>
};</pstext></ps>
    <ps name="shared/debug/SoftwareLockStatus/GetAccessComponent" mylink="shared.debug.SoftwareLockStatus.GetAccessComponent" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetAccessComponent()
// ====================
// Determines the component by decoding the physical address in the address descriptor.

impdef func <anchor link="func_GetAccessComponent_1">GetAccessComponent</anchor>(addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>) =&gt; <a link="type_Component" file="shared_pseudocode.xml">Component</a>
begin
    return <a link="enum_Component_Debug" file="shared_pseudocode.xml">Component_Debug</a>;
end;</pstext></ps>
    <ps name="shared/debug/SoftwareLockStatus/SoftwareLockStatus" mylink="shared.debug.SoftwareLockStatus.SoftwareLockStatus" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SoftwareLockStatus()
// ====================
// Returns the state of the Software Lock.

func <anchor link="func_SoftwareLockStatus_1">SoftwareLockStatus</anchor>(addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>) =&gt; boolean
begin
    let component : <a link="type_Component" file="shared_pseudocode.xml">Component</a> = <a link="func_GetAccessComponent_1" file="shared_pseudocode.xml">GetAccessComponent</a>(addrdesc);
    if !<a link="func_HaveSoftwareLock_1" file="shared_pseudocode.xml">HaveSoftwareLock</a>(component) then
        return FALSE;
    end;
    case component of
        when <a link="enum_Component_ETE" file="shared_pseudocode.xml">Component_ETE</a>   =&gt; return TRCLSR().SLK == '1';
        when <a link="enum_Component_Debug" file="shared_pseudocode.xml">Component_Debug</a> =&gt; return EDLSR().SLK == '1';
        when <a link="enum_Component_PMU" file="shared_pseudocode.xml">Component_PMU</a>   =&gt; return PMLSR().SLK == '1';
        when <a link="enum_Component_CTI" file="shared_pseudocode.xml">Component_CTI</a>   =&gt; return CTILSR().SLK == '1';
        otherwise            =&gt; return FALSE;
    end;
end;</pstext></ps>
    <ps name="shared/debug/amu/IsG1ActivityMonitorImplemented" mylink="shared.debug.amu.IsG1ActivityMonitorImplemented" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsG1ActivityMonitorImplemented()
// ================================
// Returns TRUE if a G1 activity monitor is implemented for the counter
// and FALSE otherwise.

impdef func <anchor link="func_IsG1ActivityMonitorImplemented_1">IsG1ActivityMonitorImplemented</anchor>(i : integer) =&gt; boolean
begin
    case i of
        when 0 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor is implemented for counter 0&quot;));
        when 1 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor is implemented for counter 1&quot;));
        when 2 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor is implemented for counter 2&quot;));
        when 3 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor is implemented for counter 3&quot;));
        when 4 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor is implemented for counter 4&quot;));
        when 5 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor is implemented for counter 5&quot;));
        when 6 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor is implemented for counter 6&quot;));
        when 7 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor is implemented for counter 7&quot;));
        when 8 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor is implemented for counter 8&quot;));
        when 9 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor is implemented for counter 9&quot;));
        when 10 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor is implemented for counter 10&quot;));
        when 11 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor is implemented for counter 11&quot;));
        when 12 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor is implemented for counter 12&quot;));
        when 13 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor is implemented for counter 13&quot;));
        when 14 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor is implemented for counter 14&quot;));
        when 15 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor is implemented for counter 15&quot;));
        otherwise =&gt;
            return FALSE;
    end;
end;</pstext></ps>
    <ps name="shared/debug/amu/IsG1ActivityMonitorOffsetImplemented" mylink="shared.debug.amu.IsG1ActivityMonitorOffsetImplemented" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsG1ActivityMonitorOffsetImplemented()
// ======================================
// Returns TRUE if a G1 activity monitor offset is implemented for the counter,
// and FALSE otherwise.

impdef func <anchor link="func_IsG1ActivityMonitorOffsetImplemented_1">IsG1ActivityMonitorOffsetImplemented</anchor>(i : integer) =&gt; boolean
begin
    case i of
        when 0 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor offset is implemented for counter 0&quot;));
        when 1 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor offset is implemented for counter 1&quot;));
        when 2 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor offset is implemented for counter 2&quot;));
        when 3 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor offset is implemented for counter 3&quot;));
        when 4 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor offset is implemented for counter 4&quot;));
        when 5 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor offset is implemented for counter 5&quot;));
        when 6 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor offset is implemented for counter 6&quot;));
        when 7 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor offset is implemented for counter 7&quot;));
        when 8 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor offset is implemented for counter 8&quot;));
        when 9 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor offset is implemented for counter 9&quot;));
        when 10 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor offset is implemented for counter 10&quot;));
        when 11 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor offset is implemented for counter 11&quot;));
        when 12 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor offset is implemented for counter 12&quot;));
        when 13 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor offset is implemented for counter 13&quot;));
        when 14 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor offset is implemented for counter 14&quot;));
        when 15 =&gt;
            return (ImpDefBool(
                    &quot;G1 activity monitor offset is implemented for counter 15&quot;));
        otherwise =&gt;
            return FALSE;
    end;
end;</pstext></ps>
    <ps name="shared/debug/authentication/AllowExternalDebugAccess" mylink="shared.debug.authentication.AllowExternalDebugAccess" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AllowExternalDebugAccess()
// ==========================
// Returns TRUE if an external debug interface access to the External DBGBVR&lt;n&gt;_EL1,
// DBGBCR&lt;n&gt;_EL1, DBGWVR&lt;n&gt;_EL1, DBGWCR&lt;n&gt;_EL1 registers, and, from Armv8.2, the
// OSLAR_EL1 register is allowed for the access. Returns FALSE otherwise.

func <anchor link="func_AllowExternalDebugAccess_1">AllowExternalDebugAccess</anchor>(addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>) =&gt; boolean
begin
    // The access may also be subject to OS Lock, power-down, etc.
    if IsFeatureImplemented(FEAT_RME) then
        case MDCR_EL3().[EDADE,EDAD] of
            when '00' =&gt; return TRUE;
            when '01' =&gt; return addrdesc.paddress.paspace IN {<a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>, <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>};
            when '10' =&gt; return addrdesc.paddress.paspace IN {<a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>, <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>};
            when '11' =&gt; return addrdesc.paddress.paspace == <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>;
        end;
    end;

    if IsFeatureImplemented(FEAT_Debugv8p4) then
        if addrdesc.paddress.paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> then return TRUE; end;
    else
        if !<a link="func_ExternalInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalInvasiveDebugEnabled</a>() then return FALSE; end;
        if <a link="func_ExternalSecureInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalSecureInvasiveDebugEnabled</a>() then return TRUE; end;
    end;

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        let EDAD_bit : bit = if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then SDCR().EDAD else MDCR_EL3().EDAD;
        return EDAD_bit == '0';
    else
        return <a link="func_NonSecureOnlyImplementation_0" file="shared_pseudocode.xml">NonSecureOnlyImplementation</a>();
    end;
end;</pstext></ps>
    <ps name="shared/debug/authentication/AllowExternalPMSSAccess" mylink="shared.debug.authentication.AllowExternalPMSSAccess" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AllowExternalPMSSAccess()
// =========================
// Returns TRUE if an external debug interface access to the PMU Snapshot
// registers is allowed for the given Security state, FALSE otherwise.

func <anchor link="func_AllowExternalPMSSAccess_1">AllowExternalPMSSAccess</anchor>(addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>) =&gt; boolean
begin
    assert IsFeatureImplemented(FEAT_PMUv3_SS) &amp;&amp; <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>();
    // FEAT_Debugv8p4 is always implemented when FEAT_PMUv3_SS is implemented.
    assert IsFeatureImplemented(FEAT_Debugv8p4);

    // The access may also be subject to the OS Double Lock, power-down, etc.
    var epmssad : bits(2) = if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then MDCR_EL3().EPMSSAD else '11';

    // Check for reserved values
    if !IsFeatureImplemented(FEAT_RME) &amp;&amp; epmssad IN {'01','10'} then
        (-, epmssad) = ConstrainUnpredictableBits{2}(<a link="enum_Unpredictable_RESEPMSSAD" file="shared_pseudocode.xml">Unpredictable_RESEPMSSAD</a>);
        // The value returned by ConstrainUnpredictableBits() must be a
        // non-reserved value
        assert epmssad IN {'00','11'};
    end;

    case epmssad of
        when '00' =&gt;
            if IsFeatureImplemented(FEAT_RME) then
                return addrdesc.paddress.paspace == <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>;
            else
                return addrdesc.paddress.paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>;
            end;
        when '01' =&gt;
            assert IsFeatureImplemented(FEAT_RME);
            return addrdesc.paddress.paspace IN {<a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>, <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>};
        when '10' =&gt;
            assert IsFeatureImplemented(FEAT_RME);
            return addrdesc.paddress.paspace IN {<a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>, <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>};
        when '11' =&gt;
            return TRUE;
    end;
end;</pstext></ps>
    <ps name="shared/debug/authentication/AllowExternalPMUAccess" mylink="shared.debug.authentication.AllowExternalPMUAccess" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AllowExternalPMUAccess()
// ========================
// Returns TRUE if an external debug interface access to the PMU registers is
// allowed for the given Security state, FALSE otherwise.

func <anchor link="func_AllowExternalPMUAccess_1">AllowExternalPMUAccess</anchor>(addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>) =&gt; boolean
begin
    // The access may also be subject to OS Lock, power-down, etc.
    if IsFeatureImplemented(FEAT_RME) then
        case MDCR_EL3().[EPMADE,EPMAD] of
            when '00' =&gt; return TRUE;
            when '01' =&gt; return addrdesc.paddress.paspace IN {<a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>, <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>};
            when '10' =&gt; return addrdesc.paddress.paspace IN {<a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>, <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>};
            when '11' =&gt; return addrdesc.paddress.paspace == <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>;
        end;
    end;

    if IsFeatureImplemented(FEAT_Debugv8p4) then
        if addrdesc.paddress.paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> then return TRUE; end;
    else
        if !<a link="func_ExternalInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalInvasiveDebugEnabled</a>() then return FALSE; end;
        if <a link="func_ExternalSecureInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalSecureInvasiveDebugEnabled</a>() then return TRUE; end;
    end;

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        let EPMAD_bit : bit = if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then SDCR().EPMAD else MDCR_EL3().EPMAD;
        return EPMAD_bit == '0';
    else
        return <a link="func_NonSecureOnlyImplementation_0" file="shared_pseudocode.xml">NonSecureOnlyImplementation</a>();
    end;
end;</pstext></ps>
    <ps name="shared/debug/authentication/AllowExternalTraceAccess" mylink="shared.debug.authentication.AllowExternalTraceAccess" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AllowExternalTraceAccess()
// ==========================
// Returns TRUE if an external Trace access to the Trace registers is allowed for the
// given PAS, FALSE otherwise.

func <anchor link="func_AllowExternalTraceAccess_1">AllowExternalTraceAccess</anchor>(addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>) =&gt; boolean
begin
    // The access may also be subject to OS lock, power-down, etc.
    if !IsFeatureImplemented(FEAT_TRBE) then return TRUE; end;
    assert IsFeatureImplemented(FEAT_Debugv8p4);
    if IsFeatureImplemented(FEAT_RME) then
        case MDCR_EL3().[ETADE,ETAD] of
            when '00' =&gt; return TRUE;
            when '01' =&gt; return addrdesc.paddress.paspace IN {<a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>, <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>};
            when '10' =&gt; return addrdesc.paddress.paspace IN {<a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>, <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>};
            when '11' =&gt; return addrdesc.paddress.paspace == <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>;
        end;
    end;

    if addrdesc.paddress.paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> then return TRUE; end;
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        // External Trace access is not supported for EL3 using AArch32
        assert !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
        return MDCR_EL3().ETAD == '0';
    else
        return <a link="func_NonSecureOnlyImplementation_0" file="shared_pseudocode.xml">NonSecureOnlyImplementation</a>();
    end;
end;</pstext></ps>
    <ps name="shared/debug/authentication/AllowRASMemoryMappedAccess" mylink="shared.debug.authentication.AllowRASMemoryMappedAccess" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AllowRASMemoryMappedAccess()
// ============================
// Returns TRUE if read and/or write access to RAS memory-mapped registers is
// permitted for the given access.

func <anchor link="func_AllowRASMemoryMappedAccess_2">AllowRASMemoryMappedAccess</anchor>(addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, iswrite : boolean) =&gt; boolean
begin
    // An access from the most secure implemented PAS is always permitted.
    if <a link="func_IsMostSecureAccess_1" file="shared_pseudocode.xml">IsMostSecureAccess</a>(addrdesc) then
        return TRUE;
    end;

    if IsFeatureImplemented(FEAT_RASSA_ACR) &amp;&amp; IsFeatureImplemented(FEAT_RASSAv2) then
        var ra : bits(2);
        let implements_rl_and_s : boolean = (IsFeatureImplemented(FEAT_RME) &amp;&amp;
                                             ImpDefBool(
              &quot;the error record group allows configuration of Secure and Realm register accesses&quot;));
        if <a link="func_IsAccessRealm_1" file="shared_pseudocode.xml">IsAccessRealm</a>(addrdesc) then
            ra = if implements_rl_and_s then ERRACR().RLRA else ERRACR().NSRA;
        elsif <a link="func_IsAccessSecure_1" file="shared_pseudocode.xml">IsAccessSecure</a>(addrdesc) then
            ra = if implements_rl_and_s then ERRACR().SRA else ERRACR().NSRA;
        elsif <a link="func_IsAccessNonSecure_1" file="shared_pseudocode.xml">IsAccessNonSecure</a>(addrdesc) then
            ra = ERRACR().NSRA;
        else
            unreachable;
        end;
        // '10' is reserved
        if ra == '10' then (-, ra) = ConstrainUnpredictableBits{2}(<a link="enum_Unpredictable_RES_RA" file="shared_pseudocode.xml">Unpredictable_RES_RA</a>); end;
        // Interpret configured permissions to a boolean for the requested access
        case ra of
            when '00' =&gt; return FALSE;          // RAZ/WI =&gt; no read or write
            when '01' =&gt; return !iswrite;       // RO =&gt; reads allowed, writes not
            when '11' =&gt; return TRUE;           // RW =&gt; both allowed
            otherwise =&gt; unreachable;
        end;
    end;
    return ImpDefBool(&quot;error records are accessible to all PAS&quot;);
end;</pstext></ps>
    <ps name="shared/debug/authentication/Debug" mylink="shared.debug.authentication.Debug" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Debug authentication signals
// ============================

var <anchor link="global_DBGEN">DBGEN</anchor> : <a link="type_Signal" file="shared_pseudocode.xml">Signal</a>;
var <anchor link="global_NIDEN">NIDEN</anchor> : <a link="type_Signal" file="shared_pseudocode.xml">Signal</a>;
var <anchor link="global_SPIDEN">SPIDEN</anchor> : <a link="type_Signal" file="shared_pseudocode.xml">Signal</a>;
var <anchor link="global_SPNIDEN">SPNIDEN</anchor> : <a link="type_Signal" file="shared_pseudocode.xml">Signal</a>;
var <anchor link="global_RLPIDEN">RLPIDEN</anchor> : <a link="type_Signal" file="shared_pseudocode.xml">Signal</a>;
var <anchor link="global_RTPIDEN">RTPIDEN</anchor> : <a link="type_Signal" file="shared_pseudocode.xml">Signal</a>;</pstext></ps>
    <ps name="shared/debug/authentication/ExternalInvasiveDebugEnabled" mylink="shared.debug.authentication.ExternalInvasiveDebugEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExternalInvasiveDebugEnabled()
// ==============================
// The definition of this function is IMPLEMENTATION DEFINED.
// In the recommended interface, this function returns the state of the DBGEN signal.

readonly func <anchor link="func_ExternalInvasiveDebugEnabled_0">ExternalInvasiveDebugEnabled</anchor>() =&gt; boolean
begin
    return <a link="global_DBGEN" file="shared_pseudocode.xml">DBGEN</a> == <a link="enum_HIGH" file="shared_pseudocode.xml">HIGH</a>;
end;</pstext></ps>
    <ps name="shared/debug/authentication/ExternalNoninvasiveDebugAllowed" mylink="shared.debug.authentication.ExternalNoninvasiveDebugAllowed" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExternalNoninvasiveDebugAllowed()
// =================================
// Returns TRUE if Trace and PC Sample-based Profiling are allowed

func <anchor link="func_ExternalNoninvasiveDebugAllowed_0">ExternalNoninvasiveDebugAllowed</anchor>() =&gt; boolean
begin
    return <a link="func_ExternalNoninvasiveDebugAllowed_1" file="shared_pseudocode.xml">ExternalNoninvasiveDebugAllowed</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
end;

// ExternalNoninvasiveDebugAllowed()
// =================================

func <anchor link="func_ExternalNoninvasiveDebugAllowed_1">ExternalNoninvasiveDebugAllowed</anchor>(el : bits(2)) =&gt; boolean
begin
    if !<a link="func_ExternalNoninvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalNoninvasiveDebugEnabled</a>() then return FALSE; end;
    let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(el);

    if ((<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>)) &amp;&amp; el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp;
        ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> &amp;&amp; SDER().SUNIDEN == '1') then
        return TRUE;
    end;

    case ss of
        when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt; return TRUE;
        when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;    return <a link="func_ExternalSecureNoninvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalSecureNoninvasiveDebugEnabled</a>();
        when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;     return <a link="func_ExternalRealmNoninvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalRealmNoninvasiveDebugEnabled</a>();
        when <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a> =&gt;      return <a link="func_ExternalRootNoninvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalRootNoninvasiveDebugEnabled</a>();
    end;
end;</pstext></ps>
    <ps name="shared/debug/authentication/ExternalNoninvasiveDebugEnabled" mylink="shared.debug.authentication.ExternalNoninvasiveDebugEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExternalNoninvasiveDebugEnabled()
// =================================
// This function returns TRUE if the FEAT_Debugv8p4 is implemented.
// Otherwise, this function is IMPLEMENTATION DEFINED, and, in the
// recommended interface, ExternalNoninvasiveDebugEnabled returns
// the state of the (DBGEN OR NIDEN) signal.

readonly func <anchor link="func_ExternalNoninvasiveDebugEnabled_0">ExternalNoninvasiveDebugEnabled</anchor>() =&gt; boolean
begin
    return (IsFeatureImplemented(FEAT_Debugv8p4) || <a link="func_ExternalInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalInvasiveDebugEnabled</a>() ||
            <a link="global_NIDEN" file="shared_pseudocode.xml">NIDEN</a> == <a link="enum_HIGH" file="shared_pseudocode.xml">HIGH</a>);
end;</pstext></ps>
    <ps name="shared/debug/authentication/ExternalRealmInvasiveDebugEnabled" mylink="shared.debug.authentication.ExternalRealmInvasiveDebugEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExternalRealmInvasiveDebugEnabled()
// ===================================
// The definition of this function is IMPLEMENTATION DEFINED.
// In the recommended interface, this function returns the state of the
// (DBGEN AND RLPIDEN) signal.

readonly func <anchor link="func_ExternalRealmInvasiveDebugEnabled_0">ExternalRealmInvasiveDebugEnabled</anchor>() =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_RME) then return FALSE; end;
    return <a link="func_ExternalInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalInvasiveDebugEnabled</a>() &amp;&amp; <a link="global_RLPIDEN" file="shared_pseudocode.xml">RLPIDEN</a> == <a link="enum_HIGH" file="shared_pseudocode.xml">HIGH</a>;
end;</pstext></ps>
    <ps name="shared/debug/authentication/ExternalRealmNoninvasiveDebugEnabled" mylink="shared.debug.authentication.ExternalRealmNoninvasiveDebugEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExternalRealmNoninvasiveDebugEnabled()
// ======================================
// The definition of this function is IMPLEMENTATION DEFINED.
// In the recommended interface, this function returns the state of the
// (DBGEN AND RLPIDEN) signal.

readonly func <anchor link="func_ExternalRealmNoninvasiveDebugEnabled_0">ExternalRealmNoninvasiveDebugEnabled</anchor>() =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_RME) then return FALSE; end;
    return <a link="func_ExternalRealmInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalRealmInvasiveDebugEnabled</a>();
end;</pstext></ps>
    <ps name="shared/debug/authentication/ExternalRootInvasiveDebugEnabled" mylink="shared.debug.authentication.ExternalRootInvasiveDebugEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExternalRootInvasiveDebugEnabled()
// ==================================
// The definition of this function is IMPLEMENTATION DEFINED.
// In the recommended interface, this function returns the state of the
// (DBGEN AND RLPIDEN AND RTPIDEN AND SPIDEN) signal when FEAT_SEL2 is implemented
// and the (DBGEN AND RLPIDEN AND RTPIDEN) signal when FEAT_SEL2 is not implemented.

func <anchor link="func_ExternalRootInvasiveDebugEnabled_0">ExternalRootInvasiveDebugEnabled</anchor>() =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_RME) then return FALSE; end;
    return (<a link="func_ExternalInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalInvasiveDebugEnabled</a>() &amp;&amp;
            (!IsFeatureImplemented(FEAT_SEL2) || <a link="func_ExternalSecureInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalSecureInvasiveDebugEnabled</a>()) &amp;&amp;
            <a link="func_ExternalRealmInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalRealmInvasiveDebugEnabled</a>() &amp;&amp;
            <a link="global_RTPIDEN" file="shared_pseudocode.xml">RTPIDEN</a> == <a link="enum_HIGH" file="shared_pseudocode.xml">HIGH</a>);
end;</pstext></ps>
    <ps name="shared/debug/authentication/ExternalRootNoninvasiveDebugEnabled" mylink="shared.debug.authentication.ExternalRootNoninvasiveDebugEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExternalRootNoninvasiveDebugEnabled()
// =====================================
// The definition of this function is IMPLEMENTATION DEFINED.
// In the recommended interface, this function returns the state of the
// (DBGEN AND RLPIDEN AND SPIDEN AND RTPIDEN) signal.

func <anchor link="func_ExternalRootNoninvasiveDebugEnabled_0">ExternalRootNoninvasiveDebugEnabled</anchor>() =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_RME) then return FALSE; end;
    return <a link="func_ExternalRootInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalRootInvasiveDebugEnabled</a>();
end;</pstext></ps>
    <ps name="shared/debug/authentication/ExternalSecureInvasiveDebugEnabled" mylink="shared.debug.authentication.ExternalSecureInvasiveDebugEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExternalSecureInvasiveDebugEnabled()
// ====================================
// The definition of this function is IMPLEMENTATION DEFINED.
// In the recommended interface, this function returns the state of the (DBGEN AND SPIDEN) signal.
// CoreSight allows asserting SPIDEN without also asserting DBGEN, but this is not recommended.

readonly func <anchor link="func_ExternalSecureInvasiveDebugEnabled_0">ExternalSecureInvasiveDebugEnabled</anchor>() =&gt; boolean
begin
    if !<a link="func_HaveSecureState_0" file="shared_pseudocode.xml">HaveSecureState</a>() then
        return IsFeatureImplemented(FEAT_RME) &amp;&amp; <a link="global_RTPIDEN" file="shared_pseudocode.xml">RTPIDEN</a> == <a link="enum_HIGH" file="shared_pseudocode.xml">HIGH</a>;
    end;
    return <a link="func_ExternalInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalInvasiveDebugEnabled</a>() &amp;&amp; <a link="global_SPIDEN" file="shared_pseudocode.xml">SPIDEN</a> == <a link="enum_HIGH" file="shared_pseudocode.xml">HIGH</a>;
end;</pstext></ps>
    <ps name="shared/debug/authentication/ExternalSecureNoninvasiveDebugEnabled" mylink="shared.debug.authentication.ExternalSecureNoninvasiveDebugEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExternalSecureNoninvasiveDebugEnabled()
// =======================================
// This function returns the value of ExternalSecureInvasiveDebugEnabled() when FEAT_Debugv8p4
// is implemented. Otherwise, the definition of this function is IMPLEMENTATION DEFINED.
// In the recommended interface, this function returns the state of the (DBGEN OR NIDEN) AND
// (SPIDEN OR SPNIDEN) signal.

readonly func <anchor link="func_ExternalSecureNoninvasiveDebugEnabled_0">ExternalSecureNoninvasiveDebugEnabled</anchor>() =&gt; boolean
begin
    if !<a link="func_HaveSecureState_0" file="shared_pseudocode.xml">HaveSecureState</a>() then return FALSE; end;
    if !IsFeatureImplemented(FEAT_Debugv8p4) then
        return (<a link="func_ExternalNoninvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalNoninvasiveDebugEnabled</a>() &amp;&amp;
                (<a link="global_SPIDEN" file="shared_pseudocode.xml">SPIDEN</a> == <a link="enum_HIGH" file="shared_pseudocode.xml">HIGH</a> || <a link="global_SPNIDEN" file="shared_pseudocode.xml">SPNIDEN</a> == <a link="enum_HIGH" file="shared_pseudocode.xml">HIGH</a>));
    else
        return <a link="func_ExternalSecureInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalSecureInvasiveDebugEnabled</a>();
    end;
end;</pstext></ps>
    <ps name="shared/debug/authentication/InvasiveDebugPermittedPAS" mylink="shared.debug.authentication.InvasiveDebugPermittedPAS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// InvasiveDebugPermittedPAS()
// ===========================
// Returns TRUE if the invasive debug of the configured PASpace is permitted by
// the authentication interface, and FALSE otherwise.

func <anchor link="func_InvasiveDebugPermittedPAS_1">InvasiveDebugPermittedPAS</anchor>(pas : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>) =&gt; boolean
begin
    case pas of
        when <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> =&gt;    return <a link="func_ExternalSecureInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalSecureInvasiveDebugEnabled</a>();
        when <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> =&gt; return <a link="func_ExternalInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalInvasiveDebugEnabled</a>();
        when <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a> =&gt;      return <a link="func_ExternalRootInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalRootInvasiveDebugEnabled</a>();
        when <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a> =&gt;     return <a link="func_ExternalRealmInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalRealmInvasiveDebugEnabled</a>();
        otherwise =&gt;          return FALSE;
    end;
end;</pstext></ps>
    <ps name="shared/debug/authentication/IsAccessNonSecure" mylink="shared.debug.authentication.IsAccessNonSecure" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsAccessNonSecure()
// ===================
// Returns TRUE when an access is Non-Secure

func <anchor link="func_IsAccessNonSecure_1">IsAccessNonSecure</anchor>(addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>) =&gt; boolean
begin
    return addrdesc.paddress.paspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
end;</pstext></ps>
    <ps name="shared/debug/authentication/IsAccessRealm" mylink="shared.debug.authentication.IsAccessRealm" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsAccessRealm()
// ===============
// Returns TRUE when an access is Realm

func <anchor link="func_IsAccessRealm_1">IsAccessRealm</anchor>(addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>) =&gt; boolean
begin
    return addrdesc.paddress.paspace == <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>;
end;</pstext></ps>
    <ps name="shared/debug/authentication/IsAccessRoot" mylink="shared.debug.authentication.IsAccessRoot" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsAccessRoot()
// ==============
// Returns TRUE when an access is Root

func <anchor link="func_IsAccessRoot_1">IsAccessRoot</anchor>(addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>) =&gt; boolean
begin
    return addrdesc.paddress.paspace == <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>;
end;</pstext></ps>
    <ps name="shared/debug/authentication/IsAccessSecure" mylink="shared.debug.authentication.IsAccessSecure" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsAccessSecure()
// ================
// Returns TRUE when an access is Secure

func <anchor link="func_IsAccessSecure_1">IsAccessSecure</anchor>(addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>) =&gt; boolean
begin
    return addrdesc.paddress.paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>;
end;</pstext></ps>
    <ps name="shared/debug/authentication/IsCorePowered" mylink="shared.debug.authentication.IsCorePowered" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsCorePowered()
// ===============
// Returns TRUE if the Core power domain is powered on, FALSE otherwise.

impdef func <anchor link="func_IsCorePowered_0">IsCorePowered</anchor>() =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="shared/debug/authentication/IsMostSecureAccess" mylink="shared.debug.authentication.IsMostSecureAccess" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsMostSecureAccess()
// ====================
// Returns TRUE if the security state of an access is the most secure PAS.

func <anchor link="func_IsMostSecureAccess_1">IsMostSecureAccess</anchor>(addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>) =&gt; boolean
begin
    if IsFeatureImplemented(FEAT_RME) then
        return addrdesc.paddress.paspace == <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>;
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || <a link="func_SecureOnlyImplementation_0" file="shared_pseudocode.xml">SecureOnlyImplementation</a>() then
        return addrdesc.paddress.paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>;
    else
        assert addrdesc.paddress.paspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
        return TRUE;
    end;
end;</pstext></ps>
    <ps name="shared/debug/authentication/IsPASValid" mylink="shared.debug.authentication.IsPASValid" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsPASValid()
// ============
// Returns TRUE if the given value of 'pas' is not reserved, and FALSE otherwise.

func <anchor link="func_IsPASValid_1">IsPASValid</anchor>(pas : bits(2)) =&gt; boolean
begin
    case pas of
        when '00' =&gt; return IsFeatureImplemented(FEAT_Secure);
        when '01' =&gt; return TRUE;
        when '10' =&gt; return IsFeatureImplemented(FEAT_RME);
        when '11' =&gt; return IsFeatureImplemented(FEAT_RME);
    end;
end;</pstext></ps>
    <ps name="shared/debug/breakpoint/BreakpointInfo" mylink="shared.debug.breakpoint.BreakpointInfo" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BreakpointInfo
// ==============
// Breakpoint related fields.

type <anchor link="type_BreakpointInfo">BreakpointInfo</anchor> of record {
    bptype : <a link="type_BreakpointType" file="shared_pseudocode.xml">BreakpointType</a>, // Type of breakpoint matched
    match : boolean,         // breakpoint match
    mismatch : boolean       // breakpoint mismatch
};</pstext></ps>
    <ps name="shared/debug/breakpoint/BreakpointType" mylink="shared.debug.breakpoint.BreakpointType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BreakpointType
// ==============

type <anchor link="type_BreakpointType">BreakpointType</anchor> of enumeration {
    <anchor link="enum_BreakpointType_Inactive">BreakpointType_Inactive</anchor>,     // Breakpoint inactive or disabled
    <anchor link="enum_BreakpointType_AddrMatch">BreakpointType_AddrMatch</anchor>,    // Address Match breakpoint
    <anchor link="enum_BreakpointType_AddrMismatch">BreakpointType_AddrMismatch</anchor>, // Address Mismatch breakpoint
    <anchor link="enum_BreakpointType_CtxtMatch">BreakpointType_CtxtMatch</anchor>  }; // Context matching breakpoint</pstext></ps>
    <ps name="shared/debug/breakpoint/CheckValidStateMatch" mylink="shared.debug.breakpoint.CheckValidStateMatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckValidStateMatch()
// ======================
// Checks for an invalid state match that will generate Constrained
// Unpredictable behavior, otherwise returns Constraint_NONE.

func <anchor link="func_CheckValidStateMatch_5">CheckValidStateMatch</anchor>(ssc_in : bits(2), ssce_in : bit,
                          hmc_in : bit, pxc_in : bits(2),
                          isbreakpnt : boolean) =&gt; (<a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>, bits(2), bit, bit, bits(2))
begin
    if !IsFeatureImplemented(FEAT_RME) then assert ssce_in == '0'; end;
    var reserved : boolean = FALSE;
    var ssc : bits(2) = ssc_in;
    var ssce : bit    = ssce_in;
    var hmc : bit     = hmc_in;
    var pxc : bits(2) = pxc_in;

    // Values that are not allocated in any architecture version
    case hmc::ssce::ssc::pxc of
        when '0 0 11 10' =&gt; reserved = TRUE;
        when '0 0 1x xx' =&gt; reserved = !<a link="func_HaveSecureState_0" file="shared_pseudocode.xml">HaveSecureState</a>();
        when '1 0 00 x0' =&gt; reserved = TRUE;
        when '1 0 01 10' =&gt; reserved = TRUE;
        when '1 0 1x 10' =&gt; reserved = TRUE;
        when 'x 1 xx xx' =&gt; reserved = ssc != '01' || (hmc::pxc) IN {'000','110'};
        otherwise =&gt;        reserved = FALSE;
    end;

    // Match 'Usr/Sys/Svc' valid only for AArch32 breakpoints
    if (!isbreakpnt || !<a link="func_HaveAArch32EL_1" file="shared_pseudocode.xml">HaveAArch32EL</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>)) &amp;&amp; hmc::pxc == '000' &amp;&amp; ssc != '11' then
        reserved = TRUE;
    end;

    // Both EL3 and EL2 are not implemented
    if !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; (hmc != '0' || ssc != '00') then
        reserved = TRUE;
    end;

    // EL3 is not implemented
    if !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; ssc IN {'01','10'} &amp;&amp; hmc::ssc::pxc != '10100' then
        reserved = TRUE;
    end;

    // EL3 using AArch64 only
    if (!<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>()) &amp;&amp; hmc::ssc::pxc == '11000' then
        reserved = TRUE;
    end;

    // EL2 is not implemented
    if !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; hmc::ssc::pxc == '11100' then
        reserved = TRUE;
    end;

    // Secure EL2 is not implemented
    if !IsFeatureImplemented(FEAT_SEL2) &amp;&amp; (hmc::ssc::pxc)  IN {'01100','10100','x11x1'} then
        reserved = TRUE;
    end;

    if reserved then
        // If parameters are set to a reserved type, behaves as either disabled or a defined type
        var c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>;
        var unpred_state_bits : bits(6);
        (c, unpred_state_bits) = ConstrainUnpredictableBits{6}(<a link="enum_Unpredictable_RESBPWPCTRL" file="shared_pseudocode.xml">Unpredictable_RESBPWPCTRL</a>);
        hmc = unpred_state_bits[5];
        ssc = unpred_state_bits[4:3];
        ssce = unpred_state_bits[2];
        pxc = unpred_state_bits[1:0];
        assert c IN {<a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>, <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>};
        if c == <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a> then
            return (c, ARBITRARY : bits(2), ARBITRARY : bit, ARBITRARY : bit, ARBITRARY : bits(2));
        end;
    end;
        // Otherwise the value returned by ConstrainUnpredictableBits must be a not-reserved value

    return (<a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>, ssc, ssce, hmc, pxc);
end;</pstext></ps>
    <ps name="shared/debug/breakpoint/ContextAwareBreakpointRange" mylink="shared.debug.breakpoint.ContextAwareBreakpointRange" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ContextAwareBreakpointRange()
// =============================
// Returns two numbers indicating the index of the first and last context-aware breakpoint.

func <anchor link="func_ContextAwareBreakpointRange_0">ContextAwareBreakpointRange</anchor>() =&gt; (integer, integer)
begin
    let b : integer = <a link="func_NumBreakpointsImplemented_0" file="shared_pseudocode.xml">NumBreakpointsImplemented</a>();
    let c : integer = <a link="func_NumContextAwareBreakpointsImplemented_0" file="shared_pseudocode.xml">NumContextAwareBreakpointsImplemented</a>();

    if b &lt;= 16 then
        return (b - c, b - 1);
    elsif c &lt;= 16 then
        return (16 - c, 15);
    else
        return (0, c - 1);
    end;
end;</pstext></ps>
    <ps name="shared/debug/breakpoint/IsContextAwareBreakpoint" mylink="shared.debug.breakpoint.IsContextAwareBreakpoint" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsContextAwareBreakpoint()
// ==========================
// Returns TRUE if DBGBCR_EL1[n] is a context-aware breakpoint.

func <anchor link="func_IsContextAwareBreakpoint_1">IsContextAwareBreakpoint</anchor>(n : integer) =&gt; boolean
begin
    let (lower, upper) : (integer, integer) = <a link="func_ContextAwareBreakpointRange_0" file="shared_pseudocode.xml">ContextAwareBreakpointRange</a>();
    return n &gt;= lower &amp;&amp; n &lt;= upper;
end;</pstext></ps>
    <ps name="shared/debug/breakpoint/NumBreakpointsImplemented" mylink="shared.debug.breakpoint.NumBreakpointsImplemented" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// NumBreakpointsImplemented()
// ===========================
// Returns the number of breakpoints implemented.

readonly func <anchor link="func_NumBreakpointsImplemented_0">NumBreakpointsImplemented</anchor>() =&gt; integer
begin
    return ImpDefInt(&quot;Number of breakpoints&quot;);
end;</pstext></ps>
    <ps name="shared/debug/breakpoint/NumContextAwareBreakpointsImplemented" mylink="shared.debug.breakpoint.NumContextAwareBreakpointsImplemented" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// NumContextAwareBreakpointsImplemented()
// =======================================
// Returns the number of context-aware breakpoints implemented.

readonly func <anchor link="func_NumContextAwareBreakpointsImplemented_0">NumContextAwareBreakpointsImplemented</anchor>() =&gt; integer
begin
    return ImpDefInt(&quot;Number of context-aware breakpoints&quot;);
end;</pstext></ps>
    <ps name="shared/debug/breakpoint/NumWatchpointsImplemented" mylink="shared.debug.breakpoint.NumWatchpointsImplemented" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// NumWatchpointsImplemented()
// ===========================
// Returns the number of watchpoints implemented.

readonly func <anchor link="func_NumWatchpointsImplemented_0">NumWatchpointsImplemented</anchor>() =&gt; integer
begin
    return ImpDefInt(&quot;Number of watchpoints&quot;);
end;</pstext></ps>
    <ps name="shared/debug/cti/CTI_ProcessEvent" mylink="shared.debug.cti.CTI_ProcessEvent" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CTI_ProcessEvent()
// ==================
// Process a discrete event on a Cross Trigger output event trigger.

impdef func CTI_ProcessEvent(id : <a link="type_CrossTriggerOut" file="shared_pseudocode.xml">CrossTriggerOut</a>)
begin
    return;
end;</pstext></ps>
    <ps name="shared/debug/cti/CTI_SetEventLevel" mylink="shared.debug.cti.CTI_SetEventLevel" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CTI_SetEventLevel()
// ===================
// Set a Cross Trigger multi-cycle input event trigger to the specified level.

impdef func CTI_SetEventLevel(id : <a link="type_CrossTriggerIn" file="shared_pseudocode.xml">CrossTriggerIn</a>, level : <a link="type_Signal" file="shared_pseudocode.xml">Signal</a>)
begin
    return;
end;</pstext></ps>
    <ps name="shared/debug/cti/CTI_SignalEvent" mylink="shared.debug.cti.CTI_SignalEvent" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CTI_SignalEvent()
// =================
// Signal a discrete event on a Cross Trigger input event trigger.

impdef func CTI_SignalEvent(id : <a link="type_CrossTriggerIn" file="shared_pseudocode.xml">CrossTriggerIn</a>)
begin
    return;
end;</pstext></ps>
    <ps name="shared/debug/cti/CrossTrigger" mylink="shared.debug.cti.CrossTrigger" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CrossTrigger
// ============

type <anchor link="type_CrossTriggerOut">CrossTriggerOut</anchor> of enumeration {<anchor link="enum_CrossTriggerOut_DebugRequest">CrossTriggerOut_DebugRequest</anchor>, <anchor link="enum_CrossTriggerOut_RestartRequest">CrossTriggerOut_RestartRequest</anchor>,
                                     <anchor link="enum_CrossTriggerOut_IRQ">CrossTriggerOut_IRQ</anchor>,          <anchor link="enum_CrossTriggerOut_RSVD3">CrossTriggerOut_RSVD3</anchor>,
                                     <anchor link="enum_CrossTriggerOut_TraceExtIn0">CrossTriggerOut_TraceExtIn0</anchor>,  <anchor link="enum_CrossTriggerOut_TraceExtIn1">CrossTriggerOut_TraceExtIn1</anchor>,
                                     <anchor link="enum_CrossTriggerOut_TraceExtIn2">CrossTriggerOut_TraceExtIn2</anchor>,  <anchor link="enum_CrossTriggerOut_TraceExtIn3">CrossTriggerOut_TraceExtIn3</anchor>};

type <anchor link="type_CrossTriggerIn">CrossTriggerIn</anchor> of enumeration {<anchor link="enum_CrossTriggerIn_CrossHalt">CrossTriggerIn_CrossHalt</anchor>,     <anchor link="enum_CrossTriggerIn_PMUOverflow">CrossTriggerIn_PMUOverflow</anchor>,
                                    <anchor link="enum_CrossTriggerIn_SPESample">CrossTriggerIn_SPESample</anchor>,     <anchor link="enum_CrossTriggerIn_RSVD3">CrossTriggerIn_RSVD3</anchor>,
                                    <anchor link="enum_CrossTriggerIn_TraceExtOut0">CrossTriggerIn_TraceExtOut0</anchor>,  <anchor link="enum_CrossTriggerIn_TraceExtOut1">CrossTriggerIn_TraceExtOut1</anchor>,
                                    <anchor link="enum_CrossTriggerIn_TraceExtOut2">CrossTriggerIn_TraceExtOut2</anchor>,  <anchor link="enum_CrossTriggerIn_TraceExtOut3">CrossTriggerIn_TraceExtOut3</anchor>,
                                    <anchor link="enum_CrossTriggerIn_TRBEStop">CrossTriggerIn_TRBEStop</anchor>,      <anchor link="enum_CrossTriggerIn_TRBEMgmt">CrossTriggerIn_TRBEMgmt</anchor>,
                                    <anchor link="enum_CrossTriggerIn_TRBEWrap">CrossTriggerIn_TRBEWrap</anchor>};</pstext></ps>
    <ps name="shared/debug/dccanditr/CheckForDCCInterrupts" mylink="shared.debug.dccanditr.CheckForDCCInterrupts" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckForDCCInterrupts()
// =======================

func <anchor link="func_CheckForDCCInterrupts_0">CheckForDCCInterrupts</anchor>()
begin
    let commrx : boolean = (EDSCR().RXfull == '1');
    let commtx : boolean = (EDSCR().TXfull == '0');

    // COMMRX and COMMTX support is optional and not recommended for new designs.
    // SetInterruptRequestLevel(InterruptID_COMMRX, if commrx then HIGH else LOW);
    // SetInterruptRequestLevel(InterruptID_COMMTX, if commtx then HIGH else LOW);

    // The value to be driven onto the common COMMIRQ signal.
    var commirq : boolean;
    if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        commirq = ((commrx &amp;&amp; DBGDCCINT().RX == '1') ||
                   (commtx &amp;&amp; DBGDCCINT().TX == '1'));
    else
        commirq = ((commrx &amp;&amp; MDCCINT_EL1().RX == '1') ||
                   (commtx &amp;&amp; MDCCINT_EL1().TX == '1'));
    end;
    SetInterruptRequestLevel(<a link="enum_InterruptID_COMMIRQ" file="shared_pseudocode.xml">InterruptID_COMMIRQ</a>, if commirq then <a link="enum_HIGH" file="shared_pseudocode.xml">HIGH</a> else <a link="enum_LOW" file="shared_pseudocode.xml">LOW</a>);

    return;
end;</pstext></ps>
    <ps name="shared/debug/dccanditr/DTR" mylink="shared.debug.dccanditr.DTR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DTR
// ===

var <anchor link="global_DTRRX">DTRRX</anchor> : bits(32);
var <anchor link="global_DTRTX">DTRTX</anchor> : bits(32);</pstext></ps>
    <ps name="shared/debug/dccanditr/Read_DBGDTRRX_EL0" mylink="shared.debug.dccanditr.Read_DBGDTRRX_EL0" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Read_DBGDTRRX_EL0()
// ===================
// Called on reads of debug register 0x080.

func <anchor link="func_Read_DBGDTRRX_EL0_1">Read_DBGDTRRX_EL0</anchor>(memory_mapped : boolean) =&gt; bits(32)
begin
    return <a link="global_DTRRX" file="shared_pseudocode.xml">DTRRX</a>;
end;</pstext></ps>
    <ps name="shared/debug/dccanditr/Read_DBGDTRTX_EL0" mylink="shared.debug.dccanditr.Read_DBGDTRTX_EL0" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Read_DBGDTRTX_EL0()
// ===================
// Called on reads of debug register 0x08C.

func <anchor link="func_Read_DBGDTRTX_EL0_1">Read_DBGDTRTX_EL0</anchor>(memory_mapped : boolean) =&gt; bits(32)
begin
    let underrun : boolean = (EDSCR().TXfull == '0' ||
                              (<a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() &amp;&amp; EDSCR().MA == '1' &amp;&amp; EDSCR().ITE == '0'));
    let value : bits(32)   = if underrun then ARBITRARY : bits(32) else <a link="global_DTRTX" file="shared_pseudocode.xml">DTRTX</a>;

    if EDSCR().ERR == '1' then return value; end;       // Error flag set: no side-effects

    if underrun then
        EDSCR().TXU = '1';  EDSCR().ERR = '1';          // Underrun condition: block side-effects
        return value;                                   // Return UNKNOWN
    end;

    EDSCR().TXfull = '0';
    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() &amp;&amp; EDSCR().MA == '1' then
        EDSCR().ITE = '0';                              // See comments in Write_EDITR()

        if !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
            ExecuteA64(0xB8404401[31:0]);               // A64 &quot;LDR W1,[X0],#4&quot;
        else
            ExecuteT32(0xF850[15:0] /*hw1*/, 0x1B04[15:0] /*hw2*/);      // T32 &quot;LDR R1,[R0],#4&quot;
        end;
        // If the load aborts, the Data Abort exception is taken and EDSCR.ERR is set to 1
        if EDSCR().ERR == '1' then
            EDSCR().TXfull = ARBITRARY : bit;
            DBGDTRTX_EL0() = ARBITRARY : bits(64);
        else

            if !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
                ExecuteA64(0xD5130501[31:0]);           // A64 &quot;MSR DBGDTRTX_EL0,X1&quot;
            else
                ExecuteT32(0xEE00[15:0] /*hw1*/, 0x1E15[15:0] /*hw2*/);  // T32 &quot;MSR DBGDTRTXint,R1&quot;
            end;
            // &quot;MSR DBGDTRTX_EL0,X1&quot; calls Write_DBGDTR_EL0() which sets TXfull.
            assert EDSCR().TXfull == '1';
        end;
        if !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
            <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(1) = ARBITRARY : bits(64);
        else
            <a link="accessor_R_1" file="shared_pseudocode.xml">R</a>(1) = ARBITRARY : bits(32);
        end;
        EDSCR().ITE = '1';                                // See comments in Write_EDITR()
    end;

    return value;
end;</pstext></ps>
    <ps name="shared/debug/dccanditr/Read_DBGDTR_EL0" mylink="shared.debug.dccanditr.Read_DBGDTR_EL0" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Read_DBGDTR_EL0()
// =================
// System register reads of DBGDTR_EL0, DBGDTRRX_EL0 (AArch64) and DBGDTRRXint (AArch32)

func <anchor link="func_Read_DBGDTR_EL0_1">Read_DBGDTR_EL0</anchor>{N}() =&gt; bits(N)
begin
    // For MRS &lt;Rt&gt;,DBGDTRTX_EL0  N=32, X[t]=Zeros(32):result
    // For MRS &lt;Xt&gt;,DBGDTR_EL0    N=64, X[t]=result
    assert N IN {32,64};
    var result : bits(N);
    if EDSCR().RXfull == '0' then
        result = ARBITRARY : bits(N);
    else
        // On a 64-bit read, implement a half-duplex channel
        // NOTE: the word order is reversed on reads with regards to writes
        if N == 64 then result[63:32] = <a link="global_DTRTX" file="shared_pseudocode.xml">DTRTX</a>; end;
        result[31:0] = <a link="global_DTRRX" file="shared_pseudocode.xml">DTRRX</a>;
    end;
    EDSCR().RXfull = '0';
    return result;
end;</pstext></ps>
    <ps name="shared/debug/dccanditr/Write_DBGDTRRX_EL0" mylink="shared.debug.dccanditr.Write_DBGDTRRX_EL0" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Write_DBGDTRRX_EL0()
// ====================
// Called on writes to debug register 0x080.

func <anchor link="func_Write_DBGDTRRX_EL0_2">Write_DBGDTRRX_EL0</anchor>(memory_mapped : boolean, value : bits(32))
begin
    if EDSCR().ERR == '1' then return; end;                // Error flag set: ignore write

    if EDSCR().RXfull == '1' || (<a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() &amp;&amp; EDSCR().MA == '1' &amp;&amp; EDSCR().ITE == '0') then
        EDSCR().RXO = '1';  EDSCR().ERR = '1';              // Overrun condition: ignore write
        return;
    end;

    EDSCR().RXfull = '1';
    <a link="global_DTRRX" file="shared_pseudocode.xml">DTRRX</a>          = value;

    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() &amp;&amp; EDSCR().MA == '1' then
        EDSCR().ITE = '0';                                // See comments in Write_EDITR()
        if !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
            ExecuteA64(0xD5330501[31:0]);               // A64 &quot;MRS X1,DBGDTRRX_EL0&quot;
            ExecuteA64(0xB8004401[31:0]);               // A64 &quot;STR W1,[X0],#4&quot;
            <a link="accessor_X_2" file="shared_pseudocode.xml">X</a>{64}(1) = ARBITRARY : bits(64);
        else
            ExecuteT32(0xEE10[15:0] /*hw1*/, 0x1E15[15:0] /*hw2*/);  // T32 &quot;MRS R1,DBGDTRRXint&quot;
            ExecuteT32(0xF840[15:0] /*hw1*/, 0x1B04[15:0] /*hw2*/);  // T32 &quot;STR R1,[R0],#4&quot;
            <a link="accessor_R_1" file="shared_pseudocode.xml">R</a>(1) = ARBITRARY : bits(32);
        end;
        // If the store aborts, the Data Abort exception is taken and EDSCR.ERR is set to 1
        if EDSCR().ERR == '1' then
            EDSCR().RXfull = ARBITRARY : bit;
            DBGDTRRX_EL0() = ARBITRARY : bits(64);
        else
            // &quot;MRS X1,DBGDTRRX_EL0&quot; calls Read_DBGDTR_EL0() which clears RXfull.
            assert EDSCR().RXfull == '0';
        end;

        EDSCR().ITE = '1';                                // See comments in Write_EDITR()
    end;
    return;
end;</pstext></ps>
    <ps name="shared/debug/dccanditr/Write_DBGDTRTX_EL0" mylink="shared.debug.dccanditr.Write_DBGDTRTX_EL0" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Write_DBGDTRTX_EL0()
// ====================
// Called on writes to debug register 0x08C.

func <anchor link="func_Write_DBGDTRTX_EL0_2">Write_DBGDTRTX_EL0</anchor>(memory_mapped : boolean, value : bits(32))
begin
    <a link="global_DTRTX" file="shared_pseudocode.xml">DTRTX</a> = value;
    return;
end;</pstext></ps>
    <ps name="shared/debug/dccanditr/Write_DBGDTR_EL0" mylink="shared.debug.dccanditr.Write_DBGDTR_EL0" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Write_DBGDTR_EL0()
// ==================
// System register writes to DBGDTR_EL0, DBGDTRTX_EL0 (AArch64) and DBGDTRTXint (AArch32)

func <anchor link="func_Write_DBGDTR_EL0_2">Write_DBGDTR_EL0</anchor>{N}(value_in : bits(N))
begin
    var value : bits(N) = value_in;
    // For MSR DBGDTRTX_EL0,&lt;Rt&gt;  N=32, value=X[t]&lt;31:0&gt;, X[t]&lt;63:32&gt; is ignored
    // For MSR DBGDTR_EL0,&lt;Xt&gt;    N=64, value=X[t]&lt;63:0&gt;
    assert N IN {32,64};
    if EDSCR().TXfull == '1' then
        value = ARBITRARY : bits(N);
    end;
    // On a 64-bit write, implement a half-duplex channel
    if N == 64 then <a link="global_DTRRX" file="shared_pseudocode.xml">DTRRX</a> = value[63:32]; end;
    <a link="global_DTRTX" file="shared_pseudocode.xml">DTRTX</a> = value[31:0];        // 32-bit or 64-bit write
    EDSCR().TXfull = '1';
    return;
end;</pstext></ps>
    <ps name="shared/debug/dccanditr/Write_EDITR" mylink="shared.debug.dccanditr.Write_EDITR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Write_EDITR()
// =============
// Called on writes to debug register 0x084.

func <anchor link="func_Write_EDITR_2">Write_EDITR</anchor>(memory_mapped : boolean, value : bits(32))
begin
    if EDSCR().ERR == '1' then return; end;         // Error flag set: ignore write

    if !<a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then return; end;                  // Non-debug state: ignore write

    if EDSCR().ITE == '0' || EDSCR().MA == '1' then
        EDSCR().ITO = '1';  EDSCR().ERR = '1';      // Overrun condition: block write
        return;
    end;

    // ITE indicates whether the PE is ready to accept another instruction; the PE
    // may support multiple outstanding instructions. Unlike the &quot;InstrCompl&quot; flag in [v7A] there
    // is no indication that the pipeline is empty (all instructions have completed). In this
    // pseudocode, the assumption is that only one instruction can be executed at a time,
    // meaning ITE acts like &quot;InstrCompl&quot;.
    EDSCR().ITE = '0';

    if !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        ExecuteA64(value);
    else
        ExecuteT32(value[15:0]/*hw1*/, value[31:16] /*hw2*/);
    end;

    EDSCR().ITE = '1';

    return;
end;</pstext></ps>
    <ps name="shared/debug/halting/DCPSInstruction" mylink="shared.debug.halting.DCPSInstruction" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DCPSInstruction()
// =================
// Operation of the DCPS instruction in Debug state

func <anchor link="func_DCPSInstruction_1">DCPSInstruction</anchor>(target_el : bits(2))
begin

    SynchronizeContext();

    var handle_el : bits(2);
    case target_el of
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>()) then
                handle_el = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
            elsif <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1' then
                Undefined();
            else
                handle_el = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
            end;
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            if !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
                Undefined();
            elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
                handle_el = <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
            elsif !<a link="func_IsSecureEL2Enabled_0" file="shared_pseudocode.xml">IsSecureEL2Enabled</a>() &amp;&amp; <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
                Undefined();
            else
                handle_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
            end;
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            if EDSCR().SDD == '1' || !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
                Undefined();
            else
                handle_el = <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
            end;
        otherwise =&gt;
            unreachable;
    end;

    let from_secure : boolean = <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>;
    if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(handle_el) then
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M == <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a> then SCR().NS = '0'; end;
        assert <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>();                  // Cannot move from AArch64 to AArch32
        case handle_el of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
                <a link="func_AArch32_WriteMode_1" file="shared_pseudocode.xml">AArch32_WriteMode</a>(<a link="global_M32_Svc" file="shared_pseudocode.xml">M32_Svc</a>);
                if IsFeatureImplemented(FEAT_PAN) &amp;&amp; SCTLR().SPAN == '0' then
                    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN = '1';
                end;
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;  <a link="func_AArch32_WriteMode_1" file="shared_pseudocode.xml">AArch32_WriteMode</a>(<a link="global_M32_Hyp" file="shared_pseudocode.xml">M32_Hyp</a>);
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
                <a link="func_AArch32_WriteMode_1" file="shared_pseudocode.xml">AArch32_WriteMode</a>(<a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a>);
                if IsFeatureImplemented(FEAT_PAN) then
                    if !from_secure then
                        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN = '0';
                    elsif SCTLR().SPAN == '0' then
                        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN = '1';
                    end;
                end;
        end;
        if handle_el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
            ELR_hyp() = ARBITRARY : bits(32);  HSR() = ARBITRARY : bits(32);
        else
            <a link="accessor_LR_0" file="shared_pseudocode.xml">LR</a>() = ARBITRARY : bits(32);
        end;
        <a link="accessor_SPSR_curr_0" file="shared_pseudocode.xml">SPSR_curr</a>() = ARBITRARY : bits(32);
        if handle_el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.E = HSCTLR().EE;
        else
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.E = SCTLR().EE;
        end;
        DLR() = ARBITRARY : bits(32);  DSPSR() = ARBITRARY : bits(32);

    else                                        // Targeting AArch64
        let from_32 : boolean = <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>();
        if from_32 then <a link="func_AArch64_MaybeZeroRegisterUppers_0" file="shared_pseudocode.xml">AArch64_MaybeZeroRegisterUppers</a>(); end;
        if from_32 &amp;&amp; IsFeatureImplemented(FEAT_SME) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM == '1' then
            <a link="func_ResetSVEState_0" file="shared_pseudocode.xml">ResetSVEState</a>();
        else
            <a link="func_MaybeZeroSVEUppers_1" file="shared_pseudocode.xml">MaybeZeroSVEUppers</a>(target_el);
        end;
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.nRW = '0';  <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SP = '1';  <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL = handle_el;
        if IsFeatureImplemented(FEAT_PAN) &amp;&amp; ((handle_el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; SCTLR_EL1().SPAN == '0') ||
                                              (handle_el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> &amp;&amp; <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) &amp;&amp;
                                               SCTLR_EL2().SPAN == '0')) then
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN = '1';
        end;
        <a link="accessor_ELR_ELx_0" file="shared_pseudocode.xml">ELR_ELx</a>() = ARBITRARY : bits(64);
        <a link="accessor_SPSR_ELx_0" file="shared_pseudocode.xml">SPSR_ELx</a>() = ARBITRARY : bits(64);
        <a link="accessor_ESR_ELx_0" file="shared_pseudocode.xml">ESR_ELx</a>() = ARBITRARY : bits(64);
        DLR_EL0() = ARBITRARY : bits(64);  DSPSR_EL0() = ARBITRARY : bits(64);
        if IsFeatureImplemented(FEAT_UAO) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.UAO = '0'; end;
        if IsFeatureImplemented(FEAT_MTE) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.TCO = '1'; end;
        if IsFeatureImplemented(FEAT_GCS) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EXLOCK = '0'; end;
    end;
    if IsFeatureImplemented(FEAT_UINJ) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.UINJ = '0'; end;
    <a link="func_UpdateEDSCRFields_0" file="shared_pseudocode.xml">UpdateEDSCRFields</a>();                        // Update EDSCR PE state flags
    return;
end;</pstext></ps>
    <ps name="shared/debug/halting/DRPSInstruction" mylink="shared.debug.halting.DRPSInstruction" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DRPSInstruction()
// =================
// Operation of the A64 DRPS and T32 ERET instructions in Debug state

func <anchor link="func_DRPSInstruction_0">DRPSInstruction</anchor>()
begin
    SynchronizeContext();

    <a link="func_DebugRestorePSR_0" file="shared_pseudocode.xml">DebugRestorePSR</a>();

    return;
end;</pstext></ps>
    <ps name="shared/debug/halting/DebugHalt" mylink="shared.debug.halting.DebugHalt" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DebugHalt
// =========
// Reason codes for entry to Debug state

constant <anchor link="global_DebugHalt_Breakpoint">DebugHalt_Breakpoint</anchor> : bits(6)      = '000111';
constant <anchor link="global_DebugHalt_EDBGRQ">DebugHalt_EDBGRQ</anchor> : bits(6)          = '010011';
constant <anchor link="global_DebugHalt_Step_Normal">DebugHalt_Step_Normal</anchor> : bits(6)     = '011011';
constant <anchor link="global_DebugHalt_Step_Exclusive">DebugHalt_Step_Exclusive</anchor> : bits(6)  = '011111';
constant <anchor link="global_DebugHalt_OSUnlockCatch">DebugHalt_OSUnlockCatch</anchor> : bits(6)   = '100011';
constant <anchor link="global_DebugHalt_ResetCatch">DebugHalt_ResetCatch</anchor> : bits(6)      = '100111';
constant <anchor link="global_DebugHalt_Watchpoint">DebugHalt_Watchpoint</anchor> : bits(6)      = '101011';
constant <anchor link="global_DebugHalt_HaltInstruction">DebugHalt_HaltInstruction</anchor> : bits(6) = '101111';
constant <anchor link="global_DebugHalt_SoftwareAccess">DebugHalt_SoftwareAccess</anchor> : bits(6)  = '110011';
constant <anchor link="global_DebugHalt_ExceptionCatch">DebugHalt_ExceptionCatch</anchor> : bits(6)  = '110111';
constant <anchor link="global_DebugHalt_Step_NoSyndrome">DebugHalt_Step_NoSyndrome</anchor> : bits(6) = '111011';</pstext></ps>
    <ps name="shared/debug/halting/DebugRestorePSR" mylink="shared.debug.halting.DebugRestorePSR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DebugRestorePSR()
// =================

func <anchor link="func_DebugRestorePSR_0">DebugRestorePSR</anchor>()
begin
    // PSTATE.[N,Z,C,V,Q,GE,SS,D,A,I,F] are not observable and ignored in Debug state, so
    // behave as if UNKNOWN.
    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        let spsr : bits(32) = <a link="accessor_SPSR_curr_0" file="shared_pseudocode.xml">SPSR_curr</a>();
        <a link="func_SetPSTATEFromPSR_2" file="shared_pseudocode.xml">SetPSTATEFromPSR</a>{32}(spsr);
        PSTATE.[N,Z,C,V,Q,GE,SS,A,I,F] = ARBITRARY : bits(13);
        //  In AArch32, all instructions are T32 and unconditional.
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT = '00000000';  <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T = '1';        // PSTATE.J is RES0
        DLR() = ARBITRARY : bits(32);  DSPSR() = ARBITRARY : bits(32);
    else
        let spsr : bits(64) = <a link="accessor_SPSR_ELx_0" file="shared_pseudocode.xml">SPSR_ELx</a>();
        <a link="func_SetPSTATEFromPSR_2" file="shared_pseudocode.xml">SetPSTATEFromPSR</a>{64}(spsr);
        PSTATE.[N,Z,C,V,SS,D,A,I,F] = ARBITRARY : bits(9);
        DLR_EL0() = ARBITRARY : bits(64);  DSPSR_EL0() = ARBITRARY : bits(64);
    end;
    <a link="func_UpdateEDSCRFields_0" file="shared_pseudocode.xml">UpdateEDSCRFields</a>();                                // Update EDSCR PE state flags
end;</pstext></ps>
    <ps name="shared/debug/halting/DisableITRAndResumeInstructionPrefetch" mylink="shared.debug.halting.DisableITRAndResumeInstructionPrefetch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DisableITRAndResumeInstructionPrefetch()
// ========================================

impdef func DisableITRAndResumeInstructionPrefetch()
begin
    return;
end;</pstext></ps>
    <ps name="shared/debug/halting/ExecuteA64" mylink="shared.debug.halting.ExecuteA64" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExecuteA64()
// ============
// Execute an A64 instruction in Debug state.

impdef func ExecuteA64(instr : bits(32))
begin
    Unimplemented();
end;</pstext></ps>
    <ps name="shared/debug/halting/ExecuteT32" mylink="shared.debug.halting.ExecuteT32" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExecuteT32()
// ============
// Execute a T32 instruction in Debug state.

impdef func ExecuteT32(hw1 : bits(16), hw2 : bits(16))
begin
    Unimplemented();
end;</pstext></ps>
    <ps name="shared/debug/halting/ExitDebugState" mylink="shared.debug.halting.ExitDebugState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExitDebugState()
// ================

func <anchor link="func_ExitDebugState_0">ExitDebugState</anchor>()
begin
    assert <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>();
    SynchronizeContext();

    // Although EDSCR.STATUS signals that the PE is restarting, debuggers must use EDPRSR.SDR to
    // detect that the PE has restarted.
    EDSCR().STATUS = '000001';                           // Signal restarting
    // Clear any pending Halting debug events
    if IsFeatureImplemented(FEAT_Debugv8p8) then
        EDESR()[3:0] = '0000';
    else
        EDESR()[2:0] = '000';
    end;

    var new_pc : bits(64);
    var spsr : bits(64);

    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        new_pc = ZeroExtend{64}(DLR());
        if IsFeatureImplemented(FEAT_Debugv8p9) then
            spsr = DSPSR2() :: DSPSR();
        else
            spsr = ZeroExtend{64}(DSPSR());
        end;
    else
        new_pc = DLR_EL0();
        spsr = DSPSR_EL0();
    end;

    let illegal_psr_state : boolean = <a link="func_IllegalExceptionReturn_2" file="shared_pseudocode.xml">IllegalExceptionReturn</a>{64}(spsr);
    // If this is an illegal return, SetPSTATEFromPSR() will set PSTATE.IL.
    <a link="func_SetPSTATEFromPSR_2" file="shared_pseudocode.xml">SetPSTATEFromPSR</a>{64}(spsr); // Can update privileged bits, even at EL0

    let branch_conditional : boolean = FALSE;
    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        if <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_RESTARTALIGNPC" file="shared_pseudocode.xml">Unpredictable_RESTARTALIGNPC</a>) then new_pc[0] = '0'; end;
        // AArch32 branch
        <a link="func_BranchTo_4" file="shared_pseudocode.xml">BranchTo</a>{32}(new_pc[31:0], <a link="enum_BranchType_DBGEXIT" file="shared_pseudocode.xml">BranchType_DBGEXIT</a>, branch_conditional);
    else
        // If targeting AArch32 then PC[63:32,1:0] might be set to UNKNOWN.
        if illegal_psr_state &amp;&amp; spsr[4] == '1' then
            new_pc[63:32] = ARBITRARY : bits(32);
            new_pc[1:0] = ARBITRARY : bits(2);
        end;
        if IsFeatureImplemented(FEAT_BRBE) then
            <a link="func_BRBEDebugStateExit_1" file="shared_pseudocode.xml">BRBEDebugStateExit</a>(<a link="func_AArch64_BranchAddr_2" file="shared_pseudocode.xml">AArch64_BranchAddr</a>(new_pc,<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL));
        end;
        // A type of branch that is never predicted
        <a link="func_BranchTo_4" file="shared_pseudocode.xml">BranchTo</a>{64}(new_pc, <a link="enum_BranchType_DBGEXIT" file="shared_pseudocode.xml">BranchType_DBGEXIT</a>, branch_conditional);
    end;

     // Atomically signal restarted
    EDSCR().STATUS = '000010';
    EDPRSR().SDR = '1';
    // End of atomically signal
    EDPRSR().HALTED = '0';
    <a link="func_UpdateEDSCRFields_0" file="shared_pseudocode.xml">UpdateEDSCRFields</a>();                               // Stop signalling PE state
    DisableITRAndResumeInstructionPrefetch();

    return;
end;</pstext></ps>
    <ps name="shared/debug/halting/Halt" mylink="shared.debug.halting.Halt" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Halt()
// ======

func <anchor link="func_Halt_1">Halt</anchor>(reason : bits(6))
begin
    let is_async : boolean = FALSE;
    let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_0" file="shared_pseudocode.xml">NoFault</a>();
    <a link="func_Halt_3" file="shared_pseudocode.xml">Halt</a>(reason, is_async, fault);
end;

// Halt()
// ======

func <anchor link="func_Halt_3">Halt</anchor>(reason : bits(6), is_async : boolean, fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>)
begin
    CTI_SignalEvent(<a link="enum_CrossTriggerIn_CrossHalt" file="shared_pseudocode.xml">CrossTriggerIn_CrossHalt</a>);  // Trigger other cores to halt

    let preferred_restart_address : bits(64) = ThisInstrAddr{}();
    var spsr : bits(64) = <a link="func_GetPSRFromPSTATE_2" file="shared_pseudocode.xml">GetPSRFromPSTATE</a>{64}(<a link="enum_DebugState" file="shared_pseudocode.xml">DebugState</a>);

    if (IsFeatureImplemented(FEAT_BTI) &amp;&amp; !is_async &amp;&amp;
          ! reason IN {<a link="global_DebugHalt_Step_Normal" file="shared_pseudocode.xml">DebugHalt_Step_Normal</a>, <a link="global_DebugHalt_Step_Exclusive" file="shared_pseudocode.xml">DebugHalt_Step_Exclusive</a>,
                       <a link="global_DebugHalt_Step_NoSyndrome" file="shared_pseudocode.xml">DebugHalt_Step_NoSyndrome</a>, <a link="global_DebugHalt_Breakpoint" file="shared_pseudocode.xml">DebugHalt_Breakpoint</a>,
                       <a link="global_DebugHalt_HaltInstruction" file="shared_pseudocode.xml">DebugHalt_HaltInstruction</a>} &amp;&amp;
          <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_ZEROBTYPE" file="shared_pseudocode.xml">Unpredictable_ZEROBTYPE</a>)) then
        spsr[11:10] = '00';
    end;

    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        DLR() = preferred_restart_address[31:0];
        DSPSR() = spsr[31:0];
        if IsFeatureImplemented(FEAT_Debugv8p9) then
            DSPSR2() = spsr[63:32];
        end;
    else
        DLR_EL0() = preferred_restart_address;
        DSPSR_EL0() = spsr;
    end;
    EDSCR().ITE = '1';
    EDSCR().ITO = '0';
    if IsFeatureImplemented(FEAT_RME) then
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then
            EDSCR().SDD = '0';
        else
            EDSCR().SDD = if <a link="func_ExternalRootInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalRootInvasiveDebugEnabled</a>() then '0' else '1';
        end;
    elsif <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
        EDSCR().SDD = '0';                        // If entered in Secure state, allow debug
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        EDSCR().SDD = if <a link="func_ExternalSecureInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalSecureInvasiveDebugEnabled</a>() then '0' else '1';
    else
        EDSCR().SDD = '1';                        // Otherwise EDSCR.SDD is RES1
    end;
    EDSCR().MA = '0';

    // In Debug state:
    // * PSTATE.[SS,SSBS,D,A,I,F] are not observable and ignored so behave-as-if UNKNOWN.
    // * PSTATE.[N,Z,C,V,Q,GE,E,M,nRW,EL,SP,DIT] are also not observable, but since these
    //     are not changed on exception entry, this function also leaves them unchanged.
    // * PSTATE.[IT,T] are ignored.
    // * PSTATE.IL is ignored and behave-as-if 0.
    // * PSTATE.BTYPE is ignored and behave-as-if 0.
    // * PSTATE.TCO is set 1.
    // * PSTATE.PACM is ignored and behave-as-if 0.
    // * PSTATE.[UAO,PAN] are observable and not changed on entry into Debug state.
    // * PSTATE.UINJ is set to 0.

    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        PSTATE.[IT,SS,SSBS,A,I,F,T] = ARBITRARY : bits(14);
    else
        PSTATE.[SS,SSBS,D,A,I,F]    = ARBITRARY : bits(6);
    end;

    if IsFeatureImplemented(FEAT_MTE) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.TCO = '1'; end;
    if IsFeatureImplemented(FEAT_BTI) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.BTYPE = '00'; end;
    if IsFeatureImplemented(FEAT_PAuth_LR) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PACM = '0'; end;
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL = '0';
    if IsFeatureImplemented(FEAT_UINJ) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.UINJ = '0'; end;
    if IsFeatureImplemented(FEAT_BRBE) then
        <a link="func_BRBEDebugStateEntry_1" file="shared_pseudocode.xml">BRBEDebugStateEntry</a>(preferred_restart_address);
    end;
    StopInstructionPrefetchAndEnableITR();
    // atomic write
    EDSCR().STATUS = reason;
    EDPRSR().HALTED = '1';
    // end of atomic write
    <a link="func_UpdateEDSCRFields_0" file="shared_pseudocode.xml">UpdateEDSCRFields</a>();                        // Update EDSCR PE state flags.
    if IsFeatureImplemented(FEAT_EDHSR) then
        <a link="func_UpdateEDHSR_2" file="shared_pseudocode.xml">UpdateEDHSR</a>(reason, fault);             // Update EDHSR fields.
    end;
    if !is_async then EndOfInstruction(<a link="enum_EndOfInstructionReason_Exception" file="shared_pseudocode.xml">EndOfInstructionReason_Exception</a>); end;
    return;
end;</pstext></ps>
    <ps name="shared/debug/halting/HaltOnBreakpointOrWatchpoint" mylink="shared.debug.halting.HaltOnBreakpointOrWatchpoint" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HaltOnBreakpointOrWatchpoint()
// ==============================
// Returns TRUE if the Breakpoint and Watchpoint debug events should be considered for Debug
// state entry, FALSE if they should be considered for a debug exception.

func <anchor link="func_HaltOnBreakpointOrWatchpoint_0">HaltOnBreakpointOrWatchpoint</anchor>() =&gt; boolean
begin
    return <a link="func_HaltingAllowed_0" file="shared_pseudocode.xml">HaltingAllowed</a>() &amp;&amp; EDSCR().HDE == '1' &amp;&amp; OSLSR_EL1().OSLK == '0';
end;</pstext></ps>
    <ps name="shared/debug/halting/Halted" mylink="shared.debug.halting.Halted" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Halted()
// ========

readonly func <anchor link="func_Halted_0">Halted</anchor>() =&gt; boolean
begin
    return ! EDSCR().STATUS IN {'000001', '000010'};                    // Halted
end;</pstext></ps>
    <ps name="shared/debug/halting/HaltingAllowed" mylink="shared.debug.halting.HaltingAllowed" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HaltingAllowed()
// ================
// Returns TRUE if halting is currently allowed, FALSE if halting is prohibited.

func <anchor link="func_HaltingAllowed_0">HaltingAllowed</anchor>() =&gt; boolean
begin
    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() || <a link="func_DoubleLockStatus_0" file="shared_pseudocode.xml">DoubleLockStatus</a>() then
        return FALSE;
    end;
    let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>();
    case ss of
        when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt; return <a link="func_ExternalInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalInvasiveDebugEnabled</a>();
        when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;    return <a link="func_ExternalSecureInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalSecureInvasiveDebugEnabled</a>();
        when <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a> =&gt;      return <a link="func_ExternalRootInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalRootInvasiveDebugEnabled</a>();
        when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;     return <a link="func_ExternalRealmInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalRealmInvasiveDebugEnabled</a>();
    end;
end;</pstext></ps>
    <ps name="shared/debug/halting/Restarting" mylink="shared.debug.halting.Restarting" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Restarting()
// ============

readonly func <anchor link="func_Restarting_0">Restarting</anchor>() =&gt; boolean
begin
    return EDSCR().STATUS == '000001';                                  // Restarting
end;</pstext></ps>
    <ps name="shared/debug/halting/StopInstructionPrefetchAndEnableITR" mylink="shared.debug.halting.StopInstructionPrefetchAndEnableITR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// StopInstructionPrefetchAndEnableITR()
// =====================================

impdef func StopInstructionPrefetchAndEnableITR()
begin
    return;
end;</pstext></ps>
    <ps name="shared/debug/halting/UpdateDbgAuthStatus" mylink="shared.debug.halting.UpdateDbgAuthStatus" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// UpdateDbgAuthStatus()
// =====================
// Provides information about the state of the
// IMPLEMENTATION DEFINED authentication interface for debug.

func <anchor link="func_UpdateDbgAuthStatus_0">UpdateDbgAuthStatus</anchor>()
begin
    var nsid, nsnid : bits(2);
    var sid, snid : bits(2);
    var rlid, rtid : bits(2);
    if <a link="func_SecureOnlyImplementation_0" file="shared_pseudocode.xml">SecureOnlyImplementation</a>() then
        nsid = '00';
    elsif <a link="func_ExternalInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalInvasiveDebugEnabled</a>() then
        nsid = '11';          // Non-secure Invasive debug implemented and enabled.
    else
        nsid = '10';          // Non-secure Invasive debug implemented and disabled.
    end;

    if <a link="func_SecureOnlyImplementation_0" file="shared_pseudocode.xml">SecureOnlyImplementation</a>() then
        nsnid = '00';
    elsif <a link="func_ExternalNoninvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalNoninvasiveDebugEnabled</a>() then
        nsnid = '11';         // Non-secure Non-Invasive debug implemented and enabled.
    else
        nsnid = '10';         // Non-secure Non-Invasive debug implemented and disabled.
    end;

    if !<a link="func_HaveSecureState_0" file="shared_pseudocode.xml">HaveSecureState</a>() then
        sid = '00';
    elsif <a link="func_ExternalSecureInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalSecureInvasiveDebugEnabled</a>() then
        sid = '11';           // Secure Invasive debug implemented and enabled.
    else
        sid = '10';           // Secure Invasive debug implemented and disabled.
    end;

    if !<a link="func_HaveSecureState_0" file="shared_pseudocode.xml">HaveSecureState</a>() then
        snid = '00';
    elsif <a link="func_ExternalSecureNoninvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalSecureNoninvasiveDebugEnabled</a>() then
        snid = '11';          // Secure Non-Invasive debug implemented and enabled.
    else
        snid = '10';          // Secure Non-Invasive debug implemented and disabled.
    end;

    if !IsFeatureImplemented(FEAT_RME) then
        rlid = '00';
    elsif <a link="func_ExternalRealmInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalRealmInvasiveDebugEnabled</a>() then
        rlid = '11';          // Realm Invasive debug implemented and enabled.
    else
        rlid = '10';          // Realm Invasive debug implemented and disabled.
    end;

    if !IsFeatureImplemented(FEAT_RME) then
        rtid = '00';
    elsif <a link="func_ExternalRootInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalRootInvasiveDebugEnabled</a>() then
        rtid = '11';          // Root Invasive debug implemented and enabled.
    else
        rtid = '10';          // Root Invasive debug implemented and disabled.
    end;

    DBGAUTHSTATUS_EL1().NSID  = nsid;
    DBGAUTHSTATUS_EL1().NSNID = nsnid;
    DBGAUTHSTATUS_EL1().SID   = sid;
    DBGAUTHSTATUS_EL1().SNID  = snid;
    DBGAUTHSTATUS_EL1().RLID  = rlid;
    DBGAUTHSTATUS_EL1().RLNID = rlid;    // Field has the same value as DBGAUTHSTATUS_EL1.RLID.
    DBGAUTHSTATUS_EL1().RTID  = rtid;
    DBGAUTHSTATUS_EL1().RTNID = rtid;    // Field has the same value as DBGAUTHSTATUS_EL1.RTID.
    return;
end;</pstext></ps>
    <ps name="shared/debug/halting/UpdateEDHSR" mylink="shared.debug.halting.UpdateEDHSR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// UpdateEDHSR()
// =============
// Update EDHSR watchpoint related fields.

func <anchor link="func_UpdateEDHSR_2">UpdateEDHSR</anchor>(reason : bits(6), fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>)
begin
    var syndrome : bits(64) = Zeros{};
    if reason == <a link="global_DebugHalt_Watchpoint" file="shared_pseudocode.xml">DebugHalt_Watchpoint</a> then
        if IsFeatureImplemented(FEAT_GCS) &amp;&amp; fault.accessdesc.acctype == <a link="enum_AccessType_GCS" file="shared_pseudocode.xml">AccessType_GCS</a> then
            syndrome[40] = '1';                        // GCS
        end;
        syndrome[23:0] = <a link="func_WatchpointRelatedSyndrome_1" file="shared_pseudocode.xml">WatchpointRelatedSyndrome</a>(fault);
        if IsFeatureImplemented(FEAT_Debugv8p9) then
            if fault.write then syndrome[6] = '1'; end; // WnR
            if fault.accessdesc.acctype IN {<a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>, <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>, <a link="enum_AccessType_AT" file="shared_pseudocode.xml">AccessType_AT</a>} then
                syndrome[8] = '1';                     // CM
            end;
            if IsFeatureImplemented(FEAT_NV2) &amp;&amp; fault.accessdesc.acctype == <a link="enum_AccessType_NV2" file="shared_pseudocode.xml">AccessType_NV2</a> then
                syndrome[13] = '1';                    // VNCR
            end;
        end;
    else
        syndrome = ARBITRARY : bits(64);
    end;

    EDHSR() = syndrome;
end;</pstext></ps>
    <ps name="shared/debug/halting/UpdateEDSCRFields" mylink="shared.debug.halting.UpdateEDSCRFields" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// UpdateEDSCRFields()
// ===================
// Update EDSCR PE state fields

func <anchor link="func_UpdateEDSCRFields_0">UpdateEDSCRFields</anchor>()
begin
    if !<a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then
        EDSCR().EL = '00';
        if IsFeatureImplemented(FEAT_RME) then
           // SDD bit.
            EDSCR().SDD = if <a link="func_ExternalRootInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalRootInvasiveDebugEnabled</a>() then '0' else '1';
            EDSCR().[NSE,NS] = ARBITRARY : bits(2);
        else
            // SDD bit.
            EDSCR().SDD = if <a link="func_ExternalSecureInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalSecureInvasiveDebugEnabled</a>() then '0' else '1';
            EDSCR().NS = ARBITRARY : bit;
        end;

        EDSCR().RW = '1111';
    else
        EDSCR().EL = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
        // SError Pending.
        if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().[AMO,TGE] == '10' &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>,<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} then
            EDSCR().A = if <a link="func_IsVirtualSErrorPending_0" file="shared_pseudocode.xml">IsVirtualSErrorPending</a>() then '1' else '0';
        elsif (<a link="func_EffectiveSCR_EL3_EnDSE_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_EnDSE</a>() == '1' &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>,<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>,<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>}) then
            EDSCR().A = if <a link="func_IsDelegatedSErrorPending_0" file="shared_pseudocode.xml">IsDelegatedSErrorPending</a>() then '1' else '0';
        else
            EDSCR().A = if <a link="func_IsPhysicalSErrorPending_0" file="shared_pseudocode.xml">IsPhysicalSErrorPending</a>() then '1' else '0';
        end;

        let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>();
        if IsFeatureImplemented(FEAT_RME) then
            case ss of
                when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;    EDSCR().[NSE,NS] = '00';
                when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt; EDSCR().[NSE,NS] = '01';
                when <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a> =&gt;      EDSCR().[NSE,NS] = '10';
                when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;     EDSCR().[NSE,NS] = '11';
            end;
        else
            EDSCR().NS = if ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then '0' else '1';
        end;

        var RW : bits(4);
        RW[1] = if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then '0' else '1';
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
            RW[0] = RW[1];
        else
            RW[0] = if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then '0' else '1';
        end;
        if !<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
            RW[2] = RW[1];
        else
            RW[2] = if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then '0' else '1';
        end;
        if !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
            RW[3] = RW[2];
        else
            RW[3] = if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then '0' else '1';
        end;

        // The least-significant bits of EDSCR.RW are UNKNOWN if any higher EL is using AArch32.
        if RW[3] == '0' then RW[2:0] = ARBITRARY : bits(3);
        elsif RW[2] == '0' then RW[1:0] = ARBITRARY : bits(2);
        elsif RW[1] == '0' then RW[0] = ARBITRARY : bit; end;
        EDSCR().RW = RW;
    end;
    return;
end;</pstext></ps>
    <ps name="shared/debug/haltingevents" mylink="shared.debug.haltingevents" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">var <anchor link="global_EDBGRQ">EDBGRQ</anchor> : <a link="type_Signal" file="shared_pseudocode.xml">Signal</a>;  // Input Signal in external debug interface</pstext></ps>
    <ps name="shared/debug/haltingevents/CheckEDBGRQ" mylink="shared.debug.haltingevents.CheckEDBGRQ" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckEDBGRQ()
// =============
// Checks IMPLEMENTATION DEFINED EDBGRQ Input Signal of external debug interface.
// This is an example of an IMPLEMENTATION DEFINED source of External Debug Request debug events.

func <anchor link="func_CheckEDBGRQ_0">CheckEDBGRQ</anchor>()
begin
    if <a link="global_EDBGRQ" file="shared_pseudocode.xml">EDBGRQ</a> == <a link="enum_HIGH" file="shared_pseudocode.xml">HIGH</a> then
        <a link="func_ExternalDebugRequest_0" file="shared_pseudocode.xml">ExternalDebugRequest</a>();
    end;
end;</pstext></ps>
    <ps name="shared/debug/haltingevents/CheckExceptionCatch" mylink="shared.debug.haltingevents.CheckExceptionCatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckExceptionCatch()
// =====================
// Check whether an Exception Catch debug event is set on the current Exception level

func <anchor link="func_CheckExceptionCatch_1">CheckExceptionCatch</anchor>(exception_entry : boolean)
begin
    // Called after an exception entry or exit, that is, such that the Security state
    // and PSTATE.EL are correct for the exception target. When FEAT_Debugv8p2
    // is not implemented, this function might also be called at any time.
    let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    var base : integer;

    case ss of
        when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>    =&gt; base = 0;
        when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt; base = 4;
        when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a>     =&gt; base = 16;
        when <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a>      =&gt; base = 0;
    end;
    if <a link="func_HaltingAllowed_0" file="shared_pseudocode.xml">HaltingAllowed</a>() then
        var halt : boolean;
        if IsFeatureImplemented(FEAT_Debugv8p2) then
            let exception_exit : boolean = !exception_entry;
            let increment : integer{} = if ss == <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> then 4 else 8;
            let ctrl : bits(2) = (EDECCR()[UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) + base + increment]::
                                    EDECCR()[UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) + base]);
            case ctrl of
                when '00' =&gt;  halt = FALSE;
                when '01' =&gt;  halt = TRUE;
                when '10' =&gt;  halt = (exception_exit == TRUE);
                when '11' =&gt;  halt = (exception_entry == TRUE);
            end;
        else
            halt = (EDECCR()[UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) + base] == '1');
        end;

        if halt then
            if IsFeatureImplemented(FEAT_Debugv8p8) &amp;&amp; exception_entry then
                EDESR().EC = '1';
            else
                <a link="func_Halt_1" file="shared_pseudocode.xml">Halt</a>(<a link="global_DebugHalt_ExceptionCatch" file="shared_pseudocode.xml">DebugHalt_ExceptionCatch</a>);
            end;
        end;
    end;
end;</pstext></ps>
    <ps name="shared/debug/haltingevents/CheckExternalDebugRequestEvents" mylink="shared.debug.haltingevents.CheckExternalDebugRequestEvents" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckExternalDebugRequestEvents()
// =================================
// Checks for all External Debug Request debug events.

func <anchor link="func_CheckExternalDebugRequestEvents_0">CheckExternalDebugRequestEvents</anchor>()
begin
    <a link="func_CheckTRBEHalt_0" file="shared_pseudocode.xml">CheckTRBEHalt</a>();
    <a link="func_CheckPMUHalt_0" file="shared_pseudocode.xml">CheckPMUHalt</a>();
    <a link="func_CheckEDBGRQ_0" file="shared_pseudocode.xml">CheckEDBGRQ</a>();
    return;
end;</pstext></ps>
    <ps name="shared/debug/haltingevents/CheckHaltingStep" mylink="shared.debug.haltingevents.CheckHaltingStep" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckHaltingStep()
// ==================
// Check whether EDESR.SS has been set by Halting Step

func <anchor link="func_CheckHaltingStep_1">CheckHaltingStep</anchor>(is_async : boolean)
begin
    let step_enabled : boolean = EDECR().SS == '1' &amp;&amp; <a link="func_HaltingAllowed_0" file="shared_pseudocode.xml">HaltingAllowed</a>();
    let active_pending : boolean = step_enabled &amp;&amp; EDESR().SS == '1';
    if active_pending then
        if <a link="func_HaltingStep_DidNotStep_0" file="shared_pseudocode.xml">HaltingStep_DidNotStep</a>() then
            let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_0" file="shared_pseudocode.xml">NoFault</a>();
            <a link="func_Halt_3" file="shared_pseudocode.xml">Halt</a>(<a link="global_DebugHalt_Step_NoSyndrome" file="shared_pseudocode.xml">DebugHalt_Step_NoSyndrome</a>, is_async, fault);
        elsif <a link="func_HaltingStep_SteppedEX_0" file="shared_pseudocode.xml">HaltingStep_SteppedEX</a>() then
            let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_0" file="shared_pseudocode.xml">NoFault</a>();
            <a link="func_Halt_3" file="shared_pseudocode.xml">Halt</a>(<a link="global_DebugHalt_Step_Exclusive" file="shared_pseudocode.xml">DebugHalt_Step_Exclusive</a>, is_async, fault);
        else
            let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_0" file="shared_pseudocode.xml">NoFault</a>();
            <a link="func_Halt_3" file="shared_pseudocode.xml">Halt</a>(<a link="global_DebugHalt_Step_Normal" file="shared_pseudocode.xml">DebugHalt_Step_Normal</a>, is_async, fault);
        end;
    end;
    if step_enabled then <a link="global_ShouldAdvanceHS" file="shared_pseudocode.xml">ShouldAdvanceHS</a> = TRUE; end;
    return;
end;</pstext></ps>
    <ps name="shared/debug/haltingevents/CheckOSUnlockCatch" mylink="shared.debug.haltingevents.CheckOSUnlockCatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckOSUnlockCatch()
// ====================
// Called on unlocking the OS Lock to pend an OS Unlock Catch debug event

func <anchor link="func_CheckOSUnlockCatch_0">CheckOSUnlockCatch</anchor>()
begin
    if ((IsFeatureImplemented(FEAT_DoPD) &amp;&amp; CTIDEVCTL().OSUCE == '1') ||
          (!IsFeatureImplemented(FEAT_DoPD) &amp;&amp; EDECR().OSUCE == '1')) then
        if !<a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then EDESR().OSUC = '1'; end;
    end;
end;</pstext></ps>
    <ps name="shared/debug/haltingevents/CheckPMUHalt" mylink="shared.debug.haltingevents.CheckPMUHalt" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckPMUHalt()
// ==============

func <anchor link="func_CheckPMUHalt_0">CheckPMUHalt</anchor>()
begin
    if !IsFeatureImplemented(FEAT_Debugv8p9) || !IsFeatureImplemented(FEAT_PMUv3p9) then
        return;
    end;

    // The request remains set until the condition is cleared.
    // For example, an interrupt handler or cross-triggered event handler clears
    // the overflow status flag by writing to PMOVSCLR_EL0

    let include_r1 : boolean = TRUE;
    let include_r2 : boolean = TRUE;
    let include_r3 : boolean = TRUE;

    let pmuhalt : boolean = <a link="func_CheckPMUOverflowCondition_4" file="shared_pseudocode.xml">CheckPMUOverflowCondition</a>(<a link="enum_PMUOverflowCondition_EDBGRQ" file="shared_pseudocode.xml">PMUOverflowCondition_EDBGRQ</a>,
                                                      include_r1, include_r2, include_r3);
    if pmuhalt &amp;&amp; EDECR().PME == '1' then
        <a link="func_ExternalDebugRequest_0" file="shared_pseudocode.xml">ExternalDebugRequest</a>();
    end;
end;</pstext></ps>
    <ps name="shared/debug/haltingevents/CheckPendingExceptionCatch" mylink="shared.debug.haltingevents.CheckPendingExceptionCatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckPendingExceptionCatch()
// ============================
// Check whether EDESR.EC has been set by an Exception Catch debug event.

func <anchor link="func_CheckPendingExceptionCatch_1">CheckPendingExceptionCatch</anchor>(is_async : boolean)
begin
    if IsFeatureImplemented(FEAT_Debugv8p8) &amp;&amp; <a link="func_HaltingAllowed_0" file="shared_pseudocode.xml">HaltingAllowed</a>() &amp;&amp; EDESR().EC == '1' then
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_0" file="shared_pseudocode.xml">NoFault</a>();
        <a link="func_Halt_3" file="shared_pseudocode.xml">Halt</a>(<a link="global_DebugHalt_ExceptionCatch" file="shared_pseudocode.xml">DebugHalt_ExceptionCatch</a>, is_async, fault);
    end;
end;</pstext></ps>
    <ps name="shared/debug/haltingevents/CheckPendingOSUnlockCatch" mylink="shared.debug.haltingevents.CheckPendingOSUnlockCatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckPendingOSUnlockCatch()
// ===========================
// Check whether EDESR.OSUC has been set by an OS Unlock Catch debug event

func <anchor link="func_CheckPendingOSUnlockCatch_0">CheckPendingOSUnlockCatch</anchor>()
begin
    if <a link="func_HaltingAllowed_0" file="shared_pseudocode.xml">HaltingAllowed</a>() &amp;&amp; EDESR().OSUC == '1' then
        let is_async : boolean = TRUE;
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_0" file="shared_pseudocode.xml">NoFault</a>();
        <a link="func_Halt_3" file="shared_pseudocode.xml">Halt</a>(<a link="global_DebugHalt_OSUnlockCatch" file="shared_pseudocode.xml">DebugHalt_OSUnlockCatch</a>, is_async, fault);
    end;
end;</pstext></ps>
    <ps name="shared/debug/haltingevents/CheckPendingResetCatch" mylink="shared.debug.haltingevents.CheckPendingResetCatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckPendingResetCatch()
// ========================
// Check whether EDESR.RC has been set by a Reset Catch debug event

func <anchor link="func_CheckPendingResetCatch_0">CheckPendingResetCatch</anchor>()
begin
    if <a link="func_HaltingAllowed_0" file="shared_pseudocode.xml">HaltingAllowed</a>() &amp;&amp; EDESR().RC == '1' then
        let is_async : boolean = TRUE;
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_0" file="shared_pseudocode.xml">NoFault</a>();
        <a link="func_Halt_3" file="shared_pseudocode.xml">Halt</a>(<a link="global_DebugHalt_ResetCatch" file="shared_pseudocode.xml">DebugHalt_ResetCatch</a>, is_async, fault);
    end;
end;</pstext></ps>
    <ps name="shared/debug/haltingevents/CheckResetCatch" mylink="shared.debug.haltingevents.CheckResetCatch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckResetCatch()
// =================
// Called after reset

func <anchor link="func_CheckResetCatch_0">CheckResetCatch</anchor>()
begin
    if ((IsFeatureImplemented(FEAT_DoPD) &amp;&amp; CTIDEVCTL().RCE == '1') ||
          (!IsFeatureImplemented(FEAT_DoPD) &amp;&amp; EDECR().RCE == '1')) then
        EDESR().RC = '1';
        // If halting is allowed then halt immediately
        if <a link="func_HaltingAllowed_0" file="shared_pseudocode.xml">HaltingAllowed</a>() then <a link="func_Halt_1" file="shared_pseudocode.xml">Halt</a>(<a link="global_DebugHalt_ResetCatch" file="shared_pseudocode.xml">DebugHalt_ResetCatch</a>); end;
    end;
end;</pstext></ps>
    <ps name="shared/debug/haltingevents/CheckSoftwareAccessToDebugRegisters" mylink="shared.debug.haltingevents.CheckSoftwareAccessToDebugRegisters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckSoftwareAccessToDebugRegisters()
// =====================================
// Check for access to Breakpoint and Watchpoint registers.

func <anchor link="func_CheckSoftwareAccessToDebugRegisters_0">CheckSoftwareAccessToDebugRegisters</anchor>()
begin
    let os_lock : bit = (if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then DBGOSLSR().OSLK else OSLSR_EL1().OSLK);
    if <a link="func_HaltingAllowed_0" file="shared_pseudocode.xml">HaltingAllowed</a>() &amp;&amp; EDSCR().TDA == '1' &amp;&amp; os_lock == '0' then
        <a link="func_Halt_1" file="shared_pseudocode.xml">Halt</a>(<a link="global_DebugHalt_SoftwareAccess" file="shared_pseudocode.xml">DebugHalt_SoftwareAccess</a>);
    end;
end;</pstext></ps>
    <ps name="shared/debug/haltingevents/CheckTRBEHalt" mylink="shared.debug.haltingevents.CheckTRBEHalt" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckTRBEHalt()
// ===============

func <anchor link="func_CheckTRBEHalt_0">CheckTRBEHalt</anchor>()
begin
    if !IsFeatureImplemented(FEAT_Debugv8p9) || !IsFeatureImplemented(FEAT_TRBE_EXT) then
        return;
    end;

    if <a link="func_TraceBufferEnabled_0" file="shared_pseudocode.xml">TraceBufferEnabled</a>() &amp;&amp; TRBSR_EL1().IRQ == '1' &amp;&amp; EDECR().TRBE == '1' then
        <a link="func_ExternalDebugRequest_0" file="shared_pseudocode.xml">ExternalDebugRequest</a>();
    end;
end;</pstext></ps>
    <ps name="shared/debug/haltingevents/ExternalDebugRequest" mylink="shared.debug.haltingevents.ExternalDebugRequest" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExternalDebugRequest()
// ======================

func <anchor link="func_ExternalDebugRequest_0">ExternalDebugRequest</anchor>()
begin
    if <a link="func_HaltingAllowed_0" file="shared_pseudocode.xml">HaltingAllowed</a>() then
        let is_async : boolean = TRUE;
        let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_0" file="shared_pseudocode.xml">NoFault</a>();
        <a link="func_Halt_3" file="shared_pseudocode.xml">Halt</a>(<a link="global_DebugHalt_EDBGRQ" file="shared_pseudocode.xml">DebugHalt_EDBGRQ</a>, is_async, fault);
    // Otherwise the CTI continues to assert the debug request until it is taken.
    end;
end;</pstext></ps>
    <ps name="shared/debug/haltingevents/HSAdvance" mylink="shared.debug.haltingevents.HSAdvance" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HSAdvance()
// ===========
// Advance the Halting Step State Machine

func <anchor link="func_HSAdvance_0">HSAdvance</anchor>()
begin
    if !<a link="global_ShouldAdvanceHS" file="shared_pseudocode.xml">ShouldAdvanceHS</a> then return; end;
    let step_enabled : boolean = EDECR().SS == '1' &amp;&amp; <a link="func_HaltingAllowed_0" file="shared_pseudocode.xml">HaltingAllowed</a>();
    let active_not_pending : boolean = step_enabled &amp;&amp; EDESR().SS == '0';
    if active_not_pending then EDESR().SS = '1'; end;  // set as pending.
    <a link="global_ShouldAdvanceHS" file="shared_pseudocode.xml">ShouldAdvanceHS</a> = FALSE;
    return;
end;</pstext></ps>
    <ps name="shared/debug/haltingevents/HaltingStep_DidNotStep" mylink="shared.debug.haltingevents.HaltingStep_DidNotStep" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HaltingStep_DidNotStep()
// ========================
// Returns TRUE if the previously executed instruction was executed in the inactive state, that is,
// if it was not itself stepped.

impdef func <anchor link="func_HaltingStep_DidNotStep_0">HaltingStep_DidNotStep</anchor>() =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="shared/debug/haltingevents/HaltingStep_SteppedEX" mylink="shared.debug.haltingevents.HaltingStep_SteppedEX" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HaltingStep_SteppedEX()
// =======================
// Returns TRUE if the previously executed instruction was a Load-Exclusive class instruction
// executed in the active-not-pending state.

impdef func <anchor link="func_HaltingStep_SteppedEX_0">HaltingStep_SteppedEX</anchor>() =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="shared/debug/interrupts/ExternalDebugInterruptsDisabled" mylink="shared.debug.interrupts.ExternalDebugInterruptsDisabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExternalDebugInterruptsDisabled()
// =================================
// Determine whether EDSCR disables interrupts routed to 'target'.

func <anchor link="func_ExternalDebugInterruptsDisabled_1">ExternalDebugInterruptsDisabled</anchor>(target : bits(2)) =&gt; boolean
begin
    var int_dis : boolean;
    let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(target);
    if IsFeatureImplemented(FEAT_Debugv8p4) then
        if EDSCR().INTdis[0] == '1' then
            case ss of
                when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt; int_dis = <a link="func_ExternalInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalInvasiveDebugEnabled</a>();
                when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;    int_dis = <a link="func_ExternalSecureInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalSecureInvasiveDebugEnabled</a>();
                when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;     int_dis = <a link="func_ExternalRealmInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalRealmInvasiveDebugEnabled</a>();
                when <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a> =&gt;      int_dis = <a link="func_ExternalRootInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalRootInvasiveDebugEnabled</a>();
            end;
        else
            int_dis = FALSE;
        end;
    else
        case target of
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
                int_dis = (EDSCR().INTdis == '11' &amp;&amp; <a link="func_ExternalSecureInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalSecureInvasiveDebugEnabled</a>());
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
                int_dis = (EDSCR().INTdis == '1x' &amp;&amp; <a link="func_ExternalInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalInvasiveDebugEnabled</a>());
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
                if ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
                    int_dis = (EDSCR().INTdis == '1x' &amp;&amp; <a link="func_ExternalSecureInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalSecureInvasiveDebugEnabled</a>());
                else
                    int_dis = (EDSCR().INTdis != '00' &amp;&amp; <a link="func_ExternalInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalInvasiveDebugEnabled</a>());
                end;
        end;
    end;
    return int_dis;
end;</pstext></ps>
    <ps name="shared/debug/pmu" mylink="shared.debug.pmu" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">var <anchor link="global_PMUEventAccumulator">PMUEventAccumulator</anchor> : array [[31]] of integer;   // Accumulates PMU events for a cycle
var <anchor link="global_PMULastThresholdValue">PMULastThresholdValue</anchor> : array [[31]] of boolean; // A record of the threshold result for each
                                                     // event counter on the previous cycle

// Constant used in PMU functions to represent actions on the cycle counter.
constant <anchor link="global_CYCLE_COUNTER_ID">CYCLE_COUNTER_ID</anchor> : integer = 31;
// Constant used in PMU functions to represent actions on the instruction counter.
constant <anchor link="global_INSTRUCTION_COUNTER_ID">INSTRUCTION_COUNTER_ID</anchor> : integer = 32;</pstext></ps>
    <ps name="shared/debug/pmu/CheckForPMUOverflow" mylink="shared.debug.pmu.CheckForPMUOverflow" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckForPMUOverflow()
// =====================
// Called before each instruction is executed.
// If a PMU event counter has overflowed, this function might do any of:
//  - Signal a Performance Monitors overflow interrupt request.
//  - Signal a CTI Performance Monitors overflow event.
//  - Generate an External Debug Request debug event.
//  - Generate a BRBE freeze event.

func <anchor link="func_CheckForPMUOverflow_0">CheckForPMUOverflow</anchor>()
begin
    let include_r1 : boolean = TRUE;
    let include_r2 : boolean = TRUE;
    let include_r3 : boolean = TRUE;

    let enabled : boolean = <a link="func_PMUInterruptEnabled_0" file="shared_pseudocode.xml">PMUInterruptEnabled</a>();
    let pmuirq : boolean = <a link="func_CheckPMUOverflowCondition_4" file="shared_pseudocode.xml">CheckPMUOverflowCondition</a>(<a link="enum_PMUOverflowCondition_IRQ" file="shared_pseudocode.xml">PMUOverflowCondition_IRQ</a>,
                                                     include_r1, include_r2, include_r3);

    SetInterruptRequestLevel(<a link="enum_InterruptID_PMUIRQ" file="shared_pseudocode.xml">InterruptID_PMUIRQ</a>,
                             if enabled &amp;&amp; pmuirq then <a link="enum_HIGH" file="shared_pseudocode.xml">HIGH</a> else <a link="enum_LOW" file="shared_pseudocode.xml">LOW</a>);
    CTI_SetEventLevel(<a link="enum_CrossTriggerIn_PMUOverflow" file="shared_pseudocode.xml">CrossTriggerIn_PMUOverflow</a>,
                      if pmuirq then <a link="enum_HIGH" file="shared_pseudocode.xml">HIGH</a> else <a link="enum_LOW" file="shared_pseudocode.xml">LOW</a>);

    if <a link="func_ShouldBRBEFreeze_0" file="shared_pseudocode.xml">ShouldBRBEFreeze</a>() then
        <a link="func_BRBEFreeze_0" file="shared_pseudocode.xml">BRBEFreeze</a>();
    end;

    return;
end;</pstext></ps>
    <ps name="shared/debug/pmu/CheckPMUOverflowCondition" mylink="shared.debug.pmu.CheckPMUOverflowCondition" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckPMUOverflowCondition()
// ===========================
// Checks for PMU overflow under certain parameter conditions described by 'reason'.
// If 'include_r1' is TRUE, then check counters in the range [0..(HPMN-1)], CCNTR
//     and ICNTR, unless excluded by 'reason'.
// If 'include_r2' is TRUE, then check counters in the range [HPMN..(EPMN-1)].
// If 'include_r3' is TRUE, then check counters in the range [EPMN..(N-1)].

func <anchor link="func_CheckPMUOverflowCondition_4">CheckPMUOverflowCondition</anchor>(reason : <a link="type_PMUOverflowCondition" file="shared_pseudocode.xml">PMUOverflowCondition</a>,
                               include_r1 : boolean, include_r2 : boolean, include_r3 : boolean
                              ) =&gt; boolean
begin
    // 'reason' is decoded into a further set of parameters:
    // If 'check_e' is TRUE, then check the applicable one of PMCR_EL0.E and MDCR_EL2.HPME.
    // If 'check_inten' is TRUE, then check the applicable PMINTENCLR_EL1 bit.
    // If 'exclude_cyc' is TRUE, then CCNTR is NOT checked.
    var check_e : boolean;
    var check_inten : boolean;
    var exclude_cyc : boolean;
    case reason of
        when <a link="enum_PMUOverflowCondition_PMUException" file="shared_pseudocode.xml">PMUOverflowCondition_PMUException</a> =&gt;
            check_e      = TRUE;
            check_inten  = TRUE;
            exclude_cyc  = FALSE;
        when <a link="enum_PMUOverflowCondition_BRBEFreeze" file="shared_pseudocode.xml">PMUOverflowCondition_BRBEFreeze</a> =&gt;
            check_e      = FALSE;
            check_inten  = FALSE;
            exclude_cyc  = TRUE;
        when <a link="enum_PMUOverflowCondition_Freeze" file="shared_pseudocode.xml">PMUOverflowCondition_Freeze</a> =&gt;
            check_e      = FALSE;
            check_inten  = FALSE;
            exclude_cyc  = TRUE;
        when <a link="enum_PMUOverflowCondition_IRQ" file="shared_pseudocode.xml">PMUOverflowCondition_IRQ</a>, <a link="enum_PMUOverflowCondition_EDBGRQ" file="shared_pseudocode.xml">PMUOverflowCondition_EDBGRQ</a> =&gt;
            check_e      = TRUE;
            check_inten  = TRUE;
            exclude_cyc  = FALSE;
        otherwise =&gt;
            unreachable;
    end;

    var ovsf : bits(64);

    if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then
        ovsf = PMOVSSET_EL0();
        ovsf[63:33] = Zeros{31};
        if !IsFeatureImplemented(FEAT_PMUv3_ICNTR) then
            ovsf[<a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a>] = '0';
        end;
    else
        ovsf = ZeroExtend{64}(PMOVSSET());
    end;

    let counters : integer{} = NUM_PMU_COUNTERS;
    // Remove unimplemented counters - these fields are RES0
    if counters &lt; 31 then
        ovsf[30:counters] = Zeros{31-counters};
    end;

    for idx = 0 to counters - 1 do
        var global_en : bit;
        case <a link="func_GetPMUCounterRange_1" file="shared_pseudocode.xml">GetPMUCounterRange</a>(idx) of
            when <a link="enum_PMUCounterRange_R1" file="shared_pseudocode.xml">PMUCounterRange_R1</a> =&gt;
                global_en = if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then PMCR_EL0().E else PMCR().E;
                if !include_r1 then
                    ovsf[idx] = '0';
                end;
            when <a link="enum_PMUCounterRange_R2" file="shared_pseudocode.xml">PMUCounterRange_R2</a> =&gt;
                global_en = if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then MDCR_EL2().HPME else HDCR().HPME;
                if !include_r2 then
                    ovsf[idx] = '0';
                end;
            when <a link="enum_PMUCounterRange_R3" file="shared_pseudocode.xml">PMUCounterRange_R3</a> =&gt;
                global_en = PMCCR().EPME;
                if !include_r3 then
                    ovsf[idx] = '0';
                end;
            otherwise =&gt;
                unreachable;
        end;
        if check_e then
            ovsf[idx] = ovsf[idx] AND global_en;
        end;
    end;

    // Cycle counter
    if exclude_cyc || !include_r1 then
        ovsf[<a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a>] = '0';
    end;

    if check_e then
        ovsf[<a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a>] = ovsf[<a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a>] AND PMCR_EL0().E;
    end;

    // Instruction counter
    if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() &amp;&amp; IsFeatureImplemented(FEAT_PMUv3_ICNTR) then
        if !include_r1 then
            ovsf[<a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a>] = '0';
        end;
        if check_e then
            ovsf[<a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a>] = ovsf[<a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a>] AND PMCR_EL0().E;
        end;
    end;

    if check_inten then
        let inten : bits(64) = (if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then PMINTENCLR_EL1()
                                   else ZeroExtend{64}(PMINTENCLR()));
        ovsf = ovsf AND inten;
    end;

    return !IsZero(ovsf);
end;</pstext></ps>
    <ps name="shared/debug/pmu/ClearEventCounters" mylink="shared.debug.pmu.ClearEventCounters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ClearEventCounters()
// ====================
// Zero all the event counters.
// Called on a write to PMCR_EL0 or PMCR that writes '1' to PMCR_EL0.P or PMCR.P.

func <anchor link="func_ClearEventCounters_0">ClearEventCounters</anchor>()
begin
    // Although ZeroPMUCounters implements the functionality for PMUACR_EL1
    // that is part of FEAT_PMUv3p9, it should be noted that writes to
    // PMCR_EL0 are not allowed at EL0 when PMUSERENR_EL0.UEN is 1, meaning
    // it is not relevant in this case.
    <a link="func_ZeroPMUCounters_1" file="shared_pseudocode.xml">ZeroPMUCounters</a>(Zeros{33} :: Ones{31});
end;</pstext></ps>
    <ps name="shared/debug/pmu/CountPMUEvents" mylink="shared.debug.pmu.CountPMUEvents" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CountPMUEvents()
// ================
// Return TRUE if counter &quot;idx&quot; should count its event.
// For the cycle counter, idx == CYCLE_COUNTER_ID (31).
// For the instruction counter, idx == INSTRUCTION_COUNTER_ID (32).

func <anchor link="func_CountPMUEvents_1">CountPMUEvents</anchor>(idx : integer) =&gt; boolean
begin
    let counters : integer = NUM_PMU_COUNTERS;
    assert (idx == <a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a> || idx &lt; counters ||
            (idx == <a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a> &amp;&amp; IsFeatureImplemented(FEAT_PMUv3_ICNTR)));

    var debug : boolean;
    var enabled : boolean;
    var prohibited : boolean;
    var filtered : boolean;
    var frozen : boolean;

    // Event counting is disabled in Debug state
    debug = <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>();

    // Software can reserve some counters
    let counter_range : <a link="type_PMUCounterRange" file="shared_pseudocode.xml">PMUCounterRange</a> = <a link="func_GetPMUCounterRange_1" file="shared_pseudocode.xml">GetPMUCounterRange</a>(idx);
    var ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>();

    // Main enable controls
    var global_en : bit;
    var counter_en : bit;
    case counter_range of
        when <a link="enum_PMUCounterRange_R1" file="shared_pseudocode.xml">PMUCounterRange_R1</a> =&gt;
            global_en = if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then PMCR_EL0().E else PMCR().E;
        when <a link="enum_PMUCounterRange_R2" file="shared_pseudocode.xml">PMUCounterRange_R2</a> =&gt;
            global_en = if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then MDCR_EL2().HPME else HDCR().HPME;
        when <a link="enum_PMUCounterRange_R3" file="shared_pseudocode.xml">PMUCounterRange_R3</a> =&gt;
            assert IsFeatureImplemented(FEAT_PMUv3_EXTPMN);
            global_en = PMCCR().EPME;
        otherwise =&gt;
            unreachable;
    end;

    case idx of
        when <a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a> =&gt;
            assert <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>();
            counter_en = PMCNTENSET_EL0().F0;
        when <a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a> =&gt;
            counter_en = if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then PMCNTENSET_EL0().C else PMCNTENSET().C;
        otherwise =&gt;
            counter_en = if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then PMCNTENSET_EL0()[idx] else PMCNTENSET()[idx];
    end;

    enabled = global_en == '1' &amp;&amp; counter_en == '1';

    // Event counting is allowed unless it is prohibited by any rule below
    prohibited = FALSE;

    // Event counting in Secure state or at EL3 is prohibited if all of:
    // * EL3 is implemented
    // * One of the following is true:
    //   - EL3 is using AArch64, MDCR_EL3.SPME == 0, and either:
    //     - FEAT_PMUv3p7 is not implemented
    //     - MDCR_EL3.MPMX == 0
    //   - EL3 is using AArch32 and SDCR.SPME == 0
    // * Either not executing at EL0 using AArch32, or one of the following is true:
    //     - EL3 is using AArch32 and SDER.SUNIDEN == 0
    //     - EL3 is using AArch64, EL1 is using AArch32, and SDER32_EL3.SUNIDEN == 0
    // * PMNx is not reserved for use by the external interface
    if (<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; (ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> || <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp;
          counter_range != <a link="enum_PMUCounterRange_R3" file="shared_pseudocode.xml">PMUCounterRange_R3</a>) then
        if !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
            prohibited = (MDCR_EL3().SPME == '0' &amp;&amp;
                          (!IsFeatureImplemented(FEAT_PMUv3p7) || MDCR_EL3().MPMX == '0'));
        else
            prohibited = SDCR().SPME == '0';
        end;

        if prohibited &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
            if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
                prohibited = SDER().SUNIDEN == '0';
            elsif <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
                prohibited = SDER32_EL3().SUNIDEN == '0';
            end;
        end;
    end;

    // Event counting at EL3 is prohibited if all of:
    // * FEAT_PMUv3p7 is implemented
    // * EL3 is using AArch64
    // * One of the following is true:
    //   - MDCR_EL3.SPME == 0
    //   - PMNx is not reserved for EL2
    // * MDCR_EL3.MPMX == 1
    // * PMNx is not reserved for use by the external interface
    if (!prohibited &amp;&amp; IsFeatureImplemented(FEAT_PMUv3p7) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp;
          <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() &amp;&amp; counter_range != <a link="enum_PMUCounterRange_R3" file="shared_pseudocode.xml">PMUCounterRange_R3</a>) then
        prohibited = (MDCR_EL3().MPMX == '1' &amp;&amp;
                      (MDCR_EL3().SPME == '0' || counter_range == <a link="enum_PMUCounterRange_R1" file="shared_pseudocode.xml">PMUCounterRange_R1</a>));
    end;

    // Event counting at EL2 is prohibited if all of:
    // * FEAT_PMUv3p1 is implemented
    // * PMNx is not reserved for EL2 or the external interface
    // * EL2 is using AArch64 and MDCR_EL2.HPMD == 1, or EL2 is using AArch32 and HDCR.HPMD == 1
    if (!prohibited &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> &amp;&amp; IsFeatureImplemented(FEAT_PMUv3p1) &amp;&amp;
          counter_range == <a link="enum_PMUCounterRange_R1" file="shared_pseudocode.xml">PMUCounterRange_R1</a>) then
        let hpmd : bit = if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then MDCR_EL2().HPMD else HDCR().HPMD;
        prohibited = hpmd == '1';
    end;

    // The IMPLEMENTATION DEFINED authentication interface might override software
    if prohibited &amp;&amp; !IsFeatureImplemented(FEAT_Debugv8p2) then
        prohibited = !<a link="func_ExternalSecureNoninvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalSecureNoninvasiveDebugEnabled</a>();
    end;

    // If FEAT_PMUv3p7 is implemented, event counting can be frozen
    if IsFeatureImplemented(FEAT_PMUv3p7) then
        var fz : bit;
        case counter_range of
            when <a link="enum_PMUCounterRange_R1" file="shared_pseudocode.xml">PMUCounterRange_R1</a> =&gt;
                fz = if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then PMCR_EL0().FZO else PMCR().FZO;
            when <a link="enum_PMUCounterRange_R2" file="shared_pseudocode.xml">PMUCounterRange_R2</a> =&gt;
                fz = if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then MDCR_EL2().HPMFZO else HDCR().HPMFZO;
            when <a link="enum_PMUCounterRange_R3" file="shared_pseudocode.xml">PMUCounterRange_R3</a> =&gt;
                fz = '0';
            otherwise =&gt;
                unreachable;
        end;
        frozen = (fz == '1') &amp;&amp; <a link="func_ShouldPMUFreeze_1" file="shared_pseudocode.xml">ShouldPMUFreeze</a>(counter_range);
        frozen = frozen || <a link="func_SPEFreezeOnEvent_1" file="shared_pseudocode.xml">SPEFreezeOnEvent</a>(idx);
    else
        frozen = FALSE;
    end;

    // PMCR_EL0.DP or PMCR.DP disables the cycle counter when event counting is prohibited
    // or frozen
    if (prohibited || frozen) &amp;&amp; idx == <a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a> then
        let dp : bit = if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then PMCR_EL0().DP else PMCR().DP;
        enabled = enabled &amp;&amp; dp == '0';
        // Otherwise whether event counting is prohibited or frozen does not affect the cycle
        // counter
        prohibited = FALSE;
        frozen = FALSE;
    end;

    // If FEAT_PMUv3p5 is implemented, cycle counting can be prohibited.
    // This is not overridden by PMCR_EL0.DP.
    if IsFeatureImplemented(FEAT_PMUv3p5) &amp;&amp; idx == <a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a> then
        if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; (ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> || <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
            let sccd = if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then MDCR_EL3().SCCD else SDCR().SCCD;
            if sccd == '1' then
                prohibited = TRUE;
            end;
        end;

        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
            let hccd = if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then MDCR_EL2().HCCD else HDCR().HCCD;
            if hccd == '1' then
                prohibited = TRUE;
            end;
        end;
    end;

    // If FEAT_PMUv3p7 is implemented, cycle counting an be prohibited at EL3.
    // This is not overridden by PMCR_EL0.DP.
    if IsFeatureImplemented(FEAT_PMUv3p7) &amp;&amp; idx == <a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a> then
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() &amp;&amp; MDCR_EL3().MCCD == '1' then
            prohibited = TRUE;
        end;
    end;

    // Event counting can be filtered by the {P, U, NSK, NSU, NSH, M, SH, RLK, RLU, RLH} bits
    var filter : bits(32);
    case idx of
        when <a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a> =&gt;
            filter = PMICFILTR_EL0()[31:0];
        when <a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a> =&gt;
            filter = if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then PMCCFILTR_EL0()[31:0] else PMCCFILTR();
        otherwise =&gt;
            filter = if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then PMEVTYPER_EL0(idx)[31:0] else PMEVTYPER(idx);
    end;

    let p : bit   = filter[31];
    let u : bit   = filter[30];
    let nsk : bit = if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then filter[29] else '0';
    let nsu : bit = if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then filter[28] else '0';
    let nsh : bit = if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then filter[27] else '0';
    let m : bit   = if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then filter[26] else '0';
    let sh : bit  = if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; IsFeatureImplemented(FEAT_SEL2) then filter[24] else '0';
    let rlk : bit = if IsFeatureImplemented(FEAT_RME) then filter[22] else '0';
    let rlu : bit = if IsFeatureImplemented(FEAT_RME) then filter[21] else '0';
    let rlh : bit = if IsFeatureImplemented(FEAT_RME) then filter[20] else '0';

    ss = <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>();
    case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL of
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            case ss of
                when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt; filtered = u != nsu;
                when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;    filtered = u == '1';
                when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;     filtered = u != rlu;
            end;
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            case ss of
                when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt; filtered = p != nsk;
                when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;    filtered = p == '1';
                when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;     filtered = p != rlk;
            end;
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            case ss of
                when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt; filtered = nsh == '0';
                when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;    filtered = nsh == sh;
                when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;     filtered = nsh == rlh;
            end;
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then
                filtered = m != p;
            else
                filtered = p == '1';
            end;
    end;

    if IsFeatureImplemented(FEAT_PMUv3_SME) then
        let is_streaming_mode : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM == '1';
        var vs : bits(2);
        case idx of
            when <a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a> =&gt;
                vs = PMICFILTR_EL0().VS;
            when <a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a> =&gt;
                vs = PMCCFILTR_EL0().VS;
            otherwise =&gt;
                vs = PMEVTYPER_EL0(idx).VS;
        end;

        var streaming_mode_filtered : boolean;
        if vs == '11' then
            streaming_mode_filtered = <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_RES_PMU_VS" file="shared_pseudocode.xml">Unpredictable_RES_PMU_VS</a>);
        else
            streaming_mode_filtered =  ((is_streaming_mode &amp;&amp; vs[0] == '1') ||
                                        (!is_streaming_mode &amp;&amp; vs[1] == '1'));
        end;

        filtered = filtered || streaming_mode_filtered;
    end;

    return !debug &amp;&amp; enabled &amp;&amp; !prohibited &amp;&amp; !filtered &amp;&amp; !frozen;
end;</pstext></ps>
    <ps name="shared/debug/pmu/EffectiveEPMN" mylink="shared.debug.pmu.EffectiveEPMN" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveEPMN()
// ===============
// Returns the Effective value of PMCCR.EPMN.

func <anchor link="func_EffectiveEPMN_0">EffectiveEPMN</anchor>() =&gt; bits(5)
begin
    let counters : integer = NUM_PMU_COUNTERS;
    var epmn_bits : bits(5);

    if IsFeatureImplemented(FEAT_PMUv3_EXTPMN) then
        epmn_bits = PMCCR().EPMN;
        if UInt(epmn_bits) &gt; counters then
            (-, epmn_bits) = ConstrainUnpredictableBits{5}(<a link="enum_Unpredictable_RES_EPMN" file="shared_pseudocode.xml">Unpredictable_RES_EPMN</a>);
        end;
    else
        epmn_bits = counters[4:0];
    end;

    return epmn_bits;
end;</pstext></ps>
    <ps name="shared/debug/pmu/EffectiveHPMN" mylink="shared.debug.pmu.EffectiveHPMN" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveHPMN()
// ===============
// Returns the Effective value of MDCR_EL2.HPMN or HDCR.HPMN.

func <anchor link="func_EffectiveHPMN_0">EffectiveHPMN</anchor>() =&gt; bits(5)
begin
    let counters : integer = UInt(<a link="func_EffectiveEPMN_0" file="shared_pseudocode.xml">EffectiveEPMN</a>());
    var hpmn_bits : bits(5);

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then     // Software can reserve some event counters for EL2
        hpmn_bits = if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then MDCR_EL2().HPMN else HDCR().HPMN;

        // When FEAT_PMUv3_EXTPMN is implemented, out of range values are capped.
        if UInt(hpmn_bits) &gt; counters &amp;&amp; IsFeatureImplemented(FEAT_PMUv3_EXTPMN) then
            hpmn_bits = counters[4:0];
        end;

        if (UInt(hpmn_bits) &gt; counters ||
              (!IsFeatureImplemented(FEAT_HPMN0) &amp;&amp; IsZero(hpmn_bits))) then
            (-, hpmn_bits) = ConstrainUnpredictableBits{5}(<a link="enum_Unpredictable_RES_HPMN" file="shared_pseudocode.xml">Unpredictable_RES_HPMN</a>);
        end;
    else
        hpmn_bits = counters[4:0];
    end;

    return hpmn_bits;
end;</pstext></ps>
    <ps name="shared/debug/pmu/GetNumEventCountersAccessible" mylink="shared.debug.pmu.GetNumEventCountersAccessible" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetNumEventCountersAccessible()
// ===============================
// Return the number of event counters that can be accessed at the current Exception level.

func <anchor link="func_GetNumEventCountersAccessible_0">GetNumEventCountersAccessible</anchor>() =&gt; integer{0..NUM_PMU_COUNTERS}
begin
    var n : integer;

    // Software can reserve some counters for EL2
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>} &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        n = UInt(<a link="func_EffectiveHPMN_0" file="shared_pseudocode.xml">EffectiveHPMN</a>());
    else
        n = UInt(<a link="func_EffectiveEPMN_0" file="shared_pseudocode.xml">EffectiveEPMN</a>());
    end;

    return n as integer{0..NUM_PMU_COUNTERS};
end;</pstext></ps>
    <ps name="shared/debug/pmu/GetNumEventCountersSelfHosted" mylink="shared.debug.pmu.GetNumEventCountersSelfHosted" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetNumEventCountersSelfHosted()
// ===============================
// Return the number of event counters that can be accessed by the Self-hosted software.

func <anchor link="func_GetNumEventCountersSelfHosted_0">GetNumEventCountersSelfHosted</anchor>() =&gt; integer
begin
    if IsFeatureImplemented(FEAT_PMUv3_EXTPMN) then
        return UInt(<a link="func_EffectiveEPMN_0" file="shared_pseudocode.xml">EffectiveEPMN</a>());
    else
        return NUM_PMU_COUNTERS;
    end;
end;</pstext></ps>
    <ps name="shared/debug/pmu/GetPMUAccessMask" mylink="shared.debug.pmu.GetPMUAccessMask" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetPMUAccessMask()
// ==================
// Return a mask of the PMU counters accessible at the current Exception level

func <anchor link="func_GetPMUAccessMask_0">GetPMUAccessMask</anchor>() =&gt; bits(64)
begin
    var mask : bits(64) = Zeros{};

    // PMICNTR_EL0 is only accessible at EL0 using AArch64 when PMUSERENR_EL0.UEN is 1.
    if IsFeatureImplemented(FEAT_PMUv3_ICNTR) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        assert IsFeatureImplemented(FEAT_PMUv3p9);
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> || PMUSERENR_EL0().UEN == '1' then
            mask[<a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a>] = '1';
        end;
    end;

    // PMCCNTR_EL0 is always implemented and accessible
    mask[<a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a>] = '1';

    // PMEVCNTR_EL0(n)
    let counters : integer{} = <a link="func_GetNumEventCountersAccessible_0" file="shared_pseudocode.xml">GetNumEventCountersAccessible</a>();
    if counters &gt; 0 then
        mask[counters-1:0] = Ones{counters};
    end;

    // Check EL0 ignore access conditions
    if (IsFeatureImplemented(FEAT_PMUv3p9) &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) &amp;&amp;
          <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; PMUSERENR_EL0().UEN == '1') then
        mask = mask AND PMUACR_EL1();  // User access control
    end;

    return mask;
end;</pstext></ps>
    <ps name="shared/debug/pmu/GetPMUCounterRange" mylink="shared.debug.pmu.GetPMUCounterRange" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetPMUCounterRange()
// ====================
// Returns the range that a counter is currently in.

func <anchor link="func_GetPMUCounterRange_1">GetPMUCounterRange</anchor>(n : integer) =&gt; <a link="type_PMUCounterRange" file="shared_pseudocode.xml">PMUCounterRange</a>
begin

    let counters : integer = NUM_PMU_COUNTERS;
    let epmn : integer = UInt(<a link="func_EffectiveEPMN_0" file="shared_pseudocode.xml">EffectiveEPMN</a>());
    let hpmn : integer = UInt(<a link="func_EffectiveHPMN_0" file="shared_pseudocode.xml">EffectiveHPMN</a>());

    if n &lt; hpmn then
        return <a link="enum_PMUCounterRange_R1" file="shared_pseudocode.xml">PMUCounterRange_R1</a>;
    elsif n &lt; epmn then
        return <a link="enum_PMUCounterRange_R2" file="shared_pseudocode.xml">PMUCounterRange_R2</a>;
    elsif n &lt; counters then
        assert IsFeatureImplemented(FEAT_PMUv3_EXTPMN);
        return <a link="enum_PMUCounterRange_R3" file="shared_pseudocode.xml">PMUCounterRange_R3</a>;
    elsif n == <a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a> then
        return <a link="enum_PMUCounterRange_R1" file="shared_pseudocode.xml">PMUCounterRange_R1</a>;
    elsif n == <a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a> then
        assert IsFeatureImplemented(FEAT_PMUv3_ICNTR);
        return <a link="enum_PMUCounterRange_R1" file="shared_pseudocode.xml">PMUCounterRange_R1</a>;
    else
        unreachable;
    end;
end;</pstext></ps>
    <ps name="shared/debug/pmu/GetPMUReadMask" mylink="shared.debug.pmu.GetPMUReadMask" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetPMUReadMask()
// ================
// Return a mask of the PMU counters that can be read at the current
// Exception level.
// This mask masks reads from PMCNTENSET_EL0, PMCNTENCLR_EL0, PMINTENSET_EL1,
// PMINTENCLR_EL1, PMOVSSET_EL0, and PMOVSCLR_EL0.

func <anchor link="func_GetPMUReadMask_0">GetPMUReadMask</anchor>() =&gt; bits(64)
begin
    var mask : bits(64) = <a link="func_GetPMUAccessMask_0" file="shared_pseudocode.xml">GetPMUAccessMask</a>();

    // Additional PMICNTR_EL0 accessibility checks. PMICNTR_EL0 controls read-as-zero
    // if a read of PMICFILTR_EL0 would be trapped to a higher Exception level.
    if IsFeatureImplemented(FEAT_PMUv3_ICNTR) &amp;&amp; mask[<a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a>] == '1' then
        // Check for trap to EL3.
        if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; MDCR_EL3().EnPM2 == '0' then
            mask[<a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a>] = '0';
        end;

        // Check for trap to EL2.
        if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; !<a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
            // If FEAT_PMUv3_ICNTR and EL2 are implemented, then so is FEAT_FGT2.
            assert IsFeatureImplemented(FEAT_FGT2);
            if ((<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().FGTEn2 == '0') ||
                  HDFGRTR2_EL2().nPMICFILTR_EL0 == '0') then
                mask[<a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a>] = '0';
            end;
        end;
    end;

    // Traps on other counters do not affect those counters' controls in the same way.

    return mask;
end;</pstext></ps>
    <ps name="shared/debug/pmu/GetPMUWriteMask" mylink="shared.debug.pmu.GetPMUWriteMask" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetPMUWriteMask()
// =================
// Return a mask of the PMU counters writable at the current Exception level.
// This mask masks writes to PMCNTENSET_EL0, PMCNTENCLR_EL0, PMINTENSET_EL1,
// PMINTENCLR_EL1, PMOVSSET_EL0, PMOVSCLR_EL0, and PMZR_EL0.
// 'write_counter' is TRUE for a write to PMZR_EL0, when the counter is being
// updated, and FALSE for other cases when the controls are being updated.

func <anchor link="func_GetPMUWriteMask_1">GetPMUWriteMask</anchor>(write_counter : boolean) =&gt; bits(64)
begin
    var mask : bits(64) = <a link="func_GetPMUAccessMask_0" file="shared_pseudocode.xml">GetPMUAccessMask</a>();

    // Check EL0 ignore write conditions
    if (IsFeatureImplemented(FEAT_PMUv3p9) &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) &amp;&amp;
          <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; PMUSERENR_EL0().UEN == '1') then
        if (IsFeatureImplemented(FEAT_PMUv3_ICNTR) &amp;&amp;
              PMUSERENR_EL0().IR == '1') then          // PMICNTR_EL0 read-only
            mask[<a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a>] = '0';
        end;
        if PMUSERENR_EL0().CR == '1' then              // PMCCNTR_EL0 read-only
            mask[<a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a>] = '0';
        end;
        if PMUSERENR_EL0().ER == '1' then              // PMEVCNTR[n]_EL0 read-only
            mask[30:0] = Zeros{31};
        end;
    end;

    // Additional PMICNTR_EL0 accessibility checks. PMICNTR_EL0 controls ignore writes
    // if a write of PMICFILTR_EL0 would be trapped to a higher Exception level.
    // Indirect writes to PMICNTR_EL0 (through PMZR_EL0) are ignored if a write of
    // PMICNTR_EL0 would be trapped to a higher Exception level.
    if IsFeatureImplemented(FEAT_PMUv3_ICNTR) &amp;&amp; mask[<a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a>] == '1' then
        // Check for trap to EL3.
        if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; MDCR_EL3().EnPM2 == '0' then
            mask[<a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a>] = '0';
        end;

        // Check for trap to EL2.
        if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; !<a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
            // If FEAT_PMUv3_ICNTR and EL2 are implemented, then so is FEAT_FGT2.
            assert IsFeatureImplemented(FEAT_FGT2);
            let fgt_bit : bit = (if write_counter then HDFGWTR2_EL2().nPMICNTR_EL0
                                 else HDFGWTR2_EL2().nPMICFILTR_EL0);
            if (<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().FGTEn2 == '0') || fgt_bit == '0' then
                mask[<a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a>] = '0';
            end;
        end;
    end;

    // Traps on other counters do not affect those counters' controls in the same way.

    return mask;
end;</pstext></ps>
    <ps name="shared/debug/pmu/HasElapsed64Cycles" mylink="shared.debug.pmu.HasElapsed64Cycles" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HasElapsed64Cycles()
// ====================
// Returns TRUE if 64 cycles have elapsed between the last count, and FALSE otherwise.

impdef func <anchor link="func_HasElapsed64Cycles_0">HasElapsed64Cycles</anchor>() =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="shared/debug/pmu/IncrementInstructionCounter" mylink="shared.debug.pmu.IncrementInstructionCounter" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IncrementInstructionCounter()
// =============================
// Increment the instruction counter and possibly set overflow bits.

func <anchor link="func_IncrementInstructionCounter_1">IncrementInstructionCounter</anchor>(increment : integer)
begin
    if <a link="func_CountPMUEvents_1" file="shared_pseudocode.xml">CountPMUEvents</a>(<a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a>) then
        let old_value : integer = UInt(PMICNTR_EL0());
        let new_value : integer = old_value + increment;
        PMICNTR_EL0()           = new_value[63:0];

        // The effective value of PMCR_EL0.LP is '1' for the instruction counter
        if old_value[64] != new_value[64] then
            PMOVSSET_EL0().F0 = '1';
        end;
    end;
    return;
end;</pstext></ps>
    <ps name="shared/debug/pmu/IsRange3Counter" mylink="shared.debug.pmu.IsRange3Counter" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsRange3Counter()
// =================
// Returns TRUE if the counter is in the third range.

func <anchor link="func_IsRange3Counter_1">IsRange3Counter</anchor>(n : integer) =&gt; boolean
begin
    return <a link="enum_PMUCounterRange_R3" file="shared_pseudocode.xml">PMUCounterRange_R3</a> == <a link="func_GetPMUCounterRange_1" file="shared_pseudocode.xml">GetPMUCounterRange</a>(n);
end;</pstext></ps>
    <ps name="shared/debug/pmu/PMUCaptureEvent" mylink="shared.debug.pmu.PMUCaptureEvent" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PMUCaptureEvent()
// =================
// If permitted and enabled, generate a PMU snapshot Capture event.

func <anchor link="func_PMUCaptureEvent_0">PMUCaptureEvent</anchor>()
begin
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; IsFeatureImplemented(FEAT_PMUv3_SS) &amp;&amp; <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>();
    let debug_state : boolean = <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>();

    if !<a link="func_PMUCaptureEventAllowed_0" file="shared_pseudocode.xml">PMUCaptureEventAllowed</a>() then
        // Indicate a Capture event completed, unsuccessfully
        PMSSCR_EL1().[NC,SS] = '10';
        return;
    end;
    let counters : integer = NUM_PMU_COUNTERS;
    for idx = 0 to counters - 1 do
        PMEVCNTSVR_EL1(idx) = PMEVCNTR_EL0(idx) as PMEVCNTSVR_EL1_Type;
    end;
    PMCCNTSVR_EL1() = PMCCNTR_EL0() as PMCCNTSVR_EL1_Type;

    if IsFeatureImplemented(FEAT_PMUv3_ICNTR) then
        PMICNTSVR_EL1() = PMICNTR_EL0() as PMICNTSVR_EL1_Type;
    end;

    if IsFeatureImplemented(FEAT_PCSRv8p9) &amp;&amp; PMPCSCTL().SS == '1' then
        if <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.valid &amp;&amp; !debug_state then
            <a link="func_SetPCSRActive_0" file="shared_pseudocode.xml">SetPCSRActive</a>();
            <a link="func_SetPCSample_0" file="shared_pseudocode.xml">SetPCSample</a>();
        else
            PMPCSR()[31:0] = Ones{32};
        end;
    end;

    if (IsFeatureImplemented(FEAT_BRBE) &amp;&amp; <a link="func_BranchRecordAllowed_1" file="shared_pseudocode.xml">BranchRecordAllowed</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) &amp;&amp;
          BRBCR_EL1().FZPSS == '1' &amp;&amp; (!<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) || BRBCR_EL2().FZPSS == '1')) then
        <a link="func_BRBEFreeze_0" file="shared_pseudocode.xml">BRBEFreeze</a>();
    end;

    // Indicate a successful Capture event
    PMSSCR_EL1().[NC,SS] = '00';
    if !debug_state || <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_PMUSNAPSHOTEVENT" file="shared_pseudocode.xml">Unpredictable_PMUSNAPSHOTEVENT</a>) then
        <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_PMU_SNAPSHOT);
    end;

    return;
end;</pstext></ps>
    <ps name="shared/debug/pmu/PMUCaptureEventAllowed" mylink="shared.debug.pmu.PMUCaptureEventAllowed" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PMUCaptureEventAllowed()
// ========================
// Returns TRUE if PMU Capture events are allowed, and FALSE otherwise.

func <anchor link="func_PMUCaptureEventAllowed_0">PMUCaptureEventAllowed</anchor>() =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_PMUv3_SS) || !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then
        return FALSE;
    end;

    if !<a link="func_PMUCaptureEventEnabled_0" file="shared_pseudocode.xml">PMUCaptureEventEnabled</a>() || <a link="func_OSLockStatus_0" file="shared_pseudocode.xml">OSLockStatus</a>() then
        return FALSE;
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; MDCR_EL3().PMSSE != '01' then
        return MDCR_EL3().PMSSE == '11';
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; MDCR_EL2().PMSSE != '01' then
        return MDCR_EL2().PMSSE == '11';
    else
        var pmsse_el1 : bits(2) = PMECR_EL1().SSE;
        if pmsse_el1 == '01' then            // Reserved value
            var c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>;
            (c, pmsse_el1) = ConstrainUnpredictableBits{2}(<a link="enum_Unpredictable_RESPMSSE" file="shared_pseudocode.xml">Unpredictable_RESPMSSE</a>);
            assert c IN {<a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>, <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>};
            if c == <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a> then pmsse_el1 = '00'; end;
            // Otherwise the value returned by ConstrainUnpredictableBits must be
            // a non-reserved value
        end;
        return pmsse_el1 == '11';
    end;
end;</pstext></ps>
    <ps name="shared/debug/pmu/PMUCaptureEventEnabled" mylink="shared.debug.pmu.PMUCaptureEventEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PMUCaptureEventEnabled()
// ========================
// Returns TRUE if PMU Capture events are enabled, and FALSE otherwise.

func <anchor link="func_PMUCaptureEventEnabled_0">PMUCaptureEventEnabled</anchor>() =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_PMUv3_SS) || !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then
        return FALSE;
    end;
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; MDCR_EL3().PMSSE != '01' then
        return MDCR_EL3().PMSSE == '1x';
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        return FALSE;
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; MDCR_EL2().PMSSE != '01' then
        return MDCR_EL2().PMSSE == '1x';
    elsif <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        return FALSE;
    else
        var pmsse_el1 : bits(2) = PMECR_EL1().SSE;
        if pmsse_el1 == '01' then            // Reserved value
            var c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>;
            (c, pmsse_el1) = ConstrainUnpredictableBits{2}(<a link="enum_Unpredictable_RESPMSSE" file="shared_pseudocode.xml">Unpredictable_RESPMSSE</a>);
            assert c IN {<a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>, <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>};
            if c == <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a> then pmsse_el1 = '00'; end;
        end;
            // Otherwise the value returned by ConstrainUnpredictableBits must be
            // a non-reserved value
        return pmsse_el1 == '1x';
    end;
end;</pstext></ps>
    <ps name="shared/debug/pmu/PMUCountValue" mylink="shared.debug.pmu.PMUCountValue" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PMUCountValue()
// ===============
// Implements the PMU threshold function, if implemented.
// Returns the value to increment event counter 'n' by.
// 'Vb' is the base value of the event that event counter 'n' is configured to count.
// 'Vm' is the value to increment event counter 'n-1' by if 'n' is odd, zero otherwise.

func <anchor link="func_PMUCountValue_3">PMUCountValue</anchor>(n : integer, Vb : integer, Vm : integer) =&gt; integer
begin
    assert (n MOD 2) == 1 || Vm == 0;
    assert n &lt; NUM_PMU_COUNTERS;

    if !IsFeatureImplemented(FEAT_PMUv3_TH) || !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then
        return Vb;
    end;

    let TH : integer = UInt(PMEVTYPER_EL0(n).TH);

    // Control register fields
    var tc : bits(3) = PMEVTYPER_EL0(n).TC;
    var te : bit = '0';
    if IsFeatureImplemented(FEAT_PMUv3_EDGE) then
        te = PMEVTYPER_EL0(n).TE;
    end;
    var tlc : bits(2) = '00';
    if IsFeatureImplemented(FEAT_PMUv3_TH2) &amp;&amp; (n MOD 2) == 1 then
        tlc = PMEVTYPER_EL0(n).TLC;
    end;

    // Check for reserved cases
    var c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>;
    (c, tc, te, tlc) = <a link="func_ReservedPMUThreshold_4" file="shared_pseudocode.xml">ReservedPMUThreshold</a>(n, tc, te, tlc);
    if c == <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a> then
        return Vb;
    end;
    // Otherwise the values returned by ReservedPMUThreshold must be defined values

    // Check if disabled. Note that this function will return the value of Vb when
    // the control register fields are all zero, even without this check.
    if tc == '000' &amp;&amp; TH == 0 &amp;&amp; te == '0' &amp;&amp; tlc == '00' then
        return Vb;
    end;

    // Threshold condition
    var Ct : boolean;
    case tc[2:1] of
        when '00' =&gt; Ct = (Vb != TH);        // Disabled or not-equal
        when '01' =&gt; Ct = (Vb == TH);        // Equals
        when '10' =&gt; Ct = (Vb &gt;= TH);        // Greater-than-or-equal
        when '11' =&gt; Ct = (Vb &lt;  TH);        // Less-than
    end;

    var Vn : integer;
    if te == '1' then
        // Edge condition
        let Cp : boolean = <a link="global_PMULastThresholdValue" file="shared_pseudocode.xml">PMULastThresholdValue</a>[[n]];
        var Ce : boolean;
        var Ve : integer;
        case tc[1:0] of
            when '10' =&gt;  Ce = (Cp != Ct);   // Both edges
            when 'x1' =&gt;  Ce = (!Cp &amp;&amp; Ct);  // Single edge
            otherwise =&gt;  unreachable;     // Covered by ReservedPMUThreshold
        end;
        case tlc of
            when '00' =&gt;  Ve = (if Ce then 1 else 0);
            when '10' =&gt;  Ve = (if Ce then Vm else 0);
            otherwise =&gt;  unreachable;     // Covered by ReservedPMUThreshold
        end;
        Vn = Ve;
    else
        // Threshold condition
        var Vt : integer;
        case tc[0]::tlc of
            when '0 00' =&gt;  Vt = (if Ct then Vb else 0);
            when '0 01' =&gt;  Vt = (if Ct then Vb else Vm);
            when '0 10' =&gt;  Vt = (if Ct then Vm else 0);
            when '1 00' =&gt;  Vt = (if Ct then 1 else 0);
            when '1 01' =&gt;  Vt = (if Ct then 1 else Vm);
            otherwise =&gt;    unreachable;   // Covered by ReservedPMUThreshold
        end;
        Vn = Vt;
    end;

    <a link="global_PMULastThresholdValue" file="shared_pseudocode.xml">PMULastThresholdValue</a>[[n]] = Ct;

    return Vn;
end;</pstext></ps>
    <ps name="shared/debug/pmu/PMUCounterRange" mylink="shared.debug.pmu.PMUCounterRange" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PMUCounterRange
// ===============
// Enumerates the ranges to which an event counter belongs to.

type <anchor link="type_PMUCounterRange">PMUCounterRange</anchor> of enumeration {
    <anchor link="enum_PMUCounterRange_R1">PMUCounterRange_R1</anchor>,
    <anchor link="enum_PMUCounterRange_R2">PMUCounterRange_R2</anchor>,
    <anchor link="enum_PMUCounterRange_R3">PMUCounterRange_R3</anchor>
    };</pstext></ps>
    <ps name="shared/debug/pmu/PMUEvent" mylink="shared.debug.pmu.PMUEvent" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PMUEvent()
// ==========
// Generate a PMU event. By default, increment by 1.
func <anchor link="func_PMUEvent_1">PMUEvent</anchor>(pmuevent : bits(16))
begin
    <a link="func_PMUEvent_2" file="shared_pseudocode.xml">PMUEvent</a>(pmuevent, 1);
end;

// PMUEvent()
// ==========
// Accumulate a PMU Event.

func <anchor link="func_PMUEvent_2">PMUEvent</anchor>(pmuevent : bits(16), increment : integer)
begin
    let counters : integer = NUM_PMU_COUNTERS;
    if counters != 0 then
        for idx = 0 to counters - 1 do
            <a link="func_PMUEvent_3" file="shared_pseudocode.xml">PMUEvent</a>(pmuevent, increment, idx);
        end;
    end;

    if (<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() &amp;&amp; IsFeatureImplemented(FEAT_PMUv3_ICNTR) &amp;&amp;
          pmuevent == PMU_EVENT_INST_RETIRED) then
        <a link="func_IncrementInstructionCounter_1" file="shared_pseudocode.xml">IncrementInstructionCounter</a>(increment);
    end;

end;

// PMUEvent()
// ==========
// Accumulate a PMU Event for a specific event counter.

func <anchor link="func_PMUEvent_3">PMUEvent</anchor>(pmuevent : bits(16), increment : integer, idx : integer)
begin
    if !IsFeatureImplemented(FEAT_PMUv3) then
        return;
    end;
    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        if PMEVTYPER(idx).evtCount == pmuevent then
            <a link="global_PMUEventAccumulator" file="shared_pseudocode.xml">PMUEventAccumulator</a>[[idx]] = <a link="global_PMUEventAccumulator" file="shared_pseudocode.xml">PMUEventAccumulator</a>[[idx]] + increment;
        end;
    else
        if PMEVTYPER_EL0(idx).evtCount == pmuevent then
            <a link="global_PMUEventAccumulator" file="shared_pseudocode.xml">PMUEventAccumulator</a>[[idx]] = <a link="global_PMUEventAccumulator" file="shared_pseudocode.xml">PMUEventAccumulator</a>[[idx]] + increment;
        end;
    end;
end;</pstext></ps>
    <ps name="shared/debug/pmu/PMUOverflowCondition" mylink="shared.debug.pmu.PMUOverflowCondition" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PMUOverflowCondition()
// ======================
// Enumerates the reasons for which the PMU overflow condition is evaluated.

type <anchor link="type_PMUOverflowCondition">PMUOverflowCondition</anchor> of enumeration {
    <anchor link="enum_PMUOverflowCondition_PMUException">PMUOverflowCondition_PMUException</anchor>,
    <anchor link="enum_PMUOverflowCondition_BRBEFreeze">PMUOverflowCondition_BRBEFreeze</anchor>,
    <anchor link="enum_PMUOverflowCondition_Freeze">PMUOverflowCondition_Freeze</anchor>,
    <anchor link="enum_PMUOverflowCondition_IRQ">PMUOverflowCondition_IRQ</anchor>,
    <anchor link="enum_PMUOverflowCondition_EDBGRQ">PMUOverflowCondition_EDBGRQ</anchor>
};</pstext></ps>
    <ps name="shared/debug/pmu/PMUSwIncrement" mylink="shared.debug.pmu.PMUSwIncrement" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PMUSwIncrement()
// ================
// Generate PMU Events on a write to PMSWINC

func <anchor link="func_PMUSwIncrement_1">PMUSwIncrement</anchor>(sw_incr_in : bits(64))
begin

    var sw_incr : bits(64)   = sw_incr_in;
    var mask : bits(31)      = Zeros{};
    let counters : integer{} = <a link="func_GetNumEventCountersAccessible_0" file="shared_pseudocode.xml">GetNumEventCountersAccessible</a>();
    if counters &gt; 0 then
        mask[counters-1:0] = Ones{counters};
    end;

    if (IsFeatureImplemented(FEAT_PMUv3p9) &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) &amp;&amp;
          <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; PMUSERENR_EL0().[UEN,SW] == '10') then
        mask = mask AND PMUACR_EL1()[30:0];
    end;

    sw_incr = sw_incr AND ZeroExtend{64}(mask);
    for idx = 0 to 30 do
        if sw_incr[idx] == '1' then
            <a link="func_PMUEvent_3" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SW_INCR, 1, idx);
        end;
    end;

    return;
end;</pstext></ps>
    <ps name="shared/debug/pmu/ReservedPMUThreshold" mylink="shared.debug.pmu.ReservedPMUThreshold" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ReservedPMUThreshold()
// ======================
// Checks if the given PMEVTYPER_EL1().[TH,TE,TLC] values are reserved and will
// generate Constrained Unpredictable behavior, otherwise return Constraint_NONE.

func <anchor link="func_ReservedPMUThreshold_4">ReservedPMUThreshold</anchor>(n : integer, tc_in : bits(3),
                          te_in : bit, tlc_in : bits(2)) =&gt; (<a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>, bits(3), bit, bits(2))
begin
    var tc : bits(3) = tc_in;
    var te : bit = te_in;
    var tlc : bits(2) = tlc_in;

    var reserved : boolean = FALSE;

    if IsFeatureImplemented(FEAT_PMUv3_EDGE) then
        if te == '1' &amp;&amp; tc[1:0] == '00' then      // Edge condition
            reserved = TRUE;
        end;
    else
        te = '0';                                 // Control is RES0
    end;

    if IsFeatureImplemented(FEAT_PMUv3_TH2) &amp;&amp; (n MOD 2) == 1 then
        if tlc == '11' then                       // Reserved value
            reserved = TRUE;
        end;
        if te == '1' then                         // Edge condition
            if tlc == '01' then
                reserved = TRUE;
            end;
        else                                      // Threshold condition
            if tc[0] == '1' &amp;&amp; tlc == '10' then
                reserved = TRUE;
            end;
        end;
    else
        tlc = '00';                               // Controls are RES0
    end;

    var c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>;
    if reserved then
        var unpred_reserved_bits : bits(6);
        (c, unpred_reserved_bits) = ConstrainUnpredictableBits{6}(<a link="enum_Unpredictable_RESTC" file="shared_pseudocode.xml">Unpredictable_RESTC</a>);
        tc  = unpred_reserved_bits[5:3];
        te  = unpred_reserved_bits[2];
        tlc = unpred_reserved_bits[1:0];
    end;

    return (c, tc, te, tlc);
end;</pstext></ps>
    <ps name="shared/debug/pmu/SMEPMUEventPredicate" mylink="shared.debug.pmu.SMEPMUEventPredicate" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SMEPMUEventPredicate()
// ======================
// Call the relevant PMU predication events based on the SME instruction properties.

func <anchor link="func_SMEPMUEventPredicate_4">SMEPMUEventPredicate</anchor>{N}(mask1 : bits(N), mask2 : bits(N), esize : integer)
begin
    <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SVE_PRED_SPEC);
    <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SME_PRED2_SPEC);
    if <a link="func_AllElementsActive_3" file="shared_pseudocode.xml">AllElementsActive</a>{N}(mask1, esize) &amp;&amp; <a link="func_AllElementsActive_3" file="shared_pseudocode.xml">AllElementsActive</a>{N}(mask2, esize) then
        <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SME_PRED2_FULL_SPEC);
    else
        <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SME_PRED2_NOT_FULL_SPEC);
        if !<a link="func_AnyActiveElement_3" file="shared_pseudocode.xml">AnyActiveElement</a>{N}(mask1, esize) &amp;&amp; !<a link="func_AnyActiveElement_3" file="shared_pseudocode.xml">AnyActiveElement</a>{N}(mask2, esize) then
            <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SME_PRED2_EMPTY_SPEC);
        else
            <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SME_PRED2_PARTIAL_SPEC);
        end;
    end;
end;</pstext></ps>
    <ps name="shared/debug/pmu/SVEPMUEventPredicate" mylink="shared.debug.pmu.SVEPMUEventPredicate" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SVEPMUEventPredicate()
// ======================
// Call the relevant PMU predication events based on the SVE instruction properties.

func <anchor link="func_SVEPMUEventPredicate_3">SVEPMUEventPredicate</anchor>{N}(mask : bits(N), esize : integer)
begin
    <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SVE_PRED_SPEC);
    if <a link="func_AllElementsActive_3" file="shared_pseudocode.xml">AllElementsActive</a>{N}(mask, esize) then
        <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SVE_PRED_FULL_SPEC);
    else
        <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SVE_PRED_NOT_FULL_SPEC);
        if !<a link="func_AnyActiveElement_3" file="shared_pseudocode.xml">AnyActiveElement</a>{N}(mask, esize) then
            <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SVE_PRED_EMPTY_SPEC);
        else
            <a link="func_PMUEvent_1" file="shared_pseudocode.xml">PMUEvent</a>(PMU_EVENT_SVE_PRED_PARTIAL_SPEC);
        end;
    end;
end;</pstext></ps>
    <ps name="shared/debug/pmu/ShouldPMUFreeze" mylink="shared.debug.pmu.ShouldPMUFreeze" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ShouldPMUFreeze()
// =================

func <anchor link="func_ShouldPMUFreeze_1">ShouldPMUFreeze</anchor>(r : <a link="type_PMUCounterRange" file="shared_pseudocode.xml">PMUCounterRange</a>) =&gt; boolean
begin
    let include_r1 : boolean = (r == <a link="enum_PMUCounterRange_R1" file="shared_pseudocode.xml">PMUCounterRange_R1</a>);
    let include_r2 : boolean = (r == <a link="enum_PMUCounterRange_R2" file="shared_pseudocode.xml">PMUCounterRange_R2</a>);
    let include_r3 : boolean = FALSE;

    if r == <a link="enum_PMUCounterRange_R3" file="shared_pseudocode.xml">PMUCounterRange_R3</a> then
        return FALSE;
    end;

    let overflow : boolean = <a link="func_CheckPMUOverflowCondition_4" file="shared_pseudocode.xml">CheckPMUOverflowCondition</a>(<a link="enum_PMUOverflowCondition_Freeze" file="shared_pseudocode.xml">PMUOverflowCondition_Freeze</a>,
                                                       include_r1, include_r2, include_r3);
    return overflow;
end;</pstext></ps>
    <ps name="shared/debug/pmu/ZeroCycleCounter" mylink="shared.debug.pmu.ZeroCycleCounter" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ZeroCycleCounter()
// ==================
// Called on a write to PMCR_EL0 or PMCR that writes '1' to PMCR_EL0.C or PMCR.C.

func <anchor link="func_ZeroCycleCounter_0">ZeroCycleCounter</anchor>()
begin
    var mask : bits(64) = Zeros{};
    mask[<a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a>] = '1';
    <a link="func_ZeroPMUCounters_1" file="shared_pseudocode.xml">ZeroPMUCounters</a>(mask);
end;</pstext></ps>
    <ps name="shared/debug/pmu/ZeroPMUCounters" mylink="shared.debug.pmu.ZeroPMUCounters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ZeroPMUCounters()
// =================
// Zero set of counters specified by the mask in 'val'.
// For a System register write to PMZR_EL0, 'val' is the value passed in X&lt;t&gt;.

func <anchor link="func_ZeroPMUCounters_1">ZeroPMUCounters</anchor>(val : bits(64))
begin
    let masked_val : bits(64) = val AND <a link="func_GetPMUWriteMask_1" file="shared_pseudocode.xml">GetPMUWriteMask</a>(TRUE);

    for idx = 0 to 63 do
        if masked_val[idx] == '1' &amp;&amp; !<a link="func_IsRange3Counter_1" file="shared_pseudocode.xml">IsRange3Counter</a>(idx) then
            case idx of
                when <a link="global_INSTRUCTION_COUNTER_ID" file="shared_pseudocode.xml">INSTRUCTION_COUNTER_ID</a> =&gt;
                    PMICNTR_EL0() = Zeros{64};
                when <a link="global_CYCLE_COUNTER_ID" file="shared_pseudocode.xml">CYCLE_COUNTER_ID</a> =&gt;
                    if !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then
                        PMCCNTR() = Zeros{64};
                    else
                        PMCCNTR_EL0() = Zeros{64};
                    end;
                otherwise =&gt;
                    if !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then
                        PMEVCNTR(idx) = Zeros{32};
                    elsif IsFeatureImplemented(FEAT_PMUv3p5) then
                        PMEVCNTR_EL0(idx) = Zeros{64};
                    else
                        PMEVCNTR_EL0(idx)[31:0] = Zeros{32};
                    end;
            end;
        end;
    end;

    return;
end;</pstext></ps>
    <ps name="shared/debug/samplebasedprofiling/CreatePCSample" mylink="shared.debug.samplebasedprofiling.CreatePCSample" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreatePCSample()
// ================

func <anchor link="func_CreatePCSample_0">CreatePCSample</anchor>()
begin
    // In a simple sequential execution of the program, CreatePCSample is executed each time the PE
    // executes an instruction that can be sampled. An implementation is not constrained such that
    // reads of EDPCSRlo return the current values of PC, etc.
    if <a link="func_PCSRSuspended_0" file="shared_pseudocode.xml">PCSRSuspended</a>() then return; end;
    <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.valid = <a link="func_ExternalNoninvasiveDebugAllowed_0" file="shared_pseudocode.xml">ExternalNoninvasiveDebugAllowed</a>() &amp;&amp; !<a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>();
    <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.pc = <a link="func_ThisInstrAddr_1" file="shared_pseudocode.xml">ThisInstrAddr</a>{64}();
    <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.el = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
    <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.rw = if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then '0' else '1';
    <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.ss = <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>();
    <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.contextidr = if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then CONTEXTIDR() else CONTEXTIDR_EL1()[31:0];
    <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.has_el2 = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>();

    if <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.has_el2 then
        <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.vmid = <a link="func_VMID_0" file="shared_pseudocode.xml">VMID</a>();
        if ((IsFeatureImplemented(FEAT_VHE) || IsFeatureImplemented(FEAT_Debugv8p2)) &amp;&amp;
              !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>)) then
            <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.contextidr_el2 = CONTEXTIDR_EL2()[31:0];
        else
            <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.contextidr_el2 = ARBITRARY : bits(32);
        end;
        <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.el0h = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>();
    end;
    return;
end;</pstext></ps>
    <ps name="shared/debug/samplebasedprofiling/PCSRSuspended" mylink="shared.debug.samplebasedprofiling.PCSRSuspended" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PCSRSuspended()
// ===============
// Returns TRUE if PC Sample-based Profiling is suspended, and FALSE otherwise.

func <anchor link="func_PCSRSuspended_0">PCSRSuspended</anchor>() =&gt; boolean
begin
    if IsFeatureImplemented(FEAT_PMUv3_SS) &amp;&amp; PMPCSCTL().SS == '1' then
        return FALSE;
    end;
    if IsFeatureImplemented(FEAT_PCSRv8p9) &amp;&amp; PMPCSCTL().IMP == '1' then
        return PMPCSCTL().EN == '0';
    end;
    return ImpDefBool(&quot;PCSR is suspended&quot;);
end;</pstext></ps>
    <ps name="shared/debug/samplebasedprofiling/PCSample" mylink="shared.debug.samplebasedprofiling.PCSample" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PCSample
// ========

type <anchor link="type_PCSample">PCSample</anchor> of record {
    valid : boolean,
    pc : bits(64),
    el : bits(2),
    rw : bit,
    ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>,
    has_el2 : boolean,
    contextidr : bits(32),
    contextidr_el2 : bits(32),
    el0h : boolean,
    vmid : bits(NUM_VMIDBITS)
};


var <anchor link="global_pc_sample">pc_sample</anchor> : <a link="type_PCSample" file="shared_pseudocode.xml">PCSample</a>;</pstext></ps>
    <ps name="shared/debug/samplebasedprofiling/Read_EDPCSRlo" mylink="shared.debug.samplebasedprofiling.Read_EDPCSRlo" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Read_EDPCSRlo()
// ===============

func <anchor link="func_Read_EDPCSRlo_1">Read_EDPCSRlo</anchor>(memory_mapped : boolean) =&gt; bits(32)
begin
    // The Software lock is OPTIONAL.
    let update : boolean = !memory_mapped || EDLSR().SLK == '0';// Software locked: no side-effects
    var sample : bits(32);
    if <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.valid then
        sample = <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.pc[31:0];
        if update then
            if IsFeatureImplemented(FEAT_VHE) &amp;&amp; EDSCR().SC2 == '1' then
                EDPCSRhi.PC = (if <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.rw == '0' then Zeros{24} else <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.pc[55:32]);
                EDPCSRhi.EL = <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.el;
                EDPCSRhi.NS = (if <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then '0' else '1');
            else
                EDPCSRhi = (if <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.rw == '0' then Zeros{32} else <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.pc[63:32]);
            end;
            EDCIDSR() = <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.contextidr;
            if ((IsFeatureImplemented(FEAT_VHE) || IsFeatureImplemented(FEAT_Debugv8p2)) &amp;&amp;
                  EDSCR().SC2 == '1') then
                EDVIDSR() = (if <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.has_el2 then <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.contextidr_el2
                             else ARBITRARY : bits(32));
            else
                EDVIDSR().VMID = (if <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.has_el2 &amp;&amp; <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.el IN {<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>,<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>}
                                  then <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.vmid else Zeros{NUM_VMIDBITS});
                EDVIDSR().NS = (if <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then '0' else '1');
                EDVIDSR().E2 = (if <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then '1' else '0');
                EDVIDSR().E3 = (if <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then '1' else '0') AND <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.rw;
                // The conditions for setting HV are not specified if PCSRhi is zero.
                // An example implementation may be &quot;pc_sample.rw&quot;.
                EDVIDSR().HV = (if !IsZero(EDPCSRhi) then '1'
                                else ImpDefBit(&quot;0 or 1&quot;));
            end;
        end;
    else
        sample = Ones{32};
        if update then
            EDPCSRhi  = ARBITRARY : bits(32);
            EDCIDSR() = ARBITRARY : bits(32);
            EDVIDSR() = ARBITRARY : bits(32);
        end;
    end;

    return sample;
end;</pstext></ps>
    <ps name="shared/debug/samplebasedprofiling/Read_PMPCSR" mylink="shared.debug.samplebasedprofiling.Read_PMPCSR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Read_PMPCSR()
// =============

func <anchor link="func_Read_PMPCSR_1">Read_PMPCSR</anchor>(memory_mapped : boolean) =&gt; bits(64)
begin
    // The Software lock is OPTIONAL.
    var update : boolean = !memory_mapped || PMLSR().SLK == '0'; // Software locked: no side-effects

    if IsFeatureImplemented(FEAT_PCSRv8p9) &amp;&amp; update then
        if IsFeatureImplemented(FEAT_PMUv3_SS) &amp;&amp; PMPCSCTL().SS == '1' then
            update = FALSE;
        elsif PMPCSCTL().[IMP,EN] == '10' || (PMPCSCTL().IMP == '0' &amp;&amp; <a link="func_PCSRSuspended_0" file="shared_pseudocode.xml">PCSRSuspended</a>()) then
            <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.valid = FALSE;
            <a link="func_SetPCSRActive_0" file="shared_pseudocode.xml">SetPCSRActive</a>();
        end;
    end;

    if <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.valid then
        if update then <a link="func_SetPCSample_0" file="shared_pseudocode.xml">SetPCSample</a>(); end;
        return PMPCSR();
    else
        if update then <a link="func_SetPCSRUnknown_0" file="shared_pseudocode.xml">SetPCSRUnknown</a>(); end;
        return (ARBITRARY : bits(32) :: Ones{32});
    end;
end;</pstext></ps>
    <ps name="shared/debug/samplebasedprofiling/SetPCSRActive" mylink="shared.debug.samplebasedprofiling.SetPCSRActive" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SetPCSRActive()
// ===============
// Sets PC Sample-based Profiling to active state.

func <anchor link="func_SetPCSRActive_0">SetPCSRActive</anchor>()
begin
    if PMPCSCTL().IMP == '1' then
        PMPCSCTL().EN = '1';
    // If PMPCSCTL.IMP reads as `0b0`, then PMPCSCTL.EN is RES0, and it is
    // IMPLEMENTATION DEFINED whether PSCR is suspended or active at reset.
    end;
end;</pstext></ps>
    <ps name="shared/debug/samplebasedprofiling/SetPCSRUnknown" mylink="shared.debug.samplebasedprofiling.SetPCSRUnknown" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SetPCSRUnknown()
// ================
// Sets the PC sample registers to UNKNOWN values because PC sampling
// is prohibited.

func <anchor link="func_SetPCSRUnknown_0">SetPCSRUnknown</anchor>()
begin
    PMPCSR()[31:0]  = Ones{32};
    PMPCSR()[55:32] = ARBITRARY : bits(24);
    PMPCSR().EL     = ARBITRARY : bits(2);
    PMPCSR().NS     = ARBITRARY : bit;

    if IsFeatureImplemented(FEAT_PMUv3_EXT64) then
        PMCCIDSR()      = ARBITRARY : bits(64);
        PMVCIDSR().VMID = ARBITRARY : bits(NUM_VMIDBITS);
    end;
    if IsFeatureImplemented(FEAT_PMUv3_EXT32) then
        PMCID1SR()      = ARBITRARY : bits(32);
        PMCID2SR()      = ARBITRARY : bits(32);
        PMVIDSR().VMID  = ARBITRARY : bits(NUM_VMIDBITS);
    end;

    return;
end;</pstext></ps>
    <ps name="shared/debug/samplebasedprofiling/SetPCSample" mylink="shared.debug.samplebasedprofiling.SetPCSample" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SetPCSample()
// =============
// Sets the PC sample registers to the appropriate sample values.

func <anchor link="func_SetPCSample_0">SetPCSample</anchor>()
begin
    PMPCSR()[31:0] = <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.pc[31:0];
    PMPCSR()[55:32] = (if <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.rw == '0' then Zeros{24} else <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.pc[55:32]);
    PMPCSR().EL = <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.el;
    if IsFeatureImplemented(FEAT_RME) then
        case <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.ss of
            when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;
                PMPCSR().NSE = '0'; PMPCSR().NS = '0';
            when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt;
                PMPCSR().NSE = '0'; PMPCSR().NS = '1';
            when <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a> =&gt;
                PMPCSR().NSE = '1'; PMPCSR().NS = '0';
            when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;
                PMPCSR().NSE = '1'; PMPCSR().NS = '1';
        end;
    else
        PMPCSR().NS = (if <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then '0' else '1');
    end;
    let contextidr_el2 : bits(32) = (if <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.has_el2 then
                                        <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.contextidr_el2 else ARBITRARY : bits(32));
    var vmid : bits(NUM_VMIDBITS) = ARBITRARY : bits(NUM_VMIDBITS);
    if <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.has_el2 &amp;&amp; <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.el IN {<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>,<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>} &amp;&amp; !<a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.el0h then
        vmid = <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.vmid;
    end;
    if IsFeatureImplemented(FEAT_PMUv3_EXT64) then
        PMCCIDSR() = contextidr_el2::<a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.contextidr;
        PMVCIDSR().VMID = vmid;
    end;
    if IsFeatureImplemented(FEAT_PMUv3_EXT32) then
        PMCID1SR() = <a link="global_pc_sample" file="shared_pseudocode.xml">pc_sample</a>.contextidr;
        PMCID2SR() = contextidr_el2;
        PMVIDSR().VMID = vmid;
    end;

    return;
end;</pstext></ps>
    <ps name="shared/debug/softwarestep/CheckSoftwareStep" mylink="shared.debug.softwarestep.CheckSoftwareStep" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckSoftwareStep()
// ===================
// Take a Software Step exception if in the active-pending state

func <anchor link="func_CheckSoftwareStep_0">CheckSoftwareStep</anchor>()
begin

    // Other self-hosted debug functions will call AArch32_GenerateDebugExceptions() if called from
    // AArch32 state. However, because Software Step is only active when the debug target Exception
    // level is using AArch64, CheckSoftwareStep only calls AArch64_GenerateDebugExceptions().
    let step_enabled : boolean = (!<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="func_DebugTarget_0" file="shared_pseudocode.xml">DebugTarget</a>()) &amp;&amp;
                                  <a link="func_AArch64_GenerateDebugExceptions_0" file="shared_pseudocode.xml">AArch64_GenerateDebugExceptions</a>() &amp;&amp;
                                  MDSCR_EL1().SS == '1');
    let active_pending : boolean = step_enabled &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SS == '0';   // active-pending
    if active_pending then
        <a link="func_AArch64_SoftwareStepException_0" file="shared_pseudocode.xml">AArch64_SoftwareStepException</a>();
    end;
    <a link="global_ShouldAdvanceSS" file="shared_pseudocode.xml">ShouldAdvanceSS</a> = TRUE;
    return;
end;</pstext></ps>
    <ps name="shared/debug/softwarestep/DebugExceptionReturnSS" mylink="shared.debug.softwarestep.DebugExceptionReturnSS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DebugExceptionReturnSS()
// ========================
// Returns value to write to PSTATE.SS on an exception return or Debug state exit.

func <anchor link="func_DebugExceptionReturnSS_2">DebugExceptionReturnSS</anchor>{N}(spsr : bits(N)) =&gt; bit
begin
    assert <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() || <a link="func_Restarting_0" file="shared_pseudocode.xml">Restarting</a>() ||  <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;

    var enabled_at_source : boolean;
    if <a link="func_Restarting_0" file="shared_pseudocode.xml">Restarting</a>() then
        enabled_at_source = FALSE;
    elsif <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        enabled_at_source = <a link="func_AArch32_GenerateDebugExceptions_0" file="shared_pseudocode.xml">AArch32_GenerateDebugExceptions</a>();
    else
        enabled_at_source = <a link="func_AArch64_GenerateDebugExceptions_0" file="shared_pseudocode.xml">AArch64_GenerateDebugExceptions</a>();
    end;
    var valid : boolean;
    var dest_el : bits(2);
    if <a link="func_IllegalExceptionReturn_2" file="shared_pseudocode.xml">IllegalExceptionReturn</a>{N}(spsr) then
        dest_el = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
    else
        (valid, dest_el) = <a link="func_ELFromSPSR_2" file="shared_pseudocode.xml">ELFromSPSR</a>{N}(spsr);  assert valid;
    end;

    let dest_ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(dest_el);
    var enabled_at_dest : boolean;
    let dest_using_32 : boolean = (if dest_el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then spsr[4] == '1'
                                                     else <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(dest_el));
    if dest_using_32 then
        enabled_at_dest = <a link="func_AArch32_GenerateDebugExceptionsFrom_2" file="shared_pseudocode.xml">AArch32_GenerateDebugExceptionsFrom</a>(dest_el, dest_ss);
    else
        let mask : bit = spsr[9];
        enabled_at_dest = <a link="func_AArch64_GenerateDebugExceptionsFrom_3" file="shared_pseudocode.xml">AArch64_GenerateDebugExceptionsFrom</a>(dest_el, dest_ss, mask);
    end;

    let ELd : bits(2) = <a link="func_DebugTargetFrom_1" file="shared_pseudocode.xml">DebugTargetFrom</a>(dest_ss);
    var SS_bit : bit;
    if !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(ELd) &amp;&amp; MDSCR_EL1().SS == '1' &amp;&amp; !enabled_at_source &amp;&amp; enabled_at_dest then
        SS_bit = spsr[21];
    else
        SS_bit = '0';
    end;
    return SS_bit;
end;</pstext></ps>
    <ps name="shared/debug/softwarestep/SSAdvance" mylink="shared.debug.softwarestep.SSAdvance" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SSAdvance()
// ===========
// Advance the Software Step state machine.

func <anchor link="func_SSAdvance_0">SSAdvance</anchor>()
begin

    // A simpler implementation of this function just clears PSTATE.SS to zero regardless of the
    // current Software Step state machine. However, this check is made to illustrate that the
    // PE only needs to consider advancing the state machine from the active-not-pending
    // state.
    if !<a link="global_ShouldAdvanceSS" file="shared_pseudocode.xml">ShouldAdvanceSS</a> then return; end;
    let target : bits(2) = <a link="func_DebugTarget_0" file="shared_pseudocode.xml">DebugTarget</a>();
    let step_enabled : boolean = !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(target) &amp;&amp; MDSCR_EL1().SS == '1';
    let active_not_pending : boolean = step_enabled &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SS == '1';
    if active_not_pending then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SS = '0'; end;
    <a link="global_ShouldAdvanceSS" file="shared_pseudocode.xml">ShouldAdvanceSS</a> = FALSE;
    return;
end;</pstext></ps>
    <ps name="shared/debug/softwarestep/SoftwareStepOpEnabled" mylink="shared.debug.softwarestep.SoftwareStepOpEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SoftwareStepOpEnabled()
// =======================
// Returns a boolean indicating if execution from MDSTEPOP_EL1 is enabled.

func <anchor link="func_SoftwareStepOpEnabled_0">SoftwareStepOpEnabled</anchor>() =&gt; boolean
begin

    if !IsFeatureImplemented(FEAT_STEP2) || <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        return FALSE;
    end;

    let step_enabled = <a link="func_AArch64_GenerateDebugExceptions_0" file="shared_pseudocode.xml">AArch64_GenerateDebugExceptions</a>() &amp;&amp; MDSCR_EL1().SS == '1';
    let active_not_pending = step_enabled &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SS == '1';
    let stepop = (MDSCR_EL1().EnSTEPOP == '1' &amp;&amp;
                  (!<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || MDCR_EL3().EnSTEPOP == '1') &amp;&amp;
                  (!<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() || MDCR_EL2().EnSTEPOP == '1'));
    return active_not_pending &amp;&amp; stepop;
end;</pstext></ps>
    <ps name="shared/debug/softwarestep/SoftwareStep_DidNotStep" mylink="shared.debug.softwarestep.SoftwareStep_DidNotStep" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SoftwareStep_DidNotStep()
// =========================
// Returns TRUE if the previously executed instruction was executed in the
// inactive state, that is, if it was not itself stepped.
// Might return TRUE or FALSE if the previously executed instruction was an ISB
// or ERET executed in the active-not-pending state, or if another exception
// was taken before the Software Step exception.  Returns FALSE otherwise,
// indicating that the previously executed instruction was executed in the
// active-not-pending state, that is, the instruction was stepped.

func <anchor link="func_SoftwareStep_DidNotStep_0">SoftwareStep_DidNotStep</anchor>() =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="shared/debug/softwarestep/SoftwareStep_SteppedEX" mylink="shared.debug.softwarestep.SoftwareStep_SteppedEX" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SoftwareStep_SteppedEX()
// ========================
// Returns a value that describes the previously executed instruction. The
// result is valid only if SoftwareStep_DidNotStep() returns FALSE.
// Might return TRUE or FALSE if the instruction was an AArch32 LDREX or LDAEX
// that failed its condition code test.  Otherwise returns TRUE if the
// instruction was a Load-Exclusive class instruction, and FALSE if the
// instruction was not a Load-Exclusive class instruction.

func <anchor link="func_SoftwareStep_SteppedEX_0">SoftwareStep_SteppedEX</anchor>() =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="shared/debug/watchpoint/DataCacheWatchpointSize" mylink="shared.debug.watchpoint.DataCacheWatchpointSize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DataCacheWatchpointSize()
// =========================
// Return the IMPLEMENTATION DEFINED data cache watchpoint size
func <anchor link="func_DataCacheWatchpointSize_0">DataCacheWatchpointSize</anchor>() =&gt; integer
begin
    let size : integer = ImpDefInt(&quot;Data Cache Invalidate Watchpoint Size&quot;);
    assert IsPow2(size) &amp;&amp; size &gt;= 2^(UInt(CTR_EL0().DminLine) + 2) &amp;&amp; size &lt;= 2048;
    return size;
end;</pstext></ps>
    <ps name="shared/debug/watchpoint/WatchpointInfo" mylink="shared.debug.watchpoint.WatchpointInfo" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// WatchpointInfo
// ==============
// Watchpoint related fields.

type <anchor link="type_WatchpointInfo">WatchpointInfo</anchor> of record {
    wptype : <a link="type_WatchpointType" file="shared_pseudocode.xml">WatchpointType</a>,     // Type of watchpoint matched
    maybe_false_match : boolean, // Watchpoint matches rounded range
    watchpt_num : integer,       // Matching watchpoint number
    value_match : boolean,       // Watchpoint match
    vaddress : bits(64)          // Matching Virtual Address
};</pstext></ps>
    <ps name="shared/debug/watchpoint/WatchpointType" mylink="shared.debug.watchpoint.WatchpointType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// WatchpointType
// ==============

type <anchor link="type_WatchpointType">WatchpointType</anchor> of enumeration {
    <anchor link="enum_WatchpointType_Inactive">WatchpointType_Inactive</anchor>,      // Watchpoint inactive or disabled
    <anchor link="enum_WatchpointType_AddrMatch">WatchpointType_AddrMatch</anchor>,     // Address Match watchpoint
    <anchor link="enum_WatchpointType_AddrMismatch">WatchpointType_AddrMismatch</anchor>   // Address Mismatch watchpoint
};</pstext></ps>
    <ps name="shared/exceptions/aborts/EffectiveHCRX_EL2_TMEA" mylink="shared.exceptions.aborts.EffectiveHCRX_EL2_TMEA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveHCRX_EL2_TMEA()
// ========================
// Return the Effective value of HCRX_EL2.TMEA.

func <anchor link="func_EffectiveHCRX_EL2_TMEA_0">EffectiveHCRX_EL2_TMEA</anchor>() =&gt; bit
begin
    if (IsFeatureImplemented(FEAT_DoubleFault2) &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
          !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; <a link="func_IsHCRXEL2Enabled_0" file="shared_pseudocode.xml">IsHCRXEL2Enabled</a>()) then
        return HCRX_EL2().TMEA;
    else
        return '0';
    end;
end;</pstext></ps>
    <ps name="shared/exceptions/aborts/EffectiveHCR_AMO" mylink="shared.exceptions.aborts.EffectiveHCR_AMO" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveHCR_AMO()
// ==================
// Return the Effective value of HCR_EL2.AMO.

func <anchor link="func_EffectiveHCR_AMO_0">EffectiveHCR_AMO</anchor>() =&gt; bit
begin
    if <a link="func_EffectiveTGE_0" file="shared_pseudocode.xml">EffectiveTGE</a>() == '1' then
        return (if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) || <a link="func_EffectiveHCR_EL2_E2H_0" file="shared_pseudocode.xml">EffectiveHCR_EL2_E2H</a>() == '0' then '1' else '0');
    elsif <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        return (if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then HCR().AMO else HCR_EL2().AMO);
    else
        return '0';
    end;
end;</pstext></ps>
    <ps name="shared/exceptions/aborts/EffectiveHCR_TEA" mylink="shared.exceptions.aborts.EffectiveHCR_TEA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveHCR_TEA()
// ==================
// Return the Effective value of HCR_EL2.TEA.

func <anchor link="func_EffectiveHCR_TEA_0">EffectiveHCR_TEA</anchor>() =&gt; bit
begin
    if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; IsFeatureImplemented(FEAT_RAS) then
        return (if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then HCR2().TEA else HCR_EL2().TEA);
    else
        return '0';
    end;
end;</pstext></ps>
    <ps name="shared/exceptions/aborts/EffectiveNMEA" mylink="shared.exceptions.aborts.EffectiveNMEA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveNMEA()
// ===============
// Return the Effective value of SCR_EL3.NMEA or SCTLR2_ELx.NMEA.

func <anchor link="func_EffectiveNMEA_0">EffectiveNMEA</anchor>() =&gt; bit
begin
    if IsFeatureImplemented(FEAT_DoubleFault2) then
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
            return SCR_EL3().NMEA;
        elsif (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || <a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>()) &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
            return (if <a link="func_IsSCTLR2EL2Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL2Enabled</a>() then SCTLR2_EL2().NMEA else '0');
        elsif !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
            return (if <a link="func_IsSCTLR2EL1Enabled_0" file="shared_pseudocode.xml">IsSCTLR2EL1Enabled</a>() then SCTLR2_EL1().NMEA else '0');
        else
            return '0';
        end;
    elsif IsFeatureImplemented(FEAT_DoubleFault) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        return SCR_EL3().NMEA AND <a link="func_EffectiveEA_0" file="shared_pseudocode.xml">EffectiveEA</a>();
    else
        return '0';
    end;
end;</pstext></ps>
    <ps name="shared/exceptions/aborts/EffectiveSCR_EL3_TMEA" mylink="shared.exceptions.aborts.EffectiveSCR_EL3_TMEA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveSCR_EL3_TMEA()
// =======================
// Return the Effective value of SCR_EL3.TMEA.

func <anchor link="func_EffectiveSCR_EL3_TMEA_0">EffectiveSCR_EL3_TMEA</anchor>() =&gt; bit
begin
    if (IsFeatureImplemented(FEAT_DoubleFault2) &amp;&amp; <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp;
          !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>)) then
        return SCR_EL3().TMEA;
    else
        return '0';
    end;
end;</pstext></ps>
    <ps name="shared/exceptions/aborts/PhysicalSErrorTarget" mylink="shared.exceptions.aborts.PhysicalSErrorTarget" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PhysicalSErrorTarget()
// ======================
// Returns a tuple of whether SError exception can be taken and, if so, the
// target Exception level.
// If EL3 is implemented and using AArch32, then a target Exception level of
// EL1 means Abort mode, and EL3 means Monitor mode, including in Secure
// state when Abort mode is part of EL3.

func <anchor link="func_PhysicalSErrorTarget_0">PhysicalSErrorTarget</anchor>() =&gt; (boolean, bits(2))
begin
    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then
        return (TRUE, ARBITRARY : bits(2));
    end;

    let effective_ea : bit = <a link="func_EffectiveEA_0" file="shared_pseudocode.xml">EffectiveEA</a>();
    let effective_amo : bit = <a link="func_EffectiveHCR_AMO_0" file="shared_pseudocode.xml">EffectiveHCR_AMO</a>();
    let effective_tge : bit = <a link="func_EffectiveTGE_0" file="shared_pseudocode.xml">EffectiveTGE</a>();
    let effective_nmea : bit = <a link="func_EffectiveNMEA_0" file="shared_pseudocode.xml">EffectiveNMEA</a>();

    // When EL3 is implemented and using AArch32, the SCR.AW bit can allow PSTATE.A
    // to mask SError exceptions in Non-secure state when SCR.EA is 1 and the Effective
    // value of HCR.AMO is 0.
    var effective_aw : bit;
    if (<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; effective_ea == '1' &amp;&amp;
          <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() == <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> &amp;&amp; effective_amo == '0') then
        effective_aw = SCR().AW;
    else
        effective_aw = '0';
    end;

    // The exception is masked by software.
    var masked : boolean;
    case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL of
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            masked = (!<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; effective_ea == '0') || <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.A == '1';
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            masked = ((effective_ea == '0' || effective_aw == '1') &amp;&amp;
                      ((!<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; effective_tge == '0' &amp;&amp; effective_amo == '0') ||
                       <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.A == '1'));
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            masked = ((effective_ea == '0' || effective_aw == '1') &amp;&amp;
                      effective_amo == '0' &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.A == '1');
    end;

    // When FEAT_DoubleFault or FEAT_DoubleFault2 is implemented, the mask might be overridden.
    masked = (masked &amp;&amp; effective_nmea == '0');

    // External debug might disable the exception in the current Security state.
    // This is not relevant at EL3.
    let intdis : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; <a link="func_ExternalDebugInterruptsDisabled_1" file="shared_pseudocode.xml">ExternalDebugInterruptsDisabled</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>);

    var target_el : bits(2) = ARBITRARY : bits(2);
    if effective_ea == '1' || (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>)) then
        if !masked then target_el = <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>; end;

    elsif <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; effective_amo == '1' &amp;&amp; !intdis &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} then
        target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
        masked = FALSE;

    elsif (<a link="func_EffectiveHCRX_EL2_TMEA_0" file="shared_pseudocode.xml">EffectiveHCRX_EL2_TMEA</a>() == '1' &amp;&amp; !intdis &amp;&amp;
             ((<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.A == '1') ||
              (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; masked &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>()))) then
        target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
        masked = FALSE;

    elsif (<a link="func_EffectiveSCR_EL3_TMEA_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_TMEA</a>() == '1' &amp;&amp;
             ((<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.A == '1') ||
             (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>} &amp;&amp; masked) || intdis)) then
        target_el = <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
        masked = FALSE;

    elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || <a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>() then
        if !masked then target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>; end;

    else
        assert (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> ||
                  (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>)) ||
                  (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>()));
        if !masked then target_el = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>; end;
    end;

    // External debug might disable the exception for the target Exception level.
    if !masked &amp;&amp; <a link="func_ExternalDebugInterruptsDisabled_1" file="shared_pseudocode.xml">ExternalDebugInterruptsDisabled</a>(target_el) then
        masked = TRUE;
        target_el = ARBITRARY : bits(2);
    end;

    return (masked, target_el);
end;</pstext></ps>
    <ps name="shared/exceptions/aborts/SyncExternalAbortTarget" mylink="shared.exceptions.aborts.SyncExternalAbortTarget" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SyncExternalAbortTarget()
// =========================
// Returns the target Exception level for a Synchronous External Data or
// Instruction or Prefetch Abort.
// If EL3 is implemented and using AArch32, then a target Exception level of
// EL1 means Abort mode, and EL3 means Monitor mode, including in Secure
// state when Abort mode is part of EL3.

func <anchor link="func_SyncExternalAbortTarget_1">SyncExternalAbortTarget</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; bits(2)
begin
    let effective_ea : bit = <a link="func_EffectiveEA_0" file="shared_pseudocode.xml">EffectiveEA</a>();
    let effective_tea : bit = <a link="func_EffectiveHCR_TEA_0" file="shared_pseudocode.xml">EffectiveHCR_TEA</a>();
    let effective_tge : bit = <a link="func_EffectiveTGE_0" file="shared_pseudocode.xml">EffectiveTGE</a>();

    var target_el : bits(2);
    if effective_ea == '1' || (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>)) then
        target_el = <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;

    elsif (<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>} &amp;&amp;
           (effective_tea == '1' || <a link="func_IsSecondStage_1" file="shared_pseudocode.xml">IsSecondStage</a>(fault) ||
            fault.accessdesc.acctype == <a link="enum_AccessType_NV2" file="shared_pseudocode.xml">AccessType_NV2</a> ||
            (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; effective_tge == '1'))) then
        target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;

    elsif <a link="func_EffectiveHCRX_EL2_TMEA_0" file="shared_pseudocode.xml">EffectiveHCRX_EL2_TMEA</a>() == '1' &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.A == '1' &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> then
        target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;

    elsif <a link="func_EffectiveSCR_EL3_TMEA_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_TMEA</a>() == '1' &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.A == '1' &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>} then
        target_el = <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;

    else
        assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> || <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
        target_el = (if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> else <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>);
    end;

    return target_el;
end;</pstext></ps>
    <ps name="shared/exceptions/exceptions/ConditionSyndrome" mylink="shared.exceptions.exceptions.ConditionSyndrome" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ConditionSyndrome()
// ===================
// Return CV and COND fields of instruction syndrome

func <anchor link="func_ConditionSyndrome_0">ConditionSyndrome</anchor>() =&gt; bits(5)
begin

    var syndrome : bits(5);

    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        let cond = <a link="func_CurrentCond_0" file="shared_pseudocode.xml">CurrentCond</a>();
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T == '0' then             // A32
            syndrome[4] = '1';
            // A conditional A32 instruction that is known to pass its condition code check
            // can be presented either with COND set to 0xE, the value for unconditional, or
            // the COND value held in the instruction.
            if <a link="func_ConditionHolds_1" file="shared_pseudocode.xml">ConditionHolds</a>(cond) &amp;&amp; <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_ESRCONDPASS" file="shared_pseudocode.xml">Unpredictable_ESRCONDPASS</a>) then
                syndrome[3:0] = '1110';
            else
                syndrome[3:0] = cond;
            end;
        else                                // T32
            // When a T32 instruction is trapped, it is IMPLEMENTATION DEFINED whether:
            //  * CV set to 0 and COND is set to an UNKNOWN value
            //  * CV set to 1 and COND is set to the condition code for the condition that
            //    applied to the instruction.
            if ImpDefBool(&quot;Condition valid for trapped T32&quot;) then
                syndrome[4] = '1';
                syndrome[3:0] = cond;
            else
                syndrome[4] = '0';
                syndrome[3:0] = ARBITRARY : bits(4);
            end;
        end;
    else
        syndrome[4] = '1';
        syndrome[3:0] = '1110';
    end;
    return syndrome;
end;</pstext></ps>
    <ps name="shared/exceptions/exceptions/Exception" mylink="shared.exceptions.exceptions.Exception" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Exception
// =========
// Classes of exception.

type <anchor link="type_Exception">Exception</anchor> of enumeration {
        <anchor link="enum_Exception_Uncategorized">Exception_Uncategorized</anchor>,        // Uncategorized or unknown reason
        <anchor link="enum_Exception_WFxTrap">Exception_WFxTrap</anchor>,              // Trapped WFI or WFE instruction
        <anchor link="enum_Exception_CP15RTTrap">Exception_CP15RTTrap</anchor>,           // Trapped AArch32 MCR or MRC access, coproc=0b111
        <anchor link="enum_Exception_CP15RRTTrap">Exception_CP15RRTTrap</anchor>,          // Trapped AArch32 MCRR or MRRC access, coproc=0b1111
        <anchor link="enum_Exception_CP14RTTrap">Exception_CP14RTTrap</anchor>,           // Trapped AArch32 MCR or MRC access, coproc=0b1110
        <anchor link="enum_Exception_CP14DTTrap">Exception_CP14DTTrap</anchor>,           // Trapped AArch32 LDC or STC access, coproc=0b1110
        <anchor link="enum_Exception_CP14RRTTrap">Exception_CP14RRTTrap</anchor>,          // Trapped AArch32 MRRC access, coproc=0b1110
        <anchor link="enum_Exception_AdvSIMDFPAccessTrap">Exception_AdvSIMDFPAccessTrap</anchor>,  // HCPTR-trapped access to SIMD or FP
        <anchor link="enum_Exception_FPIDTrap">Exception_FPIDTrap</anchor>,             // Trapped access to SIMD or FP ID register
        <anchor link="enum_Exception_OtherTrap">Exception_OtherTrap</anchor>,            // Trapped access to other instructions
        // Trapped BXJ instruction not supported in Armv8
        <anchor link="enum_Exception_PACTrap">Exception_PACTrap</anchor>,               // Trapped invalid PAC use
        <anchor link="enum_Exception_IllegalState">Exception_IllegalState</anchor>,          // Illegal Execution state
        <anchor link="enum_Exception_SupervisorCall">Exception_SupervisorCall</anchor>,        // Supervisor Call
        <anchor link="enum_Exception_HypervisorCall">Exception_HypervisorCall</anchor>,        // Hypervisor Call
        <anchor link="enum_Exception_MonitorCall">Exception_MonitorCall</anchor>,           // Monitor Call or Trapped SMC instruction
        <anchor link="enum_Exception_SystemRegisterTrap">Exception_SystemRegisterTrap</anchor>,    // Trapped MRS or MSR System register access
        <anchor link="enum_Exception_ERetTrap">Exception_ERetTrap</anchor>,              // Trapped invalid ERET use
        <anchor link="enum_Exception_InstructionAbort">Exception_InstructionAbort</anchor>,      // Instruction Abort or Prefetch Abort
        <anchor link="enum_Exception_PCAlignment">Exception_PCAlignment</anchor>,           // PC alignment fault
        <anchor link="enum_Exception_DataAbort">Exception_DataAbort</anchor>,             // Data Abort
        <anchor link="enum_Exception_NV2DataAbort">Exception_NV2DataAbort</anchor>,          // Data abort at EL1 reported as being from EL2
        <anchor link="enum_Exception_PACFail">Exception_PACFail</anchor>,               // PAC Authentication failure
        <anchor link="enum_Exception_SPAlignment">Exception_SPAlignment</anchor>,           // SP alignment fault
        <anchor link="enum_Exception_FPTrappedException">Exception_FPTrappedException</anchor>,    // IEEE trapped FP exception
        <anchor link="enum_Exception_SError">Exception_SError</anchor>,                // SError interrupt
        <anchor link="enum_Exception_Breakpoint">Exception_Breakpoint</anchor>,            // (Hardware) Breakpoint
        <anchor link="enum_Exception_SoftwareStep">Exception_SoftwareStep</anchor>,          // Software Step
        <anchor link="enum_Exception_Watchpoint">Exception_Watchpoint</anchor>,            // Watchpoint
        <anchor link="enum_Exception_NV2Watchpoint">Exception_NV2Watchpoint</anchor>,         // Watchpoint at EL1 reported as being from EL2
        <anchor link="enum_Exception_SoftwareBreakpoint">Exception_SoftwareBreakpoint</anchor>,    // Software Breakpoint Instruction
        <anchor link="enum_Exception_VectorCatch">Exception_VectorCatch</anchor>,           // AArch32 Vector Catch
        <anchor link="enum_Exception_IRQ">Exception_IRQ</anchor>,                   // IRQ interrupt
        <anchor link="enum_Exception_SVEAccessTrap">Exception_SVEAccessTrap</anchor>,         // HCPTR trapped access to SVE
        <anchor link="enum_Exception_SMEAccessTrap">Exception_SMEAccessTrap</anchor>,         // HCPTR trapped access to SME
        <anchor link="enum_Exception_GPC">Exception_GPC</anchor>,                   // Granule protection check
        <anchor link="enum_Exception_BranchTarget">Exception_BranchTarget</anchor>,          // Branch Target Identification
        <anchor link="enum_Exception_MemCpyMemSet">Exception_MemCpyMemSet</anchor>,          // Exception from a CPY* or SET* instruction
        <anchor link="enum_Exception_GCSFail">Exception_GCSFail</anchor>,               // GCS Exceptions
        <anchor link="enum_Exception_Profiling">Exception_Profiling</anchor>,             // Profiling exception
        <anchor link="enum_Exception_SystemRegister128Trap">Exception_SystemRegister128Trap</anchor>, // Trapped MRRS or MSRR System register or SYSP access
        <anchor link="enum_Exception_FIQ">Exception_FIQ</anchor>};                  // FIQ interrupt</pstext></ps>
    <ps name="shared/exceptions/exceptions/ExceptionRecord" mylink="shared.exceptions.exceptions.ExceptionRecord" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExceptionRecord
// ===============

type <anchor link="type_ExceptionRecord">ExceptionRecord</anchor> of record {
    exceptype : <a link="type_Exception" file="shared_pseudocode.xml">Exception</a>,           // Exception class
    syndrome : <a link="type_IssType" file="shared_pseudocode.xml">IssType</a>,              // Syndrome record
    paddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>,          // Physical fault address
    vaddress : bits(64),             // Virtual fault address
    ipavalid : boolean,              // Validity of Intermediate Physical fault address
    pavalid : boolean,               // Validity of Physical fault address
    NS : bit,                        // Intermediate Physical fault address space
    ipaddress : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>),            // Intermediate Physical fault address
    trappedsyscallinst : boolean};   // Trapped SVC or SMC instruction</pstext></ps>
    <ps name="shared/exceptions/exceptions/ExceptionSyndrome" mylink="shared.exceptions.exceptions.ExceptionSyndrome" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExceptionSyndrome()
// ===================
// Return a blank exception syndrome record for an exception of the given type.

func <anchor link="func_ExceptionSyndrome_1">ExceptionSyndrome</anchor>(exceptype : <a link="type_Exception" file="shared_pseudocode.xml">Exception</a>) =&gt; <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>
begin

    var r : <a link="type_ExceptionRecord" file="shared_pseudocode.xml">ExceptionRecord</a>;

    r.exceptype      = exceptype;

    // Initialize all other fields
    r.syndrome.iss   = Zeros{25};
    r.syndrome.iss2  = Zeros{24};
    r.vaddress       = Zeros{64};
    r.ipavalid       = FALSE;
    r.pavalid        = FALSE;
    r.NS             = '0';
    r.ipaddress      = Zeros{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>};
    r.paddress.paspace = ARBITRARY : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>;
    r.paddress.address = ARBITRARY : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>);
    r.trappedsyscallinst = FALSE;
    return r;
end;</pstext></ps>
    <ps name="shared/exceptions/traps/Undefined" mylink="shared.exceptions.traps.Undefined" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Undefined()
// ===========

noreturn func Undefined()
begin
    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        AArch32_Undefined();
    else
        AArch64_Undefined();
    end;
end;</pstext></ps>
    <ps name="shared/functions/aborts/EncodeLDFSC" mylink="shared.functions.aborts.EncodeLDFSC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EncodeLDFSC()
// =============
// Function that gives the Long-descriptor FSC code for types of Fault

func <anchor link="func_EncodeLDFSC_2">EncodeLDFSC</anchor>(statuscode : <a link="type_Fault" file="shared_pseudocode.xml">Fault</a>, level : integer) =&gt; bits(6)
begin
    var result : bits(6);

    // 128-bit descriptors will start from level -2 for 4KB to resolve bits IA[55:51]
    if level == -2 then
        assert IsFeatureImplemented(FEAT_D128);
        case statuscode of
            when <a link="enum_Fault_AddressSize" file="shared_pseudocode.xml">Fault_AddressSize</a> =&gt;          result = '101100';
            when <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a> =&gt;          result = '101010';
            when <a link="enum_Fault_SyncExternalOnWalk" file="shared_pseudocode.xml">Fault_SyncExternalOnWalk</a> =&gt;   result = '010010';
            when <a link="enum_Fault_SyncParityOnWalk" file="shared_pseudocode.xml">Fault_SyncParityOnWalk</a> =&gt;
                result = '011010';
                assert !IsFeatureImplemented(FEAT_RAS);
            when <a link="enum_Fault_GPCFOnWalk" file="shared_pseudocode.xml">Fault_GPCFOnWalk</a> =&gt;           result = '100010';
            otherwise =&gt;                       unreachable;
        end;
        return result;
    end;

    if level == -1 then
        assert IsFeatureImplemented(FEAT_LPA2);
        case statuscode of
            when <a link="enum_Fault_AddressSize" file="shared_pseudocode.xml">Fault_AddressSize</a> =&gt;          result = '101001';
            when <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a> =&gt;          result = '101011';
            when <a link="enum_Fault_SyncExternalOnWalk" file="shared_pseudocode.xml">Fault_SyncExternalOnWalk</a> =&gt;   result = '010011';
            when <a link="enum_Fault_SyncParityOnWalk" file="shared_pseudocode.xml">Fault_SyncParityOnWalk</a> =&gt;
                result = '011011';
                assert !IsFeatureImplemented(FEAT_RAS);
            when <a link="enum_Fault_GPCFOnWalk" file="shared_pseudocode.xml">Fault_GPCFOnWalk</a> =&gt;           result = '100011';
            otherwise =&gt;                       unreachable;
        end;

        return result;
    end;
    case statuscode of
        when <a link="enum_Fault_AddressSize" file="shared_pseudocode.xml">Fault_AddressSize</a> =&gt;         result = '0000'::level[1:0]; assert level IN {0,1,2,3};
        when <a link="enum_Fault_AccessFlag" file="shared_pseudocode.xml">Fault_AccessFlag</a> =&gt;          result = '0010'::level[1:0]; assert level IN {0,1,2,3};
        when <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a> =&gt;          result = '0011'::level[1:0]; assert level IN {0,1,2,3};
        when <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>   =&gt;       result = '0001'::level[1:0]; assert level IN {0,1,2,3};
        when <a link="enum_Fault_AsyncExternal" file="shared_pseudocode.xml">Fault_AsyncExternal</a> =&gt;       result = '010001'; assert <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>();
        when <a link="enum_Fault_SyncExternal" file="shared_pseudocode.xml">Fault_SyncExternal</a>  =&gt;       result = '010000';
        when <a link="enum_Fault_SyncExternalOnWalk" file="shared_pseudocode.xml">Fault_SyncExternalOnWalk</a> =&gt;  result = '0101'::level[1:0]; assert level IN {0,1,2,3};
        when <a link="enum_Fault_SyncParity" file="shared_pseudocode.xml">Fault_SyncParity</a>    =&gt;       result = '011000';
        when <a link="enum_Fault_SyncParityOnWalk" file="shared_pseudocode.xml">Fault_SyncParityOnWalk</a> =&gt;    result = '0111'::level[1:0]; assert level IN {0,1,2,3};
        when <a link="enum_Fault_AsyncParity" file="shared_pseudocode.xml">Fault_AsyncParity</a>   =&gt;       result = '011001';
        when <a link="enum_Fault_TagCheck" file="shared_pseudocode.xml">Fault_TagCheck</a> =&gt;            result = '010001'; assert IsFeatureImplemented(FEAT_MTE2);
        when <a link="enum_Fault_Alignment" file="shared_pseudocode.xml">Fault_Alignment</a> =&gt;           result = '100001';
        when <a link="enum_Fault_Debug" file="shared_pseudocode.xml">Fault_Debug</a> =&gt;               result = '100010';
        when <a link="enum_Fault_GPCFOnWalk" file="shared_pseudocode.xml">Fault_GPCFOnWalk</a> =&gt;          result = '1001'::level[1:0]; assert level IN {0,1,2,3};
        when <a link="enum_Fault_GPCFOnOutput" file="shared_pseudocode.xml">Fault_GPCFOnOutput</a> =&gt;        result = '101000';
        when <a link="enum_Fault_TLBConflict" file="shared_pseudocode.xml">Fault_TLBConflict</a> =&gt;         result = '110000';
        when <a link="enum_Fault_UnsupportedAtomicHWUpdate" file="shared_pseudocode.xml">Fault_UnsupportedAtomicHWUpdate</a> =&gt;
                                          result = '110001';
        when <a link="enum_Fault_Lockdown" file="shared_pseudocode.xml">Fault_Lockdown</a> =&gt;            result = '110100';  // IMPLEMENTATION DEFINED
        when <a link="enum_Fault_Exclusive" file="shared_pseudocode.xml">Fault_Exclusive</a> =&gt;           result = '110101';  // IMPLEMENTATION DEFINED
        otherwise =&gt;                      unreachable;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/aborts/IPAValid" mylink="shared.functions.aborts.IPAValid" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IPAValid()
// ==========
// Return TRUE if the IPA is reported for the abort

func <anchor link="func_IPAValid_1">IPAValid</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; boolean
begin
    assert fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;

    if fault.gpcf.gpf != <a link="enum_GPCF_None" file="shared_pseudocode.xml">GPCF_None</a> then
        return fault.secondstage;
    elsif fault.s2fs1walk then
        return fault.statuscode IN {
            <a link="enum_Fault_AccessFlag" file="shared_pseudocode.xml">Fault_AccessFlag</a>,
            <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a>,
            <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>,
            <a link="enum_Fault_AddressSize" file="shared_pseudocode.xml">Fault_AddressSize</a>
        };
    elsif fault.secondstage then
        return fault.statuscode IN {
            <a link="enum_Fault_AccessFlag" file="shared_pseudocode.xml">Fault_AccessFlag</a>,
            <a link="enum_Fault_Translation" file="shared_pseudocode.xml">Fault_Translation</a>,
            <a link="enum_Fault_AddressSize" file="shared_pseudocode.xml">Fault_AddressSize</a>
        };
    else
        return FALSE;
    end;
end;</pstext></ps>
    <ps name="shared/functions/aborts/IsAsyncAbort" mylink="shared.functions.aborts.IsAsyncAbort" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsAsyncAbort()
// ==============
// Returns TRUE if the abort currently being processed is an asynchronous abort, and FALSE
// otherwise.

func <anchor link="func_IsAsyncAbort_1">IsAsyncAbort</anchor>(statuscode : <a link="type_Fault" file="shared_pseudocode.xml">Fault</a>) =&gt; boolean
begin
    assert statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;

    return (statuscode IN {<a link="enum_Fault_AsyncExternal" file="shared_pseudocode.xml">Fault_AsyncExternal</a>, <a link="enum_Fault_AsyncParity" file="shared_pseudocode.xml">Fault_AsyncParity</a>});
end;

// IsAsyncAbort()
// ==============

func <anchor link="func_IsAsyncAbort_1">IsAsyncAbort</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; boolean
begin
    return <a link="func_IsAsyncAbort_1" file="shared_pseudocode.xml">IsAsyncAbort</a>(fault.statuscode);
end;</pstext></ps>
    <ps name="shared/functions/aborts/IsDebugException" mylink="shared.functions.aborts.IsDebugException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsDebugException()
// ==================

func <anchor link="func_IsDebugException_1">IsDebugException</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; boolean
begin
    assert fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;
    return fault.statuscode == <a link="enum_Fault_Debug" file="shared_pseudocode.xml">Fault_Debug</a>;
end;</pstext></ps>
    <ps name="shared/functions/aborts/IsExternalAbort" mylink="shared.functions.aborts.IsExternalAbort" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsExternalAbort()
// =================
// Returns TRUE if the abort currently being processed is an External abort and FALSE otherwise.

readonly func <anchor link="func_IsExternalAbort_1">IsExternalAbort</anchor>(statuscode : <a link="type_Fault" file="shared_pseudocode.xml">Fault</a>) =&gt; boolean
begin
    assert statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;

    return (statuscode IN {
              <a link="enum_Fault_SyncExternal" file="shared_pseudocode.xml">Fault_SyncExternal</a>,
              <a link="enum_Fault_SyncParity" file="shared_pseudocode.xml">Fault_SyncParity</a>,
              <a link="enum_Fault_SyncExternalOnWalk" file="shared_pseudocode.xml">Fault_SyncExternalOnWalk</a>,
              <a link="enum_Fault_SyncParityOnWalk" file="shared_pseudocode.xml">Fault_SyncParityOnWalk</a>,
              <a link="enum_Fault_AsyncExternal" file="shared_pseudocode.xml">Fault_AsyncExternal</a>,
              <a link="enum_Fault_AsyncParity" file="shared_pseudocode.xml">Fault_AsyncParity</a>
    });
end;

// IsExternalAbort()
// =================

readonly func <anchor link="func_IsExternalAbort_1">IsExternalAbort</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; boolean
begin
    return <a link="func_IsExternalAbort_1" file="shared_pseudocode.xml">IsExternalAbort</a>(fault.statuscode) || fault.gpcf.gpf == <a link="enum_GPCF_EABT" file="shared_pseudocode.xml">GPCF_EABT</a>;
end;</pstext></ps>
    <ps name="shared/functions/aborts/IsExternalAbortOnWalk" mylink="shared.functions.aborts.IsExternalAbortOnWalk" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsExternalAbortOnWalk()
// =======================

func <anchor link="func_IsExternalAbortOnWalk_1">IsExternalAbortOnWalk</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; boolean
begin
    assert fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;
    return fault.statuscode IN {<a link="enum_Fault_SyncExternalOnWalk" file="shared_pseudocode.xml">Fault_SyncExternalOnWalk</a>, <a link="enum_Fault_SyncParityOnWalk" file="shared_pseudocode.xml">Fault_SyncParityOnWalk</a>};
end;</pstext></ps>
    <ps name="shared/functions/aborts/IsExternalSyncAbort" mylink="shared.functions.aborts.IsExternalSyncAbort" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsExternalSyncAbort()
// =====================
// Returns TRUE if the abort currently being processed is an external
// synchronous abort and FALSE otherwise.

readonly func <anchor link="func_IsExternalSyncAbort_1">IsExternalSyncAbort</anchor>(statuscode : <a link="type_Fault" file="shared_pseudocode.xml">Fault</a>) =&gt; boolean
begin
    assert statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;
    if IsFeatureImplemented(FEAT_RAS) then
        assert ! statuscode IN {<a link="enum_Fault_SyncParity" file="shared_pseudocode.xml">Fault_SyncParity</a>, <a link="enum_Fault_SyncParityOnWalk" file="shared_pseudocode.xml">Fault_SyncParityOnWalk</a>};
    end;

    return (statuscode IN {
              <a link="enum_Fault_SyncExternal" file="shared_pseudocode.xml">Fault_SyncExternal</a>,
              <a link="enum_Fault_SyncParity" file="shared_pseudocode.xml">Fault_SyncParity</a>,
              <a link="enum_Fault_SyncExternalOnWalk" file="shared_pseudocode.xml">Fault_SyncExternalOnWalk</a>,
              <a link="enum_Fault_SyncParityOnWalk" file="shared_pseudocode.xml">Fault_SyncParityOnWalk</a>
    });
end;

// IsExternalSyncAbort()
// =====================

readonly func <anchor link="func_IsExternalSyncAbort_1">IsExternalSyncAbort</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; boolean
begin
    return <a link="func_IsExternalSyncAbort_1" file="shared_pseudocode.xml">IsExternalSyncAbort</a>(fault.statuscode) || fault.gpcf.gpf == <a link="enum_GPCF_EABT" file="shared_pseudocode.xml">GPCF_EABT</a>;
end;</pstext></ps>
    <ps name="shared/functions/aborts/IsFault" mylink="shared.functions.aborts.IsFault" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsFault()
// =========
// Return TRUE if a fault is associated with an address descriptor

func <anchor link="func_IsFault_1">IsFault</anchor>(addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>) =&gt; boolean
begin
    return addrdesc.fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;
end;

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

func <anchor link="func_IsFault_1">IsFault</anchor>(fault : <a link="type_Fault" file="shared_pseudocode.xml">Fault</a>) =&gt; boolean
begin
    return fault != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;
end;

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

func <anchor link="func_IsFault_1">IsFault</anchor>(retstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>) =&gt; boolean
begin
    return retstatus.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;
end;</pstext></ps>
    <ps name="shared/functions/aborts/IsSErrorInterrupt" mylink="shared.functions.aborts.IsSErrorInterrupt" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsSErrorInterrupt()
// ===================
// Returns TRUE if the abort currently being processed is an SError interrupt, and FALSE
// otherwise.

func <anchor link="func_IsSErrorInterrupt_1">IsSErrorInterrupt</anchor>(statuscode : <a link="type_Fault" file="shared_pseudocode.xml">Fault</a>) =&gt; boolean
begin
    assert statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;

    return (statuscode IN {<a link="enum_Fault_AsyncExternal" file="shared_pseudocode.xml">Fault_AsyncExternal</a>, <a link="enum_Fault_AsyncParity" file="shared_pseudocode.xml">Fault_AsyncParity</a>});
end;

// IsSErrorInterrupt()
// ===================

func <anchor link="func_IsSErrorInterrupt_1">IsSErrorInterrupt</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; boolean
begin
    return <a link="func_IsSErrorInterrupt_1" file="shared_pseudocode.xml">IsSErrorInterrupt</a>(fault.statuscode);
end;


// Add a specific type of return value for FaultSyndrome
type <anchor link="type_IssType">IssType</anchor> of record {
    iss : bits(25),
    iss2 : bits(24)
};</pstext></ps>
    <ps name="shared/functions/aborts/IsSecondStage" mylink="shared.functions.aborts.IsSecondStage" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsSecondStage()
// ===============

func <anchor link="func_IsSecondStage_1">IsSecondStage</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; boolean
begin
    assert fault.statuscode != <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;

    return fault.secondstage;
end;</pstext></ps>
    <ps name="shared/functions/aborts/LSInstructionSyndrome" mylink="shared.functions.aborts.LSInstructionSyndrome" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// LSInstructionSyndrome()
// =======================
// Returns the extended syndrome information for a second stage fault.
//  [10]  - Syndrome valid bit. The syndrome is valid only for certain types of access instruction.
//  [9:8] - Access size.
//  [7]   - Sign extended (for loads).
//  [6:2] - Transfer register.
//  [1]   - Transfer register is 64-bit.
//  [0]   - Instruction has acquire/release semantics.

impdef func <anchor link="func_LSInstructionSyndrome_0">LSInstructionSyndrome</anchor>() =&gt; bits(11)
begin
    return ARBITRARY : bits(11);
end;</pstext></ps>
    <ps name="shared/functions/aborts/ReportAsGPCException" mylink="shared.functions.aborts.ReportAsGPCException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ReportAsGPCException()
// ======================
// Determine whether the given GPCF is reported as a Granule Protection Check Exception
// rather than a Data or Instruction Abort

func <anchor link="func_ReportAsGPCException_1">ReportAsGPCException</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; boolean
begin
    assert IsFeatureImplemented(FEAT_RME);
    assert fault.statuscode IN {<a link="enum_Fault_GPCFOnWalk" file="shared_pseudocode.xml">Fault_GPCFOnWalk</a>, <a link="enum_Fault_GPCFOnOutput" file="shared_pseudocode.xml">Fault_GPCFOnOutput</a>};
    assert fault.gpcf.gpf != <a link="enum_GPCF_None" file="shared_pseudocode.xml">GPCF_None</a>;

    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() &amp;&amp; EDSCR().SDD == '1' then
        return FALSE;
    end;

    case fault.gpcf.gpf of
        when <a link="enum_GPCF_Walk" file="shared_pseudocode.xml">GPCF_Walk</a> =&gt;        return TRUE;
        when <a link="enum_GPCF_AddressSize" file="shared_pseudocode.xml">GPCF_AddressSize</a> =&gt; return TRUE;
        when <a link="enum_GPCF_EABT" file="shared_pseudocode.xml">GPCF_EABT</a> =&gt;        return TRUE;
        when <a link="enum_GPCF_Fail" file="shared_pseudocode.xml">GPCF_Fail</a> =&gt;        return SCR_EL3().GPF == '1' &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
    end;
end;</pstext></ps>
    <ps name="shared/functions/cache/CACHE_OP" mylink="shared.functions.cache.CACHE_OP" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CACHE_OP()
// ==========
// Performs Cache maintenance operations as per CacheRecord.

impdef func CACHE_OP(cache : <a link="type_CacheRecord" file="shared_pseudocode.xml">CacheRecord</a>)
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/cache/CPASAtPAS" mylink="shared.functions.cache.CPASAtPAS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CPASAtPAS()
// ===========
// Get cache PA space for given PA space.

func <anchor link="func_CPASAtPAS_1">CPASAtPAS</anchor>(pas : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>) =&gt; <a link="type_CachePASpace" file="shared_pseudocode.xml">CachePASpace</a>
begin
    case pas of
        when <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> =&gt;
            return <a link="enum_CPAS_NonSecure" file="shared_pseudocode.xml">CPAS_NonSecure</a>;
        when <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> =&gt;
            return <a link="enum_CPAS_Secure" file="shared_pseudocode.xml">CPAS_Secure</a>;
        when <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a> =&gt;
            return <a link="enum_CPAS_Root" file="shared_pseudocode.xml">CPAS_Root</a>;
        when <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a> =&gt;
            return <a link="enum_CPAS_Realm" file="shared_pseudocode.xml">CPAS_Realm</a>;
        when <a link="enum_PAS_SystemAgent" file="shared_pseudocode.xml">PAS_SystemAgent</a> =&gt;
            return <a link="enum_CPAS_SystemAgent" file="shared_pseudocode.xml">CPAS_SystemAgent</a>;
        when <a link="enum_PAS_NonSecureProtected" file="shared_pseudocode.xml">PAS_NonSecureProtected</a> =&gt;
            return <a link="enum_CPAS_NonSecureProtected" file="shared_pseudocode.xml">CPAS_NonSecureProtected</a>;
        when <a link="enum_PAS_NA6" file="shared_pseudocode.xml">PAS_NA6</a> =&gt;
            return <a link="enum_CPAS_NA6" file="shared_pseudocode.xml">CPAS_NA6</a>;
        when <a link="enum_PAS_NA7" file="shared_pseudocode.xml">PAS_NA7</a> =&gt;
            return <a link="enum_CPAS_NA7" file="shared_pseudocode.xml">CPAS_NA7</a>;
        otherwise =&gt;
            unreachable;
    end;
end;</pstext></ps>
    <ps name="shared/functions/cache/CPASAtSecurityState" mylink="shared.functions.cache.CPASAtSecurityState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CPASAtSecurityState()
// =====================
// Get cache PA space for given security state.

func <anchor link="func_CPASAtSecurityState_1">CPASAtSecurityState</anchor>(ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>) =&gt; <a link="type_CachePASpace" file="shared_pseudocode.xml">CachePASpace</a>
begin
    case ss of
        when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt;
            return <a link="enum_CPAS_NonSecure" file="shared_pseudocode.xml">CPAS_NonSecure</a>;
        when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;
            return <a link="enum_CPAS_SecureNonSecure" file="shared_pseudocode.xml">CPAS_SecureNonSecure</a>;
        when <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a> =&gt;
            return <a link="enum_CPAS_Any" file="shared_pseudocode.xml">CPAS_Any</a>;
        when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;
            return <a link="enum_CPAS_RealmNonSecure" file="shared_pseudocode.xml">CPAS_RealmNonSecure</a>;
    end;
end;</pstext></ps>
    <ps name="shared/functions/cache/CacheRecord" mylink="shared.functions.cache.CacheRecord" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CacheRecord
// ===========
// Details related to a cache operation.

type <anchor link="type_CacheRecord">CacheRecord</anchor> of record {
    acctype       : <a link="type_AccessType" file="shared_pseudocode.xml">AccessType</a>,        // Access type
    cacheop       : <a link="type_CacheOp" file="shared_pseudocode.xml">CacheOp</a>,           // Cache operation
    opscope       : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a>,      // Cache operation type
    cachetype     : <a link="type_CacheType" file="shared_pseudocode.xml">CacheType</a>,         // Cache type
    regval        : bits(64),
    paddress      : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>,
    vaddress      : bits(64),          // For VA operations
    setnum        : integer,           // For SW operations
    waynum        : integer,           // For SW operations
    level         : integer,           // For SW operations
    shareability  : <a link="type_Shareability" file="shared_pseudocode.xml">Shareability</a>,
    is_vmid_valid : boolean,           // is vmid valid for current context
    vmid          : bits(NUM_VMIDBITS),
    is_asid_valid : boolean,           // is asid valid for current context
    asid          : bits(NUM_ASIDBITS),
    security      : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>,
    // For cache operations to full cache or by setnum/waynum
    // For operations by address, PA space in paddress
    cpas : <a link="type_CachePASpace" file="shared_pseudocode.xml">CachePASpace</a>
};</pstext></ps>
    <ps name="shared/functions/cache/DecodeSW" mylink="shared.functions.cache.DecodeSW" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodeSW()
// ==========
// Decode input value into setnum, waynum and level for SW instructions.

func <anchor link="func_DecodeSW_2">DecodeSW</anchor>(regval : bits(64), cachetype : <a link="type_CacheType" file="shared_pseudocode.xml">CacheType</a>) =&gt; (integer, integer, integer)
begin
    let level : integer = UInt(regval[3:1]);
    let (numsets, associativity, linesize) = <a link="func_GetCacheInfo_2" file="shared_pseudocode.xml">GetCacheInfo</a>(level, cachetype);
    // For the given level and cachetype, get the number of sets, associativity and
    // cache line size in terms of actual bytes.

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

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

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

    return (setnum, waynum, level);
end;</pstext></ps>
    <ps name="shared/functions/cache/GetCacheInfo" mylink="shared.functions.cache.GetCacheInfo" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetCacheInfo()
// ==============
// Returns numsets, associativity &amp; linesize in terms of actual bytes.

impdef func <anchor link="func_GetCacheInfo_2">GetCacheInfo</anchor>(level : integer, cachetype : <a link="type_CacheType" file="shared_pseudocode.xml">CacheType</a>) =&gt; (integer, integer, integer)
begin
    let numsets : integer = ImpDefInt(&quot;Numsets for DC SW instructions&quot;);
    let associativity : integer = ImpDefInt(&quot;Associativity for DC SW instructions&quot;);
    let linesize : integer = ImpDefInt(&quot;Linesize for DC SW instructions&quot;);
    return (numsets, associativity, linesize);
end;</pstext></ps>
    <ps name="shared/functions/common/IsZeroBit" mylink="shared.functions.common.IsZeroBit" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsZeroBit()
// ===========

func <anchor link="func_IsZeroBit_2">IsZeroBit</anchor>{N}(x : bits(N)) =&gt; bit
begin
    return if IsZero(x) then '1' else '0';
end;</pstext></ps>
    <ps name="shared/functions/common/NormalizeReal" mylink="shared.functions.common.NormalizeReal" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// NormalizeReal
// =============
// Normalizes x to the form 1.xxx... x 2^y and returns (mantissa, exponent)

func <anchor link="func_NormalizeReal_1">NormalizeReal</anchor>(x : real) =&gt; (real, integer)
begin
    let exponent : integer = ILog2(x);
    let mantissa : real = x / (2.0 ^ exponent);
    return (mantissa, exponent);
end;</pstext></ps>
    <ps name="shared/functions/common/RShr" mylink="shared.functions.common.RShr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// RShr()
// ======
// Shift integer value right with rounding

func <anchor link="func_RShr_3">RShr</anchor>(value : integer, shift : integer, round : boolean) =&gt; integer
begin
    assert shift &gt; 0;
    if round then
        return (value + (1 &lt;&lt; (shift - 1))) &gt;&gt; shift;
    else
        return value &gt;&gt; shift;
    end;
end;</pstext></ps>
    <ps name="shared/functions/common/Reverse" mylink="shared.functions.common.Reverse" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Reverse()
// =========
// Reverse subwords of M bits in an N-bit word

func <anchor link="func_Reverse_3">Reverse</anchor>{N}(word : bits(N), M : integer) =&gt; bits(N)
begin
    assert N MOD M == 0;
    var result : bits(N);
    let swsize : integer{} = M as integer{1..N};
    let sw : integer = N DIV swsize;
    for s = 0 to sw-1 do
        result[((sw - 1) - s)*:swsize] = word[s*:swsize];
    end;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/common/Signal" mylink="shared.functions.common.Signal" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Signal
// ======
// Available signal types

type <anchor link="type_Signal">Signal</anchor> of enumeration {<anchor link="enum_LOW">LOW</anchor>, <anchor link="enum_HIGH">HIGH</anchor>};</pstext></ps>
    <ps name="shared/functions/counters" mylink="shared.functions.counters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">var <anchor link="global_PhysicalCount">PhysicalCount</anchor> : bits(88);

var <anchor link="global_IsLocalTimeoutEventPending">IsLocalTimeoutEventPending</anchor> : boolean;
var <anchor link="global_LocalTimeoutVal">LocalTimeoutVal</anchor> : bits(64);           // Value to compare against the Virtual Counter Timer
                                          // to generate the local timeout event.</pstext></ps>
    <ps name="shared/functions/counters/AArch32_CheckTimerConditions" mylink="shared.functions.counters.AArch32_CheckTimerConditions" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch32_CheckTimerConditions()
// ==============================
// Checking timer conditions for all A32 timer registers

func <anchor link="func_AArch32_CheckTimerConditions_0">AArch32_CheckTimerConditions</anchor>()
begin
    var status : boolean;
    var offset : bits(64);
    offset = Zeros{64};
    assert !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>();
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        if CNTP_CTL_S().ENABLE == '1' then
            status = <a link="func_IsTimerConditionMet_4" file="shared_pseudocode.xml">IsTimerConditionMet</a>(offset, CNTP_CVAL_S(),
                                         CNTP_CTL_S().IMASK, <a link="enum_InterruptID_CNTPS" file="shared_pseudocode.xml">InterruptID_CNTPS</a>);
            CNTP_CTL_S().ISTATUS = if status then '1' else '0';
        end;

        if CNTP_CTL_NS().ENABLE == '1' then
            status = <a link="func_IsTimerConditionMet_4" file="shared_pseudocode.xml">IsTimerConditionMet</a>(offset, CNTP_CVAL_NS(),
                                         CNTP_CTL_NS().IMASK, <a link="enum_InterruptID_CNTP" file="shared_pseudocode.xml">InterruptID_CNTP</a>);
            CNTP_CTL_NS().ISTATUS = if status then '1' else '0';
        end;
    else
        if CNTP_CTL().ENABLE == '1' then
            status = <a link="func_IsTimerConditionMet_4" file="shared_pseudocode.xml">IsTimerConditionMet</a>(offset, CNTP_CVAL(),
                                         CNTP_CTL().IMASK, <a link="enum_InterruptID_CNTP" file="shared_pseudocode.xml">InterruptID_CNTP</a>);
            CNTP_CTL().ISTATUS = if status then '1' else '0';
        end;
    end;
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; CNTHP_CTL().ENABLE == '1' then
        status = <a link="func_IsTimerConditionMet_4" file="shared_pseudocode.xml">IsTimerConditionMet</a>(offset, CNTHP_CVAL(),
                                     CNTHP_CTL().IMASK, <a link="enum_InterruptID_CNTHP" file="shared_pseudocode.xml">InterruptID_CNTHP</a>);
        CNTHP_CTL().ISTATUS = if status then '1' else '0';
    end;
    if CNTV_CTL_EL0().ENABLE == '1' then
        status = <a link="func_IsTimerConditionMet_4" file="shared_pseudocode.xml">IsTimerConditionMet</a>(CNTVOFF_EL2(), CNTV_CVAL_EL0(),
                                     CNTV_CTL_EL0().IMASK, <a link="enum_InterruptID_CNTV" file="shared_pseudocode.xml">InterruptID_CNTV</a>);
        CNTV_CTL_EL0().ISTATUS = if status then '1' else '0';
    end;
    return;
end;</pstext></ps>
    <ps name="shared/functions/counters/AArch64_CheckTimerConditions" mylink="shared.functions.counters.AArch64_CheckTimerConditions" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_CheckTimerConditions()
// ==============================
// Checking timer conditions for all A64 timer registers

func <anchor link="func_AArch64_CheckTimerConditions_0">AArch64_CheckTimerConditions</anchor>()
begin
    var status : boolean;
    var offset : bits(64);
    var imask : bit;
    let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>();
    if (IsFeatureImplemented(FEAT_ECV_POFF) &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) &amp;&amp;
          CNTHCTL_EL2().ECV == '1' &amp;&amp; SCR_EL3().ECVEn == '1') then
        offset = CNTPOFF_EL2();
    else
        offset = Zeros{64};
    end;
    if CNTP_CTL_EL0().ENABLE == '1' then
        imask = CNTP_CTL_EL0().IMASK;
        if (IsFeatureImplemented(FEAT_RME) &amp;&amp; ss IN {<a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a>, <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a>} &amp;&amp;
              CNTHCTL_EL2().CNTPMASK == '1') then
            imask = '1';
        end;
        status = <a link="func_IsTimerConditionMet_4" file="shared_pseudocode.xml">IsTimerConditionMet</a>(offset, CNTP_CVAL_EL0(),
                                     imask, <a link="enum_InterruptID_CNTP" file="shared_pseudocode.xml">InterruptID_CNTP</a>);
        CNTP_CTL_EL0().ISTATUS = if status then '1' else '0';
    end;
    if ((<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || (<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; !IsFeatureImplemented(FEAT_SEL2))) &amp;&amp;
       CNTHP_CTL_EL2().ENABLE == '1') then
        status = <a link="func_IsTimerConditionMet_4" file="shared_pseudocode.xml">IsTimerConditionMet</a>(Zeros{64}, CNTHP_CVAL_EL2(),
                                     CNTHP_CTL_EL2().IMASK, <a link="enum_InterruptID_CNTHP" file="shared_pseudocode.xml">InterruptID_CNTHP</a>);
        CNTHP_CTL_EL2().ISTATUS = if status then '1' else '0';
    end;
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; IsFeatureImplemented(FEAT_SEL2) &amp;&amp; CNTHPS_CTL_EL2().ENABLE == '1' then
        status = <a link="func_IsTimerConditionMet_4" file="shared_pseudocode.xml">IsTimerConditionMet</a>(Zeros{64}, CNTHPS_CVAL_EL2(),
                                     CNTHPS_CTL_EL2().IMASK, <a link="enum_InterruptID_CNTHPS" file="shared_pseudocode.xml">InterruptID_CNTHPS</a>);
        CNTHPS_CTL_EL2().ISTATUS = if status then '1' else '0';
    end;

    if CNTPS_CTL_EL1().ENABLE == '1' then
        status = <a link="func_IsTimerConditionMet_4" file="shared_pseudocode.xml">IsTimerConditionMet</a>(Zeros{64}, CNTPS_CVAL_EL1(),
                                     CNTPS_CTL_EL1().IMASK, <a link="enum_InterruptID_CNTPS" file="shared_pseudocode.xml">InterruptID_CNTPS</a>);
        CNTPS_CTL_EL1().ISTATUS = if status then '1' else '0';
    end;

    if CNTV_CTL_EL0().ENABLE == '1' then
        imask = CNTV_CTL_EL0().IMASK;
        if (IsFeatureImplemented(FEAT_RME) &amp;&amp; ss IN {<a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a>, <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a>} &amp;&amp;
              CNTHCTL_EL2().CNTVMASK == '1') then
            imask = '1';
        end;
        status = <a link="func_IsTimerConditionMet_4" file="shared_pseudocode.xml">IsTimerConditionMet</a>(CNTVOFF_EL2(), CNTV_CVAL_EL0(),
                                     imask, <a link="enum_InterruptID_CNTV" file="shared_pseudocode.xml">InterruptID_CNTV</a>);
        CNTV_CTL_EL0().ISTATUS = if status then '1' else '0';
    end;

    if ((IsFeatureImplemented(FEAT_VHE) &amp;&amp; (<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || !IsFeatureImplemented(FEAT_SEL2))) &amp;&amp;
          CNTHV_CTL_EL2().ENABLE == '1') then
        status = <a link="func_IsTimerConditionMet_4" file="shared_pseudocode.xml">IsTimerConditionMet</a>(Zeros{64}, CNTHV_CVAL_EL2(),
                                     CNTHV_CTL_EL2().IMASK, <a link="enum_InterruptID_CNTHV" file="shared_pseudocode.xml">InterruptID_CNTHV</a>);
        CNTHV_CTL_EL2().ISTATUS = if status then '1' else '0';
    end;

    if ((IsFeatureImplemented(FEAT_SEL2) &amp;&amp; IsFeatureImplemented(FEAT_VHE)) &amp;&amp;
          CNTHVS_CTL_EL2().ENABLE == '1') then
        status = <a link="func_IsTimerConditionMet_4" file="shared_pseudocode.xml">IsTimerConditionMet</a>(Zeros{64}, CNTHVS_CVAL_EL2(),
                                     CNTHVS_CTL_EL2().IMASK, <a link="enum_InterruptID_CNTHVS" file="shared_pseudocode.xml">InterruptID_CNTHVS</a>);
        CNTHVS_CTL_EL2().ISTATUS = if status then '1' else '0';
    end;
    return;
end;</pstext></ps>
    <ps name="shared/functions/counters/CNTHCTL_EL2_VHE" mylink="shared.functions.counters.CNTHCTL_EL2_VHE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CNTHCTL_EL2_VHE()
// =================
// In the case where EL2 accesses the CNTKCTL_EL1 register, and the access
// is redirected to CNTHCTL_EL2 as a result of HCR_EL2.E2H being 1,
// then the bits of CNTHCTL_EL2 that are RES0 in CNTKCTL_EL1 are
// treated as being UNKNOWN. This function applies the UNKNOWN behavior.

func <anchor link="func_CNTHCTL_EL2_VHE_1">CNTHCTL_EL2_VHE</anchor>(original_value : bits(64)) =&gt; bits(64)
begin
    assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    assert HCR_EL2().E2H == '1';

    var return_value : bits(64) = original_value;
    if !IsFeatureImplemented(FEAT_NV2p1) then
        return_value[19:18] = ARBITRARY : bits(2);
        return_value[16:10] = ARBITRARY : bits(7);
    end;
    return return_value;
end;</pstext></ps>
    <ps name="shared/functions/counters/GenericCounterTick" mylink="shared.functions.counters.GenericCounterTick" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GenericCounterTick()
// ====================
// Increments PhysicalCount value for every clock tick.

func <anchor link="func_GenericCounterTick_0">GenericCounterTick</anchor>()
begin
    var prev_physical_count : bits(64);
    if CNTCR().EN == '0' then
        if !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then
            <a link="func_AArch32_CheckTimerConditions_0" file="shared_pseudocode.xml">AArch32_CheckTimerConditions</a>();
        else
            <a link="func_AArch64_CheckTimerConditions_0" file="shared_pseudocode.xml">AArch64_CheckTimerConditions</a>();
        end;
        return;
    end;
    prev_physical_count = <a link="func_PhysicalCountInt_0" file="shared_pseudocode.xml">PhysicalCountInt</a>();
    if IsFeatureImplemented(FEAT_CNTSC) &amp;&amp; CNTCR().SCEN == '1' then
        <a link="global_PhysicalCount" file="shared_pseudocode.xml">PhysicalCount</a> = <a link="global_PhysicalCount" file="shared_pseudocode.xml">PhysicalCount</a> + ZeroExtend{88}(CNTSCR());
    else
        <a link="global_PhysicalCount" file="shared_pseudocode.xml">PhysicalCount</a>[87:24] = <a link="global_PhysicalCount" file="shared_pseudocode.xml">PhysicalCount</a>[87:24] + 1;
    end;
    if !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then
        <a link="func_AArch32_CheckTimerConditions_0" file="shared_pseudocode.xml">AArch32_CheckTimerConditions</a>();
    else
        <a link="func_AArch64_CheckTimerConditions_0" file="shared_pseudocode.xml">AArch64_CheckTimerConditions</a>();
    end;
    <a link="func_TestEventCNTP_2" file="shared_pseudocode.xml">TestEventCNTP</a>(prev_physical_count, <a link="func_PhysicalCountInt_0" file="shared_pseudocode.xml">PhysicalCountInt</a>());
    <a link="func_TestEventCNTV_2" file="shared_pseudocode.xml">TestEventCNTV</a>(prev_physical_count, <a link="func_PhysicalCountInt_0" file="shared_pseudocode.xml">PhysicalCountInt</a>());
    return;
end;</pstext></ps>
    <ps name="shared/functions/counters/IsTimerConditionMet" mylink="shared.functions.counters.IsTimerConditionMet" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsTimerConditionMet()
// =====================

func <anchor link="func_IsTimerConditionMet_4">IsTimerConditionMet</anchor>(offset : bits(64), compare_value : bits(64),
                         imask : bits(1), intid : <a link="type_InterruptID" file="shared_pseudocode.xml">InterruptID</a>) =&gt; boolean
begin
    var condition_met : boolean;
    var level : <a link="type_Signal" file="shared_pseudocode.xml">Signal</a>;
    condition_met = (UInt(<a link="func_PhysicalCountInt_0" file="shared_pseudocode.xml">PhysicalCountInt</a>() - offset) - UInt(compare_value)) &gt;= 0;
    level = if condition_met &amp;&amp; imask == '0' then <a link="enum_HIGH" file="shared_pseudocode.xml">HIGH</a> else <a link="enum_LOW" file="shared_pseudocode.xml">LOW</a>;
    SetInterruptRequestLevel(intid, level);
    return condition_met;
end;</pstext></ps>
    <ps name="shared/functions/counters/SetEventRegister" mylink="shared.functions.counters.SetEventRegister" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SetEventRegister()
// ==================
// Sets the Event Register of this PE

func <anchor link="func_SetEventRegister_0">SetEventRegister</anchor>()
begin
    <a link="global_EventRegister" file="shared_pseudocode.xml">EventRegister</a> = '1';
    return;
end;</pstext></ps>
    <ps name="shared/functions/counters/TestEventCNTP" mylink="shared.functions.counters.TestEventCNTP" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TestEventCNTP()
// ===============
// Generate Event stream from the physical counter

func <anchor link="func_TestEventCNTP_2">TestEventCNTP</anchor>(prev_physical_count : bits(64), current_physical_count : bits(64))
begin
    var offset : bits(64);
    var samplebit, previousbit : bit;
    var n : integer;
    if CNTHCTL_EL2().EVNTEN == '1' then
        n = UInt(CNTHCTL_EL2().EVNTI);
        if IsFeatureImplemented(FEAT_ECV) &amp;&amp; CNTHCTL_EL2().EVNTIS == '1' then
            n = n + 8;
        end;
        if (IsFeatureImplemented(FEAT_ECV_POFF) &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; !<a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) &amp;&amp;
             CNTHCTL_EL2().ECV == '1' &amp;&amp; SCR_EL3().ECVEn == '1') then
            offset = CNTPOFF_EL2();
        else
            offset = Zeros{64};
        end;
        samplebit   = (current_physical_count - offset)[n];
        previousbit = (prev_physical_count - offset)[n];
        if CNTHCTL_EL2().EVNTDIR == '0' then
            if previousbit == '0' &amp;&amp; samplebit == '1' then <a link="func_SetEventRegister_0" file="shared_pseudocode.xml">SetEventRegister</a>(); end;
        else
            if previousbit == '1' &amp;&amp; samplebit == '0' then <a link="func_SetEventRegister_0" file="shared_pseudocode.xml">SetEventRegister</a>(); end;
        end;
    end;
    return;
end;</pstext></ps>
    <ps name="shared/functions/counters/TestEventCNTV" mylink="shared.functions.counters.TestEventCNTV" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TestEventCNTV()
// ===============
// Generate Event stream from the virtual counter

func <anchor link="func_TestEventCNTV_2">TestEventCNTV</anchor>(prev_physical_count : bits(64), current_physical_count : bits(64))
begin
    var offset : bits(64);
    var samplebit, previousbit : bit;
    var n : integer;
    if (<a link="func_EffectiveHCR_EL2_E2H_0" file="shared_pseudocode.xml">EffectiveHCR_EL2_E2H</a>()::<a link="func_EffectiveTGE_0" file="shared_pseudocode.xml">EffectiveTGE</a>() != '11' &amp;&amp;
          CNTKCTL_EL1().EVNTEN == '1') then
        n = UInt(CNTKCTL_EL1().EVNTI);
        if IsFeatureImplemented(FEAT_ECV) &amp;&amp; CNTKCTL_EL1().EVNTIS == '1' then
            n = n + 8;
        end;
        offset      = if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then CNTVOFF_EL2() else Zeros{64};

        samplebit   = (current_physical_count - offset)[n];
        previousbit = (prev_physical_count - offset)[n];
        if CNTKCTL_EL1().EVNTDIR == '0' then
            if previousbit == '0' &amp;&amp; samplebit == '1' then <a link="func_SetEventRegister_0" file="shared_pseudocode.xml">SetEventRegister</a>(); end;
        else
            if previousbit == '1' &amp;&amp; samplebit == '0' then <a link="func_SetEventRegister_0" file="shared_pseudocode.xml">SetEventRegister</a>(); end;
        end;
    end;
    return;
end;</pstext></ps>
    <ps name="shared/functions/counters/VirtualCounterTimer" mylink="shared.functions.counters.VirtualCounterTimer" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// VirtualCounterTimer()
// =====================
// Returns the Counter-Timer Virtual Count value, the value is as read by CurrentEL to CNTVCT_EL0.

func <anchor link="func_VirtualCounterTimer_0">VirtualCounterTimer</anchor>() =&gt; bits(64)
begin
    var cntvct : bits(64);

    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then
        if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; !<a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) then
            cntvct = <a link="func_PhysicalCountInt_0" file="shared_pseudocode.xml">PhysicalCountInt</a>() - CNTVOFF_EL2();
        else
            cntvct = <a link="func_PhysicalCountInt_0" file="shared_pseudocode.xml">PhysicalCountInt</a>();
        end;
    else
        if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
            cntvct = <a link="func_PhysicalCountInt_0" file="shared_pseudocode.xml">PhysicalCountInt</a>() - CNTVOFF_EL2();
        elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
            cntvct = <a link="func_PhysicalCountInt_0" file="shared_pseudocode.xml">PhysicalCountInt</a>() - CNTVOFF();
        else
            cntvct = <a link="func_PhysicalCountInt_0" file="shared_pseudocode.xml">PhysicalCountInt</a>();
        end;
    end;

    return cntvct;
end;</pstext></ps>
    <ps name="shared/functions/crc/BitReverse" mylink="shared.functions.crc.BitReverse" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BitReverse()
// ============

func <anchor link="func_BitReverse_2">BitReverse</anchor>{N}(data : bits(N)) =&gt; bits(N)
begin
    var result : bits(N);
    for i = 0 to N-1 do
        result[(N-i)-1] = data[i];
    end;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/crc/Poly32Mod2" mylink="shared.functions.crc.Poly32Mod2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Poly32Mod2()
// ============

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

func <anchor link="func_Poly32Mod2_3">Poly32Mod2</anchor>{N}(data_in : bits(N), poly : bits(32)) =&gt; bits(32)
begin
    assert N &gt; 32;
    var data : bits(N) = data_in;
    for i = N-1 downto 32 do
        if data[i] == '1' then
            data[i-1:0] = data[i-1:0] XOR (poly::Zeros{i-32});
        end;
    end;
    return data[31:0];
end;</pstext></ps>
    <ps name="shared/functions/crypto/AESInvMixColumns" mylink="shared.functions.crypto.AESInvMixColumns" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AESInvMixColumns()
// ==================
// Transformation in the Inverse Cipher that is the inverse of AESMixColumns.

func <anchor link="func_AESInvMixColumns_1">AESInvMixColumns</anchor>(op : bits (128)) =&gt; bits(128)
begin
    let in0 : bits(4*8) = op[ 96+:8] :: op[ 64+:8] :: op[ 32+:8] :: op[  0+:8];
    let in1 : bits(4*8) = op[104+:8] :: op[ 72+:8] :: op[ 40+:8] :: op[  8+:8];
    let in2 : bits(4*8) = op[112+:8] :: op[ 80+:8] :: op[ 48+:8] :: op[ 16+:8];
    let in3 : bits(4*8) = op[120+:8] :: op[ 88+:8] :: op[ 56+:8] :: op[ 24+:8];

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

    for c = 0 to 3 do
        out0[c*8+:8] =  (<a link="func_FFmul0E_1" file="shared_pseudocode.xml">FFmul0E</a>(in0[c*8+:8]) XOR <a link="func_FFmul0B_1" file="shared_pseudocode.xml">FFmul0B</a>(in1[c*8+:8]) XOR <a link="func_FFmul0D_1" file="shared_pseudocode.xml">FFmul0D</a>(in2[c*8+:8]) XOR
                         <a link="func_FFmul09_1" file="shared_pseudocode.xml">FFmul09</a>(in3[c*8+:8]));
        out1[c*8+:8] =  (<a link="func_FFmul09_1" file="shared_pseudocode.xml">FFmul09</a>(in0[c*8+:8]) XOR <a link="func_FFmul0E_1" file="shared_pseudocode.xml">FFmul0E</a>(in1[c*8+:8]) XOR <a link="func_FFmul0B_1" file="shared_pseudocode.xml">FFmul0B</a>(in2[c*8+:8]) XOR
                         <a link="func_FFmul0D_1" file="shared_pseudocode.xml">FFmul0D</a>(in3[c*8+:8]));
        out2[c*8+:8] =  (<a link="func_FFmul0D_1" file="shared_pseudocode.xml">FFmul0D</a>(in0[c*8+:8]) XOR <a link="func_FFmul09_1" file="shared_pseudocode.xml">FFmul09</a>(in1[c*8+:8]) XOR <a link="func_FFmul0E_1" file="shared_pseudocode.xml">FFmul0E</a>(in2[c*8+:8]) XOR
                         <a link="func_FFmul0B_1" file="shared_pseudocode.xml">FFmul0B</a>(in3[c*8+:8]));
        out3[c*8+:8] =  (<a link="func_FFmul0B_1" file="shared_pseudocode.xml">FFmul0B</a>(in0[c*8+:8]) XOR <a link="func_FFmul0D_1" file="shared_pseudocode.xml">FFmul0D</a>(in1[c*8+:8]) XOR <a link="func_FFmul09_1" file="shared_pseudocode.xml">FFmul09</a>(in2[c*8+:8]) XOR
                         <a link="func_FFmul0E_1" file="shared_pseudocode.xml">FFmul0E</a>(in3[c*8+:8]));
    end;

    return (
        out3[3*8+:8] :: out2[3*8+:8] :: out1[3*8+:8] :: out0[3*8+:8] ::
        out3[2*8+:8] :: out2[2*8+:8] :: out1[2*8+:8] :: out0[2*8+:8] ::
        out3[1*8+:8] :: out2[1*8+:8] :: out1[1*8+:8] :: out0[1*8+:8] ::
        out3[0*8+:8] :: out2[0*8+:8] :: out1[0*8+:8] :: out0[0*8+:8]
    );
end;</pstext></ps>
    <ps name="shared/functions/crypto/AESInvShiftRows" mylink="shared.functions.crypto.AESInvShiftRows" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AESInvShiftRows()
// =================
// Transformation in the Inverse Cipher that is inverse of AESShiftRows.

func <anchor link="func_AESInvShiftRows_1">AESInvShiftRows</anchor>(op : bits(128)) =&gt; bits(128)
begin
    return (
        op[ 31: 24] :: op[ 55: 48] :: op[ 79: 72] :: op[103: 96] ::
        op[127:120] :: op[ 23: 16] :: op[ 47: 40] :: op[ 71: 64] ::
        op[ 95: 88] :: op[119:112] :: op[ 15:  8] :: op[ 39: 32] ::
        op[ 63: 56] :: op[ 87: 80] :: op[111:104] :: op[  7:  0]
    );
end;</pstext></ps>
    <ps name="shared/functions/crypto/AESInvSubBytes" mylink="shared.functions.crypto.AESInvSubBytes" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AESInvSubBytes()
// ================
// Transformation in the Inverse Cipher that is the inverse of AESSubBytes.

func <anchor link="func_AESInvSubBytes_1">AESInvSubBytes</anchor>(op : bits(128)) =&gt; bits(128)
begin
    // Inverse S-box values
    let GF2_inv : bits(16*16*8) = (
        /*       F E D C B A 9 8 7 6 5 4 3 2 1 0       */
        /*F*/ 0x7d0c2155631469e126d677ba7e042b17[127:0] ::
        /*E*/ 0x619953833cbbebc8b0f52aae4d3be0a0[127:0] ::
        /*D*/ 0xef9cc9939f7ae52d0d4ab519a97f5160[127:0] ::
        /*C*/ 0x5fec8027591012b131c7078833a8dd1f[127:0] ::
        /*B*/ 0xf45acd78fec0db9a2079d2c64b3e56fc[127:0] ::
        /*A*/ 0x1bbe18aa0e62b76f89c5291d711af147[127:0] ::
        /*9*/ 0x6edf751ce837f9e28535ade72274ac96[127:0] ::
        /*8*/ 0x73e6b4f0cecff297eadc674f4111913a[127:0] ::
        /*7*/ 0x6b8a130103bdafc1020f3fca8f1e2cd0[127:0] ::
        /*6*/ 0x0645b3b80558e4f70ad3bc8c00abd890[127:0] ::
        /*5*/ 0x849d8da75746155edab9edfd5048706c[127:0] ::
        /*4*/ 0x92b6655dcc5ca4d41698688664f6f872[127:0] ::
        /*3*/ 0x25d18b6d49a25b76b224d92866a12e08[127:0] ::
        /*2*/ 0x4ec3fa420b954cee3d23c2a632947b54[127:0] ::
        /*1*/ 0xcbe9dec444438e3487ff2f9b8239e37c[127:0] ::
        /*0*/ 0xfbd7f3819ea340bf38a53630d56a0952[127:0]
    );
    var out : bits(128);
    for i = 0 to 15 do
        out[i*8+:8] = GF2_inv[UInt(op[i*8+:8])*8+:8];
    end;
    return out;
end;</pstext></ps>
    <ps name="shared/functions/crypto/AESMixColumns" mylink="shared.functions.crypto.AESMixColumns" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AESMixColumns()
// ===============
// Transformation in the Cipher that takes all of the columns of the
// State and mixes their data (independently of one another) to
// produce new columns.

func <anchor link="func_AESMixColumns_1">AESMixColumns</anchor>(op : bits (128)) =&gt; bits(128)
begin
    let in0 : bits(4*8) = op[ 96+:8] :: op[ 64+:8] :: op[ 32+:8] :: op[  0+:8];
    let in1 : bits(4*8) = op[104+:8] :: op[ 72+:8] :: op[ 40+:8] :: op[  8+:8];
    let in2 : bits(4*8) = op[112+:8] :: op[ 80+:8] :: op[ 48+:8] :: op[ 16+:8];
    let in3 : bits(4*8) = op[120+:8] :: op[ 88+:8] :: op[ 56+:8] :: op[ 24+:8];

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

    for c = 0 to 3 do
        out0[c*8+:8] = (<a link="func_FFmul02_1" file="shared_pseudocode.xml">FFmul02</a>(in0[c*8+:8]) XOR <a link="func_FFmul03_1" file="shared_pseudocode.xml">FFmul03</a>(in1[c*8+:8]) XOR
                                 in2[c*8+:8]  XOR         in3[c*8+:8]);
        out1[c*8+:8] = (<a link="func_FFmul02_1" file="shared_pseudocode.xml">FFmul02</a>(in1[c*8+:8])  XOR <a link="func_FFmul03_1" file="shared_pseudocode.xml">FFmul03</a>(in2[c*8+:8]) XOR
                                in3[c*8+:8]   XOR         in0[c*8+:8]);
        out2[c*8+:8] = (<a link="func_FFmul02_1" file="shared_pseudocode.xml">FFmul02</a>(in2[c*8+:8])  XOR <a link="func_FFmul03_1" file="shared_pseudocode.xml">FFmul03</a>(in3[c*8+:8]) XOR
                                in0[c*8+:8]   XOR         in1[c*8+:8]);
        out3[c*8+:8] = (<a link="func_FFmul02_1" file="shared_pseudocode.xml">FFmul02</a>(in3[c*8+:8])  XOR <a link="func_FFmul03_1" file="shared_pseudocode.xml">FFmul03</a>(in0[c*8+:8]) XOR
                                in1[c*8+:8]   XOR         in2[c*8+:8]);
    end;

    return (
        out3[3*8+:8] :: out2[3*8+:8] :: out1[3*8+:8] :: out0[3*8+:8] ::
        out3[2*8+:8] :: out2[2*8+:8] :: out1[2*8+:8] :: out0[2*8+:8] ::
        out3[1*8+:8] :: out2[1*8+:8] :: out1[1*8+:8] :: out0[1*8+:8] ::
        out3[0*8+:8] :: out2[0*8+:8] :: out1[0*8+:8] :: out0[0*8+:8]
    );
end;</pstext></ps>
    <ps name="shared/functions/crypto/AESShiftRows" mylink="shared.functions.crypto.AESShiftRows" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AESShiftRows()
// ==============
// Transformation in the Cipher that processes the State by cyclically
// shifting the last three rows of the State by different offsets.

func <anchor link="func_AESShiftRows_1">AESShiftRows</anchor>(op : bits(128)) =&gt; bits(128)
begin
    return (
        op[ 95: 88] :: op[ 55: 48] :: op[ 15:  8] :: op[103: 96] ::
        op[ 63: 56] :: op[ 23: 16] :: op[111:104] :: op[ 71: 64] ::
        op[ 31: 24] :: op[119:112] :: op[ 79: 72] :: op[ 39: 32] ::
        op[127:120] :: op[ 87: 80] :: op[ 47: 40] :: op[  7:  0]
    );
end;</pstext></ps>
    <ps name="shared/functions/crypto/AESSubBytes" mylink="shared.functions.crypto.AESSubBytes" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AESSubBytes()
// =============
// Transformation in the Cipher that processes the State using a nonlinear
// byte substitution table (S-box) that operates on each of the State bytes
// independently.

func <anchor link="func_AESSubBytes_1">AESSubBytes</anchor>(op : bits(128)) =&gt; bits(128)
begin
    // S-box values
    let GF2 : bits(16*16*8) = (
        /*       F E D C B A 9 8 7 6 5 4 3 2 1 0       */
        /*F*/ 0x16bb54b00f2d99416842e6bf0d89a18c[127:0] ::
        /*E*/ 0xdf2855cee9871e9b948ed9691198f8e1[127:0] ::
        /*D*/ 0x9e1dc186b95735610ef6034866b53e70[127:0] ::
        /*C*/ 0x8a8bbd4b1f74dde8c6b4a61c2e2578ba[127:0] ::
        /*B*/ 0x08ae7a65eaf4566ca94ed58d6d37c8e7[127:0] ::
        /*A*/ 0x79e4959162acd3c25c2406490a3a32e0[127:0] ::
        /*9*/ 0xdb0b5ede14b8ee4688902a22dc4f8160[127:0] ::
        /*8*/ 0x73195d643d7ea7c41744975fec130ccd[127:0] ::
        /*7*/ 0xd2f3ff1021dab6bcf5389d928f40a351[127:0] ::
        /*6*/ 0xa89f3c507f02f94585334d43fbaaefd0[127:0] ::
        /*5*/ 0xcf584c4a39becb6a5bb1fc20ed00d153[127:0] ::
        /*4*/ 0x842fe329b3d63b52a05a6e1b1a2c8309[127:0] ::
        /*3*/ 0x75b227ebe28012079a059618c323c704[127:0] ::
        /*2*/ 0x1531d871f1e5a534ccf73f362693fdb7[127:0] ::
        /*1*/ 0xc072a49cafa2d4adf04759fa7dc982ca[127:0] ::
        /*0*/ 0x76abd7fe2b670130c56f6bf27b777c63[127:0]
    );
    var out : bits(128);
    for i = 0 to 15 do
        out[i*8+:8] = GF2[UInt(op[i*8+:8])*8+:8];
    end;
    return out;
end;</pstext></ps>
    <ps name="shared/functions/crypto/FFmul02" mylink="shared.functions.crypto.FFmul02" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FFmul02()
// =========

func <anchor link="func_FFmul02_1">FFmul02</anchor>(b : bits(8)) =&gt; bits(8)
begin
    let FFmul_02 : bits(256*8) = (
        /*       F E D C B A 9 8 7 6 5 4 3 2 1 0       */
        /*F*/ 0xE5E7E1E3EDEFE9EBF5F7F1F3FDFFF9FB[127:0] ::
        /*E*/ 0xC5C7C1C3CDCFC9CBD5D7D1D3DDDFD9DB[127:0] ::
        /*D*/ 0xA5A7A1A3ADAFA9ABB5B7B1B3BDBFB9BB[127:0] ::
        /*C*/ 0x858781838D8F898B959791939D9F999B[127:0] ::
        /*B*/ 0x656761636D6F696B757771737D7F797B[127:0] ::
        /*A*/ 0x454741434D4F494B555751535D5F595B[127:0] ::
        /*9*/ 0x252721232D2F292B353731333D3F393B[127:0] ::
        /*8*/ 0x050701030D0F090B151711131D1F191B[127:0] ::
        /*7*/ 0xFEFCFAF8F6F4F2F0EEECEAE8E6E4E2E0[127:0] ::
        /*6*/ 0xDEDCDAD8D6D4D2D0CECCCAC8C6C4C2C0[127:0] ::
        /*5*/ 0xBEBCBAB8B6B4B2B0AEACAAA8A6A4A2A0[127:0] ::
        /*4*/ 0x9E9C9A98969492908E8C8A8886848280[127:0] ::
        /*3*/ 0x7E7C7A78767472706E6C6A6866646260[127:0] ::
        /*2*/ 0x5E5C5A58565452504E4C4A4846444240[127:0] ::
        /*1*/ 0x3E3C3A38363432302E2C2A2826242220[127:0] ::
        /*0*/ 0x1E1C1A18161412100E0C0A0806040200[127:0]
    );
    return FFmul_02[UInt(b)*8+:8];
end;</pstext></ps>
    <ps name="shared/functions/crypto/FFmul03" mylink="shared.functions.crypto.FFmul03" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FFmul03()
// =========

func <anchor link="func_FFmul03_1">FFmul03</anchor>(b : bits(8)) =&gt; bits(8)
begin
    let FFmul_03 : bits(256*8) = (
        /*       F E D C B A 9 8 7 6 5 4 3 2 1 0       */
        /*F*/ 0x1A191C1F16151013020104070E0D080B[127:0] ::
        /*E*/ 0x2A292C2F26252023323134373E3D383B[127:0] ::
        /*D*/ 0x7A797C7F76757073626164676E6D686B[127:0] ::
        /*C*/ 0x4A494C4F46454043525154575E5D585B[127:0] ::
        /*B*/ 0xDAD9DCDFD6D5D0D3C2C1C4C7CECDC8CB[127:0] ::
        /*A*/ 0xEAE9ECEFE6E5E0E3F2F1F4F7FEFDF8FB[127:0] ::
        /*9*/ 0xBAB9BCBFB6B5B0B3A2A1A4A7AEADA8AB[127:0] ::
        /*8*/ 0x8A898C8F86858083929194979E9D989B[127:0] ::
        /*7*/ 0x818287848D8E8B88999A9F9C95969390[127:0] ::
        /*6*/ 0xB1B2B7B4BDBEBBB8A9AAAFACA5A6A3A0[127:0] ::
        /*5*/ 0xE1E2E7E4EDEEEBE8F9FAFFFCF5F6F3F0[127:0] ::
        /*4*/ 0xD1D2D7D4DDDEDBD8C9CACFCCC5C6C3C0[127:0] ::
        /*3*/ 0x414247444D4E4B48595A5F5C55565350[127:0] ::
        /*2*/ 0x717277747D7E7B78696A6F6C65666360[127:0] ::
        /*1*/ 0x212227242D2E2B28393A3F3C35363330[127:0] ::
        /*0*/ 0x111217141D1E1B18090A0F0C05060300[127:0]
    );
    return FFmul_03[UInt(b)*8+:8];
end;</pstext></ps>
    <ps name="shared/functions/crypto/FFmul09" mylink="shared.functions.crypto.FFmul09" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FFmul09()
// =========

func <anchor link="func_FFmul09_1">FFmul09</anchor>(b : bits(8)) =&gt; bits(8)
begin
    let FFmul_09 : bits(256*8) = (
        /*       F E D C B A 9 8 7 6 5 4 3 2 1 0       */
        /*F*/ 0x464F545D626B70790E071C152A233831[127:0] ::
        /*E*/ 0xD6DFC4CDF2FBE0E99E978C85BAB3A8A1[127:0] ::
        /*D*/ 0x7D746F6659504B42353C272E1118030A[127:0] ::
        /*C*/ 0xEDE4FFF6C9C0DBD2A5ACB7BE8188939A[127:0] ::
        /*B*/ 0x3039222B141D060F78716A635C554E47[127:0] ::
        /*A*/ 0xA0A9B2BB848D969FE8E1FAF3CCC5DED7[127:0] ::
        /*9*/ 0x0B0219102F263D34434A5158676E757C[127:0] ::
        /*8*/ 0x9B928980BFB6ADA4D3DAC1C8F7FEE5EC[127:0] ::
        /*7*/ 0xAAA3B8B18E879C95E2EBF0F9C6CFD4DD[127:0] ::
        /*6*/ 0x3A3328211E170C05727B6069565F444D[127:0] ::
        /*5*/ 0x9198838AB5BCA7AED9D0CBC2FDF4EFE6[127:0] ::
        /*4*/ 0x0108131A252C373E49405B526D647F76[127:0] ::
        /*3*/ 0xDCD5CEC7F8F1EAE3949D868FB0B9A2AB[127:0] ::
        /*2*/ 0x4C455E5768617A73040D161F2029323B[127:0] ::
        /*1*/ 0xE7EEF5FCC3CAD1D8AFA6BDB48B829990[127:0] ::
        /*0*/ 0x777E656C535A41483F362D241B120900[127:0]
    );
    return FFmul_09[UInt(b)*8+:8];
end;</pstext></ps>
    <ps name="shared/functions/crypto/FFmul0B" mylink="shared.functions.crypto.FFmul0B" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FFmul0B()
// =========

func <anchor link="func_FFmul0B_1">FFmul0B</anchor>(b : bits(8)) =&gt; bits(8)
begin
    let FFmul_0B : bits(256*8) = (
        /*       F E D C B A 9 8 7 6 5 4 3 2 1 0       */
        /*F*/ 0xA3A8B5BE8F849992FBF0EDE6D7DCC1CA[127:0] ::
        /*E*/ 0x1318050E3F3429224B405D56676C717A[127:0] ::
        /*D*/ 0xD8D3CEC5F4FFE2E9808B969DACA7BAB1[127:0] ::
        /*C*/ 0x68637E75444F5259303B262D1C170A01[127:0] ::
        /*B*/ 0x555E434879726F640D061B10212A373C[127:0] ::
        /*A*/ 0xE5EEF3F8C9C2DFD4BDB6ABA0919A878C[127:0] ::
        /*9*/ 0x2E2538330209141F767D606B5A514C47[127:0] ::
        /*8*/ 0x9E958883B2B9A4AFC6CDD0DBEAE1FCF7[127:0] ::
        /*7*/ 0x545F424978736E650C071A11202B363D[127:0] ::
        /*6*/ 0xE4EFF2F9C8C3DED5BCB7AAA1909B868D[127:0] ::
        /*5*/ 0x2F2439320308151E777C616A5B504D46[127:0] ::
        /*4*/ 0x9F948982B3B8A5AEC7CCD1DAEBE0FDF6[127:0] ::
        /*3*/ 0xA2A9B4BF8E859893FAF1ECE7D6DDC0CB[127:0] ::
        /*2*/ 0x1219040F3E3528234A415C57666D707B[127:0] ::
        /*1*/ 0xD9D2CFC4F5FEE3E8818A979CADA6BBB0[127:0] ::
        /*0*/ 0x69627F74454E5358313A272C1D160B00[127:0]
    );
    return FFmul_0B[UInt(b)*8+:8];
end;</pstext></ps>
    <ps name="shared/functions/crypto/FFmul0D" mylink="shared.functions.crypto.FFmul0D" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FFmul0D()
// =========

func <anchor link="func_FFmul0D_1">FFmul0D</anchor>(b : bits(8)) =&gt; bits(8)
begin
    let FFmul_0D : bits(256*8) = (
        /*       F E D C B A 9 8 7 6 5 4 3 2 1 0       */
        /*F*/ 0x979A8D80A3AEB9B4FFF2E5E8CBC6D1DC[127:0] ::
        /*E*/ 0x474A5D50737E69642F2235381B16010C[127:0] ::
        /*D*/ 0x2C21363B1815020F44495E53707D6A67[127:0] ::
        /*C*/ 0xFCF1E6EBC8C5D2DF94998E83A0ADBAB7[127:0] ::
        /*B*/ 0xFAF7E0EDCEC3D4D9929F8885A6ABBCB1[127:0] ::
        /*A*/ 0x2A27303D1E130409424F5855767B6C61[127:0] ::
        /*9*/ 0x414C5B5675786F622924333E1D10070A[127:0] ::
        /*8*/ 0x919C8B86A5A8BFB2F9F4E3EECDC0D7DA[127:0] ::
        /*7*/ 0x4D40575A7974636E25283F32111C0B06[127:0] ::
        /*6*/ 0x9D90878AA9A4B3BEF5F8EFE2C1CCDBD6[127:0] ::
        /*5*/ 0xF6FBECE1C2CFD8D59E938489AAA7B0BD[127:0] ::
        /*4*/ 0x262B3C31121F08054E4354597A77606D[127:0] ::
        /*3*/ 0x202D3A3714190E034845525F7C71666B[127:0] ::
        /*2*/ 0xF0FDEAE7C4C9DED39895828FACA1B6BB[127:0] ::
        /*1*/ 0x9B96818CAFA2B5B8F3FEE9E4C7CADDD0[127:0] ::
        /*0*/ 0x4B46515C7F726568232E3934171A0D00[127:0]
    );
    return FFmul_0D[UInt(b)*8+:8];
end;</pstext></ps>
    <ps name="shared/functions/crypto/FFmul0E" mylink="shared.functions.crypto.FFmul0E" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FFmul0E()
// =========

func <anchor link="func_FFmul0E_1">FFmul0E</anchor>(b : bits(8)) =&gt; bits(8)
begin
    let FFmul_0E : bits(256*8) = (
        /*       F E D C B A 9 8 7 6 5 4 3 2 1 0       */
        /*F*/ 0x8D83919FB5BBA9A7FDF3E1EFC5CBD9D7[127:0] ::
        /*E*/ 0x6D63717F555B49471D13010F252B3937[127:0] ::
        /*D*/ 0x56584A446E60727C26283A341E10020C[127:0] ::
        /*C*/ 0xB6B8AAA48E80929CC6C8DAD4FEF0E2EC[127:0] ::
        /*B*/ 0x202E3C321816040A505E4C426866747A[127:0] ::
        /*A*/ 0xC0CEDCD2F8F6E4EAB0BEACA28886949A[127:0] ::
        /*9*/ 0xFBF5E7E9C3CDDFD18B859799B3BDAFA1[127:0] ::
        /*8*/ 0x1B150709232D3F316B657779535D4F41[127:0] ::
        /*7*/ 0xCCC2D0DEF4FAE8E6BCB2A0AE848A9896[127:0] ::
        /*6*/ 0x2C22303E141A08065C52404E646A7876[127:0] ::
        /*5*/ 0x17190B052F21333D67697B755F51434D[127:0] ::
        /*4*/ 0xF7F9EBE5CFC1D3DD87899B95BFB1A3AD[127:0] ::
        /*3*/ 0x616F7D735957454B111F0D032927353B[127:0] ::
        /*2*/ 0x818F9D93B9B7A5ABF1FFEDE3C9C7D5DB[127:0] ::
        /*1*/ 0xBAB4A6A8828C9E90CAC4D6D8F2FCEEE0[127:0] ::
        /*0*/ 0x5A544648626C7E702A243638121C0E00[127:0]
    );
    return FFmul_0E[UInt(b)*8+:8];
end;</pstext></ps>
    <ps name="shared/functions/crypto/SHA256hash" mylink="shared.functions.crypto.SHA256hash" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SHA256hash()
// ============

func <anchor link="func_SHA256hash_4">SHA256hash</anchor>(x_in : bits (128), y_in : bits(128), w : bits(128), part1 : boolean) =&gt; bits(128)
begin
    var chs, maj, t : bits(32);
    var x : bits(128) = x_in;
    var y : bits(128) = y_in;

    for e = 0 to 3 do
        chs = <a link="func_SHAchoose_3" file="shared_pseudocode.xml">SHAchoose</a>(y[31:0], y[63:32], y[95:64]);
        maj = <a link="func_SHAmajority_4" file="shared_pseudocode.xml">SHAmajority</a>{32}(x[31:0], x[63:32], x[95:64]);
        t   = y[127:96] + <a link="func_SHA256hashSIGMA1_1" file="shared_pseudocode.xml">SHA256hashSIGMA1</a>(y[31:0]) + chs + w[e*:32];
        x[127:96] = t + x[127:96];
        y[127:96] = t + <a link="func_SHA256hashSIGMA0_1" file="shared_pseudocode.xml">SHA256hashSIGMA0</a>(x[31:0]) + maj;
        let yx : bits(256) = ROL(y :: x, 32);
        (y, x) = (yx[128+:128], yx[0+:128]);
    end;
    return (if part1 then x else y);
end;</pstext></ps>
    <ps name="shared/functions/crypto/SHA256hashSIGMA0" mylink="shared.functions.crypto.SHA256hashSIGMA0" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SHA256hashSIGMA0()
// ==================

func <anchor link="func_SHA256hashSIGMA0_1">SHA256hashSIGMA0</anchor>(x : bits(32)) =&gt; bits(32)
begin
    return ROR(x, 2) XOR ROR(x, 13) XOR ROR(x, 22);
end;</pstext></ps>
    <ps name="shared/functions/crypto/SHA256hashSIGMA1" mylink="shared.functions.crypto.SHA256hashSIGMA1" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SHA256hashSIGMA1()
// ==================

func <anchor link="func_SHA256hashSIGMA1_1">SHA256hashSIGMA1</anchor>(x : bits(32)) =&gt; bits(32)
begin
    return ROR(x, 6) XOR ROR(x, 11) XOR ROR(x, 25);
end;</pstext></ps>
    <ps name="shared/functions/crypto/SHAchoose" mylink="shared.functions.crypto.SHAchoose" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SHAchoose()
// ===========
func <anchor link="func_SHAchoose_3">SHAchoose</anchor>(x : bits(32), y : bits(32), z : bits(32)) =&gt; bits(32)
begin
    return (((y XOR z) AND x) XOR z);
end;</pstext></ps>
    <ps name="shared/functions/crypto/SHAmajority" mylink="shared.functions.crypto.SHAmajority" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SHAmajority()
// =============

func <anchor link="func_SHAmajority_4">SHAmajority</anchor>{N}(x : bits(N), y : bits(N), z : bits(N)) =&gt; bits(N)
begin
    assert N IN {32, 64};
    return ((x AND y) OR ((x OR y) AND z));
end;</pstext></ps>
    <ps name="shared/functions/crypto/SHAparity" mylink="shared.functions.crypto.SHAparity" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SHAparity()
// ===========

func <anchor link="func_SHAparity_3">SHAparity</anchor>(x : bits(32), y : bits(32), z : bits(32)) =&gt; bits(32)
begin
    return (x XOR y XOR z);
end;</pstext></ps>
    <ps name="shared/functions/crypto/Sbox" mylink="shared.functions.crypto.Sbox" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Sbox()
// ======
// Used in SM4E crypto instruction

func <anchor link="func_Sbox_1">Sbox</anchor>(sboxin : bits(8)) =&gt; bits(8)
begin
    var sboxout : bits(8);
    let sboxstring : bits(2048) = (
        /*       F E D C B A 9 8 7 6 5 4 3 2 1 0       */
        /*F*/ 0xd690e9fecce13db716b614c228fb2c05[127:0] ::
        /*E*/ 0x2b679a762abe04c3aa44132649860699[127:0] ::
        /*D*/ 0x9c4250f491ef987a33540b43edcfac62[127:0] ::
        /*C*/ 0xe4b31ca9c908e89580df94fa758f3fa6[127:0] ::
        /*B*/ 0x4707a7fcf37317ba83593c19e6854fa8[127:0] ::
        /*A*/ 0x686b81b27164da8bf8eb0f4b70569d35[127:0] ::
        /*9*/ 0x1e240e5e6358d1a225227c3b01217887[127:0] ::
        /*8*/ 0xd40046579fd327524c3602e7a0c4c89e[127:0] ::
        /*7*/ 0xeabf8ad240c738b5a3f7f2cef96115a1[127:0] ::
        /*6*/ 0xe0ae5da49b341a55ad933230f58cb1e3[127:0] ::
        /*5*/ 0x1df6e22e8266ca60c02923ab0d534e6f[127:0] ::
        /*4*/ 0xd5db3745defd8e2f03ff6a726d6c5b51[127:0] ::
        /*3*/ 0x8d1baf92bbddbc7f11d95c411f105ad8[127:0] ::
        /*2*/ 0x0ac13188a5cd7bbd2d74d012b8e5b4b0[127:0] ::
        /*1*/ 0x8969974a0c96777e65b9f109c56ec684[127:0] ::
        /*0*/ 0x18f07dec3adc4d2079ee5f3ed7cb3948[127:0]
    );
    let sboxindex : integer = 255 - UInt(sboxin);
    sboxout = sboxstring[sboxindex*:8];
    return sboxout;
end;</pstext></ps>
    <ps name="shared/functions/decode/DecodeType" mylink="shared.functions.decode.DecodeType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodeType
// ==========

type <anchor link="type_DecodeType">DecodeType</anchor> of enumeration {
    <anchor link="enum_Decode_UNDEF">Decode_UNDEF</anchor>,
    <anchor link="enum_Decode_NOP">Decode_NOP</anchor>,
    <anchor link="enum_Decode_OK">Decode_OK</anchor>
};</pstext></ps>
    <ps name="shared/functions/decode/EndOfDecode" mylink="shared.functions.decode.EndOfDecode" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EndOfDecode()
// =============
// This function is invoked to end the Decode phase and performs Branch target Checks
// before taking any UNDEFINED exceptions, NOPs, or continuing to execute.

func <anchor link="func_EndOfDecode_1">EndOfDecode</anchor>(reason : <a link="type_DecodeType" file="shared_pseudocode.xml">DecodeType</a>)
begin
    if IsFeatureImplemented(FEAT_BTI) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        <a link="func_BranchTargetCheck_0" file="shared_pseudocode.xml">BranchTargetCheck</a>();
    end;
    case reason of
        when <a link="enum_Decode_NOP" file="shared_pseudocode.xml">Decode_NOP</a>   =&gt; <a link="func_ExecuteAsNOP_0" file="shared_pseudocode.xml">ExecuteAsNOP</a>();
        when <a link="enum_Decode_UNDEF" file="shared_pseudocode.xml">Decode_UNDEF</a> =&gt; Undefined();
        when <a link="enum_Decode_OK" file="shared_pseudocode.xml">Decode_OK</a>    =&gt; pass;          // Continue to execute.
    end;
    return;
end;</pstext></ps>
    <ps name="shared/functions/exclusive/ClearExclusiveByAddress" mylink="shared.functions.exclusive.ClearExclusiveByAddress" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ClearExclusiveByAddress()
// =========================
// Clear the global Exclusives monitors for all PEs EXCEPT processorid if they
// record any part of the physical address region of size bytes starting at paddress.
// It is IMPLEMENTATION DEFINED whether the global Exclusives monitor for processorid
// is also cleared if it records any part of the address region.

impdef func ClearExclusiveByAddress(paddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>,
                                    processorid : integer,
                                    size : integer)
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/exclusive/ClearExclusiveLocal" mylink="shared.functions.exclusive.ClearExclusiveLocal" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ClearExclusiveLocal()
// =====================
// Clear the local Exclusives monitor for the specified processorid.

impdef func ClearExclusiveLocal(processorid : integer)
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/exclusive/ExclusiveMonitorsStatus" mylink="shared.functions.exclusive.ExclusiveMonitorsStatus" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExclusiveMonitorsStatus()
// =========================
// Returns '0' to indicate success if the last memory write by this PE was to
// the same physical address region endorsed by ExclusiveMonitorsPass().
// Returns '1' to indicate failure if address translation resulted in a different
// physical address.

impdef func <anchor link="func_ExclusiveMonitorsStatus_0">ExclusiveMonitorsStatus</anchor>() =&gt; bit
begin
    return '0';
end;</pstext></ps>
    <ps name="shared/functions/exclusive/IsExclusiveGlobal" mylink="shared.functions.exclusive.IsExclusiveGlobal" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsExclusiveGlobal()
// ===================
// Return TRUE if the global Exclusives monitor for processorid includes all of
// the physical address region of size bytes starting at paddress.


impdef func <anchor link="func_IsExclusiveGlobal_3">IsExclusiveGlobal</anchor>(paddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>,
                              processorid : integer,
                              size : integer) =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="shared/functions/exclusive/IsExclusiveLocal" mylink="shared.functions.exclusive.IsExclusiveLocal" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsExclusiveLocal()
// ==================
// Return TRUE if the local Exclusives monitor for processorid includes all of
// the physical address region of size bytes starting at paddress.

impdef func <anchor link="func_IsExclusiveLocal_3">IsExclusiveLocal</anchor>(paddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>, processorid : integer,
                             size : integer) =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="shared/functions/exclusive/MarkExclusiveGlobal" mylink="shared.functions.exclusive.MarkExclusiveGlobal" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MarkExclusiveGlobal()
// =====================
// Record the physical address region of size bytes starting at paddress in
// the global Exclusives monitor for processorid.

impdef func MarkExclusiveGlobal(paddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>,
                                processorid : integer,
                                size : integer)
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/exclusive/MarkExclusiveLocal" mylink="shared.functions.exclusive.MarkExclusiveLocal" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MarkExclusiveLocal()
// ====================
// Record the physical address region of size bytes starting at paddress in
// the local Exclusives monitor for processorid.

impdef func MarkExclusiveLocal(paddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>, processorid : integer, size : integer)
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/exclusive/ProcessorID" mylink="shared.functions.exclusive.ProcessorID" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ProcessorID()
// =============
// Return the ID of the currently executing PE.

impdef func <anchor link="func_ProcessorID_0">ProcessorID</anchor>() =&gt; integer
begin
    if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then
        return UInt(MPIDR_EL1().Aff3 :: MPIDR_EL1().Aff2 :: MPIDR_EL1().Aff1 :: MPIDR_EL1().Aff0);
    else
        return UInt(MPIDR().Aff2 :: MPIDR().Aff1 :: MPIDR().Aff0);
    end;
end;</pstext></ps>
    <ps name="shared/functions/extension/HaveSoftwareLock" mylink="shared.functions.extension.HaveSoftwareLock" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HaveSoftwareLock()
// ==================
// Returns TRUE if Software Lock is implemented.

func <anchor link="func_HaveSoftwareLock_1">HaveSoftwareLock</anchor>(component : <a link="type_Component" file="shared_pseudocode.xml">Component</a>) =&gt; boolean
begin
    if IsFeatureImplemented(FEAT_Debugv8p4) then
        return FALSE;
    end;
    if IsFeatureImplemented(FEAT_DoPD) &amp;&amp; component != <a link="enum_Component_CTI" file="shared_pseudocode.xml">Component_CTI</a> then
        return FALSE;
    end;
    case component of
        when <a link="enum_Component_ETE" file="shared_pseudocode.xml">Component_ETE</a> =&gt;
            return ImpDefBool(&quot;ETE has Software Lock&quot;);
        when <a link="enum_Component_Debug" file="shared_pseudocode.xml">Component_Debug</a> =&gt;
            return ImpDefBool(&quot;Debug has Software Lock&quot;);
        when <a link="enum_Component_PMU" file="shared_pseudocode.xml">Component_PMU</a> =&gt;
            return ImpDefBool(&quot;PMU has Software Lock&quot;);
        when <a link="enum_Component_CTI" file="shared_pseudocode.xml">Component_CTI</a> =&gt;
            return ImpDefBool(&quot;CTI has Software Lock&quot;);
        otherwise =&gt;
            unreachable;
    end;
end;</pstext></ps>
    <ps name="shared/functions/extension/HaveTraceExt" mylink="shared.functions.extension.HaveTraceExt" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HaveTraceExt()
// ==============
// Returns TRUE if Trace functionality as described by the Trace Architecture
// is implemented.

readonly func <anchor link="func_HaveTraceExt_0">HaveTraceExt</anchor>() =&gt; boolean
begin
    return IsFeatureImplemented(FEAT_ETE) || IsFeatureImplemented(FEAT_ETMv4);
end;</pstext></ps>
    <ps name="shared/functions/extension/InsertIESBBeforeException" mylink="shared.functions.extension.InsertIESBBeforeException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// InsertIESBBeforeException()
// ===========================
// Returns an implementation defined choice whether to insert an implicit error synchronization
// barrier before exception.
// If SCTLR_ELx.IESB is 1 when an exception is generated to ELx, any pending Unrecoverable
// SError interrupt must be taken before executing any instructions in the exception handler.
// However, this can be before the branch to the exception handler is made.

func <anchor link="func_InsertIESBBeforeException_1">InsertIESBBeforeException</anchor>(el : bits(2)) =&gt; boolean
begin
    return (IsFeatureImplemented(FEAT_IESB) &amp;&amp; ImpDefBool(
            &quot;Has Implicit Error Synchronization Barrier before Exception&quot;));
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/ActionRequired" mylink="shared.functions.externalaborts.ActionRequired" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ActionRequired()
// ================
// Return an implementation specific value:
// returns TRUE if action is required, FALSE otherwise.

impdef func <anchor link="func_ActionRequired_0">ActionRequired</anchor>() =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/ClearPendingDelegatedSError" mylink="shared.functions.externalaborts.ClearPendingDelegatedSError" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ClearPendingDelegatedSError()
// =============================
// Clear a pending delegated SError interrupt.

func <anchor link="func_ClearPendingDelegatedSError_0">ClearPendingDelegatedSError</anchor>()
begin
    assert IsFeatureImplemented(FEAT_E3DSE);
    SCR_EL3().DSE = '0';
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/ClearPendingPhysicalSError" mylink="shared.functions.externalaborts.ClearPendingPhysicalSError" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ClearPendingPhysicalSError()
// ============================
// Clear a pending physical SError interrupt.

impdef func ClearPendingPhysicalSError()
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/ClearPendingVirtualSError" mylink="shared.functions.externalaborts.ClearPendingVirtualSError" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ClearPendingVirtualSError()
// ===========================
// Clear a pending virtual SError interrupt.

func <anchor link="func_ClearPendingVirtualSError_0">ClearPendingVirtualSError</anchor>()
begin
    if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        HCR().VA      = '0';
    else
        HCR_EL2().VSE = '0';
    end;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/ErrorIsContained" mylink="shared.functions.externalaborts.ErrorIsContained" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ErrorIsContained()
// ==================
// Return an implementation specific value:
// TRUE if Error is contained by the PE, FALSE otherwise.

impdef func <anchor link="func_ErrorIsContained_0">ErrorIsContained</anchor>() =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/ErrorIsSynchronized" mylink="shared.functions.externalaborts.ErrorIsSynchronized" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ErrorIsSynchronized()
// =====================
// Return an implementation specific value:
// returns TRUE if Error is synchronized by any synchronization event
// FALSE otherwise.

impdef func <anchor link="func_ErrorIsSynchronized_0">ErrorIsSynchronized</anchor>() =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/ExtAbortToAArch64" mylink="shared.functions.externalaborts.ExtAbortToAArch64" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExtAbortToAArch64()
// ===================
// Returns TRUE if synchronous exception is being taken to an Exception level using AArch64_

func <anchor link="func_ExtAbortToAArch64_1">ExtAbortToAArch64</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; boolean
begin
    assert <a link="func_IsExternalSyncAbort_1" file="shared_pseudocode.xml">IsExternalSyncAbort</a>(fault.statuscode);

    return !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="func_SyncExternalAbortTarget_1" file="shared_pseudocode.xml">SyncExternalAbortTarget</a>(fault));
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/ExternalAbort" mylink="shared.functions.externalaborts.ExternalAbort" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExternalAbort()
// ===============

func <anchor link="func_ExternalAbort_1">ExternalAbort</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) recurselimit 1
begin
    if <a link="func_IsExternalSyncAbort_1" file="shared_pseudocode.xml">IsExternalSyncAbort</a>(fault) then
        if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
            <a link="func_AArch32_Abort_1" file="shared_pseudocode.xml">AArch32_Abort</a>(fault);
        else
            <a link="func_AArch64_Abort_1" file="shared_pseudocode.xml">AArch64_Abort</a>(fault);
        end;

    else
        PendSErrorInterrupt(fault);
    end;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/ExternalFault" mylink="shared.functions.externalaborts.ExternalFault" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExternalFault()
// ===============
// Return a fault recording indicating a fault for a Synchronous/Asynchronous External abort.

func <anchor link="func_ExternalFault_5">ExternalFault</anchor>(memretstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>, iswrite : boolean,
                   memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, size : integer,
                   accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin
    assert (memretstatus.statuscode IN {<a link="enum_Fault_SyncExternal" file="shared_pseudocode.xml">Fault_SyncExternal</a>, <a link="enum_Fault_AsyncExternal" file="shared_pseudocode.xml">Fault_AsyncExternal</a>} ||
           (!IsFeatureImplemented(FEAT_RAS) &amp;&amp; memretstatus.statuscode IN {<a link="enum_Fault_SyncParity" file="shared_pseudocode.xml">Fault_SyncParity</a>,
                                                                           <a link="enum_Fault_AsyncParity" file="shared_pseudocode.xml">Fault_AsyncParity</a>}));

    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_2" file="shared_pseudocode.xml">NoFault</a>(accdesc, memaddrdesc.vaddress);
    fault.statuscode = memretstatus.statuscode;
    fault.write      = iswrite;
    fault.extflag    = memretstatus.extflag;
    // It is implementation specific whether External aborts signaled
    // in-band synchronously are taken synchronously or asynchronously
    if (<a link="func_IsExternalSyncAbort_1" file="shared_pseudocode.xml">IsExternalSyncAbort</a>(fault) &amp;&amp;
          ((IsFeatureImplemented(FEAT_RASv2) &amp;&amp; <a link="func_ExtAbortToAArch64_1" file="shared_pseudocode.xml">ExtAbortToAArch64</a>(fault) &amp;&amp;
            <a link="func_PEErrorState_1" file="shared_pseudocode.xml">PEErrorState</a>(fault) IN {<a link="enum_ErrorState_UC" file="shared_pseudocode.xml">ErrorState_UC</a>, <a link="enum_ErrorState_UEU" file="shared_pseudocode.xml">ErrorState_UEU</a>}) ||
           !<a link="func_IsExternalAbortTakenSynchronously_5" file="shared_pseudocode.xml">IsExternalAbortTakenSynchronously</a>(memretstatus, iswrite, memaddrdesc,
                                              size, accdesc))) then
        if fault.statuscode == <a link="enum_Fault_SyncParity" file="shared_pseudocode.xml">Fault_SyncParity</a> then
            fault.statuscode = <a link="enum_Fault_AsyncParity" file="shared_pseudocode.xml">Fault_AsyncParity</a>;
        else
            fault.statuscode = <a link="enum_Fault_AsyncExternal" file="shared_pseudocode.xml">Fault_AsyncExternal</a>;
        end;
    end;

    if IsFeatureImplemented(FEAT_RAS) then
        fault.merrorstate = memretstatus.merrorstate;
    end;
    fault.paddress = memaddrdesc.paddress;
    return fault;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/FaultIsCorrected" mylink="shared.functions.externalaborts.FaultIsCorrected" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FaultIsCorrected()
// ==================
// Return an implementation specific value:
// TRUE if fault is corrected by the PE, FALSE otherwise.

readonly impdef func <anchor link="func_FaultIsCorrected_0">FaultIsCorrected</anchor>() =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/GetPendingPhysicalSError" mylink="shared.functions.externalaborts.GetPendingPhysicalSError" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetPendingPhysicalSError()
// ==========================
// Returns the FaultRecord containing details of pending Physical SError
// interrupt.

impdef func <anchor link="func_GetPendingPhysicalSError_0">GetPendingPhysicalSError</anchor>() =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin
    return ARBITRARY : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/HandleExternalAbort" mylink="shared.functions.externalaborts.HandleExternalAbort" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HandleExternalAbort()
// =====================
// Takes a Synchronous/Asynchronous abort based on fault.

func <anchor link="func_HandleExternalAbort_5">HandleExternalAbort</anchor>(memretstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>, iswrite : boolean,
                         memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, size : integer,
                         accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>)
begin
    assert (memretstatus.statuscode IN {<a link="enum_Fault_SyncExternal" file="shared_pseudocode.xml">Fault_SyncExternal</a>, <a link="enum_Fault_AsyncExternal" file="shared_pseudocode.xml">Fault_AsyncExternal</a>} ||
           (!IsFeatureImplemented(FEAT_RAS) &amp;&amp; memretstatus.statuscode IN {<a link="enum_Fault_SyncParity" file="shared_pseudocode.xml">Fault_SyncParity</a>,
                                                                           <a link="enum_Fault_AsyncParity" file="shared_pseudocode.xml">Fault_AsyncParity</a>}));

    let fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_ExternalFault_5" file="shared_pseudocode.xml">ExternalFault</a>(memretstatus, iswrite, memaddrdesc, size, accdesc);
    <a link="func_ExternalAbort_1" file="shared_pseudocode.xml">ExternalAbort</a>(fault);
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/HandleExternalReadAbort" mylink="shared.functions.externalaborts.HandleExternalReadAbort" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HandleExternalReadAbort()
// =========================
// Wrapper function for HandleExternalAbort function in case of an External
// Abort on memory read.

func <anchor link="func_HandleExternalReadAbort_4">HandleExternalReadAbort</anchor>(memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>, memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                             size : integer, accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>)
begin
    let iswrite : boolean = FALSE;
    <a link="func_HandleExternalAbort_5" file="shared_pseudocode.xml">HandleExternalAbort</a>(memstatus, iswrite, memaddrdesc, size, accdesc);
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/HandleExternalTTWAbort" mylink="shared.functions.externalaborts.HandleExternalTTWAbort" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HandleExternalTTWAbort()
// ========================
// Take Asynchronous abort or update FaultRecord for Translation Table Walk
// based on PhysMemRetStatus.

func <anchor link="func_HandleExternalTTWAbort_6">HandleExternalTTWAbort</anchor>(memretstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>, iswrite : boolean,
                            memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                            accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>, size : integer,
                            input_fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin
    var output_fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = input_fault;
    output_fault.extflag    = memretstatus.extflag;
    output_fault.statuscode = memretstatus.statuscode;
    if (<a link="func_IsExternalSyncAbort_1" file="shared_pseudocode.xml">IsExternalSyncAbort</a>(output_fault) &amp;&amp;
          ((IsFeatureImplemented(FEAT_RASv2) &amp;&amp; <a link="func_ExtAbortToAArch64_1" file="shared_pseudocode.xml">ExtAbortToAArch64</a>(output_fault) &amp;&amp;
            <a link="func_PEErrorState_1" file="shared_pseudocode.xml">PEErrorState</a>(output_fault) IN {<a link="enum_ErrorState_UC" file="shared_pseudocode.xml">ErrorState_UC</a>, <a link="enum_ErrorState_UEU" file="shared_pseudocode.xml">ErrorState_UEU</a>}) ||
           !<a link="func_IsExternalAbortTakenSynchronously_5" file="shared_pseudocode.xml">IsExternalAbortTakenSynchronously</a>(memretstatus, iswrite, memaddrdesc,
                                              size, accdesc))) then
        if output_fault.statuscode == <a link="enum_Fault_SyncParity" file="shared_pseudocode.xml">Fault_SyncParity</a> then
            output_fault.statuscode = <a link="enum_Fault_AsyncParity" file="shared_pseudocode.xml">Fault_AsyncParity</a>;
        else
            output_fault.statuscode = <a link="enum_Fault_AsyncExternal" file="shared_pseudocode.xml">Fault_AsyncExternal</a>;
        end;
    end;

    // If a synchronous fault is on a translation table walk, then update the fault type.
    if <a link="func_IsExternalSyncAbort_1" file="shared_pseudocode.xml">IsExternalSyncAbort</a>(output_fault) then
        if output_fault.statuscode == <a link="enum_Fault_SyncParity" file="shared_pseudocode.xml">Fault_SyncParity</a> then
            output_fault.statuscode = <a link="enum_Fault_SyncParityOnWalk" file="shared_pseudocode.xml">Fault_SyncParityOnWalk</a>;
        else
            output_fault.statuscode = <a link="enum_Fault_SyncExternalOnWalk" file="shared_pseudocode.xml">Fault_SyncExternalOnWalk</a>;
        end;
    end;
    if IsFeatureImplemented(FEAT_RAS) then
        output_fault.merrorstate = memretstatus.merrorstate;
    end;
    if !<a link="func_IsExternalSyncAbort_1" file="shared_pseudocode.xml">IsExternalSyncAbort</a>(output_fault) then
        PendSErrorInterrupt(output_fault);
        output_fault.statuscode = <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;
    end;
    output_fault.paddress = memaddrdesc.paddress;
    return output_fault;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/HandleExternalWriteAbort" mylink="shared.functions.externalaborts.HandleExternalWriteAbort" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HandleExternalWriteAbort()
// ==========================
// Wrapper function for HandleExternalAbort function in case of an External
// Abort on memory write.

func <anchor link="func_HandleExternalWriteAbort_4">HandleExternalWriteAbort</anchor>(memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>, memaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                              size : integer, accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>)
begin
    let iswrite : boolean = TRUE;
    <a link="func_HandleExternalAbort_5" file="shared_pseudocode.xml">HandleExternalAbort</a>(memstatus, iswrite, memaddrdesc, size, accdesc);
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/IsDelegatedSErrorPending" mylink="shared.functions.externalaborts.IsDelegatedSErrorPending" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsDelegatedSErrorPending()
// ==========================
// Return TRUE if a delegated SError interrupt is pending.

func <anchor link="func_IsDelegatedSErrorPending_0">IsDelegatedSErrorPending</anchor>() =&gt; boolean
begin
    return SCR_EL3().DSE == '1';
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/IsExternalAbortTakenSynchronously" mylink="shared.functions.externalaborts.IsExternalAbortTakenSynchronously" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsExternalAbortTakenSynchronously()
// ===================================
// Return an implementation specific value:
// TRUE if the fault returned for the access can be taken synchronously,
// FALSE otherwise.
//
// This might vary between accesses, for example depending on the error type
// or memory type being accessed.
// External aborts on data accesses and translation table walks on data accesses
// can be either synchronous or asynchronous.
//
// When FEAT_DoubleFault is not implemented, External aborts on instruction
// fetches and translation table walks on instruction fetches can be either
// synchronous or asynchronous.
// When FEAT_DoubleFault is implemented, all External abort exceptions on
// instruction fetches and translation table walks on instruction fetches
// must be synchronous.


impdef func <anchor link="func_IsExternalAbortTakenSynchronously_5">IsExternalAbortTakenSynchronously</anchor>(memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>, iswrite : boolean,
                                              desc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, size : integer,
                                              accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/IsPhysicalSErrorPending" mylink="shared.functions.externalaborts.IsPhysicalSErrorPending" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsPhysicalSErrorPending()
// =========================
// Returns TRUE if a physical SError interrupt is pending.

impdef func <anchor link="func_IsPhysicalSErrorPending_0">IsPhysicalSErrorPending</anchor>() =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/IsSErrorEdgeTriggered" mylink="shared.functions.externalaborts.IsSErrorEdgeTriggered" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsSErrorEdgeTriggered()
// =======================
// Returns TRUE if the physical SError interrupt is edge-triggered
// and FALSE otherwise.

func <anchor link="func_IsSErrorEdgeTriggered_0">IsSErrorEdgeTriggered</anchor>() =&gt; boolean
begin
    if IsFeatureImplemented(FEAT_DoubleFault) then
        return TRUE;
    else
        return ImpDefBool(&quot;Edge-triggered SError&quot;);
    end;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/IsSynchronizablePhysicalSErrorPending" mylink="shared.functions.externalaborts.IsSynchronizablePhysicalSErrorPending" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsSynchronizablePhysicalSErrorPending()
// =======================================
// Returns TRUE if a synchronizable physical SError interrupt is pending.

impdef func <anchor link="func_IsSynchronizablePhysicalSErrorPending_0">IsSynchronizablePhysicalSErrorPending</anchor>() =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/IsVirtualSErrorPending" mylink="shared.functions.externalaborts.IsVirtualSErrorPending" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsVirtualSErrorPending()
// ========================
// Return TRUE if a virtual SError interrupt is pending.

func <anchor link="func_IsVirtualSErrorPending_0">IsVirtualSErrorPending</anchor>() =&gt; boolean
begin
    if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        return HCR().VA == '1';
    else
        return HCR_EL2().VSE == '1';
    end;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/PEErrorState" mylink="shared.functions.externalaborts.PEErrorState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PEErrorState()
// ==============
// Returns the error state of the PE on taking an error exception:
// The PE error state reported to software through the exception syndrome also
// depends on how the exception is taken, and so might differ from the value
// returned from this function.

func <anchor link="func_PEErrorState_1">PEErrorState</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; <a link="type_ErrorState" file="shared_pseudocode.xml">ErrorState</a>
begin
    assert !<a link="func_FaultIsCorrected_0" file="shared_pseudocode.xml">FaultIsCorrected</a>();
    if (!<a link="func_ErrorIsContained_0" file="shared_pseudocode.xml">ErrorIsContained</a>() ||
        (!<a link="func_ErrorIsSynchronized_0" file="shared_pseudocode.xml">ErrorIsSynchronized</a>() &amp;&amp; !<a link="func_StateIsRecoverable_0" file="shared_pseudocode.xml">StateIsRecoverable</a>()) ||
         <a link="func_ReportErrorAsUC_0" file="shared_pseudocode.xml">ReportErrorAsUC</a>()) then
        return <a link="enum_ErrorState_UC" file="shared_pseudocode.xml">ErrorState_UC</a>;
    end;

    if !<a link="func_StateIsRecoverable_0" file="shared_pseudocode.xml">StateIsRecoverable</a>() || <a link="func_ReportErrorAsUEU_0" file="shared_pseudocode.xml">ReportErrorAsUEU</a>() then
        return <a link="enum_ErrorState_UEU" file="shared_pseudocode.xml">ErrorState_UEU</a>;
    end;

    if <a link="func_ActionRequired_0" file="shared_pseudocode.xml">ActionRequired</a>() || <a link="func_ReportErrorAsUER_0" file="shared_pseudocode.xml">ReportErrorAsUER</a>() then
        return <a link="enum_ErrorState_UER" file="shared_pseudocode.xml">ErrorState_UER</a>;
    end;

    return <a link="enum_ErrorState_UEO" file="shared_pseudocode.xml">ErrorState_UEO</a>;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/PendSErrorInterrupt" mylink="shared.functions.externalaborts.PendSErrorInterrupt" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PendSErrorInterrupt()
// =====================
// Pend the SError Interrupt.

impdef func PendSErrorInterrupt(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>)
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/ReportErrorAsIMPDEF" mylink="shared.functions.externalaborts.ReportErrorAsIMPDEF" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ReportErrorAsIMPDEF()
// =====================
// Return an implementation specific value:
// returns TRUE if Error is IMPDEF, FALSE otherwise.

impdef func <anchor link="func_ReportErrorAsIMPDEF_0">ReportErrorAsIMPDEF</anchor>() =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/ReportErrorAsUC" mylink="shared.functions.externalaborts.ReportErrorAsUC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ReportErrorAsUC()
// =================
// Return an implementation specific value:
// returns TRUE if Error is Uncontainable, FALSE otherwise.

impdef func <anchor link="func_ReportErrorAsUC_0">ReportErrorAsUC</anchor>() =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/ReportErrorAsUER" mylink="shared.functions.externalaborts.ReportErrorAsUER" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ReportErrorAsUER()
// ==================
// Return an implementation specific value:
// returns TRUE if Error is Recoverable, FALSE otherwise.

impdef func <anchor link="func_ReportErrorAsUER_0">ReportErrorAsUER</anchor>() =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/ReportErrorAsUEU" mylink="shared.functions.externalaborts.ReportErrorAsUEU" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ReportErrorAsUEU()
// ==================
// Return an implementation specific value:
// returns TRUE if Error is Unrecoverable, FALSE otherwise.

impdef func <anchor link="func_ReportErrorAsUEU_0">ReportErrorAsUEU</anchor>() =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/ReportErrorAsUncategorized" mylink="shared.functions.externalaborts.ReportErrorAsUncategorized" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ReportErrorAsUncategorized()
// ============================
// Return an implementation specific value:
// returns TRUE if Error is uncategorized, FALSE otherwise.

impdef func <anchor link="func_ReportErrorAsUncategorized_0">ReportErrorAsUncategorized</anchor>() =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="shared/functions/externalaborts/StateIsRecoverable" mylink="shared.functions.externalaborts.StateIsRecoverable" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// StateIsRecoverable()
// ====================
// Return an implementation specific value:
// returns TRUE is PE State is unrecoverable else FALSE.

impdef func <anchor link="func_StateIsRecoverable_0">StateIsRecoverable</anchor>() =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFAdd" mylink="shared.functions.float.bfloat.BFAdd" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFAdd()
// =======
// Non-widening BFloat16 addition used by SVE2 instructions.

func <anchor link="func_BFAdd_4">BFAdd</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    let fpexc : boolean = TRUE;
    return <a link="func_BFAdd_5" file="shared_pseudocode.xml">BFAdd</a>{N}(op1, op2, fpcr, fpexc);
end;

// BFAdd()
// =======
// Non-widening BFloat16 addition following computational behaviors
// corresponding to instructions that read and write BFloat16 values.
// Calculates op1 + op2.
// The 'fpcr' argument supplies the FPCR control bits.

func <anchor link="func_BFAdd_5">BFAdd</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type, fpexc : boolean) =&gt; bits(N)
begin
    assert N == 16;
    let rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a> = <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr);
    var done : boolean;
    var result : bits(2*N);

    let op1_s : bits(2*N) = op1 :: Zeros{N};
    let op2_s : bits(2*N) = op2 :: Zeros{N};
    let (type1,sign1,value1) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{2*N}(op1_s, fpcr, fpexc);
    let (type2,sign2,value2) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{2*N}(op2_s, fpcr, fpexc);

    (done,result) = <a link="func_FPProcessNaNs_7" file="shared_pseudocode.xml">FPProcessNaNs</a>{2*N}(type1, type2, op1_s, op2_s, fpcr, fpexc);

    if !done then
        let inf1  = (type1 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let inf2  = (type2 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let zero1 = (type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        let zero2 = (type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);

        if inf1 &amp;&amp; inf2 &amp;&amp; sign1 == NOT(sign2) then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{2*N}(fpcr);
            if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;
        elsif (inf1 &amp;&amp; sign1 == '0') || (inf2 &amp;&amp; sign2 == '0') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{2*N}('0');
        elsif (inf1 &amp;&amp; sign1 == '1') || (inf2 &amp;&amp; sign2 == '1') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{2*N}('1');
        elsif zero1 &amp;&amp; zero2 &amp;&amp; sign1 == sign2 then
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{2*N}(sign1);
        else
            let result_value : real = value1 + value2;
            if result_value == 0.0 then  // Sign of exact zero result depends on rounding mode
                let result_sign : bit = if rounding == <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a> then '1' else '0';
                result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{2*N}(result_sign);
            else
                result = <a link="func_FPRoundBF_5" file="shared_pseudocode.xml">FPRoundBF</a>{2*N}(result_value, fpcr, rounding, fpexc);
            end;
        end;

        if fpexc then <a link="func_FPProcessDenorms_4" file="shared_pseudocode.xml">FPProcessDenorms</a>(type1, type2, 2*N, fpcr); end;
    end;


    return result[2*N-1:N];
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFAdd_ZA" mylink="shared.functions.float.bfloat.BFAdd_ZA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFAdd_ZA()
// ==========
// Non-widening BFloat16 addition used by SME2 ZA-targeting instructions.

func <anchor link="func_BFAdd_ZA_3">BFAdd_ZA</anchor>(op1 : bits(16), op2 : bits(16), fpcr_in : FPCR_Type) =&gt; bits(16)
begin
    let fpexc : boolean = FALSE;
    var fpcr : FPCR_Type = fpcr_in;
    fpcr.DN = '1';          // Generate default NaN values
    return <a link="func_BFAdd_5" file="shared_pseudocode.xml">BFAdd</a>{16}(op1, op2, fpcr, fpexc);
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFClampScale" mylink="shared.functions.float.bfloat.BFClampScale" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFClampScale()
// ==============

func <anchor link="func_BFClampScale_2">BFClampScale</anchor>(op : bits(16), scale_in : integer) =&gt; integer
begin
    let E : integer = 8;
    let F : integer = 7;
    let exp : integer = UInt(op[14:7]);
    let emax : integer = (1 &lt;&lt; E) - 1;
    let min_scale : integer = -(F + 1);
    let max_scale : integer = emax + (F + 1);

    let scale : integer = Max(min_scale - exp, Min(scale_in, max_scale - exp));
    return scale;
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFDotAdd" mylink="shared.functions.float.bfloat.BFDotAdd" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFDotAdd()
// ==========
// BFloat16 2-way dot-product and add to single-precision
// result = addend + op1_a*op2_a + op1_b*op2_b

func <anchor link="func_BFDotAdd_6">BFDotAdd</anchor>(addend : bits(32), op1_a : bits(16), op1_b : bits(16),
              op2_a : bits(16), op2_b : bits(16), fpcr_in : FPCR_Type) =&gt; bits(32)
begin
    var fpcr : FPCR_Type = fpcr_in;
    var prod : bits(32);

    var result : bits(32);
    if !IsFeatureImplemented(FEAT_EBF16) || fpcr.EBF == '0' then   // Standard BFloat16 behaviors
        prod   = <a link="func_FPAdd_BF16_3" file="shared_pseudocode.xml">FPAdd_BF16</a>(<a link="func_BFMulH_3" file="shared_pseudocode.xml">BFMulH</a>(op1_a, op2_a, fpcr), <a link="func_BFMulH_3" file="shared_pseudocode.xml">BFMulH</a>(op1_b, op2_b, fpcr), fpcr);
        result = <a link="func_FPAdd_BF16_3" file="shared_pseudocode.xml">FPAdd_BF16</a>(addend, prod, fpcr);
    else                                                           // Extended BFloat16 behaviors
        let isbfloat16 : boolean = TRUE;
        let fpexc : boolean = FALSE;    // Do not generate floating-point exceptions
        fpcr.DN = '1';                  // Generate default NaN values
        prod    = <a link="func_FPDot_7" file="shared_pseudocode.xml">FPDot</a>(op1_a, op1_b, op2_a, op2_b, fpcr, isbfloat16, fpexc);
        result  = <a link="func_FPAdd_5" file="shared_pseudocode.xml">FPAdd</a>{32}(addend, prod, fpcr, fpexc);
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFInfinity" mylink="shared.functions.float.bfloat.BFInfinity" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFInfinity()
// ============

func <anchor link="func_BFInfinity_2">BFInfinity</anchor>{N}(sign : bit) =&gt; bits(N)
begin
    assert N == 16;
    let E : integer{} = 8;
    let F : integer{} = N - (E + 1);
    return sign :: Ones{E} :: Zeros{F};
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFMatMulAddH" mylink="shared.functions.float.bfloat.BFMatMulAddH" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFMatMulAddH()
// ==============
// BFloat16 matrix multiply and add to single-precision matrix
// result[2, 2] = addend[2, 2] + (op1[2, 4] * op2[4, 2])

func <anchor link="func_BFMatMulAddH_4">BFMatMulAddH</anchor>(addend : bits(128), op1 : bits(128),
                  op2 : bits(128), fpcr : FPCR_Type) =&gt; bits(128)
begin

    var result : bits(128);
    var sum : bits(32);

    for i = 0 to 1 do
        for j = 0 to 1 do
            sum = addend[(2*i + j)*:32];
            for k = 0 to 1 do
                let elt1_a : bits(16) = op1[(4*i + 2*k + 0)*:16];
                let elt1_b : bits(16) = op1[(4*i + 2*k + 1)*:16];
                let elt2_a : bits(16) = op2[(4*j + 2*k + 0)*:16];
                let elt2_b : bits(16) = op2[(4*j + 2*k + 1)*:16];
                sum = <a link="func_BFDotAdd_6" file="shared_pseudocode.xml">BFDotAdd</a>(sum, elt1_a, elt1_b, elt2_a, elt2_b, fpcr);
            end;
            result[(2*i + j)*:32] = sum;
        end;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFMax" mylink="shared.functions.float.bfloat.BFMax" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFMax()
// =======
// BFloat16 maximum.

func <anchor link="func_BFMax_4">BFMax</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    let fpexc : boolean = TRUE;
    return <a link="func_BFMax_6" file="shared_pseudocode.xml">BFMax</a>{N}(op1, op2, fpcr, altfp, fpexc);
end;

// BFMax()
// =======
// BFloat16 maximum.

func <anchor link="func_BFMax_5">BFMax</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type, altfp : boolean) =&gt; bits(N)
begin
    let fpexc : boolean = TRUE;
    return <a link="func_BFMax_6" file="shared_pseudocode.xml">BFMax</a>{N}(op1, op2, fpcr, altfp, fpexc);
end;

// BFMax()
// =======
// BFloat16 maximum following computational behaviors
// corresponding to instructions that read and write BFloat16 values.
// Compare op1 and op2 and return the larger value after rounding.
// The 'fpcr' argument supplies the FPCR control bits and 'altfp' determines
// if the function should use alternative floating-point behavior.

func <anchor link="func_BFMax_6">BFMax</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr_in : FPCR_Type,
              altfp : boolean, fpexc : boolean) =&gt; bits(N)
begin
    assert N == 16;
    var fpcr : FPCR_Type = fpcr_in;
    let rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a> = <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr);
    var done : boolean;
    var result : bits(2*N);

    let op1_s : bits(2*N) = op1 :: Zeros{N};
    let op2_s : bits(2*N) = op2 :: Zeros{N};
    let (type1,sign1,value1) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{2*N}(op1_s, fpcr, fpexc);
    let (type2,sign2,value2) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{2*N}(op2_s, fpcr, fpexc);

    if altfp &amp;&amp; type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> &amp;&amp; type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> &amp;&amp; sign1 != sign2 then
        // Alternate handling of zeros with differing sign
        return <a link="func_BFZero_2" file="shared_pseudocode.xml">BFZero</a>{N}(sign2);
    elsif altfp &amp;&amp; (type1 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>} || type2 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>}) then
        // Alternate handling of NaN inputs
        if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;
        return (if type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then <a link="func_BFZero_2" file="shared_pseudocode.xml">BFZero</a>{N}(sign2) else op2);
    end;

    (done,result) = <a link="func_FPProcessNaNs_7" file="shared_pseudocode.xml">FPProcessNaNs</a>{2*N}(type1, type2, op1_s, op2_s, fpcr, fpexc);
    if !done then
        var fptype : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>;
        var sign : bit;
        var value : real;
        if value1 &gt; value2 then
            (fptype,sign,value) = (type1,sign1,value1);
        else
            (fptype,sign,value) = (type2,sign2,value2);
        end;
        if fptype == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a> then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{2*N}(sign);
        elsif fptype == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then
            sign = sign1 AND sign2;              // Use most positive sign
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{2*N}(sign);
        else
            if altfp then    // Denormal output is not flushed to zero
                fpcr.FZ = '0';
            end;
            result = <a link="func_FPRoundBF_5" file="shared_pseudocode.xml">FPRoundBF</a>{2*N}(value, fpcr, rounding, fpexc);
        end;

        if fpexc then <a link="func_FPProcessDenorms_4" file="shared_pseudocode.xml">FPProcessDenorms</a>(type1, type2, 2*N, fpcr); end;
    end;

    return result[2*N-1:N];
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFMaxNum" mylink="shared.functions.float.bfloat.BFMaxNum" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFMaxNum()
// ==========

func <anchor link="func_BFMaxNum_4">BFMaxNum</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    let fpexc : boolean = TRUE;
    return <a link="func_BFMaxNum_5" file="shared_pseudocode.xml">BFMaxNum</a>{N}(op1, op2, fpcr, fpexc);
end;

// BFMaxNum()
// ==========
// BFloat16 maximum number following computational behaviors corresponding
// to instructions that read and write BFloat16 values.
// Compare op1 and op2 and return the larger number operand after rounding.
// The 'fpcr' argument supplies the FPCR control bits.

func <anchor link="func_BFMaxNum_5">BFMaxNum</anchor>{N}(op1_in : bits(N), op2_in : bits(N), fpcr : FPCR_Type, fpexc : boolean) =&gt; bits(N)
begin
    assert N == 16;
    let isbfloat16 : boolean = TRUE;
    var op1 : bits(N)   = op1_in;
    var op2 : bits(N)   = op2_in;
    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    var result : bits(N);

    let (type1,-,-) = <a link="func_FPUnpackBase_5" file="shared_pseudocode.xml">FPUnpackBase</a>{N}(op1, fpcr, fpexc, isbfloat16);
    let (type2,-,-) = <a link="func_FPUnpackBase_5" file="shared_pseudocode.xml">FPUnpackBase</a>{N}(op2, fpcr, fpexc, isbfloat16);

    let type1_nan : boolean = type1 IN {<a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>, <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>};
    let type2_nan : boolean = type2 IN {<a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>, <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>};

    if !(altfp &amp;&amp; type1_nan &amp;&amp; type2_nan) then
        // Treat a single quiet-NaN as -Infinity.
        if type1 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> &amp;&amp; type2 != <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
            op1 = <a link="func_BFInfinity_2" file="shared_pseudocode.xml">BFInfinity</a>{N}('1');
        elsif type1 != <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> &amp;&amp; type2 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
            op2 = <a link="func_BFInfinity_2" file="shared_pseudocode.xml">BFInfinity</a>{N}('1');
        end;
    end;

    let altfmaxfmin : boolean = FALSE;    // Do not use alternate NaN handling
    result = <a link="func_BFMax_6" file="shared_pseudocode.xml">BFMax</a>{N}(op1, op2, fpcr, altfmaxfmin, fpexc);

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFMin" mylink="shared.functions.float.bfloat.BFMin" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFMin()
// =======
// BFloat16 minimum.

func <anchor link="func_BFMin_4">BFMin</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    let fpexc : boolean = TRUE;
    return <a link="func_BFMin_6" file="shared_pseudocode.xml">BFMin</a>{N}(op1, op2, fpcr, altfp, fpexc);
end;

// BFMin()
// =======
// BFloat16 minimum.

func <anchor link="func_BFMin_5">BFMin</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type, altfp : boolean) =&gt; bits(N)
begin
    let fpexc : boolean = TRUE;
    return <a link="func_BFMin_6" file="shared_pseudocode.xml">BFMin</a>{N}(op1, op2, fpcr, altfp, fpexc);
end;

// BFMin()
// =======
// BFloat16 minimum following computational behaviors
// corresponding to instructions that read and write BFloat16 values.
// Compare op1 and op2 and return the smaller value after rounding.
// The 'fpcr' argument supplies the FPCR control bits and 'altfp' determines
// if the function should use alternative floating-point behavior.

func <anchor link="func_BFMin_6">BFMin</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr_in : FPCR_Type,
              altfp : boolean, fpexc : boolean) =&gt; bits(N)
begin
    assert N == 16;
    var fpcr : FPCR_Type = fpcr_in;
    let rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a> = <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr);
    var done : boolean;
    var result : bits(2*N);

    let op1_s : bits(2*N) = op1 :: Zeros{N};
    let op2_s : bits(2*N) = op2 :: Zeros{N};
    let (type1,sign1,value1) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{2*N}(op1_s, fpcr, fpexc);
    let (type2,sign2,value2) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{2*N}(op2_s, fpcr, fpexc);

    if altfp &amp;&amp; type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> &amp;&amp; type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> &amp;&amp; sign1 != sign2 then
        // Alternate handling of zeros with differing sign
        return <a link="func_BFZero_2" file="shared_pseudocode.xml">BFZero</a>{N}(sign2);
    elsif altfp &amp;&amp; (type1 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>} || type2 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>}) then
        // Alternate handling of NaN inputs
        if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;
        return (if type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then <a link="func_BFZero_2" file="shared_pseudocode.xml">BFZero</a>{N}(sign2) else op2);
    end;

    (done,result) = <a link="func_FPProcessNaNs_7" file="shared_pseudocode.xml">FPProcessNaNs</a>{2*N}(type1, type2, op1_s, op2_s, fpcr, fpexc);
    if !done then
        var fptype : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>;
        var sign : bit;
        var value : real;
        if value1 &lt; value2 then
            (fptype,sign,value) = (type1,sign1,value1);
        else
            (fptype,sign,value) = (type2,sign2,value2);
        end;
        if fptype == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a> then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{2*N}(sign);
        elsif fptype == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then
            sign = sign1 OR sign2;              // Use most negative sign
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{2*N}(sign);
        else
            if altfp then                       // Denormal output is not flushed to zero
                fpcr.FZ = '0';
            end;
            result = <a link="func_FPRoundBF_5" file="shared_pseudocode.xml">FPRoundBF</a>{2*N}(value, fpcr, rounding, fpexc);
        end;

        if fpexc then <a link="func_FPProcessDenorms_4" file="shared_pseudocode.xml">FPProcessDenorms</a>(type1, type2, 2*N, fpcr); end;
    end;

    return result[2*N-1:N];
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFMinNum" mylink="shared.functions.float.bfloat.BFMinNum" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFMinNum()
// ==========

func <anchor link="func_BFMinNum_4">BFMinNum</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    let fpexc : boolean = TRUE;
    return <a link="func_BFMinNum_5" file="shared_pseudocode.xml">BFMinNum</a>{N}(op1, op2, fpcr, fpexc);
end;

// BFMinNum()
// ==========
// BFloat16 minimum number following computational behaviors corresponding
// to instructions that read and write BFloat16 values.
// Compare op1 and op2 and return the smaller number operand after rounding.
// The 'fpcr' argument supplies the FPCR control bits.

func <anchor link="func_BFMinNum_5">BFMinNum</anchor>{N}(op1_in : bits(N), op2_in : bits(N), fpcr : FPCR_Type, fpexc : boolean) =&gt; bits(N)
begin
    assert N == 16;
    let isbfloat16 : boolean = TRUE;
    var op1 : bits(N)   = op1_in;
    var op2 : bits(N)   = op2_in;
    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    var result : bits(N);

    let (type1,-,-) = <a link="func_FPUnpackBase_5" file="shared_pseudocode.xml">FPUnpackBase</a>{N}(op1, fpcr, fpexc, isbfloat16);
    let (type2,-,-) = <a link="func_FPUnpackBase_5" file="shared_pseudocode.xml">FPUnpackBase</a>{N}(op2, fpcr, fpexc, isbfloat16);

    let type1_nan : boolean = type1 IN {<a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>, <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>};
    let type2_nan : boolean = type2 IN {<a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>, <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>};

    if !(altfp &amp;&amp; type1_nan &amp;&amp; type2_nan) then
        // Treat a single quiet-NaN as +Infinity.
        if type1 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> &amp;&amp; type2 != <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
            op1 = <a link="func_BFInfinity_2" file="shared_pseudocode.xml">BFInfinity</a>{N}('0');
        elsif type1 != <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> &amp;&amp; type2 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
            op2 = <a link="func_BFInfinity_2" file="shared_pseudocode.xml">BFInfinity</a>{N}('0');
        end;
    end;

    let altfmaxfmin : boolean = FALSE;    // Do not use alternate NaN handling
    result = <a link="func_BFMin_6" file="shared_pseudocode.xml">BFMin</a>{N}(op1, op2, fpcr, altfmaxfmin, fpexc);

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFMul" mylink="shared.functions.float.bfloat.BFMul" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFMul()
// =======
// Non-widening BFloat16 multiply used by SVE2 instructions.

func <anchor link="func_BFMul_3">BFMul</anchor>(op1 : bits(16), op2 : bits(16), fpcr : FPCR_Type) =&gt; bits(16)
begin
    let fpexc : boolean = TRUE;
    return <a link="func_BFMul_4" file="shared_pseudocode.xml">BFMul</a>(op1, op2, fpcr, fpexc);
end;

// BFMul()
// =======
// Non-widening BFloat16 multiply following computational behaviors
// corresponding to instructions that read and write BFloat16 values.
// Calculates op1 * op2.
// The 'fpcr' argument supplies the FPCR control bits.

func <anchor link="func_BFMul_4">BFMul</anchor>(op1 : bits(16), op2 : bits(16), fpcr : FPCR_Type, fpexc : boolean) =&gt; bits(16)
begin
    let rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a> = <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr);
    var done : boolean;
    var result : bits(32);

    let op1_s : bits(32) = op1 :: Zeros{16};
    let op2_s : bits(32) = op2 :: Zeros{16};
    let (type1,sign1,value1) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{32}(op1_s, fpcr, fpexc);
    let (type2,sign2,value2) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{32}(op2_s, fpcr, fpexc);

    (done,result) = <a link="func_FPProcessNaNs_7" file="shared_pseudocode.xml">FPProcessNaNs</a>{32}(type1, type2, op1_s, op2_s, fpcr, fpexc);

    if !done then
        let inf1  = (type1 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let inf2  = (type2 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let zero1 = (type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        let zero2 = (type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);

        if (inf1 &amp;&amp; zero2) || (zero1 &amp;&amp; inf2) then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{32}(fpcr);
            if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;
        elsif inf1 || inf2 then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{32}(sign1 XOR sign2);
        elsif zero1 || zero2 then
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{32}(sign1 XOR sign2);
        else
            result = <a link="func_FPRoundBF_5" file="shared_pseudocode.xml">FPRoundBF</a>{32}(value1*value2, fpcr, rounding, fpexc);
        end;

        if fpexc then <a link="func_FPProcessDenorms_4" file="shared_pseudocode.xml">FPProcessDenorms</a>(type1, type2, 32, fpcr); end;
    end;

    return result[31:16];
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFMulAdd" mylink="shared.functions.float.bfloat.BFMulAdd" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFMulAdd()
// ==========
// Non-widening BFloat16 fused multiply-add used by SVE2 instructions.

func <anchor link="func_BFMulAdd_4">BFMulAdd</anchor>(addend : bits(16), op1 : bits(16), op2 : bits(16), fpcr : FPCR_Type) =&gt; bits(16)
begin
    let fpexc : boolean = TRUE;
    return <a link="func_BFMulAdd_5" file="shared_pseudocode.xml">BFMulAdd</a>(addend, op1, op2, fpcr, fpexc);
end;

// BFMulAdd()
// ==========
// Non-widening BFloat16 fused multiply-add following computational behaviors
// corresponding to instructions that read and write BFloat16 values.
// Calculates addend + op1*op2 with a single rounding.
// The 'fpcr' argument supplies the FPCR control bits.

func <anchor link="func_BFMulAdd_5">BFMulAdd</anchor>(addend : bits(16), op1 : bits(16), op2 : bits(16),
              fpcr : FPCR_Type, fpexc : boolean) =&gt; bits(16)
begin
    let rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a> = <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr);
    var done : boolean;
    var result : bits(32);

    let addend_s : bits(32)  = addend :: Zeros{16};
    let op1_s : bits(32)     = op1 :: Zeros{16};
    let op2_s : bits(32)     = op2 :: Zeros{16};
    let (typeA,signA,valueA) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{32}(addend_s, fpcr, fpexc);
    let (type1,sign1,value1) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{32}(op1_s, fpcr, fpexc);
    let (type2,sign2,value2) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{32}(op2_s, fpcr, fpexc);

    let inf1  = (type1 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
    let inf2  = (type2 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
    let zero1 = (type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
    let zero2 = (type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);

    (done,result) = <a link="func_FPProcessNaNs3_9" file="shared_pseudocode.xml">FPProcessNaNs3</a>{32}(typeA, type1, type2, addend_s, op1_s, op2_s, fpcr, fpexc);

    if !(IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1') then
        if typeA == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> &amp;&amp; ((inf1 &amp;&amp; zero2) || (zero1 &amp;&amp; inf2)) then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{32}(fpcr);
            if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;
        end;
    end;

    if !done then
        let infA  = (typeA == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let zeroA = (typeA == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);

        // Determine sign and type product will have if it does not cause an
        // Invalid Operation.
        let signP = sign1 XOR sign2;
        let infP  = inf1 || inf2;
        let zeroP = zero1 || zero2;

        // Non SNaN-generated Invalid Operation cases are multiplies of zero
        // by infinity and additions of opposite-signed infinities.
        let invalidop = (inf1 &amp;&amp; zero2) || (zero1 &amp;&amp; inf2) || (infA &amp;&amp; infP &amp;&amp; signA != signP);

        if invalidop then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{32}(fpcr);
            if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;

        // Other cases involving infinities produce an infinity of the same sign.
        elsif (infA &amp;&amp; signA == '0') || (infP &amp;&amp; signP == '0') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{32}('0');
        elsif (infA &amp;&amp; signA == '1') || (infP &amp;&amp; signP == '1') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{32}('1');

        // Cases where the result is exactly zero and its sign is not determined by the
        // rounding mode are additions of same-signed zeros.
        elsif zeroA &amp;&amp; zeroP &amp;&amp; signA == signP then
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{32}(signA);

        // Otherwise calculate numerical result and round it.
        else
            let result_value : real = valueA + (value1 * value2);
            if result_value == 0.0 then  // Sign of exact zero result depends on rounding mode
                let result_sign : bit = if rounding == <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a> then '1' else '0';
                result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{32}(result_sign);
            else
                result = <a link="func_FPRoundBF_5" file="shared_pseudocode.xml">FPRoundBF</a>{32}(result_value, fpcr, rounding, fpexc);
            end;
        end;

        if !invalidop &amp;&amp; fpexc then
            <a link="func_FPProcessDenorms3_5" file="shared_pseudocode.xml">FPProcessDenorms3</a>(typeA, type1, type2, 32, fpcr);
        end;
    end;

    return result[31:16];
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFMulAddH" mylink="shared.functions.float.bfloat.BFMulAddH" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFMulAddH()
// ===========
// Used by BFMLALB, BFMLALT, BFMLSLB and BFMLSLT instructions.

func <anchor link="func_BFMulAddH_4">BFMulAddH</anchor>(addend : bits(32), op1 : bits(16), op2 : bits(16), fpcr_in : FPCR_Type) =&gt; bits(32)
begin
    let value1 : bits(32) = op1 :: Zeros{16};
    let value2 : bits(32) = op2 :: Zeros{16};
    var fpcr : FPCR_Type  = fpcr_in;
    let altfp : boolean   = IsFeatureImplemented(FEAT_AFP) &amp;&amp; fpcr.AH == '1';
    // When using alternative floating-point behavior, do not generate floating-point exceptions
    let fpexc : boolean   = !altfp;
    if altfp then fpcr.[FIZ,FZ] = '11'; end;                          // Flush denormal input and
                                                                      // output to zero
    if altfp then fpcr.RMode    = '00'; end;                          // Use RNE rounding mode
    return <a link="func_FPMulAdd_6" file="shared_pseudocode.xml">FPMulAdd</a>{32}(addend, value1, value2, fpcr, fpexc);
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFMulAddH_ZA" mylink="shared.functions.float.bfloat.BFMulAddH_ZA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFMulAddH_ZA()
// ==============
// Used by SME2 ZA-targeting BFMLAL and BFMLSL instructions.

func <anchor link="func_BFMulAddH_ZA_4">BFMulAddH_ZA</anchor>(addend : bits(32), op1 : bits(16), op2 : bits(16), fpcr : FPCR_Type) =&gt; bits(32)
begin
    let value1 : bits(32) = op1 :: Zeros{16};
    let value2 : bits(32) = op2 :: Zeros{16};
    return <a link="func_FPMulAdd_ZA_5" file="shared_pseudocode.xml">FPMulAdd_ZA</a>{32}(addend, value1, value2, fpcr);
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFMulAdd_ZA" mylink="shared.functions.float.bfloat.BFMulAdd_ZA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFMulAdd_ZA()
// =============
// Non-widening BFloat16 fused multiply-add used by SME2 ZA-targeting instructions.

func <anchor link="func_BFMulAdd_ZA_4">BFMulAdd_ZA</anchor>(addend : bits(16), op1 : bits(16), op2 : bits(16), fpcr_in : FPCR_Type) =&gt; bits(16)
begin
    let fpexc : boolean  = FALSE;
    var fpcr : FPCR_Type = fpcr_in;
    fpcr.DN = '1';          // Generate default NaN values
    return <a link="func_BFMulAdd_5" file="shared_pseudocode.xml">BFMulAdd</a>(addend, op1, op2, fpcr, fpexc);
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFMulH" mylink="shared.functions.float.bfloat.BFMulH" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFMulH()
// ========
// BFloat16 widening multiply to single-precision following BFloat16
// computation behaviors.

func <anchor link="func_BFMulH_3">BFMulH</anchor>(op1 : bits(16), op2 : bits(16), fpcr : FPCR_Type) =&gt; bits(32)
begin
    var result : bits(32);

    let (type1,sign1,value1) = <a link="func_BFUnpack_2" file="shared_pseudocode.xml">BFUnpack</a>{16}(op1);
    let (type2,sign2,value2) = <a link="func_BFUnpack_2" file="shared_pseudocode.xml">BFUnpack</a>{16}(op2);
    if type1 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> || type2 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{32}(fpcr);
    else
        let inf1  = (type1 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let inf2  = (type2 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let zero1 = (type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        let zero2 = (type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        if (inf1 &amp;&amp; zero2) || (zero1 &amp;&amp; inf2) then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{32}(fpcr);
        elsif inf1 || inf2 then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{32}(sign1 XOR sign2);
        elsif zero1 || zero2 then
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{32}(sign1 XOR sign2);
        else
            result = <a link="func_BFRound_1" file="shared_pseudocode.xml">BFRound</a>(value1*value2);
        end;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFNeg" mylink="shared.functions.float.bfloat.BFNeg" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFNeg()
// =======

func <anchor link="func_BFNeg_1">BFNeg</anchor>(op : bits(16)) =&gt; bits(16)
begin
    let honor_altfp : boolean = TRUE;    // Honor alternate handling
    return <a link="func_BFNeg_2" file="shared_pseudocode.xml">BFNeg</a>(op, honor_altfp);
end;

// BFNeg()
// =======

func <anchor link="func_BFNeg_2">BFNeg</anchor>(op : bits(16), honor_altfp : boolean) =&gt; bits(16)
begin
    if honor_altfp &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; IsFeatureImplemented(FEAT_AFP) then
        if FPCR().AH == '1' then
            let fpexc : boolean = FALSE;
            let isbfloat16 : boolean = TRUE;
            let (fptype, -, -) = <a link="func_FPUnpackBase_5" file="shared_pseudocode.xml">FPUnpackBase</a>{16}(op, FPCR(), fpexc, isbfloat16);
            if fptype IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>} then
                return op;        // When FPCR().AH=1, sign of NaN has no consequence
            end;
        end;
    end;
    return NOT(op[15]) :: op[14:0];
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFRound" mylink="shared.functions.float.bfloat.BFRound" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFRound()
// =========
// Converts a real number OP into a single-precision value using the
// Round to Odd rounding mode and following BFloat16 computation behaviors.

func <anchor link="func_BFRound_1">BFRound</anchor>(op : real) =&gt; bits(32)
begin
    assert op != 0.0;
    var result : bits(32);

    // Format parameters - minimum exponent, numbers of exponent and fraction bits.
    let minimum_exp : integer = -126;  let E : integer{} = 8;  let F : integer{} = 23;

    // Split value into sign, unrounded mantissa and exponent.
    var sign : bit;
    var exponent : integer;
    var mantissa : real;
    if op &lt; 0.0 then
        sign = '1';  mantissa = -op;
    else
        sign = '0';  mantissa = op;
    end;

    (mantissa, exponent) = <a link="func_NormalizeReal_1" file="shared_pseudocode.xml">NormalizeReal</a>(mantissa);
    // Fixed Flush-to-zero.
    if exponent &lt; minimum_exp then
        return <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{32}(sign);
    end;

    // Start creating the exponent value for the result. Start by biasing the actual exponent
    // so that the minimum exponent becomes 1, lower values 0 (indicating possible underflow).
    let biased_exp : integer = Max((exponent - minimum_exp) + 1, 0);
    if biased_exp == 0 then mantissa = mantissa / 2.0^(minimum_exp - exponent); end;

    // Get the unrounded mantissa as an integer, and the &quot;units in last place&quot; rounding error.
    // &lt; 2.0^F if biased_exp == 0, &gt;= 2.0^F if not
    var int_mant : integer = RoundDown(mantissa * 2.0^F);
    let error : real = mantissa * 2.0^F - Real(int_mant);

    // Round to Odd
    if error != 0.0 &amp;&amp; int_mant[0] == '0' then
        int_mant = int_mant + 1;
    end;

    // Deal with overflow and generate result.
    if biased_exp &gt;= 2^E - 1 then
        result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{32}(sign);      // Overflows generate appropriately-signed Infinity
    else
        result = sign :: biased_exp[E-1:0] :: int_mant[F-1:0];
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFScale" mylink="shared.functions.float.bfloat.BFScale" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFScale()
// =========
// Scales BFloat16 operand by 2.0 to the power of the signed integer value.

func <anchor link="func_BFScale_3">BFScale</anchor>(op : bits(16), scale : integer, fpcr : FPCR_Type) =&gt; bits(16)
begin
    var result : bits(32);

    let op_s : bits(32) = op :: Zeros{16};
    let (fptype,sign,value) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{32}(op_s, fpcr);

    if fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || fptype == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        result = <a link="func_FPProcessNaN_4" file="shared_pseudocode.xml">FPProcessNaN</a>{32}(fptype, op_s, fpcr);
    elsif fptype == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then
        result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{32}(sign);
    elsif fptype == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a> then
        result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{32}(sign);
    else
        let rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a> = <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr);
        let fpexc : boolean = TRUE;
        let clamped_scale : integer = <a link="func_BFClampScale_2" file="shared_pseudocode.xml">BFClampScale</a>(op, scale);
        result = <a link="func_FPRoundBF_5" file="shared_pseudocode.xml">FPRoundBF</a>{32}(value * (2.0^clamped_scale), fpcr, rounding, fpexc);
        if fpexc then <a link="func_FPProcessDenorm_3" file="shared_pseudocode.xml">FPProcessDenorm</a>(fptype, 32, fpcr); end;
    end;

    return result[31:16];
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFSub" mylink="shared.functions.float.bfloat.BFSub" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFSub()
// =======
// Non-widening BFloat16 subtraction used by SVE2 instructions.

func <anchor link="func_BFSub_3">BFSub</anchor>(op1 : bits(16), op2 : bits(16), fpcr : FPCR_Type) =&gt; bits(16)
begin
    let fpexc : boolean = TRUE;
    return <a link="func_BFSub_4" file="shared_pseudocode.xml">BFSub</a>(op1, op2, fpcr, fpexc);
end;

// BFSub()
// =======
// Non-widening BFloat16 subtraction following computational behaviors
// corresponding to instructions that read and write BFloat16 values.
// Calculates op1 - op2.
// The 'fpcr' argument supplies the FPCR control bits.

func <anchor link="func_BFSub_4">BFSub</anchor>(op1 : bits(16), op2 : bits(16), fpcr : FPCR_Type, fpexc : boolean) =&gt; bits(16)
begin
    let rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a> = <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr);
    var done : boolean;
    var result : bits(32);

    let op1_s : bits(32) = op1 :: Zeros{16};
    let op2_s : bits(32) = op2 :: Zeros{16};
    let (type1,sign1,value1) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{32}(op1_s, fpcr, fpexc);
    let (type2,sign2,value2) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{32}(op2_s, fpcr, fpexc);

    (done,result) = <a link="func_FPProcessNaNs_7" file="shared_pseudocode.xml">FPProcessNaNs</a>{32}(type1, type2, op1_s, op2_s, fpcr, fpexc);

    if !done then
        let inf1  = (type1 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let inf2  = (type2 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let zero1 = (type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        let zero2 = (type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);

        if inf1 &amp;&amp; inf2 &amp;&amp; sign1 == sign2 then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{32}(fpcr);
            if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;
        elsif (inf1 &amp;&amp; sign1 == '0') || (inf2 &amp;&amp; sign2 == '1') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{32}('0');
        elsif (inf1 &amp;&amp; sign1 == '1') || (inf2 &amp;&amp; sign2 == '0') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{32}('1');
        elsif zero1 &amp;&amp; zero2 &amp;&amp; sign1 == NOT(sign2) then
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{32}(sign1);
        else
            let result_value : real = value1 - value2;
            if result_value == 0.0 then  // Sign of exact zero result depends on rounding mode
                let result_sign : bit = if rounding == <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a> then '1' else '0';
                result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{32}(result_sign);
            else
                result = <a link="func_FPRoundBF_5" file="shared_pseudocode.xml">FPRoundBF</a>{32}(result_value, fpcr, rounding, fpexc);
            end;
        end;

        if fpexc then <a link="func_FPProcessDenorms_4" file="shared_pseudocode.xml">FPProcessDenorms</a>(type1, type2, 32, fpcr); end;
    end;

    return result[31:16];
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFSub_ZA" mylink="shared.functions.float.bfloat.BFSub_ZA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFSub_ZA()
// ==========
// Non-widening BFloat16 subtraction used by SME2 ZA-targeting instructions.

func <anchor link="func_BFSub_ZA_3">BFSub_ZA</anchor>(op1 : bits(16), op2 : bits(16), fpcr_in : FPCR_Type) =&gt; bits(16)
begin
    let fpexc : boolean = FALSE;
    var fpcr : FPCR_Type = fpcr_in;
    fpcr.DN = '1';          // Generate default NaN values
    return <a link="func_BFSub_4" file="shared_pseudocode.xml">BFSub</a>(op1, op2, fpcr, fpexc);
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFUnpack" mylink="shared.functions.float.bfloat.BFUnpack" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFUnpack()
// ==========
// Unpacks a BFloat16 or single-precision value into its type,
// sign bit and real number that it represents.
// The real number result has the correct sign for numbers and infinities,
// is very large in magnitude for infinities, and is 0.0 for NaNs.
// (These values are chosen to simplify the description of
// comparisons and conversions.)

func <anchor link="func_BFUnpack_2">BFUnpack</anchor>{N}(fpval : bits(N)) =&gt; (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real)
begin
    assert N IN {16,32};

    var sign : bit;
    var exp : bits(8);
    var frac : bits(23);
    if N == 16 then
        sign   = fpval[15];
        exp    = fpval[14:7];
        frac   = fpval[6:0] :: Zeros{16};
    else  // N == 32
        sign   = fpval[31];
        exp    = fpval[30:23];
        frac   = fpval[22:0];
    end;

    var fptype : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>;
    var value : real;
    if IsZero(exp) then
        fptype = <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>;  value = 0.0;    // Fixed Flush to Zero
    elsif IsOnes(exp) then
        if IsZero(frac) then
            fptype = <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>;  value = 2.0^1000000;
        else    // no SNaN for BF16 arithmetic
            fptype = <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>; value = 0.0;
        end;
    else
        fptype = <a link="enum_FPType_Nonzero" file="shared_pseudocode.xml">FPType_Nonzero</a>;
        value = 2.0^(UInt(exp)-127) * (1.0 + Real(UInt(frac)) * 2.0^-23);
    end;

    if sign == '1' then value = -value; end;

    return (fptype, sign, value);
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/BFZero" mylink="shared.functions.float.bfloat.BFZero" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFZero()
// ========

func <anchor link="func_BFZero_2">BFZero</anchor>{N}(sign : bit) =&gt; bits(N)
begin
    assert N == 16;
    let E : integer{} = 8;
    let F : integer{} = N - (E + 1);
    return sign :: Zeros{E} :: Zeros{F};
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/FPAdd_BF16" mylink="shared.functions.float.bfloat.FPAdd_BF16" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPAdd_BF16()
// ============
// Single-precision add following BFloat16 computation behaviors.

func <anchor link="func_FPAdd_BF16_3">FPAdd_BF16</anchor>(op1 : bits(32), op2 : bits(32), fpcr : FPCR_Type) =&gt; bits(32)
begin
    var result : bits(32);

    let (type1,sign1,value1) = <a link="func_BFUnpack_2" file="shared_pseudocode.xml">BFUnpack</a>{32}(op1);
    let (type2,sign2,value2) = <a link="func_BFUnpack_2" file="shared_pseudocode.xml">BFUnpack</a>{32}(op2);
    if type1 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> || type2 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{32}(fpcr);
    else
        let inf1  = (type1 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let inf2  = (type2 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let zero1 = (type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        let zero2 = (type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        if inf1 &amp;&amp; inf2 &amp;&amp; sign1 == NOT(sign2) then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{32}(fpcr);
        elsif (inf1 &amp;&amp; sign1 == '0') || (inf2 &amp;&amp; sign2 == '0') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{32}('0');
        elsif (inf1 &amp;&amp; sign1 == '1') || (inf2 &amp;&amp; sign2 == '1') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{32}('1');
        elsif zero1 &amp;&amp; zero2 &amp;&amp; sign1 == sign2 then
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{32}(sign1);
        else
            let result_value : real = value1 + value2;
            if result_value == 0.0 then
                result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{32}('0');    // Positive sign when Round to Odd
            else
                result = <a link="func_BFRound_1" file="shared_pseudocode.xml">BFRound</a>(result_value);
            end;
        end;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/FPConvertBF" mylink="shared.functions.float.bfloat.FPConvertBF" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPConvertBF()
// =============
// Converts a single-precision OP to BFloat16 value using the
// Round to Nearest Even rounding mode when executed from AArch64 state and
// FPCR.AH == '1', otherwise rounding is controlled by FPCR/FPSCR.

func <anchor link="func_FPConvertBF_3">FPConvertBF</anchor>(op : bits(32), fpcr_in : FPCR_Type, rounding_in : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>) =&gt; bits(16)
begin
    let halfsize : integer{}  = 16;
    var fpcr : FPCR_Type      = fpcr_in;
    var rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a> = rounding_in;
    var result : bits(32);                              // BF16 value in top 16 bits
    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    let fpexc : boolean = !altfp;                      // Generate no floating-point exceptions
    if altfp then fpcr.[FIZ,FZ] = '11'; end;           // Flush denormal input and output to zero
    if altfp then rounding = <a link="enum_FPRounding_TIEEVEN" file="shared_pseudocode.xml">FPRounding_TIEEVEN</a>; end;  // Use RNE rounding mode

    // Unpack floating-point operand, with always flush-to-zero if fpcr.AH == '1'.
    let (fptype,sign,value) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{32}(op, fpcr, fpexc);

    if fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || fptype == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        if fpcr.DN == '1' then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{32}(fpcr);
        else
            result = <a link="func_FPConvertNaN_3" file="shared_pseudocode.xml">FPConvertNaN</a>{32, 32}(op);
        end;
        if fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
            if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;
        end;
    elsif fptype == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a> then
        result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{32}(sign);
    elsif fptype == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then
        result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{32}(sign);
    else
        result = <a link="func_FPRoundBF_5" file="shared_pseudocode.xml">FPRoundBF</a>{32}(value, fpcr, rounding, fpexc);
    end;

    // Returns correctly rounded BF16 value from top 16 bits
    return result[(2*halfsize)-1:halfsize];
end;

// FPConvertBF()
// =============
// Converts a single-precision operand to BFloat16 value.

func <anchor link="func_FPConvertBF_2">FPConvertBF</anchor>(op : bits(32), fpcr : FPCR_Type) =&gt; bits(16)
begin
    return <a link="func_FPConvertBF_3" file="shared_pseudocode.xml">FPConvertBF</a>(op, fpcr, <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr));
end;</pstext></ps>
    <ps name="shared/functions/float/bfloat/FPRoundBF" mylink="shared.functions.float.bfloat.FPRoundBF" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPRoundBF()
// ===========
// Converts a real number OP into a BFloat16 value using the supplied
// rounding mode RMODE. The 'fpexc' argument controls the generation of
// floating-point exceptions.

func <anchor link="func_FPRoundBF_5">FPRoundBF</anchor>{N}(op : real, fpcr : FPCR_Type, rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>, fpexc : boolean) =&gt; bits(N)
begin
    assert N == 32;
    let isbfloat16 : boolean = TRUE;
    return <a link="func_FPRoundBase_6" file="shared_pseudocode.xml">FPRoundBase</a>{N}(op, fpcr, rounding, isbfloat16, fpexc);
end;</pstext></ps>
    <ps name="shared/functions/float/fixedtofp/FixedToFP" mylink="shared.functions.float.fixedtofp.FixedToFP" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FixedToFP()
// ===========

// Convert M-bit fixed point 'op' with FBITS fractional bits to
// N-bit precision floating point, controlled by UNSIGNED and ROUNDING.

func <anchor link="func_FixedToFP_7">FixedToFP</anchor>{N, M}(op : bits(M), fbits : integer, unsigned : boolean, fpcr : FPCR_Type,
                     rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    assert M IN {16,32,64};
    var result : bits(N);
    assert fbits &gt;= 0;
    assert rounding != <a link="enum_FPRounding_ODD" file="shared_pseudocode.xml">FPRounding_ODD</a>;

    // Correct signed-ness
    let int_operand : integer{} = if unsigned then UInt(op) else SInt(op);

    // Scale by fractional bits and generate a real value
    let real_operand : real = Real(int_operand) / 2.0^fbits;

    if real_operand == 0.0 then
        result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}('0');
    else
        result = <a link="func_FPRound_4" file="shared_pseudocode.xml">FPRound</a>{N}(real_operand, fpcr, rounding);
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fp8float/BFConvertFP8" mylink="shared.functions.float.fp8float.BFConvertFP8" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BFConvertFP8()
// ==============
// Converts a BFloat16 OP to FP8 value.

func <anchor link="func_BFConvertFP8_3">BFConvertFP8</anchor>(op_in : bits(16), fpcr : FPCR_Type, fpmr : FPMR_Type) =&gt; bits(8)
begin
    let op : bits(32) = op_in :: Zeros{16};
    return <a link="func_FPConvertFP8_5" file="shared_pseudocode.xml">FPConvertFP8</a>{8, 32}(op, fpcr, fpmr);
end;</pstext></ps>
    <ps name="shared/functions/float/fp8float/FP8Bits" mylink="shared.functions.float.fp8float.FP8Bits" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FP8Bits()
// =========
// Returns the minimum exponent, numbers of exponent and fraction bits.

func <anchor link="func_FP8Bits_1">FP8Bits</anchor>(fp8type : <a link="type_FP8Type" file="shared_pseudocode.xml">FP8Type</a>) =&gt; <a link="type_FPBitsType" file="shared_pseudocode.xml">FPBitsType</a>
begin
    var minimum_exp : integer;
    var F : integer{2..3};
    if fp8type == <a link="enum_FP8Type_OFP8_E4M3" file="shared_pseudocode.xml">FP8Type_OFP8_E4M3</a> then
        minimum_exp = -6;  F = 3;
    else  // fp8type == FP8Type_OFP8_E5M2
        minimum_exp = -14;  F = 2;
    end;

    return (F, minimum_exp);
end;</pstext></ps>
    <ps name="shared/functions/float/fp8float/FP8ConvertBF" mylink="shared.functions.float.fp8float.FP8ConvertBF" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FP8ConvertBF()
// ==============
// Converts an FP8 operand to BFloat16 value.

func <anchor link="func_FP8ConvertBF_4">FP8ConvertBF</anchor>(op : bits(8), issrc2 : boolean, fpcr : FPCR_Type, fpmr : FPMR_Type) =&gt; bits(16)
begin
    let isbfloat16 : boolean = TRUE;
    let result : bits(32) = FP8ConvertFP{}(op, issrc2, fpcr, fpmr, isbfloat16);
    return result[16+:16];
end;</pstext></ps>
    <ps name="shared/functions/float/fp8float/FP8ConvertFP" mylink="shared.functions.float.fp8float.FP8ConvertFP" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FP8ConvertFP()
// ==============
// Converts an FP8 operand to half-precision value.

func <anchor link="func_FP8ConvertFP_4">FP8ConvertFP</anchor>(op : bits(8), issrc2 : boolean, fpcr : FPCR_Type, fpmr : FPMR_Type) =&gt; bits(16)
begin
    let isbfloat16 : boolean = FALSE;
    return <a link="func_FP8ConvertFP_6" file="shared_pseudocode.xml">FP8ConvertFP</a>{16}(op, issrc2, fpcr, fpmr, isbfloat16);
end;

// FP8ConvertFP()
// ==============
// Converts an FP8 operand to half-precision or BFloat16 value.
// The downscaling factor in FPMR.LSCALE or FPMR.LSCALE2 is applied to
// the value before rounding.

func <anchor link="func_FP8ConvertFP_6">FP8ConvertFP</anchor>{M}(op : bits(8), issrc2 : boolean, fpcr_in : FPCR_Type, fpmr : FPMR_Type,
                     isbfloat16 : boolean) =&gt; bits(M)
begin
    assert M IN {16,32};
    var result : bits(M);

    let fpexc : boolean = TRUE;
    var fpcr : FPCR_Type = fpcr_in;
    // Do not flush denormal inputs and outputs to zero.
    // Do not support alternative half-precision format.
    fpcr.[FIZ,FZ,FZ16,AHP] = '0000';
    let rounding = <a link="enum_FPRounding_TIEEVEN" file="shared_pseudocode.xml">FPRounding_TIEEVEN</a>;
    let fp8type : <a link="type_FP8Type" file="shared_pseudocode.xml">FP8Type</a> = (if issrc2 then <a link="func_FP8DecodeType_1" file="shared_pseudocode.xml">FP8DecodeType</a>(fpmr.F8S2)
                                else <a link="func_FP8DecodeType_1" file="shared_pseudocode.xml">FP8DecodeType</a>(fpmr.F8S1));

    let (fptype,sign,value) = <a link="func_FP8Unpack_3" file="shared_pseudocode.xml">FP8Unpack</a>{8}(op, fp8type);

    if fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || fptype == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{M}(fpcr);
        if fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
            <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
        end;
    elsif fptype == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a> then
        result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{M}(sign);
    elsif fptype == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then
        result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{M}(sign);
    else
        var dscale : integer;
        if issrc2 then
            dscale = (if M == 16 then UInt(fpmr.LSCALE2[3:0])
                      else UInt(fpmr.LSCALE2[:6]));
        else
            dscale = (if M == 16 then UInt(fpmr.LSCALE[3:0])
                       else UInt(fpmr.LSCALE[:6]));
        end;
        let result_value : real = value * (2.0^-dscale);
        result = <a link="func_FPRoundBase_6" file="shared_pseudocode.xml">FPRoundBase</a>{M}(result_value, fpcr, rounding, isbfloat16, fpexc);
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fp8float/FP8DecodeType" mylink="shared.functions.float.fp8float.FP8DecodeType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FP8DecodeType()
// ===============
// Decode the FP8 format encoded in F8S1, F8S2 or F8D field in FPMR

func <anchor link="func_FP8DecodeType_1">FP8DecodeType</anchor>(f8format : bits(3)) =&gt; <a link="type_FP8Type" file="shared_pseudocode.xml">FP8Type</a>
begin
    case f8format of
        when '000' =&gt; return <a link="enum_FP8Type_OFP8_E5M2" file="shared_pseudocode.xml">FP8Type_OFP8_E5M2</a>;
        when '001' =&gt; return <a link="enum_FP8Type_OFP8_E4M3" file="shared_pseudocode.xml">FP8Type_OFP8_E4M3</a>;
        otherwise =&gt;  return <a link="enum_FP8Type_UNSUPPORTED" file="shared_pseudocode.xml">FP8Type_UNSUPPORTED</a>;
    end;
end;</pstext></ps>
    <ps name="shared/functions/float/fp8float/FP8DefaultNaN" mylink="shared.functions.float.fp8float.FP8DefaultNaN" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FP8DefaultNaN()
// ===============

func <anchor link="func_FP8DefaultNaN_3">FP8DefaultNaN</anchor>{N}(fp8type : <a link="type_FP8Type" file="shared_pseudocode.xml">FP8Type</a>, fpcr : FPCR_Type) =&gt; bits(N)
begin
    assert N == 8;
    assert fp8type IN {<a link="enum_FP8Type_OFP8_E5M2" file="shared_pseudocode.xml">FP8Type_OFP8_E5M2</a>, <a link="enum_FP8Type_OFP8_E4M3" file="shared_pseudocode.xml">FP8Type_OFP8_E4M3</a>};
    let sign : bit = if IsFeatureImplemented(FEAT_AFP) then fpcr.AH else '0';
    let E : integer{} = if fp8type == <a link="enum_FP8Type_OFP8_E4M3" file="shared_pseudocode.xml">FP8Type_OFP8_E4M3</a> then 4 else 5;
    let F : integer{} = N - (E + 1);
    var exp : bits(E);
    var frac : bits(F);

    case fp8type of
        when <a link="enum_FP8Type_OFP8_E4M3" file="shared_pseudocode.xml">FP8Type_OFP8_E4M3</a> =&gt;
            exp  = Ones{E};
            frac = Ones{F};
        when <a link="enum_FP8Type_OFP8_E5M2" file="shared_pseudocode.xml">FP8Type_OFP8_E5M2</a> =&gt;
            exp  = Ones{E};
            frac = '1'::Zeros{F-1};
    end;

    return sign :: exp :: frac;
end;</pstext></ps>
    <ps name="shared/functions/float/fp8float/FP8DotAddFP" mylink="shared.functions.float.fp8float.FP8DotAddFP" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FP8DotAddFP()
// =============

func <anchor link="func_FP8DotAddFP_7">FP8DotAddFP</anchor>{M, N}(addend : bits(M), op1 : bits(N), op2 : bits(N),
                       fpcr : FPCR_Type, fpmr : FPMR_Type) =&gt; bits(M)
begin
    let E : integer{} = (N DIV 8) as integer{1, 2, 4, 8};
    return <a link="func_FP8DotAddFP_8" file="shared_pseudocode.xml">FP8DotAddFP</a>{M, N}(addend, op1, op2, E, fpcr, fpmr);
end;

// FP8DotAddFP()
// ==============
// Calculates result of &quot;E&quot;-way 8-bit floating-point dot-product with scaling
// and addition to half-precision or single-precision value without
// intermediate rounding.
// c = round(c + 2^-S*(a1*b1+..+aE*bE))
// The 8-bit floating-point format for op1 is determined by FPMR.F8S1
// and the one for op2 by FPMR.F8S2. The scaling factor in FPMR.LSCALE
// is applied to the sum-of-products before adding to the addend and rounding.

func <anchor link="func_FP8DotAddFP_8">FP8DotAddFP</anchor>{M, N}(addend : bits(M), op1 : bits(N), op2 : bits(N), E : integer{1, 2, 4, 8},
                       fpcr_in : FPCR_Type, fpmr : FPMR_Type) =&gt; bits(M)
begin
    assert M IN {16,32};
    assert N IN {2*M, M, M DIV 2, M DIV 4};
    var fpcr : FPCR_Type = fpcr_in;
    var result : bits(M);

    fpcr.[FIZ,FZ,FZ16] = '000';        // Do not flush denormal inputs and outputs to zero
    fpcr.DN = '1';
    let rounding = <a link="enum_FPRounding_TIEEVEN" file="shared_pseudocode.xml">FPRounding_TIEEVEN</a>;

    let fp8type1 : <a link="type_FP8Type" file="shared_pseudocode.xml">FP8Type</a> = <a link="func_FP8DecodeType_1" file="shared_pseudocode.xml">FP8DecodeType</a>(fpmr.F8S1);
    let fp8type2 : <a link="type_FP8Type" file="shared_pseudocode.xml">FP8Type</a> = <a link="func_FP8DecodeType_1" file="shared_pseudocode.xml">FP8DecodeType</a>(fpmr.F8S2);

    var type1 : array[[E]] of <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>;
    var type2 : array[[E]] of <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>;
    var sign1 : array[[E]] of bit;
    var sign2 : array[[E]] of bit;
    var value1 : array[[E]] of real;
    var value2 : array[[E]] of real;
    var inf1 : array[[E]] of boolean;
    var inf2 : array[[E]] of boolean;
    var zero1 : array[[E]] of boolean;
    var zero2 : array[[E]] of boolean;

    let fpexc : boolean = FALSE;
    let (typeA,signA,valueA) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{M}(addend, fpcr, fpexc);
    let infA = (typeA == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);   let zeroA = (typeA == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
    var any_nan : boolean = typeA IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>};
    for i = 0 to E-1 do
        (type1[[i]], sign1[[i]], value1[[i]]) = <a link="func_FP8Unpack_3" file="shared_pseudocode.xml">FP8Unpack</a>{N DIV E}(op1[i*:(N DIV E)], fp8type1);
        (type2[[i]], sign2[[i]], value2[[i]]) = <a link="func_FP8Unpack_3" file="shared_pseudocode.xml">FP8Unpack</a>{N DIV E}(op2[i*:(N DIV E)], fp8type2);
        inf1[[i]] = (type1[[i]] == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>); zero1[[i]] = (type1[[i]] == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        inf2[[i]] = (type2[[i]] == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>); zero2[[i]] = (type2[[i]] == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        any_nan = (any_nan || type1[[i]] IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>} ||
                   type2[[i]] IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>});
    end;

    if any_nan then
        result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{M}(fpcr);
    else
        // Determine sign and type products will have if it does not cause an Invalid
        // Operation.
        var signP : array [[E]] of bit;
        var infP : array [[E]] of boolean;
        var zeroP : array [[E]] of boolean;
        for i = 0 to E-1 do
            signP[[i]] = sign1[[i]] XOR sign2[[i]];
            infP[[i]]  = inf1[[i]] || inf2[[i]];
            zeroP[[i]] = zero1[[i]] || zero2[[i]];
        end;

        // Detect non-numeric results of dot product and accumulate
        var posInfR : boolean = (infA &amp;&amp; signA == '0');
        var negInfR : boolean = (infA &amp;&amp; signA == '1');
        var zeroR : boolean = zeroA;
        var invalidop : boolean = FALSE;
        for i = 0 to E-1 do
            // Result is infinity if any input is infinity
            posInfR  = posInfR || (infP[[i]] &amp;&amp; signP[[i]] == '0');
            negInfR  = negInfR || (infP[[i]] &amp;&amp; signP[[i]] == '1');
            // Result is zero if the addend and the products are zeroes of the same sign
            zeroR    = zeroR &amp;&amp; zeroP[[i]] &amp;&amp; (signA == signP[[i]]);
            // Non SNaN-generated Invalid Operation cases are multiplies of zero
            // by infinity and additions of opposite-signed infinities.
            invalidop = (invalidop || (inf1[[i]] &amp;&amp; zero2[[i]]) || (zero1[[i]] &amp;&amp; inf2[[i]]) ||
                         (infA &amp;&amp; infP[[i]] &amp;&amp; (signA != signP[[i]])));
            for j = i+1 to E-1 do
                invalidop = invalidop || (infP[[i]] &amp;&amp; infP[[j]] &amp;&amp; (signP[[i]] != signP[[j]]));
            end;
        end;

        if invalidop then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{M}(fpcr);

        // Other cases involving infinities produce an infinity of the same sign.
        elsif posInfR then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{M}('0');
        elsif negInfR then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{M}('1');

        // Cases where the result is exactly zero and its sign is not determined by the
        // rounding mode are additions of same-signed zeros.
        elsif zeroR then
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{M}(signA);

        // Otherwise calculate numerical value and round it.
        else
            // Apply scaling to sum-of-product
            let dscale : integer = if M == 32 then UInt(fpmr.LSCALE) else UInt(fpmr.LSCALE[3:0]);

            var dp_value : real = value1[[0]] * value2[[0]];
            for i = 1 to E-1 do
                dp_value = dp_value + value1[[i]] * value2[[i]];
            end;

            let result_value : real = valueA + dp_value * (2.0^-dscale);
            if result_value == 0.0 then  // Sign of exact zero result is '0' for RNE rounding mode
                result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{M}('0');
            else
                let satoflo : boolean = (fpmr.OSM == '1');
                result = <a link="func_FPRound_FP8_5" file="shared_pseudocode.xml">FPRound_FP8</a>{M}(result_value, fpcr, rounding, satoflo);
            end;
        end;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fp8float/FP8Infinity" mylink="shared.functions.float.fp8float.FP8Infinity" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FP8Infinity()
// =============

func <anchor link="func_FP8Infinity_3">FP8Infinity</anchor>{N}(fp8type : <a link="type_FP8Type" file="shared_pseudocode.xml">FP8Type</a>, sign : bit) =&gt; bits(N)
begin
    assert N == 8;
    assert fp8type IN {<a link="enum_FP8Type_OFP8_E5M2" file="shared_pseudocode.xml">FP8Type_OFP8_E5M2</a>, <a link="enum_FP8Type_OFP8_E4M3" file="shared_pseudocode.xml">FP8Type_OFP8_E4M3</a>};
    let E : integer{} = if fp8type == <a link="enum_FP8Type_OFP8_E4M3" file="shared_pseudocode.xml">FP8Type_OFP8_E4M3</a> then 4 else 5;
    let F : integer{} = N - (E + 1);
    var exp : bits(E);
    var frac : bits(F);

    case fp8type of
        when <a link="enum_FP8Type_OFP8_E4M3" file="shared_pseudocode.xml">FP8Type_OFP8_E4M3</a> =&gt;
            exp  = Ones{E};
            frac = Ones{F};
        when <a link="enum_FP8Type_OFP8_E5M2" file="shared_pseudocode.xml">FP8Type_OFP8_E5M2</a> =&gt;
            exp  = Ones{E};
            frac = Zeros{F};
    end;

    return sign :: exp :: frac;
end;</pstext></ps>
    <ps name="shared/functions/float/fp8float/FP8MatMulAddFP" mylink="shared.functions.float.fp8float.FP8MatMulAddFP" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FP8MatMulAddFP()
// ================
// 8-bit floating-point matrix multiply with scaling and add to half-precision
// or single-precision matrix.
// result[2, 2] = addend[2, 2] + (op1[2, E] * op2[E, 2])

func <anchor link="func_FP8MatMulAddFP_7">FP8MatMulAddFP</anchor>{N}(addend : bits(N), op1 : bits(N), op2 : bits(N), E : integer{4, 8},
                       fpcr : FPCR_Type, fpmr : FPMR_Type) =&gt; bits(N)
begin
    assert N IN {64, 128};
    assert N == E*16;
    let M : integer{} = N DIV 4;
    var result : bits(N);

    for i = 0 to 1 do
        for j = 0 to 1 do
            let elt1 : bits(2*M) = op1[i*:(2*M)];
            let elt2 : bits(2*M) = op2[j*:(2*M)];
            let sum : bits(M) = addend[(2*i + j)*:M];
            result[(2*i + j)*:M] = <a link="func_FP8DotAddFP_8" file="shared_pseudocode.xml">FP8DotAddFP</a>{M, N DIV 2}(sum, elt1, elt2, E, fpcr, fpmr);
        end;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fp8float/FP8MaxNormal" mylink="shared.functions.float.fp8float.FP8MaxNormal" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FP8MaxNormal()
// ==============

func <anchor link="func_FP8MaxNormal_3">FP8MaxNormal</anchor>{N}(fp8type : <a link="type_FP8Type" file="shared_pseudocode.xml">FP8Type</a>, sign : bit) =&gt; bits(N)
begin
    assert N == 8;
    assert fp8type IN {<a link="enum_FP8Type_OFP8_E5M2" file="shared_pseudocode.xml">FP8Type_OFP8_E5M2</a>, <a link="enum_FP8Type_OFP8_E4M3" file="shared_pseudocode.xml">FP8Type_OFP8_E4M3</a>};
    let E : integer{} = if fp8type == <a link="enum_FP8Type_OFP8_E4M3" file="shared_pseudocode.xml">FP8Type_OFP8_E4M3</a> then 4 else 5;
    let F : integer{} = N - (E + 1);
    var exp : bits(E);
    var frac : bits(F);

    case fp8type of
        when <a link="enum_FP8Type_OFP8_E4M3" file="shared_pseudocode.xml">FP8Type_OFP8_E4M3</a> =&gt;
            exp  = Ones{E};
            frac = Ones{F-1}::'0';
        when <a link="enum_FP8Type_OFP8_E5M2" file="shared_pseudocode.xml">FP8Type_OFP8_E5M2</a> =&gt;
            exp  = Ones{E-1}::'0';
            frac = Ones{F};
    end;

    return sign :: exp :: frac;
end;</pstext></ps>
    <ps name="shared/functions/float/fp8float/FP8MulAddFP" mylink="shared.functions.float.fp8float.FP8MulAddFP" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FP8MulAddFP()
// =============

func <anchor link="func_FP8MulAddFP_6">FP8MulAddFP</anchor>{M}(addend : bits(M), op1 : bits(8), op2 : bits(8), fpcr : FPCR_Type,
                    fpmr : FPMR_Type) =&gt; bits(M)
begin
    assert M IN {16,32};
    let E : integer{} = 1;
    return <a link="func_FP8DotAddFP_8" file="shared_pseudocode.xml">FP8DotAddFP</a>{M, 8}(addend, op1, op2, E, fpcr, fpmr);
end;</pstext></ps>
    <ps name="shared/functions/float/fp8float/FP8Round" mylink="shared.functions.float.fp8float.FP8Round" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FP8Round()
// ==========
// Used by FP8 downconvert instructions which observe FPMR.OSC
// to convert a real number OP into an FP8 value.

func <anchor link="func_FP8Round_5">FP8Round</anchor>{N}(op : real, fp8type : <a link="type_FP8Type" file="shared_pseudocode.xml">FP8Type</a>, fpcr : FPCR_Type, fpmr : FPMR_Type) =&gt; bits(N)
begin
    assert N == 8;
    assert fp8type IN {<a link="enum_FP8Type_OFP8_E5M2" file="shared_pseudocode.xml">FP8Type_OFP8_E5M2</a>, <a link="enum_FP8Type_OFP8_E4M3" file="shared_pseudocode.xml">FP8Type_OFP8_E4M3</a>};
    assert op != 0.0;
    var result : bits(N);

    // Format parameters - minimum exponent, numbers of exponent and fraction bits.
    let (F, minimum_exp) = <a link="func_FP8Bits_1" file="shared_pseudocode.xml">FP8Bits</a>(fp8type);
    let E : integer{} = (N - F) - 1;

    // Split value into sign, unrounded mantissa and exponent.
    var sign : bit;
    var exponent : integer;
    var mantissa : real;
    if op &lt; 0.0 then
        sign = '1';  mantissa = -op;
    else
        sign = '0';  mantissa = op;
    end;

    (mantissa, exponent) = <a link="func_NormalizeReal_1" file="shared_pseudocode.xml">NormalizeReal</a>(mantissa);
    // When TRUE, detection of underflow occurs after rounding.
    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; fpcr.AH == '1';

    var biased_exp_unconstrained : integer = (exponent - minimum_exp) + 1;
    var int_mant_unconstrained : integer= RoundDown(mantissa * 2.0^F);
    let error_unconstrained : real = mantissa * 2.0^F - Real(int_mant_unconstrained);

    // Start creating the exponent value for the result. Start by biasing the actual exponent
    // so that the minimum exponent becomes 1, lower values 0 (indicating possible underflow).
    var biased_exp : integer = Max((exponent - minimum_exp) + 1, 0);
    if biased_exp == 0 then mantissa = mantissa / 2.0^(minimum_exp - exponent); end;

    // Get the unrounded mantissa as an integer, and the &quot;units in last place&quot; rounding error.
    // &lt; 2.0^F if biased_exp == 0, &gt;= 2.0^F if not
    var int_mant : integer = RoundDown(mantissa * 2.0^F);
    var error : real = mantissa * 2.0^F - Real(int_mant);

    let trapped_UF : boolean = fpcr.UFE == '1' &amp;&amp; (!<a link="func_InStreamingMode_0" file="shared_pseudocode.xml">InStreamingMode</a>() || <a link="func_IsFullA64Enabled_0" file="shared_pseudocode.xml">IsFullA64Enabled</a>());

    var round_up_unconstrained : boolean;
    var round_up : boolean;

    if altfp then
        // Round to Nearest Even
        round_up_unconstrained = (error_unconstrained &gt; 0.5 ||
                   (error_unconstrained == 0.5 &amp;&amp; int_mant_unconstrained[0] == '1'));
        round_up = (error &gt; 0.5 || (error == 0.5 &amp;&amp; int_mant[0] == '1'));

        if round_up_unconstrained then
            int_mant_unconstrained = int_mant_unconstrained + 1;
            if int_mant_unconstrained == 2^(F+1) then    // Rounded up to next exponent
                biased_exp_unconstrained = biased_exp_unconstrained + 1;
                int_mant_unconstrained   = int_mant_unconstrained DIV 2;
            end;
        end;

        // Follow alternate floating-point behavior of underflow after rounding
        if (biased_exp_unconstrained &lt; 1 &amp;&amp; int_mant_unconstrained != 0 &amp;&amp;
            (error != 0.0 || trapped_UF)) then
            <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_Underflow" file="shared_pseudocode.xml">FPExc_Underflow</a>, fpcr);
        end;
    else // altfp == FALSE
        // Underflow occurs if exponent is too small before rounding, and result is inexact or
        // the Underflow exception is trapped. This applies before rounding if FPCR.AH != '1'.
        if biased_exp == 0 &amp;&amp; (error != 0.0 || trapped_UF) then
            <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_Underflow" file="shared_pseudocode.xml">FPExc_Underflow</a>, fpcr);
        end;

        // Round to Nearest Even
        round_up = (error &gt; 0.5 || (error == 0.5 &amp;&amp; int_mant[0] == '1'));
    end;

    if round_up then
        int_mant = int_mant + 1;
        if int_mant == 2^F then      // Rounded up from denormalized to normalized
            biased_exp = 1;
        end;
        if int_mant == 2^(F+1) then  // Rounded up to next exponent
            biased_exp = biased_exp + 1;
            int_mant = int_mant DIV 2;
        end;
    end;

    // Deal with overflow and generate result.
    var overflow : boolean;
    case fp8type of
        when <a link="enum_FP8Type_OFP8_E4M3" file="shared_pseudocode.xml">FP8Type_OFP8_E4M3</a> =&gt;
            overflow = biased_exp &gt;= 2^E || (biased_exp == 2^E - 1 &amp;&amp; int_mant == 2^(F+1) - 1);
        when <a link="enum_FP8Type_OFP8_E5M2" file="shared_pseudocode.xml">FP8Type_OFP8_E5M2</a> =&gt;
            overflow = biased_exp &gt;= 2^E - 1;
    end;

    if overflow then
        result = (if fpmr.OSC == '0' then <a link="func_FP8Infinity_3" file="shared_pseudocode.xml">FP8Infinity</a>{N}(fp8type, sign)
                  else <a link="func_FP8MaxNormal_3" file="shared_pseudocode.xml">FP8MaxNormal</a>{N}(fp8type, sign));
        // Flag Overflow exception regardless of FPMR.OSC
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_Overflow" file="shared_pseudocode.xml">FPExc_Overflow</a>, fpcr);
        error = 1.0;  // Ensure that an Inexact exception occurs
    else
        result = sign :: biased_exp[E-1:0] :: int_mant[F-1:0];
    end;

    // Deal with Inexact exception.
    if error != 0.0 then
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_Inexact" file="shared_pseudocode.xml">FPExc_Inexact</a>, fpcr);
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fp8float/FP8Type" mylink="shared.functions.float.fp8float.FP8Type" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FP8Type
// =======

type <anchor link="type_FP8Type">FP8Type</anchor> of enumeration {<anchor link="enum_FP8Type_OFP8_E5M2">FP8Type_OFP8_E5M2</anchor>, <anchor link="enum_FP8Type_OFP8_E4M3">FP8Type_OFP8_E4M3</anchor>, <anchor link="enum_FP8Type_UNSUPPORTED">FP8Type_UNSUPPORTED</anchor>};</pstext></ps>
    <ps name="shared/functions/float/fp8float/FP8Unpack" mylink="shared.functions.float.fp8float.FP8Unpack" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FP8Unpack()
// ===========
// Unpacks an FP8 value into its type, sign bit and real number that
// it represents.

func <anchor link="func_FP8Unpack_3">FP8Unpack</anchor>{N}(fpval : bits(N), fp8type : <a link="type_FP8Type" file="shared_pseudocode.xml">FP8Type</a>) =&gt; (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real)
begin
    assert N == 8;
    let E : integer{} = if fp8type == <a link="enum_FP8Type_OFP8_E4M3" file="shared_pseudocode.xml">FP8Type_OFP8_E4M3</a> then 4 else 5;
    let F : integer{} = N - (E + 1);

    let sign : bit = fpval[N-1];
    let exp : bits(E) = fpval[(E+F)-1:F];
    let frac : bits(F) = fpval[F-1:0];

    var value : real;
    var fptype : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>;

    if fp8type == <a link="enum_FP8Type_OFP8_E4M3" file="shared_pseudocode.xml">FP8Type_OFP8_E4M3</a> then
        if IsZero(exp) then
            if IsZero(frac) then
                fptype = <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>;  value = 0.0;
            else
                fptype = <a link="enum_FPType_Denormal" file="shared_pseudocode.xml">FPType_Denormal</a>;  value = 2.0^-6 * (Real(UInt(frac)) * 2.0^-3);
            end;
        elsif IsOnes(exp) &amp;&amp; IsOnes(frac) then
            fptype = <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>;
            value = 0.0;
        else
            fptype = <a link="enum_FPType_Nonzero" file="shared_pseudocode.xml">FPType_Nonzero</a>;
            value = 2.0^(UInt(exp)-7) * (1.0 + Real(UInt(frac)) * 2.0^-3);
        end;

    elsif fp8type == <a link="enum_FP8Type_OFP8_E5M2" file="shared_pseudocode.xml">FP8Type_OFP8_E5M2</a> then
        if IsZero(exp) then
            if IsZero(frac) then
                fptype = <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>;  value = 0.0;
            else
                fptype = <a link="enum_FPType_Denormal" file="shared_pseudocode.xml">FPType_Denormal</a>;  value = 2.0^-14 * (Real(UInt(frac)) * 2.0^-2);
            end;
        elsif IsOnes(exp) then
            if IsZero(frac) then
                fptype = <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>;  value = 2.0^1000000;
            else
                fptype = if frac[1] == '1' then <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> else <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>;
                value = 0.0;
            end;
        else
            fptype = <a link="enum_FPType_Nonzero" file="shared_pseudocode.xml">FPType_Nonzero</a>;
            value = 2.0^(UInt(exp)-15) * (1.0 + Real(UInt(frac)) * 2.0^-2);
        end;

    else // fp8type == FP8Type_UNSUPPORTED
        fptype = <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>;
        value = 0.0;
    end;

    if sign == '1' then value = -value; end;

    return (fptype, sign, value);
end;</pstext></ps>
    <ps name="shared/functions/float/fp8float/FP8Zero" mylink="shared.functions.float.fp8float.FP8Zero" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FP8Zero()
// =========

func <anchor link="func_FP8Zero_3">FP8Zero</anchor>{N}(fp8type : <a link="type_FP8Type" file="shared_pseudocode.xml">FP8Type</a>, sign : bit) =&gt; bits(N)
begin
    assert N == 8;
    assert fp8type IN {<a link="enum_FP8Type_OFP8_E5M2" file="shared_pseudocode.xml">FP8Type_OFP8_E5M2</a>, <a link="enum_FP8Type_OFP8_E4M3" file="shared_pseudocode.xml">FP8Type_OFP8_E4M3</a>};
    let E : integer{} = if fp8type == <a link="enum_FP8Type_OFP8_E4M3" file="shared_pseudocode.xml">FP8Type_OFP8_E4M3</a> then 4 else 5;
    let F : integer{} = N - (E + 1);
    return sign :: Zeros{E} :: Zeros{F};
end;</pstext></ps>
    <ps name="shared/functions/float/fp8float/FPConvertFP8" mylink="shared.functions.float.fp8float.FPConvertFP8" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPConvertFP8()
// ==============
// Converts a half-precision or single-precision OP to FP8 value.
// The scaling factor in FPMR.NSCALE is applied to the value before rounding.

func <anchor link="func_FPConvertFP8_5">FPConvertFP8</anchor>{M, N}(op : bits(N), fpcr_in : FPCR_Type, fpmr : FPMR_Type) =&gt; bits(M)
begin
    assert N IN {16,32} &amp;&amp; M == 8;
    var result : bits(M);

    let fpexc : boolean = TRUE;
    var fpcr : FPCR_Type = fpcr_in;
    fpcr.[FIZ,FZ,FZ16] = '000';    // Do not flush denormal inputs and outputs to zero
    let fp8type : <a link="type_FP8Type" file="shared_pseudocode.xml">FP8Type</a> = <a link="func_FP8DecodeType_1" file="shared_pseudocode.xml">FP8DecodeType</a>(fpmr.F8D);

    let (fptype,sign,value) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op, fpcr, fpexc);

    if fp8type == <a link="enum_FP8Type_UNSUPPORTED" file="shared_pseudocode.xml">FP8Type_UNSUPPORTED</a> then
        result = Ones{M};
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
    elsif fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || fptype == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        result = <a link="func_FP8DefaultNaN_3" file="shared_pseudocode.xml">FP8DefaultNaN</a>{M}(fp8type, fpcr);     // Always generate Default NaN as result
        if fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
            <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
        end;
    elsif fptype == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a> then
        result = (if fpmr.OSC == '0' then <a link="func_FP8Infinity_3" file="shared_pseudocode.xml">FP8Infinity</a>{M}(fp8type, sign)
                  else <a link="func_FP8MaxNormal_3" file="shared_pseudocode.xml">FP8MaxNormal</a>{M}(fp8type, sign));
    elsif fptype == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then
        result = <a link="func_FP8Zero_3" file="shared_pseudocode.xml">FP8Zero</a>{M}(fp8type, sign);
    else
        let scale : integer = if N == 16 then SInt(fpmr.NSCALE[4:0]) else SInt(fpmr.NSCALE);
        let result_value : real = value * (2.0^scale);
        result = <a link="func_FP8Round_5" file="shared_pseudocode.xml">FP8Round</a>{M}(result_value, fp8type, fpcr, fpmr);
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpabs/FPAbs" mylink="shared.functions.float.fpabs.FPAbs" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPAbs()
// =======

func <anchor link="func_FPAbs_3">FPAbs</anchor>{N}(op : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    if !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; IsFeatureImplemented(FEAT_AFP) then
        if fpcr.AH == '1' then
            let (fptype, -, -) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op, fpcr, FALSE);
            if fptype IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>} then
                return op;       // When fpcr.AH=1, sign of NaN has no consequence
            end;
        end;
    end;
    return '0' :: op[N-2:0];
end;</pstext></ps>
    <ps name="shared/functions/float/fpabsmax/FPAbsMax" mylink="shared.functions.float.fpabsmax.FPAbsMax" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPAbsMax()
// ==========
// Compare absolute value of two operands and return the larger absolute
// value without rounding.

func <anchor link="func_FPAbsMax_4">FPAbsMax</anchor>{N}(op1_in : bits(N), op2_in : bits(N), fpcr_in : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var done : boolean;
    var result : bits(N);
    var fpcr : FPCR_Type  = fpcr_in;
    fpcr.[AH,FIZ,FZ,FZ16] = '0000';

    let op1 = '0'::op1_in[N-2:0];
    let op2 = '0'::op2_in[N-2:0];
    let (type1,-,value1) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr);
    let (type2,-,value2) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr);

    (done,result) = <a link="func_FPProcessNaNs_6" file="shared_pseudocode.xml">FPProcessNaNs</a>{N}(type1, type2, op1_in, op2_in, fpcr);

    if !done then
        // This condition covers all results other than NaNs,
        // including Zero &amp; Infinity
        result = if value1 &gt; value2 then op1 else op2;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpabsmin/FPAbsMin" mylink="shared.functions.float.fpabsmin.FPAbsMin" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPAbsMin()
// ==========
// Compare absolute value of two operands and return the smaller absolute
// value without rounding.

func <anchor link="func_FPAbsMin_4">FPAbsMin</anchor>{N}(op1_in : bits(N), op2_in : bits(N), fpcr_in : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var done : boolean;
    var result : bits(N);
    var fpcr : FPCR_Type = fpcr_in;
    fpcr.[AH,FIZ,FZ,FZ16] = '0000';

    let op1 = '0'::op1_in[N-2:0];
    let op2 = '0'::op2_in[N-2:0];
    let (type1,-,value1) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr);
    let (type2,-,value2) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr);

    (done,result) = <a link="func_FPProcessNaNs_6" file="shared_pseudocode.xml">FPProcessNaNs</a>{N}(type1, type2, op1_in, op2_in, fpcr);

    if !done then
        // This condition covers all results other than NaNs,
        // including Zero &amp; Infinity
        result = if value1 &lt; value2 then op1 else op2;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpadd/FPAdd" mylink="shared.functions.float.fpadd.FPAdd" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPAdd()
// =======

func <anchor link="func_FPAdd_4">FPAdd</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    let fpexc : boolean = TRUE;       // Generate floating-point exceptions
    return <a link="func_FPAdd_5" file="shared_pseudocode.xml">FPAdd</a>{N}(op1, op2, fpcr, fpexc);
end;

// FPAdd()
// =======

func <anchor link="func_FPAdd_5">FPAdd</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type, fpexc : boolean) =&gt; bits(N)
begin

    assert N IN {16,32,64};
    let rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a> = <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr);

    let (type1,sign1,value1) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr, fpexc);
    let (type2,sign2,value2) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr, fpexc);

    var (done,result) = <a link="func_FPProcessNaNs_7" file="shared_pseudocode.xml">FPProcessNaNs</a>{N}(type1, type2, op1, op2, fpcr, fpexc);
    if !done then
        let inf1 : boolean  = (type1 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let inf2 : boolean  = (type2 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let zero1 : boolean = (type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        let zero2 : boolean = (type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        if inf1 &amp;&amp; inf2 &amp;&amp; sign1 == NOT(sign2) then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{N}(fpcr);
            if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;
        elsif (inf1 &amp;&amp; sign1 == '0') || (inf2 &amp;&amp; sign2 == '0') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}('0');
        elsif (inf1 &amp;&amp; sign1 == '1') || (inf2 &amp;&amp; sign2 == '1') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}('1');
        elsif zero1 &amp;&amp; zero2 &amp;&amp; sign1 == sign2 then
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign1);
        else
            let result_value : real = value1 + value2;
            if result_value == 0.0 then  // Sign of exact zero result depends on rounding mode
                let result_sign : bit = if rounding == <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a> then '1' else '0';
                result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(result_sign);
            else
                result = <a link="func_FPRound_5" file="shared_pseudocode.xml">FPRound</a>{N}(result_value, fpcr, rounding, fpexc);
            end;
        end;

        if fpexc then <a link="func_FPProcessDenorms_4" file="shared_pseudocode.xml">FPProcessDenorms</a>(type1, type2, N, fpcr); end;
    end;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpadd/FPAdd_ZA" mylink="shared.functions.float.fpadd.FPAdd_ZA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPAdd_ZA()
// ==========
// Calculates op1+op2 for SME2 ZA-targeting instructions.

func <anchor link="func_FPAdd_ZA_4">FPAdd_ZA</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr_in : FPCR_Type) =&gt; bits(N)
begin
    var fpcr : FPCR_Type = fpcr_in;
    let fpexc : boolean = FALSE; // Do not generate floating-point exceptions
    fpcr.DN = '1';                  // Generate default NaN values
    return <a link="func_FPAdd_5" file="shared_pseudocode.xml">FPAdd</a>{N}(op1, op2, fpcr, fpexc);
end;</pstext></ps>
    <ps name="shared/functions/float/fpbits/FPBits" mylink="shared.functions.float.fpbits.FPBits" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPBits()
// ========
// Returns the minimum exponent, numbers of exponent and fraction bits.

func <anchor link="func_FPBits_2">FPBits</anchor>(N : integer, isbfloat16 : boolean) =&gt; <a link="type_FPBitsType" file="shared_pseudocode.xml">FPBitsType</a>
begin
    var F : <a link="type_FPFracBits" file="shared_pseudocode.xml">FPFracBits</a>;
    var minimum_exp : integer;
    if N == 16 then
        minimum_exp = -14;   F = 10;
    elsif N == 32 &amp;&amp; isbfloat16 then
        minimum_exp = -126;  F = 7;
    elsif N == 32 then
        minimum_exp = -126;  F = 23;
    else  // N == 64
        minimum_exp = -1022; F = 52;
    end;

    return (F, minimum_exp);
end;</pstext></ps>
    <ps name="shared/functions/float/fpbits/FPBitsType" mylink="shared.functions.float.fpbits.FPBitsType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPBitsType
// ==========

type <anchor link="type_FPBitsType">FPBitsType</anchor> of (<a link="type_FPFracBits" file="shared_pseudocode.xml">FPFracBits</a>, integer);</pstext></ps>
    <ps name="shared/functions/float/fpbits/FPFracBits" mylink="shared.functions.float.fpbits.FPFracBits" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPFracBits
// ==========

type <anchor link="type_FPFracBits">FPFracBits</anchor> of integer{2, 3, 7, 10, 23, 52};</pstext></ps>
    <ps name="shared/functions/float/fpcompare/FPCompare" mylink="shared.functions.float.fpcompare.FPCompare" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPCompare()
// ===========

func <anchor link="func_FPCompare_5">FPCompare</anchor>{N}(op1 : bits(N), op2 : bits(N), signal_nans : boolean, fpcr : FPCR_Type) =&gt; bits(4)
begin
    assert N IN {16,32,64};
    let (type1,sign1,value1) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr);
    let (type2,sign2,value2) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr);

    var result : bits(4);
    if type1 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>} || type2 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>} then
        result = '0011';
        if type1 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || type2 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || signal_nans then
            <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
        end;
    else
        // All non-NaN cases can be evaluated on the values produced by FPUnpack()
        if value1 == value2 then
            result = '0110';
        elsif value1 &lt; value2 then
            result = '1000';
        else  // value1 &gt; value2
            result = '0010';
        end;

        <a link="func_FPProcessDenorms_4" file="shared_pseudocode.xml">FPProcessDenorms</a>(type1, type2, N, fpcr);
    end;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpcompareeq/FPCompareEQ" mylink="shared.functions.float.fpcompareeq.FPCompareEQ" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPCompareEQ()
// =============

func <anchor link="func_FPCompareEQ_4">FPCompareEQ</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; boolean
begin
    assert N IN {16,32,64};
    let (type1,sign1,value1) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr);
    let (type2,sign2,value2) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr);

    var result : boolean;
    if type1 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>} || type2 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>} then
        result = FALSE;
        if type1 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || type2 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
            <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
        end;
    else
        // All non-NaN cases can be evaluated on the values produced by FPUnpack()
        result = (value1 == value2);
        <a link="func_FPProcessDenorms_4" file="shared_pseudocode.xml">FPProcessDenorms</a>(type1, type2, N, fpcr);

    end;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpcomparege/FPCompareGE" mylink="shared.functions.float.fpcomparege.FPCompareGE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPCompareGE()
// =============

func <anchor link="func_FPCompareGE_4">FPCompareGE</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; boolean
begin
    assert N IN {16,32,64};
    let (type1,sign1,value1) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr);
    let (type2,sign2,value2) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr);

    var result : boolean;
    if type1 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>} || type2 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>} then
        result = FALSE;
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
    else
        // All non-NaN cases can be evaluated on the values produced by FPUnpack()
        result = (value1 &gt;= value2);
        <a link="func_FPProcessDenorms_4" file="shared_pseudocode.xml">FPProcessDenorms</a>(type1, type2, N, fpcr);

    end;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpcomparegt/FPCompareGT" mylink="shared.functions.float.fpcomparegt.FPCompareGT" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPCompareGT()
// =============

func <anchor link="func_FPCompareGT_4">FPCompareGT</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; boolean
begin
    assert N IN {16,32,64};
    let (type1,sign1,value1) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr);
    let (type2,sign2,value2) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr);

    var result : boolean;
    if type1 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>} || type2 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>} then
        result = FALSE;
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
    else
        // All non-NaN cases can be evaluated on the values produced by FPUnpack()
        result = (value1 &gt; value2);
        <a link="func_FPProcessDenorms_4" file="shared_pseudocode.xml">FPProcessDenorms</a>(type1, type2, N, fpcr);

    end;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpconvert/FPConvert" mylink="shared.functions.float.fpconvert.FPConvert" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPConvert()
// ===========

// Convert floating point 'op' with N-bit precision to M-bit precision,
// with rounding controlled by ROUNDING.
// This is used by the FP-to-FP conversion instructions and so for
// half-precision data ignores FZ16, but observes AHP.

func <anchor link="func_FPConvert_5">FPConvert</anchor>{M, N}(op : bits(N), fpcr : FPCR_Type, rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>) =&gt; bits(M)
begin

    assert M IN {16,32,64};
    assert N IN {16,32,64};
    var result : bits(M);

    // Unpack floating-point operand optionally with flush-to-zero.
    let (fptype,sign,value) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpackCV_3" file="shared_pseudocode.xml">FPUnpackCV</a>{N}(op, fpcr);

    let alt_hp : boolean = (M == 16) &amp;&amp; (fpcr.AHP == '1');

    if fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || fptype == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        if alt_hp then
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{M}(sign);
        elsif fpcr.DN == '1' then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{M}(fpcr);
        else
            result = <a link="func_FPConvertNaN_3" file="shared_pseudocode.xml">FPConvertNaN</a>{M, N}(op);
        end;
        if fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || alt_hp then
            <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>,fpcr);
        end;
    elsif fptype == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a> then
        if alt_hp then
            result = sign::Ones{M-1};
            <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
        else
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{M}(sign);
        end;
    elsif fptype == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then
        result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{M}(sign);
    else
        result = <a link="func_FPRoundCV_4" file="shared_pseudocode.xml">FPRoundCV</a>{M}(value, fpcr, rounding);
        <a link="func_FPProcessDenorm_3" file="shared_pseudocode.xml">FPProcessDenorm</a>(fptype, N, fpcr);

    end;
    return result;
end;

// FPConvert()
// ===========

func <anchor link="func_FPConvert_4">FPConvert</anchor>{M, N}(op : bits(N), fpcr : FPCR_Type) =&gt; bits(M)
begin
    return <a link="func_FPConvert_5" file="shared_pseudocode.xml">FPConvert</a>{M, N}(op, fpcr, <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr));
end;</pstext></ps>
    <ps name="shared/functions/float/fpconvertnan/FPConvertNaN" mylink="shared.functions.float.fpconvertnan.FPConvertNaN" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPConvertNaN()
// ==============
// Converts a NaN of one floating-point type to another

func <anchor link="func_FPConvertNaN_3">FPConvertNaN</anchor>{M, N}(op : bits(N)) =&gt; bits(M)
begin
    assert N IN {16,32,64};
    assert M IN {16,32,64};
    var result : bits(M);
    var frac : bits(51);

    let sign : bit = op[N-1];

    // Unpack payload from input NaN
    case N of
        when 64 =&gt; frac = op[50:0];
        when 32 =&gt; frac = op[21:0]::Zeros{29};
        when 16 =&gt; frac = op[8:0]::Zeros{42};
    end;

    // Repack payload into output NaN, while
    // converting an SNaN to a QNaN.
    case M of
        when 64 =&gt; result = sign::Ones{M-52}::frac;
        when 32 =&gt; result = sign::Ones{M-23}::frac[50:29];
        when 16 =&gt; result = sign::Ones{M-10}::frac[50:42];
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpdecoderm/FPDecodeRM" mylink="shared.functions.float.fpdecoderm.FPDecodeRM" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPDecodeRM()
// ============

// Decode most common AArch32 floating-point rounding encoding.

func <anchor link="func_FPDecodeRM_1">FPDecodeRM</anchor>(rm : bits(2)) =&gt; <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>
begin
    var result : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>;
    case rm of
        when '00' =&gt; result = <a link="enum_FPRounding_TIEAWAY" file="shared_pseudocode.xml">FPRounding_TIEAWAY</a>; // A
        when '01' =&gt; result = <a link="enum_FPRounding_TIEEVEN" file="shared_pseudocode.xml">FPRounding_TIEEVEN</a>; // N
        when '10' =&gt; result = <a link="enum_FPRounding_POSINF" file="shared_pseudocode.xml">FPRounding_POSINF</a>;  // P
        when '11' =&gt; result = <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a>;  // M
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpdecoderounding/FPDecodeRounding" mylink="shared.functions.float.fpdecoderounding.FPDecodeRounding" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPDecodeRounding()
// ==================

// Decode floating-point rounding mode and common AArch64 encoding.

func <anchor link="func_FPDecodeRounding_1">FPDecodeRounding</anchor>(rmode : bits(2)) =&gt; <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>
begin
    case rmode of
        when '00' =&gt; return <a link="enum_FPRounding_TIEEVEN" file="shared_pseudocode.xml">FPRounding_TIEEVEN</a>; // N
        when '01' =&gt; return <a link="enum_FPRounding_POSINF" file="shared_pseudocode.xml">FPRounding_POSINF</a>;  // P
        when '10' =&gt; return <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a>;  // M
        when '11' =&gt; return <a link="enum_FPRounding_ZERO" file="shared_pseudocode.xml">FPRounding_ZERO</a>;    // Z
    end;
end;</pstext></ps>
    <ps name="shared/functions/float/fpdefaultnan/FPDefaultNaN" mylink="shared.functions.float.fpdefaultnan.FPDefaultNaN" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPDefaultNaN()
// ==============

func <anchor link="func_FPDefaultNaN_2">FPDefaultNaN</anchor>{N}(fpcr : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    let E : integer{} = (if N == 16 then 5 else (if N == 32 then 8 else 11));
    let F : integer{} = N - (E + 1);
    let sign : bit = if IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then fpcr.AH else '0';

    let exp : bits(E)  = Ones{};
    let frac : bits(F) = '1'::Zeros{F-1};
    return sign :: exp :: frac;
end;</pstext></ps>
    <ps name="shared/functions/float/fpdiv/FPDiv" mylink="shared.functions.float.fpdiv.FPDiv" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPDiv()
// =======

func <anchor link="func_FPDiv_4">FPDiv</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    let (type1,sign1,value1) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr);
    let (type2,sign2,value2) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr);
    var (done,result) : (boolean, bits(N)) = <a link="func_FPProcessNaNs_6" file="shared_pseudocode.xml">FPProcessNaNs</a>{N}(type1, type2, op1, op2, fpcr);

    if !done then
        let inf1 : boolean  = type1 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>;
        let inf2 : boolean  = type2 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>;
        let zero1 : boolean = type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>;
        let zero2 : boolean = type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>;

        if (inf1 &amp;&amp; inf2) || (zero1 &amp;&amp; zero2) then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{N}(fpcr);
            <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
        elsif inf1 || zero2 then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}(sign1 XOR sign2);
            if !inf1 then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_DivideByZero" file="shared_pseudocode.xml">FPExc_DivideByZero</a>, fpcr); end;
        elsif zero1 || inf2 then
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign1 XOR sign2);
        else
            result = <a link="func_FPRound_3" file="shared_pseudocode.xml">FPRound</a>{N}(value1/value2, fpcr);
        end;

        if !zero2 then
            <a link="func_FPProcessDenorms_4" file="shared_pseudocode.xml">FPProcessDenorms</a>(type1, type2, N, fpcr);
        end;
    end;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpdot/FPDot" mylink="shared.functions.float.fpdot.FPDot" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPDot()
// =======
// Calculates single-precision result of 2-way 16-bit floating-point dot-product
// with a single rounding.
// The 'fpcr' argument supplies the FPCR control bits and 'isbfloat16'
// determines whether input operands are BFloat16 or half-precision type.
// and 'fpexc' controls the generation of floating-point exceptions.

func <anchor link="func_FPDot_6">FPDot</anchor>(op1_a : bits(16), op1_b : bits(16), op2_a : bits(16),
           op2_b : bits(16), fpcr : FPCR_Type, isbfloat16 : boolean) =&gt; bits(32)
begin
    let fpexc : boolean = TRUE;       // Generate floating-point exceptions
    return <a link="func_FPDot_7" file="shared_pseudocode.xml">FPDot</a>(op1_a, op1_b, op2_a, op2_b, fpcr, isbfloat16, fpexc);
end;

func <anchor link="func_FPDot_7">FPDot</anchor>(op1_a : bits(16), op1_b : bits(16), op2_a : bits(16),
           op2_b : bits(16), fpcr_in : FPCR_Type, isbfloat16 : boolean, fpexc : boolean) =&gt; bits(32)
begin
    var fpcr : FPCR_Type = fpcr_in;
    var result : bits(32);
    var done : boolean;
    fpcr.AHP = '0';           // Ignore alternative half-precision option
    let rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a> = <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr);

    let (type1_a,sign1_a,value1_a) = <a link="func_FPUnpackBase_5" file="shared_pseudocode.xml">FPUnpackBase</a>{16}(op1_a, fpcr, fpexc, isbfloat16);
    let (type1_b,sign1_b,value1_b) = <a link="func_FPUnpackBase_5" file="shared_pseudocode.xml">FPUnpackBase</a>{16}(op1_b, fpcr, fpexc, isbfloat16);
    let (type2_a,sign2_a,value2_a) = <a link="func_FPUnpackBase_5" file="shared_pseudocode.xml">FPUnpackBase</a>{16}(op2_a, fpcr, fpexc, isbfloat16);
    let (type2_b,sign2_b,value2_b) = <a link="func_FPUnpackBase_5" file="shared_pseudocode.xml">FPUnpackBase</a>{16}(op2_b, fpcr, fpexc, isbfloat16);

    let inf1_a = (type1_a == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>); let zero1_a = (type1_a == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
    let inf1_b = (type1_b == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>); let zero1_b = (type1_b == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
    let inf2_a = (type2_a == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>); let zero2_a = (type2_a == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
    let inf2_b = (type2_b == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>); let zero2_b = (type2_b == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);

    (done,result) = <a link="func_FPProcessNaNs4_10" file="shared_pseudocode.xml">FPProcessNaNs4</a>(type1_a, type1_b, type2_a, type2_b,
                                   op1_a, op1_b, op2_a, op2_b, fpcr, fpexc);

    if !done then
        // Determine sign and type products will have if it does not cause an Invalid
        // Operation.
        let signPa = sign1_a XOR sign2_a;
        let signPb = sign1_b XOR sign2_b;
        let infPa  = inf1_a || inf2_a;
        let infPb  = inf1_b || inf2_b;
        let zeroPa = zero1_a || zero2_a;
        let zeroPb = zero1_b || zero2_b;

        // Non SNaN-generated Invalid Operation cases are multiplies of zero
        // by infinity and additions of opposite-signed infinities.
        let invalidop = ((inf1_a &amp;&amp; zero2_a) || (zero1_a &amp;&amp; inf2_a) ||
                         (inf1_b &amp;&amp; zero2_b) || (zero1_b &amp;&amp; inf2_b) ||
                         (infPa &amp;&amp; infPb &amp;&amp; signPa != signPb));

        if invalidop then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{32}(fpcr);
            if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;

       // Other cases involving infinities produce an infinity of the same sign.
        elsif (infPa &amp;&amp; signPa == '0') || (infPb &amp;&amp; signPb == '0') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{32}('0');
        elsif (infPa &amp;&amp; signPa == '1') || (infPb &amp;&amp; signPb == '1') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{32}('1');

        // Cases where the result is exactly zero and its sign is not determined by the
        // rounding mode are additions of same-signed zeros.
        elsif zeroPa &amp;&amp; zeroPb &amp;&amp; signPa == signPb then
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{32}(signPa);

        // Otherwise calculate fused sum of products and round it.
        else
            let result_value = (value1_a * value2_a) + (value1_b * value2_b);
            if result_value == 0.0 then  // Sign of exact zero result depends on rounding mode
                let result_sign = if rounding == <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a> then '1' else '0';
                result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{32}(result_sign);
            else
                result = <a link="func_FPRound_5" file="shared_pseudocode.xml">FPRound</a>{32}(result_value, fpcr, rounding, fpexc);
            end;
        end;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpdot/FPDotAdd" mylink="shared.functions.float.fpdot.FPDotAdd" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPDotAdd()
// ==========
// Half-precision 2-way dot-product and add to single-precision.

func <anchor link="func_FPDotAdd_6">FPDotAdd</anchor>(addend : bits(32), op1_a : bits(16), op1_b : bits(16),
              op2_a : bits(16), op2_b : bits(16), fpcr : FPCR_Type) =&gt; bits(32)
begin
    var prod : bits(32);
    let isbfloat16 : boolean = FALSE;
    let fpexc : boolean      = TRUE;     // Generate floating-point exceptions
    prod = <a link="func_FPDot_7" file="shared_pseudocode.xml">FPDot</a>(op1_a, op1_b, op2_a, op2_b, fpcr, isbfloat16, fpexc);
    let result : bits(32) = <a link="func_FPAdd_4" file="shared_pseudocode.xml">FPAdd</a>{}(addend, prod, fpcr, fpexc);

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpdot/FPDotAdd_ZA" mylink="shared.functions.float.fpdot.FPDotAdd_ZA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPDotAdd_ZA()
// =============
// Half-precision 2-way dot-product and add to single-precision
// for SME ZA-targeting instructions.

func <anchor link="func_FPDotAdd_ZA_6">FPDotAdd_ZA</anchor>(addend : bits(32), op1_a : bits(16), op1_b : bits(16),
                 op2_a : bits(16), op2_b : bits(16), fpcr_in : FPCR_Type) =&gt; bits(32)
begin
    var fpcr : FPCR_Type = fpcr_in;
    var prod : bits(32);
    let isbfloat16 : boolean = FALSE;
    let fpexc : boolean      = FALSE; // Do not generate floating-point exceptions
    fpcr.DN = '1';                    // Generate default NaN values
    prod = <a link="func_FPDot_7" file="shared_pseudocode.xml">FPDot</a>(op1_a, op1_b, op2_a, op2_b, fpcr, isbfloat16, fpexc);
    let result : bits(32) = <a link="func_FPAdd_4" file="shared_pseudocode.xml">FPAdd</a>{}(addend, prod, fpcr, fpexc);

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpexc/FPExc" mylink="shared.functions.float.fpexc.FPExc" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPExc
// =====

type <anchor link="type_FPExc">FPExc</anchor> of enumeration {<anchor link="enum_FPExc_InvalidOp">FPExc_InvalidOp</anchor>, <anchor link="enum_FPExc_DivideByZero">FPExc_DivideByZero</anchor>, <anchor link="enum_FPExc_Overflow">FPExc_Overflow</anchor>,
                           <anchor link="enum_FPExc_Underflow">FPExc_Underflow</anchor>, <anchor link="enum_FPExc_Inexact">FPExc_Inexact</anchor>, <anchor link="enum_FPExc_InputDenorm">FPExc_InputDenorm</anchor>};</pstext></ps>
    <ps name="shared/functions/float/fpinfinity/FPInfinity" mylink="shared.functions.float.fpinfinity.FPInfinity" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPInfinity()
// ============

func <anchor link="func_FPInfinity_2">FPInfinity</anchor>{N}(sign : bit) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    let E : integer{}  = (if N == 16 then 5 else (if N == 32 then 8 else 11));
    let F : integer{}  = N - (E + 1);
    let exp : bits(E)  = Ones{};
    let frac : bits(F) = Zeros{};
    return sign :: exp :: frac;
end;</pstext></ps>
    <ps name="shared/functions/float/fpmatmul/FPMatMulAdd" mylink="shared.functions.float.fpmatmul.FPMatMulAdd" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPMatMulAdd()
// =============
//
// Floating point matrix multiply and add to same precision matrix
// result[2, 2] = addend[2, 2] + (op1[2, 2] * op2[2, 2])

func <anchor link="func_FPMatMulAdd_6">FPMatMulAdd</anchor>{N}(addend : bits(N), op1 : bits(N), op2 : bits(N),
                    esize : <a link="type_ESize" file="shared_pseudocode.xml">ESize</a>, fpcr : FPCR_Type) =&gt; bits(N)
begin
    assert N == esize * 2 * 2;
    var result : bits(N);
    var prod0, prod1, sum : bits(esize);

    for i = 0 to 1 do
        for j = 0 to 1 do
            sum   = addend[(2*i + j)*:esize];
            prod0 = <a link="func_FPMul_4" file="shared_pseudocode.xml">FPMul</a>{esize}(op1[(2*i + 0)*:esize],
                          op2[(2*j + 0)*:esize], fpcr);
            prod1 = <a link="func_FPMul_4" file="shared_pseudocode.xml">FPMul</a>{esize}(op1[(2*i + 1)*:esize],
                          op2[(2*j + 1)*:esize], fpcr);
            sum   = <a link="func_FPAdd_4" file="shared_pseudocode.xml">FPAdd</a>{esize}(sum, <a link="func_FPAdd_4" file="shared_pseudocode.xml">FPAdd</a>{esize}(prod0, prod1, fpcr), fpcr);
            result[(2*i + j)*:esize] = sum;
        end;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpmatmulh/FPMatMulAddH" mylink="shared.functions.float.fpmatmulh.FPMatMulAddH" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPMatMulAddH()
// ==============
// Half-precision matrix multiply and add to single-precision matrix
// result[2, 2] = addend[2, 2] + (op1[2, 4] * op2[4, 2])

func <anchor link="func_FPMatMulAddH_5">FPMatMulAddH</anchor>{N}(addend : bits(N), op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    assert N == 128;
    let M : integer{} = 32;
    var result : bits(N);

    let isbfloat16 : boolean = FALSE;
    for i = 0 to 1 do
        for j = 0 to 1 do
            var sum : bits(M) = addend[(2*i + j)*:M];
            var prod : array[[2]] of bits(M);
            for k = 0 to 1 do
                let elt1_a : bits(M DIV 2) = op1[(4*i + 2*k + 0)*:(M DIV 2)];
                let elt1_b : bits(M DIV 2) = op1[(4*i + 2*k + 1)*:(M DIV 2)];
                let elt2_a : bits(M DIV 2) = op2[(4*j + 2*k + 0)*:(M DIV 2)];
                let elt2_b : bits(M DIV 2) = op2[(4*j + 2*k + 1)*:(M DIV 2)];
                prod[[k]] = <a link="func_FPDot_6" file="shared_pseudocode.xml">FPDot</a>(elt1_a, elt1_b, elt2_a, elt2_b, fpcr, isbfloat16);
            end;
            sum = <a link="func_FPAdd_4" file="shared_pseudocode.xml">FPAdd</a>{M}(sum, <a link="func_FPAdd_4" file="shared_pseudocode.xml">FPAdd</a>{M}(prod[[0]], prod[[1]], fpcr), fpcr);
            result[(2*i + j)*:M] = sum;
        end;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpmax/FPMax" mylink="shared.functions.float.fpmax.FPMax" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPMax()
// =======

func <anchor link="func_FPMax_4">FPMax</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    let fpexc : boolean = TRUE;
    return <a link="func_FPMax_6" file="shared_pseudocode.xml">FPMax</a>{N}(op1, op2, fpcr, altfp, fpexc);
end;

// FPMax()
// =======

func <anchor link="func_FPMax_5">FPMax</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type, altfp : boolean) =&gt; bits(N)
begin
    let fpexc : boolean = TRUE;
    return <a link="func_FPMax_6" file="shared_pseudocode.xml">FPMax</a>{N}(op1, op2, fpcr, altfp, fpexc);
end;

// FPMax()
// =======
// Compare two inputs and return the larger value after rounding. The
// 'fpcr' argument supplies the FPCR control bits and 'altfp' determines
// if the function should use alternative floating-point behavior.

func <anchor link="func_FPMax_6">FPMax</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr_in : FPCR_Type,
              altfp : boolean, fpexc : boolean) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var done : boolean;
    var result : bits(N);
    var fpcr : FPCR_Type = fpcr_in;
    let (type1,sign1,value1) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr, fpexc);
    let (type2,sign2,value2) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr, fpexc);

    if altfp &amp;&amp; type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> &amp;&amp; type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> &amp;&amp; sign1 != sign2 then
        // Alternate handling of zeros with differing sign
        return <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign2);
    elsif altfp &amp;&amp; (type1 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>} || type2 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>}) then
        // Alternate handling of NaN inputs
        if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;
        return (if type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign2) else op2);
    end;

    (done,result) = <a link="func_FPProcessNaNs_7" file="shared_pseudocode.xml">FPProcessNaNs</a>{N}(type1, type2, op1, op2, fpcr, fpexc);
    if !done then
        var fptype : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>;
        var sign : bit;
        var value : real;
        if value1 &gt; value2 then
            (fptype,sign,value) = (type1,sign1,value1);
        else
            (fptype,sign,value) = (type2,sign2,value2);
        end;
        if fptype == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a> then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}(sign);
        elsif fptype == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then
            sign = sign1 AND sign2;         // Use most positive sign
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign);
        else
            // The use of FPRound() covers the case where there is a trapped underflow exception
            // for a denormalized number even though the result is exact.
            let rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a> = <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr);
            if altfp then    // Denormal output is not flushed to zero
                fpcr.FZ = '0';
                fpcr.FZ16 = '0';
            end;

            result = <a link="func_FPRound_5" file="shared_pseudocode.xml">FPRound</a>{N}(value, fpcr, rounding, fpexc);
        end;
        if fpexc then <a link="func_FPProcessDenorms_4" file="shared_pseudocode.xml">FPProcessDenorms</a>(type1, type2, N, fpcr); end;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpmaxnormal/FPMaxNormal" mylink="shared.functions.float.fpmaxnormal.FPMaxNormal" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPMaxNormal()
// =============

func <anchor link="func_FPMaxNormal_2">FPMaxNormal</anchor>{N}(sign : bit) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    let E : integer{}  = (if N == 16 then 5 else (if N == 32 then 8 else 11));
    let F : integer{}  = N - (E + 1);
    let exp : bits(E)  = Ones{E-1}::'0';
    let frac : bits(F) = Ones{};
    return sign :: exp :: frac;
end;</pstext></ps>
    <ps name="shared/functions/float/fpmaxnum/FPMaxNum" mylink="shared.functions.float.fpmaxnum.FPMaxNum" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPMaxNum()
// ==========

func <anchor link="func_FPMaxNum_4">FPMaxNum</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    let fpexc : boolean = TRUE;
    return <a link="func_FPMaxNum_5" file="shared_pseudocode.xml">FPMaxNum</a>{N}(op1, op2, fpcr, fpexc);
end;

// FPMaxNum()
// ==========

func <anchor link="func_FPMaxNum_5">FPMaxNum</anchor>{N}(op1_in : bits(N), op2_in : bits(N), fpcr : FPCR_Type, fpexc : boolean) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var op1 : bits(N) = op1_in;
    var op2 : bits(N) = op2_in;
    let (type1,-,-) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr, fpexc);
    let (type2,-,-) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr, fpexc);

    let type1_nan : boolean = type1 IN {<a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>, <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>};
    let type2_nan : boolean = type2 IN {<a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>, <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>};
    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';

    if !(altfp &amp;&amp; type1_nan &amp;&amp; type2_nan) then
        // Treat a single quiet-NaN as -Infinity.
        if type1 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> &amp;&amp; type2 != <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
            op1 = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}('1');
        elsif type1 != <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> &amp;&amp; type2 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
            op2 = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}('1');
        end;
    end;

    let altfmaxfmin : boolean = FALSE;    // Restrict use of FMAX/FMIN NaN propagation rules
    let result : bits(N) = <a link="func_FPMax_5" file="shared_pseudocode.xml">FPMax</a>{}(op1, op2, fpcr, altfmaxfmin, fpexc);

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpmerge/IsMerging" mylink="shared.functions.float.fpmerge.IsMerging" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsMerging()
// ===========
// Returns TRUE if the output elements other than the lowest are taken from
// the destination register.

func <anchor link="func_IsMerging_1">IsMerging</anchor>(fpcr : FPCR_Type) =&gt; boolean
begin
    let nep : bit = (if IsFeatureImplemented(FEAT_SME) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM == '1' &amp;&amp;
                        !<a link="func_IsFullA64Enabled_0" file="shared_pseudocode.xml">IsFullA64Enabled</a>() then '0' else fpcr.NEP);
    return IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; nep == '1';
end;</pstext></ps>
    <ps name="shared/functions/float/fpmin/FPMin" mylink="shared.functions.float.fpmin.FPMin" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPMin()
// =======

func <anchor link="func_FPMin_4">FPMin</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    let fpexc : boolean = TRUE;
    return <a link="func_FPMin_6" file="shared_pseudocode.xml">FPMin</a>{N}(op1, op2, fpcr, altfp, fpexc);
end;

// FPMin()
// =======

func <anchor link="func_FPMin_5">FPMin</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type, altfp : boolean) =&gt; bits(N)
begin
    let fpexc : boolean = TRUE;
    return <a link="func_FPMin_6" file="shared_pseudocode.xml">FPMin</a>{N}(op1, op2, fpcr, altfp, fpexc);
end;

// FPMin()
// =======
// Compare two inputs and return the smaller operand after rounding. The
// 'fpcr' argument supplies the FPCR control bits and 'altfp' determines
// if the function should use alternative floating-point behavior.

func <anchor link="func_FPMin_6">FPMin</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr_in : FPCR_Type,
              altfp : boolean, fpexc : boolean) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var done : boolean;
    var result : bits(N);
    var fpcr : FPCR_Type = fpcr_in;
    let (type1,sign1,value1) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr, fpexc);
    let (type2,sign2,value2) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr, fpexc);

    if altfp &amp;&amp; type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> &amp;&amp; type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> &amp;&amp; sign1 != sign2 then
        // Alternate handling of zeros with differing sign
        return <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign2);
    elsif altfp &amp;&amp; (type1 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>} || type2 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>}) then
        // Alternate handling of NaN inputs
        if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;
        return (if type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign2) else op2);
    end;

    (done,result) = <a link="func_FPProcessNaNs_7" file="shared_pseudocode.xml">FPProcessNaNs</a>{N}(type1, type2, op1, op2, fpcr, fpexc);
    if !done then
        var fptype : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>;
        var sign : bit;
        var value : real;
        var rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>;
        if value1 &lt; value2 then
            (fptype,sign,value) = (type1,sign1,value1);
        else
            (fptype,sign,value) = (type2,sign2,value2);
        end;
        if fptype == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a> then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}(sign);
        elsif fptype == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then
            sign = sign1 OR sign2;              // Use most negative sign
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign);
        else
            // The use of FPRound() covers the case where there is a trapped underflow exception
            // for a denormalized number even though the result is exact.
            rounding = <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr);
            if altfp then    // Denormal output is not flushed to zero
                fpcr.FZ = '0';
                fpcr.FZ16 = '0';
            end;

            result = <a link="func_FPRound_5" file="shared_pseudocode.xml">FPRound</a>{N}(value, fpcr, rounding, fpexc);
        end;

        if fpexc then <a link="func_FPProcessDenorms_4" file="shared_pseudocode.xml">FPProcessDenorms</a>(type1, type2, N, fpcr); end;
    end;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpminnum/FPMinNum" mylink="shared.functions.float.fpminnum.FPMinNum" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPMinNum()
// ==========

func <anchor link="func_FPMinNum_4">FPMinNum</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    let fpexc : boolean = TRUE;
    return <a link="func_FPMinNum_5" file="shared_pseudocode.xml">FPMinNum</a>{N}(op1, op2, fpcr, fpexc);
end;

// FPMinNum()
// ==========

func <anchor link="func_FPMinNum_5">FPMinNum</anchor>{N}(op1_in : bits(N), op2_in : bits(N), fpcr : FPCR_Type, fpexc : boolean) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var op1 : bits(N) = op1_in;
    var op2 : bits(N) = op2_in;
    let (type1,-,-) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr, fpexc);
    let (type2,-,-) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr, fpexc);

    let type1_nan : boolean = type1 IN {<a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>, <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>};
    let type2_nan : boolean = type2 IN {<a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>, <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>};
    let altfp : boolean     = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp;
                                                                 fpcr.AH == '1';

    if !(altfp &amp;&amp; type1_nan &amp;&amp; type2_nan) then
        // Treat a single quiet-NaN as +Infinity.
        if type1 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> &amp;&amp; type2 != <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
            op1 = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}('0');
        elsif type1 != <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> &amp;&amp; type2 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
            op2 = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}('0');
        end;
    end;

    let altfmaxfmin : boolean = FALSE;    // Restrict use of FMAX/FMIN NaN propagation rules
    let result : bits(N) = <a link="func_FPMin_5" file="shared_pseudocode.xml">FPMin</a>{}(op1, op2, fpcr, altfmaxfmin, fpexc);

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpmul/FPMul" mylink="shared.functions.float.fpmul.FPMul" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPMul()
// =======

func <anchor link="func_FPMul_4">FPMul</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    let (type1,sign1,value1) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr);
    let (type2,sign2,value2) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr);
    var (done,result) : (boolean, bits(N)) = <a link="func_FPProcessNaNs_6" file="shared_pseudocode.xml">FPProcessNaNs</a>{N}(type1, type2, op1, op2, fpcr);
    if !done then
        let inf1 : boolean  = (type1 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let inf2 : boolean  = (type2 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let zero1 : boolean = (type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        let zero2 : boolean = (type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);

        if (inf1 &amp;&amp; zero2) || (zero1 &amp;&amp; inf2) then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{N}(fpcr);
            <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
        elsif inf1 || inf2 then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}(sign1 XOR sign2);
        elsif zero1 || zero2 then
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign1 XOR sign2);
        else
            result = <a link="func_FPRound_3" file="shared_pseudocode.xml">FPRound</a>{N}(value1*value2, fpcr);
        end;

        <a link="func_FPProcessDenorms_4" file="shared_pseudocode.xml">FPProcessDenorms</a>(type1, type2, N, fpcr);

    end;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpmuladd/FPMulAdd" mylink="shared.functions.float.fpmuladd.FPMulAdd" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPMulAdd()
// ==========

func <anchor link="func_FPMulAdd_5">FPMulAdd</anchor>{N}(addend : bits(N), op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    let fpexc : boolean = TRUE;       // Generate floating-point exceptions
    return <a link="func_FPMulAdd_6" file="shared_pseudocode.xml">FPMulAdd</a>{N}(addend, op1, op2, fpcr, fpexc);
end;

// FPMulAdd()
// ==========
//
// Calculates addend + op1*op2 with a single rounding. The 'fpcr' argument
// supplies the FPCR control bits, and 'fpexc' controls the generation of
// floating-point exceptions.

func <anchor link="func_FPMulAdd_6">FPMulAdd</anchor>{N}(addend : bits(N), op1 : bits(N), op2 : bits(N),
                 fpcr : FPCR_Type, fpexc : boolean) =&gt; bits(N)
begin
    assert N IN {16,32,64};

    let (typeA,signA,valueA) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(addend, fpcr, fpexc);
    let (type1,sign1,value1) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr, fpexc);
    let (type2,sign2,value2) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr, fpexc);
    let rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a> = <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr);
    let inf1 : boolean = (type1 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>); let zero1 : boolean = (type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
    let inf2 : boolean = (type2 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>); let zero2 : boolean = (type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);

    var (done,result) = <a link="func_FPProcessNaNs3_9" file="shared_pseudocode.xml">FPProcessNaNs3</a>{N}(typeA, type1, type2, addend, op1, op2, fpcr, fpexc);

    if !(IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1') then
        if typeA == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> &amp;&amp; ((inf1 &amp;&amp; zero2) || (zero1 &amp;&amp; inf2)) then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{N}(fpcr);
            if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;
        end;
    end;

    if !done then
        let infA : boolean = (typeA == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let zeroA : boolean = (typeA == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);

        // Determine sign and type product will have if it does not cause an
        // Invalid Operation.
        let signP : bit = sign1 XOR sign2;
        let infP : boolean  = inf1 || inf2;
        let zeroP : boolean = zero1 || zero2;

        // Non SNaN-generated Invalid Operation cases are multiplies of zero
        // by infinity and additions of opposite-signed infinities.
        let invalidop : boolean = ((inf1 &amp;&amp; zero2) || (zero1 &amp;&amp; inf2) ||
                                    (infA &amp;&amp; infP &amp;&amp; signA != signP));

        if invalidop then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{N}(fpcr);
            if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;
        // Other cases involving infinities produce an infinity of the same sign.
        elsif (infA &amp;&amp; signA == '0') || (infP &amp;&amp; signP == '0') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}('0');
        elsif (infA &amp;&amp; signA == '1') || (infP &amp;&amp; signP == '1') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}('1');

        // Cases where the result is exactly zero and its sign is not determined by the
        // rounding mode are additions of same-signed zeros.
        elsif zeroA &amp;&amp; zeroP &amp;&amp; signA == signP then
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(signA);

        // Otherwise calculate numerical result and round it.
        else
            let result_value : real = valueA + (value1 * value2);
            if result_value == 0.0 then  // Sign of exact zero result depends on rounding mode
                let result_sign : bit = if rounding == <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a> then '1' else '0';
                result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(result_sign);
            else
                result = <a link="func_FPRound_5" file="shared_pseudocode.xml">FPRound</a>{N}(result_value, fpcr, rounding, fpexc);
            end;
        end;

        if !invalidop &amp;&amp; fpexc then
            <a link="func_FPProcessDenorms3_5" file="shared_pseudocode.xml">FPProcessDenorms3</a>(typeA, type1, type2, N, fpcr);
        end;
    end;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpmuladd/FPMulAdd_ZA" mylink="shared.functions.float.fpmuladd.FPMulAdd_ZA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPMulAdd_ZA()
// =============
// Calculates addend + op1*op2 with a single rounding for SME ZA-targeting
// instructions.

func <anchor link="func_FPMulAdd_ZA_5">FPMulAdd_ZA</anchor>{N}(addend : bits(N), op1 : bits(N), op2 : bits(N), fpcr_in : FPCR_Type) =&gt; bits(N)
begin
    var fpcr : FPCR_Type = fpcr_in;
    let fpexc : boolean  = FALSE; // Do not generate floating-point exceptions
    fpcr.DN = '1';                // Generate default NaN values
    return <a link="func_FPMulAdd_6" file="shared_pseudocode.xml">FPMulAdd</a>{N}(addend, op1, op2, fpcr, fpexc);
end;</pstext></ps>
    <ps name="shared/functions/float/fpmuladdh/FPMulAddH" mylink="shared.functions.float.fpmuladdh.FPMulAddH" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPMulAddH()
// ===========
// Calculates addend + op1*op2.

func <anchor link="func_FPMulAddH_4">FPMulAddH</anchor>(addend : bits(32), op1 : bits(16), op2 : bits(16), fpcr : FPCR_Type) =&gt; bits(32)
begin
    let fpexc : boolean = TRUE;       // Generate floating-point exceptions
    return <a link="func_FPMulAddH_5" file="shared_pseudocode.xml">FPMulAddH</a>(addend, op1, op2, fpcr, fpexc);
end;

// FPMulAddH()
// ===========
// Calculates addend + op1*op2.

func <anchor link="func_FPMulAddH_5">FPMulAddH</anchor>(addend : bits(32), op1 : bits(16), op2 : bits(16),
               fpcr : FPCR_Type, fpexc : boolean) =&gt; bits(32)
begin

    let rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a> = <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr);
    let (typeA,signA,valueA)  = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{32}(addend, fpcr, fpexc);
    let (type1,sign1,value1)  = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{16}(op1, fpcr, fpexc);
    let (type2,sign2,value2)  = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{16}(op2, fpcr, fpexc);
    let inf1 = (type1 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>); let zero1 = (type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
    let inf2 = (type2 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>); let zero2 = (type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);

    var (done,result) = <a link="func_FPProcessNaNs3H_8" file="shared_pseudocode.xml">FPProcessNaNs3H</a>(typeA, type1, type2, addend, op1, op2, fpcr, fpexc);

    if !(IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1') then
        if typeA == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> &amp;&amp; ((inf1 &amp;&amp; zero2) || (zero1 &amp;&amp; inf2)) then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{32}(fpcr);
            if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;
        end;
    end;

    if !done then
        let infA = (typeA == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>); let zeroA = (typeA == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);

        // Determine sign and type product will have if it does not cause an
        // Invalid Operation.
        let signP = sign1 XOR sign2;
        let infP  = inf1 || inf2;
        let zeroP = zero1 || zero2;

        // Non SNaN-generated Invalid Operation cases are multiplies of zero by infinity and
        // additions of opposite-signed infinities.
        let invalidop = (inf1 &amp;&amp; zero2) || (zero1 &amp;&amp; inf2) || (infA &amp;&amp; infP &amp;&amp; signA != signP);

        if invalidop then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{32}(fpcr);
            if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;

        // Other cases involving infinities produce an infinity of the same sign.
        elsif (infA &amp;&amp; signA == '0') || (infP &amp;&amp; signP == '0') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{32}('0');
        elsif (infA &amp;&amp; signA == '1') || (infP &amp;&amp; signP == '1') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{32}('1');

        // Cases where the result is exactly zero and its sign is not determined by the
        // rounding mode are additions of same-signed zeros.
        elsif zeroA &amp;&amp; zeroP &amp;&amp; signA == signP then
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{32}(signA);

        // Otherwise calculate numerical result and round it.
        else
            let result_value = valueA + (value1 * value2);
            if result_value == 0.0 then // Sign of exact zero result depends on rounding mode
                let result_sign = if rounding == <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a> then '1' else '0';
                result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{32}(result_sign);
            else
                result = <a link="func_FPRound_5" file="shared_pseudocode.xml">FPRound</a>{32}(result_value, fpcr, rounding, fpexc);
            end;
        end;

        if !invalidop &amp;&amp; fpexc then
            <a link="func_FPProcessDenorm_3" file="shared_pseudocode.xml">FPProcessDenorm</a>(typeA, 32, fpcr);
        end;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpmuladdh/FPMulAddH_ZA" mylink="shared.functions.float.fpmuladdh.FPMulAddH_ZA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPMulAddH_ZA()
// ==============
// Calculates addend + op1*op2 for SME2 ZA-targeting instructions.

func <anchor link="func_FPMulAddH_ZA_4">FPMulAddH_ZA</anchor>(addend : bits(32), op1 : bits(16), op2 : bits(16),
                  fpcr_in : FPCR_Type) =&gt; bits(32)
begin
    var fpcr : FPCR_Type = fpcr_in;
    let fpexc : boolean = FALSE; // Do not generate floating-point exceptions
    fpcr.DN = '1';               // Generate default NaN values
    return <a link="func_FPMulAddH_5" file="shared_pseudocode.xml">FPMulAddH</a>(addend, op1, op2, fpcr, fpexc);
end;</pstext></ps>
    <ps name="shared/functions/float/fpmuladdh/FPProcessNaNs3H" mylink="shared.functions.float.fpmuladdh.FPProcessNaNs3H" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPProcessNaNs3H()
// =================

func <anchor link="func_FPProcessNaNs3H_8">FPProcessNaNs3H</anchor>(type1 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, type2 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, type3 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>,
                     op1 : bits(32), op2 : bits(16), op3 : bits(16),
                     fpcr : FPCR_Type, fpexc : boolean) =&gt; (boolean, bits(32))
begin

    var result : bits(32);
    var type_nan : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>;
    // When TRUE, use alternative NaN propagation rules.
    let altfp : boolean   = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    let op1_nan : boolean = type1 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>};
    let op2_nan : boolean = type2 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>};
    let op3_nan : boolean = type3 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>};
    if altfp then
        if (type1 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || type2 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || type3 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>) then
            type_nan = <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>;
        else
            type_nan = <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>;
        end;
    end;

    var done : boolean;
    if altfp &amp;&amp; op1_nan &amp;&amp; op2_nan &amp;&amp; op3_nan then          // [n] register NaN selected
        done = TRUE;  result = <a link="func_FPConvertNaN_3" file="shared_pseudocode.xml">FPConvertNaN</a>{32, 16}(<a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{16}(type_nan, op2, fpcr, fpexc));
    elsif altfp &amp;&amp; op2_nan &amp;&amp; (op1_nan || op3_nan) then     // [n] register NaN selected
        done = TRUE;  result = <a link="func_FPConvertNaN_3" file="shared_pseudocode.xml">FPConvertNaN</a>{32, 16}(<a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{16}(type_nan, op2, fpcr, fpexc));
    elsif altfp &amp;&amp; op3_nan &amp;&amp; op1_nan then                  // [m] register NaN selected
        done = TRUE;  result = <a link="func_FPConvertNaN_3" file="shared_pseudocode.xml">FPConvertNaN</a>{32, 16}(<a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{16}(type_nan, op3, fpcr, fpexc));
    elsif type1 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
        done = TRUE; result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{32}(type1, op1, fpcr, fpexc);
    elsif type2 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
        done = TRUE; result = <a link="func_FPConvertNaN_3" file="shared_pseudocode.xml">FPConvertNaN</a>{32, 16}(<a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{16}(type2, op2, fpcr, fpexc));
    elsif type3 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
        done = TRUE; result = <a link="func_FPConvertNaN_3" file="shared_pseudocode.xml">FPConvertNaN</a>{32, 16}(<a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{16}(type3, op3, fpcr, fpexc));
    elsif type1 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        done = TRUE; result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{32}(type1, op1, fpcr, fpexc);
    elsif type2 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        done = TRUE; result = <a link="func_FPConvertNaN_3" file="shared_pseudocode.xml">FPConvertNaN</a>{32, 16}(<a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{16}(type2, op2, fpcr, fpexc));
    elsif type3 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        done = TRUE; result = <a link="func_FPConvertNaN_3" file="shared_pseudocode.xml">FPConvertNaN</a>{32, 16}(<a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{16}(type3, op3, fpcr, fpexc));
    else
        done = FALSE; result = Zeros{32}; // 'Don't care' result
    end;
    return (done, result);
end;</pstext></ps>
    <ps name="shared/functions/float/fpmulx/FPMulX" mylink="shared.functions.float.fpmulx.FPMulX" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPMulX()
// ========

func <anchor link="func_FPMulX_4">FPMulX</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var result : bits(N);
    var done : boolean;
    let (type1,sign1,value1) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr);
    let (type2,sign2,value2) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr);

    (done,result) = <a link="func_FPProcessNaNs_6" file="shared_pseudocode.xml">FPProcessNaNs</a>{N}(type1, type2, op1, op2, fpcr);
    if !done then
        let inf1 : boolean = (type1 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let inf2 : boolean = (type2 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let zero1 : boolean = (type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        let zero2 : boolean = (type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);

        if (inf1 &amp;&amp; zero2) || (zero1 &amp;&amp; inf2) then
            result = <a link="func_FPTwo_2" file="shared_pseudocode.xml">FPTwo</a>{N}(sign1 XOR sign2);
        elsif inf1 || inf2 then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}(sign1 XOR sign2);
        elsif zero1 || zero2 then
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign1 XOR sign2);
        else
            result = <a link="func_FPRound_3" file="shared_pseudocode.xml">FPRound</a>{N}(value1*value2, fpcr);
        end;

        <a link="func_FPProcessDenorms_4" file="shared_pseudocode.xml">FPProcessDenorms</a>(type1, type2, N, fpcr);

    end;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpneg/FPNeg" mylink="shared.functions.float.fpneg.FPNeg" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPNeg()
// =======

func <anchor link="func_FPNeg_3">FPNeg</anchor>{N}(op : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    if !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; IsFeatureImplemented(FEAT_AFP) then
        if fpcr.AH == '1' then
            let (fptype, -, -) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op, fpcr, FALSE);
            if fptype IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>} then
                return op;        // When fpcr.AH=1, sign of NaN has no consequence
            end;
        end;
    end;
    return NOT(op[N-1]) :: op[N-2:0];
end;</pstext></ps>
    <ps name="shared/functions/float/fponepointfive/FPOnePointFive" mylink="shared.functions.float.fponepointfive.FPOnePointFive" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPOnePointFive()
// ================

func <anchor link="func_FPOnePointFive_2">FPOnePointFive</anchor>{N}(sign : bit) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    let E : integer{}  = (if N == 16 then 5 else (if N == 32 then 8 else 11));
    let F : integer{}  = N - (E + 1);
    let exp : bits(E)  = '0'::Ones{E-1};
    let frac : bits(F) = '1'::Zeros{F-1};
    let result : bits((F + E) + 1) = sign :: exp :: frac;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpprocessdenorms/FPProcessDenorm" mylink="shared.functions.float.fpprocessdenorms.FPProcessDenorm" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPProcessDenorm()
// =================
// Handles denormal input in case of single-precision or double-precision
// when using alternative floating-point mode.

func <anchor link="func_FPProcessDenorm_3">FPProcessDenorm</anchor>(fptype : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, N : integer, fpcr : FPCR_Type)
begin
    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    if altfp &amp;&amp; N != 16 &amp;&amp; fptype == <a link="enum_FPType_Denormal" file="shared_pseudocode.xml">FPType_Denormal</a> then
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InputDenorm" file="shared_pseudocode.xml">FPExc_InputDenorm</a>, fpcr);
    end;
end;</pstext></ps>
    <ps name="shared/functions/float/fpprocessdenorms/FPProcessDenorms" mylink="shared.functions.float.fpprocessdenorms.FPProcessDenorms" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPProcessDenorms()
// ==================
// Handles denormal input in case of single-precision or double-precision
// when using alternative floating-point mode.

func <anchor link="func_FPProcessDenorms_4">FPProcessDenorms</anchor>(type1 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, type2 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, N : integer, fpcr : FPCR_Type)
begin
    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    if altfp &amp;&amp; N != 16 &amp;&amp; (type1 == <a link="enum_FPType_Denormal" file="shared_pseudocode.xml">FPType_Denormal</a> || type2 == <a link="enum_FPType_Denormal" file="shared_pseudocode.xml">FPType_Denormal</a>) then
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InputDenorm" file="shared_pseudocode.xml">FPExc_InputDenorm</a>, fpcr);
    end;
end;</pstext></ps>
    <ps name="shared/functions/float/fpprocessdenorms/FPProcessDenorms3" mylink="shared.functions.float.fpprocessdenorms.FPProcessDenorms3" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPProcessDenorms3()
// ===================
// Handles denormal input in case of single-precision or double-precision
// when using alternative floating-point mode.

func <anchor link="func_FPProcessDenorms3_5">FPProcessDenorms3</anchor>(type1 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, type2 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, type3 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, N : integer,
                       fpcr : FPCR_Type)
begin
    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    if altfp &amp;&amp; N != 16 &amp;&amp; (type1 == <a link="enum_FPType_Denormal" file="shared_pseudocode.xml">FPType_Denormal</a> || type2 == <a link="enum_FPType_Denormal" file="shared_pseudocode.xml">FPType_Denormal</a> ||
        type3 == <a link="enum_FPType_Denormal" file="shared_pseudocode.xml">FPType_Denormal</a>) then
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InputDenorm" file="shared_pseudocode.xml">FPExc_InputDenorm</a>, fpcr);
    end;
end;</pstext></ps>
    <ps name="shared/functions/float/fpprocessdenorms/FPProcessDenorms4" mylink="shared.functions.float.fpprocessdenorms.FPProcessDenorms4" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPProcessDenorms4()
// ===================
// Handles denormal input in case of single-precision or double-precision
// when using alternative floating-point mode.

func <anchor link="func_FPProcessDenorms4_6">FPProcessDenorms4</anchor>(type1 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, type2 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, type3 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, type4 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>,
                       N : integer, fpcr : FPCR_Type)
begin
    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    if altfp &amp;&amp; N != 16 &amp;&amp; (type1 == <a link="enum_FPType_Denormal" file="shared_pseudocode.xml">FPType_Denormal</a> || type2 == <a link="enum_FPType_Denormal" file="shared_pseudocode.xml">FPType_Denormal</a> ||
        type3 == <a link="enum_FPType_Denormal" file="shared_pseudocode.xml">FPType_Denormal</a> || type4 == <a link="enum_FPType_Denormal" file="shared_pseudocode.xml">FPType_Denormal</a>) then
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InputDenorm" file="shared_pseudocode.xml">FPExc_InputDenorm</a>, fpcr);
    end;
end;</pstext></ps>
    <ps name="shared/functions/float/fpprocessexception/FPProcessException" mylink="shared.functions.float.fpprocessexception.FPProcessException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPProcessException()
// ====================
//
// The 'fpcr' argument supplies FPCR control bits. Status information is
// updated directly in the FPSR where appropriate.

func <anchor link="func_FPProcessException_2">FPProcessException</anchor>(except : <a link="type_FPExc" file="shared_pseudocode.xml">FPExc</a>, fpcr : FPCR_Type)
begin
    var cumul : integer;
    // Determine the cumulative exception bit number
    case except of
        when <a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a> =&gt;     cumul = 0;
        when <a link="enum_FPExc_DivideByZero" file="shared_pseudocode.xml">FPExc_DivideByZero</a> =&gt;  cumul = 1;
        when <a link="enum_FPExc_Overflow" file="shared_pseudocode.xml">FPExc_Overflow</a> =&gt;      cumul = 2;
        when <a link="enum_FPExc_Underflow" file="shared_pseudocode.xml">FPExc_Underflow</a> =&gt;     cumul = 3;
        when <a link="enum_FPExc_Inexact" file="shared_pseudocode.xml">FPExc_Inexact</a> =&gt;       cumul = 4;
        when <a link="enum_FPExc_InputDenorm" file="shared_pseudocode.xml">FPExc_InputDenorm</a> =&gt;   cumul = 7;
    end;
    let enable : integer = cumul + 8;
    if (fpcr[enable] == '1' &amp;&amp; (!IsFeatureImplemented(FEAT_SME) || <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM == '0' ||
          <a link="func_IsFullA64Enabled_0" file="shared_pseudocode.xml">IsFullA64Enabled</a>())) then
        // Trapping of the exception enabled.
        // It is IMPLEMENTATION DEFINED whether the enable bit may be set at all,
        // and if so then how exceptions and in what order that they may be
        // accumulated before calling FPTrappedException().
        var accumulated_exceptions : bits(8) = <a link="func_GetAccumulatedFPExceptions_0" file="shared_pseudocode.xml">GetAccumulatedFPExceptions</a>();
        accumulated_exceptions[cumul] = '1';
        if ImpDefBool(&quot;Support trapping of floating-point exceptions&quot;) then
            if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
                <a link="func_AArch32_FPTrappedException_1" file="shared_pseudocode.xml">AArch32_FPTrappedException</a>(accumulated_exceptions);
            else
                let is_ase : boolean = <a link="func_IsASEInstruction_0" file="shared_pseudocode.xml">IsASEInstruction</a>();
                <a link="func_AArch64_FPTrappedException_2" file="shared_pseudocode.xml">AArch64_FPTrappedException</a>(is_ase, accumulated_exceptions);
            end;
        else
            // The exceptions generated by this instruction are accumulated by the PE and
            // FPTrappedException is called later during its execution, before the next
            // instruction is executed. This field is cleared at the start of each FP instruction.
            SetAccumulatedFPExceptions(accumulated_exceptions);
        end;
    elsif <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        // Set the cumulative exception bit
        FPSCR()[cumul] = '1';
    else
        // Set the cumulative exception bit
        FPSR()[cumul] = '1';
    end;
    return;
end;</pstext></ps>
    <ps name="shared/functions/float/fpprocessnan/FPProcessNaN" mylink="shared.functions.float.fpprocessnan.FPProcessNaN" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPProcessNaN()
// ==============

func <anchor link="func_FPProcessNaN_4">FPProcessNaN</anchor>{N}(fptype : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, op : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    let fpexc : boolean = TRUE;   // Generate floating-point exceptions
    return <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(fptype, op, fpcr, fpexc);
end;

// FPProcessNaN()
// ==============
// Handle NaN input operands, returning the operand or default NaN value
// if fpcr.DN is selected. The 'fpcr' argument supplies the FPCR control bits.
// The 'fpexc' argument controls the generation of exceptions, regardless of
// whether 'fptype' is a signalling NaN or a quiet NaN.

func <anchor link="func_FPProcessNaN_5">FPProcessNaN</anchor>{N}(fptype : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, op : bits(N), fpcr : FPCR_Type, fpexc : boolean) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    assert fptype IN {<a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>, <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>};
    var topfrac : integer;

    case N of
        when 16 =&gt; topfrac =  9;
        when 32 =&gt; topfrac = 22;
        when 64 =&gt; topfrac = 51;
    end;

    var result : bits(N) = op;
    if fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
        result[topfrac] = '1';
        if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;
    end;
    if fpcr.DN == '1' then  // DefaultNaN requested
        result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{N}(fpcr);
    end;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpprocessnans/FPProcessNaNs" mylink="shared.functions.float.fpprocessnans.FPProcessNaNs" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPProcessNaNs()
// ===============

func <anchor link="func_FPProcessNaNs_6">FPProcessNaNs</anchor>{N}(type1 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, type2 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, op1 : bits(N),
                      op2 : bits(N), fpcr : FPCR_Type) =&gt; (boolean, bits(N))
begin
    let fpexc : boolean = TRUE;     // Generate floating-point exceptions
    return <a link="func_FPProcessNaNs_7" file="shared_pseudocode.xml">FPProcessNaNs</a>{N}(type1, type2, op1, op2, fpcr, fpexc);
end;

// FPProcessNaNs()
// ===============
//
// The boolean part of the return value says whether a NaN has been found and
// processed. The bits(N) part is only relevant if it has and supplies the
// result of the operation.
//
// The 'fpcr' argument supplies FPCR control bits and 'altfmaxfmin' controls
// alternative floating-point behavior for FMAX, FMIN and variants. 'fpexc'
// controls the generation of floating-point exceptions. Status information
// is updated directly in the FPSR where appropriate.

func <anchor link="func_FPProcessNaNs_7">FPProcessNaNs</anchor>{N}(type1 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, type2 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, op1 : bits(N), op2 : bits(N),
                      fpcr : FPCR_Type, fpexc : boolean) =&gt; (boolean, bits(N))
begin
    assert N IN {16,32,64};
    var done : boolean;
    var result : bits(N);
    let altfp : boolean    = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    let op1_nan : boolean  = type1 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>};
    let op2_nan : boolean  = type2 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>};
    let any_snan : boolean = type1 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || type2 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>;
    let type_nan : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a> = if any_snan then <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> else <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>;

    if altfp &amp;&amp; op1_nan &amp;&amp; op2_nan then
        // [n] register NaN selected
        done = TRUE;  result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(type_nan, op1, fpcr, fpexc);
    elsif type1 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
        done = TRUE;  result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(type1, op1, fpcr, fpexc);
    elsif type2 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
        done = TRUE;  result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(type2, op2, fpcr, fpexc);
    elsif type1 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        done = TRUE;  result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(type1, op1, fpcr, fpexc);
    elsif type2 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        done = TRUE;  result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(type2, op2, fpcr, fpexc);
    else
        done = FALSE;  result = Zeros{N};  // 'Don't care' result
    end;
    return (done, result);
end;</pstext></ps>
    <ps name="shared/functions/float/fpprocessnans3/FPProcessNaNs3" mylink="shared.functions.float.fpprocessnans3.FPProcessNaNs3" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPProcessNaNs3()
// ================

func <anchor link="func_FPProcessNaNs3_8">FPProcessNaNs3</anchor>{N}(type1 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, type2 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, type3 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>,
                       op1 : bits(N), op2 : bits(N), op3 : bits(N),
                       fpcr : FPCR_Type) =&gt; (boolean, bits(N))
begin
    let fpexc : boolean = TRUE;   // Generate floating-point exceptions
    return <a link="func_FPProcessNaNs3_9" file="shared_pseudocode.xml">FPProcessNaNs3</a>{N}(type1, type2, type3, op1, op2, op3, fpcr, fpexc);
end;

// FPProcessNaNs3()
// ================
// The boolean part of the return value says whether a NaN has been found and
// processed. The bits(N) part is only relevant if it has and supplies the
// result of the operation.
//
// The 'fpcr' argument supplies FPCR control bits and 'fpexc' controls the
// generation of floating-point exceptions. Status information is updated
// directly in the FPSR where appropriate.

func <anchor link="func_FPProcessNaNs3_9">FPProcessNaNs3</anchor>{N}(type1 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, type2 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, type3 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>,
                       op1 : bits(N), op2 : bits(N), op3 : bits(N),
                       fpcr : FPCR_Type, fpexc : boolean) =&gt; (boolean, bits(N))
begin
    assert N IN {16,32,64};
    var result : bits(N);
    let op1_nan : boolean = type1 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>};
    let op2_nan : boolean = type2 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>};
    let op3_nan : boolean = type3 IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>};

    let altfp : boolean   = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    var type_nan : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>;
    if altfp then
        if type1 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || type2 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || type3 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
            type_nan = <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>;
        else
            type_nan = <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>;
        end;
    end;

    var done : boolean;
    if altfp &amp;&amp; op1_nan &amp;&amp; op2_nan &amp;&amp; op3_nan then
        // [n] register NaN selected
        done = TRUE;  result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(type_nan, op2, fpcr, fpexc);
    elsif altfp &amp;&amp; op2_nan &amp;&amp; (op1_nan || op3_nan) then
        // [n] register NaN selected
        done = TRUE;  result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(type_nan, op2, fpcr, fpexc);
    elsif altfp &amp;&amp; op3_nan &amp;&amp; op1_nan then
        // [m] register NaN selected
        done = TRUE;  result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(type_nan, op3, fpcr, fpexc);
    elsif type1 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
        done = TRUE;  result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(type1, op1, fpcr, fpexc);
    elsif type2 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
        done = TRUE;  result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(type2, op2, fpcr, fpexc);
    elsif type3 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
        done = TRUE;  result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(type3, op3, fpcr, fpexc);
    elsif type1 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        done = TRUE;  result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(type1, op1, fpcr, fpexc);
    elsif type2 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        done = TRUE;  result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(type2, op2, fpcr, fpexc);
    elsif type3 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        done = TRUE;  result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(type3, op3, fpcr, fpexc);
    else
        done = FALSE;  result = Zeros{N};  // 'Don't care' result
    end;
    return (done, result);
end;</pstext></ps>
    <ps name="shared/functions/float/fpprocessnans4/FPProcessNaNs4" mylink="shared.functions.float.fpprocessnans4.FPProcessNaNs4" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPProcessNaNs4()
// ================
// The boolean part of the return value says whether a NaN has been found and
// processed. The bits(N) part is only relevant if it has and supplies the
// result of the operation.
//
// The 'fpcr' argument supplies FPCR control bits.
// Status information is updated directly in the FPSR where appropriate.
// The 'fpexc' controls the generation of floating-point exceptions.

func <anchor link="func_FPProcessNaNs4_10">FPProcessNaNs4</anchor>(type1 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, type2 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, type3 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, type4 : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>,
                    op1 : bits(16), op2 : bits(16), op3 : bits(16),
                    op4 : bits(16), fpcr : FPCR_Type, fpexc : boolean) =&gt; (boolean, bits(32))
begin

    var result : bits(32);
    var done : boolean;
    // The FPCR.AH control does not affect these checks
    if type1 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
        done = TRUE;  result = <a link="func_FPConvertNaN_3" file="shared_pseudocode.xml">FPConvertNaN</a>{32, 16}(<a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{16}(type1, op1, fpcr, fpexc));
    elsif type2 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
        done = TRUE;  result = <a link="func_FPConvertNaN_3" file="shared_pseudocode.xml">FPConvertNaN</a>{32, 16}(<a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{16}(type2, op2, fpcr, fpexc));
    elsif type3 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
        done = TRUE;  result = <a link="func_FPConvertNaN_3" file="shared_pseudocode.xml">FPConvertNaN</a>{32, 16}(<a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{16}(type3, op3, fpcr, fpexc));
    elsif type4 == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> then
        done = TRUE;  result = <a link="func_FPConvertNaN_3" file="shared_pseudocode.xml">FPConvertNaN</a>{32, 16}(<a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{16}(type4, op4, fpcr, fpexc));
    elsif type1 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        done = TRUE;  result = <a link="func_FPConvertNaN_3" file="shared_pseudocode.xml">FPConvertNaN</a>{32, 16}(<a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{16}(type1, op1, fpcr, fpexc));
    elsif type2 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        done = TRUE;  result = <a link="func_FPConvertNaN_3" file="shared_pseudocode.xml">FPConvertNaN</a>{32, 16}(<a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{16}(type2, op2, fpcr, fpexc));
    elsif type3 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        done = TRUE;  result = <a link="func_FPConvertNaN_3" file="shared_pseudocode.xml">FPConvertNaN</a>{32, 16}(<a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{16}(type3, op3, fpcr, fpexc));
    elsif type4 == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        done = TRUE;  result = <a link="func_FPConvertNaN_3" file="shared_pseudocode.xml">FPConvertNaN</a>{32, 16}(<a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{16}(type4, op4, fpcr, fpexc));
    else
        done = FALSE;  result = Zeros{32};  // 'Don't care' result
    end;

    return (done, result);
end;</pstext></ps>
    <ps name="shared/functions/float/fprecipestimate/FPRecipEstimate" mylink="shared.functions.float.fprecipestimate.FPRecipEstimate" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPRecipEstimate()
// =================

func <anchor link="func_FPRecipEstimate_3">FPRecipEstimate</anchor>{N}(operand : bits(N), fpcr_in : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var fpcr : FPCR_Type = fpcr_in;
    var result : bits(N);
    var overflow_to_inf : boolean;
    // When using alternative floating-point behavior, do not generate
    // floating-point exceptions, flush denormal input and output to zero,
    // and use RNE rounding mode.
    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    let fpexc : boolean = !altfp;
    if altfp then fpcr.[FIZ,FZ] = '11'; end;
    if altfp then fpcr.RMode    = '00'; end;

    let (fptype,sign,value) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(operand, fpcr, fpexc);

    let rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a> = <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr);
    if fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || fptype == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(fptype, operand, fpcr, fpexc);
    elsif fptype == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a> then
        result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign);
    elsif fptype == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then
        result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}(sign);
        if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_DivideByZero" file="shared_pseudocode.xml">FPExc_DivideByZero</a>, fpcr); end;
    elsif (
            (N == 16 &amp;&amp; Abs(value) &lt; 2.0^-16) ||
            (N == 32 &amp;&amp; Abs(value) &lt; 2.0^-128) ||
            (N == 64 &amp;&amp; Abs(value) &lt; 2.0^-1024)
          ) then
        case rounding of
            when <a link="enum_FPRounding_TIEEVEN" file="shared_pseudocode.xml">FPRounding_TIEEVEN</a> =&gt;
                overflow_to_inf = TRUE;
            when <a link="enum_FPRounding_POSINF" file="shared_pseudocode.xml">FPRounding_POSINF</a> =&gt;
                overflow_to_inf = (sign == '0');
            when <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a> =&gt;
                overflow_to_inf = (sign == '1');
            when <a link="enum_FPRounding_ZERO" file="shared_pseudocode.xml">FPRounding_ZERO</a> =&gt;
                overflow_to_inf = FALSE;
        end;
        result = if overflow_to_inf then <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}(sign) else <a link="func_FPMaxNormal_2" file="shared_pseudocode.xml">FPMaxNormal</a>{N}(sign);
        if fpexc then
            <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_Overflow" file="shared_pseudocode.xml">FPExc_Overflow</a>, fpcr);
            <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_Inexact" file="shared_pseudocode.xml">FPExc_Inexact</a>, fpcr);
        end;
    elsif ((fpcr.FZ == '1' &amp;&amp; N != 16) || (fpcr.FZ16 == '1' &amp;&amp; N == 16))
          &amp;&amp; (
               (N == 16 &amp;&amp; Abs(value) &gt;= 2.0^14) ||
               (N == 32 &amp;&amp; Abs(value) &gt;= 2.0^126) ||
               (N == 64 &amp;&amp; Abs(value) &gt;= 2.0^1022)
             ) then
        // Result flushed to zero of correct sign
        result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign);

        // Flush-to-zero never generates a trapped exception.
        if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
            FPSCR().UFC = '1';
        else
            if fpexc then FPSR().UFC = '1'; end;
        end;
    else
        // Scale to a fixed point value in the range 0.5 &lt;= x &lt; 1.0 in steps of 1/512, and
        // calculate result exponent. Scaled value has copied sign bit,
        // exponent = 1022 = double-precision biased version of -1,
        // fraction = original fraction
        var fraction : bits(52);
        var exp : integer;
        case N of
            when 16 =&gt;
                fraction = operand[9:0] :: Zeros{42};
                exp = UInt(operand[14:10]);
            when 32 =&gt;
                fraction = operand[22:0] :: Zeros{29};
                exp = UInt(operand[30:23]);
            when 64 =&gt;
                fraction = operand[51:0];
                exp = UInt(operand[62:52]);
        end;

        if exp == 0 then
            if fraction[51] == '0' then
                exp = -1;
                fraction = fraction[49:0]::'00';
            else
                fraction = fraction[50:0]::'0';
            end;
        end;

        var scaled : integer;
        let increasedprecision : boolean = N==32 &amp;&amp; IsFeatureImplemented(FEAT_RPRES) &amp;&amp; altfp;

        if !increasedprecision then
            scaled = UInt('1'::fraction[51:44]);
        else
            scaled = UInt('1'::fraction[51:41]);
        end;

        var result_exp : integer;
        case N of
            when 16 =&gt; result_exp = 29 - exp;   // In range 29-30 = -1 to 29+1 = 30
            when 32 =&gt; result_exp = 253 - exp;  // In range 253-254 = -1 to 253+1 = 254
            when 64 =&gt; result_exp = 2045 - exp; // In range 2045-2046 = -1 to 2045+1 = 2046
        end;

        // Scaled is in range 256 .. 511 or 2048 .. 4095 range representing a
        // fixed-point number in range [0.5 .. 1.0].
        let estimate : integer = <a link="func_RecipEstimate_2" file="shared_pseudocode.xml">RecipEstimate</a>(scaled, increasedprecision);

        // Estimate is in the range 256 .. 511 or 4096 .. 8191 representing a
        // fixed-point result in the range [1.0 .. 2.0].
        // Convert to scaled floating point result with copied sign bit,
        // high-order bits from estimate, and exponent calculated above.
        if !increasedprecision then
            fraction = estimate[7:0] :: Zeros{44};
        else
            fraction = estimate[11:0] :: Zeros{40};
        end;

        if result_exp == 0 then
            fraction = '1' :: fraction[51:1];
        elsif result_exp == -1 then
            fraction = '01' :: fraction[51:2];
            result_exp = 0;
        end;

        case N of
            when 16 =&gt; result = sign :: result_exp[N-12:0] :: fraction[51:42];
            when 32 =&gt; result = sign :: result_exp[N-25:0] :: fraction[51:29];
            when 64 =&gt; result = sign :: result_exp[N-54:0] :: fraction[51:0];
        end;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fprecipestimate/RecipEstimate" mylink="shared.functions.float.fprecipestimate.RecipEstimate" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// RecipEstimate()
// ===============
// Compute estimate of reciprocal of 9-bit fixed-point number.
//
// a is in range 256 .. 511 or 2048 .. 4096 representing a number in
// the range 0.5 &lt;= x &lt; 1.0.
// increasedprecision determines if the mantissa is 8-bit or 12-bit.
// result is in the range 256 .. 511 or 4096 .. 8191 representing a
// number in the range 1.0 to 511/256 or 1.00 to 8191/4096.

func <anchor link="func_RecipEstimate_2">RecipEstimate</anchor>(a_in : integer, increasedprecision : boolean) =&gt; integer
begin
    var a : integer = a_in;
    var r : integer;
    if !increasedprecision then
        assert 256 &lt;= a &amp;&amp; a &lt; 512;
        a = a*2+1;                       // Round to nearest
        let b : integer = (2 ^ 19) DIVRM a;
        r = (b+1) DIVRM 2;               // Round to nearest
        assert 256 &lt;= r &amp;&amp; r &lt; 512;
    else
        assert 2048 &lt;= a &amp;&amp; a &lt; 4096;
        a = a*2+1;                       // Round to nearest
        let b : integer = (2 ^ 26) DIVRM a;
        r = (b+1) DIVRM 2;               // Round to nearest
        assert 4096 &lt;= r &amp;&amp; r &lt; 8192;
    end;
    return r;
end;</pstext></ps>
    <ps name="shared/functions/float/fprecpx/FPRecpX" mylink="shared.functions.float.fprecpx.FPRecpX" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPRecpX()
// =========

func <anchor link="func_FPRecpX_3">FPRecpX</anchor>{N}(op : bits(N), fpcr_in : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var fpcr : FPCR_Type = fpcr_in;
    let isbfloat16 : boolean = FALSE;
    let (F, -) = <a link="func_FPBits_2" file="shared_pseudocode.xml">FPBits</a>(N, isbfloat16);
    let E = (N - F) - 1;
    var result : bits(N);
    var exp : bits(E);
    var max_exp : bits(E);
    let frac : bits(F) = Zeros{};

    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; fpcr.AH == '1';
    let fpexc : boolean = !altfp;            // Generate no floating-point exceptions
    if altfp then fpcr.[FIZ,FZ] = '11'; end; // Flush denormal input and output to zero
    let (fptype,sign,value) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op, fpcr, fpexc);
    exp = op[F+:E];
    max_exp = Ones{E} - 1;

    if fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || fptype == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(fptype, op, fpcr, fpexc);
    else
        if IsZero(exp) then                 // Zero and denormals
            result = ZeroExtend{N}(sign::max_exp::frac);
        else                                // Infinities and normals
            result = ZeroExtend{N}(sign::NOT(exp)::frac);
        end;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpround/FPRound" mylink="shared.functions.float.fpround.FPRound" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPRound()
// =========
// Generic conversion from precise, unbounded real data type to IEEE format.

func <anchor link="func_FPRound_3">FPRound</anchor>{N}(op : real, fpcr : FPCR_Type) =&gt; bits(N)
begin
    return <a link="func_FPRound_4" file="shared_pseudocode.xml">FPRound</a>{N}(op, fpcr, <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr));
end;

// FPRound()
// =========
// For directed FP conversion, includes an explicit 'rounding' argument.

func <anchor link="func_FPRound_4">FPRound</anchor>{N}(op : real, fpcr_in : FPCR_Type, rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>) =&gt; bits(N)
begin
    let fpexc : boolean = TRUE;    // Generate floating-point exceptions
    return <a link="func_FPRound_5" file="shared_pseudocode.xml">FPRound</a>{N}(op, fpcr_in, rounding, fpexc);
end;

// FPRound()
// =========
// For AltFP, includes an explicit FPEXC argument to disable exception
// generation and switches off Arm alternate half-precision mode.

func <anchor link="func_FPRound_5">FPRound</anchor>{N}(op : real, fpcr_in : FPCR_Type, rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>, fpexc : boolean) =&gt; bits(N)
begin
    var fpcr : FPCR_Type = fpcr_in;
    fpcr.AHP = '0';
    let isbfloat16 : boolean = FALSE;
    return <a link="func_FPRoundBase_6" file="shared_pseudocode.xml">FPRoundBase</a>{N}(op, fpcr, rounding, isbfloat16, fpexc);
end;</pstext></ps>
    <ps name="shared/functions/float/fpround/FPRoundBase" mylink="shared.functions.float.fpround.FPRoundBase" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPRoundBase()
// =============
// For BFloat16, includes an explicit 'isbfloat16' argument.

func <anchor link="func_FPRoundBase_5">FPRoundBase</anchor>{N}(op : real, fpcr : FPCR_Type, rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>,
                    isbfloat16 : boolean) =&gt; bits(N)
begin
    let fpexc : boolean = TRUE;    // Generate floating-point exceptions
    return <a link="func_FPRoundBase_6" file="shared_pseudocode.xml">FPRoundBase</a>{N}(op, fpcr, rounding, isbfloat16, fpexc);
end;

// FPRoundBase()
// =============
// For FP8 multiply-accumulate, dot product, and outer product instructions, includes
// an explicit saturation overflow argument.

func <anchor link="func_FPRoundBase_6">FPRoundBase</anchor>{N}(op : real, fpcr : FPCR_Type, rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>, isbfloat16 : boolean,
                    fpexc : boolean) =&gt; bits(N)
begin
    let satoflo : boolean = FALSE;
    return <a link="func_FPRoundBase_7" file="shared_pseudocode.xml">FPRoundBase</a>{N}(op, fpcr, rounding, isbfloat16, fpexc, satoflo);
end;

// FPRoundBase()
// =============
// Convert a real number 'op' into an N-bit floating-point value using the
// supplied rounding mode 'rounding'.
//
// The 'fpcr' argument supplies FPCR control bits and 'fpexc' controls the
// generation of floating-point exceptions. Status information is updated
// directly in the FPSR where appropriate. The 'satoflo' argument
// controls whether overflow generates Infinity or MaxNorm for 8-bit floating-point
// data processing instructions.

func <anchor link="func_FPRoundBase_7">FPRoundBase</anchor>{N}(op : real, fpcr : FPCR_Type, rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>, isbfloat16 : boolean,
                    fpexc : boolean, satoflo : boolean) =&gt; bits(N)
begin

    assert N IN {16,32,64};
    assert op != 0.0;
    assert rounding != <a link="enum_FPRounding_TIEAWAY" file="shared_pseudocode.xml">FPRounding_TIEAWAY</a>;
    var result : bits(N);

    // Obtain format parameters - minimum exponent, numbers of exponent and fraction bits.
    let (F, minimum_exp) = <a link="func_FPBits_2" file="shared_pseudocode.xml">FPBits</a>(N, isbfloat16);
    let zeros = if N == 32 &amp;&amp; isbfloat16 then 16 else 0;
    let E = N - (F + 1 + zeros);
    // Split value into sign, unrounded mantissa and exponent.
    var sign : bit;
    var exponent : integer;
    var mantissa : real;
    if op &lt; 0.0 then
        sign = '1';  mantissa = -op;
    else
        sign = '0';  mantissa = op;
    end;
    (mantissa, exponent) = <a link="func_NormalizeReal_1" file="shared_pseudocode.xml">NormalizeReal</a>(mantissa);

    // When TRUE, detection of underflow occurs after rounding and the test for a
    // denormalized number for single and double precision values occurs after rounding.
    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';

    // Deal with flush-to-zero before rounding if FPCR.AH != '1'.
    if (!altfp &amp;&amp; ((fpcr.FZ == '1' &amp;&amp; N != 16) || (fpcr.FZ16 == '1' &amp;&amp; N == 16)) &amp;&amp;
          exponent &lt; minimum_exp) then
        // Flush-to-zero never generates a trapped exception.
        if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
            FPSCR().UFC = '1';
        else
            if fpexc then FPSR().UFC = '1'; end;
        end;
        return <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign);
    end;

    var biased_exp_unconstrained : integer = (exponent - minimum_exp) + 1;
    var int_mant_unconstrained : integer = RoundDown(mantissa * 2.0^F);
    let error_unconstrained : real = mantissa * 2.0^F - Real(int_mant_unconstrained);

    // Start creating the exponent value for the result. Start by biasing the actual exponent
    // so that the minimum exponent becomes 1, lower values 0 (indicating possible underflow).
    var biased_exp : integer = Max((exponent - minimum_exp) + 1, 0);
    if biased_exp == 0 then mantissa = mantissa / 2.0^(minimum_exp - exponent); end;

    // Get the unrounded mantissa as an integer, and the &quot;units in last place&quot; rounding error.
    // &lt; 2.0^F if biased_exp == 0, &gt;= 2.0^F if not
    var int_mant : integer = RoundDown(mantissa * 2.0^F);
    var error : real = mantissa * 2.0^F - Real(int_mant);

    // Underflow occurs if exponent is too small before rounding, and result is inexact or
    // the Underflow exception is trapped. This applies before rounding if FPCR.AH != '1'.
    let trapped_UF : boolean = fpcr.UFE == '1' &amp;&amp; (!<a link="func_InStreamingMode_0" file="shared_pseudocode.xml">InStreamingMode</a>() || <a link="func_IsFullA64Enabled_0" file="shared_pseudocode.xml">IsFullA64Enabled</a>());
    if !altfp &amp;&amp; biased_exp == 0 &amp;&amp; (error != 0.0 || trapped_UF) then
        if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_Underflow" file="shared_pseudocode.xml">FPExc_Underflow</a>, fpcr); end;
    end;

    // Round result according to rounding mode.
    var round_up_unconstrained : boolean;
    var round_up : boolean;
    var overflow_to_inf : boolean;
    if altfp then

        case rounding of
            when <a link="enum_FPRounding_TIEEVEN" file="shared_pseudocode.xml">FPRounding_TIEEVEN</a> =&gt;
                round_up_unconstrained = (error_unconstrained &gt; 0.5 ||
                   (error_unconstrained == 0.5 &amp;&amp; int_mant_unconstrained[0] == '1'));
                round_up = (error &gt; 0.5 || (error == 0.5 &amp;&amp; int_mant[0] == '1'));
                overflow_to_inf = !satoflo;
            when <a link="enum_FPRounding_POSINF" file="shared_pseudocode.xml">FPRounding_POSINF</a> =&gt;
                round_up_unconstrained = (error_unconstrained != 0.0 &amp;&amp; sign == '0');
                round_up = (error != 0.0 &amp;&amp; sign == '0');
                overflow_to_inf = (sign == '0');
            when <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a> =&gt;
                round_up_unconstrained = (error_unconstrained != 0.0 &amp;&amp; sign == '1');
                round_up = (error != 0.0 &amp;&amp; sign == '1');
                overflow_to_inf = (sign == '1');
            when <a link="enum_FPRounding_ZERO" file="shared_pseudocode.xml">FPRounding_ZERO</a>, <a link="enum_FPRounding_ODD" file="shared_pseudocode.xml">FPRounding_ODD</a> =&gt;
                round_up_unconstrained = FALSE;
                round_up = FALSE;
                overflow_to_inf = FALSE;
        end;

        if round_up_unconstrained then
            int_mant_unconstrained = int_mant_unconstrained + 1;
            if int_mant_unconstrained == 2^(F+1) then    // Rounded up to next exponent
                biased_exp_unconstrained = biased_exp_unconstrained + 1;
                int_mant_unconstrained   = int_mant_unconstrained DIV 2;
            end;
        end;

        // Deal with flush-to-zero and underflow after rounding if FPCR.AH == '1'.
        if biased_exp_unconstrained &lt; 1 &amp;&amp; int_mant_unconstrained != 0 then
            // the result of unconstrained rounding is less than the minimum normalized number
            if (fpcr.FZ == '1' &amp;&amp; N != 16) || (fpcr.FZ16 == '1' &amp;&amp; N == 16) then   // Flush-to-zero
                if fpexc then
                    FPSR().UFC = '1';
                    <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_Inexact" file="shared_pseudocode.xml">FPExc_Inexact</a>, fpcr);
                end;
                return <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign);
            elsif error != 0.0 || trapped_UF then
                if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_Underflow" file="shared_pseudocode.xml">FPExc_Underflow</a>, fpcr); end;
            end;
        end;
    else    // altfp == FALSE
        case rounding of
            when <a link="enum_FPRounding_TIEEVEN" file="shared_pseudocode.xml">FPRounding_TIEEVEN</a> =&gt;
                round_up = (error &gt; 0.5 || (error == 0.5 &amp;&amp; int_mant[0] == '1'));
                overflow_to_inf = !satoflo;
            when <a link="enum_FPRounding_POSINF" file="shared_pseudocode.xml">FPRounding_POSINF</a> =&gt;
                round_up = (error != 0.0 &amp;&amp; sign == '0');
                overflow_to_inf = (sign == '0');
            when <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a> =&gt;
                round_up = (error != 0.0 &amp;&amp; sign == '1');
                overflow_to_inf = (sign == '1');
            when <a link="enum_FPRounding_ZERO" file="shared_pseudocode.xml">FPRounding_ZERO</a>, <a link="enum_FPRounding_ODD" file="shared_pseudocode.xml">FPRounding_ODD</a> =&gt;
                round_up = FALSE;
                overflow_to_inf = FALSE;
        end;
    end;

    if round_up then
        int_mant = int_mant + 1;
        if int_mant == 2^F then      // Rounded up from denormalized to normalized
            biased_exp = 1;
        end;
        if int_mant == 2^(F+1) then  // Rounded up to next exponent
            biased_exp = biased_exp + 1;
            int_mant = int_mant DIV 2;
        end;
    end;

    // Handle rounding to odd
    if error != 0.0 &amp;&amp; rounding == <a link="enum_FPRounding_ODD" file="shared_pseudocode.xml">FPRounding_ODD</a> &amp;&amp; int_mant[0] == '0' then
        int_mant = int_mant + 1;
    end;

    // Deal with overflow and generate result.
    if N != 16 || fpcr.AHP == '0' then  // Single, double or IEEE half precision
        if biased_exp &gt;= 2^E - 1 then
            result = if overflow_to_inf then <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}(sign) else <a link="func_FPMaxNormal_2" file="shared_pseudocode.xml">FPMaxNormal</a>{N}(sign);
            if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_Overflow" file="shared_pseudocode.xml">FPExc_Overflow</a>, fpcr); end;
            error = 1.0;  // Ensure that an Inexact exception occurs
        else
            result = sign :: biased_exp[E-1:0] :: int_mant[F-1:0] :: Zeros{N-(E+F+1)};
        end;
    else                                     // Alternative half precision
        if biased_exp &gt;= 2^E then
            result = sign :: Ones{N-1};
            if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;
            error = 0.0;  // Ensure that an Inexact exception does not occur
        else
            result = sign :: biased_exp[E-1:0] :: int_mant[F-1:0] :: Zeros{N-(E+F+1)};
        end;
    end;

    // Deal with Inexact exception.
    if error != 0.0 then
        if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_Inexact" file="shared_pseudocode.xml">FPExc_Inexact</a>, fpcr); end;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpround/FPRoundCV" mylink="shared.functions.float.fpround.FPRoundCV" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPRoundCV()
// ===========
// Used for FP to FP conversion instructions.
// For half-precision data ignores FZ16 and observes AHP.

func <anchor link="func_FPRoundCV_4">FPRoundCV</anchor>{N}(op : real, fpcr_in : FPCR_Type, rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>) =&gt; bits(N)
begin
    var fpcr : FPCR_Type = fpcr_in;
    fpcr.FZ16 = '0';
    let fpexc : boolean = TRUE;    // Generate floating-point exceptions
    let isbfloat16 : boolean = FALSE;
    return <a link="func_FPRoundBase_6" file="shared_pseudocode.xml">FPRoundBase</a>{N}(op, fpcr, rounding, isbfloat16, fpexc);
end;</pstext></ps>
    <ps name="shared/functions/float/fpround/FPRound_FP8" mylink="shared.functions.float.fpround.FPRound_FP8" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPRound_FP8()
// =============
// Used by FP8 multiply-accumulate, dot product, and outer product instructions
// which observe FPMR.OSM.

func <anchor link="func_FPRound_FP8_5">FPRound_FP8</anchor>{N}(op : real, fpcr_in : FPCR_Type, rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>,
                    satoflo : boolean) =&gt; bits(N)
begin
    var fpcr : FPCR_Type = fpcr_in;
    fpcr.AHP = '0';
    let fpexc : boolean = FALSE;
    let isbfloat16 : boolean = FALSE;
    return <a link="func_FPRoundBase_7" file="shared_pseudocode.xml">FPRoundBase</a>{N}(op, fpcr, rounding, isbfloat16, fpexc, satoflo);
end;</pstext></ps>
    <ps name="shared/functions/float/fprounding/FPRounding" mylink="shared.functions.float.fprounding.FPRounding" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPRounding
// ==========
// The conversion and rounding functions take an explicit
// rounding mode enumeration instead of booleans or FPCR values.

type <anchor link="type_FPRounding">FPRounding</anchor> of enumeration {<anchor link="enum_FPRounding_TIEEVEN">FPRounding_TIEEVEN</anchor>, <anchor link="enum_FPRounding_POSINF">FPRounding_POSINF</anchor>,
                                <anchor link="enum_FPRounding_NEGINF">FPRounding_NEGINF</anchor>,  <anchor link="enum_FPRounding_ZERO">FPRounding_ZERO</anchor>,
                                <anchor link="enum_FPRounding_TIEAWAY">FPRounding_TIEAWAY</anchor>, <anchor link="enum_FPRounding_ODD">FPRounding_ODD</anchor>};</pstext></ps>
    <ps name="shared/functions/float/fproundingmode/FPRoundingMode" mylink="shared.functions.float.fproundingmode.FPRoundingMode" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPRoundingMode()
// ================
// Return the current floating-point rounding mode.

func <anchor link="func_FPRoundingMode_1">FPRoundingMode</anchor>(fpcr : FPCR_Type) =&gt; <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>
begin
    return <a link="func_FPDecodeRounding_1" file="shared_pseudocode.xml">FPDecodeRounding</a>(fpcr.RMode);
end;</pstext></ps>
    <ps name="shared/functions/float/fproundint/FPRoundInt" mylink="shared.functions.float.fproundint.FPRoundInt" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPRoundInt()
// ============

// Round op to nearest integral floating point value using rounding mode in FPCR/FPSCR.
// If EXACT is TRUE, set FPSR.IXC if result is not numerically equal to op.

func <anchor link="func_FPRoundInt_5">FPRoundInt</anchor>{N}(op : bits(N), fpcr : FPCR_Type, rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>,
                   exact : boolean) =&gt; bits(N)
begin
    assert rounding != <a link="enum_FPRounding_ODD" file="shared_pseudocode.xml">FPRounding_ODD</a>;
    assert N IN {16,32,64};

    // When alternative floating-point support is TRUE, do not generate
    // Input Denormal floating-point exceptions.
    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    let fpexc : boolean = !altfp;

    // Unpack using FPCR to determine if subnormals are flushed-to-zero.
    let (fptype,sign,value) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op, fpcr, fpexc);

    var result : bits(N);
    if fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || fptype == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        result = <a link="func_FPProcessNaN_4" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(fptype, op, fpcr);
    elsif fptype == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a> then
        result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}(sign);
    elsif fptype == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then
        result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign);
    else
        // Extract integer component.
        var int_result : integer = RoundDown(value);
        let error : real = value - Real(int_result);

        // Determine whether supplied rounding mode requires an increment.
        var round_up : boolean;
        case rounding of
            when <a link="enum_FPRounding_TIEEVEN" file="shared_pseudocode.xml">FPRounding_TIEEVEN</a> =&gt;
                round_up = (error &gt; 0.5 || (error == 0.5 &amp;&amp; int_result[0] == '1'));
            when <a link="enum_FPRounding_POSINF" file="shared_pseudocode.xml">FPRounding_POSINF</a> =&gt;
                round_up = (error != 0.0);
            when <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a> =&gt;
                round_up = FALSE;
            when <a link="enum_FPRounding_ZERO" file="shared_pseudocode.xml">FPRounding_ZERO</a> =&gt;
                round_up = (error != 0.0 &amp;&amp; int_result &lt; 0);
            when <a link="enum_FPRounding_TIEAWAY" file="shared_pseudocode.xml">FPRounding_TIEAWAY</a> =&gt;
                round_up = (error &gt; 0.5 || (error == 0.5 &amp;&amp; int_result &gt;= 0));
        end;

        if round_up then int_result = int_result + 1; end;

        // Convert integer value into an equivalent real value.
        let real_result : real = Real(int_result);

        // Re-encode as a floating-point value, result is always exact.
        if real_result == 0.0 then
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign);
        else
            result = <a link="func_FPRound_4" file="shared_pseudocode.xml">FPRound</a>{N}(real_result, fpcr, <a link="enum_FPRounding_ZERO" file="shared_pseudocode.xml">FPRounding_ZERO</a>);
        end;

        // Generate inexact exceptions.
        if error != 0.0 &amp;&amp; exact then
            <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_Inexact" file="shared_pseudocode.xml">FPExc_Inexact</a>, fpcr);
        end;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fproundintn/FPRoundIntN" mylink="shared.functions.float.fproundintn.FPRoundIntN" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPRoundIntN()
// =============

func <anchor link="func_FPRoundIntN_5">FPRoundIntN</anchor>{N}(op : bits(N), fpcr : FPCR_Type,
                    rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>, intsize : integer) =&gt; bits(N)
begin
    assert rounding != <a link="enum_FPRounding_ODD" file="shared_pseudocode.xml">FPRounding_ODD</a>;
    assert N IN {32,64};
    assert intsize IN {32, 64};
    var exp : integer;
    var result : bits(N);
    var round_up : boolean;
    let E : integer{} = (if N == 32 then 8 else 11);
    let F : integer{} = N - (E + 1);

    // When alternative floating-point support is TRUE, do not generate
    // Input Denormal floating-point exceptions.
    let altfp = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    let fpexc = !altfp;

    // Unpack using FPCR to determine if subnormals are flushed-to-zero.
    let (fptype,sign,value) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op, fpcr, fpexc);

    if fptype IN {<a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>, <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a>, <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>} then
        if N == 32 then
            exp    = 126 + intsize;
            result = '1'::exp[(E-1):0]::Zeros{F};
        else
            exp    = 1022+intsize;
            result = '1'::exp[(E-1):0]::Zeros{F};
        end;
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
    elsif fptype == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then
        result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign);
    else
        // Extract integer component.
        var int_result = RoundDown(value);
        var error      = value - Real(int_result);

        // Determine whether supplied rounding mode requires an increment.
        case rounding of
            when <a link="enum_FPRounding_TIEEVEN" file="shared_pseudocode.xml">FPRounding_TIEEVEN</a> =&gt;
                round_up = error &gt; 0.5 || (error == 0.5 &amp;&amp; int_result[0] == '1');
            when <a link="enum_FPRounding_POSINF" file="shared_pseudocode.xml">FPRounding_POSINF</a> =&gt;
                round_up = error != 0.0;
            when <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a> =&gt;
                round_up = FALSE;
            when <a link="enum_FPRounding_ZERO" file="shared_pseudocode.xml">FPRounding_ZERO</a> =&gt;
                round_up = error != 0.0 &amp;&amp; int_result &lt; 0;
            when <a link="enum_FPRounding_TIEAWAY" file="shared_pseudocode.xml">FPRounding_TIEAWAY</a> =&gt;
                round_up = error &gt; 0.5 || (error == 0.5 &amp;&amp; int_result &gt;= 0);
        end;

        if round_up then int_result = int_result + 1; end;
        let overflow = int_result &gt; 2^(intsize-1)-1 || int_result &lt; -1*2^(intsize-1);

        if overflow then
            if N == 32 then
                exp    = 126 + intsize;
                result = '1'::exp[(E-1):0]::Zeros{F};
            else
                exp    = 1022 + intsize;
                result = '1'::exp[(E-1):0]::Zeros{F};
            end;
            <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
            // This case shouldn't set Inexact.
            error = 0.0;

        else
            // Convert integer value into an equivalent real value.
            let real_result : real = Real(int_result);

            // Re-encode as a floating-point value, result is always exact.
            if real_result == 0.0 then
                result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign);
            else
                result = <a link="func_FPRound_4" file="shared_pseudocode.xml">FPRound</a>{N}(real_result, fpcr, <a link="enum_FPRounding_ZERO" file="shared_pseudocode.xml">FPRounding_ZERO</a>);
            end;
        end;

        // Generate inexact exceptions.
        if error != 0.0 then
            <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_Inexact" file="shared_pseudocode.xml">FPExc_Inexact</a>, fpcr);
        end;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fprsqrtestimate/FPRSqrtEstimate" mylink="shared.functions.float.fprsqrtestimate.FPRSqrtEstimate" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPRSqrtEstimate()
// =================

func <anchor link="func_FPRSqrtEstimate_3">FPRSqrtEstimate</anchor>{N}(operand : bits(N), fpcr_in : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var fpcr : FPCR_Type = fpcr_in;

    // When using alternative floating-point behavior, do not generate
    // floating-point exceptions and flush denormal input to zero.
    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    let fpexc : boolean = !altfp;
    if altfp then fpcr.[FIZ,FZ] = '11'; end;

    let (fptype,sign,value) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(operand, fpcr, fpexc);

    var result : bits(N);
    if fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || fptype == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        result = <a link="func_FPProcessNaN_5" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(fptype, operand, fpcr, fpexc);
    elsif fptype == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then
        result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}(sign);
        if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_DivideByZero" file="shared_pseudocode.xml">FPExc_DivideByZero</a>, fpcr); end;
    elsif sign == '1' then
        result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{N}(fpcr);
        if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;
    elsif fptype == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a> then
        result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}('0');
    else
        // Scale to a fixed-point value in the range 0.25 &lt;= x &lt; 1.0 in steps of 512, with the
        // evenness or oddness of the exponent unchanged, and calculate result exponent.
        // Scaled value has copied sign bit, exponent = 1022 or 1021 = double-precision
        // biased version of -1 or -2, fraction = original fraction extended with zeros.

        var fraction : bits(52);
        var exp : integer;
        case N of
            when 16 =&gt;
                fraction = operand[9:0] :: Zeros{42};
                exp      = UInt(operand[14:10]);
            when 32 =&gt;
                fraction = operand[22:0] :: Zeros{29};
                exp      = UInt(operand[30:23]);
            when 64 =&gt;
                fraction = operand[51:0];
                exp      = UInt(operand[62:52]);
        end;

        if exp == 0 then
            while fraction[51] == '0' looplimit 51 do
                fraction = fraction[50:0] :: '0';
                exp      = exp - 1;
            end;
            fraction = fraction[50:0] :: '0';
        end;

        var scaled : integer;
        let increasedprecision : boolean = N==32 &amp;&amp; IsFeatureImplemented(FEAT_RPRES) &amp;&amp; altfp;

        if !increasedprecision then
            if exp[0] == '0' then
                scaled = UInt('1'::fraction[51:44]);
            else
                scaled = UInt('01'::fraction[51:45]);
            end;
        else
            if exp[0] == '0' then
                scaled = UInt('1'::fraction[51:41]);
            else
                scaled = UInt('01'::fraction[51:42]);
            end;
        end;

        var result_exp : integer;
        case N of
            when 16 =&gt; result_exp = (  44 - exp) DIVRM 2;
            when 32 =&gt; result_exp = ( 380 - exp) DIVRM 2;
            when 64 =&gt; result_exp = (3068 - exp) DIVRM 2;
        end;

        let estimate : integer = <a link="func_RecipSqrtEstimate_2" file="shared_pseudocode.xml">RecipSqrtEstimate</a>(scaled, increasedprecision);

        // Estimate is in the range 256 .. 511 or 4096 .. 8191 representing a
        // fixed-point result in the range [1.0 .. 2.0].
        // Convert to scaled floating point result with copied sign bit and high-order
        // fraction bits, and exponent calculated above.
        case N of
            when 16 =&gt; result = '0' :: result_exp[N-12:0] :: estimate[7:0]::Zeros{2};
            when 32 =&gt;
                if !increasedprecision then
                    result = '0' :: result_exp[N-25:0] :: estimate[7:0]::Zeros{15};
                else
                    result = '0' :: result_exp[N-25:0] :: estimate[11:0]::Zeros{11};
                end;
            when 64 =&gt; result = '0' :: result_exp[N-54:0] :: estimate[7:0]::Zeros{44};
        end;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fprsqrtestimate/RecipSqrtEstimate" mylink="shared.functions.float.fprsqrtestimate.RecipSqrtEstimate" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// RecipSqrtEstimate()
// ===================
// Compute estimate of reciprocal square root of 9-bit fixed-point number.
//
// a_in is in range 128 .. 511 or 1024 .. 4095, with increased precision,
// representing a number in the range 0.25 &lt;= x &lt; 1.0.
// increasedprecision determines if the mantissa is 8-bit or 12-bit.
// result is in the range 256 .. 511 or 4096 .. 8191, with increased precision,
// representing a number in the range 1.0 to 511/256 or 8191/4096.

func <anchor link="func_RecipSqrtEstimate_2">RecipSqrtEstimate</anchor>(a_in : integer, increasedprecision : boolean) =&gt; integer
begin
    var a : integer = a_in;
    var r : integer;
    if !increasedprecision then
        assert 128 &lt;= a &amp;&amp; a &lt; 512;
        if a &lt; 256 then                      // a in [128, 255], represents a value in [0.25, 0.5)
            a = a*2+1;                       // promote to 9-bit range in units of 1/512
        else                                 // a in [256, 511], represents a value in [0.5, 1.0)
            a = (a &gt;&gt; 1) &lt;&lt; 1;               // Discard bottom bit
            a = (a+1)*2;                     // round up to nearest 1/256 and convert
        end;
        var b : integer = 512;
        while a*(b+1)*(b+1) &lt; 2^28 looplimit 510 do
            b = b+1;
        end;
        // b = largest b such that b &lt; 2^14 / sqrt(a)
        r = (b+1) DIVRM 2;                   // Round to nearest
        assert 256 &lt;= r &amp;&amp; r &lt; 512;
    else
        assert 1024 &lt;= a &amp;&amp; a &lt; 4096;
        if a &lt; 2048 then                     // a in [1024, 2047], represents a value in [0.25, 0.5)
            a = a*2 + 1;                     // promote to 13-bit range in units of 1/8192
        else                                 // a in [2048, 4095], represents a value in [0.5, 1.0)
            a = (a &gt;&gt; 1) &lt;&lt; 1;               // Discard bottom bit
            a = (a+1)*2;                     // round up to nearest 1/4096 and convert
        end;
        var b : integer = 8192;
        while a*(b+1)*(b+1) &lt; 2^39 looplimit (2^39 - (2049 * 8193^2)) do
            b = b+1;
        end;
        r = (b+1) DIVRM 2;                   // Round to nearest
        assert 4096 &lt;= r &amp;&amp; r &lt; 8192;
    end;
    return r;
end;</pstext></ps>
    <ps name="shared/functions/float/fpsqrt/FPSqrt" mylink="shared.functions.float.fpsqrt.FPSqrt" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPSqrt()
// ========

func <anchor link="func_FPSqrt_3">FPSqrt</anchor>{N}(op : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    var (fptype,sign,value) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_3" file="shared_pseudocode.xml">FPUnpack</a>{N}(op, fpcr);

    var result : bits(N);
    if fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || fptype == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        result = <a link="func_FPProcessNaN_4" file="shared_pseudocode.xml">FPProcessNaN</a>{N}(fptype, op, fpcr);
    elsif fptype == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a> then
        result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign);
    elsif fptype == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a> &amp;&amp; sign == '0' then
        result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}(sign);
    elsif sign == '1' then
        result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{N}(fpcr);
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
    else
        var prec : integer;
        if N == 16 then
            prec = 13; // 10 fraction bits + 3
        elsif N == 32 then
            prec = 26; // 23 fraction bits + 3
        else // N == 64
            prec = 55; // 52 fraction bits + 3
        end;
        value = SqrtRounded(value, prec);
        result = <a link="func_FPRound_3" file="shared_pseudocode.xml">FPRound</a>{N}(value, fpcr);
        <a link="func_FPProcessDenorm_3" file="shared_pseudocode.xml">FPProcessDenorm</a>(fptype, N, fpcr);

    end;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpsub/FPSub" mylink="shared.functions.float.fpsub.FPSub" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPSub()
// =======

func <anchor link="func_FPSub_4">FPSub</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type) =&gt; bits(N)
begin
    let fpexc : boolean = TRUE;       // Generate floating-point exceptions
    return <a link="func_FPSub_5" file="shared_pseudocode.xml">FPSub</a>{N}(op1, op2, fpcr, fpexc);
end;

// FPSub()
// =======

func <anchor link="func_FPSub_5">FPSub</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr : FPCR_Type, fpexc : boolean) =&gt; bits(N)
begin

    assert N IN {16,32,64};
    let rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a> = <a link="func_FPRoundingMode_1" file="shared_pseudocode.xml">FPRoundingMode</a>(fpcr);

    let (type1,sign1,value1) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op1, fpcr, fpexc);
    let (type2,sign2,value2) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op2, fpcr, fpexc);

    var (done,result) : (boolean, bits(N)) = <a link="func_FPProcessNaNs_7" file="shared_pseudocode.xml">FPProcessNaNs</a>{N}(type1, type2, op1, op2, fpcr, fpexc);
    if !done then
        let inf1 : boolean = (type1 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let inf2 : boolean = (type2 == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>);
        let zero1 : boolean = (type1 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);
        let zero2 : boolean = (type2 == <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>);

        if inf1 &amp;&amp; inf2 &amp;&amp; sign1 == sign2 then
            result = <a link="func_FPDefaultNaN_2" file="shared_pseudocode.xml">FPDefaultNaN</a>{N}(fpcr);
            if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr); end;
        elsif (inf1 &amp;&amp; sign1 == '0') || (inf2 &amp;&amp; sign2 == '1') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}('0');
        elsif (inf1 &amp;&amp; sign1 == '1') || (inf2 &amp;&amp; sign2 == '0') then
            result = <a link="func_FPInfinity_2" file="shared_pseudocode.xml">FPInfinity</a>{N}('1');
        elsif zero1 &amp;&amp; zero2 &amp;&amp; sign1 == NOT(sign2) then
            result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(sign1);
        else
            let result_value : real = value1 - value2;
            if result_value == 0.0 then  // Sign of exact zero result depends on rounding mode
                let result_sign : bit = if rounding == <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a> then '1' else '0';
                result = <a link="func_FPZero_2" file="shared_pseudocode.xml">FPZero</a>{N}(result_sign);
            else
                result = <a link="func_FPRound_5" file="shared_pseudocode.xml">FPRound</a>{N}(result_value, fpcr, rounding, fpexc);
            end;
        end;

        if fpexc then <a link="func_FPProcessDenorms_4" file="shared_pseudocode.xml">FPProcessDenorms</a>(type1, type2, N, fpcr); end;
    end;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fpsub/FPSub_ZA" mylink="shared.functions.float.fpsub.FPSub_ZA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPSub_ZA()
// ==========
// Calculates op1-op2 for SME2 ZA-targeting instructions.

func <anchor link="func_FPSub_ZA_4">FPSub_ZA</anchor>{N}(op1 : bits(N), op2 : bits(N), fpcr_in : FPCR_Type) =&gt; bits(N)
begin
    var fpcr : FPCR_Type = fpcr_in;
    let fpexc : boolean = FALSE; // Do not generate floating-point exceptions
    fpcr.DN = '1';                  // Generate default NaN values
    return <a link="func_FPSub_5" file="shared_pseudocode.xml">FPSub</a>{N}(op1, op2, fpcr, fpexc);
end;</pstext></ps>
    <ps name="shared/functions/float/fpthree/FPThree" mylink="shared.functions.float.fpthree.FPThree" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPThree()
// =========

func <anchor link="func_FPThree_2">FPThree</anchor>{N}(sign : bit) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    let E : integer{} = (if N == 16 then 5 else (if N == 32 then 8 else 11));
    let F : integer{}  = N - (E + 1);
    let exp : bits(E)  = '1'::Zeros{E-1};
    let frac : bits(F) = '1'::Zeros{F-1};
    let result : bits((F + E) + 1) = sign :: exp :: frac;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fptofixed/FPToFixed" mylink="shared.functions.float.fptofixed.FPToFixed" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPToFixed()
// ===========

// Convert N-bit precision floating point 'op' to M-bit fixed point with
// FBITS fractional bits, controlled by UNSIGNED and ROUNDING.

func <anchor link="func_FPToFixed_7">FPToFixed</anchor>{M, N}(op : bits(N), fbits : integer, unsigned : boolean, fpcr : FPCR_Type,
                     rounding : <a link="type_FPRounding" file="shared_pseudocode.xml">FPRounding</a>) =&gt; bits(M)
begin
    assert N IN {16,32,64};
    assert M IN {16,32,64};
    assert fbits &gt;= 0;
    assert rounding != <a link="enum_FPRounding_ODD" file="shared_pseudocode.xml">FPRounding_ODD</a>;

    // When alternative floating-point support is TRUE, do not generate
    // Input Denormal floating-point exceptions.
    let altfp = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1';
    let fpexc = !altfp;

    // Unpack using fpcr to determine if subnormals are flushed-to-zero.
    var (fptype,sign,value) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{N}(op, fpcr, fpexc);

    // If NaN, set cumulative flag or take exception.
    if fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || fptype == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
    end;

    // Scale by fractional bits and produce integer rounded towards minus-infinity.
    value = value * 2.0^fbits;
    var int_result : integer = RoundDown(value);
    let error : real         = value - Real(int_result);

    // Determine whether supplied rounding mode requires an increment.
    var round_up : boolean;
    case rounding of
        when <a link="enum_FPRounding_TIEEVEN" file="shared_pseudocode.xml">FPRounding_TIEEVEN</a> =&gt;
            round_up = (error &gt; 0.5 || (error == 0.5 &amp;&amp; int_result[0] == '1'));
        when <a link="enum_FPRounding_POSINF" file="shared_pseudocode.xml">FPRounding_POSINF</a> =&gt;
            round_up = (error != 0.0);
        when <a link="enum_FPRounding_NEGINF" file="shared_pseudocode.xml">FPRounding_NEGINF</a> =&gt;
            round_up = FALSE;
        when <a link="enum_FPRounding_ZERO" file="shared_pseudocode.xml">FPRounding_ZERO</a> =&gt;
            round_up = (error != 0.0 &amp;&amp; int_result &lt; 0);
        when <a link="enum_FPRounding_TIEAWAY" file="shared_pseudocode.xml">FPRounding_TIEAWAY</a> =&gt;
            round_up = (error &gt; 0.5 || (error == 0.5 &amp;&amp; int_result &gt;= 0));
    end;

    if round_up then int_result = int_result + 1; end;

    // Generate saturated result and exceptions.
    let (result, overflow) : (bits(M), boolean) = <a link="func_SatQ_3" file="shared_pseudocode.xml">SatQ</a>{M}(int_result, unsigned);
    if overflow then
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
    elsif error != 0.0 then
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_Inexact" file="shared_pseudocode.xml">FPExc_Inexact</a>, fpcr);
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fptofixedjs/FPToFixedJS" mylink="shared.functions.float.fptofixedjs.FPToFixedJS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPToFixedJS()
// =============

// Converts a double precision floating point input value
// to a signed integer, with rounding to zero.

func <anchor link="func_FPToFixedJS_2">FPToFixedJS</anchor>(op : bits(64), fpcr : FPCR_Type) =&gt; (bits(32), bit)
begin

    // If FALSE, never generate Input Denormal floating-point exceptions.
    let fpexc_idenorm : boolean = !(IsFeatureImplemented(FEAT_AFP) &amp;&amp;
                                    !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; fpcr.AH == '1');

    // Unpack using fpcr to determine if subnormals are flushed-to-zero.
    let (fptype,sign,value) = <a link="func_FPUnpack_4" file="shared_pseudocode.xml">FPUnpack</a>{64}(op, fpcr, fpexc_idenorm);

    var z : bit = '1';
    // If NaN, set cumulative flag or take exception.
    if fptype == <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a> || fptype == <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> then
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
        z = '0';
    end;

    var int_result = RoundDown(value);
    let error = value - Real(int_result);

    // Determine whether supplied rounding mode requires an increment.

    let round_it_up = (error != 0.0 &amp;&amp; int_result &lt; 0);
    if round_it_up then int_result = int_result + 1; end;

    var result : integer;
    if int_result &lt; 0 then
        result = int_result - 2^32*RoundUp(Real(int_result)/Real(2^32));
    else
        result = int_result - 2^32*RoundDown(Real(int_result)/Real(2^32));
    end;

    // Generate exceptions.
    if int_result &lt; -(2^31) || int_result &gt; (2^31)-1 then
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InvalidOp" file="shared_pseudocode.xml">FPExc_InvalidOp</a>, fpcr);
        z = '0';
    elsif error != 0.0 then
        <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_Inexact" file="shared_pseudocode.xml">FPExc_Inexact</a>, fpcr);
        z = '0';
    elsif sign == '1' &amp;&amp; value == 0.0 then
        z = '0';
    elsif sign == '0' &amp;&amp; value == 0.0 &amp;&amp; !IsZero(op[51:0]) then
        z = '0';
    end;

    if fptype == <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a> then result = 0; end;

    return (result[31:0], z);
end;</pstext></ps>
    <ps name="shared/functions/float/fptwo/FPTwo" mylink="shared.functions.float.fptwo.FPTwo" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPTwo()
// =======

func <anchor link="func_FPTwo_2">FPTwo</anchor>{N}(sign : bit) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    let E : integer{} = (if N == 16 then 5 else (if N == 32 then 8 else 11));
    let F : integer{}  = N - (E + 1);
    let exp : bits(E)  = '1'::Zeros{E-1};
    let frac : bits(F) = Zeros{};
    let result : bits((F + E) + 1) = sign :: exp :: frac;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/fptype/FPType" mylink="shared.functions.float.fptype.FPType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPType
// ======

type <anchor link="type_FPType">FPType</anchor> of enumeration {<anchor link="enum_FPType_Zero">FPType_Zero</anchor>,
                            <anchor link="enum_FPType_Denormal">FPType_Denormal</anchor>,
                            <anchor link="enum_FPType_Nonzero">FPType_Nonzero</anchor>,
                            <anchor link="enum_FPType_Infinity">FPType_Infinity</anchor>,
                            <anchor link="enum_FPType_QNaN">FPType_QNaN</anchor>,
                            <anchor link="enum_FPType_SNaN">FPType_SNaN</anchor>};</pstext></ps>
    <ps name="shared/functions/float/fpunpack/FPUnpack" mylink="shared.functions.float.fpunpack.FPUnpack" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPUnpack()
// ==========

func <anchor link="func_FPUnpack_3">FPUnpack</anchor>{N}(fpval : bits(N), fpcr_in : FPCR_Type) =&gt; (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real)
begin
    var fpcr : FPCR_Type = fpcr_in;
    fpcr.AHP = '0';
    let fpexc : boolean = TRUE;   // Generate floating-point exceptions
    let (fp_type, sign, value) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpackBase_4" file="shared_pseudocode.xml">FPUnpackBase</a>{N}(fpval, fpcr, fpexc);
    return (fp_type, sign, value);
end;

// FPUnpack()
// ==========
//
// Used by data processing, int/fixed to FP and FP to int/fixed conversion instructions.
// For half-precision data it ignores AHP, and observes FZ16.

func <anchor link="func_FPUnpack_4">FPUnpack</anchor>{N}(fpval : bits(N), fpcr_in : FPCR_Type, fpexc : boolean) =&gt; (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real)
begin
    var fpcr : FPCR_Type = fpcr_in;
    fpcr.AHP = '0';
    let (fp_type, sign, value) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpackBase_4" file="shared_pseudocode.xml">FPUnpackBase</a>{N}(fpval, fpcr, fpexc);
    return (fp_type, sign, value);
end;</pstext></ps>
    <ps name="shared/functions/float/fpunpack/FPUnpackBase" mylink="shared.functions.float.fpunpack.FPUnpackBase" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPUnpackBase()
// ==============

func <anchor link="func_FPUnpackBase_4">FPUnpackBase</anchor>{N}(fpval : bits(N), fpcr : FPCR_Type, fpexc : boolean) =&gt; (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real)
begin
    let isbfloat16 : boolean = FALSE;
    let (fp_type, sign, value) = <a link="func_FPUnpackBase_5" file="shared_pseudocode.xml">FPUnpackBase</a>{N}(fpval, fpcr, fpexc, isbfloat16);
    return (fp_type, sign, value);
end;

// FPUnpackBase()
// ==============
//
// Unpack a floating-point number into its type, sign bit and the real number
// that it represents. The real number result has the correct sign for numbers
// and infinities, is very large in magnitude for infinities, and is 0.0 for
// NaNs. (These values are chosen to simplify the description of comparisons
// and conversions.)
//
// The 'fpcr_in' argument supplies FPCR control bits, 'fpexc' controls the
// generation of floating-point exceptions and 'isbfloat16' determines whether
// N=16 signifies BFloat16 or half-precision type. Status information is updated
// directly in the FPSR where appropriate.

func <anchor link="func_FPUnpackBase_5">FPUnpackBase</anchor>{N}(fpval : bits(N), fpcr_in : FPCR_Type, fpexc : boolean,
                     isbfloat16 : boolean) =&gt; (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real)
begin
    assert N IN {16,32,64};

    let fpcr : FPCR_Type = fpcr_in;

    let altfp : boolean = IsFeatureImplemented(FEAT_AFP) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>();
    let fiz : boolean   = altfp &amp;&amp; fpcr.FIZ == '1';
    let fz : boolean    = fpcr.FZ == '1' &amp;&amp; !(altfp &amp;&amp; fpcr.AH == '1');
    var value : real;
    var sign : bit;
    var fptype : <a link="type_FPType" file="shared_pseudocode.xml">FPType</a>;

    if N == 16 &amp;&amp; !isbfloat16 then
        sign   = fpval[15];
        let exp16 : bits(5)   = fpval[14:10];
        let frac16 : bits(10) = fpval[9:0];
        if IsZero(exp16) then
            if IsZero(frac16) || fpcr.FZ16 == '1' then
                fptype = <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>;  value = 0.0;
            else
                fptype = <a link="enum_FPType_Denormal" file="shared_pseudocode.xml">FPType_Denormal</a>;  value = 2.0^-14 * (Real(UInt(frac16)) * 2.0^-10);
            end;
        elsif IsOnes(exp16) &amp;&amp; fpcr.AHP == '0' then  // Infinity or NaN in IEEE format
            if IsZero(frac16) then
                fptype = <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>;  value = 2.0^1000000;
            else
                fptype = if frac16[9] == '1' then <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> else <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>;
                value = 0.0;
            end;
        else
            fptype = <a link="enum_FPType_Nonzero" file="shared_pseudocode.xml">FPType_Nonzero</a>;
            value = 2.0^(UInt(exp16)-15) * (1.0 + Real(UInt(frac16)) * 2.0^-10);
        end;

    elsif N == 32 || isbfloat16 then
        var exp32 : bits(8);
        var frac32 : bits(23);
        if isbfloat16 then
            sign   = fpval[15];
            exp32  = fpval[14:7];
            frac32 = fpval[6:0] :: Zeros{16};
        else
            sign   = fpval[31];
            exp32  = fpval[30:23];
            frac32 = fpval[22:0];
        end;

        if IsZero(exp32) then
            if IsZero(frac32) then
                // Produce zero if value is zero.
                fptype = <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>;  value = 0.0;
            elsif fz || fiz then        // Flush-to-zero if FIZ==1 or AH,FZ==01
                fptype = <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>;  value = 0.0;
                // Check whether to raise Input Denormal floating-point exception.
                // fpcr.FIZ==1 does not raise Input Denormal exception.
                if fz then
                    // Denormalized input flushed to zero
                    if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InputDenorm" file="shared_pseudocode.xml">FPExc_InputDenorm</a>, fpcr); end;
                end;
            else
                fptype = <a link="enum_FPType_Denormal" file="shared_pseudocode.xml">FPType_Denormal</a>;  value = 2.0^-126 * (Real(UInt(frac32)) * 2.0^-23);
            end;
        elsif IsOnes(exp32) then
            if IsZero(frac32) then
                fptype = <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>;  value = 2.0^1000000;
            else
                fptype = if frac32[22] == '1' then <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> else <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>;
                value = 0.0;
            end;
        else
            fptype = <a link="enum_FPType_Nonzero" file="shared_pseudocode.xml">FPType_Nonzero</a>;
            value = 2.0^(UInt(exp32)-127) * (1.0 + Real(UInt(frac32)) * 2.0^-23);
        end;

    else // N == 64
        sign   = fpval[63];
        let exp64 : bits(11)  = fpval[62:52];
        let frac64 : bits(52) = fpval[51:0];

        if IsZero(exp64) then
            if IsZero(frac64) then
                // Produce zero if value is zero.
                fptype = <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>;  value = 0.0;
            elsif fz || fiz then        // Flush-to-zero if FIZ==1 or AH,FZ==01
                fptype = <a link="enum_FPType_Zero" file="shared_pseudocode.xml">FPType_Zero</a>;  value = 0.0;
                // Check whether to raise Input Denormal floating-point exception.
                // fpcr.FIZ==1 does not raise Input Denormal exception.
                if fz then
                    // Denormalized input flushed to zero
                    if fpexc then <a link="func_FPProcessException_2" file="shared_pseudocode.xml">FPProcessException</a>(<a link="enum_FPExc_InputDenorm" file="shared_pseudocode.xml">FPExc_InputDenorm</a>, fpcr); end;
                end;
            else
                fptype = <a link="enum_FPType_Denormal" file="shared_pseudocode.xml">FPType_Denormal</a>;  value = 2.0^-1022 * (Real(UInt(frac64)) * 2.0^-52);
            end;
        elsif IsOnes(exp64) then
            if IsZero(frac64) then
                fptype = <a link="enum_FPType_Infinity" file="shared_pseudocode.xml">FPType_Infinity</a>;  value = 2.0^1000000;
            else
                fptype = if frac64[51] == '1' then <a link="enum_FPType_QNaN" file="shared_pseudocode.xml">FPType_QNaN</a> else <a link="enum_FPType_SNaN" file="shared_pseudocode.xml">FPType_SNaN</a>;
                value  = 0.0;
            end;
        else
            fptype = <a link="enum_FPType_Nonzero" file="shared_pseudocode.xml">FPType_Nonzero</a>;
            value  = 2.0^(UInt(exp64)-1023) * (1.0 + Real(UInt(frac64)) * 2.0^-52);
        end;
    end;

    if sign == '1' then value = -value; end;

    return (fptype, sign, value);
end;</pstext></ps>
    <ps name="shared/functions/float/fpunpack/FPUnpackCV" mylink="shared.functions.float.fpunpack.FPUnpackCV" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPUnpackCV()
// ============
//
// Used for FP to FP conversion instructions.
// For half-precision data ignores FZ16 and observes AHP.

func <anchor link="func_FPUnpackCV_3">FPUnpackCV</anchor>{N}(fpval : bits(N), fpcr_in : FPCR_Type) =&gt; (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real)
begin
    var fpcr : FPCR_Type = fpcr_in;
    fpcr.FZ16 = '0';
    let fpexc : boolean = TRUE;   // Generate floating-point exceptions
    let (fp_type, sign, value) : (<a link="type_FPType" file="shared_pseudocode.xml">FPType</a>, bit, real) = <a link="func_FPUnpackBase_4" file="shared_pseudocode.xml">FPUnpackBase</a>{N}(fpval, fpcr, fpexc);
    return (fp_type, sign, value);
end;</pstext></ps>
    <ps name="shared/functions/float/fpzero/FPZero" mylink="shared.functions.float.fpzero.FPZero" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FPZero()
// ========

func <anchor link="func_FPZero_2">FPZero</anchor>{N}(sign : bit) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    let E : integer{}  = (if N == 16 then 5 else (if N == 32 then 8 else 11));
    let F : integer{}  = N - (E + 1);
    let exp : bits(E)  = Zeros{};
    let frac : bits(F) = Zeros{};
    let result : bits((F + E) + 1) = sign :: exp :: frac;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/float/vfpexpandimm/VFPExpandImm" mylink="shared.functions.float.vfpexpandimm.VFPExpandImm" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// VFPExpandImm()
// ==============

func <anchor link="func_VFPExpandImm_2">VFPExpandImm</anchor>{N}(imm8 : bits(8)) =&gt; bits(N)
begin
    assert N IN {16,32,64};
    let E : integer{} = (if N == 16 then 5 else (if N == 32 then 8 else 11));
    let F : integer{} = (N - E) - 1;
    let sign : bit = imm8[7];
    let exp : bits(E)  = NOT(imm8[6])::Replicate{E - 3}(imm8[6])::imm8[5:4];
    let frac : bits(F) = imm8[3:0]::Zeros{F-4};
    let result : bits((F + E) + 1) = sign :: exp :: frac;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/integer/AddWithCarry" mylink="shared.functions.integer.AddWithCarry" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddWithCarry()
// ==============
// Integer addition with carry input, returning result and NZCV flags

func <anchor link="func_AddWithCarry_4">AddWithCarry</anchor>{N}(x : bits(N), y : bits(N), carry_in : bit) =&gt; (bits(N), bits(4))
begin
    let unsigned_sum : integer = UInt(x) + UInt(y) + UInt(carry_in);
    let signed_sum : integer = SInt(x) + SInt(y) + UInt(carry_in);
    let result : bits(N) = unsigned_sum[N-1:0]; // same value as signed_sum[N-1:0]
    let n : bit = result[N-1];
    let z : bit = if IsZero(result) then '1' else '0';
    let c : bit = if UInt(result) == unsigned_sum then '0' else '1';
    let v : bit = if SInt(result) == signed_sum then '0' else '1';
    return (result, n::z::c::v);
end;</pstext></ps>
    <ps name="shared/functions/interrupts/InterruptID" mylink="shared.functions.interrupts.InterruptID" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// InterruptID
// ===========

type <anchor link="type_InterruptID">InterruptID</anchor> of enumeration {
    <anchor link="enum_InterruptID_PMUIRQ">InterruptID_PMUIRQ</anchor>,
    <anchor link="enum_InterruptID_COMMIRQ">InterruptID_COMMIRQ</anchor>,
    <anchor link="enum_InterruptID_CTIIRQ">InterruptID_CTIIRQ</anchor>,
    <anchor link="enum_InterruptID_COMMRX">InterruptID_COMMRX</anchor>,
    <anchor link="enum_InterruptID_COMMTX">InterruptID_COMMTX</anchor>,
    <anchor link="enum_InterruptID_CNTP">InterruptID_CNTP</anchor>,
    <anchor link="enum_InterruptID_CNTHP">InterruptID_CNTHP</anchor>,
    <anchor link="enum_InterruptID_CNTHPS">InterruptID_CNTHPS</anchor>,
    <anchor link="enum_InterruptID_CNTPS">InterruptID_CNTPS</anchor>,
    <anchor link="enum_InterruptID_CNTV">InterruptID_CNTV</anchor>,
    <anchor link="enum_InterruptID_CNTHV">InterruptID_CNTHV</anchor>,
    <anchor link="enum_InterruptID_CNTHVS">InterruptID_CNTHVS</anchor>,
    <anchor link="enum_InterruptID_PMBIRQ">InterruptID_PMBIRQ</anchor>,
    <anchor link="enum_InterruptID_HACDBSIRQ">InterruptID_HACDBSIRQ</anchor>,

    <anchor link="enum_InterruptID_TRBIRQ">InterruptID_TRBIRQ</anchor>,
};</pstext></ps>
    <ps name="shared/functions/interrupts/SetInterruptRequestLevel" mylink="shared.functions.interrupts.SetInterruptRequestLevel" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SetInterruptRequestLevel()
// ==========================
// Set a level-sensitive interrupt to the specified level.

impdef func SetInterruptRequestLevel(id : <a link="type_InterruptID" file="shared_pseudocode.xml">InterruptID</a>, level : <a link="type_Signal" file="shared_pseudocode.xml">Signal</a>)
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/memory/AArch64_BranchAddr" mylink="shared.functions.memory.AArch64_BranchAddr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_BranchAddr()
// ====================
// Return the virtual address with tag bits removed.
// This is typically used when the address will be stored to the program counter.

func <anchor link="func_AArch64_BranchAddr_2">AArch64_BranchAddr</anchor>(vaddress : bits(64), el : bits(2)) =&gt; bits(64)
begin
    assert !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>();
    let msbit : integer{} = <a link="func_AddrTop_3" file="shared_pseudocode.xml">AddrTop</a>(vaddress, TRUE, el);
    if msbit == 63 then
        return vaddress;
    elsif (el IN {<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>, <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>} || <a link="func_IsInHost_0" file="shared_pseudocode.xml">IsInHost</a>()) &amp;&amp; vaddress[msbit] == '1' then
        return SignExtend{64}(vaddress[msbit:0]);
    else
        return ZeroExtend{64}(vaddress[msbit:0]);
    end;
end;</pstext></ps>
    <ps name="shared/functions/memory/AccessDescriptor" mylink="shared.functions.memory.AccessDescriptor" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AccessDescriptor
// ================
// Memory access or translation invocation details that steer architectural behavior


type <anchor link="type_AccessDescriptor">AccessDescriptor</anchor> of record {
    acctype : <a link="type_AccessType" file="shared_pseudocode.xml">AccessType</a>,
    el : bits(2),                  // Acting EL for the access
    ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>,            // Acting Security State for the access
    acqsc : boolean,               // Acquire with Sequential Consistency
    acqpc : boolean,               // FEAT_LRCPC: Acquire with Processor Consistency
    relsc : boolean,               // Release with Sequential Consistency
    limitedordered : boolean,      // FEAT_LOR: Acquire/Release with limited ordering
    exclusive : boolean,           // Access has Exclusive semantics
    atomicop : boolean,            // FEAT_LSE: Atomic read-modify-write access
    modop : <a link="type_MemAtomicOp" file="shared_pseudocode.xml">MemAtomicOp</a>,           // FEAT_LSE: The modification operation in the 'atomicop' access
    nontemporal : boolean,         // Hints the access is non-temporal
    read : boolean,                // Read from memory or only require read permissions
    write : boolean,               // Write to memory or only require write permissions
    cacheop : <a link="type_CacheOp" file="shared_pseudocode.xml">CacheOp</a>,             // DC/IC: Cache operation
    opscope : <a link="type_CacheOpScope" file="shared_pseudocode.xml">CacheOpScope</a>,        // DC/IC: Scope of cache operation
    cachetype : <a link="type_CacheType" file="shared_pseudocode.xml">CacheType</a>,         // DC/IC: Type of target cache
    pan : boolean,                 // FEAT_PAN: The access is subject to PSTATE.PAN
    nonfault : boolean,            // SVE: Non-faulting load
    firstfault : boolean,          // SVE: First-fault load
    first : boolean,               // SVE: First-fault load for the first active element
    contiguous : boolean,          // SVE: Contiguous load/store not gather load/scatter store
    predicated : boolean,          // SVE: Predicated load/store
    streamingsve : boolean,        // SME: Access made by PE while in streaming SVE mode
    ls64 : boolean,                // FEAT_LS64: Accesses by accelerator support loads/stores
    withstatus : boolean,          // FEAT_LS64: Store with status result
    mops : boolean,                // FEAT_MOPS: Memory operation (CPY/SET) accesses
    rcw : boolean,                 // FEAT_THE: Read-Check-Write access
    rcws : boolean,                // FEAT_THE: Read-Check-Write Software access
    toplevel : boolean,            // FEAT_THE: Translation table walk access for TTB address
    varange : <a link="type_VARange" file="shared_pseudocode.xml">VARange</a>,             // FEAT_THE: The corresponding TTBR supplying the TTB
    a32lsmd : boolean,             // A32 Load/Store Multiple Data access
    tagchecked : boolean,          // FEAT_MTE2: Access is tag checked
    tagaccess : boolean,           // FEAT_MTE: Access targets the tag bits
    stzgm : boolean,               // FEAT_MTE: Accesses that store Allocation tags to Device
                                   //           memory are CONSTRAINED UNPREDICTABLE
    Rt : integer,                  // Register named Rt in the instruction
    Rt2 : integer,                 // Register named Rt2 in the instruction
    Rs : integer,                  // Register named Rs in the instruction
    Rs2 : integer,                 // Register named Rs2 in the instruction
    ispair : boolean,              // Access represents a Load/Store pair access
    highestaddressfirst : boolean, // FEAT_LRCPC3: Highest address is accessed first
    lowestaddress : boolean,       // Is the current access the lowest address accessed by
                                   // this instruction
    mpam : <a link="type_MPAMinfo" file="shared_pseudocode.xml">MPAMinfo</a>                // FEAT_MPAM: MPAM information
};</pstext></ps>
    <ps name="shared/functions/memory/AccessType" mylink="shared.functions.memory.AccessType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AccessType
// ==========

type <anchor link="type_AccessType">AccessType</anchor> of enumeration {
    <anchor link="enum_AccessType_IFETCH">AccessType_IFETCH</anchor>,     // Instruction FETCH
    <anchor link="enum_AccessType_GPR">AccessType_GPR</anchor>,        // Software load/store to a General Purpose Register
    <anchor link="enum_AccessType_FP">AccessType_FP</anchor>,         // Software load/store to an FP register
    <anchor link="enum_AccessType_ASIMD">AccessType_ASIMD</anchor>,      // Software ASIMD extension load/store instructions
    <anchor link="enum_AccessType_SVE">AccessType_SVE</anchor>,        // Software SVE load/store instructions
    <anchor link="enum_AccessType_SME">AccessType_SME</anchor>,        // Software SME load/store instructions
    <anchor link="enum_AccessType_IC">AccessType_IC</anchor>,         // Sysop IC
    <anchor link="enum_AccessType_DC">AccessType_DC</anchor>,         // Sysop DC (not DC {Z,G,GZ}VA)
    <anchor link="enum_AccessType_DCZero">AccessType_DCZero</anchor>,     // Sysop DC {Z,G,GZ}VA
    <anchor link="enum_AccessType_AT">AccessType_AT</anchor>,         // Sysop AT
    <anchor link="enum_AccessType_NV2">AccessType_NV2</anchor>,        // NV2 memory redirected access
    <anchor link="enum_AccessType_SPE">AccessType_SPE</anchor>,        // Statistical Profiling buffer access
    <anchor link="enum_AccessType_GCS">AccessType_GCS</anchor>,        // Guarded Control Stack access
    <anchor link="enum_AccessType_TRBE">AccessType_TRBE</anchor>,       // Trace Buffer access
    <anchor link="enum_AccessType_GPTW">AccessType_GPTW</anchor>,       // Granule Protection Table Walk
    <anchor link="enum_AccessType_HACDBS">AccessType_HACDBS</anchor>,     // Access to the HACDBS structure
    <anchor link="enum_AccessType_HDBSS">AccessType_HDBSS</anchor>,      // Access to entries in HDBSS
    <anchor link="enum_AccessType_TTW">AccessType_TTW</anchor>         // Translation Table Walk
};</pstext></ps>
    <ps name="shared/functions/memory/AddrTop" mylink="shared.functions.memory.AddrTop" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddrTop()
// =========
// Return the MSB number of a virtual address in the stage 1 translation regime for &quot;el&quot;.
// If EL1 is using AArch64 then addresses from EL0 using AArch32 are zero-extended to 64 bits.

func <anchor link="func_AddrTop_3">AddrTop</anchor>(address : bits(64), IsInstr : boolean, el : bits(2)) =&gt; <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>
begin
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(el);
    let regime : bits(2) = <a link="func_S1TranslationRegime_1" file="shared_pseudocode.xml">S1TranslationRegime</a>(el);
    if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(regime) then
        // AArch32 translation regime.
        return 31;
    else
        if <a link="func_EffectiveTBI_3" file="shared_pseudocode.xml">EffectiveTBI</a>(address, IsInstr, el) == '1' then
            return 55;
        else
            return 63;
        end;
    end;
end;</pstext></ps>
    <ps name="shared/functions/memory/AddressSize" mylink="shared.functions.memory.AddressSize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddressSize
// ============

type <anchor link="type_AddressSize">AddressSize</anchor> of integer{3..64};</pstext></ps>
    <ps name="shared/functions/memory/AlignmentEnforced" mylink="shared.functions.memory.AlignmentEnforced" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AlignmentEnforced()
// ===================
// For the active translation regime, determine if alignment is required by all accesses

func <anchor link="func_AlignmentEnforced_0">AlignmentEnforced</anchor>() =&gt; boolean
begin
    let regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a> = <a link="func_TranslationRegime_1" file="shared_pseudocode.xml">TranslationRegime</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    var A : bit;
    case regime of
        when <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a> =&gt; A = SCTLR().A;
        when <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> =&gt;  A = SCTLR_EL3().A;
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> =&gt;  A = if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then HSCTLR().A else SCTLR_EL2().A;
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt; A = SCTLR_EL2().A;
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt; A = if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then SCTLR().A  else SCTLR_EL1().A;
        otherwise =&gt; unreachable;
    end;
    return A == '1';
end;</pstext></ps>
    <ps name="shared/functions/memory/AllInAlignedQuantity" mylink="shared.functions.memory.AllInAlignedQuantity" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AllInAlignedQuantity()
// ======================
// Returns TRUE if all accessed bytes are within one aligned quantity, FALSE otherwise.

readonly func <anchor link="func_AllInAlignedQuantity_4">AllInAlignedQuantity</anchor>{N : integer{32, 64}}(address : bits(N),
                                                        size : integer,
                                                        alignment : integer) =&gt; boolean
begin
    return (AlignDownSize(address+(size-1), alignment as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>) ==
            AlignDownSize(address, alignment as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>));
end;</pstext></ps>
    <ps name="shared/functions/memory/Allocation" mylink="shared.functions.memory.Allocation" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Allocation hints
// ================

constant <anchor link="global_MemHint_No">MemHint_No</anchor> : bits(2)  = '00';    // No Read-Allocate, No Write-Allocate
constant <anchor link="global_MemHint_WA">MemHint_WA</anchor> : bits(2)  = '01';    // No Read-Allocate, Write-Allocate
constant <anchor link="global_MemHint_RA">MemHint_RA</anchor> : bits(2)  = '10';    // Read-Allocate, No Write-Allocate
constant <anchor link="global_MemHint_RWA">MemHint_RWA</anchor> : bits(2) = '11';    // Read-Allocate, Write-Allocate</pstext></ps>
    <ps name="shared/functions/memory/BigEndian" mylink="shared.functions.memory.BigEndian" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BigEndian()
// ===========

func <anchor link="func_BigEndian_1">BigEndian</anchor>(acctype : <a link="type_AccessType" file="shared_pseudocode.xml">AccessType</a>) =&gt; boolean
begin
    var bigend : boolean;
    if IsFeatureImplemented(FEAT_NV2) &amp;&amp; acctype == <a link="enum_AccessType_NV2" file="shared_pseudocode.xml">AccessType_NV2</a> then
        return SCTLR_EL2().EE == '1';
    end;

    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        bigend = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.E != '0');
    elsif <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        bigend = (<a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>().E0E != '0');
    else
        bigend = (<a link="accessor_SCTLR_ELx_0" file="shared_pseudocode.xml">SCTLR_ELx</a>().EE != '0');
    end;
    return bigend;
end;</pstext></ps>
    <ps name="shared/functions/memory/BigEndianReverse" mylink="shared.functions.memory.BigEndianReverse" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BigEndianReverse()
// ==================

func <anchor link="func_BigEndianReverse_2">BigEndianReverse</anchor>{width}(value : bits(width)) =&gt; bits(width)
begin
    assert width IN {8, 16, 32, 64, 128, 256};

    if width == 8 then return value; end;
    return <a link="func_Reverse_3" file="shared_pseudocode.xml">Reverse</a>{width}(value, 8);
end;</pstext></ps>
    <ps name="shared/functions/memory/CacheOp" mylink="shared.functions.memory.CacheOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CacheOp
// =======

type <anchor link="type_CacheOp">CacheOp</anchor> of enumeration {
    <anchor link="enum_CacheOp_Clean">CacheOp_Clean</anchor>,
    <anchor link="enum_CacheOp_Invalidate">CacheOp_Invalidate</anchor>,
    <anchor link="enum_CacheOp_CleanInvalidate">CacheOp_CleanInvalidate</anchor>
};</pstext></ps>
    <ps name="shared/functions/memory/CacheOpScope" mylink="shared.functions.memory.CacheOpScope" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CacheOpScope
// ============

type <anchor link="type_CacheOpScope">CacheOpScope</anchor> of enumeration {
    <anchor link="enum_CacheOpScope_SetWay">CacheOpScope_SetWay</anchor>,
    <anchor link="enum_CacheOpScope_PoU">CacheOpScope_PoU</anchor>,
    <anchor link="enum_CacheOpScope_PoC">CacheOpScope_PoC</anchor>,
    <anchor link="enum_CacheOpScope_PoE">CacheOpScope_PoE</anchor>,
    <anchor link="enum_CacheOpScope_PoP">CacheOpScope_PoP</anchor>,
    <anchor link="enum_CacheOpScope_PoDP">CacheOpScope_PoDP</anchor>,
    <anchor link="enum_CacheOpScope_PoPA">CacheOpScope_PoPA</anchor>,
    <anchor link="enum_CacheOpScope_PoPS">CacheOpScope_PoPS</anchor>,
    <anchor link="enum_CacheOpScope_OuterCache">CacheOpScope_OuterCache</anchor>,
    <anchor link="enum_CacheOpScope_ALLU">CacheOpScope_ALLU</anchor>,
    <anchor link="enum_CacheOpScope_ALLUIS">CacheOpScope_ALLUIS</anchor>
};</pstext></ps>
    <ps name="shared/functions/memory/CachePASpace" mylink="shared.functions.memory.CachePASpace" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CachePASpace
// ============

type <anchor link="type_CachePASpace">CachePASpace</anchor> of enumeration {
    <anchor link="enum_CPAS_NonSecure">CPAS_NonSecure</anchor>,
    <anchor link="enum_CPAS_Any">CPAS_Any</anchor>,                   // Applicable only for DC *SW / IC IALLU* in Root state:
                                // match entries from any PA Space
    <anchor link="enum_CPAS_RealmNonSecure">CPAS_RealmNonSecure</anchor>,        // Applicable only for DC *SW / IC IALLU* in Realm state:
                                // match entries from Realm or Non-Secure PAS
    <anchor link="enum_CPAS_Realm">CPAS_Realm</anchor>,
    <anchor link="enum_CPAS_Root">CPAS_Root</anchor>,
    <anchor link="enum_CPAS_SystemAgent">CPAS_SystemAgent</anchor>,           // Applicable only for DC by PA:
                                // match entries from the System Agent PAS
    <anchor link="enum_CPAS_NonSecureProtected">CPAS_NonSecureProtected</anchor>,    // Applicable only for DC by PA:
                                // match entries from the Non-Secure Protected PAS
    <anchor link="enum_CPAS_NA6">CPAS_NA6</anchor>,                   // Reserved
    <anchor link="enum_CPAS_NA7">CPAS_NA7</anchor>,                   // Reserved
    <anchor link="enum_CPAS_SecureNonSecure">CPAS_SecureNonSecure</anchor>,       // Applicable only for DC *SW / IC IALLU* in Secure state:
                                // match entries from Secure or Non-Secure PAS
    <anchor link="enum_CPAS_Secure">CPAS_Secure</anchor>
};</pstext></ps>
    <ps name="shared/functions/memory/CacheType" mylink="shared.functions.memory.CacheType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CacheType
// =========

type <anchor link="type_CacheType">CacheType</anchor> of enumeration {
    <anchor link="enum_CacheType_Data">CacheType_Data</anchor>,
    <anchor link="enum_CacheType_Tag">CacheType_Tag</anchor>,
    <anchor link="enum_CacheType_Data_Tag">CacheType_Data_Tag</anchor>,
    <anchor link="enum_CacheType_Instruction">CacheType_Instruction</anchor>
};</pstext></ps>
    <ps name="shared/functions/memory/Cacheability" mylink="shared.functions.memory.Cacheability" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Cacheability attributes
// =======================

constant <anchor link="global_MemAttr_NC">MemAttr_NC</anchor> : bits(2) = '00';     // Non-cacheable
constant <anchor link="global_MemAttr_WT">MemAttr_WT</anchor> : bits(2) = '10';     // Write-through
constant <anchor link="global_MemAttr_WB">MemAttr_WB</anchor> : bits(2) = '11';     // Write-back</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescA32LSMD" mylink="shared.functions.memory.CreateAccDescA32LSMD" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescA32LSMD()
// ======================
// Access descriptor for A32 loads/store multiple general purpose registers

func <anchor link="func_CreateAccDescA32LSMD_1">CreateAccDescA32LSMD</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_GPR" file="shared_pseudocode.xml">AccessType_GPR</a>);

    accdesc.read            = memop == <a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>;
    accdesc.write           = memop == <a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>;
    accdesc.pan             = TRUE;
    accdesc.a32lsmd         = TRUE;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescASIMD" mylink="shared.functions.memory.CreateAccDescASIMD" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescASIMD()
// ====================
// Access descriptor for ASIMD&amp;FP loads/stores

func <anchor link="func_CreateAccDescASIMD_4">CreateAccDescASIMD</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, nontemporal : boolean, tagchecked : boolean,
                        privileged : boolean) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    let ispair : boolean = FALSE;
    return <a link="func_CreateAccDescASIMD_5" file="shared_pseudocode.xml">CreateAccDescASIMD</a>(memop, nontemporal, tagchecked, privileged, ispair);
end;

// CreateAccDescASIMD()
// ====================

func <anchor link="func_CreateAccDescASIMD_5">CreateAccDescASIMD</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, nontemporal : boolean, tagchecked : boolean,
                        privileged : boolean, ispair : boolean) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_ASIMD" file="shared_pseudocode.xml">AccessType_ASIMD</a>);


    accdesc.nontemporal     = nontemporal;
    accdesc.el              = if !privileged then <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> else <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
    accdesc.read            = memop == <a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>;
    accdesc.write           = memop == <a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>;
    accdesc.ispair          = ispair;
    accdesc.pan             = TRUE;
    accdesc.streamingsve    = <a link="func_InStreamingMode_0" file="shared_pseudocode.xml">InStreamingMode</a>();
    if (accdesc.streamingsve &amp;&amp; ImpDefBool(
          &quot;No tag checking of SIMD&amp;FP loads and stores in Streaming SVE mode&quot;)) then
        accdesc.tagchecked  = FALSE;
    else
        accdesc.tagchecked  = tagchecked;
    end;
    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescASIMDAcqRel" mylink="shared.functions.memory.CreateAccDescASIMDAcqRel" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescASIMDAcqRel()
// ==========================
// Access descriptor for ASIMD&amp;FP loads/stores with ordering semantics

func <anchor link="func_CreateAccDescASIMDAcqRel_2">CreateAccDescASIMDAcqRel</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, tagchecked : boolean) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_ASIMD" file="shared_pseudocode.xml">AccessType_ASIMD</a>);

    accdesc.acqpc           = memop == <a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>;
    accdesc.relsc           = memop == <a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>;
    accdesc.read            = memop == <a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>;
    accdesc.write           = memop == <a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>;
    accdesc.pan             = TRUE;
    accdesc.streamingsve    = <a link="func_InStreamingMode_0" file="shared_pseudocode.xml">InStreamingMode</a>();
    if (accdesc.streamingsve &amp;&amp; ImpDefBool(
          &quot;No tag checking of SIMD&amp;FP loads and stores in Streaming SVE mode&quot;)) then
        accdesc.tagchecked  = FALSE;
    else
        accdesc.tagchecked  = tagchecked;
    end;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescAT" mylink="shared.functions.memory.CreateAccDescAT" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescAT()
// =================
// Access descriptor for address translation operations

func <anchor link="func_CreateAccDescAT_3">CreateAccDescAT</anchor>(ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, el : bits(2), ataccess : <a link="type_ATAccess" file="shared_pseudocode.xml">ATAccess</a>) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_AT" file="shared_pseudocode.xml">AccessType_AT</a>);

    accdesc.el              = el;
    accdesc.ss              = ss;
    if ImpDefBool(&quot;MPAM uses the EL targeted by the AT instruction&quot;) then
        accdesc.mpam = <a link="func_GenMPAMAtEL_2" file="shared_pseudocode.xml">GenMPAMAtEL</a>(<a link="enum_AccessType_AT" file="shared_pseudocode.xml">AccessType_AT</a>, el);
    end;
    case ataccess of
        when <a link="enum_ATAccess_Read" file="shared_pseudocode.xml">ATAccess_Read</a> =&gt;
            accdesc.(read, write, pan) = (TRUE, FALSE, FALSE);
        when <a link="enum_ATAccess_ReadPAN" file="shared_pseudocode.xml">ATAccess_ReadPAN</a> =&gt;
            accdesc.(read, write, pan) = (TRUE, FALSE, TRUE);
        when <a link="enum_ATAccess_Write" file="shared_pseudocode.xml">ATAccess_Write</a> =&gt;
            accdesc.(read, write, pan) = (FALSE, TRUE, FALSE);
        when <a link="enum_ATAccess_WritePAN" file="shared_pseudocode.xml">ATAccess_WritePAN</a> =&gt;
            accdesc.(read, write, pan) = (FALSE, TRUE, TRUE);
        when <a link="enum_ATAccess_Any" file="shared_pseudocode.xml">ATAccess_Any</a> =&gt;
            accdesc.(read, write, pan) = (FALSE, FALSE, FALSE);
    end;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescAcqRel" mylink="shared.functions.memory.CreateAccDescAcqRel" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescAcqRel()
// =====================
// Access descriptor for general purpose register loads/stores with ordering semantics

func <anchor link="func_CreateAccDescAcqRel_3">CreateAccDescAcqRel</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, tagchecked : boolean, acqsc : boolean) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    let Rt : integer = -1;
    return <a link="func_CreateAccDescAcqRel_4" file="shared_pseudocode.xml">CreateAccDescAcqRel</a>(memop, tagchecked, acqsc, Rt);
end;

func <anchor link="func_CreateAccDescAcqRel_4">CreateAccDescAcqRel</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, tagchecked : boolean,
                         acqsc : boolean, Rt : integer) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    let ispair : boolean = FALSE;
    let Rt2 : integer = -1;
    return <a link="func_CreateAccDescAcqRel_6" file="shared_pseudocode.xml">CreateAccDescAcqRel</a>(memop, tagchecked, ispair, acqsc, Rt, Rt2);
end;

func <anchor link="func_CreateAccDescAcqRel_6">CreateAccDescAcqRel</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, tagchecked : boolean, ispair : boolean,
                         acqsc : boolean, Rt : integer, Rt2 : integer) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_GPR" file="shared_pseudocode.xml">AccessType_GPR</a>);

    accdesc.acqsc           = acqsc;
    accdesc.relsc           = memop == <a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>;
    accdesc.read            = memop == <a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>;
    accdesc.write           = memop == <a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>;
    accdesc.pan             = TRUE;
    accdesc.tagchecked      = tagchecked;
    accdesc.ispair          = ispair;
    accdesc.Rt              = Rt;
    accdesc.Rt2             = Rt2;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescAtomicOp" mylink="shared.functions.memory.CreateAccDescAtomicOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescAtomicOp()
// =======================
// Access descriptor for atomic read-modify-write memory accesses

func <anchor link="func_CreateAccDescAtomicOp_7">CreateAccDescAtomicOp</anchor>(modop : <a link="type_MemAtomicOp" file="shared_pseudocode.xml">MemAtomicOp</a>, acquire : boolean, release : boolean,
                           tagchecked : boolean, privileged : boolean, Rt : integer,
                           Rs : integer) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    let Rt2 : integer = -1;
    let Rs2 : integer = -1;

    return <a link="func_CreateAccDescAtomicOp_9" file="shared_pseudocode.xml">CreateAccDescAtomicOp</a>(modop, acquire, release, tagchecked, privileged, Rt, Rt2, Rs, Rs2);
end;

func <anchor link="func_CreateAccDescAtomicOp_9">CreateAccDescAtomicOp</anchor>(modop : <a link="type_MemAtomicOp" file="shared_pseudocode.xml">MemAtomicOp</a>, acquire : boolean, release : boolean,
                           tagchecked : boolean, privileged : boolean, Rt : integer,
                           Rt2 : integer, Rs : integer, Rs2 : integer) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_GPR" file="shared_pseudocode.xml">AccessType_GPR</a>);

    accdesc.acqsc           = acquire;
    accdesc.el              = if !privileged then <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> else <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
    accdesc.relsc           = release;
    accdesc.atomicop        = TRUE;
    accdesc.modop           = modop;
    accdesc.read            = TRUE;
    accdesc.write           = TRUE;
    accdesc.pan             = TRUE;
    accdesc.tagchecked      = tagchecked;
    accdesc.Rs              = Rs;
    accdesc.Rs2             = Rs2;
    accdesc.Rt              = Rt;
    accdesc.Rt2             = Rt2;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescDC" mylink="shared.functions.memory.CreateAccDescDC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescDC()
// =================
// Access descriptor for data cache operations

func <anchor link="func_CreateAccDescDC_1">CreateAccDescDC</anchor>(cache : <a link="type_CacheRecord" file="shared_pseudocode.xml">CacheRecord</a>) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>);

    accdesc.cacheop         = cache.cacheop;
    accdesc.cachetype       = cache.cachetype;
    accdesc.opscope         = cache.opscope;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescDCZero" mylink="shared.functions.memory.CreateAccDescDCZero" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescDCZero()
// =====================
// Access descriptor for data cache zero operations

func <anchor link="func_CreateAccDescDCZero_1">CreateAccDescDCZero</anchor>(cachetype : <a link="type_CacheType" file="shared_pseudocode.xml">CacheType</a>) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_DCZero" file="shared_pseudocode.xml">AccessType_DCZero</a>);

    accdesc.write            = TRUE;
    accdesc.pan              = TRUE;
    accdesc.tagchecked       = cachetype == <a link="enum_CacheType_Data" file="shared_pseudocode.xml">CacheType_Data</a>;
    accdesc.tagaccess        = cachetype IN {<a link="enum_CacheType_Tag" file="shared_pseudocode.xml">CacheType_Tag</a>,
                                             <a link="enum_CacheType_Data_Tag" file="shared_pseudocode.xml">CacheType_Data_Tag</a>};
    accdesc.cachetype        = cachetype;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescExLDST" mylink="shared.functions.memory.CreateAccDescExLDST" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescExLDST()
// =====================
// Access descriptor for general purpose register loads/stores with exclusive semantics

func <anchor link="func_CreateAccDescExLDST_4">CreateAccDescExLDST</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, acqrel : boolean, tagchecked : boolean,
                         privileged : boolean) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    let Rt : integer = -1;
    return <a link="func_CreateAccDescExLDST_5" file="shared_pseudocode.xml">CreateAccDescExLDST</a>(memop, acqrel, tagchecked, privileged, Rt);
end;

// CreateAccDescExLDST()
// =====================

func <anchor link="func_CreateAccDescExLDST_5">CreateAccDescExLDST</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, acqrel : boolean, tagchecked : boolean,
                         privileged : boolean, Rt : integer) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    let ispair : boolean = FALSE;
    let Rt2 : integer = -1;
    return <a link="func_CreateAccDescExLDST_7" file="shared_pseudocode.xml">CreateAccDescExLDST</a>(memop, acqrel, tagchecked, privileged, ispair, Rt, Rt2);
end;

// CreateAccDescExLDST()
// =====================

func <anchor link="func_CreateAccDescExLDST_7">CreateAccDescExLDST</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, acqrel : boolean, tagchecked : boolean,
                         privileged : boolean, ispair : boolean,
                         Rt : integer, Rt2 : integer) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_GPR" file="shared_pseudocode.xml">AccessType_GPR</a>);

    accdesc.acqsc           = acqrel &amp;&amp; memop == <a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>;
    accdesc.relsc           = acqrel &amp;&amp; memop == <a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>;
    accdesc.exclusive       = TRUE;
    accdesc.el              = if !privileged then <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> else <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
    accdesc.read            = memop == <a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>;
    accdesc.write           = memop == <a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>;
    accdesc.ispair          = ispair;
    accdesc.pan             = TRUE;
    accdesc.tagchecked      = tagchecked;
    accdesc.Rt              = Rt;
    accdesc.Rt2             = Rt2;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescFPAtomicOp" mylink="shared.functions.memory.CreateAccDescFPAtomicOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescFPAtomicOp()
// =========================
// Access descriptor for FP atomic read-modify-write memory accesses

func <anchor link="func_CreateAccDescFPAtomicOp_4">CreateAccDescFPAtomicOp</anchor>(modop : <a link="type_MemAtomicOp" file="shared_pseudocode.xml">MemAtomicOp</a>, acquire : boolean, release : boolean,
                             tagchecked : boolean) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_FP" file="shared_pseudocode.xml">AccessType_FP</a>);

    accdesc.acqsc           = acquire;
    accdesc.relsc           = release;
    accdesc.atomicop        = TRUE;
    accdesc.modop           = modop;
    accdesc.read            = TRUE;
    accdesc.write           = TRUE;
    accdesc.pan             = TRUE;
    accdesc.streamingsve    = <a link="func_InStreamingMode_0" file="shared_pseudocode.xml">InStreamingMode</a>();
    if (accdesc.streamingsve &amp;&amp; ImpDefBool(
          &quot;No tag checking of SIMD&amp;FP loads and stores in Streaming SVE mode&quot;)) then
        accdesc.tagchecked  = FALSE;
    else
        accdesc.tagchecked  = tagchecked;
    end;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescGCS" mylink="shared.functions.memory.CreateAccDescGCS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescGCS()
// ==================
// Access descriptor for memory accesses to the Guarded Control Stack

func <anchor link="func_CreateAccDescGCS_2">CreateAccDescGCS</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, privileged : boolean) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_GCS" file="shared_pseudocode.xml">AccessType_GCS</a>);

    accdesc.el              = if !privileged then <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> else <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
    accdesc.read            = memop == <a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>;
    accdesc.write           = memop == <a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescGCSSS1" mylink="shared.functions.memory.CreateAccDescGCSSS1" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescGCSSS1()
// =====================
// Access descriptor for memory accesses to the Guarded Control Stack that switch stacks

func <anchor link="func_CreateAccDescGCSSS1_1">CreateAccDescGCSSS1</anchor>(privileged : boolean) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_GCS" file="shared_pseudocode.xml">AccessType_GCS</a>);

    accdesc.el              = if !privileged then <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> else <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
    accdesc.atomicop        = TRUE;
    accdesc.modop           = <a link="enum_MemAtomicOp_GCSSS1" file="shared_pseudocode.xml">MemAtomicOp_GCSSS1</a>;
    accdesc.read            = TRUE;
    accdesc.write           = TRUE;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescGPR" mylink="shared.functions.memory.CreateAccDescGPR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescGPR()
// ==================
// Access descriptor for general purpose register loads/stores
// without exclusive or ordering semantics

func <anchor link="func_CreateAccDescGPR_4">CreateAccDescGPR</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, nontemporal : boolean, privileged : boolean,
                      tagchecked : boolean) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    let Rt : integer = -1;
    return <a link="func_CreateAccDescGPR_5" file="shared_pseudocode.xml">CreateAccDescGPR</a>(memop, nontemporal, privileged, tagchecked, Rt);
end;

func <anchor link="func_CreateAccDescGPR_5">CreateAccDescGPR</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, nontemporal : boolean, privileged : boolean,
                      tagchecked : boolean, Rt : integer) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    let ispair : boolean = FALSE;
    let Rt2 : integer = -1;
    return <a link="func_CreateAccDescGPR_7" file="shared_pseudocode.xml">CreateAccDescGPR</a>(memop, nontemporal, privileged, tagchecked, ispair, Rt, Rt2);
end;

func <anchor link="func_CreateAccDescGPR_7">CreateAccDescGPR</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, nontemporal : boolean, privileged : boolean,
                      tagchecked : boolean, ispair : boolean,
                      Rt : integer, Rt2 : integer) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_GPR" file="shared_pseudocode.xml">AccessType_GPR</a>);

    accdesc.el              = if !privileged then <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> else <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
    accdesc.nontemporal     = nontemporal;
    accdesc.read            = memop == <a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>;
    accdesc.write           = memop == <a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>;
    accdesc.pan             = TRUE;
    accdesc.tagchecked      = tagchecked;
    accdesc.Rt              = Rt;
    accdesc.Rt2             = Rt2;
    accdesc.ispair          = ispair;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescGPTW" mylink="shared.functions.memory.CreateAccDescGPTW" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescGPTW()
// ===================
// Access descriptor for Granule Protection Table walks

func <anchor link="func_CreateAccDescGPTW_1">CreateAccDescGPTW</anchor>(accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_2" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_GPTW" file="shared_pseudocode.xml">AccessType_GPTW</a>, accdesc_in.mpam);

    accdesc.el              = accdesc_in.el;
    accdesc.ss              = accdesc_in.ss;
    accdesc.read            = TRUE;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescHACDBS" mylink="shared.functions.memory.CreateAccDescHACDBS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescHACDBS()
// =====================
// Access descriptor for memory accesses to the HACDBS structure.

func <anchor link="func_CreateAccDescHACDBS_0">CreateAccDescHACDBS</anchor>() =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_HACDBS" file="shared_pseudocode.xml">AccessType_HACDBS</a>);

    accdesc.read            = TRUE;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescHDBSS" mylink="shared.functions.memory.CreateAccDescHDBSS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescHDBSS()
// ====================
// Access descriptor for appending entries to the HDBSS

func <anchor link="func_CreateAccDescHDBSS_1">CreateAccDescHDBSS</anchor>(accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_2" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_HDBSS" file="shared_pseudocode.xml">AccessType_HDBSS</a>, accdesc_in.mpam);

    accdesc.el              = accdesc_in.el;
    accdesc.ss              = accdesc_in.ss;
    accdesc.write           = TRUE;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescIC" mylink="shared.functions.memory.CreateAccDescIC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescIC()
// =================
// Access descriptor for instruction cache operations

func <anchor link="func_CreateAccDescIC_1">CreateAccDescIC</anchor>(cache : <a link="type_CacheRecord" file="shared_pseudocode.xml">CacheRecord</a>) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>);

    accdesc.cacheop         = cache.cacheop;
    accdesc.cachetype       = cache.cachetype;
    accdesc.opscope         = cache.opscope;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescIFetch" mylink="shared.functions.memory.CreateAccDescIFetch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescIFetch()
// =====================
// Access descriptor for instruction fetches

func <anchor link="func_CreateAccDescIFetch_0">CreateAccDescIFetch</anchor>() =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a>);

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescLDAcqPC" mylink="shared.functions.memory.CreateAccDescLDAcqPC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescLDAcqPC()
// ======================
// Access descriptor for general purpose register loads with local ordering semantics

func <anchor link="func_CreateAccDescLDAcqPC_3">CreateAccDescLDAcqPC</anchor>(tagchecked : boolean, acquire : boolean, Rt : integer) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    let ispair : boolean = FALSE;
    let Rt2 : integer = -1;
    return <a link="func_CreateAccDescLDAcqPC_5" file="shared_pseudocode.xml">CreateAccDescLDAcqPC</a>(tagchecked, ispair, acquire, Rt, Rt2);
end;

func <anchor link="func_CreateAccDescLDAcqPC_5">CreateAccDescLDAcqPC</anchor>(tagchecked : boolean, ispair : boolean, acquire : boolean,
                          Rt : integer, Rt2 : integer) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_GPR" file="shared_pseudocode.xml">AccessType_GPR</a>);

    accdesc.acqpc           = acquire;
    accdesc.read            = TRUE;
    accdesc.pan             = TRUE;
    accdesc.tagchecked      = tagchecked;
    accdesc.ispair          = ispair;
    accdesc.Rt              = Rt;
    accdesc.Rt2             = Rt2;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescLDGSTG" mylink="shared.functions.memory.CreateAccDescLDGSTG" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescLDGSTG()
// =====================
// Access descriptor for tag memory loads/stores

func <anchor link="func_CreateAccDescLDGSTG_3">CreateAccDescLDGSTG</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, stzgm : boolean, Rt : integer) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    let ispair : boolean = FALSE;
    let Rt2 : integer = -1;
    return <a link="func_CreateAccDescLDGSTG_5" file="shared_pseudocode.xml">CreateAccDescLDGSTG</a>(memop, stzgm, ispair, Rt, Rt2);
end;

// CreateAccDescLDGSTG()
// =====================

func <anchor link="func_CreateAccDescLDGSTG_5">CreateAccDescLDGSTG</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, stzgm : boolean, ispair : boolean, Rt : integer,
                         Rt2 : integer) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_GPR" file="shared_pseudocode.xml">AccessType_GPR</a>);

    accdesc.read            = memop == <a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>;
    accdesc.write           = memop == <a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>;
    accdesc.pan             = TRUE;
    accdesc.tagaccess       = TRUE;
    accdesc.stzgm           = stzgm;
    accdesc.ispair          = ispair;
    accdesc.Rt              = Rt;
    accdesc.Rt2             = Rt2;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescLOR" mylink="shared.functions.memory.CreateAccDescLOR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescLOR()
// ==================
// Access descriptor for general purpose register loads/stores with limited ordering semantics

func <anchor link="func_CreateAccDescLOR_4">CreateAccDescLOR</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, tagchecked : boolean,
                      acqsc : boolean, Rt : integer) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_GPR" file="shared_pseudocode.xml">AccessType_GPR</a>);

    accdesc.acqsc           = acqsc;
    accdesc.relsc           = memop == <a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>;
    accdesc.limitedordered  = TRUE;
    accdesc.read            = memop == <a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>;
    accdesc.write           = memop == <a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>;
    accdesc.pan             = TRUE;
    accdesc.tagchecked      = tagchecked;
    accdesc.Rt              = Rt;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescLS64" mylink="shared.functions.memory.CreateAccDescLS64" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescLS64()
// ===================
// Access descriptor for accelerator-supporting memory accesses

func <anchor link="func_CreateAccDescLS64_3">CreateAccDescLS64</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, withstatus : boolean,
                       tagchecked : boolean) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_GPR" file="shared_pseudocode.xml">AccessType_GPR</a>);

    accdesc.read            = memop == <a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>;
    accdesc.write           = memop == <a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>;
    accdesc.pan             = TRUE;
    accdesc.ls64            = TRUE;
    accdesc.withstatus      = withstatus;
    accdesc.tagchecked      = tagchecked;
    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescMOPS" mylink="shared.functions.memory.CreateAccDescMOPS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescMOPS()
// ===================
// Access descriptor for data memory copy and set instructions

func <anchor link="func_CreateAccDescMOPS_3">CreateAccDescMOPS</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, privileged : boolean,
                       nontemporal : boolean) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_GPR" file="shared_pseudocode.xml">AccessType_GPR</a>);

    accdesc.el              = if !privileged then <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> else <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
    accdesc.nontemporal     = nontemporal;
    accdesc.read            = memop == <a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>;
    accdesc.write           = memop == <a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>;
    accdesc.pan             = TRUE;
    accdesc.mops            = TRUE;
    accdesc.tagchecked      = TRUE;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescNV2" mylink="shared.functions.memory.CreateAccDescNV2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescNV2()
// ==================
// Access descriptor nested virtualization memory indirection loads/stores

func <anchor link="func_CreateAccDescNV2_1">CreateAccDescNV2</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_NV2" file="shared_pseudocode.xml">AccessType_NV2</a>);

    accdesc.el              = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    accdesc.ss              = <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
    accdesc.read            = memop == <a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>;
    accdesc.write           = memop == <a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescRCW" mylink="shared.functions.memory.CreateAccDescRCW" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescRCW()
// ==================
// Access descriptor for atomic read-check-write memory accesses

func <anchor link="func_CreateAccDescRCW_7">CreateAccDescRCW</anchor>(modop : <a link="type_MemAtomicOp" file="shared_pseudocode.xml">MemAtomicOp</a>, soft : boolean, acquire : boolean,
                      release : boolean, tagchecked : boolean,
                      Rt : integer, Rs : integer) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    let Rt2 : integer = -1;
    let Rs2 : integer = -1;

    return <a link="func_CreateAccDescRCW_9" file="shared_pseudocode.xml">CreateAccDescRCW</a>(modop, soft, acquire, release, tagchecked, Rt, Rt2, Rs, Rs2);
end;

func <anchor link="func_CreateAccDescRCW_9">CreateAccDescRCW</anchor>(modop : <a link="type_MemAtomicOp" file="shared_pseudocode.xml">MemAtomicOp</a>, soft : boolean, acquire : boolean,
                      release : boolean, tagchecked : boolean, Rt : integer, Rt2 : integer,
                      Rs : integer, Rs2 : integer) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_GPR" file="shared_pseudocode.xml">AccessType_GPR</a>);

    accdesc.acqsc           = acquire;
    accdesc.relsc           = release;
    accdesc.rcw             = TRUE;
    accdesc.rcws            = soft;
    accdesc.atomicop        = TRUE;
    accdesc.modop           = modop;
    accdesc.read            = TRUE;
    accdesc.write           = TRUE;
    accdesc.pan             = TRUE;
    accdesc.tagchecked      = tagchecked;
    accdesc.Rt              = Rt;
    accdesc.Rt2             = Rt2;
    accdesc.Rs              = Rs;
    accdesc.Rs2             = Rs2;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescS1TTW" mylink="shared.functions.memory.CreateAccDescS1TTW" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescS1TTW()
// ====================
// Access descriptor for stage 1 translation table walks

func <anchor link="func_CreateAccDescS1TTW_3">CreateAccDescS1TTW</anchor>(toplevel : boolean,
                        varange : <a link="type_VARange" file="shared_pseudocode.xml">VARange</a>,
                        accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_2" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_TTW" file="shared_pseudocode.xml">AccessType_TTW</a>, accdesc_in.mpam);

    accdesc.el              = accdesc_in.el;
    accdesc.ss              = accdesc_in.ss;
    accdesc.read            = TRUE;
    accdesc.toplevel        = toplevel;
    accdesc.varange         = varange;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescS2TTW" mylink="shared.functions.memory.CreateAccDescS2TTW" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescS2TTW()
// ====================
// Access descriptor for stage 2 translation table walks

func <anchor link="func_CreateAccDescS2TTW_1">CreateAccDescS2TTW</anchor>(accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_2" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_TTW" file="shared_pseudocode.xml">AccessType_TTW</a>, accdesc_in.mpam);

    accdesc.el              = accdesc_in.el;
    accdesc.ss              = accdesc_in.ss;
    accdesc.read            = TRUE;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescSME" mylink="shared.functions.memory.CreateAccDescSME" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescSME()
// ==================
// Access descriptor for SME loads/stores

func <anchor link="func_CreateAccDescSME_4">CreateAccDescSME</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, nontemporal : boolean, contiguous : boolean,
                      tagchecked : boolean) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_SME" file="shared_pseudocode.xml">AccessType_SME</a>);

    accdesc.nontemporal     = nontemporal;
    accdesc.read            = memop == <a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>;
    accdesc.write           = memop == <a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>;
    accdesc.pan             = TRUE;
    accdesc.contiguous      = contiguous;
    accdesc.streamingsve    = TRUE;
    if ImpDefBool(&quot;No tag checking of SME LDR &amp; STR instructions&quot;) then
        accdesc.tagchecked  = FALSE;
    else
        accdesc.tagchecked  = tagchecked;
    end;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescSPE" mylink="shared.functions.memory.CreateAccDescSPE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescSPE()
// ==================
// Access descriptor for memory accesses by Statistical Profiling unit

func <anchor link="func_CreateAccDescSPE_2">CreateAccDescSPE</anchor>(owning_ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, owning_el : bits(2)) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    let mpaminfo : <a link="type_MPAMinfo" file="shared_pseudocode.xml">MPAMinfo</a> = <a link="func_GenMPAMAtEL_2" file="shared_pseudocode.xml">GenMPAMAtEL</a>(<a link="enum_AccessType_SPE" file="shared_pseudocode.xml">AccessType_SPE</a>, owning_el);
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_2" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_SPE" file="shared_pseudocode.xml">AccessType_SPE</a>, mpaminfo);

    accdesc.el              = owning_el;
    accdesc.ss              = owning_ss;
    accdesc.write           = TRUE;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescSTGMOPS" mylink="shared.functions.memory.CreateAccDescSTGMOPS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescSTGMOPS()
// ======================
// Access descriptor for tag memory set instructions

func <anchor link="func_CreateAccDescSTGMOPS_2">CreateAccDescSTGMOPS</anchor>(privileged : boolean, nontemporal : boolean) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_GPR" file="shared_pseudocode.xml">AccessType_GPR</a>);

    accdesc.el              = if !privileged then <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> else <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
    accdesc.nontemporal     = nontemporal;
    accdesc.write           = TRUE;
    accdesc.pan             = TRUE;
    accdesc.mops            = TRUE;
    accdesc.tagaccess       = TRUE;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescSVE" mylink="shared.functions.memory.CreateAccDescSVE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescSVE()
// ==================
// Access descriptor for general SVE loads/stores

func <anchor link="func_CreateAccDescSVE_4">CreateAccDescSVE</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, nontemporal : boolean, contiguous : boolean,
                      tagchecked : boolean) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    let predicated : boolean = FALSE;
    return <a link="func_CreateAccDescSVE_5" file="shared_pseudocode.xml">CreateAccDescSVE</a>(memop, nontemporal, contiguous, predicated, tagchecked);
end;

func <anchor link="func_CreateAccDescSVE_5">CreateAccDescSVE</anchor>(memop : <a link="type_MemOp" file="shared_pseudocode.xml">MemOp</a>, nontemporal : boolean, contiguous : boolean,
                      predicated : boolean, tagchecked : boolean) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_SVE" file="shared_pseudocode.xml">AccessType_SVE</a>);

    accdesc.nontemporal     = nontemporal;
    accdesc.read            = memop == <a link="enum_MemOp_LOAD" file="shared_pseudocode.xml">MemOp_LOAD</a>;
    accdesc.write           = memop == <a link="enum_MemOp_STORE" file="shared_pseudocode.xml">MemOp_STORE</a>;
    accdesc.pan             = TRUE;
    accdesc.contiguous      = contiguous;
    accdesc.streamingsve    = <a link="func_InStreamingMode_0" file="shared_pseudocode.xml">InStreamingMode</a>();
    if (accdesc.streamingsve &amp;&amp; ImpDefBool(
          &quot;No tag checking of SIMD&amp;FP loads and stores in Streaming SVE mode&quot;)) then
        accdesc.tagchecked  = FALSE;
    else
        accdesc.tagchecked  = tagchecked;
    end;
    accdesc.predicated      = predicated;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescSVEFF" mylink="shared.functions.memory.CreateAccDescSVEFF" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescSVEFF()
// ====================
// Access descriptor for first-fault SVE loads

func <anchor link="func_CreateAccDescSVEFF_2">CreateAccDescSVEFF</anchor>(contiguous : boolean, tagchecked : boolean) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_SVE" file="shared_pseudocode.xml">AccessType_SVE</a>);

    accdesc.read            = TRUE;
    accdesc.pan             = TRUE;
    accdesc.firstfault      = TRUE;
    accdesc.first           = TRUE;
    accdesc.contiguous      = contiguous;
    accdesc.streamingsve    = <a link="func_InStreamingMode_0" file="shared_pseudocode.xml">InStreamingMode</a>();
    if (accdesc.streamingsve &amp;&amp; ImpDefBool(
          &quot;No tag checking of SIMD&amp;FP loads and stores in Streaming SVE mode&quot;)) then
        accdesc.tagchecked  = FALSE;
    else
        accdesc.tagchecked  = tagchecked;
    end;
    accdesc.predicated      = TRUE;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescSVENF" mylink="shared.functions.memory.CreateAccDescSVENF" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescSVENF()
// ====================
// Access descriptor for non-fault SVE loads

func <anchor link="func_CreateAccDescSVENF_2">CreateAccDescSVENF</anchor>(contiguous : boolean, tagchecked : boolean) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_1" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_SVE" file="shared_pseudocode.xml">AccessType_SVE</a>);

    accdesc.read            = TRUE;
    accdesc.pan             = TRUE;
    accdesc.nonfault        = TRUE;
    accdesc.contiguous      = contiguous;
    accdesc.streamingsve    = <a link="func_InStreamingMode_0" file="shared_pseudocode.xml">InStreamingMode</a>();
    if (accdesc.streamingsve &amp;&amp; ImpDefBool(
          &quot;No tag checking of SIMD&amp;FP loads and stores in Streaming SVE mode&quot;)) then
        accdesc.tagchecked  = FALSE;
    else
        accdesc.tagchecked  = tagchecked;
    end;
    accdesc.predicated      = TRUE;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescTRBE" mylink="shared.functions.memory.CreateAccDescTRBE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescTRBE()
// ===================
// Access descriptor for memory accesses by Trace Buffer Unit

func <anchor link="func_CreateAccDescTRBE_2">CreateAccDescTRBE</anchor>(owning_ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, owning_el : bits(2)) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var mpam : <a link="type_MPAMinfo" file="shared_pseudocode.xml">MPAMinfo</a>;
    if <a link="func_SelfHostedTraceEnabled_0" file="shared_pseudocode.xml">SelfHostedTraceEnabled</a>() then
        mpam = <a link="func_GenMPAMAtEL_2" file="shared_pseudocode.xml">GenMPAMAtEL</a>(<a link="enum_AccessType_TRBE" file="shared_pseudocode.xml">AccessType_TRBE</a>, owning_el);
    else
        mpam = <a link="func_GenMPAMCurEL_1" file="shared_pseudocode.xml">GenMPAMCurEL</a>(<a link="enum_AccessType_TRBE" file="shared_pseudocode.xml">AccessType_TRBE</a>);
    end;
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_2" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_TRBE" file="shared_pseudocode.xml">AccessType_TRBE</a>, mpam);

    accdesc.el              = owning_el;
    accdesc.ss              = owning_ss;
    accdesc.write           = TRUE;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/CreateAccDescTTEUpdate" mylink="shared.functions.memory.CreateAccDescTTEUpdate" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAccDescTTEUpdate()
// ========================
// Access descriptor for translation table entry HW update

func <anchor link="func_CreateAccDescTTEUpdate_1">CreateAccDescTTEUpdate</anchor>(accdesc_in : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_NewAccDesc_2" file="shared_pseudocode.xml">NewAccDesc</a>(<a link="enum_AccessType_TTW" file="shared_pseudocode.xml">AccessType_TTW</a>, accdesc_in.mpam);

    accdesc.el              = accdesc_in.el;
    accdesc.ss              = accdesc_in.ss;
    accdesc.atomicop        = TRUE;
    accdesc.modop           = <a link="enum_MemAtomicOp_CAS" file="shared_pseudocode.xml">MemAtomicOp_CAS</a>;
    accdesc.read            = TRUE;
    accdesc.write           = TRUE;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/DataMemoryBarrier" mylink="shared.functions.memory.DataMemoryBarrier" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DataMemoryBarrier()
// ===================

impdef func DataMemoryBarrier(types : <a link="type_MBReqTypes" file="shared_pseudocode.xml">MBReqTypes</a>)
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/memory/DataSynchronizationBarrier" mylink="shared.functions.memory.DataSynchronizationBarrier" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DataSynchronizationBarrier()
// ============================

impdef func DataSynchronizationBarrier(scope : <a link="type_MBMaintenanceScope" file="shared_pseudocode.xml">MBMaintenanceScope</a>,
                                       types : <a link="type_MBReqTypes" file="shared_pseudocode.xml">MBReqTypes</a>,
                                       nXS : boolean)
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/memory/DeviceType" mylink="shared.functions.memory.DeviceType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DeviceType
// ==========
// Extended memory types for Device memory.

type <anchor link="type_DeviceType">DeviceType</anchor> of enumeration {<anchor link="enum_DeviceType_GRE">DeviceType_GRE</anchor>, <anchor link="enum_DeviceType_nGRE">DeviceType_nGRE</anchor>,
                                <anchor link="enum_DeviceType_nGnRE">DeviceType_nGnRE</anchor>, <anchor link="enum_DeviceType_nGnRnE">DeviceType_nGnRnE</anchor>};</pstext></ps>
    <ps name="shared/functions/memory/EffectiveMTX" mylink="shared.functions.memory.EffectiveMTX" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveMTX()
// ==============
// Returns the effective MTX in the AArch64 stage 1 translation regime for &quot;el&quot;.

func <anchor link="func_EffectiveMTX_3">EffectiveMTX</anchor>(address : bits(64), is_instr : boolean, el : bits(2)) =&gt; bit
begin
    var mtx : bit;
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(el);
    let regime : bits(2) = <a link="func_S1TranslationRegime_1" file="shared_pseudocode.xml">S1TranslationRegime</a>(el);
    assert(!<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(regime));

    if is_instr then
        mtx = '0';
    else
        case regime of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
                mtx = if address[55] == '1' then TCR_EL1().MTX1 else TCR_EL1().MTX0;
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
                if IsFeatureImplemented(FEAT_VHE) &amp;&amp; <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(el) then
                    mtx = if address[55] == '1' then TCR_EL2().MTX1 else TCR_EL2().MTX0;
                else
                    mtx = TCR_EL2().MTX;
                end;
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
                mtx = TCR_EL3().MTX;
        end;
    end;

    return mtx;
end;</pstext></ps>
    <ps name="shared/functions/memory/EffectiveTBI" mylink="shared.functions.memory.EffectiveTBI" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveTBI()
// ==============
// Returns the effective TBI in the AArch64 stage 1 translation regime for &quot;el&quot;.

func <anchor link="func_EffectiveTBI_3">EffectiveTBI</anchor>(address : bits(64), IsInstr : boolean, el : bits(2)) =&gt; bit
begin
    var tbi : bit;
    var tbid : bit;
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(el);
    let regime : bits(2) = <a link="func_S1TranslationRegime_1" file="shared_pseudocode.xml">S1TranslationRegime</a>(el);
    assert(!<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(regime));

    case regime of
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            tbi = if address[55] == '1' then TCR_EL1().TBI1 else TCR_EL1().TBI0;
            if IsFeatureImplemented(FEAT_PAuth) then
                tbid = if address[55] == '1' then TCR_EL1().TBID1 else TCR_EL1().TBID0;
            end;
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            if IsFeatureImplemented(FEAT_VHE) &amp;&amp; <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(el) then
                tbi = if address[55] == '1' then TCR_EL2().TBI1 else TCR_EL2().TBI0;
                if IsFeatureImplemented(FEAT_PAuth) then
                    tbid = if address[55] == '1' then TCR_EL2().TBID1 else TCR_EL2().TBID0;
                end;
            else
                tbi = TCR_EL2().TBI;
                if IsFeatureImplemented(FEAT_PAuth) then tbid = TCR_EL2().TBID; end;
            end;
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            tbi = TCR_EL3().TBI;
            if IsFeatureImplemented(FEAT_PAuth) then tbid = TCR_EL3().TBID; end;
    end;

    return (if (tbi == '1' &amp;&amp; (!IsFeatureImplemented(FEAT_PAuth) || tbid == '0' ||
            !IsInstr)) then '1' else '0');
end;</pstext></ps>
    <ps name="shared/functions/memory/EffectiveTCMA" mylink="shared.functions.memory.EffectiveTCMA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveTCMA()
// ===============
// Returns the effective TCMA of a virtual address in the stage 1 translation regime for &quot;el&quot;.

func <anchor link="func_EffectiveTCMA_2">EffectiveTCMA</anchor>(address : bits(64), el : bits(2)) =&gt; bit
begin
    var tcma : bit;
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(el);
    let regime : bits(2) = <a link="func_S1TranslationRegime_1" file="shared_pseudocode.xml">S1TranslationRegime</a>(el);
    assert(!<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(regime));

    case regime of
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            tcma = if address[55] == '1' then TCR_EL1().TCMA1 else TCR_EL1().TCMA0;
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            if IsFeatureImplemented(FEAT_VHE) &amp;&amp; <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(el) then
                tcma = if address[55] == '1' then TCR_EL2().TCMA1 else TCR_EL2().TCMA0;
            else
                tcma = TCR_EL2().TCMA;
            end;
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            tcma = TCR_EL3().TCMA;
    end;

    return tcma;
end;</pstext></ps>
    <ps name="shared/functions/memory/ErrorState" mylink="shared.functions.memory.ErrorState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ErrorState
// ==========
// The allowed error states that can be returned by memory and used by the PE.

type <anchor link="type_ErrorState">ErrorState</anchor> of enumeration {
                        <anchor link="enum_ErrorState_UC">ErrorState_UC</anchor>,            // Uncontainable
                        <anchor link="enum_ErrorState_UEU">ErrorState_UEU</anchor>,           // Unrecoverable state
                        <anchor link="enum_ErrorState_UEO">ErrorState_UEO</anchor>,           // Restartable state
                        <anchor link="enum_ErrorState_UER">ErrorState_UER</anchor>,           // Recoverable state
                        <anchor link="enum_ErrorState_CE">ErrorState_CE</anchor>};           // Corrected</pstext></ps>
    <ps name="shared/functions/memory/Fault" mylink="shared.functions.memory.Fault" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Fault
// =====
// Fault types.

type <anchor link="type_Fault">Fault</anchor> of enumeration {
                   <anchor link="enum_Fault_None">Fault_None</anchor>,
                   <anchor link="enum_Fault_AccessFlag">Fault_AccessFlag</anchor>,
                   <anchor link="enum_Fault_Alignment">Fault_Alignment</anchor>,
                   <anchor link="enum_Fault_Background">Fault_Background</anchor>,
                   <anchor link="enum_Fault_Domain">Fault_Domain</anchor>,
                   <anchor link="enum_Fault_Permission">Fault_Permission</anchor>,
                   <anchor link="enum_Fault_Translation">Fault_Translation</anchor>,
                   <anchor link="enum_Fault_AddressSize">Fault_AddressSize</anchor>,
                   <anchor link="enum_Fault_SyncExternal">Fault_SyncExternal</anchor>,
                   <anchor link="enum_Fault_SyncExternalOnWalk">Fault_SyncExternalOnWalk</anchor>,
                   <anchor link="enum_Fault_SyncParity">Fault_SyncParity</anchor>,
                   <anchor link="enum_Fault_SyncParityOnWalk">Fault_SyncParityOnWalk</anchor>,
                   <anchor link="enum_Fault_GPCFOnWalk">Fault_GPCFOnWalk</anchor>,
                   <anchor link="enum_Fault_GPCFOnOutput">Fault_GPCFOnOutput</anchor>,
                   <anchor link="enum_Fault_AsyncParity">Fault_AsyncParity</anchor>,
                   <anchor link="enum_Fault_AsyncExternal">Fault_AsyncExternal</anchor>,
                   <anchor link="enum_Fault_TagCheck">Fault_TagCheck</anchor>,
                   <anchor link="enum_Fault_Debug">Fault_Debug</anchor>,
                   <anchor link="enum_Fault_TLBConflict">Fault_TLBConflict</anchor>,
                   <anchor link="enum_Fault_BranchTarget">Fault_BranchTarget</anchor>,
                   <anchor link="enum_Fault_UnsupportedAtomicHWUpdate">Fault_UnsupportedAtomicHWUpdate</anchor>,
                   <anchor link="enum_Fault_Lockdown">Fault_Lockdown</anchor>,
                   <anchor link="enum_Fault_Exclusive">Fault_Exclusive</anchor>,
                   <anchor link="enum_Fault_ICacheMaint">Fault_ICacheMaint</anchor>};</pstext></ps>
    <ps name="shared/functions/memory/FaultRecord" mylink="shared.functions.memory.FaultRecord" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FaultRecord
// ===========
// Fields that relate only to Faults.

type <anchor link="type_FaultRecord">FaultRecord</anchor> of record {
    statuscode : <a link="type_Fault" file="shared_pseudocode.xml">Fault</a>,             // Fault Status
    accessdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,  // Details of the faulting access
    vaddress   : bits(64),          // Faulting virtual address
    ipaddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>,        // Intermediate physical address
    paddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>,         // Physical address
    gpcf : <a link="type_GPCFRecord" file="shared_pseudocode.xml">GPCFRecord</a>,              // Granule Protection Check Fault record
    gpcfs2walk : boolean,           // GPC for a stage 2 translation table walk
    s2fs1walk : boolean,            // Is on a Stage 1 translation table walk
    write : boolean,                // TRUE for a write, FALSE for a read
    s1tagnotdata : boolean,         // TRUE for a fault due to tag not accessible at stage 1.
    tagaccess : boolean,            // TRUE for a fault due to NoTagAccess permission.
    level : integer,                // For translation, access flag and Permission faults
    extflag : bit,                  // IMPLEMENTATION DEFINED syndrome for External aborts
    secondstage : boolean,          // Is a Stage 2 abort
    assuredonly : boolean,          // Stage 2 Permission fault due to AssuredOnly attribute
    toplevel    : boolean,          // Stage 2 Permission fault due to TopLevel
    overlay : boolean,              // Fault due to overlay permissions
    dirtybit : boolean,             // Fault due to dirty state
    domain : bits(4),               // Domain number, AArch32 only
    merrorstate : <a link="type_ErrorState" file="shared_pseudocode.xml">ErrorState</a>,       // Incoming error state from memory
    hdbssf : boolean,               // Fault caused by HDBSS
    watchptinfo : <a link="type_WatchpointInfo" file="shared_pseudocode.xml">WatchpointInfo</a>,   // Watchpoint related fields
    debugmoe : bits(4)              // Debug method of entry, from AArch32 only
};</pstext></ps>
    <ps name="shared/functions/memory/FullAddress" mylink="shared.functions.memory.FullAddress" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FullAddress
// ===========
// Physical or Intermediate Physical Address type.
// Although AArch32 only has access to 40 bits of physical or intermediate physical address space,
// the full address type has NUM_PABITS bits to allow interprocessing with AArch64.
// The maximum physical or intermediate physical address size is IMPLEMENTATION DEFINED,
// but never exceeds NUM_PABITS bits.

type <anchor link="type_FullAddress">FullAddress</anchor> of record {
    paspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>,
    address : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>)
};</pstext></ps>
    <ps name="shared/functions/memory/GPCF" mylink="shared.functions.memory.GPCF" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPCF
// ====
// Possible Granule Protection Check Fault reasons

type <anchor link="type_GPCF">GPCF</anchor> of enumeration {
    <anchor link="enum_GPCF_None">GPCF_None</anchor>,        // No fault
    <anchor link="enum_GPCF_AddressSize">GPCF_AddressSize</anchor>, // GPT address size fault
    <anchor link="enum_GPCF_Walk">GPCF_Walk</anchor>,        // GPT walk fault
    <anchor link="enum_GPCF_EABT">GPCF_EABT</anchor>,        // Synchronous External abort on GPT fetch
    <anchor link="enum_GPCF_Fail">GPCF_Fail</anchor>         // Granule protection fault
};</pstext></ps>
    <ps name="shared/functions/memory/GPCFRecord" mylink="shared.functions.memory.GPCFRecord" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPCFRecord
// ==========
// Full details of a Granule Protection Check Fault

type <anchor link="type_GPCFRecord">GPCFRecord</anchor> of record {
    gpf : <a link="type_GPCF" file="shared_pseudocode.xml">GPCF</a>,
    level : integer
};</pstext></ps>
    <ps name="shared/functions/memory/Hint_Prefetch" mylink="shared.functions.memory.Hint_Prefetch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Hint_Prefetch()
// ===============
// Signals the memory system that memory accesses of type HINT to or from the specified address are
// likely in the near future. The memory system may take some action to speed up the memory
// accesses when they do occur, such as pre-loading the specified address into one or more
// caches as indicated by the innermost cache level target (0=L1, 1=L2, etc) and non-temporal hint
// stream. Any or all prefetch hints may be treated as a NOP. A prefetch hint must not cause a
// synchronous abort due to Alignment or Translation faults and the like. Its only effect on
// software-visible state should be on caches and TLBs associated with address, which must be
// accessible by reads, writes or execution, as defined in the translation regime of the current
// Exception level. It is guaranteed not to access Device memory.
// A Prefetch_EXEC hint must not result in an access that could not be performed by a speculative
// instruction fetch, therefore if all associated MMUs are disabled, then it cannot access any
// memory location that cannot be accessed by instruction fetches.

impdef func Hint_Prefetch(address : bits(64),
                          hint : <a link="type_PrefetchHint" file="shared_pseudocode.xml">PrefetchHint</a>,
                          target : integer,
                          stream : boolean)
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/memory/Hint_RangePrefetch" mylink="shared.functions.memory.Hint_RangePrefetch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Hint_RangePrefetch()
// ====================
// Signals the memory system that data memory accesses from a specified range
// of addresses are likely to occur in the near future. The memory system can
// respond by taking actions that are expected to speed up the memory accesses
// when they do occur, such as preloading the locations within the specified
// address ranges into one or more caches.

impdef func Hint_RangePrefetch(address : bits(64), length : integer, stride : integer,
                               count : integer, reuse : integer, operation : bits(6))
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/memory/IsContiguousSVEAccess" mylink="shared.functions.memory.IsContiguousSVEAccess" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsContiguousSVEAccess()
// =======================
// Return TRUE if memory access is contiguous load/stores in an SVE mode.

func <anchor link="func_IsContiguousSVEAccess_1">IsContiguousSVEAccess</anchor>(accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; boolean
begin
    return accdesc.acctype == <a link="enum_AccessType_SVE" file="shared_pseudocode.xml">AccessType_SVE</a> &amp;&amp; accdesc.contiguous;
end;</pstext></ps>
    <ps name="shared/functions/memory/IsRelaxedWatchpointAccess" mylink="shared.functions.memory.IsRelaxedWatchpointAccess" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsRelaxedWatchpointAccess()
// ===========================
// Return TRUE if memory access is one of -
// - SIMD&amp;FP load/store instruction when the PE is in Streaming SVE mode
// - SVE contiguous vector load/store instruction.
// - SME load/store instruction

func <anchor link="func_IsRelaxedWatchpointAccess_1">IsRelaxedWatchpointAccess</anchor>(accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; boolean
begin
    return (<a link="func_IsContiguousSVEAccess_1" file="shared_pseudocode.xml">IsContiguousSVEAccess</a>(accdesc) ||
            <a link="func_IsSMEAccess_1" file="shared_pseudocode.xml">IsSMEAccess</a>(accdesc) ||
            (<a link="func_IsSIMDFPAccess_1" file="shared_pseudocode.xml">IsSIMDFPAccess</a>(accdesc) &amp;&amp; <a link="func_InStreamingMode_0" file="shared_pseudocode.xml">InStreamingMode</a>()));
end;</pstext></ps>
    <ps name="shared/functions/memory/IsSIMDFPAccess" mylink="shared.functions.memory.IsSIMDFPAccess" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsSIMDFPAccess()
// ================
// Return TRUE if access is SIMD&amp;FP.

func <anchor link="func_IsSIMDFPAccess_1">IsSIMDFPAccess</anchor>(accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; boolean
begin
    return accdesc.acctype == <a link="enum_AccessType_ASIMD" file="shared_pseudocode.xml">AccessType_ASIMD</a>;
end;</pstext></ps>
    <ps name="shared/functions/memory/IsSMEAccess" mylink="shared.functions.memory.IsSMEAccess" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsSMEAccess()
// =============
// Return TRUE if access is of SME load/stores.

func <anchor link="func_IsSMEAccess_1">IsSMEAccess</anchor>(accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; boolean
begin
    return accdesc.acctype == <a link="enum_AccessType_SME" file="shared_pseudocode.xml">AccessType_SME</a>;
end;</pstext></ps>
    <ps name="shared/functions/memory/IsWatchpointableAccess" mylink="shared.functions.memory.IsWatchpointableAccess" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsWatchpointableAccess()
// ========================
// Return TRUE if access should be checked for watchpoints.

func <anchor link="func_IsWatchpointableAccess_1">IsWatchpointableAccess</anchor>(accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; boolean
begin
    return (!(accdesc.acctype IN {<a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a>,
                                  <a link="enum_AccessType_TTW" file="shared_pseudocode.xml">AccessType_TTW</a>,
                                  <a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a>,
                                  <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a>,
                                  <a link="enum_AccessType_SPE" file="shared_pseudocode.xml">AccessType_SPE</a>,
                                  <a link="enum_AccessType_TRBE" file="shared_pseudocode.xml">AccessType_TRBE</a>,
                                  <a link="enum_AccessType_AT" file="shared_pseudocode.xml">AccessType_AT</a>}) ||
            (accdesc.acctype == <a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a> &amp;&amp;
             accdesc.cacheop == <a link="enum_CacheOp_Invalidate" file="shared_pseudocode.xml">CacheOp_Invalidate</a> &amp;&amp;
             (!<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() || (ImpDefBool(&quot;DCIMVAC generates watchpoint&quot;)))));
end;</pstext></ps>
    <ps name="shared/functions/memory/MBMaintenanceScope" mylink="shared.functions.memory.MBMaintenanceScope" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MBMaintenanceScope
// ==================
// Memory barrier scope.

type <anchor link="type_MBMaintenanceScope">MBMaintenanceScope</anchor> of enumeration {<anchor link="enum_MBMaintenanceScope_Nonshareable">MBMaintenanceScope_Nonshareable</anchor>,
                                        <anchor link="enum_MBMaintenanceScope_InnerShareable">MBMaintenanceScope_InnerShareable</anchor>,
                                        <anchor link="enum_MBMaintenanceScope_OuterShareable">MBMaintenanceScope_OuterShareable</anchor>,
                                        <anchor link="enum_MBMaintenanceScope_None">MBMaintenanceScope_None</anchor>};</pstext></ps>
    <ps name="shared/functions/memory/MBReqTypes" mylink="shared.functions.memory.MBReqTypes" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MBReqTypes
// ==========
// Memory barrier read/write.

type <anchor link="type_MBReqTypes">MBReqTypes</anchor> of enumeration {<anchor link="enum_MBReqTypes_Reads">MBReqTypes_Reads</anchor>, <anchor link="enum_MBReqTypes_Writes">MBReqTypes_Writes</anchor>, <anchor link="enum_MBReqTypes_All">MBReqTypes_All</anchor>};</pstext></ps>
    <ps name="shared/functions/memory/MemAtomicOp" mylink="shared.functions.memory.MemAtomicOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemAtomicOp
// ===========
// Atomic data processing instruction types.

type <anchor link="type_MemAtomicOp">MemAtomicOp</anchor> of enumeration {
    <anchor link="enum_MemAtomicOp_GCSSS1">MemAtomicOp_GCSSS1</anchor>,
    <anchor link="enum_MemAtomicOp_ADD">MemAtomicOp_ADD</anchor>,
    <anchor link="enum_MemAtomicOp_BIC">MemAtomicOp_BIC</anchor>,
    <anchor link="enum_MemAtomicOp_EOR">MemAtomicOp_EOR</anchor>,
    <anchor link="enum_MemAtomicOp_ORR">MemAtomicOp_ORR</anchor>,
    <anchor link="enum_MemAtomicOp_SMAX">MemAtomicOp_SMAX</anchor>,
    <anchor link="enum_MemAtomicOp_SMIN">MemAtomicOp_SMIN</anchor>,
    <anchor link="enum_MemAtomicOp_UMAX">MemAtomicOp_UMAX</anchor>,
    <anchor link="enum_MemAtomicOp_UMIN">MemAtomicOp_UMIN</anchor>,
    <anchor link="enum_MemAtomicOp_SWP">MemAtomicOp_SWP</anchor>,
    <anchor link="enum_MemAtomicOp_CAS">MemAtomicOp_CAS</anchor>,
    <anchor link="enum_MemAtomicOp_FPADD">MemAtomicOp_FPADD</anchor>,
    <anchor link="enum_MemAtomicOp_FPMAX">MemAtomicOp_FPMAX</anchor>,
    <anchor link="enum_MemAtomicOp_FPMIN">MemAtomicOp_FPMIN</anchor>,
    <anchor link="enum_MemAtomicOp_FPMAXNM">MemAtomicOp_FPMAXNM</anchor>,
    <anchor link="enum_MemAtomicOp_FPMINNM">MemAtomicOp_FPMINNM</anchor>,
    <anchor link="enum_MemAtomicOp_BFADD">MemAtomicOp_BFADD</anchor>,
    <anchor link="enum_MemAtomicOp_BFMAX">MemAtomicOp_BFMAX</anchor>,
    <anchor link="enum_MemAtomicOp_BFMIN">MemAtomicOp_BFMIN</anchor>,
    <anchor link="enum_MemAtomicOp_BFMAXNM">MemAtomicOp_BFMAXNM</anchor>,
    <anchor link="enum_MemAtomicOp_BFMINNM">MemAtomicOp_BFMINNM</anchor>
};</pstext></ps>
    <ps name="shared/functions/memory/MemAttrHints" mylink="shared.functions.memory.MemAttrHints" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemAttrHints
// ============
// Attributes and hints for Normal memory.

type <anchor link="type_MemAttrHints">MemAttrHints</anchor> of record {
    attrs : bits(2),  // See MemAttr_*, Cacheability attributes
    hints : bits(2),  // See MemHint_*, Allocation hints
    transient : boolean
};</pstext></ps>
    <ps name="shared/functions/memory/MemOp" mylink="shared.functions.memory.MemOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemOp
// =====
// Memory access instruction types.

type <anchor link="type_MemOp">MemOp</anchor> of enumeration {<anchor link="enum_MemOp_LOAD">MemOp_LOAD</anchor>, <anchor link="enum_MemOp_STORE">MemOp_STORE</anchor>, <anchor link="enum_MemOp_PREFETCH">MemOp_PREFETCH</anchor>};</pstext></ps>
    <ps name="shared/functions/memory/MemType" mylink="shared.functions.memory.MemType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemType
// =======
// Basic memory types.

type <anchor link="type_MemType">MemType</anchor> of enumeration {<anchor link="enum_MemType_Normal">MemType_Normal</anchor>, <anchor link="enum_MemType_Device">MemType_Device</anchor>};</pstext></ps>
    <ps name="shared/functions/memory/Memory" mylink="shared.functions.memory.Memory" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Memory Tag type
// ===============

type <anchor link="type_MemTagType">MemTagType</anchor> of enumeration {
    <anchor link="enum_MemTag_AllocationTagged">MemTag_AllocationTagged</anchor>,
    <anchor link="enum_MemTag_CanonicallyTagged">MemTag_CanonicallyTagged</anchor>,
    <anchor link="enum_MemTag_Untagged">MemTag_Untagged</anchor>
};</pstext></ps>
    <ps name="shared/functions/memory/MemoryAttributes" mylink="shared.functions.memory.MemoryAttributes" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MemoryAttributes
// ================
// Memory attributes descriptor

type <anchor link="type_MemoryAttributes">MemoryAttributes</anchor> of record {
    memtype : <a link="type_MemType" file="shared_pseudocode.xml">MemType</a>,
    device : <a link="type_DeviceType" file="shared_pseudocode.xml">DeviceType</a>,         // For Device memory types
    inner : <a link="type_MemAttrHints" file="shared_pseudocode.xml">MemAttrHints</a>,        // Inner hints and attributes
    outer : <a link="type_MemAttrHints" file="shared_pseudocode.xml">MemAttrHints</a>,        // Outer hints and attributes
    shareability : <a link="type_Shareability" file="shared_pseudocode.xml">Shareability</a>, // Shareability attribute
    tags : <a link="type_MemTagType" file="shared_pseudocode.xml">MemTagType</a>,           // MTE tag type for this memory.
    notagaccess : boolean,       // Allocation Tag access permission
    xs : bit                     // XS attribute
};</pstext></ps>
    <ps name="shared/functions/memory/NewAccDesc" mylink="shared.functions.memory.NewAccDesc" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// NewAccDesc()
// ============
// Create a new AccessDescriptor with initialized fields

func <anchor link="func_NewAccDesc_1">NewAccDesc</anchor>(acctype : <a link="type_AccessType" file="shared_pseudocode.xml">AccessType</a>) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    let mpaminfo : <a link="type_MPAMinfo" file="shared_pseudocode.xml">MPAMinfo</a> = <a link="func_GenMPAMCurEL_1" file="shared_pseudocode.xml">GenMPAMCurEL</a>(acctype);
    return <a link="func_NewAccDesc_2" file="shared_pseudocode.xml">NewAccDesc</a>(acctype, mpaminfo);
end;

func <anchor link="func_NewAccDesc_2">NewAccDesc</anchor>(acctype : <a link="type_AccessType" file="shared_pseudocode.xml">AccessType</a>, mpam : <a link="type_MPAMinfo" file="shared_pseudocode.xml">MPAMinfo</a>) =&gt; <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
begin
    var accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>;

    accdesc.acctype             = acctype;
    accdesc.el                  = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
    accdesc.ss                  = <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    accdesc.acqsc               = FALSE;
    accdesc.acqpc               = FALSE;
    accdesc.relsc               = FALSE;
    accdesc.limitedordered      = FALSE;
    accdesc.exclusive           = FALSE;
    accdesc.rcw                 = FALSE;
    accdesc.rcws                = FALSE;
    accdesc.atomicop            = FALSE;
    accdesc.nontemporal         = FALSE;
    accdesc.read                = FALSE;
    accdesc.write               = FALSE;
    accdesc.pan                 = FALSE;
    accdesc.nonfault            = FALSE;
    accdesc.firstfault          = FALSE;
    accdesc.first               = FALSE;
    accdesc.contiguous          = FALSE;
    accdesc.predicated          = FALSE;
    accdesc.streamingsve        = FALSE;
    accdesc.ls64                = FALSE;
    accdesc.withstatus          = FALSE;
    accdesc.mops                = FALSE;
    accdesc.a32lsmd             = FALSE;
    accdesc.tagchecked          = FALSE;
    accdesc.tagaccess           = FALSE;
    accdesc.stzgm               = FALSE;
    accdesc.mpam                = mpam;
    accdesc.Rs                  = -1;
    accdesc.Rs2                 = -1;
    accdesc.Rt                  = -1;
    accdesc.Rt2                 = -1;
    accdesc.ispair              = FALSE;
    accdesc.highestaddressfirst = FALSE;
    accdesc.lowestaddress       = TRUE;

    return accdesc;
end;</pstext></ps>
    <ps name="shared/functions/memory/PASpace" mylink="shared.functions.memory.PASpace" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PASpace
// =======
// Physical address spaces

type <anchor link="type_PASpace">PASpace</anchor> of enumeration {
    <anchor link="enum_PAS_Root">PAS_Root</anchor>,
    <anchor link="enum_PAS_SystemAgent">PAS_SystemAgent</anchor>,
    <anchor link="enum_PAS_NonSecureProtected">PAS_NonSecureProtected</anchor>,
    <anchor link="enum_PAS_NA6">PAS_NA6</anchor>,                // Reserved
    <anchor link="enum_PAS_NA7">PAS_NA7</anchor>,                // Reserved
    <anchor link="enum_PAS_Realm">PAS_Realm</anchor>,
    <anchor link="enum_PAS_Secure">PAS_Secure</anchor>,
    <anchor link="enum_PAS_NonSecure">PAS_NonSecure</anchor>
};</pstext></ps>
    <ps name="shared/functions/memory/Permissions" mylink="shared.functions.memory.Permissions" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Permissions
// ===========
// Access Control bits in translation table descriptors

type <anchor link="type_Permissions">Permissions</anchor> of record {
    ap_table  : bits(2),  // Stage 1 hierarchical access permissions
    xn_table  : bit,      // Stage 1 hierarchical execute-never for single EL regimes
    pxn_table : bit,      // Stage 1 hierarchical privileged execute-never
    uxn_table : bit,      // Stage 1 hierarchical unprivileged execute-never
    ap  : bits(3),        // Stage 1 access permissions
    xn  : bit,            // Stage 1 execute-never for single EL regimes
    uxn : bit,            // Stage 1 unprivileged execute-never
    pxn : bit,            // Stage 1 privileged execute-never
    ppi : bits(4),        // Stage 1 privileged indirect permissions
    upi : bits(4),        // Stage 1 unprivileged indirect permissions
    ndirty : bit,         // Stage 1 dirty state for indirect permissions scheme
    s2pi    : bits(4),    // Stage 2 indirect permissions
    s2dirty : bit,        // Stage 2 dirty state
    po_index : bits(4),   // Stage 1 overlay permissions index
    s2po_index : bits(4), // Stage 2 overlay permissions index
    s2ap : bits(2),       // Stage 2 access permissions
    s2tag_na : bit,       // Stage 2 tag access
    s2xnx : bit,          // Stage 2 extended execute-never
    dbm : bit,            // Dirty bit management
    s2xn : bit            // Stage 2 execute-never
};</pstext></ps>
    <ps name="shared/functions/memory/PhysMemRead" mylink="shared.functions.memory.PhysMemRead" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PhysMemRead()
// =============
// Returns the value read from memory, and a status.
// Returned value is UNKNOWN if an External abort occurred while reading the
// memory.
// Otherwise the PhysMemRetStatus statuscode is Fault_None.

impdef func <anchor link="func_PhysMemRead_3">PhysMemRead</anchor>{size : integer{8, 16, 32, 64, 128, 256, 512}}(
                                                    desc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                                                    accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>
                                            ) =&gt; (<a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>, bits(size))
begin
    return (ARBITRARY : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>, ARBITRARY : bits(size));
end;</pstext></ps>
    <ps name="shared/functions/memory/PhysMemRetStatus" mylink="shared.functions.memory.PhysMemRetStatus" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PhysMemRetStatus
// ================
// Fields that relate only to return values of PhysMem functions.

type <anchor link="type_PhysMemRetStatus">PhysMemRetStatus</anchor> of record {
    statuscode : <a link="type_Fault" file="shared_pseudocode.xml">Fault</a>,       // Fault Status
    extflag : bit,            // IMPLEMENTATION DEFINED syndrome for External aborts
    merrorstate : <a link="type_ErrorState" file="shared_pseudocode.xml">ErrorState</a>, // Optional error state returned on a physical memory access
    store64bstatus : bits(64) // Status of 64B store
};</pstext></ps>
    <ps name="shared/functions/memory/PhysMemWrite" mylink="shared.functions.memory.PhysMemWrite" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PhysMemWrite()
// ==============
// Writes the value to memory, and returns the status of the write.
// If there is an External abort on the write, the PhysMemRetStatus indicates this.
// Otherwise the statuscode of PhysMemRetStatus is Fault_None.

impdef func <anchor link="func_PhysMemWrite_4">PhysMemWrite</anchor>{size : integer{8, 16, 32, 64, 128, 256, 512}}(desc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                                                                       accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                                                value : bits(size)) =&gt; <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>
begin
    return ARBITRARY : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
end;</pstext></ps>
    <ps name="shared/functions/memory/PrefetchHint" mylink="shared.functions.memory.PrefetchHint" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PrefetchHint
// ============
// Prefetch hint types.

type <anchor link="type_PrefetchHint">PrefetchHint</anchor> of enumeration {
    <anchor link="enum_Prefetch_READ">Prefetch_READ</anchor>,
    <anchor link="enum_Prefetch_WRITE">Prefetch_WRITE</anchor>,
    <anchor link="enum_Prefetch_IR">Prefetch_IR</anchor>,
    <anchor link="enum_Prefetch_EXEC">Prefetch_EXEC</anchor>
};</pstext></ps>
    <ps name="shared/functions/memory/S1AccessControls" mylink="shared.functions.memory.S1AccessControls" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// S1AccessControls
// ================
// Effective access controls defined by stage 1 translation

type <anchor link="type_S1AccessControls">S1AccessControls</anchor> of record {
    r : bit,                 // Stage 1 base read permission
    w : bit,                 // Stage 1 base write permission
    x : bit,                 // Stage 1 base execute permission
    gcs : bit,               // Stage 1 GCS permission
    overlay : boolean,       // Stage 1 FEAT_S1POE overlay applies
    or : bit,                // Stage 1 FEAT_S1POE overlay read permission
    ow : bit,                // Stage 1 FEAT_S1POE overlay write permission
    ox : bit,                // Stage 1 FEAT_S1POE overlay execute permission
    wxn : bit                // Stage 1 write permission implies execute-never

};</pstext></ps>
    <ps name="shared/functions/memory/S2AccessControls" mylink="shared.functions.memory.S2AccessControls" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// S2AccessControls
// ================
// Effective access controls defined by stage 2 translation

type <anchor link="type_S2AccessControls">S2AccessControls</anchor> of record {
    r : bit,                 // Stage 2 read permission.
    w : bit,                 // Stage 2 write permission.
    x : bit,                 // Stage 2 execute permission.
    r_rcw : bit,             // Stage 2 Read perms for RCW instruction.
    w_rcw : bit,             // Stage 2 Write perms for RCW instruction.
    r_mmu : bit,             // Stage 2 Read perms for TTW data.
    w_mmu : bit,             // Stage 2 Write perms for TTW data.
    toplevel0 : bit,         // IPA as top level table for TTBR0_EL1.
    toplevel1 : bit,         // IPA as top level table for TTBR1_EL1.
    overlay : boolean,       // Overlay enable
    or : bit,                // Stage 2 overlay read permission.
    ow : bit,                // Stage 2 overlay write permission.
    ox : bit,                // Stage 2 overlay execute permission.
    or_rcw : bit,            // Stage 2 overlay Read perms for RCW instruction.
    ow_rcw : bit,            // Stage 2 overlay Write perms for RCW instruction.
    or_mmu : bit,            // Stage 2 overlay Read perms for TTW data.
    ow_mmu : bit,            // Stage 2 overlay Write perms for TTW data.
};</pstext></ps>
    <ps name="shared/functions/memory/Shareability" mylink="shared.functions.memory.Shareability" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Shareability
// ============

type <anchor link="type_Shareability">Shareability</anchor> of enumeration {
    <anchor link="enum_Shareability_NSH">Shareability_NSH</anchor>,
    <anchor link="enum_Shareability_ISH">Shareability_ISH</anchor>,
    <anchor link="enum_Shareability_OSH">Shareability_OSH</anchor>
};</pstext></ps>
    <ps name="shared/functions/memory/SpeculativeStoreBypassBarrierToPA" mylink="shared.functions.memory.SpeculativeStoreBypassBarrierToPA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SpeculativeStoreBypassBarrierToPA()
// ===================================

impdef func SpeculativeStoreBypassBarrierToPA()
begin
    // Since there is no speculation in ASL model, this is a NOP.
    return;
end;</pstext></ps>
    <ps name="shared/functions/memory/SpeculativeStoreBypassBarrierToVA" mylink="shared.functions.memory.SpeculativeStoreBypassBarrierToVA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SpeculativeStoreBypassBarrierToVA()
// ===================================

impdef func SpeculativeStoreBypassBarrierToVA()
begin
    // Since there is no speculation in ASL model, this is a NOP.
    return;
end;</pstext></ps>
    <ps name="shared/functions/memory/Tag" mylink="shared.functions.memory.Tag" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Tag Granule size
// ================

constant <anchor link="global_LOG2_TAG_GRANULE">LOG2_TAG_GRANULE</anchor> : integer{} = 4;
constant <anchor link="global_TAG_GRANULE">TAG_GRANULE</anchor> : integer{} = 1 &lt;&lt; <a link="global_LOG2_TAG_GRANULE" file="shared_pseudocode.xml">LOG2_TAG_GRANULE</a>;</pstext></ps>
    <ps name="shared/functions/memory/VARange" mylink="shared.functions.memory.VARange" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// VARange
// =======
// Virtual address ranges

type <anchor link="type_VARange">VARange</anchor> of enumeration {
    <anchor link="enum_VARange_LOWER">VARange_LOWER</anchor>,
    <anchor link="enum_VARange_UPPER">VARange_UPPER</anchor>
};</pstext></ps>
    <ps name="shared/functions/mpam/AltPARTIDSpace" mylink="shared.functions.mpam.AltPARTIDSpace" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AltPARTIDSpace()
// ================
// From the Security state, EL and ALTSP configuration, determine
// whether to primary space or the alt space is selected and which
// PARTID space is the alternative space. Return that alternative
// PARTID space if selected or the primary space if not.

func <anchor link="func_AltPARTIDSpace_3">AltPARTIDSpace</anchor>(el : bits(2), security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>,
                    primaryPIDSpace : <a link="type_PARTIDSpaceType" file="shared_pseudocode.xml">PARTIDSpaceType</a>) =&gt; <a link="type_PARTIDSpaceType" file="shared_pseudocode.xml">PARTIDSpaceType</a>
begin
    case security of
        when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt;
            assert el != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
            return primaryPIDSpace;
        when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;
            assert el != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
            if primaryPIDSpace == <a link="enum_PIDSpace_NonSecure" file="shared_pseudocode.xml">PIDSpace_NonSecure</a> then
                return primaryPIDSpace;
            end;
            return <a link="func_AltPIDSecure_2" file="shared_pseudocode.xml">AltPIDSecure</a>(el, primaryPIDSpace);
        when <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a> =&gt;
            assert el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
            if MPAM3_EL3().ALTSP_EL3 == '1' then
                if MPAM3_EL3().RT_ALTSP_NS == '1' then
                    return <a link="enum_PIDSpace_NonSecure" file="shared_pseudocode.xml">PIDSpace_NonSecure</a>;
                else
                    return <a link="enum_PIDSpace_Secure" file="shared_pseudocode.xml">PIDSpace_Secure</a>;
                end;
            else
                return primaryPIDSpace;
            end;
        when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;
            assert el != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
            return <a link="func_AltPIDRealm_2" file="shared_pseudocode.xml">AltPIDRealm</a>(el, primaryPIDSpace);
        otherwise =&gt;
            unreachable;
    end;
end;</pstext></ps>
    <ps name="shared/functions/mpam/AltPIDRealm" mylink="shared.functions.mpam.AltPIDRealm" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AltPIDRealm()
// =============
// Compute PARTID space as either the primary PARTID space or
// alternative PARTID space in the Realm Security state.
// Helper for AltPARTIDSpace.

func <anchor link="func_AltPIDRealm_2">AltPIDRealm</anchor>(el : bits(2), primaryPIDSpace : <a link="type_PARTIDSpaceType" file="shared_pseudocode.xml">PARTIDSpaceType</a>) =&gt; <a link="type_PARTIDSpaceType" file="shared_pseudocode.xml">PARTIDSpaceType</a>
begin
    var PIDSpace : <a link="type_PARTIDSpaceType" file="shared_pseudocode.xml">PARTIDSpaceType</a> = primaryPIDSpace;
    case el of
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
                if !<a link="func_UsePrimarySpaceEL2_0" file="shared_pseudocode.xml">UsePrimarySpaceEL2</a>() then
                    PIDSpace = <a link="enum_PIDSpace_NonSecure" file="shared_pseudocode.xml">PIDSpace_NonSecure</a>;
                end;
            elsif !<a link="func_UsePrimarySpaceEL10_0" file="shared_pseudocode.xml">UsePrimarySpaceEL10</a>() then
                PIDSpace = <a link="enum_PIDSpace_NonSecure" file="shared_pseudocode.xml">PIDSpace_NonSecure</a>;
            end;
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            if !<a link="func_UsePrimarySpaceEL10_0" file="shared_pseudocode.xml">UsePrimarySpaceEL10</a>() then
                PIDSpace = <a link="enum_PIDSpace_NonSecure" file="shared_pseudocode.xml">PIDSpace_NonSecure</a>;
            end;
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            if !<a link="func_UsePrimarySpaceEL2_0" file="shared_pseudocode.xml">UsePrimarySpaceEL2</a>() then
                PIDSpace = <a link="enum_PIDSpace_NonSecure" file="shared_pseudocode.xml">PIDSpace_NonSecure</a>;
            end;
        otherwise =&gt;
            unreachable;
    end;
    return PIDSpace;
end;</pstext></ps>
    <ps name="shared/functions/mpam/AltPIDSecure" mylink="shared.functions.mpam.AltPIDSecure" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AltPIDSecure()
// ==============
// Compute PARTID space as either the primary PARTID space or
// alternative PARTID space in the Secure Security state.
// Helper for AltPARTIDSpace.

func <anchor link="func_AltPIDSecure_2">AltPIDSecure</anchor>(el : bits(2), primaryPIDSpace : <a link="type_PARTIDSpaceType" file="shared_pseudocode.xml">PARTIDSpaceType</a>) =&gt; <a link="type_PARTIDSpaceType" file="shared_pseudocode.xml">PARTIDSpaceType</a>
begin
    var PIDSpace : <a link="type_PARTIDSpaceType" file="shared_pseudocode.xml">PARTIDSpaceType</a> = primaryPIDSpace;
    case el of
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
                if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
                    if !<a link="func_UsePrimarySpaceEL2_0" file="shared_pseudocode.xml">UsePrimarySpaceEL2</a>() then
                        PIDSpace = <a link="enum_PIDSpace_NonSecure" file="shared_pseudocode.xml">PIDSpace_NonSecure</a>;
                    end;
                elsif !<a link="func_UsePrimarySpaceEL10_0" file="shared_pseudocode.xml">UsePrimarySpaceEL10</a>() then
                    PIDSpace = <a link="enum_PIDSpace_NonSecure" file="shared_pseudocode.xml">PIDSpace_NonSecure</a>;
                end;
            elsif MPAM3_EL3().ALTSP_HEN == '0' &amp;&amp; MPAM3_EL3().ALTSP_HFC == '1' then
                PIDSpace = <a link="enum_PIDSpace_NonSecure" file="shared_pseudocode.xml">PIDSpace_NonSecure</a>;
            end;
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
                if !<a link="func_UsePrimarySpaceEL10_0" file="shared_pseudocode.xml">UsePrimarySpaceEL10</a>() then
                    PIDSpace = <a link="enum_PIDSpace_NonSecure" file="shared_pseudocode.xml">PIDSpace_NonSecure</a>;
                end;
            elsif MPAM3_EL3().ALTSP_HEN == '0' &amp;&amp; MPAM3_EL3().ALTSP_HFC == '1' then
                PIDSpace = <a link="enum_PIDSpace_NonSecure" file="shared_pseudocode.xml">PIDSpace_NonSecure</a>;
            end;
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            if !<a link="func_UsePrimarySpaceEL2_0" file="shared_pseudocode.xml">UsePrimarySpaceEL2</a>() then
                PIDSpace = <a link="enum_PIDSpace_NonSecure" file="shared_pseudocode.xml">PIDSpace_NonSecure</a>;
            end;
        otherwise =&gt;
            unreachable;
    end;
    return PIDSpace;
end;</pstext></ps>
    <ps name="shared/functions/mpam/DefaultMPAMInfo" mylink="shared.functions.mpam.DefaultMPAMInfo" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DefaultMPAMInfo()
// =================
// Returns default MPAM info.  The partidspace argument sets
// the PARTID space of the default MPAM information returned.

func <anchor link="func_DefaultMPAMInfo_1">DefaultMPAMInfo</anchor>(partidspace : <a link="type_PARTIDSpaceType" file="shared_pseudocode.xml">PARTIDSpaceType</a>) =&gt; <a link="type_MPAMinfo" file="shared_pseudocode.xml">MPAMinfo</a>
begin
    var defaultinfo : <a link="type_MPAMinfo" file="shared_pseudocode.xml">MPAMinfo</a>;
    defaultinfo.mpam_sp = partidspace;
    defaultinfo.partid  = <a link="global_DEFAULT_PARTID" file="shared_pseudocode.xml">DEFAULT_PARTID</a>;
    defaultinfo.pmg     = <a link="global_DEFAULT_PMG" file="shared_pseudocode.xml">DEFAULT_PMG</a>;
    return defaultinfo;
end;</pstext></ps>
    <ps name="shared/functions/mpam/GenMPAM" mylink="shared.functions.mpam.GenMPAM" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GenMPAM()
// =========
// Returns MPAMinfo for Exception level el.
// If mpamdata.sm is TRUE returns MPAM information using MPAMSM_EL1.
// If mpamdata.trb is TRUE returns MPAM information using TRBMPAM_EL1.
// Otherwise returns MPAM information using MPAMn_ELx.

func <anchor link="func_GenMPAM_3">GenMPAM</anchor>(el_in : bits(2), mpamdata : <a link="type_MPAMdata" file="shared_pseudocode.xml">MPAMdata</a>, pspace : <a link="type_PARTIDSpaceType" file="shared_pseudocode.xml">PARTIDSpaceType</a>) =&gt; <a link="type_MPAMinfo" file="shared_pseudocode.xml">MPAMinfo</a>
begin
    var returninfo : <a link="type_MPAMinfo" file="shared_pseudocode.xml">MPAMinfo</a>;
    var partidel : <a link="type_PARTIDType" file="shared_pseudocode.xml">PARTIDType</a>;
    var perr : boolean;
    var el : bits(2) = el_in;

    // Check if the guest OS application is locked by the EL2 hypervisor to
    // only use the EL1 virtual machine's PARTIDs.
    if (el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; MPAMHCR_EL2().GSTAPP_PLK == '1' &amp;&amp;
          HCR_EL2().TGE == '0') then
        el = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    end;

    (partidel, perr)      = <a link="func_GenPARTID_3" file="shared_pseudocode.xml">GenPARTID</a>(el, mpamdata, pspace);
    let groupel : <a link="type_PMGType" file="shared_pseudocode.xml">PMGType</a> = <a link="func_GenPMG_4" file="shared_pseudocode.xml">GenPMG</a>(el, mpamdata, perr, pspace);

    returninfo.mpam_sp = pspace;
    returninfo.partid  = partidel;
    returninfo.pmg     = groupel;
    return returninfo;
end;</pstext></ps>
    <ps name="shared/functions/mpam/GenMPAMAtEL" mylink="shared.functions.mpam.GenMPAMAtEL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GenMPAMAtEL()
// =============
// Returns MPAMinfo for the specified EL.
// May be called if MPAM is not implemented (but in an version that supports
// MPAM), MPAM is disabled, or in AArch32_  In AArch32, convert the mode to
// EL if can and use that to drive MPAM information generation.  If mode
// cannot be converted, MPAM is not implemented, or MPAM is disabled return
// default MPAM information for the current security state.

func <anchor link="func_GenMPAMAtEL_2">GenMPAMAtEL</anchor>(acctype : <a link="type_AccessType" file="shared_pseudocode.xml">AccessType</a>, el : bits(2)) =&gt; <a link="type_MPAMinfo" file="shared_pseudocode.xml">MPAMinfo</a>
begin
    var mpamEL : bits(2);
    var pspace : <a link="type_PARTIDSpaceType" file="shared_pseudocode.xml">PARTIDSpaceType</a>;
    let security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(el);
    var mpamdata : <a link="type_MPAMdata" file="shared_pseudocode.xml">MPAMdata</a>      = <a link="func_GenNewMPAMData_0" file="shared_pseudocode.xml">GenNewMPAMData</a>();
    pspace = <a link="func_PARTIDSpaceFromSS_1" file="shared_pseudocode.xml">PARTIDSpaceFromSS</a>(security);
    if pspace == <a link="enum_PIDSpace_NonSecure" file="shared_pseudocode.xml">PIDSpace_NonSecure</a> &amp;&amp; !<a link="func_MPAMIsEnabled_0" file="shared_pseudocode.xml">MPAMIsEnabled</a>() then
        return <a link="func_DefaultMPAMInfo_1" file="shared_pseudocode.xml">DefaultMPAMInfo</a>(pspace);
    end;
    mpamEL = if acctype == <a link="enum_AccessType_NV2" file="shared_pseudocode.xml">AccessType_NV2</a> then <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> else el;
    case acctype of
        when <a link="enum_AccessType_IFETCH" file="shared_pseudocode.xml">AccessType_IFETCH</a>, <a link="enum_AccessType_IC" file="shared_pseudocode.xml">AccessType_IC</a> =&gt;
            mpamdata.in_d = TRUE;
        when <a link="enum_AccessType_SME" file="shared_pseudocode.xml">AccessType_SME</a> =&gt;
            mpamdata.sm = (ImpDefBool(&quot;Shared SMCU&quot;) ||
                           ImpDefBool(&quot;MPAMSM_EL1 label precedence&quot;));
        when <a link="enum_AccessType_FP" file="shared_pseudocode.xml">AccessType_FP</a>, <a link="enum_AccessType_ASIMD" file="shared_pseudocode.xml">AccessType_ASIMD</a>, <a link="enum_AccessType_SVE" file="shared_pseudocode.xml">AccessType_SVE</a> =&gt;
            mpamdata.sm = (IsFeatureImplemented(FEAT_SME) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SM == '1' &amp;&amp;
                           (ImpDefBool(&quot;Shared SMCU&quot;) ||
                            ImpDefBool(&quot;MPAMSM_EL1 label precedence&quot;)));
        when <a link="enum_AccessType_TRBE" file="shared_pseudocode.xml">AccessType_TRBE</a> =&gt;
            if !<a link="func_SelfHostedTraceEnabled_0" file="shared_pseudocode.xml">SelfHostedTraceEnabled</a>() then
                if !IsFeatureImplemented(FEAT_TRBE_MPAM) || TRBMPAM_EL1().EN == '0' then
                    return <a link="func_DefaultMPAMInfo_1" file="shared_pseudocode.xml">DefaultMPAMInfo</a>(pspace);
                else
                    mpamdata.trb = TRUE;
                end;
            end;
            if mpamdata.trb then
                var ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>;
                case TRBMPAM_EL1().MPAM_SP of
                    when '00' =&gt; ss = <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>;
                    when '01' =&gt; ss = <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a>;
                    when '10' =&gt; ss = <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a>;
                    when '11' =&gt; ss = <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a>;
                end;
                pspace = <a link="func_PARTIDSpaceFromSS_1" file="shared_pseudocode.xml">PARTIDSpaceFromSS</a>(ss);
            end;
        otherwise =&gt;
            // Other access types are DATA accesses
            mpamdata.in_d = FALSE;
    end;
    if IsFeatureImplemented(FEAT_RME) &amp;&amp; MPAMIDR_EL1().HAS_ALTSP == '1' then
        // Substitute alternative PARTID space if selected
        pspace = <a link="func_AltPARTIDSpace_3" file="shared_pseudocode.xml">AltPARTIDSpace</a>(mpamEL, security, pspace);
    end;
    if IsFeatureImplemented(FEAT_MPAMv0p1) &amp;&amp; MPAMIDR_EL1().HAS_FORCE_NS == '1' then
        if MPAM3_EL3().FORCE_NS == '1' &amp;&amp; security == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
            pspace = <a link="enum_PIDSpace_NonSecure" file="shared_pseudocode.xml">PIDSpace_NonSecure</a>;
        end;
    end;
    if ((IsFeatureImplemented(FEAT_MPAMv0p1) || IsFeatureImplemented(FEAT_MPAMv1p1)) &amp;&amp;
          MPAMIDR_EL1().HAS_SDEFLT == '1') then
        if MPAM3_EL3().SDEFLT == '1' &amp;&amp; security == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
            return <a link="func_DefaultMPAMInfo_1" file="shared_pseudocode.xml">DefaultMPAMInfo</a>(pspace);
        end;
    end;
    if !<a link="func_MPAMIsEnabled_0" file="shared_pseudocode.xml">MPAMIsEnabled</a>() then
        return <a link="func_DefaultMPAMInfo_1" file="shared_pseudocode.xml">DefaultMPAMInfo</a>(pspace);
    else
        return <a link="func_GenMPAM_3" file="shared_pseudocode.xml">GenMPAM</a>(mpamEL, mpamdata, pspace);
    end;
end;</pstext></ps>
    <ps name="shared/functions/mpam/GenMPAMCurEL" mylink="shared.functions.mpam.GenMPAMCurEL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GenMPAMCurEL()
// ==============
// Returns MPAMinfo for the current EL and security state.
// May be called if MPAM is not implemented (but in an version that supports
// MPAM), MPAM is disabled, or in AArch32_  In AArch32, convert the mode to
// EL if can and use that to drive MPAM information generation.  If mode
// cannot be converted, MPAM is not implemented, or MPAM is disabled return
// default MPAM information for the current security state.

func <anchor link="func_GenMPAMCurEL_1">GenMPAMCurEL</anchor>(acctype : <a link="type_AccessType" file="shared_pseudocode.xml">AccessType</a>) =&gt; <a link="type_MPAMinfo" file="shared_pseudocode.xml">MPAMinfo</a>
begin
    return <a link="func_GenMPAMAtEL_2" file="shared_pseudocode.xml">GenMPAMAtEL</a>(acctype, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
end;</pstext></ps>
    <ps name="shared/functions/mpam/GenNewMPAMData" mylink="shared.functions.mpam.GenNewMPAMData" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GenNewMPAMData()
// ================

func <anchor link="func_GenNewMPAMData_0">GenNewMPAMData</anchor>() =&gt; <a link="type_MPAMdata" file="shared_pseudocode.xml">MPAMdata</a>
begin
    var mpamdata : <a link="type_MPAMdata" file="shared_pseudocode.xml">MPAMdata</a>;
    mpamdata.in_d   = FALSE;
    mpamdata.sm  = FALSE;
    mpamdata.trb = FALSE;
    return mpamdata;
end;</pstext></ps>
    <ps name="shared/functions/mpam/GenPARTID" mylink="shared.functions.mpam.GenPARTID" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GenPARTID()
// ===========
// Returns physical PARTID and error boolean for Exception level el.
// If mpamdata.sm is TRUE then PARTID is from MPAMSM_EL1.
// If mpamdata.trb is TRUE then PARTID is from TRBMPAM_EL1.
// Otherwise, the PARTID is from MPAMn_ELx.

func <anchor link="func_GenPARTID_3">GenPARTID</anchor>(el : bits(2), mpamdata : <a link="type_MPAMdata" file="shared_pseudocode.xml">MPAMdata</a>, pspace : <a link="type_PARTIDSpaceType" file="shared_pseudocode.xml">PARTIDSpaceType</a>) =&gt; (<a link="type_PARTIDType" file="shared_pseudocode.xml">PARTIDType</a>, boolean)
begin
    let partidel : <a link="type_PARTIDType" file="shared_pseudocode.xml">PARTIDType</a> = <a link="func_GetMPAM_PARTID_2" file="shared_pseudocode.xml">GetMPAM_PARTID</a>(el, mpamdata);
    let partid_max : <a link="type_PARTIDType" file="shared_pseudocode.xml">PARTIDType</a> = (if mpamdata.trb then TRBDEVID1().PARTID_MAX
                                   else MPAMIDR_EL1().PARTID_MAX);
    if UInt(partidel) &gt; UInt(partid_max) then
        return (<a link="global_DEFAULT_PARTID" file="shared_pseudocode.xml">DEFAULT_PARTID</a>, TRUE);
    end;
    if <a link="func_MPAMIsVirtual_2" file="shared_pseudocode.xml">MPAMIsVirtual</a>(el, mpamdata) then
        return <a link="func_MAP_vPARTID_1" file="shared_pseudocode.xml">MAP_vPARTID</a>(partidel);
    else
        return (partidel, FALSE);
    end;
end;</pstext></ps>
    <ps name="shared/functions/mpam/GenPMG" mylink="shared.functions.mpam.GenPMG" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GenPMG()
// ========
// Returns PMG for Exception level el.
// if mpamdata.sm is TRUE then PMG is from MPAMSM_EL1.
// If mpamdata.trb is TRUE then PMG is from TRBMPAM_EL1.
// Otherwise, PMG is from MPAMn_ELx.
// If PARTID generation (GenPARTID) encountered an error, GenPMG() should be
// called with partid_err as TRUE.

func <anchor link="func_GenPMG_4">GenPMG</anchor>(el : bits(2), mpamdata : <a link="type_MPAMdata" file="shared_pseudocode.xml">MPAMdata</a>, partid_err : boolean,
            pspace : <a link="type_PARTIDSpaceType" file="shared_pseudocode.xml">PARTIDSpaceType</a>) =&gt; <a link="type_PMGType" file="shared_pseudocode.xml">PMGType</a>
begin
    if partid_err &amp;&amp; <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_USE_DEFAULT_PMG" file="shared_pseudocode.xml">Unpredictable_USE_DEFAULT_PMG</a>) then
        return <a link="global_DEFAULT_PMG" file="shared_pseudocode.xml">DEFAULT_PMG</a>;
    end;
    let groupel : <a link="type_PMGType" file="shared_pseudocode.xml">PMGType</a> = <a link="func_GetMPAM_PMG_2" file="shared_pseudocode.xml">GetMPAM_PMG</a>(el, mpamdata);
    let pmg_max : integer = (if mpamdata.trb then UInt(TRBDEVID1().PMG_MAX)
                             else UInt(MPAMIDR_EL1().PMG_MAX));
    if UInt(groupel) &lt;= pmg_max then
        return groupel;
    end;
    return <a link="global_DEFAULT_PMG" file="shared_pseudocode.xml">DEFAULT_PMG</a>;
end;</pstext></ps>
    <ps name="shared/functions/mpam/GetMPAM_PARTID" mylink="shared.functions.mpam.GetMPAM_PARTID" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetMPAM_PARTID()
// ================
// Returns a PARTID
// If mpamdata.sm is TRUE then PARTID is from MPAMSM_EL1.
// If mpamdata.trb is TRUE then PARTID is from TRBMPAM_EL1.
// Otherwise, the PARTID is from MPAMn_ELx.

func <anchor link="func_GetMPAM_PARTID_2">GetMPAM_PARTID</anchor>(MPAMn : bits(2), mpamdata : <a link="type_MPAMdata" file="shared_pseudocode.xml">MPAMdata</a>) =&gt; <a link="type_PARTIDType" file="shared_pseudocode.xml">PARTIDType</a>
begin
    if mpamdata.sm then
        return MPAMSM_EL1().PARTID_D;
    end;

    if mpamdata.trb then
        return TRBMPAM_EL1().PARTID;
    end;

    if mpamdata.in_d then
        case MPAMn of
            when '11' =&gt; return MPAM3_EL3().PARTID_I;
            when '10' =&gt; return (if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then MPAM2_EL2().PARTID_I else <a link="global_DEFAULT_PARTID" file="shared_pseudocode.xml">DEFAULT_PARTID</a>);
            when '01' =&gt; return MPAM1_EL1().PARTID_I;
            when '00' =&gt; return MPAM0_EL1().PARTID_I;
        end;
    else
        case MPAMn of
            when '11' =&gt; return MPAM3_EL3().PARTID_D;
            when '10' =&gt; return (if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then MPAM2_EL2().PARTID_D else <a link="global_DEFAULT_PARTID" file="shared_pseudocode.xml">DEFAULT_PARTID</a>);
            when '01' =&gt; return MPAM1_EL1().PARTID_D;
            when '00' =&gt; return MPAM0_EL1().PARTID_D;
        end;
    end;
end;</pstext></ps>
    <ps name="shared/functions/mpam/GetMPAM_PMG" mylink="shared.functions.mpam.GetMPAM_PMG" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetMPAM_PMG()
// =============
// Returns a PMG.
// if mpamdata.sm is TRUE then PMG is from MPAMSM_EL1.
// If mpamdata.trb is TRUE then PMG is from TRBMPAM_EL1.
// Otherwise, PMG is from MPAMn_ELx.

func <anchor link="func_GetMPAM_PMG_2">GetMPAM_PMG</anchor>(MPAMn : bits(2), mpamdata : <a link="type_MPAMdata" file="shared_pseudocode.xml">MPAMdata</a>) =&gt; <a link="type_PMGType" file="shared_pseudocode.xml">PMGType</a>
begin
    if mpamdata.sm then
        return MPAMSM_EL1().PMG_D;
    end;

    if mpamdata.trb then
        return TRBMPAM_EL1().PMG;
    end;

    if mpamdata.in_d then
        case MPAMn of
            when '11' =&gt; return MPAM3_EL3().PMG_I;
            when '10' =&gt; return (if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then MPAM2_EL2().PMG_I else <a link="global_DEFAULT_PMG" file="shared_pseudocode.xml">DEFAULT_PMG</a>);
            when '01' =&gt; return MPAM1_EL1().PMG_I;
            when '00' =&gt; return MPAM0_EL1().PMG_I;
        end;
    else
        case MPAMn of
            when '11' =&gt; return MPAM3_EL3().PMG_D;
            when '10' =&gt; return (if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then MPAM2_EL2().PMG_D else <a link="global_DEFAULT_PMG" file="shared_pseudocode.xml">DEFAULT_PMG</a>);
            when '01' =&gt; return MPAM1_EL1().PMG_D;
            when '00' =&gt; return MPAM0_EL1().PMG_D;
        end;
    end;
end;</pstext></ps>
    <ps name="shared/functions/mpam/MAP_vPARTID" mylink="shared.functions.mpam.MAP_vPARTID" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MAP_vPARTID()
// =============
// Performs conversion of virtual PARTID into physical PARTID
// Contains all of the error checking and implementation
// choices for the conversion.

func <anchor link="func_MAP_vPARTID_1">MAP_vPARTID</anchor>(vpartid : <a link="type_PARTIDType" file="shared_pseudocode.xml">PARTIDType</a>) =&gt; (<a link="type_PARTIDType" file="shared_pseudocode.xml">PARTIDType</a>, boolean)
begin
    // should not ever be called if EL2 is not implemented
    // or is implemented but not enabled in the current
    // security state.
    var ret : <a link="type_PARTIDType" file="shared_pseudocode.xml">PARTIDType</a>;
    var err : boolean;
    var virt : integer    = UInt(vpartid);
    let vpmrmax : integer = UInt(MPAMIDR_EL1().VPMR_MAX);

    // vpartid_max is largest vpartid supported
    let vpartid_max : integer = (vpmrmax &lt;&lt; 2) + 3;

    // One of many ways to reduce vpartid to value less than vpartid_max.
    if UInt(vpartid) &gt; vpartid_max then
        virt = virt MOD (vpartid_max+1);
    end;

    // Check for valid mapping entry.
    if MPAMVPMV_EL2()[virt] == '1' then
        // vpartid has a valid mapping, access the map.
        ret = <a link="func_mapvpmw_1" file="shared_pseudocode.xml">mapvpmw</a>(virt);
        err = FALSE;

    // Check for default virtual PARTID valid
    elsif MPAMVPMV_EL2()[0] == '1' then
        // Use default mapping for vpartid == 0.
        ret = MPAMVPM0_EL2()[0 +: 16];
        err = FALSE;

    // Neither is valid, use default physical PARTID.
    else
        ret = <a link="global_DEFAULT_PARTID" file="shared_pseudocode.xml">DEFAULT_PARTID</a>;
        err = TRUE;
    end;

    // Check that the physical PARTID is in-range.
    // This physical PARTID came from a virtual mapping entry.
    let partid_max : integer = UInt(MPAMIDR_EL1().PARTID_MAX);
    if UInt(ret) &gt; partid_max then
        // Out of range, so return default physical PARTID
        ret = <a link="global_DEFAULT_PARTID" file="shared_pseudocode.xml">DEFAULT_PARTID</a>;
        err = TRUE;
    end;
    return (ret, err);
end;</pstext></ps>
    <ps name="shared/functions/mpam/MPAM" mylink="shared.functions.mpam.MPAM" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MPAM Types
// ==========

type <anchor link="type_PARTIDType">PARTIDType</anchor> of bits(16);
type <anchor link="type_PMGType">PMGType</anchor> of bits(8);

type <anchor link="type_PARTIDSpaceType">PARTIDSpaceType</anchor> of enumeration {
    <anchor link="enum_PIDSpace_Secure">PIDSpace_Secure</anchor>,
    <anchor link="enum_PIDSpace_Root">PIDSpace_Root</anchor>,
    <anchor link="enum_PIDSpace_Realm">PIDSpace_Realm</anchor>,
    <anchor link="enum_PIDSpace_NonSecure">PIDSpace_NonSecure</anchor>
};

type <anchor link="type_MPAMinfo">MPAMinfo</anchor> of record {
     mpam_sp : <a link="type_PARTIDSpaceType" file="shared_pseudocode.xml">PARTIDSpaceType</a>,
     partid : <a link="type_PARTIDType" file="shared_pseudocode.xml">PARTIDType</a>,
     pmg : <a link="type_PMGType" file="shared_pseudocode.xml">PMGType</a>
};
constant <anchor link="global_DEFAULT_PARTID">DEFAULT_PARTID</anchor> : <a link="type_PARTIDType" file="shared_pseudocode.xml">PARTIDType</a> = 0[15:0];
constant <anchor link="global_DEFAULT_PMG">DEFAULT_PMG</anchor> : <a link="type_PMGType" file="shared_pseudocode.xml">PMGType</a> = 0[7:0];

type <anchor link="type_MPAMdata">MPAMdata</anchor> of record {
    in_d : boolean,       // TRUE for instruction accesses
    sm : boolean,         // TRUE for SME, SVE, SIMD&amp;FP access, and SVE prefetch
                          // instructions, when the PE is in Streaming mode
    trb : boolean         // TRUE for TRBE accesses using External mode when TRBMPAM_EL1.EN is 0b1
};</pstext></ps>
    <ps name="shared/functions/mpam/MPAMIsEnabled" mylink="shared.functions.mpam.MPAMIsEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MPAMIsEnabled()
// ===============
// Returns TRUE if MPAM is enabled.

func <anchor link="func_MPAMIsEnabled_0">MPAMIsEnabled</anchor>() =&gt; boolean
begin
    let el : bits(2) = <a link="func_HighestEL_0" file="shared_pseudocode.xml">HighestEL</a>();
    case el of
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt; return MPAM3_EL3().MPAMEN == '1';
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt; return MPAM2_EL2().MPAMEN == '1';
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt; return MPAM1_EL1().MPAMEN == '1';
    end;
end;</pstext></ps>
    <ps name="shared/functions/mpam/MPAMIsVirtual" mylink="shared.functions.mpam.MPAMIsVirtual" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MPAMIsVirtual()
// ===============
// Returns TRUE if MPAM is configured to be virtual at the given el.

func <anchor link="func_MPAMIsVirtual_2">MPAMIsVirtual</anchor>(el : bits(2), mpamdata : <a link="type_MPAMdata" file="shared_pseudocode.xml">MPAMdata</a>) =&gt; boolean
begin
    if mpamdata.trb then
        return FALSE;
    end;

    return (MPAMIDR_EL1().HAS_HCR == '1' &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp;
            ((el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; MPAMHCR_EL2().EL0_VPMEN == '1' &amp;&amp; !<a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>)) ||
             (el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; MPAMHCR_EL2().EL1_VPMEN == '1')));
end;</pstext></ps>
    <ps name="shared/functions/mpam/PARTIDSpaceFromSS" mylink="shared.functions.mpam.PARTIDSpaceFromSS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PARTIDSpaceFromSS()
// ===================
// Returns the primary PARTID space from the Security State.

func <anchor link="func_PARTIDSpaceFromSS_1">PARTIDSpaceFromSS</anchor>(security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>) =&gt; <a link="type_PARTIDSpaceType" file="shared_pseudocode.xml">PARTIDSpaceType</a>
begin
    case security of
        when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt;
            return <a link="enum_PIDSpace_NonSecure" file="shared_pseudocode.xml">PIDSpace_NonSecure</a>;
        when <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a> =&gt;
            return <a link="enum_PIDSpace_Root" file="shared_pseudocode.xml">PIDSpace_Root</a>;
        when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;
            return <a link="enum_PIDSpace_Realm" file="shared_pseudocode.xml">PIDSpace_Realm</a>;
        when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;
            return <a link="enum_PIDSpace_Secure" file="shared_pseudocode.xml">PIDSpace_Secure</a>;
        otherwise =&gt;
            unreachable;
    end;
end;</pstext></ps>
    <ps name="shared/functions/mpam/UsePrimarySpaceEL10" mylink="shared.functions.mpam.UsePrimarySpaceEL10" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// UsePrimarySpaceEL10()
// =====================
// Checks whether Primary space is configured in the
// MPAM3_EL3 and MPAM2_EL2 ALTSP control bits that affect
// MPAM ALTSP use at EL1 and EL0.

func <anchor link="func_UsePrimarySpaceEL10_0">UsePrimarySpaceEL10</anchor>() =&gt; boolean
begin
    if MPAM3_EL3().ALTSP_HEN == '0' then
        return MPAM3_EL3().ALTSP_HFC == '0';
    end;
    return !<a link="func_MPAMIsEnabled_0" file="shared_pseudocode.xml">MPAMIsEnabled</a>() || !<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() || MPAM2_EL2().ALTSP_HFC == '0';
end;</pstext></ps>
    <ps name="shared/functions/mpam/UsePrimarySpaceEL2" mylink="shared.functions.mpam.UsePrimarySpaceEL2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// UsePrimarySpaceEL2()
// ====================
// Checks whether Primary space is configured in the
// MPAM3_EL3 and MPAM2_EL2 ALTSP control bits that affect
// MPAM ALTSP use at EL2.

func <anchor link="func_UsePrimarySpaceEL2_0">UsePrimarySpaceEL2</anchor>() =&gt; boolean
begin
    if MPAM3_EL3().ALTSP_HEN == '0' then
        return MPAM3_EL3().ALTSP_HFC == '0';
    end;
    return !<a link="func_MPAMIsEnabled_0" file="shared_pseudocode.xml">MPAMIsEnabled</a>() || MPAM2_EL2().ALTSP_EL2 == '0';
end;</pstext></ps>
    <ps name="shared/functions/mpam/mapvpmw" mylink="shared.functions.mpam.mapvpmw" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// mapvpmw()
// =========
// Map a virtual PARTID into a physical PARTID using
// the MPAMVPMn_EL2 registers.
// vpartid is now assumed in-range and valid (checked by caller)
// returns physical PARTID from mapping entry.

func <anchor link="func_mapvpmw_1">mapvpmw</anchor>(vpartid : integer) =&gt; <a link="type_PARTIDType" file="shared_pseudocode.xml">PARTIDType</a>
begin
    var vpmw : bits(64);
    let wd : integer = vpartid DIVRM 4;
    case wd of
        when 0    =&gt; vpmw = MPAMVPM0_EL2();
        when 1    =&gt; vpmw = MPAMVPM1_EL2();
        when 2    =&gt; vpmw = MPAMVPM2_EL2();
        when 3    =&gt; vpmw = MPAMVPM3_EL2();
        when 4    =&gt; vpmw = MPAMVPM4_EL2();
        when 5    =&gt; vpmw = MPAMVPM5_EL2();
        when 6    =&gt; vpmw = MPAMVPM6_EL2();
        when 7    =&gt; vpmw = MPAMVPM7_EL2();
        otherwise =&gt; vpmw = Zeros{64};
    end;
    // vpme_lsb selects LSB of field within register
    let vpme_lsb : integer = (vpartid MOD 4) * 16;
    return vpmw[vpme_lsb +: 16];
end;</pstext></ps>
    <ps name="shared/functions/predictionrestrict/ASID" mylink="shared.functions.predictionrestrict.ASID" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ASID
// ====
// Effective ASID.

func <anchor link="func_ASID_0">ASID</anchor>() =&gt; bits(NUM_ASIDBITS)
begin
    if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
        if TCR_EL2().A1 == '1' then
            return TTBR1_EL2().ASID;
        else
            return TTBR0_EL2().ASID;
        end;
    end;
    if !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        if TCR_EL1().A1 == '1' then
            return TTBR1_EL1().ASID;
        else
            return TTBR0_EL1().ASID;
        end;
    else
        if TTBCR().EAE == '0' then
            return ZeroExtend{NUM_ASIDBITS}(CONTEXTIDR().ASID);
        else
            if TTBCR().A1 == '1' then
                return ZeroExtend{NUM_ASIDBITS}(TTBR1().ASID);
            else
                return ZeroExtend{NUM_ASIDBITS}(TTBR0().ASID);
            end;
        end;
    end;
end;</pstext></ps>
    <ps name="shared/functions/predictionrestrict/ExecutionCntxt" mylink="shared.functions.predictionrestrict.ExecutionCntxt" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExecutionCntxt
// ===============
// Context information for prediction restriction operation.

type <anchor link="type_ExecutionCntxt">ExecutionCntxt</anchor> of record {
    is_vmid_valid : boolean,        // is vmid valid for current context
    all_vmid      : boolean,        // should the operation be applied for all vmids
    vmid          : bits(NUM_VMIDBITS), // if all_vmid = FALSE, vmid to which operation is applied
    is_asid_valid : boolean,        // is asid valid for current context
    all_asid      : boolean,        // should the operation be applied for all asids
    asid          : bits(NUM_ASIDBITS), // if all_asid = FALSE, ASID to which operation is applied
    target_el     : bits(2),        // target EL at which operation is performed
    security      : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>,
    restriction   : <a link="type_RestrictType" file="shared_pseudocode.xml">RestrictType</a>    // type of restriction operation
};</pstext></ps>
    <ps name="shared/functions/predictionrestrict/RESTRICT_PREDICTIONS" mylink="shared.functions.predictionrestrict.RESTRICT_PREDICTIONS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// RESTRICT_PREDICTIONS()
// ======================
// Clear all speculated values.

impdef func RESTRICT_PREDICTIONS(c : <a link="type_ExecutionCntxt" file="shared_pseudocode.xml">ExecutionCntxt</a>)
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/predictionrestrict/RestrictType" mylink="shared.functions.predictionrestrict.RestrictType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// RestrictType
// ============
// Type of restriction on speculation.

type <anchor link="type_RestrictType">RestrictType</anchor> of enumeration {
    <anchor link="enum_RestrictType_DataValue">RestrictType_DataValue</anchor>,
    <anchor link="enum_RestrictType_ControlFlow">RestrictType_ControlFlow</anchor>,
    <anchor link="enum_RestrictType_CachePrefetch">RestrictType_CachePrefetch</anchor>,
    <anchor link="enum_RestrictType_Other">RestrictType_Other</anchor>              // Any other trained speculation mechanisms than those above
};</pstext></ps>
    <ps name="shared/functions/predictionrestrict/TargetSecurityState" mylink="shared.functions.predictionrestrict.TargetSecurityState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TargetSecurityState()
// =====================
// Decode the target security state for the prediction context.

func <anchor link="func_TargetSecurityState_2">TargetSecurityState</anchor>(NS : bit, NSE : bit) =&gt; <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>
begin
    let curr_ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> =  <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
    if curr_ss == <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> then
        return <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a>;
    elsif curr_ss == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> then
        case NS of
            when '0' =&gt; return <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>;
            when '1' =&gt; return <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a>;
        end;
    elsif IsFeatureImplemented(FEAT_RME) then
        if curr_ss == <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a> then
            case NSE::NS of
                when '00' =&gt; return <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>;
                when '01' =&gt; return <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a>;
                when '11' =&gt; return <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a>;
                when '10' =&gt; return <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a>;
            end;
        elsif curr_ss == <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> then
            return <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a>;
        end;
    end;
    unreachable;
end;</pstext></ps>
    <ps name="shared/functions/registers/BranchTo" mylink="shared.functions.registers.BranchTo" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BranchTo()
// ==========
// Set program counter to a new address, with a branch type.
// Parameter branch_conditional indicates whether the executed branch has a conditional encoding.
// In AArch64 state the address might include a tag in the top eight bits.

func <anchor link="func_BranchTo_4">BranchTo</anchor>{N}(target : bits(N), branch_type : <a link="type_BranchType" file="shared_pseudocode.xml">BranchType</a>, branch_conditional : boolean)
begin
    Hint_Branch(branch_type);
    if N == 32 then
        assert <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>();
        <a link="global__PC" file="shared_pseudocode.xml">_PC</a> = ZeroExtend{64}(target);
    else
        assert N == 64 &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>();
        let target_vaddress : bits(64) = <a link="func_AArch64_BranchAddr_2" file="shared_pseudocode.xml">AArch64_BranchAddr</a>(target[63:0], <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
        if (IsFeatureImplemented(FEAT_BRBE) &amp;&amp;
              branch_type IN {<a link="enum_BranchType_DIR" file="shared_pseudocode.xml">BranchType_DIR</a>, <a link="enum_BranchType_INDIR" file="shared_pseudocode.xml">BranchType_INDIR</a>,
                              <a link="enum_BranchType_DIRCALL" file="shared_pseudocode.xml">BranchType_DIRCALL</a>, <a link="enum_BranchType_INDCALL" file="shared_pseudocode.xml">BranchType_INDCALL</a>,
                              <a link="enum_BranchType_RET" file="shared_pseudocode.xml">BranchType_RET</a>}) then
            <a link="func_BRBEBranch_3" file="shared_pseudocode.xml">BRBEBranch</a>(branch_type, branch_conditional, target_vaddress);
        end;
        let branch_taken : boolean = TRUE;

        if IsFeatureImplemented(FEAT_SPE) then
            <a link="func_SPEBranch_5" file="shared_pseudocode.xml">SPEBranch</a>{N}(target, branch_type, branch_conditional, branch_taken);
        end;

        <a link="global__PC" file="shared_pseudocode.xml">_PC</a> = target_vaddress;
    end;
    return;
end;</pstext></ps>
    <ps name="shared/functions/registers/BranchToAddr" mylink="shared.functions.registers.BranchToAddr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BranchToAddr()
// ==============
// Set program counter to a new address, with a branch type.
// In AArch64 state the address does not include a tag in the top eight bits.

func <anchor link="func_BranchToAddr_3">BranchToAddr</anchor>{N}(target : bits(N), branch_type : <a link="type_BranchType" file="shared_pseudocode.xml">BranchType</a>)
begin
    Hint_Branch(branch_type);
    if N == 32 then
        assert <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>();
        <a link="global__PC" file="shared_pseudocode.xml">_PC</a> = ZeroExtend{64}(target);
    else
        assert N == 64 &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>();
        <a link="global__PC" file="shared_pseudocode.xml">_PC</a> = target[63:0];
    end;
    return;
end;</pstext></ps>
    <ps name="shared/functions/registers/BranchType" mylink="shared.functions.registers.BranchType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BranchType
// ==========
// Information associated with a change in control flow.

type <anchor link="type_BranchType">BranchType</anchor> of enumeration {
    <anchor link="enum_BranchType_DIRCALL">BranchType_DIRCALL</anchor>,     // Direct Branch with link
    <anchor link="enum_BranchType_INDCALL">BranchType_INDCALL</anchor>,     // Indirect Branch with link
    <anchor link="enum_BranchType_ERET">BranchType_ERET</anchor>,        // Exception return (indirect)
    <anchor link="enum_BranchType_DBGEXIT">BranchType_DBGEXIT</anchor>,     // Exit from Debug state
    <anchor link="enum_BranchType_RET">BranchType_RET</anchor>,         // Indirect branch with function return hint
    <anchor link="enum_BranchType_DIR">BranchType_DIR</anchor>,         // Direct branch
    <anchor link="enum_BranchType_INDIR">BranchType_INDIR</anchor>,       // Indirect branch
    <anchor link="enum_BranchType_EXCEPTION">BranchType_EXCEPTION</anchor>,   // Exception entry
    <anchor link="enum_BranchType_RESET">BranchType_RESET</anchor>,       // Reset
    <anchor link="enum_BranchType_UNKNOWN">BranchType_UNKNOWN</anchor>};    // Other</pstext></ps>
    <ps name="shared/functions/registers/Branchtypetaken" mylink="shared.functions.registers.Branchtypetaken" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Branchtypetaken
// ===============
var <anchor link="global_Branchtypetaken">Branchtypetaken</anchor> : <a link="type_BranchType" file="shared_pseudocode.xml">BranchType</a>;</pstext></ps>
    <ps name="shared/functions/registers/ESize" mylink="shared.functions.registers.ESize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ESize
// =====

type <anchor link="type_ESize">ESize</anchor> of integer{8, 16, 32, 64, 128};</pstext></ps>
    <ps name="shared/functions/registers/EffectiveFPCR" mylink="shared.functions.registers.EffectiveFPCR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveFPCR()
// ===============
// Returns the effective FPCR value

func <anchor link="func_EffectiveFPCR_0">EffectiveFPCR</anchor>() =&gt; FPCR_Type
begin
    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        var fpcr : FPCR_Type = ZeroExtend{64}(FPSCR());
        fpcr[7:0]   = '00000000';
        fpcr[31:27] = '00000';
        return fpcr;
    end;
    return FPCR();
end;</pstext></ps>
    <ps name="shared/functions/registers/Hint_Branch" mylink="shared.functions.registers.Hint_Branch" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Hint_Branch()
// =============
// Report the hint passed to BranchTo() and BranchToAddr(), for consideration when processing
// the next instruction.

impdef func Hint_Branch(hint : <a link="type_BranchType" file="shared_pseudocode.xml">BranchType</a>)
begin
    <a link="global_Branchtypetaken" file="shared_pseudocode.xml">Branchtypetaken</a> = hint;
    return;
end;</pstext></ps>
    <ps name="shared/functions/registers/NextInstrAddr" mylink="shared.functions.registers.NextInstrAddr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// NextInstrAddr()
// ===============
// Return address of the sequentially next instruction.

impdef func <anchor link="func_NextInstrAddr_1">NextInstrAddr</anchor>{N}() =&gt; bits(N)
begin
    return Zeros{N};
end;</pstext></ps>
    <ps name="shared/functions/registers/ResetExternalDebugRegisters" mylink="shared.functions.registers.ResetExternalDebugRegisters" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ResetExternalDebugRegisters()
// =============================
// Reset the External Debug registers in the Core power domain.

impdef func ResetExternalDebugRegisters(cold_reset : boolean)
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/registers/ThisInstrAddr" mylink="shared.functions.registers.ThisInstrAddr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ThisInstrAddr()
// ===============
// Return address of the current instruction.

func <anchor link="func_ThisInstrAddr_1">ThisInstrAddr</anchor>{N}() =&gt; bits(N)
begin
    assert N == 64 || (N == 32 &amp;&amp; <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>());
    return <a link="global__PC" file="shared_pseudocode.xml">_PC</a>[N-1:0];
end;</pstext></ps>
    <ps name="shared/functions/registers/UnimplementedIDRegister" mylink="shared.functions.registers.UnimplementedIDRegister" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// UnimplementedIDRegister()
// =========================
// Trap access to unimplemented encodings in the feature ID register space.

func <anchor link="func_UnimplementedIDRegister_0">UnimplementedIDRegister</anchor>()
begin
    if IsFeatureImplemented(FEAT_IDST) then
        var target_el : bits(2) = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
        if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
            target_el = if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; HCR_EL2().TGE == '1' then <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> else <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
        end;
        <a link="func_AArch64_SystemAccessTrap_2" file="shared_pseudocode.xml">AArch64_SystemAccessTrap</a>(target_el, 0x18);
    end;
    Undefined();
end;</pstext></ps>
    <ps name="shared/functions/registers/V" mylink="shared.functions.registers.V" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// V - accessor
// ============

accessor <anchor link="accessor_V_2">V</anchor>{width : <a link="type_ESize" file="shared_pseudocode.xml">ESize</a>}(n : integer) &lt;=&gt; value : bits(width)
begin
    // Read from SIMD&amp;FP register with implicit slice of 8, 16
    // 32, 64 or 128 bits.
    getter
        assert n &gt;= 0 &amp;&amp; n &lt;= 31;
        return <a link="global__Z" file="shared_pseudocode.xml">_Z</a>[[n]][width-1:0];
    end;

    // Write to SIMD&amp;FP register with implicit extension from
    // 8, 16, 32, 64 or 128 bits.
    setter
        assert n &gt;= 0 &amp;&amp; n &lt;= 31;
        if <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_SVEZEROUPPER" file="shared_pseudocode.xml">Unpredictable_SVEZEROUPPER</a>) then
            <a link="global__Z" file="shared_pseudocode.xml">_Z</a>[[n]] = ZeroExtend{<a link="global_MAX_VL" file="shared_pseudocode.xml">MAX_VL</a>}(value);
        else
            let vlen : <a link="type_VecLen" file="shared_pseudocode.xml">VecLen</a> = if <a link="func_IsSVEEnabled_1" file="shared_pseudocode.xml">IsSVEEnabled</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) then <a link="func_CurrentVL_0" file="shared_pseudocode.xml">CurrentVL</a>() else 128;
            <a link="global__Z" file="shared_pseudocode.xml">_Z</a>[[n]][vlen-1:0] = ZeroExtend{vlen}(value);
        end;
    end;
end;</pstext></ps>
    <ps name="shared/functions/registers/Vpart" mylink="shared.functions.registers.Vpart" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Vpart - accessor
// ================

accessor <anchor link="accessor_Vpart_3">Vpart</anchor>{width : <a link="type_ESize" file="shared_pseudocode.xml">ESize</a>}(n : integer, part : integer) &lt;=&gt; value : bits(width)
begin
    // Reads a 128-bit SIMD&amp;FP register in up to two parts:
    //  part 0 returns the bottom 8, 16, 32 or 64 bits of a value held in the register;
    //  part 1 returns the top half of the bottom 64 bits or the top half of the 128-bit
    //  value held in the register.
    getter
        assert n &gt;= 0 &amp;&amp; n &lt;= 31;
        assert part IN {0, 1};
        if part == 0 then
            assert width &lt; 128;
            return <a link="accessor_V_2" file="shared_pseudocode.xml">V</a>{width}(n);
        else
            assert width IN {32,64};
            let vreg : bits(128) = V{}(n);
            return vreg[(width * 2)-1:width];
        end;
    end;

    setter
    // Writes a 128-bit SIMD&amp;FP register in up to two parts:
    //  part 0 zero extends a 8, 16, 32, or 64-bit value to fill the whole register;
    //  part 1 inserts a 64-bit value into the top half of the register.
        assert n &gt;= 0 &amp;&amp; n &lt;= 31;
        assert part IN {0, 1};
        if part == 0 then
            assert width &lt; 128;
            <a link="accessor_V_2" file="shared_pseudocode.xml">V</a>{width}(n) = value;
        else
            assert width == 64;
            let vreg : bits(64) = V{}(n);
            <a link="accessor_V_2" file="shared_pseudocode.xml">V</a>{128}(n) = value[63:0] :: vreg;
        end;
    end;
end;</pstext></ps>
    <ps name="shared/functions/registers/_PC" mylink="shared.functions.registers._PC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// _PC - the program counter
// =========================

var <anchor link="global__PC">_PC</anchor> : bits(64);</pstext></ps>
    <ps name="shared/functions/registers/_R" mylink="shared.functions.registers._R" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// _R - the general-purpose register file array
// ============================================


var <anchor link="global__R">_R</anchor> : array [[31]] of bits(64);</pstext></ps>
    <ps name="shared/functions/sysregisters/SPSR_ELx" mylink="shared.functions.sysregisters.SPSR_ELx" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPSR_ELx - accessor
// ===================

accessor <anchor link="accessor_SPSR_ELx_0">SPSR_ELx</anchor>() &lt;=&gt; value :  bits(64)
begin
    getter
        var result : bits(64);
        case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>  =&gt; result = SPSR_EL1()[63:0];
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>  =&gt; result = SPSR_EL2()[63:0];
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>  =&gt; result = SPSR_EL3()[63:0];
            otherwise =&gt; unreachable;
        end;
        return result;
    end;

    setter
        case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>   =&gt; SPSR_EL1()[63:0] = value[63:0];
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>   =&gt; SPSR_EL2()[63:0] = value[63:0];
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>   =&gt; SPSR_EL3()[63:0] = value[63:0];
            otherwise  =&gt; unreachable;
        end;
    end;
end;</pstext></ps>
    <ps name="shared/functions/sysregisters/SPSR_curr" mylink="shared.functions.sysregisters.SPSR_curr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SPSR_curr - accessor
// ====================

accessor <anchor link="accessor_SPSR_curr_0">SPSR_curr</anchor>() &lt;=&gt; value : bits(32)
begin
    getter
        var result : bits(32);
        case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M of
            when <a link="global_M32_FIQ" file="shared_pseudocode.xml">M32_FIQ</a>     =&gt; result = SPSR_fiq()[31:0];
            when <a link="global_M32_IRQ" file="shared_pseudocode.xml">M32_IRQ</a>     =&gt; result = SPSR_irq()[31:0];
            when <a link="global_M32_Svc" file="shared_pseudocode.xml">M32_Svc</a>     =&gt; result = SPSR_svc()[31:0];
            when <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a> =&gt; result = SPSR_mon()[31:0];
            when <a link="global_M32_Abort" file="shared_pseudocode.xml">M32_Abort</a>   =&gt; result = SPSR_abt()[31:0];
            when <a link="global_M32_Hyp" file="shared_pseudocode.xml">M32_Hyp</a>     =&gt; result = SPSR_hyp()[31:0];
            when <a link="global_M32_Undef" file="shared_pseudocode.xml">M32_Undef</a>   =&gt; result = SPSR_und()[31:0];
            otherwise        =&gt; unreachable;
        end;
        return result;
    end;

    setter
        case <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M of
            when <a link="global_M32_FIQ" file="shared_pseudocode.xml">M32_FIQ</a>     =&gt; SPSR_fiq()[31:0] = value[31:0];
            when <a link="global_M32_IRQ" file="shared_pseudocode.xml">M32_IRQ</a>     =&gt; SPSR_irq()[31:0] = value[31:0];
            when <a link="global_M32_Svc" file="shared_pseudocode.xml">M32_Svc</a>     =&gt; SPSR_svc()[31:0] = value[31:0];
            when <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a> =&gt; SPSR_mon()[31:0] = value[31:0];
            when <a link="global_M32_Abort" file="shared_pseudocode.xml">M32_Abort</a>   =&gt; SPSR_abt()[31:0] = value[31:0];
            when <a link="global_M32_Hyp" file="shared_pseudocode.xml">M32_Hyp</a>     =&gt; SPSR_hyp()[31:0] = value[31:0];
            when <a link="global_M32_Undef" file="shared_pseudocode.xml">M32_Undef</a>   =&gt; SPSR_und()[31:0] = value[31:0];
            otherwise        =&gt; unreachable;
        end;
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/AArch64_ChkFeat" mylink="shared.functions.system.AArch64_ChkFeat" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AArch64_ChkFeat()
// =================
// Indicates the status of some features

func <anchor link="func_AArch64_ChkFeat_1">AArch64_ChkFeat</anchor>(feat_select : bits(64)) =&gt; bits(64)
begin
    var feat_en : bits(64) = Zeros{};
    feat_en[0] = if IsFeatureImplemented(FEAT_GCS) &amp;&amp; <a link="func_GCSEnabled_1" file="shared_pseudocode.xml">GCSEnabled</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) then '1' else '0';
    return feat_select AND NOT(feat_en);
end;</pstext></ps>
    <ps name="shared/functions/system/AddressAdd" mylink="shared.functions.system.AddressAdd" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddressAdd()
// ============
// Add an address with an offset and return the result.
// If FEAT_CPA2 is implemented, the pointer arithmetic is checked.

func <anchor link="func_AddressAdd_3">AddressAdd</anchor>(base : bits(64), offset : integer, accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; bits(64)
begin
    return <a link="func_AddressAdd_3" file="shared_pseudocode.xml">AddressAdd</a>(base, offset[63:0], accdesc);
end;

func <anchor link="func_AddressAdd_3">AddressAdd</anchor>(base : bits(64), offset : bits(64), accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; bits(64)
begin
    var result : bits(64) = base + offset;
    result = <a link="func_PointerAddCheckAtEL_3" file="shared_pseudocode.xml">PointerAddCheckAtEL</a>(accdesc.el, result, base);
    return result;
end;</pstext></ps>
    <ps name="shared/functions/system/AddressInNaturallyAlignedBlock" mylink="shared.functions.system.AddressInNaturallyAlignedBlock" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddressInNaturallyAlignedBlock()
// ================================
// Returns TRUE if the given addresses are in the same naturally aligned block, and FALSE otherwise.
// An address is in a naturally aligned block if it meets any of the below conditions:
// * is a power-of-two size.
// * Is no larger than the DC ZVA block size if ESR_ELx.FnP is being set to 0b0, or EDHSR is not
//   implemented or EDHSR.FnP is being set to 0b0 (as appropriate).
// * Is no larger than the smallest implemented translation granule if ESR_ELx.FnP, or EDHSR.FnP
//   (as appropriate) is being set to 0b1.
// * Contains a watchpointed address accessed by the memory access or set of contiguous memory
//   accesses that triggered the watchpoint.

impdef func <anchor link="func_AddressInNaturallyAlignedBlock_2">AddressInNaturallyAlignedBlock</anchor>(address1 : bits(64), address2 : bits(64)) =&gt; boolean
begin
    // Returns TRUE if address in within a naturally aligned block of memory as the watchpointed
    // location, else FALSE.
    return FALSE;
end;</pstext></ps>
    <ps name="shared/functions/system/AddressIncrement" mylink="shared.functions.system.AddressIncrement" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddressIncrement()
// ==================
// Increment an address and return the result.
// If FEAT_CPA2 is implemented, the pointer arithmetic may be checked.

func <anchor link="func_AddressIncrement_3">AddressIncrement</anchor>(base : bits(64), increment : integer, accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; bits(64)
begin
    return <a link="func_AddressIncrement_3" file="shared_pseudocode.xml">AddressIncrement</a>(base, increment[63:0], accdesc);
end;

func <anchor link="func_AddressIncrement_3">AddressIncrement</anchor>(base : bits(64), increment : bits(64), accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; bits(64)
begin
    var result : bits(64) = base + increment;
    // Checking the Pointer Arithmetic on an increment is equivalent to checking the
    // bytes in a sequential access crossing the 0xXXFF_FFFF_FFFF_FFFF boundary.
    if <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_CPACHECK" file="shared_pseudocode.xml">Unpredictable_CPACHECK</a>) then
        result = <a link="func_PointerAddCheckAtEL_3" file="shared_pseudocode.xml">PointerAddCheckAtEL</a>(accdesc.el, result, base);
    end;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/system/BranchTargetCheck" mylink="shared.functions.system.BranchTargetCheck" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BranchTargetCheck()
// ===================
// This function is executed checks if the current instruction is a valid target for a branch
// taken into, or inside, a guarded page. It is executed on every cycle once the current
// instruction has been decoded and the values of InGuardedPage and BTypeCompatible have been
// determined for the current instruction.

func <anchor link="func_BranchTargetCheck_0">BranchTargetCheck</anchor>()
begin
    assert IsFeatureImplemented(FEAT_BTI) &amp;&amp; !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>();

    // The branch target check considers the following state variables:
    // * InGuardedPage, which is evaluated during instruction fetch.
    // * BTypeCompatible, which is evaluated during instruction decode.
    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then
        return;
    elsif IsZero(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.BTYPE) then
        return;
    elsif <a link="global_InGuardedPage" file="shared_pseudocode.xml">InGuardedPage</a> &amp;&amp; !<a link="global_BTypeCompatible" file="shared_pseudocode.xml">BTypeCompatible</a> then
        let pc : bits(64) = ThisInstrAddr{}();
        <a link="func_AArch64_BranchTargetException_1" file="shared_pseudocode.xml">AArch64_BranchTargetException</a>(pc[51:0]);
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/ClearEventRegister" mylink="shared.functions.system.ClearEventRegister" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ClearEventRegister()
// ====================
// Clear the Event Register of this PE.

func <anchor link="func_ClearEventRegister_0">ClearEventRegister</anchor>()
begin
    <a link="global_EventRegister" file="shared_pseudocode.xml">EventRegister</a> = '0';
    return;
end;</pstext></ps>
    <ps name="shared/functions/system/ConditionHolds" mylink="shared.functions.system.ConditionHolds" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ConditionHolds()
// ================
// Return TRUE iff COND currently holds

func <anchor link="func_ConditionHolds_1">ConditionHolds</anchor>(cond : bits(4)) =&gt; boolean
begin
    // Evaluate base condition.
    var result : boolean;
    case cond[3:1] of
        when '000' =&gt; result = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.Z == '1');                          // EQ or NE
        when '001' =&gt; result = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.C == '1');                          // CS or CC
        when '010' =&gt; result = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.N == '1');                          // MI or PL
        when '011' =&gt; result = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.V == '1');                          // VS or VC
        when '100' =&gt; result = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.C == '1' &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.Z == '0');       // HI or LS
        when '101' =&gt; result = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.N == <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.V);                     // GE or LT
        when '110' =&gt; result = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.N == <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.V &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.Z == '0');  // GT or LE
        when '111' =&gt; result = TRUE;                                       // AL
    end;

    // Condition flag values in the set '111x' indicate always true
    // Otherwise, invert condition if necessary.
    if cond[0] == '1' &amp;&amp; cond != '1111' then
        result = !result;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/system/ConsumptionOfSpeculativeDataBarrier" mylink="shared.functions.system.ConsumptionOfSpeculativeDataBarrier" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ConsumptionOfSpeculativeDataBarrier()
// =====================================

impdef func ConsumptionOfSpeculativeDataBarrier()
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/system/CurrentInstrSet" mylink="shared.functions.system.CurrentInstrSet" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CurrentInstrSet()
// =================

readonly func <anchor link="func_CurrentInstrSet_0">CurrentInstrSet</anchor>() =&gt; <a link="type_InstrSet" file="shared_pseudocode.xml">InstrSet</a>
begin
    var result : <a link="type_InstrSet" file="shared_pseudocode.xml">InstrSet</a>;
    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then
        result = if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T == '0' then <a link="enum_InstrSet_A32" file="shared_pseudocode.xml">InstrSet_A32</a> else <a link="enum_InstrSet_T32" file="shared_pseudocode.xml">InstrSet_T32</a>;
        // PSTATE.J is RES0. Implementation of T32EE or Jazelle state not permitted.
    else
        result = <a link="enum_InstrSet_A64" file="shared_pseudocode.xml">InstrSet_A64</a>;
    end;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/system/CurrentSecurityState" mylink="shared.functions.system.CurrentSecurityState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CurrentSecurityState()
// ======================
// Returns the effective security state at the exception level based off current settings.

readonly func <anchor link="func_CurrentSecurityState_0">CurrentSecurityState</anchor>() =&gt; <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>
begin
    return <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
end;</pstext></ps>
    <ps name="shared/functions/system/DSBAlias" mylink="shared.functions.system.DSBAlias" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DSBAlias
// ========
// Aliases of DSB.

type <anchor link="type_DSBAlias">DSBAlias</anchor> of enumeration {<anchor link="enum_DSBAlias_SSBB">DSBAlias_SSBB</anchor>, <anchor link="enum_DSBAlias_PSSBB">DSBAlias_PSSBB</anchor>, <anchor link="enum_DSBAlias_DSB">DSBAlias_DSB</anchor>};</pstext></ps>
    <ps name="shared/functions/system/EL0" mylink="shared.functions.system.EL0" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EL0-3
// =====
// PSTATE.EL Exception level bits.

constant <anchor link="global_EL3">EL3</anchor> : bits(2) = '11';
constant <anchor link="global_EL2">EL2</anchor> : bits(2) = '10';
constant <anchor link="global_EL1">EL1</anchor> : bits(2) = '01';
constant <anchor link="global_EL0">EL0</anchor> : bits(2) = '00';</pstext></ps>
    <ps name="shared/functions/system/EL2Enabled" mylink="shared.functions.system.EL2Enabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EL2Enabled()
// ============
// Returns TRUE if EL2 is present and executing
// - with the PE in Non-secure state when Non-secure EL2 is implemented, or
// - with the PE in Realm state when Realm EL2 is implemented, or
// - with the PE in Secure state when Secure EL2 is implemented and enabled, or
// - when EL3 is not implemented.

readonly func <anchor link="func_EL2Enabled_0">EL2Enabled</anchor>() =&gt; boolean
begin
    var scr_ns : bit;
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
            scr_ns = SCR().NS;
        else
            scr_ns = SCR_EL3().NS;
        end;
    end;
    return <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; (!<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || scr_ns == '1' || <a link="func_IsSecureEL2Enabled_0" file="shared_pseudocode.xml">IsSecureEL2Enabled</a>());
end;</pstext></ps>
    <ps name="shared/functions/system/EL3SDDUndef" mylink="shared.functions.system.EL3SDDUndef" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EL3SDDUndef()
// =============
// Returns TRUE if in Debug state and EDSCR.SDD is set.

func <anchor link="func_EL3SDDUndef_0">EL3SDDUndef</anchor>() =&gt; boolean
begin
    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() &amp;&amp; EDSCR().SDD == '1' then
        assert (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>  &amp;&amp;
                  (IsFeatureImplemented(FEAT_RME) || <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() != <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>));
        return TRUE;
    else
        return FALSE;
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/EL3SDDUndefPriority" mylink="shared.functions.system.EL3SDDUndefPriority" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EL3SDDUndefPriority()
// =====================
// Returns TRUE if in Debug state, EDSCR.SDD is set, and an EL3 trap by an
// EL3 control register has priority over other traps.
// The IMPLEMENTATION DEFINED priority may be different for each case.

func <anchor link="func_EL3SDDUndefPriority_0">EL3SDDUndefPriority</anchor>() =&gt; boolean
begin
    return <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() &amp;&amp; ImpDefBool(&quot;EL3 trap priority when SDD == '1'&quot;);
end;</pstext></ps>
    <ps name="shared/functions/system/ELFromM32" mylink="shared.functions.system.ELFromM32" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ELFromM32()
// ===========

func <anchor link="func_ELFromM32_1">ELFromM32</anchor>(mode : bits(5)) =&gt; (boolean,bits(2))
begin
    // Convert an AArch32 mode encoding to an Exception level.
    // Returns (valid,EL):
    //   'valid' is TRUE if 'mode[4:0]' encodes a mode that is both valid for this implementation
    //           and the current value of SCR.NS/SCR_EL3.NS.
    //   'EL'    is the Exception level decoded from 'mode'.
    var el : bits(2);
    // Check for modes that are not valid for this implementation
    var valid : boolean = !<a link="func_BadMode_1" file="shared_pseudocode.xml">BadMode</a>(mode);
    let effective_nse_ns : bits(2) = <a link="func_EffectiveSCR_EL3_NSE_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NSE</a>() :: <a link="func_EffectiveSCR_EL3_NS_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NS</a>();

    case mode of
        when <a link="global_M32_Monitor" file="shared_pseudocode.xml">M32_Monitor</a> =&gt;
            el = <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
        when <a link="global_M32_Hyp" file="shared_pseudocode.xml">M32_Hyp</a> =&gt;
            el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
        when <a link="global_M32_FIQ" file="shared_pseudocode.xml">M32_FIQ</a>, <a link="global_M32_IRQ" file="shared_pseudocode.xml">M32_IRQ</a>, <a link="global_M32_Svc" file="shared_pseudocode.xml">M32_Svc</a>, <a link="global_M32_Abort" file="shared_pseudocode.xml">M32_Abort</a>, <a link="global_M32_Undef" file="shared_pseudocode.xml">M32_Undef</a>, <a link="global_M32_System" file="shared_pseudocode.xml">M32_System</a> =&gt;
            // If EL3 is implemented and using AArch32, then these modes are EL3 modes in Secure
            // state, and EL1 modes in Non-secure state. If EL3 is not implemented or is using
            // AArch64, then these modes are EL1 modes.
            el = (if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() &amp;&amp; SCR().NS == '0' then <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> else <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>);
        when <a link="global_M32_User" file="shared_pseudocode.xml">M32_User</a> =&gt;
            el = <a link="global_EL0" file="shared_pseudocode.xml">EL0</a>;
        otherwise =&gt;
            valid = FALSE;           // Passed an illegal mode value
    end;

    if valid &amp;&amp; el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> &amp;&amp; <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR().NS == '0' then
            valid = FALSE; // EL2 only valid in Non-secure state in AArch32
        elsif !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().NS == '0' then
            valid = FALSE; // EL2 only valid in Non-secure state in AArch32
        end;
    elsif valid &amp;&amp; IsFeatureImplemented(FEAT_RME) &amp;&amp; effective_nse_ns == '10' then
        valid = FALSE;               // Illegal Exception Return from EL3 if SCR_EL3.[NSE,NS]
                                     // selects a reserved encoding
    end;

    if !valid then el = ARBITRARY : bits(2); end;
    return (valid, el);
end;</pstext></ps>
    <ps name="shared/functions/system/ELFromSPSR" mylink="shared.functions.system.ELFromSPSR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ELFromSPSR()
// ============

// Convert an SPSR value encoding to an Exception level.
// Returns (valid,EL):
//   'valid' is TRUE if 'spsr[4:0]' encodes a valid mode for the current state.
//   'EL'    is the Exception level decoded from 'spsr'.

func <anchor link="func_ELFromSPSR_2">ELFromSPSR</anchor>{N}(spsr : bits(N)) =&gt; (boolean,bits(2))
begin
    var el : bits(2);
    var valid : boolean;
    if spsr[4] == '0' then      // AArch64 state
        el = spsr[3:2];
        let effective_nse_ns : bits(2) = <a link="func_EffectiveSCR_EL3_NSE_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NSE</a>() :: <a link="func_EffectiveSCR_EL3_NS_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NS</a>();
        if !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then
            valid = FALSE;      // No AArch64 support
        elsif !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(el) then
            valid = FALSE;      // Exception level not implemented
        elsif spsr[1] == '1' then
            valid = FALSE;      // M[1] must be 0
        elsif el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; spsr[0] == '1' then
            valid = FALSE;      // for EL0, M[0] must be 0
        elsif IsFeatureImplemented(FEAT_RME) &amp;&amp; el != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; effective_nse_ns == '10' then
            valid = FALSE;      // Only EL3 valid in Root state
        elsif el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> &amp;&amp; <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; !<a link="func_IsSecureEL2Enabled_0" file="shared_pseudocode.xml">IsSecureEL2Enabled</a>() &amp;&amp; <a link="func_EffectiveSCR_EL3_NS_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NS</a>() == '0' then
            valid = FALSE;      // Unless Secure EL2 is enabled, EL2 valid only in Non-secure state
        else
            valid = TRUE;
        end;
    elsif <a link="func_HaveAArch32_0" file="shared_pseudocode.xml">HaveAArch32</a>() then    // AArch32 state
        (valid, el) = <a link="func_ELFromM32_1" file="shared_pseudocode.xml">ELFromM32</a>(spsr[4:0]);
    else
        valid = FALSE;
    end;

    if !valid then el = ARBITRARY : bits(2); end;
    return (valid,el);
end;</pstext></ps>
    <ps name="shared/functions/system/ELIsInHost" mylink="shared.functions.system.ELIsInHost" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ELIsInHost()
// ============

readonly func <anchor link="func_ELIsInHost_1">ELIsInHost</anchor>(el : bits(2)) =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_VHE) || <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        return FALSE;
    end;
    case el of
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            return FALSE;
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            return <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; <a link="func_EffectiveHCR_EL2_E2H_0" file="shared_pseudocode.xml">EffectiveHCR_EL2_E2H</a>() == '1';
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;
            return FALSE;
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            return <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; <a link="func_EffectiveHCR_EL2_E2H_0" file="shared_pseudocode.xml">EffectiveHCR_EL2_E2H</a>()::HCR_EL2().TGE == '11';
        otherwise =&gt;
            unreachable;
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/ELStateUsingAArch32" mylink="shared.functions.system.ELStateUsingAArch32" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ELStateUsingAArch32()
// =====================

readonly func <anchor link="func_ELStateUsingAArch32_2">ELStateUsingAArch32</anchor>(el : bits(2), secure : boolean) =&gt; boolean
begin
    // See ELStateUsingAArch32K() for description. Must only be called in circumstances where
    // result is valid (typically, that means 'el IN {EL1,EL2,EL3}').
    let (known, aarch32) : (boolean, boolean) = <a link="func_ELStateUsingAArch32K_2" file="shared_pseudocode.xml">ELStateUsingAArch32K</a>(el, secure);
    assert known;
    return aarch32;
end;</pstext></ps>
    <ps name="shared/functions/system/ELStateUsingAArch32K" mylink="shared.functions.system.ELStateUsingAArch32K" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ELStateUsingAArch32K()
// ======================
// Returns (known, aarch32):
//   'known'   is FALSE for EL0 if the current Exception level is not EL0 and EL1 is
//             using AArch64, since it cannot determine the state of EL0; TRUE otherwise.
//   'aarch32' is TRUE if the specified Exception level is using AArch32; FALSE otherwise.

readonly func <anchor link="func_ELStateUsingAArch32K_2">ELStateUsingAArch32K</anchor>(el : bits(2), secure : boolean) =&gt; (boolean, boolean)
begin
    assert <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(el);

    if !<a link="func_HaveAArch32EL_1" file="shared_pseudocode.xml">HaveAArch32EL</a>(el) then
        return (TRUE, FALSE);   // Exception level is using AArch64
    elsif secure &amp;&amp; el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
        return (TRUE, FALSE);   // Secure EL2 is using AArch64
    elsif !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then
        return (TRUE, TRUE);    // Highest Exception level, therefore all levels are using AArch32
    end;

    // Remainder of function deals with the interprocessing cases when highest
    // Exception level is using AArch64.

    if el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then
        return (TRUE, FALSE);
    end;

    if (<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_EffectiveSCR_EL3_RW_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_RW</a>() == '0' &amp;&amp;
          (!secure || !IsFeatureImplemented(FEAT_SEL2) || SCR_EL3().EEL2 == '0')) then
        // AArch32 below EL3.
        return (TRUE, TRUE);
    end;

    if el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
        return (TRUE, FALSE);
    end;

    if (<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; !<a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) &amp;&amp; HCR_EL2().RW == '0' &amp;&amp;
          (!secure || (IsFeatureImplemented(FEAT_SEL2) &amp;&amp; SCR_EL3().EEL2 == '1'))) then
        // AArch32 below EL2.
        return (TRUE, TRUE);
    end;

    if el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> then
        return (TRUE, FALSE);
    end;

    // The execution state of EL0 is only known from PSTATE.nRW when executing at EL0.
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        return (TRUE, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.nRW == '1');
    else
        return (FALSE, ARBITRARY : boolean);
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/ELUsingAArch32" mylink="shared.functions.system.ELUsingAArch32" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ELUsingAArch32()
// ================

readonly func <anchor link="func_ELUsingAArch32_1">ELUsingAArch32</anchor>(el : bits(2)) =&gt; boolean
                                     recurselimit 1
begin
    return <a link="func_ELStateUsingAArch32_2" file="shared_pseudocode.xml">ELStateUsingAArch32</a>(el, <a link="func_IsSecureBelowEL3_0" file="shared_pseudocode.xml">IsSecureBelowEL3</a>());
end;</pstext></ps>
    <ps name="shared/functions/system/ELUsingAArch32K" mylink="shared.functions.system.ELUsingAArch32K" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ELUsingAArch32K()
// =================

readonly func <anchor link="func_ELUsingAArch32K_1">ELUsingAArch32K</anchor>(el : bits(2)) =&gt; (boolean,boolean)
begin
    return <a link="func_ELStateUsingAArch32K_2" file="shared_pseudocode.xml">ELStateUsingAArch32K</a>(el, <a link="func_IsSecureBelowEL3_0" file="shared_pseudocode.xml">IsSecureBelowEL3</a>());
end;</pstext></ps>
    <ps name="shared/functions/system/EffectiveEA" mylink="shared.functions.system.EffectiveEA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveEA()
// =============
// Returns effective SCR_EL3.EA value

readonly func <anchor link="func_EffectiveEA_0">EffectiveEA</anchor>() =&gt; bit
begin
    if !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then
        return '0';
    else
        return if <a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then SCR_EL3().EA else SCR().EA;
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/EffectiveHCR_EL2_E2H" mylink="shared.functions.system.EffectiveHCR_EL2_E2H" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveHCR_EL2_E2H()
// ======================
// Return the Effective HCR_EL2.E2H value.

readonly func <anchor link="func_EffectiveHCR_EL2_E2H_0">EffectiveHCR_EL2_E2H</anchor>() =&gt; bit
begin
    if !IsFeatureImplemented(FEAT_VHE) then
        return '0';
    end;

    if !IsFeatureImplemented(FEAT_E2H0) then
        return '1';
    end;

    return HCR_EL2().E2H;
end;</pstext></ps>
    <ps name="shared/functions/system/EffectiveHCR_EL2_NVx" mylink="shared.functions.system.EffectiveHCR_EL2_NVx" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveHCR_EL2_NVx()
// ======================
// Return the Effective value of HCR_EL2.[NV2,NV1,NV].

func <anchor link="func_EffectiveHCR_EL2_NVx_0">EffectiveHCR_EL2_NVx</anchor>() =&gt; bits(3)
begin
    if !<a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() || !IsFeatureImplemented(FEAT_NV) then
        return '000';
    end;

    var nv1 : bit = HCR_EL2().NV1;
    if (!IsFeatureImplemented(FEAT_E2H0) &amp;&amp;
          ImpDefBool(&quot;HCR_EL2.NV1 is implemented as RAZ&quot;)) then
        nv1 = '0';
    end;

    if HCR_EL2().NV == '0' then
        if nv1 == '1' then
            case ConstrainUnpredictable(<a link="enum_Unpredictable_NVNV1" file="shared_pseudocode.xml">Unpredictable_NVNV1</a>) of
                when <a link="enum_Constraint_NVNV1_00" file="shared_pseudocode.xml">Constraint_NVNV1_00</a> =&gt; return '000';
                when <a link="enum_Constraint_NVNV1_01" file="shared_pseudocode.xml">Constraint_NVNV1_01</a> =&gt; return '010';
                when <a link="enum_Constraint_NVNV1_11" file="shared_pseudocode.xml">Constraint_NVNV1_11</a> =&gt; return '011';
            end;
        else
            return '000';
        end;
    end;

    if !IsFeatureImplemented(FEAT_NV2) then
        return '0' :: nv1 :: '1';
    end;

    var nv2 : bit = HCR_EL2().NV2;
    if (nv2 == '0' &amp;&amp; ImpDefBool(
          &quot;Programming HCR_EL2.&lt;NV,NV2&gt; to '10' behaves as '11'&quot;)) then
        nv2 = '1';
    end;

    return nv2 :: nv1 :: '1';
end;</pstext></ps>
    <ps name="shared/functions/system/EffectiveSCR_EL3_FIQ" mylink="shared.functions.system.EffectiveSCR_EL3_FIQ" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveSCR_EL3_FIQ()
// ======================
// Returns effective SCR_EL3().FIQ value

readonly func <anchor link="func_EffectiveSCR_EL3_FIQ_0">EffectiveSCR_EL3_FIQ</anchor>() =&gt; bit
begin
    if !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        return '0';
    end;
    return SCR_EL3().FIQ;
end;</pstext></ps>
    <ps name="shared/functions/system/EffectiveSCR_EL3_IRQ" mylink="shared.functions.system.EffectiveSCR_EL3_IRQ" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveSCR_EL3_IRQ()
// ======================
// Returns effective SCR_EL3().IRQ value

readonly func <anchor link="func_EffectiveSCR_EL3_IRQ_0">EffectiveSCR_EL3_IRQ</anchor>() =&gt; bit
begin
    if !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) || <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        return '0';
    end;
    return SCR_EL3().IRQ;
end;</pstext></ps>
    <ps name="shared/functions/system/EffectiveSCR_EL3_NS" mylink="shared.functions.system.EffectiveSCR_EL3_NS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveSCR_EL3_NS()
// =====================
// Return Effective SCR_EL3.NS value.

readonly func <anchor link="func_EffectiveSCR_EL3_NS_0">EffectiveSCR_EL3_NS</anchor>() =&gt; bit
begin
    if !<a link="func_HaveSecureState_0" file="shared_pseudocode.xml">HaveSecureState</a>() then
        return '1';
    elsif !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        return '0';
    elsif <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        return SCR().NS;
    else
        return SCR_EL3().NS;
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/EffectiveSCR_EL3_NSE" mylink="shared.functions.system.EffectiveSCR_EL3_NSE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveSCR_EL3_NSE()
// ======================
// Return Effective SCR_EL3.NSE value.

readonly func <anchor link="func_EffectiveSCR_EL3_NSE_0">EffectiveSCR_EL3_NSE</anchor>() =&gt; bit
begin
    return if !IsFeatureImplemented(FEAT_RME) then '0' else SCR_EL3().NSE;
end;</pstext></ps>
    <ps name="shared/functions/system/EffectiveSCR_EL3_RW" mylink="shared.functions.system.EffectiveSCR_EL3_RW" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveSCR_EL3_RW()
// =====================
// Returns effective SCR_EL3.RW value

readonly func <anchor link="func_EffectiveSCR_EL3_RW_0">EffectiveSCR_EL3_RW</anchor>() =&gt; bit
begin
    if !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then
        return '0';
    end;
    if !<a link="func_HaveAArch32EL_1" file="shared_pseudocode.xml">HaveAArch32EL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; !<a link="func_HaveAArch32EL_1" file="shared_pseudocode.xml">HaveAArch32EL</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        return '1';
    end;
    if <a link="func_HaveAArch32EL_1" file="shared_pseudocode.xml">HaveAArch32EL</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then
        if !<a link="func_HaveAArch32EL_1" file="shared_pseudocode.xml">HaveAArch32EL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; <a link="func_EffectiveSCR_EL3_NS_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NS</a>() == '1' then
            return '1';
        end;
        if (IsFeatureImplemented(FEAT_SEL2) &amp;&amp; SCR_EL3().EEL2 == '1' &amp;&amp;
              <a link="func_EffectiveSCR_EL3_NS_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NS</a>() == '0') then
            return '1';
        end;
    end;
    return SCR_EL3().RW;
end;</pstext></ps>
    <ps name="shared/functions/system/EffectiveTGE" mylink="shared.functions.system.EffectiveTGE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveTGE()
// ==============
// Returns effective TGE value

func <anchor link="func_EffectiveTGE_0">EffectiveTGE</anchor>() =&gt; bit
begin
    if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        return if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then HCR().TGE else HCR_EL2().TGE;
    else
        return '0';        // Effective value of TGE is zero
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/EndOfInstruction" mylink="shared.functions.system.EndOfInstruction" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EndOfInstruction()
// ==================
// Terminate processing of the current instruction.

noreturn impdef func EndOfInstruction(EndReason : <a link="type_EndOfInstructionReason" file="shared_pseudocode.xml">EndOfInstructionReason</a>)
begin
    throw EndOfInstructionException{reason=EndReason};
end;</pstext></ps>
    <ps name="shared/functions/system/EndOfInstructionException" mylink="shared.functions.system.EndOfInstructionException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EndOfInstructionException
// =========================
// End of Instruction exception type.

type <anchor link="type_EndOfInstructionException">EndOfInstructionException</anchor> of exception {
    reason : <a link="type_EndOfInstructionReason" file="shared_pseudocode.xml">EndOfInstructionReason</a>
};</pstext></ps>
    <ps name="shared/functions/system/EndOfInstructionReason" mylink="shared.functions.system.EndOfInstructionReason" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EndOfInstructionReason
// ======================

type <anchor link="type_EndOfInstructionReason">EndOfInstructionReason</anchor> of enumeration {
    <anchor link="enum_EndOfInstructionReason_Retired">EndOfInstructionReason_Retired</anchor>,
    <anchor link="enum_EndOfInstructionReason_Exception">EndOfInstructionReason_Exception</anchor>
};</pstext></ps>
    <ps name="shared/functions/system/EnterLowPowerState" mylink="shared.functions.system.EnterLowPowerState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EnterLowPowerState()
// ====================
// PE enters a low-power state.


impdef func EnterLowPowerState()
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/system/EventRegister" mylink="shared.functions.system.EventRegister" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EventRegister
// =============
// Event Register for this PE.

var <anchor link="global_EventRegister">EventRegister</anchor> : bits(1);</pstext></ps>
    <ps name="shared/functions/system/ExceptionalOccurrenceTargetState" mylink="shared.functions.system.ExceptionalOccurrenceTargetState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExceptionalOccurrenceTargetState
// ================================
// Enumeration to represent the target state of an Exceptional Occurrence.
// The Exceptional Occurrence can be either Exception or Debug State entry.

type <anchor link="type_ExceptionalOccurrenceTargetState">ExceptionalOccurrenceTargetState</anchor> of enumeration {
    <anchor link="enum_AArch32_NonDebugState">AArch32_NonDebugState</anchor>,
    <anchor link="enum_AArch64_NonDebugState">AArch64_NonDebugState</anchor>,
    <anchor link="enum_DebugState">DebugState</anchor>
};</pstext></ps>
    <ps name="shared/functions/system/ExecuteAsNOP" mylink="shared.functions.system.ExecuteAsNOP" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExecuteAsNOP()
// ==============

func <anchor link="func_ExecuteAsNOP_0">ExecuteAsNOP</anchor>()
begin
    EndOfInstruction(<a link="enum_EndOfInstructionReason_Retired" file="shared_pseudocode.xml">EndOfInstructionReason_Retired</a>);
end;</pstext></ps>
    <ps name="shared/functions/system/FIQPending" mylink="shared.functions.system.FIQPending" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FIQPending()
// ============
// Returns a tuple indicating if there is any pending physical FIQ
// and if the pending FIQ has superpriority.

impdef func <anchor link="func_FIQPending_0">FIQPending</anchor>() =&gt; (boolean, boolean)
begin
    return (FALSE, FALSE);
end;</pstext></ps>
    <ps name="shared/functions/system/GetAccumulatedFPExceptions" mylink="shared.functions.system.GetAccumulatedFPExceptions" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetAccumulatedFPExceptions()
// ============================
// Returns FP exceptions accumulated by the PE.

impdef func <anchor link="func_GetAccumulatedFPExceptions_0">GetAccumulatedFPExceptions</anchor>() =&gt; bits(8)
begin
    return ARBITRARY : bits(8);
end;</pstext></ps>
    <ps name="shared/functions/system/GetLoadStoreType" mylink="shared.functions.system.GetLoadStoreType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetLoadStoreType()
// ==================
// Returns the Load/Store Type. Used when a Translation fault,
// Access flag fault, or Permission fault generates a Data Abort.

impdef func <anchor link="func_GetLoadStoreType_0">GetLoadStoreType</anchor>() =&gt; bits(2)
begin
    return ARBITRARY : bits(2);
end;</pstext></ps>
    <ps name="shared/functions/system/GetPSRFromPSTATE" mylink="shared.functions.system.GetPSRFromPSTATE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetPSRFromPSTATE()
// ==================
// Return a PSR value which represents the current PSTATE

func <anchor link="func_GetPSRFromPSTATE_2">GetPSRFromPSTATE</anchor>{N}(targetELState : <a link="type_ExceptionalOccurrenceTargetState" file="shared_pseudocode.xml">ExceptionalOccurrenceTargetState</a>) =&gt; bits(N)
begin
    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; targetELState == <a link="enum_AArch32_NonDebugState" file="shared_pseudocode.xml">AArch32_NonDebugState</a> then
        assert N == 32;
    else
        assert N == 64;
    end;

    var spsr : bits(N) = Zeros{};
    if IsFeatureImplemented(FEAT_UINJ) &amp;&amp; targetELState == <a link="enum_DebugState" file="shared_pseudocode.xml">DebugState</a> then
        spsr[36] = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.UINJ;
    end;
    spsr[31:28] = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.[N,Z,C,V];
    if IsFeatureImplemented(FEAT_PAN) then spsr[22] = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN; end;
    spsr[20]     = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL;
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.nRW == '1' then                           // AArch32 state
        spsr[27]     = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.Q;
        spsr[26:25]  = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT[1:0];
        if IsFeatureImplemented(FEAT_SSBS) then spsr[23] = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SSBS; end;
        if IsFeatureImplemented(FEAT_DIT) then
            if targetELState == <a link="enum_AArch32_NonDebugState" file="shared_pseudocode.xml">AArch32_NonDebugState</a> then
                spsr[21] = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.DIT;
            else                                        // AArch64_NonDebugState or DebugState
                spsr[24] = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.DIT;
            end;
        end;
        if targetELState IN {<a link="enum_AArch64_NonDebugState" file="shared_pseudocode.xml">AArch64_NonDebugState</a>, <a link="enum_DebugState" file="shared_pseudocode.xml">DebugState</a>} then
            spsr[21] = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SS;
        end;
        spsr[19:16]  = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.GE;
        spsr[15:10]  = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT[7:2];
        spsr[9]      = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.E;
        spsr[8:6]    = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.[A,I,F];                  // No PSTATE.D in AArch32 state
        spsr[5]      = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T;
        assert <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M[4] == <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.nRW;               // bit [4] is the discriminator
        spsr[4:0]    = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.M;
    else                                                // AArch64 state
        if IsFeatureImplemented(FEAT_PAuth_LR) then spsr[35] = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PACM; end;
        if IsFeatureImplemented(FEAT_GCS) then spsr[34] = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EXLOCK; end;
        if (IsFeatureImplemented(FEAT_EBEP) || IsFeatureImplemented(FEAT_SPE_EXC) ||
              IsFeatureImplemented(FEAT_TRBE_EXC)) then
            spsr[32] = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PM;
        end;
        if IsFeatureImplemented(FEAT_MTE) then spsr[25] = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.TCO; end;
        if IsFeatureImplemented(FEAT_DIT) then spsr[24] = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.DIT; end;
        if IsFeatureImplemented(FEAT_UAO) then spsr[23] = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.UAO; end;
        spsr[21]    = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SS;
        if IsFeatureImplemented(FEAT_NMI) then spsr[13] = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.ALLINT; end;
        if IsFeatureImplemented(FEAT_SSBS) then spsr[12] = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SSBS; end;
        if IsFeatureImplemented(FEAT_BTI) then spsr[11:10] = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.BTYPE; end;
        spsr[9:6]    = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.[D,A,I,F];
        spsr[4]      = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.nRW;
        spsr[3:2]    = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL;
        spsr[0]      = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SP;
    end;
    return spsr;
end;</pstext></ps>
    <ps name="shared/functions/system/HaveAArch32" mylink="shared.functions.system.HaveAArch32" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HaveAArch32()
// =============
// Return TRUE if AArch32 state is supported at at least EL0.

readonly func <anchor link="func_HaveAArch32_0">HaveAArch32</anchor>() =&gt; boolean
begin
    return IsFeatureImplemented(FEAT_AA32EL0);
end;</pstext></ps>
    <ps name="shared/functions/system/HaveAArch32EL" mylink="shared.functions.system.HaveAArch32EL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HaveAArch32EL()
// ===============
// Return TRUE if Exception level 'el' supports AArch32 in this implementation

readonly func <anchor link="func_HaveAArch32EL_1">HaveAArch32EL</anchor>(el : bits(2)) =&gt; boolean
begin
    case el of
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt; return IsFeatureImplemented(FEAT_AA32EL0);
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt; return IsFeatureImplemented(FEAT_AA32EL1);
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt; return IsFeatureImplemented(FEAT_AA32EL2);
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt; return IsFeatureImplemented(FEAT_AA32EL3);
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/HaveAArch64" mylink="shared.functions.system.HaveAArch64" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HaveAArch64()
// =============
// Return TRUE if the highest Exception level is using AArch64 state.

readonly func <anchor link="func_HaveAArch64_0">HaveAArch64</anchor>() =&gt; boolean
begin
    return (IsFeatureImplemented(FEAT_AA64EL0)
            || IsFeatureImplemented(FEAT_AA64EL1)
            || IsFeatureImplemented(FEAT_AA64EL2)
            || IsFeatureImplemented(FEAT_AA64EL3)
            );
end;</pstext></ps>
    <ps name="shared/functions/system/HaveEL" mylink="shared.functions.system.HaveEL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HaveEL()
// ========
// Return TRUE if Exception level 'el' is supported

readonly func <anchor link="func_HaveEL_1">HaveEL</anchor>(el : bits(2)) =&gt; boolean
begin
    case el of
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>,<a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
            return TRUE;                         // EL1 and EL0 must exist
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            return IsFeatureImplemented(FEAT_AA64EL2) || IsFeatureImplemented(FEAT_AA32EL2);
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            return IsFeatureImplemented(FEAT_AA64EL3) || IsFeatureImplemented(FEAT_AA32EL3);
        otherwise =&gt;
            unreachable;
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/HaveELUsingSecurityState" mylink="shared.functions.system.HaveELUsingSecurityState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HaveELUsingSecurityState()
// ==========================
// Returns TRUE if Exception level 'el' with Security state 'secure' is supported,
// FALSE otherwise.

readonly func <anchor link="func_HaveELUsingSecurityState_2">HaveELUsingSecurityState</anchor>(el : bits(2), secure : boolean) =&gt; boolean
begin

    case el of
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;
            assert secure;
            return <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;
            if secure then
                return <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; IsFeatureImplemented(FEAT_SEL2);
            else
                return <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
            end;
        otherwise =&gt;
            return (<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) ||
                    (secure == ImpDefBool(&quot;Secure-only implementation&quot;)));
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/HaveSecureState" mylink="shared.functions.system.HaveSecureState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HaveSecureState()
// =================
// Return TRUE if Secure State is supported.

readonly func <anchor link="func_HaveSecureState_0">HaveSecureState</anchor>() =&gt; boolean
begin
    if !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        return <a link="func_SecureOnlyImplementation_0" file="shared_pseudocode.xml">SecureOnlyImplementation</a>();
    end;
    if IsFeatureImplemented(FEAT_RME) &amp;&amp; !IsFeatureImplemented(FEAT_SEL2) then
        return FALSE;
    end;
    return TRUE;
end;</pstext></ps>
    <ps name="shared/functions/system/HighestEL" mylink="shared.functions.system.HighestEL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HighestEL()
// ===========
// Returns the highest implemented Exception level.

readonly func <anchor link="func_HighestEL_0">HighestEL</anchor>() =&gt; bits(2)
begin
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        return <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        return <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    else
        return <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/Hint_CLRBHB" mylink="shared.functions.system.Hint_CLRBHB" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Hint_CLRBHB()
// =============
// Provides a hint to clear the branch history for the current context.

impdef func Hint_CLRBHB()
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/system/Hint_DGH" mylink="shared.functions.system.Hint_DGH" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Hint_DGH()
// ==========
// Provides a hint to close any gathering occurring within the implementation.

impdef func Hint_DGH()
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/system/Hint_StoreShared" mylink="shared.functions.system.Hint_StoreShared" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Hint_StoreShared()
// ==================
// Provides a hint that if the next instruction is an explicit write it is being waited on by
// observers and as such the data should propagate to them with minimum latency.
// A stream value of FALSE indicates KEEP whilst a value of TRUE indicates STRM.

impdef func Hint_StoreShared(stream : boolean)
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/system/Hint_WFE" mylink="shared.functions.system.Hint_WFE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Hint_WFE()
// ==========
// Provides a hint indicating that the PE can enter a low-power state and
// remain there until a wakeup event occurs.

func <anchor link="func_Hint_WFE_0">Hint_WFE</anchor>()
begin
    if <a link="func_IsEventRegisterSet_0" file="shared_pseudocode.xml">IsEventRegisterSet</a>() then
        <a link="func_ClearEventRegister_0" file="shared_pseudocode.xml">ClearEventRegister</a>();
        return;
    end;

    var trap : boolean;
    var target_el : bits(2);
    (trap, target_el) = <a link="func_AArch64_CheckForWFxTrap_1" file="shared_pseudocode.xml">AArch64_CheckForWFxTrap</a>(<a link="enum_WFxType_WFE" file="shared_pseudocode.xml">WFxType_WFE</a>);
    if trap then
        if IsFeatureImplemented(FEAT_TWED) then
            // Determine if trap delay is enabled and delay amount
            var delay_enabled : boolean;
            var delay : integer;
            (delay_enabled, delay) = <a link="func_WFETrapDelay_1" file="shared_pseudocode.xml">WFETrapDelay</a>(target_el);
            if <a link="func_WaitForEventUntilDelay_2" file="shared_pseudocode.xml">WaitForEventUntilDelay</a>(delay_enabled, delay) then
                // Event arrived before delay
                return;
            end;
        end;

        // Proceed with trapping
        if target_el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then
            Undefined();
        else
            <a link="func_AArch64_WFxTrap_2" file="shared_pseudocode.xml">AArch64_WFxTrap</a>(<a link="enum_WFxType_WFE" file="shared_pseudocode.xml">WFxType_WFE</a>, target_el);
        end;
    else
        <a link="func_WaitForEvent_0" file="shared_pseudocode.xml">WaitForEvent</a>();
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/Hint_WFET" mylink="shared.functions.system.Hint_WFET" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Hint_WFET()
// ===========
// Provides a hint indicating that the PE can enter a low-power state
// and remain there until a wakeup event occurs or, for WFET,  a local
// timeout event is generated when the virtual timer value equals or
// exceeds the supplied threshold value.

func <anchor link="func_Hint_WFET_1">Hint_WFET</anchor>(localtimeout : integer)
begin
    if <a link="func_IsEventRegisterSet_0" file="shared_pseudocode.xml">IsEventRegisterSet</a>() then
        <a link="func_ClearEventRegister_0" file="shared_pseudocode.xml">ClearEventRegister</a>();
        return;
    end;

    if IsFeatureImplemented(FEAT_WFxT) &amp;&amp; <a link="func_LocalTimeoutEvent_1" file="shared_pseudocode.xml">LocalTimeoutEvent</a>(localtimeout) then
        // No further operation if the local timeout has expired.
        EndOfInstruction(<a link="enum_EndOfInstructionReason_Retired" file="shared_pseudocode.xml">EndOfInstructionReason_Retired</a>);
    end;

    var trap : boolean;
    var target_el : bits(2);
    (trap, target_el) = <a link="func_AArch64_CheckForWFxTrap_1" file="shared_pseudocode.xml">AArch64_CheckForWFxTrap</a>(<a link="enum_WFxType_WFET" file="shared_pseudocode.xml">WFxType_WFET</a>);
    if trap then
        if IsFeatureImplemented(FEAT_TWED) then
            // Determine if trap delay is enabled and delay amount
            var delay_enabled : boolean;
            var delay : integer;
            (delay_enabled, delay) = <a link="func_WFETrapDelay_1" file="shared_pseudocode.xml">WFETrapDelay</a>(target_el);
            if <a link="func_WaitForEventUntilDelay_2" file="shared_pseudocode.xml">WaitForEventUntilDelay</a>(delay_enabled, delay) then
                // Event arrived before the delay expired
                return;
            end;
        end;

        // Proceed with trapping
        if target_el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then
            Undefined();
        else
            <a link="func_AArch64_WFxTrap_2" file="shared_pseudocode.xml">AArch64_WFxTrap</a>(<a link="enum_WFxType_WFET" file="shared_pseudocode.xml">WFxType_WFET</a>, target_el);
        end;
    else
        <a link="func_WaitForEvent_1" file="shared_pseudocode.xml">WaitForEvent</a>(localtimeout);
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/Hint_WFI" mylink="shared.functions.system.Hint_WFI" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Hint_WFI()
// ==========
// Provides a hint indicating that the PE can enter a low-power state and
// remain there until a wakeup event occurs.

func <anchor link="func_Hint_WFI_0">Hint_WFI</anchor>()
begin
    if <a link="func_AArch64_InterruptPending_0" file="shared_pseudocode.xml">AArch64_InterruptPending</a>() then
        // No further operation if an interrupt is pending.
        EndOfInstruction(<a link="enum_EndOfInstructionReason_Retired" file="shared_pseudocode.xml">EndOfInstructionReason_Retired</a>);
    end;

    var trap : boolean;
    var target_el : bits(2);
    (trap, target_el) = <a link="func_AArch64_CheckForWFxTrap_1" file="shared_pseudocode.xml">AArch64_CheckForWFxTrap</a>(<a link="enum_WFxType_WFI" file="shared_pseudocode.xml">WFxType_WFI</a>);
    if trap then
        if target_el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then
            Undefined();
        end;
        <a link="func_AArch64_WFxTrap_2" file="shared_pseudocode.xml">AArch64_WFxTrap</a>(<a link="enum_WFxType_WFI" file="shared_pseudocode.xml">WFxType_WFI</a>, target_el);
    else
        <a link="func_WaitForInterrupt_0" file="shared_pseudocode.xml">WaitForInterrupt</a>();
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/Hint_WFIT" mylink="shared.functions.system.Hint_WFIT" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Hint_WFIT()
// ===========
// Provides a hint indicating that the PE can enter a low-power state and
// remain there until a wakeup event occurs or, for WFIT, a local timeout
// event is generated when the virtual timer value equals or exceeds the
// supplied threshold value.

func <anchor link="func_Hint_WFIT_1">Hint_WFIT</anchor>(localtimeout : integer)
begin
    if (<a link="func_AArch64_InterruptPending_0" file="shared_pseudocode.xml">AArch64_InterruptPending</a>() || (IsFeatureImplemented(FEAT_WFxT) &amp;&amp;
          <a link="func_LocalTimeoutEvent_1" file="shared_pseudocode.xml">LocalTimeoutEvent</a>(localtimeout))) then
        // No further operation if an interrupt is pending or the local timeout has expired.
        EndOfInstruction(<a link="enum_EndOfInstructionReason_Retired" file="shared_pseudocode.xml">EndOfInstructionReason_Retired</a>);
    end;

    var trap : boolean;
    var target_el : bits(2);
    (trap, target_el) = <a link="func_AArch64_CheckForWFxTrap_1" file="shared_pseudocode.xml">AArch64_CheckForWFxTrap</a>(<a link="enum_WFxType_WFIT" file="shared_pseudocode.xml">WFxType_WFIT</a>);
    if trap then
        if target_el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; <a link="func_EL3SDDUndef_0" file="shared_pseudocode.xml">EL3SDDUndef</a>() then
            Undefined();
        end;
        <a link="func_AArch64_WFxTrap_2" file="shared_pseudocode.xml">AArch64_WFxTrap</a>(<a link="enum_WFxType_WFIT" file="shared_pseudocode.xml">WFxType_WFIT</a>, target_el);
    else
        <a link="func_WaitForInterrupt_1" file="shared_pseudocode.xml">WaitForInterrupt</a>(localtimeout);
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/Hint_Yield" mylink="shared.functions.system.Hint_Yield" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Hint_Yield()
// ============
// Provides a hint that the task performed by a thread is of low
// importance so that it could yield to improve overall performance.

impdef func Hint_Yield()
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/system/IRQPending" mylink="shared.functions.system.IRQPending" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IRQPending()
// ============
// Returns a tuple indicating if there is any pending physical IRQ
// and if the pending IRQ has superpriority.

impdef func <anchor link="func_IRQPending_0">IRQPending</anchor>() =&gt; (boolean, boolean)
begin
    return (FALSE, FALSE);
end;</pstext></ps>
    <ps name="shared/functions/system/IllegalExceptionReturn" mylink="shared.functions.system.IllegalExceptionReturn" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IllegalExceptionReturn()
// ========================

func <anchor link="func_IllegalExceptionReturn_2">IllegalExceptionReturn</anchor>{N}(spsr : bits(N)) =&gt; boolean
begin
    // Check for illegal return:
    //   * To an unimplemented Exception level.
    //   * To EL2 in Secure state, when SecureEL2 is not enabled.
    //   * To EL0 using AArch64 state, with SPSR.M[0]==1.
    //   * To AArch64 state with SPSR.M[1]==1.
    //   * To AArch32 state with an illegal value of SPSR.M.
    let (valid, target) : (boolean, bits(2)) = <a link="func_ELFromSPSR_2" file="shared_pseudocode.xml">ELFromSPSR</a>{N}(spsr);
    if !valid then return TRUE; end;

    // Check for return to higher Exception level.
    if UInt(target) &gt; UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) then return TRUE; end;

    let spsr_mode_is_aarch32 : boolean = (spsr[4] == '1');

    // Check for illegal return:
    //   * To EL1, EL2 or EL3 with register width specified in the SPSR different from the
    //     Execution state used in the Exception level being returned to, as determined by
    //     the SCR_EL3.RW or HCR_EL2.RW bits, or as configured from reset.
    //   * To EL0 using AArch64 state when EL1 is using AArch32 state as determined by the
    //     SCR_EL3.RW or HCR_EL2.RW bits or as configured from reset.
    //   * To AArch64 state from AArch32 state (should be caught by above).
    let (known, target_el_is_aarch32) : (boolean, boolean) = <a link="func_ELUsingAArch32K_1" file="shared_pseudocode.xml">ELUsingAArch32K</a>(target);
    assert known || (target == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> &amp;&amp; !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>));
    if known &amp;&amp; spsr_mode_is_aarch32 != target_el_is_aarch32 then return TRUE; end;

    // Check for illegal return from AArch32 to AArch64.
    if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() &amp;&amp; !spsr_mode_is_aarch32 then return TRUE; end;
    // Check for illegal return to EL1 when HCR_EL2.TGE is set and when either of
    // * SecureEL2 is enabled.
    // * SecureEL2 is not enabled and EL1 is in Non-secure state.
    if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() &amp;&amp; target == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; HCR_EL2().TGE == '1' then
        if (!<a link="func_IsSecureBelowEL3_0" file="shared_pseudocode.xml">IsSecureBelowEL3</a>() || <a link="func_IsSecureEL2Enabled_0" file="shared_pseudocode.xml">IsSecureEL2Enabled</a>()) then return TRUE; end;
    end;

    if (IsFeatureImplemented(FEAT_GCS) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EXLOCK == '0' &amp;&amp;
          <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == target &amp;&amp; <a link="func_GetCurrentEXLOCKEN_0" file="shared_pseudocode.xml">GetCurrentEXLOCKEN</a>()) then
        return TRUE;
    end;

    return FALSE;
end;</pstext></ps>
    <ps name="shared/functions/system/InstrSet" mylink="shared.functions.system.InstrSet" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// InstrSet
// ========

type <anchor link="type_InstrSet">InstrSet</anchor> of enumeration {<anchor link="enum_InstrSet_A64">InstrSet_A64</anchor>, <anchor link="enum_InstrSet_A32">InstrSet_A32</anchor>, <anchor link="enum_InstrSet_T32">InstrSet_T32</anchor>};</pstext></ps>
    <ps name="shared/functions/system/InstructionFetchBarrier" mylink="shared.functions.system.InstructionFetchBarrier" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// InstructionFetchBarrier()
// =========================

impdef func InstructionFetchBarrier()
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/system/InstructionSynchronizationBarrier" mylink="shared.functions.system.InstructionSynchronizationBarrier" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// InstructionSynchronizationBarrier()
// ===================================

impdef func InstructionSynchronizationBarrier()
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/system/IsASEInstruction" mylink="shared.functions.system.IsASEInstruction" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsASEInstruction()
// ==================
// Returns TRUE if the current instruction is an ASIMD or SVE vector instruction.

impdef func <anchor link="func_IsASEInstruction_0">IsASEInstruction</anchor>() =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="shared/functions/system/IsCurrentSecurityState" mylink="shared.functions.system.IsCurrentSecurityState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsCurrentSecurityState()
// ========================
// Returns TRUE if the current Security state matches
// the given Security state, and FALSE otherwise.

func <anchor link="func_IsCurrentSecurityState_1">IsCurrentSecurityState</anchor>(ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>) =&gt; boolean
begin
    return <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() == ss;
end;</pstext></ps>
    <ps name="shared/functions/system/IsEventRegisterSet" mylink="shared.functions.system.IsEventRegisterSet" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsEventRegisterSet()
// ====================
// Return TRUE if the Event Register of this PE is set, and FALSE if it is clear.

func <anchor link="func_IsEventRegisterSet_0">IsEventRegisterSet</anchor>() =&gt; boolean
begin
    return <a link="global_EventRegister" file="shared_pseudocode.xml">EventRegister</a> == '1';
end;</pstext></ps>
    <ps name="shared/functions/system/IsHighestEL" mylink="shared.functions.system.IsHighestEL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsHighestEL()
// =============
// Returns TRUE if given exception level is the highest exception level implemented

readonly func <anchor link="func_IsHighestEL_1">IsHighestEL</anchor>(el : bits(2)) =&gt; boolean
begin
    return <a link="func_HighestEL_0" file="shared_pseudocode.xml">HighestEL</a>() == el;
end;</pstext></ps>
    <ps name="shared/functions/system/IsInHost" mylink="shared.functions.system.IsInHost" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsInHost()
// ==========

readonly func <anchor link="func_IsInHost_0">IsInHost</anchor>() =&gt; boolean
begin
    return <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
end;</pstext></ps>
    <ps name="shared/functions/system/IsSecureBelowEL3" mylink="shared.functions.system.IsSecureBelowEL3" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsSecureBelowEL3()
// ==================
// Return TRUE if an Exception level below EL3 is in Secure state
// or would be following an exception return to that level.
//
// That is, if at AArch64 EL3 or in AArch32 Monitor mode, whether an
// exception return would pass to Secure or Non-secure state.

readonly func <anchor link="func_IsSecureBelowEL3_0">IsSecureBelowEL3</anchor>() =&gt; boolean
begin
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        return if !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then SCR().NS == '0' else SCR_EL3().NS == '0';
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; (!IsFeatureImplemented(FEAT_SEL2) || !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>()) then
        // If Secure EL2 is not an architecture option then we must be Non-secure.
        return FALSE;
    else
        // TRUE if PE is Secure or FALSE if Non-secure.
        return ImpDefBool(&quot;Secure-only implementation&quot;);
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/IsSecureEL2Enabled" mylink="shared.functions.system.IsSecureEL2Enabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsSecureEL2Enabled()
// ====================
// Returns TRUE if Secure EL2 is enabled, FALSE otherwise.

readonly func <anchor link="func_IsSecureEL2Enabled_0">IsSecureEL2Enabled</anchor>() =&gt; boolean
begin
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; IsFeatureImplemented(FEAT_SEL2) then
        if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
            if !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().EEL2 == '1' then
                return TRUE;
            else
                return FALSE;
            end;
        else
            return <a link="func_SecureOnlyImplementation_0" file="shared_pseudocode.xml">SecureOnlyImplementation</a>();
        end;
    else
        return FALSE;
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/LocalTimeoutEvent" mylink="shared.functions.system.LocalTimeoutEvent" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// LocalTimeoutEvent()
// ===================
// Returns TRUE if CNTVCT_EL0 equals or exceeds the localtimeout value.

func <anchor link="func_LocalTimeoutEvent_1">LocalTimeoutEvent</anchor>(localtimeout : integer) =&gt; boolean
begin
    assert localtimeout &gt;= 0;

    let cntvct : bits(64) = <a link="func_VirtualCounterTimer_0" file="shared_pseudocode.xml">VirtualCounterTimer</a>();
    if UInt(cntvct) &gt;= localtimeout then
        return TRUE;
    end;

    <a link="global_IsLocalTimeoutEventPending" file="shared_pseudocode.xml">IsLocalTimeoutEventPending</a> = TRUE;
    <a link="global_LocalTimeoutVal" file="shared_pseudocode.xml">LocalTimeoutVal</a> = localtimeout[63:0];   // Store value to compare against
                                            // Virtual Counter Timer at subsequent clock ticks
    return FALSE;
end;</pstext></ps>
    <ps name="shared/functions/system/Mode" mylink="shared.functions.system.Mode" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Mode bits
// =========
// AArch32 PSTATE.M mode bits.

constant <anchor link="global_M32_User">M32_User</anchor> : bits(5)    = '10000';
constant <anchor link="global_M32_FIQ">M32_FIQ</anchor> : bits(5)     = '10001';
constant <anchor link="global_M32_IRQ">M32_IRQ</anchor> : bits(5)     = '10010';
constant <anchor link="global_M32_Svc">M32_Svc</anchor> : bits(5)     = '10011';
constant <anchor link="global_M32_Monitor">M32_Monitor</anchor> : bits(5) = '10110';
constant <anchor link="global_M32_Abort">M32_Abort</anchor> : bits(5)   = '10111';
constant <anchor link="global_M32_Hyp">M32_Hyp</anchor> : bits(5)     = '11010';
constant <anchor link="global_M32_Undef">M32_Undef</anchor> : bits(5)   = '11011';
constant <anchor link="global_M32_System">M32_System</anchor> : bits(5)  = '11111';</pstext></ps>
    <ps name="shared/functions/system/NonSecureOnlyImplementation" mylink="shared.functions.system.NonSecureOnlyImplementation" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// NonSecureOnlyImplementation()
// =============================
// Returns TRUE if the security state is always Non-secure for this implementation.

func <anchor link="func_NonSecureOnlyImplementation_0">NonSecureOnlyImplementation</anchor>() =&gt; boolean
begin
    return ImpDefBool(&quot;Non-secure only implementation&quot;);
end;</pstext></ps>
    <ps name="shared/functions/system/PLOfEL" mylink="shared.functions.system.PLOfEL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PLOfEL()
// ========

func <anchor link="func_PLOfEL_1">PLOfEL</anchor>(el : bits(2)) =&gt; <a link="type_PrivilegeLevel" file="shared_pseudocode.xml">PrivilegeLevel</a>
begin
    case el of
        when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;  return if !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then <a link="enum_PL1" file="shared_pseudocode.xml">PL1</a> else <a link="enum_PL3" file="shared_pseudocode.xml">PL3</a>;
        when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;  return <a link="enum_PL2" file="shared_pseudocode.xml">PL2</a>;
        when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;  return <a link="enum_PL1" file="shared_pseudocode.xml">PL1</a>;
        when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;  return <a link="enum_PL0" file="shared_pseudocode.xml">PL0</a>;
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/PSTATE" mylink="shared.functions.system.PSTATE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PSTATE
// ======
// PE state bits.
// There is no significance to the field order.

var <anchor link="global_PSTATE">PSTATE</anchor> : collection {
    N : bits (1),        // Negative condition flag
    Z : bits (1),        // Zero condition flag
    C : bits (1),        // Carry condition flag
    V : bits (1),        // Overflow condition flag
    D : bits (1),        // Debug mask bit                     [AArch64 only]
    A : bits (1),        // SError interrupt mask bit
    I : bits (1),        // IRQ mask bit
    F : bits (1),        // FIQ mask bit
    EXLOCK : bits (1),   // Lock exception return state
    PAN : bits (1),      // Privileged Access Never Bit        [v8.1]
    UAO : bits (1),      // User Access Override               [v8.2]
    DIT : bits (1),      // Data Independent Timing            [v8.4]
    TCO : bits (1),      // Tag Check Override                 [v8.5, AArch64 only]
    PM : bits (1),       // PMU exception Mask
    BTYPE : bits (2),    // Branch Type                        [v8.5]
    PACM : bits (1),     // PAC instruction modifier
    ZA : bits (1),       // Accumulation array enabled         [SME]
    SM : bits (1),       // Streaming SVE mode enabled         [SME]
    ALLINT : bits (1),   // Interrupt mask bit
    UINJ : bits (1),     // Undefined Exception Injection
    SS : bits (1),       // Software step bit
    IL : bits (1),       // Illegal Execution state bit
    EL : bits (2),       // Exception level
    nRW : bits (1),      // Execution state: 0=AArch64, 1=AArch32
    SP : bits (1),       // Stack pointer select: 0=SP0, 1=SPx [AArch64 only]
    Q : bits (1),        // Cumulative saturation flag         [AArch32 only]
    GE : bits (4),       // Greater than or Equal flags        [AArch32 only]
    SSBS : bits (1),     // Speculative Store Bypass Safe
    IT : bits (8),       // If-then bits, RES0 in CPSR         [AArch32 only]
    J : bits (1),        // J bit, RES0                        [AArch32 only, RES0 in SPSR and CPSR]
    T : bits (1),        // T32 bit, RES0 in CPSR              [AArch32 only]
    E : bits (1),        // Endianness bit                     [AArch32 only]
    M : bits (5)         // Mode field                         [AArch32 only]
};</pstext></ps>
    <ps name="shared/functions/system/PhysicalCountInt" mylink="shared.functions.system.PhysicalCountInt" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PhysicalCountInt()
// ==================
// Returns the integral part of physical count value of the System counter.

func <anchor link="func_PhysicalCountInt_0">PhysicalCountInt</anchor>() =&gt; bits(64)
begin
    return <a link="global_PhysicalCount" file="shared_pseudocode.xml">PhysicalCount</a>[87:24];
end;</pstext></ps>
    <ps name="shared/functions/system/PrivilegeLevel" mylink="shared.functions.system.PrivilegeLevel" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PrivilegeLevel
// ==============
// Privilege Level abstraction.

type <anchor link="type_PrivilegeLevel">PrivilegeLevel</anchor> of enumeration {<anchor link="enum_PL3">PL3</anchor>, <anchor link="enum_PL2">PL2</anchor>, <anchor link="enum_PL1">PL1</anchor>, <anchor link="enum_PL0">PL0</anchor>};</pstext></ps>
    <ps name="shared/functions/system/RestoredITBits" mylink="shared.functions.system.RestoredITBits" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// RestoredITBits()
// ================
// Get the value of PSTATE.IT to be restored on this exception return.

func <anchor link="func_RestoredITBits_2">RestoredITBits</anchor>{N}(spsr : bits(N)) =&gt; bits(8)
begin
    let it : bits(8) = spsr[15:10,26:25];

    // When PSTATE.IL is set, it is CONSTRAINED UNPREDICTABLE whether the IT bits are each set
    // to zero or copied from the SPSR.
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL == '1' then
        if <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_ILZEROIT" file="shared_pseudocode.xml">Unpredictable_ILZEROIT</a>) then return '00000000';
        else return it;
        end;
    end;

    // The IT bits are forced to zero when they are set to a reserved value.
    if !IsZero(it[7:4]) &amp;&amp; IsZero(it[3:0]) then
        return '00000000';
    end;

    // The IT bits are forced to zero when returning to A32 state, or when returning to an EL
    // with the ITD bit set to 1, and the IT bits are describing a multi-instruction block.
    let itd : bit = if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then HSCTLR().ITD else SCTLR().ITD;
    if (spsr[5] == '0' &amp;&amp; !IsZero(it)) || (itd == '1' &amp;&amp; !IsZero(it[2:0])) then
        return '00000000';
    else
        return it;
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/SecureOnlyImplementation" mylink="shared.functions.system.SecureOnlyImplementation" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SecureOnlyImplementation()
// ==========================
// Returns TRUE if the security state is always Secure for this implementation.

readonly func <anchor link="func_SecureOnlyImplementation_0">SecureOnlyImplementation</anchor>() =&gt; boolean
begin
    return ImpDefBool(&quot;Secure-only implementation&quot;);
end;</pstext></ps>
    <ps name="shared/functions/system/SecurityState" mylink="shared.functions.system.SecurityState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SecurityState
// =============
// The Security state of an execution context

type <anchor link="type_SecurityState">SecurityState</anchor> of enumeration {
    <anchor link="enum_SS_NonSecure">SS_NonSecure</anchor>,
    <anchor link="enum_SS_Root">SS_Root</anchor>,
    <anchor link="enum_SS_Realm">SS_Realm</anchor>,
    <anchor link="enum_SS_Secure">SS_Secure</anchor>
};</pstext></ps>
    <ps name="shared/functions/system/SecurityStateAtEL" mylink="shared.functions.system.SecurityStateAtEL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SecurityStateAtEL()
// ===================
// Returns the effective security state at the exception level based off current settings.

readonly func <anchor link="func_SecurityStateAtEL_1">SecurityStateAtEL</anchor>(EL : bits(2)) =&gt; <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>
begin
    if IsFeatureImplemented(FEAT_RME) then
        if EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then return <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a>; end;
        let effective_nse_ns : bits(2) = <a link="func_EffectiveSCR_EL3_NSE_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NSE</a>() :: <a link="func_EffectiveSCR_EL3_NS_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NS</a>();
        case effective_nse_ns of
            when '00' =&gt;
                if IsFeatureImplemented(FEAT_SEL2) then
                    return <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>;
                else
                    unreachable;
                end;
            when '01' =&gt;
                return <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a>;
            when '11' =&gt;
                return <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a>;
            otherwise =&gt;
                unreachable;
        end;
    end;

    if !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        if <a link="func_SecureOnlyImplementation_0" file="shared_pseudocode.xml">SecureOnlyImplementation</a>() then
            return <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>;
        else
            return <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a>;
        end;
    elsif EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then
        return <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>;
    else
        // For EL2 call only when EL2 is enabled in current security state
        assert(EL != <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> || <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>());
        if !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
            return if <a link="func_EffectiveSCR_EL3_NS_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NS</a>() == '1' then <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> else <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>;
        else
            return if SCR().NS == '1' then <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> else <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>;
        end;
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/SendEvent" mylink="shared.functions.system.SendEvent" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SendEvent()
// ===========
// Signal an event to all PEs in a multiprocessor system to set their Event Registers.
// When a PE executes the SEV instruction, it causes this function to be executed.

impdef func SendEvent()
begin
    <a link="func_SendEventLocal_0" file="shared_pseudocode.xml">SendEventLocal</a>();
end;</pstext></ps>
    <ps name="shared/functions/system/SendEventLocal" mylink="shared.functions.system.SendEventLocal" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SendEventLocal()
// ================
// Set the local Event Register of this PE.
// When a PE executes the SEVL instruction, it causes this function to be executed.

func <anchor link="func_SendEventLocal_0">SendEventLocal</anchor>()
begin
    <a link="global_EventRegister" file="shared_pseudocode.xml">EventRegister</a> = '1';
    return;
end;</pstext></ps>
    <ps name="shared/functions/system/SetAccumulatedFPExceptions" mylink="shared.functions.system.SetAccumulatedFPExceptions" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SetAccumulatedFPExceptions()
// ============================
// Stores FP Exceptions accumulated by the PE.

impdef func SetAccumulatedFPExceptions(accumulated_exceptions : bits(8))
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/system/SetPSTATEFromPSR" mylink="shared.functions.system.SetPSTATEFromPSR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SetPSTATEFromPSR()
// ==================

func <anchor link="func_SetPSTATEFromPSR_2">SetPSTATEFromPSR</anchor>{N}(spsr : bits(N))
begin
    let illegal_psr_state : boolean = <a link="func_IllegalExceptionReturn_2" file="shared_pseudocode.xml">IllegalExceptionReturn</a>{N}(spsr);
    <a link="func_SetPSTATEFromPSR_3" file="shared_pseudocode.xml">SetPSTATEFromPSR</a>{N}(spsr, illegal_psr_state);
end;

// SetPSTATEFromPSR()
// ==================
// Set PSTATE based on a PSR value

func <anchor link="func_SetPSTATEFromPSR_3">SetPSTATEFromPSR</anchor>{N}(spsr_in : bits(N), illegal_psr_state : boolean)
begin
    var spsr : bits(N) = spsr_in;
    let from_aarch64 : boolean = !<a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>();
    <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SS = <a link="func_DebugExceptionReturnSS_2" file="shared_pseudocode.xml">DebugExceptionReturnSS</a>{N}(spsr);
    <a link="global_ShouldAdvanceSS" file="shared_pseudocode.xml">ShouldAdvanceSS</a> = FALSE;
    if illegal_psr_state then
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL = '1';
        if IsFeatureImplemented(FEAT_SSBS) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SSBS = ARBITRARY : bit; end;
        if IsFeatureImplemented(FEAT_BTI) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.BTYPE = ARBITRARY : bits(2); end;
        if IsFeatureImplemented(FEAT_UAO) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.UAO = ARBITRARY : bit; end;
        if IsFeatureImplemented(FEAT_DIT) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.DIT = ARBITRARY : bit; end;
        if IsFeatureImplemented(FEAT_MTE) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.TCO = ARBITRARY : bit; end;
        if IsFeatureImplemented(FEAT_PAuth_LR) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PACM = ARBITRARY : bit; end;
        if IsFeatureImplemented(FEAT_UINJ) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.UINJ = '0'; end;
    else
        // State that is reinstated only on a legal exception return
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL = spsr[20];
        if IsFeatureImplemented(FEAT_UINJ) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.UINJ = spsr[36]; end;
        if spsr[4] == '1' then                    // AArch32 state
            <a link="func_AArch32_WriteMode_1" file="shared_pseudocode.xml">AArch32_WriteMode</a>(spsr[4:0]);         // Sets PSTATE.EL correctly
            if IsFeatureImplemented(FEAT_SSBS) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SSBS = spsr[23]; end;
        else                                      // AArch64 state
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.nRW = '0';
            (-, <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) = <a link="func_ELFromSPSR_2" file="shared_pseudocode.xml">ELFromSPSR</a>{N}(spsr);
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SP  = spsr[0];
            if IsFeatureImplemented(FEAT_BTI) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.BTYPE = spsr[11:10]; end;
            if IsFeatureImplemented(FEAT_SSBS) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.SSBS = spsr[12]; end;
            if IsFeatureImplemented(FEAT_UAO) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.UAO = spsr[23]; end;
            if IsFeatureImplemented(FEAT_DIT) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.DIT = spsr[24]; end;
            if IsFeatureImplemented(FEAT_MTE) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.TCO = spsr[25]; end;
            if IsFeatureImplemented(FEAT_GCS) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EXLOCK = spsr[34]; end;
            if IsFeatureImplemented(FEAT_PAuth_LR) then
                <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PACM = if <a link="func_IsPACMEnabled_0" file="shared_pseudocode.xml">IsPACMEnabled</a>() then spsr[35] else '0';
            end;
        end;
    end;

    // If PSTATE.IL is set, it is CONSTRAINED UNPREDICTABLE whether the T bit is set to zero or
    // copied from SPSR.
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IL == '1' &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.nRW == '1' then
        if <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_ILZEROT" file="shared_pseudocode.xml">Unpredictable_ILZEROT</a>) then spsr[5] = '0'; end;
    end;

    // State that is reinstated regardless of illegal exception return
    PSTATE.[N,Z,C,V] = spsr[31:28];
    if IsFeatureImplemented(FEAT_PAN) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PAN = spsr[22]; end;
    if <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.nRW == '1' then                     // AArch32 state
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.Q         = spsr[27];
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.IT        = <a link="func_RestoredITBits_2" file="shared_pseudocode.xml">RestoredITBits</a>{N}(spsr);
        <a link="global_ShouldAdvanceIT" file="shared_pseudocode.xml">ShouldAdvanceIT</a>  = FALSE;
        if IsFeatureImplemented(FEAT_DIT) then
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.DIT = (if (<a link="func_Restarting_0" file="shared_pseudocode.xml">Restarting</a>() || from_aarch64) then spsr[24] else spsr[21]);
        end;
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.GE        = spsr[19:16];
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.E         = spsr[9];
        PSTATE.[A,I,F]   = spsr[8:6];             // No PSTATE.D in AArch32 state
        <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.T         = spsr[5];               // PSTATE.J is RES0
    else                                          // AArch64 state
        if (IsFeatureImplemented(FEAT_EBEP) || IsFeatureImplemented(FEAT_SPE_EXC) ||
              IsFeatureImplemented(FEAT_TRBE_EXC)) then
            <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PM    = spsr[32];
        end;
        if IsFeatureImplemented(FEAT_NMI) then <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.ALLINT  = spsr[13]; end;
        PSTATE.[D,A,I,F] = spsr[9:6];             // No PSTATE.[Q,IT,GE,E,T] in AArch64 state
    end;
    return;
end;</pstext></ps>
    <ps name="shared/functions/system/ShouldAdvanceHS" mylink="shared.functions.system.ShouldAdvanceHS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ShouldAdvanceHS
// ===============
// Cleared if we should not advance the EDESR.SS after the current instruction.

var <anchor link="global_ShouldAdvanceHS">ShouldAdvanceHS</anchor> : boolean;</pstext></ps>
    <ps name="shared/functions/system/ShouldAdvanceIT" mylink="shared.functions.system.ShouldAdvanceIT" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ShouldAdvanceIT
// ===============
// Cleared if we should not advance the PSTATE.IT after the current instruction.

var <anchor link="global_ShouldAdvanceIT">ShouldAdvanceIT</anchor> : boolean;</pstext></ps>
    <ps name="shared/functions/system/ShouldAdvanceSS" mylink="shared.functions.system.ShouldAdvanceSS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ShouldAdvanceSS
// ===============
// Cleared if PSTATE.SS is written by the current instruction.

var <anchor link="global_ShouldAdvanceSS">ShouldAdvanceSS</anchor> : boolean;</pstext></ps>
    <ps name="shared/functions/system/SmallestTranslationGranule" mylink="shared.functions.system.SmallestTranslationGranule" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SmallestTranslationGranule()
// ============================
// Smallest implemented translation granule.

func <anchor link="func_SmallestTranslationGranule_0">SmallestTranslationGranule</anchor>() =&gt; integer
begin
    if IsFeatureImplemented(FEAT_TGran4K) then return 12; end;
    if IsFeatureImplemented(FEAT_TGran16K) then return 14; end;
    if IsFeatureImplemented(FEAT_TGran64K)  then return 16; end;
    unreachable;
end;</pstext></ps>
    <ps name="shared/functions/system/SpeculationBarrier" mylink="shared.functions.system.SpeculationBarrier" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SpeculationBarrier()
// ====================

impdef func SpeculationBarrier()
begin
    // Since there is no speculation in asl model, this is a NOP.
    return;
end;</pstext></ps>
    <ps name="shared/functions/system/SynchronizeContext" mylink="shared.functions.system.SynchronizeContext" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SynchronizeContext()
// ====================
// Context Synchronization event, includes Instruction Fetch Barrier effect

impdef func SynchronizeContext()
begin
    InstructionFetchBarrier();
end;</pstext></ps>
    <ps name="shared/functions/system/SynchronizeErrors" mylink="shared.functions.system.SynchronizeErrors" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SynchronizeErrors()
// ===================
// Implements the error synchronization event.

impdef func SynchronizeErrors()
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/system/TakeUnmaskedPhysicalSErrorInterrupts" mylink="shared.functions.system.TakeUnmaskedPhysicalSErrorInterrupts" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TakeUnmaskedPhysicalSErrorInterrupts()
// ======================================
// Take any pending unmasked physical SError interrupt.

impdef func TakeUnmaskedPhysicalSErrorInterrupts(iesb_req : boolean)
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/system/TakeUnmaskedSErrorInterrupts" mylink="shared.functions.system.TakeUnmaskedSErrorInterrupts" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TakeUnmaskedSErrorInterrupts()
// ==============================
// Take any pending unmasked physical SError interrupt or unmasked virtual SError
// interrupt.

impdef func TakeUnmaskedSErrorInterrupts()
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/system/ThisInstr" mylink="shared.functions.system.ThisInstr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ThisInstr()
// ===========
// Return the bitstring encoding of the currently executing instruction.

impdef func <anchor link="func_ThisInstr_0">ThisInstr</anchor>() =&gt; bits(32)
begin
    Unimplemented();
end;</pstext></ps>
    <ps name="shared/functions/system/ThisInstrLength" mylink="shared.functions.system.ThisInstrLength" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ThisInstrLength()
// =================
// Return the length of the current instruction.

impdef func <anchor link="func_ThisInstrLength_0">ThisInstrLength</anchor>() =&gt; integer
begin
    Unimplemented();
end;</pstext></ps>
    <ps name="shared/functions/system/UndefinedInjectionCheck" mylink="shared.functions.system.UndefinedInjectionCheck" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// UndefinedInjectionCheck()
// =========================
// Check PSTATE.UINJ to determine if execution of the current
// instruction should cause an Undefined exception.

func <anchor link="func_UndefinedInjectionCheck_0">UndefinedInjectionCheck</anchor>()
begin
    if IsFeatureImplemented(FEAT_UINJ) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.UINJ == '1' then
        Undefined();
    end;
end;</pstext></ps>
    <ps name="shared/functions/system/UsingAArch32" mylink="shared.functions.system.UsingAArch32" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// UsingAArch32()
// ==============
// Return TRUE if the current Exception level is using AArch32, FALSE if using AArch64_

readonly func <anchor link="func_UsingAArch32_0">UsingAArch32</anchor>() =&gt; boolean
begin
    let aarch32 : boolean = (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.nRW == '1');
    if !<a link="func_HaveAArch32_0" file="shared_pseudocode.xml">HaveAArch32</a>() then assert !aarch32; end;
    if !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then assert aarch32; end;
    return aarch32;
end;</pstext></ps>
    <ps name="shared/functions/system/ValidSecurityStateAtEL" mylink="shared.functions.system.ValidSecurityStateAtEL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ValidSecurityStateAtEL()
// ========================
// Returns TRUE if the current settings and architecture choices for this
// implementation permit a valid Security state at the indicated EL.

func <anchor link="func_ValidSecurityStateAtEL_1">ValidSecurityStateAtEL</anchor>(el : bits(2)) =&gt; boolean
begin
    if !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(el) then
        return FALSE;
    end;

    if el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then
        return TRUE;
    end;

    if IsFeatureImplemented(FEAT_RME) then
        let effective_nse_ns : bits(2) = <a link="func_EffectiveSCR_EL3_NSE_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NSE</a>() :: <a link="func_EffectiveSCR_EL3_NS_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NS</a>();
        if effective_nse_ns == '10' then
            return FALSE;
        end;
    end;

    if el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
        return <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>();
    end;

    return TRUE;
end;</pstext></ps>
    <ps name="shared/functions/system/VirtualFIQPending" mylink="shared.functions.system.VirtualFIQPending" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// VirtualFIQPending()
// ===================
// Returns TRUE if there is any pending virtual FIQ.

impdef func <anchor link="func_VirtualFIQPending_0">VirtualFIQPending</anchor>() =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="shared/functions/system/VirtualIRQPending" mylink="shared.functions.system.VirtualIRQPending" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// VirtualIRQPending()
// ===================
// Returns TRUE if there is any pending virtual IRQ.

impdef func <anchor link="func_VirtualIRQPending_0">VirtualIRQPending</anchor>() =&gt; boolean
begin
    return FALSE;
end;</pstext></ps>
    <ps name="shared/functions/system/WFxType" mylink="shared.functions.system.WFxType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// WFxType
// =======
// WFx instruction types.

type <anchor link="type_WFxType">WFxType</anchor> of enumeration {<anchor link="enum_WFxType_WFE">WFxType_WFE</anchor>, <anchor link="enum_WFxType_WFI">WFxType_WFI</anchor>, <anchor link="enum_WFxType_WFET">WFxType_WFET</anchor>, <anchor link="enum_WFxType_WFIT">WFxType_WFIT</anchor>};</pstext></ps>
    <ps name="shared/functions/system/WaitForEvent" mylink="shared.functions.system.WaitForEvent" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// WaitForEvent()
// ==============
// PE optionally suspends execution until one of the following occurs:
// - A WFE wakeup event.
// - A reset.
// - The implementation chooses to resume execution.
// It is IMPLEMENTATION DEFINED whether restarting execution after the period of
// suspension causes the Event Register to be cleared.

func <anchor link="func_WaitForEvent_0">WaitForEvent</anchor>()
begin
    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then return; end;
    if !<a link="func_IsEventRegisterSet_0" file="shared_pseudocode.xml">IsEventRegisterSet</a>() then
        EnterLowPowerState();
    end;
    return;
end;

// WaitForEvent()
// ==============
// PE optionally suspends execution until one of the following occurs:
// - A WFE wakeup event.
// - A reset.
// - The implementation chooses to resume execution.
// - A Wait for Event with Timeout (WFET) is executing, and a local timeout event occurs
// It is IMPLEMENTATION DEFINED whether restarting execution after the period of
// suspension causes the Event Register to be cleared.

func <anchor link="func_WaitForEvent_1">WaitForEvent</anchor>(localtimeout : integer)
begin
    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then return; end;
    if !(<a link="func_IsEventRegisterSet_0" file="shared_pseudocode.xml">IsEventRegisterSet</a>() || <a link="func_LocalTimeoutEvent_1" file="shared_pseudocode.xml">LocalTimeoutEvent</a>(localtimeout)) then
        EnterLowPowerState();
    end;
    return;
end;</pstext></ps>
    <ps name="shared/functions/system/WaitForInterrupt" mylink="shared.functions.system.WaitForInterrupt" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// WaitForInterrupt()
// ==================
// PE optionally suspends execution until one of the following occurs:
// - A WFI wakeup event.
// - A reset.
// - The implementation chooses to resume execution.

func <anchor link="func_WaitForInterrupt_0">WaitForInterrupt</anchor>()
begin
    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then return; end;
    EnterLowPowerState();
    return;
end;

// WaitForInterrupt()
// ==================
// PE optionally suspends execution until one of the following occurs:
// - A WFI wakeup event.
// - A reset.
// - The implementation chooses to resume execution.
// - A Wait for Interrupt with Timeout (WFIT) is executing, and a local timeout event occurs.

func <anchor link="func_WaitForInterrupt_1">WaitForInterrupt</anchor>(localtimeout : integer)
begin
    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() then return; end;
    if !<a link="func_LocalTimeoutEvent_1" file="shared_pseudocode.xml">LocalTimeoutEvent</a>(localtimeout) then
        EnterLowPowerState();
    end;
    return;
end;</pstext></ps>
    <ps name="shared/functions/system/WatchpointRelatedSyndrome" mylink="shared.functions.system.WatchpointRelatedSyndrome" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// WatchpointRelatedSyndrome()
// ===========================
// Update common Watchpoint related fields.

func <anchor link="func_WatchpointRelatedSyndrome_1">WatchpointRelatedSyndrome</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; bits(24)
begin
    var syndrome : bits(24) = Zeros{};

    if fault.watchptinfo.maybe_false_match then
        syndrome[16] = '1';                                          // WPF
    elsif IsFeatureImplemented(FEAT_Debugv8p2) then
        syndrome[16] = ImpDefBit(&quot;WPF value on TRUE Watchpoint match&quot;);
    end;

    if <a link="func_IsRelaxedWatchpointAccess_1" file="shared_pseudocode.xml">IsRelaxedWatchpointAccess</a>(fault.accessdesc) then
        if <a link="func_HaltOnBreakpointOrWatchpoint_0" file="shared_pseudocode.xml">HaltOnBreakpointOrWatchpoint</a>() then
            if ImpDefBool(&quot;EDWAR is not valid on watchpoint debug event&quot;) then
                syndrome[10] = '1';                                  // FnV
            end;
        else
            if ImpDefBool(&quot;FAR is not valid on watchpoint exception&quot;) then
                syndrome[10] = '1';                                  // FnV
            end;
        end;
    else
        if <a link="func_WatchpointFARNotPrecise_1" file="shared_pseudocode.xml">WatchpointFARNotPrecise</a>(fault) then
            syndrome[15] = '1';                                      // FnP
        end;
    end;

    // Watchpoint number is valid if FEAT_Debugv8p9 is implemented or
    // if Feat_Debugv8p2 is implemented and below set of conditions are satisfied:
    // - Either FnV = 1 or FnP = 1.
    // - If the address recorded in FAR is not within a naturally-aligned block of memory.
    // Otherwise, it is IMPLEMENTATION DEFINED if watchpoint number is valid.
    if IsFeatureImplemented(FEAT_Debugv8p9) then
        syndrome[17]    = '1';                                       // WPTV
        syndrome[23:18] = fault.watchptinfo.watchpt_num[5:0];        // WPT
    elsif IsFeatureImplemented(FEAT_Debugv8p2) then
        if syndrome[15] == '1' || syndrome[10] == '1' then           // Either of FnP or FnV is 1
            syndrome[17] = '1';                                      // WPTV
        elsif !<a link="func_AddressInNaturallyAlignedBlock_2" file="shared_pseudocode.xml">AddressInNaturallyAlignedBlock</a>(fault.vaddress, fault.watchptinfo.vaddress) then
            syndrome[17] = '1';                                      // WPTV
        elsif ImpDefBool(&quot;WPTV field is valid&quot;) then
            syndrome[17] = '1';
        end;
        if syndrome[17] == '1' then
            syndrome[23:18] = fault.watchptinfo.watchpt_num[5:0];    // WPT
        else
            syndrome[23:18] = ARBITRARY : bits(6);
        end;
    end;

    return syndrome;
end;</pstext></ps>
    <ps name="shared/functions/tlbi" mylink="shared.functions.tlbi" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">constant <anchor link="global_VMID_NONE">VMID_NONE</anchor> : bits(NUM_VMIDBITS) = Zeros{};
constant <anchor link="global_ASID_NONE">ASID_NONE</anchor> : bits(NUM_ASIDBITS) = Zeros{};</pstext></ps>
    <ps name="shared/functions/tlbi/Broadcast" mylink="shared.functions.tlbi.Broadcast" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Broadcast
// =========

type <anchor link="type_Broadcast">Broadcast</anchor> of enumeration {
    <anchor link="enum_Broadcast_ISH">Broadcast_ISH</anchor>,
    <anchor link="enum_Broadcast_ForcedISH">Broadcast_ForcedISH</anchor>,
    <anchor link="enum_Broadcast_OSH">Broadcast_OSH</anchor>,
    <anchor link="enum_Broadcast_NSH">Broadcast_NSH</anchor>
};</pstext></ps>
    <ps name="shared/functions/tlbi/BroadcastTLBI" mylink="shared.functions.tlbi.BroadcastTLBI" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BroadcastTLBI()
// ===============
// IMPLEMENTATION DEFINED function to broadcast TLBI operation within the indicated broadcast
// domain.

impdef func BroadcastTLBI(broadcast : <a link="type_Broadcast" file="shared_pseudocode.xml">Broadcast</a>, r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>)
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/tlbi/ExcludeXS" mylink="shared.functions.tlbi.ExcludeXS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExcludeXS()
// ===========
// Returns TRUE if a TLBI maintenance instruction without the nXS qualifier executed at EL1
// behaves in the same way as the corresponding TLBI maintenance instruction with the nXS qualifier.

func <anchor link="func_ExcludeXS_0">ExcludeXS</anchor>() =&gt; boolean
begin
    return (IsFeatureImplemented(FEAT_XS) &amp;&amp; <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp;
            <a link="func_IsHCRXEL2Enabled_0" file="shared_pseudocode.xml">IsHCRXEL2Enabled</a>() &amp;&amp; HCRX_EL2().FnXS == '1');
end;</pstext></ps>
    <ps name="shared/functions/tlbi/TLBI" mylink="shared.functions.tlbi.TLBI" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TLBI()
// ======
// Invalidates TLB entries for which TLBIMatch() returns TRUE.

impdef func TLBI(r : <a link="type_TLBIRecord" file="shared_pseudocode.xml">TLBIRecord</a>)
begin
    return;
end;</pstext></ps>
    <ps name="shared/functions/tlbi/TLBILevel" mylink="shared.functions.tlbi.TLBILevel" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TLBILevel
// =========

type <anchor link="type_TLBILevel">TLBILevel</anchor> of enumeration {
    <anchor link="enum_TLBILevel_Any">TLBILevel_Any</anchor>,        // this applies to TLB entries at all levels
    <anchor link="enum_TLBILevel_Last">TLBILevel_Last</anchor>        // this applies to TLB entries at last level only
};</pstext></ps>
    <ps name="shared/functions/tlbi/TLBIMemAttr" mylink="shared.functions.tlbi.TLBIMemAttr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TLBIMemAttr
// ===========
// Defines the attributes of the memory operations that must be completed in
// order to deem the TLBI operation as completed.

type <anchor link="type_TLBIMemAttr">TLBIMemAttr</anchor> of enumeration {
    <anchor link="enum_TLBI_AllAttr">TLBI_AllAttr</anchor>,         // All TLB entries within the scope of the invalidation
    <anchor link="enum_TLBI_ExcludeXS">TLBI_ExcludeXS</anchor>        // Only TLB entries with XS=0 within the scope of the invalidation
};</pstext></ps>
    <ps name="shared/functions/tlbi/TLBIOp" mylink="shared.functions.tlbi.TLBIOp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TLBIOp
// ======

type <anchor link="type_TLBIOp">TLBIOp</anchor> of enumeration {
    <anchor link="enum_TLBIOp_DALL">TLBIOp_DALL</anchor>,          // AArch32 Data TLBI operations - deprecated
    <anchor link="enum_TLBIOp_DASID">TLBIOp_DASID</anchor>,
    <anchor link="enum_TLBIOp_DVA">TLBIOp_DVA</anchor>,
    <anchor link="enum_TLBIOp_IALL">TLBIOp_IALL</anchor>,          // AArch32 Instruction TLBI operations - deprecated
    <anchor link="enum_TLBIOp_IASID">TLBIOp_IASID</anchor>,
    <anchor link="enum_TLBIOp_IVA">TLBIOp_IVA</anchor>,
    <anchor link="enum_TLBIOp_ALL">TLBIOp_ALL</anchor>,
    <anchor link="enum_TLBIOp_ASID">TLBIOp_ASID</anchor>,
    <anchor link="enum_TLBIOp_IPAS2">TLBIOp_IPAS2</anchor>,
    <anchor link="enum_TLBIPOp_IPAS2">TLBIPOp_IPAS2</anchor>,
    <anchor link="enum_TLBIOp_VAA">TLBIOp_VAA</anchor>,
    <anchor link="enum_TLBIOp_VA">TLBIOp_VA</anchor>,
    <anchor link="enum_TLBIPOp_VAA">TLBIPOp_VAA</anchor>,
    <anchor link="enum_TLBIPOp_VA">TLBIPOp_VA</anchor>,
    <anchor link="enum_TLBIOp_VMALL">TLBIOp_VMALL</anchor>,
    <anchor link="enum_TLBIOp_VMALLS12">TLBIOp_VMALLS12</anchor>,
    <anchor link="enum_TLBIOp_RIPAS2">TLBIOp_RIPAS2</anchor>,
    <anchor link="enum_TLBIPOp_RIPAS2">TLBIPOp_RIPAS2</anchor>,
    <anchor link="enum_TLBIOp_RVAA">TLBIOp_RVAA</anchor>,
    <anchor link="enum_TLBIOp_RVA">TLBIOp_RVA</anchor>,
    <anchor link="enum_TLBIPOp_RVAA">TLBIPOp_RVAA</anchor>,
    <anchor link="enum_TLBIPOp_RVA">TLBIPOp_RVA</anchor>,
    <anchor link="enum_TLBIOp_RPA">TLBIOp_RPA</anchor>,
    <anchor link="enum_TLBIOp_PAALL">TLBIOp_PAALL</anchor>,
    <anchor link="enum_TLBIOp_VMALLWS2">TLBIOp_VMALLWS2</anchor>
};</pstext></ps>
    <ps name="shared/functions/tlbi/TLBIRecord" mylink="shared.functions.tlbi.TLBIRecord" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TLBIRecord
// ==========
// Details related to a TLBI operation.

type <anchor link="type_TLBIRecord">TLBIRecord</anchor> of record {
    op : <a link="type_TLBIOp" file="shared_pseudocode.xml">TLBIOp</a>,
    from_aarch64 : boolean, // originated as an AArch64 operation
    security : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>,
    regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
    use_vmid : boolean,
    vmid : bits(NUM_VMIDBITS),
    asid : bits(NUM_ASIDBITS),
    level : <a link="type_TLBILevel" file="shared_pseudocode.xml">TLBILevel</a>,
    attr : <a link="type_TLBIMemAttr" file="shared_pseudocode.xml">TLBIMemAttr</a>,
    ipaspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>,     // For operations that take IPA as input address
    address : bits(64),     // input address, for range operations, start address
    end_address : bits(64), // for range operations, end; address
    d64 : boolean,          // For operations that evict VMSAv8-64 based TLB entries
    d128 : boolean,         // For operations that evict VMSAv9-128 based TLB entries
    ttl : bits(4),          // translation table walk level holding the leaf entry
                            // for the address being invalidated
                            // For Non-Range Invalidations:
                            //   When the ttl is
                            //     '00xx'    : this applies to all TLB entries
                            //     Otherwise : TLBIP instructions invalidates D128 TLB
                            //                 entries only
                            //                 TLBI instructions invalidates D64 TLB
                            //                 entries only
                            // For Range Invalidations:
                            //   When the ttl is
                            //     '00'      : this applies to all TLB entries
                            //     Otherwise : TLBIP instructions invalidates D128 TLB
                            //                 entries only
                            //                 TLBI instructions invalidates D64 TLB
                            //                 entries only
    tg : bits(2)            // for range operations, translation granule
};</pstext></ps>
    <ps name="shared/functions/tlbi/VMID" mylink="shared.functions.tlbi.VMID" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// VMID
// ====
// Effective VMID.

func <anchor link="func_VMID_0">VMID</anchor>() =&gt; bits(NUM_VMIDBITS)
begin
    if <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>() then
        if !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
            if IsFeatureImplemented(FEAT_VMID16) &amp;&amp; VTCR_EL2().VS == '1' then
                return VTTBR_EL2().VMID;
            else
                return ZeroExtend{NUM_VMIDBITS}(VTTBR_EL2().VMID[7:0]);
            end;
        else
            return ZeroExtend{NUM_VMIDBITS}(VTTBR().VMID);
        end;
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; IsFeatureImplemented(FEAT_SEL2) then
        return Zeros{NUM_VMIDBITS};
    else
        return <a link="global_VMID_NONE" file="shared_pseudocode.xml">VMID_NONE</a>;
    end;
end;</pstext></ps>
    <ps name="shared/functions/unbounded_configs/Maximum" mylink="shared.functions.unbounded_configs.Maximum" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Maximum walk levels
// ===================
let MAX_WALK_LEVELS : integer{} = (if IsFeatureImplemented(FEAT_D128) then 6
                                   else (if IsFeatureImplemented(FEAT_LPA2) then 5
                                   else 4));</pstext></ps>
    <ps name="shared/functions/unbounded_configs/Unbounded" mylink="shared.functions.unbounded_configs.Unbounded" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Unbounded Variables
// ===================
// Sets the upper limit for a specific loop or function.

constant <anchor link="global_Unbounded">Unbounded</anchor> : integer{} = 2^128;
config Unbounded_DiscardTransactionalWrites : integer{0..<a link="global_Unbounded" file="shared_pseudocode.xml">Unbounded</a>} = <a link="global_Unbounded" file="shared_pseudocode.xml">Unbounded</a>;
config Unbounded_DescriptorUpdate : integer{0..<a link="global_Unbounded" file="shared_pseudocode.xml">Unbounded</a>} = <a link="global_Unbounded" file="shared_pseudocode.xml">Unbounded</a>;
config Unbounded_semihost : integer{0..<a link="global_Unbounded" file="shared_pseudocode.xml">Unbounded</a>} = <a link="global_Unbounded" file="shared_pseudocode.xml">Unbounded</a>;
config Unbounded_ParseTrace : integer{0..<a link="global_Unbounded" file="shared_pseudocode.xml">Unbounded</a>} = <a link="global_Unbounded" file="shared_pseudocode.xml">Unbounded</a>;
config Unbounded_ParseExtensionPacket : integer{0..<a link="global_Unbounded" file="shared_pseudocode.xml">Unbounded</a>} = <a link="global_Unbounded" file="shared_pseudocode.xml">Unbounded</a>;
config Unbounded_ULEB128 : integer{0..<a link="global_Unbounded" file="shared_pseudocode.xml">Unbounded</a>} = <a link="global_Unbounded" file="shared_pseudocode.xml">Unbounded</a>;
config Unbounded_ULEB128n : integer{0..<a link="global_Unbounded" file="shared_pseudocode.xml">Unbounded</a>} = <a link="global_Unbounded" file="shared_pseudocode.xml">Unbounded</a>;
config Unbounded_FloorPow2 : integer{0..<a link="global_Unbounded" file="shared_pseudocode.xml">Unbounded</a>} = <a link="global_Unbounded" file="shared_pseudocode.xml">Unbounded</a>;
config Unbounded_NormalizeReal : integer{0..<a link="global_Unbounded" file="shared_pseudocode.xml">Unbounded</a>} = <a link="global_Unbounded" file="shared_pseudocode.xml">Unbounded</a>;</pstext></ps>
    <ps name="shared/functions/unpredictable/ConstrainUnpredictable" mylink="shared.functions.unpredictable.ConstrainUnpredictable" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ConstrainUnpredictable()
// ========================
// Return the appropriate Constraint result to control the caller's behavior.
// The return value is IMPLEMENTATION DEFINED within a permitted list for each
// UNPREDICTABLE case.
// (The permitted list is determined by an assert or case statement at the call site.)

readonly impdef func <anchor link="func_ConstrainUnpredictable_0">ConstrainUnpredictable</anchor>(which : <a link="type_Unpredictable" file="shared_pseudocode.xml">Unpredictable</a>) =&gt; <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>
begin
    case which of
        when <a link="enum_Unpredictable_VMSR" file="shared_pseudocode.xml">Unpredictable_VMSR</a> =&gt;
            return <a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a>;
        when <a link="enum_Unpredictable_WBOVERLAPLD" file="shared_pseudocode.xml">Unpredictable_WBOVERLAPLD</a> =&gt;
            return <a link="enum_Constraint_WBSUPPRESS" file="shared_pseudocode.xml">Constraint_WBSUPPRESS</a>; // return loaded value
        when <a link="enum_Unpredictable_WBOVERLAPST" file="shared_pseudocode.xml">Unpredictable_WBOVERLAPST</a> =&gt;
            return <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>;     // store pre-writeback value
        when <a link="enum_Unpredictable_LDPOVERLAP" file="shared_pseudocode.xml">Unpredictable_LDPOVERLAP</a> =&gt;
            return <a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a>;    // instruction is UNDEFINED
        when <a link="enum_Unpredictable_BASEOVERLAP" file="shared_pseudocode.xml">Unpredictable_BASEOVERLAP</a> =&gt;
            return <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>;  // use UNKNOWN address
        when <a link="enum_Unpredictable_DATAOVERLAP" file="shared_pseudocode.xml">Unpredictable_DATAOVERLAP</a> =&gt;
            return <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>;  // store UNKNOWN value
        when <a link="enum_Unpredictable_DEVPAGE2" file="shared_pseudocode.xml">Unpredictable_DEVPAGE2</a> =&gt;
            return <a link="enum_Constraint_FAULT" file="shared_pseudocode.xml">Constraint_FAULT</a>;    // take an alignment fault
        when <a link="enum_Unpredictable_RESTCF" file="shared_pseudocode.xml">Unpredictable_RESTCF</a> =&gt;
            return <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>;  // Do not take a fault
        when <a link="enum_Unpredictable_DEVICETAGSTORE" file="shared_pseudocode.xml">Unpredictable_DEVICETAGSTORE</a> =&gt;
            return <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>;     // Do not take a fault
        when <a link="enum_Unpredictable_INSTRDEVICE" file="shared_pseudocode.xml">Unpredictable_INSTRDEVICE</a> =&gt;
            return <a link="enum_Constraint_NONE" file="shared_pseudocode.xml">Constraint_NONE</a>;     // Do not take a fault
        when <a link="enum_Unpredictable_RESCPACR" file="shared_pseudocode.xml">Unpredictable_RESCPACR</a> =&gt;
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;     // Map to UNKNOWN value
        when <a link="enum_Unpredictable_RESMAIR" file="shared_pseudocode.xml">Unpredictable_RESMAIR</a> =&gt;
            return <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>;  // Map to UNKNOWN value
        when <a link="enum_Unpredictable_S1CTAGGED" file="shared_pseudocode.xml">Unpredictable_S1CTAGGED</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // SCTLR_ELx.C == '0' marks address as untagged
        when <a link="enum_Unpredictable_S2RESMEMATTR" file="shared_pseudocode.xml">Unpredictable_S2RESMEMATTR</a> =&gt;
            return <a link="enum_Constraint_NC" file="shared_pseudocode.xml">Constraint_NC</a>;       // Map to Noncacheable value
        when <a link="enum_Unpredictable_RESTEXCB" file="shared_pseudocode.xml">Unpredictable_RESTEXCB</a> =&gt;
            return <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>;  // Map to UNKNOWN value
        when <a link="enum_Unpredictable_RESDACR" file="shared_pseudocode.xml">Unpredictable_RESDACR</a> =&gt;
            return <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>;  // Map to UNKNOWN value
        when <a link="enum_Unpredictable_RESPRRR" file="shared_pseudocode.xml">Unpredictable_RESPRRR</a> =&gt;
            return <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>;  // Map to UNKNOWN value
        when <a link="enum_Unpredictable_RESVTCRS" file="shared_pseudocode.xml">Unpredictable_RESVTCRS</a> =&gt;
            return <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>;  // Map to UNKNOWN value
        when <a link="enum_Unpredictable_RESTnSZ" file="shared_pseudocode.xml">Unpredictable_RESTnSZ</a> =&gt;
            return <a link="enum_Constraint_FORCE" file="shared_pseudocode.xml">Constraint_FORCE</a>;    // Map to the limit value
        when <a link="enum_Unpredictable_OORTnSZ" file="shared_pseudocode.xml">Unpredictable_OORTnSZ</a> =&gt;
            return <a link="enum_Constraint_FORCE" file="shared_pseudocode.xml">Constraint_FORCE</a>;    // Map to the limit value
        when <a link="enum_Unpredictable_LARGEIPA" file="shared_pseudocode.xml">Unpredictable_LARGEIPA</a> =&gt;
            return <a link="enum_Constraint_FORCE" file="shared_pseudocode.xml">Constraint_FORCE</a>;    // Restrict the IA size to the PAMax value
        when <a link="enum_Unpredictable_ESRCONDPASS" file="shared_pseudocode.xml">Unpredictable_ESRCONDPASS</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // Report as &quot;AL&quot;
        when <a link="enum_Unpredictable_ILZEROIT" file="shared_pseudocode.xml">Unpredictable_ILZEROIT</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // Do not zero PSTATE.IT
        when <a link="enum_Unpredictable_ILZEROT" file="shared_pseudocode.xml">Unpredictable_ILZEROT</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // Do not zero PSTATE.T
        when <a link="enum_Unpredictable_BPVECTORCATCHPRI" file="shared_pseudocode.xml">Unpredictable_BPVECTORCATCHPRI</a> =&gt;
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;     // Debug Vector Catch: match on 2nd halfword
        when <a link="enum_Unpredictable_VCMATCHHALF" file="shared_pseudocode.xml">Unpredictable_VCMATCHHALF</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // No match
        when <a link="enum_Unpredictable_VCMATCHDAPA" file="shared_pseudocode.xml">Unpredictable_VCMATCHDAPA</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // No match on Data Abort or Prefetch abort
        when <a link="enum_Unpredictable_WPMASKANDBAS" file="shared_pseudocode.xml">Unpredictable_WPMASKANDBAS</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // Watchpoint disabled
        when <a link="enum_Unpredictable_WPBASCONTIGUOUS" file="shared_pseudocode.xml">Unpredictable_WPBASCONTIGUOUS</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // Watchpoint disabled
        when <a link="enum_Unpredictable_RESWPMASK" file="shared_pseudocode.xml">Unpredictable_RESWPMASK</a> =&gt;
            return <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>; // Watchpoint disabled
        when <a link="enum_Unpredictable_WPMASKEDBITS" file="shared_pseudocode.xml">Unpredictable_WPMASKEDBITS</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // Watchpoint disabled
        when <a link="enum_Unpredictable_RESBPWPCTRL" file="shared_pseudocode.xml">Unpredictable_RESBPWPCTRL</a> =&gt;
            return <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>; // Breakpoint/watchpoint disabled
        when <a link="enum_Unpredictable_BPNOTIMPL" file="shared_pseudocode.xml">Unpredictable_BPNOTIMPL</a> =&gt;
            return <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>; // Breakpoint disabled
        when <a link="enum_Unpredictable_RESBPTYPE" file="shared_pseudocode.xml">Unpredictable_RESBPTYPE</a> =&gt;
            return <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>; // Breakpoint disabled
        when <a link="enum_Unpredictable_BPNOTCTXCMP" file="shared_pseudocode.xml">Unpredictable_BPNOTCTXCMP</a> =&gt;
            return <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>; // Breakpoint disabled
        when <a link="enum_Unpredictable_RESMDSELR" file="shared_pseudocode.xml">Unpredictable_RESMDSELR</a> =&gt;
            return <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>;  // Map to UNKNOWN value
        when <a link="enum_Unpredictable_BPMATCHHALF" file="shared_pseudocode.xml">Unpredictable_BPMATCHHALF</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // No match
        when <a link="enum_Unpredictable_BPMISMATCHHALF" file="shared_pseudocode.xml">Unpredictable_BPMISMATCHHALF</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // No match
        when <a link="enum_Unpredictable_BPLINKINGDISABLED" file="shared_pseudocode.xml">Unpredictable_BPLINKINGDISABLED</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // Breakpoint does not match
        when <a link="enum_Unpredictable_RESTARTALIGNPC" file="shared_pseudocode.xml">Unpredictable_RESTARTALIGNPC</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // Do not force alignment
        when <a link="enum_Unpredictable_RESTARTZEROUPPERPC" file="shared_pseudocode.xml">Unpredictable_RESTARTZEROUPPERPC</a> =&gt;
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;     // Force zero extension
        when <a link="enum_Unpredictable_ZEROUPPER" file="shared_pseudocode.xml">Unpredictable_ZEROUPPER</a> =&gt;
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;     // zero top halves of X registers
        when <a link="enum_Unpredictable_ERETZEROUPPERPC" file="shared_pseudocode.xml">Unpredictable_ERETZEROUPPERPC</a> =&gt;
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;     // zero top half of PC
        when <a link="enum_Unpredictable_A32FORCEALIGNPC" file="shared_pseudocode.xml">Unpredictable_A32FORCEALIGNPC</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // Do not force alignment
        when <a link="enum_Unpredictable_SMD" file="shared_pseudocode.xml">Unpredictable_SMD</a> =&gt;
            return <a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a>;    // disabled SMC is Unallocated
        when <a link="enum_Unpredictable_NONFAULT" file="shared_pseudocode.xml">Unpredictable_NONFAULT</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // Speculation enabled
        when <a link="enum_Unpredictable_SVEZEROUPPER" file="shared_pseudocode.xml">Unpredictable_SVEZEROUPPER</a> =&gt;
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;     // zero top bits of Z registers
        when <a link="enum_Unpredictable_SVELDNFDATA" file="shared_pseudocode.xml">Unpredictable_SVELDNFDATA</a> =&gt;
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;     // Load mem data in NF loads
        when <a link="enum_Unpredictable_SVELDNFZERO" file="shared_pseudocode.xml">Unpredictable_SVELDNFZERO</a> =&gt;
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;     // Write zeros in NF loads
        when <a link="enum_Unpredictable_CHECKSPNONEACTIVE" file="shared_pseudocode.xml">Unpredictable_CHECKSPNONEACTIVE</a> =&gt;
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;     // Check SP alignment
        when <a link="enum_Unpredictable_SMEZEROUPPER" file="shared_pseudocode.xml">Unpredictable_SMEZEROUPPER</a> =&gt;
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;     // zero top bits of ZA registers
        when <a link="enum_Unpredictable_NVNV1" file="shared_pseudocode.xml">Unpredictable_NVNV1</a> =&gt;
            return <a link="enum_Constraint_NVNV1_00" file="shared_pseudocode.xml">Constraint_NVNV1_00</a>; // Map unpredictable configuration of HCR_EL2[NV,NV1]
                                        // to NV = 0 and NV1 = 0
        when <a link="enum_Unpredictable_BADDR_RESS" file="shared_pseudocode.xml">Unpredictable_BADDR_RESS</a> =&gt;
            return <a link="enum_Constraint_RESS" file="shared_pseudocode.xml">Constraint_RESS</a>;     // Values behave as RESS
        when <a link="enum_Unpredictable_Shareability" file="shared_pseudocode.xml">Unpredictable_Shareability</a> =&gt;
            return <a link="enum_Constraint_OSH" file="shared_pseudocode.xml">Constraint_OSH</a>;      // Map reserved encoding of shareability to Outer Shareable
        when <a link="enum_Unpredictable_AFUPDATE" file="shared_pseudocode.xml">Unpredictable_AFUPDATE</a> =&gt;  // AF update for alignment or Permission fault
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;
        when <a link="enum_Unpredictable_DBUPDATE" file="shared_pseudocode.xml">Unpredictable_DBUPDATE</a> =&gt;  // DB State update for alignment fault
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;
        when <a link="enum_Unpredictable_Unsupported_Atomic_HW_Update" file="shared_pseudocode.xml">Unpredictable_Unsupported_Atomic_HW_Update</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // Do not raise Unsupported Atomic HW Update fault
                                        // when encountering unsupported memory attributes
        when <a link="enum_Unpredictable_IESBinDebug" file="shared_pseudocode.xml">Unpredictable_IESBinDebug</a> =&gt;  // Use SCTLR_ELx[].IESB in Debug state
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;
        when <a link="enum_Unpredictable_BADPMSFCR" file="shared_pseudocode.xml">Unpredictable_BADPMSFCR</a> =&gt;    // Bad settings for PMSFCR_EL1/PMSEVFR_EL1/PMSLATFR_EL1
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;
        when <a link="enum_Unpredictable_RES_PMU_VS" file="shared_pseudocode.xml">Unpredictable_RES_PMU_VS</a> =&gt;   // Bad setting for SVE Streaming mode filter
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;
        when <a link="enum_Unpredictable_COUNT_CHAIN" file="shared_pseudocode.xml">Unpredictable_COUNT_CHAIN</a> =&gt;  // Chained PMU counters idx, idx+1 are not in same range
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;
        when <a link="enum_Unpredictable_EL1TIMESTAMP" file="shared_pseudocode.xml">Unpredictable_EL1TIMESTAMP</a> =&gt; // Bad settings for TRFCR_EL1
            return <a link="enum_Constraint_EL1TIMESTAMP" file="shared_pseudocode.xml">Constraint_EL1TIMESTAMP</a>;
        when <a link="enum_Unpredictable_EL2TIMESTAMP" file="shared_pseudocode.xml">Unpredictable_EL2TIMESTAMP</a> =&gt; // Bad settings for TRFCR_EL2
            return <a link="enum_Constraint_EL2TIMESTAMP" file="shared_pseudocode.xml">Constraint_EL2TIMESTAMP</a>;
        when <a link="enum_Unpredictable_ZEROBTYPE" file="shared_pseudocode.xml">Unpredictable_ZEROBTYPE</a> =&gt;
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;           // Save BTYPE in SPSR_ELx/DPSR_EL0 as '00'
        when <a link="enum_Unpredictable_CLEARERRITEZERO" file="shared_pseudocode.xml">Unpredictable_CLEARERRITEZERO</a> =&gt; // Clearing sticky errors when instruction in flight
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;
        when <a link="enum_Unpredictable_ALUEXCEPTIONRETURN" file="shared_pseudocode.xml">Unpredictable_ALUEXCEPTIONRETURN</a> =&gt;
            return <a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a>;
        when <a link="enum_Unpredictable_DBGxVR_RESS" file="shared_pseudocode.xml">Unpredictable_DBGxVR_RESS</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;
        when <a link="enum_Unpredictable_PMSCR_PCT" file="shared_pseudocode.xml">Unpredictable_PMSCR_PCT</a> =&gt;
            return <a link="enum_Constraint_PMSCR_PCT_VIRT" file="shared_pseudocode.xml">Constraint_PMSCR_PCT_VIRT</a>;
        when <a link="enum_Unpredictable_WFxTDEBUG" file="shared_pseudocode.xml">Unpredictable_WFxTDEBUG</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // WFxT in Debug state does not execute as a NOP
        // Accesses are not single-copy atomic above the byte level
        when <a link="enum_Unpredictable_LS64UNSUPPORTED" file="shared_pseudocode.xml">Unpredictable_LS64UNSUPPORTED</a> =&gt;
            return <a link="enum_Constraint_LIMITED_ATOMICITY" file="shared_pseudocode.xml">Constraint_LIMITED_ATOMICITY</a>;
        // Unaligned exclusives, atomics, acquire/release
        // to a region that is not to Normal inner write-back
        // outer write-back shareable generate an Alignment fault.
        when <a link="enum_Unpredictable_LSE2_ALIGNMENT_FAULT" file="shared_pseudocode.xml">Unpredictable_LSE2_ALIGNMENT_FAULT</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;
        when <a link="enum_Unpredictable_LSE128OVERLAP" file="shared_pseudocode.xml">Unpredictable_LSE128OVERLAP</a> =&gt;
            return <a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a>;    // instruction is UNDEFINED
        when <a link="enum_Unpredictable_IGNORETRAPINDEBUG" file="shared_pseudocode.xml">Unpredictable_IGNORETRAPINDEBUG</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // Trap to register access in debug state is enabled
        when <a link="enum_Unpredictable_PMUEVENTCOUNTER" file="shared_pseudocode.xml">Unpredictable_PMUEVENTCOUNTER</a> =&gt;
            return <a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a>;    // Accesses to the register are UNDEFINED
        when <a link="enum_Unpredictable_RES_HPMN" file="shared_pseudocode.xml">Unpredictable_RES_HPMN</a> =&gt;
            return <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>;  // The counter is reserved for EL2 use
        when <a link="enum_Unpredictable_RES_EPMN" file="shared_pseudocode.xml">Unpredictable_RES_EPMN</a> =&gt;
            return <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>;  // The counter is reserved for external use
        when <a link="enum_Unpredictable_BRBFILTRATE" file="shared_pseudocode.xml">Unpredictable_BRBFILTRATE</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // BRB_FILTRATE event not generated on BRB injection
        when <a link="enum_Unpredictable_PMUSNAPSHOTEVENT" file="shared_pseudocode.xml">Unpredictable_PMUSNAPSHOTEVENT</a> =&gt; // PMU_SNAPSHOT event not generated in Debug state
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;
        when <a link="enum_Unpredictable_RESEPMSSAD" file="shared_pseudocode.xml">Unpredictable_RESEPMSSAD</a> =&gt;
            // External access to PMUv3 Snapshot extension allowed in Secure state
            // when FEAT_RME is not implemented or Root state otherwise
            return <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a>;
        when <a link="enum_Unpredictable_RESPMSSE" file="shared_pseudocode.xml">Unpredictable_RESPMSSE</a> =&gt;
            return <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>;   // PMU capture events disabled
        when <a link="enum_Unpredictable_RESPMEE" file="shared_pseudocode.xml">Unpredictable_RESPMEE</a> =&gt;
            return <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>;   // PMU Profiling exception disabled, PMUIRQ enabled
        when <a link="enum_Unpredictable_RESPMSEE" file="shared_pseudocode.xml">Unpredictable_RESPMSEE</a> =&gt;
            return <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>;   // SPE Profiling exception disabled
        when <a link="enum_Unpredictable_RESTRFEE" file="shared_pseudocode.xml">Unpredictable_RESTRFEE</a> =&gt;
            return <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>;   // TRBE Profiling exception disabled
        when <a link="enum_Unpredictable_RESTC" file="shared_pseudocode.xml">Unpredictable_RESTC</a> =&gt;
            return <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>;   // Threshold features disabled
        when <a link="enum_Unpredictable_MOPSOVERLAP" file="shared_pseudocode.xml">Unpredictable_MOPSOVERLAP</a> =&gt; // Instruction is UNDEFINED
            return <a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a>;
        when <a link="enum_Unpredictable_MOPS_R31" file="shared_pseudocode.xml">Unpredictable_MOPS_R31</a> =&gt;    // Instruction is UNDEFINED
            return <a link="enum_Constraint_UNDEF" file="shared_pseudocode.xml">Constraint_UNDEF</a>;
        when <a link="enum_Unpredictable_CASRETURNOLDVALUE" file="shared_pseudocode.xml">Unpredictable_CASRETURNOLDVALUE</a> =&gt;
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;
        when <a link="enum_Unpredictable_WRITEFAILEDCAS" file="shared_pseudocode.xml">Unpredictable_WRITEFAILEDCAS</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;
        when <a link="enum_Unpredictable_WRITEFAILEDRCWCAS" file="shared_pseudocode.xml">Unpredictable_WRITEFAILEDRCWCAS</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;
        when <a link="enum_Unpredictable_STRONLYTAGCHECKEDCAS" file="shared_pseudocode.xml">Unpredictable_STRONLYTAGCHECKEDCAS</a> =&gt;
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;     // CAS with compare fail does a Tag Check
        when <a link="enum_Unpredictable_STRONLYTAGCHECKEDRCWSCAS" file="shared_pseudocode.xml">Unpredictable_STRONLYTAGCHECKEDRCWSCAS</a> =&gt;
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;     // RCW(S)CAS with RCW(S) fail/compare fail does a Tag Check
        when <a link="enum_Unpredictable_RESERVEDNSxB" file="shared_pseudocode.xml">Unpredictable_RESERVEDNSxB</a> =&gt;
            return <a link="enum_Constraint_MAPTOALLOCATED" file="shared_pseudocode.xml">Constraint_MAPTOALLOCATED</a>;
        when <a link="enum_Unpredictable_RESERVEDNSxB_Trap" file="shared_pseudocode.xml">Unpredictable_RESERVEDNSxB_Trap</a> =&gt;
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;
        when <a link="enum_Unpredictable_RES_ETBAD" file="shared_pseudocode.xml">Unpredictable_RES_ETBAD</a> =&gt;
            // ExternalTracebufferaccess disabled for res values
            return <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>;
        when <a link="enum_Unpredictable_RESBPMASK" file="shared_pseudocode.xml">Unpredictable_RESBPMASK</a> =&gt;
            return <a link="enum_Constraint_DISABLED" file="shared_pseudocode.xml">Constraint_DISABLED</a>; // Mask set to 0
        when <a link="enum_Unpredictable_BPMASK" file="shared_pseudocode.xml">Unpredictable_BPMASK</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // Breakpoint match will fail
        when <a link="enum_Unpredictable_BPMASKEDBITS" file="shared_pseudocode.xml">Unpredictable_BPMASKEDBITS</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // Breakpoint match will fail
        when <a link="enum_Unpredictable_BPLINKEDADDRMATCH" file="shared_pseudocode.xml">Unpredictable_BPLINKEDADDRMATCH</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;    // Breakpoint match will fail
        when <a link="enum_Unpredictable_16BYTEROUNDEDUPACCESS" file="shared_pseudocode.xml">Unpredictable_16BYTEROUNDEDUPACCESS</a> =&gt;
            // Watchpoint match of 16 byte rounded range in case of SVE access
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;
        when <a link="enum_Unpredictable_16BYTEROUNDEDDOWNACCESS" file="shared_pseudocode.xml">Unpredictable_16BYTEROUNDEDDOWNACCESS</a> =&gt;
            // Watchpoint match of 16 byte rounded range in case of SVE access
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;
        when <a link="enum_Unpredictable_NODTRTAGCHK" file="shared_pseudocode.xml">Unpredictable_NODTRTAGCHK</a> =&gt;
            // The load or store operation does not perform the Tag check in Debug state
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;
        when <a link="enum_Unpredictable_CPACHECK" file="shared_pseudocode.xml">Unpredictable_CPACHECK</a> =&gt;     // Do not perform Checked Pointer Arithmetic
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;
        when <a link="enum_Unpredictable_Atomic_SYNC_ABORT" file="shared_pseudocode.xml">Unpredictable_Atomic_SYNC_ABORT</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;
        when <a link="enum_Unpredictable_Atomic_SERROR" file="shared_pseudocode.xml">Unpredictable_Atomic_SERROR</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;
        when <a link="enum_Unpredictable_Atomic_NOP" file="shared_pseudocode.xml">Unpredictable_Atomic_NOP</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;
        when <a link="enum_Unpredictable_Atomic_MMU_IMPDEF_FAULT" file="shared_pseudocode.xml">Unpredictable_Atomic_MMU_IMPDEF_FAULT</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;
        when <a link="enum_Unpredictable_USE_DEFAULT_PMG" file="shared_pseudocode.xml">Unpredictable_USE_DEFAULT_PMG</a> =&gt;
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;
        when <a link="enum_Unpredictable_BankedRegister" file="shared_pseudocode.xml">Unpredictable_BankedRegister</a> =&gt;
            return <a link="enum_Constraint_NOP" file="shared_pseudocode.xml">Constraint_NOP</a>;
        when <a link="enum_Unpredictable_UnimplementedRegister" file="shared_pseudocode.xml">Unpredictable_UnimplementedRegister</a> =&gt;
            return <a link="enum_Constraint_NOP" file="shared_pseudocode.xml">Constraint_NOP</a>;
        when <a link="enum_Unpredictable_RES_RA" file="shared_pseudocode.xml">Unpredictable_RES_RA</a> =&gt;
            return <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>;
        when <a link="enum_Unpredictable_BPNOTLINKING" file="shared_pseudocode.xml">Unpredictable_BPNOTLINKING</a> =&gt;
            return <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>;
        otherwise =&gt;
            unreachable;
    end;
end;</pstext></ps>
    <ps name="shared/functions/unpredictable/ConstrainUnpredictableBits" mylink="shared.functions.unpredictable.ConstrainUnpredictableBits" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ConstrainUnpredictableBits()
// ============================

// This is a variant of ConstrainUnpredictable for when the result can be Constraint_UNKNOWN.
// If the result is Constraint_UNKNOWN then the function also returns UNKNOWN value, but that
// value is always an allocated value; that is, one for which the behavior is not itself
// CONSTRAINED.

readonly impdef func <anchor link="func_ConstrainUnpredictableBits_0">ConstrainUnpredictableBits</anchor>{width}(which : <a link="type_Unpredictable" file="shared_pseudocode.xml">Unpredictable</a>
                                                      ) =&gt; (<a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>, bits(width))
begin
    let c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = ConstrainUnpredictable(which);

    case c of
        when <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a> =&gt;
            return (c, Zeros{width});     // See notes; this is an example implementation only
        when <a link="enum_Constraint_PMSCR_PCT_VIRT" file="shared_pseudocode.xml">Constraint_PMSCR_PCT_VIRT</a> =&gt;
            return (c, Zeros{width});
        when <a link="enum_Constraint_NC" file="shared_pseudocode.xml">Constraint_NC</a> where which == <a link="enum_Unpredictable_S2RESMEMATTR" file="shared_pseudocode.xml">Unpredictable_S2RESMEMATTR</a> =&gt;
            assert width == 4;
            return (c, ZeroExtend{width}('0101'));
        when <a link="enum_Constraint_WT" file="shared_pseudocode.xml">Constraint_WT</a> where which == <a link="enum_Unpredictable_S2RESMEMATTR" file="shared_pseudocode.xml">Unpredictable_S2RESMEMATTR</a> =&gt;
            assert width == 4;
            return (c, ZeroExtend{width}('1010'));
        when <a link="enum_Constraint_WB" file="shared_pseudocode.xml">Constraint_WB</a> where which == <a link="enum_Unpredictable_S2RESMEMATTR" file="shared_pseudocode.xml">Unpredictable_S2RESMEMATTR</a> =&gt;
            assert width == 4;
            return (c, ZeroExtend{width}('1111'));
        when <a link="enum_Constraint_EL1TIMESTAMP" file="shared_pseudocode.xml">Constraint_EL1TIMESTAMP</a> =&gt;
            return (c, ZeroExtend{width}('01'));
        when <a link="enum_Constraint_EL2TIMESTAMP" file="shared_pseudocode.xml">Constraint_EL2TIMESTAMP</a> =&gt;
            return (c, ZeroExtend{width}('01'));
        when <a link="enum_Constraint_MAPTOALLOCATED" file="shared_pseudocode.xml">Constraint_MAPTOALLOCATED</a> =&gt;
            return (c, ZeroExtend{width}('010'));  // return non-secure state_bits
        otherwise =&gt;
            return (c, ARBITRARY : bits(width));   // bits result not used
    end;
end;</pstext></ps>
    <ps name="shared/functions/unpredictable/ConstrainUnpredictableBool" mylink="shared.functions.unpredictable.ConstrainUnpredictableBool" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ConstrainUnpredictableBool()
// ============================
// This is a variant of the ConstrainUnpredictable function where the result is either
// Constraint_TRUE or Constraint_FALSE.

impdef func <anchor link="func_ConstrainUnpredictableBool_1">ConstrainUnpredictableBool</anchor>(which : <a link="type_Unpredictable" file="shared_pseudocode.xml">Unpredictable</a>) =&gt; boolean
begin
    let c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = ConstrainUnpredictable(which);
    assert c IN {<a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>, <a link="enum_Constraint_FALSE" file="shared_pseudocode.xml">Constraint_FALSE</a>};
    return (c == <a link="enum_Constraint_TRUE" file="shared_pseudocode.xml">Constraint_TRUE</a>);
end;</pstext></ps>
    <ps name="shared/functions/unpredictable/ConstrainUnpredictableInteger" mylink="shared.functions.unpredictable.ConstrainUnpredictableInteger" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ConstrainUnpredictableInteger()
// ===============================
// This is a variant of ConstrainUnpredictable for when the result can be Constraint_UNKNOWN.
// If the result is Constraint_UNKNOWN then the function also returns an UNKNOWN
// value in the range low to high, inclusive.

impdef func <anchor link="func_ConstrainUnpredictableInteger_3">ConstrainUnpredictableInteger</anchor>(low : integer,
                                          high : integer,
                                          which : <a link="type_Unpredictable" file="shared_pseudocode.xml">Unpredictable</a>) =&gt; (<a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a>,integer)
begin
    let c : <a link="type_Constraint" file="shared_pseudocode.xml">Constraint</a> = ConstrainUnpredictable(which);
    if c == <a link="enum_Constraint_UNKNOWN" file="shared_pseudocode.xml">Constraint_UNKNOWN</a> then
        return (c, low);                 // See notes; this is an example implementation only
    else
        return (c, ARBITRARY : integer); // integer result not used
    end;
end;</pstext></ps>
    <ps name="shared/functions/unpredictable/ConstrainUnpredictableProcedure" mylink="shared.functions.unpredictable.ConstrainUnpredictableProcedure" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ConstrainUnpredictableProcedure()
// =================================
// This is a variant of ConstrainUnpredictable that implements a Constrained
// Unpredictable behavior for a given Unpredictable situation.
// The behavior is within permitted behaviors for a given Unpredictable situation,
// these are documented in the textual part of the architecture specification.
//
// This function is expected to be refined in an IMPLEMENTATION DEFINED manner.
// The details of possible outcomes may not be present in the code and must be interpreted
// for each use with respect to the CONSTRAINED UNPREDICTABLE specifications
// for the specific area.

impdef func ConstrainUnpredictableProcedure(which : <a link="type_Unpredictable" file="shared_pseudocode.xml">Unpredictable</a>)
begin
    case which of
        when <a link="enum_Unpredictable_PMUEVENTCOUNTER" file="shared_pseudocode.xml">Unpredictable_PMUEVENTCOUNTER</a> =&gt;
            Undefined();
        when <a link="enum_Unpredictable_MRC_APSR_TARGET" file="shared_pseudocode.xml">Unpredictable_MRC_APSR_TARGET</a> =&gt;
            PSTATE.[N,Z,C,V] = DBGDSCRint()[31:28];
        otherwise =&gt;
            ImpDef(&quot;IMPLEMENTATION_DEFINED&quot;);
    end;
    return;
end;</pstext></ps>
    <ps name="shared/functions/unpredictable/Constraint" mylink="shared.functions.unpredictable.Constraint" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Constraint
// ==========
// List of Constrained Unpredictable behaviors.

type <anchor link="type_Constraint">Constraint</anchor> of enumeration {
                           // General
                           <anchor link="enum_Constraint_NONE">Constraint_NONE</anchor>,              // Instruction executes with
                                                         // no change or side-effect
                                                         // to its described behavior
                           <anchor link="enum_Constraint_UNKNOWN">Constraint_UNKNOWN</anchor>,           // Destination register
                                                         // has UNKNOWN value
                           <anchor link="enum_Constraint_UNDEF">Constraint_UNDEF</anchor>,             // Instruction is UNDEFINED
                           <anchor link="enum_Constraint_UNDEFEL0">Constraint_UNDEFEL0</anchor>,          // Instruction is UNDEFINED at EL0 only
                           <anchor link="enum_Constraint_NOP">Constraint_NOP</anchor>,               // Instruction executes as NOP
                           <anchor link="enum_Constraint_TRUE">Constraint_TRUE</anchor>,
                           <anchor link="enum_Constraint_FALSE">Constraint_FALSE</anchor>,
                           <anchor link="enum_Constraint_DISABLED">Constraint_DISABLED</anchor>,
                           <anchor link="enum_Constraint_UNCOND">Constraint_UNCOND</anchor>,            // Instruction executes unconditionally
                           <anchor link="enum_Constraint_COND">Constraint_COND</anchor>,              // Instruction executes conditionally
                           <anchor link="enum_Constraint_ADDITIONAL_DECODE">Constraint_ADDITIONAL_DECODE</anchor>, // Instruction executes
                                                         // with additional decode
                           // Load-store
                           <anchor link="enum_Constraint_WBSUPPRESS">Constraint_WBSUPPRESS</anchor>,
                           <anchor link="enum_Constraint_FAULT">Constraint_FAULT</anchor>,
                           <anchor link="enum_Constraint_LIMITED_ATOMICITY">Constraint_LIMITED_ATOMICITY</anchor>, // Accesses are not
                                                         // single-copy atomic
                                                         // above the byte level
                           <anchor link="enum_Constraint_NVNV1_00">Constraint_NVNV1_00</anchor>,
                           <anchor link="enum_Constraint_NVNV1_01">Constraint_NVNV1_01</anchor>,
                           <anchor link="enum_Constraint_NVNV1_11">Constraint_NVNV1_11</anchor>,
                           <anchor link="enum_Constraint_EL1TIMESTAMP">Constraint_EL1TIMESTAMP</anchor>,      // Constrain to Virtual Timestamp
                           <anchor link="enum_Constraint_EL2TIMESTAMP">Constraint_EL2TIMESTAMP</anchor>,      // Constrain to Virtual Timestamp
                           <anchor link="enum_Constraint_OSH">Constraint_OSH</anchor>,               // Constrain to Outer Shareable
                           <anchor link="enum_Constraint_ISH">Constraint_ISH</anchor>,               // Constrain to Inner Shareable
                           <anchor link="enum_Constraint_NSH">Constraint_NSH</anchor>,               // Constrain to Nonshareable

                           <anchor link="enum_Constraint_NC">Constraint_NC</anchor>,                // Constrain to Noncacheable
                           <anchor link="enum_Constraint_WT">Constraint_WT</anchor>,                // Constrain to Writethrough
                           <anchor link="enum_Constraint_WB">Constraint_WB</anchor>,                // Constrain to Writeback
                           <anchor link="enum_Constraint_RESS">Constraint_RESS</anchor>,              // Bits behave as RESS for all purposes
                                                         // other than reading back the register
                           <anchor link="enum_Constraint_ALLRESS">Constraint_ALLRESS</anchor>,           // Bits behave as RESS for all purposes

                           // IPA too large
                           <anchor link="enum_Constraint_FORCE">Constraint_FORCE</anchor>, <anchor link="enum_Constraint_FORCENOSLCHECK">Constraint_FORCENOSLCHECK</anchor>,
                           // An unallocated System register value maps onto an allocated value
                           <anchor link="enum_Constraint_MAPTOALLOCATED">Constraint_MAPTOALLOCATED</anchor>,
                           // PMSCR_PCT reserved values select Virtual timestamp
                           <anchor link="enum_Constraint_PMSCR_PCT_VIRT">Constraint_PMSCR_PCT_VIRT</anchor>,
                           <anchor link="enum_Constraint_ANYREG">Constraint_ANYREG</anchor>,            // Any allocated register is chosen
};</pstext></ps>
    <ps name="shared/functions/unpredictable/Unpredictable" mylink="shared.functions.unpredictable.Unpredictable" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Unpredictable
// =============
// List of Constrained Unpredictable situations.

type <anchor link="type_Unpredictable">Unpredictable</anchor> of enumeration {
                           // VMSR on MVFR
                           <anchor link="enum_Unpredictable_VMSR">Unpredictable_VMSR</anchor>,
                           // Writeback/transfer register overlap (load)
                           <anchor link="enum_Unpredictable_WBOVERLAPLD">Unpredictable_WBOVERLAPLD</anchor>,
                           // Writeback/transfer register overlap (store)
                           <anchor link="enum_Unpredictable_WBOVERLAPST">Unpredictable_WBOVERLAPST</anchor>,
                           // Load Pair transfer register overlap
                           <anchor link="enum_Unpredictable_LDPOVERLAP">Unpredictable_LDPOVERLAP</anchor>,
                           // Store-exclusive base/status register overlap
                           <anchor link="enum_Unpredictable_BASEOVERLAP">Unpredictable_BASEOVERLAP</anchor>,
                           // Store-exclusive data/status register overlap
                           <anchor link="enum_Unpredictable_DATAOVERLAP">Unpredictable_DATAOVERLAP</anchor>,
                           // Load-store alignment checks
                           <anchor link="enum_Unpredictable_DEVPAGE2">Unpredictable_DEVPAGE2</anchor>,
                           // Instruction fetch from Device memory
                           <anchor link="enum_Unpredictable_INSTRDEVICE">Unpredictable_INSTRDEVICE</anchor>,
                           // Reserved CPACR value
                           <anchor link="enum_Unpredictable_RESCPACR">Unpredictable_RESCPACR</anchor>,
                           // Reserved MAIR value
                           <anchor link="enum_Unpredictable_RESMAIR">Unpredictable_RESMAIR</anchor>,
                           // Effect of SCTLR_ELx.C on Tagged attribute
                           <anchor link="enum_Unpredictable_S1CTAGGED">Unpredictable_S1CTAGGED</anchor>,
                           // Reserved Stage 2 MemAttr value
                           <anchor link="enum_Unpredictable_S2RESMEMATTR">Unpredictable_S2RESMEMATTR</anchor>,
                           // Reserved TEX::C::B value
                           <anchor link="enum_Unpredictable_RESTEXCB">Unpredictable_RESTEXCB</anchor>,
                           // Reserved PRRR value
                           <anchor link="enum_Unpredictable_RESPRRR">Unpredictable_RESPRRR</anchor>,
                           // Reserved DACR field
                           <anchor link="enum_Unpredictable_RESDACR">Unpredictable_RESDACR</anchor>,
                           // Reserved VTCR.S value
                           <anchor link="enum_Unpredictable_RESVTCRS">Unpredictable_RESVTCRS</anchor>,
                           // Reserved TCR.TnSZ value
                           <anchor link="enum_Unpredictable_RESTnSZ">Unpredictable_RESTnSZ</anchor>,
                           // Reserved SCTLR_ELx.TCF value
                           <anchor link="enum_Unpredictable_RESTCF">Unpredictable_RESTCF</anchor>,
                           // Tag stored to Device memory
                           <anchor link="enum_Unpredictable_DEVICETAGSTORE">Unpredictable_DEVICETAGSTORE</anchor>,
                           // Out-of-range TCR.TnSZ value
                           <anchor link="enum_Unpredictable_OORTnSZ">Unpredictable_OORTnSZ</anchor>,

                           // IPA size exceeds PA size
                           <anchor link="enum_Unpredictable_LARGEIPA">Unpredictable_LARGEIPA</anchor>,
                           // Syndrome for a known-passing conditional A32 instruction
                           <anchor link="enum_Unpredictable_ESRCONDPASS">Unpredictable_ESRCONDPASS</anchor>,
                           // Illegal State exception: zero PSTATE.IT
                           <anchor link="enum_Unpredictable_ILZEROIT">Unpredictable_ILZEROIT</anchor>,
                           // Illegal State exception: zero PSTATE.T
                           <anchor link="enum_Unpredictable_ILZEROT">Unpredictable_ILZEROT</anchor>,
                           // Debug: prioritization of Vector Catch
                           <anchor link="enum_Unpredictable_BPVECTORCATCHPRI">Unpredictable_BPVECTORCATCHPRI</anchor>,
                           // Debug Vector Catch: match on 2nd halfword
                           <anchor link="enum_Unpredictable_VCMATCHHALF">Unpredictable_VCMATCHHALF</anchor>,
                           // Debug Vector Catch: match on Data Abort
                           // or Prefetch abort
                           <anchor link="enum_Unpredictable_VCMATCHDAPA">Unpredictable_VCMATCHDAPA</anchor>,
                           // Debug watchpoints: nonzero MASK and non-ones BAS
                           <anchor link="enum_Unpredictable_WPMASKANDBAS">Unpredictable_WPMASKANDBAS</anchor>,
                           // Debug watchpoints: non-contiguous BAS
                           <anchor link="enum_Unpredictable_WPBASCONTIGUOUS">Unpredictable_WPBASCONTIGUOUS</anchor>,
                           // Debug watchpoints: reserved MASK
                           <anchor link="enum_Unpredictable_RESWPMASK">Unpredictable_RESWPMASK</anchor>,
                           // Debug watchpoints: nonzero MASKed bits of address
                           <anchor link="enum_Unpredictable_WPMASKEDBITS">Unpredictable_WPMASKEDBITS</anchor>,
                           // Debug breakpoints and watchpoints: reserved control bits
                           <anchor link="enum_Unpredictable_RESBPWPCTRL">Unpredictable_RESBPWPCTRL</anchor>,
                           // Debug breakpoints: not implemented
                           <anchor link="enum_Unpredictable_BPNOTIMPL">Unpredictable_BPNOTIMPL</anchor>,
                           // Debug breakpoints: reserved type
                           <anchor link="enum_Unpredictable_RESBPTYPE">Unpredictable_RESBPTYPE</anchor>,
                           // Debug breakpoints and watchpoints: reserved MDSELR_EL1.BANK
                           <anchor link="enum_Unpredictable_RESMDSELR">Unpredictable_RESMDSELR</anchor>,
                           // Debug breakpoints: not-context-aware breakpoint
                           <anchor link="enum_Unpredictable_BPNOTCTXCMP">Unpredictable_BPNOTCTXCMP</anchor>,
                           // Debug breakpoints: match on 2nd halfword of instruction
                           <anchor link="enum_Unpredictable_BPMATCHHALF">Unpredictable_BPMATCHHALF</anchor>,
                           // Debug breakpoints: mismatch on 2nd halfword of instruction
                           <anchor link="enum_Unpredictable_BPMISMATCHHALF">Unpredictable_BPMISMATCHHALF</anchor>,
                           // Debug breakpoints: a breakpoint is linked to that is not
                           // programmed with linking enabled
                           <anchor link="enum_Unpredictable_BPLINKINGDISABLED">Unpredictable_BPLINKINGDISABLED</anchor>,
                           // Debug breakpoints: reserved MASK
                           <anchor link="enum_Unpredictable_RESBPMASK">Unpredictable_RESBPMASK</anchor>,
                           // Debug breakpoints: MASK is set for a Context matching
                           // breakpoint or when DBGBCR_EL1(n).BAS != '1111'
                           <anchor link="enum_Unpredictable_BPMASK">Unpredictable_BPMASK</anchor>,
                           // Debug breakpoints: nonzero MASKed bits of address
                           <anchor link="enum_Unpredictable_BPMASKEDBITS">Unpredictable_BPMASKEDBITS</anchor>,
                           // Debug breakpoints: A linked breakpoint is
                           // linked to an address matching breakpoint
                           <anchor link="enum_Unpredictable_BPLINKEDADDRMATCH">Unpredictable_BPLINKEDADDRMATCH</anchor>,
                           // Debug: restart to a misaligned AArch32 PC value
                           <anchor link="enum_Unpredictable_RESTARTALIGNPC">Unpredictable_RESTARTALIGNPC</anchor>,
                           // Debug: restart to a not-zero-extended AArch32 PC value
                           <anchor link="enum_Unpredictable_RESTARTZEROUPPERPC">Unpredictable_RESTARTZEROUPPERPC</anchor>,
                           // Zero top 32 bits of X registers in AArch32 state
                           <anchor link="enum_Unpredictable_ZEROUPPER">Unpredictable_ZEROUPPER</anchor>,
                           // Zero top 32 bits of PC on illegal return to
                           // AArch32 state
                           <anchor link="enum_Unpredictable_ERETZEROUPPERPC">Unpredictable_ERETZEROUPPERPC</anchor>,
                           // Force address to be aligned when interworking
                           // branch to A32 state
                           <anchor link="enum_Unpredictable_A32FORCEALIGNPC">Unpredictable_A32FORCEALIGNPC</anchor>,
                           // SMC disabled
                           <anchor link="enum_Unpredictable_SMD">Unpredictable_SMD</anchor>,
                           // FF speculation
                           <anchor link="enum_Unpredictable_NONFAULT">Unpredictable_NONFAULT</anchor>,
                           // Zero top bits of Z registers in EL change
                           <anchor link="enum_Unpredictable_SVEZEROUPPER">Unpredictable_SVEZEROUPPER</anchor>,
                           // Load mem data in NF loads
                           <anchor link="enum_Unpredictable_SVELDNFDATA">Unpredictable_SVELDNFDATA</anchor>,
                           // Write zeros in NF loads
                           <anchor link="enum_Unpredictable_SVELDNFZERO">Unpredictable_SVELDNFZERO</anchor>,
                           // SP alignment fault when predicate is all zero
                           <anchor link="enum_Unpredictable_CHECKSPNONEACTIVE">Unpredictable_CHECKSPNONEACTIVE</anchor>,
                           // Zero top bits of ZA registers in EL change
                           <anchor link="enum_Unpredictable_SMEZEROUPPER">Unpredictable_SMEZEROUPPER</anchor>,
                           // Watchpoint match of last rounded up memory access in case of
                           // 16 byte rounding
                           <anchor link="enum_Unpredictable_16BYTEROUNDEDUPACCESS">Unpredictable_16BYTEROUNDEDUPACCESS</anchor>,
                           // Watchpoint match of first rounded down memory access in case of
                           // 16 byte rounding
                           <anchor link="enum_Unpredictable_16BYTEROUNDEDDOWNACCESS">Unpredictable_16BYTEROUNDEDDOWNACCESS</anchor>,
                           // HCR_EL2.[NV,NV1] == '01'
                           <anchor link="enum_Unpredictable_NVNV1">Unpredictable_NVNV1</anchor>,
                           // Upper bits of a BADDR are not RESS
                           <anchor link="enum_Unpredictable_BADDR_RESS">Unpredictable_BADDR_RESS</anchor>,
                           // Reserved shareability encoding
                           <anchor link="enum_Unpredictable_Shareability">Unpredictable_Shareability</anchor>,
                           // Access Flag Update by HW
                           <anchor link="enum_Unpredictable_AFUPDATE">Unpredictable_AFUPDATE</anchor>,
                           // Dirty Bit State Update by HW
                           <anchor link="enum_Unpredictable_DBUPDATE">Unpredictable_DBUPDATE</anchor>,
                           // Unsupported memory attributes for HW update
                           <anchor link="enum_Unpredictable_Unsupported_Atomic_HW_Update">Unpredictable_Unsupported_Atomic_HW_Update</anchor>,
                           // Consider SCTLR_ELx().IESB in Debug state
                           <anchor link="enum_Unpredictable_IESBinDebug">Unpredictable_IESBinDebug</anchor>,
                           // The HCR_EL2.TERR / HCR2.TERR and SCR_EL3.TERR / SCR.TERR
                           // trap control can be treated as RES0.
                           <anchor link="enum_Unpredictable_MINIMALRASv2">Unpredictable_MINIMALRASv2</anchor>,
                           // Bad settings for PMSFCR_EL1/PMSEVFR_EL1/PMSLATFR_EL1
                           <anchor link="enum_Unpredictable_BADPMSFCR">Unpredictable_BADPMSFCR</anchor>,
                           // Zero saved BType value in SPSR_ELx/DPSR_EL0
                           <anchor link="enum_Unpredictable_ZEROBTYPE">Unpredictable_ZEROBTYPE</anchor>,
                           // Timestamp constrained to virtual or physical
                           <anchor link="enum_Unpredictable_EL2TIMESTAMP">Unpredictable_EL2TIMESTAMP</anchor>,
                           <anchor link="enum_Unpredictable_EL1TIMESTAMP">Unpredictable_EL1TIMESTAMP</anchor>,
                            // Reserved MDCR_EL3.[NSTBE,NSTB] or MDCR_EL3.[NSPBE,NSPB] value
                            <anchor link="enum_Unpredictable_RESERVEDNSxB">Unpredictable_RESERVEDNSxB</anchor>,
                            <anchor link="enum_Unpredictable_RESERVEDNSxB_Trap">Unpredictable_RESERVEDNSxB_Trap</anchor>,
                           // WFET or WFIT instruction in Debug state
                           <anchor link="enum_Unpredictable_WFxTDEBUG">Unpredictable_WFxTDEBUG</anchor>,
                           // Address does not support LS64 instructions
                           <anchor link="enum_Unpredictable_LS64UNSUPPORTED">Unpredictable_LS64UNSUPPORTED</anchor>,
                           // Unaligned exclusives, atomics, acquire/release
                           // to a region that is not to Normal inner write-back
                           // outer write-back shareable generate an Alignment fault.
                           <anchor link="enum_Unpredictable_LSE2_ALIGNMENT_FAULT">Unpredictable_LSE2_ALIGNMENT_FAULT</anchor>,
                           // 128-bit Atomic or 128-bit RCW{S} transfer register overlap
                           <anchor link="enum_Unpredictable_LSE128OVERLAP">Unpredictable_LSE128OVERLAP</anchor>,
                           // Clearing DCC/ITR sticky flags when instruction is in flight
                           <anchor link="enum_Unpredictable_CLEARERRITEZERO">Unpredictable_CLEARERRITEZERO</anchor>,
                           // ALUEXCEPTIONRETURN when in user/system mode in
                           // A32 instructions
                           <anchor link="enum_Unpredictable_ALUEXCEPTIONRETURN">Unpredictable_ALUEXCEPTIONRETURN</anchor>,
                           // Trap to register in debug state are ignored
                           <anchor link="enum_Unpredictable_IGNORETRAPINDEBUG">Unpredictable_IGNORETRAPINDEBUG</anchor>,
                           // Compare DBGBVR.RESS for BP/WP
                           <anchor link="enum_Unpredictable_DBGxVR_RESS">Unpredictable_DBGxVR_RESS</anchor>,
                           // Inaccessible event counter
                           <anchor link="enum_Unpredictable_PMUEVENTCOUNTER">Unpredictable_PMUEVENTCOUNTER</anchor>,
                           // Reserved PMSCR.PCT behavior
                           <anchor link="enum_Unpredictable_PMSCR_PCT">Unpredictable_PMSCR_PCT</anchor>,
                           // MDCR_EL2.HPMN or HDCR.HPMN is larger than PMCR.N or
                           // FEAT_HPMN0 is not implemented and HPMN is 0.
                           <anchor link="enum_Unpredictable_RES_HPMN">Unpredictable_RES_HPMN</anchor>,
                           // Chained PMU counters idx and idx+1 are not in same range
                           <anchor link="enum_Unpredictable_COUNT_CHAIN">Unpredictable_COUNT_CHAIN</anchor>,
                           // PMCCR.EPMN is larger than PMCR.N
                           <anchor link="enum_Unpredictable_RES_EPMN">Unpredictable_RES_EPMN</anchor>,
                           // Generate BRB_FILTRATE event on BRB injection
                           <anchor link="enum_Unpredictable_BRBFILTRATE">Unpredictable_BRBFILTRATE</anchor>,
                           // Generate PMU_SNAPSHOT event in Debug state
                           <anchor link="enum_Unpredictable_PMUSNAPSHOTEVENT">Unpredictable_PMUSNAPSHOTEVENT</anchor>,
                           // Reserved MDCR_EL3.EPMSSAD value
                           <anchor link="enum_Unpredictable_RESEPMSSAD">Unpredictable_RESEPMSSAD</anchor>,
                           // Reserved PMECR_EL1.SSE value
                           <anchor link="enum_Unpredictable_RESPMSSE">Unpredictable_RESPMSSE</anchor>,
                           // Enable for PMU Profiling exception and PMUIRQ
                           <anchor link="enum_Unpredictable_RESPMEE">Unpredictable_RESPMEE</anchor>,
                           // Enables for SPE Profiling exceptions and PMSIRQ
                           <anchor link="enum_Unpredictable_RESPMSEE">Unpredictable_RESPMSEE</anchor>,
                           // Enables for TRBE Profiling exceptions and PMSIRQ
                           <anchor link="enum_Unpredictable_RESTRFEE">Unpredictable_RESTRFEE</anchor>,
                           // Operands for CPY*/SET* instructions overlap
                           <anchor link="enum_Unpredictable_MOPSOVERLAP">Unpredictable_MOPSOVERLAP</anchor>,
                           // Operands for CPY*/SET* instructions use 0b11111
                           // as a register specifier
                           <anchor link="enum_Unpredictable_MOPS_R31">Unpredictable_MOPS_R31</anchor>,
                           // Chooses which value to return in a non failed Atomic Compare and Swap
                           <anchor link="enum_Unpredictable_CASRETURNOLDVALUE">Unpredictable_CASRETURNOLDVALUE</anchor>,
                           // Enables write of the newvalue in a failed Atomic Compare and Swap
                           <anchor link="enum_Unpredictable_WRITEFAILEDCAS">Unpredictable_WRITEFAILEDCAS</anchor>,
                           // Enables write of the newvalue in a failed Atomic Compare and Swap
                           // or failed RCW{S}
                           <anchor link="enum_Unpredictable_WRITEFAILEDRCWCAS">Unpredictable_WRITEFAILEDRCWCAS</anchor>,
                           // Store-only Tag checking on a failed Atomic Compare and Swap
                           <anchor link="enum_Unpredictable_STRONLYTAGCHECKEDCAS">Unpredictable_STRONLYTAGCHECKEDCAS</anchor>,
                           // Store-only Tag checking on a failed RCW(S) checks
                           // or RCW(S) Atomic Compare and Swap
                           <anchor link="enum_Unpredictable_STRONLYTAGCHECKEDRCWSCAS">Unpredictable_STRONLYTAGCHECKEDRCWSCAS</anchor>,
                           // Reserved MDCR_EL3.ETBAD value
                           <anchor link="enum_Unpredictable_RES_ETBAD">Unpredictable_RES_ETBAD</anchor>,
                           // Invalid Streaming Mode filter bits
                           <anchor link="enum_Unpredictable_RES_PMU_VS">Unpredictable_RES_PMU_VS</anchor>,
                           // Apply Checked Pointer Arithmetic on a sequential access to bytes
                           // that cross the 0xXXFF_FFFF_FFFF_FFFF boundary.
                           <anchor link="enum_Unpredictable_CPACHECK">Unpredictable_CPACHECK</anchor>,
                           // Reserved PMEVTYPER[n]_EL0.[TC,TE,TC2] values
                           <anchor link="enum_Unpredictable_RESTC">Unpredictable_RESTC</anchor>,
                           // When FEAT_MTE is implemented, if Memory access mode is enabled
                           // and PSTATE.TCO is 0,  Reads and writes to the external debug
                           // interface DTR registers are CONSTRAINED UNPREDICTABLE for tagcheck
                           <anchor link="enum_Unpredictable_NODTRTAGCHK">Unpredictable_NODTRTAGCHK</anchor>,
                           // Use the default PMG when the default PARTID is generated
                           // due to MPAM error
                           <anchor link="enum_Unpredictable_USE_DEFAULT_PMG">Unpredictable_USE_DEFAULT_PMG</anchor>,
                           // If the atomic instructions are not atomic in regard to other
                           // agents that access memory, then the instruction can have one or
                           // more of the following effects
                           <anchor link="enum_Unpredictable_Atomic_SYNC_ABORT">Unpredictable_Atomic_SYNC_ABORT</anchor>,
                           <anchor link="enum_Unpredictable_Atomic_SERROR">Unpredictable_Atomic_SERROR</anchor>,
                           <anchor link="enum_Unpredictable_Atomic_NOP">Unpredictable_Atomic_NOP</anchor>,
                           <anchor link="enum_Unpredictable_Atomic_MMU_IMPDEF_FAULT">Unpredictable_Atomic_MMU_IMPDEF_FAULT</anchor>,
                           // Accessing DBGDSCRint via MRC in debug state
                           <anchor link="enum_Unpredictable_MRC_APSR_TARGET">Unpredictable_MRC_APSR_TARGET</anchor>,
                           // Accessing Banked register not accessible from the PE mode
                           <anchor link="enum_Unpredictable_BankedRegister">Unpredictable_BankedRegister</anchor>,
                           // Accessing unimplemented Banked register
                           <anchor link="enum_Unpredictable_UnimplementedRegister">Unpredictable_UnimplementedRegister</anchor>,
                           // Reserved ERRACR.{RLRA,SRA,NSRA} values
                           <anchor link="enum_Unpredictable_RES_RA">Unpredictable_RES_RA</anchor>,
                           // Linked target does not support linking
                           <anchor link="enum_Unpredictable_BPNOTLINKING">Unpredictable_BPNOTLINKING</anchor>
};</pstext></ps>
    <ps name="shared/functions/vector/AdvSIMDExpandImm" mylink="shared.functions.vector.AdvSIMDExpandImm" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AdvSIMDExpandImm()
// ==================

func <anchor link="func_AdvSIMDExpandImm_3">AdvSIMDExpandImm</anchor>(op : bit, cmode : bits(4), imm8 : bits(8)) =&gt; bits(64)
begin
    var imm64 : bits(64);
    case cmode[3:1] of
        when '000' =&gt;
            imm64 = Replicate{64}(Zeros{24}::imm8);
        when '001' =&gt;
            imm64 = Replicate{64}(Zeros{16}::imm8::Zeros{8});
        when '010' =&gt;
            imm64 = Replicate{64}(Zeros{8}::imm8::Zeros{16});
        when '011' =&gt;
            imm64 = Replicate{64}(imm8::Zeros{24});
        when '100' =&gt;
            imm64 = Replicate{64}(Zeros{8}::imm8);
        when '101' =&gt;
            imm64 = Replicate{64}(imm8::Zeros{8});
        when '110' =&gt;
            if cmode[0] == '0' then
                imm64 = Replicate{64}(Zeros{16}::imm8::Ones{8});
            else
                imm64 = Replicate{64}(Zeros{8}::imm8::Ones{16});
            end;
        when '111' =&gt;
            if cmode[0] == '0' &amp;&amp; op == '0' then
                imm64 = Replicate{64}(imm8);
            end;
            if cmode[0] == '0' &amp;&amp; op == '1' then
                let imm8a : bits(8) = Replicate{}(imm8[7]);
                let imm8b : bits(8) = Replicate{}(imm8[6]);
                let imm8c : bits(8) = Replicate{}(imm8[5]);
                let imm8d : bits(8) = Replicate{}(imm8[4]);
                let imm8e : bits(8) = Replicate{}(imm8[3]);
                let imm8f : bits(8) = Replicate{}(imm8[2]);
                let imm8g : bits(8) = Replicate{}(imm8[1]);
                let imm8h : bits(8) = Replicate{}(imm8[0]);
                imm64 = imm8a::imm8b::imm8c::imm8d::imm8e::imm8f::imm8g::imm8h;
            end;
            if cmode[0] == '1' &amp;&amp; op == '0' then
                let imm32 : bits(32) = (imm8[7]::NOT(imm8[6])::Replicate{5}(imm8[6])::
                                            imm8[5:0]::Zeros{19});
                imm64 = Replicate{64}(imm32);
            end;
            if cmode[0] == '1' &amp;&amp; op == '1' then
                if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then ReservedEncoding(); end;
                imm64 = imm8[7]::NOT(imm8[6])::Replicate{8}(imm8[6])::imm8[5:0]::Zeros{48};
            end;
    end;

    return imm64;
end;</pstext></ps>
    <ps name="shared/functions/vector/MatMulAdd" mylink="shared.functions.vector.MatMulAdd" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// MatMulAdd()
// ===========
//
// Signed or unsigned 8-bit integer matrix multiply and add to 32-bit integer matrix
// result[2, 2] = addend[2, 2] + (op1[2, 8] * op2[8, 2])

func <anchor link="func_MatMulAdd_5">MatMulAdd</anchor>(addend : bits(128), op1 : bits(128), op2 : bits(128), op1_unsigned : boolean,
             op2_unsigned : boolean) =&gt; bits(128)
begin

    var result : bits(128);
    var sum : bits(32);
    var prod : integer;

    for i = 0 to 1 do
        for j = 0 to 1 do
            sum = addend[(2*i + j)*:32];
            for k = 0 to 7 do
                let opelt1 : bits(8) = op1[(8*i + k)*:8];
                let opelt2 : bits(8) = op2[(8*j + k)*:8];
                let element1 : integer = if op1_unsigned then UInt(opelt1) else SInt(opelt1);
                let element2 : integer = if op2_unsigned then UInt(opelt2) else SInt(opelt2);
                prod = element1 * element2;
                sum  = sum + prod;
            end;
            result[(2*i + j)*:32] = sum;
        end;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/vector/PolynomialMult" mylink="shared.functions.vector.PolynomialMult" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PolynomialMult()
// ================

func <anchor link="func_PolynomialMult_4">PolynomialMult</anchor>{M, N}(op1 : bits(M), op2 : bits(N)) =&gt; bits(M+N)
begin
    var result : bits(N + M) = Zeros{M+N};
    let extended_op2 : bits(N + M) = ZeroExtend{M+N}(op2);
    for i=0 to M-1 do
        if op1[i] == '1' then
            result = result XOR LSL(extended_op2, i);
        end;
    end;
    return result;
end;</pstext></ps>
    <ps name="shared/functions/vector/SatQ" mylink="shared.functions.vector.SatQ" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SatQ()
// ======

func <anchor link="func_SatQ_3">SatQ</anchor>{N}(i : integer, unsigned : boolean) =&gt; (bits(N), boolean)
begin
    let (result, sat) : (bits(N), boolean) = (if unsigned then <a link="func_UnsignedSatQ_2" file="shared_pseudocode.xml">UnsignedSatQ</a>{N}(i)
                                                          else <a link="func_SignedSatQ_2" file="shared_pseudocode.xml">SignedSatQ</a>{N}(i));
    return (result, sat);
end;</pstext></ps>
    <ps name="shared/functions/vector/ShiftSat" mylink="shared.functions.vector.ShiftSat" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ShiftSat()
// ==========

func <anchor link="func_ShiftSat_2">ShiftSat</anchor>(shift : integer, esize : integer) =&gt; integer
begin
    if shift &gt; esize+1 then return esize+1;
    elsif shift &lt; -(esize+1) then return -(esize+1); end;
    return shift;
end;</pstext></ps>
    <ps name="shared/functions/vector/SignedSat" mylink="shared.functions.vector.SignedSat" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SignedSat()
// ===========

func <anchor link="func_SignedSat_2">SignedSat</anchor>{N}(i : integer) =&gt; bits(N)
begin
    let (result, -) = <a link="func_SignedSatQ_2" file="shared_pseudocode.xml">SignedSatQ</a>{N}(i);
    return result;
end;</pstext></ps>
    <ps name="shared/functions/vector/SignedSatQ" mylink="shared.functions.vector.SignedSatQ" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SignedSatQ()
// ============

func <anchor link="func_SignedSatQ_2">SignedSatQ</anchor>{N}(i : integer) =&gt; (bits(N), boolean)
begin
    var result : integer;
    var saturated : boolean;
    if i &gt; 2^(N-1) - 1 then
        result = 2^(N-1) - 1;  saturated = TRUE;
    elsif i &lt; -(2^(N-1)) then
        result = -(2^(N-1));  saturated = TRUE;
    else
        result = i;  saturated = FALSE;
    end;
    return (result[N-1:0], saturated);
end;</pstext></ps>
    <ps name="shared/functions/vector/UnsignedRSqrtEstimate" mylink="shared.functions.vector.UnsignedRSqrtEstimate" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// UnsignedRSqrtEstimate()
// =======================

func <anchor link="func_UnsignedRSqrtEstimate_2">UnsignedRSqrtEstimate</anchor>{N}(operand : bits(N)) =&gt; bits(N)
begin
    assert N == 32;
    var result : bits(N);
    if operand[N-1:N-2] == '00' then  // Operands &lt;= 0x3FFFFFFF produce 0xFFFFFFFF
        result = Ones{N};
    else
        // input is in the range 0x40000000 .. 0xffffffff representing [0.25 .. 1.0)
        // estimate is in the range 256 .. 511 representing [1.0 .. 2.0)
        let increasedprecision : boolean = FALSE;
        let estimate : integer = <a link="func_RecipSqrtEstimate_2" file="shared_pseudocode.xml">RecipSqrtEstimate</a>(UInt(operand[31:23]), increasedprecision);
        // result is in the range 0x80000000 .. 0xff800000 representing [1.0 .. 2.0)
        result = estimate[8:0] :: Zeros{N-9};
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/vector/UnsignedRecipEstimate" mylink="shared.functions.vector.UnsignedRecipEstimate" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// UnsignedRecipEstimate()
// =======================

func <anchor link="func_UnsignedRecipEstimate_2">UnsignedRecipEstimate</anchor>{N}(operand : bits(N)) =&gt; bits(N)
begin
    assert N == 32;
    var result : bits(N);
    if operand[N-1] == '0' then  // Operands &lt;= 0x7FFFFFFF produce 0xFFFFFFFF
        result = Ones{N};
    else
        // input is in the range 0x80000000 .. 0xffffffff representing [0.5 .. 1.0)

        // estimate is in the range 256 to 511 representing [1.0 .. 2.0)
        let increasedprecision : boolean = FALSE;
        let estimate : integer = <a link="func_RecipEstimate_2" file="shared_pseudocode.xml">RecipEstimate</a>(UInt(operand[31:23]), increasedprecision);

        // result is in the range 0x80000000 .. 0xff800000 representing [1.0 .. 2.0)
        result = estimate[8:0] :: Zeros{N-9};
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/functions/vector/UnsignedSat" mylink="shared.functions.vector.UnsignedSat" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// UnsignedSat()
// =============

func <anchor link="func_UnsignedSat_2">UnsignedSat</anchor>{N}(i : integer) =&gt; bits(N)
begin
    let (result, -) = <a link="func_UnsignedSatQ_2" file="shared_pseudocode.xml">UnsignedSatQ</a>{N}(i);
    return result;
end;</pstext></ps>
    <ps name="shared/functions/vector/UnsignedSatQ" mylink="shared.functions.vector.UnsignedSatQ" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// UnsignedSatQ()
// ==============

func <anchor link="func_UnsignedSatQ_2">UnsignedSatQ</anchor>{N}(i : integer) =&gt; (bits(N), boolean)
begin
    var result : integer;
    var saturated : boolean;
    if i &gt; 2^N - 1 then
        result = 2^N - 1;  saturated = TRUE;
    elsif i &lt; 0 then
        result = 0;  saturated = TRUE;
    else
        result = i;  saturated = FALSE;
    end;
    return (result[N-1:0], saturated);
end;</pstext></ps>
    <ps name="shared/trace/Common/DebugMemWrite" mylink="shared.trace.Common.DebugMemWrite" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DebugMemWrite()
// ===============
// Write data to memory one byte at a time. Starting at the passed virtual address.
// Used by SPE and TRBE.

func <anchor link="func_DebugMemWrite_4">DebugMemWrite</anchor>(vaddress : bits(64), accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                   aligned : boolean, data : bits(8)) =&gt; (<a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>, <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>)
begin

    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a> = ARBITRARY : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;

    // Translate virtual address
    var addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    let size : integer = 1;
    addrdesc = <a link="func_AArch64_TranslateAddress_4" file="shared_pseudocode.xml">AArch64_TranslateAddress</a>(vaddress, accdesc, aligned, size);

    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(addrdesc) then
        return (memstatus, addrdesc);
    end;

    memstatus = <a link="func_PhysMemWrite_4" file="shared_pseudocode.xml">PhysMemWrite</a>{8}(addrdesc, accdesc, data);

    return (memstatus, addrdesc);
end;</pstext></ps>
    <ps name="shared/trace/Common/DebugWriteExternalAbort" mylink="shared.trace.Common.DebugWriteExternalAbort" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DebugWriteExternalAbort()
// =========================
// Populate the syndrome register for an External abort caused by a call of DebugMemWrite().

func <anchor link="func_DebugWriteExternalAbort_3">DebugWriteExternalAbort</anchor>(memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>, addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                             start_vaddr : bits(64))
begin

    let iswrite : boolean = TRUE;

    var handle_as_SError : boolean = FALSE;
    case addrdesc.fault.accessdesc.acctype of
        when <a link="enum_AccessType_SPE" file="shared_pseudocode.xml">AccessType_SPE</a> =&gt;
            handle_as_SError = ImpDefBool(&quot;Report SPE ExtAbort as SError&quot;);
        when <a link="enum_AccessType_TRBE" file="shared_pseudocode.xml">AccessType_TRBE</a> =&gt;
            handle_as_SError = ImpDefBool(&quot;Report TRBE ExtAbort as SError&quot;);
        otherwise =&gt;
            unreachable;
    end;

    let ttw_abort : boolean = addrdesc.fault.statuscode IN {<a link="enum_Fault_SyncExternalOnWalk" file="shared_pseudocode.xml">Fault_SyncExternalOnWalk</a>,
                                                               <a link="enum_Fault_SyncParityOnWalk" file="shared_pseudocode.xml">Fault_SyncParityOnWalk</a>};
    let statuscode : <a link="type_Fault" file="shared_pseudocode.xml">Fault</a> = (if ttw_abort then addrdesc.fault.statuscode
                                 else memstatus.statuscode);

    if statuscode IN {<a link="enum_Fault_AsyncExternal" file="shared_pseudocode.xml">Fault_AsyncExternal</a>, <a link="enum_Fault_AsyncParity" file="shared_pseudocode.xml">Fault_AsyncParity</a>} || handle_as_SError then
        // Report the abort as an SError
        var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_0" file="shared_pseudocode.xml">NoFault</a>();
        let parity : boolean = statuscode IN {<a link="enum_Fault_SyncParity" file="shared_pseudocode.xml">Fault_SyncParity</a>, <a link="enum_Fault_AsyncParity" file="shared_pseudocode.xml">Fault_AsyncParity</a>,
                                                 <a link="enum_Fault_SyncParityOnWalk" file="shared_pseudocode.xml">Fault_SyncParityOnWalk</a>};
        fault.statuscode = if parity then <a link="enum_Fault_AsyncParity" file="shared_pseudocode.xml">Fault_AsyncParity</a> else <a link="enum_Fault_AsyncExternal" file="shared_pseudocode.xml">Fault_AsyncExternal</a>;
        if IsFeatureImplemented(FEAT_RAS) then
            fault.merrorstate = memstatus.merrorstate;
        end;
        let extflag : bit = if ttw_abort then addrdesc.fault.extflag else memstatus.extflag;
        fault.extflag = extflag;
        fault.accessdesc.acctype = addrdesc.fault.accessdesc.acctype;
        PendSErrorInterrupt(fault);
        return;
    end;

    // Generate a buffer management event, modifying the existing syndrome.
    var handle_async : boolean = FALSE;
    var syndrome : bits(64);
    case addrdesc.fault.accessdesc.acctype of
        when <a link="enum_AccessType_SPE" file="shared_pseudocode.xml">AccessType_SPE</a> =&gt;
            handle_async = ImpDefBool(&quot;Report SPE ExtAbort asynchronously&quot;);
            assert !IsFeatureImplemented(FEAT_SPE_EXC);
            syndrome = PMBSR_EL1();
        when <a link="enum_AccessType_TRBE" file="shared_pseudocode.xml">AccessType_TRBE</a> =&gt;
            handle_async = ImpDefBool(&quot;Report TRBE ExtAbort asynchronously&quot;);
            assert !IsFeatureImplemented(FEAT_TRBE_EXC);
            syndrome = TRBSR_EL1();
        otherwise =&gt;
            unreachable;
    end;

    var ec : bits(6);
    if (IsFeatureImplemented(FEAT_RME) &amp;&amp; addrdesc.fault.gpcf.gpf != <a link="enum_GPCF_None" file="shared_pseudocode.xml">GPCF_None</a> &amp;&amp;
          addrdesc.fault.gpcf.gpf != <a link="enum_GPCF_Fail" file="shared_pseudocode.xml">GPCF_Fail</a>) then
        ec = '011110';
    else
        ec = if addrdesc.fault.secondstage then '100101' else '100100';
    end;

    let mss2 : bits(24) = Zeros{};
    var mss : bits(16) = Zeros{};
    if handle_async then                // FSC bits
        mss[5:0] = '010001';
    else
        mss[5:0] = <a link="func_EncodeLDFSC_2" file="shared_pseudocode.xml">EncodeLDFSC</a>(statuscode, addrdesc.fault.level);
    end;

    // The following values are always updated in the syndrome register.
    if (addrdesc.fault.accessdesc.acctype == <a link="enum_AccessType_SPE" file="shared_pseudocode.xml">AccessType_SPE</a> &amp;&amp;
          (handle_async || start_vaddr != addrdesc.vaddress)) then
        syndrome[19] = '1';             // DL bit (SPE only)
    end;

    syndrome[18] = '1';                 // EA bit

    // The following values are not modified if a previous buffer management event
    // has not been handled. Note that in this simple sequential model, this test
    // will never fail.
    if syndrome[17] == '0' then         // Check previous 'S' bit.
        syndrome[55:32] = mss2;         // MSS2 bits
        syndrome[31:26] = ec;           // EC bits
        if addrdesc.fault.accessdesc.acctype == <a link="enum_AccessType_TRBE" file="shared_pseudocode.xml">AccessType_TRBE</a> then
            syndrome[22] = '1';         // IRQ bit (TRBE only)
        end;
        syndrome[17] = '1';             // S bit
        syndrome[15:0] = mss;           // MSS bits
    end;

    case addrdesc.fault.accessdesc.acctype of
        when <a link="enum_AccessType_SPE" file="shared_pseudocode.xml">AccessType_SPE</a> =&gt;
            PMBSR_EL1() = syndrome;
        when <a link="enum_AccessType_TRBE" file="shared_pseudocode.xml">AccessType_TRBE</a> =&gt;
            TRBSR_EL1() = syndrome;
        otherwise =&gt;
            unreachable;
    end;
end;</pstext></ps>
    <ps name="shared/trace/Common/DebugWriteFault" mylink="shared.trace.Common.DebugWriteFault" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DebugWriteFault()
// =================
// Populate the syndrome register for a fault caused by a call of DebugMemWrite().

func <anchor link="func_DebugWriteFault_2">DebugWriteFault</anchor>(vaddress : bits(64), fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>)
begin
    var ec : bits(6);
    if (IsFeatureImplemented(FEAT_RME) &amp;&amp; fault.gpcf.gpf != <a link="enum_GPCF_None" file="shared_pseudocode.xml">GPCF_None</a> &amp;&amp;
          fault.gpcf.gpf != <a link="enum_GPCF_Fail" file="shared_pseudocode.xml">GPCF_Fail</a>) then
        ec = '011110';
    else
        ec = if fault.secondstage then '100101' else '100100';
    end;

    var mss2 : bits(24) = Zeros{};
    if fault.statuscode == <a link="enum_Fault_Permission" file="shared_pseudocode.xml">Fault_Permission</a> then
        mss2[8] = if fault.toplevel then '1' else '0';      // TopLevel bit
        mss2[7] = if fault.assuredonly then '1' else '0';   // AssuredOnly bit
        mss2[6] = if fault.overlay then '1' else '0';       // Overlay bit
        mss2[5] = if fault.dirtybit then '1' else '0';      // DirtyBit
    end;


    var mss : bits(16) = Zeros{};
    if !(IsFeatureImplemented(FEAT_RME) &amp;&amp; fault.gpcf.gpf != <a link="enum_GPCF_None" file="shared_pseudocode.xml">GPCF_None</a> &amp;&amp;
           fault.gpcf.gpf != <a link="enum_GPCF_Fail" file="shared_pseudocode.xml">GPCF_Fail</a>) then
        mss[5:0] = <a link="func_EncodeLDFSC_2" file="shared_pseudocode.xml">EncodeLDFSC</a>(fault.statuscode, fault.level);  // FSC bits
    end;

    // Generate a buffer management event, modifying the existing syndrome.
    var target_el : bits(2);
    var syndrome : bits(64);
    case fault.accessdesc.acctype of
        when <a link="enum_AccessType_SPE" file="shared_pseudocode.xml">AccessType_SPE</a> =&gt;
            target_el = <a link="func_ReportSPEEvent_2" file="shared_pseudocode.xml">ReportSPEEvent</a>(ec, mss[5:0]);
            syndrome = <a link="accessor_PMBSR_EL_1" file="shared_pseudocode.xml">PMBSR_EL</a>(target_el);
        when <a link="enum_AccessType_TRBE" file="shared_pseudocode.xml">AccessType_TRBE</a> =&gt;
            target_el = <a link="func_ReportTRBEEvent_2" file="shared_pseudocode.xml">ReportTRBEEvent</a>(ec, mss[5:0]);
            syndrome = <a link="accessor_TRBSR_EL_1" file="shared_pseudocode.xml">TRBSR_EL</a>(target_el);
        otherwise =&gt;
            unreachable;
    end;

    // The following values are not modified if a previous buffer management event
    // has not been handled. Note that in this simple sequential model, this test
    // will never fail.
    if syndrome[17] == '0' then         // Check previous 'S' bit.
        syndrome[55:32] = mss2;         // MSS2 bits
        syndrome[31:26] = ec;           // EC bits
        if fault.accessdesc.acctype == <a link="enum_AccessType_TRBE" file="shared_pseudocode.xml">AccessType_TRBE</a> then
            syndrome[22] = '1';         // IRQ bit (TRBE only)
        end;
        syndrome[17] = '1';             // S bit
        syndrome[15:0] = mss;           // MSS bits
    end;

    // For SPE, PMBPTR_EL1 points to the address that generated the fault, and writing
    // to memory never started. Therefore, there isno data loss and DL is unchanged.

    case fault.accessdesc.acctype of
        when <a link="enum_AccessType_SPE" file="shared_pseudocode.xml">AccessType_SPE</a> =&gt;
            <a link="accessor_PMBSR_EL_1" file="shared_pseudocode.xml">PMBSR_EL</a>(target_el) = syndrome;

        when <a link="enum_AccessType_TRBE" file="shared_pseudocode.xml">AccessType_TRBE</a> =&gt;
            <a link="accessor_TRBSR_EL_1" file="shared_pseudocode.xml">TRBSR_EL</a>(target_el) = syndrome;

        otherwise =&gt;
            unreachable;
    end;

    return;
end;</pstext></ps>
    <ps name="shared/trace/Common/GetTimestamp" mylink="shared.trace.Common.GetTimestamp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetTimestamp()
// ==============
// Returns the Timestamp depending on the type

func <anchor link="func_GetTimestamp_1">GetTimestamp</anchor>(timeStampType : <a link="type_TimeStamp" file="shared_pseudocode.xml">TimeStamp</a>) =&gt; bits(64)
begin
    case timeStampType of
        when <a link="enum_TimeStamp_Physical" file="shared_pseudocode.xml">TimeStamp_Physical</a> =&gt;
            return <a link="func_PhysicalCountInt_0" file="shared_pseudocode.xml">PhysicalCountInt</a>();
        when <a link="enum_TimeStamp_Virtual" file="shared_pseudocode.xml">TimeStamp_Virtual</a> =&gt;
            return <a link="func_PhysicalCountInt_0" file="shared_pseudocode.xml">PhysicalCountInt</a>() - CNTVOFF_EL2();
        when <a link="enum_TimeStamp_OffsetPhysical" file="shared_pseudocode.xml">TimeStamp_OffsetPhysical</a> =&gt;
            let physoff : bits(64) = if <a link="func_PhysicalOffsetIsValid_0" file="shared_pseudocode.xml">PhysicalOffsetIsValid</a>() then CNTPOFF_EL2() else Zeros{64};
            return <a link="func_PhysicalCountInt_0" file="shared_pseudocode.xml">PhysicalCountInt</a>() - physoff;
        when <a link="enum_TimeStamp_None" file="shared_pseudocode.xml">TimeStamp_None</a> =&gt;
            return Zeros{64};
        when <a link="enum_TimeStamp_CoreSight" file="shared_pseudocode.xml">TimeStamp_CoreSight</a> =&gt;
            return ImpDefBits{64}(&quot;CoreSight timestamp&quot;);
        otherwise =&gt;
            unreachable;
    end;
end;</pstext></ps>
    <ps name="shared/trace/Common/PhysicalOffsetIsValid" mylink="shared.trace.Common.PhysicalOffsetIsValid" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PhysicalOffsetIsValid()
// =======================
// Returns whether the Physical offset for the timestamp is valid

func <anchor link="func_PhysicalOffsetIsValid_0">PhysicalOffsetIsValid</anchor>() =&gt; boolean
begin
    if !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then
        return FALSE;
    elsif !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) || !IsFeatureImplemented(FEAT_ECV_POFF) then
        return FALSE;
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_EffectiveSCR_EL3_NS_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NS</a>() == '1' &amp;&amp; <a link="func_EffectiveSCR_EL3_RW_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_RW</a>() == '0' then
        return FALSE;
    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR_EL3().ECVEn == '0' then
        return FALSE;
    elsif CNTHCTL_EL2().ECV == '0' then
        return FALSE;
    else
        return TRUE;
    end;
end;</pstext></ps>
    <ps name="shared/trace/Common/TRBCRManStopWrite" mylink="shared.trace.Common.TRBCRManStopWrite" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TRBCRManStopWrite()
// ===================
// Called on a write of 1 to TRBCR.ManStop.

func <anchor link="func_TRBCRManStopWrite_0">TRBCRManStopWrite</anchor>()
begin
    TraceUnitFlush();
    <a link="func_OtherTRBEManagementEvent_1" file="shared_pseudocode.xml">OtherTRBEManagementEvent</a>('000011');
    <a link="func_TryAssertTRBIRQ_0" file="shared_pseudocode.xml">TryAssertTRBIRQ</a>();
end;</pstext></ps>
    <ps name="shared/trace/TraceBranch/BranchNotTaken" mylink="shared.trace.TraceBranch.BranchNotTaken" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// BranchNotTaken()
// ================
// Called when a branch is not taken.

func <anchor link="func_BranchNotTaken_2">BranchNotTaken</anchor>(branchtype : <a link="type_BranchType" file="shared_pseudocode.xml">BranchType</a>, branch_conditional : boolean)
begin
    let branchtaken : boolean = FALSE;
    if IsFeatureImplemented(FEAT_SPE) then
        <a link="func_SPEBranch_5" file="shared_pseudocode.xml">SPEBranch</a>{64}(ARBITRARY : bits(64), branchtype, branch_conditional, branchtaken);
    end;
    return;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/AllowExternalTraceBufferAccess" mylink="shared.trace.TraceBuffer.AllowExternalTraceBufferAccess" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AllowExternalTraceBufferAccess()
// ================================
// Returns TRUE if an external debug interface access to the Trace Buffer
// registers is allowed for the given Security state, FALSE otherwise.
// The access may also be subject to OS Lock, power-down, etc.

func <anchor link="func_AllowExternalTraceBufferAccess_1">AllowExternalTraceBufferAccess</anchor>(addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>) =&gt; boolean
begin
    assert IsFeatureImplemented(FEAT_TRBE_EXT);
    // FEAT_Debugv8p4 is always implemented when FEAT_TRBE_EXT is implemented.
    assert IsFeatureImplemented(FEAT_Debugv8p4);

    var etbad : bits(2) = if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then MDCR_EL3().ETBAD else '11';

    // Check for reserved values
    if !IsFeatureImplemented(FEAT_RME) &amp;&amp; etbad IN {'01','10'} then
        (-, etbad) = ConstrainUnpredictableBits{2}(<a link="enum_Unpredictable_RES_ETBAD" file="shared_pseudocode.xml">Unpredictable_RES_ETBAD</a>);
        // The value returned by ConstrainUnpredictableBits must be a
        // non-reserved value
        assert etbad IN {'00', '11'};
    end;

    case etbad of
        when '00' =&gt;
            if IsFeatureImplemented(FEAT_RME) then
                return addrdesc.paddress.paspace == <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>;
            else
                return addrdesc.paddress.paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>;
            end;
        when '01' =&gt;
            assert IsFeatureImplemented(FEAT_RME);
            return addrdesc.paddress.paspace IN {<a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>, <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>};
        when '10' =&gt;
            assert IsFeatureImplemented(FEAT_RME);
            return addrdesc.paddress.paspace IN {<a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>, <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>};
        when '11' =&gt;
            return TRUE;
    end;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/CheckForTRBEException" mylink="shared.trace.TraceBuffer.CheckForTRBEException" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckForTRBEException()
// =======================
// Take a TRBE Profiling exception if pending, permitted, and unmasked.

func <anchor link="func_CheckForTRBEException_0">CheckForTRBEException</anchor>()
begin
    if !IsFeatureImplemented(FEAT_TRBE_EXC) || !<a link="func_SelfHostedTraceEnabled_0" file="shared_pseudocode.xml">SelfHostedTraceEnabled</a>() then
        return;
    end;

    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() || <a link="func_Restarting_0" file="shared_pseudocode.xml">Restarting</a>() then
        return;
    end;

    var route_to_el3 : boolean = FALSE;
    var route_to_el2 : boolean = FALSE;
    var route_to_el1 : boolean = FALSE;

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; MDCR_EL3().TRBEE == '1x' then
        let pending : boolean = TRBSR_EL3().IRQ == '1';
        let masked  : boolean = <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL       == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
        route_to_el3 = pending &amp;&amp; !masked;
    end;

    var owning_ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>;
    var owning_el : bits(2);
    (owning_ss, owning_el) = <a link="func_TraceBufferOwner_0" file="shared_pseudocode.xml">TraceBufferOwner</a>();
    let in_owning_ss : boolean = <a link="func_IsCurrentSecurityState_1" file="shared_pseudocode.xml">IsCurrentSecurityState</a>(owning_ss);

    if <a link="func_EffectiveTRFCR_EL2_EE_0" file="shared_pseudocode.xml">EffectiveTRFCR_EL2_EE</a>() IN {'1x'} then
        let pending : boolean = TRBSR_EL2().IRQ == '1';
        let masked : boolean = (!in_owning_ss || <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> ||
                                   (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> &amp;&amp; (TRFCR_EL2().EE != '11' ||
                                                         TRFCR_EL2().KE == '0' ||
                                                         <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PM == '1')));
        route_to_el2 = pending &amp;&amp; !masked;
    end;

    if <a link="func_EffectiveTRFCR_EL1_EE_0" file="shared_pseudocode.xml">EffectiveTRFCR_EL1_EE</a>() == '11' then
        let pending : boolean = TRBSR_EL1().IRQ == '1';
        let masked  : boolean = (!in_owning_ss || <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL IN {<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>} ||
                                   (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp; (TRFCR_EL1().KE == '0' ||
                                                         <a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.PM == '1')));
        if <a link="func_EffectiveTGE_0" file="shared_pseudocode.xml">EffectiveTGE</a>() == '1' then
            route_to_el2 = route_to_el2 || (pending &amp;&amp; !masked);
        else
            route_to_el1 = pending &amp;&amp; !masked;
        end;
    end;

    let fsc : bits(5) = '00010';        // TRBE exception
    let synchronous : boolean = FALSE;

    // The relative priorities of the following checks is IMPLEMENTATION DEFINED
    if route_to_el3 then
        <a link="func_TakeProfilingException_3" file="shared_pseudocode.xml">TakeProfilingException</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>, fsc, synchronous);
    end;
    if route_to_el2 then
        <a link="func_TakeProfilingException_3" file="shared_pseudocode.xml">TakeProfilingException</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>, fsc, synchronous);
    end;
    if route_to_el1 then
        <a link="func_TakeProfilingException_3" file="shared_pseudocode.xml">TakeProfilingException</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>, fsc, synchronous);
    end;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/CheckMDCR_EL3_NSTBTrap" mylink="shared.trace.TraceBuffer.CheckMDCR_EL3_NSTBTrap" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CheckMDCR_EL3_NSTBTrap()
// ========================
// Check if the register access is trappable by MDCR_EL3.[NSTBE, NSTB]

func <anchor link="func_CheckMDCR_EL3_NSTBTrap_0">CheckMDCR_EL3_NSTBTrap</anchor>() =&gt; boolean
begin
    var state_bits : bits(3);
    var reserved   : boolean;
    (state_bits, reserved) = <a link="func_EffectiveMDCR_EL3_NSTB_0" file="shared_pseudocode.xml">EffectiveMDCR_EL3_NSTB</a>();
    return ((reserved &amp;&amp; <a link="func_ConstrainUnpredictableBool_1" file="shared_pseudocode.xml">ConstrainUnpredictableBool</a>(<a link="enum_Unpredictable_RESERVEDNSxB_Trap" file="shared_pseudocode.xml">Unpredictable_RESERVEDNSxB_Trap</a>)) ||
             state_bits[0] == '0' || state_bits[1] != <a link="func_EffectiveSCR_EL3_NS_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NS</a>() ||
             (IsFeatureImplemented(FEAT_RME) &amp;&amp; state_bits[2] != <a link="func_EffectiveSCR_EL3_NSE_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NSE</a>()));
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/CollectTrace" mylink="shared.trace.TraceBuffer.CollectTrace" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CollectTrace()
// ==============
// Called for each byte generated by the trace unit.
// Returns TRUE if the Trace Buffer Unit accepts or discards the trace
// data, and FALSE if the Trace Buffer Unit rejects the trace data.

func <anchor link="func_CollectTrace_1">CollectTrace</anchor>(datum : bits(8)) =&gt; boolean recurselimit ElementStreamSize
begin
    if !<a link="func_TraceBufferEnabled_0" file="shared_pseudocode.xml">TraceBufferEnabled</a>() then  // Trace buffer disabled
        // 'datum' is discarded
        if <a link="func_HaveImpDefTraceOutput_0" file="shared_pseudocode.xml">HaveImpDefTraceOutput</a>() then
            return <a link="func_ImpDefTraceOutput_1" file="shared_pseudocode.xml">ImpDefTraceOutput</a>(datum);
        else
            return TRUE;           // Discard the trace byte
        end;
    end;

    // If the TRBE cannot accept the trace data, it must return FALSE
    if <a link="func_TRBEInternalBufferFull_0" file="shared_pseudocode.xml">TRBEInternalBufferFull</a>() then
        return FALSE;
    end;

    if <a link="func_TraceBufferRunning_0" file="shared_pseudocode.xml">TraceBufferRunning</a>() then   // Accept the data
        let address            : bits(64) = TRBPTR_EL1();
        var ttw_abort          : boolean = FALSE;
        let ttw_abort_as_fault : boolean = (ImpDefBool(
                                            &quot;Report TRBE ExtAbort on TTW as fault&quot;));
        var addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
        var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;

        if !<a link="func_SelfHostedTraceEnabled_0" file="shared_pseudocode.xml">SelfHostedTraceEnabled</a>() then
            // The Trace Buffer Unit is using External mode.
            if IsFeatureImplemented(FEAT_RME) &amp;&amp; !<a link="func_ExternalRootInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalRootInvasiveDebugEnabled</a>() then
                if IsZero(GPCCR_EL3().[TBGPCD, GPC]) then
                    return FALSE;
                end;
            end;

            let pas : bits(2) = TRBMAR_EL1().PAS;
            let paspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a> = <a link="func_DecodePASpace_3" file="shared_pseudocode.xml">DecodePASpace</a>('0', pas[1], pas[0]);
            var valid_config : boolean = <a link="func_IsPASValid_1" file="shared_pseudocode.xml">IsPASValid</a>(pas) &amp;&amp; <a link="func_InvasiveDebugPermittedPAS_1" file="shared_pseudocode.xml">InvasiveDebugPermittedPAS</a>(paspace);
            if IsFeatureImplemented(FEAT_TRBE_MPAM) &amp;&amp; TRBMPAM_EL1().EN == '1' then
                let mpam_sp : bits(2) = TRBMPAM_EL1().MPAM_SP;
                let mpam_pa : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a> = <a link="func_DecodePASpace_3" file="shared_pseudocode.xml">DecodePASpace</a>('0', mpam_sp[1], mpam_sp[0]);
                valid_config = (valid_config &amp;&amp; <a link="func_IsPASValid_1" file="shared_pseudocode.xml">IsPASValid</a>(mpam_sp) &amp;&amp;
                                <a link="func_InvasiveDebugPermittedPAS_1" file="shared_pseudocode.xml">InvasiveDebugPermittedPAS</a>(mpam_pa));
            end;

            if !valid_config then
                <a link="func_OtherTRBEManagementEvent_1" file="shared_pseudocode.xml">OtherTRBEManagementEvent</a>('000000');
                <a link="func_TryAssertTRBIRQ_0" file="shared_pseudocode.xml">TryAssertTRBIRQ</a>();
                return TRUE;
            end;

            let el : bits(2) = ARBITRARY : bits(2);
            let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = ARBITRARY : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>;
            let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescTRBE_2" file="shared_pseudocode.xml">CreateAccDescTRBE</a>(ss, el);

            var pa : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
            pa.address = address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0];
            pa.paspace = paspace;
            let memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a> = <a link="func_S1DecodeMemAttrs_3" file="shared_pseudocode.xml">S1DecodeMemAttrs</a>(TRBMAR_EL1().Attr,
                                                                  TRBMAR_EL1().SH, TRUE);
            addrdesc = <a link="func_CreateAddressDescriptor_3" file="shared_pseudocode.xml">CreateAddressDescriptor</a>(pa, memattrs, accdesc);
            addrdesc.mecid = <a link="global_DEFAULT_MECID" file="shared_pseudocode.xml">DEFAULT_MECID</a>;
            if IsFeatureImplemented(FEAT_RME) &amp;&amp; !<a link="func_ExternalRootInvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalRootInvasiveDebugEnabled</a>() then
                let gpcf : <a link="type_GPCFRecord" file="shared_pseudocode.xml">GPCFRecord</a> = <a link="func_GranuleProtectionCheck_2" file="shared_pseudocode.xml">GranuleProtectionCheck</a>(addrdesc, accdesc);
                if gpcf.gpf == <a link="enum_GPCF_None" file="shared_pseudocode.xml">GPCF_None</a> then
                    memstatus = <a link="func_PhysMemWrite_4" file="shared_pseudocode.xml">PhysMemWrite</a>{8}(addrdesc, accdesc, datum);
                else
                    addrdesc.fault.gpcf       = gpcf;
                    addrdesc.fault.statuscode = <a link="enum_Fault_GPCFOnOutput" file="shared_pseudocode.xml">Fault_GPCFOnOutput</a>;
                end;
            else
                memstatus = <a link="func_PhysMemWrite_4" file="shared_pseudocode.xml">PhysMemWrite</a>{8}(addrdesc, accdesc, datum);
            end;
        else
            // The Trace Buffer Unit is using Self-hosted mode.
            var owning_ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>;
            var owning_el : bits(2);
            (owning_ss, owning_el) = <a link="func_TraceBufferOwner_0" file="shared_pseudocode.xml">TraceBufferOwner</a>();
            let accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescTRBE_2" file="shared_pseudocode.xml">CreateAccDescTRBE</a>(owning_ss, owning_el);

            let aligned : boolean = TRUE;
            (memstatus, addrdesc) = <a link="func_DebugMemWrite_4" file="shared_pseudocode.xml">DebugMemWrite</a>(address, accdesc, aligned, datum);

            ttw_abort = addrdesc.fault.statuscode IN {<a link="enum_Fault_SyncExternalOnWalk" file="shared_pseudocode.xml">Fault_SyncExternalOnWalk</a>,
                                                      <a link="enum_Fault_SyncParityOnWalk" file="shared_pseudocode.xml">Fault_SyncParityOnWalk</a>};
        end;

        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(addrdesc.fault.statuscode) &amp;&amp; (!ttw_abort || ttw_abort_as_fault) then
            <a link="func_DebugWriteFault_2" file="shared_pseudocode.xml">DebugWriteFault</a>(address, addrdesc.fault);
            <a link="func_TryAssertTRBIRQ_0" file="shared_pseudocode.xml">TryAssertTRBIRQ</a>();
            return TRUE;
        elsif <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) || (ttw_abort &amp;&amp; !ttw_abort_as_fault) then
            <a link="func_DebugWriteExternalAbort_3" file="shared_pseudocode.xml">DebugWriteExternalAbort</a>(memstatus, addrdesc, address);
            <a link="func_TryAssertTRBIRQ_0" file="shared_pseudocode.xml">TryAssertTRBIRQ</a>();
            return TRUE;
        end;

        // Check for Trigger Event
        let target_el : bits(2) = <a link="func_DefaultTRBEEvent_0" file="shared_pseudocode.xml">DefaultTRBEEvent</a>();
        let triggered : boolean = <a link="accessor_TRBSR_EL_1" file="shared_pseudocode.xml">TRBSR_EL</a>(target_el).TRG == '1';
        if triggered &amp;&amp; !IsZero(TRBTRG_EL1().TRG) then
            TRBTRG_EL1().TRG = (TRBTRG_EL1().TRG - 1)[31:0];
            if IsZero(TRBTRG_EL1().TRG) &amp;&amp; TRBLIMITR_EL1().TM != '11' then
                TraceUnitFlush();
                <a link="func_TraceUnitFlushOnTriggerComplete_0" file="shared_pseudocode.xml">TraceUnitFlushOnTriggerComplete</a>();
            end;
        end;

        // Increment the pointer
        var next_address : bits(64) = TRBPTR_EL1() + 1;
        if next_address[63:12] == TRBLIMITR_EL1().LIMIT then
            next_address = TRBBASER_EL1().BASE::Zeros{12};
            <a link="accessor_TRBSR_EL_1" file="shared_pseudocode.xml">TRBSR_EL</a>(target_el).WRAP = '1';
            CTI_SignalEvent(<a link="enum_CrossTriggerIn_TRBEWrap" file="shared_pseudocode.xml">CrossTriggerIn_TRBEWrap</a>);
            if TRBLIMITR_EL1().FM == '00' then     // Fill mode
                let bsc : bits(6) = '000001'; // Buffer full event
                <a link="func_OtherTRBEManagementEvent_1" file="shared_pseudocode.xml">OtherTRBEManagementEvent</a>(bsc);
            elsif TRBLIMITR_EL1().FM != '11' then  // Not Circular Buffer mode
                if <a link="accessor_TRBSR_EL_1" file="shared_pseudocode.xml">TRBSR_EL</a>(target_el).IRQ == '0' then
                    <a link="accessor_TRBSR_EL_1" file="shared_pseudocode.xml">TRBSR_EL</a>(target_el).IRQ = '1';   // Assert interrupt or exception
                    CTI_SignalEvent(<a link="enum_CrossTriggerIn_TRBEMgmt" file="shared_pseudocode.xml">CrossTriggerIn_TRBEMgmt</a>);
                end;
            end;
        end;
        TRBPTR_EL1() = next_address[63:0];

        <a link="func_TryAssertTRBIRQ_0" file="shared_pseudocode.xml">TryAssertTRBIRQ</a>();
    end;
    return TRUE;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/DefaultTRBEEvent" mylink="shared.trace.TraceBuffer.DefaultTRBEEvent" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DefaultTRBEEvent()
// ==================
// Return the target ELx for an indirect write to TRBSR_ELx for an Other buffer management
// event or anything other than a buffer management event.

func <anchor link="func_DefaultTRBEEvent_0">DefaultTRBEEvent</anchor>() =&gt; bits(2)
begin
    return <a link="func_ReportTRBEEvent_2" file="shared_pseudocode.xml">ReportTRBEEvent</a>(Zeros{6}, ARBITRARY : bits(6));
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/DetectedTraceTrigger" mylink="shared.trace.TraceBuffer.DetectedTraceTrigger" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DetectedTraceTrigger()
// ======================
// Called when the trace unit detects a trace trigger

func <anchor link="func_DetectedTraceTrigger_0">DetectedTraceTrigger</anchor>()
begin
    if <a link="func_TraceBufferRunning_0" file="shared_pseudocode.xml">TraceBufferRunning</a>() then
        let target_el : bits(2) = <a link="func_DefaultTRBEEvent_0" file="shared_pseudocode.xml">DefaultTRBEEvent</a>();
        if <a link="accessor_TRBSR_EL_1" file="shared_pseudocode.xml">TRBSR_EL</a>(target_el).TRG == '0' then
            <a link="accessor_TRBSR_EL_1" file="shared_pseudocode.xml">TRBSR_EL</a>(target_el).TRG = '1';
            if IsZero(TRBTRG_EL1().TRG) &amp;&amp; TRBLIMITR_EL1().TM != '11' then
                TraceUnitFlush();
                <a link="func_TraceUnitFlushOnTriggerComplete_0" file="shared_pseudocode.xml">TraceUnitFlushOnTriggerComplete</a>();
            end;
        end;
    end;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/EffectiveMDCR_EL3_NSTB" mylink="shared.trace.TraceBuffer.EffectiveMDCR_EL3_NSTB" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveMDCR_EL3_NSTB()
// ========================
// Return the Effective value of MDCR_EL3().[NSTBE, NSTB] field and whether it is a reserved value.

func <anchor link="func_EffectiveMDCR_EL3_NSTB_0">EffectiveMDCR_EL3_NSTB</anchor>() =&gt; (bits(3), boolean)
begin
    var state_bits : bits(3);
    var reserved   : boolean = FALSE;

    if IsFeatureImplemented(FEAT_RME) then
        state_bits = MDCR_EL3().[NSTBE, NSTB];
        if state_bits == '10x' || (!IsFeatureImplemented(FEAT_Secure) &amp;&amp; state_bits == '00x') then
            // Reserved value
            reserved = TRUE;
            (-, state_bits) = ConstrainUnpredictableBits{3}(<a link="enum_Unpredictable_RESERVEDNSxB" file="shared_pseudocode.xml">Unpredictable_RESERVEDNSxB</a>);
        end;
    else
        state_bits = '0' :: MDCR_EL3().NSTB;
    end;

    return (state_bits, reserved);
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/EffectiveTRBLIMITR_EL1_nVM" mylink="shared.trace.TraceBuffer.EffectiveTRBLIMITR_EL1_nVM" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveTRBLIMITR_EL1_nVM()
// ============================

func <anchor link="func_EffectiveTRBLIMITR_EL1_nVM_0">EffectiveTRBLIMITR_EL1_nVM</anchor>() =&gt; bit
begin
    if !<a link="func_SelfHostedTraceEnabled_0" file="shared_pseudocode.xml">SelfHostedTraceEnabled</a>() then
        // If SelfHostedTraceEnabled() is FALSE, then this function is only called when
        // FEAT_TRBE_EXT is implemented.
        assert IsFeatureImplemented(FEAT_TRBE_EXT);
        return '1';
    end;
    if IsFeatureImplemented(FEAT_TRBEv1p1) &amp;&amp; <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
        let (owning_ss, owning_el) = <a link="func_TraceBufferOwner_0" file="shared_pseudocode.xml">TraceBufferOwner</a>();
        if ((owning_ss != <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> || <a link="func_IsSecureEL2Enabled_0" file="shared_pseudocode.xml">IsSecureEL2Enabled</a>()) &amp;&amp; owning_el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> &amp;&amp;
              TRFCR_EL2().DnVM == '1') then
            return '0';
        end;
    end;
    return TRBLIMITR_EL1().nVM;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/EffectiveTRFCR_EL1_EE" mylink="shared.trace.TraceBuffer.EffectiveTRFCR_EL1_EE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveTRFCR_EL1_EE()
// =======================
// Return the Effective value of TRFCR_EL1.EE for the purpose of controlling the
// TRBE Profiling exception.

func <anchor link="func_EffectiveTRFCR_EL1_EE_0">EffectiveTRFCR_EL1_EE</anchor>() =&gt; bits(2)
begin
    if <a link="func_EffectiveTRFCR_EL2_EE_0" file="shared_pseudocode.xml">EffectiveTRFCR_EL2_EE</a>() == '00' then
        return '00';
    end;

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

    return ee;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/EffectiveTRFCR_EL2_EE" mylink="shared.trace.TraceBuffer.EffectiveTRFCR_EL2_EE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveTRFCR_EL2_EE()
// =======================
// Return the Effective value of TRFCR_EL2.EE.

func <anchor link="func_EffectiveTRFCR_EL2_EE_0">EffectiveTRFCR_EL2_EE</anchor>() =&gt; bits(2)
begin
    if !IsFeatureImplemented(FEAT_TRBE_EXC) || !<a link="func_SelfHostedTraceEnabled_0" file="shared_pseudocode.xml">SelfHostedTraceEnabled</a>() then
        return '00';
    end;

    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; MDCR_EL3().TRBEE == '00' then
        return '00';
    end;

    let check_el2 : boolean = <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; (<a link="func_EffectiveSCR_EL3_NS_0" file="shared_pseudocode.xml">EffectiveSCR_EL3_NS</a>() == '1' ||
                                                 <a link="func_IsSecureEL2Enabled_0" file="shared_pseudocode.xml">IsSecureEL2Enabled</a>());
    return if check_el2 then TRFCR_EL2().EE else '01';
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/ElementStreamSize" mylink="shared.trace.TraceBuffer.ElementStreamSize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ElementStreamSize
// =================

config ElementStreamSize : integer{0..4096} = 4096;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/GetTRBSR_EL1_FSC" mylink="shared.trace.TraceBuffer.GetTRBSR_EL1_FSC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetTRBSR_EL1_FSC()
// ==================
// Query the TRBSR_EL1.FSC field.

func <anchor link="func_GetTRBSR_EL1_FSC_0">GetTRBSR_EL1_FSC</anchor>() =&gt; bits(6)
begin
    var FSC : bits(6);

    FSC = TRBSR_EL1()[5:0];
    return FSC;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/GetTRBSR_EL2_FSC" mylink="shared.trace.TraceBuffer.GetTRBSR_EL2_FSC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetTRBSR_EL2_FSC()
// ==================
// Query the TRBSR_EL2.FSC field.

func <anchor link="func_GetTRBSR_EL2_FSC_0">GetTRBSR_EL2_FSC</anchor>() =&gt; bits(6)
begin
    var FSC : bits(6);

    FSC = TRBSR_EL2()[5:0];
    return FSC;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/GetTRBSR_EL3_FSC" mylink="shared.trace.TraceBuffer.GetTRBSR_EL3_FSC" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GetTRBSR_EL3_FSC()
// ==================
// Query the TRBSR_EL3.FSC field.

func <anchor link="func_GetTRBSR_EL3_FSC_0">GetTRBSR_EL3_FSC</anchor>() =&gt; bits(6)
begin
    var FSC : bits(6);

    FSC = TRBSR_EL3()[5:0];
    return FSC;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/HaveImpDefTraceOutput" mylink="shared.trace.TraceBuffer.HaveImpDefTraceOutput" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HaveImpDefTraceOutput()
// =======================

func <anchor link="func_HaveImpDefTraceOutput_0">HaveImpDefTraceOutput</anchor>() =&gt; boolean
begin
    return ImpDefBool(&quot;Has Enabled External Trace Port&quot;);
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/ImpDefTraceOutput" mylink="shared.trace.TraceBuffer.ImpDefTraceOutput" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ImpDefTraceOutput()
// ===================

func <anchor link="func_ImpDefTraceOutput_1">ImpDefTraceOutput</anchor>(datum : bits(8)) =&gt; boolean
begin
    // Send 'datum' to an IMPLEMENTATION DEFINED trace output port
    // return TRUE if the byte is sent
    return FALSE;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/OtherTRBEManagementEvent" mylink="shared.trace.TraceBuffer.OtherTRBEManagementEvent" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// OtherTRBEManagementEvent()
// ==========================
// Report an Other buffer management event, with the status code 'bsc'

func <anchor link="func_OtherTRBEManagementEvent_1">OtherTRBEManagementEvent</anchor>(bsc : bits(6))
begin
    <a link="func_ReportTRBEManagementEvent_2" file="shared_pseudocode.xml">ReportTRBEManagementEvent</a>('000000', bsc);
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/ReportTRBEEvent" mylink="shared.trace.TraceBuffer.ReportTRBEEvent" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ReportTRBEEvent()
// =================
// Return the target ELx for an indirect write to TRBSR_ELx.
// When the indirect write is due to a buffer management event:
// 'ec_bits' is the Event Class for the management event.
// 'fsc_bits' is the Fault Status Code when this is a fault, ignored otherwise.
// Otherwise, 'ec_bits' should be Zeros().

func <anchor link="func_ReportTRBEEvent_2">ReportTRBEEvent</anchor>(ec_bits : bits(6), fsc_bits : bits(6)) =&gt; bits(2)
begin
    var target_el : bits(2);
    var route_to_el3 : boolean = FALSE;
    var route_to_el2 : boolean = FALSE;

    if IsFeatureImplemented(FEAT_TRBE_EXC) &amp;&amp; <a link="func_SelfHostedTraceEnabled_0" file="shared_pseudocode.xml">SelfHostedTraceEnabled</a>() then
        if ec_bits == '011111' then                      // implementation defined fault
            return ImpDefBits{2}(&quot;target_el for TRBE ImpDef Fault&quot;);
        end;

        let s1fault : boolean = (ec_bits == '100100');   // Stage 1 fault
        let s2fault : boolean = (ec_bits == '100101');   // Stage 2 fault

        var gpcfault, gpfault : boolean;
        if IsFeatureImplemented(FEAT_RME) then
            // Granule Protection Check fault, other than GPF. That is, a GPT address size fault,
            // GPT walk fault, or synchronous External abort on GPT fetch.
            gpcfault = (ec_bits == '011110');
            // Other Granule Protection Fault, reported as Stage 1 or Stage 2 fault.
            gpfault  =  ((s1fault || s2fault) &amp;&amp; fsc_bits IN {'10001x', '1001xx', '101000'});
        else
            gpcfault = FALSE;
            gpfault  = FALSE;
        end;
        let sync_ext_abort : boolean = ((s1fault || s2fault) &amp;&amp;
                                           fsc_bits IN {'010000', '01001x', '0101xx', '011011'});

        var owning_ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>;
        var owning_el : bits(2);
        (owning_ss, owning_el) = <a link="func_TraceBufferOwner_0" file="shared_pseudocode.xml">TraceBufferOwner</a>();

        if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; MDCR_EL3().TRBEE == '1x' then
            route_to_el3 = (MDCR_EL3().TRBEE == '11' ||
                            gpcfault || (gpfault &amp;&amp; SCR_EL3().GPF == '1') ||
                            (sync_ext_abort &amp;&amp; <a link="func_EffectiveEA_0" file="shared_pseudocode.xml">EffectiveEA</a>() == '1'));
        end;

        if <a link="func_EffectiveTRFCR_EL2_EE_0" file="shared_pseudocode.xml">EffectiveTRFCR_EL2_EE</a>() == '1x' then
            route_to_el2 = (TRFCR_EL2().EE == '11' || (s1fault &amp;&amp; owning_el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) || s2fault ||
                            gpcfault || (gpfault &amp;&amp; HCR_EL2().GPF == '1') ||
                            (sync_ext_abort &amp;&amp; <a link="func_EffectiveHCR_TEA_0" file="shared_pseudocode.xml">EffectiveHCR_TEA</a>() == '1'));
        end;
    end;

    if route_to_el3 then
        target_el = <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
    elsif route_to_el2 then
        target_el = <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    else
        target_el = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    end;

    return target_el;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/ReportTRBEManagementEvent" mylink="shared.trace.TraceBuffer.ReportTRBEManagementEvent" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ReportTRBEManagementEvent()
// ===========================
// Report a buffer management event with the event class 'ec' and status code 'bsc'

func <anchor link="func_ReportTRBEManagementEvent_2">ReportTRBEManagementEvent</anchor>(ec : bits(6), bsc : bits(6))
begin
    let target_el : bits(2) = <a link="func_DefaultTRBEEvent_0" file="shared_pseudocode.xml">DefaultTRBEEvent</a>();
    if <a link="accessor_TRBSR_EL_1" file="shared_pseudocode.xml">TRBSR_EL</a>(target_el).S == '0' then
        <a link="accessor_TRBSR_EL_1" file="shared_pseudocode.xml">TRBSR_EL</a>(target_el).S    = '1';     // Stop collection
        if <a link="accessor_TRBSR_EL_1" file="shared_pseudocode.xml">TRBSR_EL</a>(target_el).IRQ == '0' then
            <a link="accessor_TRBSR_EL_1" file="shared_pseudocode.xml">TRBSR_EL</a>(target_el).IRQ  = '1';     // Assert interrupt or exception
            CTI_SignalEvent(<a link="enum_CrossTriggerIn_TRBEMgmt" file="shared_pseudocode.xml">CrossTriggerIn_TRBEMgmt</a>);
        end;
        <a link="accessor_TRBSR_EL_1" file="shared_pseudocode.xml">TRBSR_EL</a>(target_el).EC   = ec;
        <a link="accessor_TRBSR_EL_1" file="shared_pseudocode.xml">TRBSR_EL</a>(target_el).MSS  = ZeroExtend{16}(bsc);
        <a link="accessor_TRBSR_EL_1" file="shared_pseudocode.xml">TRBSR_EL</a>(target_el).MSS2 = Zeros{24};
        CTI_SignalEvent(<a link="enum_CrossTriggerIn_TRBEStop" file="shared_pseudocode.xml">CrossTriggerIn_TRBEStop</a>);
    end;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/TRBEInternalBufferFull" mylink="shared.trace.TraceBuffer.TRBEInternalBufferFull" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TRBEInternalBufferFull()
// ========================

func <anchor link="func_TRBEInternalBufferFull_0">TRBEInternalBufferFull</anchor>() =&gt; boolean
begin
    // In the simple sequential model, the internal buffer never fills
    return FALSE;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/TRBEInterruptEnabled" mylink="shared.trace.TraceBuffer.TRBEInterruptEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TRBEInterruptEnabled()
// ======================
// Return TRUE if the TRBE interrupt request (TRBIRQ) is enabled, FALSE otherwise.

func <anchor link="func_TRBEInterruptEnabled_0">TRBEInterruptEnabled</anchor>() =&gt; boolean
begin
    return <a link="func_EffectiveTRFCR_EL1_EE_0" file="shared_pseudocode.xml">EffectiveTRFCR_EL1_EE</a>() == '00';
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/TRBE_TRBIDR_P_Read" mylink="shared.trace.TraceBuffer.TRBE_TRBIDR_P_Read" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TRBE_TRBIDR_P_Read()
// ====================
// Called when TRBIDR_EL1 is read, returns the value of TRBIDR_EL1.P

func <anchor link="func_TRBE_TRBIDR_P_Read_0">TRBE_TRBIDR_P_Read</anchor>() =&gt; bit
begin
    var owning_ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>;
    var owning_el : bits(2);
    (owning_ss, owning_el) = <a link="func_TraceBufferOwner_0" file="shared_pseudocode.xml">TraceBufferOwner</a>();

    // Reads as one if the Trace Buffer is owned by a higher Exception
    // Level or another Security state.
    if (UInt(owning_el) &gt; UInt(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) ||
          (<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL != <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> &amp;&amp; owning_ss != <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>())) then
        return '1';
    else
        return '0';
    end;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/TRBSR_EL" mylink="shared.trace.TraceBuffer.TRBSR_EL" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TRBSR_EL - accessor
// ===================

accessor <anchor link="accessor_TRBSR_EL_1">TRBSR_EL</anchor>(el : bits(2)) &lt;=&gt; value : TRBSRType
begin
    getter
        var r : bits(64);
        case el of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;   r = TRBSR_EL1();
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;   r = TRBSR_EL2();
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;   r = TRBSR_EL3();
            otherwise =&gt;  unreachable;
        end;
        return r;
    end;

    setter
        let r : bits(64) = value;
        case el of
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;   TRBSR_EL1() = r;
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;   TRBSR_EL2() = r;
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;   TRBSR_EL3() = r;
            otherwise =&gt;  unreachable;
        end;
        return;
    end;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/TraceBufferEnabled" mylink="shared.trace.TraceBuffer.TraceBufferEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TraceBufferEnabled()
// ====================

func <anchor link="func_TraceBufferEnabled_0">TraceBufferEnabled</anchor>() =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_TRBE) then
        return FALSE;
    elsif <a link="func_SelfHostedTraceEnabled_0" file="shared_pseudocode.xml">SelfHostedTraceEnabled</a>() then
        if TRBLIMITR_EL1().E == '0' then
            return FALSE;
        end;
        var el : bits(2);
        (-, el) = <a link="func_TraceBufferOwner_0" file="shared_pseudocode.xml">TraceBufferOwner</a>();
        return !<a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(el);
    elsif IsFeatureImplemented(FEAT_TRBE_EXT) then
        return TRBLIMITR_EL1().XE == '1';
    else
        return FALSE;
    end;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/TraceBufferOwner" mylink="shared.trace.TraceBuffer.TraceBufferOwner" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TraceBufferOwner()
// ==================
// Return the owning Security state and Exception level. Must only be called
// when SelfHostedTraceEnabled() is TRUE.

func <anchor link="func_TraceBufferOwner_0">TraceBufferOwner</anchor>() =&gt; (<a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, bits(2))
begin
    assert IsFeatureImplemented(FEAT_TRBE);

    var owning_ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>;
    var state_bits :  bits(3);
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        (state_bits, -) = <a link="func_EffectiveMDCR_EL3_NSTB_0" file="shared_pseudocode.xml">EffectiveMDCR_EL3_NSTB</a>();
    else
        state_bits = if <a link="func_SecureOnlyImplementation_0" file="shared_pseudocode.xml">SecureOnlyImplementation</a>() then '001' else '011';
    end;

    case state_bits of
        when '00x' =&gt; owning_ss = <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>;
        when '01x' =&gt; owning_ss = <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a>;
        when '11x' =&gt; owning_ss = <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a>;
    end;
    var owning_el : bits(2);
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) &amp;&amp; (owning_ss != <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> || <a link="func_IsSecureEL2Enabled_0" file="shared_pseudocode.xml">IsSecureEL2Enabled</a>()) then
        owning_el = if MDCR_EL2().E2TB == '00' then <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> else <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    else
        owning_el = <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    end;
    return (owning_ss, owning_el);
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/TraceBufferRunning" mylink="shared.trace.TraceBuffer.TraceBufferRunning" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TraceBufferRunning()
// ====================

func <anchor link="func_TraceBufferRunning_0">TraceBufferRunning</anchor>() =&gt; boolean
begin
    if !<a link="func_TraceBufferEnabled_0" file="shared_pseudocode.xml">TraceBufferEnabled</a>() then
        return FALSE;
    end;

    var stopped : boolean = TRBSR_EL1().S == '1';
    if IsFeatureImplemented(FEAT_TRBE_EXC) &amp;&amp; <a link="func_SelfHostedTraceEnabled_0" file="shared_pseudocode.xml">SelfHostedTraceEnabled</a>() then
        if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; MDCR_EL3().TRBEE == '1x' then
            stopped = stopped || (TRBSR_EL3().S == '1');
        end;
        if <a link="func_EffectiveTRFCR_EL2_EE_0" file="shared_pseudocode.xml">EffectiveTRFCR_EL2_EE</a>() == '1x' then
            stopped = stopped || (TRBSR_EL2().S == '1');
        end;
    end;
    return !stopped;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/TraceUnitFlushOnTriggerComplete" mylink="shared.trace.TraceBuffer.TraceUnitFlushOnTriggerComplete" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TraceUnitFlushOnTriggerComplete()
// =================================
// Called when a trace unit flush completes following a call to
// TraceUnitFlush() due to a trace trigger.

func <anchor link="func_TraceUnitFlushOnTriggerComplete_0">TraceUnitFlushOnTriggerComplete</anchor>()
begin
    if TRBLIMITR_EL1().TM == '00' then     // Stop on trigger
        let bsc : bits(6) = '000010';      // Trigger event
        <a link="func_OtherTRBEManagementEvent_1" file="shared_pseudocode.xml">OtherTRBEManagementEvent</a>(bsc);
    elsif TRBLIMITR_EL1().TM != '11' then  // Not Ignore trigger
        let target_el : bits(2) = <a link="func_DefaultTRBEEvent_0" file="shared_pseudocode.xml">DefaultTRBEEvent</a>();
        <a link="accessor_TRBSR_EL_1" file="shared_pseudocode.xml">TRBSR_EL</a>(target_el).IRQ = '1';     // Assert interrupt or exception
    end;
end;</pstext></ps>
    <ps name="shared/trace/TraceBuffer/TryAssertTRBIRQ" mylink="shared.trace.TraceBuffer.TryAssertTRBIRQ" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TryAssertTRBIRQ()
// =================
// Assert TRBIRQ pin when appropriate.

func <anchor link="func_TryAssertTRBIRQ_0">TryAssertTRBIRQ</anchor>()
begin
    if <a link="func_TRBEInterruptEnabled_0" file="shared_pseudocode.xml">TRBEInterruptEnabled</a>() &amp;&amp; TRBSR_EL1().IRQ == '1' then
        SetInterruptRequestLevel(<a link="enum_InterruptID_TRBIRQ" file="shared_pseudocode.xml">InterruptID_TRBIRQ</a>, <a link="enum_HIGH" file="shared_pseudocode.xml">HIGH</a>);
    else
        SetInterruptRequestLevel(<a link="enum_InterruptID_TRBIRQ" file="shared_pseudocode.xml">InterruptID_TRBIRQ</a>, <a link="enum_LOW" file="shared_pseudocode.xml">LOW</a>);
    end;
    return;
end;</pstext></ps>
    <ps name="shared/trace/TraceInstrumentationAllowed/TraceInstrumentationAllowed" mylink="shared.trace.TraceInstrumentationAllowed.TraceInstrumentationAllowed" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TraceInstrumentationAllowed()
// =============================
// Returns TRUE if Instrumentation Trace is allowed
// in the given Exception level and Security state.

func <anchor link="func_TraceInstrumentationAllowed_2">TraceInstrumentationAllowed</anchor>(ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>, el : bits(2)) =&gt; boolean
begin
    if !IsFeatureImplemented(FEAT_ITE) then return FALSE; end;
    if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(el) then return FALSE; end;

    if <a link="func_TraceAllowed_1" file="shared_pseudocode.xml">TraceAllowed</a>(el) then
        var ite_bit : bit;
        case el of
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt; ite_bit = '0';
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt; ite_bit = TRCITECR_EL2().E2E;
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt; ite_bit = TRCITECR_EL1().E1E;
            when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
                if <a link="func_EffectiveTGE_0" file="shared_pseudocode.xml">EffectiveTGE</a>() == '1' then
                    ite_bit = TRCITECR_EL2().E0HE;
                else
                    ite_bit = TRCITECR_EL1().E0E;
                end;
        end;

        if <a link="func_SelfHostedTraceEnabled_0" file="shared_pseudocode.xml">SelfHostedTraceEnabled</a>() then
            return ite_bit == '1';
        else
            var el_bit : bit;
            var ss_bit : bit;
            case el of
                when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt; el_bit = TRCITEEDCR().E0;
                when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt; el_bit = TRCITEEDCR().E1;
                when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt; el_bit = TRCITEEDCR().E2;
                when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt; el_bit = TRCITEEDCR().E3;
            end;
            case ss of
                when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;     ss_bit = TRCITEEDCR().RL;
                when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;    ss_bit = TRCITEEDCR().S;
                when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt; ss_bit = TRCITEEDCR().NS;
                otherwise =&gt; ss_bit = '1';
            end;

            let ed_allowed : boolean = ss_bit == '1' &amp;&amp; el_bit == '1';

            if TRCCONFIGR().ITO == '1' then
                return ed_allowed;
            else
                return ed_allowed &amp;&amp; ite_bit == '1';
            end;
        end;
    else
        return FALSE;
    end;
end;</pstext></ps>
    <ps name="shared/trace/TraceProcessElements/TraceUnitFlush" mylink="shared.trace.TraceProcessElements.TraceUnitFlush" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TraceUnitFlush()
// ================
// Called when a trace unit flush is requested, to output previous recorded trace.

impdef func TraceUnitFlush()
begin
    return;
end;</pstext></ps>
    <ps name="shared/trace/selfhosted/EffectiveE0HTRE" mylink="shared.trace.selfhosted.EffectiveE0HTRE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveE0HTRE()
// =================
// Returns effective E0HTRE value

func <anchor link="func_EffectiveE0HTRE_0">EffectiveE0HTRE</anchor>() =&gt; bit
begin
    return if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then HTRFCR().E0HTRE else TRFCR_EL2().E0HTRE;
end;</pstext></ps>
    <ps name="shared/trace/selfhosted/EffectiveE0TRE" mylink="shared.trace.selfhosted.EffectiveE0TRE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveE0TRE()
// ================
// Returns effective E0TRE value

func <anchor link="func_EffectiveE0TRE_0">EffectiveE0TRE</anchor>() =&gt; bit
begin
    return if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>) then TRFCR().E0TRE else TRFCR_EL1().E0TRE;
end;</pstext></ps>
    <ps name="shared/trace/selfhosted/EffectiveE1TRE" mylink="shared.trace.selfhosted.EffectiveE1TRE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveE1TRE()
// ================
// Returns effective E1TRE value

func <anchor link="func_EffectiveE1TRE_0">EffectiveE1TRE</anchor>() =&gt; bit
begin
    return if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then TRFCR().E1TRE else TRFCR_EL1().E1TRE;
end;</pstext></ps>
    <ps name="shared/trace/selfhosted/EffectiveE2TRE" mylink="shared.trace.selfhosted.EffectiveE2TRE" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveE2TRE()
// ================
// Returns effective E2TRE value

func <anchor link="func_EffectiveE2TRE_0">EffectiveE2TRE</anchor>() =&gt; bit
begin
    return if <a link="func_UsingAArch32_0" file="shared_pseudocode.xml">UsingAArch32</a>() then HTRFCR().E2TRE else TRFCR_EL2().E2TRE;
end;</pstext></ps>
    <ps name="shared/trace/selfhosted/SelfHostedTraceEnabled" mylink="shared.trace.selfhosted.SelfHostedTraceEnabled" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SelfHostedTraceEnabled()
// ========================
// Returns TRUE if Self-hosted Trace is enabled.

readonly func <anchor link="func_SelfHostedTraceEnabled_0">SelfHostedTraceEnabled</anchor>() =&gt; boolean
begin
    var secure_trace_enable : bit = '0';
    if !(<a link="func_HaveTraceExt_0" file="shared_pseudocode.xml">HaveTraceExt</a>() &amp;&amp; IsFeatureImplemented(FEAT_TRF)) then return FALSE; end;
    if EDSCR().TFO == '0' then return TRUE; end;
    if IsFeatureImplemented(FEAT_RME) then
        secure_trace_enable = if IsFeatureImplemented(FEAT_SEL2) then MDCR_EL3().STE else '0';
        return ((secure_trace_enable == '1' &amp;&amp; !<a link="func_ExternalSecureNoninvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalSecureNoninvasiveDebugEnabled</a>()) ||
                (MDCR_EL3().RLTE == '1' &amp;&amp; !<a link="func_ExternalRealmNoninvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalRealmNoninvasiveDebugEnabled</a>()));
    end;
    if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
        secure_trace_enable = if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then SDCR().STE else MDCR_EL3().STE;
    else
        secure_trace_enable = if <a link="func_SecureOnlyImplementation_0" file="shared_pseudocode.xml">SecureOnlyImplementation</a>() then '1' else '0';
    end;

    if secure_trace_enable == '1' &amp;&amp; !<a link="func_ExternalSecureNoninvasiveDebugEnabled_0" file="shared_pseudocode.xml">ExternalSecureNoninvasiveDebugEnabled</a>() then
        return TRUE;
    end;

    return FALSE;
end;</pstext></ps>
    <ps name="shared/trace/selfhosted/TraceAllowed" mylink="shared.trace.selfhosted.TraceAllowed" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TraceAllowed()
// ==============
// Returns TRUE if Self-hosted Trace is allowed in the given Exception level.

func <anchor link="func_TraceAllowed_1">TraceAllowed</anchor>(el : bits(2)) =&gt; boolean
begin
    if !<a link="func_HaveTraceExt_0" file="shared_pseudocode.xml">HaveTraceExt</a>() then
        return FALSE;
    end;
    // If in Debug state then tracing is not allowed
    if <a link="func_Halted_0" file="shared_pseudocode.xml">Halted</a>() &amp;&amp; !<a link="func_Restarting_0" file="shared_pseudocode.xml">Restarting</a>() then
        return FALSE;
    end;
    if <a link="func_SelfHostedTraceEnabled_0" file="shared_pseudocode.xml">SelfHostedTraceEnabled</a>() then
        var trace_allowed : boolean;
        let ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a> = <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(el);
        // Detect scenarios where tracing in this Security state is never allowed.
        case ss of
            when <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a> =&gt;
                trace_allowed = TRUE;
            when <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> =&gt;
                var trace_bit : bit;
                if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
                    trace_bit = if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then SDCR().STE else MDCR_EL3().STE;
                else
                    trace_bit = '1';
                end;
                trace_allowed = trace_bit == '1';
            when <a link="enum_SS_Realm" file="shared_pseudocode.xml">SS_Realm</a> =&gt;
                trace_allowed = MDCR_EL3().RLTE == '1';
            when <a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a> =&gt;
                trace_allowed = FALSE;
        end;

        // Tracing is prohibited if the trace buffer owning security state is not the
        // current Security state or the owning Exception level is a lower Exception level.
        if IsFeatureImplemented(FEAT_TRBE) &amp;&amp; <a link="func_TraceBufferEnabled_0" file="shared_pseudocode.xml">TraceBufferEnabled</a>() then
            let (owning_ss, owning_el) = <a link="func_TraceBufferOwner_0" file="shared_pseudocode.xml">TraceBufferOwner</a>();
            if (ss != owning_ss || UInt(owning_el) &lt; UInt(el) ||
                (<a link="func_EffectiveTGE_0" file="shared_pseudocode.xml">EffectiveTGE</a>() == '1' &amp;&amp; owning_el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>)) then
                trace_allowed = FALSE;
            end;
        end;

        var TRE_bit : bit;
        case el of
            when <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> =&gt;  TRE_bit = if !<a link="func_HaveAArch64_0" file="shared_pseudocode.xml">HaveAArch64</a>() then TRFCR().E1TRE else '0';
            when <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> =&gt;  TRE_bit = <a link="func_EffectiveE2TRE_0" file="shared_pseudocode.xml">EffectiveE2TRE</a>();
            when <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> =&gt;  TRE_bit = <a link="func_EffectiveE1TRE_0" file="shared_pseudocode.xml">EffectiveE1TRE</a>();
            when <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> =&gt;
                if <a link="func_EffectiveTGE_0" file="shared_pseudocode.xml">EffectiveTGE</a>() == '1' then
                    TRE_bit = <a link="func_EffectiveE0HTRE_0" file="shared_pseudocode.xml">EffectiveE0HTRE</a>();
                else
                    TRE_bit = <a link="func_EffectiveE0TRE_0" file="shared_pseudocode.xml">EffectiveE0TRE</a>();
                end;
        end;

        return trace_allowed &amp;&amp; TRE_bit == '1';
    else
        return <a link="func_ExternalNoninvasiveDebugAllowed_1" file="shared_pseudocode.xml">ExternalNoninvasiveDebugAllowed</a>(el);
    end;
end;</pstext></ps>
    <ps name="shared/trace/selfhosted/TraceContextIDR2" mylink="shared.trace.selfhosted.TraceContextIDR2" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TraceContextIDR2()
// ==================

func <anchor link="func_TraceContextIDR2_0">TraceContextIDR2</anchor>() =&gt; boolean
begin
    if !<a link="func_TraceAllowed_1" file="shared_pseudocode.xml">TraceAllowed</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL)|| !<a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then return FALSE; end;
    return (!<a link="func_SelfHostedTraceEnabled_0" file="shared_pseudocode.xml">SelfHostedTraceEnabled</a>() || TRFCR_EL2().CX == '1');
end;</pstext></ps>
    <ps name="shared/trace/selfhosted/TraceSynchronizationBarrier" mylink="shared.trace.selfhosted.TraceSynchronizationBarrier" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TraceSynchronizationBarrier()
// =============================
// Barrier instruction that preserves the relative order of accesses to System
// registers due to trace operations and other accesses to the same registers.
// When FEAT_TRBE is implemented, a TraceSynchronizationBarrier also acts as a memory
// barrier operation to flush any trace data generated by the trace unit, such that
// a subsequent Data Synchronization Barrier does not complete until the trace data
// has been written to memory.

func <anchor link="func_TraceSynchronizationBarrier_0">TraceSynchronizationBarrier</anchor>()
begin
    if IsFeatureImplemented(FEAT_TRBE) &amp;&amp; !<a link="func_TraceAllowed_1" file="shared_pseudocode.xml">TraceAllowed</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL) then
        TraceUnitFlush();
    end;
    return;
end;</pstext></ps>
    <ps name="shared/trace/selfhosted/TraceTimeStamp" mylink="shared.trace.selfhosted.TraceTimeStamp" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TraceTimeStamp()
// ================

func <anchor link="func_TraceTimeStamp_0">TraceTimeStamp</anchor>() =&gt; <a link="type_TimeStamp" file="shared_pseudocode.xml">TimeStamp</a>
begin
    if <a link="func_SelfHostedTraceEnabled_0" file="shared_pseudocode.xml">SelfHostedTraceEnabled</a>() then
        if <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then
            var TS_el2 : bits(2) = TRFCR_EL2().TS;
            if !IsFeatureImplemented(FEAT_ECV) &amp;&amp; TS_el2 == '10' then
                // Reserved value
                (-, TS_el2) = ConstrainUnpredictableBits{2}(<a link="enum_Unpredictable_EL2TIMESTAMP" file="shared_pseudocode.xml">Unpredictable_EL2TIMESTAMP</a>);
            end;

            case TS_el2 of
                when '00' =&gt;
                    // Falls out to check TRFCR_EL1.TS
                    pass;
                when '01' =&gt;
                    return <a link="enum_TimeStamp_Virtual" file="shared_pseudocode.xml">TimeStamp_Virtual</a>;
                when '10' =&gt;
                    // Otherwise ConstrainUnpredictableBits removes this case
                    assert IsFeatureImplemented(FEAT_ECV);
                    return <a link="enum_TimeStamp_OffsetPhysical" file="shared_pseudocode.xml">TimeStamp_OffsetPhysical</a>;
                when '11' =&gt;
                    return <a link="enum_TimeStamp_Physical" file="shared_pseudocode.xml">TimeStamp_Physical</a>;
            end;
        end;

        var TS_el1 : bits(2) = TRFCR_EL1().TS;
        if TS_el1 == '00' || (!IsFeatureImplemented(FEAT_ECV) &amp;&amp; TS_el1 == '10') then
            // Reserved value
            (-, TS_el1) = ConstrainUnpredictableBits{2}(<a link="enum_Unpredictable_EL1TIMESTAMP" file="shared_pseudocode.xml">Unpredictable_EL1TIMESTAMP</a>);
        end;

        case TS_el1 of
            when '01' =&gt;
                return <a link="enum_TimeStamp_Virtual" file="shared_pseudocode.xml">TimeStamp_Virtual</a>;
            when '10' =&gt;
                assert IsFeatureImplemented(FEAT_ECV);
                return <a link="enum_TimeStamp_OffsetPhysical" file="shared_pseudocode.xml">TimeStamp_OffsetPhysical</a>;
            when '11' =&gt;
                return <a link="enum_TimeStamp_Physical" file="shared_pseudocode.xml">TimeStamp_Physical</a>;
            otherwise =&gt;
                unreachable;         // ConstrainUnpredictableBits removes this case
        end;
    else
        return <a link="enum_TimeStamp_CoreSight" file="shared_pseudocode.xml">TimeStamp_CoreSight</a>;
    end;
end;</pstext></ps>
    <ps name="shared/trace/system/IsTraceCorePowered" mylink="shared.trace.system.IsTraceCorePowered" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsTraceCorePowered()
// ====================
// Returns TRUE if the trace unit Core power domain is powered up

impdef func <anchor link="func_IsTraceCorePowered_0">IsTraceCorePowered</anchor>() =&gt; boolean
begin
    return TRUE;
end;</pstext></ps>
    <ps name="shared/translation/at" mylink="shared.translation.at" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">type <anchor link="type_TranslationStage">TranslationStage</anchor> of enumeration {
    <anchor link="enum_TranslationStage_1">TranslationStage_1</anchor>,
    <anchor link="enum_TranslationStage_12">TranslationStage_12</anchor>
};

type <anchor link="type_ATAccess">ATAccess</anchor> of enumeration {
    <anchor link="enum_ATAccess_Read">ATAccess_Read</anchor>,
    <anchor link="enum_ATAccess_Write">ATAccess_Write</anchor>,
    <anchor link="enum_ATAccess_Any">ATAccess_Any</anchor>,
    <anchor link="enum_ATAccess_ReadPAN">ATAccess_ReadPAN</anchor>,
    <anchor link="enum_ATAccess_WritePAN">ATAccess_WritePAN</anchor>
};</pstext></ps>
    <ps name="shared/translation/at/EncodePARAttrs" mylink="shared.translation.at.EncodePARAttrs" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EncodePARAttrs()
// ================
// Convert orthogonal attributes and hints to 64-bit PAR ATTR field.

func <anchor link="func_EncodePARAttrs_1">EncodePARAttrs</anchor>(memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>) =&gt; bits(8)
begin
    var result : bits(8);

    if IsFeatureImplemented(FEAT_MTE) &amp;&amp; memattrs.tags == <a link="enum_MemTag_AllocationTagged" file="shared_pseudocode.xml">MemTag_AllocationTagged</a> then
        if IsFeatureImplemented(FEAT_MTE_PERM) &amp;&amp; memattrs.notagaccess then
            result[7:0] = '11100000';
        else
            result[7:0] = '11110000';
        end;
        return result;
    end;

    if memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> then
        result[7:4] = '0000';
        case memattrs.device of
            when <a link="enum_DeviceType_nGnRnE" file="shared_pseudocode.xml">DeviceType_nGnRnE</a> =&gt; result[3:0] = '0000';
            when <a link="enum_DeviceType_nGnRE" file="shared_pseudocode.xml">DeviceType_nGnRE</a>  =&gt; result[3:0] = '0100';
            when <a link="enum_DeviceType_nGRE" file="shared_pseudocode.xml">DeviceType_nGRE</a>   =&gt; result[3:0] = '1000';
            when <a link="enum_DeviceType_GRE" file="shared_pseudocode.xml">DeviceType_GRE</a>    =&gt; result[3:0] = '1100';
            otherwise              =&gt; unreachable;
        end;
        result[0] = NOT memattrs.xs;
    else
        if memattrs.xs == '0' then
            if (memattrs.outer.attrs == <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a> &amp;&amp; memattrs.inner.attrs == <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a> &amp;&amp;
                  !memattrs.outer.transient &amp;&amp; memattrs.outer.hints == <a link="global_MemHint_RA" file="shared_pseudocode.xml">MemHint_RA</a>) then
                return '10100000';
            elsif memattrs.outer.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> &amp;&amp; memattrs.inner.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> then
                return '01000000';
            end;
        end;

        if memattrs.outer.attrs == <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a> then
            result[7:6] = if memattrs.outer.transient then '00' else '10';
            result[5:4] = memattrs.outer.hints;
        elsif memattrs.outer.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a> then
            result[7:6] = if memattrs.outer.transient then '01' else '11';
            result[5:4] = memattrs.outer.hints;
        else // MemAttr_NC
            result[7:4] = '0100';
        end;

        if memattrs.inner.attrs == <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a> then
            result[3:2] = if memattrs.inner.transient then '00' else '10';
            result[1:0] = memattrs.inner.hints;
        elsif memattrs.inner.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a> then
            result[3:2] = if memattrs.inner.transient then '01' else '11';
            result[1:0] = memattrs.inner.hints;
        else // MemAttr_NC
            result[3:0] = '0100';
        end;
    end;

    return result;
end;</pstext></ps>
    <ps name="shared/translation/at/PAREncodeShareability" mylink="shared.translation.at.PAREncodeShareability" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PAREncodeShareability()
// =======================
// Derive 64-bit PAR SH field.

func <anchor link="func_PAREncodeShareability_1">PAREncodeShareability</anchor>(memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>) =&gt; bits(2)
begin
    if (memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> ||
            (memattrs.inner.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> &amp;&amp;
             memattrs.outer.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>)) then
        // Force Outer-Shareable on Device and Normal Non-Cacheable memory
        return '10';
    end;

    case memattrs.shareability of
        when <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a> =&gt; return '00';
        when <a link="enum_Shareability_ISH" file="shared_pseudocode.xml">Shareability_ISH</a> =&gt; return '11';
        when <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a> =&gt; return '10';
    end;
end;</pstext></ps>
    <ps name="shared/translation/at/ReportedPARAttrs" mylink="shared.translation.at.ReportedPARAttrs" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ReportedPARAttrs()
// ==================
// The value returned in this field can be the resulting attribute, as determined by any permitted
// implementation choices and any applicable configuration bits, instead of the value that appears
// in the translation table descriptor.

impdef func <anchor link="func_ReportedPARAttrs_1">ReportedPARAttrs</anchor>(parattrs : bits(8)) =&gt; bits(8)
begin
    return parattrs;
end;</pstext></ps>
    <ps name="shared/translation/at/ReportedPARShareability" mylink="shared.translation.at.ReportedPARShareability" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ReportedPARShareability()
// =========================
// The value returned in SH field can be the resulting attribute, as determined by any
// permitted implementation choices and any applicable configuration bits, instead of
// the value that appears in the translation table descriptor.

impdef func <anchor link="func_ReportedPARShareability_1">ReportedPARShareability</anchor>(sh : bits(2)) =&gt; bits(2)
begin
    return sh;
end;</pstext></ps>
    <ps name="shared/translation/attrs/DecodeDevice" mylink="shared.translation.attrs.DecodeDevice" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodeDevice()
// ==============
// Decode output Device type

func <anchor link="func_DecodeDevice_1">DecodeDevice</anchor>(device : bits(2)) =&gt; <a link="type_DeviceType" file="shared_pseudocode.xml">DeviceType</a>
begin
    case device of
        when '00' =&gt; return <a link="enum_DeviceType_nGnRnE" file="shared_pseudocode.xml">DeviceType_nGnRnE</a>;
        when '01' =&gt; return <a link="enum_DeviceType_nGnRE" file="shared_pseudocode.xml">DeviceType_nGnRE</a>;
        when '10' =&gt; return <a link="enum_DeviceType_nGRE" file="shared_pseudocode.xml">DeviceType_nGRE</a>;
        when '11' =&gt; return <a link="enum_DeviceType_GRE" file="shared_pseudocode.xml">DeviceType_GRE</a>;
    end;
end;</pstext></ps>
    <ps name="shared/translation/attrs/DecodeLDFAttr" mylink="shared.translation.attrs.DecodeLDFAttr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodeLDFAttr()
// ===============
// Decode memory attributes using LDF (Long Descriptor Format) mapping

func <anchor link="func_DecodeLDFAttr_1">DecodeLDFAttr</anchor>(attr : bits(4)) =&gt; <a link="type_MemAttrHints" file="shared_pseudocode.xml">MemAttrHints</a>
begin
    var ldfattr : <a link="type_MemAttrHints" file="shared_pseudocode.xml">MemAttrHints</a>;

    if    attr == 'x0xx' then ldfattr.attrs = <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a>; // Write-through
    elsif attr == '0100' then ldfattr.attrs = <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>; // Non-cacheable
    elsif attr == 'x1xx' then ldfattr.attrs = <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>; // Write-back
    else                      unreachable;
    end;

    // Allocation hints are applicable only to cacheable memory.
    if ldfattr.attrs != <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> then
        case attr[1:0] of
            when '00' =&gt; ldfattr.hints = <a link="global_MemHint_No" file="shared_pseudocode.xml">MemHint_No</a>;  // No allocation hints
            when '01' =&gt; ldfattr.hints = <a link="global_MemHint_WA" file="shared_pseudocode.xml">MemHint_WA</a>;  // Write-allocate
            when '10' =&gt; ldfattr.hints = <a link="global_MemHint_RA" file="shared_pseudocode.xml">MemHint_RA</a>;  // Read-allocate
            when '11' =&gt; ldfattr.hints = <a link="global_MemHint_RWA" file="shared_pseudocode.xml">MemHint_RWA</a>; // Read/Write allocate
        end;
    end;

    // The Transient hint applies only to cacheable memory with some allocation hints.
    if ldfattr.attrs != <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> &amp;&amp; ldfattr.hints != <a link="global_MemHint_No" file="shared_pseudocode.xml">MemHint_No</a> then
        ldfattr.transient = attr[3] == '0';
    end;

    return ldfattr;
end;</pstext></ps>
    <ps name="shared/translation/attrs/DecodeSDFAttr" mylink="shared.translation.attrs.DecodeSDFAttr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodeSDFAttr()
// ===============
// Decode memory attributes using SDF (Short Descriptor Format) mapping

func <anchor link="func_DecodeSDFAttr_1">DecodeSDFAttr</anchor>(rgn : bits(2)) =&gt; <a link="type_MemAttrHints" file="shared_pseudocode.xml">MemAttrHints</a>
begin
    var sdfattr : <a link="type_MemAttrHints" file="shared_pseudocode.xml">MemAttrHints</a>;

    case rgn of
        when '00' =&gt;                   // Non-cacheable (no allocate)
            sdfattr.attrs = <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>;
        when '01' =&gt;                   // Write-back, Read and Write allocate
            sdfattr.attrs = <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>;
            sdfattr.hints = <a link="global_MemHint_RWA" file="shared_pseudocode.xml">MemHint_RWA</a>;
        when '10' =&gt;                   // Write-through, Read allocate
            sdfattr.attrs = <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a>;
            sdfattr.hints = <a link="global_MemHint_RA" file="shared_pseudocode.xml">MemHint_RA</a>;
        when '11' =&gt;                   // Write-back, Read allocate
            sdfattr.attrs = <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>;
            sdfattr.hints = <a link="global_MemHint_RA" file="shared_pseudocode.xml">MemHint_RA</a>;
    end;

    sdfattr.transient = FALSE;

    return sdfattr;
end;</pstext></ps>
    <ps name="shared/translation/attrs/DecodeShareability" mylink="shared.translation.attrs.DecodeShareability" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodeShareability()
// ====================
// Decode shareability of target memory region

func <anchor link="func_DecodeShareability_1">DecodeShareability</anchor>(sh : bits(2)) =&gt; <a link="type_Shareability" file="shared_pseudocode.xml">Shareability</a>
begin
    case sh of
        when '10' =&gt; return <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
        when '11' =&gt; return <a link="enum_Shareability_ISH" file="shared_pseudocode.xml">Shareability_ISH</a>;
        when '00' =&gt; return <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a>;
        otherwise =&gt;
            case ConstrainUnpredictable(<a link="enum_Unpredictable_Shareability" file="shared_pseudocode.xml">Unpredictable_Shareability</a>) of
                when <a link="enum_Constraint_OSH" file="shared_pseudocode.xml">Constraint_OSH</a> =&gt; return <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
                when <a link="enum_Constraint_ISH" file="shared_pseudocode.xml">Constraint_ISH</a> =&gt; return <a link="enum_Shareability_ISH" file="shared_pseudocode.xml">Shareability_ISH</a>;
                when <a link="enum_Constraint_NSH" file="shared_pseudocode.xml">Constraint_NSH</a> =&gt; return <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a>;
            end;
    end;
end;</pstext></ps>
    <ps name="shared/translation/attrs/EffectiveShareability" mylink="shared.translation.attrs.EffectiveShareability" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// EffectiveShareability()
// =======================
// Force Outer Shareability on Device and Normal iNCoNC memory

func <anchor link="func_EffectiveShareability_1">EffectiveShareability</anchor>(memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>) =&gt; <a link="type_Shareability" file="shared_pseudocode.xml">Shareability</a>
begin
    if (memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> ||
          (memattrs.inner.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> &amp;&amp;
           memattrs.outer.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>)) then
        return <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
    else
        return memattrs.shareability;
    end;
end;</pstext></ps>
    <ps name="shared/translation/attrs/IsTaggableMemAttr" mylink="shared.translation.attrs.IsTaggableMemAttr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsTaggableMemAttr()
// ===================
// Determine whether the current memory attributes support MTE

func <anchor link="func_IsTaggableMemAttr_1">IsTaggableMemAttr</anchor>(attrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>) =&gt; boolean
begin
    return ((attrs.memtype == <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>)  &amp;&amp;
            (attrs.inner.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>)  &amp;&amp;
            (attrs.inner.hints == <a link="global_MemHint_RWA" file="shared_pseudocode.xml">MemHint_RWA</a>) &amp;&amp;
            (!attrs.inner.transient)           &amp;&amp;
            (attrs.outer.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>)  &amp;&amp;
            (attrs.outer.hints == <a link="global_MemHint_RWA" file="shared_pseudocode.xml">MemHint_RWA</a>) &amp;&amp;
            (!attrs.outer.transient));
end;</pstext></ps>
    <ps name="shared/translation/attrs/IsWBShareable" mylink="shared.translation.attrs.IsWBShareable" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsWBShareable()
// ===============
// Determines whether the given memory attributes are iWBoWB Shareable

func <anchor link="func_IsWBShareable_1">IsWBShareable</anchor>(memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>) =&gt; boolean
begin

    return (memattrs.memtype == <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a> &amp;&amp;
            memattrs.inner.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a> &amp;&amp;
            memattrs.outer.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a> &amp;&amp;
            memattrs.shareability IN {<a link="enum_Shareability_ISH" file="shared_pseudocode.xml">Shareability_ISH</a>, <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>});
end;</pstext></ps>
    <ps name="shared/translation/attrs/NormalNCMemAttr" mylink="shared.translation.attrs.NormalNCMemAttr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// NormalNCMemAttr()
// =================
// Normal Non-cacheable memory attributes

func <anchor link="func_NormalNCMemAttr_0">NormalNCMemAttr</anchor>() =&gt; <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>
begin
    var non_cacheable : <a link="type_MemAttrHints" file="shared_pseudocode.xml">MemAttrHints</a>;
    non_cacheable.attrs = <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>;

    var nc_memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>;
    nc_memattrs.memtype      = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
    nc_memattrs.outer        = non_cacheable;
    nc_memattrs.inner        = non_cacheable;
    nc_memattrs.shareability = <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
    nc_memattrs.tags         = <a link="enum_MemTag_Untagged" file="shared_pseudocode.xml">MemTag_Untagged</a>;
    nc_memattrs.notagaccess  = FALSE;

    return nc_memattrs;
end;</pstext></ps>
    <ps name="shared/translation/attrs/S1ConstrainUnpredictableRESMAIR" mylink="shared.translation.attrs.S1ConstrainUnpredictableRESMAIR" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// S1ConstrainUnpredictableRESMAIR()
// =================================
// Determine whether a reserved value occupies MAIR_ELx.AttrN

func <anchor link="func_S1ConstrainUnpredictableRESMAIR_2">S1ConstrainUnpredictableRESMAIR</anchor>(attr : bits(8), s1aarch64 : boolean) =&gt; boolean
begin
    case attr of
        when '0000xx01' =&gt; return !(s1aarch64 &amp;&amp; IsFeatureImplemented(FEAT_XS));
        when '0000xxxx' =&gt; return attr[1:0] != '00';
        when '01000000' =&gt; return !(s1aarch64 &amp;&amp; IsFeatureImplemented(FEAT_XS));
        when '10100000' =&gt; return !(s1aarch64 &amp;&amp; IsFeatureImplemented(FEAT_XS));
        when '11110000' =&gt; return !(s1aarch64 &amp;&amp; IsFeatureImplemented(FEAT_MTE2));
        when 'xxxx0000' =&gt; return TRUE;
        otherwise       =&gt; return FALSE;
    end;
end;</pstext></ps>
    <ps name="shared/translation/attrs/S1DecodeMemAttrs" mylink="shared.translation.attrs.S1DecodeMemAttrs" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// S1DecodeMemAttrs()
// ==================
// Decode MAIR-format memory attributes assigned in stage 1

func <anchor link="func_S1DecodeMemAttrs_3">S1DecodeMemAttrs</anchor>(attr_in : bits(8), sh : bits(2), s1aarch64 : boolean) =&gt; <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>
begin
    var attr : bits(8) = attr_in;
    if <a link="func_S1ConstrainUnpredictableRESMAIR_2" file="shared_pseudocode.xml">S1ConstrainUnpredictableRESMAIR</a>(attr, s1aarch64) then
        // Map reserved encodings to an allocated encoding
        (-, attr) = ConstrainUnpredictableBits{8}(<a link="enum_Unpredictable_RESMAIR" file="shared_pseudocode.xml">Unpredictable_RESMAIR</a>);
    end;

    var memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>;
    case attr of
        when '0000xxxx' =&gt; // Device memory
            memattrs.memtype = <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a>;
            memattrs.device  = <a link="func_DecodeDevice_1" file="shared_pseudocode.xml">DecodeDevice</a>(attr[3:2]);
            memattrs.xs      = if s1aarch64 then NOT attr[0] else '1';
        when '01000000' =&gt;
            assert s1aarch64 &amp;&amp; IsFeatureImplemented(FEAT_XS);
            memattrs.memtype = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
            memattrs.outer.attrs = <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>;
            memattrs.inner.attrs = <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>;
            memattrs.xs          = '0';
        when '10100000' =&gt;
            assert s1aarch64 &amp;&amp; IsFeatureImplemented(FEAT_XS);
            memattrs.memtype = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
            memattrs.outer.attrs     = <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a>;
            memattrs.outer.hints     = <a link="global_MemHint_RA" file="shared_pseudocode.xml">MemHint_RA</a>;
            memattrs.outer.transient = FALSE;
            memattrs.inner.attrs     = <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a>;
            memattrs.inner.hints     = <a link="global_MemHint_RA" file="shared_pseudocode.xml">MemHint_RA</a>;
            memattrs.inner.transient = FALSE;
            memattrs.xs              = '0';
        when '11110000' =&gt; // Tagged memory
            assert s1aarch64 &amp;&amp; IsFeatureImplemented(FEAT_MTE2);
            memattrs.memtype = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
            memattrs.outer.attrs     = <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>;
            memattrs.outer.hints     = <a link="global_MemHint_RWA" file="shared_pseudocode.xml">MemHint_RWA</a>;
            memattrs.outer.transient = FALSE;
            memattrs.inner.attrs     = <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>;
            memattrs.inner.hints     = <a link="global_MemHint_RWA" file="shared_pseudocode.xml">MemHint_RWA</a>;
            memattrs.inner.transient = FALSE;
            memattrs.xs              = '0';
        otherwise =&gt;
            memattrs.memtype = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
            memattrs.outer   = <a link="func_DecodeLDFAttr_1" file="shared_pseudocode.xml">DecodeLDFAttr</a>(attr[7:4]);
            memattrs.inner   = <a link="func_DecodeLDFAttr_1" file="shared_pseudocode.xml">DecodeLDFAttr</a>(attr[3:0]);

            if (memattrs.inner.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a> &amp;&amp;
                    memattrs.outer.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>) then
                memattrs.xs = '0';
            else
                memattrs.xs = '1';
            end;
    end;

    memattrs.shareability = <a link="func_DecodeShareability_1" file="shared_pseudocode.xml">DecodeShareability</a>(sh);
    memattrs.tags = <a link="enum_MemTag_Untagged" file="shared_pseudocode.xml">MemTag_Untagged</a>;
    memattrs.notagaccess = FALSE;

    return memattrs;
end;

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

func <anchor link="func_S1DecodeMemAttrs_5">S1DecodeMemAttrs</anchor>(attr_in : bits(8), sh : bits(2), s1aarch64 : boolean,
                      walkparams : <a link="type_S1TTWParams" file="shared_pseudocode.xml">S1TTWParams</a>, acctype : <a link="type_AccessType" file="shared_pseudocode.xml">AccessType</a>) =&gt; <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>
begin
    var memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a> = <a link="func_S1DecodeMemAttrs_3" file="shared_pseudocode.xml">S1DecodeMemAttrs</a>(attr_in, sh, s1aarch64);
    if s1aarch64 &amp;&amp; attr_in == '11110000' then
        memattrs.tags = <a link="enum_MemTag_AllocationTagged" file="shared_pseudocode.xml">MemTag_AllocationTagged</a>;
    elsif IsFeatureImplemented(FEAT_MTE_CANONICAL_TAGS) &amp;&amp; s1aarch64 &amp;&amp; walkparams.mtx == '1' then
        memattrs.tags = <a link="enum_MemTag_CanonicallyTagged" file="shared_pseudocode.xml">MemTag_CanonicallyTagged</a>;
    end;

    return memattrs;
end;</pstext></ps>
    <ps name="shared/translation/attrs/S2CombineS1AttrHints" mylink="shared.translation.attrs.S2CombineS1AttrHints" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// S2CombineS1AttrHints()
// ======================
// Determine resultant Normal memory cacheability and allocation hints from
// combining stage 1 Normal memory attributes and stage 2 cacheability attributes.

func <anchor link="func_S2CombineS1AttrHints_2">S2CombineS1AttrHints</anchor>(s1_attrhints : <a link="type_MemAttrHints" file="shared_pseudocode.xml">MemAttrHints</a>, s2_attrhints : <a link="type_MemAttrHints" file="shared_pseudocode.xml">MemAttrHints</a>) =&gt; <a link="type_MemAttrHints" file="shared_pseudocode.xml">MemAttrHints</a>
begin
    var attrhints : <a link="type_MemAttrHints" file="shared_pseudocode.xml">MemAttrHints</a>;

    if s1_attrhints.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> || s2_attrhints.attrs == <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> then
        attrhints.attrs = <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>;
    elsif s1_attrhints.attrs == <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a> || s2_attrhints.attrs == <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a> then
        attrhints.attrs = <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a>;
    else
        attrhints.attrs = <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>;
    end;

    // Stage 2 does not assign any allocation hints
    // Instead, they are inherited from stage 1
    if attrhints.attrs != <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a> then
        attrhints.hints     = s1_attrhints.hints;
        attrhints.transient = s1_attrhints.transient;
    end;

    return attrhints;
end;</pstext></ps>
    <ps name="shared/translation/attrs/S2CombineS1Device" mylink="shared.translation.attrs.S2CombineS1Device" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// S2CombineS1Device()
// ===================
// Determine resultant Device type from combining output memory attributes
// in stage 1 and Device attributes in stage 2

func <anchor link="func_S2CombineS1Device_2">S2CombineS1Device</anchor>(s1_device : <a link="type_DeviceType" file="shared_pseudocode.xml">DeviceType</a>, s2_device : <a link="type_DeviceType" file="shared_pseudocode.xml">DeviceType</a>) =&gt; <a link="type_DeviceType" file="shared_pseudocode.xml">DeviceType</a>
begin
    if s1_device == <a link="enum_DeviceType_nGnRnE" file="shared_pseudocode.xml">DeviceType_nGnRnE</a> || s2_device == <a link="enum_DeviceType_nGnRnE" file="shared_pseudocode.xml">DeviceType_nGnRnE</a> then
        return <a link="enum_DeviceType_nGnRnE" file="shared_pseudocode.xml">DeviceType_nGnRnE</a>;
    elsif s1_device == <a link="enum_DeviceType_nGnRE" file="shared_pseudocode.xml">DeviceType_nGnRE</a> || s2_device == <a link="enum_DeviceType_nGnRE" file="shared_pseudocode.xml">DeviceType_nGnRE</a> then
        return <a link="enum_DeviceType_nGnRE" file="shared_pseudocode.xml">DeviceType_nGnRE</a>;
    elsif s1_device == <a link="enum_DeviceType_nGRE" file="shared_pseudocode.xml">DeviceType_nGRE</a> || s2_device == <a link="enum_DeviceType_nGRE" file="shared_pseudocode.xml">DeviceType_nGRE</a> then
        return <a link="enum_DeviceType_nGRE" file="shared_pseudocode.xml">DeviceType_nGRE</a>;
    else
        return <a link="enum_DeviceType_GRE" file="shared_pseudocode.xml">DeviceType_GRE</a>;
    end;
end;</pstext></ps>
    <ps name="shared/translation/attrs/S2CombineS1MemAttrs" mylink="shared.translation.attrs.S2CombineS1MemAttrs" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// S2CombineS1MemAttrs()
// =====================
// Combine stage 2 with stage 1 memory attributes

func <anchor link="func_S2CombineS1MemAttrs_3">S2CombineS1MemAttrs</anchor>(s1_memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>, s2_memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>,
                         s2aarch64 : boolean) =&gt; <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>
begin
    var memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>;

    if s1_memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> &amp;&amp; s2_memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> then
        memattrs.memtype = <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a>;
        memattrs.device  = <a link="func_S2CombineS1Device_2" file="shared_pseudocode.xml">S2CombineS1Device</a>(s1_memattrs.device, s2_memattrs.device);
    elsif s1_memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> then    // S2 Normal, S1 Device
        memattrs = s1_memattrs;
    elsif s2_memattrs.memtype == <a link="enum_MemType_Device" file="shared_pseudocode.xml">MemType_Device</a> then    // S2 Device, S1 Normal
        memattrs = s2_memattrs;
    else                                                // S2 Normal, S1 Normal
        memattrs.memtype = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
        memattrs.inner   = <a link="func_S2CombineS1AttrHints_2" file="shared_pseudocode.xml">S2CombineS1AttrHints</a>(s1_memattrs.inner, s2_memattrs.inner);
        memattrs.outer   = <a link="func_S2CombineS1AttrHints_2" file="shared_pseudocode.xml">S2CombineS1AttrHints</a>(s1_memattrs.outer, s2_memattrs.outer);
    end;

    memattrs.tags = <a link="func_S2MemTagType_2" file="shared_pseudocode.xml">S2MemTagType</a>(memattrs, s1_memattrs.tags);

    if !IsFeatureImplemented(FEAT_MTE_PERM) then
        memattrs.notagaccess = FALSE;
    else
        memattrs.notagaccess = (s2_memattrs.notagaccess &amp;&amp;
                                s1_memattrs.tags == <a link="enum_MemTag_AllocationTagged" file="shared_pseudocode.xml">MemTag_AllocationTagged</a>);
    end;
    memattrs.shareability = <a link="func_S2CombineS1Shareability_2" file="shared_pseudocode.xml">S2CombineS1Shareability</a>(s1_memattrs.shareability,
                                                    s2_memattrs.shareability);

    if (memattrs.memtype == <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a> &amp;&amp;
            memattrs.inner.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a> &amp;&amp;
            memattrs.outer.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>) then
        memattrs.xs = '0';
    elsif s2aarch64 then
        memattrs.xs = s2_memattrs.xs AND s1_memattrs.xs;
    else
        memattrs.xs = s1_memattrs.xs;
    end;

    memattrs.shareability = <a link="func_EffectiveShareability_1" file="shared_pseudocode.xml">EffectiveShareability</a>(memattrs);
    return memattrs;
end;</pstext></ps>
    <ps name="shared/translation/attrs/S2CombineS1Shareability" mylink="shared.translation.attrs.S2CombineS1Shareability" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// S2CombineS1Shareability()
// =========================
// Combine stage 2 shareability with stage 1

func <anchor link="func_S2CombineS1Shareability_2">S2CombineS1Shareability</anchor>(s1_shareability : <a link="type_Shareability" file="shared_pseudocode.xml">Shareability</a>,
                             s2_shareability : <a link="type_Shareability" file="shared_pseudocode.xml">Shareability</a>) =&gt; <a link="type_Shareability" file="shared_pseudocode.xml">Shareability</a>
begin

    if (s1_shareability == <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a> ||
            s2_shareability == <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>) then
        return <a link="enum_Shareability_OSH" file="shared_pseudocode.xml">Shareability_OSH</a>;
    elsif (s1_shareability == <a link="enum_Shareability_ISH" file="shared_pseudocode.xml">Shareability_ISH</a> ||
            s2_shareability == <a link="enum_Shareability_ISH" file="shared_pseudocode.xml">Shareability_ISH</a>) then
        return <a link="enum_Shareability_ISH" file="shared_pseudocode.xml">Shareability_ISH</a>;
    else
        return <a link="enum_Shareability_NSH" file="shared_pseudocode.xml">Shareability_NSH</a>;
    end;
end;</pstext></ps>
    <ps name="shared/translation/attrs/S2DecodeCacheability" mylink="shared.translation.attrs.S2DecodeCacheability" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// S2DecodeCacheability()
// ======================
// Determine the stage 2 cacheability for Normal memory

func <anchor link="func_S2DecodeCacheability_1">S2DecodeCacheability</anchor>(attr : bits(2)) =&gt; <a link="type_MemAttrHints" file="shared_pseudocode.xml">MemAttrHints</a>
begin
    var s2attr : <a link="type_MemAttrHints" file="shared_pseudocode.xml">MemAttrHints</a>;

    case attr of
        when '01' =&gt; s2attr.attrs = <a link="global_MemAttr_NC" file="shared_pseudocode.xml">MemAttr_NC</a>;  // Non-cacheable
        when '10' =&gt; s2attr.attrs = <a link="global_MemAttr_WT" file="shared_pseudocode.xml">MemAttr_WT</a>;  // Write-through
        when '11' =&gt; s2attr.attrs = <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>;  // Write-back
        otherwise =&gt; unreachable;
    end;

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

    return s2attr;
end;</pstext></ps>
    <ps name="shared/translation/attrs/S2DecodeMemAttrs" mylink="shared.translation.attrs.S2DecodeMemAttrs" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// S2DecodeMemAttrs()
// ==================
// Decode stage 2 memory attributes when FWB is 0

func <anchor link="func_S2DecodeMemAttrs_3">S2DecodeMemAttrs</anchor>(attr_in : bits(4), sh : bits(2), s2aarch64 : boolean) =&gt; <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>
begin
    var memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>;

    var attr : bits(4);
    if <a link="func_S2ResMemAttr_2" file="shared_pseudocode.xml">S2ResMemAttr</a>(s2aarch64, attr_in) then
        // Map reserved encodings to an allocated encoding
        (-, attr) = ConstrainUnpredictableBits{4}(<a link="enum_Unpredictable_S2RESMEMATTR" file="shared_pseudocode.xml">Unpredictable_S2RESMEMATTR</a>);
    else
        attr = attr_in;
    end;

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

    memattrs.shareability = <a link="func_DecodeShareability_1" file="shared_pseudocode.xml">DecodeShareability</a>(sh);

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

    return memattrs;
end;</pstext></ps>
    <ps name="shared/translation/attrs/S2MemTagType" mylink="shared.translation.attrs.S2MemTagType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// S2MemTagType()
// ==============
// Determine whether the combined output memory attributes of stage 1 and
// stage 2 indicate tagged memory

func <anchor link="func_S2MemTagType_2">S2MemTagType</anchor>(s2_memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>, s1_tagtype : <a link="type_MemTagType" file="shared_pseudocode.xml">MemTagType</a>) =&gt; <a link="type_MemTagType" file="shared_pseudocode.xml">MemTagType</a>
begin

    if !IsFeatureImplemented(FEAT_MTE2) then
        return <a link="enum_MemTag_Untagged" file="shared_pseudocode.xml">MemTag_Untagged</a>;
    end;

    if s1_tagtype == <a link="enum_MemTag_AllocationTagged" file="shared_pseudocode.xml">MemTag_AllocationTagged</a> &amp;&amp; <a link="func_IsTaggableMemAttr_1" file="shared_pseudocode.xml">IsTaggableMemAttr</a>(s2_memattrs) then
        return <a link="enum_MemTag_AllocationTagged" file="shared_pseudocode.xml">MemTag_AllocationTagged</a>;
    end;

    // Return what stage 1 asked for if we can, otherwise Untagged.
    if s1_tagtype != <a link="enum_MemTag_AllocationTagged" file="shared_pseudocode.xml">MemTag_AllocationTagged</a> then
        return s1_tagtype;
    end;

    return <a link="enum_MemTag_Untagged" file="shared_pseudocode.xml">MemTag_Untagged</a>;
end;</pstext></ps>
    <ps name="shared/translation/attrs/S2ResMemAttr" mylink="shared.translation.attrs.S2ResMemAttr" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// S2ResMemAttr()
// ==============
// Determine whether a reserved value occupies stage 2 MemAttr field when FWB is 0

func <anchor link="func_S2ResMemAttr_2">S2ResMemAttr</anchor>(s2aarch64 : boolean, attr : bits(4)) =&gt; boolean
begin
    case attr of
        when '0100' =&gt; return !(s2aarch64 &amp;&amp; IsFeatureImplemented(FEAT_MTE_PERM));
        when '1x00' =&gt; return TRUE;
        otherwise   =&gt; return FALSE;
    end;
end;</pstext></ps>
    <ps name="shared/translation/attrs/WalkMemAttrs" mylink="shared.translation.attrs.WalkMemAttrs" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// WalkMemAttrs()
// ==============
// Retrieve memory attributes of translation table walk

func <anchor link="func_WalkMemAttrs_3">WalkMemAttrs</anchor>(sh : bits(2), irgn : bits(2), orgn : bits(2)) =&gt; <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>
begin
    var walkmemattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>;

    walkmemattrs.memtype      = <a link="enum_MemType_Normal" file="shared_pseudocode.xml">MemType_Normal</a>;
    walkmemattrs.shareability = <a link="func_DecodeShareability_1" file="shared_pseudocode.xml">DecodeShareability</a>(sh);
    walkmemattrs.inner        = <a link="func_DecodeSDFAttr_1" file="shared_pseudocode.xml">DecodeSDFAttr</a>(irgn);
    walkmemattrs.outer        = <a link="func_DecodeSDFAttr_1" file="shared_pseudocode.xml">DecodeSDFAttr</a>(orgn);
    walkmemattrs.tags         = <a link="enum_MemTag_Untagged" file="shared_pseudocode.xml">MemTag_Untagged</a>;
    if (walkmemattrs.inner.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a> &amp;&amp;
            walkmemattrs.outer.attrs == <a link="global_MemAttr_WB" file="shared_pseudocode.xml">MemAttr_WB</a>) then
        walkmemattrs.xs = '0';
    else
        walkmemattrs.xs = '1';
    end;
    walkmemattrs.notagaccess = FALSE;

    return walkmemattrs;
end;</pstext></ps>
    <ps name="shared/translation/faults/AlignmentFault" mylink="shared.translation.faults.AlignmentFault" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AlignmentFault()
// ================
// Return a fault record indicating an Alignment fault not due to memory type has occurred
// for a specific access

func <anchor link="func_AlignmentFault_2">AlignmentFault</anchor>(accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>, vaddress : bits(64)) =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_2" file="shared_pseudocode.xml">NoFault</a>(accdesc, vaddress);
    fault.statuscode        = <a link="enum_Fault_Alignment" file="shared_pseudocode.xml">Fault_Alignment</a>;

    return fault;
end;</pstext></ps>
    <ps name="shared/translation/faults/ExclusiveFault" mylink="shared.translation.faults.ExclusiveFault" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ExclusiveFault()
// ================
// Return a fault record indicating a fault for an unsupported Exclusive access

func <anchor link="func_ExclusiveFault_2">ExclusiveFault</anchor>(accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>, vaddress : bits(64)) =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_2" file="shared_pseudocode.xml">NoFault</a>(accdesc, vaddress);
    fault.statuscode        = <a link="enum_Fault_Exclusive" file="shared_pseudocode.xml">Fault_Exclusive</a>;

    return fault;
end;</pstext></ps>
    <ps name="shared/translation/faults/NoFault" mylink="shared.translation.faults.NoFault" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// NoFault()
// =========
// Return a clear fault record indicating no faults have occurred

func <anchor link="func_NoFault_0">NoFault</anchor>() =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>;

    fault.vaddress = ARBITRARY : bits(64);
    fault.statuscode  = <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;
    fault.accessdesc  = ARBITRARY : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>;
    fault.secondstage = FALSE;
    fault.s2fs1walk   = FALSE;
    fault.dirtybit    = FALSE;
    fault.overlay     = FALSE;
    fault.toplevel    = FALSE;
    fault.assuredonly = FALSE;
    fault.s1tagnotdata = FALSE;
    fault.tagaccess    = FALSE;
    fault.gpcfs2walk   = FALSE;
    fault.gpcf         = <a link="func_GPCNoFault_0" file="shared_pseudocode.xml">GPCNoFault</a>();
    fault.hdbssf       = FALSE;

    return fault;
end;

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

func <anchor link="func_NoFault_1">NoFault</anchor>(accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>;

    fault.statuscode  = <a link="enum_Fault_None" file="shared_pseudocode.xml">Fault_None</a>;
    fault.accessdesc  = accdesc;
    fault.secondstage = FALSE;
    fault.s2fs1walk   = FALSE;
    fault.dirtybit    = FALSE;
    fault.overlay     = FALSE;
    fault.toplevel    = FALSE;
    fault.assuredonly = FALSE;
    fault.s1tagnotdata = FALSE;
    fault.tagaccess   = FALSE;
    fault.write       = !accdesc.read &amp;&amp; accdesc.write;
    fault.gpcfs2walk  = FALSE;
    fault.gpcf        = <a link="func_GPCNoFault_0" file="shared_pseudocode.xml">GPCNoFault</a>();
    fault.hdbssf      = FALSE;

    return fault;
end;

// NoFault()
// =========

func <anchor link="func_NoFault_2">NoFault</anchor>(accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>, vaddress : bits(64)) =&gt; <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>
begin
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = <a link="func_NoFault_0" file="shared_pseudocode.xml">NoFault</a>();
    fault.accessdesc  = accdesc;
    fault.write       = !accdesc.read &amp;&amp; accdesc.write;
    fault.vaddress    = vaddress;

    return fault;
end;</pstext></ps>
    <ps name="shared/translation/gpc/AbovePPS" mylink="shared.translation.gpc.AbovePPS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AbovePPS()
// ==========
// Returns TRUE if an address exceeds the range configured in GPCCR_EL3.PPS.

func <anchor link="func_AbovePPS_1">AbovePPS</anchor>(address : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>)) =&gt; boolean
begin
    let pps : integer{} = <a link="func_DecodePPS_0" file="shared_pseudocode.xml">DecodePPS</a>();
    if pps &gt;= <a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a> then
        return FALSE;
    end;

    return !IsZero(address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:pps]);
end;</pstext></ps>
    <ps name="shared/translation/gpc/DecodeGPTBlock" mylink="shared.translation.gpc.DecodeGPTBlock" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodeGPTBlock()
// ================
// Decode a GPT Block descriptor.

func <anchor link="func_DecodeGPTBlock_2">DecodeGPTBlock</anchor>(pgs : <a link="type_PGSe" file="shared_pseudocode.xml">PGSe</a>, gpt_entry : bits(64)) =&gt; <a link="type_GPTEntry" file="shared_pseudocode.xml">GPTEntry</a>
begin
    assert gpt_entry[3:0] == <a link="global_GPT_Block" file="shared_pseudocode.xml">GPT_Block</a>;
    var result : <a link="type_GPTEntry" file="shared_pseudocode.xml">GPTEntry</a>;
    result.gpi   = gpt_entry[7:4];
    result.level = 0;
    result.istable = FALSE;

    // GPT information from a level 0 GPT Block descriptor is permitted
    // to be cached in a TLB as though the Block is a contiguous region
    // of granules each of the size configured in GPCCR_EL3.PGS.
    case pgs of
        when <a link="enum_PGS_4KB" file="shared_pseudocode.xml">PGS_4KB</a> =&gt;  result.size = <a link="global_GPTRange_4KB" file="shared_pseudocode.xml">GPTRange_4KB</a>;
        when <a link="enum_PGS_16KB" file="shared_pseudocode.xml">PGS_16KB</a> =&gt; result.size = <a link="global_GPTRange_16KB" file="shared_pseudocode.xml">GPTRange_16KB</a>;
        when <a link="enum_PGS_64KB" file="shared_pseudocode.xml">PGS_64KB</a> =&gt; result.size = <a link="global_GPTRange_64KB" file="shared_pseudocode.xml">GPTRange_64KB</a>;
        otherwise =&gt; unreachable;
    end;
    result.contig_size = <a link="func_GPTL0Size_0" file="shared_pseudocode.xml">GPTL0Size</a>();

    return result;
end;</pstext></ps>
    <ps name="shared/translation/gpc/DecodeGPTContiguous" mylink="shared.translation.gpc.DecodeGPTContiguous" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodeGPTContiguous()
// =====================
// Decode a GPT Contiguous descriptor.

func <anchor link="func_DecodeGPTContiguous_2">DecodeGPTContiguous</anchor>(pgs : <a link="type_PGSe" file="shared_pseudocode.xml">PGSe</a>, gpt_entry : bits(64)) =&gt; <a link="type_GPTEntry" file="shared_pseudocode.xml">GPTEntry</a>
begin
    assert gpt_entry[3:0] == <a link="global_GPT_Contig" file="shared_pseudocode.xml">GPT_Contig</a>;
    var result : <a link="type_GPTEntry" file="shared_pseudocode.xml">GPTEntry</a>;
    result.gpi = gpt_entry[7:4];

    case pgs of
        when <a link="enum_PGS_4KB" file="shared_pseudocode.xml">PGS_4KB</a> =&gt;  result.size = <a link="global_GPTRange_4KB" file="shared_pseudocode.xml">GPTRange_4KB</a>;
        when <a link="enum_PGS_16KB" file="shared_pseudocode.xml">PGS_16KB</a> =&gt; result.size = <a link="global_GPTRange_16KB" file="shared_pseudocode.xml">GPTRange_16KB</a>;
        when <a link="enum_PGS_64KB" file="shared_pseudocode.xml">PGS_64KB</a> =&gt; result.size = <a link="global_GPTRange_64KB" file="shared_pseudocode.xml">GPTRange_64KB</a>;
        otherwise     =&gt; unreachable;
    end;

    case gpt_entry[9:8] of
        when '01' =&gt; result.contig_size = <a link="global_GPTRange_2MB" file="shared_pseudocode.xml">GPTRange_2MB</a>;
        when '10' =&gt; result.contig_size = <a link="global_GPTRange_32MB" file="shared_pseudocode.xml">GPTRange_32MB</a>;
        when '11' =&gt; result.contig_size = <a link="global_GPTRange_512MB" file="shared_pseudocode.xml">GPTRange_512MB</a>;
        otherwise =&gt; unreachable;
    end;

    result.level = 1;
    result.istable = FALSE;

    return result;
end;</pstext></ps>
    <ps name="shared/translation/gpc/DecodeGPTGranules" mylink="shared.translation.gpc.DecodeGPTGranules" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodeGPTGranules()
// ===================
// Decode a GPT Granules descriptor.

func <anchor link="func_DecodeGPTGranules_3">DecodeGPTGranules</anchor>(pgs : <a link="type_PGSe" file="shared_pseudocode.xml">PGSe</a>, index : integer, gpt_entry : bits(64)) =&gt; <a link="type_GPTEntry" file="shared_pseudocode.xml">GPTEntry</a>
begin
    var result : <a link="type_GPTEntry" file="shared_pseudocode.xml">GPTEntry</a>;
    result.gpi = gpt_entry[index*4 +:4];

    case pgs of
        when <a link="enum_PGS_4KB" file="shared_pseudocode.xml">PGS_4KB</a>  =&gt; result.size = <a link="global_GPTRange_4KB" file="shared_pseudocode.xml">GPTRange_4KB</a>;
        when <a link="enum_PGS_16KB" file="shared_pseudocode.xml">PGS_16KB</a> =&gt; result.size = <a link="global_GPTRange_16KB" file="shared_pseudocode.xml">GPTRange_16KB</a>;
        when <a link="enum_PGS_64KB" file="shared_pseudocode.xml">PGS_64KB</a> =&gt; result.size = <a link="global_GPTRange_64KB" file="shared_pseudocode.xml">GPTRange_64KB</a>;
        otherwise     =&gt; unreachable;
    end;

    result.contig_size = result.size; // No contiguity
    result.level = 1;
    result.istable = FALSE;

    return result;
end;</pstext></ps>
    <ps name="shared/translation/gpc/DecodeGPTTable" mylink="shared.translation.gpc.DecodeGPTTable" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodeGPTTable()
// ================
// Decode a GPT Table descriptor.

func <anchor link="func_DecodeGPTTable_2">DecodeGPTTable</anchor>(pgs : <a link="type_PGSe" file="shared_pseudocode.xml">PGSe</a>, gpt_entry : bits(64)) =&gt; <a link="type_GPTTable" file="shared_pseudocode.xml">GPTTable</a>
begin
    assert gpt_entry[3:0] == <a link="global_GPT_Table" file="shared_pseudocode.xml">GPT_Table</a>;
    var result : <a link="type_GPTTable" file="shared_pseudocode.xml">GPTTable</a>;

    // Descriptor bits [L0GPTSZ-PGS-2:12] are RES0
    var s : integer{30, 34, 36, 39};
    case <a link="func_GPTL0Size_0" file="shared_pseudocode.xml">GPTL0Size</a>() of
        when <a link="global_GPTRange_1GB" file="shared_pseudocode.xml">GPTRange_1GB</a>   =&gt; s = 30;
        when <a link="global_GPTRange_16GB" file="shared_pseudocode.xml">GPTRange_16GB</a>  =&gt; s = 34;
        when <a link="global_GPTRange_64GB" file="shared_pseudocode.xml">GPTRange_64GB</a>  =&gt; s = 36;
        when <a link="global_GPTRange_512GB" file="shared_pseudocode.xml">GPTRange_512GB</a> =&gt; s = 39;
        otherwise           =&gt; unreachable;
    end;

    var p : integer{12, 14, 16};
    case pgs of
        when <a link="enum_PGS_4KB" file="shared_pseudocode.xml">PGS_4KB</a>  =&gt; p = 12;
        when <a link="enum_PGS_16KB" file="shared_pseudocode.xml">PGS_16KB</a> =&gt; p = 14;
        when <a link="enum_PGS_64KB" file="shared_pseudocode.xml">PGS_64KB</a> =&gt; p = 16;
        otherwise     =&gt; unreachable;
    end;

    let align_bits :  integer{} = (s - p) - 1;
    result.address              = AlignDownP2(gpt_entry[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:0],align_bits);

    return result;
end;</pstext></ps>
    <ps name="shared/translation/gpc/DecodePGS" mylink="shared.translation.gpc.DecodePGS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodePGS()
// ===========

func <anchor link="func_DecodePGS_1">DecodePGS</anchor>(pgs : bits(2)) =&gt; <a link="type_PGSe" file="shared_pseudocode.xml">PGSe</a>
begin
    case pgs of
        when '00' =&gt; return <a link="enum_PGS_4KB" file="shared_pseudocode.xml">PGS_4KB</a>;
        when '10' =&gt; return <a link="enum_PGS_16KB" file="shared_pseudocode.xml">PGS_16KB</a>;
        when '01' =&gt; return <a link="enum_PGS_64KB" file="shared_pseudocode.xml">PGS_64KB</a>;
        otherwise =&gt; unreachable;
    end;
end;</pstext></ps>
    <ps name="shared/translation/gpc/DecodePGSRange" mylink="shared.translation.gpc.DecodePGSRange" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodePGSRange()
// ================

func <anchor link="func_DecodePGSRange_1">DecodePGSRange</anchor>(pgs : <a link="type_PGSe" file="shared_pseudocode.xml">PGSe</a>) =&gt; <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>
begin
    case pgs of
        when <a link="enum_PGS_4KB" file="shared_pseudocode.xml">PGS_4KB</a> =&gt;  return <a link="global_GPTRange_4KB" file="shared_pseudocode.xml">GPTRange_4KB</a>;
        when <a link="enum_PGS_16KB" file="shared_pseudocode.xml">PGS_16KB</a> =&gt; return <a link="global_GPTRange_16KB" file="shared_pseudocode.xml">GPTRange_16KB</a>;
        when <a link="enum_PGS_64KB" file="shared_pseudocode.xml">PGS_64KB</a> =&gt; return <a link="global_GPTRange_64KB" file="shared_pseudocode.xml">GPTRange_64KB</a>;
        otherwise =&gt; unreachable;
    end;
end;</pstext></ps>
    <ps name="shared/translation/gpc/DecodePPS" mylink="shared.translation.gpc.DecodePPS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodePPS()
// ===========
// Size of region protected by the GPT, in bits.

func <anchor link="func_DecodePPS_0">DecodePPS</anchor>() =&gt; <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>
begin
    case GPCCR_EL3().[PPS3, PPS] of
        when '0000' =&gt; return 32;
        when '0001' =&gt; return 36;
        when '0010' =&gt; return 40;
        when '0011' =&gt; return 42;
        when '0100' =&gt; return 44;
        when '0101' =&gt; return 48;
        when '0110' =&gt; return 52;
        when '0111' =&gt; assert IsFeatureImplemented(FEAT_RME_GPC3); return 56;
        when '1000' =&gt; assert IsFeatureImplemented(FEAT_RME_GPC3); return 46;
        when '1001' =&gt; assert IsFeatureImplemented(FEAT_RME_GPC3); return 47;
        otherwise =&gt; unreachable;
    end;
end;</pstext></ps>
    <ps name="shared/translation/gpc/GPCBW_EL3BWSTRIDEValid" mylink="shared.translation.gpc.GPCBW_EL3BWSTRIDEValid" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPCBW_EL3BWSTRIDEValid()
// ========================
// Returns whether the current GPCBW_EL3.BWSTRIDE value is valid

func <anchor link="func_GPCBW_EL3BWSTRIDEValid_0">GPCBW_EL3BWSTRIDEValid</anchor>() =&gt; boolean
begin
    assert IsFeatureImplemented(FEAT_RME_GPC3);
    return GPCBW_EL3().BWSTRIDE IN {
        '00000',
        '00010',
        '00100',
        '00110',
        '00111',
        '01000',
        '01001',
        '01010',
        '10000'
    };
end;</pstext></ps>
    <ps name="shared/translation/gpc/GPCFault" mylink="shared.translation.gpc.GPCFault" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPCFault()
// ==========
// Constructs and returns a GPCF

func <anchor link="func_GPCFault_2">GPCFault</anchor>(gpf : <a link="type_GPCF" file="shared_pseudocode.xml">GPCF</a>, level : integer) =&gt; <a link="type_GPCFRecord" file="shared_pseudocode.xml">GPCFRecord</a>
begin
    var fault : <a link="type_GPCFRecord" file="shared_pseudocode.xml">GPCFRecord</a>;
    fault.gpf   = gpf;
    fault.level = level;
    return fault;
end;</pstext></ps>
    <ps name="shared/translation/gpc/GPCNoFault" mylink="shared.translation.gpc.GPCNoFault" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPCNoFault()
// ============
// Returns the default properties of a GPCF that does not represent a fault

func <anchor link="func_GPCNoFault_0">GPCNoFault</anchor>() =&gt; <a link="type_GPCFRecord" file="shared_pseudocode.xml">GPCFRecord</a>
begin
    var result : <a link="type_GPCFRecord" file="shared_pseudocode.xml">GPCFRecord</a>;
    result.gpf = <a link="enum_GPCF_None" file="shared_pseudocode.xml">GPCF_None</a>;
    return result;
end;</pstext></ps>
    <ps name="shared/translation/gpc/GPCRegistersConsistent" mylink="shared.translation.gpc.GPCRegistersConsistent" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPCRegistersConsistent()
// ========================
// Returns whether the GPT registers are configured correctly.
// This returns false if any fields select a Reserved value.

func <anchor link="func_GPCRegistersConsistent_0">GPCRegistersConsistent</anchor>() =&gt; boolean
begin
    // Check for Reserved register values
    if IsFeatureImplemented(FEAT_RME_GPC3) then
        if  ! GPCCR_EL3().[PPS3, PPS] IN {'0xxx', '100x'} then
            return FALSE;
        end;

        if GPCCR_EL3().GPCBW == '1' then
            if ! GPCBW_EL3().BWSIZE IN {'00x', '1x0', '010'} then
                return FALSE;
            end;

            if !<a link="func_GPCBW_EL3BWSTRIDEValid_0" file="shared_pseudocode.xml">GPCBW_EL3BWSTRIDEValid</a>() then
                return FALSE;
            end;

            let bwstride : integer = 1 &lt;&lt; (40 + UInt(GPCBW_EL3().BWSTRIDE));
            let bwaddr : integer = UInt(GPCBW_EL3().BWADDR) &lt;&lt; 30;
            if bwstride &lt;= bwaddr then
                return FALSE;
            end;

            if !IsAlignedSize{26}(GPCBW_EL3().BWADDR, 1 &lt;&lt; UInt(GPCBW_EL3().BWSIZE)) then
                return FALSE;
            end;
        end;
    else
        if GPCCR_EL3().PPS == '111' then
            return FALSE;
        end;
    end;

    if <a link="func_DecodePPS_0" file="shared_pseudocode.xml">DecodePPS</a>() &gt; <a link="func_AArch64_PAMax_0" file="shared_pseudocode.xml">AArch64_PAMax</a>() then
        return FALSE;
    end;
    if GPCCR_EL3().PGS == '11' then
        return FALSE;
    end;
    if GPCCR_EL3().SH == '01' then
        return FALSE;
    end;

    // Inner and Outer Non-cacheable requires Outer Shareable
    if GPCCR_EL3().[ORGN, IRGN] == '0000' &amp;&amp; GPCCR_EL3().SH != '10' then
        return FALSE;
    end;

    return TRUE;
end;</pstext></ps>
    <ps name="shared/translation/gpc/GPICheck" mylink="shared.translation.gpc.GPICheck" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPICheck()
// ==========
// Returns whether an access to a given physical address space is permitted
// given the configured GPI value.
// paspace: Physical address space of the access
// gpi: Value read from GPT for the access
// ss: Security state of the access

func <anchor link="func_GPICheck_3">GPICheck</anchor>(paspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>, gpi : bits(4), ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>) =&gt; boolean
begin
    case gpi of
        when <a link="global_GPT_NoAccess" file="shared_pseudocode.xml">GPT_NoAccess</a> =&gt;
            return FALSE;
        when <a link="global_GPT_Secure" file="shared_pseudocode.xml">GPT_Secure</a> =&gt;
            assert IsFeatureImplemented(FEAT_SEL2);
            return paspace == <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>;
        when <a link="global_GPT_NonSecure" file="shared_pseudocode.xml">GPT_NonSecure</a> =&gt;
            return paspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
        when <a link="global_GPT_Root" file="shared_pseudocode.xml">GPT_Root</a> =&gt;
            return paspace == <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>;
        when <a link="global_GPT_Realm" file="shared_pseudocode.xml">GPT_Realm</a> =&gt;
            return paspace == <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>;
        when <a link="global_GPT_NonSecureOnly" file="shared_pseudocode.xml">GPT_NonSecureOnly</a> =&gt;
            assert IsFeatureImplemented(FEAT_RME_GPC2);
            return paspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> &amp;&amp; (ss IN {<a link="enum_SS_Root" file="shared_pseudocode.xml">SS_Root</a>, <a link="enum_SS_NonSecure" file="shared_pseudocode.xml">SS_NonSecure</a>});
        when <a link="global_GPT_SystemAgent" file="shared_pseudocode.xml">GPT_SystemAgent</a> =&gt;
            assert IsFeatureImplemented(FEAT_RME_GDI);
            return paspace == <a link="enum_PAS_SystemAgent" file="shared_pseudocode.xml">PAS_SystemAgent</a>;
        when <a link="global_GPT_NonSecureProtected" file="shared_pseudocode.xml">GPT_NonSecureProtected</a> =&gt;
            assert IsFeatureImplemented(FEAT_RME_GDI);
            return paspace == <a link="enum_PAS_NonSecureProtected" file="shared_pseudocode.xml">PAS_NonSecureProtected</a>;
        when <a link="global_GPT_NA6" file="shared_pseudocode.xml">GPT_NA6</a> =&gt;
            assert IsFeatureImplemented(FEAT_RME_GDI);
            return FALSE;
        when <a link="global_GPT_NA7" file="shared_pseudocode.xml">GPT_NA7</a> =&gt;
            assert IsFeatureImplemented(FEAT_RME_GDI);
            return FALSE;
        when <a link="global_GPT_Any" file="shared_pseudocode.xml">GPT_Any</a> =&gt;
            return TRUE;
        otherwise =&gt;
            unreachable;
    end;
end;</pstext></ps>
    <ps name="shared/translation/gpc/GPIIndex" mylink="shared.translation.gpc.GPIIndex" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPIIndex()
// ==========

func <anchor link="func_GPIIndex_1">GPIIndex</anchor>(pa : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>)) =&gt; integer
begin
    case <a link="func_DecodePGS_1" file="shared_pseudocode.xml">DecodePGS</a>(GPCCR_EL3().PGS) of
        when <a link="enum_PGS_4KB" file="shared_pseudocode.xml">PGS_4KB</a> =&gt;  return UInt(pa[15:12]);
        when <a link="enum_PGS_16KB" file="shared_pseudocode.xml">PGS_16KB</a> =&gt; return UInt(pa[17:14]);
        when <a link="enum_PGS_64KB" file="shared_pseudocode.xml">PGS_64KB</a> =&gt; return UInt(pa[19:16]);
        otherwise =&gt; unreachable;
    end;
end;</pstext></ps>
    <ps name="shared/translation/gpc/GPIValid" mylink="shared.translation.gpc.GPIValid" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPIValid()
// ==========
// Returns whether a given value is a valid encoding for a GPI value

func <anchor link="func_GPIValid_1">GPIValid</anchor>(gpi : bits(4)) =&gt; boolean
begin
    case gpi of
        when <a link="global_GPT_NoAccess" file="shared_pseudocode.xml">GPT_NoAccess</a> =&gt;
            return TRUE;
        when <a link="global_GPT_NonSecureProtected" file="shared_pseudocode.xml">GPT_NonSecureProtected</a> =&gt;
            return IsFeatureImplemented(FEAT_RME_GDI) &amp;&amp; GPCCR_EL3().NSP == '1';
        when <a link="global_GPT_SystemAgent" file="shared_pseudocode.xml">GPT_SystemAgent</a> =&gt;
            return IsFeatureImplemented(FEAT_RME_GDI) &amp;&amp; GPCCR_EL3().SA  == '1';
        when <a link="global_GPT_NA6" file="shared_pseudocode.xml">GPT_NA6</a> =&gt;
            return IsFeatureImplemented(FEAT_RME_GDI) &amp;&amp; GPCCR_EL3().NA6 == '1';
        when <a link="global_GPT_NA7" file="shared_pseudocode.xml">GPT_NA7</a> =&gt;
            return IsFeatureImplemented(FEAT_RME_GDI) &amp;&amp; GPCCR_EL3().NA7 == '1';
        when <a link="global_GPT_Secure" file="shared_pseudocode.xml">GPT_Secure</a> =&gt;
            return IsFeatureImplemented(FEAT_SEL2);
        when <a link="global_GPT_NonSecure" file="shared_pseudocode.xml">GPT_NonSecure</a> =&gt;
            return TRUE;
        when <a link="global_GPT_Realm" file="shared_pseudocode.xml">GPT_Realm</a> =&gt;
            return TRUE;
        when <a link="global_GPT_Root" file="shared_pseudocode.xml">GPT_Root</a> =&gt;
            return TRUE;
        when <a link="global_GPT_NonSecureOnly" file="shared_pseudocode.xml">GPT_NonSecureOnly</a> =&gt;
            return IsFeatureImplemented(FEAT_RME_GPC2) &amp;&amp; GPCCR_EL3().NSO == '1';
        when <a link="global_GPT_Any" file="shared_pseudocode.xml">GPT_Any</a> =&gt;
            return TRUE;
        otherwise =&gt;
            return FALSE;
    end;
end;</pstext></ps>
    <ps name="shared/translation/gpc/GPT" mylink="shared.translation.gpc.GPT" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPT dimensions
// ==============

constant <anchor link="global_GPTRange_4KB">GPTRange_4KB</anchor> : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>   = 12;
constant <anchor link="global_GPTRange_16KB">GPTRange_16KB</anchor> : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>  = 14;
constant <anchor link="global_GPTRange_64KB">GPTRange_64KB</anchor> : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>  = 16;
constant <anchor link="global_GPTRange_2MB">GPTRange_2MB</anchor> : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>   = 21;
constant <anchor link="global_GPTRange_32MB">GPTRange_32MB</anchor> : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>  = 25;
constant <anchor link="global_GPTRange_512MB">GPTRange_512MB</anchor> : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = 29;
constant <anchor link="global_GPTRange_1GB">GPTRange_1GB</anchor> : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>   = 30;
constant <anchor link="global_GPTRange_16GB">GPTRange_16GB</anchor> : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>  = 34;
constant <anchor link="global_GPTRange_64GB">GPTRange_64GB</anchor> : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>  = 36;
constant <anchor link="global_GPTRange_512GB">GPTRange_512GB</anchor> : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = 39;</pstext></ps>
    <ps name="shared/translation/gpc/GPTBlockDescriptorValid" mylink="shared.translation.gpc.GPTBlockDescriptorValid" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPTBlockDescriptorValid()
// =========================
// Returns TRUE if the given GPT Block descriptor is valid, and FALSE otherwise.

func <anchor link="func_GPTBlockDescriptorValid_1">GPTBlockDescriptorValid</anchor>(level_0_entry : bits(64)) =&gt; boolean
begin
    assert level_0_entry[3:0] == <a link="global_GPT_Block" file="shared_pseudocode.xml">GPT_Block</a>;
    return IsZero(level_0_entry[63:8]) &amp;&amp; <a link="func_GPIValid_1" file="shared_pseudocode.xml">GPIValid</a>(level_0_entry[7:4]);
end;</pstext></ps>
    <ps name="shared/translation/gpc/GPTContigDescriptorValid" mylink="shared.translation.gpc.GPTContigDescriptorValid" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPTContigDescriptorValid()
// ==========================
// Returns TRUE if the given GPT Contiguous descriptor is valid, and FALSE otherwise.

func <anchor link="func_GPTContigDescriptorValid_1">GPTContigDescriptorValid</anchor>(level_1_entry : bits(64)) =&gt; boolean
begin
    assert level_1_entry[3:0] == <a link="global_GPT_Contig" file="shared_pseudocode.xml">GPT_Contig</a>;
    return (IsZero(level_1_entry[63:10]) &amp;&amp;
            !IsZero(level_1_entry[9:8])  &amp;&amp;
            <a link="func_GPIValid_1" file="shared_pseudocode.xml">GPIValid</a>(level_1_entry[7:4]));
end;</pstext></ps>
    <ps name="shared/translation/gpc/GPTEntry" mylink="shared.translation.gpc.GPTEntry" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPTEntry
// ========

type <anchor link="type_GPTEntry">GPTEntry</anchor> of record {
    gpi         : bits(4),         // GPI value for this region
    size        : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>,     // Region size
    contig_size : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>,     // Contiguous region size
    istable     : boolean,         // Flag a table entry
    level       : integer,         // Level of GPT lookup
    pa          : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>) // PA uniquely identifying the GPT entry
};</pstext></ps>
    <ps name="shared/translation/gpc/GPTGranulesDescriptorValid" mylink="shared.translation.gpc.GPTGranulesDescriptorValid" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPTGranulesDescriptorValid()
// ============================
// Returns TRUE if the given GPT Granules descriptor is valid, and FALSE otherwise.

func <anchor link="func_GPTGranulesDescriptorValid_1">GPTGranulesDescriptorValid</anchor>(level_1_entry : bits(64)) =&gt; boolean
begin
    for i = 0 to 15 do
        if !<a link="func_GPIValid_1" file="shared_pseudocode.xml">GPIValid</a>(level_1_entry[i*4 +:4]) then
            return FALSE;
        end;
    end;
    return TRUE;
end;</pstext></ps>
    <ps name="shared/translation/gpc/GPTL0Size" mylink="shared.translation.gpc.GPTL0Size" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPTL0Size()
// ===========
// Returns number of bits covered by a level 0 GPT entry

func <anchor link="func_GPTL0Size_0">GPTL0Size</anchor>() =&gt; <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>
begin
    case GPCCR_EL3().L0GPTSZ of
        when '0000' =&gt; return <a link="global_GPTRange_1GB" file="shared_pseudocode.xml">GPTRange_1GB</a>;
        when '0100' =&gt; return <a link="global_GPTRange_16GB" file="shared_pseudocode.xml">GPTRange_16GB</a>;
        when '0110' =&gt; return <a link="global_GPTRange_64GB" file="shared_pseudocode.xml">GPTRange_64GB</a>;
        when '1001' =&gt; return <a link="global_GPTRange_512GB" file="shared_pseudocode.xml">GPTRange_512GB</a>;
        otherwise   =&gt; unreachable;
    end;
    return 30;
end;</pstext></ps>
    <ps name="shared/translation/gpc/GPTLevel0EntryValid" mylink="shared.translation.gpc.GPTLevel0EntryValid" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPTLevel0EntryValid()
// =====================
// Returns TRUE if the given level 0 gpt descriptor is valid, and FALSE otherwise.

func <anchor link="func_GPTLevel0EntryValid_1">GPTLevel0EntryValid</anchor>(gpt_entry : bits(64)) =&gt; boolean
begin
    case gpt_entry[3:0] of
        when <a link="global_GPT_Block" file="shared_pseudocode.xml">GPT_Block</a> =&gt; return <a link="func_GPTBlockDescriptorValid_1" file="shared_pseudocode.xml">GPTBlockDescriptorValid</a>(gpt_entry);
        when <a link="global_GPT_Table" file="shared_pseudocode.xml">GPT_Table</a> =&gt; return <a link="func_GPTTableDescriptorValid_1" file="shared_pseudocode.xml">GPTTableDescriptorValid</a>(gpt_entry);
        otherwise =&gt;      return FALSE;
    end;
end;</pstext></ps>
    <ps name="shared/translation/gpc/GPTLevel0Index" mylink="shared.translation.gpc.GPTLevel0Index" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPTLevel0Index()
// ================
// Compute the level 0 index based on input PA.

func <anchor link="func_GPTLevel0Index_1">GPTLevel0Index</anchor>(pa : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>)) =&gt; integer
begin
    // Input address and index bounds
    let pps : integer{} = <a link="func_DecodePPS_0" file="shared_pseudocode.xml">DecodePPS</a>();
    let l0sz : integer{} = <a link="func_GPTL0Size_0" file="shared_pseudocode.xml">GPTL0Size</a>();
    if pps &lt;= l0sz then
        return 0;
    end;

    return UInt(pa[pps-1:l0sz]);
end;</pstext></ps>
    <ps name="shared/translation/gpc/GPTLevel1EntryValid" mylink="shared.translation.gpc.GPTLevel1EntryValid" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPTLevel1EntryValid()
// =====================
// Returns TRUE if the given level 1 gpt descriptor is valid, and FALSE otherwise.

func <anchor link="func_GPTLevel1EntryValid_1">GPTLevel1EntryValid</anchor>(gpt_entry : bits(64)) =&gt; boolean
begin
    case gpt_entry[3:0] of
        when <a link="global_GPT_Contig" file="shared_pseudocode.xml">GPT_Contig</a> =&gt; return <a link="func_GPTContigDescriptorValid_1" file="shared_pseudocode.xml">GPTContigDescriptorValid</a>(gpt_entry);
        otherwise =&gt;       return <a link="func_GPTGranulesDescriptorValid_1" file="shared_pseudocode.xml">GPTGranulesDescriptorValid</a>(gpt_entry);
    end;
end;</pstext></ps>
    <ps name="shared/translation/gpc/GPTLevel1Index" mylink="shared.translation.gpc.GPTLevel1Index" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPTLevel1Index()
// ================
// Compute the level 1 index based on input PA.

func <anchor link="func_GPTLevel1Index_1">GPTLevel1Index</anchor>(pa : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>)) =&gt; integer
begin
    // Input address and index bounds
    let l0sz : integer{} = <a link="func_GPTL0Size_0" file="shared_pseudocode.xml">GPTL0Size</a>();
    case <a link="func_DecodePGS_1" file="shared_pseudocode.xml">DecodePGS</a>(GPCCR_EL3().PGS) of
        when <a link="enum_PGS_4KB" file="shared_pseudocode.xml">PGS_4KB</a> =&gt;  return UInt(pa[l0sz-1:16]);
        when <a link="enum_PGS_16KB" file="shared_pseudocode.xml">PGS_16KB</a> =&gt; return UInt(pa[l0sz-1:18]);
        when <a link="enum_PGS_64KB" file="shared_pseudocode.xml">PGS_64KB</a> =&gt; return UInt(pa[l0sz-1:20]);
        otherwise =&gt; unreachable;
    end;
end;</pstext></ps>
    <ps name="shared/translation/gpc/GPTTable" mylink="shared.translation.gpc.GPTTable" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPTTable
// ========

type <anchor link="type_GPTTable">GPTTable</anchor> of record {
    address : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>)   // Base address of next table
};</pstext></ps>
    <ps name="shared/translation/gpc/GPTTableDescriptorValid" mylink="shared.translation.gpc.GPTTableDescriptorValid" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPTTableDescriptorValid()
// =========================
// Returns TRUE if the given GPT Table descriptor is valid, and FALSE otherwise.

func <anchor link="func_GPTTableDescriptorValid_1">GPTTableDescriptorValid</anchor>(level_0_entry : bits(64)) =&gt; boolean
begin
    assert level_0_entry[3:0] == <a link="global_GPT_Table" file="shared_pseudocode.xml">GPT_Table</a>;
    let l0sz : integer{} = <a link="func_GPTL0Size_0" file="shared_pseudocode.xml">GPTL0Size</a>();
    let pgs : <a link="type_PGSe" file="shared_pseudocode.xml">PGSe</a>       = <a link="func_DecodePGS_1" file="shared_pseudocode.xml">DecodePGS</a>(GPCCR_EL3().PGS);
    let p : integer{}    = <a link="func_DecodePGSRange_1" file="shared_pseudocode.xml">DecodePGSRange</a>(pgs);
    let top : integer{}  = if <a link="func_DecodePPS_0" file="shared_pseudocode.xml">DecodePPS</a>() == 56 then 56 else 52;
    return IsZero(level_0_entry[63:top,11:4]) &amp;&amp; IsZero(level_0_entry[(l0sz-p)-2:12]);
end;</pstext></ps>
    <ps name="shared/translation/gpc/GPTWalk" mylink="shared.translation.gpc.GPTWalk" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GPTWalk()
// =========
// Get the GPT entry for a given physical address, pa

func <anchor link="func_GPTWalk_2">GPTWalk</anchor>(pa : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>), accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; (<a link="type_GPCFRecord" file="shared_pseudocode.xml">GPCFRecord</a>, <a link="type_GPTEntry" file="shared_pseudocode.xml">GPTEntry</a>)
begin
    // GPT base address
    var base : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>);
    let pgs : <a link="type_PGSe" file="shared_pseudocode.xml">PGSe</a> = <a link="func_DecodePGS_1" file="shared_pseudocode.xml">DecodePGS</a>(GPCCR_EL3().PGS);

    // The level 0 GPT base address is aligned to the greater of:
    // * the size of the level 0 GPT, determined by GPCCR_EL3().[PPS, L0GPTSZ].
    // * 4KB
    base = ZeroExtend{<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>}(GPTBR_EL3().BADDR::Zeros{12});
    let pps : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_DecodePPS_0" file="shared_pseudocode.xml">DecodePPS</a>();
    let l0sz : integer{} = <a link="func_GPTL0Size_0" file="shared_pseudocode.xml">GPTL0Size</a>();
    let alignment : integer{} = Max((pps - l0sz) + 3, 12) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
    base[alignment-1:0] = Zeros{alignment};

    let gptaccdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a> = <a link="func_CreateAccDescGPTW_1" file="shared_pseudocode.xml">CreateAccDescGPTW</a>(accdesc);

    // Access attributes and address for GPT fetches
    var gptaddrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;
    gptaddrdesc.memattrs = <a link="func_WalkMemAttrs_3" file="shared_pseudocode.xml">WalkMemAttrs</a>(GPCCR_EL3().SH, GPCCR_EL3().IRGN, GPCCR_EL3().ORGN);
    gptaddrdesc.fault    = <a link="func_NoFault_1" file="shared_pseudocode.xml">NoFault</a>(gptaccdesc);

    gptaddrdesc.paddress.paspace = <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>;
    gptaddrdesc.paddress.address = base + <a link="func_GPTLevel0Index_1" file="shared_pseudocode.xml">GPTLevel0Index</a>(pa) * 8;

    // Fetch L0GPT entry
    var level_0_entry : bits(64);
    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
    (memstatus, level_0_entry) = <a link="func_PhysMemRead_3" file="shared_pseudocode.xml">PhysMemRead</a>{64}(gptaddrdesc, gptaccdesc);
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
        return (<a link="func_GPCFault_2" file="shared_pseudocode.xml">GPCFault</a>(<a link="enum_GPCF_EABT" file="shared_pseudocode.xml">GPCF_EABT</a>, 0), ARBITRARY : <a link="type_GPTEntry" file="shared_pseudocode.xml">GPTEntry</a>);
    end;

    if !<a link="func_GPTLevel0EntryValid_1" file="shared_pseudocode.xml">GPTLevel0EntryValid</a>(level_0_entry) then
        return (<a link="func_GPCFault_2" file="shared_pseudocode.xml">GPCFault</a>(<a link="enum_GPCF_Walk" file="shared_pseudocode.xml">GPCF_Walk</a>, 0), ARBITRARY : <a link="type_GPTEntry" file="shared_pseudocode.xml">GPTEntry</a>);
    end;

    var result : <a link="type_GPTEntry" file="shared_pseudocode.xml">GPTEntry</a>;
    var table : <a link="type_GPTTable" file="shared_pseudocode.xml">GPTTable</a>;
    case level_0_entry[3:0] of
        when <a link="global_GPT_Block" file="shared_pseudocode.xml">GPT_Block</a> =&gt;
            // Decode the GPI value and return that
            result = <a link="func_DecodeGPTBlock_2" file="shared_pseudocode.xml">DecodeGPTBlock</a>(pgs, level_0_entry);
            result.pa = pa;
            return (<a link="func_GPCNoFault_0" file="shared_pseudocode.xml">GPCNoFault</a>(), result);
        when <a link="global_GPT_Table" file="shared_pseudocode.xml">GPT_Table</a> =&gt;
            // Decode the table entry and continue walking
            table = <a link="func_DecodeGPTTable_2" file="shared_pseudocode.xml">DecodeGPTTable</a>(pgs, level_0_entry);
            // The address must be within the range covered by the GPT
            if <a link="func_AbovePPS_1" file="shared_pseudocode.xml">AbovePPS</a>(table.address) then
                return (<a link="func_GPCFault_2" file="shared_pseudocode.xml">GPCFault</a>(<a link="enum_GPCF_AddressSize" file="shared_pseudocode.xml">GPCF_AddressSize</a>, 0), ARBITRARY : <a link="type_GPTEntry" file="shared_pseudocode.xml">GPTEntry</a>);
            end;
        otherwise =&gt;
            // An invalid encoding would be caught by GPTLevel0EntryValid()
            unreachable;
    end;

    // Must be a GPT Table entry
    assert level_0_entry[3:0] == <a link="global_GPT_Table" file="shared_pseudocode.xml">GPT_Table</a>;

    // Address of level 1 GPT entry
    let offset : integer = <a link="func_GPTLevel1Index_1" file="shared_pseudocode.xml">GPTLevel1Index</a>(pa) * 8;

    var level_1_entry : bits(64);

    if IsFeatureImplemented(FEAT_RME_GDI) then
        // When FEAT_RME_GDI is implemented, the descriptor validation checks are performed
        // on a pair of descriptors within a naturally aligned 16-byte region of memory.
        gptaddrdesc.paddress.address = AlignDownSize{56}(table.address + offset, 16);
        var level_1_entry_lower : bits(64);
        (memstatus, level_1_entry_lower) = <a link="func_PhysMemRead_3" file="shared_pseudocode.xml">PhysMemRead</a>{64}(gptaddrdesc, gptaccdesc);
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            return (<a link="func_GPCFault_2" file="shared_pseudocode.xml">GPCFault</a>(<a link="enum_GPCF_EABT" file="shared_pseudocode.xml">GPCF_EABT</a>, 1), ARBITRARY : <a link="type_GPTEntry" file="shared_pseudocode.xml">GPTEntry</a>);
        end;

        gptaddrdesc.paddress.address = gptaddrdesc.paddress.address + 8;
        var level_1_entry_upper : bits(64);
        (memstatus, level_1_entry_upper) = <a link="func_PhysMemRead_3" file="shared_pseudocode.xml">PhysMemRead</a>{64}(gptaddrdesc, gptaccdesc);
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            return (<a link="func_GPCFault_2" file="shared_pseudocode.xml">GPCFault</a>(<a link="enum_GPCF_EABT" file="shared_pseudocode.xml">GPCF_EABT</a>, 1), ARBITRARY : <a link="type_GPTEntry" file="shared_pseudocode.xml">GPTEntry</a>);
        end;

        // An individual GPT descriptor is valid when both descriptors within the pair are valid.
        if (!<a link="func_GPTLevel1EntryValid_1" file="shared_pseudocode.xml">GPTLevel1EntryValid</a>(level_1_entry_upper) ||
              !<a link="func_GPTLevel1EntryValid_1" file="shared_pseudocode.xml">GPTLevel1EntryValid</a>(level_1_entry_lower)) then
            return (<a link="func_GPCFault_2" file="shared_pseudocode.xml">GPCFault</a>(<a link="enum_GPCF_Walk" file="shared_pseudocode.xml">GPCF_Walk</a>, 1), ARBITRARY : <a link="type_GPTEntry" file="shared_pseudocode.xml">GPTEntry</a>);
        end;

        if offset[3] == '1' then
            level_1_entry = level_1_entry_upper;
        else
            level_1_entry = level_1_entry_lower;
        end;
    else
        gptaddrdesc.paddress.address = table.address + offset;
        // Fetch L1GPT entry
        (memstatus, level_1_entry) = <a link="func_PhysMemRead_3" file="shared_pseudocode.xml">PhysMemRead</a>{64}(gptaddrdesc, gptaccdesc);
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
            return (<a link="func_GPCFault_2" file="shared_pseudocode.xml">GPCFault</a>(<a link="enum_GPCF_EABT" file="shared_pseudocode.xml">GPCF_EABT</a>, 1), ARBITRARY : <a link="type_GPTEntry" file="shared_pseudocode.xml">GPTEntry</a>);
        end;

        if !<a link="func_GPTLevel1EntryValid_1" file="shared_pseudocode.xml">GPTLevel1EntryValid</a>(level_1_entry) then
            return (<a link="func_GPCFault_2" file="shared_pseudocode.xml">GPCFault</a>(<a link="enum_GPCF_Walk" file="shared_pseudocode.xml">GPCF_Walk</a>, 1), ARBITRARY : <a link="type_GPTEntry" file="shared_pseudocode.xml">GPTEntry</a>);
        end;
    end;

    case level_1_entry[3:0] of
        when <a link="global_GPT_Contig" file="shared_pseudocode.xml">GPT_Contig</a> =&gt;
            result = <a link="func_DecodeGPTContiguous_2" file="shared_pseudocode.xml">DecodeGPTContiguous</a>(pgs, level_1_entry);
        otherwise =&gt;
            let gpi_index : integer = <a link="func_GPIIndex_1" file="shared_pseudocode.xml">GPIIndex</a>(pa);
            result = <a link="func_DecodeGPTGranules_3" file="shared_pseudocode.xml">DecodeGPTGranules</a>(pgs, gpi_index, level_1_entry);
    end;

    result.pa = pa;
    return (<a link="func_GPCNoFault_0" file="shared_pseudocode.xml">GPCNoFault</a>(), result);
end;</pstext></ps>
    <ps name="shared/translation/gpc/GranuleProtectionCheck" mylink="shared.translation.gpc.GranuleProtectionCheck" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// GranuleProtectionCheck()
// ========================
// Returns whether a given access is permitted, according to the
// granule protection check.
// addrdesc and accdesc describe the access to be checked.

func <anchor link="func_GranuleProtectionCheck_2">GranuleProtectionCheck</anchor>(addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>, accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_GPCFRecord" file="shared_pseudocode.xml">GPCFRecord</a>
begin

    assert IsFeatureImplemented(FEAT_RME);
    // The address to be checked
    let address = addrdesc.paddress;

    // Bypass mode - all accesses pass
    if GPCCR_EL3().GPC == '0' then
        return <a link="func_GPCNoFault_0" file="shared_pseudocode.xml">GPCNoFault</a>();
    end;

    // Configuration consistency check
    if !<a link="func_GPCRegistersConsistent_0" file="shared_pseudocode.xml">GPCRegistersConsistent</a>() then
        return <a link="func_GPCFault_2" file="shared_pseudocode.xml">GPCFault</a>(<a link="enum_GPCF_Walk" file="shared_pseudocode.xml">GPCF_Walk</a>, 0);
    end;

    if IsFeatureImplemented(FEAT_RME_GPC2) then
        var access_disabled : boolean;

        case address.paspace of
            when <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a> =&gt;    access_disabled = GPCCR_EL3().SPAD  == '1';
            when <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> =&gt; access_disabled = GPCCR_EL3().NSPAD == '1';
            when <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a> =&gt;     access_disabled = GPCCR_EL3().RLPAD == '1';
            when <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a> =&gt;      access_disabled = FALSE;
            otherwise =&gt;          unreachable;
        end;

        if access_disabled then
            return <a link="func_GPCFault_2" file="shared_pseudocode.xml">GPCFault</a>(<a link="enum_GPCF_Fail" file="shared_pseudocode.xml">GPCF_Fail</a>, 0);
        end;
    end;

    // Input address size check
    if <a link="func_AbovePPS_1" file="shared_pseudocode.xml">AbovePPS</a>(address.address) then
        if (address.paspace == <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a> ||
              (IsFeatureImplemented(FEAT_RME_GPC2) &amp;&amp; GPCCR_EL3().APPSAA == '1')) then
            return <a link="func_GPCNoFault_0" file="shared_pseudocode.xml">GPCNoFault</a>();
        else
            return <a link="func_GPCFault_2" file="shared_pseudocode.xml">GPCFault</a>(<a link="enum_GPCF_Fail" file="shared_pseudocode.xml">GPCF_Fail</a>, 0);
        end;
    end;

    if (IsFeatureImplemented(FEAT_RME_GPC3) &amp;&amp; GPCCR_EL3().GPCBW == '1' &amp;&amp;
          <a link="func_PAWithinGPCBypassWindow_1" file="shared_pseudocode.xml">PAWithinGPCBypassWindow</a>(address.address)) then
        return <a link="func_GPCNoFault_0" file="shared_pseudocode.xml">GPCNoFault</a>();
    end;

    // GPT base address size check
    let gpt_base : bits(<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>) = ZeroExtend{}(GPTBR_EL3().BADDR::Zeros{12});
    if <a link="func_AbovePPS_1" file="shared_pseudocode.xml">AbovePPS</a>(gpt_base) then
        return <a link="func_GPCFault_2" file="shared_pseudocode.xml">GPCFault</a>(<a link="enum_GPCF_AddressSize" file="shared_pseudocode.xml">GPCF_AddressSize</a>, 0);
    end;

    // GPT lookup
    var (gpcf, gpt_entry) = <a link="func_GPTWalk_2" file="shared_pseudocode.xml">GPTWalk</a>(address.address, accdesc);
    if gpcf.gpf != <a link="enum_GPCF_None" file="shared_pseudocode.xml">GPCF_None</a> then
        return gpcf;
    end;

    // Check input physical address space against GPI
    let permitted : boolean = <a link="func_GPICheck_3" file="shared_pseudocode.xml">GPICheck</a>(address.paspace, gpt_entry.gpi, accdesc.ss);

    if !permitted then
        gpcf = <a link="func_GPCFault_2" file="shared_pseudocode.xml">GPCFault</a>(<a link="enum_GPCF_Fail" file="shared_pseudocode.xml">GPCF_Fail</a>, gpt_entry.level);
        return gpcf;
    end;

    // Check passed

    return <a link="func_GPCNoFault_0" file="shared_pseudocode.xml">GPCNoFault</a>();
end;</pstext></ps>
    <ps name="shared/translation/gpc/IsGranuleProtectionCheckedAccess" mylink="shared.translation.gpc.IsGranuleProtectionCheckedAccess" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// IsGranuleProtectionCheckedAccess()
// ==================================
// Check if the access should be subject to Granule protection check returns
// true if it is, false otherwise

func <anchor link="func_IsGranuleProtectionCheckedAccess_1">IsGranuleProtectionCheckedAccess</anchor>(accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; boolean
begin
    if accdesc.acctype == <a link="enum_AccessType_DC" file="shared_pseudocode.xml">AccessType_DC</a> then
        return ImpDefBool(&quot;GPC Fault on DC operations&quot;);
    end;

    return TRUE;
end;</pstext></ps>
    <ps name="shared/translation/gpc/PAWithinGPCBypassWindow" mylink="shared.translation.gpc.PAWithinGPCBypassWindow" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PAWithinGPCBypassWindow()
// =========================
// Check if the supplied address is within a GPC Bypass window.

func <anchor link="func_PAWithinGPCBypassWindow_1">PAWithinGPCBypassWindow</anchor>(pa_in : bits(56)) =&gt; boolean
begin
    // Only check the top 26 bits as the minimum window size is 1GB
    let pa : bits(26) = pa_in[55:30];

    let gpcbwl : integer{} = UInt(GPCBW_EL3().BWSIZE);
    let gpcbwu : integer{} = 9 + UInt(GPCBW_EL3().BWSTRIDE);

    return pa[gpcbwu:gpcbwl] == GPCBW_EL3().BWADDR[gpcbwu:gpcbwl];
end;</pstext></ps>
    <ps name="shared/translation/gpc/PGS" mylink="shared.translation.gpc.PGS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// PGS
// ===
// Physical granule size

type <anchor link="type_PGSe">PGSe</anchor> of enumeration {
    <anchor link="enum_PGS_4KB">PGS_4KB</anchor>,
    <anchor link="enum_PGS_16KB">PGS_16KB</anchor>,
    <anchor link="enum_PGS_64KB">PGS_64KB</anchor>
};</pstext></ps>
    <ps name="shared/translation/gpc/Table" mylink="shared.translation.gpc.Table" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Table format information
// ========================
// Granule Protection Table constants

constant <anchor link="global_GPT_NoAccess">GPT_NoAccess</anchor> : bits(4)      = '0000';
constant <anchor link="global_GPT_Table">GPT_Table</anchor> : bits(4)         = '0011';
constant <anchor link="global_GPT_Block">GPT_Block</anchor> : bits(4)         = '0001';
constant <anchor link="global_GPT_Contig">GPT_Contig</anchor> : bits(4)        = '0001';
constant <anchor link="global_GPT_SystemAgent">GPT_SystemAgent</anchor> : bits(4)   = '0100';
constant <anchor link="global_GPT_NonSecureProtected">GPT_NonSecureProtected</anchor> : bits(4) = '0101';
constant <anchor link="global_GPT_NA6">GPT_NA6</anchor> : bits(4)           = '0110';
constant <anchor link="global_GPT_NA7">GPT_NA7</anchor> : bits(4)           = '0111';
constant <anchor link="global_GPT_Secure">GPT_Secure</anchor> : bits(4)        = '1000';
constant <anchor link="global_GPT_NonSecure">GPT_NonSecure</anchor> : bits(4)     = '1001';
constant <anchor link="global_GPT_Root">GPT_Root</anchor> : bits(4)          = '1010';
constant <anchor link="global_GPT_Realm">GPT_Realm</anchor> : bits(4)         = '1011';
constant <anchor link="global_GPT_NonSecureOnly">GPT_NonSecureOnly</anchor> : bits(4) = '1101';
constant <anchor link="global_GPT_Any">GPT_Any</anchor> : bits(4)           = '1111';</pstext></ps>
    <ps name="shared/translation/translation/S1TranslationRegime" mylink="shared.translation.translation.S1TranslationRegime" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// S1TranslationRegime()
// =====================
// Stage 1 translation regime for the given Exception level

readonly func <anchor link="func_S1TranslationRegime_1">S1TranslationRegime</anchor>(el : bits(2)) =&gt; bits(2)
begin
    if el != <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        return el;

    elsif <a link="func_HaveEL_1" file="shared_pseudocode.xml">HaveEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) &amp;&amp; SCR().NS == '0' then
        return <a link="global_EL3" file="shared_pseudocode.xml">EL3</a>;
    elsif IsFeatureImplemented(FEAT_VHE) &amp;&amp; <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(el) then
        return <a link="global_EL2" file="shared_pseudocode.xml">EL2</a>;
    else
        return <a link="global_EL1" file="shared_pseudocode.xml">EL1</a>;
    end;
end;

// S1TranslationRegime()
// =====================
// Returns the Exception level controlling the current Stage 1 translation regime. For the most
// part this is unused in code because the System register accessors (SCTLR_ELx, etc.) implicitly
// return the correct value.

readonly func <anchor link="func_S1TranslationRegime_0">S1TranslationRegime</anchor>() =&gt; bits(2)
begin
    return <a link="func_S1TranslationRegime_1" file="shared_pseudocode.xml">S1TranslationRegime</a>(<a link="global_PSTATE" file="shared_pseudocode.xml">PSTATE</a>.EL);
end;</pstext></ps>
    <ps name="shared/translation/vmsa/AddressDescriptor" mylink="shared.translation.vmsa.AddressDescriptor" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// AddressDescriptor
// =================
// Descriptor used to access the underlying memory array.

type <anchor link="type_AddressDescriptor">AddressDescriptor</anchor> of record {
    fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>,      // fault.statuscode indicates whether the address is valid
    memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>,
    paddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>,
    s1assured : boolean,      // Stage 1 Assured Translation Property
    s2fs1mro : boolean,       // Stage 2 MRO permission for Stage 1
    mecid : bits(16),         // FEAT_MEC: Memory Encryption Context ID
    vaddress : bits(64)
};

constant <anchor link="global_FINAL_LEVEL">FINAL_LEVEL</anchor> : integer = 3;</pstext></ps>
    <ps name="shared/translation/vmsa/ContiguousSize" mylink="shared.translation.vmsa.ContiguousSize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// ContiguousSize()
// ================
// Return the number of entries log 2 marking a contiguous output range

func <anchor link="func_ContiguousSize_3">ContiguousSize</anchor>(d128 : bit, tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>, level : integer) =&gt; integer
begin
    if d128 == '1' then
        case tgx of
            when <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a> =&gt;
                assert level IN {1, 2, 3};
                return if level == 1 then 2 else 4;
            when <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a> =&gt;
                assert level IN {1, 2, 3};
                if level == 1 then
                    return 2;
                elsif level == 2 then
                    return 4;
                else
                    return 6;
                end;
            when <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> =&gt;
                assert level IN {2, 3};
                return if level == 2 then 6 else 4;
        end;
    else
        case tgx of
            when <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a> =&gt;
                assert level IN {1, 2, 3};
                return 4;
            when <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a> =&gt;
                assert level IN {2, 3};
                return if level == 2 then 5 else 7;
            when <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> =&gt;
                assert level IN {2, 3};
                return 5;
        end;
    end;
end;</pstext></ps>
    <ps name="shared/translation/vmsa/CreateAddressDescriptor" mylink="shared.translation.vmsa.CreateAddressDescriptor" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateAddressDescriptor()
// =========================
// Set internal members for address descriptor type to valid values

func <anchor link="func_CreateAddressDescriptor_3">CreateAddressDescriptor</anchor>(pa : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>, memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>,
                             accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>
begin
    var addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;

    addrdesc.paddress = pa;
    addrdesc.memattrs = memattrs;
    addrdesc.fault    = <a link="func_NoFault_1" file="shared_pseudocode.xml">NoFault</a>(accdesc);

    return addrdesc;
end;

// CreateAddressDescriptor()
// =========================
// Set internal members for address descriptor type to valid values

func <anchor link="func_CreateAddressDescriptor_4">CreateAddressDescriptor</anchor>(va : bits(64), pa : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>,
                             memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>,
                             accdesc : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>) =&gt; <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>
begin
    var addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;

    addrdesc.paddress  = pa;
    addrdesc.vaddress  = va;
    addrdesc.memattrs  = memattrs;
    addrdesc.fault     = <a link="func_NoFault_1" file="shared_pseudocode.xml">NoFault</a>(accdesc);
    addrdesc.s1assured = FALSE;

    return addrdesc;
end;</pstext></ps>
    <ps name="shared/translation/vmsa/CreateFaultyAddressDescriptor" mylink="shared.translation.vmsa.CreateFaultyAddressDescriptor" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// CreateFaultyAddressDescriptor()
// ===============================
// Set internal members for address descriptor type with values indicating error

func <anchor link="func_CreateFaultyAddressDescriptor_1">CreateFaultyAddressDescriptor</anchor>(fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>
begin
    var addrdesc : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>;

    addrdesc.vaddress = fault.vaddress;
    addrdesc.fault    = fault;

    return addrdesc;
end;</pstext></ps>
    <ps name="shared/translation/vmsa/DecodePASpace" mylink="shared.translation.vmsa.DecodePASpace" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DecodePASpace()
// ===============
// Decode the target PA Space

func <anchor link="func_DecodePASpace_3">DecodePASpace</anchor>(nse2 : bit, nse : bit, ns : bit) =&gt; <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>
begin
    case nse2::nse::ns of
        when '000' =&gt;   return <a link="enum_PAS_Secure" file="shared_pseudocode.xml">PAS_Secure</a>;
        when '001' =&gt;   return <a link="enum_PAS_NonSecure" file="shared_pseudocode.xml">PAS_NonSecure</a>;
        when '010' =&gt;   return <a link="enum_PAS_Root" file="shared_pseudocode.xml">PAS_Root</a>;
        when '011' =&gt;   return <a link="enum_PAS_Realm" file="shared_pseudocode.xml">PAS_Realm</a>;
        when '100' =&gt;   return <a link="enum_PAS_SystemAgent" file="shared_pseudocode.xml">PAS_SystemAgent</a>;
        when '101' =&gt;   return <a link="enum_PAS_NonSecureProtected" file="shared_pseudocode.xml">PAS_NonSecureProtected</a>;
        when '110' =&gt;   return <a link="enum_PAS_NA6" file="shared_pseudocode.xml">PAS_NA6</a>;
        when '111' =&gt;   return <a link="enum_PAS_NA7" file="shared_pseudocode.xml">PAS_NA7</a>;
        otherwise =&gt;    unreachable;
    end;
end;</pstext></ps>
    <ps name="shared/translation/vmsa/DescriptorType" mylink="shared.translation.vmsa.DescriptorType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// DescriptorType
// ==============
// Translation table descriptor formats

type <anchor link="type_DescriptorType">DescriptorType</anchor> of enumeration {
    <anchor link="enum_DescriptorType_Table">DescriptorType_Table</anchor>,
    <anchor link="enum_DescriptorType_Leaf">DescriptorType_Leaf</anchor>,
    <anchor link="enum_DescriptorType_Invalid">DescriptorType_Invalid</anchor>
};</pstext></ps>
    <ps name="shared/translation/vmsa/Domains" mylink="shared.translation.vmsa.Domains" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Domains
// =======
// Short-descriptor format Domains

constant <anchor link="global_Domain_NoAccess">Domain_NoAccess</anchor> : bits(2) = '00';
constant <anchor link="global_Domain_Client">Domain_Client</anchor>   : bits(2) = '01';
constant <anchor link="global_Domain_Manager">Domain_Manager</anchor>  : bits(2) = '11';</pstext></ps>
    <ps name="shared/translation/vmsa/FetchDescriptor" mylink="shared.translation.vmsa.FetchDescriptor" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// FetchDescriptor()
// =================
// Fetch a translation table descriptor

func <anchor link="func_FetchDescriptor_5">FetchDescriptor</anchor>{N : integer{32, 64, 128}}(ee : bit, walkaddress : <a link="type_AddressDescriptor" file="shared_pseudocode.xml">AddressDescriptor</a>,
                                               walkaccess : <a link="type_AccessDescriptor" file="shared_pseudocode.xml">AccessDescriptor</a>,
                                               fault_in : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>) =&gt; (<a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a>, bits(N))
begin
    var descriptor : bits(N);
    var fault : <a link="type_FaultRecord" file="shared_pseudocode.xml">FaultRecord</a> = fault_in;

    if IsFeatureImplemented(FEAT_RME) then
        fault.gpcf = <a link="func_GranuleProtectionCheck_2" file="shared_pseudocode.xml">GranuleProtectionCheck</a>(walkaddress, walkaccess);
        if fault.gpcf.gpf != <a link="enum_GPCF_None" file="shared_pseudocode.xml">GPCF_None</a> then
            fault.statuscode = <a link="enum_Fault_GPCFOnWalk" file="shared_pseudocode.xml">Fault_GPCFOnWalk</a>;
            fault.paddress   = walkaddress.paddress;
            fault.gpcfs2walk = fault.secondstage;
            return (fault, ARBITRARY : bits(N));
        end;
    end;

    var memstatus : <a link="type_PhysMemRetStatus" file="shared_pseudocode.xml">PhysMemRetStatus</a>;
    (memstatus, descriptor) = <a link="func_PhysMemRead_3" file="shared_pseudocode.xml">PhysMemRead</a>{N}(walkaddress, walkaccess);
    if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(memstatus) then
        let iswrite : boolean = FALSE;
        fault = <a link="func_HandleExternalTTWAbort_6" file="shared_pseudocode.xml">HandleExternalTTWAbort</a>(memstatus, iswrite, walkaddress,
                                       walkaccess, N DIV 8, fault);
        if <a link="func_IsFault_1" file="shared_pseudocode.xml">IsFault</a>(fault.statuscode) then
            return (fault, ARBITRARY : bits(N));
        end;
    end;

    if ee == '1' then
        descriptor = <a link="func_BigEndianReverse_2" file="shared_pseudocode.xml">BigEndianReverse</a>{N}(descriptor);
    end;

    return (fault, descriptor);
end;</pstext></ps>
    <ps name="shared/translation/vmsa/HasUnprivileged" mylink="shared.translation.vmsa.HasUnprivileged" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// HasUnprivileged()
// =================
// Returns whether a translation regime serves EL0 as well as a higher EL

readonly func <anchor link="func_HasUnprivileged_1">HasUnprivileged</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>) =&gt; boolean
begin
    return (regime IN {
        <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>,
        <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a>,
        <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a>
    });
end;</pstext></ps>
    <ps name="shared/translation/vmsa/NUM_PABITS" mylink="shared.translation.vmsa.NUM_PABITS" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// NUM_PABITS
// ==========

constant <anchor link="global_NUM_PABITS">NUM_PABITS</anchor> : integer{} = 56;</pstext></ps>
    <ps name="shared/translation/vmsa/Regime" mylink="shared.translation.vmsa.Regime" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// Regime
// ======
// Translation regimes

type <anchor link="type_Regime">Regime</anchor> of enumeration {
    <anchor link="enum_Regime_EL3">Regime_EL3</anchor>,            // EL3
    <anchor link="enum_Regime_EL30">Regime_EL30</anchor>,           // EL3&amp;0 (PL1&amp;0 when EL3 is AArch32)
    <anchor link="enum_Regime_EL2">Regime_EL2</anchor>,            // EL2
    <anchor link="enum_Regime_EL20">Regime_EL20</anchor>,           // EL2&amp;0
    <anchor link="enum_Regime_EL10">Regime_EL10</anchor>            // EL1&amp;0
};</pstext></ps>
    <ps name="shared/translation/vmsa/RegimeUsingAArch32" mylink="shared.translation.vmsa.RegimeUsingAArch32" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// RegimeUsingAArch32()
// ====================
// Determine if the EL controlling the regime executes in AArch32 state

func <anchor link="func_RegimeUsingAArch32_1">RegimeUsingAArch32</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>) =&gt; boolean
begin
    case regime of
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt; return <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>);
        when <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a> =&gt; return TRUE;
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt; return FALSE;
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a>  =&gt; return <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
        when <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a>  =&gt; return FALSE;
    end;
end;</pstext></ps>
    <ps name="shared/translation/vmsa/S1TTWParams" mylink="shared.translation.vmsa.S1TTWParams" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// S1TTWParams
// ===========
// Register fields corresponding to stage 1 translation
// For A32-VMSA, if noted, they correspond to A32-LPAE (Long descriptor format)

type <anchor link="type_S1TTWParams">S1TTWParams</anchor> of record {
// A64-VMSA exclusive parameters
    ha : bit,         // TCR_ELx.HA
    hd : bit,         // TCR_ELx.HD
    tbi : bit,        // TCR_ELx.TBI{x}
    tbid : bit,       // TCR_ELx.TBID{x}
    nfd : bit,        // TCR_EL1.NFDx or TCR_EL2.NFDx when HCR_EL2.E2H == '1'
    e0pd : bit,       // TCR_EL1.E0PDx or TCR_EL2.E0PDx when HCR_EL2.E2H == '1'
    d128 : bit,       // TCR_ELx.D128
    aie : bit,        // (TCR2_ELx/TCR_EL3).AIE
    mair2 : MAIRType, // MAIR2_ELx
    ds : bit,         // TCR_ELx.DS
    ps : bits(3),     // TCR_ELx.{I}PS
    txsz : bits(6),   // TCR_ELx.TxSZ
    epan : bit,       // SCTLR_EL1.EPAN or SCTLR_EL2.EPAN when HCR_EL2.E2H == '1'
    dct : bit,        // HCR_EL2.DCT
    nv1 : bit,        // HCR_EL2.NV1
    cmow : bit,       // SCTLR_EL1.CMOW or SCTLR_EL2.CMOW when HCR_EL2.E2H == '1'
    pnch : bit,       // TCR{2}_ELx.PnCH
    disch : bit,      // TCR{2}_ELx.DisCH
    haft : bit,       // TCR{2}_ELx.HAFT
    mtx : bit,        // TCR_ELx.MTX{y}
    skl : bits(2),    // TTBRn_ELx.SKL
    pie : bit,        // TCR2_ELx.PIE or TCR_EL3.PIE
    pir : S1PIRType,  // PIR_ELx
    pire0 : S1PIRType,// PIRE0_EL1 or PIRE0_EL2 when HCR_EL2.E2H == '1'
    emec : bit,       // SCTLR2_EL2.EMEC or SCTLR2_EL3.EMEC
    amec : bit,       // TCR2_EL2.AMEC0 or TCR2_EL2.AMEC1 when HCR_EL2.E2H == '1'
    fng : bit,        // TCR2_EL1.FNGx or TCR2_EL2.FNGx when HCR_EL2.E2H == '1'
    fngna : bit,      // TCR2_EL1.FNGx

// A32-VMSA exclusive parameters
    t0sz : bits(3),   // TTBCR.T0SZ
    t1sz : bits(3),   // TTBCR.T1SZ
    uwxn : bit,       // SCTLR.UWXN

// Parameters common to both A64-VMSA &amp; A32-VMSA (A64/A32)
    tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>,        // TCR_ELx.TGx      / Always TGx_4KB
    irgn : bits(2),   // TCR_ELx.IRGNx    / TTBCR.IRGNx or HTCR.IRGN0
    orgn : bits(2),   // TCR_ELx.ORGNx    / TTBCR.ORGNx or HTCR.ORGN0
    sh : bits(2),     // TCR_ELx.SHx      / TTBCR.SHx or HTCR.SH0
    hpd : bit,        // TCR_ELx.HPD{x}   / TTBCR2.HPDx or HTCR.HPD
    ee : bit,         // SCTLR_ELx.EE     / SCTLR.EE or HSCTLR.EE
    wxn : bit,        // SCTLR_ELx.WXN    / SCTLR.WXN or HSCTLR.WXN
    ntlsmd : bit,     // SCTLR_ELx.nTLSMD / SCTLR.nTLSMD or HSCTLR.nTLSMD
    dc : bit,         // HCR_EL2.DC       / HCR.DC
    sif : bit,        // SCR_EL3.SIF      / SCR.SIF
    mair : MAIRType   // MAIR_ELx         / MAIR1:MAIR0 or HMAIR1:HMAIR0
};</pstext></ps>
    <ps name="shared/translation/vmsa/S2TTWParams" mylink="shared.translation.vmsa.S2TTWParams" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// S2TTWParams
// ===========
// Register fields corresponding to stage 2 translation.

type <anchor link="type_S2TTWParams">S2TTWParams</anchor> of record {
// A64-VMSA exclusive parameters
    ha : bit,           // VTCR_EL2.HA
    hd : bit,           // VTCR_EL2.HD
    sl2 : bit,          // V{S}TCR_EL2.SL2
    ds : bit,           // VTCR_EL2.DS
    d128 : bit,         // VTCR_ELx.D128
    sw : bit,           // VSTCR_EL2.SW
    nsw : bit,          // VTCR_EL2.NSW
    sa : bit,           // VSTCR_EL2.SA
    nsa : bit,          // VTCR_EL2.NSA
    ps : bits(3),       // VTCR_EL2.PS
    txsz : bits(6),     // V{S}TCR_EL2.T0SZ
    fwb : bit,          // HCR_EL2.FWB
    cmow : bit,         // HCRX_EL2.CMOW
    skl : bits(2),      // VTTBR_EL2.SKL
    s2pie : bit,        // VTCR_EL2.S2PIE
    s2pir : S2PIRType,  // S2PIR_EL2
    tl0 : bit,          // VTCR_EL2.TL0
    tl1 : bit,          // VTCR_EL2.TL1
    assuredonly : bit,  // VTCR_EL2.AssuredOnly
    haft : bit,         // VTCR_EL2.HAFT
    emec : bit,         // SCTLR2_EL2.EMEC
    hdbss : bit,        // VTCR_EL2.HDBSS

// A32-VMSA exclusive parameters
    s : bit,            // VTCR.S
    t0sz : bits(4),     // VTCR.T0SZ

// Parameters common to both A64-VMSA &amp; A32-VMSA if implemented (A64/A32)
    tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>,          // V{S}TCR_EL2.TG0  / Always TGx_4KB
    sl0 : bits(2),      // V{S}TCR_EL2.SL0  / VTCR.SL0
    irgn : bits(2),     // VTCR_EL2.IRGN0   / VTCR.IRGN0
    orgn : bits(2),     // VTCR_EL2.ORGN0   / VTCR.ORGN0
    sh : bits(2),       // VTCR_EL2.SH0     / VTCR.SH0
    ee : bit,           // SCTLR_EL2.EE     / HSCTLR.EE
    ptw : bit,          // HCR_EL2.PTW      / HCR.PTW
    vm : bit            // HCR_EL2.VM       / HCR.VM
};</pstext></ps>
    <ps name="shared/translation/vmsa/SDFType" mylink="shared.translation.vmsa.SDFType" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SDFType
// =======
// Short-descriptor format type

type <anchor link="type_SDFType">SDFType</anchor> of enumeration {
    <anchor link="enum_SDFType_Table">SDFType_Table</anchor>,
    <anchor link="enum_SDFType_Invalid">SDFType_Invalid</anchor>,
    <anchor link="enum_SDFType_Supersection">SDFType_Supersection</anchor>,
    <anchor link="enum_SDFType_Section">SDFType_Section</anchor>,
    <anchor link="enum_SDFType_LargePage">SDFType_LargePage</anchor>,
    <anchor link="enum_SDFType_SmallPage">SDFType_SmallPage</anchor>
};</pstext></ps>
    <ps name="shared/translation/vmsa/SecurityStateForRegime" mylink="shared.translation.vmsa.SecurityStateForRegime" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// SecurityStateForRegime()
// ========================
// Return the Security State of the given translation regime

func <anchor link="func_SecurityStateForRegime_1">SecurityStateForRegime</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>) =&gt; <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>
begin
    case regime of
        when <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a> =&gt;     return <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>);
        when <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a> =&gt;    return <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a>; // A32 EL3 is always Secure
        when <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a> =&gt;     return <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
        when <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> =&gt;    return <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>);
        when <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> =&gt;    return <a link="func_SecurityStateAtEL_1" file="shared_pseudocode.xml">SecurityStateAtEL</a>(<a link="global_EL1" file="shared_pseudocode.xml">EL1</a>);
    end;
end;</pstext></ps>
    <ps name="shared/translation/vmsa/StageOA" mylink="shared.translation.vmsa.StageOA" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// StageOA()
// =========
// Given the final walk state (a page or block descriptor), map the untranslated
// input address bits to the output address

func <anchor link="func_StageOA_4">StageOA</anchor>(ia : bits(64), d128 : bit, tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>, walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>) =&gt; <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>

begin
    // Output Address
    var oa : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>;
    let tsize : integer = <a link="func_TranslationSize_3" file="shared_pseudocode.xml">TranslationSize</a>(d128, tgx, walkstate.level);
    let csize : integer = (if walkstate.contiguous == '1' then
                           <a link="func_ContiguousSize_3" file="shared_pseudocode.xml">ContiguousSize</a>(d128, tgx, walkstate.level)
                           else 0);
    let ia_msb : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = (tsize + csize) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
    oa.paspace = walkstate.baseaddress.paspace;
    oa.address = walkstate.baseaddress.address[<a link="global_NUM_PABITS" file="shared_pseudocode.xml">NUM_PABITS</a>-1:ia_msb]::ia[ia_msb-1:0];

    return oa;
end;</pstext></ps>
    <ps name="shared/translation/vmsa/TGx" mylink="shared.translation.vmsa.TGx" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TGx
// ===
// Translation granules sizes

type <anchor link="type_TGx">TGx</anchor> of enumeration {
    <anchor link="enum_TGx_4KB">TGx_4KB</anchor>,
    <anchor link="enum_TGx_16KB">TGx_16KB</anchor>,
    <anchor link="enum_TGx_64KB">TGx_64KB</anchor>
};</pstext></ps>
    <ps name="shared/translation/vmsa/TGxGranuleBits" mylink="shared.translation.vmsa.TGxGranuleBits" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TGxGranuleBits()
// ================
// Retrieve the address size, in bits, of a granule

func <anchor link="func_TGxGranuleBits_1">TGxGranuleBits</anchor>(tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>) =&gt; <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>
begin
    case tgx of
        when <a link="enum_TGx_4KB" file="shared_pseudocode.xml">TGx_4KB</a> =&gt;  return 12;
        when <a link="enum_TGx_16KB" file="shared_pseudocode.xml">TGx_16KB</a> =&gt; return 14;
        when <a link="enum_TGx_64KB" file="shared_pseudocode.xml">TGx_64KB</a> =&gt; return 16;
    end;
end;</pstext></ps>
    <ps name="shared/translation/vmsa/TLBContext" mylink="shared.translation.vmsa.TLBContext" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TLBContext
// ==========
// Translation context compared on TLB lookups and invalidations, promoting a TLB hit on match

type <anchor link="type_TLBContext">TLBContext</anchor> of record {
    ss : <a link="type_SecurityState" file="shared_pseudocode.xml">SecurityState</a>,
    regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>,
    vmid : bits(NUM_VMIDBITS),
    asid : bits(NUM_ASIDBITS),
    nG : bit,
    ipaspace : <a link="type_PASpace" file="shared_pseudocode.xml">PASpace</a>,    // Used in stage 2 lookups &amp; invalidations only
    includes_s1 : boolean,
    includes_s2 : boolean,
    use_vmid : boolean,
    includes_gpt : boolean,
    ia : bits(64),         // Input Address
    tg : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>,
    cnp : bit,
    level : integer,       // Assist TLBI level hints (FEAT_TTL)
    isd128 : boolean,
    xs : bit               // XS attribute (FEAT_XS)
};</pstext></ps>
    <ps name="shared/translation/vmsa/TLBRecord" mylink="shared.translation.vmsa.TLBRecord" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TLBRecord
// =========
// Translation output as a TLB payload

type <anchor link="type_TLBRecord">TLBRecord</anchor> of record {
    context : <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>,
    walkstate : <a link="type_TTWState" file="shared_pseudocode.xml">TTWState</a>,
    blocksize : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>,  // Number of bits directly mapped from IA to OA
    contigsize : integer,     // Number of entries log 2 marking a contiguous output range
    s1descriptor : bits(128), // Stage 1 leaf descriptor in memory (valid if the TLB caches stage 1)
    s2descriptor : bits(128)  // Stage 2 leaf descriptor in memory (valid if the TLB caches stage 2)
};</pstext></ps>
    <ps name="shared/translation/vmsa/TTWState" mylink="shared.translation.vmsa.TTWState" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TTWState
// ========
// Translation table walk state

type <anchor link="type_TTWState">TTWState</anchor> of record {
    istable : boolean,
    level : integer,
    baseaddress : <a link="type_FullAddress" file="shared_pseudocode.xml">FullAddress</a>,
    contiguous : bit,
    s1assured : boolean,  // Stage 1 Assured Translation Property
    s2assuredonly : bit,  // Stage 2 AssuredOnly attribute
    disch : bit,          // Stage 1 Disable Contiguous Hint
    nG : bit,
    guardedpage : bit,
    sdftype : <a link="type_SDFType" file="shared_pseudocode.xml">SDFType</a>,    // AArch32 Short-descriptor format walk only
    domain : bits(4),     // AArch32 Short-descriptor format walk only
    memattrs : <a link="type_MemoryAttributes" file="shared_pseudocode.xml">MemoryAttributes</a>,
    permissions : <a link="type_Permissions" file="shared_pseudocode.xml">Permissions</a>
};</pstext></ps>
    <ps name="shared/translation/vmsa/TranslationRegime" mylink="shared.translation.vmsa.TranslationRegime" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TranslationRegime()
// ===================
// Select the translation regime given the target EL and PE state

func <anchor link="func_TranslationRegime_1">TranslationRegime</anchor>(el : bits(2)) =&gt; <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>
begin
    if el == <a link="global_EL3" file="shared_pseudocode.xml">EL3</a> then
        return if <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a> else <a link="enum_Regime_EL3" file="shared_pseudocode.xml">Regime_EL3</a>;
    elsif el == <a link="global_EL2" file="shared_pseudocode.xml">EL2</a> then
        return if <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL2" file="shared_pseudocode.xml">EL2</a>) then <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a> else <a link="enum_Regime_EL2" file="shared_pseudocode.xml">Regime_EL2</a>;
    elsif el == <a link="global_EL1" file="shared_pseudocode.xml">EL1</a> then
        return <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a>;
    elsif el == <a link="global_EL0" file="shared_pseudocode.xml">EL0</a> then
        if <a link="func_CurrentSecurityState_0" file="shared_pseudocode.xml">CurrentSecurityState</a>() == <a link="enum_SS_Secure" file="shared_pseudocode.xml">SS_Secure</a> &amp;&amp; <a link="func_ELUsingAArch32_1" file="shared_pseudocode.xml">ELUsingAArch32</a>(<a link="global_EL3" file="shared_pseudocode.xml">EL3</a>) then
            return <a link="enum_Regime_EL30" file="shared_pseudocode.xml">Regime_EL30</a>;
        elsif <a link="func_ELIsInHost_1" file="shared_pseudocode.xml">ELIsInHost</a>(<a link="global_EL0" file="shared_pseudocode.xml">EL0</a>) then
            return <a link="enum_Regime_EL20" file="shared_pseudocode.xml">Regime_EL20</a>;
        else
            return <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a>;
        end;
    else
        unreachable;
    end;
end;</pstext></ps>
    <ps name="shared/translation/vmsa/TranslationSize" mylink="shared.translation.vmsa.TranslationSize" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// TranslationSize()
// =================
// Compute the number of bits directly mapped from the input address
// to the output address

func <anchor link="func_TranslationSize_3">TranslationSize</anchor>(d128 : bit, tgx : <a link="type_TGx" file="shared_pseudocode.xml">TGx</a>, level : integer) =&gt; <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>
begin
    let granulebits : <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a> = <a link="func_TGxGranuleBits_1" file="shared_pseudocode.xml">TGxGranuleBits</a>(tgx);
    let descsizelog2 : integer{} = if d128 == '1' then 4 else 3;
    let blockbits : integer   = (<a link="global_FINAL_LEVEL" file="shared_pseudocode.xml">FINAL_LEVEL</a> - level) * (granulebits - descsizelog2);

    return (granulebits + blockbits) as <a link="type_AddressSize" file="shared_pseudocode.xml">AddressSize</a>;
end;</pstext></ps>
    <ps name="shared/translation/vmsa/UseASID" mylink="shared.translation.vmsa.UseASID" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// UseASID()
// =========
// Determine whether the translation context for the access requires ASID or is a global entry

func <anchor link="func_UseASID_1">UseASID</anchor>(accesscontext : <a link="type_TLBContext" file="shared_pseudocode.xml">TLBContext</a>) =&gt; boolean
begin
    return <a link="func_HasUnprivileged_1" file="shared_pseudocode.xml">HasUnprivileged</a>(accesscontext.regime);
end;</pstext></ps>
    <ps name="shared/translation/vmsa/UseVMID" mylink="shared.translation.vmsa.UseVMID" enclabels="" sections="1" secttype="Library">
      <pstext mayhavelinks="1" section="Functions" rep_section="functions">// UseVMID()
// =========
// Determine whether the translation context for the access requires VMID to match a TLB entry

func <anchor link="func_UseVMID_1">UseVMID</anchor>(regime : <a link="type_Regime" file="shared_pseudocode.xml">Regime</a>) =&gt; boolean
begin
    return regime == <a link="enum_Regime_EL10" file="shared_pseudocode.xml">Regime_EL10</a> &amp;&amp; <a link="func_EL2Enabled_0" file="shared_pseudocode.xml">EL2Enabled</a>();
end;</pstext></ps>
  </ps_section>
</instructionsection>