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

4
.gitignore vendored
View File

@@ -3,4 +3,6 @@ isodir
sysroot
.idea
.vscode
.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

@@ -10,9 +10,9 @@ kernel_size:
.long _end - _start
everything:
mov $0x1000, %ax
mov %ax, %es
mov %ax, %ds
mov $0x1000, %ax
mov %ax, %es
mov %ax, %ds
# reset disk
mov $0, %ah
@@ -20,9 +20,9 @@ everything:
# stop the cursor
mov $1, %ah
mov $0,%cl
mov $0x20,%ch
int $0x11
mov $0,%cl
mov $0x20,%ch
int $0x11
# get the system memory, if this call fails then halt
clc
@@ -35,9 +35,9 @@ everything:
add %ax, %bx
mov %bx, total_mem_mb-_start
# vga text mode
mov $0x0003, %ax
int $0x10
# vga text mode
mov $0x0003, %ax
int $0x10
enable_a20:
#enable the a20 gate
@@ -46,19 +46,19 @@ 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
ljmpl $8, $protected
ljmpl $8, $protected
halt16:
jmp halt16
.code32
protected:
mov $2*8, %ax
mov %ax, %es
mov $16, %ax
mov %ax, %es
mov %ax, %ds
mov %ax, %ss
mov $5*8, %ax
@@ -70,49 +70,14 @@ 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)
lidt idtr
ret
.global gdt_load
gdt_load:
lgdt (gdt_init)
ret
.global reboot
reboot:
cli
@@ -135,10 +100,10 @@ halt:
gdt:
.word 0,0,0,0
.word 0xffff, 0x0000, 0x9a00, 0x00cf
.word 0xffff, 0x0000, 0x9200, 0x00cf
.word 0xffff, 0x0000, 0xfa00, 0x00cf
.word 0xffff, 0x0000, 0xf200, 0x00cf
.word 0x0068, (tss-_start), 0x8901, 0x00cf
.word 0xffff, 0x0000, 0x9200, 0x00cf
.word 0xffff, 0x0000, 0xfa00, 0x00cf
.word 0xffff, 0x0000, 0xf200, 0x00cf
.word 0x0068, (tss-_start), 0x8901, 0x00cf
gdt_init:
.word gdt_init-gdt
.long gdt

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.