This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
68 lines (53 loc) · 2.06 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
.DELETE_ON_ERROR:
.PHONY: all clean
CC := i686-doors-gcc
CC_FOR_BUILD := gcc
NASM := nasm
CFLAGS ?= -O3
FIXED_FLAGS := -ffreestanding -Wall -Wextra -Werror
FIXED_LINK_FLAGS := -ffreestanding -nostdlib -T link.ld -lgcc
BUILDDIR := build
OBJFILES := $(addprefix $(BUILDDIR)/,boot.o screen.o longmode.o longmode_asm.o elf.o bootinfo.o ata.o disk.o bootsector.o)
all: $(BUILDDIR)/loader.bin $(BUILDDIR)/genfat
clean:
rm -rf $(BUILDDIR)
# TODO: allow customizing the image and boot partition size.
# Partition table entry for boot partition:
# 0x00 (not bootable), 0x20 (starting head), 0x21 (sector), 0x00 (cylinder),
# 0x06 (FAT16), 0x2A (ending head), 0x28 (sector), 0x02 (cylinder),
# 0x00 0x08 0x00 0x00 (starting LBA), 0x00 0x80 0x00 0x00 (total sectors)
# (I'm assuming 255 heads -- is this correct? But CHS is obsolete though...)
$(BUILDDIR)/loader.bin: $(OBJFILES) link.ld
$(CC) $(OBJFILES) -o $@ $(FIXED_LINK_FLAGS)
printf '\x00\x20\x21\x00\x06\x2a\x28\x02\x00\x08\x00\x00\x00\x80\x00\x00' | \
dd of=$@ bs=1 seek=446 count=16 conv=notrunc
$(BUILDDIR)/boot.o: boot.c bootloader.h
@mkdir -p $(BUILDDIR)
$(CC) -c $< -o $@ $(FIXED_FLAGS) $(CFLAGS)
$(BUILDDIR)/disk.o: disk.c bootloader.h
@mkdir -p $(BUILDDIR)
$(CC) -c $< -o $@ $(FIXED_FLAGS) $(CFLAGS)
$(BUILDDIR)/longmode.o: longmode.c bootloader.h
@mkdir -p $(BUILDDIR)
$(CC) -c $< -o $@ $(FIXED_FLAGS) $(CFLAGS)
$(BUILDDIR)/longmode_asm.o: longmode.asm
@mkdir -p $(BUILDDIR)
$(NASM) $< -o $@ -felf32
$(BUILDDIR)/elf.o: elf.c bootloader.h
@mkdir -p $(BUILDDIR)
$(CC) -c $< -o $@ $(FIXED_FLAGS) $(CFLAGS)
$(BUILDDIR)/bootinfo.o: bootinfo.c bootloader.h
@mkdir -p $(BUILDDIR)
$(CC) -c $< -o $@ $(FIXED_FLAGS) $(CFLAGS)
$(BUILDDIR)/screen.o: screen.c bootloader.h
@mkdir -p $(BUILDDIR)
$(CC) -c $< -o $@ $(FIXED_FLAGS) $(CFLAGS)
$(BUILDDIR)/ata.o: ata.c bootloader.h
@mkdir -p $(BUILDDIR)
$(CC) -c $< -o $@ $(FIXED_FLAGS) $(CFLAGS)
$(BUILDDIR)/bootsector.o: boot.asm
@mkdir -p $(BUILDDIR)
$(NASM) $< -o $@ -felf32
$(BUILDDIR)/genfat: genfat.c
@mkdir -p $(BUILDDIR)
$(CC_FOR_BUILD) $< -o $@ -Wall -Wextra -Werror -O3