11 printf(" abs\tr%d\n",OP[0]);
14 if ((int16)(State.regs[OP[0]]) < 0)
16 State.regs[OP[0]] = -(int16)(State.regs[OP[0]]);
30 printf(" abs\ta%d\n",OP[0]);
33 if (State.a[OP[0]] & BIT40 )
35 tmp = -State.a[OP[0]] & MASK40;
38 if ( !(tmp & BIT40) && (tmp > MAX32))
39 State.a[OP[0]] = MAX32;
40 else if ( (tmp & BIT40) && (tmp < MIN32))
41 State.a[OP[0]] = MIN32;
57 uint16 tmp = State.regs[OP[0]];
59 printf(" add\tr%d,r%d\n",OP[0],OP[1]);
61 State.regs[OP[0]] += State.regs[OP[1]];
62 if ( tmp > State.regs[OP[0]])
73 printf(" add\ta%d,r%d\n",OP[0],OP[1]);
82 printf(" add\t%x,%x\n",OP[0],OP[1]);
91 uint32 tmp1 = (State.regs[OP[0]]) << 16 | State.regs[OP[0]+1];
92 uint32 tmp2 = (State.regs[OP[1]]) << 16 | State.regs[OP[1]+1];
94 printf(" add2w\tr%d,r%d\n",OP[0],OP[1]);
97 if ( (tmp < tmp1) || (tmp < tmp2) )
101 State.regs[OP[0]] = tmp >> 16;
102 State.regs[OP[0]+1] = tmp & 0xFFFF;
109 uint16 tmp = State.regs[OP[0]];
111 printf(" add3\tr%d,r%d,0x%x\n",OP[0],OP[1],OP[2]);
113 State.regs[OP[0]] = State.regs[OP[1]] + OP[2];
114 if ( tmp > State.regs[OP[0]])
125 printf(" addac3\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
134 printf(" addac3\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
143 printf(" addac3s\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
152 printf(" addac3s\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
161 printf(" addi\tr%d,0x%x\n",OP[0],OP[1]);
163 State.regs[OP[0]] += OP[1];
171 printf(" and\tr%d,r%d\n",OP[0],OP[1]);
173 State.regs[OP[0]] &= State.regs[OP[1]];
181 printf(" and3\tr%d,r%d,0x%x\n",OP[0],OP[1],OP[2]);
183 State.regs[OP[0]] = State.regs[OP[1]] & OP[2];
191 printf(" bclri\tr%d,%d\n",OP[0],OP[1]);
193 State.regs[OP[0]] &= ~(0x8000 >> OP[1]);
201 printf(" bl.s\t0x%x\n",OP[0]);
203 State.regs[13] = PC+1;
212 printf(" bl.l\t0x%x\n",OP[0]);
214 State.regs[13] = PC+1;
223 printf(" bnoti\tr%d,%d\n",OP[0],OP[1]);
225 State.regs[OP[0]] ^= 0x8000 >> OP[1];
233 printf(" bra.s\t0x%x\n",OP[0]);
243 printf(" bra.l\t0x%x\n",OP[0]);
253 printf(" brf0f.s\t0x%x\n",OP[0]);
264 printf(" brf0f.l\t0x%x\n",OP[0]);
275 printf(" brf0t.s\t0x%x\n",OP[0]);
286 printf(" brf0t.l\t0x%x\n",OP[0]);
297 printf(" bseti\tr%d,%d\n",OP[0],OP[1]);
299 State.regs[OP[0]] |= 0x8000 >> OP[1];
307 printf(" btsti\tr%d,%d\n",OP[0],OP[1]);
310 State.F0 = (State.regs[OP[0]] & (0x8000 >> OP[1])) ? 1 : 0;
318 printf(" clrac\ta%d\n",OP[0]);
328 printf(" cmp\tr%d,r%d\n",OP[0],OP[1]);
331 State.F0 = ((int16)(State.regs[OP[0]]) < (int16)(State.regs[OP[1]])) ? 1 : 0;
339 printf(" cmp\t%x,%x\n",OP[0],OP[1]);
348 printf(" cmpeq\tr%d,r%d\n",OP[0],OP[1]);
351 State.F0 = (State.regs[OP[0]] == State.regs[OP[1]]) ? 1 : 0;
359 printf(" cmpeq\t%x,%x\n",OP[0],OP[1]);
368 printf(" cmpeqi.s\tr%d,0x%x\n",OP[0],OP[1]);
371 State.F0 = (State.regs[OP[0]] == SEXT4(OP[1])) ? 1 : 0;
379 printf(" cmpeqi.l\tr%d,0x%x\n",OP[0],OP[1]);
382 State.F0 = (State.regs[OP[0]] == OP[1]) ? 1 : 0;
390 printf(" cmpi.s\tr%d,0x%x\n",OP[0],OP[1]);
393 State.F0 = ((int16)(State.regs[OP[0]]) < SEXT4(OP[1])) ? 1 : 0;
401 printf(" cmpi.l\tr%d,0x%x\n",OP[0],OP[1]);
404 State.F0 = ((int16)(State.regs[OP[0]]) < (int16)(OP[1])) ? 1 : 0;
412 printf(" cmpu\tr%d,r%d\n",OP[0],OP[1]);
415 State.F0 = (State.regs[OP[0]] < State.regs[OP[1]]) ? 1 : 0;
423 printf(" cmpui\tr%d,0x%x\n",OP[0],OP[1]);
426 State.F0 = (State.regs[OP[0]] < OP[1]) ? 1 : 0;
435 printf(" cpfg\t%x,%x\n",OP[0],OP[1]);
466 uint16 foo, tmp, tmpf;
468 printf(" divs\tr%d,r%d\n",OP[0],OP[1]);
470 foo = (State.regs[OP[0]] << 1) | (State.regs[OP[0]+1] >> 15);
471 tmp = (int16)foo - (int16)(State.regs[OP[1]]);
472 tmpf = (foo >= State.regs[OP[1]]) ? 1 : 0;
473 State.regs[OP[0]] = (tmpf == 1) ? tmp : foo;
474 State.regs[OP[0]+1] = (State.regs[OP[0]+1] << 1) | tmpf;
484 State.exe = (State.F0) ? 0 : 1;
494 State.exe = State.F0;
504 State.exe = (State.F1) ? 0 : 1;
514 State.exe = State.F1;
524 State.exe = (State.F0 | State.F1) ? 0 : 1;
534 State.exe = (State.F0) ? 0 : (State.F1);
544 State.exe = (State.F1) ? 0 : (State.F0);
554 State.exe = (State.F0) ? (State.F1) : 0;
565 printf(" exp\tr%d,r%d\n",OP[0],OP[1]);
567 if (((int16)State.regs[OP[0]]) >= 0)
568 tmp = (State.regs[OP[0]] << 16) | State.regs[OP[0]+1];
570 tmp = ~((State.regs[OP[0]] << 16) | State.regs[OP[0]+1]);
577 State.regs[OP[0]] = i-1;
581 State.regs[OP[0]] = 16;
589 printf(" exp\t%x,%x\n",OP[0],OP[1]);
598 printf(" jl\t%x\n",OP[0]);
600 State.regs[13] = PC+1;
601 PC = State.regs[OP[0]];
609 printf(" jmp\tr%d\n",OP[0]);
611 PC = State.regs[OP[0]];
619 printf(" ld\tr%d,@(0x%x,r%d)\n",OP[0],OP[1],OP[2]);
621 State.regs[OP[0]] = RW (OP[1] + State.regs[OP[2]]);
629 printf(" ld\tr%d,@r%d-\n",OP[0],OP[1]);
631 State.regs[OP[0]] = RW (State.regs[OP[2]]);
632 State.regs[OP[1]] -= 2;
640 printf(" ld\tr%d,@r%d+\n",OP[0],OP[1]);
642 State.regs[OP[0]] = RW (State.regs[OP[2]]);
643 State.regs[OP[1]] += 2;
651 printf(" ld\tr%d,@r%d\n",OP[0],OP[1]);
653 State.regs[OP[0]] = RW (State.regs[OP[1]]);
661 printf(" ld2w\tr%d,@(0x%x,r%d)\n",OP[0],OP[1],OP[2]);
663 State.regs[OP[0]] = RW (OP[1] + State.regs[OP[2]]);
664 State.regs[OP[0]+1] = RW (OP[1] + State.regs[OP[2]] + 2);
672 printf(" ld2w\tr%d,@r%d-\n",OP[0],OP[1]);
674 State.regs[OP[0]] = RW (State.regs[OP[2]]);
675 State.regs[OP[0]+1] = RW (State.regs[OP[2]]+2);
676 State.regs[OP[1]] -= 4;
684 printf(" ld2w\tr%d,@r%d+\n",OP[0],OP[1]);
686 State.regs[OP[0]] = RW (State.regs[OP[2]]);
687 State.regs[OP[0]+1] = RW (State.regs[OP[2]]+2);
688 State.regs[OP[1]] += 4;
696 printf(" ld2w\tr%d,@r%d\n",OP[0],OP[1]);
698 State.regs[OP[0]] = RW (State.regs[OP[2]]);
699 State.regs[OP[0]+1] = RW (State.regs[OP[2]]+2);
707 printf(" ldb\tr%d,@(0x%x,r%d)\n",OP[0],OP[1],OP[2]);
709 State.regs[OP[0]] = RB (OP[1] + State.regs[OP[2]]);
710 SEXT8 (State.regs[OP[0]]);
718 printf(" ldb\tr%d,@r%d\n",OP[0],OP[1]);
720 State.regs[OP[0]] = RB (State.regs[OP[1]]);
721 SEXT8 (State.regs[OP[0]]);
729 printf(" ldi.s\tr%d,%x\n",OP[0],SEXT4(OP[1]));
731 State.regs[OP[0]] = SEXT4(OP[1]);
739 printf(" ldi.l\tr%d,%d\t;0x%x\n",OP[0],OP[1],OP[1]);
741 State.regs[OP[0]] = OP[1];
749 printf(" ldub\tr%d,@(0x%x,r%d)\n",OP[0],OP[1],OP[2]);
751 State.regs[OP[0]] = RB (OP[1] + State.regs[OP[2]]);
759 printf(" ldub\tr%d,@r%d\n",OP[0],OP[1]);
761 State.regs[OP[0]] = RB (State.regs[OP[1]]);
769 printf(" mac\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
778 printf(" macsu\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
787 printf(" macu\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
796 printf(" max\tr%d,r%d\n",OP[0],OP[1]);
799 if (State.regs[OP[1]] > State.regs[OP[0]])
801 State.regs[OP[0]] = State.regs[OP[1]];
813 printf(" max\t%x,%x\n",OP[0],OP[1]);
822 printf(" max\t%x,%x\n",OP[0],OP[1]);
831 printf(" min\tr%d,r%d\n",OP[0],OP[1]);
834 if (State.regs[OP[1]] < State.regs[OP[0]])
836 State.regs[OP[0]] = State.regs[OP[1]];
848 printf(" min\t%x,%x\n",OP[0],OP[1]);
857 printf(" min\t%x,%x\n",OP[0],OP[1]);
866 printf(" msb\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
875 printf(" msbsu\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
884 printf(" msbu\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
893 printf(" mul\tr%d,r%d\n",OP[0],OP[1]);
895 State.regs[OP[0]] *= State.regs[OP[1]];
903 printf(" mulx\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
912 printf(" mulxsu\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
921 printf(" mulxu\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
930 printf(" mv\tr%d,r%d\n",OP[0],OP[1]);
932 State.regs[OP[0]] = State.regs[OP[1]];
940 printf(" mv2w\tr%d,r%d\n",OP[0],OP[1]);
942 State.regs[OP[0]] = State.regs[OP[1]];
943 State.regs[OP[0]+1] = State.regs[OP[1]+1];
951 printf(" mv2wfac\tr%d,a%d\n",OP[0],OP[1]);
953 State.regs[OP[0]] = (State.a[OP[1]] >> 16) & 0xffff;
954 State.regs[OP[0]+1] = State.a[OP[1]] & 0xffff;
962 printf(" mv2wtac\tr%d,a%d\n",OP[0],OP[1]);
964 State.a[OP[1]] = SEXT16 (State.regs[OP[0]]) << 16 | State.regs[OP[0]+1];
972 printf(" mvac\ta%d,a%d\n",OP[0],OP[1]);
974 State.a[OP[0]] = State.a[OP[1]];
982 printf(" mvb\tr%d,r%d\n",OP[0],OP[1]);
984 State.regs[OP[0]] = SEXT8 (State.regs[OP[1]] & 0xff);
992 printf(" mvf0f\tr%d,r%d\n",OP[0],OP[1]);
995 State.regs[OP[0]] = State.regs[OP[1]];
1003 printf(" mvf0t\tr%d,r%d\n",OP[0],OP[1]);
1006 State.regs[OP[0]] = State.regs[OP[1]];
1014 printf(" mvfacg\tr%d,a%d\n",OP[0],OP[1]);
1016 State.regs[OP[0]] = (State.a[OP[1]] >> 32) & 0xff;
1024 printf(" mvfachi\tr%d,a%d\n",OP[0],OP[1]);
1026 State.regs[OP[0]] = (State.a[OP[1]] >> 16) & 0xffff;
1034 printf(" mvfaclo\tr%d,a%d\n",OP[0],OP[1]);
1036 State.regs[OP[0]] = State.a[OP[1]] & 0xffff;
1044 printf(" mvfc\tr%d,cr%d\n",OP[0],OP[1]);
1048 /* PSW is treated specially */
1050 if (State.SM) PSW |= 0x8000;
1051 if (State.EA) PSW |= 0x2000;
1052 if (State.DB) PSW |= 0x1000;
1053 if (State.IE) PSW |= 0x400;
1054 if (State.RP) PSW |= 0x200;
1055 if (State.MD) PSW |= 0x100;
1056 if (State.FX) PSW |= 0x80;
1057 if (State.ST) PSW |= 0x40;
1058 if (State.F0) PSW |= 8;
1059 if (State.F1) PSW |= 4;
1060 if (State.C) PSW |= 1;
1062 State.regs[OP[0]] = State.cregs[OP[1]];
1070 printf(" mvtacg\tr%d,a%d\n",OP[0],OP[1]);
1072 State.a[OP[1]] &= MASK32;
1073 State.a[OP[1]] |= (int64)(State.regs[OP[0]] & 0xff) << 32;
1082 printf(" mvtachi\tr%d,a%d\n",OP[0],OP[1]);
1084 tmp = State.a[OP[1]] & 0xffff;
1085 State.a[OP[1]] = SEXT16 (State.regs[OP[0]]) << 16 | tmp;
1086 printf("put 0x%llx\n",State.a[OP[1]]);
1094 printf(" mvtaclo\tr%d,a%d\n",OP[0],OP[1]);
1096 State.a[OP[1]] = SEXT16 (State.regs[OP[0]]);
1104 printf(" mvtc\tr%d,cr%d\n",OP[0],OP[1]);
1106 State.cregs[OP[1]] = State.regs[OP[0]];
1109 /* PSW is treated specially */
1110 State.SM = (PSW & 0x8000) ? 1 : 0;
1111 State.EA = (PSW & 0x2000) ? 1 : 0;
1112 State.DB = (PSW & 0x1000) ? 1 : 0;
1113 State.IE = (PSW & 0x400) ? 1 : 0;
1114 State.RP = (PSW & 0x200) ? 1 : 0;
1115 State.MD = (PSW & 0x100) ? 1 : 0;
1116 State.FX = (PSW & 0x80) ? 1 : 0;
1117 State.ST = (PSW & 0x40) ? 1 : 0;
1118 State.F0 = (PSW & 8) ? 1 : 0;
1119 State.F1 = (PSW & 4) ? 1 : 0;
1121 if (State.ST && !State.FX)
1123 fprintf (stderr,"ERROR at PC 0x%x: ST can only be set when FX is set.\n",PC<<2);
1134 printf(" mvub\tr%d,r%d\n",OP[0],OP[1]);
1136 State.regs[OP[0]] = State.regs[OP[1]] & 0xff;
1144 printf(" neg\tr%d\n",OP[0]);
1146 State.regs[OP[0]] = 0 - State.regs[OP[0]];
1155 printf(" neg\ta%d\n",OP[0]);
1157 tmp = -State.a[OP[0]] & MASK40;
1160 if ( !(tmp & BIT40) && (tmp > MAX32))
1161 State.a[OP[0]] = MAX32;
1162 else if ( (tmp & BIT40) && (tmp < MIN32))
1163 State.a[OP[0]] = MIN32;
1165 State.a[OP[0]] = tmp;
1168 State.a[OP[0]] = tmp;
1183 printf(" not\tr%d\n",OP[0]);
1185 State.regs[OP[0]] = ~(State.regs[OP[0]]);
1193 printf(" or\tr%d,r%d\n",OP[0],OP[1]);
1195 State.regs[OP[0]] |= State.regs[OP[1]];
1203 printf(" or3\tr%d,r%d,0x%x\n",OP[0],OP[1],OP[2]);
1205 State.regs[OP[0]] = State.regs[OP[1]] | OP[2];
1213 int shift = SEXT3 (OP[2]);
1215 printf(" rac\tr%d,a%d,%d\n",OP[0],OP[1],shift);
1217 State.F1 = State.F0;
1219 tmp = ((State.a[0] << 16) | (State.a[1] & 0xffff)) << shift;
1221 tmp = ((State.a[0] << 16) | (State.a[1] & 0xffff)) >> -shift;
1222 tmp = (tmp + 0x8000) & MASK44;
1223 if ( !(tmp & BIT44) && (tmp > MAX32))
1225 State.regs[OP[0]] = 0x7fff;
1226 State.regs[OP[0]+1] = 0xffff;
1229 else if ((tmp & BIT44) && (tmp < 0xfff80000000LL))
1231 State.regs[OP[0]] = 0x8000;
1232 State.regs[OP[0]+1] = 0;
1237 State.regs[OP[0]] = (tmp >> 16) & 0xffff;
1238 State.regs[OP[0]+1] = tmp & 0xffff;
1248 printf(" rachi\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
1257 printf(" rep\tr%d,0x%x\n",OP[0],OP[1]);
1261 RPT_C = State.regs[OP[0]];
1265 fprintf (stderr, "ERROR: rep with count=0 is illegal.\n");
1275 printf(" repi\t%d,0x%x\n",OP[0],OP[1]);
1283 fprintf (stderr, "ERROR: rep with count=0 is illegal.\n");
1311 printf(" sadd\t%x,%x\n",OP[0],OP[1]);
1320 printf(" setf0f\t%x\n",OP[0]);
1329 printf(" setf0t\t%x\n",OP[0]);
1347 printf(" sll\tr%d,r%d\n",OP[0],OP[1]);
1349 State.regs[OP[0]] <<= (State.regs[OP[1]] & 0xf);
1357 printf(" sll\t%x,%x\n",OP[0],OP[1]);
1366 printf(" slli\tr%d,%d\n",OP[0],OP[1]);
1368 State.regs[OP[0]] <<= OP[1];
1376 printf(" slli\t%x,%x\n",OP[0],OP[1]);
1386 printf(" slx\tr%d\n",OP[0]);
1388 State.regs[OP[0]] = (State.regs[OP[0]] << 1) | State.F0;
1396 printf(" sra\tr%d,r%d\n",OP[0],OP[1]);
1398 State.regs[OP[0]] = ((int16)(State.regs[OP[0]])) >> (State.regs[OP[1]] & 0xf);
1406 printf(" sra\t%x,%x\n",OP[0],OP[1]);
1415 printf(" srai\tr%d,%d\n",OP[0],OP[1]);
1417 State.regs[OP[0]] = ((int16)(State.regs[OP[0]])) >> OP[1];
1425 printf(" srai\t%x,%x\n",OP[0],OP[1]);
1434 printf(" srl\tr%d,r%d\n",OP[0],OP[1]);
1436 State.regs[OP[0]] >>= (State.regs[OP[1]] & 0xf);
1444 printf(" srl\t%x,%x\n",OP[0],OP[1]);
1453 printf(" srli\tr%d,%d\n",OP[0],OP[1]);
1455 State.regs[OP[0]] >>= OP[1];
1463 printf(" srli\t%x,%x\n",OP[0],OP[1]);
1473 printf(" srx\tr%d\n",OP[0]);
1475 tmp = State.F0 << 15;
1476 State.regs[OP[0]] = (State.regs[OP[0]] >> 1) | tmp;
1484 printf(" st\tr%d,@(0x%x,r%d)\n",OP[0],OP[1],OP[2]);
1486 SW (OP[1] + State.regs[OP[2]], State.regs[OP[0]]);
1494 printf(" st\tr%d,@r%d\n",OP[0],OP[1]);
1496 SW (State.regs[OP[1]], State.regs[OP[0]]);
1504 printf(" st\t%x,%x\n",OP[0],OP[1]);
1513 printf(" st\t%x,%x\n",OP[0],OP[1]);
1522 printf(" st\t%x,%x\n",OP[0],OP[1]);
1531 printf(" st2w\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
1540 printf(" st2w\t%x,%x\n",OP[0],OP[1]);
1549 printf(" st2w\t%x,%x\n",OP[0],OP[1]);
1558 printf(" st2w\t%x,%x\n",OP[0],OP[1]);
1567 printf(" st2w\t%x,%x\n",OP[0],OP[1]);
1576 printf(" stb\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
1585 printf(" stb\t%x,%x\n",OP[0],OP[1]);
1604 printf(" sub\t%x,%x\n",OP[0],OP[1]);
1613 printf(" sub2w\t%x,%x\n",OP[0],OP[1]);
1622 printf(" subac3\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
1631 printf(" subac3\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
1640 printf(" subac3s\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
1649 printf(" subac3s\t%x,%x,%x\n",OP[0],OP[1],OP[2]);
1658 printf(" subi\t%x,%x\n",OP[0],OP[1]);
1667 printf(" trap\t%d\n",OP[0]);
1670 /* for now, trap 0 is used for simulating IO */
1674 char *fstr = State.regs[2] + State.imem;
1675 printf (fstr,State.regs[3],State.regs[4],State.regs[5]);
1677 else if (OP[0] == 1 )
1679 char *fstr = State.regs[2] + State.imem;
1689 printf(" tst0i\t%x,%x\n",OP[0],OP[1]);
1698 printf(" tst1i\t%x,%x\n",OP[0],OP[1]);
1716 printf(" xor\t%x,%x\n",OP[0],OP[1]);
1725 printf(" xor3\t%x,%x,%x\n",OP[0],OP[1],OP[2]);