2 * OpenRISC disassembler
4 * Copyright (c) 2018 Richard Henderson <rth@twiddle.net>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
21 #include "qemu-common.h"
22 #include "disas/bfd.h"
23 #include "qemu/bitops.h"
26 typedef disassemble_info DisasContext
;
28 /* Include the auto-generated decoder. */
29 #include "decode.inc.c"
31 #define output(mnemonic, format, ...) \
32 (info->fprintf_func(info->stream, "%-9s " format, \
33 mnemonic, ##__VA_ARGS__))
35 int print_insn_or1k(bfd_vma addr
, disassemble_info
*info
)
41 status
= info
->read_memory_func(addr
, buffer
, 4, info
);
43 info
->memory_error_func(status
, addr
, info
);
46 insn
= bfd_getb32(buffer
);
48 if (!decode(info
, insn
)) {
49 output(".long", "%#08x", insn
);
54 #define INSN(opcode, format, ...) \
55 static bool trans_l_##opcode(disassemble_info *info, \
56 arg_l_##opcode *a, uint32_t insn) \
58 output("l." #opcode, format, ##__VA_ARGS__); \
62 INSN(add
, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
63 INSN(addc
, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
64 INSN(sub
, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
65 INSN(and, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
66 INSN(or, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
67 INSN(xor, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
68 INSN(sll
, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
69 INSN(srl
, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
70 INSN(sra
, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
71 INSN(ror
, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
72 INSN(exths
, "r%d, r%d", a
->d
, a
->a
)
73 INSN(extbs
, "r%d, r%d", a
->d
, a
->a
)
74 INSN(exthz
, "r%d, r%d", a
->d
, a
->a
)
75 INSN(extbz
, "r%d, r%d", a
->d
, a
->a
)
76 INSN(cmov
, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
77 INSN(ff1
, "r%d, r%d", a
->d
, a
->a
)
78 INSN(fl1
, "r%d, r%d", a
->d
, a
->a
)
79 INSN(mul
, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
80 INSN(mulu
, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
81 INSN(div
, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
82 INSN(divu
, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
83 INSN(muld
, "r%d, r%d", a
->a
, a
->b
)
84 INSN(muldu
, "r%d, r%d", a
->a
, a
->b
)
90 INSN(jalr
, "r%d", a
->b
)
91 INSN(lwa
, "r%d, %d(r%d)", a
->d
, a
->i
, a
->a
)
92 INSN(lwz
, "r%d, %d(r%d)", a
->d
, a
->i
, a
->a
)
93 INSN(lws
, "r%d, %d(r%d)", a
->d
, a
->i
, a
->a
)
94 INSN(lbz
, "r%d, %d(r%d)", a
->d
, a
->i
, a
->a
)
95 INSN(lbs
, "r%d, %d(r%d)", a
->d
, a
->i
, a
->a
)
96 INSN(lhz
, "r%d, %d(r%d)", a
->d
, a
->i
, a
->a
)
97 INSN(lhs
, "r%d, %d(r%d)", a
->d
, a
->i
, a
->a
)
98 INSN(swa
, "%d(r%d), r%d", a
->i
, a
->a
, a
->b
)
99 INSN(sw
, "%d(r%d), r%d", a
->i
, a
->a
, a
->b
)
100 INSN(sb
, "%d(r%d), r%d", a
->i
, a
->a
, a
->b
)
101 INSN(sh
, "%d(r%d), r%d", a
->i
, a
->a
, a
->b
)
103 INSN(addi
, "r%d, r%d, %d", a
->d
, a
->a
, a
->i
)
104 INSN(addic
, "r%d, r%d, %d", a
->d
, a
->a
, a
->i
)
105 INSN(muli
, "r%d, r%d, %d", a
->d
, a
->a
, a
->i
)
106 INSN(maci
, "r%d, %d", a
->a
, a
->i
)
107 INSN(andi
, "r%d, r%d, %d", a
->d
, a
->a
, a
->k
)
108 INSN(ori
, "r%d, r%d, %d", a
->d
, a
->a
, a
->k
)
109 INSN(xori
, "r%d, r%d, %d", a
->d
, a
->a
, a
->i
)
110 INSN(mfspr
, "r%d, r%d, %d", a
->d
, a
->a
, a
->k
)
111 INSN(mtspr
, "r%d, r%d, %d", a
->a
, a
->b
, a
->k
)
112 INSN(mac
, "r%d, r%d", a
->a
, a
->b
)
113 INSN(msb
, "r%d, r%d", a
->a
, a
->b
)
114 INSN(macu
, "r%d, r%d", a
->a
, a
->b
)
115 INSN(msbu
, "r%d, r%d", a
->a
, a
->b
)
116 INSN(slli
, "r%d, r%d, %d", a
->d
, a
->a
, a
->l
)
117 INSN(srli
, "r%d, r%d, %d", a
->d
, a
->a
, a
->l
)
118 INSN(srai
, "r%d, r%d, %d", a
->d
, a
->a
, a
->l
)
119 INSN(rori
, "r%d, r%d, %d", a
->d
, a
->a
, a
->l
)
120 INSN(movhi
, "r%d, %d", a
->d
, a
->k
)
121 INSN(macrc
, "r%d", a
->d
)
122 INSN(sfeq
, "r%d, r%d", a
->a
, a
->b
)
123 INSN(sfne
, "r%d, r%d", a
->a
, a
->b
)
124 INSN(sfgtu
, "r%d, r%d", a
->a
, a
->b
)
125 INSN(sfgeu
, "r%d, r%d", a
->a
, a
->b
)
126 INSN(sfltu
, "r%d, r%d", a
->a
, a
->b
)
127 INSN(sfleu
, "r%d, r%d", a
->a
, a
->b
)
128 INSN(sfgts
, "r%d, r%d", a
->a
, a
->b
)
129 INSN(sfges
, "r%d, r%d", a
->a
, a
->b
)
130 INSN(sflts
, "r%d, r%d", a
->a
, a
->b
)
131 INSN(sfles
, "r%d, r%d", a
->a
, a
->b
)
132 INSN(sfeqi
, "r%d, %d", a
->a
, a
->i
)
133 INSN(sfnei
, "r%d, %d", a
->a
, a
->i
)
134 INSN(sfgtui
, "r%d, %d", a
->a
, a
->i
)
135 INSN(sfgeui
, "r%d, %d", a
->a
, a
->i
)
136 INSN(sfltui
, "r%d, %d", a
->a
, a
->i
)
137 INSN(sfleui
, "r%d, %d", a
->a
, a
->i
)
138 INSN(sfgtsi
, "r%d, %d", a
->a
, a
->i
)
139 INSN(sfgesi
, "r%d, %d", a
->a
, a
->i
)
140 INSN(sfltsi
, "r%d, %d", a
->a
, a
->i
)
141 INSN(sflesi
, "r%d, %d", a
->a
, a
->i
)
142 INSN(sys
, "%d", a
->k
)
143 INSN(trap
, "%d", a
->k
)
149 #define FP_INSN(opcode, suffix, format, ...) \
150 static bool trans_lf_##opcode##_##suffix(disassemble_info *info, \
151 arg_lf_##opcode##_##suffix *a, uint32_t insn) \
153 output("lf." #opcode "." #suffix, format, ##__VA_ARGS__); \
157 FP_INSN(add
, s
, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
158 FP_INSN(sub
, s
, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
159 FP_INSN(mul
, s
, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
160 FP_INSN(div
, s
, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
161 FP_INSN(rem
, s
, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
162 FP_INSN(itof
, s
, "r%d, r%d", a
->d
, a
->a
)
163 FP_INSN(ftoi
, s
, "r%d, r%d", a
->d
, a
->a
)
164 FP_INSN(madd
, s
, "r%d, r%d, r%d", a
->d
, a
->a
, a
->b
)
165 FP_INSN(sfeq
, s
, "r%d, r%d", a
->a
, a
->b
)
166 FP_INSN(sfne
, s
, "r%d, r%d", a
->a
, a
->b
)
167 FP_INSN(sfgt
, s
, "r%d, r%d", a
->a
, a
->b
)
168 FP_INSN(sfge
, s
, "r%d, r%d", a
->a
, a
->b
)
169 FP_INSN(sflt
, s
, "r%d, r%d", a
->a
, a
->b
)
170 FP_INSN(sfle
, s
, "r%d, r%d", a
->a
, a
->b
)