1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-22 11:17:19 +00:00

Create a new linker set, Xficl_compile_set which contains a list of

functions to call at the appropriate time to register new forth
words. In the past we've done this with ifdef soup, but now if the
file is included in the build, we'll get the new forth words.

Use this new functionality to move the pci bios stuff out of loader.c
by moving it to biospci.c.

Move the pnp functionality to common/pnp.c.

Move the inb/outb forth words to the i386 sysdep.c file where their
implementation is defined.

Adjust the efi linker scripts and build machinery to cope.

his should be an invisible change to forth scripts and user
experience.

Differential Revision: https://reviews.freebsd.org/D8145
This commit is contained in:
Warner Losh 2016-10-14 16:23:12 +00:00
parent f36f940494
commit a2cb5fddcd
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=307324
15 changed files with 262 additions and 204 deletions

View File

@ -142,8 +142,6 @@ struct pnpinfo
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);

View File

@ -17,8 +17,9 @@ __FBSDID("$FreeBSD$");
#include <stand.h>
#include <string.h>
#include <bootstrap.h>
#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 @@ pnp_eisaformat(u_int8_t *data)
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);

View File

@ -145,6 +145,7 @@ loader.efi: ${PROG}
${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

View File

@ -40,6 +40,11 @@ SECTIONS
*(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 : {

View File

@ -47,6 +47,11 @@ SECTIONS
*(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) }

View File

@ -43,6 +43,11 @@ SECTIONS
*(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 : {

View File

@ -35,6 +35,11 @@ SECTIONS
*(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 : {

View File

@ -1150,6 +1150,13 @@ typedef struct ficlFILE
} ficlFILE;
#endif
#include <sys/linker_set.h>
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

View File

@ -81,7 +81,6 @@ void ficlFree (void *p)
}
#ifndef TESTMAIN
#ifdef __i386__
/*
* outb ( port# c -- )
* Store a byte to I/O port number port#
@ -111,7 +110,22 @@ ficlInb(FICL_VM *pVM)
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
/*

View File

@ -287,43 +287,6 @@ ficlFindfile(FICL_VM *pVM)
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 @@ static void fkey(FICL_VM *pVM)
}
#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 @@ static void ficlDictIncrease(FICL_VM *pVM)
**************************************************************************/
void ficlCompilePlatform(FICL_SYSTEM *pSys)
{
ficlCompileFcn **fnpp;
FICL_DICT *dp = pSys->dp;
assert (dp);
@ -994,24 +823,10 @@ void ficlCompilePlatform(FICL_SYSTEM *pSys)
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);

View File

@ -54,7 +54,8 @@ CFLAGS+= -DTERM_EMU
# 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.

View File

@ -1,5 +1,6 @@
/*-
* Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
* Copyright (c) 2016 Netflix, Inc
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -37,6 +38,7 @@ __FBSDID("$FreeBSD$");
#include <isapnp.h>
#include <btxv86.h>
#include "libi386.h"
#include "ficl.h"
/*
* Stupid PCI BIOS interface doesn't let you simply enumerate everything
@ -338,7 +340,7 @@ biospci_find_devclass(uint32_t class, int index, uint32_t *locator)
return (0);
}
int
static int
biospci_find_device(uint32_t devid, int index, uint32_t *locator)
{
v86.ctl = V86_FLAGS;
@ -407,7 +409,7 @@ biospci_locator(int8_t bus, uint8_t device, uint8_t function)
* 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 @@ biospci_count_device_type(uint32_t devid)
}
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);

View File

@ -104,12 +104,10 @@ extern uint32_t high_heap_size; /* extended memory region available */
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);

View File

@ -65,6 +65,10 @@ SECTIONS
__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*) }

View File

@ -37,7 +37,8 @@ CFLAGS+= -DTERM_EMU
# 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.