Page 1 of 1

floppy dont works on vmware

Posted: Wed Jun 01, 2005 12:10 pm
by guest
Hello, i have written a simple floppy driver to read data from floppy. It works properly with Qemu but on Vmware it doesnt work.

Code: Select all

//
// Initialize DMA for write / read access
//
BOOLEAN DmaInitialize(DWORD Address, 
                 BYTE Channel,
                 DWORD Mode,
                 WORD Size)
{
   _asm cli

   if (Channel == DMA_CHANNEL_FLOPPY)
   {
      WRITE_PORT_UCHAR(0x0A, 0x06);
   }
   else
   {
      _asm sti
      return FALSE;
   }

   //
   // Reset Flip-Flop
   //

   WRITE_PORT_UCHAR(0x0c, 0);

   //
   // Transfer memory to device
   //
   if (Mode == DMA_MODE_READ)
   {
      if (Channel == DMA_CHANNEL_FLOPPY)
      {
         WRITE_PORT_UCHAR(0x0b, 0x5a);
      }
   }
   //
   // Transfer device to memory
   //
   else if(Mode == DMA_MODE_WRITE)
   {
      if (Channel == DMA_CHANNEL_FLOPPY)
      {
         WRITE_PORT_UCHAR(0x0b, 0x56);
      }
   }

   
   //
   // Set the memory page
   //
   WRITE_PORT_UCHAR(0x81, Address >> 16);

   //
   // Set low byte of the offset
   //
   WRITE_PORT_UCHAR(0x04, (Address & 0xffff) & 0xFF);

   //
   // Set high byte of the offset
   //
   WRITE_PORT_UCHAR(0x04, (Address & 0xffff) >> 8);

   //
   // Set low byte of the size
   //
   WRITE_PORT_UCHAR(0x05, Size & 0xff);

   //
   // Set high byte of the offset
   //
   WRITE_PORT_UCHAR(0x05, Size >> 8);

   //
   // Clear channel mask
   //
   if (Channel == DMA_CHANNEL_FLOPPY)
   {
      WRITE_PORT_UCHAR(0x0a, 2);
   }

   _asm sti
   return TRUE;
}



BOOLEAN FdcIsReady()
{
   //
   // read from main status register
   //
   BYTE State = READ_PORT_UCHAR(FDC_MSR);

   //
   // if data register ready
   //
   if ( (State & 0xc0) == 0x80 )
      return TRUE;
   else
      return FALSE;
}

//
// Stops the system till floppy is ready
//
VOID FdcWaitForReady()
{
   while (TRUE)
   {
      if (FdcIsReady())
         break;
   }
}


VOID FdcReadSector(BYTE Sector, BYTE Track, BYTE Head)
{
   BYTE Command[9];

   WRITE_PORT_UCHAR(FDC_DOR, 0x1c);
   Command[0] = 0x46;
   Command[1] = 0;
   Command[2] = Track;
   Command[3] = Head;
   Command[4] = Sector;
   Command[5] = 0x02;
   Command[6] = 0x12;
   Command[7] = 0x18;
   Command[8] = 0x00;

   for (ULONG i = 0; i < 9; i++)
      FdcWriteByte(Command[i]);
   WRITE_PORT_UCHAR(FDC_DOR, 0);
}

Re:floppy dont works on vmware

Posted: Wed Jun 01, 2005 12:48 pm
by CloudNine
Thanks for telling us. However, how doesn't it work? Is there no floppy interrupt, is the data not transfered? I can't work it out from what you've given us.

Re:floppy dont works on vmware

Posted: Thu Jun 02, 2005 1:16 am
by distantvoices
I also find it a bad idea to hve the whole system stall in order to wait for the fdc to get ready. Use interrupts/messaging stuff for that and enjoy the powers of multitasking.

The more I canna imagine what kinda problems vmware should make. It's the least picky emulator outta there, runs things you wouldna dare to run on your da's pc for so buggy they are - without showing any of the bugs.

you are most prolly not receiving an irq as expected due to some fault setup.

I recommend you have your code spill out chars and numbers and messages in order to trace the bug down, eh? At least that's my debugging method of choice.

Re:floppy dont works on vmware

Posted: Thu Jun 02, 2005 12:44 pm
by bubach
You don't seem to do all this:
To read a sector from the drive, you need to

1. issue a seek track command (function 0X0F of controller)
2. initialize the DMA chip. (Not covered in this tutorial. but the floppy
controller used channel 2.)
3. wait (delay the driver for) head_settle_time specified in the floppy
parameter table described above.
4. write read sector command (function 0x66) to the controller
5. write the value of ((head*4)|drive) to the controller
6. write the value of the desired cylinder to be read to the controller
7. write the value of the desired head to be read to the controller
8. write the value of the desired sector to be read to the controller
9. write value of bytes_per_sector specified in the floppy parameter table to the controller
10.write value of sectors_per_track specified in the floppy parameter table to the controller
11.write value of gap_length specified in the floppy parameter table to the controller
12.write value of data_length specified in the floppy parameter table to the controller
At this point the controller will start to read the sector,so you have to wait
for it to finish, which is will signal by an interrupt.
13.wait for interrupt from controller
14.check interrupt status
15.read the result bytes sent by the controller
http://bos.asmhackers.net/docs/floppy/d ... torial.txt

/ Christoffer