1998-11-03 06:11:35 +00:00
|
|
|
/*******************************************************************
|
|
|
|
** s y s d e p . c
|
|
|
|
** Forth Inspired Command Language
|
|
|
|
** Author: John Sadler (john_sadler@alum.mit.edu)
|
|
|
|
** Created: 16 Oct 1997
|
|
|
|
** Implementations of FICL external interface functions...
|
|
|
|
**
|
|
|
|
*******************************************************************/
|
|
|
|
|
1999-09-29 05:43:16 +01:00
|
|
|
/* $FreeBSD$ */
|
|
|
|
|
1998-11-04 03:42:16 +00:00
|
|
|
#ifdef TESTMAIN
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#else
|
1998-11-04 00:29:33 +00:00
|
|
|
#include <stand.h>
|
1999-01-13 21:31:50 +00:00
|
|
|
#ifdef __i386__
|
|
|
|
#include <machine/cpufunc.h>
|
|
|
|
#endif
|
1999-01-14 23:48:03 +00:00
|
|
|
#endif
|
1998-11-03 06:11:35 +00:00
|
|
|
#include "ficl.h"
|
1998-11-04 00:29:33 +00:00
|
|
|
|
1998-11-03 06:11:35 +00:00
|
|
|
/*
|
|
|
|
******************* FreeBSD P O R T B E G I N S H E R E ******************** Michael Smith
|
|
|
|
*/
|
|
|
|
|
1999-09-29 05:43:16 +01:00
|
|
|
#if PORTABLE_LONGMULDIV == 0
|
|
|
|
DPUNS ficlLongMul(FICL_UNS x, FICL_UNS y)
|
1998-11-03 06:11:35 +00:00
|
|
|
{
|
1999-09-29 05:43:16 +01:00
|
|
|
DPUNS q;
|
1998-11-03 06:11:35 +00:00
|
|
|
u_int64_t qx;
|
|
|
|
|
|
|
|
qx = (u_int64_t)x * (u_int64_t) y;
|
|
|
|
|
|
|
|
q.hi = (u_int32_t)( qx >> 32 );
|
|
|
|
q.lo = (u_int32_t)( qx & 0xFFFFFFFFL);
|
|
|
|
|
|
|
|
return q;
|
|
|
|
}
|
|
|
|
|
1999-09-29 05:43:16 +01:00
|
|
|
UNSQR ficlLongDiv(DPUNS q, FICL_UNS y)
|
1998-11-03 06:11:35 +00:00
|
|
|
{
|
|
|
|
UNSQR result;
|
|
|
|
u_int64_t qx, qh;
|
|
|
|
|
|
|
|
qh = q.hi;
|
|
|
|
qx = (qh << 32) | q.lo;
|
|
|
|
|
|
|
|
result.quot = qx / y;
|
|
|
|
result.rem = qx % y;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
1999-09-29 05:43:16 +01:00
|
|
|
#endif
|
1998-11-03 06:11:35 +00:00
|
|
|
|
|
|
|
void ficlTextOut(FICL_VM *pVM, char *msg, int fNewline)
|
|
|
|
{
|
|
|
|
IGNORE(pVM);
|
|
|
|
|
|
|
|
while(*msg != 0)
|
|
|
|
putchar(*(msg++));
|
|
|
|
if (fNewline)
|
|
|
|
putchar('\n');
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *ficlMalloc (size_t size)
|
|
|
|
{
|
|
|
|
return malloc(size);
|
|
|
|
}
|
|
|
|
|
1999-01-22 23:52:59 +00:00
|
|
|
void *ficlRealloc (void *p, size_t size)
|
|
|
|
{
|
|
|
|
return realloc(p, size);
|
|
|
|
}
|
|
|
|
|
1998-11-03 06:11:35 +00:00
|
|
|
void ficlFree (void *p)
|
|
|
|
{
|
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
1999-01-22 23:52:59 +00:00
|
|
|
#ifndef TESTMAIN
|
1999-01-13 21:31:50 +00:00
|
|
|
#ifdef __i386__
|
|
|
|
/*
|
1999-01-14 23:48:03 +00:00
|
|
|
* outb ( port# c -- )
|
1999-01-13 21:31:50 +00:00
|
|
|
* Store a byte to I/O port number port#
|
|
|
|
*/
|
|
|
|
void
|
1999-01-14 23:48:03 +00:00
|
|
|
ficlOutb(FICL_VM *pVM)
|
1999-01-13 21:31:50 +00:00
|
|
|
{
|
|
|
|
u_char c;
|
|
|
|
u_int32_t port;
|
|
|
|
|
1999-09-29 05:43:16 +01:00
|
|
|
port=stackPopUNS(pVM->pStack);
|
|
|
|
c=(u_char)stackPopINT(pVM->pStack);
|
1999-01-13 21:31:50 +00:00
|
|
|
outb(port,c);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-01-14 23:48:03 +00:00
|
|
|
* inb ( port# -- c )
|
1999-01-13 21:31:50 +00:00
|
|
|
* Fetch a byte from I/O port number port#
|
|
|
|
*/
|
|
|
|
void
|
1999-01-14 23:48:03 +00:00
|
|
|
ficlInb(FICL_VM *pVM)
|
1999-01-13 21:31:50 +00:00
|
|
|
{
|
|
|
|
u_char c;
|
|
|
|
u_int32_t port;
|
|
|
|
|
1999-09-29 05:43:16 +01:00
|
|
|
port=stackPopUNS(pVM->pStack);
|
1999-01-13 21:31:50 +00:00
|
|
|
c=inb(port);
|
1999-09-29 05:43:16 +01:00
|
|
|
stackPushINT(pVM->pStack,c);
|
1999-01-13 21:31:50 +00:00
|
|
|
}
|
|
|
|
#endif
|
1999-01-22 23:52:59 +00:00
|
|
|
#endif
|
1999-01-13 21:31:50 +00:00
|
|
|
|
1998-11-03 06:11:35 +00:00
|
|
|
/*
|
|
|
|
** Stub function for dictionary access control - does nothing
|
|
|
|
** by default, user can redefine to guarantee exclusive dict
|
|
|
|
** access to a single thread for updates. All dict update code
|
|
|
|
** is guaranteed to be bracketed as follows:
|
|
|
|
** ficlLockDictionary(TRUE);
|
|
|
|
** <code that updates dictionary>
|
|
|
|
** ficlLockDictionary(FALSE);
|
|
|
|
**
|
|
|
|
** Returns zero if successful, nonzero if unable to acquire lock
|
|
|
|
** befor timeout (optional - could also block forever)
|
|
|
|
*/
|
|
|
|
#if FICL_MULTITHREAD
|
|
|
|
int ficlLockDictionary(short fLock)
|
|
|
|
{
|
|
|
|
IGNORE(fLock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* FICL_MULTITHREAD */
|
|
|
|
|
|
|
|
|