@echo "FRESHCONF"
checkconf:
+ @echo "CHECKCONF"
@if [ -f devel ]; then $(MAKE) freshconf; fi
# End of Makefile
uCsim is a micro-controller simulator. It is extensible to support
different micro-controller families. Currently it supports Intel MCS51
-family and Atmel AVR is under development.
+family. Atmel AVR core is working now and Z80 support is under
+development.
How to get uCsim?
uCsim is distributed in source code under GPL. It can be downloaded
from its home site:
-http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/ucsim
+http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/ucsim/
uCsim is included in sdcc, free C compiler of Sandeep Dutta. It is a
complete development package with debugger (see belove). It can be
downloaded from its home site (or from its mirrors):
-http://www.geocities.com/ResearchTriangle/Forum/1353
+http://sdcc.sourceforge.net/
Mailing list
There is no mailing list which is specifically opened for
uCsim. Announcements are sent to sdcc's mailing list. See sdcc's main
-page at above URL for subscribing infromation and the archive. Ideas,
+page at above URL for subscribing information and the archive. Ideas,
bug reports or fixes should be sent to sdcc's list too.
sdcdb
Debugger of the free C compiler, called sdcc written by Sandeep
- Dutta <dutta@comm.mot.com>. It is a usual debugger with command
+ Dutta <sandeep.dutta@usa.net>. It is a usual debugger with command
line interface which uses uCsim in background to run the
code. "Standard" interface of the sdcdb makes it possible to use
any debugger GUI such as ddd to make it comfortable.
class cl_sim *sim;
app= new cl_app();
- app->init();
- sim= new cl_simavr(app, argc, argv);
+ app->init(argc, argv);
+ sim= new cl_simavr(app);
sim->init();
app->set_simulator(sim);
sim->main();
/*@1@*/
-#include <ctype.h>
+//#include <ctype.h>
// sim.src
#include "appcl.h"
#include "avrcl.h"
-cl_simavr::cl_simavr(class cl_app *the_app, int iargc, char *iargv[]):
- cl_sim(the_app, "h", iargc, iargv)
+cl_simavr::cl_simavr(class cl_app *the_app):
+ cl_sim(the_app)
{}
-
-static void
-print_help(char *name)
-{
- printf("%s: %s\n", name, VERSIONSTR);
- printf("Usage: %s [-hHVvP] [-p prompt] [-t CPU] [-X freq[k|M]]\n"
- " [-c file] [-s file] [-S optionlist]"
-#ifdef SOCKET_AVAIL
- " [-Z portnum]"
-#endif
- "\n"
- " [files...]\n", name);
- printf
- (
- "Options:\n"
- " -t CPU Type of CPU: etc.\n"
- " -X freq[k|M] XTAL frequency\n"
- " -c file Open command console on `file'\n"
-#ifdef SOCKET_AVAIL
- " -Z portnum Use localhost:portnumber for command console\n"
-#endif
- " -s file Connect serial interface to `file'\n"
- " -S options `options' is a comma separated list of options\n"
- " according to serial interface. Know options are:\n"
- " in=file serial input will be read from file named `file'\n"
- " out=file serial output will be written to `file'\n"
- " -p prompt Specify string for prompt\n"
- " -P Prompt is a null ('\\0') character\n"
- " -V Verbose mode\n"
- " -v Print out version number\n"
- " -H Print out types of known CPUs\n"
- " -h Print out this help\n"
- );
-}
-
-
-int
-cl_simavr::proc_arg(char optopt, char *optarg)
-{
- switch (optopt)
- {
-
- case 'h':
-
- print_help("savr");
- exit(0);
- break;
-
- case '?':
-
- if (isprint(optopt))
- fprintf(stderr, "Unknown option `-%c'.\n", optopt);
- else
- fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
- return(1);
- break;
-
- default:
- // should never happen...
- abort();
- }
-}
-
-
class cl_uc *
cl_simavr::mk_controller(void)
{
class cl_simavr: public cl_sim
{
public:
- cl_simavr(class cl_app *the_app, int iargc, char *iargv[]);
- virtual int proc_arg(char optopt, char *optarg);
+ cl_simavr(class cl_app *the_app);
virtual class cl_uc *mk_controller(void);
};
# Deleting all files created by building the program
# --------------------------------------------------
clean:
- rm -f *core *[%~] *.[oa] *.so
+ rm -f *core *[%~] *.[oa] *.so ucsim
rm -f .[a-z]*~
srcdir = @srcdir@
OBJECTS = cmdset.o newcmd.o cmdutil.o syntax.o \
- get.o set.o timer.o bp.o info.o show.o cmdgui.o cmdconf.o
+ get.o set.o timer.o bp.o info.o show.o cmdgui.o cmdconf.o \
+ cmduc.o
# Compiling entire program or any subproject
* BREAK command
*/
-int
-cl_break_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_break_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_break_cmd)
{
t_addr addr= 0;
int hit= 1;
cmdline->param(2),
cmdline->param(3) };
- if (cmdline->syntax_match(sim, ADDRESS)) {
+ if (cmdline->syntax_match(uc, ADDRESS)) {
addr= params[0]->value.address;
hit= 1;
- do_fetch(sim, addr, hit, con);
+ do_fetch(uc, addr, hit, con);
}
- else if (cmdline->syntax_match(sim, ADDRESS NUMBER)) {
+ else if (cmdline->syntax_match(uc, ADDRESS NUMBER)) {
addr= params[0]->value.address;
hit= params[1]->value.number;
- do_fetch(sim, addr, hit, con);
+ do_fetch(uc, addr, hit, con);
}
- else if (cmdline->syntax_match(sim, MEMORY STRING ADDRESS)) {
+ else if (cmdline->syntax_match(uc, MEMORY STRING ADDRESS)) {
mem= params[0]->value.memory;
op= *(params[1]->get_svalue());
addr= params[2]->value.address;
hit= 1;
- do_event(sim, mem, op, addr, hit, con);
+ do_event(uc, mem, op, addr, hit, con);
}
- else if (cmdline->syntax_match(sim, MEMORY STRING ADDRESS NUMBER)) {
+ else if (cmdline->syntax_match(uc, MEMORY STRING ADDRESS NUMBER)) {
mem= params[0]->value.memory;
op= *(params[1]->get_svalue());
addr= params[2]->value.address;
hit= params[3]->value.number;
- do_event(sim, mem, op, addr, hit, con);
+ do_event(uc, mem, op, addr, hit, con);
}
else
{
}
void
-cl_break_cmd::do_fetch(class cl_sim *sim,
+cl_break_cmd::do_fetch(class cl_uc *uc,
t_addr addr, int hit, class cl_console *con)
{
if (hit > 99999)
con->printf("Hit value %d is too big.\n", hit);
return;
}
- if (sim->uc->fbrk->bp_at(addr))
+ if (uc->fbrk->bp_at(addr))
con->printf("Breakpoint at 0x%06x is already set.\n", addr);
else
{
- class cl_brk *b= new cl_fetch_brk(sim->uc->make_new_brknr(),
+ class cl_brk *b= new cl_fetch_brk(uc->make_new_brknr(),
addr, perm, hit);
b->init();
- sim->uc->fbrk->add_bp(b);
- char *s= sim->uc->disass(addr, NULL);
+ uc->fbrk->add_bp(b);
+ char *s= uc->disass(addr, NULL);
con->printf("Breakpoint %d at 0x%06x: %s\n", b->nr, addr, s);
free(s);
}
}
void
-cl_break_cmd::do_event(class cl_sim *sim,
+cl_break_cmd::do_event(class cl_uc *uc,
class cl_mem *mem, char op, t_addr addr, int hit,
class cl_console *con)
{
class cl_ev_brk *b= NULL;
- b= sim->uc->mk_ebrk(perm, mem, op, addr, hit);
+ b= uc->mk_ebrk(perm, mem, op, addr, hit);
if (b)
- sim->uc->ebrk->add_bp(b);
+ uc->ebrk->add_bp(b);
else
con->printf("Couldn't make event breakpoint\n");
}
* CLEAR address
*/
-int
-cl_clear_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_clear_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_clear_cmd)
{
int idx;
- class cl_brk *brk= sim->uc->fbrk->get_bp(sim->uc->PC, &idx);
+ class cl_brk *brk= uc->fbrk->get_bp(uc->PC, &idx);
if (cmdline->param(0) == 0)
{
con->printf("No breakpoint at this address.\n");
return(0);
}
- sim->uc->fbrk->del_bp(sim->uc->PC);
+ uc->fbrk->del_bp(uc->PC);
return(0);
}
while ((param= cmdline->param(i++)))
{
t_addr addr;
- if (!param->as_address())
+ if (!param->as_address(uc))
return(DD_FALSE);
addr= param->value.address;
- if (sim->uc->fbrk->bp_at(addr) == 0)
- sim->cmd->printf("No breakpoint at 0x%06x\n", addr);
+ if (uc->fbrk->bp_at(addr) == 0)
+ con->printf("No breakpoint at 0x%06x\n", addr);
else
- sim->uc->fbrk->del_bp(addr);
+ uc->fbrk->del_bp(addr);
}
return(DD_FALSE);
* DELETE nr nr ...
*/
-int
-cl_delete_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_delete_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_delete_cmd)
{
if (cmdline->param(0) == 0)
{
// delete all
- sim->uc->remove_all_breaks();
+ uc->remove_all_breaks();
}
else
{
{
long num;
if (param->get_ivalue(&num))
- sim->uc->rm_brk(num);
+ uc->rm_brk(num);
}
}
return(DD_FALSE);
COMMAND_HEAD(cl_break_cmd)
public:
enum brk_perm perm;
-COMMAND_METHODS(cl_break_cmd)
- virtual void do_fetch(class cl_sim *sim,
+COMMAND_METHODS_ON(uc,cl_break_cmd)
+ virtual void do_fetch(class cl_uc *uc,
t_addr addr, int hit, class cl_console *con);
- virtual void do_event(class cl_sim *sim,
+ virtual void do_event(class cl_uc *uc,
class cl_mem *mem, char op, t_addr addr, int hit,
class cl_console *con);
COMMAND_TAIL;
};
// CLEAR
-COMMAND(cl_clear_cmd);
+COMMAND_ON(uc,cl_clear_cmd);
// DELETE
-COMMAND(cl_delete_cmd);
+COMMAND_ON(uc,cl_delete_cmd);
#endif
*----------------------------------------------------------------------------
*/
-int
-cl_conf_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_conf_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_conf_cmd)
{
int i;
con->printf("ucsim version %s\n", VERSIONSTR);
- con->printf("Type of microcontroller: %s\n", sim->uc->id_string());
+ con->printf("Type of microcontroller: %s\n", uc->id_string());
con->printf("Controller has %d hardware element(s).\n",
- sim->uc->hws->count);
- for (i= 0; i < sim->uc->hws->count; i++)
+ uc->hws->count);
+ for (i= 0; i < uc->hws->count; i++)
{
- class cl_hw *hw= (class cl_hw *)(sim->uc->hws->at(i));
+ class cl_hw *hw= (class cl_hw *)(uc->hws->at(i));
con->printf(" %s[%d]\n", hw->id_string, hw->id);
}
con->printf("Memories:\n");
for (i= MEM_ROM; i < MEM_TYPES; i++)
{
- class cl_mem *mem= (class cl_mem *)(sim->uc->mems->at(i));
+ class cl_mem *mem= (class cl_mem *)(uc->mems->at(i));
if (mem)
con->printf(" %s size= 0x%06x %6d width= %2d class= \"%s\"\n",
mem->id_string(), mem->size, mem->size, mem->width,
*----------------------------------------------------------------------------
*/
-int
-cl_conf_addmem_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_conf_addmem_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_conf_addmem_cmd)
{
class cl_mem *mem= 0;
class cl_cmd_arg *params[4]= { cmdline->param(0),
cmdline->param(3) };
char *mem_class;
- if (cmdline->syntax_match(sim, STRING)) {
+ if (cmdline->syntax_match(uc, STRING)) {
mem_class= params[0]->value.string.string;
enum mem_class type;
type= (enum mem_class)get_string_id(mem_classes, mem_class, -1);
- mem= sim->uc->mk_mem(type, mem_class);
+ mem= uc->mk_mem(type, mem_class);
if (mem)
{
- class cl_mem *m= sim->uc->mem(type);
+ class cl_mem *m= uc->mem(type);
if (m)
delete m;
- sim->uc->mems->put_at(type, mem);
+ uc->mems->put_at(type, mem);
}
else
con->printf("Can not make memory \"%s\"\n", mem_class);
// CONF
-COMMAND(cl_conf_cmd);
+COMMAND_ON(uc,cl_conf_cmd);
// CONF ADDMEM
-COMMAND(cl_conf_addmem_cmd);
+COMMAND_ON(uc,cl_conf_addmem_cmd);
#endif
*----------------------------------------------------------------------------
*/
-int
-cl_gui_start_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_gui_start_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_gui_start_cmd)
{
class cl_hw *hw;
class cl_mem *mem;
cmdline->param(2),
cmdline->param(3) };
- if (cmdline->syntax_match(sim, HW)) {
+ if (cmdline->syntax_match(uc, HW)) {
hw= params[0]->value.hw;
}
- else if (cmdline->syntax_match(sim, MEMORY ADDRESS ADDRESS)) {
+ else if (cmdline->syntax_match(uc, MEMORY ADDRESS ADDRESS)) {
mem= params[0]->value.memory;
start= params[1]->value.address;
end= params[2]->value.address;
*----------------------------------------------------------------------------
*/
-int
-cl_gui_stop_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_gui_stop_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_gui_stop_cmd)
{
return(DD_FALSE);;
}
// GUI START
-COMMAND(cl_gui_start_cmd);
+COMMAND_ON(uc,cl_gui_start_cmd);
// GUI STOP
-COMMAND(cl_gui_stop_cmd);
+COMMAND_ON(uc,cl_gui_stop_cmd);
#endif
#include "ddconfig.h"
+// prj
#include "i_string.h"
-
-#include "globals.h"
#include "utils.h"
+#include "globals.h"
-// sim
+// sim.src
#include "simcl.h"
-// local
+// local, cmd.src
#include "cmdsetcl.h"
#include "cmdutil.h"
-/*
- * Command: state
- *----------------------------------------------------------------------------
- */
-
-int
-cl_state_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
-{
- //con->printf("sim state= %d\n", sim->state);
- con->printf("CPU state= %s PC= 0x%06x XTAL= %g\n",
- get_id_string(cpu_states, sim->uc->state),
- sim->uc->PC,
- sim->uc->xtal);
- con->printf("Total time since last reset= %g sec (%lu clks)\n",
- sim->uc->get_rtime(), sim->uc->ticks->ticks);
- con->printf("Time in isr = %g sec (%lu clks) %3.2g%%\n",
- sim->uc->isr_ticks->get_rtime(sim->uc->xtal),
- sim->uc->isr_ticks->ticks,
- (sim->uc->ticks->ticks == 0)?0.0:
- (100.0*((double)(sim->uc->isr_ticks->ticks)/
- (double)(sim->uc->ticks->ticks))));
- con->printf("Time in idle= %g sec (%lu clks) %3.2g%%\n",
- sim->uc->idle_ticks->get_rtime(sim->uc->xtal),
- sim->uc->idle_ticks->ticks,
- (sim->uc->ticks->ticks == 0)?0.0:
- (100.0*((double)(sim->uc->idle_ticks->ticks)/
- (double)(sim->uc->ticks->ticks))));
- con->printf("Max value of stack pointer= 0x%06x, avg= 0x%06x\n",
- sim->uc->sp_max, sim->uc->sp_avg);
- return(0);
-}
-
-
-/*
- * Command: file
- *----------------------------------------------------------------------------
- */
-
-int
-cl_file_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
-{
- char *fname= 0;
- long l;
-
- if ((cmdline->param(0) == 0) ||
- ((fname= cmdline->param(0)->get_svalue()) == NULL))
- {
- con->printf("File name is missing.\n");
- return(0);
- }
- if ((l= sim->uc->read_hex_file(fname)) >= 0)
- con->printf("%ld words read from %s\n", l, fname);
-
- return(0);
-}
-
-
-/*
- * Command: download
- *----------------------------------------------------------------------------
- */
-
-int
-cl_dl_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
-{
- long l;
-
- if ((l= sim->uc->read_hex_file(NULL)) >= 0)
- con->printf("%ld words loaded\n", l);
-
- return(0);
-}
-
-
/*
* Command: run
*----------------------------------------------------------------------------
*/
-int
-cl_run_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_run_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_SIM(cl_run_cmd)
{
class cl_brk *b;
t_addr start, end;
cmdline->param(3) };
if (params[0])
- if (!(params[0]->get_address(&start)))
+ if (!(params[0]->get_address(sim->uc, &start)))
{
con->printf("Error: wrong start address\n");
return(DD_FALSE);
}
if (params[1])
- if (!(params[1]->get_address(&end)))
+ if (!(params[1]->get_address(sim->uc, &end)))
{
con->printf("Error: wromg end address\n");
return(DD_FALSE);
*----------------------------------------------------------------------------
*/
-int
-cl_stop_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_stop_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_SIM(cl_stop_cmd)
{
sim->stop(resUSER);
sim->uc->print_disass(sim->uc->PC, con);
*----------------------------------------------------------------------------
*/
-int
-cl_step_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_step_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_step_cmd)
{
- sim->uc->do_inst(1);
- sim->uc->print_regs(con);
+ uc->do_inst(1);
+ uc->print_regs(con);
return(0);
}
*----------------------------------------------------------------------------
*/
-int
-cl_next_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_next_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_SIM(cl_next_cmd)
{
class cl_brk *b;
t_addr next;
}
-/*
- * Command: pc
- *----------------------------------------------------------------------------
- */
-
-int
-cl_pc_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
-{
- t_addr addr;
- class cl_cmd_arg *params[1]= { cmdline->param(0) };
-
- if (params[0])
- {
- if (!(params[0]->get_address(&addr)))
- {
- con->printf("Error: wrong parameter\n");
- return(DD_FALSE);
- }
- if (addr >= sim->uc->get_mem_size(MEM_ROM))
- addr= 0;
- if (!sim->uc->inst_at(addr))
- con->printf("Warning: maybe not instruction at 0x%06x\n", addr);
- sim->uc->PC= addr;
- }
- sim->uc->print_disass(sim->uc->PC, con);
- return(DD_FALSE);
-}
-
-
-/*
- * Command: reset
- *----------------------------------------------------------------------------
- */
-
-int
-cl_reset_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
-{
- sim->uc->reset();
- return(0);
-}
-
-
-/*
- * Command: dump
- *----------------------------------------------------------------------------
- */
-
-int
-cl_dump_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
-{
- class cl_mem *mem= 0;
- long bpl= 8;
- t_addr start= 0, end;
- class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
-
- if (params[0] &&
- params[0]->as_bit(sim->uc))
- {
- int i= 0;
- while (params[0] &&
- params[0]->as_bit(sim->uc))
- {
- t_mem m;
- mem= params[0]->value.bit.mem;
- m= mem->read(params[0]->value.bit.mem_address);
- char *sn=
- sim->uc->symbolic_bit_name((t_addr)-1,
- mem,
- params[0]->value.bit.mem_address,
- params[0]->value.bit.mask);
- con->printf("%10s ", sn?sn:"");
- con->printf(mem->addr_format, params[0]->value.bit.mem_address);
- con->printf(" ");
- con->printf(mem->data_format, m);
- con->printf(" %c\n", (m&(params[0]->value.bit.mask))?'1':'0');
- i++;
- params[0]= cmdline->param(i);
- }
- if (params[0])
- con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
- }
- else if (cmdline->syntax_match(sim, MEMORY))
- {
- mem= params[0]->value.memory;
- mem->dump(con);
- }
- else if (cmdline->syntax_match(sim, MEMORY ADDRESS)) {
- mem = params[0]->value.memory;
- start= params[1]->value.address;
- end = start+10*8-1;
- mem->dump(start, end, bpl, con);
- }
- else if (cmdline->syntax_match(sim, MEMORY ADDRESS ADDRESS)) {
- mem = params[0]->value.memory;
- start= params[1]->value.address;
- end = params[2]->value.address;
- mem->dump(start, end, bpl, con);
- }
- else if (cmdline->syntax_match(sim, MEMORY ADDRESS ADDRESS NUMBER)) {
- mem = params[0]->value.memory;
- start= params[1]->value.address;
- end = params[2]->value.address;
- bpl = params[3]->value.number;
- mem->dump(start, end, bpl, con);
- }
- else
- con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
-
- return(DD_FALSE);;
-}
-
-
-/*
- * Command: di
- *----------------------------------------------------------------------------
- */
-
-int
-cl_di_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
-{
- cmdline->insert_param(0, new cl_cmd_sym_arg(sim->uc, "i"));
- cl_dump_cmd::do_work(sim, cmdline, con);
- return(0);
-}
-
-
-/*
- * Command: dx
- *----------------------------------------------------------------------------
- */
-
-int
-cl_dx_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
-{
- cmdline->insert_param(0, new cl_cmd_sym_arg(sim->uc, "x"));
- cl_dump_cmd::do_work(sim, cmdline, con);
- return(0);
-}
-
-
-/*
- * Command: dch
- *----------------------------------------------------------------------------
- */
-
-int
-cl_dch_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
-{
- cmdline->insert_param(0, new cl_cmd_sym_arg(sim->uc, "r"));
- cl_dump_cmd::do_work(sim, cmdline, con);
- return(0);
-}
-
-
-/*
- * Command: ds
- *----------------------------------------------------------------------------
- */
-
-int
-cl_ds_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
-{
- cmdline->insert_param(0, new cl_cmd_sym_arg(sim->uc, "s"));
- cl_dump_cmd::do_work(sim, cmdline, con);
- return(0);
-}
-
-
-/*
- * Command: dc
- *----------------------------------------------------------------------------
- */
-
-int
-cl_dc_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
-{
- t_addr start= last, end= last+20;
- class cl_cmd_arg *params[2]= { cmdline->param(0),
- cmdline->param(1) };
- class cl_mem *rom= sim->uc->mem(MEM_ROM);
-
- if (!rom)
- return(DD_FALSE);
- if (params[0] == 0)
- ;
- else if (cmdline->syntax_match(sim, ADDRESS)) {
- start= params[0]->value.address;
- end= start+20;
- }
- else if (cmdline->syntax_match(sim, ADDRESS ADDRESS)) {
- start= params[0]->value.address;
- end= params[1]->value.address;
- }
- if (start >= rom->size)
- {
- con->printf("Error: start address is wrong\n");
- return(DD_FALSE);
- }
- if (end >= rom->size)
- {
- con->printf("Error: end address is wrong\n");
- return(DD_FALSE);
- }
-
- for (;
- start <= end;
- start+= sim->uc->inst_length(rom->get(start)))
- sim->uc->print_disass(start, con);
- last= start;
- return(DD_FALSE);
-}
-
-
-/*
- * Command: disassemble
- *----------------------------------------------------------------------------
- */
-
-static int disass_last_stop= 0;
-
-int
-cl_disassemble_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
-{
- t_addr start, realstart;
- int offset= -1, dir, lines= 20;
- class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
-
- start= disass_last_stop;
- if (params[0] == 0) ;
- else if (cmdline->syntax_match(sim, ADDRESS)) {
- start= params[0]->value.address;
- }
- else if (cmdline->syntax_match(sim, ADDRESS NUMBER)) {
- start= params[0]->value.address;
- offset= params[1]->value.number;
- }
- else if (cmdline->syntax_match(sim, ADDRESS NUMBER NUMBER)) {
- start= params[0]->value.address;
- offset= params[1]->value.number;
- lines= params[2]->value.number;
- }
- else
- {
- con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
- return(DD_FALSE);
- }
-
- if (lines < 1)
- {
- con->printf("Error: wrong `lines' parameter\n");
- return(DD_FALSE);
- }
- if (!sim->uc->there_is_inst())
- return(DD_FALSE);
- realstart= start;
- class cl_mem *rom= sim->uc->mem(MEM_ROM);
- if (!rom)
- return(DD_FALSE);
- while (realstart < rom->size &&
- !sim->uc->inst_at(realstart))
- realstart= realstart+1;
- if (offset)
- {
- dir= (offset < 0)?-1:+1;
- while (offset)
- {
- realstart= (realstart+dir) % rom->size;
- while (!sim->uc->inst_at(realstart))
- realstart= (realstart+dir) % rom->size;
- offset+= -dir;
- }
- }
-
- while (lines)
- {
- sim->uc->print_disass(realstart, sim->cmd->actual_console);
- realstart= (realstart+1) % rom->size;
- while (!sim->uc->inst_at(realstart))
- realstart= (realstart+1) % rom->size;
- lines--;
- }
-
- disass_last_stop= realstart;
-
- return(DD_FALSE);;
-}
-
-
-/*
- * Command: fill
- *----------------------------------------------------------------------------
- */
-
-int
-cl_fill_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
-{
- class cl_mem *mem= 0;
- t_mem what= 0;
- t_addr start= 0, end;
- class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
-
- if (cmdline->syntax_match(sim, MEMORY ADDRESS ADDRESS NUMBER)) {
- mem = params[0]->value.memory;
- start= params[1]->value.address;
- end = params[2]->value.address;
- what = params[3]->value.number;
- t_addr i;
- for (i= start; i <= end; i++)
- {
- t_mem d;
- d= what;
- mem->write(i, &d);
- }
- }
- else
- con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
-
- return(DD_FALSE);;
-}
-
-
-/*
- * Command: where
- *----------------------------------------------------------------------------
- */
-
-int
-cl_where_cmd::do_real_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con,
- bool case_sensitive)
-{
- class cl_mem *mem= 0;
- class cl_cmd_arg *params[2]= { cmdline->param(0),
- cmdline->param(1) };
-
- if (cmdline->syntax_match(sim, MEMORY DATALIST)) {
- mem= params[0]->value.memory;
- t_mem *array= params[1]->value.data_list.array;
- int len= params[1]->value.data_list.len;
- if (!len)
- {
- con->printf("Error: nothing to search for\n");
- return(DD_FALSE);
- }
- t_addr addr= 0;
- bool found= mem->search_next(case_sensitive, array, len, &addr);
- while (found)
- {
- mem->dump(addr, addr+len-1, 8, con);
- addr++;
- found= mem->search_next(case_sensitive, array, len, &addr);
- }
- }
- else
- con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
-
- return(DD_FALSE);
-}
-
-int
-cl_where_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
-{
- return(do_real_work(sim, cmdline, con, DD_FALSE));
-}
-
-int
-cl_Where_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
-{
- return(do_real_work(sim, cmdline, con, DD_TRUE));
-}
-
-
/*
* Command: help
*----------------------------------------------------------------------------
*/
-int
-cl_help_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_help_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_APP(cl_help_cmd)
{
+ class cl_sim *sim;
+ class cl_commander *cmd;
+ class cl_cmdset *cmdset= 0;
class cl_cmd *c;
int i;
class cl_cmd_arg *parm= cmdline->param(0);
+ sim= app->get_sim();
+ if ((cmd= app->get_commander()) != 0)
+ cmdset= cmd->cmdset;
+ if (!cmdset)
+ return(DD_FALSE);
if (!parm) {
- for (i= 0; i < sim->cmd->cmdset->count; i++)
+ for (i= 0; i < cmdset->count; i++)
{
- c= (class cl_cmd *)(sim->cmd->cmdset->at(i));
+ c= (class cl_cmd *)(cmdset->at(i));
if (c->short_help)
con->printf("%s\n", c->short_help);
else
con->printf("%s\n", (char*)(c->names->at(0)));
}
}
- else if (cmdline->syntax_match(sim, STRING)) {
+ else if (cmdline->syntax_match(/*sim*/0, STRING)) {
int matches= 0;
- for (i= 0; i < sim->cmd->cmdset->count; i++)
+ for (i= 0; i < cmdset->count; i++)
{
- c= (class cl_cmd *)(sim->cmd->cmdset->at(i));
+ c= (class cl_cmd *)(cmdset->at(i));
if (c->name_match(parm->value.string.string, DD_FALSE))
matches++;
}
if (!matches)
con->printf("No such command\n");
else if (matches > 1)
- for (i= 0; i < sim->cmd->cmdset->count; i++)
+ for (i= 0; i < cmdset->count; i++)
{
- c= (class cl_cmd *)(sim->cmd->cmdset->at(i));
+ c= (class cl_cmd *)(cmdset->at(i));
if (!c->name_match(parm->value.string.string, DD_FALSE))
continue;
if (c->short_help)
con->printf("%s\n", (char*)(c->names->at(0)));
}
else
- for (i= 0; i < sim->cmd->cmdset->count; i++)
+ for (i= 0; i < cmdset->count; i++)
{
- c= (class cl_cmd *)(sim->cmd->cmdset->at(i));
+ c= (class cl_cmd *)(cmdset->at(i));
if (!c->name_match(parm->value.string.string, DD_FALSE))
continue;
if (c->short_help)
*----------------------------------------------------------------------------
*/
-int
-cl_quit_cmd::do_work(class cl_sim *sim,
- class cl_cmdline */*cmdline*/, class cl_console */*con*/)
+//int
+//cl_quit_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline */*cmdline*/, class cl_console */*con*/)
+COMMAND_DO_WORK(cl_quit_cmd)
{
return(1);
}
*----------------------------------------------------------------------------
*/
-int
-cl_kill_cmd::do_work(class cl_sim *sim,
- class cl_cmdline */*cmdline*/, class cl_console */*con*/)
+//int
+//cl_kill_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline */*cmdline*/, class cl_console */*con*/)
+COMMAND_DO_WORK_APP(cl_kill_cmd)
{
- sim->state|= SIM_QUIT;
+ app->going= 0;
+ if (app->sim)
+ app->sim->state|= SIM_QUIT;
return(1);
}
#include "newcmdcl.h"
// STATE
-COMMAND(cl_state_cmd);
-COMMAND(cl_file_cmd);
-COMMAND(cl_dl_cmd);
-COMMAND(cl_run_cmd);
-COMMAND(cl_stop_cmd);
-COMMAND(cl_step_cmd);
-COMMAND(cl_next_cmd);
-COMMAND(cl_pc_cmd);
-COMMAND(cl_reset_cmd);
-COMMAND(cl_dump_cmd);
-COMMAND_ANCESTOR(cl_di_cmd,cl_dump_cmd);
-COMMAND_ANCESTOR(cl_dx_cmd,cl_dump_cmd);
-COMMAND_ANCESTOR(cl_dch_cmd,cl_dump_cmd);
-COMMAND_ANCESTOR(cl_ds_cmd,cl_dump_cmd);
-COMMAND_DATA(cl_dc_cmd, t_addr last);
-COMMAND_DATA(cl_disassemble_cmd,int last);
-COMMAND_DATA(cl_fill_cmd,int last);
-COMMAND_HEAD(cl_where_cmd)
- public: int last;
-COMMAND_METHODS(cl_where_cmd)
- virtual int do_real_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con,
- bool case_sensitive);
-COMMAND_TAIL;
-COMMAND_DATA_ANCESTOR(cl_Where_cmd,cl_where_cmd,int last);
-COMMAND(cl_help_cmd);
+COMMAND_ON(sim,cl_run_cmd);
+COMMAND_ON(sim,cl_stop_cmd);
+COMMAND_ON(uc,cl_step_cmd);
+COMMAND_ON(sim,cl_next_cmd);
+COMMAND_ON(app,cl_help_cmd);
COMMAND(cl_quit_cmd);
-COMMAND(cl_kill_cmd);
-
-COMMAND_HEAD(cl_timer_cmd)
-public:
- class cl_ticker *ticker;
- long what;
- char *name;
-COMMAND_METHODS(cl_timer_cmd)
- void set_ticker(class cl_sim *sim,
- class cl_cmd_arg *param);
- virtual int add(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con);
- virtual int del(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con);
- virtual int get(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con);
- virtual int run(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con);
- virtual int stop(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con);
- virtual int val(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con);
-COMMAND_TAIL;
+COMMAND_ON(app,cl_kill_cmd);
#endif
--- /dev/null
+/*
+ * Simulator of microcontrollers (cmd.src/cmduc.cc)
+ *
+ * Copyright (C) 2001,01 Drotos Daniel, Talker Bt.
+ *
+ * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
+ *
+ */
+
+/* This file is part of microcontroller simulator: ucsim.
+
+UCSIM is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+UCSIM is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with UCSIM; see the file COPYING. If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA. */
+/*@1@*/
+
+// prj
+#include "globals.h"
+#include "utils.h"
+
+// sim.src
+#include "uccl.h"
+
+// local, cmd.src
+#include "cmduccl.h"
+
+
+/*
+ * Command: state
+ *----------------------------------------------------------------------------
+ */
+
+//int
+//cl_state_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_state_cmd)
+{
+ con->printf("CPU state= %s PC= 0x%06x XTAL= %g\n",
+ get_id_string(cpu_states, uc->state),
+ uc->PC,
+ uc->xtal);
+ con->printf("Total time since last reset= %g sec (%lu clks)\n",
+ uc->get_rtime(), uc->ticks->ticks);
+ con->printf("Time in isr = %g sec (%lu clks) %3.2g%%\n",
+ uc->isr_ticks->get_rtime(uc->xtal),
+ uc->isr_ticks->ticks,
+ (uc->ticks->ticks == 0)?0.0:
+ (100.0*((double)(uc->isr_ticks->ticks)/
+ (double)(uc->ticks->ticks))));
+ con->printf("Time in idle= %g sec (%lu clks) %3.2g%%\n",
+ uc->idle_ticks->get_rtime(uc->xtal),
+ uc->idle_ticks->ticks,
+ (uc->ticks->ticks == 0)?0.0:
+ (100.0*((double)(uc->idle_ticks->ticks)/
+ (double)(uc->ticks->ticks))));
+ con->printf("Max value of stack pointer= 0x%06x, avg= 0x%06x\n",
+ uc->sp_max, uc->sp_avg);
+ return(0);
+}
+
+
+/*
+ * Command: file
+ *----------------------------------------------------------------------------
+ */
+
+//int
+//cl_file_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_file_cmd)
+{
+ char *fname= 0;
+ long l;
+
+ if ((cmdline->param(0) == 0) ||
+ ((fname= cmdline->param(0)->get_svalue()) == NULL))
+ {
+ con->printf("File name is missing.\n");
+ return(0);
+ }
+ if ((l= uc->read_hex_file(fname)) >= 0)
+ con->printf("%ld words read from %s\n", l, fname);
+
+ return(0);
+}
+
+
+/*
+ * Command: download
+ *----------------------------------------------------------------------------
+ */
+
+//int
+//cl_dl_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_dl_cmd)
+{
+ long l;
+
+ if ((l= uc->read_hex_file(NULL)) >= 0)
+ con->printf("%ld words loaded\n", l);
+
+ return(0);
+}
+
+
+/*
+ * Command: pc
+ *----------------------------------------------------------------------------
+ */
+
+//int
+//cl_pc_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_pc_cmd)
+{
+ t_addr addr;
+ class cl_cmd_arg *params[1]= { cmdline->param(0) };
+
+ if (params[0])
+ {
+ if (!(params[0]->get_address(uc, &addr)))
+ {
+ con->printf("Error: wrong parameter\n");
+ return(DD_FALSE);
+ }
+ if (addr >= uc->get_mem_size(MEM_ROM))
+ addr= 0;
+ if (!uc->inst_at(addr))
+ con->printf("Warning: maybe not instruction at 0x%06x\n", addr);
+ uc->PC= addr;
+ }
+ uc->print_disass(uc->PC, con);
+ return(DD_FALSE);
+}
+
+
+/*
+ * Command: reset
+ *----------------------------------------------------------------------------
+ */
+
+//int
+//cl_reset_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_reset_cmd)
+{
+ uc->reset();
+ return(0);
+}
+
+
+/*
+ * Command: dump
+ *----------------------------------------------------------------------------
+ */
+
+//int
+//cl_dump_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_dump_cmd)
+{
+ class cl_mem *mem= 0;
+ long bpl= 8;
+ t_addr start= 0, end;
+ class cl_cmd_arg *params[4]= { cmdline->param(0),
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
+
+ if (params[0] &&
+ params[0]->as_bit(uc))
+ {
+ int i= 0;
+ while (params[0] &&
+ params[0]->as_bit(uc))
+ {
+ t_mem m;
+ mem= params[0]->value.bit.mem;
+ m= mem->read(params[0]->value.bit.mem_address);
+ char *sn=
+ uc->symbolic_bit_name((t_addr)-1,
+ mem,
+ params[0]->value.bit.mem_address,
+ params[0]->value.bit.mask);
+ con->printf("%10s ", sn?sn:"");
+ con->printf(mem->addr_format, params[0]->value.bit.mem_address);
+ con->printf(" ");
+ con->printf(mem->data_format, m);
+ con->printf(" %c\n", (m&(params[0]->value.bit.mask))?'1':'0');
+ i++;
+ params[0]= cmdline->param(i);
+ }
+ if (params[0])
+ con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
+ }
+ else if (cmdline->syntax_match(uc, MEMORY))
+ {
+ mem= params[0]->value.memory;
+ mem->dump(con);
+ }
+ else if (cmdline->syntax_match(uc, MEMORY ADDRESS)) {
+ mem = params[0]->value.memory;
+ start= params[1]->value.address;
+ end = start+10*8-1;
+ mem->dump(start, end, bpl, con);
+ }
+ else if (cmdline->syntax_match(uc, MEMORY ADDRESS ADDRESS)) {
+ mem = params[0]->value.memory;
+ start= params[1]->value.address;
+ end = params[2]->value.address;
+ mem->dump(start, end, bpl, con);
+ }
+ else if (cmdline->syntax_match(uc, MEMORY ADDRESS ADDRESS NUMBER)) {
+ mem = params[0]->value.memory;
+ start= params[1]->value.address;
+ end = params[2]->value.address;
+ bpl = params[3]->value.number;
+ mem->dump(start, end, bpl, con);
+ }
+ else
+ con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
+
+ return(DD_FALSE);;
+}
+
+
+/*
+ * Command: di
+ *----------------------------------------------------------------------------
+ */
+
+//int
+//cl_di_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_di_cmd)
+{
+ cmdline->insert_param(0, new cl_cmd_sym_arg("i"));
+ cl_dump_cmd::do_work(uc, cmdline, con);
+ return(0);
+}
+
+
+/*
+ * Command: dx
+ *----------------------------------------------------------------------------
+ */
+
+//int
+//cl_dx_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_dx_cmd)
+{
+ cmdline->insert_param(0, new cl_cmd_sym_arg("x"));
+ cl_dump_cmd::do_work(uc, cmdline, con);
+ return(0);
+}
+
+
+/*
+ * Command: dch
+ *----------------------------------------------------------------------------
+ */
+
+//int
+//cl_dch_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_dch_cmd)
+{
+ cmdline->insert_param(0, new cl_cmd_sym_arg("r"));
+ cl_dump_cmd::do_work(uc, cmdline, con);
+ return(0);
+}
+
+
+/*
+ * Command: ds
+ *----------------------------------------------------------------------------
+ */
+
+//int
+//cl_ds_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_ds_cmd)
+{
+ cmdline->insert_param(0, new cl_cmd_sym_arg("s"));
+ cl_dump_cmd::do_work(uc, cmdline, con);
+ return(0);
+}
+
+
+/*
+ * Command: dc
+ *----------------------------------------------------------------------------
+ */
+
+//int
+//cl_dc_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_dc_cmd)
+{
+ t_addr start= last, end= last+20;
+ class cl_cmd_arg *params[2]= { cmdline->param(0),
+ cmdline->param(1) };
+ class cl_mem *rom= uc->mem(MEM_ROM);
+
+ if (!rom)
+ return(DD_FALSE);
+ if (params[0] == 0)
+ ;
+ else if (cmdline->syntax_match(uc, ADDRESS)) {
+ start= params[0]->value.address;
+ end= start+20;
+ }
+ else if (cmdline->syntax_match(uc, ADDRESS ADDRESS)) {
+ start= params[0]->value.address;
+ end= params[1]->value.address;
+ }
+ if (start >= rom->size)
+ {
+ con->printf("Error: start address is wrong\n");
+ return(DD_FALSE);
+ }
+ if (end >= rom->size)
+ {
+ con->printf("Error: end address is wrong\n");
+ return(DD_FALSE);
+ }
+
+ for (;
+ start <= end;
+ start+= uc->inst_length(rom->get(start)))
+ uc->print_disass(start, con);
+ last= start;
+ return(DD_FALSE);
+}
+
+
+/*
+ * Command: disassemble
+ *----------------------------------------------------------------------------
+ */
+
+static int disass_last_stop= 0;
+
+//int
+//cl_disassemble_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_disassemble_cmd)
+{
+ t_addr start, realstart;
+ int offset= -1, dir, lines= 20;
+ class cl_cmd_arg *params[4]= { cmdline->param(0),
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
+
+ start= disass_last_stop;
+ if (params[0] == 0) ;
+ else if (cmdline->syntax_match(uc, ADDRESS)) {
+ start= params[0]->value.address;
+ }
+ else if (cmdline->syntax_match(uc, ADDRESS NUMBER)) {
+ start= params[0]->value.address;
+ offset= params[1]->value.number;
+ }
+ else if (cmdline->syntax_match(uc, ADDRESS NUMBER NUMBER)) {
+ start= params[0]->value.address;
+ offset= params[1]->value.number;
+ lines= params[2]->value.number;
+ }
+ else
+ {
+ con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
+ return(DD_FALSE);
+ }
+
+ if (lines < 1)
+ {
+ con->printf("Error: wrong `lines' parameter\n");
+ return(DD_FALSE);
+ }
+ if (!uc->there_is_inst())
+ return(DD_FALSE);
+ realstart= start;
+ class cl_mem *rom= uc->mem(MEM_ROM);
+ if (!rom)
+ return(DD_FALSE);
+ while (realstart < rom->size &&
+ !uc->inst_at(realstart))
+ realstart= realstart+1;
+ if (offset)
+ {
+ dir= (offset < 0)?-1:+1;
+ while (offset)
+ {
+ realstart= (realstart+dir) % rom->size;
+ while (!uc->inst_at(realstart))
+ realstart= (realstart+dir) % rom->size;
+ offset+= -dir;
+ }
+ }
+
+ while (lines)
+ {
+ uc->print_disass(realstart, con);
+ realstart= (realstart+1) % rom->size;
+ while (!uc->inst_at(realstart))
+ realstart= (realstart+1) % rom->size;
+ lines--;
+ }
+
+ disass_last_stop= realstart;
+
+ return(DD_FALSE);;
+}
+
+
+/*
+ * Command: fill
+ *----------------------------------------------------------------------------
+ */
+
+//int
+//cl_fill_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_fill_cmd)
+{
+ class cl_mem *mem= 0;
+ t_mem what= 0;
+ t_addr start= 0, end;
+ class cl_cmd_arg *params[4]= { cmdline->param(0),
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
+
+ if (cmdline->syntax_match(uc, MEMORY ADDRESS ADDRESS NUMBER)) {
+ mem = params[0]->value.memory;
+ start= params[1]->value.address;
+ end = params[2]->value.address;
+ what = params[3]->value.number;
+ t_addr i;
+ for (i= start; i <= end; i++)
+ {
+ t_mem d;
+ d= what;
+ mem->write(i, &d);
+ }
+ }
+ else
+ con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
+
+ return(DD_FALSE);;
+}
+
+
+/*
+ * Command: where
+ *----------------------------------------------------------------------------
+ */
+
+int
+cl_where_cmd::do_real_work(class cl_uc *uc,
+ class cl_cmdline *cmdline, class cl_console *con,
+ bool case_sensitive)
+{
+ class cl_mem *mem= 0;
+ class cl_cmd_arg *params[2]= { cmdline->param(0),
+ cmdline->param(1) };
+
+ if (cmdline->syntax_match(uc, MEMORY DATALIST)) {
+ mem= params[0]->value.memory;
+ t_mem *array= params[1]->value.data_list.array;
+ int len= params[1]->value.data_list.len;
+ if (!len)
+ {
+ con->printf("Error: nothing to search for\n");
+ return(DD_FALSE);
+ }
+ t_addr addr= 0;
+ bool found= mem->search_next(case_sensitive, array, len, &addr);
+ while (found)
+ {
+ mem->dump(addr, addr+len-1, 8, con);
+ addr++;
+ found= mem->search_next(case_sensitive, array, len, &addr);
+ }
+ }
+ else
+ con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
+
+ return(DD_FALSE);
+}
+
+//int
+//cl_where_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_where_cmd)
+{
+ return(do_real_work(uc, cmdline, con, DD_FALSE));
+}
+
+//int
+//cl_Where_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_Where_cmd)
+{
+ return(do_real_work(uc, cmdline, con, DD_TRUE));
+}
+
+
+/* End of cmd.src/cmduc.cc */
--- /dev/null
+/*
+ * Simulator of microcontrollers (cmd.src/cmduccl.h)
+ *
+ * Copyright (C) 2001,01 Drotos Daniel, Talker Bt.
+ *
+ * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
+ *
+ */
+
+/* This file is part of microcontroller simulator: ucsim.
+
+UCSIM is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+UCSIM is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with UCSIM; see the file COPYING. If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA. */
+/*@1@*/
+
+#ifndef CMD_CMDUCCL_HEADER
+#define CMD_CMDUCCL_HEADER
+
+#include "newcmdcl.h"
+
+COMMAND_ON(uc,cl_state_cmd);
+COMMAND_ON(uc,cl_file_cmd);
+COMMAND_ON(uc,cl_dl_cmd);
+COMMAND_ON(uc,cl_pc_cmd);
+COMMAND_ON(uc,cl_reset_cmd);
+COMMAND_ON(uc,cl_dump_cmd);
+COMMAND_ANCESTOR_ON(uc,cl_di_cmd,cl_dump_cmd);
+COMMAND_ANCESTOR_ON(uc,cl_dx_cmd,cl_dump_cmd);
+COMMAND_ANCESTOR_ON(uc,cl_ds_cmd,cl_dump_cmd);
+COMMAND_ANCESTOR_ON(uc,cl_dch_cmd,cl_dump_cmd);
+COMMAND_DATA_ON(uc,cl_dc_cmd,t_addr last);
+COMMAND_DATA_ON(uc,cl_disassemble_cmd,int last);
+COMMAND_DATA_ON(uc,cl_fill_cmd,int last);
+COMMAND_HEAD(cl_where_cmd)
+ public: int last;
+COMMAND_METHODS_ON(uc,cl_where_cmd)
+ virtual int do_real_work(class cl_uc *uc,
+ class cl_cmdline *cmdline, class cl_console *con,
+ bool case_sensitive);
+COMMAND_TAIL;
+COMMAND_DATA_ANCESTOR_ON(uc,cl_Where_cmd,cl_where_cmd,int last);
+
+#endif
+
+/* End of cmd.src/cmduccl.h */
#include "ddconfig.h"
#include <ctype.h>
+#include "i_string.h"
// sim
#include "simcl.h"
*----------------------------------------------------------------------------
*/
-int
-cl_get_sfr_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_get_sfr_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_get_sfr_cmd)
{
- class cl_mem *mem= sim->uc->mem(MEM_SFR);
+ class cl_mem *mem= uc->mem(MEM_SFR);
class cl_cmd_arg *parm;
int i;
parm;
i++, parm= cmdline->param(i))
{
- if (!parm->as_address())
+ if (!parm->as_address(uc))
con->printf("Warning: Invalid address %s\n",
(char*)cmdline->tokens->at(i+1));
else
*----------------------------------------------------------------------------
*/
-int
-cl_get_option_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_get_option_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_get_option_cmd)
{
class cl_cmd_arg *parm= cmdline->param(0);
char *s= 0;
if (!parm)
;
- else if (cmdline->syntax_match(sim, STRING)) {
+ else if (cmdline->syntax_match(uc, STRING)) {
s= parm->value.string.string;
}
else
con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
int i;
- for (i= 0; i < sim->uc->options->count; i++)
+ for (i= 0; i < uc->options->count; i++)
{
- class cl_option *o= (class cl_option *)(sim->uc->options->at(i));
+ class cl_option *o= (class cl_option *)(uc->options->at(i));
if (!s ||
!strcmp(s, o->id))
{
// GET SFR
-class cl_get_sfr_cmd: public cl_cmd
+/*class cl_get_sfr_cmd: public cl_cmd
{
public:
cl_get_sfr_cmd(//class cl_sim *asim,
cl_cmd(aname, can_rep, short_hlp, long_hlp) {}
virtual int do_work(class cl_sim *sim,
class cl_cmdline *cmdline, class cl_console *con);
-};
+};*/
+COMMAND_ON(uc,cl_get_sfr_cmd);
// GET OPTION
-class cl_get_option_cmd: public cl_cmd
+/*class cl_get_option_cmd: public cl_cmd
{
public:
cl_get_option_cmd(//class cl_sim *asim,
cl_cmd(aname, can_rep, short_hlp, long_hlp) {}
virtual int do_work(class cl_sim *sim,
class cl_cmdline *cmdline, class cl_console *con);
-};
-
+};*/
+COMMAND_ON(uc,cl_get_option_cmd);
#endif
* INFO BREAKPOINTS command
*/
-int
-cl_info_bp_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_info_bp_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_info_bp_cmd)
{
int i;
char *s;
con->printf("Num Type Disp Hit Cnt Address What\n");
- for (i= 0; i < sim->uc->fbrk->count; i++)
+ for (i= 0; i < uc->fbrk->count; i++)
{
- class cl_brk *fb= (class cl_brk *)(sim->uc->fbrk->at(i));
- s= sim->uc->disass(fb->addr, NULL);
+ class cl_brk *fb= (class cl_brk *)(uc->fbrk->at(i));
+ s= uc->disass(fb->addr, NULL);
con->printf("%-3d %-10s %s %-5d %-5d 0x%06x %s\n", fb->nr,
"fetch", (fb->perm==brkFIX)?"keep":"del ",
fb->hit, fb->cnt,
fb->addr, s);
free(s);
}
- for (i= 0; i < sim->uc->ebrk->count; i++)
+ for (i= 0; i < uc->ebrk->count; i++)
{
- class cl_ev_brk *eb= (class cl_ev_brk *)(sim->uc->ebrk->at(i));
+ class cl_ev_brk *eb= (class cl_ev_brk *)(uc->ebrk->at(i));
con->printf("%-3d %-10s %s %-5d %-5d 0x%06x %s\n", eb->nr,
"event", (eb->perm==brkFIX)?"keep":"del ",
eb->hit, eb->cnt,
* INFO REGISTERS command
*/
-int
-cl_info_reg_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_info_reg_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_info_reg_cmd)
{
- sim->uc->print_regs(con);
+ uc->print_regs(con);
return(0);
}
* INFO HW command
*/
-int
-cl_info_hw_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_info_hw_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_info_hw_cmd)
{
class cl_hw *hw;
class cl_cmd_arg *params[4]= { cmdline->param(0),
cmdline->param(2),
cmdline->param(3) };
- if (cmdline->syntax_match(sim, HW)) {
+ if (cmdline->syntax_match(uc, HW)) {
hw= params[0]->value.hw;
hw->print_info(con);
}
// INFO BP
-COMMAND(cl_info_bp_cmd);
+COMMAND_ON(uc,cl_info_bp_cmd);
// INFO REG
-COMMAND(cl_info_reg_cmd);
+COMMAND_ON(uc,cl_info_reg_cmd);
// INFO HW
-COMMAND(cl_info_hw_cmd);
+COMMAND_ON(uc,cl_info_hw_cmd);
#endif
*____________________________________________________________________________
*/
-cl_cmdline::cl_cmdline(char *acmd, class cl_console *acon)
+cl_cmdline::cl_cmdline(class cl_app *the_app,
+ char *acmd, class cl_console *acon):
+ cl_base()
{
+ app= the_app;
cmd= strdup(acmd);
params= new cl_list(2, 2);
tokens= new cl_ustrings(2, 2);
int
cl_cmdline::split(void)
{
+ //class cl_sim *sim;
char *start= cmd;
int i;
+ class cl_cmd_arg *arg;
+ //sim= app->get_sim();
name= 0;
if (!cmd ||
!*cmd)
strncpy(param_str, start, 1+end-start);
param_str[1+end-start]= '\0';
tokens->add(strdup(param_str));
- params->add(con->sim->mk_cmd_str_arg(param_str));
+ params->add(arg= new cl_cmd_str_arg(param_str));
+ arg->init();
free(param_str);
if (*end)
end++;
*dot= '\0';
dot++;
if (strchr("0123456789", *param_str) != NULL)
- sfr= con->sim->mk_cmd_int_arg((long long)
- strtol(param_str, 0, 0));
+ {
+ sfr= new cl_cmd_int_arg((long)strtol(param_str, 0, 0));
+ sfr->init();
+ }
else
- sfr= con->sim->mk_cmd_sym_arg(param_str);
+ {
+ sfr= new cl_cmd_sym_arg(param_str);
+ sfr->init();
+ }
if (*dot == '\0')
{
bit= 0;
else
{
if (strchr("0123456789", *dot) != NULL)
- bit= con->sim->mk_cmd_int_arg((long long)
- strtol(dot, 0, 0));
+ {
+ bit= new cl_cmd_int_arg((long)strtol(dot, 0, 0));
+ bit->init();
+ }
else
- bit= con->sim->mk_cmd_sym_arg(dot);
- params->add(con->sim->mk_cmd_bit_arg(sfr, bit));
+ {
+ bit= new cl_cmd_sym_arg(dot);
+ bit->init();
+ }
+ params->add(arg= new cl_cmd_bit_arg(sfr, bit));
+ arg->init();
}
}
else if ((dot= strchr(param_str, '[')) != NULL)
*dot= '\0';
dot++;
if (strchr("0123456789", *param_str) != NULL)
- aname= con->sim->mk_cmd_int_arg((long long)
- strtol(param_str, 0, 0));
+ {
+ aname= new cl_cmd_int_arg((long)strtol(param_str, 0, 0));
+ aname->init();
+ }
else
- aname= con->sim->mk_cmd_sym_arg(param_str);
+ {
+ aname= new cl_cmd_sym_arg(param_str);
+ aname->init();
+ }
if (*dot == '\0')
{
aname= 0;
else
{
if (strchr("0123456789", *dot) != NULL)
- aindex= con->sim->mk_cmd_int_arg((long long)
- strtol(dot, 0, 0));
+ {
+ aindex= new cl_cmd_int_arg((long)strtol(dot, 0, 0));
+ aindex->init();
+ }
else
- aindex= con->sim->mk_cmd_sym_arg(dot);
- params->add(con->sim->mk_cmd_array_arg(aname, aindex));
+ {
+ aindex= new cl_cmd_sym_arg(dot);
+ aindex->init();
+ }
+ params->add(arg= new cl_cmd_array_arg(aname, aindex));
+ arg->init();
}
}
}
else if (strchr("0123456789", *param_str) != NULL)
{
// number
- params->add(con->sim->mk_cmd_int_arg((long long)
- strtol(param_str, 0, 0)));
+ params->add(arg= new cl_cmd_int_arg((long)
+ strtol(param_str, 0, 0)));
+ arg->init();
}
else
{
// symbol
- params->add(con->sim->mk_cmd_sym_arg(param_str));
+ params->add(arg= new cl_cmd_sym_arg(param_str));
+ arg->init();
}
free(param_str);
}
}
bool
-cl_cmdline::syntax_match(class cl_sim *sim, char *syntax)
+cl_cmdline::syntax_match(class cl_uc *uc, char *syntax)
{
if (!syntax)
return(DD_FALSE);
switch (*p)
{
case SY_ADDR:
- if (!parm->as_address())
+ if (!parm->as_address(uc))
return(DD_FALSE);
//printf("ADDRESS match %lx\n",parm->value.address);
break;
return(DD_FALSE);
break;
case SY_MEMORY:
- if (!parm->as_memory())
+ if (!parm->as_memory(uc))
return(DD_FALSE);
//printf("MEMORY match %s\n",parm->value.memory->class_name);
break;
case SY_HW:
- if (!parm->as_hw(sim->uc))
+ if (!parm->as_hw(uc))
return(DD_FALSE);
break;
case SY_STRING:
return(DD_FALSE);
break;
case SY_BIT:
- if (!parm->as_bit(sim->uc))
+ if (!parm->as_bit(uc))
return(DD_FALSE);
break;
default:
*____________________________________________________________________________
*/
-cl_cmd::cl_cmd(//class cl_sim *asim,
+cl_cmd::cl_cmd(enum cmd_operate_on op_on,
char *aname,
int can_rep,
char *short_hlp,
char *long_hlp):
cl_base()
{
- //sim= asim;
+ operate_on= op_on;
names= new cl_strings(1, 1);
names->add(aname?strdup(aname):strdup("unknown"));
can_repeat= can_rep;
}
int
-cl_cmd::work(class cl_sim *sim,
+cl_cmd::work(class cl_app *app,
class cl_cmdline *cmdline, class cl_console *con)
{
if (!syntax_ok(cmdline))
return(0);
- return(do_work(sim, cmdline, con));
+ class cl_sim *sim= app->get_sim();
+ class cl_uc *uc= 0;
+ if (sim)
+ uc= sim->uc;
+ switch (operate_on)
+ {
+ case operate_on_app:
+ if (!app)
+ {
+ con->printf("There is no application to work on!\n");
+ return(DD_TRUE);
+ }
+ return(do_work(app, cmdline, con));
+ case operate_on_sim:
+ if (!sim)
+ {
+ con->printf("There is no simulator to work on!\n");
+ return(DD_TRUE);
+ }
+ return(do_work(sim, cmdline, con));
+ case operate_on_uc:
+ if (!sim)
+ {
+ con->printf("There is no microcontroller to work on!\n");
+ return(DD_TRUE);
+ }
+ return(do_work(uc, cmdline, con));
+ default:
+ return(do_work(cmdline, con));
+ }
+}
+
+int
+cl_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
+{
+ con->printf("Command \"%s\" does nothing.\n",
+ (char*)(names->at(0)));
+ return(0);
+}
+
+int
+cl_cmd::do_work(class cl_app *app,
+ class cl_cmdline *cmdline, class cl_console *con)
+{
+ con->printf("Command \"%s\" does nothing on application.\n",
+ (char*)(names->at(0)));
+ return(0);
}
int
cl_cmd::do_work(class cl_sim *sim,
class cl_cmdline *cmdline, class cl_console *con)
{
- con->printf("Command \"%s\" does nothing.\n", (char*)(names->at(0)));
+ con->printf("Command \"%s\" does nothing on simulator.\n",
+ (char*)(names->at(0)));
+ return(0);
+}
+
+int
+cl_cmd::do_work(class cl_uc *uc,
+ class cl_cmdline *cmdline, class cl_console *con)
+{
+ con->printf("Command \"%s\" does nothing on microcontroller.\n",
+ (char*)(names->at(0)));
return(0);
}
*____________________________________________________________________________
*/
-cl_cmdset::cl_cmdset(class cl_sim *asim):
+cl_cmdset::cl_cmdset(void):
cl_list(5, 5)
{
- sim= asim;
+ //sim= 0;
last_command= 0;
}
+/*cl_cmdset::cl_cmdset(class cl_sim *asim):
+ cl_list(5, 5)
+{
+ sim= asim;
+ last_command= 0;
+}*/
+
class cl_cmd *
cl_cmdset::get_cmd(class cl_cmdline *cmdline)
{
*____________________________________________________________________________
*/
-cl_super_cmd::cl_super_cmd(//class cl_sim *asim,
- char *aname,
+cl_super_cmd::cl_super_cmd(char *aname,
int can_rep,
char *short_hlp,
char *long_hlp,
class cl_cmdset *acommands):
- cl_cmd(aname, can_rep, short_hlp, long_hlp)
+ cl_cmd(operate_on_none, aname, can_rep, short_hlp, long_hlp)
{
commands= acommands;
}
}
int
-cl_super_cmd::work(class cl_sim *sim,
+cl_super_cmd::work(class cl_app *app,
class cl_cmdline *cmdline, class cl_console *con)
{
class cl_cmd *cmd= 0;
if (!cmdline->shift())
{
if ((cmd= commands->get_cmd("_no_parameters_")) != 0)
- return(cmd->work(sim, cmdline, con));
+ return(cmd->work(app, cmdline, con));
int i;
con->printf("\"%s\" must be followed by the name of a subcommand\n"
"List of subcommands:\n", (char*)(names->at(0)));
cmdline->name, (char*)(names->at(0)));
return(0);
}
- return(cmd->work(sim, cmdline, con));
+ return(cmd->work(app, cmdline, con));
}
*____________________________________________________________________________
*/
-cl_console::cl_console(char *fin, char *fout, class cl_sim *asim):
+cl_console::cl_console(char *fin, char *fout, class cl_app *the_app):
cl_base()
{
FILE *f;
last_command= NULL;
- sim= asim;
+ app= the_app;
in= 0;
if (fin)
if (f= fopen(fin, "r+"), in= f, !f)
printf("Warning: non-interactive console\n");
}
-cl_console::cl_console(FILE *fin, FILE *fout, class cl_sim *asim):
+cl_console::cl_console(FILE *fin, FILE *fout, class cl_app *the_app):
cl_base()
{
last_command= NULL;
- sim= asim;
+ app= the_app;
in = fin;
out= fout;
prompt= 0;
return sock;
}
-cl_console::cl_console(int portnumber, class cl_sim *asim)
+cl_console::cl_console(int portnumber, class cl_app *the_app)
{
int sock= connect_to_port(portnumber);
last_command= NULL;
- sim= asim;
+ app= the_app;
if (!(in= fdopen(sock, "r+")))
fprintf(stderr, "cannot open port for input\n");
if (!(out= fdopen(sock, "w+")))
{
if (!out)
return;
- fprintf(out, "ucsim %s, Copyright (C) 1997 Daniel Drotos, Talker Bt.\n"
- "ucsim comes with ABSOLUTELY NO WARRANTY; for details type "
+ fprintf(out, "uCsim %s, Copyright (C) 1997 Daniel Drotos, Talker Bt.\n"
+ "uCsim comes with ABSOLUTELY NO WARRANTY; for details type "
"`show w'.\n"
"This is free software, and you are welcome to redistribute it\n"
"under certain conditions; type `show c' for details.\n",
flags|= CONS_PROMPT;
if (!out)
return;
- if (sim->arg_avail('P'))
+ if (app->args->arg_avail('P'))
putc('\0', out);
else
fprintf(out, "%s", (prompt && prompt[0])?prompt:
- ((p= sim->get_sarg(0, "prompt"))?p:"> "));
+ ((p= app->args->get_sarg(0, "prompt"))?p:"> "));
fflush(out);
}
}
int
-cl_console::proc_input(class cl_app *app, class cl_cmdset *cmdset)
+cl_console::proc_input(class cl_cmdset *cmdset)
{
int retval= 0;
return(1);
if (flags & CONS_FROZEN)
{
- sim->stop(resUSER);
+ app->get_sim()->stop(resUSER);
flags&= ~CONS_FROZEN;
retval= 0;
}
{
class cl_cmdline *cmdline;
class cl_cmd *cm;
- cmdline= new cl_cmdline(cmdstr, this);
+ cmdline= new cl_cmdline(app, cmdstr, this);
cmdline->init();
- cm= 0;
- if (app)
- cm= app->get_cmd(cmdline);
- if (cm == 0 &&
- cmdset)
- cm= cmdset->get_cmd(cmdline);
+ cm= cmdset->get_cmd(cmdline);
if (cm)
- retval= cm->work(sim, cmdline, this);
+ retval= cm->work(app, cmdline, this);
delete cmdline;
if (!cm)
retval= interpret(cmdstr);
int
cl_console::interpret(char *cmd)
{
- fprintf(out, "New interpreter does not known this command\n");
+ fprintf(out, "Unknown command\n");
return(0);
}
*/
#ifdef SOCKET_AVAIL
-cl_listen_console::cl_listen_console(int serverport, class cl_sim *asim)
+cl_listen_console::cl_listen_console(int serverport, class cl_app *the_app)
{
last_command= NULL;
- sim= asim;
+ app= the_app;
if ((sock= make_server_socket(serverport)) >= 0)
{
if (listen(sock, 10) < 0)
int newsock;
ACCEPT_SOCKLEN_T size;
struct sockaddr_in sock_addr;
+ class cl_commander *cmd;
+ cmd= app->get_commander();
size= sizeof(struct sockaddr);
newsock= accept(sock, (struct sockaddr*)&sock_addr, &size);
if (newsock < 0)
fprintf(stderr, "cannot open port for input\n");
if (!(out= fdopen(newsock, "w+")))
fprintf(stderr, "cannot open port for output\n");
- class cl_console *c= sim->cmd->mk_console(in, out, sim);
+ class cl_console *c= cmd->mk_console(in, out);
c->flags|= CONS_INTERACTIVE;
- c->init();
- sim->cmd->add_console(c);
+ cmd->add_console(c);
in= out= 0;
return(0);
}
*____________________________________________________________________________
*/
-cl_commander::cl_commander(class cl_app *the_app,
- class cl_cmdset *acmdset, class cl_sim *asim):
+cl_commander::cl_commander(class cl_app *the_app, class cl_cmdset *acmdset
+ /*, class cl_sim *asim*/):
cl_base()
{
app= the_app;
cons= new cl_list(1, 1);
actual_console= frozen_console= 0;
cmdset= acmdset;
- sim= asim;
}
int
cl_commander::init(void)
{
cl_base::init();
- if (!sim)
- return(1);
- if (sim->arg_avail('c'))
- add_console(mk_console(sim->get_sarg('c', 0),
- sim->get_sarg('c', 0), sim));
+
+ char *Config= app->args->get_sarg(0, "Config");
+ if (Config)
+ {
+ class cl_console *con= mk_console(0/*"/dev/tty"*/);
+ add_console(con);
+ }
+
+ if (app->args->arg_avail('c'))
+ add_console(mk_console(app->args->get_sarg('c', 0),
+ app->args->get_sarg('c', 0)));
#ifdef SOCKET_AVAIL
- if (sim->arg_avail('Z'))
- add_console(mk_console(sim->get_iarg(0, "Zport"), sim));
- if (sim->arg_avail('r'))
- add_console(mk_console(sim->get_iarg('r', 0), sim));
+ if (app->args->arg_avail('Z'))
+ add_console(mk_console(app->args->get_iarg(0, "Zport")));
+ if (app->args->arg_avail('r'))
+ add_console(mk_console(app->args->get_iarg('r', 0)));
#endif
if (cons->get_count() == 0)
- add_console(mk_console(stdin, stdout, sim));
+ add_console(mk_console(stdin, stdout));
return(0);
}
}
class cl_console *
-cl_commander::mk_console(char *fin, char *fout, class cl_sim *asim)
+cl_commander::mk_console(char *fin, char *fout)
{
- return(new cl_console(fin, fout, asim));
+ return(new cl_console(fin, fout, app));
}
class cl_console *
-cl_commander::mk_console(FILE *fin, FILE *fout, class cl_sim *asim)
+cl_commander::mk_console(FILE *fin, FILE *fout)
{
- return(new cl_console(fin, fout, asim));
+ return(new cl_console(fin, fout, app));
}
#ifdef SOCKET_AVAIL
class cl_console *
-cl_commander::mk_console(int portnumber, class cl_sim *asim)
+cl_commander::mk_console(int portnumber)
{
- return(new cl_listen_console(portnumber, asim));
+ return(new cl_listen_console(portnumber, app));
}
#endif
if (c->match(i))
{
actual_console= c;
- int retval= c->proc_input(app, cmdset);
+ int retval= c->proc_input(cmdset);
if (retval)
{
del_console(c);
# include HEADER_FD
#endif
+// prj
#include "pobjcl.h"
+// sim.src
+#include "appcl.h"
+
#define SY_ADDR 'a'
#define ADDRESS "a"
#define SY_BIT 'b'
#define BIT "b"
+enum cmd_operate_on {
+ operate_on_none,
+ operate_on_app,
+ operate_on_sim,
+ operate_on_uc
+};
+
+
/*
* Command line with parameters
*/
class cl_cmdline: cl_base
{
public:
+ class cl_app *app;
char *cmd;
char *name;
class cl_list *params;
class cl_console *con;
public:
- cl_cmdline(char *acmd, class cl_console *acon);
+ cl_cmdline(class cl_app *the_app, char *acmd, class cl_console *acon);
virtual ~cl_cmdline(void);
virtual int init(void);
virtual int repeat(void);
virtual class cl_cmd_arg *param(int num);
virtual void insert_param(int pos, class cl_cmd_arg *param);
- virtual bool syntax_match(class cl_sim *sim, char *syntax);
+ virtual bool syntax_match(class cl_uc *uc, char *syntax);
virtual bool set_data_list(class cl_cmd_arg *parm, int *iparm);
private:
char *skip_delims(char *start);
class cl_cmd: public cl_base
{
public:
- //class cl_sim *sim;
+ enum cmd_operate_on operate_on;
class cl_strings *names;
int can_repeat;
char *short_help;
char *long_help;
public:
- cl_cmd(//class cl_sim *asim,
+ cl_cmd(enum cmd_operate_on opon,
char *aname,
int can_rep,
char *short_hlp,
virtual int name_match(char *aname, int strict);
virtual int name_match(class cl_cmdline *cmdline, int strict);
virtual int syntax_ok(class cl_cmdline *cmdline);
- virtual int work(class cl_sim *sim,
+ virtual int work(class cl_app *app,
class cl_cmdline *cmdline, class cl_console *con);
+ virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
+ virtual int do_work(class cl_app *app,
+ class cl_cmdline *cmdline, class cl_console *con);
virtual int do_work(class cl_sim *sim,
class cl_cmdline *cmdline, class cl_console *con);
+ virtual int do_work(class cl_uc *uc,
+ class cl_cmdline *cmdline, class cl_console *con);
};
#define COMMAND_HEAD(CLASS_NAME) \
public:\
CLASS_NAME (char *aname,\
int can_rep,\
- char *chort_help,\
+ char *short_help,\
+ char *long_help):\
+ cl_cmd(operate_on_none, aname, can_rep, short_help, long_help) {}\
+ virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
+
+#define COMMAND_METHODS_ON(ON,CLASS_NAME) \
+public:\
+ CLASS_NAME (char *aname,\
+ int can_rep,\
+ char *short_help,\
char *long_help):\
- cl_cmd(aname, can_rep, short_help, long_help) {}\
- virtual int do_work(class cl_sim *sim,\
+ cl_cmd(operate_on_ ## ON, aname, can_rep, short_help, long_help) {}\
+ virtual int do_work(class cl_ ## ON * ON ,\
class cl_cmdline *cmdline, class cl_console *con);
+
#define COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR) \
public:\
CLASS_NAME (char *aname,\
int can_rep,\
- char *chort_help,\
+ char *short_help,\
char *long_help):\
ANCESTOR (aname, can_rep, short_help, long_help) {}\
- virtual int do_work(class cl_sim *sim,\
- class cl_cmdline *cmdline, class cl_console *con);
+ virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
+
+#define COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
+public:\
+ CLASS_NAME (char *aname,\
+ int can_rep,\
+ char *short_help,\
+ char *long_help):\
+ ANCESTOR (aname, can_rep, short_help, long_help) {}\
+ virtual int do_work(class cl_ ## ON * ON ,\
+ class cl_cmdline *cmdline, class cl_console *con); \
-#define COMMAND_TAIL \
-}
+
+#define COMMAND_TAIL }
#define COMMAND(CLASS_NAME) \
COMMAND_HEAD(CLASS_NAME) \
COMMAND_METHODS(CLASS_NAME) \
COMMAND_TAIL
+#define COMMAND_ON(ON,CLASS_NAME) \
+COMMAND_HEAD(CLASS_NAME) \
+COMMAND_METHODS_ON(ON,CLASS_NAME) \
+COMMAND_TAIL
+
#define COMMAND_DATA(CLASS_NAME,DATA) \
COMMAND_HEAD(CLASS_NAME) \
public: DATA ; \
COMMAND_METHODS(CLASS_NAME)\
COMMAND_TAIL
-#define COMMAND_ANCESTOR(CLASS_NAME,ANCESTOR) \
+#define COMMAND_DATA_ON(ON,CLASS_NAME,DATA) \
+COMMAND_HEAD(CLASS_NAME) \
+public: DATA ; \
+COMMAND_METHODS_ON(ON,CLASS_NAME)\
+COMMAND_TAIL
+
+#define COMMAND_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
-COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR) \
+COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
COMMAND_TAIL
#define COMMAND_DATA_ANCESTOR(CLASS_NAME,ANCESTOR,DATA) \
COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR)\
COMMAND_TAIL
+#define COMMAND_DATA_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR,DATA) \
+COMMAND_HEAD_ANCESTOR(CLASS_NAME,ANCESTOR) \
+public: DATA ; \
+COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR)\
+COMMAND_TAIL
+
+#define COMMAND_DO_WORK(CLASS_NAME) \
+int \
+CLASS_NAME::do_work(class cl_cmdline *cmdline, class cl_console *con)
+#define COMMAND_DO_WORK_APP(CLASS_NAME) \
+int \
+CLASS_NAME::do_work(class cl_app *app,\
+ class cl_cmdline *cmdline, class cl_console *con)
+#define COMMAND_DO_WORK_SIM(CLASS_NAME) \
+int \
+CLASS_NAME::do_work(class cl_sim *sim,\
+ class cl_cmdline *cmdline, class cl_console *con)
+#define COMMAND_DO_WORK_UC(CLASS_NAME) \
+int \
+CLASS_NAME::do_work(class cl_uc *uc,\
+ class cl_cmdline *cmdline, class cl_console *con)
// Command set is list of cl_cmd objects
class cl_cmdset: public cl_list
{
public:
- class cl_sim *sim;
+ //class cl_sim *sim;
class cl_cmd *last_command;
public:
- cl_cmdset(class cl_sim *asim);
+ cl_cmdset(void);
+ //cl_cmdset(class cl_sim *asim);
virtual class cl_cmd *get_cmd(class cl_cmdline *cmdline);
virtual class cl_cmd *get_cmd(char *cmd_name);
class cl_cmdset *commands;
public:
- cl_super_cmd(//class cl_sim *asim,
- char *aname,
+ cl_super_cmd(char *aname,
int can_rep,
char *short_hlp,
char *long_hlp,
class cl_cmdset *acommands);
~cl_super_cmd(void);
- virtual int work(class cl_sim *sim,
+ virtual int work(class cl_app *app,
class cl_cmdline *cmdline, class cl_console *con);
};
protected:
FILE *in, *out;
public:
- class cl_sim *sim;
+ class cl_app *app;
char *last_command;
int flags; // See CONS_XXXX
char *prompt;
public:
- cl_console(): cl_base() {}
- cl_console(char *fin, char *fout, class cl_sim *asim);
- cl_console(FILE *fin, FILE *fout, class cl_sim *asim);
+ cl_console(void): cl_base() { app= 0; in= out= 0; flags= 0; }
+ cl_console(char *fin, char *fout, class cl_app *the_app);
+ cl_console(FILE *fin, FILE *fout, class cl_app *the_app);
#ifdef SOCKET_AVAIL
- cl_console(int portnumber, class cl_sim *asim);
+ cl_console(int portnumber, class cl_app *the_app);
#endif
~cl_console(void);
virtual int init(void);
virtual int get_in_fd(void);
virtual int input_avail(void);
virtual char *read_line(void);
- virtual int proc_input(class cl_app *app, class cl_cmdset *cmdset);
+ virtual int proc_input(class cl_cmdset *cmdset);
virtual bool interpret(char *cmd);
};
public:
int sock;
public:
- cl_listen_console(int serverport, class cl_sim *asim);
+ cl_listen_console(int serverport, class cl_app *the_app);
virtual void welcome(void) {}
virtual void prompt(void) {}
class cl_list *cons;
fd_set read_set, active_set;
int fd_num;
- class cl_sim *sim;
+ //class cl_sim *sim;
class cl_console *actual_console, *frozen_console;
class cl_cmdset *cmdset;
public:
cl_commander(class cl_app *the_app,
- class cl_cmdset *acmdset, class cl_sim *asim);
+ class cl_cmdset *acmdset/*, class cl_sim *asim*/);
~cl_commander(void);
virtual int init(void);
- virtual class cl_console *mk_console(char *fin, char *fout,
- class cl_sim *asim);
- virtual class cl_console *mk_console(FILE *fin, FILE *fout,
- class cl_sim *asim);
+ virtual class cl_console *mk_console(char *fin, char *fout);
+ virtual class cl_console *mk_console(FILE *fin, FILE *fout);
#ifdef SOCKET_AVAIL
- virtual class cl_console *mk_console(int portnumber, class cl_sim *asim);
+ virtual class cl_console *mk_console(int portnumber);
#endif
void add_console(class cl_console *console);
void del_console(class cl_console *console);
*----------------------------------------------------------------------------
*/
-int
-cl_set_mem_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_set_mem_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_set_mem_cmd)
{
class cl_mem *mem= 0;
class cl_cmd_arg *params[4]= { cmdline->param(0),
cmdline->param(2),
cmdline->param(3) };
- if (cmdline->syntax_match(sim, MEMORY ADDRESS DATALIST)) {
+ if (cmdline->syntax_match(uc, MEMORY ADDRESS DATALIST)) {
mem= params[0]->value.memory;
t_addr start= params[1]->value.address;
t_mem *array= params[2]->value.data_list.array;
*----------------------------------------------------------------------------
*/
-int
-cl_set_bit_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_set_bit_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_set_bit_cmd)
{
class cl_mem *mem;
t_addr mem_addr= 0;
cmdline->param(2),
cmdline->param(3) };
- if (cmdline->syntax_match(sim, BIT NUMBER)) {
+ if (cmdline->syntax_match(uc, BIT NUMBER)) {
mem= params[0]->value.bit.mem;
mem_addr= params[0]->value.bit.mem_address;
bit_mask= params[0]->value.bit.mask;
*----------------------------------------------------------------------------
*/
-int
-cl_set_port_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_set_port_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_set_port_cmd)
{
class cl_hw *hw;
long l= 0, pn= -1;
cmdline->param(2),
cmdline->param(3) };
- if (cmdline->syntax_match(sim, HW NUMBER)) {
+ if (cmdline->syntax_match(uc, HW NUMBER)) {
hw= params[0]->value.hw;
pn= hw->id;
l= params[1]->value.number;
}
- else if (cmdline->syntax_match(sim, NUMBER NUMBER)) {
+ else if (cmdline->syntax_match(uc, NUMBER NUMBER)) {
pn= params[0]->value.number;
l= params[1]->value.number;
}
pn > 3)
con->printf("Error: wrong port\n");
else
- sim->uc->port_pins[pn]= l;
+ uc->port_pins[pn]= l;
return(DD_FALSE);;
}
*----------------------------------------------------------------------------
*/
-int
-cl_set_option_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_set_option_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_set_option_cmd)
{
char *id= 0, *s= 0;
class cl_cmd_arg *params[4]= { cmdline->param(0),
cmdline->param(2),
cmdline->param(3) };
- if (cmdline->syntax_match(sim, STRING STRING)) {
+ if (cmdline->syntax_match(uc, STRING STRING)) {
id= params[0]->value.string.string;
s= params[1]->value.string.string;
}
}
int i;
- for (i= 0; i < sim->uc->options->count; i++)
+ for (i= 0; i < uc->options->count; i++)
{
- class cl_option *o= (class cl_option *)(sim->uc->options->at(i));
+ class cl_option *o= (class cl_option *)(uc->options->at(i));
if (!strcmp(id, o->id))
{
o->set_value(s);
// SET MEMORY
-COMMAND(cl_set_mem_cmd);
+COMMAND_ON(uc,cl_set_mem_cmd);
// SET BIT
-COMMAND(cl_set_bit_cmd);
+COMMAND_ON(uc,cl_set_bit_cmd);
// SET PORT
-COMMAND(cl_set_port_cmd);
+COMMAND_ON(uc,cl_set_port_cmd);
// SET OPTION
-COMMAND(cl_set_option_cmd);
+COMMAND_ON(uc,cl_set_option_cmd);
#endif
*----------------------------------------------------------------------------
*/
-int
-cl_show_copying_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_show_copying_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK(cl_show_copying_cmd)
{
con->printf("%s\n", copying);
return(DD_FALSE);;
*----------------------------------------------------------------------------
*/
-int
-cl_show_warranty_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_show_warranty_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK(cl_show_warranty_cmd)
{
con->printf("%s\n", warranty);
return(DD_FALSE);;
#include "simcl.h"
// local
-#include "cmdsetcl.h"
-#include "newcmdcl.h"
+#include "timercl.h"
/*
*----------------------------------------------------------------------------
*/
-int
-cl_timer_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_timer_cmd::do_work(class cl_sim *sim,
+// class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_timer_cmd)
{
char *s;
con->printf("Timer number is missing\n");
return(0);
}
- set_ticker(sim, cmdline->param(1));
+ set_ticker(uc, cmdline->param(1));
if (strstr(s, "c") == s ||
strstr(s, "m") == s ||
strstr(s, "a") == s)
- return(add(sim, cmdline, con));
+ return(add(uc, cmdline, con));
else if (strstr(s, "d") == s)
- return(del(sim, cmdline, con));
+ return(del(uc, cmdline, con));
else if (strstr(s, "g") == s)
- return(get(sim, cmdline, con));
+ return(get(uc, cmdline, con));
else if (strstr(s, "r") == s)
- return(run(sim, cmdline, con));
+ return(run(uc, cmdline, con));
else if (strstr(s, "s") == s)
- return(stop(sim, cmdline, con));
+ return(stop(uc, cmdline, con));
else if (strstr(s, "v") == s)
- return(val(sim, cmdline, con));
+ return(val(uc, cmdline, con));
else
con->printf("Undefined timer command: \"%s\". Try \"help timer\"\n",
s);
}
void
-cl_timer_cmd::set_ticker(class cl_sim *sim,
+cl_timer_cmd::set_ticker(class cl_uc *uc,
class cl_cmd_arg *param)
{
if ((name= param->get_svalue()))
- ticker= sim->uc->get_counter(name);
+ ticker= uc->get_counter(name);
else
if (param->get_ivalue(&what))
- ticker= sim->uc->get_counter(what);
+ ticker= uc->get_counter(what);
}
/*
*/
int
-cl_timer_cmd::add(class cl_sim *sim,
+cl_timer_cmd::add(class cl_uc *uc,
class cl_cmdline *cmdline, class cl_console *con)
{
class cl_cmd_arg *params[4]= { cmdline->param(0),
if (name)
{
ticker= new cl_ticker(dir, in_isr, name);
- sim->uc->add_counter(ticker, name);
+ uc->add_counter(ticker, name);
}
else
{
ticker= new cl_ticker(dir, in_isr, 0);
- sim->uc->add_counter(ticker, what);
+ uc->add_counter(ticker, what);
}
return(DD_FALSE);
*/
int
-cl_timer_cmd::del(class cl_sim *sim,
+cl_timer_cmd::del(class cl_uc *uc,
class cl_cmdline *cmdline, class cl_console *con)
{
if (!ticker)
return(0);
}
if (name)
- sim->uc->del_counter(name);
+ uc->del_counter(name);
else
- sim->uc->del_counter(what);
+ uc->del_counter(what);
return(0);
}
*/
int
-cl_timer_cmd::get(class cl_sim *sim,
+cl_timer_cmd::get(class cl_uc *uc,
class cl_cmdline *cmdline, class cl_console *con)
{
if (ticker)
- ticker->dump(what, sim->uc->xtal, con);
+ ticker->dump(what, uc->xtal, con);
else
{
- sim->uc->ticks->dump(0, sim->uc->xtal, con);
- sim->uc->isr_ticks->dump(0, sim->uc->xtal, con);
- sim->uc->idle_ticks->dump(0, sim->uc->xtal, con);
- for (what= 0; what < sim->uc->counters->count; what++)
+ uc->ticks->dump(0, uc->xtal, con);
+ uc->isr_ticks->dump(0, uc->xtal, con);
+ uc->idle_ticks->dump(0, uc->xtal, con);
+ for (what= 0; what < uc->counters->count; what++)
{
- ticker= sim->uc->get_counter(what);
+ ticker= uc->get_counter(what);
if (ticker)
- ticker->dump(what, sim->uc->xtal, con);
+ ticker->dump(what, uc->xtal, con);
}
}
*/
int
-cl_timer_cmd::run(class cl_sim *sim,
+cl_timer_cmd::run(class cl_uc *uc,
class cl_cmdline *cmdline, class cl_console *con)
{
if (!ticker)
*/
int
-cl_timer_cmd::stop(class cl_sim *sim,
+cl_timer_cmd::stop(class cl_uc *uc,
class cl_cmdline *cmdline, class cl_console *con)
{
if (!ticker)
*/
int
-cl_timer_cmd::val(class cl_sim *sim,
+cl_timer_cmd::val(class cl_uc *uc,
class cl_cmdline *cmdline, class cl_console *con)
{
class cl_cmd_arg *params[4]= { cmdline->param(0),
--- /dev/null
+/*
+ * Simulator of microcontrollers (cmd.src/timercl.h)
+ *
+ * Copyright (C) 2001,01 Drotos Daniel, Talker Bt.
+ *
+ * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
+ *
+ */
+
+/* This file is part of microcontroller simulator: ucsim.
+
+UCSIM is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+UCSIM is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with UCSIM; see the file COPYING. If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA. */
+/*@1@*/
+
+#ifndef CMD_TIMERCL_HEADER
+#define CMD_TIMERCL_HEADER
+
+#include "newcmdcl.h"
+
+
+COMMAND_HEAD(cl_timer_cmd)
+public:
+ class cl_ticker *ticker;
+ long what;
+ char *name;
+COMMAND_METHODS_ON(uc,cl_timer_cmd)
+ void set_ticker(class cl_uc *uc,
+ class cl_cmd_arg *param);
+ virtual int add(class cl_uc *uc,
+ class cl_cmdline *cmdline, class cl_console *con);
+ virtual int del(class cl_uc *uc,
+ class cl_cmdline *cmdline, class cl_console *con);
+ virtual int get(class cl_uc *uc,
+ class cl_cmdline *cmdline, class cl_console *con);
+ virtual int run(class cl_uc *uc,
+ class cl_cmdline *cmdline, class cl_console *con);
+ virtual int stop(class cl_uc *uc,
+ class cl_cmdline *cmdline, class cl_console *con);
+ virtual int val(class cl_uc *uc,
+ class cl_cmdline *cmdline, class cl_console *con);
+COMMAND_TAIL;
+
+
+#endif
+
+/* End of cmd.src/timercl.h */
CXXFLAGS = @CXXFLAGS@ -I$(PRJDIR) -Wall
M_OR_MM = @M_OR_MM@
-UCSIM_LIBS = -lsim -lcmd -lutil
+LIB_LIST = sim cmd sim util
+UCSIM_LIBS = $(patsubst %,-l%,$(LIB_LIST))
+UCSIM_LIB_FILES = $(patsubst %,lib%.a,$(LIB_LIST))
prefix = @prefix@
exec_prefix = @exec_prefix@
ucsim_app: libs ucsim
-ucsim: $(UCSIM_OBJECTS) $()
+ucsim: $(UCSIM_OBJECTS) $(UCSIM_LIB_FILES)
+ echo $(UCSIM_LIB_FILES)
$(CXX) $(CXXFLAGS) -o $@ $< -L$(PRJDIR) $(UCSIM_LIBS)
.cc.o:
class cl_sim *sim;
app= new cl_app();
- app->init();
- sim= new cl_sim51(app, argc, argv);
+ app->init(argc, argv);
+ sim= new cl_sim51(app);
if (sim->init())
return(1);
app->set_simulator(sim);
- retval= sim->main();
+ retval= /*sim->main()*/app->run();
delete app;
return(retval);
#include "globals.h"
#include "utils.h"
#include "cmdutil.h"
-#ifdef SOCKET_AVAIL
-#include <sys/socket.h>
-#endif
#include "sim51cl.h"
//#include "cmd51cl.h"
#include "glob.h"
-cl_sim51::cl_sim51(class cl_app *the_app, int iargc, char *iargv[]):
- cl_sim(the_app, "t:s:S:hHk:", iargc, iargv)
+cl_sim51::cl_sim51(class cl_app *the_app):
+ cl_sim(the_app)
{}
-static void
-print_help(char *name)
-{
- printf("%s: %s\n", name, VERSIONSTR);
- printf("Usage: %s [-hHVvP] [-p prompt] [-t CPU] [-X freq[k|M]]\n"
- " [-c file] [-s file] [-S optionlist]"
-#ifdef SOCKET_AVAIL
- " [-Z portnum] [-k portnum]"
-#endif
- "\n"
- " [files...]\n", name);
- printf
- (
- "Options:\n"
- " -t CPU Type of CPU: 51, C52, 251, etc.\n"
- " -X freq[k|M] XTAL frequency\n"
- " -c file Open command console on `file'\n"
-#ifdef SOCKET_AVAIL
- " -Z portnum Use localhost:portnumber for command console\n"
- " -k portnum Use localhost:portnum for serial I/O\n"
-#endif
- " -s file Connect serial interface to `file'\n"
- " -S options `options' is a comma separated list of options\n"
- " according to serial interface. Know options are:\n"
- " in=file serial input will be read from file named `file'\n"
- " out=file serial output will be written to `file'\n"
- " -p prompt Specify string for prompt\n"
- " -P Prompt is a null ('\\0') character\n"
- " -V Verbose mode\n"
- " -v Print out version number\n"
- " -H Print out types of known CPUs\n"
- " -h Print out this help\n"
- );
-}
-
-enum {
- SOPT_IN= 0,
- SOPT_OUT
-};
-
-static const char *S_opts[]= {
- /*[SOPT_IN]=*/ "in",
- /*[SOPT_OUT]=*/ "out",
- NULL
-};
-
-int
-cl_sim51::proc_arg(char optopt, char *optarg)
-{
- char *cpu_type= NULL, *cp;
- int i;
- char *subopts, *value;
-
- switch (optopt)
- {
-
- case 't':
-
- if (cpu_type)
- free(cpu_type);
- cpu_type= strdup(optarg);
- for (cp= cpu_type; *cp; *cp= toupper(*cp), cp++);
- arguments->add(new cl_prg_arg('t', 0, cpu_type));
- break;
-
- case 's':
- {
- FILE *Ser_in, *Ser_out;
- if (arg_avail('s'))
- {
- fprintf(stderr, "-s option can not be used more than once.\n");
- break;
- }
- arguments->add(new cl_prg_arg('s', 0, (long)1));
- if ((Ser_in= fopen(optarg, "r")) == NULL)
- {
- fprintf(stderr,
- "Can't open `%s': %s\n", optarg, strerror(errno));
- return(4);
- }
- arguments->add(new cl_prg_arg(0, "Ser_in", Ser_in));
- if ((Ser_out= fopen(optarg, "w")) == NULL)
- {
- fprintf(stderr,
- "Can't open `%s': %s\n", optarg, strerror(errno));
- return(4);
- }
- arguments->add(new cl_prg_arg(0, "Ser_out", Ser_out));
- break;
- }
-
-#ifdef SOCKET_AVAIL
- // socket serial I/O by Alexandre Frey <Alexandre.Frey@trusted-logic.fr>
- case 'k':
- {
- FILE *Ser_in, *Ser_out;
- int sock;
- unsigned short serverport;
- int client_sock;
-
- if (arg_avail("Ser_in")) {
- fprintf(stderr, "Serial input specified more than once.\n");
- }
- if (arg_avail("Ser_out")) {
- fprintf(stderr, "Serial output specified more than once.\n");
- }
-
- serverport = atoi(optarg);
- sock = make_server_socket(serverport);
- if (listen(sock, 1) < 0) {
- fprintf(stderr, "Listen on port %d: %s\n", serverport,
- strerror(errno));
- return (4);
- }
- fprintf(stderr, "Listening on port %d for a serial connection.\n",
- serverport);
- if ((client_sock = accept(sock, NULL, NULL)) < 0) {
- fprintf(stderr, "accept: %s\n", strerror(errno));
- }
- fprintf(stderr, "Serial connection established.\n");
-
- if ((Ser_in = fdopen(client_sock, "r")) == NULL) {
- fprintf(stderr, "Can't create input stream: %s\n", strerror(errno));
- return (4);
- }
- arguments->add(new cl_prg_arg(0, "Ser_in", Ser_in));
- if ((Ser_out = fdopen(client_sock, "w")) == NULL) {
- fprintf(stderr, "Can't create output stream: %s\n", strerror(errno));
- return (4);
- }
- arguments->add(new cl_prg_arg(0, "Ser_out", Ser_out));
- break;
- }
-#endif
-
- case 'S':
-
- subopts= optarg;
- while (*subopts != '\0')
- switch (get_sub_opt(&subopts, S_opts, &value))
- {
- FILE *Ser_in, *Ser_out;
- case SOPT_IN:
- if (value == NULL) {
- fprintf(stderr, "No value for -S in\n");
- exit(1);
- }
- if (arg_avail("Ser_in"))
- {
- fprintf(stderr, "Serial input specified more than once.\n");
- break;
- }
- if ((Ser_in= fopen(value, "r")) == NULL)
- {
- fprintf(stderr,
- "Can't open `%s': %s\n", value, strerror(errno));
- exit(4);
- }
- arguments->add(new cl_prg_arg(0, "Ser_in", Ser_in));
- break;
- case SOPT_OUT:
- if (value == NULL) {
- fprintf(stderr, "No value for -S out\n");
- exit(1);
- }
- if (arg_avail("Ser_out"))
- {
- fprintf(stderr, "Serial output specified more than once.\n");
- break;
- }
- if ((Ser_out= fopen(value, "w")) == NULL)
- {
- fprintf(stderr,
- "Can't open `%s': %s\n", value, strerror(errno));
- exit(4);
- }
- arguments->add(new cl_prg_arg(0, "Ser_out", Ser_out));
- break;
- default:
- /* Unknown suboption. */
- fprintf(stderr, "Unknown suboption `%s' for -S\n", value);
- exit(1);
- break;
- }
- break;
-
- case 'h':
-
- print_help("s51");
- exit(0);
- break;
-
- case 'H':
- i= 0;
- while (cpus_51[i].type_str != NULL)
- {
- printf("%s\n", cpus_51[i].type_str);
- i++;
- }
- exit(0);
- break;
-
- case '?':
-
- if (isprint(optopt))
- fprintf(stderr, "Unknown option `-%c'.\n", optopt);
- else
- fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
- return(1);
- break;
-
- default:
- // should never happen...
- abort();
- }
- return(0);
-}
-
class cl_uc *
cl_sim51::mk_controller(void)
int i;
i= 0;
- if (get_sarg('t', 0) == NULL)
- arguments->add(new cl_prg_arg('t', 0, "C51"));
+ if (app->args->get_sarg('t', 0) == NULL)
+ app->args->add(new cl_prg_arg('t', 0, "C51"));
while ((cpus_51[i].type_str != NULL) &&
- (strcmp(get_sarg('t', 0), cpus_51[i].type_str) != 0))
+ (strcmp(app->args->get_sarg('t', 0), cpus_51[i].type_str) != 0))
i++;
if (cpus_51[i].type_str == NULL)
{
class cl_sim51: public cl_sim
{
public:
- cl_sim51(class cl_app *the_app, int iargc, char *iargv[]);
- virtual int proc_arg(char optopt, char *optarg);
+ cl_sim51(class cl_app *the_app);
+ //virtual int proc_arg(char optopt, char *optarg);
virtual class cl_uc *mk_controller(void);
};
type= Itype;
technology= Itech;
- debug= asim->get_iarg('V', 0);
+ debug= asim->app->args->get_iarg('V', 0);
stop_at_it= DD_FALSE;
options->add(new cl_bool_opt(&debug, "verbose", "Verbose flag."));
options->add(new cl_bool_opt(&stop_at_it, "stopit",
"Stop if interrupt accepted."));
- options->add(new cl_cons_debug_opt(asim, "debug",
+ options->add(new cl_cons_debug_opt(asim->app, "debug",
"Debug messages appears on this console."));
- serial_in = (FILE*)asim->get_parg(0, "Ser_in");
- serial_out= (FILE*)asim->get_parg(0, "Ser_out");
+ serial_in = (FILE*)asim->app->args->get_parg(0, "Ser_in");
+ serial_out= (FILE*)asim->app->args->get_parg(0, "Ser_out");
if (serial_in)
{
// making `serial' unbuffered
if ((step < 0) &&
((ticks->ticks % 100000) < 50))
{
- if (sim->cmd->input_avail_on_frozen())
+ if (sim->app->get_commander()->input_avail_on_frozen())
{
result= resUSER;
}
else
- if (sim->cmd->input_avail())
+ if (sim->app->get_commander()->input_avail())
break;
}
if (((result == resINTERRUPT) &&
if (state == stPD)
{
//FIXME: tick outsiders eg. watchdog
- if (sim->cmd->input_avail_on_frozen())
+ if (sim->app->get_commander()->input_avail_on_frozen())
{
//fprintf(stderr,"uc: inp avail in PD mode, user stop\n");
result= resUSER;
!(p3 & port_pins[3] & bm_INT0))
// falling edge on INT0
{
- sim->cmd->debug("%g sec (%d clks): "
- "Falling edge detected on INT0 (P3.2)\n",
+ sim->app->get_commander()->
+ debug("%g sec (%d clks): Falling edge detected on INT0 (P3.2)\n",
get_rtime(), ticks->ticks);
sfr->set_bit1(TCON, bmIE0);
}
}
if (is->clr_bit)
sfr->set_bit0(is->src_reg, is->src_mask);
- sim->cmd->debug("%g sec (%d clks): "
- "Accepting interrupt `%s' PC= 0x%06x\n",
+ sim->app->get_commander()->
+ debug("%g sec (%d clks): Accepting interrupt `%s' PC= 0x%06x\n",
get_rtime(), ticks->ticks, is->name, PC);
IL= new it_level(pr, is->addr, PC, is);
return(accept_it(IL));
if (pcon & bmIDL)
{
if (state != stIDLE)
- sim->cmd->debug("%g sec (%d clks): CPU in Idle mode\n",
- get_rtime(), ticks->ticks);
+ sim->app->get_commander()->
+ debug("%g sec (%d clks): CPU in Idle mode\n",
+ get_rtime(), ticks->ticks);
state= stIDLE;
//was_reti= 1;
}
if (pcon & bmPD)
{
if (state != stPD)
- sim->cmd->debug("%g sec (%d clks): CPU in PowerDown mode\n",
+ sim->app->get_commander()->
+ debug("%g sec (%d clks): CPU in PowerDown mode\n",
get_rtime(), ticks->ticks);
state= stPD;
}
{
PC--;
if (1)//debug)// && sim->cmd_out())
- sim->cmd->debug("Unknown instruction %02x at %06x\n", code, PC);
+ sim->app->get_commander()->
+ debug("Unknown instruction %02x at %06x\n", code, PC);
return(resHALT);
}
(*addr == 0xe1))
{
WDT= 0;
- sim->cmd->debug("%g sec (%d tick): Watchdog timer enabled/reset"
- " PC= 0x%06x\n",
- get_rtime(), ticks->ticks, PC);
+ sim->app->get_commander()->
+ debug("%g sec (%d tick): Watchdog timer enabled/reset PC= 0x%06x"
+ "\n", get_rtime(), ticks->ticks, PC);
}
wdtrst= *addr;
}
if (WDT >= 0)
{
WDT+= cycles;
-fprintf(stderr,"WDT=%d\n",WDT);
if (WDT & ~(0x3fff))
{
- sim->cmd->debug("%g sec (%d ticks): "
- "Watchdog timer resets the CPU, PC= 0x%06x\n",
- get_rtime(), ticks->ticks, PC);
+ sim->app->get_commander()->
+ debug("%g sec (%d ticks): Watchdog timer resets the CPU, "
+ "PC= 0x%06x\n", get_rtime(), ticks->ticks, PC);
reset();
return(resWDTRESET);
}
# Compiling entire program or any subproject
# ------------------------------------------
-all: checkconf sim_lib test_mem_speed
+all: checkconf sim_lib
-test_mem_speed: test_mem_speed.o
- $(CC) -o $@ $< -L$(PRJDIR) -lsim -lutil
+test_mem_speed: $(PRJDIR)/libsim.a $(PRJDIR)/libutil.a test_mem_speed.o
+ $(CC) -o $@ test_mem_speed.o -L$(PRJDIR) -lsim -lutil
sim.src: all
installdirs:
+test: test_mem_speed
+
# Creating dependencies
# ---------------------
dep: main.dep
02111-1307, USA. */
/*@1@*/
+#include "ddconfig.h"
+
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
+#ifdef HAVE_GETOPT_H
+# include <getopt.h>
+#endif
+#ifdef SOCKET_AVAIL
+#include <sys/socket.h>
+#endif
+#include <ctype.h>
+#include <errno.h>
+#include "i_string.h"
// prj
-#include "i_string.h"
+#include "utils.h"
-// sim.src
+// local, sim.src
+#include "appcl.h"
#include "simcl.h"
-// local
-#include "appcl.h"
+// cmd.src
+#include "cmdsetcl.h"
+#include "cmdutil.h"
+#include "cmdconfcl.h"
+#include "showcl.h"
/*
{
//options= new cl_options();
sim= 0;
+ args= new cl_arguments();
+ in_files= new cl_ustrings(2, 2);
+ going= 1;
}
cl_app::~cl_app(void)
{
//delete options;
remove_simulator();
+ delete commander;
+ //delete cmdset;
+ delete args;
+ delete in_files;
}
int
-cl_app::init(void)
+cl_app::init(int argc, char *argv[])
{
cl_base::init();
-
+ proc_arguments(argc, argv);
+ class cl_cmdset *cmdset= new cl_cmdset();
+ cmdset->init();
+ build_cmdset(cmdset);
+ commander= new cl_commander(this, cmdset/*, sim*/);
+ commander->init();
return(0);
}
int
cl_app::run(void)
{
+ int done= 0;
+
+ while (!done &&
+ going)
+ {
+ if (sim)
+ {
+ if (sim->state & SIM_GO)
+ {
+ if (commander->input_avail())
+ done= commander->proc_input();
+ else
+ sim->step();
+ }
+ else
+ {
+ commander->wait_input();
+ done= commander->proc_input();
+ }
+ }
+ else
+ {
+ commander->wait_input();
+ done= commander->proc_input();
+ }
+ }
return(0);
}
}
+/*
+ * Interpretation of parameters
+ */
+
+static void
+print_help(char *name)
+{
+ printf("%s: %s\n", name, VERSIONSTR);
+ printf("Usage: %s [-hHVvP] [-p prompt] [-t CPU] [-X freq[k|M]]\n"
+ " [-c file] [-s file] [-S optionlist]"
+#ifdef SOCKET_AVAIL
+ " [-Z portnum] [-k portnum]"
+#endif
+ "\n"
+ " [files...]\n", name);
+ printf
+ (
+ "Options:\n"
+ " -t CPU Type of CPU: 51, C52, 251, etc.\n"
+ " -X freq[k|M] XTAL frequency\n"
+ " -c file Open command console on `file'\n"
+#ifdef SOCKET_AVAIL
+ " -Z portnum Use localhost:portnumber for command console\n"
+ " -k portnum Use localhost:portnum for serial I/O\n"
+#endif
+ " -s file Connect serial interface to `file'\n"
+ " -S options `options' is a comma separated list of options\n"
+ " according to serial interface. Know options are:\n"
+ " in=file serial input will be read from file named `file'\n"
+ " out=file serial output will be written to `file'\n"
+ " -p prompt Specify string for prompt\n"
+ " -P Prompt is a null ('\\0') character\n"
+ " -V Verbose mode\n"
+ " -v Print out version number\n"
+ " -H Print out types of known CPUs\n"
+ " -h Print out this help\n"
+ );
+}
+
+enum {
+ SOPT_IN= 0,
+ SOPT_OUT
+};
+
+static const char *S_opts[]= {
+ /*[SOPT_IN]=*/ "in",
+ /*[SOPT_OUT]=*/ "out",
+ NULL
+};
+
+int
+cl_app::proc_arguments(int argc, char *argv[])
+{
+ int i, c;
+ char opts[100], *cp, *subopts, *value;
+ char *cpu_type= NULL;
+
+ strcpy(opts, "c:C:p:PX:vVt:s:S:hHk:");
+#ifdef SOCKET_AVAIL
+ strcat(opts, "Z:r:");
+#endif
+ //int opterr= 0;
+ while((c= getopt(argc, argv, opts)) != -1)
+ switch (c)
+ {
+ case 'c':
+ args->add(new cl_prg_arg('c', 0, optarg));
+ break;
+ case 'C':
+ args->add(new cl_prg_arg(0, "Config", optarg));
+ break;
+#ifdef SOCKET_AVAIL
+ case 'Z':
+ // By Sandeep
+ args->add(new cl_prg_arg('Z', 0, (long)1));
+ if (!optarg || !isdigit(*optarg))
+ fprintf(stderr, "expected portnumber to follow -Z\n");
+ else {
+ char *p;
+ long l= strtol(optarg, &p, 0);
+ args->add(new cl_prg_arg(0, "Zport", l));
+ }
+ break;
+#endif
+ case 'p':
+ args->add(new cl_prg_arg(0, "prompt", optarg));
+ break;
+ case 'P':
+ args->add(new cl_prg_arg('P', 0, (long)1));
+ break;
+#ifdef SOCKET_AVAIL
+ case 'r':
+ args->add(new cl_prg_arg('r', 0,
+ (long)strtol(optarg, NULL, 0)));
+ break;
+#endif
+ case 'X':
+ {
+ double XTAL;
+ for (cp= optarg; *cp; *cp= toupper(*cp), cp++);
+ XTAL= strtod(optarg, &cp);
+ if (*cp == 'K')
+ XTAL*= 1e3;
+ if (*cp == 'M')
+ XTAL*= 1e6;
+ if (XTAL == 0)
+ {
+ fprintf(stderr, "Xtal frequency must be greather than 0\n");
+ exit(1);
+ }
+ args->add(new cl_prg_arg('X', 0, XTAL));
+ break;
+ }
+ case 'v':
+ printf("%s: %s\n", argv[0], VERSIONSTR);
+ exit(0);
+ break;
+ case 'V':
+ args->add(new cl_prg_arg('V', 0, (long)1));
+ break;
+ case 't':
+ if (cpu_type)
+ free(cpu_type);
+ cpu_type= strdup(optarg);
+ for (cp= cpu_type; *cp; *cp= toupper(*cp), cp++);
+ args->add(new cl_prg_arg('t', 0, cpu_type));
+ break;
+ case 's':
+ {
+ FILE *Ser_in, *Ser_out;
+ if (args->arg_avail('s'))
+ {
+ fprintf(stderr, "-s option can not be used more than once.\n");
+ break;
+ }
+ args->add(new cl_prg_arg('s', 0, (long)1));
+ if ((Ser_in= fopen(optarg, "r")) == NULL)
+ {
+ fprintf(stderr,
+ "Can't open `%s': %s\n", optarg, strerror(errno));
+ return(4);
+ }
+ args->add(new cl_prg_arg(0, "Ser_in", Ser_in));
+ if ((Ser_out= fopen(optarg, "w")) == NULL)
+ {
+ fprintf(stderr,
+ "Can't open `%s': %s\n", optarg, strerror(errno));
+ return(4);
+ }
+ args->add(new cl_prg_arg(0, "Ser_out", Ser_out));
+ break;
+ }
+#ifdef SOCKET_AVAIL
+ // socket serial I/O by Alexandre Frey <Alexandre.Frey@trusted-logic.fr>
+ case 'k':
+ {
+ FILE *Ser_in, *Ser_out;
+ int sock;
+ unsigned short serverport;
+ int client_sock;
+
+ if (args->arg_avail("Ser_in")) {
+ fprintf(stderr, "Serial input specified more than once.\n");
+ }
+ if (args->arg_avail("Ser_out")) {
+ fprintf(stderr, "Serial output specified more than once.\n");
+ }
+
+ serverport = atoi(optarg);
+ sock= make_server_socket(serverport);
+ if (listen(sock, 1) < 0) {
+ fprintf(stderr, "Listen on port %d: %s\n", serverport,
+ strerror(errno));
+ return (4);
+ }
+ fprintf(stderr, "Listening on port %d for a serial connection.\n",
+ serverport);
+ if ((client_sock= accept(sock, NULL, NULL)) < 0) {
+ fprintf(stderr, "accept: %s\n", strerror(errno));
+ }
+ fprintf(stderr, "Serial connection established.\n");
+
+ if ((Ser_in= fdopen(client_sock, "r")) == NULL) {
+ fprintf(stderr, "Can't create input stream: %s\n", strerror(errno));
+ return (4);
+ }
+ args->add(new cl_prg_arg(0, "Ser_in", Ser_in));
+ if ((Ser_out= fdopen(client_sock, "w")) == NULL) {
+ fprintf(stderr, "Can't create output stream: %s\n", strerror(errno));
+ return (4);
+ }
+ args->add(new cl_prg_arg(0, "Ser_out", Ser_out));
+ break;
+ }
+#endif
+ case 'S':
+ subopts= optarg;
+ while (*subopts != '\0')
+ switch (get_sub_opt(&subopts, S_opts, &value))
+ {
+ FILE *Ser_in, *Ser_out;
+ case SOPT_IN:
+ if (value == NULL) {
+ fprintf(stderr, "No value for -S in\n");
+ exit(1);
+ }
+ if (args->arg_avail("Ser_in"))
+ {
+ fprintf(stderr, "Serial input specified more than once.\n");
+ break;
+ }
+ if ((Ser_in= fopen(value, "r")) == NULL)
+ {
+ fprintf(stderr,
+ "Can't open `%s': %s\n", value, strerror(errno));
+ exit(4);
+ }
+ args->add(new cl_prg_arg(0, "Ser_in", Ser_in));
+ break;
+ case SOPT_OUT:
+ if (value == NULL) {
+ fprintf(stderr, "No value for -S out\n");
+ exit(1);
+ }
+ if (args->arg_avail("Ser_out"))
+ {
+ fprintf(stderr, "Serial output specified more than once.\n");
+ break;
+ }
+ if ((Ser_out= fopen(value, "w")) == NULL)
+ {
+ fprintf(stderr,
+ "Can't open `%s': %s\n", value, strerror(errno));
+ exit(4);
+ }
+ args->add(new cl_prg_arg(0, "Ser_out", Ser_out));
+ break;
+ default:
+ /* Unknown suboption. */
+ fprintf(stderr, "Unknown suboption `%s' for -S\n", value);
+ exit(1);
+ break;
+ }
+ break;
+ case 'h':
+ print_help("s51");
+ exit(0);
+ break;
+ case 'H':
+ /*i= 0;
+ while (cpus_51[i].type_str != NULL)
+ {
+ printf("%s\n", cpus_51[i].type_str);
+ i++;
+ }*/
+ exit(0);
+ break;
+ case '?':
+ if (isprint(optopt))
+ fprintf(stderr, "Unknown option `-%c'.\n", optopt);
+ else
+ fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
+ return(1);
+ break;
+ default:
+ exit(c);
+ }
+ if (!args->arg_avail("prompt"))
+ args->add(new cl_prg_arg(0, "prompt", "> "));
+
+ for (i= optind; i < argc; i++)
+ in_files->add(argv[i]);
+
+ return(0);
+}
+
+
/* Command handling */
class cl_cmd *
}
void
-cl_app::build_cmdset(class cl_cmdset *cs)
+cl_app::build_cmdset(class cl_cmdset *cmdset)
{
-
+ class cl_cmd *cmd;
+ class cl_cmdset *cset;
+
+ {
+ cset= new cl_cmdset();
+ cset->init();
+ cset->add(cmd= new cl_conf_cmd("_no_parameters_", 0,
+"conf Configuration",
+"long help of conf"));
+ cmd->init();
+ cset->add(cmd= new cl_conf_addmem_cmd("addmem", 0,
+"conf addmem\n"
+" Make memory",
+"long help of conf addmem"));
+ cmd->init();
+ }
+ cmdset->add(cmd= new cl_super_cmd("conf", 0,
+"conf subcommand Information, see `conf' command for more help",
+"long help of conf", cset));
+ cmd->init();
+
+ cmd= new cl_help_cmd("help", 0,
+"help [command] Help about command(s)",
+"long help of help");
+ cmdset->add(cmd);
+ cmd->init();
+ cmd->add_name("?");
+
+ cmdset->add(cmd= new cl_quit_cmd("quit", 0,
+"quit Quit",
+"long help of quit"));
+ cmd->init();
+
+ cmdset->add(cmd= new cl_kill_cmd("kill", 0,
+"kill Shutdown simulator",
+"long help of kill"));
+ cmd->init();
+
+ {
+ cset= new cl_cmdset();
+ cset->init();
+ cset->add(cmd= new cl_show_copying_cmd("copying", 0,
+"show copying Conditions for redistributing copies of uCsim",
+"long help of show copying"));
+ cmd->init();
+ cset->add(cmd= new cl_show_warranty_cmd("warranty", 0,
+"show warranty Various kinds of warranty you do not have",
+"long help of show warranty"));
+ cmd->init();
+ }
+ cmdset->add(cmd= new cl_super_cmd("show", 0,
+"show subcommand Generic command for showing things about the uCsim",
+"long help of show", cset));
+ cmd->init();
}
#include "ddconfig.h"
+// prj
#include "pobjcl.h"
+// local, sim.src
+#include "argcl.h"
+
/* Options */
class cl_app: public cl_base
{
protected:
- //class cl_options *options;
+ class cl_commander *commander;
+public:
class cl_sim *sim;
- class cl_cmdset *cmdset;
+ class cl_ustrings *in_files;
+ class cl_arguments *args;
+ int going;
public:
cl_app(void);
~cl_app(void);
public:
- virtual int init(void);
+ virtual int init(int argc , char *argv[]);
virtual int run(void);
virtual void done(void);
+protected:
+ virtual int proc_arguments(int argc, char *argv[]);
+
public:
+ class cl_sim *get_sim(void) { return(sim); }
+ class cl_commander *get_commander(void) { return(commander); }
virtual class cl_cmd *get_cmd(class cl_cmdline *cmdline);
public:
}
bool
-cl_cmd_arg::as_address(void)
+cl_cmd_arg::as_address(class cl_uc *uc)
{
- return(get_address(&(value.address)));
+ return(get_address(uc, &(value.address)));
}
bool
}
bool
-cl_cmd_arg::as_memory(void)
+cl_cmd_arg::as_memory(class cl_uc *uc)
{
value.memory= uc->mem(s_value);
return(value.memory != 0);
/* Interger number */
-cl_cmd_int_arg::cl_cmd_int_arg(class cl_uc *iuc, long addr):
- cl_cmd_arg(iuc, addr)
+cl_cmd_int_arg::cl_cmd_int_arg(/*class cl_uc *iuc,*/ long addr):
+ cl_cmd_arg(/*iuc,*/ addr)
{}
bool
-cl_cmd_int_arg::get_address(t_addr *addr)
+cl_cmd_int_arg::get_address(class cl_uc *uc, t_addr *addr)
{
long iv;
{
t_addr bit_addr;
- if (!get_address(&bit_addr))
+ if (!get_address(uc, &bit_addr))
return(DD_FALSE);
return(uc->extract_bit_address(bit_addr, mem, mem_addr, bit_mask));
}
/* Symbol */
-cl_cmd_sym_arg::cl_cmd_sym_arg(class cl_uc *iuc, char *sym):
- cl_cmd_arg(iuc, sym)
+cl_cmd_sym_arg::cl_cmd_sym_arg(/*class cl_uc *iuc,*/ char *sym):
+ cl_cmd_arg(/*iuc,*/ sym)
{}
bool
}
bool
-cl_cmd_sym_arg::get_address(t_addr *addr)
+cl_cmd_sym_arg::get_address(class cl_uc *uc, t_addr *addr)
{
struct name_entry *ne;
}
bool
-cl_cmd_sym_arg::as_address(void)
+cl_cmd_sym_arg::as_address(class cl_uc *uc)
{
struct name_entry *ne;
//printf("SYM %s as addr?\n",get_svalue());
/* String */
-cl_cmd_str_arg::cl_cmd_str_arg(class cl_uc *iuc, char *str):
- cl_cmd_arg(iuc, str)
+cl_cmd_str_arg::cl_cmd_str_arg(/*class cl_uc *iuc,*/ char *str):
+ cl_cmd_arg(/*iuc,*/ str)
{}
/* Bit */
-cl_cmd_bit_arg::cl_cmd_bit_arg(class cl_uc *iuc,
+cl_cmd_bit_arg::cl_cmd_bit_arg(/*class cl_uc *iuc,*/
class cl_cmd_arg *asfr, class cl_cmd_arg *abit):
- cl_cmd_arg(iuc, (long)0)
+ cl_cmd_arg(/*iuc,*/ (long)0)
{
sfr= asfr;
bit= abit;
}
bool
-cl_cmd_bit_arg::get_address(t_addr *addr)
+cl_cmd_bit_arg::get_address(class cl_uc *uc, t_addr *addr)
{
if (sfr)
- return(sfr->get_address(addr));
+ return(sfr->get_address(uc, addr));
return(0);
}
t_addr *mem_addr,
t_mem *bit_mask)
{
-printf("**1\n");
if (mem)
*mem= uc->mem(MEM_SFR);
-printf("**2\n");
if (mem_addr)
{
-printf("**3\n");
if (!sfr ||
- !sfr->get_address(mem_addr))
+ !sfr->get_address(uc, mem_addr))
return(DD_FALSE);
-printf("**4\n");
}
-printf("**5\n");
if (bit_mask)
{
-printf("**6\n");
if (!bit)
return(DD_FALSE);
-printf("**7\n");
long l;
if (!bit->get_ivalue(&l) ||
l > 7)
return(DD_FALSE);
-printf("**8\n");
*bit_mask= 1 << l;
}
-printf("**9\n");
return(DD_TRUE);
}
/* Array */
-cl_cmd_array_arg::cl_cmd_array_arg(class cl_uc *iuc,
+cl_cmd_array_arg::cl_cmd_array_arg(/*class cl_uc *iuc,*/
class cl_cmd_arg *aname,
class cl_cmd_arg *aindex):
- cl_cmd_arg(iuc, (long)0)
+ cl_cmd_arg(/*iuc,*/ (long)0)
{
name = aname;
index= aindex;
if (name == 0 ||
index == 0 ||
(n= name->get_svalue()) == NULL ||
- !index->get_address(&a))
+ !index->get_address(uc, &a))
return(DD_FALSE);
value.hw= uc->get_hw(n, a, NULL);
}
+/*
+ * List of arguments
+ *----------------------------------------------------------------------------
+ */
+
+int
+cl_arguments::arg_avail(char name)
+{
+ class cl_prg_arg *a;
+ int i;
+
+ for (i= 0; i < count; i++)
+ {
+ a= (class cl_prg_arg *)(at(i));
+ if (a->short_name == name)
+ return(1);
+ }
+ return(0);
+}
+
+int
+cl_arguments::arg_avail(char *name)
+{
+ class cl_prg_arg *a;
+ int i;
+
+ for (i= 0; i < count; i++)
+ {
+ a= (class cl_prg_arg *)(at(i));
+ if (a->long_name &&
+ strcmp(a->long_name, name) == 0)
+ return(1);
+ }
+ return(0);
+}
+
+long
+cl_arguments::get_iarg(char sname, char *lname)
+{
+ class cl_prg_arg *a;
+ int i;
+
+ for (i= 0; i < count; i++)
+ {
+ a= (class cl_prg_arg *)(at(i));
+ if ((sname && a->short_name == sname) ||
+ (lname && a->long_name && strcmp(a->long_name, lname) == 0))
+ {
+ long iv;
+ if (a->get_ivalue(&iv))
+ return(iv);
+ else
+ //FIXME
+ return(0);
+ }
+ }
+ return(0);
+}
+
+char *
+cl_arguments::get_sarg(char sname, char *lname)
+{
+ class cl_prg_arg *a;
+ int i;
+
+ for (i= 0; i < count; i++)
+ {
+ a= (class cl_prg_arg *)(at(i));
+ if ((sname && a->short_name == sname) ||
+ (lname && a->long_name && strcmp(a->long_name, lname) == 0))
+ return(a->get_svalue());
+ }
+ return(0);
+}
+
+
+double
+cl_arguments::get_farg(char sname, char *lname)
+{
+ class cl_prg_arg *a;
+ int i;
+
+ for (i= 0; i < count; i++)
+ {
+ a= (class cl_prg_arg *)(at(i));
+ if ((sname && a->short_name == sname) ||
+ (lname && a->long_name && strcmp(a->long_name, lname) == 0))
+ return(a->get_fvalue());
+ }
+ return(0);
+}
+
+void *
+cl_arguments::get_parg(char sname, char *lname)
+{
+ class cl_prg_arg *a;
+ int i;
+
+ for (i= 0; i < count; i++)
+ {
+ a= (class cl_prg_arg *)(at(i));
+ if ((sname && a->short_name == sname) ||
+ (lname && a->long_name && strcmp(a->long_name, lname) == 0))
+ return(a->get_pvalue());
+ }
+ return(0);
+}
+
+
/* End of arg.cc */
#ifndef SIM_ARGCL_HEADER
#define SIM_ARGCL_HEADER
+// prj
#include "pobjcl.h"
+#include "stypes.h"
/*
class cl_cmd_arg: public cl_arg
{
public:
- class cl_uc *uc;
+ //class cl_uc *uc;
bool interpreted_as_string;
union {
} value;
public:
- cl_cmd_arg(class cl_uc *iuc, long i): cl_arg(i)
- { uc= iuc; interpreted_as_string= DD_FALSE; }
- cl_cmd_arg(class cl_uc *iuc, char *s): cl_arg(s)
- { uc= iuc; interpreted_as_string= DD_FALSE; }
+ cl_cmd_arg(/*class cl_uc *iuc,*/ long i): cl_arg(i)
+ { /*uc= iuc;*/ interpreted_as_string= DD_FALSE; }
+ cl_cmd_arg(/*class cl_uc *iuc,*/ char *s): cl_arg(s)
+ { /*uc= iuc;*/ interpreted_as_string= DD_FALSE; }
~cl_cmd_arg(void);
virtual int is_string(void) { return(DD_FALSE); }
- virtual bool get_address(t_addr *addr) { return(DD_FALSE); }
- virtual bool as_address(void);
+ virtual bool get_address(class cl_uc *uc, t_addr *addr) { return(DD_FALSE); }
+ virtual bool as_address(class cl_uc *uc);
virtual bool as_number(void);
virtual bool as_data(void);
virtual bool as_string(void);
- virtual bool as_memory(void);
+ virtual bool as_memory(class cl_uc *uc);
virtual bool as_hw(class cl_uc *uc);
virtual bool as_bit(class cl_uc *uc);
};
class cl_cmd_int_arg: public cl_cmd_arg
{
public:
- cl_cmd_int_arg(class cl_uc *iuc, long addr);
+ cl_cmd_int_arg(/*class cl_uc *iuc,*/ long addr);
- virtual bool get_address(t_addr *addr);
+ virtual bool get_address(class cl_uc *uc, t_addr *addr);
virtual bool get_bit_address(class cl_uc *uc, // input
class cl_mem **mem, // outputs
t_addr *mem_addr,
class cl_cmd_sym_arg: public cl_cmd_arg
{
public:
- cl_cmd_sym_arg(class cl_uc *iuc, char *sym);
+ cl_cmd_sym_arg(/*class cl_uc *iuc,*/ char *sym);
- virtual bool get_address(t_addr *addr);
+ virtual bool get_address(class cl_uc *uc, t_addr *addr);
virtual bool get_bit_address(class cl_uc *uc, // input
class cl_mem **mem, // outputs
t_addr *mem_addr,
t_mem *bit_mask);
- virtual bool as_address(void);
+ virtual bool as_address(class cl_uc *uc);
virtual bool as_string(void);
virtual bool as_hw(class cl_uc *uc);
};
class cl_cmd_str_arg: public cl_cmd_arg
{
public:
- cl_cmd_str_arg(class cl_uc *iuc, char *str);
+ cl_cmd_str_arg(/*class cl_uc *iuc,*/ char *str);
virtual int is_string(void) { return(1); }
};
class cl_cmd_arg *sfr, *bit;
public:
- cl_cmd_bit_arg(class cl_uc *iuc,
+ cl_cmd_bit_arg(/*class cl_uc *iuc,*/
class cl_cmd_arg *asfr, class cl_cmd_arg *abit);
~cl_cmd_bit_arg(void);
- virtual bool get_address(t_addr *addr);
+ virtual bool get_address(class cl_uc *uc, t_addr *addr);
virtual bool get_bit_address(class cl_uc *uc, // input
class cl_mem **mem, // outputs
t_addr *mem_addr,
class cl_cmd_arg *name, *index;
public:
- cl_cmd_array_arg(class cl_uc *iuc,
+ cl_cmd_array_arg(/*class cl_uc *iuc,*/
class cl_cmd_arg *aname, class cl_cmd_arg *aindex);
~cl_cmd_array_arg(void);
virtual bool as_hw(class cl_uc *uc);
};
+/*
+ * List of arguments
+ */
+
+class cl_arguments: public cl_list
+{
+public:
+ cl_arguments(void): cl_list(5, 5) {}
+
+ int arg_avail(char name);
+ int arg_avail(char *name);
+ virtual long get_iarg(char sname, char *lname);
+ virtual char *get_sarg(char sname, char *lname);
+ virtual double get_farg(char sname, char *lname);
+ virtual void *get_parg(char sname, char *lname);
+};
+
+
#endif
/* End of argcl.h */
# Deleting all files created by building the program
# --------------------------------------------------
clean:
- rm -f *core *[%~] *.[oa]
+ rm -f *core *[%~] *.[oa] test_mem_speed
rm -f .[a-z]*~
* Callback functions for changing memory locations
*/
-ulong
-cl_hw::read(class cl_mem *mem, long addr)
+t_mem
+cl_hw::read(class cl_mem *mem, t_addr addr)
{
// Simply return the value
return(mem->get(addr));
}
void
-cl_hw::write(class cl_mem *mem, long addr, ulong *val)
+cl_hw::write(class cl_mem *mem, t_addr addr, t_mem *val)
{
// Do not change *val by default
}
}
+t_index
+cl_hws::add(void *item)
+{
+ int i;
+ t_index res;
+
+ // pre-add
+ for (i= 0; i < count; i++)
+ {
+ class cl_hw *hw= (class cl_hw *)(at(i));
+ hw->adding((class cl_hw *)item);
+ }
+ // add
+ res= cl_list::add(item);
+ // post-add
+ for (i= 0; i < count; i++)
+ {
+ class cl_hw *hw= (class cl_hw *)(at(i));
+ hw->added((class cl_hw *)item);
+ }
+ return(res);
+}
+
+
/* End of hw.cc */
cl_hw(class cl_uc *auc, enum hw_cath cath, int aid, char *aid_string);
~cl_hw(void);
- virtual ulong read(class cl_mem *mem, long addr);
- virtual void write(class cl_mem *mem, long addr, ulong *val);
+ virtual void adding(class cl_hw *new_hw) {}
+ virtual void added(class cl_hw *new_hw) {}
+ virtual t_mem read(class cl_mem *mem, t_addr addr);
+ virtual void write(class cl_mem *mem, t_addr addr, t_mem *val);
virtual int tick(int cycles);
virtual void print_info(class cl_console *con);
};
+class cl_hws: public cl_list
+{
+public:
+ cl_hws(void): cl_list(2, 2) {}
+ virtual t_index add(void *item);
+};
+
#endif
/*
*/
-cl_cell::cl_cell(void):
+cl_cell::cl_cell(int awidth):
cl_base()
{
data= 0;
+ mask= 1;
+ for (; awidth; awidth--)
+ {
+ mask<<= 1;
+ mask|= 1;
+ }
}
-cl_cell::cl_cell(t_mem idata):
- cl_base()
+/*t_mem
+cl_cell::read(void)
+{
+ return(data);
+}*/
+
+/*t_mem
+cl_cell::get(void)
+{
+ return(data);
+}*/
+
+/*void
+cl_cell::write(t_mem *val)
+{
+ data= *val= (*val & mask);
+}*/
+
+/*void
+cl_cell::set(t_mem val)
{
- data= idata;
+ data= val & mask;
+}*/
+
+
+cl_registered_cell::cl_registered_cell(int awidth):
+ cl_cell(awidth)
+{
+ hws= new cl_list(1, 1);
+ hardwares= 0;
+ nuof_hws= 0;
}
+cl_registered_cell::~cl_registered_cell(void)
+{
+ hws->disconn_all();
+ delete hws;
+}
+
+t_mem
+cl_registered_cell::read(void)
+{
+ int i;
+
+ /*if (hws->count)
+ for (i= 0; i < hws->count; i++)
+ {
+ class cl_hw *hw= (class cl_hw *)(hws->at(i));
+ ;
+ }*/
+ if (nuof_hws)
+ for (i= 0; i < nuof_hws; i++)
+ {
+ //hardwares[i];
+ ;
+ }
+ return(data);
+}
+
+void
+cl_registered_cell::write(t_mem *val)
+{
+ int i;
+
+ /*if (hws->count)
+ for (i= 0; i < hws->count; i++)
+ {
+ class cl_hw *hw= (class cl_hw *)(hws->at(i));
+ ;
+ }*/
+ if (nuof_hws)
+ for (i= 0; i < nuof_hws; i++)
+ {
+ //hardwares[i];
+ ;
+ }
+ data= *val= (*val & mask);
+}
+
+
+/*
+ */
+
+cl_m::cl_m(t_addr asize, int awidth):
+ cl_mem(MEM_SFR, "sfr", 0, awidth)
+{
+ t_addr a;
+
+ size= asize;
+ width= awidth;
+ array= (class cl_cell **)malloc(size * sizeof(class cl_cell *));
+ for (a= 0; a < size; a++)
+ array[a]= new cl_registered_cell(width);
+}
+
+cl_m::~cl_m(void)
+{
+ t_addr a;
+
+ for (a= 0; a < size; a++)
+ delete array[a];
+ free(array);
+}
+
+t_mem
+cl_m::read(t_addr addr)
+{
+ if (addr >= size)
+ return(0);
+ return(array[addr]->read());
+}
+
+t_mem
+cl_m::get(t_addr addr)
+{
+ if (addr >= size)
+ return(0);
+ return(array[addr]->get());
+}
+
+void
+cl_m::write(t_addr addr, t_mem *val)
+{
+ if (addr >= size)
+ return;
+ array[addr]->write(val);
+}
+
+void
+cl_m::set(t_addr addr, t_mem val)
+{
+ if (addr >= size)
+ return;
+ array[addr]->set(val);
+}
+
+
/*
* Memory
******************************************************************************
class cl_memloc *get_loc(t_addr address);
};
-
-class cl_cell: public cl_base
-{
-public:
- t_mem data;
-
-public:
- cl_cell(void);
- cl_cell(t_mem idata);
-};
-
/* Memory */
class cl_mem: public cl_guiobj
~cl_rom(void);
};
+/* New type */
+
+class cl_cell: public cl_base
+{
+public:
+ t_mem data;
+protected:
+ t_mem mask;
+
+public:
+ cl_cell(int awidth);
+ virtual t_mem read(void) { return(data); }
+ virtual t_mem get(void) { return(data); }
+ virtual void write(t_mem *val) { data= *val= (*val & mask); }
+ virtual void set(t_mem val) { data= val & mask; }
+};
+
+class cl_registered_cell: public cl_cell
+{
+protected:
+ class cl_list *hws;
+ class cl_hw *hardwares;
+ int nuof_hws;
+public:
+ cl_registered_cell(int awidth);
+ ~cl_registered_cell(void);
+ virtual t_mem read(void);
+ virtual void write(t_mem *val);
+};
+
+class cl_m: public cl_mem
+{
+protected:
+ class cl_cell **array;
+public:
+ t_addr size;
+ int width;
+
+public:
+ cl_m(t_addr asize, int awidth);
+ ~cl_m(void);
+ virtual t_mem read(t_addr addr);
+ virtual t_mem get(t_addr addr);
+ virtual void write(t_addr addr, t_mem *val);
+ virtual void set(t_addr addr, t_mem val);
+};
+
#endif
* Debug on console
*/
-cl_cons_debug_opt::cl_cons_debug_opt(class cl_sim *Asim,
+cl_cons_debug_opt::cl_cons_debug_opt(class cl_app *the_app,
char *Iid,
char *Ihelp):
cl_option(0, Iid, Ihelp)
{
- sim= Asim;
+ app= the_app;
}
void
cl_cons_debug_opt::print(class cl_console *con)
{
- if (sim->cmd->actual_console &&
- sim->cmd->actual_console->flags & CONS_DEBUG)
+ if (/*sim->cmd->actual_console &&
+ sim->cmd->actual_console*/con->flags & CONS_DEBUG)
con->printf("TRUE");
else
con->printf("FALSE");
bool
cl_cons_debug_opt::get_value(void)
{
- return(sim->cmd->actual_console?
- (sim->cmd->actual_console->flags & CONS_DEBUG):
+ return(app->get_commander()->actual_console?
+ (app->get_commander()->actual_console->flags & CONS_DEBUG):
0);
}
void
cl_cons_debug_opt::set_value(bool opt)
{
- if (sim->cmd->actual_console)
+ if (app->get_commander()->actual_console)
{
if (opt)
- sim->cmd->actual_console->flags|= CONS_DEBUG;
+ app->get_commander()->actual_console->flags|= CONS_DEBUG;
else
- sim->cmd->actual_console->flags&= ~CONS_DEBUG;
+ app->get_commander()->actual_console->flags&= ~CONS_DEBUG;
}
}
char c;
if (s &&
- sim->cmd->actual_console)
+ app->get_commander()->actual_console)
{
c= toupper(*s);
if (c == '1' ||
c == 'T' ||
c == 'Y')
- sim->cmd->actual_console->flags|= CONS_DEBUG;
+ app->get_commander()->actual_console->flags|= CONS_DEBUG;
else
- sim->cmd->actual_console->flags&= ~CONS_DEBUG;
+ app->get_commander()->actual_console->flags&= ~CONS_DEBUG;
}
}
class cl_cons_debug_opt: public cl_option
{
public:
- class cl_sim *sim;
+ class cl_app *app;
public:
- cl_cons_debug_opt(class cl_sim *Asim, char *Iid, char *Ihelp);
+ cl_cons_debug_opt(class cl_app *the_app, char *Iid, char *Ihelp);
virtual void print(class cl_console *con);
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include <errno.h>
-#include <ctype.h>
-#ifdef HAVE_GETOPT_H
-# include <getopt.h>
-#endif
#include "i_string.h"
// prj
// cmd
#include "cmdsetcl.h"
-#include "infocl.h"
-#include "setcl.h"
-#include "getcl.h"
-#include "showcl.h"
-#include "bpcl.h"
#include "cmdguicl.h"
-#include "cmdconfcl.h"
-// local
+// local, sim.src
#include "simcl.h"
+#include "appcl.h"
/*
* Simulator
*/
-cl_sim::cl_sim(class cl_app *the_app,
- char *more_args, int iargc, char *iargv[]):
+cl_sim::cl_sim(class cl_app *the_app):
cl_base()
{
app= the_app;
- argc= iargc; argv= iargv;
uc= 0;
- cmd= 0;
- arguments= new cl_list(2, 2);
- accept_args= more_args?strdup(more_args):0;
- in_files= new cl_ustrings(2, 2);
+ //arguments= new cl_list(2, 2);
+ //accept_args= more_args?strdup(more_args):0;
gui= new cl_gui(this);
}
int
cl_sim::init(void)
{
- int i;
-
cl_base::init();
- proc_arguments(argc, argv);
- class cl_cmdset *cmdset= new cl_cmdset(this);
- cmdset->init();
- build_cmd_set(cmdset);
+ build_cmdset(app->get_commander()->cmdset);
if (!(uc= mk_controller()))
return(1);
uc->init();
- cmd= new cl_commander(app, cmdset, this);
- cmd->init();
- char *Config= get_sarg(0, "Config");
- if (Config)
- {
- class cl_console *con= cmd->mk_console(Config, 0/*"/dev/tty"*/, this);
- cmd->add_console(con);
- }
- if (cmd->cons->get_count() == 0)
- {
- fprintf(stderr, "No command console available.\n");
- exit(1);
- }
- for (i= 0; i < in_files->count; i++)
- {
- char *fname= (char *)(in_files->at(i));
- long l;
- if ((l= uc->read_hex_file(fname)) >= 0)
- {
- cmd->all_printf("%ld words read from %s\n", l, fname);
- fprintf(stderr, "%ld words read from %s\n", l, fname);
- }
- char *prompt;
- if (arg_avail('P'))
- cmd->all_print("\0", 1);
- else
- cmd->all_printf("%s", (prompt= get_sarg(0, "prompt"))?prompt:"> ") ;
- }
return(0);
}
delete uc;
}
-int
-cl_sim::proc_arguments(int argc, char *argv[])
-{
- int i, c;
- char *opts, *cp;
-
- opts= (char*)malloc((accept_args?strlen(accept_args):0)+100);
- strcpy(opts, "c:C:p:PX:vV");
-#ifdef SOCKET_AVAIL
- strcat(opts, "Z:r:");
-#endif
- if (accept_args)
- strcat(opts, accept_args);
- opterr= 0;
- while((c= getopt(argc, argv, opts)) != -1)
- switch (c)
- {
-
- case 'c':
- arguments->add(new cl_prg_arg('c', 0, optarg));
- break;
-
- case 'C':
- arguments->add(new cl_prg_arg(0, "Config", optarg));
- break;
-
-#ifdef SOCKET_AVAIL
- case 'Z':
- // By Sandeep
- arguments->add(new cl_prg_arg('Z', 0, (long)1));
- if (!optarg || !isdigit(*optarg))
- fprintf(stderr, "expected portnumber to follow -Z\n");
- else {
- char *p;
- long l= strtol(optarg, &p, 0);
- arguments->add(new cl_prg_arg(0, "Zport", l));
- }
- break;
-#endif
-
- case 'p':
- arguments->add(new cl_prg_arg(0, "prompt", optarg));
- break;
-
- case 'P':
- arguments->add(new cl_prg_arg('P', 0, (long)1));
- break;
-
-#ifdef SOCKET_AVAIL
- case 'r':
- arguments->add(new cl_prg_arg('r', 0,
- (long)strtol(optarg, NULL, 0)));
- break;
-#endif
-
- case 'X':
- {
- double XTAL;
- for (cp= optarg; *cp; *cp= toupper(*cp), cp++);
- XTAL= strtod(optarg, &cp);
- if (*cp == 'K')
- XTAL*= 1e3;
- if (*cp == 'M')
- XTAL*= 1e6;
- if (XTAL == 0)
- {
- fprintf(stderr, "Xtal frequency must be greather than 0\n");
- exit(1);
- }
- arguments->add(new cl_prg_arg('X', 0, XTAL));
- break;
- }
-
- case 'v':
- printf("%s: %s\n", argv[0], VERSIONSTR);
- exit(0);
- break;
-
- case 'V':
- arguments->add(new cl_prg_arg('V', 0, (long)1));
- break;
-
- case '?':
- if ((c= proc_arg(c, optarg)))
- exit(c);
- break;
-
- default:
- if ((c= proc_arg(c, optarg)))
- exit(c);
- }
- if (!arg_avail("prompt"))
- arguments->add(new cl_prg_arg(0, "prompt", "> "));
-
- for (i= optind; i < argc; i++)
- in_files->add(argv[i]);
-
- free(opts);
- return(0);
-}
-
-int
-cl_sim::proc_arg(char arg, char *optarg)
-{
- return(0);
-}
-
-int
-cl_sim::arg_avail(char name)
-{
- class cl_prg_arg *a;
- int i;
-
- for (i= 0; i < arguments->count; i++)
- {
- a= (class cl_prg_arg *)(arguments->at(i));
- if (a->short_name == name)
- return(1);
- }
- return(0);
-}
-
-int
-cl_sim::arg_avail(char *name)
-{
- class cl_prg_arg *a;
- int i;
-
- for (i= 0; i < arguments->count; i++)
- {
- a= (class cl_prg_arg *)(arguments->at(i));
- if (a->long_name &&
- strcmp(a->long_name, name) == 0)
- return(1);
- }
- return(0);
-}
-
-long long
-cl_sim::get_iarg(char sname, char *lname)
-{
- class cl_prg_arg *a;
- int i;
-
- for (i= 0; i < arguments->count; i++)
- {
- a= (class cl_prg_arg *)(arguments->at(i));
- if ((sname && a->short_name == sname) ||
- (lname && a->long_name && strcmp(a->long_name, lname) == 0))
- {
- long iv;
- if (a->get_ivalue(&iv))
- return(iv);
- else
- //FIXME
- return(0);
- }
- }
- return(0);
-}
-
-char *
-cl_sim::get_sarg(char sname, char *lname)
-{
- class cl_prg_arg *a;
- int i;
-
- for (i= 0; i < arguments->count; i++)
- {
- a= (class cl_prg_arg *)(arguments->at(i));
- if ((sname && a->short_name == sname) ||
- (lname && a->long_name && strcmp(a->long_name, lname) == 0))
- return(a->get_svalue());
- }
- return(0);
-}
-
-
-double
-cl_sim::get_farg(char sname, char *lname)
-{
- class cl_prg_arg *a;
- int i;
-
- for (i= 0; i < arguments->count; i++)
- {
- a= (class cl_prg_arg *)(arguments->at(i));
- if ((sname && a->short_name == sname) ||
- (lname && a->long_name && strcmp(a->long_name, lname) == 0))
- return(a->get_fvalue());
- }
- return(0);
-}
-
-void *
-cl_sim::get_parg(char sname, char *lname)
-{
- class cl_prg_arg *a;
- int i;
-
- for (i= 0; i < arguments->count; i++)
- {
- a= (class cl_prg_arg *)(arguments->at(i));
- if ((sname && a->short_name == sname) ||
- (lname && a->long_name && strcmp(a->long_name, lname) == 0))
- return(a->get_pvalue());
- }
- return(0);
-}
-
class cl_uc *
cl_sim::mk_controller(void)
{
return(new cl_uc(this));
}
-class cl_cmd_arg *
-cl_sim::mk_cmd_int_arg(long long i)
-{
- class cl_cmd_arg *arg= new cl_cmd_int_arg(uc, i);
- arg->init();
- return(arg);
-}
-
-class cl_cmd_arg *
-cl_sim::mk_cmd_sym_arg(char *s)
-{
- class cl_cmd_arg *arg= new cl_cmd_sym_arg(uc, s);
- arg->init();
- return(arg);
-}
-
-class cl_cmd_arg *
-cl_sim::mk_cmd_str_arg(char *s)
-{
- class cl_cmd_arg *arg= new cl_cmd_str_arg(uc, s);
- arg->init();
- return(arg);
-}
-
-class cl_cmd_arg *
-cl_sim::mk_cmd_bit_arg(class cl_cmd_arg *sfr, class cl_cmd_arg *bit)
-{
- class cl_cmd_arg *arg= new cl_cmd_bit_arg(uc, sfr, bit);
- arg->init();
- return(arg);
-}
-
-class cl_cmd_arg *
-cl_sim::mk_cmd_array_arg(class cl_cmd_arg *aname, class cl_cmd_arg *aindex)
-{
- class cl_cmd_arg *arg= new cl_cmd_array_arg(uc, aname, aindex);
- arg->init();
- return(arg);
-}
-
/*
* Main cycle of the simulator
if (state & SIM_GO)
{
uc->do_inst(-1);
- if (cmd->input_avail())
+ if (app->get_commander()->input_avail())
{
- done= cmd->proc_input();
+ done= app->get_commander()->proc_input();
}
}
else
{
- cmd->wait_input();
- done= cmd->proc_input();
+ app->get_commander()->wait_input();
+ done= app->get_commander()->proc_input();
}
}
return(0);
}
+int
+cl_sim::step(void)
+{
+ if (state & SIM_GO)
+ uc->do_inst(1);
+ return(0);
+}
+
/*int
cl_sim::do_cmd(char *cmdstr, class cl_console *console)
{
{
state|= SIM_GO;
con->flags|= CONS_FROZEN;
- cmd->frozen_console= con;
- cmd->set_fd_set();
+ app->get_commander()->frozen_console= con;
+ app->get_commander()->set_fd_set();
}
void
cl_sim::stop(int reason)
{
+ class cl_commander *cmd= app->get_commander();
+
state&= ~SIM_GO;
if (cmd->frozen_console)
{
*/
void
-cl_sim::build_cmd_set(class cl_cmdset *cmdset)
+cl_sim::build_cmdset(class cl_cmdset *cmdset)
{
class cl_cmd *cmd;
class cl_cmdset *cset;
- {
- cset= new cl_cmdset(this);
- cset->init();
- cset->add(cmd= new cl_conf_cmd("_no_parameters_", 0,
-"conf Configuration",
-"long help of conf"));
- cmd->init();
- cset->add(cmd= new cl_conf_addmem_cmd("addmem", 0,
-"conf addmem\n"
-" Make memory",
-"long help of conf addmem"));
- cmd->init();
- }
- cmdset->add(cmd= new cl_super_cmd("conf", 0,
-"conf subcommand Information, see `conf' command for more help",
-"long help of conf", cset));
- cmd->init();
-
- cmdset->add(cmd= new cl_state_cmd("state", 0,
-"state State of simulator",
-"long help of state"));
- cmd->init();
-
- cmdset->add(cmd= new cl_file_cmd("file", 0,
-"file \"FILE\" Load FILE into ROM",
-"long help of file"));
- cmd->init();
- cmd->add_name("load");
-
- cmdset->add(cmd= new cl_dl_cmd("download", 0,
-"download,dl Load (intel.hex) data",
-"long help of download"));
- cmd->init();
- cmd->add_name("dl");
-
- {
- cset= new cl_cmdset(this);
- cset->init();
- cset->add(cmd= new cl_info_bp_cmd("breakpoints", 0,
-"info breakpoints Status of user-settable breakpoints",
-"long help of info breakpoints"));
- cmd->add_name("bp");
- cmd->init();
- cset->add(cmd= new cl_info_reg_cmd("registers", 0,
-"info registers List of integer registers and their contents",
-"long help of info registers"));
- cmd->init();
- cset->add(cmd= new cl_info_hw_cmd("hardware", 0,
-"info hardware cathegory\n"
-" Status of hardware elements of the CPU",
-"long help of info hardware"));
- cmd->add_name("h w");
- cmd->init();
- }
- cmdset->add(cmd= new cl_super_cmd("info", 0,
-"info subcommand Information, see `info' command for more help",
-"long help of info", cset));
- cmd->init();
-
- {
- cset= new cl_cmdset(this);
- cset->init();
- cset->add(cmd= new cl_get_sfr_cmd("sfr", 0,
-"get sfr address...\n"
-" Get value of addressed SFRs",
-"long help of get sfr"));
- cmd->init();
- cset->add(cmd= new cl_get_option_cmd("option", 0,
-"get option name\n"
-" Get value of an option",
-"long help of get option"));
- cmd->init();
- }
- cmdset->add(cmd= new cl_super_cmd("get", 0,
-"get subcommand Get, see `get' command for more help",
-"long help of get", cset));
- cmd->init();
-
- {
- cset= new cl_cmdset(this);
- cset->init();
- cset->add(cmd= new cl_set_mem_cmd("memory", 0,
-"set memory memory_type address data...\n"
-" Place list of data into memory",
-"long help of set memory"));
- cmd->init();
- cset->add(cmd= new cl_set_bit_cmd("bit", 0,
-"set bit addr 0|1 Set specified bit to 0 or 1",
-"long help of set bit"));
- cmd->init();
- cset->add(cmd= new cl_set_port_cmd("port", 0,
-"set port hw data Set data connected to port",
-"long help of set port"));
- cmd->init();
- cset->add(cmd= new cl_set_option_cmd("option", 0,
-"set option name value\n"
-" Set value of an option",
-"long help of set option"));
- cmd->init();
- }
- cmdset->add(cmd= new cl_super_cmd("set", 0,
-"set subcommand Set, see `set' command for more help",
-"long help of set", cset));
- cmd->init();
-
- cmdset->add(cmd= new cl_timer_cmd("timer", 0,
-"timer a|d|g|r|s|v id [direction|value]\n"
-" Timer add|del|get|run|stop|value",
-"timer add|create|make id [direction] -- create a new timer\n"
-"timer del id -- delete a timer\n"
-"timer get id -- list timers\n"
-"timer run id -- turn a timer ON\n"
-"timer stop id -- turn a timer OFF\n"
-"timer value id val -- set value of a timer to `val'"));
- cmd->init();
-
cmdset->add(cmd= new cl_run_cmd("run", 0,
"run [start [stop]] Go",
"long help of run"));
cmd->init();
cmd->add_name("n");
- cmdset->add(cmd= new cl_pc_cmd("pc", 0,
-"pc [addr] Set/get PC",
-"long help of pc"));
- cmd->init();
-
- cmdset->add(cmd= new cl_reset_cmd("reset", 0,
-"reset Reset",
-"long help of reset"));
- cmd->init();
-
- cmdset->add(cmd= new cl_dump_cmd("dump", 0,
-"dump memory_type [start [stop [bytes_per_line]]]\n"
-" Dump memory of specified type\n"
-"dump bit... Dump bits",
-"long help of dump"));
- cmd->init();
-
- cmdset->add(cmd= new cl_di_cmd("di", 0,
-"di [start [stop]] Dump Internal RAM",
-"long help of di"));
- cmd->init();
-
- cmdset->add(cmd= new cl_dx_cmd("dx", 0,
-"dx [start [stop]] Dump External RAM",
-"long help of dx"));
- cmd->init();
-
- cmdset->add(cmd= new cl_ds_cmd("ds", 0,
-"ds [start [stop]] Dump SFR",
-"long help of ds"));
- cmd->init();
-
- cmdset->add(cmd= new cl_dch_cmd("dch", 0,
-"dch [start [stop]] Dump code in hex form",
-"long help of dch"));
- cmd->init();
-
- cmdset->add(cmd= new cl_dc_cmd("dc", 0,
-"dc [start [stop]] Dump code in disass form",
-"long help of dc"));
- cmd->init();
-
- cmdset->add(cmd= new cl_disassemble_cmd("disassemble", 0,
-"disassemble [start [offset [lines]]]\n"
-" Disassemble code",
-"long help of disassemble"));
- cmd->init();
-
- cmdset->add(cmd= new cl_fill_cmd("fill", 0,
-"fill memory_type start end data\n"
-" Fill memory region with data",
-"long help of fill"));
- cmd->init();
-
- cmdset->add(cmd= new cl_where_cmd("where", 0,
-"where memory_type data...\n"
-" Case unsensitive search for data",
-"long help of where"));
- cmd->init();
-
- cmdset->add(cmd= new cl_Where_cmd("Where", 0,
-"Where memory_type data...\n"
-" Case sensitive search for data",
-"long help of Where"));
- cmd->init();
-
- cmdset->add(cmd= new cl_break_cmd("break", 0,
-"break addr [hit] Set fix breakpoint\n"
-"break mem_type r|w addr [hit]\n"
-" Set fix event breakpoint",
-"long help of break"));
- cmd->init();
-
- cmdset->add(cmd= new cl_tbreak_cmd("tbreak", 0,
-"tbreak addr [hit] Set temporary breakpoint\n"
-"tbreak mem_type r|w addr [hit]\n"
-" Set temporary event breakpoint",
-"long help of tbreak"));
- cmd->init();
-
- cmdset->add(cmd= new cl_clear_cmd("clear", 0,
-"clear [addr...] Clear fix breakpoint",
-"long help of clear"));
- cmd->init();
-
- cmdset->add(cmd= new cl_delete_cmd("delete", 0,
-"delete [nr...] Delete breakpoint(s)",
-"long help of clear"));
- cmd->init();
-
- cmdset->add(cmd= new cl_help_cmd("help", 0,
-"help [command] Help about command(s)",
-"long help of help"));
- cmd->init();
- cmd->add_name("?");
-
- cmdset->add(cmd= new cl_quit_cmd("quit", 0,
-"quit Quit",
-"long help of quit"));
- cmd->init();
-
- cmdset->add(cmd= new cl_kill_cmd("kill", 0,
-"kill Shutdown simulator",
-"long help of kill"));
- cmd->init();
-
- {
- cset= new cl_cmdset(this);
- cset->init();
- cset->add(cmd= new cl_show_copying_cmd("copying", 0,
-"show copying Conditions for redistributing copies of uCsim",
-"long help of show copying"));
- cmd->init();
- cset->add(cmd= new cl_show_warranty_cmd("warranty", 0,
-"show warranty Various kinds of warranty you do not have",
-"long help of show warranty"));
- cmd->init();
- }
- cmdset->add(cmd= new cl_super_cmd("show", 0,
-"show subcommand Generic command for showing things about the uCsim",
-"long help of show", cset));
- cmd->init();
-
{
- cset= new cl_cmdset(this);
+ cset= new cl_cmdset();
cset->init();
cset->add(cmd= new cl_gui_start_cmd("start", 0,
"gui start Start interfacing with GUI tool",
class cl_sim: public cl_base
{
-protected:
- class cl_app *app;
public:
+ class cl_app *app;
int state; // See SIM_XXXX
int argc; char **argv;
- class cl_commander *cmd;
+ //class cl_commander *cmd;
class cl_uc *uc;
class cl_gui *gui;
- char *accept_args;
- class cl_ustrings *in_files;
- class cl_list *arguments;
+ //char *accept_args;
+ //class cl_list *arguments;
public:
- cl_sim(class cl_app *the_app, char *more_args, int iargc, char *iargv[]);
+ cl_sim(class cl_app *the_app);
~cl_sim(void);
virtual int init(void);
- virtual int proc_arguments(int argc, char *argv[]);
- virtual int proc_arg(char arg, char *optarg);
-
virtual class cl_uc *mk_controller(void);
- virtual void build_cmd_set(class cl_cmdset *cmdset);
- virtual class cl_cmd_arg *mk_cmd_int_arg(long long i);
- virtual class cl_cmd_arg *mk_cmd_sym_arg(char *s);
- virtual class cl_cmd_arg *mk_cmd_str_arg(char *s);
- virtual class cl_cmd_arg *mk_cmd_bit_arg(class cl_cmd_arg *sfr,
- class cl_cmd_arg *bit);
- virtual class cl_cmd_arg *mk_cmd_array_arg(class cl_cmd_arg *aname,
- class cl_cmd_arg *aindex);
-
- int arg_avail(char name);
- int arg_avail(char *name);
- virtual long long get_iarg(char sname, char *lname);
- virtual char *get_sarg(char sname, char *lname);
- virtual double get_farg(char sname, char *lname);
- virtual void *get_parg(char sname, char *lname);
+ virtual void build_cmdset(class cl_cmdset *cmdset);
virtual int main(void);
virtual void start(class cl_console *con);
virtual void stop(int reason);
+ virtual int step(void);
};
+#include <signal.h>
+#include <unistd.h>
+#include <stdio.h>
+
#include "memcl.h"
+static int go;
+
+static void
+alarmed(int sig)
+{
+ go= 0;
+ signal(sig, alarmed);
+}
+
int
main(void)
{
class cl_mem *mem;
+ class cl_m *m2;
t_addr a;
t_mem d;
+ double counter;
+
+ signal(SIGALRM, alarmed);
mem= new cl_mem(MEM_SFR, "egy", 0x10000, 8);
- for (a= 0; a < mem->size; a++)
- {
- t_mem d2= a;
- mem->write(a, &d2);
- d= mem->read(a);
- }
+ go= 1;
+ counter= 0;
+ alarm(10);
+ while (go)
+ for (a= 0; go && a < mem->size; a++)
+ {
+ t_mem d2;
+ for (d2= 0; d2 <= 255; d2++)
+ {
+ mem->write(a, &d2);
+ d= mem->read(a);
+ if (d != d2)
+ printf("%ld written to mem and %ld read back!\n", d2, d);
+ counter+= 1;
+ }
+ }
+ printf("%g operations on classic memory within 10 sec\n", counter);
+
+ m2= new cl_m(0x10000, 8);
+ go= 1;
+ counter= 0;
+ alarm(10);
+ while (go)
+ for (a= 0; go && a < m2->size; a++)
+ {
+ t_mem d2;
+ for (d2= 0; d2 <= 255; d2++)
+ {
+ m2->write(a, &d2);
+ d= m2->read(a);
+ if (d != d2)
+ printf("%ld written to m2 and %ld read back!\n", d2, d);
+ counter+= 1;
+ }
+ }
+ printf("%g operations on new memory within 10 sec\n", counter);
+
return(0);
}
#include <ctype.h>
#include "i_string.h"
+// prj
#include "globals.h"
#include "utils.h"
+// cmd.src
+#include "newcmdcl.h"
+#include "cmduccl.h"
+#include "bpcl.h"
+#include "getcl.h"
+#include "setcl.h"
+#include "infocl.h"
+#include "timercl.h"
+
+// local, sim.src
#include "uccl.h"
#include "hwcl.h"
#include "memcl.h"
int i;
sim = asim;
mems= new cl_list(MEM_TYPES, 1);
- hws = new cl_list(2, 1);
+ hws = new cl_hws();
options= new cl_list(2, 2);
for (i= MEM_ROM; i < MEM_TYPES; i++)
mems->add(0);
int
cl_uc::init(void)
{
- int mc;
+ int mc, i;
cl_base::init();
- if (!(sim->arg_avail('X')) ||
- sim->get_farg('X', 0) == 0)
+ if (!(sim->app->args->arg_avail('X')) ||
+ sim->app->args->get_farg('X', 0) == 0)
xtal= 11059200;
else
- xtal= sim->get_farg('X', 0);
+ xtal= sim->app->args->get_farg('X', 0);
for (mc= MEM_ROM; mc < MEM_TYPES; mc++)
{
class cl_mem *m= mk_mem((enum mem_class)mc,
brk_counter= 0;
mk_hw_elements();
reset();
+ class cl_cmdset *cs= sim->app->get_commander()->cmdset;
+ build_cmdset(cs);
+
+ for (i= 0; i < sim->app->in_files->count; i++)
+ {
+ char *fname= (char *)(sim->app->in_files->at(i));
+ long l;
+ if ((l= read_hex_file(fname)) >= 0)
+ {
+ sim->app->get_commander()->all_printf("%ld words read from %s\n",
+ l, fname);
+ }
+ }
return(0);
}
{
}
+void
+cl_uc::build_cmdset(class cl_cmdset *cmdset)
+{
+ class cl_cmd *cmd;
+ class cl_cmdset *cset;
+
+ cmdset->add(cmd= new cl_state_cmd("state", 0,
+"state State of microcontroller",
+"long help of state"));
+ cmd->init();
+
+ cmdset->add(cmd= new cl_file_cmd("file", 0,
+"file \"FILE\" Load FILE into ROM",
+"long help of file"));
+ cmd->init();
+ cmd->add_name("load");
+
+ cmdset->add(cmd= new cl_dl_cmd("download", 0,
+"download,dl Load (intel.hex) data",
+"long help of download"));
+ cmd->init();
+ cmd->add_name("dl");
+
+ cmdset->add(cmd= new cl_pc_cmd("pc", 0,
+"pc [addr] Set/get PC",
+"long help of pc"));
+ cmd->init();
+
+ cmdset->add(cmd= new cl_reset_cmd("reset", 0,
+"reset Reset",
+"long help of reset"));
+ cmd->init();
+
+ cmdset->add(cmd= new cl_dump_cmd("dump", 0,
+"dump memory_type [start [stop [bytes_per_line]]]\n"
+" Dump memory of specified type\n"
+"dump bit... Dump bits",
+"long help of dump"));
+ cmd->init();
+
+ cmdset->add(cmd= new cl_di_cmd("di", 0,
+"di [start [stop]] Dump Internal RAM",
+"long help of di"));
+ cmd->init();
+
+ cmdset->add(cmd= new cl_dx_cmd("dx", 0,
+"dx [start [stop]] Dump External RAM",
+"long help of dx"));
+ cmd->init();
+
+ cmdset->add(cmd= new cl_ds_cmd("ds", 0,
+"ds [start [stop]] Dump SFR",
+"long help of ds"));
+ cmd->init();
+
+ cmdset->add(cmd= new cl_dch_cmd("dch", 0,
+"dch [start [stop]] Dump code in hex form",
+"long help of dch"));
+ cmd->init();
+
+ cmdset->add(cmd= new cl_dc_cmd("dc", 0,
+"dc [start [stop]] Dump code in disass form",
+"long help of dc"));
+ cmd->init();
+
+ cmdset->add(cmd= new cl_disassemble_cmd("disassemble", 0,
+"disassemble [start [offset [lines]]]\n"
+" Disassemble code",
+"long help of disassemble"));
+ cmd->init();
+
+ cmdset->add(cmd= new cl_fill_cmd("fill", 0,
+"fill memory_type start end data\n"
+" Fill memory region with data",
+"long help of fill"));
+ cmd->init();
+
+ cmdset->add(cmd= new cl_where_cmd("where", 0,
+"where memory_type data...\n"
+" Case unsensitive search for data",
+"long help of where"));
+ cmd->init();
+
+ cmdset->add(cmd= new cl_Where_cmd("Where", 0,
+"Where memory_type data...\n"
+" Case sensitive search for data",
+"long help of Where"));
+ cmd->init();
+
+ cmdset->add(cmd= new cl_break_cmd("break", 0,
+"break addr [hit] Set fix breakpoint\n"
+"break mem_type r|w addr [hit]\n"
+" Set fix event breakpoint",
+"long help of break"));
+ cmd->init();
+
+ cmdset->add(cmd= new cl_tbreak_cmd("tbreak", 0,
+"tbreak addr [hit] Set temporary breakpoint\n"
+"tbreak mem_type r|w addr [hit]\n"
+" Set temporary event breakpoint",
+"long help of tbreak"));
+ cmd->init();
+
+ cmdset->add(cmd= new cl_clear_cmd("clear", 0,
+"clear [addr...] Clear fix breakpoint",
+"long help of clear"));
+ cmd->init();
+
+ cmdset->add(cmd= new cl_delete_cmd("delete", 0,
+"delete [nr...] Delete breakpoint(s)",
+"long help of clear"));
+ cmd->init();
+
+ {
+ cset= new cl_cmdset();
+ cset->init();
+ cset->add(cmd= new cl_get_sfr_cmd("sfr", 0,
+"get sfr address...\n"
+" Get value of addressed SFRs",
+"long help of get sfr"));
+ cmd->init();
+ cset->add(cmd= new cl_get_option_cmd("option", 0,
+"get option name\n"
+" Get value of an option",
+"long help of get option"));
+ cmd->init();
+ }
+ cmdset->add(cmd= new cl_super_cmd("get", 0,
+"get subcommand Get, see `get' command for more help",
+"long help of get", cset));
+ cmd->init();
+
+ {
+ cset= new cl_cmdset();
+ cset->init();
+ cset->add(cmd= new cl_set_mem_cmd("memory", 0,
+"set memory memory_type address data...\n"
+" Place list of data into memory",
+"long help of set memory"));
+ cmd->init();
+ cset->add(cmd= new cl_set_bit_cmd("bit", 0,
+"set bit addr 0|1 Set specified bit to 0 or 1",
+"long help of set bit"));
+ cmd->init();
+ cset->add(cmd= new cl_set_port_cmd("port", 0,
+"set port hw data Set data connected to port",
+"long help of set port"));
+ cmd->init();
+ cset->add(cmd= new cl_set_option_cmd("option", 0,
+"set option name value\n"
+" Set value of an option",
+"long help of set option"));
+ cmd->init();
+ }
+ cmdset->add(cmd= new cl_super_cmd("set", 0,
+"set subcommand Set, see `set' command for more help",
+"long help of set", cset));
+ cmd->init();
+
+ {
+ cset= new cl_cmdset();
+ cset->init();
+ cset->add(cmd= new cl_info_bp_cmd("breakpoints", 0,
+"info breakpoints Status of user-settable breakpoints",
+"long help of info breakpoints"));
+ cmd->add_name("bp");
+ cmd->init();
+ cset->add(cmd= new cl_info_reg_cmd("registers", 0,
+"info registers List of integer registers and their contents",
+"long help of info registers"));
+ cmd->init();
+ cset->add(cmd= new cl_info_hw_cmd("hardware", 0,
+"info hardware cathegory\n"
+" Status of hardware elements of the CPU",
+"long help of info hardware"));
+ cmd->add_name("h w");
+ cmd->init();
+ }
+ cmdset->add(cmd= new cl_super_cmd("info", 0,
+"info subcommand Information, see `info' command for more help",
+"long help of info", cset));
+ cmd->init();
+
+ cmdset->add(cmd= new cl_timer_cmd("timer", 0,
+"timer a|d|g|r|s|v id [direction|value]\n"
+" Timer add|del|get|run|stop|value",
+"timer add|create|make id [direction] -- create a new timer\n"
+"timer del id -- delete a timer\n"
+"timer get id -- list timers\n"
+"timer run id -- turn a timer ON\n"
+"timer stop id -- turn a timer OFF\n"
+"timer value id val -- set value of a timer to `val'"));
+ cmd->init();
+}
+
/*
* Read/write simulated memory
if (!name)
{
- sim->cmd->printf("cl_uc::read_hex_file File name not specified\n");
+ sim->app->get_commander()->
+ printf("cl_uc::read_hex_file File name not specified\n");
return(-1);
}
else
}
}
else
- if (sim->get_iarg('V', 0) &&
+ if (sim->app->args->get_iarg('V', 0) &&
rtyp != 1)
- sim->cmd->printf("Unknown record type %d(0x%x)\n",
- rtyp, rtyp);
+ sim->app->get_commander()->
+ printf("Unknown record type %d(0x%x)\n", rtyp, rtyp);
}
else
- if (sim->get_iarg('V', 0))
- sim->cmd->printf("Checksum error (%x instead of %x) in "
- "record %ld.\n", chk, sum, recnum);
+ if (sim->app->args->get_iarg('V', 0))
+ sim->app->get_commander()->
+ printf("Checksum error (%x instead of %x) in "
+ "record %ld.\n", chk, sum, recnum);
}
else
- if (sim->get_iarg('V', 0))
- sim->cmd->printf("Read error in record %ld.\n", recnum);
+ if (sim->app->args->get_iarg('V', 0))
+ sim->app->get_commander()->
+ printf("Read error in record %ld.\n", recnum);
}
}
if (get_mem_width(MEM_ROM) > 8 &&
if (name)
fclose(f);
- if (sim->get_iarg('V', 0))
- sim->cmd->printf("%ld records have been read\n", recnum);
+ if (sim->app->args->get_iarg('V', 0))
+ sim->app->get_commander()->printf("%ld records have been read\n", recnum);
analyze(0);
return(written);
}
class brk_coll *ebrk; // Collection of EVENT breakpoints
class cl_sim *sim;
class cl_list *mems;
- class cl_list *hws;
+ class cl_hws *hws;
class cl_list *it_sources; // Sources of interrupts
class cl_list *it_levels; // Follow interrupt services
virtual t_addr get_mem_size(enum mem_class type);
virtual int get_mem_width(enum mem_class type);
virtual void mk_hw_elements(void);
+ virtual void build_cmdset(class cl_cmdset *cmdset);
// manipulating memories
virtual ulong read_mem(enum mem_class type, t_addr addr);
int ret;
app= new cl_app();
- app->init();
+ app->init(argc, argv);
ret= app->run();
app->done();
return(ret);
#include "z80cl.h"
-cl_simz80::cl_simz80(class cl_app *the_app,
- char *more_args, int iargc, char *iargv[]):
- cl_sim(the_app, more_args, iargc, iargv)
+cl_simz80::cl_simz80(class cl_app *the_app):
+ cl_sim(the_app)
{}
class cl_uc *
class cl_simz80: public cl_sim
{
public:
- cl_simz80(class cl_app *the_app, char *more_args, int iargc, char *iargv[]);
+ cl_simz80(class cl_app *the_app);
virtual class cl_uc *mk_controller(void);
};
class cl_sim *sim;
app= new cl_app();
- app->init();
- sim= new cl_simz80(app, 0, argc, argv);
+ app->init(argc, argv);
+ sim= new cl_simz80(app);
sim->init();
app->set_simulator(sim);
- sim->main();
+ app->run();
delete app;
return(0);
}