Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- org 0x7C00
- bits 16
- mov ax, 0
- mov es, ax
- mov ds, ax
- mov ss, ax
- mov sp, 0x7c00 ; Stack will grow down below the bootloader.
- mov [bdv], dl
- jmp main
- ; lbaRead
- ; Reads sectors using LBA
- ; bx: LBA Address
- ; ax: Number of sectors
- ; dl: Drive number
- lbaRead:
- ; Save AX and BX
- mov [snm], ax
- push bx
- ; Read the Disk Geometry
- mov ah, 8
- mov di, 0
- int 0x13
- ; Error Handling
- jc err
- ; continue
- ; Int 0x13/ah=8 can set ES to non zero segment
- ; set ES back to 0
- mov ax, 0
- mov es, ax
- inc dh
- mov [hct], dh
- and cl, 0x3F
- mov [spt], cl
- ; Restore BX clobbered by previous int 13h
- pop bx
- ; Convert LBA to CHS
- ; Calculate temporary value (tmp) and sector
- mov dx, 0
- mov ax, bx
- mov bx, [spt]
- div bx
- inc dl
- mov [sct], dl
- ; Calculate Head and Cylinder
- mov dx, 0
- mov bx, [hct]
- div bx
- mov [hed], dl
- mov [cyl], ax
- ; Read the disk
- mov ah, 0x02
- mov al, [snm]
- mov ch, [cyl]
- mov cl, [sct]
- mov dh, [hed]
- mov dl, [bdv]
- mov bx, 0x7E00
- int 0x13
- ; Error handling
- jc err
- ret
- main:
- pusha
- mov bx, 1
- mov ax, 1
- call lbaRead
- popa
- mov ah, 0x0E
- mov al, [0x7E00]
- int 0x10
- jmp $
- err:
- mov ah, 0x0B
- mov bl, 0x4
- int 0x10
- jmp $
- ; Variables for CHS conversion
- tmp: dw 0
- sct: db 0
- hed: db 0
- cyl: dw 0
- spt: dw 0
- hct: dw 0
- bdv: db 0
- snm: dw 0
- ; Pad to 512 bytes and add 0x55AA cap
- times 510-($-$$) db 0
- db 0x55, 0xaa
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement