This commit affects ELF kernels only.
Remove "setdefs.h" and arrange to generate it automatically at ELF kernel build time. "gensetdefs.c" is a utility which scans a set of ELF object files and outputs a line ``DEFINE_SET(name, length);'' for each linker set that it finds. When generating an ELF kernel, this is run just before the final link to generate "setdefs.h". Remove the init_sets() function from "setdef0.c", and its call from "machdep.c". Since "gensetdefs.c" calculates the length of each set, it is no longer necessary in an ELF kernel to count the set elements at kernel initialization time. Also remove "set_of_sets" which was used for this purpose. Link "setdef0" and "setdef1" into the kernel only if building for ELF. Since init_sets() is no longer used, there is no need to link them into an a.out kernel.
This commit is contained in:
parent
5851a3655a
commit
61b005296f
@ -35,7 +35,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: @(#)machdep.c 7.4 (Berkeley) 6/3/91
|
||||
* $Id: machdep.c,v 1.240 1997/05/07 20:12:47 peter Exp $
|
||||
* $Id: machdep.c,v 1.241 1997/05/11 12:39:43 bde Exp $
|
||||
*/
|
||||
|
||||
#include "npx.h"
|
||||
@ -130,7 +130,6 @@ extern void earlysetcpuclass(void); /* same header file */
|
||||
extern void finishidentcpu(void);
|
||||
extern void panicifcpuunsupported(void);
|
||||
extern void initializecpu(void);
|
||||
extern void init_sets(void);
|
||||
|
||||
static void cpu_startup __P((void *));
|
||||
SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL)
|
||||
@ -1027,11 +1026,6 @@ init386(first)
|
||||
|
||||
atdevbase = ISA_HOLE_START + KERNBASE;
|
||||
|
||||
/*
|
||||
* Fill in the length fields of all linker sets (necessary for ELF).
|
||||
*/
|
||||
init_sets();
|
||||
|
||||
/*
|
||||
* Initialize the console before we print anything out.
|
||||
*/
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Makefile.i386 -- with config changes.
|
||||
# Copyright 1990 W. Jolitz
|
||||
# from: @(#)Makefile.i386 7.1 5/10/91
|
||||
# $Id: Makefile.i386,v 1.95 1997/04/27 20:01:47 peter Exp $
|
||||
# $Id: Makefile.i386,v 1.96 1997/05/07 16:05:23 dfr Exp $
|
||||
#
|
||||
# Makefile for FreeBSD
|
||||
#
|
||||
@ -55,30 +55,36 @@ DRIVER_C_C= ${CC} -c ${CFLAGS} ${PROF} ${PARAM} $<
|
||||
DRIVER_S= ${CC} -c -x assembler-with-cpp -DLOCORE ${COPTS} $<
|
||||
PROFILE_C= ${CC} -c ${CFLAGS} ${PARAM} $<
|
||||
|
||||
SYSTEM_CFILES= ${I386}/i386/setdef0.c ioconf.c param.c vnode_if.c config.c \
|
||||
${I386}/i386/setdef1.c
|
||||
# ${I386}/i386/setdef0.c and ${I386}/i386/setdef1.c are intentionally
|
||||
# omitted from SYSTEM_CFILES. They depend on setdefs.h, a header which
|
||||
# is generated from all of ${OBJS}. We don't want to have to compile
|
||||
# everything just to do a make depend.
|
||||
SYSTEM_CFILES= ioconf.c param.c vnode_if.c config.c
|
||||
SYSTEM_SFILES= ${I386}/i386/locore.s
|
||||
SYSTEM_OBJS= locore.o setdef0.o vnode_if.o ${OBJS} ioconf.o param.o config.o \
|
||||
setdef1.o
|
||||
SYSTEM_DEP= Makefile symbols.exclude symbols.sort ${SYSTEM_OBJS}
|
||||
.if ${CFLAGS:M-g} == ""
|
||||
SYMORDER_EXCLUDE=-x symbols.exclude
|
||||
.endif
|
||||
SYSTEM_LD_HEAD= @echo loading $@; rm -f $@
|
||||
.if ${BINFORMAT} == aout
|
||||
SYSTEM_OBJS= locore.o vnode_if.o ${OBJS} ioconf.o param.o config.o
|
||||
SYSTEM_LD= @${LD} -Bstatic -Z -T ${LOAD_ADDRESS} -o $@ -X ${SYSTEM_OBJS} vers.o
|
||||
SYSTEM_LD_TAIL= @echo rearranging symbols; \
|
||||
symorder -m ${SYMORDER_EXCLUDE} symbols.sort $@; \
|
||||
size $@; chmod 755 $@
|
||||
.endif
|
||||
.if ${BINFORMAT} == aoutkld
|
||||
SYSTEM_OBJS= locore.o vnode_if.o ${OBJS} ioconf.o param.o config.o
|
||||
SYSTEM_LD= @${LD} -Bforcedynamic -Z -T ${LOAD_ADDRESS} -o $@ -X ${SYSTEM_OBJS} vers.o
|
||||
SYSTEM_LD_TAIL= @echo rearranging symbols; \
|
||||
symorder -m ${SYMORDER_EXCLUDE} symbols.sort $@; \
|
||||
size $@; chmod 755 $@
|
||||
.endif
|
||||
.if ${BINFORMAT} == elf
|
||||
SYSTEM_LD= @${LD} -Bstatic -Ttext ${LOAD_ADDRESS} -e btext -o $@ -X ${SYSTEM_OBJS} vers.o
|
||||
SYSTEM_OBJS= locore.o setdef0.o vnode_if.o ${OBJS} ioconf.o param.o config.o \
|
||||
setdef1.o
|
||||
SYSTEM_LD= @${LD} -Bstatic -Ttext ${LOAD_ADDRESS} -e btext -defsym _DYNAMIC=0 \
|
||||
-o $@ -X ${SYSTEM_OBJS} vers.o
|
||||
SYSTEM_LD_TAIL= @size $@; chmod 755 $@
|
||||
.endif
|
||||
|
||||
@ -95,8 +101,8 @@ SYSTEM_LD_TAIL= @size $@; chmod 755 $@
|
||||
%CLEAN
|
||||
|
||||
clean:
|
||||
rm -f *.o *.s eddep errs genassym kernel linterrs \
|
||||
makelinks param.c symbols.exclude symbols.sort tags \
|
||||
rm -f *.o *.s eddep errs genassym gensetdefs kernel linterrs \
|
||||
makelinks param.c setdefs.h symbols.exclude symbols.sort tags \
|
||||
vers.c vnode_if.c vnode_if.h ${CLEAN}
|
||||
|
||||
#lint: /tmp param.c
|
||||
@ -116,12 +122,21 @@ symbols.sort: ${I386}/i386/symbols.raw
|
||||
locore.o: ${I386}/i386/locore.s assym.s
|
||||
${NORMAL_S}
|
||||
|
||||
setdef0.o: ${I386}/i386/setdef0.c
|
||||
setdef0.o: ${I386}/i386/setdef0.c setdefs.h
|
||||
${NORMAL_C}
|
||||
|
||||
setdef1.o: ${I386}/i386/setdef1.c
|
||||
setdef1.o: ${I386}/i386/setdef1.c setdefs.h
|
||||
${NORMAL_C}
|
||||
|
||||
setdefs.h: gensetdefs ${OBJS}
|
||||
./gensetdefs ${OBJS} >setdefs.h
|
||||
|
||||
gensetdefs: gensetdefs.o
|
||||
${CC} ${CFLAGS} gensetdefs.o -o $@
|
||||
|
||||
gensetdefs.o: ${I386}/i386/gensetdefs.c
|
||||
${CC} -c ${CFLAGS} ${I386}/i386/gensetdefs.c
|
||||
|
||||
# everything potentially depends on the Makefile since everything potentially
|
||||
# depends on the options. Some things are more dependent on the Makefile for
|
||||
# historical reasons.
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Makefile.i386 -- with config changes.
|
||||
# Copyright 1990 W. Jolitz
|
||||
# from: @(#)Makefile.i386 7.1 5/10/91
|
||||
# $Id: Makefile.i386,v 1.95 1997/04/27 20:01:47 peter Exp $
|
||||
# $Id: Makefile.i386,v 1.96 1997/05/07 16:05:23 dfr Exp $
|
||||
#
|
||||
# Makefile for FreeBSD
|
||||
#
|
||||
@ -55,30 +55,36 @@ DRIVER_C_C= ${CC} -c ${CFLAGS} ${PROF} ${PARAM} $<
|
||||
DRIVER_S= ${CC} -c -x assembler-with-cpp -DLOCORE ${COPTS} $<
|
||||
PROFILE_C= ${CC} -c ${CFLAGS} ${PARAM} $<
|
||||
|
||||
SYSTEM_CFILES= ${I386}/i386/setdef0.c ioconf.c param.c vnode_if.c config.c \
|
||||
${I386}/i386/setdef1.c
|
||||
# ${I386}/i386/setdef0.c and ${I386}/i386/setdef1.c are intentionally
|
||||
# omitted from SYSTEM_CFILES. They depend on setdefs.h, a header which
|
||||
# is generated from all of ${OBJS}. We don't want to have to compile
|
||||
# everything just to do a make depend.
|
||||
SYSTEM_CFILES= ioconf.c param.c vnode_if.c config.c
|
||||
SYSTEM_SFILES= ${I386}/i386/locore.s
|
||||
SYSTEM_OBJS= locore.o setdef0.o vnode_if.o ${OBJS} ioconf.o param.o config.o \
|
||||
setdef1.o
|
||||
SYSTEM_DEP= Makefile symbols.exclude symbols.sort ${SYSTEM_OBJS}
|
||||
.if ${CFLAGS:M-g} == ""
|
||||
SYMORDER_EXCLUDE=-x symbols.exclude
|
||||
.endif
|
||||
SYSTEM_LD_HEAD= @echo loading $@; rm -f $@
|
||||
.if ${BINFORMAT} == aout
|
||||
SYSTEM_OBJS= locore.o vnode_if.o ${OBJS} ioconf.o param.o config.o
|
||||
SYSTEM_LD= @${LD} -Bstatic -Z -T ${LOAD_ADDRESS} -o $@ -X ${SYSTEM_OBJS} vers.o
|
||||
SYSTEM_LD_TAIL= @echo rearranging symbols; \
|
||||
symorder -m ${SYMORDER_EXCLUDE} symbols.sort $@; \
|
||||
size $@; chmod 755 $@
|
||||
.endif
|
||||
.if ${BINFORMAT} == aoutkld
|
||||
SYSTEM_OBJS= locore.o vnode_if.o ${OBJS} ioconf.o param.o config.o
|
||||
SYSTEM_LD= @${LD} -Bforcedynamic -Z -T ${LOAD_ADDRESS} -o $@ -X ${SYSTEM_OBJS} vers.o
|
||||
SYSTEM_LD_TAIL= @echo rearranging symbols; \
|
||||
symorder -m ${SYMORDER_EXCLUDE} symbols.sort $@; \
|
||||
size $@; chmod 755 $@
|
||||
.endif
|
||||
.if ${BINFORMAT} == elf
|
||||
SYSTEM_LD= @${LD} -Bstatic -Ttext ${LOAD_ADDRESS} -e btext -o $@ -X ${SYSTEM_OBJS} vers.o
|
||||
SYSTEM_OBJS= locore.o setdef0.o vnode_if.o ${OBJS} ioconf.o param.o config.o \
|
||||
setdef1.o
|
||||
SYSTEM_LD= @${LD} -Bstatic -Ttext ${LOAD_ADDRESS} -e btext -defsym _DYNAMIC=0 \
|
||||
-o $@ -X ${SYSTEM_OBJS} vers.o
|
||||
SYSTEM_LD_TAIL= @size $@; chmod 755 $@
|
||||
.endif
|
||||
|
||||
@ -95,8 +101,8 @@ SYSTEM_LD_TAIL= @size $@; chmod 755 $@
|
||||
%CLEAN
|
||||
|
||||
clean:
|
||||
rm -f *.o *.s eddep errs genassym kernel linterrs \
|
||||
makelinks param.c symbols.exclude symbols.sort tags \
|
||||
rm -f *.o *.s eddep errs genassym gensetdefs kernel linterrs \
|
||||
makelinks param.c setdefs.h symbols.exclude symbols.sort tags \
|
||||
vers.c vnode_if.c vnode_if.h ${CLEAN}
|
||||
|
||||
#lint: /tmp param.c
|
||||
@ -116,12 +122,21 @@ symbols.sort: ${I386}/i386/symbols.raw
|
||||
locore.o: ${I386}/i386/locore.s assym.s
|
||||
${NORMAL_S}
|
||||
|
||||
setdef0.o: ${I386}/i386/setdef0.c
|
||||
setdef0.o: ${I386}/i386/setdef0.c setdefs.h
|
||||
${NORMAL_C}
|
||||
|
||||
setdef1.o: ${I386}/i386/setdef1.c
|
||||
setdef1.o: ${I386}/i386/setdef1.c setdefs.h
|
||||
${NORMAL_C}
|
||||
|
||||
setdefs.h: gensetdefs ${OBJS}
|
||||
./gensetdefs ${OBJS} >setdefs.h
|
||||
|
||||
gensetdefs: gensetdefs.o
|
||||
${CC} ${CFLAGS} gensetdefs.o -o $@
|
||||
|
||||
gensetdefs.o: ${I386}/i386/gensetdefs.c
|
||||
${CC} -c ${CFLAGS} ${I386}/i386/gensetdefs.c
|
||||
|
||||
# everything potentially depends on the Makefile since everything potentially
|
||||
# depends on the options. Some things are more dependent on the Makefile for
|
||||
# historical reasons.
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Makefile.i386 -- with config changes.
|
||||
# Copyright 1990 W. Jolitz
|
||||
# from: @(#)Makefile.i386 7.1 5/10/91
|
||||
# $Id: Makefile.i386,v 1.95 1997/04/27 20:01:47 peter Exp $
|
||||
# $Id: Makefile.i386,v 1.96 1997/05/07 16:05:23 dfr Exp $
|
||||
#
|
||||
# Makefile for FreeBSD
|
||||
#
|
||||
@ -55,30 +55,36 @@ DRIVER_C_C= ${CC} -c ${CFLAGS} ${PROF} ${PARAM} $<
|
||||
DRIVER_S= ${CC} -c -x assembler-with-cpp -DLOCORE ${COPTS} $<
|
||||
PROFILE_C= ${CC} -c ${CFLAGS} ${PARAM} $<
|
||||
|
||||
SYSTEM_CFILES= ${I386}/i386/setdef0.c ioconf.c param.c vnode_if.c config.c \
|
||||
${I386}/i386/setdef1.c
|
||||
# ${I386}/i386/setdef0.c and ${I386}/i386/setdef1.c are intentionally
|
||||
# omitted from SYSTEM_CFILES. They depend on setdefs.h, a header which
|
||||
# is generated from all of ${OBJS}. We don't want to have to compile
|
||||
# everything just to do a make depend.
|
||||
SYSTEM_CFILES= ioconf.c param.c vnode_if.c config.c
|
||||
SYSTEM_SFILES= ${I386}/i386/locore.s
|
||||
SYSTEM_OBJS= locore.o setdef0.o vnode_if.o ${OBJS} ioconf.o param.o config.o \
|
||||
setdef1.o
|
||||
SYSTEM_DEP= Makefile symbols.exclude symbols.sort ${SYSTEM_OBJS}
|
||||
.if ${CFLAGS:M-g} == ""
|
||||
SYMORDER_EXCLUDE=-x symbols.exclude
|
||||
.endif
|
||||
SYSTEM_LD_HEAD= @echo loading $@; rm -f $@
|
||||
.if ${BINFORMAT} == aout
|
||||
SYSTEM_OBJS= locore.o vnode_if.o ${OBJS} ioconf.o param.o config.o
|
||||
SYSTEM_LD= @${LD} -Bstatic -Z -T ${LOAD_ADDRESS} -o $@ -X ${SYSTEM_OBJS} vers.o
|
||||
SYSTEM_LD_TAIL= @echo rearranging symbols; \
|
||||
symorder -m ${SYMORDER_EXCLUDE} symbols.sort $@; \
|
||||
size $@; chmod 755 $@
|
||||
.endif
|
||||
.if ${BINFORMAT} == aoutkld
|
||||
SYSTEM_OBJS= locore.o vnode_if.o ${OBJS} ioconf.o param.o config.o
|
||||
SYSTEM_LD= @${LD} -Bforcedynamic -Z -T ${LOAD_ADDRESS} -o $@ -X ${SYSTEM_OBJS} vers.o
|
||||
SYSTEM_LD_TAIL= @echo rearranging symbols; \
|
||||
symorder -m ${SYMORDER_EXCLUDE} symbols.sort $@; \
|
||||
size $@; chmod 755 $@
|
||||
.endif
|
||||
.if ${BINFORMAT} == elf
|
||||
SYSTEM_LD= @${LD} -Bstatic -Ttext ${LOAD_ADDRESS} -e btext -o $@ -X ${SYSTEM_OBJS} vers.o
|
||||
SYSTEM_OBJS= locore.o setdef0.o vnode_if.o ${OBJS} ioconf.o param.o config.o \
|
||||
setdef1.o
|
||||
SYSTEM_LD= @${LD} -Bstatic -Ttext ${LOAD_ADDRESS} -e btext -defsym _DYNAMIC=0 \
|
||||
-o $@ -X ${SYSTEM_OBJS} vers.o
|
||||
SYSTEM_LD_TAIL= @size $@; chmod 755 $@
|
||||
.endif
|
||||
|
||||
@ -95,8 +101,8 @@ SYSTEM_LD_TAIL= @size $@; chmod 755 $@
|
||||
%CLEAN
|
||||
|
||||
clean:
|
||||
rm -f *.o *.s eddep errs genassym kernel linterrs \
|
||||
makelinks param.c symbols.exclude symbols.sort tags \
|
||||
rm -f *.o *.s eddep errs genassym gensetdefs kernel linterrs \
|
||||
makelinks param.c setdefs.h symbols.exclude symbols.sort tags \
|
||||
vers.c vnode_if.c vnode_if.h ${CLEAN}
|
||||
|
||||
#lint: /tmp param.c
|
||||
@ -116,12 +122,21 @@ symbols.sort: ${I386}/i386/symbols.raw
|
||||
locore.o: ${I386}/i386/locore.s assym.s
|
||||
${NORMAL_S}
|
||||
|
||||
setdef0.o: ${I386}/i386/setdef0.c
|
||||
setdef0.o: ${I386}/i386/setdef0.c setdefs.h
|
||||
${NORMAL_C}
|
||||
|
||||
setdef1.o: ${I386}/i386/setdef1.c
|
||||
setdef1.o: ${I386}/i386/setdef1.c setdefs.h
|
||||
${NORMAL_C}
|
||||
|
||||
setdefs.h: gensetdefs ${OBJS}
|
||||
./gensetdefs ${OBJS} >setdefs.h
|
||||
|
||||
gensetdefs: gensetdefs.o
|
||||
${CC} ${CFLAGS} gensetdefs.o -o $@
|
||||
|
||||
gensetdefs.o: ${I386}/i386/gensetdefs.c
|
||||
${CC} -c ${CFLAGS} ${I386}/i386/gensetdefs.c
|
||||
|
||||
# everything potentially depends on the Makefile since everything potentially
|
||||
# depends on the options. Some things are more dependent on the Makefile for
|
||||
# historical reasons.
|
||||
|
313
sys/i386/i386/gensetdefs.c
Normal file
313
sys/i386/i386/gensetdefs.c
Normal file
@ -0,0 +1,313 @@
|
||||
/*-
|
||||
* Copyright (c) 1997 John D. Polstra.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <machine/elf.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define HASHSIZE 1009u /* Number of hash chains. */
|
||||
#define PREFIX ".set." /* Section name prefix for linker sets. */
|
||||
|
||||
/* One entry in the hash table. */
|
||||
typedef struct hashent {
|
||||
struct hashent *next; /* Next entry with the same hash. */
|
||||
char *name; /* Name of the linker set. */
|
||||
size_t size; /* Size in bytes. */
|
||||
} hashent;
|
||||
|
||||
/* Allocate storage for "count" objects of type "type". */
|
||||
#define NEW(type, count) ((type *) xmalloc((count) * sizeof(type)))
|
||||
|
||||
static hashent *hashtab[HASHSIZE]; /* Hash chain heads. */
|
||||
|
||||
static void enter(const char *, size_t);
|
||||
static int enter_sets(const char *);
|
||||
static unsigned int hash(const char *);
|
||||
static hashent *merge(void);
|
||||
static int my_byte_order(void);
|
||||
static void *xmalloc(size_t);
|
||||
static char *xstrdup(const char *);
|
||||
|
||||
/*
|
||||
* This is a special-purpose program to generate the linker set definitions
|
||||
* needed when building an ELF kernel. Its arguments are the names of
|
||||
* ELF object files. It scans the section names of the object files,
|
||||
* building a table of those that begin with ".set.", which represent
|
||||
* linker sets. Finally, for each set "foo" with "count" elements, it
|
||||
* writes a line "DEFINE_SET(foo, count);" to the standard output.
|
||||
*/
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int status = EXIT_SUCCESS;
|
||||
hashent *list;
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
if (enter_sets(argv[i]) == -1)
|
||||
status = EXIT_FAILURE;
|
||||
|
||||
list = merge();
|
||||
while (list != NULL) {
|
||||
hashent *next;
|
||||
|
||||
printf("DEFINE_SET(%s, %lu);\n", list->name,
|
||||
(unsigned long) (list->size / sizeof (void *)));
|
||||
next = list->next;
|
||||
free(list->name);
|
||||
free(list);
|
||||
list = next;
|
||||
}
|
||||
|
||||
return (status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Enter the given string into the hash table, if it is not already there.
|
||||
* Each hash chain is kept sorted, so that it will be easy to merge the
|
||||
* chains to get a single sorted list.
|
||||
*/
|
||||
static void
|
||||
enter(const char *name, size_t size)
|
||||
{
|
||||
int c;
|
||||
hashent *entp;
|
||||
hashent **linkp;
|
||||
hashent *newp;
|
||||
|
||||
linkp = &hashtab[hash(name) % HASHSIZE];
|
||||
while ((entp = *linkp) != NULL && (c = strcmp(name, entp->name)) > 0)
|
||||
linkp = &entp->next;
|
||||
|
||||
if (entp == NULL || c != 0) { /* Not found; create a new entry. */
|
||||
newp = NEW(hashent, 1);
|
||||
newp->name = xstrdup(name);
|
||||
newp->size = 0;
|
||||
newp->next = entp;
|
||||
*linkp = newp;
|
||||
entp = newp;
|
||||
}
|
||||
|
||||
entp->size += size;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a hash value for the given string.
|
||||
*/
|
||||
static unsigned int
|
||||
hash(const char *s)
|
||||
{
|
||||
unsigned char ch;
|
||||
unsigned int h = 0;
|
||||
|
||||
while((ch = *s) != '\0') {
|
||||
h = 9*h + ch;
|
||||
s++;
|
||||
}
|
||||
return (h);
|
||||
}
|
||||
|
||||
/*
|
||||
* Enter the linker sets from the given ELF object file. Returns 0 on
|
||||
* success, or -1 if an error occurred.
|
||||
*/
|
||||
static int
|
||||
enter_sets(const char *filename)
|
||||
{
|
||||
int i;
|
||||
FILE *iop;
|
||||
Elf32_Shdr *shdr;
|
||||
char *shstr;
|
||||
Elf32_Ehdr ehdr;
|
||||
|
||||
if ((iop = fopen(filename, "rb")) == NULL) {
|
||||
warn("%s", filename);
|
||||
return (-1);
|
||||
}
|
||||
if (fread(&ehdr, sizeof ehdr, 1, iop) != 1 ||
|
||||
ehdr.e_ident[EI_MAG0] != ELFMAG0 ||
|
||||
ehdr.e_ident[EI_MAG1] != ELFMAG1 ||
|
||||
ehdr.e_ident[EI_MAG2] != ELFMAG2 ||
|
||||
ehdr.e_ident[EI_MAG3] != ELFMAG3) {
|
||||
warnx("%s: not an ELF file", filename);
|
||||
fclose(iop);
|
||||
return (-1);
|
||||
}
|
||||
if (ehdr.e_ident[EI_VERSION] != EV_CURRENT) {
|
||||
warnx("%s: unsupported ELF version", filename);
|
||||
fclose(iop);
|
||||
return (-1);
|
||||
}
|
||||
if (ehdr.e_ident[EI_DATA] != my_byte_order()) {
|
||||
warnx("%s: unsupported byte order", filename);
|
||||
fclose(iop);
|
||||
return (-1);
|
||||
}
|
||||
if (ehdr.e_shoff == 0) {
|
||||
warnx("%s: no section table", filename);
|
||||
fclose(iop);
|
||||
return (-1);
|
||||
}
|
||||
if (ehdr.e_shstrndx == SHN_UNDEF) {
|
||||
warnx("%s: no section name string table", filename);
|
||||
fclose(iop);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
shdr = NEW(Elf32_Shdr, ehdr.e_shnum);
|
||||
if (fseek(iop, ehdr.e_shoff, SEEK_SET) == -1) {
|
||||
warn("%s", filename);
|
||||
free(shdr);
|
||||
fclose(iop);
|
||||
return (-1);
|
||||
}
|
||||
if (fread(shdr, sizeof *shdr, ehdr.e_shnum, iop) != ehdr.e_shnum) {
|
||||
warnx("%s: truncated section table", filename);
|
||||
free(shdr);
|
||||
fclose(iop);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
shstr = NEW(char, shdr[ehdr.e_shstrndx].sh_size);
|
||||
if (fseek(iop, shdr[ehdr.e_shstrndx].sh_offset, SEEK_SET) == -1) {
|
||||
warn("%s", filename);
|
||||
free(shstr);
|
||||
free(shdr);
|
||||
fclose(iop);
|
||||
return (-1);
|
||||
}
|
||||
if (fread(shstr, sizeof *shstr, shdr[ehdr.e_shstrndx].sh_size, iop) !=
|
||||
shdr[ehdr.e_shstrndx].sh_size) {
|
||||
warnx("%s: truncated section name string table", filename);
|
||||
free(shstr);
|
||||
free(shdr);
|
||||
fclose(iop);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
for (i = 1; i < ehdr.e_shnum; i++) {
|
||||
const char *name = shstr + shdr[i].sh_name;
|
||||
|
||||
if (strncmp(name, PREFIX, sizeof (PREFIX) - 1) == 0)
|
||||
enter(name + sizeof (PREFIX) - 1, shdr[i].sh_size);
|
||||
}
|
||||
|
||||
free(shstr);
|
||||
free(shdr);
|
||||
fclose(iop);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Destructively merge all the sorted hash chains into a single sorted
|
||||
* list, and return a pointer to its first element.
|
||||
*/
|
||||
static hashent *
|
||||
merge(void)
|
||||
{
|
||||
unsigned int numchains = HASHSIZE;
|
||||
|
||||
while (numchains > 1) { /* More merging to do. */
|
||||
unsigned int lo = 0;
|
||||
/*
|
||||
* Merge chains pairwise from the outside in, halving the
|
||||
* number of chains.
|
||||
*/
|
||||
while (numchains - lo >= 2) {
|
||||
hashent **linkp = &hashtab[lo];
|
||||
hashent *l1 = hashtab[lo++];
|
||||
hashent *l2 = hashtab[--numchains];
|
||||
|
||||
while (l1 != NULL && l2 != NULL) {
|
||||
if (strcmp(l1->name, l2->name) < 0) {
|
||||
*linkp = l1;
|
||||
linkp = &l1->next;
|
||||
l1 = l1->next;
|
||||
} else {
|
||||
*linkp = l2;
|
||||
linkp = &l2->next;
|
||||
l2 = l2->next;
|
||||
}
|
||||
}
|
||||
*linkp = l1==NULL ? l2 : l1;
|
||||
}
|
||||
}
|
||||
|
||||
return (hashtab[0]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Determine the host byte order.
|
||||
*/
|
||||
static int
|
||||
my_byte_order(void)
|
||||
{
|
||||
static unsigned short s = 0xbbaa;
|
||||
int byte0;
|
||||
|
||||
byte0 = *(unsigned char *)&s;
|
||||
if (byte0 == 0xaa)
|
||||
return (ELFDATA2LSB);
|
||||
else if (byte0 == 0xbb)
|
||||
return (ELFDATA2MSB);
|
||||
else
|
||||
return (ELFDATANONE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a chunk of memory and return a pointer to it. Die if the
|
||||
* malloc fails.
|
||||
*/
|
||||
static void *
|
||||
xmalloc(size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = malloc(size);
|
||||
if (p == NULL)
|
||||
err(EXIT_FAILURE, "malloc");
|
||||
return (p);
|
||||
}
|
||||
|
||||
/*
|
||||
* Duplicate a string and return a pointer to the copy. Die if there is
|
||||
* not enough memory.
|
||||
*/
|
||||
static char *
|
||||
xstrdup(const char *s)
|
||||
{
|
||||
int size;
|
||||
|
||||
size = strlen(s) + 1;
|
||||
return (memcpy(xmalloc(size), s, size));
|
||||
}
|
@ -35,7 +35,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: @(#)machdep.c 7.4 (Berkeley) 6/3/91
|
||||
* $Id: machdep.c,v 1.240 1997/05/07 20:12:47 peter Exp $
|
||||
* $Id: machdep.c,v 1.241 1997/05/11 12:39:43 bde Exp $
|
||||
*/
|
||||
|
||||
#include "npx.h"
|
||||
@ -130,7 +130,6 @@ extern void earlysetcpuclass(void); /* same header file */
|
||||
extern void finishidentcpu(void);
|
||||
extern void panicifcpuunsupported(void);
|
||||
extern void initializecpu(void);
|
||||
extern void init_sets(void);
|
||||
|
||||
static void cpu_startup __P((void *));
|
||||
SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL)
|
||||
@ -1027,11 +1026,6 @@ init386(first)
|
||||
|
||||
atdevbase = ISA_HOLE_START + KERNBASE;
|
||||
|
||||
/*
|
||||
* Fill in the length fields of all linker sets (necessary for ELF).
|
||||
*/
|
||||
init_sets();
|
||||
|
||||
/*
|
||||
* Initialize the console before we print anything out.
|
||||
*/
|
||||
|
@ -23,70 +23,27 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id$
|
||||
* $Id: setdef0.c,v 1.1 1997/04/22 06:55:28 jdp Exp $
|
||||
*/
|
||||
|
||||
extern void init_sets(void);
|
||||
|
||||
#ifdef __ELF__
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
|
||||
/*
|
||||
* BEGIN_SET creates the section and label for a set, and emits the
|
||||
* count word at the front of it. The count word initially contains 0,
|
||||
* but is filled in with the correct value at runtime by init_sets().
|
||||
* DEFINE_SET creates the section and label for a set, and emits the
|
||||
* count word at the front of it.
|
||||
*/
|
||||
#define BEGIN_SET(set) \
|
||||
#define DEFINE_SET(set, count) \
|
||||
__asm__(".section .set." #set ",\"aw\""); \
|
||||
__asm__(".globl " #set); \
|
||||
__asm__(".type " #set ",@object"); \
|
||||
__asm__(".p2align 2"); \
|
||||
__asm__(#set ":"); \
|
||||
__asm__(".long 0"); \
|
||||
__asm__(".long " #count); \
|
||||
__asm__(".previous")
|
||||
|
||||
/*
|
||||
* DEFINE_SET calls BEGIN_SET and also enters the set into the mother
|
||||
* of all sets, `set_of_sets'.
|
||||
*/
|
||||
#define DEFINE_SET(set) BEGIN_SET(set); DATA_SET(set_of_sets, set)
|
||||
|
||||
/*
|
||||
* Define a set that contains a list of all the other linker sets.
|
||||
*/
|
||||
|
||||
BEGIN_SET(set_of_sets);
|
||||
|
||||
#include <i386/i386/setdefs.h> /* Contains a `DEFINE_SET' for each set */
|
||||
|
||||
extern struct linker_set set_of_sets;
|
||||
|
||||
/*
|
||||
* Fill in the leading "ls_length" fields of all linker sets. This is
|
||||
* needed for ELF. For a.out, it is already done by the linker.
|
||||
*/
|
||||
void
|
||||
init_sets(void)
|
||||
{
|
||||
struct linker_set **lspp = (struct linker_set **) set_of_sets.ls_items;
|
||||
struct linker_set *lsp;
|
||||
|
||||
for (; (lsp = *lspp) != NULL; lspp++) {
|
||||
int i;
|
||||
|
||||
for (i = 0; lsp->ls_items[i] != NULL; i++) /* Count items */
|
||||
;
|
||||
lsp->ls_length = i;
|
||||
}
|
||||
}
|
||||
|
||||
#else /* ! __ELF__ */
|
||||
|
||||
void
|
||||
init_sets(void)
|
||||
{
|
||||
}
|
||||
#include "setdefs.h" /* Contains a `DEFINE_SET' for each set */
|
||||
|
||||
#endif /* __ELF__ */
|
||||
|
@ -23,23 +23,19 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id$
|
||||
* $Id: setdef1.c,v 1.1 1997/04/22 06:55:28 jdp Exp $
|
||||
*/
|
||||
|
||||
#ifdef __ELF__
|
||||
|
||||
/*
|
||||
* END_SET emits the NULL terminator for a set.
|
||||
* DEFINE_SET emits the NULL terminator for a set.
|
||||
*/
|
||||
#define END_SET(set) \
|
||||
#define DEFINE_SET(set, count) \
|
||||
__asm__(".section .set." #set ",\"aw\""); \
|
||||
__asm__(".long 0"); \
|
||||
__asm__(".previous")
|
||||
|
||||
#define DEFINE_SET(set) END_SET(set)
|
||||
#include "setdefs.h" /* Contains a `DEFINE_SET' for each set */
|
||||
|
||||
#include <i386/i386/setdefs.h> /* Contains a `DEFINE_SET' for each set */
|
||||
|
||||
END_SET(set_of_sets); /* Terminate the mother of all sets */
|
||||
|
||||
#endif
|
||||
#endif /* __ELF__ */
|
||||
|
@ -1,107 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1997 John D. Polstra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef _MACHINE_SETDEFS_H_
|
||||
#define _MACHINE_SETDEFS_H_
|
||||
|
||||
/*
|
||||
* This file contains declarations for each linker set that can possibly
|
||||
* be included in the system. Every linker set must have an entry in this
|
||||
* file, regardless of whether it happens to be configured into a given
|
||||
* kernel.
|
||||
*
|
||||
* These declarations are unused for a.out, but they are needed for an
|
||||
* ELF kernel. ELF does not directly support linker sets, so they are
|
||||
* simulated by creating a separate section for each set. This header
|
||||
* is included by two source files: setdef0.c at the beginning of the
|
||||
* link (just after locore.s), and setdef1.c at the end of the link.
|
||||
* The DEFINE_SET macro is defined differently in these two souces, so
|
||||
* that it emits the leading count word for each set in setdef0.c, and
|
||||
* the trailing NULL pointer for each set in setdef1.c.
|
||||
*/
|
||||
|
||||
DEFINE_SET(db_show_cmd_set);
|
||||
DEFINE_SET(domain_set);
|
||||
DEFINE_SET(eisadriver_set);
|
||||
DEFINE_SET(execsw_set);
|
||||
DEFINE_SET(netisr_set);
|
||||
DEFINE_SET(pcibus_set);
|
||||
DEFINE_SET(pcidevice_set);
|
||||
DEFINE_SET(sysctl_);
|
||||
DEFINE_SET(sysctl__debug);
|
||||
DEFINE_SET(sysctl__hw);
|
||||
DEFINE_SET(sysctl__kern);
|
||||
DEFINE_SET(sysctl__kern_ipc);
|
||||
DEFINE_SET(sysctl__kern_ntp_pll);
|
||||
DEFINE_SET(sysctl__kern_proc);
|
||||
DEFINE_SET(sysctl__kern_proc_pgrp);
|
||||
DEFINE_SET(sysctl__kern_proc_pid);
|
||||
DEFINE_SET(sysctl__kern_proc_ruid);
|
||||
DEFINE_SET(sysctl__kern_proc_tty);
|
||||
DEFINE_SET(sysctl__kern_proc_uid);
|
||||
DEFINE_SET(sysctl__machdep);
|
||||
DEFINE_SET(sysctl__net);
|
||||
DEFINE_SET(sysctl__net_inet);
|
||||
DEFINE_SET(sysctl__net_inet_div);
|
||||
DEFINE_SET(sysctl__net_inet_icmp);
|
||||
DEFINE_SET(sysctl__net_inet_igmp);
|
||||
DEFINE_SET(sysctl__net_inet_ip);
|
||||
DEFINE_SET(sysctl__net_inet_ip_fw);
|
||||
DEFINE_SET(sysctl__net_inet_ip_portrange);
|
||||
DEFINE_SET(sysctl__net_inet_raw);
|
||||
DEFINE_SET(sysctl__net_inet_tcp);
|
||||
DEFINE_SET(sysctl__net_inet_udp);
|
||||
DEFINE_SET(sysctl__net_ipx);
|
||||
DEFINE_SET(sysctl__net_ipx_error);
|
||||
DEFINE_SET(sysctl__net_ipx_ipx);
|
||||
DEFINE_SET(sysctl__net_ipx_spx);
|
||||
DEFINE_SET(sysctl__net_link);
|
||||
DEFINE_SET(sysctl__net_link_ether);
|
||||
DEFINE_SET(sysctl__net_link_ether_inet);
|
||||
DEFINE_SET(sysctl__net_link_generic);
|
||||
DEFINE_SET(sysctl__net_link_generic_ifdata);
|
||||
DEFINE_SET(sysctl__net_link_generic_system);
|
||||
DEFINE_SET(sysctl__net_local);
|
||||
DEFINE_SET(sysctl__net_local_dgram);
|
||||
DEFINE_SET(sysctl__net_local_stream);
|
||||
DEFINE_SET(sysctl__net_routetable);
|
||||
DEFINE_SET(sysctl__sysctl);
|
||||
DEFINE_SET(sysctl__sysctl_name);
|
||||
DEFINE_SET(sysctl__sysctl_next);
|
||||
DEFINE_SET(sysctl__sysctl_oidfmt);
|
||||
DEFINE_SET(sysctl__user);
|
||||
DEFINE_SET(sysctl__vfs);
|
||||
DEFINE_SET(sysctl__vfs_ffs);
|
||||
DEFINE_SET(sysctl__vfs_generic);
|
||||
DEFINE_SET(sysctl__vfs_nfs);
|
||||
DEFINE_SET(sysctl__vm);
|
||||
DEFINE_SET(sysinit_set);
|
||||
DEFINE_SET(vfs_opv_descs_);
|
||||
DEFINE_SET(vfs_set);
|
||||
|
||||
#endif /* !_MACHINE_SETDEFS_H_ */
|
Loading…
x
Reference in New Issue
Block a user