5ce3a0de226c2f03e0be8bb3e496c805e4f52ead
[deliverable/binutils-gdb.git] / sim / ppc / main.c
1 /* This file is part of the program psim.
2
3 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
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>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26
27 #include "psim.h"
28
29 extern char **environ;
30 extern char *optarg;
31 extern int optind;
32 extern int optopt;
33 extern int opterr;
34
35 void
36 printf_filtered(const char *msg, ...)
37 {
38 va_list ap;
39 va_start(ap, msg);
40 vprintf(msg, ap);
41 }
42
43 void
44 error (char *msg, ...)
45 {
46 va_list ap;
47 va_start(ap, msg);
48 vprintf(msg, ap);
49 exit (1);
50 }
51
52 void *
53 zalloc(long size)
54 {
55 void *memory = malloc(size);
56 if (memory == NULL)
57 error("zmalloc failed\n");
58 bzero(memory, size);
59 return memory;
60 }
61
62 void
63 zfree(void *chunk)
64 {
65 free(chunk);
66 }
67
68 static void
69 usage(void)
70 {
71 error ("Usage: psim [ -a -p -c -C -s -i -t ] <image> [ <image-args> ... ]\n");
72 }
73
74 int
75 main(int argc, char **argv)
76 {
77 psim *system;
78 const char *name_of_file;
79 char *arg_;
80 unsigned_word stack_pointer;
81 psim_status status;
82 int letter;
83 int i;
84 int print_info = 0;
85
86 /* check for arguments -- note sim_calls.c also contains argument processing
87 code for the simulator linked within gdb. */
88 while ((letter = getopt (argc, argv, "acCiIpst")) != EOF)
89 {
90 switch (letter) {
91 case 'a':
92 for (i = 0; i < nr_trace; i++)
93 trace[i] = 1;
94 break;
95 case 'p':
96 trace[trace_cpu] = trace[trace_semantics] = 1;
97 break;
98 case 'c':
99 trace[trace_core] = 1;
100 break;
101 case 'C':
102 trace[trace_console_device] = 1;
103 break;
104 case 's':
105 trace[trace_create_stack] = 1;
106 break;
107 case 'i':
108 trace[trace_icu_device] = 1;
109 break;
110 case 'I':
111 print_info = 1;
112 break;
113 case 't':
114 trace[trace_device_tree] = 1;
115 break;
116 default:
117 usage();
118 }
119 }
120
121 if (optind >= argc)
122 usage();
123 name_of_file = argv[optind];
124
125 /* create the simulator */
126 system = psim_create(name_of_file, ((WITH_SMP > 0) ? WITH_SMP : 1));
127
128 /* fudge the environment so that _=prog-name */
129 arg_ = (char*)zalloc(strlen(argv[optind]) + strlen("_=") + 1);
130 strcpy(arg_, "_=");
131 strcat(arg_, argv[optind]);
132 putenv(arg_);
133
134 /* initialize it */
135 psim_load(system);
136 psim_stack(system, &argv[optind], environ);
137
138 psim_run(system);
139
140 if (print_info)
141 psim_print_info (system, 1);
142
143 /* why did we stop */
144 status = psim_get_status(system);
145 switch (status.reason) {
146 case was_continuing:
147 error("psim: continuing while stoped!\n");
148 return 0;
149 case was_trap:
150 error("psim: no trap insn\n");
151 return 0;
152 case was_exited:
153 return status.signal;
154 case was_signalled:
155 return status.signal;
156 default:
157 error("unknown halt condition\n");
158 return 0;
159 }
160 }
This page took 0.032451 seconds and 3 git commands to generate.