Page 1 of 2
Floppy Image File Setup / Load Sector
Posted: Sat Mar 05, 2005 11:34 pm
by Cjmovie
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.
Re:Floppy Image File Setup / Load Sector
Posted: Sat Mar 05, 2005 11:51 pm
by AR
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.
Re:Floppy Image File Setup / Load Sector
Posted: Sun Mar 06, 2005 1:58 pm
by Cjmovie
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
Re:Floppy Image File Setup / Load Sector
Posted: Tue Mar 08, 2005 1:40 am
by Brendan
Hi,
Cjmovie wrote:Well, the idea is also that I DON'T WANT to use FAT12.
I don't want my OS restricted to Microsoft's worst file system either
.
Cjmovie wrote:
And, the code is just like I said, the basics for loading to 01000h es:bx and 0Fh sectors, as below:
You've got the right idea
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?).
I just load one sector at a time (and copy each sector above 1 Mb using unreal mode) - it's slower but it means I don't have to worry about half of the above.
Cheers,
Brendan
Re:Floppy Image File Setup / Load Sector
Posted: Tue Mar 08, 2005 2:03 am
by Candy
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.
Sounds bad. What if just the floppy is dead and you have a spare one beside it? Still wreck the drive?
Re:Floppy Image File Setup / Load Sector
Posted: Tue Mar 08, 2005 2:26 am
by Brendan
Hi,
Candy wrote: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.
Sounds bad. What if just the floppy is dead and you have a spare one beside it? Still wreck the drive?
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.
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
Re:Floppy Image File Setup / Load Sector
Posted: Tue Mar 08, 2005 5:28 am
by Red Shaya
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.
Re:Floppy Image File Setup / Load Sector
Posted: Tue Mar 08, 2005 7:04 am
by aladdin
I don't want my OS restricted to Microsoft's worst file system either
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 floppy
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
Posted: Tue Mar 08, 2005 8:05 am
by Brendan
Hi,
aladdin wrote:
I don't want my OS restricted to Microsoft's worst file system either
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 floppy
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.
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.
aladdin wrote:also it is really useless to spend your time thinking about a new floppy filesystem since floppies are no more used ...
Which file system do you intend using for hard drives? Why not use the same file system for floppies too?
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
Re:Floppy Image File Setup / Load Sector
Posted: Tue Mar 08, 2005 9:28 am
by Pype.Clicker
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.
Re:Floppy Image File Setup / Load Sector
Posted: Thu Mar 10, 2005 7:57 pm
by Cjmovie
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.
Re:Floppy Image File Setup / Load Sector
Posted: Thu Mar 10, 2005 9:58 pm
by B.E
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
What drive number are use using. I mean your not setting the drive number (DL).
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
Posted: Sun Mar 13, 2005 12:19 am
by Cjmovie
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?
Re:Floppy Image File Setup / Load Sector
Posted: Sun Mar 13, 2005 12:38 am
by AR
I stated that above, all sectors in the cylinder, change heads, read the cylinder again, proceed to next cylinder using first head.
Re:Floppy Image File Setup / Load Sector
Posted: Sun Mar 13, 2005 1:48 am
by Cjmovie
Lol, thx.