81a50689e60658f34ac4402370eb28488596e757
[fw/sdcc] / sim / ucsim / stypes.h
1 /*
2  * Simulator of microcontrollers (stypes.h)
3  *
4  * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
5  * 
6  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
7  *
8  */
9
10 /* This file is part of microcontroller simulator: ucsim.
11
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.
16
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.
21
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@*/
27
28 #ifndef STYPES_HEADER
29 #define STYPES_HEADER
30
31 #include "ddconfig.h"
32
33
34 typedef unsigned char uchar;
35 typedef unsigned int  uint;
36 typedef unsigned long ulong;
37 typedef unsigned long t_addr;
38 typedef unsigned long t_mem;
39
40 struct id_element
41 {
42   int id;
43   char *id_string;
44 };
45
46 // table of dissassembled instructions
47 struct dis_entry
48 {
49   uint  code, mask;
50   char  branch;
51   uchar length;
52   char  *mnemonic;
53 };
54
55 // table entry of SFR and BIT names
56 struct name_entry
57 {
58   int  cpu_type;
59   uint addr;
60   char *name;
61 };
62
63
64 struct cpu_entry
65 {
66   char *type_str;
67   int  type;
68   int  technology;
69 };
70
71 #define CPU_51          0x0001
72 #define CPU_31          0x0002
73 #define CPU_52          0x0004
74 #define CPU_32          0x0008
75 #define CPU_51R         0x0010
76 #define CPU_89C51R      0x0020
77 #define CPU_251         0x0040
78 #define CPU_ALL_51      (CPU_51|CPU_31)
79 #define CPU_ALL_52      (CPU_52|CPU_32|CPU_51R|CPU_89C51R|CPU_251)
80
81 #define CPU_AVR         0x0001
82 #define CPU_ALL_AVR     (CPU_AVR)
83
84 #define CPU_Z80         0x0001
85 #define CPU_ALL_Z80     (CPU_Z80)
86
87 #define CPU_CMOS        0x0001
88 #define CPU_HMOS        0x0002
89
90 /* Classes of memories, this is index on the list */
91 enum mem_class
92 {
93   MEM_ROM= 0,
94   MEM_XRAM,
95   MEM_IRAM,
96   MEM_SFR,
97   MEM_TYPES
98 };
99
100 // Flags of consoles
101 #define CONS_NONE        0
102 #define CONS_DEBUG       0x01   // Print debug messages on this console
103 #define CONS_FROZEN      0x02   // Console is frozen (g command issued)
104 #define CONS_PROMPT      0x04   // Prompt is out, waiting for input
105 #define CONS_INTERACTIVE 0x08   // Interactive console
106
107 // States of simulator
108 #define SIM_NONE        0
109 #define SIM_GO          0x01    // Processor is running
110 #define SIM_QUIT        0x02    // Program must exit
111
112 /* States of CPU */
113 #define stGO            0       /* Normal state */
114 #define stIDLE          1       /* Idle mode is active */
115 #define stPD            2       /* Power Down mode is active */
116
117 /* Result of instruction simulation */
118 #define resGO           0       /* OK, go on */
119 #define resWDTRESET     1       /* Reseted by WDT */
120 #define resINTERRUPT    2       /* Interrupt accepted */
121 #define resSTOP         100     /* Stop if result greather then this */
122 #define resHALT         101     /* Serious error, halt CPU */
123 #define resINV_ADDR     102     /* Invalid indirect address */
124 #define resSTACK_OV     103     /* Stack overflow */
125 #define resBREAKPOINT   104     /* Breakpoint */
126 #define resUSER         105     /* Stopped by user */
127 #define resINV_INST     106     /* Invalid instruction */
128
129
130 #define BIT_MASK(bitaddr) (1 << (bitaddr & 0x07))
131 #define SET_BIT(newbit, reg, bitmask) \
132 if (newbit) \
133   (mem(MEM_SFR))->set_bit1((reg), (bitmask)); \
134 else \
135   (mem(MEM_SFR))->set_bit0((reg), (bitmask));
136 #define SFR_SET_BIT(newbit, reg, bitmask) \
137 if (newbit) \
138   sfr->set_bit1((reg), (bitmask)); \
139 else \
140   sfr->set_bit0((reg), (bitmask));
141 #define GET_C     (get_mem(MEM_SFR, PSW) & bmCY)
142 #define SFR_GET_C (sfr->get(PSW) & bmCY)
143 #define SET_C(newC) SET_BIT((newC), PSW, bmCY)
144
145 #define IRAM_SIZE 256     /* Size of Internal RAM */
146 #define SFR_SIZE  256     /* Size of SFR area */
147 #define SFR_START 128     /* Start address of SFR area */
148 #define ERAM_SIZE 256     /* Size of ERAM in 51R */
149 #define XRAM_SIZE 0x10000 /* Size of External RAM */
150 //#define IROM_SIZE 0x1000  /* Size of Internal ROM */
151 #define EROM_SIZE 0x10000 /* Size of External ROM */
152
153
154 /* Type of breakpoints */
155 enum brk_perm
156 {
157   brkFIX,       /* f */
158   brkDYNAMIC    /* d */
159 };
160
161 enum brk_type
162 {
163   brkFETCH,     /* f */
164   brkEVENT      /* e */
165 };
166
167 enum brk_event
168 {
169   brkNONE,
170   brkWXRAM,     /* wx */
171   brkRXRAM,     /* rx */
172   brkRCODE,     /* rc */
173   brkWIRAM,     /* wi */
174   brkRIRAM,     /* ri */
175   brkWSFR,      /* ws */
176   brkRSFR       /* rs */
177 };
178
179 struct event_rec
180 {
181   t_addr wx; /* write to XRAM at this address, else -1 */
182   t_addr rx; /* read from XRAM at this address, else -1 */
183   t_addr wi; /* write to IRAM at this address, else -1 */
184   t_addr ri; /* read from IRAM at this address, else -1 */
185   t_addr ws; /* write to SFR at this address, else -1 */
186   t_addr rs; /* read from SFR at this address, else -1 */
187   t_addr rc; /* read from ROM at this address, else -1 */
188 };
189
190 /* Interrupt levels */
191 //#define IT_NO         -1 /* not in interroupt service */
192 #define IT_LOW          1 /* low level interrupt service */
193 #define IT_HIGH         2 /* service of high priority interrupt */
194
195 /* cathegories of hw elements (peripherials) */
196 enum hw_cath {
197   HW_TIMER,
198   HW_UART,
199   HW_PORT,
200   HW_PCA,
201   HW_INTERRUPT,
202   HW_WDT
203 };
204
205 // flags of hw units
206 #define HWF_NONE        0
207 #define HWF_INSIDE      0x0001
208 #define HWF_OUTSIDE     0x0002
209 #define HWF_MISC        0x0004
210
211
212 #endif
213
214 /* End of stypes.h */