diff options
Diffstat (limited to 'sim/m68hc11')
-rw-r--r-- | sim/m68hc11/ChangeLog | 54 | ||||
-rw-r--r-- | sim/m68hc11/dv-m68hc11.c | 20 | ||||
-rw-r--r-- | sim/m68hc11/dv-m68hc11sio.c | 5 | ||||
-rw-r--r-- | sim/m68hc11/dv-m68hc11spi.c | 8 | ||||
-rw-r--r-- | sim/m68hc11/dv-m68hc11tim.c | 190 | ||||
-rw-r--r-- | sim/m68hc11/interp.c | 108 | ||||
-rw-r--r-- | sim/m68hc11/interrupts.c | 63 | ||||
-rw-r--r-- | sim/m68hc11/m68hc11_sim.c | 28 | ||||
-rw-r--r-- | sim/m68hc11/sim-main.h | 32 |
9 files changed, 412 insertions, 96 deletions
diff --git a/sim/m68hc11/ChangeLog b/sim/m68hc11/ChangeLog index 9c34d47002b..3d019d76589 100644 --- a/sim/m68hc11/ChangeLog +++ b/sim/m68hc11/ChangeLog @@ -1,3 +1,57 @@ +2003-08-08 Stephane Carrez <stcarrez@nerim.fr> + + * dv-m68hc11tim.c (cycle_to_string): Add flags parameter to better + control the translation. + (m68hc11tim_print_timer): Update cycle_to_string conversion. + (m68hc11tim_timer_event): Fix handling of output + compare register with its interrupts. + (m68hc11tim_io_write_buffer): Check output compare + after setting M6811_TMSK1. + (m68hc11tim_io_read_buffer): Fix compilation warning. + * dv-m68hc11.c (m68hc11_option_handler): Likewise. + * dv-m68hc11spi.c (m68hc11spi_info): Likewise. + * dv-m68hc11sio.c (m68hc11sio_info): Likewise. + * interrupts.c (interrupts_info): Likewise. + (interrupts_reset): Recognize bootstrap mode. + * sim-main.h (PRINT_CYCLE, PRINT_TIME): New defines. + (_sim_cpu): Add cpu_start_mode. + (cycle_to_string): Add flags member. + * m68hc11_sim.c (OPTION_CPU_BOOTSTRAP): New option. + (cpu_options): Declare new option bootstrap. + (cpu_option_handler): Handle it. + (cpu_info): Update call to cycle_to_string. + +2003-08-08 Stephane Carrez <stcarrez@nerim.fr> + + * sim-main.h (phys_to_virt): Use memory bank parameters to translate + the physical address in virtual address. + (struct _sim_cpu): Add memory bank members. + * m68hc11_sim.c (cpu_initialize): Clear memory bank parameters. + * interp.c (sim_hw_configure): Create memory bank according to memory + bank parameters. + (sim_get_bank_parameters): New function to obtain memory bank config + from the symbol table. + (sim_prepare_for_program): Call it to obtain the memory bank parameters. + (sim_open): Call sim_prepare_for_program. + * dv-m68hc11.c (m68hc11cpu_io_write_buffer): Use memory bank parameters + to check if address is within bank window. + (m68hc11cpu_io_read_buffer): Likewise. + (attach_m68hc11_regs): Map the memory bank according to memory bank + parameters. + +2003-08-08 Stephane Carrez <stcarrez@nerim.fr>, + + * sim-main.h (PAGE_REGNUM, Z_REGNUM): Use same numbering as gdb. + +2003-08-08 Stephane Carrez <stcarrez@nerim.fr>, + Gary Piercey <gpiercey@northstar-technical.com> + + * m68hc11_sim.c (print_io_word): New function to print 16-bit value. + * sim-main.h (print_io_word): Declare. + * dv-m68hc11tim.c (tmsk1_desc): New description table for TMSK1. + (tflg1_desc): Likewise for TFLG1. + (m68hc11tim_info): Print input and output compare registers + 2003-03-02 Stephane Carrez <stcarrez@nerim.fr> * Makefile.in (SIM_EXTRA_CFLAGS): Set WITH_TARGET_ADDRESS_BITSIZE diff --git a/sim/m68hc11/dv-m68hc11.c b/sim/m68hc11/dv-m68hc11.c index 669a045357a..5cc716182bc 100644 --- a/sim/m68hc11/dv-m68hc11.c +++ b/sim/m68hc11/dv-m68hc11.c @@ -1,5 +1,5 @@ /* dv-m68hc11.c -- CPU 68HC11&68HC12 as a device. - Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. Written by Stephane Carrez (stcarrez@nerim.fr) (From a driver model Contributed by Cygnus Solutions.) @@ -324,8 +324,8 @@ attach_m68hc11_regs (struct hw *me, if (hw_find_property (me, "use_bank") != NULL) hw_attach_address (hw_parent (me), 0, exec_map, - 0x08000, - 0x04000, + cpu->bank_start, + cpu->bank_end - cpu->bank_start, me); cpu_mode = "expanded"; @@ -808,13 +808,15 @@ m68hc11_option_handler (SIM_DESC sd, sim_cpu *cpu, " %d %d %35.35s\n", osc->name, freq, cur_value, next_value, - cycle_to_string (cpu, t)); + cycle_to_string (cpu, t, + PRINT_TIME | PRINT_CYCLE)); else sim_io_printf (sd, " %4.4s %8.8s hz " " %d %d %35.35s\n", osc->name, freq, cur_value, next_value, - cycle_to_string (cpu, t)); + cycle_to_string (cpu, t, + PRINT_TIME | PRINT_CYCLE)); } } break; @@ -843,7 +845,7 @@ m68hc11cpu_io_read_buffer (struct hw *me, sd = hw_system (me); cpu = STATE_CPU (sd, 0); - if (base >= 0x8000 && base < 0xc000) + if (base >= cpu->bank_start && base < cpu->bank_end) { address_word virt_addr = phys_to_virt (cpu, base); if (virt_addr != base) @@ -864,7 +866,7 @@ m68hc11cpu_io_read_buffer (struct hw *me, break; memcpy (dest, &cpu->ios[base], 1); - dest++; + dest = (char*) dest + 1; base++; byte++; nr_bytes--; @@ -1091,7 +1093,7 @@ m68hc11cpu_io_write_buffer (struct hw *me, sd = hw_system (me); cpu = STATE_CPU (sd, 0); - if (base >= 0x8000 && base < 0xc000) + if (base >= cpu->bank_start && base < cpu->bank_end) { address_word virt_addr = phys_to_virt (cpu, base); if (virt_addr != base) @@ -1113,7 +1115,7 @@ m68hc11cpu_io_write_buffer (struct hw *me, val = *((uint8*) source); m68hc11cpu_io_write (me, cpu, base, val); - source++; + source = (char*) source + 1; base++; byte++; nr_bytes--; diff --git a/sim/m68hc11/dv-m68hc11sio.c b/sim/m68hc11/dv-m68hc11sio.c index ec7a46de506..655a6dbe0d1 100644 --- a/sim/m68hc11/dv-m68hc11sio.c +++ b/sim/m68hc11/dv-m68hc11sio.c @@ -463,7 +463,8 @@ m68hc11sio_info (struct hw *me) n = (clock_cycle - t) / controller->baud_cycle; n = controller->data_length - n; sim_io_printf (sd, " Transmit finished in %s (%d bit%s)\n", - cycle_to_string (cpu, t), n, (n > 1 ? "s" : "")); + cycle_to_string (cpu, t, PRINT_TIME | PRINT_CYCLE), + n, (n > 1 ? "s" : "")); } if (controller->rx_poll_event) { @@ -471,7 +472,7 @@ m68hc11sio_info (struct hw *me) t = hw_event_remain_time (me, controller->rx_poll_event); sim_io_printf (sd, " Receive finished in %s\n", - cycle_to_string (cpu, t)); + cycle_to_string (cpu, t, PRINT_TIME | PRINT_CYCLE)); } } diff --git a/sim/m68hc11/dv-m68hc11spi.c b/sim/m68hc11/dv-m68hc11spi.c index 5f5e0bbe9cb..619a2d31fcb 100644 --- a/sim/m68hc11/dv-m68hc11spi.c +++ b/sim/m68hc11/dv-m68hc11spi.c @@ -1,6 +1,6 @@ /* dv-m68hc11spi.c -- Simulation of the 68HC11 SPI - Copyright (C) 2000, 2002 Free Software Foundation, Inc. - Written by Stephane Carrez (stcarrez@worldnet.fr) + Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc. + Written by Stephane Carrez (stcarrez@nerim.fr) (From a driver model Contributed by Cygnus Solutions.) This file is part of the program GDB, the GNU debugger. @@ -358,11 +358,11 @@ m68hc11spi_info (struct hw *me) controller->tx_bit + 1); t = hw_event_remain_time (me, controller->spi_event); sim_io_printf (sd, " SPI current bit-cycle finished in %s\n", - cycle_to_string (cpu, t)); + cycle_to_string (cpu, t, PRINT_TIME | PRINT_CYCLE)); t += (controller->tx_bit + 1) * 2 * controller->clock; sim_io_printf (sd, " SPI operation finished in %s\n", - cycle_to_string (cpu, t)); + cycle_to_string (cpu, t, PRINT_TIME | PRINT_CYCLE)); } } diff --git a/sim/m68hc11/dv-m68hc11tim.c b/sim/m68hc11/dv-m68hc11tim.c index 3edcac068a3..0456f678912 100644 --- a/sim/m68hc11/dv-m68hc11tim.c +++ b/sim/m68hc11/dv-m68hc11tim.c @@ -1,6 +1,6 @@ /* dv-m68hc11tim.c -- Simulation of the 68HC11 timer devices. - Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. - Written by Stephane Carrez (stcarrez@worldnet.fr) + Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc. + Written by Stephane Carrez (stcarrez@nerim.fr) (From a driver model Contributed by Cygnus Solutions.) This file is part of the program GDB, the GNU debugger. @@ -25,7 +25,7 @@ #include "sim-main.h" #include "hw-main.h" #include "sim-assert.h" - +#include <limits.h> /* DEVICE @@ -250,7 +250,9 @@ m68hc11tim_timer_event (struct hw *me, void *data) unsigned mask; unsigned flags; unsigned long tcnt_internal; - unsigned long tcnt; + unsigned long tcnt, tcnt_prev; + signed64 tcnt_insn_end; + signed64 tcnt_insn_start; int i; sim_events *events; @@ -289,11 +291,8 @@ m68hc11tim_timer_event (struct hw *me, void *data) break; case OVERFLOW_EVENT: - /* Compute the 68HC11 internal free running counter. - There may be 'nr_ticks_to_process' pending cycles that are - not (yet) taken into account by 'sim_events_time'. */ - tcnt_internal = sim_events_time (sd) - controller->tcnt_adjust; - tcnt_internal += events->nr_ticks_to_process; + /* Compute the 68HC11 internal free running counter. */ + tcnt_internal = (cpu->cpu_absolute_cycle - controller->tcnt_adjust); /* We must take into account the prescaler that comes before the counter (it's a power of 2). */ @@ -316,22 +315,22 @@ m68hc11tim_timer_event (struct hw *me, void *data) break; case COMPARE_EVENT: - eventp = &controller->cmp_timer_event; + /* Compute value of TCNT register (64-bit precision) at beginning + and end of instruction. */ + tcnt_insn_end = (cpu->cpu_absolute_cycle - controller->tcnt_adjust); + tcnt_insn_start = (tcnt_insn_end - cpu->cpu_current_cycle); + + /* TCNT value at beginning of current instruction. */ + tcnt_prev = (tcnt_insn_start / controller->clock_prescaler) & 0x0ffff; - /* Compute the 68HC11 internal free running counter. - There may be 'nr_ticks_to_process' pending cycles that are - not (yet) taken into account by 'sim_events_time'. */ - events = STATE_EVENTS (sd); - tcnt_internal = sim_events_time (sd) - controller->tcnt_adjust; - tcnt_internal += events->nr_ticks_to_process; + /* TCNT value at end of current instruction. */ + tcnt = (tcnt_insn_end / controller->clock_prescaler) & 0x0ffff; /* We must take into account the prescaler that comes before the counter (it's a power of 2). */ + tcnt_internal = tcnt_insn_end; tcnt_internal &= 0x0ffff * controller->clock_prescaler; - /* Get current visible TCNT register value. */ - tcnt = tcnt_internal / controller->clock_prescaler; - flags = cpu->ios[M6811_TMSK1]; mask = 0x80; delay = 65536 * controller->clock_prescaler; @@ -342,12 +341,28 @@ m68hc11tim_timer_event (struct hw *me, void *data) for (i = M6811_TOC1; i <= M6811_TOC5; i += 2, mask >>= 1) { unsigned long compare; - - compare = (cpu->ios[i] << 8) + cpu->ios[i+1]; - if (compare == tcnt && (flags & mask)) + + compare = (cpu->ios[i] << 8) + cpu->ios[i + 1]; + + /* See if compare is reached; handle wrap arround. */ + if ((compare >= tcnt_prev && compare <= tcnt && tcnt_prev < tcnt) + || (compare >= tcnt_prev && tcnt_prev > tcnt) + || (compare < tcnt && tcnt_prev > tcnt)) { + unsigned dt; + + if (compare > tcnt) + dt = 0x10000 - compare - tcnt; + else + dt = tcnt - compare; + cpu->ios[M6811_TFLG1] |= mask; - check_interrupt++; + + /* Raise interrupt now at the correct CPU cycle so that + we can find the interrupt latency. */ + cpu->cpu_absolute_cycle -= dt; + interrupts_update_pending (&cpu->cpu_interrupts); + cpu->cpu_absolute_cycle += dt; } /* Compute how many times for the next match. @@ -359,14 +374,18 @@ m68hc11tim_timer_event (struct hw *me, void *data) else compare = compare - tcnt_internal + 65536 * controller->clock_prescaler; - + if (compare < delay) delay = compare; } /* Deactivate the compare timer if no output compare is enabled. */ - if ((flags & 0xF0) == 0) + if ((flags & 0xF8) == 0) delay = 0; + else + delay += events->nr_ticks_to_process; + + eventp = &controller->cmp_timer_event; break; default: @@ -394,6 +413,30 @@ m68hc11tim_timer_event (struct hw *me, void *data) /* Descriptions of the Timer I/O ports. These descriptions are only used to give information of the Timer device under GDB. */ +io_reg_desc tmsk1_desc[] = { + { M6811_OC1I, "OC1I ", "Timer Output Compare 1 Interrupt Enable" }, + { M6811_OC2I, "OC2I ", "Timer Output Compare 2 Interrupt Enable" }, + { M6811_OC3I, "OC3I ", "Timer Output Compare 3 Interrupt Enable" }, + { M6811_OC4I, "OC4I ", "Timer Output Compare 4 Interrupt Enable" }, + { M6811_OC5I, "OC5I ", "Timer Input Capture 4 / Output Compare 5 Enable" }, + { M6811_IC1I, "IC1I ", "Timer Input Capture 1 Interrupt Enable" }, + { M6811_IC2I, "IC2I ", "Timer Input Capture 2 Interrupt Enable" }, + { M6811_IC3I, "IC3I ", "Timer Input Capture 3 Interrupt Enable" }, + { 0, 0, 0 } +}; + +io_reg_desc tflg1_desc[] = { + { M6811_OC1F, "OC1F ", "Timer Output Compare 1 Interrupt Flag" }, + { M6811_OC2F, "OC2F ", "Timer Output Compare 2 Interrupt Flag" }, + { M6811_OC3F, "OC3F ", "Timer Output Compare 3 Interrupt Flag" }, + { M6811_OC4F, "OC4F ", "Timer Output Compare 4 Interrupt Flag" }, + { M6811_OC5F, "OC5F ", "Timer Input Capture 4 / Output Compare 5 Flag" }, + { M6811_IC1F, "IC1F ", "Timer Input Capture 1 Interrupt Flag" }, + { M6811_IC2F, "IC2F ", "Timer Input Capture 2 Interrupt Flag" }, + { M6811_IC3F, "IC3F ", "Timer Input Capture 3 Interrupt Flag" }, + { 0, 0, 0 } +}; + io_reg_desc tmsk2_desc[] = { { M6811_TOI, "TOI ", "Timer Overflow Interrupt Enable" }, { M6811_RTII, "RTII ", "RTI Interrupt Enable" }, @@ -433,22 +476,35 @@ to_realtime (sim_cpu *cpu, signed64 t) } const char* -cycle_to_string (sim_cpu *cpu, signed64 t) +cycle_to_string (sim_cpu *cpu, signed64 t, int flags) { - double dt; - char tbuf[32]; + char time_buf[32]; + char cycle_buf[32]; static char buf[64]; - dt = to_realtime (cpu, t); - if (dt < 0.001) - sprintf (tbuf, "(%3.1f us)", dt * 1000000.0); - else if (dt < 1.0) - sprintf (tbuf, "(%3.1f ms)", dt * 1000.0); - else - sprintf (tbuf, "(%3.1f s)", dt); + time_buf[0] = 0; + cycle_buf[0] = 0; + if (flags & PRINT_TIME) + { + double dt; + + dt = to_realtime (cpu, t); + if (dt < 0.001) + sprintf (time_buf, " (%3.1f us)", dt * 1000000.0); + else if (dt < 1.0) + sprintf (time_buf, " (%3.1f ms)", dt * 1000.0); + else + sprintf (time_buf, " (%3.1f s)", dt); + } + + if (flags & PRINT_CYCLE) + sprintf (cycle_buf, " cycle%s", + (t > 1 ? "s" : "")); - sprintf (buf, "%llu cycle%s %10.10s", t, - (t > 1 ? "s" : ""), tbuf); + if (t < LONG_MAX) + sprintf (buf, "%9lu%s%s", (unsigned long) t, cycle_buf, time_buf); + else + sprintf (buf, "%llu%s%s", t, cycle_buf, time_buf); return buf; } @@ -472,7 +528,7 @@ m68hc11tim_print_timer (struct hw *me, const char *name, t = hw_event_remain_time (me, event); sim_io_printf (sd, " Next %s interrupt in %s\n", - name, cycle_to_string (cpu, t)); + name, cycle_to_string (cpu, t, PRINT_TIME | PRINT_CYCLE)); } } @@ -484,6 +540,7 @@ m68hc11tim_info (struct hw *me) sim_cpu *cpu; struct m68hc11tim *controller; uint8 val; + uint16 val16; sd = hw_system (me); cpu = STATE_CPU (sd, 0); @@ -493,6 +550,56 @@ m68hc11tim_info (struct hw *me) base = cpu_get_io_base (cpu); + /* Info for TIC1 */ + val16 = (cpu->ios[M6811_TIC1_H] << 8) + cpu->ios[M6811_TIC1_L]; + print_io_word (sd, "TIC1 ", 0, val16, base + M6811_TIC1); + sim_io_printf (sd, "\n"); + + /* Info for TIC2 */ + val16 = (cpu->ios[M6811_TIC2_H] << 8) + cpu->ios[M6811_TIC2_L]; + print_io_word (sd, "TIC2 ", 0, val16, base + M6811_TIC2); + sim_io_printf (sd, "\n"); + + /* Info for TIC3 */ + val16 = (cpu->ios[M6811_TIC3_H] << 8) + cpu->ios[M6811_TIC3_L]; + print_io_word (sd, "TIC3 ", 0, val16, base + M6811_TIC3); + sim_io_printf (sd, "\n"); + + /* Info for TOC1 */ + val16 = (cpu->ios[M6811_TOC1_H] << 8) + cpu->ios[M6811_TOC1_L]; + print_io_word (sd, "TOC1 ", 0, val16, base + M6811_TOC1); + sim_io_printf (sd, "\n"); + + /* Info for TOC2 */ + val16 = (cpu->ios[M6811_TOC2_H] << 8) + cpu->ios[M6811_TOC2_L]; + print_io_word (sd, "TOC2 ", 0, val16, base + M6811_TOC2); + sim_io_printf (sd, "\n"); + + /* Info for TOC3 */ + val16 = (cpu->ios[M6811_TOC3_H] << 8) + cpu->ios[M6811_TOC3_L]; + print_io_word (sd, "TOC3 ", 0, val16, base + M6811_TOC3); + sim_io_printf (sd, "\n"); + + /* Info for TOC4 */ + val16 = (cpu->ios[M6811_TOC4_H] << 8) + cpu->ios[M6811_TOC4_L]; + print_io_word (sd, "TOC4 ", 0, val16, base + M6811_TOC4); + sim_io_printf (sd, "\n"); + + /* Info for TOC5 */ + val16 = (cpu->ios[M6811_TOC5_H] << 8) + cpu->ios[M6811_TOC5_L]; + print_io_word (sd, "TOC5 ", 0, val16, base + M6811_TOC5); + sim_io_printf (sd, "\n"); + + /* Info for TMSK1 */ + val = cpu->ios[M6811_TMSK1]; + print_io_byte (sd, "TMSK1 ", tmsk1_desc, val, base + M6811_TMSK1); + sim_io_printf (sd, "\n"); + + /* Info for TFLG1 */ + val = cpu->ios[M6811_TFLG1]; + print_io_byte (sd, "TFLG1", tflg1_desc, val, base + M6811_TFLG1); + sim_io_printf (sd, "\n"); + val = cpu->ios[M6811_TMSK2]; print_io_byte (sd, "TMSK2 ", tmsk2_desc, val, base + M6811_TMSK2); sim_io_printf (sd, "\n"); @@ -568,7 +675,7 @@ m68hc11tim_io_read_buffer (struct hw *me, break; } *((unsigned8*) dest) = val; - dest++; + dest = (char*) dest + 1; base++; nr_bytes--; cnt++; @@ -679,6 +786,7 @@ m68hc11tim_io_write_buffer (struct hw *me, case M6811_TMSK1: cpu->ios[M6811_TMSK1] = val; interrupts_update_pending (&cpu->cpu_interrupts); + reset_compare = 1; break; case M6811_TFLG1: @@ -695,7 +803,7 @@ m68hc11tim_io_write_buffer (struct hw *me, cpu->ios[base] = val; reset_compare = 1; break; - + case M6811_TCTL1: case M6811_TCTL2: cpu->ios[base] = val; @@ -709,7 +817,7 @@ m68hc11tim_io_write_buffer (struct hw *me, base++; nr_bytes--; cnt++; - source++; + source = (char*) source + 1; } /* Re-compute the next timer compare event. */ diff --git a/sim/m68hc11/interp.c b/sim/m68hc11/interp.c index 3da382d88ad..b80bc940089 100644 --- a/sim/m68hc11/interp.c +++ b/sim/m68hc11/interp.c @@ -1,5 +1,5 @@ /* interp.c -- Simulator for Motorola 68HC11/68HC12 - Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. Written by Stephane Carrez (stcarrez@nerim.fr) This file is part of GDB, the GNU debugger. @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "hw-tree.h" #include "hw-device.h" #include "hw-ports.h" +#include "elf32-m68hc1x.h" #ifndef MONITOR_BASE # define MONITOR_BASE (0x0C000) @@ -194,8 +195,17 @@ sim_hw_configure (SIM_DESC sd) sim_do_commandf (sd, "memory region 0x000@%d,0x8000", M6811_RAM_LEVEL); sim_hw_parse (sd, "/m68hc11/reg 0x1000 0x03F"); + if (cpu->bank_start < cpu->bank_end) + { + sim_do_commandf (sd, "memory region 0x%lx@%d,0x100000", + cpu->bank_virtual, M6811_RAM_LEVEL); + sim_hw_parse (sd, "/m68hc11/use_bank 1"); + } } - + if (cpu->cpu_start_mode) + { + sim_hw_parse (sd, "/m68hc11/mode %s", cpu->cpu_start_mode); + } if (hw_tree_find_property (device_tree, "/m68hc11/m68hc11sio/reg") == 0) { sim_hw_parse (sd, "/m68hc11/m68hc11sio/reg 0x2b 0x5"); @@ -242,14 +252,16 @@ sim_hw_configure (SIM_DESC sd) { /* Allocate core external memory. */ sim_do_commandf (sd, "memory region 0x%lx@%d,0x%lx", - 0xC000, M6811_RAM_LEVEL, 0x4000); + 0x8000, M6811_RAM_LEVEL, 0x8000); sim_do_commandf (sd, "memory region 0x000@%d,0x8000", M6811_RAM_LEVEL); - sim_do_commandf (sd, "memory region 0x01000000@%d,0x100000", - M6811_RAM_LEVEL); - + if (cpu->bank_start < cpu->bank_end) + { + sim_do_commandf (sd, "memory region 0x%lx@%d,0x100000", + cpu->bank_virtual, M6811_RAM_LEVEL); + sim_hw_parse (sd, "/m68hc12/use_bank 1"); + } sim_hw_parse (sd, "/m68hc12/reg 0x0 0x3FF"); - sim_hw_parse (sd, "/m68hc12/use_bank 1"); } if (!hw_tree_find_property (device_tree, "/m68hc12/m68hc12sio@1/reg")) @@ -294,19 +306,77 @@ sim_hw_configure (SIM_DESC sd) return 1; } +/* Get the memory bank parameters by looking at the global symbols + defined by the linker. */ static int -sim_prepare_for_program (SIM_DESC sd, struct bfd* abfd) +sim_get_bank_parameters (SIM_DESC sd, bfd* abfd) { sim_cpu *cpu; + long symsize; + long symbol_count, i; + unsigned size; + asymbol** asymbols; + asymbol** current; cpu = STATE_CPU (sd, 0); - if (!sim_hw_configure (sd)) - return SIM_RC_FAIL; + symsize = bfd_get_symtab_upper_bound (abfd); + if (symsize < 0) + { + 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; + for (i = 0, current = asymbols; i < symbol_count; i++, current++) + { + const char* name = bfd_asymbol_name (*current); + + if (strcmp (name, BFD_M68HC11_BANK_START_NAME) == 0) + { + cpu->bank_start = bfd_asymbol_value (*current); + } + 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_shift = 0; + for (; size > 1; size >>= 1) + cpu->bank_shift++; + + return 0; +} + +static int +sim_prepare_for_program (SIM_DESC sd, bfd* abfd) +{ + sim_cpu *cpu; + int elf_flags = 0; + + cpu = STATE_CPU (sd, 0); if (abfd != NULL) { asection *s; + + if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) + elf_flags = elf_elfheader (abfd)->e_flags; + cpu->cpu_elf_start = bfd_get_start_address (abfd); /* See if any section sets the reset address */ cpu->cpu_use_elf_start = 1; @@ -331,8 +401,17 @@ sim_prepare_for_program (SIM_DESC sd, struct bfd* abfd) } } } + + if (elf_flags & E_M68HC12_BANKS) + { + if (sim_get_bank_parameters (sd, abfd) != 0) + sim_io_eprintf (sd, "Memory bank parameters are not initialized\n"); + } } + if (!sim_hw_configure (sd)) + return SIM_RC_FAIL; + /* reset all state information */ sim_board_reset (sd); @@ -341,7 +420,7 @@ sim_prepare_for_program (SIM_DESC sd, struct bfd* abfd) SIM_DESC sim_open (SIM_OPEN_KIND kind, host_callback *callback, - struct bfd *abfd, char **argv) + bfd *abfd, char **argv) { SIM_DESC sd; sim_cpu *cpu; @@ -398,8 +477,11 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, free_state (sd); return 0; } - - sim_hw_configure (sd); + if (sim_prepare_for_program (sd, abfd) != SIM_RC_OK) + { + free_state (sd); + return 0; + } /* Fudge our descriptor. */ return sd; diff --git a/sim/m68hc11/interrupts.c b/sim/m68hc11/interrupts.c index 5844c74ea12..b466d69dac9 100644 --- a/sim/m68hc11/interrupts.c +++ b/sim/m68hc11/interrupts.c @@ -1,6 +1,6 @@ /* interrupts.c -- 68HC11 Interrupts Emulation - Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc. - Written by Stephane Carrez (stcarrez@worldnet.fr) + Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. + Written by Stephane Carrez (stcarrez@nerim.fr) This file is part of GDB, GAS, and the GNU binutils. @@ -166,6 +166,20 @@ interrupts_reset (struct interrupts *interrupts) memset (interrupts->interrupts, 0, sizeof (interrupts->interrupts)); + + /* In bootstrap mode, initialize the vector table to point + to the RAM location. */ + if (interrupts->cpu->cpu_mode == M6811_SMOD) + { + bfd_vma addr = interrupts->vectors_addr; + uint16 vector = 0x0100 - 3 * (M6811_INT_NUMBER - 1); + for (i = 0; i < M6811_INT_NUMBER; i++) + { + memory_write16 (interrupts->cpu, addr, vector); + addr += 2; + vector += 3; + } + } } static int @@ -517,7 +531,7 @@ interrupts_raise (struct interrupts *interrupts, enum M6811_INT number) void interrupts_info (SIM_DESC sd, struct interrupts *interrupts) { - signed64 t; + signed64 t, prev_interrupt; int i; sim_io_printf (sd, "Interrupts Info:\n"); @@ -533,21 +547,25 @@ interrupts_info (SIM_DESC sd, struct interrupts *interrupts) interrupts->max_mask_cycles = t; sim_io_printf (sd, " Current interrupts masked sequence: %s\n", - cycle_to_string (interrupts->cpu, t)); + cycle_to_string (interrupts->cpu, t, + PRINT_TIME | PRINT_CYCLE)); } t = interrupts->min_mask_cycles == CYCLES_MAX ? interrupts->max_mask_cycles : interrupts->min_mask_cycles; sim_io_printf (sd, " Shortest interrupts masked sequence: %s\n", - cycle_to_string (interrupts->cpu, t)); + cycle_to_string (interrupts->cpu, t, + PRINT_TIME | PRINT_CYCLE)); t = interrupts->max_mask_cycles; sim_io_printf (sd, " Longest interrupts masked sequence: %s\n", - cycle_to_string (interrupts->cpu, t)); + cycle_to_string (interrupts->cpu, t, + PRINT_TIME | PRINT_CYCLE)); t = interrupts->last_mask_cycles; sim_io_printf (sd, " Last interrupts masked sequence: %s\n", - cycle_to_string (interrupts->cpu, t)); + cycle_to_string (interrupts->cpu, t, + PRINT_TIME | PRINT_CYCLE)); if (interrupts->xirq_start_mask_cycle >= 0) { @@ -558,22 +576,26 @@ interrupts_info (SIM_DESC sd, struct interrupts *interrupts) interrupts->xirq_max_mask_cycles = t; sim_io_printf (sd, " XIRQ Current interrupts masked sequence: %s\n", - cycle_to_string (interrupts->cpu, t)); + cycle_to_string (interrupts->cpu, t, + PRINT_TIME | PRINT_CYCLE)); } t = interrupts->xirq_min_mask_cycles == CYCLES_MAX ? interrupts->xirq_max_mask_cycles : interrupts->xirq_min_mask_cycles; sim_io_printf (sd, " XIRQ Min interrupts masked sequence: %s\n", - cycle_to_string (interrupts->cpu, t)); + cycle_to_string (interrupts->cpu, t, + PRINT_TIME | PRINT_CYCLE)); t = interrupts->xirq_max_mask_cycles; sim_io_printf (sd, " XIRQ Max interrupts masked sequence: %s\n", - cycle_to_string (interrupts->cpu, t)); + cycle_to_string (interrupts->cpu, t, + PRINT_TIME | PRINT_CYCLE)); t = interrupts->xirq_last_mask_cycles; sim_io_printf (sd, " XIRQ Last interrupts masked sequence: %s\n", - cycle_to_string (interrupts->cpu, t)); + cycle_to_string (interrupts->cpu, t, + PRINT_TIME | PRINT_CYCLE)); if (interrupts->pending_mask) { @@ -590,6 +612,9 @@ interrupts_info (SIM_DESC sd, struct interrupts *interrupts) sim_io_printf (sd, "\n"); } + prev_interrupt = 0; + sim_io_printf (sd, "N Interrupt Cycle Taken Latency" + " Delta between interrupts\n"); for (i = 0; i < MAX_INT_HISTORY; i++) { int which; @@ -604,10 +629,18 @@ interrupts_info (SIM_DESC sd, struct interrupts *interrupts) break; dt = h->taken_cycle - h->raised_cycle; - sim_io_printf (sd, "%2d %-10.10s %30.30s ", i, + sim_io_printf (sd, "%2d %-9.9s %15.15s ", i, interrupt_names[h->type], - cycle_to_string (interrupts->cpu, h->taken_cycle)); - sim_io_printf (sd, "%s\n", - cycle_to_string (interrupts->cpu, dt)); + cycle_to_string (interrupts->cpu, h->taken_cycle, 0)); + sim_io_printf (sd, "%15.15s", + cycle_to_string (interrupts->cpu, dt, 0)); + if (prev_interrupt) + { + dt = prev_interrupt - h->taken_cycle; + sim_io_printf (sd, " %s", + cycle_to_string (interrupts->cpu, dt, PRINT_TIME)); + } + sim_io_printf (sd, "\n"); + prev_interrupt = h->taken_cycle; } } diff --git a/sim/m68hc11/m68hc11_sim.c b/sim/m68hc11/m68hc11_sim.c index fe5985f8f1c..444147b9492 100644 --- a/sim/m68hc11/m68hc11_sim.c +++ b/sim/m68hc11/m68hc11_sim.c @@ -1,5 +1,5 @@ /* m6811_cpu.c -- 68HC11&68HC12 CPU Emulation - Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. Written by Stephane Carrez (stcarrez@nerim.fr) This file is part of GDB, GAS, and the GNU binutils. @@ -27,6 +27,7 @@ enum { OPTION_CPU_RESET = OPTION_START, OPTION_EMUL_OS, OPTION_CPU_CONFIG, + OPTION_CPU_BOOTSTRAP, OPTION_CPU_MODE }; @@ -46,6 +47,10 @@ static const OPTION cpu_options[] = '\0', NULL, "Specify the initial CPU configuration register", cpu_option_handler }, + { {"bootstrap", no_argument, NULL, OPTION_CPU_BOOTSTRAP }, + '\0', NULL, "Start the processing in bootstrap mode", + cpu_option_handler }, + { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL } }; @@ -77,7 +82,11 @@ cpu_option_handler (SIM_DESC sd, sim_cpu *cpu, else cpu->cpu_use_local_config = 0; break; - + + case OPTION_CPU_BOOTSTRAP: + cpu->cpu_start_mode = "bootstrap"; + break; + case OPTION_CPU_MODE: break; } @@ -464,6 +473,9 @@ cpu_initialize (SIM_DESC sd, sim_cpu *cpu) cpu->cpu_use_elf_start = 0; cpu->cpu_elf_start = 0; cpu->cpu_use_local_config = 0; + cpu->bank_start = 0; + cpu->bank_end = 0; + cpu->bank_shift = 0; cpu->cpu_config = M6811_NOSEC | M6811_NOCOP | M6811_ROMON | M6811_EEON; interrupts_initialize (sd, cpu); @@ -582,6 +594,15 @@ print_io_byte (SIM_DESC sd, const char *name, io_reg_desc *desc, } void +print_io_word (SIM_DESC sd, const char *name, io_reg_desc *desc, + uint16 val, uint16 addr) +{ + sim_io_printf (sd, " %-9.9s @ 0x%04x 0x%04x ", name, addr, val); + if (desc) + print_io_reg_desc (sd, desc, val, 0); +} + +void cpu_ccr_update_tst8 (sim_cpu *proc, uint8 val) { cpu_set_ccr_V (proc, 0); @@ -1037,7 +1058,8 @@ cpu_info (SIM_DESC sd, sim_cpu *cpu) { sim_io_printf (sd, "CPU info:\n"); sim_io_printf (sd, " Absolute cycle: %s\n", - cycle_to_string (cpu, cpu->cpu_absolute_cycle)); + cycle_to_string (cpu, cpu->cpu_absolute_cycle, + PRINT_TIME | PRINT_CYCLE)); sim_io_printf (sd, " Syscall emulation: %s\n", cpu->cpu_emul_syscall ? "yes, via 0xcd <n>" : "no"); diff --git a/sim/m68hc11/sim-main.h b/sim/m68hc11/sim-main.h index c8933a0791f..a4bd3a62bf8 100644 --- a/sim/m68hc11/sim-main.h +++ b/sim/m68hc11/sim-main.h @@ -1,5 +1,5 @@ /* sim-main.h -- Simulator for Motorola 68HC11 & 68HC12 - Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. Written by Stephane Carrez (stcarrez@nerim.fr) This file is part of GDB, the GNU debugger. @@ -79,8 +79,8 @@ enum cpu_type #define A_REGNUM 5 #define B_REGNUM 6 #define PSW_REGNUM 7 -#define Z_REGNUM 8 -#define PAGE_REGNUM 9 +#define PAGE_REGNUM 8 +#define Z_REGNUM 9 typedef struct m6811_regs { unsigned short d; @@ -108,6 +108,8 @@ extern void print_io_reg_desc (SIM_DESC sd, io_reg_desc *desc, int val, int mode); extern void print_io_byte (SIM_DESC sd, const char *name, io_reg_desc *desc, uint8 val, uint16 addr); +extern void print_io_word (SIM_DESC sd, const char *name, + io_reg_desc *desc, uint16 val, uint16 addr); /* List of special 68HC11&68HC12 instructions that are not handled by the @@ -198,6 +200,7 @@ struct _sim_cpu { /* The mode in which the CPU is configured (MODA and MODB pins). */ unsigned int cpu_mode; + const char* cpu_start_mode; /* The cpu being configured. */ enum cpu_type cpu_type; @@ -208,6 +211,14 @@ struct _sim_cpu { uint8 ios[MAX_PORTS]; + /* Memory bank parameters which describe how the memory bank window + is mapped in memory and how to convert it in virtual address. */ + uint16 bank_start; + uint16 bank_end; + address_word bank_virtual; + unsigned bank_shift; + + struct hw *hw_cpu; /* ... base type ... */ @@ -235,7 +246,7 @@ struct _sim_cpu { #define cpu_get_sp(PROC) ((PROC)->cpu_regs.sp) #define cpu_get_a(PROC) ((PROC->cpu_regs.d >> 8) & 0x0FF) #define cpu_get_b(PROC) ((PROC->cpu_regs.d) & 0x0FF) -#define cpu_get_page(PROC) (PROC->cpu_regs.page) +#define cpu_get_page(PROC) ((PROC)->cpu_regs.page) /* 68HC12 specific and Motorola internal registers. */ #define cpu_get_tmp3(PROC) (0) @@ -244,7 +255,7 @@ struct _sim_cpu { #define cpu_set_d(PROC,VAL) (((PROC)->cpu_regs.d) = (VAL)) #define cpu_set_x(PROC,VAL) (((PROC)->cpu_regs.ix) = (VAL)) #define cpu_set_y(PROC,VAL) (((PROC)->cpu_regs.iy) = (VAL)) -#define cpu_set_page(PROC,VAL) ((PROC->cpu_regs.page) = (VAL)) +#define cpu_set_page(PROC,VAL) (((PROC)->cpu_regs.page) = (VAL)) /* 68HC12 specific and Motorola internal registers. */ #define cpu_set_tmp3(PROC,VAL) (0) @@ -295,9 +306,10 @@ extern void cpu_memory_exception (struct _sim_cpu *proc, inline address_word phys_to_virt (sim_cpu *cpu, address_word addr) { - if (addr >= 0x8000 && addr < 0xc000) - return ((address_word) (addr) - 0x8000) - + (((address_word) cpu->cpu_regs.page) << 14) + 0x01000000; + if (addr >= cpu->bank_start && addr < cpu->bank_end) + return ((address_word) (addr - cpu->bank_start) + + (((address_word) cpu->cpu_regs.page) << cpu->bank_shift) + + cpu->bank_virtual); else return (address_word) (addr); } @@ -580,7 +592,9 @@ extern void sim_set_profile (int n); extern void sim_set_profile_size (int n); extern void sim_board_reset (SIM_DESC sd); -extern const char *cycle_to_string (sim_cpu *cpu, signed64 t); +#define PRINT_TIME 0x01 +#define PRINT_CYCLE 0x02 +extern const char *cycle_to_string (sim_cpu *cpu, signed64 t, int flags); #endif |