blob: 8faa1f44a7e713470d27f9721e7ee16e8353d364 [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'Connor0c3068d2008-12-21 17:51:36 -050012 serial.c clock.c pic.c cdrom.c ps2port.c smpdetect.c resume.c \
13 pnpbios.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'Connora06bfb62008-12-06 19:37:56 -050016 acpi.c pirtable.c smm.c mptable.c smbios.c pciinit.c \
Kevin O'Connor714325c2008-11-01 20:32:27 -040017 optionroms.c
Kevin O'Connor44c631d2008-03-02 11:24:36 -050018TABLESRC=font.c cbt.c floppy_dbt.c
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050019
Kevin O'Connor786502d2008-02-27 10:41:41 -050020cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
21 /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;)
22
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050023# Default compiler flags
Kevin O'Connorba2d0df2008-04-13 16:59:03 -040024COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=3 \
25 -mpreferred-stack-boundary=2 -mrtd \
Kevin O'Connorbc28a2b2008-03-11 19:32:38 -040026 -ffreestanding -fwhole-program -fomit-frame-pointer \
27 -fno-delete-null-pointer-checks
Kevin O'Connor786502d2008-02-27 10:41:41 -050028COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
29COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
30COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
31
Kevin O'Connorc43bcba2008-07-30 20:37:13 -040032override CFLAGS = $(COMMONCFLAGS) -g -DMODE16=0
Kevin O'Connor7ab798f2008-07-13 11:08:36 -040033CFLAGS16INC = $(COMMONCFLAGS) -DMODE16=1 -fno-jump-tables -fno-defer-pop \
Kevin O'Connora2d16922008-05-12 23:44:57 -040034 $(call cc-option,$(CC),--param large-stack-frame=8,)
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
48NM=nm
49STRIP=strip
50
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050051.PHONY : all FORCE
52
53vpath %.c src
54vpath %.S src
55
56################ Build rules
Kevin O'Connor410680b2008-03-02 20:48:35 -050057
58# Do a whole file compile - two methods are supported. The first
59# involves including all the content textually via #include
60# directives. The second method uses gcc's "-combine" option.
61ifdef AVOIDCOMBINE
62DEPHACK=
63define whole-compile
64@echo " Compiling whole program $3"
Kevin O'Connor86cebee2008-11-06 18:57:10 -050065$(Q)printf '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
Kevin O'Connor410680b2008-03-02 20:48:35 -050066$(Q)$(CC) $1 -c $3.tmp.c -o $3
67endef
68else
69# Ugly way to get gcc to generate .d files correctly.
70DEPHACK=-combine src/null.c
71define whole-compile
72@echo " Compiling whole program $3"
73$(Q)$(CC) $1 -combine -c $2 -o $3
74endef
75endif
76
77
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050078$(OUT)%.proc.16.s: $(OUT)%.16.s
Kevin O'Connor9e821222008-12-06 18:56:19 -050079 @echo " Moving data sections to text in $@"
Kevin O'Connord5f1e842008-02-28 20:01:11 -050080 $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050081
82$(OUT)%.16.s: %.c
Kevin O'Connor9e821222008-12-06 18:56:19 -050083 @echo " Compiling to assembler $@"
Kevin O'Connor410680b2008-03-02 20:48:35 -050084 $(Q)$(CC) $(CFLAGS16INC) $(DEPHACK) -S -c $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050085
86$(OUT)%.lds: %.lds.S
Kevin O'Connor9e821222008-12-06 18:56:19 -050087 @echo " Precompiling $@"
Kevin O'Connord9a8b2d2008-11-16 09:17:02 -050088 $(Q)$(CPP) -P -D__ASSEMBLY__ $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050089
Kevin O'Connor952974e2008-11-16 18:14:33 -050090$(OUT)asm-offsets.h: $(OUT)asm-offsets.16.s
91 @echo " Generating offset file $@"
92 $(Q)./tools/gen-offsets.sh $< $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050093
Kevin O'Connor9e821222008-12-06 18:56:19 -050094$(OUT)ccode.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050095
Kevin O'Connor44c631d2008-03-02 11:24:36 -050096TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC)))
Kevin O'Connor9e821222008-12-06 18:56:19 -050097$(OUT)romlayout16.o: romlayout.S $(OUT)ccode.16.s $(OUT)asm-offsets.h $(TABLEASM)
98 @echo " Compiling (16bit) $@"
99 $(Q)$(CC) $(CFLAGS16INC) -c -D__ASSEMBLY__ $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500100
Kevin O'Connor9e821222008-12-06 18:56:19 -0500101$(OUT)ccode32.o: ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@)
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400102
Kevin O'Connor9e821222008-12-06 18:56:19 -0500103$(OUT)rom32.o: $(OUT)ccode32.o $(OUT)rombios32.lds
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400104 @echo " Linking (no relocs) $@"
Kevin O'Connor1b7d8842008-11-08 10:36:16 -0500105 $(Q)$(LD) -r -d -T $(OUT)rombios32.lds $< -o $@
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400106
Kevin O'Connord2899772008-07-06 09:56:14 -0400107$(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)rombios16.lds
Kevin O'Connor9e821222008-12-06 18:56:19 -0500108 @echo " Linking (16bit) $@"
Kevin O'Connor86cebee2008-11-06 18:57:10 -0500109 $(Q)$(OBJCOPY) --prefix-symbols=_code32_ $(OUT)rom32.o $(OUT)rom32.rename.o
110 $(Q)$(LD) -T $(OUT)rombios16.lds -R $(OUT)rom32.rename.o $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500111
Kevin O'Connord2899772008-07-06 09:56:14 -0400112$(OUT)rom.o: $(OUT)rom16.o $(OUT)rom32.o $(OUT)rombios.lds
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500113 @echo " Linking $@"
Kevin O'Connor86cebee2008-11-06 18:57:10 -0500114 $(Q)$(LD) -T $(OUT)rombios.lds $(OUT)rom16.o $(OUT)rom32.o -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500115
Kevin O'Connord2899772008-07-06 09:56:14 -0400116$(OUT)bios.bin.elf: $(OUT)rom.o
Kevin O'Connor9bcc5272008-07-05 21:08:56 -0400117 @echo " Prepping $@"
Kevin O'Connor86cebee2008-11-06 18:57:10 -0500118 $(Q)$(NM) $< | ./tools/checkrom.py
119 $(Q)$(STRIP) $< -o $@
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400120
121$(OUT)bios.bin: $(OUT)bios.bin.elf
122 @echo " Extracting binary $@"
Kevin O'Connor86cebee2008-11-06 18:57:10 -0500123 $(Q)$(OBJCOPY) -O binary $< $@
Kevin O'Connor2fda7cb2008-07-05 20:41:53 -0400124
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500125
126####### Generic rules
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500127clean:
Kevin O'Connor86cebee2008-11-06 18:57:10 -0500128 $(Q)rm -rf $(OUT)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500129
130$(OUT):
Kevin O'Connor86cebee2008-11-06 18:57:10 -0500131 $(Q)mkdir $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500132
133-include $(OUT)*.d