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 sysroot
.idea .idea
.vscode .vscode
build

View File

View File

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

View File

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

View File

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

BIN
os.img Normal file

Binary file not shown.