From 6ba6105dc5975c3b0cc0d1ce53f47a1ddf4be9cf Mon Sep 17 00:00:00 2001 From: drdani Date: Mon, 2 Jul 2001 10:39:19 +0000 Subject: [PATCH] Version 0.3.2-pre1 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@993 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- sim/ucsim/.version | 2 +- sim/ucsim/Makefile | 1 + sim/ucsim/README | 11 +- sim/ucsim/avr.src/savr.cc | 4 +- sim/ucsim/avr.src/simavr.cc | 70 +--- sim/ucsim/avr.src/simavrcl.h | 3 +- sim/ucsim/clean.mk | 2 +- sim/ucsim/cmd.src/Makefile.in | 3 +- sim/ucsim/cmd.src/bp.cc | 69 ++-- sim/ucsim/cmd.src/bpcl.h | 10 +- sim/ucsim/cmd.src/cmdconf.cc | 32 +- sim/ucsim/cmd.src/cmdconfcl.h | 4 +- sim/ucsim/cmd.src/cmdgui.cc | 18 +- sim/ucsim/cmd.src/cmdguicl.h | 4 +- sim/ucsim/cmd.src/cmdset.cc | 565 +++------------------------ sim/ucsim/cmd.src/cmdsetcl.h | 55 +-- sim/ucsim/cmd.src/cmduc.cc | 523 +++++++++++++++++++++++++ sim/ucsim/cmd.src/cmduccl.h | 57 +++ sim/ucsim/cmd.src/get.cc | 25 +- sim/ucsim/cmd.src/getcl.h | 11 +- sim/ucsim/cmd.src/info.cc | 35 +- sim/ucsim/cmd.src/infocl.h | 6 +- sim/ucsim/cmd.src/newcmd.cc | 260 +++++++++---- sim/ucsim/cmd.src/newcmdcl.h | 135 +++++-- sim/ucsim/cmd.src/set.cc | 44 ++- sim/ucsim/cmd.src/setcl.h | 8 +- sim/ucsim/cmd.src/show.cc | 14 +- sim/ucsim/cmd.src/timer.cc | 64 ++-- sim/ucsim/cmd.src/timercl.h | 59 +++ sim/ucsim/main_in.mk | 7 +- sim/ucsim/s51.src/s51.cc | 6 +- sim/ucsim/s51.src/sim51.cc | 231 +---------- sim/ucsim/s51.src/sim51cl.h | 4 +- sim/ucsim/s51.src/uc51.cc | 33 +- sim/ucsim/s51.src/uc51r.cc | 13 +- sim/ucsim/sim.src/Makefile.in | 8 +- sim/ucsim/sim.src/app.cc | 400 ++++++++++++++++++- sim/ucsim/sim.src/appcl.h | 18 +- sim/ucsim/sim.src/arg.cc | 160 ++++++-- sim/ucsim/sim.src/argcl.h | 54 ++- sim/ucsim/sim.src/clean.mk | 2 +- sim/ucsim/sim.src/hw.cc | 30 +- sim/ucsim/sim.src/hwcl.h | 13 +- sim/ucsim/sim.src/mem.cc | 145 ++++++- sim/ucsim/sim.src/memcl.h | 58 ++- sim/ucsim/sim.src/option.cc | 24 +- sim/ucsim/sim.src/optioncl.h | 4 +- sim/ucsim/sim.src/sim.cc | 574 ++-------------------------- sim/ucsim/sim.src/simcl.h | 32 +- sim/ucsim/sim.src/test_mem_speed.cc | 60 ++- sim/ucsim/sim.src/uc.cc | 254 +++++++++++- sim/ucsim/sim.src/uccl.h | 3 +- sim/ucsim/ucsim.cc | 2 +- sim/ucsim/z80.src/simz80.cc | 5 +- sim/ucsim/z80.src/simz80cl.h | 2 +- sim/ucsim/z80.src/sz80.cc | 6 +- 56 files changed, 2369 insertions(+), 1873 deletions(-) create mode 100644 sim/ucsim/cmd.src/cmduc.cc create mode 100644 sim/ucsim/cmd.src/cmduccl.h create mode 100644 sim/ucsim/cmd.src/timercl.h diff --git a/sim/ucsim/.version b/sim/ucsim/.version index 0d91a54c..d724e60d 100644 --- a/sim/ucsim/.version +++ b/sim/ucsim/.version @@ -1 +1 @@ -0.3.0 +0.3.2-pre1 diff --git a/sim/ucsim/Makefile b/sim/ucsim/Makefile index 0d029cb4..27fd11df 100644 --- a/sim/ucsim/Makefile +++ b/sim/ucsim/Makefile @@ -173,6 +173,7 @@ echo_freshconf: @echo "FRESHCONF" checkconf: + @echo "CHECKCONF" @if [ -f devel ]; then $(MAKE) freshconf; fi # End of Makefile diff --git a/sim/ucsim/README b/sim/ucsim/README index bfbdefd5..2f0994ef 100644 --- a/sim/ucsim/README +++ b/sim/ucsim/README @@ -9,7 +9,8 @@ What is uCsim? 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? @@ -18,13 +19,13 @@ 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 @@ -32,7 +33,7 @@ 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. @@ -87,7 +88,7 @@ SerialView sdcdb Debugger of the free C compiler, called sdcc written by Sandeep - Dutta . It is a usual debugger with command + Dutta . 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. diff --git a/sim/ucsim/avr.src/savr.cc b/sim/ucsim/avr.src/savr.cc index 6932c2cc..80eb0d43 100644 --- a/sim/ucsim/avr.src/savr.cc +++ b/sim/ucsim/avr.src/savr.cc @@ -41,8 +41,8 @@ main(int argc, char *argv[]) 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(); diff --git a/sim/ucsim/avr.src/simavr.cc b/sim/ucsim/avr.src/simavr.cc index e3372904..58b8d8de 100644 --- a/sim/ucsim/avr.src/simavr.cc +++ b/sim/ucsim/avr.src/simavr.cc @@ -26,7 +26,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA /*@1@*/ -#include +//#include // sim.src #include "appcl.h" @@ -36,74 +36,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #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) { diff --git a/sim/ucsim/avr.src/simavrcl.h b/sim/ucsim/avr.src/simavrcl.h index f0bd4467..70347edf 100644 --- a/sim/ucsim/avr.src/simavrcl.h +++ b/sim/ucsim/avr.src/simavrcl.h @@ -34,8 +34,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 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); }; diff --git a/sim/ucsim/clean.mk b/sim/ucsim/clean.mk index 26371f82..93eefab0 100644 --- a/sim/ucsim/clean.mk +++ b/sim/ucsim/clean.mk @@ -1,7 +1,7 @@ # Deleting all files created by building the program # -------------------------------------------------- clean: - rm -f *core *[%~] *.[oa] *.so + rm -f *core *[%~] *.[oa] *.so ucsim rm -f .[a-z]*~ diff --git a/sim/ucsim/cmd.src/Makefile.in b/sim/ucsim/cmd.src/Makefile.in index 89f0361d..85b49406 100644 --- a/sim/ucsim/cmd.src/Makefile.in +++ b/sim/ucsim/cmd.src/Makefile.in @@ -35,7 +35,8 @@ infodir = @infodir@ 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 diff --git a/sim/ucsim/cmd.src/bp.cc b/sim/ucsim/cmd.src/bp.cc index 7318c6c8..19c3e767 100644 --- a/sim/ucsim/cmd.src/bp.cc +++ b/sim/ucsim/cmd.src/bp.cc @@ -43,9 +43,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA * 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; @@ -56,29 +57,29 @@ cl_break_cmd::do_work(class cl_sim *sim, 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 { @@ -89,7 +90,7 @@ cl_break_cmd::do_work(class cl_sim *sim, } 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) @@ -97,30 +98,30 @@ cl_break_cmd::do_fetch(class cl_sim *sim, 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"); } @@ -130,12 +131,13 @@ cl_break_cmd::do_event(class cl_sim *sim, * 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) { @@ -144,7 +146,7 @@ cl_clear_cmd::do_work(class cl_sim *sim, 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); } @@ -153,13 +155,13 @@ cl_clear_cmd::do_work(class cl_sim *sim, 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); @@ -170,14 +172,15 @@ cl_clear_cmd::do_work(class cl_sim *sim, * 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 { @@ -187,7 +190,7 @@ cl_delete_cmd::do_work(class cl_sim *sim, { long num; if (param->get_ivalue(&num)) - sim->uc->rm_brk(num); + uc->rm_brk(num); } } return(DD_FALSE); diff --git a/sim/ucsim/cmd.src/bpcl.h b/sim/ucsim/cmd.src/bpcl.h index cc09badf..ecf43952 100644 --- a/sim/ucsim/cmd.src/bpcl.h +++ b/sim/ucsim/cmd.src/bpcl.h @@ -35,10 +35,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 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; @@ -55,10 +55,10 @@ public: }; // CLEAR -COMMAND(cl_clear_cmd); +COMMAND_ON(uc,cl_clear_cmd); // DELETE -COMMAND(cl_delete_cmd); +COMMAND_ON(uc,cl_delete_cmd); #endif diff --git a/sim/ucsim/cmd.src/cmdconf.cc b/sim/ucsim/cmd.src/cmdconf.cc index 6afd4cab..3f69ef72 100644 --- a/sim/ucsim/cmd.src/cmdconf.cc +++ b/sim/ucsim/cmd.src/cmdconf.cc @@ -41,25 +41,26 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA *---------------------------------------------------------------------------- */ -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, @@ -73,9 +74,10 @@ cl_conf_cmd::do_work(class cl_sim *sim, *---------------------------------------------------------------------------- */ -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), @@ -84,17 +86,17 @@ cl_conf_addmem_cmd::do_work(class cl_sim *sim, 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); diff --git a/sim/ucsim/cmd.src/cmdconfcl.h b/sim/ucsim/cmd.src/cmdconfcl.h index 7be05298..9be11ca2 100644 --- a/sim/ucsim/cmd.src/cmdconfcl.h +++ b/sim/ucsim/cmd.src/cmdconfcl.h @@ -32,10 +32,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA // 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 diff --git a/sim/ucsim/cmd.src/cmdgui.cc b/sim/ucsim/cmd.src/cmdgui.cc index 80eb0ebd..96d77951 100644 --- a/sim/ucsim/cmd.src/cmdgui.cc +++ b/sim/ucsim/cmd.src/cmdgui.cc @@ -42,9 +42,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA *---------------------------------------------------------------------------- */ -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; @@ -54,10 +55,10 @@ cl_gui_start_cmd::do_work(class cl_sim *sim, 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; @@ -77,9 +78,10 @@ cl_gui_start_cmd::do_work(class cl_sim *sim, *---------------------------------------------------------------------------- */ -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);; } diff --git a/sim/ucsim/cmd.src/cmdguicl.h b/sim/ucsim/cmd.src/cmdguicl.h index f4c7fc9a..2a090804 100644 --- a/sim/ucsim/cmd.src/cmdguicl.h +++ b/sim/ucsim/cmd.src/cmdguicl.h @@ -32,10 +32,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA // 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 diff --git a/sim/ucsim/cmd.src/cmdset.cc b/sim/ucsim/cmd.src/cmdset.cc index 445e824d..59d6b2f4 100644 --- a/sim/ucsim/cmd.src/cmdset.cc +++ b/sim/ucsim/cmd.src/cmdset.cc @@ -27,104 +27,28 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #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; @@ -134,13 +58,13 @@ cl_run_cmd::do_work(class cl_sim *sim, 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); @@ -181,9 +105,10 @@ cl_run_cmd::do_work(class cl_sim *sim, *---------------------------------------------------------------------------- */ -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); @@ -196,12 +121,13 @@ cl_stop_cmd::do_work(class cl_sim *sim, *---------------------------------------------------------------------------- */ -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); } @@ -211,9 +137,10 @@ cl_step_cmd::do_work(class cl_sim *sim, *---------------------------------------------------------------------------- */ -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; @@ -248,436 +175,52 @@ cl_next_cmd::do_work(class cl_sim *sim, } -/* - * 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) @@ -686,9 +229,9 @@ cl_help_cmd::do_work(class cl_sim *sim, 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) @@ -718,9 +261,10 @@ cl_help_cmd::do_work(class cl_sim *sim, *---------------------------------------------------------------------------- */ -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); } @@ -731,11 +275,14 @@ cl_quit_cmd::do_work(class cl_sim *sim, *---------------------------------------------------------------------------- */ -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); } diff --git a/sim/ucsim/cmd.src/cmdsetcl.h b/sim/ucsim/cmd.src/cmdsetcl.h index 36beba0d..3dbd22e9 100644 --- a/sim/ucsim/cmd.src/cmdsetcl.h +++ b/sim/ucsim/cmd.src/cmdsetcl.h @@ -31,56 +31,13 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #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 diff --git a/sim/ucsim/cmd.src/cmduc.cc b/sim/ucsim/cmd.src/cmduc.cc new file mode 100644 index 00000000..0bd30a98 --- /dev/null +++ b/sim/ucsim/cmd.src/cmduc.cc @@ -0,0 +1,523 @@ +/* + * 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 */ diff --git a/sim/ucsim/cmd.src/cmduccl.h b/sim/ucsim/cmd.src/cmduccl.h new file mode 100644 index 00000000..8b7012f7 --- /dev/null +++ b/sim/ucsim/cmd.src/cmduccl.h @@ -0,0 +1,57 @@ +/* + * 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 */ diff --git a/sim/ucsim/cmd.src/get.cc b/sim/ucsim/cmd.src/get.cc index 34c99585..b3183da8 100644 --- a/sim/ucsim/cmd.src/get.cc +++ b/sim/ucsim/cmd.src/get.cc @@ -28,6 +28,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "ddconfig.h" #include +#include "i_string.h" // sim #include "simcl.h" @@ -44,11 +45,12 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA *---------------------------------------------------------------------------- */ -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; @@ -61,7 +63,7 @@ cl_get_sfr_cmd::do_work(class cl_sim *sim, 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 @@ -77,25 +79,26 @@ cl_get_sfr_cmd::do_work(class cl_sim *sim, *---------------------------------------------------------------------------- */ -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)) { diff --git a/sim/ucsim/cmd.src/getcl.h b/sim/ucsim/cmd.src/getcl.h index cc4908b5..865a9806 100644 --- a/sim/ucsim/cmd.src/getcl.h +++ b/sim/ucsim/cmd.src/getcl.h @@ -32,7 +32,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA // 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, @@ -43,10 +43,11 @@ public: 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, @@ -57,8 +58,8 @@ public: 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 diff --git a/sim/ucsim/cmd.src/info.cc b/sim/ucsim/cmd.src/info.cc index 0b7561b7..3c493589 100644 --- a/sim/ucsim/cmd.src/info.cc +++ b/sim/ucsim/cmd.src/info.cc @@ -39,27 +39,28 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA * 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, @@ -80,11 +81,12 @@ cl_info_bp_cmd::do_work(class cl_sim *sim, * 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); } @@ -93,9 +95,10 @@ cl_info_reg_cmd::do_work(class cl_sim *sim, * 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), @@ -103,7 +106,7 @@ cl_info_hw_cmd::do_work(class cl_sim *sim, 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); } diff --git a/sim/ucsim/cmd.src/infocl.h b/sim/ucsim/cmd.src/infocl.h index bb0fa2c5..ea460a0d 100644 --- a/sim/ucsim/cmd.src/infocl.h +++ b/sim/ucsim/cmd.src/infocl.h @@ -32,13 +32,13 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA // 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 diff --git a/sim/ucsim/cmd.src/newcmd.cc b/sim/ucsim/cmd.src/newcmd.cc index a0107318..8878c617 100644 --- a/sim/ucsim/cmd.src/newcmd.cc +++ b/sim/ucsim/cmd.src/newcmd.cc @@ -100,8 +100,11 @@ cmd_do_print(FILE *f, char *format, va_list ap) *____________________________________________________________________________ */ -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); @@ -139,9 +142,12 @@ cl_cmdline::skip_delims(char *start) 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) @@ -194,7 +200,8 @@ cl_cmdline::split(void) 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++; @@ -217,10 +224,15 @@ cl_cmdline::split(void) *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; @@ -230,11 +242,17 @@ cl_cmdline::split(void) 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) @@ -244,10 +262,15 @@ cl_cmdline::split(void) *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; @@ -273,24 +296,32 @@ cl_cmdline::split(void) 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); } @@ -348,7 +379,7 @@ cl_cmdline::insert_param(int pos, class cl_cmd_arg *param) } 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); @@ -371,7 +402,7 @@ cl_cmdline::syntax_match(class cl_sim *sim, char *syntax) 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; @@ -384,12 +415,12 @@ cl_cmdline::syntax_match(class cl_sim *sim, char *syntax) 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: @@ -401,7 +432,7 @@ cl_cmdline::syntax_match(class cl_sim *sim, char *syntax) return(DD_FALSE); break; case SY_BIT: - if (!parm->as_bit(sim->uc)) + if (!parm->as_bit(uc)) return(DD_FALSE); break; default: @@ -483,14 +514,14 @@ cl_cmdline::set_data_list(class cl_cmd_arg *parm, int *iparm) *____________________________________________________________________________ */ -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; @@ -566,19 +597,75 @@ cl_cmd::syntax_ok(class cl_cmdline *cmdline) } 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); } @@ -588,13 +675,20 @@ cl_cmd::do_work(class cl_sim *sim, *____________________________________________________________________________ */ -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) { @@ -684,13 +778,12 @@ cl_cmdset::replace(char *name, class cl_cmd *cmd) *____________________________________________________________________________ */ -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; } @@ -702,7 +795,7 @@ cl_super_cmd::~cl_super_cmd(void) } 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; @@ -713,7 +806,7 @@ cl_super_cmd::work(class cl_sim *sim, 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))); @@ -730,7 +823,7 @@ cl_super_cmd::work(class cl_sim *sim, cmdline->name, (char*)(names->at(0))); return(0); } - return(cmd->work(sim, cmdline, con)); + return(cmd->work(app, cmdline, con)); } @@ -739,13 +832,13 @@ cl_super_cmd::work(class cl_sim *sim, *____________________________________________________________________________ */ -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) @@ -763,11 +856,11 @@ cl_console::cl_console(char *fin, char *fout, class cl_sim *asim): 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; @@ -802,12 +895,12 @@ connect_to_port(int portnum) 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+"))) @@ -855,8 +948,8 @@ cl_console::welcome(void) { 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", @@ -874,11 +967,11 @@ cl_console::print_prompt(void) 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); } @@ -985,7 +1078,7 @@ cl_console::read_line(void) } int -cl_console::proc_input(class cl_app *app, class cl_cmdset *cmdset) +cl_console::proc_input(class cl_cmdset *cmdset) { int retval= 0; @@ -999,7 +1092,7 @@ cl_console::proc_input(class cl_app *app, class cl_cmdset *cmdset) return(1); if (flags & CONS_FROZEN) { - sim->stop(resUSER); + app->get_sim()->stop(resUSER); flags&= ~CONS_FROZEN; retval= 0; } @@ -1007,16 +1100,11 @@ cl_console::proc_input(class cl_app *app, class cl_cmdset *cmdset) { 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); @@ -1036,7 +1124,7 @@ cl_console::proc_input(class cl_app *app, class cl_cmdset *cmdset) int cl_console::interpret(char *cmd) { - fprintf(out, "New interpreter does not known this command\n"); + fprintf(out, "Unknown command\n"); return(0); } @@ -1046,10 +1134,10 @@ cl_console::interpret(char *cmd) */ #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) @@ -1077,7 +1165,9 @@ cl_listen_console::proc_input(class cl_cmdset *cmdset) 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) @@ -1089,10 +1179,9 @@ cl_listen_console::proc_input(class cl_cmdset *cmdset) 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); } @@ -1105,34 +1194,39 @@ cl_listen_console::proc_input(class cl_cmdset *cmdset) *____________________________________________________________________________ */ -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); } @@ -1143,22 +1237,22 @@ cl_commander::~cl_commander(void) } 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 @@ -1361,7 +1455,7 @@ cl_commander::proc_input(void) 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); diff --git a/sim/ucsim/cmd.src/newcmdcl.h b/sim/ucsim/cmd.src/newcmdcl.h index c0693331..8cc91379 100644 --- a/sim/ucsim/cmd.src/newcmdcl.h +++ b/sim/ucsim/cmd.src/newcmdcl.h @@ -36,8 +36,12 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA # include HEADER_FD #endif +// prj #include "pobjcl.h" +// sim.src +#include "appcl.h" + #define SY_ADDR 'a' #define ADDRESS "a" @@ -56,6 +60,14 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #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 */ @@ -63,6 +75,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA class cl_cmdline: cl_base { public: + class cl_app *app; char *cmd; char *name; class cl_list *params; @@ -71,7 +84,7 @@ public: 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); @@ -80,7 +93,7 @@ public: 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); @@ -95,14 +108,14 @@ private: 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, @@ -113,10 +126,15 @@ public: 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) \ @@ -130,38 +148,68 @@ class CLASS_NAME : public ANCESTOR \ 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) \ @@ -170,16 +218,38 @@ public: 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); @@ -194,15 +264,14 @@ public: 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); }; @@ -217,17 +286,17 @@ class cl_console: public cl_base 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); @@ -240,7 +309,7 @@ public: 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); }; @@ -250,7 +319,7 @@ class cl_listen_console: public cl_console 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) {} @@ -273,22 +342,20 @@ public: 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); diff --git a/sim/ucsim/cmd.src/set.cc b/sim/ucsim/cmd.src/set.cc index a00d1b9f..4389e3fc 100644 --- a/sim/ucsim/cmd.src/set.cc +++ b/sim/ucsim/cmd.src/set.cc @@ -43,9 +43,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA *---------------------------------------------------------------------------- */ -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), @@ -53,7 +54,7 @@ cl_set_mem_cmd::do_work(class cl_sim *sim, 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; @@ -84,9 +85,10 @@ cl_set_mem_cmd::do_work(class cl_sim *sim, *---------------------------------------------------------------------------- */ -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; @@ -96,7 +98,7 @@ cl_set_bit_cmd::do_work(class cl_sim *sim, 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; @@ -118,9 +120,10 @@ cl_set_bit_cmd::do_work(class cl_sim *sim, *---------------------------------------------------------------------------- */ -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; @@ -129,12 +132,12 @@ cl_set_port_cmd::do_work(class cl_sim *sim, 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; } @@ -144,7 +147,7 @@ cl_set_port_cmd::do_work(class cl_sim *sim, pn > 3) con->printf("Error: wrong port\n"); else - sim->uc->port_pins[pn]= l; + uc->port_pins[pn]= l; return(DD_FALSE);; } @@ -154,9 +157,10 @@ cl_set_port_cmd::do_work(class cl_sim *sim, *---------------------------------------------------------------------------- */ -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), @@ -164,7 +168,7 @@ cl_set_option_cmd::do_work(class cl_sim *sim, 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; } @@ -178,9 +182,9 @@ cl_set_option_cmd::do_work(class cl_sim *sim, } 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); diff --git a/sim/ucsim/cmd.src/setcl.h b/sim/ucsim/cmd.src/setcl.h index 057ec3a4..7ffc58fc 100644 --- a/sim/ucsim/cmd.src/setcl.h +++ b/sim/ucsim/cmd.src/setcl.h @@ -32,16 +32,16 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA // 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 diff --git a/sim/ucsim/cmd.src/show.cc b/sim/ucsim/cmd.src/show.cc index 02ba10b3..6a734cc8 100644 --- a/sim/ucsim/cmd.src/show.cc +++ b/sim/ucsim/cmd.src/show.cc @@ -42,9 +42,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA *---------------------------------------------------------------------------- */ -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);; @@ -56,9 +57,10 @@ cl_show_copying_cmd::do_work(class cl_sim *sim, *---------------------------------------------------------------------------- */ -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);; diff --git a/sim/ucsim/cmd.src/timer.cc b/sim/ucsim/cmd.src/timer.cc index 694c43da..7f47b094 100644 --- a/sim/ucsim/cmd.src/timer.cc +++ b/sim/ucsim/cmd.src/timer.cc @@ -34,8 +34,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "simcl.h" // local -#include "cmdsetcl.h" -#include "newcmdcl.h" +#include "timercl.h" /* @@ -43,9 +42,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA *---------------------------------------------------------------------------- */ -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; @@ -64,21 +64,21 @@ cl_timer_cmd::do_work(class cl_sim *sim, 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); @@ -87,14 +87,14 @@ cl_timer_cmd::do_work(class cl_sim *sim, } 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); } /* @@ -102,7 +102,7 @@ cl_timer_cmd::set_ticker(class cl_sim *sim, */ 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), @@ -141,12 +141,12 @@ cl_timer_cmd::add(class cl_sim *sim, 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); @@ -157,7 +157,7 @@ cl_timer_cmd::add(class cl_sim *sim, */ 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) @@ -169,9 +169,9 @@ cl_timer_cmd::del(class cl_sim *sim, 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); } @@ -181,21 +181,21 @@ cl_timer_cmd::del(class cl_sim *sim, */ 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); } } @@ -207,7 +207,7 @@ cl_timer_cmd::get(class cl_sim *sim, */ 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) @@ -228,7 +228,7 @@ cl_timer_cmd::run(class cl_sim *sim, */ 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) @@ -250,7 +250,7 @@ cl_timer_cmd::stop(class cl_sim *sim, */ 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), diff --git a/sim/ucsim/cmd.src/timercl.h b/sim/ucsim/cmd.src/timercl.h new file mode 100644 index 00000000..2666f37a --- /dev/null +++ b/sim/ucsim/cmd.src/timercl.h @@ -0,0 +1,59 @@ +/* + * 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 */ diff --git a/sim/ucsim/main_in.mk b/sim/ucsim/main_in.mk index b9e4c989..1a1de049 100644 --- a/sim/ucsim/main_in.mk +++ b/sim/ucsim/main_in.mk @@ -23,7 +23,9 @@ CFLAGS = @CFLAGS@ -I$(PRJDIR) -Wall 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@ @@ -103,7 +105,8 @@ libutil.a: $(OBJECTS) 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: diff --git a/sim/ucsim/s51.src/s51.cc b/sim/ucsim/s51.src/s51.cc index 50a80e0a..f59b8f6a 100644 --- a/sim/ucsim/s51.src/s51.cc +++ b/sim/ucsim/s51.src/s51.cc @@ -46,12 +46,12 @@ main(int argc, char *argv[]) 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); diff --git a/sim/ucsim/s51.src/sim51.cc b/sim/ucsim/s51.src/sim51.cc index 811c862c..8a7eb973 100644 --- a/sim/ucsim/s51.src/sim51.cc +++ b/sim/ucsim/s51.src/sim51.cc @@ -36,9 +36,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "globals.h" #include "utils.h" #include "cmdutil.h" -#ifdef SOCKET_AVAIL -#include -#endif #include "sim51cl.h" //#include "cmd51cl.h" @@ -50,228 +47,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #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 - 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) @@ -279,10 +58,10 @@ 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) { diff --git a/sim/ucsim/s51.src/sim51cl.h b/sim/ucsim/s51.src/sim51cl.h index 0365ab1d..8a3d0dbb 100644 --- a/sim/ucsim/s51.src/sim51cl.h +++ b/sim/ucsim/s51.src/sim51cl.h @@ -34,8 +34,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 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); }; diff --git a/sim/ucsim/s51.src/uc51.cc b/sim/ucsim/s51.src/uc51.cc index 8f64eb2a..211bae73 100644 --- a/sim/ucsim/s51.src/uc51.cc +++ b/sim/ucsim/s51.src/uc51.cc @@ -68,16 +68,16 @@ t_uc51::t_uc51(int Itype, int Itech, class cl_sim *asim): 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 @@ -927,12 +927,12 @@ t_uc51::do_inst(int step) 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) && @@ -946,7 +946,7 @@ t_uc51::do_inst(int step) 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; @@ -975,8 +975,8 @@ t_uc51::post_inst(void) !(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); } @@ -1438,8 +1438,8 @@ t_uc51::do_interrupt(void) } 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)); @@ -1490,15 +1490,17 @@ t_uc51::idle_pd(void) 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; } @@ -1540,7 +1542,8 @@ t_uc51::inst_unknown(uchar code) { 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); } diff --git a/sim/ucsim/s51.src/uc51r.cc b/sim/ucsim/s51.src/uc51r.cc index 7ce5ecdf..f3f9da63 100644 --- a/sim/ucsim/s51.src/uc51r.cc +++ b/sim/ucsim/s51.src/uc51r.cc @@ -110,9 +110,9 @@ t_uc51r::proc_write(uchar *addr) (*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; } @@ -370,12 +370,11 @@ t_uc51r::do_wdt(int cycles) 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); } diff --git a/sim/ucsim/sim.src/Makefile.in b/sim/ucsim/sim.src/Makefile.in index 8eeeb05a..f02164b2 100644 --- a/sim/ucsim/sim.src/Makefile.in +++ b/sim/ucsim/sim.src/Makefile.in @@ -40,10 +40,10 @@ OBJECTS = app.o sim.o itsrc.o brk.o option.o arg.o stack.o \ # 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 @@ -73,6 +73,8 @@ installcheck: installdirs: +test: test_mem_speed + # Creating dependencies # --------------------- dep: main.dep diff --git a/sim/ucsim/sim.src/app.cc b/sim/ucsim/sim.src/app.cc index 873bab17..433f9a32 100644 --- a/sim/ucsim/sim.src/app.cc +++ b/sim/ucsim/sim.src/app.cc @@ -25,17 +25,33 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*@1@*/ +#include "ddconfig.h" + #include #include +#include +#ifdef HAVE_GETOPT_H +# include +#endif +#ifdef SOCKET_AVAIL +#include +#endif +#include +#include +#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" /* @@ -92,19 +108,31 @@ cl_app::cl_app(void) { //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); } @@ -113,6 +141,32 @@ cl_app::init(void) 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); } @@ -122,6 +176,283 @@ cl_app::done(void) } +/* + * 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 + 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 * @@ -152,9 +483,62 @@ cl_app::remove_simulator(void) } 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(); } diff --git a/sim/ucsim/sim.src/appcl.h b/sim/ucsim/sim.src/appcl.h index 610eba30..b5e8a263 100644 --- a/sim/ucsim/sim.src/appcl.h +++ b/sim/ucsim/sim.src/appcl.h @@ -30,8 +30,12 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "ddconfig.h" +// prj #include "pobjcl.h" +// local, sim.src +#include "argcl.h" + /* Options */ @@ -72,20 +76,28 @@ public: 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: diff --git a/sim/ucsim/sim.src/arg.cc b/sim/ucsim/sim.src/arg.cc index 4a79f747..fe2e6811 100644 --- a/sim/ucsim/sim.src/arg.cc +++ b/sim/ucsim/sim.src/arg.cc @@ -128,9 +128,9 @@ cl_cmd_arg::~cl_cmd_arg(void) } 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 @@ -149,7 +149,7 @@ cl_cmd_arg::as_data(void) } 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); @@ -189,12 +189,12 @@ cl_cmd_arg::as_bit(class cl_uc *uc) /* 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; @@ -212,7 +212,7 @@ cl_cmd_int_arg::get_bit_address(class cl_uc *uc, // input { 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)); } @@ -229,8 +229,8 @@ cl_cmd_int_arg::as_string(void) /* 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 @@ -245,7 +245,7 @@ cl_cmd_sym_arg::as_string(void) } 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; @@ -276,7 +276,7 @@ cl_cmd_sym_arg::get_bit_address(class cl_uc *uc, // input } 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()); @@ -308,16 +308,16 @@ cl_cmd_sym_arg::as_hw(class cl_uc *uc) /* 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; @@ -332,10 +332,10 @@ cl_cmd_bit_arg::~cl_cmd_bit_arg(void) } 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); } @@ -345,43 +345,34 @@ cl_cmd_bit_arg::get_bit_address(class cl_uc *uc, // input 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; @@ -404,7 +395,7 @@ cl_cmd_array_arg::as_hw(class cl_uc *uc) 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); @@ -452,4 +443,113 @@ cl_prg_arg::~cl_prg_arg(void) } +/* + * 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 */ diff --git a/sim/ucsim/sim.src/argcl.h b/sim/ucsim/sim.src/argcl.h index 91d1f715..5bc0bbbe 100644 --- a/sim/ucsim/sim.src/argcl.h +++ b/sim/ucsim/sim.src/argcl.h @@ -28,7 +28,9 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #ifndef SIM_ARGCL_HEADER #define SIM_ARGCL_HEADER +// prj #include "pobjcl.h" +#include "stypes.h" /* @@ -70,7 +72,7 @@ public: class cl_cmd_arg: public cl_arg { public: - class cl_uc *uc; + //class cl_uc *uc; bool interpreted_as_string; union { @@ -95,19 +97,19 @@ public: } 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); }; @@ -115,9 +117,9 @@ public: 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, @@ -128,14 +130,14 @@ public: 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); }; @@ -143,7 +145,7 @@ public: 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); } }; @@ -154,11 +156,11 @@ public: 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, @@ -171,7 +173,7 @@ public: 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); @@ -197,6 +199,24 @@ public: }; +/* + * 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 */ diff --git a/sim/ucsim/sim.src/clean.mk b/sim/ucsim/sim.src/clean.mk index 74b12cbe..89e54335 100644 --- a/sim/ucsim/sim.src/clean.mk +++ b/sim/ucsim/sim.src/clean.mk @@ -1,7 +1,7 @@ # Deleting all files created by building the program # -------------------------------------------------- clean: - rm -f *core *[%~] *.[oa] + rm -f *core *[%~] *.[oa] test_mem_speed rm -f .[a-z]*~ diff --git a/sim/ucsim/sim.src/hw.cc b/sim/ucsim/sim.src/hw.cc index 210c8078..ab0f5cfb 100644 --- a/sim/ucsim/sim.src/hw.cc +++ b/sim/ucsim/sim.src/hw.cc @@ -58,15 +58,15 @@ cl_hw::~cl_hw(void) * 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 } @@ -89,4 +89,28 @@ cl_hw::print_info(class cl_console *con) } +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 */ diff --git a/sim/ucsim/sim.src/hwcl.h b/sim/ucsim/sim.src/hwcl.h index 297ffb98..daf35b63 100644 --- a/sim/ucsim/sim.src/hwcl.h +++ b/sim/ucsim/sim.src/hwcl.h @@ -51,13 +51,22 @@ public: 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 diff --git a/sim/ucsim/sim.src/mem.cc b/sim/ucsim/sim.src/mem.cc index 11c20563..0bb7e6d2 100644 --- a/sim/ucsim/sim.src/mem.cc +++ b/sim/ucsim/sim.src/mem.cc @@ -130,18 +130,155 @@ cl_memloc_coll::get_loc(t_addr address) /* */ -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 ****************************************************************************** diff --git a/sim/ucsim/sim.src/memcl.h b/sim/ucsim/sim.src/memcl.h index 2ccd3bf3..85f9462d 100644 --- a/sim/ucsim/sim.src/memcl.h +++ b/sim/ucsim/sim.src/memcl.h @@ -63,17 +63,6 @@ public: 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 @@ -138,6 +127,53 @@ public: ~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 diff --git a/sim/ucsim/sim.src/option.cc b/sim/ucsim/sim.src/option.cc index ff151da1..2b237a3a 100644 --- a/sim/ucsim/sim.src/option.cc +++ b/sim/ucsim/sim.src/option.cc @@ -112,19 +112,19 @@ cl_bool_opt::set_value(char *s) * 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"); @@ -133,20 +133,20 @@ cl_cons_debug_opt::print(class cl_console *con) 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; } } @@ -157,15 +157,15 @@ cl_cons_debug_opt::set_value(char *s) 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; } } diff --git a/sim/ucsim/sim.src/optioncl.h b/sim/ucsim/sim.src/optioncl.h index bdbe15c4..5ee8d7e8 100644 --- a/sim/ucsim/sim.src/optioncl.h +++ b/sim/ucsim/sim.src/optioncl.h @@ -71,9 +71,9 @@ public: 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); diff --git a/sim/ucsim/sim.src/sim.cc b/sim/ucsim/sim.src/sim.cc index 73e1d639..98253298 100644 --- a/sim/ucsim/sim.src/sim.cc +++ b/sim/ucsim/sim.src/sim.cc @@ -30,11 +30,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include -#include -#include -#ifdef HAVE_GETOPT_H -# include -#endif #include "i_string.h" // prj @@ -42,77 +37,35 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA // 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); } @@ -122,262 +75,12 @@ cl_sim::~cl_sim(void) 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 @@ -394,20 +97,28 @@ cl_sim::main(void) 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) { @@ -431,13 +142,15 @@ cl_sim::start(class cl_console *con) { 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) { @@ -490,127 +203,11 @@ cl_sim::stop(int reason) */ 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")); @@ -635,131 +232,8 @@ cl_sim::build_cmd_set(class cl_cmdset *cmdset) 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", diff --git a/sim/ucsim/sim.src/simcl.h b/sim/ucsim/sim.src/simcl.h index 9a7b0f29..d3e293d1 100644 --- a/sim/ucsim/sim.src/simcl.h +++ b/sim/ucsim/sim.src/simcl.h @@ -46,48 +46,30 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 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); }; diff --git a/sim/ucsim/sim.src/test_mem_speed.cc b/sim/ucsim/sim.src/test_mem_speed.cc index 05a046ac..d2359fdf 100644 --- a/sim/ucsim/sim.src/test_mem_speed.cc +++ b/sim/ucsim/sim.src/test_mem_speed.cc @@ -1,18 +1,66 @@ +#include +#include +#include + #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); } diff --git a/sim/ucsim/sim.src/uc.cc b/sim/ucsim/sim.src/uc.cc index d3293fd1..09a41fbf 100644 --- a/sim/ucsim/sim.src/uc.cc +++ b/sim/ucsim/sim.src/uc.cc @@ -33,9 +33,20 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #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" @@ -102,7 +113,7 @@ cl_uc::cl_uc(class cl_sim *asim): 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); @@ -140,14 +151,14 @@ cl_uc::~cl_uc(void) 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, @@ -160,6 +171,19 @@ cl_uc::init(void) 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); } @@ -238,6 +262,201 @@ cl_uc::mk_hw_elements(void) { } +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 @@ -407,7 +626,8 @@ cl_uc::read_hex_file(const char *name) 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 @@ -477,19 +697,21 @@ cl_uc::read_hex_file(const char *name) } } 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 && @@ -498,8 +720,8 @@ cl_uc::read_hex_file(const char *name) 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); } diff --git a/sim/ucsim/sim.src/uccl.h b/sim/ucsim/sim.src/uccl.h index efa9045a..c969e1ce 100644 --- a/sim/ucsim/sim.src/uccl.h +++ b/sim/ucsim/sim.src/uccl.h @@ -83,7 +83,7 @@ public: 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 @@ -104,6 +104,7 @@ public: 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); diff --git a/sim/ucsim/ucsim.cc b/sim/ucsim/ucsim.cc index 145b799b..81dea596 100644 --- a/sim/ucsim/ucsim.cc +++ b/sim/ucsim/ucsim.cc @@ -34,7 +34,7 @@ main(int argc, char *argv[]) int ret; app= new cl_app(); - app->init(); + app->init(argc, argv); ret= app->run(); app->done(); return(ret); diff --git a/sim/ucsim/z80.src/simz80.cc b/sim/ucsim/z80.src/simz80.cc index 5da4084f..14f89cf2 100644 --- a/sim/ucsim/z80.src/simz80.cc +++ b/sim/ucsim/z80.src/simz80.cc @@ -31,9 +31,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #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 * diff --git a/sim/ucsim/z80.src/simz80cl.h b/sim/ucsim/z80.src/simz80cl.h index 9ccaa6bb..d9b7ea1f 100644 --- a/sim/ucsim/z80.src/simz80cl.h +++ b/sim/ucsim/z80.src/simz80cl.h @@ -34,7 +34,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 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); }; diff --git a/sim/ucsim/z80.src/sz80.cc b/sim/ucsim/z80.src/sz80.cc index 5de66781..86aab983 100644 --- a/sim/ucsim/z80.src/sz80.cc +++ b/sim/ucsim/z80.src/sz80.cc @@ -39,11 +39,11 @@ main(int argc, char *argv[]) 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); } -- 2.30.2