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.
22 The IDT monitor (found on the VR4300 board), seems to lie about
23 register contents. It seems to treat the registers as sign-extended
24 32-bit values. This cause *REAL* problems when single-stepping 64-bit
29 /* The TRACE manifests enable the provision of extra features. If they
30 are not defined then a simpler (quicker) simulator is constructed
31 without the required run-time checks, etc. */
32 #if 1 /* 0 to allow user build selection, 1 to force inclusion */
38 #include "sim-utils.h"
39 #include "sim-options.h"
40 #include "sim-assert.h"
62 #include "libiberty.h"
64 #include "callback.h" /* GDB simulator callback interface */
65 #include "remote-sim.h" /* GDB simulator interface */
73 char* pr_addr
PARAMS ((SIM_ADDR addr
));
74 char* pr_uword64
PARAMS ((uword64 addr
));
77 /* Get the simulator engine description, without including the code: */
79 #define LOADDRMASK (WITH_TARGET_WORD_BITSIZE == 64 ? 0x7 : 0x3)
86 /* Within interp.c we refer to the sim_state and sim_cpu directly. */
91 /* The following reserved instruction value is used when a simulator
92 trap is required. NOTE: Care must be taken, since this value may be
93 used in later revisions of the MIPS ISA. */
94 #define RSVD_INSTRUCTION (0x00000005)
95 #define RSVD_INSTRUCTION_MASK (0xFC00003F)
97 #define RSVD_INSTRUCTION_ARG_SHIFT 6
98 #define RSVD_INSTRUCTION_ARG_MASK 0xFFFFF
101 /* Bits in the Debug register */
102 #define Debug_DBD 0x80000000 /* Debug Branch Delay */
103 #define Debug_DM 0x40000000 /* Debug Mode */
104 #define Debug_DBp 0x00000002 /* Debug Breakpoint indicator */
110 /*---------------------------------------------------------------------------*/
111 /*-- GDB simulator interface ------------------------------------------------*/
112 /*---------------------------------------------------------------------------*/
114 static void ColdReset
PARAMS((SIM_DESC sd
));
116 /*---------------------------------------------------------------------------*/
120 #define DELAYSLOT() {\
121 if (STATE & simDELAYSLOT)\
122 sim_io_eprintf(sd,"Delay slot already activated (branch in delay slot?)\n");\
123 STATE |= simDELAYSLOT;\
126 #define JALDELAYSLOT() {\
128 STATE |= simJALDELAYSLOT;\
132 STATE &= ~simDELAYSLOT;\
133 STATE |= simSKIPNEXT;\
136 #define CANCELDELAYSLOT() {\
138 STATE &= ~(simDELAYSLOT | simJALDELAYSLOT);\
141 #define INDELAYSLOT() ((STATE & simDELAYSLOT) != 0)
142 #define INJALDELAYSLOT() ((STATE & simJALDELAYSLOT) != 0)
144 #define K0BASE (0x80000000)
145 #define K0SIZE (0x20000000)
146 #define K1BASE (0xA0000000)
147 #define K1SIZE (0x20000000)
148 #define MONITOR_BASE (0xBFC00000)
149 #define MONITOR_SIZE (1 << 11)
150 #define MEM_SIZE (2 << 20)
153 static char *tracefile
= "trace.din"; /* default filename for trace log */
154 FILE *tracefh
= NULL
;
155 static void open_trace
PARAMS((SIM_DESC sd
));
158 static DECLARE_OPTION_HANDLER (mips_option_handler
);
160 #define OPTION_DINERO_TRACE 200
161 #define OPTION_DINERO_FILE 201
164 mips_option_handler (sd
, cpu
, opt
, arg
, is_command
)
174 case OPTION_DINERO_TRACE
: /* ??? */
176 /* Eventually the simTRACE flag could be treated as a toggle, to
177 allow external control of the program points being traced
178 (i.e. only from main onwards, excluding the run-time setup,
180 for (cpu_nr
= 0; cpu_nr
< sim_engine_nr_cpus (sd
); cpu_nr
++)
182 sim_cpu
*cpu
= STATE_CPU (sd
, cpu_nr
);
185 else if (strcmp (arg
, "yes") == 0)
187 else if (strcmp (arg
, "no") == 0)
189 else if (strcmp (arg
, "on") == 0)
191 else if (strcmp (arg
, "off") == 0)
195 fprintf (stderr
, "Unreconized dinero-trace option `%s'\n", arg
);
202 Simulator constructed without dinero tracing support (for performance).\n\
203 Re-compile simulator with \"-DTRACE\" to enable this option.\n");
207 case OPTION_DINERO_FILE
:
209 if (optarg
!= NULL
) {
211 tmp
= (char *)malloc(strlen(optarg
) + 1);
214 sim_io_printf(sd
,"Failed to allocate buffer for tracefile name \"%s\"\n",optarg
);
220 sim_io_printf(sd
,"Placing trace information into file \"%s\"\n",tracefile
);
231 static const OPTION mips_options
[] =
233 { {"dinero-trace", optional_argument
, NULL
, OPTION_DINERO_TRACE
},
234 '\0', "on|off", "Enable dinero tracing",
235 mips_option_handler
},
236 { {"dinero-file", required_argument
, NULL
, OPTION_DINERO_FILE
},
237 '\0', "FILE", "Write dinero trace to FILE",
238 mips_option_handler
},
239 { {NULL
, no_argument
, NULL
, 0}, '\0', NULL
, NULL
, NULL
}
243 int interrupt_pending
;
246 interrupt_event (SIM_DESC sd
, void *data
)
248 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
251 interrupt_pending
= 0;
252 SignalExceptionInterrupt ();
254 else if (!interrupt_pending
)
255 sim_events_schedule (sd
, 1, interrupt_event
, data
);
259 /*---------------------------------------------------------------------------*/
260 /*-- Device registration hook -----------------------------------------------*/
261 /*---------------------------------------------------------------------------*/
262 static void device_init(SIM_DESC sd
) {
264 extern void register_devices(SIM_DESC
);
265 register_devices(sd
);
269 /* start-sanitize-sky */
272 short i
[NUM_VU_INTEGER_REGS
];
273 int f
[NUM_VU_REGS
- NUM_VU_INTEGER_REGS
];
276 /* end-sanitize-sky */
278 /*---------------------------------------------------------------------------*/
279 /*-- GDB simulator interface ------------------------------------------------*/
280 /*---------------------------------------------------------------------------*/
283 sim_open (kind
, cb
, abfd
, argv
)
289 SIM_DESC sd
= sim_state_alloc (kind
, cb
);
290 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
292 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
294 /* FIXME: watchpoints code shouldn't need this */
295 STATE_WATCHPOINTS (sd
)->pc
= &(PC
);
296 STATE_WATCHPOINTS (sd
)->sizeof_pc
= sizeof (PC
);
297 STATE_WATCHPOINTS (sd
)->interrupt_handler
= interrupt_event
;
301 if (sim_pre_argv_init (sd
, argv
[0]) != SIM_RC_OK
)
303 sim_add_option_table (sd
, NULL
, mips_options
);
305 /* Allocate core managed memory */
308 sim_do_commandf (sd
, "memory region 0x%lx,0x%lx", MONITOR_BASE
, MONITOR_SIZE
);
309 /* For compatibility with the old code - under this (at level one)
310 are the kernel spaces K0 & K1. Both of these map to a single
311 smaller sub region */
312 sim_do_command(sd
," memory region 0x7fff8000,0x8000") ; /* MTZ- 32 k stack */
313 /* start-sanitize-sky */
315 /* end-sanitize-sky */
316 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx%%0x%lx,0x%0x",
318 MEM_SIZE
, /* actual size */
320 /* start-sanitize-sky */
322 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx%%0x%lx,0x%0x,0x%0x",
324 MEM_SIZE
, /* actual size */
326 0); /* add alias at 0x0000 */
328 /* end-sanitize-sky */
332 /* getopt will print the error message so we just have to exit if this fails.
333 FIXME: Hmmm... in the case of gdb we need getopt to call
335 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
337 /* Uninstall the modules to avoid memory leaks,
338 file descriptor leaks, etc. */
339 sim_module_uninstall (sd
);
343 /* check for/establish the a reference program image */
344 if (sim_analyze_program (sd
,
345 (STATE_PROG_ARGV (sd
) != NULL
346 ? *STATE_PROG_ARGV (sd
)
350 sim_module_uninstall (sd
);
354 /* Configure/verify the target byte order and other runtime
355 configuration options */
356 if (sim_config (sd
) != SIM_RC_OK
)
358 sim_module_uninstall (sd
);
362 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
364 /* Uninstall the modules to avoid memory leaks,
365 file descriptor leaks, etc. */
366 sim_module_uninstall (sd
);
370 /* verify assumptions the simulator made about the host type system.
371 This macro does not return if there is a problem */
372 SIM_ASSERT (sizeof(int) == (4 * sizeof(char)));
373 SIM_ASSERT (sizeof(word64
) == (8 * sizeof(char)));
375 /* This is NASTY, in that we are assuming the size of specific
379 for (rn
= 0; (rn
< (LAST_EMBED_REGNUM
+ 1)); rn
++)
382 cpu
->register_widths
[rn
] = WITH_TARGET_WORD_BITSIZE
;
383 else if ((rn
>= FGRIDX
) && (rn
< (FGRIDX
+ NR_FGR
)))
384 cpu
->register_widths
[rn
] = WITH_TARGET_FLOATING_POINT_BITSIZE
;
385 else if ((rn
>= 33) && (rn
<= 37))
386 cpu
->register_widths
[rn
] = WITH_TARGET_WORD_BITSIZE
;
387 else if ((rn
== SRIDX
)
390 || ((rn
>= 72) && (rn
<= 89)))
391 cpu
->register_widths
[rn
] = 32;
393 cpu
->register_widths
[rn
] = 0;
395 /* start-sanitize-r5900 */
397 /* set the 5900 "upper" registers to 64 bits */
398 for( rn
= LAST_EMBED_REGNUM
+1; rn
< NUM_REGS
; rn
++)
399 cpu
->register_widths
[rn
] = 64;
400 /* end-sanitize-r5900 */
402 /* start-sanitize-sky */
404 /* Now the VU registers */
405 for( rn
= 0; rn
< NUM_VU_INTEGER_REGS
; rn
++ ) {
406 cpu
->register_widths
[rn
+ NUM_R5900_REGS
] = 16;
407 cpu
->register_widths
[rn
+ NUM_R5900_REGS
+ NUM_VU_REGS
] = 16;
409 /* Hack for now - to test gdb interface */
410 vu_regs
[0].i
[rn
] = rn
+ 0x100;
411 vu_regs
[1].i
[rn
] = rn
+ 0x200;
414 for( rn
= NUM_VU_INTEGER_REGS
; rn
< NUM_VU_REGS
; rn
++ ) {
416 int first_vec_reg
= NUM_VU_INTEGER_REGS
+ 8;
418 cpu
->register_widths
[rn
+ NUM_R5900_REGS
] = 32;
419 cpu
->register_widths
[rn
+ NUM_R5900_REGS
+ NUM_VU_REGS
] = 32;
421 /* Hack for now - to test gdb interface */
422 if( rn
< first_vec_reg
) {
423 f
= rn
- NUM_VU_INTEGER_REGS
+ 100.0;
424 vu_regs
[0].f
[rn
-NUM_VU_INTEGER_REGS
] = *((unsigned *) &f
);
425 f
= rn
- NUM_VU_INTEGER_REGS
+ 200.0;
426 vu_regs
[1].f
[rn
-NUM_VU_INTEGER_REGS
] = *((unsigned *) &f
);
429 f
= (rn
- first_vec_reg
)/4 + (rn
- first_vec_reg
)%4 + 1000.0;
430 vu_regs
[0].f
[rn
-NUM_VU_INTEGER_REGS
] = *((unsigned *) &f
);
431 f
= (rn
- first_vec_reg
)/4 + (rn
- first_vec_reg
)%4 + 2000.0;
432 vu_regs
[1].f
[rn
-NUM_VU_INTEGER_REGS
] = *((unsigned *) &f
);
436 /* end-sanitize-sky */
440 if (STATE
& simTRACE
)
444 /* Write the monitor trap address handlers into the monitor (eeprom)
445 address space. This can only be done once the target endianness
446 has been determined. */
449 /* Entry into the IDT monitor is via fixed address vectors, and
450 not using machine instructions. To avoid clashing with use of
451 the MIPS TRAP system, we place our own (simulator specific)
452 "undefined" instructions into the relevant vector slots. */
453 for (loop
= 0; (loop
< MONITOR_SIZE
); loop
+= 4)
455 address_word vaddr
= (MONITOR_BASE
+ loop
);
456 unsigned32 insn
= (RSVD_INSTRUCTION
| (((loop
>> 2) & RSVD_INSTRUCTION_ARG_MASK
) << RSVD_INSTRUCTION_ARG_SHIFT
));
458 sim_write (sd
, vaddr
, (char *)&insn
, sizeof (insn
));
460 /* The PMON monitor uses the same address space, but rather than
461 branching into it the address of a routine is loaded. We can
462 cheat for the moment, and direct the PMON routine to IDT style
463 instructions within the monitor space. This relies on the IDT
464 monitor not using the locations from 0xBFC00500 onwards as its
466 for (loop
= 0; (loop
< 24); loop
++)
468 address_word vaddr
= (MONITOR_BASE
+ 0x500 + (loop
* 4));
469 unsigned32 value
= ((0x500 - 8) / 8); /* default UNDEFINED reason code */
485 value
= ((0x500 - 16) / 8); /* not an IDT reason code */
487 case 8: /* cliexit */
490 case 11: /* flush_cache */
494 /* FIXME - should monitor_base be SIM_ADDR?? */
495 value
= ((unsigned int)MONITOR_BASE
+ (value
* 8));
497 sim_write (sd
, vaddr
, (char *)&value
, sizeof (value
));
499 /* The LSI MiniRISC PMON has its vectors at 0x200, not 0x500. */
501 sim_write (sd
, vaddr
, (char *)&value
, sizeof (value
));
513 tracefh
= fopen(tracefile
,"wb+");
516 sim_io_eprintf(sd
,"Failed to create file \"%s\", writing trace information to stderr.\n",tracefile
);
523 sim_close (sd
, quitting
)
528 printf("DBG: sim_close: entered (quitting = %d)\n",quitting
);
531 /* "quitting" is non-zero if we cannot hang on errors */
533 /* Ensure that any resources allocated through the callback
534 mechanism are released: */
535 sim_io_shutdown (sd
);
538 if (tracefh
!= NULL
&& tracefh
!= stderr
)
543 /* FIXME - free SD */
550 sim_write (sd
,addr
,buffer
,size
)
553 unsigned char *buffer
;
557 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
559 /* Return the number of bytes written, or zero if error. */
561 sim_io_printf(sd
,"sim_write(0x%s,buffer,%d);\n",pr_addr(addr
),size
);
564 /* We use raw read and write routines, since we do not want to count
565 the GDB memory accesses in our statistics gathering. */
567 for (index
= 0; index
< size
; index
++)
569 address_word vaddr
= (address_word
)addr
+ index
;
572 if (!address_translation (SD
, CPU
, NULL_CIA
, vaddr
, isDATA
, isSTORE
, &paddr
, &cca
, isRAW
))
574 if (sim_core_write_buffer (SD
, CPU
, sim_core_read_map
, buffer
+ index
, paddr
, 1) != 1)
582 sim_read (sd
,addr
,buffer
,size
)
585 unsigned char *buffer
;
589 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
591 /* Return the number of bytes read, or zero if error. */
593 sim_io_printf(sd
,"sim_read(0x%s,buffer,%d);\n",pr_addr(addr
),size
);
596 for (index
= 0; (index
< size
); index
++)
598 address_word vaddr
= (address_word
)addr
+ index
;
601 if (!address_translation (SD
, CPU
, NULL_CIA
, vaddr
, isDATA
, isLOAD
, &paddr
, &cca
, isRAW
))
603 if (sim_core_read_buffer (SD
, CPU
, sim_core_read_map
, buffer
+ index
, paddr
, 1) != 1)
611 sim_store_register (sd
,rn
,memory
,length
)
614 unsigned char *memory
;
617 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
618 /* NOTE: gdb (the client) stores registers in target byte order
619 while the simulator uses host byte order */
621 sim_io_printf(sd
,"sim_store_register(%d,*memory=0x%s);\n",rn
,pr_addr(*((SIM_ADDR
*)memory
)));
624 /* Unfortunately this suffers from the same problem as the register
625 numbering one. We need to know what the width of each logical
626 register number is for the architecture being simulated. */
628 if (cpu
->register_widths
[rn
] == 0)
630 sim_io_eprintf(sd
,"Invalid register width for %d (register store ignored)\n",rn
);
634 /* start-sanitize-r5900 */
635 if (rn
>= 90 && rn
< 90 + 32)
637 GPR1
[rn
- 90] = T2H_8 (*(unsigned64
*)memory
);
643 SA
= T2H_8(*(unsigned64
*)memory
);
645 case 122: /* FIXME */
646 LO1
= T2H_8(*(unsigned64
*)memory
);
648 case 123: /* FIXME */
649 HI1
= T2H_8(*(unsigned64
*)memory
);
652 /* end-sanitize-r5900 */
654 /* start-sanitize-sky */
656 if (rn
>= NUM_R5900_REGS
)
658 int size
= 4; /* Default register size */
660 rn
= rn
- NUM_R5900_REGS
;
662 if (rn
< NUM_VU_INTEGER_REGS
)
664 vu_regs
[0].i
[rn
] = T2H_2( *(unsigned short *) memory
);
667 else if( rn
< NUM_VU_REGS
)
668 vu_regs
[0].f
[rn
- NUM_VU_INTEGER_REGS
]
669 = T2H_4( *(unsigned int *) memory
);
671 rn
= rn
- NUM_VU_REGS
;
673 if( rn
< NUM_VU_INTEGER_REGS
)
675 vu_regs
[1].i
[rn
] = T2H_2( *(unsigned short *) memory
);
678 else if( rn
< NUM_VU_REGS
)
679 vu_regs
[1].f
[rn
- NUM_VU_INTEGER_REGS
]
680 = T2H_4( *(unsigned int *) memory
);
682 sim_io_eprintf( sd
, "Invalid VU register (register store ignored)\n" );
688 /* end-sanitize-sky */
690 if (rn
>= FGRIDX
&& rn
< FGRIDX
+ NR_FGR
)
692 if (cpu
->register_widths
[rn
] == 32)
694 cpu
->fgr
[rn
- FGRIDX
] = T2H_4 (*(unsigned32
*)memory
);
699 cpu
->fgr
[rn
- FGRIDX
] = T2H_8 (*(unsigned64
*)memory
);
704 if (cpu
->register_widths
[rn
] == 32)
706 cpu
->registers
[rn
] = T2H_4 (*(unsigned32
*)memory
);
711 cpu
->registers
[rn
] = T2H_8 (*(unsigned64
*)memory
);
717 sim_fetch_register (sd
,rn
,memory
,length
)
720 unsigned char *memory
;
723 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
724 /* NOTE: gdb (the client) stores registers in target byte order
725 while the simulator uses host byte order */
727 sim_io_printf(sd
,"sim_fetch_register(%d=0x%s,mem) : place simulator registers into memory\n",rn
,pr_addr(registers
[rn
]));
730 if (cpu
->register_widths
[rn
] == 0)
732 sim_io_eprintf (sd
, "Invalid register width for %d (register fetch ignored)\n",rn
);
736 /* start-sanitize-r5900 */
737 if (rn
>= 90 && rn
< 90 + 32)
739 *(unsigned64
*)memory
= GPR1
[rn
- 90];
745 *((unsigned64
*)memory
) = H2T_8(SA
);
747 case 122: /* FIXME */
748 *((unsigned64
*)memory
) = H2T_8(LO1
);
750 case 123: /* FIXME */
751 *((unsigned64
*)memory
) = H2T_8(HI1
);
754 /* end-sanitize-r5900 */
756 /* start-sanitize-sky */
758 if (rn
>= NUM_R5900_REGS
)
760 int size
= 4; /* default register width */
762 rn
= rn
- NUM_R5900_REGS
;
764 if (rn
< NUM_VU_INTEGER_REGS
)
766 *((unsigned short *) memory
) = H2T_2( vu_regs
[0].i
[rn
] );
769 else if (rn
< NUM_VU_REGS
)
770 *((unsigned int *) memory
)
771 = H2T_4( vu_regs
[0].f
[rn
- NUM_VU_INTEGER_REGS
] );
774 rn
= rn
- NUM_VU_REGS
;
776 if (rn
< NUM_VU_INTEGER_REGS
)
778 (*(unsigned short *) memory
) = H2T_2( vu_regs
[1].i
[rn
] );
781 else if (rn
< NUM_VU_REGS
)
782 (*(unsigned int *) memory
)
783 = H2T_4( vu_regs
[1].f
[rn
- NUM_VU_INTEGER_REGS
] );
785 sim_io_eprintf( sd
, "Invalid VU register (register fetch ignored)\n" );
791 /* end-sanitize-sky */
793 /* Any floating point register */
794 if (rn
>= FGRIDX
&& rn
< FGRIDX
+ NR_FGR
)
796 if (cpu
->register_widths
[rn
] == 32)
798 *(unsigned32
*)memory
= H2T_4 (cpu
->fgr
[rn
- FGRIDX
]);
803 *(unsigned64
*)memory
= H2T_8 (cpu
->fgr
[rn
- FGRIDX
]);
808 if (cpu
->register_widths
[rn
] == 32)
810 *(unsigned32
*)memory
= H2T_4 ((unsigned32
)(cpu
->registers
[rn
]));
815 *(unsigned64
*)memory
= H2T_8 ((unsigned64
)(cpu
->registers
[rn
]));
822 sim_create_inferior (sd
, abfd
, argv
,env
)
830 printf("DBG: sim_create_inferior entered: start_address = 0x%s\n",
838 /* override PC value set by ColdReset () */
840 for (cpu_nr
= 0; cpu_nr
< sim_engine_nr_cpus (sd
); cpu_nr
++)
842 sim_cpu
*cpu
= STATE_CPU (sd
, cpu_nr
);
843 CIA_SET (cpu
, (unsigned64
) bfd_get_start_address (abfd
));
847 #if 0 /* def DEBUG */
850 /* We should really place the argv slot values into the argument
851 registers, and onto the stack as required. However, this
852 assumes that we have a stack defined, which is not
853 necessarily true at the moment. */
855 sim_io_printf(sd
,"sim_create_inferior() : passed arguments ignored\n");
856 for (cptr
= argv
; (cptr
&& *cptr
); cptr
++)
857 printf("DBG: arg \"%s\"\n",*cptr
);
865 sim_do_command (sd
,cmd
)
869 if (sim_args_command (sd
, cmd
) != SIM_RC_OK
)
870 sim_io_printf (sd
, "Error: \"%s\" is not a valid MIPS simulator command.\n",
874 /*---------------------------------------------------------------------------*/
875 /*-- Private simulator support interface ------------------------------------*/
876 /*---------------------------------------------------------------------------*/
878 /* Read a null terminated string from memory, return in a buffer */
887 while (sim_read (sd
, addr
+ nr
, &null
, 1) == 1 && null
!= 0)
889 buf
= NZALLOC (char, nr
+ 1);
890 sim_read (sd
, addr
, buf
, nr
);
894 /* Simple monitor interface (currently setup for the IDT and PMON monitors) */
896 sim_monitor (SIM_DESC sd
,
902 printf("DBG: sim_monitor: entered (reason = %d)\n",reason
);
905 /* The IDT monitor actually allows two instructions per vector
906 slot. However, the simulator currently causes a trap on each
907 individual instruction. We cheat, and lose the bottom bit. */
910 /* The following callback functions are available, however the
911 monitor we are simulating does not make use of them: get_errno,
912 isatty, lseek, rename, system, time and unlink */
916 case 6: /* int open(char *path,int flags) */
918 char *path
= fetch_str (sd
, A0
);
919 V0
= sim_io_open (sd
, path
, (int)A1
);
924 case 7: /* int read(int file,char *ptr,int len) */
928 char *buf
= zalloc (nr
);
929 V0
= sim_io_read (sd
, fd
, buf
, nr
);
930 sim_write (sd
, A1
, buf
, nr
);
935 case 8: /* int write(int file,char *ptr,int len) */
939 char *buf
= zalloc (nr
);
940 sim_read (sd
, A1
, buf
, nr
);
941 V0
= sim_io_write (sd
, fd
, buf
, nr
);
946 case 10: /* int close(int file) */
948 V0
= sim_io_close (sd
, (int)A0
);
952 case 2: /* Densan monitor: char inbyte(int waitflag) */
954 if (A0
== 0) /* waitflag == NOWAIT */
955 V0
= (unsigned_word
)-1;
957 /* Drop through to case 11 */
959 case 11: /* char inbyte(void) */
962 if (sim_io_read_stdin (sd
, &tmp
, sizeof(char)) != sizeof(char))
964 sim_io_error(sd
,"Invalid return from character read");
965 V0
= (unsigned_word
)-1;
968 V0
= (unsigned_word
)tmp
;
972 case 3: /* Densan monitor: void co(char chr) */
973 case 12: /* void outbyte(char chr) : write a byte to "stdout" */
975 char tmp
= (char)(A0
& 0xFF);
976 sim_io_write_stdout (sd
, &tmp
, sizeof(char));
980 case 17: /* void _exit() */
982 sim_io_eprintf (sd
, "sim_monitor(17): _exit(int reason) to be coded\n");
983 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
, sim_exited
,
984 (unsigned int)(A0
& 0xFFFFFFFF));
988 case 28 : /* PMON flush_cache */
991 case 55: /* void get_mem_info(unsigned int *ptr) */
992 /* in: A0 = pointer to three word memory location */
993 /* out: [A0 + 0] = size */
994 /* [A0 + 4] = instruction cache size */
995 /* [A0 + 8] = data cache size */
997 address_word value
= MEM_SIZE
/* FIXME STATE_MEM_SIZE (sd) */;
999 sim_write (sd
, A0
, (char *)&value
, sizeof (value
));
1000 /* sim_io_eprintf (sd, "sim: get_mem_info() depreciated\n"); */
1004 case 158 : /* PMON printf */
1005 /* in: A0 = pointer to format string */
1006 /* A1 = optional argument 1 */
1007 /* A2 = optional argument 2 */
1008 /* A3 = optional argument 3 */
1010 /* The following is based on the PMON printf source */
1012 address_word s
= A0
;
1014 signed_word
*ap
= &A1
; /* 1st argument */
1015 /* This isn't the quickest way, since we call the host print
1016 routine for every character almost. But it does avoid
1017 having to allocate and manage a temporary string buffer. */
1018 /* TODO: Include check that we only use three arguments (A1,
1020 while (sim_read (sd
, s
++, &c
, 1) && c
!= '\0')
1025 enum {FMT_RJUST
, FMT_LJUST
, FMT_RJUST0
, FMT_CENTER
} fmt
= FMT_RJUST
;
1026 int width
= 0, trunc
= 0, haddot
= 0, longlong
= 0;
1027 while (sim_read (sd
, s
++, &c
, 1) && c
!= '\0')
1029 if (strchr ("dobxXulscefg%", s
))
1044 else if (c
>= '1' && c
<= '9')
1048 while (sim_read (sd
, s
++, &c
, 1) == 1 && isdigit (c
))
1051 n
= (unsigned int)strtol(tmp
,NULL
,10);
1064 sim_io_printf (sd
, "%%");
1069 address_word p
= *ap
++;
1071 while (sim_read (sd
, p
++, &ch
, 1) == 1 && ch
!= '\0')
1072 sim_io_printf(sd
, "%c", ch
);
1075 sim_io_printf(sd
,"(null)");
1078 sim_io_printf (sd
, "%c", (int)*ap
++);
1083 sim_read (sd
, s
++, &c
, 1);
1087 sim_read (sd
, s
++, &c
, 1);
1090 if (strchr ("dobxXu", c
))
1092 word64 lv
= (word64
) *ap
++;
1094 sim_io_printf(sd
,"<binary not supported>");
1097 sprintf (tmp
, "%%%s%c", longlong
? "ll" : "", c
);
1099 sim_io_printf(sd
, tmp
, lv
);
1101 sim_io_printf(sd
, tmp
, (int)lv
);
1104 else if (strchr ("eEfgG", c
))
1106 double dbl
= *(double*)(ap
++);
1107 sprintf (tmp
, "%%%d.%d%c", width
, trunc
, c
);
1108 sim_io_printf (sd
, tmp
, dbl
);
1114 sim_io_printf(sd
, "%c", c
);
1120 sim_io_error (sd
, "TODO: sim_monitor(%d) : PC = 0x%s\n",
1121 reason
, pr_addr(cia
));
1127 /* Store a word into memory. */
1130 store_word (SIM_DESC sd
,
1139 if ((vaddr
& 3) != 0)
1140 SignalExceptionAddressStore ();
1143 if (AddressTranslation (vaddr
, isDATA
, isSTORE
, &paddr
, &uncached
,
1146 const uword64 mask
= 7;
1150 paddr
= (paddr
& ~mask
) | ((paddr
& mask
) ^ (ReverseEndian
<< 2));
1151 byte
= (vaddr
& mask
) ^ (BigEndianCPU
<< 2);
1152 memval
= ((uword64
) val
) << (8 * byte
);
1153 StoreMemory (uncached
, AccessLength_WORD
, memval
, 0, paddr
, vaddr
,
1159 /* Load a word from memory. */
1162 load_word (SIM_DESC sd
,
1167 if ((vaddr
& 3) != 0)
1168 SignalExceptionAddressLoad ();
1174 if (AddressTranslation (vaddr
, isDATA
, isLOAD
, &paddr
, &uncached
,
1177 const uword64 mask
= 0x7;
1178 const unsigned int reverse
= ReverseEndian
? 1 : 0;
1179 const unsigned int bigend
= BigEndianCPU
? 1 : 0;
1183 paddr
= (paddr
& ~mask
) | ((paddr
& mask
) ^ (reverse
<< 2));
1184 LoadMemory (&memval
,NULL
,uncached
, AccessLength_WORD
, paddr
, vaddr
,
1186 byte
= (vaddr
& mask
) ^ (bigend
<< 2);
1187 return SIGNEXTEND (((memval
>> (8 * byte
)) & 0xffffffff), 32);
1194 /* Simulate the mips16 entry and exit pseudo-instructions. These
1195 would normally be handled by the reserved instruction exception
1196 code, but for ease of simulation we just handle them directly. */
1199 mips16_entry (SIM_DESC sd
,
1204 int aregs
, sregs
, rreg
;
1207 printf("DBG: mips16_entry: entered (insn = 0x%08X)\n",insn
);
1210 aregs
= (insn
& 0x700) >> 8;
1211 sregs
= (insn
& 0x0c0) >> 6;
1212 rreg
= (insn
& 0x020) >> 5;
1214 /* This should be checked by the caller. */
1223 /* This is the entry pseudo-instruction. */
1225 for (i
= 0; i
< aregs
; i
++)
1226 store_word (SD
, CPU
, cia
, (uword64
) (SP
+ 4 * i
), GPR
[i
+ 4]);
1234 store_word (SD
, CPU
, cia
, (uword64
) tsp
, RA
);
1237 for (i
= 0; i
< sregs
; i
++)
1240 store_word (SD
, CPU
, cia
, (uword64
) tsp
, GPR
[16 + i
]);
1248 /* This is the exit pseudo-instruction. */
1255 RA
= load_word (SD
, CPU
, cia
, (uword64
) tsp
);
1258 for (i
= 0; i
< sregs
; i
++)
1261 GPR
[i
+ 16] = load_word (SD
, CPU
, cia
, (uword64
) tsp
);
1266 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
1270 FGR
[0] = WORD64LO (GPR
[4]);
1271 FPR_STATE
[0] = fmt_uninterpreted
;
1273 else if (aregs
== 6)
1275 FGR
[0] = WORD64LO (GPR
[5]);
1276 FGR
[1] = WORD64LO (GPR
[4]);
1277 FPR_STATE
[0] = fmt_uninterpreted
;
1278 FPR_STATE
[1] = fmt_uninterpreted
;
1287 /*-- trace support ----------------------------------------------------------*/
1289 /* The TRACE support is provided (if required) in the memory accessing
1290 routines. Since we are also providing the architecture specific
1291 features, the architecture simulation code can also deal with
1292 notifying the TRACE world of cache flushes, etc. Similarly we do
1293 not need to provide profiling support in the simulator engine,
1294 since we can sample in the instruction fetch control loop. By
1295 defining the TRACE manifest, we add tracing as a run-time
1299 /* Tracing by default produces "din" format (as required by
1300 dineroIII). Each line of such a trace file *MUST* have a din label
1301 and address field. The rest of the line is ignored, so comments can
1302 be included if desired. The first field is the label which must be
1303 one of the following values:
1308 3 escape record (treated as unknown access type)
1309 4 escape record (causes cache flush)
1311 The address field is a 32bit (lower-case) hexadecimal address
1312 value. The address should *NOT* be preceded by "0x".
1314 The size of the memory transfer is not important when dealing with
1315 cache lines (as long as no more than a cache line can be
1316 transferred in a single operation :-), however more information
1317 could be given following the dineroIII requirement to allow more
1318 complete memory and cache simulators to provide better
1319 results. i.e. the University of Pisa has a cache simulator that can
1320 also take bus size and speed as (variable) inputs to calculate
1321 complete system performance (a much more useful ability when trying
1322 to construct an end product, rather than a processor). They
1323 currently have an ARM version of their tool called ChARM. */
1327 dotrace (SIM_DESC sd
,
1335 if (STATE
& simTRACE
) {
1337 fprintf(tracefh
,"%d %s ; width %d ; ",
1341 va_start(ap
,comment
);
1342 vfprintf(tracefh
,comment
,ap
);
1344 fprintf(tracefh
,"\n");
1346 /* NOTE: Since the "din" format will only accept 32bit addresses, and
1347 we may be generating 64bit ones, we should put the hi-32bits of the
1348 address into the comment field. */
1350 /* TODO: Provide a buffer for the trace lines. We can then avoid
1351 performing writes until the buffer is filled, or the file is
1354 /* NOTE: We could consider adding a comment field to the "din" file
1355 produced using type 3 markers (unknown access). This would then
1356 allow information about the program that the "din" is for, and
1357 the MIPs world that was being simulated, to be placed into the
1364 /*---------------------------------------------------------------------------*/
1365 /*-- simulator engine -------------------------------------------------------*/
1366 /*---------------------------------------------------------------------------*/
1369 ColdReset (SIM_DESC sd
)
1372 for (cpu_nr
= 0; cpu_nr
< sim_engine_nr_cpus (sd
); cpu_nr
++)
1374 sim_cpu
*cpu
= STATE_CPU (sd
, cpu_nr
);
1375 /* RESET: Fixed PC address: */
1376 PC
= UNSIGNED64 (0xFFFFFFFFBFC00000);
1377 /* The reset vector address is in the unmapped, uncached memory space. */
1379 SR
&= ~(status_SR
| status_TS
| status_RP
);
1380 SR
|= (status_ERL
| status_BEV
);
1382 /* Cheat and allow access to the complete register set immediately */
1383 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
1384 && WITH_TARGET_WORD_BITSIZE
== 64)
1385 SR
|= status_FR
; /* 64bit registers */
1387 /* Ensure that any instructions with pending register updates are
1389 PENDING_INVALIDATE();
1391 /* Initialise the FPU registers to the unknown state */
1392 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
1395 for (rn
= 0; (rn
< 32); rn
++)
1396 FPR_STATE
[rn
] = fmt_uninterpreted
;
1402 /* Description from page A-22 of the "MIPS IV Instruction Set" manual
1404 /* Translate a virtual address to a physical address and cache
1405 coherence algorithm describing the mechanism used to resolve the
1406 memory reference. Given the virtual address vAddr, and whether the
1407 reference is to Instructions ot Data (IorD), find the corresponding
1408 physical address (pAddr) and the cache coherence algorithm (CCA)
1409 used to resolve the reference. If the virtual address is in one of
1410 the unmapped address spaces the physical address and the CCA are
1411 determined directly by the virtual address. If the virtual address
1412 is in one of the mapped address spaces then the TLB is used to
1413 determine the physical address and access type; if the required
1414 translation is not present in the TLB or the desired access is not
1415 permitted the function fails and an exception is taken.
1417 NOTE: Normally (RAW == 0), when address translation fails, this
1418 function raises an exception and does not return. */
1421 address_translation (SIM_DESC sd
,
1427 address_word
*pAddr
,
1431 int res
= -1; /* TRUE : Assume good return */
1434 sim_io_printf(sd
,"AddressTranslation(0x%s,%s,%s,...);\n",pr_addr(vAddr
),(IorD
? "isDATA" : "isINSTRUCTION"),(LorS
? "iSTORE" : "isLOAD"));
1437 /* Check that the address is valid for this memory model */
1439 /* For a simple (flat) memory model, we simply pass virtual
1440 addressess through (mostly) unchanged. */
1441 vAddr
&= 0xFFFFFFFF;
1443 *pAddr
= vAddr
; /* default for isTARGET */
1444 *CCA
= Uncached
; /* not used for isHOST */
1449 /* Description from page A-23 of the "MIPS IV Instruction Set" manual
1451 /* Prefetch data from memory. Prefetch is an advisory instruction for
1452 which an implementation specific action is taken. The action taken
1453 may increase performance, but must not change the meaning of the
1454 program, or alter architecturally-visible state. */
1457 prefetch (SIM_DESC sd
,
1467 sim_io_printf(sd
,"Prefetch(%d,0x%s,0x%s,%d,%d);\n",CCA
,pr_addr(pAddr
),pr_addr(vAddr
),DATA
,hint
);
1470 /* For our simple memory model we do nothing */
1474 /* Description from page A-22 of the "MIPS IV Instruction Set" manual
1476 /* Load a value from memory. Use the cache and main memory as
1477 specified in the Cache Coherence Algorithm (CCA) and the sort of
1478 access (IorD) to find the contents of AccessLength memory bytes
1479 starting at physical location pAddr. The data is returned in the
1480 fixed width naturally-aligned memory element (MemElem). The
1481 low-order two (or three) bits of the address and the AccessLength
1482 indicate which of the bytes within MemElem needs to be given to the
1483 processor. If the memory access type of the reference is uncached
1484 then only the referenced bytes are read from memory and valid
1485 within the memory element. If the access type is cached, and the
1486 data is not present in cache, an implementation specific size and
1487 alignment block of memory is read and loaded into the cache to
1488 satisfy a load reference. At a minimum, the block is the entire
1491 load_memory (SIM_DESC sd
,
1506 sim_io_printf(sd
,"DBG: LoadMemory(%p,%p,%d,%d,0x%s,0x%s,%s)\n",memvalp
,memval1p
,CCA
,AccessLength
,pr_addr(pAddr
),pr_addr(vAddr
),(IorD
? "isDATA" : "isINSTRUCTION"));
1509 #if defined(WARN_MEM)
1510 if (CCA
!= uncached
)
1511 sim_io_eprintf(sd
,"LoadMemory CCA (%d) is not uncached (currently all accesses treated as cached)\n",CCA
);
1512 #endif /* WARN_MEM */
1514 /* If instruction fetch then we need to check that the two lo-order
1515 bits are zero, otherwise raise a InstructionFetch exception: */
1516 if ((IorD
== isINSTRUCTION
)
1517 && ((pAddr
& 0x3) != 0)
1518 && (((pAddr
& 0x1) != 0) || ((vAddr
& 0x1) == 0)))
1519 SignalExceptionInstructionFetch ();
1521 if (((pAddr
& LOADDRMASK
) + AccessLength
) > LOADDRMASK
)
1523 /* In reality this should be a Bus Error */
1524 sim_io_error (sd
, "AccessLength of %d would extend over %dbit aligned boundary for physical address 0x%s\n",
1526 (LOADDRMASK
+ 1) << 2,
1531 dotrace (SD
, CPU
, tracefh
,((IorD
== isDATA
) ? 0 : 2),(unsigned int)(pAddr
&0xFFFFFFFF),(AccessLength
+ 1),"load%s",((IorD
== isDATA
) ? "" : " instruction"));
1534 /* Read the specified number of bytes from memory. Adjust for
1535 host/target byte ordering/ Align the least significant byte
1538 switch (AccessLength
)
1540 case AccessLength_QUADWORD
:
1542 unsigned_16 val
= sim_core_read_aligned_16 (cpu
, NULL_CIA
,
1543 sim_core_read_map
, pAddr
);
1544 value1
= VH8_16 (val
);
1545 value
= VL8_16 (val
);
1548 case AccessLength_DOUBLEWORD
:
1549 value
= sim_core_read_aligned_8 (cpu
, NULL_CIA
,
1550 sim_core_read_map
, pAddr
);
1552 case AccessLength_SEPTIBYTE
:
1553 value
= sim_core_read_misaligned_7 (cpu
, NULL_CIA
,
1554 sim_core_read_map
, pAddr
);
1556 case AccessLength_SEXTIBYTE
:
1557 value
= sim_core_read_misaligned_6 (cpu
, NULL_CIA
,
1558 sim_core_read_map
, pAddr
);
1560 case AccessLength_QUINTIBYTE
:
1561 value
= sim_core_read_misaligned_5 (cpu
, NULL_CIA
,
1562 sim_core_read_map
, pAddr
);
1564 case AccessLength_WORD
:
1565 value
= sim_core_read_aligned_4 (cpu
, NULL_CIA
,
1566 sim_core_read_map
, pAddr
);
1568 case AccessLength_TRIPLEBYTE
:
1569 value
= sim_core_read_misaligned_3 (cpu
, NULL_CIA
,
1570 sim_core_read_map
, pAddr
);
1572 case AccessLength_HALFWORD
:
1573 value
= sim_core_read_aligned_2 (cpu
, NULL_CIA
,
1574 sim_core_read_map
, pAddr
);
1576 case AccessLength_BYTE
:
1577 value
= sim_core_read_aligned_1 (cpu
, NULL_CIA
,
1578 sim_core_read_map
, pAddr
);
1585 printf("DBG: LoadMemory() : (offset %d) : value = 0x%s%s\n",
1586 (int)(pAddr
& LOADDRMASK
),pr_uword64(value1
),pr_uword64(value
));
1589 /* See also store_memory. */
1590 if (AccessLength
<= AccessLength_DOUBLEWORD
)
1593 /* for big endian target, byte (pAddr&LOADDRMASK == 0) is
1594 shifted to the most significant byte position. */
1595 value
<<= (((7 - (pAddr
& LOADDRMASK
)) - AccessLength
) * 8);
1597 /* For little endian target, byte (pAddr&LOADDRMASK == 0)
1598 is already in the correct postition. */
1599 value
<<= ((pAddr
& LOADDRMASK
) * 8);
1603 printf("DBG: LoadMemory() : shifted value = 0x%s%s\n",
1604 pr_uword64(value1
),pr_uword64(value
));
1608 if (memval1p
) *memval1p
= value1
;
1612 /* Description from page A-23 of the "MIPS IV Instruction Set" manual
1614 /* Store a value to memory. The specified data is stored into the
1615 physical location pAddr using the memory hierarchy (data caches and
1616 main memory) as specified by the Cache Coherence Algorithm
1617 (CCA). The MemElem contains the data for an aligned, fixed-width
1618 memory element (word for 32-bit processors, doubleword for 64-bit
1619 processors), though only the bytes that will actually be stored to
1620 memory need to be valid. The low-order two (or three) bits of pAddr
1621 and the AccessLength field indicates which of the bytes within the
1622 MemElem data should actually be stored; only these bytes in memory
1626 store_memory (SIM_DESC sd
,
1632 uword64 MemElem1
, /* High order 64 bits */
1637 sim_io_printf(sd
,"DBG: StoreMemory(%d,%d,0x%s,0x%s,0x%s,0x%s)\n",CCA
,AccessLength
,pr_uword64(MemElem
),pr_uword64(MemElem1
),pr_addr(pAddr
),pr_addr(vAddr
));
1640 #if defined(WARN_MEM)
1641 if (CCA
!= uncached
)
1642 sim_io_eprintf(sd
,"StoreMemory CCA (%d) is not uncached (currently all accesses treated as cached)\n",CCA
);
1643 #endif /* WARN_MEM */
1645 if (((pAddr
& LOADDRMASK
) + AccessLength
) > LOADDRMASK
)
1646 sim_io_error(sd
,"AccessLength of %d would extend over %dbit aligned boundary for physical address 0x%s\n",AccessLength
,(LOADDRMASK
+ 1)<<2,pr_addr(pAddr
));
1649 dotrace (SD
, CPU
, tracefh
,1,(unsigned int)(pAddr
&0xFFFFFFFF),(AccessLength
+ 1),"store");
1653 printf("DBG: StoreMemory: offset = %d MemElem = 0x%s%s\n",(unsigned int)(pAddr
& LOADDRMASK
),pr_uword64(MemElem1
),pr_uword64(MemElem
));
1656 /* See also load_memory */
1657 if (AccessLength
<= AccessLength_DOUBLEWORD
)
1660 /* for big endian target, byte (pAddr&LOADDRMASK == 0) is
1661 shifted to the most significant byte position. */
1662 MemElem
>>= (((7 - (pAddr
& LOADDRMASK
)) - AccessLength
) * 8);
1664 /* For little endian target, byte (pAddr&LOADDRMASK == 0)
1665 is already in the correct postition. */
1666 MemElem
>>= ((pAddr
& LOADDRMASK
) * 8);
1670 printf("DBG: StoreMemory: shift = %d MemElem = 0x%s%s\n",shift
,pr_uword64(MemElem1
),pr_uword64(MemElem
));
1673 switch (AccessLength
)
1675 case AccessLength_QUADWORD
:
1677 unsigned_16 val
= U16_8 (MemElem1
, MemElem
);
1678 sim_core_write_aligned_16 (cpu
, NULL_CIA
,
1679 sim_core_write_map
, pAddr
, val
);
1682 case AccessLength_DOUBLEWORD
:
1683 sim_core_write_aligned_8 (cpu
, NULL_CIA
,
1684 sim_core_write_map
, pAddr
, MemElem
);
1686 case AccessLength_SEPTIBYTE
:
1687 sim_core_write_misaligned_7 (cpu
, NULL_CIA
,
1688 sim_core_write_map
, pAddr
, MemElem
);
1690 case AccessLength_SEXTIBYTE
:
1691 sim_core_write_misaligned_6 (cpu
, NULL_CIA
,
1692 sim_core_write_map
, pAddr
, MemElem
);
1694 case AccessLength_QUINTIBYTE
:
1695 sim_core_write_misaligned_5 (cpu
, NULL_CIA
,
1696 sim_core_write_map
, pAddr
, MemElem
);
1698 case AccessLength_WORD
:
1699 sim_core_write_aligned_4 (cpu
, NULL_CIA
,
1700 sim_core_write_map
, pAddr
, MemElem
);
1702 case AccessLength_TRIPLEBYTE
:
1703 sim_core_write_misaligned_3 (cpu
, NULL_CIA
,
1704 sim_core_write_map
, pAddr
, MemElem
);
1706 case AccessLength_HALFWORD
:
1707 sim_core_write_aligned_2 (cpu
, NULL_CIA
,
1708 sim_core_write_map
, pAddr
, MemElem
);
1710 case AccessLength_BYTE
:
1711 sim_core_write_aligned_1 (cpu
, NULL_CIA
,
1712 sim_core_write_map
, pAddr
, MemElem
);
1723 ifetch32 (SIM_DESC sd
,
1728 /* Copy the action of the LW instruction */
1729 address_word reverse
= (ReverseEndian
? (LOADDRMASK
>> 2) : 0);
1730 address_word bigend
= (BigEndianCPU
? (LOADDRMASK
>> 2) : 0);
1733 unsigned32 instruction
;
1736 AddressTranslation (vaddr
, isINSTRUCTION
, isLOAD
, &paddr
, &cca
, isTARGET
, isREAL
);
1737 paddr
= ((paddr
& ~LOADDRMASK
) | ((paddr
& LOADDRMASK
) ^ (reverse
<< 2)));
1738 LoadMemory (&value
, NULL
, cca
, AccessLength_WORD
, paddr
, vaddr
, isINSTRUCTION
, isREAL
);
1739 byte
= ((vaddr
& LOADDRMASK
) ^ (bigend
<< 2));
1740 instruction
= ((value
>> (8 * byte
)) & 0xFFFFFFFF);
1746 ifetch16 (SIM_DESC sd
,
1751 /* Copy the action of the LW instruction */
1752 address_word reverse
= (ReverseEndian
? (LOADDRMASK
>> 2) : 0);
1753 address_word bigend
= (BigEndianCPU
? (LOADDRMASK
>> 2) : 0);
1756 unsigned16 instruction
;
1759 AddressTranslation (vaddr
, isINSTRUCTION
, isLOAD
, &paddr
, &cca
, isTARGET
, isREAL
);
1760 paddr
= ((paddr
& ~LOADDRMASK
) | ((paddr
& LOADDRMASK
) ^ (reverse
<< 2)));
1761 LoadMemory (&value
, NULL
, cca
, AccessLength_WORD
, paddr
, vaddr
, isINSTRUCTION
, isREAL
);
1762 byte
= ((vaddr
& LOADDRMASK
) ^ (bigend
<< 2));
1763 instruction
= ((value
>> (8 * byte
)) & 0xFFFFFFFF);
1768 /* Description from page A-26 of the "MIPS IV Instruction Set" manual (revision 3.1) */
1769 /* Order loads and stores to synchronise shared memory. Perform the
1770 action necessary to make the effects of groups of synchronizable
1771 loads and stores indicated by stype occur in the same order for all
1774 sync_operation (SIM_DESC sd
,
1780 sim_io_printf(sd
,"SyncOperation(%d) : TODO\n",stype
);
1785 /* Description from page A-26 of the "MIPS IV Instruction Set" manual (revision 3.1) */
1786 /* Signal an exception condition. This will result in an exception
1787 that aborts the instruction. The instruction operation pseudocode
1788 will never see a return from this function call. */
1791 signal_exception (SIM_DESC sd
,
1799 sim_io_printf(sd
,"DBG: SignalException(%d) PC = 0x%s\n",exception
,pr_addr(cia
));
1802 /* Ensure that any active atomic read/modify/write operation will fail: */
1805 switch (exception
) {
1806 /* TODO: For testing purposes I have been ignoring TRAPs. In
1807 reality we should either simulate them, or allow the user to
1808 ignore them at run-time.
1811 sim_io_eprintf(sd
,"Ignoring instruction TRAP (PC 0x%s)\n",pr_addr(cia
));
1817 unsigned int instruction
;
1820 va_start(ap
,exception
);
1821 instruction
= va_arg(ap
,unsigned int);
1824 code
= (instruction
>> 6) & 0xFFFFF;
1826 sim_io_eprintf(sd
,"Ignoring instruction `syscall %d' (PC 0x%s)\n",
1827 code
, pr_addr(cia
));
1831 case DebugBreakPoint
:
1832 if (! (Debug
& Debug_DM
))
1838 Debug
|= Debug_DBD
; /* signaled from within in delay slot */
1839 DEPC
= cia
- 4; /* reference the branch instruction */
1843 Debug
&= ~Debug_DBD
; /* not signaled from within a delay slot */
1847 Debug
|= Debug_DM
; /* in debugging mode */
1848 Debug
|= Debug_DBp
; /* raising a DBp exception */
1850 sim_engine_restart (SD
, CPU
, NULL
, NULL_CIA
);
1854 case ReservedInstruction
:
1857 unsigned int instruction
;
1858 va_start(ap
,exception
);
1859 instruction
= va_arg(ap
,unsigned int);
1861 /* Provide simple monitor support using ReservedInstruction
1862 exceptions. The following code simulates the fixed vector
1863 entry points into the IDT monitor by causing a simulator
1864 trap, performing the monitor operation, and returning to
1865 the address held in the $ra register (standard PCS return
1866 address). This means we only need to pre-load the vector
1867 space with suitable instruction values. For systems were
1868 actual trap instructions are used, we would not need to
1869 perform this magic. */
1870 if ((instruction
& RSVD_INSTRUCTION_MASK
) == RSVD_INSTRUCTION
)
1872 sim_monitor (SD
, CPU
, cia
, ((instruction
>> RSVD_INSTRUCTION_ARG_SHIFT
) & RSVD_INSTRUCTION_ARG_MASK
) );
1873 /* NOTE: This assumes that a branch-and-link style
1874 instruction was used to enter the vector (which is the
1875 case with the current IDT monitor). */
1876 sim_engine_restart (SD
, CPU
, NULL
, RA
);
1878 /* Look for the mips16 entry and exit instructions, and
1879 simulate a handler for them. */
1880 else if ((cia
& 1) != 0
1881 && (instruction
& 0xf81f) == 0xe809
1882 && (instruction
& 0x0c0) != 0x0c0)
1884 mips16_entry (SD
, CPU
, cia
, instruction
);
1885 sim_engine_restart (sd
, NULL
, NULL
, NULL_CIA
);
1887 /* else fall through to normal exception processing */
1888 sim_io_eprintf(sd
,"ReservedInstruction 0x%08X at PC = 0x%s\n",instruction
,pr_addr(cia
));
1893 sim_io_printf(sd
,"DBG: SignalException(%d) PC = 0x%s\n",exception
,pr_addr(cia
));
1895 /* Keep a copy of the current A0 in-case this is the program exit
1899 unsigned int instruction
;
1900 va_start(ap
,exception
);
1901 instruction
= va_arg(ap
,unsigned int);
1903 /* Check for our special terminating BREAK: */
1904 if ((instruction
& 0x03FFFFC0) == 0x03ff0000) {
1905 sim_engine_halt (SD
, CPU
, NULL
, cia
,
1906 sim_exited
, (unsigned int)(A0
& 0xFFFFFFFF));
1909 if (STATE
& simDELAYSLOT
)
1910 PC
= cia
- 4; /* reference the branch instruction */
1913 sim_engine_halt (SD
, CPU
, NULL
, cia
,
1914 sim_stopped
, SIM_SIGTRAP
);
1917 /* Store exception code into current exception id variable (used
1920 /* TODO: If not simulating exceptions then stop the simulator
1921 execution. At the moment we always stop the simulation. */
1923 /* See figure 5-17 for an outline of the code below */
1924 if (! (SR
& status_EXL
))
1926 CAUSE
= (exception
<< 2);
1927 if (STATE
& simDELAYSLOT
)
1929 STATE
&= ~simDELAYSLOT
;
1931 EPC
= (cia
- 4); /* reference the branch instruction */
1935 /* FIXME: TLB et.al. */
1940 CAUSE
= (exception
<< 2);
1944 /* Store exception code into current exception id variable (used
1946 if (SR
& status_BEV
)
1947 PC
= (signed)0xBFC00200 + 0x180;
1949 PC
= (signed)0x80000000 + 0x180;
1951 switch ((CAUSE
>> 2) & 0x1F)
1954 /* Interrupts arrive during event processing, no need to
1958 case TLBModification
:
1963 case InstructionFetch
:
1965 /* The following is so that the simulator will continue from the
1966 exception address on breakpoint operations. */
1968 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
,
1969 sim_stopped
, SIM_SIGBUS
);
1971 case ReservedInstruction
:
1972 case CoProcessorUnusable
:
1974 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
,
1975 sim_stopped
, SIM_SIGILL
);
1977 case IntegerOverflow
:
1979 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
,
1980 sim_stopped
, SIM_SIGFPE
);
1986 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
,
1987 sim_stopped
, SIM_SIGTRAP
);
1991 sim_engine_abort (SD
, CPU
, NULL_CIA
,
1992 "FATAL: Should not encounter a breakpoint\n");
1994 default : /* Unknown internal exception */
1996 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
,
1997 sim_stopped
, SIM_SIGABRT
);
2001 case SimulatorFault
:
2005 va_start(ap
,exception
);
2006 msg
= va_arg(ap
,char *);
2008 sim_engine_abort (SD
, CPU
, NULL_CIA
,
2009 "FATAL: Simulator error \"%s\"\n",msg
);
2016 #if defined(WARN_RESULT)
2017 /* Description from page A-26 of the "MIPS IV Instruction Set" manual (revision 3.1) */
2018 /* This function indicates that the result of the operation is
2019 undefined. However, this should not affect the instruction
2020 stream. All that is meant to happen is that the destination
2021 register is set to an undefined result. To keep the simulator
2022 simple, we just don't bother updating the destination register, so
2023 the overall result will be undefined. If desired we can stop the
2024 simulator by raising a pseudo-exception. */
2025 #define UndefinedResult() undefined_result (sd,cia)
2027 undefined_result(sd
,cia
)
2031 sim_io_eprintf(sd
,"UndefinedResult: PC = 0x%s\n",pr_addr(cia
));
2032 #if 0 /* Disabled for the moment, since it actually happens a lot at the moment. */
2037 #endif /* WARN_RESULT */
2040 cache_op (SIM_DESC sd
,
2046 unsigned int instruction
)
2048 #if 1 /* stop warning message being displayed (we should really just remove the code) */
2049 static int icache_warning
= 1;
2050 static int dcache_warning
= 1;
2052 static int icache_warning
= 0;
2053 static int dcache_warning
= 0;
2056 /* If CP0 is not useable (User or Supervisor mode) and the CP0
2057 enable bit in the Status Register is clear - a coprocessor
2058 unusable exception is taken. */
2060 sim_io_printf(sd
,"TODO: Cache availability checking (PC = 0x%s)\n",pr_addr(cia
));
2064 case 0: /* instruction cache */
2066 case 0: /* Index Invalidate */
2067 case 1: /* Index Load Tag */
2068 case 2: /* Index Store Tag */
2069 case 4: /* Hit Invalidate */
2071 case 6: /* Hit Writeback */
2072 if (!icache_warning
)
2074 sim_io_eprintf(sd
,"Instruction CACHE operation %d to be coded\n",(op
>> 2));
2080 SignalException(ReservedInstruction
,instruction
);
2085 case 1: /* data cache */
2087 case 0: /* Index Writeback Invalidate */
2088 case 1: /* Index Load Tag */
2089 case 2: /* Index Store Tag */
2090 case 3: /* Create Dirty */
2091 case 4: /* Hit Invalidate */
2092 case 5: /* Hit Writeback Invalidate */
2093 case 6: /* Hit Writeback */
2094 if (!dcache_warning
)
2096 sim_io_eprintf(sd
,"Data CACHE operation %d to be coded\n",(op
>> 2));
2102 SignalException(ReservedInstruction
,instruction
);
2107 default: /* unrecognised cache ID */
2108 SignalException(ReservedInstruction
,instruction
);
2115 /*-- FPU support routines ---------------------------------------------------*/
2117 /* Numbers are held in normalized form. The SINGLE and DOUBLE binary
2118 formats conform to ANSI/IEEE Std 754-1985. */
2119 /* SINGLE precision floating:
2120 * seeeeeeeefffffffffffffffffffffff
2122 * e = 8bits = exponent
2123 * f = 23bits = fraction
2125 /* SINGLE precision fixed:
2126 * siiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
2128 * i = 31bits = integer
2130 /* DOUBLE precision floating:
2131 * seeeeeeeeeeeffffffffffffffffffffffffffffffffffffffffffffffffffff
2133 * e = 11bits = exponent
2134 * f = 52bits = fraction
2136 /* DOUBLE precision fixed:
2137 * siiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
2139 * i = 63bits = integer
2142 /* Extract sign-bit: */
2143 #define FP_S_s(v) (((v) & ((unsigned)1 << 31)) ? 1 : 0)
2144 #define FP_D_s(v) (((v) & ((uword64)1 << 63)) ? 1 : 0)
2145 /* Extract biased exponent: */
2146 #define FP_S_be(v) (((v) >> 23) & 0xFF)
2147 #define FP_D_be(v) (((v) >> 52) & 0x7FF)
2148 /* Extract unbiased Exponent: */
2149 #define FP_S_e(v) (FP_S_be(v) - 0x7F)
2150 #define FP_D_e(v) (FP_D_be(v) - 0x3FF)
2151 /* Extract complete fraction field: */
2152 #define FP_S_f(v) ((v) & ~((unsigned)0x1FF << 23))
2153 #define FP_D_f(v) ((v) & ~((uword64)0xFFF << 52))
2154 /* Extract numbered fraction bit: */
2155 #define FP_S_fb(b,v) (((v) & (1 << (23 - (b)))) ? 1 : 0)
2156 #define FP_D_fb(b,v) (((v) & (1 << (52 - (b)))) ? 1 : 0)
2158 /* Explicit QNaN values used when value required: */
2159 #define FPQNaN_SINGLE (0x7FBFFFFF)
2160 #define FPQNaN_WORD (0x7FFFFFFF)
2161 #define FPQNaN_DOUBLE (((uword64)0x7FF7FFFF << 32) | 0xFFFFFFFF)
2162 #define FPQNaN_LONG (((uword64)0x7FFFFFFF << 32) | 0xFFFFFFFF)
2164 /* Explicit Infinity values used when required: */
2165 #define FPINF_SINGLE (0x7F800000)
2166 #define FPINF_DOUBLE (((uword64)0x7FF00000 << 32) | 0x00000000)
2168 #if 1 /* def DEBUG */
2169 #define RMMODE(v) (((v) == FP_RM_NEAREST) ? "Round" : (((v) == FP_RM_TOZERO) ? "Trunc" : (((v) == FP_RM_TOPINF) ? "Ceil" : "Floor")))
2170 #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>"))))))
2174 value_fpr (SIM_DESC sd
,
2183 /* Treat unused register values, as fixed-point 64bit values: */
2184 if ((fmt
== fmt_uninterpreted
) || (fmt
== fmt_unknown
))
2186 /* If request to read data as "uninterpreted", then use the current
2188 fmt
= FPR_STATE
[fpr
];
2193 /* For values not yet accessed, set to the desired format: */
2194 if (FPR_STATE
[fpr
] == fmt_uninterpreted
) {
2195 FPR_STATE
[fpr
] = fmt
;
2197 printf("DBG: Register %d was fmt_uninterpreted. Now %s\n",fpr
,DOFMT(fmt
));
2200 if (fmt
!= FPR_STATE
[fpr
]) {
2201 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
));
2202 FPR_STATE
[fpr
] = fmt_unknown
;
2205 if (FPR_STATE
[fpr
] == fmt_unknown
) {
2206 /* Set QNaN value: */
2209 value
= FPQNaN_SINGLE
;
2213 value
= FPQNaN_DOUBLE
;
2217 value
= FPQNaN_WORD
;
2221 value
= FPQNaN_LONG
;
2228 } else if (SizeFGR() == 64) {
2232 value
= (FGR
[fpr
] & 0xFFFFFFFF);
2235 case fmt_uninterpreted
:
2249 value
= (FGR
[fpr
] & 0xFFFFFFFF);
2252 case fmt_uninterpreted
:
2255 if ((fpr
& 1) == 0) { /* even registers only */
2256 value
= ((((uword64
)FGR
[fpr
+1]) << 32) | (FGR
[fpr
] & 0xFFFFFFFF));
2258 SignalException(ReservedInstruction
,0);
2269 SignalExceptionSimulatorFault ("Unrecognised FP format in ValueFPR()");
2272 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());
2279 store_fpr (SIM_DESC sd
,
2289 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());
2292 if (SizeFGR() == 64) {
2294 case fmt_uninterpreted_32
:
2295 fmt
= fmt_uninterpreted
;
2298 FGR
[fpr
] = (((uword64
)0xDEADC0DE << 32) | (value
& 0xFFFFFFFF));
2299 FPR_STATE
[fpr
] = fmt
;
2302 case fmt_uninterpreted_64
:
2303 fmt
= fmt_uninterpreted
;
2304 case fmt_uninterpreted
:
2308 FPR_STATE
[fpr
] = fmt
;
2312 FPR_STATE
[fpr
] = fmt_unknown
;
2318 case fmt_uninterpreted_32
:
2319 fmt
= fmt_uninterpreted
;
2322 FGR
[fpr
] = (value
& 0xFFFFFFFF);
2323 FPR_STATE
[fpr
] = fmt
;
2326 case fmt_uninterpreted_64
:
2327 fmt
= fmt_uninterpreted
;
2328 case fmt_uninterpreted
:
2331 if ((fpr
& 1) == 0) { /* even register number only */
2332 FGR
[fpr
+1] = (value
>> 32);
2333 FGR
[fpr
] = (value
& 0xFFFFFFFF);
2334 FPR_STATE
[fpr
+ 1] = fmt
;
2335 FPR_STATE
[fpr
] = fmt
;
2337 FPR_STATE
[fpr
] = fmt_unknown
;
2338 FPR_STATE
[fpr
+ 1] = fmt_unknown
;
2339 SignalException(ReservedInstruction
,0);
2344 FPR_STATE
[fpr
] = fmt_unknown
;
2349 #if defined(WARN_RESULT)
2352 #endif /* WARN_RESULT */
2355 SignalExceptionSimulatorFault ("Unrecognised FP format in StoreFPR()");
2358 printf("DBG: StoreFPR: fpr[%d] = 0x%s (format %s)\n",fpr
,pr_addr(FGR
[fpr
]),DOFMT(fmt
));
2375 sim_fpu_32to (&wop
, op
);
2376 boolean
= sim_fpu_is_nan (&wop
);
2383 sim_fpu_64to (&wop
, op
);
2384 boolean
= sim_fpu_is_nan (&wop
);
2388 fprintf (stderr
, "Bad switch\n");
2393 printf("DBG: NaN: returning %d for 0x%s (format = %s)\n",boolean
,pr_addr(op
),DOFMT(fmt
));
2407 printf("DBG: Infinity: format %s 0x%s\n",DOFMT(fmt
),pr_addr(op
));
2414 sim_fpu_32to (&wop
, op
);
2415 boolean
= sim_fpu_is_infinity (&wop
);
2421 sim_fpu_64to (&wop
, op
);
2422 boolean
= sim_fpu_is_infinity (&wop
);
2426 printf("DBG: TODO: unrecognised format (%s) for Infinity check\n",DOFMT(fmt
));
2431 printf("DBG: Infinity: returning %d for 0x%s (format = %s)\n",boolean
,pr_addr(op
),DOFMT(fmt
));
2445 /* Argument checking already performed by the FPCOMPARE code */
2448 printf("DBG: Less: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2451 /* The format type should already have been checked: */
2457 sim_fpu_32to (&wop1
, op1
);
2458 sim_fpu_32to (&wop2
, op2
);
2459 boolean
= sim_fpu_is_lt (&wop1
, &wop2
);
2466 sim_fpu_64to (&wop1
, op1
);
2467 sim_fpu_64to (&wop2
, op2
);
2468 boolean
= sim_fpu_is_lt (&wop1
, &wop2
);
2472 fprintf (stderr
, "Bad switch\n");
2477 printf("DBG: Less: returning %d (format = %s)\n",boolean
,DOFMT(fmt
));
2491 /* Argument checking already performed by the FPCOMPARE code */
2494 printf("DBG: Equal: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2497 /* The format type should already have been checked: */
2503 sim_fpu_32to (&wop1
, op1
);
2504 sim_fpu_32to (&wop2
, op2
);
2505 boolean
= sim_fpu_is_eq (&wop1
, &wop2
);
2512 sim_fpu_64to (&wop1
, op1
);
2513 sim_fpu_64to (&wop2
, op2
);
2514 boolean
= sim_fpu_is_eq (&wop1
, &wop2
);
2518 fprintf (stderr
, "Bad switch\n");
2523 printf("DBG: Equal: returning %d (format = %s)\n",boolean
,DOFMT(fmt
));
2530 AbsoluteValue(op
,fmt
)
2537 printf("DBG: AbsoluteValue: %s: op = 0x%s\n",DOFMT(fmt
),pr_addr(op
));
2540 /* The format type should already have been checked: */
2546 sim_fpu_32to (&wop
, op
);
2547 sim_fpu_abs (&wop
, &wop
);
2548 sim_fpu_to32 (&ans
, &wop
);
2556 sim_fpu_64to (&wop
, op
);
2557 sim_fpu_abs (&wop
, &wop
);
2558 sim_fpu_to64 (&ans
, &wop
);
2563 fprintf (stderr
, "Bad switch\n");
2578 printf("DBG: Negate: %s: op = 0x%s\n",DOFMT(fmt
),pr_addr(op
));
2581 /* The format type should already have been checked: */
2587 sim_fpu_32to (&wop
, op
);
2588 sim_fpu_neg (&wop
, &wop
);
2589 sim_fpu_to32 (&ans
, &wop
);
2597 sim_fpu_64to (&wop
, op
);
2598 sim_fpu_neg (&wop
, &wop
);
2599 sim_fpu_to64 (&ans
, &wop
);
2604 fprintf (stderr
, "Bad switch\n");
2620 printf("DBG: Add: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2623 /* The registers must specify FPRs valid for operands of type
2624 "fmt". If they are not valid, the result is undefined. */
2626 /* The format type should already have been checked: */
2634 sim_fpu_32to (&wop1
, op1
);
2635 sim_fpu_32to (&wop2
, op2
);
2636 sim_fpu_add (&ans
, &wop1
, &wop2
);
2637 sim_fpu_to32 (&res
, &ans
);
2647 sim_fpu_64to (&wop1
, op1
);
2648 sim_fpu_64to (&wop2
, op2
);
2649 sim_fpu_add (&ans
, &wop1
, &wop2
);
2650 sim_fpu_to64 (&res
, &ans
);
2655 fprintf (stderr
, "Bad switch\n");
2660 printf("DBG: Add: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2675 printf("DBG: Sub: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2678 /* The registers must specify FPRs valid for operands of type
2679 "fmt". If they are not valid, the result is undefined. */
2681 /* The format type should already have been checked: */
2689 sim_fpu_32to (&wop1
, op1
);
2690 sim_fpu_32to (&wop2
, op2
);
2691 sim_fpu_sub (&ans
, &wop1
, &wop2
);
2692 sim_fpu_to32 (&res
, &ans
);
2702 sim_fpu_64to (&wop1
, op1
);
2703 sim_fpu_64to (&wop2
, op2
);
2704 sim_fpu_sub (&ans
, &wop1
, &wop2
);
2705 sim_fpu_to64 (&res
, &ans
);
2710 fprintf (stderr
, "Bad switch\n");
2715 printf("DBG: Sub: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2722 Multiply(op1
,op2
,fmt
)
2730 printf("DBG: Multiply: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2733 /* The registers must specify FPRs valid for operands of type
2734 "fmt". If they are not valid, the result is undefined. */
2736 /* The format type should already have been checked: */
2744 sim_fpu_32to (&wop1
, op1
);
2745 sim_fpu_32to (&wop2
, op2
);
2746 sim_fpu_mul (&ans
, &wop1
, &wop2
);
2747 sim_fpu_to32 (&res
, &ans
);
2757 sim_fpu_64to (&wop1
, op1
);
2758 sim_fpu_64to (&wop2
, op2
);
2759 sim_fpu_mul (&ans
, &wop1
, &wop2
);
2760 sim_fpu_to64 (&res
, &ans
);
2765 fprintf (stderr
, "Bad switch\n");
2770 printf("DBG: Multiply: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2785 printf("DBG: Divide: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2788 /* The registers must specify FPRs valid for operands of type
2789 "fmt". If they are not valid, the result is undefined. */
2791 /* The format type should already have been checked: */
2799 sim_fpu_32to (&wop1
, op1
);
2800 sim_fpu_32to (&wop2
, op2
);
2801 sim_fpu_div (&ans
, &wop1
, &wop2
);
2802 sim_fpu_to32 (&res
, &ans
);
2812 sim_fpu_64to (&wop1
, op1
);
2813 sim_fpu_64to (&wop2
, op2
);
2814 sim_fpu_div (&ans
, &wop1
, &wop2
);
2815 sim_fpu_to64 (&res
, &ans
);
2820 fprintf (stderr
, "Bad switch\n");
2825 printf("DBG: Divide: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2839 printf("DBG: Recip: %s: op = 0x%s\n",DOFMT(fmt
),pr_addr(op
));
2842 /* The registers must specify FPRs valid for operands of type
2843 "fmt". If they are not valid, the result is undefined. */
2845 /* The format type should already have been checked: */
2852 sim_fpu_32to (&wop
, op
);
2853 sim_fpu_inv (&ans
, &wop
);
2854 sim_fpu_to32 (&res
, &ans
);
2863 sim_fpu_64to (&wop
, op
);
2864 sim_fpu_inv (&ans
, &wop
);
2865 sim_fpu_to64 (&res
, &ans
);
2870 fprintf (stderr
, "Bad switch\n");
2875 printf("DBG: Recip: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2889 printf("DBG: SquareRoot: %s: op = 0x%s\n",DOFMT(fmt
),pr_addr(op
));
2892 /* The registers must specify FPRs valid for operands of type
2893 "fmt". If they are not valid, the result is undefined. */
2895 /* The format type should already have been checked: */
2902 sim_fpu_32to (&wop
, op
);
2903 sim_fpu_sqrt (&ans
, &wop
);
2904 sim_fpu_to32 (&res
, &ans
);
2913 sim_fpu_64to (&wop
, op
);
2914 sim_fpu_sqrt (&ans
, &wop
);
2915 sim_fpu_to64 (&res
, &ans
);
2920 fprintf (stderr
, "Bad switch\n");
2925 printf("DBG: SquareRoot: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
2940 printf("DBG: Max: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
2943 /* The registers must specify FPRs valid for operands of type
2944 "fmt". If they are not valid, the result is undefined. */
2946 /* The format type should already have been checked: */
2953 sim_fpu_32to (&wop1
, op1
);
2954 sim_fpu_32to (&wop2
, op2
);
2955 cmp
= sim_fpu_cmp (&wop1
, &wop2
);
2962 sim_fpu_64to (&wop1
, op1
);
2963 sim_fpu_64to (&wop2
, op2
);
2964 cmp
= sim_fpu_cmp (&wop1
, &wop2
);
2968 fprintf (stderr
, "Bad switch\n");
2974 case SIM_FPU_IS_SNAN
:
2975 case SIM_FPU_IS_QNAN
:
2977 case SIM_FPU_IS_NINF
:
2978 case SIM_FPU_IS_NNUMBER
:
2979 case SIM_FPU_IS_NDENORM
:
2980 case SIM_FPU_IS_NZERO
:
2981 result
= op2
; /* op1 - op2 < 0 */
2982 case SIM_FPU_IS_PINF
:
2983 case SIM_FPU_IS_PNUMBER
:
2984 case SIM_FPU_IS_PDENORM
:
2985 case SIM_FPU_IS_PZERO
:
2986 result
= op1
; /* op1 - op2 > 0 */
2988 fprintf (stderr
, "Bad switch\n");
2993 printf("DBG: Max: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
3008 printf("DBG: Min: %s: op1 = 0x%s : op2 = 0x%s\n",DOFMT(fmt
),pr_addr(op1
),pr_addr(op2
));
3011 /* The registers must specify FPRs valid for operands of type
3012 "fmt". If they are not valid, the result is undefined. */
3014 /* The format type should already have been checked: */
3021 sim_fpu_32to (&wop1
, op1
);
3022 sim_fpu_32to (&wop2
, op2
);
3023 cmp
= sim_fpu_cmp (&wop1
, &wop2
);
3030 sim_fpu_64to (&wop1
, op1
);
3031 sim_fpu_64to (&wop2
, op2
);
3032 cmp
= sim_fpu_cmp (&wop1
, &wop2
);
3036 fprintf (stderr
, "Bad switch\n");
3042 case SIM_FPU_IS_SNAN
:
3043 case SIM_FPU_IS_QNAN
:
3045 case SIM_FPU_IS_NINF
:
3046 case SIM_FPU_IS_NNUMBER
:
3047 case SIM_FPU_IS_NDENORM
:
3048 case SIM_FPU_IS_NZERO
:
3049 result
= op1
; /* op1 - op2 < 0 */
3050 case SIM_FPU_IS_PINF
:
3051 case SIM_FPU_IS_PNUMBER
:
3052 case SIM_FPU_IS_PDENORM
:
3053 case SIM_FPU_IS_PZERO
:
3054 result
= op2
; /* op1 - op2 > 0 */
3056 fprintf (stderr
, "Bad switch\n");
3061 printf("DBG: Min: returning 0x%s (format = %s)\n",pr_addr(result
),DOFMT(fmt
));
3068 convert (SIM_DESC sd
,
3077 sim_fpu_round round
;
3078 unsigned32 result32
;
3079 unsigned64 result64
;
3082 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
));
3088 /* Round result to nearest representable value. When two
3089 representable values are equally near, round to the value
3090 that has a least significant bit of zero (i.e. is even). */
3091 round
= sim_fpu_round_near
;
3094 /* Round result to the value closest to, and not greater in
3095 magnitude than, the result. */
3096 round
= sim_fpu_round_zero
;
3099 /* Round result to the value closest to, and not less than,
3101 round
= sim_fpu_round_up
;
3105 /* Round result to the value closest to, and not greater than,
3107 round
= sim_fpu_round_down
;
3111 fprintf (stderr
, "Bad switch\n");
3115 /* Convert the input to sim_fpu internal format */
3119 sim_fpu_64to (&wop
, op
);
3122 sim_fpu_32to (&wop
, op
);
3125 sim_fpu_i32to (&wop
, op
, round
);
3128 sim_fpu_i64to (&wop
, op
, round
);
3131 fprintf (stderr
, "Bad switch\n");
3135 /* Convert sim_fpu format into the output */
3136 /* The value WOP is converted to the destination format, rounding
3137 using mode RM. When the destination is a fixed-point format, then
3138 a source value of Infinity, NaN or one which would round to an
3139 integer outside the fixed point range then an IEEE Invalid
3140 Operation condition is raised. */
3144 sim_fpu_round_32 (&wop
, round
, 0);
3145 sim_fpu_to32 (&result32
, &wop
);
3146 result64
= result32
;
3149 sim_fpu_round_64 (&wop
, round
, 0);
3150 sim_fpu_to64 (&result64
, &wop
);
3153 sim_fpu_to32i (&result32
, &wop
, round
);
3154 result64
= result32
;
3157 sim_fpu_to64i (&result64
, &wop
, round
);
3161 fprintf (stderr
, "Bad switch\n");
3166 printf("DBG: Convert: returning 0x%s (to format = %s)\n",pr_addr(result64
),DOFMT(to
));
3173 /*-- co-processor support routines ------------------------------------------*/
3176 CoProcPresent(coproc_number
)
3177 unsigned int coproc_number
;
3179 /* Return TRUE if simulator provides a model for the given co-processor number */
3184 cop_lw (SIM_DESC sd
,
3189 unsigned int memword
)
3194 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
3197 printf("DBG: COP_LW: memword = 0x%08X (uword64)memword = 0x%s\n",memword
,pr_addr(memword
));
3199 StoreFPR(coproc_reg
,fmt_word
,(uword64
)memword
);
3200 FPR_STATE
[coproc_reg
] = fmt_uninterpreted
;
3205 #if 0 /* this should be controlled by a configuration option */
3206 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
));
3215 cop_ld (SIM_DESC sd
,
3222 switch (coproc_num
) {
3224 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
3226 StoreFPR(coproc_reg
,fmt_uninterpreted
,memword
);
3231 #if 0 /* this message should be controlled by a configuration option */
3232 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
));
3241 cop_sw (SIM_DESC sd
,
3247 unsigned int value
= 0;
3252 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
3255 hold
= FPR_STATE
[coproc_reg
];
3256 FPR_STATE
[coproc_reg
] = fmt_word
;
3257 value
= (unsigned int)ValueFPR(coproc_reg
,fmt_uninterpreted
);
3258 FPR_STATE
[coproc_reg
] = hold
;
3263 #if 0 /* should be controlled by configuration option */
3264 sim_io_printf(sd
,"COP_SW(%d,%d) at PC = 0x%s : TODO (architecture specific)\n",coproc_num
,coproc_reg
,pr_addr(cia
));
3273 cop_sd (SIM_DESC sd
,
3283 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
3285 value
= ValueFPR(coproc_reg
,fmt_uninterpreted
);
3290 #if 0 /* should be controlled by configuration option */
3291 sim_io_printf(sd
,"COP_SD(%d,%d) at PC = 0x%s : TODO (architecture specific)\n",coproc_num
,coproc_reg
,pr_addr(cia
));
3300 decode_coproc (SIM_DESC sd
,
3303 unsigned int instruction
)
3305 int coprocnum
= ((instruction
>> 26) & 3);
3309 case 0: /* standard CPU control and cache registers */
3311 int code
= ((instruction
>> 21) & 0x1F);
3312 /* R4000 Users Manual (second edition) lists the following CP0
3314 DMFC0 Doubleword Move From CP0 (VR4100 = 01000000001tttttddddd00000000000)
3315 DMTC0 Doubleword Move To CP0 (VR4100 = 01000000101tttttddddd00000000000)
3316 MFC0 word Move From CP0 (VR4100 = 01000000000tttttddddd00000000000)
3317 MTC0 word Move To CP0 (VR4100 = 01000000100tttttddddd00000000000)
3318 TLBR Read Indexed TLB Entry (VR4100 = 01000010000000000000000000000001)
3319 TLBWI Write Indexed TLB Entry (VR4100 = 01000010000000000000000000000010)
3320 TLBWR Write Random TLB Entry (VR4100 = 01000010000000000000000000000110)
3321 TLBP Probe TLB for Matching Entry (VR4100 = 01000010000000000000000000001000)
3322 CACHE Cache operation (VR4100 = 101111bbbbbpppppiiiiiiiiiiiiiiii)
3323 ERET Exception return (VR4100 = 01000010000000000000000000011000)
3325 if (((code
== 0x00) || (code
== 0x04)) && ((instruction
& 0x7FF) == 0))
3327 int rt
= ((instruction
>> 16) & 0x1F);
3328 int rd
= ((instruction
>> 11) & 0x1F);
3330 switch (rd
) /* NOTEs: Standard CP0 registers */
3332 /* 0 = Index R4000 VR4100 VR4300 */
3333 /* 1 = Random R4000 VR4100 VR4300 */
3334 /* 2 = EntryLo0 R4000 VR4100 VR4300 */
3335 /* 3 = EntryLo1 R4000 VR4100 VR4300 */
3336 /* 4 = Context R4000 VR4100 VR4300 */
3337 /* 5 = PageMask R4000 VR4100 VR4300 */
3338 /* 6 = Wired R4000 VR4100 VR4300 */
3339 /* 8 = BadVAddr R4000 VR4100 VR4300 */
3340 /* 9 = Count R4000 VR4100 VR4300 */
3341 /* 10 = EntryHi R4000 VR4100 VR4300 */
3342 /* 11 = Compare R4000 VR4100 VR4300 */
3343 /* 12 = SR R4000 VR4100 VR4300 */
3350 /* 13 = Cause R4000 VR4100 VR4300 */
3357 /* 14 = EPC R4000 VR4100 VR4300 */
3358 /* 15 = PRId R4000 VR4100 VR4300 */
3359 #ifdef SUBTARGET_R3900
3368 /* 16 = Config R4000 VR4100 VR4300 */
3371 GPR
[rt
] = C0_CONFIG
;
3373 C0_CONFIG
= GPR
[rt
];
3376 #ifdef SUBTARGET_R3900
3385 /* 17 = LLAddr R4000 VR4100 VR4300 */
3387 /* 18 = WatchLo R4000 VR4100 VR4300 */
3388 /* 19 = WatchHi R4000 VR4100 VR4300 */
3389 /* 20 = XContext R4000 VR4100 VR4300 */
3390 /* 26 = PErr or ECC R4000 VR4100 VR4300 */
3391 /* 27 = CacheErr R4000 VR4100 */
3392 /* 28 = TagLo R4000 VR4100 VR4300 */
3393 /* 29 = TagHi R4000 VR4100 VR4300 */
3394 /* 30 = ErrorEPC R4000 VR4100 VR4300 */
3395 GPR
[rt
] = 0xDEADC0DE; /* CPR[0,rd] */
3396 /* CPR[0,rd] = GPR[rt]; */
3399 sim_io_printf(sd
,"Warning: MFC0 %d,%d ignored (architecture specific)\n",rt
,rd
);
3401 sim_io_printf(sd
,"Warning: MTC0 %d,%d ignored (architecture specific)\n",rt
,rd
);
3404 else if (code
== 0x10 && (instruction
& 0x3f) == 0x18)
3407 if (SR
& status_ERL
)
3409 /* Oops, not yet available */
3410 sim_io_printf(sd
,"Warning: ERET when SR[ERL] set not handled yet");
3420 else if (code
== 0x10 && (instruction
& 0x3f) == 0x10)
3424 else if (code
== 0x10 && (instruction
& 0x3f) == 0x1F)
3432 sim_io_eprintf(sd
,"Unrecognised COP0 instruction 0x%08X at PC = 0x%s : No handler present\n",instruction
,pr_addr(cia
));
3433 /* TODO: When executing an ERET or RFE instruction we should
3434 clear LLBIT, to ensure that any out-standing atomic
3435 read/modify/write sequence fails. */
3439 case 2: /* undefined co-processor */
3440 sim_io_eprintf(sd
,"COP2 instruction 0x%08X at PC = 0x%s : No handler present\n",instruction
,pr_addr(cia
));
3443 case 1: /* should not occur (FPU co-processor) */
3444 case 3: /* should not occur (FPU co-processor) */
3445 SignalException(ReservedInstruction
,instruction
);
3452 /*-- instruction simulation -------------------------------------------------*/
3454 /* When the IGEN simulator is being built, the function below is be
3455 replaced by a generated version. However, WITH_IGEN == 2 indicates
3456 that the fubction below should be compiled but under a different
3457 name (to allow backward compatibility) */
3459 #if (WITH_IGEN != 1)
3461 void old_engine_run
PARAMS ((SIM_DESC sd
, int next_cpu_nr
, int siggnal
));
3463 old_engine_run (sd
, next_cpu_nr
, nr_cpus
, siggnal
)
3466 sim_engine_run (sd
, next_cpu_nr
, nr_cpus
, siggnal
)
3469 int next_cpu_nr
; /* ignore */
3470 int nr_cpus
; /* ignore */
3471 int siggnal
; /* ignore */
3473 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* hardwire to cpu 0 */
3474 #if !defined(FASTSIM)
3475 unsigned int pipeline_count
= 1;
3479 if (STATE_MEMORY (sd
) == NULL
) {
3480 printf("DBG: simulate() entered with no memory\n");
3485 #if 0 /* Disabled to check that everything works OK */
3486 /* The VR4300 seems to sign-extend the PC on its first
3487 access. However, this may just be because it is currently
3488 configured in 32bit mode. However... */
3489 PC
= SIGNEXTEND(PC
,32);
3492 /* main controlling loop */
3494 /* vaddr is slowly being replaced with cia - current instruction
3496 address_word cia
= (uword64
)PC
;
3497 address_word vaddr
= cia
;
3500 unsigned int instruction
; /* uword64? what's this used for? FIXME! */
3504 printf("DBG: state = 0x%08X :",state
);
3505 if (state
& simHALTEX
) printf(" simHALTEX");
3506 if (state
& simHALTIN
) printf(" simHALTIN");
3511 DSSTATE
= (STATE
& simDELAYSLOT
);
3514 sim_io_printf(sd
,"DBG: DSPC = 0x%s\n",pr_addr(DSPC
));
3517 /* Fetch the next instruction from the simulator memory: */
3518 if (AddressTranslation(cia
,isINSTRUCTION
,isLOAD
,&paddr
,&cca
,isTARGET
,isREAL
)) {
3519 if ((vaddr
& 1) == 0) {
3520 /* Copy the action of the LW instruction */
3521 unsigned int reverse
= (ReverseEndian
? (LOADDRMASK
>> 2) : 0);
3522 unsigned int bigend
= (BigEndianCPU
? (LOADDRMASK
>> 2) : 0);
3525 paddr
= ((paddr
& ~LOADDRMASK
) | ((paddr
& LOADDRMASK
) ^ (reverse
<< 2)));
3526 LoadMemory(&value
,NULL
,cca
,AccessLength_WORD
,paddr
,vaddr
,isINSTRUCTION
,isREAL
);
3527 byte
= ((vaddr
& LOADDRMASK
) ^ (bigend
<< 2));
3528 instruction
= ((value
>> (8 * byte
)) & 0xFFFFFFFF);
3530 /* Copy the action of the LH instruction */
3531 unsigned int reverse
= (ReverseEndian
? (LOADDRMASK
>> 1) : 0);
3532 unsigned int bigend
= (BigEndianCPU
? (LOADDRMASK
>> 1) : 0);
3535 paddr
= (((paddr
& ~ (uword64
) 1) & ~LOADDRMASK
)
3536 | (((paddr
& ~ (uword64
) 1) & LOADDRMASK
) ^ (reverse
<< 1)));
3537 LoadMemory(&value
,NULL
,cca
, AccessLength_HALFWORD
,
3538 paddr
& ~ (uword64
) 1,
3539 vaddr
, isINSTRUCTION
, isREAL
);
3540 byte
= (((vaddr
&~ (uword64
) 1) & LOADDRMASK
) ^ (bigend
<< 1));
3541 instruction
= ((value
>> (8 * byte
)) & 0xFFFF);
3544 fprintf(stderr
,"Cannot translate address for PC = 0x%s failed\n",pr_addr(PC
));
3549 sim_io_printf(sd
,"DBG: fetched 0x%08X from PC = 0x%s\n",instruction
,pr_addr(PC
));
3552 /* This is required by exception processing, to ensure that we can
3553 cope with exceptions in the delay slots of branches that may
3554 already have changed the PC. */
3555 if ((vaddr
& 1) == 0)
3556 PC
+= 4; /* increment ready for the next fetch */
3559 /* NOTE: If we perform a delay slot change to the PC, this
3560 increment is not requuired. However, it would make the
3561 simulator more complicated to try and avoid this small hit. */
3563 /* Currently this code provides a simple model. For more
3564 complicated models we could perform exception status checks at
3565 this point, and set the simSTOP state as required. This could
3566 also include processing any hardware interrupts raised by any
3567 I/O model attached to the simulator context.
3569 Support for "asynchronous" I/O events within the simulated world
3570 could be providing by managing a counter, and calling a I/O
3571 specific handler when a particular threshold is reached. On most
3572 architectures a decrement and check for zero operation is
3573 usually quicker than an increment and compare. However, the
3574 process of managing a known value decrement to zero, is higher
3575 than the cost of using an explicit value UINT_MAX into the
3576 future. Which system is used will depend on how complicated the
3577 I/O model is, and how much it is likely to affect the simulator
3580 If events need to be scheduled further in the future than
3581 UINT_MAX event ticks, then the I/O model should just provide its
3582 own counter, triggered from the event system. */
3584 /* MIPS pipeline ticks. To allow for future support where the
3585 pipeline hit of individual instructions is known, this control
3586 loop manages a "pipeline_count" variable. It is initialised to
3587 1 (one), and will only be changed by the simulator engine when
3588 executing an instruction. If the engine does not have access to
3589 pipeline cycle count information then all instructions will be
3590 treated as using a single cycle. NOTE: A standard system is not
3591 provided by the default simulator because different MIPS
3592 architectures have different cycle counts for the same
3595 [NOTE: pipeline_count has been replaced the event queue] */
3597 /* shuffle the floating point status pipeline state */
3598 ENGINE_ISSUE_PREFIX_HOOK();
3600 /* NOTE: For multi-context simulation environments the "instruction"
3601 variable should be local to this routine. */
3603 /* Shorthand accesses for engine. Note: If we wanted to use global
3604 variables (and a single-threaded simulator engine), then we can
3605 create the actual variables with these names. */
3607 if (!(STATE
& simSKIPNEXT
)) {
3608 /* Include the simulator engine */
3609 #include "oengine.c"
3610 #if ((GPRLEN == 64) && !PROCESSOR_64BIT) || ((GPRLEN == 32) && PROCESSOR_64BIT)
3611 #error "Mismatch between run-time simulator code and simulation engine"
3613 #if (WITH_TARGET_WORD_BITSIZE != GPRLEN)
3614 #error "Mismatch between configure WITH_TARGET_WORD_BITSIZE and gencode GPRLEN"
3616 #if ((WITH_FLOATING_POINT == HARD_FLOATING_POINT) != defined (HASFPU))
3617 #error "Mismatch between configure WITH_FLOATING_POINT and gencode HASFPU"
3620 #if defined(WARN_LOHI)
3621 /* Decrement the HI/LO validity ticks */
3626 /* start-sanitize-r5900 */
3631 /* end-sanitize-r5900 */
3632 #endif /* WARN_LOHI */
3634 /* For certain MIPS architectures, GPR[0] is hardwired to zero. We
3635 should check for it being changed. It is better doing it here,
3636 than within the simulator, since it will help keep the simulator
3639 #if defined(WARN_ZERO)
3640 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
));
3641 #endif /* WARN_ZERO */
3642 ZERO
= 0; /* reset back to zero before next instruction */
3644 } else /* simSKIPNEXT check */
3645 STATE
&= ~simSKIPNEXT
;
3647 /* If the delay slot was active before the instruction is
3648 executed, then update the PC to its new value: */
3651 printf("DBG: dsstate set before instruction execution - updating PC to 0x%s\n",pr_addr(DSPC
));
3660 #if !defined(FASTSIM)
3661 if (sim_events_tickn (sd
, pipeline_count
))
3663 /* cpu->cia = cia; */
3664 sim_events_process (sd
);
3667 if (sim_events_tick (sd
))
3669 /* cpu->cia = cia; */
3670 sim_events_process (sd
);
3672 #endif /* FASTSIM */
3678 /* This code copied from gdb's utils.c. Would like to share this code,
3679 but don't know of a common place where both could get to it. */
3681 /* Temporary storage using circular buffer */
3687 static char buf
[NUMCELLS
][CELLSIZE
];
3689 if (++cell
>=NUMCELLS
) cell
=0;
3693 /* Print routines to handle variable size regs, etc */
3695 /* Eliminate warning from compiler on 32-bit systems */
3696 static int thirty_two
= 32;
3702 char *paddr_str
=get_cell();
3703 switch (sizeof(addr
))
3706 sprintf(paddr_str
,"%08lx%08lx",
3707 (unsigned long)(addr
>>thirty_two
),(unsigned long)(addr
&0xffffffff));
3710 sprintf(paddr_str
,"%08lx",(unsigned long)addr
);
3713 sprintf(paddr_str
,"%04x",(unsigned short)(addr
&0xffff));
3716 sprintf(paddr_str
,"%x",addr
);
3725 char *paddr_str
=get_cell();
3726 sprintf(paddr_str
,"%08lx%08lx",
3727 (unsigned long)(addr
>>thirty_two
),(unsigned long)(addr
&0xffffffff));
3733 pending_tick (SIM_DESC sd
,
3738 sim_io_printf (sd
, "PENDING_DRAIN - pending_in = %d, pending_out = %d, pending_total = %d\n", PENDING_IN
, PENDING_OUT
, PENDING_TOTAL
);
3739 if (PENDING_OUT
!= PENDING_IN
)
3742 int index
= PENDING_OUT
;
3743 int total
= PENDING_TOTAL
;
3744 if (PENDING_TOTAL
== 0)
3745 sim_engine_abort (SD
, CPU
, cia
, "PENDING_DRAIN - Mis-match on pending update pointers\n");
3746 for (loop
= 0; (loop
< total
); loop
++)
3748 if (PENDING_SLOT_DEST
[index
] != NULL
)
3750 PENDING_SLOT_DELAY
[index
] -= 1;
3751 if (PENDING_SLOT_DELAY
[index
] == 0)
3753 if (PENDING_SLOT_BIT
[index
] >= 0)
3754 switch (PENDING_SLOT_SIZE
[index
])
3757 if (PENDING_SLOT_VALUE
[index
])
3758 *(unsigned32
*)PENDING_SLOT_DEST
[index
] |=
3759 BIT32 (PENDING_SLOT_BIT
[index
]);
3761 *(unsigned32
*)PENDING_SLOT_DEST
[index
] &=
3762 BIT32 (PENDING_SLOT_BIT
[index
]);
3765 if (PENDING_SLOT_VALUE
[index
])
3766 *(unsigned64
*)PENDING_SLOT_DEST
[index
] |=
3767 BIT64 (PENDING_SLOT_BIT
[index
]);
3769 *(unsigned64
*)PENDING_SLOT_DEST
[index
] &=
3770 BIT64 (PENDING_SLOT_BIT
[index
]);
3775 switch (PENDING_SLOT_SIZE
[index
])
3778 *(unsigned32
*)PENDING_SLOT_DEST
[index
] =
3779 PENDING_SLOT_VALUE
[index
];
3782 *(unsigned64
*)PENDING_SLOT_DEST
[index
] =
3783 PENDING_SLOT_VALUE
[index
];
3787 if (PENDING_OUT
== index
)
3789 PENDING_SLOT_DEST
[index
] = NULL
;
3790 PENDING_OUT
= (PENDING_OUT
+ 1) % PSLOTS
;
3795 index
= (index
+ 1) % PSLOTS
;
3799 /*---------------------------------------------------------------------------*/
3800 /*> EOF interp.c <*/