xref: /freebsd/stand/ficl/powerpc/sysdep.h (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
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 */
50 
51 #if !defined (__SYSDEP_H__)
52 #define __SYSDEP_H__
53 
54 #include <sys/types.h>
55 
56 #include <stddef.h> /* size_t, NULL */
57 #include <setjmp.h>
58 #include <assert.h>
59 
60 #if !defined IGNORE		/* Macro to silence unused param warnings */
61 #define IGNORE(x) &x
62 #endif
63 
64 /*
65 ** TRUE and FALSE for C boolean operations, and
66 ** portable 32 bit types for CELLs
67 **
68 */
69 #if !defined TRUE
70 #define TRUE 1
71 #endif
72 #if !defined FALSE
73 #define FALSE 0
74 #endif
75 
76 
77 /*
78 ** System dependent data type declarations...
79 */
80 #if !defined INT32
81 #define INT32 int32_t
82 #endif
83 
84 #if !defined UNS32
85 #define UNS32 uint32_t
86 #endif
87 
88 #if !defined UNS16
89 #define UNS16 uint16_t
90 #endif
91 
92 #if !defined UNS8
93 #define UNS8 unsigned char
94 #endif
95 
96 #if !defined NULL
97 #define NULL ((void *)0)
98 #endif
99 
100 /*
101 ** FICL_UNS and FICL_INT must have the same size as a void* on
102 ** the target system. A CELL is a union of void*, FICL_UNS, and
103 ** FICL_INT.
104 ** (11/2000: same for FICL_FLOAT)
105 */
106 #if !defined FICL_INT
107 #define FICL_INT INT32
108 #endif
109 
110 #if !defined FICL_UNS
111 #define FICL_UNS UNS32
112 #endif
113 
114 #if !defined FICL_FLOAT
115 #define FICL_FLOAT float
116 #endif
117 
118 /*
119 ** Ficl presently supports values of 32 and 64 for BITS_PER_CELL
120 */
121 #if !defined BITS_PER_CELL
122 #define BITS_PER_CELL 32
123 #endif
124 
125 #if ((BITS_PER_CELL != 32) && (BITS_PER_CELL != 64))
126     Error!
127 #endif
128 
129 typedef struct
130 {
131     FICL_UNS hi;
132     FICL_UNS lo;
133 } DPUNS;
134 
135 typedef struct
136 {
137     FICL_UNS quot;
138     FICL_UNS rem;
139 } UNSQR;
140 
141 typedef struct
142 {
143     FICL_INT hi;
144     FICL_INT lo;
145 } DPINT;
146 
147 typedef struct
148 {
149     FICL_INT quot;
150     FICL_INT rem;
151 } INTQR;
152 
153 
154 /*
155 ** B U I L D   C O N T R O L S
156 */
157 
158 #if !defined (FICL_MINIMAL)
159 #define FICL_MINIMAL 0
160 #endif
161 #if (FICL_MINIMAL)
162 #define FICL_WANT_SOFTWORDS  0
163 #define FICL_WANT_FILE	     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         1
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_FILE
185 ** Includes the FILE and FILE-EXT wordset and associated code. Turn this off if you do not
186 ** have a filesystem!
187 ** Contributed by Larry Hastings
188 */
189 #if !defined (FICL_WANT_FILE)
190 #define FICL_WANT_FILE 0
191 #endif
192 
193 /*
194 ** FICL_WANT_FLOAT
195 ** Includes a floating point stack for the VM, and words to do float operations.
196 ** Contributed by Guy Carver
197 */
198 #if !defined (FICL_WANT_FLOAT)
199 #define FICL_WANT_FLOAT 0
200 #endif
201 
202 /*
203 ** FICL_WANT_DEBUGGER
204 ** Inludes a simple source level debugger
205 */
206 #if !defined (FICL_WANT_DEBUGGER)
207 #define FICL_WANT_DEBUGGER 1
208 #endif
209 
210 /*
211 ** User variables: per-instance variables bound to the VM.
212 ** Kinda like thread-local storage. Could be implemented in a
213 ** VM private dictionary, but I've chosen the lower overhead
214 ** approach of an array of CELLs instead.
215 */
216 #if !defined FICL_WANT_USER
217 #define FICL_WANT_USER 1
218 #endif
219 
220 #if !defined FICL_USER_CELLS
221 #define FICL_USER_CELLS 16
222 #endif
223 
224 /*
225 ** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and
226 ** a private dictionary for local variable compilation.
227 */
228 #if !defined FICL_WANT_LOCALS
229 #define FICL_WANT_LOCALS 1
230 #endif
231 
232 /* Max number of local variables per definition */
233 #if !defined FICL_MAX_LOCALS
234 #define FICL_MAX_LOCALS 16
235 #endif
236 
237 /*
238 ** FICL_WANT_OOP
239 ** Inludes object oriented programming support (in softwords)
240 ** OOP support requires locals and user variables!
241 */
242 #if !(FICL_WANT_LOCALS) || !(FICL_WANT_USER)
243 #if !defined (FICL_WANT_OOP)
244 #define FICL_WANT_OOP 0
245 #endif
246 #endif
247 
248 #if !defined (FICL_WANT_OOP)
249 #define FICL_WANT_OOP 1
250 #endif
251 
252 /*
253 ** FICL_WANT_SOFTWORDS
254 ** Controls inclusion of all softwords in softcore.c
255 */
256 #if !defined (FICL_WANT_SOFTWORDS)
257 #define FICL_WANT_SOFTWORDS 1
258 #endif
259 
260 /*
261 ** FICL_MULTITHREAD enables dictionary mutual exclusion
262 ** wia the ficlLockDictionary system dependent function.
263 ** Note: this implementation is experimental and poorly
264 ** tested. Further, it's unnecessary unless you really
265 ** intend to have multiple SESSIONS (poor choice of name
266 ** on my part) - that is, threads that modify the dictionary
267 ** at the same time.
268 */
269 #if !defined FICL_MULTITHREAD
270 #define FICL_MULTITHREAD 0
271 #endif
272 
273 /*
274 ** PORTABLE_LONGMULDIV causes ficlLongMul and ficlLongDiv to be
275 ** defined in C in sysdep.c. Use this if you cannot easily
276 ** generate an inline asm definition
277 */
278 #if !defined (PORTABLE_LONGMULDIV)
279 #define PORTABLE_LONGMULDIV 0
280 #endif
281 
282 /*
283 ** INLINE_INNER_LOOP causes the inner interpreter to be inline code
284 ** instead of a function call. This is mainly because MS VC++ 5
285 ** chokes with an internal compiler error on the function version.
286 ** in release mode. Sheesh.
287 */
288 #if !defined INLINE_INNER_LOOP
289 #if defined _DEBUG
290 #define INLINE_INNER_LOOP 0
291 #else
292 #define INLINE_INNER_LOOP 1
293 #endif
294 #endif
295 
296 /*
297 ** FICL_ROBUST enables bounds checking of stacks and the dictionary.
298 ** This will detect stack over and underflows and dictionary overflows.
299 ** Any exceptional condition will result in an assertion failure.
300 ** (As generated by the ANSI assert macro)
301 ** FICL_ROBUST == 1 --> stack checking in the outer interpreter
302 ** FICL_ROBUST == 2 also enables checking in many primitives
303 */
304 
305 #if !defined FICL_ROBUST
306 #define FICL_ROBUST 2
307 #endif
308 
309 /*
310 ** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of
311 ** a new virtual machine's stacks, unless overridden at
312 ** create time.
313 */
314 #if !defined FICL_DEFAULT_STACK
315 #define FICL_DEFAULT_STACK 128
316 #endif
317 
318 /*
319 ** FICL_DEFAULT_DICT specifies the number of CELLs to allocate
320 ** for the system dictionary by default. The value
321 ** can be overridden at startup time as well.
322 ** FICL_DEFAULT_ENV specifies the number of cells to allot
323 ** for the environment-query dictionary.
324 */
325 #if !defined FICL_DEFAULT_DICT
326 #define FICL_DEFAULT_DICT 12288
327 #endif
328 
329 #if !defined FICL_DEFAULT_ENV
330 #define FICL_DEFAULT_ENV 260
331 #endif
332 
333 /*
334 ** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in
335 ** the dictionary search order. See Forth DPANS sec 16.3.3
336 ** (file://dpans16.htm#16.3.3)
337 */
338 #if !defined FICL_DEFAULT_VOCS
339 #define FICL_DEFAULT_VOCS 16
340 #endif
341 
342 /*
343 ** FICL_MAX_PARSE_STEPS controls the size of an array in the FICL_SYSTEM structure
344 ** that stores pointers to parser extension functions. I would never expect to have
345 ** more than 8 of these, so that's the default limit. Too many of these functions
346 ** will probably exact a nasty performance penalty.
347 */
348 #if !defined FICL_MAX_PARSE_STEPS
349 #define FICL_MAX_PARSE_STEPS 8
350 #endif
351 
352 /*
353 ** FICL_EXTENDED_PREFIX enables a bunch of extra prefixes in prefix.c and prefix.fr (if
354 ** included as part of softcore.c)
355 */
356 #if !defined FICL_EXTENDED_PREFIX
357 #define FICL_EXTENDED_PREFIX 0
358 #endif
359 
360 /*
361 ** FICL_ALIGN is the power of two to which the dictionary
362 ** pointer address must be aligned. This value is usually
363 ** either 1 or 2, depending on the memory architecture
364 ** of the target system; 2 is safe on any 16 or 32 bit
365 ** machine. 3 would be appropriate for a 64 bit machine.
366 */
367 #if !defined FICL_ALIGN
368 #define FICL_ALIGN 2
369 #endif
370 
371 #if !defined FICL_ALIGN_ADD
372 #define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1)
373 #endif
374 
375 /*
376 ** System dependent routines --
377 ** edit the implementations in sysdep.c to be compatible
378 ** with your runtime environment...
379 ** ficlTextOut sends a NULL terminated string to the
380 **   default output device - used for system error messages
381 ** ficlMalloc and ficlFree have the same semantics as malloc and free
382 **   in standard C
383 ** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned
384 **   product
385 ** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient
386 **   and remainder
387 */
388 struct vm;
389 void  ficlTextOut(struct vm *pVM, char *msg, int fNewline);
390 void *ficlMalloc (size_t size);
391 void  ficlFree   (void *p);
392 void *ficlRealloc(void *p, size_t size);
393 /*
394 ** Stub function for dictionary access control - does nothing
395 ** by default, user can redefine to guarantee exclusive dict
396 ** access to a single thread for updates. All dict update code
397 ** must be bracketed as follows:
398 ** ficlLockDictionary(TRUE);
399 ** <code that updates dictionary>
400 ** ficlLockDictionary(FALSE);
401 **
402 ** Returns zero if successful, nonzero if unable to acquire lock
403 ** before timeout (optional - could also block forever)
404 **
405 ** NOTE: this function must be implemented with lock counting
406 ** semantics: nested calls must behave properly.
407 */
408 #if FICL_MULTITHREAD
409 int ficlLockDictionary(short fLock);
410 #else
411 #define ficlLockDictionary(x) 0 /* ignore */
412 #endif
413 
414 /*
415 ** 64 bit integer math support routines: multiply two UNS32s
416 ** to get a 64 bit product, & divide the product by an UNS32
417 ** to get an UNS32 quotient and remainder. Much easier in asm
418 ** on a 32 bit CPU than in C, which usually doesn't support
419 ** the double length result (but it should).
420 */
421 DPUNS ficlLongMul(FICL_UNS x, FICL_UNS y);
422 UNSQR ficlLongDiv(DPUNS    q, FICL_UNS y);
423 
424 /*
425 ** FICL_HAVE_FTRUNCATE indicates whether the current OS supports
426 ** the ftruncate() function (available on most UNIXes).  This
427 ** function is necessary to provide the complete File-Access wordset.
428 */
429 #if !defined (FICL_HAVE_FTRUNCATE)
430 #define FICL_HAVE_FTRUNCATE 0
431 #endif
432 
433 
434 #endif /*__SYSDEP_H__*/
435