ucsim-0.2.37-pre3 into cvs
[fw/sdcc] / sim / ucsim / sim.src / uccl.h
1 /*
2  * Simulator of microcontrollers (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 UCCL_HEADER
29 #define 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
40
41 /* Counter to count clock ticks */
42
43 #define TICK_RUN        0x01
44 #define TICK_INISR      0x02
45 #define TICK_IDLE       0x03
46
47 class cl_ticker: public cl_base
48 {
49 public:
50   unsigned long ticks;
51   int options; // see TICK_XXX above
52   int dir;
53   char *name;
54
55   cl_ticker(int adir, int in_isr, char *aname);
56   ~cl_ticker(void);
57   
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);
61 };
62
63
64 /* Abstract microcontroller */
65
66 class cl_uc: public cl_base
67 {
68 public:
69   int type;                     // CPU family
70   int technology;               // CMOS, HMOS
71   int state;                    // GO, IDLE, PD
72   class cl_list *options;
73
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
80
81   class brk_coll *fbrk;         // Collection of FETCH break-points
82   class brk_coll *ebrk;         // Collection of EVENT breakpoints
83   class cl_sim *sim;
84   class cl_list *mems;
85   class cl_list *hws;
86
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
90
91   t_addr sp_max;
92   t_addr sp_avg;
93
94 public:
95   cl_uc(class cl_sim *asim);
96   ~cl_uc(void);
97   virtual int init(void);
98   virtual char *id_string(void);
99   virtual void reset(void);
100
101   // making objects
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);
106
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);
114
115   // file handling
116   virtual long read_hex_file(const char *name);
117
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);
124
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);
130
131   // "virtual" timers
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);
141
142   // execution
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);
149
150   virtual int it_priority(uchar ie_mask) {return(0);}
151
152   // stack tracking
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);
157
158   // breakpoints
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);
165
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);
175
176   /* Following fields and virtual methods defined in uc51 I don't have
177      energy to redesign them:-( */
178 public:
179   uchar port_pins[3];   // Port pins
180 public:
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) {}
186 };
187
188
189 #endif
190
191 /* End of uccl.h */