1997-04-22 17:46:07 +00:00
|
|
|
/* This file is part of the GDB simulators.
|
|
|
|
|
|
|
|
Copyright (C) 1997, Free Software Foundation
|
|
|
|
Condtributed by Cyngnus Solutions.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "sim-main.h"
|
|
|
|
|
|
|
|
#include "idecode.h"
|
1997-05-06 19:27:57 +00:00
|
|
|
#include "itable.h"
|
1997-04-22 17:46:07 +00:00
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
1997-05-02 05:31:34 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#else
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
1997-04-22 17:46:07 +00:00
|
|
|
void
|
|
|
|
engine_init (SIM_DESC sd)
|
|
|
|
{
|
|
|
|
memset (&STATE_CPU (sd, 0)->reg, 0, sizeof STATE_CPU (sd, 0)->reg);
|
|
|
|
memset (&STATE_CPU (sd, 0)->cia, 0, sizeof STATE_CPU (sd, 0)->cia);
|
|
|
|
CPU_STATE (STATE_CPU (sd, 0)) = sd;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Mechanisms for stopping/restarting the simulation */
|
|
|
|
|
|
|
|
void
|
|
|
|
engine_error (SIM_DESC sd,
|
1997-04-24 12:06:27 +00:00
|
|
|
sim_cpu *cpu,
|
1997-04-22 17:46:07 +00:00
|
|
|
instruction_address cia,
|
|
|
|
const char *fmt,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start (ap, fmt);
|
|
|
|
sim_io_evprintf (sd, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
if (sd->halt_ok)
|
|
|
|
{
|
1997-04-29 08:41:15 +00:00
|
|
|
sim_io_eprintf (sd, "\n");
|
1997-05-12 08:33:56 +00:00
|
|
|
engine_halt (sd, cpu, cia, sim_stopped, SIGABRT);
|
1997-04-22 17:46:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
sim_io_error (sd, " - aborting simulation");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
engine_halt (SIM_DESC sd,
|
1997-04-24 12:06:27 +00:00
|
|
|
sim_cpu *cpu,
|
1997-04-22 17:46:07 +00:00
|
|
|
instruction_address cia,
|
|
|
|
enum sim_stop reason,
|
|
|
|
int siggnal)
|
|
|
|
{
|
|
|
|
if (!sd->halt_ok)
|
|
|
|
sim_io_error (sd, "engine_halt - bad longjmp");
|
|
|
|
sd->reason = reason;
|
|
|
|
sd->siggnal = siggnal;
|
|
|
|
sd->halt_ok = 0;
|
|
|
|
sd->restart_ok = 0;
|
1997-04-24 12:06:27 +00:00
|
|
|
if (cpu != NULL)
|
|
|
|
cpu->cia = cia;
|
1997-04-22 17:46:07 +00:00
|
|
|
longjmp (sd->path_to_halt, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
engine_restart (SIM_DESC sd,
|
1997-04-24 12:06:27 +00:00
|
|
|
sim_cpu *cpu,
|
1997-04-22 17:46:07 +00:00
|
|
|
instruction_address cia)
|
|
|
|
{
|
|
|
|
if (!sd->restart_ok)
|
|
|
|
sim_io_error (sd, "engine_restart - bad longjmp");
|
|
|
|
sd->restart_ok = 0;
|
1997-04-24 12:06:27 +00:00
|
|
|
cpu->cia = cia;
|
1997-04-22 17:46:07 +00:00
|
|
|
longjmp(sd->path_to_restart, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
engine_run_until_stop (SIM_DESC sd,
|
|
|
|
volatile int *keep_running)
|
|
|
|
{
|
|
|
|
if (!setjmp (sd->path_to_halt))
|
|
|
|
{
|
|
|
|
instruction_address cia;
|
1997-04-24 12:06:27 +00:00
|
|
|
sim_cpu *cpu = STATE_CPU (sd, 0);
|
1997-04-22 17:46:07 +00:00
|
|
|
sd->halt_ok = 1;
|
|
|
|
setjmp (sd->path_to_restart);
|
|
|
|
sd->restart_ok = 1;
|
1997-04-24 12:06:27 +00:00
|
|
|
cia = cpu->cia;
|
1997-04-22 17:46:07 +00:00
|
|
|
do
|
|
|
|
{
|
1997-05-13 13:57:49 +00:00
|
|
|
instruction_word insn = IMEM (cia);
|
|
|
|
cia = idecode_issue (sd, insn, cia);
|
1997-04-22 17:46:07 +00:00
|
|
|
}
|
|
|
|
while (*keep_running);
|
1997-04-24 12:06:27 +00:00
|
|
|
engine_halt (sd, cpu, cia, sim_stopped, SIGINT);
|
1997-04-22 17:46:07 +00:00
|
|
|
}
|
|
|
|
}
|
1997-05-12 04:57:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
engine_step (SIM_DESC sd)
|
|
|
|
{
|
|
|
|
if (!setjmp (sd->path_to_halt))
|
|
|
|
{
|
|
|
|
instruction_address cia;
|
1997-05-13 13:57:49 +00:00
|
|
|
instruction_word insn;
|
1997-05-12 04:57:49 +00:00
|
|
|
sim_cpu *cpu = STATE_CPU (sd, 0);
|
|
|
|
sd->halt_ok = 1;
|
|
|
|
setjmp (sd->path_to_restart);
|
|
|
|
sd->restart_ok = 1;
|
|
|
|
cia = cpu->cia;
|
1997-05-13 13:57:49 +00:00
|
|
|
insn = IMEM (cia);
|
|
|
|
cia = idecode_issue (sd, insn, cia);
|
1997-05-12 04:57:49 +00:00
|
|
|
engine_halt (sd, cpu, cia, sim_stopped, SIGTRAP);
|
|
|
|
}
|
|
|
|
}
|