Page 1 of 1

How to read the first sector of master drive via ATA PIO?

Posted: Wed Jun 11, 2014 2:21 pm
by Roman
I want to read the first sector of master drive via ATA PIO.

What is wrong with this code? This is my stage2 boot loader, I have full 64-bit environment before running this code.

Code: Select all

        section .text
        use64
        org 0x0000000000100000  ; Load address.

start:
        mov al, 'A'
        mov [0xB8000], al

        mov edi, 0x200000
        mov al, 0x40
        out 0x1F6, al
        mov al, 0x00
        out 0x1F2, al
        out 0x1F3, al
        out 0x1F4, al
        out 0x1F5, al
        mov al, 0x01
        out 0x1F2, al
        mov al, 0x00
        out 0x1F3, al
        out 0x1F4, al
        out 0x1F5, al
        mov al, 0x24
        out 0x1f7, al

        rep insw

        cli
        hlt

Re: How to read the first sector of master drive via ATA PIO

Posted: Wed Jun 11, 2014 3:21 pm
by Gigasoft
Out Iw, al is not a valid instruction. The assembler should have given you an error. Use out dx, al to write to port numbers greater than 0xff. After writing the command you need to wait for an IRQ. Then wait for the controller to become ready and check that DRQ is set. Then you read 256 words from port 0x1f0.