Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / boot / ficl / i386 / sysdep.c
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: src/sys/boot/ficl/i386/sysdep.c,v 1.7 1999/09/29 04:43:07 dcs Exp $ */
11 /* $DragonFly: src/sys/boot/ficl/i386/sysdep.c,v 1.2 2003/06/17 04:28:18 dillon Exp $ */
12
13 #ifdef TESTMAIN
14 #include <stdio.h>
15 #include <stdlib.h>
16 #else
17 #include <stand.h>
18 #ifdef __i386__
19 #include <machine/cpufunc.h>
20 #endif
21 #endif
22 #include "ficl.h"
23
24 /*
25 *******************  FreeBSD  P O R T   B E G I N S   H E R E ******************** Michael Smith
26 */
27
28 #if PORTABLE_LONGMULDIV == 0
29 DPUNS ficlLongMul(FICL_UNS x, FICL_UNS y)
30 {
31     DPUNS q;
32     u_int64_t qx;
33
34     qx = (u_int64_t)x * (u_int64_t) y;
35
36     q.hi = (u_int32_t)( qx >> 32 );
37     q.lo = (u_int32_t)( qx & 0xFFFFFFFFL);
38
39     return q;
40 }
41
42 UNSQR ficlLongDiv(DPUNS q, FICL_UNS y)
43 {
44     UNSQR result;
45     u_int64_t qx, qh;
46
47     qh = q.hi;
48     qx = (qh << 32) | q.lo;
49
50     result.quot = qx / y;
51     result.rem  = qx % y;
52
53     return result;
54 }
55 #endif
56
57 void  ficlTextOut(FICL_VM *pVM, char *msg, int fNewline)
58 {
59     IGNORE(pVM);
60
61     while(*msg != 0)
62         putchar(*(msg++));
63     if (fNewline)
64         putchar('\n');
65
66    return;
67 }
68
69 void *ficlMalloc (size_t size)
70 {
71     return malloc(size);
72 }
73
74 void *ficlRealloc (void *p, size_t size)
75 {
76     return realloc(p, size);
77 }
78
79 void  ficlFree   (void *p)
80 {
81     free(p);
82 }
83
84 #ifndef TESTMAIN
85 #ifdef __i386__
86 /* 
87  * outb ( port# c -- )
88  * Store a byte to I/O port number port#
89  */
90 void
91 ficlOutb(FICL_VM *pVM)
92 {
93         u_char c;
94         u_int32_t port;
95
96         port=stackPopUNS(pVM->pStack);
97         c=(u_char)stackPopINT(pVM->pStack);
98         outb(port,c);
99 }
100
101 /*
102  * inb ( port# -- c )
103  * Fetch a byte from I/O port number port#
104  */
105 void
106 ficlInb(FICL_VM *pVM)
107 {
108         u_char c;
109         u_int32_t port;
110
111         port=stackPopUNS(pVM->pStack);
112         c=inb(port);
113         stackPushINT(pVM->pStack,c);
114 }
115 #endif
116 #endif
117
118 /*
119 ** Stub function for dictionary access control - does nothing
120 ** by default, user can redefine to guarantee exclusive dict
121 ** access to a single thread for updates. All dict update code
122 ** is guaranteed to be bracketed as follows:
123 ** ficlLockDictionary(TRUE);
124 ** <code that updates dictionary>
125 ** ficlLockDictionary(FALSE);
126 **
127 ** Returns zero if successful, nonzero if unable to acquire lock
128 ** befor timeout (optional - could also block forever)
129 */
130 #if FICL_MULTITHREAD
131 int ficlLockDictionary(short fLock)
132 {
133         IGNORE(fLock);
134         return 0;
135 }
136 #endif /* FICL_MULTITHREAD */
137
138