Skip to content

Commit eb399f0

Browse files
Add files via upload
1 parent 506504d commit eb399f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+75861
-0
lines changed

part4/GNUmakefile

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Nuke built-in rules and variables.
2+
override MAKEFLAGS += -rR
3+
4+
override IMAGE_NAME := shitos
5+
override TEST_DRIVE := test.img
6+
7+
.PHONY: all
8+
all: $(IMAGE_NAME).iso
9+
10+
.PHONY: all-hdd
11+
all-hdd: $(IMAGE_NAME).hdd
12+
13+
.PHONY: run
14+
run: $(IMAGE_NAME).iso
15+
qemu-system-x86_64 -M q35 -m 2G -drive file=$(TEST_DRIVE),format=raw -cdrom $(IMAGE_NAME).iso -boot d
16+
17+
.PHONY: debug
18+
debug: $(IMAGE_NAME).iso
19+
objcopy --only-keep-debug "./kernel/kernel.elf" "./kernel.sym"
20+
qemu-system-x86_64 -s -S -M q35 -m 2G -drive file=$(TEST_DRIVE),format=raw -cdrom $(IMAGE_NAME).iso -boot d
21+
22+
.PHONY: run-uefi
23+
run-uefi: ovmf $(IMAGE_NAME).iso
24+
qemu-system-x86_64 -M q35 -m 2G -bios ovmf/OVMF.fd -cdrom $(IMAGE_NAME).iso -boot d -display sdl -sdl -serial stdio
25+
26+
27+
.PHONY: run-hdd
28+
run-hdd: $(IMAGE_NAME).hdd
29+
qemu-system-x86_64 -M q35 -m 2G -hda $(IMAGE_NAME).hdd
30+
31+
.PHONY: run-hdd-uefi
32+
run-hdd-uefi: ovmf $(IMAGE_NAME).hdd
33+
qemu-system-x86_64 -M q35 -m 2G -bios ovmf/OVMF.fd -hda $(IMAGE_NAME).hdd
34+
35+
ovmf:
36+
mkdir -p ovmf
37+
cd ovmf && curl -Lo OVMF-X64.zip https://efi.akeo.ie/OVMF/OVMF-X64.zip && unzip OVMF-X64.zip
38+
39+
limine:
40+
git clone https://github.com/limine-bootloader/limine.git --branch=v4.x-branch-binary --depth=1
41+
$(MAKE) -C limine
42+
43+
.PHONY: kernel
44+
kernel:
45+
$(MAKE) -C kernel
46+
47+
$(IMAGE_NAME).iso: limine kernel
48+
rm -rf iso_root
49+
mkdir -p iso_root
50+
cp kernel/kernel.elf \
51+
limine.cfg limine/limine.sys limine/limine-cd.bin limine/limine-cd-efi.bin initrd.img iso_root/
52+
xorriso -as mkisofs -b limine-cd.bin \
53+
-no-emul-boot -boot-load-size 4 -boot-info-table \
54+
--efi-boot limine-cd-efi.bin \
55+
-efi-boot-part --efi-boot-image --protective-msdos-label \
56+
iso_root -o $(IMAGE_NAME).iso
57+
limine/limine-deploy $(IMAGE_NAME).iso
58+
rm -rf iso_root
59+
60+
$(IMAGE_NAME).hdd: limine kernel
61+
rm -f $(IMAGE_NAME).hdd
62+
dd if=/dev/zero bs=1M count=0 seek=64 of=$(IMAGE_NAME).hdd
63+
parted -s $(IMAGE_NAME).hdd mklabel gpt
64+
parted -s $(IMAGE_NAME).hdd mkpart ESP fat32 2048s 100%
65+
parted -s $(IMAGE_NAME).hdd set 1 esp on
66+
limine/limine-deploy $(IMAGE_NAME).hdd
67+
sudo losetup -Pf --show $(IMAGE_NAME).hdd >loopback_dev
68+
sudo mkfs.fat -F 32 `cat loopback_dev`p1
69+
mkdir -p img_mount
70+
sudo mount `cat loopback_dev`p1 img_mount
71+
sudo mkdir -p img_mount/EFI/BOOT
72+
sudo cp -v kernel/kernel.elf initrd.img limine.cfg limine/limine.sys img_mount/
73+
sudo cp -v limine/BOOTX64.EFI img_mount/EFI/BOOT/
74+
sync
75+
sudo umount img_mount
76+
sudo losetup -d `cat loopback_dev`
77+
rm -rf loopback_dev img_mount
78+
79+
.PHONY: clean
80+
clean:
81+
rm -rf iso_root $(IMAGE_NAME).iso $(IMAGE_NAME).hdd
82+
$(MAKE) -C kernel clean
83+
84+
.PHONY: distclean
85+
distclean: clean
86+
rm -rf limine ovmf
87+
$(MAKE) -C kernel distclean

part4/initrd.img

5.57 KB
Binary file not shown.

