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