1266986Smarkj/******************************************************************* 2266986Smarkj s y s d e p . h 3266986Smarkj** Forth Inspired Command Language 4266986Smarkj** Author: John Sadler (john_sadler@alum.mit.edu) 5266986Smarkj** Created: 16 Oct 1997 6266986Smarkj** Ficl system dependent types and prototypes... 7266986Smarkj** 8266986Smarkj** Note: Ficl also depends on the use of "assert" when 9266986Smarkj** FICL_ROBUST is enabled. This may require some consideration 10266986Smarkj** in firmware systems since assert often 11266986Smarkj** assumes stderr/stdout. 12266986Smarkj** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $ 13266986Smarkj*******************************************************************/ 14266986Smarkj/* 15266986Smarkj** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu) 16266986Smarkj** All rights reserved. 17266986Smarkj** 18266986Smarkj** Get the latest Ficl release at http://ficl.sourceforge.net 19266986Smarkj** 20266986Smarkj** L I C E N S E and D I S C L A I M E R 21266986Smarkj** 22266986Smarkj** Redistribution and use in source and binary forms, with or without 23266986Smarkj** modification, are permitted provided that the following conditions 24266986Smarkj** are met: 25266986Smarkj** 1. Redistributions of source code must retain the above copyright 26266986Smarkj** notice, this list of conditions and the following disclaimer. 27266986Smarkj** 2. Redistributions in binary form must reproduce the above copyright 28266986Smarkj** notice, this list of conditions and the following disclaimer in the 29266986Smarkj** documentation and/or other materials provided with the distribution. 30266986Smarkj** 31266986Smarkj** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 32266986Smarkj** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33266986Smarkj** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34266986Smarkj** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 35266986Smarkj** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36266986Smarkj** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37266986Smarkj** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38266986Smarkj** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 39266986Smarkj** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 40266986Smarkj** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 41266986Smarkj** SUCH DAMAGE. 42266986Smarkj** 43266986Smarkj** I am interested in hearing from anyone who uses ficl. If you have 44266986Smarkj** a problem, a success story, a defect, an enhancement request, or 45266986Smarkj** if you would like to contribute to the ficl release, please send 46266986Smarkj** contact me by email at the address above. 47266986Smarkj** 48266986Smarkj** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $ 49266986Smarkj** $FreeBSD: releng/10.3/sys/boot/ficl/arm/sysdep.h 249222 2013-04-07 05:40:49Z kientzle $ 50266986Smarkj*/ 51266986Smarkj 52266986Smarkj#if !defined (__SYSDEP_H__) 53266986Smarkj#define __SYSDEP_H__ 54266986Smarkj 55266986Smarkj#include <sys/types.h> 56266986Smarkj 57266986Smarkj#include <stddef.h> /* size_t, NULL */ 58266986Smarkj#include <setjmp.h> 59266986Smarkj#include <assert.h> 60266986Smarkj 61266986Smarkj#if !defined IGNORE /* Macro to silence unused param warnings */ 62266986Smarkj#define IGNORE(x) (void)(x) 63266986Smarkj#endif 64266986Smarkj 65266986Smarkj/* 66266986Smarkj** TRUE and FALSE for C boolean operations, and 67266986Smarkj** portable 32 bit types for CELLs 68266986Smarkj** 69266986Smarkj*/ 70266986Smarkj#if !defined TRUE 71266986Smarkj#define TRUE 1 72266986Smarkj#endif 73266986Smarkj#if !defined FALSE 74266986Smarkj#define FALSE 0 75266986Smarkj#endif 76266986Smarkj 77266986Smarkj 78266986Smarkj/* 79266986Smarkj** System dependent data type declarations... 80266986Smarkj*/ 81266986Smarkj#if !defined INT32 82266986Smarkj#define INT32 int 83266986Smarkj#endif 84266986Smarkj 85266986Smarkj#if !defined UNS32 86266986Smarkj#define UNS32 unsigned int 87266986Smarkj#endif 88266986Smarkj 89266986Smarkj#if !defined UNS16 90266986Smarkj#define UNS16 unsigned short 91266986Smarkj#endif 92266986Smarkj 93266986Smarkj#if !defined UNS8 94266986Smarkj#define UNS8 unsigned char 95266986Smarkj#endif 96266986Smarkj 97266986Smarkj#if !defined NULL 98266986Smarkj#define NULL ((void *)0) 99266986Smarkj#endif 100266986Smarkj 101266986Smarkj/* 102266986Smarkj** FICL_UNS and FICL_INT must have the same size as a void* on 103266986Smarkj** the target system. A CELL is a union of void*, FICL_UNS, and 104266986Smarkj** FICL_INT. 105266986Smarkj** (11/2000: same for FICL_FLOAT) 106266986Smarkj*/ 107266986Smarkj#if !defined FICL_INT 108266986Smarkj#define FICL_INT INT32 109266986Smarkj#endif 110266986Smarkj 111266986Smarkj#if !defined FICL_UNS 112266986Smarkj#define FICL_UNS UNS32 113266986Smarkj#endif 114266986Smarkj 115266986Smarkj#if !defined FICL_FLOAT 116266986Smarkj#define FICL_FLOAT float 117266986Smarkj#endif 118266986Smarkj 119266986Smarkj/* 120266986Smarkj** Ficl presently supports values of 32 and 64 for BITS_PER_CELL 121266986Smarkj*/ 122266986Smarkj#if !defined BITS_PER_CELL 123266986Smarkj#define BITS_PER_CELL 32 124266986Smarkj#endif 125266986Smarkj 126266986Smarkj#if ((BITS_PER_CELL != 32) && (BITS_PER_CELL != 64)) 127266986Smarkj Error! 128266986Smarkj#endif 129266986Smarkj 130266986Smarkjtypedef struct 131266986Smarkj{ 132266986Smarkj FICL_UNS hi; 133266986Smarkj FICL_UNS lo; 134266986Smarkj} DPUNS; 135266986Smarkj 136266986Smarkjtypedef struct 137266986Smarkj{ 138266986Smarkj FICL_UNS quot; 139 FICL_UNS rem; 140} UNSQR; 141 142typedef struct 143{ 144 FICL_INT hi; 145 FICL_INT lo; 146} DPINT; 147 148typedef struct 149{ 150 FICL_INT quot; 151 FICL_INT rem; 152} INTQR; 153 154 155/* 156** B U I L D C O N T R O L S 157*/ 158 159#if !defined (FICL_MINIMAL) 160#define FICL_MINIMAL 0 161#endif 162#if (FICL_MINIMAL) 163#define FICL_WANT_SOFTWORDS 0 164#define FICL_WANT_FILE 0 165#define FICL_WANT_FLOAT 0 166#define FICL_WANT_USER 0 167#define FICL_WANT_LOCALS 0 168#define FICL_WANT_DEBUGGER 0 169#define FICL_WANT_OOP 0 170#define FICL_PLATFORM_EXTEND 0 171#define FICL_MULTITHREAD 0 172#define FICL_ROBUST 1 173#define FICL_EXTENDED_PREFIX 0 174#endif 175 176/* 177** FICL_PLATFORM_EXTEND 178** Includes words defined in ficlCompilePlatform 179*/ 180#if !defined (FICL_PLATFORM_EXTEND) 181#define FICL_PLATFORM_EXTEND 1 182#endif 183 184/* 185** FICL_WANT_FILE 186** Includes the FILE and FILE-EXT wordset and associated code. Turn this off if you do not 187** have a filesystem! 188** Contributed by Larry Hastings 189*/ 190#if !defined (FICL_WANT_FILE) 191#define FICL_WANT_FILE 0 192#endif 193 194/* 195** FICL_WANT_FLOAT 196** Includes a floating point stack for the VM, and words to do float operations. 197** Contributed by Guy Carver 198*/ 199#if !defined (FICL_WANT_FLOAT) 200#define FICL_WANT_FLOAT 0 201#endif 202 203/* 204** FICL_WANT_DEBUGGER 205** Inludes a simple source level debugger 206*/ 207#if !defined (FICL_WANT_DEBUGGER) 208#define FICL_WANT_DEBUGGER 1 209#endif 210 211/* 212** User variables: per-instance variables bound to the VM. 213** Kinda like thread-local storage. Could be implemented in a 214** VM private dictionary, but I've chosen the lower overhead 215** approach of an array of CELLs instead. 216*/ 217#if !defined FICL_WANT_USER 218#define FICL_WANT_USER 1 219#endif 220 221#if !defined FICL_USER_CELLS 222#define FICL_USER_CELLS 16 223#endif 224 225/* 226** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and 227** a private dictionary for local variable compilation. 228*/ 229#if !defined FICL_WANT_LOCALS 230#define FICL_WANT_LOCALS 1 231#endif 232 233/* Max number of local variables per definition */ 234#if !defined FICL_MAX_LOCALS 235#define FICL_MAX_LOCALS 16 236#endif 237 238/* 239** FICL_WANT_OOP 240** Inludes object oriented programming support (in softwords) 241** OOP support requires locals and user variables! 242*/ 243#if !(FICL_WANT_LOCALS) || !(FICL_WANT_USER) 244#if !defined (FICL_WANT_OOP) 245#define FICL_WANT_OOP 0 246#endif 247#endif 248 249#if !defined (FICL_WANT_OOP) 250#define FICL_WANT_OOP 1 251#endif 252 253/* 254** FICL_WANT_SOFTWORDS 255** Controls inclusion of all softwords in softcore.c 256*/ 257#if !defined (FICL_WANT_SOFTWORDS) 258#define FICL_WANT_SOFTWORDS 1 259#endif 260 261/* 262** FICL_MULTITHREAD enables dictionary mutual exclusion 263** wia the ficlLockDictionary system dependent function. 264** Note: this implementation is experimental and poorly 265** tested. Further, it's unnecessary unless you really 266** intend to have multiple SESSIONS (poor choice of name 267** on my part) - that is, threads that modify the dictionary 268** at the same time. 269*/ 270#if !defined FICL_MULTITHREAD 271#define FICL_MULTITHREAD 0 272#endif 273 274/* 275** PORTABLE_LONGMULDIV causes ficlLongMul and ficlLongDiv to be 276** defined in C in sysdep.c. Use this if you cannot easily 277** generate an inline asm definition 278*/ 279#if !defined (PORTABLE_LONGMULDIV) 280#define PORTABLE_LONGMULDIV 0 281#endif 282 283/* 284** INLINE_INNER_LOOP causes the inner interpreter to be inline code 285** instead of a function call. This is mainly because MS VC++ 5 286** chokes with an internal compiler error on the function version. 287** in release mode. Sheesh. 288*/ 289#if !defined INLINE_INNER_LOOP 290#if defined _DEBUG 291#define INLINE_INNER_LOOP 0 292#else 293#define INLINE_INNER_LOOP 1 294#endif 295#endif 296 297/* 298** FICL_ROBUST enables bounds checking of stacks and the dictionary. 299** This will detect stack over and underflows and dictionary overflows. 300** Any exceptional condition will result in an assertion failure. 301** (As generated by the ANSI assert macro) 302** FICL_ROBUST == 1 --> stack checking in the outer interpreter 303** FICL_ROBUST == 2 also enables checking in many primitives 304*/ 305 306#if !defined FICL_ROBUST 307#define FICL_ROBUST 2 308#endif 309 310/* 311** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of 312** a new virtual machine's stacks, unless overridden at 313** create time. 314*/ 315#if !defined FICL_DEFAULT_STACK 316#define FICL_DEFAULT_STACK 128 317#endif 318 319/* 320** FICL_DEFAULT_DICT specifies the number of CELLs to allocate 321** for the system dictionary by default. The value 322** can be overridden at startup time as well. 323** FICL_DEFAULT_ENV specifies the number of cells to allot 324** for the environment-query dictionary. 325*/ 326#if !defined FICL_DEFAULT_DICT 327#define FICL_DEFAULT_DICT 12288 328#endif 329 330#if !defined FICL_DEFAULT_ENV 331#define FICL_DEFAULT_ENV 260 332#endif 333 334/* 335** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in 336** the dictionary search order. See Forth DPANS sec 16.3.3 337** (file://dpans16.htm#16.3.3) 338*/ 339#if !defined FICL_DEFAULT_VOCS 340#define FICL_DEFAULT_VOCS 16 341#endif 342 343/* 344** FICL_MAX_PARSE_STEPS controls the size of an array in the FICL_SYSTEM structure 345** that stores pointers to parser extension functions. I would never expect to have 346** more than 8 of these, so that's the default limit. Too many of these functions 347** will probably exact a nasty performance penalty. 348*/ 349#if !defined FICL_MAX_PARSE_STEPS 350#define FICL_MAX_PARSE_STEPS 8 351#endif 352 353/* 354** FICL_EXTENDED_PREFIX enables a bunch of extra prefixes in prefix.c and prefix.fr (if 355** included as part of softcore.c) 356*/ 357#if !defined FICL_EXTENDED_PREFIX 358#define FICL_EXTENDED_PREFIX 0 359#endif 360 361/* 362** FICL_ALIGN is the power of two to which the dictionary 363** pointer address must be aligned. This value is usually 364** either 1 or 2, depending on the memory architecture 365** of the target system; 2 is safe on any 16 or 32 bit 366** machine. 3 would be appropriate for a 64 bit machine. 367*/ 368#if !defined FICL_ALIGN 369#define FICL_ALIGN 2 370#define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1) 371#endif 372 373/* 374** System dependent routines -- 375** edit the implementations in sysdep.c to be compatible 376** with your runtime environment... 377** ficlTextOut sends a NULL terminated string to the 378** default output device - used for system error messages 379** ficlMalloc and ficlFree have the same semantics as malloc and free 380** in standard C 381** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned 382** product 383** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient 384** and remainder 385*/ 386struct vm; 387void ficlTextOut(struct vm *pVM, char *msg, int fNewline); 388void *ficlMalloc (size_t size); 389void ficlFree (void *p); 390void *ficlRealloc(void *p, size_t size); 391/* 392** Stub function for dictionary access control - does nothing 393** by default, user can redefine to guarantee exclusive dict 394** access to a single thread for updates. All dict update code 395** must be bracketed as follows: 396** ficlLockDictionary(TRUE); 397** <code that updates dictionary> 398** ficlLockDictionary(FALSE); 399** 400** Returns zero if successful, nonzero if unable to acquire lock 401** before timeout (optional - could also block forever) 402** 403** NOTE: this function must be implemented with lock counting 404** semantics: nested calls must behave properly. 405*/ 406#if FICL_MULTITHREAD 407int ficlLockDictionary(short fLock); 408#else 409#define ficlLockDictionary(x) /* ignore */ 410#endif 411 412/* 413** 64 bit integer math support routines: multiply two UNS32s 414** to get a 64 bit product, & divide the product by an UNS32 415** to get an UNS32 quotient and remainder. Much easier in asm 416** on a 32 bit CPU than in C, which usually doesn't support 417** the double length result (but it should). 418*/ 419DPUNS ficlLongMul(FICL_UNS x, FICL_UNS y); 420UNSQR ficlLongDiv(DPUNS q, FICL_UNS y); 421 422/* 423** FICL_HAVE_FTRUNCATE indicates whether the current OS supports 424** the ftruncate() function (available on most UNIXes). This 425** function is necessary to provide the complete File-Access wordset. 426*/ 427#if !defined (FICL_HAVE_FTRUNCATE) 428#define FICL_HAVE_FTRUNCATE 0 429#endif 430 431 432#endif /*__SYSDEP_H__*/ 433