mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-12-01 21:33:04 +00:00
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.
This commit is contained in:
parent
d39b220c77
commit
f5da975f8f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=65617
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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__)
|
||||
|
Loading…
Reference in New Issue
Block a user