1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
|
/*
* Simulator of microcontrollers (hw.cc)
*
* Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
*
* To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
*
*/
/* This file is part of microcontroller simulator: ucsim.
UCSIM is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
UCSIM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with UCSIM; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
/*@1@*/
#include "ddconfig.h"
#include <stdlib.h>
#include "i_string.h"
#include "stypes.h"
#include "hwcl.h"
/*
*____________________________________________________________________________
*/
cl_watched_cell::cl_watched_cell(class cl_address_space *amem, t_addr aaddr,
class cl_memory_cell **astore,
enum what_to_do_on_cell_change awtd)
{
mem= amem;
addr= aaddr;
store= astore;
wtd= awtd;
if (mem)
{
cell= mem->get_cell(addr);
if (store)
*store= cell;
}
}
void
cl_watched_cell::mem_cell_changed(class cl_address_space *amem, t_addr aaddr,
class cl_hw *hw)
{
if (mem &&
mem == amem &&
addr == aaddr)
{
cell= mem->get_cell(addr);
if (store &&
(wtd & WTD_RESTORE))
*store= cell;
if (wtd & WTD_WRITE)
{
t_mem d= cell->get();
hw->write(cell, &d);
}
}
}
void
cl_watched_cell::address_space_added(class cl_address_space *amem,
class cl_hw *hw)
{
}
void
cl_used_cell::mem_cell_changed(class cl_address_space *amem, t_addr aaddr,
class cl_hw *hw)
{
if (mem &&
mem == amem &&
addr == aaddr)
{
cell= mem->get_cell(addr);
if (store &&
(wtd & WTD_RESTORE))
*store= cell;
if (wtd & WTD_WRITE)
{
t_mem d= cell->get();
hw->write(cell, &d);
}
}
}
void
cl_used_cell::address_space_added(class cl_address_space *amem,
class cl_hw *hw)
{
}
/*
*____________________________________________________________________________
*/
cl_hw::cl_hw(class cl_uc *auc, enum hw_cath cath, int aid, const char *aid_string):
cl_guiobj()
{
flags= HWF_INSIDE;
uc= auc;
cathegory= cath;
id= aid;
if (aid_string &&
*aid_string)
id_string= strdup(aid_string);
else
id_string= strdup("unknown hw element");
char *s= (char*)malloc(strlen(get_name("hw"))+100);
sprintf(s, "partners of %s", get_name("hw"));
partners= new cl_list(2, 2, s);
sprintf(s, "watched cells of %s", get_name("hw"));
watched_cells= new cl_list(2, 2, s);
free(s);
}
cl_hw::~cl_hw(void)
{
free(id_string);
//hws_to_inform->disconn_all();
delete partners;
delete watched_cells;
}
void
cl_hw::new_hw_adding(class cl_hw *new_hw)
{
}
void
cl_hw::new_hw_added(class cl_hw *new_hw)
{
int i;
for (i= 0; i < partners->count; i++)
{
class cl_partner_hw *ph= (class cl_partner_hw *)(partners->at(i));
ph->refresh(new_hw);
}
}
class cl_hw *
cl_hw::make_partner(enum hw_cath cath, int id)
{
class cl_partner_hw *ph;
class cl_hw *hw;
ph= new cl_partner_hw(uc, cath, id);
partners->add(ph);
hw= ph->get_partner();
return(hw);
}
/*
* Callback functions for changing memory locations
*/
/*t_mem
cl_hw::read(class cl_m *mem, t_addr addr)
{
// Simply return the value
return(mem->get(addr));
}*/
/*void
cl_hw::write(class cl_m *mem, t_addr addr, t_mem *val)
{
// Do not change *val by default
}*/
void
cl_hw::set_cmd(class cl_cmdline *cmdline, class cl_console_base *con)
{
con->dd_printf("Nothing to do\n");
}
class cl_memory_cell *
cl_hw::register_cell(class cl_address_space *mem, t_addr addr,
class cl_memory_cell **store,
enum what_to_do_on_cell_change awtd)
{
class cl_watched_cell *wc;
class cl_memory_cell *cell;
if (mem)
mem->register_hw(addr, this, (int*)0, DD_FALSE);
else
printf("regcell JAJ no mem\n");
wc= new cl_watched_cell(mem, addr, &cell, awtd);
if (store)
*store= cell;
watched_cells->add(wc);
// announce
//uc->sim->mem_cell_changed(mem, addr);
return(cell);
}
class cl_memory_cell *
cl_hw::use_cell(class cl_address_space *mem, t_addr addr,
class cl_memory_cell **store,
enum what_to_do_on_cell_change awtd)
{
class cl_watched_cell *wc;
class cl_memory_cell *cell;
wc= new cl_used_cell(mem, addr, &cell, awtd);
if (store)
*store= cell;
watched_cells->add(wc);
return(cell);
}
void
cl_hw::mem_cell_changed(class cl_address_space *mem, t_addr addr)
{
int i;
for (i= 0; i < watched_cells->count; i++)
{
class cl_watched_cell *wc=
(class cl_watched_cell *)(watched_cells->at(i));
wc->mem_cell_changed(mem, addr, this);
}
}
void
cl_hw::address_space_added(class cl_address_space *as)
{
int i;
for (i= 0; i < watched_cells->count; i++)
{
class cl_watched_cell *wc=
dynamic_cast<class cl_watched_cell *>(watched_cells->object_at(i));
wc->address_space_added(as, this);
}
}
/*
* Simulating `cycles' number of machine cycle
*/
int
cl_hw::tick(int cycles)
{
return(0);
}
void
cl_hw::inform_partners(enum hw_event he, void *params)
{
int i;
for (i= 0; i < partners->count; i++)
{
class cl_partner_hw *ph= (class cl_partner_hw *)(partners->at(i));
ph->happen(this, he, params);
}
}
void
cl_hw::print_info(class cl_console_base *con)
{
con->dd_printf("%s[%d]\n", id_string, id);
}
t_index
cl_hws::add(void *item)
{
int i;
t_index res;
// pre-add
for (i= 0; i < count; i++)
{
class cl_hw *hw= (class cl_hw *)(at(i));
hw->new_hw_adding((class cl_hw *)item);
}
// add
res= cl_list::add(item);
// post-add
for (i= 0; i < count; i++)
{
class cl_hw *hw= (class cl_hw *)(at(i));
hw->new_hw_added((class cl_hw *)item);
}
((class cl_hw *)item)->added_to_uc();
return(res);
}
void
cl_hws::mem_cell_changed(class cl_address_space *mem, t_addr addr)
{
int i;
for (i= 0; i < count; i++)
{
class cl_hw *hw= (class cl_hw *)(at(i));
hw->mem_cell_changed(mem, addr);
}
}
void
cl_hws::address_space_added(class cl_address_space *mem)
{
int i;
for (i= 0; i < count; i++)
{
class cl_hw *hw= (class cl_hw *)(at(i));
hw->address_space_added(mem);
}
}
/*
*____________________________________________________________________________
*/
cl_partner_hw::cl_partner_hw(class cl_uc *auc, enum hw_cath cath, int aid):
cl_base()
{
uc= auc;
cathegory= cath;
id= aid;
partner= uc->get_hw(cathegory, id, 0);
}
class cl_hw *
cl_partner_hw::get_partner(void)
{
return(partner);
}
void
cl_partner_hw::refresh(void)
{
class cl_hw *hw= uc->get_hw(cathegory, id, 0);
if (!hw)
return;
if (partner)
{
// partner is already set
if (partner != hw)
{
// partner changed?
partner= hw;
}
else
partner= hw;
}
partner= hw;
}
void
cl_partner_hw::refresh(class cl_hw *new_hw)
{
if (!new_hw)
return;
if (cathegory == new_hw->cathegory &&
id == new_hw->id)
{
if (partner)
{
// partner changed?
partner= new_hw;
}
else
partner= new_hw;
}
}
void
cl_partner_hw::happen(class cl_hw *where, enum hw_event he, void *params)
{
if (partner)
partner->happen(where, he, params);
}
/* End of hw.cc */
|