[ucsim] Update email and file info, fix stm8 flash controller
[sdcc.git] / sdcc / sim / ucsim / src / core / sim.src / stackcl.h
blob5569be720d25aca5f9bcdeccf8262869416f8904
1 /*
2 * Simulator of microcontrollers (stackcl.h)
4 * Copyright (C) 2000 Drotos Daniel
5 *
6 * To contact author send email to dr.dkdb@gmail.com
8 */
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
25 02111-1307, USA. */
26 /*@1@*/
28 #ifndef SIM_STACKCL_HEADER
29 #define SIM_STACKCL_HEADER
31 #include "stypes.h"
32 #include "pobjcl.h"
33 #include "errorcl.h"
36 enum stack_op {
37 stack_call = 0x01,
38 stack_intr = 0x02,
39 stack_push = 0x04,
40 stack_ret = 0x08,
41 stack_iret = 0x10,
42 stack_pop = 0x20
45 const int stack_write_operation= (stack_call|stack_intr|stack_push);
46 const int stack_read_operation = (stack_ret|stack_iret|stack_pop);
48 /* Abstraction of a stack operation */
49 class cl_stack_op: public cl_base
51 protected:
52 enum stack_op operation;
53 t_addr PC; // of instruction
54 t_addr SP_before;
55 t_addr SP_after;
56 public:
57 cl_stack_op(enum stack_op op,
58 t_addr iPC, t_addr iSP_before, t_addr iSP_after);
59 virtual ~cl_stack_op(void);
60 virtual class cl_stack_op *mk_copy(void);
61 static void info_head(class cl_console_base *con);
62 virtual void info(class cl_console_base *con, class cl_uc *uc);
63 protected:
64 virtual void print_info(class cl_console_base *con);
65 public:
66 virtual const char *get_op_name(void);
67 virtual const char *get_matching_name(void) { return("unknown"); }
68 virtual bool sp_increased(void);
69 virtual int data_size(void);
70 virtual bool match(class cl_stack_op *op);
71 virtual enum stack_op get_op(void) { return(operation); }
72 virtual enum stack_op get_matching_op(void) { return(operation); }
73 virtual t_addr get_after(void) { return(SP_after); }
74 virtual t_addr get_before(void) { return(SP_before); }
75 virtual t_addr get_pc(void) { return(PC); }
76 virtual bool can_removed(class cl_stack_op *op);
79 /* Call of a subroutine, must match with RET */
80 class cl_stack_call: public cl_stack_op
82 protected:
83 t_addr called_addr; // called routine
84 t_addr pushed_addr;
85 public:
86 cl_stack_call(t_addr iPC, t_addr called, t_addr pushed,
87 t_addr iSP_before, t_addr iSP_after);
88 virtual class cl_stack_op *mk_copy(void);
89 protected:
90 virtual const char *get_op_name(void);
91 virtual void print_info(class cl_console_base *con);
92 public:
93 virtual const char *get_matching_name(void);
94 virtual enum stack_op get_matching_op(void);
95 virtual bool match(class cl_stack_op *op);
98 /* Call of an ISR, must match with IRET */
99 class cl_stack_intr: public cl_stack_call
101 public:
102 cl_stack_intr(t_addr iPC, t_addr called, t_addr pushed,
103 t_addr iSP_before, t_addr iSP_after);
104 virtual class cl_stack_op *mk_copy(void);
105 protected:
106 virtual const char *get_op_name(void);
107 virtual void print_info(class cl_console_base *con);
108 public:
109 virtual const char *get_matching_name(void);
110 virtual enum stack_op get_matching_op(void);
111 virtual bool match(class cl_stack_op *op);
114 /* Push data to stack, must match with POP */
115 class cl_stack_push: public cl_stack_op
117 protected:
118 t_mem data; // pushed data
119 public:
120 cl_stack_push(t_addr iPC, t_mem idata, t_addr iSP_before, t_addr iSP_after);
121 virtual class cl_stack_op *mk_copy(void);
122 protected:
123 virtual const char *get_op_name(void);
124 virtual void print_info(class cl_console_base *con);
125 public:
126 virtual const char *get_matching_name(void);
127 virtual enum stack_op get_matching_op(void);
128 virtual bool match(class cl_stack_op *op);
131 /* Returning from a subroutine, tos must be CALL */
132 class cl_stack_ret: public cl_stack_call
134 public:
135 cl_stack_ret(t_addr iPC, t_addr iaddr, t_addr iSP_before, t_addr iSP_after);
136 virtual class cl_stack_op *mk_copy(void);
137 protected:
138 virtual const char *get_op_name(void);
139 public:
140 virtual const char *get_matching_name(void);
141 virtual enum stack_op get_matching_op(void);
142 virtual bool match(class cl_stack_op *op);
145 /* Returning from an ISR, yos must be INTR */
146 class cl_stack_iret: public cl_stack_ret
148 public:
149 cl_stack_iret(t_addr iPC, t_addr iaddr, t_addr iSP_before, t_addr iSP_after);
150 virtual class cl_stack_op *mk_copy(void);
151 protected:
152 virtual const char *get_op_name(void);
153 public:
154 virtual const char *get_matching_name(void);
155 virtual enum stack_op get_matching_op(void);
156 virtual bool match(class cl_stack_op *op);
159 /* Pop out data from stack, tos must be PUSH */
160 class cl_stack_pop: public cl_stack_push
162 public:
163 cl_stack_pop(t_addr iPC, t_mem idata, t_addr iSP_before, t_addr iSP_after);
164 virtual class cl_stack_op *mk_copy(void);
165 protected:
166 virtual const char *get_op_name(void);
167 public:
168 virtual const char *get_matching_name(void);
169 virtual enum stack_op get_matching_op(void);
170 virtual bool match(class cl_stack_op *op);
175 * All kind of stack errors
177 class cl_error_stack: public cl_error
179 private:
180 static class cl_error_class *error_stack_class;
181 public:
182 cl_error_stack(void);
186 * Stack overflow error
188 class cl_error_stack_overflow: public cl_error_stack
190 protected:
191 t_addr PC, SP_before, SP_after;
192 public:
193 cl_error_stack_overflow(class cl_stack_op *op);
194 cl_error_stack_overflow(t_addr iPC, t_addr SPbef, t_addr SPaft);
195 virtual void print(class cl_commander_base *c);
199 * All kind of stack tracker errors
201 class cl_error_stack_tracker: public cl_error_stack
203 public:
204 cl_error_stack_tracker(void);
207 class cl_error_stack_tracker_wrong_handle: public cl_error_stack_tracker
209 public:
210 bool write_operation;
211 public:
212 cl_error_stack_tracker_wrong_handle(bool write_op);
213 virtual void print(class cl_commander_base *c);
216 class cl_error_stack_tracker_empty: public cl_error_stack_tracker
218 protected:
219 class cl_stack_op *operation;
220 public:
221 cl_error_stack_tracker_empty(class cl_stack_op *op);
222 virtual ~cl_error_stack_tracker_empty(void);
223 virtual void print(class cl_commander_base *c);
226 class cl_error_stack_tracker_unmatch: public cl_error_stack_tracker
228 protected:
229 class cl_stack_op *top, *operation;
230 public:
231 cl_error_stack_tracker_unmatch(class cl_stack_op *Top,
232 class cl_stack_op *op);
233 virtual ~cl_error_stack_tracker_unmatch(void);
234 virtual void print(class cl_commander_base *c);
237 class cl_error_stack_tracker_inconsistent: public cl_error_stack_tracker
239 protected:
240 class cl_stack_op *operation;
241 int unread_data_size;
242 public:
243 cl_error_stack_tracker_inconsistent(class cl_stack_op *op,
244 int the_unread_data_size);
245 virtual ~cl_error_stack_tracker_inconsistent(void);
246 virtual void print(class cl_commander_base *c);
249 class cl_stack_error_registry: public cl_error_registry
251 public:
252 cl_stack_error_registry(void);
256 #endif
258 /* End of sim.src/stackcl.h */