OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 17, 2024 9:47 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: a few questions on floppy drive initialization
PostPosted: Mon Oct 19, 2020 2:46 am 
Offline
Member
Member

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 127
I was trying to initialize the floppy, following the instructions in the wiki...
after I send the lock command (0x94), I am reading back the result and
according to wiki it is supposed to be 1<<4, but I am getting 0x90... is it that the
documentation is wrong or I am doing it wrong?

Code:
  char c = (1<<6)| (1<<5)|(1<<4)|8; //polling mode off, FIFO on, implied seek on, threadhold =8
   floppy_write_cmd(0);
   
   // now lock the configuration
   floppy_write_cmd(0x94); // MT bit set + 0x14 for lock; 0x14 is unlock with lock bit turned off
   result = floppy_read_data();
   if (result !=(1<<4)){
        print(" lock command failed \n");
        print(" floppy initialization aborted \n");
        return;
   }
       


Top
 Profile  
 
 Post subject: Re: a few questions on floppy drive initialization
PostPosted: Mon Oct 19, 2020 6:28 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
ITchimp wrote:
I was trying to initialize the floppy, following the instructions in the wiki...
after I send the lock command (0x94), I am reading back the result and
according to wiki it is supposed to be 1<<4, but I am getting 0x90... is it that the
documentation is wrong or I am doing it wrong?

Code:
  char c = (1<<6)| (1<<5)|(1<<4)|8; //polling mode off, FIFO on, implied seek on, threadhold =8
   floppy_write_cmd(0);

You set 'c' to the values you wish to send to the controller, yet you still send '0'. Is this just a typo? i.e.:
Code:
  char c = (1<<6)| (1<<5)|(1<<4)|8; //polling mode off, FIFO on, implied seek on, threadhold =8
   floppy_write_cmd(c);

Also, using the LOCK command isn't very common. If you are going to reset the controller, you are most likely going to run through the process of initializing it anyway, including setting the FIFO.

I would ignore the LOCK command, but that is just my opinion.

Ben
- http://www.fysnet.net/media_storage_devices.htm


Top
 Profile  
 
 Post subject: Re: a few questions on floppy drive initialization
PostPosted: Wed Oct 21, 2020 1:29 am 
Offline
Member
Member

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 127
Thanks that was my bad for not send the c value to output port...

I have another question regarding the DOR definition

the lower 2 bits select the drive number for next access..
the top 4 bits turns the motor on...

so if I want to access the second floppy for a seeking
should I simply set the top 4 bits as 0x20, and then set lower 2 bits to 0x1
as well? can you clarify the definition of "next" in the "next access"?

another way of saying this is: if we can use the lower 2 bits to select the drive,,
then we only need 1 bit to turn it on, what is the point of having top 4 bits redundantly
select the motor????


Top
 Profile  
 
 Post subject: Re: a few questions on floppy drive initialization
PostPosted: Wed Oct 21, 2020 12:09 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5137
ITchimp wrote:
if we can use the lower 2 bits to select the drive,,
then we only need 1 bit to turn it on, what is the point of having top 4 bits redundantly
select the motor????

It's faster to copy data between two floppy drives if you leave both motors enabled, since you don't need to wait for each drive to spin up when you switch between them.


Top
 Profile  
 
 Post subject: Re: a few questions on floppy drive initialization
PostPosted: Wed Oct 21, 2020 5:51 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
As Octocontrabass states, this allows you to keep a disk spinning even though you may be accessing another drive. It was quite common back in the day for a computer to have at least two drives. (Just for fun, I happen to still have one here on one of my desks that has a 3 1/2" as well as a 5 1/4")

With all of this in mind, you will need to create a thread (or task) to watch the motors and turn them off after a couple of seconds. This is done in real mode via the Legacy BIOS. A value is decremented once per interrupt and if it reaches zero, the motor is turned off.

Once you move to protected mode (or even long mode), this service is no longer available, so you will need to do this yourself. It is actually quite simple. Take the time you wish to have a motor run after no more access, calculate the hertz a timer would be called, and decrement a value until zero. Just like the Legacy BIOS does it.

One more note about the floppy drive. If you happen to be booting from the floppy drive and move to protected mode before the BIOS has time to turn off the motor, the drive will continue to spin indefinitely. A really easy trick to make sure this doesn't happen is to set the value the BIOS uses (a byte at 0x00440) to 1 just before you move to protected mode. If it is already zero, skip the check. Here is some code I use.

Ben


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 87 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group