Page 1 of 1

ide - pio

Posted: Fri Dec 03, 2010 5:09 am
by vinise
Hy every one

I'm trying to read an ide hd but without sucess :(
I've read the wiki about pio but i still get some difficulty setting up the registers.

i'm using bochs with an hd image.

Code: Select all

ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=disk, path="C:\cygwin\dev\hd0", mode=flat, cylinders=4, heads=16, spt=63
and bock see it well on boot:

Code: Select all

ata0 master: Generic 1234 ATA-6 Hard-Disk (   1 MBytes)
I can read it with od in shell:

Code: Select all

$ od -A d -c /dev/hd0
0000000   h  e  l  l  o  \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0000016  \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
here is my configuration to read...

0x1f6<-0xA0
0x1f2<-0x1
0x1f3<-0x1
0x1f4<-0x0
0x1f5<-0x0
0x1f7<-0x20

and i read with this code...

Code: Select all

still_going:
	in      al,dx
	test    al,8
	jz      still_going.
	
	
	mov     cx,10        ;10 word
	mov     di, buffer
	mov     dx,0x1f0  
	rep     insw
		
	mov byte dl, [buffer+2]
	call putchar
buffer: a buffer of 10 db
putchar: function with print the char in dl on the screen

any help will be pleased

Re: ide - pio

Posted: Fri Dec 03, 2010 5:13 am
by Combuster
A read is 512 bytes, you read 20 bytes (a word is two bytes!) into a 10-byte buffer, so you have a buffer overflow for starters.

Also, you might rather want to wait for both BUSY to be cleared and DRQ set.

Re: ide - pio

Posted: Fri Dec 03, 2010 7:59 am
by vinise
i did this.. is it better?

Code: Select all

still_going:
	in      al,dx
	test    al,8           
	jz      still_going     
	test    al,0x40
	jnz     still_going  
	
	
	mov     cx,512/2
	mov     di, buffer
	mov     dx,1f0h        
	rep     insw
	
	mov ecx,0
affi:
	mov byte dl, [buffer+ecx]
	call putchar
	inc ecx
	cmp ecx,20
	jb affi
	
buffer:
times	512 DB '0'
anny way is still not working :(

Re: ide - pio

Posted: Sat Dec 04, 2010 6:17 am
by vinise
Hy,
i've try to write on the disk instead of read. but i get a strange thing.

i try to write 512byte and when I check the disk with "od" i get five "1" and it's all.

If anny one could help me please :oops:

Re: ide - pio

Posted: Mon Dec 06, 2010 7:58 am
by thepowersgang
How useful... you failed to tell us what you are writing, and how the write code differs from your read code.

Also your code completely lacks commenting.

And as a final note, did you read the "Asking Smart Questions" link (it's linked from the forum rules)

Re: ide - pio

Posted: Mon Dec 06, 2010 8:39 am
by blackoil
read sector : set up registers, wait for irq, read 512 bytes
write sector : set up registers, write 512 bytes, wait for irq

the command register should be the last one to be written

Re: ide - pio

Posted: Mon Dec 06, 2010 8:43 am
by IanSeyler

Re: ide - pio

Posted: Mon Dec 06, 2010 4:09 pm
by bewing
The problem may be your value of ES: when you are trying to read -- but it looks like you are in real mode, still? Do you have interrupts turned off? If not, the BIOS is probably stealing all your data.

Re: ide - pio

Posted: Wed Dec 08, 2010 10:05 am
by vinise
Hy

Thanks for all your answers
the problems came from this line:

Code: Select all

mov     di, buffer
I made a mistake putting di instead of edi.

It's working well with bochs but when I try on a real computer it is not working.

Is it possible to acces to a real IDE hard drive with pio?