Commit | Line | Data |
---|---|---|
f03b093c AC |
1 | /* Generic simulator halt/restart. |
2 | Copyright (C) 1997 Free Software Foundation, Inc. | |
3 | Contributed by Cygnus Support. | |
4 | ||
5 | This file is part of GDB, the GNU debugger. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License along | |
18 | with this program; if not, write to the Free Software Foundation, Inc., | |
19 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | #include "sim-main.h" | |
22 | ||
23 | #include <stdio.h> | |
24 | #include <signal.h> | |
25 | ||
26 | ||
27 | /* Generic halt */ | |
28 | ||
29 | void | |
30 | sim_engine_halt (SIM_DESC sd, | |
31 | sim_cpu *last_cpu, | |
32 | sim_cpu *next_cpu, /* NULL - use default */ | |
33 | sim_cia cia, | |
34 | enum sim_stop reason, | |
35 | int sigrc) | |
36 | { | |
37 | sim_engine *engine = STATE_ENGINE (sd); | |
38 | if (engine->jmpbuf != NULL) | |
39 | { | |
40 | jmp_buf *halt_buf = engine->jmpbuf; | |
41 | engine->last_cpu = last_cpu; | |
42 | engine->next_cpu = next_cpu; | |
43 | engine->reason = reason; | |
44 | engine->sigrc = sigrc; | |
45 | SIM_ENGINE_HALT_HOOK (sd, last_cpu, cia); | |
46 | longjmp(*halt_buf, 1); | |
47 | } | |
48 | else | |
49 | sim_io_error (sd, "sim_halt - bad long jump"); | |
50 | } | |
51 | ||
52 | ||
53 | /* Generic restart */ | |
54 | ||
55 | void | |
56 | sim_engine_restart (SIM_DESC sd, | |
57 | sim_cpu *last_cpu, | |
58 | sim_cpu *next_cpu, | |
59 | sim_cia cia) | |
60 | { | |
61 | sim_engine *engine = STATE_ENGINE (sd); | |
62 | if (engine->jmpbuf != NULL) | |
63 | { | |
64 | jmp_buf *halt_buf = engine->jmpbuf; | |
65 | engine->last_cpu = last_cpu; | |
66 | engine->next_cpu = next_cpu; | |
67 | SIM_ENGINE_RESTART_HOOK (sd, last_cpu, cia); | |
68 | longjmp(*halt_buf, 0); | |
69 | } | |
70 | else | |
71 | sim_io_error (sd, "sim_restart - bad long jump"); | |
72 | } | |
73 | ||
74 | ||
75 | /* Generic error code */ | |
76 | ||
77 | void | |
78 | sim_engine_abort (SIM_DESC sd, | |
79 | sim_cpu *cpu, | |
80 | sim_cia cia, | |
81 | const char *fmt, | |
82 | ...) | |
83 | { | |
84 | if (sd == NULL) | |
85 | { | |
86 | va_list ap; | |
87 | va_start(ap, fmt); | |
88 | vfprintf (stderr, fmt, ap); | |
89 | va_end(ap); | |
90 | fprintf (stderr, "\nQuit\n"); | |
91 | abort (); | |
92 | } | |
93 | else if (STATE_ENGINE (sd)->jmpbuf == NULL) | |
94 | { | |
95 | va_list ap; | |
96 | va_start(ap, fmt); | |
97 | sim_io_evprintf (sd, fmt, ap); | |
98 | va_end(ap); | |
99 | sim_io_eprintf (sd, "\n"); | |
100 | sim_io_error (sd, "Quit Simulator"); | |
101 | } | |
102 | else | |
103 | { | |
104 | va_list ap; | |
105 | va_start(ap, fmt); | |
106 | sim_io_evprintf (sd, fmt, ap); | |
107 | va_end(ap); | |
108 | sim_io_eprintf (sd, "\n"); | |
109 | sim_engine_halt (sd, cpu, NULL, cia, sim_stopped, SIGABRT); | |
110 | } | |
111 | } | |
112 | ||
113 | ||
114 | /* Generic next/last cpu */ | |
115 | ||
116 | int | |
117 | sim_engine_last_cpu_nr (SIM_DESC sd) | |
118 | { | |
119 | sim_engine *engine = STATE_ENGINE (sd); | |
120 | if (engine->last_cpu != NULL) | |
121 | return engine->last_cpu - STATE_CPU (sd, 0); | |
122 | else | |
123 | return MAX_NR_PROCESSORS; | |
124 | } | |
125 | ||
126 | int | |
127 | sim_engine_next_cpu_nr (SIM_DESC sd) | |
128 | { | |
129 | sim_engine *engine = STATE_ENGINE (sd); | |
130 | if (engine->next_cpu != NULL) | |
131 | return engine->next_cpu - STATE_CPU (sd, 0); | |
132 | else | |
133 | return sim_engine_last_cpu_nr (sd) + 1; | |
134 | } |