1 /* This must come before any other includes. */
5 #include "sim-signal.h"
21 #include "targ-vals.h"
23 #include "libiberty.h"
26 #if !defined(__GO32__) && !defined(_WIN32)
28 #include <sys/times.h>
32 /* This is an array of the bit positions of registers r20 .. r31 in
33 that order in a prepare/dispose instruction. */
34 int type1_regs
[12] = { 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 0, 21 };
35 /* This is an array of the bit positions of registers r16 .. r31 in
36 that order in a push/pop instruction. */
37 int type2_regs
[16] = { 3, 2, 1, 0, 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 20, 21};
38 /* This is an array of the bit positions of registers r1 .. r15 in
39 that order in a push/pop instruction. */
40 int type3_regs
[15] = { 2, 1, 0, 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 20, 21};
43 #ifndef SIZE_INSTRUCTION
44 #define SIZE_INSTRUCTION 18
48 #define SIZE_VALUES 11
52 unsigned32 trace_values
[3];
55 const char * trace_name
;
60 trace_input (char *name
, enum op_types type
, int size
)
62 if (!TRACE_ALU_P (STATE_CPU (simulator
, 0)))
67 trace_module
= TRACE_ALU_IDX
;
80 trace_values
[0] = State
.regs
[OP
[0]];
87 trace_values
[0] = State
.regs
[OP
[1]];
88 trace_values
[1] = State
.regs
[OP
[0]];
94 trace_values
[0] = SEXT5 (OP
[0]);
95 trace_values
[1] = OP
[1];
100 trace_values
[0] = SEXT5 (OP
[0]);
101 trace_num_values
= 1;
105 trace_values
[0] = State
.pc
;
106 trace_values
[1] = SEXT9 (OP
[0]);
107 trace_values
[2] = PSW
;
108 trace_num_values
= 3;
112 trace_values
[0] = OP
[1] * size
;
113 trace_values
[1] = State
.regs
[30];
114 trace_num_values
= 2;
118 trace_values
[0] = State
.regs
[OP
[0]];
119 trace_values
[1] = OP
[1] * size
;
120 trace_values
[2] = State
.regs
[30];
121 trace_num_values
= 3;
125 trace_values
[0] = EXTEND16 (OP
[2]);
126 trace_values
[1] = State
.regs
[OP
[0]];
127 trace_num_values
= 2;
131 trace_values
[0] = State
.regs
[OP
[1]];
132 trace_values
[1] = EXTEND16 (OP
[2]);
133 trace_values
[2] = State
.regs
[OP
[0]];
134 trace_num_values
= 3;
138 trace_values
[0] = SEXT22 (OP
[0]);
139 trace_values
[1] = State
.pc
;
140 trace_num_values
= 2;
144 trace_values
[0] = EXTEND16 (OP
[0]) << size
;
145 trace_values
[1] = State
.regs
[OP
[1]];
146 trace_num_values
= 2;
149 case OP_IMM16_REG_REG
:
150 trace_values
[0] = EXTEND16 (OP
[2]) << size
;
151 trace_values
[1] = State
.regs
[OP
[1]];
152 trace_num_values
= 2;
155 case OP_UIMM_REG_REG
:
156 trace_values
[0] = (OP
[0] & 0xffff) << size
;
157 trace_values
[1] = State
.regs
[OP
[1]];
158 trace_num_values
= 2;
161 case OP_UIMM16_REG_REG
:
162 trace_values
[0] = (OP
[2]) << size
;
163 trace_values
[1] = State
.regs
[OP
[1]];
164 trace_num_values
= 2;
168 trace_num_values
= 0;
172 trace_values
[0] = PSW
;
173 trace_num_values
= 1;
177 trace_num_values
= 0;
181 trace_values
[0] = State
.regs
[OP
[0]];
182 trace_num_values
= 1;
186 trace_values
[0] = State
.sregs
[OP
[1]];
187 trace_num_values
= 1;
193 trace_result (int has_result
, unsigned32 result
)
201 /* write out the values saved during the trace_input call */
204 for (i
= 0; i
< trace_num_values
; i
++)
206 sprintf (chp
, "%*s0x%.8lx", SIZE_VALUES
- 10, "",
207 (long) trace_values
[i
]);
208 chp
= strchr (chp
, '\0');
212 sprintf (chp
, "%*s", SIZE_VALUES
, "");
213 chp
= strchr (chp
, '\0');
217 /* append any result to the end of the buffer */
219 sprintf (chp
, " :: 0x%.8lx", (unsigned long) result
);
221 trace_generic (simulator
, STATE_CPU (simulator
, 0), trace_module
, "%s", buf
);
225 trace_output (enum op_types result
)
227 if (!TRACE_ALU_P (STATE_CPU (simulator
, 0)))
249 trace_result (1, State
.regs
[OP
[0]]);
253 case OP_REG_REG_MOVE
:
255 case OP_IMM_REG_MOVE
:
258 trace_result (1, State
.regs
[OP
[1]]);
262 case OP_UIMM_REG_REG
:
263 case OP_IMM16_REG_REG
:
264 case OP_UIMM16_REG_REG
:
265 trace_result (1, State
.regs
[OP
[1]]);
270 trace_result (1, State
.regs
[OP
[1]]);
276 trace_result (1, State
.sregs
[OP
[1]]);
283 /* Returns 1 if the specific condition is met, returns 0 otherwise. */
285 condition_met (unsigned code
)
287 unsigned int psw
= PSW
;
291 case 0x0: return ((psw
& PSW_OV
) != 0);
292 case 0x1: return ((psw
& PSW_CY
) != 0);
293 case 0x2: return ((psw
& PSW_Z
) != 0);
294 case 0x3: return ((((psw
& PSW_CY
) != 0) | ((psw
& PSW_Z
) != 0)) != 0);
295 case 0x4: return ((psw
& PSW_S
) != 0);
296 /*case 0x5: return 1;*/
297 case 0x6: return ((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) != 0);
298 case 0x7: return (((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) || ((psw
& PSW_Z
) != 0)) != 0);
299 case 0x8: return ((psw
& PSW_OV
) == 0);
300 case 0x9: return ((psw
& PSW_CY
) == 0);
301 case 0xa: return ((psw
& PSW_Z
) == 0);
302 case 0xb: return ((((psw
& PSW_CY
) != 0) | ((psw
& PSW_Z
) != 0)) == 0);
303 case 0xc: return ((psw
& PSW_S
) == 0);
304 case 0xd: return ((psw
& PSW_SAT
) != 0);
305 case 0xe: return ((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) == 0);
306 case 0xf: return (((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) || ((psw
& PSW_Z
) != 0)) == 0);
313 Add32 (unsigned long a1
, unsigned long a2
, int * carry
)
315 unsigned long result
= (a1
+ a2
);
317 * carry
= (result
< a1
);
323 Multiply64 (int sign
, unsigned long op0
)
334 op1
= State
.regs
[ OP
[1] ];
338 /* Compute sign of result and adjust operands if necessary. */
340 sign
= (op0
^ op1
) & 0x80000000;
342 if (((signed long) op0
) < 0)
345 if (((signed long) op1
) < 0)
349 /* We can split the 32x32 into four 16x16 operations. This ensures
350 that we do not lose precision on 32bit only hosts: */
351 lo
= ( (op0
& 0xFFFF) * (op1
& 0xFFFF));
352 mid1
= ( (op0
& 0xFFFF) * ((op1
>> 16) & 0xFFFF));
353 mid2
= (((op0
>> 16) & 0xFFFF) * (op1
& 0xFFFF));
354 hi
= (((op0
>> 16) & 0xFFFF) * ((op1
>> 16) & 0xFFFF));
356 /* We now need to add all of these results together, taking care
357 to propogate the carries from the additions: */
358 RdLo
= Add32 (lo
, (mid1
<< 16), & carry
);
360 RdLo
= Add32 (RdLo
, (mid2
<< 16), & carry
);
361 RdHi
+= (carry
+ ((mid1
>> 16) & 0xFFFF) + ((mid2
>> 16) & 0xFFFF) + hi
);
365 /* Negate result if necessary. */
369 if (RdLo
== 0xFFFFFFFF)
378 /* Don't store into register 0. */
380 State
.regs
[ OP
[1] ] = RdLo
;
382 State
.regs
[ OP
[2] >> 11 ] = RdHi
;
388 /* Read a null terminated string from memory, return in a buffer. */
391 fetch_str (SIM_DESC sd
, address_word addr
)
396 while (sim_core_read_1 (STATE_CPU (sd
, 0),
397 PC
, read_map
, addr
+ nr
) != 0)
400 buf
= NZALLOC (char, nr
+ 1);
401 sim_read (simulator
, addr
, (unsigned char *) buf
, nr
);
406 /* Read a null terminated argument vector from memory, return in a
410 fetch_argv (SIM_DESC sd
, address_word addr
)
414 char **buf
= xmalloc (max_nr
* sizeof (char*));
418 unsigned32 a
= sim_core_read_4 (STATE_CPU (sd
, 0),
419 PC
, read_map
, addr
+ nr
* 4);
421 buf
[nr
] = fetch_str (sd
, a
);
423 if (nr
== max_nr
- 1)
426 buf
= xrealloc (buf
, max_nr
* sizeof (char*));
438 trace_input ("sst.b", OP_STORE16
, 1);
440 store_mem (State
.regs
[30] + (OP
[3] & 0x7f), 1, State
.regs
[ OP
[1] ]);
442 trace_output (OP_STORE16
);
451 trace_input ("sst.h", OP_STORE16
, 2);
453 store_mem (State
.regs
[30] + ((OP
[3] & 0x7f) << 1), 2, State
.regs
[ OP
[1] ]);
455 trace_output (OP_STORE16
);
464 trace_input ("sst.w", OP_STORE16
, 4);
466 store_mem (State
.regs
[30] + ((OP
[3] & 0x7e) << 1), 4, State
.regs
[ OP
[1] ]);
468 trace_output (OP_STORE16
);
479 trace_input ("ld.b", OP_LOAD32
, 1);
481 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2]);
483 State
.regs
[ OP
[1] ] = EXTEND8 (load_mem (adr
, 1));
485 trace_output (OP_LOAD32
);
496 trace_input ("ld.h", OP_LOAD32
, 2);
498 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2]);
501 State
.regs
[ OP
[1] ] = EXTEND16 (load_mem (adr
, 2));
503 trace_output (OP_LOAD32
);
514 trace_input ("ld.w", OP_LOAD32
, 4);
516 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2] & ~1);
519 State
.regs
[ OP
[1] ] = load_mem (adr
, 4);
521 trace_output (OP_LOAD32
);
530 trace_input ("st.b", OP_STORE32
, 1);
532 store_mem (State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2]), 1, State
.regs
[ OP
[1] ]);
534 trace_output (OP_STORE32
);
545 trace_input ("st.h", OP_STORE32
, 2);
547 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2]);
550 store_mem (adr
, 2, State
.regs
[ OP
[1] ]);
552 trace_output (OP_STORE32
);
563 trace_input ("st.w", OP_STORE32
, 4);
565 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2] & ~1);
568 store_mem (adr
, 4, State
.regs
[ OP
[1] ]);
570 trace_output (OP_STORE32
);
579 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
581 trace_input ("add", OP_REG_REG
, 0);
583 /* Compute the result. */
585 op0
= State
.regs
[ OP
[0] ];
586 op1
= State
.regs
[ OP
[1] ];
590 /* Compute the condition codes. */
592 s
= (result
& 0x80000000);
593 cy
= (result
< op0
|| result
< op1
);
594 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
595 && (op0
& 0x80000000) != (result
& 0x80000000));
597 /* Store the result and condition codes. */
598 State
.regs
[OP
[1]] = result
;
599 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
600 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
601 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
602 trace_output (OP_REG_REG
);
607 /* add sign_extend(imm5), reg */
611 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
614 trace_input ("add", OP_IMM_REG
, 0);
616 /* Compute the result. */
617 temp
= SEXT5 (OP
[0]);
619 op1
= State
.regs
[OP
[1]];
622 /* Compute the condition codes. */
624 s
= (result
& 0x80000000);
625 cy
= (result
< op0
|| result
< op1
);
626 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
627 && (op0
& 0x80000000) != (result
& 0x80000000));
629 /* Store the result and condition codes. */
630 State
.regs
[OP
[1]] = result
;
631 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
632 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
633 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
634 trace_output (OP_IMM_REG
);
639 /* addi sign_extend(imm16), reg, reg */
643 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
645 trace_input ("addi", OP_IMM16_REG_REG
, 0);
647 /* Compute the result. */
649 op0
= EXTEND16 (OP
[2]);
650 op1
= State
.regs
[ OP
[0] ];
653 /* Compute the condition codes. */
655 s
= (result
& 0x80000000);
656 cy
= (result
< op0
|| result
< op1
);
657 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
658 && (op0
& 0x80000000) != (result
& 0x80000000));
660 /* Store the result and condition codes. */
661 State
.regs
[OP
[1]] = result
;
662 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
663 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
664 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
665 trace_output (OP_IMM16_REG_REG
);
674 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
676 trace_input ("sub", OP_REG_REG
, 0);
677 /* Compute the result. */
678 op0
= State
.regs
[ OP
[0] ];
679 op1
= State
.regs
[ OP
[1] ];
682 /* Compute the condition codes. */
684 s
= (result
& 0x80000000);
686 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
687 && (op1
& 0x80000000) != (result
& 0x80000000));
689 /* Store the result and condition codes. */
690 State
.regs
[OP
[1]] = result
;
691 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
692 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
693 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
694 trace_output (OP_REG_REG
);
699 /* subr reg1, reg2 */
703 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
705 trace_input ("subr", OP_REG_REG
, 0);
706 /* Compute the result. */
707 op0
= State
.regs
[ OP
[0] ];
708 op1
= State
.regs
[ OP
[1] ];
711 /* Compute the condition codes. */
713 s
= (result
& 0x80000000);
715 ov
= ((op0
& 0x80000000) != (op1
& 0x80000000)
716 && (op0
& 0x80000000) != (result
& 0x80000000));
718 /* Store the result and condition codes. */
719 State
.regs
[OP
[1]] = result
;
720 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
721 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
722 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
723 trace_output (OP_REG_REG
);
732 trace_input ("mulh", OP_REG_REG
, 0);
734 State
.regs
[ OP
[1] ] = (EXTEND16 (State
.regs
[ OP
[1] ]) * EXTEND16 (State
.regs
[ OP
[0] ]));
736 trace_output (OP_REG_REG
);
741 /* mulh sign_extend(imm5), reg2 */
745 trace_input ("mulh", OP_IMM_REG
, 0);
747 State
.regs
[ OP
[1] ] = EXTEND16 (State
.regs
[ OP
[1] ]) * SEXT5 (OP
[0]);
749 trace_output (OP_IMM_REG
);
754 /* mulhi imm16, reg1, reg2 */
758 trace_input ("mulhi", OP_IMM16_REG_REG
, 0);
760 State
.regs
[ OP
[1] ] = EXTEND16 (State
.regs
[ OP
[0] ]) * EXTEND16 (OP
[2]);
762 trace_output (OP_IMM16_REG_REG
);
771 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
773 trace_input ("cmp", OP_REG_REG_CMP
, 0);
774 /* Compute the result. */
775 op0
= State
.regs
[ OP
[0] ];
776 op1
= State
.regs
[ OP
[1] ];
779 /* Compute the condition codes. */
781 s
= (result
& 0x80000000);
783 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
784 && (op1
& 0x80000000) != (result
& 0x80000000));
786 /* Set condition codes. */
787 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
788 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
789 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
790 trace_output (OP_REG_REG_CMP
);
795 /* cmp sign_extend(imm5), reg */
799 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
802 /* Compute the result. */
803 trace_input ("cmp", OP_IMM_REG_CMP
, 0);
804 temp
= SEXT5 (OP
[0]);
806 op1
= State
.regs
[OP
[1]];
809 /* Compute the condition codes. */
811 s
= (result
& 0x80000000);
813 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
814 && (op1
& 0x80000000) != (result
& 0x80000000));
816 /* Set condition codes. */
817 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
818 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
819 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
820 trace_output (OP_IMM_REG_CMP
);
829 trace_input ("setf", OP_EX1
, 0);
831 State
.regs
[ OP
[1] ] = condition_met (OP
[0]);
833 trace_output (OP_EX1
);
842 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
844 trace_input ("satadd", OP_REG_REG
, 0);
845 /* Compute the result. */
846 op0
= State
.regs
[ OP
[0] ];
847 op1
= State
.regs
[ OP
[1] ];
850 /* Compute the condition codes. */
852 s
= (result
& 0x80000000);
853 cy
= (result
< op0
|| result
< op1
);
854 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
855 && (op0
& 0x80000000) != (result
& 0x80000000));
858 /* Handle saturated results. */
861 /* An overflow that results in a negative result implies that we
862 became too positive. */
868 /* Any other overflow must have thus been too negative. */
874 /* Store the result and condition codes. */
875 State
.regs
[OP
[1]] = result
;
876 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
877 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
878 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
879 | (sat
? PSW_SAT
: 0));
881 trace_output (OP_REG_REG
);
886 /* satadd sign_extend(imm5), reg */
890 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
894 trace_input ("satadd", OP_IMM_REG
, 0);
896 /* Compute the result. */
897 temp
= SEXT5 (OP
[0]);
899 op1
= State
.regs
[OP
[1]];
902 /* Compute the condition codes. */
904 s
= (result
& 0x80000000);
905 cy
= (result
< op0
|| result
< op1
);
906 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
907 && (op0
& 0x80000000) != (result
& 0x80000000));
910 /* Handle saturated results. */
913 /* An overflow that results in a negative result implies that we
914 became too positive. */
920 /* Any other overflow must have thus been too negative. */
926 /* Store the result and condition codes. */
927 State
.regs
[OP
[1]] = result
;
928 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
929 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
930 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
931 | (sat
? PSW_SAT
: 0));
932 trace_output (OP_IMM_REG
);
937 /* satsub reg1, reg2 */
941 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
943 trace_input ("satsub", OP_REG_REG
, 0);
945 /* Compute the result. */
946 op0
= State
.regs
[ OP
[0] ];
947 op1
= State
.regs
[ OP
[1] ];
950 /* Compute the condition codes. */
952 s
= (result
& 0x80000000);
954 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
955 && (op1
& 0x80000000) != (result
& 0x80000000));
958 /* Handle saturated results. */
961 /* An overflow that results in a negative result implies that we
962 became too positive. */
968 /* Any other overflow must have thus been too negative. */
974 /* Store the result and condition codes. */
975 State
.regs
[OP
[1]] = result
;
976 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
977 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
978 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
979 | (sat
? PSW_SAT
: 0));
981 trace_output (OP_REG_REG
);
985 /* satsubi sign_extend(imm16), reg */
989 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
992 trace_input ("satsubi", OP_IMM_REG
, 0);
994 /* Compute the result. */
995 temp
= EXTEND16 (OP
[2]);
997 op1
= State
.regs
[ OP
[0] ];
1000 /* Compute the condition codes. */
1002 s
= (result
& 0x80000000);
1004 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
1005 && (op1
& 0x80000000) != (result
& 0x80000000));
1008 /* Handle saturated results. */
1011 /* An overflow that results in a negative result implies that we
1012 became too positive. */
1013 result
= 0x7fffffff;
1018 /* Any other overflow must have thus been too negative. */
1019 result
= 0x80000000;
1024 /* Store the result and condition codes. */
1025 State
.regs
[OP
[1]] = result
;
1026 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1027 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1028 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
1029 | (sat
? PSW_SAT
: 0));
1031 trace_output (OP_IMM_REG
);
1036 /* satsubr reg,reg */
1040 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
1042 trace_input ("satsubr", OP_REG_REG
, 0);
1044 /* Compute the result. */
1045 op0
= State
.regs
[ OP
[0] ];
1046 op1
= State
.regs
[ OP
[1] ];
1049 /* Compute the condition codes. */
1051 s
= (result
& 0x80000000);
1053 ov
= ((op0
& 0x80000000) != (op1
& 0x80000000)
1054 && (op0
& 0x80000000) != (result
& 0x80000000));
1057 /* Handle saturated results. */
1060 /* An overflow that results in a negative result implies that we
1061 became too positive. */
1062 result
= 0x7fffffff;
1067 /* Any other overflow must have thus been too negative. */
1068 result
= 0x80000000;
1073 /* Store the result and condition codes. */
1074 State
.regs
[OP
[1]] = result
;
1075 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1076 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1077 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
1078 | (sat
? PSW_SAT
: 0));
1080 trace_output (OP_REG_REG
);
1089 unsigned int op0
, op1
, result
, z
, s
;
1091 trace_input ("tst", OP_REG_REG_CMP
, 0);
1093 /* Compute the result. */
1094 op0
= State
.regs
[ OP
[0] ];
1095 op1
= State
.regs
[ OP
[1] ];
1098 /* Compute the condition codes. */
1100 s
= (result
& 0x80000000);
1102 /* Store the condition codes. */
1103 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1104 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1105 trace_output (OP_REG_REG_CMP
);
1110 /* mov sign_extend(imm5), reg */
1114 int value
= SEXT5 (OP
[0]);
1116 trace_input ("mov", OP_IMM_REG_MOVE
, 0);
1118 State
.regs
[ OP
[1] ] = value
;
1120 trace_output (OP_IMM_REG_MOVE
);
1125 /* movhi imm16, reg, reg */
1129 trace_input ("movhi", OP_UIMM16_REG_REG
, 16);
1131 State
.regs
[ OP
[1] ] = State
.regs
[ OP
[0] ] + (OP
[2] << 16);
1133 trace_output (OP_UIMM16_REG_REG
);
1138 /* sar zero_extend(imm5),reg1 */
1142 unsigned int op0
, op1
, result
, z
, s
, cy
;
1144 trace_input ("sar", OP_IMM_REG
, 0);
1146 op1
= State
.regs
[ OP
[1] ];
1147 result
= (signed)op1
>> op0
;
1149 /* Compute the condition codes. */
1151 s
= (result
& 0x80000000);
1152 cy
= op0
? (op1
& (1 << (op0
- 1))) : 0;
1154 /* Store the result and condition codes. */
1155 State
.regs
[ OP
[1] ] = result
;
1156 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1157 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1158 | (cy
? PSW_CY
: 0));
1159 trace_output (OP_IMM_REG
);
1164 /* sar reg1, reg2 */
1168 unsigned int op0
, op1
, result
, z
, s
, cy
;
1170 trace_input ("sar", OP_REG_REG
, 0);
1172 op0
= State
.regs
[ OP
[0] ] & 0x1f;
1173 op1
= State
.regs
[ OP
[1] ];
1174 result
= (signed)op1
>> op0
;
1176 /* Compute the condition codes. */
1178 s
= (result
& 0x80000000);
1179 cy
= op0
? (op1
& (1 << (op0
- 1))) : 0;
1181 /* Store the result and condition codes. */
1182 State
.regs
[OP
[1]] = result
;
1183 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1184 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1185 | (cy
? PSW_CY
: 0));
1186 trace_output (OP_REG_REG
);
1191 /* shl zero_extend(imm5),reg1 */
1195 unsigned int op0
, op1
, result
, z
, s
, cy
;
1197 trace_input ("shl", OP_IMM_REG
, 0);
1199 op1
= State
.regs
[ OP
[1] ];
1200 result
= op1
<< op0
;
1202 /* Compute the condition codes. */
1204 s
= (result
& 0x80000000);
1205 cy
= op0
? (op1
& (1 << (32 - op0
))) : 0;
1207 /* Store the result and condition codes. */
1208 State
.regs
[OP
[1]] = result
;
1209 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1210 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1211 | (cy
? PSW_CY
: 0));
1212 trace_output (OP_IMM_REG
);
1217 /* shl reg1, reg2 */
1221 unsigned int op0
, op1
, result
, z
, s
, cy
;
1223 trace_input ("shl", OP_REG_REG
, 0);
1224 op0
= State
.regs
[ OP
[0] ] & 0x1f;
1225 op1
= State
.regs
[ OP
[1] ];
1226 result
= op1
<< op0
;
1228 /* Compute the condition codes. */
1230 s
= (result
& 0x80000000);
1231 cy
= op0
? (op1
& (1 << (32 - op0
))) : 0;
1233 /* Store the result and condition codes. */
1234 State
.regs
[OP
[1]] = result
;
1235 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1236 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1237 | (cy
? PSW_CY
: 0));
1238 trace_output (OP_REG_REG
);
1243 /* shr zero_extend(imm5),reg1 */
1247 unsigned int op0
, op1
, result
, z
, s
, cy
;
1249 trace_input ("shr", OP_IMM_REG
, 0);
1251 op1
= State
.regs
[ OP
[1] ];
1252 result
= op1
>> op0
;
1254 /* Compute the condition codes. */
1256 s
= (result
& 0x80000000);
1257 cy
= op0
? (op1
& (1 << (op0
- 1))) : 0;
1259 /* Store the result and condition codes. */
1260 State
.regs
[OP
[1]] = result
;
1261 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1262 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1263 | (cy
? PSW_CY
: 0));
1264 trace_output (OP_IMM_REG
);
1269 /* shr reg1, reg2 */
1273 unsigned int op0
, op1
, result
, z
, s
, cy
;
1275 trace_input ("shr", OP_REG_REG
, 0);
1276 op0
= State
.regs
[ OP
[0] ] & 0x1f;
1277 op1
= State
.regs
[ OP
[1] ];
1278 result
= op1
>> op0
;
1280 /* Compute the condition codes. */
1282 s
= (result
& 0x80000000);
1283 cy
= op0
? (op1
& (1 << (op0
- 1))) : 0;
1285 /* Store the result and condition codes. */
1286 State
.regs
[OP
[1]] = result
;
1287 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1288 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1289 | (cy
? PSW_CY
: 0));
1290 trace_output (OP_REG_REG
);
1299 unsigned int op0
, op1
, result
, z
, s
;
1301 trace_input ("or", OP_REG_REG
, 0);
1303 /* Compute the result. */
1304 op0
= State
.regs
[ OP
[0] ];
1305 op1
= State
.regs
[ OP
[1] ];
1308 /* Compute the condition codes. */
1310 s
= (result
& 0x80000000);
1312 /* Store the result and condition codes. */
1313 State
.regs
[OP
[1]] = result
;
1314 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1315 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1316 trace_output (OP_REG_REG
);
1321 /* ori zero_extend(imm16), reg, reg */
1325 unsigned int op0
, op1
, result
, z
, s
;
1327 trace_input ("ori", OP_UIMM16_REG_REG
, 0);
1329 op1
= State
.regs
[ OP
[0] ];
1332 /* Compute the condition codes. */
1334 s
= (result
& 0x80000000);
1336 /* Store the result and condition codes. */
1337 State
.regs
[OP
[1]] = result
;
1338 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1339 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1340 trace_output (OP_UIMM16_REG_REG
);
1349 unsigned int op0
, op1
, result
, z
, s
;
1351 trace_input ("and", OP_REG_REG
, 0);
1353 /* Compute the result. */
1354 op0
= State
.regs
[ OP
[0] ];
1355 op1
= State
.regs
[ OP
[1] ];
1358 /* Compute the condition codes. */
1360 s
= (result
& 0x80000000);
1362 /* Store the result and condition codes. */
1363 State
.regs
[OP
[1]] = result
;
1364 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1365 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1366 trace_output (OP_REG_REG
);
1371 /* andi zero_extend(imm16), reg, reg */
1375 unsigned int result
, z
;
1377 trace_input ("andi", OP_UIMM16_REG_REG
, 0);
1379 result
= OP
[2] & State
.regs
[ OP
[0] ];
1381 /* Compute the condition codes. */
1384 /* Store the result and condition codes. */
1385 State
.regs
[ OP
[1] ] = result
;
1387 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1388 PSW
|= (z
? PSW_Z
: 0);
1390 trace_output (OP_UIMM16_REG_REG
);
1399 unsigned int op0
, op1
, result
, z
, s
;
1401 trace_input ("xor", OP_REG_REG
, 0);
1403 /* Compute the result. */
1404 op0
= State
.regs
[ OP
[0] ];
1405 op1
= State
.regs
[ OP
[1] ];
1408 /* Compute the condition codes. */
1410 s
= (result
& 0x80000000);
1412 /* Store the result and condition codes. */
1413 State
.regs
[OP
[1]] = result
;
1414 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1415 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1416 trace_output (OP_REG_REG
);
1421 /* xori zero_extend(imm16), reg, reg */
1425 unsigned int op0
, op1
, result
, z
, s
;
1427 trace_input ("xori", OP_UIMM16_REG_REG
, 0);
1429 op1
= State
.regs
[ OP
[0] ];
1432 /* Compute the condition codes. */
1434 s
= (result
& 0x80000000);
1436 /* Store the result and condition codes. */
1437 State
.regs
[OP
[1]] = result
;
1438 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1439 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1440 trace_output (OP_UIMM16_REG_REG
);
1445 /* not reg1, reg2 */
1449 unsigned int op0
, result
, z
, s
;
1451 trace_input ("not", OP_REG_REG_MOVE
, 0);
1452 /* Compute the result. */
1453 op0
= State
.regs
[ OP
[0] ];
1456 /* Compute the condition codes. */
1458 s
= (result
& 0x80000000);
1460 /* Store the result and condition codes. */
1461 State
.regs
[OP
[1]] = result
;
1462 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1463 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1464 trace_output (OP_REG_REG_MOVE
);
1473 unsigned int op0
, op1
, op2
;
1476 trace_input ("set1", OP_BIT
, 0);
1477 op0
= State
.regs
[ OP
[0] ];
1479 temp
= EXTEND16 (OP
[2]);
1481 temp
= load_mem (op0
+ op2
, 1);
1483 if ((temp
& (1 << op1
)) == 0)
1486 store_mem (op0
+ op2
, 1, temp
);
1487 trace_output (OP_BIT
);
1496 unsigned int op0
, op1
, op2
;
1499 trace_input ("not1", OP_BIT
, 0);
1500 op0
= State
.regs
[ OP
[0] ];
1502 temp
= EXTEND16 (OP
[2]);
1504 temp
= load_mem (op0
+ op2
, 1);
1506 if ((temp
& (1 << op1
)) == 0)
1509 store_mem (op0
+ op2
, 1, temp
);
1510 trace_output (OP_BIT
);
1519 unsigned int op0
, op1
, op2
;
1522 trace_input ("clr1", OP_BIT
, 0);
1523 op0
= State
.regs
[ OP
[0] ];
1525 temp
= EXTEND16 (OP
[2]);
1527 temp
= load_mem (op0
+ op2
, 1);
1529 if ((temp
& (1 << op1
)) == 0)
1531 temp
&= ~(1 << op1
);
1532 store_mem (op0
+ op2
, 1, temp
);
1533 trace_output (OP_BIT
);
1542 unsigned int op0
, op1
, op2
;
1545 trace_input ("tst1", OP_BIT
, 0);
1546 op0
= State
.regs
[ OP
[0] ];
1548 temp
= EXTEND16 (OP
[2]);
1550 temp
= load_mem (op0
+ op2
, 1);
1552 if ((temp
& (1 << op1
)) == 0)
1554 trace_output (OP_BIT
);
1563 trace_input ("di", OP_NONE
, 0);
1565 trace_output (OP_NONE
);
1574 trace_input ("ei", OP_NONE
, 0);
1576 trace_output (OP_NONE
);
1585 trace_input ("halt", OP_NONE
, 0);
1586 /* FIXME this should put processor into a mode where NMI still handled */
1587 trace_output (OP_NONE
);
1588 sim_engine_halt (simulator
, STATE_CPU (simulator
, 0), NULL
, PC
,
1589 sim_stopped
, SIM_SIGTRAP
);
1597 trace_input ("trap", OP_TRAP
, 0);
1598 trace_output (OP_TRAP
);
1600 /* Trap 31 is used for simulating OS I/O functions */
1604 int save_errno
= errno
;
1607 /* Registers passed to trap 0 */
1609 #define FUNC State.regs[6] /* function number, return value */
1610 #define PARM1 State.regs[7] /* optional parm 1 */
1611 #define PARM2 State.regs[8] /* optional parm 2 */
1612 #define PARM3 State.regs[9] /* optional parm 3 */
1614 /* Registers set by trap 0 */
1616 #define RETVAL State.regs[10] /* return value */
1617 #define RETERR State.regs[11] /* return error code */
1619 /* Turn a pointer in a register into a pointer into real memory. */
1621 #define MEMPTR(x) (map (x))
1629 #ifdef TARGET_SYS_fork
1630 case TARGET_SYS_fork
:
1638 #ifdef TARGET_SYS_execv
1639 case TARGET_SYS_execve
:
1641 char *path
= fetch_str (simulator
, PARM1
);
1642 char **argv
= fetch_argv (simulator
, PARM2
);
1643 char **envp
= fetch_argv (simulator
, PARM3
);
1644 RETVAL
= execve (path
, (void *)argv
, (void *)envp
);
1655 #ifdef TARGET_SYS_execv
1656 case TARGET_SYS_execv
:
1658 char *path
= fetch_str (simulator
, PARM1
);
1659 char **argv
= fetch_argv (simulator
, PARM2
);
1660 RETVAL
= execv (path
, (void *)argv
);
1670 #ifdef TARGET_SYS_pipe
1671 case TARGET_SYS_pipe
:
1677 RETVAL
= pipe (host_fd
);
1678 SW (buf
, host_fd
[0]);
1679 buf
+= sizeof (uint16
);
1680 SW (buf
, host_fd
[1]);
1688 #ifdef TARGET_SYS_wait
1689 case TARGET_SYS_wait
:
1693 RETVAL
= wait (&status
);
1701 #ifdef TARGET_SYS_read
1702 case TARGET_SYS_read
:
1704 char *buf
= zalloc (PARM3
);
1705 RETVAL
= sim_io_read (simulator
, PARM1
, buf
, PARM3
);
1706 sim_write (simulator
, PARM2
, (unsigned char *) buf
, PARM3
);
1708 if ((int) RETVAL
< 0)
1709 RETERR
= sim_io_get_errno (simulator
);
1714 #ifdef TARGET_SYS_write
1715 case TARGET_SYS_write
:
1717 char *buf
= zalloc (PARM3
);
1718 sim_read (simulator
, PARM2
, (unsigned char *) buf
, PARM3
);
1720 RETVAL
= sim_io_write_stdout (simulator
, buf
, PARM3
);
1722 RETVAL
= sim_io_write (simulator
, PARM1
, buf
, PARM3
);
1724 if ((int) RETVAL
< 0)
1725 RETERR
= sim_io_get_errno (simulator
);
1730 #ifdef TARGET_SYS_lseek
1731 case TARGET_SYS_lseek
:
1732 RETVAL
= sim_io_lseek (simulator
, PARM1
, PARM2
, PARM3
);
1733 if ((int) RETVAL
< 0)
1734 RETERR
= sim_io_get_errno (simulator
);
1738 #ifdef TARGET_SYS_close
1739 case TARGET_SYS_close
:
1740 RETVAL
= sim_io_close (simulator
, PARM1
);
1741 if ((int) RETVAL
< 0)
1742 RETERR
= sim_io_get_errno (simulator
);
1746 #ifdef TARGET_SYS_open
1747 case TARGET_SYS_open
:
1749 char *buf
= fetch_str (simulator
, PARM1
);
1750 RETVAL
= sim_io_open (simulator
, buf
, PARM2
);
1752 if ((int) RETVAL
< 0)
1753 RETERR
= sim_io_get_errno (simulator
);
1758 #ifdef TARGET_SYS_exit
1759 case TARGET_SYS_exit
:
1760 if ((PARM1
& 0xffff0000) == 0xdead0000 && (PARM1
& 0xffff) != 0)
1761 /* get signal encoded by kill */
1762 sim_engine_halt (simulator
, STATE_CPU (simulator
, 0), NULL
, PC
,
1763 sim_signalled
, PARM1
& 0xffff);
1764 else if (PARM1
== 0xdead)
1766 sim_engine_halt (simulator
, STATE_CPU (simulator
, 0), NULL
, PC
,
1767 sim_stopped
, SIM_SIGABRT
);
1769 /* PARM1 has exit status */
1770 sim_engine_halt (simulator
, STATE_CPU (simulator
, 0), NULL
, PC
,
1775 #ifdef TARGET_SYS_stat
1776 case TARGET_SYS_stat
: /* added at hmsi */
1777 /* stat system call */
1779 struct stat host_stat
;
1781 char *path
= fetch_str (simulator
, PARM1
);
1783 RETVAL
= sim_io_stat (simulator
, path
, &host_stat
);
1788 /* Just wild-assed guesses. */
1789 store_mem (buf
, 2, host_stat
.st_dev
);
1790 store_mem (buf
+ 2, 2, host_stat
.st_ino
);
1791 store_mem (buf
+ 4, 4, host_stat
.st_mode
);
1792 store_mem (buf
+ 8, 2, host_stat
.st_nlink
);
1793 store_mem (buf
+ 10, 2, host_stat
.st_uid
);
1794 store_mem (buf
+ 12, 2, host_stat
.st_gid
);
1795 store_mem (buf
+ 14, 2, host_stat
.st_rdev
);
1796 store_mem (buf
+ 16, 4, host_stat
.st_size
);
1797 store_mem (buf
+ 20, 4, host_stat
.st_atime
);
1798 store_mem (buf
+ 28, 4, host_stat
.st_mtime
);
1799 store_mem (buf
+ 36, 4, host_stat
.st_ctime
);
1801 if ((int) RETVAL
< 0)
1802 RETERR
= sim_io_get_errno (simulator
);
1807 #ifdef TARGET_SYS_fstat
1808 case TARGET_SYS_fstat
:
1809 /* fstat system call */
1811 struct stat host_stat
;
1814 RETVAL
= sim_io_fstat (simulator
, PARM1
, &host_stat
);
1818 /* Just wild-assed guesses. */
1819 store_mem (buf
, 2, host_stat
.st_dev
);
1820 store_mem (buf
+ 2, 2, host_stat
.st_ino
);
1821 store_mem (buf
+ 4, 4, host_stat
.st_mode
);
1822 store_mem (buf
+ 8, 2, host_stat
.st_nlink
);
1823 store_mem (buf
+ 10, 2, host_stat
.st_uid
);
1824 store_mem (buf
+ 12, 2, host_stat
.st_gid
);
1825 store_mem (buf
+ 14, 2, host_stat
.st_rdev
);
1826 store_mem (buf
+ 16, 4, host_stat
.st_size
);
1827 store_mem (buf
+ 20, 4, host_stat
.st_atime
);
1828 store_mem (buf
+ 28, 4, host_stat
.st_mtime
);
1829 store_mem (buf
+ 36, 4, host_stat
.st_ctime
);
1831 if ((int) RETVAL
< 0)
1832 RETERR
= sim_io_get_errno (simulator
);
1837 #ifdef TARGET_SYS_rename
1838 case TARGET_SYS_rename
:
1840 char *oldpath
= fetch_str (simulator
, PARM1
);
1841 char *newpath
= fetch_str (simulator
, PARM2
);
1842 RETVAL
= sim_io_rename (simulator
, oldpath
, newpath
);
1845 if ((int) RETVAL
< 0)
1846 RETERR
= sim_io_get_errno (simulator
);
1851 #ifdef TARGET_SYS_unlink
1852 case TARGET_SYS_unlink
:
1854 char *path
= fetch_str (simulator
, PARM1
);
1855 RETVAL
= sim_io_unlink (simulator
, path
);
1857 if ((int) RETVAL
< 0)
1858 RETERR
= sim_io_get_errno (simulator
);
1863 #ifdef TARGET_SYS_chown
1864 case TARGET_SYS_chown
:
1866 char *path
= fetch_str (simulator
, PARM1
);
1867 RETVAL
= chown (path
, PARM2
, PARM3
);
1875 #ifdef TARGET_SYS_chmod
1876 case TARGET_SYS_chmod
:
1878 char *path
= fetch_str (simulator
, PARM1
);
1879 RETVAL
= chmod (path
, PARM2
);
1887 #ifdef TARGET_SYS_time
1889 case TARGET_SYS_time
:
1892 RETVAL
= time (&now
);
1893 store_mem (PARM1
, 4, now
);
1900 #if !defined(__GO32__) && !defined(_WIN32)
1901 #ifdef TARGET_SYS_times
1902 case TARGET_SYS_times
:
1905 RETVAL
= times (&tms
);
1906 store_mem (PARM1
, 4, tms
.tms_utime
);
1907 store_mem (PARM1
+ 4, 4, tms
.tms_stime
);
1908 store_mem (PARM1
+ 8, 4, tms
.tms_cutime
);
1909 store_mem (PARM1
+ 12, 4, tms
.tms_cstime
);
1916 #ifdef TARGET_SYS_gettimeofday
1917 #if !defined(__GO32__) && !defined(_WIN32)
1918 case TARGET_SYS_gettimeofday
:
1922 RETVAL
= gettimeofday (&t
, &tz
);
1923 store_mem (PARM1
, 4, t
.tv_sec
);
1924 store_mem (PARM1
+ 4, 4, t
.tv_usec
);
1925 store_mem (PARM2
, 4, tz
.tz_minuteswest
);
1926 store_mem (PARM2
+ 4, 4, tz
.tz_dsttime
);
1933 #ifdef TARGET_SYS_utime
1935 case TARGET_SYS_utime
:
1937 /* Cast the second argument to void *, to avoid type mismatch
1938 if a prototype is present. */
1939 sim_io_error (simulator
, "Utime not supported");
1940 /* RETVAL = utime (path, (void *) MEMPTR (PARM2)); */
1954 { /* Trap 0 -> 30 */
1959 ECR
|= 0x40 + OP
[0];
1960 /* Flag that we are now doing exception processing. */
1961 PSW
|= PSW_EP
| PSW_ID
;
1962 PC
= (OP
[0] < 0x10) ? 0x40 : 0x50;
1968 /* tst1 reg2, [reg1] */
1974 trace_input ("tst1", OP_BIT
, 1);
1976 temp
= load_mem (State
.regs
[ OP
[0] ], 1);
1979 if ((temp
& (1 << (State
.regs
[ OP
[1] ] & 0x7))) == 0)
1982 trace_output (OP_BIT
);
1987 /* mulu reg1, reg2, reg3 */
1991 trace_input ("mulu", OP_REG_REG_REG
, 0);
1993 Multiply64 (0, State
.regs
[ OP
[0] ]);
1995 trace_output (OP_REG_REG_REG
);
2000 #define BIT_CHANGE_OP( name, binop ) \
2002 unsigned int temp; \
2004 trace_input (name, OP_BIT_CHANGE, 0); \
2006 bit = 1 << (State.regs[ OP[1] ] & 0x7); \
2007 temp = load_mem (State.regs[ OP[0] ], 1); \
2010 if ((temp & bit) == 0) \
2014 store_mem (State.regs[ OP[0] ], 1, temp); \
2016 trace_output (OP_BIT_CHANGE); \
2020 /* clr1 reg2, [reg1] */
2024 BIT_CHANGE_OP ("clr1", &= ~ );
2027 /* not1 reg2, [reg1] */
2031 BIT_CHANGE_OP ("not1", ^= );
2038 BIT_CHANGE_OP ("set1", |= );
2045 trace_input ("sasf", OP_EX1
, 0);
2047 State
.regs
[ OP
[1] ] = (State
.regs
[ OP
[1] ] << 1) | condition_met (OP
[0]);
2049 trace_output (OP_EX1
);
2054 /* This function is courtesy of Sugimoto at NEC, via Seow Tan
2055 (Soew_Tan@el.nec.com) */
2060 unsigned long int als
,
2061 unsigned long int sfi
,
2062 unsigned32
/*unsigned long int*/ * quotient_ptr
,
2063 unsigned32
/*unsigned long int*/ * remainder_ptr
,
2067 unsigned long ald
= sfi
>> (N
- 1);
2068 unsigned long alo
= als
;
2073 unsigned int R1
= 1;
2074 unsigned int DBZ
= (als
== 0) ? 1 : 0;
2075 unsigned long alt
= Q
? ~als
: als
;
2078 alo
= ald
+ alt
+ Q
;
2079 C
= (((alt
>> 31) & (ald
>> 31))
2080 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2083 R1
= (alo
== 0) ? 0 : (R1
& Q
);
2084 if ((S
^ (alo
>>31)) && !C
)
2089 sfi
= (sfi
<< (32-N
+1)) | Q
;
2090 ald
= (alo
<< 1) | (sfi
>> 31);
2092 /* 2nd - N-1th Loop */
2093 for (i
= 2; i
< N
; i
++)
2095 alt
= Q
? ~als
: als
;
2096 alo
= ald
+ alt
+ Q
;
2097 C
= (((alt
>> 31) & (ald
>> 31))
2098 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2101 R1
= (alo
== 0) ? 0 : (R1
& Q
);
2102 if ((S
^ (alo
>>31)) && !C
&& !DBZ
)
2107 sfi
= (sfi
<< 1) | Q
;
2108 ald
= (alo
<< 1) | (sfi
>> 31);
2112 alt
= Q
? ~als
: als
;
2113 alo
= ald
+ alt
+ Q
;
2114 C
= (((alt
>> 31) & (ald
>> 31))
2115 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2118 R1
= (alo
== 0) ? 0 : (R1
& Q
);
2119 if ((S
^ (alo
>>31)) && !C
)
2124 * quotient_ptr
= (sfi
<< 1) | Q
;
2125 * remainder_ptr
= Q
? alo
: (alo
+ als
);
2126 * overflow_ptr
= DBZ
| R1
;
2129 /* This function is courtesy of Sugimoto at NEC, via Seow Tan (Soew_Tan@el.nec.com) */
2134 unsigned long int als
,
2135 unsigned long int sfi
,
2136 signed32
/*signed long int*/ * quotient_ptr
,
2137 signed32
/*signed long int*/ * remainder_ptr
,
2141 unsigned long ald
= (signed long) sfi
>> (N
- 1);
2142 unsigned long alo
= als
;
2143 unsigned int SS
= als
>> 31;
2144 unsigned int SD
= sfi
>> 31;
2145 unsigned int R1
= 1;
2147 unsigned int DBZ
= als
== 0 ? 1 : 0;
2148 unsigned int Q
= ~(SS
^ SD
) & 1;
2152 unsigned long alt
= Q
? ~als
: als
;
2157 alo
= ald
+ alt
+ Q
;
2158 C
= (((alt
>> 31) & (ald
>> 31))
2159 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2161 R1
= (alo
== 0) ? 0 : (R1
& (Q
^ (SS
^ SD
)));
2163 sfi
= (sfi
<< (32-N
+1)) | Q
;
2164 ald
= (alo
<< 1) | (sfi
>> 31);
2165 if ((alo
>> 31) ^ (ald
>> 31))
2170 /* 2nd - N-1th Loop */
2172 for (i
= 2; i
< N
; i
++)
2174 alt
= Q
? ~als
: als
;
2175 alo
= ald
+ alt
+ Q
;
2176 C
= (((alt
>> 31) & (ald
>> 31))
2177 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2179 R1
= (alo
== 0) ? 0 : (R1
& (Q
^ (SS
^ SD
)));
2181 sfi
= (sfi
<< 1) | Q
;
2182 ald
= (alo
<< 1) | (sfi
>> 31);
2183 if ((alo
>> 31) ^ (ald
>> 31))
2190 alt
= Q
? ~als
: als
;
2191 alo
= ald
+ alt
+ Q
;
2192 C
= (((alt
>> 31) & (ald
>> 31))
2193 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2195 R1
= (alo
== 0) ? 0 : (R1
& (Q
^ (SS
^ SD
)));
2196 sfi
= (sfi
<< (32-N
+1));
2202 alt
= Q
? ~als
: als
;
2203 alo
= ald
+ alt
+ Q
;
2205 R1
= R1
& ((~alo
>> 31) ^ SD
);
2206 if ((alo
!= 0) && ((Q
^ (SS
^ SD
)) ^ R1
)) alo
= ald
;
2208 ald
= sfi
= (long) ((sfi
>> 1) | (SS
^ SD
) << 31) >> (32-N
-1) | Q
;
2210 ald
= sfi
= sfi
| Q
;
2212 OV
= DBZ
| ((alo
== 0) ? 0 : R1
);
2214 * remainder_ptr
= alo
;
2217 if (((alo
!= 0) && ((SS
^ SD
) ^ R1
))
2218 || ((alo
== 0) && (SS
^ R1
)))
2223 OV
= (DBZ
| R1
) ? OV
: ((alo
>> 31) & (~ald
>> 31));
2225 * quotient_ptr
= alo
;
2226 * overflow_ptr
= OV
;
2229 /* sdivun imm5, reg1, reg2, reg3 */
2233 unsigned32
/*unsigned long int*/ quotient
;
2234 unsigned32
/*unsigned long int*/ remainder
;
2235 unsigned long int divide_by
;
2236 unsigned long int divide_this
;
2240 trace_input ("sdivun", OP_IMM_REG_REG_REG
, 0);
2242 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2244 divide_by
= State
.regs
[ OP
[0] ];
2245 divide_this
= State
.regs
[ OP
[1] ] << imm5
;
2247 divun (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2249 State
.regs
[ OP
[1] ] = quotient
;
2250 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2252 /* Set condition codes. */
2253 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2255 if (overflow
) PSW
|= PSW_OV
;
2256 if (quotient
== 0) PSW
|= PSW_Z
;
2257 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2259 trace_output (OP_IMM_REG_REG_REG
);
2264 /* sdivn imm5, reg1, reg2, reg3 */
2268 signed32
/*signed long int*/ quotient
;
2269 signed32
/*signed long int*/ remainder
;
2270 signed long int divide_by
;
2271 signed long int divide_this
;
2275 trace_input ("sdivn", OP_IMM_REG_REG_REG
, 0);
2277 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2279 divide_by
= (signed32
) State
.regs
[ OP
[0] ];
2280 divide_this
= (signed32
) (State
.regs
[ OP
[1] ] << imm5
);
2282 divn (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2284 State
.regs
[ OP
[1] ] = quotient
;
2285 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2287 /* Set condition codes. */
2288 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2290 if (overflow
) PSW
|= PSW_OV
;
2291 if (quotient
== 0) PSW
|= PSW_Z
;
2292 if (quotient
< 0) PSW
|= PSW_S
;
2294 trace_output (OP_IMM_REG_REG_REG
);
2299 /* sdivhun imm5, reg1, reg2, reg3 */
2303 unsigned32
/*unsigned long int*/ quotient
;
2304 unsigned32
/*unsigned long int*/ remainder
;
2305 unsigned long int divide_by
;
2306 unsigned long int divide_this
;
2310 trace_input ("sdivhun", OP_IMM_REG_REG_REG
, 0);
2312 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2314 divide_by
= State
.regs
[ OP
[0] ] & 0xffff;
2315 divide_this
= State
.regs
[ OP
[1] ] << imm5
;
2317 divun (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2319 State
.regs
[ OP
[1] ] = quotient
;
2320 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2322 /* Set condition codes. */
2323 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2325 if (overflow
) PSW
|= PSW_OV
;
2326 if (quotient
== 0) PSW
|= PSW_Z
;
2327 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2329 trace_output (OP_IMM_REG_REG_REG
);
2334 /* sdivhn imm5, reg1, reg2, reg3 */
2338 signed32
/*signed long int*/ quotient
;
2339 signed32
/*signed long int*/ remainder
;
2340 signed long int divide_by
;
2341 signed long int divide_this
;
2345 trace_input ("sdivhn", OP_IMM_REG_REG_REG
, 0);
2347 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2349 divide_by
= EXTEND16 (State
.regs
[ OP
[0] ]);
2350 divide_this
= (signed32
) (State
.regs
[ OP
[1] ] << imm5
);
2352 divn (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2354 State
.regs
[ OP
[1] ] = quotient
;
2355 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2357 /* Set condition codes. */
2358 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2360 if (overflow
) PSW
|= PSW_OV
;
2361 if (quotient
== 0) PSW
|= PSW_Z
;
2362 if (quotient
< 0) PSW
|= PSW_S
;
2364 trace_output (OP_IMM_REG_REG_REG
);
2369 /* divu reg1, reg2, reg3 */
2373 unsigned long int quotient
;
2374 unsigned long int remainder
;
2375 unsigned long int divide_by
;
2376 unsigned long int divide_this
;
2379 trace_input ("divu", OP_REG_REG_REG
, 0);
2381 /* Compute the result. */
2383 divide_by
= State
.regs
[ OP
[0] ];
2384 divide_this
= State
.regs
[ OP
[1] ];
2392 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
2393 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
2395 /* Set condition codes. */
2396 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2398 if (overflow
) PSW
|= PSW_OV
;
2399 if (quotient
== 0) PSW
|= PSW_Z
;
2400 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2403 trace_output (OP_REG_REG_REG
);
2408 /* div reg1, reg2, reg3 */
2412 signed long int quotient
;
2413 signed long int remainder
;
2414 signed long int divide_by
;
2415 signed long int divide_this
;
2417 trace_input ("div", OP_REG_REG_REG
, 0);
2419 /* Compute the result. */
2421 divide_by
= (signed32
) State
.regs
[ OP
[0] ];
2422 divide_this
= State
.regs
[ OP
[1] ];
2428 else if (divide_by
== -1 && divide_this
== (1L << 31))
2431 PSW
|= PSW_OV
| PSW_S
;
2432 State
.regs
[ OP
[1] ] = (1 << 31);
2433 State
.regs
[ OP
[2] >> 11 ] = 0;
2437 divide_this
= (signed32
) divide_this
;
2438 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
2439 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
2441 /* Set condition codes. */
2442 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2444 if (quotient
== 0) PSW
|= PSW_Z
;
2445 if (quotient
< 0) PSW
|= PSW_S
;
2448 trace_output (OP_REG_REG_REG
);
2453 /* divhu reg1, reg2, reg3 */
2457 unsigned long int quotient
;
2458 unsigned long int remainder
;
2459 unsigned long int divide_by
;
2460 unsigned long int divide_this
;
2463 trace_input ("divhu", OP_REG_REG_REG
, 0);
2465 /* Compute the result. */
2467 divide_by
= State
.regs
[ OP
[0] ] & 0xffff;
2468 divide_this
= State
.regs
[ OP
[1] ];
2476 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
2477 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
2479 /* Set condition codes. */
2480 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2482 if (overflow
) PSW
|= PSW_OV
;
2483 if (quotient
== 0) PSW
|= PSW_Z
;
2484 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2487 trace_output (OP_REG_REG_REG
);
2492 /* divh reg1, reg2, reg3 */
2496 signed long int quotient
;
2497 signed long int remainder
;
2498 signed long int divide_by
;
2499 signed long int divide_this
;
2502 trace_input ("divh", OP_REG_REG_REG
, 0);
2504 /* Compute the result. */
2506 divide_by
= EXTEND16 (State
.regs
[ OP
[0] ]);
2507 divide_this
= State
.regs
[ OP
[1] ];
2513 else if (divide_by
== -1 && divide_this
== (1L << 31))
2516 PSW
|= PSW_OV
| PSW_S
;
2517 State
.regs
[ OP
[1] ] = (1 << 31);
2518 State
.regs
[ OP
[2] >> 11 ] = 0;
2522 divide_this
= (signed32
) divide_this
;
2523 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
2524 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
2526 /* Set condition codes. */
2527 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2529 if (quotient
== 0) PSW
|= PSW_Z
;
2530 if (quotient
< 0) PSW
|= PSW_S
;
2533 trace_output (OP_REG_REG_REG
);
2538 /* mulu imm9, reg2, reg3 */
2542 trace_input ("mulu", OP_IMM_REG_REG
, 0);
2544 Multiply64 (0, (OP
[3] & 0x1f) | ((OP
[3] >> 13) & 0x1e0));
2546 trace_output (OP_IMM_REG_REG
);
2551 /* mul imm9, reg2, reg3 */
2555 trace_input ("mul", OP_IMM_REG_REG
, 0);
2557 Multiply64 (1, SEXT9 ((OP
[3] & 0x1f) | ((OP
[3] >> 13) & 0x1e0)));
2559 trace_output (OP_IMM_REG_REG
);
2570 trace_input ("ld.hu", OP_LOAD32
, 2);
2572 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2] & ~1);
2575 State
.regs
[ OP
[1] ] = load_mem (adr
, 2);
2577 trace_output (OP_LOAD32
);
2589 trace_input ("ld.bu", OP_LOAD32
, 1);
2591 adr
= (State
.regs
[ OP
[0] ]
2592 + (EXTEND16 (OP
[2] & ~1) | ((OP
[3] >> 5) & 1)));
2594 State
.regs
[ OP
[1] ] = load_mem (adr
, 1);
2596 trace_output (OP_LOAD32
);
2601 /* prepare list12, imm5, imm32 */
2607 trace_input ("prepare", OP_PUSHPOP1
, 0);
2609 /* Store the registers with lower number registers being placed at higher addresses. */
2610 for (i
= 0; i
< 12; i
++)
2611 if ((OP
[3] & (1 << type1_regs
[ i
])))
2614 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
2617 SP
-= (OP
[3] & 0x3e) << 1;
2619 EP
= load_mem (PC
+ 4, 4);
2621 trace_output (OP_PUSHPOP1
);
2626 /* prepare list12, imm5, imm16-32 */
2632 trace_input ("prepare", OP_PUSHPOP1
, 0);
2634 /* Store the registers with lower number registers being placed at higher addresses. */
2635 for (i
= 0; i
< 12; i
++)
2636 if ((OP
[3] & (1 << type1_regs
[ i
])))
2639 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
2642 SP
-= (OP
[3] & 0x3e) << 1;
2644 EP
= load_mem (PC
+ 4, 2) << 16;
2646 trace_output (OP_PUSHPOP1
);
2651 /* prepare list12, imm5, imm16 */
2657 trace_input ("prepare", OP_PUSHPOP1
, 0);
2659 /* Store the registers with lower number registers being placed at higher addresses. */
2660 for (i
= 0; i
< 12; i
++)
2661 if ((OP
[3] & (1 << type1_regs
[ i
])))
2664 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
2667 SP
-= (OP
[3] & 0x3e) << 1;
2669 EP
= EXTEND16 (load_mem (PC
+ 4, 2));
2671 trace_output (OP_PUSHPOP1
);
2676 /* prepare list12, imm5, sp */
2682 trace_input ("prepare", OP_PUSHPOP1
, 0);
2684 /* Store the registers with lower number registers being placed at higher addresses. */
2685 for (i
= 0; i
< 12; i
++)
2686 if ((OP
[3] & (1 << type1_regs
[ i
])))
2689 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
2692 SP
-= (OP
[3] & 0x3e) << 1;
2696 trace_output (OP_PUSHPOP1
);
2701 /* mul reg1, reg2, reg3 */
2705 trace_input ("mul", OP_REG_REG_REG
, 0);
2707 Multiply64 (1, State
.regs
[ OP
[0] ]);
2709 trace_output (OP_REG_REG_REG
);
2720 trace_input ("popmh", OP_PUSHPOP2
, 0);
2722 if (OP
[3] & (1 << 19))
2724 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
2726 FEPSW
= load_mem ( SP
& ~ 3, 4);
2727 FEPC
= load_mem ((SP
+ 4) & ~ 3, 4);
2731 EIPSW
= load_mem ( SP
& ~ 3, 4);
2732 EIPC
= load_mem ((SP
+ 4) & ~ 3, 4);
2738 /* Load the registers with lower number registers being retrieved from higher addresses. */
2740 if ((OP
[3] & (1 << type2_regs
[ i
])))
2742 State
.regs
[ i
+ 16 ] = load_mem (SP
& ~ 3, 4);
2746 trace_output (OP_PUSHPOP2
);
2757 trace_input ("popml", OP_PUSHPOP3
, 0);
2759 if (OP
[3] & (1 << 19))
2761 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
2763 FEPSW
= load_mem ( SP
& ~ 3, 4);
2764 FEPC
= load_mem ((SP
+ 4) & ~ 3, 4);
2768 EIPSW
= load_mem ( SP
& ~ 3, 4);
2769 EIPC
= load_mem ((SP
+ 4) & ~ 3, 4);
2775 if (OP
[3] & (1 << 3))
2777 PSW
= load_mem (SP
& ~ 3, 4);
2781 /* Load the registers with lower number registers being retrieved from higher addresses. */
2783 if ((OP
[3] & (1 << type3_regs
[ i
])))
2785 State
.regs
[ i
+ 1 ] = load_mem (SP
& ~ 3, 4);
2789 trace_output (OP_PUSHPOP2
);
2800 trace_input ("pushmh", OP_PUSHPOP2
, 0);
2802 /* Store the registers with lower number registers being placed at higher addresses. */
2803 for (i
= 0; i
< 16; i
++)
2804 if ((OP
[3] & (1 << type2_regs
[ i
])))
2807 store_mem (SP
& ~ 3, 4, State
.regs
[ i
+ 16 ]);
2810 if (OP
[3] & (1 << 19))
2814 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
2816 store_mem ((SP
+ 4) & ~ 3, 4, FEPC
);
2817 store_mem ( SP
& ~ 3, 4, FEPSW
);
2821 store_mem ((SP
+ 4) & ~ 3, 4, EIPC
);
2822 store_mem ( SP
& ~ 3, 4, EIPSW
);
2826 trace_output (OP_PUSHPOP2
);
2831 /* V850E2R FPU functions */
2833 sim_fpu_status_invalid_snan = 1, -V--- (sim spec.)
2834 sim_fpu_status_invalid_qnan = 2, ----- (sim spec.)
2835 sim_fpu_status_invalid_isi = 4, (inf - inf) -V---
2836 sim_fpu_status_invalid_idi = 8, (inf / inf) -V---
2837 sim_fpu_status_invalid_zdz = 16, (0 / 0) -V---
2838 sim_fpu_status_invalid_imz = 32, (inf * 0) -V---
2839 sim_fpu_status_invalid_cvi = 64, convert to integer -V---
2840 sim_fpu_status_invalid_div0 = 128, (X / 0) --Z--
2841 sim_fpu_status_invalid_cmp = 256, compare ----- (sim spec.)
2842 sim_fpu_status_invalid_sqrt = 512, -V---
2843 sim_fpu_status_rounded = 1024, I----
2844 sim_fpu_status_inexact = 2048, I---- (sim spec.)
2845 sim_fpu_status_overflow = 4096, I--O-
2846 sim_fpu_status_underflow = 8192, I---U
2847 sim_fpu_status_denorm = 16384, ----U (sim spec.)
2851 update_fpsr (SIM_DESC sd
, sim_fpu_status status
, unsigned int mask
, unsigned int double_op_p
)
2853 unsigned int fpsr
= FPSR
& mask
;
2855 unsigned int flags
= 0;
2858 && ((status
& (sim_fpu_status_rounded
2859 | sim_fpu_status_overflow
2860 | sim_fpu_status_inexact
))
2861 || (status
& sim_fpu_status_underflow
2862 && (fpsr
& (FPSR_XEU
| FPSR_XEI
)) == 0
2863 && fpsr
& FPSR_FS
)))
2865 flags
|= FPSR_XCI
| FPSR_XPI
;
2869 && (status
& (sim_fpu_status_invalid_isi
2870 | sim_fpu_status_invalid_imz
2871 | sim_fpu_status_invalid_zdz
2872 | sim_fpu_status_invalid_idi
2873 | sim_fpu_status_invalid_cvi
2874 | sim_fpu_status_invalid_sqrt
2875 | sim_fpu_status_invalid_snan
)))
2877 flags
|= FPSR_XCV
| FPSR_XPV
;
2881 && (status
& sim_fpu_status_invalid_div0
))
2883 flags
|= FPSR_XCV
| FPSR_XPV
;
2887 && (status
& sim_fpu_status_overflow
))
2889 flags
|= FPSR_XCO
| FPSR_XPO
;
2892 if (((fpsr
& FPSR_XEU
) || (fpsr
& FPSR_FS
) == 0)
2893 && (status
& (sim_fpu_status_underflow
2894 | sim_fpu_status_denorm
)))
2896 flags
|= FPSR_XCU
| FPSR_XPU
;
2904 SignalExceptionFPE (sd
, double_op_p
);
2911 SignalException (SIM_DESC sd
)
2915 PSW
= PSW
& ~(PSW_NPV
| PSW_DMP
| PSW_IMP
);
2920 SignalExceptionFPE (SIM_DESC sd
, unsigned int double_op_p
)
2922 if (((PSW
& (PSW_NP
|PSW_ID
)) == 0)
2923 || !(FPSR
& (double_op_p
? FPSR_DEM
: FPSR_SEM
)))
2927 EIIC
= (FPSR
& (double_op_p
? FPSR_DEM
: FPSR_SEM
))
2929 PSW
|= (PSW_EP
| PSW_ID
);
2932 SignalException (sd
);
2937 check_invalid_snan (SIM_DESC sd
, sim_fpu_status status
, unsigned int double_op_p
)
2939 if ((FPSR
& FPSR_XEI
)
2940 && (status
& sim_fpu_status_invalid_snan
))
2945 SignalExceptionFPE (sd
, double_op_p
);
2950 v850_float_compare (SIM_DESC sd
, int cmp
, sim_fpu wop1
, sim_fpu wop2
, int double_op_p
)
2954 if (sim_fpu_is_nan (&wop1
) || sim_fpu_is_nan (&wop2
))
2958 if (FPSR
& FPSR_XEV
)
2960 FPSR
|= FPSR_XCV
| FPSR_XPV
;
2961 SignalExceptionFPE (sd
, double_op_p
);
3019 else if (sim_fpu_is_infinity (&wop1
) && sim_fpu_is_infinity (&wop2
)
3020 && sim_fpu_sign (&wop1
) == sim_fpu_sign (&wop2
))
3078 int gt
= 0,lt
= 0,eq
= 0, status
;
3080 status
= sim_fpu_cmp (&wop1
, &wop2
);
3084 case SIM_FPU_IS_SNAN
:
3085 case SIM_FPU_IS_QNAN
:
3089 case SIM_FPU_IS_NINF
:
3092 case SIM_FPU_IS_PINF
:
3095 case SIM_FPU_IS_NNUMBER
:
3098 case SIM_FPU_IS_PNUMBER
:
3101 case SIM_FPU_IS_NDENORM
:
3104 case SIM_FPU_IS_PDENORM
:
3107 case SIM_FPU_IS_NZERO
:
3108 case SIM_FPU_IS_PZERO
:
3166 ASSERT (result
!= -1);
3171 v850_div (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
, unsigned int *op3p
)
3173 signed long int quotient
;
3174 signed long int remainder
;
3175 signed long int divide_by
;
3176 signed long int divide_this
;
3177 bfd_boolean overflow
= FALSE
;
3179 /* Compute the result. */
3183 if (divide_by
== 0 || (divide_by
== -1 && divide_this
== (1 << 31)))
3189 quotient
= divide_this
/ divide_by
;
3190 remainder
= divide_this
% divide_by
;
3192 /* Set condition codes. */
3193 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3195 if (overflow
) PSW
|= PSW_OV
;
3196 if (quotient
== 0) PSW
|= PSW_Z
;
3197 if (quotient
< 0) PSW
|= PSW_S
;
3204 v850_divu (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
, unsigned int *op3p
)
3206 unsigned long int quotient
;
3207 unsigned long int remainder
;
3208 unsigned long int divide_by
;
3209 unsigned long int divide_this
;
3210 bfd_boolean overflow
= FALSE
;
3212 /* Compute the result. */
3223 quotient
= divide_this
/ divide_by
;
3224 remainder
= divide_this
% divide_by
;
3226 /* Set condition codes. */
3227 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3229 if (overflow
) PSW
|= PSW_OV
;
3230 if (quotient
== 0) PSW
|= PSW_Z
;
3231 if (quotient
& 0x80000000) PSW
|= PSW_S
;
3238 v850_sar (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3240 unsigned int result
, z
, s
, cy
;
3243 result
= (signed)op1
>> op0
;
3245 /* Compute the condition codes. */
3247 s
= (result
& 0x80000000);
3248 cy
= (op1
& (1 << (op0
- 1)));
3250 /* Store the result and condition codes. */
3251 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
3252 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3253 | (cy
? PSW_CY
: 0));
3259 v850_shl (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3261 unsigned int result
, z
, s
, cy
;
3264 result
= op1
<< op0
;
3266 /* Compute the condition codes. */
3268 s
= (result
& 0x80000000);
3269 cy
= (op1
& (1 << (32 - op0
)));
3271 /* Store the result and condition codes. */
3272 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
3273 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3274 | (cy
? PSW_CY
: 0));
3280 v850_rotl (SIM_DESC sd
, unsigned int amount
, unsigned int src
, unsigned int * dest
)
3282 unsigned int result
, z
, s
, cy
;
3285 result
= src
<< amount
;
3286 result
|= src
>> (32 - amount
);
3288 /* Compute the condition codes. */
3290 s
= (result
& 0x80000000);
3291 cy
= ! (result
& 1);
3293 /* Store the result and condition codes. */
3294 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
3295 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3296 | (cy
? PSW_CY
: 0));
3302 v850_bins (SIM_DESC sd
, unsigned int source
, unsigned int lsb
, unsigned int msb
,
3303 unsigned int * dest
)
3306 unsigned int result
, pos
, width
;
3310 width
= (msb
- lsb
) + 1;
3312 mask
= ~ (-(1 << width
));
3315 result
= (* dest
) & ~ mask
;
3316 result
|= source
<< pos
;
3318 /* Compute the condition codes. */
3320 s
= result
& 0x80000000;
3322 /* Store the result and condition codes. */
3323 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3324 PSW
|= (z
? PSW_Z
: 0) | (s
? PSW_S
: 0);
3330 v850_shr (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3332 unsigned int result
, z
, s
, cy
;
3335 result
= op1
>> op0
;
3337 /* Compute the condition codes. */
3339 s
= (result
& 0x80000000);
3340 cy
= (op1
& (1 << (op0
- 1)));
3342 /* Store the result and condition codes. */
3343 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
3344 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3345 | (cy
? PSW_CY
: 0));
3351 v850_satadd (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3353 unsigned int result
, z
, s
, cy
, ov
, sat
;
3357 /* Compute the condition codes. */
3359 s
= (result
& 0x80000000);
3360 cy
= (result
< op0
|| result
< op1
);
3361 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
3362 && (op0
& 0x80000000) != (result
& 0x80000000));
3365 /* Store the result and condition codes. */
3366 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
3367 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3368 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
3369 | (sat
? PSW_SAT
: 0));
3371 /* Handle saturated results. */
3374 result
= 0x7fffffff;
3379 result
= 0x80000000;
3387 v850_satsub (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3389 unsigned int result
, z
, s
, cy
, ov
, sat
;
3391 /* Compute the result. */
3394 /* Compute the condition codes. */
3396 s
= (result
& 0x80000000);
3398 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
3399 && (op1
& 0x80000000) != (result
& 0x80000000));
3402 /* Store the result and condition codes. */
3403 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
3404 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3405 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
3406 | (sat
? PSW_SAT
: 0));
3408 /* Handle saturated results. */
3411 result
= 0x7fffffff;
3416 result
= 0x80000000;
3424 load_data_mem (SIM_DESC sd
,
3433 data
= sim_core_read_unaligned_1 (STATE_CPU (sd
, 0),
3434 PC
, read_map
, addr
);
3437 data
= sim_core_read_unaligned_2 (STATE_CPU (sd
, 0),
3438 PC
, read_map
, addr
);
3441 data
= sim_core_read_unaligned_4 (STATE_CPU (sd
, 0),
3442 PC
, read_map
, addr
);
3451 store_data_mem (SIM_DESC sd
,
3459 store_mem (addr
, 1, data
);
3462 store_mem (addr
, 2, data
);
3465 store_mem (addr
, 4, data
);
3473 mpu_load_mem_test (SIM_DESC sd
, unsigned int addr
, int size
, int base_reg
)
3479 if (IPE0
&& addr
>= IPA2ADDR (IPA0L
) && addr
<= IPA2ADDR (IPA0L
) && IPR0
)
3483 else if (IPE1
&& addr
>= IPA2ADDR (IPA1L
) && addr
<= IPA2ADDR (IPA1L
) && IPR1
)
3487 else if (IPE2
&& addr
>= IPA2ADDR (IPA2L
) && addr
<= IPA2ADDR (IPA2L
) && IPR2
)
3491 else if (IPE3
&& addr
>= IPA2ADDR (IPA3L
) && addr
<= IPA2ADDR (IPA3L
) && IPR3
)
3495 else if (addr
>= PPA2ADDR (PPA
& ~PPM
) && addr
<= DPA2ADDR (PPA
| PPM
))
3497 /* preifarallel area */
3499 else if (addr
>= PPA2ADDR (SPAL
) && addr
<= DPA2ADDR (SPAU
))
3503 else if (DPE0
&& addr
>= DPA2ADDR (DPA0L
) && addr
<= DPA2ADDR (DPA0L
) && DPR0
3504 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3508 else if (DPE1
&& addr
>= DPA2ADDR (DPA1L
) && addr
<= DPA2ADDR (DPA1L
) && DPR1
3509 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3513 else if (DPE2
&& addr
>= DPA2ADDR (DPA2L
) && addr
<= DPA2ADDR (DPA2L
) && DPR2
3514 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3518 else if (DPE3
&& addr
>= DPA2ADDR (DPA3L
) && addr
<= DPA2ADDR (DPA3L
) && DPR3
3519 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3525 VMECR
&= ~(VMECR_VMW
| VMECR_VMX
);
3533 SignalException (sd
);
3542 mpu_store_mem_test (SIM_DESC sd
, unsigned int addr
, int size
, int base_reg
)
3548 if (addr
>= PPA2ADDR (PPA
& ~PPM
) && addr
<= DPA2ADDR (PPA
| PPM
))
3550 /* preifarallel area */
3552 else if (addr
>= PPA2ADDR (SPAL
) && addr
<= DPA2ADDR (SPAU
))
3556 else if (DPE0
&& addr
>= DPA2ADDR (DPA0L
) && addr
<= DPA2ADDR (DPA0L
) && DPW0
3557 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3561 else if (DPE1
&& addr
>= DPA2ADDR (DPA1L
) && addr
<= DPA2ADDR (DPA1L
) && DPW1
3562 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3566 else if (DPE2
&& addr
>= DPA2ADDR (DPA2L
) && addr
<= DPA2ADDR (DPA2L
) && DPW2
3567 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3571 else if (DPE3
&& addr
>= DPA2ADDR (DPA3L
) && addr
<= DPA2ADDR (DPA3L
) && DPW3
3572 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3578 if (addr
>= PPA2ADDR (PPA
& ~PPM
) && addr
<= DPA2ADDR (PPA
| PPM
))
3593 VMECR
&= ~(VMECR_VMW
| VMECR_VMX
);