Page 1 of 1

Floppy read_write error

Posted: Tue Dec 30, 2008 10:05 am
by negcit.K
Hello.
I'm so happy that i have done the floppy driver part. But something really bad happened.
bochs always give me an message as follows:
Bochs is exiting with the following message:
[FDD ] read/write command: sector size 33554432 not supported
i debug and debug, but no change. can any one give me some advice?
here is the key codes:
get_byte function:

Code: Select all

/*
 * get *ONE* byte of results from FD_DATA register then return what 
 * it get, or retrun -1 if faile.
 */
int get_byte()
{
        volatile int msr;
        int counter;        
        for (counter = 0; counter < 1000; counter ++) {
                msr = inb_p(FD_STATUS) & (STATUS_DIR|STATUS_READY|STATUS_BUSY);
                if (msr == (STATUS_DIR|STATUS_READY|STATUS_BUSY))
                        return inb_p(FD_DATA);
                sleep(1); /* delay 10ms */
        }
        printk("get_byte: get status times out!\n");
        return -1;
}
and here is the wait interrupt function:

Code: Select all

int wait_fdc( int sensei)
{      
        /* i implemented a COUNT_DOWN counter, give the count_down a initial value, it then will deduce one at every timer ticks*/
        int time_out;
        count_down = 200; /* set count_down initial value to 2 second */        
        /* wait for FLOPPY_INTERRUPT hander to signal command finished */
        while (!done && count_down)
                ;
        time_out = count_down;

        ST0 = get_byte();      /* I THINK HERE IS THE PROBLEM */
        ST1 = get_byte();
        ST2 = get_byte();
        ST3 = get_byte();              

        if (sensei) {
                /* send a "sense interrupt status" command */
                send_byte(FD_SENSEI);
                sr0 = get_byte();
                fdc_track = get_byte();
        }
        
        done = FALSE;
        if (time_out == 0)
                return FALSE;
        else
                return TRUE;
}
setup_DMA function:

Code: Select all

static void setup_DMA(unsigned long addr, int count, int command)
{
        count = count * 512 - 1;
        
        cli();                          /* we need a safe env. */
        
	immoutb_p(4|2,0x0a);            /* mask DMA 2 */

        immoutb_p(0,0x0c);               /* clear flip flop */
        
        immoutb_p((command == FD_READ)?DMA_READ:DMA_WRITE,0x0b);

	immoutb_p(addr,4);              /* 8 low bits of addr */
	
        addr >>= 8;
	immoutb_p(addr,4);              /* bits 8-15 of addr */

	addr >>= 8;
	immoutb_p(addr,0x81);           /* bits 16-19 of addr */

	immoutb_p(count & 0xff,5);      /* low 8 bits of count-1 (1024-1=0x3ff) */

	immoutb_p(count >> 8,5);        /* high 8 bits of count-1 */

	immoutb_p(0|2,10);              /* activate DMA 2 */
	sti();
}

and here is the key of key function:

Code: Select all

int floppy_rw(int block, char *blockbuff, int command, int sectors)
{
        

        block_to_hts(block,&head,&track,&sector);

        /* turn it on if not */
        motor_on();

        if ( inb_p(FD_DIR) & 0x80) {
                changed = TRUE;
                seek(1);        /* clear "disk change" status */
                recalibrate();
                motor_off();
                printk("floppy_rw: Disk change detected. You are going to DIE:)\n");
                
                pause();  /* just put it in DIE */
        }

        /* move head to the right track */
        if (!seek(track)) {
                motor_off();
                printk("floppy_rw: Error seeking to track\n");
                return FALSE;
        }

        /* program data rate (500k/s) */
        outb_p(0,FD_DCR);
                
        setup_DMA((unsigned long)blockbuff, sectors, command);

        send_byte(command);
        send_byte(head<<2 | 0);
        send_byte(track);
        send_byte(head);
        send_byte(2);           /* sector size = 125 * 2^(2) */
        send_byte(floppy.sector);
        send_byte(floppy.gap);
        send_byte(0xFF);        /* sector size(only two valid vaules, 0xff when n!=0*/


        if ( !wait_fdc(TRUE) ) {
                printk("Time out, trying operation again after reset() \n");
                reset();
                return floppy_rw(block, blockbuff, command, sectors);
        }

        motor_off();

        if (/*res != 7 || */(ST0 & 0xf8) || (ST1 & 0xbf) || (ST2 & 0x73) ) {
                if (ST1 & 0x02) 
                        printk("Drive is write protected!\n");
                else
                        printk("floppy_rw: bad interrupt!\n");

                return 0;
        } else {
                printk("Congratulations!\nfloppy read_write OK!\n");
                 return 1;
        }
}


void floppy_read(int block, char* blockbuff, int sectors)
{
        floppy_rw(block, blockbuff, FD_READ, sectors);
}

void floppy_write(int block, char* blockbuff, int sectors)
{
        floppy_rw(block, blockbuff, FD_WRITE, sectors);
}

do i have written something wrong?

and in my test function :

Code: Select all

        floppy_read(1, (char *)tmp_floppy_area, 2);
and it always output:

Code: Select all

printk("get_byte: get status times out!\n");
printk("get_byte: get status times out!\n");
printk("get_byte: get status times out!\n");
printk("get_byte: get status times out!\n");
yeah, four times time out not SIX time out. that's to say in the wait_fdc, just when we wanna read the result of a READ or WRITE command.

can any one give me some tips?
Thanks.

Re: Floppy read_write error

Posted: Tue Dec 30, 2008 10:29 am
by System123
I have recently finished my Floppy driver, done in Pascal, and the best advice I can give you is use this as a guide when you get stuck. http://forum.osdev.org/viewtopic.php?t=13538

Re: Floppy read_write error

Posted: Tue Dec 30, 2008 10:34 am
by negcit.K
System123 wrote:I have recently finished my Floppy driver, done in Pascal, and the best advice I can give you is use this as a guide when you get stuck. http://forum.osdev.org/viewtopic.php?t=13538
Thank you.
i'll see it tomorrow, it's dark night here and i got an exam on tomorrow morning.
GOOD NIGHT. :D

Re: Floppy read_write error

Posted: Wed Dec 31, 2008 4:09 am
by negcit.K

Code: Select all

Bochs is exiting with the following message:
[FDD ] read/write command: sector size 33554432 not supported
does any one has some opinion about that ?
it don't do work yet.

Re: Floppy read_write error

Posted: Wed Dec 31, 2008 4:54 am
by negcit.K
And i don't know why always get the time out output when i use get_byte().
and the the value of msr = inb_p(FD_STATUS) & (STATUS_DIR|STATUS_READY|STATUS_BUSY) looks like always be 0x90.

Re: Floppy read_write error

Posted: Wed Dec 31, 2008 5:47 am
by negcit.K
what makes me happy is that it work, that's really strange, i test it with READ operation but WRITE not yet.
but the NAG window really bother me. And i really have no idea why i get the time out when using get_type().