1 /* This file is part of the program psim.
3 Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
4 Copyright (C) 1997, Free Software Foundation
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include "sim-options.h"
30 #include "sim-utils.h"
36 static unsigned long extmem_size = 1024*1024*8; /* 8 meg is the maximum listed in the arch. manual */
38 static const char * get_insn_name (sim_cpu *, int);
40 #define SIM_ADDR unsigned
43 #define OPTION_TRACE_CALL 200
44 #define OPTION_TRACE_TRAPDUMP 201
45 #define OPTION_EXTMEM_SIZE 202
48 d30v_option_handler (SIM_DESC sd,
61 case OPTION_TRACE_CALL:
62 if (arg == NULL || strcmp (arg, "yes") == 0 || strcmp (arg, "on") == 0)
64 else if (strcmp (arg, "no") == 0 || strcmp (arg, "off") == 0)
68 sim_io_eprintf (sd, "Unreconized --trace-call option `%s'\n", arg);
73 case OPTION_TRACE_TRAPDUMP:
74 if (arg == NULL || strcmp (arg, "yes") == 0 || strcmp (arg, "on") == 0)
76 else if (strcmp (arg, "no") == 0 || strcmp (arg, "off") == 0)
80 sim_io_eprintf (sd, "Unreconized --trace-call option `%s'\n", arg);
85 case OPTION_EXTMEM_SIZE:
86 if (arg == NULL || !isdigit (*arg))
88 sim_io_eprintf (sd, "Invalid memory size `%s'", arg);
93 extmem_size = strtol (arg, &suffix, 0);
94 if (*suffix == 'm' || *suffix == 'M')
96 else if (*suffix == 'k' || *suffix == 'K')
98 sim_do_commandf (sd, "memory delete 0x80000000");
99 sim_do_commandf (sd, "memory region 0x80000000,0x%lx", extmem_size);
104 sim_io_eprintf (sd, "Unknown option (%d)\n", opt);
108 static const OPTION d30v_options[] =
110 { {"trace-call", optional_argument, NULL, OPTION_TRACE_CALL},
111 '\0', "on|off", "Enable tracing of calls and returns, checking saved registers",
112 d30v_option_handler },
113 { {"trace-trapdump", optional_argument, NULL, OPTION_TRACE_TRAPDUMP},
116 "Traps 0..30 dump out all of the registers (defaults on)",
118 "Traps 0..30 dump out all of the registers",
120 d30v_option_handler },
121 { {"extmem-size", required_argument, NULL, OPTION_EXTMEM_SIZE},
122 '\0', "size", "Change size of external memory, default 8 meg",
123 d30v_option_handler },
124 { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL }
127 /* Return name of an insn, used by insn profiling. */
130 get_insn_name (sim_cpu *cpu, int i)
132 return itable[i].name;
135 /* Structures used by the simulator, for gdb just have static structures */
138 sim_open (SIM_OPEN_KIND kind,
139 host_callback *callback,
143 SIM_DESC sd = sim_state_alloc (kind, callback);
145 /* FIXME: watchpoints code shouldn't need this */
146 STATE_WATCHPOINTS (sd)->pc = &(PC);
147 STATE_WATCHPOINTS (sd)->sizeof_pc = sizeof (PC);
148 STATE_WATCHPOINTS (sd)->interrupt_handler = d30v_interrupt_event;
150 /* Initialize the mechanism for doing insn profiling. */
151 CPU_INSN_NAME (STATE_CPU (sd, 0)) = get_insn_name;
152 CPU_MAX_INSNS (STATE_CPU (sd, 0)) = nr_itable_entries;
155 TRACE_TRAP_P = TRAPDUMP;
158 if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK)
160 sim_add_option_table (sd, NULL, d30v_options);
162 /* Memory and EEPROM */
163 /* internal instruction RAM - fixed */
164 sim_do_commandf (sd, "memory region 0,0x10000");
165 /* internal data RAM - fixed */
166 sim_do_commandf (sd, "memory region 0x20000000,0x8000");
167 /* control register dummy area */
168 sim_do_commandf (sd, "memory region 0x40000000,0x10000");
170 sim_do_commandf (sd, "memory region 0x80000000,0x%lx", extmem_size);
172 sim_do_commandf (sd, "memory region 0xfffff000,0x1000");
174 /* getopt will print the error message so we just have to exit if this fails.
175 FIXME: Hmmm... in the case of gdb we need getopt to call
177 if (sim_parse_args (sd, argv) != SIM_RC_OK)
179 /* Uninstall the modules to avoid memory leaks,
180 file descriptor leaks, etc. */
181 sim_module_uninstall (sd);
185 /* check for/establish the a reference program image */
186 if (sim_analyze_program (sd,
187 (STATE_PROG_ARGV (sd) != NULL
188 ? *STATE_PROG_ARGV (sd)
192 sim_module_uninstall (sd);
196 /* establish any remaining configuration options */
197 if (sim_config (sd) != SIM_RC_OK)
199 sim_module_uninstall (sd);
203 if (sim_post_argv_init (sd) != SIM_RC_OK)
205 /* Uninstall the modules to avoid memory leaks,
206 file descriptor leaks, etc. */
207 sim_module_uninstall (sd);
216 sim_close (SIM_DESC sd, int quitting)
218 /* Uninstall the modules to avoid memory leaks,
219 file descriptor leaks, etc. */
220 sim_module_uninstall (sd);
225 sim_create_inferior (SIM_DESC sd,
230 /* clear all registers */
231 memset (&STATE_CPU (sd, 0)->regs, 0, sizeof (STATE_CPU (sd, 0)->regs));
232 EIT_VB = EIT_VB_DEFAULT;
233 STATE_CPU (sd, 0)->unit = any_unit;
234 sim_module_init (sd);
236 PC = bfd_get_start_address (abfd);
238 PC = 0xfffff000; /* reset value */
243 sim_do_command (SIM_DESC sd, char *cmd)
245 if (sim_args_command (sd, cmd) != SIM_RC_OK)
246 sim_io_printf (sd, "Unknown command `%s'\n", cmd);
249 /* The following register definitions were ripped off from
250 gdb/config/tm-d30v.h. If any of those defs changes, this table needs to
259 #define SPI_REGNUM 64 /* Interrupt stack pointer */
260 #define SPU_REGNUM 65 /* User stack pointer */
261 #define CREGS_START 66
263 #define PSW_REGNUM (CREGS_START + 0) /* psw, bpsw, or dpsw??? */
264 #define PSW_SM 0x80000000 /* Stack mode: 0 == interrupt (SPI),
266 #define BPSW_REGNUM (CREGS_START + 1) /* Backup PSW (on interrupt) */
267 #define PC_REGNUM (CREGS_START + 2) /* pc, bpc, or dpc??? */
268 #define BPC_REGNUM (CREGS_START + 3) /* Backup PC (on interrupt) */
269 #define DPSW_REGNUM (CREGS_START + 4) /* Backup PSW (on debug trap) */
270 #define DPC_REGNUM (CREGS_START + 5) /* Backup PC (on debug trap) */
271 #define RPT_C_REGNUM (CREGS_START + 7) /* Loop count */
272 #define RPT_S_REGNUM (CREGS_START + 8) /* Loop start address*/
273 #define RPT_E_REGNUM (CREGS_START + 9) /* Loop end address */
274 #define MOD_S_REGNUM (CREGS_START + 10)
275 #define MOD_E_REGNUM (CREGS_START + 11)
276 #define IBA_REGNUM (CREGS_START + 14) /* Instruction break address */
277 #define EIT_VB_REGNUM (CREGS_START + 15) /* Vector base address */
278 #define INT_S_REGNUM (CREGS_START + 16) /* Interrupt status */
279 #define INT_M_REGNUM (CREGS_START + 17) /* Interrupt mask */
284 sim_fetch_register (sd, regno, buf, length)
290 if (regno < A0_REGNUM)
294 if (regno <= R0_REGNUM + 63)
295 reg = sd->cpu[0].regs.general_purpose[regno];
296 else if (regno <= SPU_REGNUM)
297 reg = sd->cpu[0].regs.sp[regno - SPI_REGNUM];
299 reg = sd->cpu[0].regs.control[regno - CREGS_START];
306 else if (regno < NUM_REGS)
310 reg = sd->cpu[0].regs.accumulator[regno - A0_REGNUM] >> 32;
317 reg = sd->cpu[0].regs.accumulator[regno - A0_REGNUM];
330 sim_store_register (sd, regno, buf, length)
336 if (regno < A0_REGNUM)
340 reg = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
342 if (regno <= R0_REGNUM + 63)
343 sd->cpu[0].regs.general_purpose[regno] = reg;
344 else if (regno <= SPU_REGNUM)
345 sd->cpu[0].regs.sp[regno - SPI_REGNUM] = reg;
347 sd->cpu[0].regs.control[regno - CREGS_START] = reg;
349 else if (regno < NUM_REGS)
353 reg = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
355 sd->cpu[0].regs.accumulator[regno - A0_REGNUM] = (unsigned64)reg << 32;
357 reg = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7];
359 sd->cpu[0].regs.accumulator[regno - A0_REGNUM] |= reg;