*** empty log message ***
[fw/sdcc] / sim / ucsim / xa.src / xacl.h
1 /*
2  * Simulator of microcontrollers (xacl.h)
3  *
4  * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
5  *
6  * Written by Karl Bongers karl@turbobit.com
7  * 
8  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
9  *
10  */
11
12 /* This file is part of microcontroller simulator: ucsim.
13
14 UCSIM is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 UCSIM is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with UCSIM; see the file COPYING.  If not, write to the Free
26 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 02111-1307, USA. */
28 /*@1@*/
29
30 #ifndef XACL_HEADER
31 #define XACL_HEADER
32
33 #include "uccl.h"
34
35 #include "regsxa.h"
36
37 /*
38  * Base type of XA microcontrollers
39  */
40
41 class cl_xa: public cl_uc
42 {
43 public:
44   cl_mem *ram;
45   cl_mem *rom;
46   struct t_regs regs;
47
48   class cl_mem *sfr, *iram;
49
50   // for now make it as simple as possible
51 //  TYPE_UBYTE mem_direct[1024*2];
52 //#ifndef WORDS_BIGENDIAN
53 //  TYPE_UWORD *wmem_direct;  /* word pointer at mem_direct */
54 //#endif
55
56 public:
57   cl_xa(class cl_sim *asim);
58   virtual int init(void);
59   virtual char *id_string(void);
60
61   virtual class cl_mem *mk_mem(enum mem_class type, char *class_name);
62   virtual t_addr get_mem_size(enum mem_class type);
63   virtual void mk_hw_elements(void);
64
65   virtual struct dis_entry *dis_tbl(void);
66
67   virtual struct name_entry *sfr_tbl(void);
68   virtual struct name_entry *bit_tbl(void);
69   virtual char *get_dir_name(short);
70   virtual char *get_bit_name(short);
71
72   virtual int inst_length(t_addr addr);
73   virtual int inst_branch(t_addr addr);
74   virtual int longest_inst(void);
75
76   virtual int get_disasm_info(t_addr addr,
77                        int *ret_len,
78                        int *ret_branch,
79                        int *immed_offset,
80                        int *parms,
81                        int *mnemonic);
82
83   virtual char *disass(t_addr addr, char *sep);
84   virtual void print_regs(class cl_console *con);
85
86   virtual int exec_inst(void);
87   virtual int get_reg(int word_flag, unsigned int index);
88
89   virtual void store1(t_addr addr, unsigned char val);
90   virtual void store2(t_addr addr, unsigned char val);
91   virtual unsigned char get1(t_addr addr);
92   virtual unsigned short get2(t_addr addr);
93
94   virtual bool get_bit(int bit);
95   virtual void set_bit(int bit, int value);
96
97 #include "instcl.h"
98
99   private :
100
101    /* following are macros which get substituted for FUNC1() and FUNC2()
102       in the inst.cc to form the body of ADD,ADDC,SUB,XOR,... */
103   /* can I put these in the .cc file and still have them do the inline thing? */
104   /*-------------------------------------
105     add - flags changed:C,AC,V,N,Z.
106   |---------------------------------------*/
107   inline unsigned char add1(unsigned char dst, unsigned char src)
108   {
109     unsigned int result;
110     unsigned char flags;
111     flags = get_psw();
112     flags &= ~BIT_ALL; /* clear these bits */
113     result = dst + src;
114     if (result == 0) flags |= BIT_Z;
115     if (result > 0xff) flags |= BIT_C;
116     if (result & 0x80) flags |= BIT_N;
117     /* fixme: do AC, V */
118     set_psw(flags);
119     return (unsigned char) result;
120   }
121
122   inline unsigned short add2(unsigned short dst, unsigned short src)
123   {
124     unsigned int result;
125     unsigned char flags;
126     flags = get_psw();
127     flags &= ~BIT_ALL; /* clear these bits */
128     result = dst + src;
129     if (result == 0) flags |= BIT_Z;
130     if (result > 0xff) flags |= BIT_C;
131     if (result & 0x80) flags |= BIT_N;
132     /* fixme: do AC, V */
133     set_psw(flags);
134     return (unsigned short) result;
135   }
136
137   /*-------------------------------------
138     addc - flags changed:C,AC,V,N,Z.
139   |---------------------------------------*/
140   inline unsigned char addc1(unsigned char dst, unsigned char src)
141   {
142     unsigned int result;
143     unsigned char flags;
144     flags = get_psw();
145     if (flags & BIT_C) {
146       flags &= ~BIT_ALL; /* clear these bits */
147       result = dst + src + 1;
148     } else {
149       flags &= ~BIT_ALL; /* clear these bits */
150       result = dst + src;
151     }
152     if (result == 0) flags |= BIT_Z;
153     if (result > 0xff) flags |= BIT_C;
154     if (result & 0x80) flags |= BIT_N;
155     /* fixme: do AC, V */
156     set_psw(flags);
157     return (unsigned char) result;
158   }
159
160   inline unsigned short addc2(unsigned short dst, unsigned short src)
161   {
162     unsigned int result;
163     unsigned char flags;
164     flags = get_psw();
165     flags &= ~BIT_ALL; /* clear these bits */
166     if (flags & BIT_C) {
167       flags &= ~BIT_ALL; /* clear these bits */
168       result = dst + src + 1;
169     } else {
170       flags &= ~BIT_ALL; /* clear these bits */
171       result = dst + src;
172     }
173     if (result == 0) flags |= BIT_Z;
174     if (result > 0xff) flags |= BIT_C;
175     if (result & 0x80) flags |= BIT_N;
176     /* fixme: do AC, V */
177     set_psw(flags);
178     return (unsigned short) result;
179   }
180
181   /*-------------------------------------
182     sub - flags changed:C,AC,V,N,Z.
183   |---------------------------------------*/
184   inline unsigned char sub1(unsigned char dst, unsigned char src)
185   {
186     unsigned int result;
187     unsigned char flags;
188     flags = get_psw();
189     flags &= ~BIT_ALL; /* clear these bits */
190     result = dst - src;
191     if (result == 0) flags |= BIT_Z;
192     if (result > 0xff) flags |= BIT_C;
193     if (dst < src) flags |= BIT_N;
194     /* fixme: do AC, V */
195     set_psw(flags);
196     return (unsigned char) result;
197   }
198
199   inline unsigned short sub2(unsigned short dst, unsigned short src)
200   {
201     unsigned int result;
202     unsigned char flags;
203     flags = get_psw();
204     flags &= ~BIT_ALL; /* clear these bits */
205     result = dst - src;
206     if (result == 0) flags |= BIT_Z;
207     if (result > 0xff) flags |= BIT_C;
208     if (dst < src) flags |= BIT_N;
209     /* fixme: do AC, V */
210     set_psw(flags);
211     return (unsigned short) result;
212   }
213
214   /*-------------------------------------
215     subb - flags changed:C,AC,V,N,Z.
216   |---------------------------------------*/
217   inline unsigned char subb1(unsigned char dst, unsigned char src)
218   {
219     unsigned int result;
220     unsigned char flags;
221     flags = get_psw();
222     if (flags & BIT_C) {
223       flags &= ~BIT_ALL; /* clear these bits */
224       result = dst - src - 1;
225     } else {
226       flags &= ~BIT_ALL; /* clear these bits */
227       result = dst - src;
228     }
229     if (result == 0) flags |= BIT_Z;
230     if (result > 0xff) flags |= BIT_C;
231     if (dst < src) flags |= BIT_N;
232     /* fixme: do AC, V */
233     set_psw(flags);
234     return (unsigned char) result;
235   }
236
237   inline unsigned short subb2(unsigned short dst, unsigned short src)
238   {
239     unsigned int result;
240     unsigned char flags;
241     flags = get_psw();
242     flags &= ~BIT_ALL; /* clear these bits */
243     if (flags & BIT_C) {
244       flags &= ~BIT_ALL; /* clear these bits */
245       result = dst - src - 1;
246     } else {
247       flags &= ~BIT_ALL; /* clear these bits */
248       result = dst - src;
249     }
250     if (result == 0) flags |= BIT_Z;
251     if (result > 0xff) flags |= BIT_C;
252     if (dst < src) flags |= BIT_N;
253     /* fixme: do AC, V */
254     set_psw(flags);
255     return (unsigned short) result;
256   }
257
258   /*-------------------------------------
259     cmp - flags changed:C,AC,V,N,Z.
260   |---------------------------------------*/
261   inline unsigned char cmp1(unsigned char dst, unsigned char src)
262   {
263     unsigned int result;
264     unsigned char flags;
265     flags = get_psw();
266     flags &= ~BIT_ALL; /* clear these bits */
267     result = dst - src;
268     if (result == 0) flags |= BIT_Z;
269     if (result > 0xff) flags |= BIT_C;
270     if (dst < src) flags |= BIT_N;
271     /* fixme: do AC, V */
272     set_psw(flags);
273     return (unsigned char) dst;
274   }
275
276   inline unsigned short cmp2(unsigned short dst, unsigned short src)
277   {
278     unsigned int result;
279     unsigned char flags;
280     flags = get_psw();
281     flags &= ~BIT_ALL; /* clear these bits */
282     result = dst - src;
283     if (result == 0) flags |= BIT_Z;
284     if (result > 0xff) flags |= BIT_C;
285     if (dst < src) flags |= BIT_N;
286     /* fixme: do AC, V */
287     set_psw(flags);
288     return (unsigned short) dst;
289   }
290
291   /*-------------------------------------
292     and - flags changed:N,Z.
293   |---------------------------------------*/
294   inline unsigned char and1(unsigned char dst, unsigned char src)
295   {
296     unsigned int result;
297     unsigned char flags;
298     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
299     result = dst & src;
300     if (result == 0) flags |= BIT_Z;
301     if (result & 0x80) flags |= BIT_N;
302     set_psw(flags);
303     return (unsigned char) result;
304   }
305
306   inline unsigned short and2(unsigned short dst, unsigned short src)
307   {
308     unsigned int result;
309     unsigned char flags;
310     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
311     result = dst & src;
312     if (result == 0) flags |= BIT_Z;
313     if (result & 0x80) flags |= BIT_N;
314     set_psw(flags);
315     return (unsigned short) result;
316   }
317
318   /*-------------------------------------
319     or - flags changed:N,Z.
320   |---------------------------------------*/
321   inline unsigned char or1(unsigned char dst, unsigned char src)
322   {
323     unsigned int result;
324     unsigned char flags;
325     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
326     result = dst | src;
327     if (result == 0) flags |= BIT_Z;
328     if (result & 0x80) flags |= BIT_N;
329     set_psw(flags);
330     return (unsigned char) result;
331   }
332
333   inline unsigned short or2(unsigned short dst, unsigned short src)
334   {
335     unsigned int result;
336     unsigned char flags;
337     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
338     result = dst | src;
339     if (result == 0) flags |= BIT_Z;
340     if (result & 0x80) flags |= BIT_N;
341     set_psw(flags);
342     return (unsigned short) result;
343   }
344
345   /*-------------------------------------
346     xor - flags changed:N,Z.
347   |---------------------------------------*/
348   inline unsigned char xor1(unsigned char dst, unsigned char src)
349   {
350     unsigned char flags;
351     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
352     dst ^= src;
353     if (dst == 0) flags |= BIT_Z;
354     if (dst & 0x80) flags |= BIT_N;
355     set_psw(flags);
356     return (unsigned char) dst;
357   }
358
359   inline unsigned short xor2(unsigned short dst, unsigned short src)
360   {
361     unsigned char flags;
362     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
363     dst ^= src;
364     if (dst == 0) flags |= BIT_Z;
365     if (dst & 0x8000) flags |= BIT_N;
366     set_psw(flags);
367     return (unsigned short) dst;
368   }
369
370   /*-------------------------------------
371     mov - flags changed:N,Z.
372   |---------------------------------------*/
373   inline unsigned char mov1(unsigned char dst, unsigned char src)
374   {
375     unsigned char flags;
376     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
377     dst = src;
378     if (dst == 0) flags |= BIT_Z;
379     if (dst & 0x80) flags |= BIT_N;
380     set_psw(flags);
381     return (unsigned char) dst;
382   }
383
384   inline unsigned short mov2(unsigned short dst, unsigned short src)
385   {
386     unsigned char flags;
387     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
388     dst = src;
389     if (dst == 0) flags |= BIT_Z;
390     if (dst & 0x8000) flags |= BIT_N;
391     set_psw(flags);
392     return (unsigned short) dst;
393   }
394 };
395
396 #endif
397
398 /* End of xa.src/xacl.h */