196962Sjake/******************************************************************* 296962Sjake s y s d e p . h 396962Sjake** Forth Inspired Command Language 496962Sjake** Author: John Sadler (john_sadler@alum.mit.edu) 596962Sjake** Created: 16 Oct 1997 696962Sjake** Ficl system dependent types and prototypes... 796962Sjake** 896962Sjake** Note: Ficl also depends on the use of "assert" when 996962Sjake** FICL_ROBUST is enabled. This may require some consideration 1096962Sjake** in firmware systems since assert often 1196962Sjake** assumes stderr/stdout. 1296962Sjake** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $ 1396962Sjake*******************************************************************/ 1496962Sjake/* 1596962Sjake** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu) 1696962Sjake** All rights reserved. 1796962Sjake** 1896962Sjake** Get the latest Ficl release at http://ficl.sourceforge.net 1996962Sjake** 2096962Sjake** L I C E N S E and D I S C L A I M E R 2196962Sjake** 2296962Sjake** Redistribution and use in source and binary forms, with or without 2396962Sjake** modification, are permitted provided that the following conditions 2496962Sjake** are met: 2596962Sjake** 1. Redistributions of source code must retain the above copyright 2696962Sjake** notice, this list of conditions and the following disclaimer. 2796962Sjake** 2. Redistributions in binary form must reproduce the above copyright 2896962Sjake** notice, this list of conditions and the following disclaimer in the 2996962Sjake** documentation and/or other materials provided with the distribution. 3096962Sjake** 3196962Sjake** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 3296962Sjake** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 3396962Sjake** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 3496962Sjake** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 3596962Sjake** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3696962Sjake** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3796962Sjake** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3896962Sjake** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3996962Sjake** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 4096962Sjake** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 4196962Sjake** SUCH DAMAGE. 4296962Sjake** 4396962Sjake** I am interested in hearing from anyone who uses ficl. If you have 4496962Sjake** a problem, a success story, a defect, an enhancement request, or 4596962Sjake** if you would like to contribute to the ficl release, please send 4696962Sjake** contact me by email at the address above. 4796962Sjake** 4896962Sjake** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $ 4996962Sjake*/ 5096962Sjake 5196962Sjake/* $FreeBSD: releng/10.3/sys/boot/ficl/sparc64/sysdep.h 96962 2002-05-19 23:20:56Z jake $ */ 5296962Sjake 5396962Sjake#if !defined (__SYSDEP_H__) 5496962Sjake#define __SYSDEP_H__ 5596962Sjake 5696962Sjake#include <sys/types.h> 5796962Sjake 5896962Sjake#include <stddef.h> /* size_t, NULL */ 5996962Sjake#include <setjmp.h> 6096962Sjake#include <assert.h> 6196962Sjake 6296962Sjake#if !defined IGNORE /* Macro to silence unused param warnings */ 6396962Sjake#define IGNORE(x) &x 6496962Sjake#endif 6596962Sjake 6696962Sjake/* 6796962Sjake** TRUE and FALSE for C boolean operations, and 6896962Sjake** portable 32 bit types for CELLs 6996962Sjake** 7096962Sjake*/ 7196962Sjake#if !defined TRUE 7296962Sjake#define TRUE 1 7396962Sjake#endif 7496962Sjake#if !defined FALSE 7596962Sjake#define FALSE 0 7696962Sjake#endif 7796962Sjake 7896962Sjake 7996962Sjake/* 8096962Sjake** System dependent data type declarations... 8196962Sjake*/ 8296962Sjake#if !defined INT32 8396962Sjake#define INT32 int 8496962Sjake#endif 8596962Sjake 8696962Sjake#if !defined UNS32 8796962Sjake#define UNS32 unsigned int 8896962Sjake#endif 8996962Sjake 9096962Sjake#if !defined UNS16 9196962Sjake#define UNS16 unsigned short 9296962Sjake#endif 9396962Sjake 9496962Sjake#if !defined UNS8 9596962Sjake#define UNS8 unsigned char 9696962Sjake#endif 9796962Sjake 9896962Sjake#if !defined NULL 9996962Sjake#define NULL ((void *)0) 10096962Sjake#endif 10196962Sjake 10296962Sjake/* 10396962Sjake** FICL_UNS and FICL_INT must have the same size as a void* on 10496962Sjake** the target system. A CELL is a union of void*, FICL_UNS, and 10596962Sjake** FICL_INT. 10696962Sjake** (11/2000: same for FICL_FLOAT) 10796962Sjake*/ 10896962Sjake#if !defined FICL_INT 10996962Sjake#define FICL_INT long 11096962Sjake#endif 11196962Sjake 11296962Sjake#if !defined FICL_UNS 11396962Sjake#define FICL_UNS unsigned long 11496962Sjake#endif 11596962Sjake 11696962Sjake#if !defined FICL_FLOAT 11796962Sjake#define FICL_FLOAT float 11896962Sjake#endif 11996962Sjake 12096962Sjake/* 12196962Sjake** Ficl presently supports values of 32 and 64 for BITS_PER_CELL 12296962Sjake*/ 12396962Sjake#if !defined BITS_PER_CELL 12496962Sjake#define BITS_PER_CELL 64 12596962Sjake#endif 12696962Sjake 12796962Sjake#if ((BITS_PER_CELL != 32) && (BITS_PER_CELL != 64)) 12896962Sjake Error! 12996962Sjake#endif 13096962Sjake 13196962Sjaketypedef struct 13296962Sjake{ 13396962Sjake FICL_UNS hi; 13496962Sjake FICL_UNS lo; 13596962Sjake} DPUNS; 13696962Sjake 13796962Sjaketypedef struct 13896962Sjake{ 13996962Sjake FICL_UNS quot; 14096962Sjake FICL_UNS rem; 14196962Sjake} UNSQR; 14296962Sjake 14396962Sjaketypedef struct 14496962Sjake{ 14596962Sjake FICL_INT hi; 14696962Sjake FICL_INT lo; 14796962Sjake} DPINT; 14896962Sjake 14996962Sjaketypedef struct 15096962Sjake{ 15196962Sjake FICL_INT quot; 15296962Sjake FICL_INT rem; 15396962Sjake} INTQR; 15496962Sjake 15596962Sjake 15696962Sjake/* 15796962Sjake** B U I L D C O N T R O L S 15896962Sjake*/ 15996962Sjake 16096962Sjake#if !defined (FICL_MINIMAL) 16196962Sjake#define FICL_MINIMAL 0 16296962Sjake#endif 16396962Sjake#if (FICL_MINIMAL) 16496962Sjake#define FICL_WANT_SOFTWORDS 0 16596962Sjake#define FICL_WANT_FLOAT 0 16696962Sjake#define FICL_WANT_USER 0 16796962Sjake#define FICL_WANT_LOCALS 0 16896962Sjake#define FICL_WANT_DEBUGGER 0 16996962Sjake#define FICL_WANT_OOP 0 17096962Sjake#define FICL_PLATFORM_EXTEND 0 17196962Sjake#define FICL_MULTITHREAD 0 17296962Sjake#define FICL_ROBUST 0 17396962Sjake#define FICL_EXTENDED_PREFIX 0 17496962Sjake#endif 17596962Sjake 17696962Sjake/* 17796962Sjake** FICL_PLATFORM_EXTEND 17896962Sjake** Includes words defined in ficlCompilePlatform 17996962Sjake*/ 18096962Sjake#if !defined (FICL_PLATFORM_EXTEND) 18196962Sjake#define FICL_PLATFORM_EXTEND 1 18296962Sjake#endif 18396962Sjake 18496962Sjake/* 18596962Sjake** FICL_WANT_FLOAT 18696962Sjake** Includes a floating point stack for the VM, and words to do float operations. 18796962Sjake** Contributed by Guy Carver 18896962Sjake*/ 18996962Sjake#if !defined (FICL_WANT_FLOAT) 19096962Sjake#define FICL_WANT_FLOAT 0 19196962Sjake#endif 19296962Sjake 19396962Sjake/* 19496962Sjake** FICL_WANT_DEBUGGER 19596962Sjake** Inludes a simple source level debugger 19696962Sjake*/ 19796962Sjake#if !defined (FICL_WANT_DEBUGGER) 19896962Sjake#define FICL_WANT_DEBUGGER 1 19996962Sjake#endif 20096962Sjake 20196962Sjake/* 20296962Sjake** User variables: per-instance variables bound to the VM. 20396962Sjake** Kinda like thread-local storage. Could be implemented in a 20496962Sjake** VM private dictionary, but I've chosen the lower overhead 20596962Sjake** approach of an array of CELLs instead. 20696962Sjake*/ 20796962Sjake#if !defined FICL_WANT_USER 20896962Sjake#define FICL_WANT_USER 1 20996962Sjake#endif 21096962Sjake 21196962Sjake#if !defined FICL_USER_CELLS 21296962Sjake#define FICL_USER_CELLS 16 21396962Sjake#endif 21496962Sjake 21596962Sjake/* 21696962Sjake** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and 21796962Sjake** a private dictionary for local variable compilation. 21896962Sjake*/ 21996962Sjake#if !defined FICL_WANT_LOCALS 22096962Sjake#define FICL_WANT_LOCALS 1 22196962Sjake#endif 22296962Sjake 22396962Sjake/* Max number of local variables per definition */ 22496962Sjake#if !defined FICL_MAX_LOCALS 22596962Sjake#define FICL_MAX_LOCALS 16 22696962Sjake#endif 22796962Sjake 22896962Sjake/* 22996962Sjake** FICL_WANT_OOP 23096962Sjake** Inludes object oriented programming support (in softwords) 23196962Sjake** OOP support requires locals and user variables! 23296962Sjake*/ 23396962Sjake#if !(FICL_WANT_LOCALS) || !(FICL_WANT_USER) 23496962Sjake#if !defined (FICL_WANT_OOP) 23596962Sjake#define FICL_WANT_OOP 0 23696962Sjake#endif 23796962Sjake#endif 23896962Sjake 23996962Sjake#if !defined (FICL_WANT_OOP) 24096962Sjake#define FICL_WANT_OOP 1 24196962Sjake#endif 24296962Sjake 24396962Sjake/* 24496962Sjake** FICL_WANT_SOFTWORDS 24596962Sjake** Controls inclusion of all softwords in softcore.c 24696962Sjake*/ 24796962Sjake#if !defined (FICL_WANT_SOFTWORDS) 24896962Sjake#define FICL_WANT_SOFTWORDS 1 24996962Sjake#endif 25096962Sjake 25196962Sjake/* 25296962Sjake** FICL_MULTITHREAD enables dictionary mutual exclusion 25396962Sjake** wia the ficlLockDictionary system dependent function. 25496962Sjake** Note: this implementation is experimental and poorly 25596962Sjake** tested. Further, it's unnecessary unless you really 25696962Sjake** intend to have multiple SESSIONS (poor choice of name 25796962Sjake** on my part) - that is, threads that modify the dictionary 25896962Sjake** at the same time. 25996962Sjake*/ 26096962Sjake#if !defined FICL_MULTITHREAD 26196962Sjake#define FICL_MULTITHREAD 0 26296962Sjake#endif 26396962Sjake 26496962Sjake/* 26596962Sjake** PORTABLE_LONGMULDIV causes ficlLongMul and ficlLongDiv to be 26696962Sjake** defined in C in sysdep.c. Use this if you cannot easily 26796962Sjake** generate an inline asm definition 26896962Sjake*/ 26996962Sjake#if !defined (PORTABLE_LONGMULDIV) 27096962Sjake#define PORTABLE_LONGMULDIV 0 27196962Sjake#endif 27296962Sjake 27396962Sjake/* 27496962Sjake** INLINE_INNER_LOOP causes the inner interpreter to be inline code 27596962Sjake** instead of a function call. This is mainly because MS VC++ 5 27696962Sjake** chokes with an internal compiler error on the function version. 27796962Sjake** in release mode. Sheesh. 27896962Sjake*/ 27996962Sjake#if !defined INLINE_INNER_LOOP 28096962Sjake#if defined _DEBUG 28196962Sjake#define INLINE_INNER_LOOP 0 28296962Sjake#else 28396962Sjake#define INLINE_INNER_LOOP 1 28496962Sjake#endif 28596962Sjake#endif 28696962Sjake 28796962Sjake/* 28896962Sjake** FICL_ROBUST enables bounds checking of stacks and the dictionary. 28996962Sjake** This will detect stack over and underflows and dictionary overflows. 29096962Sjake** Any exceptional condition will result in an assertion failure. 29196962Sjake** (As generated by the ANSI assert macro) 29296962Sjake** FICL_ROBUST == 1 --> stack checking in the outer interpreter 29396962Sjake** FICL_ROBUST == 2 also enables checking in many primitives 29496962Sjake*/ 29596962Sjake 29696962Sjake#if !defined FICL_ROBUST 29796962Sjake#define FICL_ROBUST 2 29896962Sjake#endif 29996962Sjake 30096962Sjake/* 30196962Sjake** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of 30296962Sjake** a new virtual machine's stacks, unless overridden at 30396962Sjake** create time. 30496962Sjake*/ 30596962Sjake#if !defined FICL_DEFAULT_STACK 30696962Sjake#define FICL_DEFAULT_STACK 128 30796962Sjake#endif 30896962Sjake 30996962Sjake/* 31096962Sjake** FICL_DEFAULT_DICT specifies the number of CELLs to allocate 31196962Sjake** for the system dictionary by default. The value 31296962Sjake** can be overridden at startup time as well. 31396962Sjake** FICL_DEFAULT_ENV specifies the number of cells to allot 31496962Sjake** for the environment-query dictionary. 31596962Sjake*/ 31696962Sjake#if !defined FICL_DEFAULT_DICT 31796962Sjake#define FICL_DEFAULT_DICT 12288 31896962Sjake#endif 31996962Sjake 32096962Sjake#if !defined FICL_DEFAULT_ENV 32196962Sjake#define FICL_DEFAULT_ENV 260 32296962Sjake#endif 32396962Sjake 32496962Sjake/* 32596962Sjake** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in 32696962Sjake** the dictionary search order. See Forth DPANS sec 16.3.3 32796962Sjake** (file://dpans16.htm#16.3.3) 32896962Sjake*/ 32996962Sjake#if !defined FICL_DEFAULT_VOCS 33096962Sjake#define FICL_DEFAULT_VOCS 16 33196962Sjake#endif 33296962Sjake 33396962Sjake/* 33496962Sjake** FICL_MAX_PARSE_STEPS controls the size of an array in the FICL_SYSTEM structure 33596962Sjake** that stores pointers to parser extension functions. I would never expect to have 33696962Sjake** more than 8 of these, so that's the default limit. Too many of these functions 33796962Sjake** will probably exact a nasty performance penalty. 33896962Sjake*/ 33996962Sjake#if !defined FICL_MAX_PARSE_STEPS 34096962Sjake#define FICL_MAX_PARSE_STEPS 8 34196962Sjake#endif 34296962Sjake 34396962Sjake/* 34496962Sjake** FICL_EXTENDED_PREFIX enables a bunch of extra prefixes in prefix.c and prefix.fr (if 34596962Sjake** included as part of softcore.c) 34696962Sjake*/ 34796962Sjake#if !defined FICL_EXTENDED_PREFIX 34896962Sjake#define FICL_EXTENDED_PREFIX 0 34996962Sjake#endif 35096962Sjake 35196962Sjake/* 35296962Sjake** FICL_ALIGN is the power of two to which the dictionary 35396962Sjake** pointer address must be aligned. This value is usually 35496962Sjake** either 1 or 2, depending on the memory architecture 35596962Sjake** of the target system; 2 is safe on any 16 or 32 bit 35696962Sjake** machine. 3 would be appropriate for a 64 bit machine. 35796962Sjake*/ 35896962Sjake#if !defined FICL_ALIGN 35996962Sjake#define FICL_ALIGN 3 36096962Sjake#define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1) 36196962Sjake#endif 36296962Sjake 36396962Sjake/* 36496962Sjake** System dependent routines -- 36596962Sjake** edit the implementations in sysdep.c to be compatible 36696962Sjake** with your runtime environment... 36796962Sjake** ficlTextOut sends a NULL terminated string to the 36896962Sjake** default output device - used for system error messages 36996962Sjake** ficlMalloc and ficlFree have the same semantics as malloc and free 37096962Sjake** in standard C 37196962Sjake** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned 37296962Sjake** product 37396962Sjake** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient 37496962Sjake** and remainder 37596962Sjake*/ 37696962Sjakestruct vm; 37796962Sjakevoid ficlTextOut(struct vm *pVM, char *msg, int fNewline); 37896962Sjakevoid *ficlMalloc (size_t size); 37996962Sjakevoid ficlFree (void *p); 38096962Sjakevoid *ficlRealloc(void *p, size_t size); 38196962Sjake/* 38296962Sjake** Stub function for dictionary access control - does nothing 38396962Sjake** by default, user can redefine to guarantee exclusive dict 38496962Sjake** access to a single thread for updates. All dict update code 38596962Sjake** must be bracketed as follows: 38696962Sjake** ficlLockDictionary(TRUE); 38796962Sjake** <code that updates dictionary> 38896962Sjake** ficlLockDictionary(FALSE); 38996962Sjake** 39096962Sjake** Returns zero if successful, nonzero if unable to acquire lock 39196962Sjake** before timeout (optional - could also block forever) 39296962Sjake** 39396962Sjake** NOTE: this function must be implemented with lock counting 39496962Sjake** semantics: nested calls must behave properly. 39596962Sjake*/ 39696962Sjake#if FICL_MULTITHREAD 39796962Sjakeint ficlLockDictionary(short fLock); 39896962Sjake#else 39996962Sjake#define ficlLockDictionary(x) 0 /* ignore */ 40096962Sjake#endif 40196962Sjake 40296962Sjake/* 40396962Sjake** 64 bit integer math support routines: multiply two UNS32s 40496962Sjake** to get a 64 bit product, & divide the product by an UNS32 40596962Sjake** to get an UNS32 quotient and remainder. Much easier in asm 40696962Sjake** on a 32 bit CPU than in C, which usually doesn't support 40796962Sjake** the double length result (but it should). 40896962Sjake*/ 40996962SjakeDPUNS ficlLongMul(FICL_UNS x, FICL_UNS y); 41096962SjakeUNSQR ficlLongDiv(DPUNS q, FICL_UNS y); 41196962Sjake 41296962Sjake#endif /*__SYSDEP_H__*/ 413