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;
2110 unsigned long alt
= Q
? ~als
: als
;
2115 alo
= ald
+ alt
+ Q
;
2116 C
= (((alt
>> 31) & (ald
>> 31))
2117 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2119 R1
= (alo
== 0) ? 0 : (R1
& (Q
^ (SS
^ SD
)));
2120 /* S = alo >> 31; */
2121 sfi
= (sfi
<< (32-N
+1)) | Q
;
2122 ald
= (alo
<< 1) | (sfi
>> 31);
2123 if ((alo
>> 31) ^ (ald
>> 31))
2128 /* 2nd - N-1th Loop */
2130 for (i
= 2; i
< N
; i
++)
2132 alt
= Q
? ~als
: als
;
2133 alo
= ald
+ alt
+ Q
;
2134 C
= (((alt
>> 31) & (ald
>> 31))
2135 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2137 R1
= (alo
== 0) ? 0 : (R1
& (Q
^ (SS
^ SD
)));
2138 /* S = alo >> 31; */
2139 sfi
= (sfi
<< 1) | Q
;
2140 ald
= (alo
<< 1) | (sfi
>> 31);
2141 if ((alo
>> 31) ^ (ald
>> 31))
2148 alt
= Q
? ~als
: als
;
2149 alo
= ald
+ alt
+ Q
;
2150 C
= (((alt
>> 31) & (ald
>> 31))
2151 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2153 R1
= (alo
== 0) ? 0 : (R1
& (Q
^ (SS
^ SD
)));
2154 sfi
= (sfi
<< (32-N
+1));
2160 alt
= Q
? ~als
: als
;
2161 alo
= ald
+ alt
+ Q
;
2163 R1
= R1
& ((~alo
>> 31) ^ SD
);
2164 if ((alo
!= 0) && ((Q
^ (SS
^ SD
)) ^ R1
)) alo
= ald
;
2166 ald
= sfi
= (long) ((sfi
>> 1) | (SS
^ SD
) << 31) >> (32-N
-1) | Q
;
2168 ald
= sfi
= sfi
| Q
;
2170 OV
= DBZ
| ((alo
== 0) ? 0 : R1
);
2172 * remainder_ptr
= alo
;
2175 if (((alo
!= 0) && ((SS
^ SD
) ^ R1
))
2176 || ((alo
== 0) && (SS
^ R1
)))
2181 OV
= (DBZ
| R1
) ? OV
: ((alo
>> 31) & (~ald
>> 31));
2183 * quotient_ptr
= alo
;
2184 * overflow_ptr
= OV
;
2187 /* sdivun imm5, reg1, reg2, reg3 */
2191 uint32_t /*unsigned long int*/ quotient
;
2192 uint32_t /*unsigned long int*/ remainder
;
2193 unsigned long int divide_by
;
2194 unsigned long int divide_this
;
2198 trace_input ("sdivun", OP_IMM_REG_REG_REG
, 0);
2200 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2202 divide_by
= State
.regs
[ OP
[0] ];
2203 divide_this
= State
.regs
[ OP
[1] ] << imm5
;
2205 divun (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2207 State
.regs
[ OP
[1] ] = quotient
;
2208 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2210 /* Set condition codes. */
2211 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2213 if (overflow
) PSW
|= PSW_OV
;
2214 if (quotient
== 0) PSW
|= PSW_Z
;
2215 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2217 trace_output (OP_IMM_REG_REG_REG
);
2222 /* sdivn imm5, reg1, reg2, reg3 */
2226 int32_t /*signed long int*/ quotient
;
2227 int32_t /*signed long int*/ remainder
;
2228 signed long int divide_by
;
2229 signed long int divide_this
;
2233 trace_input ("sdivn", OP_IMM_REG_REG_REG
, 0);
2235 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2237 divide_by
= (int32_t) State
.regs
[ OP
[0] ];
2238 divide_this
= (int32_t) (State
.regs
[ OP
[1] ] << imm5
);
2240 divn (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2242 State
.regs
[ OP
[1] ] = quotient
;
2243 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2245 /* Set condition codes. */
2246 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2248 if (overflow
) PSW
|= PSW_OV
;
2249 if (quotient
== 0) PSW
|= PSW_Z
;
2250 if (quotient
< 0) PSW
|= PSW_S
;
2252 trace_output (OP_IMM_REG_REG_REG
);
2257 /* sdivhun imm5, reg1, reg2, reg3 */
2261 uint32_t /*unsigned long int*/ quotient
;
2262 uint32_t /*unsigned long int*/ remainder
;
2263 unsigned long int divide_by
;
2264 unsigned long int divide_this
;
2268 trace_input ("sdivhun", OP_IMM_REG_REG_REG
, 0);
2270 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2272 divide_by
= State
.regs
[ OP
[0] ] & 0xffff;
2273 divide_this
= State
.regs
[ OP
[1] ] << imm5
;
2275 divun (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2277 State
.regs
[ OP
[1] ] = quotient
;
2278 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2280 /* Set condition codes. */
2281 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2283 if (overflow
) PSW
|= PSW_OV
;
2284 if (quotient
== 0) PSW
|= PSW_Z
;
2285 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2287 trace_output (OP_IMM_REG_REG_REG
);
2292 /* sdivhn imm5, reg1, reg2, reg3 */
2296 int32_t /*signed long int*/ quotient
;
2297 int32_t /*signed long int*/ remainder
;
2298 signed long int divide_by
;
2299 signed long int divide_this
;
2303 trace_input ("sdivhn", OP_IMM_REG_REG_REG
, 0);
2305 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2307 divide_by
= EXTEND16 (State
.regs
[ OP
[0] ]);
2308 divide_this
= (int32_t) (State
.regs
[ OP
[1] ] << imm5
);
2310 divn (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2312 State
.regs
[ OP
[1] ] = quotient
;
2313 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2315 /* Set condition codes. */
2316 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2318 if (overflow
) PSW
|= PSW_OV
;
2319 if (quotient
== 0) PSW
|= PSW_Z
;
2320 if (quotient
< 0) PSW
|= PSW_S
;
2322 trace_output (OP_IMM_REG_REG_REG
);
2327 /* divu reg1, reg2, reg3 */
2331 unsigned long int quotient
;
2332 unsigned long int remainder
;
2333 unsigned long int divide_by
;
2334 unsigned long int divide_this
;
2337 trace_input ("divu", OP_REG_REG_REG
, 0);
2339 /* Compute the result. */
2341 divide_by
= State
.regs
[ OP
[0] ];
2342 divide_this
= State
.regs
[ OP
[1] ];
2350 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
2351 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
2353 /* Set condition codes. */
2354 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2356 if (overflow
) PSW
|= PSW_OV
;
2357 if (quotient
== 0) PSW
|= PSW_Z
;
2358 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2361 trace_output (OP_REG_REG_REG
);
2366 /* div reg1, reg2, reg3 */
2370 signed long int quotient
;
2371 signed long int remainder
;
2372 signed long int divide_by
;
2373 signed long int divide_this
;
2375 trace_input ("div", OP_REG_REG_REG
, 0);
2377 /* Compute the result. */
2379 divide_by
= (int32_t) State
.regs
[ OP
[0] ];
2380 divide_this
= State
.regs
[ OP
[1] ];
2386 else if (divide_by
== -1 && divide_this
== (1L << 31))
2389 PSW
|= PSW_OV
| PSW_S
;
2390 State
.regs
[ OP
[1] ] = (1 << 31);
2391 State
.regs
[ OP
[2] >> 11 ] = 0;
2395 divide_this
= (int32_t) divide_this
;
2396 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
2397 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
2399 /* Set condition codes. */
2400 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2402 if (quotient
== 0) PSW
|= PSW_Z
;
2403 if (quotient
< 0) PSW
|= PSW_S
;
2406 trace_output (OP_REG_REG_REG
);
2411 /* divhu reg1, reg2, reg3 */
2415 unsigned long int quotient
;
2416 unsigned long int remainder
;
2417 unsigned long int divide_by
;
2418 unsigned long int divide_this
;
2421 trace_input ("divhu", OP_REG_REG_REG
, 0);
2423 /* Compute the result. */
2425 divide_by
= State
.regs
[ OP
[0] ] & 0xffff;
2426 divide_this
= State
.regs
[ OP
[1] ];
2434 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
2435 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
2437 /* Set condition codes. */
2438 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2440 if (overflow
) PSW
|= PSW_OV
;
2441 if (quotient
== 0) PSW
|= PSW_Z
;
2442 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2445 trace_output (OP_REG_REG_REG
);
2450 /* divh reg1, reg2, reg3 */
2454 signed long int quotient
;
2455 signed long int remainder
;
2456 signed long int divide_by
;
2457 signed long int divide_this
;
2459 trace_input ("divh", OP_REG_REG_REG
, 0);
2461 /* Compute the result. */
2463 divide_by
= EXTEND16 (State
.regs
[ OP
[0] ]);
2464 divide_this
= State
.regs
[ OP
[1] ];
2470 else if (divide_by
== -1 && divide_this
== (1L << 31))
2473 PSW
|= PSW_OV
| PSW_S
;
2474 State
.regs
[ OP
[1] ] = (1 << 31);
2475 State
.regs
[ OP
[2] >> 11 ] = 0;
2479 divide_this
= (int32_t) divide_this
;
2480 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
2481 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
2483 /* Set condition codes. */
2484 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2486 if (quotient
== 0) PSW
|= PSW_Z
;
2487 if (quotient
< 0) PSW
|= PSW_S
;
2490 trace_output (OP_REG_REG_REG
);
2495 /* mulu imm9, reg2, reg3 */
2499 trace_input ("mulu", OP_IMM_REG_REG
, 0);
2501 Multiply64 (0, (OP
[3] & 0x1f) | ((OP
[3] >> 13) & 0x1e0));
2503 trace_output (OP_IMM_REG_REG
);
2508 /* mul imm9, reg2, reg3 */
2512 trace_input ("mul", OP_IMM_REG_REG
, 0);
2514 Multiply64 (1, SEXT9 ((OP
[3] & 0x1f) | ((OP
[3] >> 13) & 0x1e0)));
2516 trace_output (OP_IMM_REG_REG
);
2527 trace_input ("ld.hu", OP_LOAD32
, 2);
2529 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2] & ~1);
2532 State
.regs
[ OP
[1] ] = load_mem (adr
, 2);
2534 trace_output (OP_LOAD32
);
2546 trace_input ("ld.bu", OP_LOAD32
, 1);
2548 adr
= (State
.regs
[ OP
[0] ]
2549 + (EXTEND16 (OP
[2] & ~1) | ((OP
[3] >> 5) & 1)));
2551 State
.regs
[ OP
[1] ] = load_mem (adr
, 1);
2553 trace_output (OP_LOAD32
);
2558 /* prepare list12, imm5, imm32 */
2564 trace_input ("prepare", OP_PUSHPOP1
, 0);
2566 /* Store the registers with lower number registers being placed at higher addresses. */
2567 for (i
= 0; i
< 12; i
++)
2568 if ((OP
[3] & (1 << type1_regs
[ i
])))
2571 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
2574 SP
-= (OP
[3] & 0x3e) << 1;
2576 EP
= load_mem (PC
+ 4, 4);
2578 trace_output (OP_PUSHPOP1
);
2583 /* prepare list12, imm5, imm16-32 */
2589 trace_input ("prepare", OP_PUSHPOP1
, 0);
2591 /* Store the registers with lower number registers being placed at higher addresses. */
2592 for (i
= 0; i
< 12; i
++)
2593 if ((OP
[3] & (1 << type1_regs
[ i
])))
2596 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
2599 SP
-= (OP
[3] & 0x3e) << 1;
2601 EP
= load_mem (PC
+ 4, 2) << 16;
2603 trace_output (OP_PUSHPOP1
);
2608 /* prepare list12, imm5, imm16 */
2614 trace_input ("prepare", OP_PUSHPOP1
, 0);
2616 /* Store the registers with lower number registers being placed at higher addresses. */
2617 for (i
= 0; i
< 12; i
++)
2618 if ((OP
[3] & (1 << type1_regs
[ i
])))
2621 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
2624 SP
-= (OP
[3] & 0x3e) << 1;
2626 EP
= EXTEND16 (load_mem (PC
+ 4, 2));
2628 trace_output (OP_PUSHPOP1
);
2633 /* prepare list12, imm5, sp */
2639 trace_input ("prepare", OP_PUSHPOP1
, 0);
2641 /* Store the registers with lower number registers being placed at higher addresses. */
2642 for (i
= 0; i
< 12; i
++)
2643 if ((OP
[3] & (1 << type1_regs
[ i
])))
2646 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
2649 SP
-= (OP
[3] & 0x3e) << 1;
2653 trace_output (OP_PUSHPOP1
);
2658 /* mul reg1, reg2, reg3 */
2662 trace_input ("mul", OP_REG_REG_REG
, 0);
2664 Multiply64 (1, State
.regs
[ OP
[0] ]);
2666 trace_output (OP_REG_REG_REG
);
2677 trace_input ("popmh", OP_PUSHPOP2
, 0);
2679 if (OP
[3] & (1 << 19))
2681 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
2683 FEPSW
= load_mem ( SP
& ~ 3, 4);
2684 FEPC
= load_mem ((SP
+ 4) & ~ 3, 4);
2688 EIPSW
= load_mem ( SP
& ~ 3, 4);
2689 EIPC
= load_mem ((SP
+ 4) & ~ 3, 4);
2695 /* Load the registers with lower number registers being retrieved from higher addresses. */
2697 if ((OP
[3] & (1 << type2_regs
[ i
])))
2699 State
.regs
[ i
+ 16 ] = load_mem (SP
& ~ 3, 4);
2703 trace_output (OP_PUSHPOP2
);
2714 trace_input ("popml", OP_PUSHPOP3
, 0);
2716 if (OP
[3] & (1 << 19))
2718 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
2720 FEPSW
= load_mem ( SP
& ~ 3, 4);
2721 FEPC
= load_mem ((SP
+ 4) & ~ 3, 4);
2725 EIPSW
= load_mem ( SP
& ~ 3, 4);
2726 EIPC
= load_mem ((SP
+ 4) & ~ 3, 4);
2732 if (OP
[3] & (1 << 3))
2734 PSW
= load_mem (SP
& ~ 3, 4);
2738 /* Load the registers with lower number registers being retrieved from higher addresses. */
2740 if ((OP
[3] & (1 << type3_regs
[ i
])))
2742 State
.regs
[ i
+ 1 ] = load_mem (SP
& ~ 3, 4);
2746 trace_output (OP_PUSHPOP2
);
2757 trace_input ("pushmh", OP_PUSHPOP2
, 0);
2759 /* Store the registers with lower number registers being placed at higher addresses. */
2760 for (i
= 0; i
< 16; i
++)
2761 if ((OP
[3] & (1 << type2_regs
[ i
])))
2764 store_mem (SP
& ~ 3, 4, State
.regs
[ i
+ 16 ]);
2767 if (OP
[3] & (1 << 19))
2771 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
2773 store_mem ((SP
+ 4) & ~ 3, 4, FEPC
);
2774 store_mem ( SP
& ~ 3, 4, FEPSW
);
2778 store_mem ((SP
+ 4) & ~ 3, 4, EIPC
);
2779 store_mem ( SP
& ~ 3, 4, EIPSW
);
2783 trace_output (OP_PUSHPOP2
);
2788 /* V850E2R FPU functions */
2790 sim_fpu_status_invalid_snan = 1, -V--- (sim spec.)
2791 sim_fpu_status_invalid_qnan = 2, ----- (sim spec.)
2792 sim_fpu_status_invalid_isi = 4, (inf - inf) -V---
2793 sim_fpu_status_invalid_idi = 8, (inf / inf) -V---
2794 sim_fpu_status_invalid_zdz = 16, (0 / 0) -V---
2795 sim_fpu_status_invalid_imz = 32, (inf * 0) -V---
2796 sim_fpu_status_invalid_cvi = 64, convert to integer -V---
2797 sim_fpu_status_invalid_div0 = 128, (X / 0) --Z--
2798 sim_fpu_status_invalid_cmp = 256, compare ----- (sim spec.)
2799 sim_fpu_status_invalid_sqrt = 512, -V---
2800 sim_fpu_status_rounded = 1024, I----
2801 sim_fpu_status_inexact = 2048, I---- (sim spec.)
2802 sim_fpu_status_overflow = 4096, I--O-
2803 sim_fpu_status_underflow = 8192, I---U
2804 sim_fpu_status_denorm = 16384, ----U (sim spec.)
2808 update_fpsr (SIM_DESC sd
, sim_fpu_status status
, unsigned int mask
, unsigned int double_op_p
)
2810 unsigned int fpsr
= FPSR
& mask
;
2812 unsigned int flags
= 0;
2815 && ((status
& (sim_fpu_status_rounded
2816 | sim_fpu_status_overflow
2817 | sim_fpu_status_inexact
))
2818 || (status
& sim_fpu_status_underflow
2819 && (fpsr
& (FPSR_XEU
| FPSR_XEI
)) == 0
2820 && fpsr
& FPSR_FS
)))
2822 flags
|= FPSR_XCI
| FPSR_XPI
;
2826 && (status
& (sim_fpu_status_invalid_isi
2827 | sim_fpu_status_invalid_imz
2828 | sim_fpu_status_invalid_zdz
2829 | sim_fpu_status_invalid_idi
2830 | sim_fpu_status_invalid_cvi
2831 | sim_fpu_status_invalid_sqrt
2832 | sim_fpu_status_invalid_snan
)))
2834 flags
|= FPSR_XCV
| FPSR_XPV
;
2838 && (status
& sim_fpu_status_invalid_div0
))
2840 flags
|= FPSR_XCV
| FPSR_XPV
;
2844 && (status
& sim_fpu_status_overflow
))
2846 flags
|= FPSR_XCO
| FPSR_XPO
;
2849 if (((fpsr
& FPSR_XEU
) || (fpsr
& FPSR_FS
) == 0)
2850 && (status
& (sim_fpu_status_underflow
2851 | sim_fpu_status_denorm
)))
2853 flags
|= FPSR_XCU
| FPSR_XPU
;
2861 SignalExceptionFPE (sd
, double_op_p
);
2868 SignalException (SIM_DESC sd
)
2872 PSW
= PSW
& ~(PSW_NPV
| PSW_DMP
| PSW_IMP
);
2877 SignalExceptionFPE (SIM_DESC sd
, unsigned int double_op_p
)
2879 if (((PSW
& (PSW_NP
|PSW_ID
)) == 0)
2880 || !(FPSR
& (double_op_p
? FPSR_DEM
: FPSR_SEM
)))
2884 EIIC
= (FPSR
& (double_op_p
? FPSR_DEM
: FPSR_SEM
))
2886 PSW
|= (PSW_EP
| PSW_ID
);
2889 SignalException (sd
);
2894 check_invalid_snan (SIM_DESC sd
, sim_fpu_status status
, unsigned int double_op_p
)
2896 if ((FPSR
& FPSR_XEI
)
2897 && (status
& sim_fpu_status_invalid_snan
))
2902 SignalExceptionFPE (sd
, double_op_p
);
2907 v850_float_compare (SIM_DESC sd
, int cmp
, sim_fpu wop1
, sim_fpu wop2
, int double_op_p
)
2911 if (sim_fpu_is_nan (&wop1
) || sim_fpu_is_nan (&wop2
))
2915 if (FPSR
& FPSR_XEV
)
2917 FPSR
|= FPSR_XCV
| FPSR_XPV
;
2918 SignalExceptionFPE (sd
, double_op_p
);
2976 else if (sim_fpu_is_infinity (&wop1
) && sim_fpu_is_infinity (&wop2
)
2977 && sim_fpu_sign (&wop1
) == sim_fpu_sign (&wop2
))
3035 int lt
= 0, eq
= 0, status
;
3037 status
= sim_fpu_cmp (&wop1
, &wop2
);
3041 case SIM_FPU_IS_SNAN
:
3042 case SIM_FPU_IS_QNAN
:
3046 case SIM_FPU_IS_NINF
:
3049 case SIM_FPU_IS_PINF
:
3052 case SIM_FPU_IS_NNUMBER
:
3055 case SIM_FPU_IS_PNUMBER
:
3058 case SIM_FPU_IS_NDENORM
:
3061 case SIM_FPU_IS_PDENORM
:
3064 case SIM_FPU_IS_NZERO
:
3065 case SIM_FPU_IS_PZERO
:
3123 ASSERT (result
!= -1);
3128 v850_div (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
, unsigned int *op3p
)
3130 signed long int quotient
;
3131 signed long int remainder
;
3132 signed long int divide_by
;
3133 signed long int divide_this
;
3134 bfd_boolean overflow
= FALSE
;
3136 /* Compute the result. */
3137 divide_by
= (int32_t)op0
;
3138 divide_this
= (int32_t)op1
;
3140 if (divide_by
== 0 || (divide_by
== -1 && divide_this
== (1 << 31)))
3146 quotient
= divide_this
/ divide_by
;
3147 remainder
= divide_this
% divide_by
;
3149 /* Set condition codes. */
3150 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3152 if (overflow
) PSW
|= PSW_OV
;
3153 if (quotient
== 0) PSW
|= PSW_Z
;
3154 if (quotient
< 0) PSW
|= PSW_S
;
3161 v850_divu (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
, unsigned int *op3p
)
3163 unsigned long int quotient
;
3164 unsigned long int remainder
;
3165 unsigned long int divide_by
;
3166 unsigned long int divide_this
;
3167 bfd_boolean overflow
= FALSE
;
3169 /* Compute the result. */
3180 quotient
= divide_this
/ divide_by
;
3181 remainder
= divide_this
% divide_by
;
3183 /* Set condition codes. */
3184 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3186 if (overflow
) PSW
|= PSW_OV
;
3187 if (quotient
== 0) PSW
|= PSW_Z
;
3188 if (quotient
& 0x80000000) PSW
|= PSW_S
;
3195 v850_sar (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3197 unsigned int result
, z
, s
, cy
;
3200 result
= (signed)op1
>> op0
;
3202 /* Compute the condition codes. */
3204 s
= (result
& 0x80000000);
3205 cy
= (op1
& (1 << (op0
- 1)));
3207 /* Store the result and condition codes. */
3208 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
3209 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3210 | (cy
? PSW_CY
: 0));
3216 v850_shl (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3218 unsigned int result
, z
, s
, cy
;
3221 result
= op1
<< op0
;
3223 /* Compute the condition codes. */
3225 s
= (result
& 0x80000000);
3226 cy
= (op1
& (1 << (32 - op0
)));
3228 /* Store the result and condition codes. */
3229 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
3230 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3231 | (cy
? PSW_CY
: 0));
3237 v850_rotl (SIM_DESC sd
, unsigned int amount
, unsigned int src
, unsigned int * dest
)
3239 unsigned int result
, z
, s
, cy
;
3242 result
= src
<< amount
;
3243 result
|= src
>> (32 - amount
);
3245 /* Compute the condition codes. */
3247 s
= (result
& 0x80000000);
3248 cy
= ! (result
& 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_bins (SIM_DESC sd
, unsigned int source
, unsigned int lsb
, unsigned int msb
,
3260 unsigned int * dest
)
3263 unsigned int result
, pos
, width
;
3267 width
= (msb
- lsb
) + 1;
3269 /* A width of 32 exhibits undefined behavior on the shift. The easiest
3270 way to make this code safe is to just avoid that case and set the mask
3271 to the right value. */
3275 mask
= ~ (-(1 << width
));
3279 result
= (* dest
) & ~ mask
;
3280 result
|= source
<< pos
;
3282 /* Compute the condition codes. */
3284 s
= result
& 0x80000000;
3286 /* Store the result and condition codes. */
3287 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3288 PSW
|= (z
? PSW_Z
: 0) | (s
? PSW_S
: 0);
3294 v850_shr (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3296 unsigned int result
, z
, s
, cy
;
3299 result
= op1
>> op0
;
3301 /* Compute the condition codes. */
3303 s
= (result
& 0x80000000);
3304 cy
= (op1
& (1 << (op0
- 1)));
3306 /* Store the result and condition codes. */
3307 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
3308 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3309 | (cy
? PSW_CY
: 0));
3315 v850_satadd (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3317 unsigned int result
, z
, s
, cy
, ov
, sat
;
3321 /* Compute the condition codes. */
3323 s
= (result
& 0x80000000);
3324 cy
= (result
< op0
|| result
< op1
);
3325 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
3326 && (op0
& 0x80000000) != (result
& 0x80000000));
3329 /* Store the result and condition codes. */
3330 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
3331 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3332 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
3333 | (sat
? PSW_SAT
: 0));
3335 /* Handle saturated results. */
3338 result
= 0x7fffffff;
3343 result
= 0x80000000;
3351 v850_satsub (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3353 unsigned int result
, z
, s
, cy
, ov
, sat
;
3355 /* Compute the result. */
3358 /* Compute the condition codes. */
3360 s
= (result
& 0x80000000);
3362 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
3363 && (op1
& 0x80000000) != (result
& 0x80000000));
3366 /* Store the result and condition codes. */
3367 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
3368 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3369 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
3370 | (sat
? PSW_SAT
: 0));
3372 /* Handle saturated results. */
3375 result
= 0x7fffffff;
3380 result
= 0x80000000;
3388 load_data_mem (SIM_DESC sd
,
3397 data
= sim_core_read_unaligned_1 (STATE_CPU (sd
, 0),
3398 PC
, read_map
, addr
);
3401 data
= sim_core_read_unaligned_2 (STATE_CPU (sd
, 0),
3402 PC
, read_map
, addr
);
3405 data
= sim_core_read_unaligned_4 (STATE_CPU (sd
, 0),
3406 PC
, read_map
, addr
);
3415 store_data_mem (SIM_DESC sd
,
3423 store_mem (addr
, 1, data
);
3426 store_mem (addr
, 2, data
);
3429 store_mem (addr
, 4, data
);
3437 mpu_load_mem_test (SIM_DESC sd
, unsigned int addr
, int size
, int base_reg
)
3443 if (IPE0
&& addr
>= IPA2ADDR (IPA0L
) && addr
<= IPA2ADDR (IPA0L
) && IPR0
)
3447 else if (IPE1
&& addr
>= IPA2ADDR (IPA1L
) && addr
<= IPA2ADDR (IPA1L
) && IPR1
)
3451 else if (IPE2
&& addr
>= IPA2ADDR (IPA2L
) && addr
<= IPA2ADDR (IPA2L
) && IPR2
)
3455 else if (IPE3
&& addr
>= IPA2ADDR (IPA3L
) && addr
<= IPA2ADDR (IPA3L
) && IPR3
)
3459 else if (addr
>= PPA2ADDR (PPA
& ~PPM
) && addr
<= DPA2ADDR (PPA
| PPM
))
3461 /* preifarallel area */
3463 else if (addr
>= PPA2ADDR (SPAL
) && addr
<= DPA2ADDR (SPAU
))
3467 else if (DPE0
&& addr
>= DPA2ADDR (DPA0L
) && addr
<= DPA2ADDR (DPA0L
) && DPR0
3468 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3472 else if (DPE1
&& addr
>= DPA2ADDR (DPA1L
) && addr
<= DPA2ADDR (DPA1L
) && DPR1
3473 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3477 else if (DPE2
&& addr
>= DPA2ADDR (DPA2L
) && addr
<= DPA2ADDR (DPA2L
) && DPR2
3478 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3482 else if (DPE3
&& addr
>= DPA2ADDR (DPA3L
) && addr
<= DPA2ADDR (DPA3L
) && DPR3
3483 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3489 VMECR
&= ~(VMECR_VMW
| VMECR_VMX
);
3497 SignalException (sd
);
3506 mpu_store_mem_test (SIM_DESC sd
, unsigned int addr
, int size
, int base_reg
)
3512 if (addr
>= PPA2ADDR (PPA
& ~PPM
) && addr
<= DPA2ADDR (PPA
| PPM
))
3514 /* preifarallel area */
3516 else if (addr
>= PPA2ADDR (SPAL
) && addr
<= DPA2ADDR (SPAU
))
3520 else if (DPE0
&& addr
>= DPA2ADDR (DPA0L
) && addr
<= DPA2ADDR (DPA0L
) && DPW0
3521 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3525 else if (DPE1
&& addr
>= DPA2ADDR (DPA1L
) && addr
<= DPA2ADDR (DPA1L
) && DPW1
3526 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3530 else if (DPE2
&& addr
>= DPA2ADDR (DPA2L
) && addr
<= DPA2ADDR (DPA2L
) && DPW2
3531 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3535 else if (DPE3
&& addr
>= DPA2ADDR (DPA3L
) && addr
<= DPA2ADDR (DPA3L
) && DPW3
3536 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3542 if (addr
>= PPA2ADDR (PPA
& ~PPM
) && addr
<= DPA2ADDR (PPA
| PPM
))
3557 VMECR
&= ~(VMECR_VMW
| VMECR_VMX
);