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" | |
27 | ||
28 | #include <signal.h> | |
29 | ||
30 | void | |
31 | engine_init (SIM_DESC sd) | |
32 | { | |
33 | memset (&STATE_CPU (sd, 0)->reg, 0, sizeof STATE_CPU (sd, 0)->reg); | |
34 | memset (&STATE_CPU (sd, 0)->cia, 0, sizeof STATE_CPU (sd, 0)->cia); | |
35 | CPU_STATE (STATE_CPU (sd, 0)) = sd; | |
36 | } | |
37 | ||
38 | ||
39 | /* Mechanisms for stopping/restarting the simulation */ | |
40 | ||
41 | void | |
42 | engine_error (SIM_DESC sd, | |
43 | instruction_address cia, | |
44 | const char *fmt, | |
45 | ...) | |
46 | { | |
47 | va_list ap; | |
48 | va_start (ap, fmt); | |
49 | sim_io_evprintf (sd, fmt, ap); | |
50 | va_end (ap); | |
51 | ||
52 | if (sd->halt_ok) | |
53 | { | |
54 | sim_io_printf (sd, "\n"); | |
55 | engine_halt (sd, cia, sim_signalled, SIGABRT); | |
56 | } | |
57 | else | |
58 | sim_io_error (sd, " - aborting simulation"); | |
59 | } | |
60 | ||
61 | void | |
62 | engine_halt (SIM_DESC sd, | |
63 | instruction_address cia, | |
64 | enum sim_stop reason, | |
65 | int siggnal) | |
66 | { | |
67 | if (!sd->halt_ok) | |
68 | sim_io_error (sd, "engine_halt - bad longjmp"); | |
69 | sd->reason = reason; | |
70 | sd->siggnal = siggnal; | |
71 | sd->halt_ok = 0; | |
72 | sd->restart_ok = 0; | |
73 | sd->cpu.cia = cia; | |
74 | longjmp (sd->path_to_halt, 1); | |
75 | } | |
76 | ||
77 | void | |
78 | engine_restart (SIM_DESC sd, | |
79 | instruction_address cia) | |
80 | { | |
81 | if (!sd->restart_ok) | |
82 | sim_io_error (sd, "engine_restart - bad longjmp"); | |
83 | sd->restart_ok = 0; | |
84 | sd->cpu.cia = cia; | |
85 | longjmp(sd->path_to_restart, 1); | |
86 | } | |
87 | ||
88 | ||
89 | void | |
90 | engine_run_until_stop (SIM_DESC sd, | |
91 | volatile int *keep_running) | |
92 | { | |
93 | if (!setjmp (sd->path_to_halt)) | |
94 | { | |
95 | instruction_address cia; | |
96 | sd->halt_ok = 1; | |
97 | setjmp (sd->path_to_restart); | |
98 | sd->restart_ok = 1; | |
99 | cia = STATE_CPU (sd, 0)->cia; | |
100 | do | |
101 | { | |
102 | if (cia.ip == -1) | |
103 | { | |
104 | /* anulled instruction */ | |
105 | cia.ip = cia.dp; | |
106 | cia.dp = cia.dp + sizeof (instruction_word); | |
107 | } | |
108 | else | |
109 | { | |
110 | instruction_word insn = IMEM (cia.ip); | |
111 | cia = idecode_issue (sd, insn, cia); | |
112 | } | |
113 | } | |
114 | while (*keep_running); | |
115 | engine_halt (sd, cia, sim_stopped, SIGINT); | |
116 | } | |
117 | } |