I've two problems: .read fails, and it fails a lot more than 3 times. In VMware I see the "Failed read attempt" message 23 times (perhaps even more, but my buffer is only 24 lines) and one "Fatal error!" message.
What are my mistakes?
boot.asm
Code: Select all
; +-------+
; | 512 B | bootloader
; +-------+
; | 4 KiB | stack
; +-------+
org 0x7c00 ; loaded at 0x0000:0x7c00 by the BIOS
xor ax, ax
mov ds, ax ; set ds pointer to zero because org is set to 0x7c00
mov ax, 32 ; set the stack pointer, 32 paragraphs (512 B)
mov ss, ax
mov sp, 4096 ; set the stack top pointer, 4 KiB
jmp main
boot_message db "OS bootloader\r\n===================\0"
loading_kernel db "Loading kernel...\0"
kernel_loaded db "Kernel loaded!\0"
hello_from_kernel db "Hello from kernel\0"
failed_reset_attempt db "Failed reset attempt\0"
failed_read_attempt db "Failed read attempt\0"
fatal_error db "Fatal error!\0"
number_of_failed_reset_attempts db 0
number_of_failed_read_attempts db 0
maximum_number_of_attempts db 3
main:
mov si, boot_message
call io.write_line
mov si, loading_kernel
call io.write_line
jmp loader
loader:
.reset:
mov ah, 0x00
mov dl, 0x00
int 0x13
jnc .read ; success, carry bit is not set
inc byte [number_of_failed_reset_attempts]
mov si, failed_reset_attempt
call io.write_line
cmp byte [number_of_failed_reset_attempts], maximum_number_of_attempts
je .fatal_error
jmp .reset
.read:
mov ah, 0x02
mov al, 0x01 ; one sector
mov ch, 0x00 ; first track
mov cl, 0x02 ; second sector (1-based)
mov dh, 0x00 ; first head
mov dl, 0x00 ; first floppy drive
mov ax, 0x2000 ; load at 0x2000:0x0000
mov es, ax
mov bx, 0x0000
int 0x13
jnc .kernel_loaded ; success, carry bit is not set
inc byte [number_of_failed_read_attempts]
mov si, failed_read_attempt
call io.write_line
cmp byte [number_of_failed_read_attempts], maximum_number_of_attempts
je .fatal_error
jmp .read
.fatal_error:
mov si, fatal_error
call io.write_line
ret
.kernel_loaded:
mov si, kernel_loaded
call io.write_line
jmp 0x2000:0x0000
%include "io.asm"
times 512-($-$$) db 0 ; zerofill the boot sector
%include "kernel.asm"
times 1474560 - ($ - $$) db 0 ; zerofill the rest of the floppy
Code: Select all
io.write:
mov ah, 0x0e
.loop:
lodsb
cmp al, "\"
je .escape_sequence
int 0x10
jmp .loop
.escape_sequence:
lodsb
cmp al, "0"
je .escape_sequence_0
cmp al, "n"
je .escape_sequence_n
cmp al, "r"
je .escape_sequence_r
jmp .loop ; Unrecognised escape sequence, skip the character.
.escape_sequence_0:
ret
.escape_sequence_n:
mov al, 0x0a
int 0x10
jmp .loop
.escape_sequence_r:
mov al, 0x0d
int 0x10
jmp .loop
new_line db "\r\n\0"
io.write_line:
call io.write
mov si, new_line
call io.write
ret
Code: Select all
kernel:
mov si, hello_from_kernel
call io.write_line
ret