Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
88 lines (71 loc) · 2.79 KB
/
Copy pathMakefile
File metadata and controls
88 lines (71 loc) · 2.79 KB
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
# Makefile to make and run with QEMU. //ember2819
CC = clang
AS = nasm
LD = ld
OBJCOPY = objcopy
include_folder = include
CC_FLAGS = -target x86_64-elf -march=x86-64 -m64 -MMD -MP \
-ffreestanding -nostdlib -fno-builtin -fno-stack-protector \
-mno-red-zone -mcmodel=kernel \
-mno-sse -mno-sse2 -mno-avx \
-g -c $(addprefix -I,$(include_folder)) -DDEBUG
LD_FLAGS = -m elf_x86_64
SOURCES := $(shell find ./kernel -name "*.c" -o -name "*.s")
OBJECTS := $(patsubst ./kernel/%.c,./build/%.o, $(SOURCES))
OBJECTS := $(patsubst ./kernel/%.s,./build/%_s.o, $(OBJECTS))
DEPS := $(OBJECTS:.o=.d)
all: grub-iso
build/%.o: kernel/%.c
@mkdir -p $(dir $@)
$(CC) $(CC_FLAGS) $< -o $@
build/%_s.o: kernel/%.s
@mkdir -p $(dir $@)
$(AS) -felf64 $< -o $@
kernel.elf: $(OBJECTS)
$(LD) $(LD_FLAGS) -T linker.ld $^ -o kernel.elf
-include $(DEPS)
ISODIR = isodir
grub-modules/i386-pc/modinfo.sh:
@echo "Downloading i386-pc GRUB modules..."
@mkdir -p grub-modules
@curl -sL "https://archive.archlinux.org/packages/g/grub/grub-2%3A2.14-1-x86_64.pkg.tar.zst" \
-o /tmp/grub-x86_64.pkg.tar.zst
@tar --zstd -xf /tmp/grub-x86_64.pkg.tar.zst -C /tmp 2>/dev/null || true
@cp -r /tmp/usr/lib/grub/i386-pc grub-modules/
@rm -rf /tmp/usr /tmp/grub-x86_64.pkg.tar.zst
grub-iso: kernel.elf grub-modules/i386-pc/modinfo.sh
@mkdir -p $(ISODIR)/boot/grub
cp kernel.elf $(ISODIR)/boot/kernel.elf
cp boot/grub/grub.cfg $(ISODIR)/boot/grub/grub.cfg
grub-mkrescue --directory=grub-modules/i386-pc -o gecko.iso $(ISODIR) --locale-directory=/usr/share/locale
@echo "gecko.iso built. Boot with: make run-grub"
run-grub: gecko.iso
qemu-system-x86_64 -cdrom gecko.iso -boot order=d \
-netdev user,id=net0 \
-device e1000,netdev=net0
fat32.img:
dd if=/dev/zero of=fat32.img bs=1M count=64
mkfs.fat -F 32 -n "GECKOOS" fat32.img
@echo "fat32.img created."
Elffile:
$(MAKE) -C Assets/Elf\ for\ testing
mv Assets/Elf\ for\ testing/Elf .
run-fat32: gecko.iso fat32.img # I dont want to make a new .img
qemu-system-x86_64 \
-cdrom gecko.iso -m 1G \
-drive format=raw,file=fat32.img \
-boot order=d \
-netdev user,id=net0 \
-device e1000,netdev=net0 -machine acpi=on \
-monitor stdio # -M hpet=on -machine q35 # -smp 4 # -d int,pcall
VBOXCreateMachine:
VBoxManage createvm --name "GECKOOS" --ostype "Other_64" --register
VBoxManage storagectl "GECKOOS" --name "IDE Controller" --add ide
run-virtualbox: # You have to create the machine first, then you can run geckos in virtualbox
VBoxManage storageattach "GECKOOS" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium gecko.iso
VBoxManage startvm "GECKOOS"
clean:
rm -f $(OBJECTS) $(DEPS)
rm -f kernel.elf gecko.iso
rm -rf $(ISODIR)
.PHONY: all grub-iso run-grub fat32.img run-fat32 clean