2 * Simulator of microcontrollers (xacl.h)
4 * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
6 * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
7 * Other contributors include:
8 * Karl Bongers karl@turbobit.com,
9 * Johan Knol johan.knol@iduna.nl
13 /* This file is part of microcontroller simulator: ucsim.
15 UCSIM is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
20 UCSIM is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with UCSIM; see the file COPYING. If not, write to the Free
27 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
39 * Base type of XA microcontrollers
42 class cl_xa: public cl_uc
49 class cl_mem *sfr, *iram;
51 // for now make it as simple as possible
52 // TYPE_UBYTE mem_direct[1024*2];
53 //#ifndef WORDS_BIGENDIAN
54 // TYPE_UWORD *wmem_direct; /* word pointer at mem_direct */
58 cl_xa(class cl_sim *asim);
59 virtual int init(void);
60 virtual char *id_string(void);
62 virtual class cl_mem *mk_mem(enum mem_class type, char *class_name);
63 virtual t_addr get_mem_size(enum mem_class type);
64 virtual void mk_hw_elements(void);
66 virtual struct dis_entry *dis_tbl(void);
68 virtual struct name_entry *sfr_tbl(void);
69 virtual struct name_entry *bit_tbl(void);
70 virtual char *get_dir_name(short);
71 virtual char *get_bit_name(short);
73 virtual int inst_length(t_addr addr);
74 virtual int inst_branch(t_addr addr);
75 virtual int longest_inst(void);
77 virtual int get_disasm_info(t_addr addr,
84 virtual char *disass(t_addr addr, char *sep);
85 virtual void print_regs(class cl_console *con);
87 virtual int exec_inst(void);
88 virtual int get_reg(int word_flag, unsigned int index);
90 virtual void store1(t_addr addr, unsigned char val);
91 virtual void store2(t_addr addr, unsigned short val);
92 virtual unsigned char get1(t_addr addr);
93 virtual unsigned short get2(t_addr addr);
95 virtual bool get_bit(int bit);
96 virtual void set_bit(int bit, int value);
102 /* following are macros which get substituted for FUNC1() and FUNC2()
103 in the inst.cc to form the body of ADD,ADDC,SUB,XOR,... */
104 /* can I put these in the .cc file and still have them do the inline thing? */
105 /*-------------------------------------
106 add - flags changed:C,AC,V,N,Z.
107 |---------------------------------------*/
108 inline unsigned char add1(unsigned char dst, unsigned char src)
113 flags &= ~BIT_ALL; /* clear these bits */
115 if (result == 0) flags |= BIT_Z;
116 if (result > 0xff) flags |= BIT_C;
117 if (result & 0x80) flags |= BIT_N;
118 /* fixme: do AC, V */
120 return (unsigned char) result;
123 inline unsigned short add2(unsigned short dst, unsigned short src)
128 flags &= ~BIT_ALL; /* clear these bits */
130 if (result == 0) flags |= BIT_Z;
131 if (result > 0xff) flags |= BIT_C;
132 if (result & 0x80) flags |= BIT_N;
133 /* fixme: do AC, V */
135 return (unsigned short) result;
138 /*-------------------------------------
139 addc - flags changed:C,AC,V,N,Z.
140 |---------------------------------------*/
141 inline unsigned char addc1(unsigned char dst, unsigned char src)
147 flags &= ~BIT_ALL; /* clear these bits */
148 result = dst + src + 1;
150 flags &= ~BIT_ALL; /* clear these bits */
153 if (result == 0) flags |= BIT_Z;
154 if (result > 0xff) flags |= BIT_C;
155 if (result & 0x80) flags |= BIT_N;
156 /* fixme: do AC, V */
158 return (unsigned char) result;
161 inline unsigned short addc2(unsigned short dst, unsigned short src)
166 flags &= ~BIT_ALL; /* clear these bits */
168 flags &= ~BIT_ALL; /* clear these bits */
169 result = dst + src + 1;
171 flags &= ~BIT_ALL; /* clear these bits */
174 if (result == 0) flags |= BIT_Z;
175 if (result > 0xff) flags |= BIT_C;
176 if (result & 0x80) flags |= BIT_N;
177 /* fixme: do AC, V */
179 return (unsigned short) result;
182 /*-------------------------------------
183 sub - flags changed:C,AC,V,N,Z.
184 |---------------------------------------*/
185 inline unsigned char sub1(unsigned char dst, unsigned char src)
190 flags &= ~BIT_ALL; /* clear these bits */
192 if (result == 0) flags |= BIT_Z;
193 if (result > 0xff) flags |= BIT_C;
194 if (dst < src) flags |= BIT_N;
195 /* fixme: do AC, V */
197 return (unsigned char) result;
200 inline unsigned short sub2(unsigned short dst, unsigned short src)
205 flags &= ~BIT_ALL; /* clear these bits */
207 if (result == 0) flags |= BIT_Z;
208 if (result > 0xff) flags |= BIT_C;
209 if (dst < src) flags |= BIT_N;
210 /* fixme: do AC, V */
212 return (unsigned short) result;
215 /*-------------------------------------
216 subb - flags changed:C,AC,V,N,Z.
217 |---------------------------------------*/
218 inline unsigned char subb1(unsigned char dst, unsigned char src)
224 flags &= ~BIT_ALL; /* clear these bits */
225 result = dst - src - 1;
227 flags &= ~BIT_ALL; /* clear these bits */
230 if (result == 0) flags |= BIT_Z;
231 if (result > 0xff) flags |= BIT_C;
232 if (dst < src) flags |= BIT_N;
233 /* fixme: do AC, V */
235 return (unsigned char) result;
238 inline unsigned short subb2(unsigned short dst, unsigned short src)
243 flags &= ~BIT_ALL; /* clear these bits */
245 flags &= ~BIT_ALL; /* clear these bits */
246 result = dst - src - 1;
248 flags &= ~BIT_ALL; /* clear these bits */
251 if (result == 0) flags |= BIT_Z;
252 if (result > 0xff) flags |= BIT_C;
253 if (dst < src) flags |= BIT_N;
254 /* fixme: do AC, V */
256 return (unsigned short) result;
259 /*-------------------------------------
260 cmp - flags changed:C,AC,V,N,Z.
261 |---------------------------------------*/
262 inline unsigned char cmp1(unsigned char dst, unsigned char src)
267 flags &= ~BIT_ALL; /* clear these bits */
269 if (result == 0) flags |= BIT_Z;
270 if (result > 0xff) flags |= BIT_C;
271 if (dst < src) flags |= BIT_N;
272 /* fixme: do AC, V */
274 return (unsigned char) dst;
277 inline unsigned short cmp2(unsigned short dst, unsigned short src)
282 flags &= ~BIT_ALL; /* clear these bits */
284 if (result == 0) flags |= BIT_Z;
285 if (result > 0xff) flags |= BIT_C;
286 if (dst < src) flags |= BIT_N;
287 /* fixme: do AC, V */
289 return (unsigned short) dst;
292 /*-------------------------------------
293 and - flags changed:N,Z.
294 |---------------------------------------*/
295 inline unsigned char and1(unsigned char dst, unsigned char src)
299 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
301 if (result == 0) flags |= BIT_Z;
302 if (result & 0x80) flags |= BIT_N;
304 return (unsigned char) result;
307 inline unsigned short and2(unsigned short dst, unsigned short src)
311 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
313 if (result == 0) flags |= BIT_Z;
314 if (result & 0x80) flags |= BIT_N;
316 return (unsigned short) result;
319 /*-------------------------------------
320 or - flags changed:N,Z.
321 |---------------------------------------*/
322 inline unsigned char or1(unsigned char dst, unsigned char src)
326 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
328 if (result == 0) flags |= BIT_Z;
329 if (result & 0x80) flags |= BIT_N;
331 return (unsigned char) result;
334 inline unsigned short or2(unsigned short dst, unsigned short src)
338 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
340 if (result == 0) flags |= BIT_Z;
341 if (result & 0x80) flags |= BIT_N;
343 return (unsigned short) result;
346 /*-------------------------------------
347 xor - flags changed:N,Z.
348 |---------------------------------------*/
349 inline unsigned char xor1(unsigned char dst, unsigned char src)
352 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
354 if (dst == 0) flags |= BIT_Z;
355 if (dst & 0x80) flags |= BIT_N;
357 return (unsigned char) dst;
360 inline unsigned short xor2(unsigned short dst, unsigned short src)
363 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
365 if (dst == 0) flags |= BIT_Z;
366 if (dst & 0x8000) flags |= BIT_N;
368 return (unsigned short) dst;
371 /*-------------------------------------
372 mov - flags changed:N,Z.
373 |---------------------------------------*/
374 inline unsigned char mov1(unsigned char dst, unsigned char src)
377 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
379 if (dst == 0) flags |= BIT_Z;
380 if (dst & 0x80) flags |= BIT_N;
382 return (unsigned char) dst;
385 inline unsigned short mov2(unsigned short dst, unsigned short src)
388 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
390 if (dst == 0) flags |= BIT_Z;
391 if (dst & 0x8000) flags |= BIT_N;
393 return (unsigned short) dst;
399 /* End of xa.src/xacl.h */