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

2
.gitignore vendored
View File

@@ -4,3 +4,5 @@ sysroot
.idea
.vscode
build

View File

View File

@@ -1,6 +1,8 @@
#include <stdint.h>
extern void halt();
extern void idt_load();
extern void reboot();
typedef struct {
uint16_t offset_low;

View File

@@ -46,7 +46,7 @@ enable_a20:
outb %al, $0x92
prep_protected:
cli
lgdt (gdt_init-_start)
lgdt gdt_init-_start
mov %cr0, %eax
or $0x01, %eax
mov %eax, %cr0 # protected bit set
@@ -57,7 +57,7 @@ halt16:
.code32
protected:
mov $2*8, %ax
mov $16, %ax
mov %ax, %es
mov %ax, %ds
mov %ax, %ss
@@ -70,47 +70,12 @@ protected:
mov $0xFFF0, %bp
ljmpl $8, $kmain
.align 4
.global video_info_struct
video_info_struct:
.word 0
.byte 0,0
.word 0,0,0,0
.long 0
.global video_xbytes
video_xbytes:
.word 0
.global video_xres
video_xres:
.word 0
.global video_yres
video_yres:
.word 0
.byte 0,0,0,0,0,0,0,0,0
.byte 0,0,0,0,0,0,0,0,0
.global video_buffer
video_buffer:
.long 0
.long 0
.word 0
.word 0
.byte 0,0,0,0,0,0,0,0,0,0
.long 0
.rept 190
.byte 0
.endr
# some assembly stubs we can call from the kernel
.global idt_load
.extern idtr
idt_load:
lidt (idtr)
ret
.global gdt_load
gdt_load:
lgdt (gdt_init)
lidt idtr
ret
.global reboot

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)

BIN
os.img Normal file

Binary file not shown.