sim: d10v: convert to nrun

A lot of cpu state is stored in global variables, as is memory handling.
The sim_size support needs unwinding at some point.  But at least this
is an improvement on the status quo.
This commit is contained in:
Mike Frysinger 2015-03-30 02:05:33 -04:00
parent a87686e5aa
commit 541ebcee67
7 changed files with 121 additions and 130 deletions

View File

@ -1,3 +1,24 @@
2015-03-30 Mike Frysinger <vapier@gentoo.org>
* d10v_sim.h (text, text_start, text_end, prog_bfd): Delete.
(SEXT8, SEXT16, SEXT32, MASK32): Undefine.
* interp.c: Delete run-sim.h and d10v_sim.h includes. Include
sim-main.h and sim-options.h.
(myname, sim_kind, init_text_p, prog_bfd_was_opened_p, prog_bfd,
text, text_start, text_end, decode_pc, sim_set_profile,
sim_set_profile_size, sim_set_trace, sim_set_callbacks,
sim_trace, sim_do_command, sim_load): Delete.
(INLINE): Delete define.
(free_state): New function.
(trace_sd): Declare global variable.
(sim_open): Rewrite to use new common logic.
(sim_close): Delete body.
* Makefile.in (SIM_RUN_OBJS, SIM_EXTRA_CFLAGS): Delete.
(SIM_OBJS): Change to $(SIM_NEW_COMMON_OBJS).
* sim-main.h: New file.
* simops.c: Change d10v_sim.h include to sim-main.h.
(trace_input_func): Rewrite pc checks to use trace_sd.
2015-03-30 Mike Frysinger <vapier@gentoo.org>
* Makefile.in (SIM_EXTRA_CFLAGS): Delete -DNEED_UI_LOOP_HOOK.

View File

@ -1,7 +1,7 @@
# Makefile template for Configure for the D10v sim library.
# Copyright (C) 1996-2015 Free Software Foundation, Inc.
# Written by Cygnus Support.
#
#
# 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
@ -17,12 +17,16 @@
## COMMON_PRE_CONFIG_FRAG
# Use the deprecated run frontend until we migrate to nrun.o
SIM_RUN_OBJS = run.o
SIM_OBJS = interp.o table.o simops.o endian.o sim-load.o
SIM_OBJS = \
interp.o \
$(SIM_NEW_COMMON_OBJS) \
sim-cpu.o \
sim-engine.o \
sim-hload.o \
table.o \
simops.o \
endian.o
SIM_EXTRA_CLEAN = clean-extra
SIM_EXTRA_CFLAGS = -DSIM_HAVE_ENVIRONMENT -DSIM_USE_DEPRECATED_RUN_FRONTEND
INCLUDE = d10v_sim.h $(srcroot)/include/gdb/callback.h targ-vals.h endian.c \
$(srcroot)/include/gdb/sim-d10v.h

View File

