Supports sh3/sh4/sh3eb/sh4eb-unknown-linux-gnu targets
[deliverable/binutils-gdb.git] / sim / z8k / iface.c
CommitLineData
c906108c
SS
1/* gdb->simulator interface.
2 Copyright (C) 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
3
4This file is part of Z8KSIM
5
6Z8KSIM is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11Z8KSIM is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with Z8KZIM; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20#include "ansidecl.h"
21#include "sim.h"
22#include "tm.h"
23#include "signal.h"
24#include "bfd.h"
25#include "callback.h"
26#include "remote-sim.h"
27
28#ifndef NULL
29#define NULL 0
30#endif
31
32host_callback *z8k_callback;
33
34static SIM_OPEN_KIND sim_kind;
35static char *myname;
36
37void
38sim_size (n)
39 int n;
40{
41 /* Size is fixed. */
42}
43
44int
45sim_store_register (sd, regno, value, length)
46 SIM_DESC sd;
47 int regno;
48 unsigned char *value;
49 int length;
50{
51 /* FIXME: Review the computation of regval. */
52 int regval = (value[0] << 24) | (value[1] << 16) | (value[2] << 8) | value[3];
53
54 tm_store_register (regno, regval);
55 return -1;
56}
57
58int
59sim_fetch_register (sd, regno, buf, length)
60 SIM_DESC sd;
61 int regno;
62 unsigned char *buf;
63 int length;
64{
65 tm_fetch_register (regno, buf);
66 return -1;
67}
68
69int
70sim_write (sd, where, what, howmuch)
71 SIM_DESC sd;
72 SIM_ADDR where;
73 unsigned char *what;
74 int howmuch;
75{
76 int i;
77
78 for (i = 0; i < howmuch; i++)
79 tm_write_byte (where + i, what[i]);
80 return howmuch;
81}
82
83int
84sim_read (sd, where, what, howmuch)
85 SIM_DESC sd;
86 SIM_ADDR where;
87 unsigned char *what;
88 int howmuch;
89{
90 int i;
91
92 for (i = 0; i < howmuch; i++)
93 what[i] = tm_read_byte (where + i);
94 return howmuch;
95}
96
97static void
98control_c (sig, code, scp, addr)
99 int sig;
100 int code;
101 char *scp;
102 char *addr;
103{
104 tm_exception (SIM_INTERRUPT);
105}
106
107int
108sim_stop (sd)
109 SIM_DESC sd;
110{
111 tm_exception (SIM_INTERRUPT);
112 return 1;
113}
114
115void
116sim_resume (sd, step, sig)
117 SIM_DESC sd;
118 int step;
119 int sig;
120{
121 void (*prev) ();
122
123 prev = signal (SIGINT, control_c);
124 tm_resume (step);
125 signal (SIGINT, prev);
126}
127
128void
129sim_stop_reason (sd, reason, sigrc)
130 SIM_DESC sd;
131 enum sim_stop *reason;
132 int *sigrc;
133{
134 switch (tm_signal ())
135 {
136 case SIM_DIV_ZERO:
137 *sigrc = SIGFPE;
138 break;
139 case SIM_INTERRUPT:
140 *sigrc = SIGINT;
141 break;
142 case SIM_BAD_INST:
143 *sigrc = SIGILL;
144 break;
145 case SIM_BREAKPOINT:
146 *sigrc = SIGTRAP;
147 break;
148 case SIM_SINGLE_STEP:
149 *sigrc = SIGTRAP;
150 break;
151 case SIM_BAD_SYSCALL:
152 *sigrc = SIGILL;
153 break;
154 case SIM_BAD_ALIGN:
155 *sigrc = SIGSEGV;
156 break;
157 case SIM_DONE:
158 {
159 sim_state_type x;
160 tm_state (&x);
161 *sigrc = x.regs[2].word & 255;
162 *reason = sim_exited;
163 return;
164 }
165 default:
166 abort ();
167 }
168 *reason = sim_stopped;
169}
170
171void
172sim_info (sd, verbose)
173 SIM_DESC sd;
174 int verbose;
175{
176 sim_state_type x;
177
178 tm_state (&x);
179 tm_info_print (&x);
180}
181
182SIM_DESC
183sim_open (kind, cb, abfd, argv)
184 SIM_OPEN_KIND kind;
185 host_callback *cb;
186 struct _bfd *abfd;
187 char **argv;
188{
189 /* FIXME: The code in sim_load that determines the exact z8k arch
190 should be moved to here */
191
192 sim_kind = kind;
193 myname = argv[0];
194 z8k_callback = cb;
195
196 /* fudge our descriptor for now */
197 return (SIM_DESC) 1;
198}
199
200void
201sim_close (sd, quitting)
202 SIM_DESC sd;
203 int quitting;
204{
205 /* nothing to do */
206}
207
208SIM_RC
209sim_load (sd, prog, abfd, from_tty)
210 SIM_DESC sd;
211 char *prog;
212 bfd *abfd;
213 int from_tty;
214{
215 extern bfd *sim_load_file (); /* ??? Don't know where this should live. */
216 bfd *prog_bfd;
217
218 /* FIXME: The code determining the type of z9k processor should be
219 moved from here to sim_open. */
220
221 prog_bfd = sim_load_file (sd, myname, z8k_callback, prog, abfd,
222 sim_kind == SIM_OPEN_DEBUG,
223 0, sim_write);
224 if (prog_bfd == NULL)
225 return SIM_RC_FAIL;
226 if (bfd_get_mach (prog_bfd) == bfd_mach_z8001)
227 {
228 extern int sim_z8001_mode;
229 sim_z8001_mode = 1;
230 }
231 /* Close the bfd if we opened it. */
232 if (abfd == NULL)
233 bfd_close (prog_bfd);
234 return SIM_RC_OK;
235}
236
237SIM_RC
238sim_create_inferior (sd, abfd, argv, env)
239 SIM_DESC sd;
240 struct _bfd *abfd;
241 char **argv;
242 char **env;
243{
244 if (abfd != NULL)
245 tm_store_register (REG_PC, bfd_get_start_address (abfd));
246 else
247 tm_store_register (REG_PC, 0);
248 return SIM_RC_OK;
249}
250
251void
252sim_do_command (sd, cmd)
253 SIM_DESC sd;
254 char *cmd;
255{
256}
257
258void
259sim_set_callbacks (ptr)
260 host_callback *ptr;
261{
262 z8k_callback = ptr;
263}
This page took 0.09547 seconds and 4 git commands to generate.