-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export BASE_DIR=$(shell pwd) | ||
export TARGET_ISO=HelloOS.iso | ||
export CONFIG_x86_64=y | ||
export CC=gcc | ||
export AS=as | ||
export HIDE=@ | ||
ifneq ($(HIDE),) | ||
MAKEFLAGS += --no-print-dirctory | ||
endif | ||
|
||
|
||
HelloOS: | ||
$(HIDE)make -C arch | ||
|
||
clean: | ||
$(HIDE)make -C arch clean | ||
|
||
cleanall: | ||
$(HIDE)make -C arch cleanall | ||
|
||
run: | ||
qemu-system-x86_64 -m 1G -cdrom arch/$(TARGET_ISO) -nographic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
kernel_target=kernel.elf | ||
SRCS = $(BASE_DIR)/init $(BASE_DIR)/kernel $(BASE_DIR)/mm | ||
ifeq ($(CONFIG_x86_64), y) | ||
SRCS += $(BASE_DIR)/arch/x86 | ||
lds = $(BASE_DIR)/arch/x86/boot/vmlinux.lds | ||
else | ||
$(HIDE)echo "unkown arch..." | ||
endif | ||
|
||
$(TARGET_ISO): $(kernel_target) | ||
$(HIDE)rm -rf build_dir | ||
$(HIDE)mkdir -p build_dir/boot/grub | ||
$(HIDE)cp $(kernel_target) build_dir/boot | ||
|
||
$(HIDE)echo 'set timeout=0' > build_dir/boot/grub/grub.cfg | ||
$(HIDE)echo 'set default=0' >> build_dir/boot/grub/grub.cfg | ||
$(HIDE)echo 'menuentry "HelloOS" {' >> build_dir/boot/grub/grub.cfg | ||
$(HIDE)echo ' multiboot2 /boot/kernel.elf "HelloOS"' >> build_dir/boot/grub/grub.cfg | ||
$(HIDE)echo '}' >> build_dir/boot/grub/grub.cfg | ||
|
||
$(HIDE)grub-mkrescue -o $(TARGET_ISO) build_dir | ||
$(HIDE)rm -rf build_dir | ||
|
||
$(kernel_target): | ||
$(HIDE)for dir in $(SRCS); do \ | ||
make -C $$dir || exit 1; \ | ||
done | ||
$(HIDE)ld -b elf64-x86-64 -z muldefs -o $(kernel_target) -Map=./kernel.map -T $(lds) $(shell find $(SRCS) -name "*.o") | ||
|
||
clean: | ||
$(HIDE)rm -rf $(kernel_target) $(TARGET_ISO) kernel.map | ||
|
||
cleanall: clean | ||
$(HIDE)rm -rf $(kernel_target) $(TARGET_ISO) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export ASFLAGS=--64 | ||
export CFLAGS = -I$(BASE_DIR)/include --static -fno-pie -fno-builtin -fno-stack-protector -m64 | ||
|
||
x86_srcs = boot kernel | ||
|
||
build: | ||
$(HIDE)for dir in $(x86_srcs); do \ | ||
make -C $$dir || exit 1; \ | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
build: header.o | ||
|
||
header.o: header.S | ||
$(HIDE)$(CC) -E $(CFLAGS) $< > header.i | ||
$(HIDE)$(AS) $(ASFLAGS) -o $@ header.i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
head_64.o: head_64.S | ||
$(HIDE)$(CC) -E $(CFLAGS) $< > head_64.i | ||
$(HIDE)$(AS) $(ASFLAGS) -o $@ head_64.i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
build: | ||
echo "init" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
build: | ||
echo $(baseDir) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
build: | ||
echo "mm" |