This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[PATCH]: Cleanup HC11 simulator
- From: Stephane Carrez <Stephane dot Carrez at worldnet dot fr>
- To: gdb-patches at sources dot redhat dot com
- Date: Thu, 07 Mar 2002 20:10:10 +0100
- Subject: [PATCH]: Cleanup HC11 simulator
Hi!
This patch cleans up the HC11/HC12 simulator to remove some very old,
not finished and not working tentative to maintain a virtual frame pointer
within the simulator (for backtrace to work without the gcc frame).
I've committed this patch on mainline and 5_2 branch.
Stephane
2002-03-07 Stephane Carrez <Stephane.Carrez@worldnet.fr>
* sim-main.h (cpu_frame, cpu_frame_list): Remove.
(cpu_frame_reg, cpu_print_frame): Remove.
(cpu_m68hc11_push_uint8, cpu_m68hc11_pop_uint8): Cleanup.
(cpu_m68hc11_push_uint16, cpu_m68hc11_pop_uint16): Likewise.
(cpu_m68hc12_push_uint8, cpu_m68hc12_push_uint16): Likewise.
(cpu_m68hc12_pop_uint8, cpu_m68hc12_pop_uint16): Likewise.
* m68hc11_sim.c (cpu_find_frame): Remove.
(cpu_create_frame_list): Remove.
(cpu_remove_frame_list, cpu_create_frame, cpu_free_frame): Remove.
(cpu_frame_reg, cpu_print_frame, cpu_update_frame): Remove.
(cpu_call): Cleanup to remove #if HAVE_FRAME and calls to the above.
(cpu_update_frame): Likewise.
(cpu_return): Likewise.
(cpu_reset): Likewise.
(cpu_initialize): Likewise.
* interp.c (sim_do_command): Remove call to cpu_print_frame.
Index: sim-main.h
===================================================================
RCS file: /cvs/src/src/sim/m68hc11/sim-main.h,v
retrieving revision 1.5
diff -u -p -r1.5 sim-main.h
--- sim-main.h 2001/05/20 15:40:27 1.5
+++ sim-main.h 2002/03/07 19:04:57
@@ -1,5 +1,5 @@
/* sim-main.h -- Simulator for Motorola 68HC11 & 68HC12
- Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
Written by Stephane Carrez (stcarrez@worldnet.fr)
This file is part of GDB, the GNU debugger.
@@ -141,33 +141,10 @@ enum M6811_Special
M6812_WAV
};
-#define CPU_POP 1
-#define CPU_PUSH 2
-
#define M6811_MAX_PORTS (0x03f+1)
#define M6812_MAX_PORTS (0x3ff+1)
#define MAX_PORTS (M6812_MAX_PORTS)
-/* Tentative to keep track of the stack frame.
- The frame is updated each time a call or a return are made.
- We also have to take into account changes of stack pointer
- (either thread switch or longjmp). */
-struct cpu_frame
-{
- struct cpu_frame *up;
- uint16 pc;
- uint16 sp_low;
- uint16 sp_high;
-};
-
-/* Represents a list of frames (or a thread). */
-struct cpu_frame_list
-{
- struct cpu_frame_list *next;
- struct cpu_frame_list *prev;
- struct cpu_frame *frame;
-};
-
struct _sim_cpu;
typedef void (* cpu_interp) (struct _sim_cpu*);
@@ -179,10 +156,6 @@ struct _sim_cpu {
/* CPU interrupts. */
struct interrupts cpu_interrupts;
- struct cpu_frame_list *cpu_frames;
- struct cpu_frame_list *cpu_current_frame;
- int cpu_need_update_frame;
-
/* Pointer to the interpretor routine. */
cpu_interp cpu_interpretor;
@@ -433,7 +406,6 @@ cpu_m68hc11_push_uint8 (sim_cpu *proc, u
memory_write8 (proc, addr, val);
proc->cpu_regs.sp = addr - 1;
- proc->cpu_need_update_frame |= CPU_PUSH;
}
inline void
@@ -443,7 +415,6 @@ cpu_m68hc11_push_uint16 (sim_cpu *proc,
memory_write16 (proc, addr, val);
proc->cpu_regs.sp = addr - 1;
- proc->cpu_need_update_frame |= CPU_PUSH;
}
inline uint8
@@ -454,7 +425,6 @@ cpu_m68hc11_pop_uint8 (sim_cpu *proc)
val = memory_read8 (proc, addr + 1);
proc->cpu_regs.sp = addr + 1;
- proc->cpu_need_update_frame |= CPU_POP;
return val;
}
@@ -466,7 +436,6 @@ cpu_m68hc11_pop_uint16 (sim_cpu *proc)
val = memory_read16 (proc, addr + 1);
proc->cpu_regs.sp = addr + 2;
- proc->cpu_need_update_frame |= CPU_POP;
return val;
}
@@ -479,7 +448,6 @@ cpu_m68hc12_push_uint8 (sim_cpu *proc, u
addr --;
memory_write8 (proc, addr, val);
proc->cpu_regs.sp = addr;
- proc->cpu_need_update_frame |= CPU_PUSH;
}
inline void
@@ -490,7 +458,6 @@ cpu_m68hc12_push_uint16 (sim_cpu *proc,
addr -= 2;
memory_write16 (proc, addr, val);
proc->cpu_regs.sp = addr;
- proc->cpu_need_update_frame |= CPU_PUSH;
}
inline uint8
@@ -501,7 +468,6 @@ cpu_m68hc12_pop_uint8 (sim_cpu *proc)
val = memory_read8 (proc, addr);
proc->cpu_regs.sp = addr + 1;
- proc->cpu_need_update_frame |= CPU_POP;
return val;
}
@@ -513,7 +479,6 @@ cpu_m68hc12_pop_uint16 (sim_cpu *proc)
val = memory_read16 (proc, addr);
proc->cpu_regs.sp = addr + 2;
- proc->cpu_need_update_frame |= CPU_POP;
return val;
}
@@ -556,9 +521,7 @@ extern void cpu_info (SIM_DESC sd, sim_c
extern int cpu_initialize (SIM_DESC sd, sim_cpu *cpu);
-extern void cpu_print_frame (SIM_DESC sd, sim_cpu *cpu);
extern void cpu_set_sp (sim_cpu *cpu, uint16 val);
-extern uint16 cpu_frame_reg (sim_cpu *cpu, uint16 rn);
extern int cpu_reset (sim_cpu *cpu);
extern int cpu_restart (sim_cpu *cpu);
extern void sim_memory_error (sim_cpu *cpu, SIM_SIGNAL excep,
Index: m68hc11_sim.c
===================================================================
RCS file: /cvs/src/src/sim/m68hc11/m68hc11_sim.c,v
retrieving revision 1.4
diff -u -p -r1.4 m68hc11_sim.c
--- m68hc11_sim.c 2002/03/07 18:59:38 1.4
+++ m68hc11_sim.c 2002/03/07 19:04:58
@@ -23,8 +23,6 @@ Software Foundation, 59 Temple Place - S
#include "sim-module.h"
#include "sim-options.h"
-void cpu_free_frame (sim_cpu* cpu, struct cpu_frame *frame);
-
enum {
OPTION_CPU_RESET = OPTION_START,
OPTION_EMUL_OS,
@@ -88,213 +86,17 @@ cpu_option_handler (SIM_DESC sd, sim_cpu
return SIM_RC_OK;
}
-/* Tentative to keep track of the cpu frame. */
-struct cpu_frame*
-cpu_find_frame (sim_cpu *cpu, uint16 sp)
-{
- struct cpu_frame_list *flist;
-
- flist = cpu->cpu_frames;
- while (flist)
- {
- struct cpu_frame *frame;
-
- frame = flist->frame;
- while (frame)
- {
- if (frame->sp_low <= sp && frame->sp_high >= sp)
- {
- cpu->cpu_current_frame = flist;
- return frame;
- }
-
- frame = frame->up;
- }
- flist = flist->next;
- }
- return 0;
-}
-
-struct cpu_frame_list*
-cpu_create_frame_list (sim_cpu *cpu)
-{
- struct cpu_frame_list *flist;
-
- flist = (struct cpu_frame_list*) malloc (sizeof (struct cpu_frame_list));
- flist->frame = 0;
- flist->next = cpu->cpu_frames;
- flist->prev = 0;
- if (flist->next)
- flist->next->prev = flist;
- cpu->cpu_frames = flist;
- cpu->cpu_current_frame = flist;
- return flist;
-}
-
-void
-cpu_remove_frame_list (sim_cpu *cpu, struct cpu_frame_list *flist)
-{
- struct cpu_frame *frame;
-
- if (flist->prev == 0)
- cpu->cpu_frames = flist->next;
- else
- flist->prev->next = flist->next;
- if (flist->next)
- flist->next->prev = flist->prev;
-
- frame = flist->frame;
- while (frame)
- {
- struct cpu_frame* up = frame->up;
- cpu_free_frame (cpu, frame);
- frame = up;
- }
- free (flist);
-}
-
-struct cpu_frame*
-cpu_create_frame (sim_cpu *cpu, uint16 pc, uint16 sp)
-{
- struct cpu_frame *frame;
-
- frame = (struct cpu_frame*) malloc (sizeof(struct cpu_frame));
- frame->up = 0;
- frame->pc = pc;
- frame->sp_low = sp;
- frame->sp_high = sp;
- return frame;
-}
-
-void
-cpu_free_frame (sim_cpu *cpu, struct cpu_frame *frame)
-{
- free (frame);
-}
-
-uint16
-cpu_frame_reg (sim_cpu *cpu, uint16 rn)
-{
- struct cpu_frame *frame;
-
- if (cpu->cpu_current_frame == 0)
- return 0;
-
- frame = cpu->cpu_current_frame->frame;
- while (frame)
- {
- if (rn == 0)
- return frame->sp_high;
- frame = frame->up;
- rn--;
- }
- return 0;
-}
-
void
cpu_call (sim_cpu *cpu, uint16 addr)
{
-#if HAVE_FRAME
- uint16 pc = cpu->cpu_insn_pc;
- uint16 sp;
- struct cpu_frame_list *flist;
- struct cpu_frame* frame;
- struct cpu_frame* new_frame;
-#endif
cpu_set_pc (cpu, addr);
-#if HAVE_FRAME
- sp = cpu_get_sp (cpu);
-
- cpu->cpu_need_update_frame = 0;
- flist = cpu->cpu_current_frame;
- if (flist == 0)
- flist = cpu_create_frame_list (cpu);
-
- frame = flist->frame;
- if (frame && frame->sp_low > sp)
- frame->sp_low = sp;
-
- new_frame = cpu_create_frame (cpu, pc, sp);
- new_frame->up = frame;
- flist->frame = new_frame;
-#endif
}
void
-cpu_update_frame (sim_cpu *cpu, int do_create)
-{
-#if HAVE_FRAME
- struct cpu_frame *frame;
-
- frame = cpu_find_frame (cpu, cpu_get_sp (cpu));
- if (frame)
- {
- while (frame != cpu->cpu_current_frame->frame)
- {
- struct cpu_frame* up;
-
- up = cpu->cpu_current_frame->frame->up;
- cpu_free_frame (cpu, cpu->cpu_current_frame->frame);
- cpu->cpu_current_frame->frame = up;
- }
- return;
- }
-
- if (do_create)
- {
- cpu_create_frame_list (cpu);
- frame = cpu_create_frame (cpu, cpu_get_pc (cpu), cpu_get_sp (cpu));
- cpu->cpu_current_frame->frame = frame;
- }
-#endif
-}
-
-void
cpu_return (sim_cpu *cpu)
{
-#if HAVE_FRAME
- uint16 sp = cpu_get_sp (cpu);
- struct cpu_frame *frame;
- struct cpu_frame_list *flist;
-
- cpu->cpu_need_update_frame = 0;
- flist = cpu->cpu_current_frame;
- if (flist && flist->frame && flist->frame->up)
- {
- frame = flist->frame->up;
- if (frame->sp_low <= sp && frame->sp_high >= sp)
- {
- cpu_free_frame (cpu, flist->frame);
- flist->frame = frame;
- return;
- }
- }
- cpu_update_frame (cpu, 1);
-#endif
-}
-
-void
-cpu_print_frame (SIM_DESC sd, sim_cpu *cpu)
-{
- struct cpu_frame* frame;
- int level = 0;
-
- if (cpu->cpu_current_frame == 0 || cpu->cpu_current_frame->frame == 0)
- {
- sim_io_printf (sd, "No frame.\n");
- return;
- }
- sim_io_printf (sd, " # PC SP-L SP-H\n");
- frame = cpu->cpu_current_frame->frame;
- while (frame)
- {
- sim_io_printf (sd, "%3d 0x%04x 0x%04x 0x%04x\n",
- level, frame->pc, frame->sp_low, frame->sp_high);
- frame = frame->up;
- level++;
- }
}
/* Set the stack pointer and re-compute the current frame. */
@@ -302,7 +104,6 @@ void
cpu_set_sp (sim_cpu *cpu, uint16 val)
{
cpu->cpu_regs.sp = val;
- cpu_update_frame (cpu, 0);
}
uint16
@@ -653,8 +454,6 @@ cpu_initialize (SIM_DESC sd, sim_cpu *cp
cpu->cpu_running = 1;
cpu->cpu_stop_on_interrupt = 0;
cpu->cpu_frequency = 8 * 1000 * 1000;
- cpu->cpu_frames = 0;
- cpu->cpu_current_frame = 0;
cpu->cpu_use_elf_start = 0;
cpu->cpu_elf_start = 0;
cpu->cpu_use_local_config = 0;
@@ -671,11 +470,6 @@ cpu_initialize (SIM_DESC sd, sim_cpu *cp
int
cpu_reset (sim_cpu *cpu)
{
- cpu->cpu_need_update_frame = 0;
- cpu->cpu_current_frame = 0;
- while (cpu->cpu_frames)
- cpu_remove_frame_list (cpu, cpu->cpu_frames);
-
/* Initialize the config register.
It is only initialized at reset time. */
memset (cpu->ios, 0, sizeof (cpu->ios));
Index: interp.c
===================================================================
RCS file: /cvs/src/src/sim/m68hc11/interp.c,v
retrieving revision 1.5
diff -u -p -r1.5 interp.c
--- interp.c 2001/07/22 12:33:58 1.5
+++ interp.c 2002/03/07 19:04:58
@@ -1,5 +1,5 @@
-/* interp.c -- Simulator for Motorola 68HC11
- Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+/* interp.c -- Simulator for Motorola 68HC11/68HC12
+ Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
Written by Stephane Carrez (stcarrez@worldnet.fr)
This file is part of GDB, the GNU debugger.
@@ -590,8 +590,6 @@ sim_do_command (SIM_DESC sd, char *cmd)
{
if (strncmp (cmd, "info", sizeof ("info") - 1) == 0)
sim_get_info (sd, &cmd[4]);
- else if (strncmp (cmd, "frame", sizeof ("frame") - 1) == 0)
- cpu_print_frame (sd, STATE_CPU (sd, 0));
else if (strncmp (cmd, mm_cmd, strlen (mm_cmd) == 0))
sim_io_eprintf (sd,
"`memory-map' command replaced by `sim memory'\n");