root / target-m68k / translate.c @ 36bb244b
History | View | Annotate | Download (66.4 kB)
1 | e6e5906b | pbrook | /*
|
---|---|---|---|
2 | e6e5906b | pbrook | * m68k translation
|
3 | e6e5906b | pbrook | *
|
4 | e6e5906b | pbrook | * Copyright (c) 2005-2006 CodeSourcery
|
5 | e6e5906b | pbrook | * Written by Paul Brook
|
6 | e6e5906b | pbrook | *
|
7 | e6e5906b | pbrook | * This library is free software; you can redistribute it and/or
|
8 | e6e5906b | pbrook | * modify it under the terms of the GNU Lesser General Public
|
9 | e6e5906b | pbrook | * License as published by the Free Software Foundation; either
|
10 | e6e5906b | pbrook | * version 2 of the License, or (at your option) any later version.
|
11 | e6e5906b | pbrook | *
|
12 | e6e5906b | pbrook | * This library is distributed in the hope that it will be useful,
|
13 | e6e5906b | pbrook | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 | e6e5906b | pbrook | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15 | e6e5906b | pbrook | * General Public License for more details.
|
16 | e6e5906b | pbrook | *
|
17 | e6e5906b | pbrook | * You should have received a copy of the GNU Lesser General Public
|
18 | e6e5906b | pbrook | * License along with this library; if not, write to the Free Software
|
19 | e6e5906b | pbrook | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20 | e6e5906b | pbrook | */
|
21 | e6e5906b | pbrook | #include <stdarg.h> |
22 | e6e5906b | pbrook | #include <stdlib.h> |
23 | e6e5906b | pbrook | #include <stdio.h> |
24 | e6e5906b | pbrook | #include <string.h> |
25 | e6e5906b | pbrook | #include <inttypes.h> |
26 | e6e5906b | pbrook | |
27 | e6e5906b | pbrook | #include "config.h" |
28 | e6e5906b | pbrook | #include "cpu.h" |
29 | e6e5906b | pbrook | #include "exec-all.h" |
30 | e6e5906b | pbrook | #include "disas.h" |
31 | e6e5906b | pbrook | #include "m68k-qreg.h" |
32 | e6e5906b | pbrook | |
33 | e6e5906b | pbrook | static inline void qemu_assert(int cond, const char *msg) |
34 | e6e5906b | pbrook | { |
35 | e6e5906b | pbrook | if (!cond) {
|
36 | e6e5906b | pbrook | fprintf (stderr, "badness: %s\n", msg);
|
37 | e6e5906b | pbrook | abort(); |
38 | e6e5906b | pbrook | } |
39 | e6e5906b | pbrook | } |
40 | e6e5906b | pbrook | |
41 | e6e5906b | pbrook | /* internal defines */
|
42 | e6e5906b | pbrook | typedef struct DisasContext { |
43 | e6e5906b | pbrook | target_ulong pc; |
44 | e6e5906b | pbrook | int is_jmp;
|
45 | e6e5906b | pbrook | int cc_op;
|
46 | e6e5906b | pbrook | uint32_t fpcr; |
47 | e6e5906b | pbrook | struct TranslationBlock *tb;
|
48 | e6e5906b | pbrook | int singlestep_enabled;
|
49 | e6e5906b | pbrook | } DisasContext; |
50 | e6e5906b | pbrook | |
51 | e6e5906b | pbrook | #define DISAS_JUMP_NEXT 4 |
52 | e6e5906b | pbrook | |
53 | e6e5906b | pbrook | /* XXX: move that elsewhere */
|
54 | e6e5906b | pbrook | /* ??? Fix exceptions. */
|
55 | e6e5906b | pbrook | static void *gen_throws_exception; |
56 | e6e5906b | pbrook | #define gen_last_qop NULL |
57 | e6e5906b | pbrook | |
58 | e6e5906b | pbrook | static uint16_t *gen_opc_ptr;
|
59 | e6e5906b | pbrook | static uint32_t *gen_opparam_ptr;
|
60 | e6e5906b | pbrook | extern FILE *logfile;
|
61 | e6e5906b | pbrook | extern int loglevel; |
62 | e6e5906b | pbrook | |
63 | e6e5906b | pbrook | enum {
|
64 | e6e5906b | pbrook | #define DEF(s, n, copy_size) INDEX_op_ ## s, |
65 | e6e5906b | pbrook | #include "opc.h" |
66 | e6e5906b | pbrook | #undef DEF
|
67 | e6e5906b | pbrook | NB_OPS, |
68 | e6e5906b | pbrook | }; |
69 | e6e5906b | pbrook | |
70 | e6e5906b | pbrook | #include "gen-op.h" |
71 | e6e5906b | pbrook | #include "op-hacks.h" |
72 | e6e5906b | pbrook | |
73 | e6e5906b | pbrook | #define OS_BYTE 0 |
74 | e6e5906b | pbrook | #define OS_WORD 1 |
75 | e6e5906b | pbrook | #define OS_LONG 2 |
76 | e6e5906b | pbrook | #define OS_SINGLE 4 |
77 | e6e5906b | pbrook | #define OS_DOUBLE 5 |
78 | e6e5906b | pbrook | |
79 | e6e5906b | pbrook | #define DREG(insn, pos) (((insn >> pos) & 7) + QREG_D0) |
80 | e6e5906b | pbrook | #define AREG(insn, pos) (((insn >> pos) & 7) + QREG_A0) |
81 | e6e5906b | pbrook | #define FREG(insn, pos) (((insn >> pos) & 7) + QREG_F0) |
82 | e6e5906b | pbrook | |
83 | e6e5906b | pbrook | #define M68K_INSN_CF_A (1 << 0) |
84 | e6e5906b | pbrook | #define M68K_INSN_CF_B (1 << 1) |
85 | e6e5906b | pbrook | #define M68K_INSN_CF_C (1 << 2) |
86 | e6e5906b | pbrook | #define M68K_INSN_CF_MAC (1 << 3) |
87 | e6e5906b | pbrook | #define M68K_INSN_CF_EMAC (1 << 4) |
88 | e6e5906b | pbrook | #define M68K_INSN_CF_FPU (1 << 5) |
89 | e6e5906b | pbrook | |
90 | e6e5906b | pbrook | struct m68k_def_t {
|
91 | e6e5906b | pbrook | const char * name; |
92 | e6e5906b | pbrook | uint32_t insns; |
93 | e6e5906b | pbrook | }; |
94 | e6e5906b | pbrook | |
95 | e6e5906b | pbrook | static m68k_def_t m68k_cpu_defs[] = {
|
96 | e6e5906b | pbrook | {"m5206", M68K_INSN_CF_A},
|
97 | e6e5906b | pbrook | {"cfv4e", M68K_INSN_CF_A | M68K_INSN_CF_B | M68K_INSN_CF_C
|
98 | e6e5906b | pbrook | | M68K_INSN_CF_MAC | M68K_INSN_CF_EMAC | M68K_INSN_CF_FPU}, |
99 | e6e5906b | pbrook | {NULL, 0}, |
100 | e6e5906b | pbrook | }; |
101 | e6e5906b | pbrook | |
102 | e6e5906b | pbrook | typedef void (*disas_proc)(DisasContext *, uint16_t); |
103 | e6e5906b | pbrook | |
104 | e6e5906b | pbrook | #define DISAS_INSN(name) \
|
105 | e6e5906b | pbrook | static void disas_##name (DisasContext *s, uint16_t insn) |
106 | e6e5906b | pbrook | |
107 | e6e5906b | pbrook | /* Generate a load from the specified address. Narrow values are
|
108 | e6e5906b | pbrook | sign extended to full register width. */
|
109 | e6e5906b | pbrook | static inline int gen_load(int opsize, int addr, int sign) |
110 | e6e5906b | pbrook | { |
111 | e6e5906b | pbrook | int tmp;
|
112 | e6e5906b | pbrook | switch(opsize) {
|
113 | e6e5906b | pbrook | case OS_BYTE:
|
114 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
115 | e6e5906b | pbrook | if (sign)
|
116 | e6e5906b | pbrook | gen_op_ld8s32(tmp, addr); |
117 | e6e5906b | pbrook | else
|
118 | e6e5906b | pbrook | gen_op_ld8u32(tmp, addr); |
119 | e6e5906b | pbrook | break;
|
120 | e6e5906b | pbrook | case OS_WORD:
|
121 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
122 | e6e5906b | pbrook | if (sign)
|
123 | e6e5906b | pbrook | gen_op_ld16s32(tmp, addr); |
124 | e6e5906b | pbrook | else
|
125 | e6e5906b | pbrook | gen_op_ld16u32(tmp, addr); |
126 | e6e5906b | pbrook | break;
|
127 | e6e5906b | pbrook | case OS_LONG:
|
128 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
129 | e6e5906b | pbrook | gen_op_ld32(tmp, addr); |
130 | e6e5906b | pbrook | break;
|
131 | e6e5906b | pbrook | case OS_SINGLE:
|
132 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_F32); |
133 | e6e5906b | pbrook | gen_op_ldf32(tmp, addr); |
134 | e6e5906b | pbrook | break;
|
135 | e6e5906b | pbrook | case OS_DOUBLE:
|
136 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_F64); |
137 | e6e5906b | pbrook | gen_op_ldf64(tmp, addr); |
138 | e6e5906b | pbrook | break;
|
139 | e6e5906b | pbrook | default:
|
140 | e6e5906b | pbrook | qemu_assert(0, "bad load size"); |
141 | e6e5906b | pbrook | } |
142 | e6e5906b | pbrook | gen_throws_exception = gen_last_qop; |
143 | e6e5906b | pbrook | return tmp;
|
144 | e6e5906b | pbrook | } |
145 | e6e5906b | pbrook | |
146 | e6e5906b | pbrook | /* Generate a store. */
|
147 | e6e5906b | pbrook | static inline void gen_store(int opsize, int addr, int val) |
148 | e6e5906b | pbrook | { |
149 | e6e5906b | pbrook | switch(opsize) {
|
150 | e6e5906b | pbrook | case OS_BYTE:
|
151 | e6e5906b | pbrook | gen_op_st8(addr, val); |
152 | e6e5906b | pbrook | break;
|
153 | e6e5906b | pbrook | case OS_WORD:
|
154 | e6e5906b | pbrook | gen_op_st16(addr, val); |
155 | e6e5906b | pbrook | break;
|
156 | e6e5906b | pbrook | case OS_LONG:
|
157 | e6e5906b | pbrook | gen_op_st32(addr, val); |
158 | e6e5906b | pbrook | break;
|
159 | e6e5906b | pbrook | case OS_SINGLE:
|
160 | e6e5906b | pbrook | gen_op_stf32(addr, val); |
161 | e6e5906b | pbrook | break;
|
162 | e6e5906b | pbrook | case OS_DOUBLE:
|
163 | e6e5906b | pbrook | gen_op_stf64(addr, val); |
164 | e6e5906b | pbrook | break;
|
165 | e6e5906b | pbrook | default:
|
166 | e6e5906b | pbrook | qemu_assert(0, "bad store size"); |
167 | e6e5906b | pbrook | } |
168 | e6e5906b | pbrook | gen_throws_exception = gen_last_qop; |
169 | e6e5906b | pbrook | } |
170 | e6e5906b | pbrook | |
171 | e6e5906b | pbrook | /* Generate an unsigned load if VAL is 0 a signed load if val is -1,
|
172 | e6e5906b | pbrook | otherwise generate a store. */
|
173 | e6e5906b | pbrook | static int gen_ldst(int opsize, int addr, int val) |
174 | e6e5906b | pbrook | { |
175 | e6e5906b | pbrook | if (val > 0) { |
176 | e6e5906b | pbrook | gen_store(opsize, addr, val); |
177 | e6e5906b | pbrook | return 0; |
178 | e6e5906b | pbrook | } else {
|
179 | e6e5906b | pbrook | return gen_load(opsize, addr, val != 0); |
180 | e6e5906b | pbrook | } |
181 | e6e5906b | pbrook | } |
182 | e6e5906b | pbrook | |
183 | e6e5906b | pbrook | /* Handle a base + index + displacement effective addresss. A base of
|
184 | e6e5906b | pbrook | -1 means pc-relative. */
|
185 | e6e5906b | pbrook | static int gen_lea_indexed(DisasContext *s, int opsize, int base) |
186 | e6e5906b | pbrook | { |
187 | e6e5906b | pbrook | int scale;
|
188 | e6e5906b | pbrook | uint32_t offset; |
189 | e6e5906b | pbrook | uint16_t ext; |
190 | e6e5906b | pbrook | int add;
|
191 | e6e5906b | pbrook | int tmp;
|
192 | e6e5906b | pbrook | |
193 | e6e5906b | pbrook | offset = s->pc; |
194 | e6e5906b | pbrook | ext = lduw(s->pc); |
195 | e6e5906b | pbrook | s->pc += 2;
|
196 | e6e5906b | pbrook | tmp = ((ext >> 12) & 7) + ((ext & 0x8000) ? QREG_A0 : QREG_D0); |
197 | e6e5906b | pbrook | /* ??? Check W/L bit. */
|
198 | e6e5906b | pbrook | scale = (ext >> 9) & 3; |
199 | e6e5906b | pbrook | if (scale == 0) { |
200 | e6e5906b | pbrook | add = tmp; |
201 | e6e5906b | pbrook | } else {
|
202 | e6e5906b | pbrook | add = gen_new_qreg(QMODE_I32); |
203 | e6e5906b | pbrook | gen_op_shl32(add, tmp, gen_im32(scale)); |
204 | e6e5906b | pbrook | } |
205 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
206 | e6e5906b | pbrook | if (base != -1) { |
207 | e6e5906b | pbrook | gen_op_add32(tmp, base, gen_im32((int8_t)ext)); |
208 | e6e5906b | pbrook | gen_op_add32(tmp, tmp, add); |
209 | e6e5906b | pbrook | } else {
|
210 | e6e5906b | pbrook | gen_op_add32(tmp, add, gen_im32(offset + (int8_t)ext)); |
211 | e6e5906b | pbrook | } |
212 | e6e5906b | pbrook | return tmp;
|
213 | e6e5906b | pbrook | } |
214 | e6e5906b | pbrook | |
215 | e6e5906b | pbrook | /* Read a 32-bit immediate constant. */
|
216 | e6e5906b | pbrook | static inline uint32_t read_im32(DisasContext *s) |
217 | e6e5906b | pbrook | { |
218 | e6e5906b | pbrook | uint32_t im; |
219 | e6e5906b | pbrook | im = ((uint32_t)lduw(s->pc)) << 16;
|
220 | e6e5906b | pbrook | s->pc += 2;
|
221 | e6e5906b | pbrook | im |= lduw(s->pc); |
222 | e6e5906b | pbrook | s->pc += 2;
|
223 | e6e5906b | pbrook | return im;
|
224 | e6e5906b | pbrook | } |
225 | e6e5906b | pbrook | |
226 | e6e5906b | pbrook | |
227 | e6e5906b | pbrook | /* Update the CPU env CC_OP state. */
|
228 | e6e5906b | pbrook | static inline void gen_flush_cc_op(DisasContext *s) |
229 | e6e5906b | pbrook | { |
230 | e6e5906b | pbrook | if (s->cc_op != CC_OP_DYNAMIC)
|
231 | e6e5906b | pbrook | gen_op_mov32(QREG_CC_OP, gen_im32(s->cc_op)); |
232 | e6e5906b | pbrook | } |
233 | e6e5906b | pbrook | |
234 | e6e5906b | pbrook | /* Evaluate all the CC flags. */
|
235 | e6e5906b | pbrook | static inline void gen_flush_flags(DisasContext *s) |
236 | e6e5906b | pbrook | { |
237 | e6e5906b | pbrook | if (s->cc_op == CC_OP_FLAGS)
|
238 | e6e5906b | pbrook | return;
|
239 | e6e5906b | pbrook | gen_op_flush_flags(s->cc_op); |
240 | e6e5906b | pbrook | s->cc_op = CC_OP_FLAGS; |
241 | e6e5906b | pbrook | } |
242 | e6e5906b | pbrook | |
243 | e6e5906b | pbrook | static inline int opsize_bytes(int opsize) |
244 | e6e5906b | pbrook | { |
245 | e6e5906b | pbrook | switch (opsize) {
|
246 | e6e5906b | pbrook | case OS_BYTE: return 1; |
247 | e6e5906b | pbrook | case OS_WORD: return 2; |
248 | e6e5906b | pbrook | case OS_LONG: return 4; |
249 | e6e5906b | pbrook | case OS_SINGLE: return 4; |
250 | e6e5906b | pbrook | case OS_DOUBLE: return 8; |
251 | e6e5906b | pbrook | default:
|
252 | e6e5906b | pbrook | qemu_assert(0, "bad operand size"); |
253 | e6e5906b | pbrook | } |
254 | e6e5906b | pbrook | } |
255 | e6e5906b | pbrook | |
256 | e6e5906b | pbrook | /* Assign value to a register. If the width is less than the register width
|
257 | e6e5906b | pbrook | only the low part of the register is set. */
|
258 | e6e5906b | pbrook | static void gen_partset_reg(int opsize, int reg, int val) |
259 | e6e5906b | pbrook | { |
260 | e6e5906b | pbrook | int tmp;
|
261 | e6e5906b | pbrook | switch (opsize) {
|
262 | e6e5906b | pbrook | case OS_BYTE:
|
263 | e6e5906b | pbrook | gen_op_and32(reg, reg, gen_im32(0xffffff00));
|
264 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
265 | e6e5906b | pbrook | gen_op_and32(tmp, val, gen_im32(0xff));
|
266 | e6e5906b | pbrook | gen_op_or32(reg, reg, tmp); |
267 | e6e5906b | pbrook | break;
|
268 | e6e5906b | pbrook | case OS_WORD:
|
269 | e6e5906b | pbrook | gen_op_and32(reg, reg, gen_im32(0xffff0000));
|
270 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
271 | e6e5906b | pbrook | gen_op_and32(tmp, val, gen_im32(0xffff));
|
272 | e6e5906b | pbrook | gen_op_or32(reg, reg, tmp); |
273 | e6e5906b | pbrook | break;
|
274 | e6e5906b | pbrook | case OS_LONG:
|
275 | e6e5906b | pbrook | gen_op_mov32(reg, val); |
276 | e6e5906b | pbrook | break;
|
277 | e6e5906b | pbrook | case OS_SINGLE:
|
278 | e6e5906b | pbrook | gen_op_pack_32_f32(reg, val); |
279 | e6e5906b | pbrook | break;
|
280 | e6e5906b | pbrook | default:
|
281 | e6e5906b | pbrook | qemu_assert(0, "Bad operand size"); |
282 | e6e5906b | pbrook | break;
|
283 | e6e5906b | pbrook | } |
284 | e6e5906b | pbrook | } |
285 | e6e5906b | pbrook | |
286 | e6e5906b | pbrook | /* Sign or zero extend a value. */
|
287 | e6e5906b | pbrook | static inline int gen_extend(int val, int opsize, int sign) |
288 | e6e5906b | pbrook | { |
289 | e6e5906b | pbrook | int tmp;
|
290 | e6e5906b | pbrook | |
291 | e6e5906b | pbrook | switch (opsize) {
|
292 | e6e5906b | pbrook | case OS_BYTE:
|
293 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
294 | e6e5906b | pbrook | if (sign)
|
295 | e6e5906b | pbrook | gen_op_ext8s32(tmp, val); |
296 | e6e5906b | pbrook | else
|
297 | e6e5906b | pbrook | gen_op_ext8u32(tmp, val); |
298 | e6e5906b | pbrook | break;
|
299 | e6e5906b | pbrook | case OS_WORD:
|
300 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
301 | e6e5906b | pbrook | if (sign)
|
302 | e6e5906b | pbrook | gen_op_ext16s32(tmp, val); |
303 | e6e5906b | pbrook | else
|
304 | e6e5906b | pbrook | gen_op_ext16u32(tmp, val); |
305 | e6e5906b | pbrook | break;
|
306 | e6e5906b | pbrook | case OS_LONG:
|
307 | e6e5906b | pbrook | tmp = val; |
308 | e6e5906b | pbrook | break;
|
309 | e6e5906b | pbrook | case OS_SINGLE:
|
310 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_F32); |
311 | e6e5906b | pbrook | gen_op_pack_f32_32(tmp, val); |
312 | e6e5906b | pbrook | break;
|
313 | e6e5906b | pbrook | default:
|
314 | e6e5906b | pbrook | qemu_assert(0, "Bad operand size"); |
315 | e6e5906b | pbrook | } |
316 | e6e5906b | pbrook | return tmp;
|
317 | e6e5906b | pbrook | } |
318 | e6e5906b | pbrook | |
319 | e6e5906b | pbrook | /* Generate code for an "effective address". Does not adjust the base
|
320 | e6e5906b | pbrook | register for autoincrememnt addressing modes. */
|
321 | e6e5906b | pbrook | static int gen_lea(DisasContext *s, uint16_t insn, int opsize) |
322 | e6e5906b | pbrook | { |
323 | e6e5906b | pbrook | int reg;
|
324 | e6e5906b | pbrook | int tmp;
|
325 | e6e5906b | pbrook | uint16_t ext; |
326 | e6e5906b | pbrook | uint32_t offset; |
327 | e6e5906b | pbrook | |
328 | e6e5906b | pbrook | reg = insn & 7;
|
329 | e6e5906b | pbrook | switch ((insn >> 3) & 7) { |
330 | e6e5906b | pbrook | case 0: /* Data register direct. */ |
331 | e6e5906b | pbrook | case 1: /* Address register direct. */ |
332 | e6e5906b | pbrook | /* ??? generate bad addressing mode fault. */
|
333 | e6e5906b | pbrook | qemu_assert(0, "invalid addressing mode"); |
334 | e6e5906b | pbrook | case 2: /* Indirect register */ |
335 | e6e5906b | pbrook | case 3: /* Indirect postincrement. */ |
336 | e6e5906b | pbrook | reg += QREG_A0; |
337 | e6e5906b | pbrook | return reg;
|
338 | e6e5906b | pbrook | case 4: /* Indirect predecrememnt. */ |
339 | e6e5906b | pbrook | reg += QREG_A0; |
340 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
341 | e6e5906b | pbrook | gen_op_sub32(tmp, reg, gen_im32(opsize_bytes(opsize))); |
342 | e6e5906b | pbrook | return tmp;
|
343 | e6e5906b | pbrook | case 5: /* Indirect displacement. */ |
344 | e6e5906b | pbrook | reg += QREG_A0; |
345 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
346 | e6e5906b | pbrook | ext = lduw(s->pc); |
347 | e6e5906b | pbrook | s->pc += 2;
|
348 | e6e5906b | pbrook | gen_op_add32(tmp, reg, gen_im32((int16_t)ext)); |
349 | e6e5906b | pbrook | return tmp;
|
350 | e6e5906b | pbrook | case 6: /* Indirect index + displacement. */ |
351 | e6e5906b | pbrook | reg += QREG_A0; |
352 | e6e5906b | pbrook | return gen_lea_indexed(s, opsize, reg);
|
353 | e6e5906b | pbrook | case 7: /* Other */ |
354 | e6e5906b | pbrook | switch (reg) {
|
355 | e6e5906b | pbrook | case 0: /* Absolute short. */ |
356 | e6e5906b | pbrook | offset = ldsw(s->pc); |
357 | e6e5906b | pbrook | s->pc += 2;
|
358 | e6e5906b | pbrook | return gen_im32(offset);
|
359 | e6e5906b | pbrook | case 1: /* Absolute long. */ |
360 | e6e5906b | pbrook | offset = read_im32(s); |
361 | e6e5906b | pbrook | return gen_im32(offset);
|
362 | e6e5906b | pbrook | case 2: /* pc displacement */ |
363 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
364 | e6e5906b | pbrook | offset = s->pc; |
365 | e6e5906b | pbrook | offset += ldsw(s->pc); |
366 | e6e5906b | pbrook | s->pc += 2;
|
367 | e6e5906b | pbrook | return gen_im32(offset);
|
368 | e6e5906b | pbrook | case 3: /* pc index+displacement. */ |
369 | e6e5906b | pbrook | return gen_lea_indexed(s, opsize, -1); |
370 | e6e5906b | pbrook | case 4: /* Immediate. */ |
371 | e6e5906b | pbrook | default:
|
372 | e6e5906b | pbrook | /* ??? generate bad addressing mode fault. */
|
373 | e6e5906b | pbrook | qemu_assert(0, "invalid addressing mode"); |
374 | e6e5906b | pbrook | } |
375 | e6e5906b | pbrook | } |
376 | e6e5906b | pbrook | /* Should never happen. */
|
377 | e6e5906b | pbrook | return -1; |
378 | e6e5906b | pbrook | } |
379 | e6e5906b | pbrook | |
380 | e6e5906b | pbrook | /* Helper function for gen_ea. Reuse the computed address between the
|
381 | e6e5906b | pbrook | for read/write operands. */
|
382 | e6e5906b | pbrook | static inline int gen_ea_once(DisasContext *s, uint16_t insn, int opsize, |
383 | e6e5906b | pbrook | int val, int *addrp) |
384 | e6e5906b | pbrook | { |
385 | e6e5906b | pbrook | int tmp;
|
386 | e6e5906b | pbrook | |
387 | e6e5906b | pbrook | if (addrp && val > 0) { |
388 | e6e5906b | pbrook | tmp = *addrp; |
389 | e6e5906b | pbrook | } else {
|
390 | e6e5906b | pbrook | tmp = gen_lea(s, insn, opsize); |
391 | e6e5906b | pbrook | if (addrp)
|
392 | e6e5906b | pbrook | *addrp = tmp; |
393 | e6e5906b | pbrook | } |
394 | e6e5906b | pbrook | return gen_ldst(opsize, tmp, val);
|
395 | e6e5906b | pbrook | } |
396 | e6e5906b | pbrook | |
397 | e6e5906b | pbrook | /* Generate code to load/store a value ito/from an EA. If VAL > 0 this is
|
398 | e6e5906b | pbrook | a write otherwise it is a read (0 == sign extend, -1 == zero extend).
|
399 | e6e5906b | pbrook | ADDRP is non-null for readwrite operands. */
|
400 | e6e5906b | pbrook | static int gen_ea(DisasContext *s, uint16_t insn, int opsize, int val, |
401 | e6e5906b | pbrook | int *addrp)
|
402 | e6e5906b | pbrook | { |
403 | e6e5906b | pbrook | int reg;
|
404 | e6e5906b | pbrook | int result;
|
405 | e6e5906b | pbrook | uint32_t offset; |
406 | e6e5906b | pbrook | |
407 | e6e5906b | pbrook | reg = insn & 7;
|
408 | e6e5906b | pbrook | switch ((insn >> 3) & 7) { |
409 | e6e5906b | pbrook | case 0: /* Data register direct. */ |
410 | e6e5906b | pbrook | reg += QREG_D0; |
411 | e6e5906b | pbrook | if (val > 0) { |
412 | e6e5906b | pbrook | gen_partset_reg(opsize, reg, val); |
413 | e6e5906b | pbrook | return 0; |
414 | e6e5906b | pbrook | } else {
|
415 | e6e5906b | pbrook | return gen_extend(reg, opsize, val);
|
416 | e6e5906b | pbrook | } |
417 | e6e5906b | pbrook | case 1: /* Address register direct. */ |
418 | e6e5906b | pbrook | reg += QREG_A0; |
419 | e6e5906b | pbrook | if (val > 0) { |
420 | e6e5906b | pbrook | gen_op_mov32(reg, val); |
421 | e6e5906b | pbrook | return 0; |
422 | e6e5906b | pbrook | } else {
|
423 | e6e5906b | pbrook | return gen_extend(reg, opsize, val);
|
424 | e6e5906b | pbrook | } |
425 | e6e5906b | pbrook | case 2: /* Indirect register */ |
426 | e6e5906b | pbrook | reg += QREG_A0; |
427 | e6e5906b | pbrook | return gen_ldst(opsize, reg, val);
|
428 | e6e5906b | pbrook | case 3: /* Indirect postincrement. */ |
429 | e6e5906b | pbrook | reg += QREG_A0; |
430 | e6e5906b | pbrook | result = gen_ldst(opsize, reg, val); |
431 | e6e5906b | pbrook | /* ??? This is not exception safe. The instruction may still
|
432 | e6e5906b | pbrook | fault after this point. */
|
433 | e6e5906b | pbrook | if (val > 0 || !addrp) |
434 | e6e5906b | pbrook | gen_op_add32(reg, reg, gen_im32(opsize_bytes(opsize))); |
435 | e6e5906b | pbrook | return result;
|
436 | e6e5906b | pbrook | case 4: /* Indirect predecrememnt. */ |
437 | e6e5906b | pbrook | { |
438 | e6e5906b | pbrook | int tmp;
|
439 | e6e5906b | pbrook | if (addrp && val > 0) { |
440 | e6e5906b | pbrook | tmp = *addrp; |
441 | e6e5906b | pbrook | } else {
|
442 | e6e5906b | pbrook | tmp = gen_lea(s, insn, opsize); |
443 | e6e5906b | pbrook | if (addrp)
|
444 | e6e5906b | pbrook | *addrp = tmp; |
445 | e6e5906b | pbrook | } |
446 | e6e5906b | pbrook | result = gen_ldst(opsize, tmp, val); |
447 | e6e5906b | pbrook | /* ??? This is not exception safe. The instruction may still
|
448 | e6e5906b | pbrook | fault after this point. */
|
449 | e6e5906b | pbrook | if (val > 0 || !addrp) { |
450 | e6e5906b | pbrook | reg += QREG_A0; |
451 | e6e5906b | pbrook | gen_op_mov32(reg, tmp); |
452 | e6e5906b | pbrook | } |
453 | e6e5906b | pbrook | } |
454 | e6e5906b | pbrook | return result;
|
455 | e6e5906b | pbrook | case 5: /* Indirect displacement. */ |
456 | e6e5906b | pbrook | case 6: /* Indirect index + displacement. */ |
457 | e6e5906b | pbrook | return gen_ea_once(s, insn, opsize, val, addrp);
|
458 | e6e5906b | pbrook | case 7: /* Other */ |
459 | e6e5906b | pbrook | switch (reg) {
|
460 | e6e5906b | pbrook | case 0: /* Absolute short. */ |
461 | e6e5906b | pbrook | case 1: /* Absolute long. */ |
462 | e6e5906b | pbrook | case 2: /* pc displacement */ |
463 | e6e5906b | pbrook | case 3: /* pc index+displacement. */ |
464 | e6e5906b | pbrook | return gen_ea_once(s, insn, opsize, val, addrp);
|
465 | e6e5906b | pbrook | case 4: /* Immediate. */ |
466 | e6e5906b | pbrook | /* Sign extend values for consistency. */
|
467 | e6e5906b | pbrook | switch (opsize) {
|
468 | e6e5906b | pbrook | case OS_BYTE:
|
469 | e6e5906b | pbrook | if (val)
|
470 | e6e5906b | pbrook | offset = ldsb(s->pc + 1);
|
471 | e6e5906b | pbrook | else
|
472 | e6e5906b | pbrook | offset = ldub(s->pc + 1);
|
473 | e6e5906b | pbrook | s->pc += 2;
|
474 | e6e5906b | pbrook | break;
|
475 | e6e5906b | pbrook | case OS_WORD:
|
476 | e6e5906b | pbrook | if (val)
|
477 | e6e5906b | pbrook | offset = ldsw(s->pc); |
478 | e6e5906b | pbrook | else
|
479 | e6e5906b | pbrook | offset = lduw(s->pc); |
480 | e6e5906b | pbrook | s->pc += 2;
|
481 | e6e5906b | pbrook | break;
|
482 | e6e5906b | pbrook | case OS_LONG:
|
483 | e6e5906b | pbrook | offset = read_im32(s); |
484 | e6e5906b | pbrook | break;
|
485 | e6e5906b | pbrook | default:
|
486 | e6e5906b | pbrook | qemu_assert(0, "Bad immediate operand"); |
487 | e6e5906b | pbrook | } |
488 | e6e5906b | pbrook | return gen_im32(offset);
|
489 | e6e5906b | pbrook | default:
|
490 | e6e5906b | pbrook | qemu_assert(0, "invalid addressing mode"); |
491 | e6e5906b | pbrook | } |
492 | e6e5906b | pbrook | } |
493 | e6e5906b | pbrook | /* Should never happen. */
|
494 | e6e5906b | pbrook | return -1; |
495 | e6e5906b | pbrook | } |
496 | e6e5906b | pbrook | |
497 | e6e5906b | pbrook | static void gen_logic_cc(DisasContext *s, int val) |
498 | e6e5906b | pbrook | { |
499 | e6e5906b | pbrook | gen_op_logic_cc(val); |
500 | e6e5906b | pbrook | s->cc_op = CC_OP_LOGIC; |
501 | e6e5906b | pbrook | } |
502 | e6e5906b | pbrook | |
503 | e6e5906b | pbrook | static void gen_jmpcc(DisasContext *s, int cond, int l1) |
504 | e6e5906b | pbrook | { |
505 | e6e5906b | pbrook | int tmp;
|
506 | e6e5906b | pbrook | |
507 | e6e5906b | pbrook | gen_flush_flags(s); |
508 | e6e5906b | pbrook | switch (cond) {
|
509 | e6e5906b | pbrook | case 0: /* T */ |
510 | e6e5906b | pbrook | gen_op_jmp(l1); |
511 | e6e5906b | pbrook | break;
|
512 | e6e5906b | pbrook | case 1: /* F */ |
513 | e6e5906b | pbrook | break;
|
514 | e6e5906b | pbrook | case 2: /* HI (!C && !Z) */ |
515 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
516 | e6e5906b | pbrook | gen_op_and32(tmp, QREG_CC_DEST, gen_im32(CCF_C | CCF_Z)); |
517 | e6e5906b | pbrook | gen_op_jmp_z32(tmp, l1); |
518 | e6e5906b | pbrook | break;
|
519 | e6e5906b | pbrook | case 3: /* LS (C || Z) */ |
520 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
521 | e6e5906b | pbrook | gen_op_and32(tmp, QREG_CC_DEST, gen_im32(CCF_C | CCF_Z)); |
522 | e6e5906b | pbrook | gen_op_jmp_nz32(tmp, l1); |
523 | e6e5906b | pbrook | break;
|
524 | e6e5906b | pbrook | case 4: /* CC (!C) */ |
525 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
526 | e6e5906b | pbrook | gen_op_and32(tmp, QREG_CC_DEST, gen_im32(CCF_C)); |
527 | e6e5906b | pbrook | gen_op_jmp_z32(tmp, l1); |
528 | e6e5906b | pbrook | break;
|
529 | e6e5906b | pbrook | case 5: /* CS (C) */ |
530 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
531 | e6e5906b | pbrook | gen_op_and32(tmp, QREG_CC_DEST, gen_im32(CCF_C)); |
532 | e6e5906b | pbrook | gen_op_jmp_nz32(tmp, l1); |
533 | e6e5906b | pbrook | break;
|
534 | e6e5906b | pbrook | case 6: /* NE (!Z) */ |
535 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
536 | e6e5906b | pbrook | gen_op_and32(tmp, QREG_CC_DEST, gen_im32(CCF_Z)); |
537 | e6e5906b | pbrook | gen_op_jmp_z32(tmp, l1); |
538 | e6e5906b | pbrook | break;
|
539 | e6e5906b | pbrook | case 7: /* EQ (Z) */ |
540 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
541 | e6e5906b | pbrook | gen_op_and32(tmp, QREG_CC_DEST, gen_im32(CCF_Z)); |
542 | e6e5906b | pbrook | gen_op_jmp_nz32(tmp, l1); |
543 | e6e5906b | pbrook | break;
|
544 | e6e5906b | pbrook | case 8: /* VC (!V) */ |
545 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
546 | e6e5906b | pbrook | gen_op_and32(tmp, QREG_CC_DEST, gen_im32(CCF_V)); |
547 | e6e5906b | pbrook | gen_op_jmp_z32(tmp, l1); |
548 | e6e5906b | pbrook | break;
|
549 | e6e5906b | pbrook | case 9: /* VS (V) */ |
550 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
551 | e6e5906b | pbrook | gen_op_and32(tmp, QREG_CC_DEST, gen_im32(CCF_V)); |
552 | e6e5906b | pbrook | gen_op_jmp_nz32(tmp, l1); |
553 | e6e5906b | pbrook | break;
|
554 | e6e5906b | pbrook | case 10: /* PL (!N) */ |
555 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
556 | e6e5906b | pbrook | gen_op_and32(tmp, QREG_CC_DEST, gen_im32(CCF_N)); |
557 | e6e5906b | pbrook | gen_op_jmp_z32(tmp, l1); |
558 | e6e5906b | pbrook | break;
|
559 | e6e5906b | pbrook | case 11: /* MI (N) */ |
560 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
561 | e6e5906b | pbrook | gen_op_and32(tmp, QREG_CC_DEST, gen_im32(CCF_N)); |
562 | e6e5906b | pbrook | gen_op_jmp_nz32(tmp, l1); |
563 | e6e5906b | pbrook | break;
|
564 | e6e5906b | pbrook | case 12: /* GE (!(N ^ V)) */ |
565 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
566 | e6e5906b | pbrook | gen_op_shr32(tmp, QREG_CC_DEST, gen_im32(2));
|
567 | e6e5906b | pbrook | gen_op_xor32(tmp, tmp, QREG_CC_DEST); |
568 | e6e5906b | pbrook | gen_op_and32(tmp, tmp, gen_im32(CCF_V)); |
569 | e6e5906b | pbrook | gen_op_jmp_z32(tmp, l1); |
570 | e6e5906b | pbrook | break;
|
571 | e6e5906b | pbrook | case 13: /* LT (N ^ V) */ |
572 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
573 | e6e5906b | pbrook | gen_op_shr32(tmp, QREG_CC_DEST, gen_im32(2));
|
574 | e6e5906b | pbrook | gen_op_xor32(tmp, tmp, QREG_CC_DEST); |
575 | e6e5906b | pbrook | gen_op_and32(tmp, tmp, gen_im32(CCF_V)); |
576 | e6e5906b | pbrook | gen_op_jmp_nz32(tmp, l1); |
577 | e6e5906b | pbrook | break;
|
578 | e6e5906b | pbrook | case 14: /* GT (!(Z || (N ^ V))) */ |
579 | e6e5906b | pbrook | { |
580 | e6e5906b | pbrook | int l2;
|
581 | e6e5906b | pbrook | l2 = gen_new_label(); |
582 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
583 | e6e5906b | pbrook | gen_op_and32(tmp, QREG_CC_DEST, gen_im32(CCF_Z)); |
584 | e6e5906b | pbrook | gen_op_jmp_nz32(tmp, l2); |
585 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
586 | e6e5906b | pbrook | gen_op_shr32(tmp, QREG_CC_DEST, gen_im32(2));
|
587 | e6e5906b | pbrook | gen_op_xor32(tmp, tmp, QREG_CC_DEST); |
588 | e6e5906b | pbrook | gen_op_and32(tmp, tmp, gen_im32(CCF_V)); |
589 | e6e5906b | pbrook | gen_op_jmp_nz32(tmp, l2); |
590 | e6e5906b | pbrook | gen_op_jmp(l1); |
591 | e6e5906b | pbrook | gen_set_label(l2); |
592 | e6e5906b | pbrook | } |
593 | e6e5906b | pbrook | break;
|
594 | e6e5906b | pbrook | case 15: /* LE (Z || (N ^ V)) */ |
595 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
596 | e6e5906b | pbrook | gen_op_and32(tmp, QREG_CC_DEST, gen_im32(CCF_Z)); |
597 | e6e5906b | pbrook | gen_op_jmp_nz32(tmp, l1); |
598 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
599 | e6e5906b | pbrook | gen_op_shr32(tmp, QREG_CC_DEST, gen_im32(2));
|
600 | e6e5906b | pbrook | gen_op_xor32(tmp, tmp, QREG_CC_DEST); |
601 | e6e5906b | pbrook | gen_op_and32(tmp, tmp, gen_im32(CCF_V)); |
602 | e6e5906b | pbrook | gen_op_jmp_nz32(tmp, l1); |
603 | e6e5906b | pbrook | break;
|
604 | e6e5906b | pbrook | default:
|
605 | e6e5906b | pbrook | /* Should ever happen. */
|
606 | e6e5906b | pbrook | abort(); |
607 | e6e5906b | pbrook | } |
608 | e6e5906b | pbrook | } |
609 | e6e5906b | pbrook | |
610 | e6e5906b | pbrook | DISAS_INSN(scc) |
611 | e6e5906b | pbrook | { |
612 | e6e5906b | pbrook | int l1;
|
613 | e6e5906b | pbrook | int cond;
|
614 | e6e5906b | pbrook | int reg;
|
615 | e6e5906b | pbrook | |
616 | e6e5906b | pbrook | l1 = gen_new_label(); |
617 | e6e5906b | pbrook | cond = (insn >> 8) & 0xf; |
618 | e6e5906b | pbrook | reg = DREG(insn, 0);
|
619 | e6e5906b | pbrook | gen_op_and32(reg, reg, gen_im32(0xffffff00));
|
620 | e6e5906b | pbrook | gen_jmpcc(s, cond ^ 1, l1);
|
621 | e6e5906b | pbrook | gen_op_or32(reg, reg, gen_im32(0xff));
|
622 | e6e5906b | pbrook | gen_set_label(l1); |
623 | e6e5906b | pbrook | } |
624 | e6e5906b | pbrook | |
625 | e6e5906b | pbrook | /* Generate a jump to to the address in qreg DEST. */
|
626 | e6e5906b | pbrook | static void gen_jmp(DisasContext *s, int dest) |
627 | e6e5906b | pbrook | { |
628 | e6e5906b | pbrook | gen_flush_cc_op(s); |
629 | e6e5906b | pbrook | gen_op_mov32(QREG_PC, dest); |
630 | e6e5906b | pbrook | s->is_jmp = DISAS_JUMP; |
631 | e6e5906b | pbrook | } |
632 | e6e5906b | pbrook | |
633 | e6e5906b | pbrook | static void gen_exception(DisasContext *s, uint32_t where, int nr) |
634 | e6e5906b | pbrook | { |
635 | e6e5906b | pbrook | gen_flush_cc_op(s); |
636 | e6e5906b | pbrook | gen_jmp(s, gen_im32(where)); |
637 | e6e5906b | pbrook | gen_op_raise_exception(nr); |
638 | e6e5906b | pbrook | } |
639 | e6e5906b | pbrook | |
640 | e6e5906b | pbrook | /* Generate a jump to an immediate address. */
|
641 | e6e5906b | pbrook | static void gen_jmp_tb(DisasContext *s, int n, uint32_t dest) |
642 | e6e5906b | pbrook | { |
643 | e6e5906b | pbrook | TranslationBlock *tb; |
644 | e6e5906b | pbrook | |
645 | e6e5906b | pbrook | tb = s->tb; |
646 | e6e5906b | pbrook | if (__builtin_expect (s->singlestep_enabled, 0)) { |
647 | e6e5906b | pbrook | gen_exception(s, dest, EXCP_DEBUG); |
648 | e6e5906b | pbrook | } else if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) || |
649 | e6e5906b | pbrook | (s->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) { |
650 | e6e5906b | pbrook | gen_op_goto_tb(0, n, (long)tb); |
651 | e6e5906b | pbrook | gen_op_mov32(QREG_PC, gen_im32(dest)); |
652 | e6e5906b | pbrook | gen_op_mov32(QREG_T0, gen_im32((long)tb + n));
|
653 | e6e5906b | pbrook | gen_op_exit_tb(); |
654 | e6e5906b | pbrook | } else {
|
655 | e6e5906b | pbrook | gen_jmp(s, gen_im32(dest)); |
656 | e6e5906b | pbrook | gen_op_mov32(QREG_T0, gen_im32(0));
|
657 | e6e5906b | pbrook | gen_op_exit_tb(); |
658 | e6e5906b | pbrook | } |
659 | e6e5906b | pbrook | s->is_jmp = DISAS_TB_JUMP; |
660 | e6e5906b | pbrook | } |
661 | e6e5906b | pbrook | |
662 | e6e5906b | pbrook | DISAS_INSN(undef_mac) |
663 | e6e5906b | pbrook | { |
664 | e6e5906b | pbrook | gen_exception(s, s->pc - 2, EXCP_LINEA);
|
665 | e6e5906b | pbrook | } |
666 | e6e5906b | pbrook | |
667 | e6e5906b | pbrook | DISAS_INSN(undef_fpu) |
668 | e6e5906b | pbrook | { |
669 | e6e5906b | pbrook | gen_exception(s, s->pc - 2, EXCP_LINEF);
|
670 | e6e5906b | pbrook | } |
671 | e6e5906b | pbrook | |
672 | e6e5906b | pbrook | DISAS_INSN(undef) |
673 | e6e5906b | pbrook | { |
674 | e6e5906b | pbrook | gen_exception(s, s->pc - 2, EXCP_UNSUPPORTED);
|
675 | e6e5906b | pbrook | cpu_abort(cpu_single_env, "Illegal instruction: %04x @ %08x",
|
676 | e6e5906b | pbrook | insn, s->pc - 2);
|
677 | e6e5906b | pbrook | } |
678 | e6e5906b | pbrook | |
679 | e6e5906b | pbrook | DISAS_INSN(mulw) |
680 | e6e5906b | pbrook | { |
681 | e6e5906b | pbrook | int reg;
|
682 | e6e5906b | pbrook | int tmp;
|
683 | e6e5906b | pbrook | int src;
|
684 | e6e5906b | pbrook | int sign;
|
685 | e6e5906b | pbrook | |
686 | e6e5906b | pbrook | sign = (insn & 0x100) != 0; |
687 | e6e5906b | pbrook | reg = DREG(insn, 9);
|
688 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
689 | e6e5906b | pbrook | if (sign)
|
690 | e6e5906b | pbrook | gen_op_ext16s32(tmp, reg); |
691 | e6e5906b | pbrook | else
|
692 | e6e5906b | pbrook | gen_op_ext16u32(tmp, reg); |
693 | e6e5906b | pbrook | src = gen_ea(s, insn, OS_WORD, sign ? -1 : 0, NULL); |
694 | e6e5906b | pbrook | gen_op_mul32(tmp, tmp, src); |
695 | e6e5906b | pbrook | gen_op_mov32(reg, tmp); |
696 | e6e5906b | pbrook | /* Unlike m68k, coldfire always clears the overflow bit. */
|
697 | e6e5906b | pbrook | gen_logic_cc(s, tmp); |
698 | e6e5906b | pbrook | } |
699 | e6e5906b | pbrook | |
700 | e6e5906b | pbrook | DISAS_INSN(divw) |
701 | e6e5906b | pbrook | { |
702 | e6e5906b | pbrook | int reg;
|
703 | e6e5906b | pbrook | int tmp;
|
704 | e6e5906b | pbrook | int src;
|
705 | e6e5906b | pbrook | int sign;
|
706 | e6e5906b | pbrook | |
707 | e6e5906b | pbrook | sign = (insn & 0x100) != 0; |
708 | e6e5906b | pbrook | reg = DREG(insn, 9);
|
709 | e6e5906b | pbrook | if (sign) {
|
710 | e6e5906b | pbrook | gen_op_ext16s32(QREG_DIV1, reg); |
711 | e6e5906b | pbrook | } else {
|
712 | e6e5906b | pbrook | gen_op_ext16u32(QREG_DIV1, reg); |
713 | e6e5906b | pbrook | } |
714 | e6e5906b | pbrook | src = gen_ea(s, insn, OS_WORD, sign ? -1 : 0, NULL); |
715 | e6e5906b | pbrook | gen_op_mov32(QREG_DIV2, src); |
716 | e6e5906b | pbrook | if (sign) {
|
717 | e6e5906b | pbrook | gen_op_divs(1);
|
718 | e6e5906b | pbrook | } else {
|
719 | e6e5906b | pbrook | gen_op_divu(1);
|
720 | e6e5906b | pbrook | } |
721 | e6e5906b | pbrook | |
722 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
723 | e6e5906b | pbrook | src = gen_new_qreg(QMODE_I32); |
724 | e6e5906b | pbrook | gen_op_ext16u32(tmp, QREG_DIV1); |
725 | e6e5906b | pbrook | gen_op_shl32(src, QREG_DIV2, gen_im32(16));
|
726 | e6e5906b | pbrook | gen_op_or32(reg, tmp, src); |
727 | e6e5906b | pbrook | gen_op_flags_set(); |
728 | e6e5906b | pbrook | s->cc_op = CC_OP_FLAGS; |
729 | e6e5906b | pbrook | } |
730 | e6e5906b | pbrook | |
731 | e6e5906b | pbrook | DISAS_INSN(divl) |
732 | e6e5906b | pbrook | { |
733 | e6e5906b | pbrook | int num;
|
734 | e6e5906b | pbrook | int den;
|
735 | e6e5906b | pbrook | int reg;
|
736 | e6e5906b | pbrook | uint16_t ext; |
737 | e6e5906b | pbrook | |
738 | e6e5906b | pbrook | ext = lduw(s->pc); |
739 | e6e5906b | pbrook | s->pc += 2;
|
740 | e6e5906b | pbrook | if (ext & 0x87f8) { |
741 | e6e5906b | pbrook | gen_exception(s, s->pc - 4, EXCP_UNSUPPORTED);
|
742 | e6e5906b | pbrook | return;
|
743 | e6e5906b | pbrook | } |
744 | e6e5906b | pbrook | num = DREG(ext, 12);
|
745 | e6e5906b | pbrook | reg = DREG(ext, 0);
|
746 | e6e5906b | pbrook | gen_op_mov32(QREG_DIV1, num); |
747 | e6e5906b | pbrook | den = gen_ea(s, insn, OS_LONG, 0, NULL); |
748 | e6e5906b | pbrook | gen_op_mov32(QREG_DIV2, den); |
749 | e6e5906b | pbrook | if (ext & 0x0800) { |
750 | 2d37be61 | pbrook | gen_op_divs(2);
|
751 | e6e5906b | pbrook | } else {
|
752 | 2d37be61 | pbrook | gen_op_divu(2);
|
753 | e6e5906b | pbrook | } |
754 | e6e5906b | pbrook | if (num == reg) {
|
755 | e6e5906b | pbrook | /* div */
|
756 | e6e5906b | pbrook | gen_op_mov32 (reg, QREG_DIV1); |
757 | e6e5906b | pbrook | } else {
|
758 | e6e5906b | pbrook | /* rem */
|
759 | e6e5906b | pbrook | gen_op_mov32 (reg, QREG_DIV2); |
760 | e6e5906b | pbrook | } |
761 | e6e5906b | pbrook | gen_op_flags_set(); |
762 | e6e5906b | pbrook | s->cc_op = CC_OP_FLAGS; |
763 | e6e5906b | pbrook | } |
764 | e6e5906b | pbrook | |
765 | e6e5906b | pbrook | DISAS_INSN(addsub) |
766 | e6e5906b | pbrook | { |
767 | e6e5906b | pbrook | int reg;
|
768 | e6e5906b | pbrook | int dest;
|
769 | e6e5906b | pbrook | int src;
|
770 | e6e5906b | pbrook | int tmp;
|
771 | e6e5906b | pbrook | int addr;
|
772 | e6e5906b | pbrook | int add;
|
773 | e6e5906b | pbrook | |
774 | e6e5906b | pbrook | add = (insn & 0x4000) != 0; |
775 | e6e5906b | pbrook | reg = DREG(insn, 9);
|
776 | e6e5906b | pbrook | dest = gen_new_qreg(QMODE_I32); |
777 | e6e5906b | pbrook | if (insn & 0x100) { |
778 | e6e5906b | pbrook | tmp = gen_ea(s, insn, OS_LONG, 0, &addr);
|
779 | e6e5906b | pbrook | src = reg; |
780 | e6e5906b | pbrook | } else {
|
781 | e6e5906b | pbrook | tmp = reg; |
782 | e6e5906b | pbrook | src = gen_ea(s, insn, OS_LONG, 0, NULL); |
783 | e6e5906b | pbrook | } |
784 | e6e5906b | pbrook | if (add) {
|
785 | e6e5906b | pbrook | gen_op_add32(dest, tmp, src); |
786 | e6e5906b | pbrook | gen_op_update_xflag_lt(dest, src); |
787 | e6e5906b | pbrook | s->cc_op = CC_OP_ADD; |
788 | e6e5906b | pbrook | } else {
|
789 | e6e5906b | pbrook | gen_op_update_xflag_lt(tmp, src); |
790 | e6e5906b | pbrook | gen_op_sub32(dest, tmp, src); |
791 | e6e5906b | pbrook | s->cc_op = CC_OP_SUB; |
792 | e6e5906b | pbrook | } |
793 | e6e5906b | pbrook | gen_op_update_cc_add(dest, src); |
794 | e6e5906b | pbrook | if (insn & 0x100) { |
795 | e6e5906b | pbrook | gen_ea(s, insn, OS_LONG, dest, &addr); |
796 | e6e5906b | pbrook | } else {
|
797 | e6e5906b | pbrook | gen_op_mov32(reg, dest); |
798 | e6e5906b | pbrook | } |
799 | e6e5906b | pbrook | } |
800 | e6e5906b | pbrook | |
801 | e6e5906b | pbrook | |
802 | e6e5906b | pbrook | /* Reverse the order of the bits in REG. */
|
803 | e6e5906b | pbrook | DISAS_INSN(bitrev) |
804 | e6e5906b | pbrook | { |
805 | e6e5906b | pbrook | int val;
|
806 | e6e5906b | pbrook | int tmp1;
|
807 | e6e5906b | pbrook | int tmp2;
|
808 | e6e5906b | pbrook | int reg;
|
809 | e6e5906b | pbrook | |
810 | e6e5906b | pbrook | val = gen_new_qreg(QMODE_I32); |
811 | e6e5906b | pbrook | tmp1 = gen_new_qreg(QMODE_I32); |
812 | e6e5906b | pbrook | tmp2 = gen_new_qreg(QMODE_I32); |
813 | e6e5906b | pbrook | reg = DREG(insn, 0);
|
814 | e6e5906b | pbrook | gen_op_mov32(val, reg); |
815 | e6e5906b | pbrook | /* Reverse bits within each nibble. */
|
816 | e6e5906b | pbrook | gen_op_shl32(tmp1, val, gen_im32(3));
|
817 | e6e5906b | pbrook | gen_op_and32(tmp1, tmp1, gen_im32(0x88888888));
|
818 | e6e5906b | pbrook | gen_op_shl32(tmp2, val, gen_im32(1));
|
819 | e6e5906b | pbrook | gen_op_and32(tmp2, tmp2, gen_im32(0x44444444));
|
820 | e6e5906b | pbrook | gen_op_or32(tmp1, tmp1, tmp2); |
821 | e6e5906b | pbrook | gen_op_shr32(tmp2, val, gen_im32(1));
|
822 | e6e5906b | pbrook | gen_op_and32(tmp2, tmp2, gen_im32(0x22222222));
|
823 | e6e5906b | pbrook | gen_op_or32(tmp1, tmp1, tmp2); |
824 | e6e5906b | pbrook | gen_op_shr32(tmp2, val, gen_im32(3));
|
825 | e6e5906b | pbrook | gen_op_and32(tmp2, tmp2, gen_im32(0x11111111));
|
826 | e6e5906b | pbrook | gen_op_or32(tmp1, tmp1, tmp2); |
827 | e6e5906b | pbrook | /* Reverse nibbles withing bytes. */
|
828 | e6e5906b | pbrook | gen_op_shl32(val, tmp1, gen_im32(4));
|
829 | e6e5906b | pbrook | gen_op_and32(val, val, gen_im32(0xf0f0f0f0));
|
830 | e6e5906b | pbrook | gen_op_shr32(tmp2, tmp1, gen_im32(4));
|
831 | e6e5906b | pbrook | gen_op_and32(tmp2, tmp2, gen_im32(0x0f0f0f0f));
|
832 | e6e5906b | pbrook | gen_op_or32(val, val, tmp2); |
833 | e6e5906b | pbrook | /* Reverse bytes. */
|
834 | e6e5906b | pbrook | gen_op_bswap32(reg, val); |
835 | e6e5906b | pbrook | gen_op_mov32(reg, val); |
836 | e6e5906b | pbrook | } |
837 | e6e5906b | pbrook | |
838 | e6e5906b | pbrook | DISAS_INSN(bitop_reg) |
839 | e6e5906b | pbrook | { |
840 | e6e5906b | pbrook | int opsize;
|
841 | e6e5906b | pbrook | int op;
|
842 | e6e5906b | pbrook | int src1;
|
843 | e6e5906b | pbrook | int src2;
|
844 | e6e5906b | pbrook | int tmp;
|
845 | e6e5906b | pbrook | int addr;
|
846 | e6e5906b | pbrook | int dest;
|
847 | e6e5906b | pbrook | |
848 | e6e5906b | pbrook | if ((insn & 0x38) != 0) |
849 | e6e5906b | pbrook | opsize = OS_BYTE; |
850 | e6e5906b | pbrook | else
|
851 | e6e5906b | pbrook | opsize = OS_LONG; |
852 | e6e5906b | pbrook | op = (insn >> 6) & 3; |
853 | e6e5906b | pbrook | src1 = gen_ea(s, insn, opsize, 0, op ? &addr: NULL); |
854 | e6e5906b | pbrook | src2 = DREG(insn, 9);
|
855 | e6e5906b | pbrook | dest = gen_new_qreg(QMODE_I32); |
856 | e6e5906b | pbrook | |
857 | e6e5906b | pbrook | gen_flush_flags(s); |
858 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
859 | e6e5906b | pbrook | if (opsize == OS_BYTE)
|
860 | e6e5906b | pbrook | gen_op_and32(tmp, src2, gen_im32(7));
|
861 | e6e5906b | pbrook | else
|
862 | e6e5906b | pbrook | gen_op_and32(tmp, src2, gen_im32(31));
|
863 | e6e5906b | pbrook | src2 = tmp; |
864 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
865 | e6e5906b | pbrook | gen_op_shl32(tmp, gen_im32(1), src2);
|
866 | e6e5906b | pbrook | |
867 | e6e5906b | pbrook | gen_op_btest(src1, tmp); |
868 | e6e5906b | pbrook | switch (op) {
|
869 | e6e5906b | pbrook | case 1: /* bchg */ |
870 | e6e5906b | pbrook | gen_op_xor32(dest, src1, tmp); |
871 | e6e5906b | pbrook | break;
|
872 | e6e5906b | pbrook | case 2: /* bclr */ |
873 | e6e5906b | pbrook | gen_op_not32(tmp, tmp); |
874 | e6e5906b | pbrook | gen_op_and32(dest, src1, tmp); |
875 | e6e5906b | pbrook | break;
|
876 | e6e5906b | pbrook | case 3: /* bset */ |
877 | e6e5906b | pbrook | gen_op_or32(dest, src1, tmp); |
878 | e6e5906b | pbrook | break;
|
879 | e6e5906b | pbrook | default: /* btst */ |
880 | e6e5906b | pbrook | break;
|
881 | e6e5906b | pbrook | } |
882 | e6e5906b | pbrook | if (op)
|
883 | e6e5906b | pbrook | gen_ea(s, insn, opsize, dest, &addr); |
884 | e6e5906b | pbrook | } |
885 | e6e5906b | pbrook | |
886 | e6e5906b | pbrook | DISAS_INSN(sats) |
887 | e6e5906b | pbrook | { |
888 | e6e5906b | pbrook | int reg;
|
889 | e6e5906b | pbrook | int tmp;
|
890 | e6e5906b | pbrook | int l1;
|
891 | e6e5906b | pbrook | |
892 | e6e5906b | pbrook | reg = DREG(insn, 0);
|
893 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
894 | e6e5906b | pbrook | gen_flush_flags(s); |
895 | e6e5906b | pbrook | gen_op_and32(tmp, QREG_CC_DEST, gen_im32(CCF_V)); |
896 | e6e5906b | pbrook | l1 = gen_new_label(); |
897 | e6e5906b | pbrook | gen_op_jmp_z32(tmp, l1); |
898 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
899 | e6e5906b | pbrook | gen_op_shr32(tmp, reg, gen_im32(31));
|
900 | e6e5906b | pbrook | gen_op_xor32(tmp, tmp, gen_im32(0x80000000));
|
901 | e6e5906b | pbrook | gen_op_mov32(reg, tmp); |
902 | e6e5906b | pbrook | gen_set_label(l1); |
903 | e6e5906b | pbrook | gen_logic_cc(s, tmp); |
904 | e6e5906b | pbrook | } |
905 | e6e5906b | pbrook | |
906 | e6e5906b | pbrook | static void gen_push(int val) |
907 | e6e5906b | pbrook | { |
908 | e6e5906b | pbrook | int tmp;
|
909 | e6e5906b | pbrook | |
910 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
911 | e6e5906b | pbrook | gen_op_sub32(tmp, QREG_SP, gen_im32(4));
|
912 | e6e5906b | pbrook | gen_store(OS_LONG, tmp, val); |
913 | e6e5906b | pbrook | gen_op_mov32(QREG_SP, tmp); |
914 | e6e5906b | pbrook | } |
915 | e6e5906b | pbrook | |
916 | e6e5906b | pbrook | DISAS_INSN(movem) |
917 | e6e5906b | pbrook | { |
918 | e6e5906b | pbrook | int addr;
|
919 | e6e5906b | pbrook | int i;
|
920 | e6e5906b | pbrook | uint16_t mask; |
921 | e6e5906b | pbrook | int reg;
|
922 | e6e5906b | pbrook | int tmp;
|
923 | e6e5906b | pbrook | int is_load;
|
924 | e6e5906b | pbrook | |
925 | e6e5906b | pbrook | mask = lduw(s->pc); |
926 | e6e5906b | pbrook | s->pc += 2;
|
927 | e6e5906b | pbrook | tmp = gen_lea(s, insn, OS_LONG); |
928 | e6e5906b | pbrook | addr = gen_new_qreg(QMODE_I32); |
929 | e6e5906b | pbrook | gen_op_mov32(addr, tmp); |
930 | e6e5906b | pbrook | is_load = ((insn & 0x0400) != 0); |
931 | e6e5906b | pbrook | for (i = 0; i < 16; i++, mask >>= 1) { |
932 | e6e5906b | pbrook | if (mask & 1) { |
933 | e6e5906b | pbrook | if (i < 8) |
934 | e6e5906b | pbrook | reg = DREG(i, 0);
|
935 | e6e5906b | pbrook | else
|
936 | e6e5906b | pbrook | reg = AREG(i, 0);
|
937 | e6e5906b | pbrook | if (is_load) {
|
938 | e6e5906b | pbrook | tmp = gen_load(OS_LONG, addr, 0);
|
939 | e6e5906b | pbrook | gen_op_mov32(reg, tmp); |
940 | e6e5906b | pbrook | } else {
|
941 | e6e5906b | pbrook | gen_store(OS_LONG, addr, reg); |
942 | e6e5906b | pbrook | } |
943 | e6e5906b | pbrook | if (mask != 1) |
944 | e6e5906b | pbrook | gen_op_add32(addr, addr, gen_im32(4));
|
945 | e6e5906b | pbrook | } |
946 | e6e5906b | pbrook | } |
947 | e6e5906b | pbrook | } |
948 | e6e5906b | pbrook | |
949 | e6e5906b | pbrook | DISAS_INSN(bitop_im) |
950 | e6e5906b | pbrook | { |
951 | e6e5906b | pbrook | int opsize;
|
952 | e6e5906b | pbrook | int op;
|
953 | e6e5906b | pbrook | int src1;
|
954 | e6e5906b | pbrook | uint32_t mask; |
955 | e6e5906b | pbrook | int bitnum;
|
956 | e6e5906b | pbrook | int tmp;
|
957 | e6e5906b | pbrook | int addr;
|
958 | e6e5906b | pbrook | int dest;
|
959 | e6e5906b | pbrook | |
960 | e6e5906b | pbrook | if ((insn & 0x38) != 0) |
961 | e6e5906b | pbrook | opsize = OS_BYTE; |
962 | e6e5906b | pbrook | else
|
963 | e6e5906b | pbrook | opsize = OS_LONG; |
964 | e6e5906b | pbrook | op = (insn >> 6) & 3; |
965 | e6e5906b | pbrook | |
966 | e6e5906b | pbrook | bitnum = lduw(s->pc); |
967 | e6e5906b | pbrook | s->pc += 2;
|
968 | e6e5906b | pbrook | if (bitnum & 0xff00) { |
969 | e6e5906b | pbrook | disas_undef(s, insn); |
970 | e6e5906b | pbrook | return;
|
971 | e6e5906b | pbrook | } |
972 | e6e5906b | pbrook | |
973 | e6e5906b | pbrook | src1 = gen_ea(s, insn, opsize, 0, op ? &addr: NULL); |
974 | e6e5906b | pbrook | |
975 | e6e5906b | pbrook | gen_flush_flags(s); |
976 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
977 | e6e5906b | pbrook | if (opsize == OS_BYTE)
|
978 | e6e5906b | pbrook | bitnum &= 7;
|
979 | e6e5906b | pbrook | else
|
980 | e6e5906b | pbrook | bitnum &= 31;
|
981 | e6e5906b | pbrook | mask = 1 << bitnum;
|
982 | e6e5906b | pbrook | |
983 | e6e5906b | pbrook | gen_op_btest(src1, gen_im32(mask)); |
984 | e6e5906b | pbrook | if (op)
|
985 | e6e5906b | pbrook | dest = gen_new_qreg(QMODE_I32); |
986 | e6e5906b | pbrook | else
|
987 | e6e5906b | pbrook | dest = -1;
|
988 | e6e5906b | pbrook | |
989 | e6e5906b | pbrook | switch (op) {
|
990 | e6e5906b | pbrook | case 1: /* bchg */ |
991 | e6e5906b | pbrook | gen_op_xor32(dest, src1, gen_im32(mask)); |
992 | e6e5906b | pbrook | break;
|
993 | e6e5906b | pbrook | case 2: /* bclr */ |
994 | e6e5906b | pbrook | gen_op_and32(dest, src1, gen_im32(~mask)); |
995 | e6e5906b | pbrook | break;
|
996 | e6e5906b | pbrook | case 3: /* bset */ |
997 | e6e5906b | pbrook | gen_op_or32(dest, src1, gen_im32(mask)); |
998 | e6e5906b | pbrook | break;
|
999 | e6e5906b | pbrook | default: /* btst */ |
1000 | e6e5906b | pbrook | break;
|
1001 | e6e5906b | pbrook | } |
1002 | e6e5906b | pbrook | if (op)
|
1003 | e6e5906b | pbrook | gen_ea(s, insn, opsize, dest, &addr); |
1004 | e6e5906b | pbrook | } |
1005 | e6e5906b | pbrook | |
1006 | e6e5906b | pbrook | DISAS_INSN(arith_im) |
1007 | e6e5906b | pbrook | { |
1008 | e6e5906b | pbrook | int op;
|
1009 | e6e5906b | pbrook | int src1;
|
1010 | e6e5906b | pbrook | int dest;
|
1011 | e6e5906b | pbrook | int src2;
|
1012 | e6e5906b | pbrook | int addr;
|
1013 | e6e5906b | pbrook | |
1014 | e6e5906b | pbrook | op = (insn >> 9) & 7; |
1015 | e6e5906b | pbrook | src1 = gen_ea(s, insn, OS_LONG, 0, (op == 6) ? NULL : &addr); |
1016 | e6e5906b | pbrook | src2 = gen_im32(read_im32(s)); |
1017 | e6e5906b | pbrook | dest = gen_new_qreg(QMODE_I32); |
1018 | e6e5906b | pbrook | switch (op) {
|
1019 | e6e5906b | pbrook | case 0: /* ori */ |
1020 | e6e5906b | pbrook | gen_op_or32(dest, src1, src2); |
1021 | e6e5906b | pbrook | gen_logic_cc(s, dest); |
1022 | e6e5906b | pbrook | break;
|
1023 | e6e5906b | pbrook | case 1: /* andi */ |
1024 | e6e5906b | pbrook | gen_op_and32(dest, src1, src2); |
1025 | e6e5906b | pbrook | gen_logic_cc(s, dest); |
1026 | e6e5906b | pbrook | break;
|
1027 | e6e5906b | pbrook | case 2: /* subi */ |
1028 | e6e5906b | pbrook | gen_op_mov32(dest, src1); |
1029 | e6e5906b | pbrook | gen_op_update_xflag_lt(dest, src2); |
1030 | e6e5906b | pbrook | gen_op_sub32(dest, dest, src2); |
1031 | e6e5906b | pbrook | gen_op_update_cc_add(dest, src2); |
1032 | e6e5906b | pbrook | s->cc_op = CC_OP_SUB; |
1033 | e6e5906b | pbrook | break;
|
1034 | e6e5906b | pbrook | case 3: /* addi */ |
1035 | e6e5906b | pbrook | gen_op_mov32(dest, src1); |
1036 | e6e5906b | pbrook | gen_op_add32(dest, dest, src2); |
1037 | e6e5906b | pbrook | gen_op_update_cc_add(dest, src2); |
1038 | e6e5906b | pbrook | gen_op_update_xflag_lt(dest, src2); |
1039 | e6e5906b | pbrook | s->cc_op = CC_OP_ADD; |
1040 | e6e5906b | pbrook | break;
|
1041 | e6e5906b | pbrook | case 5: /* eori */ |
1042 | e6e5906b | pbrook | gen_op_xor32(dest, src1, src2); |
1043 | e6e5906b | pbrook | gen_logic_cc(s, dest); |
1044 | e6e5906b | pbrook | break;
|
1045 | e6e5906b | pbrook | case 6: /* cmpi */ |
1046 | e6e5906b | pbrook | gen_op_mov32(dest, src1); |
1047 | e6e5906b | pbrook | gen_op_sub32(dest, dest, src2); |
1048 | e6e5906b | pbrook | gen_op_update_cc_add(dest, src2); |
1049 | e6e5906b | pbrook | s->cc_op = CC_OP_SUB; |
1050 | e6e5906b | pbrook | break;
|
1051 | e6e5906b | pbrook | default:
|
1052 | e6e5906b | pbrook | abort(); |
1053 | e6e5906b | pbrook | } |
1054 | e6e5906b | pbrook | if (op != 6) { |
1055 | e6e5906b | pbrook | gen_ea(s, insn, OS_LONG, dest, &addr); |
1056 | e6e5906b | pbrook | } |
1057 | e6e5906b | pbrook | } |
1058 | e6e5906b | pbrook | |
1059 | e6e5906b | pbrook | DISAS_INSN(byterev) |
1060 | e6e5906b | pbrook | { |
1061 | e6e5906b | pbrook | int reg;
|
1062 | e6e5906b | pbrook | |
1063 | e6e5906b | pbrook | reg = DREG(insn, 0);
|
1064 | e6e5906b | pbrook | gen_op_bswap32(reg, reg); |
1065 | e6e5906b | pbrook | } |
1066 | e6e5906b | pbrook | |
1067 | e6e5906b | pbrook | DISAS_INSN(move) |
1068 | e6e5906b | pbrook | { |
1069 | e6e5906b | pbrook | int src;
|
1070 | e6e5906b | pbrook | int dest;
|
1071 | e6e5906b | pbrook | int op;
|
1072 | e6e5906b | pbrook | int opsize;
|
1073 | e6e5906b | pbrook | |
1074 | e6e5906b | pbrook | switch (insn >> 12) { |
1075 | e6e5906b | pbrook | case 1: /* move.b */ |
1076 | e6e5906b | pbrook | opsize = OS_BYTE; |
1077 | e6e5906b | pbrook | break;
|
1078 | e6e5906b | pbrook | case 2: /* move.l */ |
1079 | e6e5906b | pbrook | opsize = OS_LONG; |
1080 | e6e5906b | pbrook | break;
|
1081 | e6e5906b | pbrook | case 3: /* move.w */ |
1082 | e6e5906b | pbrook | opsize = OS_WORD; |
1083 | e6e5906b | pbrook | break;
|
1084 | e6e5906b | pbrook | default:
|
1085 | e6e5906b | pbrook | abort(); |
1086 | e6e5906b | pbrook | } |
1087 | e6e5906b | pbrook | src = gen_ea(s, insn, opsize, -1, NULL); |
1088 | e6e5906b | pbrook | op = (insn >> 6) & 7; |
1089 | e6e5906b | pbrook | if (op == 1) { |
1090 | e6e5906b | pbrook | /* movea */
|
1091 | e6e5906b | pbrook | /* The value will already have been sign extended. */
|
1092 | e6e5906b | pbrook | dest = AREG(insn, 9);
|
1093 | e6e5906b | pbrook | gen_op_mov32(dest, src); |
1094 | e6e5906b | pbrook | } else {
|
1095 | e6e5906b | pbrook | /* normal move */
|
1096 | e6e5906b | pbrook | uint16_t dest_ea; |
1097 | e6e5906b | pbrook | dest_ea = ((insn >> 9) & 7) | (op << 3); |
1098 | e6e5906b | pbrook | gen_ea(s, dest_ea, opsize, src, NULL);
|
1099 | e6e5906b | pbrook | /* This will be correct because loads sign extend. */
|
1100 | e6e5906b | pbrook | gen_logic_cc(s, src); |
1101 | e6e5906b | pbrook | } |
1102 | e6e5906b | pbrook | } |
1103 | e6e5906b | pbrook | |
1104 | e6e5906b | pbrook | DISAS_INSN(negx) |
1105 | e6e5906b | pbrook | { |
1106 | e6e5906b | pbrook | int reg;
|
1107 | e6e5906b | pbrook | int dest;
|
1108 | e6e5906b | pbrook | int tmp;
|
1109 | e6e5906b | pbrook | |
1110 | e6e5906b | pbrook | gen_flush_flags(s); |
1111 | e6e5906b | pbrook | reg = DREG(insn, 0);
|
1112 | e6e5906b | pbrook | dest = gen_new_qreg(QMODE_I32); |
1113 | e6e5906b | pbrook | gen_op_mov32 (dest, gen_im32(0));
|
1114 | e6e5906b | pbrook | gen_op_subx_cc(dest, reg); |
1115 | e6e5906b | pbrook | /* !Z is sticky. */
|
1116 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
1117 | e6e5906b | pbrook | gen_op_mov32 (tmp, QREG_CC_DEST); |
1118 | e6e5906b | pbrook | gen_op_update_cc_add(dest, reg); |
1119 | e6e5906b | pbrook | gen_op_mov32(reg, dest); |
1120 | e6e5906b | pbrook | s->cc_op = CC_OP_DYNAMIC; |
1121 | e6e5906b | pbrook | gen_flush_flags(s); |
1122 | e6e5906b | pbrook | gen_op_or32(tmp, tmp, gen_im32(~CCF_Z)); |
1123 | e6e5906b | pbrook | gen_op_and32(QREG_CC_DEST, QREG_CC_DEST, tmp); |
1124 | e6e5906b | pbrook | s->cc_op = CC_OP_FLAGS; |
1125 | e6e5906b | pbrook | } |
1126 | e6e5906b | pbrook | |
1127 | e6e5906b | pbrook | DISAS_INSN(lea) |
1128 | e6e5906b | pbrook | { |
1129 | e6e5906b | pbrook | int reg;
|
1130 | e6e5906b | pbrook | int tmp;
|
1131 | e6e5906b | pbrook | |
1132 | e6e5906b | pbrook | reg = AREG(insn, 9);
|
1133 | e6e5906b | pbrook | tmp = gen_lea(s, insn, OS_LONG); |
1134 | e6e5906b | pbrook | gen_op_mov32(reg, tmp); |
1135 | e6e5906b | pbrook | } |
1136 | e6e5906b | pbrook | |
1137 | e6e5906b | pbrook | DISAS_INSN(clr) |
1138 | e6e5906b | pbrook | { |
1139 | e6e5906b | pbrook | int opsize;
|
1140 | e6e5906b | pbrook | |
1141 | e6e5906b | pbrook | switch ((insn >> 6) & 3) { |
1142 | e6e5906b | pbrook | case 0: /* clr.b */ |
1143 | e6e5906b | pbrook | opsize = OS_BYTE; |
1144 | e6e5906b | pbrook | break;
|
1145 | e6e5906b | pbrook | case 1: /* clr.w */ |
1146 | e6e5906b | pbrook | opsize = OS_WORD; |
1147 | e6e5906b | pbrook | break;
|
1148 | e6e5906b | pbrook | case 2: /* clr.l */ |
1149 | e6e5906b | pbrook | opsize = OS_LONG; |
1150 | e6e5906b | pbrook | break;
|
1151 | e6e5906b | pbrook | default:
|
1152 | e6e5906b | pbrook | abort(); |
1153 | e6e5906b | pbrook | } |
1154 | e6e5906b | pbrook | gen_ea (s, insn, opsize, gen_im32(0), NULL); |
1155 | e6e5906b | pbrook | gen_logic_cc(s, gen_im32(0));
|
1156 | e6e5906b | pbrook | } |
1157 | e6e5906b | pbrook | |
1158 | e6e5906b | pbrook | DISAS_INSN(move_from_ccr) |
1159 | e6e5906b | pbrook | { |
1160 | e6e5906b | pbrook | int reg;
|
1161 | e6e5906b | pbrook | int dest;
|
1162 | e6e5906b | pbrook | |
1163 | e6e5906b | pbrook | gen_flush_flags(s); |
1164 | e6e5906b | pbrook | dest = gen_new_qreg(QMODE_I32); |
1165 | e6e5906b | pbrook | gen_op_get_xflag(dest); |
1166 | e6e5906b | pbrook | gen_op_shl32(dest, dest, gen_im32(4));
|
1167 | e6e5906b | pbrook | gen_op_or32(dest, dest, QREG_CC_DEST); |
1168 | e6e5906b | pbrook | reg = DREG(insn, 0);
|
1169 | e6e5906b | pbrook | gen_partset_reg(OS_WORD, reg, dest); |
1170 | e6e5906b | pbrook | } |
1171 | e6e5906b | pbrook | |
1172 | e6e5906b | pbrook | DISAS_INSN(neg) |
1173 | e6e5906b | pbrook | { |
1174 | e6e5906b | pbrook | int reg;
|
1175 | e6e5906b | pbrook | int src1;
|
1176 | e6e5906b | pbrook | |
1177 | e6e5906b | pbrook | reg = DREG(insn, 0);
|
1178 | e6e5906b | pbrook | src1 = gen_new_qreg(QMODE_I32); |
1179 | e6e5906b | pbrook | gen_op_mov32(src1, reg); |
1180 | e6e5906b | pbrook | gen_op_neg32(reg, src1); |
1181 | e6e5906b | pbrook | s->cc_op = CC_OP_SUB; |
1182 | e6e5906b | pbrook | gen_op_update_cc_add(reg, src1); |
1183 | e6e5906b | pbrook | gen_op_update_xflag_lt(gen_im32(0), src1);
|
1184 | e6e5906b | pbrook | s->cc_op = CC_OP_SUB; |
1185 | e6e5906b | pbrook | } |
1186 | e6e5906b | pbrook | |
1187 | e6e5906b | pbrook | DISAS_INSN(move_to_ccr) |
1188 | e6e5906b | pbrook | { |
1189 | e6e5906b | pbrook | int src1;
|
1190 | e6e5906b | pbrook | int reg;
|
1191 | e6e5906b | pbrook | |
1192 | e6e5906b | pbrook | s->cc_op = CC_OP_FLAGS; |
1193 | e6e5906b | pbrook | if ((insn & 0x38) == 0) |
1194 | e6e5906b | pbrook | { |
1195 | e6e5906b | pbrook | src1 = gen_new_qreg(QMODE_I32); |
1196 | e6e5906b | pbrook | reg = DREG(insn, 0);
|
1197 | e6e5906b | pbrook | gen_op_and32(src1, reg, gen_im32(0xf));
|
1198 | e6e5906b | pbrook | gen_op_logic_cc(src1); |
1199 | e6e5906b | pbrook | gen_op_shr32(src1, reg, gen_im32(4));
|
1200 | e6e5906b | pbrook | gen_op_and32(src1, src1, gen_im32(1));
|
1201 | e6e5906b | pbrook | gen_op_update_xflag_tst(src1); |
1202 | e6e5906b | pbrook | } |
1203 | e6e5906b | pbrook | else if ((insn & 0x3f) != 0x3c) |
1204 | e6e5906b | pbrook | { |
1205 | e6e5906b | pbrook | uint8_t val; |
1206 | e6e5906b | pbrook | val = ldsb(s->pc); |
1207 | e6e5906b | pbrook | s->pc += 2;
|
1208 | e6e5906b | pbrook | gen_op_logic_cc(gen_im32(val & 0xf));
|
1209 | e6e5906b | pbrook | gen_op_update_xflag_tst(gen_im32((val & 0x10) >> 4)); |
1210 | e6e5906b | pbrook | } |
1211 | e6e5906b | pbrook | else
|
1212 | e6e5906b | pbrook | disas_undef(s, insn); |
1213 | e6e5906b | pbrook | } |
1214 | e6e5906b | pbrook | |
1215 | e6e5906b | pbrook | DISAS_INSN(not) |
1216 | e6e5906b | pbrook | { |
1217 | e6e5906b | pbrook | int reg;
|
1218 | e6e5906b | pbrook | |
1219 | e6e5906b | pbrook | reg = DREG(insn, 0);
|
1220 | e6e5906b | pbrook | gen_op_not32(reg, reg); |
1221 | e6e5906b | pbrook | gen_logic_cc(s, reg); |
1222 | e6e5906b | pbrook | } |
1223 | e6e5906b | pbrook | |
1224 | e6e5906b | pbrook | DISAS_INSN(swap) |
1225 | e6e5906b | pbrook | { |
1226 | e6e5906b | pbrook | int dest;
|
1227 | e6e5906b | pbrook | int src1;
|
1228 | e6e5906b | pbrook | int src2;
|
1229 | e6e5906b | pbrook | int reg;
|
1230 | e6e5906b | pbrook | |
1231 | e6e5906b | pbrook | dest = gen_new_qreg(QMODE_I32); |
1232 | e6e5906b | pbrook | src1 = gen_new_qreg(QMODE_I32); |
1233 | e6e5906b | pbrook | src2 = gen_new_qreg(QMODE_I32); |
1234 | e6e5906b | pbrook | reg = DREG(insn, 0);
|
1235 | e6e5906b | pbrook | gen_op_shl32(src1, reg, gen_im32(16));
|
1236 | e6e5906b | pbrook | gen_op_shr32(src2, reg, gen_im32(16));
|
1237 | e6e5906b | pbrook | gen_op_or32(dest, src1, src2); |
1238 | e6e5906b | pbrook | gen_op_mov32(reg, dest); |
1239 | e6e5906b | pbrook | gen_logic_cc(s, dest); |
1240 | e6e5906b | pbrook | } |
1241 | e6e5906b | pbrook | |
1242 | e6e5906b | pbrook | DISAS_INSN(pea) |
1243 | e6e5906b | pbrook | { |
1244 | e6e5906b | pbrook | int tmp;
|
1245 | e6e5906b | pbrook | |
1246 | e6e5906b | pbrook | tmp = gen_lea(s, insn, OS_LONG); |
1247 | e6e5906b | pbrook | gen_push(tmp); |
1248 | e6e5906b | pbrook | } |
1249 | e6e5906b | pbrook | |
1250 | e6e5906b | pbrook | DISAS_INSN(ext) |
1251 | e6e5906b | pbrook | { |
1252 | e6e5906b | pbrook | int reg;
|
1253 | e6e5906b | pbrook | int op;
|
1254 | e6e5906b | pbrook | int tmp;
|
1255 | e6e5906b | pbrook | |
1256 | e6e5906b | pbrook | reg = DREG(insn, 0);
|
1257 | e6e5906b | pbrook | op = (insn >> 6) & 7; |
1258 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
1259 | e6e5906b | pbrook | if (op == 3) |
1260 | e6e5906b | pbrook | gen_op_ext16s32(tmp, reg); |
1261 | e6e5906b | pbrook | else
|
1262 | e6e5906b | pbrook | gen_op_ext8s32(tmp, reg); |
1263 | e6e5906b | pbrook | if (op == 2) |
1264 | e6e5906b | pbrook | gen_partset_reg(OS_WORD, reg, tmp); |
1265 | e6e5906b | pbrook | else
|
1266 | e6e5906b | pbrook | gen_op_mov32(reg, tmp); |
1267 | e6e5906b | pbrook | gen_logic_cc(s, tmp); |
1268 | e6e5906b | pbrook | } |
1269 | e6e5906b | pbrook | |
1270 | e6e5906b | pbrook | DISAS_INSN(tst) |
1271 | e6e5906b | pbrook | { |
1272 | e6e5906b | pbrook | int opsize;
|
1273 | e6e5906b | pbrook | int tmp;
|
1274 | e6e5906b | pbrook | |
1275 | e6e5906b | pbrook | switch ((insn >> 6) & 3) { |
1276 | e6e5906b | pbrook | case 0: /* tst.b */ |
1277 | e6e5906b | pbrook | opsize = OS_BYTE; |
1278 | e6e5906b | pbrook | break;
|
1279 | e6e5906b | pbrook | case 1: /* tst.w */ |
1280 | e6e5906b | pbrook | opsize = OS_WORD; |
1281 | e6e5906b | pbrook | break;
|
1282 | e6e5906b | pbrook | case 2: /* tst.l */ |
1283 | e6e5906b | pbrook | opsize = OS_LONG; |
1284 | e6e5906b | pbrook | break;
|
1285 | e6e5906b | pbrook | default:
|
1286 | e6e5906b | pbrook | abort(); |
1287 | e6e5906b | pbrook | } |
1288 | e6e5906b | pbrook | tmp = gen_ea(s, insn, opsize, -1, NULL); |
1289 | e6e5906b | pbrook | gen_logic_cc(s, tmp); |
1290 | e6e5906b | pbrook | } |
1291 | e6e5906b | pbrook | |
1292 | e6e5906b | pbrook | DISAS_INSN(pulse) |
1293 | e6e5906b | pbrook | { |
1294 | e6e5906b | pbrook | /* Implemented as a NOP. */
|
1295 | e6e5906b | pbrook | } |
1296 | e6e5906b | pbrook | |
1297 | e6e5906b | pbrook | DISAS_INSN(illegal) |
1298 | e6e5906b | pbrook | { |
1299 | e6e5906b | pbrook | gen_exception(s, s->pc - 2, EXCP_ILLEGAL);
|
1300 | e6e5906b | pbrook | } |
1301 | e6e5906b | pbrook | |
1302 | e6e5906b | pbrook | /* ??? This should be atomic. */
|
1303 | e6e5906b | pbrook | DISAS_INSN(tas) |
1304 | e6e5906b | pbrook | { |
1305 | e6e5906b | pbrook | int dest;
|
1306 | e6e5906b | pbrook | int src1;
|
1307 | e6e5906b | pbrook | int addr;
|
1308 | e6e5906b | pbrook | |
1309 | e6e5906b | pbrook | dest = gen_new_qreg(QMODE_I32); |
1310 | e6e5906b | pbrook | src1 = gen_ea(s, insn, OS_BYTE, -1, &addr);
|
1311 | e6e5906b | pbrook | gen_logic_cc(s, src1); |
1312 | e6e5906b | pbrook | gen_op_or32(dest, src1, gen_im32(0x80));
|
1313 | e6e5906b | pbrook | gen_ea(s, insn, OS_BYTE, dest, &addr); |
1314 | e6e5906b | pbrook | } |
1315 | e6e5906b | pbrook | |
1316 | e6e5906b | pbrook | DISAS_INSN(mull) |
1317 | e6e5906b | pbrook | { |
1318 | e6e5906b | pbrook | uint16_t ext; |
1319 | e6e5906b | pbrook | int reg;
|
1320 | e6e5906b | pbrook | int src1;
|
1321 | e6e5906b | pbrook | int dest;
|
1322 | e6e5906b | pbrook | |
1323 | e6e5906b | pbrook | /* The upper 32 bits of the product are discarded, so
|
1324 | e6e5906b | pbrook | muls.l and mulu.l are functionally equivalent. */
|
1325 | e6e5906b | pbrook | ext = lduw(s->pc); |
1326 | e6e5906b | pbrook | s->pc += 2;
|
1327 | e6e5906b | pbrook | if (ext & 0x87ff) { |
1328 | e6e5906b | pbrook | gen_exception(s, s->pc - 4, EXCP_UNSUPPORTED);
|
1329 | e6e5906b | pbrook | return;
|
1330 | e6e5906b | pbrook | } |
1331 | e6e5906b | pbrook | reg = DREG(ext, 12);
|
1332 | e6e5906b | pbrook | src1 = gen_ea(s, insn, OS_LONG, 0, NULL); |
1333 | e6e5906b | pbrook | dest = gen_new_qreg(QMODE_I32); |
1334 | e6e5906b | pbrook | gen_op_mul32(dest, src1, reg); |
1335 | e6e5906b | pbrook | gen_op_mov32(reg, dest); |
1336 | e6e5906b | pbrook | /* Unlike m68k, coldfire always clears the overflow bit. */
|
1337 | e6e5906b | pbrook | gen_logic_cc(s, dest); |
1338 | e6e5906b | pbrook | } |
1339 | e6e5906b | pbrook | |
1340 | e6e5906b | pbrook | DISAS_INSN(link) |
1341 | e6e5906b | pbrook | { |
1342 | e6e5906b | pbrook | int16_t offset; |
1343 | e6e5906b | pbrook | int reg;
|
1344 | e6e5906b | pbrook | int tmp;
|
1345 | e6e5906b | pbrook | |
1346 | e6e5906b | pbrook | offset = ldsw(s->pc); |
1347 | e6e5906b | pbrook | s->pc += 2;
|
1348 | e6e5906b | pbrook | reg = AREG(insn, 0);
|
1349 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
1350 | e6e5906b | pbrook | gen_op_sub32(tmp, QREG_SP, gen_im32(4));
|
1351 | e6e5906b | pbrook | gen_store(OS_LONG, tmp, reg); |
1352 | e6e5906b | pbrook | if (reg != QREG_SP)
|
1353 | e6e5906b | pbrook | gen_op_mov32(reg, tmp); |
1354 | e6e5906b | pbrook | gen_op_add32(QREG_SP, tmp, gen_im32(offset)); |
1355 | e6e5906b | pbrook | } |
1356 | e6e5906b | pbrook | |
1357 | e6e5906b | pbrook | DISAS_INSN(unlk) |
1358 | e6e5906b | pbrook | { |
1359 | e6e5906b | pbrook | int src;
|
1360 | e6e5906b | pbrook | int reg;
|
1361 | e6e5906b | pbrook | int tmp;
|
1362 | e6e5906b | pbrook | |
1363 | e6e5906b | pbrook | src = gen_new_qreg(QMODE_I32); |
1364 | e6e5906b | pbrook | reg = AREG(insn, 0);
|
1365 | e6e5906b | pbrook | gen_op_mov32(src, reg); |
1366 | e6e5906b | pbrook | tmp = gen_load(OS_LONG, src, 0);
|
1367 | e6e5906b | pbrook | gen_op_mov32(reg, tmp); |
1368 | e6e5906b | pbrook | gen_op_add32(QREG_SP, src, gen_im32(4));
|
1369 | e6e5906b | pbrook | } |
1370 | e6e5906b | pbrook | |
1371 | e6e5906b | pbrook | DISAS_INSN(nop) |
1372 | e6e5906b | pbrook | { |
1373 | e6e5906b | pbrook | } |
1374 | e6e5906b | pbrook | |
1375 | e6e5906b | pbrook | DISAS_INSN(rts) |
1376 | e6e5906b | pbrook | { |
1377 | e6e5906b | pbrook | int tmp;
|
1378 | e6e5906b | pbrook | |
1379 | e6e5906b | pbrook | tmp = gen_load(OS_LONG, QREG_SP, 0);
|
1380 | e6e5906b | pbrook | gen_op_add32(QREG_SP, QREG_SP, gen_im32(4));
|
1381 | e6e5906b | pbrook | gen_jmp(s, tmp); |
1382 | e6e5906b | pbrook | } |
1383 | e6e5906b | pbrook | |
1384 | e6e5906b | pbrook | DISAS_INSN(jump) |
1385 | e6e5906b | pbrook | { |
1386 | e6e5906b | pbrook | int tmp;
|
1387 | e6e5906b | pbrook | |
1388 | e6e5906b | pbrook | /* Load the target address first to ensure correct exception
|
1389 | e6e5906b | pbrook | behavior. */
|
1390 | e6e5906b | pbrook | tmp = gen_lea(s, insn, OS_LONG); |
1391 | e6e5906b | pbrook | if ((insn & 0x40) == 0) { |
1392 | e6e5906b | pbrook | /* jsr */
|
1393 | e6e5906b | pbrook | gen_push(gen_im32(s->pc)); |
1394 | e6e5906b | pbrook | } |
1395 | e6e5906b | pbrook | gen_jmp(s, tmp); |
1396 | e6e5906b | pbrook | } |
1397 | e6e5906b | pbrook | |
1398 | e6e5906b | pbrook | DISAS_INSN(addsubq) |
1399 | e6e5906b | pbrook | { |
1400 | e6e5906b | pbrook | int src1;
|
1401 | e6e5906b | pbrook | int src2;
|
1402 | e6e5906b | pbrook | int dest;
|
1403 | e6e5906b | pbrook | int val;
|
1404 | e6e5906b | pbrook | int addr;
|
1405 | e6e5906b | pbrook | |
1406 | e6e5906b | pbrook | src1 = gen_ea(s, insn, OS_LONG, 0, &addr);
|
1407 | e6e5906b | pbrook | val = (insn >> 9) & 7; |
1408 | e6e5906b | pbrook | if (val == 0) |
1409 | e6e5906b | pbrook | val = 8;
|
1410 | e6e5906b | pbrook | src2 = gen_im32(val); |
1411 | e6e5906b | pbrook | dest = gen_new_qreg(QMODE_I32); |
1412 | e6e5906b | pbrook | gen_op_mov32(dest, src1); |
1413 | e6e5906b | pbrook | if ((insn & 0x38) == 0x08) { |
1414 | e6e5906b | pbrook | /* Don't update condition codes if the destination is an
|
1415 | e6e5906b | pbrook | address register. */
|
1416 | e6e5906b | pbrook | if (insn & 0x0100) { |
1417 | e6e5906b | pbrook | gen_op_sub32(dest, dest, src2); |
1418 | e6e5906b | pbrook | } else {
|
1419 | e6e5906b | pbrook | gen_op_add32(dest, dest, src2); |
1420 | e6e5906b | pbrook | } |
1421 | e6e5906b | pbrook | } else {
|
1422 | e6e5906b | pbrook | if (insn & 0x0100) { |
1423 | e6e5906b | pbrook | gen_op_update_xflag_lt(dest, src2); |
1424 | e6e5906b | pbrook | gen_op_sub32(dest, dest, src2); |
1425 | e6e5906b | pbrook | s->cc_op = CC_OP_SUB; |
1426 | e6e5906b | pbrook | } else {
|
1427 | e6e5906b | pbrook | gen_op_add32(dest, dest, src2); |
1428 | e6e5906b | pbrook | gen_op_update_xflag_lt(dest, src2); |
1429 | e6e5906b | pbrook | s->cc_op = CC_OP_ADD; |
1430 | e6e5906b | pbrook | } |
1431 | e6e5906b | pbrook | gen_op_update_cc_add(dest, src2); |
1432 | e6e5906b | pbrook | } |
1433 | e6e5906b | pbrook | gen_ea(s, insn, OS_LONG, dest, &addr); |
1434 | e6e5906b | pbrook | } |
1435 | e6e5906b | pbrook | |
1436 | e6e5906b | pbrook | DISAS_INSN(tpf) |
1437 | e6e5906b | pbrook | { |
1438 | e6e5906b | pbrook | switch (insn & 7) { |
1439 | e6e5906b | pbrook | case 2: /* One extension word. */ |
1440 | e6e5906b | pbrook | s->pc += 2;
|
1441 | e6e5906b | pbrook | break;
|
1442 | e6e5906b | pbrook | case 3: /* Two extension words. */ |
1443 | e6e5906b | pbrook | s->pc += 4;
|
1444 | e6e5906b | pbrook | break;
|
1445 | e6e5906b | pbrook | case 4: /* No extension words. */ |
1446 | e6e5906b | pbrook | break;
|
1447 | e6e5906b | pbrook | default:
|
1448 | e6e5906b | pbrook | disas_undef(s, insn); |
1449 | e6e5906b | pbrook | } |
1450 | e6e5906b | pbrook | } |
1451 | e6e5906b | pbrook | |
1452 | e6e5906b | pbrook | DISAS_INSN(branch) |
1453 | e6e5906b | pbrook | { |
1454 | e6e5906b | pbrook | int32_t offset; |
1455 | e6e5906b | pbrook | uint32_t base; |
1456 | e6e5906b | pbrook | int op;
|
1457 | e6e5906b | pbrook | int l1;
|
1458 | e6e5906b | pbrook | |
1459 | e6e5906b | pbrook | base = s->pc; |
1460 | e6e5906b | pbrook | op = (insn >> 8) & 0xf; |
1461 | e6e5906b | pbrook | offset = (int8_t)insn; |
1462 | e6e5906b | pbrook | if (offset == 0) { |
1463 | e6e5906b | pbrook | offset = ldsw(s->pc); |
1464 | e6e5906b | pbrook | s->pc += 2;
|
1465 | e6e5906b | pbrook | } else if (offset == -1) { |
1466 | e6e5906b | pbrook | offset = read_im32(s); |
1467 | e6e5906b | pbrook | } |
1468 | e6e5906b | pbrook | if (op == 1) { |
1469 | e6e5906b | pbrook | /* bsr */
|
1470 | e6e5906b | pbrook | gen_push(gen_im32(s->pc)); |
1471 | e6e5906b | pbrook | } |
1472 | e6e5906b | pbrook | gen_flush_cc_op(s); |
1473 | e6e5906b | pbrook | if (op > 1) { |
1474 | e6e5906b | pbrook | /* Bcc */
|
1475 | e6e5906b | pbrook | l1 = gen_new_label(); |
1476 | e6e5906b | pbrook | gen_jmpcc(s, ((insn >> 8) & 0xf) ^ 1, l1); |
1477 | e6e5906b | pbrook | gen_jmp_tb(s, 1, base + offset);
|
1478 | e6e5906b | pbrook | gen_set_label(l1); |
1479 | e6e5906b | pbrook | gen_jmp_tb(s, 0, s->pc);
|
1480 | e6e5906b | pbrook | } else {
|
1481 | e6e5906b | pbrook | /* Unconditional branch. */
|
1482 | e6e5906b | pbrook | gen_jmp_tb(s, 0, base + offset);
|
1483 | e6e5906b | pbrook | } |
1484 | e6e5906b | pbrook | } |
1485 | e6e5906b | pbrook | |
1486 | e6e5906b | pbrook | DISAS_INSN(moveq) |
1487 | e6e5906b | pbrook | { |
1488 | e6e5906b | pbrook | int tmp;
|
1489 | e6e5906b | pbrook | |
1490 | e6e5906b | pbrook | tmp = gen_im32((int8_t)insn); |
1491 | e6e5906b | pbrook | gen_op_mov32(DREG(insn, 9), tmp);
|
1492 | e6e5906b | pbrook | gen_logic_cc(s, tmp); |
1493 | e6e5906b | pbrook | } |
1494 | e6e5906b | pbrook | |
1495 | e6e5906b | pbrook | DISAS_INSN(mvzs) |
1496 | e6e5906b | pbrook | { |
1497 | e6e5906b | pbrook | int opsize;
|
1498 | e6e5906b | pbrook | int src;
|
1499 | e6e5906b | pbrook | int reg;
|
1500 | e6e5906b | pbrook | |
1501 | e6e5906b | pbrook | if (insn & 0x40) |
1502 | e6e5906b | pbrook | opsize = OS_WORD; |
1503 | e6e5906b | pbrook | else
|
1504 | e6e5906b | pbrook | opsize = OS_BYTE; |
1505 | e6e5906b | pbrook | src = gen_ea(s, insn, opsize, (insn & 0x80) ? 0 : -1, NULL); |
1506 | e6e5906b | pbrook | reg = DREG(insn, 9);
|
1507 | e6e5906b | pbrook | gen_op_mov32(reg, src); |
1508 | e6e5906b | pbrook | gen_logic_cc(s, src); |
1509 | e6e5906b | pbrook | } |
1510 | e6e5906b | pbrook | |
1511 | e6e5906b | pbrook | DISAS_INSN(or) |
1512 | e6e5906b | pbrook | { |
1513 | e6e5906b | pbrook | int reg;
|
1514 | e6e5906b | pbrook | int dest;
|
1515 | e6e5906b | pbrook | int src;
|
1516 | e6e5906b | pbrook | int addr;
|
1517 | e6e5906b | pbrook | |
1518 | e6e5906b | pbrook | reg = DREG(insn, 9);
|
1519 | e6e5906b | pbrook | dest = gen_new_qreg(QMODE_I32); |
1520 | e6e5906b | pbrook | if (insn & 0x100) { |
1521 | e6e5906b | pbrook | src = gen_ea(s, insn, OS_LONG, 0, &addr);
|
1522 | e6e5906b | pbrook | gen_op_or32(dest, src, reg); |
1523 | e6e5906b | pbrook | gen_ea(s, insn, OS_LONG, dest, &addr); |
1524 | e6e5906b | pbrook | } else {
|
1525 | e6e5906b | pbrook | src = gen_ea(s, insn, OS_LONG, 0, NULL); |
1526 | e6e5906b | pbrook | gen_op_or32(dest, src, reg); |
1527 | e6e5906b | pbrook | gen_op_mov32(reg, dest); |
1528 | e6e5906b | pbrook | } |
1529 | e6e5906b | pbrook | gen_logic_cc(s, dest); |
1530 | e6e5906b | pbrook | } |
1531 | e6e5906b | pbrook | |
1532 | e6e5906b | pbrook | DISAS_INSN(suba) |
1533 | e6e5906b | pbrook | { |
1534 | e6e5906b | pbrook | int src;
|
1535 | e6e5906b | pbrook | int reg;
|
1536 | e6e5906b | pbrook | |
1537 | e6e5906b | pbrook | src = gen_ea(s, insn, OS_LONG, 0, NULL); |
1538 | e6e5906b | pbrook | reg = AREG(insn, 9);
|
1539 | e6e5906b | pbrook | gen_op_sub32(reg, reg, src); |
1540 | e6e5906b | pbrook | } |
1541 | e6e5906b | pbrook | |
1542 | e6e5906b | pbrook | DISAS_INSN(subx) |
1543 | e6e5906b | pbrook | { |
1544 | e6e5906b | pbrook | int reg;
|
1545 | e6e5906b | pbrook | int src;
|
1546 | e6e5906b | pbrook | int dest;
|
1547 | e6e5906b | pbrook | int tmp;
|
1548 | e6e5906b | pbrook | |
1549 | e6e5906b | pbrook | gen_flush_flags(s); |
1550 | e6e5906b | pbrook | reg = DREG(insn, 9);
|
1551 | e6e5906b | pbrook | src = DREG(insn, 0);
|
1552 | e6e5906b | pbrook | dest = gen_new_qreg(QMODE_I32); |
1553 | e6e5906b | pbrook | gen_op_mov32 (dest, reg); |
1554 | e6e5906b | pbrook | gen_op_subx_cc(dest, src); |
1555 | e6e5906b | pbrook | /* !Z is sticky. */
|
1556 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
1557 | e6e5906b | pbrook | gen_op_mov32 (tmp, QREG_CC_DEST); |
1558 | e6e5906b | pbrook | gen_op_update_cc_add(dest, src); |
1559 | e6e5906b | pbrook | gen_op_mov32(reg, dest); |
1560 | e6e5906b | pbrook | s->cc_op = CC_OP_DYNAMIC; |
1561 | e6e5906b | pbrook | gen_flush_flags(s); |
1562 | e6e5906b | pbrook | gen_op_or32(tmp, tmp, gen_im32(~CCF_Z)); |
1563 | e6e5906b | pbrook | gen_op_and32(QREG_CC_DEST, QREG_CC_DEST, tmp); |
1564 | e6e5906b | pbrook | s->cc_op = CC_OP_FLAGS; |
1565 | e6e5906b | pbrook | } |
1566 | e6e5906b | pbrook | |
1567 | e6e5906b | pbrook | DISAS_INSN(mov3q) |
1568 | e6e5906b | pbrook | { |
1569 | e6e5906b | pbrook | int src;
|
1570 | e6e5906b | pbrook | int val;
|
1571 | e6e5906b | pbrook | |
1572 | e6e5906b | pbrook | val = (insn >> 9) & 7; |
1573 | e6e5906b | pbrook | if (val == 0) |
1574 | e6e5906b | pbrook | val = -1;
|
1575 | e6e5906b | pbrook | src = gen_im32(val); |
1576 | e6e5906b | pbrook | gen_logic_cc(s, src); |
1577 | e6e5906b | pbrook | gen_ea(s, insn, OS_LONG, src, NULL);
|
1578 | e6e5906b | pbrook | } |
1579 | e6e5906b | pbrook | |
1580 | e6e5906b | pbrook | DISAS_INSN(cmp) |
1581 | e6e5906b | pbrook | { |
1582 | e6e5906b | pbrook | int op;
|
1583 | e6e5906b | pbrook | int src;
|
1584 | e6e5906b | pbrook | int reg;
|
1585 | e6e5906b | pbrook | int dest;
|
1586 | e6e5906b | pbrook | int opsize;
|
1587 | e6e5906b | pbrook | |
1588 | e6e5906b | pbrook | op = (insn >> 6) & 3; |
1589 | e6e5906b | pbrook | switch (op) {
|
1590 | e6e5906b | pbrook | case 0: /* cmp.b */ |
1591 | e6e5906b | pbrook | opsize = OS_BYTE; |
1592 | e6e5906b | pbrook | s->cc_op = CC_OP_CMPB; |
1593 | e6e5906b | pbrook | break;
|
1594 | e6e5906b | pbrook | case 1: /* cmp.w */ |
1595 | e6e5906b | pbrook | opsize = OS_WORD; |
1596 | e6e5906b | pbrook | s->cc_op = CC_OP_CMPW; |
1597 | e6e5906b | pbrook | break;
|
1598 | e6e5906b | pbrook | case 2: /* cmp.l */ |
1599 | e6e5906b | pbrook | opsize = OS_LONG; |
1600 | e6e5906b | pbrook | s->cc_op = CC_OP_SUB; |
1601 | e6e5906b | pbrook | break;
|
1602 | e6e5906b | pbrook | default:
|
1603 | e6e5906b | pbrook | abort(); |
1604 | e6e5906b | pbrook | } |
1605 | e6e5906b | pbrook | src = gen_ea(s, insn, opsize, -1, NULL); |
1606 | e6e5906b | pbrook | reg = DREG(insn, 9);
|
1607 | e6e5906b | pbrook | dest = gen_new_qreg(QMODE_I32); |
1608 | e6e5906b | pbrook | gen_op_sub32(dest, reg, src); |
1609 | e6e5906b | pbrook | gen_op_update_cc_add(dest, src); |
1610 | e6e5906b | pbrook | } |
1611 | e6e5906b | pbrook | |
1612 | e6e5906b | pbrook | DISAS_INSN(cmpa) |
1613 | e6e5906b | pbrook | { |
1614 | e6e5906b | pbrook | int opsize;
|
1615 | e6e5906b | pbrook | int src;
|
1616 | e6e5906b | pbrook | int reg;
|
1617 | e6e5906b | pbrook | int dest;
|
1618 | e6e5906b | pbrook | |
1619 | e6e5906b | pbrook | if (insn & 0x100) { |
1620 | e6e5906b | pbrook | opsize = OS_LONG; |
1621 | e6e5906b | pbrook | } else {
|
1622 | e6e5906b | pbrook | opsize = OS_WORD; |
1623 | e6e5906b | pbrook | } |
1624 | e6e5906b | pbrook | src = gen_ea(s, insn, opsize, -1, NULL); |
1625 | e6e5906b | pbrook | reg = AREG(insn, 9);
|
1626 | e6e5906b | pbrook | dest = gen_new_qreg(QMODE_I32); |
1627 | e6e5906b | pbrook | gen_op_sub32(dest, reg, src); |
1628 | e6e5906b | pbrook | gen_op_update_cc_add(dest, src); |
1629 | e6e5906b | pbrook | s->cc_op = CC_OP_SUB; |
1630 | e6e5906b | pbrook | } |
1631 | e6e5906b | pbrook | |
1632 | e6e5906b | pbrook | DISAS_INSN(eor) |
1633 | e6e5906b | pbrook | { |
1634 | e6e5906b | pbrook | int src;
|
1635 | e6e5906b | pbrook | int reg;
|
1636 | e6e5906b | pbrook | int dest;
|
1637 | e6e5906b | pbrook | int addr;
|
1638 | e6e5906b | pbrook | |
1639 | e6e5906b | pbrook | src = gen_ea(s, insn, OS_LONG, 0, &addr);
|
1640 | e6e5906b | pbrook | reg = DREG(insn, 9);
|
1641 | e6e5906b | pbrook | dest = gen_new_qreg(QMODE_I32); |
1642 | e6e5906b | pbrook | gen_op_xor32(dest, src, reg); |
1643 | e6e5906b | pbrook | gen_logic_cc(s, dest); |
1644 | e6e5906b | pbrook | gen_ea(s, insn, OS_LONG, dest, &addr); |
1645 | e6e5906b | pbrook | } |
1646 | e6e5906b | pbrook | |
1647 | e6e5906b | pbrook | DISAS_INSN(and) |
1648 | e6e5906b | pbrook | { |
1649 | e6e5906b | pbrook | int src;
|
1650 | e6e5906b | pbrook | int reg;
|
1651 | e6e5906b | pbrook | int dest;
|
1652 | e6e5906b | pbrook | int addr;
|
1653 | e6e5906b | pbrook | |
1654 | e6e5906b | pbrook | reg = DREG(insn, 9);
|
1655 | e6e5906b | pbrook | dest = gen_new_qreg(QMODE_I32); |
1656 | e6e5906b | pbrook | if (insn & 0x100) { |
1657 | e6e5906b | pbrook | src = gen_ea(s, insn, OS_LONG, 0, &addr);
|
1658 | e6e5906b | pbrook | gen_op_and32(dest, src, reg); |
1659 | e6e5906b | pbrook | gen_ea(s, insn, OS_LONG, dest, &addr); |
1660 | e6e5906b | pbrook | } else {
|
1661 | e6e5906b | pbrook | src = gen_ea(s, insn, OS_LONG, 0, NULL); |
1662 | e6e5906b | pbrook | gen_op_and32(dest, src, reg); |
1663 | e6e5906b | pbrook | gen_op_mov32(reg, dest); |
1664 | e6e5906b | pbrook | } |
1665 | e6e5906b | pbrook | gen_logic_cc(s, dest); |
1666 | e6e5906b | pbrook | } |
1667 | e6e5906b | pbrook | |
1668 | e6e5906b | pbrook | DISAS_INSN(adda) |
1669 | e6e5906b | pbrook | { |
1670 | e6e5906b | pbrook | int src;
|
1671 | e6e5906b | pbrook | int reg;
|
1672 | e6e5906b | pbrook | |
1673 | e6e5906b | pbrook | src = gen_ea(s, insn, OS_LONG, 0, NULL); |
1674 | e6e5906b | pbrook | reg = AREG(insn, 9);
|
1675 | e6e5906b | pbrook | gen_op_add32(reg, reg, src); |
1676 | e6e5906b | pbrook | } |
1677 | e6e5906b | pbrook | |
1678 | e6e5906b | pbrook | DISAS_INSN(addx) |
1679 | e6e5906b | pbrook | { |
1680 | e6e5906b | pbrook | int reg;
|
1681 | e6e5906b | pbrook | int src;
|
1682 | e6e5906b | pbrook | int dest;
|
1683 | e6e5906b | pbrook | int tmp;
|
1684 | e6e5906b | pbrook | |
1685 | e6e5906b | pbrook | gen_flush_flags(s); |
1686 | e6e5906b | pbrook | reg = DREG(insn, 9);
|
1687 | e6e5906b | pbrook | src = DREG(insn, 0);
|
1688 | e6e5906b | pbrook | dest = gen_new_qreg(QMODE_I32); |
1689 | e6e5906b | pbrook | gen_op_mov32 (dest, reg); |
1690 | e6e5906b | pbrook | gen_op_addx_cc(dest, src); |
1691 | e6e5906b | pbrook | /* !Z is sticky. */
|
1692 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
1693 | e6e5906b | pbrook | gen_op_mov32 (tmp, QREG_CC_DEST); |
1694 | e6e5906b | pbrook | gen_op_update_cc_add(dest, src); |
1695 | e6e5906b | pbrook | gen_op_mov32(reg, dest); |
1696 | e6e5906b | pbrook | s->cc_op = CC_OP_DYNAMIC; |
1697 | e6e5906b | pbrook | gen_flush_flags(s); |
1698 | e6e5906b | pbrook | gen_op_or32(tmp, tmp, gen_im32(~CCF_Z)); |
1699 | e6e5906b | pbrook | gen_op_and32(QREG_CC_DEST, QREG_CC_DEST, tmp); |
1700 | e6e5906b | pbrook | s->cc_op = CC_OP_FLAGS; |
1701 | e6e5906b | pbrook | } |
1702 | e6e5906b | pbrook | |
1703 | e6e5906b | pbrook | DISAS_INSN(shift_im) |
1704 | e6e5906b | pbrook | { |
1705 | e6e5906b | pbrook | int reg;
|
1706 | e6e5906b | pbrook | int tmp;
|
1707 | e6e5906b | pbrook | |
1708 | e6e5906b | pbrook | reg = DREG(insn, 0);
|
1709 | e6e5906b | pbrook | tmp = (insn >> 9) & 7; |
1710 | e6e5906b | pbrook | if (tmp == 0) |
1711 | e6e5906b | pbrook | tmp = 8;
|
1712 | e6e5906b | pbrook | if (insn & 0x100) { |
1713 | e6e5906b | pbrook | gen_op_shl_im_cc(reg, tmp); |
1714 | e6e5906b | pbrook | s->cc_op = CC_OP_SHL; |
1715 | e6e5906b | pbrook | } else {
|
1716 | e6e5906b | pbrook | if (insn & 8) { |
1717 | e6e5906b | pbrook | gen_op_shr_im_cc(reg, tmp); |
1718 | e6e5906b | pbrook | s->cc_op = CC_OP_SHR; |
1719 | e6e5906b | pbrook | } else {
|
1720 | e6e5906b | pbrook | gen_op_sar_im_cc(reg, tmp); |
1721 | e6e5906b | pbrook | s->cc_op = CC_OP_SAR; |
1722 | e6e5906b | pbrook | } |
1723 | e6e5906b | pbrook | } |
1724 | e6e5906b | pbrook | } |
1725 | e6e5906b | pbrook | |
1726 | e6e5906b | pbrook | DISAS_INSN(shift_reg) |
1727 | e6e5906b | pbrook | { |
1728 | e6e5906b | pbrook | int reg;
|
1729 | e6e5906b | pbrook | int src;
|
1730 | e6e5906b | pbrook | int tmp;
|
1731 | e6e5906b | pbrook | |
1732 | e6e5906b | pbrook | reg = DREG(insn, 0);
|
1733 | e6e5906b | pbrook | src = DREG(insn, 9);
|
1734 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32); |
1735 | e6e5906b | pbrook | gen_op_and32(tmp, src, gen_im32(63));
|
1736 | e6e5906b | pbrook | if (insn & 0x100) { |
1737 | e6e5906b | pbrook | gen_op_shl_cc(reg, tmp); |
1738 | e6e5906b | pbrook | s->cc_op = CC_OP_SHL; |
1739 | e6e5906b | pbrook | } else {
|
1740 | e6e5906b | pbrook | if (insn & 8) { |
1741 | e6e5906b | pbrook | gen_op_shr_cc(reg, tmp); |
1742 | e6e5906b | pbrook | s->cc_op = CC_OP_SHR; |
1743 | e6e5906b | pbrook | } else {
|
1744 | e6e5906b | pbrook | gen_op_sar_cc(reg, tmp); |
1745 | e6e5906b | pbrook | s->cc_op = CC_OP_SAR; |
1746 | e6e5906b | pbrook | } |
1747 | e6e5906b | pbrook | } |
1748 | e6e5906b | pbrook | } |
1749 | e6e5906b | pbrook | |
1750 | e6e5906b | pbrook | DISAS_INSN(ff1) |
1751 | e6e5906b | pbrook | { |
1752 | e6e5906b | pbrook | cpu_abort(NULL, "Unimplemented insn: ff1"); |
1753 | e6e5906b | pbrook | } |
1754 | e6e5906b | pbrook | |
1755 | e6e5906b | pbrook | DISAS_INSN(strldsr) |
1756 | e6e5906b | pbrook | { |
1757 | e6e5906b | pbrook | uint16_t ext; |
1758 | e6e5906b | pbrook | uint32_t addr; |
1759 | e6e5906b | pbrook | |
1760 | e6e5906b | pbrook | addr = s->pc - 2;
|
1761 | e6e5906b | pbrook | ext = lduw(s->pc); |
1762 | e6e5906b | pbrook | s->pc += 2;
|
1763 | e6e5906b | pbrook | if (ext != 0x46FC) |
1764 | e6e5906b | pbrook | gen_exception(s, addr, EXCP_UNSUPPORTED); |
1765 | e6e5906b | pbrook | else
|
1766 | e6e5906b | pbrook | gen_exception(s, addr, EXCP_PRIVILEGE); |
1767 | e6e5906b | pbrook | } |
1768 | e6e5906b | pbrook | |
1769 | e6e5906b | pbrook | DISAS_INSN(move_from_sr) |
1770 | e6e5906b | pbrook | { |
1771 | e6e5906b | pbrook | gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
1772 | e6e5906b | pbrook | } |
1773 | e6e5906b | pbrook | |
1774 | e6e5906b | pbrook | DISAS_INSN(move_to_sr) |
1775 | e6e5906b | pbrook | { |
1776 | e6e5906b | pbrook | gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
1777 | e6e5906b | pbrook | } |
1778 | e6e5906b | pbrook | |
1779 | e6e5906b | pbrook | DISAS_INSN(move_from_usp) |
1780 | e6e5906b | pbrook | { |
1781 | e6e5906b | pbrook | gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
1782 | e6e5906b | pbrook | } |
1783 | e6e5906b | pbrook | |
1784 | e6e5906b | pbrook | DISAS_INSN(move_to_usp) |
1785 | e6e5906b | pbrook | { |
1786 | e6e5906b | pbrook | gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
1787 | e6e5906b | pbrook | } |
1788 | e6e5906b | pbrook | |
1789 | e6e5906b | pbrook | DISAS_INSN(halt) |
1790 | e6e5906b | pbrook | { |
1791 | e6e5906b | pbrook | gen_exception(s, s->pc, EXCP_HLT); |
1792 | e6e5906b | pbrook | } |
1793 | e6e5906b | pbrook | |
1794 | e6e5906b | pbrook | DISAS_INSN(stop) |
1795 | e6e5906b | pbrook | { |
1796 | e6e5906b | pbrook | gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
1797 | e6e5906b | pbrook | } |
1798 | e6e5906b | pbrook | |
1799 | e6e5906b | pbrook | DISAS_INSN(rte) |
1800 | e6e5906b | pbrook | { |
1801 | e6e5906b | pbrook | gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
1802 | e6e5906b | pbrook | } |
1803 | e6e5906b | pbrook | |
1804 | e6e5906b | pbrook | DISAS_INSN(movec) |
1805 | e6e5906b | pbrook | { |
1806 | e6e5906b | pbrook | gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
1807 | e6e5906b | pbrook | } |
1808 | e6e5906b | pbrook | |
1809 | e6e5906b | pbrook | DISAS_INSN(intouch) |
1810 | e6e5906b | pbrook | { |
1811 | e6e5906b | pbrook | gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
1812 | e6e5906b | pbrook | } |
1813 | e6e5906b | pbrook | |
1814 | e6e5906b | pbrook | DISAS_INSN(cpushl) |
1815 | e6e5906b | pbrook | { |
1816 | e6e5906b | pbrook | gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
1817 | e6e5906b | pbrook | } |
1818 | e6e5906b | pbrook | |
1819 | e6e5906b | pbrook | DISAS_INSN(wddata) |
1820 | e6e5906b | pbrook | { |
1821 | e6e5906b | pbrook | gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
1822 | e6e5906b | pbrook | } |
1823 | e6e5906b | pbrook | |
1824 | e6e5906b | pbrook | DISAS_INSN(wdebug) |
1825 | e6e5906b | pbrook | { |
1826 | e6e5906b | pbrook | gen_exception(s, s->pc - 2, EXCP_PRIVILEGE);
|
1827 | e6e5906b | pbrook | } |
1828 | e6e5906b | pbrook | |
1829 | e6e5906b | pbrook | DISAS_INSN(trap) |
1830 | e6e5906b | pbrook | { |
1831 | e6e5906b | pbrook | gen_exception(s, s->pc - 2, EXCP_TRAP0 + (insn & 0xf)); |
1832 | e6e5906b | pbrook | } |
1833 | e6e5906b | pbrook | |
1834 | e6e5906b | pbrook | /* ??? FP exceptions are not implemented. Most exceptions are deferred until
|
1835 | e6e5906b | pbrook | immediately before the next FP instruction is executed. */
|
1836 | e6e5906b | pbrook | DISAS_INSN(fpu) |
1837 | e6e5906b | pbrook | { |
1838 | e6e5906b | pbrook | uint16_t ext; |
1839 | e6e5906b | pbrook | int opmode;
|
1840 | e6e5906b | pbrook | int src;
|
1841 | e6e5906b | pbrook | int dest;
|
1842 | e6e5906b | pbrook | int res;
|
1843 | e6e5906b | pbrook | int round;
|
1844 | e6e5906b | pbrook | int opsize;
|
1845 | e6e5906b | pbrook | |
1846 | e6e5906b | pbrook | ext = lduw(s->pc); |
1847 | e6e5906b | pbrook | s->pc += 2;
|
1848 | e6e5906b | pbrook | opmode = ext & 0x7f;
|
1849 | e6e5906b | pbrook | switch ((ext >> 13) & 7) { |
1850 | e6e5906b | pbrook | case 0: case 2: |
1851 | e6e5906b | pbrook | break;
|
1852 | e6e5906b | pbrook | case 1: |
1853 | e6e5906b | pbrook | goto undef;
|
1854 | e6e5906b | pbrook | case 3: /* fmove out */ |
1855 | e6e5906b | pbrook | src = FREG(ext, 7);
|
1856 | e6e5906b | pbrook | /* fmove */
|
1857 | e6e5906b | pbrook | /* ??? TODO: Proper behavior on overflow. */
|
1858 | e6e5906b | pbrook | switch ((ext >> 10) & 7) { |
1859 | e6e5906b | pbrook | case 0: |
1860 | e6e5906b | pbrook | opsize = OS_LONG; |
1861 | e6e5906b | pbrook | res = gen_new_qreg(QMODE_I32); |
1862 | e6e5906b | pbrook | gen_op_f64_to_i32(res, src); |
1863 | e6e5906b | pbrook | break;
|
1864 | e6e5906b | pbrook | case 1: |
1865 | e6e5906b | pbrook | opsize = OS_SINGLE; |
1866 | e6e5906b | pbrook | res = gen_new_qreg(QMODE_F32); |
1867 | e6e5906b | pbrook | gen_op_f64_to_f32(res, src); |
1868 | e6e5906b | pbrook | break;
|
1869 | e6e5906b | pbrook | case 4: |
1870 | e6e5906b | pbrook | opsize = OS_WORD; |
1871 | e6e5906b | pbrook | res = gen_new_qreg(QMODE_I32); |
1872 | e6e5906b | pbrook | gen_op_f64_to_i32(res, src); |
1873 | e6e5906b | pbrook | break;
|
1874 | e6e5906b | pbrook | case 5: |
1875 | e6e5906b | pbrook | opsize = OS_DOUBLE; |
1876 | e6e5906b | pbrook | res = src; |
1877 | e6e5906b | pbrook | break;
|
1878 | e6e5906b | pbrook | case 6: |
1879 | e6e5906b | pbrook | opsize = OS_BYTE; |
1880 | e6e5906b | pbrook | res = gen_new_qreg(QMODE_I32); |
1881 | e6e5906b | pbrook | gen_op_f64_to_i32(res, src); |
1882 | e6e5906b | pbrook | break;
|
1883 | e6e5906b | pbrook | default:
|
1884 | e6e5906b | pbrook | goto undef;
|
1885 | e6e5906b | pbrook | } |
1886 | e6e5906b | pbrook | gen_ea(s, insn, opsize, res, NULL);
|
1887 | e6e5906b | pbrook | return;
|
1888 | e6e5906b | pbrook | case 4: /* fmove to control register. */ |
1889 | e6e5906b | pbrook | switch ((ext >> 10) & 7) { |
1890 | e6e5906b | pbrook | case 4: /* FPCR */ |
1891 | e6e5906b | pbrook | /* Not implemented. Ignore writes. */
|
1892 | e6e5906b | pbrook | break;
|
1893 | e6e5906b | pbrook | case 1: /* FPIAR */ |
1894 | e6e5906b | pbrook | case 2: /* FPSR */ |
1895 | e6e5906b | pbrook | default:
|
1896 | e6e5906b | pbrook | cpu_abort(NULL, "Unimplemented: fmove to control %d", |
1897 | e6e5906b | pbrook | (ext >> 10) & 7); |
1898 | e6e5906b | pbrook | } |
1899 | e6e5906b | pbrook | break;
|
1900 | e6e5906b | pbrook | case 5: /* fmove from control register. */ |
1901 | e6e5906b | pbrook | switch ((ext >> 10) & 7) { |
1902 | e6e5906b | pbrook | case 4: /* FPCR */ |
1903 | e6e5906b | pbrook | /* Not implemented. Always return zero. */
|
1904 | e6e5906b | pbrook | res = gen_im32(0);
|
1905 | e6e5906b | pbrook | break;
|
1906 | e6e5906b | pbrook | case 1: /* FPIAR */ |
1907 | e6e5906b | pbrook | case 2: /* FPSR */ |
1908 | e6e5906b | pbrook | default:
|
1909 | e6e5906b | pbrook | cpu_abort(NULL, "Unimplemented: fmove from control %d", |
1910 | e6e5906b | pbrook | (ext >> 10) & 7); |
1911 | e6e5906b | pbrook | goto undef;
|
1912 | e6e5906b | pbrook | } |
1913 | e6e5906b | pbrook | gen_ea(s, insn, OS_LONG, res, NULL);
|
1914 | e6e5906b | pbrook | break;
|
1915 | e6e5906b | pbrook | case 6: /* fmovem */ |
1916 | e6e5906b | pbrook | case 7: |
1917 | e6e5906b | pbrook | { |
1918 | e6e5906b | pbrook | int addr;
|
1919 | e6e5906b | pbrook | uint16_t mask; |
1920 | e6e5906b | pbrook | if ((ext & 0x1f00) != 0x1000 || (ext & 0xff) == 0) |
1921 | e6e5906b | pbrook | goto undef;
|
1922 | e6e5906b | pbrook | src = gen_lea(s, insn, OS_LONG); |
1923 | e6e5906b | pbrook | addr = gen_new_qreg(QMODE_I32); |
1924 | e6e5906b | pbrook | gen_op_mov32(addr, src); |
1925 | e6e5906b | pbrook | mask = 0x80;
|
1926 | e6e5906b | pbrook | dest = QREG_F0; |
1927 | e6e5906b | pbrook | while (mask) {
|
1928 | e6e5906b | pbrook | if (ext & mask) {
|
1929 | e6e5906b | pbrook | if (ext & (1 << 13)) { |
1930 | e6e5906b | pbrook | /* store */
|
1931 | e6e5906b | pbrook | gen_op_stf64(addr, dest); |
1932 | e6e5906b | pbrook | } else {
|
1933 | e6e5906b | pbrook | /* load */
|
1934 | e6e5906b | pbrook | gen_op_ldf64(dest, addr); |
1935 | e6e5906b | pbrook | } |
1936 | e6e5906b | pbrook | if (ext & (mask - 1)) |
1937 | e6e5906b | pbrook | gen_op_add32(addr, addr, gen_im32(8));
|
1938 | e6e5906b | pbrook | } |
1939 | e6e5906b | pbrook | mask >>= 1;
|
1940 | e6e5906b | pbrook | dest++; |
1941 | e6e5906b | pbrook | } |
1942 | e6e5906b | pbrook | } |
1943 | e6e5906b | pbrook | return;
|
1944 | e6e5906b | pbrook | } |
1945 | e6e5906b | pbrook | if (ext & (1 << 14)) { |
1946 | e6e5906b | pbrook | int tmp;
|
1947 | e6e5906b | pbrook | |
1948 | e6e5906b | pbrook | /* Source effective address. */
|
1949 | e6e5906b | pbrook | switch ((ext >> 10) & 7) { |
1950 | e6e5906b | pbrook | case 0: opsize = OS_LONG; break; |
1951 | e6e5906b | pbrook | case 1: opsize = OS_SINGLE; break; |
1952 | e6e5906b | pbrook | case 4: opsize = OS_WORD; break; |
1953 | e6e5906b | pbrook | case 5: opsize = OS_DOUBLE; break; |
1954 | e6e5906b | pbrook | case 6: opsize = OS_BYTE; break; |
1955 | e6e5906b | pbrook | default:
|
1956 | e6e5906b | pbrook | goto undef;
|
1957 | e6e5906b | pbrook | } |
1958 | e6e5906b | pbrook | tmp = gen_ea(s, insn, opsize, -1, NULL); |
1959 | e6e5906b | pbrook | if (opsize == OS_DOUBLE) {
|
1960 | e6e5906b | pbrook | src = tmp; |
1961 | e6e5906b | pbrook | } else {
|
1962 | e6e5906b | pbrook | src = gen_new_qreg(QMODE_F64); |
1963 | e6e5906b | pbrook | switch (opsize) {
|
1964 | e6e5906b | pbrook | case OS_LONG:
|
1965 | e6e5906b | pbrook | case OS_WORD:
|
1966 | e6e5906b | pbrook | case OS_BYTE:
|
1967 | e6e5906b | pbrook | gen_op_i32_to_f64(src, tmp); |
1968 | e6e5906b | pbrook | break;
|
1969 | e6e5906b | pbrook | case OS_SINGLE:
|
1970 | e6e5906b | pbrook | gen_op_f32_to_f64(src, tmp); |
1971 | e6e5906b | pbrook | break;
|
1972 | e6e5906b | pbrook | } |
1973 | e6e5906b | pbrook | } |
1974 | e6e5906b | pbrook | } else {
|
1975 | e6e5906b | pbrook | /* Source register. */
|
1976 | e6e5906b | pbrook | src = FREG(ext, 10);
|
1977 | e6e5906b | pbrook | } |
1978 | e6e5906b | pbrook | dest = FREG(ext, 7);
|
1979 | e6e5906b | pbrook | res = gen_new_qreg(QMODE_F64); |
1980 | e6e5906b | pbrook | if (opmode != 0x3a) |
1981 | e6e5906b | pbrook | gen_op_movf64(res, dest); |
1982 | e6e5906b | pbrook | round = 1;
|
1983 | e6e5906b | pbrook | switch (opmode) {
|
1984 | e6e5906b | pbrook | case 0: case 0x40: case 0x44: /* fmove */ |
1985 | e6e5906b | pbrook | gen_op_movf64(res, src); |
1986 | e6e5906b | pbrook | break;
|
1987 | e6e5906b | pbrook | case 1: /* fint */ |
1988 | e6e5906b | pbrook | gen_op_iround_f64(res, src); |
1989 | e6e5906b | pbrook | round = 0;
|
1990 | e6e5906b | pbrook | break;
|
1991 | e6e5906b | pbrook | case 3: /* fintrz */ |
1992 | e6e5906b | pbrook | gen_op_itrunc_f64(res, src); |
1993 | e6e5906b | pbrook | round = 0;
|
1994 | e6e5906b | pbrook | break;
|
1995 | e6e5906b | pbrook | case 4: case 0x41: case 0x45: /* fsqrt */ |
1996 | e6e5906b | pbrook | gen_op_sqrtf64(res, src); |
1997 | e6e5906b | pbrook | break;
|
1998 | e6e5906b | pbrook | case 0x18: case 0x58: case 0x5c: /* fabs */ |
1999 | e6e5906b | pbrook | gen_op_absf64(res, src); |
2000 | e6e5906b | pbrook | break;
|
2001 | e6e5906b | pbrook | case 0x1a: case 0x5a: case 0x5e: /* fneg */ |
2002 | e6e5906b | pbrook | gen_op_chsf64(res, src); |
2003 | e6e5906b | pbrook | break;
|
2004 | e6e5906b | pbrook | case 0x20: case 0x60: case 0x64: /* fdiv */ |
2005 | e6e5906b | pbrook | gen_op_divf64(res, res, src); |
2006 | e6e5906b | pbrook | break;
|
2007 | e6e5906b | pbrook | case 0x22: case 0x62: case 0x66: /* fadd */ |
2008 | e6e5906b | pbrook | gen_op_addf64(res, res, src); |
2009 | e6e5906b | pbrook | break;
|
2010 | e6e5906b | pbrook | case 0x23: case 0x63: case 0x67: /* fmul */ |
2011 | e6e5906b | pbrook | gen_op_mulf64(res, res, src); |
2012 | e6e5906b | pbrook | break;
|
2013 | e6e5906b | pbrook | case 0x28: case 0x68: case 0x6c: /* fsub */ |
2014 | e6e5906b | pbrook | gen_op_subf64(res, res, src); |
2015 | e6e5906b | pbrook | break;
|
2016 | e6e5906b | pbrook | case 0x38: /* fcmp */ |
2017 | e6e5906b | pbrook | gen_op_sub_cmpf64(res, res, src); |
2018 | e6e5906b | pbrook | dest = 0;
|
2019 | e6e5906b | pbrook | round = 0;
|
2020 | e6e5906b | pbrook | break;
|
2021 | e6e5906b | pbrook | case 0x3a: /* ftst */ |
2022 | e6e5906b | pbrook | gen_op_movf64(res, src); |
2023 | e6e5906b | pbrook | dest = 0;
|
2024 | e6e5906b | pbrook | round = 0;
|
2025 | e6e5906b | pbrook | break;
|
2026 | e6e5906b | pbrook | default:
|
2027 | e6e5906b | pbrook | goto undef;
|
2028 | e6e5906b | pbrook | } |
2029 | e6e5906b | pbrook | if (round) {
|
2030 | e6e5906b | pbrook | if (opmode & 0x40) { |
2031 | e6e5906b | pbrook | if ((opmode & 0x4) != 0) |
2032 | e6e5906b | pbrook | round = 0;
|
2033 | e6e5906b | pbrook | } else if ((s->fpcr & M68K_FPCR_PREC) == 0) { |
2034 | e6e5906b | pbrook | round = 0;
|
2035 | e6e5906b | pbrook | } |
2036 | e6e5906b | pbrook | } |
2037 | e6e5906b | pbrook | if (round) {
|
2038 | e6e5906b | pbrook | int tmp;
|
2039 | e6e5906b | pbrook | |
2040 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_F32); |
2041 | e6e5906b | pbrook | gen_op_f64_to_f32(tmp, res); |
2042 | e6e5906b | pbrook | gen_op_f32_to_f64(res, tmp); |
2043 | e6e5906b | pbrook | } |
2044 | e6e5906b | pbrook | gen_op_fp_result(res); |
2045 | e6e5906b | pbrook | if (dest) {
|
2046 | e6e5906b | pbrook | gen_op_movf64(dest, res); |
2047 | e6e5906b | pbrook | } |
2048 | e6e5906b | pbrook | return;
|
2049 | e6e5906b | pbrook | undef:
|
2050 | e6e5906b | pbrook | s->pc -= 2;
|
2051 | e6e5906b | pbrook | disas_undef_fpu(s, insn); |
2052 | e6e5906b | pbrook | } |
2053 | e6e5906b | pbrook | |
2054 | e6e5906b | pbrook | DISAS_INSN(fbcc) |
2055 | e6e5906b | pbrook | { |
2056 | e6e5906b | pbrook | uint32_t offset; |
2057 | e6e5906b | pbrook | uint32_t addr; |
2058 | e6e5906b | pbrook | int flag;
|
2059 | e6e5906b | pbrook | int zero;
|
2060 | e6e5906b | pbrook | int l1;
|
2061 | e6e5906b | pbrook | |
2062 | e6e5906b | pbrook | addr = s->pc; |
2063 | e6e5906b | pbrook | offset = ldsw(s->pc); |
2064 | e6e5906b | pbrook | s->pc += 2;
|
2065 | e6e5906b | pbrook | if (insn & (1 << 6)) { |
2066 | e6e5906b | pbrook | offset = (offset << 16) | lduw(s->pc);
|
2067 | e6e5906b | pbrook | s->pc += 2;
|
2068 | e6e5906b | pbrook | } |
2069 | e6e5906b | pbrook | |
2070 | e6e5906b | pbrook | l1 = gen_new_label(); |
2071 | e6e5906b | pbrook | /* TODO: Raise BSUN exception. */
|
2072 | e6e5906b | pbrook | flag = gen_new_qreg(QMODE_I32); |
2073 | e6e5906b | pbrook | zero = gen_new_qreg(QMODE_F64); |
2074 | e6e5906b | pbrook | gen_op_zerof64(zero); |
2075 | e6e5906b | pbrook | gen_op_compare_quietf64(flag, QREG_FP_RESULT, zero); |
2076 | e6e5906b | pbrook | /* Jump to l1 if condition is true. */
|
2077 | e6e5906b | pbrook | switch (insn & 0xf) { |
2078 | e6e5906b | pbrook | case 0: /* f */ |
2079 | e6e5906b | pbrook | break;
|
2080 | e6e5906b | pbrook | case 1: /* eq (=0) */ |
2081 | e6e5906b | pbrook | gen_op_jmp_z32(flag, l1); |
2082 | e6e5906b | pbrook | break;
|
2083 | e6e5906b | pbrook | case 2: /* ogt (=1) */ |
2084 | e6e5906b | pbrook | gen_op_sub32(flag, flag, gen_im32(1));
|
2085 | e6e5906b | pbrook | gen_op_jmp_z32(flag, l1); |
2086 | e6e5906b | pbrook | break;
|
2087 | e6e5906b | pbrook | case 3: /* oge (=0 or =1) */ |
2088 | e6e5906b | pbrook | gen_op_jmp_z32(flag, l1); |
2089 | e6e5906b | pbrook | gen_op_sub32(flag, flag, gen_im32(1));
|
2090 | e6e5906b | pbrook | gen_op_jmp_z32(flag, l1); |
2091 | e6e5906b | pbrook | break;
|
2092 | e6e5906b | pbrook | case 4: /* olt (=-1) */ |
2093 | e6e5906b | pbrook | gen_op_jmp_s32(flag, l1); |
2094 | e6e5906b | pbrook | break;
|
2095 | e6e5906b | pbrook | case 5: /* ole (=-1 or =0) */ |
2096 | e6e5906b | pbrook | gen_op_jmp_s32(flag, l1); |
2097 | e6e5906b | pbrook | gen_op_jmp_z32(flag, l1); |
2098 | e6e5906b | pbrook | break;
|
2099 | e6e5906b | pbrook | case 6: /* ogl (=-1 or =1) */ |
2100 | e6e5906b | pbrook | gen_op_jmp_s32(flag, l1); |
2101 | e6e5906b | pbrook | gen_op_sub32(flag, flag, gen_im32(1));
|
2102 | e6e5906b | pbrook | gen_op_jmp_z32(flag, l1); |
2103 | e6e5906b | pbrook | break;
|
2104 | e6e5906b | pbrook | case 7: /* or (=2) */ |
2105 | e6e5906b | pbrook | gen_op_sub32(flag, flag, gen_im32(2));
|
2106 | e6e5906b | pbrook | gen_op_jmp_z32(flag, l1); |
2107 | e6e5906b | pbrook | break;
|
2108 | e6e5906b | pbrook | case 8: /* un (<2) */ |
2109 | e6e5906b | pbrook | gen_op_sub32(flag, flag, gen_im32(2));
|
2110 | e6e5906b | pbrook | gen_op_jmp_s32(flag, l1); |
2111 | e6e5906b | pbrook | break;
|
2112 | e6e5906b | pbrook | case 9: /* ueq (=0 or =2) */ |
2113 | e6e5906b | pbrook | gen_op_jmp_z32(flag, l1); |
2114 | e6e5906b | pbrook | gen_op_sub32(flag, flag, gen_im32(2));
|
2115 | e6e5906b | pbrook | gen_op_jmp_z32(flag, l1); |
2116 | e6e5906b | pbrook | break;
|
2117 | e6e5906b | pbrook | case 10: /* ugt (>0) */ |
2118 | e6e5906b | pbrook | /* ??? Add jmp_gtu. */
|
2119 | e6e5906b | pbrook | gen_op_sub32(flag, flag, gen_im32(1));
|
2120 | e6e5906b | pbrook | gen_op_jmp_ns32(flag, l1); |
2121 | e6e5906b | pbrook | break;
|
2122 | e6e5906b | pbrook | case 11: /* uge (>=0) */ |
2123 | e6e5906b | pbrook | gen_op_jmp_ns32(flag, l1); |
2124 | e6e5906b | pbrook | break;
|
2125 | e6e5906b | pbrook | case 12: /* ult (=-1 or =2) */ |
2126 | e6e5906b | pbrook | gen_op_jmp_s32(flag, l1); |
2127 | e6e5906b | pbrook | gen_op_sub32(flag, flag, gen_im32(2));
|
2128 | e6e5906b | pbrook | gen_op_jmp_z32(flag, l1); |
2129 | e6e5906b | pbrook | break;
|
2130 | e6e5906b | pbrook | case 13: /* ule (!=1) */ |
2131 | e6e5906b | pbrook | gen_op_sub32(flag, flag, gen_im32(1));
|
2132 | e6e5906b | pbrook | gen_op_jmp_nz32(flag, l1); |
2133 | e6e5906b | pbrook | break;
|
2134 | e6e5906b | pbrook | case 14: /* ne (!=0) */ |
2135 | e6e5906b | pbrook | gen_op_jmp_nz32(flag, l1); |
2136 | e6e5906b | pbrook | break;
|
2137 | e6e5906b | pbrook | case 15: /* t */ |
2138 | e6e5906b | pbrook | gen_op_mov32(flag, gen_im32(1));
|
2139 | e6e5906b | pbrook | break;
|
2140 | e6e5906b | pbrook | } |
2141 | e6e5906b | pbrook | gen_jmp_tb(s, 0, s->pc);
|
2142 | e6e5906b | pbrook | gen_set_label(l1); |
2143 | e6e5906b | pbrook | gen_jmp_tb(s, 1, addr + offset);
|
2144 | e6e5906b | pbrook | } |
2145 | e6e5906b | pbrook | |
2146 | e6e5906b | pbrook | static disas_proc opcode_table[65536]; |
2147 | e6e5906b | pbrook | |
2148 | e6e5906b | pbrook | static void |
2149 | e6e5906b | pbrook | register_opcode (disas_proc proc, uint16_t opcode, uint16_t mask) |
2150 | e6e5906b | pbrook | { |
2151 | e6e5906b | pbrook | int i;
|
2152 | e6e5906b | pbrook | int from;
|
2153 | e6e5906b | pbrook | int to;
|
2154 | e6e5906b | pbrook | |
2155 | e6e5906b | pbrook | /* Sanity check. All set bits must be included in the mask. */
|
2156 | e6e5906b | pbrook | if (opcode & ~mask)
|
2157 | e6e5906b | pbrook | abort(); |
2158 | e6e5906b | pbrook | /* This could probably be cleverer. For now just optimize the case where
|
2159 | e6e5906b | pbrook | the top bits are known. */
|
2160 | e6e5906b | pbrook | /* Find the first zero bit in the mask. */
|
2161 | e6e5906b | pbrook | i = 0x8000;
|
2162 | e6e5906b | pbrook | while ((i & mask) != 0) |
2163 | e6e5906b | pbrook | i >>= 1;
|
2164 | e6e5906b | pbrook | /* Iterate over all combinations of this and lower bits. */
|
2165 | e6e5906b | pbrook | if (i == 0) |
2166 | e6e5906b | pbrook | i = 1;
|
2167 | e6e5906b | pbrook | else
|
2168 | e6e5906b | pbrook | i <<= 1;
|
2169 | e6e5906b | pbrook | from = opcode & ~(i - 1);
|
2170 | e6e5906b | pbrook | to = from + i; |
2171 | e6e5906b | pbrook | for (i = from; i < to; i++)
|
2172 | e6e5906b | pbrook | { |
2173 | e6e5906b | pbrook | if ((i & mask) == opcode)
|
2174 | e6e5906b | pbrook | opcode_table[i] = proc; |
2175 | e6e5906b | pbrook | } |
2176 | e6e5906b | pbrook | } |
2177 | e6e5906b | pbrook | |
2178 | e6e5906b | pbrook | /* Register m68k opcode handlers. Order is important.
|
2179 | e6e5906b | pbrook | Later insn override earlier ones. */
|
2180 | e6e5906b | pbrook | static void |
2181 | e6e5906b | pbrook | register_m68k_insns (m68k_def_t *def) |
2182 | e6e5906b | pbrook | { |
2183 | e6e5906b | pbrook | uint32_t iflags; |
2184 | e6e5906b | pbrook | |
2185 | e6e5906b | pbrook | iflags = def->insns; |
2186 | e6e5906b | pbrook | #define INSN(name, opcode, mask, isa) \
|
2187 | e6e5906b | pbrook | if (iflags & M68K_INSN_##isa) \ |
2188 | e6e5906b | pbrook | register_opcode(disas_##name, 0x##opcode, 0x##mask) |
2189 | e6e5906b | pbrook | INSN(undef, 0000, 0000, CF_A); |
2190 | e6e5906b | pbrook | INSN(arith_im, 0080, fff8, CF_A);
|
2191 | e6e5906b | pbrook | INSN(bitrev, 00c0, fff8, CF_C);
|
2192 | e6e5906b | pbrook | INSN(bitop_reg, 0100, f1c0, CF_A);
|
2193 | e6e5906b | pbrook | INSN(bitop_reg, 0140, f1c0, CF_A);
|
2194 | e6e5906b | pbrook | INSN(bitop_reg, 0180, f1c0, CF_A);
|
2195 | e6e5906b | pbrook | INSN(bitop_reg, 01c0, f1c0, CF_A);
|
2196 | e6e5906b | pbrook | INSN(arith_im, 0280, fff8, CF_A);
|
2197 | e6e5906b | pbrook | INSN(byterev, 02c0, fff8, CF_A);
|
2198 | e6e5906b | pbrook | INSN(arith_im, 0480, fff8, CF_A);
|
2199 | e6e5906b | pbrook | INSN(ff1, 04c0, fff8, CF_C);
|
2200 | e6e5906b | pbrook | INSN(arith_im, 0680, fff8, CF_A);
|
2201 | e6e5906b | pbrook | INSN(bitop_im, 0800, ffc0, CF_A);
|
2202 | e6e5906b | pbrook | INSN(bitop_im, 0840, ffc0, CF_A);
|
2203 | e6e5906b | pbrook | INSN(bitop_im, 0880, ffc0, CF_A);
|
2204 | e6e5906b | pbrook | INSN(bitop_im, 08c0, ffc0, CF_A);
|
2205 | e6e5906b | pbrook | INSN(arith_im, 0a80, fff8, CF_A);
|
2206 | e6e5906b | pbrook | INSN(arith_im, 0c00, ff38, CF_A);
|
2207 | e6e5906b | pbrook | INSN(move, 1000, f000, CF_A);
|
2208 | e6e5906b | pbrook | INSN(move, 2000, f000, CF_A);
|
2209 | e6e5906b | pbrook | INSN(move, 3000, f000, CF_A);
|
2210 | e6e5906b | pbrook | INSN(strldsr, 40e7, ffff, CF_A); |
2211 | e6e5906b | pbrook | INSN(negx, 4080, fff8, CF_A);
|
2212 | e6e5906b | pbrook | INSN(move_from_sr, 40c0, fff8, CF_A);
|
2213 | e6e5906b | pbrook | INSN(lea, 41c0, f1c0, CF_A);
|
2214 | e6e5906b | pbrook | INSN(clr, 4200, ff00, CF_A);
|
2215 | e6e5906b | pbrook | INSN(undef, 42c0, ffc0, CF_A);
|
2216 | e6e5906b | pbrook | INSN(move_from_ccr, 42c0, fff8, CF_A);
|
2217 | e6e5906b | pbrook | INSN(neg, 4480, fff8, CF_A);
|
2218 | e6e5906b | pbrook | INSN(move_to_ccr, 44c0, ffc0, CF_A);
|
2219 | e6e5906b | pbrook | INSN(not, 4680, fff8, CF_A);
|
2220 | e6e5906b | pbrook | INSN(move_to_sr, 46c0, ffc0, CF_A);
|
2221 | e6e5906b | pbrook | INSN(pea, 4840, ffc0, CF_A);
|
2222 | e6e5906b | pbrook | INSN(swap, 4840, fff8, CF_A);
|
2223 | e6e5906b | pbrook | INSN(movem, 48c0, fbc0, CF_A);
|
2224 | e6e5906b | pbrook | INSN(ext, 4880, fff8, CF_A);
|
2225 | e6e5906b | pbrook | INSN(ext, 48c0, fff8, CF_A);
|
2226 | e6e5906b | pbrook | INSN(ext, 49c0, fff8, CF_A);
|
2227 | e6e5906b | pbrook | INSN(tst, 4a00, ff00, CF_A);
|
2228 | e6e5906b | pbrook | INSN(tas, 4ac0, ffc0, CF_B);
|
2229 | e6e5906b | pbrook | INSN(halt, 4ac8, ffff, CF_A);
|
2230 | e6e5906b | pbrook | INSN(pulse, 4acc, ffff, CF_A);
|
2231 | e6e5906b | pbrook | INSN(illegal, 4afc, ffff, CF_A);
|
2232 | e6e5906b | pbrook | INSN(mull, 4c00, ffc0, CF_A);
|
2233 | e6e5906b | pbrook | INSN(divl, 4c40, ffc0, CF_A);
|
2234 | e6e5906b | pbrook | INSN(sats, 4c80, fff8, CF_B);
|
2235 | e6e5906b | pbrook | INSN(trap, 4e40, fff0, CF_A);
|
2236 | e6e5906b | pbrook | INSN(link, 4e50, fff8, CF_A);
|
2237 | e6e5906b | pbrook | INSN(unlk, 4e58, fff8, CF_A);
|
2238 | e6e5906b | pbrook | INSN(move_to_usp, 4e60, fff8, CF_B);
|
2239 | e6e5906b | pbrook | INSN(move_from_usp, 4e68, fff8, CF_B);
|
2240 | e6e5906b | pbrook | INSN(nop, 4e71, ffff, CF_A);
|
2241 | e6e5906b | pbrook | INSN(stop, 4e72, ffff, CF_A);
|
2242 | e6e5906b | pbrook | INSN(rte, 4e73, ffff, CF_A);
|
2243 | e6e5906b | pbrook | INSN(rts, 4e75, ffff, CF_A);
|
2244 | e6e5906b | pbrook | INSN(movec, 4e7b, ffff, CF_A);
|
2245 | e6e5906b | pbrook | INSN(jump, 4e80, ffc0, CF_A);
|
2246 | e6e5906b | pbrook | INSN(jump, 4ec0, ffc0, CF_A);
|
2247 | e6e5906b | pbrook | INSN(addsubq, 5180, f1c0, CF_A);
|
2248 | e6e5906b | pbrook | INSN(scc, 50c0, f0f8, CF_A);
|
2249 | e6e5906b | pbrook | INSN(addsubq, 5080, f1c0, CF_A);
|
2250 | e6e5906b | pbrook | INSN(tpf, 51f8, fff8, CF_A); |
2251 | e6e5906b | pbrook | INSN(branch, 6000, f000, CF_A);
|
2252 | e6e5906b | pbrook | INSN(moveq, 7000, f100, CF_A);
|
2253 | e6e5906b | pbrook | INSN(mvzs, 7100, f100, CF_B);
|
2254 | e6e5906b | pbrook | INSN(or, 8000, f000, CF_A);
|
2255 | e6e5906b | pbrook | INSN(divw, 80c0, f0c0, CF_A);
|
2256 | e6e5906b | pbrook | INSN(addsub, 9000, f000, CF_A);
|
2257 | e6e5906b | pbrook | INSN(subx, 9180, f1f8, CF_A);
|
2258 | e6e5906b | pbrook | INSN(suba, 91c0, f1c0, CF_A);
|
2259 | e6e5906b | pbrook | INSN(undef_mac, a000, f000, CF_A); |
2260 | e6e5906b | pbrook | INSN(mov3q, a140, f1c0, CF_B); |
2261 | e6e5906b | pbrook | INSN(cmp, b000, f1c0, CF_B); /* cmp.b */
|
2262 | e6e5906b | pbrook | INSN(cmp, b040, f1c0, CF_B); /* cmp.w */
|
2263 | e6e5906b | pbrook | INSN(cmpa, b0c0, f1c0, CF_B); /* cmpa.w */
|
2264 | e6e5906b | pbrook | INSN(cmp, b080, f1c0, CF_A); |
2265 | e6e5906b | pbrook | INSN(cmpa, b1c0, f1c0, CF_A); |
2266 | e6e5906b | pbrook | INSN(eor, b180, f1c0, CF_A); |
2267 | e6e5906b | pbrook | INSN(and, c000, f000, CF_A); |
2268 | e6e5906b | pbrook | INSN(mulw, c0c0, f0c0, CF_A); |
2269 | e6e5906b | pbrook | INSN(addsub, d000, f000, CF_A); |
2270 | e6e5906b | pbrook | INSN(addx, d180, f1f8, CF_A); |
2271 | e6e5906b | pbrook | INSN(adda, d1c0, f1c0, CF_A); |
2272 | e6e5906b | pbrook | INSN(shift_im, e080, f0f0, CF_A); |
2273 | e6e5906b | pbrook | INSN(shift_reg, e0a0, f0f0, CF_A); |
2274 | e6e5906b | pbrook | INSN(undef_fpu, f000, f000, CF_A); |
2275 | e6e5906b | pbrook | INSN(fpu, f200, ffc0, CF_FPU); |
2276 | e6e5906b | pbrook | INSN(fbcc, f280, ffc0, CF_FPU); |
2277 | e6e5906b | pbrook | INSN(intouch, f340, ffc0, CF_A); |
2278 | e6e5906b | pbrook | INSN(cpushl, f428, ff38, CF_A); |
2279 | e6e5906b | pbrook | INSN(wddata, fb00, ff00, CF_A); |
2280 | e6e5906b | pbrook | INSN(wdebug, fbc0, ffc0, CF_A); |
2281 | e6e5906b | pbrook | #undef INSN
|
2282 | e6e5906b | pbrook | } |
2283 | e6e5906b | pbrook | |
2284 | e6e5906b | pbrook | /* ??? Some of this implementation is not exception safe. We should always
|
2285 | e6e5906b | pbrook | write back the result to memory before setting the condition codes. */
|
2286 | e6e5906b | pbrook | static void disas_m68k_insn(CPUState * env, DisasContext *s) |
2287 | e6e5906b | pbrook | { |
2288 | e6e5906b | pbrook | uint16_t insn; |
2289 | e6e5906b | pbrook | |
2290 | e6e5906b | pbrook | insn = lduw(s->pc); |
2291 | e6e5906b | pbrook | s->pc += 2;
|
2292 | e6e5906b | pbrook | |
2293 | e6e5906b | pbrook | opcode_table[insn](s, insn); |
2294 | e6e5906b | pbrook | } |
2295 | e6e5906b | pbrook | |
2296 | e6e5906b | pbrook | #if 0
|
2297 | e6e5906b | pbrook | /* Save the result of a floating point operation. */
|
2298 | e6e5906b | pbrook | static void expand_op_fp_result(qOP *qop)
|
2299 | e6e5906b | pbrook | {
|
2300 | e6e5906b | pbrook | gen_op_movf64(QREG_FP_RESULT, qop->args[0]);
|
2301 | e6e5906b | pbrook | }
|
2302 | e6e5906b | pbrook | |
2303 | e6e5906b | pbrook | /* Dummy op to indicate that the flags have been set. */
|
2304 | e6e5906b | pbrook | static void expand_op_flags_set(qOP *qop)
|
2305 | e6e5906b | pbrook | {
|
2306 | e6e5906b | pbrook | }
|
2307 | e6e5906b | pbrook | |
2308 | e6e5906b | pbrook | /* Convert the confition codes into CC_OP_FLAGS format. */
|
2309 | e6e5906b | pbrook | static void expand_op_flush_flags(qOP *qop)
|
2310 | e6e5906b | pbrook | {
|
2311 | e6e5906b | pbrook | int cc_opreg;
|
2312 | e6e5906b | pbrook | |
2313 | e6e5906b | pbrook | if (qop->args[0] == CC_OP_DYNAMIC)
|
2314 | e6e5906b | pbrook | cc_opreg = QREG_CC_OP;
|
2315 | e6e5906b | pbrook | else
|
2316 | e6e5906b | pbrook | cc_opreg = gen_im32(qop->args[0]);
|
2317 | e6e5906b | pbrook | gen_op_helper32(QREG_NULL, cc_opreg, HELPER_flush_flags);
|
2318 | e6e5906b | pbrook | }
|
2319 | e6e5906b | pbrook | |
2320 | e6e5906b | pbrook | /* Set CC_DEST after a logical or direct flag setting operation. */
|
2321 | e6e5906b | pbrook | static void expand_op_logic_cc(qOP *qop)
|
2322 | e6e5906b | pbrook | {
|
2323 | e6e5906b | pbrook | gen_op_mov32(QREG_CC_DEST, qop->args[0]);
|
2324 | e6e5906b | pbrook | }
|
2325 | e6e5906b | pbrook | |
2326 | e6e5906b | pbrook | /* Set CC_SRC and CC_DEST after an arithmetic operation. */
|
2327 | e6e5906b | pbrook | static void expand_op_update_cc_add(qOP *qop)
|
2328 | e6e5906b | pbrook | {
|
2329 | e6e5906b | pbrook | gen_op_mov32(QREG_CC_DEST, qop->args[0]);
|
2330 | e6e5906b | pbrook | gen_op_mov32(QREG_CC_SRC, qop->args[1]);
|
2331 | e6e5906b | pbrook | }
|
2332 | e6e5906b | pbrook | |
2333 | e6e5906b | pbrook | /* Update the X flag. */
|
2334 | e6e5906b | pbrook | static void expand_op_update_xflag(qOP *qop)
|
2335 | e6e5906b | pbrook | {
|
2336 | e6e5906b | pbrook | int arg0;
|
2337 | e6e5906b | pbrook | int arg1;
|
2338 | e6e5906b | pbrook | |
2339 | e6e5906b | pbrook | arg0 = qop->args[0];
|
2340 | e6e5906b | pbrook | arg1 = qop->args[1];
|
2341 | e6e5906b | pbrook | if (arg1 == QREG_NULL) {
|
2342 | e6e5906b | pbrook | /* CC_X = arg0. */
|
2343 | e6e5906b | pbrook | gen_op_mov32(QREG_CC_X, arg0);
|
2344 | e6e5906b | pbrook | } else {
|
2345 | e6e5906b | pbrook | /* CC_X = arg0 < (unsigned)arg1. */
|
2346 | e6e5906b | pbrook | gen_op_set_ltu32(QREG_CC_X, arg0, arg1);
|
2347 | e6e5906b | pbrook | }
|
2348 | e6e5906b | pbrook | }
|
2349 | e6e5906b | pbrook | |
2350 | e6e5906b | pbrook | /* Set arg0 to the contents of the X flag. */
|
2351 | e6e5906b | pbrook | static void expand_op_get_xflag(qOP *qop)
|
2352 | e6e5906b | pbrook | {
|
2353 | e6e5906b | pbrook | gen_op_mov32(qop->args[0], QREG_CC_X);
|
2354 | e6e5906b | pbrook | }
|
2355 | e6e5906b | pbrook | |
2356 | e6e5906b | pbrook | /* Expand a shift by immediate. The ISA only allows shifts by 1-8, so we
|
2357 | e6e5906b | pbrook | already know the shift is within range. */
|
2358 | e6e5906b | pbrook | static inline void expand_shift_im(qOP *qop, int right, int arith)
|
2359 | e6e5906b | pbrook | {
|
2360 | e6e5906b | pbrook | int val;
|
2361 | e6e5906b | pbrook | int reg;
|
2362 | e6e5906b | pbrook | int tmp;
|
2363 | e6e5906b | pbrook | int im;
|
2364 | e6e5906b | pbrook | |
2365 | e6e5906b | pbrook | reg = qop->args[0];
|
2366 | e6e5906b | pbrook | im = qop->args[1];
|
2367 | e6e5906b | pbrook | tmp = gen_im32(im);
|
2368 | e6e5906b | pbrook | val = gen_new_qreg(QMODE_I32);
|
2369 | e6e5906b | pbrook | gen_op_mov32(val, reg);
|
2370 | e6e5906b | pbrook | gen_op_mov32(QREG_CC_DEST, val);
|
2371 | e6e5906b | pbrook | gen_op_mov32(QREG_CC_SRC, tmp);
|
2372 | e6e5906b | pbrook | if (right) {
|
2373 | e6e5906b | pbrook | if (arith) {
|
2374 | e6e5906b | pbrook | gen_op_sar32(reg, val, tmp);
|
2375 | e6e5906b | pbrook | } else {
|
2376 | e6e5906b | pbrook | gen_op_shr32(reg, val, tmp);
|
2377 | e6e5906b | pbrook | }
|
2378 | e6e5906b | pbrook | if (im == 1)
|
2379 | e6e5906b | pbrook | tmp = QREG_NULL;
|
2380 | e6e5906b | pbrook | else
|
2381 | e6e5906b | pbrook | tmp = gen_im32(im - 1);
|
2382 | e6e5906b | pbrook | } else {
|
2383 | e6e5906b | pbrook | gen_op_shl32(reg, val, tmp);
|
2384 | e6e5906b | pbrook | tmp = gen_im32(32 - im);
|
2385 | e6e5906b | pbrook | }
|
2386 | e6e5906b | pbrook | if (tmp != QREG_NULL)
|
2387 | e6e5906b | pbrook | gen_op_shr32(val, val, tmp);
|
2388 | e6e5906b | pbrook | gen_op_and32(QREG_CC_X, val, gen_im32(1));
|
2389 | e6e5906b | pbrook | }
|
2390 | e6e5906b | pbrook | |
2391 | e6e5906b | pbrook | static void expand_op_shl_im_cc(qOP *qop)
|
2392 | e6e5906b | pbrook | {
|
2393 | e6e5906b | pbrook | expand_shift_im(qop, 0, 0);
|
2394 | e6e5906b | pbrook | }
|
2395 | e6e5906b | pbrook | |
2396 | e6e5906b | pbrook | static void expand_op_shr_im_cc(qOP *qop)
|
2397 | e6e5906b | pbrook | {
|
2398 | e6e5906b | pbrook | expand_shift_im(qop, 1, 0);
|
2399 | e6e5906b | pbrook | }
|
2400 | e6e5906b | pbrook | |
2401 | e6e5906b | pbrook | static void expand_op_sar_im_cc(qOP *qop)
|
2402 | e6e5906b | pbrook | {
|
2403 | e6e5906b | pbrook | expand_shift_im(qop, 1, 1);
|
2404 | e6e5906b | pbrook | }
|
2405 | e6e5906b | pbrook | |
2406 | e6e5906b | pbrook | /* Expand a shift by register. */
|
2407 | e6e5906b | pbrook | /* ??? This gives incorrect answers for shifts by 0 or >= 32 */
|
2408 | e6e5906b | pbrook | static inline void expand_shift_reg(qOP *qop, int right, int arith)
|
2409 | e6e5906b | pbrook | {
|
2410 | e6e5906b | pbrook | int val;
|
2411 | e6e5906b | pbrook | int reg;
|
2412 | e6e5906b | pbrook | int shift;
|
2413 | e6e5906b | pbrook | int tmp;
|
2414 | e6e5906b | pbrook | |
2415 | e6e5906b | pbrook | reg = qop->args[0];
|
2416 | e6e5906b | pbrook | shift = qop->args[1];
|
2417 | e6e5906b | pbrook | val = gen_new_qreg(QMODE_I32);
|
2418 | e6e5906b | pbrook | gen_op_mov32(val, reg);
|
2419 | e6e5906b | pbrook | gen_op_mov32(QREG_CC_DEST, val);
|
2420 | e6e5906b | pbrook | gen_op_mov32(QREG_CC_SRC, shift);
|
2421 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32);
|
2422 | e6e5906b | pbrook | if (right) {
|
2423 | e6e5906b | pbrook | if (arith) {
|
2424 | e6e5906b | pbrook | gen_op_sar32(reg, val, shift);
|
2425 | e6e5906b | pbrook | } else {
|
2426 | e6e5906b | pbrook | gen_op_shr32(reg, val, shift);
|
2427 | e6e5906b | pbrook | }
|
2428 | e6e5906b | pbrook | gen_op_sub32(tmp, shift, gen_im32(1));
|
2429 | e6e5906b | pbrook | } else {
|
2430 | e6e5906b | pbrook | gen_op_shl32(reg, val, shift);
|
2431 | e6e5906b | pbrook | gen_op_sub32(tmp, gen_im32(31), shift);
|
2432 | e6e5906b | pbrook | }
|
2433 | e6e5906b | pbrook | gen_op_shl32(val, val, tmp);
|
2434 | e6e5906b | pbrook | gen_op_and32(QREG_CC_X, val, gen_im32(1));
|
2435 | e6e5906b | pbrook | }
|
2436 | e6e5906b | pbrook | |
2437 | e6e5906b | pbrook | static void expand_op_shl_cc(qOP *qop)
|
2438 | e6e5906b | pbrook | {
|
2439 | e6e5906b | pbrook | expand_shift_reg(qop, 0, 0);
|
2440 | e6e5906b | pbrook | }
|
2441 | e6e5906b | pbrook | |
2442 | e6e5906b | pbrook | static void expand_op_shr_cc(qOP *qop)
|
2443 | e6e5906b | pbrook | {
|
2444 | e6e5906b | pbrook | expand_shift_reg(qop, 1, 0);
|
2445 | e6e5906b | pbrook | }
|
2446 | e6e5906b | pbrook | |
2447 | e6e5906b | pbrook | static void expand_op_sar_cc(qOP *qop)
|
2448 | e6e5906b | pbrook | {
|
2449 | e6e5906b | pbrook | expand_shift_reg(qop, 1, 1);
|
2450 | e6e5906b | pbrook | }
|
2451 | e6e5906b | pbrook | |
2452 | e6e5906b | pbrook | /* Set the Z flag to (arg0 & arg1) == 0. */
|
2453 | e6e5906b | pbrook | static void expand_op_btest(qOP *qop)
|
2454 | e6e5906b | pbrook | {
|
2455 | e6e5906b | pbrook | int tmp;
|
2456 | e6e5906b | pbrook | int l1;
|
2457 | e6e5906b | pbrook | |
2458 | e6e5906b | pbrook | l1 = gen_new_label();
|
2459 | e6e5906b | pbrook | tmp = gen_new_qreg(QMODE_I32);
|
2460 | e6e5906b | pbrook | gen_op_and32(tmp, qop->args[0], qop->args[1]);
|
2461 | e6e5906b | pbrook | gen_op_and32(QREG_CC_DEST, QREG_CC_DEST, gen_im32(~(uint32_t)CCF_Z));
|
2462 | e6e5906b | pbrook | gen_op_jmp_nz32(tmp, l1);
|
2463 | e6e5906b | pbrook | gen_op_or32(QREG_CC_DEST, QREG_CC_DEST, gen_im32(CCF_Z));
|
2464 | e6e5906b | pbrook | gen_op_label(l1);
|
2465 | e6e5906b | pbrook | }
|
2466 | e6e5906b | pbrook | |
2467 | e6e5906b | pbrook | /* arg0 += arg1 + CC_X */
|
2468 | e6e5906b | pbrook | static void expand_op_addx_cc(qOP *qop)
|
2469 | e6e5906b | pbrook | {
|
2470 | e6e5906b | pbrook | int arg0 = qop->args[0];
|
2471 | e6e5906b | pbrook | int arg1 = qop->args[1];
|
2472 | e6e5906b | pbrook | int l1, l2;
|
2473 | e6e5906b | pbrook |
|
2474 | e6e5906b | pbrook | gen_op_add32 (arg0, arg0, arg1);
|
2475 | e6e5906b | pbrook | l1 = gen_new_label();
|
2476 | e6e5906b | pbrook | l2 = gen_new_label();
|
2477 | e6e5906b | pbrook | gen_op_jmp_z32(QREG_CC_X, l1);
|
2478 | e6e5906b | pbrook | gen_op_add32(arg0, arg0, gen_im32(1));
|
2479 | e6e5906b | pbrook | gen_op_mov32(QREG_CC_OP, gen_im32(CC_OP_ADDX));
|
2480 | e6e5906b | pbrook | gen_op_set_leu32(QREG_CC_X, arg0, arg1);
|
2481 | e6e5906b | pbrook | gen_op_jmp(l2);
|
2482 | e6e5906b | pbrook | gen_set_label(l1);
|
2483 | e6e5906b | pbrook | gen_op_mov32(QREG_CC_OP, gen_im32(CC_OP_ADD));
|
2484 | e6e5906b | pbrook | gen_op_set_ltu32(QREG_CC_X, arg0, arg1);
|
2485 | e6e5906b | pbrook | gen_set_label(l2);
|
2486 | e6e5906b | pbrook | }
|
2487 | e6e5906b | pbrook | |
2488 | e6e5906b | pbrook | /* arg0 -= arg1 + CC_X */
|
2489 | e6e5906b | pbrook | static void expand_op_subx_cc(qOP *qop)
|
2490 | e6e5906b | pbrook | {
|
2491 | e6e5906b | pbrook | int arg0 = qop->args[0];
|
2492 | e6e5906b | pbrook | int arg1 = qop->args[1];
|
2493 | e6e5906b | pbrook | int l1, l2;
|
2494 | e6e5906b | pbrook | |
2495 | e6e5906b | pbrook | l1 = gen_new_label();
|
2496 | e6e5906b | pbrook | l2 = gen_new_label();
|
2497 | e6e5906b | pbrook | gen_op_jmp_z32(QREG_CC_X, l1);
|
2498 | e6e5906b | pbrook | gen_op_set_leu32(QREG_CC_X, arg0, arg1);
|
2499 | e6e5906b | pbrook | gen_op_sub32(arg0, arg0, gen_im32(1));
|
2500 | e6e5906b | pbrook | gen_op_mov32(QREG_CC_OP, gen_im32(CC_OP_SUBX));
|
2501 | e6e5906b | pbrook | gen_op_jmp(l2);
|
2502 | e6e5906b | pbrook | gen_set_label(l1);
|
2503 | e6e5906b | pbrook | gen_op_set_ltu32(QREG_CC_X, arg0, arg1);
|
2504 | e6e5906b | pbrook | gen_op_mov32(QREG_CC_OP, gen_im32(CC_OP_SUB));
|
2505 | e6e5906b | pbrook | gen_set_label(l2);
|
2506 | e6e5906b | pbrook | gen_op_sub32 (arg0, arg0, arg1);
|
2507 | e6e5906b | pbrook | }
|
2508 | e6e5906b | pbrook | |
2509 | e6e5906b | pbrook | /* Expand target specific ops to generic qops. */
|
2510 | e6e5906b | pbrook | static void expand_target_qops(void)
|
2511 | e6e5906b | pbrook | {
|
2512 | e6e5906b | pbrook | qOP *qop;
|
2513 | e6e5906b | pbrook | qOP *next;
|
2514 | e6e5906b | pbrook | int c;
|
2515 | e6e5906b | pbrook | |
2516 | e6e5906b | pbrook | /* Copy the list of qops, expanding target specific ops as we go. */
|
2517 | e6e5906b | pbrook | qop = gen_first_qop;
|
2518 | e6e5906b | pbrook | gen_first_qop = NULL;
|
2519 | e6e5906b | pbrook | gen_last_qop = NULL;
|
2520 | e6e5906b | pbrook | for (; qop; qop = next) {
|
2521 | e6e5906b | pbrook | c = qop->opcode;
|
2522 | e6e5906b | pbrook | next = qop->next;
|
2523 | e6e5906b | pbrook | if (c < FIRST_TARGET_OP) {
|
2524 | e6e5906b | pbrook | qop->prev = gen_last_qop;
|
2525 | e6e5906b | pbrook | qop->next = NULL;
|
2526 | e6e5906b | pbrook | if (gen_last_qop)
|
2527 | e6e5906b | pbrook | gen_last_qop->next = qop;
|
2528 | e6e5906b | pbrook | else
|
2529 | e6e5906b | pbrook | gen_first_qop = qop;
|
2530 | e6e5906b | pbrook | gen_last_qop = qop;
|
2531 | e6e5906b | pbrook | continue;
|
2532 | e6e5906b | pbrook | }
|
2533 | e6e5906b | pbrook | switch (c) {
|
2534 | e6e5906b | pbrook | #define DEF(name, nargs, barrier) \
|
2535 | e6e5906b | pbrook | case INDEX_op_##name: \
|
2536 | e6e5906b | pbrook | expand_op_##name(qop); \
|
2537 | e6e5906b | pbrook | break;
|
2538 | e6e5906b | pbrook | #include "qop-target.def"
|
2539 | e6e5906b | pbrook | #undef DEF
|
2540 | e6e5906b | pbrook | default:
|
2541 | e6e5906b | pbrook | cpu_abort(NULL, "Unexpanded target qop");
|
2542 | e6e5906b | pbrook | }
|
2543 | e6e5906b | pbrook | }
|
2544 | e6e5906b | pbrook | }
|
2545 | e6e5906b | pbrook | |
2546 | e6e5906b | pbrook | /* ??? Implement this. */
|
2547 | e6e5906b | pbrook | static void
|
2548 | e6e5906b | pbrook | optimize_flags(void)
|
2549 | e6e5906b | pbrook | {
|
2550 | e6e5906b | pbrook | }
|
2551 | e6e5906b | pbrook | #endif
|
2552 | e6e5906b | pbrook | |
2553 | e6e5906b | pbrook | /* generate intermediate code for basic block 'tb'. */
|
2554 | 820e00f2 | ths | static inline int |
2555 | 820e00f2 | ths | gen_intermediate_code_internal(CPUState *env, TranslationBlock *tb, |
2556 | 820e00f2 | ths | int search_pc)
|
2557 | e6e5906b | pbrook | { |
2558 | e6e5906b | pbrook | DisasContext dc1, *dc = &dc1; |
2559 | e6e5906b | pbrook | uint16_t *gen_opc_end; |
2560 | e6e5906b | pbrook | int j, lj;
|
2561 | e6e5906b | pbrook | target_ulong pc_start; |
2562 | e6e5906b | pbrook | int pc_offset;
|
2563 | e6e5906b | pbrook | int last_cc_op;
|
2564 | e6e5906b | pbrook | |
2565 | e6e5906b | pbrook | /* generate intermediate code */
|
2566 | e6e5906b | pbrook | pc_start = tb->pc; |
2567 | e6e5906b | pbrook | |
2568 | e6e5906b | pbrook | dc->tb = tb; |
2569 | e6e5906b | pbrook | |
2570 | e6e5906b | pbrook | gen_opc_ptr = gen_opc_buf; |
2571 | e6e5906b | pbrook | gen_opc_end = gen_opc_buf + OPC_MAX_SIZE; |
2572 | e6e5906b | pbrook | gen_opparam_ptr = gen_opparam_buf; |
2573 | e6e5906b | pbrook | |
2574 | e6e5906b | pbrook | dc->is_jmp = DISAS_NEXT; |
2575 | e6e5906b | pbrook | dc->pc = pc_start; |
2576 | e6e5906b | pbrook | dc->cc_op = CC_OP_DYNAMIC; |
2577 | e6e5906b | pbrook | dc->singlestep_enabled = env->singlestep_enabled; |
2578 | e6e5906b | pbrook | dc->fpcr = env->fpcr; |
2579 | e6e5906b | pbrook | nb_gen_labels = 0;
|
2580 | e6e5906b | pbrook | lj = -1;
|
2581 | e6e5906b | pbrook | do {
|
2582 | e6e5906b | pbrook | free_qreg = 0;
|
2583 | e6e5906b | pbrook | pc_offset = dc->pc - pc_start; |
2584 | e6e5906b | pbrook | gen_throws_exception = NULL;
|
2585 | e6e5906b | pbrook | if (env->nb_breakpoints > 0) { |
2586 | e6e5906b | pbrook | for(j = 0; j < env->nb_breakpoints; j++) { |
2587 | e6e5906b | pbrook | if (env->breakpoints[j] == dc->pc) {
|
2588 | e6e5906b | pbrook | gen_exception(dc, dc->pc, EXCP_DEBUG); |
2589 | e6e5906b | pbrook | dc->is_jmp = DISAS_JUMP; |
2590 | e6e5906b | pbrook | break;
|
2591 | e6e5906b | pbrook | } |
2592 | e6e5906b | pbrook | } |
2593 | e6e5906b | pbrook | if (dc->is_jmp)
|
2594 | e6e5906b | pbrook | break;
|
2595 | e6e5906b | pbrook | } |
2596 | e6e5906b | pbrook | if (search_pc) {
|
2597 | e6e5906b | pbrook | j = gen_opc_ptr - gen_opc_buf; |
2598 | e6e5906b | pbrook | if (lj < j) {
|
2599 | e6e5906b | pbrook | lj++; |
2600 | e6e5906b | pbrook | while (lj < j)
|
2601 | e6e5906b | pbrook | gen_opc_instr_start[lj++] = 0;
|
2602 | e6e5906b | pbrook | } |
2603 | e6e5906b | pbrook | gen_opc_pc[lj] = dc->pc; |
2604 | e6e5906b | pbrook | gen_opc_instr_start[lj] = 1;
|
2605 | e6e5906b | pbrook | } |
2606 | e6e5906b | pbrook | last_cc_op = dc->cc_op; |
2607 | e6e5906b | pbrook | disas_m68k_insn(env, dc); |
2608 | e6e5906b | pbrook | } while (!dc->is_jmp && gen_opc_ptr < gen_opc_end &&
|
2609 | e6e5906b | pbrook | !env->singlestep_enabled && |
2610 | e6e5906b | pbrook | (pc_offset) < (TARGET_PAGE_SIZE - 32));
|
2611 | e6e5906b | pbrook | |
2612 | e6e5906b | pbrook | if (__builtin_expect(env->singlestep_enabled, 0)) { |
2613 | e6e5906b | pbrook | /* Make sure the pc is updated, and raise a debug exception. */
|
2614 | e6e5906b | pbrook | if (!dc->is_jmp) {
|
2615 | e6e5906b | pbrook | gen_flush_cc_op(dc); |
2616 | e6e5906b | pbrook | gen_op_mov32(QREG_PC, gen_im32((long)dc->pc));
|
2617 | e6e5906b | pbrook | } |
2618 | e6e5906b | pbrook | gen_op_raise_exception(EXCP_DEBUG); |
2619 | e6e5906b | pbrook | } else {
|
2620 | e6e5906b | pbrook | switch(dc->is_jmp) {
|
2621 | e6e5906b | pbrook | case DISAS_NEXT:
|
2622 | e6e5906b | pbrook | gen_flush_cc_op(dc); |
2623 | e6e5906b | pbrook | gen_jmp_tb(dc, 0, dc->pc);
|
2624 | e6e5906b | pbrook | break;
|
2625 | e6e5906b | pbrook | default:
|
2626 | e6e5906b | pbrook | case DISAS_JUMP:
|
2627 | e6e5906b | pbrook | case DISAS_UPDATE:
|
2628 | e6e5906b | pbrook | gen_flush_cc_op(dc); |
2629 | e6e5906b | pbrook | /* indicate that the hash table must be used to find the next TB */
|
2630 | e6e5906b | pbrook | gen_op_mov32(QREG_T0, gen_im32(0));
|
2631 | e6e5906b | pbrook | gen_op_exit_tb(); |
2632 | e6e5906b | pbrook | break;
|
2633 | e6e5906b | pbrook | case DISAS_TB_JUMP:
|
2634 | e6e5906b | pbrook | /* nothing more to generate */
|
2635 | e6e5906b | pbrook | break;
|
2636 | e6e5906b | pbrook | } |
2637 | e6e5906b | pbrook | } |
2638 | e6e5906b | pbrook | *gen_opc_ptr = INDEX_op_end; |
2639 | e6e5906b | pbrook | |
2640 | e6e5906b | pbrook | #ifdef DEBUG_DISAS
|
2641 | e6e5906b | pbrook | if (loglevel & CPU_LOG_TB_IN_ASM) {
|
2642 | e6e5906b | pbrook | fprintf(logfile, "----------------\n");
|
2643 | e6e5906b | pbrook | fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
|
2644 | e6e5906b | pbrook | target_disas(logfile, pc_start, dc->pc - pc_start, 0);
|
2645 | e6e5906b | pbrook | fprintf(logfile, "\n");
|
2646 | e6e5906b | pbrook | if (loglevel & (CPU_LOG_TB_OP)) {
|
2647 | e6e5906b | pbrook | fprintf(logfile, "OP:\n");
|
2648 | e6e5906b | pbrook | dump_ops(gen_opc_buf, gen_opparam_buf); |
2649 | e6e5906b | pbrook | fprintf(logfile, "\n");
|
2650 | e6e5906b | pbrook | } |
2651 | e6e5906b | pbrook | } |
2652 | e6e5906b | pbrook | #endif
|
2653 | e6e5906b | pbrook | if (search_pc) {
|
2654 | e6e5906b | pbrook | j = gen_opc_ptr - gen_opc_buf; |
2655 | e6e5906b | pbrook | lj++; |
2656 | e6e5906b | pbrook | while (lj <= j)
|
2657 | e6e5906b | pbrook | gen_opc_instr_start[lj++] = 0;
|
2658 | e6e5906b | pbrook | tb->size = 0;
|
2659 | e6e5906b | pbrook | } else {
|
2660 | e6e5906b | pbrook | tb->size = dc->pc - pc_start; |
2661 | e6e5906b | pbrook | } |
2662 | e6e5906b | pbrook | |
2663 | e6e5906b | pbrook | //optimize_flags();
|
2664 | e6e5906b | pbrook | //expand_target_qops();
|
2665 | e6e5906b | pbrook | return 0; |
2666 | e6e5906b | pbrook | } |
2667 | e6e5906b | pbrook | |
2668 | e6e5906b | pbrook | int gen_intermediate_code(CPUState *env, TranslationBlock *tb)
|
2669 | e6e5906b | pbrook | { |
2670 | e6e5906b | pbrook | return gen_intermediate_code_internal(env, tb, 0); |
2671 | e6e5906b | pbrook | } |
2672 | e6e5906b | pbrook | |
2673 | e6e5906b | pbrook | int gen_intermediate_code_pc(CPUState *env, TranslationBlock *tb)
|
2674 | e6e5906b | pbrook | { |
2675 | e6e5906b | pbrook | return gen_intermediate_code_internal(env, tb, 1); |
2676 | e6e5906b | pbrook | } |
2677 | e6e5906b | pbrook | |
2678 | e6e5906b | pbrook | CPUM68KState *cpu_m68k_init(void)
|
2679 | e6e5906b | pbrook | { |
2680 | e6e5906b | pbrook | CPUM68KState *env; |
2681 | e6e5906b | pbrook | |
2682 | e6e5906b | pbrook | env = malloc(sizeof(CPUM68KState));
|
2683 | e6e5906b | pbrook | if (!env)
|
2684 | e6e5906b | pbrook | return NULL; |
2685 | e6e5906b | pbrook | cpu_exec_init(env); |
2686 | e6e5906b | pbrook | |
2687 | e6e5906b | pbrook | memset(env, 0, sizeof(CPUM68KState)); |
2688 | e6e5906b | pbrook | /* ??? FP regs should be initialized to NaN. */
|
2689 | e6e5906b | pbrook | cpu_single_env = env; |
2690 | e6e5906b | pbrook | env->cc_op = CC_OP_FLAGS; |
2691 | e6e5906b | pbrook | return env;
|
2692 | e6e5906b | pbrook | } |
2693 | e6e5906b | pbrook | |
2694 | e6e5906b | pbrook | void cpu_m68k_close(CPUM68KState *env)
|
2695 | e6e5906b | pbrook | { |
2696 | e6e5906b | pbrook | free(env); |
2697 | e6e5906b | pbrook | } |
2698 | e6e5906b | pbrook | |
2699 | e6e5906b | pbrook | m68k_def_t *m68k_find_by_name(const char *name) |
2700 | e6e5906b | pbrook | { |
2701 | e6e5906b | pbrook | m68k_def_t *def; |
2702 | e6e5906b | pbrook | |
2703 | e6e5906b | pbrook | def = m68k_cpu_defs; |
2704 | e6e5906b | pbrook | while (def->name)
|
2705 | e6e5906b | pbrook | { |
2706 | e6e5906b | pbrook | if (strcmp(def->name, name) == 0) |
2707 | e6e5906b | pbrook | return def;
|
2708 | e6e5906b | pbrook | def++; |
2709 | e6e5906b | pbrook | } |
2710 | e6e5906b | pbrook | return NULL; |
2711 | e6e5906b | pbrook | } |
2712 | e6e5906b | pbrook | |
2713 | e6e5906b | pbrook | void cpu_m68k_register(CPUM68KState *env, m68k_def_t *def)
|
2714 | e6e5906b | pbrook | { |
2715 | e6e5906b | pbrook | register_m68k_insns(def); |
2716 | e6e5906b | pbrook | } |
2717 | e6e5906b | pbrook | |
2718 | e6e5906b | pbrook | void cpu_dump_state(CPUState *env, FILE *f,
|
2719 | e6e5906b | pbrook | int (*cpu_fprintf)(FILE *f, const char *fmt, ...), |
2720 | e6e5906b | pbrook | int flags)
|
2721 | e6e5906b | pbrook | { |
2722 | e6e5906b | pbrook | int i;
|
2723 | e6e5906b | pbrook | uint16_t sr; |
2724 | e6e5906b | pbrook | CPU_DoubleU u; |
2725 | e6e5906b | pbrook | for (i = 0; i < 8; i++) |
2726 | e6e5906b | pbrook | { |
2727 | e6e5906b | pbrook | u.d = env->fregs[i]; |
2728 | e6e5906b | pbrook | cpu_fprintf (f, "D%d = %08x A%d = %08x F%d = %08x%08x (%12g)\n",
|
2729 | e6e5906b | pbrook | i, env->dregs[i], i, env->aregs[i], |
2730 | e6e5906b | pbrook | i, u.l.upper, u.l.lower, u.d); |
2731 | e6e5906b | pbrook | } |
2732 | e6e5906b | pbrook | cpu_fprintf (f, "PC = %08x ", env->pc);
|
2733 | e6e5906b | pbrook | sr = env->sr; |
2734 | e6e5906b | pbrook | cpu_fprintf (f, "SR = %04x %c%c%c%c%c ", sr, (sr & 0x10) ? 'X' : '-', |
2735 | e6e5906b | pbrook | (sr & CCF_N) ? 'N' : '-', (sr & CCF_Z) ? 'Z' : '-', |
2736 | e6e5906b | pbrook | (sr & CCF_V) ? 'V' : '-', (sr & CCF_C) ? 'C' : '-'); |
2737 | e6e5906b | pbrook | cpu_fprintf (f, "FPRESULT = %12g\n", env->fp_result);
|
2738 | e6e5906b | pbrook | } |
2739 | e6e5906b | pbrook | |
2740 | e6e5906b | pbrook | /* ??? */
|
2741 | e6e5906b | pbrook | target_ulong cpu_get_phys_page_debug(CPUState *env, target_ulong addr) |
2742 | e6e5906b | pbrook | { |
2743 | e6e5906b | pbrook | return addr;
|
2744 | e6e5906b | pbrook | } |
2745 | e6e5906b | pbrook | |
2746 | e6e5906b | pbrook | #if defined(CONFIG_USER_ONLY)
|
2747 | e6e5906b | pbrook | |
2748 | e6e5906b | pbrook | int cpu_m68k_handle_mmu_fault (CPUState *env, target_ulong address, int rw, |
2749 | e6e5906b | pbrook | int is_user, int is_softmmu) |
2750 | e6e5906b | pbrook | { |
2751 | e6e5906b | pbrook | env->exception_index = EXCP_ACCESS; |
2752 | e6e5906b | pbrook | env->mmu.ar = address; |
2753 | e6e5906b | pbrook | return 1; |
2754 | e6e5906b | pbrook | } |
2755 | e6e5906b | pbrook | |
2756 | e6e5906b | pbrook | #else
|
2757 | e6e5906b | pbrook | |
2758 | e6e5906b | pbrook | #error not implemented
|
2759 | e6e5906b | pbrook | |
2760 | e6e5906b | pbrook | #endif |