Match standalone printf_filtered to gdb prototype.
[deliverable/binutils-gdb.git] / sim / ppc / main.c
CommitLineData
4f35cbff
MM
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
29extern char **environ;
30extern char *optarg;
31extern int optind;
32extern int optopt;
33extern int opterr;
34
35void
d8d46596 36printf_filtered(const char *msg, ...)
4f35cbff
MM
37{
38 va_list ap;
39 va_start(ap, msg);
40 vprintf(msg, ap);
41}
42
43void
44error (char *msg, ...)
45{
46 va_list ap;
47 va_start(ap, msg);
48 vprintf(msg, ap);
49 exit (1);
50}
51
52void *
53zalloc(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
62void
63zfree(void *chunk)
64{
65 free(chunk);
66}
67
68static void
69usage(void)
70{
d8d46596 71 error ("Usage: psim [ -a -p -c -C -s -i -t ] <image> [ <image-args> ... ]\n");
4f35cbff
MM
72}
73
74int
75main(int argc, char **argv)
76{
77 psim *system;
4f35cbff
MM
78 const char *name_of_file;
79 char *arg_;
80 unsigned_word stack_pointer;
81 psim_status status;
82 int letter;
d8d46596 83 int i;
4f35cbff
MM
84
85 /* check for arguments - FIXME use getopt */
d8d46596 86 while ((letter = getopt (argc, argv, "acCipst")) != EOF)
4f35cbff 87 {
d8d46596
MM
88 switch (letter) {
89 case 'a':
90 for (i = 0; i < nr_trace; i++)
91 trace[i] = 1;
92 break;
4f35cbff
MM
93 case 'p':
94 trace[trace_cpu] = trace[trace_semantics] = 1;
95 break;
96 case 'c':
97 trace[trace_core] = 1;
98 break;
d8d46596
MM
99 case 'C':
100 trace[trace_console_device] = 1;
101 break;
4f35cbff
MM
102 case 's':
103 trace[trace_create_stack] = 1;
104 break;
105 case 'i':
106 trace[trace_icu_device] = 1;
107 break;
108 case 't':
109 trace[trace_device_tree] = 1;
110 break;
111 default:
112 usage();
113 }
114 }
115
d8d46596 116 if (optind >= argc)
4f35cbff 117 usage();
d8d46596 118 name_of_file = argv[optind];
4f35cbff
MM
119
120 /* create the simulator */
121 system = psim_create(name_of_file, ((WITH_SMP > 0) ? WITH_SMP : 1));
122
123 /* fudge the environment so that _=prog-name */
d8d46596 124 arg_ = (char*)zalloc(strlen(argv[optind]) + strlen("_=") + 1);
4f35cbff 125 strcpy(arg_, "_=");
d8d46596 126 strcat(arg_, argv[optind]);
4f35cbff
MM
127 putenv(arg_);
128
129 /* initialize it */
130 psim_load(system);
d8d46596 131 psim_stack(system, &argv[optind], environ);
4f35cbff
MM
132
133 psim_run(system);
134
135 /* why did we stop */
136 status = psim_get_status(system);
137 switch (status.reason) {
138 case was_continuing:
139 error("psim: continuing while stoped!\n");
140 return 0;
141 case was_trap:
142 error("psim: no trap insn\n");
143 return 0;
144 case was_exited:
145 return status.signal;
146 case was_signalled:
147 return status.signal;
148 default:
149 error("unknown halt condition\n");
150 return 0;
151 }
152}
This page took 0.029259 seconds and 4 git commands to generate.