Reading hdd with ATA PIO Mode
Posted: Wed May 25, 2011 9:05 am
Hi,
Im trying to make a driver in ATA PIO Mode in 32bits mode
When I send the DATA Port 0x1F0, for read 512bytes, ide_buff have the same values before and after (trash).
Whats the error? Im trying to recover the information of harddisk of that sector (or put the address of buffer obtained from disk).
Im trying to make a driver in ATA PIO Mode in 32bits mode
Code: Select all
static inline void insw(unsigned short port, void *addr, unsigned char cnt)
{
__asm volatile("rep; insw"
: "+D" (addr), "+c" (cnt)
: "d" (port)
: "memory");
}
static inline void outsw(unsigned short port, const void *addr, unsigned char cnt){
__asm volatile("rep; outsw" : "+S" (addr), "+c" (cnt) : "d" (port));
}
int read_sector(int LBA) {
int count = 1; //number of sectors to read
char slavebit =0; //0 for master device 1 for slave sets bit 5 in 1f6
int stat;
outb(0x3f6, 0x02); //disable interrupts
outb(0x1F6, (0xE0 | (slavebit << 4) | (LBA >> 24 & 0x0F)));
//waste some time
outb(0x1f1, 0x00);
//set the sector count
outb(0x1f2, (unsigned char)count);
sleep(1);
stat = ide_polling(0, 0);
if(stat != 0)
return stat;
//send the low 8 bits of lbs to 1f3
outb(0x1f3, (unsigned char)LBA);
sleep(1);
stat = ide_polling(0, 0);
if(stat != 0)
return stat;
//send the middle 8 bits to 1f4
outb(0x1f4, (unsigned char)(LBA >> 8));
sleep(1);
stat = ide_polling(0, 0);
if(stat != 0)
return stat;
//send the high 8 to 1f5
outb(0x1f5, (unsigned char)(LBA >> 16));
sleep(1);
stat = ide_polling(0, 0);
if(stat != 0)
return stat;
//issue a read sectors command
outb(0x20, 0x1f7);
sleep(1);
stat = ide_polling(0, 0);
if(stat != 0)
return stat;
//eat 256 words form the buffer
unsigned char ide_buff[256];
printf("DATA BEFORE: %s\n", ide_buff);
insw(0x1f0, ide_buff, 512);
ide_polling(0,0);
printf("DATA AFTER: %s", ide_buff);
}
Whats the error? Im trying to recover the information of harddisk of that sector (or put the address of buffer obtained from disk).