-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
152 lines (120 loc) · 4.91 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
BIOS_CODE := build/bios/OVMF_CODE.fd
BIOS_VARS := build/bios/OVMF_VARS.fd
# linux
EFI_DIRS := /usr/lib
GNU_INC := src/gnu-efi/inc
GNU_LIB := build/gnu-efi
GCC_FLAGS = \
-c \
-fno-stack-protector \
-fpic \
-fshort-wchar \
-mno-red-zone \
-I $(GNU_INC) \
-I $(GNU_INC)/x86_64 \
-DEFI_FUNCTION_WRAPPER \
GLD_FLAGS = \
$(GNU_LIB)/crt0-efi-x86_64.o \
-nostdlib \
-znocombreloc \
-T $(GNU_LIB)/elf_x86_64_efi.lds \
-shared \
-Bsymbolic \
-L $(EFI_DIRS) \
-lgnuefi \
-lefi \
KGCC_FLAGS = \
-ffreestanding \
-fshort-wchar \
-mno-red-zone \
-fno-exceptions \
KLD_FLAGS = \
-static \
-Bsymbolic \
-nostdlib \
-fno-stack-protector \
-shared \
OBJ_FLAGS = \
-j .text \
-j .sdata \
-j .data \
-j .dynamic \
-j .dynsym \
-j .rel \
-j .rela \
-j .reloc \
--target=efi-app-x86_64 \
SRC = $(shell find src/kernel -name *.cpp)
OBJ = $(patsubst src/kernel/%.cpp, build/kernel/%.o, $(SRC))
ASMSRC = $(shell find src/kernel -name *.asm)
ASMOBJ = $(patsubst src/kernel/%.asm, build/kernel/%_asm.o, $(ASMSRC))
run: build/myos_img/EFI/BOOT/BootX64.efi build/myos_img/kernel.elf
qemu-system-x86_64 -machine q35 -cpu qemu64 -net none \
-device virtio-vga-gl -display sdl,gl=on \
-drive if=pflash,format=raw,unit=0,file=$(BIOS_CODE),readonly=on \
-drive if=pflash,format=raw,unit=1,file=$(BIOS_VARS),readonly=on \
-drive format=raw,file=fat:rw:build/myos_img
build/bootloader/main.o: src/bootloader/main.c
gcc $< $(GCC_FLAGS) -o $@
build/bootloader/main.so: build/bootloader/main.o
ld $< $(GLD_FLAGS) -o $@
build/bootloader/main.efi: build/bootloader/main.so
objcopy $(OBJ_FLAGS) $< $@
build/myos_img/EFI/BOOT/BootX64.efi: build/bootloader/main.efi
cp $< $@
build/kernel/main.o: src/kernel/main.cpp
gcc $(KGCC_FLAGS) -c $< -o $@
build/kernel/interrupts/interrupts.o: src/kernel/interrupts/interrupts.cpp
gcc -mno-red-zone -mgeneral-regs-only -ffreestanding -c $^ -o $@
build/kernel/%.o: src/kernel/%.cpp
@mkdir -p $(@D)
gcc -ffreestanding -fshort-wchar -mno-red-zone -fno-exceptions -c $^ -o $@
build/kernel/%_asm.o: src/kernel/%.asm
@mkdir -p $(@D)
nasm $^ -f elf64 -o $@
build/myos_img/kernel.elf: build/kernel/main.o $(OBJ) $(ASMOBJ)
ld -T src/kernel/kernel.ld -o $@ $(KLD_FLAGS) $^
# macos
# EFI_DIRS := /usr/local/include/efi
# PREFIX := x86_64-elf-
# GCC_FLAGS = \
# -I $(EFI_DIRS) -fpic -ffreestanding -fno-stack-protector \
# -fno-stack-check -fshort-wchar -mno-red-zone \
# -maccumulate-outgoing-args
# GLD_FLAGS = \
# -shared -Bsymbolic \
# -L $(EFI_DIRS) -L/usr/local/lib \
# -T/usr/local/lib/elf_x86_64_efi.lds
# GLD_LIBS = \
# /usr/local/lib/crt0-efi-x86_64.o -lgnuefi -lefi
# OBJ_FLAGS = \
# -j .text -j .sdata -j .data -j .dynamic -j .dynsym \
# -j .rel -j .rela -j .rel.* -j .rela.* -j .reloc \
# --target efi-app-x86_64 --subsystem=10
# SRC = $(shell find src/kernel -name *.cpp)
# OBJ = $(patsubst src/kernel/%.cpp, build/kernel/%.o, $(SRC))
# ASMSRC = $(shell find src/kernel -name *.asm)
# ASMOBJ = $(patsubst src/kernel/%.asm, build/kernel/%_asm.o, $(ASMSRC))
# run: build/myos_img/EFI/BOOT/BootX64.efi build/myos_img/kernel.elf
# qemu-system-x86_64 -machine q35 -cpu qemu64 -net none \
# -drive if=pflash,format=raw,unit=0,file=$(BIOS_CODE),readonly=on \
# -drive if=pflash,format=raw,unit=1,file=$(BIOS_VARS),readonly=on \
# -drive format=raw,file=fat:rw:build/myos_img
# build/bootloader/main.o: src/bootloader/main.c
# $(PREFIX)gcc $(GCC_FLAGS) -c $< -o $@
# build/bootloader/main.so: build/bootloader/main.o
# $(PREFIX)ld $(GLD_FLAGS) -o $@ $< $(GLD_LIBS)
# build/bootloader/main.efi: build/bootloader/main.so
# $(PREFIX)objcopy $(OBJ_FLAGS) $< $@
# build/myos_img/EFI/BOOT/BootX64.efi: build/bootloader/main.efi
# cp $< $@
# build/kernel/main.o: src/kernel/main.cpp
# clang -target x86_64-elf -fno-stack-protector -fno-stack-check -fno-exceptions -mno-red-zone -D__x86_64__ -I. -c $< -o $@
# build/kernel/%.o: src/kernel/%.cpp
# @mkdir -p $(@D)
# clang -target x86_64-elf -fno-stack-protector -fno-stack-check -fno-exceptions -mno-red-zone -D__x86_64__ -I. -c $^ -o $@
# build/kernel/%_asm.o: src/kernel/%.asm
# @mkdir -p $(@D)
# nasm $^ -f elf64 -o $@
# build/myos_img/kernel.elf: build/kernel/main.o $(OBJ) $(ASMOBJ)
# ld.lld -nostdlib -z max-page-size=0x1000 -T src/kernel/kernel.ld -o $@ $^