Fix SWAP_8 and optimize it; print out the failing address if a signal is issued for...
[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);
22ddef46 41 va_end(ap);
4f35cbff
MM
42}
43
44void
45error (char *msg, ...)
46{
47 va_list ap;
48 va_start(ap, msg);
49 vprintf(msg, ap);
22ddef46 50 va_end(ap);
4f35cbff
MM
51 exit (1);
52}
53
54void *
55zalloc(long size)
56{
57 void *memory = malloc(size);
58 if (memory == NULL)
59 error("zmalloc failed\n");
60 bzero(memory, size);
61 return memory;
62}
63
64void
65zfree(void *chunk)
66{
67 free(chunk);
68}
69
70static void
71usage(void)
72{
22ddef46 73 error ("Usage: psim [ -a -p -c -C -s -i -I -t -g ] <image> [ <image-args> ... ]\n");
4f35cbff
MM
74}
75
76int
77main(int argc, char **argv)
78{
79 psim *system;
4f35cbff
MM
80 const char *name_of_file;
81 char *arg_;
82 unsigned_word stack_pointer;
83 psim_status status;
84 int letter;
d8d46596 85 int i;
83d96c6e 86 int print_info = 0;
4f35cbff 87
8eab189b
MM
88 /* check for arguments -- note sim_calls.c also contains argument processing
89 code for the simulator linked within gdb. */
22ddef46 90 while ((letter = getopt (argc, argv, "acCiIpstg")) != EOF)
4f35cbff 91 {
d8d46596
MM
92 switch (letter) {
93 case 'a':
94 for (i = 0; i < nr_trace; i++)
22ddef46 95 ppc_trace[i] = 1;
d8d46596 96 break;
4f35cbff 97 case 'p':
22ddef46 98 ppc_trace[trace_cpu] = ppc_trace[trace_semantics] = 1;
4f35cbff
MM
99 break;
100 case 'c':
22ddef46 101 ppc_trace[trace_core] = 1;
4f35cbff 102 break;
d8d46596 103 case 'C':
22ddef46 104 ppc_trace[trace_console_device] = 1;
d8d46596 105 break;
4f35cbff 106 case 's':
22ddef46 107 ppc_trace[trace_create_stack] = 1;
4f35cbff
MM
108 break;
109 case 'i':
22ddef46 110 ppc_trace[trace_icu_device] = 1;
4f35cbff 111 break;
83d96c6e
MM
112 case 'I':
113 print_info = 1;
114 break;
4f35cbff 115 case 't':
22ddef46
MM
116 ppc_trace[trace_device_tree] = 1;
117 break;
118 case 'g':
119 ppc_trace[trace_gdb] = 1;
4f35cbff
MM
120 break;
121 default:
122 usage();
123 }
124 }
d8d46596 125 if (optind >= argc)
4f35cbff 126 usage();
d8d46596 127 name_of_file = argv[optind];
4f35cbff
MM
128
129 /* create the simulator */
130 system = psim_create(name_of_file, ((WITH_SMP > 0) ? WITH_SMP : 1));
131
132 /* fudge the environment so that _=prog-name */
d8d46596 133 arg_ = (char*)zalloc(strlen(argv[optind]) + strlen("_=") + 1);
4f35cbff 134 strcpy(arg_, "_=");
d8d46596 135 strcat(arg_, argv[optind]);
4f35cbff
MM
136 putenv(arg_);
137
138 /* initialize it */
22ddef46 139 psim_init(system);
d8d46596 140 psim_stack(system, &argv[optind], environ);
4f35cbff
MM
141
142 psim_run(system);
143
22ddef46 144 /* any final clean up */
83d96c6e
MM
145 if (print_info)
146 psim_print_info (system, 1);
147
4f35cbff
MM
148 /* why did we stop */
149 status = psim_get_status(system);
150 switch (status.reason) {
151 case was_continuing:
152 error("psim: continuing while stoped!\n");
153 return 0;
154 case was_trap:
155 error("psim: no trap insn\n");
156 return 0;
157 case was_exited:
158 return status.signal;
159 case was_signalled:
22ddef46
MM
160 printf ("%s: Caught signal %d at address 0x%lx\n",
161 name_of_file, (int)status.signal,
162 (long)status.program_counter);
4f35cbff
MM
163 return status.signal;
164 default:
165 error("unknown halt condition\n");
166 return 0;
167 }
168}
This page took 0.032395 seconds and 4 git commands to generate.