1/******************************************************************* 2 s y s d e p . h 3** Forth Inspired Command Language 4** Author: John Sadler (john_sadler@alum.mit.edu) 5** Created: 16 Oct 1997 6** Ficl system dependent types and prototypes... 7** 8** Note: Ficl also depends on the use of "assert" when 9** FICL_ROBUST is enabled. This may require some consideration 10** in firmware systems since assert often 11** assumes stderr/stdout. 12** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $ 13*******************************************************************/ 14/* 15** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu) 16** All rights reserved. 17** 18** Get the latest Ficl release at http://ficl.sourceforge.net 19** 20** L I C E N S E and D I S C L A I M E R 21** 22** Redistribution and use in source and binary forms, with or without 23** modification, are permitted provided that the following conditions 24** are met: 25** 1. Redistributions of source code must retain the above copyright 26** notice, this list of conditions and the following disclaimer. 27** 2. Redistributions in binary form must reproduce the above copyright 28** notice, this list of conditions and the following disclaimer in the 29** documentation and/or other materials provided with the distribution. 30** 31** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 32** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 35** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 39** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 40** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 41** SUCH DAMAGE. 42** 43** I am interested in hearing from anyone who uses ficl. If you have 44** a problem, a success story, a defect, an enhancement request, or 45** if you would like to contribute to the ficl release, please send 46** contact me by email at the address above. 47** 48** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $ 49** $FreeBSD: releng/11.0/sys/boot/ficl/aarch64/sysdep.h 281297 2015-04-09 10:00:26Z andrew $ 50*/ 51 52#if !defined (__SYSDEP_H__) 53#define __SYSDEP_H__ 54 55#include <sys/types.h> 56 57#include <stddef.h> /* size_t, NULL */ 58#include <setjmp.h> 59#include <assert.h> 60 61#if !defined IGNORE /* Macro to silence unused param warnings */ 62#define IGNORE(x) (void)(x) 63#endif 64 65/* 66** TRUE and FALSE for C boolean operations, and 67** portable 32 bit types for CELLs 68** 69*/ 70#if !defined TRUE 71#define TRUE 1 72#endif 73#if !defined FALSE 74#define FALSE 0 75#endif 76 77 78/* 79** System dependent data type declarations... 80*/ 81#if !defined INT32 82#define INT32 int 83#endif 84 85#if !defined UNS32 86#define UNS32 unsigned int 87#endif 88 89#if !defined UNS16 90#define UNS16 unsigned short 91#endif 92 93#if !defined UNS8 94#define UNS8 unsigned char 95#endif 96 97#if !defined NULL 98#define NULL ((void *)0) 99#endif 100 101/* 102** FICL_UNS and FICL_INT must have the same size as a void* on 103** the target system. A CELL is a union of void*, FICL_UNS, and 104** FICL_INT. 105** (11/2000: same for FICL_FLOAT) 106*/ 107#if !defined FICL_INT 108#define FICL_INT long 109#endif 110 111#if !defined FICL_UNS 112#define FICL_UNS unsigned long 113#endif 114 115#if !defined FICL_FLOAT 116#define FICL_FLOAT float 117#endif 118 119/* 120** Ficl presently supports values of 32 and 64 for BITS_PER_CELL 121*/ 122#if !defined BITS_PER_CELL 123#define BITS_PER_CELL 64 124#endif 125 126#if ((BITS_PER_CELL != 32) && (BITS_PER_CELL != 64)) 127 Error! 128#endif 129 130typedef struct 131{ 132 FICL_UNS hi; 133 FICL_UNS lo; 134} DPUNS; 135 136typedef struct 137{ 138 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_FLOAT 0 165#define FICL_WANT_USER 0 166#define FICL_WANT_LOCALS 0 167#define FICL_WANT_DEBUGGER 0 168#define FICL_WANT_OOP 0 169#define FICL_PLATFORM_EXTEND 0 170#define FICL_MULTITHREAD 0 171#define FICL_ROBUST 0 172#define FICL_EXTENDED_PREFIX 0 173#endif 174 175/* 176** FICL_PLATFORM_EXTEND 177** Includes words defined in ficlCompilePlatform 178*/ 179#if !defined (FICL_PLATFORM_EXTEND) 180#define FICL_PLATFORM_EXTEND 1 181#endif 182 183/* 184** FICL_WANT_FLOAT 185** Includes a floating point stack for the VM, and words to do float operations. 186** Contributed by Guy Carver 187*/ 188#if !defined (FICL_WANT_FLOAT) 189#define FICL_WANT_FLOAT 0 190#endif 191 192/* 193** FICL_WANT_DEBUGGER 194** Inludes a simple source level debugger 195*/ 196#if !defined (FICL_WANT_DEBUGGER) 197#define FICL_WANT_DEBUGGER 1 198#endif 199 200/* 201** User variables: per-instance variables bound to the VM. 202** Kinda like thread-local storage. Could be implemented in a 203** VM private dictionary, but I've chosen the lower overhead 204** approach of an array of CELLs instead. 205*/ 206#if !defined FICL_WANT_USER 207#define FICL_WANT_USER 1 208#endif 209 210#if !defined FICL_USER_CELLS 211#define FICL_USER_CELLS 16 212#endif 213 214/* 215** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and 216** a private dictionary for local variable compilation. 217*/ 218#if !defined FICL_WANT_LOCALS 219#define FICL_WANT_LOCALS 1 220#endif 221 222/* Max number of local variables per definition */ 223#if !defined FICL_MAX_LOCALS 224#define FICL_MAX_LOCALS 16 225#endif 226 227/* 228** FICL_WANT_OOP 229** Inludes object oriented programming support (in softwords) 230** OOP support requires locals and user variables! 231*/ 232#if !(FICL_WANT_LOCALS) || !(FICL_WANT_USER) 233#if !defined (FICL_WANT_OOP) 234#define FICL_WANT_OOP 0 235#endif 236#endif 237 238#if !defined (FICL_WANT_OOP) 239#define FICL_WANT_OOP 1 240#endif 241 242/* 243** FICL_WANT_SOFTWORDS 244** Controls inclusion of all softwords in softcore.c 245*/ 246#if !defined (FICL_WANT_SOFTWORDS) 247#define FICL_WANT_SOFTWORDS 1 248#endif 249 250/* 251** FICL_MULTITHREAD enables dictionary mutual exclusion 252** wia the ficlLockDictionary system dependent function. 253** Note: this implementation is experimental and poorly 254** tested. Further, it's unnecessary unless you really 255** intend to have multiple SESSIONS (poor choice of name 256** on my part) - that is, threads that modify the dictionary 257** at the same time. 258*/ 259#if !defined FICL_MULTITHREAD 260#define FICL_MULTITHREAD 0 261#endif 262 263/* 264** PORTABLE_LONGMULDIV causes ficlLongMul and ficlLongDiv to be 265** defined in C in sysdep.c. Use this if you cannot easily 266** generate an inline asm definition 267*/ 268#if !defined (PORTABLE_LONGMULDIV) 269#define PORTABLE_LONGMULDIV 0 270#endif 271 272/* 273** INLINE_INNER_LOOP causes the inner interpreter to be inline code 274** instead of a function call. This is mainly because MS VC++ 5 275** chokes with an internal compiler error on the function version. 276** in release mode. Sheesh. 277*/ 278#if !defined INLINE_INNER_LOOP 279#if defined _DEBUG 280#define INLINE_INNER_LOOP 0 281#else 282#define INLINE_INNER_LOOP 1 283#endif 284#endif 285 286/* 287** FICL_ROBUST enables bounds checking of stacks and the dictionary. 288** This will detect stack over and underflows and dictionary overflows. 289** Any exceptional condition will result in an assertion failure. 290** (As generated by the ANSI assert macro) 291** FICL_ROBUST == 1 --> stack checking in the outer interpreter 292** FICL_ROBUST == 2 also enables checking in many primitives 293*/ 294 295#if !defined FICL_ROBUST 296#define FICL_ROBUST 2 297#endif 298 299/* 300** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of 301** a new virtual machine's stacks, unless overridden at 302** create time. 303*/ 304#if !defined FICL_DEFAULT_STACK 305#define FICL_DEFAULT_STACK 128 306#endif 307 308/* 309** FICL_DEFAULT_DICT specifies the number of CELLs to allocate 310** for the system dictionary by default. The value 311** can be overridden at startup time as well. 312** FICL_DEFAULT_ENV specifies the number of cells to allot 313** for the environment-query dictionary. 314*/ 315#if !defined FICL_DEFAULT_DICT 316#define FICL_DEFAULT_DICT 12288 317#endif 318 319#if !defined FICL_DEFAULT_ENV 320#define FICL_DEFAULT_ENV 260 321#endif 322 323/* 324** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in 325** the dictionary search order. See Forth DPANS sec 16.3.3 326** (file://dpans16.htm#16.3.3) 327*/ 328#if !defined FICL_DEFAULT_VOCS 329#define FICL_DEFAULT_VOCS 16 330#endif 331 332/* 333** FICL_MAX_PARSE_STEPS controls the size of an array in the FICL_SYSTEM structure 334** that stores pointers to parser extension functions. I would never expect to have 335** more than 8 of these, so that's the default limit. Too many of these functions 336** will probably exact a nasty performance penalty. 337*/ 338#if !defined FICL_MAX_PARSE_STEPS 339#define FICL_MAX_PARSE_STEPS 8 340#endif 341 342/* 343** FICL_EXTENDED_PREFIX enables a bunch of extra prefixes in prefix.c and prefix.fr (if 344** included as part of softcore.c) 345*/ 346#if !defined FICL_EXTENDED_PREFIX 347#define FICL_EXTENDED_PREFIX 0 348#endif 349 350/* 351** FICL_ALIGN is the power of two to which the dictionary 352** pointer address must be aligned. This value is usually 353** either 1 or 2, depending on the memory architecture 354** of the target system; 2 is safe on any 16 or 32 bit 355** machine. 3 would be appropriate for a 64 bit machine. 356*/ 357#if !defined FICL_ALIGN 358#define FICL_ALIGN 3 359#define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1) 360#endif 361 362/* 363** System dependent routines -- 364** edit the implementations in sysdep.c to be compatible 365** with your runtime environment... 366** ficlTextOut sends a NULL terminated string to the 367** default output device - used for system error messages 368** ficlMalloc and ficlFree have the same semantics as malloc and free 369** in standard C 370** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned 371** product 372** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient 373** and remainder 374*/ 375struct vm; 376void ficlTextOut(struct vm *pVM, char *msg, int fNewline); 377void *ficlMalloc (size_t size); 378void ficlFree (void *p); 379void *ficlRealloc(void *p, size_t size); 380/* 381** Stub function for dictionary access control - does nothing 382** by default, user can redefine to guarantee exclusive dict 383** access to a single thread for updates. All dict update code 384** must be bracketed as follows: 385** ficlLockDictionary(TRUE); 386** <code that updates dictionary> 387** ficlLockDictionary(FALSE); 388** 389** Returns zero if successful, nonzero if unable to acquire lock 390** before timeout (optional - could also block forever) 391** 392** NOTE: this function must be implemented with lock counting 393** semantics: nested calls must behave properly. 394*/ 395#if FICL_MULTITHREAD 396int ficlLockDictionary(short fLock); 397#else 398#define ficlLockDictionary(x) 0 /* ignore */ 399#endif 400 401/* 402** 64 bit integer math support routines: multiply two UNS32s 403** to get a 64 bit product, & divide the product by an UNS32 404** to get an UNS32 quotient and remainder. Much easier in asm 405** on a 32 bit CPU than in C, which usually doesn't support 406** the double length result (but it should). 407*/ 408DPUNS ficlLongMul(FICL_UNS x, FICL_UNS y); 409UNSQR ficlLongDiv(DPUNS q, FICL_UNS y); 410 411#endif /*__SYSDEP_H__*/ 412