2 /* Simulator for the MIPS architecture.
4 This file is part of the MIPS sim
6 THIS SOFTWARE IS NOT COPYRIGHTED
8 Cygnus offers the following for use in the public domain. Cygnus
9 makes no warranty with regard to the software or it's performance
10 and the user accepts the software "AS IS" with all faults.
12 CYGNUS DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO
13 THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 The IDT monitor (found on the VR4300 board), seems to lie about
22 register contents. It seems to treat the registers as sign-extended
23 32-bit values. This cause *REAL* problems when single-stepping 64-bit
28 /* The TRACE manifests enable the provision of extra features. If they
29 are not defined then a simpler (quicker) simulator is constructed
30 without the required run-time checks, etc. */
31 #if 1 /* 0 to allow user build selection, 1 to force inclusion */
37 #include "sim-utils.h"
38 #include "sim-options.h"
39 #include "sim-assert.h"
42 /* start-sanitize-sky */
46 #include "sky-libvpe.h"
51 /* end-sanitize-sky */
73 #include "libiberty.h"
75 #include "callback.h" /* GDB simulator callback interface */
76 #include "remote-sim.h" /* GDB simulator interface */
84 char* pr_addr
PARAMS ((SIM_ADDR addr
));
85 char* pr_uword64
PARAMS ((uword64 addr
));
88 /* Get the simulator engine description, without including the code: */
95 /* Within interp.c we refer to the sim_state and sim_cpu directly. */
100 /* The following reserved instruction value is used when a simulator
101 trap is required. NOTE: Care must be taken, since this value may be
102 used in later revisions of the MIPS ISA. */
104 #define RSVD_INSTRUCTION (0x00000005)
105 #define RSVD_INSTRUCTION_MASK (0xFC00003F)
107 #define RSVD_INSTRUCTION_ARG_SHIFT 6
108 #define RSVD_INSTRUCTION_ARG_MASK 0xFFFFF
111 /* Bits in the Debug register */
112 #define Debug_DBD 0x80000000 /* Debug Branch Delay */
113 #define Debug_DM 0x40000000 /* Debug Mode */
114 #define Debug_DBp 0x00000002 /* Debug Breakpoint indicator */
116 /*---------------------------------------------------------------------------*/
117 /*-- GDB simulator interface ------------------------------------------------*/
118 /*---------------------------------------------------------------------------*/
120 static void ColdReset
PARAMS((SIM_DESC sd
));
122 /*---------------------------------------------------------------------------*/
126 #define DELAYSLOT() {\
127 if (STATE & simDELAYSLOT)\
128 sim_io_eprintf(sd,"Delay slot already activated (branch in delay slot?)\n");\
129 STATE |= simDELAYSLOT;\
132 #define JALDELAYSLOT() {\
134 STATE |= simJALDELAYSLOT;\
138 STATE &= ~simDELAYSLOT;\
139 STATE |= simSKIPNEXT;\
142 #define CANCELDELAYSLOT() {\
144 STATE &= ~(simDELAYSLOT | simJALDELAYSLOT);\
147 #define INDELAYSLOT() ((STATE & simDELAYSLOT) != 0)
148 #define INJALDELAYSLOT() ((STATE & simJALDELAYSLOT) != 0)
150 #define K0BASE (0x80000000)
151 #define K0SIZE (0x20000000)
152 #define K1BASE (0xA0000000)
153 #define K1SIZE (0x20000000)
154 #define MONITOR_BASE (0xBFC00000)
155 #define MONITOR_SIZE (1 << 11)
156 #define MEM_SIZE (2 << 20)
158 /* start-sanitize-sky */
161 #define MEM_SIZE (16 << 20) /* 16 MB */
163 /* end-sanitize-sky */
166 static char *tracefile
= "trace.din"; /* default filename for trace log */
167 FILE *tracefh
= NULL
;
168 static void open_trace
PARAMS((SIM_DESC sd
));
171 /* simulation target board. NULL=canonical */
172 static char* board
= NULL
;
175 static DECLARE_OPTION_HANDLER (mips_option_handler
);
178 OPTION_DINERO_TRACE
= OPTION_START
,
180 /* start-stanitize-branchbug4011 */
181 OPTION_BRANCH_BUG_4011
,
182 /* end-stanitize-branchbug4011 */
188 mips_option_handler (sd
, cpu
, opt
, arg
, is_command
)
198 /* start-sanitize-branchbug4011 */
199 case OPTION_BRANCH_BUG_4011
:
201 for (cpu_nr
= 0; cpu_nr
< MAX_NR_PROCESSORS
; cpu_nr
++)
203 sim_cpu
*cpu
= STATE_CPU (sd
, cpu_nr
);
205 BRANCHBUG4011_OPTION
= 1;
206 else if (strcmp (arg
, "yes") == 0)
207 BRANCHBUG4011_OPTION
= 1;
208 else if (strcmp (arg
, "no") == 0)
209 BRANCHBUG4011_OPTION
= 0;
210 else if (strcmp (arg
, "on") == 0)
211 BRANCHBUG4011_OPTION
= 1;
212 else if (strcmp (arg
, "off") == 0)
213 BRANCHBUG4011_OPTION
= 0;
216 fprintf (stderr
, "Unrecognized check-4011-branch-bug option `%s'\n", arg
);
223 /* end-sanitize-branchbug4011 */
224 case OPTION_DINERO_TRACE
: /* ??? */
226 /* Eventually the simTRACE flag could be treated as a toggle, to
227 allow external control of the program points being traced
228 (i.e. only from main onwards, excluding the run-time setup,
230 for (cpu_nr
= 0; cpu_nr
< MAX_NR_PROCESSORS
; cpu_nr
++)
232 sim_cpu
*cpu
= STATE_CPU (sd
, cpu_nr
);
235 else if (strcmp (arg
, "yes") == 0)
237 else if (strcmp (arg
, "no") == 0)
239 else if (strcmp (arg
, "on") == 0)
241 else if (strcmp (arg
, "off") == 0)
245 fprintf (stderr
, "Unrecognized dinero-trace option `%s'\n", arg
);
252 Simulator constructed without dinero tracing support (for performance).\n\
253 Re-compile simulator with \"-DTRACE\" to enable this option.\n");
257 case OPTION_DINERO_FILE
:
259 if (optarg
!= NULL
) {
261 tmp
= (char *)malloc(strlen(optarg
) + 1);
264 sim_io_printf(sd
,"Failed to allocate buffer for tracefile name \"%s\"\n",optarg
);
270 sim_io_printf(sd
,"Placing trace information into file \"%s\"\n",tracefile
);
280 board
= zalloc(strlen(arg
) + 1);
291 static const OPTION mips_options
[] =
293 { {"dinero-trace", optional_argument
, NULL
, OPTION_DINERO_TRACE
},
294 '\0', "on|off", "Enable dinero tracing",
295 mips_option_handler
},
296 /* start-sanitize-branchbug4011 */
297 { {"check-4011-branch-bug", optional_argument
, NULL
, OPTION_BRANCH_BUG_4011
},
298 '\0', "on|off", "Enable checking for 4011 branch bug",
299 mips_option_handler
},
300 /* end-sanitize-branchbug4011 */
301 { {"dinero-file", required_argument
, NULL
, OPTION_DINERO_FILE
},
302 '\0', "FILE", "Write dinero trace to FILE",
303 mips_option_handler
},
304 { {"board", required_argument
, NULL
, OPTION_BOARD
},
305 '\0', "none" /* rely on compile-time string concatenation for other options */
307 /* start-sanitize-tx3904 */
308 #define BOARD_JMR3904 "jmr3904"
310 #define BOARD_JMR3904_PAL "jmr3904pal"
311 "|" BOARD_JMR3904_PAL
312 #define BOARD_JMR3904_DEBUG "jmr3904debug"
313 "|" BOARD_JMR3904_DEBUG
314 /* end-sanitize-tx3904 */
316 , "Customize simulation for a particular board.", mips_option_handler
},
318 { {NULL
, no_argument
, NULL
, 0}, '\0', NULL
, NULL
, NULL
}
322 int interrupt_pending
;
325 interrupt_event (SIM_DESC sd
, void *data
)
327 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
328 address_word cia
= CIA_GET (cpu
);
331 interrupt_pending
= 0;
332 SignalExceptionInterrupt ();
334 else if (!interrupt_pending
)
335 sim_events_schedule (sd
, 1, interrupt_event
, data
);
339 /*---------------------------------------------------------------------------*/
340 /*-- Device registration hook -----------------------------------------------*/
341 /*---------------------------------------------------------------------------*/
342 static void device_init(SIM_DESC sd
) {
344 extern void register_devices(SIM_DESC
);
345 register_devices(sd
);
349 /*---------------------------------------------------------------------------*/
350 /*-- GDB simulator interface ------------------------------------------------*/
351 /*---------------------------------------------------------------------------*/
354 sim_open (kind
, cb
, abfd
, argv
)
360 SIM_DESC sd
= sim_state_alloc (kind
, cb
);
361 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
363 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
365 /* FIXME: watchpoints code shouldn't need this */
366 STATE_WATCHPOINTS (sd
)->pc
= &(PC
);
367 STATE_WATCHPOINTS (sd
)->sizeof_pc
= sizeof (PC
);
368 STATE_WATCHPOINTS (sd
)->interrupt_handler
= interrupt_event
;
372 if (sim_pre_argv_init (sd
, argv
[0]) != SIM_RC_OK
)
374 sim_add_option_table (sd
, NULL
, mips_options
);
376 /* start-sanitize-sky */
378 sky_command_options_open (sd
);
380 /* end-sanitize-sky */
382 /* getopt will print the error message so we just have to exit if this fails.
383 FIXME: Hmmm... in the case of gdb we need getopt to call
385 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
387 /* Uninstall the modules to avoid memory leaks,
388 file descriptor leaks, etc. */
389 sim_module_uninstall (sd
);
393 /* handle board-specific memory maps */
396 /* Allocate core managed memory */
398 /* start-sanitize-sky */
400 /* end-sanitize-sky */
402 sim_do_commandf (sd
, "memory region 0x%lx,0x%lx", MONITOR_BASE
, MONITOR_SIZE
);
403 /* For compatibility with the old code - under this (at level one)
404 are the kernel spaces K0 & K1. Both of these map to a single
405 smaller sub region */
406 sim_do_command(sd
," memory region 0x7fff8000,0x8000") ; /* MTZ- 32 k stack */
407 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx%%0x%lx,0x%0x",
409 MEM_SIZE
, /* actual size */
411 /* start-sanitize-sky */
414 sim_do_commandf (sd
, "memory region 0x%lx,0x%lx", MONITOR_BASE
- K1BASE
, MONITOR_SIZE
);
415 sim_do_command (sd
," memory region 0x7fff8000,0x8000") ; /* MTZ- 32 k stack */
416 /* 16M @ 0x0. Aliases at 0x80000000 and 0xA0000000 are handled by
417 address_translation() */
418 sim_do_commandf (sd
, "memory size 0x%lx", MEM_SIZE
);
420 /* end-sanitize-sky */
425 /* start-sanitize-tx3904 */
428 && (strcmp(board
, BOARD_JMR3904
) == 0 ||
429 strcmp(board
, BOARD_JMR3904_PAL
) == 0 ||
430 strcmp(board
, BOARD_JMR3904_DEBUG
) == 0))
432 /* match VIRTUAL memory layout of JMR-TX3904 board */
436 /* ROM: 0x9FC0_0000 - 0x9FFF_FFFF and 0xBFC0_0000 - 0xBFFF_FFFF */
437 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx,0x%0x",
439 4 * 1024 * 1024, /* 4 MB */
442 /* SRAM: 0x8000_0000 - 0x803F_FFFF and 0xA000_0000 - 0xA03F_FFFF */
443 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx,0x%0x",
445 4 * 1024 * 1024, /* 4 MB */
448 /* DRAM: 0x8800_0000 - 0x89FF_FFFF and 0xA800_0000 - 0xA9FF_FFFF */
449 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx,0x%0x",
451 32 * 1024 * 1024, /* 32 MB */
454 /* --- simulated devices --- */
455 sim_hw_parse (sd
, "/tx3904irc@0xffffc000/reg 0xffffc000 0x20");
456 sim_hw_parse (sd
, "/tx3904cpu");
457 sim_hw_parse (sd
, "/tx3904tmr@0xfffff000/reg 0xfffff000 0x100");
458 sim_hw_parse (sd
, "/tx3904tmr@0xfffff100/reg 0xfffff100 0x100");
459 sim_hw_parse (sd
, "/tx3904tmr@0xfffff200/reg 0xfffff200 0x100");
461 /* -- device connections --- */
462 sim_hw_parse (sd
, "/tx3904irc > ip level /tx3904cpu");
463 sim_hw_parse (sd
, "/tx3904tmr@0xfffff000 > int tmr0 /tx3904irc");
464 sim_hw_parse (sd
, "/tx3904tmr@0xfffff100 > int tmr1 /tx3904irc");
465 sim_hw_parse (sd
, "/tx3904tmr@0xfffff200 > int tmr2 /tx3904irc");
467 /* add PAL timer & I/O module */
468 if(! strcmp(board
, BOARD_JMR3904_PAL
))
471 sim_hw_parse (sd
, "/pal@0xffff0000");
472 sim_hw_parse (sd
, "/pal@0xffff0000/reg 0xffff0000 64");
474 /* wire up interrupt ports to irc */
475 sim_hw_parse (sd
, "/pal@0x31000000 > countdown tmr0 /tx3904irc");
476 sim_hw_parse (sd
, "/pal@0x31000000 > timer tmr1 /tx3904irc");
477 sim_hw_parse (sd
, "/pal@0x31000000 > int int0 /tx3904irc");
480 if(! strcmp(board
, BOARD_JMR3904_DEBUG
))
482 /* -- DEBUG: glue interrupt generators --- */
483 sim_hw_parse (sd
, "/glue@0xffff0000/reg 0xffff0000 0x50");
484 sim_hw_parse (sd
, "/glue@0xffff0000 > int0 int0 /tx3904irc");
485 sim_hw_parse (sd
, "/glue@0xffff0000 > int1 int1 /tx3904irc");
486 sim_hw_parse (sd
, "/glue@0xffff0000 > int2 int2 /tx3904irc");
487 sim_hw_parse (sd
, "/glue@0xffff0000 > int3 int3 /tx3904irc");
488 sim_hw_parse (sd
, "/glue@0xffff0000 > int4 int4 /tx3904irc");
489 sim_hw_parse (sd
, "/glue@0xffff0000 > int5 int5 /tx3904irc");
490 sim_hw_parse (sd
, "/glue@0xffff0000 > int6 int6 /tx3904irc");
491 sim_hw_parse (sd
, "/glue@0xffff0000 > int7 int7 /tx3904irc");
492 sim_hw_parse (sd
, "/glue@0xffff0000 > int8 dmac0 /tx3904irc");
493 sim_hw_parse (sd
, "/glue@0xffff0000 > int9 dmac1 /tx3904irc");
494 sim_hw_parse (sd
, "/glue@0xffff0000 > int10 dmac2 /tx3904irc");
495 sim_hw_parse (sd
, "/glue@0xffff0000 > int11 dmac3 /tx3904irc");
496 sim_hw_parse (sd
, "/glue@0xffff0000 > int12 sio0 /tx3904irc");
497 sim_hw_parse (sd
, "/glue@0xffff0000 > int13 sio1 /tx3904irc");
498 sim_hw_parse (sd
, "/glue@0xffff0000 > int14 tmr0 /tx3904irc");
499 sim_hw_parse (sd
, "/glue@0xffff0000 > int15 tmr1 /tx3904irc");
500 sim_hw_parse (sd
, "/glue@0xffff0000 > int16 tmr2 /tx3904irc");
501 sim_hw_parse (sd
, "/glue@0xffff0000 > int17 nmi /tx3904cpu");
507 /* end-sanitize-tx3904 */
510 /* check for/establish the a reference program image */
511 if (sim_analyze_program (sd
,
512 (STATE_PROG_ARGV (sd
) != NULL
513 ? *STATE_PROG_ARGV (sd
)
517 sim_module_uninstall (sd
);
521 /* Configure/verify the target byte order and other runtime
522 configuration options */
523 if (sim_config (sd
) != SIM_RC_OK
)
525 sim_module_uninstall (sd
);
529 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
531 /* Uninstall the modules to avoid memory leaks,
532 file descriptor leaks, etc. */
533 sim_module_uninstall (sd
);
537 /* verify assumptions the simulator made about the host type system.
538 This macro does not return if there is a problem */
539 SIM_ASSERT (sizeof(int) == (4 * sizeof(char)));
540 SIM_ASSERT (sizeof(word64
) == (8 * sizeof(char)));
542 /* This is NASTY, in that we are assuming the size of specific
546 for (rn
= 0; (rn
< (LAST_EMBED_REGNUM
+ 1)); rn
++)
549 cpu
->register_widths
[rn
] = WITH_TARGET_WORD_BITSIZE
;
550 else if ((rn
>= FGRIDX
) && (rn
< (FGRIDX
+ NR_FGR
)))
551 cpu
->register_widths
[rn
] = WITH_TARGET_FLOATING_POINT_BITSIZE
;
552 else if ((rn
>= 33) && (rn
<= 37))
553 cpu
->register_widths
[rn
] = WITH_TARGET_WORD_BITSIZE
;
554 else if ((rn
== SRIDX
)
557 || ((rn
>= 72) && (rn
<= 89)))
558 cpu
->register_widths
[rn
] = 32;
560 cpu
->register_widths
[rn
] = 0;
562 /* start-sanitize-r5900 */
564 /* set the 5900 "upper" registers to 64 bits */
565 for( rn
= LAST_EMBED_REGNUM
+1; rn
< NUM_REGS
; rn
++)
566 cpu
->register_widths
[rn
] = 64;
567 /* end-sanitize-r5900 */
569 /* start-sanitize-sky */
571 /* Now the VU registers */
572 for( rn
= 0; rn
< NUM_VU_INTEGER_REGS
; rn
++ ) {
573 cpu
->register_widths
[rn
+ NUM_CORE_REGS
] = 16;
574 cpu
->register_widths
[rn
+ NUM_CORE_REGS
+ NUM_VU_REGS
] = 16;
577 for( rn
= NUM_VU_INTEGER_REGS
; rn
< NUM_VU_REGS
; rn
++ ) {
578 cpu
->register_widths
[rn
+ NUM_CORE_REGS
] = 32;
579 cpu
->register_widths
[rn
+ NUM_CORE_REGS
+ NUM_VU_REGS
] = 32;
582 /* Finally the VIF registers */
583 for( rn
= 2*NUM_VU_REGS
; rn
< 2*NUM_VU_REGS
+ 2*NUM_VIF_REGS
; rn
++ )
584 cpu
->register_widths
[rn
+ NUM_CORE_REGS
] = 32;
588 /* end-sanitize-sky */
592 if (STATE
& simTRACE
)
596 /* Write an abort sequence into the TRAP (common) exception vector
597 addresses. This is to catch code executing a TRAP (et.al.)
598 instruction without installing a trap handler. */
600 unsigned32 halt
[2] = { 0x2404002f /* addiu r4, r0, 47 */,
601 HALT_INSTRUCTION
/* BREAK */ };
604 sim_write (sd
, 0x80000180, (char *) halt
, sizeof (halt
));
605 sim_write (sd
, 0xBFC00380, (char *) halt
, sizeof (halt
));
609 /* Write the monitor trap address handlers into the monitor (eeprom)
610 address space. This can only be done once the target endianness
611 has been determined. */
614 /* Entry into the IDT monitor is via fixed address vectors, and
615 not using machine instructions. To avoid clashing with use of
616 the MIPS TRAP system, we place our own (simulator specific)
617 "undefined" instructions into the relevant vector slots. */
618 for (loop
= 0; (loop
< MONITOR_SIZE
); loop
+= 4)
620 address_word vaddr
= (MONITOR_BASE
+ loop
);
621 unsigned32 insn
= (RSVD_INSTRUCTION
| (((loop
>> 2) & RSVD_INSTRUCTION_ARG_MASK
) << RSVD_INSTRUCTION_ARG_SHIFT
));
623 sim_write (sd
, vaddr
, (char *)&insn
, sizeof (insn
));
625 /* The PMON monitor uses the same address space, but rather than
626 branching into it the address of a routine is loaded. We can
627 cheat for the moment, and direct the PMON routine to IDT style
628 instructions within the monitor space. This relies on the IDT
629 monitor not using the locations from 0xBFC00500 onwards as its
631 for (loop
= 0; (loop
< 24); loop
++)
633 address_word vaddr
= (MONITOR_BASE
+ 0x500 + (loop
* 4));
634 unsigned32 value
= ((0x500 - 8) / 8); /* default UNDEFINED reason code */
650 value
= ((0x500 - 16) / 8); /* not an IDT reason code */
652 case 8: /* cliexit */
655 case 11: /* flush_cache */
659 /* FIXME - should monitor_base be SIM_ADDR?? */
660 value
= ((unsigned int)MONITOR_BASE
+ (value
* 8));
662 sim_write (sd
, vaddr
, (char *)&value
, sizeof (value
));
664 /* The LSI MiniRISC PMON has its vectors at 0x200, not 0x500. */
666 sim_write (sd
, vaddr
, (char *)&value
, sizeof (value
));
678 tracefh
= fopen(tracefile
,"wb+");
681 sim_io_eprintf(sd
,"Failed to create file \"%s\", writing trace information to stderr.\n",tracefile
);
688 sim_close (sd
, quitting
)
693 printf("DBG: sim_close: entered (quitting = %d)\n",quitting
);
696 /* start-sanitize-sky */
698 sky_command_options_close (sd
);
700 /* end-sanitize-sky */
703 /* "quitting" is non-zero if we cannot hang on errors */
705 /* Ensure that any resources allocated through the callback
706 mechanism are released: */
707 sim_io_shutdown (sd
);
710 if (tracefh
!= NULL
&& tracefh
!= stderr
)
715 /* FIXME - free SD */
722 sim_write (sd
,addr
,buffer
,size
)
725 unsigned char *buffer
;
729 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
731 /* Return the number of bytes written, or zero if error. */
733 sim_io_printf(sd
,"sim_write(0x%s,buffer,%d);\n",pr_addr(addr
),size
);
736 /* We use raw read and write routines, since we do not want to count
737 the GDB memory accesses in our statistics gathering. */
739 for (index
= 0; index
< size
; index
++)
741 address_word vaddr
= (address_word
)addr
+ index
;
744 if (!address_translation (SD
, CPU
, NULL_CIA
, vaddr
, isDATA
, isSTORE
, &paddr
, &cca
, isRAW
))
746 if (sim_core_write_buffer (SD
, CPU
, read_map
, buffer
+ index
, paddr
, 1) != 1)
754 sim_read (sd
,addr
,buffer
,size
)
757 unsigned char *buffer
;
761 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
763 /* Return the number of bytes read, or zero if error. */
765 sim_io_printf(sd
,"sim_read(0x%s,buffer,%d);\n",pr_addr(addr
),size
);
768 for (index
= 0; (index
< size
); index
++)
770 address_word vaddr
= (address_word
)addr
+ index
;
773 if (!address_translation (SD
, CPU
, NULL_CIA
, vaddr
, isDATA
, isLOAD
, &paddr
, &cca
, isRAW
))
775 if (sim_core_read_buffer (SD
, CPU
, read_map
, buffer
+ index
, paddr
, 1) != 1)
783 sim_store_register (sd
,rn
,memory
,length
)
786 unsigned char *memory
;
789 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
790 /* NOTE: gdb (the client) stores registers in target byte order
791 while the simulator uses host byte order */
793 sim_io_printf(sd
,"sim_store_register(%d,*memory=0x%s);\n",rn
,pr_addr(*((SIM_ADDR
*)memory
)));
796 /* Unfortunately this suffers from the same problem as the register
797 numbering one. We need to know what the width of each logical
798 register number is for the architecture being simulated. */
800 if (cpu
->register_widths
[rn
] == 0)
802 sim_io_eprintf(sd
,"Invalid register width for %d (register store ignored)\n",rn
);
806 /* start-sanitize-r5900 */
807 if (rn
>= 90 && rn
< 90 + 32)
809 GPR1
[rn
- 90] = T2H_8 (*(unsigned64
*)memory
);
815 SA
= T2H_8(*(unsigned64
*)memory
);
817 case 122: /* FIXME */
818 LO1
= T2H_8(*(unsigned64
*)memory
);
820 case 123: /* FIXME */
821 HI1
= T2H_8(*(unsigned64
*)memory
);
824 /* end-sanitize-r5900 */
826 /* start-sanitize-sky */
828 if (rn
>= NUM_CORE_REGS
)
830 rn
= rn
- NUM_CORE_REGS
;
832 if( rn
< NUM_VU_REGS
)
834 if (rn
< NUM_VU_INTEGER_REGS
)
835 return write_vu_int_reg (&(vu0_device
.regs
), rn
, memory
);
836 else if (rn
>= FIRST_VEC_REG
)
839 return write_vu_vec_reg (&(vu0_device
.regs
), rn
>>2, rn
&3,
842 else switch (rn
- NUM_VU_INTEGER_REGS
)
845 return write_vu_special_reg (&vu0_device
, VU_REG_CIA
,
848 return write_vu_misc_reg (&(vu0_device
.regs
), VU_REG_MR
,
850 case 2: /* VU0 has no P register */
853 return write_vu_misc_reg (&(vu0_device
.regs
), VU_REG_MI
,
856 return write_vu_misc_reg (&(vu0_device
.regs
), VU_REG_MQ
,
859 return write_vu_acc_reg (&(vu0_device
.regs
),
860 rn
- (NUM_VU_INTEGER_REGS
+ 5),
865 rn
= rn
- NUM_VU_REGS
;
867 if (rn
< NUM_VU_REGS
)
869 if (rn
< NUM_VU_INTEGER_REGS
)
870 return write_vu_int_reg (&(vu1_device
.regs
), rn
, memory
);
871 else if (rn
>= FIRST_VEC_REG
)
874 return write_vu_vec_reg (&(vu1_device
.regs
),
875 rn
>> 2, rn
& 3, memory
);
877 else switch (rn
- NUM_VU_INTEGER_REGS
)
880 return write_vu_special_reg (&vu1_device
, VU_REG_CIA
,
883 return write_vu_misc_reg (&(vu1_device
.regs
), VU_REG_MR
,
886 return write_vu_misc_reg (&(vu1_device
.regs
), VU_REG_MP
,
889 return write_vu_misc_reg (&(vu1_device
.regs
), VU_REG_MI
,
892 return write_vu_misc_reg (&(vu1_device
.regs
), VU_REG_MQ
,
895 return write_vu_acc_reg (&(vu1_device
.regs
),
896 rn
- (NUM_VU_INTEGER_REGS
+ 5),
901 rn
-= NUM_VU_REGS
; /* VIF0 registers are next */
903 if (rn
< NUM_VIF_REGS
)
905 if (rn
< NUM_VIF_REGS
-1)
906 return write_pke_reg (&pke0_device
, rn
, memory
);
909 sim_io_eprintf( sd
, "Can't write vif0_pc (store ignored)\n" );
914 rn
-= NUM_VIF_REGS
; /* VIF1 registers are last */
916 if (rn
< NUM_VIF_REGS
)
918 if (rn
< NUM_VIF_REGS
-1)
919 return write_pke_reg (&pke1_device
, rn
, memory
);
922 sim_io_eprintf( sd
, "Can't write vif1_pc (store ignored)\n" );
927 sim_io_eprintf( sd
, "Invalid VU register (register store ignored)\n" );
931 /* end-sanitize-sky */
933 if (rn
>= FGRIDX
&& rn
< FGRIDX
+ NR_FGR
)
935 if (cpu
->register_widths
[rn
] == 32)
937 cpu
->fgr
[rn
- FGRIDX
] = T2H_4 (*(unsigned32
*)memory
);
942 cpu
->fgr
[rn
- FGRIDX
] = T2H_8 (*(unsigned64
*)memory
);
947 if (cpu
->register_widths
[rn
] == 32)
949 cpu
->registers
[rn
] = T2H_4 (*(unsigned32
*)memory
);
954 cpu
->registers
[rn
] = T2H_8 (*(unsigned64
*)memory
);
962 sim_fetch_register (sd
,rn
,memory
,length
)
965 unsigned char *memory
;
968 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
969 /* NOTE: gdb (the client) stores registers in target byte order
970 while the simulator uses host byte order */
972 sim_io_printf(sd
,"sim_fetch_register(%d=0x%s,mem) : place simulator registers into memory\n",rn
,pr_addr(registers
[rn
]));
975 if (cpu
->register_widths
[rn
] == 0)
977 sim_io_eprintf (sd
, "Invalid register width for %d (register fetch ignored)\n",rn
);
981 /* start-sanitize-r5900 */
982 if (rn
>= 90 && rn
< 90 + 32)
984 *((unsigned64
*)memory
) = H2T_8 (GPR1
[rn
- 90]);
990 *((unsigned64
*)memory
) = H2T_8(SA
);
992 case 122: /* FIXME */
993 *((unsigned64
*)memory
) = H2T_8(LO1
);
995 case 123: /* FIXME */
996 *((unsigned64
*)memory
) = H2T_8(HI1
);
999 /* end-sanitize-r5900 */
1001 /* start-sanitize-sky */
1003 if (rn
>= NUM_CORE_REGS
)
1005 rn
= rn
- NUM_CORE_REGS
;
1007 if (rn
< NUM_VU_REGS
)
1009 if (rn
< NUM_VU_INTEGER_REGS
)
1010 return read_vu_int_reg (&(vu0_device
.regs
), rn
, memory
);
1011 else if (rn
>= FIRST_VEC_REG
)
1013 rn
-= FIRST_VEC_REG
;
1014 return read_vu_vec_reg (&(vu0_device
.regs
), rn
>>2, rn
& 3,
1017 else switch (rn
- NUM_VU_INTEGER_REGS
)
1020 return read_vu_special_reg(&vu0_device
, VU_REG_CIA
, memory
);
1022 return read_vu_misc_reg (&(vu0_device
.regs
), VU_REG_MR
,
1024 case 2: /* VU0 has no P register */
1025 *((int *) memory
) = 0;
1028 return read_vu_misc_reg (&(vu0_device
.regs
), VU_REG_MI
,
1031 return read_vu_misc_reg (&(vu0_device
.regs
), VU_REG_MQ
,
1034 return read_vu_acc_reg (&(vu0_device
.regs
),
1035 rn
- (NUM_VU_INTEGER_REGS
+ 5),
1040 rn
-= NUM_VU_REGS
; /* VU1 registers are next */
1042 if (rn
< NUM_VU_REGS
)
1044 if (rn
< NUM_VU_INTEGER_REGS
)
1045 return read_vu_int_reg (&(vu1_device
.regs
), rn
, memory
);
1046 else if (rn
>= FIRST_VEC_REG
)
1048 rn
-= FIRST_VEC_REG
;
1049 return read_vu_vec_reg (&(vu1_device
.regs
),
1050 rn
>> 2, rn
& 3, memory
);
1052 else switch (rn
- NUM_VU_INTEGER_REGS
)
1055 return read_vu_special_reg(&vu1_device
, VU_REG_CIA
, memory
);
1057 return read_vu_misc_reg (&(vu1_device
.regs
),
1060 return read_vu_misc_reg (&(vu1_device
.regs
),
1063 return read_vu_misc_reg (&(vu1_device
.regs
),
1066 return read_vu_misc_reg (&(vu1_device
.regs
),
1069 return read_vu_acc_reg (&(vu1_device
.regs
),
1070 rn
- (NUM_VU_INTEGER_REGS
+ 5),
1075 rn
-= NUM_VU_REGS
; /* VIF0 registers are next */
1077 if (rn
< NUM_VIF_REGS
)
1079 if (rn
< NUM_VIF_REGS
-2)
1080 return read_pke_reg (&pke0_device
, rn
, memory
);
1081 else if (rn
== NUM_VIF_REGS
-2)
1082 return read_pke_pc (&pke0_device
, memory
);
1084 return read_pke_pcx (&pke0_device
, memory
);
1087 rn
-= NUM_VIF_REGS
; /* VIF1 registers are last */
1089 if (rn
< NUM_VIF_REGS
)
1091 if (rn
< NUM_VIF_REGS
-2)
1092 return read_pke_reg (&pke1_device
, rn
, memory
);
1093 else if (rn
== NUM_VIF_REGS
-2)
1094 return read_pke_pc (&pke1_device
, memory
);
1096 return read_pke_pcx (&pke1_device
, memory
);
1099 sim_io_eprintf( sd
, "Invalid VU register (register fetch ignored)\n" );
1102 /* end-sanitize-sky */
1104 /* Any floating point register */
1105 if (rn
>= FGRIDX
&& rn
< FGRIDX
+ NR_FGR
)
1107 if (cpu
->register_widths
[rn
] == 32)
1109 *(unsigned32
*)memory
= H2T_4 (cpu
->fgr
[rn
- FGRIDX
]);
1114 *(unsigned64
*)memory
= H2T_8 (cpu
->fgr
[rn
- FGRIDX
]);
1119 if (cpu
->register_widths
[rn
] == 32)
1121 *(unsigned32
*)memory
= H2T_4 ((unsigned32
)(cpu
->registers
[rn
]));
1126 *(unsigned64
*)memory
= H2T_8 ((unsigned64
)(cpu
->registers
[rn
]));
1135 sim_create_inferior (sd
, abfd
, argv
,env
)
1143 printf("DBG: sim_create_inferior entered: start_address = 0x%s\n",
1151 /* override PC value set by ColdReset () */
1153 for (cpu_nr
= 0; cpu_nr
< sim_engine_nr_cpus (sd
); cpu_nr
++)
1155 sim_cpu
*cpu
= STATE_CPU (sd
, cpu_nr
);
1156 CIA_SET (cpu
, (unsigned64
) bfd_get_start_address (abfd
));
1160 #if 0 /* def DEBUG */
1163 /* We should really place the argv slot values into the argument
1164 registers, and onto the stack as required. However, this
1165 assumes that we have a stack defined, which is not
1166 necessarily true at the moment. */
1168 sim_io_printf(sd
,"sim_create_inferior() : passed arguments ignored\n");
1169 for (cptr
= argv
; (cptr
&& *cptr
); cptr
++)
1170 printf("DBG: arg \"%s\"\n",*cptr
);
1178 sim_do_command (sd
,cmd
)
1182 if (sim_args_command (sd
, cmd
) != SIM_RC_OK
)
1183 sim_io_printf (sd
, "Error: \"%s\" is not a valid MIPS simulator command.\n",
1187 /*---------------------------------------------------------------------------*/
1188 /*-- Private simulator support interface ------------------------------------*/
1189 /*---------------------------------------------------------------------------*/
1191 /* Read a null terminated string from memory, return in a buffer */
1193 fetch_str (sd
, addr
)
1200 while (sim_read (sd
, addr
+ nr
, &null
, 1) == 1 && null
!= 0)
1202 buf
= NZALLOC (char, nr
+ 1);
1203 sim_read (sd
, addr
, buf
, nr
);
1207 /* Simple monitor interface (currently setup for the IDT and PMON monitors) */
1209 sim_monitor (SIM_DESC sd
,
1212 unsigned int reason
)
1215 printf("DBG: sim_monitor: entered (reason = %d)\n",reason
);
1218 /* The IDT monitor actually allows two instructions per vector
1219 slot. However, the simulator currently causes a trap on each
1220 individual instruction. We cheat, and lose the bottom bit. */
1223 /* The following callback functions are available, however the
1224 monitor we are simulating does not make use of them: get_errno,
1225 isatty, lseek, rename, system, time and unlink */
1229 case 6: /* int open(char *path,int flags) */
1231 char *path
= fetch_str (sd
, A0
);
1232 V0
= sim_io_open (sd
, path
, (int)A1
);
1237 case 7: /* int read(int file,char *ptr,int len) */
1241 char *buf
= zalloc (nr
);
1242 V0
= sim_io_read (sd
, fd
, buf
, nr
);
1243 sim_write (sd
, A1
, buf
, nr
);
1248 case 8: /* int write(int file,char *ptr,int len) */
1252 char *buf
= zalloc (nr
);
1253 sim_read (sd
, A1
, buf
, nr
);
1254 V0
= sim_io_write (sd
, fd
, buf
, nr
);
1259 case 10: /* int close(int file) */
1261 V0
= sim_io_close (sd
, (int)A0
);
1265 case 2: /* Densan monitor: char inbyte(int waitflag) */
1267 if (A0
== 0) /* waitflag == NOWAIT */
1268 V0
= (unsigned_word
)-1;
1270 /* Drop through to case 11 */
1272 case 11: /* char inbyte(void) */
1275 if (sim_io_read_stdin (sd
, &tmp
, sizeof(char)) != sizeof(char))
1277 sim_io_error(sd
,"Invalid return from character read");
1278 V0
= (unsigned_word
)-1;
1281 V0
= (unsigned_word
)tmp
;
1285 case 3: /* Densan monitor: void co(char chr) */
1286 case 12: /* void outbyte(char chr) : write a byte to "stdout" */
1288 char tmp
= (char)(A0
& 0xFF);
1289 sim_io_write_stdout (sd
, &tmp
, sizeof(char));
1293 case 17: /* void _exit() */
1295 sim_io_eprintf (sd
, "sim_monitor(17): _exit(int reason) to be coded\n");
1296 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
, sim_exited
,
1297 (unsigned int)(A0
& 0xFFFFFFFF));
1301 case 28 : /* PMON flush_cache */
1304 case 55: /* void get_mem_info(unsigned int *ptr) */
1305 /* in: A0 = pointer to three word memory location */
1306 /* out: [A0 + 0] = size */
1307 /* [A0 + 4] = instruction cache size */
1308 /* [A0 + 8] = data cache size */
1310 unsigned_4 value
= MEM_SIZE
/* FIXME STATE_MEM_SIZE (sd) */;
1311 unsigned_4 zero
= 0;
1313 sim_write (sd
, A0
+ 0, (char *)&value
, 4);
1314 sim_write (sd
, A0
+ 4, (char *)&zero
, 4);
1315 sim_write (sd
, A0
+ 8, (char *)&zero
, 4);
1316 /* sim_io_eprintf (sd, "sim: get_mem_info() depreciated\n"); */
1320 case 158 : /* PMON printf */
1321 /* in: A0 = pointer to format string */
1322 /* A1 = optional argument 1 */
1323 /* A2 = optional argument 2 */
1324 /* A3 = optional argument 3 */
1326 /* The following is based on the PMON printf source */
1328 address_word s
= A0
;
1330 signed_word
*ap
= &A1
; /* 1st argument */
1331 /* This isn't the quickest way, since we call the host print
1332 routine for every character almost. But it does avoid
1333 having to allocate and manage a temporary string buffer. */
1334 /* TODO: Include check that we only use three arguments (A1,
1336 while (sim_read (sd
, s
++, &c
, 1) && c
!= '\0')
1341 enum {FMT_RJUST
, FMT_LJUST
, FMT_RJUST0
, FMT_CENTER
} fmt
= FMT_RJUST
;
1342 int width
= 0, trunc
= 0, haddot
= 0, longlong
= 0;
1343 while (sim_read (sd
, s
++, &c
, 1) && c
!= '\0')
1345 if (strchr ("dobxXulscefg%", c
))
1360 else if (c
>= '1' && c
<= '9')
1364 while (sim_read (sd
, s
++, &c
, 1) == 1 && isdigit (c
))
1367 n
= (unsigned int)strtol(tmp
,NULL
,10);
1380 sim_io_printf (sd
, "%%");
1385 address_word p
= *ap
++;
1387 while (sim_read (sd
, p
++, &ch
, 1) == 1 && ch
!= '\0')
1388 sim_io_printf(sd
, "%c", ch
);
1391 sim_io_printf(sd
,"(null)");
1394 sim_io_printf (sd
, "%c", (int)*ap
++);
1399 sim_read (sd
, s
++, &c
, 1);
1403 sim_read (sd
, s
++, &c
, 1);
1406 if (strchr ("dobxXu", c
))
1408 word64 lv
= (word64
) *ap
++;
1410 sim_io_printf(sd
,"<binary not supported>");
1413 sprintf (tmp
, "%%%s%c", longlong
? "ll" : "", c
);
1415 sim_io_printf(sd
, tmp
, lv
);
1417 sim_io_printf(sd
, tmp
, (int)lv
);
1420 else if (strchr ("eEfgG", c
))
1422 double dbl
= *(double*)(ap
++);
1423 sprintf (tmp
, "%%%d.%d%c", width
, trunc
, c
);
1424 sim_io_printf (sd
, tmp
, dbl
);
1430 sim_io_printf(sd
, "%c", c
);
1436 sim_io_error (sd
, "TODO: sim_monitor(%d) : PC = 0x%s\n",
1437 reason
, pr_addr(cia
));
1443 /* Store a word into memory. */
1446 store_word (SIM_DESC sd
,
1455 if ((vaddr
& 3) != 0)
1456 SignalExceptionAddressStore ();
1459 if (AddressTranslation (vaddr
, isDATA
, isSTORE
, &paddr
, &uncached
,
1462 const uword64 mask
= 7;
1466 paddr
= (paddr
& ~mask
) | ((paddr
& mask
) ^ (ReverseEndian
<< 2));
1467 byte
= (vaddr
& mask
) ^ (BigEndianCPU
<< 2);
1468 memval
= ((uword64
) val
) << (8 * byte
);
1469 StoreMemory (uncached
, AccessLength_WORD
, memval
, 0, paddr
, vaddr
,
1475 /* Load a word from memory. */
1478 load_word (SIM_DESC sd
,
1483 if ((vaddr
& 3) != 0)
1484 SignalExceptionAddressLoad ();
1490 if (AddressTranslation (vaddr
, isDATA
, isLOAD
, &paddr
, &uncached
,
1493 const uword64 mask
= 0x7;
1494 const unsigned int reverse
= ReverseEndian
? 1 : 0;
1495 const unsigned int bigend
= BigEndianCPU
? 1 : 0;
1499 paddr
= (paddr
& ~mask
) | ((paddr
& mask
) ^ (reverse
<< 2));
1500 LoadMemory (&memval
,NULL
,uncached
, AccessLength_WORD
, paddr
, vaddr
,
1502 byte
= (vaddr
& mask
) ^ (bigend
<< 2);
1503 return SIGNEXTEND (((memval
>> (8 * byte
)) & 0xffffffff), 32);
1510 /* Simulate the mips16 entry and exit pseudo-instructions. These
1511 would normally be handled by the reserved instruction exception
1512 code, but for ease of simulation we just handle them directly. */
1515 mips16_entry (SIM_DESC sd
,
1520 int aregs
, sregs
, rreg
;
1523 printf("DBG: mips16_entry: entered (insn = 0x%08X)\n",insn
);
1526 aregs
= (insn
& 0x700) >> 8;
1527 sregs
= (insn
& 0x0c0) >> 6;
1528 rreg
= (insn
& 0x020) >> 5;
1530 /* This should be checked by the caller. */
1539 /* This is the entry pseudo-instruction. */
1541 for (i
= 0; i
< aregs
; i
++)
1542 store_word (SD
, CPU
, cia
, (uword64
) (SP
+ 4 * i
), GPR
[i
+ 4]);
1550 store_word (SD
, CPU
, cia
, (uword64
) tsp
, RA
);
1553 for (i
= 0; i
< sregs
; i
++)
1556 store_word (SD
, CPU
, cia
, (uword64
) tsp
, GPR
[16 + i
]);
1564 /* This is the exit pseudo-instruction. */
1571 RA
= load_word (SD
, CPU
, cia
, (uword64
) tsp
);
1574 for (i
= 0; i
< sregs
; i
++)
1577 GPR
[i
+ 16] = load_word (SD
, CPU
, cia
, (uword64
) tsp
);
1582 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
1586 FGR
[0] = WORD64LO (GPR
[4]);
1587 FPR_STATE
[0] = fmt_uninterpreted
;
1589 else if (aregs
== 6)
1591 FGR
[0] = WORD64LO (GPR
[5]);
1592 FGR
[1] = WORD64LO (GPR
[4]);
1593 FPR_STATE
[0] = fmt_uninterpreted
;
1594 FPR_STATE
[1] = fmt_uninterpreted
;
1603 /*-- trace support ----------------------------------------------------------*/
1605 /* The TRACE support is provided (if required) in the memory accessing
1606 routines. Since we are also providing the architecture specific
1607 features, the architecture simulation code can also deal with
1608 notifying the TRACE world of cache flushes, etc. Similarly we do
1609 not need to provide profiling support in the simulator engine,
1610 since we can sample in the instruction fetch control loop. By
1611 defining the TRACE manifest, we add tracing as a run-time
1615 /* Tracing by default produces "din" format (as required by
1616 dineroIII). Each line of such a trace file *MUST* have a din label
1617 and address field. The rest of the line is ignored, so comments can
1618 be included if desired. The first field is the label which must be
1619 one of the following values:
1624 3 escape record (treated as unknown access type)
1625 4 escape record (causes cache flush)
1627 The address field is a 32bit (lower-case) hexadecimal address
1628 value. The address should *NOT* be preceded by "0x".
1630 The size of the memory transfer is not important when dealing with
1631 cache lines (as long as no more than a cache line can be
1632 transferred in a single operation :-), however more information
1633 could be given following the dineroIII requirement to allow more
1634 complete memory and cache simulators to provide better
1635 results. i.e. the University of Pisa has a cache simulator that can
1636 also take bus size and speed as (variable) inputs to calculate
1637 complete system performance (a much more useful ability when trying
1638 to construct an end product, rather than a processor). They
1639 currently have an ARM version of their tool called ChARM. */
1643 dotrace (SIM_DESC sd
,
1651 if (STATE
& simTRACE
) {
1653 fprintf(tracefh
,"%d %s ; width %d ; ",
1657 va_start(ap
,comment
);
1658 vfprintf(tracefh
,comment
,ap
);
1660 fprintf(tracefh
,"\n");
1662 /* NOTE: Since the "din" format will only accept 32bit addresses, and
1663 we may be generating 64bit ones, we should put the hi-32bits of the
1664 address into the comment field. */
1666 /* TODO: Provide a buffer for the trace lines. We can then avoid
1667 performing writes until the buffer is filled, or the file is
1670 /* NOTE: We could consider adding a comment field to the "din" file
1671 produced using type 3 markers (unknown access). This would then
1672 allow information about the program that the "din" is for, and
1673 the MIPs world that was being simulated, to be placed into the
1680 /*---------------------------------------------------------------------------*/
1681 /*-- simulator engine -------------------------------------------------------*/
1682 /*---------------------------------------------------------------------------*/
1685 ColdReset (SIM_DESC sd
)
1688 for (cpu_nr
= 0; cpu_nr
< sim_engine_nr_cpus (sd
); cpu_nr
++)
1690 sim_cpu
*cpu
= STATE_CPU (sd
, cpu_nr
);
1691 /* RESET: Fixed PC address: */
1692 PC
= (unsigned_word
) UNSIGNED64 (0xFFFFFFFFBFC00000);
1693 /* The reset vector address is in the unmapped, uncached memory space. */
1695 SR
&= ~(status_SR
| status_TS
| status_RP
);
1696 SR
|= (status_ERL
| status_BEV
);
1698 /* Cheat and allow access to the complete register set immediately */
1699 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
1700 && WITH_TARGET_WORD_BITSIZE
== 64)
1701 SR
|= status_FR
; /* 64bit registers */
1703 /* Ensure that any instructions with pending register updates are
1705 PENDING_INVALIDATE();
1707 /* Initialise the FPU registers to the unknown state */
1708 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
1711 for (rn
= 0; (rn
< 32); rn
++)
1712 FPR_STATE
[rn
] = fmt_uninterpreted
;
1718 /* Description from page A-26 of the "MIPS IV Instruction Set" manual (revision 3.1) */
1719 /* Signal an exception condition. This will result in an exception
1720 that aborts the instruction. The instruction operation pseudocode
1721 will never see a return from this function call. */
1724 signal_exception (SIM_DESC sd
,
1732 sim_io_printf(sd
,"DBG: SignalException(%d) PC = 0x%s\n",exception
,pr_addr(cia
));
1735 /* Ensure that any active atomic read/modify/write operation will fail: */
1738 switch (exception
) {
1740 case DebugBreakPoint
:
1741 if (! (Debug
& Debug_DM
))
1747 Debug
|= Debug_DBD
; /* signaled from within in delay slot */
1748 DEPC
= cia
- 4; /* reference the branch instruction */
1752 Debug
&= ~Debug_DBD
; /* not signaled from within a delay slot */
1756 Debug
|= Debug_DM
; /* in debugging mode */
1757 Debug
|= Debug_DBp
; /* raising a DBp exception */
1759 sim_engine_restart (SD
, CPU
, NULL
, NULL_CIA
);
1763 case ReservedInstruction
:
1766 unsigned int instruction
;
1767 va_start(ap
,exception
);
1768 instruction
= va_arg(ap
,unsigned int);
1770 /* Provide simple monitor support using ReservedInstruction
1771 exceptions. The following code simulates the fixed vector
1772 entry points into the IDT monitor by causing a simulator
1773 trap, performing the monitor operation, and returning to
1774 the address held in the $ra register (standard PCS return
1775 address). This means we only need to pre-load the vector
1776 space with suitable instruction values. For systems were
1777 actual trap instructions are used, we would not need to
1778 perform this magic. */
1779 if ((instruction
& RSVD_INSTRUCTION_MASK
) == RSVD_INSTRUCTION
)
1781 sim_monitor (SD
, CPU
, cia
, ((instruction
>> RSVD_INSTRUCTION_ARG_SHIFT
) & RSVD_INSTRUCTION_ARG_MASK
) );
1782 /* NOTE: This assumes that a branch-and-link style
1783 instruction was used to enter the vector (which is the
1784 case with the current IDT monitor). */
1785 sim_engine_restart (SD
, CPU
, NULL
, RA
);
1787 /* Look for the mips16 entry and exit instructions, and
1788 simulate a handler for them. */
1789 else if ((cia
& 1) != 0
1790 && (instruction
& 0xf81f) == 0xe809
1791 && (instruction
& 0x0c0) != 0x0c0)
1793 mips16_entry (SD
, CPU
, cia
, instruction
);
1794 sim_engine_restart (sd
, NULL
, NULL
, NULL_CIA
);
1796 /* else fall through to normal exception processing */
1797 sim_io_eprintf(sd
,"ReservedInstruction at PC = 0x%s\n", pr_addr (cia
));
1801 /* Store exception code into current exception id variable (used
1804 /* TODO: If not simulating exceptions then stop the simulator
1805 execution. At the moment we always stop the simulation. */
1807 #ifdef SUBTARGET_R3900
1808 /* update interrupt-related registers */
1810 /* insert exception code in bits 6:2 */
1811 CAUSE
= LSMASKED32(CAUSE
, 31, 7) | LSINSERTED32(exception
, 6, 2);
1812 /* shift IE/KU history bits left */
1813 SR
= LSMASKED32(SR
, 31, 4) | LSINSERTED32(LSEXTRACTED32(SR
, 3, 0), 5, 2);
1815 if (STATE
& simDELAYSLOT
)
1817 STATE
&= ~simDELAYSLOT
;
1819 EPC
= (cia
- 4); /* reference the branch instruction */
1824 if (SR
& status_BEV
)
1825 PC
= (signed)0xBFC00000 + 0x180;
1827 PC
= (signed)0x80000000 + 0x080;
1829 /* See figure 5-17 for an outline of the code below */
1830 if (! (SR
& status_EXL
))
1832 CAUSE
= (exception
<< 2);
1833 if (STATE
& simDELAYSLOT
)
1835 STATE
&= ~simDELAYSLOT
;
1837 EPC
= (cia
- 4); /* reference the branch instruction */
1841 /* FIXME: TLB et.al. */
1842 /* vector = 0x180; */
1846 CAUSE
= (exception
<< 2);
1847 /* vector = 0x180; */
1850 /* Store exception code into current exception id variable (used
1853 if (SR
& status_BEV
)
1854 PC
= (signed)0xBFC00200 + 0x180;
1856 PC
= (signed)0x80000000 + 0x180;
1859 switch ((CAUSE
>> 2) & 0x1F)
1862 /* Interrupts arrive during event processing, no need to
1868 #ifdef SUBTARGET_3900
1869 /* Exception vector: BEV=0 BFC00000 / BEF=1 BFC00000 */
1870 PC
= (signed)0xBFC00000;
1871 #endif SUBTARGET_3900
1874 case TLBModification
:
1879 case InstructionFetch
:
1881 /* The following is so that the simulator will continue from the
1882 exception address on breakpoint operations. */
1884 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
,
1885 sim_stopped
, SIM_SIGBUS
);
1887 case ReservedInstruction
:
1888 case CoProcessorUnusable
:
1890 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
,
1891 sim_stopped
, SIM_SIGILL
);
1893 case IntegerOverflow
:
1895 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
,
1896 sim_stopped
, SIM_SIGFPE
);
1901 sim_engine_restart (SD
, CPU
, NULL
, PC
);
1906 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
,
1907 sim_stopped
, SIM_SIGTRAP
);
1909 default : /* Unknown internal exception */
1911 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
,
1912 sim_stopped
, SIM_SIGABRT
);
1916 case SimulatorFault
:
1920 va_start(ap
,exception
);
1921 msg
= va_arg(ap
,char *);
1923 sim_engine_abort (SD
, CPU
, NULL_CIA
,
1924 "FATAL: Simulator error \"%s\"\n",msg
);
1931 #if defined(WARN_RESULT)
1932 /* Description from page A-26 of the "MIPS IV Instruction Set" manual (revision 3.1) */
1933 /* This function indicates that the result of the operation is
1934 undefined. However, this should not affect the instruction
1935 stream. All that is meant to happen is that the destination
1936 register is set to an undefined result. To keep the simulator
1937 simple, we just don't bother updating the destination register, so
1938 the overall result will be undefined. If desired we can stop the
1939 simulator by raising a pseudo-exception. */
1940 #define UndefinedResult() undefined_result (sd,cia)
1942 undefined_result(sd
,cia
)
1946 sim_io_eprintf(sd
,"UndefinedResult: PC = 0x%s\n",pr_addr(cia
));
1947 #if 0 /* Disabled for the moment, since it actually happens a lot at the moment. */
1952 #endif /* WARN_RESULT */
1954 /*-- FPU support routines ---------------------------------------------------*/
1956 /* Numbers are held in normalized form. The SINGLE and DOUBLE binary
1957 formats conform to ANSI/IEEE Std 754-1985. */
1958 /* SINGLE precision floating:
1959 * seeeeeeeefffffffffffffffffffffff
1961 * e = 8bits = exponent
1962 * f = 23bits = fraction
1964 /* SINGLE precision fixed:
1965 * siiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
1967 * i = 31bits = integer
1969 /* DOUBLE precision floating:
1970 * seeeeeeeeeeeffffffffffffffffffffffffffffffffffffffffffffffffffff
1972 * e = 11bits = exponent
1973 * f = 52bits = fraction
1975 /* DOUBLE precision fixed:
1976 * siiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
1978 * i = 63bits = integer
1981 /* Extract sign-bit: */
1982 #define FP_S_s(v) (((v) & ((unsigned)1 << 31)) ? 1 : 0)
1983 #define FP_D_s(v) (((v) & ((uword64)1 << 63)) ? 1 : 0)
1984 /* Extract biased exponent: */
1985 #define FP_S_be(v) (((v) >> 23) & 0xFF)
1986 #define FP_D_be(v) (((v) >> 52) & 0x7FF)
1987 /* Extract unbiased Exponent: */
1988 #define FP_S_e(v) (FP_S_be(v) - 0x7F)
1989 #define FP_D_e(v) (FP_D_be(v) - 0x3FF)
1990 /* Extract complete fraction field: */
1991 #define FP_S_f(v) ((v) & ~((unsigned)0x1FF << 23))
1992 #define FP_D_f(v) ((v) & ~((uword64)0xFFF << 52))
1993 /* Extract numbered fraction bit: */
1994 #define FP_S_fb(b,v) (((v) & (1 << (23 - (b)))) ? 1 : 0)
1995 #define FP_D_fb(b,v) (((v) & (1 << (52 - (b)))) ? 1 : 0)
1997 /* Explicit QNaN values used when value required: */
1998 #define FPQNaN_SINGLE (0x7FBFFFFF)
1999 #define FPQNaN_WORD (0x7FFFFFFF)
2000 #define FPQNaN_DOUBLE (((uword64)0x7FF7FFFF << 32) | 0xFFFFFFFF)
2001 #define FPQNaN_LONG (((uword64)0x7FFFFFFF << 32) | 0xFFFFFFFF)
2003 /* Explicit Infinity values used when required: */
2004 #define FPINF_SINGLE (0x7F800000)
2005 #define FPINF_DOUBLE (((uword64)0x7FF00000 << 32) | 0x00000000)
2007 #if 1 /* def DEBUG */
2008 #define RMMODE(v) (((v) == FP_RM_NEAREST) ? "Round" : (((v) == FP_RM_TOZERO) ? "Trunc" : (((v) == FP_RM_TOPINF) ? "Ceil" : "Floor")))
2009 #define DOFMT(v) (((v) == fmt_single) ? "single" : (((v) == fmt_double) ? "double" : (((v) == fmt_word) ? "word" : (((v) == fmt_long) ? "long" : (((v) == fmt_unknown) ? "<unknown>" : (((v) == fmt_uninterpreted) ? "<uninterpreted>" : "<format error>"))))))
2013 value_fpr (SIM_DESC sd
,
2022 /* Treat unused register values, as fixed-point 64bit values: */
2023 if ((fmt
== fmt_uninterpreted
) || (fmt
== fmt_unknown
))
2025 /* If request to read data as "uninterpreted", then use the current
2027 fmt
= FPR_STATE
[fpr
];
2032 /* For values not yet accessed, set to the desired format: */
2033 if (FPR_STATE
[fpr
] == fmt_uninterpreted
) {
2034 FPR_STATE
[fpr
] = fmt
;
2036 printf("DBG: Register %d was fmt_uninterpreted. Now %s\n",fpr
,DOFMT(fmt
));
2039 if (fmt
!= FPR_STATE
[fpr
]) {
2040 sim_io_eprintf(sd
,"FPR %d (format %s) being accessed with format %s - setting to unknown (PC = 0x%s)\n",fpr
,DOFMT(FPR_STATE
[fpr
]),DOFMT(fmt
),pr_addr(cia
));
2041 FPR_STATE
[fpr
] = fmt_unknown
;
2044 if (FPR_STATE
[fpr
] == fmt_unknown
) {
2045 /* Set QNaN value: */
2048 value
= FPQNaN_SINGLE
;
2052 value
= FPQNaN_DOUBLE
;
2056 value
= FPQNaN_WORD
;
2060 value
= FPQNaN_LONG
;
2067 } else if (SizeFGR() == 64) {
2071 value
= (FGR
[fpr
] & 0xFFFFFFFF);
2074 case fmt_uninterpreted
:
2088 value
= (FGR
[fpr
] & 0xFFFFFFFF);
2091 case fmt_uninterpreted
:
2094 if ((fpr
& 1) == 0) { /* even registers only */
2095 value
= ((((uword64
)FGR
[fpr
+1]) << 32) | (FGR
[fpr
] & 0xFFFFFFFF));
2097 SignalException(ReservedInstruction
,0);
2108 SignalExceptionSimulatorFault ("Unrecognised FP format in ValueFPR()");
2111 printf("DBG: ValueFPR: fpr = %d, fmt = %s, value = 0x%s : PC = 0x%s : SizeFGR() = %d\n",fpr
,DOFMT(fmt
),pr_addr(value
),pr_addr(cia
),SizeFGR());
2118 store_fpr (SIM_DESC sd
,
2128 printf("DBG: StoreFPR: fpr = %d, fmt = %s, value = 0x%s : PC = 0x%s : SizeFGR() = %d\n",fpr
,DOFMT(fmt
),pr_addr(value
),pr_addr(cia
),SizeFGR());
2131 if (SizeFGR() == 64) {
2133 case fmt_uninterpreted_32
:
2134 fmt
= fmt_uninterpreted
;
2137 FGR
[fpr
] = (((uword64
)0xDEADC0DE << 32) | (value
& 0xFFFFFFFF));
2138 FPR_STATE
[fpr
] = fmt
;
2141 case fmt_uninterpreted_64
:
2142 fmt
= fmt_uninterpreted
;
2143 case fmt_uninterpreted
:
2147 FPR_STATE
[fpr
] = fmt
;
2151 FPR_STATE
[fpr
] = fmt_unknown
;
2157 case fmt_uninterpreted_32
:
2158 fmt
= fmt_uninterpreted
;
2161 FGR
[fpr
] = (value
& 0xFFFFFFFF);
2162 FPR_STATE
[fpr
] = fmt
;
2165 case fmt_uninterpreted_64
:
2166 fmt
= fmt_uninterpreted
;
2167 case fmt_uninterpreted
:
2170 if ((fpr
& 1) == 0) { /* even register number only */
2171 FGR
[fpr
+1] = (value
>> 32);
2172 FGR
[fpr
] = (value
& 0xFFFFFFFF);
2173 FPR_STATE
[fpr
+ 1] = fmt
;
2174 FPR_STATE
[fpr
] = fmt
;
2176 FPR_STATE
[fpr
] = fmt_unknown
;
2177 FPR_STATE
[fpr
+ 1] = fmt_unknown
;
2178 SignalException(ReservedInstruction
,0);
2183 FPR_STATE
[fpr
] = fmt_unknown
;
2188 #if defined(WARN_RESULT)
2191 #endif /* WARN_RESULT */
2194 SignalExceptionSimulatorFault ("Unrecognised FP format in StoreFPR()");
2197 printf("DBG: StoreFPR: fpr[%d] = 0x%s (format %s)\n",fpr
,pr_addr(FGR
[fpr
]),DOFMT(fmt
));
2214 sim_fpu_32to (&wop
, op
);
2215 boolean
= sim_fpu_is_nan (&wop
);
2222 sim_fpu_64to (&wop
, op
);
2223 boolean
= sim_fpu_is_nan (&wop
);
2227 fprintf (stderr
, "Bad switch\n");
2232 printf("DBG: NaN: returning %d for 0x%s (format = %s)\n",boolean
,pr_addr(op
),DOFMT(fmt
));
2246 printf("DBG: Infinity: format %s 0x%s\n",DOFMT(fmt
),pr_addr(op
));
2253 sim_fpu_32to (&wop
, op
);
2254 boolean
= sim_fpu_is_infinity (&wop
);
2260 sim_fpu_64to (&wop
, op
);
2261 boolean
= sim_fpu_is_infinity (&wop
);
2265 printf("DBG: TODO: unrecognised format (%s) for Infinity check\n",DOFMT(fmt
));
2270 printf("DBG: Infinity: returning %d for 0x%s (format = %s)\n",boolean
,pr_addr(op
),DOFMT(fmt
));
2284 /* Argument checking already performed by the FPCOMPARE code */
2287 printf("DBG: Less: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2290 /* The format type should already have been checked: */
2296 sim_fpu_32to (&wop1
, op1
);
2297 sim_fpu_32to (&wop2
, op2
);
2298 boolean
= sim_fpu_is_lt (&wop1
, &wop2
);
2305 sim_fpu_64to (&wop1
, op1
);
2306 sim_fpu_64to (&wop2
, op2
);
2307 boolean
= sim_fpu_is_lt (&wop1
, &wop2
);
2311 fprintf (stderr
, "Bad switch\n");
2316 printf("DBG: Less: returning %d (format = %s)\n",boolean
,DOFMT(fmt
));
2330 /* Argument checking already performed by the FPCOMPARE code */
2333 printf("DBG: Equal: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2336 /* The format type should already have been checked: */
2342 sim_fpu_32to (&wop1
, op1
);
2343 sim_fpu_32to (&wop2
, op2
);
2344 boolean
= sim_fpu_is_eq (&wop1
, &wop2
);
2351 sim_fpu_64to (&wop1
, op1
);
2352 sim_fpu_64to (&wop2
, op2
);
2353 boolean
= sim_fpu_is_eq (&wop1
, &wop2
);
2357 fprintf (stderr
, "Bad switch\n");
2362 printf("DBG: Equal: returning %d (format = %s)\n",boolean
,DOFMT(fmt
));
2369 AbsoluteValue(op
,fmt
)
2376 printf("DBG: AbsoluteValue: %s: op = 0x%s\n",DOFMT(fmt
),pr_addr(op
));
2379 /* The format type should already have been checked: */
2385 sim_fpu_32to (&wop
, op
);
2386 sim_fpu_abs (&wop
, &wop
);
2387 sim_fpu_to32 (&ans
, &wop
);
2395 sim_fpu_64to (&wop
, op
);
2396 sim_fpu_abs (&wop
, &wop
);
2397 sim_fpu_to64 (&ans
, &wop
);
2402 fprintf (stderr
, "Bad switch\n");
2417 printf("DBG: Negate: %s: op = 0x%s\n",DOFMT(fmt
),pr_addr(op
));
2420 /* The format type should already have been checked: */
2426 sim_fpu_32to (&wop
, op
);
2427 sim_fpu_neg (&wop
, &wop
);
2428 sim_fpu_to32 (&ans
, &wop
);
2436 sim_fpu_64to (&wop
, op
);
2437 sim_fpu_neg (&wop
, &wop
);
2438 sim_fpu_to64 (&ans
, &wop
);
2443 fprintf (stderr
, "Bad switch\n");
2459 printf("DBG: Add: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2462 /* The registers must specify FPRs valid for operands of type
2463 "fmt". If they are not valid, the result is undefined. */
2465 /* The format type should already have been checked: */
2473 sim_fpu_32to (&wop1
, op1
);
2474 sim_fpu_32to (&wop2
, op2
);
2475 sim_fpu_add (&ans
, &wop1
, &wop2
);
2476 sim_fpu_to32 (&res
, &ans
);
2486 sim_fpu_64to (&wop1
, op1
);
2487 sim_fpu_64to (&wop2
, op2
);
2488 sim_fpu_add (&ans
, &wop1
, &wop2
);
2489 sim_fpu_to64 (&res
, &ans
);
2494 fprintf (stderr
, "Bad switch\n");
2499 printf("DBG: Add: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2514 printf("DBG: Sub: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2517 /* The registers must specify FPRs valid for operands of type
2518 "fmt". If they are not valid, the result is undefined. */
2520 /* The format type should already have been checked: */
2528 sim_fpu_32to (&wop1
, op1
);
2529 sim_fpu_32to (&wop2
, op2
);
2530 sim_fpu_sub (&ans
, &wop1
, &wop2
);
2531 sim_fpu_to32 (&res
, &ans
);
2541 sim_fpu_64to (&wop1
, op1
);
2542 sim_fpu_64to (&wop2
, op2
);
2543 sim_fpu_sub (&ans
, &wop1
, &wop2
);
2544 sim_fpu_to64 (&res
, &ans
);
2549 fprintf (stderr
, "Bad switch\n");
2554 printf("DBG: Sub: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2561 Multiply(op1
,op2
,fmt
)
2569 printf("DBG: Multiply: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2572 /* The registers must specify FPRs valid for operands of type
2573 "fmt". If they are not valid, the result is undefined. */
2575 /* The format type should already have been checked: */
2583 sim_fpu_32to (&wop1
, op1
);
2584 sim_fpu_32to (&wop2
, op2
);
2585 sim_fpu_mul (&ans
, &wop1
, &wop2
);
2586 sim_fpu_to32 (&res
, &ans
);
2596 sim_fpu_64to (&wop1
, op1
);
2597 sim_fpu_64to (&wop2
, op2
);
2598 sim_fpu_mul (&ans
, &wop1
, &wop2
);
2599 sim_fpu_to64 (&res
, &ans
);
2604 fprintf (stderr
, "Bad switch\n");
2609 printf("DBG: Multiply: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2624 printf("DBG: Divide: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2627 /* The registers must specify FPRs valid for operands of type
2628 "fmt". If they are not valid, the result is undefined. */
2630 /* The format type should already have been checked: */
2638 sim_fpu_32to (&wop1
, op1
);
2639 sim_fpu_32to (&wop2
, op2
);
2640 sim_fpu_div (&ans
, &wop1
, &wop2
);
2641 sim_fpu_to32 (&res
, &ans
);
2651 sim_fpu_64to (&wop1
, op1
);
2652 sim_fpu_64to (&wop2
, op2
);
2653 sim_fpu_div (&ans
, &wop1
, &wop2
);
2654 sim_fpu_to64 (&res
, &ans
);
2659 fprintf (stderr
, "Bad switch\n");
2664 printf("DBG: Divide: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2678 printf("DBG: Recip: %s: op = 0x%s\n",DOFMT(fmt
),pr_addr(op
));
2681 /* The registers must specify FPRs valid for operands of type
2682 "fmt". If they are not valid, the result is undefined. */
2684 /* The format type should already have been checked: */
2691 sim_fpu_32to (&wop
, op
);
2692 sim_fpu_inv (&ans
, &wop
);
2693 sim_fpu_to32 (&res
, &ans
);
2702 sim_fpu_64to (&wop
, op
);
2703 sim_fpu_inv (&ans
, &wop
);
2704 sim_fpu_to64 (&res
, &ans
);
2709 fprintf (stderr
, "Bad switch\n");
2714 printf("DBG: Recip: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2728 printf("DBG: SquareRoot: %s: op = 0x%s\n",DOFMT(fmt
),pr_addr(op
));
2731 /* The registers must specify FPRs valid for operands of type
2732 "fmt". If they are not valid, the result is undefined. */
2734 /* The format type should already have been checked: */
2741 sim_fpu_32to (&wop
, op
);
2742 sim_fpu_sqrt (&ans
, &wop
);
2743 sim_fpu_to32 (&res
, &ans
);
2752 sim_fpu_64to (&wop
, op
);
2753 sim_fpu_sqrt (&ans
, &wop
);
2754 sim_fpu_to64 (&res
, &ans
);
2759 fprintf (stderr
, "Bad switch\n");
2764 printf("DBG: SquareRoot: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2780 printf("DBG: Max: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2783 /* The registers must specify FPRs valid for operands of type
2784 "fmt". If they are not valid, the result is undefined. */
2786 /* The format type should already have been checked: */
2793 sim_fpu_32to (&wop1
, op1
);
2794 sim_fpu_32to (&wop2
, op2
);
2795 cmp
= sim_fpu_cmp (&wop1
, &wop2
);
2802 sim_fpu_64to (&wop1
, op1
);
2803 sim_fpu_64to (&wop2
, op2
);
2804 cmp
= sim_fpu_cmp (&wop1
, &wop2
);
2808 fprintf (stderr
, "Bad switch\n");
2814 case SIM_FPU_IS_SNAN
:
2815 case SIM_FPU_IS_QNAN
:
2817 case SIM_FPU_IS_NINF
:
2818 case SIM_FPU_IS_NNUMBER
:
2819 case SIM_FPU_IS_NDENORM
:
2820 case SIM_FPU_IS_NZERO
:
2821 result
= op2
; /* op1 - op2 < 0 */
2822 case SIM_FPU_IS_PINF
:
2823 case SIM_FPU_IS_PNUMBER
:
2824 case SIM_FPU_IS_PDENORM
:
2825 case SIM_FPU_IS_PZERO
:
2826 result
= op1
; /* op1 - op2 > 0 */
2828 fprintf (stderr
, "Bad switch\n");
2833 printf("DBG: Max: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2850 printf("DBG: Min: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2853 /* The registers must specify FPRs valid for operands of type
2854 "fmt". If they are not valid, the result is undefined. */
2856 /* The format type should already have been checked: */
2863 sim_fpu_32to (&wop1
, op1
);
2864 sim_fpu_32to (&wop2
, op2
);
2865 cmp
= sim_fpu_cmp (&wop1
, &wop2
);
2872 sim_fpu_64to (&wop1
, op1
);
2873 sim_fpu_64to (&wop2
, op2
);
2874 cmp
= sim_fpu_cmp (&wop1
, &wop2
);
2878 fprintf (stderr
, "Bad switch\n");
2884 case SIM_FPU_IS_SNAN
:
2885 case SIM_FPU_IS_QNAN
:
2887 case SIM_FPU_IS_NINF
:
2888 case SIM_FPU_IS_NNUMBER
:
2889 case SIM_FPU_IS_NDENORM
:
2890 case SIM_FPU_IS_NZERO
:
2891 result
= op1
; /* op1 - op2 < 0 */
2892 case SIM_FPU_IS_PINF
:
2893 case SIM_FPU_IS_PNUMBER
:
2894 case SIM_FPU_IS_PDENORM
:
2895 case SIM_FPU_IS_PZERO
:
2896 result
= op2
; /* op1 - op2 > 0 */
2898 fprintf (stderr
, "Bad switch\n");
2903 printf("DBG: Min: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2911 convert (SIM_DESC sd
,
2920 sim_fpu_round round
;
2921 unsigned32 result32
;
2922 unsigned64 result64
;
2925 printf("DBG: Convert: mode %s : op 0x%s : from %s : to %s : (PC = 0x%s)\n",RMMODE(rm
),pr_addr(op
),DOFMT(from
),DOFMT(to
),pr_addr(IPC
));
2931 /* Round result to nearest representable value. When two
2932 representable values are equally near, round to the value
2933 that has a least significant bit of zero (i.e. is even). */
2934 round
= sim_fpu_round_near
;
2937 /* Round result to the value closest to, and not greater in
2938 magnitude than, the result. */
2939 round
= sim_fpu_round_zero
;
2942 /* Round result to the value closest to, and not less than,
2944 round
= sim_fpu_round_up
;
2948 /* Round result to the value closest to, and not greater than,
2950 round
= sim_fpu_round_down
;
2954 fprintf (stderr
, "Bad switch\n");
2958 /* Convert the input to sim_fpu internal format */
2962 sim_fpu_64to (&wop
, op
);
2965 sim_fpu_32to (&wop
, op
);
2968 sim_fpu_i32to (&wop
, op
, round
);
2971 sim_fpu_i64to (&wop
, op
, round
);
2974 fprintf (stderr
, "Bad switch\n");
2978 /* Convert sim_fpu format into the output */
2979 /* The value WOP is converted to the destination format, rounding
2980 using mode RM. When the destination is a fixed-point format, then
2981 a source value of Infinity, NaN or one which would round to an
2982 integer outside the fixed point range then an IEEE Invalid
2983 Operation condition is raised. */
2987 sim_fpu_round_32 (&wop
, round
, 0);
2988 sim_fpu_to32 (&result32
, &wop
);
2989 result64
= result32
;
2992 sim_fpu_round_64 (&wop
, round
, 0);
2993 sim_fpu_to64 (&result64
, &wop
);
2996 sim_fpu_to32i (&result32
, &wop
, round
);
2997 result64
= result32
;
3000 sim_fpu_to64i (&result64
, &wop
, round
);
3004 fprintf (stderr
, "Bad switch\n");
3009 printf("DBG: Convert: returning 0x%s (to format = %s)\n",pr_addr(result64
),DOFMT(to
));
3016 /*-- co-processor support routines ------------------------------------------*/
3019 CoProcPresent(coproc_number
)
3020 unsigned int coproc_number
;
3022 /* Return TRUE if simulator provides a model for the given co-processor number */
3027 cop_lw (SIM_DESC sd
,
3032 unsigned int memword
)
3037 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
3040 printf("DBG: COP_LW: memword = 0x%08X (uword64)memword = 0x%s\n",memword
,pr_addr(memword
));
3042 StoreFPR(coproc_reg
,fmt_word
,(uword64
)memword
);
3043 FPR_STATE
[coproc_reg
] = fmt_uninterpreted
;
3048 #if 0 /* this should be controlled by a configuration option */
3049 sim_io_printf(sd
,"COP_LW(%d,%d,0x%08X) at PC = 0x%s : TODO (architecture specific)\n",coproc_num
,coproc_reg
,memword
,pr_addr(cia
));
3058 cop_ld (SIM_DESC sd
,
3065 switch (coproc_num
) {
3067 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
3069 StoreFPR(coproc_reg
,fmt_uninterpreted
,memword
);
3074 #if 0 /* this message should be controlled by a configuration option */
3075 sim_io_printf(sd
,"COP_LD(%d,%d,0x%s) at PC = 0x%s : TODO (architecture specific)\n",coproc_num
,coproc_reg
,pr_addr(memword
),pr_addr(cia
));
3084 /* start-sanitize-sky */
3087 cop_lq (SIM_DESC sd
,
3092 unsigned128 memword
)
3103 /* one word at a time, argh! */
3107 value
= H2T_4(*A4_16(& memword
, 3-i
));
3108 write_vu_vec_reg(&(vu0_device
.regs
), coproc_reg
, i
, & value
);
3114 sim_io_printf(sd
,"COP_LQ(%d,%d,??) at PC = 0x%s : TODO (architecture specific)\n",
3115 coproc_num
,coproc_reg
,pr_addr(cia
));
3121 #endif /* TARGET_SKY */
3122 /* end-sanitize-sky */
3126 cop_sw (SIM_DESC sd
,
3132 unsigned int value
= 0;
3137 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
3140 hold
= FPR_STATE
[coproc_reg
];
3141 FPR_STATE
[coproc_reg
] = fmt_word
;
3142 value
= (unsigned int)ValueFPR(coproc_reg
,fmt_uninterpreted
);
3143 FPR_STATE
[coproc_reg
] = hold
;
3148 #if 0 /* should be controlled by configuration option */
3149 sim_io_printf(sd
,"COP_SW(%d,%d) at PC = 0x%s : TODO (architecture specific)\n",coproc_num
,coproc_reg
,pr_addr(cia
));
3158 cop_sd (SIM_DESC sd
,
3168 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
3170 value
= ValueFPR(coproc_reg
,fmt_uninterpreted
);
3175 #if 0 /* should be controlled by configuration option */
3176 sim_io_printf(sd
,"COP_SD(%d,%d) at PC = 0x%s : TODO (architecture specific)\n",coproc_num
,coproc_reg
,pr_addr(cia
));
3185 /* start-sanitize-sky */
3188 cop_sq (SIM_DESC sd
,
3194 unsigned128 value
= U16_8(0, 0);
3205 /* one word at a time, argh! */
3209 read_vu_vec_reg(&(vu0_device
.regs
), coproc_reg
, i
, & value
);
3210 *A4_16(& xyzw
, 3-i
) = T2H_4(value
);
3217 sim_io_printf(sd
,"COP_SQ(%d,%d) at PC = 0x%s : TODO (architecture specific)\n",
3218 coproc_num
,coproc_reg
,pr_addr(cia
));
3224 #endif /* TARGET_SKY */
3225 /* end-sanitize-sky */
3229 decode_coproc (SIM_DESC sd
,
3232 unsigned int instruction
)
3234 int coprocnum
= ((instruction
>> 26) & 3);
3238 case 0: /* standard CPU control and cache registers */
3240 int code
= ((instruction
>> 21) & 0x1F);
3241 int rt
= ((instruction
>> 16) & 0x1F);
3242 int rd
= ((instruction
>> 11) & 0x1F);
3243 int tail
= instruction
& 0x3ff;
3244 /* R4000 Users Manual (second edition) lists the following CP0
3246 CODE><-RT><RD-><--TAIL--->
3247 DMFC0 Doubleword Move From CP0 (VR4100 = 01000000001tttttddddd00000000000)
3248 DMTC0 Doubleword Move To CP0 (VR4100 = 01000000101tttttddddd00000000000)
3249 MFC0 word Move From CP0 (VR4100 = 01000000000tttttddddd00000000000)
3250 MTC0 word Move To CP0 (VR4100 = 01000000100tttttddddd00000000000)
3251 TLBR Read Indexed TLB Entry (VR4100 = 01000010000000000000000000000001)
3252 TLBWI Write Indexed TLB Entry (VR4100 = 01000010000000000000000000000010)
3253 TLBWR Write Random TLB Entry (VR4100 = 01000010000000000000000000000110)
3254 TLBP Probe TLB for Matching Entry (VR4100 = 01000010000000000000000000001000)
3255 CACHE Cache operation (VR4100 = 101111bbbbbpppppiiiiiiiiiiiiiiii)
3256 ERET Exception return (VR4100 = 01000010000000000000000000011000)
3258 if (((code
== 0x00) || (code
== 0x04)) && tail
== 0)
3260 /* M[TF]C0 - 32 bit word */
3262 switch (rd
) /* NOTEs: Standard CP0 registers */
3264 /* 0 = Index R4000 VR4100 VR4300 */
3265 /* 1 = Random R4000 VR4100 VR4300 */
3266 /* 2 = EntryLo0 R4000 VR4100 VR4300 */
3267 /* 3 = EntryLo1 R4000 VR4100 VR4300 */
3268 /* 4 = Context R4000 VR4100 VR4300 */
3269 /* 5 = PageMask R4000 VR4100 VR4300 */
3270 /* 6 = Wired R4000 VR4100 VR4300 */
3271 /* 8 = BadVAddr R4000 VR4100 VR4300 */
3272 /* 9 = Count R4000 VR4100 VR4300 */
3273 /* 10 = EntryHi R4000 VR4100 VR4300 */
3274 /* 11 = Compare R4000 VR4100 VR4300 */
3275 /* 12 = SR R4000 VR4100 VR4300 */
3276 #ifdef SUBTARGET_R3900
3280 /* 3 = Config R3900 */
3285 /* 3 = Cache R3900 */
3287 #endif /* SUBTARGET_R3900 */
3294 /* 13 = Cause R4000 VR4100 VR4300 */
3301 /* 14 = EPC R4000 VR4100 VR4300 */
3304 GPR
[rt
] = (signed_word
) (signed_address
) EPC
;
3308 /* 15 = PRId R4000 VR4100 VR4300 */
3309 #ifdef SUBTARGET_R3900
3318 /* 16 = Config R4000 VR4100 VR4300 */
3321 GPR
[rt
] = C0_CONFIG
;
3323 C0_CONFIG
= GPR
[rt
];
3326 #ifdef SUBTARGET_R3900
3335 /* 17 = LLAddr R4000 VR4100 VR4300 */
3337 /* 18 = WatchLo R4000 VR4100 VR4300 */
3338 /* 19 = WatchHi R4000 VR4100 VR4300 */
3339 /* 20 = XContext R4000 VR4100 VR4300 */
3340 /* 26 = PErr or ECC R4000 VR4100 VR4300 */
3341 /* 27 = CacheErr R4000 VR4100 */
3342 /* 28 = TagLo R4000 VR4100 VR4300 */
3343 /* 29 = TagHi R4000 VR4100 VR4300 */
3344 /* 30 = ErrorEPC R4000 VR4100 VR4300 */
3345 GPR
[rt
] = 0xDEADC0DE; /* CPR[0,rd] */
3346 /* CPR[0,rd] = GPR[rt]; */
3349 GPR
[rt
] = (signed_word
) (signed32
) COP0_GPR
[rd
];
3351 COP0_GPR
[rd
] = GPR
[rt
];
3354 sim_io_printf(sd
,"Warning: MFC0 %d,%d ignored (architecture specific)\n",rt
,rd
);
3356 sim_io_printf(sd
,"Warning: MTC0 %d,%d ignored (architecture specific)\n",rt
,rd
);
3360 /* start-sanitize-r5900 */
3361 else if (((code
== 0x00) || (code
== 0x04)) && rd
== 0x18 && tail
> 0 && tail
< NR_COP0_BP
)
3362 /* Break-point registers */
3365 GPR
[rt
] = (signed_word
) (signed32
) COP0_BP
[tail
];
3367 COP0_BP
[tail
] = GPR
[rt
];
3369 else if (((code
== 0x00) || (code
== 0x04)) && rd
== 0x19 && tail
> 0 && tail
< NR_COP0_P
)
3370 /* Performance registers */
3373 GPR
[rt
] = (signed_word
) (signed32
) COP0_P
[tail
];
3375 COP0_P
[tail
] = GPR
[rt
];
3377 /* end-sanitize-r5900 */
3378 else if (code
== 0x10 && (tail
& 0x3f) == 0x18)
3381 if (SR
& status_ERL
)
3383 /* Oops, not yet available */
3384 sim_io_printf(sd
,"Warning: ERET when SR[ERL] set not handled yet");
3394 else if (code
== 0x10 && (tail
& 0x3f) == 0x10)
3397 #ifdef SUBTARGET_R3900
3398 /* TX39: Copy IEp/KUp -> IEc/KUc, and IEo/KUo -> IEp/KUp */
3400 /* shift IE/KU history bits right */
3401 SR
= LSMASKED32(SR
, 31, 4) | LSINSERTED32(LSEXTRACTED32(SR
, 5, 2), 3, 0);
3403 /* TODO: CACHE register */
3404 #endif /* SUBTARGET_R3900 */
3406 else if (code
== 0x10 && (tail
& 0x3f) == 0x1F)
3414 sim_io_eprintf(sd
,"Unrecognised COP0 instruction 0x%08X at PC = 0x%s : No handler present\n",instruction
,pr_addr(cia
));
3415 /* TODO: When executing an ERET or RFE instruction we should
3416 clear LLBIT, to ensure that any out-standing atomic
3417 read/modify/write sequence fails. */
3421 case 2: /* co-processor 2 */
3425 /* start-sanitize-sky */
3427 /* On the R5900, this refers to a "VU" vector co-processor. */
3429 int i_25_21
= (instruction
>> 21) & 0x1f;
3430 int i_20_16
= (instruction
>> 16) & 0x1f;
3431 int i_20_6
= (instruction
>> 6) & 0x7fff;
3432 int i_15_11
= (instruction
>> 11) & 0x1f;
3433 int i_15_0
= instruction
& 0xffff;
3434 int i_10_1
= (instruction
>> 1) & 0x3ff;
3435 int i_10_0
= instruction
& 0x7ff;
3436 int i_10_6
= (instruction
>> 6) & 0x1f;
3437 int i_5_0
= instruction
& 0x03f;
3438 int interlock
= instruction
& 0x01;
3442 /* test COP2 usability */
3443 if(! (SR
& status_CU2
))
3445 SignalException(CoProcessorUnusable
,instruction
);
3449 /* BC2T/BC2F/BC2TL/BC2FL handled in r5900.igen */
3451 else if((i_25_21
== 0x02 && i_10_1
== 0x000) || /* CFC2 */
3452 (i_25_21
== 0x01)) /* QMFC2 */
3457 /* interlock checking */
3458 /* POLICY: never busy in macro mode */
3459 while(vu0_busy() && interlock
)
3462 /* perform VU register access */
3463 if(i_25_21
== 0x01) /* QMFC2 */
3467 /* one word at a time, argh! */
3468 read_vu_vec_reg(&(vu0_device
.regs
), id
, 3, &w
);
3469 read_vu_vec_reg(&(vu0_device
.regs
), id
, 2, &z
);
3470 read_vu_vec_reg(&(vu0_device
.regs
), id
, 1, &y
);
3471 read_vu_vec_reg(&(vu0_device
.regs
), id
, 0, &x
);
3473 GPR
[rt
] = U8_4(T2H_4(y
), T2H_4(x
));
3474 GPR1
[rt
] = U8_4(T2H_4(w
), T2H_4(z
));
3478 GPR
[rt
] = vu0_read_cop2_register(id
);
3481 else if((i_25_21
== 0x06 && i_10_1
== 0x000) || /* CTC2 */
3482 (i_25_21
== 0x05)) /* QMTC2 */
3487 /* interlock checking: wait until M or E bits set */
3488 /* POLICY: never busy in macro mode */
3489 while(vu0_busy() && interlock
)
3491 if(vu0_micro_interlock_released())
3493 vu0_micro_interlock_clear();
3500 /* perform VU register access */
3501 if(i_25_21
== 0x05) /* QMTC2 */
3505 x
= H2T_4(V4_8(GPR
[rt
], 1));
3506 y
= H2T_4(V4_8(GPR
[rt
], 0));
3507 z
= H2T_4(V4_8(GPR1
[rt
], 1));
3508 w
= H2T_4(V4_8(GPR1
[rt
], 0));
3510 /* one word at a time, argh! */
3511 write_vu_vec_reg(&(vu0_device
.regs
), id
, 3, & w
);
3512 write_vu_vec_reg(&(vu0_device
.regs
), id
, 2, & z
);
3513 write_vu_vec_reg(&(vu0_device
.regs
), id
, 1, & y
);
3514 write_vu_vec_reg(&(vu0_device
.regs
), id
, 0, & x
);
3518 vu0_write_cop2_register(id
, GPR
[rt
]);
3521 else if(i_10_0
== 0x3bf) /* VWAITQ */
3526 else if(i_5_0
== 0x38) /* VCALLMS */
3528 unsigned_4 data
= H2T_2(i_20_6
);
3533 /* write to reserved CIA register to get VU0 moving */
3534 write_vu_special_reg(& vu0_device
, VU_REG_CIA
, & data
);
3538 else if(i_5_0
== 0x39) /* VCALLMSR */
3545 read_vu_special_reg(& vu0_device
, VU_REG_CMSAR0
, & data
);
3546 /* write to reserved CIA register to get VU0 moving */
3547 write_vu_special_reg(& vu0_device
, VU_REG_CIA
, & data
);
3551 /* handle all remaining UPPER VU instructions in one block */
3552 else if((i_5_0
< 0x30) || /* VADDx .. VMINI */
3553 (i_5_0
>= 0x3c && i_10_6
< 0x0c)) /* VADDAx .. VNOP */
3555 unsigned_4 vu_upper
, vu_lower
;
3557 0x00000000 | /* bits 31 .. 25 */
3558 (instruction
& 0x01ffffff); /* bits 24 .. 0 */
3559 vu_lower
= 0x8000033c; /* NOP */
3561 /* POLICY: never busy in macro mode */
3565 vu0_macro_issue(vu_upper
, vu_lower
);
3567 /* POLICY: wait for completion of macro-instruction */
3571 /* handle all remaining LOWER VU instructions in one block */
3572 else if((i_5_0
>= 0x30 && i_5_0
<= 0x35) || /* VIADD .. VIOR */
3573 (i_5_0
>= 0x3c && i_10_6
>= 0x0c)) /* VMOVE .. VRXOR */
3574 { /* N.B.: VWAITQ already covered by prior case */
3575 unsigned_4 vu_upper
, vu_lower
;
3576 vu_upper
= 0x000002ff; /* NOP/NOP */
3578 0x80000000 | /* bits 31 .. 25 */
3579 (instruction
& 0x01ffffff); /* bits 24 .. 0 */
3581 /* POLICY: never busy in macro mode */
3585 vu0_macro_issue(vu_upper
, vu_lower
);
3587 /* POLICY: wait for completion of macro-instruction */
3591 /* ... no other COP2 instructions ... */
3594 SignalException(ReservedInstruction
, instruction
);
3602 #endif /* TARGET_SKY */
3603 /* end-sanitize-sky */
3607 sim_io_eprintf(sd
, "COP2 instruction 0x%08X at PC = 0x%s : No handler present\n",
3608 instruction
,pr_addr(cia
));
3613 case 1: /* should not occur (FPU co-processor) */
3614 case 3: /* should not occur (FPU co-processor) */
3615 SignalException(ReservedInstruction
,instruction
);
3623 /*-- instruction simulation -------------------------------------------------*/
3625 /* When the IGEN simulator is being built, the function below is be
3626 replaced by a generated version. However, WITH_IGEN == 2 indicates
3627 that the fubction below should be compiled but under a different
3628 name (to allow backward compatibility) */
3630 #if (WITH_IGEN != 1)
3632 void old_engine_run
PARAMS ((SIM_DESC sd
, int next_cpu_nr
, int siggnal
));
3634 old_engine_run (sd
, next_cpu_nr
, nr_cpus
, siggnal
)
3637 sim_engine_run (sd
, next_cpu_nr
, nr_cpus
, siggnal
)
3640 int next_cpu_nr
; /* ignore */
3641 int nr_cpus
; /* ignore */
3642 int siggnal
; /* ignore */
3644 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* hardwire to cpu 0 */
3645 #if !defined(FASTSIM)
3646 unsigned int pipeline_count
= 1;
3650 if (STATE_MEMORY (sd
) == NULL
) {
3651 printf("DBG: simulate() entered with no memory\n");
3656 #if 0 /* Disabled to check that everything works OK */
3657 /* The VR4300 seems to sign-extend the PC on its first
3658 access. However, this may just be because it is currently
3659 configured in 32bit mode. However... */
3660 PC
= SIGNEXTEND(PC
,32);
3663 /* main controlling loop */
3665 /* vaddr is slowly being replaced with cia - current instruction
3667 address_word cia
= (uword64
)PC
;
3668 address_word vaddr
= cia
;
3671 unsigned int instruction
; /* uword64? what's this used for? FIXME! */
3675 printf("DBG: state = 0x%08X :",state
);
3676 if (state
& simHALTEX
) printf(" simHALTEX");
3677 if (state
& simHALTIN
) printf(" simHALTIN");
3682 DSSTATE
= (STATE
& simDELAYSLOT
);
3685 sim_io_printf(sd
,"DBG: DSPC = 0x%s\n",pr_addr(DSPC
));
3688 /* Fetch the next instruction from the simulator memory: */
3689 if (AddressTranslation(cia
,isINSTRUCTION
,isLOAD
,&paddr
,&cca
,isTARGET
,isREAL
)) {
3690 if ((vaddr
& 1) == 0) {
3691 /* Copy the action of the LW instruction */
3692 unsigned int reverse
= (ReverseEndian
? (LOADDRMASK
>> 2) : 0);
3693 unsigned int bigend
= (BigEndianCPU
? (LOADDRMASK
>> 2) : 0);
3696 paddr
= ((paddr
& ~LOADDRMASK
) | ((paddr
& LOADDRMASK
) ^ (reverse
<< 2)));
3697 LoadMemory(&value
,NULL
,cca
,AccessLength_WORD
,paddr
,vaddr
,isINSTRUCTION
,isREAL
);
3698 byte
= ((vaddr
& LOADDRMASK
) ^ (bigend
<< 2));
3699 instruction
= ((value
>> (8 * byte
)) & 0xFFFFFFFF);
3701 /* Copy the action of the LH instruction */
3702 unsigned int reverse
= (ReverseEndian
? (LOADDRMASK
>> 1) : 0);
3703 unsigned int bigend
= (BigEndianCPU
? (LOADDRMASK
>> 1) : 0);
3706 paddr
= (((paddr
& ~ (uword64
) 1) & ~LOADDRMASK
)
3707 | (((paddr
& ~ (uword64
) 1) & LOADDRMASK
) ^ (reverse
<< 1)));
3708 LoadMemory(&value
,NULL
,cca
, AccessLength_HALFWORD
,
3709 paddr
& ~ (uword64
) 1,
3710 vaddr
, isINSTRUCTION
, isREAL
);
3711 byte
= (((vaddr
&~ (uword64
) 1) & LOADDRMASK
) ^ (bigend
<< 1));
3712 instruction
= ((value
>> (8 * byte
)) & 0xFFFF);
3715 fprintf(stderr
,"Cannot translate address for PC = 0x%s failed\n",pr_addr(PC
));
3720 sim_io_printf(sd
,"DBG: fetched 0x%08X from PC = 0x%s\n",instruction
,pr_addr(PC
));
3723 /* This is required by exception processing, to ensure that we can
3724 cope with exceptions in the delay slots of branches that may
3725 already have changed the PC. */
3726 if ((vaddr
& 1) == 0)
3727 PC
+= 4; /* increment ready for the next fetch */
3730 /* NOTE: If we perform a delay slot change to the PC, this
3731 increment is not requuired. However, it would make the
3732 simulator more complicated to try and avoid this small hit. */
3734 /* Currently this code provides a simple model. For more
3735 complicated models we could perform exception status checks at
3736 this point, and set the simSTOP state as required. This could
3737 also include processing any hardware interrupts raised by any
3738 I/O model attached to the simulator context.
3740 Support for "asynchronous" I/O events within the simulated world
3741 could be providing by managing a counter, and calling a I/O
3742 specific handler when a particular threshold is reached. On most
3743 architectures a decrement and check for zero operation is
3744 usually quicker than an increment and compare. However, the
3745 process of managing a known value decrement to zero, is higher
3746 than the cost of using an explicit value UINT_MAX into the
3747 future. Which system is used will depend on how complicated the
3748 I/O model is, and how much it is likely to affect the simulator
3751 If events need to be scheduled further in the future than
3752 UINT_MAX event ticks, then the I/O model should just provide its
3753 own counter, triggered from the event system. */
3755 /* MIPS pipeline ticks. To allow for future support where the
3756 pipeline hit of individual instructions is known, this control
3757 loop manages a "pipeline_count" variable. It is initialised to
3758 1 (one), and will only be changed by the simulator engine when
3759 executing an instruction. If the engine does not have access to
3760 pipeline cycle count information then all instructions will be
3761 treated as using a single cycle. NOTE: A standard system is not
3762 provided by the default simulator because different MIPS
3763 architectures have different cycle counts for the same
3766 [NOTE: pipeline_count has been replaced the event queue] */
3768 /* shuffle the floating point status pipeline state */
3769 ENGINE_ISSUE_PREFIX_HOOK();
3771 /* NOTE: For multi-context simulation environments the "instruction"
3772 variable should be local to this routine. */
3774 /* Shorthand accesses for engine. Note: If we wanted to use global
3775 variables (and a single-threaded simulator engine), then we can
3776 create the actual variables with these names. */
3778 if (!(STATE
& simSKIPNEXT
)) {
3779 /* Include the simulator engine */
3780 #include "oengine.c"
3781 #if ((GPRLEN == 64) && !PROCESSOR_64BIT) || ((GPRLEN == 32) && PROCESSOR_64BIT)
3782 #error "Mismatch between run-time simulator code and simulation engine"
3784 #if (WITH_TARGET_WORD_BITSIZE != GPRLEN)
3785 #error "Mismatch between configure WITH_TARGET_WORD_BITSIZE and gencode GPRLEN"
3787 #if ((WITH_FLOATING_POINT == HARD_FLOATING_POINT) != defined (HASFPU))
3788 #error "Mismatch between configure WITH_FLOATING_POINT and gencode HASFPU"
3791 /* For certain MIPS architectures, GPR[0] is hardwired to zero. We
3792 should check for it being changed. It is better doing it here,
3793 than within the simulator, since it will help keep the simulator
3796 #if defined(WARN_ZERO)
3797 sim_io_eprintf(sd
,"The ZERO register has been updated with 0x%s (PC = 0x%s) (reset back to zero)\n",pr_addr(ZERO
),pr_addr(cia
));
3798 #endif /* WARN_ZERO */
3799 ZERO
= 0; /* reset back to zero before next instruction */
3801 } else /* simSKIPNEXT check */
3802 STATE
&= ~simSKIPNEXT
;
3804 /* If the delay slot was active before the instruction is
3805 executed, then update the PC to its new value: */
3808 printf("DBG: dsstate set before instruction execution - updating PC to 0x%s\n",pr_addr(DSPC
));
3817 #if !defined(FASTSIM)
3818 if (sim_events_tickn (sd
, pipeline_count
))
3820 /* cpu->cia = cia; */
3821 sim_events_process (sd
);
3824 if (sim_events_tick (sd
))
3826 /* cpu->cia = cia; */
3827 sim_events_process (sd
);
3829 #endif /* FASTSIM */
3835 /* This code copied from gdb's utils.c. Would like to share this code,
3836 but don't know of a common place where both could get to it. */
3838 /* Temporary storage using circular buffer */
3844 static char buf
[NUMCELLS
][CELLSIZE
];
3846 if (++cell
>=NUMCELLS
) cell
=0;
3850 /* Print routines to handle variable size regs, etc */
3852 /* Eliminate warning from compiler on 32-bit systems */
3853 static int thirty_two
= 32;
3859 char *paddr_str
=get_cell();
3860 switch (sizeof(addr
))
3863 sprintf(paddr_str
,"%08lx%08lx",
3864 (unsigned long)(addr
>>thirty_two
),(unsigned long)(addr
&0xffffffff));
3867 sprintf(paddr_str
,"%08lx",(unsigned long)addr
);
3870 sprintf(paddr_str
,"%04x",(unsigned short)(addr
&0xffff));
3873 sprintf(paddr_str
,"%x",addr
);
3882 char *paddr_str
=get_cell();
3883 sprintf(paddr_str
,"%08lx%08lx",
3884 (unsigned long)(addr
>>thirty_two
),(unsigned long)(addr
&0xffffffff));
3890 /*---------------------------------------------------------------------------*/
3891 /*> EOF interp.c <*/