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 04:43:16 +00: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 04:43:16 +00:00
|
|
|
#if PORTABLE_LONGMULDIV == 0
|
|
|
|
DPUNS ficlLongMul(FICL_UNS x, FICL_UNS y)
|
1998-11-03 06:11:35 +00:00
|
|
|
{
|
1999-09-29 04:43:16 +00:00
|
|
|
DPUNS q;
|
2018-03-13 16:33:00 +00:00
|
|
|
uint64_t qx;
|
1998-11-03 06:11:35 +00:00
|
|
|
|
2018-03-13 16:33:00 +00:00
|
|
|
qx = (uint64_t)x * (uint64_t) y;
|
1998-11-03 06:11:35 +00:00
|
|
|
|
2018-03-13 16:33:00 +00:00
|
|
|
q.hi = (uint32_t)( qx >> 32 );
|
|
|
|
q.lo = (uint32_t)( qx & 0xFFFFFFFFL);
|
1998-11-03 06:11:35 +00:00
|
|
|
|
|
|
|
return q;
|
|
|
|
}
|
|
|
|
|
1999-09-29 04:43:16 +00:00
|
|
|
UNSQR ficlLongDiv(DPUNS q, FICL_UNS y)
|
1998-11-03 06:11:35 +00:00
|
|
|
{
|
|
|
|
UNSQR result;
|
2018-03-13 16:33:00 +00:00
|
|
|
uint64_t qx, qh;
|
1998-11-03 06:11:35 +00:00
|
|
|
|
|
|
|
qh = q.hi;
|
|
|
|
qx = (qh << 32) | q.lo;
|
|
|
|
|
|
|
|
result.quot = qx / y;
|
|
|
|
result.rem = qx % y;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
1999-09-29 04:43:16 +00:00
|
|
|
#endif
|
1998-11-03 06:11:35 +00:00
|
|
|
|
|
|
|
void ficlTextOut(FICL_VM *pVM, char *msg, int fNewline)
|
|
|
|
{
|
|
|
|
IGNORE(pVM);
|
|
|
|
|
|
|
|
while(*msg != 0)
|
2016-01-27 16:45:23 +00:00
|
|
|
putchar((unsigned char)*(msg++));
|
1998-11-03 06:11:35 +00:00
|
|
|
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
|
|
|
/*
|
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;
|
2018-03-13 16:33:00 +00:00
|
|
|
uint32_t port;
|
1999-01-13 21:31:50 +00:00
|
|
|
|
1999-09-29 04:43:16 +00: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;
|
2018-03-13 16:33:00 +00:00
|
|
|
uint32_t port;
|
1999-01-13 21:31:50 +00:00
|
|
|
|
1999-09-29 04:43:16 +00:00
|
|
|
port=stackPopUNS(pVM->pStack);
|
1999-01-13 21:31:50 +00:00
|
|
|
c=inb(port);
|
1999-09-29 04:43:16 +00:00
|
|
|
stackPushINT(pVM->pStack,c);
|
1999-01-13 21:31:50 +00:00
|
|
|
}
|
2016-10-14 16:23:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Glue function to add the appropriate forth words to access x86 special cpu
|
|
|
|
* functionality.
|
|
|
|
*/
|
|
|
|
static void ficlCompileCpufunc(FICL_SYSTEM *pSys)
|
|
|
|
{
|
|
|
|
FICL_DICT *dp = pSys->dp;
|
|
|
|
assert (dp);
|
|
|
|
|
|
|
|
dictAppendWord(dp, "outb", ficlOutb, FW_DEFAULT);
|
|
|
|
dictAppendWord(dp, "inb", ficlInb, FW_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
FICL_COMPILE_SET(ficlCompileCpufunc);
|
|
|
|
|
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 */
|