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