2 * Simulator of microcontrollers (cmd.src/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
48 *----------------------------------------------------------------------------
52 //cl_run_cmd::do_work(class cl_sim *sim,
53 // class cl_cmdline *cmdline, class cl_console *con)
54 COMMAND_DO_WORK_SIM(cl_run_cmd)
58 class cl_cmd_arg *params[4]= { cmdline->param(0),
64 if (!(params[0]->get_address(sim->uc, &start)))
66 con->dd_printf("Error: wrong start address\n");
70 if (!(params[1]->get_address(sim->uc, &end)))
72 con->dd_printf("Error: wromg end address\n");
77 if (!sim->uc->inst_at(start))
78 con->dd_printf("Warning: maybe not instruction at 0x%06lx\n", start);
84 con->dd_printf("Addresses must be different.\n");
87 if ((b= sim->uc->fbrk_at(end)))
92 b= new cl_fetch_brk(sim->uc->address_space(MEM_ROM_ID),
93 sim->uc->make_new_brknr(), end,
95 sim->uc->fbrk->add_bp(b);
99 con->dd_printf("Simulation started, PC=0x%06x\n", sim->uc->PC);
100 if (sim->uc->fbrk_at(sim->uc->PC))
110 *----------------------------------------------------------------------------
114 //cl_stop_cmd::do_work(class cl_sim *sim,
115 // class cl_cmdline *cmdline, class cl_console *con)
116 COMMAND_DO_WORK_SIM(cl_stop_cmd)
119 sim->uc->print_disass(sim->uc->PC, con);
126 *----------------------------------------------------------------------------
130 //cl_step_cmd::do_work(class cl_sim *sim,
131 // class cl_cmdline *cmdline, class cl_console *con)
132 COMMAND_DO_WORK_UC(cl_step_cmd)
134 //printf("step %x\n",uc->PC);
136 //printf("step done %x\n",uc->PC);
144 *----------------------------------------------------------------------------
148 //cl_next_cmd::do_work(class cl_sim *sim,
149 // class cl_cmdline *cmdline, class cl_console *con)
150 COMMAND_DO_WORK_SIM(cl_next_cmd)
158 struct dis_entry *de;
159 t_mem code= sim->uc->get_mem(MEM_ROM, sim->uc->PC);
161 de= &(sim->uc->dis_tbl()[i]);
162 while ((code & de->mask) != de->code &&
166 de= &(sim->uc->dis_tbl()[i]);
170 branch = sim->uc->inst_branch(sim->uc->PC);
171 inst_len = sim->uc->inst_length(sim->uc->PC);
173 if ((branch == 'a') || (branch == 'l'))
175 next= sim->uc->PC + inst_len;
176 if (!sim->uc->fbrk_at(next))
178 b= new cl_fetch_brk(sim->uc->address_space(MEM_ROM_ID),
179 sim->uc->make_new_brknr(),
180 next, brkDYNAMIC, 1);
183 // sim->uc->fbrk->add_bp(b);
185 sim->uc->fbrk->add(b);
188 if (sim->uc->fbrk_at(sim->uc->PC))
191 //sim->uc->do_inst(-1);
195 sim->uc->print_regs(con);
203 *----------------------------------------------------------------------------
207 //cl_help_cmd::do_work(class cl_sim *sim,
208 // class cl_cmdline *cmdline, class cl_console *con)
209 COMMAND_DO_WORK_APP(cl_help_cmd)
212 class cl_commander *commander;
213 class cl_cmdset *cmdset= 0;
215 class cl_cmd_arg *parm= cmdline->param(0);
218 if ((commander= app->get_commander()) != 0)
219 cmdset= commander->cmdset;
223 for (i= 0; i < cmdset->count; i++)
225 class cl_cmd *c= (class cl_cmd *)(cmdset->at(i));
227 con->dd_printf("%s\n", c->short_help);
229 con->dd_printf("%s\n", (char*)(c->names->at(0)));
235 do_set(cmdline, 0, cmdset, con);
240 con->dd_printf("Names of command:");
241 for (names= 0; names < cmd_found->names->count; names++)
242 con->dd_printf(" %s", (char*)(cmd_found->names->at(names)));
243 con->dd_printf("\n");
244 class cl_cmdset *subset= cmd_found->get_subcommands();
247 con->dd_printf("\"%s\" must be followed by the name of a "
248 "subcommand\nList of subcommands:\n",
249 (char*)(cmd_found->names->at(0)));
250 for (i= 0; i < subset->count; i++)
253 dynamic_cast<class cl_cmd *>(subset->object_at(i));
254 con->dd_printf("%s\n", c->short_help);
257 if (cmd_found->long_help)
258 con->dd_printf("%s\n", cmd_found->long_help);
262 con->dd_printf("No such command.\n");
266 for (pari= 0; pari < cmdline->nuof_params(); pari++)
268 class cl_cmd_arg *act_param;
269 act_param= (class cl_cmd_arg *)(cmdline->param(pari));
270 for (i= 0; i < cmdset->count; i++)
272 class cl_cmd *c= (class cl_cmd *)(cmdset->at(i));
273 if (!c->name_match(act_param->s_value, DD_FALSE))
276 con->dd_printf("%s\n", c->short_help);
278 con->dd_printf("%s\n", (char*)(c->names->at(0)));
279 if (pari < cmdline->nuof_params()-1)
281 cmdset= c->get_subcommands();
291 if (cmdline->syntax_match(0, STRING)) {
293 for (i= 0; i < cmdset->count; i++)
295 c= (class cl_cmd *)(cmdset->at(i));
296 if (c->name_match(parm->value.string.string, DD_FALSE))
300 con->dd_printf("No such command\n");
301 else if (matches > 1)
302 for (i= 0; i < cmdset->count; i++)
304 c= (class cl_cmd *)(cmdset->at(i));
305 if (!c->name_match(parm->value.string.string, DD_FALSE))
308 con->dd_printf("%s\n", c->short_help);
310 con->dd_printf("%s\n", (char*)(c->names->at(0)));
313 for (i= 0; i < cmdset->count; i++)
315 c= (class cl_cmd *)(cmdset->at(i));
316 if (!c->name_match(parm->value.string.string, DD_FALSE))
319 con->dd_printf("%s\n", c->short_help);
321 con->dd_printf("%s\n", (char*)(c->names->at(0)));
323 con->dd_printf("Names of command:");
324 for (names= 0; names < c->names->count; names++)
325 con->dd_printf(" %s", (char*)(c->names->at(names)));
326 con->dd_printf("\n");
328 con->dd_printf("%s\n", c->long_help);
330 con->dd_printf("%s\n", (char*)(c->names->at(0)));
334 con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax");
341 cl_help_cmd::do_set(class cl_cmdline *cmdline, int pari,
342 class cl_cmdset *cmdset,
343 class cl_console *con)
346 for (i= 0; i < cmdset->count; i++)
348 class cl_cmd *cmd= dynamic_cast<class cl_cmd *>(cmdset->object_at(i));
351 if (pari >= cmdline->nuof_params())
353 class cl_cmd_arg *param= cmdline->param(pari);
356 class cl_cmdset *next_set= cmd->get_subcommands();
357 if (cmd->name_match(param->s_value, DD_FALSE))
359 if (pari+1 >= cmdline->nuof_params())
364 con->dd_printf("%s\n", cmd->short_help);
366 con->dd_printf("%s\n", (char*)(cmd->names->at(0)));
371 do_set(cmdline, pari+1, next_set, con);
380 *----------------------------------------------------------------------------
384 //cl_quit_cmd::do_work(class cl_sim *sim,
385 // class cl_cmdline */*cmdline*/, class cl_console */*con*/)
386 COMMAND_DO_WORK(cl_quit_cmd)
394 *----------------------------------------------------------------------------
398 //cl_kill_cmd::do_work(class cl_sim *sim,
399 // class cl_cmdline */*cmdline*/, class cl_console */*con*/)
400 COMMAND_DO_WORK_APP(cl_kill_cmd)
404 app->sim->state|= SIM_QUIT;
413 COMMAND_DO_WORK_APP(cl_exec_cmd)
415 class cl_cmd_arg *parm= cmdline->param(0);
418 if (cmdline->syntax_match(0, STRING)) {
419 fn= parm->value.string.string;
422 con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
424 class cl_commander *c= app->get_commander();
425 class cl_console *cons= con->clone_for_exec(fn);
428 cons->flags|= CONS_NOWELCOME;
429 c->add_console(cons);
437 * expression expression
440 COMMAND_DO_WORK_APP(cl_expression_cmd)
442 //con->dd_printf("\"%s\"\n", cmdline->cmd);
443 char *s= cmdline->cmd;
447 int i= strspn(s, " \t\v\n");
449 //con->dd_printf("\"%s\"\n", s);
450 i= strspn(s, "abcdefghijklmnopqrstuvwxyz");
452 //con->dd_printf("\"%s\"\n", s);
453 class YY_cl_ucsim_parser_CLASS *pars;
454 class cl_ucsim_lexer *lexer;
455 lexer= new cl_ucsim_lexer(s);
456 pars= new YY_cl_ucsim_parser_CLASS(lexer);
463 /* End of cmd.src/cmdset.cc */