Automatic date update in version.in
[binutils-gdb.git] / sim / cr16 / simops.c
blobd58c0c93395378d3e7e46bce0bcbb1a12fc2a760
1 /* Simulation code for the CR16 processor.
2 Copyright (C) 2008-2022 Free Software Foundation, Inc.
3 Contributed by M Ranga Swami Reddy <MR.Swami.Reddy@nsc.com>
5 This file is part of GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* This must come before any other includes. */
21 #include "defs.h"
23 #include <signal.h>
24 #include <errno.h>
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #ifdef HAVE_UNISTD_H
28 #include <unistd.h>
29 #endif
30 #include <string.h>
31 #include <time.h>
32 #include <sys/time.h>
34 #include "sim-main.h"
35 #include "sim-signal.h"
36 #include "simops.h"
37 #include "target-newlib-syscall.h"
39 #ifdef HAVE_UTIME_H
40 #include <utime.h>
41 #endif
42 #include <sys/wait.h>
44 #define EXCEPTION(sig) sim_engine_halt (sd, cpu, NULL, PC, sim_stopped, sig)
46 enum op_types {
47 OP_VOID,
48 OP_CONSTANT3,
49 OP_UCONSTANT3,
50 OP_CONSTANT4,
51 OP_CONSTANT4_1,
52 OP_CONSTANT5,
53 OP_CONSTANT6,
54 OP_CONSTANT16,
55 OP_UCONSTANT16,
56 OP_CONSTANT20,
57 OP_UCONSTANT20,
58 OP_CONSTANT32,
59 OP_UCONSTANT32,
60 OP_MEMREF,
61 OP_MEMREF2,
62 OP_MEMREF3,
64 OP_DISP5,
65 OP_DISP17,
66 OP_DISP25,
67 OP_DISPE9,
68 //OP_ABS20,
69 OP_ABS20_OUTPUT,
70 //OP_ABS24,
71 OP_ABS24_OUTPUT,
73 OP_R_BASE_DISPS16,
74 OP_R_BASE_DISP20,
75 OP_R_BASE_DISPS20,
76 OP_R_BASE_DISPE20,
78 OP_RP_BASE_DISPE0,
79 OP_RP_BASE_DISP4,
80 OP_RP_BASE_DISPE4,
81 OP_RP_BASE_DISP14,
82 OP_RP_BASE_DISP16,
83 OP_RP_BASE_DISP20,
84 OP_RP_BASE_DISPS20,
85 OP_RP_BASE_DISPE20,
87 OP_R_INDEX7_ABS20,
88 OP_R_INDEX8_ABS20,
90 OP_RP_INDEX_DISP0,
91 OP_RP_INDEX_DISP14,
92 OP_RP_INDEX_DISP20,
93 OP_RP_INDEX_DISPS20,
95 OP_REG,
96 OP_REGP,
97 OP_PROC_REG,
98 OP_PROC_REGP,
99 OP_COND,
100 OP_RA
104 enum {
105 PSR_MASK = (PSR_I_BIT
106 | PSR_P_BIT
107 | PSR_E_BIT
108 | PSR_N_BIT
109 | PSR_Z_BIT
110 | PSR_F_BIT
111 | PSR_U_BIT
112 | PSR_L_BIT
113 | PSR_T_BIT
114 | PSR_C_BIT),
115 /* The following bits in the PSR _can't_ be set by instructions such
116 as mvtc. */
117 PSR_HW_MASK = (PSR_MASK)
120 /* cond Code Condition True State
121 * EQ Equal Z flag is 1
122 * NE Not Equal Z flag is 0
123 * CS Carry Set C flag is 1
124 * CC Carry Clear C flag is 0
125 * HI Higher L flag is 1
126 * LS Lower or Same L flag is 0
127 * GT Greater Than N flag is 1
128 * LE Less Than or Equal To N flag is 0
129 * FS Flag Set F flag is 1
130 * FC Flag Clear F flag is 0
131 * LO Lower Z and L flags are 0
132 * HS Higher or Same Z or L flag is 1
133 * LT Less Than Z and N flags are 0
134 * GE Greater Than or Equal To Z or N flag is 1. */
136 static int cond_stat(int cc)
138 switch (cc)
140 case 0: return PSR_Z; break;
141 case 1: return !PSR_Z; break;
142 case 2: return PSR_C; break;
143 case 3: return !PSR_C; break;
144 case 4: return PSR_L; break;
145 case 5: return !PSR_L; break;
146 case 6: return PSR_N; break;
147 case 7: return !PSR_N; break;
148 case 8: return PSR_F; break;
149 case 9: return !PSR_F; break;
150 case 10: return !PSR_Z && !PSR_L; break;
151 case 11: return PSR_Z || PSR_L; break;
152 case 12: return !PSR_Z && !PSR_N; break;
153 case 13: return PSR_Z || PSR_N; break;
154 case 14: return 1; break; /*ALWAYS. */
155 default:
156 // case NEVER: return false; break;
157 //case NO_COND_CODE:
158 //panic("Shouldn't have NO_COND_CODE in an actual instruction!");
159 return 0; break;
161 return 0;
165 creg_t
166 move_to_cr (SIM_DESC sd, SIM_CPU *cpu, int cr, creg_t mask, creg_t val, int psw_hw_p)
168 /* A MASK bit is set when the corresponding bit in the CR should
169 be left alone. */
170 /* This assumes that (VAL & MASK) == 0. */
171 switch (cr)
173 case PSR_CR:
174 if (psw_hw_p)
175 val &= PSR_HW_MASK;
176 #if 0
177 else
178 val &= PSR_MASK;
179 sim_io_printf
180 (sd,
181 "ERROR at PC 0x%x: ST can only be set when FX is set.\n", PC);
182 EXCEPTION (SIM_SIGILL);
183 #endif
184 /* keep an up-to-date psw around for tracing. */
185 State.trace.psw = (State.trace.psw & mask) | val;
186 break;
187 default:
188 break;
190 /* only issue an update if the register is being changed. */
191 if ((State.cregs[cr] & ~mask) != val)
192 SLOT_PEND_MASK (State.cregs[cr], mask, val);
194 return val;
197 #ifdef DEBUG
198 static void trace_input_func (SIM_DESC sd,
199 const char *name,
200 enum op_types in1,
201 enum op_types in2,
202 enum op_types in3);
204 #define trace_input(name, in1, in2, in3) do { if (cr16_debug) trace_input_func (sd, name, in1, in2, in3); } while (0)
206 #ifndef SIZE_INSTRUCTION
207 #define SIZE_INSTRUCTION 8
208 #endif
210 #ifndef SIZE_OPERANDS
211 #define SIZE_OPERANDS 18
212 #endif
214 #ifndef SIZE_VALUES
215 #define SIZE_VALUES 13
216 #endif
218 #ifndef SIZE_LOCATION
219 #define SIZE_LOCATION 20
220 #endif
222 #ifndef SIZE_PC
223 #define SIZE_PC 4
224 #endif
226 #ifndef SIZE_LINE_NUMBER
227 #define SIZE_LINE_NUMBER 2
228 #endif
230 static void
231 trace_input_func (SIM_DESC sd, const char *name, enum op_types in1, enum op_types in2, enum op_types in3)
233 char *comma;
234 enum op_types in[3];
235 int i;
236 char buf[1024];
237 char *p;
238 long tmp;
239 char *type;
240 const char *filename;
241 const char *functionname;
242 unsigned int linenumber;
243 bfd_vma byte_pc;
245 if ((cr16_debug & DEBUG_TRACE) == 0)
246 return;
248 switch (State.ins_type)
250 default:
251 case INS_UNKNOWN: type = " ?"; break;
254 if ((cr16_debug & DEBUG_LINE_NUMBER) == 0)
255 sim_io_printf (sd,
256 "0x%.*x %s: %-*s ",
257 SIZE_PC, (unsigned)PC,
258 type,
259 SIZE_INSTRUCTION, name);
261 else
263 buf[0] = '\0';
264 byte_pc = PC;
265 if (STATE_TEXT_SECTION (sd)
266 && byte_pc >= STATE_TEXT_START (sd)
267 && byte_pc < STATE_TEXT_END (sd))
269 filename = (const char *)0;
270 functionname = (const char *)0;
271 linenumber = 0;
272 if (bfd_find_nearest_line (STATE_PROG_BFD (sd),
273 STATE_TEXT_SECTION (sd),
274 (struct bfd_symbol **)0,
275 byte_pc - STATE_TEXT_START (sd),
276 &filename, &functionname, &linenumber))
278 p = buf;
279 if (linenumber)
281 sprintf (p, "#%-*d ", SIZE_LINE_NUMBER, linenumber);
282 p += strlen (p);
284 else
286 sprintf (p, "%-*s ", SIZE_LINE_NUMBER+1, "---");
287 p += SIZE_LINE_NUMBER+2;
290 if (functionname)
292 sprintf (p, "%s ", functionname);
293 p += strlen (p);
295 else if (filename)
297 char *q = strrchr (filename, '/');
298 sprintf (p, "%s ", (q) ? q+1 : filename);
299 p += strlen (p);
302 if (*p == ' ')
303 *p = '\0';
307 sim_io_printf (sd,
308 "0x%.*x %s: %-*.*s %-*s ",
309 SIZE_PC, (unsigned)PC,
310 type,
311 SIZE_LOCATION, SIZE_LOCATION, buf,
312 SIZE_INSTRUCTION, name);
315 in[0] = in1;
316 in[1] = in2;
317 in[2] = in3;
318 comma = "";
319 p = buf;
320 for (i = 0; i < 3; i++)
322 switch (in[i])
324 case OP_VOID:
325 break;
327 case OP_REG:
328 case OP_REGP:
329 sprintf (p, "%sr%d", comma, OP[i]);
330 p += strlen (p);
331 comma = ",";
332 break;
334 case OP_PROC_REG:
335 sprintf (p, "%scr%d", comma, OP[i]);
336 p += strlen (p);
337 comma = ",";
338 break;
340 case OP_CONSTANT16:
341 sprintf (p, "%s%d", comma, OP[i]);
342 p += strlen (p);
343 comma = ",";
344 break;
346 case OP_CONSTANT4:
347 sprintf (p, "%s%d", comma, SEXT4(OP[i]));
348 p += strlen (p);
349 comma = ",";
350 break;
352 case OP_CONSTANT3:
353 sprintf (p, "%s%d", comma, SEXT3(OP[i]));
354 p += strlen (p);
355 comma = ",";
356 break;
358 case OP_MEMREF:
359 sprintf (p, "%s@r%d", comma, OP[i]);
360 p += strlen (p);
361 comma = ",";
362 break;
364 case OP_MEMREF2:
365 sprintf (p, "%s@(%d,r%d)", comma, (int16_t)OP[i], OP[i+1]);
366 p += strlen (p);
367 comma = ",";
368 break;
370 case OP_MEMREF3:
371 sprintf (p, "%s@%d", comma, OP[i]);
372 p += strlen (p);
373 comma = ",";
374 break;
378 if ((cr16_debug & DEBUG_VALUES) == 0)
380 *p++ = '\n';
381 *p = '\0';
382 sim_io_printf (sd, "%s", buf);
384 else
386 *p = '\0';
387 sim_io_printf (sd, "%-*s", SIZE_OPERANDS, buf);
389 p = buf;
390 for (i = 0; i < 3; i++)
392 buf[0] = '\0';
393 switch (in[i])
395 case OP_VOID:
396 sim_io_printf (sd, "%*s", SIZE_VALUES, "");
397 break;
399 case OP_REG:
400 sim_io_printf (sd, "%*s0x%.4x", SIZE_VALUES-6, "",
401 (uint16_t) GPR (OP[i]));
402 break;
404 case OP_REGP:
405 tmp = (long)((((uint32_t) GPR (OP[i])) << 16) | ((uint32_t) GPR (OP[i] + 1)));
406 sim_io_printf (sd, "%*s0x%.8lx", SIZE_VALUES-10, "", tmp);
407 break;
409 case OP_PROC_REG:
410 sim_io_printf (sd, "%*s0x%.4x", SIZE_VALUES-6, "",
411 (uint16_t) CREG (OP[i]));
412 break;
414 case OP_CONSTANT16:
415 sim_io_printf (sd, "%*s0x%.4x", SIZE_VALUES-6, "",
416 (uint16_t)OP[i]);
417 break;
419 case OP_CONSTANT4:
420 sim_io_printf (sd, "%*s0x%.4x", SIZE_VALUES-6, "",
421 (uint16_t)SEXT4(OP[i]));
422 break;
424 case OP_CONSTANT3:
425 sim_io_printf (sd, "%*s0x%.4x", SIZE_VALUES-6, "",
426 (uint16_t)SEXT3(OP[i]));
427 break;
429 case OP_MEMREF2:
430 sim_io_printf (sd, "%*s0x%.4x", SIZE_VALUES-6, "",
431 (uint16_t)OP[i]);
432 sim_io_printf (sd, "%*s0x%.4x", SIZE_VALUES-6, "",
433 (uint16_t)GPR (OP[i + 1]));
434 i++;
435 break;
440 sim_io_flush_stdout (sd);
443 static void
444 do_trace_output_flush (SIM_DESC sd)
446 sim_io_flush_stdout (sd);
449 static void
450 do_trace_output_finish (SIM_DESC sd)
452 sim_io_printf (sd,
453 " F0=%d F1=%d C=%d\n",
454 (State.trace.psw & PSR_F_BIT) != 0,
455 (State.trace.psw & PSR_F_BIT) != 0,
456 (State.trace.psw & PSR_C_BIT) != 0);
457 sim_io_flush_stdout (sd);
460 #if 0
461 static void
462 trace_output_40 (SIM_DESC sd, uint64_t val)
464 if ((cr16_debug & (DEBUG_TRACE | DEBUG_VALUES)) == (DEBUG_TRACE | DEBUG_VALUES))
466 sim_io_printf (sd,
467 " :: %*s0x%.2x%.8lx",
468 SIZE_VALUES - 12,
470 ((int)(val >> 32) & 0xff),
471 ((unsigned long) val) & 0xffffffff);
472 do_trace_output_finish ();
475 #endif
477 static void
478 trace_output_32 (SIM_DESC sd, uint32_t val)
480 if ((cr16_debug & (DEBUG_TRACE | DEBUG_VALUES)) == (DEBUG_TRACE | DEBUG_VALUES))
482 sim_io_printf (sd,
483 " :: %*s0x%.8x",
484 SIZE_VALUES - 10,
486 (int) val);
487 do_trace_output_finish (sd);
491 static void
492 trace_output_16 (SIM_DESC sd, uint16_t val)
494 if ((cr16_debug & (DEBUG_TRACE | DEBUG_VALUES)) == (DEBUG_TRACE | DEBUG_VALUES))
496 sim_io_printf (sd,
497 " :: %*s0x%.4x",
498 SIZE_VALUES - 6,
500 (int) val);
501 do_trace_output_finish (sd);
505 static void
506 trace_output_void (SIM_DESC sd)
508 if ((cr16_debug & (DEBUG_TRACE | DEBUG_VALUES)) == (DEBUG_TRACE | DEBUG_VALUES))
510 sim_io_printf (sd, "\n");
511 do_trace_output_flush (sd);
515 static void
516 trace_output_flag (SIM_DESC sd)
518 if ((cr16_debug & (DEBUG_TRACE | DEBUG_VALUES)) == (DEBUG_TRACE | DEBUG_VALUES))
520 sim_io_printf (sd,
521 " :: %*s",
522 SIZE_VALUES,
523 "");
524 do_trace_output_finish (sd);
531 #else
532 #define trace_input(NAME, IN1, IN2, IN3)
533 #define trace_output(RESULT)
534 #endif
536 /* addub. */
537 void
538 OP_2C_8 (SIM_DESC sd, SIM_CPU *cpu)
540 uint8_t tmp;
541 uint8_t a = OP[0] & 0xff;
542 uint16_t b = (GPR (OP[1])) & 0xff;
543 trace_input ("addub", OP_CONSTANT4_1, OP_REG, OP_VOID);
544 tmp = (a + b) & 0xff;
545 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
546 trace_output_16 (sd, tmp);
549 /* addub. */
550 void
551 OP_2CB_C (SIM_DESC sd, SIM_CPU *cpu)
553 uint16_t tmp;
554 uint8_t a = ((OP[0]) & 0xff), b = (GPR (OP[1])) & 0xff;
555 trace_input ("addub", OP_CONSTANT16, OP_REG, OP_VOID);
556 tmp = (a + b) & 0xff;
557 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
558 trace_output_16 (sd, tmp);
561 /* addub. */
562 void
563 OP_2D_8 (SIM_DESC sd, SIM_CPU *cpu)
565 uint8_t a = (GPR (OP[0])) & 0xff;
566 uint8_t b = (GPR (OP[1])) & 0xff;
567 uint16_t tmp = (a + b) & 0xff;
568 trace_input ("addub", OP_REG, OP_REG, OP_VOID);
569 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
570 trace_output_16 (sd, tmp);
573 /* adduw. */
574 void
575 OP_2E_8 (SIM_DESC sd, SIM_CPU *cpu)
577 uint16_t a = OP[0];
578 uint16_t b = GPR (OP[1]);
579 uint16_t tmp = (a + b);
580 trace_input ("adduw", OP_CONSTANT4_1, OP_REG, OP_VOID);
581 SET_GPR (OP[1], tmp);
582 trace_output_16 (sd, tmp);
585 /* adduw. */
586 void
587 OP_2EB_C (SIM_DESC sd, SIM_CPU *cpu)
589 uint16_t a = OP[0];
590 uint16_t b = GPR (OP[1]);
591 uint16_t tmp = (a + b);
592 trace_input ("adduw", OP_CONSTANT16, OP_REG, OP_VOID);
593 SET_GPR (OP[1], tmp);
594 trace_output_16 (sd, tmp);
597 /* adduw. */
598 void
599 OP_2F_8 (SIM_DESC sd, SIM_CPU *cpu)
601 uint16_t a = GPR (OP[0]);
602 uint16_t b = GPR (OP[1]);
603 uint16_t tmp = (a + b);
604 trace_input ("adduw", OP_REG, OP_REG, OP_VOID);
605 SET_GPR (OP[1], tmp);
606 trace_output_16 (sd, tmp);
609 /* addb. */
610 void
611 OP_30_8 (SIM_DESC sd, SIM_CPU *cpu)
613 uint8_t a = OP[0];
614 uint8_t b = (GPR (OP[1]) & 0xff);
615 uint16_t tmp = (a + b) & 0xff;
616 trace_input ("addb", OP_CONSTANT4_1, OP_REG, OP_VOID);
617 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
618 SET_PSR_C (tmp > 0xFF);
619 SET_PSR_F (((a & 0x80) == (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
620 trace_output_16 (sd, tmp);
623 /* addb. */
624 void
625 OP_30B_C (SIM_DESC sd, SIM_CPU *cpu)
627 uint8_t a = (OP[0]) & 0xff;
628 uint8_t b = (GPR (OP[1]) & 0xff);
629 uint16_t tmp = (a + b) & 0xff;
630 trace_input ("addb", OP_CONSTANT16, OP_REG, OP_VOID);
631 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
632 SET_PSR_C (tmp > 0xFF);
633 SET_PSR_F (((a & 0x80) == (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
634 trace_output_16 (sd, tmp);
637 /* addb. */
638 void
639 OP_31_8 (SIM_DESC sd, SIM_CPU *cpu)
641 uint8_t a = (GPR (OP[0]) & 0xff);
642 uint8_t b = (GPR (OP[1]) & 0xff);
643 uint16_t tmp = (a + b) & 0xff;
644 trace_input ("addb", OP_REG, OP_REG, OP_VOID);
645 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
646 SET_PSR_C (tmp > 0xFF);
647 SET_PSR_F (((a & 0x80) == (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
648 trace_output_16 (sd, tmp);
651 /* addw. */
652 void
653 OP_32_8 (SIM_DESC sd, SIM_CPU *cpu)
655 int16_t a = OP[0];
656 uint16_t tmp, b = GPR (OP[1]);
657 tmp = (a + b);
658 trace_input ("addw", OP_CONSTANT4_1, OP_REG, OP_VOID);
659 SET_GPR (OP[1], tmp);
660 SET_PSR_C (tmp > 0xFFFF);
661 SET_PSR_F (((a & 0x8000) == (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
662 trace_output_16 (sd, tmp);
665 /* addw. */
666 void
667 OP_32B_C (SIM_DESC sd, SIM_CPU *cpu)
669 int16_t a = OP[0];
670 uint16_t tmp, b = GPR (OP[1]);
671 tmp = (a + b);
672 trace_input ("addw", OP_CONSTANT16, OP_REG, OP_VOID);
673 SET_GPR (OP[1], tmp);
674 SET_PSR_C (tmp > 0xFFFF);
675 SET_PSR_F (((a & 0x8000) == (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
676 trace_output_16 (sd, tmp);
679 /* addw. */
680 void
681 OP_33_8 (SIM_DESC sd, SIM_CPU *cpu)
683 uint16_t tmp, a = (GPR (OP[0])), b = (GPR (OP[1]));
684 trace_input ("addw", OP_REG, OP_REG, OP_VOID);
685 tmp = (a + b);
686 SET_GPR (OP[1], tmp);
687 SET_PSR_C (tmp > 0xFFFF);
688 SET_PSR_F (((a & 0x8000) == (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
689 trace_output_16 (sd, tmp);
692 /* addcb. */
693 void
694 OP_34_8 (SIM_DESC sd, SIM_CPU *cpu)
696 uint8_t tmp, a = OP[0] & 0xff, b = (GPR (OP[1])) & 0xff;
697 trace_input ("addcb", OP_CONSTANT4_1, OP_REG, OP_REG);
698 tmp = (a + b + PSR_C) & 0xff;
699 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
700 SET_PSR_C (tmp > 0xFF);
701 SET_PSR_F (((a & 0x80) == (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
702 trace_output_16 (sd, tmp);
705 /* addcb. */
706 void
707 OP_34B_C (SIM_DESC sd, SIM_CPU *cpu)
709 int8_t a = OP[0] & 0xff;
710 uint8_t b = (GPR (OP[1])) & 0xff;
711 uint8_t tmp = (a + b + PSR_C) & 0xff;
712 trace_input ("addcb", OP_CONSTANT16, OP_REG, OP_VOID);
713 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
714 SET_PSR_C (tmp > 0xFF);
715 SET_PSR_F (((a & 0x80) == (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
716 trace_output_16 (sd, tmp);
719 /* addcb. */
720 void
721 OP_35_8 (SIM_DESC sd, SIM_CPU *cpu)
723 uint8_t a = (GPR (OP[0])) & 0xff;
724 uint8_t b = (GPR (OP[1])) & 0xff;
725 uint8_t tmp = (a + b + PSR_C) & 0xff;
726 trace_input ("addcb", OP_REG, OP_REG, OP_VOID);
727 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
728 SET_PSR_C (tmp > 0xFF);
729 SET_PSR_F (((a & 0x80) == (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
730 trace_output_16 (sd, tmp);
733 /* addcw. */
734 void
735 OP_36_8 (SIM_DESC sd, SIM_CPU *cpu)
737 uint16_t a = OP[0];
738 uint16_t b = GPR (OP[1]);
739 uint16_t tmp = (a + b + PSR_C);
740 trace_input ("addcw", OP_CONSTANT4_1, OP_REG, OP_VOID);
741 SET_GPR (OP[1], tmp);
742 SET_PSR_C (tmp > 0xFFFF);
743 SET_PSR_F (((a & 0x8000) == (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
744 trace_output_16 (sd, tmp);
747 /* addcw. */
748 void
749 OP_36B_C (SIM_DESC sd, SIM_CPU *cpu)
751 int16_t a = OP[0];
752 uint16_t b = GPR (OP[1]);
753 uint16_t tmp = (a + b + PSR_C);
754 trace_input ("addcw", OP_CONSTANT16, OP_REG, OP_VOID);
755 SET_GPR (OP[1], tmp);
756 SET_PSR_C (tmp > 0xFFFF);
757 SET_PSR_F (((a & 0x8000) == (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
758 trace_output_16 (sd, tmp);
761 /* addcw. */
762 void
763 OP_37_8 (SIM_DESC sd, SIM_CPU *cpu)
765 uint16_t a = GPR (OP[1]);
766 uint16_t b = GPR (OP[1]);
767 uint16_t tmp = (a + b + PSR_C);
768 trace_input ("addcw", OP_REG, OP_REG, OP_VOID);
769 SET_GPR (OP[1], tmp);
770 SET_PSR_C (tmp > 0xFFFF);
771 SET_PSR_F (((a & 0x8000) == (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
772 trace_output_16 (sd, tmp);
775 /* addd. */
776 void
777 OP_60_8 (SIM_DESC sd, SIM_CPU *cpu)
779 int16_t a = (OP[0]);
780 uint32_t b = GPR32 (OP[1]);
781 uint32_t tmp = (a + b);
782 trace_input ("addd", OP_CONSTANT4_1, OP_REGP, OP_VOID);
783 SET_GPR32 (OP[1], tmp);
784 SET_PSR_C (tmp > 0xFFFFFFFF);
785 SET_PSR_F (((a & 0x80000000) == (b & 0x80000000)) && ((b & 0x80000000) != (tmp & 0x80000000)));
786 trace_output_32 (sd, tmp);
789 /* addd. */
790 void
791 OP_60B_C (SIM_DESC sd, SIM_CPU *cpu)
793 int32_t a = (SEXT16(OP[0]));
794 uint32_t b = GPR32 (OP[1]);
795 uint32_t tmp = (a + b);
796 trace_input ("addd", OP_CONSTANT16, OP_REGP, OP_VOID);
797 SET_GPR32 (OP[1], tmp);
798 SET_PSR_C (tmp > 0xFFFFFFFF);
799 SET_PSR_F (((a & 0x80000000) == (b & 0x80000000)) && ((b & 0x80000000) != (tmp & 0x80000000)));
800 trace_output_32 (sd, tmp);
803 /* addd. */
804 void
805 OP_61_8 (SIM_DESC sd, SIM_CPU *cpu)
807 uint32_t a = GPR32 (OP[0]);
808 uint32_t b = GPR32 (OP[1]);
809 uint32_t tmp = (a + b);
810 trace_input ("addd", OP_REGP, OP_REGP, OP_VOID);
811 SET_GPR32 (OP[1], tmp);
812 trace_output_32 (sd, tmp);
813 SET_PSR_C (tmp > 0xFFFFFFFF);
814 SET_PSR_F (((a & 0x80000000) == (b & 0x80000000)) && ((b & 0x80000000) != (tmp & 0x80000000)));
817 /* addd. */
818 void
819 OP_4_8 (SIM_DESC sd, SIM_CPU *cpu)
821 uint32_t a = OP[0];
822 uint32_t b = GPR32 (OP[1]);
823 uint32_t tmp;
824 trace_input ("addd", OP_CONSTANT20, OP_REGP, OP_VOID);
825 tmp = (a + b);
826 SET_GPR32 (OP[1], tmp);
827 SET_PSR_C (tmp > 0xFFFFFFFF);
828 SET_PSR_F (((a & 0x80000000) == (b & 0x80000000)) && ((b & 0x80000000) != (tmp & 0x80000000)));
829 trace_output_32 (sd, tmp);
832 /* addd. */
833 void
834 OP_2_C (SIM_DESC sd, SIM_CPU *cpu)
836 int32_t a = OP[0];
837 uint32_t b = GPR32 (OP[1]);
838 uint32_t tmp;
839 trace_input ("addd", OP_CONSTANT32, OP_REGP, OP_VOID);
840 tmp = (a + b);
841 SET_GPR32 (OP[1], tmp);
842 SET_PSR_C (tmp > 0xFFFFFFFF);
843 SET_PSR_F (((a & 0x80000000) == (b & 0x80000000)) && ((b & 0x80000000) != (tmp & 0x80000000)));
844 trace_output_32 (sd, tmp);
847 /* andb. */
848 void
849 OP_20_8 (SIM_DESC sd, SIM_CPU *cpu)
851 uint8_t tmp, a = (OP[0]) & 0xff, b = (GPR (OP[1])) & 0xff;
852 trace_input ("andb", OP_CONSTANT4, OP_REG, OP_VOID);
853 tmp = a & b;
854 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
855 trace_output_16 (sd, tmp);
858 /* andb. */
859 void
860 OP_20B_C (SIM_DESC sd, SIM_CPU *cpu)
862 uint8_t tmp, a = (OP[0]) & 0xff, b = (GPR (OP[1])) & 0xff;
863 trace_input ("andb", OP_CONSTANT16, OP_REG, OP_VOID);
864 tmp = a & b;
865 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
866 trace_output_16 (sd, tmp);
869 /* andb. */
870 void
871 OP_21_8 (SIM_DESC sd, SIM_CPU *cpu)
873 uint8_t tmp, a = (GPR (OP[0])) & 0xff, b = (GPR (OP[1])) & 0xff;
874 trace_input ("andb", OP_REG, OP_REG, OP_VOID);
875 tmp = a & b;
876 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
877 trace_output_16 (sd, tmp);
880 /* andw. */
881 void
882 OP_22_8 (SIM_DESC sd, SIM_CPU *cpu)
884 uint16_t tmp, a = OP[0], b = GPR (OP[1]);
885 trace_input ("andw", OP_CONSTANT4, OP_REG, OP_VOID);
886 tmp = a & b;
887 SET_GPR (OP[1], tmp);
888 trace_output_16 (sd, tmp);
891 /* andw. */
892 void
893 OP_22B_C (SIM_DESC sd, SIM_CPU *cpu)
895 uint16_t tmp, a = OP[0], b = GPR (OP[1]);
896 trace_input ("andw", OP_CONSTANT16, OP_REG, OP_VOID);
897 tmp = a & b;
898 SET_GPR (OP[1], tmp);
899 trace_output_16 (sd, tmp);
902 /* andw. */
903 void
904 OP_23_8 (SIM_DESC sd, SIM_CPU *cpu)
906 uint16_t tmp, a = GPR (OP[0]), b = GPR (OP[1]);
907 trace_input ("andw", OP_REG, OP_REG, OP_VOID);
908 tmp = a & b;
909 SET_GPR (OP[1], tmp);
910 trace_output_16 (sd, tmp);
913 /* andd. */
914 void
915 OP_4_C (SIM_DESC sd, SIM_CPU *cpu)
917 uint32_t tmp, a = OP[0], b = GPR32 (OP[1]);
918 trace_input ("andd", OP_CONSTANT32, OP_REGP, OP_VOID);
919 tmp = a & b;
920 SET_GPR32 (OP[1], tmp);
921 trace_output_32 (sd, tmp);
924 /* andd. */
925 void
926 OP_14B_14 (SIM_DESC sd, SIM_CPU *cpu)
928 uint32_t tmp, a = (GPR32 (OP[0])), b = (GPR32 (OP[1]));
929 trace_input ("andd", OP_REGP, OP_REGP, OP_VOID);
930 tmp = a & b;
931 SET_GPR32 (OP[1], tmp);
932 trace_output_32 (sd, tmp);
935 /* ord. */
936 void
937 OP_5_C (SIM_DESC sd, SIM_CPU *cpu)
939 uint32_t tmp, a = (OP[0]), b = GPR32 (OP[1]);
940 trace_input ("ord", OP_CONSTANT32, OP_REG, OP_VOID);
941 tmp = a | b;
942 SET_GPR32 (OP[1], tmp);
943 trace_output_32 (sd, tmp);
946 /* ord. */
947 void
948 OP_149_14 (SIM_DESC sd, SIM_CPU *cpu)
950 uint32_t tmp, a = GPR32 (OP[0]), b = GPR32 (OP[1]);
951 trace_input ("ord", OP_REGP, OP_REGP, OP_VOID);
952 tmp = a | b;
953 SET_GPR32 (OP[1], tmp);
954 trace_output_32 (sd, tmp);
957 /* xord. */
958 void
959 OP_6_C (SIM_DESC sd, SIM_CPU *cpu)
961 uint32_t tmp, a = (OP[0]), b = GPR32 (OP[1]);
962 trace_input ("xord", OP_CONSTANT32, OP_REG, OP_VOID);
963 tmp = a ^ b;
964 SET_GPR32 (OP[1], tmp);
965 trace_output_32 (sd, tmp);
968 /* xord. */
969 void
970 OP_14A_14 (SIM_DESC sd, SIM_CPU *cpu)
972 uint32_t tmp, a = GPR32 (OP[0]), b = GPR32 (OP[1]);
973 trace_input ("xord", OP_REGP, OP_REGP, OP_VOID);
974 tmp = a ^ b;
975 SET_GPR32 (OP[1], tmp);
976 trace_output_32 (sd, tmp);
980 /* b. */
981 void
982 OP_1_4 (SIM_DESC sd, SIM_CPU *cpu)
984 uint32_t tmp = 0, cc = cond_stat (OP[0]);
985 trace_input ("b", OP_CONSTANT4, OP_DISPE9, OP_VOID);
986 if (cc)
988 if (sign_flag)
989 tmp = (PC - (OP[1]));
990 else
991 tmp = (PC + (OP[1]));
992 /* If the resulting PC value is less than 0x00_0000 or greater
993 than 0xFF_FFFF, this instruction causes an IAD trap.*/
995 if ((tmp < 0x000000) || (tmp > 0xFFFFFF))
997 trace_output_void (sd);
998 EXCEPTION (SIM_SIGBUS);
1000 else
1001 JMP (tmp);
1003 sign_flag = 0; /* Reset sign_flag. */
1004 trace_output_32 (sd, tmp);
1007 /* b. */
1008 void
1009 OP_18_8 (SIM_DESC sd, SIM_CPU *cpu)
1011 uint32_t tmp = 0, cc = cond_stat (OP[0]);
1012 trace_input ("b", OP_CONSTANT4, OP_DISP17, OP_VOID);
1013 if (cc)
1015 if (sign_flag)
1016 tmp = (PC - OP[1]);
1017 else
1018 tmp = (PC + OP[1]);
1019 /* If the resulting PC value is less than 0x00_0000 or greater
1020 than 0xFF_FFFF, this instruction causes an IAD trap.*/
1022 if ((tmp < 0x000000) || (tmp > 0xFFFFFF))
1024 trace_output_void (sd);
1025 EXCEPTION (SIM_SIGBUS);
1027 else
1028 JMP (tmp);
1030 sign_flag = 0; /* Reset sign_flag. */
1031 trace_output_32 (sd, tmp);
1034 /* b. */
1035 void
1036 OP_10_10 (SIM_DESC sd, SIM_CPU *cpu)
1038 uint32_t tmp = 0, cc = cond_stat (OP[0]);
1039 trace_input ("b", OP_CONSTANT4, OP_DISP25, OP_VOID);
1040 if (cc)
1042 if (sign_flag)
1043 tmp = (PC - (OP[1]));
1044 else
1045 tmp = (PC + (OP[1]));
1046 /* If the resulting PC value is less than 0x00_0000 or greater
1047 than 0xFF_FFFF, this instruction causes an IAD trap.*/
1049 if ((tmp < 0x000000) || (tmp > 0xFFFFFF))
1051 trace_output_void (sd);
1052 EXCEPTION (SIM_SIGBUS);
1054 else
1055 JMP (tmp);
1057 sign_flag = 0; /* Reset sign_flag. */
1058 trace_output_32 (sd, tmp);
1061 /* bal. */
1062 void
1063 OP_C0_8 (SIM_DESC sd, SIM_CPU *cpu)
1065 uint32_t tmp;
1066 trace_input ("bal", OP_REG, OP_DISP17, OP_VOID);
1067 tmp = ((PC + 4) >> 1); /* Store PC in RA register. */
1068 SET_GPR32 (14, tmp);
1069 if (sign_flag)
1070 tmp = (PC - (OP[1]));
1071 else
1072 tmp = (PC + (OP[1]));
1074 /* If the resulting PC value is less than 0x00_0000 or greater
1075 than 0xFF_FFFF, this instruction causes an IAD trap. */
1077 if ((tmp < 0x000000) || (tmp > 0xFFFFFF))
1079 trace_output_void (sd);
1080 EXCEPTION (SIM_SIGBUS);
1082 else
1083 JMP (tmp);
1084 sign_flag = 0; /* Reset sign_flag. */
1085 trace_output_32 (sd, tmp);
1089 /* bal. */
1090 void
1091 OP_102_14 (SIM_DESC sd, SIM_CPU *cpu)
1093 uint32_t tmp;
1094 trace_input ("bal", OP_REGP, OP_DISP25, OP_VOID);
1095 tmp = (((PC) + 4) >> 1); /* Store PC in reg pair. */
1096 SET_GPR32 (OP[0], tmp);
1097 if (sign_flag)
1098 tmp = ((PC) - (OP[1]));
1099 else
1100 tmp = ((PC) + (OP[1]));
1101 /* If the resulting PC value is less than 0x00_0000 or greater
1102 than 0xFF_FFFF, this instruction causes an IAD trap.*/
1104 if ((tmp < 0x000000) || (tmp > 0xFFFFFF))
1106 trace_output_void (sd);
1107 EXCEPTION (SIM_SIGBUS);
1109 else
1110 JMP (tmp);
1111 sign_flag = 0; /* Reset sign_flag. */
1112 trace_output_32 (sd, tmp);
1115 /* jal. */
1116 void
1117 OP_148_14 (SIM_DESC sd, SIM_CPU *cpu)
1119 uint32_t tmp;
1120 trace_input ("jal", OP_REGP, OP_REGP, OP_VOID);
1121 SET_GPR32 (OP[0], (((PC) + 4) >> 1)); /* Store next PC in RA */
1122 tmp = GPR32 (OP[1]);
1123 tmp = SEXT24(tmp << 1);
1124 /* If the resulting PC value is less than 0x00_0000 or greater
1125 than 0xFF_FFFF, this instruction causes an IAD trap.*/
1127 if ((tmp < 0x0) || (tmp > 0xFFFFFF))
1129 trace_output_void (sd);
1130 EXCEPTION (SIM_SIGBUS);
1132 else
1133 JMP (tmp);
1135 trace_output_32 (sd, tmp);
1139 /* jal. */
1140 void
1141 OP_D_C (SIM_DESC sd, SIM_CPU *cpu)
1143 uint32_t tmp;
1144 trace_input ("jal", OP_REGP, OP_VOID, OP_VOID);
1145 SET_GPR32 (14, (((PC) + 2) >> 1)); /* Store next PC in RA */
1146 tmp = GPR32 (OP[0]);
1147 tmp = SEXT24(tmp << 1);
1148 /* If the resulting PC value is less than 0x00_0000 or greater
1149 than 0xFF_FFFF, this instruction causes an IAD trap.*/
1151 if ((tmp < 0x0) || (tmp > 0xFFFFFF))
1153 trace_output_void (sd);
1154 EXCEPTION (SIM_SIGBUS);
1156 else
1157 JMP (tmp);
1159 trace_output_32 (sd, tmp);
1163 /* beq0b. */
1164 void
1165 OP_C_8 (SIM_DESC sd, SIM_CPU *cpu)
1167 uint32_t addr;
1168 uint8_t a = (GPR (OP[0]) & 0xFF);
1169 trace_input ("beq0b", OP_REG, OP_DISP5, OP_VOID);
1170 addr = OP[1];
1171 if (a == 0)
1173 if (sign_flag)
1174 addr = (PC - OP[1]);
1175 else
1176 addr = (PC + OP[1]);
1178 JMP (addr);
1180 sign_flag = 0; /* Reset sign_flag. */
1181 trace_output_void (sd);
1184 /* bne0b. */
1185 void
1186 OP_D_8 (SIM_DESC sd, SIM_CPU *cpu)
1188 uint32_t addr;
1189 uint8_t a = (GPR (OP[0]) & 0xFF);
1190 trace_input ("bne0b", OP_REG, OP_DISP5, OP_VOID);
1191 addr = OP[1];
1192 if (a != 0)
1194 if (sign_flag)
1195 addr = (PC - OP[1]);
1196 else
1197 addr = (PC + OP[1]);
1199 JMP (addr);
1201 sign_flag = 0; /* Reset sign_flag. */
1202 trace_output_void (sd);
1205 /* beq0w. */
1206 void
1207 OP_E_8 (SIM_DESC sd, SIM_CPU *cpu)
1209 uint32_t addr;
1210 uint16_t a = GPR (OP[0]);
1211 trace_input ("beq0w", OP_REG, OP_DISP5, OP_VOID);
1212 addr = OP[1];
1213 if (a == 0)
1215 if (sign_flag)
1216 addr = (PC - OP[1]);
1217 else
1218 addr = (PC + OP[1]);
1220 JMP (addr);
1222 sign_flag = 0; /* Reset sign_flag. */
1223 trace_output_void (sd);
1226 /* bne0w. */
1227 void
1228 OP_F_8 (SIM_DESC sd, SIM_CPU *cpu)
1230 uint32_t addr;
1231 uint16_t a = GPR (OP[0]);
1232 trace_input ("bne0w", OP_REG, OP_DISP5, OP_VOID);
1233 addr = OP[1];
1234 if (a != 0)
1236 if (sign_flag)
1237 addr = (PC - OP[1]);
1238 else
1239 addr = (PC + OP[1]);
1241 JMP (addr);
1243 sign_flag = 0; /* Reset sign_flag. */
1244 trace_output_void (sd);
1248 /* jeq. */
1249 void
1250 OP_A0_C (SIM_DESC sd, SIM_CPU *cpu)
1252 uint32_t tmp = 0;
1253 trace_input ("jeq", OP_REGP, OP_VOID, OP_VOID);
1254 if ((PSR_Z) == 1)
1256 tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits. */
1257 JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit. */
1259 trace_output_32 (sd, tmp);
1262 /* jne. */
1263 void
1264 OP_A1_C (SIM_DESC sd, SIM_CPU *cpu)
1266 uint32_t tmp = 0;
1267 trace_input ("jne", OP_REGP, OP_VOID, OP_VOID);
1268 if ((PSR_Z) == 0)
1270 tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits. */
1271 JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit. */
1273 trace_output_32 (sd, tmp);
1276 /* jcs. */
1277 void
1278 OP_A2_C (SIM_DESC sd, SIM_CPU *cpu)
1280 uint32_t tmp = 0;
1281 trace_input ("jcs", OP_REGP, OP_VOID, OP_VOID);
1282 if ((PSR_C) == 1)
1284 tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
1285 JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
1287 trace_output_32 (sd, tmp);
1290 /* jcc. */
1291 void
1292 OP_A3_C (SIM_DESC sd, SIM_CPU *cpu)
1294 uint32_t tmp = 0;
1295 trace_input ("jcc", OP_REGP, OP_VOID, OP_VOID);
1296 if ((PSR_C) == 0)
1298 tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
1299 JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
1301 trace_output_32 (sd, tmp);
1304 /* jhi. */
1305 void
1306 OP_A4_C (SIM_DESC sd, SIM_CPU *cpu)
1308 uint32_t tmp = 0;
1309 trace_input ("jhi", OP_REGP, OP_VOID, OP_VOID);
1310 if ((PSR_L) == 1)
1312 tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
1313 JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
1315 trace_output_32 (sd, tmp);
1318 /* jls. */
1319 void
1320 OP_A5_C (SIM_DESC sd, SIM_CPU *cpu)
1322 uint32_t tmp = 0;
1323 trace_input ("jls", OP_REGP, OP_VOID, OP_VOID);
1324 if ((PSR_L) == 0)
1326 tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
1327 JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
1329 trace_output_32 (sd, tmp);
1332 /* jgt. */
1333 void
1334 OP_A6_C (SIM_DESC sd, SIM_CPU *cpu)
1336 uint32_t tmp = 0;
1337 trace_input ("jgt", OP_REGP, OP_VOID, OP_VOID);
1338 if ((PSR_N) == 1)
1340 tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
1341 JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
1343 trace_output_32 (sd, tmp);
1346 /* jle. */
1347 void
1348 OP_A7_C (SIM_DESC sd, SIM_CPU *cpu)
1350 uint32_t tmp = 0;
1351 trace_input ("jle", OP_REGP, OP_VOID, OP_VOID);
1352 if ((PSR_N) == 0)
1354 tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
1355 JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
1357 trace_output_32 (sd, tmp);
1361 /* jfs. */
1362 void
1363 OP_A8_C (SIM_DESC sd, SIM_CPU *cpu)
1365 uint32_t tmp = 0;
1366 trace_input ("jfs", OP_REGP, OP_VOID, OP_VOID);
1367 if ((PSR_F) == 1)
1369 tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
1370 JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
1372 trace_output_32 (sd, tmp);
1375 /* jfc. */
1376 void
1377 OP_A9_C (SIM_DESC sd, SIM_CPU *cpu)
1379 uint32_t tmp = 0;
1380 trace_input ("jfc", OP_REGP, OP_VOID, OP_VOID);
1381 if ((PSR_F) == 0)
1383 tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
1384 JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
1386 trace_output_32 (sd, tmp);
1389 /* jlo. */
1390 void
1391 OP_AA_C (SIM_DESC sd, SIM_CPU *cpu)
1393 uint32_t tmp = 0;
1394 trace_input ("jlo", OP_REGP, OP_VOID, OP_VOID);
1395 if (((PSR_Z) == 0) & ((PSR_L) == 0))
1397 tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
1398 JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
1400 trace_output_32 (sd, tmp);
1403 /* jhs. */
1404 void
1405 OP_AB_C (SIM_DESC sd, SIM_CPU *cpu)
1407 uint32_t tmp = 0;
1408 trace_input ("jhs", OP_REGP, OP_VOID, OP_VOID);
1409 if (((PSR_Z) == 1) | ((PSR_L) == 1))
1411 tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
1412 JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
1414 trace_output_32 (sd, tmp);
1417 /* jlt. */
1418 void
1419 OP_AC_C (SIM_DESC sd, SIM_CPU *cpu)
1421 uint32_t tmp = 0;
1422 trace_input ("jlt", OP_REGP, OP_VOID, OP_VOID);
1423 if (((PSR_Z) == 0) & ((PSR_N) == 0))
1425 tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
1426 JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
1428 trace_output_32 (sd, tmp);
1431 /* jge. */
1432 void
1433 OP_AD_C (SIM_DESC sd, SIM_CPU *cpu)
1435 uint32_t tmp = 0;
1436 trace_input ("jge", OP_REGP, OP_VOID, OP_VOID);
1437 if (((PSR_Z) == 1) | ((PSR_N) == 1))
1439 tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
1440 JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
1442 trace_output_32 (sd, tmp);
1445 /* jump. */
1446 void
1447 OP_AE_C (SIM_DESC sd, SIM_CPU *cpu)
1449 uint32_t tmp;
1450 trace_input ("jump", OP_REGP, OP_VOID, OP_VOID);
1451 tmp = GPR32 (OP[0]) /*& 0x3fffff*/; /* Use only 0 - 22 bits */
1452 JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
1453 trace_output_32 (sd, tmp);
1456 /* jusr. */
1457 void
1458 OP_AF_C (SIM_DESC sd, SIM_CPU *cpu)
1460 uint32_t tmp;
1461 trace_input ("jusr", OP_REGP, OP_VOID, OP_VOID);
1462 tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
1463 JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
1464 SET_PSR_U(1);
1465 trace_output_32 (sd, tmp);
1468 /* seq. */
1469 void
1470 OP_80_C (SIM_DESC sd, SIM_CPU *cpu)
1472 trace_input ("seq", OP_REG, OP_VOID, OP_VOID);
1473 if ((PSR_Z) == 1)
1474 SET_GPR (OP[0], 1);
1475 else
1476 SET_GPR (OP[0], 0);
1477 trace_output_void (sd);
1479 /* sne. */
1480 void
1481 OP_81_C (SIM_DESC sd, SIM_CPU *cpu)
1483 trace_input ("sne", OP_REG, OP_VOID, OP_VOID);
1484 if ((PSR_Z) == 0)
1485 SET_GPR (OP[0], 1);
1486 else
1487 SET_GPR (OP[0], 0);
1488 trace_output_void (sd);
1491 /* scs. */
1492 void
1493 OP_82_C (SIM_DESC sd, SIM_CPU *cpu)
1495 trace_input ("scs", OP_REG, OP_VOID, OP_VOID);
1496 if ((PSR_C) == 1)
1497 SET_GPR (OP[0], 1);
1498 else
1499 SET_GPR (OP[0], 0);
1500 trace_output_void (sd);
1503 /* scc. */
1504 void
1505 OP_83_C (SIM_DESC sd, SIM_CPU *cpu)
1507 trace_input ("scc", OP_REG, OP_VOID, OP_VOID);
1508 if ((PSR_C) == 0)
1509 SET_GPR (OP[0], 1);
1510 else
1511 SET_GPR (OP[0], 0);
1512 trace_output_void (sd);
1515 /* shi. */
1516 void
1517 OP_84_C (SIM_DESC sd, SIM_CPU *cpu)
1519 trace_input ("shi", OP_REG, OP_VOID, OP_VOID);
1520 if ((PSR_L) == 1)
1521 SET_GPR (OP[0], 1);
1522 else
1523 SET_GPR (OP[0], 0);
1524 trace_output_void (sd);
1527 /* sls. */
1528 void
1529 OP_85_C (SIM_DESC sd, SIM_CPU *cpu)
1531 trace_input ("sls", OP_REG, OP_VOID, OP_VOID);
1532 if ((PSR_L) == 0)
1533 SET_GPR (OP[0], 1);
1534 else
1535 SET_GPR (OP[0], 0);
1536 trace_output_void (sd);
1539 /* sgt. */
1540 void
1541 OP_86_C (SIM_DESC sd, SIM_CPU *cpu)
1543 trace_input ("sgt", OP_REG, OP_VOID, OP_VOID);
1544 if ((PSR_N) == 1)
1545 SET_GPR (OP[0], 1);
1546 else
1547 SET_GPR (OP[0], 0);
1548 trace_output_void (sd);
1551 /* sle. */
1552 void
1553 OP_87_C (SIM_DESC sd, SIM_CPU *cpu)
1555 trace_input ("sle", OP_REG, OP_VOID, OP_VOID);
1556 if ((PSR_N) == 0)
1557 SET_GPR (OP[0], 1);
1558 else
1559 SET_GPR (OP[0], 0);
1560 trace_output_void (sd);
1563 /* sfs. */
1564 void
1565 OP_88_C (SIM_DESC sd, SIM_CPU *cpu)
1567 trace_input ("sfs", OP_REG, OP_VOID, OP_VOID);
1568 if ((PSR_F) == 1)
1569 SET_GPR (OP[0], 1);
1570 else
1571 SET_GPR (OP[0], 0);
1572 trace_output_void (sd);
1575 /* sfc. */
1576 void
1577 OP_89_C (SIM_DESC sd, SIM_CPU *cpu)
1579 trace_input ("sfc", OP_REG, OP_VOID, OP_VOID);
1580 if ((PSR_F) == 0)
1581 SET_GPR (OP[0], 1);
1582 else
1583 SET_GPR (OP[0], 0);
1584 trace_output_void (sd);
1588 /* slo. */
1589 void
1590 OP_8A_C (SIM_DESC sd, SIM_CPU *cpu)
1592 trace_input ("slo", OP_REG, OP_VOID, OP_VOID);
1593 if (((PSR_Z) == 0) & ((PSR_L) == 0))
1594 SET_GPR (OP[0], 1);
1595 else
1596 SET_GPR (OP[0], 0);
1597 trace_output_void (sd);
1600 /* shs. */
1601 void
1602 OP_8B_C (SIM_DESC sd, SIM_CPU *cpu)
1604 trace_input ("shs", OP_REG, OP_VOID, OP_VOID);
1605 if ( ((PSR_Z) == 1) | ((PSR_L) == 1))
1606 SET_GPR (OP[0], 1);
1607 else
1608 SET_GPR (OP[0], 0);
1609 trace_output_void (sd);
1612 /* slt. */
1613 void
1614 OP_8C_C (SIM_DESC sd, SIM_CPU *cpu)
1616 trace_input ("slt", OP_REG, OP_VOID, OP_VOID);
1617 if (((PSR_Z) == 0) & ((PSR_N) == 0))
1618 SET_GPR (OP[0], 1);
1619 else
1620 SET_GPR (OP[0], 0);
1621 trace_output_void (sd);
1624 /* sge. */
1625 void
1626 OP_8D_C (SIM_DESC sd, SIM_CPU *cpu)
1628 trace_input ("sge", OP_REG, OP_VOID, OP_VOID);
1629 if (((PSR_Z) == 1) | ((PSR_N) == 1))
1630 SET_GPR (OP[0], 1);
1631 else
1632 SET_GPR (OP[0], 0);
1633 trace_output_void (sd);
1636 /* cbitb. */
1637 void
1638 OP_D7_9 (SIM_DESC sd, SIM_CPU *cpu)
1640 uint8_t a = OP[0] & 0xff;
1641 uint32_t addr = OP[1], tmp;
1642 trace_input ("cbitb", OP_CONSTANT4, OP_ABS20_OUTPUT, OP_VOID);
1643 tmp = RB (addr);
1644 SET_PSR_F (tmp & (1 << a));
1645 tmp = tmp & ~(1 << a);
1646 SB (addr, tmp);
1647 trace_output_32 (sd, tmp);
1650 /* cbitb. */
1651 void
1652 OP_107_14 (SIM_DESC sd, SIM_CPU *cpu)
1654 uint8_t a = OP[0] & 0xff;
1655 uint32_t addr = OP[1], tmp;
1656 trace_input ("cbitb", OP_CONSTANT4, OP_ABS24_OUTPUT, OP_VOID);
1657 tmp = RB (addr);
1658 SET_PSR_F (tmp & (1 << a));
1659 tmp = tmp & ~(1 << a);
1660 SB (addr, tmp);
1661 trace_output_32 (sd, tmp);
1664 /* cbitb. */
1665 void
1666 OP_68_8 (SIM_DESC sd, SIM_CPU *cpu)
1668 uint8_t a = (OP[0]) & 0xff;
1669 uint32_t addr = (GPR (OP[2])) + OP[1], tmp;
1670 trace_input ("cbitb", OP_CONSTANT4, OP_R_INDEX7_ABS20, OP_VOID);
1671 tmp = RB (addr);
1672 SET_PSR_F (tmp & (1 << a));
1673 tmp = tmp & ~(1 << a);
1674 SB (addr, tmp);
1675 trace_output_32 (sd, addr);
1678 /* cbitb. */
1679 void
1680 OP_1AA_A (SIM_DESC sd, SIM_CPU *cpu)
1682 uint8_t a = (OP[0]) & 0xff;
1683 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
1684 trace_input ("cbitb", OP_CONSTANT4, OP_RP_INDEX_DISP14, OP_VOID);
1685 tmp = RB (addr);
1686 SET_PSR_F (tmp & (1 << a));
1687 tmp = tmp & ~(1 << a);
1688 SB (addr, tmp);
1689 trace_output_32 (sd, addr);
1692 /* cbitb. */
1693 void
1694 OP_104_14 (SIM_DESC sd, SIM_CPU *cpu)
1696 uint8_t a = (OP[0]) & 0xff;
1697 uint32_t addr = (GPR (OP[2])) + OP[1], tmp;
1698 trace_input ("cbitb", OP_CONSTANT4, OP_R_BASE_DISPS20, OP_VOID);
1699 tmp = RB (addr);
1700 SET_PSR_F (tmp & (1 << a));
1701 tmp = tmp & ~(1 << a);
1702 SB (addr, tmp);
1703 trace_output_32 (sd, addr);
1706 /* cbitb. */
1707 void
1708 OP_D4_9 (SIM_DESC sd, SIM_CPU *cpu)
1710 uint8_t a = (OP[0]) & 0xff;
1711 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
1712 trace_input ("cbitb", OP_CONSTANT4, OP_RP_INDEX_DISP0, OP_VOID);
1713 tmp = RB (addr);
1714 SET_PSR_F (tmp & (1 << a));
1715 tmp = tmp & ~(1 << a);
1716 SB (addr, tmp);
1717 trace_output_32 (sd, addr);
1720 /* cbitb. */
1721 void
1722 OP_D6_9 (SIM_DESC sd, SIM_CPU *cpu)
1724 uint8_t a = (OP[0]) & 0xff;
1725 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
1726 trace_input ("cbitb", OP_CONSTANT4, OP_RP_BASE_DISP16, OP_VOID);
1727 tmp = RB (addr);
1728 SET_PSR_F (tmp & (1 << a));
1729 tmp = tmp & ~(1 << a);
1730 SB (addr, tmp);
1731 trace_output_32 (sd, addr);
1735 /* cbitb. */
1736 void
1737 OP_105_14 (SIM_DESC sd, SIM_CPU *cpu)
1739 uint8_t a = (OP[0]) & 0xff;
1740 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
1741 trace_input ("cbitb", OP_CONSTANT4, OP_RP_BASE_DISPS20, OP_VOID);
1742 tmp = RB (addr);
1743 SET_PSR_F (tmp & (1 << a));
1744 tmp = tmp & ~(1 << a);
1745 SB (addr, tmp);
1746 trace_output_32 (sd, addr);
1749 /* cbitb. */
1750 void
1751 OP_106_14 (SIM_DESC sd, SIM_CPU *cpu)
1753 uint8_t a = (OP[0]) & 0xff;
1754 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
1755 trace_input ("cbitb", OP_CONSTANT4, OP_RP_INDEX_DISPS20, OP_VOID);
1756 tmp = RB (addr);
1757 SET_PSR_F (tmp & (1 << a));
1758 tmp = tmp & ~(1 << a);
1759 SB (addr, tmp);
1760 trace_output_32 (sd, addr);
1764 /* cbitw. */
1765 void
1766 OP_6F_8 (SIM_DESC sd, SIM_CPU *cpu)
1768 uint16_t a = OP[0];
1769 uint32_t addr = OP[1], tmp;
1770 trace_input ("cbitw", OP_CONSTANT4, OP_ABS20_OUTPUT, OP_VOID);
1771 tmp = RW (addr);
1772 SET_PSR_F (tmp & (1 << a));
1773 tmp = tmp & ~(1 << a);
1774 SW (addr, tmp);
1775 trace_output_32 (sd, tmp);
1778 /* cbitw. */
1779 void
1780 OP_117_14 (SIM_DESC sd, SIM_CPU *cpu)
1782 uint16_t a = OP[0];
1783 uint32_t addr = OP[1], tmp;
1784 trace_input ("cbitw", OP_CONSTANT4, OP_ABS24_OUTPUT, OP_VOID);
1785 tmp = RW (addr);
1786 SET_PSR_F (tmp & (1 << a));
1787 tmp = tmp & ~(1 << a);
1788 SW (addr, tmp);
1789 trace_output_32 (sd, tmp);
1792 /* cbitw. */
1793 void
1794 OP_36_7 (SIM_DESC sd, SIM_CPU *cpu)
1796 uint32_t addr;
1797 uint16_t a = (OP[0]), tmp;
1798 trace_input ("cbitw", OP_CONSTANT4, OP_R_INDEX8_ABS20, OP_VOID);
1800 if (OP[1] == 0)
1801 addr = (GPR32 (12)) + OP[2];
1802 else
1803 addr = (GPR32 (13)) + OP[2];
1805 tmp = RW (addr);
1806 SET_PSR_F (tmp & (1 << a));
1807 tmp = tmp & ~(1 << a);
1808 SW (addr, tmp);
1809 trace_output_32 (sd, addr);
1813 /* cbitw. */
1814 void
1815 OP_1AB_A (SIM_DESC sd, SIM_CPU *cpu)
1817 uint16_t a = (OP[0]);
1818 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
1819 trace_input ("cbitw", OP_CONSTANT4, OP_RP_INDEX_DISP14, OP_VOID);
1820 tmp = RW (addr);
1821 SET_PSR_F (tmp & (1 << a));
1822 tmp = tmp & ~(1 << a);
1823 SW (addr, tmp);
1824 trace_output_32 (sd, addr);
1827 /* cbitw. */
1828 void
1829 OP_114_14 (SIM_DESC sd, SIM_CPU *cpu)
1831 uint16_t a = (OP[0]);
1832 uint32_t addr = (GPR (OP[2])) + OP[1], tmp;
1833 trace_input ("cbitw", OP_CONSTANT4, OP_R_BASE_DISPS20, OP_VOID);
1834 tmp = RW (addr);
1835 SET_PSR_F (tmp & (1 << a));
1836 tmp = tmp & ~(1 << a);
1837 SW (addr, tmp);
1838 trace_output_32 (sd, addr);
1842 /* cbitw. */
1843 void
1844 OP_6E_8 (SIM_DESC sd, SIM_CPU *cpu)
1846 uint16_t a = (OP[0]);
1847 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
1848 trace_input ("cbitw", OP_CONSTANT4, OP_RP_INDEX_DISP0, OP_VOID);
1849 tmp = RW (addr);
1850 SET_PSR_F (tmp & (1 << a));
1851 tmp = tmp & ~(1 << a);
1852 SW (addr, tmp);
1853 trace_output_32 (sd, addr);
1856 /* cbitw. */
1857 void
1858 OP_69_8 (SIM_DESC sd, SIM_CPU *cpu)
1860 uint16_t a = (OP[0]);
1861 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
1862 trace_input ("cbitw", OP_CONSTANT4, OP_RP_BASE_DISP16, OP_VOID);
1863 tmp = RW (addr);
1864 SET_PSR_F (tmp & (1 << a));
1865 tmp = tmp & ~(1 << a);
1866 SW (addr, tmp);
1867 trace_output_32 (sd, addr);
1871 /* cbitw. */
1872 void
1873 OP_115_14 (SIM_DESC sd, SIM_CPU *cpu)
1875 uint16_t a = (OP[0]);
1876 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
1877 trace_input ("cbitw", OP_CONSTANT4, OP_RP_BASE_DISPS20, OP_VOID);
1878 tmp = RW (addr);
1879 SET_PSR_F (tmp & (1 << a));
1880 tmp = tmp & ~(1 << a);
1881 SW (addr, tmp);
1882 trace_output_32 (sd, addr);
1885 /* cbitw. */
1886 void
1887 OP_116_14 (SIM_DESC sd, SIM_CPU *cpu)
1889 uint16_t a = (OP[0]);
1890 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
1891 trace_input ("cbitw", OP_CONSTANT4, OP_RP_INDEX_DISPS20, OP_VOID);
1892 tmp = RW (addr);
1893 SET_PSR_F (tmp & (1 << a));
1894 tmp = tmp & ~(1 << a);
1895 SW (addr, tmp);
1896 trace_output_32 (sd, addr);
1899 /* sbitb. */
1900 void
1901 OP_E7_9 (SIM_DESC sd, SIM_CPU *cpu)
1903 uint8_t a = OP[0] & 0xff;
1904 uint32_t addr = OP[1], tmp;
1905 trace_input ("sbitb", OP_CONSTANT4, OP_ABS20_OUTPUT, OP_VOID);
1906 tmp = RB (addr);
1907 SET_PSR_F (tmp & (1 << a));
1908 tmp = tmp | (1 << a);
1909 SB (addr, tmp);
1910 trace_output_32 (sd, tmp);
1913 /* sbitb. */
1914 void
1915 OP_10B_14 (SIM_DESC sd, SIM_CPU *cpu)
1917 uint8_t a = OP[0] & 0xff;
1918 uint32_t addr = OP[1], tmp;
1919 trace_input ("sbitb", OP_CONSTANT4, OP_ABS24_OUTPUT, OP_VOID);
1920 tmp = RB (addr);
1921 SET_PSR_F (tmp & (1 << a));
1922 tmp = tmp | (1 << a);
1923 SB (addr, tmp);
1924 trace_output_32 (sd, tmp);
1927 /* sbitb. */
1928 void
1929 OP_70_8 (SIM_DESC sd, SIM_CPU *cpu)
1931 uint8_t a = OP[0] & 0xff;
1932 uint32_t addr = (GPR (OP[2])) + OP[1], tmp;
1933 trace_input ("sbitb", OP_CONSTANT4, OP_R_INDEX7_ABS20, OP_VOID);
1934 tmp = RB (addr);
1935 SET_PSR_F (tmp & (1 << a));
1936 tmp = tmp | (1 << a);
1937 SB (addr, tmp);
1938 trace_output_32 (sd, tmp);
1941 /* sbitb. */
1942 void
1943 OP_1CA_A (SIM_DESC sd, SIM_CPU *cpu)
1945 uint8_t a = OP[0] & 0xff;
1946 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
1947 trace_input ("sbitb", OP_CONSTANT4, OP_RP_INDEX_DISP14, OP_VOID);
1948 tmp = RB (addr);
1949 SET_PSR_F (tmp & (1 << a));
1950 tmp = tmp | (1 << a);
1951 SB (addr, tmp);
1952 trace_output_32 (sd, tmp);
1955 /* sbitb. */
1956 void
1957 OP_108_14 (SIM_DESC sd, SIM_CPU *cpu)
1959 uint8_t a = OP[0] & 0xff;
1960 uint32_t addr = (GPR (OP[2])) + OP[1], tmp;
1961 trace_input ("sbitb", OP_CONSTANT4, OP_R_BASE_DISPS20, OP_VOID);
1962 tmp = RB (addr);
1963 SET_PSR_F (tmp & (1 << a));
1964 tmp = tmp | (1 << a);
1965 SB (addr, tmp);
1966 trace_output_32 (sd, tmp);
1970 /* sbitb. */
1971 void
1972 OP_E4_9 (SIM_DESC sd, SIM_CPU *cpu)
1974 uint8_t a = OP[0] & 0xff;
1975 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
1976 trace_input ("sbitb", OP_CONSTANT4, OP_RP_INDEX_DISP0, OP_VOID);
1977 tmp = RB (addr);
1978 SET_PSR_F (tmp & (1 << a));
1979 tmp = tmp | (1 << a);
1980 SB (addr, tmp);
1981 trace_output_32 (sd, tmp);
1984 /* sbitb. */
1985 void
1986 OP_E6_9 (SIM_DESC sd, SIM_CPU *cpu)
1988 uint8_t a = OP[0] & 0xff;
1989 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
1990 trace_input ("sbitb", OP_CONSTANT4, OP_RP_BASE_DISP16, OP_VOID);
1991 tmp = RB (addr);
1992 SET_PSR_F (tmp & (1 << a));
1993 tmp = tmp | (1 << a);
1994 SB (addr, tmp);
1995 trace_output_32 (sd, tmp);
1999 /* sbitb. */
2000 void
2001 OP_109_14 (SIM_DESC sd, SIM_CPU *cpu)
2003 uint8_t a = OP[0] & 0xff;
2004 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
2005 trace_input ("sbitb", OP_CONSTANT4, OP_RP_BASE_DISPS20, OP_VOID);
2006 tmp = RB (addr);
2007 SET_PSR_F (tmp & (1 << a));
2008 tmp = tmp | (1 << a);
2009 SB (addr, tmp);
2010 trace_output_32 (sd, tmp);
2014 /* sbitb. */
2015 void
2016 OP_10A_14 (SIM_DESC sd, SIM_CPU *cpu)
2018 uint8_t a = OP[0] & 0xff;
2019 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
2020 trace_input ("sbitb", OP_CONSTANT4, OP_RP_INDEX_DISPS20, OP_VOID);
2021 tmp = RB (addr);
2022 SET_PSR_F (tmp & (1 << a));
2023 tmp = tmp | (1 << a);
2024 SB (addr, tmp);
2025 trace_output_32 (sd, tmp);
2029 /* sbitw. */
2030 void
2031 OP_77_8 (SIM_DESC sd, SIM_CPU *cpu)
2033 uint16_t a = OP[0];
2034 uint32_t addr = OP[1], tmp;
2035 trace_input ("sbitw", OP_CONSTANT4, OP_ABS20_OUTPUT, OP_VOID);
2036 tmp = RW (addr);
2037 SET_PSR_F (tmp & (1 << a));
2038 tmp = tmp | (1 << a);
2039 SW (addr, tmp);
2040 trace_output_32 (sd, tmp);
2043 /* sbitw. */
2044 void
2045 OP_11B_14 (SIM_DESC sd, SIM_CPU *cpu)
2047 uint16_t a = OP[0];
2048 uint32_t addr = OP[1], tmp;
2049 trace_input ("sbitw", OP_CONSTANT4, OP_ABS24_OUTPUT, OP_VOID);
2050 tmp = RW (addr);
2051 SET_PSR_F (tmp & (1 << a));
2052 tmp = tmp | (1 << a);
2053 SW (addr, tmp);
2054 trace_output_32 (sd, tmp);
2057 /* sbitw. */
2058 void
2059 OP_3A_7 (SIM_DESC sd, SIM_CPU *cpu)
2061 uint32_t addr;
2062 uint16_t a = (OP[0]), tmp;
2063 trace_input ("sbitw", OP_CONSTANT4, OP_R_INDEX8_ABS20, OP_VOID);
2065 if (OP[1] == 0)
2066 addr = (GPR32 (12)) + OP[2];
2067 else
2068 addr = (GPR32 (13)) + OP[2];
2070 tmp = RW (addr);
2071 SET_PSR_F (tmp & (1 << a));
2072 tmp = tmp | (1 << a);
2073 SW (addr, tmp);
2074 trace_output_32 (sd, addr);
2077 /* sbitw. */
2078 void
2079 OP_1CB_A (SIM_DESC sd, SIM_CPU *cpu)
2081 uint16_t a = (OP[0]);
2082 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
2083 trace_input ("sbitw", OP_CONSTANT4, OP_RP_INDEX_DISP14, OP_VOID);
2084 tmp = RW (addr);
2085 SET_PSR_F (tmp & (1 << a));
2086 tmp = tmp | (1 << a);
2087 SW (addr, tmp);
2088 trace_output_32 (sd, addr);
2091 /* sbitw. */
2092 void
2093 OP_118_14 (SIM_DESC sd, SIM_CPU *cpu)
2095 uint16_t a = (OP[0]);
2096 uint32_t addr = (GPR (OP[2])) + OP[1], tmp;
2097 trace_input ("sbitw", OP_CONSTANT4, OP_R_BASE_DISPS20, OP_VOID);
2098 tmp = RW (addr);
2099 SET_PSR_F (tmp & (1 << a));
2100 tmp = tmp | (1 << a);
2101 SW (addr, tmp);
2102 trace_output_32 (sd, addr);
2105 /* sbitw. */
2106 void
2107 OP_76_8 (SIM_DESC sd, SIM_CPU *cpu)
2109 uint16_t a = (OP[0]);
2110 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
2111 trace_input ("sbitw", OP_CONSTANT4, OP_RP_INDEX_DISP0, OP_VOID);
2112 tmp = RW (addr);
2113 SET_PSR_F (tmp & (1 << a));
2114 tmp = tmp | (1 << a);
2115 SW (addr, tmp);
2116 trace_output_32 (sd, addr);
2119 /* sbitw. */
2120 void
2121 OP_71_8 (SIM_DESC sd, SIM_CPU *cpu)
2123 uint16_t a = (OP[0]);
2124 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
2125 trace_input ("sbitw", OP_CONSTANT4, OP_RP_BASE_DISP16, OP_VOID);
2126 tmp = RW (addr);
2127 SET_PSR_F (tmp & (1 << a));
2128 tmp = tmp | (1 << a);
2129 SW (addr, tmp);
2130 trace_output_32 (sd, addr);
2133 /* sbitw. */
2134 void
2135 OP_119_14 (SIM_DESC sd, SIM_CPU *cpu)
2137 uint16_t a = (OP[0]);
2138 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
2139 trace_input ("sbitw", OP_CONSTANT4, OP_RP_BASE_DISPS20, OP_VOID);
2140 tmp = RW (addr);
2141 SET_PSR_F (tmp & (1 << a));
2142 tmp = tmp | (1 << a);
2143 SW (addr, tmp);
2144 trace_output_32 (sd, addr);
2147 /* sbitw. */
2148 void
2149 OP_11A_14 (SIM_DESC sd, SIM_CPU *cpu)
2151 uint16_t a = (OP[0]);
2152 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
2153 trace_input ("sbitw", OP_CONSTANT4, OP_RP_INDEX_DISPS20, OP_VOID);
2154 tmp = RW (addr);
2155 SET_PSR_F (tmp & (1 << a));
2156 tmp = tmp | (1 << a);
2157 SW (addr, tmp);
2158 trace_output_32 (sd, addr);
2162 /* tbitb. */
2163 void
2164 OP_F7_9 (SIM_DESC sd, SIM_CPU *cpu)
2166 uint8_t a = OP[0] & 0xff;
2167 uint32_t addr = OP[1], tmp;
2168 trace_input ("tbitb", OP_CONSTANT4, OP_ABS20_OUTPUT, OP_VOID);
2169 tmp = RB (addr);
2170 SET_PSR_F (tmp & (1 << a));
2171 trace_output_32 (sd, tmp);
2174 /* tbitb. */
2175 void
2176 OP_10F_14 (SIM_DESC sd, SIM_CPU *cpu)
2178 uint8_t a = OP[0] & 0xff;
2179 uint32_t addr = OP[1], tmp;
2180 trace_input ("tbitb", OP_CONSTANT4, OP_ABS24_OUTPUT, OP_VOID);
2181 tmp = RB (addr);
2182 SET_PSR_F (tmp & (1 << a));
2183 trace_output_32 (sd, tmp);
2186 /* tbitb. */
2187 void
2188 OP_78_8 (SIM_DESC sd, SIM_CPU *cpu)
2190 uint8_t a = (OP[0]) & 0xff;
2191 uint32_t addr = (GPR (OP[2])) + OP[1], tmp;
2192 trace_input ("tbitb", OP_CONSTANT4, OP_R_INDEX7_ABS20, OP_VOID);
2193 tmp = RB (addr);
2194 SET_PSR_F (tmp & (1 << a));
2195 trace_output_32 (sd, addr);
2198 /* tbitb. */
2199 void
2200 OP_1EA_A (SIM_DESC sd, SIM_CPU *cpu)
2202 uint8_t a = (OP[0]) & 0xff;
2203 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
2204 trace_input ("tbitb", OP_CONSTANT4, OP_RP_INDEX_DISP14, OP_VOID);
2205 tmp = RB (addr);
2206 SET_PSR_F (tmp & (1 << a));
2207 trace_output_32 (sd, addr);
2210 /* tbitb. */
2211 void
2212 OP_10C_14 (SIM_DESC sd, SIM_CPU *cpu)
2214 uint8_t a = (OP[0]) & 0xff;
2215 uint32_t addr = (GPR (OP[2])) + OP[1], tmp;
2216 trace_input ("tbitb", OP_CONSTANT4, OP_R_BASE_DISPS20, OP_VOID);
2217 tmp = RB (addr);
2218 SET_PSR_F (tmp & (1 << a));
2219 trace_output_32 (sd, addr);
2222 /* tbitb. */
2223 void
2224 OP_F4_9 (SIM_DESC sd, SIM_CPU *cpu)
2226 uint8_t a = (OP[0]) & 0xff;
2227 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
2228 trace_input ("tbitb", OP_CONSTANT4, OP_RP_INDEX_DISP0, OP_VOID);
2229 tmp = RB (addr);
2230 SET_PSR_F (tmp & (1 << a));
2231 trace_output_32 (sd, addr);
2234 /* tbitb. */
2235 void
2236 OP_F6_9 (SIM_DESC sd, SIM_CPU *cpu)
2238 uint8_t a = (OP[0]) & 0xff;
2239 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
2240 trace_input ("tbitb", OP_CONSTANT4, OP_RP_BASE_DISP16, OP_VOID);
2241 tmp = RB (addr);
2242 SET_PSR_F (tmp & (1 << a));
2243 trace_output_32 (sd, addr);
2246 /* tbitb. */
2247 void
2248 OP_10D_14 (SIM_DESC sd, SIM_CPU *cpu)
2250 uint8_t a = (OP[0]) & 0xff;
2251 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
2252 trace_input ("tbitb", OP_CONSTANT4, OP_RP_BASE_DISPS20, OP_VOID);
2253 tmp = RB (addr);
2254 SET_PSR_F (tmp & (1 << a));
2255 trace_output_32 (sd, addr);
2258 /* tbitb. */
2259 void
2260 OP_10E_14 (SIM_DESC sd, SIM_CPU *cpu)
2262 uint8_t a = (OP[0]) & 0xff;
2263 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
2264 trace_input ("tbitb", OP_CONSTANT4, OP_RP_INDEX_DISPS20, OP_VOID);
2265 tmp = RB (addr);
2266 SET_PSR_F (tmp & (1 << a));
2267 trace_output_32 (sd, addr);
2271 /* tbitw. */
2272 void
2273 OP_7F_8 (SIM_DESC sd, SIM_CPU *cpu)
2275 uint16_t a = OP[0];
2276 uint32_t addr = OP[1], tmp;
2277 trace_input ("tbitw", OP_CONSTANT4, OP_ABS20_OUTPUT, OP_VOID);
2278 tmp = RW (addr);
2279 SET_PSR_F (tmp & (1 << a));
2280 trace_output_32 (sd, tmp);
2283 /* tbitw. */
2284 void
2285 OP_11F_14 (SIM_DESC sd, SIM_CPU *cpu)
2287 uint16_t a = OP[0];
2288 uint32_t addr = OP[1], tmp;
2289 trace_input ("tbitw", OP_CONSTANT4, OP_ABS24_OUTPUT, OP_VOID);
2290 tmp = RW (addr);
2291 SET_PSR_F (tmp & (1 << a));
2292 trace_output_32 (sd, tmp);
2296 /* tbitw. */
2297 void
2298 OP_3E_7 (SIM_DESC sd, SIM_CPU *cpu)
2300 uint32_t addr;
2301 uint16_t a = (OP[0]), tmp;
2302 trace_input ("tbitw", OP_CONSTANT4, OP_R_INDEX8_ABS20, OP_VOID);
2304 if (OP[1] == 0)
2305 addr = (GPR32 (12)) + OP[2];
2306 else
2307 addr = (GPR32 (13)) + OP[2];
2309 tmp = RW (addr);
2310 SET_PSR_F (tmp & (1 << a));
2311 trace_output_32 (sd, addr);
2314 /* tbitw. */
2315 void
2316 OP_1EB_A (SIM_DESC sd, SIM_CPU *cpu)
2318 uint16_t a = (OP[0]);
2319 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
2320 trace_input ("tbitw", OP_CONSTANT4, OP_RP_INDEX_DISP14, OP_VOID);
2321 tmp = RW (addr);
2322 SET_PSR_F (tmp & (1 << a));
2323 trace_output_32 (sd, addr);
2326 /* tbitw. */
2327 void
2328 OP_11C_14 (SIM_DESC sd, SIM_CPU *cpu)
2330 uint16_t a = (OP[0]);
2331 uint32_t addr = (GPR (OP[2])) + OP[1], tmp;
2332 trace_input ("tbitw", OP_CONSTANT4, OP_R_BASE_DISPS20, OP_VOID);
2333 tmp = RW (addr);
2334 SET_PSR_F (tmp & (1 << a));
2335 trace_output_32 (sd, addr);
2338 /* tbitw. */
2339 void
2340 OP_7E_8 (SIM_DESC sd, SIM_CPU *cpu)
2342 uint16_t a = (OP[0]);
2343 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
2344 trace_input ("tbitw", OP_CONSTANT4, OP_RP_INDEX_DISP0, OP_VOID);
2345 tmp = RW (addr);
2346 SET_PSR_F (tmp & (1 << a));
2347 trace_output_32 (sd, addr);
2350 /* tbitw. */
2351 void
2352 OP_79_8 (SIM_DESC sd, SIM_CPU *cpu)
2354 uint16_t a = (OP[0]);
2355 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
2356 trace_input ("tbitw", OP_CONSTANT4, OP_RP_BASE_DISP16, OP_VOID);
2357 tmp = RW (addr);
2358 SET_PSR_F (tmp & (1 << a));
2359 trace_output_32 (sd, addr);
2362 /* tbitw. */
2363 void
2364 OP_11D_14 (SIM_DESC sd, SIM_CPU *cpu)
2366 uint16_t a = (OP[0]);
2367 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
2368 trace_input ("tbitw", OP_CONSTANT4, OP_RP_BASE_DISPS20, OP_VOID);
2369 tmp = RW (addr);
2370 SET_PSR_F (tmp & (1 << a));
2371 trace_output_32 (sd, addr);
2375 /* tbitw. */
2376 void
2377 OP_11E_14 (SIM_DESC sd, SIM_CPU *cpu)
2379 uint16_t a = (OP[0]);
2380 uint32_t addr = (GPR32 (OP[2])) + OP[1], tmp;
2381 trace_input ("tbitw", OP_CONSTANT4, OP_RP_INDEX_DISPS20, OP_VOID);
2382 tmp = RW (addr);
2383 SET_PSR_F (tmp & (1 << a));
2384 trace_output_32 (sd, addr);
2388 /* tbit. */
2389 void
2390 OP_6_8 (SIM_DESC sd, SIM_CPU *cpu)
2392 uint16_t a = OP[0];
2393 uint16_t b = (GPR (OP[1]));
2394 trace_input ("tbit", OP_CONSTANT4, OP_REG, OP_VOID);
2395 SET_PSR_F (b & (1 << a));
2396 trace_output_16 (sd, b);
2399 /* tbit. */
2400 void
2401 OP_7_8 (SIM_DESC sd, SIM_CPU *cpu)
2403 uint16_t a = GPR (OP[0]);
2404 uint16_t b = (GPR (OP[1]));
2405 trace_input ("tbit", OP_REG, OP_REG, OP_VOID);
2406 SET_PSR_F (b & (1 << a));
2407 trace_output_16 (sd, b);
2411 /* cmpb. */
2412 void
2413 OP_50_8 (SIM_DESC sd, SIM_CPU *cpu)
2415 uint8_t a = (OP[0]) & 0xFF;
2416 uint8_t b = (GPR (OP[1])) & 0xFF;
2417 trace_input ("cmpb", OP_CONSTANT4, OP_REG, OP_VOID);
2418 SET_PSR_Z (a == b);
2419 SET_PSR_N ((int8_t)a > (int8_t)b);
2420 SET_PSR_L (a > b);
2421 trace_output_flag (sd);
2424 /* cmpb. */
2425 void
2426 OP_50B_C (SIM_DESC sd, SIM_CPU *cpu)
2428 uint8_t a = (OP[0]) & 0xFF;
2429 uint8_t b = (GPR (OP[1])) & 0xFF;
2430 trace_input ("cmpb", OP_CONSTANT16, OP_REG, OP_VOID);
2431 SET_PSR_Z (a == b);
2432 SET_PSR_N ((int8_t)a > (int8_t)b);
2433 SET_PSR_L (a > b);
2434 trace_output_flag (sd);
2437 /* cmpb. */
2438 void
2439 OP_51_8 (SIM_DESC sd, SIM_CPU *cpu)
2441 uint8_t a = (GPR (OP[0])) & 0xFF;
2442 uint8_t b = (GPR (OP[1])) & 0xFF;
2443 trace_input ("cmpb", OP_REG, OP_REG, OP_VOID);
2444 SET_PSR_Z (a == b);
2445 SET_PSR_N ((int8_t)a > (int8_t)b);
2446 SET_PSR_L (a > b);
2447 trace_output_flag (sd);
2450 /* cmpw. */
2451 void
2452 OP_52_8 (SIM_DESC sd, SIM_CPU *cpu)
2454 uint16_t a = (OP[0]);
2455 uint16_t b = GPR (OP[1]);
2456 trace_input ("cmpw", OP_CONSTANT4, OP_REG, OP_VOID);
2457 SET_PSR_Z (a == b);
2458 SET_PSR_N ((int16_t)a > (int16_t)b);
2459 SET_PSR_L (a > b);
2460 trace_output_flag (sd);
2463 /* cmpw. */
2464 void
2465 OP_52B_C (SIM_DESC sd, SIM_CPU *cpu)
2467 uint16_t a = (OP[0]);
2468 uint16_t b = GPR (OP[1]);
2469 trace_input ("cmpw", OP_CONSTANT16, OP_REG, OP_VOID);
2470 SET_PSR_Z (a == b);
2471 SET_PSR_N ((int16_t)a > (int16_t)b);
2472 SET_PSR_L (a > b);
2473 trace_output_flag (sd);
2476 /* cmpw. */
2477 void
2478 OP_53_8 (SIM_DESC sd, SIM_CPU *cpu)
2480 uint16_t a = GPR (OP[0]) ;
2481 uint16_t b = GPR (OP[1]) ;
2482 trace_input ("cmpw", OP_REG, OP_REG, OP_VOID);
2483 SET_PSR_Z (a == b);
2484 SET_PSR_N ((int16_t)a > (int16_t)b);
2485 SET_PSR_L (a > b);
2486 trace_output_flag (sd);
2489 /* cmpd. */
2490 void
2491 OP_56_8 (SIM_DESC sd, SIM_CPU *cpu)
2493 uint32_t a = (OP[0]);
2494 uint32_t b = GPR32 (OP[1]);
2495 trace_input ("cmpd", OP_CONSTANT4, OP_REGP, OP_VOID);
2496 SET_PSR_Z (a == b);
2497 SET_PSR_N ((int32_t)a > (int32_t)b);
2498 SET_PSR_L (a > b);
2499 trace_output_flag (sd);
2502 /* cmpd. */
2503 void
2504 OP_56B_C (SIM_DESC sd, SIM_CPU *cpu)
2506 uint32_t a = (SEXT16(OP[0]));
2507 uint32_t b = GPR32 (OP[1]);
2508 trace_input ("cmpd", OP_CONSTANT16, OP_REGP, OP_VOID);
2509 SET_PSR_Z (a == b);
2510 SET_PSR_N ((int32_t)a > (int32_t)b);
2511 SET_PSR_L (a > b);
2512 trace_output_flag (sd);
2515 /* cmpd. */
2516 void
2517 OP_57_8 (SIM_DESC sd, SIM_CPU *cpu)
2519 uint32_t a = GPR32 (OP[0]) ;
2520 uint32_t b = GPR32 (OP[1]) ;
2521 trace_input ("cmpd", OP_REGP, OP_REGP, OP_VOID);
2522 SET_PSR_Z (a == b);
2523 SET_PSR_N ((int32_t)a > (int32_t)b);
2524 SET_PSR_L (a > b);
2525 trace_output_flag (sd);
2528 /* cmpd. */
2529 void
2530 OP_9_C (SIM_DESC sd, SIM_CPU *cpu)
2532 uint32_t a = (OP[0]);
2533 uint32_t b = GPR32 (OP[1]);
2534 trace_input ("cmpd", OP_CONSTANT32, OP_REGP, OP_VOID);
2535 SET_PSR_Z (a == b);
2536 SET_PSR_N ((int32_t)a > (int32_t)b);
2537 SET_PSR_L (a > b);
2538 trace_output_flag (sd);
2542 /* movb. */
2543 void
2544 OP_58_8 (SIM_DESC sd, SIM_CPU *cpu)
2546 uint8_t tmp = OP[0] & 0xFF;
2547 uint16_t a = (GPR (OP[1])) & 0xFF00;
2548 trace_input ("movb", OP_CONSTANT4, OP_REG, OP_VOID);
2549 SET_GPR (OP[1], (a | tmp));
2550 trace_output_16 (sd, tmp);
2553 /* movb. */
2554 void
2555 OP_58B_C (SIM_DESC sd, SIM_CPU *cpu)
2557 uint8_t tmp = OP[0] & 0xFF;
2558 uint16_t a = (GPR (OP[1])) & 0xFF00;
2559 trace_input ("movb", OP_CONSTANT16, OP_REG, OP_VOID);
2560 SET_GPR (OP[1], (a | tmp));
2561 trace_output_16 (sd, tmp);
2564 /* movb. */
2565 void
2566 OP_59_8 (SIM_DESC sd, SIM_CPU *cpu)
2568 uint8_t tmp = (GPR (OP[0])) & 0xFF;
2569 uint16_t a = (GPR (OP[1])) & 0xFF00;
2570 trace_input ("movb", OP_REG, OP_REG, OP_VOID);
2571 SET_GPR (OP[1], (a | tmp));
2572 trace_output_16 (sd, tmp);
2575 /* movw. */
2576 void
2577 OP_5A_8 (SIM_DESC sd, SIM_CPU *cpu)
2579 uint16_t tmp = OP[0];
2580 trace_input ("movw", OP_CONSTANT4_1, OP_REG, OP_VOID);
2581 SET_GPR (OP[1], (tmp & 0xffff));
2582 trace_output_16 (sd, tmp);
2585 /* movw. */
2586 void
2587 OP_5AB_C (SIM_DESC sd, SIM_CPU *cpu)
2589 int16_t tmp = OP[0];
2590 trace_input ("movw", OP_CONSTANT16, OP_REG, OP_VOID);
2591 SET_GPR (OP[1], (tmp & 0xffff));
2592 trace_output_16 (sd, tmp);
2595 /* movw. */
2596 void
2597 OP_5B_8 (SIM_DESC sd, SIM_CPU *cpu)
2599 uint16_t tmp = GPR (OP[0]);
2600 uint32_t a = GPR32 (OP[1]);
2601 trace_input ("movw", OP_REG, OP_REGP, OP_VOID);
2602 a = (a & 0xffff0000) | tmp;
2603 SET_GPR32 (OP[1], a);
2604 trace_output_16 (sd, tmp);
2607 /* movxb. */
2608 void
2609 OP_5C_8 (SIM_DESC sd, SIM_CPU *cpu)
2611 uint8_t tmp = (GPR (OP[0])) & 0xFF;
2612 trace_input ("movxb", OP_REG, OP_REG, OP_VOID);
2613 SET_GPR (OP[1], ((SEXT8(tmp)) & 0xffff));
2614 trace_output_16 (sd, tmp);
2617 /* movzb. */
2618 void
2619 OP_5D_8 (SIM_DESC sd, SIM_CPU *cpu)
2621 uint8_t tmp = (GPR (OP[0])) & 0xFF;
2622 trace_input ("movzb", OP_REG, OP_REG, OP_VOID);
2623 SET_GPR (OP[1], tmp);
2624 trace_output_16 (sd, tmp);
2627 /* movxw. */
2628 void
2629 OP_5E_8 (SIM_DESC sd, SIM_CPU *cpu)
2631 uint16_t tmp = GPR (OP[0]);
2632 trace_input ("movxw", OP_REG, OP_REGP, OP_VOID);
2633 SET_GPR32 (OP[1], SEXT16(tmp));
2634 trace_output_16 (sd, tmp);
2637 /* movzw. */
2638 void
2639 OP_5F_8 (SIM_DESC sd, SIM_CPU *cpu)
2641 uint16_t tmp = GPR (OP[0]);
2642 trace_input ("movzw", OP_REG, OP_REGP, OP_VOID);
2643 SET_GPR32 (OP[1], (tmp & 0x0000FFFF));
2644 trace_output_16 (sd, tmp);
2647 /* movd. */
2648 void
2649 OP_54_8 (SIM_DESC sd, SIM_CPU *cpu)
2651 int32_t tmp = OP[0];
2652 trace_input ("movd", OP_CONSTANT4, OP_REGP, OP_VOID);
2653 SET_GPR32 (OP[1], tmp);
2654 trace_output_32 (sd, tmp);
2657 /* movd. */
2658 void
2659 OP_54B_C (SIM_DESC sd, SIM_CPU *cpu)
2661 int32_t tmp = SEXT16(OP[0]);
2662 trace_input ("movd", OP_CONSTANT16, OP_REGP, OP_VOID);
2663 SET_GPR32 (OP[1], tmp);
2664 trace_output_32 (sd, tmp);
2667 /* movd. */
2668 void
2669 OP_55_8 (SIM_DESC sd, SIM_CPU *cpu)
2671 uint32_t tmp = GPR32 (OP[0]);
2672 trace_input ("movd", OP_REGP, OP_REGP, OP_VOID);
2673 SET_GPR32 (OP[1], tmp);
2674 trace_output_32 (sd, tmp);
2677 /* movd. */
2678 void
2679 OP_5_8 (SIM_DESC sd, SIM_CPU *cpu)
2681 uint32_t tmp = OP[0];
2682 trace_input ("movd", OP_CONSTANT20, OP_REGP, OP_VOID);
2683 SET_GPR32 (OP[1], tmp);
2684 trace_output_32 (sd, tmp);
2687 /* movd. */
2688 void
2689 OP_7_C (SIM_DESC sd, SIM_CPU *cpu)
2691 int32_t tmp = OP[0];
2692 trace_input ("movd", OP_CONSTANT32, OP_REGP, OP_VOID);
2693 SET_GPR32 (OP[1], tmp);
2694 trace_output_32 (sd, tmp);
2697 /* loadm. */
2698 void
2699 OP_14_D (SIM_DESC sd, SIM_CPU *cpu)
2701 uint32_t addr = GPR (0);
2702 uint16_t count = OP[0], reg = 2, tmp;
2703 trace_input ("loadm", OP_CONSTANT4, OP_VOID, OP_VOID);
2704 if ((addr & 1))
2706 trace_output_void (sd);
2707 EXCEPTION (SIM_SIGBUS);
2710 while (count)
2712 tmp = RW (addr);
2713 SET_GPR (reg, tmp);
2714 addr +=2;
2715 --count;
2716 reg++;
2717 if (reg == 6) reg = 8;
2720 SET_GPR (0, addr);
2721 trace_output_void (sd);
2725 /* loadmp. */
2726 void
2727 OP_15_D (SIM_DESC sd, SIM_CPU *cpu)
2729 uint32_t addr = GPR32 (0);
2730 uint16_t count = OP[0], reg = 2, tmp;
2731 trace_input ("loadm", OP_CONSTANT4, OP_VOID, OP_VOID);
2732 if ((addr & 1))
2734 trace_output_void (sd);
2735 EXCEPTION (SIM_SIGBUS);
2738 while (count)
2740 tmp = RW (addr);
2741 SET_GPR (reg, tmp);
2742 addr +=2;
2743 --count;
2744 reg++;
2745 if (reg == 6) reg = 8;
2748 SET_GPR32 (0, addr);
2749 trace_output_void (sd);
2753 /* loadb. */
2754 void
2755 OP_88_8 (SIM_DESC sd, SIM_CPU *cpu)
2757 /* loadb ABS20, REG
2758 * ADDR = zext24(abs20) | remap (ie 0xF00000)
2759 * REG = [ADDR]
2760 * NOTE: remap is
2761 * If (abs20 > 0xEFFFF) the resulting address is logically ORed
2762 * with 0xF00000 i.e. addresses from 1M-64k to 1M are re-mapped
2763 * by the core to 16M-64k to 16M. */
2765 uint16_t tmp, a = (GPR (OP[1])) & 0xFF00;
2766 uint32_t addr = OP[0];
2767 trace_input ("loadb", OP_ABS20, OP_REG, OP_VOID);
2768 if (addr > 0xEFFFF) addr |= 0xF00000;
2769 tmp = (RB (addr));
2770 SET_GPR (OP[1], (a | tmp));
2771 trace_output_16 (sd, tmp);
2774 /* loadb. */
2775 void
2776 OP_127_14 (SIM_DESC sd, SIM_CPU *cpu)
2778 /* loadb ABS24, REG
2779 * ADDR = abs24
2780 * REGR = [ADDR]. */
2782 uint16_t tmp, a = (GPR (OP[1])) & 0xFF00;
2783 uint32_t addr = OP[0];
2784 trace_input ("loadb", OP_ABS24, OP_REG, OP_VOID);
2785 tmp = (RB (addr));
2786 SET_GPR (OP[1], (a | tmp));
2787 trace_output_16 (sd, tmp);
2790 /* loadb. */
2791 void
2792 OP_45_7 (SIM_DESC sd, SIM_CPU *cpu)
2794 /* loadb [Rindex]ABS20 REG
2795 * ADDR = Rindex + zext24(disp20)
2796 * REGR = [ADDR]. */
2798 uint32_t addr;
2799 uint16_t tmp, a = (GPR (OP[2])) & 0xFF00;
2800 trace_input ("loadb", OP_R_INDEX8_ABS20, OP_REG, OP_VOID);
2802 if (OP[0] == 0)
2803 addr = (GPR32 (12)) + OP[1];
2804 else
2805 addr = (GPR32 (13)) + OP[1];
2807 tmp = (RB (addr));
2808 SET_GPR (OP[2], (a | tmp));
2809 trace_output_16 (sd, tmp);
2813 /* loadb. */
2814 void
2815 OP_B_4 (SIM_DESC sd, SIM_CPU *cpu)
2817 /* loadb DIPS4(REGP) REG
2818 * ADDR = RPBASE + zext24(DISP4)
2819 * REG = [ADDR]. */
2820 uint16_t tmp, a = (GPR (OP[2])) & 0xFF00;
2821 uint32_t addr = (GPR32 (OP[1])) + OP[0];
2822 trace_input ("loadb", OP_RP_BASE_DISP4, OP_REG, OP_VOID);
2823 tmp = (RB (addr));
2824 SET_GPR (OP[2], (a | tmp));
2825 trace_output_16 (sd, tmp);
2828 /* loadb. */
2829 void
2830 OP_BE_8 (SIM_DESC sd, SIM_CPU *cpu)
2832 /* loadb [Rindex]disp0(RPbasex) REG
2833 * ADDR = Rpbasex + Rindex
2834 * REGR = [ADDR] */
2836 uint32_t addr;
2837 uint16_t tmp, a = (GPR (OP[3])) & 0xFF00;
2838 trace_input ("loadb", OP_RP_INDEX_DISP0, OP_REG, OP_VOID);
2840 addr = (GPR32 (OP[2])) + OP[1];
2842 if (OP[0] == 0)
2843 addr = (GPR32 (12)) + addr;
2844 else
2845 addr = (GPR32 (13)) + addr;
2847 tmp = (RB (addr));
2848 SET_GPR (OP[3], (a | tmp));
2849 trace_output_16 (sd, tmp);
2852 /* loadb. */
2853 void
2854 OP_219_A (SIM_DESC sd, SIM_CPU *cpu)
2856 /* loadb [Rindex]disp14(RPbasex) REG
2857 * ADDR = Rpbasex + Rindex + zext24(disp14)
2858 * REGR = [ADDR] */
2860 uint32_t addr;
2861 uint16_t tmp, a = (GPR (OP[3])) & 0xFF00;
2863 addr = (GPR32 (OP[2])) + OP[1];
2865 if (OP[0] == 0)
2866 addr = (GPR32 (12)) + addr;
2867 else
2868 addr = (GPR32 (13)) + addr;
2870 trace_input ("loadb", OP_RP_INDEX_DISP14, OP_REG, OP_VOID);
2871 tmp = (RB (addr));
2872 SET_GPR (OP[3], (a | tmp));
2873 trace_output_16 (sd, tmp);
2877 /* loadb. */
2878 void
2879 OP_184_14 (SIM_DESC sd, SIM_CPU *cpu)
2881 /* loadb DISPE20(REG) REG
2882 * zext24(Rbase) + zext24(dispe20)
2883 * REG = [ADDR] */
2885 uint16_t tmp,a = (GPR (OP[2])) & 0xFF00;
2886 uint32_t addr = OP[0] + (GPR (OP[1]));
2887 trace_input ("loadb", OP_R_BASE_DISPE20, OP_REG, OP_VOID);
2888 tmp = (RB (addr));
2889 SET_GPR (OP[2], (a | tmp));
2890 trace_output_16 (sd, tmp);
2893 /* loadb. */
2894 void
2895 OP_124_14 (SIM_DESC sd, SIM_CPU *cpu)
2897 /* loadb DISP20(REG) REG
2898 * ADDR = zext24(Rbase) + zext24(disp20)
2899 * REG = [ADDR] */
2901 uint16_t tmp,a = (GPR (OP[2])) & 0xFF00;
2902 uint32_t addr = OP[0] + (GPR (OP[1]));
2903 trace_input ("loadb", OP_R_BASE_DISP20, OP_REG, OP_VOID);
2904 tmp = (RB (addr));
2905 SET_GPR (OP[2], (a | tmp));
2906 trace_output_16 (sd, tmp);
2909 /* loadb. */
2910 void
2911 OP_BF_8 (SIM_DESC sd, SIM_CPU *cpu)
2913 /* loadb disp16(REGP) REG
2914 * ADDR = RPbase + zext24(disp16)
2915 * REGR = [ADDR] */
2917 uint16_t tmp,a = (GPR (OP[2])) & 0xFF00;
2918 uint32_t addr = (GPR32 (OP[1])) + OP[0];
2919 trace_input ("loadb", OP_RP_BASE_DISP16, OP_REG, OP_VOID);
2920 tmp = (RB (addr));
2921 SET_GPR (OP[2], (a | tmp));
2922 trace_output_16 (sd, tmp);
2925 /* loadb. */
2926 void
2927 OP_125_14 (SIM_DESC sd, SIM_CPU *cpu)
2929 /* loadb disp20(REGP) REG
2930 * ADDR = RPbase + zext24(disp20)
2931 * REGR = [ADDR] */
2932 uint16_t tmp,a = (GPR (OP[2])) & 0xFF00;
2933 uint32_t addr = (GPR32 (OP[1])) + OP[0];
2934 trace_input ("loadb", OP_RP_BASE_DISP20, OP_REG, OP_VOID);
2935 tmp = (RB (addr));
2936 SET_GPR (OP[2], (a | tmp));
2937 trace_output_16 (sd, tmp);
2941 /* loadb. */
2942 void
2943 OP_185_14 (SIM_DESC sd, SIM_CPU *cpu)
2945 /* loadb -disp20(REGP) REG
2946 * ADDR = RPbase + zext24(-disp20)
2947 * REGR = [ADDR] */
2948 uint16_t tmp,a = (GPR (OP[2])) & 0xFF00;
2949 uint32_t addr = (GPR32 (OP[1])) + OP[1];
2950 trace_input ("loadb", OP_RP_BASE_DISPE20, OP_REG, OP_VOID);
2951 tmp = (RB (addr));
2952 SET_GPR (OP[2], (a | tmp));
2953 trace_output_16 (sd, tmp);
2956 /* loadb. */
2957 void
2958 OP_126_14 (SIM_DESC sd, SIM_CPU *cpu)
2960 /* loadb [Rindex]disp20(RPbasexb) REG
2961 * ADDR = RPbasex + Rindex + zext24(disp20)
2962 * REGR = [ADDR] */
2964 uint32_t addr;
2965 uint16_t tmp, a = (GPR (OP[3])) & 0xFF00;
2966 trace_input ("loadb", OP_RP_INDEX_DISP20, OP_REG, OP_VOID);
2968 addr = (GPR32 (OP[2])) + OP[1];
2970 if (OP[0] == 0)
2971 addr = (GPR32 (12)) + addr;
2972 else
2973 addr = (GPR32 (13)) + addr;
2975 tmp = (RB (addr));
2976 SET_GPR (OP[3], (a | tmp));
2977 trace_output_16 (sd, tmp);
2981 /* loadw. */
2982 void
2983 OP_89_8 (SIM_DESC sd, SIM_CPU *cpu)
2985 /* loadw ABS20, REG
2986 * ADDR = zext24(abs20) | remap
2987 * REGR = [ADDR]
2988 * NOTE: remap is
2989 * If (abs20 > 0xEFFFF) the resulting address is logically ORed
2990 * with 0xF00000 i.e. addresses from 1M-64k to 1M are re-mapped
2991 * by the core to 16M-64k to 16M. */
2993 uint16_t tmp;
2994 uint32_t addr = OP[0];
2995 trace_input ("loadw", OP_ABS20, OP_REG, OP_VOID);
2996 if (addr > 0xEFFFF) addr |= 0xF00000;
2997 tmp = (RW (addr));
2998 SET_GPR (OP[1], tmp);
2999 trace_output_16 (sd, tmp);
3003 /* loadw. */
3004 void
3005 OP_12F_14 (SIM_DESC sd, SIM_CPU *cpu)
3007 /* loadw ABS24, REG
3008 * ADDR = abs24
3009 * REGR = [ADDR] */
3010 uint16_t tmp;
3011 uint32_t addr = OP[0];
3012 trace_input ("loadw", OP_ABS24, OP_REG, OP_VOID);
3013 tmp = (RW (addr));
3014 SET_GPR (OP[1], tmp);
3015 trace_output_16 (sd, tmp);
3018 /* loadw. */
3019 void
3020 OP_47_7 (SIM_DESC sd, SIM_CPU *cpu)
3022 /* loadw [Rindex]ABS20 REG
3023 * ADDR = Rindex + zext24(disp20)
3024 * REGR = [ADDR] */
3026 uint32_t addr;
3027 uint16_t tmp;
3028 trace_input ("loadw", OP_R_INDEX8_ABS20, OP_REG, OP_VOID);
3030 if (OP[0] == 0)
3031 addr = (GPR32 (12)) + OP[1];
3032 else
3033 addr = (GPR32 (13)) + OP[1];
3035 tmp = (RW (addr));
3036 SET_GPR (OP[2], tmp);
3037 trace_output_16 (sd, tmp);
3041 /* loadw. */
3042 void
3043 OP_9_4 (SIM_DESC sd, SIM_CPU *cpu)
3045 /* loadw DIPS4(REGP) REGP
3046 * ADDR = RPBASE + zext24(DISP4)
3047 * REGP = [ADDR]. */
3048 uint16_t tmp;
3049 uint32_t addr, a;
3050 trace_input ("loadw", OP_RP_BASE_DISP4, OP_REG, OP_VOID);
3051 addr = (GPR32 (OP[1])) + OP[0];
3052 tmp = (RW (addr));
3053 if (OP[2] > 11)
3055 a = (GPR32 (OP[2])) & 0xffff0000;
3056 SET_GPR32 (OP[2], (a | tmp));
3058 else
3059 SET_GPR (OP[2], tmp);
3061 trace_output_16 (sd, tmp);
3065 /* loadw. */
3066 void
3067 OP_9E_8 (SIM_DESC sd, SIM_CPU *cpu)
3069 /* loadw [Rindex]disp0(RPbasex) REG
3070 * ADDR = Rpbasex + Rindex
3071 * REGR = [ADDR] */
3073 uint32_t addr;
3074 uint16_t tmp;
3075 trace_input ("loadw", OP_RP_INDEX_DISP0, OP_REG, OP_VOID);
3077 addr = (GPR32 (OP[2])) + OP[1];
3079 if (OP[0] == 0)
3080 addr = (GPR32 (12)) + addr;
3081 else
3082 addr = (GPR32 (13)) + addr;
3084 tmp = RW (addr);
3085 SET_GPR (OP[3], tmp);
3086 trace_output_16 (sd, tmp);
3090 /* loadw. */
3091 void
3092 OP_21B_A (SIM_DESC sd, SIM_CPU *cpu)
3094 /* loadw [Rindex]disp14(RPbasex) REG
3095 * ADDR = Rpbasex + Rindex + zext24(disp14)
3096 * REGR = [ADDR] */
3098 uint32_t addr;
3099 uint16_t tmp;
3100 trace_input ("loadw", OP_RP_INDEX_DISP14, OP_REG, OP_VOID);
3101 addr = (GPR32 (OP[2])) + OP[1];
3103 if (OP[0] == 0)
3104 addr = (GPR32 (12)) + addr;
3105 else
3106 addr = (GPR32 (13)) + addr;
3108 tmp = (RW (addr));
3109 SET_GPR (OP[3], tmp);
3110 trace_output_16 (sd, tmp);
3113 /* loadw. */
3114 void
3115 OP_18C_14 (SIM_DESC sd, SIM_CPU *cpu)
3117 /* loadw dispe20(REG) REGP
3118 * REGP = [DISPE20+[REG]] */
3120 uint16_t tmp;
3121 uint32_t addr, a;
3122 trace_input ("loadw", OP_R_BASE_DISPE20, OP_REGP, OP_VOID);
3123 addr = OP[0] + (GPR (OP[1]));
3124 tmp = (RW (addr));
3125 if (OP[2] > 11)
3127 a = (GPR32 (OP[2])) & 0xffff0000;
3128 SET_GPR32 (OP[2], (a | tmp));
3130 else
3131 SET_GPR (OP[2], tmp);
3133 trace_output_16 (sd, tmp);
3137 /* loadw. */
3138 void
3139 OP_12C_14 (SIM_DESC sd, SIM_CPU *cpu)
3141 /* loadw DISP20(REG) REGP
3142 * ADDR = zext24(Rbase) + zext24(disp20)
3143 * REGP = [ADDR] */
3145 uint16_t tmp;
3146 uint32_t addr, a;
3147 trace_input ("loadw", OP_R_BASE_DISP20, OP_REGP, OP_VOID);
3148 addr = OP[0] + (GPR (OP[1]));
3149 tmp = (RW (addr));
3150 if (OP[2] > 11)
3152 a = (GPR32 (OP[2])) & 0xffff0000;
3153 SET_GPR32 (OP[2], (a | tmp));
3155 else
3156 SET_GPR (OP[2], tmp);
3158 trace_output_16 (sd, tmp);
3161 /* loadw. */
3162 void
3163 OP_9F_8 (SIM_DESC sd, SIM_CPU *cpu)
3165 /* loadw disp16(REGP) REGP
3166 * ADDR = RPbase + zext24(disp16)
3167 * REGP = [ADDR] */
3168 uint16_t tmp;
3169 uint32_t addr, a;
3170 trace_input ("loadw", OP_RP_BASE_DISP16, OP_REGP, OP_VOID);
3171 addr = (GPR32 (OP[1])) + OP[0];
3172 tmp = (RW (addr));
3173 if (OP[2] > 11)
3175 a = (GPR32 (OP[2])) & 0xffff0000;
3176 SET_GPR32 (OP[2], (a | tmp));
3178 else
3179 SET_GPR (OP[2], tmp);
3181 trace_output_16 (sd, tmp);
3184 /* loadw. */
3185 void
3186 OP_12D_14 (SIM_DESC sd, SIM_CPU *cpu)
3188 /* loadw disp20(REGP) REGP
3189 * ADDR = RPbase + zext24(disp20)
3190 * REGP = [ADDR] */
3191 uint16_t tmp;
3192 uint32_t addr, a;
3193 trace_input ("loadw", OP_RP_BASE_DISP20, OP_REG, OP_VOID);
3194 addr = (GPR32 (OP[1])) + OP[0];
3195 tmp = (RW (addr));
3196 if (OP[2] > 11)
3198 a = (GPR32 (OP[2])) & 0xffff0000;
3199 SET_GPR32 (OP[2], (a | tmp));
3201 else
3202 SET_GPR (OP[2], tmp);
3204 trace_output_16 (sd, tmp);
3207 /* loadw. */
3208 void
3209 OP_18D_14 (SIM_DESC sd, SIM_CPU *cpu)
3211 /* loadw -disp20(REGP) REG
3212 * ADDR = RPbase + zext24(-disp20)
3213 * REGR = [ADDR] */
3215 uint16_t tmp;
3216 uint32_t addr, a;
3217 trace_input ("loadw", OP_RP_BASE_DISPE20, OP_REG, OP_VOID);
3218 addr = (GPR32 (OP[1])) + OP[0];
3219 tmp = (RB (addr));
3220 if (OP[2] > 11)
3222 a = (GPR32 (OP[2])) & 0xffff0000;
3223 SET_GPR32 (OP[2], (a | tmp));
3225 else
3226 SET_GPR (OP[2], tmp);
3228 trace_output_16 (sd, tmp);
3232 /* loadw. */
3233 void
3234 OP_12E_14 (SIM_DESC sd, SIM_CPU *cpu)
3236 /* loadw [Rindex]disp20(RPbasexb) REG
3237 * ADDR = RPbasex + Rindex + zext24(disp20)
3238 * REGR = [ADDR] */
3240 uint32_t addr;
3241 uint16_t tmp;
3242 trace_input ("loadw", OP_RP_INDEX_DISP20, OP_REG, OP_VOID);
3244 if (OP[0] == 0)
3245 addr = (GPR32 (12)) + OP[1] + (GPR32 (OP[2]));
3246 else
3247 addr = (GPR32 (13)) + OP[1] + (GPR32 (OP[2]));
3249 tmp = (RW (addr));
3250 SET_GPR (OP[3], tmp);
3251 trace_output_16 (sd, tmp);
3255 /* loadd. */
3256 void
3257 OP_87_8 (SIM_DESC sd, SIM_CPU *cpu)
3259 /* loadd ABS20, REGP
3260 * ADDR = zext24(abs20) | remap
3261 * REGP = [ADDR]
3262 * NOTE: remap is
3263 * If (abs20 > 0xEFFFF) the resulting address is logically ORed
3264 * with 0xF00000 i.e. addresses from 1M-64k to 1M are re-mapped
3265 * by the core to 16M-64k to 16M. */
3267 uint32_t addr, tmp;
3268 addr = OP[0];
3269 trace_input ("loadd", OP_ABS20, OP_REGP, OP_VOID);
3270 if (addr > 0xEFFFF) addr |= 0xF00000;
3271 tmp = RLW (addr);
3272 tmp = ((tmp << 16) & 0xffff)| ((tmp >> 16) & 0xffff);
3273 SET_GPR32 (OP[1], tmp);
3274 trace_output_32 (sd, tmp);
3277 /* loadd. */
3278 void
3279 OP_12B_14 (SIM_DESC sd, SIM_CPU *cpu)
3281 /* loadd ABS24, REGP
3282 * ADDR = abs24
3283 * REGP = [ADDR] */
3285 uint32_t addr = OP[0];
3286 uint32_t tmp;
3287 trace_input ("loadd", OP_ABS24, OP_REGP, OP_VOID);
3288 tmp = RLW (addr);
3289 tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
3290 SET_GPR32 (OP[1],tmp);
3291 trace_output_32 (sd, tmp);
3295 /* loadd. */
3296 void
3297 OP_46_7 (SIM_DESC sd, SIM_CPU *cpu)
3299 /* loadd [Rindex]ABS20 REGP
3300 * ADDR = Rindex + zext24(disp20)
3301 * REGP = [ADDR] */
3303 uint32_t addr, tmp;
3304 trace_input ("loadd", OP_R_INDEX8_ABS20, OP_REGP, OP_VOID);
3306 if (OP[0] == 0)
3307 addr = (GPR32 (12)) + OP[1];
3308 else
3309 addr = (GPR32 (13)) + OP[1];
3311 tmp = RLW (addr);
3312 tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
3313 SET_GPR32 (OP[2], tmp);
3314 trace_output_32 (sd, tmp);
3318 /* loadd. */
3319 void
3320 OP_A_4 (SIM_DESC sd, SIM_CPU *cpu)
3322 /* loadd dips4(regp) REGP
3323 * ADDR = Rpbase + zext24(disp4)
3324 * REGP = [ADDR] */
3326 uint32_t tmp, addr = (GPR32 (OP[1])) + OP[0];
3327 trace_input ("loadd", OP_RP_BASE_DISP4, OP_REGP, OP_VOID);
3328 tmp = RLW (addr);
3329 tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
3330 SET_GPR32 (OP[2], tmp);
3331 trace_output_32 (sd, tmp);
3335 /* loadd. */
3336 void
3337 OP_AE_8 (SIM_DESC sd, SIM_CPU *cpu)
3339 /* loadd [Rindex]disp0(RPbasex) REGP
3340 * ADDR = Rpbasex + Rindex
3341 * REGP = [ADDR] */
3343 uint32_t addr, tmp;
3344 trace_input ("loadd", OP_RP_INDEX_DISP0, OP_REGP, OP_VOID);
3346 if (OP[0] == 0)
3347 addr = (GPR32 (12)) + (GPR32 (OP[2])) + OP[1];
3348 else
3349 addr = (GPR32 (13)) + (GPR32 (OP[2])) + OP[1];
3351 tmp = RLW (addr);
3352 tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
3353 SET_GPR32 (OP[3], tmp);
3354 trace_output_32 (sd, tmp);
3358 /* loadd. */
3359 void
3360 OP_21A_A (SIM_DESC sd, SIM_CPU *cpu)
3362 /* loadd [Rindex]disp14(RPbasex) REGP
3363 * ADDR = Rpbasex + Rindex + zext24(disp14)
3364 * REGR = [ADDR] */
3366 uint32_t addr, tmp;
3367 trace_input ("loadd", OP_RP_INDEX_DISP14, OP_REGP, OP_VOID);
3369 if (OP[0] == 0)
3370 addr = (GPR32 (12)) + OP[1] + (GPR32 (OP[2]));
3371 else
3372 addr = (GPR32 (13)) + OP[1] + (GPR32 (OP[2]));
3374 tmp = RLW (addr);
3375 tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
3376 SET_GPR (OP[3],tmp);
3377 trace_output_32 (sd, tmp);
3381 /* loadd. */
3382 void
3383 OP_188_14 (SIM_DESC sd, SIM_CPU *cpu)
3385 /* loadd dispe20(REG) REG
3386 * zext24(Rbase) + zext24(dispe20)
3387 * REG = [ADDR] */
3389 uint32_t tmp, addr = OP[0] + (GPR (OP[1]));
3390 trace_input ("loadd", OP_R_BASE_DISPE20, OP_REGP, OP_VOID);
3391 tmp = RLW (addr);
3392 tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
3393 SET_GPR32 (OP[2], tmp);
3394 trace_output_32 (sd, tmp);
3398 /* loadd. */
3399 void
3400 OP_128_14 (SIM_DESC sd, SIM_CPU *cpu)
3402 /* loadd DISP20(REG) REG
3403 * ADDR = zext24(Rbase) + zext24(disp20)
3404 * REG = [ADDR] */
3406 uint32_t tmp, addr = OP[0] + (GPR (OP[1]));
3407 trace_input ("loadd", OP_R_BASE_DISP20, OP_REGP, OP_VOID);
3408 tmp = RLW (addr);
3409 tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
3410 SET_GPR32 (OP[2], tmp);
3411 trace_output_32 (sd, tmp);
3414 /* loadd. */
3415 void
3416 OP_AF_8 (SIM_DESC sd, SIM_CPU *cpu)
3418 /* loadd disp16(REGP) REGP
3419 * ADDR = RPbase + zext24(disp16)
3420 * REGR = [ADDR] */
3421 uint32_t tmp, addr = OP[0] + (GPR32 (OP[1]));
3422 trace_input ("loadd", OP_RP_BASE_DISP16, OP_REGP, OP_VOID);
3423 tmp = RLW (addr);
3424 tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
3425 SET_GPR32 (OP[2], tmp);
3426 trace_output_32 (sd, tmp);
3430 /* loadd. */
3431 void
3432 OP_129_14 (SIM_DESC sd, SIM_CPU *cpu)
3434 /* loadd disp20(REGP) REGP
3435 * ADDR = RPbase + zext24(disp20)
3436 * REGP = [ADDR] */
3437 uint32_t tmp, addr = OP[0] + (GPR32 (OP[1]));
3438 trace_input ("loadd", OP_RP_BASE_DISP20, OP_REGP, OP_VOID);
3439 tmp = RLW (addr);
3440 tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
3441 SET_GPR32 (OP[2], tmp);
3442 trace_output_32 (sd, tmp);
3445 /* loadd. */
3446 void
3447 OP_189_14 (SIM_DESC sd, SIM_CPU *cpu)
3449 /* loadd -disp20(REGP) REGP
3450 * ADDR = RPbase + zext24(-disp20)
3451 * REGP = [ADDR] */
3453 uint32_t tmp, addr = OP[0] + (GPR32 (OP[1]));
3454 trace_input ("loadd", OP_RP_BASE_DISPE20, OP_REGP, OP_VOID);
3455 tmp = RLW (addr);
3456 tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
3457 SET_GPR32 (OP[2], tmp);
3458 trace_output_32 (sd, tmp);
3461 /* loadd. */
3462 void
3463 OP_12A_14 (SIM_DESC sd, SIM_CPU *cpu)
3465 /* loadd [Rindex]disp20(RPbasexb) REGP
3466 * ADDR = RPbasex + Rindex + zext24(disp20)
3467 * REGP = [ADDR] */
3469 uint32_t addr, tmp;
3470 trace_input ("loadd", OP_RP_INDEX_DISP20, OP_REGP, OP_VOID);
3472 if (OP[0] == 0)
3473 addr = (GPR32 (12)) + OP[1] + (GPR32 (OP[2]));
3474 else
3475 addr = (GPR32 (13)) + OP[1] + (GPR32 (OP[2]));
3477 tmp = RLW (addr);
3478 tmp = ((tmp << 16) & 0xffff)| ((tmp >> 16) & 0xffff);
3479 SET_GPR32 (OP[3], tmp);
3480 trace_output_32 (sd, tmp);
3484 /* storb. */
3485 void
3486 OP_C8_8 (SIM_DESC sd, SIM_CPU *cpu)
3488 /* storb REG, ABS20
3489 * ADDR = zext24(abs20) | remap
3490 * [ADDR] = REGR
3491 * NOTE: remap is
3492 * If (abs20 > 0xEFFFF) the resulting address is logically ORed
3493 * with 0xF00000 i.e. addresses from 1M-64k to 1M are re-mapped
3494 * by the core to 16M-64k to 16M. */
3496 uint8_t a = ((GPR (OP[0])) & 0xff);
3497 uint32_t addr = OP[1];
3498 trace_input ("storb", OP_REG, OP_ABS20_OUTPUT, OP_VOID);
3499 SB (addr, a);
3500 trace_output_32 (sd, addr);
3503 /* storb. */
3504 void
3505 OP_137_14 (SIM_DESC sd, SIM_CPU *cpu)
3507 /* storb REG, ABS24
3508 * ADDR = abs24
3509 * [ADDR] = REGR. */
3511 uint8_t a = ((GPR (OP[0])) & 0xff);
3512 uint32_t addr = OP[1];
3513 trace_input ("storb", OP_REG, OP_ABS24_OUTPUT, OP_VOID);
3514 SB (addr, a);
3515 trace_output_32 (sd, addr);
3518 /* storb. */
3519 void
3520 OP_65_7 (SIM_DESC sd, SIM_CPU *cpu)
3522 /* storb REG, [Rindex]ABS20
3523 * ADDR = Rindex + zext24(disp20)
3524 * [ADDR] = REGR */
3526 uint32_t addr;
3527 uint8_t a = ((GPR (OP[0])) & 0xff);
3528 trace_input ("storb", OP_REG, OP_R_INDEX8_ABS20, OP_VOID);
3530 if (OP[1] == 0)
3531 addr = (GPR32 (12)) + OP[2];
3532 else
3533 addr = (GPR32 (13)) + OP[2];
3535 SB (addr, a);
3536 trace_output_32 (sd, addr);
3539 /* storb. */
3540 void
3541 OP_F_4 (SIM_DESC sd, SIM_CPU *cpu)
3543 /* storb REG, DIPS4(REGP)
3544 * ADDR = RPBASE + zext24(DISP4)
3545 * [ADDR] = REG. */
3547 uint16_t a = ((GPR (OP[0])) & 0xff);
3548 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3549 trace_input ("storb", OP_REG, OP_RP_BASE_DISPE4, OP_VOID);
3550 SB (addr, a);
3551 trace_output_32 (sd, addr);
3554 /* storb. */
3555 void
3556 OP_FE_8 (SIM_DESC sd, SIM_CPU *cpu)
3558 /* storb [Rindex]disp0(RPbasex) REG
3559 * ADDR = Rpbasex + Rindex
3560 * [ADDR] = REGR */
3562 uint32_t addr;
3563 uint8_t a = ((GPR (OP[0])) & 0xff);
3564 trace_input ("storb", OP_REG, OP_RP_INDEX_DISP0, OP_VOID);
3566 if (OP[1] == 0)
3567 addr = (GPR32 (12)) + (GPR32 (OP[3])) + OP[2];
3568 else
3569 addr = (GPR32 (13)) + (GPR32 (OP[3])) + OP[2];
3571 SB (addr, a);
3572 trace_output_32 (sd, addr);
3575 /* storb. */
3576 void
3577 OP_319_A (SIM_DESC sd, SIM_CPU *cpu)
3579 /* storb REG, [Rindex]disp14(RPbasex)
3580 * ADDR = Rpbasex + Rindex + zext24(disp14)
3581 * [ADDR] = REGR */
3583 uint8_t a = ((GPR (OP[0])) & 0xff);
3584 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3585 trace_input ("storb", OP_REG, OP_RP_INDEX_DISP14, OP_VOID);
3586 SB (addr, a);
3587 trace_output_32 (sd, addr);
3590 /* storb. */
3591 void
3592 OP_194_14 (SIM_DESC sd, SIM_CPU *cpu)
3594 /* storb REG, DISPE20(REG)
3595 * zext24(Rbase) + zext24(dispe20)
3596 * [ADDR] = REG */
3598 uint8_t a = ((GPR (OP[0])) & 0xff);
3599 uint32_t addr = OP[1] + (GPR (OP[2]));
3600 trace_input ("storb", OP_REG, OP_R_BASE_DISPE20, OP_VOID);
3601 SB (addr, a);
3602 trace_output_32 (sd, addr);
3605 /* storb. */
3606 void
3607 OP_134_14 (SIM_DESC sd, SIM_CPU *cpu)
3609 /* storb REG, DISP20(REG)
3610 * ADDR = zext24(Rbase) + zext24(disp20)
3611 * [ADDR] = REG */
3613 uint8_t a = (GPR (OP[0]) & 0xff);
3614 uint32_t addr = OP[1] + (GPR (OP[2]));
3615 trace_input ("storb", OP_REG, OP_R_BASE_DISPS20, OP_VOID);
3616 SB (addr, a);
3617 trace_output_32 (sd, addr);
3620 /* storb. */
3621 void
3622 OP_FF_8 (SIM_DESC sd, SIM_CPU *cpu)
3624 /* storb REG, disp16(REGP)
3625 * ADDR = RPbase + zext24(disp16)
3626 * [ADDR] = REGP */
3628 uint8_t a = ((GPR (OP[0])) & 0xff);
3629 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3630 trace_input ("storb", OP_REG, OP_RP_BASE_DISP16, OP_VOID);
3631 SB (addr, a);
3632 trace_output_32 (sd, addr);
3635 /* storb. */
3636 void
3637 OP_135_14 (SIM_DESC sd, SIM_CPU *cpu)
3639 /* storb REG, disp20(REGP)
3640 * ADDR = RPbase + zext24(disp20)
3641 * [ADDR] = REGP */
3643 uint8_t a = ((GPR (OP[0])) & 0xff);
3644 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3645 trace_input ("storb", OP_REG, OP_RP_BASE_DISPS20, OP_VOID);
3646 SB (addr, a);
3647 trace_output_32 (sd, addr);
3650 /* storb. */
3651 void
3652 OP_195_14 (SIM_DESC sd, SIM_CPU *cpu)
3654 /* storb REG, -disp20(REGP)
3655 * ADDR = RPbase + zext24(-disp20)
3656 * [ADDR] = REGP */
3658 uint8_t a = (GPR (OP[0]) & 0xff);
3659 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3660 trace_input ("storb", OP_REG, OP_RP_BASE_DISPE20, OP_VOID);
3661 SB (addr, a);
3662 trace_output_32 (sd, addr);
3665 /* storb. */
3666 void
3667 OP_136_14 (SIM_DESC sd, SIM_CPU *cpu)
3669 /* storb REG, [Rindex]disp20(RPbase)
3670 * ADDR = RPbasex + Rindex + zext24(disp20)
3671 * [ADDR] = REGP */
3673 uint8_t a = (GPR (OP[0])) & 0xff;
3674 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3675 trace_input ("storb", OP_REG, OP_RP_INDEX_DISPS20, OP_VOID);
3676 SB (addr, a);
3677 trace_output_32 (sd, addr);
3680 /* STR_IMM instructions. */
3681 /* storb . */
3682 void
3683 OP_81_8 (SIM_DESC sd, SIM_CPU *cpu)
3685 uint8_t a = (OP[0]) & 0xff;
3686 uint32_t addr = OP[1];
3687 trace_input ("storb", OP_CONSTANT4, OP_ABS20_OUTPUT, OP_VOID);
3688 SB (addr, a);
3689 trace_output_32 (sd, addr);
3692 /* storb. */
3693 void
3694 OP_123_14 (SIM_DESC sd, SIM_CPU *cpu)
3696 uint8_t a = (OP[0]) & 0xff;
3697 uint32_t addr = OP[1];
3698 trace_input ("storb", OP_CONSTANT4, OP_ABS24_OUTPUT, OP_VOID);
3699 SB (addr, a);
3700 trace_output_32 (sd, addr);
3703 /* storb. */
3704 void
3705 OP_42_7 (SIM_DESC sd, SIM_CPU *cpu)
3707 uint32_t addr;
3708 uint8_t a = (OP[0]) & 0xff;
3709 trace_input ("storb", OP_CONSTANT4, OP_R_INDEX8_ABS20, OP_VOID);
3711 if (OP[1] == 0)
3712 addr = (GPR32 (12)) + OP[2];
3713 else
3714 addr = (GPR32 (13)) + OP[2];
3716 SB (addr, a);
3717 trace_output_32 (sd, addr);
3720 /* storb. */
3721 void
3722 OP_218_A (SIM_DESC sd, SIM_CPU *cpu)
3724 uint8_t a = (OP[0]) & 0xff;
3725 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3726 trace_input ("storb", OP_CONSTANT4, OP_RP_BASE_DISP14, OP_VOID);
3727 SB (addr, a);
3728 trace_output_32 (sd, addr);
3731 /* storb. */
3732 void
3733 OP_82_8 (SIM_DESC sd, SIM_CPU *cpu)
3735 uint8_t a = (OP[0]) & 0xff;
3736 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3737 trace_input ("storb", OP_CONSTANT4, OP_RP_INDEX_DISP0, OP_VOID);
3738 SB (addr, a);
3739 trace_output_32 (sd, addr);
3742 /* storb. */
3743 void
3744 OP_120_14 (SIM_DESC sd, SIM_CPU *cpu)
3746 uint8_t a = (OP[0]) & 0xff;
3747 uint32_t addr = (GPR (OP[2])) + OP[1];
3748 trace_input ("storb", OP_CONSTANT4, OP_R_BASE_DISPS20, OP_VOID);
3749 SB (addr, a);
3750 trace_output_32 (sd, addr);
3753 /* storb. */
3754 void
3755 OP_83_8 (SIM_DESC sd, SIM_CPU *cpu)
3757 uint8_t a = (OP[0]) & 0xff;
3758 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3759 trace_input ("storb", OP_CONSTANT4, OP_RP_BASE_DISP16, OP_VOID);
3760 SB (addr, a);
3761 trace_output_32 (sd, addr);
3764 /* storb. */
3765 void
3766 OP_121_14 (SIM_DESC sd, SIM_CPU *cpu)
3768 uint8_t a = (OP[0]) & 0xff;
3769 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3770 trace_input ("storb", OP_CONSTANT4, OP_RP_BASE_DISPS20, OP_VOID);
3771 SB (addr, a);
3772 trace_output_32 (sd, addr);
3775 /* storb. */
3776 void
3777 OP_122_14 (SIM_DESC sd, SIM_CPU *cpu)
3779 uint8_t a = (OP[0]) & 0xff;
3780 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3781 trace_input ("storb", OP_CONSTANT4, OP_RP_INDEX_DISPS20, OP_VOID);
3782 SB (addr, a);
3783 trace_output_32 (sd, addr);
3785 /* endif for STR_IMM. */
3787 /* storw . */
3788 void
3789 OP_C9_8 (SIM_DESC sd, SIM_CPU *cpu)
3791 uint16_t a = GPR (OP[0]);
3792 uint32_t addr = OP[1];
3793 trace_input ("storw", OP_REG, OP_ABS20_OUTPUT, OP_VOID);
3794 SW (addr, a);
3795 trace_output_32 (sd, addr);
3798 /* storw. */
3799 void
3800 OP_13F_14 (SIM_DESC sd, SIM_CPU *cpu)
3802 uint16_t a = GPR (OP[0]);
3803 uint32_t addr = OP[1];
3804 trace_input ("storw", OP_REG, OP_ABS24_OUTPUT, OP_VOID);
3805 SW (addr, a);
3806 trace_output_32 (sd, addr);
3809 /* storw. */
3810 void
3811 OP_67_7 (SIM_DESC sd, SIM_CPU *cpu)
3813 uint32_t addr;
3814 uint16_t a = GPR (OP[0]);
3815 trace_input ("storw", OP_REG, OP_R_INDEX8_ABS20, OP_VOID);
3817 if (OP[1] == 0)
3818 addr = (GPR32 (12)) + OP[2];
3819 else
3820 addr = (GPR32 (13)) + OP[2];
3822 SW (addr, a);
3823 trace_output_32 (sd, addr);
3827 /* storw. */
3828 void
3829 OP_D_4 (SIM_DESC sd, SIM_CPU *cpu)
3831 uint16_t a = (GPR (OP[0]));
3832 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3833 trace_input ("storw", OP_REGP, OP_RP_BASE_DISPE4, OP_VOID);
3834 SW (addr, a);
3835 trace_output_32 (sd, addr);
3838 /* storw. */
3839 void
3840 OP_DE_8 (SIM_DESC sd, SIM_CPU *cpu)
3842 uint16_t a = GPR (OP[0]);
3843 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3844 trace_input ("storw", OP_REG, OP_RP_INDEX_DISP0, OP_VOID);
3845 SW (addr, a);
3846 trace_output_32 (sd, addr);
3849 /* storw. */
3850 void
3851 OP_31B_A (SIM_DESC sd, SIM_CPU *cpu)
3853 uint16_t a = GPR (OP[0]);
3854 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3855 trace_input ("storw", OP_REG, OP_RP_INDEX_DISP14, OP_VOID);
3856 SW (addr, a);
3857 trace_output_32 (sd, addr);
3860 /* storw. */
3861 void
3862 OP_19C_14 (SIM_DESC sd, SIM_CPU *cpu)
3864 uint16_t a = (GPR (OP[0]));
3865 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3866 trace_input ("storw", OP_REGP, OP_RP_BASE_DISPE20, OP_VOID);
3867 SW (addr, a);
3868 trace_output_32 (sd, addr);
3871 /* storw. */
3872 void
3873 OP_13C_14 (SIM_DESC sd, SIM_CPU *cpu)
3875 uint16_t a = (GPR (OP[0]));
3876 uint32_t addr = (GPR (OP[2])) + OP[1];
3877 trace_input ("storw", OP_REG, OP_R_BASE_DISPS20, OP_VOID);
3878 SW (addr, a);
3879 trace_output_32 (sd, addr);
3882 /* storw. */
3883 void
3884 OP_DF_8 (SIM_DESC sd, SIM_CPU *cpu)
3886 uint16_t a = (GPR (OP[0]));
3887 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3888 trace_input ("storw", OP_REG, OP_RP_BASE_DISP16, OP_VOID);
3889 SW (addr, a);
3890 trace_output_32 (sd, addr);
3893 /* storw. */
3894 void
3895 OP_13D_14 (SIM_DESC sd, SIM_CPU *cpu)
3897 uint16_t a = (GPR (OP[0]));
3898 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3899 trace_input ("storw", OP_REG, OP_RP_BASE_DISPS20, OP_VOID);
3900 SW (addr, a);
3901 trace_output_32 (sd, addr);
3904 /* storw. */
3905 void
3906 OP_19D_14 (SIM_DESC sd, SIM_CPU *cpu)
3908 uint16_t a = (GPR (OP[0]));
3909 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3910 trace_input ("storw", OP_REG, OP_RP_BASE_DISPE20, OP_VOID);
3911 SW (addr, a);
3912 trace_output_32 (sd, addr);
3915 /* storw. */
3916 void
3917 OP_13E_14 (SIM_DESC sd, SIM_CPU *cpu)
3919 uint16_t a = (GPR (OP[0]));
3920 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3921 trace_input ("storw", OP_REG, OP_RP_INDEX_DISPS20, OP_VOID);
3922 SW (addr, a);
3923 trace_output_32 (sd, addr);
3926 /* STORE-w IMM instruction *****/
3927 /* storw . */
3928 void
3929 OP_C1_8 (SIM_DESC sd, SIM_CPU *cpu)
3931 uint16_t a = OP[0];
3932 uint32_t addr = OP[1];
3933 trace_input ("storw", OP_CONSTANT4, OP_ABS20_OUTPUT, OP_VOID);
3934 SW (addr, a);
3935 trace_output_32 (sd, addr);
3938 /* storw. */
3939 void
3940 OP_133_14 (SIM_DESC sd, SIM_CPU *cpu)
3942 uint16_t a = OP[0];
3943 uint32_t addr = OP[1];
3944 trace_input ("storw", OP_CONSTANT4, OP_ABS24_OUTPUT, OP_VOID);
3945 SW (addr, a);
3946 trace_output_32 (sd, addr);
3949 /* storw. */
3950 void
3951 OP_62_7 (SIM_DESC sd, SIM_CPU *cpu)
3953 uint32_t addr;
3954 uint16_t a = OP[0];
3955 trace_input ("storw", OP_CONSTANT4, OP_R_INDEX8_ABS20, OP_VOID);
3957 if (OP[1] == 0)
3958 addr = (GPR32 (12)) + OP[2];
3959 else
3960 addr = (GPR32 (13)) + OP[2];
3962 SW (addr, a);
3963 trace_output_32 (sd, addr);
3966 /* storw. */
3967 void
3968 OP_318_A (SIM_DESC sd, SIM_CPU *cpu)
3970 uint16_t a = OP[0];
3971 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3972 trace_input ("storw", OP_CONSTANT4, OP_RP_BASE_DISP14, OP_VOID);
3973 SW (addr, a);
3974 trace_output_32 (sd, addr);
3977 /* storw. */
3978 void
3979 OP_C2_8 (SIM_DESC sd, SIM_CPU *cpu)
3981 uint16_t a = OP[0];
3982 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3983 trace_input ("storw", OP_CONSTANT4, OP_RP_INDEX_DISP0, OP_VOID);
3984 SW (addr, a);
3985 trace_output_32 (sd, addr);
3988 /* storw. */
3989 void
3990 OP_130_14 (SIM_DESC sd, SIM_CPU *cpu)
3992 uint16_t a = OP[0];
3993 uint32_t addr = (GPR32 (OP[2])) + OP[1];
3994 trace_input ("storw", OP_CONSTANT4, OP_R_BASE_DISPS20, OP_VOID);
3995 SW (addr, a);
3996 trace_output_32 (sd, addr);
3999 /* storw. */
4000 void
4001 OP_C3_8 (SIM_DESC sd, SIM_CPU *cpu)
4003 uint16_t a = OP[0];
4004 uint32_t addr = (GPR32 (OP[2])) + OP[1];
4005 trace_input ("storw", OP_CONSTANT4, OP_RP_BASE_DISP16, OP_VOID);
4006 SW (addr, a);
4007 trace_output_32 (sd, addr);
4011 /* storw. */
4012 void
4013 OP_131_14 (SIM_DESC sd, SIM_CPU *cpu)
4015 uint16_t a = OP[0];
4016 uint32_t addr = (GPR32 (OP[2])) + OP[1];
4017 trace_input ("storw", OP_CONSTANT4, OP_RP_BASE_DISPS20, OP_VOID);
4018 SW (addr, a);
4019 trace_output_32 (sd, addr);
4022 /* storw. */
4023 void
4024 OP_132_14 (SIM_DESC sd, SIM_CPU *cpu)
4026 uint16_t a = OP[0];
4027 uint32_t addr = (GPR32 (OP[2])) + OP[1];
4028 trace_input ("storw", OP_CONSTANT4, OP_RP_INDEX_DISPS20, OP_VOID);
4029 SW (addr, a);
4030 trace_output_32 (sd, addr);
4034 /* stord. */
4035 void
4036 OP_C7_8 (SIM_DESC sd, SIM_CPU *cpu)
4038 uint32_t a = GPR32 (OP[0]);
4039 uint32_t addr = OP[1];
4040 trace_input ("stord", OP_REGP, OP_ABS20_OUTPUT, OP_VOID);
4041 SLW (addr, a);
4042 trace_output_32 (sd, addr);
4045 /* stord. */
4046 void
4047 OP_13B_14 (SIM_DESC sd, SIM_CPU *cpu)
4049 uint32_t a = GPR32 (OP[0]);
4050 uint32_t addr = OP[1];
4051 trace_input ("stord", OP_REGP, OP_ABS24_OUTPUT, OP_VOID);
4052 SLW (addr, a);
4053 trace_output_32 (sd, addr);
4056 /* stord. */
4057 void
4058 OP_66_7 (SIM_DESC sd, SIM_CPU *cpu)
4060 uint32_t addr, a = GPR32 (OP[0]);
4061 trace_input ("stord", OP_REGP, OP_R_INDEX8_ABS20, OP_VOID);
4063 if (OP[1] == 0)
4064 addr = (GPR32 (12)) + OP[2];
4065 else
4066 addr = (GPR32 (13)) + OP[2];
4068 SLW (addr, a);
4069 trace_output_32 (sd, addr);
4072 /* stord. */
4073 void
4074 OP_E_4 (SIM_DESC sd, SIM_CPU *cpu)
4076 uint32_t a = GPR32 (OP[0]);
4077 uint32_t addr = (GPR32 (OP[2])) + OP[1];
4078 trace_input ("stord", OP_REGP, OP_RP_BASE_DISPE4, OP_VOID);
4079 SLW (addr, a);
4080 trace_output_32 (sd, addr);
4083 /* stord. */
4084 void
4085 OP_EE_8 (SIM_DESC sd, SIM_CPU *cpu)
4087 uint32_t a = GPR32 (OP[0]);
4088 uint32_t addr = (GPR32 (OP[2])) + OP[1];
4089 trace_input ("stord", OP_REGP, OP_RP_INDEX_DISP0, OP_VOID);
4090 SLW (addr, a);
4091 trace_output_32 (sd, addr);
4094 /* stord. */
4095 void
4096 OP_31A_A (SIM_DESC sd, SIM_CPU *cpu)
4098 uint32_t a = GPR32 (OP[0]);
4099 uint32_t addr = (GPR32 (OP[2])) + OP[1];
4100 trace_input ("stord", OP_REGP, OP_RP_INDEX_DISP14, OP_VOID);
4101 SLW (addr, a);
4102 trace_output_32 (sd, addr);
4105 /* stord. */
4106 void
4107 OP_198_14 (SIM_DESC sd, SIM_CPU *cpu)
4109 uint32_t a = GPR32 (OP[0]);
4110 uint32_t addr = (GPR32 (OP[2])) + OP[1];
4111 trace_input ("stord", OP_REGP, OP_R_BASE_DISPE20, OP_VOID);
4112 SLW (addr, a);
4113 trace_output_32 (sd, addr);
4116 /* stord. */
4117 void
4118 OP_138_14 (SIM_DESC sd, SIM_CPU *cpu)
4120 uint32_t a = GPR32 (OP[0]);
4121 uint32_t addr = (GPR32 (OP[2])) + OP[1];
4122 trace_input ("stord", OP_REGP, OP_R_BASE_DISPS20, OP_VOID);
4123 SLW (addr, a);
4124 trace_output_32 (sd, addr);
4127 /* stord. */
4128 void
4129 OP_EF_8 (SIM_DESC sd, SIM_CPU *cpu)
4131 uint32_t a = GPR32 (OP[0]);
4132 uint32_t addr = (GPR32 (OP[2])) + OP[1];
4133 trace_input ("stord", OP_REGP, OP_RP_BASE_DISP16, OP_VOID);
4134 SLW (addr, a);
4135 trace_output_32 (sd, addr);
4138 /* stord. */
4139 void
4140 OP_139_14 (SIM_DESC sd, SIM_CPU *cpu)
4142 uint32_t a = GPR32 (OP[0]);
4143 uint32_t addr = (GPR32 (OP[2])) + OP[1];
4144 trace_input ("stord", OP_REGP, OP_RP_BASE_DISPS20, OP_VOID);
4145 SLW (addr, a);
4146 trace_output_32 (sd, addr);
4149 /* stord. */
4150 void
4151 OP_199_14 (SIM_DESC sd, SIM_CPU *cpu)
4153 uint32_t a = GPR32 (OP[0]);
4154 uint32_t addr = (GPR32 (OP[2])) + OP[1];
4155 trace_input ("stord", OP_REGP, OP_RP_BASE_DISPE20, OP_VOID);
4156 SLW (addr, a);
4157 trace_output_32 (sd, addr);
4160 /* stord. */
4161 void
4162 OP_13A_14 (SIM_DESC sd, SIM_CPU *cpu)
4164 uint32_t a = GPR32 (OP[0]);
4165 uint32_t addr = (GPR32 (OP[2])) + OP[1];
4166 trace_input ("stord", OP_REGP, OP_RP_INDEX_DISPS20, OP_VOID);
4167 SLW (addr, a);
4168 trace_output_32 (sd, addr);
4171 /* macqu. */
4172 void
4173 OP_14D_14 (SIM_DESC sd, SIM_CPU *cpu)
4175 int32_t tmp;
4176 int16_t src1, src2;
4177 trace_input ("macuw", OP_REG, OP_REG, OP_REGP);
4178 src1 = GPR (OP[0]);
4179 src2 = GPR (OP[1]);
4180 tmp = src1 * src2;
4181 /*REVISIT FOR SATURATION and Q FORMAT. */
4182 SET_GPR32 (OP[2], tmp);
4183 trace_output_32 (sd, tmp);
4186 /* macuw. */
4187 void
4188 OP_14E_14 (SIM_DESC sd, SIM_CPU *cpu)
4190 uint32_t tmp;
4191 uint16_t src1, src2;
4192 trace_input ("macuw", OP_REG, OP_REG, OP_REGP);
4193 src1 = GPR (OP[0]);
4194 src2 = GPR (OP[1]);
4195 tmp = src1 * src2;
4196 /*REVISIT FOR SATURATION. */
4197 SET_GPR32 (OP[2], tmp);
4198 trace_output_32 (sd, tmp);
4201 /* macsw. */
4202 void
4203 OP_14F_14 (SIM_DESC sd, SIM_CPU *cpu)
4205 int32_t tmp;
4206 int16_t src1, src2;
4207 trace_input ("macsw", OP_REG, OP_REG, OP_REGP);
4208 src1 = GPR (OP[0]);
4209 src2 = GPR (OP[1]);
4210 tmp = src1 * src2;
4211 /*REVISIT FOR SATURATION. */
4212 SET_GPR32 (OP[2], tmp);
4213 trace_output_32 (sd, tmp);
4217 /* mulb. */
4218 void
4219 OP_64_8 (SIM_DESC sd, SIM_CPU *cpu)
4221 int16_t tmp;
4222 int8_t a = (OP[0]) & 0xff;
4223 int8_t b = (GPR (OP[1])) & 0xff;
4224 trace_input ("mulb", OP_CONSTANT4_1, OP_REG, OP_VOID);
4225 tmp = (a * b) & 0xff;
4226 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
4227 trace_output_16 (sd, tmp);
4230 /* mulb. */
4231 void
4232 OP_64B_C (SIM_DESC sd, SIM_CPU *cpu)
4234 int16_t tmp;
4235 int8_t a = (OP[0]) & 0xff, b = (GPR (OP[1])) & 0xff;
4236 trace_input ("mulb", OP_CONSTANT4, OP_REG, OP_VOID);
4237 tmp = (a * b) & 0xff;
4238 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
4239 trace_output_16 (sd, tmp);
4243 /* mulb. */
4244 void
4245 OP_65_8 (SIM_DESC sd, SIM_CPU *cpu)
4247 int16_t tmp;
4248 int8_t a = (GPR (OP[0])) & 0xff, b = (GPR (OP[1])) & 0xff;
4249 trace_input ("mulb", OP_REG, OP_REG, OP_VOID);
4250 tmp = (a * b) & 0xff;
4251 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
4252 trace_output_16 (sd, tmp);
4256 /* mulw. */
4257 void
4258 OP_66_8 (SIM_DESC sd, SIM_CPU *cpu)
4260 int32_t tmp;
4261 uint16_t a = OP[0];
4262 int16_t b = (GPR (OP[1]));
4263 trace_input ("mulw", OP_CONSTANT4_1, OP_REG, OP_VOID);
4264 tmp = (a * b) & 0xffff;
4265 SET_GPR (OP[1], tmp);
4266 trace_output_32 (sd, tmp);
4269 /* mulw. */
4270 void
4271 OP_66B_C (SIM_DESC sd, SIM_CPU *cpu)
4273 int32_t tmp;
4274 int16_t a = OP[0], b = (GPR (OP[1]));
4275 trace_input ("mulw", OP_CONSTANT4, OP_REG, OP_VOID);
4276 tmp = (a * b) & 0xffff;
4277 SET_GPR (OP[1], tmp);
4278 trace_output_32 (sd, tmp);
4282 /* mulw. */
4283 void
4284 OP_67_8 (SIM_DESC sd, SIM_CPU *cpu)
4286 int32_t tmp;
4287 int16_t a = (GPR (OP[0])), b = (GPR (OP[1]));
4288 trace_input ("mulw", OP_REG, OP_REG, OP_VOID);
4289 tmp = (a * b) & 0xffff;
4290 SET_GPR (OP[1], tmp);
4291 trace_output_32 (sd, tmp);
4295 /* mulsb. */
4296 void
4297 OP_B_8 (SIM_DESC sd, SIM_CPU *cpu)
4299 int16_t tmp;
4300 int8_t a = (GPR (OP[0])) & 0xff, b = (GPR (OP[1])) & 0xff;
4301 trace_input ("mulsb", OP_REG, OP_REG, OP_VOID);
4302 tmp = a * b;
4303 SET_GPR (OP[1], tmp);
4304 trace_output_32 (sd, tmp);
4307 /* mulsw. */
4308 void
4309 OP_62_8 (SIM_DESC sd, SIM_CPU *cpu)
4311 int32_t tmp;
4312 int16_t a = (GPR (OP[0])), b = (GPR (OP[1]));
4313 trace_input ("mulsw", OP_REG, OP_REGP, OP_VOID);
4314 tmp = a * b;
4315 SET_GPR32 (OP[1], tmp);
4316 trace_output_32 (sd, tmp);
4319 /* muluw. */
4320 void
4321 OP_63_8 (SIM_DESC sd, SIM_CPU *cpu)
4323 uint32_t tmp;
4324 uint16_t a = (GPR (OP[0])), b = (GPR (OP[1]));
4325 trace_input ("muluw", OP_REG, OP_REGP, OP_VOID);
4326 tmp = a * b;
4327 SET_GPR32 (OP[1], tmp);
4328 trace_output_32 (sd, tmp);
4332 /* nop. */
4333 void
4334 OP_2C00_10 (SIM_DESC sd, SIM_CPU *cpu)
4336 trace_input ("nop", OP_VOID, OP_VOID, OP_VOID);
4338 #if 0
4339 ins_type_counters[ (int)State.ins_type ]--; /* don't count nops as normal instructions */
4340 switch (State.ins_type)
4342 default:
4343 ins_type_counters[ (int)INS_UNKNOWN ]++;
4344 break;
4347 EXCEPTION (SIM_SIGTRAP);
4348 #endif
4349 trace_output_void (sd);
4353 /* orb. */
4354 void
4355 OP_24_8 (SIM_DESC sd, SIM_CPU *cpu)
4357 uint8_t tmp, a = (OP[0]) & 0xff, b = (GPR (OP[1])) & 0xff;
4358 trace_input ("orb", OP_CONSTANT4, OP_REG, OP_VOID);
4359 tmp = a | b;
4360 SET_GPR (OP[1], ((GPR (OP[1]) | tmp)));
4361 trace_output_16 (sd, tmp);
4364 /* orb. */
4365 void
4366 OP_24B_C (SIM_DESC sd, SIM_CPU *cpu)
4368 uint8_t tmp, a = (OP[0]) & 0xff, b = (GPR (OP[1])) & 0xff;
4369 trace_input ("orb", OP_CONSTANT16, OP_REG, OP_VOID);
4370 tmp = a | b;
4371 SET_GPR (OP[1], ((GPR (OP[1]) | tmp)));
4372 trace_output_16 (sd, tmp);
4375 /* orb. */
4376 void
4377 OP_25_8 (SIM_DESC sd, SIM_CPU *cpu)
4379 uint8_t tmp, a = (GPR (OP[0])) & 0xff, b = (GPR (OP[1])) & 0xff;
4380 trace_input ("orb", OP_REG, OP_REG, OP_VOID);
4381 tmp = a | b;
4382 SET_GPR (OP[1], ((GPR (OP[1]) | tmp)));
4383 trace_output_16 (sd, tmp);
4386 /* orw. */
4387 void
4388 OP_26_8 (SIM_DESC sd, SIM_CPU *cpu)
4390 uint16_t tmp, a = (OP[0]), b = (GPR (OP[1]));
4391 trace_input ("orw", OP_CONSTANT4, OP_REG, OP_VOID);
4392 tmp = a | b;
4393 SET_GPR (OP[1], tmp);
4394 trace_output_16 (sd, tmp);
4398 /* orw. */
4399 void
4400 OP_26B_C (SIM_DESC sd, SIM_CPU *cpu)
4402 uint16_t tmp, a = (OP[0]), b = (GPR (OP[1]));
4403 trace_input ("orw", OP_CONSTANT16, OP_REG, OP_VOID);
4404 tmp = a | b;
4405 SET_GPR (OP[1], tmp);
4406 trace_output_16 (sd, tmp);
4409 /* orw. */
4410 void
4411 OP_27_8 (SIM_DESC sd, SIM_CPU *cpu)
4413 uint16_t tmp, a = (GPR (OP[0])), b = (GPR (OP[1]));
4414 trace_input ("orw", OP_REG, OP_REG, OP_VOID);
4415 tmp = a | b;
4416 SET_GPR (OP[1], tmp);
4417 trace_output_16 (sd, tmp);
4421 /* lshb. */
4422 void
4423 OP_13_9 (SIM_DESC sd, SIM_CPU *cpu)
4425 uint16_t a = OP[0];
4426 uint16_t tmp, b = (GPR (OP[1])) & 0xFF;
4427 trace_input ("lshb", OP_CONSTANT4, OP_REG, OP_VOID);
4428 /* A positive count specifies a shift to the left;
4429 * A negative count specifies a shift to the right. */
4430 if (sign_flag)
4431 tmp = b >> a;
4432 else
4433 tmp = b << a;
4435 sign_flag = 0; /* Reset sign_flag. */
4437 SET_GPR (OP[1], ((tmp & 0xFF) | ((GPR (OP[1])) & 0xFF00)));
4438 trace_output_16 (sd, tmp);
4441 /* lshb. */
4442 void
4443 OP_44_8 (SIM_DESC sd, SIM_CPU *cpu)
4445 uint16_t a = (GPR (OP[0])) & 0xff;
4446 uint16_t tmp, b = (GPR (OP[1])) & 0xFF;
4447 trace_input ("lshb", OP_REG, OP_REG, OP_VOID);
4448 if (a & ((long)1 << 3))
4450 sign_flag = 1;
4451 a = ~(a) + 1;
4453 a = (unsigned int) (a & 0x7);
4455 /* A positive count specifies a shift to the left;
4456 * A negative count specifies a shift to the right. */
4457 if (sign_flag)
4458 tmp = b >> a;
4459 else
4460 tmp = b << a;
4462 sign_flag = 0; /* Reset sign_flag. */
4463 SET_GPR (OP[1], ((tmp & 0xFF) | ((GPR (OP[1])) & 0xFF00)));
4464 trace_output_16 (sd, tmp);
4467 /* lshw. */
4468 void
4469 OP_46_8 (SIM_DESC sd, SIM_CPU *cpu)
4471 uint16_t tmp, b = GPR (OP[1]);
4472 int16_t a = GPR (OP[0]);
4473 trace_input ("lshw", OP_REG, OP_REG, OP_VOID);
4474 if (a & ((long)1 << 4))
4476 sign_flag = 1;
4477 a = ~(a) + 1;
4479 a = (unsigned int) (a & 0xf);
4481 /* A positive count specifies a shift to the left;
4482 * A negative count specifies a shift to the right. */
4483 if (sign_flag)
4484 tmp = b >> a;
4485 else
4486 tmp = b << a;
4488 sign_flag = 0; /* Reset sign_flag. */
4489 SET_GPR (OP[1], (tmp & 0xffff));
4490 trace_output_16 (sd, tmp);
4493 /* lshw. */
4494 void
4495 OP_49_8 (SIM_DESC sd, SIM_CPU *cpu)
4497 uint16_t tmp, b = GPR (OP[1]);
4498 uint16_t a = OP[0];
4499 trace_input ("lshw", OP_CONSTANT5, OP_REG, OP_VOID);
4500 /* A positive count specifies a shift to the left;
4501 * A negative count specifies a shift to the right. */
4502 if (sign_flag)
4503 tmp = b >> a;
4504 else
4505 tmp = b << a;
4507 sign_flag = 0; /* Reset sign_flag. */
4508 SET_GPR (OP[1], (tmp & 0xffff));
4509 trace_output_16 (sd, tmp);
4512 /* lshd. */
4513 void
4514 OP_25_7 (SIM_DESC sd, SIM_CPU *cpu)
4516 uint32_t tmp, b = GPR32 (OP[1]);
4517 uint16_t a = OP[0];
4518 trace_input ("lshd", OP_CONSTANT6, OP_REGP, OP_VOID);
4519 /* A positive count specifies a shift to the left;
4520 * A negative count specifies a shift to the right. */
4521 if (sign_flag)
4522 tmp = b >> a;
4523 else
4524 tmp = b << a;
4526 sign_flag = 0; /* Reset sign flag. */
4528 SET_GPR32 (OP[1], tmp);
4529 trace_output_32 (sd, tmp);
4532 /* lshd. */
4533 void
4534 OP_47_8 (SIM_DESC sd, SIM_CPU *cpu)
4536 uint32_t tmp, b = GPR32 (OP[1]);
4537 uint16_t a = GPR (OP[0]);
4538 trace_input ("lshd", OP_REG, OP_REGP, OP_VOID);
4539 if (a & ((long)1 << 5))
4541 sign_flag = 1;
4542 a = ~(a) + 1;
4544 a = (unsigned int) (a & 0x1f);
4545 /* A positive count specifies a shift to the left;
4546 * A negative count specifies a shift to the right. */
4547 if (sign_flag)
4548 tmp = b >> a;
4549 else
4550 tmp = b << a;
4552 sign_flag = 0; /* Reset sign flag. */
4554 SET_GPR32 (OP[1], tmp);
4555 trace_output_32 (sd, tmp);
4558 /* ashub. */
4559 void
4560 OP_80_9 (SIM_DESC sd, SIM_CPU *cpu)
4562 uint16_t a = OP[0];
4563 int8_t tmp, b = (GPR (OP[1])) & 0xFF;
4564 trace_input ("ashub", OP_CONSTANT4, OP_REG, OP_VOID);
4565 /* A positive count specifies a shift to the left;
4566 * A negative count specifies a shift to the right. */
4567 if (sign_flag)
4568 tmp = b >> a;
4569 else
4570 tmp = b << a;
4572 sign_flag = 0; /* Reset sign flag. */
4574 SET_GPR (OP[1], ((tmp & 0xFF) | ((GPR (OP[1])) & 0xff00)));
4575 trace_output_16 (sd, tmp);
4578 /* ashub. */
4579 void
4580 OP_81_9 (SIM_DESC sd, SIM_CPU *cpu)
4582 uint16_t a = OP[0];
4583 int8_t tmp, b = (GPR (OP[1])) & 0xFF;
4584 trace_input ("ashub", OP_CONSTANT4, OP_REG, OP_VOID);
4585 /* A positive count specifies a shift to the left;
4586 * A negative count specifies a shift to the right. */
4587 if (sign_flag)
4588 tmp = b >> a;
4589 else
4590 tmp = b << a;
4592 sign_flag = 0; /* Reset sign flag. */
4594 SET_GPR (OP[1], ((tmp & 0xFF) | ((GPR (OP[1])) & 0xFF00)));
4595 trace_output_16 (sd, tmp);
4599 /* ashub. */
4600 void
4601 OP_41_8 (SIM_DESC sd, SIM_CPU *cpu)
4603 int16_t a = (GPR (OP[0]));
4604 int8_t tmp, b = (GPR (OP[1])) & 0xFF;
4605 trace_input ("ashub", OP_REG, OP_REG, OP_VOID);
4607 if (a & ((long)1 << 3))
4609 sign_flag = 1;
4610 a = ~(a) + 1;
4612 a = (unsigned int) (a & 0x7);
4614 /* A positive count specifies a shift to the left;
4615 * A negative count specifies a shift to the right. */
4616 if (sign_flag)
4617 tmp = b >> a;
4618 else
4619 tmp = b << a;
4621 sign_flag = 0; /* Reset sign flag. */
4623 SET_GPR (OP[1], ((tmp & 0xFF) | ((GPR (OP[1])) & 0xFF00)));
4624 trace_output_16 (sd, tmp);
4628 /* ashuw. */
4629 void
4630 OP_42_8 (SIM_DESC sd, SIM_CPU *cpu)
4632 int16_t tmp, b = GPR (OP[1]);
4633 uint16_t a = OP[0];
4634 trace_input ("ashuw", OP_CONSTANT5, OP_REG, OP_VOID);
4635 /* A positive count specifies a shift to the left;
4636 * A negative count specifies a shift to the right. */
4637 if (sign_flag)
4638 tmp = b >> a;
4639 else
4640 tmp = b << a;
4642 sign_flag = 0; /* Reset sign flag. */
4644 SET_GPR (OP[1], (tmp & 0xffff));
4645 trace_output_16 (sd, tmp);
4648 /* ashuw. */
4649 void
4650 OP_43_8 (SIM_DESC sd, SIM_CPU *cpu)
4652 int16_t tmp, b = GPR (OP[1]);
4653 uint16_t a = OP[0];
4654 trace_input ("ashuw", OP_CONSTANT5, OP_REG, OP_VOID);
4655 /* A positive count specifies a shift to the left;
4656 * A negative count specifies a shift to the right. */
4657 if (sign_flag)
4658 tmp = b >> a;
4659 else
4660 tmp = b << a;
4662 sign_flag = 0; /* Reset sign flag. */
4663 SET_GPR (OP[1], (tmp & 0xffff));
4664 trace_output_16 (sd, tmp);
4667 /* ashuw. */
4668 void
4669 OP_45_8 (SIM_DESC sd, SIM_CPU *cpu)
4671 int16_t tmp;
4672 int16_t a = GPR (OP[0]), b = GPR (OP[1]);
4673 trace_input ("ashuw", OP_REG, OP_REG, OP_VOID);
4675 if (a & ((long)1 << 4))
4677 sign_flag = 1;
4678 a = ~(a) + 1;
4680 a = (unsigned int) (a & 0xf);
4681 /* A positive count specifies a shift to the left;
4682 * A negative count specifies a shift to the right. */
4684 if (sign_flag)
4685 tmp = b >> a;
4686 else
4687 tmp = b << a;
4689 sign_flag = 0; /* Reset sign flag. */
4690 SET_GPR (OP[1], (tmp & 0xffff));
4691 trace_output_16 (sd, tmp);
4694 /* ashud. */
4695 void
4696 OP_26_7 (SIM_DESC sd, SIM_CPU *cpu)
4698 int32_t tmp,b = GPR32 (OP[1]);
4699 uint32_t a = OP[0];
4700 trace_input ("ashud", OP_CONSTANT6, OP_REGP, OP_VOID);
4701 /* A positive count specifies a shift to the left;
4702 * A negative count specifies a shift to the right. */
4703 if (sign_flag)
4704 tmp = b >> a;
4705 else
4706 tmp = b << a;
4708 sign_flag = 0; /* Reset sign flag. */
4709 SET_GPR32 (OP[1], tmp);
4710 trace_output_32 (sd, tmp);
4713 /* ashud. */
4714 void
4715 OP_27_7 (SIM_DESC sd, SIM_CPU *cpu)
4717 int32_t tmp;
4718 int32_t a = OP[0], b = GPR32 (OP[1]);
4719 trace_input ("ashud", OP_CONSTANT6, OP_REGP, OP_VOID);
4720 /* A positive count specifies a shift to the left;
4721 * A negative count specifies a shift to the right. */
4722 if (sign_flag)
4723 tmp = b >> a;
4724 else
4725 tmp = b << a;
4727 sign_flag = 0; /* Reset sign flag. */
4728 SET_GPR32 (OP[1], tmp);
4729 trace_output_32 (sd, tmp);
4732 /* ashud. */
4733 void
4734 OP_48_8 (SIM_DESC sd, SIM_CPU *cpu)
4736 int32_t tmp;
4737 int32_t a = GPR32 (OP[0]), b = GPR32 (OP[1]);
4738 trace_input ("ashud", OP_REGP, OP_REGP, OP_VOID);
4740 if (a & ((long)1 << 5))
4742 sign_flag = 1;
4743 a = ~(a) + 1;
4745 a = (unsigned int) (a & 0x1f);
4746 /* A positive count specifies a shift to the left;
4747 * A negative count specifies a shift to the right. */
4748 if (sign_flag)
4749 tmp = b >> a;
4750 else
4751 tmp = b << a;
4753 sign_flag = 0; /* Reset sign flag. */
4754 SET_GPR32 (OP[1], tmp);
4755 trace_output_32 (sd, tmp);
4759 /* storm. */
4760 void
4761 OP_16_D (SIM_DESC sd, SIM_CPU *cpu)
4763 uint32_t addr = GPR (1);
4764 uint16_t count = OP[0], reg = 2;
4765 trace_input ("storm", OP_CONSTANT4, OP_VOID, OP_VOID);
4766 if ((addr & 1))
4768 trace_output_void (sd);
4769 EXCEPTION (SIM_SIGBUS);
4772 while (count)
4774 SW (addr, (GPR (reg)));
4775 addr +=2;
4776 --count;
4777 reg++;
4778 if (reg == 6) reg = 8;
4781 SET_GPR (1, addr);
4783 trace_output_void (sd);
4787 /* stormp. */
4788 void
4789 OP_17_D (SIM_DESC sd, SIM_CPU *cpu)
4791 uint32_t addr = GPR32 (6);
4792 uint16_t count = OP[0], reg = 2;
4793 trace_input ("stormp", OP_CONSTANT4, OP_VOID, OP_VOID);
4794 if ((addr & 1))
4796 trace_output_void (sd);
4797 EXCEPTION (SIM_SIGBUS);
4800 while (count)
4802 SW (addr, (GPR (reg)));
4803 addr +=2;
4804 --count;
4805 reg++;
4806 if (reg == 6) reg = 8;
4809 SET_GPR32 (6, addr);
4810 trace_output_void (sd);
4813 /* subb. */
4814 void
4815 OP_38_8 (SIM_DESC sd, SIM_CPU *cpu)
4817 uint8_t a = OP[0];
4818 uint8_t b = (GPR (OP[1])) & 0xff;
4819 uint16_t tmp = (~a + 1 + b) & 0xff;
4820 trace_input ("subb", OP_CONSTANT4, OP_REG, OP_VOID);
4821 /* see ../common/sim-alu.h for a more extensive discussion on how to
4822 compute the carry/overflow bits. */
4823 SET_PSR_C (tmp > 0xff);
4824 SET_PSR_F (((a & 0x80) != (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
4825 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
4826 trace_output_16 (sd, tmp);
4829 /* subb. */
4830 void
4831 OP_38B_C (SIM_DESC sd, SIM_CPU *cpu)
4833 uint8_t a = OP[0] & 0xFF;
4834 uint8_t b = (GPR (OP[1])) & 0xFF;
4835 uint16_t tmp = (~a + 1 + b) & 0xFF;
4836 trace_input ("subb", OP_CONSTANT16, OP_REG, OP_VOID);
4837 /* see ../common/sim-alu.h for a more extensive discussion on how to
4838 compute the carry/overflow bits. */
4839 SET_PSR_C (tmp > 0xff);
4840 SET_PSR_F (((a & 0x80) != (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
4841 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
4842 trace_output_16 (sd, tmp);
4845 /* subb. */
4846 void
4847 OP_39_8 (SIM_DESC sd, SIM_CPU *cpu)
4849 uint8_t a = (GPR (OP[0])) & 0xFF;
4850 uint8_t b = (GPR (OP[1])) & 0xFF;
4851 uint16_t tmp = (~a + 1 + b) & 0xff;
4852 trace_input ("subb", OP_REG, OP_REG, OP_VOID);
4853 /* see ../common/sim-alu.h for a more extensive discussion on how to
4854 compute the carry/overflow bits. */
4855 SET_PSR_C (tmp > 0xff);
4856 SET_PSR_F (((a & 0x80) != (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
4857 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
4858 trace_output_16 (sd, tmp);
4861 /* subw. */
4862 void
4863 OP_3A_8 (SIM_DESC sd, SIM_CPU *cpu)
4865 uint16_t a = OP[0];
4866 uint16_t b = GPR (OP[1]);
4867 uint16_t tmp = (~a + 1 + b);
4868 trace_input ("subw", OP_CONSTANT4, OP_REG, OP_VOID);
4869 /* see ../common/sim-alu.h for a more extensive discussion on how to
4870 compute the carry/overflow bits. */
4871 SET_PSR_C (tmp > 0xffff);
4872 SET_PSR_F (((a & 0x8000) != (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
4873 SET_GPR (OP[1], tmp);
4874 trace_output_16 (sd, tmp);
4877 /* subw. */
4878 void
4879 OP_3AB_C (SIM_DESC sd, SIM_CPU *cpu)
4881 uint16_t a = OP[0];
4882 uint16_t b = GPR (OP[1]);
4883 uint32_t tmp = (~a + 1 + b);
4884 trace_input ("subw", OP_CONSTANT16, OP_REG, OP_VOID);
4885 /* see ../common/sim-alu.h for a more extensive discussion on how to
4886 compute the carry/overflow bits. */
4887 SET_PSR_C (tmp > 0xffff);
4888 SET_PSR_F (((a & 0x8000) != (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
4889 SET_GPR (OP[1], tmp & 0xffff);
4890 trace_output_16 (sd, tmp);
4893 /* subw. */
4894 void
4895 OP_3B_8 (SIM_DESC sd, SIM_CPU *cpu)
4897 uint16_t a = GPR (OP[0]);
4898 uint16_t b = GPR (OP[1]);
4899 uint32_t tmp = (~a + 1 + b);
4900 trace_input ("subw", OP_REG, OP_REG, OP_VOID);
4901 /* see ../common/sim-alu.h for a more extensive discussion on how to
4902 compute the carry/overflow bits. */
4903 SET_PSR_C (tmp > 0xffff);
4904 SET_PSR_F (((a & 0x8000) != (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
4905 SET_GPR (OP[1], tmp & 0xffff);
4906 trace_output_16 (sd, tmp);
4909 /* subcb. */
4910 void
4911 OP_3C_8 (SIM_DESC sd, SIM_CPU *cpu)
4913 uint8_t a = OP[0];
4914 uint8_t b = (GPR (OP[1])) & 0xff;
4915 //uint16_t tmp1 = a + 1;
4916 uint16_t tmp1 = a + (PSR_C);
4917 uint16_t tmp = (~tmp1 + 1 + b);
4918 trace_input ("subcb", OP_CONSTANT4, OP_REG, OP_VOID);
4919 /* see ../common/sim-alu.h for a more extensive discussion on how to
4920 compute the carry/overflow bits. */
4921 SET_PSR_C (tmp > 0xff);
4922 SET_PSR_F (((a & 0x80) != (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
4923 SET_GPR (OP[1], tmp);
4924 trace_output_16 (sd, tmp);
4927 /* subcb. */
4928 void
4929 OP_3CB_C (SIM_DESC sd, SIM_CPU *cpu)
4931 uint16_t a = OP[0];
4932 uint16_t b = (GPR (OP[1])) & 0xff;
4933 //uint16_t tmp1 = a + 1;
4934 uint16_t tmp1 = a + (PSR_C);
4935 uint16_t tmp = (~tmp1 + 1 + b);
4936 trace_input ("subcb", OP_CONSTANT16, OP_REG, OP_VOID);
4937 /* see ../common/sim-alu.h for a more extensive discussion on how to
4938 compute the carry/overflow bits. */
4939 SET_PSR_C (tmp > 0xff);
4940 SET_PSR_F (((a & 0x80) != (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
4941 SET_GPR (OP[1], tmp);
4942 trace_output_16 (sd, tmp);
4945 /* subcb. */
4946 void
4947 OP_3D_8 (SIM_DESC sd, SIM_CPU *cpu)
4949 uint16_t a = (GPR (OP[0])) & 0xff;
4950 uint16_t b = (GPR (OP[1])) & 0xff;
4951 uint16_t tmp1 = a + (PSR_C);
4952 uint16_t tmp = (~tmp1 + 1 + b);
4953 trace_input ("subcb", OP_REG, OP_REG, OP_VOID);
4954 /* see ../common/sim-alu.h for a more extensive discussion on how to
4955 compute the carry/overflow bits. */
4956 SET_PSR_C (tmp > 0xff);
4957 SET_PSR_F (((a & 0x80) != (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
4958 SET_GPR (OP[1], tmp);
4959 trace_output_16 (sd, tmp);
4962 /* subcw. */
4963 void
4964 OP_3E_8 (SIM_DESC sd, SIM_CPU *cpu)
4966 uint16_t a = OP[0], b = (GPR (OP[1]));
4967 uint16_t tmp1 = a + (PSR_C);
4968 uint16_t tmp = (~tmp1 + 1 + b);
4969 trace_input ("subcw", OP_CONSTANT4, OP_REG, OP_VOID);
4970 /* see ../common/sim-alu.h for a more extensive discussion on how to
4971 compute the carry/overflow bits. */
4972 SET_PSR_C (tmp > 0xffff);
4973 SET_PSR_F (((a & 0x8000) != (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
4974 SET_GPR (OP[1], tmp);
4975 trace_output_16 (sd, tmp);
4978 /* subcw. */
4979 void
4980 OP_3EB_C (SIM_DESC sd, SIM_CPU *cpu)
4982 int16_t a = OP[0];
4983 uint16_t b = GPR (OP[1]);
4984 uint16_t tmp1 = a + (PSR_C);
4985 uint16_t tmp = (~tmp1 + 1 + b);
4986 trace_input ("subcw", OP_CONSTANT16, OP_REG, OP_VOID);
4987 /* see ../common/sim-alu.h for a more extensive discussion on how to
4988 compute the carry/overflow bits. */
4989 SET_PSR_C (tmp > 0xffff);
4990 SET_PSR_F (((a & 0x8000) != (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
4991 SET_GPR (OP[1], tmp);
4992 trace_output_16 (sd, tmp);
4995 /* subcw. */
4996 void
4997 OP_3F_8 (SIM_DESC sd, SIM_CPU *cpu)
4999 uint16_t a = (GPR (OP[0])), b = (GPR (OP[1]));
5000 uint16_t tmp1 = a + (PSR_C);
5001 uint16_t tmp = (~tmp1 + 1 + b);
5002 trace_input ("subcw", OP_REG, OP_REG, OP_VOID);
5003 /* see ../common/sim-alu.h for a more extensive discussion on how to
5004 compute the carry/overflow bits. */
5005 SET_PSR_C (tmp > 0xffff);
5006 SET_PSR_F (((a & 0x8000) != (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
5007 SET_GPR (OP[1], tmp);
5008 trace_output_16 (sd, tmp);
5011 /* subd. */
5012 void
5013 OP_3_C (SIM_DESC sd, SIM_CPU *cpu)
5015 int32_t a = OP[0];
5016 uint32_t b = GPR32 (OP[1]);
5017 uint32_t tmp = (~a + 1 + b);
5018 trace_input ("subd", OP_CONSTANT32, OP_REGP, OP_VOID);
5019 /* see ../common/sim-alu.h for a more extensive discussion on how to
5020 compute the carry/overflow bits. */
5021 SET_PSR_C (tmp > 0xffffffff);
5022 SET_PSR_F (((a & 0x80000000) != (b & 0x80000000)) &&
5023 ((b & 0x80000000) != (tmp & 0x80000000)));
5024 SET_GPR32 (OP[1], tmp);
5025 trace_output_32 (sd, tmp);
5028 /* subd. */
5029 void
5030 OP_14C_14 (SIM_DESC sd, SIM_CPU *cpu)
5032 uint32_t a = GPR32 (OP[0]);
5033 uint32_t b = GPR32 (OP[1]);
5034 uint32_t tmp = (~a + 1 + b);
5035 trace_input ("subd", OP_REGP, OP_REGP, OP_VOID);
5036 /* see ../common/sim-alu.h for a more extensive discussion on how to
5037 compute the carry/overflow bits. */
5038 SET_PSR_C (tmp > 0xffffffff);
5039 SET_PSR_F (((a & 0x80000000) != (b & 0x80000000)) &&
5040 ((b & 0x80000000) != (tmp & 0x80000000)));
5041 SET_GPR32 (OP[1], tmp);
5042 trace_output_32 (sd, tmp);
5045 /* excp. */
5046 void
5047 OP_C_C (SIM_DESC sd, SIM_CPU *cpu)
5049 host_callback *cb = STATE_CALLBACK (sd);
5050 uint32_t tmp;
5051 uint16_t a;
5052 trace_input ("excp", OP_CONSTANT4, OP_VOID, OP_VOID);
5053 switch (OP[0])
5055 default:
5056 #if (DEBUG & DEBUG_TRAP) == 0
5058 #if 0
5059 uint16_t vec = OP[0] + TRAP_VECTOR_START;
5060 SET_BPC (PC + 1);
5061 SET_BPSR (PSR);
5062 SET_PSR (PSR & PSR_SM_BIT);
5063 JMP (vec);
5064 break;
5065 #endif
5067 #else /* if debugging use trap to print registers */
5069 int i;
5070 static int first_time = 1;
5072 if (first_time)
5074 first_time = 0;
5075 sim_io_printf (sd, "Trap # PC ");
5076 for (i = 0; i < 16; i++)
5077 sim_io_printf (sd, " %sr%d", (i > 9) ? "" : " ", i);
5078 sim_io_printf (sd, " a0 a1 f0 f1 c\n");
5081 sim_io_printf (sd, "Trap %2d 0x%.4x:", (int)OP[0], (int)PC);
5083 for (i = 0; i < 16; i++)
5084 sim_io_printf (sd, " %.4x", (int) GPR (i));
5086 for (i = 0; i < 2; i++)
5087 sim_io_printf (sd, " %.2x%.8lx",
5088 ((int)(ACC (i) >> 32) & 0xff),
5089 ((unsigned long) ACC (i)) & 0xffffffff);
5091 sim_io_printf (sd, " %d %d %d\n",
5092 PSR_F != 0, PSR_F != 0, PSR_C != 0);
5093 sim_io_flush_stdout (sd);
5094 break;
5096 #endif
5097 case 8: /* new system call trap */
5098 /* Trap 8 is used for simulating low-level I/O */
5100 uint32_t result = 0;
5101 errno = 0;
5103 /* Registers passed to trap 0. */
5105 #define FUNC GPR (0) /* function number. */
5106 #define PARM1 GPR (2) /* optional parm 1. */
5107 #define PARM2 GPR (3) /* optional parm 2. */
5108 #define PARM3 GPR (4) /* optional parm 3. */
5109 #define PARM4 GPR (5) /* optional parm 4. */
5111 /* Registers set by trap 0 */
5113 #define RETVAL(X) do { result = (0xffff & (X));SET_GPR (0, result);} while (0)
5114 #define RETVAL32(X) do { result = (X); SET_GPR32 (0, result);} while (0)
5115 #define RETERR(X) SET_GPR (4, (X)) /* return error code. */
5117 /* Turn a pointer in a register into a pointer into real memory. */
5119 #define MEMPTR(x) sim_core_trans_addr (sd, cpu, read_map, x)
5121 switch (FUNC)
5123 #if !defined(__GO32__) && !defined(_WIN32)
5124 case TARGET_NEWLIB_CR16_SYS_fork:
5125 trace_input ("<fork>", OP_VOID, OP_VOID, OP_VOID);
5126 RETVAL (fork ());
5127 trace_output_16 (sd, result);
5128 break;
5130 #define getpid() 47
5131 case TARGET_NEWLIB_CR16_SYS_getpid:
5132 trace_input ("<getpid>", OP_VOID, OP_VOID, OP_VOID);
5133 RETVAL (getpid ());
5134 trace_output_16 (sd, result);
5135 break;
5137 case TARGET_NEWLIB_CR16_SYS_kill:
5138 trace_input ("<kill>", OP_REG, OP_REG, OP_VOID);
5139 if (PARM1 == getpid ())
5141 trace_output_void (sd);
5142 EXCEPTION (PARM2);
5144 else
5146 int os_sig = -1;
5147 switch (PARM2)
5149 #ifdef SIGHUP
5150 case 1: os_sig = SIGHUP; break;
5151 #endif
5152 #ifdef SIGINT
5153 case 2: os_sig = SIGINT; break;
5154 #endif
5155 #ifdef SIGQUIT
5156 case 3: os_sig = SIGQUIT; break;
5157 #endif
5158 #ifdef SIGILL
5159 case 4: os_sig = SIGILL; break;
5160 #endif
5161 #ifdef SIGTRAP
5162 case 5: os_sig = SIGTRAP; break;
5163 #endif
5164 #ifdef SIGABRT
5165 case 6: os_sig = SIGABRT; break;
5166 #elif defined(SIGIOT)
5167 case 6: os_sig = SIGIOT; break;
5168 #endif
5169 #ifdef SIGEMT
5170 case 7: os_sig = SIGEMT; break;
5171 #endif
5172 #ifdef SIGFPE
5173 case 8: os_sig = SIGFPE; break;
5174 #endif
5175 #ifdef SIGKILL
5176 case 9: os_sig = SIGKILL; break;
5177 #endif
5178 #ifdef SIGBUS
5179 case 10: os_sig = SIGBUS; break;
5180 #endif
5181 #ifdef SIGSEGV
5182 case 11: os_sig = SIGSEGV; break;
5183 #endif
5184 #ifdef SIGSYS
5185 case 12: os_sig = SIGSYS; break;
5186 #endif
5187 #ifdef SIGPIPE
5188 case 13: os_sig = SIGPIPE; break;
5189 #endif
5190 #ifdef SIGALRM
5191 case 14: os_sig = SIGALRM; break;
5192 #endif
5193 #ifdef SIGTERM
5194 case 15: os_sig = SIGTERM; break;
5195 #endif
5196 #ifdef SIGURG
5197 case 16: os_sig = SIGURG; break;
5198 #endif
5199 #ifdef SIGSTOP
5200 case 17: os_sig = SIGSTOP; break;
5201 #endif
5202 #ifdef SIGTSTP
5203 case 18: os_sig = SIGTSTP; break;
5204 #endif
5205 #ifdef SIGCONT
5206 case 19: os_sig = SIGCONT; break;
5207 #endif
5208 #ifdef SIGCHLD
5209 case 20: os_sig = SIGCHLD; break;
5210 #elif defined(SIGCLD)
5211 case 20: os_sig = SIGCLD; break;
5212 #endif
5213 #ifdef SIGTTIN
5214 case 21: os_sig = SIGTTIN; break;
5215 #endif
5216 #ifdef SIGTTOU
5217 case 22: os_sig = SIGTTOU; break;
5218 #endif
5219 #ifdef SIGIO
5220 case 23: os_sig = SIGIO; break;
5221 #elif defined (SIGPOLL)
5222 case 23: os_sig = SIGPOLL; break;
5223 #endif
5224 #ifdef SIGXCPU
5225 case 24: os_sig = SIGXCPU; break;
5226 #endif
5227 #ifdef SIGXFSZ
5228 case 25: os_sig = SIGXFSZ; break;
5229 #endif
5230 #ifdef SIGVTALRM
5231 case 26: os_sig = SIGVTALRM; break;
5232 #endif
5233 #ifdef SIGPROF
5234 case 27: os_sig = SIGPROF; break;
5235 #endif
5236 #ifdef SIGWINCH
5237 case 28: os_sig = SIGWINCH; break;
5238 #endif
5239 #ifdef SIGLOST
5240 case 29: os_sig = SIGLOST; break;
5241 #endif
5242 #ifdef SIGUSR1
5243 case 30: os_sig = SIGUSR1; break;
5244 #endif
5245 #ifdef SIGUSR2
5246 case 31: os_sig = SIGUSR2; break;
5247 #endif
5250 if (os_sig == -1)
5252 trace_output_void (sd);
5253 sim_io_printf (sd, "Unknown signal %d\n", PARM2);
5254 sim_io_flush_stdout (sd);
5255 EXCEPTION (SIM_SIGILL);
5257 else
5259 RETVAL (kill (PARM1, PARM2));
5260 trace_output_16 (sd, result);
5263 break;
5265 case TARGET_NEWLIB_CR16_SYS_execve:
5266 trace_input ("<execve>", OP_VOID, OP_VOID, OP_VOID);
5267 RETVAL (execve (MEMPTR (PARM1), (char **) MEMPTR (PARM2<<16|PARM3),
5268 (char **)MEMPTR (PARM4)));
5269 trace_output_16 (sd, result);
5270 break;
5272 case TARGET_NEWLIB_CR16_SYS_execv:
5273 trace_input ("<execv>", OP_VOID, OP_VOID, OP_VOID);
5274 RETVAL (execve (MEMPTR (PARM1), (char **) MEMPTR (PARM2), NULL));
5275 trace_output_16 (sd, result);
5276 break;
5278 case TARGET_NEWLIB_CR16_SYS_pipe:
5280 reg_t buf;
5281 int host_fd[2];
5283 trace_input ("<pipe>", OP_VOID, OP_VOID, OP_VOID);
5284 buf = PARM1;
5285 RETVAL (pipe (host_fd));
5286 SW (buf, host_fd[0]);
5287 buf += sizeof(uint16_t);
5288 SW (buf, host_fd[1]);
5289 trace_output_16 (sd, result);
5291 break;
5293 case TARGET_NEWLIB_CR16_SYS_wait:
5295 int status;
5296 trace_input ("<wait>", OP_REG, OP_VOID, OP_VOID);
5297 RETVAL (wait (&status));
5298 if (PARM1)
5299 SW (PARM1, status);
5300 trace_output_16 (sd, result);
5302 break;
5303 #else
5304 case TARGET_NEWLIB_CR16_SYS_getpid:
5305 trace_input ("<getpid>", OP_VOID, OP_VOID, OP_VOID);
5306 RETVAL (1);
5307 trace_output_16 (sd, result);
5308 break;
5310 case TARGET_NEWLIB_CR16_SYS_kill:
5311 trace_input ("<kill>", OP_REG, OP_REG, OP_VOID);
5312 trace_output_void (sd);
5313 EXCEPTION (PARM2);
5314 break;
5315 #endif
5317 case TARGET_NEWLIB_CR16_SYS_read:
5318 trace_input ("<read>", OP_REG, OP_MEMREF, OP_REG);
5319 RETVAL (cb->read (cb, PARM1,
5320 MEMPTR (((unsigned long)PARM3 << 16)
5321 | ((unsigned long)PARM2)), PARM4));
5322 trace_output_16 (sd, result);
5323 break;
5325 case TARGET_NEWLIB_CR16_SYS_write:
5326 trace_input ("<write>", OP_REG, OP_MEMREF, OP_REG);
5327 RETVAL ((int)cb->write (cb, PARM1,
5328 MEMPTR (((unsigned long)PARM3 << 16)
5329 | PARM2), PARM4));
5330 trace_output_16 (sd, result);
5331 break;
5333 case TARGET_NEWLIB_CR16_SYS_lseek:
5334 trace_input ("<lseek>", OP_REG, OP_REGP, OP_REG);
5335 RETVAL32 (cb->lseek (cb, PARM1, ((((long) PARM3) << 16) | PARM2),
5336 PARM4));
5337 trace_output_32 (sd, result);
5338 break;
5340 case TARGET_NEWLIB_CR16_SYS_close:
5341 trace_input ("<close>", OP_REG, OP_VOID, OP_VOID);
5342 RETVAL (cb->close (cb, PARM1));
5343 trace_output_16 (sd, result);
5344 break;
5346 case TARGET_NEWLIB_CR16_SYS_open:
5347 trace_input ("<open>", OP_MEMREF, OP_REG, OP_VOID);
5348 RETVAL32 (cb->open (cb, MEMPTR ((((unsigned long)PARM2) << 16)
5349 | PARM1), PARM3));
5350 trace_output_32 (sd, result);
5351 break;
5353 case TARGET_NEWLIB_CR16_SYS_rename:
5354 trace_input ("<rename>", OP_MEMREF, OP_MEMREF, OP_VOID);
5355 RETVAL (cb->rename (cb, MEMPTR ((((unsigned long)PARM2) << 16) | PARM1),
5356 MEMPTR ((((unsigned long)PARM4) << 16) | PARM3)));
5357 trace_output_16 (sd, result);
5358 break;
5360 case 0x408: /* REVISIT: Added a dummy getenv call. */
5361 trace_input ("<getenv>", OP_MEMREF, OP_MEMREF, OP_VOID);
5362 RETVAL32 (0);
5363 trace_output_32 (sd, result);
5364 break;
5366 case TARGET_NEWLIB_CR16_SYS_exit:
5367 trace_input ("<exit>", OP_VOID, OP_VOID, OP_VOID);
5368 trace_output_void (sd);
5369 sim_engine_halt (sd, cpu, NULL, PC, sim_exited, GPR (2));
5370 break;
5372 case TARGET_NEWLIB_CR16_SYS_unlink:
5373 trace_input ("<unlink>", OP_MEMREF, OP_VOID, OP_VOID);
5374 RETVAL (cb->unlink (cb, MEMPTR (((unsigned long)PARM2 << 16) | PARM1)));
5375 trace_output_16 (sd, result);
5376 break;
5378 case TARGET_NEWLIB_CR16_SYS_stat:
5379 trace_input ("<stat>", OP_VOID, OP_VOID, OP_VOID);
5380 /* stat system call. */
5382 struct stat host_stat;
5383 reg_t buf;
5385 RETVAL (stat (MEMPTR ((((unsigned long)PARM2) << 16)|PARM1), &host_stat));
5387 buf = PARM2;
5389 /* The hard-coded offsets and sizes were determined by using
5390 * the CR16 compiler on a test program that used struct stat.
5392 SW (buf, host_stat.st_dev);
5393 SW (buf+2, host_stat.st_ino);
5394 SW (buf+4, host_stat.st_mode);
5395 SW (buf+6, host_stat.st_nlink);
5396 SW (buf+8, host_stat.st_uid);
5397 SW (buf+10, host_stat.st_gid);
5398 SW (buf+12, host_stat.st_rdev);
5399 SLW (buf+16, host_stat.st_size);
5400 SLW (buf+20, host_stat.st_atime);
5401 SLW (buf+28, host_stat.st_mtime);
5402 SLW (buf+36, host_stat.st_ctime);
5404 trace_output_16 (sd, result);
5405 break;
5407 case TARGET_NEWLIB_CR16_SYS_chown:
5408 trace_input ("<chown>", OP_VOID, OP_VOID, OP_VOID);
5409 RETVAL (chown (MEMPTR (PARM1), PARM2, PARM3));
5410 trace_output_16 (sd, result);
5411 break;
5413 case TARGET_NEWLIB_CR16_SYS_chmod:
5414 trace_input ("<chmod>", OP_VOID, OP_VOID, OP_VOID);
5415 RETVAL (chmod (MEMPTR (PARM1), PARM2));
5416 trace_output_16 (sd, result);
5417 break;
5419 case TARGET_NEWLIB_CR16_SYS_utime:
5420 trace_input ("<utime>", OP_REG, OP_REG, OP_REG);
5421 /* Cast the second argument to void *, to avoid type mismatch
5422 if a prototype is present. */
5423 RETVAL (utime (MEMPTR (PARM1), (void *) MEMPTR (PARM2)));
5424 trace_output_16 (sd, result);
5425 break;
5427 case TARGET_NEWLIB_CR16_SYS_time:
5428 trace_input ("<time>", OP_VOID, OP_VOID, OP_REG);
5429 RETVAL32 (time (NULL));
5430 trace_output_32 (sd, result);
5431 break;
5433 default:
5434 a = OP[0];
5435 switch (a)
5437 case TRAP_BREAKPOINT:
5438 tmp = (PC);
5439 JMP(tmp);
5440 trace_output_void (sd);
5441 EXCEPTION (SIM_SIGTRAP);
5442 break;
5443 case SIGTRAP: /* supervisor call ? */
5444 trace_output_void (sd);
5445 sim_engine_halt (sd, cpu, NULL, PC, sim_exited, GPR (2));
5446 break;
5447 default:
5448 cb->error (cb, "Unknown syscall %d", FUNC);
5449 break;
5452 if ((uint16_t) result == (uint16_t) -1)
5453 RETERR (cb->get_errno (cb));
5454 else
5455 RETERR (0);
5456 break;
5462 /* push. */
5463 void
5464 OP_3_9 (SIM_DESC sd, SIM_CPU *cpu)
5466 uint16_t a = OP[0] + 1, b = OP[1], c = OP[2], i = 0;
5467 uint32_t tmp, sp_addr = (GPR32 (15)) - (a * 2) - 4, is_regp = 0;
5468 trace_input ("push", OP_CONSTANT3, OP_REG, OP_REG);
5470 for (; i < a; ++i)
5472 if ((b+i) <= 11)
5474 SW (sp_addr, (GPR (b+i)));
5475 sp_addr +=2;
5477 else
5479 if (is_regp == 0)
5480 tmp = (GPR32 (b+i));
5481 else
5482 tmp = (GPR32 (b+i-1));
5484 if ((a-i) > 1)
5486 SLW (sp_addr, tmp);
5487 sp_addr +=4;
5489 else
5491 SW (sp_addr, tmp);
5492 sp_addr +=2;
5494 ++i;
5495 is_regp = 1;
5499 sp_addr +=4;
5501 /* Store RA address. */
5502 tmp = (GPR32 (14));
5503 SLW(sp_addr,tmp);
5505 sp_addr = (GPR32 (15)) - (a * 2) - 4;
5506 SET_GPR32 (15, sp_addr); /* Update SP address. */
5508 trace_output_void (sd);
5511 /* push. */
5512 void
5513 OP_1_8 (SIM_DESC sd, SIM_CPU *cpu)
5515 uint32_t sp_addr, tmp, is_regp = 0;
5516 uint16_t a = OP[0] + 1, b = OP[1], c = OP[2], i = 0;
5517 trace_input ("push", OP_CONSTANT3, OP_REG, OP_VOID);
5519 if (c == 1)
5520 sp_addr = (GPR32 (15)) - (a * 2) - 4;
5521 else
5522 sp_addr = (GPR32 (15)) - (a * 2);
5524 for (; i < a; ++i)
5526 if ((b+i) <= 11)
5528 SW (sp_addr, (GPR (b+i)));
5529 sp_addr +=2;
5531 else
5533 if (is_regp == 0)
5534 tmp = (GPR32 (b+i));
5535 else
5536 tmp = (GPR32 (b+i-1));
5538 if ((a-i) > 1)
5540 SLW (sp_addr, tmp);
5541 sp_addr +=4;
5543 else
5545 SW (sp_addr, tmp);
5546 sp_addr +=2;
5548 ++i;
5549 is_regp = 1;
5553 if (c == 1)
5555 /* Store RA address. */
5556 tmp = (GPR32 (14));
5557 SLW(sp_addr,tmp);
5558 sp_addr = (GPR32 (15)) - (a * 2) - 4;
5560 else
5561 sp_addr = (GPR32 (15)) - (a * 2);
5563 SET_GPR32 (15, sp_addr); /* Update SP address. */
5565 trace_output_void (sd);
5569 /* push. */
5570 void
5571 OP_11E_10 (SIM_DESC sd, SIM_CPU *cpu)
5573 uint32_t sp_addr = (GPR32 (15)), tmp;
5574 trace_input ("push", OP_VOID, OP_VOID, OP_VOID);
5575 tmp = (GPR32 (14));
5576 SLW(sp_addr-4,tmp); /* Store RA address. */
5577 SET_GPR32 (15, (sp_addr - 4)); /* Update SP address. */
5578 trace_output_void (sd);
5582 /* pop. */
5583 void
5584 OP_5_9 (SIM_DESC sd, SIM_CPU *cpu)
5586 uint16_t a = OP[0] + 1, b = OP[1], c = OP[2], i = 0;
5587 uint32_t tmp, sp_addr = (GPR32 (15)), is_regp = 0;;
5588 trace_input ("pop", OP_CONSTANT3, OP_REG, OP_REG);
5590 for (; i < a; ++i)
5592 if ((b+i) <= 11)
5594 SET_GPR ((b+i), RW(sp_addr));
5595 sp_addr +=2;
5597 else
5599 if ((a-i) > 1)
5601 tmp = RLW(sp_addr);
5602 sp_addr +=4;
5604 else
5606 tmp = RW(sp_addr);
5607 sp_addr +=2;
5609 if (is_regp == 0)
5610 tmp = (tmp << 16) | (GPR32 (b+i));
5611 else
5612 tmp = (tmp << 16) | (GPR32 (b+i-1));
5615 if (is_regp == 0)
5616 SET_GPR32 ((b+i), (((tmp & 0xffff) << 16)
5617 | ((tmp >> 16) & 0xffff)));
5618 else
5619 SET_GPR32 ((b+i-1), (((tmp & 0xffff) << 16)
5620 | ((tmp >> 16) & 0xffff)));
5622 ++i;
5623 is_regp = 1;
5627 tmp = RLW(sp_addr); /* store RA also. */
5628 SET_GPR32 (14, (((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff)));
5630 SET_GPR32 (15, (sp_addr + 4)); /* Update SP address. */
5632 trace_output_void (sd);
5635 /* pop. */
5636 void
5637 OP_2_8 (SIM_DESC sd, SIM_CPU *cpu)
5639 uint16_t a = OP[0] + 1, b = OP[1], c = OP[2], i = 0;
5640 uint32_t tmp, sp_addr = (GPR32 (15)), is_regp = 0;
5641 trace_input ("pop", OP_CONSTANT3, OP_REG, OP_VOID);
5643 for (; i < a; ++i)
5645 if ((b+i) <= 11)
5647 SET_GPR ((b+i), RW(sp_addr));
5648 sp_addr +=2;
5650 else
5652 if ((a-i) > 1)
5654 tmp = RLW(sp_addr);
5655 sp_addr +=4;
5657 else
5659 tmp = RW(sp_addr);
5660 sp_addr +=2;
5662 if (is_regp == 0)
5663 tmp = ((tmp << 16) & 0xffffffff) | (GPR32 (b+i));
5664 else
5665 tmp = ((tmp << 16) & 0xffffffff) | (GPR32 (b+i-1));
5668 if (is_regp == 0)
5669 SET_GPR32 ((b+i), (((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff)));
5670 else
5671 SET_GPR32 ((b+i-1), (((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff)));
5672 ++i;
5673 is_regp = 1;
5677 if (c == 1)
5679 tmp = RLW(sp_addr); /* Store RA Reg. */
5680 SET_GPR32 (14, (((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff)));
5681 sp_addr +=4;
5684 SET_GPR32 (15, sp_addr); /* Update SP address. */
5686 trace_output_void (sd);
5689 /* pop. */
5690 void
5691 OP_21E_10 (SIM_DESC sd, SIM_CPU *cpu)
5693 uint32_t sp_addr = GPR32 (15);
5694 uint32_t tmp;
5695 trace_input ("pop", OP_VOID, OP_VOID, OP_VOID);
5697 tmp = RLW(sp_addr);
5698 SET_GPR32 (14, (((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff)));
5699 SET_GPR32 (15, (sp_addr+4)); /* Update SP address. */
5701 trace_output_void (sd);
5704 /* popret. */
5705 void
5706 OP_7_9 (SIM_DESC sd, SIM_CPU *cpu)
5708 uint16_t a = OP[0], b = OP[1];
5709 trace_input ("popret", OP_CONSTANT3, OP_REG, OP_REG);
5710 OP_5_9 (sd, cpu);
5711 JMP(((GPR32(14)) << 1) & 0xffffff);
5713 trace_output_void (sd);
5716 /* popret. */
5717 void
5718 OP_3_8 (SIM_DESC sd, SIM_CPU *cpu)
5720 uint16_t a = OP[0], b = OP[1];
5721 trace_input ("popret", OP_CONSTANT3, OP_REG, OP_VOID);
5722 OP_2_8 (sd, cpu);
5723 JMP(((GPR32(14)) << 1) & 0xffffff);
5725 trace_output_void (sd);
5728 /* popret. */
5729 void
5730 OP_31E_10 (SIM_DESC sd, SIM_CPU *cpu)
5732 uint32_t tmp;
5733 trace_input ("popret", OP_VOID, OP_VOID, OP_VOID);
5734 OP_21E_10 (sd, cpu);
5735 tmp = (((GPR32(14)) << 1) & 0xffffff);
5736 /* If the resulting PC value is less than 0x00_0000 or greater
5737 than 0xFF_FFFF, this instruction causes an IAD trap.*/
5739 if ((tmp < 0x0) || (tmp > 0xFFFFFF))
5741 trace_output_void (sd);
5742 EXCEPTION (SIM_SIGBUS);
5744 else
5745 JMP (tmp);
5747 trace_output_32 (sd, tmp);
5751 /* cinv[i]. */
5752 void
5753 OP_A_10 (SIM_DESC sd, SIM_CPU *cpu)
5755 trace_input ("cinv[i]", OP_VOID, OP_VOID, OP_VOID);
5756 SET_PSR_I (1);
5757 trace_output_void (sd);
5760 /* cinv[i,u]. */
5761 void
5762 OP_B_10 (SIM_DESC sd, SIM_CPU *cpu)
5764 trace_input ("cinv[i,u]", OP_VOID, OP_VOID, OP_VOID);
5765 SET_PSR_I (1);
5766 trace_output_void (sd);
5769 /* cinv[d]. */
5770 void
5771 OP_C_10 (SIM_DESC sd, SIM_CPU *cpu)
5773 trace_input ("cinv[d]", OP_VOID, OP_VOID, OP_VOID);
5774 SET_PSR_I (1);
5775 trace_output_void (sd);
5778 /* cinv[d,u]. */
5779 void
5780 OP_D_10 (SIM_DESC sd, SIM_CPU *cpu)
5782 trace_input ("cinv[i,u]", OP_VOID, OP_VOID, OP_VOID);
5783 SET_PSR_I (1);
5784 trace_output_void (sd);
5787 /* cinv[d,i]. */
5788 void
5789 OP_E_10 (SIM_DESC sd, SIM_CPU *cpu)
5791 trace_input ("cinv[d,i]", OP_VOID, OP_VOID, OP_VOID);
5792 SET_PSR_I (1);
5793 trace_output_void (sd);
5796 /* cinv[d,i,u]. */
5797 void
5798 OP_F_10 (SIM_DESC sd, SIM_CPU *cpu)
5800 trace_input ("cinv[d,i,u]", OP_VOID, OP_VOID, OP_VOID);
5801 SET_PSR_I (1);
5802 trace_output_void (sd);
5805 /* retx. */
5806 void
5807 OP_3_10 (SIM_DESC sd, SIM_CPU *cpu)
5809 trace_input ("retx", OP_VOID, OP_VOID, OP_VOID);
5810 SET_PSR_I (1);
5811 trace_output_void (sd);
5814 /* di. */
5815 void
5816 OP_4_10 (SIM_DESC sd, SIM_CPU *cpu)
5818 trace_input ("di", OP_VOID, OP_VOID, OP_VOID);
5819 SET_PSR_I (1);
5820 trace_output_void (sd);
5823 /* ei. */
5824 void
5825 OP_5_10 (SIM_DESC sd, SIM_CPU *cpu)
5827 trace_input ("ei", OP_VOID, OP_VOID, OP_VOID);
5828 SET_PSR_I (1);
5829 trace_output_void (sd);
5832 /* wait. */
5833 void
5834 OP_6_10 (SIM_DESC sd, SIM_CPU *cpu)
5836 trace_input ("wait", OP_VOID, OP_VOID, OP_VOID);
5837 trace_output_void (sd);
5838 EXCEPTION (SIM_SIGTRAP);
5841 /* ewait. */
5842 void
5843 OP_7_10 (SIM_DESC sd, SIM_CPU *cpu)
5845 trace_input ("ewait", OP_VOID, OP_VOID, OP_VOID);
5846 SET_PSR_I (1);
5847 trace_output_void (sd);
5850 /* xorb. */
5851 void
5852 OP_28_8 (SIM_DESC sd, SIM_CPU *cpu)
5854 uint8_t tmp, a = (OP[0]) & 0xff, b = (GPR (OP[1])) & 0xff;
5855 trace_input ("xorb", OP_CONSTANT4, OP_REG, OP_VOID);
5856 tmp = a ^ b;
5857 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
5858 trace_output_16 (sd, tmp);
5861 /* xorb. */
5862 void
5863 OP_28B_C (SIM_DESC sd, SIM_CPU *cpu)
5865 uint8_t tmp, a = (OP[0]) & 0xff, b = (GPR (OP[1])) & 0xff;
5866 trace_input ("xorb", OP_CONSTANT16, OP_REG, OP_VOID);
5867 tmp = a ^ b;
5868 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
5869 trace_output_16 (sd, tmp);
5872 /* xorb. */
5873 void
5874 OP_29_8 (SIM_DESC sd, SIM_CPU *cpu)
5876 uint8_t tmp, a = (GPR (OP[0])) & 0xff, b = (GPR (OP[1])) & 0xff;
5877 trace_input ("xorb", OP_REG, OP_REG, OP_VOID);
5878 tmp = a ^ b;
5879 SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
5880 trace_output_16 (sd, tmp);
5883 /* xorw. */
5884 void
5885 OP_2A_8 (SIM_DESC sd, SIM_CPU *cpu)
5887 uint16_t tmp, a = (OP[0]), b = (GPR (OP[1]));
5888 trace_input ("xorw", OP_CONSTANT4, OP_REG, OP_VOID);
5889 tmp = a ^ b;
5890 SET_GPR (OP[1], tmp);
5891 trace_output_16 (sd, tmp);
5894 /* xorw. */
5895 void
5896 OP_2AB_C (SIM_DESC sd, SIM_CPU *cpu)
5898 uint16_t tmp, a = (OP[0]), b = (GPR (OP[1]));
5899 trace_input ("xorw", OP_CONSTANT16, OP_REG, OP_VOID);
5900 tmp = a ^ b;
5901 SET_GPR (OP[1], tmp);
5902 trace_output_16 (sd, tmp);
5905 /* xorw. */
5906 void
5907 OP_2B_8 (SIM_DESC sd, SIM_CPU *cpu)
5909 uint16_t tmp, a = (GPR (OP[0])), b = (GPR (OP[1]));
5910 trace_input ("xorw", OP_REG, OP_REG, OP_VOID);
5911 tmp = a ^ b;
5912 SET_GPR (OP[1], tmp);
5913 trace_output_16 (sd, tmp);
5916 /*REVISIT FOR LPR/SPR . */
5918 /* lpr. */
5919 void
5920 OP_140_14 (SIM_DESC sd, SIM_CPU *cpu)
5922 uint16_t a = GPR (OP[0]);
5923 trace_input ("lpr", OP_REG, OP_REG, OP_VOID);
5924 SET_CREG (OP[1], a);
5925 trace_output_16 (sd, a);
5928 /* lprd. */
5929 void
5930 OP_141_14 (SIM_DESC sd, SIM_CPU *cpu)
5932 uint32_t a = GPR32 (OP[0]);
5933 trace_input ("lprd", OP_REGP, OP_REG, OP_VOID);
5934 SET_CREG (OP[1], a);
5935 trace_output_flag (sd);
5938 /* spr. */
5939 void
5940 OP_142_14 (SIM_DESC sd, SIM_CPU *cpu)
5942 uint16_t a = CREG (OP[0]);
5943 trace_input ("spr", OP_REG, OP_REG, OP_VOID);
5944 SET_GPR (OP[1], a);
5945 trace_output_16 (sd, a);
5948 /* sprd. */
5949 void
5950 OP_143_14 (SIM_DESC sd, SIM_CPU *cpu)
5952 uint32_t a = CREG (OP[0]);
5953 trace_input ("sprd", OP_REGP, OP_REGP, OP_VOID);
5954 SET_GPR32 (OP[1], a);
5955 trace_output_32 (sd, a);
5958 /* null. */
5959 void
5960 OP_0_20 (SIM_DESC sd, SIM_CPU *cpu)
5962 trace_input ("null", OP_VOID, OP_VOID, OP_VOID);
5963 sim_engine_halt (sd, cpu, NULL, PC, sim_exited, 0);