Skip to content

Commit ef0e8fe

Browse files
committed
Commented disk_mng.asm
1 parent ed650fc commit ef0e8fe

2 files changed

Lines changed: 24 additions & 24 deletions

File tree

boot.asm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ section .text:
3636
pop ax ; Recover AX value from stack
3737
pop bx ; Recover BX value from stack
3838
39-
mov [disk_index], dl
40-
mov bx, kernel_address
41-
mov dh, 2
42-
call _read_disk
39+
mov [disk_index], dl ; Save boot disk to variable
40+
mov bx, kernel_address ; Write to BX kernel origin
41+
mov dh, 2 ; Read two sectors
42+
call _read_disk ; Read 16 bits from disk
4343

4444
jmp $ ; Stops the processor
4545

@@ -52,10 +52,10 @@ section .text:
5252
5353
buffer: times 4 db 0 ; Defines input buffer
5454

55-
kernel_address: equ 0x1000
56-
disk_index: db 0
55+
kernel_address: equ 0x1000 ; Kernel origin
56+
disk_index: db 0 ; Variable to store boot drive index
5757

58-
Global Descriptor Table
58+
; Global Descriptor Table
5959
GDT_start:
6060
GDT_null:
6161
dd 0x0

functions/disk_mng.asm

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ global _read_disk
22

33
section .text:
44
_read_disk:
5-
pusha
6-
push dx
7-
8-
mov ah, 0x02
9-
mov al, dh
10-
mov cl, 0x02
11-
mov ch, 0x00
12-
mov dh, 0x00
13-
14-
int 0x13
15-
jc disk_error
16-
17-
pop dx
18-
cmp al, dh
19-
jne sectors_error
20-
popa
21-
ret
5+
pusha ; Push registers
6+
push dx ; Save dx to the stack
7+
8+
mov ah, 0x02 ; Enable disk reading
9+
mov al, dh ; Amount sectors to read
10+
mov cl, 0x02 ; Read from second sector
11+
mov ch, 0x00 ; Cylinder to read from
12+
mov dh, 0x00 ; Head that read
13+
14+
int 0x13 ; BIOS interupt to read data
15+
jc disk_error ; If carry is set raise an error
16+
17+
pop dx ; Recover DX from stack
18+
cmp al, dh ; Check amount of readen sectors
19+
jne sectors_error ; If they are not equal raise an error
20+
popa ; Recover registers
21+
ret ; Exit the function
2222

2323

2424
disk_error:

0 commit comments

Comments
 (0)