xref: /openbmc/qemu/target/arm/tcg/t16.decode (revision e1f9f73ba15e0356ce1aa3317d7bd294f587ab58)
1*f0984d40SFabiano Rosas# Thumb1 instructions
2*f0984d40SFabiano Rosas#
3*f0984d40SFabiano Rosas#  Copyright (c) 2019 Linaro, Ltd
4*f0984d40SFabiano Rosas#
5*f0984d40SFabiano Rosas# This library is free software; you can redistribute it and/or
6*f0984d40SFabiano Rosas# modify it under the terms of the GNU Lesser General Public
7*f0984d40SFabiano Rosas# License as published by the Free Software Foundation; either
8*f0984d40SFabiano Rosas# version 2.1 of the License, or (at your option) any later version.
9*f0984d40SFabiano Rosas#
10*f0984d40SFabiano Rosas# This library is distributed in the hope that it will be useful,
11*f0984d40SFabiano Rosas# but WITHOUT ANY WARRANTY; without even the implied warranty of
12*f0984d40SFabiano Rosas# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13*f0984d40SFabiano Rosas# Lesser General Public License for more details.
14*f0984d40SFabiano Rosas#
15*f0984d40SFabiano Rosas# You should have received a copy of the GNU Lesser General Public
16*f0984d40SFabiano Rosas# License along with this library; if not, see <http://www.gnu.org/licenses/>.
17*f0984d40SFabiano Rosas
18*f0984d40SFabiano Rosas#
19*f0984d40SFabiano Rosas# This file is processed by scripts/decodetree.py
20*f0984d40SFabiano Rosas#
21*f0984d40SFabiano Rosas
22*f0984d40SFabiano Rosas&empty           !extern
23*f0984d40SFabiano Rosas&s_rrr_shi       !extern s rd rn rm shim shty
24*f0984d40SFabiano Rosas&s_rrr_shr       !extern s rn rd rm rs shty
25*f0984d40SFabiano Rosas&s_rri_rot       !extern s rn rd imm rot
26*f0984d40SFabiano Rosas&s_rrrr          !extern s rd rn rm ra
27*f0984d40SFabiano Rosas&rrr_rot         !extern rd rn rm rot
28*f0984d40SFabiano Rosas&rr              !extern rd rm
29*f0984d40SFabiano Rosas&ri              !extern rd imm
30*f0984d40SFabiano Rosas&r               !extern rm
31*f0984d40SFabiano Rosas&i               !extern imm
32*f0984d40SFabiano Rosas&ldst_rr         !extern p w u rn rt rm shimm shtype
33*f0984d40SFabiano Rosas&ldst_ri         !extern p w u rn rt imm
34*f0984d40SFabiano Rosas&ldst_block      !extern rn i b u w list
35*f0984d40SFabiano Rosas&setend          !extern E
36*f0984d40SFabiano Rosas&cps             !extern mode imod M A I F
37*f0984d40SFabiano Rosas&ci              !extern cond imm
38*f0984d40SFabiano Rosas
39*f0984d40SFabiano Rosas# Set S if the instruction is outside of an IT block.
40*f0984d40SFabiano Rosas%s               !function=t16_setflags
41*f0984d40SFabiano Rosas
42*f0984d40SFabiano Rosas# Data-processing (two low registers)
43*f0984d40SFabiano Rosas
44*f0984d40SFabiano Rosas%reg_0           0:3
45*f0984d40SFabiano Rosas
46*f0984d40SFabiano Rosas@lll_noshr       ...... .... rm:3 rd:3 \
47*f0984d40SFabiano Rosas                 &s_rrr_shi %s rn=%reg_0 shim=0 shty=0
48*f0984d40SFabiano Rosas@xll_noshr       ...... .... rm:3 rn:3 \
49*f0984d40SFabiano Rosas                 &s_rrr_shi s=1 rd=0 shim=0 shty=0
50*f0984d40SFabiano Rosas@lxl_shr         ...... .... rs:3 rd:3 \
51*f0984d40SFabiano Rosas                 &s_rrr_shr %s rm=%reg_0 rn=0
52*f0984d40SFabiano Rosas
53*f0984d40SFabiano RosasAND_rrri         010000 0000 ... ...            @lll_noshr
54*f0984d40SFabiano RosasEOR_rrri         010000 0001 ... ...            @lll_noshr
55*f0984d40SFabiano RosasMOV_rxrr         010000 0010 ... ...            @lxl_shr shty=0  # LSL
56*f0984d40SFabiano RosasMOV_rxrr         010000 0011 ... ...            @lxl_shr shty=1  # LSR
57*f0984d40SFabiano RosasMOV_rxrr         010000 0100 ... ...            @lxl_shr shty=2  # ASR
58*f0984d40SFabiano RosasADC_rrri         010000 0101 ... ...            @lll_noshr
59*f0984d40SFabiano RosasSBC_rrri         010000 0110 ... ...            @lll_noshr
60*f0984d40SFabiano RosasMOV_rxrr         010000 0111 ... ...            @lxl_shr shty=3  # ROR
61*f0984d40SFabiano RosasTST_xrri         010000 1000 ... ...            @xll_noshr
62*f0984d40SFabiano RosasRSB_rri          010000 1001 rn:3 rd:3          &s_rri_rot %s imm=0 rot=0
63*f0984d40SFabiano RosasCMP_xrri         010000 1010 ... ...            @xll_noshr
64*f0984d40SFabiano RosasCMN_xrri         010000 1011 ... ...            @xll_noshr
65*f0984d40SFabiano RosasORR_rrri         010000 1100 ... ...            @lll_noshr
66*f0984d40SFabiano RosasMUL              010000 1101 rn:3 rd:3          &s_rrrr %s rm=%reg_0 ra=0
67*f0984d40SFabiano RosasBIC_rrri         010000 1110 ... ...            @lll_noshr
68*f0984d40SFabiano RosasMVN_rxri         010000 1111 ... ...            @lll_noshr
69*f0984d40SFabiano Rosas
70*f0984d40SFabiano Rosas# Load/store (register offset)
71*f0984d40SFabiano Rosas
72*f0984d40SFabiano Rosas@ldst_rr         ....... rm:3 rn:3 rt:3 \
73*f0984d40SFabiano Rosas                 &ldst_rr p=1 w=0 u=1 shimm=0 shtype=0
74*f0984d40SFabiano Rosas
75*f0984d40SFabiano RosasSTR_rr           0101 000 ... ... ...           @ldst_rr
76*f0984d40SFabiano RosasSTRH_rr          0101 001 ... ... ...           @ldst_rr
77*f0984d40SFabiano RosasSTRB_rr          0101 010 ... ... ...           @ldst_rr
78*f0984d40SFabiano RosasLDRSB_rr         0101 011 ... ... ...           @ldst_rr
79*f0984d40SFabiano RosasLDR_rr           0101 100 ... ... ...           @ldst_rr
80*f0984d40SFabiano RosasLDRH_rr          0101 101 ... ... ...           @ldst_rr
81*f0984d40SFabiano RosasLDRB_rr          0101 110 ... ... ...           @ldst_rr
82*f0984d40SFabiano RosasLDRSH_rr         0101 111 ... ... ...           @ldst_rr
83*f0984d40SFabiano Rosas
84*f0984d40SFabiano Rosas# Load/store word/byte (immediate offset)
85*f0984d40SFabiano Rosas
86*f0984d40SFabiano Rosas%imm5_6x4       6:5 !function=times_4
87*f0984d40SFabiano Rosas
88*f0984d40SFabiano Rosas@ldst_ri_1      ..... imm:5 rn:3 rt:3 \
89*f0984d40SFabiano Rosas                &ldst_ri p=1 w=0 u=1
90*f0984d40SFabiano Rosas@ldst_ri_4      ..... ..... rn:3 rt:3 \
91*f0984d40SFabiano Rosas                &ldst_ri p=1 w=0 u=1 imm=%imm5_6x4
92*f0984d40SFabiano Rosas
93*f0984d40SFabiano RosasSTR_ri          01100 ..... ... ...             @ldst_ri_4
94*f0984d40SFabiano RosasLDR_ri          01101 ..... ... ...             @ldst_ri_4
95*f0984d40SFabiano RosasSTRB_ri         01110 ..... ... ...             @ldst_ri_1
96*f0984d40SFabiano RosasLDRB_ri         01111 ..... ... ...             @ldst_ri_1
97*f0984d40SFabiano Rosas
98*f0984d40SFabiano Rosas# Load/store halfword (immediate offset)
99*f0984d40SFabiano Rosas
100*f0984d40SFabiano Rosas%imm5_6x2       6:5 !function=times_2
101*f0984d40SFabiano Rosas@ldst_ri_2      ..... ..... rn:3 rt:3 \
102*f0984d40SFabiano Rosas                &ldst_ri p=1 w=0 u=1 imm=%imm5_6x2
103*f0984d40SFabiano Rosas
104*f0984d40SFabiano RosasSTRH_ri         10000 ..... ... ...             @ldst_ri_2
105*f0984d40SFabiano RosasLDRH_ri         10001 ..... ... ...             @ldst_ri_2
106*f0984d40SFabiano Rosas
107*f0984d40SFabiano Rosas# Load/store (SP-relative)
108*f0984d40SFabiano Rosas
109*f0984d40SFabiano Rosas%imm8_0x4       0:8 !function=times_4
110*f0984d40SFabiano Rosas@ldst_spec_i    ..... rt:3 ........ \
111*f0984d40SFabiano Rosas                &ldst_ri p=1 w=0 u=1 imm=%imm8_0x4
112*f0984d40SFabiano Rosas
113*f0984d40SFabiano RosasSTR_ri          10010 ... ........              @ldst_spec_i rn=13
114*f0984d40SFabiano RosasLDR_ri          10011 ... ........              @ldst_spec_i rn=13
115*f0984d40SFabiano Rosas
116*f0984d40SFabiano Rosas# Load (PC-relative)
117*f0984d40SFabiano Rosas
118*f0984d40SFabiano RosasLDR_ri          01001 ... ........              @ldst_spec_i rn=15
119*f0984d40SFabiano Rosas
120*f0984d40SFabiano Rosas# Add PC/SP (immediate)
121*f0984d40SFabiano Rosas
122*f0984d40SFabiano RosasADR             10100 rd:3 ........             imm=%imm8_0x4
123*f0984d40SFabiano RosasADD_rri         10101 rd:3 ........ \
124*f0984d40SFabiano Rosas                &s_rri_rot rn=13 s=0 rot=0 imm=%imm8_0x4  # SP
125*f0984d40SFabiano Rosas
126*f0984d40SFabiano Rosas# Load/store multiple
127*f0984d40SFabiano Rosas
128*f0984d40SFabiano Rosas@ldstm          ..... rn:3 list:8               &ldst_block i=1 b=0 u=0 w=1
129*f0984d40SFabiano Rosas
130*f0984d40SFabiano RosasSTM             11000 ... ........              @ldstm
131*f0984d40SFabiano RosasLDM_t16         11001 ... ........              @ldstm
132*f0984d40SFabiano Rosas
133*f0984d40SFabiano Rosas# Shift (immediate)
134*f0984d40SFabiano Rosas
135*f0984d40SFabiano Rosas@shift_i        ..... shim:5 rm:3 rd:3          &s_rrr_shi %s rn=%reg_0
136*f0984d40SFabiano Rosas
137*f0984d40SFabiano RosasMOV_rxri        000 00 ..... ... ...            @shift_i shty=0  # LSL
138*f0984d40SFabiano RosasMOV_rxri        000 01 ..... ... ...            @shift_i shty=1  # LSR
139*f0984d40SFabiano RosasMOV_rxri        000 10 ..... ... ...            @shift_i shty=2  # ASR
140*f0984d40SFabiano Rosas
141*f0984d40SFabiano Rosas# Add/subtract (three low registers)
142*f0984d40SFabiano Rosas
143*f0984d40SFabiano Rosas@addsub_3       ....... rm:3 rn:3 rd:3 \
144*f0984d40SFabiano Rosas                &s_rrr_shi %s shim=0 shty=0
145*f0984d40SFabiano Rosas
146*f0984d40SFabiano RosasADD_rrri        0001100 ... ... ...             @addsub_3
147*f0984d40SFabiano RosasSUB_rrri        0001101 ... ... ...             @addsub_3
148*f0984d40SFabiano Rosas
149*f0984d40SFabiano Rosas# Add/subtract (two low registers and immediate)
150*f0984d40SFabiano Rosas
151*f0984d40SFabiano Rosas@addsub_2i      ....... imm:3 rn:3 rd:3 \
152*f0984d40SFabiano Rosas                &s_rri_rot %s rot=0
153*f0984d40SFabiano Rosas
154*f0984d40SFabiano RosasADD_rri         0001 110 ... ... ...            @addsub_2i
155*f0984d40SFabiano RosasSUB_rri         0001 111 ... ... ...            @addsub_2i
156*f0984d40SFabiano Rosas
157*f0984d40SFabiano Rosas# Add, subtract, compare, move (one low register and immediate)
158*f0984d40SFabiano Rosas
159*f0984d40SFabiano Rosas%reg_8          8:3
160*f0984d40SFabiano Rosas@arith_1i       ..... rd:3 imm:8 \
161*f0984d40SFabiano Rosas                &s_rri_rot rot=0 rn=%reg_8
162*f0984d40SFabiano Rosas
163*f0984d40SFabiano RosasMOV_rxi         00100 ... ........              @arith_1i %s
164*f0984d40SFabiano RosasCMP_xri         00101 ... ........              @arith_1i s=1
165*f0984d40SFabiano RosasADD_rri         00110 ... ........              @arith_1i %s
166*f0984d40SFabiano RosasSUB_rri         00111 ... ........              @arith_1i %s
167*f0984d40SFabiano Rosas
168*f0984d40SFabiano Rosas# Add, compare, move (two high registers)
169*f0984d40SFabiano Rosas
170*f0984d40SFabiano Rosas%reg_0_7        7:1 0:3
171*f0984d40SFabiano Rosas@addsub_2h      .... .... . rm:4 ... \
172*f0984d40SFabiano Rosas                &s_rrr_shi rd=%reg_0_7 rn=%reg_0_7 shim=0 shty=0
173*f0984d40SFabiano Rosas
174*f0984d40SFabiano RosasADD_rrri        0100 0100 . .... ...            @addsub_2h s=0
175*f0984d40SFabiano RosasCMP_xrri        0100 0101 . .... ...            @addsub_2h s=1
176*f0984d40SFabiano RosasMOV_rxri        0100 0110 . .... ...            @addsub_2h s=0
177*f0984d40SFabiano Rosas
178*f0984d40SFabiano Rosas# Adjust SP (immediate)
179*f0984d40SFabiano Rosas
180*f0984d40SFabiano Rosas%imm7_0x4       0:7 !function=times_4
181*f0984d40SFabiano Rosas@addsub_sp_i    .... .... . ....... \
182*f0984d40SFabiano Rosas                &s_rri_rot s=0 rd=13 rn=13 rot=0 imm=%imm7_0x4
183*f0984d40SFabiano Rosas
184*f0984d40SFabiano RosasADD_rri         1011 0000 0 .......             @addsub_sp_i
185*f0984d40SFabiano RosasSUB_rri         1011 0000 1 .......             @addsub_sp_i
186*f0984d40SFabiano Rosas
187*f0984d40SFabiano Rosas# Branch and exchange
188*f0984d40SFabiano Rosas
189*f0984d40SFabiano Rosas@branchr        .... .... . rm:4 ...            &r
190*f0984d40SFabiano Rosas
191*f0984d40SFabiano RosasBX              0100 0111 0 .... 000            @branchr
192*f0984d40SFabiano RosasBLX_r           0100 0111 1 .... 000            @branchr
193*f0984d40SFabiano RosasBXNS            0100 0111 0 .... 100            @branchr
194*f0984d40SFabiano RosasBLXNS           0100 0111 1 .... 100            @branchr
195*f0984d40SFabiano Rosas
196*f0984d40SFabiano Rosas# Extend
197*f0984d40SFabiano Rosas
198*f0984d40SFabiano Rosas@extend         .... .... .. rm:3 rd:3          &rrr_rot rn=15 rot=0
199*f0984d40SFabiano Rosas
200*f0984d40SFabiano RosasSXTAH           1011 0010 00 ... ...            @extend
201*f0984d40SFabiano RosasSXTAB           1011 0010 01 ... ...            @extend
202*f0984d40SFabiano RosasUXTAH           1011 0010 10 ... ...            @extend
203*f0984d40SFabiano RosasUXTAB           1011 0010 11 ... ...            @extend
204*f0984d40SFabiano Rosas
205*f0984d40SFabiano Rosas# Change processor state
206*f0984d40SFabiano Rosas
207*f0984d40SFabiano Rosas%imod           4:1 !function=plus_2
208*f0984d40SFabiano Rosas
209*f0984d40SFabiano RosasSETEND          1011 0110 010 1 E:1 000         &setend
210*f0984d40SFabiano Rosas{
211*f0984d40SFabiano Rosas  CPS           1011 0110 011 . 0 A:1 I:1 F:1   &cps mode=0 M=0 %imod
212*f0984d40SFabiano Rosas  CPS_v7m       1011 0110 011 im:1 00 I:1 F:1
213*f0984d40SFabiano Rosas}
214*f0984d40SFabiano Rosas
215*f0984d40SFabiano Rosas# Reverse bytes
216*f0984d40SFabiano Rosas
217*f0984d40SFabiano Rosas@rdm            .... .... .. rm:3 rd:3          &rr
218*f0984d40SFabiano Rosas
219*f0984d40SFabiano RosasREV             1011 1010 00 ... ...            @rdm
220*f0984d40SFabiano RosasREV16           1011 1010 01 ... ...            @rdm
221*f0984d40SFabiano RosasREVSH           1011 1010 11 ... ...            @rdm
222*f0984d40SFabiano Rosas
223*f0984d40SFabiano Rosas# Hints
224*f0984d40SFabiano Rosas
225*f0984d40SFabiano Rosas{
226*f0984d40SFabiano Rosas  {
227*f0984d40SFabiano Rosas    YIELD       1011 1111 0001 0000
228*f0984d40SFabiano Rosas    WFE         1011 1111 0010 0000
229*f0984d40SFabiano Rosas    WFI         1011 1111 0011 0000
230*f0984d40SFabiano Rosas
231*f0984d40SFabiano Rosas    # TODO: Implement SEV, SEVL; may help SMP performance.
232*f0984d40SFabiano Rosas    # SEV       1011 1111 0100 0000
233*f0984d40SFabiano Rosas    # SEVL      1011 1111 0101 0000
234*f0984d40SFabiano Rosas
235*f0984d40SFabiano Rosas    # The canonical nop has the second nibble as 0000, but the whole of the
236*f0984d40SFabiano Rosas    # rest of the space is a reserved hint, behaves as nop.
237*f0984d40SFabiano Rosas    NOP         1011 1111 ---- 0000
238*f0984d40SFabiano Rosas  }
239*f0984d40SFabiano Rosas  IT            1011 1111 cond_mask:8
240*f0984d40SFabiano Rosas}
241*f0984d40SFabiano Rosas
242*f0984d40SFabiano Rosas# Miscellaneous 16-bit instructions
243*f0984d40SFabiano Rosas
244*f0984d40SFabiano Rosas%imm6_9_3       9:1 3:5 !function=times_2
245*f0984d40SFabiano Rosas
246*f0984d40SFabiano RosasHLT             1011 1010 10 imm:6              &i
247*f0984d40SFabiano RosasBKPT            1011 1110 imm:8                 &i
248*f0984d40SFabiano RosasCBZ             1011 nz:1 0.1 ..... rn:3        imm=%imm6_9_3
249*f0984d40SFabiano Rosas
250*f0984d40SFabiano Rosas# Push and Pop
251*f0984d40SFabiano Rosas
252*f0984d40SFabiano Rosas%push_list      0:9 !function=t16_push_list
253*f0984d40SFabiano Rosas%pop_list       0:9 !function=t16_pop_list
254*f0984d40SFabiano Rosas
255*f0984d40SFabiano RosasSTM             1011 010 ......... \
256*f0984d40SFabiano Rosas                &ldst_block i=0 b=1 u=0 w=1 rn=13 list=%push_list
257*f0984d40SFabiano RosasLDM_t16         1011 110 ......... \
258*f0984d40SFabiano Rosas                &ldst_block i=1 b=0 u=0 w=1 rn=13 list=%pop_list
259*f0984d40SFabiano Rosas
260*f0984d40SFabiano Rosas# Conditional branches, Supervisor call
261*f0984d40SFabiano Rosas
262*f0984d40SFabiano Rosas%imm8_0x2       0:s8 !function=times_2
263*f0984d40SFabiano Rosas
264*f0984d40SFabiano Rosas{
265*f0984d40SFabiano Rosas  UDF           1101 1110 ---- ----
266*f0984d40SFabiano Rosas  SVC           1101 1111 imm:8                 &i
267*f0984d40SFabiano Rosas  B_cond_thumb  1101 cond:4 ........            &ci imm=%imm8_0x2
268*f0984d40SFabiano Rosas}
269*f0984d40SFabiano Rosas
270*f0984d40SFabiano Rosas# Unconditional Branch
271*f0984d40SFabiano Rosas
272*f0984d40SFabiano Rosas%imm11_0x2      0:s11 !function=times_2
273*f0984d40SFabiano Rosas
274*f0984d40SFabiano RosasB               11100 ...........               &i imm=%imm11_0x2
275*f0984d40SFabiano Rosas
276*f0984d40SFabiano Rosas# thumb_insn_is_16bit() ensures we won't be decoding these as
277*f0984d40SFabiano Rosas# T16 instructions for a Thumb2 CPU, so these patterns must be
278*f0984d40SFabiano Rosas# a Thumb1 split BL/BLX.
279*f0984d40SFabiano RosasBLX_suffix      11101 imm:11                    &i
280*f0984d40SFabiano RosasBL_BLX_prefix   11110 imm:s11                   &i
281*f0984d40SFabiano RosasBL_suffix       11111 imm:11                    &i
282