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