18 /* FIXME - should be including a version of syscall.h that does not
19 pollute the name space */
20 #include "../../libgloss/v850/sys/syscall.h"
23 #include "libiberty.h"
26 #if !defined(__GO32__) && !defined(_WIN32)
28 #include <sys/times.h>
57 /* start-sanitize-v850e */
61 /* end-sanitize-v850e */
62 /* start-sanitize-v850eq */
67 /* end-sanitize-v850eq */
70 /* start-sanitize-v850e */
71 /* This is an array of the bit positions of registers r20 .. r31 in that order in a prepare/dispose instruction. */
72 static int type1_regs[12] = { 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 0, 21 };
73 /* end-sanitize-v850e */
74 /* start-sanitize-v850eq */
75 /* This is an array of the bit positions of registers r16 .. r31 in that order in a push/pop instruction. */
76 static int type2_regs[16] = { 3, 2, 1, 0, 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 20, 21};
77 /* This is an array of the bit positions of registers r1 .. r15 in that order in a push/pop instruction. */
78 static int type3_regs[15] = { 2, 1, 0, 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 20, 21};
79 /* end-sanitize-v850eq */
82 static void trace_input PARAMS ((char *name, enum op_types type, int size));
83 static void trace_output PARAMS ((enum op_types result));
84 static int init_text_p = 0;
85 static asection *text;
86 static bfd_vma text_start;
87 static bfd_vma text_end;
90 #ifndef SIZE_INSTRUCTION
91 #define SIZE_INSTRUCTION 6
95 #define SIZE_OPERANDS 16
99 #define SIZE_VALUES 11
102 #ifndef SIZE_LOCATION
103 #define SIZE_LOCATION 40
108 trace_input (name, type, size)
119 const char *filename;
120 const char *functionname;
121 unsigned int linenumber;
123 if ((v850_debug & DEBUG_TRACE) == 0)
130 for (s = prog_bfd->sections; s; s = s->next)
131 if (strcmp (bfd_get_section_name (prog_bfd, s), ".text") == 0)
134 text_start = bfd_get_section_vma (prog_bfd, s);
135 text_end = text_start + bfd_section_size (prog_bfd, s);
140 if (text && PC >= text_start && PC < text_end)
142 filename = (const char *)0;
143 functionname = (const char *)0;
145 if (bfd_find_nearest_line (prog_bfd, text, (struct symbol_cache_entry **)0, PC - text_start,
146 &filename, &functionname, &linenumber))
151 sprintf (p, "Line %5d ", linenumber);
157 sprintf (p, "Func %s ", functionname);
162 char *q = (char *) strrchr (filename, '/');
163 sprintf (p, "File %s ", (q) ? q+1 : filename);
172 (*v850_callback->printf_filtered) (v850_callback, "0x%.8x: %-*.*s %-*s",
174 SIZE_LOCATION, SIZE_LOCATION, buf,
175 SIZE_INSTRUCTION, name);
182 strcpy (buf, "unknown");
186 sprintf (buf, "%d", OP[0]);
190 sprintf (buf, "r%d", OP[0]);
195 case OP_REG_REG_MOVE:
196 sprintf (buf, "r%d,r%d", OP[0], OP[1]);
201 case OP_IMM_REG_MOVE:
202 sprintf (buf, "%d,r%d", OP[0], OP[1]);
206 sprintf (buf, "%d", SEXT9 (OP[0]));
210 sprintf (buf, "%d[r30],r%d", OP[1] * size, OP[0]);
214 sprintf (buf, "r%d,%d[r30]", OP[0], OP[1] * size);
218 sprintf (buf, "%d[r%d],r%d", SEXT16 (OP[2]) & ~0x1, OP[0], OP[1]);
222 sprintf (buf, "r%d,%d[r%d]", OP[1], SEXT16 (OP[2] & ~0x1), OP[0]);
226 sprintf (buf, "%d,r%d", SEXT22 (OP[0]), OP[1]);
230 sprintf (buf, "%d,r%d,r%d", SEXT16 (OP[0]), OP[1], OP[2]);
233 case OP_UIMM_REG_REG:
234 sprintf (buf, "%d,r%d,r%d", OP[0] & 0xffff, OP[1], OP[2]);
238 sprintf (buf, "%d,%d[r%d]", OP[1] & 0x7, SEXT16 (OP[2]), OP[0]);
244 default: cond = "?"; break;
245 case 0x0: cond = "v"; break;
246 case 0x1: cond = "c"; break;
247 case 0x2: cond = "z"; break;
248 case 0x3: cond = "nh"; break;
249 case 0x4: cond = "s"; break;
250 case 0x5: cond = "t"; break;
251 case 0x6: cond = "lt"; break;
252 case 0x7: cond = "le"; break;
253 case 0x8: cond = "nv"; break;
254 case 0x9: cond = "nc"; break;
255 case 0xa: cond = "nz"; break;
256 case 0xb: cond = "h"; break;
257 case 0xc: cond = "ns"; break;
258 case 0xd: cond = "sa"; break;
259 case 0xe: cond = "ge"; break;
260 case 0xf: cond = "gt"; break;
263 sprintf (buf, "%s,r%d", cond, OP[1]);
272 sprintf (buf, "r%d,s%d", OP[0], OP[1]);
276 for (i = 0; i < 12; i++)
277 if (OP[3] & (1 << type1_regs[i]))
278 strcat (buf, "r%d ", i + 20);
282 for (i = 0; i < 16; i++)
283 if (OP[3] & (1 << type2_regs[i]))
284 strcat (buf, "r%d ", i + 16);
285 if (OP[3] & (1 << 19))
286 strcat (buf, "F/EIPC, F/EIPSW " );
290 for (i = 0; i < 15; i++)
291 if (OP[3] & (1 << type3_regs[i]))
292 strcat (buf, "r%d ", i + 1);
293 if (OP[3] & (1 << 3))
294 strcat (buf, "PSW " );
295 if (OP[3] & (1 << 19))
296 strcat (buf, "F/EIPC, F/EIPSW " );
300 sprintf (buf, "r%d, [r%d]", OP[1], OP[0] );
304 if ((v850_debug & DEBUG_VALUES) == 0)
306 (*v850_callback->printf_filtered) (v850_callback, "%s\n", buf);
310 (*v850_callback->printf_filtered) (v850_callback, "%-*s", SIZE_OPERANDS, buf);
321 case OP_REG_REG_MOVE:
322 values[0] = State.regs[OP[0]];
329 values[0] = State.regs[OP[1]];
330 values[1] = State.regs[OP[0]];
336 values[0] = SEXT5 (OP[0]);
341 case OP_IMM_REG_MOVE:
342 values[0] = SEXT5 (OP[0]);
347 values[0] = State.pc;
348 values[1] = SEXT9 (OP[0]);
354 values[0] = OP[1] * size;
355 values[1] = State.regs[30];
360 values[0] = State.regs[OP[0]];
361 values[1] = OP[1] * size;
362 values[2] = State.regs[30];
367 values[0] = SEXT16 (OP[2]);
368 values[1] = State.regs[OP[0]];
373 values[0] = State.regs[OP[1]];
374 values[1] = SEXT16 (OP[2]);
375 values[2] = State.regs[OP[0]];
380 values[0] = SEXT22 (OP[0]);
381 values[1] = State.pc;
386 values[0] = SEXT16 (OP[0]) << size;
387 values[1] = State.regs[OP[1]];
391 case OP_UIMM_REG_REG:
392 values[0] = (OP[0] & 0xffff) << size;
393 values[1] = State.regs[OP[1]];
411 values[0] = State.regs[OP[0]];
416 values[0] = State.sregs[OP[1]];
420 for (i = 0; i < num_values; i++)
421 (*v850_callback->printf_filtered) (v850_callback, "%*s0x%.8lx", SIZE_VALUES - 10, "", values[i]);
424 (*v850_callback->printf_filtered) (v850_callback, "%*s", SIZE_VALUES, "");
429 trace_output (result)
430 enum op_types result;
432 if ((v850_debug & (DEBUG_TRACE | DEBUG_VALUES)) == (DEBUG_TRACE | DEBUG_VALUES))
452 (*v850_callback->printf_filtered) (v850_callback, " :: 0x%.8lx",
453 (unsigned long)State.regs[OP[0]]);
457 case OP_REG_REG_MOVE:
459 case OP_IMM_REG_MOVE:
462 (*v850_callback->printf_filtered) (v850_callback, " :: 0x%.8lx",
463 (unsigned long)State.regs[OP[1]]);
467 case OP_UIMM_REG_REG:
468 (*v850_callback->printf_filtered) (v850_callback, " :: 0x%.8lx",
469 (unsigned long)State.regs[OP[2]]);
474 (*v850_callback->printf_filtered) (v850_callback, " :: 0x%.8lx",
475 (unsigned long)State.regs[OP[1]]);
479 (*v850_callback->printf_filtered) (v850_callback, " :: 0x%.8lx",
480 (unsigned long)State.sregs[OP[1]]);
484 (*v850_callback->printf_filtered) (v850_callback, "\n");
489 #define trace_input(NAME, IN1, IN2)
490 #define trace_output(RESULT)
492 //#define trace_input(NAME, IN1, IN2) fprintf (stderr, NAME "\n" );
497 /* Returns 1 if the specific condition is met, returns 0 otherwise. */
499 condition_met (unsigned code)
501 unsigned int psw = PSW;
505 case 0x0: return ((psw & PSW_OV) != 0);
506 case 0x1: return ((psw & PSW_CY) != 0);
507 case 0x2: return ((psw & PSW_Z) != 0);
508 case 0x3: return ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) != 0);
509 case 0x4: return ((psw & PSW_S) != 0);
510 /*case 0x5: return 1;*/
511 case 0x6: return ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) != 0);
512 case 0x7: return (((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) || ((psw & PSW_Z) != 0)) != 0);
513 case 0x8: return ((psw & PSW_OV) == 0);
514 case 0x9: return ((psw & PSW_CY) == 0);
515 case 0xa: return ((psw & PSW_Z) == 0);
516 case 0xb: return ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) == 0);
517 case 0xc: return ((psw & PSW_S) == 0);
518 case 0xd: return ((psw & PSW_SAT) != 0);
519 case 0xe: return ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) == 0);
520 case 0xf: return (((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) || ((psw & PSW_Z) != 0)) == 0);
527 Add32 (unsigned long a1, unsigned long a2, int * carry)
529 unsigned long result = (a1 + a2);
531 * carry = (result < a1);
537 Multiply64 (boolean sign, unsigned long op0)
548 op1 = State.regs[ OP[1] ];
552 /* Compute sign of result and adjust operands if necessary. */
554 sign = (op0 ^ op1) & 0x80000000;
556 if (((signed long) op0) < 0)
559 if (((signed long) op1) < 0)
563 /* We can split the 32x32 into four 16x16 operations. This ensures
564 that we do not lose precision on 32bit only hosts: */
565 lo = ( (op0 & 0xFFFF) * (op1 & 0xFFFF));
566 mid1 = ( (op0 & 0xFFFF) * ((op1 >> 16) & 0xFFFF));
567 mid2 = (((op0 >> 16) & 0xFFFF) * (op1 & 0xFFFF));
568 hi = (((op0 >> 16) & 0xFFFF) * ((op1 >> 16) & 0xFFFF));
570 /* We now need to add all of these results together, taking care
571 to propogate the carries from the additions: */
572 RdLo = Add32 (lo, (mid1 << 16), & carry);
574 RdLo = Add32 (RdLo, (mid2 << 16), & carry);
575 RdHi += (carry + ((mid1 >> 16) & 0xFFFF) + ((mid2 >> 16) & 0xFFFF) + hi);
579 /* Negate result if necessary. */
583 if (RdLo == 0xFFFFFFFF)
592 State.regs[ OP[1] ] = RdLo;
593 State.regs[ OP[2] >> 11 ] = RdHi;
599 /* Read a null terminated string from memory, return in a buffer */
607 while (sim_core_read_1 (STATE_CPU (sd, 0),
608 PC, sim_core_read_map, addr + nr) != 0)
610 buf = NZALLOC (char, nr + 1);
611 sim_read (simulator, addr, buf, nr);
615 /* Read a null terminated argument vector from memory, return in a
618 fetch_argv (sd, addr)
624 char **buf = xmalloc (max_nr * sizeof (char*));
627 unsigned32 a = sim_core_read_4 (STATE_CPU (sd, 0),
628 PC, sim_core_read_map, addr + nr * 4);
630 buf[nr] = fetch_str (sd, a);
632 if (nr == max_nr - 1)
635 buf = xrealloc (buf, max_nr * sizeof (char*));
647 unsigned long result;
649 result = load_mem (State.regs[30] + (OP[3] & 0x7f), 1);
651 /* start-sanitize-v850eq */
653 trace_input ("sld.bu", OP_LOAD16, 1);
655 State.regs[ OP[1] ] = result;
657 /* end-sanitize-v850eq */
658 trace_input ("sld.b", OP_LOAD16, 1);
660 State.regs[ OP[1] ] = SEXT8 (result);
661 /* start-sanitize-v850eq */
663 /* end-sanitize-v850eq */
665 trace_output (OP_LOAD16);
674 unsigned long result;
676 result = load_mem (State.regs[30] + ((OP[3] & 0x7f) << 1), 2);
678 /* start-sanitize-v850eq */
680 trace_input ("sld.hu", OP_LOAD16, 2);
682 State.regs[ OP[1] ] = result;
684 /* end-sanitize-v850eq */
685 trace_input ("sld.h", OP_LOAD16, 2);
687 State.regs[ OP[1] ] = SEXT16 (result);
688 /* start-sanitize-v850eq */
690 /* end-sanitize-v850eq */
692 trace_output (OP_LOAD16);
701 trace_input ("sld.w", OP_LOAD16, 4);
703 State.regs[ OP[1] ] = load_mem (State.regs[30] + ((OP[3] & 0x7f) << 1), 4);
705 trace_output (OP_LOAD16);
714 trace_input ("sst.b", OP_STORE16, 1);
716 store_mem (State.regs[30] + (OP[3] & 0x7f), 1, State.regs[ OP[1] ]);
718 trace_output (OP_STORE16);
727 trace_input ("sst.h", OP_STORE16, 2);
729 store_mem (State.regs[30] + ((OP[3] & 0x7f) << 1), 2, State.regs[ OP[1] ]);
731 trace_output (OP_STORE16);
740 trace_input ("sst.w", OP_STORE16, 4);
742 store_mem (State.regs[30] + ((OP[3] & 0x7e) << 1), 4, State.regs[ OP[1] ]);
744 trace_output (OP_STORE16);
755 trace_input ("ld.b", OP_LOAD32, 1);
757 adr = State.regs[ OP[0] ] + SEXT16 (OP[2]);
759 State.regs[ OP[1] ] = SEXT8 (load_mem (adr, 1));
761 trace_output (OP_LOAD32);
772 trace_input ("ld.h", OP_LOAD32, 2);
774 adr = State.regs[ OP[0] ] + SEXT16 (OP[2]);
777 State.regs[ OP[1] ] = SEXT16 (load_mem (adr, 2));
779 trace_output (OP_LOAD32);
790 trace_input ("ld.w", OP_LOAD32, 4);
792 adr = State.regs[ OP[0] ] + SEXT16 (OP[2] & ~1);
795 State.regs[ OP[1] ] = load_mem (adr, 4);
797 trace_output (OP_LOAD32);
806 trace_input ("st.b", OP_STORE32, 1);
808 store_mem (State.regs[ OP[0] ] + SEXT16 (OP[2]), 1, State.regs[ OP[1] ]);
810 trace_output (OP_STORE32);
821 trace_input ("st.h", OP_STORE32, 2);
823 adr = State.regs[ OP[0] ] + SEXT16 (OP[2]);
826 store_mem (adr, 2, State.regs[ OP[1] ]);
828 trace_output (OP_STORE32);
839 trace_input ("st.w", OP_STORE32, 4);
841 adr = State.regs[ OP[0] ] + SEXT16 (OP[2] & ~1);
844 store_mem (adr, 4, State.regs[ OP[1] ]);
846 trace_output (OP_STORE32);
854 trace_input ("Bcond", OP_COND_BR, 0);
855 trace_output (OP_COND_BR);
857 if (condition_met (code))
858 return SEXT9 (((OP[3] & 0x70) >> 3) | ((OP[3] & 0xf800) >> 7));
976 /* sld.bu disp4[ep], reg2 */
982 trace_input ("jmp", OP_REG, 0);
984 PC = State.regs[ OP[0] ];
986 trace_output (OP_REG);
988 return 0; /* Add nothing to the PC, we have already done it. */
990 /* start-sanitize-v850e */
993 unsigned long result;
995 result = load_mem (State.regs[30] + (OP[3] & 0xf), 1);
997 /* start-sanitize-v850eq */
999 trace_input ("sld.b", OP_LOAD16, 1);
1001 State.regs[ OP[1] ] = SEXT8 (result);
1003 /* end-sanitize-v850eq */
1004 trace_input ("sld.bu", OP_LOAD16, 1);
1006 State.regs[ OP[1] ] = result;
1007 /* start-sanitize-v850eq */
1009 /* end-sanitize-v850eq */
1011 trace_output (OP_LOAD16);
1015 /* end-sanitize-v850e */
1018 /* jarl/jr disp22, reg */
1022 trace_input ("jarl/jr", OP_JUMP, 0);
1025 State.regs[ OP[1] ] = PC + 4;
1027 trace_output (OP_JUMP);
1029 return SEXT22 (((OP[3] & 0x3f) << 16) | OP[2]);
1036 unsigned int op0, op1, result, z, s, cy, ov;
1038 trace_input ("add", OP_REG_REG, 0);
1040 /* Compute the result. */
1042 op0 = State.regs[ OP[0] ];
1043 op1 = State.regs[ OP[1] ];
1047 /* Compute the condition codes. */
1049 s = (result & 0x80000000);
1050 cy = (result < op0 || result < op1);
1051 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
1052 && (op0 & 0x80000000) != (result & 0x80000000));
1054 /* Store the result and condition codes. */
1055 State.regs[OP[1]] = result;
1056 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1057 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1058 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1059 trace_output (OP_REG_REG);
1064 /* add sign_extend(imm5), reg */
1068 unsigned int op0, op1, result, z, s, cy, ov;
1071 trace_input ("add", OP_IMM_REG, 0);
1073 /* Compute the result. */
1074 temp = SEXT5 (OP[0]);
1076 op1 = State.regs[OP[1]];
1079 /* Compute the condition codes. */
1081 s = (result & 0x80000000);
1082 cy = (result < op0 || result < op1);
1083 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
1084 && (op0 & 0x80000000) != (result & 0x80000000));
1086 /* Store the result and condition codes. */
1087 State.regs[OP[1]] = result;
1088 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1089 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1090 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1091 trace_output (OP_IMM_REG);
1096 /* addi sign_extend(imm16), reg, reg */
1100 unsigned int op0, op1, result, z, s, cy, ov;
1102 trace_input ("addi", OP_IMM_REG_REG, 0);
1104 /* Compute the result. */
1106 op0 = SEXT16 (OP[2]);
1107 op1 = State.regs[ OP[0] ];
1110 /* Compute the condition codes. */
1112 s = (result & 0x80000000);
1113 cy = (result < op0 || result < op1);
1114 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
1115 && (op0 & 0x80000000) != (result & 0x80000000));
1117 /* Store the result and condition codes. */
1118 State.regs[OP[1]] = result;
1119 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1120 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1121 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1122 trace_output (OP_IMM_REG_REG);
1127 /* sub reg1, reg2 */
1131 unsigned int op0, op1, result, z, s, cy, ov;
1133 trace_input ("sub", OP_REG_REG, 0);
1134 /* Compute the result. */
1135 op0 = State.regs[ OP[0] ];
1136 op1 = State.regs[ OP[1] ];
1139 /* Compute the condition codes. */
1141 s = (result & 0x80000000);
1143 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1144 && (op1 & 0x80000000) != (result & 0x80000000));
1146 /* Store the result and condition codes. */
1147 State.regs[OP[1]] = result;
1148 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1149 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1150 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1151 trace_output (OP_REG_REG);
1156 /* subr reg1, reg2 */
1160 unsigned int op0, op1, result, z, s, cy, ov;
1162 trace_input ("subr", OP_REG_REG, 0);
1163 /* Compute the result. */
1164 op0 = State.regs[ OP[0] ];
1165 op1 = State.regs[ OP[1] ];
1168 /* Compute the condition codes. */
1170 s = (result & 0x80000000);
1172 ov = ((op0 & 0x80000000) != (op1 & 0x80000000)
1173 && (op0 & 0x80000000) != (result & 0x80000000));
1175 /* Store the result and condition codes. */
1176 State.regs[OP[1]] = result;
1177 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1178 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1179 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1180 trace_output (OP_REG_REG);
1186 /* mulh reg1, reg2 */
1190 /* start-sanitize-v850e */
1193 trace_input ("sxh", OP_REG, 0);
1195 State.regs[ OP[0] ] = SEXT16 (State.regs[ OP[0] ]);
1197 trace_output (OP_REG);
1200 /* end-sanitize-v850e */
1202 trace_input ("mulh", OP_REG_REG, 0);
1204 State.regs[ OP[1] ] = (SEXT16 (State.regs[ OP[1] ]) * SEXT16 (State.regs[ OP[0] ]));
1206 trace_output (OP_REG_REG);
1212 /* mulh sign_extend(imm5), reg2 */
1216 trace_input ("mulh", OP_IMM_REG, 0);
1218 State.regs[ OP[1] ] = SEXT16 (State.regs[ OP[1] ]) * SEXT5 (OP[0]);
1220 trace_output (OP_IMM_REG);
1225 /* mulhi imm16, reg1, reg2 */
1234 trace_input ("mulhi", OP_IMM_REG_REG, 0);
1236 State.regs[ OP[1] ] = SEXT16 (State.regs[ OP[0] ]) * SEXT16 (OP[2]);
1238 trace_output (OP_IMM_REG_REG);
1244 /* divh reg1, reg2 */
1249 /* start-sanitize-v850e */
1254 trace_input ("switch", OP_REG, 0);
1256 adr = State.pc + 2 + (State.regs[ OP[0] ] << 1);
1257 State.pc = State.pc + 2 + (SEXT16 (load_mem (adr, 2)) << 1);
1259 trace_output (OP_REG);
1262 /* end-sanitize-v850e */
1264 unsigned int op0, op1, result, ov, s, z;
1267 trace_input ("divh", OP_REG_REG, 0);
1269 /* Compute the result. */
1270 temp = SEXT16 (State.regs[ OP[0] ]);
1272 op1 = State.regs[OP[1]];
1274 if (op0 == 0xffffffff && op1 == 0x80000000)
1276 result = 0x80000000;
1290 /* Compute the condition codes. */
1292 s = (result & 0x80000000);
1294 /* Store the result and condition codes. */
1295 State.regs[OP[1]] = result;
1296 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1297 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1298 | (ov ? PSW_OV : 0));
1299 trace_output (OP_REG_REG);
1309 unsigned int op0, op1, result, z, s, cy, ov;
1311 trace_input ("cmp", OP_REG_REG_CMP, 0);
1312 /* Compute the result. */
1313 op0 = State.regs[ OP[0] ];
1314 op1 = State.regs[ OP[1] ];
1317 /* Compute the condition codes. */
1319 s = (result & 0x80000000);
1321 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1322 && (op1 & 0x80000000) != (result & 0x80000000));
1324 /* Set condition codes. */
1325 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1326 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1327 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1328 trace_output (OP_REG_REG_CMP);
1333 /* cmp sign_extend(imm5), reg */
1337 unsigned int op0, op1, result, z, s, cy, ov;
1340 /* Compute the result. */
1341 trace_input ("cmp", OP_IMM_REG_CMP, 0);
1342 temp = SEXT5 (OP[0]);
1344 op1 = State.regs[OP[1]];
1347 /* Compute the condition codes. */
1349 s = (result & 0x80000000);
1351 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1352 && (op1 & 0x80000000) != (result & 0x80000000));
1354 /* Set condition codes. */
1355 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1356 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1357 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1358 trace_output (OP_IMM_REG_CMP);
1363 /* setf cccc,reg2 */
1367 trace_input ("setf", OP_EX1, 0);
1369 State.regs[ OP[1] ] = condition_met (OP[0]);
1371 trace_output (OP_EX1);
1377 /* satadd reg,reg */
1381 /* start-sanitize-v850e */
1384 trace_input ("zxh", OP_REG, 0);
1386 State.regs[ OP[0] ] &= 0xffff;
1388 trace_output (OP_REG);
1391 /* end-sanitize-v850e */
1393 unsigned int op0, op1, result, z, s, cy, ov, sat;
1395 trace_input ("satadd", OP_REG_REG, 0);
1396 /* Compute the result. */
1397 op0 = State.regs[ OP[0] ];
1398 op1 = State.regs[ OP[1] ];
1401 /* Compute the condition codes. */
1403 s = (result & 0x80000000);
1404 cy = (result < op0 || result < op1);
1405 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
1406 && (op0 & 0x80000000) != (result & 0x80000000));
1409 /* Store the result and condition codes. */
1410 State.regs[OP[1]] = result;
1411 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1412 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1413 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1414 | (sat ? PSW_SAT : 0));
1416 /* Handle saturated results. */
1418 State.regs[OP[1]] = 0x80000000;
1420 State.regs[OP[1]] = 0x7fffffff;
1421 trace_output (OP_REG_REG);
1427 /* satadd sign_extend(imm5), reg */
1431 unsigned int op0, op1, result, z, s, cy, ov, sat;
1435 trace_input ("satadd", OP_IMM_REG, 0);
1437 /* Compute the result. */
1438 temp = SEXT5 (OP[0]);
1440 op1 = State.regs[OP[1]];
1443 /* Compute the condition codes. */
1445 s = (result & 0x80000000);
1446 cy = (result < op0 || result < op1);
1447 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
1448 && (op0 & 0x80000000) != (result & 0x80000000));
1451 /* Store the result and condition codes. */
1452 State.regs[OP[1]] = result;
1453 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1454 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1455 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1456 | (sat ? PSW_SAT : 0));
1458 /* Handle saturated results. */
1460 State.regs[OP[1]] = 0x80000000;
1462 State.regs[OP[1]] = 0x7fffffff;
1463 trace_output (OP_IMM_REG);
1468 /* satsub reg1, reg2 */
1473 /* start-sanitize-v850e */
1476 trace_input ("sxb", OP_REG, 0);
1478 State.regs[ OP[0] ] = SEXT8 (State.regs[ OP[0] ]);
1480 trace_output (OP_REG);
1483 /* end-sanitize-v850e */
1485 unsigned int op0, op1, result, z, s, cy, ov, sat;
1487 trace_input ("satsub", OP_REG_REG, 0);
1489 /* Compute the result. */
1490 op0 = State.regs[ OP[0] ];
1491 op1 = State.regs[ OP[1] ];
1494 /* Compute the condition codes. */
1496 s = (result & 0x80000000);
1498 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1499 && (op1 & 0x80000000) != (result & 0x80000000));
1502 /* Store the result and condition codes. */
1503 State.regs[OP[1]] = result;
1504 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1505 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1506 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1507 | (sat ? PSW_SAT : 0));
1509 /* Handle saturated results. */
1511 State.regs[OP[1]] = 0x80000000;
1513 State.regs[OP[1]] = 0x7fffffff;
1514 trace_output (OP_REG_REG);
1520 /* satsubi sign_extend(imm16), reg */
1524 unsigned int op0, op1, result, z, s, cy, ov, sat;
1527 trace_input ("satsubi", OP_IMM_REG, 0);
1529 /* Compute the result. */
1530 temp = SEXT16 (OP[2]);
1532 op1 = State.regs[ OP[0] ];
1535 /* Compute the condition codes. */
1537 s = (result & 0x80000000);
1539 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1540 && (op1 & 0x80000000) != (result & 0x80000000));
1543 /* Store the result and condition codes. */
1544 State.regs[OP[1]] = result;
1545 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1546 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1547 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1548 | (sat ? PSW_SAT : 0));
1550 /* Handle saturated results. */
1552 State.regs[OP[1]] = 0x80000000;
1554 State.regs[OP[1]] = 0x7fffffff;
1555 trace_output (OP_IMM_REG);
1560 /* satsubr reg,reg */
1565 /* start-sanitize-v850e */
1568 trace_input ("zxb", OP_REG, 0);
1570 State.regs[ OP[0] ] &= 0xff;
1572 trace_output (OP_REG);
1575 /* end-sanitize-v850e */
1577 unsigned int op0, op1, result, z, s, cy, ov, sat;
1579 trace_input ("satsubr", OP_REG_REG, 0);
1581 /* Compute the result. */
1582 op0 = State.regs[ OP[0] ];
1583 op1 = State.regs[ OP[1] ];
1586 /* Compute the condition codes. */
1588 s = (result & 0x80000000);
1589 cy = (result < op0);
1590 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
1591 && (op1 & 0x80000000) != (result & 0x80000000));
1594 /* Store the result and condition codes. */
1595 State.regs[OP[1]] = result;
1596 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
1597 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1598 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
1599 | (sat ? PSW_SAT : 0));
1601 /* Handle saturated results. */
1603 State.regs[OP[1]] = 0x80000000;
1605 State.regs[OP[1]] = 0x7fffffff;
1606 trace_output (OP_REG_REG);
1616 unsigned int op0, op1, result, z, s;
1618 trace_input ("tst", OP_REG_REG_CMP, 0);
1620 /* Compute the result. */
1621 op0 = State.regs[ OP[0] ];
1622 op1 = State.regs[ OP[1] ];
1625 /* Compute the condition codes. */
1627 s = (result & 0x80000000);
1629 /* Store the condition codes. */
1630 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1631 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1632 trace_output (OP_REG_REG_CMP);
1641 trace_input ("mov", OP_REG_REG_MOVE, 0);
1643 State.regs[ OP[1] ] = State.regs[ OP[0] ];
1645 trace_output (OP_REG_REG_MOVE);
1650 /* mov sign_extend(imm5), reg */
1655 /* start-sanitize-v850e */
1660 trace_input ("callt", OP_LOAD16, 1);
1665 adr = CTBP + ((OP[3] & 0x3f) << 1);
1667 PC = CTBP + load_mem (adr, 1);
1669 trace_output (OP_LOAD16);
1674 /* end-sanitize-v850e */
1676 int value = SEXT5 (OP[0]);
1678 trace_input ("mov", OP_IMM_REG_MOVE, 0);
1680 State.regs[ OP[1] ] = value;
1682 trace_output (OP_IMM_REG_MOVE);
1688 /* mov imm32, reg1 */
1689 /* movea sign_extend(imm16), reg, reg */
1693 /* start-sanitize-v850e */
1696 trace_input ("mov", OP_IMM32_REG, 4);
1698 State.regs[ OP[0] ] = load_mem (PC + 2, 4);
1700 trace_output (OP_IMM32_REG);
1705 /* end-sanitize-v850e */
1707 trace_input ("movea", OP_IMM_REG_REG, 0);
1709 State.regs[ OP[1] ] = State.regs[ OP[0] ] + SEXT16 (OP[2]);
1711 trace_output (OP_IMM_REG_REG);
1717 /* dispose imm5, list12 [, reg1] */
1718 /* movhi imm16, reg, reg */
1722 /* start-sanitize-v850e */
1728 trace_input ("dispose", OP_PUSHPOP1, 0);
1730 SP += (OP[3] & 0x3e) << 1;
1732 /* Load the registers with lower number registers being retrieved from higher addresses. */
1734 if ((OP[3] & (1 << type1_regs[ i ])))
1736 State.regs[ 20 + i ] = load_mem (SP, 4);
1740 if ((OP[3] & 0x1f0000) != 0)
1742 PC = State.regs[ (OP[3] >> 16) & 0x1f];
1746 trace_output (OP_PUSHPOP1);
1749 /* end-sanitize-v850e */
1751 trace_input ("movhi", OP_UIMM_REG_REG, 16);
1753 State.regs[ OP[1] ] = State.regs[ OP[0] ] + (OP[2] << 16);
1755 trace_output (OP_UIMM_REG_REG);
1761 /* sar zero_extend(imm5),reg1 */
1765 unsigned int op0, op1, result, z, s, cy;
1767 trace_input ("sar", OP_IMM_REG, 0);
1769 op1 = State.regs[ OP[1] ];
1770 result = (signed)op1 >> op0;
1772 /* Compute the condition codes. */
1774 s = (result & 0x80000000);
1775 cy = (op1 & (1 << (op0 - 1)));
1777 /* Store the result and condition codes. */
1778 State.regs[ OP[1] ] = result;
1779 PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1780 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1781 | (cy ? PSW_CY : 0));
1782 trace_output (OP_IMM_REG);
1787 /* sar reg1, reg2 */
1791 unsigned int op0, op1, result, z, s, cy;
1793 trace_input ("sar", OP_REG_REG, 0);
1795 op0 = State.regs[ OP[0] ] & 0x1f;
1796 op1 = State.regs[ OP[1] ];
1797 result = (signed)op1 >> op0;
1799 /* Compute the condition codes. */
1801 s = (result & 0x80000000);
1802 cy = (op1 & (1 << (op0 - 1)));
1804 /* Store the result and condition codes. */
1805 State.regs[OP[1]] = result;
1806 PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1807 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1808 | (cy ? PSW_CY : 0));
1809 trace_output (OP_REG_REG);
1814 /* shl zero_extend(imm5),reg1 */
1818 unsigned int op0, op1, result, z, s, cy;
1820 trace_input ("shl", OP_IMM_REG, 0);
1822 op1 = State.regs[ OP[1] ];
1823 result = op1 << op0;
1825 /* Compute the condition codes. */
1827 s = (result & 0x80000000);
1828 cy = (op1 & (1 << (32 - op0)));
1830 /* Store the result and condition codes. */
1831 State.regs[OP[1]] = result;
1832 PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1833 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1834 | (cy ? PSW_CY : 0));
1835 trace_output (OP_IMM_REG);
1840 /* shl reg1, reg2 */
1844 unsigned int op0, op1, result, z, s, cy;
1846 trace_input ("shl", OP_REG_REG, 0);
1847 op0 = State.regs[ OP[0] ] & 0x1f;
1848 op1 = State.regs[ OP[1] ];
1849 result = op1 << op0;
1851 /* Compute the condition codes. */
1853 s = (result & 0x80000000);
1854 cy = (op1 & (1 << (32 - op0)));
1856 /* Store the result and condition codes. */
1857 State.regs[OP[1]] = result;
1858 PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1859 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1860 | (cy ? PSW_CY : 0));
1861 trace_output (OP_REG_REG);
1866 /* shr zero_extend(imm5),reg1 */
1870 unsigned int op0, op1, result, z, s, cy;
1872 trace_input ("shr", OP_IMM_REG, 0);
1874 op1 = State.regs[ OP[1] ];
1875 result = op1 >> op0;
1877 /* Compute the condition codes. */
1879 s = (result & 0x80000000);
1880 cy = (op1 & (1 << (op0 - 1)));
1882 /* Store the result and condition codes. */
1883 State.regs[OP[1]] = result;
1884 PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1885 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1886 | (cy ? PSW_CY : 0));
1887 trace_output (OP_IMM_REG);
1892 /* shr reg1, reg2 */
1896 unsigned int op0, op1, result, z, s, cy;
1898 trace_input ("shr", OP_REG_REG, 0);
1899 op0 = State.regs[ OP[0] ] & 0x1f;
1900 op1 = State.regs[ OP[1] ];
1901 result = op1 >> op0;
1903 /* Compute the condition codes. */
1905 s = (result & 0x80000000);
1906 cy = (op1 & (1 << (op0 - 1)));
1908 /* Store the result and condition codes. */
1909 State.regs[OP[1]] = result;
1910 PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1911 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1912 | (cy ? PSW_CY : 0));
1913 trace_output (OP_REG_REG);
1922 unsigned int op0, op1, result, z, s;
1924 trace_input ("or", 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 /* ori zero_extend(imm16), reg, reg */
1948 unsigned int op0, op1, result, z, s;
1950 trace_input ("ori", OP_UIMM_REG_REG, 0);
1952 op1 = State.regs[ OP[0] ];
1955 /* Compute the condition codes. */
1957 s = (result & 0x80000000);
1959 /* Store the result and condition codes. */
1960 State.regs[OP[1]] = result;
1961 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
1962 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1963 trace_output (OP_UIMM_REG_REG);
1972 unsigned int op0, op1, result, z, s;
1974 trace_input ("and", 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 /* andi zero_extend(imm16), reg, reg */
1998 unsigned int result, z;
2000 trace_input ("andi", OP_UIMM_REG_REG, 0);
2002 result = OP[2] & State.regs[ OP[0] ];
2004 /* Compute the condition codes. */
2007 /* Store the result and condition codes. */
2008 State.regs[ OP[1] ] = result;
2010 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2011 PSW |= (z ? PSW_Z : 0);
2013 trace_output (OP_UIMM_REG_REG);
2022 unsigned int op0, op1, result, z, s;
2024 trace_input ("xor", OP_REG_REG, 0);
2026 /* Compute the result. */
2027 op0 = State.regs[ OP[0] ];
2028 op1 = State.regs[ OP[1] ];
2031 /* Compute the condition codes. */
2033 s = (result & 0x80000000);
2035 /* Store the result and condition codes. */
2036 State.regs[OP[1]] = result;
2037 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2038 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
2039 trace_output (OP_REG_REG);
2044 /* xori zero_extend(imm16), reg, reg */
2048 unsigned int op0, op1, result, z, s;
2050 trace_input ("xori", OP_UIMM_REG_REG, 0);
2052 op1 = State.regs[ OP[0] ];
2055 /* Compute the condition codes. */
2057 s = (result & 0x80000000);
2059 /* Store the result and condition codes. */
2060 State.regs[OP[1]] = result;
2061 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2062 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
2063 trace_output (OP_UIMM_REG_REG);
2068 /* not reg1, reg2 */
2072 unsigned int op0, result, z, s;
2074 trace_input ("not", OP_REG_REG_MOVE, 0);
2075 /* Compute the result. */
2076 op0 = State.regs[ OP[0] ];
2079 /* Compute the condition codes. */
2081 s = (result & 0x80000000);
2083 /* Store the result and condition codes. */
2084 State.regs[OP[1]] = result;
2085 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2086 PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
2087 trace_output (OP_REG_REG_MOVE);
2096 unsigned int op0, op1, op2;
2099 trace_input ("set1", OP_BIT, 0);
2100 op0 = State.regs[ OP[0] ];
2102 temp = SEXT16 (OP[2]);
2104 temp = load_mem (op0 + op2, 1);
2106 if ((temp & (1 << op1)) == 0)
2109 store_mem (op0 + op2, 1, temp);
2110 trace_output (OP_BIT);
2119 unsigned int op0, op1, op2;
2122 trace_input ("not1", OP_BIT, 0);
2123 op0 = State.regs[ OP[0] ];
2125 temp = SEXT16 (OP[2]);
2127 temp = load_mem (op0 + op2, 1);
2129 if ((temp & (1 << op1)) == 0)
2132 store_mem (op0 + op2, 1, temp);
2133 trace_output (OP_BIT);
2142 unsigned int op0, op1, op2;
2145 trace_input ("clr1", OP_BIT, 0);
2146 op0 = State.regs[ OP[0] ];
2148 temp = SEXT16 (OP[2]);
2150 temp = load_mem (op0 + op2, 1);
2152 if ((temp & (1 << op1)) == 0)
2154 temp &= ~(1 << op1);
2155 store_mem (op0 + op2, 1, temp);
2156 trace_output (OP_BIT);
2165 unsigned int op0, op1, op2;
2168 trace_input ("tst1", OP_BIT, 0);
2169 op0 = State.regs[ OP[0] ];
2171 temp = SEXT16 (OP[2]);
2173 temp = load_mem (op0 + op2, 1);
2175 if ((temp & (1 << op1)) == 0)
2177 trace_output (OP_BIT);
2186 State.exception = SIGTRAP;
2194 trace_input ("di", OP_NONE, 0);
2196 trace_output (OP_NONE);
2205 trace_input ("ei", OP_NONE, 0);
2207 trace_output (OP_NONE);
2216 trace_input ("halt", OP_NONE, 0);
2217 /* FIXME this should put processor into a mode where NMI still handled */
2218 State.exception = SIGQUIT;
2219 trace_output (OP_NONE);
2228 trace_input ("reti", OP_NONE, 0);
2229 trace_output (OP_NONE);
2231 /* Restore for NMI if only NP on, otherwise is interrupt or exception. */
2232 if ((PSW & (PSW_NP | PSW_EP)) == PSW_NP)
2250 trace_input ("trap", OP_TRAP, 0);
2251 trace_output (OP_TRAP);
2253 /* Trap 31 is used for simulating OS I/O functions */
2257 int save_errno = errno;
2260 /* Registers passed to trap 0 */
2262 #define FUNC State.regs[6] /* function number, return value */
2263 #define PARM1 State.regs[7] /* optional parm 1 */
2264 #define PARM2 State.regs[8] /* optional parm 2 */
2265 #define PARM3 State.regs[9] /* optional parm 3 */
2267 /* Registers set by trap 0 */
2269 #define RETVAL State.regs[10] /* return value */
2270 #define RETERR State.regs[11] /* return error code */
2272 /* Turn a pointer in a register into a pointer into real memory. */
2274 #define MEMPTR(x) (map (x))
2291 char *path = fetch_str (simulator, PARM1);
2292 char **argv = fetch_argv (simulator, PARM2);
2293 char **envp = fetch_argv (simulator, PARM3);
2294 RETVAL = execve (path, argv, envp);
2307 char *path = fetch_str (simulator, PARM1);
2308 char **argv = fetch_argv (simulator, PARM2);
2309 RETVAL = execv (path, argv);
2325 RETVAL = pipe (host_fd);
2326 SW (buf, host_fd[0]);
2327 buf += sizeof(uint16);
2328 SW (buf, host_fd[1]);
2340 RETVAL = wait (&status);
2350 char *buf = zalloc (PARM3);
2351 RETVAL = sim_io_read (simulator, PARM1, buf, PARM3);
2352 sim_write (simulator, PARM2, buf, PARM3);
2361 char *buf = zalloc (PARM3);
2362 sim_read (simulator, PARM2, buf, PARM3);
2364 RETVAL = sim_io_write_stdout (simulator, buf, PARM3);
2366 RETVAL = sim_io_write (simulator, PARM1, buf, PARM3);
2374 RETVAL = sim_io_lseek (simulator, PARM1, PARM2, PARM3);
2380 RETVAL = sim_io_close (simulator, PARM1);
2387 char *buf = fetch_str (simulator, PARM1);
2388 RETVAL = sim_io_open (simulator, buf, PARM2);
2396 if ((PARM1 & 0xffff0000) == 0xdead0000 && (PARM1 & 0xffff) != 0)
2397 State.exception = PARM1 & 0xffff; /* get signal encoded by kill */
2398 else if (PARM1 == 0xdead)
2399 State.exception = SIGABRT; /* old libraries */
2401 State.exception = SIG_V850_EXIT; /* PARM1 has exit status encoded */
2405 #if !defined(__GO32__) && !defined(_WIN32)
2407 case SYS_stat: /* added at hmsi */
2408 /* stat system call */
2410 struct stat host_stat;
2412 char *path = fetch_str (simulator, PARM1);
2414 RETVAL = stat (path, &host_stat);
2419 /* Just wild-assed guesses. */
2420 store_mem (buf, 2, host_stat.st_dev);
2421 store_mem (buf + 2, 2, host_stat.st_ino);
2422 store_mem (buf + 4, 4, host_stat.st_mode);
2423 store_mem (buf + 8, 2, host_stat.st_nlink);
2424 store_mem (buf + 10, 2, host_stat.st_uid);
2425 store_mem (buf + 12, 2, host_stat.st_gid);
2426 store_mem (buf + 14, 2, host_stat.st_rdev);
2427 store_mem (buf + 16, 4, host_stat.st_size);
2428 store_mem (buf + 20, 4, host_stat.st_atime);
2429 store_mem (buf + 28, 4, host_stat.st_mtime);
2430 store_mem (buf + 36, 4, host_stat.st_ctime);
2440 char *path = fetch_str (simulator, PARM1);
2441 RETVAL = chown (path, PARM2, PARM3);
2452 char *path = fetch_str (simulator, PARM1);
2453 RETVAL = chmod (path, PARM2);
2465 RETVAL = time (&now);
2466 store_mem (PARM1, 4, now);
2472 #if !defined(__GO32__) && !defined(_WIN32)
2477 RETVAL = times (&tms);
2478 store_mem (PARM1, 4, tms.tms_utime);
2479 store_mem (PARM1 + 4, 4, tms.tms_stime);
2480 store_mem (PARM1 + 8, 4, tms.tms_cutime);
2481 store_mem (PARM1 + 12, 4, tms.tms_cstime);
2487 #ifdef SYS_gettimeofday
2488 #if !defined(__GO32__) && !defined(_WIN32)
2489 case SYS_gettimeofday:
2493 RETVAL = gettimeofday (&t, &tz);
2494 store_mem (PARM1, 4, t.tv_sec);
2495 store_mem (PARM1 + 4, 4, t.tv_usec);
2496 store_mem (PARM2, 4, tz.tz_minuteswest);
2497 store_mem (PARM2 + 4, 4, tz.tz_dsttime);
2507 /* Cast the second argument to void *, to avoid type mismatch
2508 if a prototype is present. */
2509 sim_io_error (simulator, "Utime not supported");
2510 /* RETVAL = utime (path, (void *) MEMPTR (PARM2)); */
2525 { /* Trap 0 -> 30 */
2530 ECR |= 0x40 + OP[0];
2531 /* Flag that we are now doing exception processing. */
2532 PSW |= PSW_EP | PSW_ID;
2533 PC = ((OP[0] < 0x10) ? 0x40 : 0x50) - 4;
2543 trace_input ("ldsr", OP_LDSR, 0);
2545 State.sregs[ OP[1] ] = State.regs[ OP[0] ];
2547 trace_output (OP_LDSR);
2556 trace_input ("stsr", OP_STSR, 0);
2558 State.regs[ OP[1] ] = State.sregs[ OP[0] ];
2560 trace_output (OP_STSR);
2565 /* tst1 reg2, [reg1] */
2571 trace_input ("tst1", OP_BIT_LOAD, 1);
2573 temp = load_mem (State.regs[ OP[0] ], 1);
2576 if ((temp & (1 << State.regs[ OP[1] & 0x7 ])) == 0)
2579 trace_output (OP_BIT_LOAD);
2584 /* mulu reg1, reg2, reg3 */
2588 trace_input ("mulu", OP_REG_REG_REG, 0);
2590 Multiply64 (false, State.regs[ OP[0] ]);
2592 trace_output (OP_REG_REG_REG);
2597 /* start-sanitize-v850e */
2599 #define BIT_CHANGE_OP( name, binop ) \
2601 unsigned int temp; \
2603 trace_input (name, OP_BIT_CHANGE, 0); \
2605 bit = 1 << State.regs[ OP[1] & 0x7 ]; \
2606 temp = load_mem (State.regs[ OP[0] ], 1); \
2609 if ((temp & bit) == 0) \
2613 store_mem (State.regs[ OP[0] ], 1, temp); \
2615 trace_output (OP_BIT_CHANGE); \
2619 /* clr1 reg2, [reg1] */
2623 BIT_CHANGE_OP ("clr1", &= ~ );
2626 /* not1 reg2, [reg1] */
2630 BIT_CHANGE_OP ("not1", ^= );
2637 BIT_CHANGE_OP ("set1", |= );
2644 trace_input ("sasf", OP_EX1, 0);
2646 State.regs[ OP[1] ] = (State.regs[ OP[1] ] << 1) | condition_met (OP[0]);
2648 trace_output (OP_EX1);
2652 /* end-sanitize-v850e */
2654 /* start-sanitize-v850eq */
2655 /* This function is courtesy of Sugimoto at NEC, via Seow Tan (Soew_Tan@el.nec.com) */
2660 unsigned long int als,
2661 unsigned long int sfi,
2662 unsigned long int * quotient_ptr,
2663 unsigned long int * remainder_ptr,
2664 boolean * overflow_ptr
2667 unsigned long ald = sfi >> (N - 1);
2668 unsigned long alo = als;
2673 unsigned int R1 = 1;
2674 unsigned int DBZ = (als == 0) ? 1 : 0;
2675 unsigned long alt = Q ? ~als : als;
2678 alo = ald + alt + Q;
2679 C = (((alt >> 31) & (ald >> 31))
2680 | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2683 R1 = (alo == 0) ? 0 : (R1 & Q);
2684 if ((S ^ (alo>>31)) && !C)
2689 sfi = (sfi << (32-N+1)) | Q;
2690 ald = (alo << 1) | (sfi >> 31);
2692 /* 2nd - N-1th Loop */
2693 for (i = 2; i < N; i++)
2695 alt = Q ? ~als : als;
2696 alo = ald + alt + Q;
2697 C = (((alt >> 31) & (ald >> 31))
2698 | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2701 R1 = (alo == 0) ? 0 : (R1 & Q);
2702 if ((S ^ (alo>>31)) && !C && !DBZ)
2707 sfi = (sfi << 1) | Q;
2708 ald = (alo << 1) | (sfi >> 31);
2712 alt = Q ? ~als : als;
2713 alo = ald + alt + Q;
2714 C = (((alt >> 31) & (ald >> 31))
2715 | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2718 R1 = (alo == 0) ? 0 : (R1 & Q);
2719 if ((S ^ (alo>>31)) && !C)
2724 * quotient_ptr = (sfi << 1) | Q;
2725 * remainder_ptr = Q ? alo : (alo + als);
2726 * overflow_ptr = DBZ | R1;
2729 /* This function is courtesy of Sugimoto at NEC, via Seow Tan (Soew_Tan@el.nec.com) */
2734 unsigned long int als,
2735 unsigned long int sfi,
2736 signed long int * quotient_ptr,
2737 signed long int * remainder_ptr,
2738 boolean * overflow_ptr
2741 unsigned long ald = (signed long) sfi >> (N - 1);
2742 unsigned long alo = als;
2743 unsigned int SS = als >> 31;
2744 unsigned int SD = sfi >> 31;
2745 unsigned int R1 = 1;
2747 unsigned int DBZ = als == 0 ? 1 : 0;
2748 unsigned int Q = ~(SS ^ SD) & 1;
2752 unsigned long alt = Q ? ~als : als;
2757 alo = ald + alt + Q;
2758 C = (((alt >> 31) & (ald >> 31))
2759 | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2761 R1 = (alo == 0) ? 0 : (R1 & (Q ^ (SS ^ SD)));
2763 sfi = (sfi << (32-N+1)) | Q;
2764 ald = (alo << 1) | (sfi >> 31);
2765 if ((alo >> 31) ^ (ald >> 31))
2770 /* 2nd - N-1th Loop */
2772 for (i = 2; i < N; i++)
2774 alt = Q ? ~als : als;
2775 alo = ald + alt + Q;
2776 C = (((alt >> 31) & (ald >> 31))
2777 | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2779 R1 = (alo == 0) ? 0 : (R1 & (Q ^ (SS ^ SD)));
2781 sfi = (sfi << 1) | Q;
2782 ald = (alo << 1) | (sfi >> 31);
2783 if ((alo >> 31) ^ (ald >> 31))
2790 alt = Q ? ~als : als;
2791 alo = ald + alt + Q;
2792 C = (((alt >> 31) & (ald >> 31))
2793 | (((alt >> 31) ^ (ald >> 31)) & (~alo >> 31)));
2795 R1 = (alo == 0) ? 0 : (R1 & (Q ^ (SS ^ SD)));
2796 sfi = (sfi << (32-N+1));
2802 alt = Q ? ~als : als;
2803 alo = ald + alt + Q;
2805 R1 = R1 & ((~alo >> 31) ^ SD);
2806 if ((alo != 0) && ((Q ^ (SS ^ SD)) ^ R1)) alo = ald;
2808 ald = sfi = (long) ((sfi >> 1) | (SS ^ SD) << 31) >> (32-N-1) | Q;
2810 ald = sfi = sfi | Q;
2812 OV = DBZ | ((alo == 0) ? 0 : R1);
2814 * remainder_ptr = alo;
2817 if (((alo != 0) && ((SS ^ SD) ^ R1))
2818 || ((alo == 0) && (SS ^ R1)))
2823 OV = (DBZ | R1) ? OV : ((alo >> 31) & (~ald >> 31));
2825 * quotient_ptr = alo;
2826 * overflow_ptr = OV;
2829 /* sdivun imm5, reg1, reg2, reg3 */
2833 unsigned long int quotient;
2834 unsigned long int remainder;
2835 unsigned long int divide_by;
2836 unsigned long int divide_this;
2837 boolean overflow = false;
2840 trace_input ("sdivun", OP_IMM_REG_REG_REG, 0);
2842 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2844 divide_by = State.regs[ OP[0] ];
2845 divide_this = State.regs[ OP[1] ] << imm5;
2847 divun (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2849 State.regs[ OP[1] ] = quotient;
2850 State.regs[ OP[2] >> 11 ] = remainder;
2852 /* Set condition codes. */
2853 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2855 if (overflow) PSW |= PSW_OV;
2856 if (quotient == 0) PSW |= PSW_Z;
2857 if (quotient & 0x80000000) PSW |= PSW_S;
2859 trace_output (OP_IMM_REG_REG_REG);
2864 /* sdivn imm5, reg1, reg2, reg3 */
2868 signed long int quotient;
2869 signed long int remainder;
2870 signed long int divide_by;
2871 signed long int divide_this;
2872 boolean overflow = false;
2875 trace_input ("sdivn", OP_IMM_REG_REG_REG, 0);
2877 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2879 divide_by = State.regs[ OP[0] ];
2880 divide_this = State.regs[ OP[1] ] << imm5;
2882 divn (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2884 State.regs[ OP[1] ] = quotient;
2885 State.regs[ OP[2] >> 11 ] = remainder;
2887 /* Set condition codes. */
2888 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2890 if (overflow) PSW |= PSW_OV;
2891 if (quotient == 0) PSW |= PSW_Z;
2892 if (quotient < 0) PSW |= PSW_S;
2894 trace_output (OP_IMM_REG_REG_REG);
2899 /* sdivhun imm5, reg1, reg2, reg3 */
2903 unsigned long int quotient;
2904 unsigned long int remainder;
2905 unsigned long int divide_by;
2906 unsigned long int divide_this;
2907 boolean overflow = false;
2910 trace_input ("sdivhun", OP_IMM_REG_REG_REG, 0);
2912 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2914 divide_by = State.regs[ OP[0] ] & 0xffff;
2915 divide_this = State.regs[ OP[1] ] << imm5;
2917 divun (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2919 State.regs[ OP[1] ] = quotient;
2920 State.regs[ OP[2] >> 11 ] = remainder;
2922 /* Set condition codes. */
2923 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2925 if (overflow) PSW |= PSW_OV;
2926 if (quotient == 0) PSW |= PSW_Z;
2927 if (quotient & 0x80000000) PSW |= PSW_S;
2929 trace_output (OP_IMM_REG_REG_REG);
2934 /* sdivhn imm5, reg1, reg2, reg3 */
2938 signed long int quotient;
2939 signed long int remainder;
2940 signed long int divide_by;
2941 signed long int divide_this;
2942 boolean overflow = false;
2945 trace_input ("sdivhn", OP_IMM_REG_REG_REG, 0);
2947 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
2949 divide_by = SEXT16 (State.regs[ OP[0] ]);
2950 divide_this = State.regs[ OP[1] ] << imm5;
2952 divn (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
2954 State.regs[ OP[1] ] = quotient;
2955 State.regs[ OP[2] >> 11 ] = remainder;
2957 /* Set condition codes. */
2958 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
2960 if (overflow) PSW |= PSW_OV;
2961 if (quotient == 0) PSW |= PSW_Z;
2962 if (quotient < 0) PSW |= PSW_S;
2964 trace_output (OP_IMM_REG_REG_REG);
2968 /* end-sanitize-v850eq */
2970 /* start-sanitize-v850e */
2971 /* divu reg1, reg2, reg3 */
2975 unsigned long int quotient;
2976 unsigned long int remainder;
2977 unsigned long int divide_by;
2978 unsigned long int divide_this;
2979 boolean overflow = false;
2981 if ((OP[3] & 0x3c0000) == 0)
2983 trace_input ("divu", OP_REG_REG_REG, 0);
2985 /* Compute the result. */
2987 divide_by = State.regs[ OP[0] ];
2988 divide_this = State.regs[ OP[1] ];
2996 State.regs[ OP[1] ] = quotient = divide_this / divide_by;
2997 State.regs[ OP[2] >> 11 ] = remainder = divide_this % divide_by;
2999 /* Set condition codes. */
3000 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
3002 if (overflow) PSW |= PSW_OV;
3003 if (quotient == 0) PSW |= PSW_Z;
3004 if (quotient & 0x80000000) PSW |= PSW_S;
3006 trace_output (OP_REG_REG_REG);
3008 /* start-sanitize-v850eq */
3009 /* divun imm5, reg1, reg2, reg3 */
3014 trace_input ("divun", OP_IMM_REG_REG_REG, 0);
3016 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
3018 divide_by = State.regs[ OP[0] ];
3019 divide_this = State.regs[ OP[1] ];
3021 divun (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
3023 State.regs[ OP[1] ] = quotient;
3024 State.regs[ OP[2] >> 11 ] = remainder;
3026 /* Set condition codes. */
3027 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
3029 if (overflow) PSW |= PSW_OV;
3030 if (quotient == 0) PSW |= PSW_Z;
3031 if (quotient & 0x80000000) PSW |= PSW_S;
3033 trace_output (OP_IMM_REG_REG_REG);
3035 /* end-sanitize-v850eq */
3040 /* div reg1, reg2, reg3 */
3044 signed long int quotient;
3045 signed long int remainder;
3046 signed long int divide_by;
3047 signed long int divide_this;
3048 boolean overflow = false;
3050 if ((OP[3] & 0x3c0000) == 0)
3052 trace_input ("div", OP_REG_REG_REG, 0);
3054 /* Compute the result. */
3056 divide_by = State.regs[ OP[0] ];
3057 divide_this = State.regs[ OP[1] ];
3059 if (divide_by == 0 || (divide_by == -1 && divide_this == (1 << 31)))
3065 State.regs[ OP[1] ] = quotient = divide_this / divide_by;
3066 State.regs[ OP[2] >> 11 ] = remainder = divide_this % divide_by;
3068 /* Set condition codes. */
3069 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
3071 if (overflow) PSW |= PSW_OV;
3072 if (quotient == 0) PSW |= PSW_Z;
3073 if (quotient < 0) PSW |= PSW_S;
3075 trace_output (OP_REG_REG_REG);
3077 /* start-sanitize-v850eq */
3078 /* divn imm5, reg1, reg2, reg3 */
3083 trace_input ("divn", OP_IMM_REG_REG_REG, 0);
3085 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
3087 divide_by = State.regs[ OP[0] ];
3088 divide_this = State.regs[ OP[1] ];
3090 divn (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
3092 State.regs[ OP[1] ] = quotient;
3093 State.regs[ OP[2] >> 11 ] = remainder;
3095 /* Set condition codes. */
3096 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
3098 if (overflow) PSW |= PSW_OV;
3099 if (quotient == 0) PSW |= PSW_Z;
3100 if (quotient < 0) PSW |= PSW_S;
3102 trace_output (OP_IMM_REG_REG_REG);
3104 /* end-sanitize-v850eq */
3109 /* divhu reg1, reg2, reg3 */
3113 unsigned long int quotient;
3114 unsigned long int remainder;
3115 unsigned long int divide_by;
3116 unsigned long int divide_this;
3117 boolean overflow = false;
3119 if ((OP[3] & 0x3c0000) == 0)
3121 trace_input ("divhu", OP_REG_REG_REG, 0);
3123 /* Compute the result. */
3125 divide_by = State.regs[ OP[0] ] & 0xffff;
3126 divide_this = State.regs[ OP[1] ];
3134 State.regs[ OP[1] ] = quotient = divide_this / divide_by;
3135 State.regs[ OP[2] >> 11 ] = remainder = divide_this % divide_by;
3137 /* Set condition codes. */
3138 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
3140 if (overflow) PSW |= PSW_OV;
3141 if (quotient == 0) PSW |= PSW_Z;
3142 if (quotient & 0x80000000) PSW |= PSW_S;
3144 trace_output (OP_REG_REG_REG);
3146 /* start-sanitize-v850eq */
3147 /* divhun imm5, reg1, reg2, reg3 */
3152 trace_input ("divhun", OP_IMM_REG_REG_REG, 0);
3154 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
3156 divide_by = State.regs[ OP[0] ] & 0xffff;
3157 divide_this = State.regs[ OP[1] ];
3159 divun (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
3161 State.regs[ OP[1] ] = quotient;
3162 State.regs[ OP[2] >> 11 ] = remainder;
3164 /* Set condition codes. */
3165 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
3167 if (overflow) PSW |= PSW_OV;
3168 if (quotient == 0) PSW |= PSW_Z;
3169 if (quotient & 0x80000000) PSW |= PSW_S;
3171 trace_output (OP_IMM_REG_REG_REG);
3173 /* end-sanitize-v850eq */
3178 /* divh reg1, reg2, reg3 */
3182 signed long int quotient;
3183 signed long int remainder;
3184 signed long int divide_by;
3185 signed long int divide_this;
3186 boolean overflow = false;
3188 if ((OP[3] & 0x3c0000) == 0)
3190 trace_input ("divh", OP_REG_REG_REG, 0);
3192 /* Compute the result. */
3194 divide_by = State.regs[ OP[0] ];
3195 divide_this = SEXT16 (State.regs[ OP[1] ]);
3197 if (divide_by == 0 || (divide_by == -1 && divide_this == (1 << 31)))
3203 State.regs[ OP[1] ] = quotient = divide_this / divide_by;
3204 State.regs[ OP[2] >> 11 ] = remainder = divide_this % divide_by;
3206 /* Set condition codes. */
3207 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
3209 if (overflow) PSW |= PSW_OV;
3210 if (quotient == 0) PSW |= PSW_Z;
3211 if (quotient < 0) PSW |= PSW_S;
3213 trace_output (OP_REG_REG_REG);
3215 /* start-sanitize-v850eq */
3216 /* divhn imm5, reg1, reg2, reg3 */
3221 trace_input ("divhn", OP_IMM_REG_REG_REG, 0);
3223 imm5 = 32 - ((OP[3] & 0x3c0000) >> 17);
3225 divide_by = SEXT16 (State.regs[ OP[0] ]);
3226 divide_this = State.regs[ OP[1] ];
3228 divn (imm5, divide_by, divide_this, & quotient, & remainder, & overflow);
3230 State.regs[ OP[1] ] = quotient;
3231 State.regs[ OP[2] >> 11 ] = remainder;
3233 /* Set condition codes. */
3234 PSW &= ~(PSW_Z | PSW_S | PSW_OV);
3236 if (overflow) PSW |= PSW_OV;
3237 if (quotient == 0) PSW |= PSW_Z;
3238 if (quotient < 0) PSW |= PSW_S;
3240 trace_output (OP_IMM_REG_REG_REG);
3242 /* end-sanitize-v850eq */
3247 /* mulu imm9, reg2, reg3 */
3251 trace_input ("mulu", OP_IMM_REG_REG, 0);
3253 Multiply64 (false, (OP[3] & 0x1f) | ((OP[3] >> 13) & 0x1e0));
3255 trace_output (OP_IMM_REG_REG);
3260 /* mul imm9, reg2, reg3 */
3264 trace_input ("mul", OP_IMM_REG_REG, 0);
3266 Multiply64 (true, (OP[3] & 0x1f) | ((OP[3] >> 13) & 0x1e0));
3268 trace_output (OP_IMM_REG_REG);
3273 /* cmov imm5, reg2, reg3 */
3277 trace_input ("cmov", OP_IMM_REG_REG, 0);
3279 State.regs[ OP[2] >> 11 ] = condition_met (OP[0]) ? SEXT5( OP[0] ) : State.regs[ OP[1] ];
3281 trace_output (OP_IMM_REG_REG);
3291 trace_input ("ctret", OP_NONE, 0);
3296 trace_output (OP_NONE);
3305 unsigned long value;
3307 trace_input ("hsw", OP_REG_REG3, 0);
3309 value = State.regs[ OP[ 1 ] ];
3311 value |= (State.regs[ OP[ 1 ] ] << 16);
3313 State.regs[ OP[2] >> 11 ] = value;
3315 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
3317 if (value == 0) PSW |= PSW_Z;
3318 if (value & 0x80000000) PSW |= PSW_S;
3319 if (((value & 0xffff) == 0) || (value & 0xffff0000) == 0) PSW |= PSW_CY;
3321 trace_output (OP_REG_REG3);
3326 #define WORDHASNULLBYTE(x) (((x) - 0x01010101) & ~(x)&0x80808080)
3332 unsigned long value;
3334 trace_input ("bsw", OP_REG_REG3, 0);
3336 value = State.regs[ OP[ 1 ] ];
3338 value |= (State.regs[ OP[ 1 ] ] << 24);
3339 value |= ((State.regs[ OP[ 1 ] ] << 8) & 0x00ff0000);
3340 value |= ((State.regs[ OP[ 1 ] ] >> 8) & 0x0000ff00);
3342 State.regs[ OP[2] >> 11 ] = value;
3344 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
3346 if (value == 0) PSW |= PSW_Z;
3347 if (value & 0x80000000) PSW |= PSW_S;
3348 if (WORDHASNULLBYTE (value)) PSW |= PSW_CY;
3350 trace_output (OP_REG_REG3);
3359 unsigned long value;
3361 trace_input ("bsh", OP_REG_REG3, 0);
3363 value = State.regs[ OP[ 1 ] ];
3365 value |= ((State.regs[ OP[ 1 ] ] << 8) & 0xff00ff00);
3366 value |= ((State.regs[ OP[ 1 ] ] >> 8) & 0x000000ff);
3368 State.regs[ OP[2] >> 11 ] = value;
3370 PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
3372 if (value == 0) PSW |= PSW_Z;
3373 if (value & 0x80000000) PSW |= PSW_S;
3374 if (((value & 0xff) == 0) || (value & 0x00ff) == 0) PSW |= PSW_CY;
3376 trace_output (OP_REG_REG3);
3390 trace_input ("pushml", OP_PUSHPOP3, 0);
3392 /* Store the registers with lower number registers being placed at higher addresses. */
3393 for (i = 0; i < 15; i++)
3394 if ((OP[3] & (1 << type3_regs[ i ])))
3397 store_mem (SP & ~ 3, 4, State.regs[ i + 1 ]);
3400 if (OP[3] & (1 << 3))
3404 store_mem (SP & ~ 3, 4, PSW);
3407 if (OP[3] & (1 << 19))
3411 if ((PSW & PSW_NP) && ((PSW & PSW_EP) == 0))
3413 store_mem ((SP + 4) & ~ 3, 4, FEPC);
3414 store_mem ( SP & ~ 3, 4, FEPSW);
3418 store_mem ((SP + 4) & ~ 3, 4, EIPC);
3419 store_mem ( SP & ~ 3, 4, EIPSW);
3423 trace_output (OP_PUSHPOP2);
3429 trace_input ("ld.hu", OP_LOAD32, 2);
3431 adr = State.regs[ OP[0] ] + SEXT16 (OP[2] & ~1);
3434 State.regs[ OP[1] ] = load_mem (adr, 2);
3436 trace_output (OP_LOAD32);
3442 /* prepare list12, imm5 */
3451 trace_input ("prepare", OP_PUSHPOP1, 0);
3453 /* Store the registers with lower number registers being placed at higher addresses. */
3454 for (i = 0; i < 12; i++)
3455 if ((OP[3] & (1 << type1_regs[ i ])))
3458 store_mem (SP, 4, State.regs[ 20 + i ]);
3461 SP -= (OP[3] & 0x3e) << 1;
3463 trace_output (OP_PUSHPOP1);
3469 trace_input ("ld.bu", OP_LOAD32, 1);
3471 adr = (State.regs[ OP[0] ]
3472 + (SEXT16 (OP[2] & ~1) | ((OP[3] >> 5) & 1)));
3474 State.regs[ OP[1] ] = load_mem (adr, 1);
3476 trace_output (OP_LOAD32);
3482 /* prepare list12, imm5, imm32 */
3488 trace_input ("prepare", OP_PUSHPOP1, 0);
3490 /* Store the registers with lower number registers being placed at higher addresses. */
3491 for (i = 0; i < 12; i++)
3492 if ((OP[3] & (1 << type1_regs[ i ])))
3495 store_mem (SP, 4, State.regs[ 20 + i ]);
3498 SP -= (OP[3] & 0x3e) << 1;
3500 EP = load_mem (PC + 4, 4);
3502 trace_output (OP_PUSHPOP1);
3507 /* prepare list12, imm5, imm16-32 */
3513 trace_input ("prepare", OP_PUSHPOP1, 0);
3515 /* Store the registers with lower number registers being placed at higher addresses. */
3516 for (i = 0; i < 12; i++)
3517 if ((OP[3] & (1 << type1_regs[ i ])))
3520 store_mem (SP, 4, State.regs[ 20 + i ]);
3523 SP -= (OP[3] & 0x3e) << 1;
3525 EP = load_mem (PC + 4, 2) << 16;
3527 trace_output (OP_PUSHPOP1);
3532 /* prepare list12, imm5, imm16 */
3538 trace_input ("prepare", OP_PUSHPOP1, 0);
3540 /* Store the registers with lower number registers being placed at higher addresses. */
3541 for (i = 0; i < 12; i++)
3542 if ((OP[3] & (1 << type1_regs[ i ])))
3545 store_mem (SP, 4, State.regs[ 20 + i ]);
3548 SP -= (OP[3] & 0x3e) << 1;
3550 EP = SEXT16 (load_mem (PC + 4, 2));
3552 trace_output (OP_PUSHPOP1);
3557 /* prepare list12, imm5, sp */
3563 trace_input ("prepare", OP_PUSHPOP1, 0);
3565 /* Store the registers with lower number registers being placed at higher addresses. */
3566 for (i = 0; i < 12; i++)
3567 if ((OP[3] & (1 << type1_regs[ i ])))
3570 store_mem (SP, 4, State.regs[ 20 + i ]);
3573 SP -= (OP[3] & 0x3e) << 1;
3577 trace_output (OP_PUSHPOP1);
3586 unsigned long result;
3588 result = load_mem (State.regs[30] + ((OP[3] & 0xf) << 1), 2);
3590 /* start-sanitize-v850eq */
3592 trace_input ("sld.h", OP_LOAD16, 2);
3594 State.regs[ OP[1] ] = SEXT16 (result);
3596 /* end-sanitize-v850eq */
3597 trace_input ("sld.hu", OP_LOAD16, 2);
3599 State.regs[ OP[1] ] = result;
3600 /* start-sanitize-v850eq */
3602 /* end-sanitize-v850eq */
3604 trace_output (OP_LOAD16);
3609 /* cmov reg1, reg2, reg3 */
3613 trace_input ("cmov", OP_REG_REG_REG, 0);
3615 State.regs[ OP[2] >> 11 ] = condition_met (OP[0]) ? State.regs[ OP[0] ] : State.regs[ OP[1] ];
3617 trace_output (OP_REG_REG_REG);
3622 /* mul reg1, reg2, reg3 */
3626 trace_input ("mul", OP_REG_REG_REG, 0);
3628 Multiply64 (true, State.regs[ OP[0] ]);
3630 trace_output (OP_REG_REG_REG);
3635 /* end-sanitize-v850e */
3636 /* start-sanitize-v850eq */
3644 trace_input ("popmh", OP_PUSHPOP2, 0);
3646 if (OP[3] & (1 << 19))
3648 if ((PSW & PSW_NP) && ((PSW & PSW_EP) == 0))
3650 FEPSW = load_mem ( SP & ~ 3, 4);
3651 FEPC = load_mem ((SP + 4) & ~ 3, 4);
3655 EIPSW = load_mem ( SP & ~ 3, 4);
3656 EIPC = load_mem ((SP + 4) & ~ 3, 4);
3662 /* Load the registers with lower number registers being retrieved from higher addresses. */
3664 if ((OP[3] & (1 << type2_regs[ i ])))
3666 State.regs[ i + 16 ] = load_mem (SP & ~ 3, 4);
3670 trace_output (OP_PUSHPOP2);
3681 trace_input ("popml", OP_PUSHPOP3, 0);
3683 if (OP[3] & (1 << 19))
3685 if ((PSW & PSW_NP) && ((PSW & PSW_EP) == 0))
3687 FEPSW = load_mem ( SP & ~ 3, 4);
3688 FEPC = load_mem ((SP + 4) & ~ 3, 4);
3692 EIPSW = load_mem ( SP & ~ 3, 4);
3693 EIPC = load_mem ((SP + 4) & ~ 3, 4);
3699 if (OP[3] & (1 << 3))
3701 PSW = load_mem (SP & ~ 3, 4);
3705 /* Load the registers with lower number registers being retrieved from higher addresses. */
3707 if ((OP[3] & (1 << type3_regs[ i ])))
3709 State.regs[ i + 1 ] = load_mem (SP & ~ 3, 4);
3713 trace_output (OP_PUSHPOP2);
3724 trace_input ("pushmh", OP_PUSHPOP2, 0);
3726 /* Store the registers with lower number registers being placed at higher addresses. */
3727 for (i = 0; i < 16; i++)
3728 if ((OP[3] & (1 << type2_regs[ i ])))
3731 store_mem (SP & ~ 3, 4, State.regs[ i + 16 ]);
3734 if (OP[3] & (1 << 19))
3738 if ((PSW & PSW_NP) && ((PSW & PSW_EP) == 0))
3740 store_mem ((SP + 4) & ~ 3, 4, FEPC);
3741 store_mem ( SP & ~ 3, 4, FEPSW);
3745 store_mem ((SP + 4) & ~ 3, 4, EIPC);
3746 store_mem ( SP & ~ 3, 4, EIPSW);
3750 trace_output (OP_PUSHPOP2);
3755 /* end-sanitize-v850eq */