afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Copyright (c) 2000 Daniel Capo Sobral
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * All rights reserved.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Redistribution and use in source and binary forms, with or without
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * modification, are permitted provided that the following conditions
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * 1. Redistributions of source code must retain the above copyright
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * notice, this list of conditions and the following disclaimer.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * notice, this list of conditions and the following disclaimer in the
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * documentation and/or other materials provided with the distribution.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * SUCH DAMAGE.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * l o a d e r . c
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Additional FICL words designed for FreeBSD's loader
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soomeextern int biospci_write_config(uint32_t, int, int, uint32_t);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soomeextern int biospci_read_config(uint32_t, int, int, uint32_t *);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soomeextern int biospci_find_devclass(uint32_t, int, uint32_t *);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soomeextern int biospci_find_device(uint32_t, int, uint32_t *);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soomeextern uint32_t biospci_locator(uint8_t, uint8_t, uint8_t);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * FreeBSD's loader interaction words and extras
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * setenv ( value n name n' -- )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * setenv? ( value n name n' flag -- )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * getenv ( addr n -- addr' n' | -1 )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * unsetenv ( addr n -- )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * copyin ( addr addr' len -- )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * copyout ( addr addr' len -- )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * findfile ( name len type len' -- addr )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * pnpdevices ( -- addr )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * pnphandlers ( -- addr )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * ccall ( [[...[p10] p9] ... p1] n addr -- result )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * .# ( value -- )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 4, 0);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome names = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome namep = (char *)ficlStackPopPointer(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome values = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome valuep = (char *)ficlStackPopPointer(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 5, 0);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome overwrite = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome names = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome namep = (char *)ficlStackPopPointer(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome values = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome valuep = (char *)ficlStackPopPointer(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 2, 2);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome names = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome namep = (char *)ficlStackPopPointer(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushPointer(ficlVmGetDataStack(pVM), value);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), strlen(value));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), -1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 2, 0);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome names = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome namep = (char *)ficlStackPopPointer(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 3, 0);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome len = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome dest = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome src = ficlStackPopPointer(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome (void) ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome (void) ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome (void) ficlStackPopPointer(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 3, 0);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome len = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome dest = ficlStackPopPointer(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome src = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome (void) ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome (void) ficlStackPopPointer(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome (void) ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 4, 1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome types = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome typep = (char *)ficlStackPopPointer(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome names = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome namep = (char *)ficlStackPopPointer(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome (void) ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome (void) ficlStackPopPointer(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome (void) ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome (void) ficlStackPopPointer(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushPointer(ficlVmGetDataStack(pVM), fp);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 0, 1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushPointer(ficlVmGetDataStack(pVM), &pnp_devices);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 0, 1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushPointer(ficlVmGetDataStack(pVM), pnphandlers);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome#endif /* ifdef STAND */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome int (*func)(int, ...);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 2, 0);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome func = (int (*)(int, ...))ficlStackPopPointer(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome nparam = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), nparam, 1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome for (i = 0; i < nparam; i++)
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome p[i] = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome result = func(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8],
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), result);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * f i c l E x e c F D
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * reads in text from file fd and passes it to ficlExec()
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * returns FICL_VM_STATUS_OUT_OF_TEXT on success or the ficlExec() error
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * code on failure.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome int nLine = 0, rval = FICL_VM_STATUS_OUT_OF_TEXT;
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome pVM->sourceId.i = fd+1; /* in loader we can get 0, there is no stdin */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome /* feed each line to ficlExec */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome while ((status = read(fd, &ch, 1)) > 0 && ch != '\n')
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Pass an empty line with SOURCE-ID == -1 to flush
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * any pending REFILLs (as required by FILE wordset)
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 1, 0);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * isdir? - Return whether an fd corresponds to a directory.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * isdir? ( fd -- bool )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 1, 1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome fd = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome } while (0);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), flag);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * fopen - open a file and return new fd on stack.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * fopen ( ptr count mode -- fd )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soomeextern char *get_dev(const char *);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 3, 1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome mode = ficlStackPopInteger(ficlVmGetDataStack(pVM)); /* get mode */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome count = ficlStackPopInteger(ficlVmGetDataStack(pVM)); /* get count */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ptr = ficlStackPopPointer(ficlVmGetDataStack(pVM)); /* get ptr */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), -1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome /* ensure that the string is null terminated */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome /* open the file */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), fd);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * fclose - close a file who's fd is on stack.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * fclose ( fd -- )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 1, 0);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome fd = ficlStackPopInteger(ficlVmGetDataStack(pVM)); /* get fd */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * fread - read file contents
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * fread ( fd buf nbytes -- nread )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 3, 1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome len = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome buf = ficlStackPopPointer(ficlVmGetDataStack(pVM)); /* get buffer */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome fd = ficlStackPopInteger(ficlVmGetDataStack(pVM)); /* get fd */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), -1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * fopendir - open directory
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * fopendir ( addr len -- ptr TRUE | FALSE )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 2, 1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome count = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ptr = ficlStackPopPointer(ficlVmGetDataStack(pVM)); /* get ptr */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), -1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome /* ensure that the string is null terminated */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), fd);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), flag);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome } while (0);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), flag);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), flag);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushPointer(ficlVmGetDataStack(pVM), dir);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), flag);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * freaddir - read directory contents
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * freaddir ( fd -- ptr len TRUE | FALSE )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 1, 3);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * libstand readdir does not always return . nor .. so filter
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * them out to have consistent behaviour.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome dir = ficlStackPopPointer(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome } while (d != NULL);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome fd = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome } while (d != NULL);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushPointer(ficlVmGetDataStack(pVM), d->d_name);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), FICL_TRUE);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), FICL_FALSE);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * fclosedir - close a dir on stack.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * fclosedir ( fd -- )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 1, 0);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome dir = ficlStackPopPointer(ficlVmGetDataStack(pVM)); /* get dir */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome fd = ficlStackPopInteger(ficlVmGetDataStack(pVM)); /* get fd */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * fload - interpret file contents
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * fload ( fd -- )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 1, 0);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome fd = ficlStackPopInteger(ficlVmGetDataStack(pVM)); /* get fd */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * fwrite - write file contents
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * fwrite ( fd buf nbytes -- nwritten )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 3, 1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome len = ficlStackPopInteger(ficlVmGetDataStack(pVM)); /* bytes to read */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome buf = ficlStackPopPointer(ficlVmGetDataStack(pVM)); /* get buffer */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome fd = ficlStackPopInteger(ficlVmGetDataStack(pVM)); /* get fd */
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), -1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * fseek - seek to a new position in a file
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * fseek ( fd ofs whence -- pos )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 3, 1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome whence = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome pos = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome fd = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), lseek(fd, pos, whence));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * key - get a character from stdin
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * key ( -- char )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 0, 1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), getchar());
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * key? - check for a character from stdin (FACILITY)
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * key? ( -- flag )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 0, 1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * seconds - gives number of seconds since beginning of time
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * beginning of time is defined as:
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * BTX - number of seconds since midnight
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * FreeBSD - number of seconds since Jan 1 1970
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * seconds ( -- u )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 0, 1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * ms - wait at least that many milliseconds (FACILITY)
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * ms ( u -- )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 1, 0);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome usleep(ficlStackPopUnsigned(ficlVmGetDataStack(pVM)) * 1000);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome delay(ficlStackPopUnsigned(ficlVmGetDataStack(pVM)) * 1000);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * fkey - get a character from a file
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * fkey ( file -- char )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 1, 1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome fd = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), i > 0 ? ch : -1);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * outb ( port# c -- )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Store a byte to I/O port number port#
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome port = ficlStackPopUnsigned(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome c = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * inb ( port# -- c )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Fetch a byte from I/O port number port#
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome port = ficlStackPopUnsigned(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), c);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * pcibios-device-count (devid -- count)
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Returns the PCI BIOS' count of how many devices matching devid are
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * in the system. devid is the 32-bit vendor + device.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome devid = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), i);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * pcibios-write-config (locator offset width value -- )
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Writes the specified config register.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Locator is bus << 8 | device << 3 | fuction
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * offset is the pci config register
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * width is 0 for byte, 1 for word, 2 for dword
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * value is the value to write
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome value = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome width = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome offset = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome locator = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome biospci_write_config(locator, offset, width, value);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * pcibios-read-config (locator offset width -- value)
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Reads the specified config register.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Locator is bus << 8 | device << 3 | fuction
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * offset is the pci config register
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * width is 0 for byte, 1 for word, 2 for dword
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * value is the value to read from the register
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome width = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome offset = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome locator = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome biospci_read_config(locator, offset, width, &value);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), value);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * pcibios-find-devclass (class index -- locator)
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Finds the index'th instance of class in the pci tree.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * must be an exact match.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * class is the class to search for.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * index 0..N (set to 0, increment until error)
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Locator is bus << 8 | device << 3 | fuction (or -1 on error)
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome index = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome class = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome if (biospci_find_devclass(class, index, &locator))
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), locator);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * pcibios-find-device(devid index -- locator)
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Finds the index'th instance of devid in the pci tree.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * must be an exact match.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * class is the class to search for.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * index 0..N (set to 0, increment until error)
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Locator is bus << 8 | device << 3 | fuction (or -1 on error)
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome index = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome devid = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome if (biospci_find_device(devid, index, &locator))
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), locator);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * pcibios-find-device(bus device function -- locator)
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * converts bus, device, function to locator.
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Locator is bus << 8 | device << 3 | fuction
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome function = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome device = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome bus = ficlStackPopInteger(ficlVmGetDataStack(pVM));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome locator = biospci_locator(bus, device, function);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlStackPushInteger(ficlVmGetDataStack(pVM), locator);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Retrieves free space remaining on the dictionary
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionaryCellsAvailable(ficlVmGetDictionary(pVM)));
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * f i c l C o m p i l e P l a t f o r m
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome * Build FreeBSD platform extensions into the system dictionary
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionary *dp = ficlSystemGetDictionary(pSys);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionary *env = ficlSystemGetEnvironment(pSys);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, ".#", displayCellNoPad,
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "isdir?", isdirQuestion,
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "fopen", pfopen, FICL_WORD_DEFAULT);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "fclose", pfclose, FICL_WORD_DEFAULT);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "fread", pfread, FICL_WORD_DEFAULT);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "fopendir", pfopendir,
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "freaddir", pfreaddir,
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "fclosedir", pfclosedir,
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "fload", pfload, FICL_WORD_DEFAULT);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "fkey", fkey, FICL_WORD_DEFAULT);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "fseek", pfseek, FICL_WORD_DEFAULT);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "fwrite", pfwrite, FICL_WORD_DEFAULT);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "key", key, FICL_WORD_DEFAULT);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "key?", keyQuestion, FICL_WORD_DEFAULT);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "ms", ms, FICL_WORD_DEFAULT);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "seconds", pseconds, FICL_WORD_DEFAULT);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "heap?", freeHeap, FICL_WORD_DEFAULT);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "setenv", ficlSetenv, FICL_WORD_DEFAULT);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "setenv?", ficlSetenvq,
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "getenv", ficlGetenv, FICL_WORD_DEFAULT);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "unsetenv", ficlUnsetenv,
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "copyin", ficlCopyin, FICL_WORD_DEFAULT);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "copyout", ficlCopyout,
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "findfile", ficlFindfile,
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "ccall", ficlCcall, FICL_WORD_DEFAULT);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "outb", ficlOutb, FICL_WORD_DEFAULT);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "inb", ficlInb, FICL_WORD_DEFAULT);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "pnpdevices", ficlPnpdevices,
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "pnphandlers", ficlPnphandlers,
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "pcibios-device-count",
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "pcibios-read-config",
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "pcibios-write-config",
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "pcibios-find-devclass",
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "pcibios-find-device",
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetPrimitive(dp, "pcibios-locator", ficlPciBiosLocator,
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetConstant(env, "arch-i386", FICL_TRUE);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetConstant(env, "arch-sparc", FICL_FALSE);
afc2ba1deb75b323afde536f2dd18bcafdaa308dToomas Soome ficlDictionarySetConstant(env, "arch-i386", FICL_FALSE);