Numerous fixes.
[deliverable/binutils-gdb.git] / sim / tic80 / interp.c
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 sim_cpu *cpu,
44 instruction_address cia,
45 const char *fmt,
46 ...)
47 {
48 va_list ap;
49 va_start (ap, fmt);
50 sim_io_evprintf (sd, fmt, ap);
51 va_end (ap);
52
53 if (sd->halt_ok)
54 {
55 sim_io_eprintf (sd, "\n");
56 engine_halt (sd, cpu, cia, sim_signalled, SIGABRT);
57 }
58 else
59 sim_io_error (sd, " - aborting simulation");
60 }
61
62 void
63 engine_halt (SIM_DESC sd,
64 sim_cpu *cpu,
65 instruction_address cia,
66 enum sim_stop reason,
67 int siggnal)
68 {
69 if (!sd->halt_ok)
70 sim_io_error (sd, "engine_halt - bad longjmp");
71 sd->reason = reason;
72 sd->siggnal = siggnal;
73 sd->halt_ok = 0;
74 sd->restart_ok = 0;
75 if (cpu != NULL)
76 cpu->cia = cia;
77 longjmp (sd->path_to_halt, 1);
78 }
79
80 void
81 engine_restart (SIM_DESC sd,
82 sim_cpu *cpu,
83 instruction_address cia)
84 {
85 if (!sd->restart_ok)
86 sim_io_error (sd, "engine_restart - bad longjmp");
87 sd->restart_ok = 0;
88 cpu->cia = cia;
89 longjmp(sd->path_to_restart, 1);
90 }
91
92
93 void
94 engine_run_until_stop (SIM_DESC sd,
95 volatile int *keep_running)
96 {
97 if (!setjmp (sd->path_to_halt))
98 {
99 instruction_address cia;
100 sim_cpu *cpu = STATE_CPU (sd, 0);
101 sd->halt_ok = 1;
102 setjmp (sd->path_to_restart);
103 sd->restart_ok = 1;
104 cia = cpu->cia;
105 do
106 {
107 if (cia.ip == -1)
108 {
109 /* anulled instruction */
110 cia.ip = cia.dp;
111 cia.dp = cia.dp + sizeof (instruction_word);
112 }
113 else
114 {
115 instruction_word insn = IMEM (cia.ip);
116 cia = idecode_issue (sd, insn, cia);
117 }
118 }
119 while (*keep_running);
120 engine_halt (sd, cpu, cia, sim_stopped, SIGINT);
121 }
122 }
This page took 0.031997 seconds and 5 git commands to generate.