e4dd4e4c4c265fca58decb6f0f2fd9003b27fa5e
[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 //extern class cl_error_class error_stack_class;
177 //class cl_error_stack: public cl_error
178 class cl_error_stack: public cl_error
179 {
180 private:
181   static class cl_error_class *error_stack_class;
182 public:
183   cl_error_stack(void);
184 };
185
186 /*
187  * All kind of stack tracker errors
188  */
189 class cl_error_stack_tracker: public cl_error_stack
190 {
191 private:
192   static class cl_error_class *error_stack_tracker_class;
193 public:
194   cl_error_stack_tracker(void);
195 };
196
197 class cl_error_stack_tracker_wrong_handle: public cl_error_stack_tracker
198 {
199 private:
200   static class cl_error_class *error_stack_tracker_wrong_handle_class;
201 public:
202   bool write_operation;
203 public:
204   cl_error_stack_tracker_wrong_handle(bool write_op);
205
206   virtual void print(class cl_commander *c);
207 };
208
209 class cl_error_stack_tracker_empty: public cl_error_stack_tracker
210 {
211 private:
212   static class cl_error_class *error_stack_tracker_empty_class;
213 protected:
214   class cl_stack_op *operation;
215 public:
216   cl_error_stack_tracker_empty(class cl_stack_op *op);
217   virtual ~cl_error_stack_tracker_empty(void);
218
219   virtual void print(class cl_commander *c);
220 };
221
222 class cl_error_stack_tracker_unmatch: public cl_error_stack_tracker
223 {
224 private:
225   static class cl_error_class *error_stack_tracker_unmatch_class;
226 protected:
227   class cl_stack_op *top, *operation;
228 public:
229   cl_error_stack_tracker_unmatch(class cl_stack_op *Top,
230                                 class cl_stack_op *op);
231   virtual ~cl_error_stack_tracker_unmatch(void);
232
233   virtual void print(class cl_commander *c);
234 };
235
236 class cl_error_stack_tracker_inconsistent: public cl_error_stack_tracker
237 {
238 private:
239   static class cl_error_class *error_stack_tracker_inconsistent_class;
240 protected:
241   class cl_stack_op *operation;
242   int unread_data_size;
243 public:
244   cl_error_stack_tracker_inconsistent(class cl_stack_op *op,
245                                       int the_unread_data_size);
246   virtual ~cl_error_stack_tracker_inconsistent(void);
247
248   virtual void print(class cl_commander *c);
249 };
250
251
252 #endif
253
254 /* End of sim.src/stackcl.h */