sim: moxie: convert to nrun.o

This port already used a lot of common/ files, so cutting it over to
nrun.o and using a few more common objects is pretty straight forward.
This commit is contained in:
Mike Frysinger 2015-03-22 23:59:45 -04:00
parent 523ba8f92e
commit cc8ab1ded5
6 changed files with 201 additions and 189 deletions

View File

@ -1,3 +1,28 @@
2015-03-24 Mike Frysinger <vapier@gentoo.org>
* configure: Regenerate.
* configure.ac: Call SIM_AC_OPTION_WARNINGS.
* interp.c: Delete gdb/callback.h include. Add sim-options.h include.
(callback, myname, sim_kind): Delete.
(tracefile, tracine, TRACE): Move code together and add a TODO.
(struct moxie_regset): Add a TODO.
(cpu): Likewise.
(callback, issue_messages, sim_size, sim_write, sim_read, sim_trace,
sim_stop_reason, sim_stop, sim_info, sim_load, sim_set_callbacks):
Delete.
(set_initial_gprs): Change prototype to (void).
(free_state): New function.
(sim_open): Call sim_cpu_alloc_all, sim_parse_args, and
sim_analyze_program. Move set_initial_gprs to the end. Set
STATE_WATCHPOINTS pc data. Delete callback, myname, and
issue_messages. Call free_state on error.
(sim_create_inferior): Delete references to issue_messages and
set_initial_gprs.
* Makefile.in (SIM_RUN_OBJS, SIM_EXTRA_CFLAGS): Delete.
(SIM_OBJS): Change to $(SIM_NEW_COMMON_OBJS).
* sim-main.h (struct sim_state): Change cpu to a pointer array.
(STATE_CPU): Drop the &.
2015-03-24 Mike Frysinger <vapier@gentoo.org>
* Makefile.in (SIM_OBJS): Add sim-command.o.

View File

@ -1,7 +1,7 @@
# Makefile template for Configure for the moxie sim library.
# Copyright (C) 2008-2015 Free Software Foundation, Inc.
# Written by Anthony Green
#
#
# 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 3 of the License, or
@ -19,14 +19,15 @@
dtbdir = @datadir@/gdb/dtb
# Use the deprecated run frontend until we migrate to nrun.o
SIM_RUN_OBJS = run.o
SIM_EXTRA_CFLAGS = -DSIM_USE_DEPRECATED_RUN_FRONTEND
SIM_OBJS = interp.o sim-load.o sim-io.o sim-config.o sim-utils.o \
sim-options.o sim-module.o sim-core.o sim-endian.o sim-trace.o \
sim-engine.o sim-fpu.o sim-bits.o sim-profile.o sim-events.o \
sim-memopt.o sim-command.o
SIM_OBJS = \
$(SIM_NEW_COMMON_OBJS) \
interp.o \
sim-cpu.o \
sim-engine.o \
sim-hload.o \
sim-hrw.o \
sim-reason.o \
sim-stop.o
SIM_EXTRA_LIBS = -lm -lz
SIM_EXTRA_INSTALL = install-dtb

114
sim/moxie/configure vendored
View File

