From f5da975f8fc404dac0769da922ef5dc7b1e4fd58 Mon Sep 17 00:00:00 2001 From: "Daniel C. Sobral" Date: Fri, 8 Sep 2000 17:03:53 +0000 Subject: [PATCH] Add the infrastructure necessary to handle PnP from a Forth script. Also, export the file_findfile() function. Again, this is taken from work in progress but frozen for the time being. Since it works, I'd rather commit and remove any uglyness later than hide it on my tree. --- sys/boot/ficl/ficl.h | 4 ++ sys/boot/ficl/loader.c | 95 ++++++++++++++++++++++++++++++++++++++++++ sys/boot/ficl/words.c | 4 ++ 3 files changed, 103 insertions(+) diff --git a/sys/boot/ficl/ficl.h b/sys/boot/ficl/ficl.h index b78fab2603f..fe041ad80b7 100644 --- a/sys/boot/ficl/ficl.h +++ b/sys/boot/ficl/ficl.h @@ -873,6 +873,10 @@ extern void ficlGetenv(FICL_VM *pVM); extern void ficlUnsetenv(FICL_VM *pVM); extern void ficlCopyin(FICL_VM *pVM); extern void ficlCopyout(FICL_VM *pVM); +extern void ficlFindfile(FICL_VM *pVM); +extern void ficlPnpdevices(FICL_VM *pVM); +extern void ficlPnphandlers(FICL_VM *pVM); +extern void ficlCcall(FICL_VM *pVM); #endif #ifdef __cplusplus diff --git a/sys/boot/ficl/loader.c b/sys/boot/ficl/loader.c index 1444bbcbb4d..34bdb7fee3e 100644 --- a/sys/boot/ficl/loader.c +++ b/sys/boot/ficl/loader.c @@ -45,6 +45,10 @@ * unsetenv ( addr n -- ) * copyin ( addr addr' len -- ) * copyout ( addr addr' len -- ) + * findfile ( name len type len' -- addr ) + * pnpdevices ( -- addr ) + * pnphandlers ( -- addr ) + * ccall ( [[...[p10] p9] ... p1] n addr -- result ) */ void @@ -206,3 +210,94 @@ ficlCopyout(FICL_VM *pVM) return; } +void +ficlFindfile(FICL_VM *pVM) +{ + char *name, *type, *namep, *typep; + struct preloaded_file* fp; + int names, types; + +#if FICL_ROBUST > 1 + vmCheckStack(pVM, 4, 1); +#endif + + types = stackPopINT(pVM->pStack); + typep = (char*) stackPopPtr(pVM->pStack); + names = stackPopINT(pVM->pStack); + namep = (char*) stackPopPtr(pVM->pStack); + name = (char*) ficlMalloc(names+1); + if (!name) + vmThrowErr(pVM, "Error: out of memory"); + strncpy(name, namep, names); + name[names] = '\0'; + type = (char*) ficlMalloc(types+1); + if (!type) + vmThrowErr(pVM, "Error: out of memory"); + strncpy(type, typep, types); + type[types] = '\0'; + + fp = file_findfile(name, type); + stackPushPtr(pVM->pStack, fp); + + return; +} + +void +ficlPnpdevices(FICL_VM *pVM) +{ + static int pnp_devices_initted = 0; +#if FICL_ROBUST > 1 + vmCheckStack(pVM, 0, 1); +#endif + + if(!pnp_devices_initted) { + STAILQ_INIT(&pnp_devices); + pnp_devices_initted = 1; + } + + stackPushPtr(pVM->pStack, &pnp_devices); + + return; +} + +void +ficlPnphandlers(FICL_VM *pVM) +{ +#if FICL_ROBUST > 1 + vmCheckStack(pVM, 0, 1); +#endif + + stackPushPtr(pVM->pStack, pnphandlers); + + return; +} + +void +ficlCcall(FICL_VM *pVM) +{ + int (*func)(int, ...); + int result, p[10]; + int nparam, i; + +#if FICL_ROBUST > 1 + vmCheckStack(pVM, 2, 0); +#endif + + func = stackPopPtr(pVM->pStack); + nparam = stackPopINT(pVM->pStack); + +#if FICL_ROBUST > 1 + vmCheckStack(pVM, nparam, 1); +#endif + + for (i = 0; i < nparam; i++) + p[i] = stackPopINT(pVM->pStack); + + result = func(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], + p[9]); + + stackPushINT(pVM->pStack, result); + + return; +} + diff --git a/sys/boot/ficl/words.c b/sys/boot/ficl/words.c index 621a3f7ffaa..0136610354d 100644 --- a/sys/boot/ficl/words.c +++ b/sys/boot/ficl/words.c @@ -4832,6 +4832,10 @@ void ficlCompileCore(FICL_DICT *dp) dictAppendWord(dp, "unsetenv", ficlUnsetenv, FW_DEFAULT); dictAppendWord(dp, "copyin", ficlCopyin, FW_DEFAULT); dictAppendWord(dp, "copyout", ficlCopyout, FW_DEFAULT); + dictAppendWord(dp, "findfile", ficlFindfile, FW_DEFAULT); + dictAppendWord(dp, "pnpdevices",ficlPnpdevices, FW_DEFAULT); + dictAppendWord(dp, "pnphandlers",ficlPnphandlers, FW_DEFAULT); + dictAppendWord(dp, "ccall", ficlCcall, FW_DEFAULT); #endif #if defined(__i386__) -- 2.45.2