sim: unify symbol table handling
The common sim tracing code already handles loading and tracking of symbols from the target program so that it can show symbol info in trace/disassembly calls. Once we touch up the trace code and add a few API callbacks, ports don't need to do loading and searching of symbol tables themselves anymore.
This commit is contained in:
parent
31925464a8
commit
5357150c97
17 changed files with 164 additions and 170 deletions
|
@ -1,3 +1,22 @@
|
||||||
|
2016-08-15 Mike Frysinger <vapier@gentoo.org>
|
||||||
|
|
||||||
|
* interp.c: Include bfd.h.
|
||||||
|
(symcount, symtab, aarch64_get_sym_value): Delete.
|
||||||
|
(remove_useless_symbols): Change count type to long.
|
||||||
|
(aarch64_get_func): Add SIM_DESC to arg list. Add symcount
|
||||||
|
and symtab local variables.
|
||||||
|
(sim_create_inferior): Delete storage. Replace symbol code
|
||||||
|
with a call to trace_load_symbols.
|
||||||
|
* memory.c: Delete bfd.h, elf/internal.h, and elf/common.h
|
||||||
|
includes.
|
||||||
|
(aarch64_get_heap_start): Change aarch64_get_sym_value to
|
||||||
|
trace_sym_value.
|
||||||
|
* memory.h: Delete bfd.h include.
|
||||||
|
(mem_add_blk): Delete unused prototype.
|
||||||
|
* simulator.c (bl, blr): Pass SIM_DESC to aarch64_get_func.
|
||||||
|
* simulator.c (aarch64_get_func): Add SIM_DESC to arg list.
|
||||||
|
(aarch64_get_sym_value): Delete.
|
||||||
|
|
||||||
2016-08-12 Nick Clifton <nickc@redhat.com>
|
2016-08-12 Nick Clifton <nickc@redhat.com>
|
||||||
|
|
||||||
* simulator.c (aarch64_step): Revert pervious delta.
|
* simulator.c (aarch64_step): Revert pervious delta.
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "ansidecl.h"
|
#include "ansidecl.h"
|
||||||
|
#include "bfd.h"
|
||||||
#include "gdb/callback.h"
|
#include "gdb/callback.h"
|
||||||
#include "gdb/remote-sim.h"
|
#include "gdb/remote-sim.h"
|
||||||
#include "gdb/signals.h"
|
#include "gdb/signals.h"
|
||||||
|
@ -38,15 +39,12 @@
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "simulator.h"
|
#include "simulator.h"
|
||||||
|
|
||||||
static unsigned long symcount = 0;
|
|
||||||
static asymbol ** symtab = NULL;
|
|
||||||
|
|
||||||
/* Filter out (in place) symbols that are useless for disassembly.
|
/* Filter out (in place) symbols that are useless for disassembly.
|
||||||
COUNT is the number of elements in SYMBOLS.
|
COUNT is the number of elements in SYMBOLS.
|
||||||
Return the number of useful symbols. */
|
Return the number of useful symbols. */
|
||||||
|
|
||||||
static unsigned long
|
static long
|
||||||
remove_useless_symbols (asymbol **symbols, unsigned long count)
|
remove_useless_symbols (asymbol **symbols, long count)
|
||||||
{
|
{
|
||||||
asymbol **in_ptr = symbols;
|
asymbol **in_ptr = symbols;
|
||||||
asymbol **out_ptr = symbols;
|
asymbol **out_ptr = symbols;
|
||||||
|
@ -87,8 +85,10 @@ compare_symbols (const void *ap, const void *bp)
|
||||||
|
|
||||||
/* Find the name of the function at ADDR. */
|
/* Find the name of the function at ADDR. */
|
||||||
const char *
|
const char *
|
||||||
aarch64_get_func (uint64_t addr)
|
aarch64_get_func (SIM_DESC sd, uint64_t addr)
|
||||||
{
|
{
|
||||||
|
long symcount = STATE_PROG_SYMS_COUNT (sd);
|
||||||
|
asymbol **symtab = STATE_PROG_SYMS (sd);
|
||||||
int min, max;
|
int min, max;
|
||||||
|
|
||||||
min = -1;
|
min = -1;
|
||||||
|
@ -118,24 +118,11 @@ aarch64_get_func (uint64_t addr)
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t
|
|
||||||
aarch64_get_sym_value (const char *name)
|
|
||||||
{
|
|
||||||
unsigned long i;
|
|
||||||
|
|
||||||
for (i = 0; i < symcount; i++)
|
|
||||||
if (strcmp (bfd_asymbol_name (symtab[i]), name) == 0)
|
|
||||||
return bfd_asymbol_value (symtab[i]);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SIM_RC
|
SIM_RC
|
||||||
sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
|
sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
|
||||||
char * const *argv, char * const *env)
|
char * const *argv, char * const *env)
|
||||||
{
|
{
|
||||||
sim_cpu *cpu = STATE_CPU (sd, 0);
|
sim_cpu *cpu = STATE_CPU (sd, 0);
|
||||||
long storage = 0;
|
|
||||||
bfd_vma addr = 0;
|
bfd_vma addr = 0;
|
||||||
|
|
||||||
if (abfd != NULL)
|
if (abfd != NULL)
|
||||||
|
@ -154,14 +141,13 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
|
||||||
STATE_PROG_ARGV (sd) = dupargv (argv);
|
STATE_PROG_ARGV (sd) = dupargv (argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (abfd != NULL)
|
if (trace_load_symbols (sd))
|
||||||
storage = bfd_get_symtab_upper_bound (abfd);
|
|
||||||
if (storage > 0)
|
|
||||||
{
|
{
|
||||||
symtab = (asymbol **) xmalloc (storage);
|
STATE_PROG_SYMS_COUNT (sd) =
|
||||||
symcount = bfd_canonicalize_symtab (abfd, symtab);
|
remove_useless_symbols (STATE_PROG_SYMS (sd),
|
||||||
symcount = remove_useless_symbols (symtab, symcount);
|
STATE_PROG_SYMS_COUNT (sd));
|
||||||
qsort (symtab, symcount, sizeof (asymbol *), compare_symbols);
|
qsort (STATE_PROG_SYMS (sd), STATE_PROG_SYMS_COUNT (sd),
|
||||||
|
sizeof (asymbol *), compare_symbols);
|
||||||
}
|
}
|
||||||
|
|
||||||
aarch64_init (cpu, addr);
|
aarch64_init (cpu, addr);
|
||||||
|
|
|
@ -25,10 +25,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "bfd.h"
|
|
||||||
#include "libiberty.h"
|
#include "libiberty.h"
|
||||||
#include "elf/internal.h"
|
|
||||||
#include "elf/common.h"
|
|
||||||
|
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "simulator.h"
|
#include "simulator.h"
|
||||||
|
@ -163,10 +160,10 @@ aarch64_get_mem_ptr (sim_cpu *cpu, uint64_t address)
|
||||||
uint64_t
|
uint64_t
|
||||||
aarch64_get_heap_start (sim_cpu *cpu)
|
aarch64_get_heap_start (sim_cpu *cpu)
|
||||||
{
|
{
|
||||||
uint64_t heap = aarch64_get_sym_value ("end");
|
uint64_t heap = trace_sym_value (CPU_STATE (cpu), "end");
|
||||||
|
|
||||||
if (heap == 0)
|
if (heap == 0)
|
||||||
heap = aarch64_get_sym_value ("_end");
|
heap = trace_sym_value (CPU_STATE (cpu), "_end");
|
||||||
if (heap == 0)
|
if (heap == 0)
|
||||||
{
|
{
|
||||||
heap = STACK_TOP - 0x100000;
|
heap = STACK_TOP - 0x100000;
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#define _MEMORY_H
|
#define _MEMORY_H
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "bfd.h"
|
|
||||||
#include "simulator.h"
|
#include "simulator.h"
|
||||||
|
|
||||||
extern void aarch64_get_mem_long_double (sim_cpu *, uint64_t, FRegister *);
|
extern void aarch64_get_mem_long_double (sim_cpu *, uint64_t, FRegister *);
|
||||||
|
@ -53,6 +52,4 @@ extern void aarch64_set_mem_s8 (sim_cpu *, uint64_t, int8_t);
|
||||||
extern uint64_t aarch64_get_heap_start (sim_cpu *);
|
extern uint64_t aarch64_get_heap_start (sim_cpu *);
|
||||||
extern uint64_t aarch64_get_stack_start (sim_cpu *);
|
extern uint64_t aarch64_get_stack_start (sim_cpu *);
|
||||||
|
|
||||||
extern void mem_add_blk (sim_cpu *, uint64_t, char *, uint64_t, bfd_boolean);
|
|
||||||
|
|
||||||
#endif /* _MEMORY_H */
|
#endif /* _MEMORY_H */
|
||||||
|
|
|
@ -13163,7 +13163,8 @@ bl (sim_cpu *cpu, int32_t offset)
|
||||||
" %*scall %" PRIx64 " [%s]"
|
" %*scall %" PRIx64 " [%s]"
|
||||||
" [args: %" PRIx64 " %" PRIx64 " %" PRIx64 "]",
|
" [args: %" PRIx64 " %" PRIx64 " %" PRIx64 "]",
|
||||||
stack_depth, " ", aarch64_get_next_PC (cpu),
|
stack_depth, " ", aarch64_get_next_PC (cpu),
|
||||||
aarch64_get_func (aarch64_get_next_PC (cpu)),
|
aarch64_get_func (CPU_STATE (cpu),
|
||||||
|
aarch64_get_next_PC (cpu)),
|
||||||
aarch64_get_reg_u64 (cpu, 0, NO_SP),
|
aarch64_get_reg_u64 (cpu, 0, NO_SP),
|
||||||
aarch64_get_reg_u64 (cpu, 1, NO_SP),
|
aarch64_get_reg_u64 (cpu, 1, NO_SP),
|
||||||
aarch64_get_reg_u64 (cpu, 2, NO_SP)
|
aarch64_get_reg_u64 (cpu, 2, NO_SP)
|
||||||
|
@ -13202,7 +13203,8 @@ blr (sim_cpu *cpu)
|
||||||
" %*scall %" PRIx64 " [%s]"
|
" %*scall %" PRIx64 " [%s]"
|
||||||
" [args: %" PRIx64 " %" PRIx64 " %" PRIx64 "]",
|
" [args: %" PRIx64 " %" PRIx64 " %" PRIx64 "]",
|
||||||
stack_depth, " ", aarch64_get_next_PC (cpu),
|
stack_depth, " ", aarch64_get_next_PC (cpu),
|
||||||
aarch64_get_func (aarch64_get_next_PC (cpu)),
|
aarch64_get_func (CPU_STATE (cpu),
|
||||||
|
aarch64_get_next_PC (cpu)),
|
||||||
aarch64_get_reg_u64 (cpu, 0, NO_SP),
|
aarch64_get_reg_u64 (cpu, 0, NO_SP),
|
||||||
aarch64_get_reg_u64 (cpu, 1, NO_SP),
|
aarch64_get_reg_u64 (cpu, 1, NO_SP),
|
||||||
aarch64_get_reg_u64 (cpu, 2, NO_SP)
|
aarch64_get_reg_u64 (cpu, 2, NO_SP)
|
||||||
|
|
|
@ -46,8 +46,7 @@ extern void aarch64_init (sim_cpu *, uint64_t);
|
||||||
hit an error. */
|
hit an error. */
|
||||||
|
|
||||||
extern void aarch64_run (SIM_DESC);
|
extern void aarch64_run (SIM_DESC);
|
||||||
extern const char * aarch64_get_func (uint64_t);
|
extern const char * aarch64_get_func (SIM_DESC, uint64_t);
|
||||||
extern uint64_t aarch64_get_sym_value (const char *);
|
|
||||||
extern void aarch64_init_LIT_table (void);
|
extern void aarch64_init_LIT_table (void);
|
||||||
|
|
||||||
#endif /* _SIMULATOR_H */
|
#endif /* _SIMULATOR_H */
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
2016-08-15 Mike Frysinger <vapier@gentoo.org>
|
||||||
|
|
||||||
|
* sim-base.h (sim_state_base): Add prog_syms_count.
|
||||||
|
(STATE_PROG_SYMS_COUNT): Define.
|
||||||
|
* sim-trace.c (trace_uninstall): Free STATE_PROG_SYMS memory.
|
||||||
|
(trace_load_symbols): New function.
|
||||||
|
(trace_sym_value): Likewise.
|
||||||
|
(trace_prefix): Change STATE_CPU(cpu) to sd. Replace symbol
|
||||||
|
loading logic with a call to trace_load_symbols.
|
||||||
|
* sim-trace.h (trace_load_symbols, trace_sym_value): New
|
||||||
|
prototypes.
|
||||||
|
|
||||||
2016-08-13 Mike Frysinger <vapier@gentoo.org>
|
2016-08-13 Mike Frysinger <vapier@gentoo.org>
|
||||||
|
|
||||||
* cgen-types.h (mode_names): Mark const.
|
* cgen-types.h (mode_names): Mark const.
|
||||||
|
|
|
@ -160,6 +160,10 @@ typedef struct {
|
||||||
struct bfd_symbol **prog_syms;
|
struct bfd_symbol **prog_syms;
|
||||||
#define STATE_PROG_SYMS(sd) ((sd)->base.prog_syms)
|
#define STATE_PROG_SYMS(sd) ((sd)->base.prog_syms)
|
||||||
|
|
||||||
|
/* Number of prog_syms symbols. */
|
||||||
|
long prog_syms_count;
|
||||||
|
#define STATE_PROG_SYMS_COUNT(sd) ((sd)->base.prog_syms_count)
|
||||||
|
|
||||||
/* The program's text section. */
|
/* The program's text section. */
|
||||||
struct bfd_section *text_section;
|
struct bfd_section *text_section;
|
||||||
/* Starting and ending text section addresses from the bfd. */
|
/* Starting and ending text section addresses from the bfd. */
|
||||||
|
|
|
@ -510,6 +510,9 @@ trace_uninstall (SIM_DESC sd)
|
||||||
fclose (cfile);
|
fclose (cfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (STATE_PROG_SYMS (sd))
|
||||||
|
free (STATE_PROG_SYMS (sd));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* compute the nr of trace data units consumed by data */
|
/* compute the nr of trace data units consumed by data */
|
||||||
|
@ -685,6 +688,57 @@ trace_results (SIM_DESC sd,
|
||||||
trace_printf (sd, cpu, "\n");
|
trace_printf (sd, cpu, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
trace_load_symbols (SIM_DESC sd)
|
||||||
|
{
|
||||||
|
bfd *abfd;
|
||||||
|
asymbol **asymbols;
|
||||||
|
long symsize;
|
||||||
|
long symbol_count;
|
||||||
|
|
||||||
|
/* Already loaded, so nothing to do. */
|
||||||
|
if (STATE_PROG_SYMS (sd))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
abfd = STATE_PROG_BFD (sd);
|
||||||
|
if (abfd == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
symsize = bfd_get_symtab_upper_bound (abfd);
|
||||||
|
if (symsize < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
asymbols = xmalloc (symsize);
|
||||||
|
symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
|
||||||
|
if (symbol_count < 0)
|
||||||
|
{
|
||||||
|
free (asymbols);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
STATE_PROG_SYMS (sd) = asymbols;
|
||||||
|
STATE_PROG_SYMS_COUNT (sd) = symbol_count;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bfd_vma
|
||||||
|
trace_sym_value (SIM_DESC sd, const char *name)
|
||||||
|
{
|
||||||
|
asymbol **asymbols;
|
||||||
|
long i;
|
||||||
|
|
||||||
|
if (!trace_load_symbols (sd))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
asymbols = STATE_PROG_SYMS (sd);
|
||||||
|
|
||||||
|
for (i = 0; i < STATE_PROG_SYMS_COUNT (sd); ++i)
|
||||||
|
if (strcmp (asymbols[i]->name, name) == 0)
|
||||||
|
return bfd_asymbol_value (asymbols[i]);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
trace_prefix (SIM_DESC sd,
|
trace_prefix (SIM_DESC sd,
|
||||||
sim_cpu *cpu,
|
sim_cpu *cpu,
|
||||||
|
@ -744,9 +798,9 @@ trace_prefix (SIM_DESC sd,
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
if (STATE_TEXT_SECTION (CPU_STATE (cpu))
|
if (STATE_TEXT_SECTION (sd)
|
||||||
&& pc >= STATE_TEXT_START (CPU_STATE (cpu))
|
&& pc >= STATE_TEXT_START (sd)
|
||||||
&& pc < STATE_TEXT_END (CPU_STATE (cpu)))
|
&& pc < STATE_TEXT_END (sd))
|
||||||
{
|
{
|
||||||
const char *pc_filename = (const char *)0;
|
const char *pc_filename = (const char *)0;
|
||||||
const char *pc_function = (const char *)0;
|
const char *pc_function = (const char *)0;
|
||||||
|
@ -754,31 +808,14 @@ trace_prefix (SIM_DESC sd,
|
||||||
bfd *abfd;
|
bfd *abfd;
|
||||||
asymbol **asymbols;
|
asymbol **asymbols;
|
||||||
|
|
||||||
abfd = STATE_PROG_BFD (CPU_STATE (cpu));
|
if (!trace_load_symbols (sd))
|
||||||
asymbols = STATE_PROG_SYMS (CPU_STATE (cpu));
|
sim_engine_abort (sd, cpu, cia, "could not load symbols");
|
||||||
if (asymbols == NULL)
|
|
||||||
{
|
|
||||||
long symsize;
|
|
||||||
long symbol_count;
|
|
||||||
|
|
||||||
symsize = bfd_get_symtab_upper_bound (abfd);
|
abfd = STATE_PROG_BFD (sd);
|
||||||
if (symsize < 0)
|
asymbols = STATE_PROG_SYMS (sd);
|
||||||
{
|
|
||||||
sim_engine_abort (sd, cpu, cia, "could not read symbols");
|
|
||||||
}
|
|
||||||
asymbols = (asymbol **) xmalloc (symsize);
|
|
||||||
symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
|
|
||||||
if (symbol_count < 0)
|
|
||||||
{
|
|
||||||
sim_engine_abort (sd, cpu, cia, "could not canonicalize symbols");
|
|
||||||
}
|
|
||||||
STATE_PROG_SYMS (CPU_STATE (cpu)) = asymbols;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bfd_find_nearest_line (abfd,
|
if (bfd_find_nearest_line (abfd, STATE_TEXT_SECTION (sd), asymbols,
|
||||||
STATE_TEXT_SECTION (CPU_STATE (cpu)),
|
pc - STATE_TEXT_START (sd),
|
||||||
asymbols,
|
|
||||||
pc - STATE_TEXT_START (CPU_STATE (cpu)),
|
|
||||||
&pc_filename, &pc_function, &pc_linenum))
|
&pc_filename, &pc_function, &pc_linenum))
|
||||||
{
|
{
|
||||||
char *p = buf;
|
char *p = buf;
|
||||||
|
|
|
@ -671,6 +671,10 @@ extern void trace_vprintf (SIM_DESC, sim_cpu *, const char *, va_list);
|
||||||
/* Non-zero if "--debug-insn" specified. */
|
/* Non-zero if "--debug-insn" specified. */
|
||||||
#define DEBUG_INSN_P(cpu) DEBUG_P (cpu, DEBUG_INSN_IDX)
|
#define DEBUG_INSN_P(cpu) DEBUG_P (cpu, DEBUG_INSN_IDX)
|
||||||
|
|
||||||
|
/* Symbol related helpers. */
|
||||||
|
int trace_load_symbols (SIM_DESC);
|
||||||
|
bfd_vma trace_sym_value (SIM_DESC, const char *name);
|
||||||
|
|
||||||
extern void sim_debug_printf (sim_cpu *, const char *, ...)
|
extern void sim_debug_printf (sim_cpu *, const char *, ...)
|
||||||
__attribute__((format (printf, 2, 3)));
|
__attribute__((format (printf, 2, 3)));
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
2016-08-15 Mike Frysinger <vapier@gentoo.org>
|
||||||
|
|
||||||
|
* sim-if.c (find_limit): Change prototype to take a SIM_DESC.
|
||||||
|
Replace symbol lookup code with a call to trace_sym_value.
|
||||||
|
(sim_open): Update find_limit call.
|
||||||
|
|
||||||
2016-01-10 Mike Frysinger <vapier@gentoo.org>
|
2016-01-10 Mike Frysinger <vapier@gentoo.org>
|
||||||
|
|
||||||
* config.in, configure: Regenerate.
|
* config.in, configure: Regenerate.
|
||||||
|
|
|
@ -71,27 +71,15 @@ find_base (bfd *prog_bfd)
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned long
|
static unsigned long
|
||||||
find_limit (bfd *prog_bfd)
|
find_limit (SIM_DESC sd)
|
||||||
{
|
{
|
||||||
struct bfd_symbol **asymbols;
|
bfd_vma addr;
|
||||||
long symsize;
|
|
||||||
long symbol_count;
|
|
||||||
long s;
|
|
||||||
|
|
||||||
symsize = bfd_get_symtab_upper_bound (prog_bfd);
|
addr = trace_sym_value (sd, "_fstack");
|
||||||
if (symsize < 0)
|
if (addr == -1)
|
||||||
return 0;
|
|
||||||
asymbols = (asymbol **) xmalloc (symsize);
|
|
||||||
symbol_count = bfd_canonicalize_symtab (prog_bfd, asymbols);
|
|
||||||
if (symbol_count < 0)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (s = 0; s < symbol_count; s++)
|
return (addr + 65536) & ~(0xffffUL);
|
||||||
{
|
|
||||||
if (!strcmp (asymbols[s]->name, "_fstack"))
|
|
||||||
return (asymbols[s]->value + 65536) & ~(0xffffUL);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create an instance of the simulator. */
|
/* Create an instance of the simulator. */
|
||||||
|
@ -159,7 +147,7 @@ sim_open (kind, callback, abfd, argv)
|
||||||
{
|
{
|
||||||
/* It doesn't, so we should try to allocate enough memory to hold program. */
|
/* It doesn't, so we should try to allocate enough memory to hold program. */
|
||||||
base = find_base (STATE_PROG_BFD (sd));
|
base = find_base (STATE_PROG_BFD (sd));
|
||||||
limit = find_limit (STATE_PROG_BFD (sd));
|
limit = find_limit (sd);
|
||||||
if (limit == 0)
|
if (limit == 0)
|
||||||
{
|
{
|
||||||
sim_io_eprintf (sd,
|
sim_io_eprintf (sd,
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
2016-08-15 Mike Frysinger <vapier@gentoo.org>
|
||||||
|
|
||||||
|
* interp.c (sim_get_bank_parameters): Delete abfd arg.
|
||||||
|
Replace all symbol lookup code with calls to trace_sym_value.
|
||||||
|
(sim_prepare_for_program): Update sim_get_bank_parameters call.
|
||||||
|
|
||||||
2016-08-13 Mike Frysinger <vapier@gentoo.org>
|
2016-08-13 Mike Frysinger <vapier@gentoo.org>
|
||||||
|
|
||||||
* dv-m68hc11.c (m68hc11cpu_port_event): Adjust cpu prototype style.
|
* dv-m68hc11.c (m68hc11cpu_port_event): Adjust cpu prototype style.
|
||||||
|
|
|
@ -292,50 +292,25 @@ sim_hw_configure (SIM_DESC sd)
|
||||||
/* Get the memory bank parameters by looking at the global symbols
|
/* Get the memory bank parameters by looking at the global symbols
|
||||||
defined by the linker. */
|
defined by the linker. */
|
||||||
static int
|
static int
|
||||||
sim_get_bank_parameters (SIM_DESC sd, bfd* abfd)
|
sim_get_bank_parameters (SIM_DESC sd)
|
||||||
{
|
{
|
||||||
sim_cpu *cpu;
|
sim_cpu *cpu;
|
||||||
long symsize;
|
|
||||||
long symbol_count, i;
|
|
||||||
unsigned size;
|
unsigned size;
|
||||||
asymbol** asymbols;
|
bfd_vma addr;
|
||||||
asymbol** current;
|
|
||||||
|
|
||||||
cpu = STATE_CPU (sd, 0);
|
cpu = STATE_CPU (sd, 0);
|
||||||
|
|
||||||
symsize = bfd_get_symtab_upper_bound (abfd);
|
addr = trace_sym_value (sd, BFD_M68HC11_BANK_START_NAME);
|
||||||
if (symsize < 0)
|
if (addr != -1)
|
||||||
{
|
cpu->bank_start = addr;
|
||||||
sim_io_eprintf (sd, "Cannot read symbols of program");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
asymbols = (asymbol **) xmalloc (symsize);
|
|
||||||
symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
|
|
||||||
if (symbol_count < 0)
|
|
||||||
{
|
|
||||||
sim_io_eprintf (sd, "Cannot read symbols of program");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size = 0;
|
size = trace_sym_value (sd, BFD_M68HC11_BANK_SIZE_NAME);
|
||||||
for (i = 0, current = asymbols; i < symbol_count; i++, current++)
|
if (size == -1)
|
||||||
{
|
size = 0;
|
||||||
const char* name = bfd_asymbol_name (*current);
|
|
||||||
|
|
||||||
if (strcmp (name, BFD_M68HC11_BANK_START_NAME) == 0)
|
addr = trace_sym_value (sd, BFD_M68HC11_BANK_VIRTUAL_NAME);
|
||||||
{
|
if (addr != -1)
|
||||||
cpu->bank_start = bfd_asymbol_value (*current);
|
cpu->bank_virtual = addr;
|
||||||
}
|
|
||||||
else if (strcmp (name, BFD_M68HC11_BANK_SIZE_NAME) == 0)
|
|
||||||
{
|
|
||||||
size = bfd_asymbol_value (*current);
|
|
||||||
}
|
|
||||||
else if (strcmp (name, BFD_M68HC11_BANK_VIRTUAL_NAME) == 0)
|
|
||||||
{
|
|
||||||
cpu->bank_virtual = bfd_asymbol_value (*current);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free (asymbols);
|
|
||||||
|
|
||||||
cpu->bank_end = cpu->bank_start + size;
|
cpu->bank_end = cpu->bank_start + size;
|
||||||
cpu->bank_shift = 0;
|
cpu->bank_shift = 0;
|
||||||
|
@ -387,7 +362,7 @@ sim_prepare_for_program (SIM_DESC sd, bfd* abfd)
|
||||||
|
|
||||||
if (elf_flags & E_M68HC12_BANKS)
|
if (elf_flags & E_M68HC12_BANKS)
|
||||||
{
|
{
|
||||||
if (sim_get_bank_parameters (sd, abfd) != 0)
|
if (sim_get_bank_parameters (sd) != 0)
|
||||||
sim_io_eprintf (sd, "Memory bank parameters are not initialized\n");
|
sim_io_eprintf (sd, "Memory bank parameters are not initialized\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,13 @@
|
||||||
|
2016-08-15 Mike Frysinger <vapier@gentoo.org>
|
||||||
|
|
||||||
|
* msp430-sim.c: Delete bfd.h include.
|
||||||
|
(lookup_symbol, msp430_sim_close): Delete.
|
||||||
|
(sim_open): Change lookup_symbol to trace_sym_value.
|
||||||
|
* sim-main.h (struct sim_state): Delete symbol_table and
|
||||||
|
number_of_symbols.
|
||||||
|
(STATE_SYMBOL_TABLE, STATE_NUM_SYMBOLS, msp430_sim_close,
|
||||||
|
SIM_CLOSE_HOOK): Delete.
|
||||||
|
|
||||||
2016-01-10 Mike Frysinger <vapier@gentoo.org>
|
2016-01-10 Mike Frysinger <vapier@gentoo.org>
|
||||||
|
|
||||||
* config.in, configure: Regenerate.
|
* config.in, configure: Regenerate.
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "bfd.h"
|
|
||||||
#include "opcode/msp430-decode.h"
|
#include "opcode/msp430-decode.h"
|
||||||
#include "sim-main.h"
|
#include "sim-main.h"
|
||||||
#include "sim-syscall.h"
|
#include "sim-syscall.h"
|
||||||
|
@ -44,39 +43,6 @@ msp430_pc_store (SIM_CPU *cpu, sim_cia newpc)
|
||||||
cpu->state.regs[0] = newpc;
|
cpu->state.regs[0] = newpc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long
|
|
||||||
lookup_symbol (SIM_DESC sd, const char *name)
|
|
||||||
{
|
|
||||||
struct bfd *abfd = STATE_PROG_BFD (sd);
|
|
||||||
asymbol **symbol_table = STATE_SYMBOL_TABLE (sd);
|
|
||||||
long number_of_symbols = STATE_NUM_SYMBOLS (sd);
|
|
||||||
long i;
|
|
||||||
|
|
||||||
if (abfd == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (symbol_table == NULL)
|
|
||||||
{
|
|
||||||
long storage_needed;
|
|
||||||
|
|
||||||
storage_needed = bfd_get_symtab_upper_bound (abfd);
|
|
||||||
if (storage_needed <= 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
STATE_SYMBOL_TABLE (sd) = symbol_table = xmalloc (storage_needed);
|
|
||||||
STATE_NUM_SYMBOLS (sd) = number_of_symbols =
|
|
||||||
bfd_canonicalize_symtab (abfd, symbol_table);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < number_of_symbols; i++)
|
|
||||||
if (strcmp (symbol_table[i]->name, name) == 0)
|
|
||||||
{
|
|
||||||
long val = symbol_table[i]->section->vma + symbol_table[i]->value;
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
msp430_reg_fetch (SIM_CPU *cpu, int regno, unsigned char *buf, int len)
|
msp430_reg_fetch (SIM_CPU *cpu, int regno, unsigned char *buf, int len)
|
||||||
{
|
{
|
||||||
|
@ -207,20 +173,14 @@ sim_open (SIM_OPEN_KIND kind,
|
||||||
assert (MAX_NR_PROCESSORS == 1);
|
assert (MAX_NR_PROCESSORS == 1);
|
||||||
msp430_initialize_cpu (sd, MSP430_CPU (sd));
|
msp430_initialize_cpu (sd, MSP430_CPU (sd));
|
||||||
|
|
||||||
MSP430_CPU (sd)->state.cio_breakpoint = lookup_symbol (sd, "C$$IO$$");
|
MSP430_CPU (sd)->state.cio_breakpoint = trace_sym_value (sd, "C$$IO$$");
|
||||||
MSP430_CPU (sd)->state.cio_buffer = lookup_symbol (sd, "__CIOBUF__");
|
MSP430_CPU (sd)->state.cio_buffer = trace_sym_value (sd, "__CIOBUF__");
|
||||||
if (MSP430_CPU (sd)->state.cio_buffer == -1)
|
if (MSP430_CPU (sd)->state.cio_buffer == -1)
|
||||||
MSP430_CPU (sd)->state.cio_buffer = lookup_symbol (sd, "_CIOBUF_");
|
MSP430_CPU (sd)->state.cio_buffer = trace_sym_value (sd, "_CIOBUF_");
|
||||||
|
|
||||||
return sd;
|
return sd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
msp430_sim_close (SIM_DESC sd, int quitting)
|
|
||||||
{
|
|
||||||
free (STATE_SYMBOL_TABLE (sd));
|
|
||||||
}
|
|
||||||
|
|
||||||
SIM_RC
|
SIM_RC
|
||||||
sim_create_inferior (SIM_DESC sd,
|
sim_create_inferior (SIM_DESC sd,
|
||||||
struct bfd *abfd,
|
struct bfd *abfd,
|
||||||
|
|
|
@ -37,11 +37,6 @@ struct sim_state
|
||||||
{
|
{
|
||||||
sim_cpu *cpu[MAX_NR_PROCESSORS];
|
sim_cpu *cpu[MAX_NR_PROCESSORS];
|
||||||
|
|
||||||
asymbol **symbol_table;
|
|
||||||
long number_of_symbols;
|
|
||||||
#define STATE_SYMBOL_TABLE(sd) ((sd)->symbol_table)
|
|
||||||
#define STATE_NUM_SYMBOLS(sd) ((sd)->number_of_symbols)
|
|
||||||
|
|
||||||
/* Simulator specific members. */
|
/* Simulator specific members. */
|
||||||
sim_state_base base;
|
sim_state_base base;
|
||||||
};
|
};
|
||||||
|
@ -54,7 +49,4 @@ struct sim_state
|
||||||
#include "sim-engine.h"
|
#include "sim-engine.h"
|
||||||
#include "sim-options.h"
|
#include "sim-options.h"
|
||||||
|
|
||||||
extern void msp430_sim_close (SIM_DESC sd, int quitting);
|
|
||||||
#define SIM_CLOSE_HOOK(...) msp430_sim_close (__VA_ARGS__)
|
|
||||||
|
|
||||||
#endif /* _MSP430_MAIN_SIM_H_ */
|
#endif /* _MSP430_MAIN_SIM_H_ */
|
||||||
|
|
Loading…
Reference in a new issue