Add function sim_args_command() which takes a `(gdb) sim <command>' and
[deliverable/binutils-gdb.git] / sim / tic80 / sim-calls.c
CommitLineData
15c16493
AC
1/* This file is part of the program psim.
2
3 Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
4 Copyright (C) 1997, Free Software Foundation
5
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.
10
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.
15
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.
19
20 */
21
22
23#include <signal.h> /* FIXME - should be machine dependant version */
24#include <stdarg.h>
25#include <ctype.h>
26
27#include "bfd.h"
28#include "sim-main.h"
d9b75947
AC
29#include "sim-utils.h"
30#include "sim-options.h"
15c16493
AC
31
32#ifdef HAVE_STDLIB_H
33#include <stdlib.h>
34#endif
35
36#ifdef HAVE_STRING_H
37#include <string.h>
38#else
39#ifdef HAVE_STRINGS_H
40#include <strings.h>
41#endif
42#endif
43
44
45#define SIM_ADDR unsigned
46
47/* Structures used by the simulator, for gdb just have static structures */
48
49struct sim_state simulation = { 0 };
50
51
52SIM_DESC
53sim_open (SIM_OPEN_KIND kind, char **argv)
54{
15c16493
AC
55 STATE_OPEN_KIND (&simulation) = kind;
56
57 /* establish the simulator configuration */
58 sim_config (&simulation,
59 LITTLE_ENDIAN/*d30v always big endian*/);
60
61 if (sim_pre_argv_init (&simulation, argv[0]) != SIM_RC_OK)
62 return 0;
63
64 /* getopt will print the error message so we just have to exit if this fails.
65 FIXME: Hmmm... in the case of gdb we need getopt to call
66 print_filtered. */
67 if (sim_parse_args (&simulation, argv) != SIM_RC_OK)
dd442a44
DE
68 {
69 /* Uninstall the modules to avoid memory leaks,
70 file descriptor leaks, etc. */
71 sim_module_uninstall (&simulation);
72 return 0;
73 }
74
75 if (sim_post_argv_init (&simulation) != SIM_RC_OK)
76 {
77 /* Uninstall the modules to avoid memory leaks,
78 file descriptor leaks, etc. */
79 sim_module_uninstall (&simulation);
80 return 0;
81 }
15c16493
AC
82
83 engine_init(&simulation);
84
d5e2c74e
AC
85#define TIC80_MEM_START 0x2000000
86#define TIC80_MEM_SIZE 0x100000
87
15c16493
AC
88 /* external memory */
89 sim_core_attach(&simulation,
7a418800 90 NULL,
15c16493
AC
91 attach_raw_memory,
92 access_read_write_exec,
d5e2c74e
AC
93 0, TIC80_MEM_START, TIC80_MEM_SIZE, NULL, NULL);
94 sim_core_attach(&simulation,
7a418800 95 NULL,
d5e2c74e
AC
96 attach_raw_memory,
97 access_read_write_exec,
98 0, 0, TIC80_MEM_SIZE, NULL, NULL);
15c16493
AC
99
100 /* FIXME: for now */
101 return (SIM_DESC) &simulation;
102}
103
104
105/* NOTE: sim_size is going away */
106void sim_size (int i);
107void
108sim_size (int i)
109{
110 sim_io_error (NULL, "unexpected call to sim_size()");
111}
112
113
114void
115sim_close (SIM_DESC sd, int quitting)
116{
dd442a44
DE
117 /* Uninstall the modules to avoid memory leaks,
118 file descriptor leaks, etc. */
119 sim_module_uninstall (&simulation);
15c16493
AC
120}
121
122
123SIM_RC
124sim_load (SIM_DESC sd, char *prog, bfd *abfd, int from_tty)
125{
126 extern bfd *sim_load_file (); /* ??? Don't know where this should live. */
127 bfd *prog_bfd;
128
129 prog_bfd = sim_load_file (sd, STATE_MY_NAME (sd),
130 STATE_CALLBACK (sd),
131 prog,
132 /* pass NULL for abfd, we always open our own */
133 NULL,
134 STATE_OPEN_KIND (sd) == SIM_OPEN_DEBUG);
135 if (prog_bfd == NULL)
136 return SIM_RC_FAIL;
137 sim_analyze_program (sd, prog_bfd);
138 return SIM_RC_OK;
139}
140
141
142void
143sim_kill (SIM_DESC sd)
144{
145}
146
147
148int
149sim_read (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
150{
abe293a0
AC
151 return sim_core_read_buffer (sd, sim_core_write_map,
152 buf, mem, length);
15c16493
AC
153}
154
155
156int
157sim_write (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
158{
159 return sim_core_write_buffer (sd, sim_core_write_map,
160 buf, mem, length);
161}
162
163
abe293a0
AC
164/* FIXME - these magic numbers need to be moved elsewhere */
165
166#define SP_REGNUM 1 /* Contains address of top of stack */
167#define FP_REGNUM 31 /* Contains address of executing stack frame */
168#define PC_REGNUM 32 /* Contains program counter (FIXME?) */
169#define NPC_REGNUM 33 /* Contains the next program counter (FIXME?) */
170#define A0_REGNUM 34 /* Accumulator register 0 */
171#define A3_REGNUM 37 /* Accumulator register 1 */
172
173#define R0_REGNUM 0 /* General Purpose Register 0 - for sim */
174#define Rn_REGNUM 31 /* Last General Purpose Register - for sim */
175#define An_REGNUM A3_REGNUM /* Last Accumulator register - for sim */
176
15c16493 177void
abe293a0 178sim_fetch_register (SIM_DESC sd, int regnr, unsigned char *buf)
15c16493 179{
abe293a0
AC
180 if (regnr >= R0_REGNUM && regnr <= Rn_REGNUM)
181 *(unsigned32*)buf = H2T_4 (STATE_CPU (sd, 0)->reg[regnr - A0_REGNUM]);
182 else if (regnr == PC_REGNUM)
183 *(unsigned32*)buf = H2T_4 (STATE_CPU (sd, 0)->cia.ip);
184 else if (regnr == NPC_REGNUM)
185 *(unsigned32*)buf = H2T_4 (STATE_CPU (sd, 0)->cia.dp);
186 else if (regnr >= A0_REGNUM && regnr <= An_REGNUM)
187 *(unsigned64*)buf = H2T_8 (STATE_CPU (sd, 0)->acc[regnr - A0_REGNUM]);
188 else
189 sim_io_error (sd, "sim_fetch_register - unknown register nr %d", regnr);
190 return;
15c16493
AC
191}
192
193
194void
abe293a0 195sim_store_register (SIM_DESC sd, int regnr, unsigned char *buf)
15c16493 196{
abe293a0
AC
197 if (regnr >= R0_REGNUM && regnr <= Rn_REGNUM)
198 STATE_CPU (sd, 0)->reg[regnr - A0_REGNUM] = T2H_4 (*(unsigned32*)buf);
199 else if (regnr == PC_REGNUM)
200 STATE_CPU (sd, 0)->cia.ip = T2H_4 (*(unsigned32*)buf);
201 else if (regnr == NPC_REGNUM)
202 STATE_CPU (sd, 0)->cia.dp = T2H_4 (*(unsigned32*)buf);
203 else if (regnr == A0_REGNUM && regnr <= An_REGNUM)
43c53e07 204 STATE_CPU (sd, 0)->acc[regnr - A0_REGNUM] = T2H_8 (*(unsigned64*)buf);
abe293a0
AC
205 else
206 sim_io_error (sd, "sim_fetch_register - unknown register nr %d", regnr);
207 return;
15c16493
AC
208}
209
210
211void
212sim_info (SIM_DESC sd, int verbose)
213{
214}
215
216
217SIM_RC
218sim_create_inferior (SIM_DESC sd,
219 char **argv,
220 char **envp)
221{
222 STATE_CPU (sd, 0)->cia.ip = STATE_START_ADDR(sd);
223 STATE_CPU (sd, 0)->cia.dp = (STATE_START_ADDR(sd)
224 + sizeof (instruction_word));
381f42ef 225 STATE_CPU (sd, 0)->cr[IE_CR] |= IE_CR_IE;
d5e2c74e 226 STATE_CPU (sd, 0)->reg[1] = TIC80_MEM_START + TIC80_MEM_SIZE - 16;
15c16493
AC
227 return SIM_RC_OK;
228}
229
230
231volatile int keep_running = 1;
232
233void
234sim_stop_reason (SIM_DESC sd, enum sim_stop *reason, int *sigrc)
235{
236 *reason = simulation.reason;
237 *sigrc = simulation.siggnal;
238 keep_running = 1; /* ready for next run */
239}
240
241
242int
243sim_stop (SIM_DESC sd)
244{
245 keep_running = 0;
246 return 1;
247}
248
249void
250sim_resume (SIM_DESC sd, int step, int siggnal)
251{
252 /* keep_running = 1 - in sim_stop_reason */
253 if (step)
254 keep_running = 0;
255 engine_run_until_stop(sd, &keep_running);
256}
257
258void
259sim_do_command (SIM_DESC sd, char *cmd)
260{
43c53e07
AC
261 if (sim_args_command (sd, cmd) != SIM_RC_OK)
262 sim_io_eprintf (sd, "Unknown command `%s'\n", cmd);
15c16493
AC
263}
264
265
266void
267sim_set_callbacks (SIM_DESC sd, host_callback *callback)
268{
269 STATE_CALLBACK (&simulation) = callback;
270}
This page took 0.050004 seconds and 4 git commands to generate.