@ -765,6 +765,9 @@ enable_sim_alignment
enable_sim_hostendian
enable_sim_environment
enable_sim_inline
enable_werror
enable_build_warnings
enable_sim_build_warnings
'
ac_precious_vars='build_alias
host_alias
@ -1412,6 +1415,11 @@ Optional Features:
--enable-sim-hostendian=end Specify host byte endian orientation.
--enable-sim-environment=environment Specify mixed, user, virtual or operating environment.
--enable-sim-inline=inlines Specify which functions should be inlined.
--enable-werror treat compile warnings as errors
--enable-build-warnings enable build-time compiler warnings if gcc is used
--enable-sim-build-warnings
enable SIM specific build-time compiler warnings if
gcc is used
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
@ -12365,7 +12373,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 12368 "configure"
#line 12376 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@ -12471,7 +12479,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 12474 "configure"
#line 12482 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@ -13457,6 +13465,108 @@ fi
fi
# Check whether --enable-werror was given.
if test "${enable_werror+set}" = set; then :
enableval=$enable_werror; case "${enableval}" in
yes | y) ERROR_ON_WARNING="yes" ;;
no | n) ERROR_ON_WARNING="no" ;;
*) as_fn_error "bad value ${enableval} for --enable-werror" "$LINENO" 5 ;;
esac
fi
# Enable -Werror by default when using gcc
if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
ERROR_ON_WARNING=yes
fi
WERROR_CFLAGS=""
if test "${ERROR_ON_WARNING}" = yes ; then
# NOTE: Disabled in the sim dir due to most sims generating warnings.
# WERROR_CFLAGS="-Werror"
true
fi
build_warnings="-Wall -Wdeclaration-after-statement -Wpointer-arith \
-Wpointer-sign \
-Wno-unused -Wunused-value -Wunused-function \
-Wno-switch -Wno-char-subscripts -Wmissing-prototypes
-Wdeclaration-after-statement -Wempty-body -Wmissing-parameter-type \
-Wold-style-declaration -Wold-style-definition"
# Enable -Wno-format by default when using gcc on mingw since many
# GCC versions complain about %I64.
case "${host}" in
*-*-mingw32*) build_warnings="$build_warnings -Wno-format" ;;
*) build_warnings="$build_warnings -Wformat-nonliteral" ;;
esac
# Check whether --enable-build-warnings was given.
if test "${enable_build_warnings+set}" = set; then :
enableval=$enable_build_warnings; case "${enableval}" in
yes) ;;
no) build_warnings="-w";;
,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
build_warnings="${build_warnings} ${t}";;
*,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
build_warnings="${t} ${build_warnings}";;
*) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
esac
if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
echo "Setting compiler warning flags = $build_warnings" 6>&1
fi
fi
# Check whether --enable-sim-build-warnings was given.
if test "${enable_sim_build_warnings+set}" = set; then :
enableval=$enable_sim_build_warnings; case "${enableval}" in
yes) ;;
no) build_warnings="-w";;
,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
build_warnings="${build_warnings} ${t}";;
*,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
build_warnings="${t} ${build_warnings}";;
*) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
esac
if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
echo "Setting GDB specific compiler warning flags = $build_warnings" 6>&1
fi
fi
WARN_CFLAGS=""
if test "x${build_warnings}" != x -a "x$GCC" = xyes
then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking compiler warning flags" >&5
$as_echo_n "checking compiler warning flags... " >&6; }
# Separate out the -Werror flag as some files just cannot be
# compiled with it enabled.
for w in ${build_warnings}; do
case $w in
-Werr*) WERROR_CFLAGS=-Werror ;;
*) # Check that GCC accepts it
saved_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $w"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
WARN_CFLAGS="${WARN_CFLAGS} $w"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CFLAGS="$saved_CFLAGS"
esac
done
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${WARN_CFLAGS} ${WERROR_CFLAGS}" >&5
$as_echo "${WARN_CFLAGS} ${WERROR_CFLAGS}" >&6; }
fi
ac_sources="$sim_link_files"
ac_dests="$sim_link_links"

View File

@ -11,6 +11,7 @@ SIM_AC_OPTION_ENDIAN(BIG_ENDIAN)
SIM_AC_OPTION_ALIGNMENT(STRICT_ALIGNMENT)
SIM_AC_OPTION_HOSTENDIAN
SIM_AC_OPTION_ENVIRONMENT
SIM_AC_OPTION_INLINE()
SIM_AC_OPTION_INLINE
SIM_AC_OPTION_WARNINGS
SIM_AC_OUTPUT

View File

