1 /* This must come before any other includes. */
5 #include "sim-signal.h"
19 #include "libiberty.h"
22 #if !defined(__GO32__) && !defined(_WIN32)
24 #include <sys/times.h>
28 #include "target-newlib-syscall.h"
30 /* This is an array of the bit positions of registers r20 .. r31 in
31 that order in a prepare/dispose instruction. */
32 int type1_regs
[12] = { 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 0, 21 };
33 /* This is an array of the bit positions of registers r16 .. r31 in
34 that order in a push/pop instruction. */
35 int type2_regs
[16] = { 3, 2, 1, 0, 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 20, 21};
36 /* This is an array of the bit positions of registers r1 .. r15 in
37 that order in a push/pop instruction. */
38 int type3_regs
[15] = { 2, 1, 0, 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 20, 21};
41 #ifndef SIZE_INSTRUCTION
42 #define SIZE_INSTRUCTION 18
46 #define SIZE_VALUES 11
49 /* TODO: This file largely assumes a single CPU. */
50 #define CPU STATE_CPU (sd, 0)
53 uint32_t trace_values
[3];
56 const char * trace_name
;
61 trace_input (char *name
, enum op_types type
, int size
)
63 if (!TRACE_ALU_P (STATE_CPU (simulator
, 0)))
68 trace_module
= TRACE_ALU_IDX
;
81 trace_values
[0] = State
.regs
[OP
[0]];
88 trace_values
[0] = State
.regs
[OP
[1]];
89 trace_values
[1] = State
.regs
[OP
[0]];
95 trace_values
[0] = SEXT5 (OP
[0]);
96 trace_values
[1] = OP
[1];
100 case OP_IMM_REG_MOVE
:
101 trace_values
[0] = SEXT5 (OP
[0]);
102 trace_num_values
= 1;
106 trace_values
[0] = State
.pc
;
107 trace_values
[1] = SEXT9 (OP
[0]);
108 trace_values
[2] = PSW
;
109 trace_num_values
= 3;
113 trace_values
[0] = OP
[1] * size
;
114 trace_values
[1] = State
.regs
[30];
115 trace_num_values
= 2;
119 trace_values
[0] = State
.regs
[OP
[0]];
120 trace_values
[1] = OP
[1] * size
;
121 trace_values
[2] = State
.regs
[30];
122 trace_num_values
= 3;
126 trace_values
[0] = EXTEND16 (OP
[2]);
127 trace_values
[1] = State
.regs
[OP
[0]];
128 trace_num_values
= 2;
132 trace_values
[0] = State
.regs
[OP
[1]];
133 trace_values
[1] = EXTEND16 (OP
[2]);
134 trace_values
[2] = State
.regs
[OP
[0]];
135 trace_num_values
= 3;
139 trace_values
[0] = SEXT22 (OP
[0]);
140 trace_values
[1] = State
.pc
;
141 trace_num_values
= 2;
145 trace_values
[0] = EXTEND16 (OP
[0]) << size
;
146 trace_values
[1] = State
.regs
[OP
[1]];
147 trace_num_values
= 2;
150 case OP_IMM16_REG_REG
:
151 trace_values
[0] = EXTEND16 (OP
[2]) << size
;
152 trace_values
[1] = State
.regs
[OP
[1]];
153 trace_num_values
= 2;
156 case OP_UIMM_REG_REG
:
157 trace_values
[0] = (OP
[0] & 0xffff) << size
;
158 trace_values
[1] = State
.regs
[OP
[1]];
159 trace_num_values
= 2;
162 case OP_UIMM16_REG_REG
:
163 trace_values
[0] = (OP
[2]) << size
;
164 trace_values
[1] = State
.regs
[OP
[1]];
165 trace_num_values
= 2;
169 trace_num_values
= 0;
173 trace_values
[0] = PSW
;
174 trace_num_values
= 1;
178 trace_num_values
= 0;
182 trace_values
[0] = State
.regs
[OP
[0]];
183 trace_num_values
= 1;
187 trace_values
[0] = State
.sregs
[OP
[1]];
188 trace_num_values
= 1;
194 trace_result (int has_result
, uint32_t result
)
202 /* write out the values saved during the trace_input call */
205 for (i
= 0; i
< trace_num_values
; i
++)
207 sprintf (chp
, "%*s0x%.8lx", SIZE_VALUES
- 10, "",
208 (long) trace_values
[i
]);
209 chp
= strchr (chp
, '\0');
213 sprintf (chp
, "%*s", SIZE_VALUES
, "");
214 chp
= strchr (chp
, '\0');
218 /* append any result to the end of the buffer */
220 sprintf (chp
, " :: 0x%.8lx", (unsigned long) result
);
222 trace_generic (simulator
, STATE_CPU (simulator
, 0), trace_module
, "%s", buf
);
226 trace_output (enum op_types result
)
228 if (!TRACE_ALU_P (STATE_CPU (simulator
, 0)))
250 trace_result (1, State
.regs
[OP
[0]]);
254 case OP_REG_REG_MOVE
:
256 case OP_IMM_REG_MOVE
:
259 trace_result (1, State
.regs
[OP
[1]]);
263 case OP_UIMM_REG_REG
:
264 case OP_IMM16_REG_REG
:
265 case OP_UIMM16_REG_REG
:
266 trace_result (1, State
.regs
[OP
[1]]);
271 trace_result (1, State
.regs
[OP
[1]]);
277 trace_result (1, State
.sregs
[OP
[1]]);
284 /* Returns 1 if the specific condition is met, returns 0 otherwise. */
286 condition_met (unsigned code
)
288 unsigned int psw
= PSW
;
292 case 0x0: return ((psw
& PSW_OV
) != 0);
293 case 0x1: return ((psw
& PSW_CY
) != 0);
294 case 0x2: return ((psw
& PSW_Z
) != 0);
295 case 0x3: return ((((psw
& PSW_CY
) != 0) | ((psw
& PSW_Z
) != 0)) != 0);
296 case 0x4: return ((psw
& PSW_S
) != 0);
297 /*case 0x5: return 1;*/
298 case 0x6: return ((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) != 0);
299 case 0x7: return (((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) || ((psw
& PSW_Z
) != 0)) != 0);
300 case 0x8: return ((psw
& PSW_OV
) == 0);
301 case 0x9: return ((psw
& PSW_CY
) == 0);
302 case 0xa: return ((psw
& PSW_Z
) == 0);
303 case 0xb: return ((((psw
& PSW_CY
) != 0) | ((psw
& PSW_Z
) != 0)) == 0);
304 case 0xc: return ((psw
& PSW_S
) == 0);
305 case 0xd: return ((psw
& PSW_SAT
) != 0);
306 case 0xe: return ((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) == 0);
307 case 0xf: return (((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) || ((psw
& PSW_Z
) != 0)) == 0);
314 Add32 (unsigned long a1
, unsigned long a2
, int * carry
)
316 unsigned long result
= (a1
+ a2
);
318 * carry
= (result
< a1
);
324 Multiply64 (int sign
, unsigned long op0
)
335 op1
= State
.regs
[ OP
[1] ];
339 /* Compute sign of result and adjust operands if necessary. */
341 sign
= (op0
^ op1
) & 0x80000000;
343 if (op0
& 0x80000000)
346 if (op1
& 0x80000000)
350 /* We can split the 32x32 into four 16x16 operations. This ensures
351 that we do not lose precision on 32bit only hosts: */
352 lo
= ( (op0
& 0xFFFF) * (op1
& 0xFFFF));
353 mid1
= ( (op0
& 0xFFFF) * ((op1
>> 16) & 0xFFFF));
354 mid2
= (((op0
>> 16) & 0xFFFF) * (op1
& 0xFFFF));
355 hi
= (((op0
>> 16) & 0xFFFF) * ((op1
>> 16) & 0xFFFF));
357 /* We now need to add all of these results together, taking care
358 to propogate the carries from the additions: */
359 RdLo
= Add32 (lo
, (mid1
<< 16), & carry
);
361 RdLo
= Add32 (RdLo
, (mid2
<< 16), & carry
);
362 RdHi
+= (carry
+ ((mid1
>> 16) & 0xFFFF) + ((mid2
>> 16) & 0xFFFF) + hi
);
366 /* Negate result if necessary. */
370 if (RdLo
== 0xFFFFFFFF)
379 /* Don't store into register 0. */
381 State
.regs
[ OP
[1] ] = RdLo
;
383 State
.regs
[ OP
[2] >> 11 ] = RdHi
;
389 /* Read a null terminated string from memory, return in a buffer. */
392 fetch_str (SIM_DESC sd
, address_word addr
)
397 while (sim_core_read_1 (STATE_CPU (sd
, 0),
398 PC
, read_map
, addr
+ nr
) != 0)
401 buf
= NZALLOC (char, nr
+ 1);
402 sim_read (simulator
, addr
, buf
, nr
);
407 /* Read a null terminated argument vector from memory, return in a
411 fetch_argv (SIM_DESC sd
, address_word addr
)
415 char **buf
= xmalloc (max_nr
* sizeof (char*));
419 uint32_t a
= sim_core_read_4 (STATE_CPU (sd
, 0),
420 PC
, read_map
, addr
+ nr
* 4);
422 buf
[nr
] = fetch_str (sd
, a
);
424 if (nr
== max_nr
- 1)
427 buf
= xrealloc (buf
, max_nr
* sizeof (char*));
439 trace_input ("sst.b", OP_STORE16
, 1);
441 store_mem (State
.regs
[30] + (OP
[3] & 0x7f), 1, State
.regs
[ OP
[1] ]);
443 trace_output (OP_STORE16
);
452 trace_input ("sst.h", OP_STORE16
, 2);
454 store_mem (State
.regs
[30] + ((OP
[3] & 0x7f) << 1), 2, State
.regs
[ OP
[1] ]);
456 trace_output (OP_STORE16
);
465 trace_input ("sst.w", OP_STORE16
, 4);
467 store_mem (State
.regs
[30] + ((OP
[3] & 0x7e) << 1), 4, State
.regs
[ OP
[1] ]);
469 trace_output (OP_STORE16
);
480 trace_input ("ld.b", OP_LOAD32
, 1);
482 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2]);
484 State
.regs
[ OP
[1] ] = EXTEND8 (load_mem (adr
, 1));
486 trace_output (OP_LOAD32
);
497 trace_input ("ld.h", OP_LOAD32
, 2);
499 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2]);
502 State
.regs
[ OP
[1] ] = EXTEND16 (load_mem (adr
, 2));
504 trace_output (OP_LOAD32
);
515 trace_input ("ld.w", OP_LOAD32
, 4);
517 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2] & ~1);
520 State
.regs
[ OP
[1] ] = load_mem (adr
, 4);
522 trace_output (OP_LOAD32
);
531 trace_input ("st.b", OP_STORE32
, 1);
533 store_mem (State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2]), 1, State
.regs
[ OP
[1] ]);
535 trace_output (OP_STORE32
);
546 trace_input ("st.h", OP_STORE32
, 2);
548 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2]);
551 store_mem (adr
, 2, State
.regs
[ OP
[1] ]);
553 trace_output (OP_STORE32
);
564 trace_input ("st.w", OP_STORE32
, 4);
566 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2] & ~1);
569 store_mem (adr
, 4, State
.regs
[ OP
[1] ]);
571 trace_output (OP_STORE32
);
580 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
582 trace_input ("add", OP_REG_REG
, 0);
584 /* Compute the result. */
586 op0
= State
.regs
[ OP
[0] ];
587 op1
= State
.regs
[ OP
[1] ];
591 /* Compute the condition codes. */
593 s
= (result
& 0x80000000);
594 cy
= (result
< op0
|| result
< op1
);
595 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
596 && (op0
& 0x80000000) != (result
& 0x80000000));
598 /* Store the result and condition codes. */
599 State
.regs
[OP
[1]] = result
;
600 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
601 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
602 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
603 trace_output (OP_REG_REG
);
608 /* add sign_extend(imm5), reg */
612 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
615 trace_input ("add", OP_IMM_REG
, 0);
617 /* Compute the result. */
618 temp
= SEXT5 (OP
[0]);
620 op1
= State
.regs
[OP
[1]];
623 /* Compute the condition codes. */
625 s
= (result
& 0x80000000);
626 cy
= (result
< op0
|| result
< op1
);
627 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
628 && (op0
& 0x80000000) != (result
& 0x80000000));
630 /* Store the result and condition codes. */
631 State
.regs
[OP
[1]] = result
;
632 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
633 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
634 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
635 trace_output (OP_IMM_REG
);
640 /* addi sign_extend(imm16), reg, reg */
644 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
646 trace_input ("addi", OP_IMM16_REG_REG
, 0);
648 /* Compute the result. */
650 op0
= EXTEND16 (OP
[2]);
651 op1
= State
.regs
[ OP
[0] ];
654 /* Compute the condition codes. */
656 s
= (result
& 0x80000000);
657 cy
= (result
< op0
|| result
< op1
);
658 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
659 && (op0
& 0x80000000) != (result
& 0x80000000));
661 /* Store the result and condition codes. */
662 State
.regs
[OP
[1]] = result
;
663 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
664 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
665 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
666 trace_output (OP_IMM16_REG_REG
);
675 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
677 trace_input ("sub", OP_REG_REG
, 0);
678 /* Compute the result. */
679 op0
= State
.regs
[ OP
[0] ];
680 op1
= State
.regs
[ OP
[1] ];
683 /* Compute the condition codes. */
685 s
= (result
& 0x80000000);
687 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
688 && (op1
& 0x80000000) != (result
& 0x80000000));
690 /* Store the result and condition codes. */
691 State
.regs
[OP
[1]] = result
;
692 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
693 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
694 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
695 trace_output (OP_REG_REG
);
700 /* subr reg1, reg2 */
704 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
706 trace_input ("subr", OP_REG_REG
, 0);
707 /* Compute the result. */
708 op0
= State
.regs
[ OP
[0] ];
709 op1
= State
.regs
[ OP
[1] ];
712 /* Compute the condition codes. */
714 s
= (result
& 0x80000000);
716 ov
= ((op0
& 0x80000000) != (op1
& 0x80000000)
717 && (op0
& 0x80000000) != (result
& 0x80000000));
719 /* Store the result and condition codes. */
720 State
.regs
[OP
[1]] = result
;
721 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
722 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
723 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
724 trace_output (OP_REG_REG
);
733 trace_input ("mulh", OP_REG_REG
, 0);
735 State
.regs
[ OP
[1] ] = (EXTEND16 (State
.regs
[ OP
[1] ]) * EXTEND16 (State
.regs
[ OP
[0] ]));
737 trace_output (OP_REG_REG
);
742 /* mulh sign_extend(imm5), reg2 */
746 trace_input ("mulh", OP_IMM_REG
, 0);
748 State
.regs
[ OP
[1] ] = EXTEND16 (State
.regs
[ OP
[1] ]) * SEXT5 (OP
[0]);
750 trace_output (OP_IMM_REG
);
755 /* mulhi imm16, reg1, reg2 */
759 trace_input ("mulhi", OP_IMM16_REG_REG
, 0);
761 State
.regs
[ OP
[1] ] = EXTEND16 (State
.regs
[ OP
[0] ]) * EXTEND16 (OP
[2]);
763 trace_output (OP_IMM16_REG_REG
);
772 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
774 trace_input ("cmp", OP_REG_REG_CMP
, 0);
775 /* Compute the result. */
776 op0
= State
.regs
[ OP
[0] ];
777 op1
= State
.regs
[ OP
[1] ];
780 /* Compute the condition codes. */
782 s
= (result
& 0x80000000);
784 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
785 && (op1
& 0x80000000) != (result
& 0x80000000));
787 /* Set condition codes. */
788 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
789 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
790 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
791 trace_output (OP_REG_REG_CMP
);
796 /* cmp sign_extend(imm5), reg */
800 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
803 /* Compute the result. */
804 trace_input ("cmp", OP_IMM_REG_CMP
, 0);
805 temp
= SEXT5 (OP
[0]);
807 op1
= State
.regs
[OP
[1]];
810 /* Compute the condition codes. */
812 s
= (result
& 0x80000000);
814 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
815 && (op1
& 0x80000000) != (result
& 0x80000000));
817 /* Set condition codes. */
818 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
819 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
820 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
821 trace_output (OP_IMM_REG_CMP
);
830 trace_input ("setf", OP_EX1
, 0);
832 State
.regs
[ OP
[1] ] = condition_met (OP
[0]);
834 trace_output (OP_EX1
);
843 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
845 trace_input ("satadd", OP_REG_REG
, 0);
846 /* Compute the result. */
847 op0
= State
.regs
[ OP
[0] ];
848 op1
= State
.regs
[ OP
[1] ];
851 /* Compute the condition codes. */
853 s
= (result
& 0x80000000);
854 cy
= (result
< op0
|| result
< op1
);
855 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
856 && (op0
& 0x80000000) != (result
& 0x80000000));
859 /* Handle saturated results. */
862 /* An overflow that results in a negative result implies that we
863 became too positive. */
869 /* Any other overflow must have thus been too negative. */
875 /* Store the result and condition codes. */
876 State
.regs
[OP
[1]] = result
;
877 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
878 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
879 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
880 | (sat
? PSW_SAT
: 0));
882 trace_output (OP_REG_REG
);
887 /* satadd sign_extend(imm5), reg */
891 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
895 trace_input ("satadd", OP_IMM_REG
, 0);
897 /* Compute the result. */
898 temp
= SEXT5 (OP
[0]);
900 op1
= State
.regs
[OP
[1]];
903 /* Compute the condition codes. */
905 s
= (result
& 0x80000000);
906 cy
= (result
< op0
|| result
< op1
);
907 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
908 && (op0
& 0x80000000) != (result
& 0x80000000));
911 /* Handle saturated results. */
914 /* An overflow that results in a negative result implies that we
915 became too positive. */
921 /* Any other overflow must have thus been too negative. */
927 /* Store the result and condition codes. */
928 State
.regs
[OP
[1]] = result
;
929 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
930 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
931 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
932 | (sat
? PSW_SAT
: 0));
933 trace_output (OP_IMM_REG
);
938 /* satsub reg1, reg2 */
942 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
944 trace_input ("satsub", OP_REG_REG
, 0);
946 /* Compute the result. */
947 op0
= State
.regs
[ OP
[0] ];
948 op1
= State
.regs
[ OP
[1] ];
951 /* Compute the condition codes. */
953 s
= (result
& 0x80000000);
955 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
956 && (op1
& 0x80000000) != (result
& 0x80000000));
959 /* Handle saturated results. */
962 /* An overflow that results in a negative result implies that we
963 became too positive. */
969 /* Any other overflow must have thus been too negative. */
975 /* Store the result and condition codes. */
976 State
.regs
[OP
[1]] = result
;
977 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
978 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
979 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
980 | (sat
? PSW_SAT
: 0));
982 trace_output (OP_REG_REG
);
986 /* satsubi sign_extend(imm16), reg */
990 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
993 trace_input ("satsubi", OP_IMM_REG
, 0);
995 /* Compute the result. */
996 temp
= EXTEND16 (OP
[2]);
998 op1
= State
.regs
[ OP
[0] ];
1001 /* Compute the condition codes. */
1003 s
= (result
& 0x80000000);
1005 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
1006 && (op1
& 0x80000000) != (result
& 0x80000000));
1009 /* Handle saturated results. */
1012 /* An overflow that results in a negative result implies that we
1013 became too positive. */
1014 result
= 0x7fffffff;
1019 /* Any other overflow must have thus been too negative. */
1020 result
= 0x80000000;
1025 /* Store the result and condition codes. */
1026 State
.regs
[OP
[1]] = result
;
1027 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1028 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1029 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
1030 | (sat
? PSW_SAT
: 0));
1032 trace_output (OP_IMM_REG
);
1037 /* satsubr reg,reg */
1041 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
1043 trace_input ("satsubr", OP_REG_REG
, 0);
1045 /* Compute the result. */
1046 op0
= State
.regs
[ OP
[0] ];
1047 op1
= State
.regs
[ OP
[1] ];
1050 /* Compute the condition codes. */
1052 s
= (result
& 0x80000000);
1054 ov
= ((op0
& 0x80000000) != (op1
& 0x80000000)
1055 && (op0
& 0x80000000) != (result
& 0x80000000));
1058 /* Handle saturated results. */
1061 /* An overflow that results in a negative result implies that we
1062 became too positive. */
1063 result
= 0x7fffffff;
1068 /* Any other overflow must have thus been too negative. */
1069 result
= 0x80000000;
1074 /* Store the result and condition codes. */
1075 State
.regs
[OP
[1]] = result
;
1076 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1077 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1078 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
1079 | (sat
? PSW_SAT
: 0));
1081 trace_output (OP_REG_REG
);
1090 unsigned int op0
, op1
, result
, z
, s
;
1092 trace_input ("tst", OP_REG_REG_CMP
, 0);
1094 /* Compute the result. */
1095 op0
= State
.regs
[ OP
[0] ];
1096 op1
= State
.regs
[ OP
[1] ];
1099 /* Compute the condition codes. */
1101 s
= (result
& 0x80000000);
1103 /* Store the condition codes. */
1104 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1105 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1106 trace_output (OP_REG_REG_CMP
);
1111 /* mov sign_extend(imm5), reg */
1115 int value
= SEXT5 (OP
[0]);
1117 trace_input ("mov", OP_IMM_REG_MOVE
, 0);
1119 State
.regs
[ OP
[1] ] = value
;
1121 trace_output (OP_IMM_REG_MOVE
);
1126 /* movhi imm16, reg, reg */
1130 trace_input ("movhi", OP_UIMM16_REG_REG
, 16);
1132 State
.regs
[ OP
[1] ] = State
.regs
[ OP
[0] ] + (OP
[2] << 16);
1134 trace_output (OP_UIMM16_REG_REG
);
1139 /* sar zero_extend(imm5),reg1 */
1143 unsigned int op0
, op1
, result
, z
, s
, cy
;
1145 trace_input ("sar", OP_IMM_REG
, 0);
1147 op1
= State
.regs
[ OP
[1] ];
1148 result
= (signed)op1
>> op0
;
1150 /* Compute the condition codes. */
1152 s
= (result
& 0x80000000);
1153 cy
= op0
? (op1
& (1 << (op0
- 1))) : 0;
1155 /* Store the result and condition codes. */
1156 State
.regs
[ OP
[1] ] = result
;
1157 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1158 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1159 | (cy
? PSW_CY
: 0));
1160 trace_output (OP_IMM_REG
);
1165 /* sar reg1, reg2 */
1169 unsigned int op0
, op1
, result
, z
, s
, cy
;
1171 trace_input ("sar", OP_REG_REG
, 0);
1173 op0
= State
.regs
[ OP
[0] ] & 0x1f;
1174 op1
= State
.regs
[ OP
[1] ];
1175 result
= (signed)op1
>> op0
;
1177 /* Compute the condition codes. */
1179 s
= (result
& 0x80000000);
1180 cy
= op0
? (op1
& (1 << (op0
- 1))) : 0;
1182 /* Store the result and condition codes. */
1183 State
.regs
[OP
[1]] = result
;
1184 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1185 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1186 | (cy
? PSW_CY
: 0));
1187 trace_output (OP_REG_REG
);
1192 /* shl zero_extend(imm5),reg1 */
1196 unsigned int op0
, op1
, result
, z
, s
, cy
;
1198 trace_input ("shl", OP_IMM_REG
, 0);
1200 op1
= State
.regs
[ OP
[1] ];
1201 result
= op1
<< op0
;
1203 /* Compute the condition codes. */
1205 s
= (result
& 0x80000000);
1206 cy
= op0
? (op1
& (1 << (32 - op0
))) : 0;
1208 /* Store the result and condition codes. */
1209 State
.regs
[OP
[1]] = result
;
1210 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1211 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1212 | (cy
? PSW_CY
: 0));
1213 trace_output (OP_IMM_REG
);
1218 /* shl reg1, reg2 */
1222 unsigned int op0
, op1
, result
, z
, s
, cy
;
1224 trace_input ("shl", OP_REG_REG
, 0);
1225 op0
= State
.regs
[ OP
[0] ] & 0x1f;
1226 op1
= State
.regs
[ OP
[1] ];
1227 result
= op1
<< op0
;
1229 /* Compute the condition codes. */
1231 s
= (result
& 0x80000000);
1232 cy
= op0
? (op1
& (1 << (32 - op0
))) : 0;
1234 /* Store the result and condition codes. */
1235 State
.regs
[OP
[1]] = result
;
1236 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1237 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1238 | (cy
? PSW_CY
: 0));
1239 trace_output (OP_REG_REG
);
1244 /* shr zero_extend(imm5),reg1 */
1248 unsigned int op0
, op1
, result
, z
, s
, cy
;
1250 trace_input ("shr", OP_IMM_REG
, 0);
1252 op1
= State
.regs
[ OP
[1] ];
1253 result
= op1
>> op0
;
1255 /* Compute the condition codes. */
1257 s
= (result
& 0x80000000);
1258 cy
= op0
? (op1
& (1 << (op0
- 1))) : 0;
1260 /* Store the result and condition codes. */
1261 State
.regs
[OP
[1]] = result
;
1262 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1263 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1264 | (cy
? PSW_CY
: 0));
1265 trace_output (OP_IMM_REG
);
1270 /* shr reg1, reg2 */
1274 unsigned int op0
, op1
, result
, z
, s
, cy
;
1276 trace_input ("shr", OP_REG_REG
, 0);
1277 op0
= State
.regs
[ OP
[0] ] & 0x1f;
1278 op1
= State
.regs
[ OP
[1] ];
1279 result
= op1
>> op0
;
1281 /* Compute the condition codes. */
1283 s
= (result
& 0x80000000);
1284 cy
= op0
? (op1
& (1 << (op0
- 1))) : 0;
1286 /* Store the result and condition codes. */
1287 State
.regs
[OP
[1]] = result
;
1288 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1289 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1290 | (cy
? PSW_CY
: 0));
1291 trace_output (OP_REG_REG
);
1300 unsigned int op0
, op1
, result
, z
, s
;
1302 trace_input ("or", OP_REG_REG
, 0);
1304 /* Compute the result. */
1305 op0
= State
.regs
[ OP
[0] ];
1306 op1
= State
.regs
[ OP
[1] ];
1309 /* Compute the condition codes. */
1311 s
= (result
& 0x80000000);
1313 /* Store the result and condition codes. */
1314 State
.regs
[OP
[1]] = result
;
1315 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1316 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1317 trace_output (OP_REG_REG
);
1322 /* ori zero_extend(imm16), reg, reg */
1326 unsigned int op0
, op1
, result
, z
, s
;
1328 trace_input ("ori", OP_UIMM16_REG_REG
, 0);
1330 op1
= State
.regs
[ OP
[0] ];
1333 /* Compute the condition codes. */
1335 s
= (result
& 0x80000000);
1337 /* Store the result and condition codes. */
1338 State
.regs
[OP
[1]] = result
;
1339 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1340 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1341 trace_output (OP_UIMM16_REG_REG
);
1350 unsigned int op0
, op1
, result
, z
, s
;
1352 trace_input ("and", OP_REG_REG
, 0);
1354 /* Compute the result. */
1355 op0
= State
.regs
[ OP
[0] ];
1356 op1
= State
.regs
[ OP
[1] ];
1359 /* Compute the condition codes. */
1361 s
= (result
& 0x80000000);
1363 /* Store the result and condition codes. */
1364 State
.regs
[OP
[1]] = result
;
1365 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1366 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1367 trace_output (OP_REG_REG
);
1372 /* andi zero_extend(imm16), reg, reg */
1376 unsigned int result
, z
;
1378 trace_input ("andi", OP_UIMM16_REG_REG
, 0);
1380 result
= OP
[2] & State
.regs
[ OP
[0] ];
1382 /* Compute the condition codes. */
1385 /* Store the result and condition codes. */
1386 State
.regs
[ OP
[1] ] = result
;
1388 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1389 PSW
|= (z
? PSW_Z
: 0);
1391 trace_output (OP_UIMM16_REG_REG
);
1400 unsigned int op0
, op1
, result
, z
, s
;
1402 trace_input ("xor", OP_REG_REG
, 0);
1404 /* Compute the result. */
1405 op0
= State
.regs
[ OP
[0] ];
1406 op1
= State
.regs
[ OP
[1] ];
1409 /* Compute the condition codes. */
1411 s
= (result
& 0x80000000);
1413 /* Store the result and condition codes. */
1414 State
.regs
[OP
[1]] = result
;
1415 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1416 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1417 trace_output (OP_REG_REG
);
1422 /* xori zero_extend(imm16), reg, reg */
1426 unsigned int op0
, op1
, result
, z
, s
;
1428 trace_input ("xori", OP_UIMM16_REG_REG
, 0);
1430 op1
= State
.regs
[ OP
[0] ];
1433 /* Compute the condition codes. */
1435 s
= (result
& 0x80000000);
1437 /* Store the result and condition codes. */
1438 State
.regs
[OP
[1]] = result
;
1439 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1440 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1441 trace_output (OP_UIMM16_REG_REG
);
1446 /* not reg1, reg2 */
1450 unsigned int op0
, result
, z
, s
;
1452 trace_input ("not", OP_REG_REG_MOVE
, 0);
1453 /* Compute the result. */
1454 op0
= State
.regs
[ OP
[0] ];
1457 /* Compute the condition codes. */
1459 s
= (result
& 0x80000000);
1461 /* Store the result and condition codes. */
1462 State
.regs
[OP
[1]] = result
;
1463 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1464 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1465 trace_output (OP_REG_REG_MOVE
);
1474 unsigned int op0
, op1
, op2
;
1477 trace_input ("set1", OP_BIT
, 0);
1478 op0
= State
.regs
[ OP
[0] ];
1480 temp
= EXTEND16 (OP
[2]);
1482 temp
= load_mem (op0
+ op2
, 1);
1484 if ((temp
& (1 << op1
)) == 0)
1487 store_mem (op0
+ op2
, 1, temp
);
1488 trace_output (OP_BIT
);
1497 unsigned int op0
, op1
, op2
;
1500 trace_input ("not1", OP_BIT
, 0);
1501 op0
= State
.regs
[ OP
[0] ];
1503 temp
= EXTEND16 (OP
[2]);
1505 temp
= load_mem (op0
+ op2
, 1);
1507 if ((temp
& (1 << op1
)) == 0)
1510 store_mem (op0
+ op2
, 1, temp
);
1511 trace_output (OP_BIT
);
1520 unsigned int op0
, op1
, op2
;
1523 trace_input ("clr1", OP_BIT
, 0);
1524 op0
= State
.regs
[ OP
[0] ];
1526 temp
= EXTEND16 (OP
[2]);
1528 temp
= load_mem (op0
+ op2
, 1);
1530 if ((temp
& (1 << op1
)) == 0)
1532 temp
&= ~(1 << op1
);
1533 store_mem (op0
+ op2
, 1, temp
);
1534 trace_output (OP_BIT
);
1543 unsigned int op0
, op1
, op2
;
1546 trace_input ("tst1", OP_BIT
, 0);
1547 op0
= State
.regs
[ OP
[0] ];
1549 temp
= EXTEND16 (OP
[2]);
1551 temp
= load_mem (op0
+ op2
, 1);
1553 if ((temp
& (1 << op1
)) == 0)
1555 trace_output (OP_BIT
);
1564 trace_input ("di", OP_NONE
, 0);
1566 trace_output (OP_NONE
);
1575 trace_input ("ei", OP_NONE
, 0);
1577 trace_output (OP_NONE
);
1586 trace_input ("halt", OP_NONE
, 0);
1587 /* FIXME this should put processor into a mode where NMI still handled */
1588 trace_output (OP_NONE
);
1589 sim_engine_halt (simulator
, STATE_CPU (simulator
, 0), NULL
, PC
,
1590 sim_stopped
, SIM_SIGTRAP
);
1598 trace_input ("trap", OP_TRAP
, 0);
1599 trace_output (OP_TRAP
);
1601 /* Trap 31 is used for simulating OS I/O functions */
1605 int save_errno
= errno
;
1608 /* Registers passed to trap 0 */
1610 #define FUNC State.regs[6] /* function number, return value */
1611 #define PARM1 State.regs[7] /* optional parm 1 */
1612 #define PARM2 State.regs[8] /* optional parm 2 */
1613 #define PARM3 State.regs[9] /* optional parm 3 */
1615 /* Registers set by trap 0 */
1617 #define RETVAL State.regs[10] /* return value */
1618 #define RETERR State.regs[11] /* return error code */
1620 /* Turn a pointer in a register into a pointer into real memory. */
1622 #define MEMPTR(x) (map (x))
1630 case TARGET_NEWLIB_V850_SYS_fork
:
1637 case TARGET_NEWLIB_V850_SYS_execve
:
1639 char *path
= fetch_str (simulator
, PARM1
);
1640 char **argv
= fetch_argv (simulator
, PARM2
);
1641 char **envp
= fetch_argv (simulator
, PARM3
);
1642 RETVAL
= execve (path
, (void *)argv
, (void *)envp
);
1652 case TARGET_NEWLIB_V850_SYS_execv
:
1654 char *path
= fetch_str (simulator
, PARM1
);
1655 char **argv
= fetch_argv (simulator
, PARM2
);
1656 RETVAL
= execv (path
, (void *)argv
);
1665 case TARGET_NEWLIB_V850_SYS_pipe
:
1671 RETVAL
= pipe (host_fd
);
1672 SW (buf
, host_fd
[0]);
1673 buf
+= sizeof (uint16_t);
1674 SW (buf
, host_fd
[1]);
1681 case TARGET_NEWLIB_V850_SYS_wait
:
1685 RETVAL
= wait (&status
);
1692 case TARGET_NEWLIB_V850_SYS_read
:
1694 char *buf
= zalloc (PARM3
);
1695 RETVAL
= sim_io_read (simulator
, PARM1
, buf
, PARM3
);
1696 sim_write (simulator
, PARM2
, buf
, PARM3
);
1698 if ((int) RETVAL
< 0)
1699 RETERR
= sim_io_get_errno (simulator
);
1703 case TARGET_NEWLIB_V850_SYS_write
:
1705 char *buf
= zalloc (PARM3
);
1706 sim_read (simulator
, PARM2
, buf
, PARM3
);
1708 RETVAL
= sim_io_write_stdout (simulator
, buf
, PARM3
);
1710 RETVAL
= sim_io_write (simulator
, PARM1
, buf
, PARM3
);
1712 if ((int) RETVAL
< 0)
1713 RETERR
= sim_io_get_errno (simulator
);
1717 case TARGET_NEWLIB_V850_SYS_lseek
:
1718 RETVAL
= sim_io_lseek (simulator
, PARM1
, PARM2
, PARM3
);
1719 if ((int) RETVAL
< 0)
1720 RETERR
= sim_io_get_errno (simulator
);
1723 case TARGET_NEWLIB_V850_SYS_close
:
1724 RETVAL
= sim_io_close (simulator
, PARM1
);
1725 if ((int) RETVAL
< 0)
1726 RETERR
= sim_io_get_errno (simulator
);
1729 case TARGET_NEWLIB_V850_SYS_open
:
1731 char *buf
= fetch_str (simulator
, PARM1
);
1732 RETVAL
= sim_io_open (simulator
, buf
, PARM2
);
1734 if ((int) RETVAL
< 0)
1735 RETERR
= sim_io_get_errno (simulator
);
1739 case TARGET_NEWLIB_V850_SYS_exit
:
1740 if ((PARM1
& 0xffff0000) == 0xdead0000 && (PARM1
& 0xffff) != 0)
1741 /* get signal encoded by kill */
1742 sim_engine_halt (simulator
, STATE_CPU (simulator
, 0), NULL
, PC
,
1743 sim_signalled
, PARM1
& 0xffff);
1744 else if (PARM1
== 0xdead)
1746 sim_engine_halt (simulator
, STATE_CPU (simulator
, 0), NULL
, PC
,
1747 sim_stopped
, SIM_SIGABRT
);
1749 /* PARM1 has exit status */
1750 sim_engine_halt (simulator
, STATE_CPU (simulator
, 0), NULL
, PC
,
1754 case TARGET_NEWLIB_V850_SYS_stat
: /* added at hmsi */
1755 /* stat system call */
1757 struct stat host_stat
;
1759 char *path
= fetch_str (simulator
, PARM1
);
1761 RETVAL
= sim_io_stat (simulator
, path
, &host_stat
);
1766 /* Just wild-assed guesses. */
1767 store_mem (buf
, 2, host_stat
.st_dev
);
1768 store_mem (buf
+ 2, 2, host_stat
.st_ino
);
1769 store_mem (buf
+ 4, 4, host_stat
.st_mode
);
1770 store_mem (buf
+ 8, 2, host_stat
.st_nlink
);
1771 store_mem (buf
+ 10, 2, host_stat
.st_uid
);
1772 store_mem (buf
+ 12, 2, host_stat
.st_gid
);
1773 store_mem (buf
+ 14, 2, host_stat
.st_rdev
);
1774 store_mem (buf
+ 16, 4, host_stat
.st_size
);
1775 store_mem (buf
+ 20, 4, host_stat
.st_atime
);
1776 store_mem (buf
+ 28, 4, host_stat
.st_mtime
);
1777 store_mem (buf
+ 36, 4, host_stat
.st_ctime
);
1779 if ((int) RETVAL
< 0)
1780 RETERR
= sim_io_get_errno (simulator
);
1784 case TARGET_NEWLIB_V850_SYS_fstat
:
1785 /* fstat system call */
1787 struct stat host_stat
;
1790 RETVAL
= sim_io_fstat (simulator
, PARM1
, &host_stat
);
1794 /* Just wild-assed guesses. */
1795 store_mem (buf
, 2, host_stat
.st_dev
);
1796 store_mem (buf
+ 2, 2, host_stat
.st_ino
);
1797 store_mem (buf
+ 4, 4, host_stat
.st_mode
);
1798 store_mem (buf
+ 8, 2, host_stat
.st_nlink
);
1799 store_mem (buf
+ 10, 2, host_stat
.st_uid
);
1800 store_mem (buf
+ 12, 2, host_stat
.st_gid
);
1801 store_mem (buf
+ 14, 2, host_stat
.st_rdev
);
1802 store_mem (buf
+ 16, 4, host_stat
.st_size
);
1803 store_mem (buf
+ 20, 4, host_stat
.st_atime
);
1804 store_mem (buf
+ 28, 4, host_stat
.st_mtime
);
1805 store_mem (buf
+ 36, 4, host_stat
.st_ctime
);
1807 if ((int) RETVAL
< 0)
1808 RETERR
= sim_io_get_errno (simulator
);
1812 case TARGET_NEWLIB_V850_SYS_rename
:
1814 char *oldpath
= fetch_str (simulator
, PARM1
);
1815 char *newpath
= fetch_str (simulator
, PARM2
);
1816 RETVAL
= sim_io_rename (simulator
, oldpath
, newpath
);
1819 if ((int) RETVAL
< 0)
1820 RETERR
= sim_io_get_errno (simulator
);
1824 case TARGET_NEWLIB_V850_SYS_unlink
:
1826 char *path
= fetch_str (simulator
, PARM1
);
1827 RETVAL
= sim_io_unlink (simulator
, path
);
1829 if ((int) RETVAL
< 0)
1830 RETERR
= sim_io_get_errno (simulator
);
1834 case TARGET_NEWLIB_V850_SYS_chown
:
1836 char *path
= fetch_str (simulator
, PARM1
);
1837 RETVAL
= chown (path
, PARM2
, PARM3
);
1844 case TARGET_NEWLIB_V850_SYS_chmod
:
1846 char *path
= fetch_str (simulator
, PARM1
);
1847 RETVAL
= chmod (path
, PARM2
);
1855 case TARGET_NEWLIB_V850_SYS_time
:
1858 RETVAL
= time (&now
);
1859 store_mem (PARM1
, 4, now
);
1865 #if !defined(__GO32__) && !defined(_WIN32)
1866 case TARGET_NEWLIB_V850_SYS_times
:
1869 RETVAL
= times (&tms
);
1870 store_mem (PARM1
, 4, tms
.tms_utime
);
1871 store_mem (PARM1
+ 4, 4, tms
.tms_stime
);
1872 store_mem (PARM1
+ 8, 4, tms
.tms_cutime
);
1873 store_mem (PARM1
+ 12, 4, tms
.tms_cstime
);
1879 #if !defined(__GO32__) && !defined(_WIN32)
1880 case TARGET_NEWLIB_V850_SYS_gettimeofday
:
1884 RETVAL
= gettimeofday (&t
, &tz
);
1885 store_mem (PARM1
, 4, t
.tv_sec
);
1886 store_mem (PARM1
+ 4, 4, t
.tv_usec
);
1887 store_mem (PARM2
, 4, tz
.tz_minuteswest
);
1888 store_mem (PARM2
+ 4, 4, tz
.tz_dsttime
);
1895 case TARGET_NEWLIB_V850_SYS_utime
:
1897 /* Cast the second argument to void *, to avoid type mismatch
1898 if a prototype is present. */
1899 sim_io_error (simulator
, "Utime not supported");
1900 /* RETVAL = utime (path, (void *) MEMPTR (PARM2)); */
1913 { /* Trap 0 -> 30 */
1918 ECR
|= 0x40 + OP
[0];
1919 /* Flag that we are now doing exception processing. */
1920 PSW
|= PSW_EP
| PSW_ID
;
1921 PC
= (OP
[0] < 0x10) ? 0x40 : 0x50;
1927 /* tst1 reg2, [reg1] */
1933 trace_input ("tst1", OP_BIT
, 1);
1935 temp
= load_mem (State
.regs
[ OP
[0] ], 1);
1938 if ((temp
& (1 << (State
.regs
[ OP
[1] ] & 0x7))) == 0)
1941 trace_output (OP_BIT
);
1946 /* mulu reg1, reg2, reg3 */
1950 trace_input ("mulu", OP_REG_REG_REG
, 0);
1952 Multiply64 (0, State
.regs
[ OP
[0] ]);
1954 trace_output (OP_REG_REG_REG
);
1959 #define BIT_CHANGE_OP( name, binop ) \
1961 unsigned int temp; \
1963 trace_input (name, OP_BIT_CHANGE, 0); \
1965 bit = 1 << (State.regs[ OP[1] ] & 0x7); \
1966 temp = load_mem (State.regs[ OP[0] ], 1); \
1969 if ((temp & bit) == 0) \
1973 store_mem (State.regs[ OP[0] ], 1, temp); \
1975 trace_output (OP_BIT_CHANGE); \
1979 /* clr1 reg2, [reg1] */
1983 BIT_CHANGE_OP ("clr1", &= ~ );
1986 /* not1 reg2, [reg1] */
1990 BIT_CHANGE_OP ("not1", ^= );
1997 BIT_CHANGE_OP ("set1", |= );
2004 trace_input ("sasf", OP_EX1
, 0);
2006 State
.regs
[ OP
[1] ] = (State
.regs
[ OP
[1] ] << 1) | condition_met (OP
[0]);
2008 trace_output (OP_EX1
);
2013 /* This function is courtesy of Sugimoto at NEC, via Seow Tan
2014 (Soew_Tan@el.nec.com) */
2019 unsigned long int als
,
2020 unsigned long int sfi
,
2021 uint32_t /*unsigned long int*/ * quotient_ptr
,
2022 uint32_t /*unsigned long int*/ * remainder_ptr
,
2026 unsigned long ald
= sfi
>> (N
- 1);
2027 unsigned long alo
= als
;
2032 unsigned int R1
= 1;
2033 unsigned int DBZ
= (als
== 0) ? 1 : 0;
2034 unsigned long alt
= Q
? ~als
: als
;
2037 alo
= ald
+ alt
+ Q
;
2038 C
= (((alt
>> 31) & (ald
>> 31))
2039 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2042 R1
= (alo
== 0) ? 0 : (R1
& Q
);
2043 if ((S
^ (alo
>>31)) && !C
)
2048 sfi
= (sfi
<< (32-N
+1)) | Q
;
2049 ald
= (alo
<< 1) | (sfi
>> 31);
2051 /* 2nd - N-1th Loop */
2052 for (i
= 2; i
< N
; i
++)
2054 alt
= Q
? ~als
: als
;
2055 alo
= ald
+ alt
+ Q
;
2056 C
= (((alt
>> 31) & (ald
>> 31))
2057 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2060 R1
= (alo
== 0) ? 0 : (R1
& Q
);
2061 if ((S
^ (alo
>>31)) && !C
&& !DBZ
)
2066 sfi
= (sfi
<< 1) | Q
;
2067 ald
= (alo
<< 1) | (sfi
>> 31);
2071 alt
= Q
? ~als
: als
;
2072 alo
= ald
+ alt
+ Q
;
2073 C
= (((alt
>> 31) & (ald
>> 31))
2074 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2077 R1
= (alo
== 0) ? 0 : (R1
& Q
);
2078 if ((S
^ (alo
>>31)) && !C
)
2083 * quotient_ptr
= (sfi
<< 1) | Q
;
2084 * remainder_ptr
= Q
? alo
: (alo
+ als
);
2085 * overflow_ptr
= DBZ
| R1
;
2088 /* This function is courtesy of Sugimoto at NEC, via Seow Tan (Soew_Tan@el.nec.com) */
2093 unsigned long int als
,
2094 unsigned long int sfi
,
2095 int32_t /*signed long int*/ * quotient_ptr
,
2096 int32_t /*signed long int*/ * remainder_ptr
,
2100 unsigned long ald
= (signed long) sfi
>> (N
- 1);
2101 unsigned long alo
= als
;
2102 unsigned int SS
= als
>> 31;
2103 unsigned int SD
= sfi
>> 31;
2104 unsigned int R1
= 1;
2106 unsigned int DBZ
= als
== 0 ? 1 : 0;
2107 unsigned int Q
= ~(SS
^ SD
) & 1;
2111 unsigned long alt
= Q
? ~als
: als
;
2116 alo
= ald
+ alt
+ Q
;
2117 C
= (((alt
>> 31) & (ald
>> 31))
2118 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2120 R1
= (alo
== 0) ? 0 : (R1
& (Q
^ (SS
^ SD
)));
2122 sfi
= (sfi
<< (32-N
+1)) | Q
;
2123 ald
= (alo
<< 1) | (sfi
>> 31);
2124 if ((alo
>> 31) ^ (ald
>> 31))
2129 /* 2nd - N-1th Loop */
2131 for (i
= 2; i
< N
; i
++)
2133 alt
= Q
? ~als
: als
;
2134 alo
= ald
+ alt
+ Q
;
2135 C
= (((alt
>> 31) & (ald
>> 31))
2136 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2138 R1
= (alo
== 0) ? 0 : (R1
& (Q
^ (SS
^ SD
)));
2140 sfi
= (sfi
<< 1) | Q
;
2141 ald
= (alo
<< 1) | (sfi
>> 31);
2142 if ((alo
>> 31) ^ (ald
>> 31))
2149 alt
= Q
? ~als
: als
;
2150 alo
= ald
+ alt
+ Q
;
2151 C
= (((alt
>> 31) & (ald
>> 31))
2152 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2154 R1
= (alo
== 0) ? 0 : (R1
& (Q
^ (SS
^ SD
)));
2155 sfi
= (sfi
<< (32-N
+1));
2161 alt
= Q
? ~als
: als
;
2162 alo
= ald
+ alt
+ Q
;
2164 R1
= R1
& ((~alo
>> 31) ^ SD
);
2165 if ((alo
!= 0) && ((Q
^ (SS
^ SD
)) ^ R1
)) alo
= ald
;
2167 ald
= sfi
= (long) ((sfi
>> 1) | (SS
^ SD
) << 31) >> (32-N
-1) | Q
;
2169 ald
= sfi
= sfi
| Q
;
2171 OV
= DBZ
| ((alo
== 0) ? 0 : R1
);
2173 * remainder_ptr
= alo
;
2176 if (((alo
!= 0) && ((SS
^ SD
) ^ R1
))
2177 || ((alo
== 0) && (SS
^ R1
)))
2182 OV
= (DBZ
| R1
) ? OV
: ((alo
>> 31) & (~ald
>> 31));
2184 * quotient_ptr
= alo
;
2185 * overflow_ptr
= OV
;
2188 /* sdivun imm5, reg1, reg2, reg3 */
2192 uint32_t /*unsigned long int*/ quotient
;
2193 uint32_t /*unsigned long int*/ remainder
;
2194 unsigned long int divide_by
;
2195 unsigned long int divide_this
;
2199 trace_input ("sdivun", OP_IMM_REG_REG_REG
, 0);
2201 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2203 divide_by
= State
.regs
[ OP
[0] ];
2204 divide_this
= State
.regs
[ OP
[1] ] << imm5
;
2206 divun (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2208 State
.regs
[ OP
[1] ] = quotient
;
2209 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2211 /* Set condition codes. */
2212 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2214 if (overflow
) PSW
|= PSW_OV
;
2215 if (quotient
== 0) PSW
|= PSW_Z
;
2216 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2218 trace_output (OP_IMM_REG_REG_REG
);
2223 /* sdivn imm5, reg1, reg2, reg3 */
2227 int32_t /*signed long int*/ quotient
;
2228 int32_t /*signed long int*/ remainder
;
2229 signed long int divide_by
;
2230 signed long int divide_this
;
2234 trace_input ("sdivn", OP_IMM_REG_REG_REG
, 0);
2236 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2238 divide_by
= (int32_t) State
.regs
[ OP
[0] ];
2239 divide_this
= (int32_t) (State
.regs
[ OP
[1] ] << imm5
);
2241 divn (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2243 State
.regs
[ OP
[1] ] = quotient
;
2244 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2246 /* Set condition codes. */
2247 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2249 if (overflow
) PSW
|= PSW_OV
;
2250 if (quotient
== 0) PSW
|= PSW_Z
;
2251 if (quotient
< 0) PSW
|= PSW_S
;
2253 trace_output (OP_IMM_REG_REG_REG
);
2258 /* sdivhun imm5, reg1, reg2, reg3 */
2262 uint32_t /*unsigned long int*/ quotient
;
2263 uint32_t /*unsigned long int*/ remainder
;
2264 unsigned long int divide_by
;
2265 unsigned long int divide_this
;
2269 trace_input ("sdivhun", OP_IMM_REG_REG_REG
, 0);
2271 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2273 divide_by
= State
.regs
[ OP
[0] ] & 0xffff;
2274 divide_this
= State
.regs
[ OP
[1] ] << imm5
;
2276 divun (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2278 State
.regs
[ OP
[1] ] = quotient
;
2279 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2281 /* Set condition codes. */
2282 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2284 if (overflow
) PSW
|= PSW_OV
;
2285 if (quotient
== 0) PSW
|= PSW_Z
;
2286 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2288 trace_output (OP_IMM_REG_REG_REG
);
2293 /* sdivhn imm5, reg1, reg2, reg3 */
2297 int32_t /*signed long int*/ quotient
;
2298 int32_t /*signed long int*/ remainder
;
2299 signed long int divide_by
;
2300 signed long int divide_this
;
2304 trace_input ("sdivhn", OP_IMM_REG_REG_REG
, 0);
2306 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2308 divide_by
= EXTEND16 (State
.regs
[ OP
[0] ]);
2309 divide_this
= (int32_t) (State
.regs
[ OP
[1] ] << imm5
);
2311 divn (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2313 State
.regs
[ OP
[1] ] = quotient
;
2314 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2316 /* Set condition codes. */
2317 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2319 if (overflow
) PSW
|= PSW_OV
;
2320 if (quotient
== 0) PSW
|= PSW_Z
;
2321 if (quotient
< 0) PSW
|= PSW_S
;
2323 trace_output (OP_IMM_REG_REG_REG
);
2328 /* divu reg1, reg2, reg3 */
2332 unsigned long int quotient
;
2333 unsigned long int remainder
;
2334 unsigned long int divide_by
;
2335 unsigned long int divide_this
;
2338 trace_input ("divu", OP_REG_REG_REG
, 0);
2340 /* Compute the result. */
2342 divide_by
= State
.regs
[ OP
[0] ];
2343 divide_this
= State
.regs
[ OP
[1] ];
2351 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
2352 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
2354 /* Set condition codes. */
2355 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2357 if (overflow
) PSW
|= PSW_OV
;
2358 if (quotient
== 0) PSW
|= PSW_Z
;
2359 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2362 trace_output (OP_REG_REG_REG
);
2367 /* div reg1, reg2, reg3 */
2371 signed long int quotient
;
2372 signed long int remainder
;
2373 signed long int divide_by
;
2374 signed long int divide_this
;
2376 trace_input ("div", OP_REG_REG_REG
, 0);
2378 /* Compute the result. */
2380 divide_by
= (int32_t) State
.regs
[ OP
[0] ];
2381 divide_this
= State
.regs
[ OP
[1] ];
2387 else if (divide_by
== -1 && divide_this
== (1L << 31))
2390 PSW
|= PSW_OV
| PSW_S
;
2391 State
.regs
[ OP
[1] ] = (1 << 31);
2392 State
.regs
[ OP
[2] >> 11 ] = 0;
2396 divide_this
= (int32_t) divide_this
;
2397 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
2398 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
2400 /* Set condition codes. */
2401 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2403 if (quotient
== 0) PSW
|= PSW_Z
;
2404 if (quotient
< 0) PSW
|= PSW_S
;
2407 trace_output (OP_REG_REG_REG
);
2412 /* divhu reg1, reg2, reg3 */
2416 unsigned long int quotient
;
2417 unsigned long int remainder
;
2418 unsigned long int divide_by
;
2419 unsigned long int divide_this
;
2422 trace_input ("divhu", OP_REG_REG_REG
, 0);
2424 /* Compute the result. */
2426 divide_by
= State
.regs
[ OP
[0] ] & 0xffff;
2427 divide_this
= State
.regs
[ OP
[1] ];
2435 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
2436 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
2438 /* Set condition codes. */
2439 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2441 if (overflow
) PSW
|= PSW_OV
;
2442 if (quotient
== 0) PSW
|= PSW_Z
;
2443 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2446 trace_output (OP_REG_REG_REG
);
2451 /* divh reg1, reg2, reg3 */
2455 signed long int quotient
;
2456 signed long int remainder
;
2457 signed long int divide_by
;
2458 signed long int divide_this
;
2461 trace_input ("divh", OP_REG_REG_REG
, 0);
2463 /* Compute the result. */
2465 divide_by
= EXTEND16 (State
.regs
[ OP
[0] ]);
2466 divide_this
= State
.regs
[ OP
[1] ];
2472 else if (divide_by
== -1 && divide_this
== (1L << 31))
2475 PSW
|= PSW_OV
| PSW_S
;
2476 State
.regs
[ OP
[1] ] = (1 << 31);
2477 State
.regs
[ OP
[2] >> 11 ] = 0;
2481 divide_this
= (int32_t) divide_this
;
2482 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
2483 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
2485 /* Set condition codes. */
2486 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2488 if (quotient
== 0) PSW
|= PSW_Z
;
2489 if (quotient
< 0) PSW
|= PSW_S
;
2492 trace_output (OP_REG_REG_REG
);
2497 /* mulu imm9, reg2, reg3 */
2501 trace_input ("mulu", OP_IMM_REG_REG
, 0);
2503 Multiply64 (0, (OP
[3] & 0x1f) | ((OP
[3] >> 13) & 0x1e0));
2505 trace_output (OP_IMM_REG_REG
);
2510 /* mul imm9, reg2, reg3 */
2514 trace_input ("mul", OP_IMM_REG_REG
, 0);
2516 Multiply64 (1, SEXT9 ((OP
[3] & 0x1f) | ((OP
[3] >> 13) & 0x1e0)));
2518 trace_output (OP_IMM_REG_REG
);
2529 trace_input ("ld.hu", OP_LOAD32
, 2);
2531 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2] & ~1);
2534 State
.regs
[ OP
[1] ] = load_mem (adr
, 2);
2536 trace_output (OP_LOAD32
);
2548 trace_input ("ld.bu", OP_LOAD32
, 1);
2550 adr
= (State
.regs
[ OP
[0] ]
2551 + (EXTEND16 (OP
[2] & ~1) | ((OP
[3] >> 5) & 1)));
2553 State
.regs
[ OP
[1] ] = load_mem (adr
, 1);
2555 trace_output (OP_LOAD32
);
2560 /* prepare list12, imm5, imm32 */
2566 trace_input ("prepare", OP_PUSHPOP1
, 0);
2568 /* Store the registers with lower number registers being placed at higher addresses. */
2569 for (i
= 0; i
< 12; i
++)
2570 if ((OP
[3] & (1 << type1_regs
[ i
])))
2573 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
2576 SP
-= (OP
[3] & 0x3e) << 1;
2578 EP
= load_mem (PC
+ 4, 4);
2580 trace_output (OP_PUSHPOP1
);
2585 /* prepare list12, imm5, imm16-32 */
2591 trace_input ("prepare", OP_PUSHPOP1
, 0);
2593 /* Store the registers with lower number registers being placed at higher addresses. */
2594 for (i
= 0; i
< 12; i
++)
2595 if ((OP
[3] & (1 << type1_regs
[ i
])))
2598 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
2601 SP
-= (OP
[3] & 0x3e) << 1;
2603 EP
= load_mem (PC
+ 4, 2) << 16;
2605 trace_output (OP_PUSHPOP1
);
2610 /* prepare list12, imm5, imm16 */
2616 trace_input ("prepare", OP_PUSHPOP1
, 0);
2618 /* Store the registers with lower number registers being placed at higher addresses. */
2619 for (i
= 0; i
< 12; i
++)
2620 if ((OP
[3] & (1 << type1_regs
[ i
])))
2623 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
2626 SP
-= (OP
[3] & 0x3e) << 1;
2628 EP
= EXTEND16 (load_mem (PC
+ 4, 2));
2630 trace_output (OP_PUSHPOP1
);
2635 /* prepare list12, imm5, sp */
2641 trace_input ("prepare", OP_PUSHPOP1
, 0);
2643 /* Store the registers with lower number registers being placed at higher addresses. */
2644 for (i
= 0; i
< 12; i
++)
2645 if ((OP
[3] & (1 << type1_regs
[ i
])))
2648 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
2651 SP
-= (OP
[3] & 0x3e) << 1;
2655 trace_output (OP_PUSHPOP1
);
2660 /* mul reg1, reg2, reg3 */
2664 trace_input ("mul", OP_REG_REG_REG
, 0);
2666 Multiply64 (1, State
.regs
[ OP
[0] ]);
2668 trace_output (OP_REG_REG_REG
);
2679 trace_input ("popmh", OP_PUSHPOP2
, 0);
2681 if (OP
[3] & (1 << 19))
2683 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
2685 FEPSW
= load_mem ( SP
& ~ 3, 4);
2686 FEPC
= load_mem ((SP
+ 4) & ~ 3, 4);
2690 EIPSW
= load_mem ( SP
& ~ 3, 4);
2691 EIPC
= load_mem ((SP
+ 4) & ~ 3, 4);
2697 /* Load the registers with lower number registers being retrieved from higher addresses. */
2699 if ((OP
[3] & (1 << type2_regs
[ i
])))
2701 State
.regs
[ i
+ 16 ] = load_mem (SP
& ~ 3, 4);
2705 trace_output (OP_PUSHPOP2
);
2716 trace_input ("popml", OP_PUSHPOP3
, 0);
2718 if (OP
[3] & (1 << 19))
2720 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
2722 FEPSW
= load_mem ( SP
& ~ 3, 4);
2723 FEPC
= load_mem ((SP
+ 4) & ~ 3, 4);
2727 EIPSW
= load_mem ( SP
& ~ 3, 4);
2728 EIPC
= load_mem ((SP
+ 4) & ~ 3, 4);
2734 if (OP
[3] & (1 << 3))
2736 PSW
= load_mem (SP
& ~ 3, 4);
2740 /* Load the registers with lower number registers being retrieved from higher addresses. */
2742 if ((OP
[3] & (1 << type3_regs
[ i
])))
2744 State
.regs
[ i
+ 1 ] = load_mem (SP
& ~ 3, 4);
2748 trace_output (OP_PUSHPOP2
);
2759 trace_input ("pushmh", OP_PUSHPOP2
, 0);
2761 /* Store the registers with lower number registers being placed at higher addresses. */
2762 for (i
= 0; i
< 16; i
++)
2763 if ((OP
[3] & (1 << type2_regs
[ i
])))
2766 store_mem (SP
& ~ 3, 4, State
.regs
[ i
+ 16 ]);
2769 if (OP
[3] & (1 << 19))
2773 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
2775 store_mem ((SP
+ 4) & ~ 3, 4, FEPC
);
2776 store_mem ( SP
& ~ 3, 4, FEPSW
);
2780 store_mem ((SP
+ 4) & ~ 3, 4, EIPC
);
2781 store_mem ( SP
& ~ 3, 4, EIPSW
);
2785 trace_output (OP_PUSHPOP2
);
2790 /* V850E2R FPU functions */
2792 sim_fpu_status_invalid_snan = 1, -V--- (sim spec.)
2793 sim_fpu_status_invalid_qnan = 2, ----- (sim spec.)
2794 sim_fpu_status_invalid_isi = 4, (inf - inf) -V---
2795 sim_fpu_status_invalid_idi = 8, (inf / inf) -V---
2796 sim_fpu_status_invalid_zdz = 16, (0 / 0) -V---
2797 sim_fpu_status_invalid_imz = 32, (inf * 0) -V---
2798 sim_fpu_status_invalid_cvi = 64, convert to integer -V---
2799 sim_fpu_status_invalid_div0 = 128, (X / 0) --Z--
2800 sim_fpu_status_invalid_cmp = 256, compare ----- (sim spec.)
2801 sim_fpu_status_invalid_sqrt = 512, -V---
2802 sim_fpu_status_rounded = 1024, I----
2803 sim_fpu_status_inexact = 2048, I---- (sim spec.)
2804 sim_fpu_status_overflow = 4096, I--O-
2805 sim_fpu_status_underflow = 8192, I---U
2806 sim_fpu_status_denorm = 16384, ----U (sim spec.)
2810 update_fpsr (SIM_DESC sd
, sim_fpu_status status
, unsigned int mask
, unsigned int double_op_p
)
2812 unsigned int fpsr
= FPSR
& mask
;
2814 unsigned int flags
= 0;
2817 && ((status
& (sim_fpu_status_rounded
2818 | sim_fpu_status_overflow
2819 | sim_fpu_status_inexact
))
2820 || (status
& sim_fpu_status_underflow
2821 && (fpsr
& (FPSR_XEU
| FPSR_XEI
)) == 0
2822 && fpsr
& FPSR_FS
)))
2824 flags
|= FPSR_XCI
| FPSR_XPI
;
2828 && (status
& (sim_fpu_status_invalid_isi
2829 | sim_fpu_status_invalid_imz
2830 | sim_fpu_status_invalid_zdz
2831 | sim_fpu_status_invalid_idi
2832 | sim_fpu_status_invalid_cvi
2833 | sim_fpu_status_invalid_sqrt
2834 | sim_fpu_status_invalid_snan
)))
2836 flags
|= FPSR_XCV
| FPSR_XPV
;
2840 && (status
& sim_fpu_status_invalid_div0
))
2842 flags
|= FPSR_XCV
| FPSR_XPV
;
2846 && (status
& sim_fpu_status_overflow
))
2848 flags
|= FPSR_XCO
| FPSR_XPO
;
2851 if (((fpsr
& FPSR_XEU
) || (fpsr
& FPSR_FS
) == 0)
2852 && (status
& (sim_fpu_status_underflow
2853 | sim_fpu_status_denorm
)))
2855 flags
|= FPSR_XCU
| FPSR_XPU
;
2863 SignalExceptionFPE (sd
, double_op_p
);
2870 SignalException (SIM_DESC sd
)
2874 PSW
= PSW
& ~(PSW_NPV
| PSW_DMP
| PSW_IMP
);
2879 SignalExceptionFPE (SIM_DESC sd
, unsigned int double_op_p
)
2881 if (((PSW
& (PSW_NP
|PSW_ID
)) == 0)
2882 || !(FPSR
& (double_op_p
? FPSR_DEM
: FPSR_SEM
)))
2886 EIIC
= (FPSR
& (double_op_p
? FPSR_DEM
: FPSR_SEM
))
2888 PSW
|= (PSW_EP
| PSW_ID
);
2891 SignalException (sd
);
2896 check_invalid_snan (SIM_DESC sd
, sim_fpu_status status
, unsigned int double_op_p
)
2898 if ((FPSR
& FPSR_XEI
)
2899 && (status
& sim_fpu_status_invalid_snan
))
2904 SignalExceptionFPE (sd
, double_op_p
);
2909 v850_float_compare (SIM_DESC sd
, int cmp
, sim_fpu wop1
, sim_fpu wop2
, int double_op_p
)
2913 if (sim_fpu_is_nan (&wop1
) || sim_fpu_is_nan (&wop2
))
2917 if (FPSR
& FPSR_XEV
)
2919 FPSR
|= FPSR_XCV
| FPSR_XPV
;
2920 SignalExceptionFPE (sd
, double_op_p
);
2978 else if (sim_fpu_is_infinity (&wop1
) && sim_fpu_is_infinity (&wop2
)
2979 && sim_fpu_sign (&wop1
) == sim_fpu_sign (&wop2
))
3037 int gt
= 0,lt
= 0,eq
= 0, status
;
3039 status
= sim_fpu_cmp (&wop1
, &wop2
);
3043 case SIM_FPU_IS_SNAN
:
3044 case SIM_FPU_IS_QNAN
:
3048 case SIM_FPU_IS_NINF
:
3051 case SIM_FPU_IS_PINF
:
3054 case SIM_FPU_IS_NNUMBER
:
3057 case SIM_FPU_IS_PNUMBER
:
3060 case SIM_FPU_IS_NDENORM
:
3063 case SIM_FPU_IS_PDENORM
:
3066 case SIM_FPU_IS_NZERO
:
3067 case SIM_FPU_IS_PZERO
:
3125 ASSERT (result
!= -1);
3130 v850_div (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
, unsigned int *op3p
)
3132 signed long int quotient
;
3133 signed long int remainder
;
3134 signed long int divide_by
;
3135 signed long int divide_this
;
3136 bfd_boolean overflow
= FALSE
;
3138 /* Compute the result. */
3139 divide_by
= (int32_t)op0
;
3140 divide_this
= (int32_t)op1
;
3142 if (divide_by
== 0 || (divide_by
== -1 && divide_this
== (1 << 31)))
3148 quotient
= divide_this
/ divide_by
;
3149 remainder
= divide_this
% divide_by
;
3151 /* Set condition codes. */
3152 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3154 if (overflow
) PSW
|= PSW_OV
;
3155 if (quotient
== 0) PSW
|= PSW_Z
;
3156 if (quotient
< 0) PSW
|= PSW_S
;
3163 v850_divu (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
, unsigned int *op3p
)
3165 unsigned long int quotient
;
3166 unsigned long int remainder
;
3167 unsigned long int divide_by
;
3168 unsigned long int divide_this
;
3169 bfd_boolean overflow
= FALSE
;
3171 /* Compute the result. */
3182 quotient
= divide_this
/ divide_by
;
3183 remainder
= divide_this
% divide_by
;
3185 /* Set condition codes. */
3186 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3188 if (overflow
) PSW
|= PSW_OV
;
3189 if (quotient
== 0) PSW
|= PSW_Z
;
3190 if (quotient
& 0x80000000) PSW
|= PSW_S
;
3197 v850_sar (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3199 unsigned int result
, z
, s
, cy
;
3202 result
= (signed)op1
>> op0
;
3204 /* Compute the condition codes. */
3206 s
= (result
& 0x80000000);
3207 cy
= (op1
& (1 << (op0
- 1)));
3209 /* Store the result and condition codes. */
3210 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
3211 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3212 | (cy
? PSW_CY
: 0));
3218 v850_shl (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3220 unsigned int result
, z
, s
, cy
;
3223 result
= op1
<< op0
;
3225 /* Compute the condition codes. */
3227 s
= (result
& 0x80000000);
3228 cy
= (op1
& (1 << (32 - op0
)));
3230 /* Store the result and condition codes. */
3231 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
3232 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3233 | (cy
? PSW_CY
: 0));
3239 v850_rotl (SIM_DESC sd
, unsigned int amount
, unsigned int src
, unsigned int * dest
)
3241 unsigned int result
, z
, s
, cy
;
3244 result
= src
<< amount
;
3245 result
|= src
>> (32 - amount
);
3247 /* Compute the condition codes. */
3249 s
= (result
& 0x80000000);
3250 cy
= ! (result
& 1);
3252 /* Store the result and condition codes. */
3253 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
3254 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3255 | (cy
? PSW_CY
: 0));
3261 v850_bins (SIM_DESC sd
, unsigned int source
, unsigned int lsb
, unsigned int msb
,
3262 unsigned int * dest
)
3265 unsigned int result
, pos
, width
;
3269 width
= (msb
- lsb
) + 1;
3271 /* A width of 32 exhibits undefined behavior on the shift. The easiest
3272 way to make this code safe is to just avoid that case and set the mask
3273 to the right value. */
3277 mask
= ~ (-(1 << width
));
3281 result
= (* dest
) & ~ mask
;
3282 result
|= source
<< pos
;
3284 /* Compute the condition codes. */
3286 s
= result
& 0x80000000;
3288 /* Store the result and condition codes. */
3289 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3290 PSW
|= (z
? PSW_Z
: 0) | (s
? PSW_S
: 0);
3296 v850_shr (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3298 unsigned int result
, z
, s
, cy
;
3301 result
= op1
>> op0
;
3303 /* Compute the condition codes. */
3305 s
= (result
& 0x80000000);
3306 cy
= (op1
& (1 << (op0
- 1)));
3308 /* Store the result and condition codes. */
3309 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
3310 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3311 | (cy
? PSW_CY
: 0));
3317 v850_satadd (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3319 unsigned int result
, z
, s
, cy
, ov
, sat
;
3323 /* Compute the condition codes. */
3325 s
= (result
& 0x80000000);
3326 cy
= (result
< op0
|| result
< op1
);
3327 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
3328 && (op0
& 0x80000000) != (result
& 0x80000000));
3331 /* Store the result and condition codes. */
3332 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
3333 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3334 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
3335 | (sat
? PSW_SAT
: 0));
3337 /* Handle saturated results. */
3340 result
= 0x7fffffff;
3345 result
= 0x80000000;
3353 v850_satsub (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3355 unsigned int result
, z
, s
, cy
, ov
, sat
;
3357 /* Compute the result. */
3360 /* Compute the condition codes. */
3362 s
= (result
& 0x80000000);
3364 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
3365 && (op1
& 0x80000000) != (result
& 0x80000000));
3368 /* Store the result and condition codes. */
3369 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
3370 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3371 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
3372 | (sat
? PSW_SAT
: 0));
3374 /* Handle saturated results. */
3377 result
= 0x7fffffff;
3382 result
= 0x80000000;
3390 load_data_mem (SIM_DESC sd
,
3399 data
= sim_core_read_unaligned_1 (STATE_CPU (sd
, 0),
3400 PC
, read_map
, addr
);
3403 data
= sim_core_read_unaligned_2 (STATE_CPU (sd
, 0),
3404 PC
, read_map
, addr
);
3407 data
= sim_core_read_unaligned_4 (STATE_CPU (sd
, 0),
3408 PC
, read_map
, addr
);
3417 store_data_mem (SIM_DESC sd
,
3425 store_mem (addr
, 1, data
);
3428 store_mem (addr
, 2, data
);
3431 store_mem (addr
, 4, data
);
3439 mpu_load_mem_test (SIM_DESC sd
, unsigned int addr
, int size
, int base_reg
)
3445 if (IPE0
&& addr
>= IPA2ADDR (IPA0L
) && addr
<= IPA2ADDR (IPA0L
) && IPR0
)
3449 else if (IPE1
&& addr
>= IPA2ADDR (IPA1L
) && addr
<= IPA2ADDR (IPA1L
) && IPR1
)
3453 else if (IPE2
&& addr
>= IPA2ADDR (IPA2L
) && addr
<= IPA2ADDR (IPA2L
) && IPR2
)
3457 else if (IPE3
&& addr
>= IPA2ADDR (IPA3L
) && addr
<= IPA2ADDR (IPA3L
) && IPR3
)
3461 else if (addr
>= PPA2ADDR (PPA
& ~PPM
) && addr
<= DPA2ADDR (PPA
| PPM
))
3463 /* preifarallel area */
3465 else if (addr
>= PPA2ADDR (SPAL
) && addr
<= DPA2ADDR (SPAU
))
3469 else if (DPE0
&& addr
>= DPA2ADDR (DPA0L
) && addr
<= DPA2ADDR (DPA0L
) && DPR0
3470 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3474 else if (DPE1
&& addr
>= DPA2ADDR (DPA1L
) && addr
<= DPA2ADDR (DPA1L
) && DPR1
3475 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3479 else if (DPE2
&& addr
>= DPA2ADDR (DPA2L
) && addr
<= DPA2ADDR (DPA2L
) && DPR2
3480 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3484 else if (DPE3
&& addr
>= DPA2ADDR (DPA3L
) && addr
<= DPA2ADDR (DPA3L
) && DPR3
3485 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3491 VMECR
&= ~(VMECR_VMW
| VMECR_VMX
);
3499 SignalException (sd
);
3508 mpu_store_mem_test (SIM_DESC sd
, unsigned int addr
, int size
, int base_reg
)
3514 if (addr
>= PPA2ADDR (PPA
& ~PPM
) && addr
<= DPA2ADDR (PPA
| PPM
))
3516 /* preifarallel area */
3518 else if (addr
>= PPA2ADDR (SPAL
) && addr
<= DPA2ADDR (SPAU
))
3522 else if (DPE0
&& addr
>= DPA2ADDR (DPA0L
) && addr
<= DPA2ADDR (DPA0L
) && DPW0
3523 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3527 else if (DPE1
&& addr
>= DPA2ADDR (DPA1L
) && addr
<= DPA2ADDR (DPA1L
) && DPW1
3528 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3532 else if (DPE2
&& addr
>= DPA2ADDR (DPA2L
) && addr
<= DPA2ADDR (DPA2L
) && DPW2
3533 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3537 else if (DPE3
&& addr
>= DPA2ADDR (DPA3L
) && addr
<= DPA2ADDR (DPA3L
) && DPW3
3538 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3544 if (addr
>= PPA2ADDR (PPA
& ~PPM
) && addr
<= DPA2ADDR (PPA
| PPM
))
3559 VMECR
&= ~(VMECR_VMW
| VMECR_VMX
);