Page 1 of 2
Reading Floppy Drive
Posted: Mon Dec 22, 2003 11:07 am
by Rahman
I have started programming FDC in the DMA mode. I assigned the track buffer at the address 0x80000 and initialized the DMA controller. I just wanted to know that should I enable paging before reading sectors from the floppy drive, since the page number of the track buffer should be sent to the DMA controller (?). I haven't got this point clear, whether this 64 kb pages are same as that of the 4 kb pages. Whenever I read sector from the FDD, the command starts execution, but terminates abnormally. The status registers returned are:
ST0 = 40h
ST1 = 4h
ST2 = 10h
But it returns the correct CHS value.
I have given my DMA initialization code:
Code: Select all
void ReadSector(int block)
{
...
InitDMA (2, 0x80000, DEV_READ, 512);
...
}
void InitDMA(UCHAR Channel, long tBuffer, UCHAR Mode, int Size)
{
__asm__ __volatile__ ("cli");
outb (DMA_MASK, 4 | Channel);
outb (DMA_FLIPFLOP, 0);
if(Mode == DEV_READ)
outb (DMA_MODE, 0x58 | Channel);
else
outb (DMA_MODE, 0x54 | Channel);
outb (DMA_PAGE, tBuffer >> 16);
outb (DMA_ADDRESS, 0x00);
outb (DMA_ADDRESS, (tBuffer & 0xFF));
outb (DMA_ADDRESS, (tBuffer & 0xFFFF) >> 8);
outb (DMA_SIZE, Size & 0xFF);
outb (DMA_SIZE, (Size & 0xFFFF) >> 8);
outb (DMA_MASK, 2);
__asm__ __volatile__ ("sti");
}
What would be wrong with this code ?
thank u.
Re:Reading Floppy Drive
Posted: Tue Dec 23, 2003 12:12 am
by Rahman
when i try to write to floppy, i received the same problem.
plz. help me out of this problem.
Re:Reading Floppy Drive
Posted: Tue Dec 23, 2003 11:12 am
by Rahman
should i have to enable paging before implementing floppy driver ?
any help appreciated.
Re:Reading Floppy Drive
Posted: Tue Dec 23, 2003 12:42 pm
by Pype.Clicker
Rahman wrote:
should i have to enable paging before implementing floppy driver ?
any help appreciated.
no, this is not required. However, if you do have paging enabled and then want to use your FLoppy code, make sure you noticed that the DMA will use *phyiscal* addresses while the program will use *virtual* addresses.
Re:Reading Floppy Drive
Posted: Tue Dec 23, 2003 12:48 pm
by Rahman
i'm now in protected mode. i haven't enabled paging. but still the command doesn't work.
Re:Reading Floppy Drive
Posted: Tue Dec 23, 2003 6:20 pm
by Slasher
hi,
did you enable the DMA controller?
Code: Select all
outportb(0x08,0X10); /*FIXED PRIORITY,ENABLE CONTROLLER*/
did you mask the channel off before seting the mode and then back on?
Code: Select all
outportb(DMA8_CHANNEL_MASK_REG,(channel|4)); /*mask channel,turn off so can be programmed*/
outportb(DMA8_CHANNEL_MODE_REG,(mode|channel)); /*set mode for channel*/
outportb(DMA8_CHANNEL_MASK_REG,channel); /*mask channel,turn on*/
how did you start the DMA transfer?
Code: Select all
unsigned char start_dma(unsigned char channel,char mode,unsigned long buffer,unsigned short count)
{
unsigned short offset;
unsigned char page;
if(channel > 3)
return 0;
page=(unsigned char)((buffer>>16) & 0xff);
offset=(unsigned short)(buffer & 0xffff);
asm("cli");
outportb(DMA8_CHANNEL_MASK_REG,(channel|4)); /*mask channel,turn off so can be programmed*/
outportb(DMA8_CLEAR_FLIP_FLOP,0x00); /*clear flip flop*/
outportb(DMA8_CHANNEL_MODE_REG,(mode|channel)); /*set mode for channel*/
outportb(dma_address_reg[channel],(offset&0x00ff)); /*out low byte*/
outportb(dma_address_reg[channel],(offset >>8));/*output high byte*/
outportb(dma_count_reg[channel],(count & 0x00ff));
outportb(dma_count_reg[channel],(count >> 8));
outportb(dma_Page_reg[channel],page);
asm("sti");
outportb(DMA8_CHANNEL_MASK_REG,channel); /*unmask channel,turn on*/
return 1;
}
PS
comment your code so that we know what you are trying to achieve.
you are free to use the code as you like.
Re:Reading Floppy Drive
Posted: Wed Dec 24, 2003 3:10 am
by Rahman
thank you CS, now, i've enabled the DMA controller. but, still it doesn't work. i just wanted to know, does the FDC get interrupted before completing its read command. because, i've used a variable 'fdd_status' for maintaining the status of the floppy. i move FDS_IDLE, whenever the interrupt is called. i've given my ReadData() function which reads the data from the given sector and places it in the address 0x80000.
Code: Select all
void ReadSector(int block)
{
...
SeekCylinder(cyl); // seeks the cyl.
while (fdd_status != FDS_IDLE); // wait till the FDC gets IDLE
InitDMA (2, 0x80000, DEV_READ, 512); // initialized DMA
StartFDDMotor(); // starts drive A motor
outb (FDC_CCR, 0); // transfer rate 500 kb/s
SendByte (CMD_READ); // command for read op.
SendByte (head << 2); // head bit shifted two times
SendByte (cyl); // cylinder
SendByte (head); // head
SendByte (sect); //sector number
SendByte (2); // sector size
SendByte (FD_SPT); // no. of sectors per track
SendByte (FD_GAP3RW); // length of GAP3 (0x1b)
SendByte (0xFF); // data length
while (fdd_status != FDS_IDLE);
st0 = ReadByte(); // read st0
st1 = ReadByte(); // read st1
st2 = ReadByte(); // read st2
c = ReadByte(); // read current cyl.
h = ReadByte(); // read current head
s = ReadByte(); // read current sector
ns = ReadByte(); // read sector size
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(); // stop motor from spinning
}
it prints
ST0=40;
ST1=4;
ST2=10
Cylinder = 0
Head = 0
Sector = 1
Sector Size = 2
Code: Select all
fdd_irq()
{
fdd_status=FDS_IDLE;
}
when i read the 0th sector.
any help appreciated.
Re:Reading Floppy Drive
Posted: Wed Dec 24, 2003 3:34 am
by Pype.Clicker
your "status" variable need to be declared as volatile in order to have working code.
Re:Reading Floppy Drive
Posted: Wed Dec 24, 2003 10:22 pm
by Rahman
i've declared the status variable as volatile. but, still the problem persists. could any one explain me about the steps involved in handling the interrupt after the read command.
any code appreciated.
Re:Reading Floppy Drive
Posted: Thu Dec 25, 2003 4:10 am
by Slasher
here is my floppy interrupt handler
Code: Select all
_floppy_int:
push eax
push dword [_floppy_semaphore] ;the floppy semaphore
call _wake ;wake up the first task sleeping on the semaphore
add esp,4 ;remove the parameter from the stack
mov al,0x20 ;acknowledge the interrupt to the PIC
out 0x20,al ;Master PIC
pop eax
iretd
jmp $
where do you install your floppy interrupt handler? It should be on the 6th entry of the Master PIC. So if you reprogrammed the Master PIC to start from 0x20, then the floppy Interrupt entry is at 0x26.
Re:Reading Floppy Drive
Posted: Fri Dec 26, 2003 11:40 am
by Rahman
yeah, i just wanted to know that after sending the command bytes for reading a sector, will the FDC get interrupted before reading the sector ? should i have to wait for the DMA completion after sending the command.
thank u
Re:Reading Floppy Drive
Posted: Sat Dec 27, 2003 7:45 am
by Rahman
could anyone explain me about the steps that i should follow to read a sector using non-dma mode i.e., how should i receive the data from the FDC through the interrupt handler. when i try to read data from the interrupt handler after issuing the read command, i receive only the status variables as abnormal program termination.
Re:Reading Floppy Drive
Posted: Sat Dec 27, 2003 7:10 pm
by Slasher
Non DMA transfer is Not supported by all controller. And DMA transfer is easy.
1. follow the steps for programming the DMA controller but use channel 2 as this is used by floppy
2. Get the info on programming the floppy controller and understand it properly before starting
3. initialize the floppy controller and DMA controller before you start
You can get the needed doc for the DMA and Floppy from
www.osdever.net
Re:Reading Floppy Drive
Posted: Sun Dec 28, 2003 11:08 am
by Rahman
i couldn't find the problem in my floppy driver. so, i have attached my cfloppy.c (floppy driver routines) and the cdma.c (DMA initialization coding). could any one plz. find out the problem and report it to me.
any help appreciated.
thank u.
[attachment deleted by admin]
Re:Reading Floppy Drive
Posted: Sun Dec 28, 2003 12:25 pm
by BI lazy
Well ... how about starting/stopping the floppy motor before doing a reset/recalibrate/seek/readwrite command? How should the floppy seek before the motor is started.
Second: amuse your brains and *install interrupt handlers* before you want to continue with exploring the floppy driver stuff. your code (one *can* call it this way for sure) has several busy waiting loops that make me get goosepimple. this sort of stuff is far easier to be done with interrupt handlers.
third: CodeSlashers Floppy driver tutorial should show you the basic layout of such a thing. Of course, you need some prerequisites: Interrupt handlers, timer handlers (for the delays and the waiting stuff - I f. ex. use nonbusy delays - shall others do work meanwhile)
and now, lean back. fasten your seatbelt and ... get a clue. ];->
aha ... and please learn at least one or two techniques to track down a problem to some specific point.