2 * Simulator of microcontrollers (cmdset.cc)
4 * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
6 * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
10 /* This file is part of microcontroller simulator: ucsim.
12 UCSIM is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 UCSIM is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with UCSIM; see the file COPYING. If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
44 *----------------------------------------------------------------------------
48 cl_conf_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
52 con->printf("ucsim version %s\n", VERSIONSTR);
53 con->printf("Type of microcontroller: %s\n", sim->uc->id_string());
54 con->printf("Controller has %d hardware element(s).\n",
56 for (i= 0; i < sim->uc->hws->count; i++)
58 class cl_hw *hw= (class cl_hw *)(sim->uc->hws->at(i));
59 con->printf(" %s[%d]\n", hw->id_string, hw->id);
61 con->printf("Memories:\n");
62 for (i= MEM_ROM; i < MEM_TYPES; i++)
64 class cl_mem *mem= (class cl_mem *)(sim->uc->mems->at(i));
66 con->printf(" %s size= 0x%06x %d\n",
67 mem->id_string(), mem->size, mem->size);
75 *----------------------------------------------------------------------------
79 cl_state_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
81 //con->printf("sim state= %d\n", sim->state);
82 con->printf("CPU state= %s PC= 0x%06x XTAL= %g\n",
83 get_id_string(cpu_states, sim->uc->state),
86 con->printf("Total time since last reset= %g sec (%lu clks)\n",
87 sim->uc->get_rtime(), sim->uc->ticks->ticks);
88 con->printf("Time in isr = %g sec (%lu clks) %3.2g%%\n",
89 sim->uc->isr_ticks->get_rtime(sim->uc->xtal),
90 sim->uc->isr_ticks->ticks,
91 (sim->uc->ticks->ticks == 0)?0.0:
92 (100.0*((double)(sim->uc->isr_ticks->ticks)/
93 (double)(sim->uc->ticks->ticks))));
94 con->printf("Time in idle= %g sec (%lu clks) %3.2g%%\n",
95 sim->uc->idle_ticks->get_rtime(sim->uc->xtal),
96 sim->uc->idle_ticks->ticks,
97 (sim->uc->ticks->ticks == 0)?0.0:
98 (100.0*((double)(sim->uc->idle_ticks->ticks)/
99 (double)(sim->uc->ticks->ticks))));
100 con->printf("Max value of stack pointer= 0x%06x, avg= 0x%06x\n",
101 sim->uc->sp_max, sim->uc->sp_avg);
108 *----------------------------------------------------------------------------
112 cl_file_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
117 if ((cmdline->param(0) == 0) ||
118 ((fname= cmdline->param(0)->get_svalue()) == NULL))
120 con->printf("File name is missing.\n");
123 if ((l= sim->uc->read_hex_file(fname)) >= 0)
124 con->printf("%ld words read from %s\n", l, fname);
132 *----------------------------------------------------------------------------
136 cl_dl_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
140 if ((l= sim->uc->read_hex_file(NULL)) >= 0)
141 con->printf("%ld words loaded\n", l);
149 *----------------------------------------------------------------------------
153 cl_get_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
157 if (cmdline->param(0) == 0)
159 con->printf("Get what?\n");
162 if ((s= cmdline->param(0)->get_svalue()))
164 if (strstr(s, "t") == s)
165 return(timer(cmdline, con));
167 con->printf("Unknow keyword of get command\n");
175 *----------------------------------------------------------------------------
180 cl_set_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
184 if (cmdline->param(0) == 0)
186 con->printf("Set what?\n");
189 if ((s= cmdline->param(0)->get_svalue()))
191 if (strstr(s, "t") == s)
192 return(timer(cmdline, con));
194 con->printf("Unknow keyword of set command\n");
202 *----------------------------------------------------------------------------
207 cl_run_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
216 *----------------------------------------------------------------------------
221 cl_step_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
224 sim->uc->print_regs(con);
231 *----------------------------------------------------------------------------
236 cl_reset_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
245 *----------------------------------------------------------------------------
249 cl_dump_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
253 long l, start= -1, end= 10*8-1, bpl= 8;
254 class cl_cmd_arg *params[4]= { cmdline->param(0),
261 con->printf("Memory type missing\n");
264 if ((s= params[0]->get_svalue()))
266 if (strstr(s, "i") == s)
267 mem= sim->uc->mem(MEM_IRAM);
268 else if (strstr(s, "x") == s)
269 mem= sim->uc->mem(MEM_XRAM);
270 else if (strstr(s, "r") == s)
271 mem= sim->uc->mem(MEM_ROM);
272 else if (strstr(s, "s") == s)
273 mem= sim->uc->mem(MEM_SFR);
276 con->printf("Unknown memory type\n");
281 con->printf("No such memory\n");
287 con->printf("Wrong memory type\n");
293 if ((start= params[1]->get_address()) >= 0)
298 if ((l= params[2]->get_address()) >= 0)
302 con->printf("End address is wrong\n");
309 con->printf("Start address is wrong\n");
314 (l= params[3]->get_address()) >= 0)
316 mem->dump(start, end, bpl, con);
323 *----------------------------------------------------------------------------
327 cl_di_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
329 cmdline->insert_param(0, new cl_cmd_sym_arg("i"));
330 cl_dump_cmd::do_work(cmdline, con);
337 *----------------------------------------------------------------------------
341 cl_dx_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
343 cmdline->insert_param(0, new cl_cmd_sym_arg("x"));
344 cl_dump_cmd::do_work(cmdline, con);
351 *----------------------------------------------------------------------------
355 cl_dch_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
357 cmdline->insert_param(0, new cl_cmd_sym_arg("r"));
358 cl_dump_cmd::do_work(cmdline, con);
365 *----------------------------------------------------------------------------
369 cl_ds_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
371 cmdline->insert_param(0, new cl_cmd_sym_arg("s"));
372 cl_dump_cmd::do_work(cmdline, con);
379 *----------------------------------------------------------------------------
383 cl_dc_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
385 long i, l, start= last, end= -1;
386 class cl_cmd_arg *params[2]= { cmdline->param(0),
391 if ((start= params[0]->get_address()) >= 0)
395 if ((l= params[1]->get_address()) >= 0)
399 con->printf("End address is wrong\n");
406 con->printf("Start address is wrong\n");
412 (end < 0 && i < 20) || l <= end;
413 l+= sim->uc->inst_length(sim->uc->get_mem(MEM_ROM, l)), i++)
414 sim->uc->print_disass(l, con);
422 *----------------------------------------------------------------------------
426 cl_help_cmd::do_work(class cl_cmdline */*cmdline*/, class cl_console *con)
431 for (i= 0; i < sim->cmdset->count; i++)
433 c= (class cl_cmd *)(sim->cmdset->at(i));
435 con->printf("%s\n", c->short_help);
437 con->printf("%s\n", (char*)(c->names->at(0)));
445 *----------------------------------------------------------------------------
449 cl_quit_cmd::do_work(class cl_cmdline */*cmdline*/, class cl_console */*con*/)
456 *----------------------------------------------------------------------------
460 cl_kill_cmd::do_work(class cl_cmdline */*cmdline*/, class cl_console */*con*/)
462 sim->state|= SIM_QUIT;
467 /* End of cmdset.cc */