# Simulator main loop for CRIS. -*- C -*-
|
# Simulator main loop for CRIS. -*- C -*-
|
# Copyright (C) 2004, 2005, 2007, 2008, 2009, 2010
|
# Copyright (C) 2004, 2005, 2007, 2008, 2009, 2010
|
# Free Software Foundation, Inc.
|
# Free Software Foundation, Inc.
|
# Contributed by Axis Communications.
|
# Contributed by Axis Communications.
|
#
|
#
|
# This file is part of the GNU simulators.
|
# This file is part of the GNU simulators.
|
#
|
#
|
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
# the Free Software Foundation; either version 3 of the License, or
|
# the Free Software Foundation; either version 3 of the License, or
|
# (at your option) any later version.
|
# (at your option) any later version.
|
#
|
#
|
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
#
|
#
|
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
# along with this program. If not, see .
|
# along with this program. If not, see .
|
|
|
# Based on the fr30 file.
|
# Based on the fr30 file.
|
|
|
# Syntax:
|
# Syntax:
|
# /bin/sh mainloop.in command
|
# /bin/sh mainloop.in command
|
#
|
#
|
# Command is one of:
|
# Command is one of:
|
#
|
#
|
# init
|
# init
|
# support
|
# support
|
# extract-{simple,scache,pbb}
|
# extract-{simple,scache,pbb}
|
# {full,fast}-exec-{simple,scache,pbb}
|
# {full,fast}-exec-{simple,scache,pbb}
|
#
|
#
|
# A target need only provide a "full" version of one of simple,scache,pbb.
|
# A target need only provide a "full" version of one of simple,scache,pbb.
|
# If the target wants it can also provide a fast version of same.
|
# If the target wants it can also provide a fast version of same.
|
# It can't provide more than this, however for illustration's sake the CRIS
|
# It can't provide more than this, however for illustration's sake the CRIS
|
# port provides examples of all.
|
# port provides examples of all.
|
|
|
# ??? After a few more ports are done, revisit.
|
# ??? After a few more ports are done, revisit.
|
# Will eventually need to machine generate a lot of this.
|
# Will eventually need to machine generate a lot of this.
|
|
|
case "x$1" in
|
case "x$1" in
|
|
|
xsupport)
|
xsupport)
|
|
|
cat <
|
cat <
|
/* It seems we don't have a templated header file corresponding to
|
/* It seems we don't have a templated header file corresponding to
|
cris-tmpl.c, so we have to get out declarations the hackish way. */
|
cris-tmpl.c, so we have to get out declarations the hackish way. */
|
extern void @cpu@_specific_init (SIM_CPU *current_cpu);
|
extern void @cpu@_specific_init (SIM_CPU *current_cpu);
|
|
|
static INLINE const IDESC *
|
static INLINE const IDESC *
|
extract (SIM_CPU *current_cpu, PCADDR pc, CGEN_INSN_INT insn, ARGBUF *abuf,
|
extract (SIM_CPU *current_cpu, PCADDR pc, CGEN_INSN_INT insn, ARGBUF *abuf,
|
int fast_p)
|
int fast_p)
|
{
|
{
|
const IDESC *id = @cpu@_decode (current_cpu, pc, insn,
|
const IDESC *id = @cpu@_decode (current_cpu, pc, insn,
|
#if CGEN_INT_INSN_P
|
#if CGEN_INT_INSN_P
|
insn,
|
insn,
|
#endif
|
#endif
|
abuf);
|
abuf);
|
@cpu@_fill_argbuf (current_cpu, abuf, id, pc, fast_p);
|
@cpu@_fill_argbuf (current_cpu, abuf, id, pc, fast_p);
|
if (! fast_p)
|
if (! fast_p)
|
{
|
{
|
int trace_p = PC_IN_TRACE_RANGE_P (current_cpu, pc);
|
int trace_p = PC_IN_TRACE_RANGE_P (current_cpu, pc);
|
int profile_p = PC_IN_PROFILE_RANGE_P (current_cpu, pc);
|
int profile_p = PC_IN_PROFILE_RANGE_P (current_cpu, pc);
|
@cpu@_fill_argbuf_tp (current_cpu, abuf, trace_p, profile_p);
|
@cpu@_fill_argbuf_tp (current_cpu, abuf, trace_p, profile_p);
|
}
|
}
|
return id;
|
return id;
|
}
|
}
|
|
|
static INLINE SEM_PC
|
static INLINE SEM_PC
|
execute (SIM_CPU *current_cpu, SCACHE *sc, int fast_p)
|
execute (SIM_CPU *current_cpu, SCACHE *sc, int fast_p)
|
{
|
{
|
SEM_PC vpc;
|
SEM_PC vpc;
|
|
|
if (fast_p)
|
if (fast_p)
|
{
|
{
|
#if ! WITH_SEM_SWITCH_FAST
|
#if ! WITH_SEM_SWITCH_FAST
|
#if WITH_SCACHE
|
#if WITH_SCACHE
|
vpc = (*sc->argbuf.semantic.sem_fast) (current_cpu, sc);
|
vpc = (*sc->argbuf.semantic.sem_fast) (current_cpu, sc);
|
#else
|
#else
|
vpc = (*sc->argbuf.semantic.sem_fast) (current_cpu, &sc->argbuf);
|
vpc = (*sc->argbuf.semantic.sem_fast) (current_cpu, &sc->argbuf);
|
#endif
|
#endif
|
#else
|
#else
|
abort ();
|
abort ();
|
#endif /* WITH_SEM_SWITCH_FAST */
|
#endif /* WITH_SEM_SWITCH_FAST */
|
}
|
}
|
else
|
else
|
{
|
{
|
#if ! WITH_SEM_SWITCH_FULL
|
#if ! WITH_SEM_SWITCH_FULL
|
ARGBUF *abuf = &sc->argbuf;
|
ARGBUF *abuf = &sc->argbuf;
|
const IDESC *idesc = abuf->idesc;
|
const IDESC *idesc = abuf->idesc;
|
#if WITH_SCACHE_PBB
|
#if WITH_SCACHE_PBB
|
int virtual_p = CGEN_ATTR_VALUE (NULL, idesc->attrs, CGEN_INSN_VIRTUAL);
|
int virtual_p = CGEN_ATTR_VALUE (NULL, idesc->attrs, CGEN_INSN_VIRTUAL);
|
#else
|
#else
|
int virtual_p = 0;
|
int virtual_p = 0;
|
#endif
|
#endif
|
|
|
if (! virtual_p)
|
if (! virtual_p)
|
{
|
{
|
/* FIXME: call x-before */
|
/* FIXME: call x-before */
|
if (ARGBUF_PROFILE_P (abuf))
|
if (ARGBUF_PROFILE_P (abuf))
|
PROFILE_COUNT_INSN (current_cpu, abuf->addr, idesc->num);
|
PROFILE_COUNT_INSN (current_cpu, abuf->addr, idesc->num);
|
/* FIXME: Later make cover macros: PROFILE_INSN_{INIT,FINI}. */
|
/* FIXME: Later make cover macros: PROFILE_INSN_{INIT,FINI}. */
|
if (PROFILE_MODEL_P (current_cpu)
|
if (PROFILE_MODEL_P (current_cpu)
|
&& ARGBUF_PROFILE_P (abuf))
|
&& ARGBUF_PROFILE_P (abuf))
|
@cpu@_model_insn_before (current_cpu, 1 /*first_p*/);
|
@cpu@_model_insn_before (current_cpu, 1 /*first_p*/);
|
TRACE_INSN_INIT (current_cpu, abuf, 1);
|
TRACE_INSN_INIT (current_cpu, abuf, 1);
|
TRACE_INSN (current_cpu, idesc->idata,
|
TRACE_INSN (current_cpu, idesc->idata,
|
(const struct argbuf *) abuf, abuf->addr);
|
(const struct argbuf *) abuf, abuf->addr);
|
}
|
}
|
#if WITH_SCACHE
|
#if WITH_SCACHE
|
vpc = (*sc->argbuf.semantic.sem_full) (current_cpu, sc);
|
vpc = (*sc->argbuf.semantic.sem_full) (current_cpu, sc);
|
#else
|
#else
|
vpc = (*sc->argbuf.semantic.sem_full) (current_cpu, abuf);
|
vpc = (*sc->argbuf.semantic.sem_full) (current_cpu, abuf);
|
#endif
|
#endif
|
if (! virtual_p)
|
if (! virtual_p)
|
{
|
{
|
/* FIXME: call x-after */
|
/* FIXME: call x-after */
|
if (PROFILE_MODEL_P (current_cpu)
|
if (PROFILE_MODEL_P (current_cpu)
|
&& ARGBUF_PROFILE_P (abuf))
|
&& ARGBUF_PROFILE_P (abuf))
|
{
|
{
|
int cycles;
|
int cycles;
|
|
|
cycles = (*idesc->timing->model_fn) (current_cpu, sc);
|
cycles = (*idesc->timing->model_fn) (current_cpu, sc);
|
@cpu@_model_insn_after (current_cpu, 1 /*last_p*/, cycles);
|
@cpu@_model_insn_after (current_cpu, 1 /*last_p*/, cycles);
|
}
|
}
|
TRACE_INSN_FINI (current_cpu, abuf, 1);
|
TRACE_INSN_FINI (current_cpu, abuf, 1);
|
}
|
}
|
#else
|
#else
|
abort ();
|
abort ();
|
#endif /* WITH_SEM_SWITCH_FULL */
|
#endif /* WITH_SEM_SWITCH_FULL */
|
}
|
}
|
|
|
return vpc;
|
return vpc;
|
}
|
}
|
|
|
EOF
|
EOF
|
|
|
;;
|
;;
|
|
|
xinit)
|
xinit)
|
|
|
cat <
|
cat <
|
/* This seemed the only sane location to emit a call to a
|
/* This seemed the only sane location to emit a call to a
|
model-specific init function. It may not work for all simulator
|
model-specific init function. It may not work for all simulator
|
types. FIXME: Introduce a model-init hook. */
|
types. FIXME: Introduce a model-init hook. */
|
|
|
/* We use the same condition as the code that's expected to follow, so
|
/* We use the same condition as the code that's expected to follow, so
|
GCC can consolidate the code with only one conditional. */
|
GCC can consolidate the code with only one conditional. */
|
if (! CPU_IDESC_SEM_INIT_P (current_cpu))
|
if (! CPU_IDESC_SEM_INIT_P (current_cpu))
|
@cpu@_specific_init (current_cpu);
|
@cpu@_specific_init (current_cpu);
|
EOF
|
EOF
|
|
|
;;
|
;;
|
|
|
xextract-simple | xextract-scache)
|
xextract-simple | xextract-scache)
|
|
|
# Inputs: current_cpu, vpc, sc, FAST_P
|
# Inputs: current_cpu, vpc, sc, FAST_P
|
# Outputs: sc filled in
|
# Outputs: sc filled in
|
|
|
cat <
|
cat <
|
{
|
{
|
CGEN_INSN_INT insn = GETIMEMUHI (current_cpu, vpc);
|
CGEN_INSN_INT insn = GETIMEMUHI (current_cpu, vpc);
|
extract (current_cpu, vpc, insn, SEM_ARGBUF (sc), FAST_P);
|
extract (current_cpu, vpc, insn, SEM_ARGBUF (sc), FAST_P);
|
}
|
}
|
EOF
|
EOF
|
|
|
;;
|
;;
|
|
|
xextract-pbb)
|
xextract-pbb)
|
|
|
# Inputs: current_cpu, pc, sc, max_insns, FAST_P
|
# Inputs: current_cpu, pc, sc, max_insns, FAST_P
|
# Outputs: sc, pc
|
# Outputs: sc, pc
|
# sc must be left pointing past the last created entry.
|
# sc must be left pointing past the last created entry.
|
# pc must be left pointing past the last created entry.
|
# pc must be left pointing past the last created entry.
|
# If the pbb is terminated by a cti insn, SET_CTI_VPC(sc) must be called
|
# If the pbb is terminated by a cti insn, SET_CTI_VPC(sc) must be called
|
# to record the vpc of the cti insn.
|
# to record the vpc of the cti insn.
|
# SET_INSN_COUNT(n) must be called to record number of real insns.
|
# SET_INSN_COUNT(n) must be called to record number of real insns.
|
|
|
cat <
|
cat <
|
{
|
{
|
const IDESC *idesc;
|
const IDESC *idesc;
|
int icount = 0;
|
int icount = 0;
|
|
|
/* Make sure the buffer doesn't overflow for profiled insns if
|
/* Make sure the buffer doesn't overflow for profiled insns if
|
max_insns happens to not be a multiple of 3. */
|
max_insns happens to not be a multiple of 3. */
|
if (!FAST_P)
|
if (!FAST_P)
|
max_insns -= 2 + 3;
|
max_insns -= 2 + 3;
|
else
|
else
|
/* There might be two real insns handled per loop. */
|
/* There might be two real insns handled per loop. */
|
max_insns--;
|
max_insns--;
|
|
|
while (max_insns > 0)
|
while (max_insns > 0)
|
{
|
{
|
UHI insn = GETIMEMUHI (current_cpu, pc);
|
UHI insn = GETIMEMUHI (current_cpu, pc);
|
int trace_p = PC_IN_TRACE_RANGE_P (current_cpu, pc);
|
int trace_p = PC_IN_TRACE_RANGE_P (current_cpu, pc);
|
int profile_p = PC_IN_PROFILE_RANGE_P (current_cpu, pc);
|
int profile_p = PC_IN_PROFILE_RANGE_P (current_cpu, pc);
|
int befaft_p = profile_p || trace_p;
|
int befaft_p = profile_p || trace_p;
|
|
|
if (befaft_p)
|
if (befaft_p)
|
{
|
{
|
@cpu@_emit_before (current_cpu, sc, pc, 1);
|
@cpu@_emit_before (current_cpu, sc, pc, 1);
|
++sc;
|
++sc;
|
sc->argbuf.trace_p = trace_p;
|
sc->argbuf.trace_p = trace_p;
|
sc->argbuf.profile_p = profile_p;
|
sc->argbuf.profile_p = profile_p;
|
--max_insns;
|
--max_insns;
|
}
|
}
|
|
|
idesc = extract (current_cpu, pc, insn, &sc->argbuf, FAST_P);
|
idesc = extract (current_cpu, pc, insn, &sc->argbuf, FAST_P);
|
++sc;
|
++sc;
|
--max_insns;
|
--max_insns;
|
++icount;
|
++icount;
|
|
|
if (befaft_p)
|
if (befaft_p)
|
{
|
{
|
@cpu@_emit_after (current_cpu, sc, pc);
|
@cpu@_emit_after (current_cpu, sc, pc);
|
++sc;
|
++sc;
|
--max_insns;
|
--max_insns;
|
}
|
}
|
|
|
pc += idesc->length;
|
pc += idesc->length;
|
|
|
if (IDESC_CTI_P (idesc))
|
if (IDESC_CTI_P (idesc))
|
{
|
{
|
SET_CTI_VPC (sc - 1);
|
SET_CTI_VPC (sc - 1);
|
|
|
/* Delay slot? Ignore for zero-instructions (bcc .+2) since
|
/* Delay slot? Ignore for zero-instructions (bcc .+2) since
|
those are treated as exit insns to avoid runaway sessions
|
those are treated as exit insns to avoid runaway sessions
|
for invalid programs. */
|
for invalid programs. */
|
if (insn != 0 && CGEN_ATTR_VALUE (NULL, idesc->attrs, CGEN_INSN_DELAY_SLOT))
|
if (insn != 0 && CGEN_ATTR_VALUE (NULL, idesc->attrs, CGEN_INSN_DELAY_SLOT))
|
{
|
{
|
UHI insn;
|
UHI insn;
|
trace_p = PC_IN_TRACE_RANGE_P (current_cpu, pc);
|
trace_p = PC_IN_TRACE_RANGE_P (current_cpu, pc);
|
profile_p = PC_IN_PROFILE_RANGE_P (current_cpu, pc);
|
profile_p = PC_IN_PROFILE_RANGE_P (current_cpu, pc);
|
befaft_p = profile_p || trace_p;
|
befaft_p = profile_p || trace_p;
|
|
|
if (befaft_p)
|
if (befaft_p)
|
{
|
{
|
@cpu@_emit_before (current_cpu, sc, pc, 1);
|
@cpu@_emit_before (current_cpu, sc, pc, 1);
|
++sc;
|
++sc;
|
sc->argbuf.trace_p = trace_p;
|
sc->argbuf.trace_p = trace_p;
|
sc->argbuf.profile_p = profile_p;
|
sc->argbuf.profile_p = profile_p;
|
--max_insns;
|
--max_insns;
|
}
|
}
|
|
|
insn = GETIMEMUHI (current_cpu, pc);
|
insn = GETIMEMUHI (current_cpu, pc);
|
idesc = extract (current_cpu, pc, insn, &sc->argbuf, FAST_P);
|
idesc = extract (current_cpu, pc, insn, &sc->argbuf, FAST_P);
|
++sc;
|
++sc;
|
--max_insns;
|
--max_insns;
|
++icount;
|
++icount;
|
|
|
if (befaft_p)
|
if (befaft_p)
|
{
|
{
|
@cpu@_emit_after (current_cpu, sc, pc);
|
@cpu@_emit_after (current_cpu, sc, pc);
|
++sc;
|
++sc;
|
--max_insns;
|
--max_insns;
|
}
|
}
|
pc += idesc->length;
|
pc += idesc->length;
|
}
|
}
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
Finish:
|
Finish:
|
SET_INSN_COUNT (icount);
|
SET_INSN_COUNT (icount);
|
}
|
}
|
EOF
|
EOF
|
|
|
;;
|
;;
|
|
|
xfull-exec-* | xfast-exec-*)
|
xfull-exec-* | xfast-exec-*)
|
|
|
# Inputs: current_cpu, sc, FAST_P
|
# Inputs: current_cpu, sc, FAST_P
|
# Outputs: vpc
|
# Outputs: vpc
|
# vpc contains the address of the next insn to execute
|
# vpc contains the address of the next insn to execute
|
|
|
cat <
|
cat <
|
{
|
{
|
#if (! FAST_P && WITH_SEM_SWITCH_FULL) || (FAST_P && WITH_SEM_SWITCH_FAST)
|
#if (! FAST_P && WITH_SEM_SWITCH_FULL) || (FAST_P && WITH_SEM_SWITCH_FAST)
|
#define DEFINE_SWITCH
|
#define DEFINE_SWITCH
|
#include "sem@cpu@-switch.c"
|
#include "sem@cpu@-switch.c"
|
#else
|
#else
|
vpc = execute (current_cpu, vpc, FAST_P);
|
vpc = execute (current_cpu, vpc, FAST_P);
|
#endif
|
#endif
|
}
|
}
|
EOF
|
EOF
|
|
|
;;
|
;;
|
|
|
*)
|
*)
|
echo "Invalid argument to mainloop.in: $1" >&2
|
echo "Invalid argument to mainloop.in: $1" >&2
|
exit 1
|
exit 1
|
;;
|
;;
|
|
|
esac
|
esac
|
|
|