1223695Sdfr/*******************************************************************
2223695Sdfr                    s y s d e p . h
3223695Sdfr** Forth Inspired Command Language
4223695Sdfr** Author: John Sadler (john_sadler@alum.mit.edu)
5223695Sdfr** Created: 16 Oct 1997
6223695Sdfr** Ficl system dependent types and prototypes...
7223695Sdfr**
8223695Sdfr** Note: Ficl also depends on the use of "assert" when
9223695Sdfr** FICL_ROBUST is enabled. This may require some consideration
10223695Sdfr** in firmware systems since assert often
11223695Sdfr** assumes stderr/stdout.
12223695Sdfr** $Id: sysdep.h,v 1.11 2001/12/05 07:21:34 jsadler Exp $
13223695Sdfr*******************************************************************/
14223695Sdfr/*
15223695Sdfr** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)
16223695Sdfr** All rights reserved.
17223695Sdfr**
18223695Sdfr** Get the latest Ficl release at http://ficl.sourceforge.net
19223695Sdfr**
20223695Sdfr** I am interested in hearing from anyone who uses ficl. If you have
21223695Sdfr** a problem, a success story, a defect, an enhancement request, or
22223695Sdfr** if you would like to contribute to the ficl release, please
23223695Sdfr** contact me by email at the address above.
24223695Sdfr**
25223695Sdfr** L I C E N S E  and  D I S C L A I M E R
26223695Sdfr**
27223695Sdfr** Redistribution and use in source and binary forms, with or without
28223695Sdfr** modification, are permitted provided that the following conditions
29223695Sdfr** are met:
30223695Sdfr** 1. Redistributions of source code must retain the above copyright
31223695Sdfr**    notice, this list of conditions and the following disclaimer.
32223695Sdfr** 2. Redistributions in binary form must reproduce the above copyright
33223695Sdfr**    notice, this list of conditions and the following disclaimer in the
34223695Sdfr**    documentation and/or other materials provided with the distribution.
35223695Sdfr**
36223695Sdfr** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
37223695Sdfr** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38223695Sdfr** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39223695Sdfr** ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
40223695Sdfr** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41223695Sdfr** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
42223695Sdfr** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43223695Sdfr** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
44223695Sdfr** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45223695Sdfr** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46223695Sdfr** SUCH DAMAGE.
47223695Sdfr**
48223695Sdfr** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $
49223695Sdfr*/
50223695Sdfr
51223695Sdfr/* $FreeBSD: stable/11/stand/ficl/amd64/sysdep.h 223695 2011-06-30 16:08:56Z dfr $ */
52223695Sdfr
53223695Sdfr#if !defined (__SYSDEP_H__)
54223695Sdfr#define __SYSDEP_H__
55223695Sdfr
56223695Sdfr#include <sys/types.h>
57223695Sdfr
58223695Sdfr#include <stddef.h> /* size_t, NULL */
59223695Sdfr#include <setjmp.h>
60223695Sdfr#include <assert.h>
61223695Sdfr
62223695Sdfr#if !defined IGNORE		/* Macro to silence unused param warnings */
63223695Sdfr#define IGNORE(x) &x
64223695Sdfr#endif
65223695Sdfr
66223695Sdfr/*
67223695Sdfr** TRUE and FALSE for C boolean operations, and
68223695Sdfr** portable 32 bit types for CELLs
69223695Sdfr**
70223695Sdfr*/
71223695Sdfr#if !defined TRUE
72223695Sdfr#define TRUE 1
73223695Sdfr#endif
74223695Sdfr#if !defined FALSE
75223695Sdfr#define FALSE 0
76223695Sdfr#endif
77223695Sdfr
78223695Sdfr/*
79223695Sdfr** System dependent data type declarations...
80223695Sdfr*/
81223695Sdfr#if !defined INT32
82223695Sdfr#define INT32 int
83223695Sdfr#endif
84223695Sdfr
85223695Sdfr#if !defined UNS32
86223695Sdfr#define UNS32 unsigned int
87223695Sdfr#endif
88223695Sdfr
89223695Sdfr#if !defined UNS16
90223695Sdfr#define UNS16 unsigned short
91223695Sdfr#endif
92223695Sdfr
93223695Sdfr#if !defined UNS8
94223695Sdfr#define UNS8 unsigned char
95223695Sdfr#endif
96223695Sdfr
97223695Sdfr#if !defined NULL
98223695Sdfr#define NULL ((void *)0)
99223695Sdfr#endif
100223695Sdfr
101223695Sdfr/*
102223695Sdfr** FICL_UNS and FICL_INT must have the same size as a void* on
103223695Sdfr** the target system. A CELL is a union of void*, FICL_UNS, and
104223695Sdfr** FICL_INT.
105223695Sdfr** (11/2000: same for FICL_FLOAT)
106223695Sdfr*/
107223695Sdfr#if !defined FICL_INT
108223695Sdfr#define FICL_INT long
109223695Sdfr#endif
110223695Sdfr
111223695Sdfr#if !defined FICL_UNS
112223695Sdfr#define FICL_UNS unsigned long
113223695Sdfr#endif
114223695Sdfr
115223695Sdfr#if !defined FICL_FLOAT
116223695Sdfr#define FICL_FLOAT float
117223695Sdfr#endif
118223695Sdfr
119223695Sdfr/*
120223695Sdfr** Ficl presently supports values of 32 and 64 for BITS_PER_CELL
121223695Sdfr*/
122223695Sdfr#if !defined BITS_PER_CELL
123223695Sdfr#define BITS_PER_CELL 64
124223695Sdfr#endif
125223695Sdfr
126223695Sdfr#if ((BITS_PER_CELL != 32) && (BITS_PER_CELL != 64))
127223695Sdfr    Error!
128223695Sdfr#endif
129223695Sdfr
130223695Sdfrtypedef struct
131223695Sdfr{
132223695Sdfr    FICL_UNS hi;
133223695Sdfr    FICL_UNS lo;
134223695Sdfr} DPUNS;
135223695Sdfr
136223695Sdfrtypedef struct
137223695Sdfr{
138223695Sdfr    FICL_UNS quot;
139223695Sdfr    FICL_UNS rem;
140223695Sdfr} UNSQR;
141223695Sdfr
142223695Sdfrtypedef struct
143223695Sdfr{
144223695Sdfr    FICL_INT hi;
145223695Sdfr    FICL_INT lo;
146223695Sdfr} DPINT;
147223695Sdfr
148223695Sdfrtypedef struct
149223695Sdfr{
150223695Sdfr    FICL_INT quot;
151223695Sdfr    FICL_INT rem;
152223695Sdfr} INTQR;
153223695Sdfr
154223695Sdfr
155223695Sdfr/*
156223695Sdfr** B U I L D   C O N T R O L S
157223695Sdfr*/
158223695Sdfr
159223695Sdfr#if !defined (FICL_MINIMAL)
160223695Sdfr#define FICL_MINIMAL 0
161223695Sdfr#endif
162223695Sdfr#if (FICL_MINIMAL)
163223695Sdfr#define FICL_WANT_SOFTWORDS  0
164223695Sdfr#define FICL_WANT_FILE       0
165223695Sdfr#define FICL_WANT_FLOAT      0
166223695Sdfr#define FICL_WANT_USER       0
167223695Sdfr#define FICL_WANT_LOCALS     0
168223695Sdfr#define FICL_WANT_DEBUGGER   0
169223695Sdfr#define FICL_WANT_OOP        0
170223695Sdfr#define FICL_PLATFORM_EXTEND 0
171223695Sdfr#define FICL_MULTITHREAD     0
172223695Sdfr#define FICL_ROBUST          0
173223695Sdfr#define FICL_EXTENDED_PREFIX 0
174223695Sdfr#endif
175223695Sdfr
176223695Sdfr/*
177223695Sdfr** FICL_PLATFORM_EXTEND
178223695Sdfr** Includes words defined in ficlCompilePlatform
179223695Sdfr*/
180223695Sdfr#if !defined (FICL_PLATFORM_EXTEND)
181223695Sdfr#define FICL_PLATFORM_EXTEND 1
182223695Sdfr#endif
183223695Sdfr
184223695Sdfr
185223695Sdfr/*
186223695Sdfr** FICL_WANT_FILE
187223695Sdfr** Includes the FILE and FILE-EXT wordset and associated code. Turn this off if you do not
188223695Sdfr** have a filesystem!
189223695Sdfr** Contributed by Larry Hastings
190223695Sdfr*/
191223695Sdfr#if !defined (FICL_WANT_FILE)
192223695Sdfr#define FICL_WANT_FILE 0
193223695Sdfr#endif
194223695Sdfr
195223695Sdfr/*
196223695Sdfr** FICL_WANT_FLOAT
197223695Sdfr** Includes a floating point stack for the VM, and words to do float operations.
198223695Sdfr** Contributed by Guy Carver
199223695Sdfr*/
200223695Sdfr#if !defined (FICL_WANT_FLOAT)
201223695Sdfr#define FICL_WANT_FLOAT 0
202223695Sdfr#endif
203223695Sdfr
204223695Sdfr/*
205223695Sdfr** FICL_WANT_DEBUGGER
206223695Sdfr** Inludes a simple source level debugger
207223695Sdfr*/
208223695Sdfr#if !defined (FICL_WANT_DEBUGGER)
209223695Sdfr#define FICL_WANT_DEBUGGER 1
210223695Sdfr#endif
211223695Sdfr
212223695Sdfr/*
213223695Sdfr** FICL_EXTENDED_PREFIX enables a bunch of extra prefixes in prefix.c and prefix.fr (if
214223695Sdfr** included as part of softcore.c)
215223695Sdfr*/
216223695Sdfr#if !defined FICL_EXTENDED_PREFIX
217223695Sdfr#define FICL_EXTENDED_PREFIX 0
218223695Sdfr#endif
219223695Sdfr
220223695Sdfr/*
221223695Sdfr** User variables: per-instance variables bound to the VM.
222223695Sdfr** Kinda like thread-local storage. Could be implemented in a
223223695Sdfr** VM private dictionary, but I've chosen the lower overhead
224223695Sdfr** approach of an array of CELLs instead.
225223695Sdfr*/
226223695Sdfr#if !defined FICL_WANT_USER
227223695Sdfr#define FICL_WANT_USER 1
228223695Sdfr#endif
229223695Sdfr
230223695Sdfr#if !defined FICL_USER_CELLS
231223695Sdfr#define FICL_USER_CELLS 16
232223695Sdfr#endif
233223695Sdfr
234223695Sdfr/*
235223695Sdfr** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and
236223695Sdfr** a private dictionary for local variable compilation.
237223695Sdfr*/
238223695Sdfr#if !defined FICL_WANT_LOCALS
239223695Sdfr#define FICL_WANT_LOCALS 1
240223695Sdfr#endif
241223695Sdfr
242223695Sdfr/* Max number of local variables per definition */
243223695Sdfr#if !defined FICL_MAX_LOCALS
244223695Sdfr#define FICL_MAX_LOCALS 16
245223695Sdfr#endif
246223695Sdfr
247223695Sdfr/*
248223695Sdfr** FICL_WANT_OOP
249223695Sdfr** Inludes object oriented programming support (in softwords)
250223695Sdfr** OOP support requires locals and user variables!
251223695Sdfr*/
252223695Sdfr#if !(FICL_WANT_LOCALS) || !(FICL_WANT_USER)
253223695Sdfr#if !defined (FICL_WANT_OOP)
254223695Sdfr#define FICL_WANT_OOP 0
255223695Sdfr#endif
256223695Sdfr#endif
257223695Sdfr
258223695Sdfr#if !defined (FICL_WANT_OOP)
259223695Sdfr#define FICL_WANT_OOP 1
260223695Sdfr#endif
261223695Sdfr
262223695Sdfr/*
263223695Sdfr** FICL_WANT_SOFTWORDS
264223695Sdfr** Controls inclusion of all softwords in softcore.c
265223695Sdfr*/
266223695Sdfr#if !defined (FICL_WANT_SOFTWORDS)
267223695Sdfr#define FICL_WANT_SOFTWORDS 1
268223695Sdfr#endif
269223695Sdfr
270223695Sdfr/*
271223695Sdfr** FICL_MULTITHREAD enables dictionary mutual exclusion
272223695Sdfr** wia the ficlLockDictionary system dependent function.
273223695Sdfr** Note: this implementation is experimental and poorly
274223695Sdfr** tested. Further, it's unnecessary unless you really
275223695Sdfr** intend to have multiple SESSIONS (poor choice of name
276223695Sdfr** on my part) - that is, threads that modify the dictionary
277223695Sdfr** at the same time.
278223695Sdfr*/
279223695Sdfr#if !defined FICL_MULTITHREAD
280223695Sdfr#define FICL_MULTITHREAD 0
281223695Sdfr#endif
282223695Sdfr
283223695Sdfr/*
284223695Sdfr** PORTABLE_LONGMULDIV causes ficlLongMul and ficlLongDiv to be
285223695Sdfr** defined in C in sysdep.c. Use this if you cannot easily
286223695Sdfr** generate an inline asm definition
287223695Sdfr*/
288223695Sdfr#if !defined (PORTABLE_LONGMULDIV)
289223695Sdfr#define PORTABLE_LONGMULDIV 0
290223695Sdfr#endif
291223695Sdfr
292223695Sdfr/*
293223695Sdfr** INLINE_INNER_LOOP causes the inner interpreter to be inline code
294223695Sdfr** instead of a function call. This is mainly because MS VC++ 5
295223695Sdfr** chokes with an internal compiler error on the function version.
296223695Sdfr** in release mode. Sheesh.
297223695Sdfr*/
298223695Sdfr#if !defined INLINE_INNER_LOOP
299223695Sdfr#if defined _DEBUG
300223695Sdfr#define INLINE_INNER_LOOP 0
301223695Sdfr#else
302223695Sdfr#define INLINE_INNER_LOOP 1
303223695Sdfr#endif
304223695Sdfr#endif
305223695Sdfr
306223695Sdfr/*
307223695Sdfr** FICL_ROBUST enables bounds checking of stacks and the dictionary.
308223695Sdfr** This will detect stack over and underflows and dictionary overflows.
309223695Sdfr** Any exceptional condition will result in an assertion failure.
310223695Sdfr** (As generated by the ANSI assert macro)
311223695Sdfr** FICL_ROBUST == 1 --> stack checking in the outer interpreter
312223695Sdfr** FICL_ROBUST == 2 also enables checking in many primitives
313223695Sdfr*/
314223695Sdfr
315223695Sdfr#if !defined FICL_ROBUST
316223695Sdfr#define FICL_ROBUST 2
317223695Sdfr#endif
318223695Sdfr
319223695Sdfr/*
320223695Sdfr** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of
321223695Sdfr** a new virtual machine's stacks, unless overridden at
322223695Sdfr** create time.
323223695Sdfr*/
324223695Sdfr#if !defined FICL_DEFAULT_STACK
325223695Sdfr#define FICL_DEFAULT_STACK 128
326223695Sdfr#endif
327223695Sdfr
328223695Sdfr/*
329223695Sdfr** FICL_DEFAULT_DICT specifies the number of CELLs to allocate
330223695Sdfr** for the system dictionary by default. The value
331223695Sdfr** can be overridden at startup time as well.
332223695Sdfr** FICL_DEFAULT_ENV specifies the number of cells to allot
333223695Sdfr** for the environment-query dictionary.
334223695Sdfr*/
335223695Sdfr#if !defined FICL_DEFAULT_DICT
336223695Sdfr#define FICL_DEFAULT_DICT 12288
337223695Sdfr#endif
338223695Sdfr
339223695Sdfr#if !defined FICL_DEFAULT_ENV
340223695Sdfr#define FICL_DEFAULT_ENV 260
341223695Sdfr#endif
342223695Sdfr
343223695Sdfr/*
344223695Sdfr** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in
345223695Sdfr** the dictionary search order. See Forth DPANS sec 16.3.3
346223695Sdfr** (file://dpans16.htm#16.3.3)
347223695Sdfr*/
348223695Sdfr#if !defined FICL_DEFAULT_VOCS
349223695Sdfr#define FICL_DEFAULT_VOCS 16
350223695Sdfr#endif
351223695Sdfr
352223695Sdfr/*
353223695Sdfr** FICL_MAX_PARSE_STEPS controls the size of an array in the FICL_SYSTEM structure
354223695Sdfr** that stores pointers to parser extension functions. I would never expect to have
355223695Sdfr** more than 8 of these, so that's the default limit. Too many of these functions
356223695Sdfr** will probably exact a nasty performance penalty.
357223695Sdfr*/
358223695Sdfr#if !defined FICL_MAX_PARSE_STEPS
359223695Sdfr#define FICL_MAX_PARSE_STEPS 8
360223695Sdfr#endif
361223695Sdfr
362223695Sdfr/*
363223695Sdfr** FICL_ALIGN is the power of two to which the dictionary
364223695Sdfr** pointer address must be aligned. This value is usually
365223695Sdfr** either 1 or 2, depending on the memory architecture
366223695Sdfr** of the target system; 2 is safe on any 16 or 32 bit
367223695Sdfr** machine. 3 would be appropriate for a 64 bit machine.
368223695Sdfr*/
369223695Sdfr#if !defined FICL_ALIGN
370223695Sdfr#define FICL_ALIGN 3
371223695Sdfr#define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1)
372223695Sdfr#endif
373223695Sdfr
374223695Sdfr/*
375223695Sdfr** System dependent routines --
376223695Sdfr** edit the implementations in sysdep.c to be compatible
377223695Sdfr** with your runtime environment...
378223695Sdfr** ficlTextOut sends a NULL terminated string to the
379223695Sdfr**   default output device - used for system error messages
380223695Sdfr** ficlMalloc and ficlFree have the same semantics as malloc and free
381223695Sdfr**   in standard C
382223695Sdfr** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned
383223695Sdfr**   product
384223695Sdfr** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient
385223695Sdfr**   and remainder
386223695Sdfr*/
387223695Sdfrstruct vm;
388223695Sdfrvoid  ficlTextOut(struct vm *pVM, char *msg, int fNewline);
389223695Sdfrvoid *ficlMalloc (size_t size);
390223695Sdfrvoid  ficlFree   (void *p);
391223695Sdfrvoid *ficlRealloc(void *p, size_t size);
392223695Sdfr/*
393223695Sdfr** Stub function for dictionary access control - does nothing
394223695Sdfr** by default, user can redefine to guarantee exclusive dict
395223695Sdfr** access to a single thread for updates. All dict update code
396223695Sdfr** must be bracketed as follows:
397223695Sdfr** ficlLockDictionary(TRUE);
398223695Sdfr** <code that updates dictionary>
399223695Sdfr** ficlLockDictionary(FALSE);
400223695Sdfr**
401223695Sdfr** Returns zero if successful, nonzero if unable to acquire lock
402223695Sdfr** before timeout (optional - could also block forever)
403223695Sdfr**
404223695Sdfr** NOTE: this function must be implemented with lock counting
405223695Sdfr** semantics: nested calls must behave properly.
406223695Sdfr*/
407223695Sdfr#if FICL_MULTITHREAD
408223695Sdfrint ficlLockDictionary(short fLock);
409223695Sdfr#else
410223695Sdfr#define ficlLockDictionary(x) 0 /* ignore */
411223695Sdfr#endif
412223695Sdfr
413223695Sdfr/*
414223695Sdfr** 64 bit integer math support routines: multiply two UNS32s
415223695Sdfr** to get a 64 bit product, & divide the product by an UNS32
416223695Sdfr** to get an UNS32 quotient and remainder. Much easier in asm
417223695Sdfr** on a 32 bit CPU than in C, which usually doesn't support
418223695Sdfr** the double length result (but it should).
419223695Sdfr*/
420223695SdfrDPUNS ficlLongMul(FICL_UNS x, FICL_UNS y);
421223695SdfrUNSQR ficlLongDiv(DPUNS    q, FICL_UNS y);
422223695Sdfr
423223695Sdfr
424223695Sdfr/*
425223695Sdfr** FICL_HAVE_FTRUNCATE indicates whether the current OS supports
426223695Sdfr** the ftruncate() function (available on most UNIXes).  This
427223695Sdfr** function is necessary to provide the complete File-Access wordset.
428223695Sdfr*/
429223695Sdfr#if !defined (FICL_HAVE_FTRUNCATE)
430223695Sdfr#define FICL_HAVE_FTRUNCATE 0
431223695Sdfr#endif
432223695Sdfr
433223695Sdfr
434223695Sdfr#endif /*__SYSDEP_H__*/
435