Imported Upstream version 2.9.0
[debian/cc1111] / sim / ucsim / sim.src / uccl.h
1 /*
2  * Simulator of microcontrollers (sim.src/uccl.h)
3  *
4  * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
5  *
6  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
7  *
8  */
9
10 /* This file is part of microcontroller simulator: ucsim.
11
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.
16
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.
21
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
25 02111-1307, USA. */
26 /*@1@*/
27
28 #ifndef SIM_UCCL_HEADER
29 #define SIM_UCCL_HEADER
30
31 // prj
32 #include "stypes.h"
33 #include "pobjcl.h"
34
35 // sim
36 #include "hwcl.h"
37 #include "memcl.h"
38 #include "brkcl.h"
39 #include "stackcl.h"
40
41
42 /* Counter to count clock ticks */
43
44 #define TICK_RUN        0x01
45 #define TICK_INISR      0x02
46 #define TICK_IDLE       0x03
47
48 class cl_ticker: public cl_base
49 {
50 public:
51   unsigned long ticks;
52   int options; // see TICK_XXX above
53   int dir;
54   //char *name;
55
56   cl_ticker(int adir, int in_isr, const char *aname);
57   virtual ~cl_ticker(void);
58
59   virtual int tick(int nr);
60   virtual double get_rtime(double xtal);
61   virtual void dump(int nr, double xtal, class cl_console_base *con);
62 };
63
64
65 /* Options of the microcontroller */
66 class cl_xtal_option: public cl_optref
67 {
68 protected:
69   class cl_uc *uc;
70 public:
71   cl_xtal_option(class cl_uc *the_uc);
72   virtual void option_changed(void);
73 };
74
75 /* Abstract microcontroller */
76
77 class cl_uc: public cl_base
78 {
79 public:
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;
85
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
94
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
98   class cl_sim *sim;
99   //class cl_list *mems;
100   class cl_hws *hws;
101
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
105
106   //class cl_list *address_decoders;
107
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
111
112   class cl_list *errors;        // Errors of instruction execution
113   class cl_list *events;        // Events happened during inst exec
114
115   t_addr sp_max;
116   t_addr sp_avg;
117
118 public:
119   cl_uc(class cl_sim *asim);
120   virtual ~cl_uc(void);
121   virtual int init(void);
122   virtual const char *id_string(void);
123   virtual void reset(void);
124
125   // making objects
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);
132
133   // manipulating memories
134   virtual t_mem read_mem(const char *id, t_addr addr);
135   virtual t_mem get_mem(const char *id, t_addr addr);
136   virtual void write_mem(const char *id, t_addr addr, t_mem val);
137   virtual void set_mem(const char *id, t_addr addr, t_mem val);
138   virtual class cl_address_space *address_space(const char *id);
139   virtual class cl_memory *memory(const char *id);
140
141   // file handling
142   virtual long read_hex_file(const char *nam);
143
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);
150
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);
156
157   // "virtual" timers
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);
169
170   // execution
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);
177
178   virtual int it_priority(uchar ie_mask) {return(0);}
179
180   // stack tracking
181   virtual void stack_write(class cl_stack_op *op);
182   virtual void stack_read(class cl_stack_op *op);
183
184   // breakpoints
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);
198
199   // disassembling and symbol recognition
200   virtual const char *disass(t_addr addr, const 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_base *con);
205   virtual void print_regs(class cl_console_base *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[],
211                               t_addr *addr);
212   virtual char *symbolic_bit_name(t_addr bit_address,
213                                   class cl_memory *mem,
214                                   t_addr mem_addr,
215                                   t_mem bit_mask);
216
217   /* Converting abstract address spaces into real ones */
218   virtual class cl_address_space *bit2mem(t_addr bitaddr,
219                                           t_addr *memaddr,
220                                           t_mem *bitmask);
221   virtual t_addr bit_address(class cl_memory *mem,
222                              t_addr mem_address,
223                              int bit_number) { return(-1); }
224
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);
229
230   // Error handling
231   virtual void error(class cl_error *error);
232   virtual void check_errors(void);
233
234   /* Following fields and virtual methods defined in uc51 I don't have
235      energy to redesign them:-( */
236 public:
237   virtual void eram2xram(void) {} // Dirty hack for 51R
238   virtual void xram2eram(void) {}
239 };
240
241
242 /*
243  * Errors
244  */
245
246 #include "errorcl.h"
247
248 class cl_error_unknown_code: public cl_error
249 {
250 protected:
251   class cl_uc *uc;
252 public:
253   cl_error_unknown_code(class cl_uc *the_uc);
254
255   virtual void print(class cl_commander_base *c);
256 };
257
258 class cl_uc_error_registry: public cl_error_registry
259 {
260 public:
261   cl_uc_error_registry(void);
262 };
263
264 #endif
265
266
267 /* End of uccl.h */