OSDev.org
https://forum.osdev.org/

a few questions on floppy drive initialization
https://forum.osdev.org/viewtopic.php?f=1&t=37368
Page 1 of 1

Author:  ITchimp [ Mon Oct 19, 2020 2:46 am ]
Post subject:  a few questions on floppy drive initialization

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;
   }
       

Author:  BenLunt [ Mon Oct 19, 2020 6:28 pm ]
Post subject:  Re: a few questions on floppy drive initialization

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

Author:  ITchimp [ Wed Oct 21, 2020 1:29 am ]
Post subject:  Re: a few questions on floppy drive initialization

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????

Author:  Octocontrabass [ Wed Oct 21, 2020 12:09 pm ]
Post subject:  Re: a few questions on floppy drive initialization

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.

Author:  BenLunt [ Wed Oct 21, 2020 5:51 pm ]
Post subject:  Re: a few questions on floppy drive initialization

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

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/