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