2 * Simulator of microcontrollers (sim.src/uccl.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_UCCL_HEADER
29 #define SIM_UCCL_HEADER
42 /* Counter to count clock ticks */
45 #define TICK_INISR 0x02
46 #define TICK_IDLE 0x03
48 class cl_ticker: public cl_base
52 int options; // see TICK_XXX above
56 cl_ticker(int adir, int in_isr, char *aname);
57 virtual ~cl_ticker(void);
59 virtual int tick(int nr);
60 virtual double get_rtime(double xtal);
61 virtual void dump(int nr, double xtal, class cl_console *con);
65 /* Options of the microcontroller */
66 class cl_xtal_option: public cl_optref
71 cl_xtal_option(class cl_uc *the_uc);
72 virtual void option_changed(void);
75 /* Abstract microcontroller */
77 class cl_uc: public cl_base
80 int type; // CPU family
81 int technology; // CMOS, HMOS
82 int state; // GO, IDLE, PD
83 //class cl_list *options;
84 class cl_xtal_option *xtal_option;
86 t_addr PC, instPC; // Program Counter
87 bool inst_exec; // Instruction is executed
88 class cl_ticker *ticks; // Nr of XTAL clocks
89 class cl_ticker *isr_ticks; // Time in ISRs
90 class cl_ticker *idle_ticks; // Time in idle mode
91 class cl_list *counters; // User definable timers (tickers)
92 int inst_ticks; // ticks of an instruction
93 double xtal; // Clock speed
95 int brk_counter; // Number of breakpoints
96 class brk_coll *fbrk; // Collection of FETCH break-points
97 class brk_coll *ebrk; // Collection of EVENT breakpoints
99 //class cl_list *mems;
102 class cl_list *memchips; // v3
103 class cl_address_space_list *address_spaces;
104 class cl_address_space *rom; // Required for almost every uc
106 //class cl_list *address_decoders;
108 class cl_irqs *it_sources; // Sources of interrupts
109 class cl_list *it_levels; // Follow interrupt services
110 class cl_list *stack_ops; // Track stack operations
112 class cl_list *errors; // Errors of instruction execution
113 class cl_list *events; // Events happened during inst exec
119 cl_uc(class cl_sim *asim);
120 virtual ~cl_uc(void);
121 virtual int init(void);
122 virtual char *id_string(void);
123 virtual void reset(void);
126 //virtual class cl_m *mk_mem(enum mem_class type, char *class_name);
127 virtual void make_memories(void);
128 //virtual t_addr get_mem_size(char *id);
129 //virtual int get_mem_width(char *id);
130 virtual void mk_hw_elements(void);
131 virtual void build_cmdset(class cl_cmdset *cmdset);
133 // manipulating memories
134 virtual t_mem read_mem(char *id, t_addr addr);
135 virtual t_mem get_mem(char *id, t_addr addr);
136 virtual void write_mem(char *id, t_addr addr, t_mem val);
137 virtual void set_mem(char *id, t_addr addr, t_mem val);
138 virtual class cl_address_space *address_space(char *id);
139 virtual class cl_memory *memory(char *id);
142 virtual long read_hex_file(const char *nam);
144 // instructions, code analyzer
145 virtual void analyze(t_addr addr) {}
146 virtual bool inst_at(t_addr addr);
147 virtual void set_inst_at(t_addr addr);
148 virtual void del_inst_at(t_addr addr);
149 virtual bool there_is_inst(void);
151 // manipulating hw elements
152 virtual class cl_hw *get_hw(enum hw_cath cath, int *idx);
153 virtual class cl_hw *get_hw(char *id_string, int *idx);
154 virtual class cl_hw *get_hw(enum hw_cath cath, int hwid, int *idx);
155 virtual class cl_hw *get_hw(char *id_string, int hwid, int *idx);
158 virtual int tick_hw(int cycles);
159 virtual void do_extra_hw(int cycles);
160 virtual int tick(int cycles);
161 virtual class cl_ticker *get_counter(int nr);
162 virtual class cl_ticker *get_counter(char *nam);
163 virtual void add_counter(class cl_ticker *ticker, int nr);
164 virtual void add_counter(class cl_ticker *ticker, char *nam);
165 virtual void del_counter(int nr);
166 virtual void del_counter(char *nam);
167 virtual double get_rtime(void);
168 virtual int clock_per_cycle(void);
171 virtual t_mem fetch(void);
172 virtual bool fetch(t_mem *code);
173 virtual int do_inst(int step);
174 virtual void pre_inst(void);
175 virtual int exec_inst(void);
176 virtual void post_inst(void);
178 virtual int it_priority(uchar ie_mask) {return(0);}
181 virtual void stack_write(class cl_stack_op *op);
182 virtual void stack_read(class cl_stack_op *op);
185 virtual class cl_fetch_brk *fbrk_at(t_addr addr);
186 virtual class cl_ev_brk *ebrk_at(t_addr addr, char *id);
187 virtual class cl_brk *brk_by_nr(int nr);
188 virtual class cl_brk *brk_by_nr(class brk_coll *bpcoll, int nr);
189 virtual void rm_ebrk(t_addr addr, char *id);
190 virtual bool rm_brk(int nr);
191 virtual void put_breaks(void);
192 virtual void remove_all_breaks(void);
193 virtual int make_new_brknr(void);
194 virtual class cl_ev_brk *mk_ebrk(enum brk_perm perm,
195 class cl_address_space *mem,
196 char op, t_addr addr, int hit);
197 virtual void check_events(void);
199 // disassembling and symbol recognition
200 virtual char *disass(t_addr addr, char *sep);
201 virtual struct dis_entry *dis_tbl(void);
202 virtual struct name_entry *sfr_tbl(void);
203 virtual struct name_entry *bit_tbl(void);
204 virtual void print_disass(t_addr addr, class cl_console *con);
205 virtual void print_regs(class cl_console *con);
206 virtual int inst_length(t_addr addr);
207 virtual int inst_branch(t_addr addr);
208 virtual int longest_inst(void);
209 virtual bool get_name(t_addr addr, struct name_entry tab[], char *buf);
210 virtual bool symbol2address(char *sym, struct name_entry tab[],
212 virtual char *symbolic_bit_name(t_addr bit_address,
213 class cl_memory *mem,
217 /* Converting abstract address spaces into real ones */
218 virtual class cl_address_space *bit2mem(t_addr bitaddr,
221 virtual t_addr bit_address(class cl_memory *mem,
223 int bit_number) { return(-1); }
225 // messages from app to handle and broadcast
226 virtual bool handle_event(class cl_event &event);
227 //virtual void mem_cell_changed(class cl_address_space *mem, t_addr addr);
228 virtual void address_space_added(class cl_address_space *as);
231 virtual void error(class cl_error *error);
232 virtual void check_errors(void);
234 /* Following fields and virtual methods defined in uc51 I don't have
235 energy to redesign them:-( */
237 virtual void eram2xram(void) {} // Dirty hack for 51R
238 virtual void xram2eram(void) {}
248 ERROR_CLASS_DECL(unknown_code): public cl_error
253 cl_error_unknown_code(class cl_uc *the_uc);
255 virtual void print(class cl_commander *c);