4 #include "sys/syscall.h"
14 temp = (temp << 25) >> 25;
16 result = get_byte (State.mem + State.regs[30] + op2);
17 result = (result << 24) >> 24;
18 State.regs[OP[0]] = result;
29 temp = (temp << 25) >> 25;
31 result = get_half (State.mem + State.regs[30] + op2);
32 result = (result << 16) >> 16;
33 State.regs[OP[0]] = result;
44 temp = (temp << 25) >> 25;
46 result = get_word (State.mem + State.regs[30] + op2);
47 State.regs[OP[0]] = result;
54 unsigned int op0, op1;
57 op0 = State.regs[OP[0]];
59 temp = (temp << 25) >> 25;
61 put_byte (State.mem + State.regs[30] + op1, op0);
68 unsigned int op0, op1;
71 op0 = State.regs[OP[0]];
73 temp = (temp << 25) >> 25;
75 put_half (State.mem + State.regs[30] + op1, op0);
82 unsigned int op0, op1;
85 op0 = State.regs[OP[0]];
87 temp = (temp << 25) >> 25;
89 put_word (State.mem + State.regs[30] + op1, op0);
96 unsigned int op0, op2;
99 op0 = State.regs[OP[0]];
101 temp = (temp << 16) >> 16;
103 result = get_byte (State.mem + op0 + op2);
104 result = (result << 24) >> 24;
105 State.regs[OP[1]] = result;
112 unsigned int op0, op2;
115 op0 = State.regs[OP[0]];
117 temp = (temp << 16) >> 16;
120 result = get_half (State.mem + op0 + op2);
121 result = (result << 16) >> 16;
122 State.regs[OP[1]] = result;
129 unsigned int op0, op2;
132 op0 = State.regs[OP[0]];
134 temp = (temp << 16) >> 16;
137 result = get_word (State.mem + op0 + op2);
138 State.regs[OP[1]] = result;
145 unsigned int op0, op1, op2;
148 op0 = State.regs[OP[0]];
149 op1 = State.regs[OP[1]];
151 temp = (temp << 16) >> 16;
153 put_byte (State.mem + op0 + op2, op1);
160 unsigned int op0, op1, op2;
163 op0 = State.regs[OP[0]];
164 op1 = State.regs[OP[1]];
167 temp = (temp << 16) >> 16;
169 put_half (State.mem + op0 + op2, op1);
176 unsigned int op0, op1, op2;
179 op0 = State.regs[OP[0]];
180 op1 = State.regs[OP[1]];
183 temp = (temp << 16) >> 16;
185 put_word (State.mem + op0 + op2, op1);
192 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;
209 op0 = ((signed)OP[0] << 23) >> 23;
210 psw = State.sregs[5];
212 if ((psw & PSW_CY) != 0)
222 unsigned int op0, psw;
224 op0 = ((signed)OP[0] << 23) >> 23;
225 psw = State.sregs[5];
227 if ((psw & PSW_Z) != 0)
237 unsigned int op0, psw;
239 op0 = ((signed)OP[0] << 23) >> 23;
240 psw = State.sregs[5];
242 if ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) != 0)
252 unsigned int op0, psw;
254 op0 = ((signed)OP[0] << 23) >> 23;
255 psw = State.sregs[5];
257 if ((psw & PSW_S) != 0)
269 op0 = ((signed)OP[0] << 23) >> 23;
277 unsigned int op0, psw;
279 op0 = ((signed)OP[0] << 23) >> 23;
280 psw = State.sregs[5];
282 if ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) != 0)
292 unsigned int op0, psw;
294 op0 = ((signed)OP[0] << 23) >> 23;
295 psw = State.sregs[5];
297 if ((((psw & PSW_Z) != 0)
298 || (((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0))) != 0)
308 unsigned int op0, psw;
310 op0 = ((signed)OP[0] << 23) >> 23;
311 psw = State.sregs[5];
313 if ((psw & PSW_OV) == 0)
323 unsigned int op0, psw;
325 op0 = ((signed)OP[0] << 23) >> 23;
326 psw = State.sregs[5];
328 if ((psw & PSW_CY) == 0)
338 unsigned int op0, psw;
340 op0 = ((signed)OP[0] << 23) >> 23;
341 psw = State.sregs[5];
343 if ((psw & PSW_Z) == 0)
353 unsigned int op0, psw;
355 op0 = ((signed)OP[0] << 23) >> 23;
356 psw = State.sregs[5];
358 if ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) == 0)
368 unsigned int op0, psw;
370 op0 = ((signed)OP[0] << 23) >> 23;
371 psw = State.sregs[5];
373 if ((psw & PSW_S) == 0)
383 unsigned int op0, psw;
385 op0 = ((signed)OP[0] << 23) >> 23;
386 psw = State.sregs[5];
388 if ((psw & PSW_SAT) != 0)
398 unsigned int op0, psw;
400 op0 = ((signed)OP[0] << 23) >> 23;
401 psw = State.sregs[5];
403 if ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) == 0)
413 unsigned int op0, psw;
415 op0 = ((signed)OP[0] << 23) >> 23;
416 psw = State.sregs[5];
418 if ((((psw & PSW_Z) != 0)
419 || (((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0))) == 0)
429 /* interp.c will bump this by +2, so correct for it here. */
430 State.pc = State.regs[OP[0]] - 2;
433 /* jarl disp22, reg */
437 unsigned int op0, opc;
441 temp = (temp << 10) >> 10;
447 /* Gross. jarl X,r0 is really jr and doesn't save its result. */
449 State.regs[OP[1]] = opc + 4;
456 unsigned int op0, op1, result, z, s, cy, ov;
458 /* Compute the result. */
459 op0 = State.regs[OP[0]];
460 op1 = State.regs[OP[1]];
463 /* Compute the condition codes. */
465 s = (result & 0x80000000);
466 cy = (result < op0 || result < op1);
467 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
468 && (op0 & 0x80000000) != (result & 0x80000000));
470 /* Store the result and condition codes. */
471 State.regs[OP[1]] = result;
472 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
473 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
474 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
477 /* add sign_extend(imm5), reg */
481 unsigned int op0, op1, result, z, s, cy, ov;
484 /* Compute the result. */
485 temp = (OP[0] & 0x1f);
486 temp = (temp << 27) >> 27;
488 op1 = State.regs[OP[1]];
491 /* Compute the condition codes. */
493 s = (result & 0x80000000);
494 cy = (result < op0 || result < op1);
495 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
496 && (op0 & 0x80000000) != (result & 0x80000000));
498 /* Store the result and condition codes. */
499 State.regs[OP[1]] = result;
500 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
501 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
502 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
505 /* addi sign_extend(imm16), reg, reg */
509 unsigned int op0, op1, result, z, s, cy, ov;
512 /* Compute the result. */
513 temp = (OP[0] & 0xffff);
514 temp = (temp << 16) >> 16;
516 op1 = State.regs[OP[1]];
519 /* Compute the condition codes. */
521 s = (result & 0x80000000);
522 cy = (result < op0 || result < op1);
523 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
524 && (op0 & 0x80000000) != (result & 0x80000000));
526 /* Store the result and condition codes. */
527 State.regs[OP[2]] = result;
528 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
529 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
530 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
537 unsigned int op0, op1, result, z, s, cy, ov;
539 /* Compute the result. */
540 op0 = State.regs[OP[0]];
541 op1 = State.regs[OP[1]];
544 /* Compute the condition codes. */
546 s = (result & 0x80000000);
548 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
549 && (op1 & 0x80000000) != (result & 0x80000000));
551 /* Store the result and condition codes. */
552 State.regs[OP[1]] = result;
553 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
554 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
555 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
558 /* subr reg1, reg2 */
562 unsigned int op0, op1, result, z, s, cy, ov;
564 /* Compute the result. */
565 op0 = State.regs[OP[0]];
566 op1 = State.regs[OP[1]];
569 /* Compute the condition codes. */
571 s = (result & 0x80000000);
573 ov = ((op0 & 0x80000000) != (op1 & 0x80000000)
574 && (op0 & 0x80000000) != (result & 0x80000000));
576 /* Store the result and condition codes. */
577 State.regs[OP[1]] = result;
578 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
579 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
580 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
583 /* mulh reg1, reg2 */
587 State.regs[OP[1]] = ((State.regs[OP[1]] & 0xffff)
588 * (State.regs[OP[0]] & 0xffff));
591 /* mulh sign_extend(imm5), reg2
599 value = (value << 27) >> 27;
601 State.regs[OP[1]] = (State.regs[OP[1]] & 0xffff) * value;
604 /* mulhi imm16, reg1, reg2 */
610 value = value & 0xffff;
612 State.regs[OP[2]] = (State.regs[OP[1]] & 0xffff) * value;
615 /* divh reg1, reg2 */
619 unsigned int op0, op1, result, ov, s, z;
622 /* Compute the result. */
623 temp = State.regs[OP[0]] & 0xffff;
624 temp = (temp << 16) >> 16;
626 op1 = State.regs[OP[1]];
628 if (op0 == 0xffffffff && op1 == 0x80000000)
644 /* Compute the condition codes. */
646 s = (result & 0x80000000);
648 /* Store the result and condition codes. */
649 State.regs[OP[1]] = result;
650 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
651 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
652 | (ov ? PSW_OV : 0));
659 unsigned int op0, op1, result, z, s, cy, ov;
661 /* Compute the result. */
662 op0 = State.regs[OP[0]];
663 op1 = State.regs[OP[1]];
666 /* Compute the condition codes. */
668 s = (result & 0x80000000);
670 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
671 && (op1 & 0x80000000) != (result & 0x80000000));
673 /* Set condition codes. */
674 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
675 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
676 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
679 /* cmp sign_extend(imm5), reg */
683 unsigned int op0, op1, result, z, s, cy, ov;
686 /* Compute the result. */
688 temp = (temp << 27) >> 27;
690 op1 = State.regs[OP[1]];
693 /* Compute the condition codes. */
695 s = (result & 0x80000000);
697 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
698 && (op1 & 0x80000000) != (result & 0x80000000));
700 /* Set condition codes. */
701 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
702 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
703 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
710 /* Hack alert. We turn off a bit in op0 since we really only
712 unsigned int op0, psw, result = 0;
715 psw = State.sregs[5];
720 result = ((psw & PSW_OV) != 0);
723 result = ((psw & PSW_CY) != 0);
726 result = ((psw & PSW_Z) != 0);
729 result = ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) != 0);
732 result = ((psw & PSW_S) != 0);
738 result = ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) != 0);
741 result = (((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0))
742 || ((psw & PSW_Z) != 0)) != 0);
745 result = ((psw & PSW_OV) == 0);
748 result = ((psw & PSW_CY) == 0);
751 result = ((psw & PSW_Z) == 0);
754 result = ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) == 0);
757 result = ((psw & PSW_S) == 0);
760 result = ((psw & PSW_SAT) != 0);
763 result = ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) == 0);
766 result = (((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0))
767 || ((psw & PSW_Z) != 0)) == 0);
771 State.regs[OP[1]] = result;
778 unsigned int op0, op1, result, z, s, cy, ov, sat;
780 /* Compute the result. */
781 op0 = State.regs[OP[0]];
782 op1 = State.regs[OP[1]];
785 /* Compute the condition codes. */
787 s = (result & 0x80000000);
788 cy = (result < op0 || result < op1);
789 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
790 && (op0 & 0x80000000) != (result & 0x80000000));
793 /* Store the result and condition codes. */
794 State.regs[OP[1]] = result;
795 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
796 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
797 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
798 | (sat ? PSW_SAT : 0));
800 /* Handle saturated results. */
802 State.regs[OP[1]] = 0x80000000;
804 State.regs[OP[1]] = 0x7fffffff;
807 /* satadd sign_extend(imm5), reg */
811 unsigned int op0, op1, result, z, s, cy, ov, sat;
815 /* Compute the result. */
816 temp = (OP[0] & 0x1f);
817 temp = (temp << 27) >> 27;
819 op1 = State.regs[OP[1]];
822 /* Compute the condition codes. */
824 s = (result & 0x80000000);
825 cy = (result < op0 || result < op1);
826 ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
827 && (op0 & 0x80000000) != (result & 0x80000000));
830 /* Store the result and condition codes. */
831 State.regs[OP[1]] = result;
832 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
833 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
834 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
835 | (sat ? PSW_SAT : 0));
837 /* Handle saturated results. */
839 State.regs[OP[1]] = 0x80000000;
841 State.regs[OP[1]] = 0x7fffffff;
844 /* satsub reg1, reg2 */
848 unsigned int op0, op1, result, z, s, cy, ov, sat;
850 /* Compute the result. */
851 op0 = State.regs[OP[0]];
852 op1 = State.regs[OP[1]];
855 /* Compute the condition codes. */
857 s = (result & 0x80000000);
859 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
860 && (op1 & 0x80000000) != (result & 0x80000000));
863 /* Store the result and condition codes. */
864 State.regs[OP[1]] = result;
865 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
866 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
867 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
868 | (sat ? PSW_SAT : 0));
870 /* Handle saturated results. */
872 State.regs[OP[1]] = 0x80000000;
874 State.regs[OP[1]] = 0x7fffffff;
877 /* satsubi sign_extend(imm16), reg */
881 unsigned int op0, op1, result, z, s, cy, ov, sat;
884 /* Compute the result. */
885 temp = (OP[0] & 0xffff);
886 temp = (temp << 16) >> 16;
888 op1 = State.regs[OP[1]];
891 /* Compute the condition codes. */
893 s = (result & 0x80000000);
895 ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
896 && (op1 & 0x80000000) != (result & 0x80000000));
899 /* Store the result and condition codes. */
900 State.regs[OP[1]] = result;
901 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
902 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
903 | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
904 | (sat ? PSW_SAT : 0));
906 /* Handle saturated results. */
908 State.regs[OP[1]] = 0x80000000;
910 State.regs[OP[1]] = 0x7fffffff;
916 unsigned int op0, op1, result, z, s, cy, ov, sat;
918 /* Compute the result. */
919 op0 = State.regs[OP[0]];
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;
949 unsigned int op0, op1, result, z, s;
951 /* Compute the result. */
952 op0 = State.regs[OP[0]];
953 op1 = State.regs[OP[1]];
956 /* Compute the condition codes. */
958 s = (result & 0x80000000);
960 /* Store the condition codes. */
961 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
962 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
969 State.regs[OP[1]] = State.regs[OP[0]];
972 /* mov sign_extend(imm5), reg */
978 value = (value << 27) >> 27;
979 State.regs[OP[1]] = value;
982 /* movea sign_extend(imm16), reg, reg */
989 value = (value << 16) >> 16;
991 State.regs[OP[2]] = State.regs[OP[1]] + value;
994 /* movhi imm16, reg, reg */
1000 value = (value & 0xffff) << 16;
1002 State.regs[OP[2]] = State.regs[OP[1]] + value;
1005 /* sar zero_extend(imm5),reg1 */
1009 unsigned int op0, op1, result, z, s, cy;
1012 op1 = State.regs[OP[1]];
1013 result = (signed)op1 >> op0;
1015 /* Compute the condition codes. */
1017 s = (result & 0x80000000);
1018 cy = (op1 & (1 << (op0 - 1)));
1020 /* Store the result and condition codes. */
1021 State.regs[OP[1]] = result;
1022 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1023 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1024 | (cy ? PSW_CY : 0));
1027 /* sar reg1, reg2 */
1031 unsigned int op0, op1, result, z, s, cy;
1033 op0 = State.regs[OP[0]] & 0x1f;
1034 op1 = State.regs[OP[1]];
1035 result = (signed)op1 >> op0;
1037 /* Compute the condition codes. */
1039 s = (result & 0x80000000);
1040 cy = (op1 & (1 << (op0 - 1)));
1042 /* Store the result and condition codes. */
1043 State.regs[OP[1]] = result;
1044 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1045 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1046 | (cy ? PSW_CY : 0));
1049 /* shl zero_extend(imm5),reg1 */
1053 unsigned int op0, op1, result, z, s, cy;
1056 op1 = State.regs[OP[1]];
1057 result = op1 << op0;
1059 /* Compute the condition codes. */
1061 s = (result & 0x80000000);
1062 cy = (op1 & (1 << (32 - op0)));
1064 /* Store the result and condition codes. */
1065 State.regs[OP[1]] = result;
1066 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1067 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1068 | (cy ? PSW_CY : 0));
1071 /* shl reg1, reg2 */
1075 unsigned int op0, op1, result, z, s, cy;
1077 op0 = State.regs[OP[0]] & 0x1f;
1078 op1 = State.regs[OP[1]];
1079 result = op1 << op0;
1081 /* Compute the condition codes. */
1083 s = (result & 0x80000000);
1084 cy = (op1 & (1 << (32 - op0)));
1086 /* Store the result and condition codes. */
1087 State.regs[OP[1]] = result;
1088 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1089 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1090 | (cy ? PSW_CY : 0));
1093 /* shr zero_extend(imm5),reg1 */
1097 unsigned int op0, op1, result, z, s, cy;
1100 op1 = State.regs[OP[1]];
1101 result = op1 >> op0;
1103 /* Compute the condition codes. */
1105 s = (result & 0x80000000);
1106 cy = (op1 & (1 << (op0 - 1)));
1108 /* Store the result and condition codes. */
1109 State.regs[OP[1]] = result;
1110 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1111 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1112 | (cy ? PSW_CY : 0));
1115 /* shr reg1, reg2 */
1119 unsigned int op0, op1, result, z, s, cy;
1121 op0 = State.regs[OP[0]] & 0x1f;
1122 op1 = State.regs[OP[1]];
1123 result = op1 >> op0;
1125 /* Compute the condition codes. */
1127 s = (result & 0x80000000);
1128 cy = (op1 & (1 << (op0 - 1)));
1130 /* Store the result and condition codes. */
1131 State.regs[OP[1]] = result;
1132 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
1133 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
1134 | (cy ? PSW_CY : 0));
1141 unsigned int op0, op1, result, z, s;
1143 /* Compute the result. */
1144 op0 = State.regs[OP[0]];
1145 op1 = State.regs[OP[1]];
1148 /* Compute the condition codes. */
1150 s = (result & 0x80000000);
1152 /* Store the result and condition codes. */
1153 State.regs[OP[1]] = result;
1154 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
1155 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1158 /* ori zero_extend(imm16), reg, reg */
1162 unsigned int op0, op1, result, z, s;
1164 op0 = OP[0] & 0xffff;
1165 op1 = State.regs[OP[1]];
1168 /* Compute the condition codes. */
1170 s = (result & 0x80000000);
1172 /* Store the result and condition codes. */
1173 State.regs[OP[2]] = result;
1174 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
1175 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1182 unsigned int op0, op1, result, z, s;
1184 /* Compute the result. */
1185 op0 = State.regs[OP[0]];
1186 op1 = State.regs[OP[1]];
1189 /* Compute the condition codes. */
1191 s = (result & 0x80000000);
1193 /* Store the result and condition codes. */
1194 State.regs[OP[1]] = result;
1195 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
1196 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1199 /* andi zero_extend(imm16), reg, reg */
1203 unsigned int op0, op1, result, z;
1205 op0 = OP[0] & 0xffff;
1206 op1 = State.regs[OP[1]];
1209 /* Compute the condition codes. */
1212 /* Store the result and condition codes. */
1213 State.regs[OP[2]] = result;
1214 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
1215 State.sregs[5] |= (z ? PSW_Z : 0);
1222 unsigned int op0, op1, result, z, s;
1224 /* Compute the result. */
1225 op0 = State.regs[OP[0]];
1226 op1 = State.regs[OP[1]];
1229 /* Compute the condition codes. */
1231 s = (result & 0x80000000);
1233 /* Store the result and condition codes. */
1234 State.regs[OP[1]] = result;
1235 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
1236 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1239 /* xori zero_extend(imm16), reg, reg */
1243 unsigned int op0, op1, result, z, s;
1245 op0 = OP[0] & 0xffff;
1246 op1 = State.regs[OP[1]];
1249 /* Compute the condition codes. */
1251 s = (result & 0x80000000);
1253 /* Store the result and condition codes. */
1254 State.regs[OP[2]] = result;
1255 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
1256 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1259 /* not reg1, reg2 */
1263 unsigned int op0, result, z, s;
1265 /* Compute the result. */
1266 op0 = State.regs[OP[0]];
1269 /* Compute the condition codes. */
1271 s = (result & 0x80000000);
1273 /* Store the result and condition codes. */
1274 State.regs[OP[1]] = result;
1275 State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
1276 State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
1283 unsigned int op0, op1, op2;
1286 op0 = State.regs[OP[0]];
1289 temp = (temp << 16) >> 16;
1291 temp = get_byte (State.mem + op0 + op2);
1292 State.sregs[5] &= ~PSW_Z;
1293 if ((temp & (1 << op1)) == 0)
1294 State.sregs[5] |= PSW_Z;
1296 put_byte (State.mem + op0 + op2, temp);
1303 unsigned int op0, op1, op2;
1306 op0 = State.regs[OP[0]];
1309 temp = (temp << 16) >> 16;
1311 temp = get_byte (State.mem + op0 + op2);
1312 State.sregs[5] &= ~PSW_Z;
1313 if ((temp & (1 << op1)) == 0)
1314 State.sregs[5] |= PSW_Z;
1316 put_byte (State.mem + op0 + op2, temp);
1323 unsigned int op0, op1, op2;
1326 op0 = State.regs[OP[0]];
1329 temp = (temp << 16) >> 16;
1331 temp = get_byte (State.mem + op0 + op2);
1332 State.sregs[5] &= ~PSW_Z;
1333 if ((temp & (1 << op1)) == 0)
1334 State.sregs[5] |= PSW_Z;
1335 temp &= ~(1 << op1);
1336 put_byte (State.mem + op0 + op2, temp);
1343 unsigned int op0, op1, op2;
1346 op0 = State.regs[OP[0]];
1349 temp = (temp << 16) >> 16;
1351 temp = get_byte (State.mem + op0 + op2);
1352 State.sregs[5] &= ~PSW_Z;
1353 if ((temp & (1 << op1)) == 0)
1354 State.sregs[5] |= PSW_Z;
1361 State.sregs[5] |= PSW_ID;
1368 State.sregs[5] &= ~PSW_ID;
1371 /* halt, not supported */
1375 State.exception = SIGQUIT;
1378 /* reti, not supported */
1385 /* trap, not supportd */
1391 /* Trap 0 is used for simulating low-level I/O */
1395 int save_errno = errno;
1398 /* Registers passed to trap 0 */
1400 #define FUNC State.regs[6] /* function number, return value */
1401 #define PARM1 State.regs[7] /* optional parm 1 */
1402 #define PARM2 State.regs[8] /* optional parm 2 */
1403 #define PARM3 State.regs[9] /* optional parm 3 */
1405 /* Registers set by trap 0 */
1407 #define RETVAL State.regs[10] /* return value */
1408 #define RETERR State.regs[11] /* return error code */
1410 /* Turn a pointer in a register into a pointer into real memory. */
1412 #define MEMPTR(x) ((char *)((x) + State.mem))
1417 #if !defined(__GO32__) && !defined(_WIN32)
1422 RETVAL = execve (MEMPTR (PARM1), (char **) MEMPTR (PARM2),
1423 (char **)MEMPTR (PARM3));
1426 RETVAL = execve (MEMPTR (PARM1), (char **) MEMPTR (PARM2), NULL);
1435 RETVAL = pipe (host_fd);
1436 SW (buf, host_fd[0]);
1437 buf += sizeof(uint16);
1438 SW (buf, host_fd[1]);
1446 RETVAL = wait (&status);
1454 RETVAL = v850_callback->read (v850_callback, PARM1, MEMPTR (PARM2),
1459 RETVAL = (int)v850_callback->write_stdout (v850_callback,
1460 MEMPTR (PARM2), PARM3);
1462 RETVAL = (int)v850_callback->write (v850_callback, PARM1,
1463 MEMPTR (PARM2), PARM3);
1466 RETVAL = v850_callback->lseek (v850_callback, PARM1, PARM2, PARM3);
1469 RETVAL = v850_callback->close (v850_callback, PARM1);
1472 RETVAL = v850_callback->open (v850_callback, MEMPTR (PARM1), PARM2);
1475 /* EXIT - caller can look in PARM1 to work out the
1477 if (PARM1 == 0xdead || PARM1 == 0x1)
1478 State.exception = SIGABRT;
1480 State.exception = SIGQUIT;
1484 case SYS_stat: /* added at hmsi */
1485 /* stat system call */
1487 struct stat host_stat;
1490 RETVAL = stat (MEMPTR (PARM1), &host_stat);
1494 /* The hard-coded offsets and sizes were determined by using
1495 * the D10V compiler on a test program that used struct stat.
1497 SW (buf, host_stat.st_dev);
1498 SW (buf+2, host_stat.st_ino);
1499 SW (buf+4, host_stat.st_mode);
1500 SW (buf+6, host_stat.st_nlink);
1501 SW (buf+8, host_stat.st_uid);
1502 SW (buf+10, host_stat.st_gid);
1503 SW (buf+12, host_stat.st_rdev);
1504 SLW (buf+16, host_stat.st_size);
1505 SLW (buf+20, host_stat.st_atime);
1506 SLW (buf+28, host_stat.st_mtime);
1507 SLW (buf+36, host_stat.st_ctime);
1513 RETVAL = chown (MEMPTR (PARM1), PARM2, PARM3);
1516 RETVAL = chmod (MEMPTR (PARM1), PARM2);
1519 /* Cast the second argument to void *, to avoid type mismatch
1520 if a prototype is present. */
1521 RETVAL = utime (MEMPTR (PARM1), (void *) MEMPTR (PARM2));
1529 else if (OP[0] == 1 )
1531 char *fstr = State.regs[2] + State.mem;
1542 op0 = State.regs[OP[0]];
1543 State.sregs[OP[1]] = op0;
1546 /* stsr, not supported */
1552 op0 = State.sregs[OP[1]];
1553 State.regs[OP[0]] = op0;