140843Smsmith/******************************************************************* 240843Smsmith** s y s d e p . c 340843Smsmith** Forth Inspired Command Language 440843Smsmith** Author: John Sadler (john_sadler@alum.mit.edu) 540843Smsmith** Created: 16 Oct 1997 640843Smsmith** Implementations of FICL external interface functions... 740843Smsmith** 840843Smsmith*******************************************************************/ 940843Smsmith 1051786Sdcs/* $FreeBSD$ */ 1151786Sdcs 1240883Smsmith#ifdef TESTMAIN 1340883Smsmith#include <stdio.h> 1440883Smsmith#include <stdlib.h> 1540883Smsmith#else 1640876Smsmith#include <stand.h> 1742634Sabial#ifdef __i386__ 1842634Sabial#include <machine/cpufunc.h> 1942634Sabial#endif 2042679Sabial#endif 2140876Smsmith#include "ficl.h" 2240843Smsmith 2340843Smsmith/* 2440843Smsmith******************* FreeBSD P O R T B E G I N S H E R E ******************** Michael Smith 2540843Smsmith*/ 2640843Smsmith 2751786Sdcs#if PORTABLE_LONGMULDIV == 0 2851786SdcsDPUNS ficlLongMul(FICL_UNS x, FICL_UNS y) 2940843Smsmith{ 3051786Sdcs DPUNS q; 3140843Smsmith u_int64_t qx; 3240843Smsmith 3340843Smsmith qx = (u_int64_t)x * (u_int64_t) y; 3440843Smsmith 3540843Smsmith q.hi = (u_int32_t)( qx >> 32 ); 3640843Smsmith q.lo = (u_int32_t)( qx & 0xFFFFFFFFL); 3740843Smsmith 3840843Smsmith return q; 3940843Smsmith} 4040843Smsmith 4151786SdcsUNSQR ficlLongDiv(DPUNS q, FICL_UNS y) 4240843Smsmith{ 4340843Smsmith UNSQR result; 4440843Smsmith u_int64_t qx, qh; 4540843Smsmith 4640843Smsmith qh = q.hi; 4740843Smsmith qx = (qh << 32) | q.lo; 4840843Smsmith 4940843Smsmith result.quot = qx / y; 5040843Smsmith result.rem = qx % y; 5140843Smsmith 5240843Smsmith return result; 5340843Smsmith} 5451786Sdcs#endif 5540843Smsmith 5640843Smsmithvoid ficlTextOut(FICL_VM *pVM, char *msg, int fNewline) 5740843Smsmith{ 5840843Smsmith IGNORE(pVM); 5940843Smsmith 6040843Smsmith while(*msg != 0) 6140843Smsmith putchar(*(msg++)); 6240843Smsmith if (fNewline) 6340843Smsmith putchar('\n'); 6440843Smsmith 6540843Smsmith return; 6640843Smsmith} 6740843Smsmith 6840843Smsmithvoid *ficlMalloc (size_t size) 6940843Smsmith{ 7040843Smsmith return malloc(size); 7140843Smsmith} 7240843Smsmith 7343078Smsmithvoid *ficlRealloc (void *p, size_t size) 7443078Smsmith{ 7543078Smsmith return realloc(p, size); 7643078Smsmith} 7743078Smsmith 7840843Smsmithvoid ficlFree (void *p) 7940843Smsmith{ 8040843Smsmith free(p); 8140843Smsmith} 8240843Smsmith 8343078Smsmith#ifndef TESTMAIN 8442634Sabial#ifdef __i386__ 8542634Sabial/* 8642679Sabial * outb ( port# c -- ) 8742634Sabial * Store a byte to I/O port number port# 8842634Sabial */ 8942634Sabialvoid 9042679SabialficlOutb(FICL_VM *pVM) 9142634Sabial{ 9242634Sabial u_char c; 9342634Sabial u_int32_t port; 9442634Sabial 9551786Sdcs port=stackPopUNS(pVM->pStack); 9651786Sdcs c=(u_char)stackPopINT(pVM->pStack); 9742634Sabial outb(port,c); 9842634Sabial} 9942634Sabial 10040843Smsmith/* 10142679Sabial * inb ( port# -- c ) 10242634Sabial * Fetch a byte from I/O port number port# 10342634Sabial */ 10442634Sabialvoid 10542679SabialficlInb(FICL_VM *pVM) 10642634Sabial{ 10742634Sabial u_char c; 10842634Sabial u_int32_t port; 10942634Sabial 11051786Sdcs port=stackPopUNS(pVM->pStack); 11142634Sabial c=inb(port); 11251786Sdcs stackPushINT(pVM->pStack,c); 11342634Sabial} 11442634Sabial#endif 11543078Smsmith#endif 11642634Sabial 11742634Sabial/* 11840843Smsmith** Stub function for dictionary access control - does nothing 11940843Smsmith** by default, user can redefine to guarantee exclusive dict 12040843Smsmith** access to a single thread for updates. All dict update code 12140843Smsmith** is guaranteed to be bracketed as follows: 12240843Smsmith** ficlLockDictionary(TRUE); 12340843Smsmith** <code that updates dictionary> 12440843Smsmith** ficlLockDictionary(FALSE); 12540843Smsmith** 12640843Smsmith** Returns zero if successful, nonzero if unable to acquire lock 12740843Smsmith** befor timeout (optional - could also block forever) 12840843Smsmith*/ 12940843Smsmith#if FICL_MULTITHREAD 13040843Smsmithint ficlLockDictionary(short fLock) 13140843Smsmith{ 13240843Smsmith IGNORE(fLock); 13340843Smsmith return 0; 13440843Smsmith} 13540843Smsmith#endif /* FICL_MULTITHREAD */ 13640843Smsmith 13740843Smsmith 138