10 /* FIXME - should be including a version of syscall.h that does not
11 pollute the name space */
12 #include "../../libgloss/v850/sys/syscall.h"
16 #if !defined(__GO32__) && !defined(_WIN32)
18 #include <sys/times.h>
47 /* start-sanitize-v850e */
51 /* end-sanitize-v850e */
52 /* start-sanitize-v850eq */
57 /* end-sanitize-v850eq */
60 /* start-sanitize-v850e */
61 /* This is an array of the bit positions of registers r20 .. r31 in that order in a prepare/dispose instruction. */
62 static int type1_regs[12] = { 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 0, 21 };
63 /* end-sanitize-v850e */
64 /* start-sanitize-v850eq */
65 /* This is an array of the bit positions of registers r16 .. r31 in that order in a push/pop instruction. */
66 static int type2_regs[16] = { 3, 2, 1, 0, 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 20, 21};
67 /* This is an array of the bit positions of registers r1 .. r15 in that order in a push/pop instruction. */
68 static int type3_regs[15] = { 2, 1, 0, 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 20, 21};
69 /* end-sanitize-v850eq */
72 static void trace_input PARAMS ((char *name, enum op_types type, int size));
73 static void trace_output PARAMS ((enum op_types result));
74 static int init_text_p = 0;
75 static asection *text;
76 static bfd_vma text_start;
77 static bfd_vma text_end;
80 #ifndef SIZE_INSTRUCTION
81 #define SIZE_INSTRUCTION 6
85 #define SIZE_OPERANDS 16
89 #define SIZE_VALUES 11
93 #define SIZE_LOCATION 40
98 trace_input (name, type, size)
109 const char *filename;
110 const char *functionname;
111 unsigned int linenumber;
113 if ((v850_debug & DEBUG_TRACE) == 0)
120 for (s = prog_bfd->sections; s; s = s->next)
121 if (strcmp (bfd_get_section_name (prog_bfd, s), ".text") == 0)
124 text_start = bfd_get_section_vma (prog_bfd, s);
125 text_end = text_start + bfd_section_size (prog_bfd, s);
130 if (text && PC >= text_start && PC < text_end)
132 filename = (const char *)0;
133 functionname = (const char *)0;
135 if (bfd_find_nearest_line (prog_bfd, text, (struct symbol_cache_entry **)0, PC - text_start,
136 &filename, &functionname, &linenumber))
141 sprintf (p, "Line %5d ", linenumber);
147 sprintf (p, "Func %s ", functionname);
152 char *q = (char *) strrchr (filename, '/');
153 sprintf (p, "File %s ", (q) ? q+1 : filename);
162 (*v850_callback->printf_filtered) (v850_callback, "0x%.8x: %-*.*s %-*s",
164 SIZE_LOCATION, SIZE_LOCATION, buf,
165 SIZE_INSTRUCTION, name);
172 strcpy (buf, "unknown");
176 sprintf (buf, "%d", OP[0]);
180 sprintf (buf, "r%d", OP[0]);
185 case OP_REG_REG_MOVE:
186 sprintf (buf, "r%d,r%d", OP[0], OP[1]);
191 case OP_IMM_REG_MOVE:
192 sprintf (buf, "%d,r%d", OP[0], OP[1]);
196 sprintf (buf, "%d", SEXT9 (OP[0]));
200 sprintf (buf, "%d[r30],r%d", OP[1] * size, OP[0]);
204 sprintf (buf, "r%d,%d[r30]", OP[0], OP[1] * size);
208 sprintf (buf, "%d[r%d],r%d", SEXT16 (OP[2]) & ~0x1, OP[0], OP[1]);
212 sprintf (buf, "r%d,%d[r%d]", OP[1], SEXT16 (OP[2] & ~0x1), OP[0]);
216 sprintf (buf, "%d,r%d", SEXT22 (OP[0]), OP[1]);
220 sprintf (buf, "%d,r%d,r%d", SEXT16 (OP[0]), OP[1], OP[2]);
223 case OP_UIMM_REG_REG:
224 sprintf (buf, "%d,r%d,r%d", OP[0] & 0xffff, OP[1], OP[2]);
228 sprintf (buf, "%d,%d[r%d]", OP[1] & 0x7, SEXT16 (OP[2]), OP[0]);
234 default: cond = "?"; break;
235 case 0x0: cond = "v"; break;
236 case 0x1: cond = "c"; break;
237 case 0x2: cond = "z"; break;
238 case 0x3: cond = "nh"; break;
239 case 0x4: cond = "s"; break;
240 case 0x5: cond = "t"; break;
241 case 0x6: cond = "lt"; break;
242 case 0x7: cond = "le"; break;
243 case 0x8: cond = "nv"; break;
244 case 0x9: cond = "nc"; break;
245 case 0xa: cond = "nz"; break;
246 case 0xb: cond = "h"; break;
247 case 0xc: cond = "ns"; break;
248 case 0xd: cond = "sa"; break;
249 case 0xe: cond = "ge"; break;
250 case 0xf: cond = "gt"; break;
253 sprintf (buf, "%s,r%d", cond, OP[1]);
262 sprintf (buf, "r%d,s%d", OP[0], OP[1]);
266 for (i = 0; i < 12; i++)
267 if (OP[3] & (1 << type1_regs[i]))
268 strcat (buf, "r%d ", i + 20);
272 for (i = 0; i < 16; i++)
273 if (OP[3] & (1 << type2_regs[i]))
274 strcat (buf, "r%d ", i + 16);
275 if (OP[3] & (1 << 19))
276 strcat (buf, "F/EIPC, F/EIPSW " );
280 for (i = 0; i < 15; i++)
281 if (OP[3] & (1 << type3_regs[i]))
282 strcat (buf, "r%d ", i + 1);
283 if (OP[3] & (1 << 3))
284 strcat (buf, "PSW " );
285 if (OP[3] & (1 << 19))
286 strcat (buf, "F/EIPC, F/EIPSW " );
290 sprintf (buf, "r%d, [r%d]", OP[1], OP[0] );
294 if ((v850_debug & DEBUG_VALUES) == 0)
296 (*v850_callback->printf_filtered) (v850_callback, "%s\n", buf);
300 (*v850_callback->printf_filtered) (v850_callback, "%-*s", SIZE_OPERANDS, buf);
311 case OP_REG_REG_MOVE:
312 values[0] = State.regs[OP[0]];
319 values[0] = State.regs[OP[1]];
320 values[1] = State.regs[OP[0]];
326 values[0] = SEXT5 (OP[0]);
331 case OP_IMM_REG_MOVE:
332 values[0] = SEXT5 (OP[0]);
337 values[0] = State.pc;
338 values[1] = SEXT9 (OP[0]);
344 values[0] = OP[1] * size;
345 values[1] = State.regs[30];
350 values[0] = State.regs[OP[0]];
351 values[1] = OP[1] * size;
352 values[2] = State.regs[30];
357 values[0] = SEXT16 (OP[2]);
358 values[1] = State.regs[OP[0]];
363 values[0] = State.regs[OP[1]];
364 values[1] = SEXT16 (OP[2]);
365 values[2] = State.regs[OP[0]];
370 values[0] = SEXT22 (OP[0]);
371 values[1] = State.pc;
376 values[0] = SEXT16 (OP[0]) << size;
377 values[1] = State.regs[OP[1]];
381 case OP_UIMM_REG_REG:
382 values[0] = (OP[0] & 0xffff) << size;
383 values[1] = State.regs[OP[1]];
401 values[0] = State.regs[OP[0]];
406 values[0] = State.sregs[OP[1]];
410 for (i = 0; i < num_values; i++)
411 (*v850_callback->printf_filtered) (v850_callback, "%*s0x%.8lx", SIZE_VALUES - 10, "", values[i]);
414 (*v850_callback->printf_filtered) (v850_callback, "%*s", SIZE_VALUES, "");
419 trace_output (result)
420 enum op_types result;
422 if ((v850_debug & (DEBUG_TRACE | DEBUG_VALUES)) == (DEBUG_TRACE | DEBUG_VALUES))
442 (*v850_callback->printf_filtered) (v850_callback, " :: 0x%.8lx",
443 (unsigned long)State.regs[OP[0]]);
447 case OP_REG_REG_MOVE:
449 case OP_IMM_REG_MOVE:
452 (*v850_callback->printf_filtered) (v850_callback, " :: 0x%.8lx",
453 (unsigned long)State.regs[OP[1]]);
457 case OP_UIMM_REG_REG:
458 (*v850_callback->printf_filtered) (v850_callback, " :: 0x%.8lx",
459 (unsigned long)State.regs[OP[2]]);
464 (*v850_callback->printf_filtered) (v850_callback, " :: 0x%.8lx",
465 (unsigned long)State.regs[OP[1]]);
469 (*v850_callback->printf_filtered) (v850_callback, " :: 0x%.8lx",
470 (unsigned long)State.sregs[OP[1]]);
474 (*v850_callback->printf_filtered) (v850_callback, "\n");
479 #define trace_input(NAME, IN1, IN2)
480 #define trace_output(RESULT)
482 //#define trace_input(NAME, IN1, IN2) fprintf (stderr, NAME "\n" );
487 /* Returns 1 if the specific condition is met, returns 0 otherwise. */
489 condition_met (unsigned code)
491 unsigned int psw = PSW;
495 case 0x0: return ((psw & PSW_OV) != 0);
496 case 0x1: return ((psw & PSW_CY) != 0);
497 case 0x2: return ((psw & PSW_Z) != 0);
498 case 0x3: return ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) != 0);
499 case 0x4: return ((psw & PSW_S) != 0);
500 /*case 0x5: return 1;*/
501 case 0x6: return ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) != 0);
502 case 0x7: return (((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) || ((psw & PSW_Z) != 0)) != 0);
503 case 0x8: return ((psw & PSW_OV) == 0);
504 case 0x9: return ((psw & PSW_CY) == 0);
505 case 0xa: return ((psw & PSW_Z) == 0);
506 case 0xb: return ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) == 0);
507 case 0xc: return ((psw & PSW_S) == 0);
508 case 0xd: return ((psw & PSW_SAT) != 0);
509 case 0xe: return ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) == 0);
510 case 0xf: return (((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) || ((psw & PSW_Z) != 0)) == 0);
517 Add32 (unsigned long a1, unsigned long a2, int * carry)
519 unsigned long result = (a1 + a2);
521 * carry = (result < a1);
527 Multiply64 (boolean sign, unsigned long op0)
538 op1 = State.regs[ OP[1] ];
542 /* Compute sign of result and adjust operands if necessary. */
544 sign = (op0 ^ op1) & 0x80000000;
546 if (((signed long) op0) < 0)
549 if (((signed long) op1) < 0)
553 /* We can split the 32x32 into four 16x16 operations. This ensures
554 that we do not lose precision on 32bit only hosts: */
555 lo = ( (op0 & 0xFFFF) * (op1 & 0xFFFF));
556 mid1 = ( (op0 & 0xFFFF) * ((op1 >> 16) & 0xFFFF));
557 mid2 = (((op0 >> 16) & 0xFFFF) * (op1 & 0xFFFF));
558 hi = (((op0 >> 16) & 0xFFFF) * ((op1 >> 16) & 0xFFFF));
560 /* We now need to add all of these results together, taking care
561 to propogate the carries from the additions: */
562 RdLo = Add32 (lo, (mid1 << 16), & carry);
564 RdLo = Add32 (RdLo, (mid2 << 16), & carry);
565 RdHi += (carry + ((mid1 >> 16) & 0xFFFF) + ((mid2 >> 16) & 0xFFFF) + hi);
569 /* Negate result if necessary. */
573 if (RdLo == 0xFFFFFFFF)
582 State.regs[ OP[1] ] = RdLo;
583 State.regs[ OP[2] >> 11 ] = RdHi;
593 unsigned long result;
595 result = load_mem (State.regs[30] + (OP[3] & 0x7f), 1);
597 /* start-sanitize-v850eq */
599 trace_input ("sld.bu", OP_LOAD16, 1);
601 State.regs[ OP[1] ] = result;
603 /* end-sanitize-v850eq */
604 trace_input ("sld.b", OP_LOAD16, 1);
606 State.regs[ OP[1] ] = SEXT8 (result);
607 /* start-sanitize-v850eq */
609 /* end-sanitize-v850eq */
611 trace_output (OP_LOAD16);
620 unsigned long result;
622 result = load_mem (State.regs[30] + ((OP[3] & 0x7f) << 1), 2);
624 /* start-sanitize-v850eq */
626 trace_input ("sld.hu", OP_LOAD16, 2);
628 State.regs[ OP[1] ] = result;
630 /* end-sanitize-v850eq */
631 trace_input ("sld.h", OP_LOAD16, 2);
633 State.regs[ OP[1] ] = SEXT16 (result);
634 /* start-sanitize-v850eq */
636 /* end-sanitize-v850eq */
638 trace_output (OP_LOAD16);
647 trace_input ("sld.w", OP_LOAD16, 4);
649 State.regs[ OP[1] ] = load_mem (State.regs[30] + ((OP[3] & 0x7f) << 1), 4);
651 trace_output (OP_LOAD16);
660 trace_input ("sst.b", OP_STORE16, 1);
662 store_mem (State.regs[30] + (OP[3] & 0x7f), 1, State.regs[ OP[1] ]);
664 trace_output (OP_STORE16);
673 trace_input ("sst.h", OP_STORE16, 2);
675 store_mem (State.regs[30] + ((OP[3] & 0x7f) << 1), 2, State.regs[ OP[1] ]);
677 trace_output (OP_STORE16);
686 trace_input ("sst.w", OP_STORE16, 4);
688 store_mem (State.regs[30] + ((OP[3] & 0x7e) << 1), 4, State.regs[ OP[1] ]);
690 trace_output (OP_STORE16);
701 trace_input ("ld.b", OP_LOAD32, 1);
703 adr = State.regs[ OP[0] ] + SEXT16 (OP[2]);
705 State.regs[ OP[1] ] = SEXT8 (load_mem (adr, 1));
707 trace_output (OP_LOAD32);
718 trace_input ("ld.h", OP_LOAD32, 2);
720 adr = State.regs[ OP[0] ] + SEXT16 (OP[2]);
723 State.regs[ OP[1] ] = SEXT16 (load_mem (adr, 2));
725 trace_output (OP_LOAD32);
736 trace_input ("ld.w", OP_LOAD32, 4);
738 adr = State.regs[ OP[0] ] + SEXT16 (OP[2] & ~1);
741 State.regs[ OP[1] ] = load_mem (adr, 4);
743 trace_output (OP_LOAD32);
752 trace_input ("st.b", OP_STORE32, 1);
754 store_mem (State.regs[ OP[0] ] + SEXT16 (OP[2]), 1, State.regs[ OP[1] ]);
756 trace_output (OP_STORE32);
767 trace_input ("st.h", OP_STORE32, 2);
769 adr = State.regs[ OP[0] ] + SEXT16 (OP[2]);
772 store_mem (adr, 2, State.regs[ OP[1] ]);
774 trace_output (OP_STORE32);
785 trace_input ("st.w", OP_STORE32, 4);
787 adr = State.regs[ OP[0] ] + SEXT16 (OP[2] & ~1);
790 store_mem (adr, 4, State.regs[ OP[1] ]);
792 trace_output (OP_STORE32);
800 trace_input ("Bcond", OP_COND_BR, 0);
801 trace_output (OP_COND_BR);
803 if (condition_met (code))
804 return SEXT9 (((OP[3] & 0x70) >> 3) | ((OP[3] & 0xf800) >> 7));
922 /* sld.bu disp4[ep], reg2 */
928 trace_input ("jmp", OP_REG, 0);
930 PC = State.regs[ OP[0] ];
932 trace_output (OP_REG);
934 return 0; /* Add nothing to the PC, we have already done it. */
936 /* start-sanitize-v850e */
939 unsigned long result;
941 result = load_mem (State.regs[30] + (OP[3] & 0xf), 1);
943 /* start-sanitize-v850eq */
945 trace_input ("sld.b", OP_LOAD16, 1);
947 State.regs[ OP[1] ] = SEXT8 (result);
949 /* end-sanitize-v850eq */
950 trace_input ("sld.bu", OP_LOAD16, 1);
952 State.regs[ OP[1] ] = result;
953 /* start-sanitize-v850eq */
955 /* end-sanitize-v850eq */
957 trace_output (OP_LOAD16);
961 /* end-sanitize-v850e */
964 /* jarl/jr disp22, reg */
968 trace_input ("jarl/jr", OP_JUMP, 0);
971 State.regs[ OP[1] ] = PC + 4;
973 trace_output (OP_JUMP);
975 return SEXT22 (((OP[3] & 0x3f) << 16) | OP[2]);
982 unsigned int op0, op1, result, z, s, cy, ov;
984 trace_input ("add", OP_REG_REG, 0);
986 /* Compute the result. */
988 op0 = State.regs[ OP[0] ];
989 op1 = State.regs[ OP[1] ];
993 /* Compute the condition codes. */
995 s = (result & 0x80000000);
996 cy = (result < op0 || result < op1);
997 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
998 && (op0 & 0x80000000) != (result & 0x80000000));
1000 /* Store the result and condition codes. */
1001 State.regs[OP[1]] = result;
1002 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1003 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1004 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1005 trace_output (OP_REG_REG);
1010 /* add sign_extend(imm5), reg */
1014 unsigned int op0, op1, result, z, s, cy, ov;
1017 trace_input ("add", OP_IMM_REG, 0);
1019 /* Compute the result. */
1020 temp = SEXT5 (OP[0]);
1022 op1 = State.regs[OP[1]];
1025 /* Compute the condition codes. */
1027 s = (result & 0x80000000);
1028 cy = (result < op0 || result < op1);
1029 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
1030 && (op0 & 0x80000000) != (result & 0x80000000));
1032 /* Store the result and condition codes. */
1033 State.regs[OP[1]] = result;
1034 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1035 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1036 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1037 trace_output (OP_IMM_REG);
1042 /* addi sign_extend(imm16), reg, reg */
1046 unsigned int op0, op1, result, z, s, cy, ov;
1048 trace_input ("addi", OP_IMM_REG_REG, 0);
1050 /* Compute the result. */
1052 op0 = SEXT16 (OP[2]);
1053 op1 = State.regs[ OP[0] ];
1056 /* Compute the condition codes. */
1058 s = (result & 0x80000000);
1059 cy = (result < op0 || result < op1);
1060 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
1061 && (op0 & 0x80000000) != (result & 0x80000000));
1063 /* Store the result and condition codes. */
1064 State.regs[OP[1]] = result;
1065 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1066 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1067 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1068 trace_output (OP_IMM_REG_REG);
1073 /* sub reg1, reg2 */
1077 unsigned int op0, op1, result, z, s, cy, ov;
1079 trace_input ("sub", OP_REG_REG, 0);
1080 /* Compute the result. */
1081 op0 = State.regs[ OP[0] ];
1082 op1 = State.regs[ OP[1] ];
1085 /* Compute the condition codes. */
1087 s = (result & 0x80000000);
1089 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1090 && (op1 & 0x80000000) != (result & 0x80000000));
1092 /* Store the result and condition codes. */
1093 State.regs[OP[1]] = result;
1094 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1095 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1096 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1097 trace_output (OP_REG_REG);
1102 /* subr reg1, reg2 */
1106 unsigned int op0, op1, result, z, s, cy, ov;
1108 trace_input ("subr", OP_REG_REG, 0);
1109 /* Compute the result. */
1110 op0 = State.regs[ OP[0] ];
1111 op1 = State.regs[ OP[1] ];
1114 /* Compute the condition codes. */
1116 s = (result & 0x80000000);
1118 ov = ((op0 & 0x80000000) != (op1 & 0x80000000)
1119 && (op0 & 0x80000000) != (result & 0x80000000));
1121 /* Store the result and condition codes. */
1122 State.regs[OP[1]] = result;
1123 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1124 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1125 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1126 trace_output (OP_REG_REG);
1132 /* mulh reg1, reg2 */
1136 /* start-sanitize-v850e */
1139 trace_input ("sxh", OP_REG, 0);
1141 State.regs[ OP[0] ] = SEXT16 (State.regs[ OP[0] ]);
1143 trace_output (OP_REG);
1146 /* end-sanitize-v850e */
1148 trace_input ("mulh", OP_REG_REG, 0);
1150 State.regs[ OP[1] ] = (SEXT16 (State.regs[ OP[1] ]) * SEXT16 (State.regs[ OP[0] ]));
1152 trace_output (OP_REG_REG);
1158 /* mulh sign_extend(imm5), reg2 */
1162 trace_input ("mulh", OP_IMM_REG, 0);
1164 State.regs[ OP[1] ] = SEXT16 (State.regs[ OP[1] ]) * SEXT5 (OP[0]);
1166 trace_output (OP_IMM_REG);
1171 /* mulhi imm16, reg1, reg2 */
1180 trace_input ("mulhi", OP_IMM_REG_REG, 0);
1182 State.regs[ OP[1] ] = SEXT16 (State.regs[ OP[0] ]) * SEXT16 (OP[2]);
1184 trace_output (OP_IMM_REG_REG);
1190 /* divh reg1, reg2 */
1195 /* start-sanitize-v850e */
1200 trace_input ("switch", OP_REG, 0);
1202 adr = State.pc + 2 + (State.regs[ OP[0] ] << 1);
1203 State.pc = State.pc + 2 + (SEXT16 (load_mem (adr, 2)) << 1);
1205 trace_output (OP_REG);
1208 /* end-sanitize-v850e */
1210 unsigned int op0, op1, result, ov, s, z;
1213 trace_input ("divh", OP_REG_REG, 0);
1215 /* Compute the result. */
1216 temp = SEXT16 (State.regs[ OP[0] ]);
1218 op1 = State.regs[OP[1]];
1220 if (op0 == 0xffffffff && op1 == 0x80000000)
1222 result = 0x80000000;
1236 /* Compute the condition codes. */
1238 s = (result & 0x80000000);
1240 /* Store the result and condition codes. */
1241 State.regs[OP[1]] = result;
1242 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1243 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1244 | (ov ? PSW_OV : 0));
1245 trace_output (OP_REG_REG);
1255 unsigned int op0, op1, result, z, s, cy, ov;
1257 trace_input ("cmp", OP_REG_REG_CMP, 0);
1258 /* Compute the result. */
1259 op0 = State.regs[ OP[0] ];
1260 op1 = State.regs[ OP[1] ];
1263 /* Compute the condition codes. */
1265 s = (result & 0x80000000);
1267 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1268 && (op1 & 0x80000000) != (result & 0x80000000));
1270 /* Set condition codes. */
1271 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1272 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1273 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1274 trace_output (OP_REG_REG_CMP);
1279 /* cmp sign_extend(imm5), reg */
1283 unsigned int op0, op1, result, z, s, cy, ov;
1286 /* Compute the result. */
1287 trace_input ("cmp", OP_IMM_REG_CMP, 0);
1288 temp = SEXT5 (OP[0]);
1290 op1 = State.regs[OP[1]];
1293 /* Compute the condition codes. */
1295 s = (result & 0x80000000);
1297 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1298 && (op1 & 0x80000000) != (result & 0x80000000));
1300 /* Set condition codes. */
1301 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1302 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1303 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1304 trace_output (OP_IMM_REG_CMP);
1309 /* setf cccc,reg2 */
1313 trace_input ("setf", OP_EX1, 0);
1315 State.regs[ OP[1] ] = condition_met (OP[0]);
1317 trace_output (OP_EX1);
1323 /* satadd reg,reg */
1327 /* start-sanitize-v850e */
1330 trace_input ("zxh", OP_REG, 0);
1332 State.regs[ OP[0] ] &= 0xffff;
1334 trace_output (OP_REG);
1337 /* end-sanitize-v850e */
1339 unsigned int op0, op1, result, z, s, cy, ov, sat;
1341 trace_input ("satadd", OP_REG_REG, 0);
1342 /* Compute the result. */
1343 op0 = State.regs[ OP[0] ];
1344 op1 = State.regs[ OP[1] ];
1347 /* Compute the condition codes. */
1349 s = (result & 0x80000000);
1350 cy = (result < op0 || result < op1);
1351 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
1352 && (op0 & 0x80000000) != (result & 0x80000000));
1355 /* Store the result and condition codes. */
1356 State.regs[OP[1]] = result;
1357 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1358 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1359 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1360 | (sat ? PSW_SAT : 0));
1362 /* Handle saturated results. */
1364 State.regs[OP[1]] = 0x80000000;
1366 State.regs[OP[1]] = 0x7fffffff;
1367 trace_output (OP_REG_REG);
1373 /* satadd sign_extend(imm5), reg */
1377 unsigned int op0, op1, result, z, s, cy, ov, sat;
1381 trace_input ("satadd", OP_IMM_REG, 0);
1383 /* Compute the result. */
1384 temp = SEXT5 (OP[0]);
1386 op1 = State.regs[OP[1]];
1389 /* Compute the condition codes. */
1391 s = (result & 0x80000000);
1392 cy = (result < op0 || result < op1);
1393 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
1394 && (op0 & 0x80000000) != (result & 0x80000000));
1397 /* Store the result and condition codes. */
1398 State.regs[OP[1]] = result;
1399 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1400 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1401 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1402 | (sat ? PSW_SAT : 0));
1404 /* Handle saturated results. */
1406 State.regs[OP[1]] = 0x80000000;
1408 State.regs[OP[1]] = 0x7fffffff;
1409 trace_output (OP_IMM_REG);
1414 /* satsub reg1, reg2 */
1419 /* start-sanitize-v850e */
1422 trace_input ("sxb", OP_REG, 0);
1424 State.regs[ OP[0] ] = SEXT8 (State.regs[ OP[0] ]);
1426 trace_output (OP_REG);
1429 /* end-sanitize-v850e */
1431 unsigned int op0, op1, result, z, s, cy, ov, sat;
1433 trace_input ("satsub", OP_REG_REG, 0);
1435 /* Compute the result. */
1436 op0 = State.regs[ OP[0] ];
1437 op1 = State.regs[ OP[1] ];
1440 /* Compute the condition codes. */
1442 s = (result & 0x80000000);
1444 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1445 && (op1 & 0x80000000) != (result & 0x80000000));
1448 /* Store the result and condition codes. */
1449 State.regs[OP[1]] = result;
1450 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1451 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1452 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1453 | (sat ? PSW_SAT : 0));
1455 /* Handle saturated results. */
1457 State.regs[OP[1]] = 0x80000000;
1459 State.regs[OP[1]] = 0x7fffffff;
1460 trace_output (OP_REG_REG);
1466 /* satsubi sign_extend(imm16), reg */
1470 unsigned int op0, op1, result, z, s, cy, ov, sat;
1473 trace_input ("satsubi", OP_IMM_REG, 0);
1475 /* Compute the result. */
1476 temp = SEXT16 (OP[2]);
1478 op1 = State.regs[ OP[0] ];
1481 /* Compute the condition codes. */
1483 s = (result & 0x80000000);
1485 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1486 && (op1 & 0x80000000) != (result & 0x80000000));
1489 /* Store the result and condition codes. */
1490 State.regs[OP[1]] = result;
1491 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1492 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1493 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1494 | (sat ? PSW_SAT : 0));
1496 /* Handle saturated results. */
1498 State.regs[OP[1]] = 0x80000000;
1500 State.regs[OP[1]] = 0x7fffffff;
1501 trace_output (OP_IMM_REG);
1506 /* satsubr reg,reg */
1511 /* start-sanitize-v850e */
1514 trace_input ("zxb", OP_REG, 0);
1516 State.regs[ OP[0] ] &= 0xff;
1518 trace_output (OP_REG);
1521 /* end-sanitize-v850e */
1523 unsigned int op0, op1, result, z, s, cy, ov, sat;
1525 trace_input ("satsubr", OP_REG_REG, 0);
1527 /* Compute the result. */
1528 op0 = State.regs[ OP[0] ];
1529 op1 = State.regs[ OP[1] ];
1532 /* Compute the condition codes. */
1534 s = (result & 0x80000000);
1535 cy = (result < op0);
1536 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1537 && (op1 & 0x80000000) != (result & 0x80000000));
1540 /* Store the result and condition codes. */
1541 State.regs[OP[1]] = result;
1542 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1543 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1544 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1545 | (sat ? PSW_SAT : 0));
1547 /* Handle saturated results. */
1549 State.regs[OP[1]] = 0x80000000;
1551 State.regs[OP[1]] = 0x7fffffff;
1552 trace_output (OP_REG_REG);
1562 unsigned int op0, op1, result, z, s;
1564 trace_input ("tst", OP_REG_REG_CMP, 0);
1566 /* Compute the result. */
1567 op0 = State.regs[ OP[0] ];
1568 op1 = State.regs[ OP[1] ];
1571 /* Compute the condition codes. */
1573 s = (result & 0x80000000);
1575 /* Store the condition codes. */
1576 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1577 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1578 trace_output (OP_REG_REG_CMP);
1587 trace_input ("mov", OP_REG_REG_MOVE, 0);
1589 State.regs[ OP[1] ] = State.regs[ OP[0] ];
1591 trace_output (OP_REG_REG_MOVE);
1596 /* mov sign_extend(imm5), reg */
1601 /* start-sanitize-v850e */
1606 trace_input ("callt", OP_LOAD16, 1);
1611 adr = CTBP + ((OP[3] & 0x3f) << 1);
1613 PC = CTBP + load_mem (adr, 1);
1615 trace_output (OP_LOAD16);
1620 /* end-sanitize-v850e */
1622 int value = SEXT5 (OP[0]);
1624 trace_input ("mov", OP_IMM_REG_MOVE, 0);
1626 State.regs[ OP[1] ] = value;
1628 trace_output (OP_IMM_REG_MOVE);
1634 /* mov imm32, reg1 */
1635 /* movea sign_extend(imm16), reg, reg */
1639 /* start-sanitize-v850e */
1642 trace_input ("mov", OP_IMM32_REG, 4);
1644 State.regs[ OP[0] ] = load_mem (PC + 2, 4);
1646 trace_output (OP_IMM32_REG);
1651 /* end-sanitize-v850e */
1653 trace_input ("movea", OP_IMM_REG_REG, 0);
1655 State.regs[ OP[1] ] = State.regs[ OP[0] ] + SEXT16 (OP[2]);
1657 trace_output (OP_IMM_REG_REG);
1663 /* dispose imm5, list12 [, reg1] */
1664 /* movhi imm16, reg, reg */
1668 /* start-sanitize-v850e */
1674 trace_input ("dispose", OP_PUSHPOP1, 0);
1676 SP += (OP[3] & 0x3e) << 1;
1678 /* Load the registers with lower number registers being retrieved from higher addresses. */
1680 if ((OP[3] & (1 << type1_regs[ i ])))
1682 State.regs[ 20 + i ] = load_mem (SP, 4);
1686 if ((OP[3] & 0x1f0000) != 0)
1688 PC = State.regs[ (OP[3] >> 16) & 0x1f];
1692 trace_output (OP_PUSHPOP1);
1695 /* end-sanitize-v850e */
1697 trace_input ("movhi", OP_UIMM_REG_REG, 16);
1699 State.regs[ OP[1] ] = State.regs[ OP[0] ] + (OP[2] << 16);
1701 trace_output (OP_UIMM_REG_REG);
1707 /* sar zero_extend(imm5),reg1 */
1711 unsigned int op0, op1, result, z, s, cy;
1713 trace_input ("sar", OP_IMM_REG, 0);
1715 op1 = State.regs[ OP[1] ];
1716 result = (signed)op1 >> op0;
1718 /* Compute the condition codes. */
1720 s = (result & 0x80000000);
1721 cy = (op1 & (1 << (op0 - 1)));
1723 /* Store the result and condition codes. */
1724 State.regs[ OP[1] ] = result;
1725 PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1726 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1727 | (cy ? PSW_CY : 0));
1728 trace_output (OP_IMM_REG);
1733 /* sar reg1, reg2 */
1737 unsigned int op0, op1, result, z, s, cy;
1739 trace_input ("sar", OP_REG_REG, 0);
1741 op0 = State.regs[ OP[0] ] & 0x1f;
1742 op1 = State.regs[ OP[1] ];
1743 result = (signed)op1 >> op0;
1745 /* Compute the condition codes. */
1747 s = (result & 0x80000000);
1748 cy = (op1 & (1 << (op0 - 1)));
1750 /* Store the result and condition codes. */
1751 State.regs[OP[1]] = result;
1752 PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1753 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1754 | (cy ? PSW_CY : 0));
1755 trace_output (OP_REG_REG);
1760 /* shl zero_extend(imm5),reg1 */
1764 unsigned int op0, op1, result, z, s, cy;
1766 trace_input ("shl", OP_IMM_REG, 0);
1768 op1 = State.regs[ OP[1] ];
1769 result = op1 << op0;
1771 /* Compute the condition codes. */
1773 s = (result & 0x80000000);
1774 cy = (op1 & (1 << (32 - op0)));
1776 /* Store the result and condition codes. */
1777 State.regs[OP[1]] = result;
1778 PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1779 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1780 | (cy ? PSW_CY : 0));
1781 trace_output (OP_IMM_REG);
1786 /* shl reg1, reg2 */
1790 unsigned int op0, op1, result, z, s, cy;
1792 trace_input ("shl", OP_REG_REG, 0);
1793 op0 = State.regs[ OP[0] ] & 0x1f;
1794 op1 = State.regs[ OP[1] ];
1795 result = op1 << op0;
1797 /* Compute the condition codes. */
1799 s = (result & 0x80000000);
1800 cy = (op1 & (1 << (32 - op0)));
1802 /* Store the result and condition codes. */
1803 State.regs[OP[1]] = result;
1804 PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1805 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1806 | (cy ? PSW_CY : 0));
1807 trace_output (OP_REG_REG);
1812 /* shr zero_extend(imm5),reg1 */
1816 unsigned int op0, op1, result, z, s, cy;
1818 trace_input ("shr", OP_IMM_REG, 0);
1820 op1 = State.regs[ OP[1] ];
1821 result = op1 >> op0;
1823 /* Compute the condition codes. */
1825 s = (result & 0x80000000);
1826 cy = (op1 & (1 << (op0 - 1)));
1828 /* Store the result and condition codes. */
1829 State.regs[OP[1]] = result;
1830 PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1831 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1832 | (cy ? PSW_CY : 0));
1833 trace_output (OP_IMM_REG);
1838 /* shr reg1, reg2 */
1842 unsigned int op0, op1, result, z, s, cy;
1844 trace_input ("shr", OP_REG_REG, 0);
1845 op0 = State.regs[ OP[0] ] & 0x1f;
1846 op1 = State.regs[ OP[1] ];
1847 result = op1 >> op0;
1849 /* Compute the condition codes. */
1851 s = (result & 0x80000000);
1852 cy = (op1 & (1 << (op0 - 1)));
1854 /* Store the result and condition codes. */
1855 State.regs[OP[1]] = result;
1856 PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1857 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1858 | (cy ? PSW_CY : 0));
1859 trace_output (OP_REG_REG);
1868 unsigned int op0, op1, result, z, s;
1870 trace_input ("or", OP_REG_REG, 0);
1872 /* Compute the result. */
1873 op0 = State.regs[ OP[0] ];
1874 op1 = State.regs[ OP[1] ];
1877 /* Compute the condition codes. */
1879 s = (result & 0x80000000);
1881 /* Store the result and condition codes. */
1882 State.regs[OP[1]] = result;
1883 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1884 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1885 trace_output (OP_REG_REG);
1890 /* ori zero_extend(imm16), reg, reg */
1894 unsigned int op0, op1, result, z, s;
1896 trace_input ("ori", OP_UIMM_REG_REG, 0);
1898 op1 = State.regs[ OP[0] ];
1901 /* Compute the condition codes. */
1903 s = (result & 0x80000000);
1905 /* Store the result and condition codes. */
1906 State.regs[OP[1]] = result;
1907 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1908 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1909 trace_output (OP_UIMM_REG_REG);
1918 unsigned int op0, op1, result, z, s;
1920 trace_input ("and", OP_REG_REG, 0);
1922 /* Compute the result. */
1923 op0 = State.regs[ OP[0] ];
1924 op1 = State.regs[ OP[1] ];
1927 /* Compute the condition codes. */
1929 s = (result & 0x80000000);
1931 /* Store the result and condition codes. */
1932 State.regs[OP[1]] = result;
1933 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1934 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1935 trace_output (OP_REG_REG);
1940 /* andi zero_extend(imm16), reg, reg */
1944 unsigned int result, z;
1946 trace_input ("andi", OP_UIMM_REG_REG, 0);
1948 result = OP[2] & State.regs[ OP[0] ];
1950 /* Compute the condition codes. */
1953 /* Store the result and condition codes. */
1954 State.regs[ OP[1] ] = result;
1956 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1957 PSW |= (z ? PSW_Z : 0);
1959 trace_output (OP_UIMM_REG_REG);
1968 unsigned int op0, op1, result, z, s;
1970 trace_input ("xor", OP_REG_REG, 0);
1972 /* Compute the result. */
1973 op0 = State.regs[ OP[0] ];
1974 op1 = State.regs[ OP[1] ];
1977 /* Compute the condition codes. */
1979 s = (result & 0x80000000);
1981 /* Store the result and condition codes. */
1982 State.regs[OP[1]] = result;
1983 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1984 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1985 trace_output (OP_REG_REG);
1990 /* xori zero_extend(imm16), reg, reg */
1994 unsigned int op0, op1, result, z, s;
1996 trace_input ("xori", OP_UIMM_REG_REG, 0);
1998 op1 = State.regs[ OP[0] ];
2001 /* Compute the condition codes. */
2003 s = (result & 0x80000000);
2005 /* Store the result and condition codes. */
2006 State.regs[OP[1]] = result;
2007 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2008 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
2009 trace_output (OP_UIMM_REG_REG);
2014 /* not reg1, reg2 */
2018 unsigned int op0, result, z, s;
2020 trace_input ("not", OP_REG_REG_MOVE, 0);
2021 /* Compute the result. */
2022 op0 = State.regs[ OP[0] ];
2025 /* Compute the condition codes. */
2027 s = (result & 0x80000000);
2029 /* Store the result and condition codes. */
2030 State.regs[OP[1]] = result;
2031 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2032 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
2033 trace_output (OP_REG_REG_MOVE);
2042 unsigned int op0, op1, op2;
2045 trace_input ("set1", OP_BIT, 0);
2046 op0 = State.regs[ OP[0] ];
2048 temp = SEXT16 (OP[2]);
2050 temp = load_mem (op0 + op2, 1);
2052 if ((temp & (1 << op1)) == 0)
2055 store_mem (op0 + op2, 1, temp);
2056 trace_output (OP_BIT);
2065 unsigned int op0, op1, op2;
2068 trace_input ("not1", OP_BIT, 0);
2069 op0 = State.regs[ OP[0] ];
2071 temp = SEXT16 (OP[2]);
2073 temp = load_mem (op0 + op2, 1);
2075 if ((temp & (1 << op1)) == 0)
2078 store_mem (op0 + op2, 1, temp);
2079 trace_output (OP_BIT);
2088 unsigned int op0, op1, op2;
2091 trace_input ("clr1", OP_BIT, 0);
2092 op0 = State.regs[ OP[0] ];
2094 temp = SEXT16 (OP[2]);
2096 temp = load_mem (op0 + op2, 1);
2098 if ((temp & (1 << op1)) == 0)
2100 temp &= ~(1 << op1);
2101 store_mem (op0 + op2, 1, temp);
2102 trace_output (OP_BIT);
2111 unsigned int op0, op1, op2;
2114 trace_input ("tst1", OP_BIT, 0);
2115 op0 = State.regs[ OP[0] ];
2117 temp = SEXT16 (OP[2]);
2119 temp = load_mem (op0 + op2, 1);
2121 if ((temp & (1 << op1)) == 0)
2123 trace_output (OP_BIT);
2132 State.exception = SIGTRAP;
2140 trace_input ("di", OP_NONE, 0);
2142 trace_output (OP_NONE);
2151 trace_input ("ei", OP_NONE, 0);
2153 trace_output (OP_NONE);
2162 trace_input ("halt", OP_NONE, 0);
2163 /* FIXME this should put processor into a mode where NMI still handled */
2164 State.exception = SIGQUIT;
2165 trace_output (OP_NONE);
2174 trace_input ("reti", OP_NONE, 0);
2175 trace_output (OP_NONE);
2177 /* Restore for NMI if only NP on, otherwise is interrupt or exception. */
2178 if ((PSW & (PSW_NP | PSW_EP)) == PSW_NP)
2196 trace_input ("trap", OP_TRAP, 0);
2197 trace_output (OP_TRAP);
2199 /* Trap 31 is used for simulating OS I/O functions */
2203 int save_errno = errno;
2206 /* Registers passed to trap 0 */
2208 #define FUNC State.regs[6] /* function number, return value */
2209 #define PARM1 State.regs[7] /* optional parm 1 */
2210 #define PARM2 State.regs[8] /* optional parm 2 */
2211 #define PARM3 State.regs[9] /* optional parm 3 */
2213 /* Registers set by trap 0 */
2215 #define RETVAL State.regs[10] /* return value */
2216 #define RETERR State.regs[11] /* return error code */
2218 /* Turn a pointer in a register into a pointer into real memory. */
2220 #define MEMPTR(x) (map (x))
2225 #if !defined(__GO32__) && !defined(_WIN32)
2233 #if !defined(__GO32__) && !defined(_WIN32)
2236 RETVAL = execve (MEMPTR (PARM1), (char **) MEMPTR (PARM2),
2237 (char **)MEMPTR (PARM3));
2242 #if !defined(__GO32__) && !defined(_WIN32)
2245 RETVAL = execve (MEMPTR (PARM1), (char **) MEMPTR (PARM2), NULL);
2258 RETVAL = pipe (host_fd);
2259 SW (buf, host_fd[0]);
2260 buf += sizeof(uint16);
2261 SW (buf, host_fd[1]);
2273 RETVAL = wait (&status);
2282 RETVAL = sim_io_read (simulator, PARM1, MEMPTR (PARM2), PARM3);
2289 RETVAL = sim_io_write_stdout (simulator, MEMPTR (PARM2), PARM3);
2291 RETVAL = sim_io_write (simulator, PARM1, MEMPTR (PARM2), PARM3);
2297 RETVAL = sim_io_lseek (simulator, PARM1, PARM2, PARM3);
2303 RETVAL = sim_io_close (simulator, PARM1);
2309 RETVAL = sim_io_open (simulator, MEMPTR (PARM1), PARM2);
2315 if ((PARM1 & 0xffff0000) == 0xdead0000 && (PARM1 & 0xffff) != 0)
2316 State.exception = PARM1 & 0xffff; /* get signal encoded by kill */
2317 else if (PARM1 == 0xdead)
2318 State.exception = SIGABRT; /* old libraries */
2320 State.exception = SIG_V850_EXIT; /* PARM1 has exit status encoded */
2324 #if !defined(__GO32__) && !defined(_WIN32)
2326 case SYS_stat: /* added at hmsi */
2327 /* stat system call */
2329 struct stat host_stat;
2332 RETVAL = stat (MEMPTR (PARM1), &host_stat);
2336 /* Just wild-assed guesses. */
2337 store_mem (buf, 2, host_stat.st_dev);
2338 store_mem (buf + 2, 2, host_stat.st_ino);
2339 store_mem (buf + 4, 4, host_stat.st_mode);
2340 store_mem (buf + 8, 2, host_stat.st_nlink);
2341 store_mem (buf + 10, 2, host_stat.st_uid);
2342 store_mem (buf + 12, 2, host_stat.st_gid);
2343 store_mem (buf + 14, 2, host_stat.st_rdev);
2344 store_mem (buf + 16, 4, host_stat.st_size);
2345 store_mem (buf + 20, 4, host_stat.st_atime);
2346 store_mem (buf + 28, 4, host_stat.st_mtime);
2347 store_mem (buf + 36, 4, host_stat.st_ctime);
2353 #if !defined(__GO32__) && !defined(_WIN32)
2356 RETVAL = chown (MEMPTR (PARM1), PARM2, PARM3);
2364 RETVAL = chmod (MEMPTR (PARM1), PARM2);
2374 RETVAL = time (&now);
2375 store_mem (PARM1, 4, now);
2381 #if !defined(__GO32__) && !defined(_WIN32)
2386 RETVAL = times (&tms);
2387 store_mem (PARM1, 4, tms.tms_utime);
2388 store_mem (PARM1 + 4, 4, tms.tms_stime);
2389 store_mem (PARM1 + 8, 4, tms.tms_cutime);
2390 store_mem (PARM1 + 12, 4, tms.tms_cstime);
2396 #ifdef SYS_gettimeofday
2397 #if !defined(__GO32__) && !defined(_WIN32)
2398 case SYS_gettimeofday:
2402 RETVAL = gettimeofday (&t, &tz);
2403 store_mem (PARM1, 4, t.tv_sec);
2404 store_mem (PARM1 + 4, 4, t.tv_usec);
2405 store_mem (PARM2, 4, tz.tz_minuteswest);
2406 store_mem (PARM2 + 4, 4, tz.tz_dsttime);
2415 /* Cast the second argument to void *, to avoid type mismatch
2416 if a prototype is present. */
2417 RETVAL = utime (MEMPTR (PARM1), (void *) MEMPTR (PARM2));
2431 { /* Trap 0 -> 30 */
2436 ECR |= 0x40 + OP[0];
2437 /* Flag that we are now doing exception processing. */
2438 PSW |= PSW_EP | PSW_ID;
2439 PC = ((OP[0] < 0x10) ? 0x40 : 0x50) - 4;
2449 trace_input ("ldsr", OP_LDSR, 0);
2451 State.sregs[ OP[1] ] = State.regs[ OP[0] ];
2453 trace_output (OP_LDSR);
2462 trace_input ("stsr", OP_STSR, 0);
2464 State.regs[ OP[1] ] = State.sregs[ OP[0] ];
2466 trace_output (OP_STSR);
2471 /* tst1 reg2, [reg1] */
2477 trace_input ("tst1", OP_BIT_LOAD, 1);
2479 temp = load_mem (State.regs[ OP[0] ], 1);
2482 if ((temp & (1 << State.regs[ OP[1] & 0x7 ])) == 0)
2485 trace_output (OP_BIT_LOAD);
2490 /* mulu reg1, reg2, reg3 */
2494 trace_input ("mulu", OP_REG_REG_REG, 0);
2496 Multiply64 (false, State.regs[ OP[0] ]);
2498 trace_output (OP_REG_REG_REG);
2503 /* start-sanitize-v850e */
2505 #define BIT_CHANGE_OP( name, binop ) \
2507 unsigned int temp; \
2509 trace_input (name, OP_BIT_CHANGE, 0); \
2511 bit = 1 << State.regs[ OP[1] & 0x7 ]; \
2512 temp = load_mem (State.regs[ OP[0] ], 1); \
2515 if ((temp & bit) == 0) \
2519 store_mem (State.regs[ OP[0] ], 1, temp); \
2521 trace_output (OP_BIT_CHANGE); \
2525 /* clr1 reg2, [reg1] */
2529 BIT_CHANGE_OP ("clr1", &= ~ );
2532 /* not1 reg2, [reg1] */
2536 BIT_CHANGE_OP ("not1", ^= );
2543 BIT_CHANGE_OP ("set1", |= );
2550 trace_input ("sasf", OP_EX1, 0);
2552 State.regs[ OP[1] ] = (State.regs[ OP[1] ] << 1) | condition_met (OP[0]);
2554 trace_output (OP_EX1);
2558 /* end-sanitize-v850e */
2560 /* start-sanitize-v850eq */
2561 /* This function is courtesy of Sugimoto at NEC, via Seow Tan (Soew_Tan@el.nec.com) */
2566 unsigned long int als,
2567 unsigned long int sfi,
2568 unsigned long int * quotient_ptr,
2569 unsigned long int * remainder_ptr,
2570 boolean * overflow_ptr
2573 unsigned long ald = sfi >> (N - 1);
2574 unsigned long alo = als;
2579 unsigned int R1 = 1;
2580 unsigned int DBZ = (als == 0) ? 1 : 0;
2581 unsigned long alt = Q ? ~als : als;
2584 alo = ald + alt + Q;
2585 C = (((alt >> 31) & (ald >> 31))
2586 | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2589 R1 = (alo == 0) ? 0 : (R1 & Q);
2590 if ((S ^ (alo>>31)) && !C)
2595 sfi = (sfi << (32-N+1)) | Q;
2596 ald = (alo << 1) | (sfi >> 31);
2598 /* 2nd - N-1th Loop */
2599 for (i = 2; i < N; i++)
2601 alt = Q ? ~als : als;
2602 alo = ald + alt + Q;
2603 C = (((alt >> 31) & (ald >> 31))
2604 | (((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))
2621 | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2624 R1 = (alo == 0) ? 0 : (R1 & Q);
2625 if ((S ^ (alo>>31)) && !C)
2630 * quotient_ptr = (sfi << 1) | Q;
2631 * remainder_ptr = Q ? alo : (alo + als);
2632 * overflow_ptr = DBZ | R1;
2635 /* This function is courtesy of Sugimoto at NEC, via Seow Tan (Soew_Tan@el.nec.com) */
2640 unsigned long int als,
2641 unsigned long int sfi,
2642 signed long int * quotient_ptr,
2643 signed long int * remainder_ptr,
2644 boolean * overflow_ptr
2647 unsigned long ald = (signed long) sfi >> (N - 1);
2648 unsigned long alo = als;
2649 unsigned int SS = als >> 31;
2650 unsigned int SD = sfi >> 31;
2651 unsigned int R1 = 1;
2653 unsigned int DBZ = als == 0 ? 1 : 0;
2654 unsigned int Q = ~(SS ^ SD) & 1;
2658 unsigned long alt = Q ? ~als : als;
2663 alo = ald + alt + Q;
2664 C = (((alt >> 31) & (ald >> 31))
2665 | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2667 R1 = (alo == 0) ? 0 : (R1 & (Q ^ (SS ^ SD)));
2669 sfi = (sfi << (32-N+1)) | Q;
2670 ald = (alo << 1) | (sfi >> 31);
2671 if ((alo >> 31) ^ (ald >> 31))
2676 /* 2nd - N-1th Loop */
2678 for (i = 2; i < N; i++)
2680 alt = Q ? ~als : als;
2681 alo = ald + alt + Q;
2682 C = (((alt >> 31) & (ald >> 31))
2683 | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2685 R1 = (alo == 0) ? 0 : (R1 & (Q ^ (SS ^ SD)));
2687 sfi = (sfi << 1) | Q;
2688 ald = (alo << 1) | (sfi >> 31);
2689 if ((alo >> 31) ^ (ald >> 31))
2696 alt = Q ? ~als : als;
2697 alo = ald + alt + Q;
2698 C = (((alt >> 31) & (ald >> 31))
2699 | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2701 R1 = (alo == 0) ? 0 : (R1 & (Q ^ (SS ^ SD)));
2702 sfi = (sfi << (32-N+1));
2708 alt = Q ? ~als : als;
2709 alo = ald + alt + Q;
2711 R1 = R1 & ((~alo >> 31) ^ SD);
2712 if ((alo != 0) && ((Q ^ (SS ^ SD)) ^ R1)) alo = ald;
2714 ald = sfi = (long) ((sfi >> 1) | (SS ^ SD) << 31) >> (32-N-1) | Q;
2716 ald = sfi = sfi | Q;
2718 OV = DBZ | ((alo == 0) ? 0 : R1);
2720 * remainder_ptr = alo;
2723 if (((alo != 0) && ((SS ^ SD) ^ R1))
2724 || ((alo == 0) && (SS ^ R1)))
2729 OV = (DBZ | R1) ? OV : ((alo >> 31) & (~ald >> 31));
2731 * quotient_ptr = alo;
2732 * overflow_ptr = OV;
2735 /* sdivun imm5, reg1, reg2, reg3 */
2739 unsigned long int quotient;
2740 unsigned long int remainder;
2741 unsigned long int divide_by;
2742 unsigned long int divide_this;
2743 boolean overflow = false;
2746 trace_input ("sdivun", OP_IMM_REG_REG_REG, 0);
2748 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2750 divide_by = State.regs[ OP[0] ];
2751 divide_this = State.regs[ OP[1] ] << imm5;
2753 divun (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2755 State.regs[ OP[1] ] = quotient;
2756 State.regs[ OP[2] >> 11 ] = remainder;
2758 /* Set condition codes. */
2759 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2761 if (overflow) PSW |= PSW_OV;
2762 if (quotient == 0) PSW |= PSW_Z;
2763 if (quotient & 0x80000000) PSW |= PSW_S;
2765 trace_output (OP_IMM_REG_REG_REG);
2770 /* sdivn imm5, reg1, reg2, reg3 */
2774 signed long int quotient;
2775 signed long int remainder;
2776 signed long int divide_by;
2777 signed long int divide_this;
2778 boolean overflow = false;
2781 trace_input ("sdivn", OP_IMM_REG_REG_REG, 0);
2783 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2785 divide_by = State.regs[ OP[0] ];
2786 divide_this = State.regs[ OP[1] ] << imm5;
2788 divn (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2790 State.regs[ OP[1] ] = quotient;
2791 State.regs[ OP[2] >> 11 ] = remainder;
2793 /* Set condition codes. */
2794 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2796 if (overflow) PSW |= PSW_OV;
2797 if (quotient == 0) PSW |= PSW_Z;
2798 if (quotient < 0) PSW |= PSW_S;
2800 trace_output (OP_IMM_REG_REG_REG);
2805 /* sdivhun imm5, reg1, reg2, reg3 */
2809 unsigned long int quotient;
2810 unsigned long int remainder;
2811 unsigned long int divide_by;
2812 unsigned long int divide_this;
2813 boolean overflow = false;
2816 trace_input ("sdivhun", OP_IMM_REG_REG_REG, 0);
2818 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2820 divide_by = State.regs[ OP[0] ] & 0xffff;
2821 divide_this = State.regs[ OP[1] ] << imm5;
2823 divun (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2825 State.regs[ OP[1] ] = quotient;
2826 State.regs[ OP[2] >> 11 ] = remainder;
2828 /* Set condition codes. */
2829 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2831 if (overflow) PSW |= PSW_OV;
2832 if (quotient == 0) PSW |= PSW_Z;
2833 if (quotient & 0x80000000) PSW |= PSW_S;
2835 trace_output (OP_IMM_REG_REG_REG);
2840 /* sdivhn imm5, reg1, reg2, reg3 */
2844 signed long int quotient;
2845 signed long int remainder;
2846 signed long int divide_by;
2847 signed long int divide_this;
2848 boolean overflow = false;
2851 trace_input ("sdivhn", OP_IMM_REG_REG_REG, 0);
2853 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2855 divide_by = SEXT16 (State.regs[ OP[0] ]);
2856 divide_this = State.regs[ OP[1] ] << imm5;
2858 divn (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2860 State.regs[ OP[1] ] = quotient;
2861 State.regs[ OP[2] >> 11 ] = remainder;
2863 /* Set condition codes. */
2864 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2866 if (overflow) PSW |= PSW_OV;
2867 if (quotient == 0) PSW |= PSW_Z;
2868 if (quotient < 0) PSW |= PSW_S;
2870 trace_output (OP_IMM_REG_REG_REG);
2874 /* end-sanitize-v850eq */
2876 /* start-sanitize-v850e */
2877 /* divu reg1, reg2, reg3 */
2881 unsigned long int quotient;
2882 unsigned long int remainder;
2883 unsigned long int divide_by;
2884 unsigned long int divide_this;
2885 boolean overflow = false;
2887 if ((OP[3] & 0x3c0000) == 0)
2889 trace_input ("divu", OP_REG_REG_REG, 0);
2891 /* Compute the result. */
2893 divide_by = State.regs[ OP[0] ];
2894 divide_this = State.regs[ OP[1] ];
2902 State.regs[ OP[1] ] = quotient = divide_this / divide_by;
2903 State.regs[ OP[2] >> 11 ] = remainder = divide_this % divide_by;
2905 /* Set condition codes. */
2906 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2908 if (overflow) PSW |= PSW_OV;
2909 if (quotient == 0) PSW |= PSW_Z;
2910 if (quotient & 0x80000000) PSW |= PSW_S;
2912 trace_output (OP_REG_REG_REG);
2914 /* start-sanitize-v850eq */
2915 /* divun imm5, reg1, reg2, reg3 */
2920 trace_input ("divun", OP_IMM_REG_REG_REG, 0);
2922 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2924 divide_by = State.regs[ OP[0] ];
2925 divide_this = State.regs[ OP[1] ];
2927 divun (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2929 State.regs[ OP[1] ] = quotient;
2930 State.regs[ OP[2] >> 11 ] = remainder;
2932 /* Set condition codes. */
2933 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2935 if (overflow) PSW |= PSW_OV;
2936 if (quotient == 0) PSW |= PSW_Z;
2937 if (quotient & 0x80000000) PSW |= PSW_S;
2939 trace_output (OP_IMM_REG_REG_REG);
2941 /* end-sanitize-v850eq */
2946 /* div reg1, reg2, reg3 */
2950 signed long int quotient;
2951 signed long int remainder;
2952 signed long int divide_by;
2953 signed long int divide_this;
2954 boolean overflow = false;
2956 if ((OP[3] & 0x3c0000) == 0)
2958 trace_input ("div", OP_REG_REG_REG, 0);
2960 /* Compute the result. */
2962 divide_by = State.regs[ OP[0] ];
2963 divide_this = State.regs[ OP[1] ];
2965 if (divide_by == 0 || (divide_by == -1 && divide_this == (1 << 31)))
2971 State.regs[ OP[1] ] = quotient = divide_this / divide_by;
2972 State.regs[ OP[2] >> 11 ] = remainder = divide_this % divide_by;
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_REG_REG_REG);
2983 /* start-sanitize-v850eq */
2984 /* divn imm5, reg1, reg2, reg3 */
2989 trace_input ("divn", OP_IMM_REG_REG_REG, 0);
2991 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2993 divide_by = State.regs[ OP[0] ];
2994 divide_this = State.regs[ OP[1] ];
2996 divn (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2998 State.regs[ OP[1] ] = quotient;
2999 State.regs[ OP[2] >> 11 ] = remainder;
3001 /* Set condition codes. */
3002 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
3004 if (overflow) PSW |= PSW_OV;
3005 if (quotient == 0) PSW |= PSW_Z;
3006 if (quotient < 0) PSW |= PSW_S;
3008 trace_output (OP_IMM_REG_REG_REG);
3010 /* end-sanitize-v850eq */
3015 /* divhu reg1, reg2, reg3 */
3019 unsigned long int quotient;
3020 unsigned long int remainder;
3021 unsigned long int divide_by;
3022 unsigned long int divide_this;
3023 boolean overflow = false;
3025 if ((OP[3] & 0x3c0000) == 0)
3027 trace_input ("divhu", OP_REG_REG_REG, 0);
3029 /* Compute the result. */
3031 divide_by = State.regs[ OP[0] ] & 0xffff;
3032 divide_this = State.regs[ OP[1] ];
3040 State.regs[ OP[1] ] = quotient = divide_this / divide_by;
3041 State.regs[ OP[2] >> 11 ] = remainder = divide_this % divide_by;
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_REG_REG_REG);
3052 /* start-sanitize-v850eq */
3053 /* divhun imm5, reg1, reg2, reg3 */
3058 trace_input ("divhun", OP_IMM_REG_REG_REG, 0);
3060 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
3062 divide_by = State.regs[ OP[0] ] & 0xffff;
3063 divide_this = State.regs[ OP[1] ];
3065 divun (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
3067 State.regs[ OP[1] ] = quotient;
3068 State.regs[ OP[2] >> 11 ] = remainder;
3070 /* Set condition codes. */
3071 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
3073 if (overflow) PSW |= PSW_OV;
3074 if (quotient == 0) PSW |= PSW_Z;
3075 if (quotient & 0x80000000) PSW |= PSW_S;
3077 trace_output (OP_IMM_REG_REG_REG);
3079 /* end-sanitize-v850eq */
3084 /* divh reg1, reg2, reg3 */
3088 signed long int quotient;
3089 signed long int remainder;
3090 signed long int divide_by;
3091 signed long int divide_this;
3092 boolean overflow = false;
3094 if ((OP[3] & 0x3c0000) == 0)
3096 trace_input ("divh", OP_REG_REG_REG, 0);
3098 /* Compute the result. */
3100 divide_by = State.regs[ OP[0] ];
3101 divide_this = SEXT16 (State.regs[ OP[1] ]);
3103 if (divide_by == 0 || (divide_by == -1 && divide_this == (1 << 31)))
3109 State.regs[ OP[1] ] = quotient = divide_this / divide_by;
3110 State.regs[ OP[2] >> 11 ] = remainder = divide_this % divide_by;
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_REG_REG_REG);
3121 /* start-sanitize-v850eq */
3122 /* divhn imm5, reg1, reg2, reg3 */
3127 trace_input ("divhn", OP_IMM_REG_REG_REG, 0);
3129 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
3131 divide_by = SEXT16 (State.regs[ OP[0] ]);
3132 divide_this = State.regs[ OP[1] ];
3134 divn (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
3136 State.regs[ OP[1] ] = quotient;
3137 State.regs[ OP[2] >> 11 ] = remainder;
3139 /* Set condition codes. */
3140 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
3142 if (overflow) PSW |= PSW_OV;
3143 if (quotient == 0) PSW |= PSW_Z;
3144 if (quotient < 0) PSW |= PSW_S;
3146 trace_output (OP_IMM_REG_REG_REG);
3148 /* end-sanitize-v850eq */
3153 /* mulu imm9, reg2, reg3 */
3157 trace_input ("mulu", OP_IMM_REG_REG, 0);
3159 Multiply64 (false, (OP[3] & 0x1f) | ((OP[3] >> 13) & 0x1e0));
3161 trace_output (OP_IMM_REG_REG);
3166 /* mul imm9, reg2, reg3 */
3170 trace_input ("mul", OP_IMM_REG_REG, 0);
3172 Multiply64 (true, (OP[3] & 0x1f) | ((OP[3] >> 13) & 0x1e0));
3174 trace_output (OP_IMM_REG_REG);
3179 /* cmov imm5, reg2, reg3 */
3183 trace_input ("cmov", OP_IMM_REG_REG, 0);
3185 State.regs[ OP[2] >> 11 ] = condition_met (OP[0]) ? SEXT5( OP[0] ) : State.regs[ OP[1] ];
3187 trace_output (OP_IMM_REG_REG);
3197 trace_input ("ctret", OP_NONE, 0);
3202 trace_output (OP_NONE);
3211 unsigned long value;
3213 trace_input ("hsw", OP_REG_REG3, 0);
3215 value = State.regs[ OP[ 1 ] ];
3217 value |= (State.regs[ OP[ 1 ] ] << 16);
3219 State.regs[ OP[2] >> 11 ] = value;
3221 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
3223 if (value == 0) PSW |= PSW_Z;
3224 if (value & 0x80000000) PSW |= PSW_S;
3225 if (((value & 0xffff) == 0) || (value & 0xffff0000) == 0) PSW |= PSW_CY;
3227 trace_output (OP_REG_REG3);
3232 #define WORDHASNULLBYTE(x) (((x) - 0x01010101) & ~(x)&0x80808080)
3238 unsigned long value;
3240 trace_input ("bsw", OP_REG_REG3, 0);
3242 value = State.regs[ OP[ 1 ] ];
3244 value |= (State.regs[ OP[ 1 ] ] << 24);
3245 value |= ((State.regs[ OP[ 1 ] ] << 8) & 0x00ff0000);
3246 value |= ((State.regs[ OP[ 1 ] ] >> 8) & 0x0000ff00);
3248 State.regs[ OP[2] >> 11 ] = value;
3250 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
3252 if (value == 0) PSW |= PSW_Z;
3253 if (value & 0x80000000) PSW |= PSW_S;
3254 if (WORDHASNULLBYTE (value)) PSW |= PSW_CY;
3256 trace_output (OP_REG_REG3);
3265 unsigned long value;
3267 trace_input ("bsh", OP_REG_REG3, 0);
3269 value = State.regs[ OP[ 1 ] ];
3271 value |= ((State.regs[ OP[ 1 ] ] << 8) & 0xff00ff00);
3272 value |= ((State.regs[ OP[ 1 ] ] >> 8) & 0x000000ff);
3274 State.regs[ OP[2] >> 11 ] = value;
3276 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
3278 if (value == 0) PSW |= PSW_Z;
3279 if (value & 0x80000000) PSW |= PSW_S;
3280 if (((value & 0xff) == 0) || (value & 0x00ff) == 0) PSW |= PSW_CY;
3282 trace_output (OP_REG_REG3);
3296 trace_input ("pushml", OP_PUSHPOP3, 0);
3298 /* Store the registers with lower number registers being placed at higher addresses. */
3299 for (i = 0; i < 15; i++)
3300 if ((OP[3] & (1 << type3_regs[ i ])))
3303 store_mem (SP & ~ 3, 4, State.regs[ i + 1 ]);
3306 if (OP[3] & (1 << 3))
3310 store_mem (SP & ~ 3, 4, PSW);
3313 if (OP[3] & (1 << 19))
3317 if ((PSW & PSW_NP) && ((PSW & PSW_EP) == 0))
3319 store_mem ((SP + 4) & ~ 3, 4, FEPC);
3320 store_mem ( SP & ~ 3, 4, FEPSW);
3324 store_mem ((SP + 4) & ~ 3, 4, EIPC);
3325 store_mem ( SP & ~ 3, 4, EIPSW);
3329 trace_output (OP_PUSHPOP2);
3335 trace_input ("ld.hu", OP_LOAD32, 2);
3337 adr = State.regs[ OP[0] ] + SEXT16 (OP[2] & ~1);
3340 State.regs[ OP[1] ] = load_mem (adr, 2);
3342 trace_output (OP_LOAD32);
3348 /* prepare list12, imm5 */
3357 trace_input ("prepare", OP_PUSHPOP1, 0);
3359 /* Store the registers with lower number registers being placed at higher addresses. */
3360 for (i = 0; i < 12; i++)
3361 if ((OP[3] & (1 << type1_regs[ i ])))
3364 store_mem (SP, 4, State.regs[ 20 + i ]);
3367 SP -= (OP[3] & 0x3e) << 1;
3369 trace_output (OP_PUSHPOP1);
3375 trace_input ("ld.bu", OP_LOAD32, 1);
3377 adr = (State.regs[ OP[0] ]
3378 + (SEXT16 (OP[2] & ~1) | ((OP[3] >> 5) & 1)));
3380 State.regs[ OP[1] ] = load_mem (adr, 1);
3382 trace_output (OP_LOAD32);
3388 /* prepare list12, imm5, imm32 */
3394 trace_input ("prepare", OP_PUSHPOP1, 0);
3396 /* Store the registers with lower number registers being placed at higher addresses. */
3397 for (i = 0; i < 12; i++)
3398 if ((OP[3] & (1 << type1_regs[ i ])))
3401 store_mem (SP, 4, State.regs[ 20 + i ]);
3404 SP -= (OP[3] & 0x3e) << 1;
3406 EP = load_mem (PC + 4, 4);
3408 trace_output (OP_PUSHPOP1);
3413 /* prepare list12, imm5, imm16-32 */
3419 trace_input ("prepare", OP_PUSHPOP1, 0);
3421 /* Store the registers with lower number registers being placed at higher addresses. */
3422 for (i = 0; i < 12; i++)
3423 if ((OP[3] & (1 << type1_regs[ i ])))
3426 store_mem (SP, 4, State.regs[ 20 + i ]);
3429 SP -= (OP[3] & 0x3e) << 1;
3431 EP = load_mem (PC + 4, 2) << 16;
3433 trace_output (OP_PUSHPOP1);
3438 /* prepare list12, imm5, imm16 */
3444 trace_input ("prepare", OP_PUSHPOP1, 0);
3446 /* Store the registers with lower number registers being placed at higher addresses. */
3447 for (i = 0; i < 12; i++)
3448 if ((OP[3] & (1 << type1_regs[ i ])))
3451 store_mem (SP, 4, State.regs[ 20 + i ]);
3454 SP -= (OP[3] & 0x3e) << 1;
3456 EP = SEXT16 (load_mem (PC + 4, 2));
3458 trace_output (OP_PUSHPOP1);
3463 /* prepare list12, imm5, sp */
3469 trace_input ("prepare", OP_PUSHPOP1, 0);
3471 /* Store the registers with lower number registers being placed at higher addresses. */
3472 for (i = 0; i < 12; i++)
3473 if ((OP[3] & (1 << type1_regs[ i ])))
3476 store_mem (SP, 4, State.regs[ 20 + i ]);
3479 SP -= (OP[3] & 0x3e) << 1;
3483 trace_output (OP_PUSHPOP1);
3492 unsigned long result;
3494 result = load_mem (State.regs[30] + ((OP[3] & 0xf) << 1), 2);
3496 /* start-sanitize-v850eq */
3498 trace_input ("sld.h", OP_LOAD16, 2);
3500 State.regs[ OP[1] ] = SEXT16 (result);
3502 /* end-sanitize-v850eq */
3503 trace_input ("sld.hu", OP_LOAD16, 2);
3505 State.regs[ OP[1] ] = result;
3506 /* start-sanitize-v850eq */
3508 /* end-sanitize-v850eq */
3510 trace_output (OP_LOAD16);
3515 /* cmov reg1, reg2, reg3 */
3519 trace_input ("cmov", OP_REG_REG_REG, 0);
3521 State.regs[ OP[2] >> 11 ] = condition_met (OP[0]) ? State.regs[ OP[0] ] : State.regs[ OP[1] ];
3523 trace_output (OP_REG_REG_REG);
3528 /* mul reg1, reg2, reg3 */
3532 trace_input ("mul", OP_REG_REG_REG, 0);
3534 Multiply64 (true, State.regs[ OP[0] ]);
3536 trace_output (OP_REG_REG_REG);
3541 /* end-sanitize-v850e */
3542 /* start-sanitize-v850eq */
3550 trace_input ("popmh", OP_PUSHPOP2, 0);
3552 if (OP[3] & (1 << 19))
3554 if ((PSW & PSW_NP) && ((PSW & PSW_EP) == 0))
3556 FEPSW = load_mem ( SP & ~ 3, 4);
3557 FEPC = load_mem ((SP + 4) & ~ 3, 4);
3561 EIPSW = load_mem ( SP & ~ 3, 4);
3562 EIPC = load_mem ((SP + 4) & ~ 3, 4);
3568 /* Load the registers with lower number registers being retrieved from higher addresses. */
3570 if ((OP[3] & (1 << type2_regs[ i ])))
3572 State.regs[ i + 16 ] = load_mem (SP & ~ 3, 4);
3576 trace_output (OP_PUSHPOP2);
3587 trace_input ("popml", OP_PUSHPOP3, 0);
3589 if (OP[3] & (1 << 19))
3591 if ((PSW & PSW_NP) && ((PSW & PSW_EP) == 0))
3593 FEPSW = load_mem ( SP & ~ 3, 4);
3594 FEPC = load_mem ((SP + 4) & ~ 3, 4);
3598 EIPSW = load_mem ( SP & ~ 3, 4);
3599 EIPC = load_mem ((SP + 4) & ~ 3, 4);
3605 if (OP[3] & (1 << 3))
3607 PSW = load_mem (SP & ~ 3, 4);
3611 /* Load the registers with lower number registers being retrieved from higher addresses. */
3613 if ((OP[3] & (1 << type3_regs[ i ])))
3615 State.regs[ i + 1 ] = load_mem (SP & ~ 3, 4);
3619 trace_output (OP_PUSHPOP2);
3630 trace_input ("pushmh", OP_PUSHPOP2, 0);
3632 /* Store the registers with lower number registers being placed at higher addresses. */
3633 for (i = 0; i < 16; i++)
3634 if ((OP[3] & (1 << type2_regs[ i ])))
3637 store_mem (SP & ~ 3, 4, State.regs[ i + 16 ]);
3640 if (OP[3] & (1 << 19))
3644 if ((PSW & PSW_NP) && ((PSW & PSW_EP) == 0))
3646 store_mem ((SP + 4) & ~ 3, 4, FEPC);
3647 store_mem ( SP & ~ 3, 4, FEPSW);
3651 store_mem ((SP + 4) & ~ 3, 4, EIPC);
3652 store_mem ( SP & ~ 3, 4, EIPSW);
3656 trace_output (OP_PUSHPOP2);
3661 /* end-sanitize-v850eq */