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 | 592323f | 2009-04-26 23:17:49 -0400 | [diff] [blame] | 16 | acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \ |
| 17 | lzmadecode.c |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 18 | |
Kevin O'Connor | 786502d | 2008-02-27 10:41:41 -0500 | [diff] [blame] | 19 | cc-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'Connor | bdce35f | 2008-02-26 21:33:14 -0500 | [diff] [blame] | 22 | # Default compiler flags |
Kevin O'Connor | ba2d0df | 2008-04-13 16:59:03 -0400 | [diff] [blame] | 23 | COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=3 \ |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 24 | -mpreferred-stack-boundary=2 -mrtd -freg-struct-return \ |
Kevin O'Connor | bc28a2b | 2008-03-11 19:32:38 -0400 | [diff] [blame] | 25 | -ffreestanding -fwhole-program -fomit-frame-pointer \ |
Kevin O'Connor | d944114 | 2009-04-19 23:18:54 -0400 | [diff] [blame] | 26 | -fno-delete-null-pointer-checks -Wno-strict-aliasing \ |
| 27 | -minline-all-stringops |
Kevin O'Connor | 786502d | 2008-02-27 10:41:41 -0500 | [diff] [blame] | 28 | COMMONCFLAGS += $(call cc-option,$(CC),-nopie,) |
| 29 | COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,) |
| 30 | COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,) |
| 31 | |
Kevin O'Connor | c43bcba | 2008-07-30 20:37:13 -0400 | [diff] [blame] | 32 | override CFLAGS = $(COMMONCFLAGS) -g -DMODE16=0 |
Kevin O'Connor | 7ab798f | 2008-07-13 11:08:36 -0400 | [diff] [blame] | 33 | CFLAGS16INC = $(COMMONCFLAGS) -DMODE16=1 -fno-jump-tables -fno-defer-pop \ |
Kevin O'Connor | b49e058 | 2009-04-08 21:25:00 -0400 | [diff] [blame] | 34 | $(call cc-option,$(CC),-fno-tree-switch-conversion,) \ |
Kevin O'Connor | 9646224 | 2009-01-01 17:54:16 -0500 | [diff] [blame] | 35 | $(call cc-option,$(CC),--param large-stack-frame=4,) |
Kevin O'Connor | 202024a | 2009-01-17 10:41:28 -0500 | [diff] [blame] | 36 | CFLAGS16INC += -ffunction-sections -fdata-sections |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 37 | CFLAGS16 = $(CFLAGS16INC) -g |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 38 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 39 | all: $(OUT) $(OUT)bios.bin |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 40 | |
| 41 | # Run with "make V=1" to see the actual compile commands |
| 42 | ifdef V |
| 43 | Q= |
| 44 | else |
| 45 | Q=@ |
| 46 | endif |
| 47 | |
Kevin O'Connor | 2fc90bd | 2008-11-07 21:42:00 -0500 | [diff] [blame] | 48 | OBJCOPY=objcopy |
Kevin O'Connor | 202024a | 2009-01-17 10:41:28 -0500 | [diff] [blame] | 49 | OBJDUMP=objdump |
Kevin O'Connor | 2fc90bd | 2008-11-07 21:42:00 -0500 | [diff] [blame] | 50 | NM=nm |
| 51 | STRIP=strip |
| 52 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 53 | .PHONY : all FORCE |
| 54 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 55 | vpath %.c src vgasrc |
| 56 | vpath %.S src vgasrc |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 57 | |
| 58 | ################ Build rules |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 59 | |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 60 | TESTGCC:=$(shell CC=$(CC) tools/test-gcc.sh) |
| 61 | ifeq "$(TESTGCC)" "-1" |
| 62 | $(error "Please upgrade GCC") |
| 63 | endif |
| 64 | |
Kevin O'Connor | 231f710 | 2009-01-25 16:11:27 -0500 | [diff] [blame] | 65 | ifndef AVOIDCOMBINE |
Kevin O'Connor | 03f630e | 2009-03-26 20:45:36 -0400 | [diff] [blame] | 66 | AVOIDCOMBINE=$(TESTGCC) |
Kevin O'Connor | 231f710 | 2009-01-25 16:11:27 -0500 | [diff] [blame] | 67 | endif |
| 68 | |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 69 | # Do a whole file compile - two methods are supported. The first |
| 70 | # involves including all the content textually via #include |
| 71 | # directives. The second method uses gcc's "-combine" option. |
Kevin O'Connor | 231f710 | 2009-01-25 16:11:27 -0500 | [diff] [blame] | 72 | ifeq "$(AVOIDCOMBINE)" "1" |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 73 | define whole-compile |
| 74 | @echo " Compiling whole program $3" |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 75 | $(Q)printf '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 76 | $(Q)$(CC) $1 -c $3.tmp.c -o $3 |
| 77 | endef |
| 78 | else |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame] | 79 | define whole-compile |
| 80 | @echo " Compiling whole program $3" |
| 81 | $(Q)$(CC) $1 -combine -c $2 -o $3 |
| 82 | endef |
| 83 | endif |
| 84 | |
| 85 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 86 | $(OUT)%.s: %.c |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 87 | @echo " Compiling to assembler $@" |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 88 | $(Q)$(CC) $(CFLAGS16INC) -S -c $< -o $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 89 | |
| 90 | $(OUT)%.lds: %.lds.S |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 91 | @echo " Precompiling $@" |
Kevin O'Connor | d9a8b2d | 2008-11-16 09:17:02 -0500 | [diff] [blame] | 92 | $(Q)$(CPP) -P -D__ASSEMBLY__ $< -o $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 93 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 94 | $(OUT)asm-offsets.h: $(OUT)asm-offsets.s |
Kevin O'Connor | 952974e | 2008-11-16 18:14:33 -0500 | [diff] [blame] | 95 | @echo " Generating offset file $@" |
| 96 | $(Q)./tools/gen-offsets.sh $< $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 97 | |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 98 | $(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] | 99 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 100 | $(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] | 101 | @echo " Compiling (16bit) $@" |
| 102 | $(Q)$(CC) $(CFLAGS16INC) -c -D__ASSEMBLY__ $< -o $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 103 | |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 104 | $(OUT)ccode32.o: ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@) |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 105 | |
Kevin O'Connor | 9e82122 | 2008-12-06 18:56:19 -0500 | [diff] [blame] | 106 | $(OUT)rom32.o: $(OUT)ccode32.o $(OUT)rombios32.lds |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 107 | @echo " Linking (no relocs) $@" |
Kevin O'Connor | 7cf17f2 | 2009-04-08 21:10:08 -0400 | [diff] [blame] | 108 | $(Q)$(LD) -r -T $(OUT)rombios32.lds $< -o $@ |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 109 | |
Kevin O'Connor | 202024a | 2009-01-17 10:41:28 -0500 | [diff] [blame] | 110 | $(OUT)romlayout.lds: $(OUT)romlayout16.o |
| 111 | @echo " Building layout information $@" |
Kevin O'Connor | 711ddc6 | 2009-01-17 15:17:34 -0500 | [diff] [blame] | 112 | $(Q)$(OBJDUMP) -h $< | ./tools/layoutrom.py $@ |
Kevin O'Connor | 202024a | 2009-01-17 10:41:28 -0500 | [diff] [blame] | 113 | |
| 114 | $(OUT)rombios16.lds: $(OUT)romlayout.lds |
| 115 | |
Kevin O'Connor | d289977 | 2008-07-06 09:56:14 -0400 | [diff] [blame] | 116 | $(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] | 117 | @echo " Linking (16bit) $@" |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 118 | $(Q)$(OBJCOPY) --prefix-symbols=_code32_ $(OUT)rom32.o $(OUT)rom32.rename.o |
| 119 | $(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] | 120 | |
Kevin O'Connor | d289977 | 2008-07-06 09:56:14 -0400 | [diff] [blame] | 121 | $(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] | 122 | @echo " Linking $@" |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 123 | $(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] | 124 | |
Kevin O'Connor | d289977 | 2008-07-06 09:56:14 -0400 | [diff] [blame] | 125 | $(OUT)bios.bin.elf: $(OUT)rom.o |
Kevin O'Connor | 9bcc527 | 2008-07-05 21:08:56 -0400 | [diff] [blame] | 126 | @echo " Prepping $@" |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 127 | $(Q)$(NM) $< | ./tools/checkrom.py |
| 128 | $(Q)$(STRIP) $< -o $@ |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 129 | |
| 130 | $(OUT)bios.bin: $(OUT)bios.bin.elf |
| 131 | @echo " Extracting binary $@" |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 132 | $(Q)$(OBJCOPY) -O binary $< $@ |
Kevin O'Connor | 2fda7cb | 2008-07-05 20:41:53 -0400 | [diff] [blame] | 133 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 134 | |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 135 | ################ VGA build rules |
| 136 | |
| 137 | # VGA src files |
Kevin O'Connor | 8d8e094 | 2009-05-17 21:14:46 -0400 | [diff] [blame] | 138 | SRCVGA=src/output.c src/util.c vgasrc/vga.c vgasrc/vgafb.c vgasrc/vgaio.c \ |
| 139 | vgasrc/vgatables.c vgasrc/vgafonts.c vgasrc/clext.c |
Kevin O'Connor | 1f2c307 | 2009-05-06 23:35:59 -0400 | [diff] [blame] | 140 | |
| 141 | $(OUT)vgaccode.16.s: ; $(call whole-compile, $(CFLAGS16) -S -Isrc, $(SRCVGA),$@) |
| 142 | |
| 143 | $(OUT)vgalayout16.o: vgaentry.S $(OUT)vgaccode.16.s $(OUT)asm-offsets.h |
| 144 | @echo " Compiling (16bit) $@" |
| 145 | $(Q)$(CC) $(CFLAGS16INC) -c -D__ASSEMBLY__ -Isrc $< -o $@ |
| 146 | |
| 147 | $(OUT)vgarom.o: $(OUT)vgalayout16.o $(OUT)vgalayout.lds |
| 148 | @echo " Linking $@" |
| 149 | $(Q)$(LD) -T $(OUT)vgalayout.lds $(OUT)vgalayout16.o -o $@ |
| 150 | |
| 151 | $(OUT)vgabios.bin.raw: $(OUT)vgarom.o |
| 152 | @echo " Extracting binary $@" |
| 153 | $(Q)$(OBJCOPY) -O binary $< $@ |
| 154 | |
| 155 | $(OUT)vgabios.bin: $(OUT)vgabios.bin.raw |
| 156 | @echo " Finalizing rom $@" |
| 157 | $(Q)./tools/buildrom.py $< $@ |
| 158 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 159 | ####### Generic rules |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 160 | clean: |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 161 | $(Q)rm -rf $(OUT) |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 162 | |
| 163 | $(OUT): |
Kevin O'Connor | 86cebee | 2008-11-06 18:57:10 -0500 | [diff] [blame] | 164 | $(Q)mkdir $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 165 | |
| 166 | -include $(OUT)*.d |