summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-05-28 18:58:00 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-05-28 18:58:00 -0700
commit4ba801edb01acae7281fe09f6225c38390033817 (patch)
tree6bee72af361b984332a6414297f2c10f4d6016ad
parentff747ef4c75c9e55c9d5c5552126d994c96da245 (diff)
downloadsyslinux-4ba801edb01acae7281fe09f6225c38390033817.tar.gz
Assemble via ELF, to enable future linking
Assemble all files to ELF instead of using the NASM built-in linker. This can enable us to do actual linking in the future.
-rw-r--r--.gitignore1
-rw-r--r--Makefile40
-rw-r--r--dos/Makefile3
-rw-r--r--extlinux.asm2
-rw-r--r--extlinux/Makefile3
-rw-r--r--extlinux/main.c (renamed from extlinux/extlinux.c)0
-rw-r--r--head.inc2
-rw-r--r--layout.inc52
-rw-r--r--ldlinux.asm2
-rwxr-xr-xlstadjust.pl10
-rw-r--r--mtools/Makefile3
-rw-r--r--syslinux.ld105
-rw-r--r--unix/Makefile3
13 files changed, 168 insertions, 58 deletions
diff --git a/.gitignore b/.gitignore
index fc5482cc..cd35dd2f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,6 +17,7 @@
*.orig
*.rej
*.s
+*.sec
*.sys
*_bin.c
*~
diff --git a/Makefile b/Makefile
index cbdb7b53..e1b71917 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,8 @@
#
# No builtin rules
-MAKEFLAGS = -r
+MAKEFLAGS += -r
+MAKE += -r
TMPFILE = $(shell mktemp /tmp/gcc_ok.XXXXXX)
@@ -33,6 +34,9 @@ PIC = -fPIC
LDFLAGS = -O2 -s $(LDHASH)
AR = ar
RANLIB = ranlib
+LD = ld
+OBJCOPY = objcopy
+OBJDUMP = objdump
NASM = nasm
NASMOPT = -O9999
@@ -145,20 +149,26 @@ version.h: version version.pl
kwdhash.gen: keywords genhash.pl
$(PERL) genhash.pl < keywords > kwdhash.gen
+.PRECIOUS: %.elf
+
# Standard rule for {isolinux,isolinux-debug}.bin
-iso%.bin: iso%.asm kwdhash.gen version.gen
- $(NASM) $(NASMOPT) -f bin -DDATE_STR="'$(DATE)'" -DHEXDATE="$(HEXDATE)" \
- -DMAP=$(@:.bin=.map) -l $(@:.bin=.lsr) -o $@ $<
- $(PERL) lstadjust.pl $(@:.bin=.lsr) $(@:.bin=.map) $(@:.bin=.lst)
+iso%.bin: iso%.elf
+ $(OBJCOPY) -O binary $< $@
$(PERL) checksumiso.pl $@
- $(PERL) checkov.pl $(@:.bin=.map) $@
# Standard rule for {ldlinux,pxelinux,extlinux}.bin
-%.bin: %.asm kwdhash.gen version.gen
- $(NASM) $(NASMOPT) -f bin -DDATE_STR="'$(DATE)'" -DHEXDATE="$(HEXDATE)" \
- -DMAP=$(@:.bin=.map) -l $(@:.bin=.lsr) -o $@ $<
- $(PERL) lstadjust.pl $(@:.bin=.lsr) $(@:.bin=.map) $(@:.bin=.lst)
- $(PERL) checkov.pl $(@:.bin=.map) $@
+%.bin: %.elf
+ $(OBJCOPY) -O binary $< $@
+
+%.o: %.asm kwdhash.gen version.gen
+ $(NASM) $(NASMOPT) -f elf -F stabs -DDATE_STR="'$(DATE)'" \
+ -DHEXDATE="$(HEXDATE)" \
+ -l $(@:.o=.lsr) -o $@ $<
+
+%.elf: %.o syslinux.ld
+ $(LD) -m elf_i386 -T syslinux.ld -M -o $@ $< > $(@:.elf=.map)
+ $(OBJDUMP) -h $@ > $(@:.elf=.sec)
+ $(PERL) lstadjust.pl $(@:.elf=.lsr) $(@:.elf=.sec) $(@:.elf=.lst)
pxelinux.0: pxelinux.bin
cp -f $< $@
@@ -230,13 +240,13 @@ netinstall: installer
install -m 644 $(NETINSTALLABLE) $(INSTALLROOT)$(TFTPBOOT)
local-tidy:
- rm -f *.o *_bin.c stupid.* patch.offset
- rm -f *.lsr *.lst *.map
+ rm -f *.o *.elf *_bin.c stupid.* patch.offset
+ rm -f *.lsr *.lst *.map *.sec
rm -f $(OBSOLETE)
- $(MAKE) -C gpxe/src veryclean
tidy: local-tidy
set -e ; for i in $(BESUBDIRS) $(IESUBDIRS) $(BSUBDIRS) $(ISUBDIRS) ; do $(MAKE) -C $$i $@ ; done
+ $(MAKE) -C gpxe/src veryclean
local-clean:
rm -f $(ITARGET)
@@ -258,7 +268,7 @@ spotless: local-clean dist local-spotless
.depend:
rm -f .depend
for csrc in $(CSRC) ; do $(CC) $(INCLUDE) -MM $$csrc >> .depend ; done
- for nsrc in $(NASMSRC) ; do $(NASM) -DDEPEND $(NINCLUDE) -o `echo $$nsrc | sed -e 's/\.asm/\.bin/'` -M $$nsrc >> .depend ; done
+ for nsrc in $(NASMSRC) ; do $(NASM) -DDEPEND $(NINCLUDE) -o `echo $$nsrc | sed -e 's/\.asm/\.o/'` -M $$nsrc >> .depend ; done
local-depend:
rm -f .depend
diff --git a/dos/Makefile b/dos/Makefile
index 964c7fdc..04550dab 100644
--- a/dos/Makefile
+++ b/dos/Makefile
@@ -21,7 +21,8 @@ RANLIB = ranlib
LIBGCC := $(shell $(CC) --print-libgcc)
SRCS = syslinux.c \
- ../syslxmod.c ../bootsect_bin.c ../ldlinux_bin.c ../mbr_bin.c \
+ ../libinstaller/syslxmod.c \
+ ../bootsect_bin.c ../ldlinux_bin.c ../mbr_bin.c \
$(wildcard ../libfat/*.c)
OBJS = crt0.o $(patsubst %.c,%.o,$(notdir $(SRCS)))
LIBOBJS = conio.o memcpy.o memset.o skipatou.o atou.o malloc.o free.o \
diff --git a/extlinux.asm b/extlinux.asm
index 2b43533b..6c2946c2 100644
--- a/extlinux.asm
+++ b/extlinux.asm
@@ -143,7 +143,7 @@ OrigESDI equ StackBuf-4 ; The high dword on the stack
; "magic number" (using the term very loosely) for the DOS superblock.
;
bootsec equ $
- jmp short start ; 2 bytes
+_start: jmp short start ; 2 bytes
nop ; 1 byte
;
; "Superblock" follows -- it's in the boot sector, so it's already
diff --git a/extlinux/Makefile b/extlinux/Makefile
index f4267020..88d4d1a9 100644
--- a/extlinux/Makefile
+++ b/extlinux/Makefile
@@ -12,7 +12,8 @@ INCLUDES = -I. -I.. -I../libinstaller
CFLAGS = -W -Wall -Wno-sign-compare -D_FILE_OFFSET_BITS=64 $(OPTFLAGS) $(INCLUDES)
LDFLAGS = $(LDHASH) # -s
-SRCS = extlinux.c setadv.c extlinux_bss_bin.c extlinux_sys_bin.c
+SRCS = main.c ../libinstaller/setadv.c \
+ ../extlinux_bss_bin.c ../extlinux_sys_bin.c
OBJS = $(patsubst %.c,%.o,$(notdir $(SRCS)))
.SUFFIXES: .c .o .i .s .S
diff --git a/extlinux/extlinux.c b/extlinux/main.c
index 0edce5a5..0edce5a5 100644
--- a/extlinux/extlinux.c
+++ b/extlinux/main.c
diff --git a/head.inc b/head.inc
index 95a7d193..928f07fb 100644
--- a/head.inc
+++ b/head.inc
@@ -21,10 +21,10 @@
%include "macros.inc"
%include "config.inc"
+%include "layout.inc"
%include "kernel.inc"
%include "bios.inc"
%include "tracers.inc"
-%include "layout.inc"
%include "stack.inc"
%endif ; _HEAD_INC
diff --git a/layout.inc b/layout.inc
index c800f1b1..f58ec8fa 100644
--- a/layout.inc
+++ b/layout.inc
@@ -16,6 +16,8 @@
; Memory layout of segments
;
+ ; Default to 16-bit code
+ bits 16
; Memory below 0800h is reserved for the BIOS and the MBR.
BSS_START equ 0800h
@@ -28,11 +30,6 @@ TEXT_START equ 7C00h
; but it doesn't seem to work that way.
LATEBSS_START equ 0B800h
-; Reserve memory for the stack. This causes checkov to abort the
-; compile if we violate this space.
-STACK_SIZE equ 4096
-STACK_START equ TEXT_START-STACK_SIZE
-
%ifdef MAP
[map all MAP]
%endif
@@ -40,18 +37,16 @@ STACK_START equ TEXT_START-STACK_SIZE
;
; The various sections and their relationship
;
- org TEXT_START
-
; Use .earlybss for things that MUST be in low memory.
section .earlybss nobits start=BSS_START
- section .bcopy32 align=4 valign=16 follows=.data vfollows=.earlybss
- section .config align=4 valign=16 follows=.bcopy32 vfollows=.bcopy32
- section .config.end nobits valign=4 vfollows=.config
+ section .bcopy32 exec nowrite progbits align=4
+ section .config write progbits align=4
+ section .config.end write nobits align=4
; Use .bss for things that doesn't have to be in low memory;
; with .bss1 and .bss2 to offload. .earlybss should be used
; for things that absolutely have to be below 0x7c00.
- section .bss nobits valign=16 vfollows=.config.end
+ section .bss write nobits align=16
; Warning here: RBFG build 22 randomly overwrites
; memory location [0x5680,0x576c), possibly more. It
@@ -59,37 +54,38 @@ STACK_START equ TEXT_START-STACK_SIZE
; pointer to its own internal packet buffer and starts
; writing a received ARP packet into low memory.
%if IS_PXELINUX
- section .rbfg nobits start=0x5680
+ section .rbfg write nobits
RBFG_brainfuck: resb 2048 ; Bigger than an Ethernet packet...
%endif
; For section following .rbfg
%if IS_PXELINUX
- section .bss2 nobits valign=16 vfollows=.rbfg
+ section .bss2 write nobits align=16
%else
- section .bss2 nobits valign=16 vfollows=.bss
+ section .bss2 write nobits align=16
%endif
- section .text start=TEXT_START
- ; NASM BUG: .data always follows .text; can't override
- section .data align=16 ; follows=.text
-
- ; This empty section works around a NASM bug with regards
- ; to follows= and nobits sections following a section which
- ; has VMA != LMA.
- section .advpad progbits align=512 follows=.config
+ section .text exec write progbits align=16
+ section .data write progbits align=16
- section .adv nobits align=512 follows=.advpad
+ section .adv write nobits align=512
; .uibss contains bss data which is guaranteed to be
; safe to clobber during the loading of the image. This
; is because while loading the primary image we will clobber
; the spillover from the last fractional sector load.
- section .uibss nobits align=16 follows=.adv
+ section .uibss write nobits align=16
; Normal bss...
- section .bss1 nobits align=16 follows=.uibss
+ section .bss1 write nobits align=16
+
+ ; Symbols from linker script
+ extern Stack
+ extern section..bcopy32.start
+ extern section..config.start
+ extern section..config.vstart
+ extern section..config.end.start
+
+ global _start
- ; Reserve space for stack
- section .stack nobits align=16 start=STACK_START
-Stack resb STACK_SIZE
+ section .text
diff --git a/ldlinux.asm b/ldlinux.asm
index 012fd3da..86de4588 100644
--- a/ldlinux.asm
+++ b/ldlinux.asm
@@ -151,7 +151,7 @@ OrigESDI equ StackBuf-4 ; The high dword on the stack
; "magic number" (using the term very loosely) for the DOS superblock.
;
bootsec equ $
- jmp short start ; 2 bytes
+_start: jmp short start ; 2 bytes
nop ; 1 byte
;
; "Superblock" follows -- it's in the boot sector, so it's already
diff --git a/lstadjust.pl b/lstadjust.pl
index 381c86c3..cec54029 100755
--- a/lstadjust.pl
+++ b/lstadjust.pl
@@ -18,16 +18,10 @@ open(OUT, "> $outfile\0")
or die "$0: cannot create: $outfile: $!\n";
%vstart = ();
-undef $sec;
while (defined($line = <MAP>)) {
- chomp $line;
- if ($line =~ /^\-+\s+Section\s+(\S+)\s+\-/) {
- $sec = $1;
- }
- next unless (defined($sec));
- if ($line =~ /^vstart:\s+([0-9a-f]+)/i) {
- $vstart{$sec} = hex $1;
+ if ($line =~ /^\s*([0-9]+)\s+(\S+)\s+([0-9a-f]+)\s+([0-9a-f]+)\s+([0-9a-f]+)\s+([0-9a-f]+)\s+2\*\*([0-9]+)/i) {
+ $vstart{$2} = hex $4;
}
}
close(MAP);
diff --git a/mtools/Makefile b/mtools/Makefile
index 7175bb3f..a53e378f 100644
--- a/mtools/Makefile
+++ b/mtools/Makefile
@@ -12,7 +12,8 @@ INCLUDES = -I. -I.. -I../libfat -I../libinstaller
CFLAGS = -W -Wall -D_FILE_OFFSET_BITS=64 $(OPTFLAGS) $(INCLUDES)
LDFLAGS = $(LDHASH) -s
-SRCS = syslinux.c ../syslxmod.c ../bootsect_bin.c ../ldlinux_bin.c $(wildcard ../libfat/*.c)
+SRCS = syslinux.c ../syslxmod.c ../bootsect_bin.c ../ldlinux_bin.c \
+ $(wildcard ../libfat/*.c)
OBJS = $(patsubst %.c,%.o,$(notdir $(SRCS)))
.SUFFIXES: .c .o .i .s .S
diff --git a/syslinux.ld b/syslinux.ld
new file mode 100644
index 00000000..d6fa685d
--- /dev/null
+++ b/syslinux.ld
@@ -0,0 +1,105 @@
+/*
+ * Linker script for the SYSLINUX core
+ */
+
+OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
+OUTPUT_ARCH(i386)
+EXTERN(_start)
+ENTRY(_start)
+
+STACK_LEN = 4096;
+
+SECTIONS
+{
+ /* "Early" sections (before the load) */
+ . = 0x0800;
+
+ .earlybss : {
+ __earlybss_start = .;
+ *(.earlybss)
+ __earlybss_len = . - __earlybss_start;
+ }
+
+ .bcopy32 : AT (__bcopy32_lma) {
+ FILL(0x90909090)
+ __bcopy32_start = .;
+ *(.bcopy32)
+ __bcopy32_len = . - __bcopy32_start;
+ }
+
+ .config : AT (__config_lma) {
+ __config_start = .;
+ *(.config)
+ __config_len = . - __config_start;
+ }
+
+ .bss : AT(__bss_start) {
+ __bss_start = .;
+ *(.bss)
+ *(.bss2)
+ __bss_len = . - __bss_start;
+ }
+
+ /* Stack */
+
+ . = 0x7c00 - STACK_LEN;
+ .stack : {
+ __stack_start = .;
+ . += STACK_LEN;
+ __stack_len = . - __stack_start;
+ }
+
+ /* Initialized sections */
+
+ . = 0x7c00;
+ .text : {
+ FILL(0x90909090)
+ __text_start = .;
+ *(.text)
+ __text_len = . - __text_start;
+ }
+
+ . = ALIGN(4);
+ __bcopy32_lma = .;
+ . += SIZEOF(.bcopy32);
+
+ . = ALIGN(4);
+ .data : {
+ __data_start = .;
+ *(.data)
+ __data_len = . - __data_start;
+ }
+
+ . = ALIGN(4);
+ __config_lma = .;
+ . += SIZEOF(.config);
+
+ /* ADV, must be the last intialized section */
+
+ . = ALIGN(512);
+ .adv : {
+ __adv_start = .;
+ *(.adv)
+ __adv_len = . - __adv_start;
+ }
+
+ /* Late uninitialized sections */
+
+ .uibss : {
+ __uibss_start = .;
+ *(.uibss)
+ __uibss_len = . - __uibss_start;
+ }
+
+ .bss1 : {
+ __bss1_start = .;
+ *(.bss1)
+ __bss1_len = . - __bss1_start;
+ }
+
+ Stack = __stack_start;
+ section..bcopy32.start = __bcopy32_lma;
+ section..config.start = __config_lma;
+ section..config.vstart = __config_start;
+ section..config.end.start = __config_start + SIZEOF(.config);
+}
diff --git a/unix/Makefile b/unix/Makefile
index 8d92d3a2..07f97d67 100644
--- a/unix/Makefile
+++ b/unix/Makefile
@@ -12,7 +12,8 @@ INCLUDES = -I. -I.. -I../libinstaller
CFLAGS = -W -Wall -D_FILE_OFFSET_BITS=64 $(OPTFLAGS) $(INCLUDES)
LDFLAGS = $(LDHASH) -s
-SRCS = syslinux.c ../syslxmod.c ../bootsect_bin.c ../ldlinux_bin.c
+SRCS = syslinux.c ../libinstaller/syslxmod.c \
+ ../bootsect_bin.c ../ldlinux_bin.c
OBJS = $(patsubst %.c,%.o,$(notdir $(SRCS)))
.SUFFIXES: .c .o .i .s .S