ide - pio

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.
Post Reply
vinise
Posts: 10
Joined: Mon Nov 22, 2010 3:33 pm

ide - pio

Post 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
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: ide - pio

Post 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.
"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 ]
vinise
Posts: 10
Joined: Mon Nov 22, 2010 3:33 pm

Re: ide - pio

Post 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 :(
vinise
Posts: 10
Joined: Mon Nov 22, 2010 3:33 pm

Re: ide - pio

Post 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:
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: ide - pio

Post 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)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: ide - pio

Post 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
User avatar
IanSeyler
Member
Member
Posts: 326
Joined: Mon Jul 28, 2008 9:46 am
Location: Ontario, Canada
Contact:

Re: ide - pio

Post by IanSeyler »

BareMetal OS - http://www.returninfinity.com/
Mono-tasking 64-bit OS for x86-64 based computers, written entirely in Assembly
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: ide - pio

Post 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.
vinise
Posts: 10
Joined: Mon Nov 22, 2010 3:33 pm

Re: ide - pio

Post 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?
Post Reply