+/* This must come before any other includes. */
+#include "defs.h"
+
#include <signal.h>
#include "sim-main.h"
#include "sim-options.h"
#include "sim-hw.h"
-#include "sysdep.h"
#include "bfd.h"
#include "sim-assert.h"
-
-#ifdef HAVE_STDLIB_H
#include <stdlib.h>
-#endif
-
-#ifdef HAVE_STRING_H
#include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
#include "bfd.h"
-#ifndef INLINE
-#ifdef __GNUC__
-#define INLINE inline
-#else
-#define INLINE
-#endif
-#endif
-
-host_callback *mn10300_callback;
-int mn10300_debug;
struct _state State;
/* For compatibility */
SIM_DESC simulator;
+static sim_cia
+mn10300_pc_get (sim_cpu *cpu)
+{
+ return PC;
+}
+
+static void
+mn10300_pc_set (sim_cpu *cpu, sim_cia pc)
+{
+ PC = pc;
+}
+
+static int mn10300_reg_fetch (SIM_CPU *, int, unsigned char *, int);
+static int mn10300_reg_store (SIM_CPU *, int, unsigned char *, int);
+
/* These default values correspond to expected usage for the chip. */
SIM_DESC
sim_open (SIM_OPEN_KIND kind,
host_callback *cb,
struct bfd *abfd,
- char **argv)
+ char * const *argv)
{
+ int i;
SIM_DESC sd = sim_state_alloc (kind, cb);
- mn10300_callback = cb;
SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
+ /* Set default options before parsing user options. */
+ current_target_byte_order = BFD_ENDIAN_LITTLE;
+
+ /* The cpu data is kept in a separately allocated chunk of memory. */
+ if (sim_cpu_alloc_all (sd, 1) != SIM_RC_OK)
+ return 0;
+
/* for compatibility */
simulator = sd;
/* FIXME: should be better way of setting up interrupts. For
moment, only support watchpoints causing a breakpoint (gdb
halt). */
- STATE_WATCHPOINTS (sd)->pc = &(PC);
- STATE_WATCHPOINTS (sd)->sizeof_pc = sizeof (PC);
STATE_WATCHPOINTS (sd)->interrupt_handler = NULL;
STATE_WATCHPOINTS (sd)->interrupt_names = NULL;
sim_do_command (sd, "memory region 0,0x100000");
sim_do_command (sd, "memory region 0x40000000,0x200000");
- /* getopt will print the error message so we just have to exit if this fails.
- FIXME: Hmmm... in the case of gdb we need getopt to call
- print_filtered. */
+ /* The parser will print an error message for us, so we silently return. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
/* Uninstall the modules to avoid memory leaks,
/* STATE_CPU (sd, 0)->psw_mask = (PSW_NP | PSW_EP | PSW_ID | PSW_SAT */
/* | PSW_CY | PSW_OV | PSW_S | PSW_Z); */
- return sd;
-}
+ /* CPU specific initialization. */
+ for (i = 0; i < MAX_NR_PROCESSORS; ++i)
+ {
+ SIM_CPU *cpu = STATE_CPU (sd, i);
+ CPU_REG_FETCH (cpu) = mn10300_reg_fetch;
+ CPU_REG_STORE (cpu) = mn10300_reg_store;
+ CPU_PC_FETCH (cpu) = mn10300_pc_get;
+ CPU_PC_STORE (cpu) = mn10300_pc_set;
+ }
-void
-sim_close (SIM_DESC sd, int quitting)
-{
- sim_module_uninstall (sd);
+ return sd;
}
-
SIM_RC
sim_create_inferior (SIM_DESC sd,
struct bfd *prog_bfd,
- char **argv,
- char **env)
+ char * const *argv,
+ char * const *env)
{
memset (&State, 0, sizeof (State));
if (prog_bfd != NULL) {
} else {
PC = 0;
}
- CIA_SET (STATE_CPU (sd, 0), (unsigned64) PC);
+ CPU_PC_SET (STATE_CPU (sd, 0), (unsigned64) PC);
if (STATE_ARCHITECTURE (sd)->mach == bfd_mach_am33_2)
PSW |= PSW_FE;
return SIM_RC_OK;
}
-void
-sim_do_command (SIM_DESC sd, char *cmd)
-{
- char *mm_cmd = "memory-map";
- char *int_cmd = "interrupt";
-
- if (sim_args_command (sd, cmd) != SIM_RC_OK)
- {
- if (strncmp (cmd, mm_cmd, strlen (mm_cmd) == 0))
- sim_io_eprintf (sd, "`memory-map' command replaced by `sim memory'\n");
- else if (strncmp (cmd, int_cmd, strlen (int_cmd)) == 0)
- sim_io_eprintf (sd, "`interrupt' command replaced by `sim watch'\n");
- else
- sim_io_eprintf (sd, "Unknown command `%s'\n", cmd);
- }
-}
-
/* FIXME These would more efficient to use than load_mem/store_mem,
but need to be changed to use the memory map. */
-uint8
-get_byte (uint8 *x)
-{
- return *x;
-}
-
-uint16
-get_half (uint8 *x)
-{
- uint8 *a = x;
- return (a[1] << 8) + (a[0]);
-}
-
-uint32
-get_word (uint8 *x)
-{
- uint8 *a = x;
- return (a[3]<<24) + (a[2]<<16) + (a[1]<<8) + (a[0]);
-}
-
-void
-put_byte (uint8 *addr, uint8 data)
-{
- uint8 *a = addr;
- a[0] = data;
-}
-
-void
-put_half (uint8 *addr, uint16 data)
-{
- uint8 *a = addr;
- a[0] = data & 0xff;
- a[1] = (data >> 8) & 0xff;
-}
-
-void
-put_word (uint8 *addr, uint32 data)
-{
- uint8 *a = addr;
- a[0] = data & 0xff;
- a[1] = (data >> 8) & 0xff;
- a[2] = (data >> 16) & 0xff;
- a[3] = (data >> 24) & 0xff;
-}
-
-int
-sim_fetch_register (SIM_DESC sd,
- int rn,
- unsigned char *memory,
- int length)
+static int
+mn10300_reg_fetch (SIM_CPU *cpu, int rn, unsigned char *memory, int length)
{
- put_word (memory, State.regs[rn]);
- return -1;
+ reg_t reg = State.regs[rn];
+ uint8 *a = memory;
+ a[0] = reg;
+ a[1] = reg >> 8;
+ a[2] = reg >> 16;
+ a[3] = reg >> 24;
+ return length;
}
-int
-sim_store_register (SIM_DESC sd,
- int rn,
- unsigned char *memory,
- int length)
+static int
+mn10300_reg_store (SIM_CPU *cpu, int rn, unsigned char *memory, int length)
{
- State.regs[rn] = get_word (memory);
- return -1;
+ uint8 *a = memory;
+ State.regs[rn] = (a[3] << 24) + (a[2] << 16) + (a[1] << 8) + a[0];
+ return length;
}
-
void
mn10300_core_signal (SIM_DESC sd,
sim_cpu *cpu,
/* avoid infinite recursion */
if (in_interrupt)
- {
- (*mn10300_callback->printf_filtered) (mn10300_callback,
- "ERROR: recursion in program_interrupt during software exception dispatch.");
- }
+ sim_io_printf (sd, "ERROR: recursion in program_interrupt during software exception dispatch.");
else
{
in_interrupt = 1;
/* copy NMI handler code from dv-mn103cpu.c */
- store_word (SP - 4, CIA_GET (cpu));
+ store_word (SP - 4, CPU_PC_GET (cpu));
store_half (SP - 8, PSW);
/* Set the SYSEF flag in NMICR by backdoor method. See
PSW &= ~PSW_IE;
SP = SP - 8;
- CIA_SET (cpu, 0x40000008);
+ CPU_PC_SET (cpu, 0x40000008);
in_interrupt = 0;
sim_engine_halt(sd, cpu, NULL, cia, sim_stopped, sig);
if(State.exc_suspended > 0)
sim_io_eprintf(sd, "Warning, nested exception triggered (%d)\n", State.exc_suspended);
- CIA_SET (cpu, cia);
+ CPU_PC_SET (cpu, cia);
memcpy(State.exc_trigger_regs, State.regs, sizeof(State.exc_trigger_regs));
State.exc_suspended = 0;
}
memcpy(State.exc_suspend_regs, State.regs, sizeof(State.exc_suspend_regs));
memcpy(State.regs, State.exc_trigger_regs, sizeof(State.regs));
- CIA_SET (cpu, PC); /* copy PC back from new State.regs */
+ CPU_PC_SET (cpu, PC); /* copy PC back from new State.regs */
State.exc_suspended = exception;
}
if(exception == 0 && State.exc_suspended > 0)
{
+#ifndef SIGTRAP
+# define SIGTRAP 5
+#endif
if(State.exc_suspended != SIGTRAP) /* warn not for breakpoints */
sim_io_eprintf(sd, "Warning, resuming but ignoring pending exception signal (%d)\n",
State.exc_suspended);
State.exc_suspended, exception);
memcpy(State.regs, State.exc_suspend_regs, sizeof(State.regs));
- CIA_SET (cpu, PC); /* copy PC back from new State.regs */
+ CPU_PC_SET (cpu, PC); /* copy PC back from new State.regs */
}
else if(exception != 0 && State.exc_suspended == 0)
{
/* Round the given sim_fpu value to double precision, following the
target platform rounding and denormalization conventions. On
AM33/2.0, round_near is the only rounding mode. */
-int
+static int
round_64 (sim_fpu *val)
{
return sim_fpu_round_64 (val, sim_fpu_round_near, sim_fpu_denorm_zero);
/* Check whether overflow, underflow or inexact exceptions should be
raised. */
-int
+static int
fpu_status_ok (sim_fpu_status stat)
{
if ((stat & sim_fpu_status_overflow)