summaryrefslogtreecommitdiff
path: root/src/boot/stage1_functions.asm
diff options
context:
space:
mode:
Diffstat (limited to 'src/boot/stage1_functions.asm')
-rw-r--r--src/boot/stage1_functions.asm121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/boot/stage1_functions.asm b/src/boot/stage1_functions.asm
new file mode 100644
index 0000000..bdb2aac
--- /dev/null
+++ b/src/boot/stage1_functions.asm
@@ -0,0 +1,121 @@
+; IN dx: hex value to print
+print_hex:
+ push bx
+ push si
+ mov si, HEX_TEMPLATE
+ mov bx, dx
+ shr bx, 12
+ mov bx, [HEXABET+bx]
+ mov [HEX_TEMPLATE+2], bl
+ mov bx, dx
+ and bx, 0x0FFF
+ shr bx, 8
+ mov bx, [HEXABET+bx]
+ mov [HEX_TEMPLATE+3], bl
+ mov bx, dx
+ and bx, 0x00FF
+ shr bx, 4
+ mov bx, [HEXABET+bx]
+ mov [HEX_TEMPLATE+4], bl
+ mov bx, dx
+ and bx, 0x000F
+ mov bx, [HEXABET+bx]
+ mov [HEX_TEMPLATE+5], bl
+ call print_string
+ pop si
+ pop bx
+ ret
+
+HEX_TEMPLATE:
+ db '0x???? ', 0
+
+HEXABET:
+ db '0123456789ABCDEF'
+
+print_newline:
+ push ax
+ mov al, 10
+ call print_char
+ mov al, 13
+ call print_char
+ pop ax
+ ret
+
+; IN si
+print_string:
+ push ax
+.loop:
+ lodsb
+ cmp al, 0
+ je .fini
+ call print_char
+ jmp .loop
+.fini:
+ pop ax
+ ret
+
+; IN al: character to print
+; MOD ah
+print_char:
+ mov ah, 0x0e
+ int 0x10
+ ret
+
+fat_cursor:
+ push ax
+ push cx
+ mov ah, 0x01
+ mov cx, 0x0007
+ int 0x10
+ pop cx
+ pop ax
+ ret
+
+; OUT: current row
+current_row:
+ push ax
+ push bx
+ push cx
+ mov ah, 0x03
+ mov bh, 0
+ int 0x10
+ pop cx
+ pop bx
+ pop ax
+ ret
+
+; IN dl: drive to read from
+read_stage2_from_disk:
+ mov ah, 0x02 ; read sectors from drive
+
+ mov al, 3 ; read 3 sectors of stage 2
+ mov ch, 0 ; select first cylinder
+ mov dh, 0 ; first head
+ mov cl, 2 ; second sector after boot sector
+
+ mov bx, 0 ; where to store the data
+ mov es, bx
+ mov bx, 0x7e00 ; 512 bytes after first sector
+
+ int 0x13
+
+ jc .read_error
+
+ cmp al, 3 ; 3 sectors read?
+ jne .short_read ; if not, short read
+
+ ret
+
+.read_error:
+ mov si, DISK_ERROR
+ call print_string
+ mov dh, 0
+ mov dl, ah
+ call print_hex
+ jmp $
+
+.short_read:
+ mov si, SHORT_READ
+ call print_string
+ jmp $
+