Page 1 of 1
ATA PIO driver
Posted: Thu Nov 14, 2013 9:50 pm
by teodori
Hello, right now I try to read from and write to ata drive, but I got some problems. I downloaded a PDF about ATA and ATAPI, but I still can't manage a simple PIO read or write. Lets say I do this, what shoul I do next to get the bytes from ATA device:
Code: Select all
#define ATA0_MSTR 0x01f0
#define ATA0_SLVE 0x03f0
#define ATA1_MSTR 0x0170
#define ATA1_SLVE 0x0370
outb(0x40, ATA0_MSTR + 0x0006); // Select Master
outb(0x00, ATA0_MSTR + 0x0002); // sectorcount high byte
outb(0x00, ATA0_MSTR + 0x0003); // LBA4
outb(0x00, ATA0_MSTR + 0x0004); // LBA5
outb(0x00, ATA0_MSTR + 0x0005); // LBA6
outb(0x01, ATA0_MSTR + 0x0002); // sectorcount low byte
outb(0x00, ATA0_MSTR + 0x0003); // LBA1
outb(0x00, ATA0_MSTR + 0x0004); // LBA2
outb(0x00, ATA0_MSTR + 0x0005); // LBA3
outb(0x24, ATA0_MSTR + 0x0007); // read pio cmd
Read ATA0_MSTR?
Who can explain ATA in details?
Re: ATA PIO driver
Posted: Fri Nov 15, 2013 1:22 am
by Combuster
Re: ATA PIO driver
Posted: Fri Nov 15, 2013 10:04 am
by teodori
Hello yeah I readed this one but it's not very comprehensive. Through the code example I somehow deducted how it works. .. still I get bochs errors and it doesn't work.
Re: ATA PIO driver
Posted: Fri Nov 15, 2013 12:15 pm
by justin
teodori wrote:Hello yeah I readed this one but it's not very comprehensive. Through the code example I somehow deducted how it works. .. still I get bochs errors and it doesn't work.
What kind of errors do you get from bochs? Post your log. You need to give a lot more details for people to be able to help.
Re: ATA PIO driver
Posted: Fri Nov 15, 2013 3:52 pm
by teodori
Ok here is my test example
Code: Select all
void ata_lba_read(){
outb(0x40, ATA0_MSTR + 0x0006); // Select Master
outb(0x00, ATA0_MSTR + 0x0002); // sectorcount high byte
outb(0x00, ATA0_MSTR + 0x0003); // LBA4
outb(0x00, ATA0_MSTR + 0x0004); // LBA5
outb(0x00, ATA0_MSTR + 0x0005); // LBA6
outb(0x01, ATA0_MSTR + 0x0002); // sectorcount low byte
outb(0x00, ATA0_MSTR + 0x0003); // LBA1
outb(0x00, ATA0_MSTR + 0x0004); // LBA2
outb(0x00, ATA0_MSTR + 0x0005); // LBA3
outb(0x24, ATA0_MSTR + 0x0007); // read pio cmd
int i;
uint8_t data;
for(i = 0; i < 512; i++){
data = inb(ATA0_MSTR); // read byte
vga_write(COLOR_BLACK, COLOR_CYAN, data, 800 + i);
}
}
and I get:
Code: Select all
00005225966e[DEV ] read from port 0x01f0 with len 1 returns 0xff
00054400644i[CPU0 ] WARNING: HLT instruction with IF=0!
00214022005i[ ] cpu loop quit, shutting down simulator
00214022005i[CPU0 ] CPU is in long mode (halted)
00214022005i[CPU0 ] CS.mode = 64 bit
00214022005i[CPU0 ] SS.mode = 64 bit
00214022005i[CPU0 ] EFER = 0x00000501
00214022005i[CPU0 ] | RAX=0000000000000469 RBX=0000000000200003
00214022005i[CPU0 ] | RCX=0000000000000068 RDX=00000000000b80d0
00214022005i[CPU0 ] | RSP=0000000000007e00 RBP=00000000000000ac
00214022005i[CPU0 ] | RSI=0000000000000004 RDI=0000000000000000
00214022005i[CPU0 ] | R8=0000000000000000 R9=0000000000000000
00214022005i[CPU0 ] | R10=0000000000000000 R11=0000000000000000
00214022005i[CPU0 ] | R12=0000000000000000 R13=0000000000000000
00214022005i[CPU0 ] | R14=0000000000000000 R15=0000000000000000
00214022005i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf zf af pf cf
00214022005i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00214022005i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 ffffffff 1 0
00214022005i[CPU0 ] | DS:0020( 0004| 0| 0) 00000000 ffffffff 1 0
00214022005i[CPU0 ] | SS:0020( 0004| 0| 0) 00000000 ffffffff 1 0
00214022005i[CPU0 ] | ES:0020( 0004| 0| 0) 00000000 ffffffff 1 0
00214022005i[CPU0 ] | FS:0020( 0004| 0| 0) 00000000 ffffffff 1 0
00214022005i[CPU0 ] | GS:0020( 0004| 0| 0) 00000000 ffffffff 1 0
00214022005i[CPU0 ] | MSR_FS_BASE:0000000000000000
00214022005i[CPU0 ] | MSR_GS_BASE:0000000000000000
00214022005i[CPU0 ] | RIP=0000000000007f10 (0000000000007f10)
00214022005i[CPU0 ] | CR0=0xe0000011 CR2=0x0000000000000000
00214022005i[CPU0 ] | CR3=0x00000008 CR4=0x000000a0
00214022005i[CPU0 ] 0x0000000000007f10>> jmp .-3 (0x0000000000007f0f) : EBFD
00214022005i[CMOS ] Last time is 1384552459 (Fri Nov 15 22:54:19 2013)
00214022005i[XGUI ] Exit
00214022005i[ ] restoring default signal behavior
00214022005i[CTRL ] quit_sim called with exit code 1
Re: ATA PIO driver
Posted: Fri Nov 15, 2013 4:15 pm
by Combuster
the wiki wrote:8. Wait for an IRQ or poll.
9. Transfer 256 words, a word at a time
Read properly: You're failing at doing 9 as documented, and you're skipping 8 altogether.
Re: ATA PIO driver
Posted: Fri Nov 15, 2013 6:48 pm
by teodori
Ok so I send the command to the controller, then wait for hardware interrupt. Next I check the status to see if I can read from data port. Does that also mean I will have 256 interrupts where I read the data port 2 times? PIO is very bad...
Re: ATA PIO driver
Posted: Sat Nov 16, 2013 4:00 pm
by Gigasoft
Of course not. After receiving an interrupt and checking the status register, you perform 256 word reads from the data port.
Re: ATA PIO driver
Posted: Sun Nov 17, 2013 12:17 pm
by teodori
Ok thank you