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"
53 /* end-sanitize-sky */
75 #include "libiberty.h"
77 #include "callback.h" /* GDB simulator callback interface */
78 #include "remote-sim.h" /* GDB simulator interface */
86 char* pr_addr
PARAMS ((SIM_ADDR addr
));
87 char* pr_uword64
PARAMS ((uword64 addr
));
90 /* Get the simulator engine description, without including the code: */
97 /* Within interp.c we refer to the sim_state and sim_cpu directly. */
102 /* The following reserved instruction value is used when a simulator
103 trap is required. NOTE: Care must be taken, since this value may be
104 used in later revisions of the MIPS ISA. */
106 #define RSVD_INSTRUCTION (0x00000005)
107 #define RSVD_INSTRUCTION_MASK (0xFC00003F)
109 #define RSVD_INSTRUCTION_ARG_SHIFT 6
110 #define RSVD_INSTRUCTION_ARG_MASK 0xFFFFF
113 /* Bits in the Debug register */
114 #define Debug_DBD 0x80000000 /* Debug Branch Delay */
115 #define Debug_DM 0x40000000 /* Debug Mode */
116 #define Debug_DBp 0x00000002 /* Debug Breakpoint indicator */
118 /*---------------------------------------------------------------------------*/
119 /*-- GDB simulator interface ------------------------------------------------*/
120 /*---------------------------------------------------------------------------*/
122 static void ColdReset
PARAMS((SIM_DESC sd
));
124 /*---------------------------------------------------------------------------*/
128 #define DELAYSLOT() {\
129 if (STATE & simDELAYSLOT)\
130 sim_io_eprintf(sd,"Delay slot already activated (branch in delay slot?)\n");\
131 STATE |= simDELAYSLOT;\
134 #define JALDELAYSLOT() {\
136 STATE |= simJALDELAYSLOT;\
140 STATE &= ~simDELAYSLOT;\
141 STATE |= simSKIPNEXT;\
144 #define CANCELDELAYSLOT() {\
146 STATE &= ~(simDELAYSLOT | simJALDELAYSLOT);\
149 #define INDELAYSLOT() ((STATE & simDELAYSLOT) != 0)
150 #define INJALDELAYSLOT() ((STATE & simJALDELAYSLOT) != 0)
152 #define K0BASE (0x80000000)
153 #define K0SIZE (0x20000000)
154 #define K1BASE (0xA0000000)
155 #define K1SIZE (0x20000000)
156 #define MONITOR_BASE (0xBFC00000)
157 #define MONITOR_SIZE (1 << 11)
158 #define MEM_SIZE (2 << 20)
160 /* start-sanitize-sky */
163 #define MEM_SIZE (16 << 20) /* 16 MB */
165 /* end-sanitize-sky */
168 static char *tracefile
= "trace.din"; /* default filename for trace log */
169 FILE *tracefh
= NULL
;
170 static void open_trace
PARAMS((SIM_DESC sd
));
173 /* simulation target board. NULL=canonical */
174 static char* board
= NULL
;
177 static DECLARE_OPTION_HANDLER (mips_option_handler
);
180 OPTION_DINERO_TRACE
= OPTION_START
,
187 mips_option_handler (sd
, cpu
, opt
, arg
, is_command
)
197 case OPTION_DINERO_TRACE
: /* ??? */
199 /* Eventually the simTRACE flag could be treated as a toggle, to
200 allow external control of the program points being traced
201 (i.e. only from main onwards, excluding the run-time setup,
203 for (cpu_nr
= 0; cpu_nr
< MAX_NR_PROCESSORS
; cpu_nr
++)
205 sim_cpu
*cpu
= STATE_CPU (sd
, cpu_nr
);
208 else if (strcmp (arg
, "yes") == 0)
210 else if (strcmp (arg
, "no") == 0)
212 else if (strcmp (arg
, "on") == 0)
214 else if (strcmp (arg
, "off") == 0)
218 fprintf (stderr
, "Unrecognized dinero-trace option `%s'\n", arg
);
225 Simulator constructed without dinero tracing support (for performance).\n\
226 Re-compile simulator with \"-DTRACE\" to enable this option.\n");
230 case OPTION_DINERO_FILE
:
232 if (optarg
!= NULL
) {
234 tmp
= (char *)malloc(strlen(optarg
) + 1);
237 sim_io_printf(sd
,"Failed to allocate buffer for tracefile name \"%s\"\n",optarg
);
243 sim_io_printf(sd
,"Placing trace information into file \"%s\"\n",tracefile
);
253 board
= zalloc(strlen(arg
) + 1);
264 static const OPTION mips_options
[] =
266 { {"dinero-trace", optional_argument
, NULL
, OPTION_DINERO_TRACE
},
267 '\0', "on|off", "Enable dinero tracing",
268 mips_option_handler
},
269 { {"dinero-file", required_argument
, NULL
, OPTION_DINERO_FILE
},
270 '\0', "FILE", "Write dinero trace to FILE",
271 mips_option_handler
},
272 { {"board", required_argument
, NULL
, OPTION_BOARD
},
273 '\0', "none" /* rely on compile-time string concatenation for other options */
275 /* start-sanitize-tx3904 */
276 #define BOARD_JMR3904 "jmr3904"
278 #define BOARD_JMR3904_PAL "jmr3904pal"
279 "|" BOARD_JMR3904_PAL
280 #define BOARD_JMR3904_DEBUG "jmr3904debug"
281 "|" BOARD_JMR3904_DEBUG
282 /* end-sanitize-tx3904 */
284 , "Customize simulation for a particular board.", mips_option_handler
},
286 { {NULL
, no_argument
, NULL
, 0}, '\0', NULL
, NULL
, NULL
}
290 int interrupt_pending
;
293 interrupt_event (SIM_DESC sd
, void *data
)
295 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
296 address_word cia
= CIA_GET (cpu
);
299 interrupt_pending
= 0;
300 SignalExceptionInterrupt ();
302 else if (!interrupt_pending
)
303 sim_events_schedule (sd
, 1, interrupt_event
, data
);
307 /*---------------------------------------------------------------------------*/
308 /*-- Device registration hook -----------------------------------------------*/
309 /*---------------------------------------------------------------------------*/
310 static void device_init(SIM_DESC sd
) {
312 extern void register_devices(SIM_DESC
);
313 register_devices(sd
);
317 /*---------------------------------------------------------------------------*/
318 /*-- GDB simulator interface ------------------------------------------------*/
319 /*---------------------------------------------------------------------------*/
322 sim_open (kind
, cb
, abfd
, argv
)
328 SIM_DESC sd
= sim_state_alloc (kind
, cb
);
329 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
331 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
334 /* FIXME: watchpoints code shouldn't need this */
335 STATE_WATCHPOINTS (sd
)->pc
= &(PC
);
336 STATE_WATCHPOINTS (sd
)->sizeof_pc
= sizeof (PC
);
337 STATE_WATCHPOINTS (sd
)->interrupt_handler
= interrupt_event
;
341 if (sim_pre_argv_init (sd
, argv
[0]) != SIM_RC_OK
)
343 sim_add_option_table (sd
, NULL
, mips_options
);
345 /* start-sanitize-sky */
347 sky_command_options_open (sd
);
349 /* end-sanitize-sky */
351 /* getopt will print the error message so we just have to exit if this fails.
352 FIXME: Hmmm... in the case of gdb we need getopt to call
354 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
356 /* Uninstall the modules to avoid memory leaks,
357 file descriptor leaks, etc. */
358 sim_module_uninstall (sd
);
362 /* handle board-specific memory maps */
365 /* Allocate core managed memory */
367 /* start-sanitize-sky */
369 /* end-sanitize-sky */
371 sim_do_commandf (sd
, "memory region 0x%lx,0x%lx", MONITOR_BASE
, MONITOR_SIZE
);
372 /* For compatibility with the old code - under this (at level one)
373 are the kernel spaces K0 & K1. Both of these map to a single
374 smaller sub region */
375 sim_do_command(sd
," memory region 0x7fff8000,0x8000") ; /* MTZ- 32 k stack */
376 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx%%0x%lx,0x%0x",
378 MEM_SIZE
, /* actual size */
380 /* start-sanitize-sky */
383 sim_do_commandf (sd
, "memory region 0x%lx,0x%lx", MONITOR_BASE
- K1BASE
, MONITOR_SIZE
);
384 sim_do_command (sd
," memory region 0x7fff8000,0x8000") ; /* MTZ- 32 k stack */
385 /* 16M @ 0x0. Aliases at 0x80000000 and 0xA0000000 are handled by
386 address_translation() */
387 sim_do_commandf (sd
, "memory size 0x%lx", MEM_SIZE
);
389 /* end-sanitize-sky */
394 /* start-sanitize-tx3904 */
397 && (strcmp(board
, BOARD_JMR3904
) == 0 ||
398 strcmp(board
, BOARD_JMR3904_PAL
) == 0 ||
399 strcmp(board
, BOARD_JMR3904_DEBUG
) == 0))
401 /* match VIRTUAL memory layout of JMR-TX3904 board */
405 /* ROM: 0x9FC0_0000 - 0x9FFF_FFFF and 0xBFC0_0000 - 0xBFFF_FFFF */
406 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx,0x%0x",
408 4 * 1024 * 1024, /* 4 MB */
411 /* SRAM: 0x8000_0000 - 0x803F_FFFF and 0xA000_0000 - 0xA03F_FFFF */
412 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx,0x%0x",
414 4 * 1024 * 1024, /* 4 MB */
417 /* DRAM: 0x8800_0000 - 0x89FF_FFFF and 0xA800_0000 - 0xA9FF_FFFF */
418 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx,0x%0x",
420 32 * 1024 * 1024, /* 32 MB */
423 /* --- simulated devices --- */
424 sim_hw_parse (sd
, "/tx3904irc@0xffffc000/reg 0xffffc000 0x20");
425 sim_hw_parse (sd
, "/tx3904cpu");
426 sim_hw_parse (sd
, "/tx3904tmr@0xfffff000/reg 0xfffff000 0x100");
427 sim_hw_parse (sd
, "/tx3904tmr@0xfffff100/reg 0xfffff100 0x100");
428 sim_hw_parse (sd
, "/tx3904tmr@0xfffff200/reg 0xfffff200 0x100");
430 /* -- device connections --- */
431 sim_hw_parse (sd
, "/tx3904irc > ip level /tx3904cpu");
432 sim_hw_parse (sd
, "/tx3904tmr@0xfffff000 > int tmr0 /tx3904irc");
433 sim_hw_parse (sd
, "/tx3904tmr@0xfffff100 > int tmr1 /tx3904irc");
434 sim_hw_parse (sd
, "/tx3904tmr@0xfffff200 > int tmr2 /tx3904irc");
436 /* add PAL timer & I/O module */
437 if(! strcmp(board
, BOARD_JMR3904_PAL
))
440 sim_hw_parse (sd
, "/pal@0xffff0000");
441 sim_hw_parse (sd
, "/pal@0xffff0000/reg 0xffff0000 64");
443 /* wire up interrupt ports to irc */
444 sim_hw_parse (sd
, "/pal@0x31000000 > countdown tmr0 /tx3904irc");
445 sim_hw_parse (sd
, "/pal@0x31000000 > timer tmr1 /tx3904irc");
446 sim_hw_parse (sd
, "/pal@0x31000000 > int int0 /tx3904irc");
449 if(! strcmp(board
, BOARD_JMR3904_DEBUG
))
451 /* -- DEBUG: glue interrupt generators --- */
452 sim_hw_parse (sd
, "/glue@0xffff0000/reg 0xffff0000 0x50");
453 sim_hw_parse (sd
, "/glue@0xffff0000 > int0 int0 /tx3904irc");
454 sim_hw_parse (sd
, "/glue@0xffff0000 > int1 int1 /tx3904irc");
455 sim_hw_parse (sd
, "/glue@0xffff0000 > int2 int2 /tx3904irc");
456 sim_hw_parse (sd
, "/glue@0xffff0000 > int3 int3 /tx3904irc");
457 sim_hw_parse (sd
, "/glue@0xffff0000 > int4 int4 /tx3904irc");
458 sim_hw_parse (sd
, "/glue@0xffff0000 > int5 int5 /tx3904irc");
459 sim_hw_parse (sd
, "/glue@0xffff0000 > int6 int6 /tx3904irc");
460 sim_hw_parse (sd
, "/glue@0xffff0000 > int7 int7 /tx3904irc");
461 sim_hw_parse (sd
, "/glue@0xffff0000 > int8 dmac0 /tx3904irc");
462 sim_hw_parse (sd
, "/glue@0xffff0000 > int9 dmac1 /tx3904irc");
463 sim_hw_parse (sd
, "/glue@0xffff0000 > int10 dmac2 /tx3904irc");
464 sim_hw_parse (sd
, "/glue@0xffff0000 > int11 dmac3 /tx3904irc");
465 sim_hw_parse (sd
, "/glue@0xffff0000 > int12 sio0 /tx3904irc");
466 sim_hw_parse (sd
, "/glue@0xffff0000 > int13 sio1 /tx3904irc");
467 sim_hw_parse (sd
, "/glue@0xffff0000 > int14 tmr0 /tx3904irc");
468 sim_hw_parse (sd
, "/glue@0xffff0000 > int15 tmr1 /tx3904irc");
469 sim_hw_parse (sd
, "/glue@0xffff0000 > int16 tmr2 /tx3904irc");
470 sim_hw_parse (sd
, "/glue@0xffff0000 > int17 nmi /tx3904cpu");
476 /* end-sanitize-tx3904 */
479 /* check for/establish the a reference program image */
480 if (sim_analyze_program (sd
,
481 (STATE_PROG_ARGV (sd
) != NULL
482 ? *STATE_PROG_ARGV (sd
)
486 sim_module_uninstall (sd
);
490 /* Configure/verify the target byte order and other runtime
491 configuration options */
492 if (sim_config (sd
) != SIM_RC_OK
)
494 sim_module_uninstall (sd
);
498 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
500 /* Uninstall the modules to avoid memory leaks,
501 file descriptor leaks, etc. */
502 sim_module_uninstall (sd
);
506 /* verify assumptions the simulator made about the host type system.
507 This macro does not return if there is a problem */
508 SIM_ASSERT (sizeof(int) == (4 * sizeof(char)));
509 SIM_ASSERT (sizeof(word64
) == (8 * sizeof(char)));
511 /* This is NASTY, in that we are assuming the size of specific
515 for (rn
= 0; (rn
< (LAST_EMBED_REGNUM
+ 1)); rn
++)
518 cpu
->register_widths
[rn
] = WITH_TARGET_WORD_BITSIZE
;
519 else if ((rn
>= FGRIDX
) && (rn
< (FGRIDX
+ NR_FGR
)))
520 cpu
->register_widths
[rn
] = WITH_TARGET_FLOATING_POINT_BITSIZE
;
521 else if ((rn
>= 33) && (rn
<= 37))
522 cpu
->register_widths
[rn
] = WITH_TARGET_WORD_BITSIZE
;
523 else if ((rn
== SRIDX
)
526 || ((rn
>= 72) && (rn
<= 89)))
527 cpu
->register_widths
[rn
] = 32;
529 cpu
->register_widths
[rn
] = 0;
531 /* start-sanitize-r5900 */
533 /* set the 5900 "upper" registers to 64 bits */
534 for( rn
= LAST_EMBED_REGNUM
+1; rn
< NUM_REGS
; rn
++)
535 cpu
->register_widths
[rn
] = 64;
536 /* end-sanitize-r5900 */
538 /* start-sanitize-sky */
540 /* Now the VU registers */
541 for( rn
= 0; rn
< NUM_VU_INTEGER_REGS
; rn
++ ) {
542 cpu
->register_widths
[rn
+ NUM_R5900_REGS
] = 16;
543 cpu
->register_widths
[rn
+ NUM_R5900_REGS
+ NUM_VU_REGS
] = 16;
546 for( rn
= NUM_VU_INTEGER_REGS
; rn
< NUM_VU_REGS
; rn
++ ) {
547 cpu
->register_widths
[rn
+ NUM_R5900_REGS
] = 32;
548 cpu
->register_widths
[rn
+ NUM_R5900_REGS
+ NUM_VU_REGS
] = 32;
551 /* Finally the VIF registers */
552 for( rn
= 2*NUM_VU_REGS
; rn
< 2*NUM_VU_REGS
+ 2*NUM_VIF_REGS
; rn
++ )
553 cpu
->register_widths
[rn
+ NUM_R5900_REGS
] = 32;
557 /* end-sanitize-sky */
561 if (STATE
& simTRACE
)
565 /* Write an abort sequence into the TRAP (common) exception vector
566 addresses. This is to catch code executing a TRAP (et.al.)
567 instruction without installing a trap handler. */
569 unsigned32 halt
[2] = { 0x2404002f /* addiu r4, r0, 47 */,
570 HALT_INSTRUCTION
/* BREAK */ };
573 sim_write (sd
, 0x80000180, (char *) halt
, sizeof (halt
));
574 sim_write (sd
, 0xBFC00380, (char *) halt
, sizeof (halt
));
578 /* Write the monitor trap address handlers into the monitor (eeprom)
579 address space. This can only be done once the target endianness
580 has been determined. */
583 /* Entry into the IDT monitor is via fixed address vectors, and
584 not using machine instructions. To avoid clashing with use of
585 the MIPS TRAP system, we place our own (simulator specific)
586 "undefined" instructions into the relevant vector slots. */
587 for (loop
= 0; (loop
< MONITOR_SIZE
); loop
+= 4)
589 address_word vaddr
= (MONITOR_BASE
+ loop
);
590 unsigned32 insn
= (RSVD_INSTRUCTION
| (((loop
>> 2) & RSVD_INSTRUCTION_ARG_MASK
) << RSVD_INSTRUCTION_ARG_SHIFT
));
592 sim_write (sd
, vaddr
, (char *)&insn
, sizeof (insn
));
594 /* The PMON monitor uses the same address space, but rather than
595 branching into it the address of a routine is loaded. We can
596 cheat for the moment, and direct the PMON routine to IDT style
597 instructions within the monitor space. This relies on the IDT
598 monitor not using the locations from 0xBFC00500 onwards as its
600 for (loop
= 0; (loop
< 24); loop
++)
602 address_word vaddr
= (MONITOR_BASE
+ 0x500 + (loop
* 4));
603 unsigned32 value
= ((0x500 - 8) / 8); /* default UNDEFINED reason code */
619 value
= ((0x500 - 16) / 8); /* not an IDT reason code */
621 case 8: /* cliexit */
624 case 11: /* flush_cache */
628 /* FIXME - should monitor_base be SIM_ADDR?? */
629 value
= ((unsigned int)MONITOR_BASE
+ (value
* 8));
631 sim_write (sd
, vaddr
, (char *)&value
, sizeof (value
));
633 /* The LSI MiniRISC PMON has its vectors at 0x200, not 0x500. */
635 sim_write (sd
, vaddr
, (char *)&value
, sizeof (value
));
647 tracefh
= fopen(tracefile
,"wb+");
650 sim_io_eprintf(sd
,"Failed to create file \"%s\", writing trace information to stderr.\n",tracefile
);
657 sim_close (sd
, quitting
)
662 printf("DBG: sim_close: entered (quitting = %d)\n",quitting
);
665 /* start-sanitize-sky */
667 sky_command_options_close (sd
);
669 /* end-sanitize-sky */
672 /* "quitting" is non-zero if we cannot hang on errors */
674 /* Ensure that any resources allocated through the callback
675 mechanism are released: */
676 sim_io_shutdown (sd
);
679 if (tracefh
!= NULL
&& tracefh
!= stderr
)
684 /* FIXME - free SD */
691 sim_write (sd
,addr
,buffer
,size
)
694 unsigned char *buffer
;
698 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
700 /* Return the number of bytes written, or zero if error. */
702 sim_io_printf(sd
,"sim_write(0x%s,buffer,%d);\n",pr_addr(addr
),size
);
705 /* We use raw read and write routines, since we do not want to count
706 the GDB memory accesses in our statistics gathering. */
708 for (index
= 0; index
< size
; index
++)
710 address_word vaddr
= (address_word
)addr
+ index
;
713 if (!address_translation (SD
, CPU
, NULL_CIA
, vaddr
, isDATA
, isSTORE
, &paddr
, &cca
, isRAW
))
715 if (sim_core_write_buffer (SD
, CPU
, read_map
, buffer
+ index
, paddr
, 1) != 1)
723 sim_read (sd
,addr
,buffer
,size
)
726 unsigned char *buffer
;
730 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
732 /* Return the number of bytes read, or zero if error. */
734 sim_io_printf(sd
,"sim_read(0x%s,buffer,%d);\n",pr_addr(addr
),size
);
737 for (index
= 0; (index
< size
); index
++)
739 address_word vaddr
= (address_word
)addr
+ index
;
742 if (!address_translation (SD
, CPU
, NULL_CIA
, vaddr
, isDATA
, isLOAD
, &paddr
, &cca
, isRAW
))
744 if (sim_core_read_buffer (SD
, CPU
, read_map
, buffer
+ index
, paddr
, 1) != 1)
752 sim_store_register (sd
,rn
,memory
,length
)
755 unsigned char *memory
;
758 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
759 /* NOTE: gdb (the client) stores registers in target byte order
760 while the simulator uses host byte order */
762 sim_io_printf(sd
,"sim_store_register(%d,*memory=0x%s);\n",rn
,pr_addr(*((SIM_ADDR
*)memory
)));
765 /* Unfortunately this suffers from the same problem as the register
766 numbering one. We need to know what the width of each logical
767 register number is for the architecture being simulated. */
769 if (cpu
->register_widths
[rn
] == 0)
771 sim_io_eprintf(sd
,"Invalid register width for %d (register store ignored)\n",rn
);
775 /* start-sanitize-r5900 */
776 if (rn
>= 90 && rn
< 90 + 32)
778 GPR1
[rn
- 90] = T2H_8 (*(unsigned64
*)memory
);
784 SA
= T2H_8(*(unsigned64
*)memory
);
786 case 122: /* FIXME */
787 LO1
= T2H_8(*(unsigned64
*)memory
);
789 case 123: /* FIXME */
790 HI1
= T2H_8(*(unsigned64
*)memory
);
793 /* end-sanitize-r5900 */
795 /* start-sanitize-sky */
797 if (rn
>= NUM_R5900_REGS
)
799 rn
= rn
- NUM_R5900_REGS
;
801 if( rn
< NUM_VU_REGS
)
803 if (rn
< NUM_VU_INTEGER_REGS
)
804 return write_vu_int_reg (&(vu0_device
.regs
), rn
, memory
);
805 else if (rn
>= FIRST_VEC_REG
)
808 return write_vu_vec_reg (&(vu0_device
.regs
), rn
>>2, rn
&3,
811 else switch (rn
- NUM_VU_INTEGER_REGS
)
814 return write_vu_special_reg (&vu0_device
, VU_REG_CIA
,
817 return write_vu_misc_reg (&(vu0_device
.regs
), VU_REG_MR
,
819 case 2: /* VU0 has no P register */
822 return write_vu_misc_reg (&(vu0_device
.regs
), VU_REG_MI
,
825 return write_vu_misc_reg (&(vu0_device
.regs
), VU_REG_MQ
,
828 return write_vu_acc_reg (&(vu0_device
.regs
),
829 rn
- (NUM_VU_INTEGER_REGS
+ 5),
834 rn
= rn
- NUM_VU_REGS
;
836 if (rn
< NUM_VU_REGS
)
838 if (rn
< NUM_VU_INTEGER_REGS
)
839 return write_vu_int_reg (&(vu1_device
.regs
), rn
, memory
);
840 else if (rn
>= FIRST_VEC_REG
)
843 return write_vu_vec_reg (&(vu1_device
.regs
),
844 rn
>> 2, rn
& 3, memory
);
846 else switch (rn
- NUM_VU_INTEGER_REGS
)
849 return write_vu_special_reg (&vu1_device
, VU_REG_CIA
,
852 return write_vu_misc_reg (&(vu1_device
.regs
), VU_REG_MR
,
855 return write_vu_misc_reg (&(vu1_device
.regs
), VU_REG_MP
,
858 return write_vu_misc_reg (&(vu1_device
.regs
), VU_REG_MI
,
861 return write_vu_misc_reg (&(vu1_device
.regs
), VU_REG_MQ
,
864 return write_vu_acc_reg (&(vu1_device
.regs
),
865 rn
- (NUM_VU_INTEGER_REGS
+ 5),
870 rn
-= NUM_VU_REGS
; /* VIF0 registers are next */
872 if (rn
< NUM_VIF_REGS
)
874 if (rn
< NUM_VIF_REGS
-1)
875 return write_pke_reg (&pke0_device
, rn
, memory
);
878 sim_io_eprintf( sd
, "Can't write vif0_pc (store ignored)\n" );
883 rn
-= NUM_VIF_REGS
; /* VIF1 registers are last */
885 if (rn
< NUM_VIF_REGS
)
887 if (rn
< NUM_VIF_REGS
-1)
888 return write_pke_reg (&pke1_device
, rn
, memory
);
891 sim_io_eprintf( sd
, "Can't write vif1_pc (store ignored)\n" );
896 sim_io_eprintf( sd
, "Invalid VU register (register store ignored)\n" );
900 /* end-sanitize-sky */
902 if (rn
>= FGRIDX
&& rn
< FGRIDX
+ NR_FGR
)
904 if (cpu
->register_widths
[rn
] == 32)
906 cpu
->fgr
[rn
- FGRIDX
] = T2H_4 (*(unsigned32
*)memory
);
911 cpu
->fgr
[rn
- FGRIDX
] = T2H_8 (*(unsigned64
*)memory
);
916 if (cpu
->register_widths
[rn
] == 32)
918 cpu
->registers
[rn
] = T2H_4 (*(unsigned32
*)memory
);
923 cpu
->registers
[rn
] = T2H_8 (*(unsigned64
*)memory
);
931 sim_fetch_register (sd
,rn
,memory
,length
)
934 unsigned char *memory
;
937 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
938 /* NOTE: gdb (the client) stores registers in target byte order
939 while the simulator uses host byte order */
941 sim_io_printf(sd
,"sim_fetch_register(%d=0x%s,mem) : place simulator registers into memory\n",rn
,pr_addr(registers
[rn
]));
944 if (cpu
->register_widths
[rn
] == 0)
946 sim_io_eprintf (sd
, "Invalid register width for %d (register fetch ignored)\n",rn
);
950 /* start-sanitize-r5900 */
951 if (rn
>= 90 && rn
< 90 + 32)
953 *((unsigned64
*)memory
) = H2T_8 (GPR1
[rn
- 90]);
959 *((unsigned64
*)memory
) = H2T_8(SA
);
961 case 122: /* FIXME */
962 *((unsigned64
*)memory
) = H2T_8(LO1
);
964 case 123: /* FIXME */
965 *((unsigned64
*)memory
) = H2T_8(HI1
);
968 /* end-sanitize-r5900 */
970 /* start-sanitize-sky */
972 if (rn
>= NUM_R5900_REGS
)
974 rn
= rn
- NUM_R5900_REGS
;
976 if (rn
< NUM_VU_REGS
)
978 if (rn
< NUM_VU_INTEGER_REGS
)
979 return read_vu_int_reg (&(vu0_device
.regs
), rn
, memory
);
980 else if (rn
>= FIRST_VEC_REG
)
983 return read_vu_vec_reg (&(vu0_device
.regs
), rn
>>2, rn
& 3,
986 else switch (rn
- NUM_VU_INTEGER_REGS
)
989 return read_vu_special_reg(&vu0_device
, VU_REG_CIA
, memory
);
991 return read_vu_misc_reg (&(vu0_device
.regs
), VU_REG_MR
,
993 case 2: /* VU0 has no P register */
994 *((int *) memory
) = 0;
997 return read_vu_misc_reg (&(vu0_device
.regs
), VU_REG_MI
,
1000 return read_vu_misc_reg (&(vu0_device
.regs
), VU_REG_MQ
,
1003 return read_vu_acc_reg (&(vu0_device
.regs
),
1004 rn
- (NUM_VU_INTEGER_REGS
+ 5),
1009 rn
-= NUM_VU_REGS
; /* VU1 registers are next */
1011 if (rn
< NUM_VU_REGS
)
1013 if (rn
< NUM_VU_INTEGER_REGS
)
1014 return read_vu_int_reg (&(vu1_device
.regs
), rn
, memory
);
1015 else if (rn
>= FIRST_VEC_REG
)
1017 rn
-= FIRST_VEC_REG
;
1018 return read_vu_vec_reg (&(vu1_device
.regs
),
1019 rn
>> 2, rn
& 3, memory
);
1021 else switch (rn
- NUM_VU_INTEGER_REGS
)
1024 return read_vu_special_reg(&vu1_device
, VU_REG_CIA
, memory
);
1026 return read_vu_misc_reg (&(vu1_device
.regs
),
1029 return read_vu_misc_reg (&(vu1_device
.regs
),
1032 return read_vu_misc_reg (&(vu1_device
.regs
),
1035 return read_vu_misc_reg (&(vu1_device
.regs
),
1038 return read_vu_acc_reg (&(vu1_device
.regs
),
1039 rn
- (NUM_VU_INTEGER_REGS
+ 5),
1044 rn
-= NUM_VU_REGS
; /* VIF0 registers are next */
1046 if (rn
< NUM_VIF_REGS
)
1048 if (rn
< NUM_VIF_REGS
-2)
1049 return read_pke_reg (&pke0_device
, rn
, memory
);
1050 else if (rn
== NUM_VIF_REGS
-2)
1051 return read_pke_pc (&pke0_device
, memory
);
1053 return read_pke_pcx (&pke0_device
, memory
);
1056 rn
-= NUM_VIF_REGS
; /* VIF1 registers are last */
1058 if (rn
< NUM_VIF_REGS
)
1060 if (rn
< NUM_VIF_REGS
-2)
1061 return read_pke_reg (&pke1_device
, rn
, memory
);
1062 else if (rn
== NUM_VIF_REGS
-2)
1063 return read_pke_pc (&pke1_device
, memory
);
1065 return read_pke_pcx (&pke1_device
, memory
);
1068 sim_io_eprintf( sd
, "Invalid VU register (register fetch ignored)\n" );
1071 /* end-sanitize-sky */
1073 /* Any floating point register */
1074 if (rn
>= FGRIDX
&& rn
< FGRIDX
+ NR_FGR
)
1076 if (cpu
->register_widths
[rn
] == 32)
1078 *(unsigned32
*)memory
= H2T_4 (cpu
->fgr
[rn
- FGRIDX
]);
1083 *(unsigned64
*)memory
= H2T_8 (cpu
->fgr
[rn
- FGRIDX
]);
1088 if (cpu
->register_widths
[rn
] == 32)
1090 *(unsigned32
*)memory
= H2T_4 ((unsigned32
)(cpu
->registers
[rn
]));
1095 *(unsigned64
*)memory
= H2T_8 ((unsigned64
)(cpu
->registers
[rn
]));
1104 sim_create_inferior (sd
, abfd
, argv
,env
)
1112 printf("DBG: sim_create_inferior entered: start_address = 0x%s\n",
1120 /* override PC value set by ColdReset () */
1122 for (cpu_nr
= 0; cpu_nr
< sim_engine_nr_cpus (sd
); cpu_nr
++)
1124 sim_cpu
*cpu
= STATE_CPU (sd
, cpu_nr
);
1125 CIA_SET (cpu
, (unsigned64
) bfd_get_start_address (abfd
));
1129 #if 0 /* def DEBUG */
1132 /* We should really place the argv slot values into the argument
1133 registers, and onto the stack as required. However, this
1134 assumes that we have a stack defined, which is not
1135 necessarily true at the moment. */
1137 sim_io_printf(sd
,"sim_create_inferior() : passed arguments ignored\n");
1138 for (cptr
= argv
; (cptr
&& *cptr
); cptr
++)
1139 printf("DBG: arg \"%s\"\n",*cptr
);
1147 sim_do_command (sd
,cmd
)
1151 if (sim_args_command (sd
, cmd
) != SIM_RC_OK
)
1152 sim_io_printf (sd
, "Error: \"%s\" is not a valid MIPS simulator command.\n",
1156 /*---------------------------------------------------------------------------*/
1157 /*-- Private simulator support interface ------------------------------------*/
1158 /*---------------------------------------------------------------------------*/
1160 /* Read a null terminated string from memory, return in a buffer */
1162 fetch_str (sd
, addr
)
1169 while (sim_read (sd
, addr
+ nr
, &null
, 1) == 1 && null
!= 0)
1171 buf
= NZALLOC (char, nr
+ 1);
1172 sim_read (sd
, addr
, buf
, nr
);
1176 /* Simple monitor interface (currently setup for the IDT and PMON monitors) */
1178 sim_monitor (SIM_DESC sd
,
1181 unsigned int reason
)
1184 printf("DBG: sim_monitor: entered (reason = %d)\n",reason
);
1187 /* The IDT monitor actually allows two instructions per vector
1188 slot. However, the simulator currently causes a trap on each
1189 individual instruction. We cheat, and lose the bottom bit. */
1192 /* The following callback functions are available, however the
1193 monitor we are simulating does not make use of them: get_errno,
1194 isatty, lseek, rename, system, time and unlink */
1198 case 6: /* int open(char *path,int flags) */
1200 char *path
= fetch_str (sd
, A0
);
1201 V0
= sim_io_open (sd
, path
, (int)A1
);
1206 case 7: /* int read(int file,char *ptr,int len) */
1210 char *buf
= zalloc (nr
);
1211 V0
= sim_io_read (sd
, fd
, buf
, nr
);
1212 sim_write (sd
, A1
, buf
, nr
);
1217 case 8: /* int write(int file,char *ptr,int len) */
1221 char *buf
= zalloc (nr
);
1222 sim_read (sd
, A1
, buf
, nr
);
1223 V0
= sim_io_write (sd
, fd
, buf
, nr
);
1228 case 10: /* int close(int file) */
1230 V0
= sim_io_close (sd
, (int)A0
);
1234 case 2: /* Densan monitor: char inbyte(int waitflag) */
1236 if (A0
== 0) /* waitflag == NOWAIT */
1237 V0
= (unsigned_word
)-1;
1239 /* Drop through to case 11 */
1241 case 11: /* char inbyte(void) */
1244 if (sim_io_read_stdin (sd
, &tmp
, sizeof(char)) != sizeof(char))
1246 sim_io_error(sd
,"Invalid return from character read");
1247 V0
= (unsigned_word
)-1;
1250 V0
= (unsigned_word
)tmp
;
1254 case 3: /* Densan monitor: void co(char chr) */
1255 case 12: /* void outbyte(char chr) : write a byte to "stdout" */
1257 char tmp
= (char)(A0
& 0xFF);
1258 sim_io_write_stdout (sd
, &tmp
, sizeof(char));
1262 case 17: /* void _exit() */
1264 sim_io_eprintf (sd
, "sim_monitor(17): _exit(int reason) to be coded\n");
1265 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
, sim_exited
,
1266 (unsigned int)(A0
& 0xFFFFFFFF));
1270 case 28 : /* PMON flush_cache */
1273 case 55: /* void get_mem_info(unsigned int *ptr) */
1274 /* in: A0 = pointer to three word memory location */
1275 /* out: [A0 + 0] = size */
1276 /* [A0 + 4] = instruction cache size */
1277 /* [A0 + 8] = data cache size */
1279 unsigned_4 value
= MEM_SIZE
/* FIXME STATE_MEM_SIZE (sd) */;
1280 unsigned_4 zero
= 0;
1282 sim_write (sd
, A0
+ 0, (char *)&value
, 4);
1283 sim_write (sd
, A0
+ 4, (char *)&zero
, 4);
1284 sim_write (sd
, A0
+ 8, (char *)&zero
, 4);
1285 /* sim_io_eprintf (sd, "sim: get_mem_info() depreciated\n"); */
1289 case 158 : /* PMON printf */
1290 /* in: A0 = pointer to format string */
1291 /* A1 = optional argument 1 */
1292 /* A2 = optional argument 2 */
1293 /* A3 = optional argument 3 */
1295 /* The following is based on the PMON printf source */
1297 address_word s
= A0
;
1299 signed_word
*ap
= &A1
; /* 1st argument */
1300 /* This isn't the quickest way, since we call the host print
1301 routine for every character almost. But it does avoid
1302 having to allocate and manage a temporary string buffer. */
1303 /* TODO: Include check that we only use three arguments (A1,
1305 while (sim_read (sd
, s
++, &c
, 1) && c
!= '\0')
1310 enum {FMT_RJUST
, FMT_LJUST
, FMT_RJUST0
, FMT_CENTER
} fmt
= FMT_RJUST
;
1311 int width
= 0, trunc
= 0, haddot
= 0, longlong
= 0;
1312 while (sim_read (sd
, s
++, &c
, 1) && c
!= '\0')
1314 if (strchr ("dobxXulscefg%", c
))
1329 else if (c
>= '1' && c
<= '9')
1333 while (sim_read (sd
, s
++, &c
, 1) == 1 && isdigit (c
))
1336 n
= (unsigned int)strtol(tmp
,NULL
,10);
1349 sim_io_printf (sd
, "%%");
1354 address_word p
= *ap
++;
1356 while (sim_read (sd
, p
++, &ch
, 1) == 1 && ch
!= '\0')
1357 sim_io_printf(sd
, "%c", ch
);
1360 sim_io_printf(sd
,"(null)");
1363 sim_io_printf (sd
, "%c", (int)*ap
++);
1368 sim_read (sd
, s
++, &c
, 1);
1372 sim_read (sd
, s
++, &c
, 1);
1375 if (strchr ("dobxXu", c
))
1377 word64 lv
= (word64
) *ap
++;
1379 sim_io_printf(sd
,"<binary not supported>");
1382 sprintf (tmp
, "%%%s%c", longlong
? "ll" : "", c
);
1384 sim_io_printf(sd
, tmp
, lv
);
1386 sim_io_printf(sd
, tmp
, (int)lv
);
1389 else if (strchr ("eEfgG", c
))
1391 double dbl
= *(double*)(ap
++);
1392 sprintf (tmp
, "%%%d.%d%c", width
, trunc
, c
);
1393 sim_io_printf (sd
, tmp
, dbl
);
1399 sim_io_printf(sd
, "%c", c
);
1405 sim_io_error (sd
, "TODO: sim_monitor(%d) : PC = 0x%s\n",
1406 reason
, pr_addr(cia
));
1412 /* Store a word into memory. */
1415 store_word (SIM_DESC sd
,
1424 if ((vaddr
& 3) != 0)
1425 SignalExceptionAddressStore ();
1428 if (AddressTranslation (vaddr
, isDATA
, isSTORE
, &paddr
, &uncached
,
1431 const uword64 mask
= 7;
1435 paddr
= (paddr
& ~mask
) | ((paddr
& mask
) ^ (ReverseEndian
<< 2));
1436 byte
= (vaddr
& mask
) ^ (BigEndianCPU
<< 2);
1437 memval
= ((uword64
) val
) << (8 * byte
);
1438 StoreMemory (uncached
, AccessLength_WORD
, memval
, 0, paddr
, vaddr
,
1444 /* Load a word from memory. */
1447 load_word (SIM_DESC sd
,
1452 if ((vaddr
& 3) != 0)
1453 SignalExceptionAddressLoad ();
1459 if (AddressTranslation (vaddr
, isDATA
, isLOAD
, &paddr
, &uncached
,
1462 const uword64 mask
= 0x7;
1463 const unsigned int reverse
= ReverseEndian
? 1 : 0;
1464 const unsigned int bigend
= BigEndianCPU
? 1 : 0;
1468 paddr
= (paddr
& ~mask
) | ((paddr
& mask
) ^ (reverse
<< 2));
1469 LoadMemory (&memval
,NULL
,uncached
, AccessLength_WORD
, paddr
, vaddr
,
1471 byte
= (vaddr
& mask
) ^ (bigend
<< 2);
1472 return SIGNEXTEND (((memval
>> (8 * byte
)) & 0xffffffff), 32);
1479 /* Simulate the mips16 entry and exit pseudo-instructions. These
1480 would normally be handled by the reserved instruction exception
1481 code, but for ease of simulation we just handle them directly. */
1484 mips16_entry (SIM_DESC sd
,
1489 int aregs
, sregs
, rreg
;
1492 printf("DBG: mips16_entry: entered (insn = 0x%08X)\n",insn
);
1495 aregs
= (insn
& 0x700) >> 8;
1496 sregs
= (insn
& 0x0c0) >> 6;
1497 rreg
= (insn
& 0x020) >> 5;
1499 /* This should be checked by the caller. */
1508 /* This is the entry pseudo-instruction. */
1510 for (i
= 0; i
< aregs
; i
++)
1511 store_word (SD
, CPU
, cia
, (uword64
) (SP
+ 4 * i
), GPR
[i
+ 4]);
1519 store_word (SD
, CPU
, cia
, (uword64
) tsp
, RA
);
1522 for (i
= 0; i
< sregs
; i
++)
1525 store_word (SD
, CPU
, cia
, (uword64
) tsp
, GPR
[16 + i
]);
1533 /* This is the exit pseudo-instruction. */
1540 RA
= load_word (SD
, CPU
, cia
, (uword64
) tsp
);
1543 for (i
= 0; i
< sregs
; i
++)
1546 GPR
[i
+ 16] = load_word (SD
, CPU
, cia
, (uword64
) tsp
);
1551 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
1555 FGR
[0] = WORD64LO (GPR
[4]);
1556 FPR_STATE
[0] = fmt_uninterpreted
;
1558 else if (aregs
== 6)
1560 FGR
[0] = WORD64LO (GPR
[5]);
1561 FGR
[1] = WORD64LO (GPR
[4]);
1562 FPR_STATE
[0] = fmt_uninterpreted
;
1563 FPR_STATE
[1] = fmt_uninterpreted
;
1572 /*-- trace support ----------------------------------------------------------*/
1574 /* The TRACE support is provided (if required) in the memory accessing
1575 routines. Since we are also providing the architecture specific
1576 features, the architecture simulation code can also deal with
1577 notifying the TRACE world of cache flushes, etc. Similarly we do
1578 not need to provide profiling support in the simulator engine,
1579 since we can sample in the instruction fetch control loop. By
1580 defining the TRACE manifest, we add tracing as a run-time
1584 /* Tracing by default produces "din" format (as required by
1585 dineroIII). Each line of such a trace file *MUST* have a din label
1586 and address field. The rest of the line is ignored, so comments can
1587 be included if desired. The first field is the label which must be
1588 one of the following values:
1593 3 escape record (treated as unknown access type)
1594 4 escape record (causes cache flush)
1596 The address field is a 32bit (lower-case) hexadecimal address
1597 value. The address should *NOT* be preceded by "0x".
1599 The size of the memory transfer is not important when dealing with
1600 cache lines (as long as no more than a cache line can be
1601 transferred in a single operation :-), however more information
1602 could be given following the dineroIII requirement to allow more
1603 complete memory and cache simulators to provide better
1604 results. i.e. the University of Pisa has a cache simulator that can
1605 also take bus size and speed as (variable) inputs to calculate
1606 complete system performance (a much more useful ability when trying
1607 to construct an end product, rather than a processor). They
1608 currently have an ARM version of their tool called ChARM. */
1612 dotrace (SIM_DESC sd
,
1620 if (STATE
& simTRACE
) {
1622 fprintf(tracefh
,"%d %s ; width %d ; ",
1626 va_start(ap
,comment
);
1627 vfprintf(tracefh
,comment
,ap
);
1629 fprintf(tracefh
,"\n");
1631 /* NOTE: Since the "din" format will only accept 32bit addresses, and
1632 we may be generating 64bit ones, we should put the hi-32bits of the
1633 address into the comment field. */
1635 /* TODO: Provide a buffer for the trace lines. We can then avoid
1636 performing writes until the buffer is filled, or the file is
1639 /* NOTE: We could consider adding a comment field to the "din" file
1640 produced using type 3 markers (unknown access). This would then
1641 allow information about the program that the "din" is for, and
1642 the MIPs world that was being simulated, to be placed into the
1649 /*---------------------------------------------------------------------------*/
1650 /*-- simulator engine -------------------------------------------------------*/
1651 /*---------------------------------------------------------------------------*/
1654 ColdReset (SIM_DESC sd
)
1657 for (cpu_nr
= 0; cpu_nr
< sim_engine_nr_cpus (sd
); cpu_nr
++)
1659 sim_cpu
*cpu
= STATE_CPU (sd
, cpu_nr
);
1660 /* RESET: Fixed PC address: */
1661 PC
= (unsigned_word
) UNSIGNED64 (0xFFFFFFFFBFC00000);
1662 /* The reset vector address is in the unmapped, uncached memory space. */
1664 SR
&= ~(status_SR
| status_TS
| status_RP
);
1665 SR
|= (status_ERL
| status_BEV
);
1667 /* Cheat and allow access to the complete register set immediately */
1668 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
1669 && WITH_TARGET_WORD_BITSIZE
== 64)
1670 SR
|= status_FR
; /* 64bit registers */
1672 /* Ensure that any instructions with pending register updates are
1674 PENDING_INVALIDATE();
1676 /* Initialise the FPU registers to the unknown state */
1677 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
1680 for (rn
= 0; (rn
< 32); rn
++)
1681 FPR_STATE
[rn
] = fmt_uninterpreted
;
1687 /* Description from page A-26 of the "MIPS IV Instruction Set" manual (revision 3.1) */
1688 /* Signal an exception condition. This will result in an exception
1689 that aborts the instruction. The instruction operation pseudocode
1690 will never see a return from this function call. */
1693 signal_exception (SIM_DESC sd
,
1701 sim_io_printf(sd
,"DBG: SignalException(%d) PC = 0x%s\n",exception
,pr_addr(cia
));
1704 /* Ensure that any active atomic read/modify/write operation will fail: */
1707 switch (exception
) {
1709 case DebugBreakPoint
:
1710 if (! (Debug
& Debug_DM
))
1716 Debug
|= Debug_DBD
; /* signaled from within in delay slot */
1717 DEPC
= cia
- 4; /* reference the branch instruction */
1721 Debug
&= ~Debug_DBD
; /* not signaled from within a delay slot */
1725 Debug
|= Debug_DM
; /* in debugging mode */
1726 Debug
|= Debug_DBp
; /* raising a DBp exception */
1728 sim_engine_restart (SD
, CPU
, NULL
, NULL_CIA
);
1732 case ReservedInstruction
:
1735 unsigned int instruction
;
1736 va_start(ap
,exception
);
1737 instruction
= va_arg(ap
,unsigned int);
1739 /* Provide simple monitor support using ReservedInstruction
1740 exceptions. The following code simulates the fixed vector
1741 entry points into the IDT monitor by causing a simulator
1742 trap, performing the monitor operation, and returning to
1743 the address held in the $ra register (standard PCS return
1744 address). This means we only need to pre-load the vector
1745 space with suitable instruction values. For systems were
1746 actual trap instructions are used, we would not need to
1747 perform this magic. */
1748 if ((instruction
& RSVD_INSTRUCTION_MASK
) == RSVD_INSTRUCTION
)
1750 sim_monitor (SD
, CPU
, cia
, ((instruction
>> RSVD_INSTRUCTION_ARG_SHIFT
) & RSVD_INSTRUCTION_ARG_MASK
) );
1751 /* NOTE: This assumes that a branch-and-link style
1752 instruction was used to enter the vector (which is the
1753 case with the current IDT monitor). */
1754 sim_engine_restart (SD
, CPU
, NULL
, RA
);
1756 /* Look for the mips16 entry and exit instructions, and
1757 simulate a handler for them. */
1758 else if ((cia
& 1) != 0
1759 && (instruction
& 0xf81f) == 0xe809
1760 && (instruction
& 0x0c0) != 0x0c0)
1762 mips16_entry (SD
, CPU
, cia
, instruction
);
1763 sim_engine_restart (sd
, NULL
, NULL
, NULL_CIA
);
1765 /* else fall through to normal exception processing */
1766 sim_io_eprintf(sd
,"ReservedInstruction at PC = 0x%s\n", pr_addr (cia
));
1770 /* Store exception code into current exception id variable (used
1773 /* TODO: If not simulating exceptions then stop the simulator
1774 execution. At the moment we always stop the simulation. */
1776 #ifdef SUBTARGET_R3900
1777 /* update interrupt-related registers */
1779 /* insert exception code in bits 6:2 */
1780 CAUSE
= LSMASKED32(CAUSE
, 31, 7) | LSINSERTED32(exception
, 6, 2);
1781 /* shift IE/KU history bits left */
1782 SR
= LSMASKED32(SR
, 31, 4) | LSINSERTED32(LSEXTRACTED32(SR
, 3, 0), 5, 2);
1784 if (STATE
& simDELAYSLOT
)
1786 STATE
&= ~simDELAYSLOT
;
1788 EPC
= (cia
- 4); /* reference the branch instruction */
1793 if (SR
& status_BEV
)
1794 PC
= (signed)0xBFC00000 + 0x180;
1796 PC
= (signed)0x80000000 + 0x080;
1798 /* See figure 5-17 for an outline of the code below */
1799 if (! (SR
& status_EXL
))
1801 CAUSE
= (exception
<< 2);
1802 if (STATE
& simDELAYSLOT
)
1804 STATE
&= ~simDELAYSLOT
;
1806 EPC
= (cia
- 4); /* reference the branch instruction */
1810 /* FIXME: TLB et.al. */
1811 /* vector = 0x180; */
1815 CAUSE
= (exception
<< 2);
1816 /* vector = 0x180; */
1819 /* Store exception code into current exception id variable (used
1822 if (SR
& status_BEV
)
1823 PC
= (signed)0xBFC00200 + 0x180;
1825 PC
= (signed)0x80000000 + 0x180;
1828 switch ((CAUSE
>> 2) & 0x1F)
1831 /* Interrupts arrive during event processing, no need to
1837 #ifdef SUBTARGET_3900
1838 /* Exception vector: BEV=0 BFC00000 / BEF=1 BFC00000 */
1839 PC
= (signed)0xBFC00000;
1840 #endif SUBTARGET_3900
1843 case TLBModification
:
1848 case InstructionFetch
:
1850 /* The following is so that the simulator will continue from the
1851 exception address on breakpoint operations. */
1853 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
,
1854 sim_stopped
, SIM_SIGBUS
);
1856 case ReservedInstruction
:
1857 case CoProcessorUnusable
:
1859 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
,
1860 sim_stopped
, SIM_SIGILL
);
1862 case IntegerOverflow
:
1864 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
,
1865 sim_stopped
, SIM_SIGFPE
);
1870 sim_engine_restart (SD
, CPU
, NULL
, PC
);
1875 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
,
1876 sim_stopped
, SIM_SIGTRAP
);
1878 default : /* Unknown internal exception */
1880 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
,
1881 sim_stopped
, SIM_SIGABRT
);
1885 case SimulatorFault
:
1889 va_start(ap
,exception
);
1890 msg
= va_arg(ap
,char *);
1892 sim_engine_abort (SD
, CPU
, NULL_CIA
,
1893 "FATAL: Simulator error \"%s\"\n",msg
);
1900 #if defined(WARN_RESULT)
1901 /* Description from page A-26 of the "MIPS IV Instruction Set" manual (revision 3.1) */
1902 /* This function indicates that the result of the operation is
1903 undefined. However, this should not affect the instruction
1904 stream. All that is meant to happen is that the destination
1905 register is set to an undefined result. To keep the simulator
1906 simple, we just don't bother updating the destination register, so
1907 the overall result will be undefined. If desired we can stop the
1908 simulator by raising a pseudo-exception. */
1909 #define UndefinedResult() undefined_result (sd,cia)
1911 undefined_result(sd
,cia
)
1915 sim_io_eprintf(sd
,"UndefinedResult: PC = 0x%s\n",pr_addr(cia
));
1916 #if 0 /* Disabled for the moment, since it actually happens a lot at the moment. */
1921 #endif /* WARN_RESULT */
1923 /*-- FPU support routines ---------------------------------------------------*/
1925 /* Numbers are held in normalized form. The SINGLE and DOUBLE binary
1926 formats conform to ANSI/IEEE Std 754-1985. */
1927 /* SINGLE precision floating:
1928 * seeeeeeeefffffffffffffffffffffff
1930 * e = 8bits = exponent
1931 * f = 23bits = fraction
1933 /* SINGLE precision fixed:
1934 * siiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
1936 * i = 31bits = integer
1938 /* DOUBLE precision floating:
1939 * seeeeeeeeeeeffffffffffffffffffffffffffffffffffffffffffffffffffff
1941 * e = 11bits = exponent
1942 * f = 52bits = fraction
1944 /* DOUBLE precision fixed:
1945 * siiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
1947 * i = 63bits = integer
1950 /* Extract sign-bit: */
1951 #define FP_S_s(v) (((v) & ((unsigned)1 << 31)) ? 1 : 0)
1952 #define FP_D_s(v) (((v) & ((uword64)1 << 63)) ? 1 : 0)
1953 /* Extract biased exponent: */
1954 #define FP_S_be(v) (((v) >> 23) & 0xFF)
1955 #define FP_D_be(v) (((v) >> 52) & 0x7FF)
1956 /* Extract unbiased Exponent: */
1957 #define FP_S_e(v) (FP_S_be(v) - 0x7F)
1958 #define FP_D_e(v) (FP_D_be(v) - 0x3FF)
1959 /* Extract complete fraction field: */
1960 #define FP_S_f(v) ((v) & ~((unsigned)0x1FF << 23))
1961 #define FP_D_f(v) ((v) & ~((uword64)0xFFF << 52))
1962 /* Extract numbered fraction bit: */
1963 #define FP_S_fb(b,v) (((v) & (1 << (23 - (b)))) ? 1 : 0)
1964 #define FP_D_fb(b,v) (((v) & (1 << (52 - (b)))) ? 1 : 0)
1966 /* Explicit QNaN values used when value required: */
1967 #define FPQNaN_SINGLE (0x7FBFFFFF)
1968 #define FPQNaN_WORD (0x7FFFFFFF)
1969 #define FPQNaN_DOUBLE (((uword64)0x7FF7FFFF << 32) | 0xFFFFFFFF)
1970 #define FPQNaN_LONG (((uword64)0x7FFFFFFF << 32) | 0xFFFFFFFF)
1972 /* Explicit Infinity values used when required: */
1973 #define FPINF_SINGLE (0x7F800000)
1974 #define FPINF_DOUBLE (((uword64)0x7FF00000 << 32) | 0x00000000)
1976 #if 1 /* def DEBUG */
1977 #define RMMODE(v) (((v) == FP_RM_NEAREST) ? "Round" : (((v) == FP_RM_TOZERO) ? "Trunc" : (((v) == FP_RM_TOPINF) ? "Ceil" : "Floor")))
1978 #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>"))))))
1982 value_fpr (SIM_DESC sd
,
1991 /* Treat unused register values, as fixed-point 64bit values: */
1992 if ((fmt
== fmt_uninterpreted
) || (fmt
== fmt_unknown
))
1994 /* If request to read data as "uninterpreted", then use the current
1996 fmt
= FPR_STATE
[fpr
];
2001 /* For values not yet accessed, set to the desired format: */
2002 if (FPR_STATE
[fpr
] == fmt_uninterpreted
) {
2003 FPR_STATE
[fpr
] = fmt
;
2005 printf("DBG: Register %d was fmt_uninterpreted. Now %s\n",fpr
,DOFMT(fmt
));
2008 if (fmt
!= FPR_STATE
[fpr
]) {
2009 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
));
2010 FPR_STATE
[fpr
] = fmt_unknown
;
2013 if (FPR_STATE
[fpr
] == fmt_unknown
) {
2014 /* Set QNaN value: */
2017 value
= FPQNaN_SINGLE
;
2021 value
= FPQNaN_DOUBLE
;
2025 value
= FPQNaN_WORD
;
2029 value
= FPQNaN_LONG
;
2036 } else if (SizeFGR() == 64) {
2040 value
= (FGR
[fpr
] & 0xFFFFFFFF);
2043 case fmt_uninterpreted
:
2057 value
= (FGR
[fpr
] & 0xFFFFFFFF);
2060 case fmt_uninterpreted
:
2063 if ((fpr
& 1) == 0) { /* even registers only */
2064 value
= ((((uword64
)FGR
[fpr
+1]) << 32) | (FGR
[fpr
] & 0xFFFFFFFF));
2066 SignalException(ReservedInstruction
,0);
2077 SignalExceptionSimulatorFault ("Unrecognised FP format in ValueFPR()");
2080 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());
2087 store_fpr (SIM_DESC sd
,
2097 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());
2100 if (SizeFGR() == 64) {
2102 case fmt_uninterpreted_32
:
2103 fmt
= fmt_uninterpreted
;
2106 FGR
[fpr
] = (((uword64
)0xDEADC0DE << 32) | (value
& 0xFFFFFFFF));
2107 FPR_STATE
[fpr
] = fmt
;
2110 case fmt_uninterpreted_64
:
2111 fmt
= fmt_uninterpreted
;
2112 case fmt_uninterpreted
:
2116 FPR_STATE
[fpr
] = fmt
;
2120 FPR_STATE
[fpr
] = fmt_unknown
;
2126 case fmt_uninterpreted_32
:
2127 fmt
= fmt_uninterpreted
;
2130 FGR
[fpr
] = (value
& 0xFFFFFFFF);
2131 FPR_STATE
[fpr
] = fmt
;
2134 case fmt_uninterpreted_64
:
2135 fmt
= fmt_uninterpreted
;
2136 case fmt_uninterpreted
:
2139 if ((fpr
& 1) == 0) { /* even register number only */
2140 FGR
[fpr
+1] = (value
>> 32);
2141 FGR
[fpr
] = (value
& 0xFFFFFFFF);
2142 FPR_STATE
[fpr
+ 1] = fmt
;
2143 FPR_STATE
[fpr
] = fmt
;
2145 FPR_STATE
[fpr
] = fmt_unknown
;
2146 FPR_STATE
[fpr
+ 1] = fmt_unknown
;
2147 SignalException(ReservedInstruction
,0);
2152 FPR_STATE
[fpr
] = fmt_unknown
;
2157 #if defined(WARN_RESULT)
2160 #endif /* WARN_RESULT */
2163 SignalExceptionSimulatorFault ("Unrecognised FP format in StoreFPR()");
2166 printf("DBG: StoreFPR: fpr[%d] = 0x%s (format %s)\n",fpr
,pr_addr(FGR
[fpr
]),DOFMT(fmt
));
2183 sim_fpu_32to (&wop
, op
);
2184 boolean
= sim_fpu_is_nan (&wop
);
2191 sim_fpu_64to (&wop
, op
);
2192 boolean
= sim_fpu_is_nan (&wop
);
2196 fprintf (stderr
, "Bad switch\n");
2201 printf("DBG: NaN: returning %d for 0x%s (format = %s)\n",boolean
,pr_addr(op
),DOFMT(fmt
));
2215 printf("DBG: Infinity: format %s 0x%s\n",DOFMT(fmt
),pr_addr(op
));
2222 sim_fpu_32to (&wop
, op
);
2223 boolean
= sim_fpu_is_infinity (&wop
);
2229 sim_fpu_64to (&wop
, op
);
2230 boolean
= sim_fpu_is_infinity (&wop
);
2234 printf("DBG: TODO: unrecognised format (%s) for Infinity check\n",DOFMT(fmt
));
2239 printf("DBG: Infinity: returning %d for 0x%s (format = %s)\n",boolean
,pr_addr(op
),DOFMT(fmt
));
2253 /* Argument checking already performed by the FPCOMPARE code */
2256 printf("DBG: Less: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2259 /* The format type should already have been checked: */
2265 sim_fpu_32to (&wop1
, op1
);
2266 sim_fpu_32to (&wop2
, op2
);
2267 boolean
= sim_fpu_is_lt (&wop1
, &wop2
);
2274 sim_fpu_64to (&wop1
, op1
);
2275 sim_fpu_64to (&wop2
, op2
);
2276 boolean
= sim_fpu_is_lt (&wop1
, &wop2
);
2280 fprintf (stderr
, "Bad switch\n");
2285 printf("DBG: Less: returning %d (format = %s)\n",boolean
,DOFMT(fmt
));
2299 /* Argument checking already performed by the FPCOMPARE code */
2302 printf("DBG: Equal: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2305 /* The format type should already have been checked: */
2311 sim_fpu_32to (&wop1
, op1
);
2312 sim_fpu_32to (&wop2
, op2
);
2313 boolean
= sim_fpu_is_eq (&wop1
, &wop2
);
2320 sim_fpu_64to (&wop1
, op1
);
2321 sim_fpu_64to (&wop2
, op2
);
2322 boolean
= sim_fpu_is_eq (&wop1
, &wop2
);
2326 fprintf (stderr
, "Bad switch\n");
2331 printf("DBG: Equal: returning %d (format = %s)\n",boolean
,DOFMT(fmt
));
2338 AbsoluteValue(op
,fmt
)
2345 printf("DBG: AbsoluteValue: %s: op = 0x%s\n",DOFMT(fmt
),pr_addr(op
));
2348 /* The format type should already have been checked: */
2354 sim_fpu_32to (&wop
, op
);
2355 sim_fpu_abs (&wop
, &wop
);
2356 sim_fpu_to32 (&ans
, &wop
);
2364 sim_fpu_64to (&wop
, op
);
2365 sim_fpu_abs (&wop
, &wop
);
2366 sim_fpu_to64 (&ans
, &wop
);
2371 fprintf (stderr
, "Bad switch\n");
2386 printf("DBG: Negate: %s: op = 0x%s\n",DOFMT(fmt
),pr_addr(op
));
2389 /* The format type should already have been checked: */
2395 sim_fpu_32to (&wop
, op
);
2396 sim_fpu_neg (&wop
, &wop
);
2397 sim_fpu_to32 (&ans
, &wop
);
2405 sim_fpu_64to (&wop
, op
);
2406 sim_fpu_neg (&wop
, &wop
);
2407 sim_fpu_to64 (&ans
, &wop
);
2412 fprintf (stderr
, "Bad switch\n");
2428 printf("DBG: Add: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2431 /* The registers must specify FPRs valid for operands of type
2432 "fmt". If they are not valid, the result is undefined. */
2434 /* The format type should already have been checked: */
2442 sim_fpu_32to (&wop1
, op1
);
2443 sim_fpu_32to (&wop2
, op2
);
2444 sim_fpu_add (&ans
, &wop1
, &wop2
);
2445 sim_fpu_to32 (&res
, &ans
);
2455 sim_fpu_64to (&wop1
, op1
);
2456 sim_fpu_64to (&wop2
, op2
);
2457 sim_fpu_add (&ans
, &wop1
, &wop2
);
2458 sim_fpu_to64 (&res
, &ans
);
2463 fprintf (stderr
, "Bad switch\n");
2468 printf("DBG: Add: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2483 printf("DBG: Sub: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2486 /* The registers must specify FPRs valid for operands of type
2487 "fmt". If they are not valid, the result is undefined. */
2489 /* The format type should already have been checked: */
2497 sim_fpu_32to (&wop1
, op1
);
2498 sim_fpu_32to (&wop2
, op2
);
2499 sim_fpu_sub (&ans
, &wop1
, &wop2
);
2500 sim_fpu_to32 (&res
, &ans
);
2510 sim_fpu_64to (&wop1
, op1
);
2511 sim_fpu_64to (&wop2
, op2
);
2512 sim_fpu_sub (&ans
, &wop1
, &wop2
);
2513 sim_fpu_to64 (&res
, &ans
);
2518 fprintf (stderr
, "Bad switch\n");
2523 printf("DBG: Sub: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2530 Multiply(op1
,op2
,fmt
)
2538 printf("DBG: Multiply: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2541 /* The registers must specify FPRs valid for operands of type
2542 "fmt". If they are not valid, the result is undefined. */
2544 /* The format type should already have been checked: */
2552 sim_fpu_32to (&wop1
, op1
);
2553 sim_fpu_32to (&wop2
, op2
);
2554 sim_fpu_mul (&ans
, &wop1
, &wop2
);
2555 sim_fpu_to32 (&res
, &ans
);
2565 sim_fpu_64to (&wop1
, op1
);
2566 sim_fpu_64to (&wop2
, op2
);
2567 sim_fpu_mul (&ans
, &wop1
, &wop2
);
2568 sim_fpu_to64 (&res
, &ans
);
2573 fprintf (stderr
, "Bad switch\n");
2578 printf("DBG: Multiply: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2593 printf("DBG: Divide: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2596 /* The registers must specify FPRs valid for operands of type
2597 "fmt". If they are not valid, the result is undefined. */
2599 /* The format type should already have been checked: */
2607 sim_fpu_32to (&wop1
, op1
);
2608 sim_fpu_32to (&wop2
, op2
);
2609 sim_fpu_div (&ans
, &wop1
, &wop2
);
2610 sim_fpu_to32 (&res
, &ans
);
2620 sim_fpu_64to (&wop1
, op1
);
2621 sim_fpu_64to (&wop2
, op2
);
2622 sim_fpu_div (&ans
, &wop1
, &wop2
);
2623 sim_fpu_to64 (&res
, &ans
);
2628 fprintf (stderr
, "Bad switch\n");
2633 printf("DBG: Divide: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2647 printf("DBG: Recip: %s: op = 0x%s\n",DOFMT(fmt
),pr_addr(op
));
2650 /* The registers must specify FPRs valid for operands of type
2651 "fmt". If they are not valid, the result is undefined. */
2653 /* The format type should already have been checked: */
2660 sim_fpu_32to (&wop
, op
);
2661 sim_fpu_inv (&ans
, &wop
);
2662 sim_fpu_to32 (&res
, &ans
);
2671 sim_fpu_64to (&wop
, op
);
2672 sim_fpu_inv (&ans
, &wop
);
2673 sim_fpu_to64 (&res
, &ans
);
2678 fprintf (stderr
, "Bad switch\n");
2683 printf("DBG: Recip: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2697 printf("DBG: SquareRoot: %s: op = 0x%s\n",DOFMT(fmt
),pr_addr(op
));
2700 /* The registers must specify FPRs valid for operands of type
2701 "fmt". If they are not valid, the result is undefined. */
2703 /* The format type should already have been checked: */
2710 sim_fpu_32to (&wop
, op
);
2711 sim_fpu_sqrt (&ans
, &wop
);
2712 sim_fpu_to32 (&res
, &ans
);
2721 sim_fpu_64to (&wop
, op
);
2722 sim_fpu_sqrt (&ans
, &wop
);
2723 sim_fpu_to64 (&res
, &ans
);
2728 fprintf (stderr
, "Bad switch\n");
2733 printf("DBG: SquareRoot: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2749 printf("DBG: Max: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2752 /* The registers must specify FPRs valid for operands of type
2753 "fmt". If they are not valid, the result is undefined. */
2755 /* The format type should already have been checked: */
2762 sim_fpu_32to (&wop1
, op1
);
2763 sim_fpu_32to (&wop2
, op2
);
2764 cmp
= sim_fpu_cmp (&wop1
, &wop2
);
2771 sim_fpu_64to (&wop1
, op1
);
2772 sim_fpu_64to (&wop2
, op2
);
2773 cmp
= sim_fpu_cmp (&wop1
, &wop2
);
2777 fprintf (stderr
, "Bad switch\n");
2783 case SIM_FPU_IS_SNAN
:
2784 case SIM_FPU_IS_QNAN
:
2786 case SIM_FPU_IS_NINF
:
2787 case SIM_FPU_IS_NNUMBER
:
2788 case SIM_FPU_IS_NDENORM
:
2789 case SIM_FPU_IS_NZERO
:
2790 result
= op2
; /* op1 - op2 < 0 */
2791 case SIM_FPU_IS_PINF
:
2792 case SIM_FPU_IS_PNUMBER
:
2793 case SIM_FPU_IS_PDENORM
:
2794 case SIM_FPU_IS_PZERO
:
2795 result
= op1
; /* op1 - op2 > 0 */
2797 fprintf (stderr
, "Bad switch\n");
2802 printf("DBG: Max: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2819 printf("DBG: Min: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2822 /* The registers must specify FPRs valid for operands of type
2823 "fmt". If they are not valid, the result is undefined. */
2825 /* The format type should already have been checked: */
2832 sim_fpu_32to (&wop1
, op1
);
2833 sim_fpu_32to (&wop2
, op2
);
2834 cmp
= sim_fpu_cmp (&wop1
, &wop2
);
2841 sim_fpu_64to (&wop1
, op1
);
2842 sim_fpu_64to (&wop2
, op2
);
2843 cmp
= sim_fpu_cmp (&wop1
, &wop2
);
2847 fprintf (stderr
, "Bad switch\n");
2853 case SIM_FPU_IS_SNAN
:
2854 case SIM_FPU_IS_QNAN
:
2856 case SIM_FPU_IS_NINF
:
2857 case SIM_FPU_IS_NNUMBER
:
2858 case SIM_FPU_IS_NDENORM
:
2859 case SIM_FPU_IS_NZERO
:
2860 result
= op1
; /* op1 - op2 < 0 */
2861 case SIM_FPU_IS_PINF
:
2862 case SIM_FPU_IS_PNUMBER
:
2863 case SIM_FPU_IS_PDENORM
:
2864 case SIM_FPU_IS_PZERO
:
2865 result
= op2
; /* op1 - op2 > 0 */
2867 fprintf (stderr
, "Bad switch\n");
2872 printf("DBG: Min: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2880 convert (SIM_DESC sd
,
2889 sim_fpu_round round
;
2890 unsigned32 result32
;
2891 unsigned64 result64
;
2894 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
));
2900 /* Round result to nearest representable value. When two
2901 representable values are equally near, round to the value
2902 that has a least significant bit of zero (i.e. is even). */
2903 round
= sim_fpu_round_near
;
2906 /* Round result to the value closest to, and not greater in
2907 magnitude than, the result. */
2908 round
= sim_fpu_round_zero
;
2911 /* Round result to the value closest to, and not less than,
2913 round
= sim_fpu_round_up
;
2917 /* Round result to the value closest to, and not greater than,
2919 round
= sim_fpu_round_down
;
2923 fprintf (stderr
, "Bad switch\n");
2927 /* Convert the input to sim_fpu internal format */
2931 sim_fpu_64to (&wop
, op
);
2934 sim_fpu_32to (&wop
, op
);
2937 sim_fpu_i32to (&wop
, op
, round
);
2940 sim_fpu_i64to (&wop
, op
, round
);
2943 fprintf (stderr
, "Bad switch\n");
2947 /* Convert sim_fpu format into the output */
2948 /* The value WOP is converted to the destination format, rounding
2949 using mode RM. When the destination is a fixed-point format, then
2950 a source value of Infinity, NaN or one which would round to an
2951 integer outside the fixed point range then an IEEE Invalid
2952 Operation condition is raised. */
2956 sim_fpu_round_32 (&wop
, round
, 0);
2957 sim_fpu_to32 (&result32
, &wop
);
2958 result64
= result32
;
2961 sim_fpu_round_64 (&wop
, round
, 0);
2962 sim_fpu_to64 (&result64
, &wop
);
2965 sim_fpu_to32i (&result32
, &wop
, round
);
2966 result64
= result32
;
2969 sim_fpu_to64i (&result64
, &wop
, round
);
2973 fprintf (stderr
, "Bad switch\n");
2978 printf("DBG: Convert: returning 0x%s (to format = %s)\n",pr_addr(result64
),DOFMT(to
));
2985 /*-- co-processor support routines ------------------------------------------*/
2988 CoProcPresent(coproc_number
)
2989 unsigned int coproc_number
;
2991 /* Return TRUE if simulator provides a model for the given co-processor number */
2996 cop_lw (SIM_DESC sd
,
3001 unsigned int memword
)
3006 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
3009 printf("DBG: COP_LW: memword = 0x%08X (uword64)memword = 0x%s\n",memword
,pr_addr(memword
));
3011 StoreFPR(coproc_reg
,fmt_word
,(uword64
)memword
);
3012 FPR_STATE
[coproc_reg
] = fmt_uninterpreted
;
3017 #if 0 /* this should be controlled by a configuration option */
3018 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
));
3027 cop_ld (SIM_DESC sd
,
3034 switch (coproc_num
) {
3036 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
3038 StoreFPR(coproc_reg
,fmt_uninterpreted
,memword
);
3043 #if 0 /* this message should be controlled by a configuration option */
3044 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
));
3053 /* start-sanitize-sky */
3056 cop_lq (SIM_DESC sd
,
3061 unsigned128 memword
)
3072 /* one word at a time, argh! */
3076 value
= H2T_4(*A4_16(& memword
, 3-i
));
3077 write_vu_vec_reg(&(vu0_device
.regs
), coproc_reg
, i
, & value
);
3083 sim_io_printf(sd
,"COP_LQ(%d,%d,??) at PC = 0x%s : TODO (architecture specific)\n",
3084 coproc_num
,coproc_reg
,pr_addr(cia
));
3090 #endif /* TARGET_SKY */
3091 /* end-sanitize-sky */
3095 cop_sw (SIM_DESC sd
,
3101 unsigned int value
= 0;
3106 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
3109 hold
= FPR_STATE
[coproc_reg
];
3110 FPR_STATE
[coproc_reg
] = fmt_word
;
3111 value
= (unsigned int)ValueFPR(coproc_reg
,fmt_uninterpreted
);
3112 FPR_STATE
[coproc_reg
] = hold
;
3117 #if 0 /* should be controlled by configuration option */
3118 sim_io_printf(sd
,"COP_SW(%d,%d) at PC = 0x%s : TODO (architecture specific)\n",coproc_num
,coproc_reg
,pr_addr(cia
));
3127 cop_sd (SIM_DESC sd
,
3137 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
3139 value
= ValueFPR(coproc_reg
,fmt_uninterpreted
);
3144 #if 0 /* should be controlled by configuration option */
3145 sim_io_printf(sd
,"COP_SD(%d,%d) at PC = 0x%s : TODO (architecture specific)\n",coproc_num
,coproc_reg
,pr_addr(cia
));
3154 /* start-sanitize-sky */
3157 cop_sq (SIM_DESC sd
,
3163 unsigned128 value
= U16_8(0, 0);
3174 /* one word at a time, argh! */
3178 read_vu_vec_reg(&(vu0_device
.regs
), coproc_reg
, i
, & value
);
3179 *A4_16(& xyzw
, 3-i
) = T2H_4(value
);
3186 sim_io_printf(sd
,"COP_SQ(%d,%d) at PC = 0x%s : TODO (architecture specific)\n",
3187 coproc_num
,coproc_reg
,pr_addr(cia
));
3193 #endif /* TARGET_SKY */
3194 /* end-sanitize-sky */
3198 decode_coproc (SIM_DESC sd
,
3201 unsigned int instruction
)
3203 int coprocnum
= ((instruction
>> 26) & 3);
3207 case 0: /* standard CPU control and cache registers */
3209 int code
= ((instruction
>> 21) & 0x1F);
3210 /* R4000 Users Manual (second edition) lists the following CP0
3212 DMFC0 Doubleword Move From CP0 (VR4100 = 01000000001tttttddddd00000000000)
3213 DMTC0 Doubleword Move To CP0 (VR4100 = 01000000101tttttddddd00000000000)
3214 MFC0 word Move From CP0 (VR4100 = 01000000000tttttddddd00000000000)
3215 MTC0 word Move To CP0 (VR4100 = 01000000100tttttddddd00000000000)
3216 TLBR Read Indexed TLB Entry (VR4100 = 01000010000000000000000000000001)
3217 TLBWI Write Indexed TLB Entry (VR4100 = 01000010000000000000000000000010)
3218 TLBWR Write Random TLB Entry (VR4100 = 01000010000000000000000000000110)
3219 TLBP Probe TLB for Matching Entry (VR4100 = 01000010000000000000000000001000)
3220 CACHE Cache operation (VR4100 = 101111bbbbbpppppiiiiiiiiiiiiiiii)
3221 ERET Exception return (VR4100 = 01000010000000000000000000011000)
3223 if (((code
== 0x00) || (code
== 0x04)) && ((instruction
& 0x7FF) == 0))
3225 int rt
= ((instruction
>> 16) & 0x1F);
3226 int rd
= ((instruction
>> 11) & 0x1F);
3228 switch (rd
) /* NOTEs: Standard CP0 registers */
3230 /* 0 = Index R4000 VR4100 VR4300 */
3231 /* 1 = Random R4000 VR4100 VR4300 */
3232 /* 2 = EntryLo0 R4000 VR4100 VR4300 */
3233 /* 3 = EntryLo1 R4000 VR4100 VR4300 */
3234 /* 4 = Context R4000 VR4100 VR4300 */
3235 /* 5 = PageMask R4000 VR4100 VR4300 */
3236 /* 6 = Wired R4000 VR4100 VR4300 */
3237 /* 8 = BadVAddr R4000 VR4100 VR4300 */
3238 /* 9 = Count R4000 VR4100 VR4300 */
3239 /* 10 = EntryHi R4000 VR4100 VR4300 */
3240 /* 11 = Compare R4000 VR4100 VR4300 */
3241 /* 12 = SR R4000 VR4100 VR4300 */
3242 #ifdef SUBTARGET_R3900
3246 /* 3 = Config R3900 */
3251 /* 3 = Cache R3900 */
3253 #endif /* SUBTARGET_R3900 */
3260 /* 13 = Cause R4000 VR4100 VR4300 */
3267 /* 14 = EPC R4000 VR4100 VR4300 */
3270 GPR
[rt
] = (signed_word
) (signed_address
) EPC
;
3274 /* 15 = PRId R4000 VR4100 VR4300 */
3275 #ifdef SUBTARGET_R3900
3284 /* 16 = Config R4000 VR4100 VR4300 */
3287 GPR
[rt
] = C0_CONFIG
;
3289 C0_CONFIG
= GPR
[rt
];
3292 #ifdef SUBTARGET_R3900
3301 /* 17 = LLAddr R4000 VR4100 VR4300 */
3303 /* 18 = WatchLo R4000 VR4100 VR4300 */
3304 /* 19 = WatchHi R4000 VR4100 VR4300 */
3305 /* 20 = XContext R4000 VR4100 VR4300 */
3306 /* 26 = PErr or ECC R4000 VR4100 VR4300 */
3307 /* 27 = CacheErr R4000 VR4100 */
3308 /* 28 = TagLo R4000 VR4100 VR4300 */
3309 /* 29 = TagHi R4000 VR4100 VR4300 */
3310 /* 30 = ErrorEPC R4000 VR4100 VR4300 */
3311 GPR
[rt
] = 0xDEADC0DE; /* CPR[0,rd] */
3312 /* CPR[0,rd] = GPR[rt]; */
3315 sim_io_printf(sd
,"Warning: MFC0 %d,%d ignored (architecture specific)\n",rt
,rd
);
3317 sim_io_printf(sd
,"Warning: MTC0 %d,%d ignored (architecture specific)\n",rt
,rd
);
3320 else if (code
== 0x10 && (instruction
& 0x3f) == 0x18)
3323 if (SR
& status_ERL
)
3325 /* Oops, not yet available */
3326 sim_io_printf(sd
,"Warning: ERET when SR[ERL] set not handled yet");
3336 else if (code
== 0x10 && (instruction
& 0x3f) == 0x10)
3339 #ifdef SUBTARGET_R3900
3340 /* TX39: Copy IEp/KUp -> IEc/KUc, and IEo/KUo -> IEp/KUp */
3342 /* shift IE/KU history bits right */
3343 SR
= LSMASKED32(SR
, 31, 4) | LSINSERTED32(LSEXTRACTED32(SR
, 5, 2), 3, 0);
3345 /* TODO: CACHE register */
3346 #endif /* SUBTARGET_R3900 */
3348 else if (code
== 0x10 && (instruction
& 0x3f) == 0x1F)
3356 sim_io_eprintf(sd
,"Unrecognised COP0 instruction 0x%08X at PC = 0x%s : No handler present\n",instruction
,pr_addr(cia
));
3357 /* TODO: When executing an ERET or RFE instruction we should
3358 clear LLBIT, to ensure that any out-standing atomic
3359 read/modify/write sequence fails. */
3363 case 2: /* co-processor 2 */
3367 /* start-sanitize-sky */
3369 /* On the R5900, this refers to a "VU" vector co-processor. */
3371 int i_25_21
= (instruction
>> 21) & 0x1f;
3372 int i_20_16
= (instruction
>> 16) & 0x1f;
3373 int i_20_6
= (instruction
>> 6) & 0x7fff;
3374 int i_15_11
= (instruction
>> 11) & 0x1f;
3375 int i_15_0
= instruction
& 0xffff;
3376 int i_10_1
= (instruction
>> 1) & 0x3ff;
3377 int i_10_0
= instruction
& 0x7ff;
3378 int i_10_6
= (instruction
>> 6) & 0x1f;
3379 int i_5_0
= instruction
& 0x03f;
3380 int interlock
= instruction
& 0x01;
3381 /* setup for semantic.c-like actions below */
3382 typedef unsigned_4 instruction_word
;
3388 /* test COP2 usability */
3389 if(! (SR
& status_CU2
))
3391 SignalException(CoProcessorUnusable
,instruction
);
3395 #define MY_INDEX itable_COPz_NORMAL
3396 #define MY_PREFIX COPz_NORMAL
3397 #define MY_NAME "COPz_NORMAL"
3399 /* classify & execute basic COP2 instructions */
3400 if(i_25_21
== 0x08 && i_20_16
== 0x00) /* BC2F */
3402 address_word offset
= EXTEND16(i_15_0
) << 2;
3403 if(! vu0_busy()) DELAY_SLOT(cia
+ 4 + offset
);
3405 else if(i_25_21
== 0x08 && i_20_16
==0x02) /* BC2FL */
3407 address_word offset
= EXTEND16(i_15_0
) << 2;
3408 if(! vu0_busy()) DELAY_SLOT(cia
+ 4 + offset
);
3409 else NULLIFY_NEXT_INSTRUCTION();
3411 else if(i_25_21
== 0x08 && i_20_16
== 0x01) /* BC2T */
3413 address_word offset
= EXTEND16(i_15_0
) << 2;
3414 if(vu0_busy()) DELAY_SLOT(cia
+ 4 + offset
);
3416 else if(i_25_21
== 0x08 && i_20_16
== 0x03) /* BC2TL */
3418 address_word offset
= EXTEND16(i_15_0
) << 2;
3419 if(vu0_busy()) DELAY_SLOT(cia
+ 4 + offset
);
3420 else NULLIFY_NEXT_INSTRUCTION();
3422 else if((i_25_21
== 0x02 && i_10_1
== 0x000) || /* CFC2 */
3423 (i_25_21
== 0x01)) /* QMFC2 */
3428 /* interlock checking */
3429 /* POLICY: never busy in macro mode */
3430 while(vu0_busy() && interlock
)
3433 /* perform VU register address */
3434 if(i_25_21
== 0x01) /* QMFC2 */
3437 /* one word at a time, argh! */
3438 read_vu_vec_reg(&(vu0_device
.regs
), id
, 0, A4_16(& xyzw
, 3));
3439 read_vu_vec_reg(&(vu0_device
.regs
), id
, 1, A4_16(& xyzw
, 2));
3440 read_vu_vec_reg(&(vu0_device
.regs
), id
, 2, A4_16(& xyzw
, 1));
3441 read_vu_vec_reg(&(vu0_device
.regs
), id
, 3, A4_16(& xyzw
, 0));
3442 GPR
[rt
] = T2H_8(* A8_16(& xyzw
, 1));
3443 GPR1
[rt
] = T2H_8(* A8_16(& xyzw
, 0));
3447 GPR
[rt
] = vu0_read_cop2_register(id
);
3450 else if((i_25_21
== 0x06 && i_10_1
== 0x000) || /* CTC2 */
3451 (i_25_21
== 0x05)) /* QMTC2 */
3456 /* interlock checking: wait until M or E bits set */
3457 /* POLICY: never busy in macro mode */
3458 while(vu0_busy() && interlock
)
3460 if(vu0_micro_interlock_released())
3462 vu0_micro_interlock_clear();
3469 /* perform VU register address */
3470 if(i_25_21
== 0x05) /* QMTC2 */
3472 unsigned_16 xyzw
= U16_8(GPR1
[rt
], GPR
[rt
]);
3474 xyzw
= H2T_16(xyzw
);
3475 /* one word at a time, argh! */
3476 write_vu_vec_reg(&(vu0_device
.regs
), id
, 0, A4_16(& xyzw
, 3));
3477 write_vu_vec_reg(&(vu0_device
.regs
), id
, 1, A4_16(& xyzw
, 2));
3478 write_vu_vec_reg(&(vu0_device
.regs
), id
, 2, A4_16(& xyzw
, 1));
3479 write_vu_vec_reg(&(vu0_device
.regs
), id
, 3, A4_16(& xyzw
, 0));
3483 vu0_write_cop2_register(id
, GPR
[rt
]);
3486 else if(i_10_0
== 0x3bf) /* VWAITQ */
3491 else if(i_5_0
== 0x38) /* VCALLMS */
3493 unsigned_4 data
= H2T_2(i_20_6
);
3498 /* write to reserved CIA register to get VU0 moving */
3499 write_vu_special_reg(& vu0_device
, VU_REG_CIA
, & data
);
3503 else if(i_5_0
== 0x39) /* VCALLMSR */
3510 read_vu_special_reg(& vu0_device
, VU_REG_CMSAR0
, & data
);
3511 /* write to reserved CIA register to get VU0 moving */
3512 write_vu_special_reg(& vu0_device
, VU_REG_CIA
, & data
);
3516 /* handle all remaining UPPER VU instructions in one block */
3517 else if((i_5_0
< 0x30) || /* VADDx .. VMINI */
3518 (i_5_0
>= 0x3c && i_10_6
< 0x0c)) /* VADDAx .. VNOP */
3520 unsigned_4 vu_upper
, vu_lower
;
3522 0x00000000 | /* bits 31 .. 25 */
3523 (instruction
& 0x01ffffff); /* bits 24 .. 0 */
3524 vu_lower
= 0x8000033c; /* NOP */
3526 /* POLICY: never busy in macro mode */
3530 vu0_macro_issue(vu_upper
, vu_lower
);
3532 /* POLICY: wait for completion of macro-instruction */
3536 /* handle all remaining LOWER VU instructions in one block */
3537 else if((i_5_0
>= 0x30 && i_5_0
<= 0x35) || /* VIADD .. VIOR */
3538 (i_5_0
>= 0x3c && i_10_6
>= 0x0c)) /* VMOVE .. VRXOR */
3539 { /* N.B.: VWAITQ already covered by prior case */
3540 unsigned_4 vu_upper
, vu_lower
;
3541 vu_upper
= 0x000002ff; /* NOP/NOP */
3543 0x80000000 | /* bits 31 .. 25 */
3544 (instruction
& 0x01ffffff); /* bits 24 .. 0 */
3546 /* POLICY: never busy in macro mode */
3550 vu0_macro_issue(vu_upper
, vu_lower
);
3552 /* POLICY: wait for completion of macro-instruction */
3556 /* ... no other COP2 instructions ... */
3559 SignalException(ReservedInstruction
, instruction
);
3563 /* cleanup for semantic.c-like actions above */
3570 #endif /* TARGET_SKY */
3571 /* end-sanitize-sky */
3575 sim_io_eprintf(sd
, "COP2 instruction 0x%08X at PC = 0x%s : No handler present\n",
3576 instruction
,pr_addr(cia
));
3581 case 1: /* should not occur (FPU co-processor) */
3582 case 3: /* should not occur (FPU co-processor) */
3583 SignalException(ReservedInstruction
,instruction
);
3591 /*-- instruction simulation -------------------------------------------------*/
3593 /* When the IGEN simulator is being built, the function below is be
3594 replaced by a generated version. However, WITH_IGEN == 2 indicates
3595 that the fubction below should be compiled but under a different
3596 name (to allow backward compatibility) */
3598 #if (WITH_IGEN != 1)
3600 void old_engine_run
PARAMS ((SIM_DESC sd
, int next_cpu_nr
, int siggnal
));
3602 old_engine_run (sd
, next_cpu_nr
, nr_cpus
, siggnal
)
3605 sim_engine_run (sd
, next_cpu_nr
, nr_cpus
, siggnal
)
3608 int next_cpu_nr
; /* ignore */
3609 int nr_cpus
; /* ignore */
3610 int siggnal
; /* ignore */
3612 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* hardwire to cpu 0 */
3613 #if !defined(FASTSIM)
3614 unsigned int pipeline_count
= 1;
3618 if (STATE_MEMORY (sd
) == NULL
) {
3619 printf("DBG: simulate() entered with no memory\n");
3624 #if 0 /* Disabled to check that everything works OK */
3625 /* The VR4300 seems to sign-extend the PC on its first
3626 access. However, this may just be because it is currently
3627 configured in 32bit mode. However... */
3628 PC
= SIGNEXTEND(PC
,32);
3631 /* main controlling loop */
3633 /* vaddr is slowly being replaced with cia - current instruction
3635 address_word cia
= (uword64
)PC
;
3636 address_word vaddr
= cia
;
3639 unsigned int instruction
; /* uword64? what's this used for? FIXME! */
3643 printf("DBG: state = 0x%08X :",state
);
3644 if (state
& simHALTEX
) printf(" simHALTEX");
3645 if (state
& simHALTIN
) printf(" simHALTIN");
3650 DSSTATE
= (STATE
& simDELAYSLOT
);
3653 sim_io_printf(sd
,"DBG: DSPC = 0x%s\n",pr_addr(DSPC
));
3656 /* Fetch the next instruction from the simulator memory: */
3657 if (AddressTranslation(cia
,isINSTRUCTION
,isLOAD
,&paddr
,&cca
,isTARGET
,isREAL
)) {
3658 if ((vaddr
& 1) == 0) {
3659 /* Copy the action of the LW instruction */
3660 unsigned int reverse
= (ReverseEndian
? (LOADDRMASK
>> 2) : 0);
3661 unsigned int bigend
= (BigEndianCPU
? (LOADDRMASK
>> 2) : 0);
3664 paddr
= ((paddr
& ~LOADDRMASK
) | ((paddr
& LOADDRMASK
) ^ (reverse
<< 2)));
3665 LoadMemory(&value
,NULL
,cca
,AccessLength_WORD
,paddr
,vaddr
,isINSTRUCTION
,isREAL
);
3666 byte
= ((vaddr
& LOADDRMASK
) ^ (bigend
<< 2));
3667 instruction
= ((value
>> (8 * byte
)) & 0xFFFFFFFF);
3669 /* Copy the action of the LH instruction */
3670 unsigned int reverse
= (ReverseEndian
? (LOADDRMASK
>> 1) : 0);
3671 unsigned int bigend
= (BigEndianCPU
? (LOADDRMASK
>> 1) : 0);
3674 paddr
= (((paddr
& ~ (uword64
) 1) & ~LOADDRMASK
)
3675 | (((paddr
& ~ (uword64
) 1) & LOADDRMASK
) ^ (reverse
<< 1)));
3676 LoadMemory(&value
,NULL
,cca
, AccessLength_HALFWORD
,
3677 paddr
& ~ (uword64
) 1,
3678 vaddr
, isINSTRUCTION
, isREAL
);
3679 byte
= (((vaddr
&~ (uword64
) 1) & LOADDRMASK
) ^ (bigend
<< 1));
3680 instruction
= ((value
>> (8 * byte
)) & 0xFFFF);
3683 fprintf(stderr
,"Cannot translate address for PC = 0x%s failed\n",pr_addr(PC
));
3688 sim_io_printf(sd
,"DBG: fetched 0x%08X from PC = 0x%s\n",instruction
,pr_addr(PC
));
3691 /* This is required by exception processing, to ensure that we can
3692 cope with exceptions in the delay slots of branches that may
3693 already have changed the PC. */
3694 if ((vaddr
& 1) == 0)
3695 PC
+= 4; /* increment ready for the next fetch */
3698 /* NOTE: If we perform a delay slot change to the PC, this
3699 increment is not requuired. However, it would make the
3700 simulator more complicated to try and avoid this small hit. */
3702 /* Currently this code provides a simple model. For more
3703 complicated models we could perform exception status checks at
3704 this point, and set the simSTOP state as required. This could
3705 also include processing any hardware interrupts raised by any
3706 I/O model attached to the simulator context.
3708 Support for "asynchronous" I/O events within the simulated world
3709 could be providing by managing a counter, and calling a I/O
3710 specific handler when a particular threshold is reached. On most
3711 architectures a decrement and check for zero operation is
3712 usually quicker than an increment and compare. However, the
3713 process of managing a known value decrement to zero, is higher
3714 than the cost of using an explicit value UINT_MAX into the
3715 future. Which system is used will depend on how complicated the
3716 I/O model is, and how much it is likely to affect the simulator
3719 If events need to be scheduled further in the future than
3720 UINT_MAX event ticks, then the I/O model should just provide its
3721 own counter, triggered from the event system. */
3723 /* MIPS pipeline ticks. To allow for future support where the
3724 pipeline hit of individual instructions is known, this control
3725 loop manages a "pipeline_count" variable. It is initialised to
3726 1 (one), and will only be changed by the simulator engine when
3727 executing an instruction. If the engine does not have access to
3728 pipeline cycle count information then all instructions will be
3729 treated as using a single cycle. NOTE: A standard system is not
3730 provided by the default simulator because different MIPS
3731 architectures have different cycle counts for the same
3734 [NOTE: pipeline_count has been replaced the event queue] */
3736 /* shuffle the floating point status pipeline state */
3737 ENGINE_ISSUE_PREFIX_HOOK();
3739 /* NOTE: For multi-context simulation environments the "instruction"
3740 variable should be local to this routine. */
3742 /* Shorthand accesses for engine. Note: If we wanted to use global
3743 variables (and a single-threaded simulator engine), then we can
3744 create the actual variables with these names. */
3746 if (!(STATE
& simSKIPNEXT
)) {
3747 /* Include the simulator engine */
3748 #include "oengine.c"
3749 #if ((GPRLEN == 64) && !PROCESSOR_64BIT) || ((GPRLEN == 32) && PROCESSOR_64BIT)
3750 #error "Mismatch between run-time simulator code and simulation engine"
3752 #if (WITH_TARGET_WORD_BITSIZE != GPRLEN)
3753 #error "Mismatch between configure WITH_TARGET_WORD_BITSIZE and gencode GPRLEN"
3755 #if ((WITH_FLOATING_POINT == HARD_FLOATING_POINT) != defined (HASFPU))
3756 #error "Mismatch between configure WITH_FLOATING_POINT and gencode HASFPU"
3759 /* For certain MIPS architectures, GPR[0] is hardwired to zero. We
3760 should check for it being changed. It is better doing it here,
3761 than within the simulator, since it will help keep the simulator
3764 #if defined(WARN_ZERO)
3765 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
));
3766 #endif /* WARN_ZERO */
3767 ZERO
= 0; /* reset back to zero before next instruction */
3769 } else /* simSKIPNEXT check */
3770 STATE
&= ~simSKIPNEXT
;
3772 /* If the delay slot was active before the instruction is
3773 executed, then update the PC to its new value: */
3776 printf("DBG: dsstate set before instruction execution - updating PC to 0x%s\n",pr_addr(DSPC
));
3785 #if !defined(FASTSIM)
3786 if (sim_events_tickn (sd
, pipeline_count
))
3788 /* cpu->cia = cia; */
3789 sim_events_process (sd
);
3792 if (sim_events_tick (sd
))
3794 /* cpu->cia = cia; */
3795 sim_events_process (sd
);
3797 #endif /* FASTSIM */
3803 /* This code copied from gdb's utils.c. Would like to share this code,
3804 but don't know of a common place where both could get to it. */
3806 /* Temporary storage using circular buffer */
3812 static char buf
[NUMCELLS
][CELLSIZE
];
3814 if (++cell
>=NUMCELLS
) cell
=0;
3818 /* Print routines to handle variable size regs, etc */
3820 /* Eliminate warning from compiler on 32-bit systems */
3821 static int thirty_two
= 32;
3827 char *paddr_str
=get_cell();
3828 switch (sizeof(addr
))
3831 sprintf(paddr_str
,"%08lx%08lx",
3832 (unsigned long)(addr
>>thirty_two
),(unsigned long)(addr
&0xffffffff));
3835 sprintf(paddr_str
,"%08lx",(unsigned long)addr
);
3838 sprintf(paddr_str
,"%04x",(unsigned short)(addr
&0xffff));
3841 sprintf(paddr_str
,"%x",addr
);
3850 char *paddr_str
=get_cell();
3851 sprintf(paddr_str
,"%08lx%08lx",
3852 (unsigned long)(addr
>>thirty_two
),(unsigned long)(addr
&0xffffffff));
3858 /*---------------------------------------------------------------------------*/
3859 /*> EOF interp.c <*/