blob: c7ab73a8dea4c8d176661ba1773b1b11b247a3ce [file] [log] [blame]
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05001# Legacy Bios build system
2#
3# Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4#
5# This file may be distributed under the terms of the GNU GPLv3 license.
6
7# Output directory
8OUT=out/
9
10# Source files
Kevin O'Connor44eeaf12008-07-06 10:14:49 -040011SRCBOTH=output.c util.c floppy.c ata.c system.c mouse.c kbd.c pci.c \
12 serial.c clock.c pic.c cdrom.c
13SRC16=$(SRCBOTH) disk.c apm.c pcibios.c
14SRC32=$(SRCBOTH) post.c shadow.c post_menu.c memmap.c coreboot.c boot.c \
Kevin O'Connor0525d292008-07-04 06:18:30 -040015 acpi.c pirtable.c smm.c smpdetect.c mptable.c smbios.c pciinit.c
Kevin O'Connor44c631d2008-03-02 11:24:36 -050016TABLESRC=font.c cbt.c floppy_dbt.c
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050017
Kevin O'Connor786502d2008-02-27 10:41:41 -050018cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
19 /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;)
20
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050021# Default compiler flags
Kevin O'Connorba2d0df2008-04-13 16:59:03 -040022COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=3 \
23 -mpreferred-stack-boundary=2 -mrtd \
Kevin O'Connorbc28a2b2008-03-11 19:32:38 -040024 -ffreestanding -fwhole-program -fomit-frame-pointer \
25 -fno-delete-null-pointer-checks
Kevin O'Connor786502d2008-02-27 10:41:41 -050026COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
27COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
28COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
29
Kevin O'Connor7ab798f2008-07-13 11:08:36 -040030CFLAGS = $(COMMONCFLAGS) -g -DMODE16=0
31CFLAGS16INC = $(COMMONCFLAGS) -DMODE16=1 -fno-jump-tables -fno-defer-pop \
Kevin O'Connora2d16922008-05-12 23:44:57 -040032 $(call cc-option,$(CC),--param large-stack-frame=8,)
Kevin O'Connor410680b2008-03-02 20:48:35 -050033CFLAGS16 = $(CFLAGS16INC) -g
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050034
Kevin O'Connor44c631d2008-03-02 11:24:36 -050035TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC)))
Kevin O'Connor59fead62008-05-10 15:49:20 -040036all: $(OUT) $(OUT)bios.bin $(TABLETMP)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050037
38# Run with "make V=1" to see the actual compile commands
39ifdef V
40Q=
41else
42Q=@
43endif
44
45.PHONY : all FORCE
46
47vpath %.c src
48vpath %.S src
49
50################ Build rules
Kevin O'Connor410680b2008-03-02 20:48:35 -050051
52# Do a whole file compile - two methods are supported. The first
53# involves including all the content textually via #include
54# directives. The second method uses gcc's "-combine" option.
55ifdef AVOIDCOMBINE
56DEPHACK=
57define whole-compile
58@echo " Compiling whole program $3"
59$(Q)/bin/echo -e '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
60$(Q)$(CC) $1 -c $3.tmp.c -o $3
61endef
62else
63# Ugly way to get gcc to generate .d files correctly.
64DEPHACK=-combine src/null.c
65define whole-compile
66@echo " Compiling whole program $3"
67$(Q)$(CC) $1 -combine -c $2 -o $3
68endef
69endif
70
71
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050072$(OUT)%.proc.16.s: $(OUT)%.16.s
73 @echo " Moving data sections to text in $<"
Kevin O'Connord5f1e842008-02-28 20:01:11 -050074 $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050075
76$(OUT)%.16.s: %.c
77 @echo " Generating assembler for $<"
Kevin O'Connor410680b2008-03-02 20:48:35 -050078 $(Q)$(CC) $(CFLAGS16INC) $(DEPHACK) -S -c $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050079
80$(OUT)%.lds: %.lds.S
81 @echo " Precompiling $<"
82 $(Q)$(CPP) -P $< -o $@
83
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050084
Kevin O'Connor410680b2008-03-02 20:48:35 -050085$(OUT)blob.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050086
Kevin O'Connor44c631d2008-03-02 11:24:36 -050087TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC)))
Kevin O'Connor74534532008-05-12 18:28:58 -040088$(OUT)romlayout16.o: romlayout.S $(OUT)blob.16.s $(TABLEASM)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050089 @echo " Generating 16bit layout of $@"
90 $(Q)$(CC) $(CFLAGS16) -c $< -o $@
91
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -040092$(OUT)romlayout32.o: ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@)
93
Kevin O'Connord2899772008-07-06 09:56:14 -040094$(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -040095 @echo " Linking (no relocs) $@"
Kevin O'Connord2899772008-07-06 09:56:14 -040096 $(Q)ld -r -T $(OUT)rombios32.lds $< -o $@
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -040097
Kevin O'Connord2899772008-07-06 09:56:14 -040098$(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)rombios16.lds
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050099 @echo " Linking $@"
Kevin O'Connord2899772008-07-06 09:56:14 -0400100 $(Q)objcopy --prefix-symbols=_code32_ $(OUT)rom32.o $(OUT)rom32.rename.o
101 $(Q)ld -T $(OUT)rombios16.lds -R $(OUT)rom32.rename.o $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500102
Kevin O'Connord2899772008-07-06 09:56:14 -0400103$(OUT)rom.o: $(OUT)rom16.o $(OUT)rom32.o $(OUT)rombios.lds
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500104 @echo " Linking $@"
Kevin O'Connord2899772008-07-06 09:56:14 -0400105 $(Q)ld -T $(OUT)rombios.lds $(OUT)rom16.o $(OUT)rom32.o -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500106
Kevin O'Connord2899772008-07-06 09:56:14 -0400107$(OUT)bios.bin.elf: $(OUT)rom.o
Kevin O'Connor9bcc5272008-07-05 21:08:56 -0400108 @echo " Prepping $@"
109 $(Q)nm $< | ./tools/checkrom.py
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400110 $(Q)strip $< -o $@
111
112$(OUT)bios.bin: $(OUT)bios.bin.elf
113 @echo " Extracting binary $@"
114 $(Q)objcopy -O binary $< $@
115
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500116
117####### Generic rules
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500118clean:
119 rm -rf $(OUT)
120
121$(OUT):
122 mkdir $@
123
124-include $(OUT)*.d