xref: /qemu/target/avr/insn.decode (revision 9d316c75abafbefb1e40e8429e41858b2ab3eeb0)
1865f3bb9SMichael Rolnik#
2865f3bb9SMichael Rolnik# AVR instruction decode definitions.
3865f3bb9SMichael Rolnik#
4865f3bb9SMichael Rolnik# Copyright (c) 2019-2020 Michael Rolnik <mrolnik@gmail.com>
5865f3bb9SMichael Rolnik#
6865f3bb9SMichael Rolnik# This library is free software; you can redistribute it and/or
7865f3bb9SMichael Rolnik# modify it under the terms of the GNU Lesser General Public
8865f3bb9SMichael Rolnik# License as published by the Free Software Foundation; either
9865f3bb9SMichael Rolnik# version 2.1 of the License, or (at your option) any later version.
10865f3bb9SMichael Rolnik#
11865f3bb9SMichael Rolnik# This library is distributed in the hope that it will be useful,
12865f3bb9SMichael Rolnik# but WITHOUT ANY WARRANTY; without even the implied warranty of
13865f3bb9SMichael Rolnik# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14865f3bb9SMichael Rolnik# Lesser General Public License for more details.
15865f3bb9SMichael Rolnik#
16865f3bb9SMichael Rolnik# You should have received a copy of the GNU Lesser General Public
17865f3bb9SMichael Rolnik# License along with this library; if not, see <http://www.gnu.org/licenses/>.
18865f3bb9SMichael Rolnik#
19865f3bb9SMichael Rolnik
20865f3bb9SMichael Rolnik#
21865f3bb9SMichael Rolnik#   regs_16_31_by_one = [16 .. 31]
22865f3bb9SMichael Rolnik#   regs_16_23_by_one = [16 .. 23]
23865f3bb9SMichael Rolnik#   regs_24_30_by_two = [24, 26, 28, 30]
24865f3bb9SMichael Rolnik#   regs_00_30_by_two = [0, 2, 4, 6, 8, .. 30]
25865f3bb9SMichael Rolnik
26865f3bb9SMichael Rolnik%rd             4:5
27865f3bb9SMichael Rolnik%rr             9:1 0:4
28865f3bb9SMichael Rolnik
29865f3bb9SMichael Rolnik%rd_a           4:4                         !function=to_regs_16_31_by_one
30865f3bb9SMichael Rolnik%rd_b           4:3                         !function=to_regs_16_23_by_one
31865f3bb9SMichael Rolnik%rd_c           4:2                         !function=to_regs_24_30_by_two
32865f3bb9SMichael Rolnik%rr_a           0:4                         !function=to_regs_16_31_by_one
33865f3bb9SMichael Rolnik%rr_b           0:3                         !function=to_regs_16_23_by_one
34865f3bb9SMichael Rolnik
35865f3bb9SMichael Rolnik%imm6           6:2 0:4
36865f3bb9SMichael Rolnik%imm8           8:4 0:4
37865f3bb9SMichael Rolnik
38865f3bb9SMichael Rolnik%io_imm         9:2 0:4
39865f3bb9SMichael Rolnik%ldst_d_imm     13:1 10:2 0:3
40865f3bb9SMichael Rolnik
41865f3bb9SMichael Rolnik
42865f3bb9SMichael Rolnik&rd_rr          rd rr
43865f3bb9SMichael Rolnik&rd_imm         rd imm
44865f3bb9SMichael Rolnik
45865f3bb9SMichael Rolnik@op_rd_rr       .... .. . ..... ....        &rd_rr      rd=%rd rr=%rr
46865f3bb9SMichael Rolnik@op_rd_imm6     .... .... .. .. ....        &rd_imm     rd=%rd_c imm=%imm6
47865f3bb9SMichael Rolnik@op_rd_imm8     .... .... .... ....         &rd_imm     rd=%rd_a imm=%imm8
48865f3bb9SMichael Rolnik@fmul           .... .... . ... . ...       &rd_rr      rd=%rd_b rr=%rr_b
49865f3bb9SMichael Rolnik
50865f3bb9SMichael Rolnik#
51865f3bb9SMichael Rolnik# Arithmetic Instructions
52865f3bb9SMichael Rolnik#
53865f3bb9SMichael RolnikADD             0000 11 . ..... ....        @op_rd_rr
54865f3bb9SMichael RolnikADC             0001 11 . ..... ....        @op_rd_rr
55865f3bb9SMichael RolnikADIW            1001 0110 .. .. ....        @op_rd_imm6
56865f3bb9SMichael RolnikSUB             0001 10 . ..... ....        @op_rd_rr
57865f3bb9SMichael RolnikSUBI            0101 .... .... ....         @op_rd_imm8
58865f3bb9SMichael RolnikSBC             0000 10 . ..... ....        @op_rd_rr
59865f3bb9SMichael RolnikSBCI            0100 .... .... ....         @op_rd_imm8
60865f3bb9SMichael RolnikSBIW            1001 0111 .. .. ....        @op_rd_imm6
61865f3bb9SMichael RolnikAND             0010 00 . ..... ....        @op_rd_rr
62865f3bb9SMichael RolnikANDI            0111 .... .... ....         @op_rd_imm8
63865f3bb9SMichael RolnikOR              0010 10 . ..... ....        @op_rd_rr
64865f3bb9SMichael RolnikORI             0110 .... .... ....         @op_rd_imm8
65865f3bb9SMichael RolnikEOR             0010 01 . ..... ....        @op_rd_rr
66865f3bb9SMichael RolnikCOM             1001 010 rd:5 0000
67865f3bb9SMichael RolnikNEG             1001 010 rd:5 0001
68865f3bb9SMichael RolnikINC             1001 010 rd:5 0011
69865f3bb9SMichael RolnikDEC             1001 010 rd:5 1010
70865f3bb9SMichael RolnikMUL             1001 11 . ..... ....        @op_rd_rr
71865f3bb9SMichael RolnikMULS            0000 0010 .... ....         &rd_rr      rd=%rd_a rr=%rr_a
72865f3bb9SMichael RolnikMULSU           0000 0011 0 ... 0 ...       @fmul
73865f3bb9SMichael RolnikFMUL            0000 0011 0 ... 1 ...       @fmul
74865f3bb9SMichael RolnikFMULS           0000 0011 1 ... 0 ...       @fmul
75865f3bb9SMichael RolnikFMULSU          0000 0011 1 ... 1 ...       @fmul
76865f3bb9SMichael RolnikDES             1001 0100 imm:4 1011
77*9d316c75SMichael Rolnik
78*9d316c75SMichael Rolnik#
79*9d316c75SMichael Rolnik# Branch Instructions
80*9d316c75SMichael Rolnik#
81*9d316c75SMichael Rolnik
82*9d316c75SMichael Rolnik# The 22-bit immediate is partially in the opcode word,
83*9d316c75SMichael Rolnik# and partially in the next.  Use append_16 to build the
84*9d316c75SMichael Rolnik# complete 22-bit value.
85*9d316c75SMichael Rolnik%imm_call       4:5 0:1                     !function=append_16
86*9d316c75SMichael Rolnik
87*9d316c75SMichael Rolnik@op_bit         .... .... . bit:3 ....
88*9d316c75SMichael Rolnik@op_bit_imm     .... .. imm:s7 bit:3
89*9d316c75SMichael Rolnik
90*9d316c75SMichael RolnikRJMP            1100 imm:s12
91*9d316c75SMichael RolnikIJMP            1001 0100 0000 1001
92*9d316c75SMichael RolnikEIJMP           1001 0100 0001 1001
93*9d316c75SMichael RolnikJMP             1001 010 ..... 110 .        imm=%imm_call
94*9d316c75SMichael RolnikRCALL           1101 imm:s12
95*9d316c75SMichael RolnikICALL           1001 0101 0000 1001
96*9d316c75SMichael RolnikEICALL          1001 0101 0001 1001
97*9d316c75SMichael RolnikCALL            1001 010 ..... 111 .        imm=%imm_call
98*9d316c75SMichael RolnikRET             1001 0101 0000 1000
99*9d316c75SMichael RolnikRETI            1001 0101 0001 1000
100*9d316c75SMichael RolnikCPSE            0001 00 . ..... ....        @op_rd_rr
101*9d316c75SMichael RolnikCP              0001 01 . ..... ....        @op_rd_rr
102*9d316c75SMichael RolnikCPC             0000 01 . ..... ....        @op_rd_rr
103*9d316c75SMichael RolnikCPI             0011 .... .... ....         @op_rd_imm8
104*9d316c75SMichael RolnikSBRC            1111 110 rr:5 0 bit:3
105*9d316c75SMichael RolnikSBRS            1111 111 rr:5 0 bit:3
106*9d316c75SMichael RolnikSBIC            1001 1001 reg:5 bit:3
107*9d316c75SMichael RolnikSBIS            1001 1011 reg:5 bit:3
108*9d316c75SMichael RolnikBRBS            1111 00 ....... ...         @op_bit_imm
109*9d316c75SMichael RolnikBRBC            1111 01 ....... ...         @op_bit_imm
110