2 * Simulator of microcontrollers (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
41 /* Counter to count clock ticks */
44 #define TICK_INISR 0x02
45 #define TICK_IDLE 0x03
47 class cl_ticker: public cl_base
51 int options; // see TICK_XXX above
55 cl_ticker(int adir, int in_isr, char *aname);
58 virtual int tick(int nr);
59 virtual double get_rtime(double xtal);
60 virtual void dump(int nr, double xtal, class cl_console *con);
64 /* Abstract microcontroller */
66 class cl_uc: public cl_base
69 int type; // CPU family
70 int technology; // CMOS, HMOS
71 int state; // GO, IDLE, PD
72 class cl_list *options;
74 t_addr PC; // Program Counter
75 class cl_ticker *ticks; // Nr of XTAL clocks
76 class cl_ticker *isr_ticks; // Time in ISRs
77 class cl_ticker *idle_ticks; // Time in idle mode
78 class cl_list *counters; // User definable timers (tickers)
79 double xtal; // Clock speed
81 class brk_coll *fbrk; // Collection of FETCH break-points
82 class brk_coll *ebrk; // Collection of EVENT breakpoints
87 class cl_list *it_sources; // Sources of interrupts
88 class cl_list *it_levels; // Follow interrupt services
89 class cl_list *st_ops; // Track stack operations
95 cl_uc(class cl_sim *asim);
97 virtual int init(void);
98 virtual char *id_string(void);
99 virtual void reset(void);
102 virtual class cl_mem *mk_mem(enum mem_class type);
103 virtual t_addr get_mem_size(enum mem_class type);
104 virtual int get_mem_width(enum mem_class type);
105 virtual void mk_hw_elements(void);
107 // manipulating memories
108 virtual ulong read_mem(enum mem_class type, long addr);
109 virtual ulong get_mem(enum mem_class type, long addr);
110 virtual void write_mem(enum mem_class type, long addr, ulong val);
111 virtual void set_mem(enum mem_class type, long addr, ulong val);
112 virtual class cl_mem *mem(enum mem_class type);
113 virtual uchar *MEM(enum mem_class type);
116 virtual long read_hex_file(const char *name);
118 // instructions, code analyzer
119 virtual void analyze(uint addr) {}
120 virtual bool inst_at(uint addr);
121 virtual void set_inst_at(uint addr);
122 virtual void del_inst_at(uint addr);
123 virtual bool there_is_inst(void);
125 // manipulating hw elements
126 virtual void register_hw_read(enum mem_class, long addr, class cl_hw *hw);
127 virtual void register_hw_write(enum mem_class, long addr, class cl_hw *hw);
128 virtual class cl_hw *get_hw(enum hw_cath cath, int *idx);
129 virtual class cl_hw *get_hw(enum hw_cath cath, int hwid, int *idx);
132 virtual int tick(int cycles);
133 virtual class cl_ticker *get_counter(int nr);
134 virtual class cl_ticker *get_counter(char *name);
135 virtual void add_counter(class cl_ticker *ticker, int nr);
136 virtual void add_counter(class cl_ticker *ticker, char *name);
137 virtual void del_counter(int nr);
138 virtual void del_counter(char *name);
139 virtual double get_rtime(void);
140 virtual int clock_per_cycle(void);
143 virtual t_mem fetch(void);
144 virtual bool fetch(ulong *code);
145 virtual int do_inst(int step);
146 virtual void pre_inst(void);
147 virtual int exec_inst(void);
148 virtual void post_inst(void);
150 virtual int it_priority(uchar ie_mask) {return(0);}
153 virtual void st_push(class cl_stack_op *op);
154 virtual void st_call(class cl_stack_op *op);
155 virtual int st_pop(class cl_stack_op *op);
156 virtual int st_ret(class cl_stack_op *op);
159 virtual class cl_fetch_brk *fbrk_at(long addr);
160 virtual class cl_ev_brk *ebrk_at(t_addr addr, char *id);
161 //virtual void rm_fbrk(long addr);
162 virtual void rm_ebrk(t_addr addr, char *id);
163 virtual void put_breaks(void);
164 virtual void remove_breaks(void);
166 // disassembling and symbol recognition
167 virtual char *disass(uint addr, char *sep);
168 virtual struct dis_entry *dis_tbl(void);
169 virtual struct name_entry *sfr_tbl(void);
170 virtual struct name_entry *bit_tbl(void);
171 virtual void print_disass(uint addr, class cl_console *con);
172 virtual void print_regs(class cl_console *con);
173 virtual int inst_length(uint code);
174 virtual bool get_name(uint addr, struct name_entry tab[], char *buf);
176 /* Following fields and virtual methods defined in uc51 I don't have
177 energy to redesign them:-( */
179 uchar port_pins[3]; // Port pins
181 virtual void proc_write(uchar *addr) {}
182 virtual void set_p_flag(void) {}
183 virtual uchar *get_bit(uchar bitaddr) { return(0); }
184 virtual void eram2xram(void) {} // Dirty hack for 51R
185 virtual void xram2eram(void) {}