2024-01-27 03:29:49 +00:00
|
|
|
SRC_DIR=src
|
|
|
|
INCLUDE_DIR=include
|
|
|
|
BUILD_DIR=build
|
|
|
|
|
|
|
|
K_BIN_NAME=kernel.bin
|
|
|
|
ISO_NAME=os_image.iso
|
|
|
|
|
2024-01-27 06:16:48 +00:00
|
|
|
CC=cc
|
|
|
|
LD=ld
|
|
|
|
|
2024-02-01 02:19:22 +00:00
|
|
|
CFLAGS+=-std=c2x -ffreestanding -fno-stack-protector -g -Wall -Wextra -pedantic -lgcc -isystem $(INCLUDE_DIR)
|
|
|
|
CFLAGS+=-DPAGE_SIZE=4096
|
|
|
|
|
2024-02-01 02:26:55 +00:00
|
|
|
LDFLAGS+=-nmagic
|
2024-01-27 06:16:48 +00:00
|
|
|
|
2024-01-27 03:29:49 +00:00
|
|
|
C_SRC=$(shell find $(SRC_DIR) -type f -name "*.c")
|
|
|
|
C_OBJ=$(patsubst %.c,$(BUILD_DIR)/%.o,$(C_SRC))
|
|
|
|
|
2024-01-27 06:16:48 +00:00
|
|
|
H_SRC=$(shell find $(SRC_DIR) -type f -name "*.h")
|
|
|
|
H_INCLUDE=$(shell find $(INCLUDE_DIR) -type f -name "*.h")
|
2024-01-27 03:29:49 +00:00
|
|
|
|
|
|
|
A_SRC=$(shell find $(SRC_DIR) -type f -name "*.S")
|
|
|
|
A_OBJ=$(patsubst %.S,$(BUILD_DIR)/%.S.o,$(A_SRC))
|
|
|
|
|
|
|
|
.PHONY: all clean
|
|
|
|
|
|
|
|
all: $(BUILD_DIR)/$(ISO_NAME)
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -rf $(BUILD_DIR)/*
|
|
|
|
|
|
|
|
$(A_OBJ): $(BUILD_DIR)/%.S.o : %.S
|
|
|
|
@mkdir -p $(@D)
|
|
|
|
nasm $< -f elf64 -o $@
|
|
|
|
|
|
|
|
$(C_OBJ): $(BUILD_DIR)/%.o : %.c
|
|
|
|
@mkdir -p $(@D)
|
|
|
|
$(CC) -c $(CFLAGS) -o $@ $<
|
|
|
|
|
2024-02-01 02:26:55 +00:00
|
|
|
$(BUILD_DIR)/$(K_BIN_NAME): arch/amd64/linker.ld $(A_OBJ) $(C_OBJ) $(H_SRC) $(H_INCLUDE)
|
2024-01-27 03:29:49 +00:00
|
|
|
@mkdir -p $(@D)
|
2024-02-01 02:26:55 +00:00
|
|
|
$(LD) $(LDFLAGS) -T arch/amd64/linker.ld -o $(BUILD_DIR)/$(K_BIN_NAME) $(A_OBJ) $(C_OBJ)
|
2024-01-27 03:29:49 +00:00
|
|
|
|
|
|
|
$(BUILD_DIR)/$(ISO_NAME): $(BUILD_DIR)/$(K_BIN_NAME) grub.cfg
|
|
|
|
@mkdir -p $(@D)
|
|
|
|
@mkdir -p $(BUILD_DIR)/iso/boot/grub
|
2024-02-01 02:26:55 +00:00
|
|
|
cp grub.cfg $(BUILD_DIR)/iso/boot/grub
|
2024-01-27 03:29:49 +00:00
|
|
|
cp $(BUILD_DIR)/$(K_BIN_NAME) $(BUILD_DIR)/iso/boot
|
|
|
|
grub-mkrescue -o $(BUILD_DIR)/$(ISO_NAME) $(BUILD_DIR)/iso
|
2024-01-27 08:33:01 +00:00
|
|
|
|
2024-01-29 00:22:09 +00:00
|
|
|
run: all
|
2024-01-30 17:53:31 +00:00
|
|
|
qemu-system-x86_64 \
|
|
|
|
-cdrom $(BUILD_DIR)/$(ISO_NAME) \
|
|
|
|
-serial stdio \
|
2024-02-01 17:48:55 +00:00
|
|
|
-display gtk,show-menubar=off,zoom-to-fit=on \
|
2024-01-30 17:53:31 +00:00
|
|
|
-m 4G \
|
2024-02-01 17:48:55 +00:00
|
|
|
-enable-kvm \
|
2024-01-30 17:53:31 +00:00
|
|
|
-name corn
|