sysdep.h revision 249222
133965Sjdp/******************************************************************* 278828Sobrien s y s d e p . h 3130561Sobrien** Forth Inspired Command Language 438889Sjdp** Author: John Sadler (john_sadler@alum.mit.edu) 533965Sjdp** Created: 16 Oct 1997 6130561Sobrien** Ficl system dependent types and prototypes... 733965Sjdp** 8130561Sobrien** Note: Ficl also depends on the use of "assert" when 9130561Sobrien** FICL_ROBUST is enabled. This may require some consideration 10130561Sobrien** in firmware systems since assert often 11130561Sobrien** assumes stderr/stdout. 1233965Sjdp** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $ 13130561Sobrien*******************************************************************/ 14130561Sobrien/* 15130561Sobrien** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu) 16130561Sobrien** All rights reserved. 1733965Sjdp** 18130561Sobrien** Get the latest Ficl release at http://ficl.sourceforge.net 19130561Sobrien** 20130561Sobrien** L I C E N S E and D I S C L A I M E R 21130561Sobrien** 2233965Sjdp** Redistribution and use in source and binary forms, with or without 2333965Sjdp** modification, are permitted provided that the following conditions 2433965Sjdp** are met: 2533965Sjdp** 1. Redistributions of source code must retain the above copyright 2633965Sjdp** notice, this list of conditions and the following disclaimer. 2733965Sjdp** 2. Redistributions in binary form must reproduce the above copyright 2889857Sobrien** notice, this list of conditions and the following disclaimer in the 2933965Sjdp** documentation and/or other materials provided with the distribution. 3033965Sjdp** 3133965Sjdp** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 3233965Sjdp** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 3333965Sjdp** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 3433965Sjdp** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 3533965Sjdp** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36107492Sobrien** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3733965Sjdp** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3833965Sjdp** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3933965Sjdp** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 4033965Sjdp** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 4177298Sobrien** SUCH DAMAGE. 4233965Sjdp** 4338889Sjdp** I am interested in hearing from anyone who uses ficl. If you have 4438889Sjdp** a problem, a success story, a defect, an enhancement request, or 4538889Sjdp** if you would like to contribute to the ficl release, please send 4638889Sjdp** contact me by email at the address above. 4738889Sjdp** 4838889Sjdp** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $ 4938889Sjdp** $FreeBSD: head/sys/boot/ficl/arm/sysdep.h 249222 2013-04-07 05:40:49Z kientzle $ 5038889Sjdp*/ 5177298Sobrien 5233965Sjdp#if !defined (__SYSDEP_H__) 5333965Sjdp#define __SYSDEP_H__ 5433965Sjdp 5533965Sjdp#include <sys/types.h> 56130561Sobrien 57130561Sobrien#include <stddef.h> /* size_t, NULL */ 58130561Sobrien#include <setjmp.h> 5933965Sjdp#include <assert.h> 6033965Sjdp 6133965Sjdp#if !defined IGNORE /* Macro to silence unused param warnings */ 6233965Sjdp#define IGNORE(x) (void)(x) 6333965Sjdp#endif 6433965Sjdp 65130561Sobrien/* 66130561Sobrien** TRUE and FALSE for C boolean operations, and 67130561Sobrien** portable 32 bit types for CELLs 68130561Sobrien** 69130561Sobrien*/ 70130561Sobrien#if !defined TRUE 71130561Sobrien#define TRUE 1 72130561Sobrien#endif 73130561Sobrien#if !defined FALSE 74130561Sobrien#define FALSE 0 75130561Sobrien#endif 76130561Sobrien 77130561Sobrien 78130561Sobrien/* 79130561Sobrien** System dependent data type declarations... 80130561Sobrien*/ 81130561Sobrien#if !defined INT32 82130561Sobrien#define INT32 int 83130561Sobrien#endif 84130561Sobrien 85130561Sobrien#if !defined UNS32 86130561Sobrien#define UNS32 unsigned int 87130561Sobrien#endif 88130561Sobrien 89130561Sobrien#if !defined UNS16 90130561Sobrien#define UNS16 unsigned short 91130561Sobrien#endif 92130561Sobrien 93130561Sobrien#if !defined UNS8 94130561Sobrien#define UNS8 unsigned char 95130561Sobrien#endif 96130561Sobrien 97130561Sobrien#if !defined NULL 98130561Sobrien#define NULL ((void *)0) 99130561Sobrien#endif 100130561Sobrien 101130561Sobrien/* 102130561Sobrien** FICL_UNS and FICL_INT must have the same size as a void* on 103130561Sobrien** the target system. A CELL is a union of void*, FICL_UNS, and 104130561Sobrien** FICL_INT. 105130561Sobrien** (11/2000: same for FICL_FLOAT) 106130561Sobrien*/ 107130561Sobrien#if !defined FICL_INT 108130561Sobrien#define FICL_INT INT32 109130561Sobrien#endif 110130561Sobrien 111130561Sobrien#if !defined FICL_UNS 112130561Sobrien#define FICL_UNS UNS32 113130561Sobrien#endif 114130561Sobrien 115130561Sobrien#if !defined FICL_FLOAT 116130561Sobrien#define FICL_FLOAT float 117130561Sobrien#endif 118130561Sobrien 119130561Sobrien/* 120130561Sobrien** Ficl presently supports values of 32 and 64 for BITS_PER_CELL 121130561Sobrien*/ 122130561Sobrien#if !defined BITS_PER_CELL 123130561Sobrien#define BITS_PER_CELL 32 124130561Sobrien#endif 125130561Sobrien 126130561Sobrien#if ((BITS_PER_CELL != 32) && (BITS_PER_CELL != 64)) 127130561Sobrien Error! 128130561Sobrien#endif 129130561Sobrien 130130561Sobrientypedef struct 131130561Sobrien{ 132130561Sobrien FICL_UNS hi; 133130561Sobrien FICL_UNS lo; 134130561Sobrien} DPUNS; 135130561Sobrien 136130561Sobrientypedef struct 137130561Sobrien{ 138130561Sobrien FICL_UNS quot; 139130561Sobrien FICL_UNS rem; 140130561Sobrien} UNSQR; 141130561Sobrien 142130561Sobrientypedef struct 143130561Sobrien{ 144130561Sobrien FICL_INT hi; 145130561Sobrien FICL_INT lo; 146130561Sobrien} DPINT; 14733965Sjdp 14833965Sjdptypedef struct 14933965Sjdp{ 15033965Sjdp FICL_INT quot; 15133965Sjdp FICL_INT rem; 15233965Sjdp} INTQR; 15333965Sjdp 15433965Sjdp 15533965Sjdp/* 15633965Sjdp** B U I L D C O N T R O L S 15733965Sjdp*/ 15833965Sjdp 15933965Sjdp#if !defined (FICL_MINIMAL) 16033965Sjdp#define FICL_MINIMAL 0 16133965Sjdp#endif 16277298Sobrien#if (FICL_MINIMAL) 16377298Sobrien#define FICL_WANT_SOFTWORDS 0 16477298Sobrien#define FICL_WANT_FILE 0 16577298Sobrien#define FICL_WANT_FLOAT 0 16677298Sobrien#define FICL_WANT_USER 0 16777298Sobrien#define FICL_WANT_LOCALS 0 16877298Sobrien#define FICL_WANT_DEBUGGER 0 16977298Sobrien#define FICL_WANT_OOP 0 17077298Sobrien#define FICL_PLATFORM_EXTEND 0 17177298Sobrien#define FICL_MULTITHREAD 0 17277298Sobrien#define FICL_ROBUST 1 17377298Sobrien#define FICL_EXTENDED_PREFIX 0 17477298Sobrien#endif 17577298Sobrien 17677298Sobrien/* 17777298Sobrien** FICL_PLATFORM_EXTEND 17877298Sobrien** Includes words defined in ficlCompilePlatform 17977298Sobrien*/ 18033965Sjdp#if !defined (FICL_PLATFORM_EXTEND) 18133965Sjdp#define FICL_PLATFORM_EXTEND 1 18233965Sjdp#endif 18333965Sjdp 18433965Sjdp/* 18560484Sobrien** FICL_WANT_FILE 18633965Sjdp** Includes the FILE and FILE-EXT wordset and associated code. Turn this off if you do not 18733965Sjdp** have a filesystem! 18860484Sobrien** Contributed by Larry Hastings 18933965Sjdp*/ 19060484Sobrien#if !defined (FICL_WANT_FILE) 19133965Sjdp#define FICL_WANT_FILE 0 19260484Sobrien#endif 19333965Sjdp 19460484Sobrien/* 19533965Sjdp** FICL_WANT_FLOAT 19633965Sjdp** Includes a floating point stack for the VM, and words to do float operations. 19733965Sjdp** Contributed by Guy Carver 19860484Sobrien*/ 19933965Sjdp#if !defined (FICL_WANT_FLOAT) 20060484Sobrien#define FICL_WANT_FLOAT 0 20160484Sobrien#endif 20260484Sobrien 20360484Sobrien/* 20460484Sobrien** FICL_WANT_DEBUGGER 20533965Sjdp** Inludes a simple source level debugger 20660484Sobrien*/ 20733965Sjdp#if !defined (FICL_WANT_DEBUGGER) 20833965Sjdp#define FICL_WANT_DEBUGGER 1 20960484Sobrien#endif 21033965Sjdp 21160484Sobrien/* 21233965Sjdp** User variables: per-instance variables bound to the VM. 21360484Sobrien** Kinda like thread-local storage. Could be implemented in a 21433965Sjdp** VM private dictionary, but I've chosen the lower overhead 21533965Sjdp** approach of an array of CELLs instead. 21660484Sobrien*/ 21789857Sobrien#if !defined FICL_WANT_USER 21889857Sobrien#define FICL_WANT_USER 1 21933965Sjdp#endif 22060484Sobrien 22133965Sjdp#if !defined FICL_USER_CELLS 22260484Sobrien#define FICL_USER_CELLS 16 22333965Sjdp#endif 22460484Sobrien 22533965Sjdp/* 22660484Sobrien** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and 22733965Sjdp** a private dictionary for local variable compilation. 22860484Sobrien*/ 22933965Sjdp#if !defined FICL_WANT_LOCALS 23060484Sobrien#define FICL_WANT_LOCALS 1 23177298Sobrien#endif 232130561Sobrien 233130561Sobrien/* Max number of local variables per definition */ 23433965Sjdp#if !defined FICL_MAX_LOCALS 23577298Sobrien#define FICL_MAX_LOCALS 16 23633965Sjdp#endif 23760484Sobrien 23860484Sobrien/* 23960484Sobrien** FICL_WANT_OOP 24077298Sobrien** Inludes object oriented programming support (in softwords) 24177298Sobrien** OOP support requires locals and user variables! 242130561Sobrien*/ 243130561Sobrien#if !(FICL_WANT_LOCALS) || !(FICL_WANT_USER) 24433965Sjdp#if !defined (FICL_WANT_OOP) 24533965Sjdp#define FICL_WANT_OOP 0 24633965Sjdp#endif 24760484Sobrien#endif 24833965Sjdp 24933965Sjdp#if !defined (FICL_WANT_OOP) 25060484Sobrien#define FICL_WANT_OOP 1 25133965Sjdp#endif 25260484Sobrien 253130561Sobrien/* 254130561Sobrien** FICL_WANT_SOFTWORDS 255130561Sobrien** Controls inclusion of all softwords in softcore.c 256130561Sobrien*/ 25733965Sjdp#if !defined (FICL_WANT_SOFTWORDS) 25860484Sobrien#define FICL_WANT_SOFTWORDS 1 25933965Sjdp#endif 26060484Sobrien 26133965Sjdp/* 26260484Sobrien** FICL_MULTITHREAD enables dictionary mutual exclusion 26377298Sobrien** wia the ficlLockDictionary system dependent function. 26477298Sobrien** Note: this implementation is experimental and poorly 26560484Sobrien** tested. Further, it's unnecessary unless you really 26660484Sobrien** intend to have multiple SESSIONS (poor choice of name 26733965Sjdp** on my part) - that is, threads that modify the dictionary 26860484Sobrien** at the same time. 26933965Sjdp*/ 27060484Sobrien#if !defined FICL_MULTITHREAD 27133965Sjdp#define FICL_MULTITHREAD 0 27260484Sobrien#endif 27333965Sjdp 27489857Sobrien/* 27589857Sobrien** PORTABLE_LONGMULDIV causes ficlLongMul and ficlLongDiv to be 27689857Sobrien** defined in C in sysdep.c. Use this if you cannot easily 27733965Sjdp** generate an inline asm definition 27860484Sobrien*/ 27933965Sjdp#if !defined (PORTABLE_LONGMULDIV) 28060484Sobrien#define PORTABLE_LONGMULDIV 0 28133965Sjdp#endif 28260484Sobrien 28333965Sjdp/* 28460484Sobrien** INLINE_INNER_LOOP causes the inner interpreter to be inline code 285130561Sobrien** instead of a function call. This is mainly because MS VC++ 5 286130561Sobrien** chokes with an internal compiler error on the function version. 287130561Sobrien** in release mode. Sheesh. 288130561Sobrien*/ 28933965Sjdp#if !defined INLINE_INNER_LOOP 29060484Sobrien#if defined _DEBUG 29133965Sjdp#define INLINE_INNER_LOOP 0 29260484Sobrien#else 29333965Sjdp#define INLINE_INNER_LOOP 1 29433965Sjdp#endif 29533965Sjdp#endif 29633965Sjdp 29733965Sjdp/* 29860484Sobrien** FICL_ROBUST enables bounds checking of stacks and the dictionary. 29933965Sjdp** This will detect stack over and underflows and dictionary overflows. 30033965Sjdp** Any exceptional condition will result in an assertion failure. 30133965Sjdp** (As generated by the ANSI assert macro) 30233965Sjdp** FICL_ROBUST == 1 --> stack checking in the outer interpreter 30333965Sjdp** FICL_ROBUST == 2 also enables checking in many primitives 30433965Sjdp*/ 30533965Sjdp 30660484Sobrien#if !defined FICL_ROBUST 30760484Sobrien#define FICL_ROBUST 2 30860484Sobrien#endif 30960484Sobrien 31060484Sobrien/* 31160484Sobrien** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of 31233965Sjdp** a new virtual machine's stacks, unless overridden at 31360484Sobrien** create time. 31433965Sjdp*/ 31560484Sobrien#if !defined FICL_DEFAULT_STACK 31677298Sobrien#define FICL_DEFAULT_STACK 128 31777298Sobrien#endif 31833965Sjdp 31960484Sobrien/* 32060484Sobrien** FICL_DEFAULT_DICT specifies the number of CELLs to allocate 32160484Sobrien** for the system dictionary by default. The value 32233965Sjdp** can be overridden at startup time as well. 32360484Sobrien** FICL_DEFAULT_ENV specifies the number of cells to allot 32460484Sobrien** for the environment-query dictionary. 32560484Sobrien*/ 32660484Sobrien#if !defined FICL_DEFAULT_DICT 32760484Sobrien#define FICL_DEFAULT_DICT 12288 32860484Sobrien#endif 32960484Sobrien 33033965Sjdp#if !defined FICL_DEFAULT_ENV 33160484Sobrien#define FICL_DEFAULT_ENV 260 33260484Sobrien#endif 33360484Sobrien 33433965Sjdp/* 33560484Sobrien** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in 33689857Sobrien** the dictionary search order. See Forth DPANS sec 16.3.3 33789857Sobrien** (file://dpans16.htm#16.3.3) 33860484Sobrien*/ 33960484Sobrien#if !defined FICL_DEFAULT_VOCS 34033965Sjdp#define FICL_DEFAULT_VOCS 16 34160484Sobrien#endif 34260484Sobrien 343130561Sobrien/* 34477298Sobrien** FICL_MAX_PARSE_STEPS controls the size of an array in the FICL_SYSTEM structure 345130561Sobrien** that stores pointers to parser extension functions. I would never expect to have 346130561Sobrien** more than 8 of these, so that's the default limit. Too many of these functions 347130561Sobrien** will probably exact a nasty performance penalty. 348104834Sobrien*/ 349104834Sobrien#if !defined FICL_MAX_PARSE_STEPS 350104834Sobrien#define FICL_MAX_PARSE_STEPS 8 351104834Sobrien#endif 35238889Sjdp 35360484Sobrien/* 35433965Sjdp** FICL_EXTENDED_PREFIX enables a bunch of extra prefixes in prefix.c and prefix.fr (if 35560484Sobrien** included as part of softcore.c) 35633965Sjdp*/ 35760484Sobrien#if !defined FICL_EXTENDED_PREFIX 35833965Sjdp#define FICL_EXTENDED_PREFIX 0 35933965Sjdp#endif 36089857Sobrien 36189857Sobrien/* 36233965Sjdp** FICL_ALIGN is the power of two to which the dictionary 36377298Sobrien** pointer address must be aligned. This value is usually 36433965Sjdp** either 1 or 2, depending on the memory architecture 36560484Sobrien** of the target system; 2 is safe on any 16 or 32 bit 36633965Sjdp** machine. 3 would be appropriate for a 64 bit machine. 36760484Sobrien*/ 36833965Sjdp#if !defined FICL_ALIGN 36933965Sjdp#define FICL_ALIGN 2 37060484Sobrien#define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1) 37133965Sjdp#endif 37260484Sobrien 37333965Sjdp/* 37460484Sobrien** System dependent routines -- 37533965Sjdp** edit the implementations in sysdep.c to be compatible 37660484Sobrien** with your runtime environment... 37733965Sjdp** ficlTextOut sends a NULL terminated string to the 37833965Sjdp** default output device - used for system error messages 379130561Sobrien** ficlMalloc and ficlFree have the same semantics as malloc and free 380130561Sobrien** in standard C 381130561Sobrien** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned 382130561Sobrien** product 38333965Sjdp** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient 38460484Sobrien** and remainder 38533965Sjdp*/ 38633965Sjdpstruct vm; 38789857Sobrienvoid ficlTextOut(struct vm *pVM, char *msg, int fNewline); 38889857Sobrienvoid *ficlMalloc (size_t size); 38977298Sobrienvoid ficlFree (void *p); 39077298Sobrienvoid *ficlRealloc(void *p, size_t size); 39177298Sobrien/* 39277298Sobrien** Stub function for dictionary access control - does nothing 39333965Sjdp** by default, user can redefine to guarantee exclusive dict 39460484Sobrien** access to a single thread for updates. All dict update code 39577298Sobrien** must be bracketed as follows: 39677298Sobrien** ficlLockDictionary(TRUE); 39738889Sjdp** <code that updates dictionary> 39860484Sobrien** ficlLockDictionary(FALSE); 39933965Sjdp** 40060484Sobrien** Returns zero if successful, nonzero if unable to acquire lock 40177298Sobrien** before timeout (optional - could also block forever) 40277298Sobrien** 40333965Sjdp** NOTE: this function must be implemented with lock counting 40460484Sobrien** semantics: nested calls must behave properly. 40533965Sjdp*/ 40660484Sobrien#if FICL_MULTITHREAD 40733965Sjdpint ficlLockDictionary(short fLock); 40860484Sobrien#else 409130561Sobrien#define ficlLockDictionary(x) /* ignore */ 410130561Sobrien#endif 411130561Sobrien 41233965Sjdp/* 41360484Sobrien** 64 bit integer math support routines: multiply two UNS32s 41433965Sjdp** to get a 64 bit product, & divide the product by an UNS32 41533965Sjdp** to get an UNS32 quotient and remainder. Much easier in asm 41633965Sjdp** on a 32 bit CPU than in C, which usually doesn't support 41760484Sobrien** the double length result (but it should). 41860484Sobrien*/ 41960484SobrienDPUNS ficlLongMul(FICL_UNS x, FICL_UNS y); 42060484SobrienUNSQR ficlLongDiv(DPUNS q, FICL_UNS y); 42160484Sobrien 42233965Sjdp/* 42360484Sobrien** FICL_HAVE_FTRUNCATE indicates whether the current OS supports 42433965Sjdp** the ftruncate() function (available on most UNIXes). This 42560484Sobrien** function is necessary to provide the complete File-Access wordset. 42633965Sjdp*/ 42733965Sjdp#if !defined (FICL_HAVE_FTRUNCATE) 42860484Sobrien#define FICL_HAVE_FTRUNCATE 0 42933965Sjdp#endif 43060484Sobrien 43133965Sjdp 43260484Sobrien#endif /*__SYSDEP_H__*/ 43333965Sjdp