Loaded a kernel

This commit is contained in:
2026-02-26 17:41:53 +00:00
parent 8993630081
commit f266dd7c8c
5 changed files with 365 additions and 79 deletions

View File

@@ -37,6 +37,9 @@ LIBS = -lefi -lgnuefi
TARGET = BOOTX64.EFI
TARGET_SO = bootx64.so
OBJ = $(BUILD_DIR)/main.o
KERNEL_TARGET = kernel.elf
KERNEL_OBJ = $(BUILD_DIR)/kernel.o
KERNEL_LD = kernel.ld
# QEMU settings
QEMU = qemu-system-x86_64
@@ -79,7 +82,7 @@ QEMU_FLAGS = -machine q35 \
.PHONY: all clean run setup install-deps
# Default target
all: setup $(EFI_DIR)/$(TARGET)
all: setup $(EFI_DIR)/$(TARGET) $(BUILD_DIR)/$(KERNEL_TARGET)
# Create necessary directories
setup:
@@ -92,6 +95,17 @@ $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@echo "Compiling $<..."
$(CC) $(CFLAGS) -c $< -o $@
# Compile kernel source
$(KERNEL_OBJ): $(SRC_DIR)/kernel.c
@echo "Compiling kernel.c..."
$(CC) -ffreestanding -fno-stack-protector -fno-pic -fshort-wchar \
-mno-red-zone -Wall -Wextra $(EFI_INCLUDES) -c $< -o $@
# Link kernel ELF
$(BUILD_DIR)/$(KERNEL_TARGET): $(KERNEL_OBJ) $(KERNEL_LD)
@echo "Linking kernel ELF..."
$(LD) -nostdlib -T $(KERNEL_LD) $(KERNEL_OBJ) -o $@
# Link to create shared object
$(BUILD_DIR)/$(TARGET_SO): $(OBJ)
@echo "Linking $@..."