diff --git a/Makefile b/Makefile index 388b52f..5a5e21b 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,9 @@ compile_kernel: i686-elf-gcc -T kernel/linker.ld -o target/kernel.bin -ffreestanding -O2 -nostdlib target/boot.o target/kernel.o -lgcc compile_bootloader: compile_kernel - rm -rf target/boot.bin - nasm -f bin -o target/boot.bin bootloader/main.asm + rm -rf target/bootloader.bin + nasm -f bin -o target/bootloader.bin bootloader/main.asm + cat target/bootloader.bin target/kernel.bin > target/boot.bin run_bootloader: compile_bootloader - qemu-system-i386 -drive format=raw,file=target/boot.bin -drive format=raw,file=target/kernel.bin -monitor stdio + qemu-system-i386 -drive format=raw,file=target/boot.bin -monitor stdio diff --git a/bootloader/main.asm b/bootloader/main.asm index 67da8d8..6c9fb4e 100644 --- a/bootloader/main.asm +++ b/bootloader/main.asm @@ -1,14 +1,15 @@ -DISK_ID EQU 0x81 +DISK_ID EQU 0x80 KERNEL_START EQU 0x100000 - ELF_START EQU 0x8000 +NUM_SECTORS EQU 21 + org 0x7C00 bits 16 jmp .start - + [bits 16] ; Function: check_a20 @@ -160,7 +161,7 @@ mov bl, ah call puthex .reset_disk_no_error: -mov cx, 1 ; start at sector 1 +mov cx, 2 ; start at sector 2 (skip bootloader) mov bx, ELF_START ; write to ELF_START push bx push cx @@ -175,12 +176,11 @@ mov dh, 0x00 ; head number mov dl, DISK_ID ; drive number int 0x13 +; exit on error jc .read_disk_error -; print result on error -jnc .read_disk_no_error -mov bl, ah -call puthex -.read_disk_no_error: + +cmp cx, NUM_SECTORS +jge .read_disk_end ; we have reached the sector limit, time to boot pop cx pop bx @@ -190,8 +190,14 @@ push bx push cx jmp .read_disk_loop + .read_disk_error: +mov bl, ah +call puthex + +.read_disk_end: + call check_a20 cmp ax, 1 je .a20_enabled @@ -306,7 +312,7 @@ jmp .end .data: .str_no_A20: -db "A20 not enabled" +db "A20 fault" db 0 diff --git a/kernel/kernel.c b/kernel/kernel.c index 3bed179..51d7ccd 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -114,11 +114,16 @@ void kernel_main(void) { /* Initialize terminal interface */ terminal_initialize(); + + terminal_putchar('H'); + terminal_putchar('e'); + terminal_putchar('l'); + terminal_putchar('l'); + terminal_putchar('o'); /* Newline support is left as an exercise. */ - terminal_writestring("Hello, "); terminal_setcolor(vga_entry_color(VGA_COLOR_GREEN, VGA_COLOR_BLACK)); - terminal_writestring("kernel"); + terminal_writestring(" kernel"); terminal_setcolor(vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK)); terminal_writestring(" World!\n"); terminal_writestring("Newlines!");