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