Clear cntrl-c after handling it.
[deliverable/binutils-gdb.git] / sim / tic80 / interp.c
CommitLineData
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
39void
40engine_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
50void
51engine_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
71void
72engine_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
89void
90engine_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
102void
103engine_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 {
116 if (cia.ip == -1)
117 {
118 /* anulled instruction */
119 cia.ip = cia.dp;
120 cia.dp = cia.dp + sizeof (instruction_word);
121 }
122 else
123 {
124 instruction_word insn = IMEM (cia.ip);
125 cia = idecode_issue (sd, insn, cia);
126 }
127 }
128 while (*keep_running);
abe293a0 129 engine_halt (sd, cpu, cia, sim_stopped, SIGINT);
15c16493
AC
130 }
131}
c445af5a
AC
132
133
134void
135engine_step (SIM_DESC sd)
136{
137 if (!setjmp (sd->path_to_halt))
138 {
139 instruction_address cia;
140 sim_cpu *cpu = STATE_CPU (sd, 0);
141 sd->halt_ok = 1;
142 setjmp (sd->path_to_restart);
143 sd->restart_ok = 1;
144 cia = cpu->cia;
145 if (cia.ip == -1)
146 {
147 /* anulled instruction */
148 cia.ip = cia.dp;
149 cia.dp = cia.dp + sizeof (instruction_word);
150 }
151 else
152 {
153 instruction_word insn = IMEM (cia.ip);
154 cia = idecode_issue (sd, insn, cia);
155 }
156 engine_halt (sd, cpu, cia, sim_stopped, SIGTRAP);
157 }
158}
This page took 0.031267 seconds and 4 git commands to generate.