<?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="ERET" title="ERET -- A64" type="instruction">
  <docvars>
    <docvar key="instr-class" value="system" />
    <docvar key="isa" value="A64" />
    <docvar key="mnemonic" value="ERET" />
  </docvars>
  <heading>ERET</heading>
  <desc>
    <brief>
      <para>Exception Return</para>
    </brief>
    <authored>
      <para>Exception Return using the ELR and SPSR for the current Exception level. When executed, the PE restores <xref linkend="BEIDIGBH">PSTATE</xref> from the SPSR, and branches to the address held in the 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>ERET</instruction> is <arm-defined-word>undefined</arm-defined-word> at EL0.</para>
    </authored>
  </desc>
  <alias_list howmany="0"></alias_list>
  <classes>
    <iclass name="System" oneof="1" id="iclass_system" no_encodings="1" isa="A64">
      <docvars>
        <docvar key="instr-class" value="system" />
        <docvar key="isa" value="A64" />
        <docvar key="mnemonic" value="ERET" />
      </docvars>
      <iclassintro count="1"></iclassintro>
      <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>0</c>
        </box>
        <box hibit="10" name="M" usename="1" settings="1" psbits="x">
          <c>0</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>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
        </box>
      </regdiagram>
      <encoding name="ERET_64E_branch_reg" oneofinclass="1" oneof="1" label="">
        <docvars>
          <docvar key="instr-class" value="system" />
          <docvar key="isa" value="A64" />
          <docvar key="mnemonic" value="ERET" />
        </docvars>
        <asmtemplate><text>ERET</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>
