1 /*******************************************************************
2 ** s y s d e p . c
3 ** Forth Inspired Command Language
4 ** Author: John Sadler (john_sadler@alum.mit.edu)
5 ** Created: 16 Oct 1997
6 ** Implementations of FICL external interface functions...
7 **
8 *******************************************************************/
9
10
11 #ifdef TESTMAIN
12 #include <stdio.h>
13 #include <stdlib.h>
14 #else
15 #include <stand.h>
16 #endif
17 #include "ficl.h"
18
19 #include "../x86/sysdep.c"
20
21 /*
22 ******************* FreeBSD P O R T B E G I N S H E R E ******************** Michael Smith
23 */
24
25 #if PORTABLE_LONGMULDIV == 0
ficlLongMul(FICL_UNS x,FICL_UNS y)26 DPUNS ficlLongMul(FICL_UNS x, FICL_UNS y)
27 {
28 DPUNS q;
29 uint64_t qx;
30
31 qx = (uint64_t)x * (uint64_t) y;
32
33 q.hi = (uint32_t)( qx >> 32 );
34 q.lo = (uint32_t)( qx & 0xFFFFFFFFL);
35
36 return q;
37 }
38
ficlLongDiv(DPUNS q,FICL_UNS y)39 UNSQR ficlLongDiv(DPUNS q, FICL_UNS y)
40 {
41 UNSQR result;
42 uint64_t qx, qh;
43
44 qh = q.hi;
45 qx = (qh << 32) | q.lo;
46
47 result.quot = qx / y;
48 result.rem = qx % y;
49
50 return result;
51 }
52 #endif
53
ficlTextOut(FICL_VM * pVM,char * msg,int fNewline)54 void ficlTextOut(FICL_VM *pVM, char *msg, int fNewline)
55 {
56 IGNORE(pVM);
57
58 while(*msg != 0)
59 putchar((unsigned char)*(msg++));
60 if (fNewline)
61 putchar('\n');
62
63 return;
64 }
65
ficlMalloc(size_t size)66 void *ficlMalloc (size_t size)
67 {
68 return malloc(size);
69 }
70
ficlRealloc(void * p,size_t size)71 void *ficlRealloc (void *p, size_t size)
72 {
73 return realloc(p, size);
74 }
75
ficlFree(void * p)76 void ficlFree (void *p)
77 {
78 free(p);
79 }
80
81
82 /*
83 ** Stub function for dictionary access control - does nothing
84 ** by default, user can redefine to guarantee exclusive dict
85 ** access to a single thread for updates. All dict update code
86 ** is guaranteed to be bracketed as follows:
87 ** ficlLockDictionary(TRUE);
88 ** <code that updates dictionary>
89 ** ficlLockDictionary(FALSE);
90 **
91 ** Returns zero if successful, nonzero if unable to acquire lock
92 ** befor timeout (optional - could also block forever)
93 */
94 #if FICL_MULTITHREAD
ficlLockDictionary(short fLock)95 int ficlLockDictionary(short fLock)
96 {
97 IGNORE(fLock);
98 return 0;
99 }
100 #endif /* FICL_MULTITHREAD */
101