aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2015-03-29 17:40:30 -0400
committerMike Frysinger <vapier@gentoo.org>2015-03-29 17:40:30 -0400
commit2b4bc832a7668438827f5cdca9bf22adab85a915 (patch)
treedf569b0c17be6027e0abb93625da9f504babfe81
parent97eca187b3b286c903d78070736bbe1d95721ec4 (diff)
downloadgdb-2b4bc832a7668438827f5cdca9bf22adab85a915.zip
gdb-2b4bc832a7668438827f5cdca9bf22adab85a915.tar.gz
gdb-2b4bc832a7668438827f5cdca9bf22adab85a915.tar.bz2
sim: microblaze: convert to nrun
This port already was storing its cpu state in the sim_cpu structure, so converting it over was pretty easy. It is allocating memory itself still, but we'll fix that up in the future at some point.
-rw-r--r--sim/microblaze/ChangeLog29
-rw-r--r--sim/microblaze/Makefile.in14
-rw-r--r--sim/microblaze/interp.c286
-rw-r--r--sim/microblaze/microblaze.h14
-rw-r--r--sim/microblaze/sim-main.h26
5 files changed, 176 insertions, 193 deletions
diff --git a/sim/microblaze/ChangeLog b/sim/microblaze/ChangeLog
index 2501423..565359e 100644
--- a/sim/microblaze/ChangeLog
+++ b/sim/microblaze/ChangeLog
@@ -1,5 +1,34 @@
2015-03-29 Mike Frysinger <vapier@gentoo.org>
+ * Makefile.in (SIM_RUN_OBJS, SIM_EXTRA_CFLAGS, SIM_EXTRA_LIBS): Delete.
+ (SIM_OBJS): Change to $(SIM_NEW_COMMON_OBJS).
+ * interp.c: Drop sys/times.h, sys/param.h, run-sim.h, and sim-utils.h
+ includes.
+ (target_big_endian): Replace with CURRENT_TARGET_BYTE_ORDER.
+ (callback, microblaze_state, sim_kind, myname, sim_trace, sim_stop,
+ sim_load, sim_set_callbacks, sim_complete_command): Delete.
+ (wbat, wlat, what, rbat, rlat, rhat): Add SIM_CPU* as first arg.
+ (sim_size): Mark static and add SIM_CPU* as first arg.
+ (init_pointers): Add SIM_CPU* as first arg and pass to sim_size.
+ (set_initial_gprs): Add SIM_CPU* as first arg and pass to init_pointers.
+ (sim_resume): Add local cpu variable. Pass it to rlat.
+ (sim_write, sim_read, sim_store_register, sim_fetch_register): Add local
+ cpu variable. Pass it to init_pointers.
+ (sim_stop_reason, sim_do_command): Add local cpu variable.
+ (sim_info): Add local cpu and callback variables.
+ (free_state): New cleanup function.
+ (sim_open): Rewrite to use new common logic.
+ (sim_close): Delete body.
+ (sim_create_inferior): Delete call to set_initial_gprs.
+ * microblaze.h (CPU): Redefine using cpu.
+ (MEM_RD_BYTE, MEM_RD_HALF, MEM_RD_WORD, MEM_WR_BYTE, MEM_WR_HALF,
+ MEM_WR_WORD): Pass in cpu as first arg.
+ * sim-main.h (CIA_GET, CIA_SET, SIM_CPU): Define.
+ (MAX_NR_PROCESSORS): Delete.
+ (struct sim_state): Change cpu to *cpu, and rewrite STATE_CPU.
+
+2015-03-29 Mike Frysinger <vapier@gentoo.org>
+
* interp.c (NUM_ELEM, heap_ptr, stack_ptr, memcycles, struct aout,
LONG, SHORT): Delete.
[WATCHFUNCTIONS]: Delete.
diff --git a/sim/microblaze/Makefile.in b/sim/microblaze/Makefile.in
index 6dc6e4e..ca31766 100644
--- a/sim/microblaze/Makefile.in
+++ b/sim/microblaze/Makefile.in
@@ -17,11 +17,13 @@
## COMMON_PRE_CONFIG_FRAG
-# 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_EXTRA_LIBS = -lm
+SIM_OBJS = \
+ interp.o \
+ $(SIM_NEW_COMMON_OBJS) \
+ sim-cpu.o \
+ sim-engine.o \
+ sim-hload.o \
+ sim-reason.o \
+ sim-stop.o
## COMMON_POST_CONFIG_FRAG
diff --git a/sim/microblaze/interp.c b/sim/microblaze/interp.c
index 335181a..9e95e1e 100644
--- a/sim/microblaze/interp.c
+++ b/sim/microblaze/interp.c
@@ -20,20 +20,18 @@
#include <signal.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/times.h>
-#include <sys/param.h>
#include <unistd.h>
#include "bfd.h"
#include "gdb/callback.h"
#include "libiberty.h"
#include "gdb/remote-sim.h"
-#include "run-sim.h"
+
#include "sim-main.h"
-#include "sim-utils.h"
+#include "sim-options.h"
+
#include "microblaze-dis.h"
-static int target_big_endian = 1;
-host_callback *callback;
+#define target_big_endian (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
static unsigned long
microblaze_extract_unsigned_integer (unsigned char *addr, int len)
@@ -91,15 +89,11 @@ microblaze_store_unsigned_integer (unsigned char *addr, int len,
}
}
-struct sim_state microblaze_state;
-
-static SIM_OPEN_KIND sim_kind;
-static char *myname;
-
+/* TODO: Convert to common tracing framework. */
static int issue_messages = 0;
static void /* INLINE */
-wbat (word x, word v)
+wbat (SIM_CPU *cpu, word x, word v)
{
if (((uword)x) >= CPU.msize)
{
@@ -116,7 +110,7 @@ wbat (word x, word v)
}
static void /* INLINE */
-wlat (word x, word v)
+wlat (SIM_CPU *cpu, word x, word v)
{
if (((uword)x) >= CPU.msize)
{
@@ -154,7 +148,7 @@ wlat (word x, word v)
}
static void /* INLINE */
-what (word x, word v)
+what (SIM_CPU *cpu, word x, word v)
{
if (((uword)x) >= CPU.msize)
{
@@ -190,7 +184,7 @@ what (word x, word v)
/* Read functions. */
static int /* INLINE */
-rbat (word x)
+rbat (SIM_CPU *cpu, word x)
{
if (((uword)x) >= CPU.msize)
{
@@ -208,7 +202,7 @@ rbat (word x)
}
static int /* INLINE */
-rlat (word x)
+rlat (SIM_CPU *cpu, word x)
{
if (((uword) x) >= CPU.msize)
{
@@ -242,7 +236,7 @@ rlat (word x)
}
static int /* INLINE */
-rhat (word x)
+rhat (SIM_CPU *cpu, word x)
{
if (((uword)x) >= CPU.msize)
{
@@ -275,12 +269,13 @@ rhat (word x)
}
}
+/* TODO: Delete all sim_size and use common memory functions. */
/* Default to a 8 Mbyte (== 2^23) memory space. */
static int sim_memory_size = 1 << 23;
#define MEM_SIZE_FLOOR 64
-void
-sim_size (int size)
+static void
+sim_size (SIM_CPU *cpu, int size)
{
sim_memory_size = size;
CPU.msize = sim_memory_size;
@@ -303,20 +298,20 @@ sim_size (int size)
}
static void
-init_pointers (void)
+init_pointers (SIM_CPU *cpu)
{
if (CPU.msize != (sim_memory_size))
- sim_size (sim_memory_size);
+ sim_size (cpu, sim_memory_size);
}
static void
-set_initial_gprs (void)
+set_initial_gprs (SIM_CPU *cpu)
{
int i;
long space;
unsigned long memsize;
- init_pointers ();
+ init_pointers (cpu);
/* Set up machine just out of reset. */
PC = 0;
@@ -341,6 +336,7 @@ static int tracing = 0;
void
sim_resume (SIM_DESC sd, int step, int siggnal)
{
+ SIM_CPU *cpu = STATE_CPU (sd, 0);
int needfetch;
word inst;
enum microblaze_instr op;
@@ -369,7 +365,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
do
{
/* Fetch the initial instructions that we'll decode. */
- inst = rlat (PC & 0xFFFFFFFC);
+ inst = rlat (cpu, PC & 0xFFFFFFFC);
op = get_insn_microblaze (inst, &imm_unsigned, &insn_type,
&num_delay_slot);
@@ -443,7 +439,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
{
newpc = PC;
PC = oldpc + INST_SIZE;
- inst = rlat (PC & 0xFFFFFFFC);
+ inst = rlat (cpu, PC & 0xFFFFFFFC);
op = get_insn_microblaze (inst, &imm_unsigned, &insn_type,
&num_delay_slot);
if (op == invalid_inst)
@@ -530,8 +526,10 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
int
sim_write (SIM_DESC sd, SIM_ADDR addr, const unsigned char *buffer, int size)
{
+ SIM_CPU *cpu = STATE_CPU (sd, 0);
int i;
- init_pointers ();
+
+ init_pointers (cpu);
memcpy (&CPU.memory[addr], buffer, size);
@@ -541,8 +539,10 @@ sim_write (SIM_DESC sd, SIM_ADDR addr, const unsigned char *buffer, int size)
int
sim_read (SIM_DESC sd, SIM_ADDR addr, unsigned char *buffer, int size)
{
+ SIM_CPU *cpu = STATE_CPU (sd, 0);
int i;
- init_pointers ();
+
+ init_pointers (cpu);
memcpy (buffer, &CPU.memory[addr], size);
@@ -553,7 +553,9 @@ sim_read (SIM_DESC sd, SIM_ADDR addr, unsigned char *buffer, int size)
int
sim_store_register (SIM_DESC sd, int rn, unsigned char *memory, int length)
{
- init_pointers ();
+ SIM_CPU *cpu = STATE_CPU (sd, 0);
+
+ init_pointers (cpu);
if (rn < NUM_REGS + NUM_SPECIAL && rn >= 0)
{
@@ -577,8 +579,10 @@ sim_store_register (SIM_DESC sd, int rn, unsigned char *memory, int length)
int
sim_fetch_register (SIM_DESC sd, int rn, unsigned char *memory, int length)
{
+ SIM_CPU *cpu = STATE_CPU (sd, 0);
long ival;
- init_pointers ();
+
+ init_pointers (cpu);
if (rn < NUM_REGS + NUM_SPECIAL && rn >= 0)
{
@@ -600,22 +604,11 @@ sim_fetch_register (SIM_DESC sd, int rn, unsigned char *memory, int length)
return 0;
}
-
-int
-sim_trace (SIM_DESC sd)
-{
- tracing = 1;
-
- sim_resume (sd, 0, 0);
-
- tracing = 0;
-
- return 1;
-}
-
void
sim_stop_reason (SIM_DESC sd, enum sim_stop *reason, int *sigrc)
{
+ SIM_CPU *cpu = STATE_CPU (sd, 0);
+
if (CPU.exception == SIGQUIT)
{
*reason = sim_exited;
@@ -628,163 +621,122 @@ sim_stop_reason (SIM_DESC sd, enum sim_stop *reason, int *sigrc)
}
}
-
-int
-sim_stop (SIM_DESC sd)
-{
- CPU.exception = SIGINT;
- return 1;
-}
-
-
void
sim_info (SIM_DESC sd, int verbose)
{
+ SIM_CPU *cpu = STATE_CPU (sd, 0);
+ host_callback *callback = STATE_CALLBACK (sd);
+
callback->printf_filtered (callback, "\n\n# instructions executed %10d\n",
CPU.insts);
callback->printf_filtered (callback, "# cycles %10d\n",
(CPU.cycles) ? CPU.cycles+2 : 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
sim_open (SIM_OPEN_KIND kind, host_callback *cb, struct bfd *abfd, char **argv)
{
- /* SIM_DESC sd = sim_state_alloc(kind, alloc);*/
+ int i;
+ 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;
+ }
+
+ if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK)
+ {
+ free_state (sd);
+ return 0;
+ }
- int osize = sim_memory_size;
- myname = argv[0];
- callback = cb;
+ /* 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;
+ }
if (kind == SIM_OPEN_STANDALONE)
issue_messages = 1;
- /* Discard and reacquire memory -- start with a clean slate. */
- sim_size (1); /* small */
- sim_size (osize); /* and back again */
+ /* CPU specific initialization. */
+ for (i = 0; i < MAX_NR_PROCESSORS; ++i)
+ {
+ SIM_CPU *cpu = STATE_CPU (sd, i);
+ int osize = sim_memory_size;
+
+ set_initial_gprs (cpu);
- set_initial_gprs (); /* Reset the GPR registers. */
+ /* Discard and reacquire memory -- start with a clean slate. */
+ sim_size (cpu, 1); /* small */
+ sim_size (cpu, osize); /* and back again */
+ }
- return ((SIM_DESC) 1);
+ return sd;
}
void
sim_close (SIM_DESC sd, int quitting)
{
- if (CPU.memory)
- {
- free(CPU.memory);
- CPU.memory = NULL;
- CPU.msize = 0;
- }
-}
-
-SIM_RC
-sim_load (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;
- asection *s;
- int found_loadable_section = 0;
- bfd_vma max_addr = 0;
- handle = bfd_openr (prog, 0);
-
- 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;
- }
-
- for (s = handle->sections; s; s = s->next)
- {
- if (s->flags & SEC_ALLOC)
- {
- bfd_vma vma = 0;
- int size = bfd_get_section_size (s);
- if (size > 0)
- {
- vma = bfd_section_vma (handle, s);
- if (vma >= max_addr)
- {
- max_addr = vma + size;
- }
- }
- if (s->flags & SEC_LOAD)
- found_loadable_section = 1;
- }
- }
-
- if (!found_loadable_section)
- {
- /* No loadable sections */
- bfd_close(handle);
- printf("No loadable sections in file %s\n", prog);
- return SIM_RC_FAIL;
- }
-
- sim_memory_size = (unsigned long) max_addr;
-
- /* 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,
- 0, sim_write);
- if (prog_bfd == NULL)
- return SIM_RC_FAIL;
-
- target_big_endian = bfd_big_endian (prog_bfd);
- PC = bfd_get_start_address (prog_bfd);
-
- if (abfd == NULL)
- bfd_close (prog_bfd);
-
- return SIM_RC_OK;
+ /* Do nothing. */
}
SIM_RC
sim_create_inferior (SIM_DESC sd, struct bfd *prog_bfd, char **argv, char **env)
{
- int l;
-
- /* Set the initial register set. */
- l = issue_messages;
- issue_messages = 0;
- set_initial_gprs ();
- issue_messages = l;
+ SIM_CPU *cpu = STATE_CPU (sd, 0);
PC = bfd_get_start_address (prog_bfd);
- /* For now ignore all parameters to the program */
-
return SIM_RC_OK;
}
void
sim_do_command (SIM_DESC sd, const char *cmd)
{
+ SIM_CPU *cpu = STATE_CPU (sd, 0);
+
/* Nothing there yet; it's all an error. */
if (cmd != NULL)
@@ -833,15 +785,3 @@ sim_do_command (SIM_DESC sd, const char *cmd)
fprintf (stderr, " verbose\n");
}
}
-
-void
-sim_set_callbacks (host_callback *ptr)
-{
- callback = ptr;
-}
-
-char **
-sim_complete_command (SIM_DESC sd, const char *text, const char *word)
-{
- return NULL;
-}
diff --git a/sim/microblaze/microblaze.h b/sim/microblaze/microblaze.h
index df5d992..e08f5a0 100644
--- a/sim/microblaze/microblaze.h
+++ b/sim/microblaze/microblaze.h
@@ -24,7 +24,7 @@
#define GET_RA ((inst & RA_MASK) >> RA_LOW)
#define GET_RB ((inst & RB_MASK) >> RB_LOW)
-#define CPU microblaze_state.cpu[0].microblaze_cpu
+#define CPU cpu->microblaze_cpu
#define RD CPU.regs[rd]
#define RA CPU.regs[ra]
@@ -54,16 +54,16 @@
#define MEM(X) memory[X]
-#define MEM_RD_BYTE(X) rbat(X)
-#define MEM_RD_HALF(X) rhat(X)
-#define MEM_RD_WORD(X) rlat(X)
+#define MEM_RD_BYTE(X) rbat(cpu, X)
+#define MEM_RD_HALF(X) rhat(cpu, X)
+#define MEM_RD_WORD(X) rlat(cpu, X)
#define MEM_RD_UBYTE(X) (ubyte) MEM_RD_BYTE(X)
#define MEM_RD_UHALF(X) (uhalf) MEM_RD_HALF(X)
#define MEM_RD_UWORD(X) (uword) MEM_RD_WORD(X)
-#define MEM_WR_BYTE(X, D) wbat(X, D)
-#define MEM_WR_HALF(X, D) what(X, D)
-#define MEM_WR_WORD(X, D) wlat(X, D)
+#define MEM_WR_BYTE(X, D) wbat(cpu, X, D)
+#define MEM_WR_HALF(X, D) what(cpu, X, D)
+#define MEM_WR_WORD(X, D) wlat(cpu, X, D)
#define MICROBLAZE_SEXT8(X) ((char) X)
diff --git a/sim/microblaze/sim-main.h b/sim/microblaze/sim-main.h
index a29159b..cf1a5f9 100644
--- a/sim/microblaze/sim-main.h
+++ b/sim/microblaze/sim-main.h
@@ -1,6 +1,3 @@
-#ifndef MICROBLAZE_SIM_MAIN
-#define MICROBLAZE_SIM_MAIN
-
/* Copyright 2009-2015 Free Software Foundation, Inc.
This file is part of the Xilinx MicroBlaze simulator.
@@ -18,9 +15,19 @@
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>. */
+#ifndef MICROBLAZE_SIM_MAIN
+#define MICROBLAZE_SIM_MAIN
+
#include "microblaze.h"
#include "sim-basics.h"
+
typedef address_word sim_cia;
+
+#define CIA_GET(cpu) (cpu)->microblaze_cpu.spregs[0]
+#define CIA_SET(cpu,val) (cpu)->microblaze_cpu.spregs[0] = (val)
+
+typedef struct _sim_cpu SIM_CPU;
+
#include "sim-base.h"
/* The machine state.
@@ -52,11 +59,16 @@ struct _sim_cpu {
sim_cpu_base base;
};
-#define MAX_NR_PROCESSORS 1
struct sim_state {
- sim_cpu cpu[MAX_NR_PROCESSORS];
-#define STATE_CPU(sd, n) (&(sd)->cpu[0])
+
+ sim_cpu *cpu[MAX_NR_PROCESSORS];
+#if (WITH_SMP)
+#define STATE_CPU(sd,n) ((sd)->cpu[n])
+#else
+#define STATE_CPU(sd,n) ((sd)->cpu[0])
+#endif
+
sim_state_base base;
};
-#endif /* MICROBLAZE_SIM_MAIN */
+#endif /* MICROBLAZE_SIM_MAIN */