48 Bit LBA

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.
aKzenT

48 Bit LBA

Post by aKzenT »

I want to use 48 Bit LBA without using the BIOS (I'm in PMode), so I'm working with ports. This works fine if I use the READ SECTOR (0x20) command with CHS, but I've got problems when using READ SECTOR EXT (0x24) with LBA. I want to use 48 Bit Addressing, to use disk larger than 136 GB. If I read the data-port out, I got only the byte value 0xff all the time, but no real disk data. But if I read the error-register, I see no error (0x0). Do you have example code, that could help me with LBA & 48 Bit?

Thanks,
Thomas Krause

P.S. Why has the data-port only one physical byte (the next address is the error-register) but is 16 Bit width? I thought you could replace an inport(port) with an inportb(port) and an inportb(port+1)?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:48 Bit LBA

Post by Pype.Clicker »

most of intel chips allow indeed you to do OUTW x instead of OUTB x, OUTB x+1. However, here, the hardware *require* that you read *words* out of the HDD controler. period.

Iirc, the "read sector ext" is a command that allows you to read the CRC checksum and things like that along with the sector bytes. Do you really need that for 48bits LBA ?
aKzenT

Re:48 Bit LBA

Post by aKzenT »

What you mean is "read sector long" afaik. The normal read sector function uses only 24 Bits, which is to less for my needs.

Thanks,
Thomas Krause
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:48 Bit LBA

Post by Candy »

aKzenT wrote: What you mean is "read sector long" afaik. The normal read sector function uses only 24 Bits, which is to less for my needs.

Thanks,
Thomas Krause
Reading a sector using 48 bits requires sending two commands, one which stores the first 24 (or last, anyway, half of the) bits in the controller, and then you send the actual command which reads the last (or first, the other half of the) bits and executes the command. Since a harddisk command is a short command, a very long wait and a normal reply, the command could easily be longer :).

In effect, try ATA specs for ATA 6 or 7. You do NOT want read sector ext, that reads 516 byte sectors, not sectors located somewhere else.

PS: do you have a 128+ GB harddisk to test the code with?
aKzenT

Re:48 Bit LBA

Post by aKzenT »

I checked the ATA specs 6. All EXT-Commands are in the 48-Bit-Address-Feature set. I don't know if it reads 512 or 516 bytes, but I know that it seams to be the only possibility to address with 48 Bit.

I have Hard-Disks to test it, but I'm emulating in a VM without a Hard Disk that is so big.

At the moment I simply do 6 outport commands to fill every LBA-register two times, exactly how it is described in the specs. After writing all LBA and Sector register, I put one 24h command, which does not produce anything. Do I really have to send 2 commands, one after I fill the adress registers the first time and the after to actually execute it? I can't find something about this in the ATA specs.
Since a harddisk command is a short command, a very long wait and a normal reply, the command could easily be longer
I don't understand this sentence (forgive me for my poor english).

Thank you very much for your help,
Thomas Krause
tom1000000

Re:48 Bit LBA

Post by tom1000000 »

HI,

"Since a harddisk command is a short command, a very long wait and a normal reply, the command could easily be longer"

That isn't the clearest sentence. If I am correct "harddisk command" should be "hard disk sector read".

Basically it takes a long time read the disk, so sending the command is a miniscule amount of time.

If you want 48bit LBA why don't you look at the Linux or FreeBSD sources? Its only 1 specific piece of functionality you want so shouldn't be hard to find.
aKzenT

Re:48 Bit LBA

Post by aKzenT »

Thank you for this idea. Do you know where I can find the sources without downloading the whole distribution. I have only a 56kb modem.

Thomas Krause
tom1000000

Re:48 Bit LBA

Post by tom1000000 »

Have you ever heard of google?
aKzenT

Re:48 Bit LBA

Post by aKzenT »

I searched in google for weeks and I found only the official ATA-specs that shows how you can use 48 Bit, but it simply does not work.

aKzenT
tom1000000

Re:48 Bit LBA

Post by tom1000000 »

Hi,

I was referring to the Linux source code. That is extremely easy to find on the web. Then you can search it and find the 48 bit LBA (I presume).
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:48 Bit LBA

Post by bubach »

"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
aKzenT

Re:48 Bit LBA

Post by aKzenT »

Thank you!

Is the "Notify of replies" check box broken? I check it all the time, but I never get a notification. Perhaps it is filtered by my spam filter... I will check that.

Thomas Krause
Ben Green

Re:48 Bit LBA

Post by Ben Green »

I hope this is of help, you said that you have tried using the 28bit CHS mode... but have you tried using the 28bit LBA mode?

To do this you must set bit 7 of the drive/head specifier:

outportb (0x20, hdcbaseport+7); // Command (PIO Read)
outportb (0x01, hdcbaseport+1); // Sector Count
outportb (0x64, hdcbaseport+2); // lba 0..7
outportb (0x00, hdcbaseport+3); // lba 8..15
outportb (0x00, hdcbaseport+4); // lba 16..24
/* now comes the magic */
outportb (0xE0, hdcbaseport+5);

The lower 4 bits are LBA 25..28, bit 7 set means use LBA the above example, of course, will use the master drive and read the sector at LBA 0x64. if you change the command to 0x24 and ouput the LBA Address as detailed in the Maxtor recomendation... it should work. I cannot test the 48 bit version (my drives are all too old!!) but the one above does work.

I hope this helps... if you want some code let me know!

Ben.
Ben Green

Re:48 Bit LBA

Post by Ben Green »

Ooops... the above code should read:

outportb (0x20, hdcbaseport+7); // Command (PIO Read)
outportb (0x01, hdcbaseport+2); // Sector Count
outportb (0x64, hdcbaseport+3); // lba 0..7
outportb (0x00, hdcbaseport+4); // lba 8..15
outportb (0x00, hdcbaseport+5); // lba 16..24
/* now comes the magic */
outportb (0xE0, hdcbaseport+6);

Sorry about that!
bengreen5

Re:48 Bit LBA

Post by bengreen5 »

Ben Green wrote: The lower 4 bits are LBA 25..28, bit 7 set means use LBA the above...
Should read "The lower 4 bits are LBA 25..28, bit 6 set means use LBA the above..." I live in the UK and it is 02:37 here now... I am tired!
Post Reply