]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/tic80/sim-calls.c
Flush defunct sim_kill.
[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,
54 host_callback *callback,
55 struct _bfd *abfd,
56 char **argv)
57 {
58 SIM_DESC sd = &simulation;
59 STATE_OPEN_KIND (sd) = kind;
60 STATE_MAGIC (sd) = SIM_MAGIC_NUMBER;
61 STATE_CALLBACK (&simulation) = callback;
62
63 if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK)
64 return 0;
65
66 /* getopt will print the error message so we just have to exit if this fails.
67 FIXME: Hmmm... in the case of gdb we need getopt to call
68 print_filtered. */
69 if (sim_parse_args (sd, argv) != SIM_RC_OK)
70 {
71 /* Uninstall the modules to avoid memory leaks,
72 file descriptor leaks, etc. */
73 sim_module_uninstall (sd);
74 return 0;
75 }
76
77 /* establish the simulator configuration */
78 if (sim_config (sd, abfd) != SIM_RC_OK)
79 {
80 sim_module_uninstall (sd);
81 return 0;
82 }
83
84 if (sim_post_argv_init (sd) != SIM_RC_OK)
85 {
86 /* Uninstall the modules to avoid memory leaks,
87 file descriptor leaks, etc. */
88 sim_module_uninstall (sd);
89 return 0;
90 }
91
92 /* Initialize the main processor */
93 memset (&STATE_CPU (sd, 0)->reg, 0, sizeof STATE_CPU (sd, 0)->reg);
94 memset (&STATE_CPU (sd, 0)->acc, 0, sizeof STATE_CPU (sd, 0)->acc);
95 memset (&STATE_CPU (sd, 0)->cr, 0, sizeof STATE_CPU (sd, 0)->cr);
96 STATE_CPU (sd, 0)->is_user_mode = 0;
97 memset (&STATE_CPU (sd, 0)->cia, 0, sizeof STATE_CPU (sd, 0)->cia);
98 CPU_STATE (STATE_CPU (sd, 0)) = sd;
99
100 #define TIC80_MEM_START 0x2000000
101 #define TIC80_MEM_SIZE 0x100000
102
103 /* external memory */
104 sim_core_attach(sd,
105 NULL,
106 attach_raw_memory,
107 access_read_write_exec,
108 0, TIC80_MEM_START, TIC80_MEM_SIZE, NULL, NULL);
109 sim_core_attach(sd,
110 NULL,
111 attach_raw_memory,
112 access_read_write_exec,
113 0, 0, TIC80_MEM_SIZE, NULL, NULL);
114
115 /* FIXME: for now */
116 return sd;
117 }
118
119
120 void
121 sim_close (SIM_DESC sd, int quitting)
122 {
123 /* Uninstall the modules to avoid memory leaks,
124 file descriptor leaks, etc. */
125 sim_module_uninstall (sd);
126 }
127
128
129 SIM_RC
130 sim_load (SIM_DESC sd, char *prog, bfd *abfd, int from_tty)
131 {
132 bfd *prog_bfd;
133
134 prog_bfd = sim_load_file (sd, STATE_MY_NAME (sd),
135 STATE_CALLBACK (sd),
136 prog,
137 /* pass NULL for abfd, we always open our own */
138 NULL,
139 STATE_OPEN_KIND (sd) == SIM_OPEN_DEBUG);
140 if (prog_bfd == NULL)
141 return SIM_RC_FAIL;
142 sim_analyze_program (sd, prog_bfd);
143 return SIM_RC_OK;
144 }
145
146
147 int
148 sim_read (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
149 {
150 return sim_core_read_buffer (sd, NULL, sim_core_write_map,
151 buf, mem, length);
152 }
153
154
155 int
156 sim_write (SIM_DESC sd, SIM_ADDR mem, unsigned char *buf, int length)
157 {
158 return sim_core_write_buffer (sd, NULL, sim_core_write_map,
159 buf, mem, length);
160 }
161
162
163 /* FIXME - these magic numbers need to be moved elsewhere */
164
165 #define SP_REGNUM 1 /* Contains address of top of stack */
166 #define FP_REGNUM 31 /* Contains address of executing stack frame */
167 #define PC_REGNUM 32 /* Contains program counter (FIXME?) */
168 #define NPC_REGNUM 33 /* Contains the next program counter (FIXME?) */
169 #define A0_REGNUM 34 /* Accumulator register 0 */
170 #define A3_REGNUM 37 /* Accumulator register 1 */
171
172 #define R0_REGNUM 0 /* General Purpose Register 0 - for sim */
173 #define Rn_REGNUM 31 /* Last General Purpose Register - for sim */
174 #define An_REGNUM A3_REGNUM /* Last Accumulator register - for sim */
175
176 void
177 sim_fetch_register (SIM_DESC sd, int regnr, unsigned char *buf)
178 {
179 if (regnr == R0_REGNUM)
180 memset (buf, 0, sizeof (unsigned32));
181 else if (regnr > R0_REGNUM && regnr <= Rn_REGNUM)
182 *(unsigned32*)buf = H2T_4 (STATE_CPU (sd, 0)->reg[regnr - R0_REGNUM]);
183 else if (regnr == PC_REGNUM)
184 *(unsigned32*)buf = H2T_4 (STATE_CPU (sd, 0)->cia.ip);
185 else if (regnr == NPC_REGNUM)
186 *(unsigned32*)buf = H2T_4 (STATE_CPU (sd, 0)->cia.dp);
187 else if (regnr >= A0_REGNUM && regnr <= An_REGNUM)
188 *(unsigned64*)buf = H2T_8 (STATE_CPU (sd, 0)->acc[regnr - A0_REGNUM]);
189 else
190 sim_io_error (sd, "sim_fetch_register - unknown register nr %d", regnr);
191 return;
192 }
193
194
195 void
196 sim_store_register (SIM_DESC sd, int regnr, unsigned char *buf)
197 {
198 if (regnr >= R0_REGNUM && regnr <= Rn_REGNUM)
199 STATE_CPU (sd, 0)->reg[regnr - R0_REGNUM] = T2H_4 (*(unsigned32*)buf);
200 else if (regnr == PC_REGNUM)
201 STATE_CPU (sd, 0)->cia.ip = T2H_4 (*(unsigned32*)buf);
202 else if (regnr == NPC_REGNUM)
203 STATE_CPU (sd, 0)->cia.dp = T2H_4 (*(unsigned32*)buf);
204 else if (regnr >= A0_REGNUM && regnr <= An_REGNUM)
205 STATE_CPU (sd, 0)->acc[regnr - A0_REGNUM] = T2H_8 (*(unsigned64*)buf);
206 else
207 sim_io_error (sd, "sim_store_register - unknown register nr %d", regnr);
208 return;
209 }
210
211
212 void
213 sim_info (SIM_DESC sd, int verbose)
214 {
215 }
216
217
218 SIM_RC
219 sim_create_inferior (SIM_DESC sd,
220 char **argv,
221 char **envp)
222 {
223 STATE_CPU (sd, 0)->cia.ip = STATE_START_ADDR(sd);
224 STATE_CPU (sd, 0)->cia.dp = (STATE_START_ADDR(sd)
225 + sizeof (instruction_word));
226 STATE_CPU (sd, 0)->cr[IE_CR] |= IE_CR_IE;
227 STATE_CPU (sd, 0)->reg[1] = TIC80_MEM_START + TIC80_MEM_SIZE - 16;
228 return SIM_RC_OK;
229 }
230
231
232 void
233 sim_do_command (SIM_DESC sd, char *cmd)
234 {
235 if (sim_args_command (sd, cmd) != SIM_RC_OK)
236 sim_io_eprintf (sd, "Unknown command `%s'\n", cmd);
237 }