Commit | Line | Data |
---|---|---|
15c16493 AC |
1 | /* This file is part of the GDB simulators. |
2 | ||
3 | Copyright (C) 1997, Free Software Foundation | |
4 | Condtributed by Cyngnus Solutions. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
19 | ||
20 | */ | |
21 | ||
22 | ||
23 | ||
24 | #include "sim-main.h" | |
25 | ||
26 | #include "idecode.h" | |
7b167b09 | 27 | #include "itable.h" |
15c16493 AC |
28 | |
29 | #include <signal.h> | |
30 | ||
d9b75947 AC |
31 | #ifdef HAVE_STRING_H |
32 | #include <string.h> | |
33 | #else | |
34 | #ifdef HAVE_STRINGS_H | |
35 | #include <strings.h> | |
36 | #endif | |
37 | #endif | |
38 | ||
15c16493 AC |
39 | void |
40 | engine_init (SIM_DESC sd) | |
41 | { | |
42 | memset (&STATE_CPU (sd, 0)->reg, 0, sizeof STATE_CPU (sd, 0)->reg); | |
43 | memset (&STATE_CPU (sd, 0)->cia, 0, sizeof STATE_CPU (sd, 0)->cia); | |
44 | CPU_STATE (STATE_CPU (sd, 0)) = sd; | |
45 | } | |
46 | ||
47 | ||
48 | /* Mechanisms for stopping/restarting the simulation */ | |
49 | ||
50 | void | |
51 | engine_error (SIM_DESC sd, | |
abe293a0 | 52 | sim_cpu *cpu, |
15c16493 AC |
53 | instruction_address cia, |
54 | const char *fmt, | |
55 | ...) | |
56 | { | |
57 | va_list ap; | |
58 | va_start (ap, fmt); | |
59 | sim_io_evprintf (sd, fmt, ap); | |
60 | va_end (ap); | |
61 | ||
62 | if (sd->halt_ok) | |
63 | { | |
d5e2c74e | 64 | sim_io_eprintf (sd, "\n"); |
9af5dcea | 65 | engine_halt (sd, cpu, cia, sim_stopped, SIGABRT); |
15c16493 AC |
66 | } |
67 | else | |
68 | sim_io_error (sd, " - aborting simulation"); | |
69 | } | |
70 | ||
71 | void | |
72 | engine_halt (SIM_DESC sd, | |
abe293a0 | 73 | sim_cpu *cpu, |
15c16493 AC |
74 | instruction_address cia, |
75 | enum sim_stop reason, | |
76 | int siggnal) | |
77 | { | |
78 | if (!sd->halt_ok) | |
79 | sim_io_error (sd, "engine_halt - bad longjmp"); | |
80 | sd->reason = reason; | |
81 | sd->siggnal = siggnal; | |
82 | sd->halt_ok = 0; | |
83 | sd->restart_ok = 0; | |
abe293a0 AC |
84 | if (cpu != NULL) |
85 | cpu->cia = cia; | |
15c16493 AC |
86 | longjmp (sd->path_to_halt, 1); |
87 | } | |
88 | ||
89 | void | |
90 | engine_restart (SIM_DESC sd, | |
abe293a0 | 91 | sim_cpu *cpu, |
15c16493 AC |
92 | instruction_address cia) |
93 | { | |
94 | if (!sd->restart_ok) | |
95 | sim_io_error (sd, "engine_restart - bad longjmp"); | |
96 | sd->restart_ok = 0; | |
abe293a0 | 97 | cpu->cia = cia; |
15c16493 AC |
98 | longjmp(sd->path_to_restart, 1); |
99 | } | |
100 | ||
101 | ||
102 | void | |
103 | engine_run_until_stop (SIM_DESC sd, | |
104 | volatile int *keep_running) | |
105 | { | |
106 | if (!setjmp (sd->path_to_halt)) | |
107 | { | |
108 | instruction_address cia; | |
abe293a0 | 109 | sim_cpu *cpu = STATE_CPU (sd, 0); |
15c16493 AC |
110 | sd->halt_ok = 1; |
111 | setjmp (sd->path_to_restart); | |
112 | sd->restart_ok = 1; | |
abe293a0 | 113 | cia = cpu->cia; |
15c16493 AC |
114 | do |
115 | { | |
84902350 AC |
116 | instruction_word insn = IMEM (cia); |
117 | cia = idecode_issue (sd, insn, cia); | |
15c16493 AC |
118 | } |
119 | while (*keep_running); | |
abe293a0 | 120 | engine_halt (sd, cpu, cia, sim_stopped, SIGINT); |
15c16493 AC |
121 | } |
122 | } | |
c445af5a AC |
123 | |
124 | ||
125 | void | |
126 | engine_step (SIM_DESC sd) | |
127 | { | |
128 | if (!setjmp (sd->path_to_halt)) | |
129 | { | |
130 | instruction_address cia; | |
84902350 | 131 | instruction_word insn; |
c445af5a AC |
132 | sim_cpu *cpu = STATE_CPU (sd, 0); |
133 | sd->halt_ok = 1; | |
134 | setjmp (sd->path_to_restart); | |
135 | sd->restart_ok = 1; | |
136 | cia = cpu->cia; | |
84902350 AC |
137 | insn = IMEM (cia); |
138 | cia = idecode_issue (sd, insn, cia); | |
c445af5a AC |
139 | engine_halt (sd, cpu, cia, sim_stopped, SIGTRAP); |
140 | } | |
141 | } |