2 * Simulator of microcontrollers (hw.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
38 *____________________________________________________________________________
41 cl_watched_cell::cl_watched_cell(class cl_address_space *amem, t_addr aaddr,
42 class cl_memory_cell **astore,
43 enum what_to_do_on_cell_change awtd)
51 cell= mem->get_cell(addr);
58 cl_watched_cell::mem_cell_changed(class cl_address_space *amem, t_addr aaddr,
65 cell= mem->get_cell(addr);
78 cl_watched_cell::address_space_added(class cl_address_space *amem,
84 cl_used_cell::mem_cell_changed(class cl_address_space *amem, t_addr aaddr,
91 cell= mem->get_cell(addr);
104 cl_used_cell::address_space_added(class cl_address_space *amem,
111 *____________________________________________________________________________
114 cl_hw::cl_hw(class cl_uc *auc, enum hw_cath cath, int aid, char *aid_string):
123 id_string= strdup(aid_string);
125 id_string= strdup("unknown hw element");
126 char *s= (char*)malloc(strlen(get_name("hw"))+100);
127 sprintf(s, "partners of %s", get_name("hw"));
128 partners= new cl_list(2, 2, s);
129 sprintf(s, "watched cells of %s", get_name("hw"));
130 watched_cells= new cl_list(2, 2, s);
137 //hws_to_inform->disconn_all();
139 delete watched_cells;
144 cl_hw::new_hw_adding(class cl_hw *new_hw)
149 cl_hw::new_hw_added(class cl_hw *new_hw)
153 for (i= 0; i < partners->count; i++)
155 class cl_partner_hw *ph= (class cl_partner_hw *)(partners->at(i));
161 cl_hw::make_partner(enum hw_cath cath, int id)
163 class cl_partner_hw *ph;
166 ph= new cl_partner_hw(uc, cath, id);
168 hw= ph->get_partner();
174 * Callback functions for changing memory locations
178 cl_hw::read(class cl_m *mem, t_addr addr)
180 // Simply return the value
181 return(mem->get(addr));
185 cl_hw::write(class cl_m *mem, t_addr addr, t_mem *val)
187 // Do not change *val by default
191 cl_hw::set_cmd(class cl_cmdline *cmdline, class cl_console_base *con)
193 con->dd_printf("Nothing to do\n");
196 class cl_memory_cell *
197 cl_hw::register_cell(class cl_address_space *mem, t_addr addr,
198 class cl_memory_cell **store,
199 enum what_to_do_on_cell_change awtd)
201 class cl_watched_cell *wc;
202 class cl_memory_cell *cell;
205 mem->register_hw(addr, this, (int*)0, DD_FALSE);
207 printf("regcell JAJ no mem\n");
208 wc= new cl_watched_cell(mem, addr, &cell, awtd);
211 watched_cells->add(wc);
213 //uc->sim->mem_cell_changed(mem, addr);
217 class cl_memory_cell *
218 cl_hw::use_cell(class cl_address_space *mem, t_addr addr,
219 class cl_memory_cell **store,
220 enum what_to_do_on_cell_change awtd)
222 class cl_watched_cell *wc;
223 class cl_memory_cell *cell;
225 wc= new cl_used_cell(mem, addr, &cell, awtd);
228 watched_cells->add(wc);
233 cl_hw::mem_cell_changed(class cl_address_space *mem, t_addr addr)
237 for (i= 0; i < watched_cells->count; i++)
239 class cl_watched_cell *wc=
240 (class cl_watched_cell *)(watched_cells->at(i));
241 wc->mem_cell_changed(mem, addr, this);
246 cl_hw::address_space_added(class cl_address_space *as)
250 for (i= 0; i < watched_cells->count; i++)
252 class cl_watched_cell *wc=
253 dynamic_cast<class cl_watched_cell *>(watched_cells->object_at(i));
254 wc->address_space_added(as, this);
260 * Simulating `cycles' number of machine cycle
264 cl_hw::tick(int cycles)
270 cl_hw::inform_partners(enum hw_event he, void *params)
274 for (i= 0; i < partners->count; i++)
276 class cl_partner_hw *ph= (class cl_partner_hw *)(partners->at(i));
277 ph->happen(this, he, params);
283 cl_hw::print_info(class cl_console_base *con)
285 con->dd_printf("%s[%d]\n", id_string, id);
290 cl_hws::add(void *item)
296 for (i= 0; i < count; i++)
298 class cl_hw *hw= (class cl_hw *)(at(i));
299 hw->new_hw_adding((class cl_hw *)item);
302 res= cl_list::add(item);
304 for (i= 0; i < count; i++)
306 class cl_hw *hw= (class cl_hw *)(at(i));
307 hw->new_hw_added((class cl_hw *)item);
309 ((class cl_hw *)item)->added_to_uc();
315 cl_hws::mem_cell_changed(class cl_address_space *mem, t_addr addr)
319 for (i= 0; i < count; i++)
321 class cl_hw *hw= (class cl_hw *)(at(i));
322 hw->mem_cell_changed(mem, addr);
327 cl_hws::address_space_added(class cl_address_space *mem)
331 for (i= 0; i < count; i++)
333 class cl_hw *hw= (class cl_hw *)(at(i));
334 hw->address_space_added(mem);
340 *____________________________________________________________________________
343 cl_partner_hw::cl_partner_hw(class cl_uc *auc, enum hw_cath cath, int aid):
349 partner= uc->get_hw(cathegory, id, 0);
353 cl_partner_hw::get_partner(void)
359 cl_partner_hw::refresh(void)
361 class cl_hw *hw= uc->get_hw(cathegory, id, 0);
367 // partner is already set
380 cl_partner_hw::refresh(class cl_hw *new_hw)
384 if (cathegory == new_hw->cathegory &&
398 cl_partner_hw::happen(class cl_hw *where, enum hw_event he, void *params)
401 partner->happen(where, he, params);