Page 1 of 1

ATAPI

Posted: Mon Aug 17, 2009 7:47 pm
by sebopop
Hi everyone!

First, thank to all of you for this site, it's really great!
Here is my problem :
for sometime now, i have been trying to write a simple ATAPI driver but i can't get IDENTIFY DEVICE to work!!!!
i have been searching on the wiki, forums and source and tried a few things, but it still doesn t work, so in last resort i just ask : WTF is wrong with my code???

here is the code :

Code: Select all

BYTE ATAPI_CMD_IDENTIFY[12]		= {0xA1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

DWORD ata_wait_bsy(DWORD drivenb)
{
	DWORD status;
	while(1)
	{
		status = inb(drivenb+ATA_REG_CMD);
		if(status&ATA_STATUS_ERR)
			return 1;
		if(!(status&ATA_STATUS_BSY))
			return 0;
	}
}

DWORD atapi_send_cmd(PDISK disk, BYTE* cmd)
{
	ata_wait_bsy(disk->baseport);

	outb (disk->baseport+ATA_REG_FLAGS, disk->slave<<4);

	ata_wait_bsy(disk->baseport);


	outb(disk->baseport+ATA_REG_CMD, 0xA0);
	inb(disk->baseport+ATA_REG_CMD);
	inb(disk->baseport+ATA_REG_CMD);
	inb(disk->baseport+ATA_REG_CMD);
	inb(disk->baseport+ATA_REG_CMD);
	inb(disk->baseport+ATA_REG_CMD);//*/

	
	ata_wait_drq(disk->baseport);

	for(int i=0;i<6;i++)
	{
		outw(disk->baseport, (WORD)cmd[i*2]);
		//inb(0x3f6);
	}

	return 0;
}


identify func :
{
...
tested being atapi
...
atapi_send_cmd(disk, ATAPI_CMD_IDENTIFY);
ata_wait_drq(disk->baseport);
for(int i=0;i<0x100;i++)
			disk->params.ataid.words[i] = inw(disk->baseport);
...
}
thanks for any help.

Re: ATAPI

Posted: Mon Aug 17, 2009 8:55 pm
by bewing
The Identify Packet Device command (which is what I think you are trying to send) is not an ATAPI command. It is a normal PIO command. You should not be sending the the "enter atapi mode" (0xA0) command first, followed by the 0xA1 command as an ATAPI command string -- you just send 0xA1 as a simple PIO command, then grab the data like normal.

> outw(disk->baseport, (WORD)cmd[i*2]);

Also, this line assumes a specific endianness for the computer that it is running on -- so I don't think this is a wise way to handle ATAPI command strings.

Re: ATAPI

Posted: Mon Aug 17, 2009 9:45 pm
by sebopop
works. now that makes me an idiot right? :oops:

thanks a lot man, very kind of you