4 /* FIXME - should be including a version of syscall.h that does not
5 pollute the name space */
6 #include "../../libgloss/v850/sys/syscall.h"
9 #if !defined(__GO32__) && !defined(_WIN32)
11 #include <sys/times.h>
40 /* start-sanitize-v850e */
44 /* end-sanitize-v850e */
45 /* start-sanitize-v850eq */
50 /* end-sanitize-v850eq */
53 /* start-sanitize-v850e */
54 /* This is an array of the bit positions of registers r20 .. r31 in that order in a prepare/dispose instruction. */
55 static int type1_regs
[12] = { 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 0, 21 };
56 /* end-sanitize-v850e */
57 /* start-sanitize-v850eq */
58 /* This is an array of the bit positions of registers r16 .. r31 in that order in a push/pop instruction. */
59 static int type2_regs
[16] = { 3, 2, 1, 0, 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 20, 21};
60 /* This is an array of the bit positions of registers r1 .. r15 in that order in a push/pop instruction. */
61 static int type3_regs
[15] = { 2, 1, 0, 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 20, 21};
62 /* end-sanitize-v850eq */
65 static void trace_input
PARAMS ((char *name
, enum op_types type
, int size
));
66 static void trace_output
PARAMS ((enum op_types result
));
67 static int init_text_p
= 0;
68 static asection
*text
;
69 static bfd_vma text_start
;
70 static bfd_vma text_end
;
73 #ifndef SIZE_INSTRUCTION
74 #define SIZE_INSTRUCTION 6
78 #define SIZE_OPERANDS 16
82 #define SIZE_VALUES 11
86 #define SIZE_LOCATION 40
91 trace_input (name
, type
, size
)
102 const char *filename
;
103 const char *functionname
;
104 unsigned int linenumber
;
106 if ((v850_debug
& DEBUG_TRACE
) == 0)
113 for (s
= prog_bfd
->sections
; s
; s
= s
->next
)
114 if (strcmp (bfd_get_section_name (prog_bfd
, s
), ".text") == 0)
117 text_start
= bfd_get_section_vma (prog_bfd
, s
);
118 text_end
= text_start
+ bfd_section_size (prog_bfd
, s
);
123 if (text
&& PC
>= text_start
&& PC
< text_end
)
125 filename
= (const char *)0;
126 functionname
= (const char *)0;
128 if (bfd_find_nearest_line (prog_bfd
, text
, (struct symbol_cache_entry
**)0, PC
- text_start
,
129 &filename
, &functionname
, &linenumber
))
134 sprintf (p
, "Line %5d ", linenumber
);
140 sprintf (p
, "Func %s ", functionname
);
145 char *q
= (char *) strrchr (filename
, '/');
146 sprintf (p
, "File %s ", (q
) ? q
+1 : filename
);
155 (*v850_callback
->printf_filtered
) (v850_callback
, "0x%.8x: %-*.*s %-*s",
157 SIZE_LOCATION
, SIZE_LOCATION
, buf
,
158 SIZE_INSTRUCTION
, name
);
165 strcpy (buf
, "unknown");
169 sprintf (buf
, "%d", OP
[0]);
173 sprintf (buf
, "r%d", OP
[0]);
178 case OP_REG_REG_MOVE
:
179 sprintf (buf
, "r%d,r%d", OP
[0], OP
[1]);
184 case OP_IMM_REG_MOVE
:
185 sprintf (buf
, "%d,r%d", OP
[0], OP
[1]);
189 sprintf (buf
, "%d", SEXT9 (OP
[0]));
193 sprintf (buf
, "%d[r30],r%d", OP
[1] * size
, OP
[0]);
197 sprintf (buf
, "r%d,%d[r30]", OP
[0], OP
[1] * size
);
201 sprintf (buf
, "%d[r%d],r%d", SEXT16 (OP
[2]) & ~0x1, OP
[0], OP
[1]);
205 sprintf (buf
, "r%d,%d[r%d]", OP
[1], SEXT16 (OP
[2] & ~0x1), OP
[0]);
209 sprintf (buf
, "%d,r%d", SEXT22 (OP
[0]), OP
[1]);
213 sprintf (buf
, "%d,r%d,r%d", SEXT16 (OP
[0]), OP
[1], OP
[2]);
216 case OP_UIMM_REG_REG
:
217 sprintf (buf
, "%d,r%d,r%d", OP
[0] & 0xffff, OP
[1], OP
[2]);
221 sprintf (buf
, "%d,%d[r%d]", OP
[1] & 0x7, SEXT16 (OP
[2]), OP
[0]);
227 default: cond
= "?"; break;
228 case 0x0: cond
= "v"; break;
229 case 0x1: cond
= "c"; break;
230 case 0x2: cond
= "z"; break;
231 case 0x3: cond
= "nh"; break;
232 case 0x4: cond
= "s"; break;
233 case 0x5: cond
= "t"; break;
234 case 0x6: cond
= "lt"; break;
235 case 0x7: cond
= "le"; break;
236 case 0x8: cond
= "nv"; break;
237 case 0x9: cond
= "nc"; break;
238 case 0xa: cond
= "nz"; break;
239 case 0xb: cond
= "h"; break;
240 case 0xc: cond
= "ns"; break;
241 case 0xd: cond
= "sa"; break;
242 case 0xe: cond
= "ge"; break;
243 case 0xf: cond
= "gt"; break;
246 sprintf (buf
, "%s,r%d", cond
, OP
[1]);
255 sprintf (buf
, "r%d,s%d", OP
[0], OP
[1]);
259 for (i
= 0; i
< 12; i
++)
260 if (OP
[3] & (1 << type1_regs
[i
]))
261 strcat (buf
, "r%d ", i
+ 20);
265 for (i
= 0; i
< 16; i
++)
266 if (OP
[3] & (1 << type2_regs
[i
]))
267 strcat (buf
, "r%d ", i
+ 16);
268 if (OP
[3] & (1 << 19))
269 strcat (buf
, "F/EIPC, F/EIPSW " );
273 for (i
= 0; i
< 15; i
++)
274 if (OP
[3] & (1 << type3_regs
[i
]))
275 strcat (buf
, "r%d ", i
+ 1);
276 if (OP
[3] & (1 << 3))
277 strcat (buf
, "PSW " );
278 if (OP
[3] & (1 << 19))
279 strcat (buf
, "F/EIPC, F/EIPSW " );
283 sprintf (buf
, "r%d, [r%d]", OP
[1], OP
[0] );
287 if ((v850_debug
& DEBUG_VALUES
) == 0)
289 (*v850_callback
->printf_filtered
) (v850_callback
, "%s\n", buf
);
293 (*v850_callback
->printf_filtered
) (v850_callback
, "%-*s", SIZE_OPERANDS
, buf
);
304 case OP_REG_REG_MOVE
:
305 values
[0] = State
.regs
[OP
[0]];
312 values
[0] = State
.regs
[OP
[1]];
313 values
[1] = State
.regs
[OP
[0]];
319 values
[0] = SEXT5 (OP
[0]);
324 case OP_IMM_REG_MOVE
:
325 values
[0] = SEXT5 (OP
[0]);
330 values
[0] = State
.pc
;
331 values
[1] = SEXT9 (OP
[0]);
337 values
[0] = OP
[1] * size
;
338 values
[1] = State
.regs
[30];
343 values
[0] = State
.regs
[OP
[0]];
344 values
[1] = OP
[1] * size
;
345 values
[2] = State
.regs
[30];
350 values
[0] = SEXT16 (OP
[2]);
351 values
[1] = State
.regs
[OP
[0]];
356 values
[0] = State
.regs
[OP
[1]];
357 values
[1] = SEXT16 (OP
[2]);
358 values
[2] = State
.regs
[OP
[0]];
363 values
[0] = SEXT22 (OP
[0]);
364 values
[1] = State
.pc
;
369 values
[0] = SEXT16 (OP
[0]) << size
;
370 values
[1] = State
.regs
[OP
[1]];
374 case OP_UIMM_REG_REG
:
375 values
[0] = (OP
[0] & 0xffff) << size
;
376 values
[1] = State
.regs
[OP
[1]];
394 values
[0] = State
.regs
[OP
[0]];
399 values
[0] = State
.sregs
[OP
[1]];
403 for (i
= 0; i
< num_values
; i
++)
404 (*v850_callback
->printf_filtered
) (v850_callback
, "%*s0x%.8lx", SIZE_VALUES
- 10, "", values
[i
]);
407 (*v850_callback
->printf_filtered
) (v850_callback
, "%*s", SIZE_VALUES
, "");
412 trace_output (result
)
413 enum op_types result
;
415 if ((v850_debug
& (DEBUG_TRACE
| DEBUG_VALUES
)) == (DEBUG_TRACE
| DEBUG_VALUES
))
435 (*v850_callback
->printf_filtered
) (v850_callback
, " :: 0x%.8lx",
436 (unsigned long)State
.regs
[OP
[0]]);
440 case OP_REG_REG_MOVE
:
442 case OP_IMM_REG_MOVE
:
445 (*v850_callback
->printf_filtered
) (v850_callback
, " :: 0x%.8lx",
446 (unsigned long)State
.regs
[OP
[1]]);
450 case OP_UIMM_REG_REG
:
451 (*v850_callback
->printf_filtered
) (v850_callback
, " :: 0x%.8lx",
452 (unsigned long)State
.regs
[OP
[2]]);
457 (*v850_callback
->printf_filtered
) (v850_callback
, " :: 0x%.8lx",
458 (unsigned long)State
.regs
[OP
[1]]);
462 (*v850_callback
->printf_filtered
) (v850_callback
, " :: 0x%.8lx",
463 (unsigned long)State
.sregs
[OP
[1]]);
467 (*v850_callback
->printf_filtered
) (v850_callback
, "\n");
472 #define trace_input(NAME, IN1, IN2)
473 #define trace_output(RESULT)
475 //#define trace_input(NAME, IN1, IN2) fprintf (stderr, NAME "\n" );
480 /* Returns 1 if the specific condition is met, returns 0 otherwise. */
482 condition_met (unsigned code
)
484 unsigned int psw
= PSW
;
488 case 0x0: return ((psw
& PSW_OV
) != 0);
489 case 0x1: return ((psw
& PSW_CY
) != 0);
490 case 0x2: return ((psw
& PSW_Z
) != 0);
491 case 0x3: return ((((psw
& PSW_CY
) != 0) | ((psw
& PSW_Z
) != 0)) != 0);
492 case 0x4: return ((psw
& PSW_S
) != 0);
493 /*case 0x5: return 1;*/
494 case 0x6: return ((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) != 0);
495 case 0x7: return (((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) || ((psw
& PSW_Z
) != 0)) != 0);
496 case 0x8: return ((psw
& PSW_OV
) == 0);
497 case 0x9: return ((psw
& PSW_CY
) == 0);
498 case 0xa: return ((psw
& PSW_Z
) == 0);
499 case 0xb: return ((((psw
& PSW_CY
) != 0) | ((psw
& PSW_Z
) != 0)) == 0);
500 case 0xc: return ((psw
& PSW_S
) == 0);
501 case 0xd: return ((psw
& PSW_SAT
) != 0);
502 case 0xe: return ((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) == 0);
503 case 0xf: return (((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) || ((psw
& PSW_Z
) != 0)) == 0);
510 Add32 (unsigned long a1
, unsigned long a2
, int * carry
)
512 unsigned long result
= (a1
+ a2
);
514 * carry
= (result
< a1
);
520 Multiply64 (boolean sign
, unsigned long op0
)
531 op1
= State
.regs
[ OP
[1] ];
535 /* Compute sign of result and adjust operands if necessary. */
537 sign
= (op0
^ op1
) & 0x80000000;
539 if (((signed long) op0
) < 0)
542 if (((signed long) op1
) < 0)
546 /* We can split the 32x32 into four 16x16 operations. This ensures
547 that we do not lose precision on 32bit only hosts: */
548 lo
= ( (op0
& 0xFFFF) * (op1
& 0xFFFF));
549 mid1
= ( (op0
& 0xFFFF) * ((op1
>> 16) & 0xFFFF));
550 mid2
= (((op0
>> 16) & 0xFFFF) * (op1
& 0xFFFF));
551 hi
= (((op0
>> 16) & 0xFFFF) * ((op1
>> 16) & 0xFFFF));
553 /* We now need to add all of these results together, taking care
554 to propogate the carries from the additions: */
555 RdLo
= Add32 (lo
, (mid1
<< 16), & carry
);
557 RdLo
= Add32 (RdLo
, (mid2
<< 16), & carry
);
558 RdHi
+= (carry
+ ((mid1
>> 16) & 0xFFFF) + ((mid2
>> 16) & 0xFFFF) + hi
);
562 /* Negate result if necessary. */
566 if (RdLo
== 0xFFFFFFFF)
575 State
.regs
[ OP
[1] ] = RdLo
;
576 State
.regs
[ OP
[2] >> 11 ] = RdHi
;
586 unsigned long result
;
588 result
= load_mem (State
.regs
[30] + (OP
[3] & 0x7f), 1);
590 /* start-sanitize-v850eq */
592 trace_input ("sld.bu", OP_LOAD16
, 1);
594 State
.regs
[ OP
[1] ] = result
;
596 /* end-sanitize-v850eq */
597 trace_input ("sld.b", OP_LOAD16
, 1);
599 State
.regs
[ OP
[1] ] = SEXT8 (result
);
600 /* start-sanitize-v850eq */
602 /* end-sanitize-v850eq */
604 trace_output (OP_LOAD16
);
613 unsigned long result
;
615 result
= load_mem (State
.regs
[30] + ((OP
[3] & 0x7f) << 1), 2);
617 /* start-sanitize-v850eq */
619 trace_input ("sld.hu", OP_LOAD16
, 2);
621 State
.regs
[ OP
[1] ] = result
;
623 /* end-sanitize-v850eq */
624 trace_input ("sld.h", OP_LOAD16
, 2);
626 State
.regs
[ OP
[1] ] = SEXT16 (result
);
627 /* start-sanitize-v850eq */
629 /* end-sanitize-v850eq */
631 trace_output (OP_LOAD16
);
640 trace_input ("sld.w", OP_LOAD16
, 4);
642 State
.regs
[ OP
[1] ] = load_mem (State
.regs
[30] + ((OP
[3] & 0x7f) << 1), 4);
644 trace_output (OP_LOAD16
);
653 trace_input ("sst.b", OP_STORE16
, 1);
655 store_mem (State
.regs
[30] + (OP
[3] & 0x7f), 1, State
.regs
[ OP
[1] ]);
657 trace_output (OP_STORE16
);
666 trace_input ("sst.h", OP_STORE16
, 2);
668 store_mem (State
.regs
[30] + ((OP
[3] & 0x7f) << 1), 2, State
.regs
[ OP
[1] ]);
670 trace_output (OP_STORE16
);
679 trace_input ("sst.w", OP_STORE16
, 4);
681 store_mem (State
.regs
[30] + ((OP
[3] & 0x7e) << 1), 4, State
.regs
[ OP
[1] ]);
683 trace_output (OP_STORE16
);
694 trace_input ("ld.b", OP_LOAD32
, 1);
696 adr
= State
.regs
[ OP
[0] ] + SEXT16 (OP
[2]);
698 State
.regs
[ OP
[1] ] = SEXT8 (load_mem (adr
, 1));
700 trace_output (OP_LOAD32
);
711 trace_input ("ld.h", OP_LOAD32
, 2);
713 adr
= State
.regs
[ OP
[0] ] + SEXT16 (OP
[2]);
716 State
.regs
[ OP
[1] ] = SEXT16 (load_mem (adr
, 2));
718 trace_output (OP_LOAD32
);
729 trace_input ("ld.w", OP_LOAD32
, 4);
731 adr
= State
.regs
[ OP
[0] ] + SEXT16 (OP
[2] & ~1);
734 State
.regs
[ OP
[1] ] = load_mem (adr
, 4);
736 trace_output (OP_LOAD32
);
745 trace_input ("st.b", OP_STORE32
, 1);
747 store_mem (State
.regs
[ OP
[0] ] + SEXT16 (OP
[2]), 1, State
.regs
[ OP
[1] ]);
749 trace_output (OP_STORE32
);
760 trace_input ("st.h", OP_STORE32
, 2);
762 adr
= State
.regs
[ OP
[0] ] + SEXT16 (OP
[2]);
765 store_mem (adr
, 2, State
.regs
[ OP
[1] ]);
767 trace_output (OP_STORE32
);
778 trace_input ("st.w", OP_STORE32
, 4);
780 adr
= State
.regs
[ OP
[0] ] + SEXT16 (OP
[2] & ~1);
783 store_mem (adr
, 4, State
.regs
[ OP
[1] ]);
785 trace_output (OP_STORE32
);
796 trace_input ("Bcond", OP_COND_BR
, 0);
797 trace_output (OP_COND_BR
);
799 if (condition_met (code
))
800 return SEXT9 (((OP
[3] & 0x70) >> 3) | ((OP
[3] & 0xf800) >> 7));
918 /* sld.bu disp4[ep], reg2 */
924 trace_input ("jmp", OP_REG
, 0);
926 PC
= State
.regs
[ OP
[0] ];
928 trace_output (OP_REG
);
930 return 0; /* Add nothing to the PC, we have already done it. */
932 /* start-sanitize-v850e */
935 unsigned long result
;
937 result
= load_mem (State
.regs
[30] + (OP
[3] & 0xf), 1);
939 /* start-sanitize-v850eq */
941 trace_input ("sld.b", OP_LOAD16
, 1);
943 State
.regs
[ OP
[1] ] = SEXT8 (result
);
945 /* end-sanitize-v850eq */
946 trace_input ("sld.bu", OP_LOAD16
, 1);
948 State
.regs
[ OP
[1] ] = result
;
949 /* start-sanitize-v850eq */
951 /* end-sanitize-v850eq */
953 trace_output (OP_LOAD16
);
957 /* end-sanitize-v850e */
960 /* jarl/jr disp22, reg */
964 trace_input ("jarl/jr", OP_JUMP
, 0);
967 State
.regs
[ OP
[1] ] = PC
+ 4;
969 trace_output (OP_JUMP
);
971 return SEXT22 (((OP
[3] & 0x3f) << 16) | OP
[2]);
978 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
980 trace_input ("add", OP_REG_REG
, 0);
982 /* Compute the result. */
984 op0
= State
.regs
[ OP
[0] ];
985 op1
= State
.regs
[ OP
[1] ];
989 /* Compute the condition codes. */
991 s
= (result
& 0x80000000);
992 cy
= (result
< op0
|| result
< op1
);
993 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
994 && (op0
& 0x80000000) != (result
& 0x80000000));
996 /* Store the result and condition codes. */
997 State
.regs
[OP
[1]] = result
;
998 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
999 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1000 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
1001 trace_output (OP_REG_REG
);
1006 /* add sign_extend(imm5), reg */
1010 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
1013 trace_input ("add", OP_IMM_REG
, 0);
1015 /* Compute the result. */
1016 temp
= SEXT5 (OP
[0]);
1018 op1
= State
.regs
[OP
[1]];
1021 /* Compute the condition codes. */
1023 s
= (result
& 0x80000000);
1024 cy
= (result
< op0
|| result
< op1
);
1025 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
1026 && (op0
& 0x80000000) != (result
& 0x80000000));
1028 /* Store the result and condition codes. */
1029 State
.regs
[OP
[1]] = result
;
1030 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1031 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1032 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
1033 trace_output (OP_IMM_REG
);
1038 /* addi sign_extend(imm16), reg, reg */
1042 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
1044 trace_input ("addi", OP_IMM_REG_REG
, 0);
1046 /* Compute the result. */
1048 op0
= SEXT16 (OP
[2]);
1049 op1
= State
.regs
[ OP
[0] ];
1052 /* Compute the condition codes. */
1054 s
= (result
& 0x80000000);
1055 cy
= (result
< op0
|| result
< op1
);
1056 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
1057 && (op0
& 0x80000000) != (result
& 0x80000000));
1059 /* Store the result and condition codes. */
1060 State
.regs
[OP
[1]] = result
;
1061 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1062 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1063 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
1064 trace_output (OP_IMM_REG_REG
);
1069 /* sub reg1, reg2 */
1073 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
1075 trace_input ("sub", OP_REG_REG
, 0);
1076 /* Compute the result. */
1077 op0
= State
.regs
[ OP
[0] ];
1078 op1
= State
.regs
[ OP
[1] ];
1081 /* Compute the condition codes. */
1083 s
= (result
& 0x80000000);
1085 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
1086 && (op1
& 0x80000000) != (result
& 0x80000000));
1088 /* Store the result and condition codes. */
1089 State
.regs
[OP
[1]] = result
;
1090 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1091 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1092 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
1093 trace_output (OP_REG_REG
);
1098 /* subr reg1, reg2 */
1102 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
1104 trace_input ("subr", OP_REG_REG
, 0);
1105 /* Compute the result. */
1106 op0
= State
.regs
[ OP
[0] ];
1107 op1
= State
.regs
[ OP
[1] ];
1110 /* Compute the condition codes. */
1112 s
= (result
& 0x80000000);
1114 ov
= ((op0
& 0x80000000) != (op1
& 0x80000000)
1115 && (op0
& 0x80000000) != (result
& 0x80000000));
1117 /* Store the result and condition codes. */
1118 State
.regs
[OP
[1]] = result
;
1119 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1120 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1121 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
1122 trace_output (OP_REG_REG
);
1128 /* mulh reg1, reg2 */
1132 /* start-sanitize-v850e */
1135 trace_input ("sxh", OP_REG
, 0);
1137 State
.regs
[ OP
[0] ] = SEXT16 (State
.regs
[ OP
[0] ]);
1139 trace_output (OP_REG
);
1142 /* end-sanitize-v850e */
1144 trace_input ("mulh", OP_REG_REG
, 0);
1146 State
.regs
[ OP
[1] ] = (SEXT16 (State
.regs
[ OP
[1] ]) * SEXT16 (State
.regs
[ OP
[0] ]));
1148 trace_output (OP_REG_REG
);
1154 /* mulh sign_extend(imm5), reg2 */
1158 trace_input ("mulh", OP_IMM_REG
, 0);
1160 State
.regs
[ OP
[1] ] = SEXT16 (State
.regs
[ OP
[1] ]) * SEXT5 (OP
[0]);
1162 trace_output (OP_IMM_REG
);
1167 /* mulhi imm16, reg1, reg2 */
1176 trace_input ("mulhi", OP_IMM_REG_REG
, 0);
1178 State
.regs
[ OP
[1] ] = SEXT16 (State
.regs
[ OP
[0] ]) * SEXT16 (OP
[2]);
1180 trace_output (OP_IMM_REG_REG
);
1186 /* divh reg1, reg2 */
1191 /* start-sanitize-v850e */
1196 trace_input ("switch", OP_REG
, 0);
1198 adr
= State
.pc
+ 2 + (State
.regs
[ OP
[0] ] << 1);
1199 State
.pc
= State
.pc
+ 2 + (SEXT16 (load_mem (adr
, 2)) << 1);
1201 trace_output (OP_REG
);
1204 /* end-sanitize-v850e */
1206 unsigned int op0
, op1
, result
, ov
, s
, z
;
1209 trace_input ("divh", OP_REG_REG
, 0);
1211 /* Compute the result. */
1212 temp
= SEXT16 (State
.regs
[ OP
[0] ]);
1214 op1
= State
.regs
[OP
[1]];
1216 if (op0
== 0xffffffff && op1
== 0x80000000)
1218 result
= 0x80000000;
1232 /* Compute the condition codes. */
1234 s
= (result
& 0x80000000);
1236 /* Store the result and condition codes. */
1237 State
.regs
[OP
[1]] = result
;
1238 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1239 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1240 | (ov
? PSW_OV
: 0));
1241 trace_output (OP_REG_REG
);
1251 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
1253 trace_input ("cmp", OP_REG_REG_CMP
, 0);
1254 /* Compute the result. */
1255 op0
= State
.regs
[ OP
[0] ];
1256 op1
= State
.regs
[ OP
[1] ];
1259 /* Compute the condition codes. */
1261 s
= (result
& 0x80000000);
1263 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
1264 && (op1
& 0x80000000) != (result
& 0x80000000));
1266 /* Set condition codes. */
1267 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1268 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1269 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
1270 trace_output (OP_REG_REG_CMP
);
1275 /* cmp sign_extend(imm5), reg */
1279 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
1282 /* Compute the result. */
1283 trace_input ("cmp", OP_IMM_REG_CMP
, 0);
1284 temp
= SEXT5 (OP
[0]);
1286 op1
= State
.regs
[OP
[1]];
1289 /* Compute the condition codes. */
1291 s
= (result
& 0x80000000);
1293 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
1294 && (op1
& 0x80000000) != (result
& 0x80000000));
1296 /* Set condition codes. */
1297 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1298 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1299 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
1300 trace_output (OP_IMM_REG_CMP
);
1305 /* setf cccc,reg2 */
1309 trace_input ("setf", OP_EX1
, 0);
1311 State
.regs
[ OP
[1] ] = condition_met (OP
[0]);
1313 trace_output (OP_EX1
);
1319 /* satadd reg,reg */
1323 /* start-sanitize-v850e */
1326 trace_input ("zxh", OP_REG
, 0);
1328 State
.regs
[ OP
[0] ] &= 0xffff;
1330 trace_output (OP_REG
);
1333 /* end-sanitize-v850e */
1335 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
1337 trace_input ("satadd", OP_REG_REG
, 0);
1338 /* Compute the result. */
1339 op0
= State
.regs
[ OP
[0] ];
1340 op1
= State
.regs
[ OP
[1] ];
1343 /* Compute the condition codes. */
1345 s
= (result
& 0x80000000);
1346 cy
= (result
< op0
|| result
< op1
);
1347 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
1348 && (op0
& 0x80000000) != (result
& 0x80000000));
1351 /* Store the result and condition codes. */
1352 State
.regs
[OP
[1]] = result
;
1353 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1354 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1355 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
1356 | (sat
? PSW_SAT
: 0));
1358 /* Handle saturated results. */
1360 State
.regs
[OP
[1]] = 0x80000000;
1362 State
.regs
[OP
[1]] = 0x7fffffff;
1363 trace_output (OP_REG_REG
);
1369 /* satadd sign_extend(imm5), reg */
1373 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
1377 trace_input ("satadd", OP_IMM_REG
, 0);
1379 /* Compute the result. */
1380 temp
= SEXT5 (OP
[0]);
1382 op1
= State
.regs
[OP
[1]];
1385 /* Compute the condition codes. */
1387 s
= (result
& 0x80000000);
1388 cy
= (result
< op0
|| result
< op1
);
1389 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
1390 && (op0
& 0x80000000) != (result
& 0x80000000));
1393 /* Store the result and condition codes. */
1394 State
.regs
[OP
[1]] = result
;
1395 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1396 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1397 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
1398 | (sat
? PSW_SAT
: 0));
1400 /* Handle saturated results. */
1402 State
.regs
[OP
[1]] = 0x80000000;
1404 State
.regs
[OP
[1]] = 0x7fffffff;
1405 trace_output (OP_IMM_REG
);
1410 /* satsub reg1, reg2 */
1415 /* start-sanitize-v850e */
1418 trace_input ("sxb", OP_REG
, 0);
1420 State
.regs
[ OP
[0] ] = SEXT8 (State
.regs
[ OP
[0] ]);
1422 trace_output (OP_REG
);
1425 /* end-sanitize-v850e */
1427 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
1429 trace_input ("satsub", OP_REG_REG
, 0);
1431 /* Compute the result. */
1432 op0
= State
.regs
[ OP
[0] ];
1433 op1
= State
.regs
[ OP
[1] ];
1436 /* Compute the condition codes. */
1438 s
= (result
& 0x80000000);
1440 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
1441 && (op1
& 0x80000000) != (result
& 0x80000000));
1444 /* Store the result and condition codes. */
1445 State
.regs
[OP
[1]] = result
;
1446 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1447 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1448 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
1449 | (sat
? PSW_SAT
: 0));
1451 /* Handle saturated results. */
1453 State
.regs
[OP
[1]] = 0x80000000;
1455 State
.regs
[OP
[1]] = 0x7fffffff;
1456 trace_output (OP_REG_REG
);
1462 /* satsubi sign_extend(imm16), reg */
1466 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
1469 trace_input ("satsubi", OP_IMM_REG
, 0);
1471 /* Compute the result. */
1472 temp
= SEXT16 (OP
[2]);
1474 op1
= State
.regs
[ OP
[0] ];
1477 /* Compute the condition codes. */
1479 s
= (result
& 0x80000000);
1481 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
1482 && (op1
& 0x80000000) != (result
& 0x80000000));
1485 /* Store the result and condition codes. */
1486 State
.regs
[OP
[1]] = result
;
1487 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1488 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1489 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
1490 | (sat
? PSW_SAT
: 0));
1492 /* Handle saturated results. */
1494 State
.regs
[OP
[1]] = 0x80000000;
1496 State
.regs
[OP
[1]] = 0x7fffffff;
1497 trace_output (OP_IMM_REG
);
1502 /* satsubr reg,reg */
1507 /* start-sanitize-v850e */
1510 trace_input ("zxb", OP_REG
, 0);
1512 State
.regs
[ OP
[0] ] &= 0xff;
1514 trace_output (OP_REG
);
1517 /* end-sanitize-v850e */
1519 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
1521 trace_input ("satsubr", OP_REG_REG
, 0);
1523 /* Compute the result. */
1524 op0
= State
.regs
[ OP
[0] ];
1525 op1
= State
.regs
[ OP
[1] ];
1528 /* Compute the condition codes. */
1530 s
= (result
& 0x80000000);
1531 cy
= (result
< op0
);
1532 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
1533 && (op1
& 0x80000000) != (result
& 0x80000000));
1536 /* Store the result and condition codes. */
1537 State
.regs
[OP
[1]] = result
;
1538 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1539 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1540 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
1541 | (sat
? PSW_SAT
: 0));
1543 /* Handle saturated results. */
1545 State
.regs
[OP
[1]] = 0x80000000;
1547 State
.regs
[OP
[1]] = 0x7fffffff;
1548 trace_output (OP_REG_REG
);
1558 unsigned int op0
, op1
, result
, z
, s
;
1560 trace_input ("tst", OP_REG_REG_CMP
, 0);
1562 /* Compute the result. */
1563 op0
= State
.regs
[ OP
[0] ];
1564 op1
= State
.regs
[ OP
[1] ];
1567 /* Compute the condition codes. */
1569 s
= (result
& 0x80000000);
1571 /* Store the condition codes. */
1572 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1573 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1574 trace_output (OP_REG_REG_CMP
);
1583 trace_input ("mov", OP_REG_REG_MOVE
, 0);
1585 State
.regs
[ OP
[1] ] = State
.regs
[ OP
[0] ];
1587 trace_output (OP_REG_REG_MOVE
);
1592 /* mov sign_extend(imm5), reg */
1597 /* start-sanitize-v850e */
1602 trace_input ("callt", OP_LOAD16
, 1);
1607 adr
= CTBP
+ ((OP
[3] & 0x3f) << 1);
1609 PC
= CTBP
+ load_mem (adr
, 1);
1611 trace_output (OP_LOAD16
);
1616 /* end-sanitize-v850e */
1618 int value
= SEXT5 (OP
[0]);
1620 trace_input ("mov", OP_IMM_REG_MOVE
, 0);
1622 State
.regs
[ OP
[1] ] = value
;
1624 trace_output (OP_IMM_REG_MOVE
);
1630 /* mov imm32, reg1 */
1631 /* movea sign_extend(imm16), reg, reg */
1635 /* start-sanitize-v850e */
1638 trace_input ("mov", OP_IMM32_REG
, 4);
1640 State
.regs
[ OP
[0] ] = load_mem (PC
+ 2, 4);
1642 trace_output (OP_IMM32_REG
);
1647 /* end-sanitize-v850e */
1649 trace_input ("movea", OP_IMM_REG_REG
, 0);
1651 State
.regs
[ OP
[1] ] = State
.regs
[ OP
[0] ] + SEXT16 (OP
[2]);
1653 trace_output (OP_IMM_REG_REG
);
1659 /* dispose imm5, list12 [, reg1] */
1660 /* movhi imm16, reg, reg */
1664 /* start-sanitize-v850e */
1670 trace_input ("dispose", OP_PUSHPOP1
, 0);
1672 SP
+= (OP
[3] & 0x3e) << 1;
1674 /* Load the registers with lower number registers being retrieved from higher addresses. */
1676 if ((OP
[3] & (1 << type1_regs
[ i
])))
1678 State
.regs
[ 20 + i
] = load_mem (SP
, 4);
1682 if ((OP
[3] & 0x1f0000) != 0)
1684 PC
= State
.regs
[ (OP
[3] >> 16) & 0x1f];
1688 trace_output (OP_PUSHPOP1
);
1691 /* end-sanitize-v850e */
1693 trace_input ("movhi", OP_UIMM_REG_REG
, 16);
1695 State
.regs
[ OP
[1] ] = State
.regs
[ OP
[0] ] + OP
[2] << 16;
1697 trace_output (OP_UIMM_REG_REG
);
1703 /* sar zero_extend(imm5),reg1 */
1707 unsigned int op0
, op1
, result
, z
, s
, cy
;
1709 trace_input ("sar", OP_IMM_REG
, 0);
1711 op1
= State
.regs
[ OP
[1] ];
1712 result
= (signed)op1
>> op0
;
1714 /* Compute the condition codes. */
1716 s
= (result
& 0x80000000);
1717 cy
= (op1
& (1 << (op0
- 1)));
1719 /* Store the result and condition codes. */
1720 State
.regs
[ OP
[1] ] = result
;
1721 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1722 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1723 | (cy
? PSW_CY
: 0));
1724 trace_output (OP_IMM_REG
);
1729 /* sar reg1, reg2 */
1733 unsigned int op0
, op1
, result
, z
, s
, cy
;
1735 trace_input ("sar", OP_REG_REG
, 0);
1737 op0
= State
.regs
[ OP
[0] ] & 0x1f;
1738 op1
= State
.regs
[ OP
[1] ];
1739 result
= (signed)op1
>> op0
;
1741 /* Compute the condition codes. */
1743 s
= (result
& 0x80000000);
1744 cy
= (op1
& (1 << (op0
- 1)));
1746 /* Store the result and condition codes. */
1747 State
.regs
[OP
[1]] = result
;
1748 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1749 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1750 | (cy
? PSW_CY
: 0));
1751 trace_output (OP_REG_REG
);
1756 /* shl zero_extend(imm5),reg1 */
1760 unsigned int op0
, op1
, result
, z
, s
, cy
;
1762 trace_input ("shl", OP_IMM_REG
, 0);
1764 op1
= State
.regs
[ OP
[1] ];
1765 result
= op1
<< op0
;
1767 /* Compute the condition codes. */
1769 s
= (result
& 0x80000000);
1770 cy
= (op1
& (1 << (32 - op0
)));
1772 /* Store the result and condition codes. */
1773 State
.regs
[OP
[1]] = result
;
1774 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1775 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1776 | (cy
? PSW_CY
: 0));
1777 trace_output (OP_IMM_REG
);
1782 /* shl reg1, reg2 */
1786 unsigned int op0
, op1
, result
, z
, s
, cy
;
1788 trace_input ("shl", OP_REG_REG
, 0);
1789 op0
= State
.regs
[ OP
[0] ] & 0x1f;
1790 op1
= State
.regs
[ OP
[1] ];
1791 result
= op1
<< op0
;
1793 /* Compute the condition codes. */
1795 s
= (result
& 0x80000000);
1796 cy
= (op1
& (1 << (32 - op0
)));
1798 /* Store the result and condition codes. */
1799 State
.regs
[OP
[1]] = result
;
1800 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1801 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1802 | (cy
? PSW_CY
: 0));
1803 trace_output (OP_REG_REG
);
1808 /* shr zero_extend(imm5),reg1 */
1812 unsigned int op0
, op1
, result
, z
, s
, cy
;
1814 trace_input ("shr", OP_IMM_REG
, 0);
1816 op1
= State
.regs
[ OP
[1] ];
1817 result
= op1
>> op0
;
1819 /* Compute the condition codes. */
1821 s
= (result
& 0x80000000);
1822 cy
= (op1
& (1 << (op0
- 1)));
1824 /* Store the result and condition codes. */
1825 State
.regs
[OP
[1]] = result
;
1826 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1827 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1828 | (cy
? PSW_CY
: 0));
1829 trace_output (OP_IMM_REG
);
1834 /* shr reg1, reg2 */
1838 unsigned int op0
, op1
, result
, z
, s
, cy
;
1840 trace_input ("shr", OP_REG_REG
, 0);
1841 op0
= State
.regs
[ OP
[0] ] & 0x1f;
1842 op1
= State
.regs
[ OP
[1] ];
1843 result
= op1
>> op0
;
1845 /* Compute the condition codes. */
1847 s
= (result
& 0x80000000);
1848 cy
= (op1
& (1 << (op0
- 1)));
1850 /* Store the result and condition codes. */
1851 State
.regs
[OP
[1]] = result
;
1852 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1853 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1854 | (cy
? PSW_CY
: 0));
1855 trace_output (OP_REG_REG
);
1864 unsigned int op0
, op1
, result
, z
, s
;
1866 trace_input ("or", OP_REG_REG
, 0);
1868 /* Compute the result. */
1869 op0
= State
.regs
[ OP
[0] ];
1870 op1
= State
.regs
[ OP
[1] ];
1873 /* Compute the condition codes. */
1875 s
= (result
& 0x80000000);
1877 /* Store the result and condition codes. */
1878 State
.regs
[OP
[1]] = result
;
1879 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1880 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1881 trace_output (OP_REG_REG
);
1886 /* ori zero_extend(imm16), reg, reg */
1890 unsigned int op0
, op1
, result
, z
, s
;
1892 trace_input ("ori", OP_UIMM_REG_REG
, 0);
1894 op1
= State
.regs
[ OP
[0] ];
1897 /* Compute the condition codes. */
1899 s
= (result
& 0x80000000);
1901 /* Store the result and condition codes. */
1902 State
.regs
[OP
[1]] = result
;
1903 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1904 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1905 trace_output (OP_UIMM_REG_REG
);
1914 unsigned int op0
, op1
, result
, z
, s
;
1916 trace_input ("and", OP_REG_REG
, 0);
1918 /* Compute the result. */
1919 op0
= State
.regs
[ OP
[0] ];
1920 op1
= State
.regs
[ OP
[1] ];
1923 /* Compute the condition codes. */
1925 s
= (result
& 0x80000000);
1927 /* Store the result and condition codes. */
1928 State
.regs
[OP
[1]] = result
;
1929 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1930 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1931 trace_output (OP_REG_REG
);
1936 /* andi zero_extend(imm16), reg, reg */
1940 unsigned int result
, z
;
1942 trace_input ("andi", OP_UIMM_REG_REG
, 0);
1944 result
= OP
[2] & State
.regs
[ OP
[0] ];
1946 /* Compute the condition codes. */
1949 /* Store the result and condition codes. */
1950 State
.regs
[ OP
[1] ] = result
;
1952 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1953 PSW
|= (z
? PSW_Z
: 0);
1955 trace_output (OP_UIMM_REG_REG
);
1964 unsigned int op0
, op1
, result
, z
, s
;
1966 trace_input ("xor", OP_REG_REG
, 0);
1968 /* Compute the result. */
1969 op0
= State
.regs
[ OP
[0] ];
1970 op1
= State
.regs
[ OP
[1] ];
1973 /* Compute the condition codes. */
1975 s
= (result
& 0x80000000);
1977 /* Store the result and condition codes. */
1978 State
.regs
[OP
[1]] = result
;
1979 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1980 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1981 trace_output (OP_REG_REG
);
1986 /* xori zero_extend(imm16), reg, reg */
1990 unsigned int op0
, op1
, result
, z
, s
;
1992 trace_input ("xori", OP_UIMM_REG_REG
, 0);
1994 op1
= State
.regs
[ OP
[0] ];
1997 /* Compute the condition codes. */
1999 s
= (result
& 0x80000000);
2001 /* Store the result and condition codes. */
2002 State
.regs
[OP
[1]] = result
;
2003 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2004 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
2005 trace_output (OP_UIMM_REG_REG
);
2010 /* not reg1, reg2 */
2014 unsigned int op0
, result
, z
, s
;
2016 trace_input ("not", OP_REG_REG_MOVE
, 0);
2017 /* Compute the result. */
2018 op0
= State
.regs
[ OP
[0] ];
2021 /* Compute the condition codes. */
2023 s
= (result
& 0x80000000);
2025 /* Store the result and condition codes. */
2026 State
.regs
[OP
[1]] = result
;
2027 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2028 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
2029 trace_output (OP_REG_REG_MOVE
);
2038 unsigned int op0
, op1
, op2
;
2041 trace_input ("set1", OP_BIT
, 0);
2042 op0
= State
.regs
[ OP
[0] ];
2044 temp
= SEXT16 (OP
[2]);
2046 temp
= load_mem (op0
+ op2
, 1);
2048 if ((temp
& (1 << op1
)) == 0)
2051 store_mem (op0
+ op2
, 1, temp
);
2052 trace_output (OP_BIT
);
2061 unsigned int op0
, op1
, op2
;
2064 trace_input ("not1", OP_BIT
, 0);
2065 op0
= State
.regs
[ OP
[0] ];
2067 temp
= SEXT16 (OP
[2]);
2069 temp
= load_mem (op0
+ op2
, 1);
2071 if ((temp
& (1 << op1
)) == 0)
2074 store_mem (op0
+ op2
, 1, temp
);
2075 trace_output (OP_BIT
);
2084 unsigned int op0
, op1
, op2
;
2087 trace_input ("clr1", OP_BIT
, 0);
2088 op0
= State
.regs
[ OP
[0] ];
2090 temp
= SEXT16 (OP
[2]);
2092 temp
= load_mem (op0
+ op2
, 1);
2094 if ((temp
& (1 << op1
)) == 0)
2096 temp
&= ~(1 << op1
);
2097 store_mem (op0
+ op2
, 1, temp
);
2098 trace_output (OP_BIT
);
2107 unsigned int op0
, op1
, op2
;
2110 trace_input ("tst1", OP_BIT
, 0);
2111 op0
= State
.regs
[ OP
[0] ];
2113 temp
= SEXT16 (OP
[2]);
2115 temp
= load_mem (op0
+ op2
, 1);
2117 if ((temp
& (1 << op1
)) == 0)
2119 trace_output (OP_BIT
);
2128 State
.exception
= SIGTRAP
;
2136 trace_input ("di", OP_NONE
, 0);
2138 trace_output (OP_NONE
);
2147 trace_input ("ei", OP_NONE
, 0);
2149 trace_output (OP_NONE
);
2158 trace_input ("halt", OP_NONE
, 0);
2159 /* FIXME this should put processor into a mode where NMI still handled */
2160 State
.exception
= SIGQUIT
;
2161 trace_output (OP_NONE
);
2170 trace_input ("reti", OP_NONE
, 0);
2171 trace_output (OP_NONE
);
2173 /* Restore for NMI if only NP on, otherwise is interrupt or exception. */
2174 if ((PSW
& (PSW_NP
| PSW_EP
)) == PSW_NP
)
2192 trace_input ("trap", OP_TRAP
, 0);
2193 trace_output (OP_TRAP
);
2195 /* Trap 31 is used for simulating OS I/O functions */
2199 int save_errno
= errno
;
2202 /* Registers passed to trap 0 */
2204 #define FUNC State.regs[6] /* function number, return value */
2205 #define PARM1 State.regs[7] /* optional parm 1 */
2206 #define PARM2 State.regs[8] /* optional parm 2 */
2207 #define PARM3 State.regs[9] /* optional parm 3 */
2209 /* Registers set by trap 0 */
2211 #define RETVAL State.regs[10] /* return value */
2212 #define RETERR State.regs[11] /* return error code */
2214 /* Turn a pointer in a register into a pointer into real memory. */
2216 #define MEMPTR(x) (map (x))
2221 #if !defined(__GO32__) && !defined(_WIN32)
2229 #if !defined(__GO32__) && !defined(_WIN32)
2232 RETVAL
= execve (MEMPTR (PARM1
), (char **) MEMPTR (PARM2
),
2233 (char **)MEMPTR (PARM3
));
2238 #if !defined(__GO32__) && !defined(_WIN32)
2241 RETVAL
= execve (MEMPTR (PARM1
), (char **) MEMPTR (PARM2
), NULL
);
2254 RETVAL
= pipe (host_fd
);
2255 SW (buf
, host_fd
[0]);
2256 buf
+= sizeof(uint16
);
2257 SW (buf
, host_fd
[1]);
2269 RETVAL
= wait (&status
);
2278 RETVAL
= v850_callback
->read (v850_callback
, PARM1
, MEMPTR (PARM2
),
2286 RETVAL
= (int)v850_callback
->write_stdout (v850_callback
,
2287 MEMPTR (PARM2
), PARM3
);
2289 RETVAL
= (int)v850_callback
->write (v850_callback
, PARM1
,
2290 MEMPTR (PARM2
), PARM3
);
2296 RETVAL
= v850_callback
->lseek (v850_callback
, PARM1
, PARM2
, PARM3
);
2302 RETVAL
= v850_callback
->close (v850_callback
, PARM1
);
2308 RETVAL
= v850_callback
->open (v850_callback
, MEMPTR (PARM1
), PARM2
);
2314 if ((PARM1
& 0xffff0000) == 0xdead0000 && (PARM1
& 0xffff) != 0)
2315 State
.exception
= PARM1
& 0xffff; /* get signal encoded by kill */
2316 else if (PARM1
== 0xdead)
2317 State
.exception
= SIGABRT
; /* old libraries */
2319 State
.exception
= SIG_V850_EXIT
; /* PARM1 has exit status encoded */
2323 #if !defined(__GO32__) && !defined(_WIN32)
2325 case SYS_stat
: /* added at hmsi */
2326 /* stat system call */
2328 struct stat host_stat
;
2331 RETVAL
= stat (MEMPTR (PARM1
), &host_stat
);
2335 /* Just wild-assed guesses. */
2336 store_mem (buf
, 2, host_stat
.st_dev
);
2337 store_mem (buf
+ 2, 2, host_stat
.st_ino
);
2338 store_mem (buf
+ 4, 4, host_stat
.st_mode
);
2339 store_mem (buf
+ 8, 2, host_stat
.st_nlink
);
2340 store_mem (buf
+ 10, 2, host_stat
.st_uid
);
2341 store_mem (buf
+ 12, 2, host_stat
.st_gid
);
2342 store_mem (buf
+ 14, 2, host_stat
.st_rdev
);
2343 store_mem (buf
+ 16, 4, host_stat
.st_size
);
2344 store_mem (buf
+ 20, 4, host_stat
.st_atime
);
2345 store_mem (buf
+ 28, 4, host_stat
.st_mtime
);
2346 store_mem (buf
+ 36, 4, host_stat
.st_ctime
);
2352 #if !defined(__GO32__) && !defined(_WIN32)
2355 RETVAL
= chown (MEMPTR (PARM1
), PARM2
, PARM3
);
2363 RETVAL
= chmod (MEMPTR (PARM1
), PARM2
);
2373 RETVAL
= time (&now
);
2374 store_mem (PARM1
, 4, now
);
2380 #if !defined(__GO32__) && !defined(_WIN32)
2385 RETVAL
= times (&tms
);
2386 store_mem (PARM1
, 4, tms
.tms_utime
);
2387 store_mem (PARM1
+ 4, 4, tms
.tms_stime
);
2388 store_mem (PARM1
+ 8, 4, tms
.tms_cutime
);
2389 store_mem (PARM1
+ 12, 4, tms
.tms_cstime
);
2395 #ifdef SYS_gettimeofday
2396 #if !defined(__GO32__) && !defined(_WIN32)
2397 case SYS_gettimeofday
:
2401 RETVAL
= gettimeofday (&t
, &tz
);
2402 store_mem (PARM1
, 4, t
.tv_sec
);
2403 store_mem (PARM1
+ 4, 4, t
.tv_usec
);
2404 store_mem (PARM2
, 4, tz
.tz_minuteswest
);
2405 store_mem (PARM2
+ 4, 4, tz
.tz_dsttime
);
2411 #if !defined(__GO32__) && !defined(_WIN32)
2414 /* Cast the second argument to void *, to avoid type mismatch
2415 if a prototype is present. */
2416 RETVAL
= utime (MEMPTR (PARM1
), (void *) MEMPTR (PARM2
));
2430 { /* Trap 0 -> 30 */
2435 ECR
|= 0x40 + OP
[0];
2436 /* Flag that we are now doing exception processing. */
2437 PSW
|= PSW_EP
| PSW_ID
;
2438 PC
= ((OP
[0] < 0x10) ? 0x40 : 0x50) - 4;
2448 trace_input ("ldsr", OP_LDSR
, 0);
2450 State
.sregs
[ OP
[1] ] = State
.regs
[ OP
[0] ];
2452 trace_output (OP_LDSR
);
2463 trace_input ("stsr", OP_STSR
, 0);
2465 State
.regs
[ OP
[1] ] = State
.sregs
[ OP
[0] ];
2467 trace_output (OP_STSR
);
2472 /* tst1 reg2, [reg1] */
2478 trace_input ("tst1", OP_BIT_LOAD
, 1);
2480 temp
= load_mem (State
.regs
[ OP
[0] ], 1);
2483 if ((temp
& (1 << State
.regs
[ OP
[1] & 0x7 ])) == 0)
2486 trace_output (OP_BIT_LOAD
);
2491 /* mulu reg1, reg2, reg3 */
2495 trace_input ("mulu", OP_REG_REG_REG
, 0);
2497 Multiply64 (false, State
.regs
[ OP
[0] ]);
2499 trace_output (OP_REG_REG_REG
);
2504 /* start-sanitize-v850e */
2506 #define BIT_CHANGE_OP( name, binop ) \
2508 unsigned int temp; \
2510 trace_input (name, OP_BIT_CHANGE, 0); \
2512 bit = 1 << State.regs[ OP[1] & 0x7 ]; \
2513 temp = load_mem (State.regs[ OP[0] ], 1); \
2516 if ((temp & bit) == 0) \
2520 store_mem (State.regs[ OP[0] ], 1, temp); \
2522 trace_output (OP_BIT_CHANGE); \
2526 /* clr1 reg2, [reg1] */
2530 BIT_CHANGE_OP ("clr1", &= ~ );
2533 /* not1 reg2, [reg1] */
2537 BIT_CHANGE_OP ("not1", ^= );
2544 BIT_CHANGE_OP ("set1", |= );
2551 trace_input ("sasf", OP_EX1
, 0);
2553 State
.regs
[ OP
[1] ] = (State
.regs
[ OP
[1] ] << 1) | condition_met (OP
[0]);
2555 trace_output (OP_EX1
);
2559 /* end-sanitize-v850e */
2561 /* start-sanitize-v850eq */
2562 /* This function is courtesy of Sugimoto at NEC, via Seow Tan (Soew_Tan@el.nec.com) */
2567 unsigned long int als
,
2568 unsigned long int sfi
,
2569 unsigned long int * quotient_ptr
,
2570 unsigned long int * remainder_ptr
,
2571 boolean
* overflow_ptr
2574 unsigned long ald
= sfi
>> N
- 1;
2575 unsigned long alo
= als
;
2580 unsigned int R1
= 1;
2582 unsigned int DBZ
= (als
== 0) ? 1 : 0;
2583 unsigned long alt
= Q
? ~als
: als
;
2586 alo
= ald
+ alt
+ Q
;
2587 C
= (alt
>> 31) & (ald
>> 31) | ((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31);
2590 R1
= (alo
== 0) ? 0 : (R1
& Q
);
2591 if ((S
^ (alo
>>31)) && !C
)
2596 sfi
= (sfi
<< (32-N
+1)) | Q
;
2597 ald
= (alo
<< 1) | (sfi
>> 31);
2599 /* 2nd - N-1th Loop */
2600 for (i
= 2; i
< N
; i
++)
2602 alt
= Q
? ~als
: als
;
2603 alo
= ald
+ alt
+ Q
;
2604 C
= (alt
>> 31) & (ald
>> 31) | ((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31);
2607 R1
= (alo
== 0) ? 0 : (R1
& Q
);
2608 if ((S
^ (alo
>>31)) && !C
&& !DBZ
)
2613 sfi
= (sfi
<< 1) | Q
;
2614 ald
= (alo
<< 1) | (sfi
>> 31);
2618 alt
= Q
? ~als
: als
;
2619 alo
= ald
+ alt
+ Q
;
2620 C
= (alt
>> 31) & (ald
>> 31) | ((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31);
2623 R1
= (alo
== 0) ? 0 : (R1
& Q
);
2624 if ((S
^ (alo
>>31)) && !C
)
2629 * quotient_ptr
= (sfi
<< 1) | Q
;
2630 * remainder_ptr
= Q
? alo
: (alo
+ als
);
2631 * overflow_ptr
= DBZ
| R1
;
2634 /* This function is courtesy of Sugimoto at NEC, via Seow Tan (Soew_Tan@el.nec.com) */
2639 unsigned long int als
,
2640 unsigned long int sfi
,
2641 signed long int * quotient_ptr
,
2642 signed long int * remainder_ptr
,
2643 boolean
* overflow_ptr
2646 unsigned long ald
= (signed long) sfi
>> (N
- 1);
2647 unsigned long alo
= als
;
2648 unsigned int SS
= als
>> 31;
2649 unsigned int SD
= sfi
>> 31;
2650 unsigned int R1
= 1;
2652 unsigned int DBZ
= als
== 0 ? 1 : 0;
2653 unsigned int Q
= ~(SS
^ SD
) & 1;
2657 unsigned long alt
= Q
? ~als
: als
;
2662 alo
= ald
+ alt
+ Q
;
2663 C
= (alt
>> 31) & (ald
>> 31) | ((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31);
2665 R1
= (alo
== 0) ? 0 : (R1
& (Q
^ (SS
^ SD
)));
2667 sfi
= (sfi
<< (32-N
+1)) | Q
;
2668 ald
= (alo
<< 1) | (sfi
>> 31);
2669 if ((alo
>> 31) ^ (ald
>> 31))
2674 /* 2nd - N-1th Loop */
2676 for (i
= 2; i
< N
; i
++)
2678 alt
= Q
? ~als
: als
;
2679 alo
= ald
+ alt
+ Q
;
2680 C
= (alt
>> 31) & (ald
>> 31) | ((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31);
2682 R1
= (alo
== 0) ? 0 : (R1
& (Q
^ (SS
^ SD
)));
2684 sfi
= (sfi
<< 1) | Q
;
2685 ald
= (alo
<< 1) | (sfi
>> 31);
2686 if ((alo
>> 31) ^ (ald
>> 31))
2693 alt
= Q
? ~als
: als
;
2694 alo
= ald
+ alt
+ Q
;
2695 C
= (alt
>> 31) & (ald
>> 31) | ((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31);
2697 R1
= (alo
== 0) ? 0 : (R1
& (Q
^ (SS
^ SD
)));
2698 sfi
= (sfi
<< (32-N
+1));
2704 alt
= Q
? ~als
: als
;
2705 alo
= ald
+ alt
+ Q
;
2707 R1
= R1
& ((~alo
>> 31) ^ SD
);
2708 if ((alo
!= 0) && ((Q
^ (SS
^ SD
)) ^ R1
)) alo
= ald
;
2710 ald
= sfi
= (long) ((sfi
>> 1) | (SS
^ SD
) << 31) >> (32-N
-1) | Q
;
2712 ald
= sfi
= sfi
| Q
;
2714 OV
= DBZ
| ((alo
== 0) ? 0 : R1
);
2716 * remainder_ptr
= alo
;
2719 if ((alo
!= 0) && ((SS
^ SD
) ^ R1
) || (alo
== 0) && (SS
^ R1
))
2724 OV
= (DBZ
| R1
) ? OV
: ((alo
>> 31) & (~ald
>> 31));
2726 * quotient_ptr
= alo
;
2727 * overflow_ptr
= OV
;
2730 /* sdivun imm5, reg1, reg2, reg3 */
2734 unsigned long int quotient
;
2735 unsigned long int remainder
;
2736 unsigned long int divide_by
;
2737 unsigned long int divide_this
;
2738 boolean overflow
= false;
2741 trace_input ("sdivun", OP_IMM_REG_REG_REG
, 0);
2743 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2745 divide_by
= State
.regs
[ OP
[0] ];
2746 divide_this
= State
.regs
[ OP
[1] ] << imm5
;
2748 divun (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2750 State
.regs
[ OP
[1] ] = quotient
;
2751 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2753 /* Set condition codes. */
2754 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2756 if (overflow
) PSW
|= PSW_OV
;
2757 if (quotient
== 0) PSW
|= PSW_Z
;
2758 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2760 trace_output (OP_IMM_REG_REG_REG
);
2765 /* sdivn imm5, reg1, reg2, reg3 */
2769 signed long int quotient
;
2770 signed long int remainder
;
2771 signed long int divide_by
;
2772 signed long int divide_this
;
2773 boolean overflow
= false;
2776 trace_input ("sdivn", OP_IMM_REG_REG_REG
, 0);
2778 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2780 divide_by
= State
.regs
[ OP
[0] ];
2781 divide_this
= State
.regs
[ OP
[1] ] << imm5
;
2783 divn (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2785 State
.regs
[ OP
[1] ] = quotient
;
2786 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2788 /* Set condition codes. */
2789 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2791 if (overflow
) PSW
|= PSW_OV
;
2792 if (quotient
== 0) PSW
|= PSW_Z
;
2793 if (quotient
< 0) PSW
|= PSW_S
;
2795 trace_output (OP_IMM_REG_REG_REG
);
2800 /* sdivhun imm5, reg1, reg2, reg3 */
2804 unsigned long int quotient
;
2805 unsigned long int remainder
;
2806 unsigned long int divide_by
;
2807 unsigned long int divide_this
;
2808 boolean overflow
= false;
2811 trace_input ("sdivhun", OP_IMM_REG_REG_REG
, 0);
2813 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2815 divide_by
= State
.regs
[ OP
[0] ] & 0xffff;
2816 divide_this
= State
.regs
[ OP
[1] ] << imm5
;
2818 divun (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2820 State
.regs
[ OP
[1] ] = quotient
;
2821 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2823 /* Set condition codes. */
2824 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2826 if (overflow
) PSW
|= PSW_OV
;
2827 if (quotient
== 0) PSW
|= PSW_Z
;
2828 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2830 trace_output (OP_IMM_REG_REG_REG
);
2835 /* sdivhn imm5, reg1, reg2, reg3 */
2839 signed long int quotient
;
2840 signed long int remainder
;
2841 signed long int divide_by
;
2842 signed long int divide_this
;
2843 boolean overflow
= false;
2846 trace_input ("sdivhn", OP_IMM_REG_REG_REG
, 0);
2848 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2850 divide_by
= SEXT16 (State
.regs
[ OP
[0] ]);
2851 divide_this
= State
.regs
[ OP
[1] ] << imm5
;
2853 divn (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2855 State
.regs
[ OP
[1] ] = quotient
;
2856 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2858 /* Set condition codes. */
2859 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2861 if (overflow
) PSW
|= PSW_OV
;
2862 if (quotient
== 0) PSW
|= PSW_Z
;
2863 if (quotient
< 0) PSW
|= PSW_S
;
2865 trace_output (OP_IMM_REG_REG_REG
);
2869 /* end-sanitize-v850eq */
2871 /* start-sanitize-v850e */
2872 /* divu reg1, reg2, reg3 */
2876 unsigned long int quotient
;
2877 unsigned long int remainder
;
2878 unsigned long int divide_by
;
2879 unsigned long int divide_this
;
2880 boolean overflow
= false;
2882 if ((OP
[3] & 0x3c0000) == 0)
2884 trace_input ("divu", OP_REG_REG_REG
, 0);
2886 /* Compute the result. */
2888 divide_by
= State
.regs
[ OP
[0] ];
2889 divide_this
= State
.regs
[ OP
[1] ];
2897 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
2898 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
2900 /* Set condition codes. */
2901 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2903 if (overflow
) PSW
|= PSW_OV
;
2904 if (quotient
== 0) PSW
|= PSW_Z
;
2905 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2907 trace_output (OP_REG_REG_REG
);
2909 /* start-sanitize-v850eq */
2910 /* divun imm5, reg1, reg2, reg3 */
2915 trace_input ("divun", OP_IMM_REG_REG_REG
, 0);
2917 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2919 divide_by
= State
.regs
[ OP
[0] ];
2920 divide_this
= State
.regs
[ OP
[1] ];
2922 divun (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2924 State
.regs
[ OP
[1] ] = quotient
;
2925 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2927 /* Set condition codes. */
2928 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2930 if (overflow
) PSW
|= PSW_OV
;
2931 if (quotient
== 0) PSW
|= PSW_Z
;
2932 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2934 trace_output (OP_IMM_REG_REG_REG
);
2936 /* end-sanitize-v850eq */
2941 /* div reg1, reg2, reg3 */
2945 signed long int quotient
;
2946 signed long int remainder
;
2947 signed long int divide_by
;
2948 signed long int divide_this
;
2949 boolean overflow
= false;
2951 if ((OP
[3] & 0x3c0000) == 0)
2953 trace_input ("div", OP_REG_REG_REG
, 0);
2955 /* Compute the result. */
2957 divide_by
= State
.regs
[ OP
[0] ];
2958 divide_this
= State
.regs
[ OP
[1] ];
2960 if (divide_by
== 0 || (divide_by
== -1 && divide_this
== (1 << 31)))
2966 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
2967 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
2969 /* Set condition codes. */
2970 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2972 if (overflow
) PSW
|= PSW_OV
;
2973 if (quotient
== 0) PSW
|= PSW_Z
;
2974 if (quotient
< 0) PSW
|= PSW_S
;
2976 trace_output (OP_REG_REG_REG
);
2978 /* start-sanitize-v850eq */
2979 /* divn imm5, reg1, reg2, reg3 */
2984 trace_input ("divn", OP_IMM_REG_REG_REG
, 0);
2986 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2988 divide_by
= State
.regs
[ OP
[0] ];
2989 divide_this
= State
.regs
[ OP
[1] ];
2991 divn (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2993 State
.regs
[ OP
[1] ] = quotient
;
2994 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2996 /* Set condition codes. */
2997 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2999 if (overflow
) PSW
|= PSW_OV
;
3000 if (quotient
== 0) PSW
|= PSW_Z
;
3001 if (quotient
< 0) PSW
|= PSW_S
;
3003 trace_output (OP_IMM_REG_REG_REG
);
3005 /* end-sanitize-v850eq */
3010 /* divhu reg1, reg2, reg3 */
3014 unsigned long int quotient
;
3015 unsigned long int remainder
;
3016 unsigned long int divide_by
;
3017 unsigned long int divide_this
;
3018 boolean overflow
= false;
3020 if ((OP
[3] & 0x3c0000) == 0)
3022 trace_input ("divhu", OP_REG_REG_REG
, 0);
3024 /* Compute the result. */
3026 divide_by
= State
.regs
[ OP
[0] ] & 0xffff;
3027 divide_this
= State
.regs
[ OP
[1] ];
3035 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
3036 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
3038 /* Set condition codes. */
3039 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3041 if (overflow
) PSW
|= PSW_OV
;
3042 if (quotient
== 0) PSW
|= PSW_Z
;
3043 if (quotient
& 0x80000000) PSW
|= PSW_S
;
3045 trace_output (OP_REG_REG_REG
);
3047 /* start-sanitize-v850eq */
3048 /* divhun imm5, reg1, reg2, reg3 */
3053 trace_input ("divhun", OP_IMM_REG_REG_REG
, 0);
3055 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
3057 divide_by
= State
.regs
[ OP
[0] ] & 0xffff;
3058 divide_this
= State
.regs
[ OP
[1] ];
3060 divun (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
3062 State
.regs
[ OP
[1] ] = quotient
;
3063 State
.regs
[ OP
[2] >> 11 ] = remainder
;
3065 /* Set condition codes. */
3066 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3068 if (overflow
) PSW
|= PSW_OV
;
3069 if (quotient
== 0) PSW
|= PSW_Z
;
3070 if (quotient
& 0x80000000) PSW
|= PSW_S
;
3072 trace_output (OP_IMM_REG_REG_REG
);
3074 /* end-sanitize-v850eq */
3079 /* divh reg1, reg2, reg3 */
3083 signed long int quotient
;
3084 signed long int remainder
;
3085 signed long int divide_by
;
3086 signed long int divide_this
;
3087 boolean overflow
= false;
3089 if ((OP
[3] & 0x3c0000) == 0)
3091 trace_input ("divh", OP_REG_REG_REG
, 0);
3093 /* Compute the result. */
3095 divide_by
= State
.regs
[ OP
[0] ];
3096 divide_this
= SEXT16 (State
.regs
[ OP
[1] ]);
3098 if (divide_by
== 0 || (divide_by
== -1 && divide_this
== (1 << 31)))
3104 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
3105 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
3107 /* Set condition codes. */
3108 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3110 if (overflow
) PSW
|= PSW_OV
;
3111 if (quotient
== 0) PSW
|= PSW_Z
;
3112 if (quotient
< 0) PSW
|= PSW_S
;
3114 trace_output (OP_REG_REG_REG
);
3116 /* start-sanitize-v850eq */
3117 /* divhn imm5, reg1, reg2, reg3 */
3122 trace_input ("divhn", OP_IMM_REG_REG_REG
, 0);
3124 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
3126 divide_by
= SEXT16 (State
.regs
[ OP
[0] ]);
3127 divide_this
= State
.regs
[ OP
[1] ];
3129 divn (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
3131 State
.regs
[ OP
[1] ] = quotient
;
3132 State
.regs
[ OP
[2] >> 11 ] = remainder
;
3134 /* Set condition codes. */
3135 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3137 if (overflow
) PSW
|= PSW_OV
;
3138 if (quotient
== 0) PSW
|= PSW_Z
;
3139 if (quotient
< 0) PSW
|= PSW_S
;
3141 trace_output (OP_IMM_REG_REG_REG
);
3143 /* end-sanitize-v850eq */
3148 /* mulu imm9, reg2, reg3 */
3152 trace_input ("mulu", OP_IMM_REG_REG
, 0);
3154 Multiply64 (false, (OP
[3] & 0x1f) | ((OP
[3] >> 13) & 0x1e0));
3156 trace_output (OP_IMM_REG_REG
);
3161 /* mul imm9, reg2, reg3 */
3165 trace_input ("mul", OP_IMM_REG_REG
, 0);
3167 Multiply64 (true, (OP
[3] & 0x1f) | ((OP
[3] >> 13) & 0x1e0));
3169 trace_output (OP_IMM_REG_REG
);
3174 /* cmov imm5, reg2, reg3 */
3178 trace_input ("cmov", OP_IMM_REG_REG
, 0);
3180 State
.regs
[ OP
[2] >> 11 ] = condition_met (OP
[0]) ? SEXT5( OP
[0] ) : State
.regs
[ OP
[1] ];
3182 trace_output (OP_IMM_REG_REG
);
3192 trace_input ("ctret", OP_NONE
, 0);
3197 trace_output (OP_NONE
);
3206 unsigned long value
;
3208 trace_input ("hsw", OP_REG_REG3
, 0);
3210 value
= State
.regs
[ OP
[ 1 ] ];
3212 value
|= (State
.regs
[ OP
[ 1 ] ] << 16);
3214 State
.regs
[ OP
[2] >> 11 ] = value
;
3216 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
3218 if (value
== 0) PSW
|= PSW_Z
;
3219 if (value
& 0x80000000) PSW
|= PSW_S
;
3220 if (((value
& 0xffff) == 0) || (value
& 0xffff0000) == 0) PSW
|= PSW_CY
;
3222 trace_output (OP_REG_REG3
);
3227 #define WORDHASNULLBYTE(x) (((x) - 0x01010101) & ~(x)&0x80808080)
3233 unsigned long value
;
3235 trace_input ("bsw", OP_REG_REG3
, 0);
3237 value
= State
.regs
[ OP
[ 1 ] ];
3239 value
|= (State
.regs
[ OP
[ 1 ] ] << 24);
3240 value
|= ((State
.regs
[ OP
[ 1 ] ] << 8) & 0x00ff0000);
3241 value
|= ((State
.regs
[ OP
[ 1 ] ] >> 8) & 0x0000ff00);
3243 State
.regs
[ OP
[2] >> 11 ] = value
;
3245 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
3247 if (value
== 0) PSW
|= PSW_Z
;
3248 if (value
& 0x80000000) PSW
|= PSW_S
;
3249 if (WORDHASNULLBYTE (value
)) PSW
|= PSW_CY
;
3251 trace_output (OP_REG_REG3
);
3260 unsigned long value
;
3262 trace_input ("bsh", OP_REG_REG3
, 0);
3264 value
= State
.regs
[ OP
[ 1 ] ];
3266 value
|= ((State
.regs
[ OP
[ 1 ] ] << 8) & 0xff00ff00);
3267 value
|= ((State
.regs
[ OP
[ 1 ] ] >> 8) & 0x000000ff);
3269 State
.regs
[ OP
[2] >> 11 ] = value
;
3271 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
3273 if (value
== 0) PSW
|= PSW_Z
;
3274 if (value
& 0x80000000) PSW
|= PSW_S
;
3275 if (((value
& 0xff) == 0) || (value
& 0x00ff) == 0) PSW
|= PSW_CY
;
3277 trace_output (OP_REG_REG3
);
3291 trace_input ("pushml", OP_PUSHPOP3
, 0);
3293 /* Store the registers with lower number registers being placed at higher addresses. */
3294 for (i
= 0; i
< 15; i
++)
3295 if ((OP
[3] & (1 << type3_regs
[ i
])))
3298 store_mem (SP
& ~ 3, 4, State
.regs
[ i
+ 1 ]);
3301 if (OP
[3] & (1 << 3))
3305 store_mem (SP
& ~ 3, 4, PSW
);
3308 if (OP
[3] & (1 << 19))
3312 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
3314 store_mem ((SP
+ 4) & ~ 3, 4, FEPC
);
3315 store_mem ( SP
& ~ 3, 4, FEPSW
);
3319 store_mem ((SP
+ 4) & ~ 3, 4, EIPC
);
3320 store_mem ( SP
& ~ 3, 4, EIPSW
);
3324 trace_output (OP_PUSHPOP2
);
3330 trace_input ("ld.hu", OP_LOAD32
, 2);
3332 adr
= State
.regs
[ OP
[0] ] + SEXT16 (OP
[2] & ~1);
3335 State
.regs
[ OP
[1] ] = load_mem (adr
, 2);
3337 trace_output (OP_LOAD32
);
3343 /* prepare list12, imm5 */
3352 trace_input ("prepare", OP_PUSHPOP1
, 0);
3354 /* Store the registers with lower number registers being placed at higher addresses. */
3355 for (i
= 0; i
< 12; i
++)
3356 if ((OP
[3] & (1 << type1_regs
[ i
])))
3359 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
3362 SP
-= (OP
[3] & 0x3e) << 1;
3364 trace_output (OP_PUSHPOP1
);
3370 trace_input ("ld.bu", OP_LOAD32
, 1);
3372 adr
= State
.regs
[ OP
[0] ] + SEXT16 (OP
[2] & ~1) | ((OP
[3] >> 5) & 1);
3374 State
.regs
[ OP
[1] ] = load_mem (adr
, 1);
3376 trace_output (OP_LOAD32
);
3382 /* prepare list12, imm5, imm32 */
3388 trace_input ("prepare", OP_PUSHPOP1
, 0);
3390 /* Store the registers with lower number registers being placed at higher addresses. */
3391 for (i
= 0; i
< 12; i
++)
3392 if ((OP
[3] & (1 << type1_regs
[ i
])))
3395 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
3398 SP
-= (OP
[3] & 0x3e) << 1;
3400 EP
= load_mem (PC
+ 4, 4);
3402 trace_output (OP_PUSHPOP1
);
3407 /* prepare list12, imm5, imm16-32 */
3413 trace_input ("prepare", OP_PUSHPOP1
, 0);
3415 /* Store the registers with lower number registers being placed at higher addresses. */
3416 for (i
= 0; i
< 12; i
++)
3417 if ((OP
[3] & (1 << type1_regs
[ i
])))
3420 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
3423 SP
-= (OP
[3] & 0x3e) << 1;
3425 EP
= load_mem (PC
+ 4, 2) << 16;
3427 trace_output (OP_PUSHPOP1
);
3432 /* prepare list12, imm5, imm16 */
3438 trace_input ("prepare", OP_PUSHPOP1
, 0);
3440 /* Store the registers with lower number registers being placed at higher addresses. */
3441 for (i
= 0; i
< 12; i
++)
3442 if ((OP
[3] & (1 << type1_regs
[ i
])))
3445 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
3448 SP
-= (OP
[3] & 0x3e) << 1;
3450 EP
= SEXT16 (load_mem (PC
+ 4, 2));
3452 trace_output (OP_PUSHPOP1
);
3457 /* prepare list12, imm5, sp */
3463 trace_input ("prepare", OP_PUSHPOP1
, 0);
3465 /* Store the registers with lower number registers being placed at higher addresses. */
3466 for (i
= 0; i
< 12; i
++)
3467 if ((OP
[3] & (1 << type1_regs
[ i
])))
3470 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
3473 SP
-= (OP
[3] & 0x3e) << 1;
3477 trace_output (OP_PUSHPOP1
);
3486 unsigned long result
;
3488 result
= load_mem (State
.regs
[30] + ((OP
[3] & 0xf) << 1), 2);
3490 /* start-sanitize-v850eq */
3492 trace_input ("sld.h", OP_LOAD16
, 2);
3494 State
.regs
[ OP
[1] ] = SEXT16 (result
);
3496 /* end-sanitize-v850eq */
3497 trace_input ("sld.hu", OP_LOAD16
, 2);
3499 State
.regs
[ OP
[1] ] = result
;
3500 /* start-sanitize-v850eq */
3502 /* end-sanitize-v850eq */
3504 trace_output (OP_LOAD16
);
3509 /* cmov reg1, reg2, reg3 */
3513 trace_input ("cmov", OP_REG_REG_REG
, 0);
3515 State
.regs
[ OP
[2] >> 11 ] = condition_met (OP
[0]) ? State
.regs
[ OP
[0] ] : State
.regs
[ OP
[1] ];
3517 trace_output (OP_REG_REG_REG
);
3522 /* mul reg1, reg2, reg3 */
3526 trace_input ("mul", OP_REG_REG_REG
, 0);
3528 Multiply64 (true, State
.regs
[ OP
[0] ]);
3530 trace_output (OP_REG_REG_REG
);
3535 /* end-sanitize-v850e */
3536 /* start-sanitize-v850eq */
3544 trace_input ("popmh", OP_PUSHPOP2
, 0);
3546 if (OP
[3] & (1 << 19))
3548 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
3550 FEPSW
= load_mem ( SP
& ~ 3, 4);
3551 FEPC
= load_mem ((SP
+ 4) & ~ 3, 4);
3555 EIPSW
= load_mem ( SP
& ~ 3, 4);
3556 EIPC
= load_mem ((SP
+ 4) & ~ 3, 4);
3562 /* Load the registers with lower number registers being retrieved from higher addresses. */
3564 if ((OP
[3] & (1 << type2_regs
[ i
])))
3566 State
.regs
[ i
+ 16 ] = load_mem (SP
& ~ 3, 4);
3570 trace_output (OP_PUSHPOP2
);
3581 trace_input ("popml", OP_PUSHPOP3
, 0);
3583 if (OP
[3] & (1 << 19))
3585 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
3587 FEPSW
= load_mem ( SP
& ~ 3, 4);
3588 FEPC
= load_mem ((SP
+ 4) & ~ 3, 4);
3592 EIPSW
= load_mem ( SP
& ~ 3, 4);
3593 EIPC
= load_mem ((SP
+ 4) & ~ 3, 4);
3599 if (OP
[3] & (1 << 3))
3601 PSW
= load_mem (SP
& ~ 3, 4);
3605 /* Load the registers with lower number registers being retrieved from higher addresses. */
3607 if ((OP
[3] & (1 << type3_regs
[ i
])))
3609 State
.regs
[ i
+ 1 ] = load_mem (SP
& ~ 3, 4);
3613 trace_output (OP_PUSHPOP2
);
3622 trace_input ("pushmh", OP_PUSHPOP2
, 0);
3624 /* Store the registers with lower number registers being placed at higher addresses. */
3625 for (i
= 0; i
< 16; i
++)
3626 if ((OP
[3] & (1 << type2_regs
[ i
])))
3629 store_mem (SP
& ~ 3, 4, State
.regs
[ i
+ 16 ]);
3632 if (OP
[3] & (1 << 19))
3636 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
3638 store_mem ((SP
+ 4) & ~ 3, 4, FEPC
);
3639 store_mem ( SP
& ~ 3, 4, FEPSW
);
3643 store_mem ((SP
+ 4) & ~ 3, 4, EIPC
);
3644 store_mem ( SP
& ~ 3, 4, EIPSW
);
3648 trace_output (OP_PUSHPOP2
);
3653 /* end-sanitize-v850eq */