/* 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 <signal.h>
|
#include <signal.h>
|
#include <stdarg.h>
|
#include <stdarg.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 "trace.h"
|
#include "trace.h"
|
#include "execute.h"
|
#include "execute.h"
|
|
|
#include "coff.h"
|
#include "coff.h"
|
|
|
/* CVS revision number. */
|
/* CVS revision number. */
|
static const char rcsrev[] = "$Revision: 1.7 $";
|
static const char rcsrev[] = "$Revision: 1.8 $";
|
|
|
/* 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",
|
"q",
|
"t",
|
"t",
|
"help",
|
"help",
|
"de",
|
"de",
|
"dm",
|
"dm",
|
"run",
|
"run",
|
"pr",
|
"pr",
|
"pm",
|
"pm",
|
"pc",
|
"pc",
|
"reset",
|
"reset",
|
"break",
|
"break",
|
"hist",
|
"hist",
|
"stats",
|
"stats",
|
"info",
|
"info",
|
"r",
|
"r",
|
0
|
0
|
};
|
};
|
|
|
void debug(const char *format, ...)
|
void debug(const char *format, ...)
|
{
|
{
|
#if DEBUG
|
#if DEBUG
|
char *p;
|
char *p;
|
va_list ap;
|
va_list ap;
|
|
|
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
|
return;
|
return;
|
}
|
}
|
|
|
|
/* Strip whitespace from the start and end of STRING. Return a pointer
|
|
into STRING. */
|
|
#ifndef whitespace
|
|
#define whitespace(a) ((a) == '\t' ? 1 : ((a) == ' '? 1 : 0))
|
|
#endif
|
|
|
|
char *
|
|
stripwhite (string)
|
|
char *string;
|
|
{
|
|
register char *s, *t;
|
|
|
|
for (s = string; whitespace (*s); s++)
|
|
;
|
|
|
|
if (*s == 0)
|
|
return (s);
|
|
|
|
t = s + strlen (s) - 1;
|
|
while (t > s && whitespace (*t))
|
|
t--;
|
|
*++t = '\0';
|
|
|
|
return s;
|
|
}
|
|
|
void
|
void
|
ctrl_c(signum)
|
ctrl_c(signum)
|
int signum;
|
int signum;
|
{
|
{
|
cont_run = 1;
|
cont_run = 1;
|
signal(SIGINT, ctrl_c);
|
signal(SIGINT, ctrl_c);
|
}
|
}
|
|
|
void
|
void
|
version()
|
version()
|
{
|
{
|
printf ("\n");
|
printf ("\n");
|
printf ("OpenRISC 1000 (OR16+OR32) Architectural Simulator, %s\n", rcsrev);
|
printf ("OpenRISC 1000 (OR16+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 ("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 <cycles> [<hush>] - execute <cycles> instructions, no reg dump if hush\n");
|
printf("run <cycles> [<hush>] - execute <cycles> 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 - debug insn memory\n");
|
printf("de - 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("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("<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");
|
printf("help - available commands (this list)\n");
|
printf("help - available commands (this list)\n");
|
}
|
}
|
|
|
void debugmem();
|
void debugmem();
|
|
|
main(argc, argv)
|
main(argc, argv)
|
int argc;
|
int argc;
|
char *argv[];
|
char *argv[];
|
{
|
{
|
char *linestr;
|
char *linestr;
|
char item1[500], b2[500];
|
char item1[500], b2[500];
|
char *redirstr;
|
char *redirstr;
|
int hush;
|
int hush;
|
|
|
if (argc != 2)
|
if (argc != 2)
|
{
|
{
|
printf("Usage: %s <filename>\n", argv[0]);
|
printf("Usage: %s <filename>\n", argv[0]);
|
exit(-1);
|
exit(-1);
|
}
|
}
|
|
|
#ifdef HAVE_LIBREADLINE
|
#ifdef HAVE_LIBREADLINE
|
initialize_readline (); /* Bind our completer. */
|
initialize_readline (); /* Bind our completer. */
|
#endif
|
#endif
|
|
|
version();
|
version();
|
init_defconfig();
|
init_defconfig();
|
signal(SIGINT, ctrl_c);
|
signal(SIGINT, ctrl_c);
|
initstats();
|
initstats();
|
loadcode(argv[1]);
|
loadcode(argv[1]);
|
|
uart_reset();
|
reset();
|
reset();
|
|
|
while(1)
|
while(1)
|
{
|
{
|
#ifdef HAVE_LIBREADLINE
|
#ifdef HAVE_LIBREADLINE
|
linestr = readline("(sim) ");
|
linestr = readline("(sim) ");
|
#else
|
#else
|
printf ("(sim) ");
|
printf ("(sim) ");
|
linestr = fgets(b2, sizeof b2, stdin);
|
linestr = fgets(b2, sizeof b2, stdin);
|
#endif
|
#endif
|
|
|
if (!linestr)
|
if (!linestr)
|
{
|
{
|
break;
|
break;
|
}
|
}
|
linestr = stripwhite (linestr);
|
linestr = stripwhite (linestr);
|
|
|
#ifdef HAVE_LIBREADLINE
|
#ifdef HAVE_LIBREADLINE
|
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);
|
}
|
}
|
|
|
strtoken(linestr, item1, 1);
|
strtoken(linestr, item1, 1);
|
if (strcmp(item1, "q") == 0) /* quit */
|
if (strcmp(item1, "q") == 0) /* quit */
|
exit(0);
|
exit(0);
|
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);
|
dumpmemory(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;
|
|
|
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));
|
set_mem32(addr, strtoul(item3, NULL, 0));
|
} 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);
|
set_reg32(item2, strtoul(item3, NULL, 0));
|
set_reg32(item2, 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);
|
pctemp = strtoul(item2, NULL, 0);
|
pctemp = 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 */
|
debugmem();
|
debugmem();
|
} else
|
} else
|
if (strcmp(item1, "reset") == 0) { /* reset simulator */
|
if (strcmp(item1, "reset") == 0) { /* reset simulator */
|
|
uart_reset();
|
reset();
|
reset();
|
} else
|
} else
|
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);
|
dumpmemory(histexec[i - 1], histexec[i - 1] + 4);
|
} 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 = strtoul(item2, NULL, 0);
|
cont_run = strtoul(item2, NULL, 0);
|
} 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 */
|
bpb_info();
|
bpb_info();
|
btic_info();
|
btic_info();
|
ic_info();
|
ic_info();
|
dc_info();
|
dc_info();
|
|
uart_status();
|
|
sprs_status();
|
} else {
|
} else {
|
printf("%s: Unknown command.\n", linestr);
|
printf("%s: Unknown command.\n", linestr);
|
}
|
}
|
|
|
while(cont_run) {
|
while(cont_run) {
|
cont_run--;
|
cont_run--;
|
fetch();
|
fetch();
|
decode(&iqueue[0]);
|
decode(&iqueue[0]);
|
execute();
|
execute();
|
|
uart_clock();
|
if (!hush)
|
if (!hush)
|
dumpreg();
|
dumpreg();
|
}
|
}
|
|
|
hush = 0;
|
hush = 0;
|
fflush(stdout);
|
fflush(stdout);
|
freopen("/dev/fd/0", "w+", stdout);
|
freopen("/dev/fd/0", "w+", stdout);
|
|
|
#ifdef HAVE_LIBREADLINE
|
#ifdef HAVE_LIBREADLINE
|
if (linestr)
|
if (linestr)
|
free (linestr);
|
free (linestr);
|
#endif
|
#endif
|
|
|
}
|
}
|
exit(0);
|
exit(0);
|
}
|
}
|
|
|
#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);
|
}
|
}
|
|
|
char *
|
char *
|
dupstr (s)
|
dupstr (s)
|
char *s;
|
char *s;
|
{
|
{
|
char *r;
|
char *r;
|
|
|
r = xmalloc (strlen (s) + 1);
|
r = xmalloc (strlen (s) + 1);
|
strcpy (r, s);
|
strcpy (r, s);
|
return (r);
|
return (r);
|
}
|
}
|
|
|
/* 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
|
|
|
/* Strip whitespace from the start and end of STRING. Return a pointer
|
|
into STRING. */
|
|
#ifndef whitespace
|
|
#define whitespace(a) ((a) == '\t' ? 1 : ((a) == ' '? 1 : 0))
|
|
#endif
|
|
|
|
char *
|
|
stripwhite (string)
|
|
char *string;
|
|
{
|
|
register char *s, *t;
|
|
|
|
for (s = string; whitespace (*s); s++)
|
|
;
|
|
|
|
if (*s == 0)
|
|
return (s);
|
|
|
|
t = s + strlen (s) - 1;
|
|
while (t > s && whitespace (*t))
|
|
t--;
|
|
*++t = '\0';
|
|
|
|
return s;
|
|
}
|
|
|
|
void debugmem() {
|
void debugmem() {
|
int i;
|
int i;
|
printf("starting to dump mem...\n");
|
printf("starting to dump mem...\n");
|
for(i=0; i<500; i++) {
|
for(i=0; i<500; i++) {
|
printf("i=%x :: ", i);
|
printf("i=%x :: ", i);
|
if(strlen(mem[i].label) != 0)
|
if (mem[i].label)
|
printf("label: %s |", mem[i].label->name);
|
printf("label: %s |", mem[i].label->name);
|
printf("%s ", mem[i].insn->insn);
|
printf("%s ", mem[i].insn->insn);
|
if(strlen(mem[i].insn->op1) != 0) printf("%s ", mem[i].insn->op1);
|
if(strlen(mem[i].insn->op1) != 0) printf("%s ", mem[i].insn->op1);
|
if(strlen(mem[i].insn->op2) != 0) printf("%s ", mem[i].insn->op2);
|
if(strlen(mem[i].insn->op2) != 0) printf("%s ", mem[i].insn->op2);
|
if(strlen(mem[i].insn->op3) != 0) printf("%s ", mem[i].insn->op3);
|
if(strlen(mem[i].insn->op3) != 0) printf("%s ", mem[i].insn->op3);
|
if(strlen(mem[i].insn->op4) != 0) printf("%s ", mem[i].insn->op4);
|
if(strlen(mem[i].insn->op4) != 0) printf("%s ", mem[i].insn->op4);
|
printf("\n");
|
printf("\n");
|
}
|
}
|
}
|
}
|
|
|