blob: 7bfb34535ec23cd1f4f90d2d8c3c933550a638d0 [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 \
Kevin O'Connor3b897192008-07-20 10:08:59 -040012 serial.c clock.c pic.c cdrom.c ps2port.c
Kevin O'Connorcbffa8e2008-08-17 11:11:07 -040013SRC16=$(SRCBOTH) disk.c apm.c pcibios.c vgahooks.c
Kevin O'Connor44eeaf12008-07-06 10:14:49 -040014SRC32=$(SRCBOTH) post.c shadow.c post_menu.c memmap.c coreboot.c boot.c \
Kevin O'Connor714325c2008-11-01 20:32:27 -040015 acpi.c pirtable.c smm.c smpdetect.c mptable.c smbios.c pciinit.c \
16 optionroms.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 \
26 -fno-delete-null-pointer-checks
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'Connora2d16922008-05-12 23:44:57 -040033 $(call cc-option,$(CC),--param large-stack-frame=8,)
Kevin O'Connor410680b2008-03-02 20:48:35 -050034CFLAGS16 = $(CFLAGS16INC) -g
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050035
Kevin O'Connor44c631d2008-03-02 11:24:36 -050036TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC)))
Kevin O'Connor59fead62008-05-10 15:49:20 -040037all: $(OUT) $(OUT)bios.bin $(TABLETMP)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050038
39# Run with "make V=1" to see the actual compile commands
40ifdef V
41Q=
42else
43Q=@
44endif
45
Kevin O'Connor2fc90bd2008-11-07 21:42:00 -050046OBJCOPY=objcopy
47NM=nm
48STRIP=strip
49
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050050.PHONY : all FORCE
51
52vpath %.c src
53vpath %.S src
54
55################ Build rules
Kevin O'Connor410680b2008-03-02 20:48:35 -050056
57# Do a whole file compile - two methods are supported. The first
58# involves including all the content textually via #include
59# directives. The second method uses gcc's "-combine" option.
60ifdef AVOIDCOMBINE
61DEPHACK=
62define whole-compile
63@echo " Compiling whole program $3"
Kevin O'Connor86cebee2008-11-06 18:57:10 -050064$(Q)printf '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
Kevin O'Connor410680b2008-03-02 20:48:35 -050065$(Q)$(CC) $1 -c $3.tmp.c -o $3
66endef
67else
68# Ugly way to get gcc to generate .d files correctly.
69DEPHACK=-combine src/null.c
70define whole-compile
71@echo " Compiling whole program $3"
72$(Q)$(CC) $1 -combine -c $2 -o $3
73endef
74endif
75
76
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050077$(OUT)%.proc.16.s: $(OUT)%.16.s
78 @echo " Moving data sections to text in $<"
Kevin O'Connord5f1e842008-02-28 20:01:11 -050079 $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050080
81$(OUT)%.16.s: %.c
82 @echo " Generating assembler for $<"
Kevin O'Connor410680b2008-03-02 20:48:35 -050083 $(Q)$(CC) $(CFLAGS16INC) $(DEPHACK) -S -c $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050084
85$(OUT)%.lds: %.lds.S
86 @echo " Precompiling $<"
Kevin O'Connord9a8b2d2008-11-16 09:17:02 -050087 $(Q)$(CPP) -P -D__ASSEMBLY__ $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050088
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050089
Kevin O'Connor410680b2008-03-02 20:48:35 -050090$(OUT)blob.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050091
Kevin O'Connor44c631d2008-03-02 11:24:36 -050092TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC)))
Kevin O'Connor74534532008-05-12 18:28:58 -040093$(OUT)romlayout16.o: romlayout.S $(OUT)blob.16.s $(TABLEASM)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050094 @echo " Generating 16bit layout of $@"
Kevin O'Connord9a8b2d2008-11-16 09:17:02 -050095 $(Q)$(CC) $(CFLAGS16) -c -D__ASSEMBLY__ $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050096
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -040097$(OUT)romlayout32.o: ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@)
98
Kevin O'Connord2899772008-07-06 09:56:14 -040099$(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400100 @echo " Linking (no relocs) $@"
Kevin O'Connor1b7d8842008-11-08 10:36:16 -0500101 $(Q)$(LD) -r -d -T $(OUT)rombios32.lds $< -o $@
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400102
Kevin O'Connord2899772008-07-06 09:56:14 -0400103$(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)rombios16.lds
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500104 @echo " Linking $@"
Kevin O'Connor86cebee2008-11-06 18:57:10 -0500105 $(Q)$(OBJCOPY) --prefix-symbols=_code32_ $(OUT)rom32.o $(OUT)rom32.rename.o
106 $(Q)$(LD) -T $(OUT)rombios16.lds -R $(OUT)rom32.rename.o $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500107
Kevin O'Connord2899772008-07-06 09:56:14 -0400108$(OUT)rom.o: $(OUT)rom16.o $(OUT)rom32.o $(OUT)rombios.lds
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500109 @echo " Linking $@"
Kevin O'Connor86cebee2008-11-06 18:57:10 -0500110 $(Q)$(LD) -T $(OUT)rombios.lds $(OUT)rom16.o $(OUT)rom32.o -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500111
Kevin O'Connord2899772008-07-06 09:56:14 -0400112$(OUT)bios.bin.elf: $(OUT)rom.o
Kevin O'Connor9bcc5272008-07-05 21:08:56 -0400113 @echo " Prepping $@"
Kevin O'Connor86cebee2008-11-06 18:57:10 -0500114 $(Q)$(NM) $< | ./tools/checkrom.py
115 $(Q)$(STRIP) $< -o $@
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400116
117$(OUT)bios.bin: $(OUT)bios.bin.elf
118 @echo " Extracting binary $@"
Kevin O'Connor86cebee2008-11-06 18:57:10 -0500119 $(Q)$(OBJCOPY) -O binary $< $@
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400120
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500121
122####### Generic rules
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500123clean:
Kevin O'Connor86cebee2008-11-06 18:57:10 -0500124 $(Q)rm -rf $(OUT)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500125
126$(OUT):
Kevin O'Connor86cebee2008-11-06 18:57:10 -0500127 $(Q)mkdir $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500128
129-include $(OUT)*.d