sysdep.c revision 256281
1100513Sru/*******************************************************************
242660Smarkm** s y s d e p . c
393139Sru** Forth Inspired Command Language
493139Sru** Author: John Sadler (john_sadler@alum.mit.edu)
593139Sru** Created: 16 Oct 1997
642660Smarkm** Implementations of FICL external interface functions...
742660Smarkm**
8100513Sru*******************************************************************/
993139Sru
1093139Sru/* $FreeBSD: stable/10/sys/boot/ficl/arm/sysdep.c 161454 2006-08-18 21:41:43Z imp $ */
1193139Sru
1293139Sru#ifdef TESTMAIN
1393139Sru#include <stdio.h>
1493139Sru#include <stdlib.h>
15100513Sru#else
1693139Sru#include <stand.h>
1793139Sru#endif
18100513Sru#include "ficl.h"
1942660Smarkm
2042660Smarkm/*
21100513Sru*******************  FreeBSD  P O R T   B E G I N S   H E R E ******************** Michael Smith
22100513Sru*/
2342660Smarkm
2442660Smarkm#if PORTABLE_LONGMULDIV == 0
25100513SruDPUNS ficlLongMul(FICL_UNS x, FICL_UNS y)
2693139Sru{
2742660Smarkm    DPUNS q;
28100513Sru    u_int64_t qx;
2993139Sru
3042660Smarkm    qx = (u_int64_t)x * (u_int64_t) y;
3193139Sru
3293139Sru    q.hi = (u_int32_t)( qx >> 32 );
3393139Sru    q.lo = (u_int32_t)( qx & 0xFFFFFFFFL);
3456160Sru
35114472Sru    return q;
36114472Sru}
37114472Sru
38114472SruUNSQR ficlLongDiv(DPUNS q, FICL_UNS y)
3993139Sru{
4093139Sru    UNSQR result;
4142660Smarkm    u_int64_t qx, qh;
4293139Sru
4393139Sru    qh = q.hi;
4442660Smarkm    qx = (qh << 32) | q.lo;
4593139Sru
4693139Sru    result.quot = qx / y;
4742660Smarkm    result.rem  = qx % y;
4893139Sru
4993139Sru    return result;
5042660Smarkm}
51100513Sru#endif
5293139Sru
5342660Smarkmvoid  ficlTextOut(FICL_VM *pVM, char *msg, int fNewline)
54100513Sru{
5593139Sru    IGNORE(pVM);
5642660Smarkm
57100513Sru    while(*msg != 0)
5893139Sru	putchar(*(msg++));
5942660Smarkm    if (fNewline)
60100513Sru	putchar('\n');
6193139Sru
6242660Smarkm   return;
63100513Sru}
6493139Sru
6542660Smarkmvoid *ficlMalloc (size_t size)
66100513Sru{
6793139Sru    return malloc(size);
6842660Smarkm}
69100513Sru
7093139Sruvoid *ficlRealloc (void *p, size_t size)
7156160Sru{
72100513Sru    return realloc(p, size);
7393139Sru}
7442660Smarkm
75100513Sruvoid  ficlFree   (void *p)
7693139Sru{
7742660Smarkm    free(p);
78100513Sru}
7993139Sru
8042660Smarkm
8193139Sru/*
8242660Smarkm** Stub function for dictionary access control - does nothing
8342660Smarkm** by default, user can redefine to guarantee exclusive dict
84114472Sru** access to a single thread for updates. All dict update code
85114472Sru** is guaranteed to be bracketed as follows:
86114472Sru** ficlLockDictionary(TRUE);
87100513Sru** <code that updates dictionary>
8893139Sru** ficlLockDictionary(FALSE);
8942660Smarkm**
9093139Sru** Returns zero if successful, nonzero if unable to acquire lock
9193139Sru** befor timeout (optional - could also block forever)
9242660Smarkm*/
93114472Sru#if FICL_MULTITHREAD
9493139Sruint ficlLockDictionary(short fLock)
9542660Smarkm{
96114472Sru	IGNORE(fLock);
97114472Sru	return 0;
98114472Sru}
99114472Sru#endif /* FICL_MULTITHREAD */
100100513Sru
10193139Sru
10242660Smarkm