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.
#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)
}
}
-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)
{
}
static void /* INLINE */
-wlat (word x, word v)
+wlat (SIM_CPU *cpu, word x, word v)
{
if (((uword)x) >= CPU.msize)
{
}
static void /* INLINE */
-what (word x, word v)
+what (SIM_CPU *cpu, word x, word v)
{
if (((uword)x) >= CPU.msize)
{
/* Read functions. */
static int /* INLINE */
-rbat (word x)
+rbat (SIM_CPU *cpu, word x)
{
if (((uword)x) >= CPU.msize)
{
}
static int /* INLINE */
-rlat (word x)
+rlat (SIM_CPU *cpu, word x)
{
if (((uword) x) >= CPU.msize)
{
}
static int /* INLINE */
-rhat (word x)
+rhat (SIM_CPU *cpu, word x)
{
if (((uword)x) >= CPU.msize)
{
}
}
+/* 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;
}
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;
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;
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);
{
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)
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);
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);
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)
{
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)
{
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;
}
}
-
-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)
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;
-}