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

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

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

Post 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
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

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

Post 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.
Post Reply