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.
18 The IDT monitor (found on the VR4300 board), seems to lie about
19 register contents. It seems to treat the registers as sign-extended
20 32-bit values. This cause *REAL* problems when single-stepping 64-bit
28 #include "sim-utils.h"
29 #include "sim-options.h"
30 #include "sim-assert.h"
48 #include "libiberty.h"
51 #include "sim/callback.h" /* GDB simulator callback interface */
52 #include "sim/sim.h" /* GDB simulator interface */
53 #include "sim-syscall.h" /* Simulator system call support */
55 char* pr_addr (SIM_ADDR addr
);
56 char* pr_uword64 (uword64 addr
);
59 /* Within interp.c we refer to the sim_state and sim_cpu directly. */
64 /* The following reserved instruction value is used when a simulator
65 trap is required. NOTE: Care must be taken, since this value may be
66 used in later revisions of the MIPS ISA. */
68 #define RSVD_INSTRUCTION (0x00000039)
69 #define RSVD_INSTRUCTION_MASK (0xFC00003F)
71 #define RSVD_INSTRUCTION_ARG_SHIFT 6
72 #define RSVD_INSTRUCTION_ARG_MASK 0xFFFFF
75 /* Bits in the Debug register */
76 #define Debug_DBD 0x80000000 /* Debug Branch Delay */
77 #define Debug_DM 0x40000000 /* Debug Mode */
78 #define Debug_DBp 0x00000002 /* Debug Breakpoint indicator */
80 /*---------------------------------------------------------------------------*/
81 /*-- GDB simulator interface ------------------------------------------------*/
82 /*---------------------------------------------------------------------------*/
84 static void ColdReset (SIM_DESC sd
);
86 /*---------------------------------------------------------------------------*/
90 #define DELAYSLOT() {\
91 if (STATE & simDELAYSLOT)\
92 sim_io_eprintf(sd,"Delay slot already activated (branch in delay slot?)\n");\
93 STATE |= simDELAYSLOT;\
96 #define JALDELAYSLOT() {\
98 STATE |= simJALDELAYSLOT;\
102 STATE &= ~simDELAYSLOT;\
103 STATE |= simSKIPNEXT;\
106 #define CANCELDELAYSLOT() {\
108 STATE &= ~(simDELAYSLOT | simJALDELAYSLOT);\
111 #define INDELAYSLOT() ((STATE & simDELAYSLOT) != 0)
112 #define INJALDELAYSLOT() ((STATE & simJALDELAYSLOT) != 0)
114 /* Note that the monitor code essentially assumes this layout of memory.
115 If you change these, change the monitor code, too. */
116 /* FIXME Currently addresses are truncated to 32-bits, see
117 mips/sim-main.c:address_translation(). If that changes, then these
118 values will need to be extended, and tested for more carefully. */
119 #define K0BASE (0x80000000)
120 #define K0SIZE (0x20000000)
121 #define K1BASE (0xA0000000)
122 #define K1SIZE (0x20000000)
124 /* Simple run-time monitor support.
126 We emulate the monitor by placing magic reserved instructions at
127 the monitor's entry points; when we hit these instructions, instead
128 of raising an exception (as we would normally), we look at the
129 instruction and perform the appropriate monitory operation.
131 `*_monitor_base' are the physical addresses at which the corresponding
132 monitor vectors are located. `0' means none. By default,
134 The RSVD_INSTRUCTION... macros specify the magic instructions we
135 use at the monitor entry points. */
136 static int firmware_option_p
= 0;
137 static SIM_ADDR idt_monitor_base
= 0xBFC00000;
138 static SIM_ADDR pmon_monitor_base
= 0xBFC00500;
139 static SIM_ADDR lsipmon_monitor_base
= 0xBFC00200;
141 static SIM_RC
sim_firmware_command (SIM_DESC sd
, char* arg
);
143 #define MEM_SIZE (8 << 20) /* 8 MBytes */
147 static char *tracefile
= "trace.din"; /* default filename for trace log */
148 FILE *tracefh
= NULL
;
149 static void open_trace (SIM_DESC sd
);
151 #define open_trace(sd)
154 static const char * get_insn_name (sim_cpu
*, int);
156 /* simulation target board. NULL=canonical */
157 static char* board
= NULL
;
160 static DECLARE_OPTION_HANDLER (mips_option_handler
);
163 OPTION_DINERO_TRACE
= OPTION_START
,
170 static int display_mem_info
= 0;
173 mips_option_handler (SIM_DESC sd
, sim_cpu
*cpu
, int opt
, char *arg
,
179 case OPTION_DINERO_TRACE
: /* ??? */
181 /* Eventually the simTRACE flag could be treated as a toggle, to
182 allow external control of the program points being traced
183 (i.e. only from main onwards, excluding the run-time setup,
185 for (cpu_nr
= 0; cpu_nr
< MAX_NR_PROCESSORS
; cpu_nr
++)
187 sim_cpu
*cpu
= STATE_CPU (sd
, cpu_nr
);
190 else if (strcmp (arg
, "yes") == 0)
192 else if (strcmp (arg
, "no") == 0)
194 else if (strcmp (arg
, "on") == 0)
196 else if (strcmp (arg
, "off") == 0)
200 fprintf (stderr
, "Unrecognized dinero-trace option `%s'\n", arg
);
205 #else /* !WITH_TRACE_ANY_P */
207 Simulator constructed without dinero tracing support (for performance).\n\
208 Re-compile simulator with \"-DWITH_TRACE_ANY_P\" to enable this option.\n");
210 #endif /* !WITH_TRACE_ANY_P */
212 case OPTION_DINERO_FILE
:
214 if (optarg
!= NULL
) {
216 tmp
= (char *)malloc(strlen(optarg
) + 1);
219 sim_io_printf(sd
,"Failed to allocate buffer for tracefile name \"%s\"\n",optarg
);
225 sim_io_printf(sd
,"Placing trace information into file \"%s\"\n",tracefile
);
228 #endif /* WITH_TRACE_ANY_P */
231 case OPTION_FIRMWARE
:
232 return sim_firmware_command (sd
, arg
);
238 board
= zalloc(strlen(arg
) + 1);
244 case OPTION_INFO_MEMORY
:
245 display_mem_info
= 1;
253 static const OPTION mips_options
[] =
255 { {"dinero-trace", optional_argument
, NULL
, OPTION_DINERO_TRACE
},
256 '\0', "on|off", "Enable dinero tracing",
257 mips_option_handler
},
258 { {"dinero-file", required_argument
, NULL
, OPTION_DINERO_FILE
},
259 '\0', "FILE", "Write dinero trace to FILE",
260 mips_option_handler
},
261 { {"firmware", required_argument
, NULL
, OPTION_FIRMWARE
},
262 '\0', "[idt|pmon|lsipmon|none][@ADDRESS]", "Emulate ROM monitor",
263 mips_option_handler
},
264 { {"board", required_argument
, NULL
, OPTION_BOARD
},
265 '\0', "none" /* rely on compile-time string concatenation for other options */
267 #define BOARD_JMR3904 "jmr3904"
269 #define BOARD_JMR3904_PAL "jmr3904pal"
270 "|" BOARD_JMR3904_PAL
271 #define BOARD_JMR3904_DEBUG "jmr3904debug"
272 "|" BOARD_JMR3904_DEBUG
273 #define BOARD_BSP "bsp"
276 , "Customize simulation for a particular board.", mips_option_handler
},
278 /* These next two options have the same names as ones found in the
279 memory_options[] array in common/sim-memopt.c. This is because
280 the intention is to provide an alternative handler for those two
281 options. We need an alternative handler because the memory
282 regions are not set up until after the command line arguments
283 have been parsed, and so we cannot display the memory info whilst
284 processing the command line. There is a hack in sim_open to
285 remove these handlers when we want the real --memory-info option
287 { { "info-memory", no_argument
, NULL
, OPTION_INFO_MEMORY
},
288 '\0', NULL
, "List configured memory regions", mips_option_handler
},
289 { { "memory-info", no_argument
, NULL
, OPTION_INFO_MEMORY
},
290 '\0', NULL
, NULL
, mips_option_handler
},
292 { {NULL
, no_argument
, NULL
, 0}, '\0', NULL
, NULL
, NULL
}
296 int interrupt_pending
;
299 interrupt_event (SIM_DESC sd
, void *data
)
301 sim_cpu
*cpu
= STATE_CPU (sd
, 0); /* FIXME */
302 address_word cia
= CPU_PC_GET (cpu
);
305 interrupt_pending
= 0;
306 SignalExceptionInterrupt (1); /* interrupt "1" */
308 else if (!interrupt_pending
)
309 sim_events_schedule (sd
, 1, interrupt_event
, data
);
313 /*---------------------------------------------------------------------------*/
314 /*-- Device registration hook -----------------------------------------------*/
315 /*---------------------------------------------------------------------------*/
316 static void device_init(SIM_DESC sd
) {
318 extern void register_devices(SIM_DESC
);
319 register_devices(sd
);
323 /*---------------------------------------------------------------------------*/
324 /*-- GDB simulator interface ------------------------------------------------*/
325 /*---------------------------------------------------------------------------*/
328 mips_pc_get (sim_cpu
*cpu
)
334 mips_pc_set (sim_cpu
*cpu
, sim_cia pc
)
339 static int mips_reg_fetch (SIM_CPU
*, int, unsigned char *, int);
340 static int mips_reg_store (SIM_CPU
*, int, unsigned char *, int);
343 sim_open (SIM_OPEN_KIND kind
, host_callback
*cb
,
344 struct bfd
*abfd
, char * const *argv
)
347 SIM_DESC sd
= sim_state_alloc (kind
, cb
);
350 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
352 /* The cpu data is kept in a separately allocated chunk of memory. */
353 if (sim_cpu_alloc_all (sd
, 1) != SIM_RC_OK
)
356 cpu
= STATE_CPU (sd
, 0); /* FIXME */
358 /* FIXME: watchpoints code shouldn't need this */
359 STATE_WATCHPOINTS (sd
)->interrupt_handler
= interrupt_event
;
361 /* Initialize the mechanism for doing insn profiling. */
362 CPU_INSN_NAME (cpu
) = get_insn_name
;
363 CPU_MAX_INSNS (cpu
) = nr_itable_entries
;
367 if (sim_pre_argv_init (sd
, argv
[0]) != SIM_RC_OK
)
369 sim_add_option_table (sd
, NULL
, mips_options
);
372 /* The parser will print an error message for us, so we silently return. */
373 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
375 /* Uninstall the modules to avoid memory leaks,
376 file descriptor leaks, etc. */
377 sim_module_uninstall (sd
);
381 /* handle board-specific memory maps */
384 /* Allocate core managed memory */
385 sim_memopt
*entry
, *match
= NULL
;
386 address_word mem_size
= 0;
389 /* For compatibility with the old code - under this (at level one)
390 are the kernel spaces K0 & K1. Both of these map to a single
391 smaller sub region */
392 sim_do_command(sd
," memory region 0x7fff8000,0x8000") ; /* MTZ- 32 k stack */
394 /* Look for largest memory region defined on command-line at
396 for (entry
= STATE_MEMOPT (sd
); entry
!= NULL
; entry
= entry
->next
)
398 /* If we find an entry at address 0, then we will end up
399 allocating a new buffer in the "memory alias" command
400 below. The region at address 0 will be deleted. */
401 address_word size
= (entry
->modulo
!= 0
402 ? entry
->modulo
: entry
->nr_bytes
);
404 && (!match
|| entry
->level
< match
->level
))
406 else if (entry
->addr
== K0BASE
|| entry
->addr
== K1BASE
)
411 for (alias
= entry
->alias
; alias
!= NULL
; alias
= alias
->next
)
414 && (!match
|| entry
->level
< match
->level
))
416 else if (alias
->addr
== K0BASE
|| alias
->addr
== K1BASE
)
426 /* Get existing memory region size. */
427 mem_size
= (match
->modulo
!= 0
428 ? match
->modulo
: match
->nr_bytes
);
429 /* Delete old region. */
430 sim_do_commandf (sd
, "memory delete %d:0x%lx@%d",
431 match
->space
, match
->addr
, match
->level
);
433 else if (mem_size
== 0)
435 /* Limit to KSEG1 size (512MB) */
436 if (mem_size
> K1SIZE
)
438 /* memory alias K1BASE@1,K1SIZE%MEMSIZE,K0BASE */
439 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx%%0x%lx,0x%0x",
440 K1BASE
, K1SIZE
, (long)mem_size
, K0BASE
);
445 else if (board
!= NULL
446 && (strcmp(board
, BOARD_BSP
) == 0))
450 STATE_ENVIRONMENT (sd
) = OPERATING_ENVIRONMENT
;
452 /* ROM: 0x9FC0_0000 - 0x9FFF_FFFF and 0xBFC0_0000 - 0xBFFF_FFFF */
453 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx,0x%0x",
455 4 * 1024 * 1024, /* 4 MB */
458 /* SRAM: 0x8000_0000 - 0x803F_FFFF and 0xA000_0000 - 0xA03F_FFFF */
459 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx,0x%0x",
461 4 * 1024 * 1024, /* 4 MB */
464 /* DRAM: 0x8800_0000 - 0x89FF_FFFF and 0xA800_0000 - 0xA9FF_FFFF */
465 for (i
=0; i
<8; i
++) /* 32 MB total */
467 unsigned size
= 4 * 1024 * 1024; /* 4 MB */
468 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx,0x%0x",
469 0x88000000 + (i
* size
),
471 0xA8000000 + (i
* size
));
475 else if (board
!= NULL
476 && (strcmp(board
, BOARD_JMR3904
) == 0 ||
477 strcmp(board
, BOARD_JMR3904_PAL
) == 0 ||
478 strcmp(board
, BOARD_JMR3904_DEBUG
) == 0))
480 /* match VIRTUAL memory layout of JMR-TX3904 board */
483 /* --- disable monitor unless forced on by user --- */
485 if (! firmware_option_p
)
487 idt_monitor_base
= 0;
488 pmon_monitor_base
= 0;
489 lsipmon_monitor_base
= 0;
492 /* --- environment --- */
494 STATE_ENVIRONMENT (sd
) = OPERATING_ENVIRONMENT
;
498 /* ROM: 0x9FC0_0000 - 0x9FFF_FFFF and 0xBFC0_0000 - 0xBFFF_FFFF */
499 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx,0x%0x",
501 4 * 1024 * 1024, /* 4 MB */
504 /* SRAM: 0x8000_0000 - 0x803F_FFFF and 0xA000_0000 - 0xA03F_FFFF */
505 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx,0x%0x",
507 4 * 1024 * 1024, /* 4 MB */
510 /* DRAM: 0x8800_0000 - 0x89FF_FFFF and 0xA800_0000 - 0xA9FF_FFFF */
511 for (i
=0; i
<8; i
++) /* 32 MB total */
513 unsigned size
= 4 * 1024 * 1024; /* 4 MB */
514 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx,0x%0x",
515 0x88000000 + (i
* size
),
517 0xA8000000 + (i
* size
));
520 /* Dummy memory regions for unsimulated devices - sorted by address */
522 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx", 0xB1000000, 0x400); /* ISA I/O */
523 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx", 0xB2100000, 0x004); /* ISA ctl */
524 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx", 0xB2500000, 0x004); /* LED/switch */
525 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx", 0xB2700000, 0x004); /* RTC */
526 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx", 0xB3C00000, 0x004); /* RTC */
527 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx", 0xFFFF8000, 0x900); /* DRAMC */
528 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx", 0xFFFF9000, 0x200); /* EBIF */
529 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx", 0xFFFFE000, 0x01c); /* EBIF */
530 sim_do_commandf (sd
, "memory alias 0x%lx@1,0x%lx", 0xFFFFF500, 0x300); /* PIO */
533 /* --- simulated devices --- */
534 sim_hw_parse (sd
, "/tx3904irc@0xffffc000/reg 0xffffc000 0x20");
535 sim_hw_parse (sd
, "/tx3904cpu");
536 sim_hw_parse (sd
, "/tx3904tmr@0xfffff000/reg 0xfffff000 0x100");
537 sim_hw_parse (sd
, "/tx3904tmr@0xfffff100/reg 0xfffff100 0x100");
538 sim_hw_parse (sd
, "/tx3904tmr@0xfffff200/reg 0xfffff200 0x100");
539 sim_hw_parse (sd
, "/tx3904sio@0xfffff300/reg 0xfffff300 0x100");
541 /* FIXME: poking at dv-sockser internals, use tcp backend if
542 --sockser_addr option was given.*/
543 extern char* sockser_addr
;
544 if(sockser_addr
== NULL
)
545 sim_hw_parse (sd
, "/tx3904sio@0xfffff300/backend stdio");
547 sim_hw_parse (sd
, "/tx3904sio@0xfffff300/backend tcp");
549 sim_hw_parse (sd
, "/tx3904sio@0xfffff400/reg 0xfffff400 0x100");
550 sim_hw_parse (sd
, "/tx3904sio@0xfffff400/backend stdio");
552 /* -- device connections --- */
553 sim_hw_parse (sd
, "/tx3904irc > ip level /tx3904cpu");
554 sim_hw_parse (sd
, "/tx3904tmr@0xfffff000 > int tmr0 /tx3904irc");
555 sim_hw_parse (sd
, "/tx3904tmr@0xfffff100 > int tmr1 /tx3904irc");
556 sim_hw_parse (sd
, "/tx3904tmr@0xfffff200 > int tmr2 /tx3904irc");
557 sim_hw_parse (sd
, "/tx3904sio@0xfffff300 > int sio0 /tx3904irc");
558 sim_hw_parse (sd
, "/tx3904sio@0xfffff400 > int sio1 /tx3904irc");
560 /* add PAL timer & I/O module */
561 if(! strcmp(board
, BOARD_JMR3904_PAL
))
564 sim_hw_parse (sd
, "/pal@0xffff0000");
565 sim_hw_parse (sd
, "/pal@0xffff0000/reg 0xffff0000 64");
567 /* wire up interrupt ports to irc */
568 sim_hw_parse (sd
, "/pal@0x31000000 > countdown tmr0 /tx3904irc");
569 sim_hw_parse (sd
, "/pal@0x31000000 > timer tmr1 /tx3904irc");
570 sim_hw_parse (sd
, "/pal@0x31000000 > int int0 /tx3904irc");
573 if(! strcmp(board
, BOARD_JMR3904_DEBUG
))
575 /* -- DEBUG: glue interrupt generators --- */
576 sim_hw_parse (sd
, "/glue@0xffff0000/reg 0xffff0000 0x50");
577 sim_hw_parse (sd
, "/glue@0xffff0000 > int0 int0 /tx3904irc");
578 sim_hw_parse (sd
, "/glue@0xffff0000 > int1 int1 /tx3904irc");
579 sim_hw_parse (sd
, "/glue@0xffff0000 > int2 int2 /tx3904irc");
580 sim_hw_parse (sd
, "/glue@0xffff0000 > int3 int3 /tx3904irc");
581 sim_hw_parse (sd
, "/glue@0xffff0000 > int4 int4 /tx3904irc");
582 sim_hw_parse (sd
, "/glue@0xffff0000 > int5 int5 /tx3904irc");
583 sim_hw_parse (sd
, "/glue@0xffff0000 > int6 int6 /tx3904irc");
584 sim_hw_parse (sd
, "/glue@0xffff0000 > int7 int7 /tx3904irc");
585 sim_hw_parse (sd
, "/glue@0xffff0000 > int8 dmac0 /tx3904irc");
586 sim_hw_parse (sd
, "/glue@0xffff0000 > int9 dmac1 /tx3904irc");
587 sim_hw_parse (sd
, "/glue@0xffff0000 > int10 dmac2 /tx3904irc");
588 sim_hw_parse (sd
, "/glue@0xffff0000 > int11 dmac3 /tx3904irc");
589 sim_hw_parse (sd
, "/glue@0xffff0000 > int12 sio0 /tx3904irc");
590 sim_hw_parse (sd
, "/glue@0xffff0000 > int13 sio1 /tx3904irc");
591 sim_hw_parse (sd
, "/glue@0xffff0000 > int14 tmr0 /tx3904irc");
592 sim_hw_parse (sd
, "/glue@0xffff0000 > int15 tmr1 /tx3904irc");
593 sim_hw_parse (sd
, "/glue@0xffff0000 > int16 tmr2 /tx3904irc");
594 sim_hw_parse (sd
, "/glue@0xffff0000 > int17 nmi /tx3904cpu");
601 if (display_mem_info
)
603 struct option_list
* ol
;
604 struct option_list
* prev
;
606 /* This is a hack. We want to execute the real --memory-info command
607 line switch which is handled in common/sim-memopts.c, not the
608 override we have defined in this file. So we remove the
609 mips_options array from the state options list. This is safe
610 because we have now processed all of the command line. */
611 for (ol
= STATE_OPTIONS (sd
), prev
= NULL
;
613 prev
= ol
, ol
= ol
->next
)
614 if (ol
->options
== mips_options
)
617 SIM_ASSERT (ol
!= NULL
);
620 STATE_OPTIONS (sd
) = ol
->next
;
622 prev
->next
= ol
->next
;
624 sim_do_commandf (sd
, "memory-info");
627 /* check for/establish the a reference program image */
628 if (sim_analyze_program (sd
,
629 (STATE_PROG_ARGV (sd
) != NULL
630 ? *STATE_PROG_ARGV (sd
)
634 sim_module_uninstall (sd
);
638 /* Configure/verify the target byte order and other runtime
639 configuration options */
640 if (sim_config (sd
) != SIM_RC_OK
)
642 sim_module_uninstall (sd
);
646 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
648 /* Uninstall the modules to avoid memory leaks,
649 file descriptor leaks, etc. */
650 sim_module_uninstall (sd
);
654 /* verify assumptions the simulator made about the host type system.
655 This macro does not return if there is a problem */
656 SIM_ASSERT (sizeof(int) == (4 * sizeof(char)));
657 SIM_ASSERT (sizeof(word64
) == (8 * sizeof(char)));
659 /* This is NASTY, in that we are assuming the size of specific
663 for (rn
= 0; (rn
< (LAST_EMBED_REGNUM
+ 1)); rn
++)
666 cpu
->register_widths
[rn
] = WITH_TARGET_WORD_BITSIZE
;
667 else if ((rn
>= FGR_BASE
) && (rn
< (FGR_BASE
+ NR_FGR
)))
668 cpu
->register_widths
[rn
] = WITH_TARGET_FLOATING_POINT_BITSIZE
;
669 else if ((rn
>= 33) && (rn
<= 37))
670 cpu
->register_widths
[rn
] = WITH_TARGET_WORD_BITSIZE
;
671 else if ((rn
== SRIDX
)
674 || ((rn
>= 72) && (rn
<= 89)))
675 cpu
->register_widths
[rn
] = 32;
677 cpu
->register_widths
[rn
] = 0;
683 if (STATE
& simTRACE
)
687 sim_io_eprintf (sd, "idt@%x pmon@%x lsipmon@%x\n",
690 lsipmon_monitor_base);
693 /* Write the monitor trap address handlers into the monitor (eeprom)
694 address space. This can only be done once the target endianness
695 has been determined. */
696 if (idt_monitor_base
!= 0)
699 unsigned idt_monitor_size
= 1 << 11;
701 /* the default monitor region */
702 sim_do_commandf (sd
, "memory region 0x%x,0x%x",
703 idt_monitor_base
, idt_monitor_size
);
705 /* Entry into the IDT monitor is via fixed address vectors, and
706 not using machine instructions. To avoid clashing with use of
707 the MIPS TRAP system, we place our own (simulator specific)
708 "undefined" instructions into the relevant vector slots. */
709 for (loop
= 0; (loop
< idt_monitor_size
); loop
+= 4)
711 address_word vaddr
= (idt_monitor_base
+ loop
);
712 unsigned32 insn
= (RSVD_INSTRUCTION
|
713 (((loop
>> 2) & RSVD_INSTRUCTION_ARG_MASK
)
714 << RSVD_INSTRUCTION_ARG_SHIFT
));
716 sim_write (sd
, vaddr
, (unsigned char *)&insn
, sizeof (insn
));
720 if ((pmon_monitor_base
!= 0) || (lsipmon_monitor_base
!= 0))
722 /* The PMON monitor uses the same address space, but rather than
723 branching into it the address of a routine is loaded. We can
724 cheat for the moment, and direct the PMON routine to IDT style
725 instructions within the monitor space. This relies on the IDT
726 monitor not using the locations from 0xBFC00500 onwards as its
729 for (loop
= 0; (loop
< 24); loop
++)
731 unsigned32 value
= ((0x500 - 8) / 8); /* default UNDEFINED reason code */
747 value
= ((0x500 - 16) / 8); /* not an IDT reason code */
749 case 8: /* cliexit */
752 case 11: /* flush_cache */
757 SIM_ASSERT (idt_monitor_base
!= 0);
758 value
= ((unsigned int) idt_monitor_base
+ (value
* 8));
761 if (pmon_monitor_base
!= 0)
763 address_word vaddr
= (pmon_monitor_base
+ (loop
* 4));
764 sim_write (sd
, vaddr
, (unsigned char *)&value
, sizeof (value
));
767 if (lsipmon_monitor_base
!= 0)
769 address_word vaddr
= (lsipmon_monitor_base
+ (loop
* 4));
770 sim_write (sd
, vaddr
, (unsigned char *)&value
, sizeof (value
));
774 /* Write an abort sequence into the TRAP (common) exception vector
775 addresses. This is to catch code executing a TRAP (et.al.)
776 instruction without installing a trap handler. */
777 if ((idt_monitor_base
!= 0) ||
778 (pmon_monitor_base
!= 0) ||
779 (lsipmon_monitor_base
!= 0))
781 unsigned32 halt
[2] = { 0x2404002f /* addiu r4, r0, 47 */,
782 HALT_INSTRUCTION
/* BREAK */ };
785 sim_write (sd
, 0x80000000, (unsigned char *) halt
, sizeof (halt
));
786 sim_write (sd
, 0x80000180, (unsigned char *) halt
, sizeof (halt
));
787 sim_write (sd
, 0x80000200, (unsigned char *) halt
, sizeof (halt
));
788 /* XXX: Write here unconditionally? */
789 sim_write (sd
, 0xBFC00200, (unsigned char *) halt
, sizeof (halt
));
790 sim_write (sd
, 0xBFC00380, (unsigned char *) halt
, sizeof (halt
));
791 sim_write (sd
, 0xBFC00400, (unsigned char *) halt
, sizeof (halt
));
795 /* CPU specific initialization. */
796 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
798 SIM_CPU
*cpu
= STATE_CPU (sd
, i
);
800 CPU_REG_FETCH (cpu
) = mips_reg_fetch
;
801 CPU_REG_STORE (cpu
) = mips_reg_store
;
802 CPU_PC_FETCH (cpu
) = mips_pc_get
;
803 CPU_PC_STORE (cpu
) = mips_pc_set
;
811 open_trace (SIM_DESC sd
)
813 tracefh
= fopen(tracefile
,"wb+");
816 sim_io_eprintf(sd
,"Failed to create file \"%s\", writing trace information to stderr.\n",tracefile
);
822 /* Return name of an insn, used by insn profiling. */
824 get_insn_name (sim_cpu
*cpu
, int i
)
826 return itable
[i
].name
;
830 mips_sim_close (SIM_DESC sd
, int quitting
)
833 if (tracefh
!= NULL
&& tracefh
!= stderr
)
840 mips_reg_store (SIM_CPU
*cpu
, int rn
, unsigned char *memory
, int length
)
842 /* NOTE: gdb (the client) stores registers in target byte order
843 while the simulator uses host byte order */
845 /* Unfortunately this suffers from the same problem as the register
846 numbering one. We need to know what the width of each logical
847 register number is for the architecture being simulated. */
849 if (cpu
->register_widths
[rn
] == 0)
851 sim_io_eprintf (CPU_STATE (cpu
), "Invalid register width for %d (register store ignored)\n", rn
);
855 if (rn
>= FGR_BASE
&& rn
< FGR_BASE
+ NR_FGR
)
857 cpu
->fpr_state
[rn
- FGR_BASE
] = fmt_uninterpreted
;
858 if (cpu
->register_widths
[rn
] == 32)
862 cpu
->fgr
[rn
- FGR_BASE
] =
863 (unsigned32
) T2H_8 (*(unsigned64
*)memory
);
868 cpu
->fgr
[rn
- FGR_BASE
] = T2H_4 (*(unsigned32
*)memory
);
876 cpu
->fgr
[rn
- FGR_BASE
] = T2H_8 (*(unsigned64
*)memory
);
881 cpu
->fgr
[rn
- FGR_BASE
] = T2H_4 (*(unsigned32
*)memory
);
887 if (cpu
->register_widths
[rn
] == 32)
892 (unsigned32
) T2H_8 (*(unsigned64
*)memory
);
897 cpu
->registers
[rn
] = T2H_4 (*(unsigned32
*)memory
);
905 cpu
->registers
[rn
] = T2H_8 (*(unsigned64
*)memory
);
910 cpu
->registers
[rn
] = (signed32
) T2H_4(*(unsigned32
*)memory
);
919 mips_reg_fetch (SIM_CPU
*cpu
, int rn
, unsigned char *memory
, int length
)
921 /* NOTE: gdb (the client) stores registers in target byte order
922 while the simulator uses host byte order */
924 if (cpu
->register_widths
[rn
] == 0)
926 sim_io_eprintf (CPU_STATE (cpu
), "Invalid register width for %d (register fetch ignored)\n", rn
);
930 /* Any floating point register */
931 if (rn
>= FGR_BASE
&& rn
< FGR_BASE
+ NR_FGR
)
933 if (cpu
->register_widths
[rn
] == 32)
937 *(unsigned64
*)memory
=
938 H2T_8 ((unsigned32
) (cpu
->fgr
[rn
- FGR_BASE
]));
943 *(unsigned32
*)memory
= H2T_4 (cpu
->fgr
[rn
- FGR_BASE
]);
951 *(unsigned64
*)memory
= H2T_8 (cpu
->fgr
[rn
- FGR_BASE
]);
956 *(unsigned32
*)memory
= H2T_4 ((unsigned32
)(cpu
->fgr
[rn
- FGR_BASE
]));
962 if (cpu
->register_widths
[rn
] == 32)
966 *(unsigned64
*)memory
=
967 H2T_8 ((unsigned32
) (cpu
->registers
[rn
]));
972 *(unsigned32
*)memory
= H2T_4 ((unsigned32
)(cpu
->registers
[rn
]));
980 *(unsigned64
*)memory
=
981 H2T_8 ((unsigned64
) (cpu
->registers
[rn
]));
986 *(unsigned32
*)memory
= H2T_4 ((unsigned32
)(cpu
->registers
[rn
]));
995 sim_create_inferior (SIM_DESC sd
, struct bfd
*abfd
,
996 char * const *argv
, char * const *env
)
1000 #if 0 /* FIXME: doesn't compile */
1001 printf("DBG: sim_create_inferior entered: start_address = 0x%s\n",
1010 /* override PC value set by ColdReset () */
1012 for (cpu_nr
= 0; cpu_nr
< sim_engine_nr_cpus (sd
); cpu_nr
++)
1014 sim_cpu
*cpu
= STATE_CPU (sd
, cpu_nr
);
1015 sim_cia pc
= bfd_get_start_address (abfd
);
1017 /* We need to undo brain-dead bfd behavior where it sign-extends
1018 addresses that are supposed to be unsigned. See the mips bfd
1019 sign_extend_vma setting. We have to check the ELF data itself
1020 in order to handle o32 & n32 ABIs. */
1021 if (abfd
->tdata
.elf_obj_data
->elf_header
->e_ident
[EI_CLASS
] ==
1023 pc
= (unsigned32
) pc
;
1025 CPU_PC_SET (cpu
, pc
);
1029 #if 0 /* def DEBUG */
1032 /* We should really place the argv slot values into the argument
1033 registers, and onto the stack as required. However, this
1034 assumes that we have a stack defined, which is not
1035 necessarily true at the moment. */
1037 sim_io_printf(sd
,"sim_create_inferior() : passed arguments ignored\n");
1038 for (cptr
= argv
; (cptr
&& *cptr
); cptr
++)
1039 printf("DBG: arg \"%s\"\n",*cptr
);
1046 /*---------------------------------------------------------------------------*/
1047 /*-- Private simulator support interface ------------------------------------*/
1048 /*---------------------------------------------------------------------------*/
1050 /* Read a null terminated string from memory, return in a buffer */
1052 fetch_str (SIM_DESC sd
,
1058 while (sim_read (sd
, addr
+ nr
, &null
, 1) == 1 && null
!= 0)
1060 buf
= NZALLOC (char, nr
+ 1);
1061 sim_read (sd
, addr
, (unsigned char *)buf
, nr
);
1066 /* Implements the "sim firmware" command:
1067 sim firmware NAME[@ADDRESS] --- emulate ROM monitor named NAME.
1068 NAME can be idt, pmon, or lsipmon. If omitted, ADDRESS
1069 defaults to the normal address for that monitor.
1070 sim firmware none --- don't emulate any ROM monitor. Useful
1071 if you need a clean address space. */
1073 sim_firmware_command (SIM_DESC sd
, char *arg
)
1075 int address_present
= 0;
1078 /* Signal occurrence of this option. */
1079 firmware_option_p
= 1;
1081 /* Parse out the address, if present. */
1083 char *p
= strchr (arg
, '@');
1087 address_present
= 1;
1088 p
++; /* skip over @ */
1090 address
= strtoul (p
, &q
, 0);
1093 sim_io_printf (sd
, "Invalid address given to the"
1094 "`sim firmware NAME@ADDRESS' command: %s\n",
1101 address_present
= 0;
1102 address
= -1; /* Dummy value. */
1106 if (! strncmp (arg
, "idt", 3))
1108 idt_monitor_base
= address_present
? address
: 0xBFC00000;
1109 pmon_monitor_base
= 0;
1110 lsipmon_monitor_base
= 0;
1112 else if (! strncmp (arg
, "pmon", 4))
1114 /* pmon uses indirect calls. Hook into implied idt. */
1115 pmon_monitor_base
= address_present
? address
: 0xBFC00500;
1116 idt_monitor_base
= pmon_monitor_base
- 0x500;
1117 lsipmon_monitor_base
= 0;
1119 else if (! strncmp (arg
, "lsipmon", 7))
1121 /* lsipmon uses indirect calls. Hook into implied idt. */
1122 pmon_monitor_base
= 0;
1123 lsipmon_monitor_base
= address_present
? address
: 0xBFC00200;
1124 idt_monitor_base
= lsipmon_monitor_base
- 0x200;
1126 else if (! strncmp (arg
, "none", 4))
1128 if (address_present
)
1131 "The `sim firmware none' command does "
1132 "not take an `ADDRESS' argument.\n");
1135 idt_monitor_base
= 0;
1136 pmon_monitor_base
= 0;
1137 lsipmon_monitor_base
= 0;
1141 sim_io_printf (sd
, "\
1142 Unrecognized name given to the `sim firmware NAME' command: %s\n\
1143 Recognized firmware names are: `idt', `pmon', `lsipmon', and `none'.\n",
1151 /* stat structures from MIPS32/64. */
1152 static const char stat32_map
[] =
1153 "st_dev,2:st_ino,2:st_mode,4:st_nlink,2:st_uid,2:st_gid,2"
1154 ":st_rdev,2:st_size,4:st_atime,4:st_spare1,4:st_mtime,4:st_spare2,4"
1155 ":st_ctime,4:st_spare3,4:st_blksize,4:st_blocks,4:st_spare4,8";
1157 static const char stat64_map
[] =
1158 "st_dev,2:st_ino,2:st_mode,4:st_nlink,2:st_uid,2:st_gid,2"
1159 ":st_rdev,2:st_size,8:st_atime,8:st_spare1,8:st_mtime,8:st_spare2,8"
1160 ":st_ctime,8:st_spare3,8:st_blksize,8:st_blocks,8:st_spare4,16";
1162 /* Map for calls using the host struct stat. */
1163 static const CB_TARGET_DEFS_MAP CB_stat_map
[] =
1165 { "stat", CB_SYS_stat
, 15 },
1170 /* Simple monitor interface (currently setup for the IDT and PMON monitors) */
1172 sim_monitor (SIM_DESC sd
,
1175 unsigned int reason
)
1178 printf("DBG: sim_monitor: entered (reason = %d)\n",reason
);
1181 /* The IDT monitor actually allows two instructions per vector
1182 slot. However, the simulator currently causes a trap on each
1183 individual instruction. We cheat, and lose the bottom bit. */
1186 /* The following callback functions are available, however the
1187 monitor we are simulating does not make use of them: get_errno,
1188 isatty, rename, system and time. */
1192 case 6: /* int open(char *path,int flags) */
1194 char *path
= fetch_str (sd
, A0
);
1195 V0
= sim_io_open (sd
, path
, (int)A1
);
1200 case 7: /* int read(int file,char *ptr,int len) */
1204 char *buf
= zalloc (nr
);
1205 V0
= sim_io_read (sd
, fd
, buf
, nr
);
1206 sim_write (sd
, A1
, (unsigned char *)buf
, nr
);
1211 case 8: /* int write(int file,char *ptr,int len) */
1215 char *buf
= zalloc (nr
);
1216 sim_read (sd
, A1
, (unsigned char *)buf
, nr
);
1217 V0
= sim_io_write (sd
, fd
, buf
, nr
);
1219 sim_io_flush_stdout (sd
);
1221 sim_io_flush_stderr (sd
);
1226 case 10: /* int close(int file) */
1228 V0
= sim_io_close (sd
, (int)A0
);
1232 case 2: /* Densan monitor: char inbyte(int waitflag) */
1234 if (A0
== 0) /* waitflag == NOWAIT */
1235 V0
= (unsigned_word
)-1;
1237 /* Drop through to case 11 */
1239 case 11: /* char inbyte(void) */
1242 /* ensure that all output has gone... */
1243 sim_io_flush_stdout (sd
);
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 13: /* int unlink(const char *path) */
1264 char *path
= fetch_str (sd
, A0
);
1265 V0
= sim_io_unlink (sd
, path
);
1270 case 14: /* int lseek(int fd, int offset, int whence) */
1272 V0
= sim_io_lseek (sd
, A0
, A1
, A2
);
1276 case 15: /* int stat(const char *path, struct stat *buf); */
1278 /* As long as the infrastructure doesn't cache anything
1279 related to the stat mapping, this trick gets us a dual
1280 "struct stat"-type mapping in the least error-prone way. */
1281 host_callback
*cb
= STATE_CALLBACK (sd
);
1282 const char *saved_map
= cb
->stat_map
;
1283 CB_TARGET_DEFS_MAP
*saved_syscall_map
= cb
->syscall_map
;
1284 bfd
*prog_bfd
= STATE_PROG_BFD (sd
);
1285 int is_elf32bit
= (elf_elfheader(prog_bfd
)->e_ident
[EI_CLASS
] ==
1287 static CB_SYSCALL s
;
1288 CB_SYSCALL_INIT (&s
);
1290 /* Mask out the sign extension part for 64-bit targets because the
1291 MIPS simulator's memory model is still 32-bit. */
1292 s
.arg1
= A0
& 0xFFFFFFFF;
1293 s
.arg2
= A1
& 0xFFFFFFFF;
1296 s
.read_mem
= sim_syscall_read_mem
;
1297 s
.write_mem
= sim_syscall_write_mem
;
1299 cb
->syscall_map
= (CB_TARGET_DEFS_MAP
*) CB_stat_map
;
1300 cb
->stat_map
= is_elf32bit
? stat32_map
: stat64_map
;
1302 if (cb_syscall (cb
, &s
) != CB_RC_OK
)
1303 sim_engine_halt (sd
, cpu
, NULL
, mips_pc_get (cpu
),
1304 sim_stopped
, SIM_SIGILL
);
1307 cb
->stat_map
= saved_map
;
1308 cb
->syscall_map
= saved_syscall_map
;
1312 case 17: /* void _exit() */
1314 sim_io_eprintf (sd
, "sim_monitor(17): _exit(int reason) to be coded\n");
1315 sim_engine_halt (SD
, CPU
, NULL
, NULL_CIA
, sim_exited
,
1316 (unsigned int)(A0
& 0xFFFFFFFF));
1320 case 28: /* PMON flush_cache */
1323 case 55: /* void get_mem_info(unsigned int *ptr) */
1324 /* in: A0 = pointer to three word memory location */
1325 /* out: [A0 + 0] = size */
1326 /* [A0 + 4] = instruction cache size */
1327 /* [A0 + 8] = data cache size */
1330 unsigned_4 zero
= 0;
1331 address_word mem_size
;
1332 sim_memopt
*entry
, *match
= NULL
;
1334 /* Search for memory region mapped to KSEG0 or KSEG1. */
1335 for (entry
= STATE_MEMOPT (sd
);
1337 entry
= entry
->next
)
1339 if ((entry
->addr
== K0BASE
|| entry
->addr
== K1BASE
)
1340 && (!match
|| entry
->level
< match
->level
))
1345 for (alias
= entry
->alias
;
1347 alias
= alias
->next
)
1348 if ((alias
->addr
== K0BASE
|| alias
->addr
== K1BASE
)
1349 && (!match
|| entry
->level
< match
->level
))
1354 /* Get region size, limit to KSEG1 size (512MB). */
1355 SIM_ASSERT (match
!= NULL
);
1356 mem_size
= (match
->modulo
!= 0
1357 ? match
->modulo
: match
->nr_bytes
);
1358 if (mem_size
> K1SIZE
)
1363 sim_write (sd
, A0
+ 0, (unsigned char *)&value
, 4);
1364 sim_write (sd
, A0
+ 4, (unsigned char *)&zero
, 4);
1365 sim_write (sd
, A0
+ 8, (unsigned char *)&zero
, 4);
1366 /* sim_io_eprintf (sd, "sim: get_mem_info() deprecated\n"); */
1370 case 158: /* PMON printf */
1371 /* in: A0 = pointer to format string */
1372 /* A1 = optional argument 1 */
1373 /* A2 = optional argument 2 */
1374 /* A3 = optional argument 3 */
1376 /* The following is based on the PMON printf source */
1378 address_word s
= A0
;
1380 signed_word
*ap
= &A1
; /* 1st argument */
1381 /* This isn't the quickest way, since we call the host print
1382 routine for every character almost. But it does avoid
1383 having to allocate and manage a temporary string buffer. */
1384 /* TODO: Include check that we only use three arguments (A1,
1386 while (sim_read (sd
, s
++, &c
, 1) && c
!= '\0')
1391 enum {FMT_RJUST
, FMT_LJUST
, FMT_RJUST0
, FMT_CENTER
} fmt
= FMT_RJUST
;
1392 int width
= 0, trunc
= 0, haddot
= 0, longlong
= 0;
1393 while (sim_read (sd
, s
++, &c
, 1) && c
!= '\0')
1395 if (strchr ("dobxXulscefg%", c
))
1410 else if (c
>= '1' && c
<= '9')
1414 while (sim_read (sd
, s
++, &c
, 1) == 1 && isdigit (c
))
1417 n
= (unsigned int)strtol(tmp
,NULL
,10);
1430 sim_io_printf (sd
, "%%");
1435 address_word p
= *ap
++;
1437 while (sim_read (sd
, p
++, &ch
, 1) == 1 && ch
!= '\0')
1438 sim_io_printf(sd
, "%c", ch
);
1441 sim_io_printf(sd
,"(null)");
1444 sim_io_printf (sd
, "%c", (int)*ap
++);
1449 sim_read (sd
, s
++, &c
, 1);
1453 sim_read (sd
, s
++, &c
, 1);
1456 if (strchr ("dobxXu", c
))
1458 word64 lv
= (word64
) *ap
++;
1460 sim_io_printf(sd
,"<binary not supported>");
1463 sprintf (tmp
, "%%%s%c", longlong
? "ll" : "", c
);
1465 sim_io_printf(sd
, tmp
, lv
);
1467 sim_io_printf(sd
, tmp
, (int)lv
);
1470 else if (strchr ("eEfgG", c
))
1472 double dbl
= *(double*)(ap
++);
1473 sprintf (tmp
, "%%%d.%d%c", width
, trunc
, c
);
1474 sim_io_printf (sd
, tmp
, dbl
);
1480 sim_io_printf(sd
, "%c", c
);
1486 /* Unknown reason. */
1492 /* Store a word into memory. */
1495 store_word (SIM_DESC sd
,
1501 address_word paddr
= vaddr
;
1503 if ((vaddr
& 3) != 0)
1504 SignalExceptionAddressStore ();
1507 const uword64 mask
= 7;
1511 paddr
= (paddr
& ~mask
) | ((paddr
& mask
) ^ (ReverseEndian
<< 2));
1512 byte
= (vaddr
& mask
) ^ (BigEndianCPU
<< 2);
1513 memval
= ((uword64
) val
) << (8 * byte
);
1514 StoreMemory (AccessLength_WORD
, memval
, 0, paddr
, vaddr
,
1519 /* Load a word from memory. */
1522 load_word (SIM_DESC sd
,
1527 if ((vaddr
& 3) != 0)
1529 SIM_CORE_SIGNAL (SD
, cpu
, cia
, read_map
, AccessLength_WORD
+1, vaddr
, read_transfer
, sim_core_unaligned_signal
);
1533 address_word paddr
= vaddr
;
1534 const uword64 mask
= 0x7;
1535 const unsigned int reverse
= ReverseEndian
? 1 : 0;
1536 const unsigned int bigend
= BigEndianCPU
? 1 : 0;
1540 paddr
= (paddr
& ~mask
) | ((paddr
& mask
) ^ (reverse
<< 2));
1541 LoadMemory (&memval
, NULL
, AccessLength_WORD
, paddr
, vaddr
, isDATA
,
1543 byte
= (vaddr
& mask
) ^ (bigend
<< 2);
1544 return EXTEND32 (memval
>> (8 * byte
));
1550 /* Simulate the mips16 entry and exit pseudo-instructions. These
1551 would normally be handled by the reserved instruction exception
1552 code, but for ease of simulation we just handle them directly. */
1555 mips16_entry (SIM_DESC sd
,
1560 int aregs
, sregs
, rreg
;
1563 printf("DBG: mips16_entry: entered (insn = 0x%08X)\n",insn
);
1566 aregs
= (insn
& 0x700) >> 8;
1567 sregs
= (insn
& 0x0c0) >> 6;
1568 rreg
= (insn
& 0x020) >> 5;
1570 /* This should be checked by the caller. */
1579 /* This is the entry pseudo-instruction. */
1581 for (i
= 0; i
< aregs
; i
++)
1582 store_word (SD
, CPU
, cia
, (uword64
) (SP
+ 4 * i
), GPR
[i
+ 4]);
1590 store_word (SD
, CPU
, cia
, (uword64
) tsp
, RA
);
1593 for (i
= 0; i
< sregs
; i
++)
1596 store_word (SD
, CPU
, cia
, (uword64
) tsp
, GPR
[16 + i
]);
1604 /* This is the exit pseudo-instruction. */
1611 RA
= load_word (SD
, CPU
, cia
, (uword64
) tsp
);
1614 for (i
= 0; i
< sregs
; i
++)
1617 GPR
[i
+ 16] = load_word (SD
, CPU
, cia
, (uword64
) tsp
);
1622 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
1626 FGR
[0] = WORD64LO (GPR
[4]);
1627 FPR_STATE
[0] = fmt_uninterpreted
;
1629 else if (aregs
== 6)
1631 FGR
[0] = WORD64LO (GPR
[5]);
1632 FGR
[1] = WORD64LO (GPR
[4]);
1633 FPR_STATE
[0] = fmt_uninterpreted
;
1634 FPR_STATE
[1] = fmt_uninterpreted
;
1643 /*-- trace support ----------------------------------------------------------*/
1645 /* The trace support is provided (if required) in the memory accessing
1646 routines. Since we are also providing the architecture specific
1647 features, the architecture simulation code can also deal with
1648 notifying the trace world of cache flushes, etc. Similarly we do
1649 not need to provide profiling support in the simulator engine,
1650 since we can sample in the instruction fetch control loop. By
1651 defining the trace manifest, we add tracing as a run-time
1654 #if WITH_TRACE_ANY_P
1655 /* Tracing by default produces "din" format (as required by
1656 dineroIII). Each line of such a trace file *MUST* have a din label
1657 and address field. The rest of the line is ignored, so comments can
1658 be included if desired. The first field is the label which must be
1659 one of the following values:
1664 3 escape record (treated as unknown access type)
1665 4 escape record (causes cache flush)
1667 The address field is a 32bit (lower-case) hexadecimal address
1668 value. The address should *NOT* be preceded by "0x".
1670 The size of the memory transfer is not important when dealing with
1671 cache lines (as long as no more than a cache line can be
1672 transferred in a single operation :-), however more information
1673 could be given following the dineroIII requirement to allow more
1674 complete memory and cache simulators to provide better
1675 results. i.e. the University of Pisa has a cache simulator that can
1676 also take bus size and speed as (variable) inputs to calculate
1677 complete system performance (a much more useful ability when trying
1678 to construct an end product, rather than a processor). They
1679 currently have an ARM version of their tool called ChARM. */
1683 dotrace (SIM_DESC sd
,
1691 if (STATE
& simTRACE
) {
1693 fprintf(tracefh
,"%d %s ; width %d ; ",
1697 va_start(ap
,comment
);
1698 vfprintf(tracefh
,comment
,ap
);
1700 fprintf(tracefh
,"\n");
1702 /* NOTE: Since the "din" format will only accept 32bit addresses, and
1703 we may be generating 64bit ones, we should put the hi-32bits of the
1704 address into the comment field. */
1706 /* TODO: Provide a buffer for the trace lines. We can then avoid
1707 performing writes until the buffer is filled, or the file is
1710 /* NOTE: We could consider adding a comment field to the "din" file
1711 produced using type 3 markers (unknown access). This would then
1712 allow information about the program that the "din" is for, and
1713 the MIPs world that was being simulated, to be placed into the
1718 #endif /* WITH_TRACE_ANY_P */
1720 /*---------------------------------------------------------------------------*/
1721 /*-- simulator engine -------------------------------------------------------*/
1722 /*---------------------------------------------------------------------------*/
1725 ColdReset (SIM_DESC sd
)
1728 for (cpu_nr
= 0; cpu_nr
< sim_engine_nr_cpus (sd
); cpu_nr
++)
1730 sim_cpu
*cpu
= STATE_CPU (sd
, cpu_nr
);
1731 /* RESET: Fixed PC address: */
1732 PC
= (unsigned_word
) UNSIGNED64 (0xFFFFFFFFBFC00000);
1733 /* The reset vector address is in the unmapped, uncached memory space. */
1735 SR
&= ~(status_SR
| status_TS
| status_RP
);
1736 SR
|= (status_ERL
| status_BEV
);
1738 /* Cheat and allow access to the complete register set immediately */
1739 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
1740 && WITH_TARGET_WORD_BITSIZE
== 64)
1741 SR
|= status_FR
; /* 64bit registers */
1743 /* Ensure that any instructions with pending register updates are
1745 PENDING_INVALIDATE();
1747 /* Initialise the FPU registers to the unknown state */
1748 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
1751 for (rn
= 0; (rn
< 32); rn
++)
1752 FPR_STATE
[rn
] = fmt_uninterpreted
;
1755 /* Initialise the Config0 register. */
1756 C0_CONFIG
= 0x80000000 /* Config1 present */
1757 | 2; /* KSEG0 uncached */
1758 if (WITH_TARGET_WORD_BITSIZE
== 64)
1760 /* FIXME Currently mips/sim-main.c:address_translation()
1761 truncates all addresses to 32-bits. */
1762 if (0 && WITH_TARGET_ADDRESS_BITSIZE
== 64)
1763 C0_CONFIG
|= (2 << 13); /* MIPS64, 64-bit addresses */
1765 C0_CONFIG
|= (1 << 13); /* MIPS64, 32-bit addresses */
1768 C0_CONFIG
|= 0x00008000; /* Big Endian */
1775 /* Description from page A-26 of the "MIPS IV Instruction Set" manual (revision 3.1) */
1776 /* Signal an exception condition. This will result in an exception
1777 that aborts the instruction. The instruction operation pseudocode
1778 will never see a return from this function call. */
1781 signal_exception (SIM_DESC sd
,
1789 sim_io_printf(sd
,"DBG: SignalException(%d) PC = 0x%s\n",exception
,pr_addr(cia
));
1792 /* Ensure that any active atomic read/modify/write operation will fail: */
1795 /* Save registers before interrupt dispatching */
1796 #ifdef SIM_CPU_EXCEPTION_TRIGGER
1797 SIM_CPU_EXCEPTION_TRIGGER(sd
, cpu
, cia
);
1800 switch (exception
) {
1802 case DebugBreakPoint
:
1803 if (! (Debug
& Debug_DM
))
1809 Debug
|= Debug_DBD
; /* signaled from within in delay slot */
1810 DEPC
= cia
- 4; /* reference the branch instruction */
1814 Debug
&= ~Debug_DBD
; /* not signaled from within a delay slot */
1818 Debug
|= Debug_DM
; /* in debugging mode */
1819 Debug
|= Debug_DBp
; /* raising a DBp exception */
1821 sim_engine_restart (SD
, CPU
, NULL
, NULL_CIA
);
1825 case ReservedInstruction
:
1828 unsigned int instruction
;
1829 va_start(ap
,exception
);
1830 instruction
= va_arg(ap
,unsigned int);
1832 /* Provide simple monitor support using ReservedInstruction
1833 exceptions. The following code simulates the fixed vector
1834 entry points into the IDT monitor by causing a simulator
1835 trap, performing the monitor operation, and returning to
1836 the address held in the $ra register (standard PCS return
1837 address). This means we only need to pre-load the vector
1838 space with suitable instruction values. For systems were
1839 actual trap instructions are used, we would not need to
1840 perform this magic. */
1841 if ((instruction
& RSVD_INSTRUCTION_MASK
) == RSVD_INSTRUCTION
)
1843 int reason
= (instruction
>> RSVD_INSTRUCTION_ARG_SHIFT
) & RSVD_INSTRUCTION_ARG_MASK
;
1844 if (!sim_monitor (SD
, CPU
, cia
, reason
))
1845 sim_io_error (sd
, "sim_monitor: unhandled reason = %d, pc = 0x%s\n", reason
, pr_addr (cia
));
1847 /* NOTE: This assumes that a branch-and-link style
1848 instruction was used to enter the vector (which is the
1849 case with the current IDT monitor). */
1850 sim_engine_restart (SD
, CPU
, NULL
, RA
);
1852 /* Look for the mips16 entry and exit instructions, and
1853 simulate a handler for them. */
1854 else if ((cia
& 1) != 0
1855 && (instruction
& 0xf81f) == 0xe809
1856 && (instruction
& 0x0c0) != 0x0c0)
1858 mips16_entry (SD
, CPU
, cia
, instruction
);
1859 sim_engine_restart (sd
, NULL
, NULL
, NULL_CIA
);
1861 /* else fall through to normal exception processing */
1862 sim_io_eprintf(sd
,"ReservedInstruction at PC = 0x%s\n", pr_addr (cia
));
1866 /* Store exception code into current exception id variable (used
1869 /* TODO: If not simulating exceptions then stop the simulator
1870 execution. At the moment we always stop the simulation. */
1872 #ifdef SUBTARGET_R3900
1873 /* update interrupt-related registers */
1875 /* insert exception code in bits 6:2 */
1876 CAUSE
= LSMASKED32(CAUSE
, 31, 7) | LSINSERTED32(exception
, 6, 2);
1877 /* shift IE/KU history bits left */
1878 SR
= LSMASKED32(SR
, 31, 4) | LSINSERTED32(LSEXTRACTED32(SR
, 3, 0), 5, 2);
1880 if (STATE
& simDELAYSLOT
)
1882 STATE
&= ~simDELAYSLOT
;
1884 EPC
= (cia
- 4); /* reference the branch instruction */
1889 if (SR
& status_BEV
)
1890 PC
= (signed)0xBFC00000 + 0x180;
1892 PC
= (signed)0x80000000 + 0x080;
1894 /* See figure 5-17 for an outline of the code below */
1895 if (! (SR
& status_EXL
))
1897 CAUSE
= (exception
<< 2);
1898 if (STATE
& simDELAYSLOT
)
1900 STATE
&= ~simDELAYSLOT
;
1902 EPC
= (cia
- 4); /* reference the branch instruction */
1906 /* FIXME: TLB et.al. */
1907 /* vector = 0x180; */
1911 CAUSE
= (exception
<< 2);
1912 /* vector = 0x180; */
1915 /* Store exception code into current exception id variable (used
1918 if (SR
& status_BEV
)
1919 PC
= (signed)0xBFC00200 + 0x180;
1921 PC
= (signed)0x80000000 + 0x180;
1924 switch ((CAUSE
>> 2) & 0x1F)
1927 /* Interrupts arrive during event processing, no need to
1933 #ifdef SUBTARGET_3900
1934 /* Exception vector: BEV=0 BFC00000 / BEF=1 BFC00000 */
1935 PC
= (signed)0xBFC00000;
1936 #endif /* SUBTARGET_3900 */
1939 case TLBModification
:
1944 case InstructionFetch
:
1946 /* The following is so that the simulator will continue from the
1947 exception handler address. */
1948 sim_engine_halt (SD
, CPU
, NULL
, PC
,
1949 sim_stopped
, SIM_SIGBUS
);
1951 case ReservedInstruction
:
1952 case CoProcessorUnusable
:
1954 sim_engine_halt (SD
, CPU
, NULL
, PC
,
1955 sim_stopped
, SIM_SIGILL
);
1957 case IntegerOverflow
:
1959 sim_engine_halt (SD
, CPU
, NULL
, PC
,
1960 sim_stopped
, SIM_SIGFPE
);
1963 sim_engine_halt (SD
, CPU
, NULL
, PC
, sim_stopped
, SIM_SIGTRAP
);
1968 sim_engine_restart (SD
, CPU
, NULL
, PC
);
1973 sim_engine_halt (SD
, CPU
, NULL
, PC
,
1974 sim_stopped
, SIM_SIGTRAP
);
1976 default: /* Unknown internal exception */
1978 sim_engine_halt (SD
, CPU
, NULL
, PC
,
1979 sim_stopped
, SIM_SIGABRT
);
1983 case SimulatorFault
:
1987 va_start(ap
,exception
);
1988 msg
= va_arg(ap
,char *);
1990 sim_engine_abort (SD
, CPU
, NULL_CIA
,
1991 "FATAL: Simulator error \"%s\"\n",msg
);
2000 /* This function implements what the MIPS32 and MIPS64 ISAs define as
2001 "UNPREDICTABLE" behaviour.
2003 About UNPREDICTABLE behaviour they say: "UNPREDICTABLE results
2004 may vary from processor implementation to processor implementation,
2005 instruction to instruction, or as a function of time on the same
2006 implementation or instruction. Software can never depend on results
2007 that are UNPREDICTABLE. ..." (MIPS64 Architecture for Programmers
2008 Volume II, The MIPS64 Instruction Set. MIPS Document MD00087 revision
2011 For UNPREDICTABLE behaviour, we print a message, if possible print
2012 the offending instructions mips.igen instruction name (provided by
2013 the caller), and stop the simulator.
2015 XXX FIXME: eventually, stopping the simulator should be made conditional
2016 on a command-line option. */
2018 unpredictable_action(sim_cpu
*cpu
, address_word cia
)
2020 SIM_DESC sd
= CPU_STATE(cpu
);
2022 sim_io_eprintf(sd
, "UNPREDICTABLE: PC = 0x%s\n", pr_addr (cia
));
2023 sim_engine_halt (SD
, CPU
, NULL
, cia
, sim_stopped
, SIM_SIGABRT
);
2027 /*-- co-processor support routines ------------------------------------------*/
2030 CoProcPresent(unsigned int coproc_number
)
2032 /* Return TRUE if simulator provides a model for the given co-processor number */
2037 cop_lw (SIM_DESC sd
,
2042 unsigned int memword
)
2047 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
2050 printf("DBG: COP_LW: memword = 0x%08X (uword64)memword = 0x%s\n",memword
,pr_addr(memword
));
2052 StoreFPR(coproc_reg
,fmt_uninterpreted_32
,(uword64
)memword
);
2057 #if 0 /* this should be controlled by a configuration option */
2058 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
));
2067 cop_ld (SIM_DESC sd
,
2076 printf("DBG: COP_LD: coproc_num = %d, coproc_reg = %d, value = 0x%s : PC = 0x%s\n", coproc_num
, coproc_reg
, pr_uword64(memword
), pr_addr(cia
) );
2079 switch (coproc_num
) {
2081 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
2083 StoreFPR(coproc_reg
,fmt_uninterpreted_64
,memword
);
2088 #if 0 /* this message should be controlled by a configuration option */
2089 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
));
2101 cop_sw (SIM_DESC sd
,
2107 unsigned int value
= 0;
2112 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
2114 value
= (unsigned int)ValueFPR(coproc_reg
,fmt_uninterpreted_32
);
2119 #if 0 /* should be controlled by configuration option */
2120 sim_io_printf(sd
,"COP_SW(%d,%d) at PC = 0x%s : TODO (architecture specific)\n",coproc_num
,coproc_reg
,pr_addr(cia
));
2129 cop_sd (SIM_DESC sd
,
2139 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
2141 value
= ValueFPR(coproc_reg
,fmt_uninterpreted_64
);
2146 #if 0 /* should be controlled by configuration option */
2147 sim_io_printf(sd
,"COP_SD(%d,%d) at PC = 0x%s : TODO (architecture specific)\n",coproc_num
,coproc_reg
,pr_addr(cia
));
2159 decode_coproc (SIM_DESC sd
,
2162 unsigned int instruction
,
2171 case 0: /* standard CPU control and cache registers */
2173 /* R4000 Users Manual (second edition) lists the following CP0
2175 CODE><-RT><RD-><--TAIL--->
2176 DMFC0 Doubleword Move From CP0 (VR4100 = 01000000001tttttddddd00000000000)
2177 DMTC0 Doubleword Move To CP0 (VR4100 = 01000000101tttttddddd00000000000)
2178 MFC0 word Move From CP0 (VR4100 = 01000000000tttttddddd00000000000)
2179 MTC0 word Move To CP0 (VR4100 = 01000000100tttttddddd00000000000)
2180 TLBR Read Indexed TLB Entry (VR4100 = 01000010000000000000000000000001)
2181 TLBWI Write Indexed TLB Entry (VR4100 = 01000010000000000000000000000010)
2182 TLBWR Write Random TLB Entry (VR4100 = 01000010000000000000000000000110)
2183 TLBP Probe TLB for Matching Entry (VR4100 = 01000010000000000000000000001000)
2184 CACHE Cache operation (VR4100 = 101111bbbbbpppppiiiiiiiiiiiiiiii)
2185 ERET Exception return (VR4100 = 01000010000000000000000000011000)
2187 if (((op
== cp0_mfc0
) || (op
== cp0_mtc0
) /* MFC0 / MTC0 */
2188 || (op
== cp0_dmfc0
) || (op
== cp0_dmtc0
)) /* DMFC0 / DMTC0 */
2191 switch (rd
) /* NOTEs: Standard CP0 registers */
2193 /* 0 = Index R4000 VR4100 VR4300 */
2194 /* 1 = Random R4000 VR4100 VR4300 */
2195 /* 2 = EntryLo0 R4000 VR4100 VR4300 */
2196 /* 3 = EntryLo1 R4000 VR4100 VR4300 */
2197 /* 4 = Context R4000 VR4100 VR4300 */
2198 /* 5 = PageMask R4000 VR4100 VR4300 */
2199 /* 6 = Wired R4000 VR4100 VR4300 */
2200 /* 8 = BadVAddr R4000 VR4100 VR4300 */
2201 /* 9 = Count R4000 VR4100 VR4300 */
2202 /* 10 = EntryHi R4000 VR4100 VR4300 */
2203 /* 11 = Compare R4000 VR4100 VR4300 */
2204 /* 12 = SR R4000 VR4100 VR4300 */
2205 #ifdef SUBTARGET_R3900
2207 /* 3 = Config R3900 */
2209 /* 7 = Cache R3900 */
2211 /* 15 = PRID R3900 */
2217 /* 8 = BadVAddr R4000 VR4100 VR4300 */
2218 if (op
== cp0_mfc0
|| op
== cp0_dmfc0
)
2219 GPR
[rt
] = (signed_word
) (signed_address
) COP0_BADVADDR
;
2221 COP0_BADVADDR
= GPR
[rt
];
2224 #endif /* SUBTARGET_R3900 */
2226 if (op
== cp0_mfc0
|| op
== cp0_dmfc0
)
2231 /* 13 = Cause R4000 VR4100 VR4300 */
2233 if (op
== cp0_mfc0
|| op
== cp0_dmfc0
)
2238 /* 14 = EPC R4000 VR4100 VR4300 */
2240 if (op
== cp0_mfc0
|| op
== cp0_dmfc0
)
2241 GPR
[rt
] = (signed_word
) (signed_address
) EPC
;
2245 /* 15 = PRId R4000 VR4100 VR4300 */
2246 #ifdef SUBTARGET_R3900
2249 if (op
== cp0_mfc0
|| op
== cp0_dmfc0
)
2255 /* 16 = Config R4000 VR4100 VR4300 */
2257 if (op
== cp0_mfc0
|| op
== cp0_dmfc0
)
2258 GPR
[rt
] = C0_CONFIG
;
2260 /* only bottom three bits are writable */
2261 C0_CONFIG
= (C0_CONFIG
& ~0x7) | (GPR
[rt
] & 0x7);
2264 #ifdef SUBTARGET_R3900
2267 if (op
== cp0_mfc0
|| op
== cp0_dmfc0
)
2273 /* 17 = LLAddr R4000 VR4100 VR4300 */
2275 /* 18 = WatchLo R4000 VR4100 VR4300 */
2276 /* 19 = WatchHi R4000 VR4100 VR4300 */
2277 /* 20 = XContext R4000 VR4100 VR4300 */
2278 /* 26 = PErr or ECC R4000 VR4100 VR4300 */
2279 /* 27 = CacheErr R4000 VR4100 */
2280 /* 28 = TagLo R4000 VR4100 VR4300 */
2281 /* 29 = TagHi R4000 VR4100 VR4300 */
2282 /* 30 = ErrorEPC R4000 VR4100 VR4300 */
2283 if (STATE_VERBOSE_P(SD
))
2285 "Warning: PC 0x%lx:interp.c decode_coproc DEADC0DE\n",
2286 (unsigned long)cia
);
2287 GPR
[rt
] = 0xDEADC0DE; /* CPR[0,rd] */
2288 /* CPR[0,rd] = GPR[rt]; */
2290 if (op
== cp0_mfc0
|| op
== cp0_dmfc0
)
2291 GPR
[rt
] = (signed_word
) (signed32
) COP0_GPR
[rd
];
2293 COP0_GPR
[rd
] = GPR
[rt
];
2296 sim_io_printf(sd
,"Warning: MFC0 %d,%d ignored, PC=%08x (architecture specific)\n",rt
,rd
, (unsigned)cia
);
2298 sim_io_printf(sd
,"Warning: MTC0 %d,%d ignored, PC=%08x (architecture specific)\n",rt
,rd
, (unsigned)cia
);
2302 else if ((op
== cp0_mfc0
|| op
== cp0_dmfc0
)
2305 /* [D]MFC0 RT,C0_CONFIG,SEL */
2313 /* MIPS32 r/o Config1:
2316 /* MIPS16 implemented.
2317 XXX How to check configuration? */
2319 if (CURRENT_FLOATING_POINT
== HARD_FLOATING_POINT
)
2320 /* MDMX & FPU implemented */
2324 /* MIPS32 r/o Config2:
2329 /* MIPS32 r/o Config3:
2330 SmartMIPS implemented. */
2336 else if (op
== cp0_eret
&& sel
== 0x18)
2339 if (SR
& status_ERL
)
2341 /* Oops, not yet available */
2342 sim_io_printf(sd
,"Warning: ERET when SR[ERL] set not handled yet");
2352 else if (op
== cp0_rfe
&& sel
== 0x10)
2355 #ifdef SUBTARGET_R3900
2356 /* TX39: Copy IEp/KUp -> IEc/KUc, and IEo/KUo -> IEp/KUp */
2358 /* shift IE/KU history bits right */
2359 SR
= LSMASKED32(SR
, 31, 4) | LSINSERTED32(LSEXTRACTED32(SR
, 5, 2), 3, 0);
2361 /* TODO: CACHE register */
2362 #endif /* SUBTARGET_R3900 */
2364 else if (op
== cp0_deret
&& sel
== 0x1F)
2372 sim_io_eprintf(sd
,"Unrecognised COP0 instruction 0x%08X at PC = 0x%s : No handler present\n",instruction
,pr_addr(cia
));
2373 /* TODO: When executing an ERET or RFE instruction we should
2374 clear LLBIT, to ensure that any out-standing atomic
2375 read/modify/write sequence fails. */
2379 case 2: /* co-processor 2 */
2386 sim_io_eprintf(sd
, "COP2 instruction 0x%08X at PC = 0x%s : No handler present\n",
2387 instruction
,pr_addr(cia
));
2392 case 1: /* should not occur (FPU co-processor) */
2393 case 3: /* should not occur (FPU co-processor) */
2394 SignalException(ReservedInstruction
,instruction
);
2402 /* This code copied from gdb's utils.c. Would like to share this code,
2403 but don't know of a common place where both could get to it. */
2405 /* Temporary storage using circular buffer */
2411 static char buf
[NUMCELLS
][CELLSIZE
];
2413 if (++cell
>=NUMCELLS
) cell
=0;
2417 /* Print routines to handle variable size regs, etc */
2419 /* Eliminate warning from compiler on 32-bit systems */
2420 static int thirty_two
= 32;
2423 pr_addr (SIM_ADDR addr
)
2425 char *paddr_str
=get_cell();
2426 switch (sizeof(addr
))
2429 sprintf(paddr_str
,"%08lx%08lx",
2430 (unsigned long)(addr
>>thirty_two
),(unsigned long)(addr
&0xffffffff));
2433 sprintf(paddr_str
,"%08lx",(unsigned long)addr
);
2436 sprintf(paddr_str
,"%04x",(unsigned short)(addr
&0xffff));
2439 sprintf(paddr_str
,"%x",addr
);
2445 pr_uword64 (uword64 addr
)
2447 char *paddr_str
=get_cell();
2448 sprintf(paddr_str
,"%08lx%08lx",
2449 (unsigned long)(addr
>>thirty_two
),(unsigned long)(addr
&0xffffffff));
2455 mips_core_signal (SIM_DESC sd
,
2461 transfer_type transfer
,
2462 sim_core_signals sig
)
2464 const char *copy
= (transfer
== read_transfer
? "read" : "write");
2465 address_word ip
= CIA_ADDR (cia
);
2469 case sim_core_unmapped_signal
:
2470 sim_io_eprintf (sd
, "mips-core: %d byte %s to unmapped address 0x%lx at 0x%lx\n",
2472 (unsigned long) addr
, (unsigned long) ip
);
2473 COP0_BADVADDR
= addr
;
2474 SignalExceptionDataReference();
2477 case sim_core_unaligned_signal
:
2478 sim_io_eprintf (sd
, "mips-core: %d byte %s to unaligned address 0x%lx at 0x%lx\n",
2480 (unsigned long) addr
, (unsigned long) ip
);
2481 COP0_BADVADDR
= addr
;
2482 if(transfer
== read_transfer
)
2483 SignalExceptionAddressLoad();
2485 SignalExceptionAddressStore();
2489 sim_engine_abort (sd
, cpu
, cia
,
2490 "mips_core_signal - internal error - bad switch");
2496 mips_cpu_exception_trigger(SIM_DESC sd
, sim_cpu
* cpu
, address_word cia
)
2498 ASSERT(cpu
!= NULL
);
2500 if(cpu
->exc_suspended
> 0)
2501 sim_io_eprintf(sd
, "Warning, nested exception triggered (%d)\n", cpu
->exc_suspended
);
2504 memcpy(cpu
->exc_trigger_registers
, cpu
->registers
, sizeof(cpu
->exc_trigger_registers
));
2505 cpu
->exc_suspended
= 0;
2509 mips_cpu_exception_suspend(SIM_DESC sd
, sim_cpu
* cpu
, int exception
)
2511 ASSERT(cpu
!= NULL
);
2513 if(cpu
->exc_suspended
> 0)
2514 sim_io_eprintf(sd
, "Warning, nested exception signal (%d then %d)\n",
2515 cpu
->exc_suspended
, exception
);
2517 memcpy(cpu
->exc_suspend_registers
, cpu
->registers
, sizeof(cpu
->exc_suspend_registers
));
2518 memcpy(cpu
->registers
, cpu
->exc_trigger_registers
, sizeof(cpu
->registers
));
2519 cpu
->exc_suspended
= exception
;
2523 mips_cpu_exception_resume(SIM_DESC sd
, sim_cpu
* cpu
, int exception
)
2525 ASSERT(cpu
!= NULL
);
2527 if(exception
== 0 && cpu
->exc_suspended
> 0)
2529 /* warn not for breakpoints */
2530 if(cpu
->exc_suspended
!= sim_signal_to_host(sd
, SIM_SIGTRAP
))
2531 sim_io_eprintf(sd
, "Warning, resuming but ignoring pending exception signal (%d)\n",
2532 cpu
->exc_suspended
);
2534 else if(exception
!= 0 && cpu
->exc_suspended
> 0)
2536 if(exception
!= cpu
->exc_suspended
)
2537 sim_io_eprintf(sd
, "Warning, resuming with mismatched exception signal (%d vs %d)\n",
2538 cpu
->exc_suspended
, exception
);
2540 memcpy(cpu
->registers
, cpu
->exc_suspend_registers
, sizeof(cpu
->registers
));
2542 else if(exception
!= 0 && cpu
->exc_suspended
== 0)
2544 sim_io_eprintf(sd
, "Warning, ignoring spontanous exception signal (%d)\n", exception
);
2546 cpu
->exc_suspended
= 0;
2550 /*---------------------------------------------------------------------------*/
2551 /*> EOF interp.c <*/