first stage in function unit support; add new switches & latest code from andrew
[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 <stdio.h>
24
25 #include "psim.h"
26 #include "function_unit.h"
27
28 #ifdef HAVE_STDLIB_H
29 #include <stdlib.h>
30 #endif
31
32 #ifdef HAVE_UNISTD_H
33 #include <unistd.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 extern char **environ;
45 extern char *optarg;
46 extern int optind;
47 extern int optopt;
48 extern int opterr;
49
50 void
51 printf_filtered(const char *msg, ...)
52 {
53 va_list ap;
54 va_start(ap, msg);
55 vprintf(msg, ap);
56 va_end(ap);
57 }
58
59 void
60 error (char *msg, ...)
61 {
62 va_list ap;
63 va_start(ap, msg);
64 vprintf(msg, ap);
65 va_end(ap);
66 exit (1);
67 }
68
69 void *
70 zalloc(long size)
71 {
72 void *memory = malloc(size);
73 if (memory == NULL)
74 error("zmalloc failed\n");
75 bzero(memory, size);
76 return memory;
77 }
78
79 void
80 zfree(void *chunk)
81 {
82 free(chunk);
83 }
84
85 static void
86 usage(void)
87 {
88 printf_filtered("Usage:\n\tpsim [ -t <trace-option> ] [-m model] [-i] [-I] <image> [ <image-args> ... ]\n");
89 trace_usage();
90 error("");
91 }
92
93 int
94 main(int argc, char **argv)
95 {
96 psim *system;
97 const char *name_of_file;
98 char *arg_;
99 psim_status status;
100 int letter;
101 int print_info = 0;
102
103 /* check for arguments -- note sim_calls.c also contains argument processing
104 code for the simulator linked within gdb. */
105 while ((letter = getopt (argc, argv, "Iim:t:")) != EOF)
106 {
107 switch (letter) {
108 case 't':
109 trace_option(optarg);
110 break;
111 case 'm':
112 function_unit_model(optarg);
113 break;
114 case 'i':
115 print_info = 1;
116 break;
117 case 'I':
118 print_info = 2;
119 break;
120 default:
121 usage();
122 }
123 }
124 if (optind >= argc)
125 usage();
126 name_of_file = argv[optind];
127
128 /* create the simulator */
129 system = psim_create(name_of_file);
130
131 /* fudge the environment so that _=prog-name */
132 arg_ = (char*)zalloc(strlen(argv[optind]) + strlen("_=") + 1);
133 strcpy(arg_, "_=");
134 strcat(arg_, argv[optind]);
135 putenv(arg_);
136
137 /* initialize it */
138 psim_init(system);
139 psim_stack(system, &argv[optind], environ);
140
141 psim_run(system);
142
143 /* any final clean up */
144 if (print_info)
145 psim_print_info (system, print_info);
146
147 /* why did we stop */
148 status = psim_get_status(system);
149 switch (status.reason) {
150 case was_continuing:
151 error("psim: continuing while stoped!\n");
152 return 0;
153 case was_trap:
154 error("psim: no trap insn\n");
155 return 0;
156 case was_exited:
157 return status.signal;
158 case was_signalled:
159 printf ("%s: Caught signal %d at address 0x%lx\n",
160 name_of_file, (int)status.signal,
161 (long)status.program_counter);
162 return status.signal;
163 default:
164 error("unknown halt condition\n");
165 return 0;
166 }
167 }
This page took 0.033959 seconds and 5 git commands to generate.