1 /*******************************************************************
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...
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.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $
13 *******************************************************************/
15 ** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)
16 ** All rights reserved.
18 ** Get the latest Ficl release at http://ficl.sourceforge.net
20 ** L I C E N S E and D I S C L A I M E R
22 ** Redistribution and use in source and binary forms, with or without
23 ** modification, are permitted provided that the following conditions
25 ** 1. Redistributions of source code must retain the above copyright
26 ** notice, this list of conditions and the following disclaimer.
27 ** 2. Redistributions in binary form must reproduce the above copyright
28 ** notice, this list of conditions and the following disclaimer in the
29 ** documentation and/or other materials provided with the distribution.
31 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
32 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34 ** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
35 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 ** I am interested in hearing from anyone who uses ficl. If you have
44 ** a problem, a success story, a defect, an enhancement request, or
45 ** if you would like to contribute to the ficl release, please send
46 ** contact me by email at the address above.
48 ** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $
52 * $FreeBSD: src/sys/boot/ficl/sparc64/sysdep.h,v 1.1 2002/05/19 23:20:56 jake Exp $
53 * $DragonFly: src/sys/boot/ficl/sparc64/sysdep.h,v 1.1 2003/11/10 06:08:34 dillon Exp $
56 #if !defined (__SYSDEP_H__)
59 #include <sys/types.h>
61 #include <stddef.h> /* size_t, NULL */
65 #if !defined IGNORE /* Macro to silence unused param warnings */
70 ** TRUE and FALSE for C boolean operations, and
71 ** portable 32 bit types for CELLs
83 ** System dependent data type declarations...
90 #define UNS32 unsigned int
94 #define UNS16 unsigned short
98 #define UNS8 unsigned char
102 #define NULL ((void *)0)
106 ** FICL_UNS and FICL_INT must have the same size as a void* on
107 ** the target system. A CELL is a union of void*, FICL_UNS, and
109 ** (11/2000: same for FICL_FLOAT)
111 #if !defined FICL_INT
112 #define FICL_INT long
115 #if !defined FICL_UNS
116 #define FICL_UNS unsigned long
119 #if !defined FICL_FLOAT
120 #define FICL_FLOAT float
124 ** Ficl presently supports values of 32 and 64 for BITS_PER_CELL
126 #if !defined BITS_PER_CELL
127 #define BITS_PER_CELL 64
130 #if ((BITS_PER_CELL != 32) && (BITS_PER_CELL != 64))
160 ** B U I L D C O N T R O L S
163 #if !defined (FICL_MINIMAL)
164 #define FICL_MINIMAL 0
167 #define FICL_WANT_SOFTWORDS 0
168 #define FICL_WANT_FLOAT 0
169 #define FICL_WANT_USER 0
170 #define FICL_WANT_LOCALS 0
171 #define FICL_WANT_DEBUGGER 0
172 #define FICL_WANT_OOP 0
173 #define FICL_PLATFORM_EXTEND 0
174 #define FICL_MULTITHREAD 0
175 #define FICL_ROBUST 0
176 #define FICL_EXTENDED_PREFIX 0
180 ** FICL_PLATFORM_EXTEND
181 ** Includes words defined in ficlCompilePlatform
183 #if !defined (FICL_PLATFORM_EXTEND)
184 #define FICL_PLATFORM_EXTEND 1
189 ** Includes a floating point stack for the VM, and words to do float operations.
190 ** Contributed by Guy Carver
192 #if !defined (FICL_WANT_FLOAT)
193 #define FICL_WANT_FLOAT 0
197 ** FICL_WANT_DEBUGGER
198 ** Inludes a simple source level debugger
200 #if !defined (FICL_WANT_DEBUGGER)
201 #define FICL_WANT_DEBUGGER 1
205 ** User variables: per-instance variables bound to the VM.
206 ** Kinda like thread-local storage. Could be implemented in a
207 ** VM private dictionary, but I've chosen the lower overhead
208 ** approach of an array of CELLs instead.
210 #if !defined FICL_WANT_USER
211 #define FICL_WANT_USER 1
214 #if !defined FICL_USER_CELLS
215 #define FICL_USER_CELLS 16
219 ** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and
220 ** a private dictionary for local variable compilation.
222 #if !defined FICL_WANT_LOCALS
223 #define FICL_WANT_LOCALS 1
226 /* Max number of local variables per definition */
227 #if !defined FICL_MAX_LOCALS
228 #define FICL_MAX_LOCALS 16
233 ** Inludes object oriented programming support (in softwords)
234 ** OOP support requires locals and user variables!
236 #if !(FICL_WANT_LOCALS) || !(FICL_WANT_USER)
237 #if !defined (FICL_WANT_OOP)
238 #define FICL_WANT_OOP 0
242 #if !defined (FICL_WANT_OOP)
243 #define FICL_WANT_OOP 1
247 ** FICL_WANT_SOFTWORDS
248 ** Controls inclusion of all softwords in softcore.c
250 #if !defined (FICL_WANT_SOFTWORDS)
251 #define FICL_WANT_SOFTWORDS 1
255 ** FICL_MULTITHREAD enables dictionary mutual exclusion
256 ** wia the ficlLockDictionary system dependent function.
257 ** Note: this implementation is experimental and poorly
258 ** tested. Further, it's unnecessary unless you really
259 ** intend to have multiple SESSIONS (poor choice of name
260 ** on my part) - that is, threads that modify the dictionary
263 #if !defined FICL_MULTITHREAD
264 #define FICL_MULTITHREAD 0
268 ** PORTABLE_LONGMULDIV causes ficlLongMul and ficlLongDiv to be
269 ** defined in C in sysdep.c. Use this if you cannot easily
270 ** generate an inline asm definition
272 #if !defined (PORTABLE_LONGMULDIV)
273 #define PORTABLE_LONGMULDIV 0
277 ** INLINE_INNER_LOOP causes the inner interpreter to be inline code
278 ** instead of a function call. This is mainly because MS VC++ 5
279 ** chokes with an internal compiler error on the function version.
280 ** in release mode. Sheesh.
282 #if !defined INLINE_INNER_LOOP
284 #define INLINE_INNER_LOOP 0
286 #define INLINE_INNER_LOOP 1
291 ** FICL_ROBUST enables bounds checking of stacks and the dictionary.
292 ** This will detect stack over and underflows and dictionary overflows.
293 ** Any exceptional condition will result in an assertion failure.
294 ** (As generated by the ANSI assert macro)
295 ** FICL_ROBUST == 1 --> stack checking in the outer interpreter
296 ** FICL_ROBUST == 2 also enables checking in many primitives
299 #if !defined FICL_ROBUST
300 #define FICL_ROBUST 2
304 ** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of
305 ** a new virtual machine's stacks, unless overridden at
308 #if !defined FICL_DEFAULT_STACK
309 #define FICL_DEFAULT_STACK 128
313 ** FICL_DEFAULT_DICT specifies the number of CELLs to allocate
314 ** for the system dictionary by default. The value
315 ** can be overridden at startup time as well.
316 ** FICL_DEFAULT_ENV specifies the number of cells to allot
317 ** for the environment-query dictionary.
319 #if !defined FICL_DEFAULT_DICT
320 #define FICL_DEFAULT_DICT 12288
323 #if !defined FICL_DEFAULT_ENV
324 #define FICL_DEFAULT_ENV 260
328 ** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in
329 ** the dictionary search order. See Forth DPANS sec 16.3.3
330 ** (file://dpans16.htm#16.3.3)
332 #if !defined FICL_DEFAULT_VOCS
333 #define FICL_DEFAULT_VOCS 16
337 ** FICL_MAX_PARSE_STEPS controls the size of an array in the FICL_SYSTEM structure
338 ** that stores pointers to parser extension functions. I would never expect to have
339 ** more than 8 of these, so that's the default limit. Too many of these functions
340 ** will probably exact a nasty performance penalty.
342 #if !defined FICL_MAX_PARSE_STEPS
343 #define FICL_MAX_PARSE_STEPS 8
347 ** FICL_EXTENDED_PREFIX enables a bunch of extra prefixes in prefix.c and prefix.fr (if
348 ** included as part of softcore.c)
350 #if !defined FICL_EXTENDED_PREFIX
351 #define FICL_EXTENDED_PREFIX 0
355 ** FICL_ALIGN is the power of two to which the dictionary
356 ** pointer address must be aligned. This value is usually
357 ** either 1 or 2, depending on the memory architecture
358 ** of the target system; 2 is safe on any 16 or 32 bit
359 ** machine. 3 would be appropriate for a 64 bit machine.
361 #if !defined FICL_ALIGN
363 #define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1)
367 ** System dependent routines --
368 ** edit the implementations in sysdep.c to be compatible
369 ** with your runtime environment...
370 ** ficlTextOut sends a NULL terminated string to the
371 ** default output device - used for system error messages
372 ** ficlMalloc and ficlFree have the same semantics as malloc and free
374 ** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned
376 ** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient
380 void ficlTextOut(struct vm
*pVM
, char *msg
, int fNewline
);
381 void *ficlMalloc (size_t size
);
382 void ficlFree (void *p
);
383 void *ficlRealloc(void *p
, size_t size
);
385 ** Stub function for dictionary access control - does nothing
386 ** by default, user can redefine to guarantee exclusive dict
387 ** access to a single thread for updates. All dict update code
388 ** must be bracketed as follows:
389 ** ficlLockDictionary(TRUE);
390 ** <code that updates dictionary>
391 ** ficlLockDictionary(FALSE);
393 ** Returns zero if successful, nonzero if unable to acquire lock
394 ** before timeout (optional - could also block forever)
396 ** NOTE: this function must be implemented with lock counting
397 ** semantics: nested calls must behave properly.
400 int ficlLockDictionary(short fLock
);
402 #define ficlLockDictionary(x) 0 /* ignore */
406 ** 64 bit integer math support routines: multiply two UNS32s
407 ** to get a 64 bit product, & divide the product by an UNS32
408 ** to get an UNS32 quotient and remainder. Much easier in asm
409 ** on a 32 bit CPU than in C, which usually doesn't support
410 ** the double length result (but it should).
412 DPUNS
ficlLongMul(FICL_UNS x
, FICL_UNS y
);
413 UNSQR
ficlLongDiv(DPUNS q
, FICL_UNS y
);
415 #endif /*__SYSDEP_H__*/