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