1123372Sgrehan/*******************************************************************
2123372Sgrehan                    s y s d e p . h
3123372Sgrehan** Forth Inspired Command Language
4123372Sgrehan** Author: John Sadler (john_sadler@alum.mit.edu)
5123372Sgrehan** Created: 16 Oct 1997
6123372Sgrehan** Ficl system dependent types and prototypes...
7123372Sgrehan**
8123372Sgrehan** Note: Ficl also depends on the use of "assert" when
9123372Sgrehan** FICL_ROBUST is enabled. This may require some consideration
10123372Sgrehan** in firmware systems since assert often
11123372Sgrehan** assumes stderr/stdout.
12123372Sgrehan** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $
13123372Sgrehan*******************************************************************/
14123372Sgrehan/*
15123372Sgrehan** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)
16123372Sgrehan** All rights reserved.
17123372Sgrehan**
18123372Sgrehan** Get the latest Ficl release at http://ficl.sourceforge.net
19123372Sgrehan**
20123372Sgrehan** L I C E N S E  and  D I S C L A I M E R
21123372Sgrehan**
22123372Sgrehan** Redistribution and use in source and binary forms, with or without
23123372Sgrehan** modification, are permitted provided that the following conditions
24123372Sgrehan** are met:
25123372Sgrehan** 1. Redistributions of source code must retain the above copyright
26123372Sgrehan**    notice, this list of conditions and the following disclaimer.
27123372Sgrehan** 2. Redistributions in binary form must reproduce the above copyright
28123372Sgrehan**    notice, this list of conditions and the following disclaimer in the
29123372Sgrehan**    documentation and/or other materials provided with the distribution.
30123372Sgrehan**
31123372Sgrehan** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
32123372Sgrehan** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33123372Sgrehan** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34123372Sgrehan** ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
35123372Sgrehan** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36123372Sgrehan** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37123372Sgrehan** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38123372Sgrehan** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39123372Sgrehan** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40123372Sgrehan** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41123372Sgrehan** SUCH DAMAGE.
42123372Sgrehan**
43123372Sgrehan** I am interested in hearing from anyone who uses ficl. If you have
44123372Sgrehan** a problem, a success story, a defect, an enhancement request, or
45123372Sgrehan** if you would like to contribute to the ficl release, please send
46123372Sgrehan** contact me by email at the address above.
47123372Sgrehan**
48123372Sgrehan** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $
49123372Sgrehan** $FreeBSD: releng/10.3/sys/boot/ficl/powerpc/sysdep.h 123372 2003-12-10 09:05:08Z grehan $
50123372Sgrehan*/
51123372Sgrehan
52123372Sgrehan#if !defined (__SYSDEP_H__)
53123372Sgrehan#define __SYSDEP_H__
54123372Sgrehan
55123372Sgrehan#include <sys/types.h>
56123372Sgrehan
57123372Sgrehan#include <stddef.h> /* size_t, NULL */
58123372Sgrehan#include <setjmp.h>
59123372Sgrehan#include <assert.h>
60123372Sgrehan
61123372Sgrehan#if !defined IGNORE		/* Macro to silence unused param warnings */
62123372Sgrehan#define IGNORE(x) &x
63123372Sgrehan#endif
64123372Sgrehan
65123372Sgrehan/*
66123372Sgrehan** TRUE and FALSE for C boolean operations, and
67123372Sgrehan** portable 32 bit types for CELLs
68123372Sgrehan**
69123372Sgrehan*/
70123372Sgrehan#if !defined TRUE
71123372Sgrehan#define TRUE 1
72123372Sgrehan#endif
73123372Sgrehan#if !defined FALSE
74123372Sgrehan#define FALSE 0
75123372Sgrehan#endif
76123372Sgrehan
77123372Sgrehan
78123372Sgrehan/*
79123372Sgrehan** System dependent data type declarations...
80123372Sgrehan*/
81123372Sgrehan#if !defined INT32
82123372Sgrehan#define INT32 int
83123372Sgrehan#endif
84123372Sgrehan
85123372Sgrehan#if !defined UNS32
86123372Sgrehan#define UNS32 unsigned int
87123372Sgrehan#endif
88123372Sgrehan
89123372Sgrehan#if !defined UNS16
90123372Sgrehan#define UNS16 unsigned short
91123372Sgrehan#endif
92123372Sgrehan
93123372Sgrehan#if !defined UNS8
94123372Sgrehan#define UNS8 unsigned char
95123372Sgrehan#endif
96123372Sgrehan
97123372Sgrehan#if !defined NULL
98123372Sgrehan#define NULL ((void *)0)
99123372Sgrehan#endif
100123372Sgrehan
101123372Sgrehan/*
102123372Sgrehan** FICL_UNS and FICL_INT must have the same size as a void* on
103123372Sgrehan** the target system. A CELL is a union of void*, FICL_UNS, and
104123372Sgrehan** FICL_INT.
105123372Sgrehan** (11/2000: same for FICL_FLOAT)
106123372Sgrehan*/
107123372Sgrehan#if !defined FICL_INT
108123372Sgrehan#define FICL_INT INT32
109123372Sgrehan#endif
110123372Sgrehan
111123372Sgrehan#if !defined FICL_UNS
112123372Sgrehan#define FICL_UNS UNS32
113123372Sgrehan#endif
114123372Sgrehan
115123372Sgrehan#if !defined FICL_FLOAT
116123372Sgrehan#define FICL_FLOAT float
117123372Sgrehan#endif
118123372Sgrehan
119123372Sgrehan/*
120123372Sgrehan** Ficl presently supports values of 32 and 64 for BITS_PER_CELL
121123372Sgrehan*/
122123372Sgrehan#if !defined BITS_PER_CELL
123123372Sgrehan#define BITS_PER_CELL 32
124123372Sgrehan#endif
125123372Sgrehan
126123372Sgrehan#if ((BITS_PER_CELL != 32) && (BITS_PER_CELL != 64))
127123372Sgrehan    Error!
128123372Sgrehan#endif
129123372Sgrehan
130123372Sgrehantypedef struct
131123372Sgrehan{
132123372Sgrehan    FICL_UNS hi;
133123372Sgrehan    FICL_UNS lo;
134123372Sgrehan} DPUNS;
135123372Sgrehan
136123372Sgrehantypedef struct
137123372Sgrehan{
138123372Sgrehan    FICL_UNS quot;
139123372Sgrehan    FICL_UNS rem;
140123372Sgrehan} UNSQR;
141123372Sgrehan
142123372Sgrehantypedef struct
143123372Sgrehan{
144123372Sgrehan    FICL_INT hi;
145123372Sgrehan    FICL_INT lo;
146123372Sgrehan} DPINT;
147123372Sgrehan
148123372Sgrehantypedef struct
149123372Sgrehan{
150123372Sgrehan    FICL_INT quot;
151123372Sgrehan    FICL_INT rem;
152123372Sgrehan} INTQR;
153123372Sgrehan
154123372Sgrehan
155123372Sgrehan/*
156123372Sgrehan** B U I L D   C O N T R O L S
157123372Sgrehan*/
158123372Sgrehan
159123372Sgrehan#if !defined (FICL_MINIMAL)
160123372Sgrehan#define FICL_MINIMAL 0
161123372Sgrehan#endif
162123372Sgrehan#if (FICL_MINIMAL)
163123372Sgrehan#define FICL_WANT_SOFTWORDS  0
164123372Sgrehan#define FICL_WANT_FILE	     0
165123372Sgrehan#define FICL_WANT_FLOAT      0
166123372Sgrehan#define FICL_WANT_USER       0
167123372Sgrehan#define FICL_WANT_LOCALS     0
168123372Sgrehan#define FICL_WANT_DEBUGGER   0
169123372Sgrehan#define FICL_WANT_OOP        0
170123372Sgrehan#define FICL_PLATFORM_EXTEND 0
171123372Sgrehan#define FICL_MULTITHREAD     0
172123372Sgrehan#define FICL_ROBUST         1
173123372Sgrehan#define FICL_EXTENDED_PREFIX 0
174123372Sgrehan#endif
175123372Sgrehan
176123372Sgrehan/*
177123372Sgrehan** FICL_PLATFORM_EXTEND
178123372Sgrehan** Includes words defined in ficlCompilePlatform
179123372Sgrehan*/
180123372Sgrehan#if !defined (FICL_PLATFORM_EXTEND)
181123372Sgrehan#define FICL_PLATFORM_EXTEND 1
182123372Sgrehan#endif
183123372Sgrehan
184123372Sgrehan/*
185123372Sgrehan** FICL_WANT_FILE
186123372Sgrehan** Includes the FILE and FILE-EXT wordset and associated code. Turn this off if you do not
187123372Sgrehan** have a filesystem!
188123372Sgrehan** Contributed by Larry Hastings
189123372Sgrehan*/
190123372Sgrehan#if !defined (FICL_WANT_FILE)
191123372Sgrehan#define FICL_WANT_FILE 0
192123372Sgrehan#endif
193123372Sgrehan
194123372Sgrehan/*
195123372Sgrehan** FICL_WANT_FLOAT
196123372Sgrehan** Includes a floating point stack for the VM, and words to do float operations.
197123372Sgrehan** Contributed by Guy Carver
198123372Sgrehan*/
199123372Sgrehan#if !defined (FICL_WANT_FLOAT)
200123372Sgrehan#define FICL_WANT_FLOAT 0
201123372Sgrehan#endif
202123372Sgrehan
203123372Sgrehan/*
204123372Sgrehan** FICL_WANT_DEBUGGER
205123372Sgrehan** Inludes a simple source level debugger
206123372Sgrehan*/
207123372Sgrehan#if !defined (FICL_WANT_DEBUGGER)
208123372Sgrehan#define FICL_WANT_DEBUGGER 1
209123372Sgrehan#endif
210123372Sgrehan
211123372Sgrehan/*
212123372Sgrehan** User variables: per-instance variables bound to the VM.
213123372Sgrehan** Kinda like thread-local storage. Could be implemented in a
214123372Sgrehan** VM private dictionary, but I've chosen the lower overhead
215123372Sgrehan** approach of an array of CELLs instead.
216123372Sgrehan*/
217123372Sgrehan#if !defined FICL_WANT_USER
218123372Sgrehan#define FICL_WANT_USER 1
219123372Sgrehan#endif
220123372Sgrehan
221123372Sgrehan#if !defined FICL_USER_CELLS
222123372Sgrehan#define FICL_USER_CELLS 16
223123372Sgrehan#endif
224123372Sgrehan
225123372Sgrehan/*
226123372Sgrehan** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and
227123372Sgrehan** a private dictionary for local variable compilation.
228123372Sgrehan*/
229123372Sgrehan#if !defined FICL_WANT_LOCALS
230123372Sgrehan#define FICL_WANT_LOCALS 1
231123372Sgrehan#endif
232123372Sgrehan
233123372Sgrehan/* Max number of local variables per definition */
234123372Sgrehan#if !defined FICL_MAX_LOCALS
235123372Sgrehan#define FICL_MAX_LOCALS 16
236123372Sgrehan#endif
237123372Sgrehan
238123372Sgrehan/*
239123372Sgrehan** FICL_WANT_OOP
240123372Sgrehan** Inludes object oriented programming support (in softwords)
241123372Sgrehan** OOP support requires locals and user variables!
242123372Sgrehan*/
243123372Sgrehan#if !(FICL_WANT_LOCALS) || !(FICL_WANT_USER)
244123372Sgrehan#if !defined (FICL_WANT_OOP)
245123372Sgrehan#define FICL_WANT_OOP 0
246123372Sgrehan#endif
247123372Sgrehan#endif
248123372Sgrehan
249123372Sgrehan#if !defined (FICL_WANT_OOP)
250123372Sgrehan#define FICL_WANT_OOP 1
251123372Sgrehan#endif
252123372Sgrehan
253123372Sgrehan/*
254123372Sgrehan** FICL_WANT_SOFTWORDS
255123372Sgrehan** Controls inclusion of all softwords in softcore.c
256123372Sgrehan*/
257123372Sgrehan#if !defined (FICL_WANT_SOFTWORDS)
258123372Sgrehan#define FICL_WANT_SOFTWORDS 1
259123372Sgrehan#endif
260123372Sgrehan
261123372Sgrehan/*
262123372Sgrehan** FICL_MULTITHREAD enables dictionary mutual exclusion
263123372Sgrehan** wia the ficlLockDictionary system dependent function.
264123372Sgrehan** Note: this implementation is experimental and poorly
265123372Sgrehan** tested. Further, it's unnecessary unless you really
266123372Sgrehan** intend to have multiple SESSIONS (poor choice of name
267123372Sgrehan** on my part) - that is, threads that modify the dictionary
268123372Sgrehan** at the same time.
269123372Sgrehan*/
270123372Sgrehan#if !defined FICL_MULTITHREAD
271123372Sgrehan#define FICL_MULTITHREAD 0
272123372Sgrehan#endif
273123372Sgrehan
274123372Sgrehan/*
275123372Sgrehan** PORTABLE_LONGMULDIV causes ficlLongMul and ficlLongDiv to be
276123372Sgrehan** defined in C in sysdep.c. Use this if you cannot easily
277123372Sgrehan** generate an inline asm definition
278123372Sgrehan*/
279123372Sgrehan#if !defined (PORTABLE_LONGMULDIV)
280123372Sgrehan#define PORTABLE_LONGMULDIV 0
281123372Sgrehan#endif
282123372Sgrehan
283123372Sgrehan/*
284123372Sgrehan** INLINE_INNER_LOOP causes the inner interpreter to be inline code
285123372Sgrehan** instead of a function call. This is mainly because MS VC++ 5
286123372Sgrehan** chokes with an internal compiler error on the function version.
287123372Sgrehan** in release mode. Sheesh.
288123372Sgrehan*/
289123372Sgrehan#if !defined INLINE_INNER_LOOP
290123372Sgrehan#if defined _DEBUG
291123372Sgrehan#define INLINE_INNER_LOOP 0
292123372Sgrehan#else
293123372Sgrehan#define INLINE_INNER_LOOP 1
294123372Sgrehan#endif
295123372Sgrehan#endif
296123372Sgrehan
297123372Sgrehan/*
298123372Sgrehan** FICL_ROBUST enables bounds checking of stacks and the dictionary.
299123372Sgrehan** This will detect stack over and underflows and dictionary overflows.
300123372Sgrehan** Any exceptional condition will result in an assertion failure.
301123372Sgrehan** (As generated by the ANSI assert macro)
302123372Sgrehan** FICL_ROBUST == 1 --> stack checking in the outer interpreter
303123372Sgrehan** FICL_ROBUST == 2 also enables checking in many primitives
304123372Sgrehan*/
305123372Sgrehan
306123372Sgrehan#if !defined FICL_ROBUST
307123372Sgrehan#define FICL_ROBUST 2
308123372Sgrehan#endif
309123372Sgrehan
310123372Sgrehan/*
311123372Sgrehan** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of
312123372Sgrehan** a new virtual machine's stacks, unless overridden at
313123372Sgrehan** create time.
314123372Sgrehan*/
315123372Sgrehan#if !defined FICL_DEFAULT_STACK
316123372Sgrehan#define FICL_DEFAULT_STACK 128
317123372Sgrehan#endif
318123372Sgrehan
319123372Sgrehan/*
320123372Sgrehan** FICL_DEFAULT_DICT specifies the number of CELLs to allocate
321123372Sgrehan** for the system dictionary by default. The value
322123372Sgrehan** can be overridden at startup time as well.
323123372Sgrehan** FICL_DEFAULT_ENV specifies the number of cells to allot
324123372Sgrehan** for the environment-query dictionary.
325123372Sgrehan*/
326123372Sgrehan#if !defined FICL_DEFAULT_DICT
327123372Sgrehan#define FICL_DEFAULT_DICT 12288
328123372Sgrehan#endif
329123372Sgrehan
330123372Sgrehan#if !defined FICL_DEFAULT_ENV
331123372Sgrehan#define FICL_DEFAULT_ENV 260
332123372Sgrehan#endif
333123372Sgrehan
334123372Sgrehan/*
335123372Sgrehan** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in
336123372Sgrehan** the dictionary search order. See Forth DPANS sec 16.3.3
337123372Sgrehan** (file://dpans16.htm#16.3.3)
338123372Sgrehan*/
339123372Sgrehan#if !defined FICL_DEFAULT_VOCS
340123372Sgrehan#define FICL_DEFAULT_VOCS 16
341123372Sgrehan#endif
342123372Sgrehan
343123372Sgrehan/*
344123372Sgrehan** FICL_MAX_PARSE_STEPS controls the size of an array in the FICL_SYSTEM structure
345123372Sgrehan** that stores pointers to parser extension functions. I would never expect to have
346123372Sgrehan** more than 8 of these, so that's the default limit. Too many of these functions
347123372Sgrehan** will probably exact a nasty performance penalty.
348123372Sgrehan*/
349123372Sgrehan#if !defined FICL_MAX_PARSE_STEPS
350123372Sgrehan#define FICL_MAX_PARSE_STEPS 8
351123372Sgrehan#endif
352123372Sgrehan
353123372Sgrehan/*
354123372Sgrehan** FICL_EXTENDED_PREFIX enables a bunch of extra prefixes in prefix.c and prefix.fr (if
355123372Sgrehan** included as part of softcore.c)
356123372Sgrehan*/
357123372Sgrehan#if !defined FICL_EXTENDED_PREFIX
358123372Sgrehan#define FICL_EXTENDED_PREFIX 0
359123372Sgrehan#endif
360123372Sgrehan
361123372Sgrehan/*
362123372Sgrehan** FICL_ALIGN is the power of two to which the dictionary
363123372Sgrehan** pointer address must be aligned. This value is usually
364123372Sgrehan** either 1 or 2, depending on the memory architecture
365123372Sgrehan** of the target system; 2 is safe on any 16 or 32 bit
366123372Sgrehan** machine. 3 would be appropriate for a 64 bit machine.
367123372Sgrehan*/
368123372Sgrehan#if !defined FICL_ALIGN
369123372Sgrehan#define FICL_ALIGN 2
370123372Sgrehan#define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1)
371123372Sgrehan#endif
372123372Sgrehan
373123372Sgrehan/*
374123372Sgrehan** System dependent routines --
375123372Sgrehan** edit the implementations in sysdep.c to be compatible
376123372Sgrehan** with your runtime environment...
377123372Sgrehan** ficlTextOut sends a NULL terminated string to the
378123372Sgrehan**   default output device - used for system error messages
379123372Sgrehan** ficlMalloc and ficlFree have the same semantics as malloc and free
380123372Sgrehan**   in standard C
381123372Sgrehan** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned
382123372Sgrehan**   product
383123372Sgrehan** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient
384123372Sgrehan**   and remainder
385123372Sgrehan*/
386123372Sgrehanstruct vm;
387123372Sgrehanvoid  ficlTextOut(struct vm *pVM, char *msg, int fNewline);
388123372Sgrehanvoid *ficlMalloc (size_t size);
389123372Sgrehanvoid  ficlFree   (void *p);
390123372Sgrehanvoid *ficlRealloc(void *p, size_t size);
391123372Sgrehan/*
392123372Sgrehan** Stub function for dictionary access control - does nothing
393123372Sgrehan** by default, user can redefine to guarantee exclusive dict
394123372Sgrehan** access to a single thread for updates. All dict update code
395123372Sgrehan** must be bracketed as follows:
396123372Sgrehan** ficlLockDictionary(TRUE);
397123372Sgrehan** <code that updates dictionary>
398123372Sgrehan** ficlLockDictionary(FALSE);
399123372Sgrehan**
400123372Sgrehan** Returns zero if successful, nonzero if unable to acquire lock
401123372Sgrehan** before timeout (optional - could also block forever)
402123372Sgrehan**
403123372Sgrehan** NOTE: this function must be implemented with lock counting
404123372Sgrehan** semantics: nested calls must behave properly.
405123372Sgrehan*/
406123372Sgrehan#if FICL_MULTITHREAD
407123372Sgrehanint ficlLockDictionary(short fLock);
408123372Sgrehan#else
409123372Sgrehan#define ficlLockDictionary(x) 0 /* ignore */
410123372Sgrehan#endif
411123372Sgrehan
412123372Sgrehan/*
413123372Sgrehan** 64 bit integer math support routines: multiply two UNS32s
414123372Sgrehan** to get a 64 bit product, & divide the product by an UNS32
415123372Sgrehan** to get an UNS32 quotient and remainder. Much easier in asm
416123372Sgrehan** on a 32 bit CPU than in C, which usually doesn't support
417123372Sgrehan** the double length result (but it should).
418123372Sgrehan*/
419123372SgrehanDPUNS ficlLongMul(FICL_UNS x, FICL_UNS y);
420123372SgrehanUNSQR ficlLongDiv(DPUNS    q, FICL_UNS y);
421123372Sgrehan
422123372Sgrehan/*
423123372Sgrehan** FICL_HAVE_FTRUNCATE indicates whether the current OS supports
424123372Sgrehan** the ftruncate() function (available on most UNIXes).  This
425123372Sgrehan** function is necessary to provide the complete File-Access wordset.
426123372Sgrehan*/
427123372Sgrehan#if !defined (FICL_HAVE_FTRUNCATE)
428123372Sgrehan#define FICL_HAVE_FTRUNCATE 0
429123372Sgrehan#endif
430123372Sgrehan
431123372Sgrehan
432123372Sgrehan#endif /*__SYSDEP_H__*/
433