3 # Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net>
5 # This file may be distributed under the terms of the GNU LGPLv3 license.
8 VERSION
=pre-0.5
.2-$(shell date
+"%Y%m%d_%H%M%S")-$(shell hostname
)
14 SRCBOTH
=misc.c pmm.c stacks.c output.c util.c block.c floppy.c ata.c mouse.c \
15 kbd.c pci.c serial.c clock.c pic.c cdrom.c ps2port.c smp.c resume.c \
16 pnpbios.c pirtable.c vgahooks.c ramdisk.c pcibios.c blockcmd.c \
17 usb.c usb-uhci.c usb-ohci.c usb-ehci.c usb-hid.c usb-msc.c
18 SRC16
=$(SRCBOTH
) system.c disk.c apm.c font.c
19 SRC32FLAT
=$(SRCBOTH
) post.c shadow.c memmap.c coreboot.c boot.c \
20 acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \
21 lzmadecode.c usb-hub.c paravirt.c
22 SRC32SEG
=util.c output.c pci.c pcibios.c apm.c
24 cc-option
= $(shell if
test -z
"`$(1) $(2) -S -o /dev/null -xc \
25 /dev/null 2>&1`"; then echo
"$(2)"; else echo
"$(3)"; fi
;)
27 # Default compiler flags
28 COMMONCFLAGS
= -Os
-MD
-Wall
-Wno-strict-aliasing
-Wold-style-definition \
29 $(call cc-option
,$(CC
),-Wtype-limits
,) \
30 -m32
-march
=i386
-mregparm
=3 -mpreferred-stack-boundary
=2 \
31 -mrtd
-minline-all-stringops \
32 -freg-struct-return
-ffreestanding
-fomit-frame-pointer \
33 -fno-delete-null-pointer-checks \
34 -ffunction-sections
-fdata-sections
-fno-common
35 COMMONCFLAGS
+= $(call cc-option
,$(CC
),-nopie
,)
36 COMMONCFLAGS
+= $(call cc-option
,$(CC
),-fno-stack-protector
,)
37 COMMONCFLAGS
+= $(call cc-option
,$(CC
),-fno-stack-protector-all
,)
39 CFLAGS32FLAT
= $(COMMONCFLAGS
) -g
-DMODE16
=0 -DMODESEGMENT
=0
40 CFLAGSSEG
= $(COMMONCFLAGS
) -DMODESEGMENT
=1 -fno-defer-pop \
41 $(call cc-option
,$(CC
),-fno-jump-tables
,-DMANUAL_NO_JUMP_TABLE
) \
42 $(call cc-option
,$(CC
),-fno-tree-switch-conversion
,)
43 CFLAGS32SEG
= $(CFLAGSSEG
) -DMODE16
=0 -g
44 CFLAGS16INC
= $(CFLAGSSEG
) -DMODE16
=1 \
45 $(call cc-option
,$(CC
),--param large-stack-frame
=4,-fno-inline
)
46 CFLAGS16
= $(CFLAGS16INC
) -g
48 all: $(OUT
) $(OUT
)bios.bin
50 # Run with "make V=1" to see the actual compile commands
66 ################ Build rules
68 # Verify the gcc configuration and test if -fwhole-program works.
69 TESTGCC
:=$(shell CC
=$(CC
) tools
/test-gcc.sh
)
70 ifeq "$(TESTGCC)" "-1"
71 $(error
"Please upgrade GCC")
78 # Do a whole file compile - three methods are supported.
79 ifeq "$(COMPSTRAT)" "1"
80 # First method - use -fwhole-program without -combine.
82 @echo
" Compiling whole program $3"
83 $(Q
)printf
'$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
84 $(Q
)$(CC
) $1 -fwhole-program
-DWHOLE_PROGRAM
-c
$3.tmp.c
-o
$3
87 ifeq "$(COMPSTRAT)" "2"
88 # Second menthod - don't use -fwhole-program at all.
90 @echo
" Compiling whole program $3"
91 $(Q
)printf
'$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
92 $(Q
)$(CC
) $1 -c
$3.tmp.c
-o
$3
95 # Third (and preferred) method - use -fwhole-program with -combine
97 @echo
" Compiling whole program $3"
98 $(Q
)$(CC
) $1 -fwhole-program
-DWHOLE_PROGRAM
-combine
-c
$2 -o
$3
105 @echo
" Compiling to assembler $@"
106 $(Q
)$(CC
) $(CFLAGS16INC
) -S
-c
$< -o
$@
109 @echo
" Precompiling $@"
110 $(Q
)$(CPP
) -P
-D__ASSEMBLY__
$< -o
$@
112 $(OUT
)asm-offsets.h
: $(OUT
)asm-offsets.s
113 @echo
" Generating offset file $@"
114 $(Q
).
/tools
/gen-offsets.sh
$< $@
117 $(OUT
)ccode
.16.s
: ; $(call whole-compile
, $(CFLAGS16
) -S
, $(addprefix src
/, $(SRC16
)),$@
)
119 $(OUT
)code32seg.o
: ; $(call whole-compile
, $(CFLAGS32SEG
), $(addprefix src
/, $(SRC32SEG
)),$@
)
121 $(OUT
)ccode32flat.o
: ; $(call whole-compile
, $(CFLAGS32FLAT
), $(addprefix src
/, $(SRC32FLAT
)),$@
)
123 $(OUT
)code16.o
: romlayout.S
$(OUT
)ccode
.16.s
$(OUT
)asm-offsets.h
124 @echo
" Compiling (16bit) $@"
125 $(Q
)$(CC
) $(CFLAGS16INC
) -c
-D__ASSEMBLY__
$< -o
$@
127 $(OUT
)romlayout16.lds
$(OUT
)romlayout32seg.lds
$(OUT
)romlayout32flat.lds
$(OUT
)code32flat.o
: $(OUT
)ccode32flat.o
$(OUT
)code32seg.o
$(OUT
)code16.o tools
/layoutrom.py
128 @echo
" Building ld scripts (version \"$(VERSION)\")"
129 $(Q
)echo
'const char VERSION[] = "$(VERSION)";' > $(OUT
)version.c
130 $(Q
)$(CC
) $(CFLAGS32FLAT
) -c
$(OUT
)version.c
-o
$(OUT
)version.o
131 $(Q
)$(LD
) -melf_i386
-r
$(OUT
)ccode32flat.o
$(OUT
)version.o
-o
$(OUT
)code32flat.o
132 $(Q
)$(OBJDUMP
) -thr
$(OUT
)code32flat.o
> $(OUT
)code32flat.o.objdump
133 $(Q
)$(OBJDUMP
) -thr
$(OUT
)code32seg.o
> $(OUT
)code32seg.o.objdump
134 $(Q
)$(OBJDUMP
) -thr
$(OUT
)code16.o
> $(OUT
)code16.o.objdump
135 $(Q
).
/tools
/layoutrom.py
$(OUT
)code16.o.objdump
$(OUT
)code32seg.o.objdump
$(OUT
)code32flat.o.objdump
$(OUT
)romlayout16.lds
$(OUT
)romlayout32seg.lds
$(OUT
)romlayout32flat.lds
138 $(OUT
)rom16.o
: $(OUT
)code16.o
$(OUT
)rom32flat.o
$(OUT
)romlayout16.lds
139 @echo
" Linking (no relocs) $@"
140 $(Q
)$(LD
) -r
-T
$(OUT
)romlayout16.lds
$< -o
$@
142 $(OUT
)rom32seg.o
: $(OUT
)code32seg.o
$(OUT
)romlayout32seg.lds
143 @echo
" Linking (no relocs) $@"
144 $(Q
)$(LD
) -r
-T
$(OUT
)romlayout32seg.lds
$< -o
$@
146 $(OUT
)rom32flat.o
: $(OUT
)code32flat.o
$(OUT
)romlayout32flat.lds
147 @echo
" Linking (no relocs) $@"
148 $(Q
)$(LD
) -r
-T
$(OUT
)romlayout32flat.lds
$< -o
$@
150 $(OUT
)rom.o
: $(OUT
)rom16.o
$(OUT
)rom32seg.o
$(OUT
)rom32flat.o
$(OUT
)rombios16.lds
$(OUT
)rombios32seg.lds
$(OUT
)rombios.lds
152 $(Q
)$(LD
) -T
$(OUT
)rombios16.lds
$(OUT
)rom16.o
-R
$(OUT
)rom32seg.o
-R
$(OUT
)rom32flat.o
-o
$(OUT
)rom16.reloc.o
153 $(Q
)$(STRIP
) $(OUT
)rom16.reloc.o
-o
$(OUT
)rom16.final.o
154 $(Q
)$(OBJCOPY
) --adjust-vma
0xf0000 $(OUT
)rom16.o
$(OUT
)rom16.moved.o
155 $(Q
)$(LD
) -T
$(OUT
)rombios32seg.lds
$(OUT
)rom32seg.o
-R
$(OUT
)rom16.o
-R
$(OUT
)rom32flat.o
-o
$(OUT
)rom32seg.reloc.o
156 $(Q
)$(STRIP
) $(OUT
)rom32seg.reloc.o
-o
$(OUT
)rom32seg.final.o
157 $(Q
)$(OBJCOPY
) --adjust-vma
0xf0000 $(OUT
)rom32seg.o
$(OUT
)rom32seg.moved.o
158 $(Q
)$(LD
) -T
$(OUT
)rombios.lds
$(OUT
)rom16.final.o
$(OUT
)rom32seg.final.o
$(OUT
)rom32flat.o
-R
$(OUT
)rom16.moved.o
-R
$(OUT
)rom32seg.moved.o
-o
$@
160 $(OUT
)bios.bin.elf
$(OUT
)bios.bin
: $(OUT
)rom.o tools
/checkrom.py
162 $(Q
)$(OBJDUMP
) -thr
$< > $<.objdump
163 $(Q
)$(OBJCOPY
) -O binary
$< $(OUT
)bios.bin.raw
164 $(Q
).
/tools
/checkrom.py
$<.objdump
$(OUT
)bios.bin.raw
$(OUT
)bios.bin
165 $(Q
)$(STRIP
) -R .comment
$< -o
$(OUT
)bios.bin.elf
168 ################ VGA build rules
171 SRCVGA
=src
/output.c src
/util.c vgasrc
/vga.c vgasrc
/vgafb.c vgasrc
/vgaio.c \
172 vgasrc
/vgatables.c vgasrc
/vgafonts.c vgasrc
/clext.c
174 $(OUT
)vgaccode
.16.s
: ; $(call whole-compile
, $(CFLAGS16
) -S
-Isrc
, $(SRCVGA
),$@
)
176 $(OUT
)vgalayout16.o
: vgaentry.S
$(OUT
)vgaccode
.16.s
$(OUT
)asm-offsets.h
177 @echo
" Compiling (16bit) $@"
178 $(Q
)$(CC
) $(CFLAGS16INC
) -c
-D__ASSEMBLY__
-Isrc
$< -o
$@
180 $(OUT
)vgarom.o
: $(OUT
)vgalayout16.o
$(OUT
)vgalayout.lds
182 $(Q
)$(LD
) --gc-sections
-T
$(OUT
)vgalayout.lds
$(OUT
)vgalayout16.o
-o
$@
184 $(OUT
)vgabios.bin.raw
: $(OUT
)vgarom.o
185 @echo
" Extracting binary $@"
186 $(Q
)$(OBJCOPY
) -O binary
$< $@
188 $(OUT
)vgabios.bin
: $(OUT
)vgabios.bin.raw tools
/buildrom.py
189 @echo
" Finalizing rom $@"
190 $(Q
).
/tools
/buildrom.py
$< $@
192 ####### dsdt build rules
193 src
/acpi-dsdt.hex
: src
/acpi-dsdt.dsl
194 @echo
"Compiling DSDT"
195 $(Q
)cpp -P
$< > $(OUT
)acpi-dsdt.dsl.i
196 $(Q
)iasl
-tc
-p
$@
$(OUT
)acpi-dsdt.dsl.i
197 $(Q
)rm $(OUT
)acpi-dsdt.dsl.i
199 ####### Generic rules