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