Floppy Image File Setup / Load Sector
Floppy Image File Setup / Load Sector
My question is twofold:
First of all, how is a floppy image file setup? What I mean is, I create a floppy image using a program that directly creates it by writing 512 bytes for bootloader then however many sectors for kernel. The thing is, I can't seem to figure out how to know what sector/cylinder/head they are situated on.
Also, (I know this is REALLY basic) I can't seem to find a bootloader that literally reads so many sectors starting at the second one, without the fancy FAT12 etc., so I made this one on my own (mostly...small bits copied), and I can't seem to load more than 2 sectors, causing bochs to give the error "running in bogus memory". I am just simply doing the minimum setup for INT 13h, calling it with 0Fh sectors to read, load to 01000h.
First of all, how is a floppy image file setup? What I mean is, I create a floppy image using a program that directly creates it by writing 512 bytes for bootloader then however many sectors for kernel. The thing is, I can't seem to figure out how to know what sector/cylinder/head they are situated on.
Also, (I know this is REALLY basic) I can't seem to find a bootloader that literally reads so many sectors starting at the second one, without the fancy FAT12 etc., so I made this one on my own (mostly...small bits copied), and I can't seem to load more than 2 sectors, causing bochs to give the error "running in bogus memory". I am just simply doing the minimum setup for INT 13h, calling it with 0Fh sectors to read, load to 01000h.
Re:Floppy Image File Setup / Load Sector
It's impossible to diagnose what's going wrong, especially given the amount of things that can go wrong, without seeing the code.
Floppies go like this basically:
1-18 = Cylinder 0, Head 0
19-36 = Cylinder 0, Head 1
37-54 = Cylinder 1, Head 0
55-72 = Cylinder 1, Head 1
And so on
If you don't want to implement the FAT12 support yourself then you can use GRUB to do it for you as well.
Floppies go like this basically:
1-18 = Cylinder 0, Head 0
19-36 = Cylinder 0, Head 1
37-54 = Cylinder 1, Head 0
55-72 = Cylinder 1, Head 1
And so on
If you don't want to implement the FAT12 support yourself then you can use GRUB to do it for you as well.
Re:Floppy Image File Setup / Load Sector
Well, the idea is also that I DON'T WANT to use FAT12.
And, the code is just like I said, the basics for loading to 01000h es:bx and 0Fh sectors, as below:
And, the code is just like I said, the basics for loading to 01000h es:bx and 0Fh sectors, as below:
Code: Select all
reset_drive:
mov ah, 0
int 13h
or ah, ah
jnz reset_drive
mov ax, 0
mov es, ax
mov bx, 0x1000
mov ah, 02h
mov al, 0Fh
mov ch, 0
mov cl, 02h
mov dh, 0
int 13h
or ah, ah
jnz reset_drive
Re:Floppy Image File Setup / Load Sector
Hi,
There are a couple notes though:
Cheers,
Brendan
I don't want my OS restricted to Microsoft's worst file system either .Cjmovie wrote:Well, the idea is also that I DON'T WANT to use FAT12.
You've got the right ideaCjmovie wrote: And, the code is just like I said, the basics for loading to 01000h es:bx and 0Fh sectors, as below:
There are a couple notes though:
- AFAIK not all BIOSs can transfer floppy data across 64 Kb boundary (same restrictions as ISA DMA).
Before you can load more than one track you need to tell the BIOS how many sectors there are per track (I think it's: http://www.ctyme.com/intr/rb-0643.htm).
If a floppy function fails you should retry 3 (or more) times - your code already does this, although like Linux's old boot code if someone starts the boot and walks away it could keep trying until the floppy drive melts a few days later.
You could keep the "device number" (passed by the BIOS to the boot sector in DL) and use that when reading, etc - not sure if you do this already or not. This is optional, and allows boot loaders (e.g. LILO, GRUB, etc) to load your OS from a second floppy drive (or something else?).
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.
Re:Floppy Image File Setup / Load Sector
Sounds bad. What if just the floppy is dead and you have a spare one beside it? Still wreck the drive?Brendan wrote: If a floppy function fails you should retry 3 (or more) times - your code already does this, although like Linux's old boot code if someone starts the boot and walks away it could keep trying until the floppy drive melts a few days later.
Re:Floppy Image File Setup / Load Sector
Hi,
IMHO good boot code should retry between 3 and 6 times and then display an error message - something generic like "File IO Error - Boot aborted" (or if you've got time and space a more detailed error message like "ERROR: Failed to find address mark at sector 1234, boot aborted").
Infinite retries (like Linux's old boot code) is a bug.
Cheers,
Brendan
If someone boots the OS and waits to see if it works then it shouldn't matter. If they assume it works and don't wait it could be a disaster.Candy wrote:Sounds bad. What if just the floppy is dead and you have a spare one beside it? Still wreck the drive?Brendan wrote:If a floppy function fails you should retry 3 (or more) times - your code already does this, although like Linux's old boot code if someone starts the boot and walks away it could keep trying until the floppy drive melts a few days later.
IMHO good boot code should retry between 3 and 6 times and then display an error message - something generic like "File IO Error - Boot aborted" (or if you've got time and space a more detailed error message like "ERROR: Failed to find address mark at sector 1234, boot aborted").
Infinite retries (like Linux's old boot code) is a bug.
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.
Re:Floppy Image File Setup / Load Sector
What's the error code you get in AH?
that might give us a clue about the problem.
And I join the people here about avoiding an endless loop if the read fails.
that might give us a clue about the problem.
And I join the people here about avoiding an endless loop if the read fails.
Re:Floppy Image File Setup / Load Sector
i'm also an any Micro$oft, but IMO, fat12 is the best filesystem for floppy disks, since it is very simple, and you don't need big performances while reading/writing a floppyI don't want my OS restricted to Microsoft's worst file system either
also it is really useless to spend your time thinking about a new floppy filesystem since floppies are no more used ...
;D
Re:Floppy Image File Setup / Load Sector
Hi,
For the purpose of booting an OS from floppy I wouldn't really bother with any file system - for e.g. my OS uses the first 2 sectors as the "boot sector" which is immediately followed by N sectors for the boot image. This gives highest possible performance as it's read track by track without reading any additonal baggage. As an added bonus you get a nice steady "tick....tick...tick" as it loads rather than the rattle & grind I associate with windows startup disks.
BTW floppies have been "no more used" for the last 5 years, but I still can't buy a desktop computer without one and still use them regularly. If manufacturers stopped producing desktop computers with floppy drives today it'd take another 10 years before most people didn't have one. Then there's still the "emulated floppies" used on boot CDs..
Cheers,
Brendan
I'd agree that FAT12 may be adequate for floppies in general, but the lack of file permissions and other features makes it unsuitable for storing files for my OS.aladdin wrote:i'm also an any Micro$oft, but IMO, fat12 is the best filesystem for floppy disks, since it is very simple, and you don't need big performances while reading/writing a floppyI don't want my OS restricted to Microsoft's worst file system either
For the purpose of booting an OS from floppy I wouldn't really bother with any file system - for e.g. my OS uses the first 2 sectors as the "boot sector" which is immediately followed by N sectors for the boot image. This gives highest possible performance as it's read track by track without reading any additonal baggage. As an added bonus you get a nice steady "tick....tick...tick" as it loads rather than the rattle & grind I associate with windows startup disks.
Which file system do you intend using for hard drives? Why not use the same file system for floppies too?aladdin wrote:also it is really useless to spend your time thinking about a new floppy filesystem since floppies are no more used ...
BTW floppies have been "no more used" for the last 5 years, but I still can't buy a desktop computer without one and still use them regularly. If manufacturers stopped producing desktop computers with floppy drives today it'd take another 10 years before most people didn't have one. Then there's still the "emulated floppies" used on boot CDs..
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.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Floppy Image File Setup / Load Sector
sure, FAT suxx ... and it is patented, too ...
That being said, you can have your kernel image in the "reserved" sectors of a FAT disk. Just think about the following scenario:
- myOs system is down. I need a repair disk which contains kernel plus parameters such as nameserver, country code, etc.
- unfortunately, all the repair disks for myOs are damaged ::) i need to download one.
- i only have an UglyOs system at hand to download and i unfortunately didn't port tools to edit repair disks configuration to UglyOs ...
If repair disks were FAT-formatted, i could use any text/hex editor to patch the configuration files. but i'm stuck ...
Honestly, floppies aren't meant to _store_ files anymore, but they're the last-chance for file _exchanges_. You need to store additionnal properties ? fine. write them down in an XML file. You need user Z not to access data on your floppy ? fine. don't give Z your floppy.
That being said, you can have your kernel image in the "reserved" sectors of a FAT disk. Just think about the following scenario:
- myOs system is down. I need a repair disk which contains kernel plus parameters such as nameserver, country code, etc.
- unfortunately, all the repair disks for myOs are damaged ::) i need to download one.
- i only have an UglyOs system at hand to download and i unfortunately didn't port tools to edit repair disks configuration to UglyOs ...
If repair disks were FAT-formatted, i could use any text/hex editor to patch the configuration files. but i'm stuck ...
Honestly, floppies aren't meant to _store_ files anymore, but they're the last-chance for file _exchanges_. You need to store additionnal properties ? fine. write them down in an XML file. You need user Z not to access data on your floppy ? fine. don't give Z your floppy.
Re:Floppy Image File Setup / Load Sector
Been away :).
As for the error in AH, there isn't one....(duh?) Otherwords bochs would never get to stop the infinite loop, therefore never jumping to the erronous part of memory.
As for the error in AH, there isn't one....(duh?) Otherwords bochs would never get to stop the infinite loop, therefore never jumping to the erronous part of memory.
Re:Floppy Image File Setup / Load Sector
What drive number are use using. I mean your not setting the drive number (DL).Cjmovie wrote: Well, the idea is also that I DON'T WANT to use FAT12.
And, the code is just like I said, the basics for loading to 01000h es:bx and 0Fh sectors, as below:
Code: Select all
reset_drive: mov ah, 0 int 13h or ah, ah jnz reset_drive mov ax, 0 mov es, ax mov bx, 0x1000 mov ah, 02h mov al, 0Fh mov ch, 0 mov cl, 02h mov dh, 0 int 13h or ah, ah jnz reset_drive
Your original question about sector/cylinder/head. It's easy you must convert LBA (Logical Block address) to CHS(cylinder, head,sector)
Re:Floppy Image File Setup / Load Sector
But there are more than one LBA/CHS algorithams, and I don't know which one floppy images use.
I mean, does it do all of one head, then the second?
Or does it switch heads each time?
Or does it do all the sectors in a cylinder, switch head, and go again?
I mean, what LBA to CHS algoritham is a floppy image based on?
I mean, does it do all of one head, then the second?
Or does it switch heads each time?
Or does it do all the sectors in a cylinder, switch head, and go again?
I mean, what LBA to CHS algoritham is a floppy image based on?
Re:Floppy Image File Setup / Load Sector
I stated that above, all sectors in the cylinder, change heads, read the cylinder again, proceed to next cylinder using first head.