Floppy driver

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.
Post Reply
User avatar
Khaoticmind
Member
Member
Posts: 29
Joined: Tue Nov 18, 2008 1:06 pm
Location: Brazil

Floppy driver

Post by Khaoticmind »

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).
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Floppy driver

Post by Brendan »

Hi,
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).
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).

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.
User avatar
Khaoticmind
Member
Member
Posts: 29
Joined: Tue Nov 18, 2008 1:06 pm
Location: Brazil

Re: Floppy driver

Post by Khaoticmind »

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
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Floppy driver

Post by Love4Boobies »

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 ]
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Floppy driver

Post by Brendan »

Hi,
Khaoticmind wrote:But even int13 requires the CHS to be defined. I can do a direct map of it?
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.

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.
User avatar
Khaoticmind
Member
Member
Posts: 29
Joined: Tue Nov 18, 2008 1:06 pm
Location: Brazil

Re: Floppy driver

Post by Khaoticmind »

Love4Boobies wrote:Why not use EDD (Enhanced Disk Drive) services, so you can use LBA instead of CHS?
Mainly because i didn't even know they existed :mrgreen:
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
I just don't get why it does

Code: Select all

	xor dx, dx			; Now calculate the head
	div word [SectorsPerTrack]
before calculating the head value...

Thanks and cheers,
KM
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Floppy driver

Post by Love4Boobies »

All modern BIOSes have it. And by modern I also mean kind of old too :D 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.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Floppy driver

Post by Brendan »

Hi,
Love4Boobies wrote:All modern BIOSes have it. And by modern I also mean kind of old too :D The fact is that with CHS you can only get up to 8.4 GiB.
Do you have a 8.4 GiB floppy disk? ;)


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.
User avatar
Khaoticmind
Member
Member
Posts: 29
Joined: Tue Nov 18, 2008 1:06 pm
Location: Brazil

Re: Floppy driver

Post by Khaoticmind »

Brendan wrote:Hi,
Love4Boobies wrote:All modern BIOSes have it. And by modern I also mean kind of old too :D The fact is that with CHS you can only get up to 8.4 GiB.
Do you have a 8.4 GiB floppy disk? ;)
I thought EDD worked with Hard Disks as well, and not only floppies...

@brendan: you mean future BIOSes may drop support for floppies or that maybe current computers doesn't support it?
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Floppy driver

Post by Love4Boobies »

Well, most computers you buy today don't have floppy drives anymore.
Brendan wrote:Hi,
Love4Boobies wrote:All modern BIOSes have it. And by modern I also mean kind of old too :D The fact is that with CHS you can only get up to 8.4 GiB.
Do you have a 8.4 GiB floppy disk? ;)


Cheers,

Brendan
Yes. But it's not very floppy. It's called a hard disk.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: Floppy driver

Post by Dex »

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
Post Reply