140843Smsmith/*******************************************************************
240843Smsmith                    s y s d e p . h
340843Smsmith** Forth Inspired Command Language
440843Smsmith** Author: John Sadler (john_sadler@alum.mit.edu)
540843Smsmith** Created: 16 Oct 1997
640843Smsmith** Ficl system dependent types and prototypes...
740843Smsmith**
840843Smsmith** Note: Ficl also depends on the use of "assert" when
940843Smsmith** FICL_ROBUST is enabled. This may require some consideration
1040843Smsmith** in firmware systems since assert often
1140843Smsmith** assumes stderr/stdout.
1294290Sdcs** $Id: sysdep.h,v 1.11 2001/12/05 07:21:34 jsadler Exp $
1340843Smsmith*******************************************************************/
1440843Smsmith/*
1576116Sdcs** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)
1676116Sdcs** All rights reserved.
1776116Sdcs**
1876116Sdcs** Get the latest Ficl release at http://ficl.sourceforge.net
1976116Sdcs**
2094290Sdcs** I am interested in hearing from anyone who uses ficl. If you have
2194290Sdcs** a problem, a success story, a defect, an enhancement request, or
2294290Sdcs** if you would like to contribute to the ficl release, please
2394290Sdcs** contact me by email at the address above.
2494290Sdcs**
2576116Sdcs** L I C E N S E  and  D I S C L A I M E R
2640843Smsmith**
2776116Sdcs** Redistribution and use in source and binary forms, with or without
2876116Sdcs** modification, are permitted provided that the following conditions
2976116Sdcs** are met:
3076116Sdcs** 1. Redistributions of source code must retain the above copyright
3176116Sdcs**    notice, this list of conditions and the following disclaimer.
3276116Sdcs** 2. Redistributions in binary form must reproduce the above copyright
3376116Sdcs**    notice, this list of conditions and the following disclaimer in the
3476116Sdcs**    documentation and/or other materials provided with the distribution.
3576116Sdcs**
3676116Sdcs** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
3776116Sdcs** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3876116Sdcs** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3976116Sdcs** ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4076116Sdcs** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4176116Sdcs** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4276116Sdcs** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4376116Sdcs** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4476116Sdcs** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
4576116Sdcs** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4676116Sdcs** SUCH DAMAGE.
4740843Smsmith*/
4840843Smsmith
4951786Sdcs/* $FreeBSD: releng/10.3/sys/boot/ficl/i386/sysdep.h 231042 2012-02-05 20:00:39Z rpaulo $ */
5051786Sdcs
5140843Smsmith#if !defined (__SYSDEP_H__)
5240843Smsmith#define __SYSDEP_H__
5340843Smsmith
5440843Smsmith#include <sys/types.h>
5540843Smsmith
5640843Smsmith#include <stddef.h> /* size_t, NULL */
5740843Smsmith#include <setjmp.h>
5840843Smsmith#include <assert.h>
5940843Smsmith
6040843Smsmith#if !defined IGNORE		/* Macro to silence unused param warnings */
61231042Srpaulo#define IGNORE(x) (void)x
6240843Smsmith#endif
6340843Smsmith
6440843Smsmith/*
6540843Smsmith** TRUE and FALSE for C boolean operations, and
6640843Smsmith** portable 32 bit types for CELLs
6740843Smsmith**
6840843Smsmith*/
6940843Smsmith#if !defined TRUE
7040843Smsmith#define TRUE 1
7140843Smsmith#endif
7240843Smsmith#if !defined FALSE
7340843Smsmith#define FALSE 0
7440843Smsmith#endif
7540843Smsmith
7651786Sdcs/*
7751786Sdcs** System dependent data type declarations...
7851786Sdcs*/
7940843Smsmith#if !defined INT32
8051786Sdcs#define INT32 long
8140843Smsmith#endif
8240843Smsmith
8340843Smsmith#if !defined UNS32
8451786Sdcs#define UNS32 unsigned long
8540843Smsmith#endif
8640843Smsmith
8740843Smsmith#if !defined UNS16
8851786Sdcs#define UNS16 unsigned short
8940843Smsmith#endif
9040843Smsmith
9140843Smsmith#if !defined UNS8
9251786Sdcs#define UNS8 unsigned char
9340843Smsmith#endif
9440843Smsmith
9540843Smsmith#if !defined NULL
9640843Smsmith#define NULL ((void *)0)
9740843Smsmith#endif
9840843Smsmith
9951786Sdcs/*
10051786Sdcs** FICL_UNS and FICL_INT must have the same size as a void* on
10151786Sdcs** the target system. A CELL is a union of void*, FICL_UNS, and
10251786Sdcs** FICL_INT.
10376116Sdcs** (11/2000: same for FICL_FLOAT)
10451786Sdcs*/
10551786Sdcs#if !defined FICL_INT
10651786Sdcs#define FICL_INT INT32
10751786Sdcs#endif
10851786Sdcs
10951786Sdcs#if !defined FICL_UNS
11051786Sdcs#define FICL_UNS UNS32
11151786Sdcs#endif
11251786Sdcs
11376116Sdcs#if !defined FICL_FLOAT
11476116Sdcs#define FICL_FLOAT float
11576116Sdcs#endif
11676116Sdcs
11751786Sdcs/*
11851786Sdcs** Ficl presently supports values of 32 and 64 for BITS_PER_CELL
11951786Sdcs*/
12051786Sdcs#if !defined BITS_PER_CELL
12151786Sdcs#define BITS_PER_CELL 32
12251786Sdcs#endif
12351786Sdcs
12451786Sdcs#if ((BITS_PER_CELL != 32) && (BITS_PER_CELL != 64))
12551786Sdcs    Error!
12651786Sdcs#endif
12751786Sdcs
12840843Smsmithtypedef struct
12940843Smsmith{
13051786Sdcs    FICL_UNS hi;
13151786Sdcs    FICL_UNS lo;
13251786Sdcs} DPUNS;
13340843Smsmith
13440843Smsmithtypedef struct
13540843Smsmith{
13651786Sdcs    FICL_UNS quot;
13751786Sdcs    FICL_UNS rem;
13840843Smsmith} UNSQR;
13940843Smsmith
14040843Smsmithtypedef struct
14140843Smsmith{
14251786Sdcs    FICL_INT hi;
14351786Sdcs    FICL_INT lo;
14451786Sdcs} DPINT;
14540843Smsmith
14640843Smsmithtypedef struct
14740843Smsmith{
14851786Sdcs    FICL_INT quot;
14951786Sdcs    FICL_INT rem;
15040843Smsmith} INTQR;
15140843Smsmith
15240843Smsmith
15340843Smsmith/*
15476116Sdcs** B U I L D   C O N T R O L S
15576116Sdcs*/
15676116Sdcs
15776116Sdcs#if !defined (FICL_MINIMAL)
15876116Sdcs#define FICL_MINIMAL 0
15976116Sdcs#endif
16076116Sdcs#if (FICL_MINIMAL)
16176116Sdcs#define FICL_WANT_SOFTWORDS  0
16294290Sdcs#define FICL_WANT_FILE       0
16376116Sdcs#define FICL_WANT_FLOAT      0
16476116Sdcs#define FICL_WANT_USER       0
16576116Sdcs#define FICL_WANT_LOCALS     0
16676116Sdcs#define FICL_WANT_DEBUGGER   0
16776116Sdcs#define FICL_WANT_OOP        0
16876116Sdcs#define FICL_PLATFORM_EXTEND 0
16976116Sdcs#define FICL_MULTITHREAD     0
17076116Sdcs#define FICL_ROBUST          0
17176116Sdcs#define FICL_EXTENDED_PREFIX 0
17276116Sdcs#endif
17376116Sdcs
17476116Sdcs/*
17576116Sdcs** FICL_PLATFORM_EXTEND
17676116Sdcs** Includes words defined in ficlCompilePlatform
17776116Sdcs*/
17876116Sdcs#if !defined (FICL_PLATFORM_EXTEND)
17976116Sdcs#define FICL_PLATFORM_EXTEND 1
18076116Sdcs#endif
18176116Sdcs
18294290Sdcs
18376116Sdcs/*
18494290Sdcs** FICL_WANT_FILE
18594290Sdcs** Includes the FILE and FILE-EXT wordset and associated code. Turn this off if you do not
18696755Strhodes** have a filesystem!
18794290Sdcs** Contributed by Larry Hastings
18894290Sdcs*/
18994290Sdcs#if !defined (FICL_WANT_FILE)
19094290Sdcs#define FICL_WANT_FILE 0
19194290Sdcs#endif
19294290Sdcs
19394290Sdcs/*
19476116Sdcs** FICL_WANT_FLOAT
19576116Sdcs** Includes a floating point stack for the VM, and words to do float operations.
19676116Sdcs** Contributed by Guy Carver
19776116Sdcs*/
19876116Sdcs#if !defined (FICL_WANT_FLOAT)
19976116Sdcs#define FICL_WANT_FLOAT 0
20076116Sdcs#endif
20176116Sdcs
20276116Sdcs/*
20376116Sdcs** FICL_WANT_DEBUGGER
20476116Sdcs** Inludes a simple source level debugger
20576116Sdcs*/
20676116Sdcs#if !defined (FICL_WANT_DEBUGGER)
20776116Sdcs#define FICL_WANT_DEBUGGER 1
20876116Sdcs#endif
20976116Sdcs
21076116Sdcs/*
21194290Sdcs** FICL_EXTENDED_PREFIX enables a bunch of extra prefixes in prefix.c and prefix.fr (if
21294290Sdcs** included as part of softcore.c)
21394290Sdcs*/
21494290Sdcs#if !defined FICL_EXTENDED_PREFIX
21594290Sdcs#define FICL_EXTENDED_PREFIX 0
21694290Sdcs#endif
21794290Sdcs
21894290Sdcs/*
21976116Sdcs** User variables: per-instance variables bound to the VM.
22076116Sdcs** Kinda like thread-local storage. Could be implemented in a
22176116Sdcs** VM private dictionary, but I've chosen the lower overhead
22276116Sdcs** approach of an array of CELLs instead.
22376116Sdcs*/
22476116Sdcs#if !defined FICL_WANT_USER
22576116Sdcs#define FICL_WANT_USER 1
22676116Sdcs#endif
22776116Sdcs
22876116Sdcs#if !defined FICL_USER_CELLS
22976116Sdcs#define FICL_USER_CELLS 16
23076116Sdcs#endif
23176116Sdcs
23276116Sdcs/*
23376116Sdcs** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and
23476116Sdcs** a private dictionary for local variable compilation.
23576116Sdcs*/
23676116Sdcs#if !defined FICL_WANT_LOCALS
23776116Sdcs#define FICL_WANT_LOCALS 1
23876116Sdcs#endif
23976116Sdcs
24076116Sdcs/* Max number of local variables per definition */
24176116Sdcs#if !defined FICL_MAX_LOCALS
24276116Sdcs#define FICL_MAX_LOCALS 16
24376116Sdcs#endif
24476116Sdcs
24576116Sdcs/*
24676116Sdcs** FICL_WANT_OOP
24776116Sdcs** Inludes object oriented programming support (in softwords)
24876116Sdcs** OOP support requires locals and user variables!
24976116Sdcs*/
25076116Sdcs#if !(FICL_WANT_LOCALS) || !(FICL_WANT_USER)
25176116Sdcs#if !defined (FICL_WANT_OOP)
25276116Sdcs#define FICL_WANT_OOP 0
25376116Sdcs#endif
25476116Sdcs#endif
25576116Sdcs
25676116Sdcs#if !defined (FICL_WANT_OOP)
25776116Sdcs#define FICL_WANT_OOP 1
25876116Sdcs#endif
25976116Sdcs
26076116Sdcs/*
26176116Sdcs** FICL_WANT_SOFTWORDS
26276116Sdcs** Controls inclusion of all softwords in softcore.c
26376116Sdcs*/
26476116Sdcs#if !defined (FICL_WANT_SOFTWORDS)
26576116Sdcs#define FICL_WANT_SOFTWORDS 1
26676116Sdcs#endif
26776116Sdcs
26876116Sdcs/*
26940843Smsmith** FICL_MULTITHREAD enables dictionary mutual exclusion
27040843Smsmith** wia the ficlLockDictionary system dependent function.
27176116Sdcs** Note: this implementation is experimental and poorly
27276116Sdcs** tested. Further, it's unnecessary unless you really
27376116Sdcs** intend to have multiple SESSIONS (poor choice of name
27476116Sdcs** on my part) - that is, threads that modify the dictionary
27576116Sdcs** at the same time.
27640843Smsmith*/
27740843Smsmith#if !defined FICL_MULTITHREAD
27840843Smsmith#define FICL_MULTITHREAD 0
27940843Smsmith#endif
28040843Smsmith
28140843Smsmith/*
28251786Sdcs** PORTABLE_LONGMULDIV causes ficlLongMul and ficlLongDiv to be
28351786Sdcs** defined in C in sysdep.c. Use this if you cannot easily
28451786Sdcs** generate an inline asm definition
28551786Sdcs*/
28651786Sdcs#if !defined (PORTABLE_LONGMULDIV)
28751786Sdcs#define PORTABLE_LONGMULDIV 0
28851786Sdcs#endif
28951786Sdcs
29051786Sdcs/*
29151786Sdcs** INLINE_INNER_LOOP causes the inner interpreter to be inline code
29251786Sdcs** instead of a function call. This is mainly because MS VC++ 5
29351786Sdcs** chokes with an internal compiler error on the function version.
29451786Sdcs** in release mode. Sheesh.
29551786Sdcs*/
29651786Sdcs#if !defined INLINE_INNER_LOOP
29751786Sdcs#if defined _DEBUG
29851786Sdcs#define INLINE_INNER_LOOP 0
29951786Sdcs#else
30051786Sdcs#define INLINE_INNER_LOOP 1
30151786Sdcs#endif
30251786Sdcs#endif
30351786Sdcs
30451786Sdcs/*
30540843Smsmith** FICL_ROBUST enables bounds checking of stacks and the dictionary.
30640843Smsmith** This will detect stack over and underflows and dictionary overflows.
30740843Smsmith** Any exceptional condition will result in an assertion failure.
30840843Smsmith** (As generated by the ANSI assert macro)
30940843Smsmith** FICL_ROBUST == 1 --> stack checking in the outer interpreter
31040843Smsmith** FICL_ROBUST == 2 also enables checking in many primitives
31140843Smsmith*/
31240843Smsmith
31340843Smsmith#if !defined FICL_ROBUST
31440843Smsmith#define FICL_ROBUST 2
31540843Smsmith#endif
31640843Smsmith
31740843Smsmith/*
31840843Smsmith** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of
31940843Smsmith** a new virtual machine's stacks, unless overridden at
32040843Smsmith** create time.
32140843Smsmith*/
32240843Smsmith#if !defined FICL_DEFAULT_STACK
32340843Smsmith#define FICL_DEFAULT_STACK 128
32440843Smsmith#endif
32540843Smsmith
32640843Smsmith/*
32740843Smsmith** FICL_DEFAULT_DICT specifies the number of CELLs to allocate
32840843Smsmith** for the system dictionary by default. The value
32940843Smsmith** can be overridden at startup time as well.
33040843Smsmith** FICL_DEFAULT_ENV specifies the number of cells to allot
33140843Smsmith** for the environment-query dictionary.
33240843Smsmith*/
33340843Smsmith#if !defined FICL_DEFAULT_DICT
33440843Smsmith#define FICL_DEFAULT_DICT 12288
33540843Smsmith#endif
33640843Smsmith
33740843Smsmith#if !defined FICL_DEFAULT_ENV
33840843Smsmith#define FICL_DEFAULT_ENV 260
33940843Smsmith#endif
34040843Smsmith
34140843Smsmith/*
34240843Smsmith** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in
34340843Smsmith** the dictionary search order. See Forth DPANS sec 16.3.3
34440843Smsmith** (file://dpans16.htm#16.3.3)
34540843Smsmith*/
34640843Smsmith#if !defined FICL_DEFAULT_VOCS
34740843Smsmith#define FICL_DEFAULT_VOCS 16
34840843Smsmith#endif
34940843Smsmith
35040843Smsmith/*
35176116Sdcs** FICL_MAX_PARSE_STEPS controls the size of an array in the FICL_SYSTEM structure
35276116Sdcs** that stores pointers to parser extension functions. I would never expect to have
35376116Sdcs** more than 8 of these, so that's the default limit. Too many of these functions
35476116Sdcs** will probably exact a nasty performance penalty.
35540843Smsmith*/
35676116Sdcs#if !defined FICL_MAX_PARSE_STEPS
35776116Sdcs#define FICL_MAX_PARSE_STEPS 8
35840843Smsmith#endif
35940843Smsmith
36076116Sdcs/*
36140843Smsmith** FICL_ALIGN is the power of two to which the dictionary
36240843Smsmith** pointer address must be aligned. This value is usually
36340843Smsmith** either 1 or 2, depending on the memory architecture
36440843Smsmith** of the target system; 2 is safe on any 16 or 32 bit
36551786Sdcs** machine. 3 would be appropriate for a 64 bit machine.
36640843Smsmith*/
36740843Smsmith#if !defined FICL_ALIGN
36840843Smsmith#define FICL_ALIGN 2
36940843Smsmith#define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1)
37040843Smsmith#endif
37140843Smsmith
37240843Smsmith/*
37340843Smsmith** System dependent routines --
37440843Smsmith** edit the implementations in sysdep.c to be compatible
37540843Smsmith** with your runtime environment...
37640843Smsmith** ficlTextOut sends a NULL terminated string to the
37740843Smsmith**   default output device - used for system error messages
37840843Smsmith** ficlMalloc and ficlFree have the same semantics as malloc and free
37940843Smsmith**   in standard C
38040843Smsmith** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned
38140843Smsmith**   product
38240843Smsmith** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient
38340843Smsmith**   and remainder
38440843Smsmith*/
38540843Smsmithstruct vm;
38640843Smsmithvoid  ficlTextOut(struct vm *pVM, char *msg, int fNewline);
38740843Smsmithvoid *ficlMalloc (size_t size);
38840843Smsmithvoid  ficlFree   (void *p);
38951786Sdcsvoid *ficlRealloc(void *p, size_t size);
39040843Smsmith/*
39140843Smsmith** Stub function for dictionary access control - does nothing
39240843Smsmith** by default, user can redefine to guarantee exclusive dict
39340843Smsmith** access to a single thread for updates. All dict update code
39440843Smsmith** must be bracketed as follows:
39540843Smsmith** ficlLockDictionary(TRUE);
39640843Smsmith** <code that updates dictionary>
39740843Smsmith** ficlLockDictionary(FALSE);
39840843Smsmith**
39940843Smsmith** Returns zero if successful, nonzero if unable to acquire lock
40040843Smsmith** before timeout (optional - could also block forever)
40140843Smsmith**
40240843Smsmith** NOTE: this function must be implemented with lock counting
40340843Smsmith** semantics: nested calls must behave properly.
40440843Smsmith*/
40540843Smsmith#if FICL_MULTITHREAD
40640843Smsmithint ficlLockDictionary(short fLock);
40740843Smsmith#else
408231042Srpaulo#define ficlLockDictionary(x) /* ignore */
40940843Smsmith#endif
41040843Smsmith
41140843Smsmith/*
41240843Smsmith** 64 bit integer math support routines: multiply two UNS32s
41351786Sdcs** to get a 64 bit product, & divide the product by an UNS32
41440843Smsmith** to get an UNS32 quotient and remainder. Much easier in asm
41540843Smsmith** on a 32 bit CPU than in C, which usually doesn't support
41640843Smsmith** the double length result (but it should).
41740843Smsmith*/
41851786SdcsDPUNS ficlLongMul(FICL_UNS x, FICL_UNS y);
41951786SdcsUNSQR ficlLongDiv(DPUNS    q, FICL_UNS y);
42040843Smsmith
42194290Sdcs
42294290Sdcs/*
42394290Sdcs** FICL_HAVE_FTRUNCATE indicates whether the current OS supports
42494290Sdcs** the ftruncate() function (available on most UNIXes).  This
42594290Sdcs** function is necessary to provide the complete File-Access wordset.
42694290Sdcs*/
42794290Sdcs#if !defined (FICL_HAVE_FTRUNCATE)
42894290Sdcs#define FICL_HAVE_FTRUNCATE 0
42994290Sdcs#endif
43094290Sdcs
43194290Sdcs
43240843Smsmith#endif /*__SYSDEP_H__*/
433