/* toplevel.c -- Top level simulator source file
|
/* toplevel.c -- Top level simulator source file
|
Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
|
Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
|
|
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
|
|
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
(at your option) any later version.
|
(at your option) any later version.
|
|
|
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
GNU General Public License for more details.
|
GNU General Public License for more details.
|
|
|
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
|
/* Simulator commands. Help and version output. SIGINT processing.
|
/* Simulator commands. Help and version output. SIGINT processing.
|
Stdout redirection is specific to linux (I need to fix this). */
|
Stdout redirection is specific to linux (I need to fix this). */
|
|
|
#include "config.h"
|
#include "config.h"
|
|
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <ctype.h>
|
#include <ctype.h>
|
#include <string.h>
|
#include <string.h>
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#include <unistd.h>
|
#include <unistd.h>
|
#include <signal.h>
|
#include <signal.h>
|
#include <stdarg.h>
|
#include <stdarg.h>
|
#include <fcntl.h>
|
#include <fcntl.h>
|
#include <limits.h>
|
#include <limits.h>
|
|
|
#ifdef HAVE_LIBREADLINE
|
#ifdef HAVE_LIBREADLINE
|
#include <readline/readline.h>
|
#include <readline/readline.h>
|
#include <readline/history.h>
|
#include <readline/history.h>
|
#endif /* HAVE_LIBREADLINE */
|
#endif /* HAVE_LIBREADLINE */
|
|
|
#include "arch.h"
|
#include "arch.h"
|
#include "parse.h"
|
#include "parse.h"
|
#include "abstract.h"
|
#include "abstract.h"
|
#include "labels.h"
|
#include "labels.h"
|
#include "execute.h"
|
#include "execute.h"
|
#include "sim-config.h"
|
#include "sim-config.h"
|
#include "spr_defs.h"
|
#include "spr_defs.h"
|
#include "sprs.h"
|
#include "sprs.h"
|
#include "dma.h"
|
#include "dma.h"
|
#include "vga.h"
|
#include "vga.h"
|
#include "fb.h"
|
#include "fb.h"
|
#include "ps2kbd.h"
|
#include "ps2kbd.h"
|
#include "vapi.h"
|
#include "vapi.h"
|
#include "gdbcomm.h"
|
#include "gdbcomm.h"
|
#include "debug_unit.h"
|
#include "debug_unit.h"
|
#include "coff.h"
|
#include "coff.h"
|
#include "sched.h"
|
#include "sched.h"
|
#include "profiler.h"
|
#include "profiler.h"
|
#include "mprofiler.h"
|
#include "mprofiler.h"
|
|
#include "mc.h"
|
|
|
/* CVS revision number. */
|
/* CVS revision number. */
|
const char rcsrev[] = "$Revision: 1.79 $";
|
const char rcsrev[] = "$Revision: 1.80 $";
|
|
|
/* Continuos run versus single step tracing switch. */
|
/* Continuos run versus single step tracing switch. */
|
int cont_run;
|
int cont_run;
|
|
|
/* History of execution */
|
/* History of execution */
|
int histexec[HISTEXEC_LEN];
|
int histexec[HISTEXEC_LEN];
|
|
|
char *sim_commands [] = {
|
char *sim_commands [] = {
|
"q", "t", "help", "de", "dm", "run", "pr", "pm", "pc",
|
"q", "t", "help", "de", "dm", "run", "pr", "pm", "pc",
|
"reset", "break", "hist", "stats", "stall" "info",
|
"reset", "break", "hist", "stats", "stall" "info",
|
"r", "dv",
|
"r", "dv",
|
#if !FAST_SIM
|
#if !FAST_SIM
|
"set",
|
"set",
|
#endif
|
#endif
|
0
|
0
|
};
|
};
|
|
|
inline void debug(int level, const char *format, ...)
|
inline void debug(int level, const char *format, ...)
|
{
|
{
|
char *p;
|
char *p;
|
va_list ap;
|
va_list ap;
|
|
|
if (config.sim.debug >= level) {
|
if (config.sim.debug >= level) {
|
if ((p = malloc(1000)) == NULL)
|
if ((p = malloc(1000)) == NULL)
|
return;
|
return;
|
va_start(ap, format);
|
va_start(ap, format);
|
(void) vsnprintf(p, 1000, format, ap);
|
(void) vsnprintf(p, 1000, format, ap);
|
va_end(ap);
|
va_end(ap);
|
printf("%s", p);
|
printf("%s", p);
|
fflush(stdout);
|
fflush(stdout);
|
free(p);
|
free(p);
|
} else {
|
} else {
|
#if DEBUG
|
#if DEBUG
|
if ((p = malloc(1000)) == NULL)
|
if ((p = malloc(1000)) == NULL)
|
return;
|
return;
|
va_start(ap, format);
|
va_start(ap, format);
|
(void) vsnprintf(p, 1000, format, ap);
|
(void) vsnprintf(p, 1000, format, ap);
|
va_end(ap);
|
va_end(ap);
|
printf("%s\n", p);
|
printf("%s\n", p);
|
fflush(stdout);
|
fflush(stdout);
|
free(p);
|
free(p);
|
#endif
|
#endif
|
}
|
}
|
}
|
}
|
|
|
void ctrl_c(signum)
|
void ctrl_c(signum)
|
int signum;
|
int signum;
|
{
|
{
|
cont_run = cpu_stalled ? 0 : 1;
|
cont_run = cpu_stalled ? 0 : 1;
|
runtime.sim.iprompt = 1;
|
runtime.sim.iprompt = 1;
|
set_stall_state (0);
|
set_stall_state (0);
|
signal(SIGINT, ctrl_c);
|
signal(SIGINT, ctrl_c);
|
}
|
}
|
|
|
void version()
|
void version()
|
{
|
{
|
printf ("\n");
|
printf ("\n");
|
printf ("OpenRISC 1000 (OR32) Architectural Simulator, %s\n", rcsrev);
|
printf ("OpenRISC 1000 (OR32) Architectural Simulator, %s\n", rcsrev);
|
printf ("Copyright (C) 1999 Damjan Lampret, lampret@opencores.org\n");
|
printf ("Copyright (C) 1999 Damjan Lampret, lampret@opencores.org\n");
|
printf ("Copyright (C) 2000 Damjan Lampret, lampret@opencores.org\n");
|
printf ("Copyright (C) 2000 Damjan Lampret, lampret@opencores.org\n");
|
printf (" Jimmy Chen-Min Chen, jimmy@ee.nctu.edu.tw\n");
|
printf (" Jimmy Chen-Min Chen, jimmy@ee.nctu.edu.tw\n");
|
printf (" Johan Rydberg, johan.rydberg@insight.se\n");
|
printf (" Johan Rydberg, johan.rydberg@insight.se\n");
|
printf (" Marko Mlinar, markom@opencores.org\n");
|
printf (" Marko Mlinar, markom@opencores.org\n");
|
printf ("Copyright (C) 2001 Simon Srot, simons@opencores.org\n");
|
printf ("Copyright (C) 2001 Simon Srot, simons@opencores.org\n");
|
printf (" Marko Mlinar, markom@opencores.org\n");
|
printf (" Marko Mlinar, markom@opencores.org\n");
|
printf ("Visit http://www.opencores.org for more information about ");
|
printf ("Visit http://www.opencores.org for more information about ");
|
printf ("OpenRISC 1000 and\nother open source cores.\n\n");
|
printf ("OpenRISC 1000 and\nother open source cores.\n\n");
|
printf ("This software comes with ABSOLUTELY NO WARRANTY; for ");
|
printf ("This software comes with ABSOLUTELY NO WARRANTY; for ");
|
printf ("details see COPYING.\nThis is free software, and you ");
|
printf ("details see COPYING.\nThis is free software, and you ");
|
printf ("are welcome to redistribute it under certain\nconditions; ");
|
printf ("are welcome to redistribute it under certain\nconditions; ");
|
printf ("for details see COPYING.\n");
|
printf ("for details see COPYING.\n");
|
}
|
}
|
|
|
void
|
void
|
help()
|
help()
|
{
|
{
|
printf("q - quit simulator\n");
|
printf("q - quit simulator\n");
|
printf("r - display all registers\n");
|
printf("r - display all registers\n");
|
printf("t - execute next instruction\n");
|
printf("t - execute next instruction\n");
|
printf("run <instructions> [<hush>] - execute <instruction> instructions, no reg dump if hush\n");
|
printf("run <instructions> [<hush>] - execute <instruction> instructions, no reg dump if hush\n");
|
printf("pr <r> <value> - patch register <r> with <value>\n");
|
printf("pr <r> <value> - patch register <r> with <value>\n");
|
printf("dm <fromaddr> [<toaddr>] - display memory from <fromaddr> to <toaddr>\n");
|
printf("dm <fromaddr> [<toaddr>] - display memory from <fromaddr> to <toaddr>\n");
|
printf("de <fromaddr> [<toaddr>] - debug insn memory\n");
|
printf("de <fromaddr> [<toaddr>] - debug insn memory\n");
|
printf("pm <addr> <value> - patch memory location <addr> with <value>\n");
|
printf("pm <addr> <value> - patch memory location <addr> with <value>\n");
|
printf("pc <value> - patch PC register with <value>\n");
|
printf("pc <value> - patch PC register with <value>\n");
|
printf("break <addr> - toggle breakpoint at address <addr>\n");
|
printf("break <addr> - toggle breakpoint at address <addr>\n");
|
printf("reset - simulator reset\n");
|
printf("reset - simulator reset\n");
|
printf("hist - execution history\n");
|
printf("hist - execution history\n");
|
printf("stall - stalls the processor and gives control to the debugger\n");
|
printf("stall - stalls the processor and gives control to the debugger\n");
|
printf("stats <num|clear> - execution statistics num or clear it.\n");
|
printf("stats <num|clear> - execution statistics num or clear it.\n");
|
printf("info - configuration info (caches etc.)\n");
|
printf("info - configuration info (caches etc.)\n");
|
printf("dv <fromaddr> [<toaddr>] [<modname>] - dumps memory as verilog (use redirect)\n");
|
printf("dv <fromaddr> [<toaddr>] [<modname>] - dumps memory as verilog (use redirect)\n");
|
printf("dh <fromaddr> [<toaddr>] - dumps memory as hex code (use redirect)\n");
|
printf("dh <fromaddr> [<toaddr>] - dumps memory as hex code (use redirect)\n");
|
printf("<cmd> > <filename> - redirect simulator stdout to <filename> (and not emulated printf)\n");
|
printf("<cmd> > <filename> - redirect simulator stdout to <filename> (and not emulated printf)\n");
|
#if !FAST_SIM
|
#if !FAST_SIM
|
printf("set <section> <item> = <param> - set configuration. See sim.cfg for more information.\n");
|
printf("set <section> <item> = <param> - set configuration. See sim.cfg for more information.\n");
|
printf("debug - toggles simulator debug mode\n");
|
printf("debug - toggles simulator debug mode\n");
|
#endif
|
#endif
|
printf("help - available commands (this list)\n");
|
printf("help - available commands (this list)\n");
|
}
|
}
|
|
|
void debugmem (unsigned long from, unsigned long to );
|
void debugmem (unsigned long from, unsigned long to );
|
|
|
/* Resets all subunits */
|
/* Resets all subunits */
|
void sim_reset ()
|
void sim_reset ()
|
{
|
{
|
SCHED_INIT();
|
SCHED_INIT();
|
uart_reset();
|
uart_reset();
|
dma_reset();
|
dma_reset();
|
eth_reset();
|
eth_reset();
|
gpio_reset();
|
gpio_reset();
|
vga_reset ();
|
vga_reset ();
|
fb_reset ();
|
fb_reset ();
|
kbd_reset ();
|
kbd_reset ();
|
tick_reset();
|
tick_reset();
|
pm_reset();
|
pm_reset();
|
pic_reset();
|
pic_reset();
|
mc_reset();
|
mc_reset();
|
du_reset ();
|
du_reset ();
|
cpu_reset();
|
cpu_reset();
|
}
|
}
|
|
|
/* Initalizes all devices and sim */
|
/* Initalizes all devices and sim */
|
void sim_init ()
|
void sim_init ()
|
{
|
{
|
init_memory_table ();
|
init_memory_table ();
|
init_labels();
|
init_labels();
|
init_breakpoints();
|
init_breakpoints();
|
initstats();
|
initstats();
|
build_automata();
|
build_automata();
|
|
|
if (config.sim.profile) {
|
if (config.sim.profile) {
|
runtime.sim.fprof = fopen(config.sim.prof_fn, "wt+");
|
runtime.sim.fprof = fopen(config.sim.prof_fn, "wt+");
|
if(!runtime.sim.fprof) {
|
if(!runtime.sim.fprof) {
|
fprintf(stderr, "ERROR: Problems opening profile file.\n");
|
fprintf(stderr, "ERROR: Problems opening profile file.\n");
|
exit (1);
|
exit (1);
|
} else
|
} else
|
fprintf(runtime.sim.fprof, "+00000000 FFFFFFFF FFFFFFFF total\n");
|
fprintf(runtime.sim.fprof, "+00000000 FFFFFFFF FFFFFFFF total\n");
|
}
|
}
|
|
|
if (config.sim.mprofile) {
|
if (config.sim.mprofile) {
|
runtime.sim.fmprof = fopen(config.sim.mprof_fn, "wb+");
|
runtime.sim.fmprof = fopen(config.sim.mprof_fn, "wb+");
|
if(!runtime.sim.fmprof) {
|
if(!runtime.sim.fmprof) {
|
fprintf(stderr, "ERROR: Problems opening memory profile file.\n");
|
fprintf(stderr, "ERROR: Problems opening memory profile file.\n");
|
exit (1);
|
exit (1);
|
}
|
}
|
}
|
}
|
|
|
if (config.sim.exe_log) {
|
if (config.sim.exe_log) {
|
runtime.sim.fexe_log = fopen(config.sim.exe_log_fn, "wt+");
|
runtime.sim.fexe_log = fopen(config.sim.exe_log_fn, "wt+");
|
if(!runtime.sim.fexe_log) {
|
if(!runtime.sim.fexe_log) {
|
printf("ERROR: Problems opening exe_log file.\n");
|
printf("ERROR: Problems opening exe_log file.\n");
|
exit (1);
|
exit (1);
|
}
|
}
|
}
|
}
|
|
|
if (config.sim.spr_log) {
|
if (config.sim.spr_log) {
|
printf("OPENING SPRLOG\n");
|
printf("OPENING SPRLOG\n");
|
runtime.sim.fspr_log = fopen(config.sim.spr_log_fn, "wt+");
|
runtime.sim.fspr_log = fopen(config.sim.spr_log_fn, "wt+");
|
if (!runtime.sim.fspr_log) {
|
if (!runtime.sim.fspr_log) {
|
printf("ERROR: Problems opening spr_log file.\n");
|
printf("ERROR: Problems opening spr_log file.\n");
|
exit(1);
|
exit(1);
|
}
|
}
|
}
|
}
|
|
|
/* Initialize memory */
|
/* Initialize memory */
|
{
|
{
|
extern struct dev_memarea *dev_list;
|
extern struct dev_memarea *dev_list;
|
struct dev_memarea *area;
|
struct dev_memarea *area;
|
int i;
|
int i;
|
if (config.memory.type == MT_RANDOM) {
|
if (config.memory.type == MT_RANDOM) {
|
unsigned int val = 0;
|
unsigned int val = 0;
|
|
|
if (config.memory.random_seed == -1) {
|
if (config.memory.random_seed == -1) {
|
runtime.memory.random_seed = time(NULL);
|
runtime.memory.random_seed = time(NULL);
|
/* Print out the seed just in case we ever need to debug */
|
/* Print out the seed just in case we ever need to debug */
|
printf("Seeding random generator with value %d\n", config.memory.random_seed);
|
printf("Seeding random generator with value %d\n", config.memory.random_seed);
|
} else
|
} else
|
runtime.memory.random_seed = config.memory.random_seed;
|
runtime.memory.random_seed = config.memory.random_seed;
|
srandom(runtime.memory.random_seed);
|
srandom(runtime.memory.random_seed);
|
|
|
for (area = dev_list; area; area = area->next)
|
for (area = dev_list; area; area = area->next)
|
for(i = 0; i < area->size; i++) {
|
for(i = 0; i < area->size; i++) {
|
val = random();
|
val = random();
|
setsim_mem8(i + area->addr_compare, val & 0xFF);
|
setsim_mem8(i + area->addr_compare, val & 0xFF);
|
}
|
}
|
} else if(config.memory.type == MT_PATTERN) {
|
} else if(config.memory.type == MT_PATTERN) {
|
for (area = dev_list; area; area = area->next)
|
for (area = dev_list; area; area = area->next)
|
for(i = 0; i < area->size; i++)
|
for(i = 0; i < area->size; i++)
|
setsim_mem8(i + area->addr_compare, config.memory.pattern);
|
setsim_mem8(i + area->addr_compare, config.memory.pattern);
|
} else if (config.memory.type != MT_UNKNOWN) {
|
} else if (config.memory.type != MT_UNKNOWN) {
|
fprintf(stderr, "Invalid memory configuration type.\n");
|
fprintf(stderr, "Invalid memory configuration type.\n");
|
exit(1);
|
exit(1);
|
}
|
}
|
}
|
}
|
|
|
if(runtime.sim.filename) {
|
if(runtime.sim.filename) {
|
unsigned long endaddr = 0xFFFFFFFF;
|
unsigned long endaddr = 0xFFFFFFFF;
|
endaddr = loadcode(runtime.sim.filename, 0, 0); /* MM170901 always load at address zero. */
|
endaddr = loadcode(runtime.sim.filename, 0, 0); /* MM170901 always load at address zero. */
|
if (endaddr == -1) {
|
if (endaddr == -1) {
|
fprintf(stderr, "Problems loading boot code.\n");
|
fprintf(stderr, "Problems loading boot code.\n");
|
exit(1);
|
exit(1);
|
}
|
}
|
}
|
}
|
|
|
#if !FAST_SIM /* We assume we have valid configuration with fsim*/
|
#if !FAST_SIM /* We assume we have valid configuration with fsim*/
|
/* Disable gdb debugging, if debug module is not available. */
|
/* Disable gdb debugging, if debug module is not available. */
|
if (config.debug.gdb_enabled && !config.debug.enabled) {
|
if (config.debug.gdb_enabled && !config.debug.enabled) {
|
config.debug.gdb_enabled = 0;
|
config.debug.gdb_enabled = 0;
|
if (config.sim.verbose)
|
if (config.sim.verbose)
|
fprintf (stderr, "WARNING: Debug module not enabled, cannot start gdb.\n");
|
fprintf (stderr, "WARNING: Debug module not enabled, cannot start gdb.\n");
|
}
|
}
|
#endif
|
#endif
|
|
|
if (config.debug.gdb_enabled)
|
if (config.debug.gdb_enabled)
|
gdbcomm_init ();
|
gdbcomm_init ();
|
|
|
#if !FAST_SIM /* We assume we have valid configuration with fsim*/
|
#if !FAST_SIM /* We assume we have valid configuration with fsim*/
|
/* Enable dependency stats, if we want to do history analisis */
|
/* Enable dependency stats, if we want to do history analisis */
|
if (config.sim.history && !config.cpu.dependstats) {
|
if (config.sim.history && !config.cpu.dependstats) {
|
config.cpu.dependstats = 1;
|
config.cpu.dependstats = 1;
|
if (config.sim.verbose)
|
if (config.sim.verbose)
|
fprintf (stderr, "WARNING: dependstats stats must be enabled to do history analisis.\n");
|
fprintf (stderr, "WARNING: dependstats stats must be enabled to do history analisis.\n");
|
}
|
}
|
#endif
|
#endif
|
|
|
#if !FAST_SIM /* We assume we have valid configuration with fsim*/
|
#if !FAST_SIM /* We assume we have valid configuration with fsim*/
|
/* Debug forces verbose */
|
/* Debug forces verbose */
|
if (config.sim.debug && !config.sim.verbose) {
|
if (config.sim.debug && !config.sim.verbose) {
|
config.sim.verbose = 1;
|
config.sim.verbose = 1;
|
fprintf (stderr, "WARNING: verbose turned on.\n");
|
fprintf (stderr, "WARNING: verbose turned on.\n");
|
}
|
}
|
#endif
|
#endif
|
|
|
/* Start VAPI before device initialization. */
|
/* Start VAPI before device initialization. */
|
if (config.vapi.enabled) {
|
if (config.vapi.enabled) {
|
runtime.vapi.enabled = 1;
|
runtime.vapi.enabled = 1;
|
vapi_init ();
|
vapi_init ();
|
if (config.sim.verbose)
|
if (config.sim.verbose)
|
printf ("VAPI started, waiting for clients.\n");
|
printf ("VAPI started, waiting for clients.\n");
|
}
|
}
|
|
|
sim_reset ();
|
sim_reset ();
|
|
|
lock_memory_table ();
|
lock_memory_table ();
|
|
|
/* Wait till all test are connected. */
|
/* Wait till all test are connected. */
|
if (runtime.vapi.enabled) {
|
if (runtime.vapi.enabled) {
|
int numu = vapi_num_unconnected (0);
|
int numu = vapi_num_unconnected (0);
|
if (numu) {
|
if (numu) {
|
printf ("\nWaiting for VAPI tests with ids:\n");
|
printf ("\nWaiting for VAPI tests with ids:\n");
|
vapi_num_unconnected (1);
|
vapi_num_unconnected (1);
|
printf ("\n");
|
printf ("\n");
|
while (numu = vapi_num_unconnected (0)) {
|
while (numu = vapi_num_unconnected (0)) {
|
vapi_check ();
|
vapi_check ();
|
printf ("\rStill waiting for %i VAPI test(s) to connect. ", numu);
|
printf ("\rStill waiting for %i VAPI test(s) to connect. ", numu);
|
usleep (100);
|
usleep (100);
|
}
|
}
|
printf ("\n");
|
printf ("\n");
|
}
|
}
|
printf ("All devices connected \n");
|
printf ("All devices connected \n");
|
}
|
}
|
/* simulator is initialized */
|
/* simulator is initialized */
|
runtime.sim.init = 0;
|
runtime.sim.init = 0;
|
}
|
}
|
|
|
/* Display info about various modules */
|
/* Display info about various modules */
|
void sim_info () {
|
void sim_info () {
|
sprs_status();
|
sprs_status();
|
printf ("\n");
|
printf ("\n");
|
memory_table_status ();
|
memory_table_status ();
|
if (config.immu.enabled) itlb_status(-1);
|
if (config.immu.enabled) itlb_status(-1);
|
if (config.dmmu.enabled) dtlb_status(-1);
|
if (config.dmmu.enabled) dtlb_status(-1);
|
if (config.ic.enabled) ic_info();
|
if (config.ic.enabled) ic_info();
|
if (config.dc.enabled) dc_info();
|
if (config.dc.enabled) dc_info();
|
|
|
if (config.bpb.enabled) bpb_info();
|
if (config.bpb.enabled) bpb_info();
|
if (config.bpb.btic) btic_info();
|
if (config.bpb.btic) btic_info();
|
|
|
|
if (config.mc.enabled) mc_status();
|
if (config.nuarts) uart_status();
|
if (config.nuarts) uart_status();
|
if (config.ndmas) dma_status();
|
if (config.ndmas) dma_status();
|
if (config.nethernets) eth_status();
|
if (config.nethernets) eth_status();
|
if (config.ngpios) gpio_status();
|
if (config.ngpios) gpio_status();
|
kbd_info();
|
kbd_info();
|
}
|
}
|
|
|
/* Cleanup */
|
/* Cleanup */
|
void sim_done ()
|
void sim_done ()
|
{
|
{
|
if (config.sim.profile) {
|
if (config.sim.profile) {
|
extern int cycles;
|
extern int cycles;
|
fprintf(runtime.sim.fprof,"-%08X FFFFFFFF\n", cycles);
|
fprintf(runtime.sim.fprof,"-%08X FFFFFFFF\n", cycles);
|
fclose(runtime.sim.fprof);
|
fclose(runtime.sim.fprof);
|
|
|
main_profile(config.sim.profile_mode, config.sim.prof_fn);
|
main_profile(config.sim.profile_mode, config.sim.prof_fn);
|
}
|
}
|
|
|
if (config.sim.mprofile) {
|
if (config.sim.mprofile) {
|
fclose(runtime.sim.fmprof);
|
fclose(runtime.sim.fmprof);
|
|
|
main_mprofiler(config.sim.mprofile_mode,
|
main_mprofiler(config.sim.mprofile_mode,
|
config.sim.mprofile_group,
|
config.sim.mprofile_group,
|
config.sim.mprof_fn);
|
config.sim.mprof_fn);
|
}
|
}
|
|
|
if (config.sim.exe_log) fclose(runtime.sim.fexe_log);
|
if (config.sim.exe_log) fclose(runtime.sim.fexe_log);
|
if (runtime.vapi.enabled) vapi_done ();
|
if (runtime.vapi.enabled) vapi_done ();
|
done_memory_table ();
|
done_memory_table ();
|
exit(0);
|
exit(0);
|
}
|
}
|
|
|
/* Executes jobs in time queue */
|
/* Executes jobs in time queue */
|
static inline void do_scheduler ()
|
static inline void do_scheduler ()
|
{
|
{
|
void (*func)(int);
|
void (*func)(int);
|
int param;
|
int param;
|
|
|
/* Execute all jobs till now */
|
/* Execute all jobs till now */
|
do {
|
do {
|
func = SCHED_PEEK().func;
|
func = SCHED_PEEK().func;
|
param = SCHED_PEEK().param;
|
param = SCHED_PEEK().param;
|
SCHED_REMOVE();
|
SCHED_REMOVE();
|
func (param);
|
func (param);
|
} while (cycles >= SCHED_PEEK().time);
|
} while (cycles >= SCHED_PEEK().time);
|
}
|
}
|
|
|
/* Main function */
|
/* Main function */
|
int main(argc, argv)
|
int main(argc, argv)
|
int argc;
|
int argc;
|
char *argv[];
|
char *argv[];
|
{
|
{
|
char *linestr;
|
char *linestr;
|
char item1[500], b2[500], prev_str[500] = "";
|
char item1[500], b2[500], prev_str[500] = "";
|
char *redirstr;
|
char *redirstr;
|
int hush = 0;
|
int hush = 0;
|
int first_prompt = 1;
|
int first_prompt = 1;
|
|
|
srand(getpid());
|
srand(getpid());
|
init_defconfig();
|
init_defconfig();
|
if (parse_args(argc, argv)) {
|
if (parse_args(argc, argv)) {
|
printf("Usage: %s [options] <filename>\n", argv[0]);
|
printf("Usage: %s [options] <filename>\n", argv[0]);
|
printf("Options:\n");
|
printf("Options:\n");
|
printf(" -v version and copyright note\n");
|
printf(" -v version and copyright note\n");
|
printf(" -i enable interactive command prompt\n");
|
printf(" -i enable interactive command prompt\n");
|
printf(" --nosrv do not launch JTAG proxy server\n"); /* (CZ) */
|
printf(" --nosrv do not launch JTAG proxy server\n"); /* (CZ) */
|
printf(" --srv <n> launch JTAG proxy server on port <n>; [random]\n"); /* (CZ) */
|
printf(" --srv <n> launch JTAG proxy server on port <n>; [random]\n"); /* (CZ) */
|
#if !FAST_SIM
|
#if !FAST_SIM
|
printf(" -f or --file load script file [sim.cfg]\n");
|
printf(" -f or --file load script file [sim.cfg]\n");
|
printf(" --profile <[c]|[q]> enable profiling. c - cumulative, q - quiet\n");
|
printf(" --profile <[c]|[q]> enable profiling. c - cumulative, q - quiet\n");
|
printf(" --mprofile <[c]|[q]> enable memory profiling. c - cumulative, q - quiet\n");
|
printf(" --mprofile <[c]|[q]> enable memory profiling. c - cumulative, q - quiet\n");
|
#endif
|
#endif
|
printf(" --output-cfg prints C structure of current configuration to standard output\n");
|
printf(" --output-cfg prints C structure of current configuration to standard output\n");
|
exit(-1);
|
exit(-1);
|
}
|
}
|
|
|
#ifdef HAVE_LIBREADLINE
|
#ifdef HAVE_LIBREADLINE
|
initialize_readline (); /* Bind our completer. */
|
initialize_readline (); /* Bind our completer. */
|
#endif
|
#endif
|
|
|
#if !FAST_SIM
|
#if !FAST_SIM
|
/* Read configuration file. */
|
/* Read configuration file. */
|
if (!runtime.sim.script_file_specified)
|
if (!runtime.sim.script_file_specified)
|
read_script_file ("sim.cfg");
|
read_script_file ("sim.cfg");
|
if (!runtime.sim.script_file_specified && config.sim.verbose)
|
if (!runtime.sim.script_file_specified && config.sim.verbose)
|
fprintf (stderr, "WARNING: No config file read, assuming default configuration.\n");
|
fprintf (stderr, "WARNING: No config file read, assuming default configuration.\n");
|
#else
|
#else
|
printf ("\n\tNOTE: running fast sim with fixed configuration!\n\n");
|
printf ("\n\tNOTE: running fast sim with fixed configuration!\n\n");
|
#endif
|
#endif
|
if (runtime.sim.output_cfg) {
|
if (runtime.sim.output_cfg) {
|
output_cfg (stdout);
|
output_cfg (stdout);
|
exit (0);
|
exit (0);
|
}
|
}
|
print_config();
|
print_config();
|
sim_init ();
|
sim_init ();
|
signal(SIGINT, ctrl_c);
|
signal(SIGINT, ctrl_c);
|
|
|
while(1) {
|
while(1) {
|
if (runtime.sim.iprompt) {
|
if (runtime.sim.iprompt) {
|
if (config.debug.gdb_enabled)
|
if (config.debug.gdb_enabled)
|
{
|
{
|
printf ("(sim) ");
|
printf ("(sim) ");
|
fflush(stdout);
|
fflush(stdout);
|
HandleServerSocket(true); /* block & check_stdin = true */
|
HandleServerSocket(true); /* block & check_stdin = true */
|
}
|
}
|
#ifdef HAVE_LIBREADLINE
|
#ifdef HAVE_LIBREADLINE
|
/* Must disable readline in new mode. It isn't compatible
|
/* Must disable readline in new mode. It isn't compatible
|
with non blocking environments */
|
with non blocking environments */
|
if(!config.debug.gdb_enabled)
|
if(!config.debug.gdb_enabled)
|
linestr = readline("(sim) ");
|
linestr = readline("(sim) ");
|
else
|
else
|
linestr = fgets(b2, sizeof b2, stdin);
|
linestr = fgets(b2, sizeof b2, stdin);
|
#else
|
#else
|
if(!config.debug.gdb_enabled)
|
if(!config.debug.gdb_enabled)
|
printf ("(sim) ");
|
printf ("(sim) ");
|
linestr = fgets(b2, sizeof b2, stdin);
|
linestr = fgets(b2, sizeof b2, stdin);
|
#endif
|
#endif
|
} else
|
} else
|
strcpy(linestr = b2, "run -1 hush");
|
strcpy(linestr = b2, "run -1 hush");
|
|
|
if (!linestr)
|
if (!linestr)
|
break;
|
break;
|
linestr = stripwhite (linestr);
|
linestr = stripwhite (linestr);
|
|
|
#ifdef HAVE_LIBREADLINE
|
#ifdef HAVE_LIBREADLINE
|
/* Readline only works in the old mode */
|
/* Readline only works in the old mode */
|
if(!server_fd)
|
if(!server_fd)
|
{
|
{
|
if (strlen(linestr) == 0) {
|
if (strlen(linestr) == 0) {
|
char *l = repeat_last_command ();
|
char *l = repeat_last_command ();
|
|
|
if (l) {
|
if (l) {
|
free (linestr);
|
free (linestr);
|
linestr = l;
|
linestr = l;
|
}
|
}
|
}
|
}
|
|
|
if (*linestr) {
|
if (*linestr) {
|
add_history (linestr);
|
add_history (linestr);
|
}
|
}
|
}
|
}
|
#endif /* HAVE_LIBREADLINE */
|
#endif /* HAVE_LIBREADLINE */
|
|
|
if (redirstr = strstr(linestr, ">")) {
|
if (redirstr = strstr(linestr, ">")) {
|
*redirstr = '\0';
|
*redirstr = '\0';
|
strtoken(&redirstr[1], item1, 1);
|
strtoken(&redirstr[1], item1, 1);
|
freopen(item1, "w+", stdout);
|
freopen(item1, "w+", stdout);
|
}
|
}
|
|
|
if (linestr[0] == '\n')
|
if (linestr[0] == '\n')
|
strcpy (linestr, &prev_str[0]);
|
strcpy (linestr, &prev_str[0]);
|
else
|
else
|
strcpy (&prev_str[0], linestr);
|
strcpy (&prev_str[0], linestr);
|
|
|
strtoken(linestr, item1, 1);
|
strtoken(linestr, item1, 1);
|
if (strcmp(item1, "q") == 0) { /* quit */
|
if (strcmp(item1, "q") == 0) { /* quit */
|
printf ("\n");
|
printf ("\n");
|
sim_done ();
|
sim_done ();
|
} else
|
} else
|
if (strcmp(item1, "help") == 0) /* help */
|
if (strcmp(item1, "help") == 0) /* help */
|
help();
|
help();
|
else
|
else
|
if (strcmp(item1, "t") == 0) { /* trace */
|
if (strcmp(item1, "t") == 0) { /* trace */
|
cont_run = 1;
|
cont_run = 1;
|
} else
|
} else
|
if (strcmp(item1, "dm") == 0) { /* dump memory */
|
if (strcmp(item1, "dm") == 0) { /* dump memory */
|
char item2[20];
|
char item2[20];
|
char item3[20];
|
char item3[20];
|
static int from = 0, to = 0;
|
static int from = 0, to = 0;
|
|
|
strtoken(linestr, item2, 2);
|
strtoken(linestr, item2, 2);
|
strtoken(linestr, item3, 3);
|
strtoken(linestr, item3, 3);
|
|
|
if (strlen(item2)) {
|
if (strlen(item2)) {
|
if (item2[0] == '_')
|
if (item2[0] == '_')
|
from = eval_label(item2);
|
from = eval_label(item2);
|
else
|
else
|
from = strtoul(item2, NULL, 0);
|
from = strtoul(item2, NULL, 0);
|
to = from + 0x40;
|
to = from + 0x40;
|
}
|
}
|
if (strlen(item3))
|
if (strlen(item3))
|
to = strtoul(item3, NULL, 0);
|
to = strtoul(item3, NULL, 0);
|
dumpmemory(from, to, 0, 1);
|
dumpmemory(from, to, 0, 1);
|
printf("\n");
|
printf("\n");
|
} else
|
} else
|
if (strcmp(item1, "dv") == 0) {/* dump memory as verilog*/
|
if (strcmp(item1, "dv") == 0) {/* dump memory as verilog*/
|
char item2[20];
|
char item2[20];
|
char item3[20];
|
char item3[20];
|
char item4[20];
|
char item4[20];
|
static int from = 0, to = 0;
|
static int from = 0, to = 0;
|
|
|
strtoken(linestr, item2, 2);
|
strtoken(linestr, item2, 2);
|
strtoken(linestr, item3, 3);
|
strtoken(linestr, item3, 3);
|
strtoken(linestr, item4, 4);
|
strtoken(linestr, item4, 4);
|
|
|
if (strlen(item2)) {
|
if (strlen(item2)) {
|
if (item2[0] == '_')
|
if (item2[0] == '_')
|
from = eval_label(item2);
|
from = eval_label(item2);
|
else
|
else
|
from = strtoul(item2, NULL, 0);
|
from = strtoul(item2, NULL, 0);
|
to = from + 0x40;
|
to = from + 0x40;
|
}
|
}
|
if (strlen(item3))
|
if (strlen(item3))
|
to = strtoul(item3, NULL, 0);
|
to = strtoul(item3, NULL, 0);
|
if (!strlen(item4))
|
if (!strlen(item4))
|
strcpy(item4, "or1k_mem");
|
strcpy(item4, "or1k_mem");
|
dumpverilog(item4, from, to);
|
dumpverilog(item4, from, to);
|
printf("\n");
|
printf("\n");
|
} else
|
} else
|
if (strcmp(item1, "dh") == 0) {/* dump memory as hex*/
|
if (strcmp(item1, "dh") == 0) {/* dump memory as hex*/
|
char item2[20];
|
char item2[20];
|
char item3[20];
|
char item3[20];
|
static int from = 0, to = 0;
|
static int from = 0, to = 0;
|
|
|
strtoken(linestr, item2, 2);
|
strtoken(linestr, item2, 2);
|
strtoken(linestr, item3, 3);
|
strtoken(linestr, item3, 3);
|
|
|
if (strlen(item2)) {
|
if (strlen(item2)) {
|
if (item2[0] == '_')
|
if (item2[0] == '_')
|
from = eval_label(item2);
|
from = eval_label(item2);
|
else
|
else
|
from = strtoul(item2, NULL, 0);
|
from = strtoul(item2, NULL, 0);
|
to = from + 0x40;
|
to = from + 0x40;
|
}
|
}
|
if (strlen(item3))
|
if (strlen(item3))
|
to = strtoul(item3, NULL, 0);
|
to = strtoul(item3, NULL, 0);
|
dumphex(from, to);
|
dumphex(from, to);
|
printf("\n");
|
printf("\n");
|
} else
|
} else
|
if (strcmp(item1, "pm") == 0) { /* patch memory */
|
if (strcmp(item1, "pm") == 0) { /* patch memory */
|
char item2[20];
|
char item2[20];
|
char item3[20];
|
char item3[20];
|
static int addr = 0;
|
static int addr = 0;
|
int breakpoint = 0;
|
int breakpoint = 0;
|
|
|
strtoken(linestr, item2, 2);
|
strtoken(linestr, item2, 2);
|
strtoken(linestr, item3, 3);
|
strtoken(linestr, item3, 3);
|
if (strlen(item2))
|
if (strlen(item2))
|
if (item2[0] == '_')
|
if (item2[0] == '_')
|
addr = eval_label(item2);
|
addr = eval_label(item2);
|
else
|
else
|
addr = strtoul(item2, NULL, 0);
|
addr = strtoul(item2, NULL, 0);
|
set_mem32(addr, strtoul(item3, NULL, 0), &breakpoint);
|
set_mem32(addr, strtoul(item3, NULL, 0), &breakpoint);
|
} else
|
} else
|
if (strcmp(item1, "pr") == 0) { /* patch regs */
|
if (strcmp(item1, "pr") == 0) { /* patch regs */
|
char item2[20];
|
char item2[20];
|
char item3[20];
|
char item3[20];
|
|
|
strtoken(linestr, item2, 2);
|
strtoken(linestr, item2, 2);
|
strtoken(linestr, item3, 3);
|
strtoken(linestr, item3, 3);
|
setsim_reg32(strtoul(item2, NULL,0), strtoul(item3, NULL, 0));
|
setsim_reg32(strtoul(item2, NULL,0), strtoul(item3, NULL, 0));
|
} else
|
} else
|
if (strcmp(item1, "pc") == 0) { /* patch PC */
|
if (strcmp(item1, "pc") == 0) { /* patch PC */
|
char item2[20];
|
char item2[20];
|
|
|
strtoken(linestr, item2, 2);
|
strtoken(linestr, item2, 2);
|
pc = strtoul(item2, NULL, 0);
|
pc = strtoul(item2, NULL, 0);
|
} else
|
} else
|
if (strcmp(item1, "break") == 0) { /* set/clear breakpoint */
|
if (strcmp(item1, "break") == 0) { /* set/clear breakpoint */
|
char item2[20];
|
char item2[20];
|
|
|
strtoken(linestr, item2, 2);
|
strtoken(linestr, item2, 2);
|
set_insnbrkpoint(strtoul(item2, NULL, 0));
|
set_insnbrkpoint(strtoul(item2, NULL, 0));
|
} else
|
} else
|
if (strcmp(item1, "r") == 0) { /* dump regs */
|
if (strcmp(item1, "r") == 0) { /* dump regs */
|
dumpreg();
|
dumpreg();
|
} else
|
} else
|
if (strcmp(item1, "de") == 0) { /* reset simulator */
|
if (strcmp(item1, "de") == 0) { /* reset simulator */
|
char item2[20];
|
char item2[20];
|
char item3[20];
|
char item3[20];
|
static int from = 0, to = 0;
|
static int from = 0, to = 0;
|
|
|
strtoken(linestr, item2, 2);
|
strtoken(linestr, item2, 2);
|
strtoken(linestr, item3, 3);
|
strtoken(linestr, item3, 3);
|
|
|
if (strlen(item2)) {
|
if (strlen(item2)) {
|
if (item2[0] == '_')
|
if (item2[0] == '_')
|
from = eval_label(item2);
|
from = eval_label(item2);
|
else
|
else
|
from = strtoul(item2, NULL, 0);
|
from = strtoul(item2, NULL, 0);
|
to = from + 0x40;
|
to = from + 0x40;
|
}
|
}
|
if (strlen(item3))
|
if (strlen(item3))
|
to = strtoul(item3, NULL, 0);
|
to = strtoul(item3, NULL, 0);
|
debugmem(from, to);
|
debugmem(from, to);
|
printf("\n");
|
printf("\n");
|
} else
|
} else
|
if (strcmp(item1, "reset") == 0) { /* reset simulator */
|
if (strcmp(item1, "reset") == 0) { /* reset simulator */
|
sim_reset();
|
sim_reset();
|
} else
|
} else
|
#if !FAST_SIM
|
#if !FAST_SIM
|
if (strcmp(item1, "debug") == 0) { /* debug mode */
|
if (strcmp(item1, "debug") == 0) { /* debug mode */
|
config.sim.debug ^= 1;
|
config.sim.debug ^= 1;
|
} else
|
} else
|
#endif
|
#endif
|
if (strcmp(item1, "hist") == 0) { /* dump history */
|
if (strcmp(item1, "hist") == 0) { /* dump history */
|
int i;
|
int i;
|
for(i = HISTEXEC_LEN; i; i--)
|
for(i = HISTEXEC_LEN; i; i--)
|
dumpmemory(histexec[i - 1], histexec[i - 1] + 4, 1, 1);
|
dumpmemory(histexec[i - 1], histexec[i - 1] + 4, 1, 1);
|
printf("\n");
|
printf("\n");
|
} else
|
} else
|
if (strcmp(item1, "run") == 0) { /* run */
|
if (strcmp(item1, "run") == 0) { /* run */
|
char item2[20];
|
char item2[20];
|
char item3[20];
|
char item3[20];
|
|
|
strtoken(linestr, item2, 2);
|
strtoken(linestr, item2, 2);
|
strtoken(linestr, item3, 3);
|
strtoken(linestr, item3, 3);
|
if (strcmp(item3, "hush") == 0)
|
if (strcmp(item3, "hush") == 0)
|
hush = 1;
|
hush = 1;
|
else
|
else
|
hush = 0;
|
hush = 0;
|
cont_run = strtol(item2, NULL, 0);
|
cont_run = strtol(item2, NULL, 0);
|
} else
|
} else
|
if(!strcmp(item1, "stall")) { /* Added by CZ 210801 */
|
if(!strcmp(item1, "stall")) { /* Added by CZ 210801 */
|
set_stall_state (1);
|
set_stall_state (1);
|
runtime.sim.iprompt = 0;
|
runtime.sim.iprompt = 0;
|
cont_run = -1;
|
cont_run = -1;
|
hush = 1;
|
hush = 1;
|
} else
|
} else
|
if (strcmp(item1, "stats") == 0) { /* stats */
|
if (strcmp(item1, "stats") == 0) { /* stats */
|
char item2[20];
|
char item2[20];
|
int i = 0;
|
int i = 0;
|
|
|
strtoken(linestr, item2, 2);
|
strtoken(linestr, item2, 2);
|
if (strcmp(item2, "clear") == 0) {
|
if (strcmp(item2, "clear") == 0) {
|
initstats();
|
initstats();
|
printf("Cleared.\n");
|
printf("Cleared.\n");
|
} else {
|
} else {
|
i = strtoul(item2, NULL, 0);
|
i = strtoul(item2, NULL, 0);
|
printstats(i);
|
printstats(i);
|
}
|
}
|
} else
|
} else
|
if (strcmp(item1, "info") == 0) /* configuration info */
|
if (strcmp(item1, "info") == 0) /* configuration info */
|
sim_info ();
|
sim_info ();
|
else
|
else
|
#if !FAST_SIM
|
#if !FAST_SIM
|
if (strcmp(item1, "set") == 0) { /* configuration info */
|
if (strcmp(item1, "set") == 0) { /* configuration info */
|
char *s = linestr;
|
char *s = linestr;
|
int i;
|
int i;
|
extern section;
|
extern section;
|
extern struct section sections[];
|
extern struct section sections[];
|
while (*s != ' ' && *s) s++;
|
while (*s != ' ' && *s) s++;
|
set_config_command (s);
|
set_config_command (s);
|
} else
|
} else
|
#endif /* !FAST_SIM */
|
#endif /* !FAST_SIM */
|
printf("%s: Unknown command.\n", linestr);
|
printf("%s: Unknown command.\n", linestr);
|
|
|
{ /* Needed by execution */
|
{ /* Needed by execution */
|
extern int do_stats;
|
extern int do_stats;
|
do_stats = config.cpu.dependstats || config.cpu.superscalar || config.cpu.dependstats
|
do_stats = config.cpu.dependstats || config.cpu.superscalar || config.cpu.dependstats
|
|| config.sim.history || config.sim.exe_log;
|
|| config.sim.history || config.sim.exe_log;
|
}
|
}
|
|
|
/* MM: 'run -1' means endless execution. */
|
/* MM: 'run -1' means endless execution. */
|
while(cont_run) {
|
while(cont_run) {
|
extern int mem_cycles;
|
extern int mem_cycles;
|
|
|
IFF (config.debug.enabled) {
|
IFF (config.debug.enabled) {
|
if (cpu_stalled) {
|
if (cpu_stalled) {
|
if(config.debug.gdb_enabled) {
|
if(config.debug.gdb_enabled) {
|
BlockJTAG();
|
BlockJTAG();
|
HandleServerSocket(false);
|
HandleServerSocket(false);
|
} else {
|
} else {
|
fprintf (stderr, "WARNING: CPU stalled and gdb connection not enabled.");
|
fprintf (stderr, "WARNING: CPU stalled and gdb connection not enabled.");
|
cont_run = 0;
|
cont_run = 0;
|
}
|
}
|
continue;
|
continue;
|
}
|
}
|
}
|
}
|
|
|
/* Each cycle has counter of mem_cycles; this value is joined with cycles
|
/* Each cycle has counter of mem_cycles; this value is joined with cycles
|
at the end of the cycle; no sim originated memory accesses should be
|
at the end of the cycle; no sim originated memory accesses should be
|
performed inbetween. */
|
performed inbetween. */
|
mem_cycles = 0;
|
mem_cycles = 0;
|
if (!config.pm.enabled || !testsprbits(SPR_PMR, SPR_PMR_DME | SPR_PMR_SME)) {
|
if (!config.pm.enabled || !testsprbits(SPR_PMR, SPR_PMR_DME | SPR_PMR_SME)) {
|
if (cont_run > 0) cont_run--;
|
if (cont_run > 0) cont_run--;
|
pic_clock ();
|
pic_clock ();
|
if (cpu_clock ()) break;
|
if (cpu_clock ()) break;
|
if (config.dc.enabled) dc_clock();
|
if (config.dc.enabled) dc_clock();
|
if (config.ic.enabled) ic_clock();
|
if (config.ic.enabled) ic_clock();
|
}
|
}
|
|
|
if (config.pm.enabled) pm_clock();
|
if (config.pm.enabled) pm_clock();
|
if (config.uarts) uart_clock();
|
if (config.uarts) uart_clock();
|
if (config.dmas) dma_clock();
|
if (config.dmas) dma_clock();
|
if (config.ethernets) eth_clock();
|
if (config.ethernets) eth_clock();
|
if (config.ngpios) gpio_clock();
|
if (config.ngpios) gpio_clock();
|
if (config.nvgas) vga_clock();
|
if (config.nvgas) vga_clock();
|
if (config.fb.enabled) fb_clock();
|
if (config.fb.enabled) fb_clock();
|
if (config.kbd.enabled) kbd_clock();
|
if (config.kbd.enabled) kbd_clock();
|
if (config.vapi.enabled && runtime.vapi.enabled) vapi_check();
|
if (config.vapi.enabled && runtime.vapi.enabled) vapi_check();
|
if (config.debug.gdb_enabled) HandleServerSocket(false); /* block & check_stdin = false */
|
if (config.debug.gdb_enabled) HandleServerSocket(false); /* block & check_stdin = false */
|
IFF(config.debug.enabled)
|
IFF(config.debug.enabled)
|
if (testsprbits(SPR_DMR1, SPR_DMR1_ST)) set_stall_state (1);
|
if (testsprbits(SPR_DMR1, SPR_DMR1_ST)) set_stall_state (1);
|
|
|
cycles += mem_cycles;
|
cycles += mem_cycles;
|
if (cycles >= SCHED_PEEK().time) do_scheduler ();
|
if (cycles >= SCHED_PEEK().time) do_scheduler ();
|
if (!hush) dumpreg();
|
if (!hush) dumpreg();
|
}
|
}
|
hush = 0;
|
hush = 0;
|
fflush(stdout);
|
fflush(stdout);
|
freopen("/dev/fd/0", "w+", stdout);
|
freopen("/dev/fd/0", "w+", stdout);
|
|
|
if (!runtime.sim.iprompt) /* non-interactive quit */
|
if (!runtime.sim.iprompt) /* non-interactive quit */
|
sim_done();
|
sim_done();
|
|
|
#ifdef HAVE_LIBREADLINE
|
#ifdef HAVE_LIBREADLINE
|
if (linestr)
|
if (linestr)
|
free (linestr);
|
free (linestr);
|
#endif
|
#endif
|
|
|
}
|
}
|
sim_done();
|
sim_done();
|
}
|
}
|
|
|
#ifdef HAVE_LIBREADLINE
|
#ifdef HAVE_LIBREADLINE
|
char *command_generator ();
|
char *command_generator ();
|
char **sim_completion ();
|
char **sim_completion ();
|
|
|
/* Tell the GNU readline library how to complete. We want to try to complete
|
/* Tell the GNU readline library how to complete. We want to try to complete
|
on command names if this is the first word in the line, or on filenames
|
on command names if this is the first word in the line, or on filenames
|
if not. */
|
if not. */
|
void initialize_readline ()
|
void initialize_readline ()
|
{
|
{
|
/* Allow conditional parsing of the ~/.inputrc file. */
|
/* Allow conditional parsing of the ~/.inputrc file. */
|
rl_readline_name = "or1ksim";
|
rl_readline_name = "or1ksim";
|
|
|
/* Tell the completer that we want a crack first. */
|
/* Tell the completer that we want a crack first. */
|
rl_attempted_completion_function = (CPPFunction *)sim_completion;
|
rl_attempted_completion_function = (CPPFunction *)sim_completion;
|
}
|
}
|
|
|
/* Attempt to complete on the contents of TEXT. START and END bound the
|
/* Attempt to complete on the contents of TEXT. START and END bound the
|
region of rl_line_buffer that contains the word to complete. TEXT is
|
region of rl_line_buffer that contains the word to complete. TEXT is
|
the word to complete. We can use the entire contents of rl_line_buffer
|
the word to complete. We can use the entire contents of rl_line_buffer
|
in case we want to do some simple parsing. Return the array of matches,
|
in case we want to do some simple parsing. Return the array of matches,
|
or NULL if there aren't any. */
|
or NULL if there aren't any. */
|
char **
|
char **
|
sim_completion (text, start, end)
|
sim_completion (text, start, end)
|
char *text;
|
char *text;
|
int start, end;
|
int start, end;
|
{
|
{
|
char **matches;
|
char **matches;
|
|
|
matches = (char **)NULL;
|
matches = (char **)NULL;
|
|
|
/* If this word is at the start of the line, then it is a command
|
/* If this word is at the start of the line, then it is a command
|
to complete. Otherwise it is the name of a file in the current
|
to complete. Otherwise it is the name of a file in the current
|
directory. */
|
directory. */
|
if (start == 0)
|
if (start == 0)
|
matches = completion_matches (text, command_generator);
|
matches = completion_matches (text, command_generator);
|
|
|
return (matches);
|
return (matches);
|
}
|
}
|
|
|
/* Generator function for command completion. STATE lets us know whether
|
/* Generator function for command completion. STATE lets us know whether
|
to start from scratch; without any state (i.e. STATE == 0), then we
|
to start from scratch; without any state (i.e. STATE == 0), then we
|
start at the top of the list. */
|
start at the top of the list. */
|
char *
|
char *
|
command_generator (text, state)
|
command_generator (text, state)
|
char *text;
|
char *text;
|
int state;
|
int state;
|
{
|
{
|
static int list_index, len;
|
static int list_index, len;
|
char *name;
|
char *name;
|
|
|
/* If this is a new word to complete, initialize now. This includes
|
/* If this is a new word to complete, initialize now. This includes
|
saving the length of TEXT for efficiency, and initializing the index
|
saving the length of TEXT for efficiency, and initializing the index
|
variable to 0. */
|
variable to 0. */
|
if (!state)
|
if (!state)
|
{
|
{
|
list_index = 0;
|
list_index = 0;
|
len = strlen (text);
|
len = strlen (text);
|
}
|
}
|
|
|
/* Return the next name which partially matches from the command list. */
|
/* Return the next name which partially matches from the command list. */
|
while (name = sim_commands[list_index])
|
while (name = sim_commands[list_index])
|
{
|
{
|
list_index++;
|
list_index++;
|
|
|
if (strncmp (name, text, len) == 0)
|
if (strncmp (name, text, len) == 0)
|
return (dupstr(name));
|
return (dupstr(name));
|
}
|
}
|
|
|
/* If no names matched, then return NULL. */
|
/* If no names matched, then return NULL. */
|
return ((char *)NULL);
|
return ((char *)NULL);
|
}
|
}
|
|
|
/* Repeats the last command. */
|
/* Repeats the last command. */
|
char *
|
char *
|
repeat_last_command ()
|
repeat_last_command ()
|
{
|
{
|
int offset = where_history ();
|
int offset = where_history ();
|
HIST_ENTRY *hist;
|
HIST_ENTRY *hist;
|
|
|
if (hist = history_get (offset))
|
if (hist = history_get (offset))
|
return dupstr (hist->line);
|
return dupstr (hist->line);
|
return 0;
|
return 0;
|
}
|
}
|
|
|
#endif
|
#endif
|
|
|
extern char *disassembled;
|
extern char *disassembled;
|
void debugmem( unsigned long from, unsigned long to )
|
void debugmem( unsigned long from, unsigned long to )
|
{
|
{
|
int i;
|
int i;
|
printf("starting to dump mem...\n");
|
printf("starting to dump mem...\n");
|
for(i=from; i<to; ) {
|
for(i=from; i<to; ) {
|
struct label_entry *entry;
|
struct label_entry *entry;
|
unsigned int _insn;
|
unsigned int _insn;
|
printf("i=%x :: ", i);
|
printf("i=%x :: ", i);
|
|
|
if (verify_memoryarea(i) && (entry = get_label(i)))
|
if (verify_memoryarea(i) && (entry = get_label(i)))
|
printf("label: %s |", entry->name);
|
printf("label: %s |", entry->name);
|
|
|
iqueue[0].insn = _insn = evalsim_mem32(i);
|
iqueue[0].insn = _insn = evalsim_mem32(i);
|
iqueue[0].insn_index = insn_decode(_insn);
|
iqueue[0].insn_index = insn_decode(_insn);
|
disassemble_insn (_insn);
|
disassemble_insn (_insn);
|
printf("%08x %s\n", _insn, disassembled);
|
printf("%08x %s\n", _insn, disassembled);
|
i += insn_len( iqueue[0].insn_index );
|
i += insn_len( iqueue[0].insn_index );
|
}
|
}
|
}
|
}
|
|
|