<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" encoding="UTF-8" href="iform.xsl" version="1.0"?>
<!DOCTYPE instructionsection PUBLIC "-//ARM//DTD instructionsection //EN" "iform-p.dtd">
<!-- Copyright (c) 2010-2022 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="ERETA" title="ERETAA, ERETAB -- A64" type="instruction">
  <docvars>
    <docvar key="instr-class" value="general" />
    <docvar key="isa" value="A64" />
  </docvars>
  <heading>ERETAA, ERETAB</heading>
  <desc>
    <brief>
      <para>Exception Return, with pointer authentication</para>
    </brief>
    <authored>
      <para>Exception Return, with pointer authentication. This instruction authenticates the address in ELR, using SP as the modifier and the specified key, the PE restores <xref linkend="BEIDIGBH">PSTATE</xref> from the SPSR for the current Exception level, and branches to the authenticated address.</para>
      <para>Key A is used for <instruction>ERETAA</instruction>. Key B is used for <instruction>ERETAB</instruction>.</para>
      <para>If the authentication passes, the PE continues execution at the target of the branch. For information on behavior if the authentication fails, see <xref>Faulting on pointer authentication</xref>.</para>
      <para>The authenticated address is not written back to ELR.</para>
      <para>The PE checks the SPSR for the current Exception level for an illegal return event. See <xref linkend="BEIEGDFD">Illegal return events from AArch64 state</xref>.</para>
      <para><instruction>ERETAA</instruction> and <instruction>ERETAB</instruction> are <arm-defined-word>undefined</arm-defined-word> at EL0.</para>
    </authored>
  </desc>
  <alias_list howmany="0"></alias_list>
  <classes>
    <iclass name="Integer" oneof="1" id="iclass_general" no_encodings="2" isa="A64">
      <docvars>
        <docvar key="instr-class" value="general" />
        <docvar key="isa" value="A64" />
      </docvars>
      <iclassintro count="2"></iclassintro>
      <arch_variants>
        <arch_variant name="ARMv8.3" feature="FEAT_PAuth" />
      </arch_variants>
      <regdiagram form="32" psname="aarch64/instrs/branch/unconditional/eret" tworows="1">
        <box hibit="31" width="7" settings="7">
          <c>1</c>
          <c>1</c>
          <c>0</c>
          <c>1</c>
          <c>0</c>
          <c>1</c>
          <c>1</c>
        </box>
        <box hibit="24" name="opc[3]" settings="1">
          <c>0</c>
        </box>
        <box hibit="23" width="3" name="opc[2:0]" settings="3">
          <c>1</c>
          <c>0</c>
          <c>0</c>
        </box>
        <box hibit="20" width="5" name="op2" settings="5">
          <c>1</c>
          <c>1</c>
          <c>1</c>
          <c>1</c>
          <c>1</c>
        </box>
        <box hibit="15" width="4" name="op3[5:2]" settings="4">
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
        </box>
        <box hibit="11" name="A" usename="1" settings="1" psbits="x">
          <c>1</c>
        </box>
        <box hibit="10" name="M" usename="1">
          <c></c>
        </box>
        <box hibit="9" width="5" name="Rn" usename="1" settings="5" psbits="xxxxx">
          <c>1</c>
          <c>1</c>
          <c>1</c>
          <c>1</c>
          <c>1</c>
        </box>
        <box hibit="4" width="5" name="op4" usename="1" settings="5" psbits="xxxxx">
          <c>1</c>
          <c>1</c>
          <c>1</c>
          <c>1</c>
          <c>1</c>
        </box>
      </regdiagram>
      <encoding name="ERETAA_64E_branch_reg" oneofinclass="2" oneof="2" label="ERETAA" bitdiffs="M == 0">
        <docvars>
          <docvar key="instr-class" value="general" />
          <docvar key="isa" value="A64" />
          <docvar key="mnemonic" value="ERETAA" />
        </docvars>
        <box hibit="10" width="1" name="M">
          <c>0</c>
        </box>
        <asmtemplate><text>ERETAA</text></asmtemplate>
      </encoding>
      <encoding name="ERETAB_64E_branch_reg" oneofinclass="2" oneof="2" label="ERETAB" bitdiffs="M == 1">
        <docvars>
          <docvar key="instr-class" value="general" />
          <docvar key="isa" value="A64" />
          <docvar key="mnemonic" value="ERETAB" />
        </docvars>
        <box hibit="10" width="1" name="M">
          <c>1</c>
        </box>
        <asmtemplate><text>ERETAB</text></asmtemplate>
      </encoding>
      <ps_section howmany="1">
        <ps name="aarch64/instrs/branch/unconditional/eret" mylink="aarch64.instrs.branch.unconditional.eret" enclabels="" sections="1" secttype="noheading">
          <pstext mayhavelinks="1" section="Decode" rep_section="decode">if PSTATE.EL == <a link="EL0" file="shared_pseudocode.xml" hover="constant bits(2) EL0 = '00'">EL0</a> then UNDEFINED;
boolean pac = (A == '1');
boolean use_key_a = (M == '0');

if !pac &amp;&amp; op4 != '00000' then
    UNDEFINED;
elsif pac &amp;&amp; (!<a link="impl-aarch64.HavePACExt.0" file="shared_pseudocode.xml" hover="function: boolean HavePACExt()">HavePACExt</a>() || op4 != '11111') then
    UNDEFINED;

if Rn != '11111' then 
    UNDEFINED;</pstext>
        </ps>
      </ps_section>
    </iclass>
  </classes>
  <explanations scope="all"></explanations>
  <ps_section howmany="1">
    <ps name="aarch64/instrs/branch/unconditional/eret" mylink="execute" enclabels="" sections="1" secttype="Operation">
      <pstext mayhavelinks="1" section="Execute" rep_section="execute"><a link="AArch64.CheckForERetTrap.2" file="shared_pseudocode.xml" hover="function: AArch64.CheckForERetTrap(boolean eret_with_pac, boolean pac_uses_key_a)">AArch64.CheckForERetTrap</a>(pac, use_key_a);
bits(64) target = <a link="impl-aarch64.ELR.read.0" file="shared_pseudocode.xml" hover="accessor: bits(64) ELR[]">ELR</a>[];
bits(64) modifier = <a link="impl-aarch64.SP.read.0" file="shared_pseudocode.xml" hover="accessor: bits(64) SP[]">SP</a>[];
boolean auth_then_branch = TRUE;

if pac then
    if use_key_a then
        target = <a link="impl-aarch64.AuthIA.3" file="shared_pseudocode.xml" hover="function: bits(64) AuthIA(bits(64) x, bits(64) y, boolean is_combined)">AuthIA</a>(target, modifier, auth_then_branch);
    else
        target = <a link="impl-aarch64.AuthIB.3" file="shared_pseudocode.xml" hover="function: bits(64) AuthIB(bits(64) x, bits(64) y, boolean is_combined)">AuthIB</a>(target, modifier, auth_then_branch);

<a link="AArch64.ExceptionReturn.2" file="shared_pseudocode.xml" hover="function: AArch64.ExceptionReturn(bits(64) new_pc_in, bits(64) spsr)">AArch64.ExceptionReturn</a>(target, <a link="impl-shared.SPSR.read.0" file="shared_pseudocode.xml" hover="accessor: bits(N) SPSR[]">SPSR</a>[]);</pstext>
    </ps>
  </ps_section>
</instructionsection>
