Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[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 /* $DragonFly: src/sys/boot/ficl/i386/sysdep.h,v 1.2 2003/06/17 04:28:18 dillon Exp $ */
37
38 #if !defined (__SYSDEP_H__)
39 #define __SYSDEP_H__ 
40
41 #include <sys/types.h>
42
43 #include <stddef.h> /* size_t, NULL */
44 #include <setjmp.h>
45
46 #include <assert.h>
47
48 #if !defined IGNORE             /* Macro to silence unused param warnings */
49 #define IGNORE(x) &x
50 #endif
51
52
53 /*
54 ** TRUE and FALSE for C boolean operations, and
55 ** portable 32 bit types for CELLs
56 ** 
57 */
58 #if !defined TRUE
59 #define TRUE 1
60 #endif
61 #if !defined FALSE
62 #define FALSE 0
63 #endif
64
65
66 /*
67 ** System dependent data type declarations...
68 */
69 #if !defined INT32
70 #define INT32 long
71 #endif
72
73 #if !defined UNS32
74 #define UNS32 unsigned long
75 #endif
76
77 #if !defined UNS16
78 #define UNS16 unsigned short
79 #endif
80
81 #if !defined UNS8
82 #define UNS8 unsigned char
83 #endif
84
85 #if !defined NULL
86 #define NULL ((void *)0)
87 #endif
88
89 /*
90 ** FICL_UNS and FICL_INT must have the same size as a void* on
91 ** the target system. A CELL is a union of void*, FICL_UNS, and
92 ** FICL_INT. 
93 */
94 #if !defined FICL_INT
95 #define FICL_INT INT32
96 #endif
97
98 #if !defined FICL_UNS
99 #define FICL_UNS UNS32
100 #endif
101
102 /*
103 ** Ficl presently supports values of 32 and 64 for BITS_PER_CELL
104 */
105 #if !defined BITS_PER_CELL
106 #define BITS_PER_CELL 32
107 #endif
108
109 #if ((BITS_PER_CELL != 32) && (BITS_PER_CELL != 64))
110     Error!
111 #endif
112
113 typedef struct
114 {
115     FICL_UNS hi;
116     FICL_UNS lo;
117 } DPUNS;
118
119 typedef struct
120 {
121     FICL_UNS quot;
122     FICL_UNS rem;
123 } UNSQR;
124
125 typedef struct
126 {
127     FICL_INT hi;
128     FICL_INT lo;
129 } DPINT;
130
131 typedef struct
132 {
133     FICL_INT quot;
134     FICL_INT rem;
135 } INTQR;
136
137
138 /*
139 ** Build controls
140 ** FICL_MULTITHREAD enables dictionary mutual exclusion
141 ** wia the ficlLockDictionary system dependent function.
142 */
143 #if !defined FICL_MULTITHREAD
144 #define FICL_MULTITHREAD 0
145 #endif
146
147 /*
148 ** PORTABLE_LONGMULDIV causes ficlLongMul and ficlLongDiv to be
149 ** defined in C in sysdep.c. Use this if you cannot easily 
150 ** generate an inline asm definition
151 */ 
152 #if !defined (PORTABLE_LONGMULDIV)
153 #define PORTABLE_LONGMULDIV 0
154 #endif
155
156
157 /*
158 ** INLINE_INNER_LOOP causes the inner interpreter to be inline code
159 ** instead of a function call. This is mainly because MS VC++ 5
160 ** chokes with an internal compiler error on the function version.
161 ** in release mode. Sheesh.
162 */
163 #if !defined INLINE_INNER_LOOP
164 #if defined _DEBUG
165 #define INLINE_INNER_LOOP 0
166 #else
167 #define INLINE_INNER_LOOP 1
168 #endif
169 #endif
170
171 /*
172 ** FICL_ROBUST enables bounds checking of stacks and the dictionary.
173 ** This will detect stack over and underflows and dictionary overflows.
174 ** Any exceptional condition will result in an assertion failure.
175 ** (As generated by the ANSI assert macro)
176 ** FICL_ROBUST == 1 --> stack checking in the outer interpreter
177 ** FICL_ROBUST == 2 also enables checking in many primitives
178 */
179
180 #if !defined FICL_ROBUST
181 #define FICL_ROBUST 2
182 #endif
183
184 /*
185 ** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of
186 ** a new virtual machine's stacks, unless overridden at 
187 ** create time.
188 */
189 #if !defined FICL_DEFAULT_STACK
190 #define FICL_DEFAULT_STACK 128
191 #endif
192
193 /*
194 ** FICL_DEFAULT_DICT specifies the number of CELLs to allocate
195 ** for the system dictionary by default. The value
196 ** can be overridden at startup time as well.
197 ** FICL_DEFAULT_ENV specifies the number of cells to allot
198 ** for the environment-query dictionary.
199 */
200 #if !defined FICL_DEFAULT_DICT
201 #define FICL_DEFAULT_DICT 12288
202 #endif
203
204 #if !defined FICL_DEFAULT_ENV
205 #define FICL_DEFAULT_ENV 260
206 #endif
207
208 /*
209 ** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in 
210 ** the dictionary search order. See Forth DPANS sec 16.3.3
211 ** (file://dpans16.htm#16.3.3)
212 */
213 #if !defined FICL_DEFAULT_VOCS
214 #define FICL_DEFAULT_VOCS 16
215 #endif
216
217 /*
218 ** User variables: per-instance variables bound to the VM.
219 ** Kinda like thread-local storage. Could be implemented in a 
220 ** VM private dictionary, but I've chosen the lower overhead
221 ** approach of an array of CELLs instead.
222 */
223 #if !defined FICL_WANT_USER
224 #define FICL_WANT_USER 1
225 #endif
226
227 #if !defined FICL_USER_CELLS
228 #define FICL_USER_CELLS 16
229 #endif
230
231 /* 
232 ** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and
233 ** a private dictionary for local variable compilation.
234 */
235 #if !defined FICL_WANT_LOCALS
236 #define FICL_WANT_LOCALS 1
237 #endif
238
239 /* Max number of local variables per definition */
240 #if !defined FICL_MAX_LOCALS
241 #define FICL_MAX_LOCALS 16
242 #endif
243
244 /*
245 ** FICL_ALIGN is the power of two to which the dictionary
246 ** pointer address must be aligned. This value is usually
247 ** either 1 or 2, depending on the memory architecture
248 ** of the target system; 2 is safe on any 16 or 32 bit
249 ** machine. 3 would be appropriate for a 64 bit machine.
250 */
251 #if !defined FICL_ALIGN
252 #define FICL_ALIGN 2
253 #define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1)
254 #endif
255
256 /*
257 ** System dependent routines --
258 ** edit the implementations in sysdep.c to be compatible
259 ** with your runtime environment...
260 ** ficlTextOut sends a NULL terminated string to the 
261 **   default output device - used for system error messages
262 ** ficlMalloc and ficlFree have the same semantics as malloc and free
263 **   in standard C
264 ** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned 
265 **   product
266 ** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient
267 **   and remainder
268 */
269 struct vm;
270 void  ficlTextOut(struct vm *pVM, char *msg, int fNewline);
271 void *ficlMalloc (size_t size);
272 void  ficlFree   (void *p);
273 void *ficlRealloc(void *p, size_t size);
274 /*
275 ** Stub function for dictionary access control - does nothing
276 ** by default, user can redefine to guarantee exclusive dict
277 ** access to a single thread for updates. All dict update code
278 ** must be bracketed as follows:
279 ** ficlLockDictionary(TRUE);
280 ** <code that updates dictionary>
281 ** ficlLockDictionary(FALSE);
282 **
283 ** Returns zero if successful, nonzero if unable to acquire lock
284 ** before timeout (optional - could also block forever)
285 **
286 ** NOTE: this function must be implemented with lock counting
287 ** semantics: nested calls must behave properly.
288 */
289 #if FICL_MULTITHREAD
290 int ficlLockDictionary(short fLock);
291 #else
292 #define ficlLockDictionary(x) 0 /* ignore */
293 #endif
294
295 /*
296 ** 64 bit integer math support routines: multiply two UNS32s
297 ** to get a 64 bit product, & divide the product by an UNS32
298 ** to get an UNS32 quotient and remainder. Much easier in asm
299 ** on a 32 bit CPU than in C, which usually doesn't support 
300 ** the double length result (but it should).
301 */
302 DPUNS ficlLongMul(FICL_UNS x, FICL_UNS y);
303 UNSQR ficlLongDiv(DPUNS    q, FICL_UNS y);
304
305 #endif /*__SYSDEP_H__*/