Do I have to enable 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.
Bietje
Member
Member
Posts: 100
Joined: Wed Apr 20, 2011 6:57 am

Do I have to enable ATA PIO Mode?

Post by Bietje »

Hello there,

I'm writing a disk driver and I use ATA PIO mode. Do I have to enable this mode or something? Because the driver says that on some (newer) machines there is no disk attached to the bus (the status byte reads 0xff). If you want to see sources, just tell me.

Thanks in advance!
Luns
Member
Member
Posts: 56
Joined: Sun May 01, 2011 12:15 am

Re: Do I have to enable ATA PIO Mode?

Post by Luns »

Writing 0 to the features port sets the disk in PIO mode. I don't know if this is required, but you could try.

Are you sure the disk is IDE (or at least pretending to be), and not anything else?
Bietje
Member
Member
Posts: 100
Joined: Wed Apr 20, 2011 6:57 am

Re: Do I have to enable ATA PIO Mode?

Post by Bietje »

Ahh that will be it.. I'm using an USB drive. Some PC emulate it as IDE drive apparently and some other not. So I should let the drive emulate as IDE if that is possible..? i.e. can I use PIO mode when the drive is not directly an IDE drive (e.g. newer hard drives and stuff like that)? Or do I have to write way more complicated drivers for them?
Luns
Member
Member
Posts: 56
Joined: Sun May 01, 2011 12:15 am

Re: Do I have to enable ATA PIO Mode?

Post by Luns »

If there's a way to make the drive pretend to be an IDE, then you should be able to treat it as a normal IDE drive. If you don't want to write more drivers, then you can try finding an option in the BIOS to get the drive to do that.
guyfawkes
Member
Member
Posts: 93
Joined: Mon Jul 18, 2011 9:47 am

Re: Do I have to enable ATA PIO Mode?

Post by guyfawkes »

Bietje wrote:Ahh that will be it.. I'm using an USB drive. Some PC emulate it as IDE drive apparently and some other not. So I should let the drive emulate as IDE if that is possible..? i.e. can I use PIO mode when the drive is not directly an IDE drive (e.g. newer hard drives and stuff like that)? Or do I have to write way more complicated drivers for them?
What your trying to do is not possible, without code a USB stack.
The only way to do it without writing USB stack, is to use int 13h in realmode, as the BIOS hook this function to enable USB booting.
Once you enter PM/Long mode emulation stops.
Bietje
Member
Member
Posts: 100
Joined: Wed Apr 20, 2011 6:57 am

Re: Do I have to enable ATA PIO Mode?

Post by Bietje »

I have also a fairly new (~1 year old) netbook. When I boot up and chose to see the boot menu, it tells me there is an IDE drive inside. This is probably emulated, as the ATA PIO status register reads 0xff. Does this mean that I have to write a ton of drivers to be able to just boot from the pc's there are currently on the market? Isn't there one method of disk io which is compatible to almost all drives? Except for usb's and weird things like that..
Luns
Member
Member
Posts: 56
Joined: Sun May 01, 2011 12:15 am

Re: Do I have to enable ATA PIO Mode?

Post by Luns »

Are you sure you sure you're trying to read from the right bus and drive? What do you mean the status register reads 0xFF, after doing what?
Bietje
Member
Member
Posts: 100
Joined: Wed Apr 20, 2011 6:57 am

Re: Do I have to enable ATA PIO Mode?

Post by Bietje »

I tested the primary bus and the secondary bus.. It is 0xff after I did nothing, after I selected a drive, after a reset, after everything I done untill now. Please note that I tested on another laptop, and there is everything fine. But on3 of the five computers it isn't working yet..

Edit: Also when I set lba mid and high to zero and read the values back later I get 0xff.

Here is some code:

Code: Select all

[GLOBAL ata_identify]
ata_identify:
	push ebp
	mov ebp, esp

	mov dx, OL_MASTER_ATA_DRIVE_SELECT
	mov al, 0xa0 ; select master drive
	out dx, al

	xor al, al
	mov dx, OL_MASTER_ATA_SECTOR_COUNT
	out dx, al
	
	or dx, 1b ; inc dx -> dx = 0xf3
	out dx, al

	inc dx
	out dx, al

	inc dx
	out dx, al

	mov al, 0xec ; identify command
	mov dx, OL_MASTER_ATA_COMMAND
	out dx, al

	mov dx, OL_MASTER_ATA_STATUS
	xor eax, eax
	in al, dx
	in al, dx
	in al, dx
	in al, dx

.retry:
	in al, dx
	cmp al, 0xff
	je .testLBA
	jmp .done

.testLBA:
	mov dx, OL_MASTER_ATA_MID_LBA
	in al, dx
	or al, al
	jnz .fail

	inc dx
	in al, dx
	or al, al
	jnz .fail
	jmp .done

.fail:
	jmp  $

.done:
	and eax, 0xff
	pop ebp
	ret
