Forward port bochs smp changes; rename smpdetect.c to smp.c.
[seabios.git] / Makefile
index 3a4a1e9345bc937f2fbe91696d7a408f24da0d33..71e3cb48b0df271c9dd7795a5201e47264d373e0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ OUT=out/
 
 # Source files
 SRCBOTH=output.c util.c floppy.c ata.c misc.c mouse.c kbd.c pci.c \
-        serial.c clock.c pic.c cdrom.c ps2port.c smpdetect.c resume.c \
+        serial.c clock.c pic.c cdrom.c ps2port.c smp.c resume.c \
         pnpbios.c pirtable.c
 SRC16=$(SRCBOTH) system.c disk.c apm.c pcibios.c vgahooks.c font.c
 SRC32=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \
@@ -22,18 +22,19 @@ cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
 # Default compiler flags
 COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=3 \
                -mpreferred-stack-boundary=2 -mrtd -freg-struct-return \
-               -ffreestanding -fwhole-program -fomit-frame-pointer \
+               -ffreestanding -fomit-frame-pointer \
                -fno-delete-null-pointer-checks -Wno-strict-aliasing \
+               -ffunction-sections -fdata-sections -fno-common \
                -minline-all-stringops
 COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
 
 override CFLAGS = $(COMMONCFLAGS) -g -DMODE16=0
-CFLAGS16INC = $(COMMONCFLAGS) -DMODE16=1 -fno-jump-tables -fno-defer-pop \
+CFLAGS16INC = $(COMMONCFLAGS) -DMODE16=1 -fno-defer-pop \
+              $(call cc-option,$(CC),-fno-jump-tables,-DMANUAL_NO_JUMP_TABLE) \
               $(call cc-option,$(CC),-fno-tree-switch-conversion,) \
               $(call cc-option,$(CC),--param large-stack-frame=4,)
-CFLAGS16INC += -ffunction-sections -fdata-sections
 CFLAGS16 = $(CFLAGS16INC) -g
 
 all: $(OUT) $(OUT)bios.bin
@@ -57,30 +58,40 @@ vpath %.S src vgasrc
 
 ################ Build rules
 
+# Verify the gcc configuration and test if -fwhole-program works.
 TESTGCC:=$(shell CC=$(CC) tools/test-gcc.sh)
 ifeq "$(TESTGCC)" "-1"
 $(error "Please upgrade GCC")
 endif
 
-ifndef AVOIDCOMBINE
-AVOIDCOMBINE=$(TESTGCC)
+ifndef COMPSTRAT
+COMPSTRAT=$(TESTGCC)
 endif
 
-# Do a whole file compile - two methods are supported.  The first
-# involves including all the content textually via #include
-# directives.  The second method uses gcc's "-combine" option.
-ifeq "$(AVOIDCOMBINE)" "1"
+# Do a whole file compile - three methods are supported.
+ifeq "$(COMPSTRAT)" "1"
+# First method - use -fwhole-program without -combine.
+define whole-compile
+@echo "  Compiling whole program $3"
+$(Q)printf '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
+$(Q)$(CC) $1 -fwhole-program -DWHOLE_PROGRAM -c $3.tmp.c -o $3
+endef
+else
+ifeq "$(COMPSTRAT)" "2"
+# Second menthod - don't use -fwhole-program at all.
 define whole-compile
 @echo "  Compiling whole program $3"
 $(Q)printf '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
 $(Q)$(CC) $1 -c $3.tmp.c -o $3
 endef
 else
+# Third (and preferred) method - use -fwhole-program with -combine
 define whole-compile
 @echo "  Compiling whole program $3"
-$(Q)$(CC) $1 -combine -c $2 -o $3
+$(Q)$(CC) $1 -fwhole-program -DWHOLE_PROGRAM -combine -c $2 -o $3
 endef
 endif
+endif
 
 
 $(OUT)%.s: %.c
@@ -107,11 +118,14 @@ $(OUT)rom32.o: $(OUT)ccode32.o $(OUT)rombios32.lds
        @echo "  Linking (no relocs) $@"
        $(Q)$(LD) -r -T $(OUT)rombios32.lds $< -o $@
 
-$(OUT)romlayout.lds: $(OUT)romlayout16.o
+$(OUT)romlayout16.lds $(OUT)romlayout32.lds: $(OUT)ccode32.o $(OUT)romlayout16.o
        @echo "  Building layout information $@"
-       $(Q)$(OBJDUMP) -h $< | ./tools/layoutrom.py $@
+       $(Q)$(OBJDUMP) -thr $(OUT)ccode32.o > $(OUT)ccode32.o.objdump
+       $(Q)$(OBJDUMP) -thr $(OUT)romlayout16.o > $(OUT)romlayout16.o.objdump
+       $(Q)./tools/layoutrom.py $(OUT)romlayout16.o.objdump $(OUT)ccode32.o.objdump $(OUT)romlayout16.lds $(OUT)romlayout32.lds
 
-$(OUT)layout16.lds: $(OUT)romlayout.lds
+$(OUT)layout16.lds: $(OUT)romlayout16.lds
+$(OUT)rombios32.lds: $(OUT)romlayout32.lds
 
 $(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)layout16.lds
        @echo "  Linking (no relocs) $@"
@@ -119,8 +133,8 @@ $(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)layout16.lds
 
 $(OUT)rom.o: $(OUT)rom16.o $(OUT)rom32.o $(OUT)rombios16.lds $(OUT)rombios.lds
        @echo "  Linking $@"
-       $(Q)$(LD) -T $(OUT)rombios16.lds $(OUT)rom16.o -R $(OUT)rom32.o -o $(OUT)rom16.final.o
-       $(Q)$(STRIP) $(OUT)rom16.final.o
+       $(Q)$(LD) -T $(OUT)rombios16.lds $(OUT)rom16.o -R $(OUT)rom32.o -o $(OUT)rom16.reloc.o
+       $(Q)$(STRIP) $(OUT)rom16.reloc.o -o $(OUT)rom16.final.o
        $(Q)$(OBJCOPY) --extract-symbol --adjust-vma 0xf0000 $(OUT)rom16.o $(OUT)rom16.moved.o
        $(Q)$(LD) -T $(OUT)rombios.lds $(OUT)rom16.final.o $(OUT)rom32.o -R $(OUT)rom16.moved.o -o $@
 
@@ -148,7 +162,7 @@ $(OUT)vgalayout16.o: vgaentry.S $(OUT)vgaccode.16.s $(OUT)asm-offsets.h
 
 $(OUT)vgarom.o: $(OUT)vgalayout16.o $(OUT)vgalayout.lds
        @echo "  Linking $@"
-       $(Q)$(LD) -T $(OUT)vgalayout.lds $(OUT)vgalayout16.o -o $@
+       $(Q)$(LD) --gc-sections -T $(OUT)vgalayout.lds $(OUT)vgalayout16.o -o $@
 
 $(OUT)vgabios.bin.raw: $(OUT)vgarom.o
        @echo "  Extracting binary $@"