* sdcc/sim/ucsim/globals.cc: New: IXRAM.
[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_DS390               0x0080
79 #define CPU_DS390F              0x0100
80 #define CPU_ALL_51      (CPU_51|CPU_31)
81 #define CPU_ALL_52      (CPU_52|CPU_32|CPU_51R|CPU_89C51R|CPU_251|CPU_DS390|CPU_DS390F)
82
83 #define CPU_AVR         0x0001
84 #define CPU_ALL_AVR     (CPU_AVR)
85
86 #define CPU_Z80         0x0001
87 #define CPU_ALL_Z80     (CPU_Z80)
88
89 #define CPU_CMOS        0x0001
90 #define CPU_HMOS        0x0002
91
92 /* Classes of memories, this is index on the list */
93 enum mem_class
94 {
95   MEM_ROM= 0,
96   MEM_XRAM,
97   MEM_IRAM,
98   MEM_SFR,
99   MEM_IXRAM,
100   MEM_TYPES
101 };
102
103 // Flags of consoles
104 #define CONS_NONE        0
105 #define CONS_DEBUG       0x01   // Print debug messages on this console
106 #define CONS_FROZEN      0x02   // Console is frozen (g command issued)
107 #define CONS_PROMPT      0x04   // Prompt is out, waiting for input
108 #define CONS_INTERACTIVE 0x08   // Interactive console
109
110 // States of simulator
111 #define SIM_NONE        0
112 #define SIM_GO          0x01    // Processor is running
113 #define SIM_QUIT        0x02    // Program must exit
114
115 /* States of CPU */
116 #define stGO            0       /* Normal state */
117 #define stIDLE          1       /* Idle mode is active */
118 #define stPD            2       /* Power Down mode is active */
119
120 /* Result of instruction simulation */
121 #define resGO           0       /* OK, go on */
122 #define resWDTRESET     1       /* Reseted by WDT */
123 #define resINTERRUPT    2       /* Interrupt accepted */
124 #define resSTOP         100     /* Stop if result greather then this */
125 #define resHALT         101     /* Serious error, halt CPU */
126 #define resINV_ADDR     102     /* Invalid indirect address */
127 #define resSTACK_OV     103     /* Stack overflow */
128 #define resBREAKPOINT   104     /* Breakpoint */
129 #define resUSER         105     /* Stopped by user */
130 #define resINV_INST     106     /* Invalid instruction */
131
132
133 #define BIT_MASK(bitaddr) (1 << (bitaddr & 0x07))
134 #define SET_BIT(newbit, reg, bitmask) \
135 if (newbit) \
136   (mem(MEM_SFR))->set_bit1((reg), (bitmask)); \
137 else \
138   (mem(MEM_SFR))->set_bit0((reg), (bitmask));
139 #define SFR_SET_BIT(newbit, reg, bitmask) \
140 if (newbit) \
141   sfr->set_bit1((reg), (bitmask)); \
142 else \
143   sfr->set_bit0((reg), (bitmask));
144 #define GET_C     (get_mem(MEM_SFR, PSW) & bmCY)
145 #define SFR_GET_C (sfr->get(PSW) & bmCY)
146 #define SET_C(newC) SET_BIT((newC), PSW, bmCY)
147
148 #define IRAM_SIZE 256     /* Size of Internal RAM */
149 #define SFR_SIZE  256     /* Size of SFR area */
150 #define SFR_START 128     /* Start address of SFR area */
151 #define ERAM_SIZE 256     /* Size of ERAM in 51R */
152 #define XRAM_SIZE 0x10000 /* Size of External RAM */
153 //#define IROM_SIZE 0x1000  /* Size of Internal ROM */
154 #define EROM_SIZE 0x10000 /* Size of External ROM */
155
156
157 /* Type of breakpoints */
158 enum brk_perm
159 {
160   brkFIX,       /* f */
161   brkDYNAMIC    /* d */
162 };
163
164 enum brk_type
165 {
166   brkFETCH,     /* f */
167   brkEVENT      /* e */
168 };
169
170 enum brk_event
171 {
172   brkNONE,
173   brkWXRAM,     /* wx */
174   brkRXRAM,     /* rx */
175   brkRCODE,     /* rc */
176   brkWIRAM,     /* wi */
177   brkRIRAM,     /* ri */
178   brkWSFR,      /* ws */
179   brkRSFR       /* rs */
180 };
181
182 struct event_rec
183 {
184   t_addr wx; /* write to XRAM at this address, else -1 */
185   t_addr rx; /* read from XRAM at this address, else -1 */
186   t_addr wi; /* write to IRAM at this address, else -1 */
187   t_addr ri; /* read from IRAM at this address, else -1 */
188   t_addr ws; /* write to SFR at this address, else -1 */
189   t_addr rs; /* read from SFR at this address, else -1 */
190   t_addr rc; /* read from ROM at this address, else -1 */
191 };
192
193 /* Interrupt levels */
194 //#define IT_NO         -1 /* not in interroupt service */
195 #define IT_LOW          1 /* low level interrupt service */
196 #define IT_HIGH         2 /* service of high priority interrupt */
197
198 /* cathegories of hw elements (peripherials) */
199 enum hw_cath {
200   HW_TIMER,
201   HW_UART,
202   HW_PORT,
203   HW_PCA,
204   HW_INTERRUPT,
205   HW_WDT
206 };
207
208 // flags of hw units
209 #define HWF_NONE        0
210 #define HWF_INSIDE      0x0001
211 #define HWF_OUTSIDE     0x0002
212 #define HWF_MISC        0x0004
213
214
215 #endif
216
217 /* End of stypes.h */