blob: f69ed834856cfe74cc7fb2cb898a47a65e013387 [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#
Kevin O'Connorb1b7c2a2009-01-15 20:52:58 -05005# This file may be distributed under the terms of the GNU LGPLv3 license.
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05006
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 \
Kevin O'Connor0c3068d2008-12-21 17:51:36 -050012 serial.c clock.c pic.c cdrom.c ps2port.c smpdetect.c resume.c \
Kevin O'Connor51358db2008-12-28 21:50:29 -050013 pnpbios.c pirtable.c
Kevin O'Connorcbffa8e2008-08-17 11:11:07 -040014SRC16=$(SRCBOTH) disk.c apm.c pcibios.c vgahooks.c
Kevin O'Connor44eeaf12008-07-06 10:14:49 -040015SRC32=$(SRCBOTH) post.c shadow.c post_menu.c memmap.c coreboot.c boot.c \
Kevin O'Connor7061eb62009-01-04 21:48:22 -050016 acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c
Kevin O'Connor44c631d2008-03-02 11:24:36 -050017TABLESRC=font.c cbt.c floppy_dbt.c
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050018
Kevin O'Connor786502d2008-02-27 10:41:41 -050019cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
20 /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;)
21
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050022# Default compiler flags
Kevin O'Connorba2d0df2008-04-13 16:59:03 -040023COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=3 \
24 -mpreferred-stack-boundary=2 -mrtd \
Kevin O'Connorbc28a2b2008-03-11 19:32:38 -040025 -ffreestanding -fwhole-program -fomit-frame-pointer \
Kevin O'Connor7bb32532009-01-04 11:15:36 -050026 -fno-delete-null-pointer-checks -Wno-strict-aliasing
Kevin O'Connor786502d2008-02-27 10:41:41 -050027COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
28COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
29COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
30
Kevin O'Connorc43bcba2008-07-30 20:37:13 -040031override CFLAGS = $(COMMONCFLAGS) -g -DMODE16=0
Kevin O'Connor7ab798f2008-07-13 11:08:36 -040032CFLAGS16INC = $(COMMONCFLAGS) -DMODE16=1 -fno-jump-tables -fno-defer-pop \
Kevin O'Connor96462242009-01-01 17:54:16 -050033 $(call cc-option,$(CC),--param large-stack-frame=4,)
Kevin O'Connor202024a2009-01-17 10:41:28 -050034CFLAGS16INC += -ffunction-sections -fdata-sections
Kevin O'Connor410680b2008-03-02 20:48:35 -050035CFLAGS16 = $(CFLAGS16INC) -g
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050036
Kevin O'Connor44c631d2008-03-02 11:24:36 -050037TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC)))
Kevin O'Connor59fead62008-05-10 15:49:20 -040038all: $(OUT) $(OUT)bios.bin $(TABLETMP)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050039
40# Run with "make V=1" to see the actual compile commands
41ifdef V
42Q=
43else
44Q=@
45endif
46
Kevin O'Connor2fc90bd2008-11-07 21:42:00 -050047OBJCOPY=objcopy
Kevin O'Connor202024a2009-01-17 10:41:28 -050048OBJDUMP=objdump
Kevin O'Connor2fc90bd2008-11-07 21:42:00 -050049NM=nm
50STRIP=strip
51
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050052.PHONY : all FORCE
53
54vpath %.c src
55vpath %.S src
56
57################ Build rules
Kevin O'Connor410680b2008-03-02 20:48:35 -050058
59# Do a whole file compile - two methods are supported. The first
60# involves including all the content textually via #include
61# directives. The second method uses gcc's "-combine" option.
62ifdef AVOIDCOMBINE
63DEPHACK=
64define whole-compile
65@echo " Compiling whole program $3"
Kevin O'Connor86cebee2008-11-06 18:57:10 -050066$(Q)printf '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
Kevin O'Connor410680b2008-03-02 20:48:35 -050067$(Q)$(CC) $1 -c $3.tmp.c -o $3
68endef
69else
70# Ugly way to get gcc to generate .d files correctly.
71DEPHACK=-combine src/null.c
72define whole-compile
73@echo " Compiling whole program $3"
74$(Q)$(CC) $1 -combine -c $2 -o $3
75endef
76endif
77
78
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050079$(OUT)%.proc.16.s: $(OUT)%.16.s
Kevin O'Connor9e821222008-12-06 18:56:19 -050080 @echo " Moving data sections to text in $@"
Kevin O'Connor92f95b02008-12-29 20:42:40 -050081 $(Q)sed 's/^\t\.section\t\.\(ro\)\?data.*// ; s/^\t\.data$$//' < $< > $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050082
83$(OUT)%.16.s: %.c
Kevin O'Connor9e821222008-12-06 18:56:19 -050084 @echo " Compiling to assembler $@"
Kevin O'Connor410680b2008-03-02 20:48:35 -050085 $(Q)$(CC) $(CFLAGS16INC) $(DEPHACK) -S -c $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050086
87$(OUT)%.lds: %.lds.S
Kevin O'Connor9e821222008-12-06 18:56:19 -050088 @echo " Precompiling $@"
Kevin O'Connord9a8b2d2008-11-16 09:17:02 -050089 $(Q)$(CPP) -P -D__ASSEMBLY__ $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050090
Kevin O'Connor952974e2008-11-16 18:14:33 -050091$(OUT)asm-offsets.h: $(OUT)asm-offsets.16.s
92 @echo " Generating offset file $@"
93 $(Q)./tools/gen-offsets.sh $< $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050094
Kevin O'Connor9e821222008-12-06 18:56:19 -050095$(OUT)ccode.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050096
Kevin O'Connor44c631d2008-03-02 11:24:36 -050097TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC)))
Kevin O'Connor9e821222008-12-06 18:56:19 -050098$(OUT)romlayout16.o: romlayout.S $(OUT)ccode.16.s $(OUT)asm-offsets.h $(TABLEASM)
99 @echo " Compiling (16bit) $@"
100 $(Q)$(CC) $(CFLAGS16INC) -c -D__ASSEMBLY__ $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500101
Kevin O'Connor9e821222008-12-06 18:56:19 -0500102$(OUT)ccode32.o: ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@)
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400103
Kevin O'Connor9e821222008-12-06 18:56:19 -0500104$(OUT)rom32.o: $(OUT)ccode32.o $(OUT)rombios32.lds
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400105 @echo " Linking (no relocs) $@"
Kevin O'Connor1b7d8842008-11-08 10:36:16 -0500106 $(Q)$(LD) -r -d -T $(OUT)rombios32.lds $< -o $@
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400107
Kevin O'Connor202024a2009-01-17 10:41:28 -0500108$(OUT)romlayout.lds: $(OUT)romlayout16.o
109 @echo " Building layout information $@"
Kevin O'Connor711ddc62009-01-17 15:17:34 -0500110 $(Q)$(OBJDUMP) -h $< | ./tools/layoutrom.py $@
Kevin O'Connor202024a2009-01-17 10:41:28 -0500111
112$(OUT)rombios16.lds: $(OUT)romlayout.lds
113
Kevin O'Connord2899772008-07-06 09:56:14 -0400114$(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)rombios16.lds
Kevin O'Connor9e821222008-12-06 18:56:19 -0500115 @echo " Linking (16bit) $@"
Kevin O'Connor86cebee2008-11-06 18:57:10 -0500116 $(Q)$(OBJCOPY) --prefix-symbols=_code32_ $(OUT)rom32.o $(OUT)rom32.rename.o
117 $(Q)$(LD) -T $(OUT)rombios16.lds -R $(OUT)rom32.rename.o $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500118
Kevin O'Connord2899772008-07-06 09:56:14 -0400119$(OUT)rom.o: $(OUT)rom16.o $(OUT)rom32.o $(OUT)rombios.lds
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500120 @echo " Linking $@"
Kevin O'Connor86cebee2008-11-06 18:57:10 -0500121 $(Q)$(LD) -T $(OUT)rombios.lds $(OUT)rom16.o $(OUT)rom32.o -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500122
Kevin O'Connord2899772008-07-06 09:56:14 -0400123$(OUT)bios.bin.elf: $(OUT)rom.o
Kevin O'Connor9bcc5272008-07-05 21:08:56 -0400124 @echo " Prepping $@"
Kevin O'Connor86cebee2008-11-06 18:57:10 -0500125 $(Q)$(NM) $< | ./tools/checkrom.py
126 $(Q)$(STRIP) $< -o $@
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400127
128$(OUT)bios.bin: $(OUT)bios.bin.elf
129 @echo " Extracting binary $@"
Kevin O'Connor86cebee2008-11-06 18:57:10 -0500130 $(Q)$(OBJCOPY) -O binary $< $@
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400131
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500132
133####### Generic rules
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500134clean:
Kevin O'Connor86cebee2008-11-06 18:57:10 -0500135 $(Q)rm -rf $(OUT)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500136
137$(OUT):
Kevin O'Connor86cebee2008-11-06 18:57:10 -0500138 $(Q)mkdir $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500139
140-include $(OUT)*.d