Commit | Line | Data |
---|---|---|
d45a4bef JB |
1 | /* m32c.opc --- semantics for m32c opcodes. -*- mode: c -*- |
2 | ||
7b6bb8da JB |
3 | Copyright (C) 2005, 2007, 2008, 2009, 2010, 2011 |
4 | Free Software Foundation, Inc. | |
d45a4bef JB |
5 | Contributed by Red Hat, Inc. |
6 | ||
7 | This file is part of the GNU simulators. | |
8 | ||
4744ac1b JB |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 3 of the License, or | |
12 | (at your option) any later version. | |
d45a4bef | 13 | |
4744ac1b JB |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
d45a4bef JB |
18 | |
19 | You should have received a copy of the GNU General Public License | |
4744ac1b | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
d45a4bef JB |
21 | |
22 | ||
23 | #include <stdio.h> | |
24 | #include <stdlib.h> | |
25 | ||
26 | #include "cpu.h" | |
27 | #include "mem.h" | |
28 | #include "misc.h" | |
29 | #include "int.h" | |
30 | ||
31 | #define AU __attribute__((unused)) | |
32 | ||
33 | #define tprintf if (trace) printf | |
34 | ||
35 | static unsigned char | |
36 | getbyte () | |
37 | { | |
38 | int tsave = trace; | |
39 | unsigned char b; | |
40 | ||
41 | if (trace == 1) | |
42 | trace = 0; | |
43 | b = mem_get_pc (); | |
44 | regs.r_pc ++; | |
45 | trace = tsave; | |
46 | return b; | |
47 | } | |
48 | ||
49 | #define M32C_ONLY() /* FIXME: add something here */ | |
50 | ||
51 | #define GETBYTE() (op[opi++] = getbyte()) | |
52 | ||
3877a145 DD |
53 | #define UNSUPPORTED() unsupported("unsupported", m32c_opcode_pc) |
54 | #define NOTYET() unsupported("unimplemented", m32c_opcode_pc) | |
d45a4bef JB |
55 | |
56 | static void | |
57 | unsupported (char *tag, int orig_pc) | |
58 | { | |
59 | int i; | |
60 | printf("%s opcode at %08x\n", tag, orig_pc); | |
61 | regs.r_pc = orig_pc; | |
62 | for (i=0; i<2; i++) | |
63 | { | |
64 | int b = mem_get_pc(); | |
65 | printf(" %s", bits(b>>4, 4)); | |
66 | printf(" %s", bits(b, 4)); | |
67 | regs.r_pc ++; | |
68 | } | |
69 | printf("\n"); | |
70 | regs.r_pc = orig_pc; | |
71 | for (i=0; i<6; i++) | |
72 | { | |
73 | printf(" %02x", mem_get_pc ()); | |
74 | regs.r_pc ++; | |
75 | } | |
76 | printf("\n"); | |
77 | exit(1); | |
78 | } | |
79 | ||
80 | static int | |
81 | IMM(int bytes) | |
82 | { | |
83 | int rv = 0; | |
84 | switch (bytes) | |
85 | { | |
86 | case 1: | |
87 | rv = mem_get_qi (get_reg(pc)); | |
88 | break; | |
89 | case 2: | |
90 | rv = mem_get_hi (get_reg(pc)); | |
91 | break; | |
92 | case 3: | |
93 | rv = mem_get_psi (get_reg(pc)); | |
94 | break; | |
95 | case 4: | |
96 | rv = mem_get_si (get_reg(pc)); | |
97 | break; | |
98 | } | |
99 | regs.r_pc += bytes; | |
100 | return rv; | |
101 | } | |
102 | ||
103 | #define IMM4() (immm >= 8 ? 7 - immm : immm + 1) | |
104 | ||
105 | #define NO_PREFIX() PREFIX(0,0,0) | |
106 | ||
107 | /* Indicate which sorts of prefixes are allowed for the current | |
108 | opcode. */ | |
109 | void | |
110 | prefix (src_allowed, dest_allowed, index_bytewidth) | |
111 | { | |
112 | /* At the moment, we don't do anything with this information. We | |
113 | just wanted to get the information entered in some | |
114 | machine-readable form while we were going through all the | |
115 | opcodes. */ | |
116 | } | |
117 | ||
118 | #define MATH_OP(dc,s,c,op) \ | |
119 | { \ | |
120 | int ma, mb; \ | |
121 | ma = get_src(dc); \ | |
122 | mb = s & b2mask[dc.bytes]; \ | |
123 | ll = (long long)ma op (long long)mb op c; \ | |
124 | tprintf("0x%x " #op " 0x%x " #op " 0x%x = 0x%llx\n", ma, mb, c, ll); \ | |
125 | ma = sign_ext (ma, dc.bytes * 8); \ | |
126 | mb = sign_ext (s, dc.bytes * 8); \ | |
127 | v = ma op mb op c; \ | |
128 | tprintf("%d " #op " %d " #op " %d = %d\n", ma, mb, c, v); \ | |
2b1a61a6 | 129 | set_oszc (v, dc.bytes, (1 op 1) ? (ll > b2mask[dc.bytes]) : (ll >= 0)); \ |
d45a4bef JB |
130 | put_dest (dc, v); \ |
131 | } | |
132 | ||
133 | #define LOGIC_OP(dc,s,op) \ | |
134 | { \ | |
135 | int ma, mb; \ | |
136 | ma = get_src(dc); \ | |
137 | mb = s & b2mask[dc.bytes]; \ | |
138 | v = ma op mb; \ | |
139 | tprintf("0x%x " #op " 0x%x = 0x%x\n", ma, mb, v); \ | |
140 | set_sz (v, dc.bytes); \ | |
141 | put_dest (dc, v); \ | |
142 | } | |
143 | ||
144 | #define BIT_OP(dc,bit,expr) \ | |
145 | b = get_bit2 (dc, bitindex == -1 ? bit : bitindex); \ | |
146 | v = expr; \ | |
147 | tprintf ("b=%d, bit=%d, carry=%d, %s = %d\n", \ | |
148 | b, bitindex == -1 ? bit : bitindex, carry, #expr, v); \ | |
149 | put_bit2 (dc, bitindex == -1 ? bit : bitindex, v); | |
150 | ||
151 | #define BIT_OPC(dc,bit,expr) \ | |
152 | b = get_bit2 (dc, bitindex == -1 ? bit : bitindex); \ | |
153 | v = expr; \ | |
154 | tprintf ("b=%d, bit=%d, carry=%d, %s = %d\n", \ | |
155 | b, bitindex == -1 ? bit : bitindex, carry, #expr, v); \ | |
156 | set_c (v); | |
157 | ||
158 | #define carry (FLAG_C ? 1 : 0) | |
159 | ||
160 | static void | |
161 | cmp (int d, int s, int bytes) | |
162 | { | |
163 | int a, b, f=0; | |
164 | a = d - s; | |
165 | b = sign_ext (d, bytes*8) - sign_ext (s, bytes*8); | |
166 | tprintf ("cmp: %x - %x = %08x, %x - %x = %d\n", | |
167 | d, s, a, | |
168 | sign_ext(d,bytes*8), sign_ext(s,bytes*8), b); | |
169 | ||
170 | if (b == 0) | |
171 | f |= FLAGBIT_Z; | |
172 | if (b & b2signbit[bytes]) | |
173 | f |= FLAGBIT_S; | |
174 | if ((d & b2mask[bytes]) >= (s & b2mask[bytes])) | |
175 | f |= FLAGBIT_C; | |
176 | if (b < b2minsigned[bytes] || b > b2maxsigned[bytes]) | |
177 | f |= FLAGBIT_O; | |
178 | ||
179 | set_flags (FLAGBIT_Z | FLAGBIT_S | FLAGBIT_O | FLAGBIT_C, f); | |
180 | } | |
181 | ||
182 | static void | |
183 | dadd_op (int ddd, int dd, int sss, int ss, int imm, int add, int cy, int w) | |
184 | { | |
185 | srcdest sc, dc; | |
186 | int a, b=0, res; | |
187 | ||
188 | prefix (0, 0, 0); | |
189 | ||
190 | if (!imm) | |
191 | { | |
192 | sc = decode_src23 (sss, ss, w+1); | |
193 | b = get_src (sc); | |
194 | } | |
195 | dc = decode_dest23 (ddd, dd, w+1); | |
196 | a = get_src (dc); | |
197 | if (imm) | |
198 | b = IMM(w+1); | |
199 | ||
200 | a = bcd2int(a, w); | |
201 | b = bcd2int(b, w); | |
202 | ||
203 | tprintf("decimal: %d %s %d", a, add?"+":"-", b); | |
204 | if (cy) | |
205 | tprintf(" c=%d", carry); | |
206 | ||
207 | if (add) | |
208 | { | |
209 | res = a + b; | |
210 | if (cy) | |
211 | res += carry; | |
212 | cy = res > (w ? 9999 : 99); | |
213 | } | |
214 | else | |
215 | { | |
216 | res = a - b; | |
217 | if (cy) | |
218 | res -= (1-carry); | |
219 | cy = res >= 0; | |
220 | if (res < 0) | |
221 | res += w ? 10000 : 100; | |
222 | } | |
223 | ||
224 | res = int2bcd (res, w); | |
225 | tprintf(" = %x\n", res); | |
226 | ||
227 | set_szc (res, w+1, cy); | |
228 | ||
229 | put_dest (dc, res); | |
230 | } | |
231 | #define DADDV(A,C) dadd_op(ddd, dd, sss, ss, 0, A, C, w) | |
232 | #define DADDI(A,C) dadd_op(ddd, dd, 0, 0, 1, A, C, w) | |
233 | ||
234 | static void | |
235 | div_op (int sss, int ss, int u, int x, int bytes) | |
236 | { | |
237 | srcdest sc; | |
238 | int s, v, a, b; | |
239 | ||
240 | if (sss == -1) | |
241 | s = IMM(bytes); | |
242 | else | |
243 | { | |
244 | sc = decode_dest23 (sss, ss, bytes); | |
245 | s = get_src (sc); | |
246 | } | |
247 | ||
248 | v = get_reg (bytes > 1 ? r2r0 : r0); | |
249 | ||
250 | if (!u) | |
251 | { | |
252 | /* FIXME? do we sign extend a0/a1 to .L? Docs say zero extend. */ | |
253 | s = sign_ext (s, bytes*8); | |
254 | v = sign_ext (v, bytes*8); | |
255 | } | |
256 | ||
257 | if (s == 0) | |
258 | { | |
259 | set_flags (FLAGBIT_O, FLAGBIT_O); | |
260 | return; | |
261 | } | |
262 | ||
263 | if (u) | |
264 | { | |
265 | a = (unsigned int)v / (unsigned int)s; | |
266 | b = (unsigned int)v % (unsigned int)s; | |
267 | } | |
268 | else | |
269 | { | |
270 | a = v / s; | |
271 | b = v % s; | |
272 | } | |
273 | if (x) | |
274 | { | |
275 | if ((s > 0 && b < 0) | |
276 | || (s < 0 && b > 0)) | |
277 | { | |
278 | a --; | |
279 | b += s; | |
280 | } | |
281 | } | |
282 | tprintf ("%d / %d = %d rem %d\n", v, s, a, b); | |
283 | if ((!u && (a > b2maxsigned[bytes] | |
284 | || a < b2minsigned[bytes])) | |
285 | || (u && (a > b2mask[bytes]))) | |
286 | set_flags (FLAGBIT_O, FLAGBIT_O); | |
287 | else | |
288 | set_flags (FLAGBIT_O, 0); | |
289 | ||
290 | switch (bytes) | |
291 | { | |
292 | case 1: | |
293 | put_reg (r0l, a); | |
294 | put_reg (r0h, b); | |
295 | break; | |
296 | case 2: | |
297 | put_reg (r0, a); | |
298 | put_reg (r2, b); | |
299 | break; | |
300 | case 4: | |
301 | put_reg (r2r0, a); | |
302 | break; | |
303 | } | |
304 | } | |
305 | ||
306 | static void | |
307 | index_op (int sss, int ss, int do_s, int do_d, int scale, int w) | |
308 | { | |
309 | srcdest sc = decode_src23 (sss, ss, w+1); | |
310 | int v = get_src (sc) * scale; | |
311 | tprintf("%d = %d * %d, %d %d\n", v, get_src(sc), scale, do_s, do_d); | |
312 | decode_index (do_s * v, do_d * v); | |
313 | } | |
314 | #define INDEXOP(scale,do_s,do_d) \ | |
315 | index_op (sss, ss, do_s, do_d, scale, w); goto next_opcode | |
316 | ||
317 | static void | |
318 | rot_op (srcdest sd, int rotc, int count) | |
319 | { | |
320 | int mask = (sd.bytes == 2) ? 0xffff : 0xff; | |
321 | int msb = (sd.bytes == 2) ? 0x8000 : 0x80; | |
322 | int v = get_src (sd); | |
323 | int c = carry, ct; | |
324 | ||
325 | tprintf("%s %x by %d\n", rotc ? "rotc" : "rot", v, count); | |
326 | tprintf (": %s %d\n", bits(v, 8*sd.bytes), c); | |
327 | while (count > 0) | |
328 | { | |
329 | ct = (v & msb) ? 1 : 0; | |
330 | v <<= 1; | |
331 | v |= rotc ? c : ct; | |
332 | v &= mask; | |
333 | c = ct; | |
334 | tprintf (": %s %d\n", bits(v, 8*sd.bytes), c); | |
335 | count --; | |
336 | } | |
337 | while (count < 0) | |
338 | { | |
339 | ct = v & 1; | |
340 | v >>= 1; | |
341 | v |= (rotc ? c : ct) * msb; | |
342 | c = ct; | |
343 | tprintf (": %s %d\n", bits(v, 8*sd.bytes), c); | |
344 | count ++; | |
345 | } | |
346 | put_dest (sd, v); | |
347 | set_szc (v, sd.bytes, c); | |
348 | } | |
349 | ||
350 | static void | |
351 | shift_op (srcdest sd, int arith, int count, int setc) | |
352 | { | |
353 | int mask = (sd.bytes == 2) ? 0xffff : 0xff; | |
354 | int msb = (sd.bytes == 2) ? 0x8000 : 0x80; | |
355 | int v = get_src (sd); | |
356 | int c = 0; | |
357 | int o = 0; | |
358 | ||
359 | if (sd.bytes == 4) | |
360 | { | |
361 | mask = 0xffffffffU; | |
362 | msb = 0x80000000U; | |
363 | } | |
364 | ||
365 | tprintf("%s %x by %d\n", arith ? "sha" : "shl", v, count); | |
366 | tprintf (": %s %d %d\n", bits(v, 8*sd.bytes), c, o); | |
367 | while (count > 0) | |
368 | { | |
369 | c = (v & msb) ? 1 : 0; | |
370 | v <<= 1; | |
371 | v &= mask; | |
372 | if (c != ((v & msb) ? 1 : 0)) | |
373 | o = 1; | |
374 | tprintf (": %s %d %d\n", bits(v, 8*sd.bytes), c, o); | |
375 | count --; | |
376 | } | |
377 | while (count < 0) | |
378 | { | |
379 | c = v & 1; | |
380 | if (arith) | |
381 | v = (v & msb) | (v >> 1); | |
382 | else | |
383 | v = (v >> 1) & (msb - 1); | |
384 | tprintf (": %s %d %d\n", bits(v, 8*sd.bytes), c, o); | |
385 | count ++; | |
386 | } | |
387 | put_dest (sd, v); | |
388 | set_sz (v, sd.bytes); | |
389 | if (setc) | |
390 | set_c (c); | |
391 | set_flags (FLAGBIT_O, o ? FLAGBIT_O : 0); | |
392 | } | |
393 | ||
3877a145 DD |
394 | static int pcs[16]; |
395 | static int ipcs = 0; | |
396 | ||
d45a4bef JB |
397 | int |
398 | decode_m32c() | |
399 | { | |
400 | unsigned char op[40]; | |
401 | int opi; | |
d45a4bef JB |
402 | int v, a, b; |
403 | long long ll; | |
404 | srcdest sc, dc; | |
405 | int imm; | |
406 | int bitindex = -1; | |
407 | int t0, t1=0, t2, t3=0; | |
408 | int ta0, ta1, dif; | |
409 | ||
410 | step_result = M32C_MAKE_STEPPED (); | |
411 | ||
412 | decode_indirect (0, 0); | |
413 | decode_index (0, 0); | |
414 | ||
415 | next_opcode: | |
416 | opi = 0; | |
3877a145 DD |
417 | m32c_opcode_pc = get_reg (pc); |
418 | ||
419 | tprintf("trace: decode pc = %06x\n", m32c_opcode_pc); | |
d45a4bef | 420 | |
3877a145 DD |
421 | if (m32c_opcode_pc == 0) |
422 | { | |
423 | int i; | |
424 | printf("Abort: PC is zero, here from:\n"); | |
425 | for (i=0; i<4; i++) | |
426 | printf(" 0x%06x\n", pcs[(ipcs+15-i)%16]); | |
427 | return M32C_MAKE_HIT_BREAK (); | |
428 | } | |
429 | pcs[ipcs++] = m32c_opcode_pc; | |
430 | ipcs %= 16; | |
d45a4bef JB |
431 | |
432 | /** VARY sss 000 001 010 011 100 */ | |
433 | /** VARY ddd 000 001 010 011 100 */ | |
434 | ||
435 | /** 0000 1001 indirect dest */ | |
436 | ||
437 | decode_indirect (0, 1); | |
438 | goto next_opcode; | |
439 | ||
440 | /** 0100 0001 indirect src */ | |
441 | ||
442 | decode_indirect (1, 0); | |
443 | goto next_opcode; | |
444 | ||
445 | /** 0100 1001 indirect src and dest */ | |
446 | ||
447 | decode_indirect (1, 1); | |
448 | goto next_opcode; | |
449 | ||
450 | /** 1010 ddd w dd01 1111 ABS.size dest */ | |
451 | ||
452 | prefix (0, 1, 0); | |
453 | dc = decode_dest23 (ddd, dd, w+1); | |
454 | v = sign_ext (get_src (dc), w?16:8); | |
455 | a = v<0 ? -v : v; | |
456 | tprintf("abs(%d) = %d\n", v, a); | |
457 | set_osz(a, w+1); | |
458 | put_dest (dc, a); | |
459 | ||
460 | /** 0000 0001 1000 ddd w dd10 1110 ADC.size #IMM,dest */ | |
461 | ||
462 | prefix (0, 0, 0); | |
463 | dc = decode_dest23 (ddd, dd, w+1); | |
464 | imm = IMM (w+1); | |
465 | MATH_OP (dc, imm, carry, +); | |
466 | ||
467 | /** 0000 0001 1sss ddd w dd ss 0100 ADC.size src,dest */ | |
468 | ||
469 | prefix (0, 0, 0); | |
470 | sc = decode_src23 (sss, ss, w+1); | |
471 | dc = decode_dest23 (ddd, dd, w+1); | |
472 | b = get_src (sc); | |
473 | MATH_OP (dc, b, carry, +); | |
474 | ||
475 | /** 1011 ddd w dd01 1110 ADCF.size dest */ | |
476 | ||
477 | prefix (0, 1, 0); | |
478 | dc = decode_dest23 (ddd, dd, w+1); | |
479 | MATH_OP (dc, 0, carry, +); | |
480 | ||
481 | /** 1000 ddd w dd10 1110 ADD.size:G #IMM,dest */ | |
482 | ||
483 | prefix (0, 1, 0); | |
484 | dc = decode_dest23(ddd, dd, w+1); | |
485 | imm = IMM(w+1); | |
486 | MATH_OP (dc, imm, 0, +); | |
487 | ||
488 | /** 1000 ddd0 dd11 0001 ADD.L:G #IMM,dest */ | |
489 | ||
490 | prefix (0, 1, 0); | |
491 | dc = decode_dest23(ddd, dd, 4); | |
492 | imm = IMM(4); | |
493 | MATH_OP (dc, imm, 0, +); | |
494 | ||
495 | /** 111L ddd w dd11 immm ADD.size:Q #IMM,dest */ | |
496 | ||
497 | prefix (0, 1, 0); | |
498 | dc = decode_dest23(ddd, dd, L ? 4 : (w+1)); | |
499 | imm = sign_ext (immm, 4); | |
500 | MATH_OP (dc, imm, 0, +); | |
501 | ||
502 | /** 00dd 011w ADD.size:S #IMM,dest */ | |
503 | ||
504 | prefix (0, 1, 0); | |
505 | dc = decode_dest2(dd, w+1); | |
506 | imm = IMM (w+1); | |
507 | MATH_OP (dc, imm, 0, +); | |
508 | ||
509 | /** 10i0 110d ADD.L:S #IMM,A0/A1 */ | |
510 | ||
511 | prefix (0, 0, 0); | |
512 | dc = reg_sd (d ? a1 : a0); | |
513 | imm = i ? 2 : 1; | |
514 | MATH_OP (dc, imm, 0, +); | |
515 | ||
516 | /** 1sss ddd w dd ss 1000 ADD.size:G src,dest */ | |
517 | ||
518 | prefix (1, 1, 0); | |
519 | sc = decode_src23(sss, ss, w+1); | |
520 | dc = decode_dest23(ddd, dd, w+1); | |
521 | b = get_src (sc); | |
522 | MATH_OP (dc, b, 0, +); | |
523 | ||
524 | /** 1sss ddd1 dd ss 0010 ADD.L:G src,dest */ | |
525 | ||
526 | prefix (1, 1, 0); | |
527 | sc = decode_src23(sss, ss, 4); | |
528 | dc = decode_dest23(ddd, dd, 4); | |
529 | b = get_src (sc); | |
530 | MATH_OP (dc, b, 0, +); | |
531 | ||
532 | /** 1011 0110 0001 0011 ADD.L:G #IMM16,SP */ | |
533 | ||
534 | prefix (0, 0, 0); | |
535 | dc = reg_sd (sp); | |
536 | b = sign_ext (IMM(2), 16); | |
537 | MATH_OP (dc, b, 0, +); | |
538 | ||
539 | /** 01ii 001i ADD.L:Q #IMM3,SP */ | |
540 | ||
541 | prefix (0, 0, 0); | |
542 | dc = reg_sd (sp); | |
543 | b = ii * 2 + i + 1; | |
544 | MATH_OP (dc, b, 0, +); | |
545 | ||
546 | /** 1011 0110 0000 0011 ADD.L:S #IMM8,SP */ | |
547 | ||
548 | prefix (0, 0, 0); | |
549 | dc = reg_sd (sp); | |
550 | b = sign_ext (IMM(1), 8); | |
551 | MATH_OP (dc, b, 0, +); | |
552 | ||
553 | /** 1000 ddd0 dd01 0001 ADDX #IMM,dest */ | |
554 | ||
555 | prefix (0, 1, 0); | |
556 | dc = decode_dest23(ddd, dd, 4); | |
557 | imm = sign_ext (IMM(1), 8); | |
558 | MATH_OP (dc, imm, 0, +); | |
559 | ||
560 | /** 1sss ddd0 dd ss 0010 ADDX src,dest */ | |
561 | ||
562 | prefix (1, 1, 0); | |
563 | sc = decode_src23(sss, ss, 1); | |
564 | dc = decode_dest23(ddd, dd, 4); | |
565 | b = sign_ext (get_src (sc), 8); | |
566 | MATH_OP (dc, b, 0, +); | |
567 | ||
568 | /** 1111 ddd w dd01 immm ADJNZ.size #IMM,dest,label */ | |
569 | ||
570 | prefix (0, 0, 0); | |
571 | dc = decode_dest23 (ddd, dd, w+1); | |
572 | v = get_src (dc); | |
573 | imm = sign_ext(immm, 4); | |
574 | tprintf("%d + %d = %d\n", v, imm, v+imm); | |
575 | v += imm; | |
576 | put_dest (dc, v); | |
577 | a = sign_ext (IMM(1), 8); | |
578 | if ((v & (w ? 0xffff : 0xff)) != 0) | |
579 | { | |
580 | tprintf("jmp: %x + 2 + %d = ", get_reg (pc), a); | |
3877a145 | 581 | put_reg (pc, m32c_opcode_pc + 2 + a); |
d45a4bef JB |
582 | tprintf("%x\n", get_reg (pc)); |
583 | } | |
584 | ||
585 | /** 1000 ddd w dd11 1111 AND.size:G #IMM,dest */ | |
586 | ||
587 | prefix (0, 1, 0); | |
588 | dc = decode_dest23(ddd, dd, w+1); | |
589 | imm = IMM(w+1); | |
590 | LOGIC_OP (dc, imm, &); | |
591 | ||
592 | /** 01dd 110w AND.size:S #IMM,dest */ | |
593 | ||
594 | prefix (0, 1, 0); | |
595 | dc = decode_dest2(dd, w+1); | |
596 | imm = IMM (w+1); | |
597 | LOGIC_OP (dc, imm, &); | |
598 | ||
599 | /** 1sss ddd w dd ss 1101 AND.size:G src,dest */ | |
600 | ||
601 | prefix (1, 1, 0); | |
602 | sc = decode_src23(sss, ss, w+1); | |
603 | dc = decode_dest23(ddd, dd, w+1); | |
604 | b = get_src (sc); | |
605 | LOGIC_OP (dc, b, &); | |
606 | ||
607 | /** 0000 0001 1101 sss0 ss00 1bit BAND src */ | |
608 | ||
609 | sc = decode_src23 (sss, ss, 1); | |
610 | BIT_OPC (sc, bit, b & carry); | |
611 | ||
612 | /** 1101 ddd0 dd11 0bit BCLR dest */ | |
613 | ||
614 | dc = decode_dest23 (ddd, dd, 1); | |
615 | BIT_OP (dc, bit, 0); | |
616 | ||
617 | /** 1100 ddd w dd10 1110 BITINDEX.size src */ | |
618 | ||
619 | prefix (0, 0, 0); | |
620 | dc = decode_dest23 (ddd, dd, w+1); | |
621 | bitindex = get_src (dc); | |
622 | tprintf ("bitindex set to %d\n", bitindex); | |
623 | goto next_opcode; | |
624 | ||
625 | /** 1101 ddd0 dd01 0bit BMcnd dest */ | |
626 | ||
627 | prefix (0, 0, 0); | |
628 | dc = decode_dest23 (ddd, dd, 1); | |
629 | if (condition_true (IMM (1))) | |
630 | put_bit2 (dc, bit, 1); | |
631 | else | |
632 | put_bit2 (dc, bit, 0); | |
633 | ||
634 | /** 1101 1001 0c10 1cnd BMcnd C */ | |
635 | ||
636 | prefix (0, 0, 0); | |
637 | if (condition_true (c * 8 + cnd)) | |
638 | set_c (1); | |
639 | else | |
640 | set_c (0); | |
641 | ||
642 | /** 0000 0001 1101 sss0 ss01 1bit BNAND src */ | |
643 | ||
644 | prefix (0, 0, 0); | |
645 | sc = decode_src23 (sss, ss, 1); | |
ed25d732 | 646 | BIT_OPC (sc, bit, (!b) & carry); |
d45a4bef JB |
647 | |
648 | /** 0000 0001 1101 sss0 ss11 0bit BNOR src */ | |
649 | ||
650 | prefix (0, 0, 0); | |
651 | sc = decode_src23 (sss, ss, 1); | |
ed25d732 | 652 | BIT_OPC (sc, bit, (!b) | carry); |
d45a4bef JB |
653 | |
654 | /** 1101 ddd0 dd01 1bit BNOT dest */ | |
655 | ||
656 | prefix (0, 0, 0); | |
657 | dc = decode_dest23 (ddd, dd, 1); | |
658 | BIT_OP (dc, bit, !b); | |
659 | ||
660 | /** 0000 0001 1101 sss0 ss00 0bit BNTST src */ | |
661 | ||
662 | prefix (0, 0, 0); | |
663 | sc = decode_dest23 (sss, ss, 1); | |
664 | b = get_bit2 (sc, bit); | |
665 | set_zc (!b, !b); | |
666 | ||
667 | /** 0000 0001 1101 sss0 ss11 1bit BNXOR src */ | |
668 | ||
669 | prefix (0, 0, 0); | |
670 | sc = decode_src23 (sss, ss, 1); | |
671 | BIT_OPC (sc, bit, !b ^ carry); | |
672 | ||
673 | /** 0000 0001 1101 sss0 ss10 0bit BOR src */ | |
674 | ||
675 | prefix (0, 0, 0); | |
676 | sc = decode_src23 (sss, ss, 1); | |
677 | BIT_OPC (sc, bit, b | carry); | |
678 | ||
679 | /** 0000 0000 BRK */ | |
680 | ||
681 | /* We report the break to our caller with the PC still pointing at the | |
682 | breakpoint instruction. */ | |
3877a145 | 683 | put_reg (pc, m32c_opcode_pc); |
e7ddc197 | 684 | if (verbose) |
d45a4bef | 685 | printf("[break]\n"); |
3877a145 DD |
686 | if (in_gdb || (regs.r_intbl == 0 && regs.r_intbh == 0)) |
687 | return M32C_MAKE_HIT_BREAK (); | |
688 | if (mem_get_qi (0xFFFFE7) == 0xff) | |
689 | trigger_based_interrupt (0); | |
690 | else | |
691 | trigger_fixed_interrupt (0xFFFFE4); | |
692 | ||
693 | /** 1111 1110 GBRK */ | |
694 | ||
695 | /* This alternate break, which is not part of the chip's opcode set, | |
696 | is here in case you need to debug a program that itself uses the | |
697 | chip's BRK opcode. You'll need to modify your copy of GDB to use | |
698 | this opcode instead of the real BRK. */ | |
699 | ||
700 | /* GDB Break. */ | |
701 | /* We report the break to our caller with the PC still pointing at the | |
702 | breakpoint instruction. */ | |
703 | put_reg (pc, m32c_opcode_pc); | |
e7ddc197 | 704 | if (verbose) |
3877a145 | 705 | printf("[gdb break]\n"); |
d45a4bef JB |
706 | return M32C_MAKE_HIT_BREAK (); |
707 | ||
3877a145 | 708 | /** 0000 1000 BRK2 */ |
d45a4bef JB |
709 | |
710 | if (verbose) | |
711 | printf("[break2]\n"); | |
3877a145 DD |
712 | if (in_gdb) |
713 | return M32C_MAKE_HIT_BREAK (); | |
714 | if (mem_get_qi (0xFFFFE7) == 0xff) | |
715 | trigger_based_interrupt (0); | |
716 | else | |
717 | trigger_fixed_interrupt (0xFFFFE4); | |
d45a4bef JB |
718 | |
719 | /** 1101 ddd0 dd11 1bit BSET dest */ | |
720 | ||
721 | dc = decode_dest23 (ddd, dd, 1); | |
722 | BIT_OP (dc, bit, 1); | |
723 | ||
724 | /** 1101 sss0 ss00 0bit BTST:G src */ | |
725 | ||
726 | prefix (0, 0, 0); | |
727 | sc = decode_src23 (sss, ss, 1); | |
728 | b = get_bit2 (sc, bit); | |
729 | set_zc (!b, b); | |
730 | ||
731 | /** 00bb 101b BTST:S src */ | |
732 | ||
733 | sc = decode_src23 (3, 3, 1); /* bit,base:19 */ | |
734 | b = get_bit2 (sc, bb*2 + b); | |
735 | set_zc (!b, b); | |
736 | ||
737 | /** 1101 ddd0 dd10 0bit BTSTC dest */ | |
738 | ||
739 | prefix (0, 0, 0); | |
740 | sc = decode_dest23 (ddd, dd, 1); | |
741 | b = get_bit2 (sc, bit); | |
742 | set_zc (!b, b); | |
743 | put_bit2 (sc, bit, 0); | |
744 | ||
745 | /** 1101 ddd0 dd10 1bit BTSTS dest */ | |
746 | ||
747 | prefix (0, 0, 0); | |
748 | sc = decode_dest23 (ddd, dd, 1); | |
749 | b = get_bit2 (sc, bit); | |
750 | set_zc (!b, b); | |
751 | put_bit2 (sc, bit, 1); | |
752 | ||
753 | /** 0000 0001 1101 sss0 ss10 1bit BXOR src */ | |
754 | ||
755 | prefix (0, 0, 0); | |
756 | sc = decode_src23 (sss, ss, 1); | |
757 | BIT_OPC (sc, bit, b ^ carry); | |
758 | ||
759 | /** 0000 0001 1000 ddd w dd11 1110 CLIP.size #IMM1,#IMM2,dest */ | |
760 | ||
761 | prefix (0, 0, 0); | |
762 | dc = decode_dest23 (ddd, dd, w+1); | |
763 | a = sign_ext (IMM(w+1), w*8+8); | |
764 | b = sign_ext (IMM(w+1), w*8+8); | |
765 | v = sign_ext (get_src (dc), w*8+8); | |
766 | tprintf("clip %d <= %d <= %d : ", a, v, b); | |
767 | if (a > v) | |
768 | v = a; | |
769 | if (v > b) | |
770 | v = b; | |
771 | tprintf("%d\n", v); | |
772 | put_dest (dc, v); | |
773 | ||
774 | /** 1001 ddd w dd10 1110 CMP.size:G #IMM,dest */ | |
775 | ||
776 | prefix (0, 1, 0); | |
777 | dc = decode_dest23 (ddd, dd, w+1); | |
778 | v = get_src (dc); | |
779 | imm = IMM(w+1); | |
780 | cmp (v, imm, w+1); | |
781 | ||
782 | /** 1010 ddd0 dd11 0001 CMP.L:G #IMM32,dest */ | |
783 | ||
784 | prefix (0, 1, 0); | |
785 | dc = decode_dest23 (ddd, dd, 4); | |
786 | v = get_src (dc); | |
787 | imm = IMM(4); | |
788 | cmp (v, imm, 4); | |
789 | ||
790 | /** 1110 ddd w dd01 immm CMP.size:Q #IMM,dest */ | |
791 | ||
792 | prefix (0, 1, 0); | |
793 | dc = decode_dest23 (ddd, dd, w+1); | |
794 | v = get_src (dc); | |
795 | immm = sign_ext (immm, 4); | |
796 | cmp (v, immm, w+1); | |
797 | ||
798 | /** 01dd 011w CMP.size:S #IMM,dest */ | |
799 | ||
800 | prefix (0, 1, 0); | |
801 | dc = decode_dest2 (dd, w+1); | |
802 | v = get_src (dc); | |
803 | imm = sign_ext (IMM(w+1),w*8+8); | |
804 | cmp (v, imm, w+1); | |
805 | ||
806 | /** 1sss ddd w dd ss 0110 CMP.size:G src,dest */ | |
807 | ||
808 | prefix (1, 1, 0); | |
809 | sc = decode_src23 (sss, ss, w+1); | |
810 | dc = decode_dest23 (ddd, dd, w+1); | |
811 | a = get_src (dc); | |
812 | b = get_src (sc); | |
813 | cmp (a, b, w+1); | |
814 | ||
815 | /** 1sss ddd1 dd ss 0001 CMP.L:G src,dest */ | |
816 | ||
817 | prefix (1, 1, 0); | |
818 | sc = decode_src23 (sss, ss, 4); | |
819 | dc = decode_dest23 (ddd, dd, 4); | |
820 | a = get_src (dc); | |
821 | b = get_src (sc); | |
822 | cmp (a, b, 4); | |
823 | ||
824 | /** 01dd 000w CMP.size:S src,R0/R0L */ | |
825 | ||
826 | prefix (0, 1, 0); | |
827 | dc = decode_dest2 (dd, w+1); | |
828 | a = get_reg (w ? r0 : r0l); | |
829 | b = get_src (dc); | |
830 | cmp (a, b, w+1); | |
831 | ||
832 | /** 1010 ddd0 dd01 0001 CMPX #IMM,dest */ | |
833 | ||
834 | prefix (0, 1, 0); | |
835 | dc = decode_dest23 (ddd, dd, 4); | |
836 | v = get_src (dc); | |
837 | imm = sign_ext (IMM(1), 8); | |
838 | cmp (v, imm, 4); | |
839 | ||
840 | /** 0000 0001 1000 ddd w dd00 1110 DADC.size #IMM,dest */ | |
841 | ||
842 | DADDI(1,1); | |
843 | ||
844 | /** 0000 0001 1sss ddd w dd ss 1000 DADC.size src,dest */ | |
845 | ||
846 | DADDV(1,1); | |
847 | ||
848 | /** 0000 0001 1000 ddd w dd01 1110 DADD.size #IMM,dest */ | |
849 | ||
850 | DADDI(1,0); | |
851 | ||
852 | /** 0000 0001 1sss ddd w dd ss 0000 DADD.size src,dest */ | |
853 | ||
854 | DADDV(1,0); | |
855 | ||
856 | /** 1011 ddd w dd00 1110 DEC.size dest */ | |
857 | ||
858 | prefix (0, 1, 0); | |
859 | dc = decode_dest23 (ddd, dd, w+1); | |
860 | a = get_src (dc); | |
861 | v = a-1; | |
862 | tprintf ("%x -- = %x\n", a, v); | |
863 | set_sz (v, w+1); | |
864 | put_dest (dc, v); | |
865 | ||
866 | /** 1011 0000 010w 0011 DIV.size #IMM */ | |
867 | ||
868 | prefix (0, 0, 0); | |
869 | div_op (-1, 0, 0, 0, w+1); | |
870 | ||
871 | /** 1000 sss w ss01 1110 DIV.size src */ | |
872 | ||
873 | prefix (0, 1, 0); | |
874 | div_op (sss, ss, 0, 0, w+1); | |
875 | ||
876 | /** 0000 0001 1010 sss1 ss01 1111 DIV.L src */ | |
877 | ||
878 | M32C_ONLY(); | |
879 | prefix (0, 0, 0); | |
880 | div_op (sss, ss, 0, 0, 4); | |
881 | ||
882 | /** 1011 0000 000w 0011 DIVU.size #IMM */ | |
883 | ||
884 | prefix (0, 0, 0); | |
885 | div_op (-1, 0, 1, 0, w+1); | |
886 | ||
887 | /** 1000 sss w ss00 1110 DIVU.size src */ | |
888 | ||
889 | prefix (0, 1, 0); | |
890 | div_op (sss, ss, 1, 0, w+1); | |
891 | ||
892 | /** 0000 0001 1010 sss1 ss00 1111 DIVU.L src */ | |
893 | ||
894 | M32C_ONLY(); | |
895 | prefix (0, 0, 0); | |
896 | div_op (sss, ss, 1, 0, 4); | |
897 | ||
898 | /** 1011 0010 010w 0011 DIVX.size #IMM */ | |
899 | ||
900 | prefix (0, 0, 0); | |
901 | div_op (-1, 0, 0, 1, w+1); | |
902 | ||
903 | /** 1001 sss w ss01 1110 DIVX.size src */ | |
904 | ||
905 | prefix (0, 1, 0); | |
906 | div_op (sss, ss, 0, 1, w+1); | |
907 | ||
908 | /** 0000 0001 1010 sss1 ss10 1111 DIVX.L src */ | |
909 | ||
910 | M32C_ONLY(); | |
911 | prefix (0, 0, 0); | |
912 | div_op (sss, ss, 0, 1, 4); | |
913 | ||
914 | /** 0000 0001 1001 ddd w dd00 1110 DSBB.size #IMM,dest */ | |
915 | ||
916 | DADDI(0,1); | |
917 | ||
918 | /** 0000 0001 1sss ddd w dd ss 1010 DSBB.size src,dest */ | |
919 | ||
920 | DADDV(0,1); | |
921 | ||
922 | /** 0000 0001 1001 ddd w dd01 1110 DSUB.size #IMM,dest */ | |
923 | ||
924 | DADDI(0,0); | |
925 | ||
926 | /** 0000 0001 1sss ddd w dd ss 0010 DSUB.size src,dest */ | |
927 | ||
928 | DADDV(0,0); | |
929 | ||
930 | /** 1110 1100 ENTER #IMM */ | |
931 | ||
932 | imm = IMM(1); | |
933 | put_reg (sp, get_reg (sp) - 4); | |
934 | mem_put_si (get_reg (sp), get_reg (fb)); | |
935 | put_reg (fb, get_reg (sp)); | |
936 | put_reg (sp, get_reg (sp) - imm); | |
937 | ||
938 | /** 1111 1100 EXITD */ | |
939 | ||
940 | put_reg (sp, get_reg (fb)); | |
941 | put_reg (fb, mem_get_si (get_reg (sp))); | |
942 | put_reg (sp, get_reg (sp) + 4); | |
943 | put_reg (pc, mem_get_si (get_reg (sp))); | |
944 | put_reg (sp, get_reg (sp) + 4); | |
945 | ||
946 | /** 1100 ddd w dd01 1110 EXTS.size dest */ | |
947 | ||
948 | prefix (0, 0, 0); | |
949 | dc = decode_dest23 (ddd, dd, w+1); | |
950 | v = sign_ext (get_src (dc), (w+1)*8); | |
951 | dc = widen_sd (dc); | |
952 | put_dest (dc, v); | |
953 | set_sz (v, (w+1)*2); | |
954 | ||
955 | /** 0000 0001 1sss ddd0 dd ss 0111 EXTS.B src,dest */ | |
956 | ||
957 | prefix (0, 0, 0); | |
958 | sc = decode_src23 (sss, ss, 1); | |
959 | dc = decode_dest23 (ddd, dd, 2); | |
960 | v = sign_ext (get_src (sc), 8); | |
961 | put_dest (dc, v); | |
962 | set_sz (v, 16); | |
963 | ||
964 | /** 0000 0001 1sss ddd0 dd ss 1011 EXTZ src,dest */ | |
965 | ||
966 | prefix (0, 0, 0); | |
967 | sc = decode_src23 (sss, ss, 1); | |
968 | dc = decode_dest23 (ddd, dd, 2); | |
969 | v = get_src (sc); | |
970 | put_dest (dc, v); | |
971 | set_sz (v, 16); | |
972 | ||
973 | /** 1101 0011 1110 1dst FCLR dest */ | |
974 | ||
975 | set_flags (1 << dst, 0); | |
976 | ||
977 | /** 1001 1111 FREIT */ | |
978 | ||
979 | NOTYET(); | |
980 | ||
981 | /** 1101 0001 1110 1dst FSET dest */ | |
982 | ||
983 | set_flags (1 << dst, 1 << dst); | |
984 | ||
985 | /** 1010 ddd w dd00 1110 INC.size dest */ | |
986 | ||
987 | prefix (0, 1, 0); | |
988 | dc = decode_dest23 (ddd, dd, w+1); | |
989 | a = get_src (dc); | |
990 | v = a+1; | |
991 | tprintf ("%x ++ = %x\n", a, v); | |
992 | set_sz (v, w+1); | |
993 | put_dest (dc, v); | |
994 | ||
995 | /** 1000 sss0 ss0w 0011 INDEXB.size src */ | |
996 | INDEXOP(1, 1, 1); | |
997 | /** 1010 sss0 ss0w 0011 INDEXBD.size src */ | |
998 | INDEXOP(1, 0, 1); | |
999 | /** 1100 sss0 ss0w 0011 INDEXBS.size src */ | |
1000 | INDEXOP(1, 1, 0); | |
1001 | /** 1001 sss0 ss1w 0011 INDEXL.size src */ | |
1002 | INDEXOP(4, 1, 1); | |
1003 | /** 1011 sss0 ss1w 0011 INDEXLD.size src */ | |
1004 | INDEXOP(4, 0, 1); | |
1005 | /** 1001 sss0 ss0w 0011 INDEXLS.size src */ | |
1006 | INDEXOP(4, 1, 0); | |
1007 | /** 1000 sss0 ss1w 0011 INDEXW.size src */ | |
1008 | INDEXOP(2, 1, 1); | |
1009 | /** 1010 sss0 ss1w 0011 INDEXWD.size src */ | |
1010 | INDEXOP(2, 0, 1); | |
1011 | /** 1100 sss0 ss1w 0011 INDEXWS.size src */ | |
1012 | INDEXOP(2, 1, 0); | |
1013 | ||
1014 | /** 1011 1110 vector00 INT #IMM */ | |
1015 | ||
1016 | prefix (0, 0, 0); | |
1017 | trigger_based_interrupt (vector); | |
1018 | ||
1019 | /** 1011 1111 INTO */ | |
1020 | ||
1021 | prefix (0, 0, 0); | |
1022 | if (FLAG_O) | |
1023 | trigger_fixed_interrupt (0xffffe0); | |
1024 | ||
1025 | /** 1ccc 101c Jcnd label */ | |
1026 | ||
1027 | prefix (0, 0, 0); | |
1028 | v = sign_ext (IMM(1), 8); | |
1029 | if (condition_true (ccc*2+c)) | |
3877a145 | 1030 | put_reg (pc, m32c_opcode_pc + 1 + v); |
d45a4bef JB |
1031 | |
1032 | /** 01dd 101d JMP.S label */ | |
1033 | ||
1034 | prefix (0, 0, 0); | |
3877a145 | 1035 | put_reg (pc, m32c_opcode_pc + (dd*2+d) + 2); |
d45a4bef JB |
1036 | |
1037 | /** 1011 1011 JMP.B label */ | |
1038 | ||
1039 | prefix (0, 0, 0); | |
1040 | imm = sign_ext (IMM(1), 8); | |
1041 | if (imm == -1) | |
1042 | { | |
1043 | if (verbose) | |
1044 | printf("[jmp-to-self detected as exit]\n"); | |
1045 | return M32C_MAKE_HIT_BREAK (); | |
1046 | } | |
3877a145 | 1047 | put_reg (pc, m32c_opcode_pc + 1 + imm); |
d45a4bef JB |
1048 | |
1049 | /** 1100 1110 JMP.W label */ | |
1050 | ||
1051 | prefix (0, 0, 0); | |
1052 | imm = sign_ext (IMM(2), 16); | |
3877a145 | 1053 | put_reg (pc, m32c_opcode_pc + 1 + imm); |
d45a4bef JB |
1054 | |
1055 | /** 1100 1100 JMP.A label */ | |
1056 | ||
1057 | prefix (0, 0, 0); | |
1058 | imm = IMM(3); | |
1059 | put_reg (pc, imm); | |
1060 | ||
1061 | /** 1100 sss1 ss00 1111 JMPI.W src */ | |
1062 | ||
1063 | prefix (0, 0, 0); | |
1064 | sc = decode_src23 (sss, ss, 2); | |
1065 | a = get_src (sc); | |
1066 | a = sign_ext (a, 16); | |
3877a145 | 1067 | put_reg (pc, m32c_opcode_pc + a); |
d45a4bef JB |
1068 | |
1069 | /** 1000 sss0 ss00 0001 JMPI.A src */ | |
1070 | ||
1071 | prefix (0, 0, 0); | |
1072 | sc = decode_src23 (sss, ss, 3); | |
1073 | a = get_src (sc); | |
1074 | put_reg (pc, a); | |
1075 | ||
1076 | /** 1101 1100 JMPS #IMM8 */ | |
1077 | ||
1078 | prefix (0, 0, 0); | |
1079 | imm = IMM(1); | |
1080 | a = 0xff0000 + mem_get_hi (0xfffe00 - imm * 2); | |
1081 | put_reg (pc, a); | |
1082 | ||
1083 | /** 1100 1111 JSR.W label */ | |
1084 | ||
1085 | prefix (0, 0, 0); | |
1086 | imm = sign_ext (IMM(2), 16); | |
1087 | put_reg (sp, get_reg (sp) - 4); | |
1088 | mem_put_si (get_reg (sp), get_reg (pc)); | |
3877a145 | 1089 | put_reg (pc, m32c_opcode_pc + imm + 1); |
d45a4bef JB |
1090 | |
1091 | /** 1100 1101 JSR.A label */ | |
1092 | ||
1093 | prefix (0, 0, 0); | |
1094 | imm = IMM(3); | |
1095 | put_reg (sp, get_reg (sp) - 4); | |
1096 | mem_put_si (get_reg (sp), get_reg (pc)); | |
1097 | put_reg (pc, imm); | |
1098 | ||
1099 | /** 1100 sss1 ss01 1111 JSRI.W src */ | |
1100 | ||
1101 | prefix (0, 0, 0); | |
1102 | sc = decode_src23 (sss, ss, 2); | |
1103 | a = get_src (sc); | |
1104 | a = sign_ext (a, 16); | |
1105 | put_reg (sp, get_reg (sp) - 4); | |
1106 | mem_put_si (get_reg (sp), get_reg (pc)); | |
3877a145 | 1107 | put_reg (pc, m32c_opcode_pc + a); |
d45a4bef JB |
1108 | |
1109 | /** 1001 sss0 ss00 0001 JSRI.A src */ | |
1110 | ||
1111 | prefix (0, 0, 0); | |
1112 | sc = decode_src23 (sss, ss, 3); | |
1113 | a = get_src (sc); | |
1114 | put_reg (sp, get_reg (sp) - 4); | |
1115 | mem_put_si (get_reg (sp), get_reg (pc)); | |
1116 | put_reg (pc, a); | |
1117 | ||
1118 | /** 1101 1101 JSRS #IMM8 */ | |
1119 | ||
1120 | prefix (0, 0, 0); | |
1121 | imm = IMM(1); | |
1122 | a = 0xff0000 + mem_get_hi (0xfffe00 - imm * 2); | |
1123 | put_reg (sp, get_reg (sp) - 4); | |
1124 | mem_put_si (get_reg (sp), get_reg (pc)); | |
1125 | put_reg (pc, a); | |
1126 | ||
1127 | /** 1101 0101 1010 1dst LDC #IMM16,dest */ | |
1128 | ||
1129 | imm = IMM(2); | |
1130 | dc = decode_cr_b (dst, CR_B_DCT0); | |
1131 | put_dest (dc, imm); | |
1132 | ||
1133 | /** 1101 0101 0010 1dst LDC #IMM24,dest */ | |
1134 | ||
1135 | imm = IMM(3); | |
1136 | dc = decode_cr_b (dst, CR_B_INTB); | |
1137 | put_dest (dc, imm); | |
1138 | ||
1139 | /** 1101 0101 0110 1dst LDC #IMM24,dest */ | |
1140 | ||
1141 | imm = IMM(3); | |
1142 | dc = decode_cr_b (dst, CR_B_DMA0); | |
1143 | put_dest (dc, imm); | |
1144 | ||
1145 | /** 0000 0001 1101 sss1 ss00 1dst LDC src,dest */ | |
1146 | ||
1147 | prefix (0, 0, 0); | |
1148 | sc = decode_src23 (sss, ss, 2); | |
1149 | dc = decode_cr_b (dst, CR_B_DCT0); | |
1150 | a = get_src (sc); | |
1151 | put_dest (dc, a); | |
1152 | ||
1153 | /** 1101 sss1 ss00 0dst LDC src,dest */ | |
1154 | ||
1155 | prefix (0, 0, 0); | |
1156 | sc = decode_src23 (sss, ss, 3); | |
1157 | dc = decode_cr_b (dst, CR_B_INTB); | |
1158 | a = get_src (sc); | |
1159 | put_dest (dc, a); | |
1160 | ||
1161 | /** 0000 0001 1101 sss1 ss00 0dst LDC src,dest */ | |
1162 | ||
1163 | prefix (0, 0, 0); | |
1164 | sc = decode_src23 (sss, ss, 3); | |
1165 | dc = decode_cr_b (dst, CR_B_DMA0); | |
1166 | a = get_src (sc); | |
1167 | put_dest (dc, a); | |
1168 | ||
1169 | /** 1011 0110 1100 0011 LDCTX */ | |
1170 | ||
1171 | NOTYET(); | |
1172 | ||
1173 | /** 1101 0101 1110 1imm LDIPL #IMM */ | |
1174 | ||
1175 | set_flags (0x7000, imm*0x1000); | |
1176 | ||
1177 | /** 0000 0001 1000 ddd w dd11 1111 MAX.size #IMM,dest */ | |
1178 | ||
1179 | prefix (0, 0, 0); | |
1180 | w++; | |
1181 | dc = decode_dest23 (ddd, dd, w); | |
1182 | imm = sign_ext (IMM(w), w*8); | |
1183 | a = sign_ext (get_src (dc), w*8); | |
1184 | tprintf ("max %d %d\n", imm, a); | |
1185 | if (imm > a) | |
1186 | put_dest (dc, imm); | |
1187 | ||
1188 | /** 0000 0001 1sss ddd w dd ss 1101 MAX.size src,dest */ | |
1189 | ||
1190 | prefix (0, 0, 0); | |
1191 | w++; | |
1192 | sc = decode_src23 (sss, ss, w); | |
1193 | dc = decode_dest23 (ddd, dd, w); | |
1194 | b = sign_ext (get_src (sc), w*8); | |
1195 | a = sign_ext (get_src (dc), w*8); | |
1196 | tprintf ("max %d %d\n", b, a); | |
1197 | if (b > a) | |
1198 | put_dest (dc, b); | |
1199 | ||
1200 | /** 0000 0001 1000 ddd w dd10 1111 MIN.size #IMM,dest */ | |
1201 | ||
1202 | prefix (0, 0, 0); | |
1203 | w++; | |
1204 | dc = decode_dest23 (ddd, dd, w); | |
1205 | imm = sign_ext (IMM(w), w*8); | |
1206 | a = sign_ext (get_src (dc), w*8); | |
1207 | tprintf ("min %d %d\n", imm, a); | |
1208 | if (imm < a) | |
1209 | put_dest (dc, imm); | |
1210 | ||
1211 | /** 0000 0001 1sss ddd w dd ss 1100 MIN.size src,dest */ | |
1212 | ||
1213 | prefix (0, 0, 0); | |
1214 | w++; | |
1215 | sc = decode_src23 (sss, ss, w); | |
1216 | dc = decode_dest23 (ddd, dd, w); | |
1217 | b = sign_ext (get_src (sc), w*8); | |
1218 | a = sign_ext (get_src (dc), w*8); | |
1219 | tprintf ("min %d %d\n", b, a); | |
1220 | if (b < a) | |
1221 | put_dest (dc, b); | |
1222 | ||
1223 | /** 1001 ddd w dd10 1111 MOV.size:G #IMM,dest */ | |
1224 | ||
1225 | dc = decode_dest23 (ddd, dd, w+1); | |
1226 | imm = IMM(w+1); | |
1227 | v = imm; | |
1228 | tprintf("%x = %x\n", v, v); | |
1229 | set_sz(v, w+1); | |
1230 | put_dest (dc, v); | |
1231 | ||
1232 | /** 1011 ddd0 dd11 0001 MOV.L:G #IMM,dest */ | |
1233 | ||
1234 | dc = decode_dest23 (ddd, dd, 4); | |
1235 | imm = IMM(4); | |
1236 | v = imm; | |
1237 | tprintf("%x = %x\n", v, v); | |
1238 | set_sz(v, 4); | |
1239 | put_dest (dc, v); | |
1240 | ||
1241 | /** 1111 ddd w dd10 immm MOV.size:Q #IMM4,dest */ | |
1242 | ||
1243 | dc = decode_dest23 (ddd, dd, w+1); | |
1244 | imm = sign_ext (immm, 4); | |
1245 | v = imm; | |
1246 | tprintf("%x = %d\n", v, v); | |
1247 | set_sz(v, w+1); | |
1248 | put_dest (dc, v); | |
1249 | ||
1250 | /** 00dd 010w MOV.size:S #IMM,dest */ | |
1251 | ||
1252 | prefix (0, 1, 0); | |
1253 | dc = decode_dest2 (dd, w+1); | |
1254 | imm = IMM(w+1); | |
1255 | put_dest (dc, imm); | |
1256 | set_sz (imm, w+1); | |
1257 | ||
1258 | /** 10w1 110d MOV.size:S #IMM,a0/a1 */ | |
1259 | ||
1260 | imm = IMM(w ? 3 : 2); | |
1261 | put_reg (d ? a1 : a0, imm); | |
1262 | set_sz (imm & addr_mask, w+1); | |
1263 | ||
1264 | /** 00dd 001w MOV.size:Z #0,dest */ | |
1265 | ||
1266 | prefix (0, 1, 0); | |
1267 | dc = decode_dest2 (dd, w+1); | |
1268 | put_dest (dc, 0); | |
1269 | set_sz (0, w+1); | |
1270 | ||
1271 | /** 1sss ddd w dd ss 1011 MOV.size:G src,dest */ | |
1272 | ||
1273 | prefix (1, 1, 0); | |
1274 | sc = decode_src23 (sss, ss, w+1); | |
1275 | dc = decode_dest23 (ddd, dd, w+1); | |
1276 | v = get_src (sc); | |
1277 | put_dest (dc, v); | |
1278 | set_sz (v, w+1); | |
1279 | ||
1280 | /** 1sss ddd1 dd ss 0011 MOV.L:G src,dest */ | |
1281 | ||
1282 | prefix (1, 1, 0); | |
1283 | sc = decode_src23 (sss, ss, 4); | |
1284 | dc = decode_dest23 (ddd, dd, 4); | |
1285 | v = get_src (sc); | |
1286 | put_dest (dc, v); | |
1287 | set_sz (v, 4); | |
1288 | ||
1289 | /** VARY SS 01 10 11 */ | |
1290 | /** 00SS 100w MOV.size:S src,R0L/R0 */ | |
1291 | ||
1292 | prefix (0, 1, 0); | |
1293 | sc = decode_dest2 (SS, w+1); | |
1294 | v = get_src (sc); | |
1295 | put_reg (w ? r0 : r0l, v); | |
1296 | set_sz (v, w+1); | |
1297 | ||
1298 | /** 01ss 111w MOV.size:S src,R1L/R1 */ | |
1299 | ||
1300 | prefix (0, 1, 0); | |
1301 | sc = decode_dest2 (ss, w+1); | |
1302 | v = get_src (sc); | |
1303 | put_reg (w ? r1 : r1l, v); | |
1304 | set_sz (v, w+1); | |
1305 | ||
1306 | /** VARY DD 01 10 11 */ | |
1307 | /** 00DD 000w MOV.size:S R0L/R0,dest */ | |
1308 | ||
1309 | prefix (0, 1, 0); | |
1310 | dc = decode_dest2 (DD, w+1); | |
1311 | v = get_reg (w ? r0 : r0l); | |
1312 | put_dest (dc, v); | |
1313 | set_sz (v, w+1); | |
1314 | ||
1315 | /** 01ss 100d MOV.L:S src,A0/A1 */ | |
1316 | ||
1317 | prefix (0, 1, 0); | |
1318 | sc = decode_dest2 (ss, 4); | |
1319 | v = get_src (sc); | |
1320 | put_reg (d ? a1 : a0, v); | |
1321 | set_sz (v, 4); | |
1322 | ||
1323 | /** 1011 ddd w dd00 1111 MOV.size:G dsp:8[SP], dest */ | |
1324 | ||
1325 | prefix (0, 0, 0); | |
1326 | imm = IMM(1); | |
1327 | dc = decode_dest23 (ddd, dd, w+1); | |
1328 | a = get_reg (sp) + sign_ext (imm, 8); | |
1329 | a &= addr_mask; | |
1330 | if (w) | |
1331 | v = mem_get_hi (a); | |
1332 | else | |
1333 | v = mem_get_qi (a); | |
1334 | put_dest (dc, v); | |
1335 | set_sz (v, w+1); | |
1336 | ||
1337 | /** 1010 sss w ss00 1111 MOV.size:G src,dsp:8[SP] */ | |
1338 | ||
1339 | prefix (0, 0, 0); | |
1340 | sc = decode_dest23 (sss, ss, w+1); | |
1341 | imm = IMM(1); | |
1342 | a = get_reg (sp) + sign_ext (imm, 8); | |
1343 | a &= addr_mask; | |
1344 | v = get_src (sc); | |
1345 | if (w) | |
1346 | mem_put_hi (a, v); | |
1347 | else | |
1348 | mem_put_qi (a, v); | |
1349 | set_sz (v, w+1); | |
1350 | ||
1351 | /** 1101 sss1 ss01 1dst MOVA src,dest */ | |
1352 | ||
1353 | static reg_id map[8] = { r2r0, r3r1, a0, a1 }; | |
1354 | prefix (0, 0, 0); | |
1355 | sc = decode_src23 (sss, ss, 1); | |
1356 | if (!sc.mem || !map[dst]) | |
1357 | UNSUPPORTED(); | |
1358 | put_reg (map[dst], sc.u.addr); | |
1359 | ||
1360 | /** 0000 0001 1011 ddd0 dd hl 1110 MOVdir R0L,dest */ | |
1361 | ||
1362 | prefix (0, 0, 0); | |
1363 | dc = decode_dest23 (ddd, dd, 1); | |
1364 | a = get_src (dc); | |
1365 | b = get_reg (r0l); | |
1366 | switch (hl) | |
1367 | { | |
1368 | case 0: a = (a & 0xf0) | (b & 0x0f); break; | |
1369 | case 1: a = (a & 0xf0) | ((b>>4) & 0x0f); break; | |
1370 | case 2: a = (a & 0x0f) | ((b & 0x0f)<<4); break; | |
1371 | case 3: a = (a & 0x0f) | (b & 0xf0); break; | |
1372 | } | |
1373 | put_dest (dc, a); | |
1374 | ||
1375 | /** 0000 0001 1010 sss0 ss hl 1110 MOVdir src,R0L */ | |
1376 | ||
1377 | prefix (0, 0, 0); | |
1378 | sc = decode_dest23 (sss, ss, 1); | |
1379 | a = get_reg (r0l); | |
1380 | b = get_src (dc); | |
1381 | switch (hl) | |
1382 | { | |
1383 | case 0: a = (a & 0xf0) | (b & 0x0f); break; | |
1384 | case 1: a = (a & 0xf0) | ((b>>4) & 0x0f); break; | |
1385 | case 2: a = (a & 0x0f) | ((b & 0x0f)<<4); break; | |
1386 | case 3: a = (a & 0x0f) | (b & 0xf0); break; | |
1387 | } | |
1388 | put_reg (r0l, a); | |
1389 | ||
1390 | /** 1011 ddd0 dd01 0001 MOVX #IMM,dest */ | |
1391 | ||
1392 | prefix (0, 1, 0); | |
1393 | dc = decode_dest23 (ddd, dd, 4); | |
1394 | imm = sign_ext (IMM(1), 8); | |
1395 | put_dest (dc, imm); | |
1396 | set_sz (imm, 1); | |
1397 | ||
1398 | /** 1000 ddd w dd01 1111 MUL.size #IMM,dest */ | |
1399 | ||
1400 | prefix (0, 1, 0); | |
1401 | w ++; | |
1402 | dc = decode_dest23 (ddd, dd, w); | |
1403 | v = sign_ext (get_src (dc), w*8); | |
1404 | imm = sign_ext (IMM(w), w*8); | |
1405 | tprintf("%d * %d = %d\n", v, imm, v*imm); | |
1406 | v *= imm; | |
1407 | dc = widen_sd (dc); | |
1408 | put_dest (dc, v); | |
1409 | ||
1410 | /** 1sss ddd w dd ss 1100 MUL.size src,dest */ | |
1411 | ||
1412 | prefix (1, 1, 0); | |
1413 | w ++; | |
1414 | sc = decode_src23 (sss, ss, w); | |
1415 | dc = decode_dest23 (ddd, dd, w); | |
1416 | a = sign_ext (get_src (sc), w*8); | |
1417 | b = sign_ext (get_src (dc), w*8); | |
1418 | tprintf("%d * %d = %d\n", a, b, a*b); | |
1419 | v = a * b; | |
1420 | dc = widen_sd (dc); | |
1421 | put_dest (dc, v); | |
1422 | ||
1423 | /** 0000 0001 1000 sss1 ss01 1111 MUL.L src,R2R0 */ | |
1424 | ||
1425 | M32C_ONLY(); | |
1426 | prefix (0, 0, 0); | |
1427 | sc = decode_src23 (sss, ss, 4); | |
1428 | a = sign_ext (get_src (sc), 32); | |
1429 | b = sign_ext (get_reg (r2r0), 32); | |
1430 | ll = (long long)a * (long long)b; | |
1431 | tprintf("%d * %d = %lld (%llx)\n", a, b, ll, ll); | |
1432 | if (ll < b2minsigned[4] || ll > b2maxsigned[4]) | |
1433 | set_flags (FLAGBIT_O, FLAGBIT_O); | |
1434 | else | |
1435 | set_flags (FLAGBIT_O, 0); | |
1436 | put_reg (r2r0, (int)ll); | |
1437 | ||
1438 | /** 1100 sss1 ss11 1110 MULEX src */ | |
1439 | ||
1440 | prefix (0, 1, 0); | |
1441 | sc = decode_dest23 (sss, ss, 2); | |
1442 | a = sign_ext (get_src (sc), 16); | |
1443 | b = sign_ext (get_reg (r2r0), 32); | |
1444 | ll = (long long)a * (long long)b; | |
1445 | tprintf("%d * %d = %lld (%llx)\n", a, b, ll, ll); | |
1446 | put_reg (r2r0, (int)ll); | |
1447 | put_reg (r1, (int)(ll >> 32)); | |
1448 | ||
1449 | /** 1000 ddd w dd00 1111 MULU.size #IMM,dest */ | |
1450 | ||
1451 | prefix (0, 1, 0); | |
1452 | w ++; | |
1453 | dc = decode_dest23 (ddd, dd, w); | |
1454 | v = get_src (dc); | |
1455 | imm = IMM(w); | |
1456 | tprintf("%d * %d = %d\n", v, imm, v*imm); | |
1457 | v *= imm; | |
1458 | dc = widen_sd (dc); | |
1459 | put_dest (dc, v); | |
1460 | ||
1461 | /** 1sss ddd w dd ss 0100 MULU.size src,dest */ | |
1462 | ||
1463 | prefix (1, 1, 0); | |
1464 | w ++; | |
1465 | sc = decode_src23 (sss, ss, w); | |
1466 | dc = decode_dest23 (ddd, dd, w); | |
1467 | a = get_src (sc); | |
1468 | b = get_src (dc); | |
1469 | tprintf("%d * %d = %d\n", a, b, a*b); | |
1470 | v = a * b; | |
1471 | dc = widen_sd (dc); | |
1472 | put_dest (dc, v); | |
1473 | ||
1474 | /** 0000 0001 1000 sss1 ss00 1111 MULU.L src,R2R0 */ | |
1475 | ||
1476 | M32C_ONLY(); | |
1477 | prefix (0, 0, 0); | |
1478 | sc = decode_src23 (sss, ss, 4); | |
1479 | a = get_src (sc); | |
1480 | b = get_reg (r2r0); | |
1481 | ll = (long long)a * (long long)b; | |
1482 | tprintf("%d * %d = %lld (%llx)\n", a, b, ll, ll); | |
1483 | if (ll < b2minsigned[4] || ll > b2maxsigned[4]) | |
1484 | set_flags (FLAGBIT_O, FLAGBIT_O); | |
1485 | else | |
1486 | set_flags (FLAGBIT_O, 0); | |
1487 | put_reg (r2r0, (int)ll); | |
1488 | ||
1489 | /** 1010 ddd w dd10 1111 NEG.size dest */ | |
1490 | ||
1491 | prefix (0, 1, 0); | |
1492 | dc = decode_dest23 (ddd, dd, w+1); | |
1493 | a = sign_ext (get_src (dc), (w+1)*8); | |
1494 | v = -a; | |
1495 | tprintf("%d * -1 = %d\n", a, v); | |
1496 | set_oszc(v, w+1, v==0); | |
1497 | put_dest (dc, v); | |
1498 | ||
1499 | /** 1101 1110 NOP */ | |
1500 | ||
1501 | tprintf("nop\n"); | |
1502 | ||
1503 | /** 1010 ddd w dd01 1110 NOT.size dest */ | |
1504 | ||
1505 | prefix (0, 1, 0); | |
1506 | dc = decode_dest23 (ddd, dd, w+1); | |
1507 | a = get_src (dc); | |
1508 | v = ~a; | |
1509 | tprintf("~ %x = %x\n", a, v); | |
1510 | set_sz(v, w+1); | |
1511 | put_dest (dc, v); | |
1512 | ||
1513 | /** 1000 ddd w dd10 1111 OR.size:G #IMM,dest */ | |
1514 | ||
1515 | prefix (0, 1, 0); | |
1516 | dc = decode_dest23(ddd, dd, w+1); | |
1517 | imm = IMM(w+1); | |
1518 | LOGIC_OP (dc, imm, |); | |
1519 | ||
1520 | /** 01dd 010w OR.size:S #IMM,dest */ | |
1521 | ||
1522 | prefix (0, 1, 0); | |
1523 | dc = decode_dest2(dd, w+1); | |
1524 | imm = IMM (w+1); | |
1525 | LOGIC_OP (dc, imm, |); | |
1526 | ||
1527 | /** 1sss ddd w dd ss 0101 OR.size:G src,dest */ | |
1528 | ||
1529 | prefix (1, 1, 0); | |
1530 | sc = decode_src23(sss, ss, w+1); | |
1531 | dc = decode_dest23(ddd, dd, w+1); | |
1532 | b = get_src (sc); | |
1533 | LOGIC_OP (dc, b, |); | |
1534 | ||
1535 | /** 1011 ddd w dd10 1111 POP.size dest */ | |
1536 | ||
1537 | prefix (0, 1, 0); | |
1538 | dc = decode_dest23 (ddd, dd, w+1); | |
1539 | if (w) | |
1540 | a = mem_get_hi (get_reg (sp)); | |
1541 | else | |
1542 | a = mem_get_qi (get_reg (sp)); | |
1543 | put_reg (sp, get_reg (sp) + 2); | |
1544 | tprintf("pop%s: %x\n", w ? "hi" : "qi", a); | |
1545 | put_dest (dc, a); | |
1546 | ||
1547 | /** 1101 0011 1010 1dst POPC dest */ | |
1548 | ||
1549 | prefix (0, 0, 0); | |
1550 | dc = decode_cr_b (dst, CR_B_DCT0); | |
1551 | a = mem_get_hi (get_reg (sp)); | |
1552 | put_reg (sp, get_reg (sp) + 2); | |
1553 | tprintf("pophi: %x\n", a); | |
1554 | put_dest (dc, a); | |
1555 | ||
1556 | /** 1101 0011 0010 1dst POPC dest */ | |
1557 | ||
1558 | prefix (0, 0, 0); | |
1559 | dc = decode_cr_b (dst, CR_B_INTB); | |
1560 | a = mem_get_si (get_reg (sp)); | |
1561 | put_reg (sp, get_reg (sp) + 4); | |
1562 | tprintf("popsi: %x\n", a); | |
1563 | put_dest (dc, a); | |
1564 | ||
1565 | /** 1000 1110 POPM dest */ | |
1566 | ||
1567 | static int map[] = { r0, r1, r2, r3, a0, a1, sb, fb }; | |
1568 | prefix (0, 0, 0); | |
1569 | imm = IMM(1); | |
1570 | tprintf("popm: %x\n", imm); | |
1571 | for (a=0; a<4; a++) | |
1572 | if (imm & (1<<a)) | |
1573 | { | |
1574 | v = mem_get_hi (get_reg (sp)); | |
1575 | put_reg (map[a], v); | |
1576 | put_reg (sp, get_reg (sp) + 2); | |
1577 | } | |
1578 | for (; a<8; a++) | |
1579 | if (imm & (1<<a)) | |
1580 | { | |
1581 | v = mem_get_si (get_reg (sp)); | |
1582 | put_reg (map[a], v); | |
1583 | put_reg (sp, get_reg (sp) + 4); | |
1584 | } | |
1585 | ||
1586 | /** 1010 111w PUSH.size #IMM */ | |
1587 | ||
1588 | prefix (0, 0, 0); | |
1589 | imm = IMM(w+1); | |
1590 | tprintf("push%s: %x\n", w ? "hi" : "qi", imm); | |
1591 | int a = get_reg (sp) - 2; | |
1592 | if (w) | |
1593 | mem_put_hi (a, imm); | |
1594 | else | |
1595 | mem_put_qi (a, imm); | |
1596 | put_reg (sp, a); | |
1597 | ||
1598 | /** 1100 sss w ss00 1110 PUSH.size src */ | |
1599 | ||
1600 | prefix (0, 1, 0); | |
1601 | sc = decode_dest23 (sss, ss, w+1); | |
1602 | a = get_src (sc); | |
1603 | put_reg (sp, get_reg (sp) - 2); | |
1604 | if (w) | |
1605 | mem_put_hi (get_reg (sp), a); | |
1606 | else | |
1607 | mem_put_qi (get_reg (sp), a); | |
1608 | tprintf("push%s: %x\n", w ? "hi" : "qi", a); | |
1609 | ||
1610 | /** 1011 0110 0101 0011 PUSH.L #IMM32 */ | |
1611 | ||
1612 | imm = IMM(4); | |
1613 | put_reg (sp, get_reg (sp) - 4); | |
1614 | mem_put_si (get_reg (sp), imm); | |
1615 | ||
1616 | /** 1010 sss0 ss00 0001 PUSH.L src */ | |
1617 | ||
1618 | prefix (0, 1, 0); | |
1619 | sc = decode_dest23 (sss, ss, 4); | |
1620 | a = get_src (sc); | |
1621 | put_reg (sp, get_reg (sp) - 4); | |
1622 | mem_put_si (get_reg (sp), a); | |
1623 | ||
1624 | /** 1011 0sa0 ss00 0001 PUSHA src */ | |
1625 | ||
1626 | prefix (0, 0, 0); | |
1627 | sc = decode_dest23 (sa, ss, 1); | |
1628 | put_reg (sp, get_reg (sp) - 4); | |
1629 | mem_put_hi (get_reg (sp), sc.u.addr); | |
1630 | tprintf("pushsi: %x\n", sc.u.addr); | |
1631 | ||
1632 | /** 1101 0001 1010 1src PUSHC src */ | |
1633 | ||
1634 | prefix (0, 0, 0); | |
1635 | sc = decode_cr_b (src, CR_B_DCT0); | |
1636 | a = get_src (sc); | |
1637 | put_reg (sp, get_reg (sp) - 2); | |
1638 | mem_put_hi (get_reg (sp), a); | |
1639 | tprintf("pushhi: %x\n", a); | |
1640 | ||
1641 | /** 1101 0001 0010 1src PUSHC src */ | |
1642 | ||
1643 | prefix (0, 0, 0); | |
1644 | sc = decode_cr_b (src, CR_B_INTB); | |
1645 | a = get_src (sc); | |
1646 | put_reg (sp, get_reg (sp) - 4); | |
1647 | mem_put_si (get_reg (sp), a); | |
1648 | tprintf("pushsi: %x\n", a); | |
1649 | ||
1650 | /** 1000 1111 PUSHM src */ | |
1651 | ||
1652 | static int map[] = { fb, sb, a1, a0, r3, r2, r1, r0 }; | |
1653 | imm = IMM(1); | |
1654 | tprintf("pushm: %x\n", imm); | |
1655 | for (a=0; a<4; a++) | |
1656 | if (imm & (1<<a)) | |
1657 | { | |
1658 | put_reg (sp, get_reg (sp) - 4); | |
1659 | v = get_reg (map[a]); | |
1660 | mem_put_si (get_reg (sp), v); | |
1661 | } | |
1662 | for (; a<8; a++) | |
1663 | if (imm & (1<<a)) | |
1664 | { | |
1665 | put_reg (sp, get_reg (sp) - 2); | |
1666 | v = get_reg (map[a]); | |
1667 | mem_put_hi (get_reg (sp), v); | |
1668 | } | |
1669 | ||
1670 | /** 1001 1110 REIT */ | |
1671 | ||
1672 | a = get_reg (sp); | |
1673 | put_reg (pc, mem_get_si (a)); | |
1674 | a += 4; | |
1675 | put_reg (flags, mem_get_hi (a)); | |
1676 | a += 2; | |
1677 | put_reg (sp, a); | |
1678 | ||
1679 | /** 1011 1000 010w 0011 RMPA.size */ | |
1680 | ||
1681 | int count = get_reg (r3); | |
1682 | int list1 = get_reg (a0); | |
1683 | int list2 = get_reg (a1); | |
1684 | long long sum = get_reg_ll (r3r1r2r0) & 0xffffff; | |
1685 | ||
1686 | while (count) | |
1687 | { | |
1688 | if (w) | |
1689 | { | |
1690 | a = sign_ext (mem_get_hi (list1), 16); | |
1691 | b = sign_ext (mem_get_hi (list2), 16); | |
1692 | } | |
1693 | else | |
1694 | { | |
1695 | a = sign_ext (mem_get_qi (list1), 8); | |
1696 | b = sign_ext (mem_get_qi (list2), 8); | |
1697 | } | |
1698 | tprintf("%lld + %d * %d = ", sum, a, b); | |
1699 | sum += a * b; | |
1700 | tprintf("%lld\n", sum); | |
1701 | list1 += w ? 2 : 1; | |
1702 | list2 += w ? 2 : 1; | |
1703 | count --; | |
1704 | } | |
1705 | put_reg (r3, count); | |
1706 | put_reg (a0, list1); | |
1707 | put_reg (a1, list2); | |
1708 | put_reg (r2r0, (int)(sum & 0xffffffffU)); | |
1709 | put_reg (r1, (int)(sum >> 32)); | |
1710 | ||
1711 | /** 1011 ddd w dd10 1110 ROLC.size dest */ | |
1712 | ||
1713 | prefix (0, 1, 0); | |
1714 | dc = decode_dest23 (ddd, dd, w+1); | |
1715 | rot_op (dc, 1, 1); | |
1716 | ||
1717 | /** 1010 ddd w dd10 1110 RORC.size dest */ | |
1718 | ||
1719 | prefix (0, 1, 0); | |
1720 | dc = decode_dest23 (ddd, dd, w+1); | |
1721 | rot_op (dc, 1, -1); | |
1722 | ||
1723 | /** 1110 ddd w dd10 immm ROT.size #IMM, dest */ | |
1724 | ||
1725 | prefix (0, 1, 0); | |
1726 | dc = decode_dest23 (ddd, dd, w+1); | |
1727 | rot_op (dc, IMM4(), -1); | |
1728 | ||
1729 | /** 1010 ddd w dd11 1111 ROT.size R1H,dest */ | |
1730 | ||
1731 | prefix (0, 1, 0); | |
1732 | dc = decode_dest23 (ddd, dd, w+1); | |
1733 | a = sign_ext (get_reg (r1h), 8); | |
1734 | rot_op (dc, a, -1); | |
1735 | ||
1736 | /** 1101 1111 RTS */ | |
1737 | ||
1738 | put_reg (pc, mem_get_si (get_reg (sp))); | |
1739 | put_reg (sp, get_reg (sp) + 4); | |
1740 | ||
1741 | /** 0000 0001 1001 ddd w dd10 1110 SBB.size #IMM, dest */ | |
1742 | ||
1743 | prefix (0, 0, 0); | |
1744 | dc = decode_dest23 (ddd, dd, w+1); | |
1745 | imm = IMM (w+1); | |
1746 | MATH_OP (dc, imm, !carry, -); | |
1747 | ||
1748 | /** 0000 0001 1sss ddd w dd ss 0110 SBB.size src,dest */ | |
1749 | ||
1750 | prefix (0, 0, 0); | |
1751 | sc = decode_src23 (sss, ss, w+1); | |
1752 | dc = decode_dest23 (ddd, dd, w+1); | |
1753 | MATH_OP (dc, get_src (sc), !carry, -); | |
1754 | ||
1755 | /** 1101 ddd1 dd11 cond SCcond dest */ | |
1756 | ||
1757 | prefix (0, 1, 0); | |
1758 | dc = decode_dest23 (ddd, dd, 2); | |
1759 | if (condition_true (cond)) | |
1760 | put_dest (dc, 1); | |
1761 | else | |
1762 | put_dest (dc, 0); | |
1763 | ||
1764 | /** 1011 1000 110w 0011 SCMPU.size */ | |
1765 | ||
1766 | ta0 = get_reg (a0); | |
1767 | ta1 = get_reg (a1); | |
1768 | ||
1769 | for (;;) | |
1770 | { | |
1771 | t0 = mem_get_qi (ta0); | |
1772 | t2 = mem_get_qi (ta1); | |
1773 | if (w) | |
1774 | { | |
1775 | t1 = mem_get_qi (ta0 + 1); | |
1776 | t3 = mem_get_qi (ta1 + 1); | |
1777 | } | |
1778 | dif = t0 - t2; | |
1779 | if (dif == 0 && t0 != 0 && w) | |
1780 | dif = t1 - t3; | |
1781 | set_oszc (dif, 1, dif > 0); | |
1782 | ||
1783 | ta0 += w ? 2 : 1; | |
1784 | ta1 += w ? 2 : 1; | |
1785 | ||
1786 | if (t0 == 0 || t0 != t2) | |
1787 | break; | |
1788 | if (w && (t1 == 0 || t1 != t3)) | |
1789 | break; | |
1790 | } | |
1791 | ||
1792 | /** 1111 ddd w dd00 immm SHA.size #IMM,dest */ | |
1793 | ||
1794 | prefix (0, 1, 0); | |
1795 | dc = decode_dest23 (ddd, dd, w+1); | |
1796 | shift_op (dc, 1, IMM4(), 1); | |
1797 | ||
1798 | /** 1010 ddd0 dd10 0001 SHA.L #IMM,dest */ | |
1799 | ||
1800 | prefix (0, 1, 0); | |
1801 | dc = decode_dest23 (ddd, dd, 4); | |
1802 | imm = sign_ext (IMM(1), 8); | |
1803 | shift_op (dc, 1, imm, 1); | |
1804 | ||
1805 | /** 1011 ddd w dd11 1110 SHA.size R1H,dest */ | |
1806 | ||
1807 | prefix (0, 1, 0); | |
1808 | dc = decode_dest23 (ddd, dd, w+1); | |
1809 | a = sign_ext (get_reg (r1h), 8); | |
1810 | shift_op (dc, 1, a, 1); | |
1811 | ||
1812 | /** 1100 ddd0 dd01 0001 SHA.L R1H,dest */ | |
1813 | ||
1814 | prefix (0, 1, 0); | |
1815 | dc = decode_dest23 (ddd, dd, 4); | |
1816 | a = sign_ext (get_reg (r1h), 8); | |
1817 | shift_op (dc, 1, a, 1); | |
1818 | ||
1819 | /** 1100 ddd0 dd10 0001 SHANC.L #IMM,dest */ | |
1820 | ||
1821 | M32C_ONLY(); | |
1822 | prefix (0, 1, 0); | |
1823 | dc = decode_dest23 (ddd, dd, 4); | |
1824 | imm = sign_ext (IMM(1), 8); | |
1825 | shift_op (dc, 1, imm, 0); | |
1826 | ||
1827 | /** 1110 ddd w dd00 immm SHL.size #IMM, dest */ | |
1828 | ||
1829 | prefix (0, 1, 0); | |
1830 | dc = decode_dest23 (ddd, dd, w+1); | |
1831 | shift_op (dc, 0, IMM4(), 1); | |
1832 | ||
1833 | /** 1001 ddd0 dd10 0001 SHL.L #IMM, dest */ | |
1834 | ||
1835 | prefix (0, 1, 0); | |
1836 | dc = decode_dest23 (ddd, dd, 4); | |
1837 | imm = sign_ext (IMM(1), 8); | |
1838 | shift_op (dc, 0, imm, 1); | |
1839 | ||
1840 | /** 1010 ddd w dd11 1110 SHL.size R1H,dest */ | |
1841 | ||
1842 | prefix (0, 1, 0); | |
1843 | dc = decode_dest23 (ddd, dd, w+1); | |
1844 | a = sign_ext (get_reg (r1h), 8); | |
1845 | shift_op (dc, 0, a, 1); | |
1846 | ||
1847 | /** 1100 ddd0 dd00 0001 SHL.L R1H,dest */ | |
1848 | ||
1849 | prefix (0, 1, 0); | |
1850 | dc = decode_dest23 (ddd, dd, 4); | |
1851 | a = sign_ext (get_reg (r1h), 8); | |
1852 | shift_op (dc, 0, a, 1); | |
1853 | ||
1854 | /** 1000 ddd0 dd10 0001 SHLNC.L #IMM,dest */ | |
1855 | ||
1856 | M32C_ONLY(); | |
1857 | prefix (0, 1, 0); | |
1858 | dc = decode_dest23 (ddd, dd, 4); | |
1859 | imm = sign_ext (IMM(1), 8); | |
1860 | shift_op (dc, 0, imm, 0); | |
1861 | ||
1862 | /** 1011 0010 100w 0011 SIN.size */ | |
1863 | ||
1864 | v = get_reg (a0); | |
1865 | a = get_reg (a1); | |
1866 | b = get_reg (r3); | |
1867 | if (b) for (;b;) | |
1868 | { | |
1869 | if (w) | |
1870 | mem_put_hi(a, mem_get_hi (v)); | |
1871 | else | |
1872 | mem_put_qi(a, mem_get_qi (v)); | |
1873 | a += w ? 2 : 1; | |
1874 | b --; | |
1875 | } | |
1876 | put_reg (a0, v); | |
1877 | put_reg (a1, a); | |
1878 | put_reg (r3, b); | |
1879 | ||
1880 | /** 1011 0110 100w 0011 SMOVB.size */ | |
1881 | ||
1882 | v = get_reg (a0); | |
1883 | a = get_reg (a1); | |
1884 | b = get_reg (r3); | |
1885 | if (b) for (;b;) | |
1886 | { | |
1887 | if (w) | |
1888 | mem_put_hi(a, mem_get_hi (v)); | |
1889 | else | |
1890 | mem_put_qi(a, mem_get_qi (v)); | |
1891 | v -= w ? 2 : 1; | |
1892 | a -= w ? 2 : 1; | |
1893 | b --; | |
1894 | } | |
1895 | put_reg (a0, v); | |
1896 | put_reg (a1, a); | |
1897 | put_reg (r3, b); | |
1898 | ||
1899 | /** 1011 0000 100w 0011 SMOVF.size */ | |
1900 | ||
1901 | v = get_reg (a0); | |
1902 | a = get_reg (a1); | |
1903 | b = get_reg (r3); | |
1904 | if (b) for (;b;) | |
1905 | { | |
1906 | if (w) | |
1907 | mem_put_hi(a, mem_get_hi (v)); | |
1908 | else | |
1909 | mem_put_qi(a, mem_get_qi (v)); | |
1910 | v += w ? 2 : 1; | |
1911 | a += w ? 2 : 1; | |
1912 | b --; | |
1913 | } | |
1914 | put_reg (a0, v); | |
1915 | put_reg (a1, a); | |
1916 | put_reg (r3, b); | |
1917 | ||
1918 | /** 1011 1000 100w 0011 SMOVU.size */ | |
1919 | ||
1920 | v = get_reg (a0); | |
1921 | a = get_reg (a1); | |
1922 | do | |
1923 | { | |
1924 | if (w) | |
1925 | mem_put_hi(a, (t0 = mem_get_hi (v))); | |
1926 | else | |
1927 | mem_put_qi(a, (t0 = mem_get_qi (v))); | |
1928 | v += w ? 2 : 1; | |
1929 | a += w ? 2 : 1; | |
1930 | if (t0 == 0 | |
1931 | || (w && ((t0 & 0xff) == 0 || (t0 & 0xff00) == 0))) | |
1932 | break; | |
1933 | } while (1); | |
1934 | put_reg (a0, v); | |
1935 | put_reg (a1, a); | |
1936 | ||
1937 | /** 1011 0100 100w 0011 SOUT.size */ | |
1938 | ||
1939 | v = get_reg (a0); | |
1940 | a = get_reg (a1); | |
1941 | b = get_reg (r3); | |
1942 | for (;b;) | |
1943 | { | |
1944 | if (w) | |
1945 | mem_put_hi(a, mem_get_hi (v)); | |
1946 | else | |
1947 | mem_put_qi(a, mem_get_qi (v)); | |
1948 | v += w ? 2 : 1; | |
1949 | b --; | |
1950 | } | |
1951 | put_reg (a0, v); | |
1952 | put_reg (a1, a); | |
1953 | put_reg (r3, b); | |
1954 | ||
1955 | /** 1011 1000 000w 0011 SSTR.size */ | |
1956 | ||
1957 | a = get_reg (a1); | |
1958 | b = get_reg (r3); | |
3877a145 | 1959 | v = get_reg (w ? r0 : r0l); |
d45a4bef JB |
1960 | for (;b;) |
1961 | { | |
1962 | if (w) | |
3877a145 | 1963 | mem_put_hi(a, v); |
d45a4bef | 1964 | else |
3877a145 | 1965 | mem_put_qi(a, v); |
d45a4bef JB |
1966 | a += w ? 2 : 1; |
1967 | b --; | |
1968 | } | |
1969 | put_reg (a1, a); | |
1970 | put_reg (r3, b); | |
1971 | ||
1972 | /** 0000 0001 1101 ddd1 dd01 0src STC src,dest */ | |
1973 | ||
1974 | prefix (0, 0, 0); | |
1975 | dc = decode_dest23 (ddd, dd, 4); | |
1976 | sc = decode_cr_b (src, CR_B_DMA0); | |
1977 | a = get_src (sc); | |
1978 | put_dest (dc, a); | |
1979 | ||
1980 | /** 0000 0001 1101 ddd1 dd01 1src STC src,dest */ | |
1981 | ||
1982 | prefix (0, 0, 0); | |
1983 | dc = decode_dest23 (ddd, dd, 2); | |
1984 | sc = decode_cr_b (src, CR_B_DCT0); | |
1985 | a = get_src (sc); | |
1986 | put_dest (dc, a); | |
1987 | ||
1988 | /** 1101 ddd1 dd01 0src STC src,dest */ | |
1989 | ||
1990 | prefix (0, 0, 0); | |
1991 | dc = decode_dest23 (ddd, dd, 4); | |
1992 | sc = decode_cr_b (src, CR_B_INTB); | |
1993 | a = get_src (sc); | |
1994 | put_dest (dc, a); | |
1995 | ||
1996 | /** 1011 0110 1101 0011 STCX abs16,abs24 */ | |
1997 | ||
1998 | NOTYET(); | |
1999 | ||
2000 | /** 1001 ddd w dd01 1111 STNZ.size #IMM,dest */ | |
2001 | ||
2002 | prefix (0, 1, 0); | |
2003 | dc = decode_dest23 (ddd, dd, w+1); | |
2004 | imm = IMM(w+1); | |
2005 | if (! FLAG_Z) | |
2006 | put_dest (dc, imm); | |
2007 | ||
2008 | /** 1001 ddd w dd00 1111 STZ.size #IMM,dest */ | |
2009 | ||
2010 | prefix (0, 1, 0); | |
2011 | dc = decode_dest23 (ddd, dd, w+1); | |
2012 | imm = IMM(w+1); | |
2013 | if (FLAG_Z) | |
2014 | put_dest (dc, imm); | |
2015 | ||
2016 | /** 1001 ddd w dd11 1111 STZX.size #IMM1,#IMM2,dest */ | |
2017 | ||
2018 | prefix (0, 1, 0); | |
2019 | dc = decode_dest23 (ddd, dd, w+1); | |
2020 | a = IMM(w+1); | |
2021 | b = IMM(w+1); | |
2022 | if (FLAG_Z) | |
2023 | put_dest (dc, a); | |
2024 | else | |
2025 | put_dest (dc, b); | |
2026 | ||
2027 | /** 1000 ddd w dd11 1110 SUB.size:G #IMM,dest */ | |
2028 | ||
2029 | prefix (0, 1, 0); | |
2030 | dc = decode_dest23(ddd, dd, w+1); | |
2031 | imm = IMM(w+1); | |
2032 | MATH_OP (dc, imm, 0, -); | |
2033 | ||
2034 | /** 1001 ddd0 dd11 0001 SUB.L:G #IMM,dest */ | |
2035 | ||
2036 | prefix (0, 1, 0); | |
2037 | dc = decode_dest23(ddd, dd, 4); | |
2038 | imm = IMM(4); | |
2039 | MATH_OP (dc, imm, 0, -); | |
2040 | ||
2041 | /** 00dd 111w SUB.size:S #IMM,dest */ | |
2042 | ||
2043 | prefix (0, 1, 0); | |
2044 | dc = decode_dest2(dd, w+1); | |
2045 | imm = IMM (w+1); | |
2046 | MATH_OP (dc, imm, 0, -); | |
2047 | ||
2048 | /** 1sss ddd w dd ss 1010 SUB.size:G src,dest */ | |
2049 | ||
2050 | prefix (1, 1, 0); | |
2051 | sc = decode_src23(sss, ss, w+1); | |
2052 | dc = decode_dest23(ddd, dd, w+1); | |
2053 | b = get_src (sc); | |
2054 | MATH_OP (dc, b, 0, -); | |
2055 | ||
2056 | /** 1sss ddd1 dd ss 0000 SUB.L:G src,dest */ | |
2057 | ||
2058 | prefix (1, 1, 0); | |
2059 | sc = decode_src23(sss, ss, 4); | |
2060 | dc = decode_dest23(ddd, dd, 4); | |
2061 | b = get_src (sc); | |
2062 | MATH_OP (dc, b, 0, -); | |
2063 | ||
2064 | /** 1001 ddd0 dd01 0001 SUBX #IMM,dest */ | |
2065 | ||
2066 | prefix (0, 1, 0); | |
2067 | dc = decode_dest23(ddd, dd, 4); | |
2068 | imm = sign_ext (IMM(1), 8); | |
2069 | MATH_OP (dc, imm, 0, -); | |
2070 | ||
2071 | /** 1sss ddd0 dd ss 0000 SUBX src,dest */ | |
2072 | ||
2073 | prefix (1, 1, 0); | |
2074 | sc = decode_src23(sss, ss, 1); | |
2075 | dc = decode_dest23(ddd, dd, 4); | |
2076 | b = sign_ext (get_src (sc), 8); | |
2077 | MATH_OP (dc, b, 0, -); | |
2078 | ||
2079 | /** 1001 ddd w dd11 1110 TST.size:G #IMM,dest */ | |
2080 | ||
2081 | prefix (0, 0, 0); | |
2082 | dc = decode_dest23 (ddd, dd, w+1); | |
2083 | imm = IMM(w+1); | |
2084 | a = get_src (dc); | |
2085 | v = a & imm; | |
2086 | set_sz (v, w+1); | |
2087 | ||
2088 | /** 00dd 110w TST.size:S #IMM,dest */ | |
2089 | ||
2090 | prefix (0, 0, 0); | |
2091 | dc = decode_dest2 (dd, w+1); | |
2092 | imm = IMM(w+1); | |
2093 | a = get_src (dc); | |
2094 | v = a & imm; | |
2095 | set_sz (v, w+1); | |
2096 | ||
2097 | /** 0000 0001 1sss ddd w dd ss 1001 TST.size:G src,dest */ | |
2098 | ||
2099 | prefix (0, 0, 0); | |
2100 | sc = decode_src23 (sss, ss, w+1); | |
2101 | dc = decode_dest23 (ddd, dd, w+1); | |
2102 | b = get_src (sc); | |
2103 | a = get_src (dc); | |
2104 | v = a & b; | |
2105 | set_sz (v, w+1); | |
2106 | ||
2107 | /** 1111 1111 UND */ | |
2108 | ||
2109 | trigger_fixed_interrupt (0xffffdc); | |
2110 | ||
2111 | /** 1011 0010 0000 0011 WAIT */ | |
2112 | ||
2113 | ; | |
2114 | ||
2115 | /** 1101 ddd w dd00 1src XCHG.size src,dest */ | |
2116 | ||
2117 | dc = decode_dest23 (ddd, dd, w+1); | |
2118 | sc = decode_src3 (src, w+1); | |
2119 | a = get_src (dc); | |
2120 | b = get_src (sc); | |
2121 | put_dest (dc, b); | |
2122 | put_dest (sc, a); | |
2123 | ||
2124 | /** 1001 ddd w dd00 1110 XOR.size #IMM,dest */ | |
2125 | ||
2126 | prefix (0, 1, 0); | |
2127 | dc = decode_dest23(ddd, dd, w+1); | |
2128 | imm = IMM(w+1); | |
2129 | LOGIC_OP (dc, imm, ^); | |
2130 | ||
2131 | /** 1sss ddd w dd ss 1001 XOR.size src,dest */ | |
2132 | ||
2133 | prefix (1, 1, 0); | |
2134 | sc = decode_src23(sss, ss, w+1); | |
2135 | dc = decode_dest23(ddd, dd, w+1); | |
2136 | b = get_src (sc); | |
2137 | LOGIC_OP (dc, b, ^); | |
2138 | ||
2139 | /** */ | |
2140 | ||
2141 | return step_result; | |
2142 | } |