Set maximum sector count

This commit is contained in:
Robbe Van Herck 2019-12-30 16:02:43 +01:00
parent af4b198341
commit bf8c360063
No known key found for this signature in database
GPG key ID: A66F76F7B81BD784
3 changed files with 27 additions and 15 deletions

View file

@ -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 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 compile_bootloader: compile_kernel
rm -rf target/boot.bin rm -rf target/bootloader.bin
nasm -f bin -o target/boot.bin bootloader/main.asm nasm -f bin -o target/bootloader.bin bootloader/main.asm
cat target/bootloader.bin target/kernel.bin > target/boot.bin
run_bootloader: compile_bootloader 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

View file

@ -1,14 +1,15 @@
DISK_ID EQU 0x81 DISK_ID EQU 0x80
KERNEL_START EQU 0x100000 KERNEL_START EQU 0x100000
ELF_START EQU 0x8000 ELF_START EQU 0x8000
NUM_SECTORS EQU 21
org 0x7C00 org 0x7C00
bits 16 bits 16
jmp .start jmp .start
[bits 16] [bits 16]
; Function: check_a20 ; Function: check_a20
@ -160,7 +161,7 @@ mov bl, ah
call puthex call puthex
.reset_disk_no_error: .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 mov bx, ELF_START ; write to ELF_START
push bx push bx
push cx push cx
@ -175,12 +176,11 @@ mov dh, 0x00 ; head number
mov dl, DISK_ID ; drive number mov dl, DISK_ID ; drive number
int 0x13 int 0x13
; exit on error
jc .read_disk_error jc .read_disk_error
; print result on error
jnc .read_disk_no_error cmp cx, NUM_SECTORS
mov bl, ah jge .read_disk_end ; we have reached the sector limit, time to boot
call puthex
.read_disk_no_error:
pop cx pop cx
pop bx pop bx
@ -190,8 +190,14 @@ push bx
push cx push cx
jmp .read_disk_loop jmp .read_disk_loop
.read_disk_error: .read_disk_error:
mov bl, ah
call puthex
.read_disk_end:
call check_a20 call check_a20
cmp ax, 1 cmp ax, 1
je .a20_enabled je .a20_enabled
@ -306,7 +312,7 @@ jmp .end
.data: .data:
.str_no_A20: .str_no_A20:
db "A20 not enabled" db "A20 fault"
db 0 db 0

View file

@ -114,11 +114,16 @@ void kernel_main(void)
{ {
/* Initialize terminal interface */ /* Initialize terminal interface */
terminal_initialize(); terminal_initialize();
terminal_putchar('H');
terminal_putchar('e');
terminal_putchar('l');
terminal_putchar('l');
terminal_putchar('o');
/* Newline support is left as an exercise. */ /* Newline support is left as an exercise. */
terminal_writestring("Hello, ");
terminal_setcolor(vga_entry_color(VGA_COLOR_GREEN, VGA_COLOR_BLACK)); 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_setcolor(vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK));
terminal_writestring(" World!\n"); terminal_writestring(" World!\n");
terminal_writestring("Newlines!"); terminal_writestring("Newlines!");