Re: ATA PIO Mode
Posted: Tue Feb 07, 2012 4:18 pm
No, it doesn't work that way.
You don't even bother to properly format your code.
You don't even bother to properly format your code.
Code: Select all
#include <./Devices/ATA/ATA.h>
#include <types.h>
#include <system.h>
#include <console.h>
#include <HAL.h>
#include <interrupt_number.h>
#define READ_SECTORS 0x20
#define WRITE_SECTORS 0x30
void ata_lba28_read_sector(uint32 drive, uint32 LBA, char* buffer)
{
outb(drive | 1, 0x00);
outb(drive | 2, 0x01);
outb(drive | 3, (uint8) LBA);
outb(drive | 4, (uint8) (LBA >> 8));
outb(drive | 5, (uint8) (LBA >> 16));
outb(drive | 6, 0xE0 | (drive << 4) | ((LBA >> 24) & 0x0F));
outb(drive | 7, READ_SECTORS);
while(!(inb(drive | 7) & 0x08));
uint16 i=0;
uint16 temp=0;
while(i < 256)
{
temp = inw(drive);
buffer[i*2] = (uint8) temp;
buffer[(i*2)+1] = (uint8) (temp >> 8);
i++;
}
}
void ata_lba28_write_sector(uint32 drive, uint32 LBA, char* buffer)
{
outb(drive | 1, 0x00);
outb(drive | 2, 0x01);
outb(drive | 3, (uint8) LBA);
outb(drive | 4, (uint8) (LBA >> 8));
outb(drive | 5, (uint8) (LBA >> 16));
outb(drive | 6, 0xE0 | (drive << 4) | ((LBA >> 24) & 0x0F));
outb(drive | 7, WRITE_SECTORS);
while(!(inb(drive | 7) & 0x08));
uint16 i=0;
uint16 temp=0;
while(i < 256)
{
temp = buffer[8 + i * 2] | (buffer[8 + i * 2 + 1] << 8);
outw(drive, temp);
}
}
uint32 ata_detect_drives()
{
outb(0x1F3, 0x4);
if(inb(0x1F3) == 0x4)
return 0; //success
else
return -1; //fail
}
uint32 ata_detect_controllers()
{
if(ata_detect_drives() == -1)
{
printf_color("WARNING: No Drives detected...\n", 0x04);
}
else
printf_color("Drive detected...\n", 0x02);
outb(0x1F6, 0xA0);
uint32 i=0;
while(i < 50000)
{
i++;
}
uint8 tmp = inb(0x1F7);
if(tmp & 0x40)
{
printf_color("Primary Controller Exists...\n", 0x02);
return 0;
}
else
{
printf_color("WARNING: Primary Doesn't Controller Exists...\n", 0x04);
return -1;
}
}
Nobody's obligated to help you.sds2017 wrote:Here it is in the format you wanted I don't mean to offend you but, instead of ranting on of how I forgot to put the code tags you could be helping me by telling me what I did wrong because yes, I have done my research in a matter of fact here's the two places I looked at:
Two resources? what about official specifications? chipset datasheets?sds2017 wrote:1.[wiki]http://wiki.osdev.org/ATA_PIO_Mode[/wiki]
2.http://www.osdever.net/tutorials/view/l ... ss-via-pio
the second link at the very end says it's been tested and it works but, I've checked over my code countless number of times which you probably understand what that feels like and it still doesn't work.
It's still not indented, it's still not commented, you still use magic numbers, and most importantly: you still did not understand what the forum rules are telling you. In other words: it's just as illegible as the first attempt.Here it is in the format you wanted