part4/kernel/GNUmakefile

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Nuke built-in rules and variables.
2+
override MAKEFLAGS += -rR
3+
4+
CC = /usr/local/cross-compiler/bin/x86_64-elf-gcc
5+
LD = /usr/local/cross-compiler/bin/x86_64-elf-ld
6+
# This is the name that our final kernel executable will have.
7+
# Change as needed.
8+
override KERNEL := kernel.elf
9+
10+
# Convenience macro to reliably declare user overridable variables.
11+
define DEFAULT_VAR =
12+
ifeq ($(origin $1),default)
13+
override $(1) := $(2)
14+
endif
15+
ifeq ($(origin $1),undefined)
16+
override $(1) := $(2)
17+
endif
18+
endef
19+
20+
# It is highly recommended to use a custom built cross toolchain to build a kernel.
21+
# We are only using "cc" as a placeholder here. It may work by using
22+
# the host system's toolchain, but this is not guaranteed.
23+
$(eval $(call $(CC)))
24+
25+
# Same thing for "ld" (the linker).
26+
$(eval $(call $(LD)))
27+
28+
# User controllable C flags.
29+
$(eval $(call $(CC),CFLAGS,-g -O2 -pipe -Wall -Wextra))
30+
31+
# User controllable C preprocessor flags. We set none by default.
32+
$(eval $(call $(CC),CPPFLAGS,))
33+
34+
# User controllable nasm flags.
35+
$(eval $(call DEFAULT_VAR,NASMFLAGS,-F dwarf -g))
36+
37+
# User controllable linker flags. We set none by default.
38+
$(eval $(call $(LD),LDFLAGS,))
39+
40+
# Internal C flags that should not be changed by the user.
41+
override CFLAGS += \
42+
-std=gnu11 \
43+
-ffreestanding \
44+
-fno-stack-protector \
45+
-fno-stack-check \
46+
-fno-lto \
47+
-fno-pie \
48+
-fno-pic \
49+
-m64 \
50+
-march=x86-64 \
51+
-mabi=sysv \
52+
-mno-80387 \
53+
-mno-mmx \
54+
-mno-sse \
55+
-mno-sse2 \
56+
-mno-red-zone \
57+
-mcmodel=kernel
58+
59+
# Internal C preprocessor flags that should not be changed by the user.
60+
override CPPFLAGS := \
61+
-I. \
62+
$(CPPFLAGS) \
63+
-MMD \
64+
-MP
65+
66+
# Internal linker flags that should not be changed by the user.
67+
override LDFLAGS += \
68+
-nostdlib \
69+
-static \
70+
\
71+
-z max-page-size=0x1000 \
72+
-T linker.ld
73+
74+
# Check if the linker supports -no-pie and enable it if it does.
75+
76+
# Internal nasm flags that should not be changed by the user.
77+
override NASMFLAGS += \
78+
-f elf64
79+
80+
# Use "find" to glob all *.c, *.S, and *.asm files in the tree and obtain the
81+
# object and header dependency file names.
82+
override CFILES := $(shell find -L . -type f -name '*.c')
83+
override ASFILES := $(shell find -L . -type f -name '*.S')
84+
override NASMFILES := $(shell find -L . -type f -name '*.asm')
85+
override OBJ := $(CFILES:.c=.o) $(ASFILES:.S=.o) $(NASMFILES:.asm=.o)
86+
override HEADER_DEPS := $(CFILES:.c=.d) $(ASFILES:.S=.d)
87+
88+
# Default target.
89+
.PHONY: all
90+
all: $(KERNEL)
91+
92+
limine.h:
93+
curl -Lo $@ https://github.com/limine-bootloader/limine/raw/trunk/limine.h
94+
95+
# Link rules for the final kernel executable.
96+
$(KERNEL): $(OBJ)
97+
sudo $(LD) $(OBJ) $(LDFLAGS) -o $@
98+
99+
# Include header dependencies.
100+
-include $(HEADER_DEPS)
101+
102+
# Compilation rules for *.c files.
103+
%.o: %.c limine.h
104+
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
105+
106+
# Compilation rules for *.S files.
107+
%.o: %.S limine.h
108+
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
109+
110+
# Compilation rules for *.asm (nasm) files.
111+
%.o: %.asm
112+
nasm $(NASMFLAGS) $< -o $@
113+
114+
.PHONY: debug
115+
debug: $(KERNEL)
116+
117+
%.o: %.c limine.h
118+
$(CC) $(CFLAGS) -g $(INTERNALCFLAGS) -c $< -o $@
119+
120+
# Remove object files and the final executable.
121+
.PHONY: clean
122+
clean:
123+
rm -rf $(KERNEL) $(OBJ) $(HEADER_DEPS)
124+
125+
.PHONY: distclean
126+
distclean: clean
127+
rm -f limine.h

part4/kernel/cprintc.o

7.95 KB
Binary file not shown.

0 commit comments

Comments
 (0)