2008-02-26 04:25:15 +01:00
|
|
|
# Legacy Bios build system
|
|
|
|
#
|
|
|
|
# Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
|
|
|
|
#
|
|
|
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
|
|
|
|
|
|
|
# Output directory
|
|
|
|
OUT=out/
|
|
|
|
|
|
|
|
# Source files
|
2008-07-06 16:14:49 +02:00
|
|
|
SRCBOTH=output.c util.c floppy.c ata.c system.c mouse.c kbd.c pci.c \
|
2008-07-20 16:08:59 +02:00
|
|
|
serial.c clock.c pic.c cdrom.c ps2port.c
|
2008-08-17 17:11:07 +02:00
|
|
|
SRC16=$(SRCBOTH) disk.c apm.c pcibios.c vgahooks.c
|
2008-07-06 16:14:49 +02:00
|
|
|
SRC32=$(SRCBOTH) post.c shadow.c post_menu.c memmap.c coreboot.c boot.c \
|
2008-11-02 01:32:27 +01:00
|
|
|
acpi.c pirtable.c smm.c smpdetect.c mptable.c smbios.c pciinit.c \
|
|
|
|
optionroms.c
|
2008-03-02 17:24:36 +01:00
|
|
|
TABLESRC=font.c cbt.c floppy_dbt.c
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2008-02-27 16:41:41 +01:00
|
|
|
cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
|
|
|
|
/dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;)
|
|
|
|
|
2008-02-27 03:33:14 +01:00
|
|
|
# Default compiler flags
|
2008-04-13 22:59:03 +02:00
|
|
|
COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=3 \
|
|
|
|
-mpreferred-stack-boundary=2 -mrtd \
|
2008-03-12 00:32:38 +01:00
|
|
|
-ffreestanding -fwhole-program -fomit-frame-pointer \
|
|
|
|
-fno-delete-null-pointer-checks
|
2008-02-27 16:41:41 +01:00
|
|
|
COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
|
|
|
|
COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
|
|
|
|
COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
|
|
|
|
|
2008-07-31 02:37:13 +02:00
|
|
|
override CFLAGS = $(COMMONCFLAGS) -g -DMODE16=0
|
2008-07-13 17:08:36 +02:00
|
|
|
CFLAGS16INC = $(COMMONCFLAGS) -DMODE16=1 -fno-jump-tables -fno-defer-pop \
|
2008-05-13 05:44:57 +02:00
|
|
|
$(call cc-option,$(CC),--param large-stack-frame=8,)
|
2008-03-03 02:48:35 +01:00
|
|
|
CFLAGS16 = $(CFLAGS16INC) -g
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2008-03-02 17:24:36 +01:00
|
|
|
TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC)))
|
2008-05-10 21:49:20 +02:00
|
|
|
all: $(OUT) $(OUT)bios.bin $(TABLETMP)
|
2008-02-26 04:25:15 +01:00
|
|
|
|
|
|
|
# Run with "make V=1" to see the actual compile commands
|
|
|
|
ifdef V
|
|
|
|
Q=
|
|
|
|
else
|
|
|
|
Q=@
|
|
|
|
endif
|
|
|
|
|
|
|
|
.PHONY : all FORCE
|
|
|
|
|
|
|
|
vpath %.c src
|
|
|
|
vpath %.S src
|
|
|
|
|
|
|
|
################ Build rules
|
2008-03-03 02:48:35 +01:00
|
|
|
|
|
|
|
# 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.
|
|
|
|
ifdef AVOIDCOMBINE
|
|
|
|
DEPHACK=
|
|
|
|
define whole-compile
|
|
|
|
@echo " Compiling whole program $3"
|
|
|
|
$(Q)/bin/echo -e '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
|
|
|
|
$(Q)$(CC) $1 -c $3.tmp.c -o $3
|
|
|
|
endef
|
|
|
|
else
|
|
|
|
# Ugly way to get gcc to generate .d files correctly.
|
|
|
|
DEPHACK=-combine src/null.c
|
|
|
|
define whole-compile
|
|
|
|
@echo " Compiling whole program $3"
|
|
|
|
$(Q)$(CC) $1 -combine -c $2 -o $3
|
|
|
|
endef
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
2008-02-26 04:25:15 +01:00
|
|
|
$(OUT)%.proc.16.s: $(OUT)%.16.s
|
|
|
|
@echo " Moving data sections to text in $<"
|
2008-02-29 02:01:11 +01:00
|
|
|
$(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
|
|
|
$(OUT)%.16.s: %.c
|
|
|
|
@echo " Generating assembler for $<"
|
2008-03-03 02:48:35 +01:00
|
|
|
$(Q)$(CC) $(CFLAGS16INC) $(DEPHACK) -S -c $< -o $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
|
|
|
$(OUT)%.lds: %.lds.S
|
|
|
|
@echo " Precompiling $<"
|
|
|
|
$(Q)$(CPP) -P $< -o $@
|
|
|
|
|
|
|
|
|
2008-03-03 02:48:35 +01:00
|
|
|
$(OUT)blob.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@)
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2008-03-02 17:24:36 +01:00
|
|
|
TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC)))
|
2008-05-13 00:28:58 +02:00
|
|
|
$(OUT)romlayout16.o: romlayout.S $(OUT)blob.16.s $(TABLEASM)
|
2008-02-26 04:25:15 +01:00
|
|
|
@echo " Generating 16bit layout of $@"
|
|
|
|
$(Q)$(CC) $(CFLAGS16) -c $< -o $@
|
|
|
|
|
2008-07-06 02:41:53 +02:00
|
|
|
$(OUT)romlayout32.o: ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@)
|
|
|
|
|
2008-07-06 15:56:14 +02:00
|
|
|
$(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
|
2008-07-06 02:41:53 +02:00
|
|
|
@echo " Linking (no relocs) $@"
|
2008-07-06 15:56:14 +02:00
|
|
|
$(Q)ld -r -T $(OUT)rombios32.lds $< -o $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2008-07-06 15:56:14 +02:00
|
|
|
$(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)rombios16.lds
|
2008-07-06 02:41:53 +02:00
|
|
|
@echo " Linking $@"
|
2008-07-06 15:56:14 +02:00
|
|
|
$(Q)objcopy --prefix-symbols=_code32_ $(OUT)rom32.o $(OUT)rom32.rename.o
|
|
|
|
$(Q)ld -T $(OUT)rombios16.lds -R $(OUT)rom32.rename.o $< -o $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2008-07-06 15:56:14 +02:00
|
|
|
$(OUT)rom.o: $(OUT)rom16.o $(OUT)rom32.o $(OUT)rombios.lds
|
2008-02-26 04:25:15 +01:00
|
|
|
@echo " Linking $@"
|
2008-07-06 15:56:14 +02:00
|
|
|
$(Q)ld -T $(OUT)rombios.lds $(OUT)rom16.o $(OUT)rom32.o -o $@
|
2008-07-06 02:41:53 +02:00
|
|
|
|
2008-07-06 15:56:14 +02:00
|
|
|
$(OUT)bios.bin.elf: $(OUT)rom.o
|
2008-07-06 03:08:56 +02:00
|
|
|
@echo " Prepping $@"
|
|
|
|
$(Q)nm $< | ./tools/checkrom.py
|
2008-07-06 02:41:53 +02:00
|
|
|
$(Q)strip $< -o $@
|
|
|
|
|
|
|
|
$(OUT)bios.bin: $(OUT)bios.bin.elf
|
|
|
|
@echo " Extracting binary $@"
|
|
|
|
$(Q)objcopy -O binary $< $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
####### Generic rules
|
|
|
|
clean:
|
|
|
|
rm -rf $(OUT)
|
|
|
|
|
|
|
|
$(OUT):
|
|
|
|
mkdir $@
|
|
|
|
|
|
|
|
-include $(OUT)*.d
|