2 * Simulator of microcontrollers (sim.src/stackcl.h)
4 * Copyright (C) 2000,00 Drotos Daniel, Talker Bt.
6 * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
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
44 const int stack_write_operation= (stack_call|stack_intr|stack_push);
45 const int stack_read_operation = (stack_ret|stack_iret|stack_pop);
47 /* Abstraction of a stack operation */
48 class cl_stack_op: public cl_base
51 enum stack_op operation;
52 t_addr PC; // of instruction
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_base *con);
61 virtual void info(class cl_console_base *con, class cl_uc *uc);
63 virtual void print_info(class cl_console_base *con);
65 virtual const char *get_op_name(void);
66 virtual const 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);
78 /* Call of a subrutine, must match with RET */
79 class cl_stack_call: public cl_stack_op
82 t_addr called_addr; // called routine
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);
89 virtual const char *get_op_name(void);
90 virtual void print_info(class cl_console_base *con);
92 virtual const char *get_matching_name(void);
93 virtual enum stack_op get_matching_op(void);
94 virtual bool match(class cl_stack_op *op);
97 /* Call of an ISR, must match with IRET */
98 class cl_stack_intr: public cl_stack_call
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);
105 virtual const char *get_op_name(void);
106 virtual void print_info(class cl_console_base *con);
108 virtual const char *get_matching_name(void);
109 virtual enum stack_op get_matching_op(void);
110 virtual bool match(class cl_stack_op *op);
113 /* Push data to stack, must match with POP */
114 class cl_stack_push: public cl_stack_op
117 t_mem data; // pushed data
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);
122 virtual const char *get_op_name(void);
123 virtual void print_info(class cl_console_base *con);
125 virtual const char *get_matching_name(void);
126 virtual enum stack_op get_matching_op(void);
127 virtual bool match(class cl_stack_op *op);
130 /* Returning from a subroutine, tos must be CALL */
131 class cl_stack_ret: public cl_stack_call
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);
137 virtual const char *get_op_name(void);
139 virtual const char *get_matching_name(void);
140 virtual enum stack_op get_matching_op(void);
141 virtual bool match(class cl_stack_op *op);
144 /* Returning from an ISR, yos must be INTR */
145 class cl_stack_iret: public cl_stack_ret
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);
151 virtual const char *get_op_name(void);
153 virtual const char *get_matching_name(void);
154 virtual enum stack_op get_matching_op(void);
155 virtual bool match(class cl_stack_op *op);
158 /* Pop out data from stack, tos must be PUSH */
159 class cl_stack_pop: public cl_stack_push
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);
165 virtual const char *get_op_name(void);
167 virtual const char *get_matching_name(void);
168 virtual enum stack_op get_matching_op(void);
169 virtual bool match(class cl_stack_op *op);
174 * All kind of stack errors
176 class cl_error_stack: public cl_error
179 static class cl_error_class *error_stack_class;
181 cl_error_stack(void);
185 * All kind of stack tracker errors
187 class cl_error_stack_tracker: public cl_error_stack
190 cl_error_stack_tracker(void);
193 class cl_error_stack_tracker_wrong_handle: public cl_error_stack_tracker
196 bool write_operation;
198 cl_error_stack_tracker_wrong_handle(bool write_op);
200 virtual void print(class cl_commander_base *c);
203 class cl_error_stack_tracker_empty: public cl_error_stack_tracker
206 class cl_stack_op *operation;
208 cl_error_stack_tracker_empty(class cl_stack_op *op);
209 virtual ~cl_error_stack_tracker_empty(void);
211 virtual void print(class cl_commander_base *c);
214 class cl_error_stack_tracker_unmatch: public cl_error_stack_tracker
217 class cl_stack_op *top, *operation;
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);
223 virtual void print(class cl_commander_base *c);
226 class cl_error_stack_tracker_inconsistent: public cl_error_stack_tracker
229 class cl_stack_op *operation;
230 int unread_data_size;
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);
236 virtual void print(class cl_commander_base *c);
239 class cl_stack_error_registry: public cl_error_registry
242 cl_stack_error_registry(void);
248 /* End of sim.src/stackcl.h */