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 if (addr >= uc->get_mem_size(MEM_ROM))
140 if (!uc->inst_at(addr))
141 con->dd_printf("Warning: maybe not instruction at 0x%06x\n", addr);
144 uc->print_disass(uc->PC, con);
151 *----------------------------------------------------------------------------
155 //cl_reset_cmd::do_work(class cl_sim *sim,
156 // class cl_cmdline *cmdline, class cl_console *con)
157 COMMAND_DO_WORK_UC(cl_reset_cmd)
166 *----------------------------------------------------------------------------
170 //cl_dump_cmd::do_work(class cl_sim *sim,
171 // class cl_cmdline *cmdline, class cl_console *con)
172 COMMAND_DO_WORK_UC(cl_dump_cmd)
174 class cl_mem *mem= 0;
176 t_addr start= 0, end;
177 class cl_cmd_arg *params[4]= { cmdline->param(0),
183 params[0]->as_bit(uc))
187 params[0]->as_bit(uc))
190 mem= params[0]->value.bit.mem;
191 m= mem->read(params[0]->value.bit.mem_address);
193 uc->symbolic_bit_name((t_addr)-1,
195 params[0]->value.bit.mem_address,
196 params[0]->value.bit.mask);
197 con->dd_printf("%10s ", sn?sn:"");
198 con->dd_printf(mem->addr_format, params[0]->value.bit.mem_address);
200 con->dd_printf(mem->data_format, m);
201 con->dd_printf(" %c\n", (m&(params[0]->value.bit.mask))?'1':'0');
203 params[0]= cmdline->param(i);
206 con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
208 else if (cmdline->syntax_match(uc, MEMORY))
210 mem= params[0]->value.memory;
213 else if (cmdline->syntax_match(uc, MEMORY ADDRESS)) {
214 mem = params[0]->value.memory;
215 start= params[1]->value.address;
217 mem->dump(start, end, bpl, con);
219 else if (cmdline->syntax_match(uc, MEMORY ADDRESS ADDRESS)) {
220 mem = params[0]->value.memory;
221 start= params[1]->value.address;
222 end = params[2]->value.address;
223 mem->dump(start, end, bpl, con);
225 else if (cmdline->syntax_match(uc, MEMORY ADDRESS ADDRESS NUMBER)) {
226 mem = params[0]->value.memory;
227 start= params[1]->value.address;
228 end = params[2]->value.address;
229 bpl = params[3]->value.number;
230 mem->dump(start, end, bpl, con);
233 con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
241 *----------------------------------------------------------------------------
245 //cl_di_cmd::do_work(class cl_sim *sim,
246 // class cl_cmdline *cmdline, class cl_console *con)
247 COMMAND_DO_WORK_UC(cl_di_cmd)
249 cmdline->insert_param(0, new cl_cmd_sym_arg("i"));
250 cl_dump_cmd::do_work(uc, cmdline, con);
257 *----------------------------------------------------------------------------
261 //cl_dx_cmd::do_work(class cl_sim *sim,
262 // class cl_cmdline *cmdline, class cl_console *con)
263 COMMAND_DO_WORK_UC(cl_dx_cmd)
265 cmdline->insert_param(0, new cl_cmd_sym_arg("x"));
266 cl_dump_cmd::do_work(uc, cmdline, con);
273 *----------------------------------------------------------------------------
277 //cl_dch_cmd::do_work(class cl_sim *sim,
278 // class cl_cmdline *cmdline, class cl_console *con)
279 COMMAND_DO_WORK_UC(cl_dch_cmd)
281 cmdline->insert_param(0, new cl_cmd_sym_arg("r"));
282 cl_dump_cmd::do_work(uc, cmdline, con);
289 *----------------------------------------------------------------------------
293 //cl_ds_cmd::do_work(class cl_sim *sim,
294 // class cl_cmdline *cmdline, class cl_console *con)
295 COMMAND_DO_WORK_UC(cl_ds_cmd)
297 cmdline->insert_param(0, new cl_cmd_sym_arg("s"));
298 cl_dump_cmd::do_work(uc, cmdline, con);
305 *----------------------------------------------------------------------------
309 //cl_dc_cmd::do_work(class cl_sim *sim,
310 // class cl_cmdline *cmdline, class cl_console *con)
311 COMMAND_DO_WORK_UC(cl_dc_cmd)
313 t_addr start= last, end= last+20;
314 class cl_cmd_arg *params[2]= { cmdline->param(0),
316 class cl_mem *rom= uc->mem(MEM_ROM);
322 else if (cmdline->syntax_match(uc, ADDRESS)) {
323 start= params[0]->value.address;
326 else if (cmdline->syntax_match(uc, ADDRESS ADDRESS)) {
327 start= params[0]->value.address;
328 end= params[1]->value.address;
330 if (start >= rom->size)
332 con->dd_printf("Error: start address is wrong\n");
335 if (end >= rom->size)
337 con->dd_printf("Error: end address is wrong\n");
343 start+= uc->inst_length(rom->get(start)))
344 uc->print_disass(start, con);
351 * Command: disassemble
352 *----------------------------------------------------------------------------
355 static int disass_last_stop= 0;
358 //cl_disassemble_cmd::do_work(class cl_sim *sim,
359 // class cl_cmdline *cmdline, class cl_console *con)
360 COMMAND_DO_WORK_UC(cl_disassemble_cmd)
362 t_addr start, realstart;
363 int offset= -1, dir, lines= 20;
364 class cl_cmd_arg *params[4]= { cmdline->param(0),
369 start= disass_last_stop;
370 if (params[0] == 0) ;
371 else if (cmdline->syntax_match(uc, ADDRESS)) {
372 start= params[0]->value.address;
374 else if (cmdline->syntax_match(uc, ADDRESS NUMBER)) {
375 start= params[0]->value.address;
376 offset= params[1]->value.number;
378 else if (cmdline->syntax_match(uc, ADDRESS NUMBER NUMBER)) {
379 start= params[0]->value.address;
380 offset= params[1]->value.number;
381 lines= params[2]->value.number;
385 con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
391 con->dd_printf("Error: wrong `lines' parameter\n");
394 if (!uc->there_is_inst())
397 class cl_mem *rom= uc->mem(MEM_ROM);
400 while (realstart < rom->size &&
401 !uc->inst_at(realstart))
402 realstart= realstart+1;
405 dir= (offset < 0)?-1:+1;
408 realstart= (realstart+dir) % rom->size;
409 while (!uc->inst_at(realstart))
410 realstart= (realstart+dir) % rom->size;
417 uc->print_disass(realstart, con);
418 realstart= (realstart+1) % rom->size;
419 while (!uc->inst_at(realstart))
420 realstart= (realstart+1) % rom->size;
424 disass_last_stop= realstart;
432 *----------------------------------------------------------------------------
436 //cl_fill_cmd::do_work(class cl_sim *sim,
437 // class cl_cmdline *cmdline, class cl_console *con)
438 COMMAND_DO_WORK_UC(cl_fill_cmd)
440 class cl_mem *mem= 0;
442 t_addr start= 0, end;
443 class cl_cmd_arg *params[4]= { cmdline->param(0),
448 if (cmdline->syntax_match(uc, MEMORY ADDRESS ADDRESS NUMBER)) {
449 mem = params[0]->value.memory;
450 start= params[1]->value.address;
451 end = params[2]->value.address;
452 what = params[3]->value.number;
454 for (i= start; i <= end; i++)
462 con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
470 *----------------------------------------------------------------------------
474 cl_where_cmd::do_real_work(class cl_uc *uc,
475 class cl_cmdline *cmdline, class cl_console *con,
478 class cl_mem *mem= 0;
479 class cl_cmd_arg *params[2]= { cmdline->param(0),
482 if (cmdline->syntax_match(uc, MEMORY DATALIST)) {
483 mem= params[0]->value.memory;
484 t_mem *array= params[1]->value.data_list.array;
485 int len= params[1]->value.data_list.len;
488 con->dd_printf("Error: nothing to search for\n");
492 bool found= mem->search_next(case_sensitive, array, len, &addr);
495 mem->dump(addr, addr+len-1, 8, con);
497 found= mem->search_next(case_sensitive, array, len, &addr);
501 con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
507 //cl_where_cmd::do_work(class cl_sim *sim,
508 // class cl_cmdline *cmdline, class cl_console *con)
509 COMMAND_DO_WORK_UC(cl_where_cmd)
511 return(do_real_work(uc, cmdline, con, DD_FALSE));
515 //cl_Where_cmd::do_work(class cl_sim *sim,
516 // class cl_cmdline *cmdline, class cl_console *con)
517 COMMAND_DO_WORK_UC(cl_Where_cmd)
519 return(do_real_work(uc, cmdline, con, DD_TRUE));
523 /* End of cmd.src/cmduc.cc */