1 /* This must come before any other includes. */
5 #include "sim-signal.h"
21 #include "libiberty.h"
24 #if !defined(__GO32__) && !defined(_WIN32)
26 #include <sys/times.h>
30 #include "target-newlib-syscall.h"
32 /* This is an array of the bit positions of registers r20 .. r31 in
33 that order in a prepare/dispose instruction. */
34 int type1_regs
[12] = { 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 0, 21 };
35 /* This is an array of the bit positions of registers r16 .. r31 in
36 that order in a push/pop instruction. */
37 int type2_regs
[16] = { 3, 2, 1, 0, 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 20, 21};
38 /* This is an array of the bit positions of registers r1 .. r15 in
39 that order in a push/pop instruction. */
40 int type3_regs
[15] = { 2, 1, 0, 27, 26, 25, 24, 31, 30, 29, 28, 23, 22, 20, 21};
43 #ifndef SIZE_INSTRUCTION
44 #define SIZE_INSTRUCTION 18
48 #define SIZE_VALUES 11
51 /* TODO: This file largely assumes a single CPU. */
52 #define CPU STATE_CPU (sd, 0)
55 uint32_t trace_values
[3];
58 const char * trace_name
;
63 trace_input (char *name
, enum op_types type
, int size
)
65 if (!TRACE_ALU_P (STATE_CPU (simulator
, 0)))
70 trace_module
= TRACE_ALU_IDX
;
83 trace_values
[0] = State
.regs
[OP
[0]];
90 trace_values
[0] = State
.regs
[OP
[1]];
91 trace_values
[1] = State
.regs
[OP
[0]];
97 trace_values
[0] = SEXT5 (OP
[0]);
98 trace_values
[1] = OP
[1];
102 case OP_IMM_REG_MOVE
:
103 trace_values
[0] = SEXT5 (OP
[0]);
104 trace_num_values
= 1;
108 trace_values
[0] = State
.pc
;
109 trace_values
[1] = SEXT9 (OP
[0]);
110 trace_values
[2] = PSW
;
111 trace_num_values
= 3;
115 trace_values
[0] = OP
[1] * size
;
116 trace_values
[1] = State
.regs
[30];
117 trace_num_values
= 2;
121 trace_values
[0] = State
.regs
[OP
[0]];
122 trace_values
[1] = OP
[1] * size
;
123 trace_values
[2] = State
.regs
[30];
124 trace_num_values
= 3;
128 trace_values
[0] = EXTEND16 (OP
[2]);
129 trace_values
[1] = State
.regs
[OP
[0]];
130 trace_num_values
= 2;
134 trace_values
[0] = State
.regs
[OP
[1]];
135 trace_values
[1] = EXTEND16 (OP
[2]);
136 trace_values
[2] = State
.regs
[OP
[0]];
137 trace_num_values
= 3;
141 trace_values
[0] = SEXT22 (OP
[0]);
142 trace_values
[1] = State
.pc
;
143 trace_num_values
= 2;
147 trace_values
[0] = EXTEND16 (OP
[0]) << size
;
148 trace_values
[1] = State
.regs
[OP
[1]];
149 trace_num_values
= 2;
152 case OP_IMM16_REG_REG
:
153 trace_values
[0] = EXTEND16 (OP
[2]) << size
;
154 trace_values
[1] = State
.regs
[OP
[1]];
155 trace_num_values
= 2;
158 case OP_UIMM_REG_REG
:
159 trace_values
[0] = (OP
[0] & 0xffff) << size
;
160 trace_values
[1] = State
.regs
[OP
[1]];
161 trace_num_values
= 2;
164 case OP_UIMM16_REG_REG
:
165 trace_values
[0] = (OP
[2]) << size
;
166 trace_values
[1] = State
.regs
[OP
[1]];
167 trace_num_values
= 2;
171 trace_num_values
= 0;
175 trace_values
[0] = PSW
;
176 trace_num_values
= 1;
180 trace_num_values
= 0;
184 trace_values
[0] = State
.regs
[OP
[0]];
185 trace_num_values
= 1;
189 trace_values
[0] = State
.sregs
[OP
[1]];
190 trace_num_values
= 1;
196 trace_result (int has_result
, uint32_t result
)
204 /* write out the values saved during the trace_input call */
207 for (i
= 0; i
< trace_num_values
; i
++)
209 sprintf (chp
, "%*s0x%.8lx", SIZE_VALUES
- 10, "",
210 (long) trace_values
[i
]);
211 chp
= strchr (chp
, '\0');
215 sprintf (chp
, "%*s", SIZE_VALUES
, "");
216 chp
= strchr (chp
, '\0');
220 /* append any result to the end of the buffer */
222 sprintf (chp
, " :: 0x%.8lx", (unsigned long) result
);
224 trace_generic (simulator
, STATE_CPU (simulator
, 0), trace_module
, "%s", buf
);
228 trace_output (enum op_types result
)
230 if (!TRACE_ALU_P (STATE_CPU (simulator
, 0)))
252 trace_result (1, State
.regs
[OP
[0]]);
256 case OP_REG_REG_MOVE
:
258 case OP_IMM_REG_MOVE
:
261 trace_result (1, State
.regs
[OP
[1]]);
265 case OP_UIMM_REG_REG
:
266 case OP_IMM16_REG_REG
:
267 case OP_UIMM16_REG_REG
:
268 trace_result (1, State
.regs
[OP
[1]]);
273 trace_result (1, State
.regs
[OP
[1]]);
279 trace_result (1, State
.sregs
[OP
[1]]);
286 /* Returns 1 if the specific condition is met, returns 0 otherwise. */
288 condition_met (unsigned code
)
290 unsigned int psw
= PSW
;
294 case 0x0: return ((psw
& PSW_OV
) != 0);
295 case 0x1: return ((psw
& PSW_CY
) != 0);
296 case 0x2: return ((psw
& PSW_Z
) != 0);
297 case 0x3: return ((((psw
& PSW_CY
) != 0) | ((psw
& PSW_Z
) != 0)) != 0);
298 case 0x4: return ((psw
& PSW_S
) != 0);
299 /*case 0x5: return 1;*/
300 case 0x6: return ((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) != 0);
301 case 0x7: return (((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) || ((psw
& PSW_Z
) != 0)) != 0);
302 case 0x8: return ((psw
& PSW_OV
) == 0);
303 case 0x9: return ((psw
& PSW_CY
) == 0);
304 case 0xa: return ((psw
& PSW_Z
) == 0);
305 case 0xb: return ((((psw
& PSW_CY
) != 0) | ((psw
& PSW_Z
) != 0)) == 0);
306 case 0xc: return ((psw
& PSW_S
) == 0);
307 case 0xd: return ((psw
& PSW_SAT
) != 0);
308 case 0xe: return ((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) == 0);
309 case 0xf: return (((((psw
& PSW_S
) != 0) ^ ((psw
& PSW_OV
) != 0)) || ((psw
& PSW_Z
) != 0)) == 0);
316 Add32 (unsigned long a1
, unsigned long a2
, int * carry
)
318 unsigned long result
= (a1
+ a2
);
320 * carry
= (result
< a1
);
326 Multiply64 (int sign
, unsigned long op0
)
337 op1
= State
.regs
[ OP
[1] ];
341 /* Compute sign of result and adjust operands if necessary. */
343 sign
= (op0
^ op1
) & 0x80000000;
345 if (op0
& 0x80000000)
348 if (op1
& 0x80000000)
352 /* We can split the 32x32 into four 16x16 operations. This ensures
353 that we do not lose precision on 32bit only hosts: */
354 lo
= ( (op0
& 0xFFFF) * (op1
& 0xFFFF));
355 mid1
= ( (op0
& 0xFFFF) * ((op1
>> 16) & 0xFFFF));
356 mid2
= (((op0
>> 16) & 0xFFFF) * (op1
& 0xFFFF));
357 hi
= (((op0
>> 16) & 0xFFFF) * ((op1
>> 16) & 0xFFFF));
359 /* We now need to add all of these results together, taking care
360 to propogate the carries from the additions: */
361 RdLo
= Add32 (lo
, (mid1
<< 16), & carry
);
363 RdLo
= Add32 (RdLo
, (mid2
<< 16), & carry
);
364 RdHi
+= (carry
+ ((mid1
>> 16) & 0xFFFF) + ((mid2
>> 16) & 0xFFFF) + hi
);
368 /* Negate result if necessary. */
372 if (RdLo
== 0xFFFFFFFF)
381 /* Don't store into register 0. */
383 State
.regs
[ OP
[1] ] = RdLo
;
385 State
.regs
[ OP
[2] >> 11 ] = RdHi
;
391 /* Read a null terminated string from memory, return in a buffer. */
394 fetch_str (SIM_DESC sd
, address_word addr
)
399 while (sim_core_read_1 (STATE_CPU (sd
, 0),
400 PC
, read_map
, addr
+ nr
) != 0)
403 buf
= NZALLOC (char, nr
+ 1);
404 sim_read (simulator
, addr
, buf
, nr
);
409 /* Read a null terminated argument vector from memory, return in a
413 fetch_argv (SIM_DESC sd
, address_word addr
)
417 char **buf
= xmalloc (max_nr
* sizeof (char*));
421 uint32_t a
= sim_core_read_4 (STATE_CPU (sd
, 0),
422 PC
, read_map
, addr
+ nr
* 4);
424 buf
[nr
] = fetch_str (sd
, a
);
426 if (nr
== max_nr
- 1)
429 buf
= xrealloc (buf
, max_nr
* sizeof (char*));
441 trace_input ("sst.b", OP_STORE16
, 1);
443 store_mem (State
.regs
[30] + (OP
[3] & 0x7f), 1, State
.regs
[ OP
[1] ]);
445 trace_output (OP_STORE16
);
454 trace_input ("sst.h", OP_STORE16
, 2);
456 store_mem (State
.regs
[30] + ((OP
[3] & 0x7f) << 1), 2, State
.regs
[ OP
[1] ]);
458 trace_output (OP_STORE16
);
467 trace_input ("sst.w", OP_STORE16
, 4);
469 store_mem (State
.regs
[30] + ((OP
[3] & 0x7e) << 1), 4, State
.regs
[ OP
[1] ]);
471 trace_output (OP_STORE16
);
482 trace_input ("ld.b", OP_LOAD32
, 1);
484 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2]);
486 State
.regs
[ OP
[1] ] = EXTEND8 (load_mem (adr
, 1));
488 trace_output (OP_LOAD32
);
499 trace_input ("ld.h", OP_LOAD32
, 2);
501 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2]);
504 State
.regs
[ OP
[1] ] = EXTEND16 (load_mem (adr
, 2));
506 trace_output (OP_LOAD32
);
517 trace_input ("ld.w", OP_LOAD32
, 4);
519 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2] & ~1);
522 State
.regs
[ OP
[1] ] = load_mem (adr
, 4);
524 trace_output (OP_LOAD32
);
533 trace_input ("st.b", OP_STORE32
, 1);
535 store_mem (State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2]), 1, State
.regs
[ OP
[1] ]);
537 trace_output (OP_STORE32
);
548 trace_input ("st.h", OP_STORE32
, 2);
550 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2]);
553 store_mem (adr
, 2, State
.regs
[ OP
[1] ]);
555 trace_output (OP_STORE32
);
566 trace_input ("st.w", OP_STORE32
, 4);
568 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2] & ~1);
571 store_mem (adr
, 4, State
.regs
[ OP
[1] ]);
573 trace_output (OP_STORE32
);
582 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
584 trace_input ("add", OP_REG_REG
, 0);
586 /* Compute the result. */
588 op0
= State
.regs
[ OP
[0] ];
589 op1
= State
.regs
[ OP
[1] ];
593 /* Compute the condition codes. */
595 s
= (result
& 0x80000000);
596 cy
= (result
< op0
|| result
< op1
);
597 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
598 && (op0
& 0x80000000) != (result
& 0x80000000));
600 /* Store the result and condition codes. */
601 State
.regs
[OP
[1]] = result
;
602 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
603 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
604 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
605 trace_output (OP_REG_REG
);
610 /* add sign_extend(imm5), reg */
614 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
617 trace_input ("add", OP_IMM_REG
, 0);
619 /* Compute the result. */
620 temp
= SEXT5 (OP
[0]);
622 op1
= State
.regs
[OP
[1]];
625 /* Compute the condition codes. */
627 s
= (result
& 0x80000000);
628 cy
= (result
< op0
|| result
< op1
);
629 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
630 && (op0
& 0x80000000) != (result
& 0x80000000));
632 /* Store the result and condition codes. */
633 State
.regs
[OP
[1]] = result
;
634 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
635 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
636 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
637 trace_output (OP_IMM_REG
);
642 /* addi sign_extend(imm16), reg, reg */
646 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
648 trace_input ("addi", OP_IMM16_REG_REG
, 0);
650 /* Compute the result. */
652 op0
= EXTEND16 (OP
[2]);
653 op1
= State
.regs
[ OP
[0] ];
656 /* Compute the condition codes. */
658 s
= (result
& 0x80000000);
659 cy
= (result
< op0
|| result
< op1
);
660 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
661 && (op0
& 0x80000000) != (result
& 0x80000000));
663 /* Store the result and condition codes. */
664 State
.regs
[OP
[1]] = result
;
665 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
666 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
667 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
668 trace_output (OP_IMM16_REG_REG
);
677 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
679 trace_input ("sub", OP_REG_REG
, 0);
680 /* Compute the result. */
681 op0
= State
.regs
[ OP
[0] ];
682 op1
= State
.regs
[ OP
[1] ];
685 /* Compute the condition codes. */
687 s
= (result
& 0x80000000);
689 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
690 && (op1
& 0x80000000) != (result
& 0x80000000));
692 /* Store the result and condition codes. */
693 State
.regs
[OP
[1]] = result
;
694 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
695 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
696 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
697 trace_output (OP_REG_REG
);
702 /* subr reg1, reg2 */
706 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
708 trace_input ("subr", OP_REG_REG
, 0);
709 /* Compute the result. */
710 op0
= State
.regs
[ OP
[0] ];
711 op1
= State
.regs
[ OP
[1] ];
714 /* Compute the condition codes. */
716 s
= (result
& 0x80000000);
718 ov
= ((op0
& 0x80000000) != (op1
& 0x80000000)
719 && (op0
& 0x80000000) != (result
& 0x80000000));
721 /* Store the result and condition codes. */
722 State
.regs
[OP
[1]] = result
;
723 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
724 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
725 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
726 trace_output (OP_REG_REG
);
735 trace_input ("mulh", OP_REG_REG
, 0);
737 State
.regs
[ OP
[1] ] = (EXTEND16 (State
.regs
[ OP
[1] ]) * EXTEND16 (State
.regs
[ OP
[0] ]));
739 trace_output (OP_REG_REG
);
744 /* mulh sign_extend(imm5), reg2 */
748 trace_input ("mulh", OP_IMM_REG
, 0);
750 State
.regs
[ OP
[1] ] = EXTEND16 (State
.regs
[ OP
[1] ]) * SEXT5 (OP
[0]);
752 trace_output (OP_IMM_REG
);
757 /* mulhi imm16, reg1, reg2 */
761 trace_input ("mulhi", OP_IMM16_REG_REG
, 0);
763 State
.regs
[ OP
[1] ] = EXTEND16 (State
.regs
[ OP
[0] ]) * EXTEND16 (OP
[2]);
765 trace_output (OP_IMM16_REG_REG
);
774 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
776 trace_input ("cmp", OP_REG_REG_CMP
, 0);
777 /* Compute the result. */
778 op0
= State
.regs
[ OP
[0] ];
779 op1
= State
.regs
[ OP
[1] ];
782 /* Compute the condition codes. */
784 s
= (result
& 0x80000000);
786 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
787 && (op1
& 0x80000000) != (result
& 0x80000000));
789 /* Set condition codes. */
790 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
791 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
792 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
793 trace_output (OP_REG_REG_CMP
);
798 /* cmp sign_extend(imm5), reg */
802 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
;
805 /* Compute the result. */
806 trace_input ("cmp", OP_IMM_REG_CMP
, 0);
807 temp
= SEXT5 (OP
[0]);
809 op1
= State
.regs
[OP
[1]];
812 /* Compute the condition codes. */
814 s
= (result
& 0x80000000);
816 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
817 && (op1
& 0x80000000) != (result
& 0x80000000));
819 /* Set condition codes. */
820 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
821 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
822 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0));
823 trace_output (OP_IMM_REG_CMP
);
832 trace_input ("setf", OP_EX1
, 0);
834 State
.regs
[ OP
[1] ] = condition_met (OP
[0]);
836 trace_output (OP_EX1
);
845 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
847 trace_input ("satadd", OP_REG_REG
, 0);
848 /* Compute the result. */
849 op0
= State
.regs
[ OP
[0] ];
850 op1
= State
.regs
[ OP
[1] ];
853 /* Compute the condition codes. */
855 s
= (result
& 0x80000000);
856 cy
= (result
< op0
|| result
< op1
);
857 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
858 && (op0
& 0x80000000) != (result
& 0x80000000));
861 /* Handle saturated results. */
864 /* An overflow that results in a negative result implies that we
865 became too positive. */
871 /* Any other overflow must have thus been too negative. */
877 /* Store the result and condition codes. */
878 State
.regs
[OP
[1]] = result
;
879 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
880 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
881 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
882 | (sat
? PSW_SAT
: 0));
884 trace_output (OP_REG_REG
);
889 /* satadd sign_extend(imm5), reg */
893 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
897 trace_input ("satadd", OP_IMM_REG
, 0);
899 /* Compute the result. */
900 temp
= SEXT5 (OP
[0]);
902 op1
= State
.regs
[OP
[1]];
905 /* Compute the condition codes. */
907 s
= (result
& 0x80000000);
908 cy
= (result
< op0
|| result
< op1
);
909 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
910 && (op0
& 0x80000000) != (result
& 0x80000000));
913 /* Handle saturated results. */
916 /* An overflow that results in a negative result implies that we
917 became too positive. */
923 /* Any other overflow must have thus been too negative. */
929 /* Store the result and condition codes. */
930 State
.regs
[OP
[1]] = result
;
931 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
932 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
933 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
934 | (sat
? PSW_SAT
: 0));
935 trace_output (OP_IMM_REG
);
940 /* satsub reg1, reg2 */
944 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
946 trace_input ("satsub", OP_REG_REG
, 0);
948 /* Compute the result. */
949 op0
= State
.regs
[ OP
[0] ];
950 op1
= State
.regs
[ OP
[1] ];
953 /* Compute the condition codes. */
955 s
= (result
& 0x80000000);
957 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
958 && (op1
& 0x80000000) != (result
& 0x80000000));
961 /* Handle saturated results. */
964 /* An overflow that results in a negative result implies that we
965 became too positive. */
971 /* Any other overflow must have thus been too negative. */
977 /* Store the result and condition codes. */
978 State
.regs
[OP
[1]] = result
;
979 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
980 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
981 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
982 | (sat
? PSW_SAT
: 0));
984 trace_output (OP_REG_REG
);
988 /* satsubi sign_extend(imm16), reg */
992 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
995 trace_input ("satsubi", OP_IMM_REG
, 0);
997 /* Compute the result. */
998 temp
= EXTEND16 (OP
[2]);
1000 op1
= State
.regs
[ OP
[0] ];
1003 /* Compute the condition codes. */
1005 s
= (result
& 0x80000000);
1007 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
1008 && (op1
& 0x80000000) != (result
& 0x80000000));
1011 /* Handle saturated results. */
1014 /* An overflow that results in a negative result implies that we
1015 became too positive. */
1016 result
= 0x7fffffff;
1021 /* Any other overflow must have thus been too negative. */
1022 result
= 0x80000000;
1027 /* Store the result and condition codes. */
1028 State
.regs
[OP
[1]] = result
;
1029 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1030 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1031 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
1032 | (sat
? PSW_SAT
: 0));
1034 trace_output (OP_IMM_REG
);
1039 /* satsubr reg,reg */
1043 unsigned int op0
, op1
, result
, z
, s
, cy
, ov
, sat
;
1045 trace_input ("satsubr", OP_REG_REG
, 0);
1047 /* Compute the result. */
1048 op0
= State
.regs
[ OP
[0] ];
1049 op1
= State
.regs
[ OP
[1] ];
1052 /* Compute the condition codes. */
1054 s
= (result
& 0x80000000);
1056 ov
= ((op0
& 0x80000000) != (op1
& 0x80000000)
1057 && (op0
& 0x80000000) != (result
& 0x80000000));
1060 /* Handle saturated results. */
1063 /* An overflow that results in a negative result implies that we
1064 became too positive. */
1065 result
= 0x7fffffff;
1070 /* Any other overflow must have thus been too negative. */
1071 result
= 0x80000000;
1076 /* Store the result and condition codes. */
1077 State
.regs
[OP
[1]] = result
;
1078 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
1079 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1080 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
1081 | (sat
? PSW_SAT
: 0));
1083 trace_output (OP_REG_REG
);
1092 unsigned int op0
, op1
, result
, z
, s
;
1094 trace_input ("tst", OP_REG_REG_CMP
, 0);
1096 /* Compute the result. */
1097 op0
= State
.regs
[ OP
[0] ];
1098 op1
= State
.regs
[ OP
[1] ];
1101 /* Compute the condition codes. */
1103 s
= (result
& 0x80000000);
1105 /* Store the condition codes. */
1106 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1107 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1108 trace_output (OP_REG_REG_CMP
);
1113 /* mov sign_extend(imm5), reg */
1117 int value
= SEXT5 (OP
[0]);
1119 trace_input ("mov", OP_IMM_REG_MOVE
, 0);
1121 State
.regs
[ OP
[1] ] = value
;
1123 trace_output (OP_IMM_REG_MOVE
);
1128 /* movhi imm16, reg, reg */
1132 trace_input ("movhi", OP_UIMM16_REG_REG
, 16);
1134 State
.regs
[ OP
[1] ] = State
.regs
[ OP
[0] ] + (OP
[2] << 16);
1136 trace_output (OP_UIMM16_REG_REG
);
1141 /* sar zero_extend(imm5),reg1 */
1145 unsigned int op0
, op1
, result
, z
, s
, cy
;
1147 trace_input ("sar", OP_IMM_REG
, 0);
1149 op1
= State
.regs
[ OP
[1] ];
1150 result
= (signed)op1
>> op0
;
1152 /* Compute the condition codes. */
1154 s
= (result
& 0x80000000);
1155 cy
= op0
? (op1
& (1 << (op0
- 1))) : 0;
1157 /* Store the result and condition codes. */
1158 State
.regs
[ OP
[1] ] = result
;
1159 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1160 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1161 | (cy
? PSW_CY
: 0));
1162 trace_output (OP_IMM_REG
);
1167 /* sar reg1, reg2 */
1171 unsigned int op0
, op1
, result
, z
, s
, cy
;
1173 trace_input ("sar", OP_REG_REG
, 0);
1175 op0
= State
.regs
[ OP
[0] ] & 0x1f;
1176 op1
= State
.regs
[ OP
[1] ];
1177 result
= (signed)op1
>> op0
;
1179 /* Compute the condition codes. */
1181 s
= (result
& 0x80000000);
1182 cy
= op0
? (op1
& (1 << (op0
- 1))) : 0;
1184 /* Store the result and condition codes. */
1185 State
.regs
[OP
[1]] = result
;
1186 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1187 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1188 | (cy
? PSW_CY
: 0));
1189 trace_output (OP_REG_REG
);
1194 /* shl zero_extend(imm5),reg1 */
1198 unsigned int op0
, op1
, result
, z
, s
, cy
;
1200 trace_input ("shl", OP_IMM_REG
, 0);
1202 op1
= State
.regs
[ OP
[1] ];
1203 result
= op1
<< op0
;
1205 /* Compute the condition codes. */
1207 s
= (result
& 0x80000000);
1208 cy
= op0
? (op1
& (1 << (32 - op0
))) : 0;
1210 /* Store the result and condition codes. */
1211 State
.regs
[OP
[1]] = result
;
1212 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1213 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1214 | (cy
? PSW_CY
: 0));
1215 trace_output (OP_IMM_REG
);
1220 /* shl reg1, reg2 */
1224 unsigned int op0
, op1
, result
, z
, s
, cy
;
1226 trace_input ("shl", OP_REG_REG
, 0);
1227 op0
= State
.regs
[ OP
[0] ] & 0x1f;
1228 op1
= State
.regs
[ OP
[1] ];
1229 result
= op1
<< op0
;
1231 /* Compute the condition codes. */
1233 s
= (result
& 0x80000000);
1234 cy
= op0
? (op1
& (1 << (32 - op0
))) : 0;
1236 /* Store the result and condition codes. */
1237 State
.regs
[OP
[1]] = result
;
1238 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1239 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1240 | (cy
? PSW_CY
: 0));
1241 trace_output (OP_REG_REG
);
1246 /* shr zero_extend(imm5),reg1 */
1250 unsigned int op0
, op1
, result
, z
, s
, cy
;
1252 trace_input ("shr", OP_IMM_REG
, 0);
1254 op1
= State
.regs
[ OP
[1] ];
1255 result
= op1
>> op0
;
1257 /* Compute the condition codes. */
1259 s
= (result
& 0x80000000);
1260 cy
= op0
? (op1
& (1 << (op0
- 1))) : 0;
1262 /* Store the result and condition codes. */
1263 State
.regs
[OP
[1]] = result
;
1264 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1265 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1266 | (cy
? PSW_CY
: 0));
1267 trace_output (OP_IMM_REG
);
1272 /* shr reg1, reg2 */
1276 unsigned int op0
, op1
, result
, z
, s
, cy
;
1278 trace_input ("shr", OP_REG_REG
, 0);
1279 op0
= State
.regs
[ OP
[0] ] & 0x1f;
1280 op1
= State
.regs
[ OP
[1] ];
1281 result
= op1
>> op0
;
1283 /* Compute the condition codes. */
1285 s
= (result
& 0x80000000);
1286 cy
= op0
? (op1
& (1 << (op0
- 1))) : 0;
1288 /* Store the result and condition codes. */
1289 State
.regs
[OP
[1]] = result
;
1290 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
1291 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
1292 | (cy
? PSW_CY
: 0));
1293 trace_output (OP_REG_REG
);
1302 unsigned int op0
, op1
, result
, z
, s
;
1304 trace_input ("or", OP_REG_REG
, 0);
1306 /* Compute the result. */
1307 op0
= State
.regs
[ OP
[0] ];
1308 op1
= State
.regs
[ OP
[1] ];
1311 /* Compute the condition codes. */
1313 s
= (result
& 0x80000000);
1315 /* Store the result and condition codes. */
1316 State
.regs
[OP
[1]] = result
;
1317 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1318 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1319 trace_output (OP_REG_REG
);
1324 /* ori zero_extend(imm16), reg, reg */
1328 unsigned int op0
, op1
, result
, z
, s
;
1330 trace_input ("ori", OP_UIMM16_REG_REG
, 0);
1332 op1
= State
.regs
[ OP
[0] ];
1335 /* Compute the condition codes. */
1337 s
= (result
& 0x80000000);
1339 /* Store the result and condition codes. */
1340 State
.regs
[OP
[1]] = result
;
1341 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1342 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1343 trace_output (OP_UIMM16_REG_REG
);
1352 unsigned int op0
, op1
, result
, z
, s
;
1354 trace_input ("and", OP_REG_REG
, 0);
1356 /* Compute the result. */
1357 op0
= State
.regs
[ OP
[0] ];
1358 op1
= State
.regs
[ OP
[1] ];
1361 /* Compute the condition codes. */
1363 s
= (result
& 0x80000000);
1365 /* Store the result and condition codes. */
1366 State
.regs
[OP
[1]] = result
;
1367 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1368 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1369 trace_output (OP_REG_REG
);
1374 /* andi zero_extend(imm16), reg, reg */
1378 unsigned int result
, z
;
1380 trace_input ("andi", OP_UIMM16_REG_REG
, 0);
1382 result
= OP
[2] & State
.regs
[ OP
[0] ];
1384 /* Compute the condition codes. */
1387 /* Store the result and condition codes. */
1388 State
.regs
[ OP
[1] ] = result
;
1390 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1391 PSW
|= (z
? PSW_Z
: 0);
1393 trace_output (OP_UIMM16_REG_REG
);
1402 unsigned int op0
, op1
, result
, z
, s
;
1404 trace_input ("xor", OP_REG_REG
, 0);
1406 /* Compute the result. */
1407 op0
= State
.regs
[ OP
[0] ];
1408 op1
= State
.regs
[ OP
[1] ];
1411 /* Compute the condition codes. */
1413 s
= (result
& 0x80000000);
1415 /* Store the result and condition codes. */
1416 State
.regs
[OP
[1]] = result
;
1417 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1418 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1419 trace_output (OP_REG_REG
);
1424 /* xori zero_extend(imm16), reg, reg */
1428 unsigned int op0
, op1
, result
, z
, s
;
1430 trace_input ("xori", OP_UIMM16_REG_REG
, 0);
1432 op1
= State
.regs
[ OP
[0] ];
1435 /* Compute the condition codes. */
1437 s
= (result
& 0x80000000);
1439 /* Store the result and condition codes. */
1440 State
.regs
[OP
[1]] = result
;
1441 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1442 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1443 trace_output (OP_UIMM16_REG_REG
);
1448 /* not reg1, reg2 */
1452 unsigned int op0
, result
, z
, s
;
1454 trace_input ("not", OP_REG_REG_MOVE
, 0);
1455 /* Compute the result. */
1456 op0
= State
.regs
[ OP
[0] ];
1459 /* Compute the condition codes. */
1461 s
= (result
& 0x80000000);
1463 /* Store the result and condition codes. */
1464 State
.regs
[OP
[1]] = result
;
1465 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
1466 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0));
1467 trace_output (OP_REG_REG_MOVE
);
1476 unsigned int op0
, op1
, op2
;
1479 trace_input ("set1", OP_BIT
, 0);
1480 op0
= State
.regs
[ OP
[0] ];
1482 temp
= EXTEND16 (OP
[2]);
1484 temp
= load_mem (op0
+ op2
, 1);
1486 if ((temp
& (1 << op1
)) == 0)
1489 store_mem (op0
+ op2
, 1, temp
);
1490 trace_output (OP_BIT
);
1499 unsigned int op0
, op1
, op2
;
1502 trace_input ("not1", OP_BIT
, 0);
1503 op0
= State
.regs
[ OP
[0] ];
1505 temp
= EXTEND16 (OP
[2]);
1507 temp
= load_mem (op0
+ op2
, 1);
1509 if ((temp
& (1 << op1
)) == 0)
1512 store_mem (op0
+ op2
, 1, temp
);
1513 trace_output (OP_BIT
);
1522 unsigned int op0
, op1
, op2
;
1525 trace_input ("clr1", OP_BIT
, 0);
1526 op0
= State
.regs
[ OP
[0] ];
1528 temp
= EXTEND16 (OP
[2]);
1530 temp
= load_mem (op0
+ op2
, 1);
1532 if ((temp
& (1 << op1
)) == 0)
1534 temp
&= ~(1 << op1
);
1535 store_mem (op0
+ op2
, 1, temp
);
1536 trace_output (OP_BIT
);
1545 unsigned int op0
, op1
, op2
;
1548 trace_input ("tst1", OP_BIT
, 0);
1549 op0
= State
.regs
[ OP
[0] ];
1551 temp
= EXTEND16 (OP
[2]);
1553 temp
= load_mem (op0
+ op2
, 1);
1555 if ((temp
& (1 << op1
)) == 0)
1557 trace_output (OP_BIT
);
1566 trace_input ("di", OP_NONE
, 0);
1568 trace_output (OP_NONE
);
1577 trace_input ("ei", OP_NONE
, 0);
1579 trace_output (OP_NONE
);
1588 trace_input ("halt", OP_NONE
, 0);
1589 /* FIXME this should put processor into a mode where NMI still handled */
1590 trace_output (OP_NONE
);
1591 sim_engine_halt (simulator
, STATE_CPU (simulator
, 0), NULL
, PC
,
1592 sim_stopped
, SIM_SIGTRAP
);
1600 trace_input ("trap", OP_TRAP
, 0);
1601 trace_output (OP_TRAP
);
1603 /* Trap 31 is used for simulating OS I/O functions */
1607 int save_errno
= errno
;
1610 /* Registers passed to trap 0 */
1612 #define FUNC State.regs[6] /* function number, return value */
1613 #define PARM1 State.regs[7] /* optional parm 1 */
1614 #define PARM2 State.regs[8] /* optional parm 2 */
1615 #define PARM3 State.regs[9] /* optional parm 3 */
1617 /* Registers set by trap 0 */
1619 #define RETVAL State.regs[10] /* return value */
1620 #define RETERR State.regs[11] /* return error code */
1622 /* Turn a pointer in a register into a pointer into real memory. */
1624 #define MEMPTR(x) (map (x))
1632 case TARGET_NEWLIB_V850_SYS_fork
:
1639 case TARGET_NEWLIB_V850_SYS_execve
:
1641 char *path
= fetch_str (simulator
, PARM1
);
1642 char **argv
= fetch_argv (simulator
, PARM2
);
1643 char **envp
= fetch_argv (simulator
, PARM3
);
1644 RETVAL
= execve (path
, (void *)argv
, (void *)envp
);
1654 case TARGET_NEWLIB_V850_SYS_execv
:
1656 char *path
= fetch_str (simulator
, PARM1
);
1657 char **argv
= fetch_argv (simulator
, PARM2
);
1658 RETVAL
= execv (path
, (void *)argv
);
1667 case TARGET_NEWLIB_V850_SYS_pipe
:
1673 RETVAL
= pipe (host_fd
);
1674 SW (buf
, host_fd
[0]);
1675 buf
+= sizeof (uint16_t);
1676 SW (buf
, host_fd
[1]);
1683 case TARGET_NEWLIB_V850_SYS_wait
:
1687 RETVAL
= wait (&status
);
1694 case TARGET_NEWLIB_V850_SYS_read
:
1696 char *buf
= zalloc (PARM3
);
1697 RETVAL
= sim_io_read (simulator
, PARM1
, buf
, PARM3
);
1698 sim_write (simulator
, PARM2
, buf
, PARM3
);
1700 if ((int) RETVAL
< 0)
1701 RETERR
= sim_io_get_errno (simulator
);
1705 case TARGET_NEWLIB_V850_SYS_write
:
1707 char *buf
= zalloc (PARM3
);
1708 sim_read (simulator
, PARM2
, buf
, PARM3
);
1710 RETVAL
= sim_io_write_stdout (simulator
, buf
, PARM3
);
1712 RETVAL
= sim_io_write (simulator
, PARM1
, buf
, PARM3
);
1714 if ((int) RETVAL
< 0)
1715 RETERR
= sim_io_get_errno (simulator
);
1719 case TARGET_NEWLIB_V850_SYS_lseek
:
1720 RETVAL
= sim_io_lseek (simulator
, PARM1
, PARM2
, PARM3
);
1721 if ((int) RETVAL
< 0)
1722 RETERR
= sim_io_get_errno (simulator
);
1725 case TARGET_NEWLIB_V850_SYS_close
:
1726 RETVAL
= sim_io_close (simulator
, PARM1
);
1727 if ((int) RETVAL
< 0)
1728 RETERR
= sim_io_get_errno (simulator
);
1731 case TARGET_NEWLIB_V850_SYS_open
:
1733 char *buf
= fetch_str (simulator
, PARM1
);
1734 RETVAL
= sim_io_open (simulator
, buf
, PARM2
);
1736 if ((int) RETVAL
< 0)
1737 RETERR
= sim_io_get_errno (simulator
);
1741 case TARGET_NEWLIB_V850_SYS_exit
:
1742 if ((PARM1
& 0xffff0000) == 0xdead0000 && (PARM1
& 0xffff) != 0)
1743 /* get signal encoded by kill */
1744 sim_engine_halt (simulator
, STATE_CPU (simulator
, 0), NULL
, PC
,
1745 sim_signalled
, PARM1
& 0xffff);
1746 else if (PARM1
== 0xdead)
1748 sim_engine_halt (simulator
, STATE_CPU (simulator
, 0), NULL
, PC
,
1749 sim_stopped
, SIM_SIGABRT
);
1751 /* PARM1 has exit status */
1752 sim_engine_halt (simulator
, STATE_CPU (simulator
, 0), NULL
, PC
,
1756 case TARGET_NEWLIB_V850_SYS_stat
: /* added at hmsi */
1757 /* stat system call */
1759 struct stat host_stat
;
1761 char *path
= fetch_str (simulator
, PARM1
);
1763 RETVAL
= sim_io_stat (simulator
, path
, &host_stat
);
1768 /* Just wild-assed guesses. */
1769 store_mem (buf
, 2, host_stat
.st_dev
);
1770 store_mem (buf
+ 2, 2, host_stat
.st_ino
);
1771 store_mem (buf
+ 4, 4, host_stat
.st_mode
);
1772 store_mem (buf
+ 8, 2, host_stat
.st_nlink
);
1773 store_mem (buf
+ 10, 2, host_stat
.st_uid
);
1774 store_mem (buf
+ 12, 2, host_stat
.st_gid
);
1775 store_mem (buf
+ 14, 2, host_stat
.st_rdev
);
1776 store_mem (buf
+ 16, 4, host_stat
.st_size
);
1777 store_mem (buf
+ 20, 4, host_stat
.st_atime
);
1778 store_mem (buf
+ 28, 4, host_stat
.st_mtime
);
1779 store_mem (buf
+ 36, 4, host_stat
.st_ctime
);
1781 if ((int) RETVAL
< 0)
1782 RETERR
= sim_io_get_errno (simulator
);
1786 case TARGET_NEWLIB_V850_SYS_fstat
:
1787 /* fstat system call */
1789 struct stat host_stat
;
1792 RETVAL
= sim_io_fstat (simulator
, PARM1
, &host_stat
);
1796 /* Just wild-assed guesses. */
1797 store_mem (buf
, 2, host_stat
.st_dev
);
1798 store_mem (buf
+ 2, 2, host_stat
.st_ino
);
1799 store_mem (buf
+ 4, 4, host_stat
.st_mode
);
1800 store_mem (buf
+ 8, 2, host_stat
.st_nlink
);
1801 store_mem (buf
+ 10, 2, host_stat
.st_uid
);
1802 store_mem (buf
+ 12, 2, host_stat
.st_gid
);
1803 store_mem (buf
+ 14, 2, host_stat
.st_rdev
);
1804 store_mem (buf
+ 16, 4, host_stat
.st_size
);
1805 store_mem (buf
+ 20, 4, host_stat
.st_atime
);
1806 store_mem (buf
+ 28, 4, host_stat
.st_mtime
);
1807 store_mem (buf
+ 36, 4, host_stat
.st_ctime
);
1809 if ((int) RETVAL
< 0)
1810 RETERR
= sim_io_get_errno (simulator
);
1814 case TARGET_NEWLIB_V850_SYS_rename
:
1816 char *oldpath
= fetch_str (simulator
, PARM1
);
1817 char *newpath
= fetch_str (simulator
, PARM2
);
1818 RETVAL
= sim_io_rename (simulator
, oldpath
, newpath
);
1821 if ((int) RETVAL
< 0)
1822 RETERR
= sim_io_get_errno (simulator
);
1826 case TARGET_NEWLIB_V850_SYS_unlink
:
1828 char *path
= fetch_str (simulator
, PARM1
);
1829 RETVAL
= sim_io_unlink (simulator
, path
);
1831 if ((int) RETVAL
< 0)
1832 RETERR
= sim_io_get_errno (simulator
);
1836 case TARGET_NEWLIB_V850_SYS_chown
:
1838 char *path
= fetch_str (simulator
, PARM1
);
1839 RETVAL
= chown (path
, PARM2
, PARM3
);
1846 case TARGET_NEWLIB_V850_SYS_chmod
:
1848 char *path
= fetch_str (simulator
, PARM1
);
1849 RETVAL
= chmod (path
, PARM2
);
1857 case TARGET_NEWLIB_V850_SYS_time
:
1860 RETVAL
= time (&now
);
1861 store_mem (PARM1
, 4, now
);
1867 #if !defined(__GO32__) && !defined(_WIN32)
1868 case TARGET_NEWLIB_V850_SYS_times
:
1871 RETVAL
= times (&tms
);
1872 store_mem (PARM1
, 4, tms
.tms_utime
);
1873 store_mem (PARM1
+ 4, 4, tms
.tms_stime
);
1874 store_mem (PARM1
+ 8, 4, tms
.tms_cutime
);
1875 store_mem (PARM1
+ 12, 4, tms
.tms_cstime
);
1881 #if !defined(__GO32__) && !defined(_WIN32)
1882 case TARGET_NEWLIB_V850_SYS_gettimeofday
:
1886 RETVAL
= gettimeofday (&t
, &tz
);
1887 store_mem (PARM1
, 4, t
.tv_sec
);
1888 store_mem (PARM1
+ 4, 4, t
.tv_usec
);
1889 store_mem (PARM2
, 4, tz
.tz_minuteswest
);
1890 store_mem (PARM2
+ 4, 4, tz
.tz_dsttime
);
1897 case TARGET_NEWLIB_V850_SYS_utime
:
1899 /* Cast the second argument to void *, to avoid type mismatch
1900 if a prototype is present. */
1901 sim_io_error (simulator
, "Utime not supported");
1902 /* RETVAL = utime (path, (void *) MEMPTR (PARM2)); */
1915 { /* Trap 0 -> 30 */
1920 ECR
|= 0x40 + OP
[0];
1921 /* Flag that we are now doing exception processing. */
1922 PSW
|= PSW_EP
| PSW_ID
;
1923 PC
= (OP
[0] < 0x10) ? 0x40 : 0x50;
1929 /* tst1 reg2, [reg1] */
1935 trace_input ("tst1", OP_BIT
, 1);
1937 temp
= load_mem (State
.regs
[ OP
[0] ], 1);
1940 if ((temp
& (1 << (State
.regs
[ OP
[1] ] & 0x7))) == 0)
1943 trace_output (OP_BIT
);
1948 /* mulu reg1, reg2, reg3 */
1952 trace_input ("mulu", OP_REG_REG_REG
, 0);
1954 Multiply64 (0, State
.regs
[ OP
[0] ]);
1956 trace_output (OP_REG_REG_REG
);
1961 #define BIT_CHANGE_OP( name, binop ) \
1963 unsigned int temp; \
1965 trace_input (name, OP_BIT_CHANGE, 0); \
1967 bit = 1 << (State.regs[ OP[1] ] & 0x7); \
1968 temp = load_mem (State.regs[ OP[0] ], 1); \
1971 if ((temp & bit) == 0) \
1975 store_mem (State.regs[ OP[0] ], 1, temp); \
1977 trace_output (OP_BIT_CHANGE); \
1981 /* clr1 reg2, [reg1] */
1985 BIT_CHANGE_OP ("clr1", &= ~ );
1988 /* not1 reg2, [reg1] */
1992 BIT_CHANGE_OP ("not1", ^= );
1999 BIT_CHANGE_OP ("set1", |= );
2006 trace_input ("sasf", OP_EX1
, 0);
2008 State
.regs
[ OP
[1] ] = (State
.regs
[ OP
[1] ] << 1) | condition_met (OP
[0]);
2010 trace_output (OP_EX1
);
2015 /* This function is courtesy of Sugimoto at NEC, via Seow Tan
2016 (Soew_Tan@el.nec.com) */
2021 unsigned long int als
,
2022 unsigned long int sfi
,
2023 uint32_t /*unsigned long int*/ * quotient_ptr
,
2024 uint32_t /*unsigned long int*/ * remainder_ptr
,
2028 unsigned long ald
= sfi
>> (N
- 1);
2029 unsigned long alo
= als
;
2034 unsigned int R1
= 1;
2035 unsigned int DBZ
= (als
== 0) ? 1 : 0;
2036 unsigned long alt
= Q
? ~als
: als
;
2039 alo
= ald
+ alt
+ Q
;
2040 C
= (((alt
>> 31) & (ald
>> 31))
2041 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2044 R1
= (alo
== 0) ? 0 : (R1
& Q
);
2045 if ((S
^ (alo
>>31)) && !C
)
2050 sfi
= (sfi
<< (32-N
+1)) | Q
;
2051 ald
= (alo
<< 1) | (sfi
>> 31);
2053 /* 2nd - N-1th Loop */
2054 for (i
= 2; i
< N
; i
++)
2056 alt
= Q
? ~als
: als
;
2057 alo
= ald
+ alt
+ Q
;
2058 C
= (((alt
>> 31) & (ald
>> 31))
2059 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2062 R1
= (alo
== 0) ? 0 : (R1
& Q
);
2063 if ((S
^ (alo
>>31)) && !C
&& !DBZ
)
2068 sfi
= (sfi
<< 1) | Q
;
2069 ald
= (alo
<< 1) | (sfi
>> 31);
2073 alt
= Q
? ~als
: als
;
2074 alo
= ald
+ alt
+ Q
;
2075 C
= (((alt
>> 31) & (ald
>> 31))
2076 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2079 R1
= (alo
== 0) ? 0 : (R1
& Q
);
2080 if ((S
^ (alo
>>31)) && !C
)
2085 * quotient_ptr
= (sfi
<< 1) | Q
;
2086 * remainder_ptr
= Q
? alo
: (alo
+ als
);
2087 * overflow_ptr
= DBZ
| R1
;
2090 /* This function is courtesy of Sugimoto at NEC, via Seow Tan (Soew_Tan@el.nec.com) */
2095 unsigned long int als
,
2096 unsigned long int sfi
,
2097 int32_t /*signed long int*/ * quotient_ptr
,
2098 int32_t /*signed long int*/ * remainder_ptr
,
2102 unsigned long ald
= (signed long) sfi
>> (N
- 1);
2103 unsigned long alo
= als
;
2104 unsigned int SS
= als
>> 31;
2105 unsigned int SD
= sfi
>> 31;
2106 unsigned int R1
= 1;
2108 unsigned int DBZ
= als
== 0 ? 1 : 0;
2109 unsigned int Q
= ~(SS
^ SD
) & 1;
2113 unsigned long alt
= Q
? ~als
: als
;
2118 alo
= ald
+ alt
+ Q
;
2119 C
= (((alt
>> 31) & (ald
>> 31))
2120 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2122 R1
= (alo
== 0) ? 0 : (R1
& (Q
^ (SS
^ SD
)));
2124 sfi
= (sfi
<< (32-N
+1)) | Q
;
2125 ald
= (alo
<< 1) | (sfi
>> 31);
2126 if ((alo
>> 31) ^ (ald
>> 31))
2131 /* 2nd - N-1th Loop */
2133 for (i
= 2; i
< N
; i
++)
2135 alt
= Q
? ~als
: als
;
2136 alo
= ald
+ alt
+ Q
;
2137 C
= (((alt
>> 31) & (ald
>> 31))
2138 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2140 R1
= (alo
== 0) ? 0 : (R1
& (Q
^ (SS
^ SD
)));
2142 sfi
= (sfi
<< 1) | Q
;
2143 ald
= (alo
<< 1) | (sfi
>> 31);
2144 if ((alo
>> 31) ^ (ald
>> 31))
2151 alt
= Q
? ~als
: als
;
2152 alo
= ald
+ alt
+ Q
;
2153 C
= (((alt
>> 31) & (ald
>> 31))
2154 | (((alt
>> 31) ^ (ald
>> 31)) & (~alo
>> 31)));
2156 R1
= (alo
== 0) ? 0 : (R1
& (Q
^ (SS
^ SD
)));
2157 sfi
= (sfi
<< (32-N
+1));
2163 alt
= Q
? ~als
: als
;
2164 alo
= ald
+ alt
+ Q
;
2166 R1
= R1
& ((~alo
>> 31) ^ SD
);
2167 if ((alo
!= 0) && ((Q
^ (SS
^ SD
)) ^ R1
)) alo
= ald
;
2169 ald
= sfi
= (long) ((sfi
>> 1) | (SS
^ SD
) << 31) >> (32-N
-1) | Q
;
2171 ald
= sfi
= sfi
| Q
;
2173 OV
= DBZ
| ((alo
== 0) ? 0 : R1
);
2175 * remainder_ptr
= alo
;
2178 if (((alo
!= 0) && ((SS
^ SD
) ^ R1
))
2179 || ((alo
== 0) && (SS
^ R1
)))
2184 OV
= (DBZ
| R1
) ? OV
: ((alo
>> 31) & (~ald
>> 31));
2186 * quotient_ptr
= alo
;
2187 * overflow_ptr
= OV
;
2190 /* sdivun imm5, reg1, reg2, reg3 */
2194 uint32_t /*unsigned long int*/ quotient
;
2195 uint32_t /*unsigned long int*/ remainder
;
2196 unsigned long int divide_by
;
2197 unsigned long int divide_this
;
2201 trace_input ("sdivun", OP_IMM_REG_REG_REG
, 0);
2203 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2205 divide_by
= State
.regs
[ OP
[0] ];
2206 divide_this
= State
.regs
[ OP
[1] ] << imm5
;
2208 divun (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2210 State
.regs
[ OP
[1] ] = quotient
;
2211 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2213 /* Set condition codes. */
2214 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2216 if (overflow
) PSW
|= PSW_OV
;
2217 if (quotient
== 0) PSW
|= PSW_Z
;
2218 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2220 trace_output (OP_IMM_REG_REG_REG
);
2225 /* sdivn imm5, reg1, reg2, reg3 */
2229 int32_t /*signed long int*/ quotient
;
2230 int32_t /*signed long int*/ remainder
;
2231 signed long int divide_by
;
2232 signed long int divide_this
;
2236 trace_input ("sdivn", OP_IMM_REG_REG_REG
, 0);
2238 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2240 divide_by
= (int32_t) State
.regs
[ OP
[0] ];
2241 divide_this
= (int32_t) (State
.regs
[ OP
[1] ] << imm5
);
2243 divn (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2245 State
.regs
[ OP
[1] ] = quotient
;
2246 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2248 /* Set condition codes. */
2249 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2251 if (overflow
) PSW
|= PSW_OV
;
2252 if (quotient
== 0) PSW
|= PSW_Z
;
2253 if (quotient
< 0) PSW
|= PSW_S
;
2255 trace_output (OP_IMM_REG_REG_REG
);
2260 /* sdivhun imm5, reg1, reg2, reg3 */
2264 uint32_t /*unsigned long int*/ quotient
;
2265 uint32_t /*unsigned long int*/ remainder
;
2266 unsigned long int divide_by
;
2267 unsigned long int divide_this
;
2271 trace_input ("sdivhun", OP_IMM_REG_REG_REG
, 0);
2273 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2275 divide_by
= State
.regs
[ OP
[0] ] & 0xffff;
2276 divide_this
= State
.regs
[ OP
[1] ] << imm5
;
2278 divun (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2280 State
.regs
[ OP
[1] ] = quotient
;
2281 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2283 /* Set condition codes. */
2284 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2286 if (overflow
) PSW
|= PSW_OV
;
2287 if (quotient
== 0) PSW
|= PSW_Z
;
2288 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2290 trace_output (OP_IMM_REG_REG_REG
);
2295 /* sdivhn imm5, reg1, reg2, reg3 */
2299 int32_t /*signed long int*/ quotient
;
2300 int32_t /*signed long int*/ remainder
;
2301 signed long int divide_by
;
2302 signed long int divide_this
;
2306 trace_input ("sdivhn", OP_IMM_REG_REG_REG
, 0);
2308 imm5
= 32 - ((OP
[3] & 0x3c0000) >> 17);
2310 divide_by
= EXTEND16 (State
.regs
[ OP
[0] ]);
2311 divide_this
= (int32_t) (State
.regs
[ OP
[1] ] << imm5
);
2313 divn (imm5
, divide_by
, divide_this
, & quotient
, & remainder
, & overflow
);
2315 State
.regs
[ OP
[1] ] = quotient
;
2316 State
.regs
[ OP
[2] >> 11 ] = remainder
;
2318 /* Set condition codes. */
2319 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2321 if (overflow
) PSW
|= PSW_OV
;
2322 if (quotient
== 0) PSW
|= PSW_Z
;
2323 if (quotient
< 0) PSW
|= PSW_S
;
2325 trace_output (OP_IMM_REG_REG_REG
);
2330 /* divu reg1, reg2, reg3 */
2334 unsigned long int quotient
;
2335 unsigned long int remainder
;
2336 unsigned long int divide_by
;
2337 unsigned long int divide_this
;
2340 trace_input ("divu", OP_REG_REG_REG
, 0);
2342 /* Compute the result. */
2344 divide_by
= State
.regs
[ OP
[0] ];
2345 divide_this
= State
.regs
[ OP
[1] ];
2353 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
2354 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
2356 /* Set condition codes. */
2357 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2359 if (overflow
) PSW
|= PSW_OV
;
2360 if (quotient
== 0) PSW
|= PSW_Z
;
2361 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2364 trace_output (OP_REG_REG_REG
);
2369 /* div reg1, reg2, reg3 */
2373 signed long int quotient
;
2374 signed long int remainder
;
2375 signed long int divide_by
;
2376 signed long int divide_this
;
2378 trace_input ("div", OP_REG_REG_REG
, 0);
2380 /* Compute the result. */
2382 divide_by
= (int32_t) State
.regs
[ OP
[0] ];
2383 divide_this
= State
.regs
[ OP
[1] ];
2389 else if (divide_by
== -1 && divide_this
== (1L << 31))
2392 PSW
|= PSW_OV
| PSW_S
;
2393 State
.regs
[ OP
[1] ] = (1 << 31);
2394 State
.regs
[ OP
[2] >> 11 ] = 0;
2398 divide_this
= (int32_t) divide_this
;
2399 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
2400 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
2402 /* Set condition codes. */
2403 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2405 if (quotient
== 0) PSW
|= PSW_Z
;
2406 if (quotient
< 0) PSW
|= PSW_S
;
2409 trace_output (OP_REG_REG_REG
);
2414 /* divhu reg1, reg2, reg3 */
2418 unsigned long int quotient
;
2419 unsigned long int remainder
;
2420 unsigned long int divide_by
;
2421 unsigned long int divide_this
;
2424 trace_input ("divhu", OP_REG_REG_REG
, 0);
2426 /* Compute the result. */
2428 divide_by
= State
.regs
[ OP
[0] ] & 0xffff;
2429 divide_this
= State
.regs
[ OP
[1] ];
2437 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
2438 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
2440 /* Set condition codes. */
2441 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2443 if (overflow
) PSW
|= PSW_OV
;
2444 if (quotient
== 0) PSW
|= PSW_Z
;
2445 if (quotient
& 0x80000000) PSW
|= PSW_S
;
2448 trace_output (OP_REG_REG_REG
);
2453 /* divh reg1, reg2, reg3 */
2457 signed long int quotient
;
2458 signed long int remainder
;
2459 signed long int divide_by
;
2460 signed long int divide_this
;
2463 trace_input ("divh", OP_REG_REG_REG
, 0);
2465 /* Compute the result. */
2467 divide_by
= EXTEND16 (State
.regs
[ OP
[0] ]);
2468 divide_this
= State
.regs
[ OP
[1] ];
2474 else if (divide_by
== -1 && divide_this
== (1L << 31))
2477 PSW
|= PSW_OV
| PSW_S
;
2478 State
.regs
[ OP
[1] ] = (1 << 31);
2479 State
.regs
[ OP
[2] >> 11 ] = 0;
2483 divide_this
= (int32_t) divide_this
;
2484 State
.regs
[ OP
[1] ] = quotient
= divide_this
/ divide_by
;
2485 State
.regs
[ OP
[2] >> 11 ] = remainder
= divide_this
% divide_by
;
2487 /* Set condition codes. */
2488 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
2490 if (quotient
== 0) PSW
|= PSW_Z
;
2491 if (quotient
< 0) PSW
|= PSW_S
;
2494 trace_output (OP_REG_REG_REG
);
2499 /* mulu imm9, reg2, reg3 */
2503 trace_input ("mulu", OP_IMM_REG_REG
, 0);
2505 Multiply64 (0, (OP
[3] & 0x1f) | ((OP
[3] >> 13) & 0x1e0));
2507 trace_output (OP_IMM_REG_REG
);
2512 /* mul imm9, reg2, reg3 */
2516 trace_input ("mul", OP_IMM_REG_REG
, 0);
2518 Multiply64 (1, SEXT9 ((OP
[3] & 0x1f) | ((OP
[3] >> 13) & 0x1e0)));
2520 trace_output (OP_IMM_REG_REG
);
2531 trace_input ("ld.hu", OP_LOAD32
, 2);
2533 adr
= State
.regs
[ OP
[0] ] + EXTEND16 (OP
[2] & ~1);
2536 State
.regs
[ OP
[1] ] = load_mem (adr
, 2);
2538 trace_output (OP_LOAD32
);
2550 trace_input ("ld.bu", OP_LOAD32
, 1);
2552 adr
= (State
.regs
[ OP
[0] ]
2553 + (EXTEND16 (OP
[2] & ~1) | ((OP
[3] >> 5) & 1)));
2555 State
.regs
[ OP
[1] ] = load_mem (adr
, 1);
2557 trace_output (OP_LOAD32
);
2562 /* prepare list12, imm5, imm32 */
2568 trace_input ("prepare", OP_PUSHPOP1
, 0);
2570 /* Store the registers with lower number registers being placed at higher addresses. */
2571 for (i
= 0; i
< 12; i
++)
2572 if ((OP
[3] & (1 << type1_regs
[ i
])))
2575 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
2578 SP
-= (OP
[3] & 0x3e) << 1;
2580 EP
= load_mem (PC
+ 4, 4);
2582 trace_output (OP_PUSHPOP1
);
2587 /* prepare list12, imm5, imm16-32 */
2593 trace_input ("prepare", OP_PUSHPOP1
, 0);
2595 /* Store the registers with lower number registers being placed at higher addresses. */
2596 for (i
= 0; i
< 12; i
++)
2597 if ((OP
[3] & (1 << type1_regs
[ i
])))
2600 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
2603 SP
-= (OP
[3] & 0x3e) << 1;
2605 EP
= load_mem (PC
+ 4, 2) << 16;
2607 trace_output (OP_PUSHPOP1
);
2612 /* prepare list12, imm5, imm16 */
2618 trace_input ("prepare", OP_PUSHPOP1
, 0);
2620 /* Store the registers with lower number registers being placed at higher addresses. */
2621 for (i
= 0; i
< 12; i
++)
2622 if ((OP
[3] & (1 << type1_regs
[ i
])))
2625 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
2628 SP
-= (OP
[3] & 0x3e) << 1;
2630 EP
= EXTEND16 (load_mem (PC
+ 4, 2));
2632 trace_output (OP_PUSHPOP1
);
2637 /* prepare list12, imm5, sp */
2643 trace_input ("prepare", OP_PUSHPOP1
, 0);
2645 /* Store the registers with lower number registers being placed at higher addresses. */
2646 for (i
= 0; i
< 12; i
++)
2647 if ((OP
[3] & (1 << type1_regs
[ i
])))
2650 store_mem (SP
, 4, State
.regs
[ 20 + i
]);
2653 SP
-= (OP
[3] & 0x3e) << 1;
2657 trace_output (OP_PUSHPOP1
);
2662 /* mul reg1, reg2, reg3 */
2666 trace_input ("mul", OP_REG_REG_REG
, 0);
2668 Multiply64 (1, State
.regs
[ OP
[0] ]);
2670 trace_output (OP_REG_REG_REG
);
2681 trace_input ("popmh", OP_PUSHPOP2
, 0);
2683 if (OP
[3] & (1 << 19))
2685 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
2687 FEPSW
= load_mem ( SP
& ~ 3, 4);
2688 FEPC
= load_mem ((SP
+ 4) & ~ 3, 4);
2692 EIPSW
= load_mem ( SP
& ~ 3, 4);
2693 EIPC
= load_mem ((SP
+ 4) & ~ 3, 4);
2699 /* Load the registers with lower number registers being retrieved from higher addresses. */
2701 if ((OP
[3] & (1 << type2_regs
[ i
])))
2703 State
.regs
[ i
+ 16 ] = load_mem (SP
& ~ 3, 4);
2707 trace_output (OP_PUSHPOP2
);
2718 trace_input ("popml", OP_PUSHPOP3
, 0);
2720 if (OP
[3] & (1 << 19))
2722 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
2724 FEPSW
= load_mem ( SP
& ~ 3, 4);
2725 FEPC
= load_mem ((SP
+ 4) & ~ 3, 4);
2729 EIPSW
= load_mem ( SP
& ~ 3, 4);
2730 EIPC
= load_mem ((SP
+ 4) & ~ 3, 4);
2736 if (OP
[3] & (1 << 3))
2738 PSW
= load_mem (SP
& ~ 3, 4);
2742 /* Load the registers with lower number registers being retrieved from higher addresses. */
2744 if ((OP
[3] & (1 << type3_regs
[ i
])))
2746 State
.regs
[ i
+ 1 ] = load_mem (SP
& ~ 3, 4);
2750 trace_output (OP_PUSHPOP2
);
2761 trace_input ("pushmh", OP_PUSHPOP2
, 0);
2763 /* Store the registers with lower number registers being placed at higher addresses. */
2764 for (i
= 0; i
< 16; i
++)
2765 if ((OP
[3] & (1 << type2_regs
[ i
])))
2768 store_mem (SP
& ~ 3, 4, State
.regs
[ i
+ 16 ]);
2771 if (OP
[3] & (1 << 19))
2775 if ((PSW
& PSW_NP
) && ((PSW
& PSW_EP
) == 0))
2777 store_mem ((SP
+ 4) & ~ 3, 4, FEPC
);
2778 store_mem ( SP
& ~ 3, 4, FEPSW
);
2782 store_mem ((SP
+ 4) & ~ 3, 4, EIPC
);
2783 store_mem ( SP
& ~ 3, 4, EIPSW
);
2787 trace_output (OP_PUSHPOP2
);
2792 /* V850E2R FPU functions */
2794 sim_fpu_status_invalid_snan = 1, -V--- (sim spec.)
2795 sim_fpu_status_invalid_qnan = 2, ----- (sim spec.)
2796 sim_fpu_status_invalid_isi = 4, (inf - inf) -V---
2797 sim_fpu_status_invalid_idi = 8, (inf / inf) -V---
2798 sim_fpu_status_invalid_zdz = 16, (0 / 0) -V---
2799 sim_fpu_status_invalid_imz = 32, (inf * 0) -V---
2800 sim_fpu_status_invalid_cvi = 64, convert to integer -V---
2801 sim_fpu_status_invalid_div0 = 128, (X / 0) --Z--
2802 sim_fpu_status_invalid_cmp = 256, compare ----- (sim spec.)
2803 sim_fpu_status_invalid_sqrt = 512, -V---
2804 sim_fpu_status_rounded = 1024, I----
2805 sim_fpu_status_inexact = 2048, I---- (sim spec.)
2806 sim_fpu_status_overflow = 4096, I--O-
2807 sim_fpu_status_underflow = 8192, I---U
2808 sim_fpu_status_denorm = 16384, ----U (sim spec.)
2812 update_fpsr (SIM_DESC sd
, sim_fpu_status status
, unsigned int mask
, unsigned int double_op_p
)
2814 unsigned int fpsr
= FPSR
& mask
;
2816 unsigned int flags
= 0;
2819 && ((status
& (sim_fpu_status_rounded
2820 | sim_fpu_status_overflow
2821 | sim_fpu_status_inexact
))
2822 || (status
& sim_fpu_status_underflow
2823 && (fpsr
& (FPSR_XEU
| FPSR_XEI
)) == 0
2824 && fpsr
& FPSR_FS
)))
2826 flags
|= FPSR_XCI
| FPSR_XPI
;
2830 && (status
& (sim_fpu_status_invalid_isi
2831 | sim_fpu_status_invalid_imz
2832 | sim_fpu_status_invalid_zdz
2833 | sim_fpu_status_invalid_idi
2834 | sim_fpu_status_invalid_cvi
2835 | sim_fpu_status_invalid_sqrt
2836 | sim_fpu_status_invalid_snan
)))
2838 flags
|= FPSR_XCV
| FPSR_XPV
;
2842 && (status
& sim_fpu_status_invalid_div0
))
2844 flags
|= FPSR_XCV
| FPSR_XPV
;
2848 && (status
& sim_fpu_status_overflow
))
2850 flags
|= FPSR_XCO
| FPSR_XPO
;
2853 if (((fpsr
& FPSR_XEU
) || (fpsr
& FPSR_FS
) == 0)
2854 && (status
& (sim_fpu_status_underflow
2855 | sim_fpu_status_denorm
)))
2857 flags
|= FPSR_XCU
| FPSR_XPU
;
2865 SignalExceptionFPE (sd
, double_op_p
);
2872 SignalException (SIM_DESC sd
)
2876 PSW
= PSW
& ~(PSW_NPV
| PSW_DMP
| PSW_IMP
);
2881 SignalExceptionFPE (SIM_DESC sd
, unsigned int double_op_p
)
2883 if (((PSW
& (PSW_NP
|PSW_ID
)) == 0)
2884 || !(FPSR
& (double_op_p
? FPSR_DEM
: FPSR_SEM
)))
2888 EIIC
= (FPSR
& (double_op_p
? FPSR_DEM
: FPSR_SEM
))
2890 PSW
|= (PSW_EP
| PSW_ID
);
2893 SignalException (sd
);
2898 check_invalid_snan (SIM_DESC sd
, sim_fpu_status status
, unsigned int double_op_p
)
2900 if ((FPSR
& FPSR_XEI
)
2901 && (status
& sim_fpu_status_invalid_snan
))
2906 SignalExceptionFPE (sd
, double_op_p
);
2911 v850_float_compare (SIM_DESC sd
, int cmp
, sim_fpu wop1
, sim_fpu wop2
, int double_op_p
)
2915 if (sim_fpu_is_nan (&wop1
) || sim_fpu_is_nan (&wop2
))
2919 if (FPSR
& FPSR_XEV
)
2921 FPSR
|= FPSR_XCV
| FPSR_XPV
;
2922 SignalExceptionFPE (sd
, double_op_p
);
2980 else if (sim_fpu_is_infinity (&wop1
) && sim_fpu_is_infinity (&wop2
)
2981 && sim_fpu_sign (&wop1
) == sim_fpu_sign (&wop2
))
3039 int gt
= 0,lt
= 0,eq
= 0, status
;
3041 status
= sim_fpu_cmp (&wop1
, &wop2
);
3045 case SIM_FPU_IS_SNAN
:
3046 case SIM_FPU_IS_QNAN
:
3050 case SIM_FPU_IS_NINF
:
3053 case SIM_FPU_IS_PINF
:
3056 case SIM_FPU_IS_NNUMBER
:
3059 case SIM_FPU_IS_PNUMBER
:
3062 case SIM_FPU_IS_NDENORM
:
3065 case SIM_FPU_IS_PDENORM
:
3068 case SIM_FPU_IS_NZERO
:
3069 case SIM_FPU_IS_PZERO
:
3127 ASSERT (result
!= -1);
3132 v850_div (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
, unsigned int *op3p
)
3134 signed long int quotient
;
3135 signed long int remainder
;
3136 signed long int divide_by
;
3137 signed long int divide_this
;
3138 bfd_boolean overflow
= FALSE
;
3140 /* Compute the result. */
3141 divide_by
= (int32_t)op0
;
3142 divide_this
= (int32_t)op1
;
3144 if (divide_by
== 0 || (divide_by
== -1 && divide_this
== (1 << 31)))
3150 quotient
= divide_this
/ divide_by
;
3151 remainder
= divide_this
% divide_by
;
3153 /* Set condition codes. */
3154 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3156 if (overflow
) PSW
|= PSW_OV
;
3157 if (quotient
== 0) PSW
|= PSW_Z
;
3158 if (quotient
< 0) PSW
|= PSW_S
;
3165 v850_divu (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
, unsigned int *op3p
)
3167 unsigned long int quotient
;
3168 unsigned long int remainder
;
3169 unsigned long int divide_by
;
3170 unsigned long int divide_this
;
3171 bfd_boolean overflow
= FALSE
;
3173 /* Compute the result. */
3184 quotient
= divide_this
/ divide_by
;
3185 remainder
= divide_this
% divide_by
;
3187 /* Set condition codes. */
3188 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3190 if (overflow
) PSW
|= PSW_OV
;
3191 if (quotient
== 0) PSW
|= PSW_Z
;
3192 if (quotient
& 0x80000000) PSW
|= PSW_S
;
3199 v850_sar (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3201 unsigned int result
, z
, s
, cy
;
3204 result
= (signed)op1
>> op0
;
3206 /* Compute the condition codes. */
3208 s
= (result
& 0x80000000);
3209 cy
= (op1
& (1 << (op0
- 1)));
3211 /* Store the result and condition codes. */
3212 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
3213 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3214 | (cy
? PSW_CY
: 0));
3220 v850_shl (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3222 unsigned int result
, z
, s
, cy
;
3225 result
= op1
<< op0
;
3227 /* Compute the condition codes. */
3229 s
= (result
& 0x80000000);
3230 cy
= (op1
& (1 << (32 - op0
)));
3232 /* Store the result and condition codes. */
3233 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
3234 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3235 | (cy
? PSW_CY
: 0));
3241 v850_rotl (SIM_DESC sd
, unsigned int amount
, unsigned int src
, unsigned int * dest
)
3243 unsigned int result
, z
, s
, cy
;
3246 result
= src
<< amount
;
3247 result
|= src
>> (32 - amount
);
3249 /* Compute the condition codes. */
3251 s
= (result
& 0x80000000);
3252 cy
= ! (result
& 1);
3254 /* Store the result and condition codes. */
3255 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
3256 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3257 | (cy
? PSW_CY
: 0));
3263 v850_bins (SIM_DESC sd
, unsigned int source
, unsigned int lsb
, unsigned int msb
,
3264 unsigned int * dest
)
3267 unsigned int result
, pos
, width
;
3271 width
= (msb
- lsb
) + 1;
3273 /* A width of 32 exhibits undefined behavior on the shift. The easiest
3274 way to make this code safe is to just avoid that case and set the mask
3275 to the right value. */
3279 mask
= ~ (-(1 << width
));
3283 result
= (* dest
) & ~ mask
;
3284 result
|= source
<< pos
;
3286 /* Compute the condition codes. */
3288 s
= result
& 0x80000000;
3290 /* Store the result and condition codes. */
3291 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
);
3292 PSW
|= (z
? PSW_Z
: 0) | (s
? PSW_S
: 0);
3298 v850_shr (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3300 unsigned int result
, z
, s
, cy
;
3303 result
= op1
>> op0
;
3305 /* Compute the condition codes. */
3307 s
= (result
& 0x80000000);
3308 cy
= (op1
& (1 << (op0
- 1)));
3310 /* Store the result and condition codes. */
3311 PSW
&= ~(PSW_Z
| PSW_S
| PSW_OV
| PSW_CY
);
3312 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3313 | (cy
? PSW_CY
: 0));
3319 v850_satadd (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3321 unsigned int result
, z
, s
, cy
, ov
, sat
;
3325 /* Compute the condition codes. */
3327 s
= (result
& 0x80000000);
3328 cy
= (result
< op0
|| result
< op1
);
3329 ov
= ((op0
& 0x80000000) == (op1
& 0x80000000)
3330 && (op0
& 0x80000000) != (result
& 0x80000000));
3333 /* Store the result and condition codes. */
3334 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
3335 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3336 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
3337 | (sat
? PSW_SAT
: 0));
3339 /* Handle saturated results. */
3342 result
= 0x7fffffff;
3347 result
= 0x80000000;
3355 v850_satsub (SIM_DESC sd
, unsigned int op0
, unsigned int op1
, unsigned int *op2p
)
3357 unsigned int result
, z
, s
, cy
, ov
, sat
;
3359 /* Compute the result. */
3362 /* Compute the condition codes. */
3364 s
= (result
& 0x80000000);
3366 ov
= ((op1
& 0x80000000) != (op0
& 0x80000000)
3367 && (op1
& 0x80000000) != (result
& 0x80000000));
3370 /* Store the result and condition codes. */
3371 PSW
&= ~(PSW_Z
| PSW_S
| PSW_CY
| PSW_OV
);
3372 PSW
|= ((z
? PSW_Z
: 0) | (s
? PSW_S
: 0)
3373 | (cy
? PSW_CY
: 0) | (ov
? PSW_OV
: 0)
3374 | (sat
? PSW_SAT
: 0));
3376 /* Handle saturated results. */
3379 result
= 0x7fffffff;
3384 result
= 0x80000000;
3392 load_data_mem (SIM_DESC sd
,
3401 data
= sim_core_read_unaligned_1 (STATE_CPU (sd
, 0),
3402 PC
, read_map
, addr
);
3405 data
= sim_core_read_unaligned_2 (STATE_CPU (sd
, 0),
3406 PC
, read_map
, addr
);
3409 data
= sim_core_read_unaligned_4 (STATE_CPU (sd
, 0),
3410 PC
, read_map
, addr
);
3419 store_data_mem (SIM_DESC sd
,
3427 store_mem (addr
, 1, data
);
3430 store_mem (addr
, 2, data
);
3433 store_mem (addr
, 4, data
);
3441 mpu_load_mem_test (SIM_DESC sd
, unsigned int addr
, int size
, int base_reg
)
3447 if (IPE0
&& addr
>= IPA2ADDR (IPA0L
) && addr
<= IPA2ADDR (IPA0L
) && IPR0
)
3451 else if (IPE1
&& addr
>= IPA2ADDR (IPA1L
) && addr
<= IPA2ADDR (IPA1L
) && IPR1
)
3455 else if (IPE2
&& addr
>= IPA2ADDR (IPA2L
) && addr
<= IPA2ADDR (IPA2L
) && IPR2
)
3459 else if (IPE3
&& addr
>= IPA2ADDR (IPA3L
) && addr
<= IPA2ADDR (IPA3L
) && IPR3
)
3463 else if (addr
>= PPA2ADDR (PPA
& ~PPM
) && addr
<= DPA2ADDR (PPA
| PPM
))
3465 /* preifarallel area */
3467 else if (addr
>= PPA2ADDR (SPAL
) && addr
<= DPA2ADDR (SPAU
))
3471 else if (DPE0
&& addr
>= DPA2ADDR (DPA0L
) && addr
<= DPA2ADDR (DPA0L
) && DPR0
3472 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3476 else if (DPE1
&& addr
>= DPA2ADDR (DPA1L
) && addr
<= DPA2ADDR (DPA1L
) && DPR1
3477 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3481 else if (DPE2
&& addr
>= DPA2ADDR (DPA2L
) && addr
<= DPA2ADDR (DPA2L
) && DPR2
3482 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3486 else if (DPE3
&& addr
>= DPA2ADDR (DPA3L
) && addr
<= DPA2ADDR (DPA3L
) && DPR3
3487 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3493 VMECR
&= ~(VMECR_VMW
| VMECR_VMX
);
3501 SignalException (sd
);
3510 mpu_store_mem_test (SIM_DESC sd
, unsigned int addr
, int size
, int base_reg
)
3516 if (addr
>= PPA2ADDR (PPA
& ~PPM
) && addr
<= DPA2ADDR (PPA
| PPM
))
3518 /* preifarallel area */
3520 else if (addr
>= PPA2ADDR (SPAL
) && addr
<= DPA2ADDR (SPAU
))
3524 else if (DPE0
&& addr
>= DPA2ADDR (DPA0L
) && addr
<= DPA2ADDR (DPA0L
) && DPW0
3525 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3529 else if (DPE1
&& addr
>= DPA2ADDR (DPA1L
) && addr
<= DPA2ADDR (DPA1L
) && DPW1
3530 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3534 else if (DPE2
&& addr
>= DPA2ADDR (DPA2L
) && addr
<= DPA2ADDR (DPA2L
) && DPW2
3535 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3539 else if (DPE3
&& addr
>= DPA2ADDR (DPA3L
) && addr
<= DPA2ADDR (DPA3L
) && DPW3
3540 && ((SPAL
& SPAL_SPS
) ? base_reg
== SP_REGNO
: 1))
3546 if (addr
>= PPA2ADDR (PPA
& ~PPM
) && addr
<= DPA2ADDR (PPA
| PPM
))
3561 VMECR
&= ~(VMECR_VMW
| VMECR_VMX
);