X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=sim%2Fucsim%2Fcmd.src%2Fcmdset.cc;h=8f3523bb3b03c6371bedff9f8ff61edd82b65e46;hb=90f4aedaef8a2310573eef905f95c671f84e5cde;hp=8a659f68b1d2517a68c4cfcab5a14ee13e7e99b4;hpb=1854d0ec377d6032617c09d2bd31fa0866764744;p=fw%2Fsdcc diff --git a/sim/ucsim/cmd.src/cmdset.cc b/sim/ucsim/cmd.src/cmdset.cc index 8a659f68..8f3523bb 100644 --- a/sim/ucsim/cmd.src/cmdset.cc +++ b/sim/ucsim/cmd.src/cmdset.cc @@ -1,5 +1,5 @@ /* - * Simulator of microcontrollers (cmdset.cc) + * Simulator of microcontrollers (cmd.src/cmdset.cc) * * Copyright (C) 1999,99 Drotos Daniel, Talker Bt. * @@ -27,441 +27,437 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "ddconfig.h" -#include "i_string.h" +#include "cmdlexcl.h" +#include "cmdpars.h" -#include "globals.h" +// prj +#include "i_string.h" #include "utils.h" +#include "globals.h" -// sim +// sim.src #include "simcl.h" -// local +// local, cmd.src #include "cmdsetcl.h" +#include "cmdutil.h" /* - * Command: conf + * Command: run *---------------------------------------------------------------------------- */ -int -cl_conf_cmd::do_work(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_base *con) +COMMAND_DO_WORK_SIM(cl_run_cmd) { - int i; + class cl_brk *b; + t_addr start, end; + class cl_cmd_arg *params[4]= { cmdline->param(0), + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; - con->printf("ucsim version %s\n", VERSIONSTR); - con->printf("Type of microcontroller: %s\n", sim->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++) - { - class cl_hw *hw= (class cl_hw *)(sim->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++) + if (params[0]) + if (!(params[0]->get_address(sim->uc, &start))) + { + con->dd_printf("Error: wrong start address\n"); + return(DD_FALSE); + } + if (params[1]) + if (!(params[1]->get_address(sim->uc, &end))) + { + con->dd_printf("Error: wromg end address\n"); + return(DD_FALSE); + } + if (params[0]) { - class cl_mem *mem= (class cl_mem *)(sim->uc->mems->at(i)); - if (mem) - con->printf(" %s size= 0x%06x %d\n", - mem->id_string(), mem->size, mem->size); + if (!sim->uc->inst_at(start)) + con->dd_printf("Warning: maybe not instruction at 0x%06lx\n", start); + sim->uc->PC= start; + if (params[1]) + { + if (start == end) + { + con->dd_printf("Addresses must be different.\n"); + return(DD_FALSE); + } + if ((b= sim->uc->fbrk_at(end))) + { + } + else + { + b= new cl_fetch_brk(sim->uc->address_space(MEM_ROM_ID), + sim->uc->make_new_brknr(), end, + brkDYNAMIC, 1); + sim->uc->fbrk->add_bp(b); + } + } } - return(0); -} + con->dd_printf("Simulation started, PC=0x%06x\n", sim->uc->PC); + if (sim->uc->fbrk_at(sim->uc->PC)) + sim->uc->do_inst(1); - -/* - * Command: state - *---------------------------------------------------------------------------- - */ - -int -cl_state_cmd::do_work(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); + sim->start(con); + return(DD_FALSE); } /* - * Command: file + * Command: stop *---------------------------------------------------------------------------- */ -int -cl_file_cmd::do_work(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_base *con) +COMMAND_DO_WORK_SIM(cl_stop_cmd) { - char *fname; - 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); + sim->stop(resUSER); + sim->uc->print_disass(sim->uc->PC, con); + return(DD_FALSE); } /* - * Command: download + * Command: step *---------------------------------------------------------------------------- */ -int -cl_dl_cmd::do_work(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_base *con) +COMMAND_DO_WORK_UC(cl_step_cmd) { - long l; - - if ((l= sim->uc->read_hex_file(NULL)) >= 0) - con->printf("%ld words loaded\n", l); - + //printf("step %x\n",uc->PC); + uc->do_inst(1); + //printf("step done %x\n",uc->PC); + uc->print_regs(con); return(0); } /* - * Command: get + * Command: next *---------------------------------------------------------------------------- */ -int -cl_get_cmd::do_work(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_base *con) +COMMAND_DO_WORK_SIM(cl_next_cmd) { - char *s; - - if (cmdline->param(0) == 0) - { - con->printf("Get what?\n"); - return(0); - } - if ((s= cmdline->param(0)->get_svalue())) + class cl_brk *b; + t_addr next; + int branch; + int inst_len; + +#if 0 + struct dis_entry *de; + t_mem code= sim->uc->get_mem(MEM_ROM, sim->uc->PC); + int i= 0; + de= &(sim->uc->dis_tbl()[i]); + while ((code & de->mask) != de->code && + de->mnemonic) { - if (strstr(s, "t") == s) - return(timer(cmdline, con)); - else - con->printf("Unknow keyword of get command\n"); + i++; + de= &(sim->uc->dis_tbl()[i]); } - return(0); -} - - -/* - * Command: set - *---------------------------------------------------------------------------- - */ +#endif + branch = sim->uc->inst_branch(sim->uc->PC); + inst_len = sim->uc->inst_length(sim->uc->PC); -int -cl_set_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con) -{ - char *s; - - if (cmdline->param(0) == 0) + if ((branch == 'a') || (branch == 'l')) { - con->printf("Set what?\n"); - return(0); + next= sim->uc->PC + inst_len; + if (!sim->uc->fbrk_at(next)) + { + b= new cl_fetch_brk(sim->uc->address_space(MEM_ROM_ID), + sim->uc->make_new_brknr(), + next, brkDYNAMIC, 1); + + b->init(); +// sim->uc->fbrk->add_bp(b); + + sim->uc->fbrk->add(b); + b->activate(); + } + if (sim->uc->fbrk_at(sim->uc->PC)) + sim->uc->do_inst(1); + sim->start(con); + //sim->uc->do_inst(-1); } - if ((s= cmdline->param(0)->get_svalue())) - { - if (strstr(s, "t") == s) - return(timer(cmdline, con)); - else - con->printf("Unknow keyword of set command\n"); - } - return(0); -} - - -/* - * Command: run - *---------------------------------------------------------------------------- - */ - - -int -cl_run_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con) -{ - sim->start(con); - return(0); -} - - -/* - * Command: step - *---------------------------------------------------------------------------- - */ - - -int -cl_step_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con) -{ - sim->uc->do_inst(1); - sim->uc->print_regs(con); - return(0); -} - - -/* - * Command: reset - *---------------------------------------------------------------------------- - */ - - -int -cl_reset_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con) -{ - sim->uc->reset(); - return(0); + else { + sim->uc->do_inst(1); + sim->uc->print_regs(con); + } + return(DD_FALSE); } /* - * Command: dump + * Command: help *---------------------------------------------------------------------------- */ -int -cl_dump_cmd::do_work(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_base *con) +COMMAND_DO_WORK_APP(cl_help_cmd) { - class cl_mem *mem; - char *s; - long l, start= -1, end= 10*8-1, bpl= 8; - class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; - - if (params[0] == 0) - { - con->printf("Memory type missing\n"); - return(0); - } - if ((s= params[0]->get_svalue())) - { - if (strstr(s, "i") == s) - mem= sim->uc->mem(MEM_IRAM); - else if (strstr(s, "x") == s) - mem= sim->uc->mem(MEM_XRAM); - else if (strstr(s, "r") == s) - mem= sim->uc->mem(MEM_ROM); - else if (strstr(s, "s") == s) - mem= sim->uc->mem(MEM_SFR); - else - { - con->printf("Unknown memory type\n"); - return(0); - } - if (!mem) - { - con->printf("No such memory\n"); - return(0); - } - } + class cl_sim *sim; + class cl_commander_base *commander; + class cl_cmdset *cmdset= 0; + int i; + class cl_cmd_arg *parm= cmdline->param(0); + + sim= app->get_sim(); + if ((commander= app->get_commander()) != 0) + cmdset= commander->cmdset; + if (!cmdset) + return(DD_FALSE); + if (!parm) { + for (i= 0; i < cmdset->count; i++) + { + class cl_cmd *c= (class cl_cmd *)(cmdset->at(i)); + if (c->short_help) + con->dd_printf("%s\n", c->short_help); + else + con->dd_printf("%s\n", (char*)(c->names->at(0))); + } + } else { - con->printf("Wrong memory type\n"); - return(0); + matches= 0; + do_set(cmdline, 0, cmdset, con); + if (matches == 1 && + cmd_found) + { + int names; + con->dd_printf("Names of command:"); + for (names= 0; names < cmd_found->names->count; names++) + con->dd_printf(" %s", (char*)(cmd_found->names->at(names))); + con->dd_printf("\n"); + class cl_cmdset *subset= cmd_found->get_subcommands(); + if (subset) + { + con->dd_printf("\"%s\" must be followed by the name of a " + "subcommand\nList of subcommands:\n", + (char*)(cmd_found->names->at(0))); + for (i= 0; i < subset->count; i++) + { + class cl_cmd *c= + dynamic_cast(subset->object_at(i)); + con->dd_printf("%s\n", c->short_help); + } + } + if (cmd_found->long_help) + con->dd_printf("%s\n", cmd_found->long_help); + } + if (!matches || + !cmd_found) + con->dd_printf("No such command.\n"); + //return(DD_FALSE); + /* + int pari; + for (pari= 0; pari < cmdline->nuof_params(); pari++) + { + class cl_cmd_arg *act_param; + act_param= (class cl_cmd_arg *)(cmdline->param(pari)); + for (i= 0; i < cmdset->count; i++) + { + class cl_cmd *c= (class cl_cmd *)(cmdset->at(i)); + if (!c->name_match(act_param->s_value, DD_FALSE)) + continue; + if (c->short_help) + con->dd_printf("%s\n", c->short_help); + else + con->dd_printf("%s\n", (char*)(c->names->at(0))); + if (pari < cmdline->nuof_params()-1) + continue; + cmdset= c->get_subcommands(); + if (!cmdset) + return(DD_FALSE); + } + } + return(DD_FALSE); + */ } + return(DD_FALSE); + /* + if (cmdline->syntax_match(0, STRING)) { + matches= 0; + for (i= 0; i < cmdset->count; i++) + { + c= (class cl_cmd *)(cmdset->at(i)); + if (c->name_match(parm->value.string.string, DD_FALSE)) + matches++; + } + if (!matches) + con->dd_printf("No such command\n"); + else if (matches > 1) + for (i= 0; i < cmdset->count; i++) + { + c= (class cl_cmd *)(cmdset->at(i)); + if (!c->name_match(parm->value.string.string, DD_FALSE)) + continue; + if (c->short_help) + con->dd_printf("%s\n", c->short_help); + else + con->dd_printf("%s\n", (char*)(c->names->at(0))); + } + else + for (i= 0; i < cmdset->count; i++) + { + c= (class cl_cmd *)(cmdset->at(i)); + if (!c->name_match(parm->value.string.string, DD_FALSE)) + continue; + if (c->short_help) + con->dd_printf("%s\n", c->short_help); + else + con->dd_printf("%s\n", (char*)(c->names->at(0))); + int names; + con->dd_printf("Names of command:"); + for (names= 0; names < c->names->count; names++) + con->dd_printf(" %s", (char*)(c->names->at(names))); + con->dd_printf("\n"); + if (c->long_help) + con->dd_printf("%s\n", c->long_help); + else + con->dd_printf("%s\n", (char*)(c->names->at(0))); + } + } + else + con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax"); - if (params[1]) - { - if ((start= params[1]->get_address()) >= 0) - { - end+= start; - if (params[2]) - { - if ((l= params[2]->get_address()) >= 0) - end= l; - else - { - con->printf("End address is wrong\n"); - return(0); - } - } - } - else - { - con->printf("Start address is wrong\n"); - return(0); - } - } - if (params[3] && - (l= params[3]->get_address()) >= 0) - bpl= l; - mem->dump(start, end, bpl, con); return(0); + */ } - -/* - * Command: di - *---------------------------------------------------------------------------- - */ - -int -cl_di_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con) +bool +cl_help_cmd::do_set(class cl_cmdline *cmdline, int pari, + class cl_cmdset *cmdset, + class cl_console_base *con) { - cmdline->insert_param(0, new cl_cmd_sym_arg("i")); - cl_dump_cmd::do_work(cmdline, con); - return(0); + int i; + for (i= 0; i < cmdset->count; i++) + { + class cl_cmd *cmd= dynamic_cast(cmdset->object_at(i)); + if (!cmd) + continue; + if (pari >= cmdline->nuof_params()) + return(DD_FALSE); + class cl_cmd_arg *param= cmdline->param(pari); + if (!param) + return(DD_FALSE); + class cl_cmdset *next_set= cmd->get_subcommands(); + if (cmd->name_match(param->s_value, DD_FALSE)) + { + if (pari+1 >= cmdline->nuof_params()) + { + matches++; + cmd_found= cmd; + if (cmd->short_help) + con->dd_printf("%s\n", cmd->short_help); + else + con->dd_printf("%s\n", (char*)(cmd->names->at(0))); + //continue; + } + else + if (next_set) + do_set(cmdline, pari+1, next_set, con); + } + } + return(DD_TRUE); } /* - * Command: dx + * Command: quit *---------------------------------------------------------------------------- */ -int -cl_dx_cmd::do_work(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_base */*con*/) +COMMAND_DO_WORK(cl_quit_cmd) { - cmdline->insert_param(0, new cl_cmd_sym_arg("x")); - cl_dump_cmd::do_work(cmdline, con); - return(0); + return(1); } /* - * Command: dch + * Command: kill *---------------------------------------------------------------------------- */ -int -cl_dch_cmd::do_work(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_base */*con*/) +COMMAND_DO_WORK_APP(cl_kill_cmd) { - cmdline->insert_param(0, new cl_cmd_sym_arg("r")); - cl_dump_cmd::do_work(cmdline, con); - return(0); + app->going= 0; + if (app->sim) + app->sim->state|= SIM_QUIT; + return(1); } /* - * Command: ds - *---------------------------------------------------------------------------- + * EXEC file */ -int -cl_ds_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con) +COMMAND_DO_WORK_APP(cl_exec_cmd) { - cmdline->insert_param(0, new cl_cmd_sym_arg("s")); - cl_dump_cmd::do_work(cmdline, con); - return(0); -} - + class cl_cmd_arg *parm= cmdline->param(0); + char *fn= 0; -/* - * Command: dc - *---------------------------------------------------------------------------- - */ - -int -cl_dc_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con) -{ - long i, l, start= last, end= -1; - class cl_cmd_arg *params[2]= { cmdline->param(0), - cmdline->param(1) }; + if (cmdline->syntax_match(0, STRING)) { + fn= parm->value.string.string; + } + else + con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n"); - if (params[0]) + class cl_commander_base *c= app->get_commander(); + class cl_console_base *cons= con->clone_for_exec(fn); + if (cons) { - if ((start= params[0]->get_address()) >= 0) - { - if (params[1]) - { - if ((l= params[1]->get_address()) >= 0) - end= l; - else - { - con->printf("End address is wrong\n"); - return(0); - } - } - } - else - { - con->printf("Start address is wrong\n"); - return(0); - } + cons->flags|= CONS_NOWELCOME; + c->add_console(cons); } - i= 0; - for (l= start; - (end < 0 && i < 20) || l <= end; - l+= sim->uc->inst_length(sim->uc->get_mem(MEM_ROM, l)), i++) - sim->uc->print_disass(l, con); - last= l; - return(0); -} - -/* - * Command: help - *---------------------------------------------------------------------------- - */ - -int -cl_help_cmd::do_work(class cl_cmdline */*cmdline*/, class cl_console *con) -{ - class cl_cmd *c; - int i; - - for (i= 0; i < sim->cmdset->count; i++) - { - c= (class cl_cmd *)(sim->cmdset->at(i)); - if (c->short_help) - con->printf("%s\n", c->short_help); - else - con->printf("%s\n", (char*)(c->names->at(0))); - } - return(0); + return(DD_FALSE); } /* - * Command: quit - *---------------------------------------------------------------------------- + * expression expression */ -int -cl_quit_cmd::do_work(class cl_cmdline */*cmdline*/, class cl_console */*con*/) +COMMAND_DO_WORK_APP(cl_expression_cmd) { - return(1); -} - -/* - * Command: kill - *---------------------------------------------------------------------------- - */ - -int -cl_kill_cmd::do_work(class cl_cmdline */*cmdline*/, class cl_console */*con*/) -{ - sim->state|= SIM_QUIT; - return(1); + //con->dd_printf("\"%s\"\n", cmdline->cmd); + char *s= cmdline->cmd; + if (!s || + !*s) + return(DD_FALSE); + int i= strspn(s, " \t\v\n"); + s+= i; + //con->dd_printf("\"%s\"\n", s); + i= strspn(s, "abcdefghijklmnopqrstuvwxyz"); + s+= i; + //con->dd_printf("\"%s\"\n", s); + class YY_cl_ucsim_parser_CLASS *pars; + class cl_ucsim_lexer *lexer; + lexer= new cl_ucsim_lexer(s); + pars= new YY_cl_ucsim_parser_CLASS(lexer); + pars->yyparse(); + delete pars; + return(DD_FALSE); } -/* End of cmdset.cc */ +/* End of cmd.src/cmdset.cc */