Page 1 of 1

hard disk I/O

Posted: Tue Aug 11, 2009 1:22 am
by waliak
Hello,

I was reading lot of posts here and I think this forum is great. I'm preparing myself to create semi-os for data recovery. I was looking answer in specifications of ATA and PCI and ISA arch.

Code: Select all

			
                                  mov     dx,1f6h         ;Drive and head port
			mov     al,0a0h         ;Drive 0, head 0
			out     dx,al
		
			mov     dx,1f2h         ;Sector count port
			mov     al,1            ;Read one sector
			out     dx,al
		
			mov     dx,1f3h         ;Sector number port
			mov     al,1            ;Read sector one
			out     dx,al
		
			mov     dx,1f4h         ;Cylinder low port
			mov     al,0            ;Cylinder 0
			out     dx,al
		
			mov     dx,1f5h         ;Cylinder high port
			mov     al,0            ;The rest of the cylinder 0
			out     dx,al
		
			mov     dx,1f7h         ;Command port
			mov     al,20h          ;Read with retry.
			out     dx,al
		still_going:
			in      al,dx
			test    al,8            ;This means the sector buffer requires
						;servicing.
			jz      still_going     ;Don't continue until the sector buffer
						;is ready.
		
			mov     ecx,512        ;One sector /2
			;mov     edi,offset buffer
			mov     dx,1f0h         ;Data port - data comes in and out of here.  
			rep     insd
Problem is that this piece of code on some machines works and at some doesn't. When it doesn't work it writes to buffer 00600060 or 01560000. I've tested it on 5 different machines (2x lenovo laptops - works, 2x dell laptops - doesn't work, HP PC desktop - works).

Any one have a clue what i've done wrong?

Cheers,
WA

Re: hard disk I/O

Posted: Fri Aug 14, 2009 12:12 pm
by bewing
First problem:
You should be reading using INSW and not INSD. Using INSD could cause undefined and very buggy behavior.
Second problem:
You are trying to read one sector of words. A sector is 512 bytes. So you should be setting ecx to 256 -- and certainly not to 512, because there are only 256 words in a sector.
Third problem:
The data gets stored at whatever address the EDI register is set to. The only line that sets EDI in the code that you posted is commented out. Whether or not the A20 line has been enabled or not can also change the storage address. So, to tell you exactly why your data is getting stored at those two addresses, we would need to see the code that sets EDI, and you would need to tell us whether you have set A20 properly.