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