collab/polyglot-riscv-arm

what if the same machine code was valid riscv and arm asm

git clone https://git.julia.blue/collab/polyglot-riscv-arm

Jonathan Dönszelmannwebsite start885cc4e

main
15.0 KiB116 linesraw
1<?xml version="1.0" encoding="utf-8"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="insn.css"/><meta name="generator" content="iform.xsl"/><title>BL, BLX (immediate) -- AArch32</title></head><body><table style="margin: 0 auto;"><tr><td><div class="topbar"><a href="index.html">Base Instructions</a></div></td><td><div class="topbar"><a href="fpsimdindex.html">SIMD&amp;FP Instructions</a></div></td><td><div class="topbar"><a href="a32_encindex.html">A32 Instructions by Encoding</a></div></td><td><div class="topbar"><a href="t32_encindex.html">T32 Instructions by Encoding</a></div></td><td><div class="topbar"><a href="shared_pseudocode.html">Shared Pseudocode</a></div></td><td><div class="topbar"><a href="notice.html">Proprietary Notice</a></div></td></tr></table><hr/><h2 class="instruction-section">BL, BLX (immediate)</h2>
4      <p class="aml">Branch with Link calls a subroutine at a PC-relative address, and setting LR to the return address.</p>
5      <p class="aml">Branch with Link and Exchange Instruction Sets (immediate) calls a subroutine at a PC-relative address, setting LR to the return address, and changes the instruction set from A32 to T32, or from T32 to A32.</p>
6    
7    <p class="desc">
8      It has encodings from the following instruction sets:
9       A32 (
10      <a href="#iclass_a1">A1</a>
11       and 
12      <a href="#iclass_a2">A2</a>
13      )
14       and 
15       T32 (
16      <a href="#iclass_t1">T1</a>
17       and 
18      <a href="#iclass_t2">T2</a>
19      )
20      .
21    </p>
22    <h3 class="classheading"><a id="iclass_a1"/>A1</h3><div class="regdiagram-32"><table class="regdiagram"><thead><tr><td>31</td><td>30</td><td>29</td><td>28</td><td>27</td><td>26</td><td>25</td><td>24</td><td>23</td><td>22</td><td>21</td><td>20</td><td>19</td><td>18</td><td>17</td><td>16</td><td>15</td><td>14</td><td>13</td><td>12</td><td>11</td><td>10</td><td>9</td><td>8</td><td>7</td><td>6</td><td>5</td><td>4</td><td>3</td><td>2</td><td>1</td><td>0</td></tr></thead><tbody><tr class="firstrow"><td colspan="4" class="lr">!= 1111</td><td class="l">1</td><td>0</td><td class="r">1</td><td class="lr">1</td><td colspan="24" class="lr">imm24</td></tr><tr class="secondrow"><td colspan="4" class="droppedname">cond</td><td colspan="3"/><td/><td colspan="24"/></tr></tbody></table></div><div class="encoding"><h4 class="encoding">A1</h4><a id="BL_i_A1"/><p class="asm-code">BL{<a href="#sa_c" title="See {xref{ARMARM_Babbefhf}{Standard assembler syntax fields}}">&lt;c&gt;</a>}{<a href="#sa_q" title="See {xref{ARMARM_Babbefhf}{Standard assembler syntax fields}}">&lt;q&gt;</a>} <a href="#sa_label_2" title="The label of instruction that is to be branched to">&lt;label&gt;</a></p></div><p class="pseudocode">constant imm32 = <a href="shared_pseudocode.html#impl-shared.SignExtend.2" title="function: bits(N) SignExtend(bits(M) x, integer N)">SignExtend</a>(imm24:'00', 32);  constant targetInstrSet = <a href="shared_pseudocode.html#InstrSet_A32" title="enumeration InstrSet {InstrSet_A64, InstrSet_A32, InstrSet_T32}">InstrSet_A32</a>;</p>
23    <h3 class="classheading"><a id="iclass_a2"/>A2</h3><div class="regdiagram-32"><table class="regdiagram"><thead><tr><td>31</td><td>30</td><td>29</td><td>28</td><td>27</td><td>26</td><td>25</td><td>24</td><td>23</td><td>22</td><td>21</td><td>20</td><td>19</td><td>18</td><td>17</td><td>16</td><td>15</td><td>14</td><td>13</td><td>12</td><td>11</td><td>10</td><td>9</td><td>8</td><td>7</td><td>6</td><td>5</td><td>4</td><td>3</td><td>2</td><td>1</td><td>0</td></tr></thead><tbody><tr class="firstrow"><td class="l">1</td><td>1</td><td>1</td><td class="r">1</td><td class="l">1</td><td>0</td><td class="r">1</td><td class="lr">H</td><td colspan="24" class="lr">imm24</td></tr><tr class="secondrow"><td colspan="4" class="droppedname">cond</td><td colspan="3"/><td/><td colspan="24"/></tr></tbody></table></div><div class="encoding"><h4 class="encoding">A2</h4><a id="BL_i_A2"/><p class="asm-code">BLX{<a href="#sa_c_1" title="See {xref{ARMARM_Babbefhf}{Standard assembler syntax fields}}">&lt;c&gt;</a>}{<a href="#sa_q" title="See {xref{ARMARM_Babbefhf}{Standard assembler syntax fields}}">&lt;q&gt;</a>} <a href="#sa_label_3" title="The label of instruction that is to be branched to">&lt;label&gt;</a></p></div><p class="pseudocode">constant imm32 = <a href="shared_pseudocode.html#impl-shared.SignExtend.2" title="function: bits(N) SignExtend(bits(M) x, integer N)">SignExtend</a>(imm24:H:'0', 32);  constant targetInstrSet = <a href="shared_pseudocode.html#InstrSet_T32" title="enumeration InstrSet {InstrSet_A64, InstrSet_A32, InstrSet_T32}">InstrSet_T32</a>;</p>
24    <h3 class="classheading"><a id="iclass_t1"/>T1</h3><div class="regdiagram-16x2"><table class="regdiagram"><thead><tr><td>15</td><td>14</td><td>13</td><td>12</td><td>11</td><td>10</td><td>9</td><td>8</td><td>7</td><td>6</td><td>5</td><td>4</td><td>3</td><td>2</td><td>1</td><td>0</td><td>15</td><td>14</td><td>13</td><td>12</td><td>11</td><td>10</td><td>9</td><td>8</td><td>7</td><td>6</td><td>5</td><td>4</td><td>3</td><td>2</td><td>1</td><td>0</td></tr></thead><tbody><tr class="firstrow"><td class="l">1</td><td>1</td><td>1</td><td>1</td><td class="r">0</td><td class="lr">S</td><td colspan="10" class="lr">imm10</td><td class="l">1</td><td class="r">1</td><td class="lr">J1</td><td class="lr">1</td><td class="lr">J2</td><td colspan="11" class="lr">imm11</td></tr></tbody></table></div><div class="encoding"><h4 class="encoding">T1</h4><a id="BL_i_T1"/><p class="asm-code">BL{<a href="#sa_c" title="See {xref{ARMARM_Babbefhf}{Standard assembler syntax fields}}">&lt;c&gt;</a>}{<a href="#sa_q" title="See {xref{ARMARM_Babbefhf}{Standard assembler syntax fields}}">&lt;q&gt;</a>} <a href="#sa_label" title="The label of instruction that is to be branched to">&lt;label&gt;</a></p></div><p class="pseudocode">constant I1 = NOT(J1 EOR S);  constant I2 = NOT(J2 EOR S);
25constant imm32 = <a href="shared_pseudocode.html#impl-shared.SignExtend.2" title="function: bits(N) SignExtend(bits(M) x, integer N)">SignExtend</a>(S:I1:I2:imm10:imm11:'0', 32);
26constant targetInstrSet = <a href="shared_pseudocode.html#InstrSet_T32" title="enumeration InstrSet {InstrSet_A64, InstrSet_A32, InstrSet_T32}">InstrSet_T32</a>;
27if <a href="shared_pseudocode.html#impl-aarch32.InITBlock.0" title="function: boolean InITBlock()">InITBlock</a>() &amp;&amp; !<a href="shared_pseudocode.html#impl-aarch32.LastInITBlock.0" title="function: boolean LastInITBlock()">LastInITBlock</a>() then UNPREDICTABLE;</p>
28    <h3 class="classheading"><a id="iclass_t2"/>T2</h3><div class="regdiagram-16x2"><table class="regdiagram"><thead><tr><td>15</td><td>14</td><td>13</td><td>12</td><td>11</td><td>10</td><td>9</td><td>8</td><td>7</td><td>6</td><td>5</td><td>4</td><td>3</td><td>2</td><td>1</td><td>0</td><td>15</td><td>14</td><td>13</td><td>12</td><td>11</td><td>10</td><td>9</td><td>8</td><td>7</td><td>6</td><td>5</td><td>4</td><td>3</td><td>2</td><td>1</td><td>0</td></tr></thead><tbody><tr class="firstrow"><td class="l">1</td><td>1</td><td>1</td><td>1</td><td class="r">0</td><td class="lr">S</td><td colspan="10" class="lr">imm10H</td><td class="l">1</td><td class="r">1</td><td class="lr">J1</td><td class="lr">0</td><td class="lr">J2</td><td colspan="10" class="lr">imm10L</td><td class="lr">H</td></tr></tbody></table></div><div class="encoding"><h4 class="encoding">T2</h4><a id="BL_i_T2"/><p class="asm-code">BLX{<a href="#sa_c" title="See {xref{ARMARM_Babbefhf}{Standard assembler syntax fields}}">&lt;c&gt;</a>}{<a href="#sa_q" title="See {xref{ARMARM_Babbefhf}{Standard assembler syntax fields}}">&lt;q&gt;</a>} <a href="#sa_label_1" title="The label of instruction that is to be branched to">&lt;label&gt;</a></p></div><p class="pseudocode">if H == '1' then UNDEFINED;
29constant I1 = NOT(J1 EOR S);  constant I2 = NOT(J2 EOR S);
30constant imm32 = <a href="shared_pseudocode.html#impl-shared.SignExtend.2" title="function: bits(N) SignExtend(bits(M) x, integer N)">SignExtend</a>(S:I1:I2:imm10H:imm10L:'00', 32);
31constant targetInstrSet = <a href="shared_pseudocode.html#InstrSet_A32" title="enumeration InstrSet {InstrSet_A64, InstrSet_A32, InstrSet_T32}">InstrSet_A32</a>;
32if <a href="shared_pseudocode.html#impl-aarch32.InITBlock.0" title="function: boolean InITBlock()">InITBlock</a>() &amp;&amp; !<a href="shared_pseudocode.html#impl-aarch32.LastInITBlock.0" title="function: boolean LastInITBlock()">LastInITBlock</a>() then UNPREDICTABLE;</p>
33  <div class="encoding-notes">
34      <p class="aml">For more information about the <span class="arm-defined-word">constrained unpredictable</span> behavior, see <a class="armarm-xref" title="Reference to Armv8 ARM section" data-linkend="CJAEGDJC">Architectural Constraints on UNPREDICTABLE behaviors</a>.</p>
35    </div><h3 class="explanations">Assembler Symbols</h3><div class="explanations"><table><col class="asyn-l"/><col class="asyn-r"/><tr><td>&lt;c&gt;</td><td><a id="sa_c"/>
36        
37          <p class="aml">For encoding A1, T1 and T2: see <a class="armarm-xref" title="Reference to Armv8 ARM section" data-linkend="Babbefhf">Standard assembler syntax fields</a>.</p>
38        
39      </td></tr><tr><td/><td><a id="sa_c_1"/>
40        
41          
42          
43          
44        
45        
46          <p class="aml">For encoding A2: see <a class="armarm-xref" title="Reference to Armv8 ARM section" data-linkend="Babbefhf">Standard assembler syntax fields</a>. &lt;c&gt; must be AL or omitted.</p>
47        
48      </td></tr></table><table><col class="asyn-l"/><col class="asyn-r"/><tr><td>&lt;q&gt;</td><td><a id="sa_q"/>
49        
50          <p class="aml">See <a class="armarm-xref" title="Reference to Armv8 ARM section" data-linkend="Babbefhf">Standard assembler syntax fields</a>.</p>
51        
52      </td></tr></table><table><col class="asyn-l"/><col class="asyn-r"/><tr><td>&lt;label&gt;</td><td><a id="sa_label_2"/>
53        
54          
55          
56          
57        
58        
59          <p class="aml">For encoding A1: the label of the instruction that is to be branched to. The assembler calculates the required value of the offset from the PC value of the <span class="asm-code">BL</span> instruction to this label, then selects an encoding that sets imm32 to that offset.</p>
60          <p class="aml">Permitted offsets are multiples of 4 in the range –33554432 to 33554428.</p>
61        
62      </td></tr><tr><td/><td><a id="sa_label_3"/>
63        
64          
65          
66          
67        
68        
69          <p class="aml">For encoding A2: the label of the instruction that is to be branched to. The assembler calculates the required value of the offset from the PC value of the <span class="asm-code">BLX</span> instruction to this label, then selects an encoding with imm32 set to that offset.</p>
70          <p class="aml">Permitted offsets are even numbers in the range –33554432 to 33554430.</p>
71        
72      </td></tr><tr><td/><td><a id="sa_label"/>
73        
74          
75          
76          
77        
78        
79          <p class="aml">For encoding T1: the label of the instruction that is to be branched to.</p>
80          <p class="aml">The assembler calculates the required value of the offset from the PC value of the <span class="asm-code">BL</span> instruction to this label, then selects an encoding with imm32 set to that offset.</p>
81          <p class="aml">Permitted offsets are even numbers in the range –16777216 to 16777214.</p>
82        
83      </td></tr><tr><td/><td><a id="sa_label_1"/>
84        
85          
86          
87          
88        
89        
90          <p class="aml">For encoding T2: the label of the instruction that is to be branched to.</p>
91          <p class="aml">The assembler calculates the required value of the offset from the Align(PC, 4) value of the <span class="asm-code">BLX</span> instruction to this label, then selects an encoding with imm32 set to that offset.</p>
92          <p class="aml">Permitted offsets are multiples of 4 in the range –16777216 to 16777212.</p>
93        
94      </td></tr></table></div><div class="syntax-notes"/>
95    <div class="ps"><a id="execute"/><h3 class="pseudocode">Operation</h3>
96      <p class="pseudocode">if <a href="shared_pseudocode.html#impl-aarch32.ConditionPassed.0" title="function: boolean ConditionPassed()">ConditionPassed</a>() then
97    EncodingSpecificOperations();
98    if <a href="shared_pseudocode.html#impl-shared.CurrentInstrSet.0" title="function: InstrSet CurrentInstrSet()">CurrentInstrSet</a>() == <a href="shared_pseudocode.html#InstrSet_A32" title="enumeration InstrSet {InstrSet_A64, InstrSet_A32, InstrSet_T32}">InstrSet_A32</a> then
99        <a href="shared_pseudocode.html#impl-aarch32.LR.write.none" title="accessor: LR = bits(32) value">LR</a> = <a href="shared_pseudocode.html#impl-aarch32.PC32.read.none" title="accessor: bits(32) PC32">PC32</a> - 4;
100    else
101        <a href="shared_pseudocode.html#impl-aarch32.LR.write.none" title="accessor: LR = bits(32) value">LR</a> = <a href="shared_pseudocode.html#impl-aarch32.PC32.read.none" title="accessor: bits(32) PC32">PC32</a>&lt;31:1&gt; : '1';
102    bits(32) targetAddress;
103    if targetInstrSet == <a href="shared_pseudocode.html#InstrSet_A32" title="enumeration InstrSet {InstrSet_A64, InstrSet_A32, InstrSet_T32}">InstrSet_A32</a> then
104        targetAddress = <a href="shared_pseudocode.html#impl-shared.Align.2" title="function: integer Align(integer x, integer y)">Align</a>(<a href="shared_pseudocode.html#impl-aarch32.PC32.read.none" title="accessor: bits(32) PC32">PC32</a>,4) + imm32;
105    else
106        targetAddress = <a href="shared_pseudocode.html#impl-aarch32.PC32.read.none" title="accessor: bits(32) PC32">PC32</a> + imm32;
107    <a href="shared_pseudocode.html#impl-aarch32.SelectInstrSet.1" title="function: SelectInstrSet(InstrSet iset)">SelectInstrSet</a>(targetInstrSet);
108    <a href="shared_pseudocode.html#impl-aarch32.BranchWritePC.2" title="function: BranchWritePC(bits(32) address_in, BranchType branch_type)">BranchWritePC</a>(targetAddress, <a href="shared_pseudocode.html#BranchType_DIRCALL" title="enumeration BranchType { BranchType_DIRCALL, BranchType_INDCALL, BranchType_ERET, BranchType_DBGEXIT, BranchType_RET, BranchType_DIR, BranchType_INDIR, BranchType_EXCEPTION, BranchType_TMFAIL, BranchType_RESET, BranchType_UNKNOWN}">BranchType_DIRCALL</a>);</p>
109    </div>
110  <hr/><table style="margin: 0 auto;"><tr><td><div class="topbar"><a href="index.html">Base Instructions</a></div></td><td><div class="topbar"><a href="fpsimdindex.html">SIMD&amp;FP Instructions</a></div></td><td><div class="topbar"><a href="a32_encindex.html">A32 Instructions by Encoding</a></div></td><td><div class="topbar"><a href="t32_encindex.html">T32 Instructions by Encoding</a></div></td><td><div class="topbar"><a href="shared_pseudocode.html">Shared Pseudocode</a></div></td><td><div class="topbar"><a href="notice.html">Proprietary Notice</a></div></td></tr></table><p class="versions">
111      Internal version only: isa v01_31, pseudocode v2024-09_rel
112      ; Build timestamp: 2024-09-26T13:26
113    </p><p class="copyconf">
114      Copyright © 2010-2024 Arm Limited or its affiliates. All rights reserved.
115      This document is Non-Confidential.
116    </p></body></html>