* sim/ucsim/error.cc, sim/ucsim/errorcl.h,
[fw/sdcc] / sim / ucsim / sim.src / stackcl.h
1 /*
2  * Simulator of microcontrollers (sim.src/stackcl.h)
3  *
4  * Copyright (C) 2000,00 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_STACKCL_HEADER
29 #define SIM_STACKCL_HEADER
30
31 #include "stypes.h"
32 #include "pobjcl.h"
33
34
35 enum stack_op {
36   stack_call   = 0x01,
37   stack_intr   = 0x02,
38   stack_push   = 0x04,
39   stack_ret    = 0x08,
40   stack_iret   = 0x10,
41   stack_pop    = 0x20
42 };
43
44 const int stack_write_operation= (stack_call|stack_intr|stack_push);
45 const int stack_read_operation = (stack_ret|stack_iret|stack_pop);
46
47 /* Abstraction of a stack operation */
48 class cl_stack_op: public cl_base
49 {
50 protected:
51   enum stack_op operation;
52   t_addr PC;    // of instruction
53   t_addr SP_before;
54   t_addr SP_after;
55 public:
56   cl_stack_op(enum stack_op op,
57               t_addr iPC, t_addr iSP_before, t_addr iSP_after);
58   virtual ~cl_stack_op(void);
59   virtual class cl_stack_op *mk_copy(void);
60   static void info_head(class cl_console *con);
61   virtual void info(class cl_console *con, class cl_uc *uc);
62 protected:
63   virtual void print_info(class cl_console *con);
64 public:
65   virtual char *get_op_name(void);
66   virtual char *get_matching_name(void) { return("unknown"); }
67   virtual bool sp_increased(void);
68   virtual int data_size(void);
69   virtual bool match(class cl_stack_op *op);
70   virtual enum stack_op get_op(void) { return(operation); }
71   virtual enum stack_op get_matching_op(void) { return(operation); }
72   virtual t_addr get_after(void) { return(SP_after); }
73   virtual t_addr get_before(void) { return(SP_before); }
74   virtual t_addr get_pc(void) { return(PC); }
75   virtual bool can_removed(class cl_stack_op *op);
76 };
77
78 /* Call of a subrutine, must match with RET */
79 class cl_stack_call: public cl_stack_op
80 {
81 protected:
82   t_addr called_addr; // called routine
83   t_addr pushed_addr;
84 public:
85   cl_stack_call(t_addr iPC, t_addr called, t_addr pushed,
86                 t_addr iSP_before, t_addr iSP_after);
87   virtual class cl_stack_op *mk_copy(void);
88 protected:
89   virtual char *get_op_name(void);
90   virtual void print_info(class cl_console *con);
91 public:
92   virtual char *get_matching_name(void);
93   virtual enum stack_op get_matching_op(void);
94   virtual bool match(class cl_stack_op *op);
95 };
96
97 /* Call of an ISR, must match with IRET */
98 class cl_stack_intr: public cl_stack_call
99 {
100 public:
101   cl_stack_intr(t_addr iPC, t_addr called, t_addr pushed,
102                 t_addr iSP_before, t_addr iSP_after);
103   virtual class cl_stack_op *mk_copy(void);
104 protected:
105   virtual char *get_op_name(void);
106   virtual void print_info(class cl_console *con);
107 public:
108   virtual char *get_matching_name(void);
109   virtual enum stack_op get_matching_op(void);
110   virtual bool match(class cl_stack_op *op);
111 };
112
113 /* Push data to stack, must match with POP */
114 class cl_stack_push: public cl_stack_op
115 {
116 protected:
117   t_mem data;  // pushed data
118 public:
119   cl_stack_push(t_addr iPC, t_mem idata, t_addr iSP_before, t_addr iSP_after);
120   virtual class cl_stack_op *mk_copy(void);
121 protected:
122   virtual char *get_op_name(void);
123   virtual void print_info(class cl_console *con);
124 public:
125   virtual char *get_matching_name(void);
126   virtual enum stack_op get_matching_op(void);
127   virtual bool match(class cl_stack_op *op);
128 };
129
130 /* Returning from a subroutine, tos must be CALL */
131 class cl_stack_ret: public cl_stack_call
132 {
133 public:
134   cl_stack_ret(t_addr iPC, t_addr iaddr, t_addr iSP_before, t_addr iSP_after);
135   virtual class cl_stack_op *mk_copy(void);
136 protected:
137   virtual char *get_op_name(void);
138 public:
139   virtual char *get_matching_name(void);
140   virtual enum stack_op get_matching_op(void);
141   virtual bool match(class cl_stack_op *op);
142 };
143
144 /* Returning from an ISR, yos must be INTR */
145 class cl_stack_iret: public cl_stack_ret
146 {
147 public:
148   cl_stack_iret(t_addr iPC, t_addr iaddr, t_addr iSP_before, t_addr iSP_after);
149   virtual class cl_stack_op *mk_copy(void);
150 protected:
151   virtual char *get_op_name(void);
152 public:
153   virtual char *get_matching_name(void);
154   virtual enum stack_op get_matching_op(void);
155   virtual bool match(class cl_stack_op *op);
156 };
157
158 /* Pop out data from stack, tos must be PUSH */
159 class cl_stack_pop: public cl_stack_push
160 {
161 public:
162   cl_stack_pop(t_addr iPC, t_mem idata, t_addr iSP_before, t_addr iSP_after);
163   virtual class cl_stack_op *mk_copy(void);
164 protected:
165   virtual char *get_op_name(void);
166 public:
167   virtual char *get_matching_name(void);
168   virtual enum stack_op get_matching_op(void);
169   virtual bool match(class cl_stack_op *op);
170 };
171
172
173 /*
174  * All kind of stack errors
175  */
176 class cl_error_stack: public cl_error
177 {
178 private:
179   static class cl_error_class *error_stack_class;
180 public:
181   cl_error_stack(void);
182 };
183
184 /*
185  * All kind of stack tracker errors
186  */
187 class cl_error_stack_tracker: public cl_error_stack
188 {
189 public:
190   cl_error_stack_tracker(void);
191 };
192
193 class cl_error_stack_tracker_wrong_handle: public cl_error_stack_tracker
194 {
195 public:
196   bool write_operation;
197 public:
198   cl_error_stack_tracker_wrong_handle(bool write_op);
199
200   virtual void print(class cl_commander *c);
201 };
202
203 class cl_error_stack_tracker_empty: public cl_error_stack_tracker
204 {
205 protected:
206   class cl_stack_op *operation;
207 public:
208   cl_error_stack_tracker_empty(class cl_stack_op *op);
209   virtual ~cl_error_stack_tracker_empty(void);
210
211   virtual void print(class cl_commander *c);
212 };
213
214 class cl_error_stack_tracker_unmatch: public cl_error_stack_tracker
215 {
216 protected:
217   class cl_stack_op *top, *operation;
218 public:
219   cl_error_stack_tracker_unmatch(class cl_stack_op *Top,
220                                 class cl_stack_op *op);
221   virtual ~cl_error_stack_tracker_unmatch(void);
222
223   virtual void print(class cl_commander *c);
224 };
225
226 class cl_error_stack_tracker_inconsistent: public cl_error_stack_tracker
227 {
228 protected:
229   class cl_stack_op *operation;
230   int unread_data_size;
231 public:
232   cl_error_stack_tracker_inconsistent(class cl_stack_op *op,
233                                       int the_unread_data_size);
234   virtual ~cl_error_stack_tracker_inconsistent(void);
235
236   virtual void print(class cl_commander *c);
237 };
238
239 class cl_stack_error_registry: public cl_error_registry
240 {
241 public:
242   cl_stack_error_registry(void);
243 };
244
245 #endif
246
247
248 /* End of sim.src/stackcl.h */