Load second bootloader - best way

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
Merdini
Member
Member
Posts: 34
Joined: Fri May 04, 2007 10:11 pm
Location: Sweden, Gothenburg

Load second bootloader - best way

Post by Merdini »

Im currently loading my second bootloader via int 13, searching for the second file in the fat.
Is there other ways to do this? A more simple and faster way?
Second file is loaded into 07C0:0200 . Can i address the second file directly instead of searching for it?

Can i write the second file to the second sector on the floppydisk just the same way i do with the bootloader?
And access the second file through the bootloader more easily?
Thanks
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Load second bootloader - best way

Post by Brendan »

Hi,
Kurdistan wrote:Im currently loading my second bootloader via int 13, searching for the second file in the fat.
Is there other ways to do this? A more simple and faster way?
Second file is loaded into 07C0:0200 . Can i address the second file directly instead of searching for it?
When you create the file system, you could make sure that the second file is contiguous (not fragmented), mark it as a "system" file (to try to prevent other utilities from moving it) and store the starting sector and length of it in the first boot loader's sector.
Kurdistan wrote:Can i write the second file to the second sector on the floppydisk just the same way i do with the bootloader?
And access the second file through the bootloader more easily?
That's possible too - there's a "number of hidden sectors" field that is normally 1, but could be increased so that more sectors are hidden/reserved for boot code. However, I'm not too sure if all implementations of FAT support this properly (some implementation might assume that there's 1 hidden sector without checking).

The third option is: stop using FAT.

When your OS is booting from a (real or emulated) hard drive, FAT is crap because there's partition size limits, file size limits, no usable file permissions, etc. In this case it's better to use a good file system (e.g. ext2/3/4) or to invent your own; and if you do invent your own you can (for e.g.) say "the first N sectors are reserved for boot code" and worry about everything else much later on.

When your OS is booting from a (real or emulated) floppy disk you'll be lucky if your kernel (and boot code, etc) fit, and it's very unlikely that there will be free space for anyone to store any other files on the floppy. In this case using FAT just makes things more complicated, wastes disk space and slows down boot (due to avoidable disk seeks, etc), and it's better to just use raw sectors.

When your OS is booting from CD with "no emulation" you have to use ISO9660 (or an extension of ISO9660). You don't get too much choice.

Basically, there are no sane reasons (that I'm aware of) to use FAT for any type of boot disk. I'd even go one step further and say that the only sane reason to use FAT for anything is transferring files between different OSs and devices (if some sort of networking isn't an option).


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.
Merdini
Member
Member
Posts: 34
Joined: Fri May 04, 2007 10:11 pm
Location: Sweden, Gothenburg

Re: Load second bootloader - best way

Post by Merdini »

Thanks for your answer!

Actually, i have no reason using FAT, im new to osdev, might be the reason.
From now on, i'll be skipping the bpb headers.

How do i copy the second file via partcopy? Lets say the other file is 512bytes aswell.
i've tried:
pcopy bl.bin 200 200 -f0
Shouldn't that be the second sector?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Load second bootloader - best way

Post by Brendan »

Hi,
Kurdistan wrote:Actually, i have no reason using FAT, im new to osdev, might be the reason.
From now on, i'll be skipping the bpb headers.
The BPB headers should probably be included for floppy disks (even floppy disks that don't use FAT), as most (all?) versions of Windows use the BPB to determine how many heads, sectors and cylinders the floppy disk has and will think the disk is unusable/corrupt if it's not present (which prevents the user from formatting it and reusing it, unless they've got another OS that doesn't rely on the BPB to determine the floppy format).
Kurdistan wrote:How do i copy the second file via partcopy?
I've never used partcopy...

I normally create a floppy image using NASM (e.g. with "incbin", "times", etc) or write a utility to create floppy images; and then copy the image to a disk (e.g. "cp floppy.img /dev/fd0" on Linux) or use the image directly in emulators.


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.
neato
Member
Member
Posts: 75
Joined: Fri Jan 15, 2010 2:46 am

Re: Load second bootloader - best way

Post by neato »

That is what I do: incbin
Merdini
Member
Member
Posts: 34
Joined: Fri May 04, 2007 10:11 pm
Location: Sweden, Gothenburg

Re: Load second bootloader - best way

Post by Merdini »

Thanks again for the answers.

You can still write to the sectors with partcopy even if you dont have the BPB headers.
So there seems to be no problem with it when using msdos.
This is still temporary, i'll be using 2 floppy disks for my OS. I got 2 floppy drives.

How can i just copy the file to the disk and find the starting sector for the file?
I dont want to search for the file, because of the search time.
Instead i want to refer to a sector on the disk (that i already have chosen for the second file).

I will simple use int 13, but my problem is to copy the file to the desired sector. Copying the file manually to the disk will not make sure that the file gets the same sector each time, right?
My code wont be dynamically, i will always use the same sectors for each of my files.

Thanks
Merdini
Member
Member
Posts: 34
Joined: Fri May 04, 2007 10:11 pm
Location: Sweden, Gothenburg

Re: Load second bootloader - best way

Post by Merdini »

Found it!

pcopy bl.bin 0 200 -f0 200
where the bolded is the destination.
This writes 512bytes to the second sector on the floppy.
Post Reply