Floppy driver
- Khaoticmind
- Member
- Posts: 29
- Joined: Tue Nov 18, 2008 1:06 pm
- Location: Brazil
Floppy driver
Hey guys,
I'm starting on OS development and right now i'm trying to right a driver to read some data from the floppy*.
I've got the 82077AA datasheet and have read the Floppy_Disk_Controller wiki here.
So... my doubt, when reading data we need to pass the cylinder, sector and head to the controller. I know how to get the sector number from the cluster on the FAT, but how does it map to heads/cylinder/sector of the disk geometry?
Thanks for any help!
*Actually I'm writing a bootloader. And to load my kernel I will read it from a FAT12 floppy. I don't want to use the BIOS to read the floppy for me (trying to make everything independent from the BIOS).
I'm starting on OS development and right now i'm trying to right a driver to read some data from the floppy*.
I've got the 82077AA datasheet and have read the Floppy_Disk_Controller wiki here.
So... my doubt, when reading data we need to pass the cylinder, sector and head to the controller. I know how to get the sector number from the cluster on the FAT, but how does it map to heads/cylinder/sector of the disk geometry?
Thanks for any help!
*Actually I'm writing a bootloader. And to load my kernel I will read it from a FAT12 floppy. I don't want to use the BIOS to read the floppy for me (trying to make everything independent from the BIOS).
Re: Floppy driver
Hi,
Trying to make everything independent from the BIOS is a good idea. The best way to do that would be to use several BIOS/firmware specific boot loaders that all load any files needed and configure the computer into the same state; and then a have "boot loader independent" second stage or kernel or whatever that's started by the boot loader.
Cheers,
Brendan
That's not necessarily a good reason - you rely on the BIOS to load your boot loader into memory to begin with, and I doubt you'll be able to fit a floppy driver and FAT support code into 512 bytes (and even if you do manage to fit it all in, the code will be crap - no error handling, etc). You'll also lose support for bootable CD-ROMs and USB flash devices (a normal floppy boot loader would be able to use the "emulated floppy" option).Khaoticmind wrote:*Actually I'm writing a bootloader. And to load my kernel I will read it from a FAT12 floppy. I don't want to use the BIOS to read the floppy for me (trying to make everything independent from the BIOS).
Trying to make everything independent from the BIOS is a good idea. The best way to do that would be to use several BIOS/firmware specific boot loaders that all load any files needed and configure the computer into the same state; and then a have "boot loader independent" second stage or kernel or whatever that's started by the boot loader.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
- Khaoticmind
- Member
- Posts: 29
- Joined: Tue Nov 18, 2008 1:06 pm
- Location: Brazil
Re: Floppy driver
Thanks for the tip Brendan, I had this issue in mind already. I might use int13 simply because it's simpler , and i can continue with my development quicker, and worry about a floppy driver later, with other tools at hand.
But even int13 requires the CHS to be defined. I can do a direct map of it?
I mean... if in the FAT i get the cluster i want is in sector 100, that would mean its in Head 0, Track 5, Sector 10?
So Head 1 would be only used when the sector would be greater than 1440 (18 sectors * 80 tracks)?
thanks,
KM
But even int13 requires the CHS to be defined. I can do a direct map of it?
I mean... if in the FAT i get the cluster i want is in sector 100, that would mean its in Head 0, Track 5, Sector 10?
So Head 1 would be only used when the sector would be greater than 1440 (18 sectors * 80 tracks)?
thanks,
KM
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Floppy driver
Why not use EDD (Enhanced Disk Drive) services, so you can use LBA instead of CHS?
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
Re: Floppy driver
Hi,
You might also like to see this source code, which is my code to load a variable number of sectors from an LBA address using the BIOS (which includes full error handling, and supports all possible floppy disk formats by using values from the BPB).
@Love4Boobies: EDD isn't supported on old computers and may not support floppy on newer computers.
Cheers,
Brendan
You'd want to convert LBA addresses (Logical Block Addressing) into the BIOS's CHS addressing (Cylinder, Header, Sector). Here's some information on how to do the conversion.Khaoticmind wrote:But even int13 requires the CHS to be defined. I can do a direct map of it?
You might also like to see this source code, which is my code to load a variable number of sectors from an LBA address using the BIOS (which includes full error handling, and supports all possible floppy disk formats by using values from the BPB).
@Love4Boobies: EDD isn't supported on old computers and may not support floppy on newer computers.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
- Khaoticmind
- Member
- Posts: 29
- Joined: Tue Nov 18, 2008 1:06 pm
- Location: Brazil
Re: Floppy driver
Mainly because i didn't even know they existedLove4Boobies wrote:Why not use EDD (Enhanced Disk Drive) services, so you can use LBA instead of CHS?
That looks good, but that's a standard BIOS thing? How widely is it used/implemented? Specially in bootsector code?
Also, I've looked at MikeOS and found that my initial assumptions is exactly what it does, in bootload.asm it reads
Code: Select all
l2hts: ; Calculate head, track and sector settings for int 13h
; IN: logical sector in AX, OUT: correct registers for int 13h
push bx
push ax
mov bx, ax ; Save logical sector
xor dx, dx ; First the sector
div word [SectorsPerTrack]
add dl, 01h ; Physical sectors start at 1
mov cl, dl ; Sectors belong in CL for int 13h
mov ax, bx
xor dx, dx ; Now calculate the head
div word [SectorsPerTrack]
xor dx, dx
div word [Sides]
mov dh, dl ; Head/side
mov ch, al ; Track
pop ax
pop bx
mov dl, byte [bootdev] ; Set correct device
ret
Code: Select all
xor dx, dx ; Now calculate the head
div word [SectorsPerTrack]
Thanks and cheers,
KM
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Floppy driver
All modern BIOSes have it. And by modern I also mean kind of old too The fact is that with CHS you can only get up to 8.4 GiB.
EDIT: btw, for anyone interested, I found out looking through t13's docs that they're planning to make an EDD 4.0 spec sometime soon.
EDIT: btw, for anyone interested, I found out looking through t13's docs that they're planning to make an EDD 4.0 spec sometime soon.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
Re: Floppy driver
Hi,
Cheers,
Brendan
Do you have a 8.4 GiB floppy disk?Love4Boobies wrote:All modern BIOSes have it. And by modern I also mean kind of old too The fact is that with CHS you can only get up to 8.4 GiB.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
- Khaoticmind
- Member
- Posts: 29
- Joined: Tue Nov 18, 2008 1:06 pm
- Location: Brazil
Re: Floppy driver
I thought EDD worked with Hard Disks as well, and not only floppies...Brendan wrote:Hi,
Do you have a 8.4 GiB floppy disk?Love4Boobies wrote:All modern BIOSes have it. And by modern I also mean kind of old too The fact is that with CHS you can only get up to 8.4 GiB.
@brendan: you mean future BIOSes may drop support for floppies or that maybe current computers doesn't support it?
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Floppy driver
Well, most computers you buy today don't have floppy drives anymore.
Yes. But it's not very floppy. It's called a hard disk.Brendan wrote:Hi,
Do you have a 8.4 GiB floppy disk?Love4Boobies wrote:All modern BIOSes have it. And by modern I also mean kind of old too The fact is that with CHS you can only get up to 8.4 GiB.
Cheers,
Brendan
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
Re: Floppy driver
If you still want to write your own floppy driver, here is a demo i writen of a pmode floppy driver that may help
http://dex4u.com/demos/FddDemo.zip
http://dex4u.com/demos/FddDemo.zip