Defines:

Code: Select all

; ATA I/O registers
%define OL_MASTER_ATA_BASE 0x1f0

%define OL_MASTER_ATA_DATA 		OL_MASTER_ATA_BASE

%define OL_MASTER_ATA_ERR_INFO 		OL_MASTER_ATA_BASE+1
%define OL_MASTER_ATA_FEATURES		OL_MASTER_ATA_ERR_INFO

%define OL_MASTER_ATA_SECTOR_COUNT 	OL_MASTER_ATA_BASE+2
%define OL_MASTER_ATA_LOW_LBA 		OL_MASTER_ATA_BASE+3
%define OL_MASTER_ATA_MID_LBA		OL_MASTER_ATA_BASE+4
%define OL_MASTER_ATA_HIGH_LBA		OL_MASTER_ATA_BASE+5

%define OL_MASTER_ATA_DRIVE_SELECT	OL_MASTER_ATA_BASE+6
%define OL_MASTER_ATA_HEAD_SELECT	OL_MASTER_ATA_DRIVE_SELECT

%define OL_MASTER_ATA_COMMAND		OL_MASTER_ATA_BASE+7
%define OL_MASTER_ATA_STATUS		OL_MASTER_ATA_COMMAND
Luns
Member
Member
Posts: 56
Joined: Sun May 01, 2011 12:15 am

Re: Do I have to enable ATA PIO Mode?

Post by Luns »

It looks like that code only tests the master drive on the primary bus - not the secondary bus or either slave drives.

After you issue the IDENTIFY device command, you need to wait until the BSY bit in the status register clears. After that, you can test the cylinder high and cylinder low values to determine the type of drive.
Bietje
Member
Member
Posts: 100
Joined: Wed Apr 20, 2011 6:57 am

Re: Do I have to enable ATA PIO Mode?

Post by Bietje »

It looks like that code only tests the master drive on the primary bus - not the secondary bus or either slave drives.
I adjusted the values for secondary bus. This was the code in the repository.
After you issue the IDENTIFY device command, you need to wait until the BSY bit in the status register clears. After that, you can test the cylinder high and cylinder low values to determine the type of drive.
Eeek, totally forgot. I will implement that now.

Edit: The busy bit does never clear. It just keeps looping forever:

Code: Select all

.retry:
	in al, dx
	test al, byte 0x80
	jz .testLBA
	jmp .retry
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: Do I have to enable ATA PIO Mode?

Post by Combuster »

Busy clearing is just one of many options. A typical debugging step is to keep polling the register and print an update to the screen every time it changes, whether that be because of the busy bit or something else. That way you can monitor the device for many changes rather than just one.
"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 ]
Bietje
Member
Member
Posts: 100
Joined: Wed Apr 20, 2011 6:57 am

Re: Do I have to enable ATA PIO Mode?

Post by Bietje »

Combuster wrote:Busy clearing is just one of many options. A typical debugging step is to keep polling the register and print an update to the screen every time it changes, whether that be because of the busy bit or something else. That way you can monitor the device for many changes rather than just one.
You mean something like.. this:

Code: Select all

xor bl, bl
.retry:
	in al, dx
	push ax
	xor al, bl
	pop ax
	mov bl, al
	jnz .printAL
	jmp .retry

.printAL:
	pushad
	push 0
	push 0
	push 16
	push eax
	call printnum
	add esp, 4*4
	popad
	jmp .retry
The value, is and keeps 0xff.
Bietje
Member
Member
Posts: 100
Joined: Wed Apr 20, 2011 6:57 am

Re: Do I have to enable ATA PIO Mode?

Post by Bietje »

Update:

I always thought that this was drive dependent.. Apparently not, because I just grabbed some unused 500 GB from my cabinet and I wrote my bootloader to it. I opened up a dell dimension, connected tested -> nothing seems to be wrong. Status register starts out as something like 0x80 and then sets to 0x0.

After that I opened up my newer acer pc, connected the drive in that machine tested -> b00m value keeps hanging at 0xff. I was like what the ****?

Anyone has any idea's? Are there more options I can try? Should i try more busses? Use dma?
Luns
Member
Member
Posts: 56
Joined: Sun May 01, 2011 12:15 am

Re: Do I have to enable ATA PIO Mode?

Post by Luns »

Yes, make sure you're testing all the possible bus/drive combinations. Is the new drive IDE?

While you wait for the busy bit to clear, also be checking for other bits such as the abort bit and error bit. Check the ATA documentation for what different status bits mean.
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: Do I have to enable ATA PIO Mode?

Post by Combuster »

I went through the thread and collected the entire problem description: 0xff is an all ones, which is the same thing you get if you didn't connect anything. Is your drive connected by an IDE cable to the motherboard? Have you, as suggested, tried masters and slaves on both buses? Can the BIOS see the drive? If any of those answers is no, your test setup is essentially broken.
"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 ]
Post Reply