Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
ASM := nasm
CC := gcc
LD := ld
OBJCOPY := objcopy
QEMU := qemu-system-x86_64

BOOT_DIR := boot
KERNEL_DIR := kernel
OUT_DIR := out

BOOT_BIN := $(OUT_DIR)/bootloader.bin
KERNEL_ELF := $(OUT_DIR)/kernel.elf
KERNEL_BIN := $(OUT_DIR)/kernel.bin
OS_IMG := $(OUT_DIR)/os.img

ASMFLAGS := -f bin
CFLAGS := -ffreestanding -nostdlib -m32 -Wall -Wextra -O2 -std=c11
LDFLAGS := -m elf_i386 -nostdlib -Ttext 0x1000

.PHONY: all build run clean

all: build

build: $(OS_IMG)

$(OUT_DIR):
mkdir -p $@

$(BOOT_BIN): $(BOOT_DIR)/bootloader.asm | $(OUT_DIR)
$(ASM) $(ASMFLAGS) -o $@ $<

$(KERNEL_ELF): $(KERNEL_DIR)/kernel.c | $(OUT_DIR)
$(CC) $(CFLAGS) -nostartfiles -Wl,-e,kernel_main -o $@ $<

$(KERNEL_BIN): $(KERNEL_ELF) | $(OUT_DIR)
$(OBJCOPY) -O binary $< $@

$(OS_IMG): $(BOOT_BIN) $(KERNEL_BIN) | $(OUT_DIR)
cat $(BOOT_BIN) $(KERNEL_BIN) > $@
dd if=/dev/zero bs=1024 count=1440 >> $@ 2>/dev/null || true

run: $(OS_IMG)
$(QEMU) -fda $<

clean:
rm -rf $(OUT_DIR)
22 changes: 22 additions & 0 deletions boot/bootloader.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
mov ah, 0x0e
mov al, 65 ; starting with capital A
int 0x10

; print the alphabet while alternating caps
.loop:
cmp al, 120 ; 122 is for z
jg .done

xor al, 32 ; the space for each capital/lowercase is 32
inc al

int 0x10
jmp .loop


.done:
jmp $ ; jump to current address forever

; Boot sector padding
times 510 - ($ - $$) db 0x0
dw 0xaa55