Page 1 of 1

Bochs HDD serial number?

Posted: Tue Oct 25, 2005 2:18 pm
by stonedzealot
I print the hard drive serial number for the master primary IDE device, just for shits and grins. The only thing is that when I do a command 0xEC (identify drive) to get information on it, there are some problems...

First of all, the drive's first 16bits returned are all 1s which seems to conflict. Second the serial is reported as:

XXXXXXXZXXXXXXXXXZXX

I'm not sure if Bochs is just weird when it comes to giving virtual drives serials, or what. Here's the read code:

Code: Select all

void idedriveinfo(ushort device)
{
   inportb(device + IDEERROR); //0x1F1
   idedrivewait(device, IDESTATUSREADY + IDESTATUSSEEKCOMPLETE); //0x1F0, 01010000b
   outportb(device + IDEDRIVEHEAD, IDEDRIVEHEADRESERVED + IDEDRIVEHEADPRIMARY); //0x1F6, 0xA0
   outportb(device + IDECOMMAND, IDECOMMANDIDENT); //0x1F7, 0xEC
   idedrivewait(device, IDESTATUSREADY + IDESTATUSSEEKCOMPLETE + IDESTATUSDRQ); //0x1F0, 01011000b

   kprintf("IDE Probe of Device at: 0x%h\n", device);
   kprintf("Flags: %b%b \n", inportb(device), inportb(device));

   uint i = 0;

   for(i = 10; i>0;i--)
   {
      inportb(device);
      inportb(device);
   }

   char serial[21];
   serial[20] = 0;

   for(i=20;i>0;i--)
      serial[i-1] = inportb(device);

   kprintf(serial);   
}
Note that the read on the error register is there to clear the error bit from something that bochs did. The idedrivewait just waits for the device's status register to be of a known value.

So does anyone see a problem with this code, or is Bochs just unreliable/strange in it's reporting of serials?

I'm getting all of my information from http://www.nondot.org/sabre/os/files/Disk/IDE-tech.html and http://www.nondot.org/sabre/os/files/Di ... rogate.zip

Re:Bochs HDD serial number?

Posted: Tue Oct 25, 2005 2:29 pm
by stonedzealot
Briefly looking into boch's iodev/harddrv.cc source file, apparently the serial is supposed to be VT00001 and the first bits aren't supposed to all be 1s, so, there's obviously something wrong with the code.

EDIT: the above was in a big if defined block, which I didn't have defined, so Bochs is actually supposed to return nothing for the serial. The bug that made it output that kinda crap however, was that I was using two inportbs instead of inportw while the harddrive is apparently only able to return full words at a time.

Nevermind, all.

Re:Bochs HDD serial number?

Posted: Wed Oct 26, 2005 2:41 am
by Pype.Clicker
iirc, you should never use inportb to receive ATA datas, but always inportw ... I also suggest you read the whole "information sector" in memory and then try to decrypt it: that will be easier for later trouble shooting.

The "all 1" bits are indeed suspicious: looks like you're reading a non-responding device.