14 /* FIXME - should be including a version of syscall.h that does not
15 pollute the name space */
16 #include "../../libgloss/v850/sys/syscall.h"
20 #if !defined(__GO32__) && !defined(_WIN32)
22 #include <sys/times.h>
51 /* start-sanitize-v850e */
55 /* end-sanitize-v850e */
56 /* start-sanitize-v850eq */
61 /* end-sanitize-v850eq */
64 /* start-sanitize-v850e */
65 /* This is an array of the bit positions of registers r20 .. r31 in that order in a prepare/dispose instruction. */
66 static int type1_regs[12] = { 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 0, 21 };
67 /* end-sanitize-v850e */
68 /* start-sanitize-v850eq */
69 /* This is an array of the bit positions of registers r16 .. r31 in that order in a push/pop instruction. */
70 static int type2_regs[16] = { 3, 2, 1, 0, 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 20, 21};
71 /* This is an array of the bit positions of registers r1 .. r15 in that order in a push/pop instruction. */
72 static int type3_regs[15] = { 2, 1, 0, 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 20, 21};
73 /* end-sanitize-v850eq */
76 static void trace_input PARAMS ((char *name, enum op_types type, int size));
77 static void trace_output PARAMS ((enum op_types result));
78 static int init_text_p = 0;
79 static asection *text;
80 static bfd_vma text_start;
81 static bfd_vma text_end;
84 #ifndef SIZE_INSTRUCTION
85 #define SIZE_INSTRUCTION 6
89 #define SIZE_OPERANDS 16
93 #define SIZE_VALUES 11
97 #define SIZE_LOCATION 40
102 trace_input (name, type, size)
113 const char *filename;
114 const char *functionname;
115 unsigned int linenumber;
117 if ((v850_debug & DEBUG_TRACE) == 0)
124 for (s = prog_bfd->sections; s; s = s->next)
125 if (strcmp (bfd_get_section_name (prog_bfd, s), ".text") == 0)
128 text_start = bfd_get_section_vma (prog_bfd, s);
129 text_end = text_start + bfd_section_size (prog_bfd, s);
134 if (text && PC >= text_start && PC < text_end)
136 filename = (const char *)0;
137 functionname = (const char *)0;
139 if (bfd_find_nearest_line (prog_bfd, text, (struct symbol_cache_entry **)0, PC - text_start,
140 &filename, &functionname, &linenumber))
145 sprintf (p, "Line %5d ", linenumber);
151 sprintf (p, "Func %s ", functionname);
156 char *q = (char *) strrchr (filename, '/');
157 sprintf (p, "File %s ", (q) ? q+1 : filename);
166 (*v850_callback->printf_filtered) (v850_callback, "0x%.8x: %-*.*s %-*s",
168 SIZE_LOCATION, SIZE_LOCATION, buf,
169 SIZE_INSTRUCTION, name);
176 strcpy (buf, "unknown");
180 sprintf (buf, "%d", OP[0]);
184 sprintf (buf, "r%d", OP[0]);
189 case OP_REG_REG_MOVE:
190 sprintf (buf, "r%d,r%d", OP[0], OP[1]);
195 case OP_IMM_REG_MOVE:
196 sprintf (buf, "%d,r%d", OP[0], OP[1]);
200 sprintf (buf, "%d", SEXT9 (OP[0]));
204 sprintf (buf, "%d[r30],r%d", OP[1] * size, OP[0]);
208 sprintf (buf, "r%d,%d[r30]", OP[0], OP[1] * size);
212 sprintf (buf, "%d[r%d],r%d", SEXT16 (OP[2]) & ~0x1, OP[0], OP[1]);
216 sprintf (buf, "r%d,%d[r%d]", OP[1], SEXT16 (OP[2] & ~0x1), OP[0]);
220 sprintf (buf, "%d,r%d", SEXT22 (OP[0]), OP[1]);
224 sprintf (buf, "%d,r%d,r%d", SEXT16 (OP[0]), OP[1], OP[2]);
227 case OP_UIMM_REG_REG:
228 sprintf (buf, "%d,r%d,r%d", OP[0] & 0xffff, OP[1], OP[2]);
232 sprintf (buf, "%d,%d[r%d]", OP[1] & 0x7, SEXT16 (OP[2]), OP[0]);
238 default: cond = "?"; break;
239 case 0x0: cond = "v"; break;
240 case 0x1: cond = "c"; break;
241 case 0x2: cond = "z"; break;
242 case 0x3: cond = "nh"; break;
243 case 0x4: cond = "s"; break;
244 case 0x5: cond = "t"; break;
245 case 0x6: cond = "lt"; break;
246 case 0x7: cond = "le"; break;
247 case 0x8: cond = "nv"; break;
248 case 0x9: cond = "nc"; break;
249 case 0xa: cond = "nz"; break;
250 case 0xb: cond = "h"; break;
251 case 0xc: cond = "ns"; break;
252 case 0xd: cond = "sa"; break;
253 case 0xe: cond = "ge"; break;
254 case 0xf: cond = "gt"; break;
257 sprintf (buf, "%s,r%d", cond, OP[1]);
266 sprintf (buf, "r%d,s%d", OP[0], OP[1]);
270 for (i = 0; i < 12; i++)
271 if (OP[3] & (1 << type1_regs[i]))
272 strcat (buf, "r%d ", i + 20);
276 for (i = 0; i < 16; i++)
277 if (OP[3] & (1 << type2_regs[i]))
278 strcat (buf, "r%d ", i + 16);
279 if (OP[3] & (1 << 19))
280 strcat (buf, "F/EIPC, F/EIPSW " );
284 for (i = 0; i < 15; i++)
285 if (OP[3] & (1 << type3_regs[i]))
286 strcat (buf, "r%d ", i + 1);
287 if (OP[3] & (1 << 3))
288 strcat (buf, "PSW " );
289 if (OP[3] & (1 << 19))
290 strcat (buf, "F/EIPC, F/EIPSW " );
294 sprintf (buf, "r%d, [r%d]", OP[1], OP[0] );
298 if ((v850_debug & DEBUG_VALUES) == 0)
300 (*v850_callback->printf_filtered) (v850_callback, "%s\n", buf);
304 (*v850_callback->printf_filtered) (v850_callback, "%-*s", SIZE_OPERANDS, buf);
315 case OP_REG_REG_MOVE:
316 values[0] = State.regs[OP[0]];
323 values[0] = State.regs[OP[1]];
324 values[1] = State.regs[OP[0]];
330 values[0] = SEXT5 (OP[0]);
335 case OP_IMM_REG_MOVE:
336 values[0] = SEXT5 (OP[0]);
341 values[0] = State.pc;
342 values[1] = SEXT9 (OP[0]);
348 values[0] = OP[1] * size;
349 values[1] = State.regs[30];
354 values[0] = State.regs[OP[0]];
355 values[1] = OP[1] * size;
356 values[2] = State.regs[30];
361 values[0] = SEXT16 (OP[2]);
362 values[1] = State.regs[OP[0]];
367 values[0] = State.regs[OP[1]];
368 values[1] = SEXT16 (OP[2]);
369 values[2] = State.regs[OP[0]];
374 values[0] = SEXT22 (OP[0]);
375 values[1] = State.pc;
380 values[0] = SEXT16 (OP[0]) << size;
381 values[1] = State.regs[OP[1]];
385 case OP_UIMM_REG_REG:
386 values[0] = (OP[0] & 0xffff) << size;
387 values[1] = State.regs[OP[1]];
405 values[0] = State.regs[OP[0]];
410 values[0] = State.sregs[OP[1]];
414 for (i = 0; i < num_values; i++)
415 (*v850_callback->printf_filtered) (v850_callback, "%*s0x%.8lx", SIZE_VALUES - 10, "", values[i]);
418 (*v850_callback->printf_filtered) (v850_callback, "%*s", SIZE_VALUES, "");
423 trace_output (result)
424 enum op_types result;
426 if ((v850_debug & (DEBUG_TRACE | DEBUG_VALUES)) == (DEBUG_TRACE | DEBUG_VALUES))
446 (*v850_callback->printf_filtered) (v850_callback, " :: 0x%.8lx",
447 (unsigned long)State.regs[OP[0]]);
451 case OP_REG_REG_MOVE:
453 case OP_IMM_REG_MOVE:
456 (*v850_callback->printf_filtered) (v850_callback, " :: 0x%.8lx",
457 (unsigned long)State.regs[OP[1]]);
461 case OP_UIMM_REG_REG:
462 (*v850_callback->printf_filtered) (v850_callback, " :: 0x%.8lx",
463 (unsigned long)State.regs[OP[2]]);
468 (*v850_callback->printf_filtered) (v850_callback, " :: 0x%.8lx",
469 (unsigned long)State.regs[OP[1]]);
473 (*v850_callback->printf_filtered) (v850_callback, " :: 0x%.8lx",
474 (unsigned long)State.sregs[OP[1]]);
478 (*v850_callback->printf_filtered) (v850_callback, "\n");
483 #define trace_input(NAME, IN1, IN2)
484 #define trace_output(RESULT)
486 //#define trace_input(NAME, IN1, IN2) fprintf (stderr, NAME "\n" );
491 /* Returns 1 if the specific condition is met, returns 0 otherwise. */
493 condition_met (unsigned code)
495 unsigned int psw = PSW;
499 case 0x0: return ((psw & PSW_OV) != 0);
500 case 0x1: return ((psw & PSW_CY) != 0);
501 case 0x2: return ((psw & PSW_Z) != 0);
502 case 0x3: return ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) != 0);
503 case 0x4: return ((psw & PSW_S) != 0);
504 /*case 0x5: return 1;*/
505 case 0x6: return ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) != 0);
506 case 0x7: return (((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) || ((psw & PSW_Z) != 0)) != 0);
507 case 0x8: return ((psw & PSW_OV) == 0);
508 case 0x9: return ((psw & PSW_CY) == 0);
509 case 0xa: return ((psw & PSW_Z) == 0);
510 case 0xb: return ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) == 0);
511 case 0xc: return ((psw & PSW_S) == 0);
512 case 0xd: return ((psw & PSW_SAT) != 0);
513 case 0xe: return ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) == 0);
514 case 0xf: return (((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) || ((psw & PSW_Z) != 0)) == 0);
521 Add32 (unsigned long a1, unsigned long a2, int * carry)
523 unsigned long result = (a1 + a2);
525 * carry = (result < a1);
531 Multiply64 (boolean sign, unsigned long op0)
542 op1 = State.regs[ OP[1] ];
546 /* Compute sign of result and adjust operands if necessary. */
548 sign = (op0 ^ op1) & 0x80000000;
550 if (((signed long) op0) < 0)
553 if (((signed long) op1) < 0)
557 /* We can split the 32x32 into four 16x16 operations. This ensures
558 that we do not lose precision on 32bit only hosts: */
559 lo = ( (op0 & 0xFFFF) * (op1 & 0xFFFF));
560 mid1 = ( (op0 & 0xFFFF) * ((op1 >> 16) & 0xFFFF));
561 mid2 = (((op0 >> 16) & 0xFFFF) * (op1 & 0xFFFF));
562 hi = (((op0 >> 16) & 0xFFFF) * ((op1 >> 16) & 0xFFFF));
564 /* We now need to add all of these results together, taking care
565 to propogate the carries from the additions: */
566 RdLo = Add32 (lo, (mid1 << 16), & carry);
568 RdLo = Add32 (RdLo, (mid2 << 16), & carry);
569 RdHi += (carry + ((mid1 >> 16) & 0xFFFF) + ((mid2 >> 16) & 0xFFFF) + hi);
573 /* Negate result if necessary. */
577 if (RdLo == 0xFFFFFFFF)
586 State.regs[ OP[1] ] = RdLo;
587 State.regs[ OP[2] >> 11 ] = RdHi;
597 unsigned long result;
599 result = load_mem (State.regs[30] + (OP[3] & 0x7f), 1);
601 /* start-sanitize-v850eq */
603 trace_input ("sld.bu", OP_LOAD16, 1);
605 State.regs[ OP[1] ] = result;
607 /* end-sanitize-v850eq */
608 trace_input ("sld.b", OP_LOAD16, 1);
610 State.regs[ OP[1] ] = SEXT8 (result);
611 /* start-sanitize-v850eq */
613 /* end-sanitize-v850eq */
615 trace_output (OP_LOAD16);
624 unsigned long result;
626 result = load_mem (State.regs[30] + ((OP[3] & 0x7f) << 1), 2);
628 /* start-sanitize-v850eq */
630 trace_input ("sld.hu", OP_LOAD16, 2);
632 State.regs[ OP[1] ] = result;
634 /* end-sanitize-v850eq */
635 trace_input ("sld.h", OP_LOAD16, 2);
637 State.regs[ OP[1] ] = SEXT16 (result);
638 /* start-sanitize-v850eq */
640 /* end-sanitize-v850eq */
642 trace_output (OP_LOAD16);
651 trace_input ("sld.w", OP_LOAD16, 4);
653 State.regs[ OP[1] ] = load_mem (State.regs[30] + ((OP[3] & 0x7f) << 1), 4);
655 trace_output (OP_LOAD16);
664 trace_input ("sst.b", OP_STORE16, 1);
666 store_mem (State.regs[30] + (OP[3] & 0x7f), 1, State.regs[ OP[1] ]);
668 trace_output (OP_STORE16);
677 trace_input ("sst.h", OP_STORE16, 2);
679 store_mem (State.regs[30] + ((OP[3] & 0x7f) << 1), 2, State.regs[ OP[1] ]);
681 trace_output (OP_STORE16);
690 trace_input ("sst.w", OP_STORE16, 4);
692 store_mem (State.regs[30] + ((OP[3] & 0x7e) << 1), 4, State.regs[ OP[1] ]);
694 trace_output (OP_STORE16);
705 trace_input ("ld.b", OP_LOAD32, 1);
707 adr = State.regs[ OP[0] ] + SEXT16 (OP[2]);
709 State.regs[ OP[1] ] = SEXT8 (load_mem (adr, 1));
711 trace_output (OP_LOAD32);
722 trace_input ("ld.h", OP_LOAD32, 2);
724 adr = State.regs[ OP[0] ] + SEXT16 (OP[2]);
727 State.regs[ OP[1] ] = SEXT16 (load_mem (adr, 2));
729 trace_output (OP_LOAD32);
740 trace_input ("ld.w", OP_LOAD32, 4);
742 adr = State.regs[ OP[0] ] + SEXT16 (OP[2] & ~1);
745 State.regs[ OP[1] ] = load_mem (adr, 4);
747 trace_output (OP_LOAD32);
756 trace_input ("st.b", OP_STORE32, 1);
758 store_mem (State.regs[ OP[0] ] + SEXT16 (OP[2]), 1, State.regs[ OP[1] ]);
760 trace_output (OP_STORE32);
771 trace_input ("st.h", OP_STORE32, 2);
773 adr = State.regs[ OP[0] ] + SEXT16 (OP[2]);
776 store_mem (adr, 2, State.regs[ OP[1] ]);
778 trace_output (OP_STORE32);
789 trace_input ("st.w", OP_STORE32, 4);
791 adr = State.regs[ OP[0] ] + SEXT16 (OP[2] & ~1);
794 store_mem (adr, 4, State.regs[ OP[1] ]);
796 trace_output (OP_STORE32);
804 trace_input ("Bcond", OP_COND_BR, 0);
805 trace_output (OP_COND_BR);
807 if (condition_met (code))
808 return SEXT9 (((OP[3] & 0x70) >> 3) | ((OP[3] & 0xf800) >> 7));
926 /* sld.bu disp4[ep], reg2 */
932 trace_input ("jmp", OP_REG, 0);
934 PC = State.regs[ OP[0] ];
936 trace_output (OP_REG);
938 return 0; /* Add nothing to the PC, we have already done it. */
940 /* start-sanitize-v850e */
943 unsigned long result;
945 result = load_mem (State.regs[30] + (OP[3] & 0xf), 1);
947 /* start-sanitize-v850eq */
949 trace_input ("sld.b", OP_LOAD16, 1);
951 State.regs[ OP[1] ] = SEXT8 (result);
953 /* end-sanitize-v850eq */
954 trace_input ("sld.bu", OP_LOAD16, 1);
956 State.regs[ OP[1] ] = result;
957 /* start-sanitize-v850eq */
959 /* end-sanitize-v850eq */
961 trace_output (OP_LOAD16);
965 /* end-sanitize-v850e */
968 /* jarl/jr disp22, reg */
972 trace_input ("jarl/jr", OP_JUMP, 0);
975 State.regs[ OP[1] ] = PC + 4;
977 trace_output (OP_JUMP);
979 return SEXT22 (((OP[3] & 0x3f) << 16) | OP[2]);
986 unsigned int op0, op1, result, z, s, cy, ov;
988 trace_input ("add", OP_REG_REG, 0);
990 /* Compute the result. */
992 op0 = State.regs[ OP[0] ];
993 op1 = State.regs[ OP[1] ];
997 /* Compute the condition codes. */
999 s = (result & 0x80000000);
1000 cy = (result < op0 || result < op1);
1001 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
1002 && (op0 & 0x80000000) != (result & 0x80000000));
1004 /* Store the result and condition codes. */
1005 State.regs[OP[1]] = result;
1006 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1007 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1008 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1009 trace_output (OP_REG_REG);
1014 /* add sign_extend(imm5), reg */
1018 unsigned int op0, op1, result, z, s, cy, ov;
1021 trace_input ("add", OP_IMM_REG, 0);
1023 /* Compute the result. */
1024 temp = SEXT5 (OP[0]);
1026 op1 = State.regs[OP[1]];
1029 /* Compute the condition codes. */
1031 s = (result & 0x80000000);
1032 cy = (result < op0 || result < op1);
1033 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
1034 && (op0 & 0x80000000) != (result & 0x80000000));
1036 /* Store the result and condition codes. */
1037 State.regs[OP[1]] = result;
1038 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1039 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1040 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1041 trace_output (OP_IMM_REG);
1046 /* addi sign_extend(imm16), reg, reg */
1050 unsigned int op0, op1, result, z, s, cy, ov;
1052 trace_input ("addi", OP_IMM_REG_REG, 0);
1054 /* Compute the result. */
1056 op0 = SEXT16 (OP[2]);
1057 op1 = State.regs[ OP[0] ];
1060 /* Compute the condition codes. */
1062 s = (result & 0x80000000);
1063 cy = (result < op0 || result < op1);
1064 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
1065 && (op0 & 0x80000000) != (result & 0x80000000));
1067 /* Store the result and condition codes. */
1068 State.regs[OP[1]] = result;
1069 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1070 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1071 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1072 trace_output (OP_IMM_REG_REG);
1077 /* sub reg1, reg2 */
1081 unsigned int op0, op1, result, z, s, cy, ov;
1083 trace_input ("sub", OP_REG_REG, 0);
1084 /* Compute the result. */
1085 op0 = State.regs[ OP[0] ];
1086 op1 = State.regs[ OP[1] ];
1089 /* Compute the condition codes. */
1091 s = (result & 0x80000000);
1093 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1094 && (op1 & 0x80000000) != (result & 0x80000000));
1096 /* Store the result and condition codes. */
1097 State.regs[OP[1]] = result;
1098 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1099 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1100 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1101 trace_output (OP_REG_REG);
1106 /* subr reg1, reg2 */
1110 unsigned int op0, op1, result, z, s, cy, ov;
1112 trace_input ("subr", OP_REG_REG, 0);
1113 /* Compute the result. */
1114 op0 = State.regs[ OP[0] ];
1115 op1 = State.regs[ OP[1] ];
1118 /* Compute the condition codes. */
1120 s = (result & 0x80000000);
1122 ov = ((op0 & 0x80000000) != (op1 & 0x80000000)
1123 && (op0 & 0x80000000) != (result & 0x80000000));
1125 /* Store the result and condition codes. */
1126 State.regs[OP[1]] = result;
1127 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1128 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1129 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1130 trace_output (OP_REG_REG);
1136 /* mulh reg1, reg2 */
1140 /* start-sanitize-v850e */
1143 trace_input ("sxh", OP_REG, 0);
1145 State.regs[ OP[0] ] = SEXT16 (State.regs[ OP[0] ]);
1147 trace_output (OP_REG);
1150 /* end-sanitize-v850e */
1152 trace_input ("mulh", OP_REG_REG, 0);
1154 State.regs[ OP[1] ] = (SEXT16 (State.regs[ OP[1] ]) * SEXT16 (State.regs[ OP[0] ]));
1156 trace_output (OP_REG_REG);
1162 /* mulh sign_extend(imm5), reg2 */
1166 trace_input ("mulh", OP_IMM_REG, 0);
1168 State.regs[ OP[1] ] = SEXT16 (State.regs[ OP[1] ]) * SEXT5 (OP[0]);
1170 trace_output (OP_IMM_REG);
1175 /* mulhi imm16, reg1, reg2 */
1184 trace_input ("mulhi", OP_IMM_REG_REG, 0);
1186 State.regs[ OP[1] ] = SEXT16 (State.regs[ OP[0] ]) * SEXT16 (OP[2]);
1188 trace_output (OP_IMM_REG_REG);
1194 /* divh reg1, reg2 */
1199 /* start-sanitize-v850e */
1204 trace_input ("switch", OP_REG, 0);
1206 adr = State.pc + 2 + (State.regs[ OP[0] ] << 1);
1207 State.pc = State.pc + 2 + (SEXT16 (load_mem (adr, 2)) << 1);
1209 trace_output (OP_REG);
1212 /* end-sanitize-v850e */
1214 unsigned int op0, op1, result, ov, s, z;
1217 trace_input ("divh", OP_REG_REG, 0);
1219 /* Compute the result. */
1220 temp = SEXT16 (State.regs[ OP[0] ]);
1222 op1 = State.regs[OP[1]];
1224 if (op0 == 0xffffffff && op1 == 0x80000000)
1226 result = 0x80000000;
1240 /* Compute the condition codes. */
1242 s = (result & 0x80000000);
1244 /* Store the result and condition codes. */
1245 State.regs[OP[1]] = result;
1246 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1247 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1248 | (ov ? PSW_OV : 0));
1249 trace_output (OP_REG_REG);
1259 unsigned int op0, op1, result, z, s, cy, ov;
1261 trace_input ("cmp", OP_REG_REG_CMP, 0);
1262 /* Compute the result. */
1263 op0 = State.regs[ OP[0] ];
1264 op1 = State.regs[ OP[1] ];
1267 /* Compute the condition codes. */
1269 s = (result & 0x80000000);
1271 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1272 && (op1 & 0x80000000) != (result & 0x80000000));
1274 /* Set condition codes. */
1275 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1276 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1277 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1278 trace_output (OP_REG_REG_CMP);
1283 /* cmp sign_extend(imm5), reg */
1287 unsigned int op0, op1, result, z, s, cy, ov;
1290 /* Compute the result. */
1291 trace_input ("cmp", OP_IMM_REG_CMP, 0);
1292 temp = SEXT5 (OP[0]);
1294 op1 = State.regs[OP[1]];
1297 /* Compute the condition codes. */
1299 s = (result & 0x80000000);
1301 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1302 && (op1 & 0x80000000) != (result & 0x80000000));
1304 /* Set condition codes. */
1305 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1306 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1307 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1308 trace_output (OP_IMM_REG_CMP);
1313 /* setf cccc,reg2 */
1317 trace_input ("setf", OP_EX1, 0);
1319 State.regs[ OP[1] ] = condition_met (OP[0]);
1321 trace_output (OP_EX1);
1327 /* satadd reg,reg */
1331 /* start-sanitize-v850e */
1334 trace_input ("zxh", OP_REG, 0);
1336 State.regs[ OP[0] ] &= 0xffff;
1338 trace_output (OP_REG);
1341 /* end-sanitize-v850e */
1343 unsigned int op0, op1, result, z, s, cy, ov, sat;
1345 trace_input ("satadd", OP_REG_REG, 0);
1346 /* Compute the result. */
1347 op0 = State.regs[ OP[0] ];
1348 op1 = State.regs[ OP[1] ];
1351 /* Compute the condition codes. */
1353 s = (result & 0x80000000);
1354 cy = (result < op0 || result < op1);
1355 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
1356 && (op0 & 0x80000000) != (result & 0x80000000));
1359 /* Store the result and condition codes. */
1360 State.regs[OP[1]] = result;
1361 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1362 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1363 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1364 | (sat ? PSW_SAT : 0));
1366 /* Handle saturated results. */
1368 State.regs[OP[1]] = 0x80000000;
1370 State.regs[OP[1]] = 0x7fffffff;
1371 trace_output (OP_REG_REG);
1377 /* satadd sign_extend(imm5), reg */
1381 unsigned int op0, op1, result, z, s, cy, ov, sat;
1385 trace_input ("satadd", OP_IMM_REG, 0);
1387 /* Compute the result. */
1388 temp = SEXT5 (OP[0]);
1390 op1 = State.regs[OP[1]];
1393 /* Compute the condition codes. */
1395 s = (result & 0x80000000);
1396 cy = (result < op0 || result < op1);
1397 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
1398 && (op0 & 0x80000000) != (result & 0x80000000));
1401 /* Store the result and condition codes. */
1402 State.regs[OP[1]] = result;
1403 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1404 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1405 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1406 | (sat ? PSW_SAT : 0));
1408 /* Handle saturated results. */
1410 State.regs[OP[1]] = 0x80000000;
1412 State.regs[OP[1]] = 0x7fffffff;
1413 trace_output (OP_IMM_REG);
1418 /* satsub reg1, reg2 */
1423 /* start-sanitize-v850e */
1426 trace_input ("sxb", OP_REG, 0);
1428 State.regs[ OP[0] ] = SEXT8 (State.regs[ OP[0] ]);
1430 trace_output (OP_REG);
1433 /* end-sanitize-v850e */
1435 unsigned int op0, op1, result, z, s, cy, ov, sat;
1437 trace_input ("satsub", OP_REG_REG, 0);
1439 /* Compute the result. */
1440 op0 = State.regs[ OP[0] ];
1441 op1 = State.regs[ OP[1] ];
1444 /* Compute the condition codes. */
1446 s = (result & 0x80000000);
1448 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1449 && (op1 & 0x80000000) != (result & 0x80000000));
1452 /* Store the result and condition codes. */
1453 State.regs[OP[1]] = result;
1454 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1455 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1456 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1457 | (sat ? PSW_SAT : 0));
1459 /* Handle saturated results. */
1461 State.regs[OP[1]] = 0x80000000;
1463 State.regs[OP[1]] = 0x7fffffff;
1464 trace_output (OP_REG_REG);
1470 /* satsubi sign_extend(imm16), reg */
1474 unsigned int op0, op1, result, z, s, cy, ov, sat;
1477 trace_input ("satsubi", OP_IMM_REG, 0);
1479 /* Compute the result. */
1480 temp = SEXT16 (OP[2]);
1482 op1 = State.regs[ OP[0] ];
1485 /* Compute the condition codes. */
1487 s = (result & 0x80000000);
1489 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1490 && (op1 & 0x80000000) != (result & 0x80000000));
1493 /* Store the result and condition codes. */
1494 State.regs[OP[1]] = result;
1495 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1496 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1497 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1498 | (sat ? PSW_SAT : 0));
1500 /* Handle saturated results. */
1502 State.regs[OP[1]] = 0x80000000;
1504 State.regs[OP[1]] = 0x7fffffff;
1505 trace_output (OP_IMM_REG);
1510 /* satsubr reg,reg */
1515 /* start-sanitize-v850e */
1518 trace_input ("zxb", OP_REG, 0);
1520 State.regs[ OP[0] ] &= 0xff;
1522 trace_output (OP_REG);
1525 /* end-sanitize-v850e */
1527 unsigned int op0, op1, result, z, s, cy, ov, sat;
1529 trace_input ("satsubr", OP_REG_REG, 0);
1531 /* Compute the result. */
1532 op0 = State.regs[ OP[0] ];
1533 op1 = State.regs[ OP[1] ];
1536 /* Compute the condition codes. */
1538 s = (result & 0x80000000);
1539 cy = (result < op0);
1540 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1541 && (op1 & 0x80000000) != (result & 0x80000000));
1544 /* Store the result and condition codes. */
1545 State.regs[OP[1]] = result;
1546 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1547 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1548 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1549 | (sat ? PSW_SAT : 0));
1551 /* Handle saturated results. */
1553 State.regs[OP[1]] = 0x80000000;
1555 State.regs[OP[1]] = 0x7fffffff;
1556 trace_output (OP_REG_REG);
1566 unsigned int op0, op1, result, z, s;
1568 trace_input ("tst", OP_REG_REG_CMP, 0);
1570 /* Compute the result. */
1571 op0 = State.regs[ OP[0] ];
1572 op1 = State.regs[ OP[1] ];
1575 /* Compute the condition codes. */
1577 s = (result & 0x80000000);
1579 /* Store the condition codes. */
1580 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1581 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1582 trace_output (OP_REG_REG_CMP);
1591 trace_input ("mov", OP_REG_REG_MOVE, 0);
1593 State.regs[ OP[1] ] = State.regs[ OP[0] ];
1595 trace_output (OP_REG_REG_MOVE);
1600 /* mov sign_extend(imm5), reg */
1605 /* start-sanitize-v850e */
1610 trace_input ("callt", OP_LOAD16, 1);
1615 adr = CTBP + ((OP[3] & 0x3f) << 1);
1617 PC = CTBP + load_mem (adr, 1);
1619 trace_output (OP_LOAD16);
1624 /* end-sanitize-v850e */
1626 int value = SEXT5 (OP[0]);
1628 trace_input ("mov", OP_IMM_REG_MOVE, 0);
1630 State.regs[ OP[1] ] = value;
1632 trace_output (OP_IMM_REG_MOVE);
1638 /* mov imm32, reg1 */
1639 /* movea sign_extend(imm16), reg, reg */
1643 /* start-sanitize-v850e */
1646 trace_input ("mov", OP_IMM32_REG, 4);
1648 State.regs[ OP[0] ] = load_mem (PC + 2, 4);
1650 trace_output (OP_IMM32_REG);
1655 /* end-sanitize-v850e */
1657 trace_input ("movea", OP_IMM_REG_REG, 0);
1659 State.regs[ OP[1] ] = State.regs[ OP[0] ] + SEXT16 (OP[2]);
1661 trace_output (OP_IMM_REG_REG);
1667 /* dispose imm5, list12 [, reg1] */
1668 /* movhi imm16, reg, reg */
1672 /* start-sanitize-v850e */
1678 trace_input ("dispose", OP_PUSHPOP1, 0);
1680 SP += (OP[3] & 0x3e) << 1;
1682 /* Load the registers with lower number registers being retrieved from higher addresses. */
1684 if ((OP[3] & (1 << type1_regs[ i ])))
1686 State.regs[ 20 + i ] = load_mem (SP, 4);
1690 if ((OP[3] & 0x1f0000) != 0)
1692 PC = State.regs[ (OP[3] >> 16) & 0x1f];
1696 trace_output (OP_PUSHPOP1);
1699 /* end-sanitize-v850e */
1701 trace_input ("movhi", OP_UIMM_REG_REG, 16);
1703 State.regs[ OP[1] ] = State.regs[ OP[0] ] + (OP[2] << 16);
1705 trace_output (OP_UIMM_REG_REG);
1711 /* sar zero_extend(imm5),reg1 */
1715 unsigned int op0, op1, result, z, s, cy;
1717 trace_input ("sar", OP_IMM_REG, 0);
1719 op1 = State.regs[ OP[1] ];
1720 result = (signed)op1 >> op0;
1722 /* Compute the condition codes. */
1724 s = (result & 0x80000000);
1725 cy = (op1 & (1 << (op0 - 1)));
1727 /* Store the result and condition codes. */
1728 State.regs[ OP[1] ] = result;
1729 PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1730 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1731 | (cy ? PSW_CY : 0));
1732 trace_output (OP_IMM_REG);
1737 /* sar reg1, reg2 */
1741 unsigned int op0, op1, result, z, s, cy;
1743 trace_input ("sar", OP_REG_REG, 0);
1745 op0 = State.regs[ OP[0] ] & 0x1f;
1746 op1 = State.regs[ OP[1] ];
1747 result = (signed)op1 >> op0;
1749 /* Compute the condition codes. */
1751 s = (result & 0x80000000);
1752 cy = (op1 & (1 << (op0 - 1)));
1754 /* Store the result and condition codes. */
1755 State.regs[OP[1]] = result;
1756 PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1757 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1758 | (cy ? PSW_CY : 0));
1759 trace_output (OP_REG_REG);
1764 /* shl zero_extend(imm5),reg1 */
1768 unsigned int op0, op1, result, z, s, cy;
1770 trace_input ("shl", OP_IMM_REG, 0);
1772 op1 = State.regs[ OP[1] ];
1773 result = op1 << op0;
1775 /* Compute the condition codes. */
1777 s = (result & 0x80000000);
1778 cy = (op1 & (1 << (32 - op0)));
1780 /* Store the result and condition codes. */
1781 State.regs[OP[1]] = result;
1782 PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1783 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1784 | (cy ? PSW_CY : 0));
1785 trace_output (OP_IMM_REG);
1790 /* shl reg1, reg2 */
1794 unsigned int op0, op1, result, z, s, cy;
1796 trace_input ("shl", OP_REG_REG, 0);
1797 op0 = State.regs[ OP[0] ] & 0x1f;
1798 op1 = State.regs[ OP[1] ];
1799 result = op1 << op0;
1801 /* Compute the condition codes. */
1803 s = (result & 0x80000000);
1804 cy = (op1 & (1 << (32 - op0)));
1806 /* Store the result and condition codes. */
1807 State.regs[OP[1]] = result;
1808 PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1809 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1810 | (cy ? PSW_CY : 0));
1811 trace_output (OP_REG_REG);
1816 /* shr zero_extend(imm5),reg1 */
1820 unsigned int op0, op1, result, z, s, cy;
1822 trace_input ("shr", OP_IMM_REG, 0);
1824 op1 = State.regs[ OP[1] ];
1825 result = op1 >> op0;
1827 /* Compute the condition codes. */
1829 s = (result & 0x80000000);
1830 cy = (op1 & (1 << (op0 - 1)));
1832 /* Store the result and condition codes. */
1833 State.regs[OP[1]] = result;
1834 PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1835 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1836 | (cy ? PSW_CY : 0));
1837 trace_output (OP_IMM_REG);
1842 /* shr reg1, reg2 */
1846 unsigned int op0, op1, result, z, s, cy;
1848 trace_input ("shr", OP_REG_REG, 0);
1849 op0 = State.regs[ OP[0] ] & 0x1f;
1850 op1 = State.regs[ OP[1] ];
1851 result = op1 >> op0;
1853 /* Compute the condition codes. */
1855 s = (result & 0x80000000);
1856 cy = (op1 & (1 << (op0 - 1)));
1858 /* Store the result and condition codes. */
1859 State.regs[OP[1]] = result;
1860 PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1861 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1862 | (cy ? PSW_CY : 0));
1863 trace_output (OP_REG_REG);
1872 unsigned int op0, op1, result, z, s;
1874 trace_input ("or", OP_REG_REG, 0);
1876 /* Compute the result. */
1877 op0 = State.regs[ OP[0] ];
1878 op1 = State.regs[ OP[1] ];
1881 /* Compute the condition codes. */
1883 s = (result & 0x80000000);
1885 /* Store the result and condition codes. */
1886 State.regs[OP[1]] = result;
1887 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1888 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1889 trace_output (OP_REG_REG);
1894 /* ori zero_extend(imm16), reg, reg */
1898 unsigned int op0, op1, result, z, s;
1900 trace_input ("ori", OP_UIMM_REG_REG, 0);
1902 op1 = State.regs[ OP[0] ];
1905 /* Compute the condition codes. */
1907 s = (result & 0x80000000);
1909 /* Store the result and condition codes. */
1910 State.regs[OP[1]] = result;
1911 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1912 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1913 trace_output (OP_UIMM_REG_REG);
1922 unsigned int op0, op1, result, z, s;
1924 trace_input ("and", OP_REG_REG, 0);
1926 /* Compute the result. */
1927 op0 = State.regs[ OP[0] ];
1928 op1 = State.regs[ OP[1] ];
1931 /* Compute the condition codes. */
1933 s = (result & 0x80000000);
1935 /* Store the result and condition codes. */
1936 State.regs[OP[1]] = result;
1937 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1938 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1939 trace_output (OP_REG_REG);
1944 /* andi zero_extend(imm16), reg, reg */
1948 unsigned int result, z;
1950 trace_input ("andi", OP_UIMM_REG_REG, 0);
1952 result = OP[2] & State.regs[ OP[0] ];
1954 /* Compute the condition codes. */
1957 /* Store the result and condition codes. */
1958 State.regs[ OP[1] ] = result;
1960 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1961 PSW |= (z ? PSW_Z : 0);
1963 trace_output (OP_UIMM_REG_REG);
1972 unsigned int op0, op1, result, z, s;
1974 trace_input ("xor", OP_REG_REG, 0);
1976 /* Compute the result. */
1977 op0 = State.regs[ OP[0] ];
1978 op1 = State.regs[ OP[1] ];
1981 /* Compute the condition codes. */
1983 s = (result & 0x80000000);
1985 /* Store the result and condition codes. */
1986 State.regs[OP[1]] = result;
1987 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1988 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1989 trace_output (OP_REG_REG);
1994 /* xori zero_extend(imm16), reg, reg */
1998 unsigned int op0, op1, result, z, s;
2000 trace_input ("xori", OP_UIMM_REG_REG, 0);
2002 op1 = State.regs[ OP[0] ];
2005 /* Compute the condition codes. */
2007 s = (result & 0x80000000);
2009 /* Store the result and condition codes. */
2010 State.regs[OP[1]] = result;
2011 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2012 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
2013 trace_output (OP_UIMM_REG_REG);
2018 /* not reg1, reg2 */
2022 unsigned int op0, result, z, s;
2024 trace_input ("not", OP_REG_REG_MOVE, 0);
2025 /* Compute the result. */
2026 op0 = State.regs[ OP[0] ];
2029 /* Compute the condition codes. */
2031 s = (result & 0x80000000);
2033 /* Store the result and condition codes. */
2034 State.regs[OP[1]] = result;
2035 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2036 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
2037 trace_output (OP_REG_REG_MOVE);
2046 unsigned int op0, op1, op2;
2049 trace_input ("set1", OP_BIT, 0);
2050 op0 = State.regs[ OP[0] ];
2052 temp = SEXT16 (OP[2]);
2054 temp = load_mem (op0 + op2, 1);
2056 if ((temp & (1 << op1)) == 0)
2059 store_mem (op0 + op2, 1, temp);
2060 trace_output (OP_BIT);
2069 unsigned int op0, op1, op2;
2072 trace_input ("not1", OP_BIT, 0);
2073 op0 = State.regs[ OP[0] ];
2075 temp = SEXT16 (OP[2]);
2077 temp = load_mem (op0 + op2, 1);
2079 if ((temp & (1 << op1)) == 0)
2082 store_mem (op0 + op2, 1, temp);
2083 trace_output (OP_BIT);
2092 unsigned int op0, op1, op2;
2095 trace_input ("clr1", OP_BIT, 0);
2096 op0 = State.regs[ OP[0] ];
2098 temp = SEXT16 (OP[2]);
2100 temp = load_mem (op0 + op2, 1);
2102 if ((temp & (1 << op1)) == 0)
2104 temp &= ~(1 << op1);
2105 store_mem (op0 + op2, 1, temp);
2106 trace_output (OP_BIT);
2115 unsigned int op0, op1, op2;
2118 trace_input ("tst1", OP_BIT, 0);
2119 op0 = State.regs[ OP[0] ];
2121 temp = SEXT16 (OP[2]);
2123 temp = load_mem (op0 + op2, 1);
2125 if ((temp & (1 << op1)) == 0)
2127 trace_output (OP_BIT);
2136 State.exception = SIGTRAP;
2144 trace_input ("di", OP_NONE, 0);
2146 trace_output (OP_NONE);
2155 trace_input ("ei", OP_NONE, 0);
2157 trace_output (OP_NONE);
2166 trace_input ("halt", OP_NONE, 0);
2167 /* FIXME this should put processor into a mode where NMI still handled */
2168 State.exception = SIGQUIT;
2169 trace_output (OP_NONE);
2178 trace_input ("reti", OP_NONE, 0);
2179 trace_output (OP_NONE);
2181 /* Restore for NMI if only NP on, otherwise is interrupt or exception. */
2182 if ((PSW & (PSW_NP | PSW_EP)) == PSW_NP)
2200 trace_input ("trap", OP_TRAP, 0);
2201 trace_output (OP_TRAP);
2203 /* Trap 31 is used for simulating OS I/O functions */
2207 int save_errno = errno;
2210 /* Registers passed to trap 0 */
2212 #define FUNC State.regs[6] /* function number, return value */
2213 #define PARM1 State.regs[7] /* optional parm 1 */
2214 #define PARM2 State.regs[8] /* optional parm 2 */
2215 #define PARM3 State.regs[9] /* optional parm 3 */
2217 /* Registers set by trap 0 */
2219 #define RETVAL State.regs[10] /* return value */
2220 #define RETERR State.regs[11] /* return error code */
2222 /* Turn a pointer in a register into a pointer into real memory. */
2224 #define MEMPTR(x) (map (x))
2229 #if !defined(__GO32__) && !defined(_WIN32)
2237 #if !defined(__GO32__) && !defined(_WIN32)
2240 RETVAL = execve (MEMPTR (PARM1), (char **) MEMPTR (PARM2),
2241 (char **)MEMPTR (PARM3));
2246 #if !defined(__GO32__) && !defined(_WIN32)
2249 RETVAL = execve (MEMPTR (PARM1), (char **) MEMPTR (PARM2), NULL);
2262 RETVAL = pipe (host_fd);
2263 SW (buf, host_fd[0]);
2264 buf += sizeof(uint16);
2265 SW (buf, host_fd[1]);
2277 RETVAL = wait (&status);
2286 RETVAL = sim_io_read (simulator, PARM1, MEMPTR (PARM2), PARM3);
2293 RETVAL = sim_io_write_stdout (simulator, MEMPTR (PARM2), PARM3);
2295 RETVAL = sim_io_write (simulator, PARM1, MEMPTR (PARM2), PARM3);
2301 RETVAL = sim_io_lseek (simulator, PARM1, PARM2, PARM3);
2307 RETVAL = sim_io_close (simulator, PARM1);
2313 RETVAL = sim_io_open (simulator, MEMPTR (PARM1), PARM2);
2319 if ((PARM1 & 0xffff0000) == 0xdead0000 && (PARM1 & 0xffff) != 0)
2320 State.exception = PARM1 & 0xffff; /* get signal encoded by kill */
2321 else if (PARM1 == 0xdead)
2322 State.exception = SIGABRT; /* old libraries */
2324 State.exception = SIG_V850_EXIT; /* PARM1 has exit status encoded */
2328 #if !defined(__GO32__) && !defined(_WIN32)
2330 case SYS_stat: /* added at hmsi */
2331 /* stat system call */
2333 struct stat host_stat;
2336 RETVAL = stat (MEMPTR (PARM1), &host_stat);
2340 /* Just wild-assed guesses. */
2341 store_mem (buf, 2, host_stat.st_dev);
2342 store_mem (buf + 2, 2, host_stat.st_ino);
2343 store_mem (buf + 4, 4, host_stat.st_mode);
2344 store_mem (buf + 8, 2, host_stat.st_nlink);
2345 store_mem (buf + 10, 2, host_stat.st_uid);
2346 store_mem (buf + 12, 2, host_stat.st_gid);
2347 store_mem (buf + 14, 2, host_stat.st_rdev);
2348 store_mem (buf + 16, 4, host_stat.st_size);
2349 store_mem (buf + 20, 4, host_stat.st_atime);
2350 store_mem (buf + 28, 4, host_stat.st_mtime);
2351 store_mem (buf + 36, 4, host_stat.st_ctime);
2357 #if !defined(__GO32__) && !defined(_WIN32)
2360 RETVAL = chown (MEMPTR (PARM1), PARM2, PARM3);
2368 RETVAL = chmod (MEMPTR (PARM1), PARM2);
2378 RETVAL = time (&now);
2379 store_mem (PARM1, 4, now);
2385 #if !defined(__GO32__) && !defined(_WIN32)
2390 RETVAL = times (&tms);
2391 store_mem (PARM1, 4, tms.tms_utime);
2392 store_mem (PARM1 + 4, 4, tms.tms_stime);
2393 store_mem (PARM1 + 8, 4, tms.tms_cutime);
2394 store_mem (PARM1 + 12, 4, tms.tms_cstime);
2400 #ifdef SYS_gettimeofday
2401 #if !defined(__GO32__) && !defined(_WIN32)
2402 case SYS_gettimeofday:
2406 RETVAL = gettimeofday (&t, &tz);
2407 store_mem (PARM1, 4, t.tv_sec);
2408 store_mem (PARM1 + 4, 4, t.tv_usec);
2409 store_mem (PARM2, 4, tz.tz_minuteswest);
2410 store_mem (PARM2 + 4, 4, tz.tz_dsttime);
2419 /* Cast the second argument to void *, to avoid type mismatch
2420 if a prototype is present. */
2421 RETVAL = utime (MEMPTR (PARM1), (void *) MEMPTR (PARM2));
2435 { /* Trap 0 -> 30 */
2440 ECR |= 0x40 + OP[0];
2441 /* Flag that we are now doing exception processing. */
2442 PSW |= PSW_EP | PSW_ID;
2443 PC = ((OP[0] < 0x10) ? 0x40 : 0x50) - 4;
2453 trace_input ("ldsr", OP_LDSR, 0);
2455 State.sregs[ OP[1] ] = State.regs[ OP[0] ];
2457 trace_output (OP_LDSR);
2466 trace_input ("stsr", OP_STSR, 0);
2468 State.regs[ OP[1] ] = State.sregs[ OP[0] ];
2470 trace_output (OP_STSR);
2475 /* tst1 reg2, [reg1] */
2481 trace_input ("tst1", OP_BIT_LOAD, 1);
2483 temp = load_mem (State.regs[ OP[0] ], 1);
2486 if ((temp & (1 << State.regs[ OP[1] & 0x7 ])) == 0)
2489 trace_output (OP_BIT_LOAD);
2494 /* mulu reg1, reg2, reg3 */
2498 trace_input ("mulu", OP_REG_REG_REG, 0);
2500 Multiply64 (false, State.regs[ OP[0] ]);
2502 trace_output (OP_REG_REG_REG);
2507 /* start-sanitize-v850e */
2509 #define BIT_CHANGE_OP( name, binop ) \
2511 unsigned int temp; \
2513 trace_input (name, OP_BIT_CHANGE, 0); \
2515 bit = 1 << State.regs[ OP[1] & 0x7 ]; \
2516 temp = load_mem (State.regs[ OP[0] ], 1); \
2519 if ((temp & bit) == 0) \
2523 store_mem (State.regs[ OP[0] ], 1, temp); \
2525 trace_output (OP_BIT_CHANGE); \
2529 /* clr1 reg2, [reg1] */
2533 BIT_CHANGE_OP ("clr1", &= ~ );
2536 /* not1 reg2, [reg1] */
2540 BIT_CHANGE_OP ("not1", ^= );
2547 BIT_CHANGE_OP ("set1", |= );
2554 trace_input ("sasf", OP_EX1, 0);
2556 State.regs[ OP[1] ] = (State.regs[ OP[1] ] << 1) | condition_met (OP[0]);
2558 trace_output (OP_EX1);
2562 /* end-sanitize-v850e */
2564 /* start-sanitize-v850eq */
2565 /* This function is courtesy of Sugimoto at NEC, via Seow Tan (Soew_Tan@el.nec.com) */
2570 unsigned long int als,
2571 unsigned long int sfi,
2572 unsigned long int * quotient_ptr,
2573 unsigned long int * remainder_ptr,
2574 boolean * overflow_ptr
2577 unsigned long ald = sfi >> (N - 1);
2578 unsigned long alo = als;
2583 unsigned int R1 = 1;
2584 unsigned int DBZ = (als == 0) ? 1 : 0;
2585 unsigned long alt = Q ? ~als : als;
2588 alo = ald + alt + Q;
2589 C = (((alt >> 31) & (ald >> 31))
2590 | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2593 R1 = (alo == 0) ? 0 : (R1 & Q);
2594 if ((S ^ (alo>>31)) && !C)
2599 sfi = (sfi << (32-N+1)) | Q;
2600 ald = (alo << 1) | (sfi >> 31);
2602 /* 2nd - N-1th Loop */
2603 for (i = 2; i < N; i++)
2605 alt = Q ? ~als : als;
2606 alo = ald + alt + Q;
2607 C = (((alt >> 31) & (ald >> 31))
2608 | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2611 R1 = (alo == 0) ? 0 : (R1 & Q);
2612 if ((S ^ (alo>>31)) && !C && !DBZ)
2617 sfi = (sfi << 1) | Q;
2618 ald = (alo << 1) | (sfi >> 31);
2622 alt = Q ? ~als : als;
2623 alo = ald + alt + Q;
2624 C = (((alt >> 31) & (ald >> 31))
2625 | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2628 R1 = (alo == 0) ? 0 : (R1 & Q);
2629 if ((S ^ (alo>>31)) && !C)
2634 * quotient_ptr = (sfi << 1) | Q;
2635 * remainder_ptr = Q ? alo : (alo + als);
2636 * overflow_ptr = DBZ | R1;
2639 /* This function is courtesy of Sugimoto at NEC, via Seow Tan (Soew_Tan@el.nec.com) */
2644 unsigned long int als,
2645 unsigned long int sfi,
2646 signed long int * quotient_ptr,
2647 signed long int * remainder_ptr,
2648 boolean * overflow_ptr
2651 unsigned long ald = (signed long) sfi >> (N - 1);
2652 unsigned long alo = als;
2653 unsigned int SS = als >> 31;
2654 unsigned int SD = sfi >> 31;
2655 unsigned int R1 = 1;
2657 unsigned int DBZ = als == 0 ? 1 : 0;
2658 unsigned int Q = ~(SS ^ SD) & 1;
2662 unsigned long alt = Q ? ~als : als;
2667 alo = ald + alt + Q;
2668 C = (((alt >> 31) & (ald >> 31))
2669 | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2671 R1 = (alo == 0) ? 0 : (R1 & (Q ^ (SS ^ SD)));
2673 sfi = (sfi << (32-N+1)) | Q;
2674 ald = (alo << 1) | (sfi >> 31);
2675 if ((alo >> 31) ^ (ald >> 31))
2680 /* 2nd - N-1th Loop */
2682 for (i = 2; i < N; i++)
2684 alt = Q ? ~als : als;
2685 alo = ald + alt + Q;
2686 C = (((alt >> 31) & (ald >> 31))
2687 | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2689 R1 = (alo == 0) ? 0 : (R1 & (Q ^ (SS ^ SD)));
2691 sfi = (sfi << 1) | Q;
2692 ald = (alo << 1) | (sfi >> 31);
2693 if ((alo >> 31) ^ (ald >> 31))
2700 alt = Q ? ~als : als;
2701 alo = ald + alt + Q;
2702 C = (((alt >> 31) & (ald >> 31))
2703 | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2705 R1 = (alo == 0) ? 0 : (R1 & (Q ^ (SS ^ SD)));
2706 sfi = (sfi << (32-N+1));
2712 alt = Q ? ~als : als;
2713 alo = ald + alt + Q;
2715 R1 = R1 & ((~alo >> 31) ^ SD);
2716 if ((alo != 0) && ((Q ^ (SS ^ SD)) ^ R1)) alo = ald;
2718 ald = sfi = (long) ((sfi >> 1) | (SS ^ SD) << 31) >> (32-N-1) | Q;
2720 ald = sfi = sfi | Q;
2722 OV = DBZ | ((alo == 0) ? 0 : R1);
2724 * remainder_ptr = alo;
2727 if (((alo != 0) && ((SS ^ SD) ^ R1))
2728 || ((alo == 0) && (SS ^ R1)))
2733 OV = (DBZ | R1) ? OV : ((alo >> 31) & (~ald >> 31));
2735 * quotient_ptr = alo;
2736 * overflow_ptr = OV;
2739 /* sdivun imm5, reg1, reg2, reg3 */
2743 unsigned long int quotient;
2744 unsigned long int remainder;
2745 unsigned long int divide_by;
2746 unsigned long int divide_this;
2747 boolean overflow = false;
2750 trace_input ("sdivun", OP_IMM_REG_REG_REG, 0);
2752 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2754 divide_by = State.regs[ OP[0] ];
2755 divide_this = State.regs[ OP[1] ] << imm5;
2757 divun (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2759 State.regs[ OP[1] ] = quotient;
2760 State.regs[ OP[2] >> 11 ] = remainder;
2762 /* Set condition codes. */
2763 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2765 if (overflow) PSW |= PSW_OV;
2766 if (quotient == 0) PSW |= PSW_Z;
2767 if (quotient & 0x80000000) PSW |= PSW_S;
2769 trace_output (OP_IMM_REG_REG_REG);
2774 /* sdivn imm5, reg1, reg2, reg3 */
2778 signed long int quotient;
2779 signed long int remainder;
2780 signed long int divide_by;
2781 signed long int divide_this;
2782 boolean overflow = false;
2785 trace_input ("sdivn", OP_IMM_REG_REG_REG, 0);
2787 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2789 divide_by = State.regs[ OP[0] ];
2790 divide_this = State.regs[ OP[1] ] << imm5;
2792 divn (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2794 State.regs[ OP[1] ] = quotient;
2795 State.regs[ OP[2] >> 11 ] = remainder;
2797 /* Set condition codes. */
2798 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2800 if (overflow) PSW |= PSW_OV;
2801 if (quotient == 0) PSW |= PSW_Z;
2802 if (quotient < 0) PSW |= PSW_S;
2804 trace_output (OP_IMM_REG_REG_REG);
2809 /* sdivhun imm5, reg1, reg2, reg3 */
2813 unsigned long int quotient;
2814 unsigned long int remainder;
2815 unsigned long int divide_by;
2816 unsigned long int divide_this;
2817 boolean overflow = false;
2820 trace_input ("sdivhun", OP_IMM_REG_REG_REG, 0);
2822 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2824 divide_by = State.regs[ OP[0] ] & 0xffff;
2825 divide_this = State.regs[ OP[1] ] << imm5;
2827 divun (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2829 State.regs[ OP[1] ] = quotient;
2830 State.regs[ OP[2] >> 11 ] = remainder;
2832 /* Set condition codes. */
2833 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2835 if (overflow) PSW |= PSW_OV;
2836 if (quotient == 0) PSW |= PSW_Z;
2837 if (quotient & 0x80000000) PSW |= PSW_S;
2839 trace_output (OP_IMM_REG_REG_REG);
2844 /* sdivhn imm5, reg1, reg2, reg3 */
2848 signed long int quotient;
2849 signed long int remainder;
2850 signed long int divide_by;
2851 signed long int divide_this;
2852 boolean overflow = false;
2855 trace_input ("sdivhn", OP_IMM_REG_REG_REG, 0);
2857 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2859 divide_by = SEXT16 (State.regs[ OP[0] ]);
2860 divide_this = State.regs[ OP[1] ] << imm5;
2862 divn (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2864 State.regs[ OP[1] ] = quotient;
2865 State.regs[ OP[2] >> 11 ] = remainder;
2867 /* Set condition codes. */
2868 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2870 if (overflow) PSW |= PSW_OV;
2871 if (quotient == 0) PSW |= PSW_Z;
2872 if (quotient < 0) PSW |= PSW_S;
2874 trace_output (OP_IMM_REG_REG_REG);
2878 /* end-sanitize-v850eq */
2880 /* start-sanitize-v850e */
2881 /* divu reg1, reg2, reg3 */
2885 unsigned long int quotient;
2886 unsigned long int remainder;
2887 unsigned long int divide_by;
2888 unsigned long int divide_this;
2889 boolean overflow = false;
2891 if ((OP[3] & 0x3c0000) == 0)
2893 trace_input ("divu", OP_REG_REG_REG, 0);
2895 /* Compute the result. */
2897 divide_by = State.regs[ OP[0] ];
2898 divide_this = State.regs[ OP[1] ];
2906 State.regs[ OP[1] ] = quotient = divide_this / divide_by;
2907 State.regs[ OP[2] >> 11 ] = remainder = divide_this % divide_by;
2909 /* Set condition codes. */
2910 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2912 if (overflow) PSW |= PSW_OV;
2913 if (quotient == 0) PSW |= PSW_Z;
2914 if (quotient & 0x80000000) PSW |= PSW_S;
2916 trace_output (OP_REG_REG_REG);
2918 /* start-sanitize-v850eq */
2919 /* divun imm5, reg1, reg2, reg3 */
2924 trace_input ("divun", OP_IMM_REG_REG_REG, 0);
2926 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2928 divide_by = State.regs[ OP[0] ];
2929 divide_this = State.regs[ OP[1] ];
2931 divun (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2933 State.regs[ OP[1] ] = quotient;
2934 State.regs[ OP[2] >> 11 ] = remainder;
2936 /* Set condition codes. */
2937 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2939 if (overflow) PSW |= PSW_OV;
2940 if (quotient == 0) PSW |= PSW_Z;
2941 if (quotient & 0x80000000) PSW |= PSW_S;
2943 trace_output (OP_IMM_REG_REG_REG);
2945 /* end-sanitize-v850eq */
2950 /* div reg1, reg2, reg3 */
2954 signed long int quotient;
2955 signed long int remainder;
2956 signed long int divide_by;
2957 signed long int divide_this;
2958 boolean overflow = false;
2960 if ((OP[3] & 0x3c0000) == 0)
2962 trace_input ("div", OP_REG_REG_REG, 0);
2964 /* Compute the result. */
2966 divide_by = State.regs[ OP[0] ];
2967 divide_this = State.regs[ OP[1] ];
2969 if (divide_by == 0 || (divide_by == -1 && divide_this == (1 << 31)))
2975 State.regs[ OP[1] ] = quotient = divide_this / divide_by;
2976 State.regs[ OP[2] >> 11 ] = remainder = divide_this % divide_by;
2978 /* Set condition codes. */
2979 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2981 if (overflow) PSW |= PSW_OV;
2982 if (quotient == 0) PSW |= PSW_Z;
2983 if (quotient < 0) PSW |= PSW_S;
2985 trace_output (OP_REG_REG_REG);
2987 /* start-sanitize-v850eq */
2988 /* divn imm5, reg1, reg2, reg3 */
2993 trace_input ("divn", OP_IMM_REG_REG_REG, 0);
2995 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2997 divide_by = State.regs[ OP[0] ];
2998 divide_this = State.regs[ OP[1] ];
3000 divn (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
3002 State.regs[ OP[1] ] = quotient;
3003 State.regs[ OP[2] >> 11 ] = remainder;
3005 /* Set condition codes. */
3006 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
3008 if (overflow) PSW |= PSW_OV;
3009 if (quotient == 0) PSW |= PSW_Z;
3010 if (quotient < 0) PSW |= PSW_S;
3012 trace_output (OP_IMM_REG_REG_REG);
3014 /* end-sanitize-v850eq */
3019 /* divhu reg1, reg2, reg3 */
3023 unsigned long int quotient;
3024 unsigned long int remainder;
3025 unsigned long int divide_by;
3026 unsigned long int divide_this;
3027 boolean overflow = false;
3029 if ((OP[3] & 0x3c0000) == 0)
3031 trace_input ("divhu", OP_REG_REG_REG, 0);
3033 /* Compute the result. */
3035 divide_by = State.regs[ OP[0] ] & 0xffff;
3036 divide_this = State.regs[ OP[1] ];
3044 State.regs[ OP[1] ] = quotient = divide_this / divide_by;
3045 State.regs[ OP[2] >> 11 ] = remainder = divide_this % divide_by;
3047 /* Set condition codes. */
3048 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
3050 if (overflow) PSW |= PSW_OV;
3051 if (quotient == 0) PSW |= PSW_Z;
3052 if (quotient & 0x80000000) PSW |= PSW_S;
3054 trace_output (OP_REG_REG_REG);
3056 /* start-sanitize-v850eq */
3057 /* divhun imm5, reg1, reg2, reg3 */
3062 trace_input ("divhun", OP_IMM_REG_REG_REG, 0);
3064 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
3066 divide_by = State.regs[ OP[0] ] & 0xffff;
3067 divide_this = State.regs[ OP[1] ];
3069 divun (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
3071 State.regs[ OP[1] ] = quotient;
3072 State.regs[ OP[2] >> 11 ] = remainder;
3074 /* Set condition codes. */
3075 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
3077 if (overflow) PSW |= PSW_OV;
3078 if (quotient == 0) PSW |= PSW_Z;
3079 if (quotient & 0x80000000) PSW |= PSW_S;
3081 trace_output (OP_IMM_REG_REG_REG);
3083 /* end-sanitize-v850eq */
3088 /* divh reg1, reg2, reg3 */
3092 signed long int quotient;
3093 signed long int remainder;
3094 signed long int divide_by;
3095 signed long int divide_this;
3096 boolean overflow = false;
3098 if ((OP[3] & 0x3c0000) == 0)
3100 trace_input ("divh", OP_REG_REG_REG, 0);
3102 /* Compute the result. */
3104 divide_by = State.regs[ OP[0] ];
3105 divide_this = SEXT16 (State.regs[ OP[1] ]);
3107 if (divide_by == 0 || (divide_by == -1 && divide_this == (1 << 31)))
3113 State.regs[ OP[1] ] = quotient = divide_this / divide_by;
3114 State.regs[ OP[2] >> 11 ] = remainder = divide_this % divide_by;
3116 /* Set condition codes. */
3117 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
3119 if (overflow) PSW |= PSW_OV;
3120 if (quotient == 0) PSW |= PSW_Z;
3121 if (quotient < 0) PSW |= PSW_S;
3123 trace_output (OP_REG_REG_REG);
3125 /* start-sanitize-v850eq */
3126 /* divhn imm5, reg1, reg2, reg3 */
3131 trace_input ("divhn", OP_IMM_REG_REG_REG, 0);
3133 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
3135 divide_by = SEXT16 (State.regs[ OP[0] ]);
3136 divide_this = State.regs[ OP[1] ];
3138 divn (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
3140 State.regs[ OP[1] ] = quotient;
3141 State.regs[ OP[2] >> 11 ] = remainder;
3143 /* Set condition codes. */
3144 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
3146 if (overflow) PSW |= PSW_OV;
3147 if (quotient == 0) PSW |= PSW_Z;
3148 if (quotient < 0) PSW |= PSW_S;
3150 trace_output (OP_IMM_REG_REG_REG);
3152 /* end-sanitize-v850eq */
3157 /* mulu imm9, reg2, reg3 */
3161 trace_input ("mulu", OP_IMM_REG_REG, 0);
3163 Multiply64 (false, (OP[3] & 0x1f) | ((OP[3] >> 13) & 0x1e0));
3165 trace_output (OP_IMM_REG_REG);
3170 /* mul imm9, reg2, reg3 */
3174 trace_input ("mul", OP_IMM_REG_REG, 0);
3176 Multiply64 (true, (OP[3] & 0x1f) | ((OP[3] >> 13) & 0x1e0));
3178 trace_output (OP_IMM_REG_REG);
3183 /* cmov imm5, reg2, reg3 */
3187 trace_input ("cmov", OP_IMM_REG_REG, 0);
3189 State.regs[ OP[2] >> 11 ] = condition_met (OP[0]) ? SEXT5( OP[0] ) : State.regs[ OP[1] ];
3191 trace_output (OP_IMM_REG_REG);
3201 trace_input ("ctret", OP_NONE, 0);
3206 trace_output (OP_NONE);
3215 unsigned long value;
3217 trace_input ("hsw", OP_REG_REG3, 0);
3219 value = State.regs[ OP[ 1 ] ];
3221 value |= (State.regs[ OP[ 1 ] ] << 16);
3223 State.regs[ OP[2] >> 11 ] = value;
3225 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
3227 if (value == 0) PSW |= PSW_Z;
3228 if (value & 0x80000000) PSW |= PSW_S;
3229 if (((value & 0xffff) == 0) || (value & 0xffff0000) == 0) PSW |= PSW_CY;
3231 trace_output (OP_REG_REG3);
3236 #define WORDHASNULLBYTE(x) (((x) - 0x01010101) & ~(x)&0x80808080)
3242 unsigned long value;
3244 trace_input ("bsw", OP_REG_REG3, 0);
3246 value = State.regs[ OP[ 1 ] ];
3248 value |= (State.regs[ OP[ 1 ] ] << 24);
3249 value |= ((State.regs[ OP[ 1 ] ] << 8) & 0x00ff0000);
3250 value |= ((State.regs[ OP[ 1 ] ] >> 8) & 0x0000ff00);
3252 State.regs[ OP[2] >> 11 ] = value;
3254 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
3256 if (value == 0) PSW |= PSW_Z;
3257 if (value & 0x80000000) PSW |= PSW_S;
3258 if (WORDHASNULLBYTE (value)) PSW |= PSW_CY;
3260 trace_output (OP_REG_REG3);
3269 unsigned long value;
3271 trace_input ("bsh", OP_REG_REG3, 0);
3273 value = State.regs[ OP[ 1 ] ];
3275 value |= ((State.regs[ OP[ 1 ] ] << 8) & 0xff00ff00);
3276 value |= ((State.regs[ OP[ 1 ] ] >> 8) & 0x000000ff);
3278 State.regs[ OP[2] >> 11 ] = value;
3280 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
3282 if (value == 0) PSW |= PSW_Z;
3283 if (value & 0x80000000) PSW |= PSW_S;
3284 if (((value & 0xff) == 0) || (value & 0x00ff) == 0) PSW |= PSW_CY;
3286 trace_output (OP_REG_REG3);
3300 trace_input ("pushml", OP_PUSHPOP3, 0);
3302 /* Store the registers with lower number registers being placed at higher addresses. */
3303 for (i = 0; i < 15; i++)
3304 if ((OP[3] & (1 << type3_regs[ i ])))
3307 store_mem (SP & ~ 3, 4, State.regs[ i + 1 ]);
3310 if (OP[3] & (1 << 3))
3314 store_mem (SP & ~ 3, 4, PSW);
3317 if (OP[3] & (1 << 19))
3321 if ((PSW & PSW_NP) && ((PSW & PSW_EP) == 0))
3323 store_mem ((SP + 4) & ~ 3, 4, FEPC);
3324 store_mem ( SP & ~ 3, 4, FEPSW);
3328 store_mem ((SP + 4) & ~ 3, 4, EIPC);
3329 store_mem ( SP & ~ 3, 4, EIPSW);
3333 trace_output (OP_PUSHPOP2);
3339 trace_input ("ld.hu", OP_LOAD32, 2);
3341 adr = State.regs[ OP[0] ] + SEXT16 (OP[2] & ~1);
3344 State.regs[ OP[1] ] = load_mem (adr, 2);
3346 trace_output (OP_LOAD32);
3352 /* prepare list12, imm5 */
3361 trace_input ("prepare", OP_PUSHPOP1, 0);
3363 /* Store the registers with lower number registers being placed at higher addresses. */
3364 for (i = 0; i < 12; i++)
3365 if ((OP[3] & (1 << type1_regs[ i ])))
3368 store_mem (SP, 4, State.regs[ 20 + i ]);
3371 SP -= (OP[3] & 0x3e) << 1;
3373 trace_output (OP_PUSHPOP1);
3379 trace_input ("ld.bu", OP_LOAD32, 1);
3381 adr = (State.regs[ OP[0] ]
3382 + (SEXT16 (OP[2] & ~1) | ((OP[3] >> 5) & 1)));
3384 State.regs[ OP[1] ] = load_mem (adr, 1);
3386 trace_output (OP_LOAD32);
3392 /* prepare list12, imm5, imm32 */
3398 trace_input ("prepare", OP_PUSHPOP1, 0);
3400 /* Store the registers with lower number registers being placed at higher addresses. */
3401 for (i = 0; i < 12; i++)
3402 if ((OP[3] & (1 << type1_regs[ i ])))
3405 store_mem (SP, 4, State.regs[ 20 + i ]);
3408 SP -= (OP[3] & 0x3e) << 1;
3410 EP = load_mem (PC + 4, 4);
3412 trace_output (OP_PUSHPOP1);
3417 /* prepare list12, imm5, imm16-32 */
3423 trace_input ("prepare", OP_PUSHPOP1, 0);
3425 /* Store the registers with lower number registers being placed at higher addresses. */
3426 for (i = 0; i < 12; i++)
3427 if ((OP[3] & (1 << type1_regs[ i ])))
3430 store_mem (SP, 4, State.regs[ 20 + i ]);
3433 SP -= (OP[3] & 0x3e) << 1;
3435 EP = load_mem (PC + 4, 2) << 16;
3437 trace_output (OP_PUSHPOP1);
3442 /* prepare list12, imm5, imm16 */
3448 trace_input ("prepare", OP_PUSHPOP1, 0);
3450 /* Store the registers with lower number registers being placed at higher addresses. */
3451 for (i = 0; i < 12; i++)
3452 if ((OP[3] & (1 << type1_regs[ i ])))
3455 store_mem (SP, 4, State.regs[ 20 + i ]);
3458 SP -= (OP[3] & 0x3e) << 1;
3460 EP = SEXT16 (load_mem (PC + 4, 2));
3462 trace_output (OP_PUSHPOP1);
3467 /* prepare list12, imm5, sp */
3473 trace_input ("prepare", OP_PUSHPOP1, 0);
3475 /* Store the registers with lower number registers being placed at higher addresses. */
3476 for (i = 0; i < 12; i++)
3477 if ((OP[3] & (1 << type1_regs[ i ])))
3480 store_mem (SP, 4, State.regs[ 20 + i ]);
3483 SP -= (OP[3] & 0x3e) << 1;
3487 trace_output (OP_PUSHPOP1);
3496 unsigned long result;
3498 result = load_mem (State.regs[30] + ((OP[3] & 0xf) << 1), 2);
3500 /* start-sanitize-v850eq */
3502 trace_input ("sld.h", OP_LOAD16, 2);
3504 State.regs[ OP[1] ] = SEXT16 (result);
3506 /* end-sanitize-v850eq */
3507 trace_input ("sld.hu", OP_LOAD16, 2);
3509 State.regs[ OP[1] ] = result;
3510 /* start-sanitize-v850eq */
3512 /* end-sanitize-v850eq */
3514 trace_output (OP_LOAD16);
3519 /* cmov reg1, reg2, reg3 */
3523 trace_input ("cmov", OP_REG_REG_REG, 0);
3525 State.regs[ OP[2] >> 11 ] = condition_met (OP[0]) ? State.regs[ OP[0] ] : State.regs[ OP[1] ];
3527 trace_output (OP_REG_REG_REG);
3532 /* mul reg1, reg2, reg3 */
3536 trace_input ("mul", OP_REG_REG_REG, 0);
3538 Multiply64 (true, State.regs[ OP[0] ]);
3540 trace_output (OP_REG_REG_REG);
3545 /* end-sanitize-v850e */
3546 /* start-sanitize-v850eq */
3554 trace_input ("popmh", OP_PUSHPOP2, 0);
3556 if (OP[3] & (1 << 19))
3558 if ((PSW & PSW_NP) && ((PSW & PSW_EP) == 0))
3560 FEPSW = load_mem ( SP & ~ 3, 4);
3561 FEPC = load_mem ((SP + 4) & ~ 3, 4);
3565 EIPSW = load_mem ( SP & ~ 3, 4);
3566 EIPC = load_mem ((SP + 4) & ~ 3, 4);
3572 /* Load the registers with lower number registers being retrieved from higher addresses. */
3574 if ((OP[3] & (1 << type2_regs[ i ])))
3576 State.regs[ i + 16 ] = load_mem (SP & ~ 3, 4);
3580 trace_output (OP_PUSHPOP2);
3591 trace_input ("popml", OP_PUSHPOP3, 0);
3593 if (OP[3] & (1 << 19))
3595 if ((PSW & PSW_NP) && ((PSW & PSW_EP) == 0))
3597 FEPSW = load_mem ( SP & ~ 3, 4);
3598 FEPC = load_mem ((SP + 4) & ~ 3, 4);
3602 EIPSW = load_mem ( SP & ~ 3, 4);
3603 EIPC = load_mem ((SP + 4) & ~ 3, 4);
3609 if (OP[3] & (1 << 3))
3611 PSW = load_mem (SP & ~ 3, 4);
3615 /* Load the registers with lower number registers being retrieved from higher addresses. */
3617 if ((OP[3] & (1 << type3_regs[ i ])))
3619 State.regs[ i + 1 ] = load_mem (SP & ~ 3, 4);
3623 trace_output (OP_PUSHPOP2);
3634 trace_input ("pushmh", OP_PUSHPOP2, 0);
3636 /* Store the registers with lower number registers being placed at higher addresses. */
3637 for (i = 0; i < 16; i++)
3638 if ((OP[3] & (1 << type2_regs[ i ])))
3641 store_mem (SP & ~ 3, 4, State.regs[ i + 16 ]);
3644 if (OP[3] & (1 << 19))
3648 if ((PSW & PSW_NP) && ((PSW & PSW_EP) == 0))
3650 store_mem ((SP + 4) & ~ 3, 4, FEPC);
3651 store_mem ( SP & ~ 3, 4, FEPSW);
3655 store_mem ((SP + 4) & ~ 3, 4, EIPC);
3656 store_mem ( SP & ~ 3, 4, EIPSW);
3660 trace_output (OP_PUSHPOP2);
3665 /* end-sanitize-v850eq */