7cb50368a91eae51a62f3f407de36f3720084cbb
1 /* This file is part of the program psim.
3 Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #include "device.h" /* FIXME: psim should provide the interface */
31 #include "events.h" /* FIXME: psim should provide the interface */
34 #include "gdb/callback.h"
35 #include "gdb/remote-sim.h"
55 #if !defined(O_NDELAY) || !defined(F_GETFL) || !defined(F_SETFL)
57 #define WITH_STDIO DO_USE_STDIO
61 extern char **environ
;
63 static psim
*simulation
= NULL
;
67 sim_io_poll_quit (void)
73 sim_io_printf_filtered(const char *msg
, ...)
82 error (const char *msg
, ...)
90 /* any final clean up */
91 if (ppc_trace
[trace_print_info
] && simulation
!= NULL
)
92 psim_print_info (simulation
, ppc_trace
[trace_print_info
]);
98 sim_io_write_stdout(const char *buf
,
101 switch (CURRENT_STDIO
) {
105 for (i
= 0; i
< sizeof_buf
; i
++) {
112 return write(1, buf
, sizeof_buf
);
115 error("sim_io_write_stdout: invalid switch\n");
121 sim_io_write_stderr(const char *buf
,
124 switch (CURRENT_STDIO
) {
128 for (i
= 0; i
< sizeof_buf
; i
++) {
129 fputc(buf
[i
], stderr
);
135 return write(2, buf
, sizeof_buf
);
138 error("sim_io_write_stdout: invalid switch\n");
144 sim_io_read_stdin(char *buf
,
147 switch (CURRENT_STDIO
) {
149 if (sizeof_buf
> 1) {
150 if (fgets(buf
, sizeof_buf
, stdin
) != NULL
)
153 else if (sizeof_buf
== 1) {
155 if (fgets(b
, sizeof(b
), stdin
) != NULL
) {
156 memcpy(buf
, b
, strlen(b
));
160 else if (sizeof_buf
== 0)
165 #if defined(O_NDELAY) && defined(F_GETFL) && defined(F_SETFL)
167 /* check for input */
172 /* get the old status */
173 flags
= fcntl(0, F_GETFL
, 0);
175 perror("sim_io_read_stdin");
178 /* temp, disable blocking IO */
179 status
= fcntl(0, F_SETFL
, flags
| O_NDELAY
);
181 perror("sim_io_read_stdin");
185 nr_read
= read(0, buf
, sizeof_buf
);
187 || (nr_read
== 0 && sizeof_buf
== 0))
189 else if (nr_read
== 0)
191 else { /* nr_read < 0 */
193 result
= sim_io_not_ready
;
197 /* return to regular vewing */
198 status
= fcntl(0, F_SETFL
, flags
);
200 perror("sim_io_read_stdin");
208 error("sim_io_read_stdin: invalid switch\n");
215 sim_io_flush_stdoutput(void)
217 switch (CURRENT_STDIO
) {
224 error("sim_io_flush_stdoutput: invalid switch\n");
230 sim_io_error (SIM_DESC sd
, const char *msg
, ...)
238 /* any final clean up */
239 if (ppc_trace
[trace_print_info
] && simulation
!= NULL
)
240 psim_print_info (simulation
, ppc_trace
[trace_print_info
]);
249 void *memory
= malloc(size
);
251 error("zalloc failed\n");
252 memset(memory
, 0, size
);
256 /* When a CNTRL-C occures, queue an event to shut down the simulation */
261 psim_stop (simulation
);
266 main(int argc
, char **argv
)
268 const char *name_of_file
;
271 device
*root
= psim_tree();
273 /* parse the arguments */
274 argv
= psim_options(root
, argv
+ 1);
275 if (argv
[0] == NULL
) {
276 if (ppc_trace
[trace_opts
]) {
283 name_of_file
= argv
[0];
285 if (ppc_trace
[trace_opts
])
288 /* create the simulator */
289 simulation
= psim_create(name_of_file
, root
);
291 /* fudge the environment so that _=prog-name */
292 arg_
= (char*)zalloc(strlen(argv
[0]) + strlen("_=") + 1);
294 strcat(arg_
, argv
[0]);
298 psim_init(simulation
);
299 psim_stack(simulation
, argv
, environ
);
302 RETSIGTYPE (*prev
) ();
303 prev
= signal(SIGINT
, cntrl_c
);
304 psim_run(simulation
);
305 signal(SIGINT
, prev
);
308 /* any final clean up */
309 if (ppc_trace
[trace_print_info
])
310 psim_print_info (simulation
, ppc_trace
[trace_print_info
]);
312 /* why did we stop */
313 status
= psim_get_status(simulation
);
314 switch (status
.reason
) {
316 error("psim: continuing while stopped!\n");
319 error("psim: no trap insn\n");
322 return status
.signal
;
324 printf ("%s: Caught signal %d at address 0x%lx\n",
325 name_of_file
, (int)status
.signal
,
326 (long)status
.program_counter
);
327 return status
.signal
;
329 error("unknown halt condition\n");
This page took 0.034923 seconds and 4 git commands to generate.