7f8cd0943aff7731ff41bdb0d97af664b3337ae4
9 #include "sys/syscall.h"
37 static void trace_input_func
PARAMS ((char *name
,
42 #define trace_input(name, in1, in2, in3) do { if (d10v_debug) trace_input_func (name, in1, in2, in3); } while (0)
44 static void trace_output_func
PARAMS ((enum op_types result
));
46 #define trace_output(result) do { if (d10v_debug) trace_output_func (result); } while (0)
48 static int init_text_p
= 0;
49 static asection
*text
;
50 static bfd_vma text_start
;
51 static bfd_vma text_end
;
54 #ifndef SIZE_INSTRUCTION
55 #define SIZE_INSTRUCTION 8
59 #define SIZE_OPERANDS 18
63 #define SIZE_VALUES 13
67 #define SIZE_LOCATION 20
71 trace_input_func (name
, in1
, in2
, in3
)
86 const char *functionname
;
87 unsigned int linenumber
;
90 if ((d10v_debug
& DEBUG_TRACE
) == 0)
93 switch (State
.ins_type
)
96 case INS_UNKNOWN
: type
= " ?"; break;
97 case INS_LEFT
: type
= " L"; break;
98 case INS_RIGHT
: type
= " R"; break;
99 case INS_LEFT_PARALLEL
: type
= "*L"; break;
100 case INS_RIGHT_PARALLEL
: type
= "*R"; break;
101 case INS_LONG
: type
= " B"; break;
104 if ((d10v_debug
& DEBUG_LINE_NUMBER
) == 0)
105 (*d10v_callback
->printf_filtered
) (d10v_callback
,
108 SIZE_INSTRUCTION
, name
);
116 for (s
= sim_bfd
->sections
; s
; s
= s
->next
)
117 if (strcmp (bfd_get_section_name (sim_bfd
, s
), ".text") == 0)
120 text_start
= bfd_get_section_vma (sim_bfd
, s
);
121 text_end
= text_start
+ bfd_section_size (sim_bfd
, s
);
126 byte_pc
= (bfd_vma
)PC
<< 2;
127 if (text
&& byte_pc
>= text_start
&& byte_pc
< text_end
)
129 filename
= (const char *)0;
130 functionname
= (const char *)0;
132 if (bfd_find_nearest_line (sim_bfd
, text
, (struct symbol_cache_entry
**)0, byte_pc
- text_start
,
133 &filename
, &functionname
, &linenumber
))
138 sprintf (p
, "#%-4d ", linenumber
);
144 sprintf (p
, "%s ", functionname
);
149 char *q
= (char *) strrchr (filename
, '/');
150 sprintf (p
, "%s ", (q
) ? q
+1 : filename
);
159 (*d10v_callback
->printf_filtered
) (d10v_callback
,
160 "0x%.6x %s: %-*.*s %-*s",
162 SIZE_LOCATION
, SIZE_LOCATION
, buf
,
163 SIZE_INSTRUCTION
, name
);
171 for (i
= 0; i
< 3; i
++)
182 sprintf (p
, "%sr%d", comma
, OP
[i
]);
190 sprintf (p
, "%scr%d", comma
, OP
[i
]);
196 case OP_ACCUM_OUTPUT
:
197 case OP_ACCUM_REVERSE
:
198 sprintf (p
, "%sa%d", comma
, OP
[i
]);
204 sprintf (p
, "%s%d", comma
, OP
[i
]);
210 sprintf (p
, "%s%d", comma
, SEXT4(OP
[i
]));
216 sprintf (p
, "%s%d", comma
, SEXT3(OP
[i
]));
222 sprintf (p
, "%s@r%d", comma
, OP
[i
]);
228 sprintf (p
, "%s@(%d,r%d)", comma
, (int16
)OP
[i
], OP
[i
+1]);
234 sprintf (p
, "%s@r%d+", comma
, OP
[i
]);
240 sprintf (p
, "%s@r%d-", comma
, OP
[i
]);
246 sprintf (p
, "%s@-r%d", comma
, OP
[i
]);
254 sprintf (p
, "%sf0", comma
);
257 sprintf (p
, "%sf1", comma
);
260 sprintf (p
, "%sc", comma
);
268 if ((d10v_debug
& DEBUG_VALUES
) == 0)
272 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%s", buf
);
277 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%-*s", SIZE_OPERANDS
, buf
);
280 for (i
= 0; i
< 3; i
++)
286 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s", SIZE_VALUES
, "");
292 case OP_ACCUM_OUTPUT
:
294 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s", SIZE_VALUES
, "---");
302 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "",
303 (uint16
)State
.regs
[OP
[i
]]);
307 tmp
= (long)((((uint32
) State
.regs
[OP
[i
]]) << 16) | ((uint32
) State
.regs
[OP
[i
]+1]));
308 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.8lx", SIZE_VALUES
-10, "", tmp
);
313 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "",
314 (uint16
)State
.cregs
[OP
[i
]]);
318 case OP_ACCUM_REVERSE
:
319 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.2x%.8lx", SIZE_VALUES
-12, "",
320 ((int)(State
.a
[OP
[i
]] >> 32) & 0xff),
321 ((unsigned long)State
.a
[OP
[i
]]) & 0xffffffff);
325 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "",
330 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "",
331 (uint16
)SEXT4(OP
[i
]));
335 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "",
336 (uint16
)SEXT3(OP
[i
]));
341 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*sF0 = %d", SIZE_VALUES
-6, "",
345 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*sF1 = %d", SIZE_VALUES
-6, "",
349 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*sC = %d", SIZE_VALUES
-5, "",
355 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "",
357 (*d10v_callback
->printf_filtered
) (d10v_callback
, "%*s0x%.4x", SIZE_VALUES
-6, "",
358 (uint16
)State
.regs
[OP
[++i
]]);
366 trace_output_func (result
)
367 enum op_types result
;
369 if ((d10v_debug
& (DEBUG_TRACE
| DEBUG_VALUES
)) == (DEBUG_TRACE
| DEBUG_VALUES
))
381 (*d10v_callback
->printf_filtered
) (d10v_callback
, " :: %*s0x%.4x F0=%d F1=%d C=%d\n", SIZE_VALUES
-6, "",
382 (uint16
)State
.regs
[OP
[0]],
383 State
.F0
!= 0, State
.F1
!= 0, State
.C
!= 0);
388 tmp
= (long)((((uint32
) State
.regs
[OP
[0]]) << 16) | ((uint32
) State
.regs
[OP
[0]+1]));
389 (*d10v_callback
->printf_filtered
) (d10v_callback
, " :: %*s0x%.8lx F0=%d F1=%d C=%d\n", SIZE_VALUES
-10, "", tmp
,
390 State
.F0
!= 0, State
.F1
!= 0, State
.C
!= 0);
395 (*d10v_callback
->printf_filtered
) (d10v_callback
, " :: %*s0x%.4x F0=%d F1=%d C=%d\n", SIZE_VALUES
-6, "",
396 (uint16
)State
.cregs
[OP
[0]],
397 State
.F0
!= 0, State
.F1
!= 0, State
.C
!= 0);
401 (*d10v_callback
->printf_filtered
) (d10v_callback
, " :: %*s0x%.4x F0=%d F1=%d C=%d\n", SIZE_VALUES
-6, "",
402 (uint16
)State
.cregs
[OP
[1]],
403 State
.F0
!= 0, State
.F1
!= 0, State
.C
!= 0);
407 case OP_ACCUM_OUTPUT
:
408 (*d10v_callback
->printf_filtered
) (d10v_callback
, " :: %*s0x%.2x%.8lx F0=%d F1=%d C=%d\n", SIZE_VALUES
-12, "",
409 ((int)(State
.a
[OP
[0]] >> 32) & 0xff),
410 ((unsigned long)State
.a
[OP
[0]]) & 0xffffffff,
411 State
.F0
!= 0, State
.F1
!= 0, State
.C
!= 0);
414 case OP_ACCUM_REVERSE
:
415 (*d10v_callback
->printf_filtered
) (d10v_callback
, " :: %*s0x%.2x%.8lx F0=%d F1=%d C=%d\n", SIZE_VALUES
-12, "",
416 ((int)(State
.a
[OP
[1]] >> 32) & 0xff),
417 ((unsigned long)State
.a
[OP
[1]]) & 0xffffffff,
418 State
.F0
!= 0, State
.F1
!= 0, State
.C
!= 0);
423 (*d10v_callback
->printf_filtered
) (d10v_callback
, " :: %*s F0=%d F1=%d C=%d\n", SIZE_VALUES
, "",
424 State
.F0
!= 0, State
.F1
!= 0, State
.C
!= 0);
431 #define trace_input(NAME, IN1, IN2, IN3)
432 #define trace_output(RESULT)
439 trace_input ("abs", OP_REG
, OP_VOID
, OP_VOID
);
441 if ((int16
)(State
.regs
[OP
[0]]) < 0)
443 State
.regs
[OP
[0]] = -(int16
)(State
.regs
[OP
[0]]);
448 trace_output (OP_REG
);
457 trace_input ("abs", OP_ACCUM
, OP_VOID
, OP_VOID
);
459 State
.a
[OP
[0]] = SEXT40(State
.a
[OP
[0]]);
461 if (State
.a
[OP
[0]] < 0 )
463 tmp
= -State
.a
[OP
[0]];
467 State
.a
[OP
[0]] = MAX32
;
468 else if (tmp
< MIN32
)
469 State
.a
[OP
[0]] = MIN32
;
471 State
.a
[OP
[0]] = tmp
& MASK40
;
474 State
.a
[OP
[0]] = tmp
& MASK40
;
479 trace_output (OP_ACCUM
);
486 uint16 tmp
= State
.regs
[OP
[0]];
487 trace_input ("add", OP_REG
, OP_REG
, OP_VOID
);
488 State
.regs
[OP
[0]] += State
.regs
[OP
[1]];
489 if ( tmp
> State
.regs
[OP
[0]])
493 trace_output (OP_REG
);
501 tmp
= SEXT40(State
.a
[OP
[0]]) + (SEXT16 (State
.regs
[OP
[1]]) << 16 | State
.regs
[OP
[1]+1]);
503 trace_input ("add", OP_ACCUM
, OP_REG
, OP_VOID
);
507 State
.a
[OP
[0]] = MAX32
;
508 else if ( tmp
< MIN32
)
509 State
.a
[OP
[0]] = MIN32
;
511 State
.a
[OP
[0]] = tmp
& MASK40
;
514 State
.a
[OP
[0]] = tmp
& MASK40
;
515 trace_output (OP_ACCUM
);
523 tmp
= SEXT40(State
.a
[OP
[0]]) + SEXT40(State
.a
[OP
[1]]);
525 trace_input ("add", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
529 State
.a
[OP
[0]] = MAX32
;
530 else if ( tmp
< MIN32
)
531 State
.a
[OP
[0]] = MIN32
;
533 State
.a
[OP
[0]] = tmp
& MASK40
;
536 State
.a
[OP
[0]] = tmp
& MASK40
;
537 trace_output (OP_ACCUM
);
545 uint32 tmp1
= (State
.regs
[OP
[0]]) << 16 | State
.regs
[OP
[0]+1];
546 uint32 tmp2
= (State
.regs
[OP
[1]]) << 16 | State
.regs
[OP
[1]+1];
548 trace_input ("add2w", OP_DREG
, OP_DREG
, OP_VOID
);
550 if ( (tmp
< tmp1
) || (tmp
< tmp2
) )
554 State
.regs
[OP
[0]] = tmp
>> 16;
555 State
.regs
[OP
[0]+1] = tmp
& 0xFFFF;
556 trace_output (OP_DREG
);
563 uint16 tmp
= State
.regs
[OP
[0]];
564 State
.regs
[OP
[0]] = State
.regs
[OP
[1]] + OP
[2];
566 trace_input ("add3", OP_REG_OUTPUT
, OP_REG
, OP_CONSTANT16
);
567 if ( tmp
> State
.regs
[OP
[0]])
571 trace_output (OP_REG
);
579 tmp
= SEXT40(State
.a
[OP
[2]]) + SEXT40 ((State
.regs
[OP
[1]] << 16) | State
.regs
[OP
[1]+1]);
581 trace_input ("addac3", OP_DREG_OUTPUT
, OP_DREG
, OP_ACCUM
);
582 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
583 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
584 trace_output (OP_DREG
);
592 tmp
= SEXT40(State
.a
[OP
[1]]) + SEXT40(State
.a
[OP
[2]]);
594 trace_input ("addac3", OP_DREG_OUTPUT
, OP_ACCUM
, OP_ACCUM
);
595 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
596 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
597 trace_output (OP_DREG
);
607 trace_input ("addac3s", OP_DREG_OUTPUT
, OP_DREG
, OP_ACCUM
);
608 tmp
= SEXT40(State
.a
[OP
[2]]) + SEXT40 ((State
.regs
[OP
[1]] << 16) | State
.regs
[OP
[1]+1]);
611 State
.regs
[OP
[0]] = 0x7fff;
612 State
.regs
[OP
[0]+1] = 0xffff;
615 else if (tmp
< MIN32
)
617 State
.regs
[OP
[0]] = 0x8000;
618 State
.regs
[OP
[0]+1] = 0;
623 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
624 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
627 trace_output (OP_DREG
);
637 trace_input ("addac3s", OP_DREG_OUTPUT
, OP_ACCUM
, OP_ACCUM
);
638 tmp
= SEXT40(State
.a
[OP
[1]]) + SEXT40(State
.a
[OP
[2]]);
641 State
.regs
[OP
[0]] = 0x7fff;
642 State
.regs
[OP
[0]+1] = 0xffff;
645 else if (tmp
< MIN32
)
647 State
.regs
[OP
[0]] = 0x8000;
648 State
.regs
[OP
[0]+1] = 0;
653 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
654 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
657 trace_output (OP_DREG
);
664 uint tmp
= State
.regs
[OP
[0]];
667 trace_input ("addi", OP_REG
, OP_CONSTANT16
, OP_VOID
);
668 State
.regs
[OP
[0]] += OP
[1];
669 if (tmp
> State
.regs
[OP
[0]])
673 trace_output (OP_REG
);
680 trace_input ("and", OP_REG
, OP_REG
, OP_VOID
);
681 State
.regs
[OP
[0]] &= State
.regs
[OP
[1]];
682 trace_output (OP_REG
);
689 trace_input ("and3", OP_REG_OUTPUT
, OP_REG
, OP_CONSTANT16
);
690 State
.regs
[OP
[0]] = State
.regs
[OP
[1]] & OP
[2];
691 trace_output (OP_REG
);
698 trace_input ("bclri", OP_REG
, OP_CONSTANT16
, OP_VOID
);
699 State
.regs
[OP
[0]] &= ~(0x8000 >> OP
[1]);
700 trace_output (OP_REG
);
707 trace_input ("bl.s", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
708 State
.regs
[13] = PC
+1;
710 trace_output (OP_VOID
);
717 trace_input ("bl.l", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
718 State
.regs
[13] = PC
+1;
720 trace_output (OP_VOID
);
727 trace_input ("bnoti", OP_REG
, OP_CONSTANT16
, OP_VOID
);
728 State
.regs
[OP
[0]] ^= 0x8000 >> OP
[1];
729 trace_output (OP_REG
);
736 trace_input ("bra.s", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
738 trace_output (OP_VOID
);
745 trace_input ("bra.l", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
747 trace_output (OP_VOID
);
754 trace_input ("brf0f.s", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
757 trace_output (OP_FLAG
);
764 trace_input ("brf0f.l", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
767 trace_output (OP_FLAG
);
774 trace_input ("brf0t.s", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
777 trace_output (OP_FLAG
);
784 trace_input ("brf0t.l", OP_CONSTANT16
, OP_VOID
, OP_VOID
);
787 trace_output (OP_FLAG
);
794 trace_input ("bseti", OP_REG
, OP_CONSTANT16
, OP_VOID
);
795 State
.regs
[OP
[0]] |= 0x8000 >> OP
[1];
796 trace_output (OP_REG
);
803 trace_input ("btsti", OP_REG
, OP_CONSTANT16
, OP_VOID
);
805 State
.F0
= (State
.regs
[OP
[0]] & (0x8000 >> OP
[1])) ? 1 : 0;
806 trace_output (OP_FLAG
);
813 trace_input ("clrac", OP_ACCUM_OUTPUT
, OP_VOID
, OP_VOID
);
815 trace_output (OP_ACCUM
);
822 trace_input ("cmp", OP_REG
, OP_REG
, OP_VOID
);
824 State
.F0
= ((int16
)(State
.regs
[OP
[0]]) < (int16
)(State
.regs
[OP
[1]])) ? 1 : 0;
825 trace_output (OP_FLAG
);
832 trace_input ("cmp", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
834 State
.F0
= (SEXT40(State
.a
[OP
[0]]) < SEXT40(State
.a
[OP
[1]])) ? 1 : 0;
835 trace_output (OP_FLAG
);
842 trace_input ("cmpeq", OP_REG
, OP_REG
, OP_VOID
);
844 State
.F0
= (State
.regs
[OP
[0]] == State
.regs
[OP
[1]]) ? 1 : 0;
845 trace_output (OP_FLAG
);
852 trace_input ("cmpeq", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
854 State
.F0
= (State
.a
[OP
[0]] == State
.a
[OP
[1]]) ? 1 : 0;
855 trace_output (OP_FLAG
);
862 trace_input ("cmpeqi.s", OP_REG
, OP_CONSTANT16
, OP_VOID
);
864 State
.F0
= (State
.regs
[OP
[0]] == SEXT4(OP
[1])) ? 1 : 0;
865 trace_output (OP_FLAG
);
872 trace_input ("cmpeqi.l", OP_REG
, OP_CONSTANT16
, OP_VOID
);
874 State
.F0
= (State
.regs
[OP
[0]] == OP
[1]) ? 1 : 0;
875 trace_output (OP_FLAG
);
882 trace_input ("cmpi.s", OP_REG
, OP_CONSTANT4
, OP_VOID
);
884 State
.F0
= ((int16
)(State
.regs
[OP
[0]]) < SEXT4(OP
[1])) ? 1 : 0;
885 trace_output (OP_FLAG
);
892 trace_input ("cmpi.l", OP_REG
, OP_CONSTANT16
, OP_VOID
);
894 State
.F0
= ((int16
)(State
.regs
[OP
[0]]) < (int16
)(OP
[1])) ? 1 : 0;
895 trace_output (OP_FLAG
);
902 trace_input ("cmpu", OP_REG
, OP_REG
, OP_VOID
);
904 State
.F0
= (State
.regs
[OP
[0]] < State
.regs
[OP
[1]]) ? 1 : 0;
905 trace_output (OP_FLAG
);
912 trace_input ("cmpui", OP_REG
, OP_CONSTANT16
, OP_VOID
);
914 State
.F0
= (State
.regs
[OP
[0]] < OP
[1]) ? 1 : 0;
915 trace_output (OP_FLAG
);
924 trace_input ("cpfg", OP_FLAG_OUTPUT
, OP_FLAG
, OP_VOID
);
938 trace_output (OP_FLAG
);
945 /* d10v_callback->printf_filtered(d10v_callback, "***** DBT ***** PC=%x\n",PC); */
946 State
.exception
= SIGTRAP
;
953 uint16 foo
, tmp
, tmpf
;
955 trace_input ("divs", OP_DREG
, OP_REG
, OP_VOID
);
956 foo
= (State
.regs
[OP
[0]] << 1) | (State
.regs
[OP
[0]+1] >> 15);
957 tmp
= (int16
)foo
- (int16
)(State
.regs
[OP
[1]]);
958 tmpf
= (foo
>= State
.regs
[OP
[1]]) ? 1 : 0;
959 State
.regs
[OP
[0]] = (tmpf
== 1) ? tmp
: foo
;
960 State
.regs
[OP
[0]+1] = (State
.regs
[OP
[0]+1] << 1) | tmpf
;
961 trace_output (OP_DREG
);
968 trace_input ("exef0f", OP_VOID
, OP_VOID
, OP_VOID
);
969 State
.exe
= (State
.F0
== 0);
970 trace_output (OP_FLAG
);
977 trace_input ("exef0t", OP_VOID
, OP_VOID
, OP_VOID
);
978 State
.exe
= (State
.F0
!= 0);
979 trace_output (OP_FLAG
);
986 trace_input ("exef1f", OP_VOID
, OP_VOID
, OP_VOID
);
987 State
.exe
= (State
.F1
== 0);
988 trace_output (OP_FLAG
);
995 trace_input ("exef1t", OP_VOID
, OP_VOID
, OP_VOID
);
996 State
.exe
= (State
.F1
!= 0);
997 trace_output (OP_FLAG
);
1004 trace_input ("exefaf", OP_VOID
, OP_VOID
, OP_VOID
);
1005 State
.exe
= (State
.F0
== 0) & (State
.F1
== 0);
1006 trace_output (OP_FLAG
);
1013 trace_input ("exefat", OP_VOID
, OP_VOID
, OP_VOID
);
1014 State
.exe
= (State
.F0
== 0) & (State
.F1
!= 0);
1015 trace_output (OP_FLAG
);
1022 trace_input ("exetaf", OP_VOID
, OP_VOID
, OP_VOID
);
1023 State
.exe
= (State
.F0
!= 0) & (State
.F1
== 0);
1024 trace_output (OP_FLAG
);
1031 trace_input ("exetat", OP_VOID
, OP_VOID
, OP_VOID
);
1032 State
.exe
= (State
.F0
!= 0) & (State
.F1
!= 0);
1033 trace_output (OP_FLAG
);
1043 trace_input ("exp", OP_REG_OUTPUT
, OP_DREG
, OP_VOID
);
1044 if (((int16
)State
.regs
[OP
[1]]) >= 0)
1045 tmp
= (State
.regs
[OP
[1]] << 16) | State
.regs
[OP
[1]+1];
1047 tmp
= ~((State
.regs
[OP
[1]] << 16) | State
.regs
[OP
[1]+1]);
1054 State
.regs
[OP
[0]] = i
-1;
1055 trace_output (OP_REG
);
1060 State
.regs
[OP
[0]] = 16;
1061 trace_output (OP_REG
);
1071 trace_input ("exp", OP_REG_OUTPUT
, OP_ACCUM
, OP_VOID
);
1072 if (SEXT40(State
.a
[OP
[1]]) >= 0)
1073 tmp
= State
.a
[OP
[1]];
1075 tmp
= ~(State
.a
[OP
[1]]);
1077 foo
= 0x4000000000LL
;
1082 State
.regs
[OP
[0]] = i
-9;
1083 trace_output (OP_REG
);
1088 State
.regs
[OP
[0]] = 16;
1089 trace_output (OP_REG
);
1096 trace_input ("jl", OP_REG
, OP_VOID
, OP_VOID
);
1097 State
.regs
[13] = PC
+1;
1098 PC
= State
.regs
[OP
[0]];
1099 trace_output (OP_VOID
);
1106 trace_input ("jmp", OP_REG
, OP_VOID
, OP_VOID
);
1107 PC
= State
.regs
[OP
[0]];
1108 trace_output (OP_VOID
);
1115 trace_input ("ld", OP_REG_OUTPUT
, OP_MEMREF2
, OP_VOID
);
1116 State
.regs
[OP
[0]] = RW (OP
[1] + State
.regs
[OP
[2]]);
1117 trace_output (OP_REG
);
1124 trace_input ("ld", OP_REG_OUTPUT
, OP_POSTDEC
, OP_VOID
);
1125 State
.regs
[OP
[0]] = RW (State
.regs
[OP
[1]]);
1126 INC_ADDR(State
.regs
[OP
[1]],-2);
1127 trace_output (OP_REG
);
1134 trace_input ("ld", OP_REG_OUTPUT
, OP_POSTINC
, OP_VOID
);
1135 State
.regs
[OP
[0]] = RW (State
.regs
[OP
[1]]);
1136 INC_ADDR(State
.regs
[OP
[1]],2);
1137 trace_output (OP_REG
);
1144 trace_input ("ld", OP_REG_OUTPUT
, OP_MEMREF
, OP_VOID
);
1145 State
.regs
[OP
[0]] = RW (State
.regs
[OP
[1]]);
1146 trace_output (OP_REG
);
1153 trace_input ("ld2w", OP_REG_OUTPUT
, OP_MEMREF2
, OP_VOID
);
1154 State
.regs
[OP
[0]] = RW (OP
[1] + State
.regs
[OP
[2]]);
1155 State
.regs
[OP
[0]+1] = RW (OP
[1] + State
.regs
[OP
[2]] + 2);
1156 trace_output (OP_DREG
);
1163 trace_input ("ld2w", OP_REG_OUTPUT
, OP_POSTDEC
, OP_VOID
);
1164 State
.regs
[OP
[0]] = RW (State
.regs
[OP
[1]]);
1165 State
.regs
[OP
[0]+1] = RW (State
.regs
[OP
[1]]+2);
1166 INC_ADDR(State
.regs
[OP
[1]],-4);
1167 trace_output (OP_DREG
);
1174 trace_input ("ld2w", OP_REG_OUTPUT
, OP_POSTINC
, OP_VOID
);
1175 State
.regs
[OP
[0]] = RW (State
.regs
[OP
[1]]);
1176 State
.regs
[OP
[0]+1] = RW (State
.regs
[OP
[1]]+2);
1177 INC_ADDR(State
.regs
[OP
[1]],4);
1178 trace_output (OP_REG
);
1185 trace_input ("ld", OP_REG_OUTPUT
, OP_MEMREF
, OP_VOID
);
1186 State
.regs
[OP
[0]] = RW (State
.regs
[OP
[1]]);
1187 State
.regs
[OP
[0]+1] = RW (State
.regs
[OP
[1]]+2);
1188 trace_output (OP_REG
);
1195 trace_input ("ldb", OP_REG_OUTPUT
, OP_MEMREF2
, OP_VOID
);
1196 State
.regs
[OP
[0]] = RB (OP
[1] + State
.regs
[OP
[2]]);
1197 SEXT8 (State
.regs
[OP
[0]]);
1198 trace_output (OP_REG
);
1205 trace_input ("ldb", OP_REG_OUTPUT
, OP_MEMREF
, OP_VOID
);
1206 State
.regs
[OP
[0]] = RB (State
.regs
[OP
[1]]);
1207 SEXT8 (State
.regs
[OP
[0]]);
1208 trace_output (OP_REG
);
1215 trace_input ("ldi.s", OP_REG_OUTPUT
, OP_CONSTANT4
, OP_VOID
);
1216 State
.regs
[OP
[0]] = SEXT4(OP
[1]);
1217 trace_output (OP_REG
);
1224 trace_input ("ldi.s", OP_REG_OUTPUT
, OP_CONSTANT16
, OP_VOID
);
1225 State
.regs
[OP
[0]] = OP
[1];
1226 trace_output (OP_REG
);
1233 trace_input ("ldub", OP_REG_OUTPUT
, OP_MEMREF2
, OP_VOID
);
1234 State
.regs
[OP
[0]] = RB (OP
[1] + State
.regs
[OP
[2]]);
1235 trace_output (OP_REG
);
1242 trace_input ("ldub", OP_REG_OUTPUT
, OP_MEMREF
, OP_VOID
);
1243 State
.regs
[OP
[0]] = RB (State
.regs
[OP
[1]]);
1244 trace_output (OP_REG
);
1253 trace_input ("mac", OP_ACCUM
, OP_REG
, OP_REG
);
1254 tmp
= SEXT40 ((int16
)(State
.regs
[OP
[1]]) * (int16
)(State
.regs
[OP
[2]]));
1257 tmp
= SEXT40( (tmp
<< 1) & MASK40
);
1259 if (State
.ST
&& tmp
> MAX32
)
1262 tmp
+= SEXT40(State
.a
[OP
[0]]);
1266 State
.a
[OP
[0]] = MAX32
;
1267 else if (tmp
< MIN32
)
1268 State
.a
[OP
[0]] = MIN32
;
1270 State
.a
[OP
[0]] = tmp
& MASK40
;
1273 State
.a
[OP
[0]] = tmp
& MASK40
;
1274 trace_output (OP_ACCUM
);
1283 trace_input ("macsu", OP_ACCUM
, OP_REG
, OP_REG
);
1284 tmp
= SEXT40 ((int16
)State
.regs
[OP
[1]] * State
.regs
[OP
[2]]);
1286 tmp
= SEXT40( (tmp
<< 1) & MASK40
);
1288 State
.a
[OP
[0]] = (SEXT40 (State
.a
[OP
[0]]) + tmp
) & MASK40
;
1289 trace_output (OP_ACCUM
);
1298 trace_input ("macu", OP_ACCUM
, OP_REG
, OP_REG
);
1299 tmp
= SEXT40 (State
.regs
[OP
[1]] * State
.regs
[OP
[2]]);
1301 tmp
= SEXT40( (tmp
<< 1) & MASK40
);
1302 State
.a
[OP
[0]] = (SEXT40 (State
.a
[OP
[0]]) + tmp
) & MASK40
;
1303 trace_output (OP_ACCUM
);
1310 trace_input ("max", OP_REG
, OP_REG
, OP_VOID
);
1311 State
.F1
= State
.F0
;
1312 if ((int16
)State
.regs
[OP
[1]] > (int16
)State
.regs
[OP
[0]])
1314 State
.regs
[OP
[0]] = State
.regs
[OP
[1]];
1319 trace_output (OP_REG
);
1328 trace_input ("max", OP_ACCUM
, OP_DREG
, OP_VOID
);
1329 State
.F1
= State
.F0
;
1330 tmp
= SEXT16 (State
.regs
[OP
[1]]) << 16 | State
.regs
[OP
[1]+1];
1331 if (tmp
> SEXT40(State
.a
[OP
[0]]))
1333 State
.a
[OP
[0]] = tmp
& MASK40
;
1338 trace_output (OP_ACCUM
);
1345 trace_input ("max", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
1346 State
.F1
= State
.F0
;
1347 if (SEXT40(State
.a
[OP
[1]]) > SEXT40(State
.a
[OP
[0]]))
1349 State
.a
[OP
[0]] = State
.a
[OP
[1]];
1354 trace_output (OP_ACCUM
);
1362 trace_input ("min", OP_REG
, OP_REG
, OP_VOID
);
1363 State
.F1
= State
.F0
;
1364 if ((int16
)State
.regs
[OP
[1]] < (int16
)State
.regs
[OP
[0]])
1366 State
.regs
[OP
[0]] = State
.regs
[OP
[1]];
1371 trace_output (OP_REG
);
1380 trace_input ("min", OP_ACCUM
, OP_DREG
, OP_VOID
);
1381 State
.F1
= State
.F0
;
1382 tmp
= SEXT16 (State
.regs
[OP
[1]]) << 16 | State
.regs
[OP
[1]+1];
1383 if (tmp
< SEXT40(State
.a
[OP
[0]]))
1385 State
.a
[OP
[0]] = tmp
& MASK40
;
1390 trace_output (OP_ACCUM
);
1397 trace_input ("min", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
1398 State
.F1
= State
.F0
;
1399 if (SEXT40(State
.a
[OP
[1]]) < SEXT40(State
.a
[OP
[0]]))
1401 State
.a
[OP
[0]] = State
.a
[OP
[1]];
1406 trace_output (OP_ACCUM
);
1415 trace_input ("msb", OP_ACCUM
, OP_REG
, OP_REG
);
1416 tmp
= SEXT40 ((int16
)(State
.regs
[OP
[1]]) * (int16
)(State
.regs
[OP
[2]]));
1419 tmp
= SEXT40 ((tmp
<< 1) & MASK40
);
1421 if (State
.ST
&& tmp
> MAX32
)
1424 tmp
= SEXT40(State
.a
[OP
[0]]) - tmp
;
1428 State
.a
[OP
[0]] = MAX32
;
1429 else if (tmp
< MIN32
)
1430 State
.a
[OP
[0]] = MIN32
;
1432 State
.a
[OP
[0]] = tmp
& MASK40
;
1435 State
.a
[OP
[0]] = tmp
& MASK40
;
1436 trace_output (OP_ACCUM
);
1445 trace_input ("msbsu", OP_ACCUM
, OP_REG
, OP_REG
);
1446 tmp
= SEXT40 ((int16
)State
.regs
[OP
[1]] * State
.regs
[OP
[2]]);
1448 tmp
= SEXT40( (tmp
<< 1) & MASK40
);
1450 State
.a
[OP
[0]] = (SEXT40 (State
.a
[OP
[0]]) - tmp
) & MASK40
;
1451 trace_output (OP_ACCUM
);
1460 trace_input ("msbu", OP_ACCUM
, OP_REG
, OP_REG
);
1461 tmp
= SEXT40 (State
.regs
[OP
[1]] * State
.regs
[OP
[2]]);
1463 tmp
= SEXT40( (tmp
<< 1) & MASK40
);
1465 State
.a
[OP
[0]] = (SEXT40 (State
.a
[OP
[0]]) - tmp
) & MASK40
;
1466 trace_output (OP_ACCUM
);
1473 trace_input ("mul", OP_REG
, OP_REG
, OP_VOID
);
1474 State
.regs
[OP
[0]] *= State
.regs
[OP
[1]];
1475 trace_output (OP_REG
);
1484 trace_input ("mulx", OP_ACCUM_OUTPUT
, OP_REG
, OP_REG
);
1485 tmp
= SEXT40 ((int16
)(State
.regs
[OP
[1]]) * (int16
)(State
.regs
[OP
[2]]));
1488 tmp
= SEXT40 ((tmp
<< 1) & MASK40
);
1490 if (State
.ST
&& tmp
> MAX32
)
1491 State
.a
[OP
[0]] = MAX32
;
1493 State
.a
[OP
[0]] = tmp
& MASK40
;
1494 trace_output (OP_ACCUM
);
1503 trace_input ("mulxsu", OP_ACCUM_OUTPUT
, OP_REG
, OP_REG
);
1504 tmp
= SEXT40 ((int16
)(State
.regs
[OP
[1]]) * State
.regs
[OP
[2]]);
1509 State
.a
[OP
[0]] = tmp
& MASK40
;
1510 trace_output (OP_ACCUM
);
1519 trace_input ("mulxu", OP_ACCUM_OUTPUT
, OP_REG
, OP_REG
);
1520 tmp
= SEXT40 (State
.regs
[OP
[1]] * State
.regs
[OP
[2]]);
1525 State
.a
[OP
[0]] = tmp
& MASK40
;
1526 trace_output (OP_ACCUM
);
1533 trace_input ("mv", OP_REG_OUTPUT
, OP_REG
, OP_VOID
);
1534 State
.regs
[OP
[0]] = State
.regs
[OP
[1]];
1535 trace_output (OP_REG
);
1542 trace_input ("mv2w", OP_DREG_OUTPUT
, OP_DREG
, OP_VOID
);
1543 State
.regs
[OP
[0]] = State
.regs
[OP
[1]];
1544 State
.regs
[OP
[0]+1] = State
.regs
[OP
[1]+1];
1545 trace_output (OP_DREG
);
1552 trace_input ("mv2wfac", OP_DREG_OUTPUT
, OP_ACCUM
, OP_VOID
);
1553 State
.regs
[OP
[0]] = (State
.a
[OP
[1]] >> 16) & 0xffff;
1554 State
.regs
[OP
[0]+1] = State
.a
[OP
[1]] & 0xffff;
1555 trace_output (OP_DREG
);
1562 trace_input ("mv2wtac", OP_ACCUM_OUTPUT
, OP_DREG
, OP_VOID
);
1563 State
.a
[OP
[1]] = (SEXT16 (State
.regs
[OP
[0]]) << 16 | State
.regs
[OP
[0]+1]) & MASK40
;
1564 trace_output (OP_ACCUM
);
1571 trace_input ("mvac", OP_ACCUM_OUTPUT
, OP_ACCUM
, OP_VOID
);
1572 State
.a
[OP
[0]] = State
.a
[OP
[1]];
1573 trace_output (OP_ACCUM
);
1580 trace_input ("mvb", OP_REG_OUTPUT
, OP_REG
, OP_VOID
);
1581 State
.regs
[OP
[0]] = SEXT8 (State
.regs
[OP
[1]] & 0xff);
1582 trace_output (OP_REG
);
1589 trace_input ("mf0f", OP_REG_OUTPUT
, OP_REG
, OP_VOID
);
1591 State
.regs
[OP
[0]] = State
.regs
[OP
[1]];
1592 trace_output (OP_REG
);
1599 trace_input ("mf0t", OP_REG_OUTPUT
, OP_REG
, OP_VOID
);
1601 State
.regs
[OP
[0]] = State
.regs
[OP
[1]];
1602 trace_output (OP_REG
);
1609 trace_input ("mvfacg", OP_REG_OUTPUT
, OP_ACCUM
, OP_VOID
);
1610 State
.regs
[OP
[0]] = (State
.a
[OP
[1]] >> 32) & 0xff;
1611 trace_output (OP_ACCUM
);
1618 trace_input ("mvfachi", OP_REG_OUTPUT
, OP_ACCUM
, OP_VOID
);
1619 State
.regs
[OP
[0]] = (State
.a
[OP
[1]] >> 16) & 0xffff;
1620 trace_output (OP_REG
);
1627 trace_input ("mvfaclo", OP_REG_OUTPUT
, OP_ACCUM
, OP_VOID
);
1628 State
.regs
[OP
[0]] = State
.a
[OP
[1]] & 0xffff;
1629 trace_output (OP_REG
);
1636 trace_input ("mvfc", OP_REG_OUTPUT
, OP_CR
, OP_VOID
);
1639 /* PSW is treated specially */
1641 if (State
.SM
) PSW
|= 0x8000;
1642 if (State
.EA
) PSW
|= 0x2000;
1643 if (State
.DB
) PSW
|= 0x1000;
1644 if (State
.IE
) PSW
|= 0x400;
1645 if (State
.RP
) PSW
|= 0x200;
1646 if (State
.MD
) PSW
|= 0x100;
1647 if (State
.FX
) PSW
|= 0x80;
1648 if (State
.ST
) PSW
|= 0x40;
1649 if (State
.F0
) PSW
|= 8;
1650 if (State
.F1
) PSW
|= 4;
1651 if (State
.C
) PSW
|= 1;
1653 State
.regs
[OP
[0]] = State
.cregs
[OP
[1]];
1654 trace_output (OP_REG
);
1661 trace_input ("mvtacg", OP_REG
, OP_ACCUM
, OP_VOID
);
1662 State
.a
[OP
[1]] &= MASK32
;
1663 State
.a
[OP
[1]] |= (int64
)(State
.regs
[OP
[0]] & 0xff) << 32;
1664 trace_output (OP_ACCUM_REVERSE
);
1673 trace_input ("mvtachi", OP_REG
, OP_ACCUM
, OP_VOID
);
1674 tmp
= State
.a
[OP
[1]] & 0xffff;
1675 State
.a
[OP
[1]] = (SEXT16 (State
.regs
[OP
[0]]) << 16 | tmp
) & MASK40
;
1676 trace_output (OP_ACCUM_REVERSE
);
1683 trace_input ("mvtaclo", OP_REG
, OP_ACCUM
, OP_VOID
);
1684 State
.a
[OP
[1]] = (SEXT16 (State
.regs
[OP
[0]])) & MASK40
;
1685 trace_output (OP_ACCUM_REVERSE
);
1692 trace_input ("mvtc", OP_REG
, OP_CR_OUTPUT
, OP_VOID
);
1693 State
.cregs
[OP
[1]] = State
.regs
[OP
[0]];
1696 /* PSW is treated specially */
1697 State
.SM
= (PSW
& 0x8000) ? 1 : 0;
1698 State
.EA
= (PSW
& 0x2000) ? 1 : 0;
1699 State
.DB
= (PSW
& 0x1000) ? 1 : 0;
1700 State
.IE
= (PSW
& 0x400) ? 1 : 0;
1701 State
.RP
= (PSW
& 0x200) ? 1 : 0;
1702 State
.MD
= (PSW
& 0x100) ? 1 : 0;
1703 State
.FX
= (PSW
& 0x80) ? 1 : 0;
1704 State
.ST
= (PSW
& 0x40) ? 1 : 0;
1705 State
.F0
= (PSW
& 8) ? 1 : 0;
1706 State
.F1
= (PSW
& 4) ? 1 : 0;
1708 if (State
.ST
&& !State
.FX
)
1710 (*d10v_callback
->printf_filtered
) (d10v_callback
,
1711 "ERROR at PC 0x%x: ST can only be set when FX is set.\n",
1713 State
.exception
= SIGILL
;
1716 trace_output (OP_CR_REVERSE
);
1723 trace_input ("mvub", OP_REG_OUTPUT
, OP_REG
, OP_VOID
);
1724 State
.regs
[OP
[0]] = State
.regs
[OP
[1]] & 0xff;
1725 trace_output (OP_REG
);
1732 trace_input ("neg", OP_REG
, OP_VOID
, OP_VOID
);
1733 State
.regs
[OP
[0]] = 0 - State
.regs
[OP
[0]];
1734 trace_output (OP_REG
);
1743 trace_input ("neg", OP_ACCUM
, OP_VOID
, OP_VOID
);
1744 tmp
= -SEXT40(State
.a
[OP
[0]]);
1748 State
.a
[OP
[0]] = MAX32
;
1749 else if (tmp
< MIN32
)
1750 State
.a
[OP
[0]] = MIN32
;
1752 State
.a
[OP
[0]] = tmp
& MASK40
;
1755 State
.a
[OP
[0]] = tmp
& MASK40
;
1756 trace_output (OP_ACCUM
);
1764 trace_input ("nop", OP_VOID
, OP_VOID
, OP_VOID
);
1765 trace_output (OP_VOID
);
1767 if (State
.ins_type
== INS_LEFT
|| State
.ins_type
== INS_LEFT_PARALLEL
)
1777 trace_input ("not", OP_REG
, OP_VOID
, OP_VOID
);
1778 State
.regs
[OP
[0]] = ~(State
.regs
[OP
[0]]);
1779 trace_output (OP_REG
);
1786 trace_input ("or", OP_REG
, OP_REG
, OP_VOID
);
1787 State
.regs
[OP
[0]] |= State
.regs
[OP
[1]];
1788 trace_output (OP_REG
);
1795 trace_input ("or3", OP_REG_OUTPUT
, OP_REG
, OP_CONSTANT16
);
1796 State
.regs
[OP
[0]] = State
.regs
[OP
[1]] | OP
[2];
1797 trace_output (OP_REG
);
1805 int shift
= SEXT3 (OP
[2]);
1807 trace_input ("rac", OP_DREG_OUTPUT
, OP_ACCUM
, OP_CONSTANT3
);
1810 (*d10v_callback
->printf_filtered
) (d10v_callback
,
1811 "ERROR at PC 0x%x: instruction only valid for A0\n",
1813 State
.exception
= SIGILL
;
1816 State
.F1
= State
.F0
;
1818 tmp
= ((State
.a
[0] << 16) | (State
.a
[1] & 0xffff)) << shift
;
1820 tmp
= ((State
.a
[0] << 16) | (State
.a
[1] & 0xffff)) >> -shift
;
1821 tmp
= ( SEXT60(tmp
) + 0x8000 ) >> 16;
1824 State
.regs
[OP
[0]] = 0x7fff;
1825 State
.regs
[OP
[0]+1] = 0xffff;
1828 else if (tmp
< MIN32
)
1830 State
.regs
[OP
[0]] = 0x8000;
1831 State
.regs
[OP
[0]+1] = 0;
1836 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
1837 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
1840 trace_output (OP_DREG
);
1848 int shift
= SEXT3 (OP
[2]);
1850 trace_input ("rachi", OP_REG_OUTPUT
, OP_ACCUM
, OP_CONSTANT3
);
1851 State
.F1
= State
.F0
;
1853 tmp
= SEXT44 (State
.a
[1]) << shift
;
1855 tmp
= SEXT44 (State
.a
[1]) >> -shift
;
1860 State
.regs
[OP
[0]] = 0x7fff;
1863 else if (tmp
< 0xfff80000000LL
)
1865 State
.regs
[OP
[0]] = 0x8000;
1870 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
1873 trace_output (OP_REG
);
1880 trace_input ("rep", OP_REG
, OP_CONSTANT16
, OP_VOID
);
1883 RPT_C
= State
.regs
[OP
[0]];
1887 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: rep with count=0 is illegal.\n");
1888 State
.exception
= SIGILL
;
1892 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: rep must include at least 4 instructions.\n");
1893 State
.exception
= SIGILL
;
1895 trace_output (OP_VOID
);
1902 trace_input ("repi", OP_CONSTANT16
, OP_CONSTANT16
, OP_VOID
);
1909 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: repi with count=0 is illegal.\n");
1910 State
.exception
= SIGILL
;
1914 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: repi must include at least 4 instructions.\n");
1915 State
.exception
= SIGILL
;
1917 trace_output (OP_VOID
);
1924 d10v_callback
->printf_filtered(d10v_callback
, "ERROR: rtd - NOT IMPLEMENTED\n");
1925 State
.exception
= SIGILL
;
1932 trace_input ("rte", OP_VOID
, OP_VOID
, OP_VOID
);
1935 trace_output (OP_VOID
);
1944 trace_input ("sadd", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
1945 tmp
= SEXT40(State
.a
[OP
[0]]) + (SEXT40(State
.a
[OP
[1]]) >> 16);
1949 State
.a
[OP
[0]] = MAX32
;
1950 else if (tmp
< MIN32
)
1951 State
.a
[OP
[0]] = MIN32
;
1953 State
.a
[OP
[0]] = tmp
& MASK40
;
1956 State
.a
[OP
[0]] = tmp
& MASK40
;
1957 trace_output (OP_ACCUM
);
1964 trace_input ("setf0f", OP_REG_OUTPUT
, OP_VOID
, OP_VOID
);
1965 State
.regs
[OP
[0]] = (State
.F0
== 0) ? 1 : 0;
1966 trace_output (OP_REG
);
1973 trace_input ("setf0t", OP_REG_OUTPUT
, OP_VOID
, OP_VOID
);
1974 State
.regs
[OP
[0]] = (State
.F0
== 1) ? 1 : 0;
1975 trace_output (OP_REG
);
1982 trace_input ("sleep", OP_VOID
, OP_VOID
, OP_VOID
);
1984 trace_output (OP_VOID
);
1991 trace_input ("sll", OP_REG
, OP_REG
, OP_VOID
);
1992 State
.regs
[OP
[0]] <<= (State
.regs
[OP
[1]] & 0xf);
1993 trace_output (OP_REG
);
2001 trace_input ("sll", OP_ACCUM
, OP_REG
, OP_VOID
);
2002 if ((State
.regs
[OP
[1]] & 31) <= 16)
2003 tmp
= SEXT40 (State
.a
[OP
[0]]) << (State
.regs
[OP
[1]] & 31);
2006 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: shift value %d too large.\n", State
.regs
[OP
[1]] & 31);
2007 State
.exception
= SIGILL
;
2014 State
.a
[OP
[0]] = MAX32
;
2015 else if (tmp
< 0xffffff80000000LL
)
2016 State
.a
[OP
[0]] = MIN32
;
2018 State
.a
[OP
[0]] = tmp
& MASK40
;
2021 State
.a
[OP
[0]] = tmp
& MASK40
;
2022 trace_output (OP_ACCUM
);
2029 trace_input ("slli", OP_REG
, OP_CONSTANT16
, OP_VOID
);
2030 State
.regs
[OP
[0]] <<= OP
[1];
2031 trace_output (OP_REG
);
2043 trace_input ("slli", OP_ACCUM
, OP_CONSTANT16
, OP_VOID
);
2044 tmp
= SEXT40(State
.a
[OP
[0]]) << OP
[1];
2049 State
.a
[OP
[0]] = MAX32
;
2050 else if (tmp
< 0xffffff80000000LL
)
2051 State
.a
[OP
[0]] = MIN32
;
2053 State
.a
[OP
[0]] = tmp
& MASK40
;
2056 State
.a
[OP
[0]] = tmp
& MASK40
;
2057 trace_output (OP_ACCUM
);
2066 trace_input ("slx", OP_REG
, OP_FLAG
, OP_VOID
);
2067 State
.regs
[OP
[0]] = (State
.regs
[OP
[0]] << 1) | State
.F0
;
2068 trace_output (OP_REG
);
2075 trace_input ("sra", OP_REG
, OP_REG
, OP_VOID
);
2076 State
.regs
[OP
[0]] = ((int16
)(State
.regs
[OP
[0]])) >> (State
.regs
[OP
[1]] & 0xf);
2077 trace_output (OP_REG
);
2084 trace_input ("sra", OP_ACCUM
, OP_REG
, OP_VOID
);
2085 if ((State
.regs
[OP
[1]] & 31) <= 16)
2086 State
.a
[OP
[0]] >>= (State
.regs
[OP
[1]] & 31);
2089 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: shift value %d too large.\n", State
.regs
[OP
[1]] & 31);
2090 State
.exception
= SIGILL
;
2094 trace_output (OP_ACCUM
);
2101 trace_input ("srai", OP_REG
, OP_CONSTANT16
, OP_VOID
);
2102 State
.regs
[OP
[0]] = ((int16
)(State
.regs
[OP
[0]])) >> OP
[1];
2103 trace_output (OP_REG
);
2113 trace_input ("srai", OP_ACCUM
, OP_CONSTANT16
, OP_VOID
);
2114 State
.a
[OP
[0]] >>= OP
[1];
2115 trace_output (OP_ACCUM
);
2122 trace_input ("srl", OP_REG
, OP_REG
, OP_VOID
);
2123 State
.regs
[OP
[0]] >>= (State
.regs
[OP
[1]] & 0xf);
2124 trace_output (OP_REG
);
2131 trace_input ("srl", OP_ACCUM
, OP_REG
, OP_VOID
);
2132 if ((State
.regs
[OP
[1]] & 31) <= 16)
2133 State
.a
[OP
[0]] >>= (State
.regs
[OP
[1]] & 31);
2136 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: shift value %d too large.\n", State
.regs
[OP
[1]] & 31);
2137 State
.exception
= SIGILL
;
2141 trace_output (OP_ACCUM
);
2148 trace_input ("srli", OP_REG
, OP_CONSTANT16
, OP_VOID
);
2149 State
.regs
[OP
[0]] >>= OP
[1];
2150 trace_output (OP_REG
);
2160 trace_input ("srli", OP_ACCUM
, OP_CONSTANT16
, OP_VOID
);
2161 State
.a
[OP
[0]] >>= OP
[1];
2162 trace_output (OP_ACCUM
);
2171 trace_input ("srx", OP_REG
, OP_FLAG
, OP_VOID
);
2172 tmp
= State
.F0
<< 15;
2173 State
.regs
[OP
[0]] = (State
.regs
[OP
[0]] >> 1) | tmp
;
2174 trace_output (OP_REG
);
2181 trace_input ("st", OP_REG
, OP_MEMREF2
, OP_VOID
);
2182 SW (OP
[1] + State
.regs
[OP
[2]], State
.regs
[OP
[0]]);
2183 trace_output (OP_VOID
);
2190 trace_input ("st", OP_REG
, OP_MEMREF
, OP_VOID
);
2191 SW (State
.regs
[OP
[1]], State
.regs
[OP
[0]]);
2192 trace_output (OP_VOID
);
2199 trace_input ("st", OP_REG
, OP_PREDEC
, OP_VOID
);
2202 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: cannot pre-decrement any registers but r15 (SP).\n");
2203 State
.exception
= SIGILL
;
2206 State
.regs
[OP
[1]] -= 2;
2207 SW (State
.regs
[OP
[1]], State
.regs
[OP
[0]]);
2208 trace_output (OP_VOID
);
2215 trace_input ("st", OP_REG
, OP_POSTINC
, OP_VOID
);
2216 SW (State
.regs
[OP
[1]], State
.regs
[OP
[0]]);
2217 INC_ADDR (State
.regs
[OP
[1]],2);
2218 trace_output (OP_VOID
);
2225 trace_input ("st", OP_REG
, OP_POSTDEC
, OP_VOID
);
2226 SW (State
.regs
[OP
[1]], State
.regs
[OP
[0]]);
2227 INC_ADDR (State
.regs
[OP
[1]],-2);
2228 trace_output (OP_VOID
);
2235 trace_input ("st2w", OP_DREG
, OP_MEMREF2
, OP_VOID
);
2236 SW (State
.regs
[OP
[2]]+OP
[1], State
.regs
[OP
[0]]);
2237 SW (State
.regs
[OP
[2]]+OP
[1]+2, State
.regs
[OP
[0]+1]);
2238 trace_output (OP_VOID
);
2245 trace_input ("st2w", OP_REG
, OP_MEMREF
, OP_VOID
);
2246 SW (State
.regs
[OP
[1]], State
.regs
[OP
[0]]);
2247 SW (State
.regs
[OP
[1]]+2, State
.regs
[OP
[0]+1]);
2248 trace_output (OP_VOID
);
2255 trace_input ("st2w", OP_REG
, OP_PREDEC
, OP_VOID
);
2258 (*d10v_callback
->printf_filtered
) (d10v_callback
, "ERROR: cannot pre-decrement any registers but r15 (SP).\n");
2259 State
.exception
= SIGILL
;
2262 State
.regs
[OP
[1]] -= 4;
2263 SW (State
.regs
[OP
[1]], State
.regs
[OP
[0]]);
2264 SW (State
.regs
[OP
[1]]+2, State
.regs
[OP
[0]+1]);
2265 trace_output (OP_VOID
);
2272 trace_input ("st2w", OP_REG
, OP_POSTDEC
, OP_VOID
);
2273 SW (State
.regs
[OP
[1]], State
.regs
[OP
[0]]);
2274 SW (State
.regs
[OP
[1]]+2, State
.regs
[OP
[0]+1]);
2275 INC_ADDR (State
.regs
[OP
[1]],4);
2276 trace_output (OP_VOID
);
2283 trace_input ("st2w", OP_REG
, OP_POSTINC
, OP_VOID
);
2284 SW (State
.regs
[OP
[1]], State
.regs
[OP
[0]]);
2285 SW (State
.regs
[OP
[1]]+2, State
.regs
[OP
[0]+1]);
2286 INC_ADDR (State
.regs
[OP
[1]],-4);
2287 trace_output (OP_VOID
);
2294 trace_input ("stb", OP_REG
, OP_MEMREF2
, OP_VOID
);
2295 SB (State
.regs
[OP
[2]]+OP
[1], State
.regs
[OP
[0]]);
2296 trace_output (OP_VOID
);
2303 trace_input ("stb", OP_REG
, OP_MEMREF
, OP_VOID
);
2304 SB (State
.regs
[OP
[1]], State
.regs
[OP
[0]]);
2305 trace_output (OP_VOID
);
2312 trace_input ("stop", OP_VOID
, OP_VOID
, OP_VOID
);
2313 State
.exception
= SIG_D10V_STOP
;
2314 trace_output (OP_VOID
);
2323 trace_input ("sub", OP_REG
, OP_REG
, OP_VOID
);
2324 tmp
= (int16
)State
.regs
[OP
[0]]- (int16
)State
.regs
[OP
[1]];
2325 State
.C
= (tmp
& 0xffff0000) ? 1 : 0;
2326 State
.regs
[OP
[0]] = tmp
& 0xffff;
2327 trace_output (OP_REG
);
2336 trace_input ("sub", OP_ACCUM
, OP_DREG
, OP_VOID
);
2337 tmp
= SEXT40(State
.a
[OP
[0]]) - (SEXT16 (State
.regs
[OP
[1]]) << 16 | State
.regs
[OP
[1]+1]);
2341 State
.a
[OP
[0]] = MAX32
;
2342 else if ( tmp
< MIN32
)
2343 State
.a
[OP
[0]] = MIN32
;
2345 State
.a
[OP
[0]] = tmp
& MASK40
;
2348 State
.a
[OP
[0]] = tmp
& MASK40
;
2350 trace_output (OP_ACCUM
);
2360 trace_input ("sub", OP_ACCUM
, OP_ACCUM
, OP_VOID
);
2361 tmp
= SEXT40(State
.a
[OP
[0]]) - SEXT40(State
.a
[OP
[1]]);
2365 State
.a
[OP
[0]] = MAX32
;
2366 else if ( tmp
< MIN32
)
2367 State
.a
[OP
[0]] = MIN32
;
2369 State
.a
[OP
[0]] = tmp
& MASK40
;
2372 State
.a
[OP
[0]] = tmp
& MASK40
;
2374 trace_output (OP_ACCUM
);
2384 trace_input ("sub2w", OP_DREG
, OP_DREG
, OP_VOID
);
2385 a
= (int32
)((State
.regs
[OP
[0]] << 16) | State
.regs
[OP
[0]+1]);
2386 b
= (int32
)((State
.regs
[OP
[1]] << 16) | State
.regs
[OP
[1]+1]);
2388 State
.C
= (tmp
& 0xffffffff00000000LL
) ? 1 : 0;
2389 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
2390 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
2391 trace_output (OP_DREG
);
2400 trace_input ("subac3", OP_DREG_OUTPUT
, OP_DREG
, OP_ACCUM
);
2401 tmp
= SEXT40 ((State
.regs
[OP
[1]] << 16) | State
.regs
[OP
[1]+1]) - SEXT40 (State
.a
[OP
[2]]);
2402 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
2403 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
2404 trace_output (OP_DREG
);
2413 trace_input ("subac3", OP_DREG_OUTPUT
, OP_ACCUM
, OP_ACCUM
);
2414 tmp
= SEXT40(State
.a
[OP
[1]]) - SEXT40(State
.a
[OP
[2]]);
2415 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
2416 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
2417 trace_output (OP_DREG
);
2426 trace_input ("subac3s", OP_DREG_OUTPUT
, OP_DREG
, OP_ACCUM
);
2427 State
.F1
= State
.F0
;
2428 tmp
= SEXT40 ((State
.regs
[OP
[1]] << 16) | State
.regs
[OP
[1]+1]) - SEXT40(State
.a
[OP
[2]]);
2431 State
.regs
[OP
[0]] = 0x7fff;
2432 State
.regs
[OP
[0]+1] = 0xffff;
2435 else if (tmp
< MIN32
)
2437 State
.regs
[OP
[0]] = 0x8000;
2438 State
.regs
[OP
[0]+1] = 0;
2443 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
2444 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
2447 trace_output (OP_DREG
);
2456 trace_input ("subac3s", OP_DREG_OUTPUT
, OP_ACCUM
, OP_ACCUM
);
2457 State
.F1
= State
.F0
;
2458 tmp
= SEXT40(State
.a
[OP
[1]]) - SEXT40(State
.a
[OP
[2]]);
2461 State
.regs
[OP
[0]] = 0x7fff;
2462 State
.regs
[OP
[0]+1] = 0xffff;
2465 else if (tmp
< MIN32
)
2467 State
.regs
[OP
[0]] = 0x8000;
2468 State
.regs
[OP
[0]+1] = 0;
2473 State
.regs
[OP
[0]] = (tmp
>> 16) & 0xffff;
2474 State
.regs
[OP
[0]+1] = tmp
& 0xffff;
2477 trace_output (OP_DREG
);
2488 trace_input ("subi", OP_REG
, OP_CONSTANT16
, OP_VOID
);
2489 tmp
= (int16
)State
.regs
[OP
[0]] - OP
[1];
2490 State
.C
= (tmp
& 0xffff0000) ? 1 : 0;
2491 State
.regs
[OP
[0]] = tmp
& 0xffff;
2492 trace_output (OP_REG
);
2499 trace_input ("trap", OP_CONSTANT4
, OP_VOID
, OP_VOID
);
2500 trace_output (OP_VOID
);
2506 (*d10v_callback
->printf_filtered
) (d10v_callback
, "Unknown trap code %d\n", OP
[0]);
2507 State
.exception
= SIGILL
;
2509 /* Use any other traps for batch debugging. */
2512 static int first_time
= 1;
2517 (*d10v_callback
->printf_filtered
) (d10v_callback
, "Trap # PC ");
2518 for (i
= 0; i
< 16; i
++)
2519 (*d10v_callback
->printf_filtered
) (d10v_callback
, " %sr%d", (i
> 9) ? "" : " ", i
);
2520 (*d10v_callback
->printf_filtered
) (d10v_callback
, " a0 a1 f0 f1 c\n");
2523 (*d10v_callback
->printf_filtered
) (d10v_callback
, "Trap %2d 0x%.4x:", (int)OP
[0], (int)PC
);
2525 for (i
= 0; i
< 16; i
++)
2526 (*d10v_callback
->printf_filtered
) (d10v_callback
, " %.4x", (int) State
.regs
[i
]);
2528 for (i
= 0; i
< 2; i
++)
2529 (*d10v_callback
->printf_filtered
) (d10v_callback
, " %.2x%.8lx",
2530 ((int)(State
.a
[OP
[i
]] >> 32) & 0xff),
2531 ((unsigned long)State
.a
[OP
[i
]]) & 0xffffffff);
2533 (*d10v_callback
->printf_filtered
) (d10v_callback
, " %d %d %d\n",
2534 State
.F0
!= 0, State
.F1
!= 0, State
.C
!= 0);
2539 /* Trap 0 is used for simulating low-level I/O */
2541 int save_errno
= errno
;
2544 /* Registers passed to trap 0 */
2546 #define FUNC State.regs[6] /* function number */
2547 #define PARM1 State.regs[2] /* optional parm 1 */
2548 #define PARM2 State.regs[3] /* optional parm 2 */
2549 #define PARM3 State.regs[4] /* optional parm 3 */
2550 #define PARM4 State.regs[5] /* optional parm 3 */
2552 /* Registers set by trap 0 */
2554 #define RETVAL State.regs[2] /* return value */
2555 #define RETVAL_HIGH State.regs[2] /* return value */
2556 #define RETVAL_LOW State.regs[3] /* return value */
2557 #define RETERR State.regs[4] /* return error code */
2559 /* Turn a pointer in a register into a pointer into real memory. */
2561 #define MEMPTR(x) ((char *)((x) + State.imem))
2565 #if !defined(__GO32__) && !defined(_WIN32)
2570 RETVAL
= execve (MEMPTR (PARM1
), (char **) MEMPTR (PARM2
),
2571 (char **)MEMPTR (PARM3
));
2574 RETVAL
= execve (MEMPTR (PARM1
), (char **) MEMPTR (PARM2
), NULL
);
2582 RETVAL
= pipe (host_fd
);
2583 SW (buf
, host_fd
[0]);
2584 buf
+= sizeof(uint16
);
2585 SW (buf
, host_fd
[1]);
2592 RETVAL
= wait (&status
);
2598 RETVAL
= d10v_callback
->read (d10v_callback
, PARM1
, MEMPTR (PARM2
),
2603 RETVAL
= (int)d10v_callback
->write_stdout (d10v_callback
,
2604 MEMPTR (PARM2
), PARM3
);
2606 RETVAL
= (int)d10v_callback
->write (d10v_callback
, PARM1
,
2607 MEMPTR (PARM2
), PARM3
);
2611 unsigned long ret
= d10v_callback
->lseek (d10v_callback
, PARM1
,
2612 (((unsigned long)PARM2
) << 16) || (unsigned long)PARM3
,
2614 RETVAL_HIGH
= ret
>> 16;
2615 RETVAL_LOW
= ret
& 0xffff;
2619 RETVAL
= d10v_callback
->close (d10v_callback
, PARM1
);
2622 RETVAL
= d10v_callback
->open (d10v_callback
, MEMPTR (PARM1
), PARM2
);
2625 State
.exception
= SIG_D10V_EXIT
;
2629 /* stat system call */
2631 struct stat host_stat
;
2634 RETVAL
= stat (MEMPTR (PARM1
), &host_stat
);
2638 /* The hard-coded offsets and sizes were determined by using
2639 * the D10V compiler on a test program that used struct stat.
2641 SW (buf
, host_stat
.st_dev
);
2642 SW (buf
+2, host_stat
.st_ino
);
2643 SW (buf
+4, host_stat
.st_mode
);
2644 SW (buf
+6, host_stat
.st_nlink
);
2645 SW (buf
+8, host_stat
.st_uid
);
2646 SW (buf
+10, host_stat
.st_gid
);
2647 SW (buf
+12, host_stat
.st_rdev
);
2648 SLW (buf
+16, host_stat
.st_size
);
2649 SLW (buf
+20, host_stat
.st_atime
);
2650 SLW (buf
+28, host_stat
.st_mtime
);
2651 SLW (buf
+36, host_stat
.st_ctime
);
2656 RETVAL
= chown (MEMPTR (PARM1
), PARM2
, PARM3
);
2659 RETVAL
= chmod (MEMPTR (PARM1
), PARM2
);
2662 /* Cast the second argument to void *, to avoid type mismatch
2663 if a prototype is present. */
2664 RETVAL
= utime (MEMPTR (PARM1
), (void *) MEMPTR (PARM2
));
2669 RETERR
= d10v_callback
->get_errno(d10v_callback
);
2674 /* Trap 1 prints a string */
2676 char *fstr
= State
.regs
[2] + State
.imem
;
2677 fputs (fstr
, stdout
);
2682 /* Trap 2 calls printf */
2684 char *fstr
= State
.regs
[2] + State
.imem
;
2685 (*d10v_callback
->printf_filtered
) (d10v_callback
, fstr
,
2686 (int16
)State
.regs
[3],
2687 (int16
)State
.regs
[4],
2688 (int16
)State
.regs
[5]);
2693 /* Trap 3 writes a character */
2694 putchar (State
.regs
[2]);
2704 trace_input ("tst0i", OP_REG
, OP_CONSTANT16
, OP_VOID
);
2705 State
.F1
= State
.F0
;
2706 State
.F0
= (State
.regs
[OP
[0]] & OP
[1]) ? 1 : 0;
2707 trace_output (OP_FLAG
);
2714 trace_input ("tst1i", OP_REG
, OP_CONSTANT16
, OP_VOID
);
2715 State
.F1
= State
.F0
;
2716 State
.F0
= (~(State
.regs
[OP
[0]]) & OP
[1]) ? 1 : 0;
2717 trace_output (OP_FLAG
);
2724 trace_input ("wait", OP_VOID
, OP_VOID
, OP_VOID
);
2726 trace_output (OP_VOID
);
2733 trace_input ("xor", OP_REG
, OP_REG
, OP_VOID
);
2734 State
.regs
[OP
[0]] ^= State
.regs
[OP
[1]];
2735 trace_output (OP_REG
);
2742 trace_input ("xor3", OP_REG_OUTPUT
, OP_REG
, OP_CONSTANT16
);
2743 State
.regs
[OP
[0]] = State
.regs
[OP
[1]] ^ OP
[2];
2744 trace_output (OP_REG
);
This page took 0.087756 seconds and 4 git commands to generate.