Reading floppy using ports...

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

Re:Reading floppy using ports...

Post by human »

I too face this problem. Whenever I try to read a sector(0,0,1) from the floppy drive, the controller couldn't find the specified sector ID. What could be the problem behind this?

any help appreciated.
Slasher

Re:Reading floppy using ports...

Post by Slasher »

We can't help you without seeing the code you are using
hum

Re:Reading floppy using ports...

Post by hum »

   I have given my coding for just reading the sector 0,0,1 of the floppy drive. The FDC returns informing that it couldn't find the specified sector ID address mark. I have to complete this coding before the end of this month. so, plz help me. And I also wanted to know that should I initialize the floppy using any other command before reading the sector.

Code: Select all

void sendb(UCHAR data)
{
   UCHAR msr;
   msr = inb(0x3F4);   // Get MSR

   while((msr & 0xC0) != 0x80)   // Wait till FDC gets free
     msr = inb(0x3F4);

   outb(FDC_DATA, data);   // Send byte to data register
   kprintf("\nByte Sent %x", data);
}
UCHAR readb()
{
   UCHAR msr;
   msr = inb(0x3F4);
   while((msr & 0xC0) != 0xC0)
     msr = inb(0x3F4);
   msr = inb(0x3F5);
   return msr;
}

void readblock(UCHAR block, UCHAR *dBuffer)
{
   UCHAR cyl, sect, head, i, st0, st1, st2, c,h,s,ns;
   LBA2CHS(block, &cyl, &head, &sect);

   outb (FDC_CCR, 0);   // Data Transfer Rate (500kb/s)

   floppy_status = FDS_READING;

   StartFDDMotor();
   sendb (0x66); // command to read a sector
   sendb (0);   // head 0 of drive 0
   sendb (0); // cylinder
   sendb (0); //head
   sendb (1); //sector
   sendb (2);  // sector size
   sendb (18); // sectors per track
   sendb (0x1B); //FD_GAP3RW
   sendb (0xFF);

   while(floppy_status != FDS_IDLE);

    st0 = readb();
   st1 = readb();
   st2 = readb();
   c = readb();
   h = readb();
   s = readb();
   ns = readb();

   kprintf("\nST0 = %x",st0);
   kprintf("\nST1 = %x",st1);
   kprintf("\nST2 = %x",st2);
   kprintf("\nCylinder = %x",c);
   kprintf("\nHead = %x",h);
   kprintf("\nSector = %x",s);
   kprintf("\nSector Size = %x",ns);

   StopFDDMotor();
}
any help greatly appreciated.
Slasher

Re:Reading floppy using ports...

Post by Slasher »

while(floppy_status != FDS_IDLE);
That is an endless loop. Where is the code to read the status in the while loop?
I think this is what you want

while(floppy_status != CONSTANT INDICATING FLOPPY IS FREE)
floppy_status = read floppy status port;

as the code is you are reading the result phase when the floppy controller is still in the data phase. This is because you set
floppy_status = FDS_READING and then did
while(floppy_status != FDS_IDLE). That is a BAD design. Floppy status should be what the controller returns as the status after you read the status port(s) and not what you set by yourself.
Besides that is what lead to your endless loop,
you set floppy_status = FDS_READING and then you are testing for floppy_status = FDS_IDLE without modifying the status


I suggest you write
wait_floppy_ready and wait_floppy_data routines.
The_Human

Re:Reading floppy using ports...

Post by The_Human »

I'm sorry. I forgot to post my floppy IRQ Handler. Now i've given the FDC IRQ.

Code: Select all

void FDD_Irq()
{
             int i;
   kprintf("\nIRQ Called\n");

   switch(fdd_status)
   {
   case FDS_READINGID:
      fdd_status = FDS_IDLE;
      break;
   case FDS_READING:

        // Reading the result registers

        for(i=0;i<=6;i++)
         kprintf("\n%x",ReadByte());

      fdd_status = FDS_IDLE;
      break;

   case FDS_RESETTING:
      fdd_status = FDS_IDLE;
      break;
   case FDS_CALIBRATING:
      fdd_status = FDS_IDLE;
      break;
   case FDS_SEEKING:
      fdd_status = FDS_IDLE;
      break;
   }
}
any help appreciated
The_Human

