Index: sys/boot/common/bootstrap.h =================================================================== --- sys/boot/common/bootstrap.h +++ sys/boot/common/bootstrap.h @@ -142,8 +142,6 @@ STAILQ_HEAD(pnpinfo_stql, pnpinfo); -extern struct pnpinfo_stql pnp_devices; - extern struct pnphandler *pnphandlers[]; /* provided by MD code */ void pnp_addident(struct pnpinfo *pi, char *ident); Index: sys/boot/common/pnp.c =================================================================== --- sys/boot/common/pnp.c +++ sys/boot/common/pnp.c @@ -17,8 +17,9 @@ #include #include #include +#include "ficl.h" -struct pnpinfo_stql pnp_devices; +static struct pnpinfo_stql pnp_devices; static int pnp_devices_initted = 0; static void pnp_discard(void); @@ -185,3 +186,47 @@ return(idbuf); } +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; +} + +/* + * Glue function to add the appropriate forth words to access pnp BIOS + * functionality. + */ +static void ficlCompilePnp(FICL_SYSTEM *pSys) +{ + FICL_DICT *dp = pSys->dp; + assert (dp); + + dictAppendWord(dp, "pnpdevices",ficlPnpdevices, FW_DEFAULT); + dictAppendWord(dp, "pnphandlers",ficlPnphandlers, FW_DEFAULT); +} + +FICL_COMPILE_SET(ficlCompilePnp); Index: sys/boot/efi/loader/Makefile =================================================================== --- sys/boot/efi/loader/Makefile +++ sys/boot/efi/loader/Makefile @@ -143,6 +143,7 @@ ${OBJCOPY} -j .peheader -j .text -j .sdata -j .data \ -j .dynamic -j .dynsym -j .rel.dyn \ -j .rela.dyn -j .reloc -j .eh_frame -j set_Xcommand_set \ + -j set_Xficl_compile_set \ --output-target=${EFI_TARGET} ${.ALLSRC} ${.TARGET} LIBEFI= ${.OBJDIR}/../libefi/libefi.a Index: sys/boot/efi/loader/arch/amd64/ldscript.amd64 =================================================================== --- sys/boot/efi/loader/arch/amd64/ldscript.amd64 +++ sys/boot/efi/loader/arch/amd64/ldscript.amd64 @@ -40,6 +40,11 @@ *(set_Xcommand_set) __stop_set_Xcommand_set = .; } + set_Xficl_compile_set : { + __start_set_Xficl_compile_set = .; + *(set_Xficl_compile_set) + __stop_set_Xficl_compile_set = .; + } . = ALIGN(4096); __gp = .; .sdata : { Index: sys/boot/efi/loader/arch/arm/ldscript.arm =================================================================== --- sys/boot/efi/loader/arch/arm/ldscript.arm +++ sys/boot/efi/loader/arch/arm/ldscript.arm @@ -47,6 +47,11 @@ *(set_Xcommand_set) __stop_set_Xcommand_set = .; } + set_Xficl_compile_set : { + __start_set_Xficl_compile_set = .; + *(set_Xficl_compile_set) + __stop_set_Xficl_compile_set = .; + } __gp = .; .plt : { *(.plt) } .dynamic : { *(.dynamic) } Index: sys/boot/efi/loader/arch/arm64/ldscript.arm64 =================================================================== --- sys/boot/efi/loader/arch/arm64/ldscript.arm64 +++ sys/boot/efi/loader/arch/arm64/ldscript.arm64 @@ -43,6 +43,11 @@ *(set_Xcommand_set) __stop_set_Xcommand_set = .; } + set_Xficl_compile_set : { + __start_set_Xficl_compile_set = .; + *(set_Xficl_compile_set) + __stop_set_Xficl_compile_set = .; + } . = ALIGN(16); __gp = .; .sdata : { Index: sys/boot/efi/loader/arch/i386/ldscript.i386 =================================================================== --- sys/boot/efi/loader/arch/i386/ldscript.i386 +++ sys/boot/efi/loader/arch/i386/ldscript.i386 @@ -35,6 +35,11 @@ *(set_Xcommand_set) __stop_set_Xcommand_set = .; } + set_Xficl_compile_set : { + __start_set_Xficl_compile_set = .; + *(set_Xficl_compile_set) + __stop_set_Xficl_compile_set = .; + } . = ALIGN(4096); __gp = .; .sdata : { Index: sys/boot/ficl/ficl.h =================================================================== --- sys/boot/ficl/ficl.h +++ sys/boot/ficl/ficl.h @@ -1150,6 +1150,13 @@ } ficlFILE; #endif +#include + +typedef void ficlCompileFcn(FICL_SYSTEM *); +#define FICL_COMPILE_SET(func) \ + DATA_SET(Xficl_compile_set, func) +SET_DECLARE(Xficl_compile_set, ficlCompileFcn); + #ifdef __cplusplus } #endif Index: sys/boot/ficl/i386/sysdep.c =================================================================== --- sys/boot/ficl/i386/sysdep.c +++ sys/boot/ficl/i386/sysdep.c @@ -81,7 +81,6 @@ } #ifndef TESTMAIN -#ifdef __i386__ /* * outb ( port# c -- ) * Store a byte to I/O port number port# @@ -111,7 +110,22 @@ c=inb(port); stackPushINT(pVM->pStack,c); } -#endif + +/* + * Glue function to add the appropriate forth words to access x86 special cpu + * functionality. + */ +static void ficlCompileCpufunc(FICL_SYSTEM *pSys) +{ + FICL_DICT *dp = pSys->dp; + assert (dp); + + dictAppendWord(dp, "outb", ficlOutb, FW_DEFAULT); + dictAppendWord(dp, "inb", ficlInb, FW_DEFAULT); +} + +FICL_COMPILE_SET(ficlCompileCpufunc); + #endif /* Index: sys/boot/ficl/loader.c =================================================================== --- sys/boot/ficl/loader.c +++ sys/boot/ficl/loader.c @@ -287,43 +287,6 @@ return; } -#ifndef TESTMAIN -#ifdef HAVE_PNP - -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; -} - -#endif - -#endif /* ndef TESTMAIN */ - void ficlCcall(FICL_VM *pVM) { @@ -800,141 +763,6 @@ } -#ifdef __i386__ -/* - * pcibios-device-count (devid -- count) - * - * Returns the PCI BIOS' count of how many devices matching devid are in the system. - * devid is the 32-bit vendor + device. - */ -static void -ficlPciBiosCountDevices(FICL_VM *pVM) -{ - uint32_t devid; - int i; - - devid = stackPopINT(pVM->pStack); - - i = biospci_count_device_type(devid); - - stackPushINT(pVM->pStack, i); -} - -/* - * pcibios-write-config (locator offset width value -- ) - * - * Writes the specified config register. - * Locator is bus << 8 | device << 3 | fuction - * offset is the pci config register - * width is 0 for byte, 1 for word, 2 for dword - * value is the value to write - */ -static void -ficlPciBiosWriteConfig(FICL_VM *pVM) -{ - uint32_t value, width, offset, locator; - - value = stackPopINT(pVM->pStack); - width = stackPopINT(pVM->pStack); - offset = stackPopINT(pVM->pStack); - locator = stackPopINT(pVM->pStack); - - biospci_write_config(locator, offset, width, value); -} - -/* - * pcibios-read-config (locator offset width -- value) - * - * Reads the specified config register. - * Locator is bus << 8 | device << 3 | fuction - * offset is the pci config register - * width is 0 for byte, 1 for word, 2 for dword - * value is the value to read from the register - */ -static void -ficlPciBiosReadConfig(FICL_VM *pVM) -{ - uint32_t value, width, offset, locator; - - width = stackPopINT(pVM->pStack); - offset = stackPopINT(pVM->pStack); - locator = stackPopINT(pVM->pStack); - - biospci_read_config(locator, offset, width, &value); - - stackPushINT(pVM->pStack, value); -} - -/* - * pcibios-find-devclass (class index -- locator) - * - * Finds the index'th instance of class in the pci tree. - * must be an exact match. - * class is the class to search for. - * index 0..N (set to 0, increment until error) - * - * Locator is bus << 8 | device << 3 | fuction (or -1 on error) - */ -static void -ficlPciBiosFindDevclass(FICL_VM *pVM) -{ - uint32_t index, class, locator; - - index = stackPopINT(pVM->pStack); - class = stackPopINT(pVM->pStack); - - if (biospci_find_devclass(class, index, &locator)) - locator = 0xffffffff; - - stackPushINT(pVM->pStack, locator); -} - -/* - * pcibios-find-device(devid index -- locator) - * - * Finds the index'th instance of devid in the pci tree. - * must be an exact match. - * class is the class to search for. - * index 0..N (set to 0, increment until error) - * - * Locator is bus << 8 | device << 3 | fuction (or -1 on error) - */ -static void -ficlPciBiosFindDevice(FICL_VM *pVM) -{ - uint32_t index, devid, locator; - - index = stackPopINT(pVM->pStack); - devid = stackPopINT(pVM->pStack); - - if (biospci_find_device(devid, index, &locator)) - locator = 0xffffffff; - - stackPushINT(pVM->pStack, locator); -} - -/* - * pcibios-find-device(bus device function -- locator) - * - * converts bus, device, function to locator. - * - * Locator is bus << 8 | device << 3 | fuction - */ -static void -ficlPciBiosLocator(FICL_VM *pVM) -{ - uint32_t bus, device, function, locator; - - function = stackPopINT(pVM->pStack); - device = stackPopINT(pVM->pStack); - bus = stackPopINT(pVM->pStack); - - locator = biospci_locator(bus, device, function); - - stackPushINT(pVM->pStack, locator); -} -#endif - /* ** Retrieves free space remaining on the dictionary */ @@ -963,6 +791,7 @@ **************************************************************************/ void ficlCompilePlatform(FICL_SYSTEM *pSys) { + ficlCompileFcn **fnpp; FICL_DICT *dp = pSys->dp; assert (dp); @@ -994,24 +823,10 @@ dictAppendWord(dp, "ccall", ficlCcall, FW_DEFAULT); dictAppendWord(dp, "uuid-from-string", ficlUuidFromString, FW_DEFAULT); dictAppendWord(dp, "uuid-to-string", ficlUuidToString, FW_DEFAULT); -#ifndef TESTMAIN -#ifdef __i386__ - dictAppendWord(dp, "outb", ficlOutb, FW_DEFAULT); - dictAppendWord(dp, "inb", ficlInb, FW_DEFAULT); -#endif -#ifdef HAVE_PNP - dictAppendWord(dp, "pnpdevices",ficlPnpdevices, FW_DEFAULT); - dictAppendWord(dp, "pnphandlers",ficlPnphandlers, FW_DEFAULT); -#endif -#endif -#ifdef __i386__ - dictAppendWord(dp, "pcibios-device-count", ficlPciBiosCountDevices, FW_DEFAULT); - dictAppendWord(dp, "pcibios-read-config", ficlPciBiosReadConfig, FW_DEFAULT); - dictAppendWord(dp, "pcibios-write-config", ficlPciBiosWriteConfig, FW_DEFAULT); - dictAppendWord(dp, "pcibios-find-devclass", ficlPciBiosFindDevclass, FW_DEFAULT); - dictAppendWord(dp, "pcibios-find-device", ficlPciBiosFindDevice, FW_DEFAULT); - dictAppendWord(dp, "pcibios-locator", ficlPciBiosLocator, FW_DEFAULT); -#endif + + SET_FOREACH(fnpp, Xficl_compile_set) { + (*fnpp)(pSys); + } #if defined(PC98) ficlSetEnv(pSys, "arch-pc98", FICL_TRUE); Index: sys/boot/i386/libi386/Makefile =================================================================== --- sys/boot/i386/libi386/Makefile +++ sys/boot/i386/libi386/Makefile @@ -54,7 +54,8 @@ # XXX: make alloca() useable CFLAGS+= -Dalloca=__builtin_alloca -CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}/../common \ +CFLAGS+= -I${.CURDIR}/../../ficl -I${.CURDIR}/../../ficl/i386 \ + -I${.CURDIR}/../../common -I${.CURDIR}/../common \ -I${.CURDIR}/../btx/lib \ -I${.CURDIR}/../../../contrib/dev/acpica/include \ -I${.CURDIR}/../../.. -I. Index: sys/boot/i386/libi386/biospci.c =================================================================== --- sys/boot/i386/libi386/biospci.c +++ sys/boot/i386/libi386/biospci.c @@ -1,5 +1,6 @@ /*- * Copyright (c) 1998 Michael Smith + * Copyright (c) 2016 Netflix, Inc * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,6 +38,7 @@ #include #include #include "libi386.h" +#include "ficl.h" /* * Stupid PCI BIOS interface doesn't let you simply enumerate everything @@ -338,7 +340,7 @@ return (0); } -int +static int biospci_find_device(uint32_t devid, int index, uint32_t *locator) { v86.ctl = V86_FLAGS; @@ -407,7 +409,7 @@ * Counts the number of instances of devid we have in the system, as least as * far as the PCI BIOS is able to tell. */ -int +static int biospci_count_device_type(uint32_t devid) { int i; @@ -426,3 +428,155 @@ } return i; } + +/* + * pcibios-device-count (devid -- count) + * + * Returns the PCI BIOS' count of how many devices matching devid are in the system. + * devid is the 32-bit vendor + device. + */ +static void +ficlPciBiosCountDevices(FICL_VM *pVM) +{ + uint32_t devid; + int i; + + devid = stackPopINT(pVM->pStack); + + i = biospci_count_device_type(devid); + + stackPushINT(pVM->pStack, i); +} + +/* + * pcibios-write-config (locator offset width value -- ) + * + * Writes the specified config register. + * Locator is bus << 8 | device << 3 | fuction + * offset is the pci config register + * width is 0 for byte, 1 for word, 2 for dword + * value is the value to write + */ +static void +ficlPciBiosWriteConfig(FICL_VM *pVM) +{ + uint32_t value, width, offset, locator; + + value = stackPopINT(pVM->pStack); + width = stackPopINT(pVM->pStack); + offset = stackPopINT(pVM->pStack); + locator = stackPopINT(pVM->pStack); + + biospci_write_config(locator, offset, width, value); +} + +/* + * pcibios-read-config (locator offset width -- value) + * + * Reads the specified config register. + * Locator is bus << 8 | device << 3 | fuction + * offset is the pci config register + * width is 0 for byte, 1 for word, 2 for dword + * value is the value to read from the register + */ +static void +ficlPciBiosReadConfig(FICL_VM *pVM) +{ + uint32_t value, width, offset, locator; + + width = stackPopINT(pVM->pStack); + offset = stackPopINT(pVM->pStack); + locator = stackPopINT(pVM->pStack); + + biospci_read_config(locator, offset, width, &value); + + stackPushINT(pVM->pStack, value); +} + +/* + * pcibios-find-devclass (class index -- locator) + * + * Finds the index'th instance of class in the pci tree. + * must be an exact match. + * class is the class to search for. + * index 0..N (set to 0, increment until error) + * + * Locator is bus << 8 | device << 3 | fuction (or -1 on error) + */ +static void +ficlPciBiosFindDevclass(FICL_VM *pVM) +{ + uint32_t index, class, locator; + + index = stackPopINT(pVM->pStack); + class = stackPopINT(pVM->pStack); + + if (biospci_find_devclass(class, index, &locator)) + locator = 0xffffffff; + + stackPushINT(pVM->pStack, locator); +} + +/* + * pcibios-find-device(devid index -- locator) + * + * Finds the index'th instance of devid in the pci tree. + * must be an exact match. + * class is the class to search for. + * index 0..N (set to 0, increment until error) + * + * Locator is bus << 8 | device << 3 | fuction (or -1 on error) + */ +static void +ficlPciBiosFindDevice(FICL_VM *pVM) +{ + uint32_t index, devid, locator; + + index = stackPopINT(pVM->pStack); + devid = stackPopINT(pVM->pStack); + + if (biospci_find_device(devid, index, &locator)) + locator = 0xffffffff; + + stackPushINT(pVM->pStack, locator); +} + +/* + * pcibios-find-device(bus device function -- locator) + * + * converts bus, device, function to locator. + * + * Locator is bus << 8 | device << 3 | fuction + */ +static void +ficlPciBiosLocator(FICL_VM *pVM) +{ + uint32_t bus, device, function, locator; + + function = stackPopINT(pVM->pStack); + device = stackPopINT(pVM->pStack); + bus = stackPopINT(pVM->pStack); + + locator = biospci_locator(bus, device, function); + + stackPushINT(pVM->pStack, locator); +} + +/* + * Glue function to add the appropriate forth words to access pci bios + * functionality. + */ +static void ficlCompilePciBios(FICL_SYSTEM *pSys) +{ + FICL_DICT *dp = pSys->dp; + assert (dp); + + dictAppendWord(dp, "pcibios-device-count", ficlPciBiosCountDevices, FW_DEFAULT); + dictAppendWord(dp, "pcibios-read-config", ficlPciBiosReadConfig, FW_DEFAULT); + dictAppendWord(dp, "pcibios-write-config", ficlPciBiosWriteConfig, FW_DEFAULT); + dictAppendWord(dp, "pcibios-find-devclass", ficlPciBiosFindDevclass, FW_DEFAULT); + dictAppendWord(dp, "pcibios-find-device", ficlPciBiosFindDevice, FW_DEFAULT); + dictAppendWord(dp, "pcibios-locator", ficlPciBiosLocator, FW_DEFAULT); +} + +FICL_COMPILE_SET(ficlCompilePciBios); Index: sys/boot/i386/libi386/libi386.h =================================================================== --- sys/boot/i386/libi386/libi386.h +++ sys/boot/i386/libi386/libi386.h @@ -104,12 +104,10 @@ extern vm_offset_t high_heap_base; /* for use as the heap */ void biospci_detect(void); -int biospci_count_device_type(uint32_t devid); -int biospci_find_devclass(uint32_t class, int index, uint32_t *locator); -int biospci_find_device(uint32_t devid, int index, uint32_t *locator); -int biospci_write_config(uint32_t locator, int offset, int width, uint32_t val); -int biospci_read_config(uint32_t locator, int offset, int width, uint32_t *val); +int biospci_find_devclass(uint32_t class, int index, uint32_t *locator); +int biospci_read_config(uint32_t locator, int offset, int width, uint32_t *val); uint32_t biospci_locator(int8_t bus, uint8_t device, uint8_t function); +int biospci_write_config(uint32_t locator, int offset, int width, uint32_t val); void biosacpi_detect(void); Index: sys/boot/mips/beri/loader/loader.ldscript =================================================================== --- sys/boot/mips/beri/loader/loader.ldscript +++ sys/boot/mips/beri/loader/loader.ldscript @@ -65,6 +65,10 @@ __start_set_Xcommand_set = .; KEEP(*(set_Xcommand_set)) __stop_set_Xcommand_set = .; + + __start_set_Xficl_compile_set = .; + KEEP(*(set_Xficl_compile_set)) + __stop_set_Xficl_compile_set = .; } .data ALIGN(0x10): { *(.data*)} .bss ALIGN(0x10): { *(.bss*) } Index: sys/boot/pc98/libpc98/Makefile =================================================================== --- sys/boot/pc98/libpc98/Makefile +++ sys/boot/pc98/libpc98/Makefile @@ -37,7 +37,8 @@ # XXX: make alloca() useable CFLAGS+= -Dalloca=__builtin_alloca -CFLAGS+= -I${.CURDIR}/../../common \ +CFLAGS+= -I${.CURDIR}/../../ficl -I${.CURDIR}/../../ficl/i386 \ + -I${.CURDIR}/../../common \ -I${.CURDIR}/../btx/lib \ -I${.CURDIR}/../../i386/libi386 \ -I${.CURDIR}/../../.. -I.