* elflink.h (elf_link_add_object_symbols): Don't let a weak
[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 84
8eab189b
MM
85 /* check for arguments -- note sim_calls.c also contains argument processing
86 code for the simulator linked within gdb. */
d8d46596 87 while ((letter = getopt (argc, argv, "acCipst")) != EOF)
4f35cbff 88 {
d8d46596
MM
89 switch (letter) {
90 case 'a':
91 for (i = 0; i < nr_trace; i++)
92 trace[i] = 1;
93 break;
4f35cbff
MM
94 case 'p':
95 trace[trace_cpu] = trace[trace_semantics] = 1;
96 break;
97 case 'c':
98 trace[trace_core] = 1;
99 break;
d8d46596
MM
100 case 'C':
101 trace[trace_console_device] = 1;
102 break;
4f35cbff
MM
103 case 's':
104 trace[trace_create_stack] = 1;
105 break;
106 case 'i':
107 trace[trace_icu_device] = 1;
108 break;
109 case 't':
110 trace[trace_device_tree] = 1;
111 break;
112 default:
113 usage();
114 }
115 }
116
d8d46596 117 if (optind >= argc)
4f35cbff 118 usage();
d8d46596 119 name_of_file = argv[optind];
4f35cbff
MM
120
121 /* create the simulator */
122 system = psim_create(name_of_file, ((WITH_SMP > 0) ? WITH_SMP : 1));
123
124 /* fudge the environment so that _=prog-name */
d8d46596 125 arg_ = (char*)zalloc(strlen(argv[optind]) + strlen("_=") + 1);
4f35cbff 126 strcpy(arg_, "_=");
d8d46596 127 strcat(arg_, argv[optind]);
4f35cbff
MM
128 putenv(arg_);
129
130 /* initialize it */
131 psim_load(system);
d8d46596 132 psim_stack(system, &argv[optind], environ);
4f35cbff
MM
133
134 psim_run(system);
135
136 /* why did we stop */
137 status = psim_get_status(system);
138 switch (status.reason) {
139 case was_continuing:
140 error("psim: continuing while stoped!\n");
141 return 0;
142 case was_trap:
143 error("psim: no trap insn\n");
144 return 0;
145 case was_exited:
146 return status.signal;
147 case was_signalled:
148 return status.signal;
149 default:
150 error("unknown halt condition\n");
151 return 0;
152 }
153}
This page took 0.034799 seconds and 4 git commands to generate.