sim: h8300: invert sim_cpu storage

This commit is contained in:
Mike Frysinger
2016-08-16 19:50:25 -07:00
parent 79d784aef9
commit 3fbdc6f908
2 changed files with 36 additions and 34 deletions

View File

@ -57,13 +57,13 @@ static int memory_size;
static unsigned int static unsigned int
h8_get_reg (sim_cpu *cpu, int regnum) h8_get_reg (sim_cpu *cpu, int regnum)
{ {
return cpu->regs[regnum]; return H8300_SIM_CPU (cpu)->regs[regnum];
} }
static void static void
h8_set_reg (sim_cpu *cpu, int regnum, int val) h8_set_reg (sim_cpu *cpu, int regnum, int val)
{ {
cpu->regs[regnum] = val; H8300_SIM_CPU (cpu)->regs[regnum] = val;
} }
#define h8_get_ccr(cpu) h8_get_reg (cpu, CCR_REGNUM) #define h8_get_ccr(cpu) h8_get_reg (cpu, CCR_REGNUM)
@ -88,25 +88,25 @@ h8_set_reg (sim_cpu *cpu, int regnum, int val)
static int static int
h8_get_mask (sim_cpu *cpu) h8_get_mask (sim_cpu *cpu)
{ {
return cpu->mask; return H8300_SIM_CPU (cpu)->mask;
} }
static void static void
h8_set_mask (sim_cpu *cpu, int val) h8_set_mask (sim_cpu *cpu, int val)
{ {
cpu->mask = val; H8300_SIM_CPU (cpu)->mask = val;
} }
#if 0 #if 0
static int static int
h8_get_exception (sim_cpu *cpu) h8_get_exception (sim_cpu *cpu)
{ {
return cpu->exception; return H8300_SIM_CPU (cpu)->exception;
} }
static void static void
h8_set_exception (sim_cpu *cpu, int val) h8_set_exception (sim_cpu *cpu, int val)
{ {
cpu->exception = val; H8300_SIM_CPU (cpu)->exception = val;
} }
static enum h8300_sim_state static enum h8300_sim_state
@ -125,7 +125,7 @@ h8_set_state (SIM_DESC sd, enum h8300_sim_state val)
static unsigned int * static unsigned int *
h8_get_reg_buf (sim_cpu *cpu) h8_get_reg_buf (sim_cpu *cpu)
{ {
return &cpu->regs[0]; return &H8300_SIM_CPU (cpu)->regs[0];
} }
#ifdef ADEBUG #ifdef ADEBUG
@ -145,77 +145,77 @@ h8_increment_stats (SIM_DESC sd, int idx)
static unsigned char * static unsigned char *
h8_get_memory_buf (sim_cpu *cpu) h8_get_memory_buf (sim_cpu *cpu)
{ {
return cpu->memory; return H8300_SIM_CPU (cpu)->memory;
} }
static void static void
h8_set_memory_buf (sim_cpu *cpu, unsigned char *ptr) h8_set_memory_buf (sim_cpu *cpu, unsigned char *ptr)
{ {
cpu->memory = ptr; H8300_SIM_CPU (cpu)->memory = ptr;
} }
static unsigned char static unsigned char
h8_get_memory (sim_cpu *cpu, int idx) h8_get_memory (sim_cpu *cpu, int idx)
{ {
ASSERT (idx < memory_size); ASSERT (idx < memory_size);
return cpu->memory[idx]; return H8300_SIM_CPU (cpu)->memory[idx];
} }
static void static void
h8_set_memory (sim_cpu *cpu, int idx, unsigned int val) h8_set_memory (sim_cpu *cpu, int idx, unsigned int val)
{ {
ASSERT (idx < memory_size); ASSERT (idx < memory_size);
cpu->memory[idx] = (unsigned char) val; H8300_SIM_CPU (cpu)->memory[idx] = (unsigned char) val;
} }
static unsigned int static unsigned int
h8_get_delayed_branch (sim_cpu *cpu) h8_get_delayed_branch (sim_cpu *cpu)
{ {
return cpu->delayed_branch; return H8300_SIM_CPU (cpu)->delayed_branch;
} }
static void static void
h8_set_delayed_branch (sim_cpu *cpu, unsigned int dest) h8_set_delayed_branch (sim_cpu *cpu, unsigned int dest)
{ {
cpu->delayed_branch = dest; H8300_SIM_CPU (cpu)->delayed_branch = dest;
} }
static char ** static char **
h8_get_command_line (sim_cpu *cpu) h8_get_command_line (sim_cpu *cpu)
{ {
return cpu->command_line; return H8300_SIM_CPU (cpu)->command_line;
} }
static void static void
h8_set_command_line (sim_cpu *cpu, char ** val) h8_set_command_line (sim_cpu *cpu, char ** val)
{ {
cpu->command_line = val; H8300_SIM_CPU (cpu)->command_line = val;
} }
static char * static char *
h8_get_cmdline_arg (sim_cpu *cpu, int index) h8_get_cmdline_arg (sim_cpu *cpu, int index)
{ {
return cpu->command_line[index]; return H8300_SIM_CPU (cpu)->command_line[index];
} }
static void static void
h8_set_cmdline_arg (sim_cpu *cpu, int index, char * val) h8_set_cmdline_arg (sim_cpu *cpu, int index, char * val)
{ {
cpu->command_line[index] = val; H8300_SIM_CPU (cpu)->command_line[index] = val;
} }
/* MAC Saturation Mode */ /* MAC Saturation Mode */
static int static int
h8_get_macS (sim_cpu *cpu) h8_get_macS (sim_cpu *cpu)
{ {
return cpu->macS; return H8300_SIM_CPU (cpu)->macS;
} }
#if 0 #if 0
static void static void
h8_set_macS (sim_cpu *cpu, int val) h8_set_macS (sim_cpu *cpu, int val)
{ {
cpu->macS = (val != 0); H8300_SIM_CPU (cpu)->macS = (val != 0);
} }
#endif #endif
@ -223,39 +223,39 @@ h8_set_macS (sim_cpu *cpu, int val)
static int static int
h8_get_macZ (sim_cpu *cpu) h8_get_macZ (sim_cpu *cpu)
{ {
return cpu->macZ; return H8300_SIM_CPU (cpu)->macZ;
} }
static void static void
h8_set_macZ (sim_cpu *cpu, int val) h8_set_macZ (sim_cpu *cpu, int val)
{ {
cpu->macZ = (val != 0); H8300_SIM_CPU (cpu)->macZ = (val != 0);
} }
/* MAC Negative Flag */ /* MAC Negative Flag */
static int static int
h8_get_macN (sim_cpu *cpu) h8_get_macN (sim_cpu *cpu)
{ {
return cpu->macN; return H8300_SIM_CPU (cpu)->macN;
} }
static void static void
h8_set_macN (sim_cpu *cpu, int val) h8_set_macN (sim_cpu *cpu, int val)
{ {
cpu->macN = (val != 0); H8300_SIM_CPU (cpu)->macN = (val != 0);
} }
/* MAC Overflow Flag */ /* MAC Overflow Flag */
static int static int
h8_get_macV (sim_cpu *cpu) h8_get_macV (sim_cpu *cpu)
{ {
return cpu->macV; return H8300_SIM_CPU (cpu)->macV;
} }
static void static void
h8_set_macV (sim_cpu *cpu, int val) h8_set_macV (sim_cpu *cpu, int val)
{ {
cpu->macV = (val != 0); H8300_SIM_CPU (cpu)->macV = (val != 0);
} }
/* End CPU data object. */ /* End CPU data object. */
@ -1593,7 +1593,7 @@ init_pointers (SIM_DESC sd)
h8_set_mask (cpu, memory_size - 1); h8_set_mask (cpu, memory_size - 1);
memset (h8_get_reg_buf (cpu), 0, sizeof (cpu->regs)); memset (h8_get_reg_buf (cpu), 0, sizeof (H8300_SIM_CPU (cpu)->regs));
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
@ -4592,13 +4592,13 @@ static const OPTION h8300_options[] =
static sim_cia static sim_cia
h8300_pc_get (sim_cpu *cpu) h8300_pc_get (sim_cpu *cpu)
{ {
return cpu->pc; return H8300_SIM_CPU (cpu)->pc;
} }
static void static void
h8300_pc_set (sim_cpu *cpu, sim_cia pc) h8300_pc_set (sim_cpu *cpu, sim_cia pc)
{ {
cpu->pc = pc; H8300_SIM_CPU (cpu)->pc = pc;
} }
/* Cover function of sim_state_free to free the cpu buffers as well. */ /* Cover function of sim_state_free to free the cpu buffers as well. */
@ -4629,7 +4629,8 @@ sim_open (SIM_OPEN_KIND kind,
current_target_byte_order = BFD_ENDIAN_BIG; current_target_byte_order = BFD_ENDIAN_BIG;
/* The cpu data is kept in a separately allocated chunk of memory. */ /* The cpu data is kept in a separately allocated chunk of memory. */
if (sim_cpu_alloc_all (sd, 1) != SIM_RC_OK) if (sim_cpu_alloc_all_extra (sd, 1, sizeof (struct h8300_sim_cpu))
!= SIM_RC_OK)
{ {
free_state (sd); free_state (sd);
return 0; return 0;

View File

@ -5,6 +5,8 @@
#ifndef SIM_MAIN_H #ifndef SIM_MAIN_H
#define SIM_MAIN_H #define SIM_MAIN_H
#define SIM_HAVE_COMMON_SIM_CPU
#define DEBUG #define DEBUG
/* These define the size of main memory for the simulator. /* These define the size of main memory for the simulator.
@ -114,7 +116,7 @@ typedef struct
#endif #endif
} decoded_inst; } decoded_inst;
struct _sim_cpu { struct h8300_sim_cpu {
unsigned int regs[20]; /* 8 GR's plus ZERO, SBR, and VBR. */ unsigned int regs[20]; /* 8 GR's plus ZERO, SBR, and VBR. */
unsigned int pc; unsigned int pc;
@ -128,9 +130,8 @@ struct _sim_cpu {
unsigned char *memory; unsigned char *memory;
int mask; int mask;
sim_cpu_base base;
}; };
#define H8300_SIM_CPU(sd) ((struct h8300_sim_cpu *) CPU_ARCH_DATA (sd))
struct h8300_sim_state { struct h8300_sim_state {
unsigned long memory_size; unsigned long memory_size;
@ -142,8 +143,8 @@ struct h8300_sim_state {
/* The current state of the processor; registers, memory, etc. */ /* The current state of the processor; registers, memory, etc. */
#define cpu_set_pc(CPU, VAL) (((CPU)->pc) = (VAL)) #define cpu_set_pc(cpu, val) (H8300_SIM_CPU (cpu)->pc = (val))
#define cpu_get_pc(CPU) (((CPU)->pc)) #define cpu_get_pc(cpu) (H8300_SIM_CPU (cpu)->pc)
/* Magic numbers used to distinguish an exit from a breakpoint. */ /* Magic numbers used to distinguish an exit from a breakpoint. */
#define LIBC_EXIT_MAGIC1 0xdead #define LIBC_EXIT_MAGIC1 0xdead