]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/d10v/simops.c
13 #include "targ-vals.h"
15 extern char *strrchr ();
48 PSW_MASK
= (PSW_SM_BIT
63 move_to_cr (int cr
, reg_t mask
, reg_t val
)
65 /* A MASK bit is set when the corresponding bit in the CR should
67 /* This assumes that (VAL & MASK) == 0 */
72 if ((mask
& PSW_SM_BIT
) == 0)
74 int new_sm
= (val
& PSW_SM_BIT
) != 0;
75 SET_HELD_SP (PSW_SM
, GPR (SP_IDX
)); /* save old SP */
77 SET_GPR (SP_IDX
, HELD_SP (new_sm
)); /* restore new SP */
79 if ((mask
& (PSW_ST_BIT
| PSW_FX_BIT
)) == 0)
81 if (val
& PSW_ST_BIT
&& !(val
& PSW_FX_BIT
))
83 (*d10v_callback
->printf_filtered
)
85 "ERROR at PC 0x%x: ST can only be set when FX is set.\n",
87 State
.exception
= SIGILL
;
90 /* keep an up-to-date psw around for tracing */
91 State
.trace
.psw
= (State
.trace
.psw
& mask
) | val
;
104 /* only issue an update if the register is being changed */
105 if ((State
.cregs
[cr
] & ~mask
) != val
)
106 SLOT_PEND_MASK (State
.cregs
[cr
], mask
, val
);
111 static void trace_input_func
PARAMS ((char *name
,
116 #define trace_input(name, in1, in2, in3) do { if (d10v_debug) trace_input_func (name, in1, in2, in3); } while (0)
118 #ifndef SIZE_INSTRUCTION
119 #define SIZE_INSTRUCTION 8
122 #ifndef SIZE_OPERANDS
123 #define SIZE_OPERANDS 18
127 #define SIZE_VALUES 13
130 #ifndef SIZE_LOCATION
131 #define SIZE_LOCATION 20
138 #ifndef SIZE_LINE_NUMBER
139 #define SIZE_LINE_NUMBER 4
143 trace_input_func (name
, in1
, in2
, in3
)
156 const char *filename
;
157 const char *functionname
;
158 unsigned int linenumber
;
161 if ((d10v_debug
& DEBUG_TRACE
) == 0)
164 switch (State
.ins_type
)
167 case INS_UNKNOWN
: type
= " ?"; break;
168 case INS_LEFT
: type
= " L"; break;
169 case INS_RIGHT
: type
= " R"; break;
170 case INS_LEFT_PARALLEL
: type
= "*L"; break;
171 case INS_RIGHT_PARALLEL
: type
= "*R"; break;
172 case INS_LEFT_COND_TEST
: type
= "?L"; break;
173 case INS_RIGHT_COND_TEST
: type
= "?R"; break;
174 case INS_LEFT_COND_EXE
: type
= "&L"; break;
175 case INS_RIGHT_COND_EXE
: type
= "&R"; break;
176 case INS_LONG
: type
= " B"; break;
179 if ((d10v_debug
& DEBUG_LINE_NUMBER
) == 0)
180 (*d10v_callback
->printf_filtered
) (d10v_callback
,
182 SIZE_PC
, (unsigned)PC
,
184 SIZE_INSTRUCTION
, name
);
189 byte_pc
= decode_pc ();
190 if (text
&& byte_pc
>= text_start
&& byte_pc
< text_end
)
192 filename
= (const char *)0;
193 functionname
= (const char *)0;
195 if (bfd_find_nearest_line (prog_bfd
, text
, (struct symbol_cache_entry
**)0, byte_pc
- text_start
,
196 &filename
, &functionname
, &linenumber
))
201 sprintf (p
, "#%-*d ", SIZE_LINE_NUMBER
, linenumber
);
206 sprintf (p
, "%-*s ", SIZE_LINE_NUMBER
+1, "---");
207 p
+= SIZE_LINE_NUMBER
+2;
212 sprintf (p
, "%s ", functionname
);
217 char *q
= strrchr (filename
, '/');
218 sprintf (p
, "%s ", (q
) ? q
+1 : filename
);
227 (*d10v_callback
->printf_filtered
) (d10v_callback
,
228 "0x%.*x %s: %-*.*s %-*s ",
229 SIZE_PC
, (unsigned)PC
,
231 SIZE_LOCATION
, SIZE_LOCATION
, buf
,
232 SIZE_INSTRUCTION
, name
);
240 for (i
= 0; i
< 3; i
++)
254 sprintf (p
, "%sr%d", comma
, OP
[i
]);
262 sprintf (p
, "%scr%d", comma
, OP
[i
]);
268 case OP_ACCUM_OUTPUT
:
269 case OP_ACCUM_REVERSE
:
270 sprintf (p
, "%sa%d", comma
, OP
[i
]);
276 sprintf (p
, "%s%d", comma
, OP
[i
]);
282 sprintf (p
, "%s%d", comma
, SEXT8(OP
[i
]));
288 sprintf (p
, "%s%d", comma
, SEXT4(OP
[i
]));
294 sprintf (p
, "%s%d", comma
, SEXT3(OP
[i
]));
300 sprintf (p
, "%s@r%d", comma
, OP
[i
]);
306 sprintf (p
, "%s@(%d,r%d)", comma
, (int16
)OP
[i
], OP
[i
+1]);
312 sprintf (p
, "%s@%d", comma
, OP
[i
]);
318 sprintf (p
, "%s@r%d+", comma
, OP
[i
]);
324 sprintf (p
, "%s@r%d-", comma
, OP
[i
]);
330 sprintf (p
, "%s@-r%d", comma
, OP
[i
]);
338 sprintf (p
, "%sf0", comma
);
341 sprintf (p
, "%sf1", comma
);
344 sprintf (p
, "%sc", comma
);
352 if ((d10v_debug
& DEBUG_VALUES
) == 0)
356 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%s", buf
);
361 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%-*s", SIZE_OPERANDS
, buf
);
364 for (i
= 0; i
< 3; i
++)
370 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s", SIZE_VALUES
, "");
376 case OP_ACCUM_OUTPUT
:
378 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s", SIZE_VALUES
, "---");
386 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "",
387 (uint16
) GPR (OP
[i
]));
391 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "", (uint16
) OP
[i
]);
395 tmp
= (long)((((uint32
) GPR (OP
[i
])) << 16) | ((uint32
) GPR (OP
[i
] + 1)));
396 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.8lx", SIZE_VALUES
-10, "", tmp
);
401 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "",
402 (uint16
) CREG (OP
[i
]));
406 case OP_ACCUM_REVERSE
:
407 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.2x%.8lx", SIZE_VALUES
-12, "",
408 ((int)(ACC (OP
[i
]) >> 32) & 0xff),
409 ((unsigned long) ACC (OP
[i
])) & 0xffffffff);
413 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "",
418 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "",
419 (uint16
)SEXT4(OP
[i
]));
423 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "",
424 (uint16
)SEXT8(OP
[i
]));
428 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "",
429 (uint16
)SEXT3(OP
[i
]));
434 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*sF0 = %d", SIZE_VALUES
-6, "",
438 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*sF1 = %d", SIZE_VALUES
-6, "",
442 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*sC = %d", SIZE_VALUES
-5, "",
448 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "",
450 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "",
451 (uint16
)GPR (OP
[i
+ 1]));
456 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "",
461 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "",
466 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "",
474 (*d10v_callback
->flush_stdout
) (d10v_callback
);
478 do_trace_output_flush (void)
480 (*d10v_callback
->flush_stdout
) (d10v_callback
);
484 do_trace_output_finish (void)
486 (*d10v_callback
->printf_filtered
) (d10v_callback
,
487 " F0=%d F1=%d C=%d\n",
488 (State
.trace
.psw
& PSW_F0_BIT
) != 0,
489 (State
.trace
.psw
& PSW_F1_BIT
) != 0,
490 (State
.trace
.psw
& PSW_C_BIT
) != 0);
491 (*d10v_callback
->flush_stdout
) (d10v_callback
);
495 trace_output_40 (uint64 val
)
497 if ((d10v_debug
& (DEBUG_TRACE
| DEBUG_VALUES
)) == (DEBUG_TRACE
| DEBUG_VALUES
))
499 (*d10v_callback
->printf_filtered
) (d10v_callback
,
500 " :: %*s0x%.2x%.8lx",
503 ((int)(val
>> 32) & 0xff),
504 ((unsigned long) val
) & 0xffffffff);
505 do_trace_output_finish ();
510 trace_output_32 (uint32 val
)
512 if ((d10v_debug
& (DEBUG_TRACE
| DEBUG_VALUES
)) == (DEBUG_TRACE
| DEBUG_VALUES
))
514 (*d10v_callback
->printf_filtered
) (d10v_callback
,
519 do_trace_output_finish ();
524 trace_output_16 (uint16 val
)
526 if ((d10v_debug
& (DEBUG_TRACE
| DEBUG_VALUES
)) == (DEBUG_TRACE
| DEBUG_VALUES
))
528 (*d10v_callback
->printf_filtered
) (d10v_callback
,
533 do_trace_output_finish ();
540 if ((d10v_debug
& (DEBUG_TRACE
| DEBUG_VALUES
)) == (DEBUG_TRACE
| DEBUG_VALUES
))
542 (*d10v_callback
->printf_filtered
) (d10v_callback
, "\n");
543 do_trace_output_flush ();
550 if ((d10v_debug
& (DEBUG_TRACE
| DEBUG_VALUES
)) == (DEBUG_TRACE
| DEBUG_VALUES
))
552 (*d10v_callback
->printf_filtered
) (d10v_callback
,
556 do_trace_output_finish ();
564 #define trace_input(NAME, IN1, IN2, IN3)
565 #define trace_output(RESULT)
573 trace_input ("abs", OP_REG
, OP_VOID
, OP_VOID
);
583 SET_GPR (OP
[0], tmp
);
584 trace_output_16 (tmp
);
592 trace_input ("abs", OP_ACCUM
, OP_VOID
, OP_VOID
);
595 tmp
= SEXT40 (ACC (OP
[0]));
601 if (tmp
> SEXT40(MAX32
))
603 else if (tmp
< SEXT40(MIN32
))
606 tmp
= (tmp
& MASK40
);
609 tmp
= (tmp
& MASK40
);
614 tmp
= (tmp
& MASK40
);
617 SET_ACC (OP
[0], tmp
);
618 trace_output_40 (tmp
);
625 uint16 a
= GPR (OP
[0]);
626 uint16 b
= GPR (OP
[1]);
627 uint16 tmp
= (a
+ b
);
628 trace_input ("add", OP_REG
, OP_REG
, OP_VOID
);
630 SET_GPR (OP
[0], tmp
);
631 trace_output_16 (tmp
);
639 tmp
= SEXT40(ACC (OP
[0])) + (SEXT16 (GPR (OP
[1])) << 16 | GPR (OP
[1] + 1));
641 trace_input ("add", OP_ACCUM
, OP_REG
, OP_VOID
);
644 if (tmp
> SEXT40(MAX32
))
646 else if (tmp
< SEXT40(MIN32
))
649 tmp
= (tmp
& MASK40
);
652 tmp
= (tmp
& MASK40
);
653 SET_ACC (OP
[0], tmp
);
654 trace_output_40 (tmp
);
662 tmp
= SEXT40(ACC (OP
[0])) + SEXT40(ACC (OP
[1]));
664 trace_input ("add", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
667 if (tmp
> SEXT40(MAX32
))
669 else if (tmp
< SEXT40(MIN32
))
672 tmp
= (tmp
& MASK40
);
675 tmp
= (tmp
& MASK40
);
676 SET_ACC (OP
[0], tmp
);
677 trace_output_40 (tmp
);
685 uint32 a
= (GPR (OP
[0])) << 16 | GPR (OP
[0] + 1);
686 uint32 b
= (GPR (OP
[1])) << 16 | GPR (OP
[1] + 1);
687 trace_input ("add2w", OP_DREG
, OP_DREG
, OP_VOID
);
690 SET_GPR (OP
[0] + 0, (tmp
>> 16));
691 SET_GPR (OP
[0] + 1, (tmp
& 0xFFFF));
692 trace_output_32 (tmp
);
699 uint16 a
= GPR (OP
[1]);
701 uint16 tmp
= (a
+ b
);
702 trace_input ("add3", OP_REG_OUTPUT
, OP_REG
, OP_CONSTANT16
);
704 SET_GPR (OP
[0], tmp
);
705 trace_output_16 (tmp
);
713 tmp
= SEXT40(ACC (OP
[2])) + SEXT40 ((GPR (OP
[1]) << 16) | GPR (OP
[1] + 1));
715 trace_input ("addac3", OP_DREG_OUTPUT
, OP_DREG
, OP_ACCUM
);
716 SET_GPR (OP
[0] + 0, ((tmp
>> 16) & 0xffff));
717 SET_GPR (OP
[0] + 1, (tmp
& 0xffff));
718 trace_output_32 (tmp
);
726 tmp
= SEXT40(ACC (OP
[1])) + SEXT40(ACC (OP
[2]));
728 trace_input ("addac3", OP_DREG_OUTPUT
, OP_ACCUM
, OP_ACCUM
);
729 SET_GPR (OP
[0] + 0, (tmp
>> 16) & 0xffff);
730 SET_GPR (OP
[0] + 1, tmp
& 0xffff);
731 trace_output_32 (tmp
);
741 trace_input ("addac3s", OP_DREG_OUTPUT
, OP_DREG
, OP_ACCUM
);
742 tmp
= SEXT40 (ACC (OP
[2])) + SEXT40 ((GPR (OP
[1]) << 16) | GPR (OP
[1] + 1));
743 if (tmp
> SEXT40(MAX32
))
748 else if (tmp
< SEXT40(MIN32
))
757 SET_GPR (OP
[0] + 0, (tmp
>> 16) & 0xffff);
758 SET_GPR (OP
[0] + 1, (tmp
& 0xffff));
759 trace_output_32 (tmp
);
769 trace_input ("addac3s", OP_DREG_OUTPUT
, OP_ACCUM
, OP_ACCUM
);
770 tmp
= SEXT40(ACC (OP
[1])) + SEXT40(ACC (OP
[2]));
771 if (tmp
> SEXT40(MAX32
))
776 else if (tmp
< SEXT40(MIN32
))
785 SET_GPR (OP
[0] + 0, (tmp
>> 16) & 0xffff);
786 SET_GPR (OP
[0] + 1, (tmp
& 0xffff));
787 trace_output_32 (tmp
);
794 uint16 a
= GPR (OP
[0]);
801 trace_input ("addi", OP_REG
, OP_CONSTANT16
, OP_VOID
);
803 SET_GPR (OP
[0], tmp
);
804 trace_output_16 (tmp
);
811 uint16 tmp
= GPR (OP
[0]) & GPR (OP
[1]);
812 trace_input ("and", OP_REG
, OP_REG
, OP_VOID
);
813 SET_GPR (OP
[0], tmp
);
814 trace_output_16 (tmp
);
821 uint16 tmp
= GPR (OP
[1]) & OP
[2];
822 trace_input ("and3", OP_REG_OUTPUT
, OP_REG
, OP_CONSTANT16
);
823 SET_GPR (OP
[0], tmp
);
824 trace_output_16 (tmp
);
832 trace_input ("bclri", OP_REG
, OP_CONSTANT16
, OP_VOID
);
833 tmp
= (GPR (OP
[0]) &~(0x8000 >> OP
[1]));
834 SET_GPR (OP
[0], tmp
);
835 trace_output_16 (tmp
);
842 trace_input ("bl.s", OP_CONSTANT8
, OP_R0
, OP_R1
);
843 SET_GPR (13, PC
+ 1);
844 JMP( PC
+ SEXT8 (OP
[0]));
845 trace_output_void ();
852 trace_input ("bl.l", OP_CONSTANT16
, OP_R0
, OP_R1
);
853 SET_GPR (13, (PC
+ 1));
855 trace_output_void ();
863 trace_input ("bnoti", OP_REG
, OP_CONSTANT16
, OP_VOID
);
864 tmp
= (GPR (OP
[0]) ^ (0x8000 >> OP
[1]));
865 SET_GPR (OP
[0], tmp
);
866 trace_output_16 (tmp
);
873 trace_input ("bra.s", OP_CONSTANT8
, OP_VOID
, OP_VOID
);
874 JMP (PC
+ SEXT8 (OP
[0]));
875 trace_output_void ();
882 trace_input ("bra.l", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
884 trace_output_void ();
891 trace_input ("brf0f.s", OP_CONSTANT8
, OP_VOID
, OP_VOID
);
893 JMP (PC
+ SEXT8 (OP
[0]));
894 trace_output_flag ();
901 trace_input ("brf0f.l", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
904 trace_output_flag ();
911 trace_input ("brf0t.s", OP_CONSTANT8
, OP_VOID
, OP_VOID
);
913 JMP (PC
+ SEXT8 (OP
[0]));
914 trace_output_flag ();
921 trace_input ("brf0t.l", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
924 trace_output_flag ();
932 trace_input ("bseti", OP_REG
, OP_CONSTANT16
, OP_VOID
);
933 tmp
= (GPR (OP
[0]) | (0x8000 >> OP
[1]));
934 SET_GPR (OP
[0], tmp
);
935 trace_output_16 (tmp
);
942 trace_input ("btsti", OP_REG
, OP_CONSTANT16
, OP_VOID
);
944 SET_PSW_F0 ((GPR (OP
[0]) & (0x8000 >> OP
[1])) ? 1 : 0);
945 trace_output_flag ();
952 trace_input ("clrac", OP_ACCUM_OUTPUT
, OP_VOID
, OP_VOID
);
961 trace_input ("cmp", OP_REG
, OP_REG
, OP_VOID
);
963 SET_PSW_F0 (((int16
)(GPR (OP
[0])) < (int16
)(GPR (OP
[1]))) ? 1 : 0);
964 trace_output_flag ();
971 trace_input ("cmp", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
973 SET_PSW_F0 ((SEXT40(ACC (OP
[0])) < SEXT40(ACC (OP
[1]))) ? 1 : 0);
974 trace_output_flag ();
981 trace_input ("cmpeq", OP_REG
, OP_REG
, OP_VOID
);
983 SET_PSW_F0 ((GPR (OP
[0]) == GPR (OP
[1])) ? 1 : 0);
984 trace_output_flag ();
991 trace_input ("cmpeq", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
993 SET_PSW_F0 (((ACC (OP
[0]) & MASK40
) == (ACC (OP
[1]) & MASK40
)) ? 1 : 0);
994 trace_output_flag ();
1001 trace_input ("cmpeqi.s", OP_REG
, OP_CONSTANT4
, OP_VOID
);
1002 SET_PSW_F1 (PSW_F0
);
1003 SET_PSW_F0 ((GPR (OP
[0]) == (reg_t
) SEXT4 (OP
[1])) ? 1 : 0);
1004 trace_output_flag ();
1011 trace_input ("cmpeqi.l", OP_REG
, OP_CONSTANT16
, OP_VOID
);
1012 SET_PSW_F1 (PSW_F0
);
1013 SET_PSW_F0 ((GPR (OP
[0]) == (reg_t
)OP
[1]) ? 1 : 0);
1014 trace_output_flag ();
1021 trace_input ("cmpi.s", OP_REG
, OP_CONSTANT4
, OP_VOID
);
1022 SET_PSW_F1 (PSW_F0
);
1023 SET_PSW_F0 (((int16
)(GPR (OP
[0])) < (int16
)SEXT4(OP
[1])) ? 1 : 0);
1024 trace_output_flag ();
1031 trace_input ("cmpi.l", OP_REG
, OP_CONSTANT16
, OP_VOID
);
1032 SET_PSW_F1 (PSW_F0
);
1033 SET_PSW_F0 (((int16
)(GPR (OP
[0])) < (int16
)(OP
[1])) ? 1 : 0);
1034 trace_output_flag ();
1041 trace_input ("cmpu", OP_REG
, OP_REG
, OP_VOID
);
1042 SET_PSW_F1 (PSW_F0
);
1043 SET_PSW_F0 ((GPR (OP
[0]) < GPR (OP
[1])) ? 1 : 0);
1044 trace_output_flag ();
1051 trace_input ("cmpui", OP_REG
, OP_CONSTANT16
, OP_VOID
);
1052 SET_PSW_F1 (PSW_F0
);
1053 SET_PSW_F0 ((GPR (OP
[0]) < (reg_t
)OP
[1]) ? 1 : 0);
1054 trace_output_flag ();
1063 trace_input ("cpfg", OP_FLAG_OUTPUT
, OP_FLAG
, OP_VOID
);
1067 else if (OP
[1] == 1)
1076 trace_output_flag ();
1083 /* d10v_callback->printf_filtered(d10v_callback, "***** DBT ***** PC=%x\n",PC); */
1085 /* GDB uses the instruction pair ``dbt || nop'' as a break-point.
1086 The conditional below is for either of the instruction pairs
1087 ``dbt -> XXX'' or ``dbt <- XXX'' and treats them as as cases
1088 where the dbt instruction should be interpreted.
1090 The module `sim-break' provides a more effective mechanism for
1091 detecting GDB planted breakpoints. The code below may,
1092 eventually, be changed to use that mechanism. */
1094 if (State
.ins_type
== INS_LEFT
1095 || State
.ins_type
== INS_RIGHT
)
1097 trace_input ("dbt", OP_VOID
, OP_VOID
, OP_VOID
);
1100 SET_PSW (PSW_DM_BIT
| (PSW
& (PSW_F0_BIT
| PSW_F1_BIT
| PSW_C_BIT
)));
1101 JMP (DBT_VECTOR_START
);
1102 trace_output_void ();
1106 State
.exception
= SIGTRAP
;
1114 uint16 foo
, tmp
, tmpf
;
1118 trace_input ("divs", OP_DREG
, OP_REG
, OP_VOID
);
1119 foo
= (GPR (OP
[0]) << 1) | (GPR (OP
[0] + 1) >> 15);
1120 tmp
= (int16
)foo
- (int16
)(GPR (OP
[1]));
1121 tmpf
= (foo
>= GPR (OP
[1])) ? 1 : 0;
1122 hi
= ((tmpf
== 1) ? tmp
: foo
);
1123 lo
= ((GPR (OP
[0] + 1) << 1) | tmpf
);
1124 SET_GPR (OP
[0] + 0, hi
);
1125 SET_GPR (OP
[0] + 1, lo
);
1126 trace_output_32 (((uint32
) hi
<< 16) | lo
);
1133 trace_input ("exef0f", OP_VOID
, OP_VOID
, OP_VOID
);
1134 State
.exe
= (PSW_F0
== 0);
1135 trace_output_flag ();
1142 trace_input ("exef0t", OP_VOID
, OP_VOID
, OP_VOID
);
1143 State
.exe
= (PSW_F0
!= 0);
1144 trace_output_flag ();
1151 trace_input ("exef1f", OP_VOID
, OP_VOID
, OP_VOID
);
1152 State
.exe
= (PSW_F1
== 0);
1153 trace_output_flag ();
1160 trace_input ("exef1t", OP_VOID
, OP_VOID
, OP_VOID
);
1161 State
.exe
= (PSW_F1
!= 0);
1162 trace_output_flag ();
1169 trace_input ("exefaf", OP_VOID
, OP_VOID
, OP_VOID
);
1170 State
.exe
= (PSW_F0
== 0) & (PSW_F1
== 0);
1171 trace_output_flag ();
1178 trace_input ("exefat", OP_VOID
, OP_VOID
, OP_VOID
);
1179 State
.exe
= (PSW_F0
== 0) & (PSW_F1
!= 0);
1180 trace_output_flag ();
1187 trace_input ("exetaf", OP_VOID
, OP_VOID
, OP_VOID
);
1188 State
.exe
= (PSW_F0
!= 0) & (PSW_F1
== 0);
1189 trace_output_flag ();
1196 trace_input ("exetat", OP_VOID
, OP_VOID
, OP_VOID
);
1197 State
.exe
= (PSW_F0
!= 0) & (PSW_F1
!= 0);
1198 trace_output_flag ();
1208 trace_input ("exp", OP_REG_OUTPUT
, OP_DREG
, OP_VOID
);
1209 if (((int16
)GPR (OP
[1])) >= 0)
1210 tmp
= (GPR (OP
[1]) << 16) | GPR (OP
[1] + 1);
1212 tmp
= ~((GPR (OP
[1]) << 16) | GPR (OP
[1] + 1));
1219 SET_GPR (OP
[0], (i
- 1));
1220 trace_output_16 (i
- 1);
1225 SET_GPR (OP
[0], 16);
1226 trace_output_16 (16);
1236 trace_input ("exp", OP_REG_OUTPUT
, OP_ACCUM
, OP_VOID
);
1237 tmp
= SEXT40(ACC (OP
[1]));
1239 tmp
= ~tmp
& MASK40
;
1241 foo
= 0x4000000000LL
;
1246 SET_GPR (OP
[0], i
- 9);
1247 trace_output_16 (i
- 9);
1252 SET_GPR (OP
[0], 16);
1253 trace_output_16 (16);
1260 trace_input ("jl", OP_REG
, OP_R0
, OP_R1
);
1261 SET_GPR (13, PC
+ 1);
1263 trace_output_void ();
1270 trace_input ("jmp", OP_REG
,
1271 (OP
[0] == 13) ? OP_R0
: OP_VOID
,
1272 (OP
[0] == 13) ? OP_R1
: OP_VOID
);
1275 trace_output_void ();
1283 trace_input ("ld", OP_REG_OUTPUT
, OP_MEMREF2
, OP_VOID
);
1284 tmp
= RW (OP
[1] + GPR (OP
[2]));
1285 SET_GPR (OP
[0], tmp
);
1286 trace_output_16 (tmp
);
1294 trace_input ("ld", OP_REG_OUTPUT
, OP_POSTDEC
, OP_VOID
);
1295 tmp
= RW (GPR (OP
[1]));
1296 SET_GPR (OP
[0], tmp
);
1298 INC_ADDR (OP
[1], -2);
1299 trace_output_16 (tmp
);
1307 trace_input ("ld", OP_REG_OUTPUT
, OP_POSTINC
, OP_VOID
);
1308 tmp
= RW (GPR (OP
[1]));
1309 SET_GPR (OP
[0], tmp
);
1311 INC_ADDR (OP
[1], 2);
1312 trace_output_16 (tmp
);
1320 trace_input ("ld", OP_REG_OUTPUT
, OP_MEMREF
, OP_VOID
);
1321 tmp
= RW (GPR (OP
[1]));
1322 SET_GPR (OP
[0], tmp
);
1323 trace_output_16 (tmp
);
1332 trace_input ("ld", OP_REG_OUTPUT
, OP_MEMREF3
, OP_VOID
);
1334 SET_GPR (OP
[0], tmp
);
1335 trace_output_16 (tmp
);
1343 uint16 addr
= GPR (OP
[2]);
1344 trace_input ("ld2w", OP_REG_OUTPUT
, OP_MEMREF2
, OP_VOID
);
1345 tmp
= RLW (OP
[1] + addr
);
1346 SET_GPR32 (OP
[0], tmp
);
1347 trace_output_32 (tmp
);
1354 uint16 addr
= GPR (OP
[1]);
1356 trace_input ("ld2w", OP_REG_OUTPUT
, OP_POSTDEC
, OP_VOID
);
1358 SET_GPR32 (OP
[0], tmp
);
1359 if (OP
[0] != OP
[1] && ((OP
[0] + 1) != OP
[1]))
1360 INC_ADDR (OP
[1], -4);
1361 trace_output_32 (tmp
);
1369 uint16 addr
= GPR (OP
[1]);
1370 trace_input ("ld2w", OP_REG_OUTPUT
, OP_POSTINC
, OP_VOID
);
1372 SET_GPR32 (OP
[0], tmp
);
1373 if (OP
[0] != OP
[1] && ((OP
[0] + 1) != OP
[1]))
1374 INC_ADDR (OP
[1], 4);
1375 trace_output_32 (tmp
);
1382 uint16 addr
= GPR (OP
[1]);
1384 trace_input ("ld2w", OP_REG_OUTPUT
, OP_MEMREF
, OP_VOID
);
1385 tmp
= RLW (addr
+ 0);
1386 SET_GPR32 (OP
[0], tmp
);
1387 trace_output_32 (tmp
);
1396 trace_input ("ld2w", OP_REG_OUTPUT
, OP_MEMREF3
, OP_VOID
);
1398 SET_GPR32 (OP
[0], tmp
);
1399 trace_output_32 (tmp
);
1407 trace_input ("ldb", OP_REG_OUTPUT
, OP_MEMREF2
, OP_VOID
);
1408 tmp
= SEXT8 (RB (OP
[1] + GPR (OP
[2])));
1409 SET_GPR (OP
[0], tmp
);
1410 trace_output_16 (tmp
);
1418 trace_input ("ldb", OP_REG_OUTPUT
, OP_MEMREF
, OP_VOID
);
1419 tmp
= SEXT8 (RB (GPR (OP
[1])));
1420 SET_GPR (OP
[0], tmp
);
1421 trace_output_16 (tmp
);
1429 trace_input ("ldi.s", OP_REG_OUTPUT
, OP_CONSTANT4
, OP_VOID
);
1430 tmp
= SEXT4 (OP
[1]);
1431 SET_GPR (OP
[0], tmp
);
1432 trace_output_16 (tmp
);
1440 trace_input ("ldi.l", OP_REG_OUTPUT
, OP_CONSTANT16
, OP_VOID
);
1442 SET_GPR (OP
[0], tmp
);
1443 trace_output_16 (tmp
);
1451 trace_input ("ldub", OP_REG_OUTPUT
, OP_MEMREF2
, OP_VOID
);
1452 tmp
= RB (OP
[1] + GPR (OP
[2]));
1453 SET_GPR (OP
[0], tmp
);
1454 trace_output_16 (tmp
);
1462 trace_input ("ldub", OP_REG_OUTPUT
, OP_MEMREF
, OP_VOID
);
1463 tmp
= RB (GPR (OP
[1]));
1464 SET_GPR (OP
[0], tmp
);
1465 trace_output_16 (tmp
);
1474 trace_input ("mac", OP_ACCUM
, OP_REG
, OP_REG
);
1475 tmp
= SEXT40 ((int16
)(GPR (OP
[1])) * (int16
)(GPR (OP
[2])));
1478 tmp
= SEXT40( (tmp
<< 1) & MASK40
);
1480 if (PSW_ST
&& tmp
> SEXT40(MAX32
))
1483 tmp
+= SEXT40 (ACC (OP
[0]));
1486 if (tmp
> SEXT40(MAX32
))
1488 else if (tmp
< SEXT40(MIN32
))
1491 tmp
= (tmp
& MASK40
);
1494 tmp
= (tmp
& MASK40
);
1495 SET_ACC (OP
[0], tmp
);
1496 trace_output_40 (tmp
);
1505 trace_input ("macsu", OP_ACCUM
, OP_REG
, OP_REG
);
1506 tmp
= SEXT40 ((int16
) GPR (OP
[1]) * GPR (OP
[2]));
1508 tmp
= SEXT40 ((tmp
<< 1) & MASK40
);
1509 tmp
= ((SEXT40 (ACC (OP
[0])) + tmp
) & MASK40
);
1510 SET_ACC (OP
[0], tmp
);
1511 trace_output_40 (tmp
);
1522 trace_input ("macu", OP_ACCUM
, OP_REG
, OP_REG
);
1523 src1
= (uint16
) GPR (OP
[1]);
1524 src2
= (uint16
) GPR (OP
[2]);
1528 tmp
= ((ACC (OP
[0]) + tmp
) & MASK40
);
1529 SET_ACC (OP
[0], tmp
);
1530 trace_output_40 (tmp
);
1538 trace_input ("max", OP_REG
, OP_REG
, OP_VOID
);
1539 SET_PSW_F1 (PSW_F0
);
1540 if ((int16
) GPR (OP
[1]) > (int16
)GPR (OP
[0]))
1550 SET_GPR (OP
[0], tmp
);
1551 trace_output_16 (tmp
);
1560 trace_input ("max", OP_ACCUM
, OP_DREG
, OP_VOID
);
1561 SET_PSW_F1 (PSW_F0
);
1562 tmp
= SEXT16 (GPR (OP
[1])) << 16 | GPR (OP
[1] + 1);
1563 if (tmp
> SEXT40 (ACC (OP
[0])))
1565 tmp
= (tmp
& MASK40
);
1573 SET_ACC (OP
[0], tmp
);
1574 trace_output_40 (tmp
);
1582 trace_input ("max", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
1583 SET_PSW_F1 (PSW_F0
);
1584 if (SEXT40 (ACC (OP
[1])) > SEXT40 (ACC (OP
[0])))
1594 SET_ACC (OP
[0], tmp
);
1595 trace_output_40 (tmp
);
1604 trace_input ("min", OP_REG
, OP_REG
, OP_VOID
);
1605 SET_PSW_F1 (PSW_F0
);
1606 if ((int16
)GPR (OP
[1]) < (int16
)GPR (OP
[0]))
1616 SET_GPR (OP
[0], tmp
);
1617 trace_output_16 (tmp
);
1626 trace_input ("min", OP_ACCUM
, OP_DREG
, OP_VOID
);
1627 SET_PSW_F1 (PSW_F0
);
1628 tmp
= SEXT16 (GPR (OP
[1])) << 16 | GPR (OP
[1] + 1);
1629 if (tmp
< SEXT40(ACC (OP
[0])))
1631 tmp
= (tmp
& MASK40
);
1639 SET_ACC (OP
[0], tmp
);
1640 trace_output_40 (tmp
);
1648 trace_input ("min", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
1649 SET_PSW_F1 (PSW_F0
);
1650 if (SEXT40(ACC (OP
[1])) < SEXT40(ACC (OP
[0])))
1660 SET_ACC (OP
[0], tmp
);
1661 trace_output_40 (tmp
);
1670 trace_input ("msb", OP_ACCUM
, OP_REG
, OP_REG
);
1671 tmp
= SEXT40 ((int16
)(GPR (OP
[1])) * (int16
)(GPR (OP
[2])));
1674 tmp
= SEXT40 ((tmp
<< 1) & MASK40
);
1676 if (PSW_ST
&& tmp
> SEXT40(MAX32
))
1679 tmp
= SEXT40(ACC (OP
[0])) - tmp
;
1682 if (tmp
> SEXT40(MAX32
))
1684 else if (tmp
< SEXT40(MIN32
))
1687 tmp
= (tmp
& MASK40
);
1691 tmp
= (tmp
& MASK40
);
1693 SET_ACC (OP
[0], tmp
);
1694 trace_output_40 (tmp
);
1703 trace_input ("msbsu", OP_ACCUM
, OP_REG
, OP_REG
);
1704 tmp
= SEXT40 ((int16
)GPR (OP
[1]) * GPR (OP
[2]));
1706 tmp
= SEXT40( (tmp
<< 1) & MASK40
);
1707 tmp
= ((SEXT40 (ACC (OP
[0])) - tmp
) & MASK40
);
1708 SET_ACC (OP
[0], tmp
);
1709 trace_output_40 (tmp
);
1720 trace_input ("msbu", OP_ACCUM
, OP_REG
, OP_REG
);
1721 src1
= (uint16
) GPR (OP
[1]);
1722 src2
= (uint16
) GPR (OP
[2]);
1726 tmp
= ((ACC (OP
[0]) - tmp
) & MASK40
);
1727 SET_ACC (OP
[0], tmp
);
1728 trace_output_40 (tmp
);
1736 trace_input ("mul", OP_REG
, OP_REG
, OP_VOID
);
1737 tmp
= GPR (OP
[0]) * GPR (OP
[1]);
1738 SET_GPR (OP
[0], tmp
);
1739 trace_output_16 (tmp
);
1748 trace_input ("mulx", OP_ACCUM_OUTPUT
, OP_REG
, OP_REG
);
1749 tmp
= SEXT40 ((int16
)(GPR (OP
[1])) * (int16
)(GPR (OP
[2])));
1752 tmp
= SEXT40 ((tmp
<< 1) & MASK40
);
1754 if (PSW_ST
&& tmp
> SEXT40(MAX32
))
1757 tmp
= (tmp
& MASK40
);
1758 SET_ACC (OP
[0], tmp
);
1759 trace_output_40 (tmp
);
1768 trace_input ("mulxsu", OP_ACCUM_OUTPUT
, OP_REG
, OP_REG
);
1769 tmp
= SEXT40 ((int16
)(GPR (OP
[1])) * GPR (OP
[2]));
1773 tmp
= (tmp
& MASK40
);
1774 SET_ACC (OP
[0], tmp
);
1775 trace_output_40 (tmp
);
1786 trace_input ("mulxu", OP_ACCUM_OUTPUT
, OP_REG
, OP_REG
);
1787 src1
= (uint16
) GPR (OP
[1]);
1788 src2
= (uint16
) GPR (OP
[2]);
1792 tmp
= (tmp
& MASK40
);
1793 SET_ACC (OP
[0], tmp
);
1794 trace_output_40 (tmp
);
1802 trace_input ("mv", OP_REG_OUTPUT
, OP_REG
, OP_VOID
);
1804 SET_GPR (OP
[0], tmp
);
1805 trace_output_16 (tmp
);
1813 trace_input ("mv2w", OP_DREG_OUTPUT
, OP_DREG
, OP_VOID
);
1814 tmp
= GPR32 (OP
[1]);
1815 SET_GPR32 (OP
[0], tmp
);
1816 trace_output_32 (tmp
);
1824 trace_input ("mv2wfac", OP_DREG_OUTPUT
, OP_ACCUM
, OP_VOID
);
1826 SET_GPR32 (OP
[0], tmp
);
1827 trace_output_32 (tmp
);
1835 trace_input ("mv2wtac", OP_DREG
, OP_ACCUM_OUTPUT
, OP_VOID
);
1836 tmp
= ((SEXT16 (GPR (OP
[0])) << 16 | GPR (OP
[0] + 1)) & MASK40
);
1837 SET_ACC (OP
[1], tmp
);
1838 trace_output_40 (tmp
);
1846 trace_input ("mvac", OP_ACCUM_OUTPUT
, OP_ACCUM
, OP_VOID
);
1848 SET_ACC (OP
[0], tmp
);
1849 trace_output_40 (tmp
);
1857 trace_input ("mvb", OP_REG_OUTPUT
, OP_REG
, OP_VOID
);
1858 tmp
= SEXT8 (GPR (OP
[1]) & 0xff);
1859 SET_GPR (OP
[0], tmp
);
1860 trace_output_16 (tmp
);
1868 trace_input ("mf0f", OP_REG_OUTPUT
, OP_REG
, OP_VOID
);
1872 SET_GPR (OP
[0], tmp
);
1876 trace_output_16 (tmp
);
1884 trace_input ("mf0t", OP_REG_OUTPUT
, OP_REG
, OP_VOID
);
1888 SET_GPR (OP
[0], tmp
);
1892 trace_output_16 (tmp
);
1900 trace_input ("mvfacg", OP_REG_OUTPUT
, OP_ACCUM
, OP_VOID
);
1901 tmp
= ((ACC (OP
[1]) >> 32) & 0xff);
1902 SET_GPR (OP
[0], tmp
);
1903 trace_output_16 (tmp
);
1911 trace_input ("mvfachi", OP_REG_OUTPUT
, OP_ACCUM
, OP_VOID
);
1912 tmp
= (ACC (OP
[1]) >> 16);
1913 SET_GPR (OP
[0], tmp
);
1914 trace_output_16 (tmp
);
1922 trace_input ("mvfaclo", OP_REG_OUTPUT
, OP_ACCUM
, OP_VOID
);
1924 SET_GPR (OP
[0], tmp
);
1925 trace_output_16 (tmp
);
1933 trace_input ("mvfc", OP_REG_OUTPUT
, OP_CR
, OP_VOID
);
1935 SET_GPR (OP
[0], tmp
);
1936 trace_output_16 (tmp
);
1944 trace_input ("mvtacg", OP_REG
, OP_ACCUM
, OP_VOID
);
1945 tmp
= ((ACC (OP
[1]) & MASK32
)
1946 | ((int64
)(GPR (OP
[0]) & 0xff) << 32));
1947 SET_ACC (OP
[1], tmp
);
1948 trace_output_40 (tmp
);
1956 trace_input ("mvtachi", OP_REG
, OP_ACCUM
, OP_VOID
);
1957 tmp
= ACC (OP
[1]) & 0xffff;
1958 tmp
= ((SEXT16 (GPR (OP
[0])) << 16 | tmp
) & MASK40
);
1959 SET_ACC (OP
[1], tmp
);
1960 trace_output_40 (tmp
);
1968 trace_input ("mvtaclo", OP_REG
, OP_ACCUM
, OP_VOID
);
1969 tmp
= ((SEXT16 (GPR (OP
[0]))) & MASK40
);
1970 SET_ACC (OP
[1], tmp
);
1971 trace_output_40 (tmp
);
1979 trace_input ("mvtc", OP_REG
, OP_CR_OUTPUT
, OP_VOID
);
1981 tmp
= SET_CREG (OP
[1], tmp
);
1982 trace_output_16 (tmp
);
1990 trace_input ("mvub", OP_REG_OUTPUT
, OP_REG
, OP_VOID
);
1991 tmp
= (GPR (OP
[1]) & 0xff);
1992 SET_GPR (OP
[0], tmp
);
1993 trace_output_16 (tmp
);
2001 trace_input ("neg", OP_REG
, OP_VOID
, OP_VOID
);
2002 tmp
= - GPR (OP
[0]);
2003 SET_GPR (OP
[0], tmp
);
2004 trace_output_16 (tmp
);
2013 trace_input ("neg", OP_ACCUM
, OP_VOID
, OP_VOID
);
2014 tmp
= -SEXT40(ACC (OP
[0]));
2017 if (tmp
> SEXT40(MAX32
))
2019 else if (tmp
< SEXT40(MIN32
))
2022 tmp
= (tmp
& MASK40
);
2025 tmp
= (tmp
& MASK40
);
2026 SET_ACC (OP
[0], tmp
);
2027 trace_output_40 (tmp
);
2035 trace_input ("nop", OP_VOID
, OP_VOID
, OP_VOID
);
2037 ins_type_counters
[ (int)State
.ins_type
]--; /* don't count nops as normal instructions */
2038 switch (State
.ins_type
)
2041 ins_type_counters
[ (int)INS_UNKNOWN
]++;
2044 case INS_LEFT_PARALLEL
:
2045 /* Don't count a parallel op that includes a NOP as a true parallel op */
2046 ins_type_counters
[ (int)INS_RIGHT_PARALLEL
]--;
2047 ins_type_counters
[ (int)INS_RIGHT
]++;
2048 ins_type_counters
[ (int)INS_LEFT_NOPS
]++;
2052 case INS_LEFT_COND_EXE
:
2053 ins_type_counters
[ (int)INS_LEFT_NOPS
]++;
2056 case INS_RIGHT_PARALLEL
:
2057 /* Don't count a parallel op that includes a NOP as a true parallel op */
2058 ins_type_counters
[ (int)INS_LEFT_PARALLEL
]--;
2059 ins_type_counters
[ (int)INS_LEFT
]++;
2060 ins_type_counters
[ (int)INS_RIGHT_NOPS
]++;
2064 case INS_RIGHT_COND_EXE
:
2065 ins_type_counters
[ (int)INS_RIGHT_NOPS
]++;
2069 trace_output_void ();
2077 trace_input ("not", OP_REG
, OP_VOID
, OP_VOID
);
2079 SET_GPR (OP
[0], tmp
);
2080 trace_output_16 (tmp
);
2088 trace_input ("or", OP_REG
, OP_REG
, OP_VOID
);
2089 tmp
= (GPR (OP
[0]) | GPR (OP
[1]));
2090 SET_GPR (OP
[0], tmp
);
2091 trace_output_16 (tmp
);
2099 trace_input ("or3", OP_REG_OUTPUT
, OP_REG
, OP_CONSTANT16
);
2100 tmp
= (GPR (OP
[1]) | OP
[2]);
2101 SET_GPR (OP
[0], tmp
);
2102 trace_output_16 (tmp
);
2110 int shift
= SEXT3 (OP
[2]);
2112 trace_input ("rac", OP_DREG_OUTPUT
, OP_ACCUM
, OP_CONSTANT3
);
2115 (*d10v_callback
->printf_filtered
) (d10v_callback
,
2116 "ERROR at PC 0x%x: instruction only valid for A0\n",
2118 State
.exception
= SIGILL
;
2121 SET_PSW_F1 (PSW_F0
);
2122 tmp
= SEXT56 ((ACC (0) << 16) | (ACC (1) & 0xffff));
2128 tmp
>>= 16; /* look at bits 0:43 */
2129 if (tmp
> SEXT44 (SIGNED64 (0x0007fffffff)))
2134 else if (tmp
< SEXT44 (SIGNED64 (0xfff80000000)))
2143 SET_GPR32 (OP
[0], tmp
);
2144 trace_output_32 (tmp
);
2152 int shift
= SEXT3 (OP
[2]);
2154 trace_input ("rachi", OP_REG_OUTPUT
, OP_ACCUM
, OP_CONSTANT3
);
2155 SET_PSW_F1 (PSW_F0
);
2157 tmp
= SEXT40 (ACC (OP
[1])) << shift
;
2159 tmp
= SEXT40 (ACC (OP
[1])) >> -shift
;
2162 if (tmp
> SEXT44 (SIGNED64 (0x0007fffffff)))
2167 else if (tmp
< SEXT44 (SIGNED64 (0xfff80000000)))
2177 SET_GPR (OP
[0], tmp
);
2178 trace_output_16 (tmp
);
2185 trace_input ("rep", OP_REG
, OP_CONSTANT16
, OP_VOID
);
2187 SET_RPT_E (PC
+ OP
[1]);
2188 SET_RPT_C (GPR (OP
[0]));
2190 if (GPR (OP
[0]) == 0)
2192 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: rep with count=0 is illegal.\n");
2193 State
.exception
= SIGILL
;
2197 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: rep must include at least 4 instructions.\n");
2198 State
.exception
= SIGILL
;
2200 trace_output_void ();
2207 trace_input ("repi", OP_CONSTANT16
, OP_CONSTANT16
, OP_VOID
);
2209 SET_RPT_E (PC
+ OP
[1]);
2214 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: repi with count=0 is illegal.\n");
2215 State
.exception
= SIGILL
;
2219 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: repi must include at least 4 instructions.\n");
2220 State
.exception
= SIGILL
;
2222 trace_output_void ();
2229 trace_input ("rtd", OP_VOID
, OP_VOID
, OP_VOID
);
2230 SET_CREG (PSW_CR
, DPSW
);
2232 trace_output_void ();
2239 trace_input ("rte", OP_VOID
, OP_VOID
, OP_VOID
);
2240 SET_CREG (PSW_CR
, BPSW
);
2242 trace_output_void ();
2251 trace_input ("sac", OP_REG_OUTPUT
, OP_ACCUM
, OP_VOID
);
2253 tmp
= SEXT40(ACC (OP
[1]));
2255 SET_PSW_F1 (PSW_F0
);
2257 if (tmp
> SEXT40(MAX32
))
2262 else if (tmp
< SEXT40(MIN32
))
2269 tmp
= (tmp
& MASK32
);
2273 SET_GPR32 (OP
[0], tmp
);
2275 trace_output_40 (tmp
);
2285 trace_input ("sachi", OP_REG_OUTPUT
, OP_ACCUM
, OP_VOID
);
2287 tmp
= SEXT40(ACC (OP
[1]));
2289 SET_PSW_F1 (PSW_F0
);
2291 if (tmp
> SEXT40(MAX32
))
2296 else if (tmp
< SEXT40(MIN32
))
2307 SET_GPR (OP
[0], tmp
);
2309 trace_output_16 (OP
[0]);
2319 trace_input ("sadd", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
2320 tmp
= SEXT40(ACC (OP
[0])) + (SEXT40(ACC (OP
[1])) >> 16);
2323 if (tmp
> SEXT40(MAX32
))
2325 else if (tmp
< SEXT40(MIN32
))
2328 tmp
= (tmp
& MASK40
);
2331 tmp
= (tmp
& MASK40
);
2332 SET_ACC (OP
[0], tmp
);
2333 trace_output_40 (tmp
);
2341 trace_input ("setf0f", OP_REG_OUTPUT
, OP_VOID
, OP_VOID
);
2342 tmp
= ((PSW_F0
== 0) ? 1 : 0);
2343 SET_GPR (OP
[0], tmp
);
2344 trace_output_16 (tmp
);
2352 trace_input ("setf0t", OP_REG_OUTPUT
, OP_VOID
, OP_VOID
);
2353 tmp
= ((PSW_F0
== 1) ? 1 : 0);
2354 SET_GPR (OP
[0], tmp
);
2355 trace_output_16 (tmp
);
2365 trace_input ("slae", OP_ACCUM
, OP_REG
, OP_VOID
);
2367 reg
= SEXT16( GPR (OP
[1]));
2369 if (reg
>= 17 || reg
<= -17)
2371 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: shift value %d too large.\n", reg
);
2372 State
.exception
= SIGILL
;
2376 tmp
= SEXT40 (ACC (OP
[0]));
2378 if (PSW_ST
&& (tmp
< SEXT40 (MIN32
) || tmp
> SEXT40 (MAX32
)))
2380 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: value to shift 0x%x out of range.\n", tmp
);
2381 State
.exception
= SIGILL
;
2385 if (reg
>= 0 && reg
<= 16)
2387 tmp
= SEXT56 ((SEXT56 (tmp
)) << (GPR (OP
[1])));
2390 if (tmp
> SEXT40(MAX32
))
2392 else if (tmp
< SEXT40(MIN32
))
2395 tmp
= (tmp
& MASK40
);
2398 tmp
= (tmp
& MASK40
);
2402 tmp
= (SEXT40 (ACC (OP
[0]))) >> (-GPR (OP
[1]));
2405 SET_ACC(OP
[0], tmp
);
2407 trace_output_40(tmp
);
2415 trace_input ("sleep", OP_VOID
, OP_VOID
, OP_VOID
);
2417 trace_output_void ();
2425 trace_input ("sll", OP_REG
, OP_REG
, OP_VOID
);
2426 tmp
= (GPR (OP
[0]) << (GPR (OP
[1]) & 0xf));
2427 SET_GPR (OP
[0], tmp
);
2428 trace_output_16 (tmp
);
2436 trace_input ("sll", OP_ACCUM
, OP_REG
, OP_VOID
);
2437 if ((GPR (OP
[1]) & 31) <= 16)
2438 tmp
= SEXT40 (ACC (OP
[0])) << (GPR (OP
[1]) & 31);
2441 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: shift value %d too large.\n", GPR (OP
[1]) & 31);
2442 State
.exception
= SIGILL
;
2448 if (tmp
> SEXT40(MAX32
))
2450 else if (tmp
< SEXT40(MIN32
))
2453 tmp
= (tmp
& MASK40
);
2456 tmp
= (tmp
& MASK40
);
2457 SET_ACC (OP
[0], tmp
);
2458 trace_output_40 (tmp
);
2466 trace_input ("slli", OP_REG
, OP_CONSTANT16
, OP_VOID
);
2467 tmp
= (GPR (OP
[0]) << OP
[1]);
2468 SET_GPR (OP
[0], tmp
);
2469 trace_output_16 (tmp
);
2481 trace_input ("slli", OP_ACCUM
, OP_CONSTANT16
, OP_VOID
);
2482 tmp
= SEXT40(ACC (OP
[0])) << OP
[1];
2486 if (tmp
> SEXT40(MAX32
))
2488 else if (tmp
< SEXT40(MIN32
))
2491 tmp
= (tmp
& MASK40
);
2494 tmp
= (tmp
& MASK40
);
2495 SET_ACC (OP
[0], tmp
);
2496 trace_output_40 (tmp
);
2504 trace_input ("slx", OP_REG
, OP_FLAG
, OP_VOID
);
2505 tmp
= ((GPR (OP
[0]) << 1) | PSW_F0
);
2506 SET_GPR (OP
[0], tmp
);
2507 trace_output_16 (tmp
);
2515 trace_input ("sra", OP_REG
, OP_REG
, OP_VOID
);
2516 tmp
= (((int16
)(GPR (OP
[0]))) >> (GPR (OP
[1]) & 0xf));
2517 SET_GPR (OP
[0], tmp
);
2518 trace_output_16 (tmp
);
2525 trace_input ("sra", OP_ACCUM
, OP_REG
, OP_VOID
);
2526 if ((GPR (OP
[1]) & 31) <= 16)
2528 int64 tmp
= ((SEXT40(ACC (OP
[0])) >> (GPR (OP
[1]) & 31)) & MASK40
);
2529 SET_ACC (OP
[0], tmp
);
2530 trace_output_40 (tmp
);
2534 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: shift value %d too large.\n", GPR (OP
[1]) & 31);
2535 State
.exception
= SIGILL
;
2545 trace_input ("srai", OP_REG
, OP_CONSTANT16
, OP_VOID
);
2546 tmp
= (((int16
)(GPR (OP
[0]))) >> OP
[1]);
2547 SET_GPR (OP
[0], tmp
);
2548 trace_output_16 (tmp
);
2559 trace_input ("srai", OP_ACCUM
, OP_CONSTANT16
, OP_VOID
);
2560 tmp
= ((SEXT40(ACC (OP
[0])) >> OP
[1]) & MASK40
);
2561 SET_ACC (OP
[0], tmp
);
2562 trace_output_40 (tmp
);
2570 trace_input ("srl", OP_REG
, OP_REG
, OP_VOID
);
2571 tmp
= (GPR (OP
[0]) >> (GPR (OP
[1]) & 0xf));
2572 SET_GPR (OP
[0], tmp
);
2573 trace_output_16 (tmp
);
2580 trace_input ("srl", OP_ACCUM
, OP_REG
, OP_VOID
);
2581 if ((GPR (OP
[1]) & 31) <= 16)
2583 int64 tmp
= ((uint64
)((ACC (OP
[0]) & MASK40
) >> (GPR (OP
[1]) & 31)));
2584 SET_ACC (OP
[0], tmp
);
2585 trace_output_40 (tmp
);
2589 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: shift value %d too large.\n", GPR (OP
[1]) & 31);
2590 State
.exception
= SIGILL
;
2601 trace_input ("srli", OP_REG
, OP_CONSTANT16
, OP_VOID
);
2602 tmp
= (GPR (OP
[0]) >> OP
[1]);
2603 SET_GPR (OP
[0], tmp
);
2604 trace_output_16 (tmp
);
2615 trace_input ("srli", OP_ACCUM
, OP_CONSTANT16
, OP_VOID
);
2616 tmp
= ((uint64
)(ACC (OP
[0]) & MASK40
) >> OP
[1]);
2617 SET_ACC (OP
[0], tmp
);
2618 trace_output_40 (tmp
);
2626 trace_input ("srx", OP_REG
, OP_FLAG
, OP_VOID
);
2628 tmp
= ((GPR (OP
[0]) >> 1) | tmp
);
2629 SET_GPR (OP
[0], tmp
);
2630 trace_output_16 (tmp
);
2637 trace_input ("st", OP_REG
, OP_MEMREF2
, OP_VOID
);
2638 SW (OP
[1] + GPR (OP
[2]), GPR (OP
[0]));
2639 trace_output_void ();
2646 trace_input ("st", OP_REG
, OP_MEMREF
, OP_VOID
);
2647 SW (GPR (OP
[1]), GPR (OP
[0]));
2648 trace_output_void ();
2655 uint16 addr
= GPR (OP
[1]) - 2;
2656 trace_input ("st", OP_REG
, OP_PREDEC
, OP_VOID
);
2659 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: cannot pre-decrement any registers but r15 (SP).\n");
2660 State
.exception
= SIGILL
;
2663 SW (addr
, GPR (OP
[0]));
2664 SET_GPR (OP
[1], addr
);
2665 trace_output_void ();
2672 trace_input ("st", OP_REG
, OP_POSTINC
, OP_VOID
);
2673 SW (GPR (OP
[1]), GPR (OP
[0]));
2674 INC_ADDR (OP
[1], 2);
2675 trace_output_void ();
2682 trace_input ("st", OP_REG
, OP_POSTDEC
, OP_VOID
);
2685 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: cannot post-decrement register r15 (SP).\n");
2686 State
.exception
= SIGILL
;
2689 SW (GPR (OP
[1]), GPR (OP
[0]));
2690 INC_ADDR (OP
[1], -2);
2691 trace_output_void ();
2698 trace_input ("st", OP_REG
, OP_MEMREF3
, OP_VOID
);
2699 SW (OP
[1], GPR (OP
[0]));
2700 trace_output_void ();
2707 trace_input ("st2w", OP_DREG
, OP_MEMREF2
, OP_VOID
);
2708 SW (GPR (OP
[2])+ OP
[1] + 0, GPR (OP
[0] + 0));
2709 SW (GPR (OP
[2])+ OP
[1] + 2, GPR (OP
[0] + 1));
2710 trace_output_void ();
2717 trace_input ("st2w", OP_DREG
, OP_MEMREF
, OP_VOID
);
2718 SW (GPR (OP
[1]) + 0, GPR (OP
[0] + 0));
2719 SW (GPR (OP
[1]) + 2, GPR (OP
[0] + 1));
2720 trace_output_void ();
2727 uint16 addr
= GPR (OP
[1]) - 4;
2728 trace_input ("st2w", OP_DREG
, OP_PREDEC
, OP_VOID
);
2731 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: cannot pre-decrement any registers but r15 (SP).\n");
2732 State
.exception
= SIGILL
;
2735 SW (addr
+ 0, GPR (OP
[0] + 0));
2736 SW (addr
+ 2, GPR (OP
[0] + 1));
2737 SET_GPR (OP
[1], addr
);
2738 trace_output_void ();
2745 trace_input ("st2w", OP_DREG
, OP_POSTINC
, OP_VOID
);
2746 SW (GPR (OP
[1]) + 0, GPR (OP
[0] + 0));
2747 SW (GPR (OP
[1]) + 2, GPR (OP
[0] + 1));
2748 INC_ADDR (OP
[1], 4);
2749 trace_output_void ();
2756 trace_input ("st2w", OP_DREG
, OP_POSTDEC
, OP_VOID
);
2759 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: cannot post-decrement register r15 (SP).\n");
2760 State
.exception
= SIGILL
;
2763 SW (GPR (OP
[1]) + 0, GPR (OP
[0] + 0));
2764 SW (GPR (OP
[1]) + 2, GPR (OP
[0] + 1));
2765 INC_ADDR (OP
[1], -4);
2766 trace_output_void ();
2773 trace_input ("st2w", OP_DREG
, OP_MEMREF3
, OP_VOID
);
2774 SW (OP
[1] + 0, GPR (OP
[0] + 0));
2775 SW (OP
[1] + 2, GPR (OP
[0] + 1));
2776 trace_output_void ();
2783 trace_input ("stb", OP_REG
, OP_MEMREF2
, OP_VOID
);
2784 SB (GPR (OP
[2]) + OP
[1], GPR (OP
[0]));
2785 trace_output_void ();
2792 trace_input ("stb", OP_REG
, OP_MEMREF
, OP_VOID
);
2793 SB (GPR (OP
[1]), GPR (OP
[0]));
2794 trace_output_void ();
2801 trace_input ("stop", OP_VOID
, OP_VOID
, OP_VOID
);
2802 State
.exception
= SIG_D10V_STOP
;
2803 trace_output_void ();
2810 uint16 a
= GPR (OP
[0]);
2811 uint16 b
= GPR (OP
[1]);
2812 uint16 tmp
= (a
- b
);
2813 trace_input ("sub", OP_REG
, OP_REG
, OP_VOID
);
2814 /* see ../common/sim-alu.h for a more extensive discussion on how to
2815 compute the carry/overflow bits. */
2817 SET_GPR (OP
[0], tmp
);
2818 trace_output_16 (tmp
);
2827 trace_input ("sub", OP_ACCUM
, OP_DREG
, OP_VOID
);
2828 tmp
= SEXT40(ACC (OP
[0])) - (SEXT16 (GPR (OP
[1])) << 16 | GPR (OP
[1] + 1));
2831 if (tmp
> SEXT40(MAX32
))
2833 else if (tmp
< SEXT40(MIN32
))
2836 tmp
= (tmp
& MASK40
);
2839 tmp
= (tmp
& MASK40
);
2840 SET_ACC (OP
[0], tmp
);
2842 trace_output_40 (tmp
);
2852 trace_input ("sub", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
2853 tmp
= SEXT40(ACC (OP
[0])) - SEXT40(ACC (OP
[1]));
2856 if (tmp
> SEXT40(MAX32
))
2858 else if (tmp
< SEXT40(MIN32
))
2861 tmp
= (tmp
& MASK40
);
2864 tmp
= (tmp
& MASK40
);
2865 SET_ACC (OP
[0], tmp
);
2867 trace_output_40 (tmp
);
2876 trace_input ("sub2w", OP_DREG
, OP_DREG
, OP_VOID
);
2877 a
= (uint32
)((GPR (OP
[0]) << 16) | GPR (OP
[0] + 1));
2878 b
= (uint32
)((GPR (OP
[1]) << 16) | GPR (OP
[1] + 1));
2879 /* see ../common/sim-alu.h for a more extensive discussion on how to
2880 compute the carry/overflow bits */
2883 SET_GPR32 (OP
[0], tmp
);
2884 trace_output_32 (tmp
);
2893 trace_input ("subac3", OP_DREG_OUTPUT
, OP_DREG
, OP_ACCUM
);
2894 tmp
= SEXT40 ((GPR (OP
[1]) << 16) | GPR (OP
[1] + 1)) - SEXT40 (ACC (OP
[2]));
2895 SET_GPR32 (OP
[0], tmp
);
2896 trace_output_32 (tmp
);
2905 trace_input ("subac3", OP_DREG_OUTPUT
, OP_ACCUM
, OP_ACCUM
);
2906 tmp
= SEXT40 (ACC (OP
[1])) - SEXT40(ACC (OP
[2]));
2907 SET_GPR32 (OP
[0], tmp
);
2908 trace_output_32 (tmp
);
2917 trace_input ("subac3s", OP_DREG_OUTPUT
, OP_DREG
, OP_ACCUM
);
2918 SET_PSW_F1 (PSW_F0
);
2919 tmp
= SEXT40 ((GPR (OP
[1]) << 16) | GPR (OP
[1] + 1)) - SEXT40(ACC (OP
[2]));
2920 if (tmp
> SEXT40(MAX32
))
2925 else if (tmp
< SEXT40(MIN32
))
2934 SET_GPR32 (OP
[0], tmp
);
2935 trace_output_32 (tmp
);
2944 trace_input ("subac3s", OP_DREG_OUTPUT
, OP_ACCUM
, OP_ACCUM
);
2945 SET_PSW_F1 (PSW_F0
);
2946 tmp
= SEXT40(ACC (OP
[1])) - SEXT40(ACC (OP
[2]));
2947 if (tmp
> SEXT40(MAX32
))
2952 else if (tmp
< SEXT40(MIN32
))
2961 SET_GPR32 (OP
[0], tmp
);
2962 trace_output_32 (tmp
);
2973 trace_input ("subi", OP_REG
, OP_CONSTANT16
, OP_VOID
);
2974 /* see ../common/sim-alu.h for a more extensive discussion on how to
2975 compute the carry/overflow bits. */
2976 /* since OP[1] is never <= 0, -OP[1] == ~OP[1]+1 can never overflow */
2977 tmp
= ((unsigned)(unsigned16
) GPR (OP
[0])
2978 + (unsigned)(unsigned16
) ( - OP
[1]));
2979 SET_PSW_C (tmp
>= (1 << 16));
2980 SET_GPR (OP
[0], tmp
);
2981 trace_output_16 (tmp
);
2988 trace_input ("trap", OP_CONSTANT4
, OP_VOID
, OP_VOID
);
2989 trace_output_void ();
2994 #if (DEBUG & DEBUG_TRAP) == 0
2996 uint16 vec
= OP
[0] + TRAP_VECTOR_START
;
2999 SET_PSW (PSW
& PSW_SM_BIT
);
3003 #else /* if debugging use trap to print registers */
3006 static int first_time
= 1;
3011 (*d10v_callback
->printf_filtered
) (d10v_callback
, "Trap # PC ");
3012 for (i
= 0; i
< 16; i
++)
3013 (*d10v_callback
->printf_filtered
) (d10v_callback
, " %sr%d", (i
> 9) ? "" : " ", i
);
3014 (*d10v_callback
->printf_filtered
) (d10v_callback
, " a0 a1 f0 f1 c\n");
3017 (*d10v_callback
->printf_filtered
) (d10v_callback
, "Trap %2d 0x%.4x:", (int)OP
[0], (int)PC
);
3019 for (i
= 0; i
< 16; i
++)
3020 (*d10v_callback
->printf_filtered
) (d10v_callback
, " %.4x", (int) GPR (i
));
3022 for (i
= 0; i
< 2; i
++)
3023 (*d10v_callback
->printf_filtered
) (d10v_callback
, " %.2x%.8lx",
3024 ((int)(ACC (i
) >> 32) & 0xff),
3025 ((unsigned long) ACC (i
)) & 0xffffffff);
3027 (*d10v_callback
->printf_filtered
) (d10v_callback
, " %d %d %d\n",
3028 PSW_F0
!= 0, PSW_F1
!= 0, PSW_C
!= 0);
3029 (*d10v_callback
->flush_stdout
) (d10v_callback
);
3033 case 15: /* new system call trap */
3034 /* Trap 15 is used for simulating low-level I/O */
3036 unsigned32 result
= 0;
3039 /* Registers passed to trap 0 */
3041 #define FUNC GPR (4) /* function number */
3042 #define PARM1 GPR (0) /* optional parm 1 */
3043 #define PARM2 GPR (1) /* optional parm 2 */
3044 #define PARM3 GPR (2) /* optional parm 3 */
3045 #define PARM4 GPR (3) /* optional parm 3 */
3047 /* Registers set by trap 0 */
3049 #define RETVAL(X) do { result = (X); SET_GPR (0, result); } while (0)
3050 #define RETVAL32(X) do { result = (X); SET_GPR (0, result >> 16); SET_GPR (1, result); } while (0)
3051 #define RETERR(X) SET_GPR (4, (X)) /* return error code */
3053 /* Turn a pointer in a register into a pointer into real memory. */
3055 #define MEMPTR(x) ((char *)(dmem_addr(x)))
3059 #if !defined(__GO32__) && !defined(_WIN32)
3060 case TARGET_SYS_fork
:
3061 trace_input ("<fork>", OP_VOID
, OP_VOID
, OP_VOID
);
3063 trace_output_16 (result
);
3067 case TARGET_SYS_getpid
:
3068 trace_input ("<getpid>", OP_VOID
, OP_VOID
, OP_VOID
);
3070 trace_output_16 (result
);
3073 case TARGET_SYS_kill
:
3074 trace_input ("<kill>", OP_R0
, OP_R1
, OP_VOID
);
3075 if (PARM1
== getpid ())
3077 trace_output_void ();
3078 State
.exception
= PARM2
;
3086 case 1: os_sig
= SIGHUP
; break;
3089 case 2: os_sig
= SIGINT
; break;
3092 case 3: os_sig
= SIGQUIT
; break;
3095 case 4: os_sig
= SIGILL
; break;
3098 case 5: os_sig
= SIGTRAP
; break;
3101 case 6: os_sig
= SIGABRT
; break;
3102 #elif defined(SIGIOT)
3103 case 6: os_sig
= SIGIOT
; break;
3106 case 7: os_sig
= SIGEMT
; break;
3109 case 8: os_sig
= SIGFPE
; break;
3112 case 9: os_sig
= SIGKILL
; break;
3115 case 10: os_sig
= SIGBUS
; break;
3118 case 11: os_sig
= SIGSEGV
; break;
3121 case 12: os_sig
= SIGSYS
; break;
3124 case 13: os_sig
= SIGPIPE
; break;
3127 case 14: os_sig
= SIGALRM
; break;
3130 case 15: os_sig
= SIGTERM
; break;
3133 case 16: os_sig
= SIGURG
; break;
3136 case 17: os_sig
= SIGSTOP
; break;
3139 case 18: os_sig
= SIGTSTP
; break;
3142 case 19: os_sig
= SIGCONT
; break;
3145 case 20: os_sig
= SIGCHLD
; break;
3146 #elif defined(SIGCLD)
3147 case 20: os_sig
= SIGCLD
; break;
3150 case 21: os_sig
= SIGTTIN
; break;
3153 case 22: os_sig
= SIGTTOU
; break;
3156 case 23: os_sig
= SIGIO
; break;
3157 #elif defined (SIGPOLL)
3158 case 23: os_sig
= SIGPOLL
; break;
3161 case 24: os_sig
= SIGXCPU
; break;
3164 case 25: os_sig
= SIGXFSZ
; break;
3167 case 26: os_sig
= SIGVTALRM
; break;
3170 case 27: os_sig
= SIGPROF
; break;
3173 case 28: os_sig
= SIGWINCH
; break;
3176 case 29: os_sig
= SIGLOST
; break;
3179 case 30: os_sig
= SIGUSR1
; break;
3182 case 31: os_sig
= SIGUSR2
; break;
3188 trace_output_void ();
3189 (*d10v_callback
->printf_filtered
) (d10v_callback
, "Unknown signal %d\n", PARM2
);
3190 (*d10v_callback
->flush_stdout
) (d10v_callback
);
3191 State
.exception
= SIGILL
;
3195 RETVAL (kill (PARM1
, PARM2
));
3196 trace_output_16 (result
);
3201 case TARGET_SYS_execve
:
3202 trace_input ("<execve>", OP_R0
, OP_R1
, OP_R2
);
3203 RETVAL (execve (MEMPTR (PARM1
), (char **) MEMPTR (PARM2
),
3204 (char **)MEMPTR (PARM3
)));
3205 trace_output_16 (result
);
3208 #ifdef TARGET_SYS_execv
3209 case TARGET_SYS_execv
:
3210 trace_input ("<execv>", OP_R0
, OP_R1
, OP_VOID
);
3211 RETVAL (execve (MEMPTR (PARM1
), (char **) MEMPTR (PARM2
), NULL
));
3212 trace_output_16 (result
);
3216 case TARGET_SYS_pipe
:
3221 trace_input ("<pipe>", OP_R0
, OP_VOID
, OP_VOID
);
3223 RETVAL (pipe (host_fd
));
3224 SW (buf
, host_fd
[0]);
3225 buf
+= sizeof(uint16
);
3226 SW (buf
, host_fd
[1]);
3227 trace_output_16 (result
);
3232 #ifdef TARGET_SYS_wait
3233 case TARGET_SYS_wait
:
3236 trace_input ("<wait>", OP_R0
, OP_VOID
, OP_VOID
);
3237 RETVAL (wait (&status
));
3240 trace_output_16 (result
);
3246 case TARGET_SYS_getpid
:
3247 trace_input ("<getpid>", OP_VOID
, OP_VOID
, OP_VOID
);
3249 trace_output_16 (result
);
3252 case TARGET_SYS_kill
:
3253 trace_input ("<kill>", OP_REG
, OP_REG
, OP_VOID
);
3254 trace_output_void ();
3255 State
.exception
= PARM2
;
3259 case TARGET_SYS_read
:
3260 trace_input ("<read>", OP_R0
, OP_R1
, OP_R2
);
3261 RETVAL (d10v_callback
->read (d10v_callback
, PARM1
, MEMPTR (PARM2
),
3263 trace_output_16 (result
);
3266 case TARGET_SYS_write
:
3267 trace_input ("<write>", OP_R0
, OP_R1
, OP_R2
);
3269 RETVAL ((int)d10v_callback
->write_stdout (d10v_callback
,
3270 MEMPTR (PARM2
), PARM3
));
3272 RETVAL ((int)d10v_callback
->write (d10v_callback
, PARM1
,
3273 MEMPTR (PARM2
), PARM3
));
3274 trace_output_16 (result
);
3277 case TARGET_SYS_lseek
:
3278 trace_input ("<lseek>", OP_R0
, OP_R1
, OP_R2
);
3279 RETVAL32 (d10v_callback
->lseek (d10v_callback
, PARM1
,
3280 ((((unsigned long) PARM2
) << 16)
3281 || (unsigned long) PARM3
),
3283 trace_output_32 (result
);
3286 case TARGET_SYS_close
:
3287 trace_input ("<close>", OP_R0
, OP_VOID
, OP_VOID
);
3288 RETVAL (d10v_callback
->close (d10v_callback
, PARM1
));
3289 trace_output_16 (result
);
3292 case TARGET_SYS_open
:
3293 trace_input ("<open>", OP_R0
, OP_R1
, OP_R2
);
3294 RETVAL (d10v_callback
->open (d10v_callback
, MEMPTR (PARM1
), PARM2
));
3295 trace_output_16 (result
);
3298 case TARGET_SYS_exit
:
3299 trace_input ("<exit>", OP_R0
, OP_VOID
, OP_VOID
);
3300 State
.exception
= SIG_D10V_EXIT
;
3301 trace_output_void ();
3304 #ifdef TARGET_SYS_stat
3305 case TARGET_SYS_stat
:
3306 trace_input ("<stat>", OP_R0
, OP_R1
, OP_VOID
);
3307 /* stat system call */
3309 struct stat host_stat
;
3312 RETVAL (stat (MEMPTR (PARM1
), &host_stat
));
3316 /* The hard-coded offsets and sizes were determined by using
3317 * the D10V compiler on a test program that used struct stat.
3319 SW (buf
, host_stat
.st_dev
);
3320 SW (buf
+2, host_stat
.st_ino
);
3321 SW (buf
+4, host_stat
.st_mode
);
3322 SW (buf
+6, host_stat
.st_nlink
);
3323 SW (buf
+8, host_stat
.st_uid
);
3324 SW (buf
+10, host_stat
.st_gid
);
3325 SW (buf
+12, host_stat
.st_rdev
);
3326 SLW (buf
+16, host_stat
.st_size
);
3327 SLW (buf
+20, host_stat
.st_atime
);
3328 SLW (buf
+28, host_stat
.st_mtime
);
3329 SLW (buf
+36, host_stat
.st_ctime
);
3331 trace_output_16 (result
);
3335 case TARGET_SYS_chown
:
3336 trace_input ("<chown>", OP_R0
, OP_R1
, OP_R2
);
3337 RETVAL (chown (MEMPTR (PARM1
), PARM2
, PARM3
));
3338 trace_output_16 (result
);
3341 case TARGET_SYS_chmod
:
3342 trace_input ("<chmod>", OP_R0
, OP_R1
, OP_R2
);
3343 RETVAL (chmod (MEMPTR (PARM1
), PARM2
));
3344 trace_output_16 (result
);
3348 #ifdef TARGET_SYS_utime
3349 case TARGET_SYS_utime
:
3350 trace_input ("<utime>", OP_R0
, OP_R1
, OP_R2
);
3351 /* Cast the second argument to void *, to avoid type mismatch
3352 if a prototype is present. */
3353 RETVAL (utime (MEMPTR (PARM1
), (void *) MEMPTR (PARM2
)));
3354 trace_output_16 (result
);
3360 #ifdef TARGET_SYS_time
3361 case TARGET_SYS_time
:
3362 trace_input ("<time>", OP_R0
, OP_R1
, OP_R2
);
3363 RETVAL32 (time (PARM1
? MEMPTR (PARM1
) : NULL
));
3364 trace_output_32 (result
);
3370 d10v_callback
->error (d10v_callback
, "Unknown syscall %d", FUNC
);
3372 if ((uint16
) result
== (uint16
) -1)
3373 RETERR (d10v_callback
->get_errno(d10v_callback
));
3385 trace_input ("tst0i", OP_REG
, OP_CONSTANT16
, OP_VOID
);
3386 SET_PSW_F1 (PSW_F0
);;
3387 SET_PSW_F0 ((GPR (OP
[0]) & OP
[1]) ? 1 : 0);
3388 trace_output_flag ();
3395 trace_input ("tst1i", OP_REG
, OP_CONSTANT16
, OP_VOID
);
3396 SET_PSW_F1 (PSW_F0
);
3397 SET_PSW_F0 ((~(GPR (OP
[0])) & OP
[1]) ? 1 : 0);
3398 trace_output_flag ();
3405 trace_input ("wait", OP_VOID
, OP_VOID
, OP_VOID
);
3407 trace_output_void ();
3415 trace_input ("xor", OP_REG
, OP_REG
, OP_VOID
);
3416 tmp
= (GPR (OP
[0]) ^ GPR (OP
[1]));
3417 SET_GPR (OP
[0], tmp
);
3418 trace_output_16 (tmp
);
3426 trace_input ("xor3", OP_REG_OUTPUT
, OP_REG
, OP_CONSTANT16
);
3427 tmp
= (GPR (OP
[1]) ^ OP
[2]);
3428 SET_GPR (OP
[0], tmp
);
3429 trace_output_16 (tmp
);