Floppy driver tutorial

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

Re:Floppy driver tutorial

Post by Vladaz »

Yes, I have:)
Dex4u

Re:Floppy driver tutorial

Post by Dex4u »

This is the wait for floppy int in my driver

Code: Select all

 ;----------------------------------------------------;
 ; Wait Done                 ;waits for a floppy int. ;
 ;----------------------------------------------------;

WaitDone:
mov   [Timer],30  ; 20 = about 1 second,we use (1.5 seconds).
mov   [TimerOn],1  ; start couting.
WaitDoneLoop:
mov   al,[TimerOn]  ; we test if
or    al,al                ; timeout is up yet?.
jz    WaitDoneError  ; if it is we exit,with error.
mov   ax,[done]       ; if not we check for floppt int.
or    ax,ax
jz    WaitDoneLoop ; if not do another loop.
clc                         ; we end here if we have a int:-)
ret

WaitDoneError:      ;we end up here if we run out of time:-(.
stc
ret
It is called like this:

Code: Select all

mov   [done],0  ; we need to wait
call  WaitDone  ; for floppy int.
jc    FddReadError  ; jump to error exit,if timeout.
And here is what appans whan a floppy int comes
Also Note this code go in your ISR, so when it firers, it sets [done] to 1.

Code: Select all

or    [done],1
Thats how it works, if your using C, you will need to convert it.
Vladaz

Re:Floppy driver tutorial

Post by Vladaz »

So that's just makes a thing "where to go if something happens". But how to check that floppy interrupt, when it comes and else? I mean, maybe there you have to check some port or anything else or is it enough?
Phugoid

Re:Floppy driver tutorial

Post by Phugoid »

Uh. You have to write an interrupt handler that will set the byte at "done" to use that code, as Dex4u just pointed out. You don't directly "check" for when an interrupt comes. It just comes and interrupts you. It causes the processor to drop what it's doing and execute the code in the appropriate interrupt handler. When the interrupt handler is finished, the processor resumes executing the code that was interrupted. You can think of it as subroutine that can be called by devices.
Dex4u

Re:Floppy driver tutorial

Post by Dex4u »

@Vladaz.
You miss understand the code, first the var [done] is set to 0 , when the floppy irq fires, it sets the [done] var to 1 .
We test the var [done] if its 0, we loop, if its 1 we exit with no error, if it has not fired by 1.5 seconds we exit with a timeout error.

The "or [done],1 " code goes in your floppy ISR.
Vladaz

Re:Floppy driver tutorial

Post by Vladaz »

Oh. Now I get it:) But how Floppy Interrupt can know when to fire?:)

And I have another question about the another function:
start_dma();
Any ideas?:)
Dex4u

Re:Floppy driver tutorial

Post by Dex4u »

I can not see how you have got your IDT working, but do not know about hardware int's and software int's and things like Dma, i think you should read up on these before going on with your floppy driver.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Floppy driver tutorial

Post by Candy »

Dex4u wrote: This is the wait for floppy int in my driver
What's the point of interrupt-driven programming if you're going to convert it into a polling loop?
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:Floppy driver tutorial

Post by bubach »

It's single tasking.
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
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:Floppy driver tutorial

Post by Pype.Clicker »

Vladaz wrote: Oh. Now I get it:) But how Floppy Interrupt can know when to fire?:)

And I have another question about the another function:
start_dma();
Any ideas?:)
http://www.osdev.org/osfaq2/index.php/DMA ?
dushara

Re:Floppy driver tutorial

Post by dushara »

Hi I don't know how to reply to an individual message so I'm writing here:

@ Code Slasher,

extern _floppy_int_count
_floppy_int:
inc word [_floppy_int_count]
mov al,0x20 ;acknowledge interrupt to PIC
out 0x20,al
iret


then in the C code,
Code:

unsigned short floppy_int_count=0;
void wait_floppy_interrupt()
{
while(floppy_int_count <= 0);
floppy_int_count--;
return;
}


shouldn't floppy_int_count be declared volatile?
Slasher

Re:Floppy driver tutorial

Post by Slasher »

If you want, you can declare it as volatile. Doesn't make much difference, as only used in 2 places.

Note: That code is used to show a principle. In my os, the driver actually does to sleep instead of polling.
Dex4u

Re:Floppy driver tutorial

Post by Dex4u »

Candy wrote:What's the point of interrupt-driven programming if you're going to convert it into a polling loop?
Yes i was waiting for someone to point this out ;D .
As bubach said it single tasking. but maybe if we add multi-threading support, we may rethink this.
Vladaz

Re:Floppy driver tutorial

Post by Vladaz »

And actually, I'm now searching for the information about making the functions usleep() or sleep(). I will appreciate any good ideas. Or maybe even source code:)
Phugoid

Re:Floppy driver tutorial

Post by Phugoid »

Hi,

I've got two good ideas:
1. Tell us what sleep and usleep are supposed to do.
2. Come up with the solution completely on your own without asking for source code, and learn from it.
Post Reply