moved stuff around

This commit is contained in:
2026-06-10 09:39:37 -04:00
parent 20fd32f978
commit 0f8d5f8ce7
8 changed files with 58 additions and 76 deletions

View File

@@ -5,38 +5,51 @@ OBJCOPY = i686-elf-objcopy
CFLAGS = -m32 -ffreestanding -O2 -Wall -Wextra -nostdlib
ASFLAGS = -m32
BOOT_DIR := boot
KERNEL_DIR := kernel
BUILD_DIR := build
BOOT_BIN := $(BUILD_DIR)/boot.bin
KERNEL_BIN := $(BUILD_DIR)/kernel.bin
IMAGE := os.img
.PHONY: all clean run
all: os.img
all: $(IMAGE)
boot.o: boot.s
$(CC) $(ASFLAGS) -c boot.s -o boot.o
$(BUILD_DIR)/%.o: $(BOOT_DIR)/%.s | $(BUILD_DIR)
$(CC) $(ASFLAGS) -c $< -o $@
boot.elf: boot.o boot.ld
$(LD) -T boot.ld -o boot.elf boot.o
$(BUILD_DIR)/%.o: $(KERNEL_DIR)/%.s | $(BUILD_DIR)
$(CC) $(ASFLAGS) -c $< -o $@
boot.bin: boot.elf
$(OBJCOPY) -O binary boot.elf boot.bin
$(BUILD_DIR)/%.o: $(KERNEL_DIR)/%.c | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
prekernel.o: prekernel.s
$(CC) $(ASFLAGS) -c prekernel.s -o prekernel.o
$(BUILD_DIR)/boot.elf: $(BUILD_DIR)/boot.o $(BOOT_DIR)/boot.ld
$(LD) -T $(BOOT_DIR)/boot.ld -o $@ $(BUILD_DIR)/boot.o
kmain.o: kmain.c
$(CC) $(CFLAGS) -c kmain.c -o kmain.o
$(BOOT_BIN): $(BUILD_DIR)/boot.elf
$(OBJCOPY) -O binary $< $@
kernel.elf: prekernel.o kmain.o kernel.ld
$(LD) -T kernel.ld -o kernel.elf prekernel.o kmain.o
KERNEL_OBJS := $(BUILD_DIR)/prekernel.o $(BUILD_DIR)/kmain.o
kernel.bin: kernel.elf
$(OBJCOPY) -O binary kernel.elf kernel.bin
$(BUILD_DIR)/kernel.elf: $(KERNEL_OBJS) $(KERNEL_DIR)/kernel.ld
$(LD) -T $(KERNEL_DIR)/kernel.ld -o $@ $(KERNEL_OBJS)
os.img: boot.bin kernel.bin
dd if=boot.bin of=os.img bs=512 count=1
dd if=kernel.bin of=os.img bs=512 seek=1
truncate -s 1440k os.img
$(KERNEL_BIN): $(BUILD_DIR)/kernel.elf
$(OBJCOPY) -O binary $< $@
run: os.img
qemu-system-i386 -drive format=raw,file=os.img
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(IMAGE): $(BOOT_BIN) $(KERNEL_BIN)
dd if=$(BOOT_BIN) of=$@ bs=512 count=1
dd if=$(KERNEL_BIN) of=$@ bs=512 seek=1
truncate -s 1440k $@
run: $(IMAGE)
qemu-system-i386 -drive format=raw,file=$(IMAGE)
clean:
rm -f *.o *.elf *.bin os.img
rm -rf $(BUILD_DIR) $(IMAGE)