2 * Simulator of microcontrollers (cmd.src/cmduc.cc)
4 * Copyright (C) 2001,01 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
41 *----------------------------------------------------------------------------
45 //cl_state_cmd::do_work(class cl_sim *sim,
46 // class cl_cmdline *cmdline, class cl_console *con)
47 COMMAND_DO_WORK_UC(cl_state_cmd)
49 con->dd_printf("CPU state= %s PC= 0x%06x XTAL= %g\n",
50 get_id_string(cpu_states, uc->state),
53 con->dd_printf("Total time since last reset= %g sec (%lu clks)\n",
54 uc->get_rtime(), uc->ticks->ticks);
55 con->dd_printf("Time in isr = %g sec (%lu clks) %3.2g%%\n",
56 uc->isr_ticks->get_rtime(uc->xtal),
58 (uc->ticks->ticks == 0)?0.0:
59 (100.0*((double)(uc->isr_ticks->ticks)/
60 (double)(uc->ticks->ticks))));
61 con->dd_printf("Time in idle= %g sec (%lu clks) %3.2g%%\n",
62 uc->idle_ticks->get_rtime(uc->xtal),
63 uc->idle_ticks->ticks,
64 (uc->ticks->ticks == 0)?0.0:
65 (100.0*((double)(uc->idle_ticks->ticks)/
66 (double)(uc->ticks->ticks))));
67 con->dd_printf("Max value of stack pointer= 0x%06x, avg= 0x%06x\n",
68 uc->sp_max, uc->sp_avg);
75 *----------------------------------------------------------------------------
79 //cl_file_cmd::do_work(class cl_sim *sim,
80 // class cl_cmdline *cmdline, class cl_console *con)
81 COMMAND_DO_WORK_UC(cl_file_cmd)
86 if ((cmdline->param(0) == 0) ||
87 ((fname= cmdline->param(0)->get_svalue()) == NULL))
89 con->dd_printf("File name is missing.\n");
92 if ((l= uc->read_hex_file(fname)) >= 0)
93 con->dd_printf("%ld words read from %s\n", l, fname);
101 *----------------------------------------------------------------------------
105 //cl_dl_cmd::do_work(class cl_sim *sim,
106 // class cl_cmdline *cmdline, class cl_console *con)
107 COMMAND_DO_WORK_UC(cl_dl_cmd)
111 if ((l= uc->read_hex_file(NULL)) >= 0)
112 con->dd_printf("%ld words loaded\n", l);
120 *----------------------------------------------------------------------------
124 //cl_pc_cmd::do_work(class cl_sim *sim,
125 // class cl_cmdline *cmdline, class cl_console *con)
126 COMMAND_DO_WORK_UC(cl_pc_cmd)
129 class cl_cmd_arg *params[1]= { cmdline->param(0) };
133 if (!(params[0]->get_address(uc, &addr)))
135 con->dd_printf("Error: wrong parameter\n");
138 class cl_address_space *rom= uc->address_space(MEM_ROM_ID);
141 if (addr > rom->highest_valid_address())
142 addr= rom->highest_valid_address();
144 if (!uc->inst_at(addr))
145 con->dd_printf("Warning: maybe not instruction at 0x%06x\n", addr);
148 uc->print_disass(uc->PC, con);
155 *----------------------------------------------------------------------------
159 //cl_reset_cmd::do_work(class cl_sim *sim,
160 // class cl_cmdline *cmdline, class cl_console *con)
161 COMMAND_DO_WORK_UC(cl_reset_cmd)
170 *----------------------------------------------------------------------------
174 //cl_dump_cmd::do_work(class cl_sim *sim,
175 // class cl_cmdline *cmdline, class cl_console *con)
176 COMMAND_DO_WORK_UC(cl_dump_cmd)
178 class cl_memory *mem= 0;
180 t_addr start= 0, end;
181 class cl_cmd_arg *params[4]= { cmdline->param(0),
187 params[0]->as_bit(uc))
191 params[0]->as_bit(uc))
194 mem= params[0]->value.bit.mem;
195 m= mem->read(params[0]->value.bit.mem_address);
197 uc->symbolic_bit_name((t_addr)-1,
199 params[0]->value.bit.mem_address,
200 params[0]->value.bit.mask);
201 con->dd_printf("%10s ", sn?sn:"");
202 con->dd_printf(mem->addr_format, params[0]->value.bit.mem_address);
204 con->dd_printf(mem->data_format, m);
205 con->dd_printf(" %c\n", (m&(params[0]->value.bit.mask))?'1':'0');
207 params[0]= cmdline->param(i);
210 con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
215 !params[0]->as_memory(uc))
217 con->dd_printf("No memory specified. Use \"info memory\" for available memories\n");
220 if (cmdline->syntax_match(uc, MEMORY))
222 mem= params[0]->value.memory.memory;
225 else if (cmdline->syntax_match(uc, MEMORY ADDRESS)) {
226 mem = params[0]->value.memory.memory;
227 start= params[1]->value.address;
229 mem->dump(start, end, bpl, con);
231 else if (cmdline->syntax_match(uc, MEMORY ADDRESS ADDRESS)) {
232 mem = params[0]->value.memory.memory;
233 start= params[1]->value.address;
234 end = params[2]->value.address;
235 mem->dump(start, end, bpl, con);
237 else if (cmdline->syntax_match(uc, MEMORY ADDRESS ADDRESS NUMBER)) {
238 mem = params[0]->value.memory.memory;
239 start= params[1]->value.address;
240 end = params[2]->value.address;
241 bpl = params[3]->value.number;
242 mem->dump(start, end, bpl, con);
245 con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
254 *----------------------------------------------------------------------------
258 //cl_di_cmd::do_work(class cl_sim *sim,
259 // class cl_cmdline *cmdline, class cl_console *con)
260 COMMAND_DO_WORK_UC(cl_di_cmd)
262 cmdline->insert_param(0, new cl_cmd_sym_arg("iram"));
263 cl_dump_cmd::do_work(uc, cmdline, con);
270 *----------------------------------------------------------------------------
274 //cl_dx_cmd::do_work(class cl_sim *sim,
275 // class cl_cmdline *cmdline, class cl_console *con)
276 COMMAND_DO_WORK_UC(cl_dx_cmd)
278 cmdline->insert_param(0, new cl_cmd_sym_arg("xram"));
279 cl_dump_cmd::do_work(uc, cmdline, con);
286 *----------------------------------------------------------------------------
290 //cl_dch_cmd::do_work(class cl_sim *sim,
291 // class cl_cmdline *cmdline, class cl_console *con)
292 COMMAND_DO_WORK_UC(cl_dch_cmd)
294 cmdline->insert_param(0, new cl_cmd_sym_arg("rom"));
295 cl_dump_cmd::do_work(uc, cmdline, con);
302 *----------------------------------------------------------------------------
306 //cl_ds_cmd::do_work(class cl_sim *sim,
307 // class cl_cmdline *cmdline, class cl_console *con)
308 COMMAND_DO_WORK_UC(cl_ds_cmd)
310 cmdline->insert_param(0, new cl_cmd_sym_arg("sfr"));
311 cl_dump_cmd::do_work(uc, cmdline, con);
318 *----------------------------------------------------------------------------
322 //cl_dc_cmd::do_work(class cl_sim *sim,
323 // class cl_cmdline *cmdline, class cl_console *con)
324 COMMAND_DO_WORK_UC(cl_dc_cmd)
326 t_addr start= last, end= last+20;
327 class cl_cmd_arg *params[2]= { cmdline->param(0),
329 class cl_address_space *rom= uc->address_space(MEM_ROM_ID);
335 else if (cmdline->syntax_match(uc, ADDRESS)) {
336 start= params[0]->value.address;
339 else if (cmdline->syntax_match(uc, ADDRESS ADDRESS)) {
340 start= params[0]->value.address;
341 end= params[1]->value.address;
343 if (start > rom->highest_valid_address())
345 con->dd_printf("Error: start address is too high\n");
348 if (end > rom->highest_valid_address())
350 con->dd_printf("Error: end address is too high\n");
356 start+= uc->inst_length(start))
357 uc->print_disass(start, con);
364 * Command: disassemble
365 *----------------------------------------------------------------------------
368 static int disass_last_stop= 0;
371 //cl_disassemble_cmd::do_work(class cl_sim *sim,
372 // class cl_cmdline *cmdline, class cl_console *con)
373 COMMAND_DO_WORK_UC(cl_disassemble_cmd)
375 t_addr start, realstart;
376 int offset= -1, dir, lines= 20;
377 class cl_cmd_arg *params[4]= { cmdline->param(0),
382 start= disass_last_stop;
383 if (params[0] == 0) ;
384 else if (cmdline->syntax_match(uc, ADDRESS)) {
385 start= params[0]->value.address;
387 else if (cmdline->syntax_match(uc, ADDRESS NUMBER)) {
388 start= params[0]->value.address;
389 offset= params[1]->value.number;
391 else if (cmdline->syntax_match(uc, ADDRESS NUMBER NUMBER)) {
392 start= params[0]->value.address;
393 offset= params[1]->value.number;
394 lines= params[2]->value.number;
398 con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
404 con->dd_printf("Error: wrong `lines' parameter\n");
407 if (!uc->there_is_inst())
410 class cl_address_space *rom= uc->address_space(MEM_ROM_ID);
413 while (realstart <= rom->highest_valid_address() &&
414 !uc->inst_at(realstart))
415 realstart= realstart+1;
418 dir= (offset < 0)?-1:+1;
421 realstart= rom->inc_address(realstart, dir);
422 while (!uc->inst_at(realstart))
423 realstart= rom->inc_address(realstart, dir);
430 uc->print_disass(realstart, con);
431 realstart= rom->inc_address(realstart, +1) + rom->start_address;
432 while (!uc->inst_at(realstart))
433 realstart= rom->inc_address(realstart, +1) + rom->start_address;
437 disass_last_stop= realstart;
445 *----------------------------------------------------------------------------
449 //cl_fill_cmd::do_work(class cl_sim *sim,
450 // class cl_cmdline *cmdline, class cl_console *con)
451 COMMAND_DO_WORK_UC(cl_fill_cmd)
453 class cl_memory *mem= 0;
455 t_addr start= 0, end;
456 class cl_cmd_arg *params[4]= { cmdline->param(0),
461 if (cmdline->syntax_match(uc, MEMORY ADDRESS ADDRESS NUMBER)) {
462 mem = params[0]->value.memory.memory;
463 start= params[1]->value.address;
464 end = params[2]->value.address;
465 what = params[3]->value.number;
467 for (i= start; i <= end; i++)
475 con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
483 *----------------------------------------------------------------------------
487 cl_where_cmd::do_real_work(class cl_uc *uc,
488 class cl_cmdline *cmdline, class cl_console *con,
491 class cl_memory *mem= 0;
492 class cl_cmd_arg *params[2]= { cmdline->param(0),
495 if (cmdline->syntax_match(uc, MEMORY DATALIST)) {
496 mem= params[0]->value.memory.memory;
497 t_mem *array= params[1]->value.data_list.array;
498 int len= params[1]->value.data_list.len;
501 con->dd_printf("Error: nothing to search for\n");
505 bool found= mem->search_next(case_sensitive, array, len, &addr);
508 mem->dump(addr, addr+len-1, 8, con);
510 found= mem->search_next(case_sensitive, array, len, &addr);
514 con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
520 //cl_where_cmd::do_work(class cl_sim *sim,
521 // class cl_cmdline *cmdline, class cl_console *con)
522 COMMAND_DO_WORK_UC(cl_where_cmd)
524 return(do_real_work(uc, cmdline, con, DD_FALSE));
528 //cl_Where_cmd::do_work(class cl_sim *sim,
529 // class cl_cmdline *cmdline, class cl_console *con)
530 COMMAND_DO_WORK_UC(cl_Where_cmd)
532 return(do_real_work(uc, cmdline, con, DD_TRUE));
536 /* End of cmd.src/cmduc.cc */