9 #include "sys/syscall.h"
34 #if (DEBUG & DEBUG_TRACE) != 0
35 static void trace_input
PARAMS ((char *name
,
40 static void trace_output
PARAMS ((enum op_types result
));
42 #ifndef SIZE_INSTRUCTION
43 #define SIZE_INSTRUCTION 10
47 #define SIZE_OPERANDS 24
51 #define SIZE_VALUES 13
55 trace_input (name
, in1
, in2
, in3
)
69 switch (State
.ins_type
)
72 case INS_UNKNOWN
: type
= " ?"; break;
73 case INS_LEFT
: type
= " L"; break;
74 case INS_RIGHT
: type
= " R"; break;
75 case INS_LEFT_PARALLEL
: type
= "*L"; break;
76 case INS_RIGHT_PARALLEL
: type
= "*R"; break;
77 case INS_LONG
: type
= " B"; break;
80 printf ("0x%.6x %s: %-*s", (unsigned)PC
, type
, SIZE_INSTRUCTION
, name
);
87 for (i
= 0; i
< 3; i
++)
98 sprintf (p
, "%sr%d", comma
, OP
[i
]);
106 sprintf (p
, "%scr%d", comma
, OP
[i
]);
112 case OP_ACCUM_OUTPUT
:
113 case OP_ACCUM_REVERSE
:
114 sprintf (p
, "%sa%d", comma
, OP
[i
]);
120 sprintf (p
, "%s%d", comma
, OP
[i
]);
126 sprintf (p
, "%s%d", comma
, SEXT4(OP
[i
]));
132 sprintf (p
, "%s%d", comma
, SEXT3(OP
[i
]));
138 sprintf (p
, "%s@r%d", comma
, OP
[i
]);
144 sprintf (p
, "%s@(%d,r%d)", comma
, (int16
)OP
[i
], OP
[i
+1]);
150 sprintf (p
, "%s@r%d+", comma
, OP
[i
]);
156 sprintf (p
, "%s@r%d-", comma
, OP
[i
]);
162 sprintf (p
, "%s@-r%d", comma
, OP
[i
]);
169 sprintf (p
, "%sf0", comma
);
172 sprintf (p
, "%sf1", comma
);
175 sprintf (p
, "%scarry", comma
);
183 #if (DEBUG & DEBUG_VALUES) == 0
188 #else /* DEBUG_VALUES */
190 printf ("%-*s", SIZE_OPERANDS
, buf
);
193 for (i
= 0; i
< 3; i
++)
199 printf ("%*s", SIZE_VALUES
, "");
205 case OP_ACCUM_OUTPUT
:
206 printf ("%*s", SIZE_VALUES
, "---");
214 printf ("%*s0x%.4x", SIZE_VALUES
-6, "", (uint16
)State
.regs
[OP
[i
]]);
218 tmp
= (long)((((uint32
) State
.regs
[OP
[i
]]) << 16) | ((uint32
) State
.regs
[OP
[i
]+1]));
219 printf ("%*s0x%.8lx", SIZE_VALUES
-10, "", tmp
);
224 printf ("%*s0x%.4x", SIZE_VALUES
-6, "", (uint16
)State
.cregs
[OP
[i
]]);
228 case OP_ACCUM_REVERSE
:
229 printf ("%*s0x%.2x%.8lx", SIZE_VALUES
-12, "",
230 ((int)(State
.a
[OP
[i
]] >> 32) & 0xff),
231 ((unsigned long)State
.a
[OP
[i
]]) & 0xffffffff);
235 printf ("%*s0x%.4x", SIZE_VALUES
-6, "", (uint16
)OP
[i
]);
239 printf ("%*s0x%.4x", SIZE_VALUES
-6, "", (uint16
)SEXT4(OP
[i
]));
243 printf ("%*s0x%.4x", SIZE_VALUES
-6, "", (uint16
)SEXT3(OP
[i
]));
248 printf ("%*sF0 = %d", SIZE_VALUES
-6, "", State
.F0
!= 0);
251 printf ("%*sF1 = %d", SIZE_VALUES
-6, "", State
.F1
!= 0);
254 printf ("%*sC = %d", SIZE_VALUES
-5, "", State
.C
!= 0);
259 printf ("%*s0x%.4x", SIZE_VALUES
-6, "", (uint16
)OP
[i
]);
260 printf ("%*s0x%.4x", SIZE_VALUES
-6, "", (uint16
)State
.regs
[OP
[++i
]]);
268 trace_output (result
)
269 enum op_types result
;
271 #if (DEBUG & DEBUG_VALUES) != 0
282 printf (" :: %*s0x%.4x F0=%d F1=%d C=%d\n", SIZE_VALUES
-6, "", (uint16
)State
.regs
[OP
[0]],
283 State
.F0
!= 0, State
.F1
!= 0, State
.C
!= 0);
288 tmp
= (long)((((uint32
) State
.regs
[OP
[0]]) << 16) | ((uint32
) State
.regs
[OP
[0]+1]));
289 printf (" :: %*s0x%.8lx F0=%d F1=%d C=%d\n", SIZE_VALUES
-10, "", tmp
,
290 State
.F0
!= 0, State
.F1
!= 0, State
.C
!= 0);
295 printf (" :: %*s0x%.4x F0=%d F1=%d C=%d\n", SIZE_VALUES
-6, "", (uint16
)State
.cregs
[OP
[0]],
296 State
.F0
!= 0, State
.F1
!= 0, State
.C
!= 0);
300 printf (" :: %*s0x%.4x F0=%d F1=%d C=%d\n", SIZE_VALUES
-6, "", (uint16
)State
.cregs
[OP
[1]],
301 State
.F0
!= 0, State
.F1
!= 0, State
.C
!= 0);
305 case OP_ACCUM_OUTPUT
:
306 printf (" :: %*s0x%.2x%.8lx F0=%d F1=%d C=%d\n", SIZE_VALUES
-10, "",
307 ((int)(State
.a
[OP
[0]] >> 32) & 0xff),
308 ((unsigned long)State
.a
[OP
[0]]) & 0xffffffff,
309 State
.F0
!= 0, State
.F1
!= 0, State
.C
!= 0);
312 case OP_ACCUM_REVERSE
:
313 printf (" :: %*s0x%.2x%.8lx F0=%d F1=%d C=%d\n", SIZE_VALUES
-10, "",
314 ((int)(State
.a
[OP
[1]] >> 32) & 0xff),
315 ((unsigned long)State
.a
[OP
[1]]) & 0xffffffff,
316 State
.F0
!= 0, State
.F1
!= 0, State
.C
!= 0);
320 printf (" :: %*s F0=%d F1=%d C=%d\n", SIZE_VALUES
, "",
321 State
.F0
!= 0, State
.F1
!= 0, State
.C
!= 0);
330 #define trace_input(NAME, IN1, IN2, IN3)
331 #define trace_output(RESULT)
338 trace_input ("abs", OP_REG
, OP_VOID
, OP_VOID
);
340 if ((int16
)(State
.regs
[OP
[0]]) < 0)
342 State
.regs
[OP
[0]] = -(int16
)(State
.regs
[OP
[0]]);
347 trace_output (OP_REG
);
356 trace_input ("abs", OP_ACCUM
, OP_VOID
, OP_VOID
);
358 State
.a
[OP
[0]] = SEXT40(State
.a
[OP
[0]]);
360 if (State
.a
[OP
[0]] < 0 )
362 tmp
= -State
.a
[OP
[0]];
366 State
.a
[OP
[0]] = MAX32
;
367 else if (tmp
< MIN32
)
368 State
.a
[OP
[0]] = MIN32
;
370 State
.a
[OP
[0]] = tmp
& MASK40
;
373 State
.a
[OP
[0]] = tmp
& MASK40
;
378 trace_output (OP_ACCUM
);
385 uint16 tmp
= State
.regs
[OP
[0]];
386 trace_input ("add", OP_REG
, OP_REG
, OP_VOID
);
387 State
.regs
[OP
[0]] += State
.regs
[OP
[1]];
388 if ( tmp
> State
.regs
[OP
[0]])
392 trace_output (OP_REG
);
400 tmp
= SEXT40(State
.a
[OP
[0]]) + (SEXT16 (State
.regs
[OP
[1]]) << 16 | State
.regs
[OP
[1]+1]);
402 trace_input ("add", OP_ACCUM
, OP_REG
, OP_VOID
);
406 State
.a
[OP
[0]] = MAX32
;
407 else if ( tmp
< MIN32
)
408 State
.a
[OP
[0]] = MIN32
;
410 State
.a
[OP
[0]] = tmp
& MASK40
;
413 State
.a
[OP
[0]] = tmp
& MASK40
;
414 trace_output (OP_ACCUM
);
422 tmp
= SEXT40(State
.a
[OP
[0]]) + SEXT40(State
.a
[OP
[1]]);
424 trace_input ("add", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
428 State
.a
[OP
[0]] = MAX32
;
429 else if ( tmp
< MIN32
)
430 State
.a
[OP
[0]] = MIN32
;
432 State
.a
[OP
[0]] = tmp
& MASK40
;
435 State
.a
[OP
[0]] = tmp
& MASK40
;
436 trace_output (OP_ACCUM
);
444 uint32 tmp1
= (State
.regs
[OP
[0]]) << 16 | State
.regs
[OP
[0]+1];
445 uint32 tmp2
= (State
.regs
[OP
[1]]) << 16 | State
.regs
[OP
[1]+1];
447 trace_input ("add2w", OP_DREG
, OP_DREG
, OP_VOID
);
449 if ( (tmp
< tmp1
) || (tmp
< tmp2
) )
453 State
.regs
[OP
[0]] = tmp
>> 16;
454 State
.regs
[OP
[0]+1] = tmp
& 0xFFFF;
455 trace_output (OP_DREG
);
462 uint16 tmp
= State
.regs
[OP
[0]];
463 State
.regs
[OP
[0]] = State
.regs
[OP
[1]] + OP
[2];
465 trace_input ("add3", OP_REG_OUTPUT
, OP_REG
, OP_CONSTANT16
);
466 if ( tmp
> State
.regs
[OP
[0]])
470 trace_output (OP_REG
);
478 tmp
= SEXT40(State
.a
[OP
[2]]) + SEXT40 ((State
.regs
[OP
[1]] << 16) | State
.regs
[OP
[1]+1]);
480 trace_input ("addac3", OP_DREG_OUTPUT
, OP_DREG
, OP_ACCUM
);
481 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
482 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
483 trace_output (OP_DREG
);
491 tmp
= SEXT40(State
.a
[OP
[1]]) + SEXT40(State
.a
[OP
[2]]);
493 trace_input ("addac3", OP_DREG_OUTPUT
, OP_ACCUM
, OP_ACCUM
);
494 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
495 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
496 trace_output (OP_DREG
);
506 trace_input ("addac3s", OP_DREG_OUTPUT
, OP_DREG
, OP_ACCUM
);
507 tmp
= SEXT40(State
.a
[OP
[2]]) + SEXT40 ((State
.regs
[OP
[1]] << 16) | State
.regs
[OP
[1]+1]);
510 State
.regs
[OP
[0]] = 0x7fff;
511 State
.regs
[OP
[0]+1] = 0xffff;
514 else if (tmp
< MIN32
)
516 State
.regs
[OP
[0]] = 0x8000;
517 State
.regs
[OP
[0]+1] = 0;
522 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
523 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
526 trace_output (OP_DREG
);
536 trace_input ("addac3s", OP_DREG_OUTPUT
, OP_ACCUM
, OP_ACCUM
);
537 tmp
= SEXT40(State
.a
[OP
[1]]) + SEXT40(State
.a
[OP
[2]]);
540 State
.regs
[OP
[0]] = 0x7fff;
541 State
.regs
[OP
[0]+1] = 0xffff;
544 else if (tmp
< MIN32
)
546 State
.regs
[OP
[0]] = 0x8000;
547 State
.regs
[OP
[0]+1] = 0;
552 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
553 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
556 trace_output (OP_DREG
);
565 trace_input ("addi", OP_REG
, OP_CONSTANT16
, OP_VOID
);
566 State
.regs
[OP
[0]] += OP
[1];
567 trace_output (OP_REG
);
574 trace_input ("and", OP_REG
, OP_REG
, OP_VOID
);
575 State
.regs
[OP
[0]] &= State
.regs
[OP
[1]];
576 trace_output (OP_REG
);
583 trace_input ("and3", OP_REG_OUTPUT
, OP_REG
, OP_CONSTANT16
);
584 State
.regs
[OP
[0]] = State
.regs
[OP
[1]] & OP
[2];
585 trace_output (OP_REG
);
592 trace_input ("bclri", OP_REG
, OP_CONSTANT16
, OP_VOID
);
593 State
.regs
[OP
[0]] &= ~(0x8000 >> OP
[1]);
594 trace_output (OP_REG
);
601 trace_input ("bl.s", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
602 State
.regs
[13] = PC
+1;
604 trace_output (OP_VOID
);
611 trace_input ("bl.l", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
612 State
.regs
[13] = PC
+1;
614 trace_output (OP_VOID
);
621 trace_input ("bnoti", OP_REG
, OP_CONSTANT16
, OP_VOID
);
622 State
.regs
[OP
[0]] ^= 0x8000 >> OP
[1];
623 trace_output (OP_REG
);
630 trace_input ("bra.s", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
632 trace_output (OP_VOID
);
639 trace_input ("bra.l", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
641 trace_output (OP_VOID
);
648 trace_input ("brf0f.s", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
651 trace_output (OP_FLAG
);
658 trace_input ("brf0f.l", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
661 trace_output (OP_FLAG
);
668 trace_input ("brf0t.s", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
671 trace_output (OP_FLAG
);
678 trace_input ("brf0t.l", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
681 trace_output (OP_FLAG
);
688 trace_input ("bseti", OP_REG
, OP_CONSTANT16
, OP_VOID
);
689 State
.regs
[OP
[0]] |= 0x8000 >> OP
[1];
690 trace_output (OP_REG
);
697 trace_input ("btsti", OP_REG
, OP_CONSTANT16
, OP_VOID
);
699 State
.F0
= (State
.regs
[OP
[0]] & (0x8000 >> OP
[1])) ? 1 : 0;
700 trace_output (OP_FLAG
);
707 trace_input ("clrac", OP_ACCUM_OUTPUT
, OP_VOID
, OP_VOID
);
709 trace_output (OP_ACCUM
);
716 trace_input ("cmp", OP_REG
, OP_REG
, OP_VOID
);
718 State
.F0
= ((int16
)(State
.regs
[OP
[0]]) < (int16
)(State
.regs
[OP
[1]])) ? 1 : 0;
719 trace_output (OP_FLAG
);
726 trace_input ("cmp", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
728 State
.F0
= (SEXT40(State
.a
[OP
[0]]) < SEXT40(State
.a
[OP
[1]])) ? 1 : 0;
729 trace_output (OP_FLAG
);
736 trace_input ("cmpeq", OP_REG
, OP_REG
, OP_VOID
);
738 State
.F0
= (State
.regs
[OP
[0]] == State
.regs
[OP
[1]]) ? 1 : 0;
739 trace_output (OP_FLAG
);
746 trace_input ("cmpeq", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
748 State
.F0
= (State
.a
[OP
[0]] == State
.a
[OP
[1]]) ? 1 : 0;
749 trace_output (OP_FLAG
);
756 trace_input ("cmpeqi.s", OP_REG
, OP_CONSTANT16
, OP_VOID
);
758 State
.F0
= (State
.regs
[OP
[0]] == SEXT4(OP
[1])) ? 1 : 0;
759 trace_output (OP_FLAG
);
766 trace_input ("cmpeqi.l", OP_REG
, OP_CONSTANT16
, OP_VOID
);
768 State
.F0
= (State
.regs
[OP
[0]] == OP
[1]) ? 1 : 0;
769 trace_output (OP_FLAG
);
776 trace_input ("cmpi.s", OP_REG
, OP_CONSTANT4
, OP_VOID
);
778 State
.F0
= ((int16
)(State
.regs
[OP
[0]]) < SEXT4(OP
[1])) ? 1 : 0;
779 trace_output (OP_FLAG
);
786 trace_input ("cmpi.l", OP_REG
, OP_CONSTANT16
, OP_VOID
);
788 State
.F0
= ((int16
)(State
.regs
[OP
[0]]) < (int16
)(OP
[1])) ? 1 : 0;
789 trace_output (OP_FLAG
);
796 trace_input ("cmpu", OP_REG
, OP_REG
, OP_VOID
);
798 State
.F0
= (State
.regs
[OP
[0]] < State
.regs
[OP
[1]]) ? 1 : 0;
799 trace_output (OP_FLAG
);
806 trace_input ("cmpui", OP_REG
, OP_CONSTANT16
, OP_VOID
);
808 State
.F0
= (State
.regs
[OP
[0]] < OP
[1]) ? 1 : 0;
809 trace_output (OP_FLAG
);
818 trace_input ("cpfg", OP_FLAG
, OP_VOID
, OP_VOID
);
832 trace_output (OP_FLAG
);
839 printf("***** DBT ***** PC=%x\n",PC
);
840 State
.exception
= SIGTRAP
;
847 uint16 foo
, tmp
, tmpf
;
849 trace_input ("divs", OP_DREG
, OP_REG
, OP_VOID
);
850 foo
= (State
.regs
[OP
[0]] << 1) | (State
.regs
[OP
[0]+1] >> 15);
851 tmp
= (int16
)foo
- (int16
)(State
.regs
[OP
[1]]);
852 tmpf
= (foo
>= State
.regs
[OP
[1]]) ? 1 : 0;
853 State
.regs
[OP
[0]] = (tmpf
== 1) ? tmp
: foo
;
854 State
.regs
[OP
[0]+1] = (State
.regs
[OP
[0]+1] << 1) | tmpf
;
855 trace_output (OP_DREG
);
862 trace_input ("exef0f", OP_VOID
, OP_VOID
, OP_VOID
);
863 State
.exe
= (State
.F0
) ? 0 : 1;
864 trace_output (OP_FLAG
);
871 trace_input ("exef0t", OP_VOID
, OP_VOID
, OP_VOID
);
872 State
.exe
= State
.F0
;
873 trace_output (OP_FLAG
);
880 trace_input ("exef1f", OP_VOID
, OP_VOID
, OP_VOID
);
881 State
.exe
= (State
.F1
) ? 0 : 1;
882 trace_output (OP_FLAG
);
889 trace_input ("exef1t", OP_VOID
, OP_VOID
, OP_VOID
);
890 State
.exe
= State
.F1
;
891 trace_output (OP_FLAG
);
898 trace_input ("exefaf", OP_VOID
, OP_VOID
, OP_VOID
);
899 State
.exe
= (State
.F0
| State
.F1
) ? 0 : 1;
900 trace_output (OP_FLAG
);
907 trace_input ("exefat", OP_VOID
, OP_VOID
, OP_VOID
);
908 State
.exe
= (State
.F0
) ? 0 : (State
.F1
);
909 trace_output (OP_FLAG
);
916 trace_input ("exetaf", OP_VOID
, OP_VOID
, OP_VOID
);
917 State
.exe
= (State
.F1
) ? 0 : (State
.F0
);
918 trace_output (OP_FLAG
);
925 trace_input ("exetat", OP_VOID
, OP_VOID
, OP_VOID
);
926 State
.exe
= (State
.F0
) ? (State
.F1
) : 0;
927 trace_output (OP_FLAG
);
937 trace_input ("exp", OP_REG_OUTPUT
, OP_DREG
, OP_VOID
);
938 if (((int16
)State
.regs
[OP
[1]]) >= 0)
939 tmp
= (State
.regs
[OP
[1]] << 16) | State
.regs
[OP
[1]+1];
941 tmp
= ~((State
.regs
[OP
[1]] << 16) | State
.regs
[OP
[1]+1]);
948 State
.regs
[OP
[0]] = i
-1;
949 trace_output (OP_REG
);
954 State
.regs
[OP
[0]] = 16;
955 trace_output (OP_REG
);
965 trace_input ("exp", OP_REG_OUTPUT
, OP_ACCUM
, OP_VOID
);
966 if (SEXT40(State
.a
[OP
[1]]) >= 0)
967 tmp
= State
.a
[OP
[1]];
969 tmp
= ~(State
.a
[OP
[1]]);
971 foo
= 0x4000000000LL
;
976 State
.regs
[OP
[0]] = i
-9;
977 trace_output (OP_REG
);
982 State
.regs
[OP
[0]] = 16;
983 trace_output (OP_REG
);
990 trace_input ("jl", OP_REG
, OP_VOID
, OP_VOID
);
991 State
.regs
[13] = PC
+1;
992 PC
= State
.regs
[OP
[0]];
993 trace_output (OP_VOID
);
1000 trace_input ("jmp", OP_REG
, OP_VOID
, OP_VOID
);
1001 PC
= State
.regs
[OP
[0]];
1002 trace_output (OP_VOID
);
1009 trace_input ("ld", OP_REG_OUTPUT
, OP_MEMREF2
, OP_VOID
);
1010 State
.regs
[OP
[0]] = RW (OP
[1] + State
.regs
[OP
[2]]);
1011 trace_output (OP_REG
);
1018 trace_input ("ld", OP_REG_OUTPUT
, OP_POSTDEC
, OP_VOID
);
1019 State
.regs
[OP
[0]] = RW (State
.regs
[OP
[1]]);
1020 INC_ADDR(State
.regs
[OP
[1]],-2);
1021 trace_output (OP_REG
);
1028 trace_input ("ld", OP_REG_OUTPUT
, OP_POSTINC
, OP_VOID
);
1029 State
.regs
[OP
[0]] = RW (State
.regs
[OP
[1]]);
1030 INC_ADDR(State
.regs
[OP
[1]],2);
1031 trace_output (OP_REG
);
1038 trace_input ("ld", OP_REG_OUTPUT
, OP_MEMREF
, OP_VOID
);
1039 State
.regs
[OP
[0]] = RW (State
.regs
[OP
[1]]);
1040 trace_output (OP_REG
);
1047 trace_input ("ld2w", OP_REG_OUTPUT
, OP_MEMREF
, OP_VOID
);
1048 State
.regs
[OP
[0]] = RW (OP
[1] + State
.regs
[OP
[2]]);
1049 State
.regs
[OP
[0]+1] = RW (OP
[1] + State
.regs
[OP
[2]] + 2);
1050 trace_output (OP_DREG
);
1057 trace_input ("ld2w", OP_REG_OUTPUT
, OP_POSTDEC
, OP_VOID
);
1058 State
.regs
[OP
[0]] = RW (State
.regs
[OP
[1]]);
1059 State
.regs
[OP
[0]+1] = RW (State
.regs
[OP
[1]]+2);
1060 INC_ADDR(State
.regs
[OP
[1]],-4);
1061 trace_output (OP_DREG
);
1068 trace_input ("ld2w", OP_REG_OUTPUT
, OP_POSTINC
, OP_VOID
);
1069 State
.regs
[OP
[0]] = RW (State
.regs
[OP
[1]]);
1070 State
.regs
[OP
[0]+1] = RW (State
.regs
[OP
[1]]+2);
1071 INC_ADDR(State
.regs
[OP
[1]],4);
1072 trace_output (OP_REG
);
1079 trace_input ("ld", OP_REG_OUTPUT
, OP_MEMREF
, OP_VOID
);
1080 State
.regs
[OP
[0]] = RW (State
.regs
[OP
[1]]);
1081 State
.regs
[OP
[0]+1] = RW (State
.regs
[OP
[1]]+2);
1082 trace_output (OP_REG
);
1089 trace_input ("ldb", OP_REG_OUTPUT
, OP_MEMREF2
, OP_VOID
);
1090 State
.regs
[OP
[0]] = RB (OP
[1] + State
.regs
[OP
[2]]);
1091 SEXT8 (State
.regs
[OP
[0]]);
1092 trace_output (OP_REG
);
1099 trace_input ("ldb", OP_REG_OUTPUT
, OP_MEMREF
, OP_VOID
);
1100 State
.regs
[OP
[0]] = RB (State
.regs
[OP
[1]]);
1101 SEXT8 (State
.regs
[OP
[0]]);
1102 trace_output (OP_REG
);
1109 trace_input ("ldi.s", OP_REG_OUTPUT
, OP_CONSTANT4
, OP_VOID
);
1110 State
.regs
[OP
[0]] = SEXT4(OP
[1]);
1111 trace_output (OP_REG
);
1118 trace_input ("ldi.s", OP_REG_OUTPUT
, OP_CONSTANT16
, OP_VOID
);
1119 State
.regs
[OP
[0]] = OP
[1];
1120 trace_output (OP_REG
);
1127 trace_input ("ldub", OP_REG_OUTPUT
, OP_MEMREF2
, OP_VOID
);
1128 State
.regs
[OP
[0]] = RB (OP
[1] + State
.regs
[OP
[2]]);
1129 trace_output (OP_REG
);
1136 trace_input ("ldub", OP_REG_OUTPUT
, OP_MEMREF
, OP_VOID
);
1137 State
.regs
[OP
[0]] = RB (State
.regs
[OP
[1]]);
1138 trace_output (OP_REG
);
1147 trace_input ("mac", OP_ACCUM
, OP_REG
, OP_REG
);
1148 tmp
= SEXT40 ((int16
)(State
.regs
[OP
[1]]) * (int16
)(State
.regs
[OP
[2]]));
1151 tmp
= SEXT40( (tmp
<< 1) & MASK40
);
1153 if (State
.ST
&& tmp
> MAX32
)
1156 tmp
+= SEXT40(State
.a
[OP
[0]]);
1160 State
.a
[OP
[0]] = MAX32
;
1161 else if (tmp
< MIN32
)
1162 State
.a
[OP
[0]] = MIN32
;
1164 State
.a
[OP
[0]] = tmp
& MASK40
;
1167 State
.a
[OP
[0]] = tmp
& MASK40
;
1168 trace_output (OP_ACCUM
);
1177 trace_input ("macsu", OP_ACCUM
, OP_REG
, OP_REG
);
1178 tmp
= SEXT40 ((int16
)State
.regs
[OP
[1]] * State
.regs
[OP
[2]]);
1180 tmp
= SEXT40( (tmp
<< 1) & MASK40
);
1182 State
.a
[OP
[0]] = (SEXT40 (State
.a
[OP
[0]]) + tmp
) & MASK40
;
1183 trace_output (OP_ACCUM
);
1192 trace_input ("macu", OP_ACCUM
, OP_REG
, OP_REG
);
1193 tmp
= SEXT40 (State
.regs
[OP
[1]] * State
.regs
[OP
[2]]);
1195 tmp
= SEXT40( (tmp
<< 1) & MASK40
);
1196 State
.a
[OP
[0]] = (SEXT40 (State
.a
[OP
[0]]) + tmp
) & MASK40
;
1197 trace_output (OP_ACCUM
);
1204 trace_input ("max", OP_REG
, OP_REG
, OP_VOID
);
1205 State
.F1
= State
.F0
;
1206 if (State
.regs
[OP
[1]] > State
.regs
[OP
[0]])
1208 State
.regs
[OP
[0]] = State
.regs
[OP
[1]];
1213 trace_output (OP_REG
);
1222 trace_input ("max", OP_ACCUM
, OP_DREG
, OP_VOID
);
1223 State
.F1
= State
.F0
;
1224 tmp
= SEXT16 (State
.regs
[OP
[1]]) << 16 | State
.regs
[OP
[1]+1];
1225 if (tmp
> SEXT40(State
.a
[OP
[0]]))
1227 State
.a
[OP
[0]] = tmp
& MASK40
;
1232 trace_output (OP_ACCUM
);
1239 trace_input ("max", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
1240 State
.F1
= State
.F0
;
1241 if (SEXT40(State
.a
[OP
[1]]) > SEXT40(State
.a
[OP
[0]]))
1243 State
.a
[OP
[0]] = State
.a
[OP
[1]];
1248 trace_output (OP_ACCUM
);
1256 trace_input ("min", OP_REG
, OP_REG
, OP_VOID
);
1257 State
.F1
= State
.F0
;
1258 if (State
.regs
[OP
[1]] < State
.regs
[OP
[0]])
1260 State
.regs
[OP
[0]] = State
.regs
[OP
[1]];
1265 trace_output (OP_REG
);
1274 trace_input ("min", OP_ACCUM
, OP_DREG
, OP_VOID
);
1275 State
.F1
= State
.F0
;
1276 tmp
= SEXT16 (State
.regs
[OP
[1]]) << 16 | State
.regs
[OP
[1]+1];
1277 if (tmp
< SEXT40(State
.a
[OP
[0]]))
1279 State
.a
[OP
[0]] = tmp
& MASK40
;
1284 trace_output (OP_ACCUM
);
1291 trace_input ("min", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
1292 State
.F1
= State
.F0
;
1293 if (SEXT40(State
.a
[OP
[1]]) < SEXT40(State
.a
[OP
[0]]))
1295 State
.a
[OP
[0]] = State
.a
[OP
[1]];
1300 trace_output (OP_ACCUM
);
1309 trace_input ("msb", OP_ACCUM
, OP_REG
, OP_REG
);
1310 tmp
= SEXT40 ((int16
)(State
.regs
[OP
[1]]) * (int16
)(State
.regs
[OP
[2]]));
1313 tmp
= SEXT40 ((tmp
<< 1) & MASK40
);
1315 if (State
.ST
&& tmp
> MAX32
)
1318 tmp
= SEXT40(State
.a
[OP
[0]]) - tmp
;
1322 State
.a
[OP
[0]] = MAX32
;
1323 else if (tmp
< MIN32
)
1324 State
.a
[OP
[0]] = MIN32
;
1326 State
.a
[OP
[0]] = tmp
& MASK40
;
1329 State
.a
[OP
[0]] = tmp
& MASK40
;
1330 trace_output (OP_ACCUM
);
1339 trace_input ("msbsu", OP_ACCUM
, OP_REG
, OP_REG
);
1340 tmp
= SEXT40 ((int16
)State
.regs
[OP
[1]] * State
.regs
[OP
[2]]);
1342 tmp
= SEXT40( (tmp
<< 1) & MASK40
);
1344 State
.a
[OP
[0]] = (SEXT40 (State
.a
[OP
[0]]) - tmp
) & MASK40
;
1345 trace_output (OP_ACCUM
);
1354 trace_input ("msbu", OP_ACCUM
, OP_REG
, OP_REG
);
1355 tmp
= SEXT40 (State
.regs
[OP
[1]] * State
.regs
[OP
[2]]);
1357 tmp
= SEXT40( (tmp
<< 1) & MASK40
);
1359 State
.a
[OP
[0]] = (SEXT40 (State
.a
[OP
[0]]) - tmp
) & MASK40
;
1360 trace_output (OP_ACCUM
);
1367 trace_input ("mul", OP_REG
, OP_REG
, OP_VOID
);
1368 State
.regs
[OP
[0]] *= State
.regs
[OP
[1]];
1369 trace_output (OP_REG
);
1378 trace_input ("mulx", OP_ACCUM_OUTPUT
, OP_REG
, OP_REG
);
1379 tmp
= SEXT40 ((int16
)(State
.regs
[OP
[1]]) * (int16
)(State
.regs
[OP
[2]]));
1382 tmp
= SEXT40 ((tmp
<< 1) & MASK40
);
1384 if (State
.ST
&& tmp
> MAX32
)
1385 State
.a
[OP
[0]] = MAX32
;
1387 State
.a
[OP
[0]] = tmp
& MASK40
;
1388 trace_output (OP_ACCUM
);
1397 trace_input ("mulxsu", OP_ACCUM_OUTPUT
, OP_REG
, OP_REG
);
1398 tmp
= SEXT40 ((int16
)(State
.regs
[OP
[1]]) * State
.regs
[OP
[2]]);
1403 State
.a
[OP
[0]] = tmp
& MASK40
;
1404 trace_output (OP_ACCUM
);
1413 trace_input ("mulxu", OP_ACCUM_OUTPUT
, OP_REG
, OP_REG
);
1414 tmp
= SEXT40 (State
.regs
[OP
[1]] * State
.regs
[OP
[2]]);
1419 State
.a
[OP
[0]] = tmp
& MASK40
;
1420 trace_output (OP_ACCUM
);
1427 trace_input ("mv", OP_REG_OUTPUT
, OP_REG
, OP_VOID
);
1428 State
.regs
[OP
[0]] = State
.regs
[OP
[1]];
1429 trace_output (OP_REG
);
1436 trace_input ("mv2w", OP_DREG_OUTPUT
, OP_DREG
, OP_VOID
);
1437 State
.regs
[OP
[0]] = State
.regs
[OP
[1]];
1438 State
.regs
[OP
[0]+1] = State
.regs
[OP
[1]+1];
1439 trace_output (OP_DREG
);
1446 trace_input ("mv2wfac", OP_DREG_OUTPUT
, OP_ACCUM
, OP_VOID
);
1447 State
.regs
[OP
[0]] = (State
.a
[OP
[1]] >> 16) & 0xffff;
1448 State
.regs
[OP
[0]+1] = State
.a
[OP
[1]] & 0xffff;
1449 trace_output (OP_DREG
);
1456 trace_input ("mv2wtac", OP_ACCUM_OUTPUT
, OP_DREG
, OP_VOID
);
1457 State
.a
[OP
[1]] = (SEXT16 (State
.regs
[OP
[0]]) << 16 | State
.regs
[OP
[0]+1]) & MASK40
;
1458 trace_output (OP_ACCUM
);
1465 trace_input ("mvac", OP_ACCUM_OUTPUT
, OP_ACCUM
, OP_VOID
);
1466 State
.a
[OP
[0]] = State
.a
[OP
[1]];
1467 trace_output (OP_ACCUM
);
1474 trace_input ("mvb", OP_REG_OUTPUT
, OP_REG
, OP_VOID
);
1475 State
.regs
[OP
[0]] = SEXT8 (State
.regs
[OP
[1]] & 0xff);
1476 trace_output (OP_REG
);
1483 trace_input ("mf0f", OP_REG_OUTPUT
, OP_REG
, OP_VOID
);
1485 State
.regs
[OP
[0]] = State
.regs
[OP
[1]];
1486 trace_output (OP_REG
);
1493 trace_input ("mf0t", OP_REG_OUTPUT
, OP_REG
, OP_VOID
);
1495 State
.regs
[OP
[0]] = State
.regs
[OP
[1]];
1496 trace_output (OP_REG
);
1503 trace_input ("mvfacg", OP_REG_OUTPUT
, OP_ACCUM
, OP_VOID
);
1504 State
.regs
[OP
[0]] = (State
.a
[OP
[1]] >> 32) & 0xff;
1505 trace_output (OP_ACCUM
);
1512 trace_input ("mvfachi", OP_REG_OUTPUT
, OP_ACCUM
, OP_VOID
);
1513 State
.regs
[OP
[0]] = (State
.a
[OP
[1]] >> 16) & 0xffff;
1514 trace_output (OP_REG
);
1521 trace_input ("mvfaclo", OP_REG_OUTPUT
, OP_ACCUM
, OP_VOID
);
1522 State
.regs
[OP
[0]] = State
.a
[OP
[1]] & 0xffff;
1523 trace_output (OP_REG
);
1530 trace_input ("mvfc", OP_REG_OUTPUT
, OP_CR
, OP_VOID
);
1533 /* PSW is treated specially */
1535 if (State
.SM
) PSW
|= 0x8000;
1536 if (State
.EA
) PSW
|= 0x2000;
1537 if (State
.DB
) PSW
|= 0x1000;
1538 if (State
.IE
) PSW
|= 0x400;
1539 if (State
.RP
) PSW
|= 0x200;
1540 if (State
.MD
) PSW
|= 0x100;
1541 if (State
.FX
) PSW
|= 0x80;
1542 if (State
.ST
) PSW
|= 0x40;
1543 if (State
.F0
) PSW
|= 8;
1544 if (State
.F1
) PSW
|= 4;
1545 if (State
.C
) PSW
|= 1;
1547 State
.regs
[OP
[0]] = State
.cregs
[OP
[1]];
1548 trace_output (OP_REG
);
1555 trace_input ("mvtacg", OP_REG
, OP_ACCUM
, OP_VOID
);
1556 State
.a
[OP
[1]] &= MASK32
;
1557 State
.a
[OP
[1]] |= (int64
)(State
.regs
[OP
[0]] & 0xff) << 32;
1558 trace_output (OP_ACCUM_REVERSE
);
1567 trace_input ("mvtachi", OP_REG
, OP_ACCUM
, OP_VOID
);
1568 tmp
= State
.a
[OP
[1]] & 0xffff;
1569 State
.a
[OP
[1]] = (SEXT16 (State
.regs
[OP
[0]]) << 16 | tmp
) & MASK40
;
1570 trace_output (OP_ACCUM_REVERSE
);
1577 trace_input ("mvtaclo", OP_REG
, OP_ACCUM
, OP_VOID
);
1578 State
.a
[OP
[1]] = (SEXT16 (State
.regs
[OP
[0]])) & MASK40
;
1579 trace_output (OP_ACCUM_REVERSE
);
1586 trace_input ("mvtc", OP_REG
, OP_CR_OUTPUT
, OP_VOID
);
1587 State
.cregs
[OP
[1]] = State
.regs
[OP
[0]];
1590 /* PSW is treated specially */
1591 State
.SM
= (PSW
& 0x8000) ? 1 : 0;
1592 State
.EA
= (PSW
& 0x2000) ? 1 : 0;
1593 State
.DB
= (PSW
& 0x1000) ? 1 : 0;
1594 State
.IE
= (PSW
& 0x400) ? 1 : 0;
1595 State
.RP
= (PSW
& 0x200) ? 1 : 0;
1596 State
.MD
= (PSW
& 0x100) ? 1 : 0;
1597 State
.FX
= (PSW
& 0x80) ? 1 : 0;
1598 State
.ST
= (PSW
& 0x40) ? 1 : 0;
1599 State
.F0
= (PSW
& 8) ? 1 : 0;
1600 State
.F1
= (PSW
& 4) ? 1 : 0;
1602 if (State
.ST
&& !State
.FX
)
1604 fprintf (stderr
,"ERROR at PC 0x%x: ST can only be set when FX is set.\n",PC
<<2);
1605 State
.exception
= SIGILL
;
1608 trace_output (OP_CR_REVERSE
);
1615 trace_input ("mvub", OP_REG_OUTPUT
, OP_REG
, OP_VOID
);
1616 State
.regs
[OP
[0]] = State
.regs
[OP
[1]] & 0xff;
1617 trace_output (OP_REG
);
1624 trace_input ("neg", OP_REG
, OP_VOID
, OP_VOID
);
1625 State
.regs
[OP
[0]] = 0 - State
.regs
[OP
[0]];
1626 trace_output (OP_REG
);
1635 trace_input ("neg", OP_ACCUM
, OP_VOID
, OP_VOID
);
1636 tmp
= -SEXT40(State
.a
[OP
[0]]);
1640 State
.a
[OP
[0]] = MAX32
;
1641 else if (tmp
< MIN32
)
1642 State
.a
[OP
[0]] = MIN32
;
1644 State
.a
[OP
[0]] = tmp
& MASK40
;
1647 State
.a
[OP
[0]] = tmp
& MASK40
;
1648 trace_output (OP_ACCUM
);
1656 trace_input ("nop", OP_VOID
, OP_VOID
, OP_VOID
);
1657 trace_output (OP_VOID
);
1664 trace_input ("not", OP_REG
, OP_VOID
, OP_VOID
);
1665 State
.regs
[OP
[0]] = ~(State
.regs
[OP
[0]]);
1666 trace_output (OP_REG
);
1673 trace_input ("or", OP_REG
, OP_REG
, OP_VOID
);
1674 State
.regs
[OP
[0]] |= State
.regs
[OP
[1]];
1675 trace_output (OP_REG
);
1682 trace_input ("or3", OP_REG_OUTPUT
, OP_REG
, OP_CONSTANT16
);
1683 State
.regs
[OP
[0]] = State
.regs
[OP
[1]] | OP
[2];
1684 trace_output (OP_REG
);
1692 int shift
= SEXT3 (OP
[2]);
1694 trace_input ("rac", OP_DREG_OUTPUT
, OP_ACCUM
, OP_CONSTANT3
);
1697 fprintf (stderr
,"ERROR at PC 0x%x: instruction only valid for A0\n",PC
<<2);
1698 State
.exception
= SIGILL
;
1701 State
.F1
= State
.F0
;
1703 tmp
= ((State
.a
[0] << 16) | (State
.a
[1] & 0xffff)) << shift
;
1705 tmp
= ((State
.a
[0] << 16) | (State
.a
[1] & 0xffff)) >> -shift
;
1706 tmp
= ( SEXT60(tmp
) + 0x8000 ) >> 16;
1709 State
.regs
[OP
[0]] = 0x7fff;
1710 State
.regs
[OP
[0]+1] = 0xffff;
1713 else if (tmp
< MIN32
)
1715 State
.regs
[OP
[0]] = 0x8000;
1716 State
.regs
[OP
[0]+1] = 0;
1721 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
1722 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
1725 trace_output (OP_DREG
);
1733 int shift
= SEXT3 (OP
[2]);
1735 trace_input ("rachi", OP_REG_OUTPUT
, OP_ACCUM
, OP_CONSTANT3
);
1736 State
.F1
= State
.F0
;
1738 tmp
= SEXT44 (State
.a
[1]) << shift
;
1740 tmp
= SEXT44 (State
.a
[1]) >> -shift
;
1745 State
.regs
[OP
[0]] = 0x7fff;
1748 else if (tmp
< 0xfff80000000LL
)
1750 State
.regs
[OP
[0]] = 0x8000;
1755 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
1758 trace_output (OP_REG
);
1765 trace_input ("rep", OP_REG
, OP_CONSTANT16
, OP_VOID
);
1768 RPT_C
= State
.regs
[OP
[0]];
1772 fprintf (stderr
, "ERROR: rep with count=0 is illegal.\n");
1773 State
.exception
= SIGILL
;
1777 fprintf (stderr
, "ERROR: rep must include at least 4 instructions.\n");
1778 State
.exception
= SIGILL
;
1780 trace_output (OP_VOID
);
1787 trace_input ("repi", OP_CONSTANT16
, OP_CONSTANT16
, OP_VOID
);
1794 fprintf (stderr
, "ERROR: repi with count=0 is illegal.\n");
1795 State
.exception
= SIGILL
;
1799 fprintf (stderr
, "ERROR: repi must include at least 4 instructions.\n");
1800 State
.exception
= SIGILL
;
1802 trace_output (OP_VOID
);
1809 fprintf(stderr
, "ERROR: rtd - NOT IMPLEMENTED\n");
1810 State
.exception
= SIGILL
;
1817 trace_input ("rte", OP_VOID
, OP_VOID
, OP_VOID
);
1820 trace_output (OP_VOID
);
1829 trace_input ("sadd", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
1830 tmp
= SEXT40(State
.a
[OP
[0]]) + (SEXT40(State
.a
[OP
[1]]) >> 16);
1834 State
.a
[OP
[0]] = MAX32
;
1835 else if (tmp
< MIN32
)
1836 State
.a
[OP
[0]] = MIN32
;
1838 State
.a
[OP
[0]] = tmp
& MASK40
;
1841 State
.a
[OP
[0]] = tmp
& MASK40
;
1842 trace_output (OP_ACCUM
);
1849 trace_input ("setf0f", OP_REG_OUTPUT
, OP_VOID
, OP_VOID
);
1850 State
.regs
[OP
[0]] = (State
.F0
== 0) ? 1 : 0;
1851 trace_output (OP_REG
);
1858 trace_input ("setf0t", OP_REG_OUTPUT
, OP_VOID
, OP_VOID
);
1859 State
.regs
[OP
[0]] = (State
.F0
== 1) ? 1 : 0;
1860 trace_output (OP_REG
);
1867 trace_input ("sleep", OP_VOID
, OP_VOID
, OP_VOID
);
1869 trace_output (OP_VOID
);
1876 trace_input ("sll", OP_REG
, OP_REG
, OP_VOID
);
1877 State
.regs
[OP
[0]] <<= (State
.regs
[OP
[1]] & 0xf);
1878 trace_output (OP_REG
);
1886 trace_input ("sll", OP_ACCUM
, OP_REG
, OP_VOID
);
1887 if (State
.regs
[OP
[1]] & 31 <= 16)
1888 tmp
= SEXT40 (State
.a
[OP
[0]]) << (State
.regs
[OP
[1]] & 31);
1893 State
.a
[OP
[0]] = MAX32
;
1894 else if (tmp
< 0xffffff80000000LL
)
1895 State
.a
[OP
[0]] = MIN32
;
1897 State
.a
[OP
[0]] = tmp
& MASK40
;
1900 State
.a
[OP
[0]] = tmp
& MASK40
;
1901 trace_output (OP_ACCUM
);
1908 trace_input ("slli", OP_REG
, OP_CONSTANT16
, OP_VOID
);
1909 State
.regs
[OP
[0]] <<= OP
[1];
1910 trace_output (OP_REG
);
1922 trace_input ("slli", OP_ACCUM
, OP_CONSTANT16
, OP_VOID
);
1923 tmp
= SEXT40(State
.a
[OP
[0]]) << OP
[1];
1928 State
.a
[OP
[0]] = MAX32
;
1929 else if (tmp
< 0xffffff80000000LL
)
1930 State
.a
[OP
[0]] = MIN32
;
1932 State
.a
[OP
[0]] = tmp
& MASK40
;
1935 State
.a
[OP
[0]] = tmp
& MASK40
;
1936 trace_output (OP_ACCUM
);
1945 trace_input ("slx", OP_REG
, OP_FLAG
, OP_VOID
);
1946 State
.regs
[OP
[0]] = (State
.regs
[OP
[0]] << 1) | State
.F0
;
1947 trace_output (OP_REG
);
1954 trace_input ("sra", OP_REG
, OP_REG
, OP_VOID
);
1955 State
.regs
[OP
[0]] = ((int16
)(State
.regs
[OP
[0]])) >> (State
.regs
[OP
[1]] & 0xf);
1956 trace_output (OP_REG
);
1963 trace_input ("sra", OP_ACCUM
, OP_REG
, OP_VOID
);
1964 if (State
.regs
[OP
[1]] & 31 <= 16)
1965 State
.a
[OP
[0]] >>= (State
.regs
[OP
[1]] & 31);
1966 trace_output (OP_ACCUM
);
1973 trace_input ("srai", OP_REG
, OP_CONSTANT16
, OP_VOID
);
1974 State
.regs
[OP
[0]] = ((int16
)(State
.regs
[OP
[0]])) >> OP
[1];
1975 trace_output (OP_REG
);
1985 trace_input ("srai", OP_ACCUM
, OP_CONSTANT16
, OP_VOID
);
1986 State
.a
[OP
[0]] >>= OP
[1];
1987 trace_output (OP_ACCUM
);
1994 trace_input ("srl", OP_REG
, OP_REG
, OP_VOID
);
1995 State
.regs
[OP
[0]] >>= (State
.regs
[OP
[1]] & 0xf);
1996 trace_output (OP_REG
);
2003 trace_input ("srl", OP_ACCUM
, OP_REG
, OP_VOID
);
2004 if (State
.regs
[OP
[1]] & 31 <= 16)
2005 State
.a
[OP
[0]] >>= (State
.regs
[OP
[1]] & 31);
2006 trace_output (OP_ACCUM
);
2013 trace_input ("srli", OP_REG
, OP_CONSTANT16
, OP_VOID
);
2014 State
.regs
[OP
[0]] >>= OP
[1];
2015 trace_output (OP_REG
);
2025 trace_input ("srli", OP_ACCUM
, OP_CONSTANT16
, OP_VOID
);
2026 State
.a
[OP
[0]] >>= OP
[1];
2027 trace_output (OP_ACCUM
);
2036 trace_input ("srx", OP_REG
, OP_FLAG
, OP_VOID
);
2037 tmp
= State
.F0
<< 15;
2038 State
.regs
[OP
[0]] = (State
.regs
[OP
[0]] >> 1) | tmp
;
2039 trace_output (OP_REG
);
2046 trace_input ("st", OP_REG
, OP_MEMREF2
, OP_VOID
);
2047 SW (OP
[1] + State
.regs
[OP
[2]], State
.regs
[OP
[0]]);
2048 trace_output (OP_VOID
);
2055 trace_input ("st", OP_REG
, OP_MEMREF
, OP_VOID
);
2056 SW (State
.regs
[OP
[1]], State
.regs
[OP
[0]]);
2057 trace_output (OP_VOID
);
2064 trace_input ("st", OP_REG
, OP_PREDEC
, OP_VOID
);
2067 fprintf (stderr
,"ERROR: cannot pre-decrement any registers but r15 (SP).\n");
2068 State
.exception
= SIGILL
;
2071 State
.regs
[OP
[1]] -= 2;
2072 SW (State
.regs
[OP
[1]], State
.regs
[OP
[0]]);
2073 trace_output (OP_VOID
);
2080 trace_input ("st", OP_REG
, OP_POSTINC
, OP_VOID
);
2081 SW (State
.regs
[OP
[1]], State
.regs
[OP
[0]]);
2082 INC_ADDR (State
.regs
[OP
[1]],2);
2083 trace_output (OP_VOID
);
2090 trace_input ("st", OP_REG
, OP_POSTDEC
, OP_VOID
);
2091 SW (State
.regs
[OP
[1]], State
.regs
[OP
[0]]);
2092 INC_ADDR (State
.regs
[OP
[1]],-2);
2093 trace_output (OP_VOID
);
2100 trace_input ("st2w", OP_DREG
, OP_MEMREF2
, OP_VOID
);
2101 SW (State
.regs
[OP
[2]]+OP
[1], State
.regs
[OP
[0]]);
2102 SW (State
.regs
[OP
[2]]+OP
[1]+2, State
.regs
[OP
[0]+1]);
2103 trace_output (OP_VOID
);
2110 trace_input ("st2w", OP_REG
, OP_MEMREF
, OP_VOID
);
2111 SW (State
.regs
[OP
[1]], State
.regs
[OP
[0]]);
2112 SW (State
.regs
[OP
[1]]+2, State
.regs
[OP
[0]+1]);
2113 trace_output (OP_VOID
);
2120 trace_input ("st2w", OP_REG
, OP_PREDEC
, OP_VOID
);
2123 fprintf (stderr
,"ERROR: cannot pre-decrement any registers but r15 (SP).\n");
2124 State
.exception
= SIGILL
;
2127 State
.regs
[OP
[1]] -= 4;
2128 SW (State
.regs
[OP
[1]], State
.regs
[OP
[0]]);
2129 SW (State
.regs
[OP
[1]]+2, State
.regs
[OP
[0]+1]);
2130 trace_output (OP_VOID
);
2137 trace_input ("st2w", OP_REG
, OP_POSTDEC
, OP_VOID
);
2138 SW (State
.regs
[OP
[1]], State
.regs
[OP
[0]]);
2139 SW (State
.regs
[OP
[1]]+2, State
.regs
[OP
[0]+1]);
2140 INC_ADDR (State
.regs
[OP
[1]],4);
2141 trace_output (OP_VOID
);
2148 trace_input ("st2w", OP_REG
, OP_POSTINC
, OP_VOID
);
2149 SW (State
.regs
[OP
[1]], State
.regs
[OP
[0]]);
2150 SW (State
.regs
[OP
[1]]+2, State
.regs
[OP
[0]+1]);
2151 INC_ADDR (State
.regs
[OP
[1]],-4);
2152 trace_output (OP_VOID
);
2159 trace_input ("stb", OP_REG
, OP_MEMREF2
, OP_VOID
);
2160 SB (State
.regs
[OP
[2]]+OP
[1], State
.regs
[OP
[0]]);
2161 trace_output (OP_VOID
);
2168 trace_input ("stb", OP_REG
, OP_MEMREF
, OP_VOID
);
2169 SB (State
.regs
[OP
[1]], State
.regs
[OP
[0]]);
2170 trace_output (OP_VOID
);
2177 trace_input ("stop", OP_VOID
, OP_VOID
, OP_VOID
);
2178 State
.exception
= SIGQUIT
;
2179 trace_output (OP_VOID
);
2188 trace_input ("sub", OP_REG
, OP_REG
, OP_VOID
);
2189 tmp
= (int16
)State
.regs
[OP
[0]]- (int16
)State
.regs
[OP
[1]];
2190 State
.C
= (tmp
& 0xffff0000) ? 1 : 0;
2191 State
.regs
[OP
[0]] = tmp
& 0xffff;
2192 trace_output (OP_REG
);
2201 trace_input ("sub", OP_ACCUM
, OP_DREG
, OP_VOID
);
2202 tmp
= SEXT40(State
.a
[OP
[0]]) - (SEXT16 (State
.regs
[OP
[1]]) << 16 | State
.regs
[OP
[1]+1]);
2206 State
.a
[OP
[0]] = MAX32
;
2207 else if ( tmp
< MIN32
)
2208 State
.a
[OP
[0]] = MIN32
;
2210 State
.a
[OP
[0]] = tmp
& MASK40
;
2213 State
.a
[OP
[0]] = tmp
& MASK40
;
2215 trace_output (OP_ACCUM
);
2225 trace_input ("sub", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
2226 tmp
= SEXT40(State
.a
[OP
[0]]) - SEXT40(State
.a
[OP
[1]]);
2230 State
.a
[OP
[0]] = MAX32
;
2231 else if ( tmp
< MIN32
)
2232 State
.a
[OP
[0]] = MIN32
;
2234 State
.a
[OP
[0]] = tmp
& MASK40
;
2237 State
.a
[OP
[0]] = tmp
& MASK40
;
2239 trace_output (OP_ACCUM
);
2249 trace_input ("sub2w", OP_DREG
, OP_DREG
, OP_VOID
);
2250 a
= (int32
)((State
.regs
[OP
[0]] << 16) | State
.regs
[OP
[0]+1]);
2251 b
= (int32
)((State
.regs
[OP
[1]] << 16) | State
.regs
[OP
[1]+1]);
2253 State
.C
= (tmp
& 0xffffffff00000000LL
) ? 1 : 0;
2254 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
2255 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
2256 trace_output (OP_DREG
);
2265 trace_input ("subac3", OP_DREG_OUTPUT
, OP_DREG
, OP_ACCUM
);
2266 tmp
= SEXT40 ((State
.regs
[OP
[1]] << 16) | State
.regs
[OP
[1]+1]) - SEXT40 (State
.a
[OP
[2]]);
2267 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
2268 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
2269 trace_output (OP_DREG
);
2278 trace_input ("subac3", OP_DREG_OUTPUT
, OP_ACCUM
, OP_ACCUM
);
2279 tmp
= SEXT40(State
.a
[OP
[1]]) - SEXT40(State
.a
[OP
[2]]);
2280 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
2281 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
2282 trace_output (OP_DREG
);
2291 trace_input ("subac3s", OP_DREG_OUTPUT
, OP_DREG
, OP_ACCUM
);
2292 State
.F1
= State
.F0
;
2293 tmp
= SEXT40 ((State
.regs
[OP
[1]] << 16) | State
.regs
[OP
[1]+1]) - SEXT40(State
.a
[OP
[2]]);
2296 State
.regs
[OP
[0]] = 0x7fff;
2297 State
.regs
[OP
[0]+1] = 0xffff;
2300 else if (tmp
< MIN32
)
2302 State
.regs
[OP
[0]] = 0x8000;
2303 State
.regs
[OP
[0]+1] = 0;
2308 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
2309 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
2312 trace_output (OP_DREG
);
2321 trace_input ("subac3s", OP_DREG_OUTPUT
, OP_ACCUM
, OP_ACCUM
);
2322 State
.F1
= State
.F0
;
2323 tmp
= SEXT40(State
.a
[OP
[1]]) - SEXT40(State
.a
[OP
[2]]);
2326 State
.regs
[OP
[0]] = 0x7fff;
2327 State
.regs
[OP
[0]+1] = 0xffff;
2330 else if (tmp
< MIN32
)
2332 State
.regs
[OP
[0]] = 0x8000;
2333 State
.regs
[OP
[0]+1] = 0;
2338 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
2339 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
2342 trace_output (OP_DREG
);
2353 trace_input ("subi", OP_REG
, OP_CONSTANT16
, OP_VOID
);
2354 tmp
= (int16
)State
.regs
[OP
[0]] - OP
[1];
2355 State
.C
= (tmp
& 0xffff0000) ? 1 : 0;
2356 State
.regs
[OP
[0]] = tmp
& 0xffff;
2357 trace_output (OP_REG
);
2364 trace_input ("trap", OP_CONSTANT16
, OP_REG
, OP_VOID
);
2365 trace_output (OP_VOID
);
2370 fprintf (stderr
, "Unknown trap code %d\n", OP
[0]);
2371 State
.exception
= SIGILL
;
2374 /* Trap 0 is used for simulating low-level I/O */
2376 int save_errno
= errno
;
2379 /* Registers passed to trap 0 */
2381 #define FUNC State.regs[2] /* function number, return value */
2382 #define PARM1 State.regs[3] /* optional parm 1 */
2383 #define PARM2 State.regs[4] /* optional parm 2 */
2384 #define PARM3 State.regs[5] /* optional parm 3 */
2386 /* Registers set by trap 0 */
2388 #define RETVAL State.regs[2] /* return value */
2389 #define RETERR State.regs[3] /* return error code */
2391 /* Turn a pointer in a register into a pointer into real memory. */
2393 #define MEMPTR(x) ((char *)((x) + State.imem))
2397 #if !defined(__GO32__) && !defined(_WIN32)
2405 RETVAL
= execve (MEMPTR (PARM1
), (char **) MEMPTR (PARM2
),
2406 (char **)MEMPTR (PARM3
));
2411 RETVAL
= execve (MEMPTR (PARM1
), (char **) MEMPTR (PARM2
), NULL
);
2421 RETVAL
= pipe (host_fd
);
2422 SW (buf
, host_fd
[0]);
2423 buf
+= sizeof(uint16
);
2424 SW (buf
, host_fd
[1]);
2433 RETVAL
= wait (&status
);
2442 RETVAL
= d10v_callback
->read (d10v_callback
, PARM1
, MEMPTR (PARM2
),
2449 RETVAL
= (int)d10v_callback
->write_stdout (d10v_callback
,
2450 MEMPTR (PARM2
), PARM3
);
2452 RETVAL
= (int)d10v_callback
->write (d10v_callback
, PARM1
,
2453 MEMPTR (PARM2
), PARM3
);
2458 RETVAL
= d10v_callback
->lseek (d10v_callback
, PARM1
, PARM2
, PARM3
);
2463 RETVAL
= d10v_callback
->close (d10v_callback
, PARM1
);
2468 RETVAL
= d10v_callback
->open (d10v_callback
, MEMPTR (PARM1
), PARM2
);
2473 /* EXIT - caller can look in PARM1 to work out the
2475 State
.exception
= SIGQUIT
;
2481 /* stat system call */
2483 struct stat host_stat
;
2486 RETVAL
= stat (MEMPTR (PARM1
), &host_stat
);
2490 /* The hard-coded offsets and sizes were determined by using
2491 * the D10V compiler on a test program that used struct stat.
2493 SW (buf
, host_stat
.st_dev
);
2494 SW (buf
+2, host_stat
.st_ino
);
2495 SW (buf
+4, host_stat
.st_mode
);
2496 SW (buf
+6, host_stat
.st_nlink
);
2497 SW (buf
+8, host_stat
.st_uid
);
2498 SW (buf
+10, host_stat
.st_gid
);
2499 SW (buf
+12, host_stat
.st_rdev
);
2500 SLW (buf
+16, host_stat
.st_size
);
2501 SLW (buf
+20, host_stat
.st_atime
);
2502 SLW (buf
+28, host_stat
.st_mtime
);
2503 SLW (buf
+36, host_stat
.st_ctime
);
2510 RETVAL
= chown (MEMPTR (PARM1
), PARM2
, PARM3
);
2515 RETVAL
= chmod (MEMPTR (PARM1
), PARM2
);
2520 /* Cast the second argument to void *, to avoid type mismatch
2521 if a prototype is present. */
2522 RETVAL
= utime (MEMPTR (PARM1
), (void *) MEMPTR (PARM2
));
2534 /* Trap 1 prints a string */
2536 char *fstr
= State
.regs
[2] + State
.imem
;
2537 fputs (fstr
, stdout
);
2542 /* Trap 2 calls printf */
2544 char *fstr
= State
.regs
[2] + State
.imem
;
2545 printf (fstr
, (int16
)State
.regs
[3], (int16
)State
.regs
[4], (int16
)State
.regs
[5]);
2550 /* Trap 3 writes a character */
2551 putchar (State
.regs
[2]);
2560 trace_input ("tst0i", OP_REG
, OP_CONSTANT16
, OP_VOID
);
2561 State
.F1
= State
.F0
;
2562 State
.F0
= (State
.regs
[OP
[0]] & OP
[1]) ? 1 : 0;
2563 trace_output (OP_FLAG
);
2570 trace_input ("tst1i", OP_REG
, OP_CONSTANT16
, OP_VOID
);
2571 State
.F1
= State
.F0
;
2572 State
.F0
= (~(State
.regs
[OP
[0]]) & OP
[1]) ? 1 : 0;
2573 trace_output (OP_FLAG
);
2580 trace_input ("wait", OP_VOID
, OP_VOID
, OP_VOID
);
2582 trace_output (OP_VOID
);
2589 trace_input ("xor", OP_REG
, OP_REG
, OP_VOID
);
2590 State
.regs
[OP
[0]] ^= State
.regs
[OP
[1]];
2591 trace_output (OP_REG
);
2598 trace_input ("xor3", OP_REG_OUTPUT
, OP_REG
, OP_CONSTANT16
);
2599 State
.regs
[OP
[0]] = State
.regs
[OP
[1]] ^ OP
[2];
2600 trace_output (OP_REG
);
This page took 0.083593 seconds and 4 git commands to generate.