Page 1 of 1

ATA Device Detection

Posted: Thu Aug 12, 2010 11:05 pm
by brodeur235
Right now I'm just trying to get ATA device information in PIO mode at boot. However, whenever I fetch the status register, it reads 0; always. The first thing I do is check to see if the buses (primary or secondary) are floating, by reading the status register and checking it for the maxed out 0xFF value. Then I select the master drive on the primary bus and then I wait 400ns for that drive selection to take effect. Then I send the IDENTIFY command to the master drive and wait another 400ns. At this point the status register for the primary bus and it is still 0, which I suspect it shouldn't be because the os booted from an emulated floppy drive and I have an emulated HDD as well as bochsrc configured to have 2 buses attached to the controller chip with these lines:

Code: Select all

ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15
Here is my POI initialization code:

Code: Select all

;((~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~))
;((                     ATA DRIVER                    ))
;((~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~))
%define ATA
%include "system.inc"

[BITS 32]


; define primary bus ports

%define PB_0 0x1F0
%define PB_1 0x1F1
%define PB_2 0x1F2
%define PB_3 0x1F3
%define PB_4 0x1F4
%define PB_5 0x1F5
%define PB_6 0x1F6
%define PB_7 0x1F7
%define PB_8 0x1F8

; define secondary bus ports

%define SB_0 0x170
%define SB_1 0x171
%define SB_2 0x172
%define SB_3 0x173
%define SB_4 0x174
%define SB_5 0x175
%define SB_6 0x176
%define SB_7 0x177
%define SB_8 0x178


global _init_in_PIO
_init_in_PIO:
	
	; setup stack frame
	push ebp 
	mov ebp,esp
	pushad
	
	; get the primary bus's status byte
	xor eax,eax
	mov dx,PB_7
	in al,dx
	
	; check to make sure the primary bus isn't "floating"
	cmp al,0xFF
	jz .primary_floats
	jmp .primary_okay
	
	.primary_floats:
		
		; do ops
		call _dbg_no
		jmp .end
		
	.primary_okay:
		
	; get the secondary bus's status byte
	xor eax,eax
	mov dx,SB_7
	in al,dx
	
	; check to make sure the secondary bus isn't "floating"
	cmp al,0xFF
	jz .secondary_floats
	jmp .secondary_okay
	
	.secondary_floats:
		
		; do ops
		call _dbg_no
		jmp .end
		
	.secondary_okay:
	
	; select the master drive on the primary bus
	mov dx,PB_6
	mov al,BYTE 0xA0
	out dx,al
	
	; 400ns delay for status byte to indicate readiness
	mov dx,PB_7
	in al,dx
	in al,dx
	in al,dx
	in al,dx
	
	; send the "identify" command (0xEC)
	mov dx,PB_7
	mov al,BYTE 0xEC
	out dx,al
	
	; 400ns delay for status byte to indicate readiness
	mov dx,PB_7
	in al,dx
	in al,dx
	in al,dx
	in al,dx
	
	; now read the status byte
	xor eax,eax
	in al,dx
	
	;DEBUG
	push eax
	push dword 4
	mov eax,esp
	add eax,0x04
	push eax
	call VGA_PRINT_MEM_HEX
	add esp,0x0c
	;/DEBUG
	
	
	.end:
	
	; clean up stack frame
	popad
	mov esp,ebp
	pop ebp
	ret
Why is that status byte always coming out to be 0x00 when drives do exist.

Brodeur235

Re: ATA Device Detection

Posted: Fri Aug 13, 2010 5:53 am
by bewing
What is your bochsrc line that defines your emulated HD?

Re: ATA Device Detection

Posted: Fri Aug 13, 2010 5:16 pm
by brodeur235
Thanks for the reply bewing, I fixed this problem.

Brodeur235

Re: ATA Device Detection

Posted: Sat Aug 14, 2010 3:50 am
by sebihepp
Can you post your solution?
I have an equal problem with my ATA driver and perhaps I get some new ideas...

TIA
sebihepp