2008-02-26 04:25:15 +01:00
|
|
|
# Legacy Bios build system
|
|
|
|
#
|
|
|
|
# Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
|
|
|
|
#
|
2009-01-16 02:52:58 +01:00
|
|
|
# This file may be distributed under the terms of the GNU LGPLv3 license.
|
2008-02-26 04:25:15 +01:00
|
|
|
|
|
|
|
# Output directory
|
|
|
|
OUT=out/
|
|
|
|
|
|
|
|
# Source files
|
2009-01-18 00:49:20 +01:00
|
|
|
SRCBOTH=output.c util.c floppy.c ata.c misc.c mouse.c kbd.c pci.c \
|
2008-12-21 23:51:36 +01:00
|
|
|
serial.c clock.c pic.c cdrom.c ps2port.c smpdetect.c resume.c \
|
2008-12-29 03:50:29 +01:00
|
|
|
pnpbios.c pirtable.c
|
2009-01-18 00:49:20 +01:00
|
|
|
SRC16=$(SRCBOTH) system.c disk.c apm.c pcibios.c vgahooks.c font.c
|
2009-02-08 21:44:08 +01:00
|
|
|
SRC32=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \
|
2009-01-05 03:48:22 +01:00
|
|
|
acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.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 \
|
2009-01-04 17:15:36 +01:00
|
|
|
-fno-delete-null-pointer-checks -Wno-strict-aliasing
|
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 \
|
2009-01-01 23:54:16 +01:00
|
|
|
$(call cc-option,$(CC),--param large-stack-frame=4,)
|
2009-01-17 16:41:28 +01:00
|
|
|
CFLAGS16INC += -ffunction-sections -fdata-sections
|
2008-03-03 02:48:35 +01:00
|
|
|
CFLAGS16 = $(CFLAGS16INC) -g
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2009-01-18 00:49:20 +01:00
|
|
|
all: $(OUT) $(OUT)bios.bin
|
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
|
|
|
|
|
2008-11-08 03:42:00 +01:00
|
|
|
OBJCOPY=objcopy
|
2009-01-17 16:41:28 +01:00
|
|
|
OBJDUMP=objdump
|
2008-11-08 03:42:00 +01:00
|
|
|
NM=nm
|
|
|
|
STRIP=strip
|
|
|
|
|
2008-02-26 04:25:15 +01:00
|
|
|
.PHONY : all FORCE
|
|
|
|
|
|
|
|
vpath %.c src
|
|
|
|
vpath %.S src
|
|
|
|
|
|
|
|
################ Build rules
|
2008-03-03 02:48:35 +01:00
|
|
|
|
2009-01-25 22:11:27 +01:00
|
|
|
ifndef AVOIDCOMBINE
|
|
|
|
AVOIDCOMBINE=$(shell CC=$(CC) tools/test-combine.sh)
|
|
|
|
endif
|
|
|
|
|
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.
|
2009-01-25 22:11:27 +01:00
|
|
|
ifeq "$(AVOIDCOMBINE)" "1"
|
2008-03-03 02:48:35 +01:00
|
|
|
define whole-compile
|
|
|
|
@echo " Compiling whole program $3"
|
2008-11-07 00:57:10 +01:00
|
|
|
$(Q)printf '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
|
2008-03-03 02:48:35 +01:00
|
|
|
$(Q)$(CC) $1 -c $3.tmp.c -o $3
|
|
|
|
endef
|
|
|
|
else
|
|
|
|
define whole-compile
|
|
|
|
@echo " Compiling whole program $3"
|
|
|
|
$(Q)$(CC) $1 -combine -c $2 -o $3
|
|
|
|
endef
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
2009-01-18 00:49:20 +01:00
|
|
|
$(OUT)%.s: %.c
|
2008-12-07 00:56:19 +01:00
|
|
|
@echo " Compiling to assembler $@"
|
2009-01-18 00:49:20 +01:00
|
|
|
$(Q)$(CC) $(CFLAGS16INC) -S -c $< -o $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
|
|
|
$(OUT)%.lds: %.lds.S
|
2008-12-07 00:56:19 +01:00
|
|
|
@echo " Precompiling $@"
|
2008-11-16 15:17:02 +01:00
|
|
|
$(Q)$(CPP) -P -D__ASSEMBLY__ $< -o $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2009-01-18 00:49:20 +01:00
|
|
|
$(OUT)asm-offsets.h: $(OUT)asm-offsets.s
|
2008-11-17 00:14:33 +01:00
|
|
|
@echo " Generating offset file $@"
|
|
|
|
$(Q)./tools/gen-offsets.sh $< $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2008-12-07 00:56:19 +01:00
|
|
|
$(OUT)ccode.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@)
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2009-01-18 00:49:20 +01:00
|
|
|
$(OUT)romlayout16.o: romlayout.S $(OUT)ccode.16.s $(OUT)asm-offsets.h
|
2008-12-07 00:56:19 +01:00
|
|
|
@echo " Compiling (16bit) $@"
|
|
|
|
$(Q)$(CC) $(CFLAGS16INC) -c -D__ASSEMBLY__ $< -o $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2008-12-07 00:56:19 +01:00
|
|
|
$(OUT)ccode32.o: ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@)
|
2008-07-06 02:41:53 +02:00
|
|
|
|
2008-12-07 00:56:19 +01:00
|
|
|
$(OUT)rom32.o: $(OUT)ccode32.o $(OUT)rombios32.lds
|
2008-07-06 02:41:53 +02:00
|
|
|
@echo " Linking (no relocs) $@"
|
2008-11-08 16:36:16 +01:00
|
|
|
$(Q)$(LD) -r -d -T $(OUT)rombios32.lds $< -o $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
2009-01-17 16:41:28 +01:00
|
|
|
$(OUT)romlayout.lds: $(OUT)romlayout16.o
|
|
|
|
@echo " Building layout information $@"
|
2009-01-17 21:17:34 +01:00
|
|
|
$(Q)$(OBJDUMP) -h $< | ./tools/layoutrom.py $@
|
2009-01-17 16:41:28 +01:00
|
|
|
|
|
|
|
$(OUT)rombios16.lds: $(OUT)romlayout.lds
|
|
|
|
|
2008-07-06 15:56:14 +02:00
|
|
|
$(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)rombios16.lds
|
2008-12-07 00:56:19 +01:00
|
|
|
@echo " Linking (16bit) $@"
|
2008-11-07 00:57:10 +01: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-11-07 00:57:10 +01: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 $@"
|
2008-11-07 00:57:10 +01:00
|
|
|
$(Q)$(NM) $< | ./tools/checkrom.py
|
|
|
|
$(Q)$(STRIP) $< -o $@
|
2008-07-06 02:41:53 +02:00
|
|
|
|
|
|
|
$(OUT)bios.bin: $(OUT)bios.bin.elf
|
|
|
|
@echo " Extracting binary $@"
|
2008-11-07 00:57:10 +01:00
|
|
|
$(Q)$(OBJCOPY) -O binary $< $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
####### Generic rules
|
|
|
|
clean:
|
2008-11-07 00:57:10 +01:00
|
|
|
$(Q)rm -rf $(OUT)
|
2008-02-26 04:25:15 +01:00
|
|
|
|
|
|
|
$(OUT):
|
2008-11-07 00:57:10 +01:00
|
|
|
$(Q)mkdir $@
|
2008-02-26 04:25:15 +01:00
|
|
|
|
|
|
|
-include $(OUT)*.d
|