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
45 *----------------------------------------------------------------------------
49 //cl_run_cmd::do_work(class cl_sim *sim,
50 // class cl_cmdline *cmdline, class cl_console *con)
51 COMMAND_DO_WORK_SIM(cl_run_cmd)
55 class cl_cmd_arg *params[4]= { cmdline->param(0),
61 if (!(params[0]->get_address(sim->uc, &start)))
63 con->dd_printf("Error: wrong start address\n");
67 if (!(params[1]->get_address(sim->uc, &end)))
69 con->dd_printf("Error: wromg end address\n");
74 if (!sim->uc->inst_at(start))
75 con->dd_printf("Warning: maybe not instruction at 0x%06lx\n", start);
81 con->dd_printf("Addresses must be different.\n");
84 if ((b= sim->uc->fbrk_at(end)))
89 b= new cl_fetch_brk(sim->uc->mem(MEM_ROM),
90 sim->uc->make_new_brknr(), end,
92 sim->uc->fbrk->add_bp(b);
96 con->dd_printf("Simulation started, PC=0x%06x\n", sim->uc->PC);
97 if (sim->uc->fbrk_at(sim->uc->PC))
107 *----------------------------------------------------------------------------
111 //cl_stop_cmd::do_work(class cl_sim *sim,
112 // class cl_cmdline *cmdline, class cl_console *con)
113 COMMAND_DO_WORK_SIM(cl_stop_cmd)
116 sim->uc->print_disass(sim->uc->PC, con);
123 *----------------------------------------------------------------------------
127 //cl_step_cmd::do_work(class cl_sim *sim,
128 // class cl_cmdline *cmdline, class cl_console *con)
129 COMMAND_DO_WORK_UC(cl_step_cmd)
131 //printf("step %x\n",uc->PC);
133 //printf("step done %x\n",uc->PC);
141 *----------------------------------------------------------------------------
145 //cl_next_cmd::do_work(class cl_sim *sim,
146 // class cl_cmdline *cmdline, class cl_console *con)
147 COMMAND_DO_WORK_SIM(cl_next_cmd)
155 struct dis_entry *de;
156 t_mem code= sim->uc->get_mem(MEM_ROM, sim->uc->PC);
158 de= &(sim->uc->dis_tbl()[i]);
159 while ((code & de->mask) != de->code &&
163 de= &(sim->uc->dis_tbl()[i]);
167 branch = sim->uc->inst_branch(sim->uc->PC);
168 inst_len = sim->uc->inst_length(sim->uc->PC);
170 if ((branch == 'a') || (branch == 'l'))
172 next= sim->uc->PC + inst_len;
173 if (!sim->uc->fbrk_at(next))
175 b= new cl_fetch_brk(sim->uc->mem(MEM_ROM),
176 sim->uc->make_new_brknr(),
177 next, brkDYNAMIC, 1);
180 // sim->uc->fbrk->add_bp(b);
182 sim->uc->fbrk->add(b);
185 if (sim->uc->fbrk_at(sim->uc->PC))
188 //sim->uc->do_inst(-1);
192 sim->uc->print_regs(con);
200 *----------------------------------------------------------------------------
204 //cl_help_cmd::do_work(class cl_sim *sim,
205 // class cl_cmdline *cmdline, class cl_console *con)
206 COMMAND_DO_WORK_APP(cl_help_cmd)
209 class cl_commander *cmd;
210 class cl_cmdset *cmdset= 0;
213 class cl_cmd_arg *parm= cmdline->param(0);
216 if ((cmd= app->get_commander()) != 0)
221 for (i= 0; i < cmdset->count; i++)
223 c= (class cl_cmd *)(cmdset->at(i));
225 con->dd_printf("%s\n", c->short_help);
227 con->dd_printf("%s\n", (char*)(c->names->at(0)));
230 else if (cmdline->syntax_match(/*sim*/0, STRING)) {
232 for (i= 0; i < cmdset->count; i++)
234 c= (class cl_cmd *)(cmdset->at(i));
235 if (c->name_match(parm->value.string.string, DD_FALSE))
239 con->dd_printf("No such command\n");
240 else if (matches > 1)
241 for (i= 0; i < cmdset->count; i++)
243 c= (class cl_cmd *)(cmdset->at(i));
244 if (!c->name_match(parm->value.string.string, DD_FALSE))
247 con->dd_printf("%s\n", c->short_help);
249 con->dd_printf("%s\n", (char*)(c->names->at(0)));
252 for (i= 0; i < cmdset->count; i++)
254 c= (class cl_cmd *)(cmdset->at(i));
255 if (!c->name_match(parm->value.string.string, DD_FALSE))
258 con->dd_printf("%s\n", c->short_help);
260 con->dd_printf("%s\n", (char*)(c->names->at(0)));
262 con->dd_printf("Names of command:");
263 for (names= 0; names < c->names->count; names++)
264 con->dd_printf(" %s", (char*)(c->names->at(names)));
265 con->dd_printf("\n");
267 con->dd_printf("%s\n", c->long_help);
269 con->dd_printf("%s\n", (char*)(c->names->at(0)));
273 con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax");
281 *----------------------------------------------------------------------------
285 //cl_quit_cmd::do_work(class cl_sim *sim,
286 // class cl_cmdline */*cmdline*/, class cl_console */*con*/)
287 COMMAND_DO_WORK(cl_quit_cmd)
295 *----------------------------------------------------------------------------
299 //cl_kill_cmd::do_work(class cl_sim *sim,
300 // class cl_cmdline */*cmdline*/, class cl_console */*con*/)
301 COMMAND_DO_WORK_APP(cl_kill_cmd)
305 app->sim->state|= SIM_QUIT;
314 COMMAND_DO_WORK_APP(cl_exec_cmd)
316 class cl_cmd_arg *parm= cmdline->param(0);
319 if (cmdline->syntax_match(0, STRING)) {
320 fn= parm->value.string.string;
323 con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
325 class cl_commander *c= app->get_commander();
326 class cl_console *cons= con->clone_for_exec(fn);
329 cons->flags|= CONS_NOWELCOME;
330 c->add_console(cons);
337 /* End of cmd.src/cmdset.cc */