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
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

View file

@ -1,9 +1,10 @@
DISK_ID EQU 0x81
DISK_ID EQU 0x80
KERNEL_START EQU 0x100000
ELF_START EQU 0x8000
NUM_SECTORS EQU 21
org 0x7C00
bits 16
@ -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

View file

@ -115,10 +115,15 @@ 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!");