sysdep.h revision 96755
1167514Skmacy/******************************************************************* 2167514Skmacy s y s d e p . h 3177340Skmacy** Forth Inspired Command Language 4167514Skmacy** Author: John Sadler (john_sadler@alum.mit.edu) 5167514Skmacy** Created: 16 Oct 1997 6167514Skmacy** Ficl system dependent types and prototypes... 7167514Skmacy** 8167514Skmacy** Note: Ficl also depends on the use of "assert" when 9167514Skmacy** FICL_ROBUST is enabled. This may require some consideration 10167514Skmacy** in firmware systems since assert often 11167514Skmacy** assumes stderr/stdout. 12170076Skmacy** $Id: sysdep.h,v 1.11 2001/12/05 07:21:34 jsadler Exp $ 13167514Skmacy*******************************************************************/ 14167514Skmacy/* 15167514Skmacy** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu) 16167514Skmacy** All rights reserved. 17167514Skmacy** 18167514Skmacy** Get the latest Ficl release at http://ficl.sourceforge.net 19167514Skmacy** 20167514Skmacy** I am interested in hearing from anyone who uses ficl. If you have 21167514Skmacy** a problem, a success story, a defect, an enhancement request, or 22167514Skmacy** if you would like to contribute to the ficl release, please 23167514Skmacy** contact me by email at the address above. 24167514Skmacy** 25167514Skmacy** L I C E N S E and D I S C L A I M E R 26167514Skmacy** 27167514Skmacy** Redistribution and use in source and binary forms, with or without 28167514Skmacy** modification, are permitted provided that the following conditions 29167514Skmacy** are met: 30167514Skmacy** 1. Redistributions of source code must retain the above copyright 31167514Skmacy** notice, this list of conditions and the following disclaimer. 32167514Skmacy** 2. Redistributions in binary form must reproduce the above copyright 33170076Skmacy** notice, this list of conditions and the following disclaimer in the 34167514Skmacy** documentation and/or other materials provided with the distribution. 35176472Skmacy** 36176472Skmacy** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 37176472Skmacy** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 38167514Skmacy** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 39181614Skmacy** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 40181614Skmacy** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 41181614Skmacy** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 42181614Skmacy** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 43181614Skmacy** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 44181614Skmacy** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 45181614Skmacy** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 46167514Skmacy** SUCH DAMAGE. 47167514Skmacy** 48167514Skmacy** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $ 49167514Skmacy*/ 50167514Skmacy 51167514Skmacy/* $FreeBSD: head/sys/boot/ficl/ia64/sysdep.h 96755 2002-05-16 21:28:32Z trhodes $ */ 52180583Skmacy 53181614Skmacy#if !defined (__SYSDEP_H__) 54181614Skmacy#define __SYSDEP_H__ 55181614Skmacy 56181614Skmacy#include <sys/types.h> 57181614Skmacy 58180583Skmacy#include <stddef.h> /* size_t, NULL */ 59167514Skmacy#include <setjmp.h> 60181614Skmacy#include <assert.h> 61181614Skmacy 62181614Skmacy#if !defined IGNORE /* Macro to silence unused param warnings */ 63181614Skmacy#define IGNORE(x) &x 64181614Skmacy#endif 65181614Skmacy 66181614Skmacy/* 67180583Skmacy** TRUE and FALSE for C boolean operations, and 68180583Skmacy** portable 32 bit types for CELLs 69180583Skmacy** 70180583Skmacy*/ 71180583Skmacy#if !defined TRUE 72167514Skmacy#define TRUE 1 73167514Skmacy#endif 74186282Sgnn#if !defined FALSE 75186282Sgnn#define FALSE 0 76186282Sgnn#endif 77186282Sgnn 78186282Sgnn/* 79186282Sgnn** System dependent data type declarations... 80186282Sgnn*/ 81186282Sgnn#if !defined INT32 82186282Sgnn#define INT32 int 83186282Sgnn#endif 84186282Sgnn 85186282Sgnn#if !defined UNS32 86186282Sgnn#define UNS32 unsigned int 87186282Sgnn#endif 88186282Sgnn 89186282Sgnn#if !defined UNS16 90186282Sgnn#define UNS16 unsigned short 91186282Sgnn#endif 92186282Sgnn 93186282Sgnn#if !defined UNS8 94186282Sgnn#define UNS8 unsigned char 95186282Sgnn#endif 96186282Sgnn 97186282Sgnn#if !defined NULL 98186282Sgnn#define NULL ((void *)0) 99186282Sgnn#endif 100186282Sgnn 101186282Sgnn/* 102186282Sgnn** FICL_UNS and FICL_INT must have the same size as a void* on 103186282Sgnn** the target system. A CELL is a union of void*, FICL_UNS, and 104186282Sgnn** FICL_INT. 105186282Sgnn** (11/2000: same for FICL_FLOAT) 106186282Sgnn*/ 107186282Sgnn#if !defined FICL_INT 108186282Sgnn#define FICL_INT long 109186282Sgnn#endif 110186282Sgnn 111186282Sgnn#if !defined FICL_UNS 112186282Sgnn#define FICL_UNS unsigned long 113186282Sgnn#endif 114186282Sgnn 115186282Sgnn#if !defined FICL_FLOAT 116186282Sgnn#define FICL_FLOAT float 117186282Sgnn#endif 118186282Sgnn 119186282Sgnn/* 120186282Sgnn** Ficl presently supports values of 32 and 64 for BITS_PER_CELL 121186282Sgnn*/ 122186282Sgnn#if !defined BITS_PER_CELL 123186282Sgnn#define BITS_PER_CELL 64 124186282Sgnn#endif 125186282Sgnn 126186282Sgnn#if ((BITS_PER_CELL != 32) && (BITS_PER_CELL != 64)) 127186282Sgnn Error! 128186282Sgnn#endif 129186282Sgnn 130186282Sgnntypedef struct 131186282Sgnn{ 132186282Sgnn FICL_UNS hi; 133186282Sgnn FICL_UNS lo; 134186282Sgnn} DPUNS; 135186282Sgnn 136186282Sgnntypedef struct 137186282Sgnn{ 138186282Sgnn FICL_UNS quot; 139186282Sgnn FICL_UNS rem; 140186282Sgnn} UNSQR; 141186282Sgnn 142180583Skmacytypedef struct 143180583Skmacy{ 144180583Skmacy FICL_INT hi; 145180583Skmacy FICL_INT lo; 146180583Skmacy} DPINT; 147180583Skmacy 148180583Skmacytypedef struct 149180583Skmacy{ 150180583Skmacy FICL_INT quot; 151180583Skmacy FICL_INT rem; 152180583Skmacy} INTQR; 153180583Skmacy 154180583Skmacy 155180583Skmacy/* 156180583Skmacy** B U I L D C O N T R O L S 157180583Skmacy*/ 158167514Skmacy 159167514Skmacy#if !defined (FICL_MINIMAL) 160167514Skmacy#define FICL_MINIMAL 0 161167514Skmacy#endif 162176472Skmacy#if (FICL_MINIMAL) 163167514Skmacy#define FICL_WANT_SOFTWORDS 0 164176472Skmacy#define FICL_WANT_FILE 0 165167514Skmacy#define FICL_WANT_FLOAT 0 166167514Skmacy#define FICL_WANT_USER 0 167167514Skmacy#define FICL_WANT_LOCALS 0 168167514Skmacy#define FICL_WANT_DEBUGGER 0 169167514Skmacy#define FICL_WANT_OOP 0 170167514Skmacy#define FICL_PLATFORM_EXTEND 0 171167514Skmacy#define FICL_MULTITHREAD 0 172167514Skmacy#define FICL_ROBUST 0 173167514Skmacy#define FICL_EXTENDED_PREFIX 0 174167514Skmacy#endif 175167514Skmacy 176167514Skmacy/* 177167514Skmacy** FICL_PLATFORM_EXTEND 178186282Sgnn** Includes words defined in ficlCompilePlatform 179186282Sgnn*/ 180186282Sgnn#if !defined (FICL_PLATFORM_EXTEND) 181186282Sgnn#define FICL_PLATFORM_EXTEND 1 182186282Sgnn#endif 183186282Sgnn 184186282Sgnn 185186282Sgnn/* 186186282Sgnn** FICL_WANT_FILE 187186282Sgnn** Includes the FILE and FILE-EXT wordset and associated code. Turn this off if you do not 188186282Sgnn** have a filesystem! 189186282Sgnn** Contributed by Larry Hastings 190167514Skmacy*/ 191167514Skmacy#if !defined (FICL_WANT_FILE) 192167514Skmacy#define FICL_WANT_FILE 0 193167514Skmacy#endif 194167514Skmacy 195167514Skmacy/* 196167514Skmacy** FICL_WANT_FLOAT 197167514Skmacy** Includes a floating point stack for the VM, and words to do float operations. 198167514Skmacy** Contributed by Guy Carver 199167514Skmacy*/ 200167514Skmacy#if !defined (FICL_WANT_FLOAT) 201167514Skmacy#define FICL_WANT_FLOAT 0 202186282Sgnn#endif 203186282Sgnn 204186282Sgnn/* 205186282Sgnn** FICL_WANT_DEBUGGER 206186282Sgnn** Inludes a simple source level debugger 207167514Skmacy*/ 208167514Skmacy#if !defined (FICL_WANT_DEBUGGER) 209167514Skmacy#define FICL_WANT_DEBUGGER 1 210167514Skmacy#endif 211167514Skmacy 212167514Skmacy/* 213167514Skmacy** FICL_EXTENDED_PREFIX enables a bunch of extra prefixes in prefix.c and prefix.fr (if 214167514Skmacy** included as part of softcore.c) 215181614Skmacy*/ 216181614Skmacy#if !defined FICL_EXTENDED_PREFIX 217181614Skmacy#define FICL_EXTENDED_PREFIX 0 218181614Skmacy#endif 219181614Skmacy 220167514Skmacy/* 221167514Skmacy** User variables: per-instance variables bound to the VM. 222181614Skmacy** Kinda like thread-local storage. Could be implemented in a 223181614Skmacy** VM private dictionary, but I've chosen the lower overhead 224167514Skmacy** approach of an array of CELLs instead. 225181614Skmacy*/ 226181614Skmacy#if !defined FICL_WANT_USER 227181614Skmacy#define FICL_WANT_USER 1 228181614Skmacy#endif 229167514Skmacy 230167514Skmacy#if !defined FICL_USER_CELLS 231181614Skmacy#define FICL_USER_CELLS 16 232167514Skmacy#endif 233167514Skmacy 234167514Skmacy/* 235167514Skmacy** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and 236167514Skmacy** a private dictionary for local variable compilation. 237167514Skmacy*/ 238167514Skmacy#if !defined FICL_WANT_LOCALS 239167514Skmacy#define FICL_WANT_LOCALS 1 240167514Skmacy#endif 241167514Skmacy 242167514Skmacy/* Max number of local variables per definition */ 243167514Skmacy#if !defined FICL_MAX_LOCALS 244167514Skmacy#define FICL_MAX_LOCALS 16 245167514Skmacy#endif 246167514Skmacy 247167514Skmacy/* 248167514Skmacy** FICL_WANT_OOP 249167514Skmacy** Inludes object oriented programming support (in softwords) 250167514Skmacy** OOP support requires locals and user variables! 251167514Skmacy*/ 252181614Skmacy#if !(FICL_WANT_LOCALS) || !(FICL_WANT_USER) 253167514Skmacy#if !defined (FICL_WANT_OOP) 254167514Skmacy#define FICL_WANT_OOP 0 255167514Skmacy#endif 256167514Skmacy#endif 257167514Skmacy 258167514Skmacy#if !defined (FICL_WANT_OOP) 259167514Skmacy#define FICL_WANT_OOP 1 260167514Skmacy#endif 261167514Skmacy 262181614Skmacy/* 263167514Skmacy** FICL_WANT_SOFTWORDS 264167514Skmacy** Controls inclusion of all softwords in softcore.c 265167514Skmacy*/ 266167514Skmacy#if !defined (FICL_WANT_SOFTWORDS) 267176472Skmacy#define FICL_WANT_SOFTWORDS 1 268176472Skmacy#endif 269167514Skmacy 270186282Sgnn/* 271186282Sgnn** FICL_MULTITHREAD enables dictionary mutual exclusion 272176472Skmacy** wia the ficlLockDictionary system dependent function. 273176472Skmacy** Note: this implementation is experimental and poorly 274177340Skmacy** tested. Further, it's unnecessary unless you really 275167514Skmacy** intend to have multiple SESSIONS (poor choice of name 276186282Sgnn** on my part) - that is, threads that modify the dictionary 277186282Sgnn** at the same time. 278186282Sgnn*/ 279186282Sgnn#if !defined FICL_MULTITHREAD 280186282Sgnn#define FICL_MULTITHREAD 0 281176472Skmacy#endif 282167514Skmacy 283167514Skmacy/* 284167514Skmacy** PORTABLE_LONGMULDIV causes ficlLongMul and ficlLongDiv to be 285167514Skmacy** defined in C in sysdep.c. Use this if you cannot easily 286185157Sgnn** generate an inline asm definition 287185157Sgnn*/ 288185157Sgnn#if !defined (PORTABLE_LONGMULDIV) 289185157Sgnn#define PORTABLE_LONGMULDIV 0 290185157Sgnn#endif 291185157Sgnn 292185157Sgnn/* 293185157Sgnn** INLINE_INNER_LOOP causes the inner interpreter to be inline code 294185157Sgnn** instead of a function call. This is mainly because MS VC++ 5 295185157Sgnn** chokes with an internal compiler error on the function version. 296185157Sgnn** in release mode. Sheesh. 297185157Sgnn*/ 298185157Sgnn#if !defined INLINE_INNER_LOOP 299185157Sgnn#if defined _DEBUG 300185620Sgnn#define INLINE_INNER_LOOP 0 301185620Sgnn#else 302185620Sgnn#define INLINE_INNER_LOOP 1 303185620Sgnn#endif 304185620Sgnn#endif 305185620Sgnn 306185620Sgnn/* 307185620Sgnn** FICL_ROBUST enables bounds checking of stacks and the dictionary. 308185620Sgnn** This will detect stack over and underflows and dictionary overflows. 309185620Sgnn** Any exceptional condition will result in an assertion failure. 310185157Sgnn** (As generated by the ANSI assert macro) 311167514Skmacy** FICL_ROBUST == 1 --> stack checking in the outer interpreter 312167514Skmacy** FICL_ROBUST == 2 also enables checking in many primitives 313167514Skmacy*/ 314167514Skmacy 315167514Skmacy#if !defined FICL_ROBUST 316167514Skmacy#define FICL_ROBUST 2 317167514Skmacy#endif 318167514Skmacy 319167514Skmacy/* 320167514Skmacy** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of 321167514Skmacy** a new virtual machine's stacks, unless overridden at 322180583Skmacy** create time. 323180583Skmacy*/ 324180583Skmacy#if !defined FICL_DEFAULT_STACK 325180583Skmacy#define FICL_DEFAULT_STACK 128 326167514Skmacy#endif 327167514Skmacy 328167514Skmacy/* 329167514Skmacy** FICL_DEFAULT_DICT specifies the number of CELLs to allocate 330167514Skmacy** for the system dictionary by default. The value 331181614Skmacy** can be overridden at startup time as well. 332167514Skmacy** FICL_DEFAULT_ENV specifies the number of cells to allot 333167514Skmacy** for the environment-query dictionary. 334167514Skmacy*/ 335167514Skmacy#if !defined FICL_DEFAULT_DICT 336167514Skmacy#define FICL_DEFAULT_DICT 12288 337180583Skmacy#endif 338180583Skmacy 339180583Skmacy#if !defined FICL_DEFAULT_ENV 340180583Skmacy#define FICL_DEFAULT_ENV 260 341181614Skmacy#endif 342167514Skmacy 343167514Skmacy/* 344167514Skmacy** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in 345167514Skmacy** the dictionary search order. See Forth DPANS sec 16.3.3 346176472Skmacy** (file://dpans16.htm#16.3.3) 347176472Skmacy*/ 348167514Skmacy#if !defined FICL_DEFAULT_VOCS 349176472Skmacy#define FICL_DEFAULT_VOCS 16 350176472Skmacy#endif 351176472Skmacy 352167514Skmacy/* 353176472Skmacy** FICL_MAX_PARSE_STEPS controls the size of an array in the FICL_SYSTEM structure 354167514Skmacy** that stores pointers to parser extension functions. I would never expect to have 355167514Skmacy** more than 8 of these, so that's the default limit. Too many of these functions 356180583Skmacy** will probably exact a nasty performance penalty. 357180583Skmacy*/ 358181614Skmacy#if !defined FICL_MAX_PARSE_STEPS 359181614Skmacy#define FICL_MAX_PARSE_STEPS 8 360181614Skmacy#endif 361181614Skmacy 362181614Skmacy/* 363181614Skmacy** FICL_ALIGN is the power of two to which the dictionary 364180583Skmacy** pointer address must be aligned. This value is usually 365180583Skmacy** either 1 or 2, depending on the memory architecture 366180583Skmacy** of the target system; 2 is safe on any 16 or 32 bit 367180583Skmacy** machine. 3 would be appropriate for a 64 bit machine. 368180583Skmacy*/ 369180583Skmacy#if !defined FICL_ALIGN 370180583Skmacy#define FICL_ALIGN 3 371180583Skmacy#define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1) 372180583Skmacy#endif 373180583Skmacy 374180583Skmacy/* 375180583Skmacy** System dependent routines -- 376180583Skmacy** edit the implementations in sysdep.c to be compatible 377180583Skmacy** with your runtime environment... 378180583Skmacy** ficlTextOut sends a NULL terminated string to the 379180583Skmacy** default output device - used for system error messages 380180583Skmacy** ficlMalloc and ficlFree have the same semantics as malloc and free 381180583Skmacy** in standard C 382180583Skmacy** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned 383180583Skmacy** product 384180583Skmacy** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient 385180583Skmacy** and remainder 386180583Skmacy*/ 387180583Skmacystruct vm; 388180583Skmacyvoid ficlTextOut(struct vm *pVM, char *msg, int fNewline); 389180583Skmacyvoid *ficlMalloc (size_t size); 390180583Skmacyvoid ficlFree (void *p); 391180583Skmacyvoid *ficlRealloc(void *p, size_t size); 392180583Skmacy/* 393180583Skmacy** Stub function for dictionary access control - does nothing 394180583Skmacy** by default, user can redefine to guarantee exclusive dict 395180583Skmacy** access to a single thread for updates. All dict update code 396180583Skmacy** must be bracketed as follows: 397180583Skmacy** ficlLockDictionary(TRUE); 398180583Skmacy** <code that updates dictionary> 399180583Skmacy** ficlLockDictionary(FALSE); 400180583Skmacy** 401180583Skmacy** Returns zero if successful, nonzero if unable to acquire lock 402180583Skmacy** before timeout (optional - could also block forever) 403180583Skmacy** 404180583Skmacy** NOTE: this function must be implemented with lock counting 405180583Skmacy** semantics: nested calls must behave properly. 406180583Skmacy*/ 407180583Skmacy#if FICL_MULTITHREAD 408180583Skmacyint ficlLockDictionary(short fLock); 409180583Skmacy#else 410180583Skmacy#define ficlLockDictionary(x) 0 /* ignore */ 411180583Skmacy#endif 412180583Skmacy 413180583Skmacy/* 414180583Skmacy** 64 bit integer math support routines: multiply two UNS32s 415180583Skmacy** to get a 64 bit product, & divide the product by an UNS32 416180583Skmacy** to get an UNS32 quotient and remainder. Much easier in asm 417180583Skmacy** on a 32 bit CPU than in C, which usually doesn't support 418180583Skmacy** the double length result (but it should). 419180583Skmacy*/ 420180583SkmacyDPUNS ficlLongMul(FICL_UNS x, FICL_UNS y); 421180583SkmacyUNSQR ficlLongDiv(DPUNS q, FICL_UNS y); 422180583Skmacy 423180583Skmacy 424180583Skmacy/* 425180583Skmacy** FICL_HAVE_FTRUNCATE indicates whether the current OS supports 426180583Skmacy** the ftruncate() function (available on most UNIXes). This 427180583Skmacy** function is necessary to provide the complete File-Access wordset. 428180583Skmacy*/ 429180583Skmacy#if !defined (FICL_HAVE_FTRUNCATE) 430180583Skmacy#define FICL_HAVE_FTRUNCATE 0 431180583Skmacy#endif 432180583Skmacy 433180583Skmacy 434180583Skmacy#endif /*__SYSDEP_H__*/ 435180583Skmacy