X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=sim%2Fucsim%2Fsim.src%2Fsim.cc;h=982532984692b7ff660bec537436af8e7d9f531f;hb=6ba6105dc5975c3b0cc0d1ce53f47a1ddf4be9cf;hp=73e1d6397aac8f39005692e39ac584c213aa5780;hpb=02d4f3e2b701dcdb88981a3292d226fc818b93b7;p=fw%2Fsdcc 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",