30 /* FIXME - should be including a version of syscall.h that does not
31 pollute the name space */
32 #include "../../libgloss/v850/sys/syscall.h"
35 #include "libiberty.h"
38 #if !defined(__GO32__) && !defined(_WIN32)
40 #include <sys/times.h>
69 /* start-sanitize-v850e */
73 /* end-sanitize-v850e */
74 /* start-sanitize-v850eq */
79 /* end-sanitize-v850eq */
82 /* start-sanitize-v850e */
83 /* This is an array of the bit positions of registers r20 .. r31 in that order in a prepare/dispose instruction. */
84 static int type1_regs
[12] = { 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 0, 21 };
85 /* end-sanitize-v850e */
86 /* start-sanitize-v850eq */
87 /* This is an array of the bit positions of registers r16 .. r31 in that order in a push/pop instruction. */
88 static int type2_regs
[16] = { 3, 2, 1, 0, 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 20, 21};
89 /* This is an array of the bit positions of registers r1 .. r15 in that order in a push/pop instruction. */
90 static int type3_regs
[15] = { 2, 1, 0, 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 20, 21};
91 /* end-sanitize-v850eq */
94 static void trace_input
PARAMS ((char *name
, enum op_types type
, int size
));
95 static void trace_output
PARAMS ((enum op_types result
));
97 #ifndef SIZE_INSTRUCTION
98 #define SIZE_INSTRUCTION 6
101 #ifndef SIZE_OPERANDS
102 #define SIZE_OPERANDS 16
106 #define SIZE_VALUES 11
109 #ifndef SIZE_LOCATION
110 #define SIZE_LOCATION 40
115 trace_input (name
, type
, size
)
124 const char *filename
;
125 const char *functionname
;
126 unsigned int linenumber
;
128 if (!TRACE_ALU_P (STATE_CPU (simulator
, 0)))
133 if (STATE_TEXT_SECTION (simulator
)
134 && PC
>= STATE_TEXT_START (simulator
)
135 && PC
< STATE_TEXT_END (simulator
))
137 filename
= (const char *)0;
138 functionname
= (const char *)0;
140 if (bfd_find_nearest_line (STATE_PROG_BFD (simulator
),
141 STATE_TEXT_SECTION (simulator
),
142 (struct symbol_cache_entry
**)0,
143 PC
- STATE_TEXT_START (simulator
),
144 &filename
, &functionname
, &linenumber
))
149 sprintf (p
, "Line %5d ", linenumber
);
155 sprintf (p
, "Func %s ", functionname
);
160 char *q
= (char *) strrchr (filename
, '/');
161 sprintf (p
, "File %s ", (q
) ? q
+1 : filename
);
170 trace_printf (simulator
, STATE_CPU (simulator
, 0),
171 "0x%.8x: %-*.*s %-*s",
173 SIZE_LOCATION
, SIZE_LOCATION
, buf
,
174 SIZE_INSTRUCTION
, name
);
182 strcpy (buf
, "unknown");
186 sprintf (buf
, "%ld", OP
[0]);
190 sprintf (buf
, "r%ld", OP
[0]);
195 case OP_REG_REG_MOVE
:
196 sprintf (buf
, "r%ld,r%ld", OP
[0], OP
[1]);
201 case OP_IMM_REG_MOVE
:
202 sprintf (buf
, "%ld,r%ld", OP
[0], OP
[1]);
206 sprintf (buf
, "%ld", SEXT9 (OP
[0]));
210 sprintf (buf
, "%ld[r30],r%ld", OP
[1] * size
, OP
[0]);
214 sprintf (buf
, "r%ld,%ld[r30]", OP
[0], OP
[1] * size
);
218 sprintf (buf
, "%ld[r%ld],r%ld", EXTEND16 (OP
[2]) & ~0x1, OP
[0], OP
[1]);
222 sprintf (buf
, "r%ld,%ld[r%ld]", OP
[1], EXTEND16 (OP
[2] & ~0x1), OP
[0]);
226 sprintf (buf
, "%ld,r%ld", SEXT22 (OP
[0]), OP
[1]);
230 sprintf (buf
, "%ld,r%ld,r%ld", EXTEND16 (OP
[0]), OP
[1], OP
[2]);
233 case OP_UIMM_REG_REG
:
234 sprintf (buf
, "%ld,r%ld,r%ld", OP
[0] & 0xffff, OP
[1], OP
[2]);
238 sprintf (buf
, "%ld,%ld[r%ld]", OP
[1] & 0x7, EXTEND16 (OP
[2]), OP
[0]);
246 default: cond
= "?"; break;
247 case 0x0: cond
= "v"; break;
248 case 0x1: cond
= "c"; break;
249 case 0x2: cond
= "z"; break;
250 case 0x3: cond
= "nh"; break;
251 case 0x4: cond
= "s"; break;
252 case 0x5: cond
= "t"; break;
253 case 0x6: cond
= "lt"; break;
254 case 0x7: cond
= "le"; break;
255 case 0x8: cond
= "nv"; break;
256 case 0x9: cond
= "nc"; break;
257 case 0xa: cond
= "nz"; break;
258 case 0xb: cond
= "h"; break;
259 case 0xc: cond
= "ns"; break;
260 case 0xd: cond
= "sa"; break;
261 case 0xe: cond
= "ge"; break;
262 case 0xf: cond
= "gt"; break;
264 sprintf (buf
, "%s,r%ld", cond
, OP
[1]);
274 sprintf (buf
, "r%ld,s%ld", OP
[0], OP
[1]);
278 for (i
= 0; i
< 12; i
++)
279 if (OP
[3] & (1 << type1_regs
[i
]))
280 sprintf (strchr (buf
, 0), "r%d ", i
+ 20);
284 for (i
= 0; i
< 16; i
++)
285 if (OP
[3] & (1 << type2_regs
[i
]))
286 sprintf (strchr (buf
, 0), "r%d ", i
+ 16);
287 if (OP
[3] & (1 << 19))
288 strcat (buf
, "F/EIPC, F/EIPSW " );
292 for (i
= 0; i
< 15; i
++)
293 if (OP
[3] & (1 << type3_regs
[i
]))
294 sprintf (strchr (buf
, 0), "r%d ", i
+ 1);
295 if (OP
[3] & (1 << 3))
296 strcat (buf
, "PSW " );
297 if (OP
[3] & (1 << 19))
298 strcat (buf
, "F/EIPC, F/EIPSW " );
302 sprintf (buf
, "r%ld, [r%ld]", OP
[1], OP
[0] );
307 if (!TRACE_ALU_P (STATE_CPU (simulator
, 0)))
309 trace_printf (simulator
, STATE_CPU (simulator
, 0),
315 trace_printf (simulator
, STATE_CPU (simulator
, 0),
316 "%-*s", SIZE_OPERANDS
, buf
);
328 case OP_REG_REG_MOVE
:
329 values
[0] = State
.regs
[OP
[0]];
336 values
[0] = State
.regs
[OP
[1]];
337 values
[1] = State
.regs
[OP
[0]];
343 values
[0] = SEXT5 (OP
[0]);
348 case OP_IMM_REG_MOVE
:
349 values
[0] = SEXT5 (OP
[0]);
354 values
[0] = State
.pc
;
355 values
[1] = SEXT9 (OP
[0]);
361 values
[0] = OP
[1] * size
;
362 values
[1] = State
.regs
[30];
367 values
[0] = State
.regs
[OP
[0]];
368 values
[1] = OP
[1] * size
;
369 values
[2] = State
.regs
[30];
374 values
[0] = EXTEND16 (OP
[2]);
375 values
[1] = State
.regs
[OP
[0]];
380 values
[0] = State
.regs
[OP
[1]];
381 values
[1] = EXTEND16 (OP
[2]);
382 values
[2] = State
.regs
[OP
[0]];
387 values
[0] = SEXT22 (OP
[0]);
388 values
[1] = State
.pc
;
393 values
[0] = EXTEND16 (OP
[0]) << size
;
394 values
[1] = State
.regs
[OP
[1]];
398 case OP_UIMM_REG_REG
:
399 values
[0] = (OP
[0] & 0xffff) << size
;
400 values
[1] = State
.regs
[OP
[1]];
418 values
[0] = State
.regs
[OP
[0]];
423 values
[0] = State
.sregs
[OP
[1]];
427 for (i
= 0; i
< num_values
; i
++)
428 trace_printf (simulator
, STATE_CPU (simulator
, 0),
429 "%*s0x%.8lx", SIZE_VALUES
- 10, "", values
[i
]);
432 trace_printf (simulator
, STATE_CPU (simulator
, 0),
433 "%*s", SIZE_VALUES
, "");
438 trace_output (result
)
439 enum op_types result
;
441 if (TRACE_ALU_P (STATE_CPU (simulator
, 0)))
461 trace_printf (simulator
, STATE_CPU (simulator
, 0),
462 " :: 0x%.8lx", (unsigned long)State
.regs
[OP
[0]]);
466 case OP_REG_REG_MOVE
:
468 case OP_IMM_REG_MOVE
:
471 trace_printf (simulator
, STATE_CPU (simulator
, 0),
472 " :: 0x%.8lx", (unsigned long)State
.regs
[OP
[1]]);
476 case OP_UIMM_REG_REG
:
477 trace_printf (simulator
, STATE_CPU (simulator
, 0),
478 " :: 0x%.8lx", (unsigned long)State
.regs
[OP
[2]]);
483 trace_printf (simulator
, STATE_CPU (simulator
, 0),
484 " :: 0x%.8lx", (unsigned long)State
.regs
[OP
[1]]);
488 trace_printf (simulator
, STATE_CPU (simulator
, 0),
489 " :: 0x%.8lx", (unsigned long)State
.sregs
[OP
[1]]);
493 trace_printf (simulator
, STATE_CPU (simulator
, 0),
499 #define trace_input(NAME, IN1, IN2)
500 #define trace_output(RESULT)
502 /* #define trace_input(NAME, IN1, IN2) fprintf (stderr, NAME "\n" ); */
507 /* Returns 1 if the specific condition is met, returns 0 otherwise. */
509 condition_met (unsigned code
)
511 unsigned int psw
= PSW
;
515 case 0x0: return ((psw
& PSW_OV
) != 0);
516 case 0x1: return ((psw
& PSW_CY
) != 0);
517 case 0x2: return ((psw
& PSW_Z
) != 0);
518 case 0x3: return ((((psw
& PSW_CY
) != 0) | ((psw
& PSW_Z
) != 0)) != 0);
519 case 0x4: return ((psw
& PSW_S
) != 0);
520 /*case 0x5: return 1;*/
521 case 0x6: return ((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) != 0);
522 case 0x7: return (((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) || ((psw
& PSW_Z
) != 0)) != 0);
523 case 0x8: return ((psw
& PSW_OV
) == 0);
524 case 0x9: return ((psw
& PSW_CY
) == 0);
525 case 0xa: return ((psw
& PSW_Z
) == 0);
526 case 0xb: return ((((psw
& PSW_CY
) != 0) | ((psw
& PSW_Z
) != 0)) == 0);
527 case 0xc: return ((psw
& PSW_S
) == 0);
528 case 0xd: return ((psw
& PSW_SAT
) != 0);
529 case 0xe: return ((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) == 0);
530 case 0xf: return (((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) || ((psw
& PSW_Z
) != 0)) == 0);
537 Add32 (unsigned long a1
, unsigned long a2
, int * carry
)
539 unsigned long result
= (a1
+ a2
);
541 * carry
= (result
< a1
);
547 Multiply64 (boolean sign
, unsigned long op0
)
558 op1
= State
.regs
[ OP
[1] ];
562 /* Compute sign of result and adjust operands if necessary. */
564 sign
= (op0
^ op1
) & 0x80000000;
566 if (((signed long) op0
) < 0)
569 if (((signed long) op1
) < 0)
573 /* We can split the 32x32 into four 16x16 operations. This ensures
574 that we do not lose precision on 32bit only hosts: */
575 lo
= ( (op0
& 0xFFFF) * (op1
& 0xFFFF));
576 mid1
= ( (op0
& 0xFFFF) * ((op1
>> 16) & 0xFFFF));
577 mid2
= (((op0
>> 16) & 0xFFFF) * (op1
& 0xFFFF));
578 hi
= (((op0
>> 16) & 0xFFFF) * ((op1
>> 16) & 0xFFFF));
580 /* We now need to add all of these results together, taking care
581 to propogate the carries from the additions: */
582 RdLo
= Add32 (lo
, (mid1
<< 16), & carry
);
584 RdLo
= Add32 (RdLo
, (mid2
<< 16), & carry
);
585 RdHi
+= (carry
+ ((mid1
>> 16) & 0xFFFF) + ((mid2
>> 16) & 0xFFFF) + hi
);
589 /* Negate result if necessary. */
593 if (RdLo
== 0xFFFFFFFF)
602 State
.regs
[ OP
[1] ] = RdLo
;
603 State
.regs
[ OP
[2] >> 11 ] = RdHi
;
609 /* Read a null terminated string from memory, return in a buffer */
617 while (sim_core_read_1 (STATE_CPU (sd
, 0),
618 PC
, sim_core_read_map
, addr
+ nr
) != 0)
620 buf
= NZALLOC (char, nr
+ 1);
621 sim_read (simulator
, addr
, buf
, nr
);
625 /* Read a null terminated argument vector from memory, return in a
628 fetch_argv (sd
, addr
)
634 char **buf
= xmalloc (max_nr
* sizeof (char*));
637 unsigned32 a
= sim_core_read_4 (STATE_CPU (sd
, 0),
638 PC
, sim_core_read_map
, addr
+ nr
* 4);
640 buf
[nr
] = fetch_str (sd
, a
);
642 if (nr
== max_nr
- 1)
645 buf
= xrealloc (buf
, max_nr
* sizeof (char*));
657 unsigned long result
;
659 result
= load_mem (State
.regs
[30] + (OP
[3] & 0x7f), 1);
661 /* start-sanitize-v850eq */
663 trace_input ("sld.bu", OP_LOAD16
, 1);
665 State
.regs
[ OP
[1] ] = result
;
667 /* end-sanitize-v850eq */
668 trace_input ("sld.b", OP_LOAD16
, 1);
670 State
.regs
[ OP
[1] ] = EXTEND8 (result
);
671 /* start-sanitize-v850eq */
673 /* end-sanitize-v850eq */
675 trace_output (OP_LOAD16
);
684 unsigned long result
;
686 result
= load_mem (State
.regs
[30] + ((OP
[3] & 0x7f) << 1), 2);
688 /* start-sanitize-v850eq */
690 trace_input ("sld.hu", OP_LOAD16
, 2);
692 State
.regs
[ OP
[1] ] = result
;
694 /* end-sanitize-v850eq */
695 trace_input ("sld.h", OP_LOAD16
, 2);
697 State
.regs
[ OP
[1] ] = EXTEND16 (result
);
698 /* start-sanitize-v850eq */
700 /* end-sanitize-v850eq */
702 trace_output (OP_LOAD16
);
711 trace_input ("sld.w", OP_LOAD16
, 4);
713 State
.regs
[ OP
[1] ] = load_mem (State
.regs
[30] + ((OP
[3] & 0x7f) << 1), 4);
715 trace_output (OP_LOAD16
);
724 trace_input ("sst.b", OP_STORE16
, 1);
726 store_mem (State
.regs
[30] + (OP
[3] & 0x7f), 1, State
.regs
[ OP
[1] ]);
728 trace_output (OP_STORE16
);
737 trace_input ("sst.h", OP_STORE16
, 2);
739 store_mem (State
.regs
[30] + ((OP
[3] & 0x7f) << 1), 2, State
.regs
[ OP
[1] ]);
741 trace_output (OP_STORE16
);
750 trace_input ("sst.w", OP_STORE16
, 4);
752 store_mem (State
.regs
[30] + ((OP
[3] & 0x7e) << 1), 4, State
.regs
[ OP
[1] ]);
754 trace_output (OP_STORE16
);
765 trace_input ("ld.b", OP_LOAD32
, 1);
767 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2]);
769 State
.regs
[ OP
[1] ] = EXTEND8 (load_mem (adr
, 1));
771 trace_output (OP_LOAD32
);
782 trace_input ("ld.h", OP_LOAD32
, 2);
784 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2]);
787 State
.regs
[ OP
[1] ] = EXTEND16 (load_mem (adr
, 2));
789 trace_output (OP_LOAD32
);
800 trace_input ("ld.w", OP_LOAD32
, 4);
802 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2] & ~1);
805 State
.regs
[ OP
[1] ] = load_mem (adr
, 4);
807 trace_output (OP_LOAD32
);
816 trace_input ("st.b", OP_STORE32
, 1);
818 store_mem (State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2]), 1, State
.regs
[ OP
[1] ]);
820 trace_output (OP_STORE32
);
831 trace_input ("st.h", OP_STORE32
, 2);
833 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2]);
836 store_mem (adr
, 2, State
.regs
[ OP
[1] ]);
838 trace_output (OP_STORE32
);
849 trace_input ("st.w", OP_STORE32
, 4);
851 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2] & ~1);
854 store_mem (adr
, 4, State
.regs
[ OP
[1] ]);
856 trace_output (OP_STORE32
);
864 trace_input ("Bcond", OP_COND_BR
, 0);
865 trace_output (OP_COND_BR
);
867 if (condition_met (code
))
868 return SEXT9 (((OP
[3] & 0x70) >> 3) | ((OP
[3] & 0xf800) >> 7));
986 /* sld.bu disp4[ep], reg2 */
992 trace_input ("jmp", OP_REG
, 0);
994 PC
= State
.regs
[ OP
[0] ];
996 trace_output (OP_REG
);
998 return 0; /* Add nothing to the PC, we have already done it. */
1000 /* start-sanitize-v850e */
1003 unsigned long result
;
1005 result
= load_mem (State
.regs
[30] + (OP
[3] & 0xf), 1);
1007 /* start-sanitize-v850eq */
1009 trace_input ("sld.b", OP_LOAD16
, 1);
1011 State
.regs
[ OP
[1] ] = EXTEND8 (result
);
1013 /* end-sanitize-v850eq */
1014 trace_input ("sld.bu", OP_LOAD16
, 1);
1016 State
.regs
[ OP
[1] ] = result
;
1017 /* start-sanitize-v850eq */
1019 /* end-sanitize-v850eq */
1021 trace_output (OP_LOAD16
);
1025 /* end-sanitize-v850e */
1028 /* jarl/jr disp22, reg */
1032 trace_input ("jarl/jr", OP_JUMP
, 0);
1035 State
.regs
[ OP
[1] ] = PC
+ 4;
1037 trace_output (OP_JUMP
);
1039 return SEXT22 (((OP
[3] & 0x3f) << 16) | OP
[2]);
1046 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
1048 trace_input ("add", OP_REG_REG
, 0);
1050 /* Compute the result. */
1052 op0
= State
.regs
[ OP
[0] ];
1053 op1
= State
.regs
[ OP
[1] ];
1057 /* Compute the condition codes. */
1059 s
= (result
& 0x80000000);
1060 cy
= (result
< op0
|| result
< op1
);
1061 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
1062 && (op0
& 0x80000000) != (result
& 0x80000000));
1064 /* Store the result and condition codes. */
1065 State
.regs
[OP
[1]] = result
;
1066 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1067 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1068 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
1069 trace_output (OP_REG_REG
);
1074 /* add sign_extend(imm5), reg */
1078 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
1081 trace_input ("add", OP_IMM_REG
, 0);
1083 /* Compute the result. */
1084 temp
= SEXT5 (OP
[0]);
1086 op1
= State
.regs
[OP
[1]];
1089 /* Compute the condition codes. */
1091 s
= (result
& 0x80000000);
1092 cy
= (result
< op0
|| result
< op1
);
1093 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
1094 && (op0
& 0x80000000) != (result
& 0x80000000));
1096 /* Store the result and condition codes. */
1097 State
.regs
[OP
[1]] = result
;
1098 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1099 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1100 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
1101 trace_output (OP_IMM_REG
);
1106 /* addi sign_extend(imm16), reg, reg */
1110 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
1112 trace_input ("addi", OP_IMM_REG_REG
, 0);
1114 /* Compute the result. */
1116 op0
= EXTEND16 (OP
[2]);
1117 op1
= State
.regs
[ OP
[0] ];
1120 /* Compute the condition codes. */
1122 s
= (result
& 0x80000000);
1123 cy
= (result
< op0
|| result
< op1
);
1124 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
1125 && (op0
& 0x80000000) != (result
& 0x80000000));
1127 /* Store the result and condition codes. */
1128 State
.regs
[OP
[1]] = result
;
1129 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1130 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1131 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
1132 trace_output (OP_IMM_REG_REG
);
1137 /* sub reg1, reg2 */
1141 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
1143 trace_input ("sub", OP_REG_REG
, 0);
1144 /* Compute the result. */
1145 op0
= State
.regs
[ OP
[0] ];
1146 op1
= State
.regs
[ OP
[1] ];
1149 /* Compute the condition codes. */
1151 s
= (result
& 0x80000000);
1153 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
1154 && (op1
& 0x80000000) != (result
& 0x80000000));
1156 /* Store the result and condition codes. */
1157 State
.regs
[OP
[1]] = result
;
1158 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1159 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1160 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
1161 trace_output (OP_REG_REG
);
1166 /* subr reg1, reg2 */
1170 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
1172 trace_input ("subr", OP_REG_REG
, 0);
1173 /* Compute the result. */
1174 op0
= State
.regs
[ OP
[0] ];
1175 op1
= State
.regs
[ OP
[1] ];
1178 /* Compute the condition codes. */
1180 s
= (result
& 0x80000000);
1182 ov
= ((op0
& 0x80000000) != (op1
& 0x80000000)
1183 && (op0
& 0x80000000) != (result
& 0x80000000));
1185 /* Store the result and condition codes. */
1186 State
.regs
[OP
[1]] = result
;
1187 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1188 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1189 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
1190 trace_output (OP_REG_REG
);
1196 /* mulh reg1, reg2 */
1200 /* start-sanitize-v850e */
1203 trace_input ("sxh", OP_REG
, 0);
1205 State
.regs
[ OP
[0] ] = EXTEND16 (State
.regs
[ OP
[0] ]);
1207 trace_output (OP_REG
);
1210 /* end-sanitize-v850e */
1212 trace_input ("mulh", OP_REG_REG
, 0);
1214 State
.regs
[ OP
[1] ] = (EXTEND16 (State
.regs
[ OP
[1] ]) * EXTEND16 (State
.regs
[ OP
[0] ]));
1216 trace_output (OP_REG_REG
);
1222 /* mulh sign_extend(imm5), reg2 */
1226 trace_input ("mulh", OP_IMM_REG
, 0);
1228 State
.regs
[ OP
[1] ] = EXTEND16 (State
.regs
[ OP
[1] ]) * SEXT5 (OP
[0]);
1230 trace_output (OP_IMM_REG
);
1235 /* mulhi imm16, reg1, reg2 */
1244 trace_input ("mulhi", OP_IMM_REG_REG
, 0);
1246 State
.regs
[ OP
[1] ] = EXTEND16 (State
.regs
[ OP
[0] ]) * EXTEND16 (OP
[2]);
1248 trace_output (OP_IMM_REG_REG
);
1254 /* divh reg1, reg2 */
1259 /* start-sanitize-v850e */
1264 trace_input ("switch", OP_REG
, 0);
1266 adr
= State
.pc
+ 2 + (State
.regs
[ OP
[0] ] << 1);
1267 State
.pc
= State
.pc
+ 2 + (EXTEND16 (load_mem (adr
, 2)) << 1);
1269 trace_output (OP_REG
);
1272 /* end-sanitize-v850e */
1274 unsigned int op0
, op1
, result
, ov
, s
, z
;
1277 trace_input ("divh", OP_REG_REG
, 0);
1279 /* Compute the result. */
1280 temp
= EXTEND16 (State
.regs
[ OP
[0] ]);
1282 op1
= State
.regs
[OP
[1]];
1284 if (op0
== 0xffffffff && op1
== 0x80000000)
1286 result
= 0x80000000;
1300 /* Compute the condition codes. */
1302 s
= (result
& 0x80000000);
1304 /* Store the result and condition codes. */
1305 State
.regs
[OP
[1]] = result
;
1306 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1307 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1308 | (ov
? PSW_OV
: 0));
1309 trace_output (OP_REG_REG
);
1319 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
1321 trace_input ("cmp", OP_REG_REG_CMP
, 0);
1322 /* Compute the result. */
1323 op0
= State
.regs
[ OP
[0] ];
1324 op1
= State
.regs
[ OP
[1] ];
1327 /* Compute the condition codes. */
1329 s
= (result
& 0x80000000);
1331 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
1332 && (op1
& 0x80000000) != (result
& 0x80000000));
1334 /* Set condition codes. */
1335 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1336 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1337 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
1338 trace_output (OP_REG_REG_CMP
);
1343 /* cmp sign_extend(imm5), reg */
1347 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
1350 /* Compute the result. */
1351 trace_input ("cmp", OP_IMM_REG_CMP
, 0);
1352 temp
= SEXT5 (OP
[0]);
1354 op1
= State
.regs
[OP
[1]];
1357 /* Compute the condition codes. */
1359 s
= (result
& 0x80000000);
1361 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
1362 && (op1
& 0x80000000) != (result
& 0x80000000));
1364 /* Set condition codes. */
1365 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1366 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1367 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
1368 trace_output (OP_IMM_REG_CMP
);
1373 /* setf cccc,reg2 */
1377 trace_input ("setf", OP_EX1
, 0);
1379 State
.regs
[ OP
[1] ] = condition_met (OP
[0]);
1381 trace_output (OP_EX1
);
1387 /* satadd reg,reg */
1391 /* start-sanitize-v850e */
1394 trace_input ("zxh", OP_REG
, 0);
1396 State
.regs
[ OP
[0] ] &= 0xffff;
1398 trace_output (OP_REG
);
1401 /* end-sanitize-v850e */
1403 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
1405 trace_input ("satadd", OP_REG_REG
, 0);
1406 /* Compute the result. */
1407 op0
= State
.regs
[ OP
[0] ];
1408 op1
= State
.regs
[ OP
[1] ];
1411 /* Compute the condition codes. */
1413 s
= (result
& 0x80000000);
1414 cy
= (result
< op0
|| result
< op1
);
1415 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
1416 && (op0
& 0x80000000) != (result
& 0x80000000));
1419 /* Store the result and condition codes. */
1420 State
.regs
[OP
[1]] = result
;
1421 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1422 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1423 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
1424 | (sat
? PSW_SAT
: 0));
1426 /* Handle saturated results. */
1428 State
.regs
[OP
[1]] = 0x80000000;
1430 State
.regs
[OP
[1]] = 0x7fffffff;
1431 trace_output (OP_REG_REG
);
1437 /* satadd sign_extend(imm5), reg */
1441 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
1445 trace_input ("satadd", OP_IMM_REG
, 0);
1447 /* Compute the result. */
1448 temp
= SEXT5 (OP
[0]);
1450 op1
= State
.regs
[OP
[1]];
1453 /* Compute the condition codes. */
1455 s
= (result
& 0x80000000);
1456 cy
= (result
< op0
|| result
< op1
);
1457 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
1458 && (op0
& 0x80000000) != (result
& 0x80000000));
1461 /* Store the result and condition codes. */
1462 State
.regs
[OP
[1]] = result
;
1463 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1464 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1465 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
1466 | (sat
? PSW_SAT
: 0));
1468 /* Handle saturated results. */
1470 State
.regs
[OP
[1]] = 0x80000000;
1472 State
.regs
[OP
[1]] = 0x7fffffff;
1473 trace_output (OP_IMM_REG
);
1478 /* satsub reg1, reg2 */
1483 /* start-sanitize-v850e */
1486 trace_input ("sxb", OP_REG
, 0);
1488 State
.regs
[ OP
[0] ] = EXTEND8 (State
.regs
[ OP
[0] ]);
1490 trace_output (OP_REG
);
1493 /* end-sanitize-v850e */
1495 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
1497 trace_input ("satsub", OP_REG_REG
, 0);
1499 /* Compute the result. */
1500 op0
= State
.regs
[ OP
[0] ];
1501 op1
= State
.regs
[ OP
[1] ];
1504 /* Compute the condition codes. */
1506 s
= (result
& 0x80000000);
1508 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
1509 && (op1
& 0x80000000) != (result
& 0x80000000));
1512 /* Store the result and condition codes. */
1513 State
.regs
[OP
[1]] = result
;
1514 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1515 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1516 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
1517 | (sat
? PSW_SAT
: 0));
1519 /* Handle saturated results. */
1521 State
.regs
[OP
[1]] = 0x80000000;
1523 State
.regs
[OP
[1]] = 0x7fffffff;
1524 trace_output (OP_REG_REG
);
1530 /* satsubi sign_extend(imm16), reg */
1534 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
1537 trace_input ("satsubi", OP_IMM_REG
, 0);
1539 /* Compute the result. */
1540 temp
= EXTEND16 (OP
[2]);
1542 op1
= State
.regs
[ OP
[0] ];
1545 /* Compute the condition codes. */
1547 s
= (result
& 0x80000000);
1549 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
1550 && (op1
& 0x80000000) != (result
& 0x80000000));
1553 /* Store the result and condition codes. */
1554 State
.regs
[OP
[1]] = result
;
1555 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1556 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1557 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
1558 | (sat
? PSW_SAT
: 0));
1560 /* Handle saturated results. */
1562 State
.regs
[OP
[1]] = 0x80000000;
1564 State
.regs
[OP
[1]] = 0x7fffffff;
1565 trace_output (OP_IMM_REG
);
1570 /* satsubr reg,reg */
1575 /* start-sanitize-v850e */
1578 trace_input ("zxb", OP_REG
, 0);
1580 State
.regs
[ OP
[0] ] &= 0xff;
1582 trace_output (OP_REG
);
1585 /* end-sanitize-v850e */
1587 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
1589 trace_input ("satsubr", OP_REG_REG
, 0);
1591 /* Compute the result. */
1592 op0
= State
.regs
[ OP
[0] ];
1593 op1
= State
.regs
[ OP
[1] ];
1596 /* Compute the condition codes. */
1598 s
= (result
& 0x80000000);
1599 cy
= (result
< op0
);
1600 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
1601 && (op1
& 0x80000000) != (result
& 0x80000000));
1604 /* Store the result and condition codes. */
1605 State
.regs
[OP
[1]] = result
;
1606 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1607 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1608 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
1609 | (sat
? PSW_SAT
: 0));
1611 /* Handle saturated results. */
1613 State
.regs
[OP
[1]] = 0x80000000;
1615 State
.regs
[OP
[1]] = 0x7fffffff;
1616 trace_output (OP_REG_REG
);
1626 unsigned int op0
, op1
, result
, z
, s
;
1628 trace_input ("tst", OP_REG_REG_CMP
, 0);
1630 /* Compute the result. */
1631 op0
= State
.regs
[ OP
[0] ];
1632 op1
= State
.regs
[ OP
[1] ];
1635 /* Compute the condition codes. */
1637 s
= (result
& 0x80000000);
1639 /* Store the condition codes. */
1640 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1641 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1642 trace_output (OP_REG_REG_CMP
);
1651 trace_input ("mov", OP_REG_REG_MOVE
, 0);
1653 State
.regs
[ OP
[1] ] = State
.regs
[ OP
[0] ];
1655 trace_output (OP_REG_REG_MOVE
);
1660 /* mov sign_extend(imm5), reg */
1665 /* start-sanitize-v850e */
1670 trace_input ("callt", OP_LOAD16
, 1);
1675 adr
= CTBP
+ ((OP
[3] & 0x3f) << 1);
1677 PC
= CTBP
+ load_mem (adr
, 1);
1679 trace_output (OP_LOAD16
);
1684 /* end-sanitize-v850e */
1686 int value
= SEXT5 (OP
[0]);
1688 trace_input ("mov", OP_IMM_REG_MOVE
, 0);
1690 State
.regs
[ OP
[1] ] = value
;
1692 trace_output (OP_IMM_REG_MOVE
);
1698 /* mov imm32, reg1 */
1699 /* movea sign_extend(imm16), reg, reg */
1703 /* start-sanitize-v850e */
1706 trace_input ("mov", OP_IMM_REG
, 4);
1708 State
.regs
[ OP
[0] ] = load_mem (PC
+ 2, 4);
1710 trace_output (OP_IMM_REG
);
1715 /* end-sanitize-v850e */
1717 trace_input ("movea", OP_IMM_REG_REG
, 0);
1719 State
.regs
[ OP
[1] ] = State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2]);
1721 trace_output (OP_IMM_REG_REG
);
1727 /* dispose imm5, list12 [, reg1] */
1728 /* movhi imm16, reg, reg */
1732 /* start-sanitize-v850e */
1738 trace_input ("dispose", OP_PUSHPOP1
, 0);
1740 SP
+= (OP
[3] & 0x3e) << 1;
1742 /* Load the registers with lower number registers being retrieved from higher addresses. */
1744 if ((OP
[3] & (1 << type1_regs
[ i
])))
1746 State
.regs
[ 20 + i
] = load_mem (SP
, 4);
1750 if ((OP
[3] & 0x1f0000) != 0)
1752 PC
= State
.regs
[ (OP
[3] >> 16) & 0x1f];
1756 trace_output (OP_PUSHPOP1
);
1759 /* end-sanitize-v850e */
1761 trace_input ("movhi", OP_UIMM_REG_REG
, 16);
1763 State
.regs
[ OP
[1] ] = State
.regs
[ OP
[0] ] + (OP
[2] << 16);
1765 trace_output (OP_UIMM_REG_REG
);
1771 /* sar zero_extend(imm5),reg1 */
1775 unsigned int op0
, op1
, result
, z
, s
, cy
;
1777 trace_input ("sar", OP_IMM_REG
, 0);
1779 op1
= State
.regs
[ OP
[1] ];
1780 result
= (signed)op1
>> op0
;
1782 /* Compute the condition codes. */
1784 s
= (result
& 0x80000000);
1785 cy
= (op1
& (1 << (op0
- 1)));
1787 /* Store the result and condition codes. */
1788 State
.regs
[ OP
[1] ] = result
;
1789 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1790 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1791 | (cy
? PSW_CY
: 0));
1792 trace_output (OP_IMM_REG
);
1797 /* sar reg1, reg2 */
1801 unsigned int op0
, op1
, result
, z
, s
, cy
;
1803 trace_input ("sar", OP_REG_REG
, 0);
1805 op0
= State
.regs
[ OP
[0] ] & 0x1f;
1806 op1
= State
.regs
[ OP
[1] ];
1807 result
= (signed)op1
>> op0
;
1809 /* Compute the condition codes. */
1811 s
= (result
& 0x80000000);
1812 cy
= (op1
& (1 << (op0
- 1)));
1814 /* Store the result and condition codes. */
1815 State
.regs
[OP
[1]] = result
;
1816 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1817 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1818 | (cy
? PSW_CY
: 0));
1819 trace_output (OP_REG_REG
);
1824 /* shl zero_extend(imm5),reg1 */
1828 unsigned int op0
, op1
, result
, z
, s
, cy
;
1830 trace_input ("shl", OP_IMM_REG
, 0);
1832 op1
= State
.regs
[ OP
[1] ];
1833 result
= op1
<< op0
;
1835 /* Compute the condition codes. */
1837 s
= (result
& 0x80000000);
1838 cy
= (op1
& (1 << (32 - op0
)));
1840 /* Store the result and condition codes. */
1841 State
.regs
[OP
[1]] = result
;
1842 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1843 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1844 | (cy
? PSW_CY
: 0));
1845 trace_output (OP_IMM_REG
);
1850 /* shl reg1, reg2 */
1854 unsigned int op0
, op1
, result
, z
, s
, cy
;
1856 trace_input ("shl", OP_REG_REG
, 0);
1857 op0
= State
.regs
[ OP
[0] ] & 0x1f;
1858 op1
= State
.regs
[ OP
[1] ];
1859 result
= op1
<< op0
;
1861 /* Compute the condition codes. */
1863 s
= (result
& 0x80000000);
1864 cy
= (op1
& (1 << (32 - op0
)));
1866 /* Store the result and condition codes. */
1867 State
.regs
[OP
[1]] = result
;
1868 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1869 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1870 | (cy
? PSW_CY
: 0));
1871 trace_output (OP_REG_REG
);
1876 /* shr zero_extend(imm5),reg1 */
1880 unsigned int op0
, op1
, result
, z
, s
, cy
;
1882 trace_input ("shr", OP_IMM_REG
, 0);
1884 op1
= State
.regs
[ OP
[1] ];
1885 result
= op1
>> op0
;
1887 /* Compute the condition codes. */
1889 s
= (result
& 0x80000000);
1890 cy
= (op1
& (1 << (op0
- 1)));
1892 /* Store the result and condition codes. */
1893 State
.regs
[OP
[1]] = result
;
1894 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1895 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1896 | (cy
? PSW_CY
: 0));
1897 trace_output (OP_IMM_REG
);
1902 /* shr reg1, reg2 */
1906 unsigned int op0
, op1
, result
, z
, s
, cy
;
1908 trace_input ("shr", OP_REG_REG
, 0);
1909 op0
= State
.regs
[ OP
[0] ] & 0x1f;
1910 op1
= State
.regs
[ OP
[1] ];
1911 result
= op1
>> op0
;
1913 /* Compute the condition codes. */
1915 s
= (result
& 0x80000000);
1916 cy
= (op1
& (1 << (op0
- 1)));
1918 /* Store the result and condition codes. */
1919 State
.regs
[OP
[1]] = result
;
1920 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1921 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1922 | (cy
? PSW_CY
: 0));
1923 trace_output (OP_REG_REG
);
1932 unsigned int op0
, op1
, result
, z
, s
;
1934 trace_input ("or", OP_REG_REG
, 0);
1936 /* Compute the result. */
1937 op0
= State
.regs
[ OP
[0] ];
1938 op1
= State
.regs
[ OP
[1] ];
1941 /* Compute the condition codes. */
1943 s
= (result
& 0x80000000);
1945 /* Store the result and condition codes. */
1946 State
.regs
[OP
[1]] = result
;
1947 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1948 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1949 trace_output (OP_REG_REG
);
1954 /* ori zero_extend(imm16), reg, reg */
1958 unsigned int op0
, op1
, result
, z
, s
;
1960 trace_input ("ori", OP_UIMM_REG_REG
, 0);
1962 op1
= State
.regs
[ OP
[0] ];
1965 /* Compute the condition codes. */
1967 s
= (result
& 0x80000000);
1969 /* Store the result and condition codes. */
1970 State
.regs
[OP
[1]] = result
;
1971 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1972 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1973 trace_output (OP_UIMM_REG_REG
);
1982 unsigned int op0
, op1
, result
, z
, s
;
1984 trace_input ("and", OP_REG_REG
, 0);
1986 /* Compute the result. */
1987 op0
= State
.regs
[ OP
[0] ];
1988 op1
= State
.regs
[ OP
[1] ];
1991 /* Compute the condition codes. */
1993 s
= (result
& 0x80000000);
1995 /* Store the result and condition codes. */
1996 State
.regs
[OP
[1]] = result
;
1997 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1998 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1999 trace_output (OP_REG_REG
);
2004 /* andi zero_extend(imm16), reg, reg */
2008 unsigned int result
, z
;
2010 trace_input ("andi", OP_UIMM_REG_REG
, 0);
2012 result
= OP
[2] & State
.regs
[ OP
[0] ];
2014 /* Compute the condition codes. */
2017 /* Store the result and condition codes. */
2018 State
.regs
[ OP
[1] ] = result
;
2020 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2021 PSW
|= (z
? PSW_Z
: 0);
2023 trace_output (OP_UIMM_REG_REG
);
2032 unsigned int op0
, op1
, result
, z
, s
;
2034 trace_input ("xor", OP_REG_REG
, 0);
2036 /* Compute the result. */
2037 op0
= State
.regs
[ OP
[0] ];
2038 op1
= State
.regs
[ OP
[1] ];
2041 /* Compute the condition codes. */
2043 s
= (result
& 0x80000000);
2045 /* Store the result and condition codes. */
2046 State
.regs
[OP
[1]] = result
;
2047 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2048 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
2049 trace_output (OP_REG_REG
);
2054 /* xori zero_extend(imm16), reg, reg */
2058 unsigned int op0
, op1
, result
, z
, s
;
2060 trace_input ("xori", OP_UIMM_REG_REG
, 0);
2062 op1
= State
.regs
[ OP
[0] ];
2065 /* Compute the condition codes. */
2067 s
= (result
& 0x80000000);
2069 /* Store the result and condition codes. */
2070 State
.regs
[OP
[1]] = result
;
2071 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2072 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
2073 trace_output (OP_UIMM_REG_REG
);
2078 /* not reg1, reg2 */
2082 unsigned int op0
, result
, z
, s
;
2084 trace_input ("not", OP_REG_REG_MOVE
, 0);
2085 /* Compute the result. */
2086 op0
= State
.regs
[ OP
[0] ];
2089 /* Compute the condition codes. */
2091 s
= (result
& 0x80000000);
2093 /* Store the result and condition codes. */
2094 State
.regs
[OP
[1]] = result
;
2095 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2096 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
2097 trace_output (OP_REG_REG_MOVE
);
2106 unsigned int op0
, op1
, op2
;
2109 trace_input ("set1", OP_BIT
, 0);
2110 op0
= State
.regs
[ OP
[0] ];
2112 temp
= EXTEND16 (OP
[2]);
2114 temp
= load_mem (op0
+ op2
, 1);
2116 if ((temp
& (1 << op1
)) == 0)
2119 store_mem (op0
+ op2
, 1, temp
);
2120 trace_output (OP_BIT
);
2129 unsigned int op0
, op1
, op2
;
2132 trace_input ("not1", OP_BIT
, 0);
2133 op0
= State
.regs
[ OP
[0] ];
2135 temp
= EXTEND16 (OP
[2]);
2137 temp
= load_mem (op0
+ op2
, 1);
2139 if ((temp
& (1 << op1
)) == 0)
2142 store_mem (op0
+ op2
, 1, temp
);
2143 trace_output (OP_BIT
);
2152 unsigned int op0
, op1
, op2
;
2155 trace_input ("clr1", OP_BIT
, 0);
2156 op0
= State
.regs
[ OP
[0] ];
2158 temp
= EXTEND16 (OP
[2]);
2160 temp
= load_mem (op0
+ op2
, 1);
2162 if ((temp
& (1 << op1
)) == 0)
2164 temp
&= ~(1 << op1
);
2165 store_mem (op0
+ op2
, 1, temp
);
2166 trace_output (OP_BIT
);
2175 unsigned int op0
, op1
, op2
;
2178 trace_input ("tst1", OP_BIT
, 0);
2179 op0
= State
.regs
[ OP
[0] ];
2181 temp
= EXTEND16 (OP
[2]);
2183 temp
= load_mem (op0
+ op2
, 1);
2185 if ((temp
& (1 << op1
)) == 0)
2187 trace_output (OP_BIT
);
2196 sim_engine_halt (simulator
, STATE_CPU (simulator
, 0), NULL
, PC
,
2197 sim_stopped
, SIGTRAP
);
2205 trace_input ("di", OP_NONE
, 0);
2207 trace_output (OP_NONE
);
2216 trace_input ("ei", OP_NONE
, 0);
2218 trace_output (OP_NONE
);
2227 trace_input ("halt", OP_NONE
, 0);
2228 /* FIXME this should put processor into a mode where NMI still handled */
2229 trace_output (OP_NONE
);
2230 sim_engine_halt (simulator
, STATE_CPU (simulator
, 0), NULL
, PC
,
2231 sim_stopped
, SIGTRAP
);
2239 trace_input ("reti", OP_NONE
, 0);
2240 trace_output (OP_NONE
);
2242 /* Restore for NMI if only NP on, otherwise is interrupt or exception. */
2243 if ((PSW
& (PSW_NP
| PSW_EP
)) == PSW_NP
)
2261 trace_input ("trap", OP_TRAP
, 0);
2262 trace_output (OP_TRAP
);
2264 /* Trap 31 is used for simulating OS I/O functions */
2268 int save_errno
= errno
;
2271 /* Registers passed to trap 0 */
2273 #define FUNC State.regs[6] /* function number, return value */
2274 #define PARM1 State.regs[7] /* optional parm 1 */
2275 #define PARM2 State.regs[8] /* optional parm 2 */
2276 #define PARM3 State.regs[9] /* optional parm 3 */
2278 /* Registers set by trap 0 */
2280 #define RETVAL State.regs[10] /* return value */
2281 #define RETERR State.regs[11] /* return error code */
2283 /* Turn a pointer in a register into a pointer into real memory. */
2285 #define MEMPTR(x) (map (x))
2302 char *path
= fetch_str (simulator
, PARM1
);
2303 char **argv
= fetch_argv (simulator
, PARM2
);
2304 char **envp
= fetch_argv (simulator
, PARM3
);
2305 RETVAL
= execve (path
, argv
, envp
);
2318 char *path
= fetch_str (simulator
, PARM1
);
2319 char **argv
= fetch_argv (simulator
, PARM2
);
2320 RETVAL
= execv (path
, argv
);
2336 RETVAL
= pipe (host_fd
);
2337 SW (buf
, host_fd
[0]);
2338 buf
+= sizeof(uint16
);
2339 SW (buf
, host_fd
[1]);
2351 RETVAL
= wait (&status
);
2361 char *buf
= zalloc (PARM3
);
2362 RETVAL
= sim_io_read (simulator
, PARM1
, buf
, PARM3
);
2363 sim_write (simulator
, PARM2
, buf
, PARM3
);
2372 char *buf
= zalloc (PARM3
);
2373 sim_read (simulator
, PARM2
, buf
, PARM3
);
2375 RETVAL
= sim_io_write_stdout (simulator
, buf
, PARM3
);
2377 RETVAL
= sim_io_write (simulator
, PARM1
, buf
, PARM3
);
2385 RETVAL
= sim_io_lseek (simulator
, PARM1
, PARM2
, PARM3
);
2391 RETVAL
= sim_io_close (simulator
, PARM1
);
2398 char *buf
= fetch_str (simulator
, PARM1
);
2399 RETVAL
= sim_io_open (simulator
, buf
, PARM2
);
2407 if ((PARM1
& 0xffff0000) == 0xdead0000 && (PARM1
& 0xffff) != 0)
2408 /* get signal encoded by kill */
2409 sim_engine_halt (simulator
, STATE_CPU (simulator
, 0), NULL
, PC
,
2410 sim_signalled
, PARM1
& 0xffff);
2411 else if (PARM1
== 0xdead)
2413 sim_engine_halt (simulator
, STATE_CPU (simulator
, 0), NULL
, PC
,
2414 sim_exited
, SIGABRT
);
2416 /* PARM1 has exit status */
2417 sim_engine_halt (simulator
, STATE_CPU (simulator
, 0), NULL
, PC
,
2422 #if !defined(__GO32__) && !defined(_WIN32)
2424 case SYS_stat
: /* added at hmsi */
2425 /* stat system call */
2427 struct stat host_stat
;
2429 char *path
= fetch_str (simulator
, PARM1
);
2431 RETVAL
= stat (path
, &host_stat
);
2436 /* Just wild-assed guesses. */
2437 store_mem (buf
, 2, host_stat
.st_dev
);
2438 store_mem (buf
+ 2, 2, host_stat
.st_ino
);
2439 store_mem (buf
+ 4, 4, host_stat
.st_mode
);
2440 store_mem (buf
+ 8, 2, host_stat
.st_nlink
);
2441 store_mem (buf
+ 10, 2, host_stat
.st_uid
);
2442 store_mem (buf
+ 12, 2, host_stat
.st_gid
);
2443 store_mem (buf
+ 14, 2, host_stat
.st_rdev
);
2444 store_mem (buf
+ 16, 4, host_stat
.st_size
);
2445 store_mem (buf
+ 20, 4, host_stat
.st_atime
);
2446 store_mem (buf
+ 28, 4, host_stat
.st_mtime
);
2447 store_mem (buf
+ 36, 4, host_stat
.st_ctime
);
2457 char *path
= fetch_str (simulator
, PARM1
);
2458 RETVAL
= chown (path
, PARM2
, PARM3
);
2469 char *path
= fetch_str (simulator
, PARM1
);
2470 RETVAL
= chmod (path
, PARM2
);
2482 RETVAL
= time (&now
);
2483 store_mem (PARM1
, 4, now
);
2489 #if !defined(__GO32__) && !defined(_WIN32)
2494 RETVAL
= times (&tms
);
2495 store_mem (PARM1
, 4, tms
.tms_utime
);
2496 store_mem (PARM1
+ 4, 4, tms
.tms_stime
);
2497 store_mem (PARM1
+ 8, 4, tms
.tms_cutime
);
2498 store_mem (PARM1
+ 12, 4, tms
.tms_cstime
);
2504 #ifdef SYS_gettimeofday
2505 #if !defined(__GO32__) && !defined(_WIN32)
2506 case SYS_gettimeofday
:
2510 RETVAL
= gettimeofday (&t
, &tz
);
2511 store_mem (PARM1
, 4, t
.tv_sec
);
2512 store_mem (PARM1
+ 4, 4, t
.tv_usec
);
2513 store_mem (PARM2
, 4, tz
.tz_minuteswest
);
2514 store_mem (PARM2
+ 4, 4, tz
.tz_dsttime
);
2524 /* Cast the second argument to void *, to avoid type mismatch
2525 if a prototype is present. */
2526 sim_io_error (simulator
, "Utime not supported");
2527 /* RETVAL = utime (path, (void *) MEMPTR (PARM2)); */
2542 { /* Trap 0 -> 30 */
2547 ECR
|= 0x40 + OP
[0];
2548 /* Flag that we are now doing exception processing. */
2549 PSW
|= PSW_EP
| PSW_ID
;
2550 PC
= ((OP
[0] < 0x10) ? 0x40 : 0x50) - 4;
2560 trace_input ("ldsr", OP_LDSR
, 0);
2562 State
.sregs
[ OP
[1] ] = State
.regs
[ OP
[0] ];
2564 trace_output (OP_LDSR
);
2573 trace_input ("stsr", OP_STSR
, 0);
2575 State
.regs
[ OP
[1] ] = State
.sregs
[ OP
[0] ];
2577 trace_output (OP_STSR
);
2582 /* tst1 reg2, [reg1] */
2588 trace_input ("tst1", OP_BIT
, 1);
2590 temp
= load_mem (State
.regs
[ OP
[0] ], 1);
2593 if ((temp
& (1 << State
.regs
[ OP
[1] & 0x7 ])) == 0)
2596 trace_output (OP_BIT
);
2601 /* mulu reg1, reg2, reg3 */
2605 trace_input ("mulu", OP_REG_REG_REG
, 0);
2607 Multiply64 (false, State
.regs
[ OP
[0] ]);
2609 trace_output (OP_REG_REG_REG
);
2614 /* start-sanitize-v850e */
2616 #define BIT_CHANGE_OP( name, binop ) \
2618 unsigned int temp; \
2620 trace_input (name, OP_BIT_CHANGE, 0); \
2622 bit = 1 << State.regs[ OP[1] & 0x7 ]; \
2623 temp = load_mem (State.regs[ OP[0] ], 1); \
2626 if ((temp & bit) == 0) \
2630 store_mem (State.regs[ OP[0] ], 1, temp); \
2632 trace_output (OP_BIT_CHANGE); \
2636 /* clr1 reg2, [reg1] */
2640 BIT_CHANGE_OP ("clr1", &= ~ );
2643 /* not1 reg2, [reg1] */
2647 BIT_CHANGE_OP ("not1", ^= );
2654 BIT_CHANGE_OP ("set1", |= );
2661 trace_input ("sasf", OP_EX1
, 0);
2663 State
.regs
[ OP
[1] ] = (State
.regs
[ OP
[1] ] << 1) | condition_met (OP
[0]);
2665 trace_output (OP_EX1
);
2669 /* end-sanitize-v850e */
2671 /* start-sanitize-v850eq */
2672 /* This function is courtesy of Sugimoto at NEC, via Seow Tan (Soew_Tan@el.nec.com) */
2677 unsigned long int als
,
2678 unsigned long int sfi
,
2679 unsigned long int * quotient_ptr
,
2680 unsigned long int * remainder_ptr
,
2681 boolean
* overflow_ptr
2684 unsigned long ald
= sfi
>> (N
- 1);
2685 unsigned long alo
= als
;
2690 unsigned int R1
= 1;
2691 unsigned int DBZ
= (als
== 0) ? 1 : 0;
2692 unsigned long alt
= Q
? ~als
: als
;
2695 alo
= ald
+ alt
+ Q
;
2696 C
= (((alt
>> 31) & (ald
>> 31))
2697 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2700 R1
= (alo
== 0) ? 0 : (R1
& Q
);
2701 if ((S
^ (alo
>>31)) && !C
)
2706 sfi
= (sfi
<< (32-N
+1)) | Q
;
2707 ald
= (alo
<< 1) | (sfi
>> 31);
2709 /* 2nd - N-1th Loop */
2710 for (i
= 2; i
< N
; i
++)
2712 alt
= Q
? ~als
: als
;
2713 alo
= ald
+ alt
+ Q
;
2714 C
= (((alt
>> 31) & (ald
>> 31))
2715 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2718 R1
= (alo
== 0) ? 0 : (R1
& Q
);
2719 if ((S
^ (alo
>>31)) && !C
&& !DBZ
)
2724 sfi
= (sfi
<< 1) | Q
;
2725 ald
= (alo
<< 1) | (sfi
>> 31);
2729 alt
= Q
? ~als
: als
;
2730 alo
= ald
+ alt
+ Q
;
2731 C
= (((alt
>> 31) & (ald
>> 31))
2732 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2735 R1
= (alo
== 0) ? 0 : (R1
& Q
);
2736 if ((S
^ (alo
>>31)) && !C
)
2741 * quotient_ptr
= (sfi
<< 1) | Q
;
2742 * remainder_ptr
= Q
? alo
: (alo
+ als
);
2743 * overflow_ptr
= DBZ
| R1
;
2746 /* This function is courtesy of Sugimoto at NEC, via Seow Tan (Soew_Tan@el.nec.com) */
2751 unsigned long int als
,
2752 unsigned long int sfi
,
2753 signed long int * quotient_ptr
,
2754 signed long int * remainder_ptr
,
2755 boolean
* overflow_ptr
2758 unsigned long ald
= (signed long) sfi
>> (N
- 1);
2759 unsigned long alo
= als
;
2760 unsigned int SS
= als
>> 31;
2761 unsigned int SD
= sfi
>> 31;
2762 unsigned int R1
= 1;
2764 unsigned int DBZ
= als
== 0 ? 1 : 0;
2765 unsigned int Q
= ~(SS
^ SD
) & 1;
2769 unsigned long alt
= Q
? ~als
: als
;
2774 alo
= ald
+ alt
+ Q
;
2775 C
= (((alt
>> 31) & (ald
>> 31))
2776 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2778 R1
= (alo
== 0) ? 0 : (R1
& (Q
^ (SS
^ SD
)));
2780 sfi
= (sfi
<< (32-N
+1)) | Q
;
2781 ald
= (alo
<< 1) | (sfi
>> 31);
2782 if ((alo
>> 31) ^ (ald
>> 31))
2787 /* 2nd - N-1th Loop */
2789 for (i
= 2; i
< N
; i
++)
2791 alt
= Q
? ~als
: als
;
2792 alo
= ald
+ alt
+ Q
;
2793 C
= (((alt
>> 31) & (ald
>> 31))
2794 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2796 R1
= (alo
== 0) ? 0 : (R1
& (Q
^ (SS
^ SD
)));
2798 sfi
= (sfi
<< 1) | Q
;
2799 ald
= (alo
<< 1) | (sfi
>> 31);
2800 if ((alo
>> 31) ^ (ald
>> 31))
2807 alt
= Q
? ~als
: als
;
2808 alo
= ald
+ alt
+ Q
;
2809 C
= (((alt
>> 31) & (ald
>> 31))
2810 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2812 R1
= (alo
== 0) ? 0 : (R1
& (Q
^ (SS
^ SD
)));
2813 sfi
= (sfi
<< (32-N
+1));
2819 alt
= Q
? ~als
: als
;
2820 alo
= ald
+ alt
+ Q
;
2822 R1
= R1
& ((~alo
>> 31) ^ SD
);
2823 if ((alo
!= 0) && ((Q
^ (SS
^ SD
)) ^ R1
)) alo
= ald
;
2825 ald
= sfi
= (long) ((sfi
>> 1) | (SS
^ SD
) << 31) >> (32-N
-1) | Q
;
2827 ald
= sfi
= sfi
| Q
;
2829 OV
= DBZ
| ((alo
== 0) ? 0 : R1
);
2831 * remainder_ptr
= alo
;
2834 if (((alo
!= 0) && ((SS
^ SD
) ^ R1
))
2835 || ((alo
== 0) && (SS
^ R1
)))
2840 OV
= (DBZ
| R1
) ? OV
: ((alo
>> 31) & (~ald
>> 31));
2842 * quotient_ptr
= alo
;
2843 * overflow_ptr
= OV
;
2846 /* sdivun imm5, reg1, reg2, reg3 */
2850 unsigned long int quotient
;
2851 unsigned long int remainder
;
2852 unsigned long int divide_by
;
2853 unsigned long int divide_this
;
2854 boolean overflow
= false;
2857 trace_input ("sdivun", OP_IMM_REG_REG_REG
, 0);
2859 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2861 divide_by
= State
.regs
[ OP
[0] ];
2862 divide_this
= State
.regs
[ OP
[1] ] << imm5
;
2864 divun (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2866 State
.regs
[ OP
[1] ] = quotient
;
2867 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2869 /* Set condition codes. */
2870 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2872 if (overflow
) PSW
|= PSW_OV
;
2873 if (quotient
== 0) PSW
|= PSW_Z
;
2874 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2876 trace_output (OP_IMM_REG_REG_REG
);
2881 /* sdivn imm5, reg1, reg2, reg3 */
2885 signed long int quotient
;
2886 signed long int remainder
;
2887 signed long int divide_by
;
2888 signed long int divide_this
;
2889 boolean overflow
= false;
2892 trace_input ("sdivn", OP_IMM_REG_REG_REG
, 0);
2894 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2896 divide_by
= State
.regs
[ OP
[0] ];
2897 divide_this
= State
.regs
[ OP
[1] ] << imm5
;
2899 divn (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2901 State
.regs
[ OP
[1] ] = quotient
;
2902 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2904 /* Set condition codes. */
2905 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2907 if (overflow
) PSW
|= PSW_OV
;
2908 if (quotient
== 0) PSW
|= PSW_Z
;
2909 if (quotient
< 0) PSW
|= PSW_S
;
2911 trace_output (OP_IMM_REG_REG_REG
);
2916 /* sdivhun imm5, reg1, reg2, reg3 */
2920 unsigned long int quotient
;
2921 unsigned long int remainder
;
2922 unsigned long int divide_by
;
2923 unsigned long int divide_this
;
2924 boolean overflow
= false;
2927 trace_input ("sdivhun", OP_IMM_REG_REG_REG
, 0);
2929 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2931 divide_by
= State
.regs
[ OP
[0] ] & 0xffff;
2932 divide_this
= State
.regs
[ OP
[1] ] << imm5
;
2934 divun (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2936 State
.regs
[ OP
[1] ] = quotient
;
2937 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2939 /* Set condition codes. */
2940 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2942 if (overflow
) PSW
|= PSW_OV
;
2943 if (quotient
== 0) PSW
|= PSW_Z
;
2944 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2946 trace_output (OP_IMM_REG_REG_REG
);
2951 /* sdivhn imm5, reg1, reg2, reg3 */
2955 signed long int quotient
;
2956 signed long int remainder
;
2957 signed long int divide_by
;
2958 signed long int divide_this
;
2959 boolean overflow
= false;
2962 trace_input ("sdivhn", OP_IMM_REG_REG_REG
, 0);
2964 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2966 divide_by
= EXTEND16 (State
.regs
[ OP
[0] ]);
2967 divide_this
= State
.regs
[ OP
[1] ] << imm5
;
2969 divn (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2971 State
.regs
[ OP
[1] ] = quotient
;
2972 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2974 /* Set condition codes. */
2975 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2977 if (overflow
) PSW
|= PSW_OV
;
2978 if (quotient
== 0) PSW
|= PSW_Z
;
2979 if (quotient
< 0) PSW
|= PSW_S
;
2981 trace_output (OP_IMM_REG_REG_REG
);
2985 /* end-sanitize-v850eq */
2987 /* start-sanitize-v850e */
2988 /* divu reg1, reg2, reg3 */
2992 unsigned long int quotient
;
2993 unsigned long int remainder
;
2994 unsigned long int divide_by
;
2995 unsigned long int divide_this
;
2996 boolean overflow
= false;
2998 if ((OP
[3] & 0x3c0000) == 0)
3000 trace_input ("divu", OP_REG_REG_REG
, 0);
3002 /* Compute the result. */
3004 divide_by
= State
.regs
[ OP
[0] ];
3005 divide_this
= State
.regs
[ OP
[1] ];
3013 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
3014 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
3016 /* Set condition codes. */
3017 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3019 if (overflow
) PSW
|= PSW_OV
;
3020 if (quotient
== 0) PSW
|= PSW_Z
;
3021 if (quotient
& 0x80000000) PSW
|= PSW_S
;
3023 trace_output (OP_REG_REG_REG
);
3025 /* start-sanitize-v850eq */
3026 /* divun imm5, reg1, reg2, reg3 */
3031 trace_input ("divun", OP_IMM_REG_REG_REG
, 0);
3033 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
3035 divide_by
= State
.regs
[ OP
[0] ];
3036 divide_this
= State
.regs
[ OP
[1] ];
3038 divun (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
3040 State
.regs
[ OP
[1] ] = quotient
;
3041 State
.regs
[ OP
[2] >> 11 ] = remainder
;
3043 /* Set condition codes. */
3044 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3046 if (overflow
) PSW
|= PSW_OV
;
3047 if (quotient
== 0) PSW
|= PSW_Z
;
3048 if (quotient
& 0x80000000) PSW
|= PSW_S
;
3050 trace_output (OP_IMM_REG_REG_REG
);
3052 /* end-sanitize-v850eq */
3057 /* div reg1, reg2, reg3 */
3061 signed long int quotient
;
3062 signed long int remainder
;
3063 signed long int divide_by
;
3064 signed long int divide_this
;
3065 boolean overflow
= false;
3067 if ((OP
[3] & 0x3c0000) == 0)
3069 trace_input ("div", OP_REG_REG_REG
, 0);
3071 /* Compute the result. */
3073 divide_by
= State
.regs
[ OP
[0] ];
3074 divide_this
= State
.regs
[ OP
[1] ];
3076 if (divide_by
== 0 || (divide_by
== -1 && divide_this
== (1 << 31)))
3082 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
3083 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
3085 /* Set condition codes. */
3086 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3088 if (overflow
) PSW
|= PSW_OV
;
3089 if (quotient
== 0) PSW
|= PSW_Z
;
3090 if (quotient
< 0) PSW
|= PSW_S
;
3092 trace_output (OP_REG_REG_REG
);
3094 /* start-sanitize-v850eq */
3095 /* divn imm5, reg1, reg2, reg3 */
3100 trace_input ("divn", OP_IMM_REG_REG_REG
, 0);
3102 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
3104 divide_by
= State
.regs
[ OP
[0] ];
3105 divide_this
= State
.regs
[ OP
[1] ];
3107 divn (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
3109 State
.regs
[ OP
[1] ] = quotient
;
3110 State
.regs
[ OP
[2] >> 11 ] = remainder
;
3112 /* Set condition codes. */
3113 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3115 if (overflow
) PSW
|= PSW_OV
;
3116 if (quotient
== 0) PSW
|= PSW_Z
;
3117 if (quotient
< 0) PSW
|= PSW_S
;
3119 trace_output (OP_IMM_REG_REG_REG
);
3121 /* end-sanitize-v850eq */
3126 /* divhu reg1, reg2, reg3 */
3130 unsigned long int quotient
;
3131 unsigned long int remainder
;
3132 unsigned long int divide_by
;
3133 unsigned long int divide_this
;
3134 boolean overflow
= false;
3136 if ((OP
[3] & 0x3c0000) == 0)
3138 trace_input ("divhu", OP_REG_REG_REG
, 0);
3140 /* Compute the result. */
3142 divide_by
= State
.regs
[ OP
[0] ] & 0xffff;
3143 divide_this
= State
.regs
[ OP
[1] ];
3151 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
3152 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
3154 /* Set condition codes. */
3155 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3157 if (overflow
) PSW
|= PSW_OV
;
3158 if (quotient
== 0) PSW
|= PSW_Z
;
3159 if (quotient
& 0x80000000) PSW
|= PSW_S
;
3161 trace_output (OP_REG_REG_REG
);
3163 /* start-sanitize-v850eq */
3164 /* divhun imm5, reg1, reg2, reg3 */
3169 trace_input ("divhun", OP_IMM_REG_REG_REG
, 0);
3171 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
3173 divide_by
= State
.regs
[ OP
[0] ] & 0xffff;
3174 divide_this
= State
.regs
[ OP
[1] ];
3176 divun (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
3178 State
.regs
[ OP
[1] ] = quotient
;
3179 State
.regs
[ OP
[2] >> 11 ] = remainder
;
3181 /* Set condition codes. */
3182 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3184 if (overflow
) PSW
|= PSW_OV
;
3185 if (quotient
== 0) PSW
|= PSW_Z
;
3186 if (quotient
& 0x80000000) PSW
|= PSW_S
;
3188 trace_output (OP_IMM_REG_REG_REG
);
3190 /* end-sanitize-v850eq */
3195 /* divh reg1, reg2, reg3 */
3199 signed long int quotient
;
3200 signed long int remainder
;
3201 signed long int divide_by
;
3202 signed long int divide_this
;
3203 boolean overflow
= false;
3205 if ((OP
[3] & 0x3c0000) == 0)
3207 trace_input ("divh", OP_REG_REG_REG
, 0);
3209 /* Compute the result. */
3211 divide_by
= State
.regs
[ OP
[0] ];
3212 divide_this
= EXTEND16 (State
.regs
[ OP
[1] ]);
3214 if (divide_by
== 0 || (divide_by
== -1 && divide_this
== (1 << 31)))
3220 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
3221 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
3223 /* Set condition codes. */
3224 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3226 if (overflow
) PSW
|= PSW_OV
;
3227 if (quotient
== 0) PSW
|= PSW_Z
;
3228 if (quotient
< 0) PSW
|= PSW_S
;
3230 trace_output (OP_REG_REG_REG
);
3232 /* start-sanitize-v850eq */
3233 /* divhn imm5, reg1, reg2, reg3 */
3238 trace_input ("divhn", OP_IMM_REG_REG_REG
, 0);
3240 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
3242 divide_by
= EXTEND16 (State
.regs
[ OP
[0] ]);
3243 divide_this
= State
.regs
[ OP
[1] ];
3245 divn (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
3247 State
.regs
[ OP
[1] ] = quotient
;
3248 State
.regs
[ OP
[2] >> 11 ] = remainder
;
3250 /* Set condition codes. */
3251 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3253 if (overflow
) PSW
|= PSW_OV
;
3254 if (quotient
== 0) PSW
|= PSW_Z
;
3255 if (quotient
< 0) PSW
|= PSW_S
;
3257 trace_output (OP_IMM_REG_REG_REG
);
3259 /* end-sanitize-v850eq */
3264 /* mulu imm9, reg2, reg3 */
3268 trace_input ("mulu", OP_IMM_REG_REG
, 0);
3270 Multiply64 (false, (OP
[3] & 0x1f) | ((OP
[3] >> 13) & 0x1e0));
3272 trace_output (OP_IMM_REG_REG
);
3277 /* mul imm9, reg2, reg3 */
3281 trace_input ("mul", OP_IMM_REG_REG
, 0);
3283 Multiply64 (true, (OP
[3] & 0x1f) | ((OP
[3] >> 13) & 0x1e0));
3285 trace_output (OP_IMM_REG_REG
);
3290 /* cmov imm5, reg2, reg3 */
3294 trace_input ("cmov", OP_IMM_REG_REG
, 0);
3296 State
.regs
[ OP
[2] >> 11 ] = condition_met (OP
[0]) ? SEXT5( OP
[0] ) : State
.regs
[ OP
[1] ];
3298 trace_output (OP_IMM_REG_REG
);
3308 trace_input ("ctret", OP_NONE
, 0);
3313 trace_output (OP_NONE
);
3322 unsigned long value
;
3324 trace_input ("hsw", OP_REG_REG3
, 0);
3326 value
= State
.regs
[ OP
[ 1 ] ];
3328 value
|= (State
.regs
[ OP
[ 1 ] ] << 16);
3330 State
.regs
[ OP
[2] >> 11 ] = value
;
3332 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
3334 if (value
== 0) PSW
|= PSW_Z
;
3335 if (value
& 0x80000000) PSW
|= PSW_S
;
3336 if (((value
& 0xffff) == 0) || (value
& 0xffff0000) == 0) PSW
|= PSW_CY
;
3338 trace_output (OP_REG_REG3
);
3343 #define WORDHASNULLBYTE(x) (((x) - 0x01010101) & ~(x)&0x80808080)
3349 unsigned long value
;
3351 trace_input ("bsw", OP_REG_REG3
, 0);
3353 value
= State
.regs
[ OP
[ 1 ] ];
3355 value
|= (State
.regs
[ OP
[ 1 ] ] << 24);
3356 value
|= ((State
.regs
[ OP
[ 1 ] ] << 8) & 0x00ff0000);
3357 value
|= ((State
.regs
[ OP
[ 1 ] ] >> 8) & 0x0000ff00);
3359 State
.regs
[ OP
[2] >> 11 ] = value
;
3361 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
3363 if (value
== 0) PSW
|= PSW_Z
;
3364 if (value
& 0x80000000) PSW
|= PSW_S
;
3365 if (WORDHASNULLBYTE (value
)) PSW
|= PSW_CY
;
3367 trace_output (OP_REG_REG3
);
3376 unsigned long value
;
3378 trace_input ("bsh", OP_REG_REG3
, 0);
3380 value
= State
.regs
[ OP
[ 1 ] ];
3382 value
|= ((State
.regs
[ OP
[ 1 ] ] << 8) & 0xff00ff00);
3383 value
|= ((State
.regs
[ OP
[ 1 ] ] >> 8) & 0x000000ff);
3385 State
.regs
[ OP
[2] >> 11 ] = value
;
3387 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
3389 if (value
== 0) PSW
|= PSW_Z
;
3390 if (value
& 0x80000000) PSW
|= PSW_S
;
3391 if (((value
& 0xff) == 0) || (value
& 0x00ff) == 0) PSW
|= PSW_CY
;
3393 trace_output (OP_REG_REG3
);
3407 trace_input ("pushml", OP_PUSHPOP3
, 0);
3409 /* Store the registers with lower number registers being placed at higher addresses. */
3410 for (i
= 0; i
< 15; i
++)
3411 if ((OP
[3] & (1 << type3_regs
[ i
])))
3414 store_mem (SP
& ~ 3, 4, State
.regs
[ i
+ 1 ]);
3417 if (OP
[3] & (1 << 3))
3421 store_mem (SP
& ~ 3, 4, PSW
);
3424 if (OP
[3] & (1 << 19))
3428 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
3430 store_mem ((SP
+ 4) & ~ 3, 4, FEPC
);
3431 store_mem ( SP
& ~ 3, 4, FEPSW
);
3435 store_mem ((SP
+ 4) & ~ 3, 4, EIPC
);
3436 store_mem ( SP
& ~ 3, 4, EIPSW
);
3440 trace_output (OP_PUSHPOP2
);
3446 trace_input ("ld.hu", OP_LOAD32
, 2);
3448 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2] & ~1);
3451 State
.regs
[ OP
[1] ] = load_mem (adr
, 2);
3453 trace_output (OP_LOAD32
);
3459 /* prepare list12, imm5 */
3468 trace_input ("prepare", OP_PUSHPOP1
, 0);
3470 /* Store the registers with lower number registers being placed at higher addresses. */
3471 for (i
= 0; i
< 12; i
++)
3472 if ((OP
[3] & (1 << type1_regs
[ i
])))
3475 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
3478 SP
-= (OP
[3] & 0x3e) << 1;
3480 trace_output (OP_PUSHPOP1
);
3486 trace_input ("ld.bu", OP_LOAD32
, 1);
3488 adr
= (State
.regs
[ OP
[0] ]
3489 + (EXTEND16 (OP
[2] & ~1) | ((OP
[3] >> 5) & 1)));
3491 State
.regs
[ OP
[1] ] = load_mem (adr
, 1);
3493 trace_output (OP_LOAD32
);
3499 /* prepare list12, imm5, imm32 */
3505 trace_input ("prepare", OP_PUSHPOP1
, 0);
3507 /* Store the registers with lower number registers being placed at higher addresses. */
3508 for (i
= 0; i
< 12; i
++)
3509 if ((OP
[3] & (1 << type1_regs
[ i
])))
3512 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
3515 SP
-= (OP
[3] & 0x3e) << 1;
3517 EP
= load_mem (PC
+ 4, 4);
3519 trace_output (OP_PUSHPOP1
);
3524 /* prepare list12, imm5, imm16-32 */
3530 trace_input ("prepare", OP_PUSHPOP1
, 0);
3532 /* Store the registers with lower number registers being placed at higher addresses. */
3533 for (i
= 0; i
< 12; i
++)
3534 if ((OP
[3] & (1 << type1_regs
[ i
])))
3537 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
3540 SP
-= (OP
[3] & 0x3e) << 1;
3542 EP
= load_mem (PC
+ 4, 2) << 16;
3544 trace_output (OP_PUSHPOP1
);
3549 /* prepare list12, imm5, imm16 */
3555 trace_input ("prepare", OP_PUSHPOP1
, 0);
3557 /* Store the registers with lower number registers being placed at higher addresses. */
3558 for (i
= 0; i
< 12; i
++)
3559 if ((OP
[3] & (1 << type1_regs
[ i
])))
3562 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
3565 SP
-= (OP
[3] & 0x3e) << 1;
3567 EP
= EXTEND16 (load_mem (PC
+ 4, 2));
3569 trace_output (OP_PUSHPOP1
);
3574 /* prepare list12, imm5, sp */
3580 trace_input ("prepare", OP_PUSHPOP1
, 0);
3582 /* Store the registers with lower number registers being placed at higher addresses. */
3583 for (i
= 0; i
< 12; i
++)
3584 if ((OP
[3] & (1 << type1_regs
[ i
])))
3587 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
3590 SP
-= (OP
[3] & 0x3e) << 1;
3594 trace_output (OP_PUSHPOP1
);
3603 unsigned long result
;
3605 result
= load_mem (State
.regs
[30] + ((OP
[3] & 0xf) << 1), 2);
3607 /* start-sanitize-v850eq */
3609 trace_input ("sld.h", OP_LOAD16
, 2);
3611 State
.regs
[ OP
[1] ] = EXTEND16 (result
);
3613 /* end-sanitize-v850eq */
3614 trace_input ("sld.hu", OP_LOAD16
, 2);
3616 State
.regs
[ OP
[1] ] = result
;
3617 /* start-sanitize-v850eq */
3619 /* end-sanitize-v850eq */
3621 trace_output (OP_LOAD16
);
3626 /* cmov reg1, reg2, reg3 */
3630 trace_input ("cmov", OP_REG_REG_REG
, 0);
3632 State
.regs
[ OP
[2] >> 11 ] = condition_met (OP
[0]) ? State
.regs
[ OP
[0] ] : State
.regs
[ OP
[1] ];
3634 trace_output (OP_REG_REG_REG
);
3639 /* mul reg1, reg2, reg3 */
3643 trace_input ("mul", OP_REG_REG_REG
, 0);
3645 Multiply64 (true, State
.regs
[ OP
[0] ]);
3647 trace_output (OP_REG_REG_REG
);
3652 /* end-sanitize-v850e */
3653 /* start-sanitize-v850eq */
3661 trace_input ("popmh", OP_PUSHPOP2
, 0);
3663 if (OP
[3] & (1 << 19))
3665 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
3667 FEPSW
= load_mem ( SP
& ~ 3, 4);
3668 FEPC
= load_mem ((SP
+ 4) & ~ 3, 4);
3672 EIPSW
= load_mem ( SP
& ~ 3, 4);
3673 EIPC
= load_mem ((SP
+ 4) & ~ 3, 4);
3679 /* Load the registers with lower number registers being retrieved from higher addresses. */
3681 if ((OP
[3] & (1 << type2_regs
[ i
])))
3683 State
.regs
[ i
+ 16 ] = load_mem (SP
& ~ 3, 4);
3687 trace_output (OP_PUSHPOP2
);
3698 trace_input ("popml", OP_PUSHPOP3
, 0);
3700 if (OP
[3] & (1 << 19))
3702 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
3704 FEPSW
= load_mem ( SP
& ~ 3, 4);
3705 FEPC
= load_mem ((SP
+ 4) & ~ 3, 4);
3709 EIPSW
= load_mem ( SP
& ~ 3, 4);
3710 EIPC
= load_mem ((SP
+ 4) & ~ 3, 4);
3716 if (OP
[3] & (1 << 3))
3718 PSW
= load_mem (SP
& ~ 3, 4);
3722 /* Load the registers with lower number registers being retrieved from higher addresses. */
3724 if ((OP
[3] & (1 << type3_regs
[ i
])))
3726 State
.regs
[ i
+ 1 ] = load_mem (SP
& ~ 3, 4);
3730 trace_output (OP_PUSHPOP2
);
3741 trace_input ("pushmh", OP_PUSHPOP2
, 0);
3743 /* Store the registers with lower number registers being placed at higher addresses. */
3744 for (i
= 0; i
< 16; i
++)
3745 if ((OP
[3] & (1 << type2_regs
[ i
])))
3748 store_mem (SP
& ~ 3, 4, State
.regs
[ i
+ 16 ]);
3751 if (OP
[3] & (1 << 19))
3755 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
3757 store_mem ((SP
+ 4) & ~ 3, 4, FEPC
);
3758 store_mem ( SP
& ~ 3, 4, FEPSW
);
3762 store_mem ((SP
+ 4) & ~ 3, 4, EIPC
);
3763 store_mem ( SP
& ~ 3, 4, EIPSW
);
3767 trace_output (OP_PUSHPOP2
);
3772 /* end-sanitize-v850eq */
This page took 0.107463 seconds and 4 git commands to generate.