2 * Simulator of microcontrollers (stackcl.h)
4 * Copyright (C) 2000 Drotos Daniel
6 * To contact author send email to dr.dkdb@gmail.com
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
28 #ifndef SIM_STACKCL_HEADER
29 #define SIM_STACKCL_HEADER
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
52 enum stack_op operation
;
53 t_addr PC
; // of instruction
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
);
64 virtual void print_info(class cl_console_base
*con
);
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
83 t_addr called_addr
; // called routine
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);
90 virtual const char *get_op_name(void);
91 virtual void print_info(class cl_console_base
*con
);
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
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);
106 virtual const char *get_op_name(void);
107 virtual void print_info(class cl_console_base
*con
);
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
118 t_mem data
; // pushed data
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);
123 virtual const char *get_op_name(void);
124 virtual void print_info(class cl_console_base
*con
);
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
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);
138 virtual const char *get_op_name(void);
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
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);
152 virtual const char *get_op_name(void);
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
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);
166 virtual const char *get_op_name(void);
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
180 static class cl_error_class
*error_stack_class
;
182 cl_error_stack(void);
186 * Stack overflow error
188 class cl_error_stack_overflow
: public cl_error_stack
191 t_addr PC
, SP_before
, SP_after
;
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
204 cl_error_stack_tracker(void);
207 class cl_error_stack_tracker_wrong_handle
: public cl_error_stack_tracker
210 bool write_operation
;
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
219 class cl_stack_op
*operation
;
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
229 class cl_stack_op
*top
, *operation
;
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
240 class cl_stack_op
*operation
;
241 int unread_data_size
;
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
252 cl_stack_error_registry(void);
258 /* End of sim.src/stackcl.h */