/*
- * Simulator of microcontrollers (cmdset.cc)
+ * Simulator of microcontrollers (cmd.src/cmdset.cc)
*
* Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
*
#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"
-
-
-/*
- * Command: conf
- *----------------------------------------------------------------------------
- */
-
-int
-cl_conf_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
-{
- int i;
-
- 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++)
- {
- 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);
- }
- return(0);
-}
-
-
-/*
- * 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);
-}
-
-
-/*
- * Command: file
- *----------------------------------------------------------------------------
- */
-
-int
-cl_file_cmd::do_work(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_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: get
- *----------------------------------------------------------------------------
- */
-
-int
-cl_get_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
-{
- char *s;
-
- if (cmdline->param(0) == 0)
- {
- con->printf("Get what?\n");
- return(0);
- }
- if ((s= cmdline->param(0)->get_svalue()))
- {
- if (strstr(s, "t") == s)
- return(timer(cmdline, con));
- else
- con->printf("Unknow keyword of get command\n");
- }
- return(0);
-}
-
-
-/*
- * Command: set
- *----------------------------------------------------------------------------
- */
-
-
-int
-cl_set_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
-{
- char *s;
-
- if (cmdline->param(0) == 0)
- {
- con->printf("Set what?\n");
- return(0);
- }
- 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);
-}
+#include "cmdutil.h"
/*
*----------------------------------------------------------------------------
*/
-
-int
-cl_run_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 *con)
+COMMAND_DO_WORK_SIM(cl_run_cmd)
{
- 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);
-}
-
-
-/*
- * Command: dump
- *----------------------------------------------------------------------------
- */
-
-int
-cl_dump_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
-{
- class cl_mem *mem;
- char *s;
- long l, start= -1, end= 10*8-1, bpl= 8;
+ 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) };
- 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);
- }
- }
- else
- {
- con->printf("Wrong memory type\n");
- return(0);
- }
-
+ 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])
{
- if ((start= params[1]->get_address()) >= 0)
+ 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])
{
- end+= start;
- if (params[2])
+ if (start == end)
{
- if ((l= params[2]->get_address()) >= 0)
- end= l;
- else
- {
- con->printf("End address is wrong\n");
- return(0);
- }
+ 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->mem(MEM_ROM),
+ sim->uc->make_new_brknr(), end,
+ brkDYNAMIC, 1);
+ sim->uc->fbrk->add_bp(b);
}
- }
- 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);
-}
-
+ 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: di
- *----------------------------------------------------------------------------
- */
-
-int
-cl_di_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
-{
- cmdline->insert_param(0, new cl_cmd_sym_arg("i"));
- cl_dump_cmd::do_work(cmdline, con);
- return(0);
+ sim->start(con);
+ return(DD_FALSE);
}
/*
- * Command: dx
+ * Command: stop
*----------------------------------------------------------------------------
*/
-int
-cl_dx_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 *con)
+COMMAND_DO_WORK_SIM(cl_stop_cmd)
{
- cmdline->insert_param(0, new cl_cmd_sym_arg("x"));
- cl_dump_cmd::do_work(cmdline, con);
- return(0);
+ sim->stop(resUSER);
+ sim->uc->print_disass(sim->uc->PC, con);
+ return(DD_FALSE);
}
/*
- * Command: dch
+ * Command: step
*----------------------------------------------------------------------------
*/
-int
-cl_dch_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 *con)
+COMMAND_DO_WORK_UC(cl_step_cmd)
{
- cmdline->insert_param(0, new cl_cmd_sym_arg("r"));
- cl_dump_cmd::do_work(cmdline, con);
+ //printf("step %x\n",uc->PC);
+ uc->do_inst(1);
+ //printf("step done %x\n",uc->PC);
+ uc->print_regs(con);
return(0);
}
/*
- * Command: ds
+ * Command: next
*----------------------------------------------------------------------------
*/
-int
-cl_ds_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 *con)
+COMMAND_DO_WORK_SIM(cl_next_cmd)
{
- cmdline->insert_param(0, new cl_cmd_sym_arg("s"));
- cl_dump_cmd::do_work(cmdline, con);
- return(0);
-}
-
-
-/*
- * Command: dc
- *----------------------------------------------------------------------------
- */
+ 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)
+ {
+ i++;
+ de= &(sim->uc->dis_tbl()[i]);
+ }
+#endif
-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) };
+ branch = sim->uc->inst_branch(sim->uc->PC);
+ inst_len = sim->uc->inst_length(sim->uc->PC);
- if (params[0])
+ if ((branch == 'a') || (branch == 'l'))
{
- if ((start= params[0]->get_address()) >= 0)
+ next= sim->uc->PC + inst_len;
+ if (!sim->uc->fbrk_at(next))
{
- 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);
+ b= new cl_fetch_brk(sim->uc->mem(MEM_ROM),
+ 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);
}
- 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);
+ else
+ sim->uc->do_inst(1);
+ sim->uc->print_regs(con);
+ return(DD_FALSE);
}
*----------------------------------------------------------------------------
*/
-int
-cl_help_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 *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 < cmdset->count; i++)
+ {
+ 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 if (cmdline->syntax_match(/*sim*/0, STRING)) {
+ int 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");
- 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);
}
*----------------------------------------------------------------------------
*/
-int
-cl_quit_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 */*con*/)
+COMMAND_DO_WORK(cl_quit_cmd)
{
return(1);
}
+
/*
* Command: kill
*----------------------------------------------------------------------------
*/
-int
-cl_kill_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 */*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);
}
-/* End of cmdset.cc */
+/* End of cmd.src/cmdset.cc */