Remove arch-alpha variable.
[dragonfly.git] / sys / boot / ficl / alpha / 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 ** $Id: sysdep.h,v 1.11 2001/12/05 07:21:34 jsadler Exp $
13 *******************************************************************/
14 /*
15 ** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)
16 ** All rights reserved.
17 **
18 ** Get the latest Ficl release at http://ficl.sourceforge.net
19 **
20 ** I am interested in hearing from anyone who uses ficl. If you have
21 ** a problem, a success story, a defect, an enhancement request, or
22 ** if you would like to contribute to the ficl release, please
23 ** contact me by email at the address above.
24 **
25 ** L I C E N S E  and  D I S C L A I M E R
26 ** 
27 ** Redistribution and use in source and binary forms, with or without
28 ** modification, are permitted provided that the following conditions
29 ** are met:
30 ** 1. Redistributions of source code must retain the above copyright
31 **    notice, this list of conditions and the following disclaimer.
32 ** 2. Redistributions in binary form must reproduce the above copyright
33 **    notice, this list of conditions and the following disclaimer in the
34 **    documentation and/or other materials provided with the distribution.
35 **
36 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
37 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39 ** ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
40 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
42 ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
44 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 ** SUCH DAMAGE.
47 */
48
49 /*
50  * $FreeBSD: src/sys/boot/ficl/alpha/sysdep.h,v 1.9 2002/05/16 21:21:50 trhodes Exp $
51  * $DragonFly: src/sys/boot/ficl/alpha/Attic/sysdep.h,v 1.3 2003/11/10 06:08:33 dillon Exp $
52  */
53
54 #if !defined (__SYSDEP_H__)
55 #define __SYSDEP_H__ 
56
57 #include <sys/types.h>
58
59 #include <stddef.h> /* size_t, NULL */
60 #include <setjmp.h>
61 #include <assert.h>
62
63 #if !defined IGNORE             /* Macro to silence unused param warnings */
64 #define IGNORE(x) &x
65 #endif
66
67 /*
68 ** TRUE and FALSE for C boolean operations, and
69 ** portable 32 bit types for CELLs
70 ** 
71 */
72 #if !defined TRUE
73 #define TRUE 1
74 #endif
75 #if !defined FALSE
76 #define FALSE 0
77 #endif
78
79 /*
80 ** System dependent data type declarations...
81 */
82 #if !defined INT32
83 #define INT32 int
84 #endif
85
86 #if !defined UNS32
87 #define UNS32 unsigned int
88 #endif
89
90 #if !defined UNS16
91 #define UNS16 unsigned short
92 #endif
93
94 #if !defined UNS8
95 #define UNS8 unsigned char
96 #endif
97
98 #if !defined NULL
99 #define NULL ((void *)0)
100 #endif
101
102 /*
103 ** FICL_UNS and FICL_INT must have the same size as a void* on
104 ** the target system. A CELL is a union of void*, FICL_UNS, and
105 ** FICL_INT. 
106 ** (11/2000: same for FICL_FLOAT)
107 */
108 #if !defined FICL_INT
109 #define FICL_INT long
110 #endif
111
112 #if !defined FICL_UNS
113 #define FICL_UNS unsigned long
114 #endif
115
116 #if !defined FICL_FLOAT
117 #define FICL_FLOAT float
118 #endif
119
120 /*
121 ** Ficl presently supports values of 32 and 64 for BITS_PER_CELL
122 */
123 #if !defined BITS_PER_CELL
124 #define BITS_PER_CELL 64
125 #endif
126
127 #if ((BITS_PER_CELL != 32) && (BITS_PER_CELL != 64))
128     Error!
129 #endif
130
131 typedef struct
132 {
133     FICL_UNS hi;
134     FICL_UNS lo;
135 } DPUNS;
136
137 typedef struct
138 {
139     FICL_UNS quot;
140     FICL_UNS rem;
141 } UNSQR;
142
143 typedef struct
144 {
145     FICL_INT hi;
146     FICL_INT lo;
147 } DPINT;
148
149 typedef struct
150 {
151     FICL_INT quot;
152     FICL_INT rem;
153 } INTQR;
154
155
156 /*
157 ** B U I L D   C O N T R O L S
158 */
159
160 #if !defined (FICL_MINIMAL)
161 #define FICL_MINIMAL 0
162 #endif
163 #if (FICL_MINIMAL)
164 #define FICL_WANT_SOFTWORDS  0
165 #define FICL_WANT_FILE       0
166 #define FICL_WANT_FLOAT      0
167 #define FICL_WANT_USER       0
168 #define FICL_WANT_LOCALS     0
169 #define FICL_WANT_DEBUGGER   0
170 #define FICL_WANT_OOP        0
171 #define FICL_PLATFORM_EXTEND 0
172 #define FICL_MULTITHREAD     0
173 #define FICL_ROBUST          0
174 #define FICL_EXTENDED_PREFIX 0
175 #endif
176
177 /*
178 ** FICL_PLATFORM_EXTEND
179 ** Includes words defined in ficlCompilePlatform
180 */
181 #if !defined (FICL_PLATFORM_EXTEND)
182 #define FICL_PLATFORM_EXTEND 1
183 #endif
184
185
186 /*
187 ** FICL_WANT_FILE
188 ** Includes the FILE and FILE-EXT wordset and associated code. Turn this off if you do not
189 ** have a filesystem!
190 ** Contributed by Larry Hastings
191 */
192 #if !defined (FICL_WANT_FILE)
193 #define FICL_WANT_FILE 0
194 #endif
195
196 /*
197 ** FICL_WANT_FLOAT
198 ** Includes a floating point stack for the VM, and words to do float operations.
199 ** Contributed by Guy Carver
200 */
201 #if !defined (FICL_WANT_FLOAT)
202 #define FICL_WANT_FLOAT 0
203 #endif
204
205 /*
206 ** FICL_WANT_DEBUGGER
207 ** Inludes a simple source level debugger
208 */
209 #if !defined (FICL_WANT_DEBUGGER)
210 #define FICL_WANT_DEBUGGER 1
211 #endif
212
213 /*
214 ** FICL_EXTENDED_PREFIX enables a bunch of extra prefixes in prefix.c and prefix.fr (if
215 ** included as part of softcore.c)
216 */
217 #if !defined FICL_EXTENDED_PREFIX
218 #define FICL_EXTENDED_PREFIX 0
219 #endif
220
221 /*
222 ** User variables: per-instance variables bound to the VM.
223 ** Kinda like thread-local storage. Could be implemented in a 
224 ** VM private dictionary, but I've chosen the lower overhead
225 ** approach of an array of CELLs instead.
226 */
227 #if !defined FICL_WANT_USER
228 #define FICL_WANT_USER 1
229 #endif
230
231 #if !defined FICL_USER_CELLS
232 #define FICL_USER_CELLS 16
233 #endif
234
235 /* 
236 ** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and
237 ** a private dictionary for local variable compilation.
238 */
239 #if !defined FICL_WANT_LOCALS
240 #define FICL_WANT_LOCALS 1
241 #endif
242
243 /* Max number of local variables per definition */
244 #if !defined FICL_MAX_LOCALS
245 #define FICL_MAX_LOCALS 16
246 #endif
247
248 /*
249 ** FICL_WANT_OOP
250 ** Inludes object oriented programming support (in softwords)
251 ** OOP support requires locals and user variables!
252 */
253 #if !(FICL_WANT_LOCALS) || !(FICL_WANT_USER)
254 #if !defined (FICL_WANT_OOP)
255 #define FICL_WANT_OOP 0
256 #endif
257 #endif
258
259 #if !defined (FICL_WANT_OOP)
260 #define FICL_WANT_OOP 1
261 #endif
262
263 /*
264 ** FICL_WANT_SOFTWORDS
265 ** Controls inclusion of all softwords in softcore.c
266 */
267 #if !defined (FICL_WANT_SOFTWORDS)
268 #define FICL_WANT_SOFTWORDS 1
269 #endif
270
271 /*
272 ** FICL_MULTITHREAD enables dictionary mutual exclusion
273 ** wia the ficlLockDictionary system dependent function.
274 ** Note: this implementation is experimental and poorly
275 ** tested. Further, it's unnecessary unless you really
276 ** intend to have multiple SESSIONS (poor choice of name
277 ** on my part) - that is, threads that modify the dictionary
278 ** at the same time.
279 */
280 #if !defined FICL_MULTITHREAD
281 #define FICL_MULTITHREAD 0
282 #endif
283
284 /*
285 ** PORTABLE_LONGMULDIV causes ficlLongMul and ficlLongDiv to be
286 ** defined in C in sysdep.c. Use this if you cannot easily 
287 ** generate an inline asm definition
288 */ 
289 #if !defined (PORTABLE_LONGMULDIV)
290 #define PORTABLE_LONGMULDIV 0
291 #endif
292
293 /*
294 ** INLINE_INNER_LOOP causes the inner interpreter to be inline code
295 ** instead of a function call. This is mainly because MS VC++ 5
296 ** chokes with an internal compiler error on the function version.
297 ** in release mode. Sheesh.
298 */
299 #if !defined INLINE_INNER_LOOP
300 #if defined _DEBUG
301 #define INLINE_INNER_LOOP 0
302 #else
303 #define INLINE_INNER_LOOP 1
304 #endif
305 #endif
306
307 /*
308 ** FICL_ROBUST enables bounds checking of stacks and the dictionary.
309 ** This will detect stack over and underflows and dictionary overflows.
310 ** Any exceptional condition will result in an assertion failure.
311 ** (As generated by the ANSI assert macro)
312 ** FICL_ROBUST == 1 --> stack checking in the outer interpreter
313 ** FICL_ROBUST == 2 also enables checking in many primitives
314 */
315
316 #if !defined FICL_ROBUST
317 #define FICL_ROBUST 2
318 #endif
319
320 /*
321 ** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of
322 ** a new virtual machine's stacks, unless overridden at 
323 ** create time.
324 */
325 #if !defined FICL_DEFAULT_STACK
326 #define FICL_DEFAULT_STACK 128
327 #endif
328
329 /*
330 ** FICL_DEFAULT_DICT specifies the number of CELLs to allocate
331 ** for the system dictionary by default. The value
332 ** can be overridden at startup time as well.
333 ** FICL_DEFAULT_ENV specifies the number of cells to allot
334 ** for the environment-query dictionary.
335 */
336 #if !defined FICL_DEFAULT_DICT
337 #define FICL_DEFAULT_DICT 12288
338 #endif
339
340 #if !defined FICL_DEFAULT_ENV
341 #define FICL_DEFAULT_ENV 260
342 #endif
343
344 /*
345 ** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in 
346 ** the dictionary search order. See Forth DPANS sec 16.3.3
347 ** (file://dpans16.htm#16.3.3)
348 */
349 #if !defined FICL_DEFAULT_VOCS
350 #define FICL_DEFAULT_VOCS 16
351 #endif
352
353 /*
354 ** FICL_MAX_PARSE_STEPS controls the size of an array in the FICL_SYSTEM structure
355 ** that stores pointers to parser extension functions. I would never expect to have
356 ** more than 8 of these, so that's the default limit. Too many of these functions
357 ** will probably exact a nasty performance penalty.
358 */
359 #if !defined FICL_MAX_PARSE_STEPS
360 #define FICL_MAX_PARSE_STEPS 8
361 #endif
362
363 /*
364 ** FICL_ALIGN is the power of two to which the dictionary
365 ** pointer address must be aligned. This value is usually
366 ** either 1 or 2, depending on the memory architecture
367 ** of the target system; 2 is safe on any 16 or 32 bit
368 ** machine. 3 would be appropriate for a 64 bit machine.
369 */
370 #if !defined FICL_ALIGN
371 #define FICL_ALIGN 3
372 #define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1)
373 #endif
374
375 /*
376 ** System dependent routines --
377 ** edit the implementations in sysdep.c to be compatible
378 ** with your runtime environment...
379 ** ficlTextOut sends a NULL terminated string to the 
380 **   default output device - used for system error messages
381 ** ficlMalloc and ficlFree have the same semantics as malloc and free
382 **   in standard C
383 ** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned 
384 **   product
385 ** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient
386 **   and remainder
387 */
388 struct vm;
389 void  ficlTextOut(struct vm *pVM, char *msg, int fNewline);
390 void *ficlMalloc (size_t size);
391 void  ficlFree   (void *p);
392 void *ficlRealloc(void *p, size_t size);
393 /*
394 ** Stub function for dictionary access control - does nothing
395 ** by default, user can redefine to guarantee exclusive dict
396 ** access to a single thread for updates. All dict update code
397 ** must be bracketed as follows:
398 ** ficlLockDictionary(TRUE);
399 ** <code that updates dictionary>
400 ** ficlLockDictionary(FALSE);
401 **
402 ** Returns zero if successful, nonzero if unable to acquire lock
403 ** before timeout (optional - could also block forever)
404 **
405 ** NOTE: this function must be implemented with lock counting
406 ** semantics: nested calls must behave properly.
407 */
408 #if FICL_MULTITHREAD
409 int ficlLockDictionary(short fLock);
410 #else
411 #define ficlLockDictionary(x) 0 /* ignore */
412 #endif
413
414 /*
415 ** 64 bit integer math support routines: multiply two UNS32s
416 ** to get a 64 bit product, & divide the product by an UNS32
417 ** to get an UNS32 quotient and remainder. Much easier in asm
418 ** on a 32 bit CPU than in C, which usually doesn't support 
419 ** the double length result (but it should).
420 */
421 DPUNS ficlLongMul(FICL_UNS x, FICL_UNS y);
422 UNSQR ficlLongDiv(DPUNS    q, FICL_UNS y);
423
424
425 /*
426 ** FICL_HAVE_FTRUNCATE indicates whether the current OS supports
427 ** the ftruncate() function (available on most UNIXes).  This
428 ** function is necessary to provide the complete File-Access wordset.
429 */
430 #if !defined (FICL_HAVE_FTRUNCATE)
431 #define FICL_HAVE_FTRUNCATE 0
432 #endif
433
434
435 #endif /*__SYSDEP_H__*/