Reading from the hard drive

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
Lunatic
Posts: 5
Joined: Wed Nov 21, 2007 4:35 am

Reading from the hard drive

Post by Lunatic »

Hello.

I have found tutorials on how to read from a hard drive. My code does read something (not sure if that is what it should read) but I wanted to ask about one parameter sent to port 0x1F6. For giving a request I have this code:

Code: Select all

	outportb(0x1F1, 0x00);
	outportb(0x1F2, sectors);
	outportb(0x1F3, (unsigned char)(block_addr));
	outportb(0x1F4, (unsigned char)(block_addr>> 8));
	outportb(0x1F5, (unsigned char)(block_addr>> 16));
	outportb(0x1F6, 0xE0 | (DRIVE << 4) | ((block_addr>> 24) & 0x0F));	
	outportb(0x1F7, 0x20);
I am not sure what should be passed on instead of DRIVE. All I know is that it is called 'drive indicator'. What does that mean?
Also, what data types should be used for each variable? sectors, DRIVE and block_addr.
Thanks![/i]
Ad astra per aspera
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

Technical Information on the ports:
Port Read/Write Misc
------ ------------ -------------------------------------------------
1f0 r/w data register, the bytes are written/read here
1f1 r error register (look these values up yourself)
1f2 r/w sector count, how many sectors to read/write
1f3 r/w sector number, the actual sector wanted
1f4 r/w cylinder low, cylinders is 0-1024
1f5 r/w cylinder high, this makes up the rest of the 1024
1f6 r/w drive/head
bit 7 = 1
bit 6 = 0
bit 5 = 1
bit 4 = 0 drive 0 select
= 1 drive 1 select
bit 3-0 head select bits
1f7 r status register
bit 7 = 1 controller is executing a command
bit 6 = 1 drive is ready
bit 5 = 1 write fault
bit 4 = 1 seek complete
bit 3 = 1 sector buffer requires servicing
bit 2 = 1 disk data read corrected
bit 1 = 1 index - set to 1 each revolution
bit 0 = 1 previous command ended in an error
1f7 w command register
commands:
50h format track
20h read sectors with retry
21h read sectors without retry
22h read long with retry
23h read long without retry
30h write sectors with retry
31h write sectors without retry
32h write long with retry
33h write long without retry
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

Yes, I've seen that myself, and wondered the same thing. If you puzzle through Dex's info, you will see that DRIVE is just a bit, with a value of 0 (master) or 1 (slave).
Post Reply