Skip to content

Commit

Permalink
compile and run
Browse files Browse the repository at this point in the history
  • Loading branch information
BitInit committed Jan 7, 2024
1 parent ae9db44 commit 0315f03
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Makefile
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
34 changes: 34 additions & 0 deletions arch/Makefile
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)
9 changes: 9 additions & 0 deletions arch/x86/Makefile
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
6 changes: 6 additions & 0 deletions arch/x86/boot/Makefile
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
4 changes: 4 additions & 0 deletions arch/x86/kernel/Makefile
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
3 changes: 3 additions & 0 deletions init/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

build:
echo "init"
4 changes: 4 additions & 0 deletions kernel/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

build:
echo $(baseDir)

3 changes: 3 additions & 0 deletions mm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

build:
echo "mm"

0 comments on commit 0315f03

Please sign in to comment.