Floppy controller state right after boot and other questions
Posted: Sat Mar 12, 2011 12:07 am
I've recently started a hobby OS project with the goal of using as little code as possible that I did not write myself. This includes assemblers, compilers, and as much BIOS code as I can possibly do without. It's meant to hearken back, as far as possible, to the old days of hand assembling programs and punching them in on the front panel (which x86's, unfortunately, don't have). I'm writing my image files with a text editor and a Java program I wrote that reads in two characters, checks if they're both in one of the ranges 0-9 A-F a-f, and writes out a byte, as well as allowing me to define and use word-length constants (that last part is probably cheating a bit, but keeping track of pointers is a royal *pain* otherwise). I'm disassembling my code for proofreading with HTE.
(Before anyone asks: Yes, I'm five flavors of insane. I have no illusions that I'll get anywhere quickly with this project, and it's not unlikely that it will die an early death, but I'm going to try.)
The first stage of this project will be to write a bootable text editor and a bootable not-really-an-assembler that uses the same syntax as my Java program. But to make anything bootable I have to have a boot sector that loads in the rest of the program from a disk. I already have a boot sector that uses int 0x13 to read the rest of the first track and boot it, which I've used to test some other bits of code, but, of course, I'm trying not to use BIOS, so I'm working on a DMA boot sector. Since I'm pretty much coding in machine code, I'm trying to keep my code as simple as possible to economize on time and to reduce the possibility of errors.
So I have several questions about what state I'm most likely to find the floppy controller in directly after booting off a floppy and how much code I can shave off the tutorials (as well as questions about places where the tutorials argue with each other). I have the feeling that alot of these questions are going to have the answer "highly BIOS dependent", but even rules of thumb will be helpful.
My going-in assumptions:
-This code will be executing under Bochs and on a single, ten year old, physical machine.
-This code will always be loaded from the first floppy drive (drive A: / fd0)
-This code will be used on one physical disk, formatted as a standard 1.44 megabyte 3.5 inch floppy, as well as one floppy image file for Bochs.
-This code is meant to be quick and dirty. It will likely be revisited and cleaned up once I've built myself more usable tools (if I get that far). As such, the standard is "can be generally expected to work", not "best practices".
My questions:
1: Is resetting the controller necessary / advisable immediately after booting from a floppy?
2: Since BIOS has just loaded our boot code from the first sector on the disk, which is on the first cylinder, can we assume that we don't have to calibrate or seek to the first cylinder?
3: When booting from a floppy, does BIOS leave the drive motor on? I think the answer here is "no", given that I've fiddled with writing some boot sector only programs that didn't mess with the FDC at all (either directly or through int 0x13) and saw no indication of continuing drive motor activity, nor do I see no mention in the Intel datasheets that the FDC automatically times out the motors. On the other hand, given that the vast majority of bootable disks are going to be pulling data in from beyond the boot sector, I'd think it would be fairly sensible for the BIOS to leave the motors on on the assumption that they'd be used again in short order. (Of course, "I'd think it would be sensible" does not always mean "sensible", and "sensible" does not always mean "done in practice").
4: After a reset in polling mode, how many "sense interrupt" commands do I need? The Wiki says four, this tutorial seems to say one. The datasheet seems to imply that it's one for each drive on the controller, but I'm not sure if that means "one for each drive that you plan to use" or "one for each drive slot on the controller, whether you use it or not, and whether or not it actually has a drive".
5: The link the Wiki gives to the tutorial at http://forum.osdev.org/viewtopic.php?t=13538 says that it has a few tiny errors. I see a few typo's and such mentioned in the thread following the tutorial. Are there any errors *not* mentioned in the thread that I need to be aware of?
6: To wrap up all of the above and reiterate the main point of all my questions: What steps are *absolutely necessary* to bring the first track of a floppy into memory without the use of int 0x13, when the floppy in question is the boot medium, the format is known, and the computer that will be executing the code is more or less known (IE, no curveballs from hardware differences as long as Bochs doesn't throw a wrench into the works).
(Before anyone asks: Yes, I'm five flavors of insane. I have no illusions that I'll get anywhere quickly with this project, and it's not unlikely that it will die an early death, but I'm going to try.)
The first stage of this project will be to write a bootable text editor and a bootable not-really-an-assembler that uses the same syntax as my Java program. But to make anything bootable I have to have a boot sector that loads in the rest of the program from a disk. I already have a boot sector that uses int 0x13 to read the rest of the first track and boot it, which I've used to test some other bits of code, but, of course, I'm trying not to use BIOS, so I'm working on a DMA boot sector. Since I'm pretty much coding in machine code, I'm trying to keep my code as simple as possible to economize on time and to reduce the possibility of errors.
So I have several questions about what state I'm most likely to find the floppy controller in directly after booting off a floppy and how much code I can shave off the tutorials (as well as questions about places where the tutorials argue with each other). I have the feeling that alot of these questions are going to have the answer "highly BIOS dependent", but even rules of thumb will be helpful.
My going-in assumptions:
-This code will be executing under Bochs and on a single, ten year old, physical machine.
-This code will always be loaded from the first floppy drive (drive A: / fd0)
-This code will be used on one physical disk, formatted as a standard 1.44 megabyte 3.5 inch floppy, as well as one floppy image file for Bochs.
-This code is meant to be quick and dirty. It will likely be revisited and cleaned up once I've built myself more usable tools (if I get that far). As such, the standard is "can be generally expected to work", not "best practices".
My questions:
1: Is resetting the controller necessary / advisable immediately after booting from a floppy?
2: Since BIOS has just loaded our boot code from the first sector on the disk, which is on the first cylinder, can we assume that we don't have to calibrate or seek to the first cylinder?
3: When booting from a floppy, does BIOS leave the drive motor on? I think the answer here is "no", given that I've fiddled with writing some boot sector only programs that didn't mess with the FDC at all (either directly or through int 0x13) and saw no indication of continuing drive motor activity, nor do I see no mention in the Intel datasheets that the FDC automatically times out the motors. On the other hand, given that the vast majority of bootable disks are going to be pulling data in from beyond the boot sector, I'd think it would be fairly sensible for the BIOS to leave the motors on on the assumption that they'd be used again in short order. (Of course, "I'd think it would be sensible" does not always mean "sensible", and "sensible" does not always mean "done in practice").
4: After a reset in polling mode, how many "sense interrupt" commands do I need? The Wiki says four, this tutorial seems to say one. The datasheet seems to imply that it's one for each drive on the controller, but I'm not sure if that means "one for each drive that you plan to use" or "one for each drive slot on the controller, whether you use it or not, and whether or not it actually has a drive".
5: The link the Wiki gives to the tutorial at http://forum.osdev.org/viewtopic.php?t=13538 says that it has a few tiny errors. I see a few typo's and such mentioned in the thread following the tutorial. Are there any errors *not* mentioned in the thread that I need to be aware of?
6: To wrap up all of the above and reiterate the main point of all my questions: What steps are *absolutely necessary* to bring the first track of a floppy into memory without the use of int 0x13, when the floppy in question is the boot medium, the format is known, and the computer that will be executing the code is more or less known (IE, no curveballs from hardware differences as long as Bochs doesn't throw a wrench into the works).