summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bootloader.asm143
1 files changed, 139 insertions, 4 deletions
diff --git a/bootloader.asm b/bootloader.asm
index 181c1dc..2993726 100644
--- a/bootloader.asm
+++ b/bootloader.asm
@@ -1,12 +1,147 @@
+[BITS 16]
+[ORG 7c00h]
- mov cx, 0x10
- mov ah, 0x0A
- mov al, 0x74
- int 0x10
+init:
+ mov cx, 0xB800
+ mov gs, cx
+start:
+ call clr_vga
+ mov si, HELLO
+ call write_str
+ call disk_read
+ mov si, VERIFY
+ call write_str
+ mov ax, 0x61
+ call cursor_next_line
+ call write_char_default_attr
+ mov ax, 0x62
+ call cursor_next_line
+ call write_char_default_attr
+ mov ax, 0x63
+ call cursor_next_line
+ call write_char_default_attr
+ call write_char_default_attr
+ call write_char_default_attr
+ call cursor_back_one
+ call cursor_backspace
+ jmp hang
+
+read_err:
+ mov si, READ_ERR
+ call write_str
hang:
jmp hang
+write_str:
+ push ax
+ push si
+ xor ax, ax
+write_str_each_char:
+ mov al, byte [si]
+ cmp al, 0
+ je write_str_done
+ inc si
+ call write_char_default_attr
+ jmp write_str_each_char
+write_str_done:
+ pop si
+ pop ax
+ ret
+
+write_char_default_attr:
+ push bx
+ mov bl, 0x07
+ jmp write_char_inner
+write_char:
+ push bx
+write_char_inner:
+ push di
+ mov di, [CURSOR_LOC]
+ mov byte [gs:di], al
+ inc di
+ mov byte [gs:di], bl
+ inc di
+ mov [CURSOR_LOC], di
+ pop di
+ pop bx
+ ret
+
+clr_vga:
+ mov di, 4000
+clr_vga_loop:
+ dec di
+ mov byte [gs:di], 0x00
+ cmp di, 0
+ jne clr_vga_loop
+ mov word [CURSOR_LOC], 0
+ ret
+
+disk_read:
+ ; ax = disk number to read from
+ ; reference: http://www.delorie.com/djgpp/doc/rbinter/id/14/7.html
+ mov dx, 0x80
+ or ax, dx
+ mov si, LBA_DISK_READ_PACKET
+ mov ah, 0x42
+ int 0x13
+ jc read_err
+ mov si, READ_SUCC
+ call write_str
+ ret
+
+READ_ERR:
+ db 'Read failed: ', 0
+READ_SUCC:
+ db 'Read didnt fail: ', 0
+HELLO:
+ db 'Bootloader init: ', 0
+CURSOR_LOC:
+ dw 0
+
+ ; reference: http://www.delorie.com/djgpp/doc/rbinter/it/72/2.html
+LBA_DISK_READ_PACKET:
+ db 0x10
+ db 0
+ dw 1 ; number of blocks to read, reset to # actually read when done
+ dw 0x7e00 ; read destination address
+ dw 0
+ dd 1 ; lba to read from
+ dd 0 ; for extended lba adresses (not really used here)
+
times 510-($-$$) db 0
db 0x55
db 0xAA
+
+cursor_next_line:
+ mov di, [CURSOR_LOC]
+ add di, 160
+ mov [CURSOR_LOC], di
+ ret
+
+cursor_prev_line:
+ mov di, [CURSOR_LOC]
+ sub di, 160
+ mov [CURSOR_LOC], di
+ ret
+
+cursor_backspace:
+ push ax
+ call cursor_back_one
+ mov ax, 0x00
+ call write_char_default_attr
+ call cursor_back_one
+ pop ax
+ ret
+
+cursor_back_one:
+ mov di, [CURSOR_LOC]
+ dec di
+ dec di
+ mov [CURSOR_LOC], di
+ ret
+
+VERIFY:
+ db '[x] read next block: ', 0
+
+ times 1024-($-$$) db 0