* gdbtk.tcl (files_command): Correctly insert list of files into
[deliverable/binutils-gdb.git] / sim / ppc / main.c
CommitLineData
4f35cbff
MM
1/* This file is part of the program psim.
2
262faa54 3 Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
4f35cbff
MM
4
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.
9
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.
14
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.
18
19 */
20
21
22#include <stdarg.h>
4f35cbff 23#include <stdio.h>
4f35cbff
MM
24
25#include "psim.h"
28816f45 26#include "options.h"
262faa54 27#include "device.h" /* FIXME: psim should provide the interface */
4f35cbff 28
c494cadd
MM
29#ifdef HAVE_STDLIB_H
30#include <stdlib.h>
31#endif
32
73c4941b
MM
33#ifdef HAVE_UNISTD_H
34#include <unistd.h>
35#endif
36
c494cadd
MM
37#ifdef HAVE_STRING_H
38#include <string.h>
39#else
40#ifdef HAVE_STRINGS_H
41#include <strings.h>
42#endif
43#endif
44
4f35cbff 45extern char **environ;
4f35cbff
MM
46
47void
d8d46596 48printf_filtered(const char *msg, ...)
4f35cbff
MM
49{
50 va_list ap;
51 va_start(ap, msg);
52 vprintf(msg, ap);
22ddef46 53 va_end(ap);
4f35cbff
MM
54}
55
262faa54
MM
56void
57flush_stdoutput(void)
58{
59 fflush (stdout);
60}
61
4f35cbff
MM
62void
63error (char *msg, ...)
64{
65 va_list ap;
66 va_start(ap, msg);
67 vprintf(msg, ap);
22ddef46 68 va_end(ap);
4f35cbff
MM
69 exit (1);
70}
71
72void *
73zalloc(long size)
74{
75 void *memory = malloc(size);
76 if (memory == NULL)
77 error("zmalloc failed\n");
1dc7c0ed 78 memset(memory, 0, size);
4f35cbff
MM
79 return memory;
80}
81
82void
83zfree(void *chunk)
84{
85 free(chunk);
86}
87
4f35cbff
MM
88int
89main(int argc, char **argv)
90{
91 psim *system;
4f35cbff
MM
92 const char *name_of_file;
93 char *arg_;
4f35cbff 94 psim_status status;
262faa54
MM
95 device *root = psim_tree();
96
97 /* parse the arguments */
98 argv = psim_options(root, argv + 1);
99 if (argv[0] == NULL)
100 psim_usage(0);
101 name_of_file = argv[0];
4f35cbff 102
28816f45
MM
103 if (ppc_trace[trace_opts])
104 print_options ();
105
4f35cbff 106 /* create the simulator */
262faa54 107 system = psim_create(name_of_file, root);
4f35cbff
MM
108
109 /* fudge the environment so that _=prog-name */
262faa54 110 arg_ = (char*)zalloc(strlen(argv[0]) + strlen("_=") + 1);
4f35cbff 111 strcpy(arg_, "_=");
262faa54 112 strcat(arg_, argv[0]);
4f35cbff
MM
113 putenv(arg_);
114
115 /* initialize it */
22ddef46 116 psim_init(system);
262faa54 117 psim_stack(system, argv, environ);
4f35cbff
MM
118
119 psim_run(system);
120
22ddef46 121 /* any final clean up */
262faa54
MM
122 if (ppc_trace[trace_print_info])
123 psim_print_info (system, ppc_trace[trace_print_info]);
83d96c6e 124
4f35cbff
MM
125 /* why did we stop */
126 status = psim_get_status(system);
127 switch (status.reason) {
128 case was_continuing:
129 error("psim: continuing while stoped!\n");
130 return 0;
131 case was_trap:
132 error("psim: no trap insn\n");
133 return 0;
134 case was_exited:
135 return status.signal;
136 case was_signalled:
22ddef46 137 printf ("%s: Caught signal %d at address 0x%lx\n",
a983c8f0
MM
138 name_of_file, (int)status.signal,
139 (long)status.program_counter);
4f35cbff
MM
140 return status.signal;
141 default:
142 error("unknown halt condition\n");
143 return 0;
144 }
145}
This page took 0.062952 seconds and 4 git commands to generate.