Page 1 of 1

Floppy driver

Posted: Wed Nov 26, 2008 5:18 am
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).

Re: Floppy driver

Posted: Wed Nov 26, 2008 5:41 am
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

Re: Floppy driver

Posted: Wed Nov 26, 2008 6:53 am
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

Re: Floppy driver

Posted: Wed Nov 26, 2008 7:13 am
by Love4Boobies
Why not use EDD (Enhanced Disk Drive) services, so you can use LBA instead of CHS?

Re: Floppy driver

Posted: Wed Nov 26, 2008 7:20 am
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

Re: Floppy driver

Posted: Wed Nov 26, 2008 7:30 am
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

Re: Floppy driver

Posted: Wed Nov 26, 2008 7:45 am
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.

Re: Floppy driver

Posted: Wed Nov 26, 2008 8:25 am
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

Re: Floppy driver

Posted: Wed Nov 26, 2008 9:32 am
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?

Re: Floppy driver

Posted: Wed Nov 26, 2008 10:07 am
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.

Re: Floppy driver

Posted: Wed Nov 26, 2008 10:46 am
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