Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / boot / ficl / i386 / sysdep.h
1 /*******************************************************************
2                     s y s d e p . h
3 ** Forth Inspired Command Language
4 ** Author: John Sadler (john_sadler@alum.mit.edu)
5 ** Created: 16 Oct 1997
6 ** Ficl system dependent types and prototypes...
7 **
8 ** Note: Ficl also depends on the use of "assert" when
9 ** FICL_ROBUST is enabled. This may require some consideration
10 ** in firmware systems since assert often
11 ** assumes stderr/stdout.  
12 ** 
13 *******************************************************************/
14 /*
15 ** N O T I C E -- DISCLAIMER OF WARRANTY
16 ** 
17 ** Ficl is freeware. Use it in any way that you like, with
18 ** the understanding that the code is not supported.
19 ** 
20 ** Any third party may reproduce, distribute, or modify the ficl
21 ** software code or any derivative  works thereof without any 
22 ** compensation or license, provided that the author information
23 ** and this disclaimer text are retained in the source code files.
24 ** The ficl software code is provided on an "as is"  basis without
25 ** warranty of any kind, including, without limitation, the implied
26 ** warranties of merchantability and fitness for a particular purpose
27 ** and their equivalents under the laws of any jurisdiction.  
28 ** 
29 ** I am interested in hearing from anyone who uses ficl. If you have
30 ** a problem, a success story, a defect, an enhancement request, or
31 ** if you would like to contribute to the ficl release (yay!), please
32 ** send me email at the address above. 
33 */
34
35 /* $FreeBSD: src/sys/boot/ficl/i386/sysdep.h,v 1.5 1999/11/23 15:24:30 dcs Exp $ */
36
37 #if !defined (__SYSDEP_H__)
38 #define __SYSDEP_H__ 
39
40 #include <sys/types.h>
41
42 #include <stddef.h> /* size_t, NULL */
43 #include <setjmp.h>
44
45 #include <assert.h>
46
47 #if !defined IGNORE             /* Macro to silence unused param warnings */
48 #define IGNORE(x) &x
49 #endif
50
51
52 /*
53 ** TRUE and FALSE for C boolean operations, and
54 ** portable 32 bit types for CELLs
55 ** 
56 */
57 #if !defined TRUE
58 #define TRUE 1
59 #endif
60 #if !defined FALSE
61 #define FALSE 0
62 #endif
63
64
65 /*
66 ** System dependent data type declarations...
67 */
68 #if !defined INT32
69 #define INT32 long
70 #endif
71
72 #if !defined UNS32
73 #define UNS32 unsigned long
74 #endif
75
76 #if !defined UNS16
77 #define UNS16 unsigned short
78 #endif
79
80 #if !defined UNS8
81 #define UNS8 unsigned char
82 #endif
83
84 #if !defined NULL
85 #define NULL ((void *)0)
86 #endif
87
88 /*
89 ** FICL_UNS and FICL_INT must have the same size as a void* on
90 ** the target system. A CELL is a union of void*, FICL_UNS, and
91 ** FICL_INT. 
92 */
93 #if !defined FICL_INT
94 #define FICL_INT INT32
95 #endif
96
97 #if !defined FICL_UNS
98 #define FICL_UNS UNS32
99 #endif
100
101 /*
102 ** Ficl presently supports values of 32 and 64 for BITS_PER_CELL
103 */
104 #if !defined BITS_PER_CELL
105 #define BITS_PER_CELL 32
106 #endif
107
108 #if ((BITS_PER_CELL != 32) && (BITS_PER_CELL != 64))
109     Error!
110 #endif
111
112 typedef struct
113 {
114     FICL_UNS hi;
115     FICL_UNS lo;
116 } DPUNS;
117
118 typedef struct
119 {
120     FICL_UNS quot;
121     FICL_UNS rem;
122 } UNSQR;
123
124 typedef struct
125 {
126     FICL_INT hi;
127     FICL_INT lo;
128 } DPINT;
129
130 typedef struct
131 {
132     FICL_INT quot;
133     FICL_INT rem;
134 } INTQR;
135
136
137 /*
138 ** Build controls
139 ** FICL_MULTITHREAD enables dictionary mutual exclusion
140 ** wia the ficlLockDictionary system dependent function.
141 */
142 #if !defined FICL_MULTITHREAD
143 #define FICL_MULTITHREAD 0
144 #endif
145
146 /*
147 ** PORTABLE_LONGMULDIV causes ficlLongMul and ficlLongDiv to be
148 ** defined in C in sysdep.c. Use this if you cannot easily 
149 ** generate an inline asm definition
150 */ 
151 #if !defined (PORTABLE_LONGMULDIV)
152 #define PORTABLE_LONGMULDIV 0
153 #endif
154
155
156 /*
157 ** INLINE_INNER_LOOP causes the inner interpreter to be inline code
158 ** instead of a function call. This is mainly because MS VC++ 5
159 ** chokes with an internal compiler error on the function version.
160 ** in release mode. Sheesh.
161 */
162 #if !defined INLINE_INNER_LOOP
163 #if defined _DEBUG
164 #define INLINE_INNER_LOOP 0
165 #else
166 #define INLINE_INNER_LOOP 1
167 #endif
168 #endif
169
170 /*
171 ** FICL_ROBUST enables bounds checking of stacks and the dictionary.
172 ** This will detect stack over and underflows and dictionary overflows.
173 ** Any exceptional condition will result in an assertion failure.
174 ** (As generated by the ANSI assert macro)
175 ** FICL_ROBUST == 1 --> stack checking in the outer interpreter
176 ** FICL_ROBUST == 2 also enables checking in many primitives
177 */
178
179 #if !defined FICL_ROBUST
180 #define FICL_ROBUST 2
181 #endif
182
183 /*
184 ** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of
185 ** a new virtual machine's stacks, unless overridden at 
186 ** create time.
187 */
188 #if !defined FICL_DEFAULT_STACK
189 #define FICL_DEFAULT_STACK 128
190 #endif
191
192 /*
193 ** FICL_DEFAULT_DICT specifies the number of CELLs to allocate
194 ** for the system dictionary by default. The value
195 ** can be overridden at startup time as well.
196 ** FICL_DEFAULT_ENV specifies the number of cells to allot
197 ** for the environment-query dictionary.
198 */
199 #if !defined FICL_DEFAULT_DICT
200 #define FICL_DEFAULT_DICT 12288
201 #endif
202
203 #if !defined FICL_DEFAULT_ENV
204 #define FICL_DEFAULT_ENV 260
205 #endif
206
207 /*
208 ** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in 
209 ** the dictionary search order. See Forth DPANS sec 16.3.3
210 ** (file://dpans16.htm#16.3.3)
211 */
212 #if !defined FICL_DEFAULT_VOCS
213 #define FICL_DEFAULT_VOCS 16
214 #endif
215
216 /*
217 ** User variables: per-instance variables bound to the VM.
218 ** Kinda like thread-local storage. Could be implemented in a 
219 ** VM private dictionary, but I've chosen the lower overhead
220 ** approach of an array of CELLs instead.
221 */
222 #if !defined FICL_WANT_USER
223 #define FICL_WANT_USER 1
224 #endif
225
226 #if !defined FICL_USER_CELLS
227 #define FICL_USER_CELLS 16
228 #endif
229
230 /* 
231 ** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and
232 ** a private dictionary for local variable compilation.
233 */
234 #if !defined FICL_WANT_LOCALS
235 #define FICL_WANT_LOCALS 1
236 #endif
237
238 /* Max number of local variables per definition */
239 #if !defined FICL_MAX_LOCALS
240 #define FICL_MAX_LOCALS 16
241 #endif
242
243 /*
244 ** FICL_ALIGN is the power of two to which the dictionary
245 ** pointer address must be aligned. This value is usually
246 ** either 1 or 2, depending on the memory architecture
247 ** of the target system; 2 is safe on any 16 or 32 bit
248 ** machine. 3 would be appropriate for a 64 bit machine.
249 */
250 #if !defined FICL_ALIGN
251 #define FICL_ALIGN 2
252 #define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1)
253 #endif
254
255 /*
256 ** System dependent routines --
257 ** edit the implementations in sysdep.c to be compatible
258 ** with your runtime environment...
259 ** ficlTextOut sends a NULL terminated string to the 
260 **   default output device - used for system error messages
261 ** ficlMalloc and ficlFree have the same semantics as malloc and free
262 **   in standard C
263 ** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned 
264 **   product
265 ** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient
266 **   and remainder
267 */
268 struct vm;
269 void  ficlTextOut(struct vm *pVM, char *msg, int fNewline);
270 void *ficlMalloc (size_t size);
271 void  ficlFree   (void *p);
272 void *ficlRealloc(void *p, size_t size);
273 /*
274 ** Stub function for dictionary access control - does nothing
275 ** by default, user can redefine to guarantee exclusive dict
276 ** access to a single thread for updates. All dict update code
277 ** must be bracketed as follows:
278 ** ficlLockDictionary(TRUE);
279 ** <code that updates dictionary>
280 ** ficlLockDictionary(FALSE);
281 **
282 ** Returns zero if successful, nonzero if unable to acquire lock
283 ** before timeout (optional - could also block forever)
284 **
285 ** NOTE: this function must be implemented with lock counting
286 ** semantics: nested calls must behave properly.
287 */
288 #if FICL_MULTITHREAD
289 int ficlLockDictionary(short fLock);
290 #else
291 #define ficlLockDictionary(x) 0 /* ignore */
292 #endif
293
294 /*
295 ** 64 bit integer math support routines: multiply two UNS32s
296 ** to get a 64 bit product, & divide the product by an UNS32
297 ** to get an UNS32 quotient and remainder. Much easier in asm
298 ** on a 32 bit CPU than in C, which usually doesn't support 
299 ** the double length result (but it should).
300 */
301 DPUNS ficlLongMul(FICL_UNS x, FICL_UNS y);
302 UNSQR ficlLongDiv(DPUNS    q, FICL_UNS y);
303
304 #endif /*__SYSDEP_H__*/