aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Bucur <stefanb@zytor.com>2008-07-24 17:15:42 -0700
committerStefan Bucur <stefan@stefan-ubumac.(none)>2009-03-15 10:08:55 +0200
commitfde412ebc21ae2ec9b3b69838fc6867adc9641ce (patch)
treed0333599fe42c9194d453a26ec85b9a40fa334b4
parent9c13daa87966de47de29b3fa317001bb19c54aed (diff)
downloadsyslinux-elf-fde412ebc21ae2ec9b3b69838fc6867adc9641ce.tar.gz
syslinux-elf-fde412ebc21ae2ec9b3b69838fc6867adc9641ce.tar.xz
syslinux-elf-fde412ebc21ae2ec9b3b69838fc6867adc9641ce.zip
Reorganized a little the elflink subdirectory and made a simple module to load klibc.
-rw-r--r--com32/elflink/Makefile13
-rw-r--r--com32/elflink/Makefile.user6
-rw-r--r--com32/elflink/elf_module.c22
-rw-r--r--com32/elflink/modules/README1
-rw-r--r--com32/elflink/test_com32.c61
-rw-r--r--com32/elflink/test_memalign.c (renamed from com32/elflink/elflink.c)2
-rw-r--r--com32/elflink/test_user.c (renamed from com32/elflink/elftest.c)0
-rw-r--r--com32/include/klibc/compiler.h3
-rw-r--r--com32/lib/Makefile131
-rw-r--r--com32/lib/stack.c2
10 files changed, 160 insertions, 81 deletions
diff --git a/com32/elflink/Makefile b/com32/elflink/Makefile
index 1151c677..d010e121 100644
--- a/com32/elflink/Makefile
+++ b/com32/elflink/Makefile
@@ -36,7 +36,7 @@ LNXCFLAGS = -W -Wall -O -g -I../libutil/include
LNXSFLAGS = -g
LNXLDFLAGS = -g
SFLAGS = -D__COM32__ -march=i386
-LDFLAGS = -T ../lib/com32.ld
+LDFLAGS = -n -T ../lib/com32.ld
OBJCOPY = objcopy
PPMTOLSS16 = ../ppmtolss16
LIBGCC := $(shell $(CC) --print-libgcc)
@@ -52,7 +52,7 @@ AUXDIR = $(DATADIR)/syslinux
INCDIR = /usr/include
COM32DIR = $(AUXDIR)/com32
-MODULES = elflink.c32
+MODULES = test_memalign.c32 test_com32.c32
TESTFILES =
@@ -85,14 +85,19 @@ all: $(MODULES) $(TESTFILES)
%.c32: %.elf
$(OBJCOPY) -O binary $< $@
-elflink.elf : elflink.o elf_module.o elf_utils.o $(LIBS)
+test_memalign.elf : test_memalign.o $(LIBS)
$(LD) $(LDFLAGS) -o $@ $^
+test_com32.elf: CFLAGS += -DELF_DEBUG
+test_com32.elf: test_com32.o elf_module.o elf_utils.o $(LIBS)
+ $(LD) $(LDFLAGS) -o $@ $^
+ $(OBJCOPY) --extract-symbol $@ _root_.dyn
+
tidy dist:
rm -f *.o *.lo *.a *.lst *.elf .*.d
clean: tidy
- rm -f *.lss *.c32 *.lnx *.com
+ rm -f *.lss *.c32 *.lnx *.com *.dyn
spotless: clean
rm -f *~ \#*
diff --git a/com32/elflink/Makefile.user b/com32/elflink/Makefile.user
index e800d6c6..296f6185 100644
--- a/com32/elflink/Makefile.user
+++ b/com32/elflink/Makefile.user
@@ -13,7 +13,7 @@ RM = rm -f
################
# Build options
-CFLAGS = -g3 -O0 -Wall -DELF_USERSPACE_TEST
+CFLAGS = -g3 -O0 -Wall -DELF_DEBUG
LDFLAGS =
@@ -21,7 +21,7 @@ LDFLAGS =
# Generated files
# Test executable name
-TESTPROG = elftest
+TESTPROG = test_user
###############
@@ -34,7 +34,7 @@ all: test-prog test-module
# The testing user-space application
test-prog: $(TESTPROG)
-$(TESTPROG): elftest.o elf_module.o elf_utils.o
+$(TESTPROG): test_user.o elf_module.o elf_utils.o
$(CC) -o $@ $^
diff --git a/com32/elflink/elf_module.c b/com32/elflink/elf_module.c
index 000ec0b1..7d7235a4 100644
--- a/com32/elflink/elf_module.c
+++ b/com32/elflink/elf_module.c
@@ -23,7 +23,7 @@ static LIST_HEAD(modules);
// User-space debugging routines
-#ifdef ELF_USERSPACE_TEST
+#ifdef ELF_DEBUG
static void print_elf_ehdr(Elf32_Ehdr *ehdr) {
int i;
@@ -65,15 +65,10 @@ static void print_elf_symbols(struct elf_module *module) {
}
}
}
-#endif //ELF_USERSPACE_TEST
+#endif //ELF_DEBUG
static int image_load(struct elf_module *module) {
- char file_name[MODULE_NAME_SIZE+3]; // Include the extension
-
- strcpy(file_name, module->name);
- strcat(file_name, ".so");
-
- module->_file = fopen(file_name, "rb");
+ module->_file = fopen(module->name, "rb");
if (module->_file == NULL) {
perror("Could not open object file");
@@ -623,7 +618,7 @@ static int resolve_symbols(struct elf_module *module) {
static int check_symbols(struct elf_module *module) {
unsigned int i;
- Elf32_Sym *crt_sym, *ref_sym;
+ Elf32_Sym *crt_sym = NULL, *ref_sym = NULL;
char *crt_name;
struct elf_module *crt_module;
@@ -690,20 +685,15 @@ int module_load(struct elf_module *module) {
CHECKED(res, check_header(&elf_hdr), error);
// DEBUG
-#ifdef ELF_USERSPACE_TEST
+#ifdef ELF_DEBUG
print_elf_ehdr(&elf_hdr);
-#endif // ELF_USERSPACE_TEST
+#endif // ELF_DEBUG
// Load the segments in the memory
CHECKED(res, load_segments(module, &elf_hdr), error);
// Obtain dynamic linking information
CHECKED(res, prepare_dynlinking(module), error);
- // DEBUG
-#ifdef ELF_USERSPACE_TEST
- print_elf_symbols(module);
-#endif // ELF_USERSPACE_TEST
-
// Check the symbols for duplicates / missing definitions
CHECKED(res, check_symbols(module), error);
diff --git a/com32/elflink/modules/README b/com32/elflink/modules/README
new file mode 100644
index 00000000..090313a7
--- /dev/null
+++ b/com32/elflink/modules/README
@@ -0,0 +1 @@
+This folder contains dynamically loadable ELF modules for SYSLINUX. \ No newline at end of file
diff --git a/com32/elflink/test_com32.c b/com32/elflink/test_com32.c
new file mode 100644
index 00000000..71b19d4c
--- /dev/null
+++ b/com32/elflink/test_com32.c
@@ -0,0 +1,61 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <console.h>
+
+#include "elf_module.h"
+
+#define KLIBC_NAME "klibc.dyn"
+
+#define ELF_DIRECTORY "/dyn/"
+
+static struct elf_module *mod_klibc;
+
+int modules_com32_setup() {
+ int res;
+
+ res = modules_init();
+
+ if (res != 0)
+ return res;
+
+ ////////////////////////////////////////
+ // Load the klibc module
+
+ // Create its associated structure
+ mod_klibc = module_alloc(ELF_DIRECTORY KLIBC_NAME);
+
+ if (mod_klibc == NULL) {
+ return -1;
+ }
+
+ res = module_load(mod_klibc);
+
+ if (res != 0) {
+ return res;
+ }
+
+ return 0;
+}
+
+void modules_com32_finalize() {
+ modules_term();
+}
+
+int main(int argc, char **argv) {
+ int res;
+
+ // Open a standard r/w console
+ openconsole(&dev_stdcon_r, &dev_stdcon_w);
+
+ // Initializing the module subsystem
+ res = modules_com32_setup();
+
+ if (res != 0) {
+ printf("ERROR: Could not fully initialize the module!\n");
+ return res;
+ }
+
+ modules_com32_finalize();
+
+ return 0;
+}
diff --git a/com32/elflink/elflink.c b/com32/elflink/test_memalign.c
index 0f373393..ea2b0165 100644
--- a/com32/elflink/elflink.c
+++ b/com32/elflink/test_memalign.c
@@ -3,8 +3,6 @@
#include <console.h>
#include <errno.h>
-#include "elf_module.h"
-
void perform_allocation(int align) {
int res = 0;
int size = 100;
diff --git a/com32/elflink/elftest.c b/com32/elflink/test_user.c
index 0a38bbe6..0a38bbe6 100644
--- a/com32/elflink/elftest.c
+++ b/com32/elflink/test_user.c
diff --git a/com32/include/klibc/compiler.h b/com32/include/klibc/compiler.h
index 5ac21185..6a938278 100644
--- a/com32/include/klibc/compiler.h
+++ b/com32/include/klibc/compiler.h
@@ -126,4 +126,7 @@
#define __common __attribute__((common))
#define __nocommon __attribute__((nocommon))
+/* Weak symbols */
+#define __weak __attribute__((weak))
+
#endif
diff --git a/com32/lib/Makefile b/com32/lib/Makefile
index 6c137f9d..717e2e56 100644
--- a/com32/lib/Makefile
+++ b/com32/lib/Makefile
@@ -7,7 +7,60 @@ NOGPL := 1
topdir = ../..
include MCONFIG
-LIBOBJS = \
+LIBPNGOBJS = \
+ libpng/png.o libpng/pngset.o libpng/pngget.o libpng/pngrutil.o \
+ libpng/pngtrans.o libpng/pngwutil.o libpng/pngread.o \
+ libpng/pngrio.o libpng/pngwio.o libpng/pngwrite.o \
+ libpng/pngrtran.o libpng/pngwtran.o libpng/pngmem.o \
+ libpng/pngerror.o libpng/pngpread.o
+
+LIBZLIBOBJS = \
+ zlib/adler32.o zlib/compress.o zlib/crc32.o zlib/gzio.o \
+ zlib/uncompr.o zlib/deflate.o zlib/trees.o zlib/zutil.o \
+ zlib/inflate.o zlib/infback.o zlib/inftrees.o zlib/inffast.o
+
+LIBJPGOBJS = \
+ jpeg/tinyjpeg.o jpeg/jidctflt.o jpeg/decode1.o jpeg/decode3.o \
+ jpeg/rgb24.o jpeg/bgr24.o jpeg/yuv420p.o jpeg/grey.o \
+ jpeg/rgba32.o jpeg/bgra32.o
+
+LIBENTRYOBJS = \
+ sys/intcall.o sys/farcall.o sys/cfarcall.o sys/zeroregs.o \
+ sys/entry.o sys/exit.o sys/argv.o sys/times.o \
+ sys/fileinfo.o sys/opendev.o sys/read.o sys/write.o sys/ftell.o \
+ sys/close.o sys/open.o sys/fileread.o sys/fileclose.o \
+ sys/isatty.o sys/fstat.o
+
+LIBVESAOBJS = \
+ sys/vesacon_write.o sys/vesaserial_write.o \
+ sys/vesa/initvesa.o sys/vesa/drawtxt.o sys/vesa/background.o \
+ sys/vesa/alphatbl.o sys/vesa/screencpy.o sys/vesa/fmtpixel.o \
+
+LIBSYSLINUXOBJS = \
+ syslinux/idle.o syslinux/reboot.o \
+ syslinux/features.o syslinux/config.o syslinux/serial.o \
+ syslinux/ipappend.o syslinux/dsinfo.o syslinux/version.o \
+ \
+ syslinux/addlist.o syslinux/freelist.o syslinux/memmap.o \
+ syslinux/movebits.o syslinux/shuffle.o syslinux/shuffle_pm.o \
+ syslinux/shuffle_rm.o syslinux/zonelist.o \
+ syslinux/dump_mmap.o syslinux/dump_movelist.o \
+ \
+ syslinux/run_default.o syslinux/run_command.o \
+ syslinux/cleanup.o syslinux/localboot.o syslinux/runimage.o \
+ \
+ syslinux/loadfile.o syslinux/floadfile.o syslinux/zloadfile.o \
+ \
+ syslinux/load_linux.o syslinux/initramfs.o \
+ syslinux/initramfs_file.o syslinux/initramfs_loadfile.o \
+ syslinux/initramfs_archive.o \
+ \
+ syslinux/pxe_get_cached.o \
+ \
+ syslinux/adv.o syslinux/advwrite.o syslinux/getadv.o \
+ syslinux/setadv.o
+
+LIBOTHEROBJS = \
abort.o atexit.o atoi.o atol.o atoll.o calloc.o creat.o \
ctypes.o errno.o fgetc.o fgets.o fopen.o fprintf.o fputc.o \
fclose.o putchar.o setjmp.o \
@@ -16,9 +69,9 @@ LIBOBJS = \
memcpy.o mempcpy.o memmem.o memmove.o memset.o memswap.o \
exit.o onexit.o \
perror.o printf.o puts.o qsort.o realloc.o seed48.o snprintf.o \
- sprintf.o srand48.o sscanf.o stack.o strcasecmp.o strcat.o \
- strchr.o strcmp.o strcpy.o strpcpy.o strdup.o strlen.o \
- strerror.o strnlen.o \
+ sprintf.o srand48.o sscanf.o strcasecmp.o strcat.o \
+ strchr.o strcmp.o strcpy.o strdup.o strerror.o strlen.o \
+ strnlen.o \
strncasecmp.o strncat.o strncmp.o strncpy.o strndup.o \
stpcpy.o stpncpy.o \
strntoimax.o strntoumax.o strrchr.o strsep.o strspn.o strstr.o \
@@ -34,12 +87,6 @@ LIBOBJS = \
libgcc/__muldi3.o libgcc/__udivmoddi4.o libgcc/__umoddi3.o \
libgcc/__divdi3.o libgcc/__moddi3.o \
\
- sys/intcall.o sys/farcall.o sys/cfarcall.o sys/zeroregs.o \
- sys/entry.o sys/exit.o sys/argv.o sys/times.o \
- sys/fileinfo.o sys/opendev.o sys/read.o sys/write.o sys/ftell.o \
- sys/close.o sys/open.o sys/fileread.o sys/fileclose.o \
- sys/isatty.o sys/fstat.o \
- \
sys/zfile.o sys/zfopen.o \
\
sys/openconsole.o sys/line_input.o \
@@ -55,53 +102,20 @@ LIBOBJS = \
\
sys/ansicon_write.o sys/ansiserial_write.o \
\
- sys/vesacon_write.o sys/vesaserial_write.o \
- sys/vesa/initvesa.o sys/vesa/drawtxt.o sys/vesa/background.o \
- sys/vesa/alphatbl.o sys/vesa/screencpy.o sys/vesa/fmtpixel.o \
- \
pci/cfgtype.o pci/scan.o \
pci/readb.o pci/readw.o pci/readl.o pci/readbios.o \
pci/writeb.o pci/writew.o pci/writel.o pci/writebios.o \
\
- zlib/adler32.o zlib/compress.o zlib/crc32.o zlib/gzio.o \
- zlib/uncompr.o zlib/deflate.o zlib/trees.o zlib/zutil.o \
- zlib/inflate.o zlib/infback.o zlib/inftrees.o zlib/inffast.o \
- \
- libpng/png.o libpng/pngset.o libpng/pngget.o libpng/pngrutil.o \
- libpng/pngtrans.o libpng/pngwutil.o libpng/pngread.o \
- libpng/pngrio.o libpng/pngwio.o libpng/pngwrite.o \
- libpng/pngrtran.o libpng/pngwtran.o libpng/pngmem.o \
- libpng/pngerror.o libpng/pngpread.o \
- \
- jpeg/tinyjpeg.o jpeg/jidctflt.o jpeg/decode1.o jpeg/decode3.o \
- jpeg/rgb24.o jpeg/bgr24.o jpeg/yuv420p.o jpeg/grey.o \
- jpeg/rgba32.o jpeg/bgra32.o \
- \
- sys/x86_init_fpu.o math/pow.o math/strtod.o \
- \
- syslinux/idle.o syslinux/reboot.o \
- syslinux/features.o syslinux/config.o syslinux/serial.o \
- syslinux/ipappend.o syslinux/dsinfo.o syslinux/version.o \
- syslinux/keyboard.o \
- \
- syslinux/addlist.o syslinux/freelist.o syslinux/memmap.o \
- syslinux/movebits.o syslinux/shuffle.o syslinux/shuffle_pm.o \
- syslinux/shuffle_rm.o syslinux/zonelist.o \
- syslinux/dump_mmap.o syslinux/dump_movelist.o \
- \
- syslinux/run_default.o syslinux/run_command.o \
- syslinux/cleanup.o syslinux/localboot.o syslinux/runimage.o \
- \
- syslinux/loadfile.o syslinux/floadfile.o syslinux/zloadfile.o \
- \
- syslinux/load_linux.o syslinux/initramfs.o \
- syslinux/initramfs_file.o syslinux/initramfs_loadfile.o \
- syslinux/initramfs_archive.o \
- \
- syslinux/pxe_get_cached.o syslinux/pxe_get_nic.o \
- \
- syslinux/adv.o syslinux/advwrite.o syslinux/getadv.o \
- syslinux/setadv.o
+ sys/x86_init_fpu.o math/pow.o math/strtod.o
+
+LIBOBJS = \
+ $(LIBOTHEROBJS) \
+ $(LIBENTRYOBJS) \
+ $(LIBZLIBOBJS) \
+ $(LIBPNGOBJS) \
+ $(LIBVESAOBJS) \
+ $(LIBJPGOBJS) \
+ $(LIBSYSLINUXOBJS)
BINDIR = /usr/bin
LIBDIR = /usr/lib
@@ -110,18 +124,25 @@ AUXDIR = $(DATADIR)/syslinux
INCDIR = /usr/include
COM32DIR = $(AUXDIR)/com32
-all: libcom32.a
+all: libcom32.a klibc.dyn
libcom32.a : $(LIBOBJS)
rm -f $@
$(AR) cq $@ $^
$(RANLIB) $@
-tidy dist clean:
+klibc.dyn : $(LIBOTHEROBJS)
+ rm -f $@
+ $(LD) -shared -o $@ $(LIBOTHEROBJS)
+
+tidy dist:
rm -f sys/vesa/alphatbl.c
find . \( -name \*.o -o -name \*.a -o -name .\*.d -o -name \*.tmp \) -print0 | \
xargs -0r rm -f
+clean: tidy
+ rm -f *.a *.dyn
+
spotless: clean
rm -f *.a
rm -f *~ \#* */*~ */\#*
diff --git a/com32/lib/stack.c b/com32/lib/stack.c
index dd7d9d46..f1c9ea2b 100644
--- a/com32/lib/stack.c
+++ b/com32/lib/stack.c
@@ -1,4 +1,4 @@
#include <stdlib.h>
/* Default stack size 8 MB */
-size_t __stack_size = 8 << 20;
+size_t __weak __stack_size = 8 << 20;