Help with BIOS Disk Read Interrupt

Discussion in 'Computer Software and Operating Systems' started by Mr. Mysterio, May 12, 2015.

  1. Mr. Mysterio

    Mr. Mysterio Super Genius

    Sep 16, 2014
    United States
    Rosalina's Comet Observatory
    I've been trying to write a MBR that bootstraps code from the disk. I've been trying to use the BIOS interrupt 0x13 with ah=2, but it always fills the memory with zeros. The return is ah = 0 = success, and al = the correct number of read sectors. I'm using NASM. Here is my code:

    [org 0x7c00]
    [BITS 16]
    ; Init stack.
    mov bp, 0x7B00
    mov sp, bp
    mov ah , 0x02 ; BIOS read sector function.
    mov al , 0x01 ; Read 1 sector.
    mov ch , 0x00 ; Cylinder 0.
    mov dh , 0x00 ; Head 0.
    mov cl , 0x02 ; Start from sector 2.
    mov bx, 0
    mov es, bx
    mov bx, 0x8000 ; Read data to 0x0000:0x8000. dl already contains the boot drive index.
    int 0x13
    jc disk_error ; Jump if error.
    mov bx, 0x8000 ; Start from 0x8000.
    mov ax, 0x200 ; Read 512 bytes.
    clc ; Do not prepend "0x".
    call printx ; Print bytes as hex.
    jmp $
    I've tried starting from sectors 0 through 5 and reading different amounts with no luck. I haven't been using an emulator, I've been directly testing it on a PC. I had this function working once in the past so I know it can work with my SD card, but my HDD died and killed that data. I haven't been able to get it working again. Please help!