Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 1 | # Legacy Bios build system |
| 2 | # |
| 3 | # Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net> |
| 4 | # |
Kevin O'Connor | b1b7c2a | 2009-01-15 20:52:58 -0500 | [diff] [blame] | 5 | # This file may be distributed under the terms of the GNU LGPLv3 license. |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 6 | |
| 7 | # Output directory |
| 8 | OUT=out/ |
| 9 | |
| 10 | # Source files |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 11 | SRCBOTH=output.c util.c floppy.c ata.c misc.c mouse.c kbd.c pci.c \ |
Kevin O'Connor | 0c3068d | 2008-12-21 17:51:36 -0500 | [diff] [blame] | 12 | serial.c clock.c pic.c cdrom.c ps2port.c smpdetect.c resume.c \ |
Kevin O'Connor | 51358db | 2008-12-28 21:50:29 -0500 | [diff] [blame] | 13 | pnpbios.c pirtable.c |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 14 | SRC16=$(SRCBOTH) system.c disk.c apm.c pcibios.c vgahooks.c font.c |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame^] | 15 | SRC32=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \ |
Kevin O'Connor | 7061eb6 | 2009-01-04 21:48:22 -0500 | [diff] [blame] | 16 | acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 17 | |
Kevin O'Connor | 786502d | 2008-02-27 10:41:41 -0500 | [diff] [blame] | 18 | cc-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'Connor | bdce35f | 2008-02-26 21:33:14 -0500 | [diff] [blame] | 21 | # Default compiler flags |
Kevin O'Connor | ba2d0df | 2008-04-13 16:59:03 -0400 | [diff] [blame] | 22 | COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=3 \ |
| 23 | -mpreferred-stack-boundary=2 -mrtd \ |
Kevin O'Connor | bc28a2b | 2008-03-11 19:32:38 -0400 | [diff] [blame] | 24 | -ffreestanding -fwhole-program -fomit-frame-pointer \ |
Kevin O'Connor | 7bb3253 | 2009-01-04 11:15:36 -0500 | [diff] [blame] | 25 | -fno-delete-null-pointer-checks -Wno-strict-aliasing |
Kevin O'Connor | 786502d | 2008-02-27 10:41:41 -0500 | [diff] [blame] | 26 | COMMONCFLAGS += $(call cc-option,$(CC),-nopie,) |
| 27 | COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,) |
| 28 | COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,) |
| 29 | |
Kevin O'Connor | c43bcba | 2008-07-30 20:37:13 -0400 | [diff] [blame] | 30 | override CFLAGS = $(COMMONCFLAGS) -g -DMODE16=0 |
Kevin O'Connor | 7ab798f | 2008-07-13 11:08:36 -0400 | [diff] [blame] | 31 | CFLAGS16INC = $(COMMONCFLAGS) -DMODE16=1 -fno-jump-tables -fno-defer-pop \ |
Kevin O'Connor | 9646224 | 2009-01-01 17:54:16 -0500 | [diff] [blame] | 32 | $(call cc-option,$(CC),--param large-stack-frame=4,) |
Kevin O'Connor | 202024a | 2009-01-17 10:41:28 -0500 | [diff] [blame] | 33 | CFLAGS16INC += -ffunction-sections -fdata-sections |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 34 | CFLAGS16 = $(CFLAGS16INC) -g |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 35 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 36 | all: $(OUT) $(OUT)bios.bin |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 37 | |
| 38 | # Run with "make V=1" to see the actual compile commands |
| 39 | ifdef V |
| 40 | Q= |
| 41 | else |
| 42 | Q=@ |
| 43 | endif |
| 44 | |
Kevin O'Connor | 2fc90bd | 2008-11-07 21:42:00 -0500 | [diff] [blame] | 45 | OBJCOPY=objcopy |
Kevin O'Connor | 202024a | 2009-01-17 10:41:28 -0500 | [diff] [blame] | 46 | OBJDUMP=objdump |
Kevin O'Connor | 2fc90bd | 2008-11-07 21:42:00 -0500 | [diff] [blame] | 47 | NM=nm |
| 48 | STRIP=strip |
| 49 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 50 | .PHONY : all FORCE |
| 51 | |
| 52 | vpath %.c src |
| 53 | vpath %.S src |
| 54 | |
| 55 | ################ Build rules |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 56 | |
Kevin O'Connor | 231f710 | 2009-01-25 16:11:27 -0500 | [diff] [blame] | 57 | ifndef AVOIDCOMBINE |
| 58 | AVOIDCOMBINE=$(shell CC=$(CC) tools/test-combine.sh) |
| 59 | endif |
| 60 | |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 61 | # Do a whole file compile - two methods are supported. The first |
| 62 | # involves including all the content textually via #include |
| 63 | # directives. The second method uses gcc's "-combine" option. |
Kevin O'Connor | 231f710 | 2009-01-25 16:11:27 -0500 | [diff] [blame] | 64 | ifeq "$(AVOIDCOMBINE)" "1" |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 65 | define whole-compile |
| 66 | @echo " Compiling whole program $3" |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 67 | $(Q)printf '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 68 | $(Q)$(CC) $1 -c $3.tmp.c -o $3 |
| 69 | endef |
| 70 | else |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 71 | define whole-compile |
| 72 | @echo " Compiling whole program $3" |
| 73 | $(Q)$(CC) $1 -combine -c $2 -o $3 |
| 74 | endef |
| 75 | endif |
| 76 | |
| 77 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 78 | $(OUT)%.s: %.c |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 79 | @echo " Compiling to assembler $@" |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 80 | $(Q)$(CC) $(CFLAGS16INC) -S -c $< -o $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 81 | |
| 82 | $(OUT)%.lds: %.lds.S |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 83 | @echo " Precompiling $@" |
Kevin O'Connor | d9a8b2d | 2008-11-16 09:17:02 -0500 | [diff] [blame] | 84 | $(Q)$(CPP) -P -D__ASSEMBLY__ $< -o $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 85 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 86 | $(OUT)asm-offsets.h: $(OUT)asm-offsets.s |
Kevin O'Connor | 952974e | 2008-11-16 18:14:33 -0500 | [diff] [blame] | 87 | @echo " Generating offset file $@" |
| 88 | $(Q)./tools/gen-offsets.sh $< $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 89 | |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 90 | $(OUT)ccode.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@) |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 91 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 92 | $(OUT)romlayout16.o: romlayout.S $(OUT)ccode.16.s $(OUT)asm-offsets.h |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 93 | @echo " Compiling (16bit) $@" |
| 94 | $(Q)$(CC) $(CFLAGS16INC) -c -D__ASSEMBLY__ $< -o $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 95 | |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 96 | $(OUT)ccode32.o: ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@) |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 97 | |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 98 | $(OUT)rom32.o: $(OUT)ccode32.o $(OUT)rombios32.lds |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 99 | @echo " Linking (no relocs) $@" |
Kevin O'Connor | 1b7d884 | 2008-11-08 10:36:16 -0500 | [diff] [blame] | 100 | $(Q)$(LD) -r -d -T $(OUT)rombios32.lds $< -o $@ |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 101 | |
Kevin O'Connor | 202024a | 2009-01-17 10:41:28 -0500 | [diff] [blame] | 102 | $(OUT)romlayout.lds: $(OUT)romlayout16.o |
| 103 | @echo " Building layout information $@" |
Kevin O'Connor | 711ddc6 | 2009-01-17 15:17:34 -0500 | [diff] [blame] | 104 | $(Q)$(OBJDUMP) -h $< | ./tools/layoutrom.py $@ |
Kevin O'Connor | 202024a | 2009-01-17 10:41:28 -0500 | [diff] [blame] | 105 | |
| 106 | $(OUT)rombios16.lds: $(OUT)romlayout.lds |
| 107 | |
Kevin O'Connor | d289977 | 2008-07-06 09:56:14 -0400 | [diff] [blame] | 108 | $(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)rombios16.lds |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 109 | @echo " Linking (16bit) $@" |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 110 | $(Q)$(OBJCOPY) --prefix-symbols=_code32_ $(OUT)rom32.o $(OUT)rom32.rename.o |
| 111 | $(Q)$(LD) -T $(OUT)rombios16.lds -R $(OUT)rom32.rename.o $< -o $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 112 | |
Kevin O'Connor | d289977 | 2008-07-06 09:56:14 -0400 | [diff] [blame] | 113 | $(OUT)rom.o: $(OUT)rom16.o $(OUT)rom32.o $(OUT)rombios.lds |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 114 | @echo " Linking $@" |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 115 | $(Q)$(LD) -T $(OUT)rombios.lds $(OUT)rom16.o $(OUT)rom32.o -o $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 116 | |
Kevin O'Connor | d289977 | 2008-07-06 09:56:14 -0400 | [diff] [blame] | 117 | $(OUT)bios.bin.elf: $(OUT)rom.o |
Kevin O'Connor | 9bcc527 | 2008-07-05 21:08:56 -0400 | [diff] [blame] | 118 | @echo " Prepping $@" |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 119 | $(Q)$(NM) $< | ./tools/checkrom.py |
| 120 | $(Q)$(STRIP) $< -o $@ |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 121 | |
| 122 | $(OUT)bios.bin: $(OUT)bios.bin.elf |
| 123 | @echo " Extracting binary $@" |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 124 | $(Q)$(OBJCOPY) -O binary $< $@ |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 125 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 126 | |
| 127 | ####### Generic rules |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 128 | clean: |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 129 | $(Q)rm -rf $(OUT) |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 130 | |
| 131 | $(OUT): |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 132 | $(Q)mkdir $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 133 | |
| 134 | -include $(OUT)*.d |