aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Bucur <stefanb@zytor.com>2008-07-28 20:07:20 -0700
committerStefan Bucur <stefan@stefan-ubumac.(none)>2009-03-15 10:10:49 +0200
commit81f53774fd8d140ff4bdd05c32dfc69a09f707de (patch)
tree8ca32fa26890355d2e23ff169b223ed7d8125134
parentf081bb948673519ebb4a97e8b53c4ea85478959f (diff)
downloadsyslinux-elf-81f53774fd8d140ff4bdd05c32dfc69a09f707de.tar.gz
syslinux-elf-81f53774fd8d140ff4bdd05c32dfc69a09f707de.tar.xz
syslinux-elf-81f53774fd8d140ff4bdd05c32dfc69a09f707de.zip
Created a prototype for the first ELF module.
-rw-r--r--com32/Makefile2
-rw-r--r--com32/elflink/elf_module.c6
-rw-r--r--com32/elflink/elf_module.h8
-rw-r--r--com32/elflink/modules/Makefile100
-rw-r--r--com32/elflink/modules/hello.c29
-rw-r--r--com32/lib/elf32.ld19
6 files changed, 152 insertions, 12 deletions
diff --git a/com32/Makefile b/com32/Makefile
index 22bbbc16..53501197 100644
--- a/com32/Makefile
+++ b/com32/Makefile
@@ -1,4 +1,4 @@
-SUBDIRS = lib gpllib libutil modules menu samples elflink rosh cmenu hdt
+SUBDIRS = lib gpllib libutil modules menu samples elflink elflink/modules rosh cmenu hdt
all tidy dist clean spotless install:
set -e; for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
diff --git a/com32/elflink/elf_module.c b/com32/elflink/elf_module.c
index 758a0631..fbd596e4 100644
--- a/com32/elflink/elf_module.c
+++ b/com32/elflink/elf_module.c
@@ -133,12 +133,12 @@ static int image_seek(Elf32_Off offset, struct elf_module *module) {
// Initialization of the module subsystem
-int modules_init() {
+int modules_init(void) {
return 0;
}
// Termination of the module subsystem
-void modules_term() {
+void modules_term(void) {
}
@@ -770,7 +770,7 @@ static int check_symbols(struct elf_module *module) {
if (strong_count > 0 && ELF32_ST_BIND(ref_sym->st_info) == STB_GLOBAL) {
// It's not an error - at relocation, the most recent symbol
// will be considered
- DBG_PRINT("Symbol %s is defined more than once\n", crt_name);
+ DBG_PRINT("Info: Symbol %s is defined more than once\n", crt_name);
}
}
}
diff --git a/com32/elflink/elf_module.h b/com32/elflink/elf_module.h
index b93dc0df..cdc2254f 100644
--- a/com32/elflink/elf_module.h
+++ b/com32/elflink/elf_module.h
@@ -16,8 +16,8 @@
#define MODULE_ELF_MACHINE EM_386
-typedef int (*module_init_func)();
-typedef void (*module_exit_func)();
+typedef int (*module_init_func)(void);
+typedef void (*module_exit_func)(void);
// Structure encapsulating a module loaded in memory
struct elf_module {
@@ -62,9 +62,9 @@ struct module_dep {
};
// Initialization of the module subsystem
-extern int modules_init();
+extern int modules_init(void);
// Termination of the module subsystem
-extern void modules_term();
+extern void modules_term(void);
// Allocates the structure for a new module
extern struct elf_module *module_alloc(const char *name);
diff --git a/com32/elflink/modules/Makefile b/com32/elflink/modules/Makefile
new file mode 100644
index 00000000..35958cf6
--- /dev/null
+++ b/com32/elflink/modules/Makefile
@@ -0,0 +1,100 @@
+## -----------------------------------------------------------------------
+##
+## Copyright 2001-2008 H. Peter Anvin - All Rights Reserved
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, Inc., 53 Temple Place Ste 330,
+## Boston MA 02111-1307, USA; either version 2 of the License, or
+## (at your option) any later version; incorporated herein by reference.
+##
+## -----------------------------------------------------------------------
+
+##
+## COM32 standard modules
+##
+
+TMPFILE = $(shell mktemp /tmp/gcc_ok.XXXXXX)
+CC = gcc
+
+gcc_ok = $(shell tmpf=$(TMPFILE); if $(CC) $(1) -c -x c /dev/null -o $$tmpf 2>/dev/null; \
+ then echo $(1); else echo $(2); fi; rm -f $$tmpf)
+
+M32 := $(call gcc_ok,-m32,) $(call gcc_ok,-fno-stack-protector,)
+
+LD = ld -m elf_i386
+AR = ar
+NASM = nasm
+NASMOPT = -O9999
+RANLIB = ranlib
+CFLAGS = $(M32) -mregparm=3 -DREGPARM=3 -W -Wall -march=i386 -Os \
+ -fomit-frame-pointer -D__COM32__ \
+ -nostdinc -iwithprefix include \
+ -I../../libutil/include -I../../include \
+ -Wp,-MT,$@,-MD,$(dir $@).$(notdir $@).d
+LNXCFLAGS = -W -Wall -O -g -I../libutil/include
+LNXSFLAGS = -g
+LNXLDFLAGS = -g
+SFLAGS = -D__COM32__ -march=i386
+LDFLAGS = -shared -T ../../lib/elf32.ld
+OBJCOPY = objcopy
+PPMTOLSS16 = ../ppmtolss16
+LIBGCC := $(shell $(CC) --print-libgcc)
+LIBS = $(LIBGCC)
+
+.SUFFIXES: .lss .c .o .dyn
+
+BINDIR = /usr/bin
+LIBDIR = /usr/lib
+DATADIR = /usr/share
+AUXDIR = $(DATADIR)/syslinux
+INCDIR = /usr/include
+COM32DIR = $(AUXDIR)/com32
+
+MODULES = hello.dyn
+
+TESTFILES =
+
+all: $(MODULES) $(TESTFILES)
+
+.PRECIOUS: %.o
+%.o: %.S
+ $(CC) $(SFLAGS) -c -o $@ $<
+
+.PRECIOUS: %.o
+%.o: %.c
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+.PRECIOUS: %.dyn
+%.dyn: %.o $(LIBS)
+ $(LD) $(LDFLAGS) -o $@ $^
+
+.PRECIOUS: %.lo
+%.lo: %.S
+ $(CC) $(LNXSFLAGS) -c -o $@ $<
+
+.PRECIOUS: %.lo
+%.lo: %.c
+ $(CC) $(LNXCFLAGS) -c -o $@ $<
+
+.PRECIOUS: %.lnx
+%.lnx: %.lo $(LNXLIBS)
+ $(CC) $(LNXLDFLAGS) -o $@ $^
+
+hello.dyn : hello.o $(LIBS)
+ $(LD) $(LDFLAGS) -o $@ $^
+
+tidy dist:
+ rm -f *.o *.lo *.a *.lst .*.d
+
+clean: tidy
+ rm -f *.lss *.lnx *.com *.dyn
+
+spotless: clean
+ rm -f *~ \#*
+
+install: all
+ mkdir -m 755 -p $(INSTALLROOT)$(AUXDIR)
+ install -m 644 $(MODULES) $(INSTALLROOT)$(AUXDIR)
+
+-include .*.d
diff --git a/com32/elflink/modules/hello.c b/com32/elflink/modules/hello.c
new file mode 100644
index 00000000..f396c794
--- /dev/null
+++ b/com32/elflink/modules/hello.c
@@ -0,0 +1,29 @@
+/*
+ * The first prototype of an ELF module, inspired from the Linux kernel
+ * module system.
+ */
+
+#include <stdio.h>
+
+typedef int (*module_init_t)(void);
+typedef void (*module_exit_t)(void);
+
+#define __used __attribute__((used))
+
+#define MODULE_INIT(fn) static module_init_t __module_init \
+ __used __attribute__((section(".ctors_module"))) = fn
+
+#define MODULE_EXIT(fn) static module_exit_t __module_exit \
+ __used __attribute__((section(".dtors_module"))) = fn
+
+static int hello_init(void) {
+ printf("Hello, world, from 0x%08X!\n", (unsigned int)&hello_init);
+ return 0;
+}
+
+static void hello_exit(void) {
+ printf("Good bye, cruel world!\n");
+}
+
+MODULE_INIT(hello_init);
+MODULE_EXIT(hello_exit);
diff --git a/com32/lib/elf32.ld b/com32/lib/elf32.ld
index c0c77fe2..20234c2c 100644
--- a/com32/lib/elf32.ld
+++ b/com32/lib/elf32.ld
@@ -84,16 +84,26 @@ SECTIONS
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
}
+ __ctors_start = .;
.ctors :
{
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
+ __module_init_ptr = .;
+ KEEP (*(.ctors_module))
+ LONG(0x00000000)
}
+
+ __dtors_start = .;
.dtors :
{
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
+ __module_exit_ptr = .;
+ KEEP (*(.dtors_module))
+ LONG(0x00000000)
}
+
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
@@ -107,8 +117,8 @@ SECTIONS
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
- _edata = .; PROVIDE (edata = .);
- __bss_start = .;
+ PROVIDE (edata = .);
+ PROVIDE (_edata = .);
.bss :
{
*(.dynbss)
@@ -123,8 +133,9 @@ SECTIONS
}
. = ALIGN(32 / 8);
. = ALIGN(32 / 8);
- _end = .; PROVIDE (end = .);
- /*. = DATA_SEGMENT_END (.); -> -> This gives a "invalid assignment to location counter" error */
+ PROVIDE (_end = .);
+ PROVIDE (end = .);
+ /*. = DATA_SEGMENT_END (.); -> This gives a "invalid assignment to location counter" error */
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }