Floppy read_write error
Posted: Tue Dec 30, 2008 10:05 am
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:
here is the key codes:
get_byte function:
and here is the wait interrupt function:
setup_DMA function:
and here is the key of key function:
do i have written something wrong?
and in my test function :
and it always output:
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.
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:
i debug and debug, but no change. can any one give me some advice?Bochs is exiting with the following message:
[FDD ] read/write command: sector size 33554432 not supported
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;
}
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;
}
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,§or);
/* 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);
}
and in my test function :
Code: Select all
floppy_read(1, (char *)tmp_floppy_area, 2);
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");
can any one give me some tips?
Thanks.