@ -26,20 +26,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <sys/param.h>
#include <unistd.h>
#include "bfd.h"
#include "gdb/callback.h"
#include "libiberty.h"
#include "gdb/remote-sim.h"
#include "sim-main.h"
#include "sim-base.h"
#include "sim-options.h"
typedef int word;
typedef unsigned int uword;
host_callback * callback;
FILE *tracefile;
/* Extract the signed 10-bit offset from a 16-bit branch
instruction. */
#define INST2OFFSET(o) ((((signed short)((o & ((1<<10)-1))<<6))>>6)<<1)
@ -117,6 +113,7 @@ static const char *reg_names[16] =
/* The ordering of the moxie_regset structure is matched in the
gdb/config/moxie/tm-moxie.h file in the REGISTER_NAMES macro. */
/* TODO: This should be moved to sim-main.h:_sim_cpu. */
struct moxie_regset
{
word regs[NUM_MOXIE_REGS + 1]; /* primary registers */
@ -132,23 +129,15 @@ struct moxie_regset
#define CC_GTU 1<<3
#define CC_LTU 1<<4
/* TODO: This should be moved to sim-main.h:_sim_cpu. */
union
{
struct moxie_regset asregs;
word asints [1]; /* but accessed larger... */
} cpu;
static char *myname;
static SIM_OPEN_KIND sim_kind;
static int issue_messages = 0;
void
sim_size (int s)
{
}
static void
set_initial_gprs ()
set_initial_gprs (void)
{
int i;
long space;
@ -246,10 +235,11 @@ convert_target_flags (unsigned int tflags)
return hflags;
}
/* TODO: Move to sim-trace.h. */
static FILE *tracefile;
static const int tracing = 0;
#define TRACE(str) if (tracing) fprintf(tracefile,"0x%08x, %s, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", opc, str, cpu.asregs.regs[0], cpu.asregs.regs[1], cpu.asregs.regs[2], cpu.asregs.regs[3], cpu.asregs.regs[4], cpu.asregs.regs[5], cpu.asregs.regs[6], cpu.asregs.regs[7], cpu.asregs.regs[8], cpu.asregs.regs[9], cpu.asregs.regs[10], cpu.asregs.regs[11], cpu.asregs.regs[12], cpu.asregs.regs[13], cpu.asregs.regs[14], cpu.asregs.regs[15]);
static int tracing = 0;
void
sim_resume (sd, step, siggnal)
SIM_DESC sd;
@ -1127,35 +1117,6 @@ sim_resume (sd, step, siggnal)
cpu.asregs.insts += insts; /* instructions done ... */
}
int
sim_write (sd, addr, buffer, size)
SIM_DESC sd;
SIM_ADDR addr;
const unsigned char * buffer;
int size;
{
sim_cpu *scpu = STATE_CPU (sd, 0); /* FIXME */
sim_core_write_buffer (sd, scpu, write_map, buffer, addr, size);
return size;
}
int
sim_read (sd, addr, buffer, size)
SIM_DESC sd;
SIM_ADDR addr;
unsigned char * buffer;
int size;
{
sim_cpu *scpu = STATE_CPU (sd, 0); /* FIXME */
sim_core_read_buffer (sd, scpu, read_map, buffer, addr, size);
return size;
}
int
sim_store_register (sd, rn, memory, length)
SIM_DESC sd;
@ -1203,61 +1164,15 @@ sim_fetch_register (sd, rn, memory, length)
return 0;
}
int
sim_trace (sd)
SIM_DESC sd;
static void
free_state (SIM_DESC sd)
{
if (tracefile == 0)
tracefile = fopen("trace.csv", "wb");
tracing = 1;
sim_resume (sd, 0, 0);
tracing = 0;
return 1;
if (STATE_MODULES (sd) != NULL)
sim_module_uninstall (sd);
sim_cpu_free_all (sd);
sim_state_free (sd);
}
void
sim_stop_reason (sd, reason, sigrc)
SIM_DESC sd;
enum sim_stop * reason;
int * sigrc;
{
if (cpu.asregs.exception == SIGQUIT)
{
* reason = sim_exited;
* sigrc = cpu.asregs.regs[2];
}
else
{
* reason = sim_stopped;
* sigrc = cpu.asregs.exception;
}
}
int
sim_stop (sd)
SIM_DESC sd;
{
cpu.asregs.exception = SIGINT;
return 1;
}
void
sim_info (sd, verbose)
SIM_DESC sd;
int verbose;
{
callback->printf_filtered (callback, "\n\n# instructions executed %llu\n",
cpu.asregs.insts);
}
SIM_DESC
sim_open (kind, cb, abfd, argv)
SIM_OPEN_KIND kind;
@ -1268,20 +1183,44 @@ sim_open (kind, cb, abfd, argv)
SIM_DESC sd = sim_state_alloc (kind, cb);
SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
/* The cpu data is kept in a separately allocated chunk of memory. */
if (sim_cpu_alloc_all (sd, 1, /*cgen_cpu_max_extra_bytes ()*/0) != SIM_RC_OK)
{
free_state (sd);
return 0;
}
STATE_WATCHPOINTS (sd)->pc = &cpu.asregs.regs[PC_REGNO];
STATE_WATCHPOINTS (sd)->sizeof_pc = sizeof (word);
if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK)
return 0;
{
free_state (sd);
return 0;
}
/* getopt will print the error message so we just have to exit if this fails.
FIXME: Hmmm... in the case of gdb we need getopt to call
print_filtered. */
if (sim_parse_args (sd, argv) != SIM_RC_OK)
{
free_state (sd);
return 0;
}
sim_do_command(sd," memory region 0x00000000,0x4000000") ;
sim_do_command(sd," memory region 0xE0000000,0x10000") ;
myname = argv[0];
callback = cb;
if (kind == SIM_OPEN_STANDALONE)
issue_messages = 1;
set_initial_gprs (); /* Reset the GPR registers. */
/* Check for/establish the a reference program image. */
if (sim_analyze_program (sd,
(STATE_PROG_ARGV (sd) != NULL
? *STATE_PROG_ARGV (sd)
: NULL), abfd) != SIM_RC_OK)
{
free_state (sd);
return 0;
}
/* Configure/verify the target byte order and other runtime
configuration options. */
if (sim_config (sd) != SIM_RC_OK)
@ -1298,6 +1237,9 @@ sim_open (kind, cb, abfd, argv)
return 0;
}
/* CPU specific initialization. */
set_initial_gprs ();
return sd;
}
@ -1338,60 +1280,6 @@ load_dtb (SIM_DESC sd, const char *filename)
fclose (f);
}
SIM_RC
sim_load (sd, prog, abfd, from_tty)
SIM_DESC sd;
const char * prog;
bfd * abfd;
int from_tty;
{
/* Do the right thing for ELF executables; this turns out to be
just about the right thing for any object format that:
- we crack using BFD routines
- follows the traditional UNIX text/data/bss layout
- calls the bss section ".bss". */
extern bfd * sim_load_file (); /* ??? Don't know where this should live. */
bfd * prog_bfd;
{
bfd * handle;
handle = bfd_openr (prog, 0); /* could be "moxie" */
if (!handle)
{
printf("``%s'' could not be opened.\n", prog);
return SIM_RC_FAIL;
}
/* Makes sure that we have an object file, also cleans gets the
section headers in place. */
if (!bfd_check_format (handle, bfd_object))
{
/* wasn't an object file */
bfd_close (handle);
printf ("``%s'' is not appropriate object file.\n", prog);
return SIM_RC_FAIL;
}
/* Clean up after ourselves. */
bfd_close (handle);
}
/* from sh -- dac */
prog_bfd = sim_load_file (sd, myname, callback, prog, abfd,
sim_kind == SIM_OPEN_DEBUG,
0, sim_write);
if (prog_bfd == NULL)
return SIM_RC_FAIL;
if (abfd == NULL)
bfd_close (prog_bfd);
return SIM_RC_OK;
}
SIM_RC
sim_create_inferior (sd, prog_bfd, argv, env)
SIM_DESC sd;
@ -1403,12 +1291,6 @@ sim_create_inferior (sd, prog_bfd, argv, env)
int l, argc, i, tp;
sim_cpu *scpu = STATE_CPU (sd, 0); /* FIXME */
/* Set the initial register set. */
l = issue_messages;
issue_messages = 0;
set_initial_gprs ();
issue_messages = l;
if (prog_bfd != NULL)
cpu.asregs.regs[PC_REGNO] = bfd_get_start_address (prog_bfd);
@ -1449,10 +1331,3 @@ sim_create_inferior (sd, prog_bfd, argv, env)
return SIM_RC_OK;
}
void
sim_set_callbacks (ptr)
host_callback * ptr;
{
callback = ptr;
}

View File

@ -48,11 +48,11 @@ struct _sim_cpu {
struct sim_state {
sim_cpu cpu[MAX_NR_PROCESSORS];
sim_cpu *cpu[MAX_NR_PROCESSORS];
#if (WITH_SMP)
#define STATE_CPU(sd,n) (&(sd)->cpu[n])
#define STATE_CPU(sd,n) ((sd)->cpu[n])
#else
#define STATE_CPU(sd,n) (&(sd)->cpu[0])
#define STATE_CPU(sd,n) ((sd)->cpu[0])
#endif
sim_state_base base;