ATA PIO Mode

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.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: ATA PIO Mode

Post by Brynet-Inc »

No, it doesn't work that way.

You don't even bother to properly format your code.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: ATA PIO Mode

Post by AJ »

Hi,

Just to put that another way:

1. Read the forum rules. Check you have done your research.
2. Use code tags.

Cheers,
Adam
sds2017
Member
Member
Posts: 61
Joined: Tue Jul 05, 2011 10:05 am

Re: ATA PIO Mode

Post by sds2017 »

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;
}
}
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:

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.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: ATA PIO Mode

Post by Brynet-Inc »

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:
Nobody's obligated to help you.
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.
Two resources? what about official specifications? chipset datasheets?
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: ATA PIO Mode

Post by Combuster »

Here it is in the format you wanted
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.

Also, desk-checking is not the only thing you should do. Observe what the hardware really does. Dump registers at strategic moments. Most importantly, demonstrate how we can observe the same results as you do.

Act like a developer if you want a meaningful response. People who repeatedly break a rule (you broke at least two in this thread) have a habit of breaking the others too. Did you actually break the "stupidity" rule here as well or are we just thinking that?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
sds2017
Member
Member
Posts: 61
Joined: Tue Jul 05, 2011 10:05 am

Re: ATA PIO Mode

Post by sds2017 »

Combuster: I doubt you'll get this message but as I looked at your files(not source) for your os and I found one named ata something. Although this subject on this forum is done and I'm not going to get an answer I found an ata file on your os I didn't look at it but, I'm guessing it has lba 28 code in it. So, I don't know why you would need any comments. Anyway I appreciate you helping the people on this forum because I know you could be doing something else with your time.

Also when I said resources I meant tutorials; I looked at t13 which is a website made by the people who designed the ata specifications. If nobody wants to help then don't because it's not worth anybodies time. If you don't want to then don't respond because it's not worth your time or mine. Anyways, I do have to say you have helped lots of people and when I say all these things about how you don't have to respond in my post I realize that you're the people that help me but, again if you don't think that you need to help, don't want to help, or you think that they need to develop in user mode first then don't respond because most people on this forum are adamant about developing an operating system even though some don't need to be (ex. What's a pointer? ("LOL")). Closing my statement, I thought the point of a forum was to help people not to criticize or question in a way that makes you certain that the person is insulting you.

Lastly, I going to go ahead and just forget that I posted this, move on and just keep on debugging because, obviously this subject was not worth anybodies time and wasn't necessary.


Anyways thank for you help.
Locked