2 * Simulator of microcontrollers (sim.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
51 cl_sim::cl_sim(class cl_app *the_app):
56 //arguments= new cl_list(2, 2);
57 //accept_args= more_args?strdup(more_args):0;
58 gui= new cl_gui(this);
65 build_cmdset(app->get_commander()->cmdset);
66 if (!(uc= mk_controller()))
79 cl_sim::mk_controller(void)
81 return(new cl_uc(this));
86 * Main cycle of the simulator
95 (state & SIM_QUIT) == 0)
100 if (app->get_commander()->input_avail())
102 done= app->get_commander()->proc_input();
107 app->get_commander()->wait_input();
108 done= app->get_commander()->proc_input();
123 cl_sim::do_cmd(char *cmdstr, class cl_console *console)
125 class cl_cmdline *cmdline;
129 cmdline= new cl_cmdline(cmdstr, console);
131 cm= cmd->cmdset->get_cmd(cmdline);
133 retval= cm->work(cmdline, console);
137 return(console->interpret(cmdstr));
141 cl_sim::start(class cl_console *con)
144 con->flags|= CONS_FROZEN;
145 app->get_commander()->frozen_console= con;
146 app->get_commander()->set_fd_set();
150 cl_sim::stop(int reason)
152 class cl_commander *cmd= app->get_commander();
155 if (cmd->frozen_console)
157 if (reason == resUSER &&
158 cmd->frozen_console->input_avail())
159 cmd->frozen_console->read_line();
160 cmd->frozen_console->dd_printf("Stop at 0x%06x: (%d) ", uc->PC, reason);
164 cmd->frozen_console->dd_printf("Halted\n");
167 cmd->frozen_console->dd_printf("Invalid address\n");
170 cmd->frozen_console->dd_printf("Stack overflow\n");
173 cmd->frozen_console->dd_printf("Breakpoint\n");
174 uc->print_regs(cmd->frozen_console);
177 cmd->frozen_console->dd_printf("Interrupt\n");
180 cmd->frozen_console->dd_printf("Watchdog reset\n");
183 cmd->frozen_console->dd_printf("User stopped\n");
186 cmd->frozen_console->dd_printf("Invalid instruction 0x%04x\n",
187 uc->get_mem(MEM_ROM, uc->PC));
190 cmd->frozen_console->dd_printf("Unknown reason\n");
193 cmd->frozen_console->dd_printf("F 0x%06x\n", uc->PC); // for sdcdb
194 //if (cmd->actual_console != cmd->frozen_console)
195 cmd->frozen_console->flags&= ~CONS_FROZEN;
196 cmd->frozen_console->print_prompt();
197 cmd->frozen_console= 0;
207 cl_sim::build_cmdset(class cl_cmdset *cmdset)
210 class cl_cmdset *cset;
212 cmdset->add(cmd= new cl_run_cmd("run", 0,
213 "run [start [stop]] Go",
214 "long help of run"));
219 cmdset->add(cmd= new cl_stop_cmd("stop", 0,
221 "long help of stop"));
224 cmdset->add(cmd= new cl_step_cmd("step", 0,
226 "long help of step"));
230 cmdset->add(cmd= new cl_next_cmd("next", 0,
232 "long help of next"));
237 cset= new cl_cmdset();
239 cset->add(cmd= new cl_gui_start_cmd("start", 0,
240 "gui start Start interfacing with GUI tool",
241 "long help of gui start"));
243 cset->add(cmd= new cl_gui_stop_cmd("stop", 0,
244 "gui stop Stop interfacing with GUI tool",
245 "long help of gui stop"));
248 cmdset->add(cmd= new cl_super_cmd("gui", 0,
249 "gui subcommand Operations to support GUI tools",
250 "long help of gui", cset));
256 * Messages to broadcast
260 cl_sim::mem_cell_changed(class cl_mem *mem, t_addr addr)
263 uc->mem_cell_changed(mem, addr);
269 /* End of sim.src/sim.cc */