@ -278,10 +278,6 @@ struct _state
extern host_callback *d10v_callback;
extern uint16 OP[4];
extern struct simops Simops[];
extern asection *text;
extern bfd_vma text_start;
extern bfd_vma text_end;
extern bfd *prog_bfd;
enum
{
@ -397,6 +393,12 @@ enum
#define SIG_D10V_EXIT -2
#define SIG_D10V_BUS -3
/* TODO: Resolve conflicts with common headers. */
#undef SEXT8
#undef SEXT16
#undef SEXT32
#undef MASK32
#define SEXT3(x) ((((x)&0x7)^(~3))+4)
/* sign-extend a 4-bit number */

View File

@ -4,9 +4,10 @@
#include "bfd.h"
#include "gdb/callback.h"
#include "gdb/remote-sim.h"
#include "run-sim.h"
#include "d10v_sim.h"
#include "sim-main.h"
#include "sim-options.h"
#include "gdb/sim-d10v.h"
#include "gdb/signals.h"
@ -24,8 +25,6 @@
enum _leftright { LEFT_FIRST, RIGHT_FIRST };
static char *myname;
static SIM_OPEN_KIND sim_kind;
int d10v_debug;
/* Set this to true to get the previous segment layout. */
@ -37,14 +36,6 @@ unsigned long ins_type_counters[ (int)INS_MAX ];
uint16 OP[4];
static int init_text_p = 0;
/* non-zero if we opened prog_bfd */
static int prog_bfd_was_opened_p;
bfd *prog_bfd;
asection *text;
bfd_vma text_start;
bfd_vma text_end;
static long hash (long insn, int format);
static struct hash_entry *lookup_hash (uint32 ins, int size);
static void get_operands (struct simops *s, uint32 ins);
@ -56,14 +47,6 @@ extern void sim_set_profile (int n);
extern void sim_set_profile_size (int n);
static INLINE uint8 *map_memory (unsigned phys_addr);
#ifndef INLINE
#if defined(__GNUC__) && defined(__OPTIMIZE__)
#define INLINE __inline__
#else
#define INLINE
#endif
#endif
#define MAX_HASH 63
struct hash_entry
{
@ -126,26 +109,6 @@ get_operands (struct simops *s, uint32 ins)
State.trace.psw = PSW;
}
bfd_vma
decode_pc (void)
{
asection *s;
if (!init_text_p && prog_bfd != NULL)
{
init_text_p = 1;
for (s = prog_bfd->sections; s; s = s->next)
if (strcmp (bfd_get_section_name (prog_bfd, s), ".text") == 0)
{
text = s;
text_start = bfd_get_section_vma (prog_bfd, s);
text_end = text_start + bfd_section_size (prog_bfd, s);
break;
}
}
return (PC << 2) + text_start;
}
static void
do_long (uint32 ins)
{
@ -761,18 +724,77 @@ sim_read (SIM_DESC sd, SIM_ADDR addr, unsigned char *buffer, int size)
return xfer_mem( addr, buffer, size, 0);
}
static void
free_state (SIM_DESC sd)
{
if (STATE_MODULES (sd) != NULL)
sim_module_uninstall (sd);
sim_cpu_free_all (sd);
sim_state_free (sd);
}
SIM_DESC trace_sd = NULL;
SIM_DESC
sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd, char **argv)
sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
{
struct simops *s;
struct hash_entry *h;
static int init_p = 0;
char **p;
SIM_DESC sd = sim_state_alloc (kind, cb);
SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
sim_kind = kind;
d10v_callback = callback;
myname = argv[0];
/* 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;
}
if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK)
{
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;
}
/* 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)
{
sim_module_uninstall (sd);
return 0;
}
if (sim_post_argv_init (sd) != SIM_RC_OK)
{
/* Uninstall the modules to avoid memory leaks,
file descriptor leaks, etc. */
sim_module_uninstall (sd);
return 0;
}
trace_sd = sd;
d10v_callback = cb;
old_segment_mapping = 0;
/* NOTE: This argument parsing is only effective when this function
@ -788,8 +810,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd, char **
else if (strncmp (*p, "-t", 2) == 0)
d10v_debug = atoi (*p + 2);
#endif
else
(*d10v_callback->printf_filtered) (d10v_callback, "ERROR: unsupported option(s): %s\n",*p);
}
/* put all the opcodes in the hash table */
@ -823,32 +843,14 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd, char **
sim_size (1);
sim_create_inferior ((SIM_DESC) 1, NULL, NULL, NULL);
/* Fudge our descriptor. */
return (SIM_DESC) 1;
return sd;
}
void
sim_close (SIM_DESC sd, int quitting)
{
if (prog_bfd != NULL && prog_bfd_was_opened_p)
{
bfd_close (prog_bfd);
prog_bfd = NULL;
prog_bfd_was_opened_p = 0;
}
}
void
sim_set_profile (int n)
{
(*d10v_callback->printf_filtered) (d10v_callback, "sim_set_profile %d\n",n);
}
void
sim_set_profile_size (int n)
{
(*d10v_callback->printf_filtered) (d10v_callback, "sim_set_profile_size %d\n",n);
/* Nothing to do. */
}
uint8 *
@ -1038,14 +1040,6 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
State.exception = SIGTRAP;
}
void
sim_set_trace (void)
{
#ifdef DEBUG
d10v_debug = DEBUG;
#endif
}
void
sim_info (SIM_DESC sd, int verbose)
{
@ -1205,21 +1199,6 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env)
return SIM_RC_OK;
}
void
sim_set_callbacks (host_callback *p)
{
d10v_callback = p;
}
int
sim_trace (SIM_DESC sd)
{
sim_resume (sd, 0, 0);
return 1;
}
void
sim_stop_reason (SIM_DESC sd, enum sim_stop *reason, int *sigrc)
{
@ -1418,29 +1397,3 @@ sim_store_register (SIM_DESC sd, int rn, unsigned char *memory, int length)
SLOT_FLUSH ();
return size;
}
void
sim_do_command (SIM_DESC sd, const char *cmd)
{
(*d10v_callback->printf_filtered) (d10v_callback, "sim_do_command: %s\n",cmd);
}
SIM_RC
sim_load (SIM_DESC sd, const char *prog, bfd *abfd, int from_tty)
{
extern bfd *sim_load_file (); /* ??? Don't know where this should live. */
if (prog_bfd != NULL && prog_bfd_was_opened_p)
{
bfd_close (prog_bfd);
prog_bfd_was_opened_p = 0;
}
prog_bfd = sim_load_file (sd, myname, d10v_callback, prog, abfd,
sim_kind == SIM_OPEN_DEBUG,
1/*LMA*/, sim_write);
if (prog_bfd == NULL)
return SIM_RC_FAIL;
prog_bfd_was_opened_p = abfd == NULL;
return SIM_RC_OK;
}

View File

@ -11,7 +11,7 @@
#include <string.h>
#endif
#include "d10v_sim.h"
#include "sim-main.h"
#include "simops.h"
#include "targ-vals.h"
@ -193,14 +193,21 @@ trace_input_func (const char *name, enum op_types in1, enum op_types in2, enum o
else
{
extern SIM_DESC trace_sd;
buf[0] = '\0';
byte_pc = decode_pc ();
if (text && byte_pc >= text_start && byte_pc < text_end)
byte_pc = PC;
if (STATE_TEXT_SECTION (trace_sd)
&& byte_pc >= STATE_TEXT_START (trace_sd)
&& byte_pc < STATE_TEXT_END (trace_sd))
{
filename = (const char *)0;
functionname = (const char *)0;
linenumber = 0;
if (bfd_find_nearest_line (prog_bfd, text, (struct bfd_symbol **)0, byte_pc - text_start,
if (bfd_find_nearest_line (STATE_PROG_BFD (trace_sd),
STATE_TEXT_SECTION (trace_sd),
(struct bfd_symbol **)0,
byte_pc - STATE_TEXT_START (trace_sd),
&filename, &functionname, &linenumber))
{
p = buf;

View File

@ -1,3 +1,7 @@
2015-03-30 Mike Frysinger <vapier@gentoo.org>
* Makefile.in (RUNFLAGS_FOR_TARGET): Set to --environment operating.
2009-08-22 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* configure: Regenerate.

View File

@ -107,7 +107,7 @@ RUN_FOR_TARGET = `\
fi`
# Force d10v into operating mode.
RUNFLAGS_FOR_TARGET=-o
RUNFLAGS_FOR_TARGET=--environment operating
check: sanity $(TESTS)