Re:Reading floppy using ports...

Post by The_Human »

Is it necessary to initialize the FDC before issuing the read command? and also, how long should I wait to receive data from the data register after issuing the read command?

any help appreciated
Guest

Re:Reading floppy using ports...

Post by Guest »

This floppy function gives me a value of 0x28 on BOCHS and 0x04 on my computer. Is the output correct? how can it be 0x04 in the st3 register?

Code: Select all

void chk_drive_status(void)
{
  volatile BYTE st3=0,msr=0;
  while( (inb(FDCA_BASE+MSR) & 0xC0)!=0x80 );
  outb(FDCA_BASE+DR,CHK_DRIVE_STATUS);
  outb(FDCA_BASE+DR,0x0);
  while( (inb(FDCA_BASE+MSR) & 0x80)!=0x80);
  st3=inb(FDCA_BASE+DR);
  printf("\nST3=%x",st3);
}
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Reading floppy using ports...

Post by Neo »

Just curios. Is floppy programming really difficult or is it that most of you haven't witten floppy drivers as yet?
I;m asking because i haven't started out as yet.
Only Human
Adek336

Re:Reading floppy using ports...

Post by Adek336 »

It is isn't *that* simple, but neither it is very hard. Some time ago I tried and I in 2 weeks I had my driver only read a bootsector. But then, perhaps I wasn't experienced enough. Now I wrote the driver in a week's time. Thank God it works and I can focus on the file service :P
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Reading floppy using ports...

Post by Neo »

Great then what do i need before i start out? Right now my kernel has a memory manager with paging enabled and also has interrupts etc setup can i start out now.
It is isn't *that* simple, but neither it is very hard.
then why hasn't anyone been able to answer these questions here?
Only Human
Adek336

Re:Reading floppy using ports...

Post by Adek336 »

then why hasn't anyone been able to answer these questions here?
perhaps nobody took his time to reply.
Great then what do i need before i start out?
an interrupt manager, and the pic reprogrammed so you can catch fdc irqs.
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:Reading floppy using ports...

Post by Pype.Clicker »

Neo wrote: then why hasn't anyone been able to answer these questions here?
Quoting a comment in 'linux/drivers/block/floppy.c'
/*
* This file is certainly a mess. I've tried my best to get it working,
* but I don't like programming floppies, and I have only one anyway.
* Urgel. I should check for more errors, and do more graceful error
* recovery. Seems there are problems with several drives. I've tried to
* correct them. No promises.
*/
most of the ppl that start with a floppy driver send their resume as "i see ST2 has 03, is it normal ?"
how could i know if i haven't a cache hit for the floppy specs right at the moment ... I've used INT13 to read what i wanted from my boot floppy, but i do not consider floppy driver as something "interresting" to do ... i'm more focusing on hard disks ...

I saw Tim had a nice Floppy driver in the Mobius and that it was GPL ... i'll probably port that one when i'll have no other choice (after i ask for his blessing, of course :)
PCI and USB sounds more interresting to me ...
Tim

Re:Reading floppy using ports...

Post by Tim »

Feel free to use my source :). The current version doesn't support multiple drives on one controller, though, and it probably won't do soon.
Guest

Re:Reading floppy using ports...

Post by Guest »

sir,what is the procedure to do a "check interrupt status" command with the floppy controller?
The one i have written right now goes like this

Code: Select all

1) Read MSR and check if MRQ bit is set and DIO it is clear
2) send the command(0x08) to the  Data register(DR)
3) read the DR twice first for ST0 and then for CYLinder no.
on printing ST0 and CYL i got ST0=8 and CYL=8.

is this procedure right? do i have to wait before reading the DR? if so what bits should i check for?
does the "check int status" itself issue an interrupt after completion?
do i have to include any delays anywhere?
Post Reply