* interp.c: Improve hashing routine to avoid long list
[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"
27
28#include <signal.h>
29
d9b75947
AC
30#ifdef HAVE_STRING_H
31#include <string.h>
32#else
33#ifdef HAVE_STRINGS_H
34#include <strings.h>
35#endif
36#endif
37
15c16493
AC
38void
39engine_init (SIM_DESC sd)
40{
41 memset (&STATE_CPU (sd, 0)->reg, 0, sizeof STATE_CPU (sd, 0)->reg);
42 memset (&STATE_CPU (sd, 0)->cia, 0, sizeof STATE_CPU (sd, 0)->cia);
43 CPU_STATE (STATE_CPU (sd, 0)) = sd;
44}
45
46
47/* Mechanisms for stopping/restarting the simulation */
48
49void
50engine_error (SIM_DESC sd,
abe293a0 51 sim_cpu *cpu,
15c16493
AC
52 instruction_address cia,
53 const char *fmt,
54 ...)
55{
56 va_list ap;
57 va_start (ap, fmt);
58 sim_io_evprintf (sd, fmt, ap);
59 va_end (ap);
60
61 if (sd->halt_ok)
62 {
d5e2c74e 63 sim_io_eprintf (sd, "\n");
abe293a0 64 engine_halt (sd, cpu, cia, sim_signalled, SIGABRT);
15c16493
AC
65 }
66 else
67 sim_io_error (sd, " - aborting simulation");
68}
69
70void
71engine_halt (SIM_DESC sd,
abe293a0 72 sim_cpu *cpu,
15c16493
AC
73 instruction_address cia,
74 enum sim_stop reason,
75 int siggnal)
76{
77 if (!sd->halt_ok)
78 sim_io_error (sd, "engine_halt - bad longjmp");
79 sd->reason = reason;
80 sd->siggnal = siggnal;
81 sd->halt_ok = 0;
82 sd->restart_ok = 0;
abe293a0
AC
83 if (cpu != NULL)
84 cpu->cia = cia;
15c16493
AC
85 longjmp (sd->path_to_halt, 1);
86}
87
88void
89engine_restart (SIM_DESC sd,
abe293a0 90 sim_cpu *cpu,
15c16493
AC
91 instruction_address cia)
92{
93 if (!sd->restart_ok)
94 sim_io_error (sd, "engine_restart - bad longjmp");
95 sd->restart_ok = 0;
abe293a0 96 cpu->cia = cia;
15c16493
AC
97 longjmp(sd->path_to_restart, 1);
98}
99
100
101void
102engine_run_until_stop (SIM_DESC sd,
103 volatile int *keep_running)
104{
105 if (!setjmp (sd->path_to_halt))
106 {
107 instruction_address cia;
abe293a0 108 sim_cpu *cpu = STATE_CPU (sd, 0);
15c16493
AC
109 sd->halt_ok = 1;
110 setjmp (sd->path_to_restart);
111 sd->restart_ok = 1;
abe293a0 112 cia = cpu->cia;
15c16493
AC
113 do
114 {
115 if (cia.ip == -1)
116 {
117 /* anulled instruction */
118 cia.ip = cia.dp;
119 cia.dp = cia.dp + sizeof (instruction_word);
120 }
121 else
122 {
123 instruction_word insn = IMEM (cia.ip);
124 cia = idecode_issue (sd, insn, cia);
125 }
126 }
127 while (*keep_running);
abe293a0 128 engine_halt (sd, cpu, cia, sim_stopped, SIGINT);
15c16493
AC
129 }
130}
This page took 0.028589 seconds and 4 git commands to generate.