2 * Simulator of microcontrollers (sim.src/memcl.h)
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
28 #ifndef SIM_MEMCL_HEADER
29 #define SIM_MEMCL_HEADER
41 class cl_event_handler;
45 #define CELL_NORMAL 0x00 /* Nothing special */
46 #define CELL_HW_READ 0x01 /* Hw handles read */
47 #define CELL_HW_WRITE 0x02 /* Hw catches write */
48 //#define CELL_INST 0x04 /* Marked as instruction */
49 //#define CELL_FETCH_BRK 0x08 /* Fetch breakpoint */
50 #define CELL_READ_BRK 0x10 /* Read event breakpoint */
51 #define CELL_WRITE_BRK 0x20 /* Write event breakpoint */
56 CELL_INST = 0x04, /* Marked as instruction */
57 CELL_FETCH_BRK = 0x08, /* Fetch breakpoint */
58 CELL_NON_DECODED = 0x40 /* Cell is not decoded (yet) */
61 #define CELL_GENERAL (CELL_NORMAL|CELL_INST|CELL_FETCH_BRK)
65 * 3rd version of memory system
68 class cl_memory: public cl_base
76 char *addr_format, *data_format;
80 //char *class_name; // used by cl_m!!
84 cl_memory(char *id, t_addr asize, int awidth);
85 virtual ~cl_memory(void);
86 virtual int init(void);
88 t_addr get_start_address(void) { return(start_address); }
89 t_addr get_size(void) { return(size); }
90 virtual void set_uc(class cl_uc *auc) { uc= auc; }
91 virtual bool valid_address(t_addr addr);
92 virtual t_addr inc_address(t_addr addr, int val);
93 virtual t_addr inc_address(t_addr addr);
94 virtual t_addr validate_address(t_addr addr);
96 virtual bool is_chip(void) { return(DD_FALSE); }
97 virtual bool is_address_space(void) { return(DD_FALSE); }
99 virtual void err_inv_addr(t_addr addr);
100 virtual void err_non_decoded(t_addr addr);
102 virtual t_addr dump(t_addr start, t_addr stop, int bpl,
103 class cl_console *con);
104 virtual t_addr dump(class cl_console *con);
105 virtual bool search_next(bool case_sensitive,
106 t_mem *array, int len, t_addr *addr);
109 virtual t_addr lowest_valid_address(void) { return(start_address); }
110 virtual t_addr highest_valid_address(void) { return(start_address+size-1); }
113 virtual t_mem read(t_addr addr)=0;
114 virtual t_mem read(t_addr addr, enum hw_cath skip)=0;
115 virtual t_mem get(t_addr addr)=0;
116 virtual t_mem write(t_addr addr, t_mem val)=0;
117 virtual void set(t_addr addr, t_mem val)=0;
118 virtual void set_bit1(t_addr addr, t_mem bits)=0;
119 virtual void set_bit0(t_addr addr, t_mem bits)=0;
124 * Operators for memory cells
127 class cl_memory_operator: public cl_base
133 class cl_memory_operator *next_operator;
134 class cl_memory_cell *cell;
136 cl_memory_operator(class cl_memory_cell *acell, t_addr addr);
137 cl_memory_operator(class cl_memory_cell *acell, t_addr addr,
138 t_mem *data_place, t_mem the_mask);
140 virtual void set_data(t_mem *data_place, t_mem the_mask);
141 virtual class cl_memory_operator *get_next(void) { return(next_operator); }
142 virtual void set_next(class cl_memory_operator *next) { next_operator= next;}
144 virtual bool match(class cl_hw *the_hw) { return(DD_FALSE); }
145 virtual bool match(class cl_brk *brk) { return(DD_FALSE); }
147 virtual t_mem read(void);
148 virtual t_mem read(enum hw_cath skip) { return(read()); }
149 virtual t_mem write(t_mem val);
152 class cl_hw_operator: public cl_memory_operator
157 cl_hw_operator(class cl_memory_cell *acell, t_addr addr,
158 t_mem *data_place, t_mem the_mask, class cl_hw *ahw);
160 virtual bool match(class cl_hw *the_hw) { return(hw == the_hw); }
162 virtual t_mem read(void);
163 virtual t_mem read(enum hw_cath skip);
164 virtual t_mem write(t_mem val);
167 class cl_event_break_operator: public cl_memory_operator
173 cl_event_break_operator(class cl_memory_cell *acell, t_addr addr,
174 t_mem *data_place, t_mem the_mask,
175 class cl_uc *auc, class cl_brk *the_bp):
176 cl_memory_operator(acell, addr, data_place, the_mask)
182 virtual bool match(class cl_brk *brk) { return(bp == brk); }
185 class cl_write_operator: public cl_event_break_operator
188 cl_write_operator(class cl_memory_cell *acell, t_addr addr,
189 t_mem *data_place, t_mem the_mask,
190 class cl_uc *auc, class cl_brk *the_bp);
192 virtual t_mem write(t_mem val);
195 class cl_read_operator: public cl_event_break_operator
198 cl_read_operator(class cl_memory_cell *acell, t_addr addr,
199 t_mem *data_place, t_mem the_mask,
200 class cl_uc *auc, class cl_brk *the_bp);
202 virtual t_mem read(void);
210 class cl_memory_cell: public cl_base
214 unsigned long nuof_writes, nuof_reads;
221 class cl_memory_operator *operators;
223 cl_memory_cell(void);
224 virtual ~cl_memory_cell(void);
225 virtual int init(void);
227 virtual t_mem *get_data(void) { return(data); }
228 virtual t_mem get_mask(void) { return(mask); }
229 virtual TYPE_UBYTE get_flags(void);
230 virtual bool get_flag(enum cell_flag flag);
231 virtual void set_flags(TYPE_UBYTE what);
232 virtual void set_flag(enum cell_flag flag, bool val);
234 virtual void un_decode(void);
235 virtual void decode(class cl_memory_chip *chip, t_addr addr);
237 virtual t_mem read(void);
238 virtual t_mem read(enum hw_cath skip);
239 virtual t_mem get(void);
240 virtual t_mem write(t_mem val);
241 virtual t_mem set(t_mem val);
243 virtual t_mem add(long what);
244 virtual t_mem wadd(long what);
246 virtual void set_bit1(t_mem bits);
247 virtual void set_bit0(t_mem bits);
249 virtual void append_operator(class cl_memory_operator *op);
250 virtual void prepend_operator(class cl_memory_operator *op);
251 virtual void del_operator(class cl_brk *brk);
253 virtual class cl_memory_cell *add_hw(class cl_hw *hw, int *ith, t_addr addr);
254 //virtual class cl_hw *get_hw(int ith);
255 virtual class cl_event_handler *get_event_handler(void);
258 class cl_dummy_cell: public cl_memory_cell
261 cl_dummy_cell(void): cl_memory_cell() {}
263 virtual t_mem write(t_mem val);
264 virtual t_mem set(t_mem val);
272 class cl_memory_chip;
274 class cl_address_space: public cl_memory
277 class cl_memory_cell **cells, *dummy;
279 class cl_decoder_list *decoders;
281 cl_address_space(char *id, t_addr astart, t_addr asize, int awidth);
282 virtual ~cl_address_space(void);
284 virtual bool is_address_space(void) { return(DD_TRUE); }
286 virtual t_mem read(t_addr addr);
287 virtual t_mem read(t_addr addr, enum hw_cath skip);
288 virtual t_mem get(t_addr addr);
289 virtual t_mem write(t_addr addr, t_mem val);
290 virtual void set(t_addr addr, t_mem val);
291 virtual t_mem wadd(t_addr addr, long what);
292 virtual void set_bit1(t_addr addr, t_mem bits);
293 virtual void set_bit0(t_addr addr, t_mem bits);
295 virtual class cl_memory_cell *get_cell(t_addr addr);
296 virtual int get_cell_flag(t_addr addr);
297 virtual bool get_cell_flag(t_addr addr, enum cell_flag flag);
298 virtual void set_cell_flag(t_addr addr, bool set_to, enum cell_flag flag);
300 virtual bool decode_cell(t_addr addr,
301 class cl_memory_chip *chip, t_addr chipaddr);
302 virtual void undecode_cell(t_addr addr);
303 virtual void undecode_area(class cl_address_decoder *skip,
304 t_addr begin, t_addr end, class cl_console *con);
306 virtual class cl_memory_cell *register_hw(t_addr addr, class cl_hw *hw,
310 virtual void set_brk(t_addr addr, class cl_brk *brk);
311 virtual void del_brk(t_addr addr, class cl_brk *brk);
314 virtual unsigned long get_nuof_reads(void) { return(0); }
315 virtual unsigned long get_nuof_writes(void) { return(0); }
316 virtual void set_nuof_reads(unsigned long value) {}
317 virtual void set_nuof_writes(unsigned long value) {}
321 class cl_address_space_list: public cl_list
326 cl_address_space_list(class cl_uc *the_uc);
327 virtual t_index add(class cl_address_space *mem);
332 * Memory chip (storage)
335 class cl_memory_chip: public cl_memory
341 cl_memory_chip(char *id, int asize, int awidth, int initial= -1);
342 virtual ~cl_memory_chip(void);
343 virtual int init(void);
345 virtual bool is_chip(void) { return(DD_TRUE); }
347 virtual t_mem *get_slot(t_addr addr);
349 virtual t_mem read(t_addr addr) { return(get(addr)); }
350 virtual t_mem read(t_addr addr, enum hw_cath skip) { return(get(addr)); }
351 virtual t_mem get(t_addr addr);
352 virtual t_mem write(t_addr addr, t_mem val) { set(addr, val); return(val); }
353 virtual void set(t_addr addr, t_mem val);
354 virtual void set_bit1(t_addr addr, t_mem bits);
355 virtual void set_bit0(t_addr addr, t_mem bits);
363 class cl_address_decoder: public cl_base
366 class cl_address_space *address_space;
367 class cl_memory_chip *memchip;
368 t_addr as_begin, as_end;
372 cl_address_decoder(class cl_memory *as, class cl_memory *chip,
373 t_addr asb, t_addr ase, t_addr cb);
374 virtual ~cl_address_decoder(void);
375 virtual int init(void);
377 virtual bool activate(class cl_console *con);
379 virtual bool fully_covered_by(t_addr begin, t_addr end);
380 virtual bool is_in(t_addr begin, t_addr end);
381 virtual bool covers(t_addr begin, t_addr end);
383 virtual bool shrink_out_of(t_addr begin, t_addr end);
384 virtual class cl_address_decoder *split(t_addr begin, t_addr end);
387 /* List of address decoders */
389 class cl_decoder_list: public cl_sorted_list
394 cl_decoder_list(t_index alimit, t_index adelta, bool bychip);
396 virtual void *key_of(void *item);
397 virtual int compare(void *key1, void *key2);
407 class cl_event_address_space_added: public cl_event
410 class cl_address_space *as;
411 cl_event_address_space_added(class cl_address_space *the_as):
412 cl_event(ev_address_space_added)
418 * Errors in memory handling
423 class cl_error_mem: public cl_error
426 class cl_memory *mem;
429 cl_error_mem(class cl_memory *amem, t_addr aaddr);
432 class cl_error_mem_invalid_address: public cl_error_mem
435 cl_error_mem_invalid_address(class cl_memory *amem, t_addr aaddr);
437 virtual void print(class cl_commander *c);
440 class cl_error_mem_non_decoded: public cl_error_mem
443 cl_error_mem_non_decoded(class cl_memory *amem, t_addr aaddr);
445 virtual void print(class cl_commander *c);
448 class cl_mem_error_registry: public cl_error_registry
451 cl_mem_error_registry(void);