9 unsigned int op0, op1, op2;
13 temp = (temp << 25) >> 25;
15 result = get_byte (State.mem + State.regs[30] + op2);
16 result = (result << 24) >> 24;
17 State.regs[OP[0]] = result;
24 unsigned int op0, op1, op2;
28 temp = (temp << 25) >> 25;
30 result = get_half (State.mem + State.regs[30] + op2);
31 result = (result << 16) >> 16;
32 State.regs[OP[0]] = result;
39 unsigned int op0, op1, op2;
43 temp = (temp << 25) >> 25;
45 result = get_word (State.mem + State.regs[30] + op2);
46 State.regs[OP[0]] = result;
53 unsigned int op0, op1, op2;
56 op0 = State.regs[OP[0]];
58 temp = (temp << 25) >> 25;
60 put_byte (State.mem + State.regs[30] + op1, op0);
67 unsigned int op0, op1, op2;
70 op0 = State.regs[OP[0]];
72 temp = (temp << 25) >> 25;
74 put_half (State.mem + State.regs[30] + op1, op0);
81 unsigned int op0, op1, op2;
84 op0 = State.regs[OP[0]];
86 temp = (temp << 25) >> 25;
88 put_word (State.mem + State.regs[30] + op1, op0);
95 unsigned int op0, op1, op2;
98 op0 = State.regs[OP[0]];
100 temp = (temp << 16) >> 16;
102 result = get_byte (State.mem + op0 + op2);
103 result = (result << 24) >> 24;
104 State.regs[OP[1]] = result;
111 unsigned int op0, op1, op2;
114 op0 = State.regs[OP[0]];
116 temp = (temp << 16) >> 16;
119 result = get_half (State.mem + op0 + op2);
120 result = (result << 16) >> 16;
121 State.regs[OP[1]] = result;
128 unsigned int op0, op1, op2;
131 op0 = State.regs[OP[0]];
133 temp = (temp << 16) >> 16;
136 result = get_word (State.mem + op0 + op2);
137 State.regs[OP[1]] = result;
144 unsigned int op0, op1, op2;
147 op0 = State.regs[OP[0]];
148 op1 = State.regs[OP[1]];
150 temp = (temp << 16) >> 16;
152 put_byte (State.mem + op0 + op2, op1);
159 unsigned int op0, op1, op2;
162 op0 = State.regs[OP[0]];
163 op1 = State.regs[OP[1]];
166 temp = (temp << 16) >> 16;
168 put_half (State.mem + op0 + op2, op1);
175 unsigned int op0, op1, op2;
178 op0 = State.regs[OP[0]];
179 op1 = State.regs[OP[1]];
182 temp = (temp << 16) >> 16;
184 put_word (State.mem + op0 + op2, op1);
191 unsigned int op0, psw;
194 op0 = ((signed)OP[0] << 23) >> 23;
195 psw = State.sregs[5];
197 if ((psw & PSW_OV) != 0)
207 unsigned int op0, psw;
210 op0 = ((signed)OP[0] << 23) >> 23;
211 psw = State.sregs[5];
213 if ((psw & PSW_CY) != 0)
223 unsigned int op0, psw;
226 op0 = ((signed)OP[0] << 23) >> 23;
227 psw = State.sregs[5];
229 if ((psw & PSW_Z) != 0)
239 unsigned int op0, psw;
242 op0 = ((signed)OP[0] << 23) >> 23;
243 psw = State.sregs[5];
245 if ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) != 0)
255 unsigned int op0, psw;
258 op0 = ((signed)OP[0] << 23) >> 23;
259 psw = State.sregs[5];
261 if ((psw & PSW_S) != 0)
274 op0 = ((signed)OP[0] << 23) >> 23;
282 unsigned int op0, psw;
285 op0 = ((signed)OP[0] << 23) >> 23;
286 psw = State.sregs[5];
288 if ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) != 0)
298 unsigned int op0, psw;
301 op0 = ((signed)OP[0] << 23) >> 23;
302 psw = State.sregs[5];
304 if ((((psw & PSW_Z) != 0)
305 || (((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0))) != 0)
315 unsigned int op0, psw;
318 op0 = ((signed)OP[0] << 23) >> 23;
319 psw = State.sregs[5];
321 if ((psw & PSW_OV) == 0)
331 unsigned int op0, psw;
334 op0 = ((signed)OP[0] << 23) >> 23;
335 psw = State.sregs[5];
337 if ((psw & PSW_CY) == 0)
347 unsigned int op0, psw;
350 op0 = ((signed)OP[0] << 23) >> 23;
351 psw = State.sregs[5];
353 if ((psw & PSW_Z) == 0)
363 unsigned int op0, psw;
366 op0 = ((signed)OP[0] << 23) >> 23;
367 psw = State.sregs[5];
369 if ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) == 0)
379 unsigned int op0, psw;
382 op0 = ((signed)OP[0] << 23) >> 23;
383 psw = State.sregs[5];
385 if ((psw & PSW_S) == 0)
395 unsigned int op0, psw;
398 op0 = ((signed)OP[0] << 23) >> 23;
399 psw = State.sregs[5];
401 if ((psw & PSW_SAT) != 0)
411 unsigned int op0, psw;
414 op0 = ((signed)OP[0] << 23) >> 23;
415 psw = State.sregs[5];
417 if ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) == 0)
427 unsigned int op0, psw;
430 op0 = ((signed)OP[0] << 23) >> 23;
431 psw = State.sregs[5];
433 if ((((psw & PSW_Z) != 0)
434 || (((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0))) == 0)
444 /* interp.c will bump this by +2, so correct for it here. */
445 State.pc = State.regs[OP[0]] - 2;
448 /* jarl disp22, reg */
452 unsigned int op0, opc;
456 temp = (temp << 10) >> 10;
462 /* Gross. jarl X,r0 is really jr and doesn't save its result. */
464 State.regs[OP[1]] = opc + 4;
471 unsigned int op0, op1, result, z, s, cy, ov;
473 /* Compute the result. */
474 op0 = State.regs[OP[0]];
475 op1 = State.regs[OP[1]];
478 /* Compute the condition codes. */
480 s = (result & 0x80000000);
481 cy = (result < op0 || result < op1);
482 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
483 && (op0 & 0x80000000) != (result & 0x80000000));
485 /* According to the manual, 's' is inverted if 'ov'
489 /* Store the result and condition codes. */
490 State.regs[OP[1]] = result;
491 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
492 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
493 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
496 /* add sign_extend(imm5), reg */
500 unsigned int op0, op1, result, z, s, cy, ov;
503 /* Compute the result. */
504 temp = (OP[0] & 0x1f);
505 temp = (temp << 27) >> 27;
507 op1 = State.regs[OP[1]];
510 /* Compute the condition codes. */
512 s = (result & 0x80000000);
513 cy = (result < op0 || result < op1);
514 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
515 && (op0 & 0x80000000) != (result & 0x80000000));
517 /* According to the manual, 's' is inverted if 'ov'
521 /* Store the result and condition codes. */
522 State.regs[OP[1]] = result;
523 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
524 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
525 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
528 /* addi sign_extend(imm16), reg, reg */
532 unsigned int op0, op1, result, z, s, cy, ov;
535 /* Compute the result. */
536 temp = (OP[0] & 0xffff);
537 temp = (temp << 16) >> 16;
539 op1 = State.regs[OP[1]];
542 /* Compute the condition codes. */
544 s = (result & 0x80000000);
545 cy = (result < op0 || result < op1);
546 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
547 && (op0 & 0x80000000) != (result & 0x80000000));
549 /* According to the manual, 's' is inverted if 'ov'
553 /* Store the result and condition codes. */
554 State.regs[OP[2]] = result;
555 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
556 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
557 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
564 unsigned int op0, op1, result, z, s, cy, ov;
566 /* Compute the result. */
567 op0 = State.regs[OP[0]];
568 op1 = State.regs[OP[1]];
571 /* Compute the condition codes. */
573 s = (result & 0x80000000);
575 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
576 && (op1 & 0x80000000) != (result & 0x80000000));
578 /* According to the manual, 's' is inverted if 'ov'
582 /* Store the result and condition codes. */
583 State.regs[OP[1]] = result;
584 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
585 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
586 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
589 /* subr reg1, reg2 */
593 unsigned int op0, op1, result, z, s, cy, ov;
595 /* Compute the result. */
596 op0 = State.regs[OP[0]];
597 op1 = State.regs[OP[1]];
600 /* Compute the condition codes. */
602 s = (result & 0x80000000);
604 ov = ((op0 & 0x80000000) != (op1 & 0x80000000)
605 && (op0 & 0x80000000) != (result & 0x80000000));
607 /* According to the manual, 's' is inverted if 'ov'
611 /* Store the result and condition codes. */
612 State.regs[OP[1]] = result;
613 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
614 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
615 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
618 /* mulh reg1, reg2 */
622 State.regs[OP[1]] = ((State.regs[OP[1]] & 0xffff)
623 * (State.regs[OP[0]] & 0xffff));
626 /* mulh sign_extend(imm5), reg2
634 value = (value << 27) >> 27;
636 State.regs[OP[1]] = (State.regs[OP[1]] & 0xffff) * value;
639 /* mulhi imm16, reg1, reg2 */
645 value = value & 0xffff;
647 State.regs[OP[2]] = (State.regs[OP[1]] & 0xffff) * value;
650 /* divh reg1, reg2 */
654 unsigned int op0, op1, result, z, s, cy, ov;
657 /* Compute the result. */
658 temp = State.regs[OP[0]] & 0xffff;
659 temp = (temp << 16) >> 16;
661 op1 = State.regs[OP[1]];
663 if (op0 == 0xffffffff && op1 == 0x80000000)
676 /* Compute the condition codes. */
678 s = (result & 0x80000000);
680 /* Store the result and condition codes. */
681 State.regs[OP[1]] = result;
682 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
683 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
684 | (ov ? PSW_OV : 0));
691 unsigned int op0, op1, result, z, s, cy, ov;
693 /* Compute the result. */
694 op0 = State.regs[OP[0]];
695 op1 = State.regs[OP[1]];
698 /* Compute the condition codes. */
700 s = (result & 0x80000000);
702 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
703 && (op1 & 0x80000000) != (result & 0x80000000));
705 /* Set condition codes. */
706 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
707 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
708 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
711 /* cmp sign_extend(imm5), reg */
715 unsigned int op0, op1, result, z, s, cy, ov;
718 /* Compute the result. */
720 temp = (temp << 27) >> 27;
722 op1 = State.regs[OP[1]];
725 /* Compute the condition codes. */
727 s = (result & 0x80000000);
729 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
730 && (op1 & 0x80000000) != (result & 0x80000000));
732 /* Set condition codes. */
733 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
734 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
735 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
742 /* Hack alert. We turn off a bit in op0 since we really only
744 unsigned int op0, psw, result;
747 psw = State.sregs[5];
752 result = ((psw & PSW_OV) != 0);
755 result = ((psw & PSW_CY) != 0);
758 result = ((psw & PSW_Z) != 0);
761 result = ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) != 0);
764 result = ((psw & PSW_S) != 0);
770 result = ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) != 0);
773 result = (((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0))
774 || ((psw & PSW_Z) != 0)) != 0);
777 result = ((psw & PSW_OV) == 0);
780 result = ((psw & PSW_CY) == 0);
783 result = ((psw & PSW_Z) == 0);
786 result = ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) == 0);
789 result = ((psw & PSW_S) == 0);
792 result = ((psw & PSW_SAT) != 0);
795 result = ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) == 0);
798 result = (((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0))
799 || ((psw & PSW_Z) != 0)) == 0);
803 State.regs[OP[1]] = result;
810 unsigned int op0, op1, result, z, s, cy, ov, sat;
812 /* Compute the result. */
813 op0 = State.regs[OP[0]];
814 op1 = State.regs[OP[1]];
817 /* Compute the condition codes. */
819 s = (result & 0x80000000);
820 cy = (result < op0 || result < op1);
821 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
822 && (op0 & 0x80000000) != (result & 0x80000000));
825 /* Store the result and condition codes. */
826 State.regs[OP[1]] = result;
827 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
828 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
829 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
830 | (sat ? PSW_SAT : 0));
832 /* Handle saturated results. */
834 State.regs[OP[1]] = 0x80000000;
836 State.regs[OP[1]] = 0x7fffffff;
839 /* satadd sign_extend(imm5), reg */
843 unsigned int op0, op1, result, z, s, cy, ov, sat;
847 /* Compute the result. */
848 temp = (OP[0] & 0x1f);
849 temp = (temp << 27) >> 27;
851 op1 = State.regs[OP[1]];
854 /* Compute the condition codes. */
856 s = (result & 0x80000000);
857 cy = (result < op0 || result < op1);
858 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
859 && (op0 & 0x80000000) != (result & 0x80000000));
862 /* Store the result and condition codes. */
863 State.regs[OP[1]] = result;
864 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
865 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
866 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
867 | (sat ? PSW_SAT : 0));
869 /* Handle saturated results. */
871 State.regs[OP[1]] = 0x80000000;
873 State.regs[OP[1]] = 0x7fffffff;
876 /* satsub reg1, reg2 */
880 unsigned int op0, op1, result, z, s, cy, ov, sat;
882 /* Compute the result. */
883 op0 = State.regs[OP[0]];
884 op1 = State.regs[OP[1]];
887 /* Compute the condition codes. */
889 s = (result & 0x80000000);
891 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
892 && (op1 & 0x80000000) != (result & 0x80000000));
895 /* Store the result and condition codes. */
896 State.regs[OP[1]] = result;
897 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
898 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
899 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
900 | (sat ? PSW_SAT : 0));
902 /* Handle saturated results. */
904 State.regs[OP[1]] = 0x80000000;
906 State.regs[OP[1]] = 0x7fffffff;
909 /* satsubi sign_extend(imm16), reg */
913 unsigned int op0, op1, result, z, s, cy, ov, sat;
916 /* Compute the result. */
917 temp = (OP[0] & 0xffff);
918 temp = (temp << 16) >> 16;
920 op1 = State.regs[OP[1]];
923 /* Compute the condition codes. */
925 s = (result & 0x80000000);
927 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
928 && (op1 & 0x80000000) != (result & 0x80000000));
931 /* Store the result and condition codes. */
932 State.regs[OP[1]] = result;
933 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
934 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
935 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
936 | (sat ? PSW_SAT : 0));
938 /* Handle saturated results. */
940 State.regs[OP[1]] = 0x80000000;
942 State.regs[OP[1]] = 0x7fffffff;
948 unsigned int op0, op1, result, z, s, cy, ov, sat;
950 /* Compute the result. */
951 op0 = State.regs[OP[0]];
952 op1 = State.regs[OP[1]];
955 /* Compute the condition codes. */
957 s = (result & 0x80000000);
959 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
960 && (op1 & 0x80000000) != (result & 0x80000000));
963 /* Store the result and condition codes. */
964 State.regs[OP[1]] = result;
965 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
966 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
967 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
968 | (sat ? PSW_SAT : 0));
970 /* Handle saturated results. */
972 State.regs[OP[1]] = 0x80000000;
974 State.regs[OP[1]] = 0x7fffffff;
981 unsigned int op0, op1, result, z, s, cy, ov;
983 /* Compute the result. */
984 op0 = State.regs[OP[0]];
985 op1 = State.regs[OP[1]];
988 /* Compute the condition codes. */
990 s = (result & 0x80000000);
992 /* Store the condition codes. */
993 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
994 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1001 State.regs[OP[1]] = State.regs[OP[0]];
1004 /* mov sign_extend(imm5), reg */
1010 value = (value << 27) >> 27;
1011 State.regs[OP[1]] = value;
1014 /* movea sign_extend(imm16), reg, reg */
1021 value = (value << 16) >> 16;
1023 State.regs[OP[2]] = State.regs[OP[1]] + value;
1026 /* movhi imm16, reg, reg */
1032 value = (value & 0xffff) << 16;
1034 State.regs[OP[2]] = State.regs[OP[1]] + value;
1037 /* sar zero_extend(imm5),reg1 */
1041 unsigned int op0, op1, result, z, s, cy, ov;
1044 op1 = State.regs[OP[1]];
1045 result = (signed)op1 >> op0;
1047 /* Compute the condition codes. */
1049 s = (result & 0x80000000);
1050 cy = (op1 & (1 << (op0 - 1)));
1052 /* Store the result and condition codes. */
1053 State.regs[OP[1]] = result;
1054 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1055 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1056 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
1059 /* sar reg1, reg2 */
1063 unsigned int op0, op1, result, z, s, cy, ov;
1065 op0 = State.regs[OP[0]] & 0x1f;
1066 op1 = State.regs[OP[1]];
1067 result = (signed)op1 >> op0;
1069 /* Compute the condition codes. */
1071 s = (result & 0x80000000);
1072 cy = (op1 & (1 << (op0 - 1)));
1074 /* Store the result and condition codes. */
1075 State.regs[OP[1]] = result;
1076 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1077 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1078 | (cy ? PSW_CY : 0));
1081 /* shl zero_extend(imm5),reg1 */
1085 unsigned int op0, op1, result, z, s, cy, ov;
1088 op1 = State.regs[OP[1]];
1089 result = op1 << op0;
1091 /* Compute the condition codes. */
1093 s = (result & 0x80000000);
1094 cy = (op1 & (1 << (32 - op0)));
1096 /* Store the result and condition codes. */
1097 State.regs[OP[1]] = result;
1098 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1099 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1100 | (cy ? PSW_CY : 0));
1103 /* shl reg1, reg2 */
1107 unsigned int op0, op1, result, z, s, cy, ov;
1109 op0 = State.regs[OP[0]] & 0x1f;
1110 op1 = State.regs[OP[1]];
1111 result = op1 << op0;
1113 /* Compute the condition codes. */
1115 s = (result & 0x80000000);
1116 cy = (op1 & (1 << (32 - op0)));
1118 /* Store the result and condition codes. */
1119 State.regs[OP[1]] = result;
1120 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1121 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1122 | (cy ? PSW_CY : 0));
1125 /* shr zero_extend(imm5),reg1 */
1129 unsigned int op0, op1, result, z, s, cy, ov;
1132 op1 = State.regs[OP[1]];
1133 result = op1 >> op0;
1135 /* Compute the condition codes. */
1137 s = (result & 0x80000000);
1138 cy = (op1 & (1 << (op0 - 1)));
1140 /* Store the result and condition codes. */
1141 State.regs[OP[1]] = result;
1142 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1143 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1144 | (cy ? PSW_CY : 0));
1147 /* shr reg1, reg2 */
1151 unsigned int op0, op1, result, z, s, cy, ov;
1153 op0 = State.regs[OP[0]] & 0x1f;
1154 op1 = State.regs[OP[1]];
1155 result = op1 >> op0;
1157 /* Compute the condition codes. */
1159 s = (result & 0x80000000);
1160 cy = (op1 & (1 << (op0 - 1)));
1162 /* Store the result and condition codes. */
1163 State.regs[OP[1]] = result;
1164 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1165 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1166 | (cy ? PSW_CY : 0));
1173 unsigned int op0, op1, result, z, s, cy, ov;
1175 /* Compute the result. */
1176 op0 = State.regs[OP[0]];
1177 op1 = State.regs[OP[1]];
1180 /* Compute the condition codes. */
1182 s = (result & 0x80000000);
1184 /* Store the result and condition codes. */
1185 State.regs[OP[1]] = result;
1186 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
1187 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1190 /* ori zero_extend(imm16), reg, reg */
1194 unsigned int op0, op1, result, z, s, cy, ov;
1196 op0 = OP[0] & 0xffff;
1197 op1 = State.regs[OP[1]];
1200 /* Compute the condition codes. */
1202 s = (result & 0x80000000);
1204 /* Store the result and condition codes. */
1205 State.regs[OP[2]] = result;
1206 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
1207 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1214 unsigned int op0, op1, result, z, s, cy, ov;
1216 /* Compute the result. */
1217 op0 = State.regs[OP[0]];
1218 op1 = State.regs[OP[1]];
1221 /* Compute the condition codes. */
1223 s = (result & 0x80000000);
1225 /* Store the result and condition codes. */
1226 State.regs[OP[1]] = result;
1227 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
1228 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1231 /* andi zero_extend(imm16), reg, reg */
1235 unsigned int op0, op1, result, z, s, cy, ov;
1237 op0 = OP[0] & 0xffff;
1238 op1 = State.regs[OP[1]];
1241 /* Compute the condition codes. */
1244 /* Store the result and condition codes. */
1245 State.regs[OP[2]] = result;
1246 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
1247 State.sregs[5] |= (z ? PSW_Z : 0);
1254 unsigned int op0, op1, result, z, s, cy, ov;
1256 /* Compute the result. */
1257 op0 = State.regs[OP[0]];
1258 op1 = State.regs[OP[1]];
1261 /* Compute the condition codes. */
1263 s = (result & 0x80000000);
1265 /* Store the result and condition codes. */
1266 State.regs[OP[1]] = result;
1267 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
1268 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1271 /* xori zero_extend(imm16), reg, reg */
1275 unsigned int op0, op1, result, z, s, cy, ov;
1277 op0 = OP[0] & 0xffff;
1278 op1 = State.regs[OP[1]];
1281 /* Compute the condition codes. */
1283 s = (result & 0x80000000);
1285 /* Store the result and condition codes. */
1286 State.regs[OP[2]] = result;
1287 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
1288 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1291 /* not reg1, reg2 */
1295 unsigned int op0, result, z, s, cy, ov;
1297 /* Compute the result. */
1298 op0 = State.regs[OP[0]];
1301 /* Compute the condition codes. */
1303 s = (result & 0x80000000);
1305 /* Store the result and condition codes. */
1306 State.regs[OP[1]] = result;
1307 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
1308 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1315 unsigned int op0, op1, op2;
1318 op0 = State.regs[OP[0]];
1321 temp = (temp << 16) >> 16;
1323 temp = get_byte (State.mem + op0 + op2);
1324 State.sregs[5] &= ~PSW_Z;
1325 if ((temp & (1 << op1)) == 0)
1326 State.sregs[5] |= PSW_Z;
1328 put_byte (State.mem + op0 + op2, temp);
1335 unsigned int op0, op1, op2;
1338 op0 = State.regs[OP[0]];
1341 temp = (temp << 16) >> 16;
1343 temp = get_byte (State.mem + op0 + op2);
1344 State.sregs[5] &= ~PSW_Z;
1345 if ((temp & (1 << op1)) == 0)
1346 State.sregs[5] |= PSW_Z;
1348 put_byte (State.mem + op0 + op2, temp);
1355 unsigned int op0, op1, op2;
1358 op0 = State.regs[OP[0]];
1361 temp = (temp << 16) >> 16;
1363 temp = get_byte (State.mem + op0 + op2);
1364 State.sregs[5] &= ~PSW_Z;
1365 if ((temp & (1 << op1)) == 0)
1366 State.sregs[5] |= PSW_Z;
1367 temp &= ~(1 << op1);
1368 put_byte (State.mem + op0 + op2, temp);
1375 unsigned int op0, op1, op2;
1378 op0 = State.regs[OP[0]];
1381 temp = (temp << 16) >> 16;
1383 temp = get_byte (State.mem + op0 + op2);
1384 State.sregs[5] &= ~PSW_Z;
1385 if ((temp & (1 << op1)) == 0)
1386 State.sregs[5] |= PSW_Z;
1393 State.sregs[5] |= PSW_ID;
1400 State.sregs[5] &= ~PSW_ID;
1403 /* halt, not supported */
1407 State.exception = SIGQUIT;
1410 /* reti, not supported */
1417 /* trap, not supportd */
1423 /* Trap 0 is used for simulating low-level I/O */
1428 char *fstr = State.regs[2] + State.imem;
1429 printf (fstr,State.regs[3],State.regs[4],State.regs[5]);
1431 int save_errno = errno;
1434 /* Registers passed to trap 0 */
1436 #define FUNC State.regs[6] /* function number, return value */
1437 #define PARM1 State.regs[7] /* optional parm 1 */
1438 #define PARM2 State.regs[8] /* optional parm 2 */
1439 #define PARM3 State.regs[9] /* optional parm 3 */
1441 /* Registers set by trap 0 */
1443 #define RETVAL State.regs[10] /* return value */
1444 #define RETERR State.regs[11] /* return error code */
1446 /* Turn a pointer in a register into a pointer into real memory. */
1448 #define MEMPTR(x) ((char *)((x) + State.mem))
1454 #if !defined(__GO32__) && !defined(_WIN32)
1459 RETVAL = execve (MEMPTR (PARM1), (char **) MEMPTR (PARM2),
1460 (char **)MEMPTR (PARM3));
1463 RETVAL = execve (MEMPTR (PARM1), (char **) MEMPTR (PARM2), NULL);
1471 RETVAL = pipe (host_fd);
1472 SW (buf, host_fd[0]);
1473 buf += sizeof(uint16);
1474 SW (buf, host_fd[1]);
1482 RETVAL = wait (&status);
1489 RETVAL = v850_callback->read (v850_callback, PARM1, MEMPTR (PARM2),
1495 RETVAL = (int)v850_callback->write_stdout (v850_callback,
1496 MEMPTR (PARM2), PARM3);
1498 RETVAL = (int)v850_callback->write (v850_callback, PARM1,
1499 MEMPTR (PARM2), PARM3);
1503 RETVAL = v850_callback->lseek (v850_callback, PARM1, PARM2, PARM3);
1506 RETVAL = v850_callback->close (v850_callback, PARM1);
1509 RETVAL = v850_callback->open (v850_callback, MEMPTR (PARM1), PARM2);
1513 /* EXIT - caller can look in PARM1 to work out the
1515 if (PARM1 == 0xdead || PARM1 == 0x1)
1516 State.exception = SIGABRT;
1518 State.exception = SIGQUIT;
1522 case SYS_stat: /* added at hmsi */
1523 /* stat system call */
1525 struct stat host_stat;
1528 RETVAL = stat (MEMPTR (PARM1), &host_stat);
1532 /* The hard-coded offsets and sizes were determined by using
1533 * the D10V compiler on a test program that used struct stat.
1535 SW (buf, host_stat.st_dev);
1536 SW (buf+2, host_stat.st_ino);
1537 SW (buf+4, host_stat.st_mode);
1538 SW (buf+6, host_stat.st_nlink);
1539 SW (buf+8, host_stat.st_uid);
1540 SW (buf+10, host_stat.st_gid);
1541 SW (buf+12, host_stat.st_rdev);
1542 SLW (buf+16, host_stat.st_size);
1543 SLW (buf+20, host_stat.st_atime);
1544 SLW (buf+28, host_stat.st_mtime);
1545 SLW (buf+36, host_stat.st_ctime);
1550 RETVAL = chown (MEMPTR (PARM1), PARM2, PARM3);
1553 RETVAL = chmod (MEMPTR (PARM1), PARM2);
1556 /* Cast the second argument to void *, to avoid type mismatch
1557 if a prototype is present. */
1558 RETVAL = utime (MEMPTR (PARM1), (void *) MEMPTR (PARM2));
1568 else if (OP[0] == 1 )
1570 char *fstr = State.regs[2] + State.mem;
1581 op0 = State.regs[OP[0]];
1582 State.sregs[OP[1]] = op0;
1585 /* stsr, not supported */
1591 op0 = State.sregs[OP[1]];
1592 State.regs[OP[0]] = op0;