]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/tic80/sim-calls.c
o Add core and event objects into simulator
[thirdparty/binutils-gdb.git] / sim / tic80 / sim-calls.c
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"
29 #include "sim-utils.h"
30 #include "sim-options.h"
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
49 struct sim_state simulation = { 0 };
50
51
52 SIM_DESC
53 sim_open (SIM_OPEN_KIND kind, char **argv)
54 {
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)
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 }
82
83 engine_init(&simulation);
84
85 #define TIC80_MEM_START 0x2000000
86 #define TIC80_MEM_SIZE 0x100000
87
88 /* external memory */
89 sim_core_attach(&simulation,
90 attach_raw_memory,
91 access_read_write_exec,
92 0, TIC80_MEM_START, TIC80_MEM_SIZE, NULL, NULL);
93 sim_core_attach(&simulation,
94 attach_raw_memory,
95 access_read_write_exec,
96 0, 0, TIC80_MEM_SIZE, NULL, NULL);
97
98 /* FIXME: for now */
99 return (SIM_DESC) &simulation;
100 }
101
102
103 /* NOTE: sim_size is going away */
104 void sim_size (int i);
105 void
106 sim_size (int i)
107 {
108 sim_io_error (NULL, "unexpected call to sim_size()");
109 }
110
111
112 void
113 sim_close (SIM_DESC sd, int quitting)
114 {
115 /* Uninstall the modules to avoid memory leaks,
116 file descriptor leaks, etc. */
117 sim_module_uninstall (&simulation);
118 }
119
120
121 SIM_RC
122 sim_load (SIM_DESC sd, char *prog, bfd *abfd, int from_tty)
123 {
124 extern bfd *sim_load_file (); /* ??? Don't know where this should live. */
125 bfd *prog_bfd;
126
127 prog_bfd = sim_load_file (sd, STATE_MY_NAME (sd),
128 STATE_CALLBACK (sd),
129 prog,
130 /* pass NULL for abfd, we always open our own */
131 NULL,
132 STATE_OPEN_KIND (sd) == SIM_OPEN_DEBUG);
133 if (prog_bfd == NULL)
134 return SIM_RC_FAIL;
135 sim_analyze_program (sd, prog_bfd);
136 return SIM_RC_OK;
137 }
138
139
140 void
141 sim_kill (SIM_DESC sd)
142 {
143 }
144
145
146 int
147 sim_read (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
148 {
149 return sim_core_read_buffer (sd, sim_core_write_map,
150 buf, mem, length);
151 }
152
153
154 int
155 sim_write (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
156 {
157 return sim_core_write_buffer (sd, sim_core_write_map,
158 buf, mem, length);
159 }
160
161
162 /* FIXME - these magic numbers need to be moved elsewhere */
163
164 #define SP_REGNUM 1 /* Contains address of top of stack */
165 #define FP_REGNUM 31 /* Contains address of executing stack frame */
166 #define PC_REGNUM 32 /* Contains program counter (FIXME?) */
167 #define NPC_REGNUM 33 /* Contains the next program counter (FIXME?) */
168 #define A0_REGNUM 34 /* Accumulator register 0 */
169 #define A3_REGNUM 37 /* Accumulator register 1 */
170
171 #define R0_REGNUM 0 /* General Purpose Register 0 - for sim */
172 #define Rn_REGNUM 31 /* Last General Purpose Register - for sim */
173 #define An_REGNUM A3_REGNUM /* Last Accumulator register - for sim */
174
175 void
176 sim_fetch_register (SIM_DESC sd, int regnr, unsigned char *buf)
177 {
178 if (regnr >= R0_REGNUM && regnr <= Rn_REGNUM)
179 *(unsigned32*)buf = H2T_4 (STATE_CPU (sd, 0)->reg[regnr - A0_REGNUM]);
180 else if (regnr == PC_REGNUM)
181 *(unsigned32*)buf = H2T_4 (STATE_CPU (sd, 0)->cia.ip);
182 else if (regnr == NPC_REGNUM)
183 *(unsigned32*)buf = H2T_4 (STATE_CPU (sd, 0)->cia.dp);
184 else if (regnr >= A0_REGNUM && regnr <= An_REGNUM)
185 *(unsigned64*)buf = H2T_8 (STATE_CPU (sd, 0)->acc[regnr - A0_REGNUM]);
186 else
187 sim_io_error (sd, "sim_fetch_register - unknown register nr %d", regnr);
188 return;
189 }
190
191
192 void
193 sim_store_register (SIM_DESC sd, int regnr, unsigned char *buf)
194 {
195 if (regnr >= R0_REGNUM && regnr <= Rn_REGNUM)
196 STATE_CPU (sd, 0)->reg[regnr - A0_REGNUM] = T2H_4 (*(unsigned32*)buf);
197 else if (regnr == PC_REGNUM)
198 STATE_CPU (sd, 0)->cia.ip = T2H_4 (*(unsigned32*)buf);
199 else if (regnr == NPC_REGNUM)
200 STATE_CPU (sd, 0)->cia.dp = T2H_4 (*(unsigned32*)buf);
201 else if (regnr == A0_REGNUM && regnr <= An_REGNUM)
202 STATE_CPU (sd, 0)->acc[regnr - A0_REGNUM] = H2T_8 (*(unsigned64*)buf);
203 else
204 sim_io_error (sd, "sim_fetch_register - unknown register nr %d", regnr);
205 return;
206 }
207
208
209 void
210 sim_info (SIM_DESC sd, int verbose)
211 {
212 }
213
214
215 SIM_RC
216 sim_create_inferior (SIM_DESC sd,
217 char **argv,
218 char **envp)
219 {
220 STATE_CPU (sd, 0)->cia.ip = STATE_START_ADDR(sd);
221 STATE_CPU (sd, 0)->cia.dp = (STATE_START_ADDR(sd)
222 + sizeof (instruction_word));
223 STATE_CPU (sd, 0)->reg[1] = TIC80_MEM_START + TIC80_MEM_SIZE - 16;
224 return SIM_RC_OK;
225 }
226
227
228 volatile int keep_running = 1;
229
230 void
231 sim_stop_reason (SIM_DESC sd, enum sim_stop *reason, int *sigrc)
232 {
233 *reason = simulation.reason;
234 *sigrc = simulation.siggnal;
235 keep_running = 1; /* ready for next run */
236 }
237
238
239 int
240 sim_stop (SIM_DESC sd)
241 {
242 keep_running = 0;
243 return 1;
244 }
245
246 void
247 sim_resume (SIM_DESC sd, int step, int siggnal)
248 {
249 /* keep_running = 1 - in sim_stop_reason */
250 if (step)
251 keep_running = 0;
252 engine_run_until_stop(sd, &keep_running);
253 }
254
255 void
256 sim_do_command (SIM_DESC sd, char *cmd)
257 {
258 sim_io_error (sd, "sim_do_command - unimplemented");
259 }
260
261
262 void
263 sim_set_callbacks (SIM_DESC sd, host_callback *callback)
264 {
265 STATE_CALLBACK (&simulation) = callback;
266 }