Hi,
b.zaar wrote:Ok, I think I see a good progression of this project to satisfy most of the people interested in contributing. Firstly the base system would be a simple boot loader, it can be installed to the MBR for a single OS install or it can be installed to the VBR of the OSes partition and be chain loaded from a non conforming (GANDALF boot standard) boot manager.
That sounds good to me.
b.zaar wrote:The base system would include a simple library like PDClib.
A quick checklist:
- Does the boot loader need signals and signal handling?
- Does it need floating point (or complex numbers) for anything?
- Does it need setjmp/longjmp?
- Does fork()/exec() make any sense?
- Are time and date functions (and "sleep()") needed?
- How about localisation?
- Is support for wide characters needed?
This might only really leave file IO, heap and some string functions (strlen(), memcpy(), etc). For heap, UEFI firmware provides it (but it may need to be a little different as you may need to say what the memory is being allocated for) and for PC BIOS by the time you get through memory detection you'll probably have 90% of memory management done anyway (e.g. code to change the type of an arbitrary area in the memory map from one type into a different type - e.g. from "unknown" to "ACPI NVS", or from "usable RAM" to "allocated").
For file IO; directory handling can't work in some environments (e.g. when booting from network - TFTP simply doesn't support it) and writing to files can't work in some environments (CD-ROM). For simplicity, I wouldn't bother allowing directories to be read or created, and wouldn't support "stat()", and wouldn't support writing to files. I'd also use fixed file names, where the name/s of file/s are set when the boot loader is installed, because it's the only thing that makes sense when you can't read directories.
Of course you probably only need to read a maximum of 3 files - the OS's next piece of code (e.g. the kernel), an optional extra file (e.g. containing an initrd or boot image or something), and an optional something containing arbitrary data for the OS (e.g. kernel command line or whatever).
Note: the OS's next piece of code might not be a kernel. For example, the initrd or boot image might contains 5 kernels, and the "OS's next piece of code" might be something to determine which of those kernels to start. The only thing a generic boot loader would need to know is that the "OS's next piece of code" is OS dependant and could be anything.
Now; if you're only loading a maximum of 3 files; excluding booting from network and CD-ROM, is it necessary to have file names when booting from hard drive or floppy? If people are willing to use something like "starting LBA and length" instead, then the need to support arbitrary file systems disappears (and a whole layer of pain/complexity disappears with it). This would mean that the files couldn't be fragmented (but that shouldn't be a problem and you could use "list of extents" instead if it is a problem). It would also mean that an OS would need to update the boot loader if the files are changed (but that is extremely easy due to "KISS"). What I'm suggesting here is that the advantages of supporting arbitrary file systems is "almost nothing" and the disadvantages (complexity/bloat) aren't justified.
I'd also point out (for the benefit of those people that simply assume something is good if Linux does it), that this is how the native boot loader for Linux (LILO) works. There's a utility (also called LILO) that installs the boot loader and creates a list of extents, and the boot loader simply loads sectors from that list of extents (with no knowledge of any file system needed).
Note: GRUB is not the native boot loader for Linux - it's something that came alone much later, that tried to slaughter the boot loaders for many different OS's using a devastating weapon called "over engineering" (and sadly, succeeded in several cases).
So; getting back to C libraries, does the boot loader need anything more than "string.h", and is it worth bothering with a C library if a few loops are enough? Don't forget that the UEFI API is a pain (that doesn't use normal C calling conventions and requires special wrappers that are typically implemented in inline assembly), and that (for PC BIOS) most C compilers that people would want to use (GCC, clang/LLVM) don't support 16-bit/real mode code in the first place.
b.zaar wrote:In this mode the boot loader loads only the single OS reading from a text configuration file for any boot options. The boot loader would configure the system to run in flat 32 bit pmode with a structure of the systems configuration in the GANDALF boot standard format. The boot loader requires executable file support (ELF/DWARF), as external modules, to be able to load the kernel. When the system is in a set mode it loads and executes it's first module or kernel file.
Is ELF necessary? Dynamic linking doesn't make any sense and I doubt anyone wants to use relocatable code, the section attributes will probably be ignored and you wouldn't want arbitrary sections at arbitrary addresses. I don't see any point requiring ELF for OS's that are hopefully not boring *nix clones (and therefore don't necessarily comply with the "UNIX System V" specifications, which includes the ELF file format). Just assume "flat binary" - it's easier and can work for ELF, PE, something designed for the OS itself, etc.
b.zaar wrote:Then any boot loader extensions, scripting support, VBE support, Boot Manager support and conforming kernels would all be seen as modules to the boot loader. The boot loader remains resident and loads and runs the modules in order until it never returns to the boot loader as a boot manager or kernel has taken over control of the system. None of these extension are necessary to load any conforming kernel, they are there just to add functionality before the kernel is loaded and is controlling the PC. Any OS may choose not to include then in the primary installion of the boot loader.
I still don't think there's any need for any scripting languages. Slap some sort of data structure in the first module's "GANDALF header" and use fields in that data structure to control the boot loader. For example, you might have a few fields in this header that are used by the boot loader to determine which video modes are acceptable, a field for the entry point, and one more field in case I forgot something. If the OS needs a scripting language (for generating dynamic HTML pages or something?), then the OS's first module can be a script interpreter, or the OS project can fork the boot loader and add whatever features it likes.
Cheers,
Brendan