Multiboot overhaul
Hi.
I'm working on a microkernel for x86_64 (with looking forward to ppc64
and sparc64 ports). As you know, microkernels are quite useless without
user-space servers that provide "classic" OS services. But microkernels
are so useless that they even cannot load servers from disk :). That's
why bootloader need to load servers images directly into memory in
addition to image of microkernel itself. For i386-pc we have multiboot
and it "just works". But it's really too i386-pc-specific. We also have draft of next multiboot version, but I think it still lacks flexibility (e.g. single 'flags' field for all image format, platform, and machine related features requests, no versioning). So I've implemented new loader (patch attached) focused on exensibility and versioning.
Design in few words:
Interface - format and interpretation of corresponding header and info structures. Each interface has a version (X.Y, X - major number, Y - minor number, both are 12-bits wide). Version X.Z MUST be backward compatible with version X.Y if Z>Y.
Interface negotiation - bootloader procedure which selects version and header from given list of (version, header) pairs. Bootloader MUST provide info compatible with selected version with respect to the selected header.
Header consists of the following parts:
1) Generic header. Defines container version and parameters and modules alignment.
2) List of image format related (version, header) pairs*.
3) List of platform related (version, header) pairs*.
4) List of machine related (version, header) pairs*.
* - In order of preference. Special version GRUB_ELBP_VERSION_NONE means that it's ok to omit header (and provide no info) of this type.
Given this header, bootloader negotiates interfaces and constructs info structure.
Info consists of the following parts:
1) Generic info. Provides modules list and command lines.
2) Image format related info.
3) Platform related info.
4) Machine related info.
You can find more details in the code, I've tried to comment things :). Opinions are appreciated.
P.S. Some parts of the patch haven't been well tested (e.g. ELF loading) and I haven't implemented a.out loading yet. But grub boots itself fine. P.P.S. Patch depends on self-multiboot patch I posted few days ago.P.P.P.S. ELBP stands for Extensible Loading and Booting Protocol :)
conf/i386-pc.mk renamed from grub2.multiboot/conf/i386-pc.mk +106 -1
@@ -833,7 +833,8 @@ pkgdata_MODULES = _chain.mod _linux.mod linux.mod normal.mod \ _multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ - videotest.mod play.mod bitmap.mod tga.mod cpuid.mod + videotest.mod play.mod bitmap.mod tga.mod cpuid.mod \ + _elbp.mod elbp.mod # For _chain.mod. _chain_mod_SOURCES = loader/i386/pc/chainloader.c
@@ -2075,4 +2076,108 @@ cpuid_mod_CFLAGS = $(COMMON_CFLAGS) cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For _elbp.mod. +_elbp_mod_SOURCES = loader/i386/pc/elbp.c +CLEANFILES += _elbp.mod mod-_elbp.o mod-_elbp.c pre-_elbp.o _elbp_mod-loader_i386_pc_elbp.o und-_elbp.lst +ifneq ($(_elbp_mod_EXPORTS),no) +CLEANFILES += def-_elbp.lst +DEFSYMFILES += def-_elbp.lst +endif +MOSTLYCLEANFILES += _elbp_mod-loader_i386_pc_elbp.d +UNDSYMFILES += und-_elbp.lst + +_elbp.mod: pre-_elbp.o mod-_elbp.o + -rm -f $@ + $(TARGET_CC) $(_elbp_mod_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ $^ + $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -R .note -R .comment $@ + +pre-_elbp.o: $(_elbp_mod_DEPENDENCIES) _elbp_mod-loader_i386_pc_elbp.o + -rm -f $@ + $(TARGET_CC) $(_elbp_mod_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ _elbp_mod-loader_i386_pc_elbp.o + +mod-_elbp.o: mod-_elbp.c + $(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(_elbp_mod_CFLAGS) -c -o $@ $< + +mod-_elbp.c: moddep.lst genmodsrc.sh + sh $(srcdir)/genmodsrc.sh '_elbp' $< > $@ || (rm -f $@; exit 1) + +ifneq ($(_elbp_mod_EXPORTS),no) +def-_elbp.lst: pre-_elbp.o + $(NM) -g --defined-only -P -p $< | sed 's/^\([^ ]*\).*/\1 _elbp/' > $@ +endif + +und-_elbp.lst: pre-_elbp.o + echo '_elbp' > $@ + $(NM) -u -P -p $< | cut -f1 -d' ' >> $@ + +_elbp_mod-loader_i386_pc_elbp.o: loader/i386/pc/elbp.c + $(TARGET_CC) -Iloader/i386/pc -I$(srcdir)/loader/i386/pc $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(_elbp_mod_CFLAGS) -MD -c -o $@ $< +-include _elbp_mod-loader_i386_pc_elbp.d + +CLEANFILES += cmd-_elbp_mod-loader_i386_pc_elbp.lst fs-_elbp_mod-loader_i386_pc_elbp.lst +COMMANDFILES += cmd-_elbp_mod-loader_i386_pc_elbp.lst +FSFILES += fs-_elbp_mod-loader_i386_pc_elbp.lst + +cmd-_elbp_mod-loader_i386_pc_elbp.lst: loader/i386/pc/elbp.c gencmdlist.sh + set -e; $(TARGET_CC) -Iloader/i386/pc -I$(srcdir)/loader/i386/pc $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(_elbp_mod_CFLAGS) -E $< | sh $(srcdir)/gencmdlist.sh _elbp > $@ || (rm -f $@; exit 1) + +fs-_elbp_mod-loader_i386_pc_elbp.lst: loader/i386/pc/elbp.c genfslist.sh + set -e; $(TARGET_CC) -Iloader/i386/pc -I$(srcdir)/loader/i386/pc $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(_elbp_mod_CFLAGS) -E $< | sh $(srcdir)/genfslist.sh _elbp > $@ || (rm -f $@; exit 1) + + +_elbp_mod_CFLAGS = $(COMMON_CFLAGS) +_elbp_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For elbp.mod. +elbp_mod_SOURCES = loader/i386/pc/elbp_normal.c +CLEANFILES += elbp.mod mod-elbp.o mod-elbp.c pre-elbp.o elbp_mod-loader_i386_pc_elbp_normal.o und-elbp.lst +ifneq ($(elbp_mod_EXPORTS),no) +CLEANFILES += def-elbp.lst +DEFSYMFILES += def-elbp.lst +endif +MOSTLYCLEANFILES += elbp_mod-loader_i386_pc_elbp_normal.d +UNDSYMFILES += und-elbp.lst + +elbp.mod: pre-elbp.o mod-elbp.o + -rm -f $@ + $(TARGET_CC) $(elbp_mod_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ $^ + $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -R .note -R .comment $@ + +pre-elbp.o: $(elbp_mod_DEPENDENCIES) elbp_mod-loader_i386_pc_elbp_normal.o + -rm -f $@ + $(TARGET_CC) $(elbp_mod_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ elbp_mod-loader_i386_pc_elbp_normal.o + +mod-elbp.o: mod-elbp.c + $(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(elbp_mod_CFLAGS) -c -o $@ $< + +mod-elbp.c: moddep.lst genmodsrc.sh + sh $(srcdir)/genmodsrc.sh 'elbp' $< > $@ || (rm -f $@; exit 1) + +ifneq ($(elbp_mod_EXPORTS),no) +def-elbp.lst: pre-elbp.o + $(NM) -g --defined-only -P -p $< | sed 's/^\([^ ]*\).*/\1 elbp/' > $@ +endif + +und-elbp.lst: pre-elbp.o + echo 'elbp' > $@ + $(NM) -u -P -p $< | cut -f1 -d' ' >> $@ + +elbp_mod-loader_i386_pc_elbp_normal.o: loader/i386/pc/elbp_normal.c + $(TARGET_CC) -Iloader/i386/pc -I$(srcdir)/loader/i386/pc $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(elbp_mod_CFLAGS) -MD -c -o $@ $< +-include elbp_mod-loader_i386_pc_elbp_normal.d + +CLEANFILES += cmd-elbp_mod-loader_i386_pc_elbp_normal.lst fs-elbp_mod-loader_i386_pc_elbp_normal.lst +COMMANDFILES += cmd-elbp_mod-loader_i386_pc_elbp_normal.lst +FSFILES += fs-elbp_mod-loader_i386_pc_elbp_normal.lst + +cmd-elbp_mod-loader_i386_pc_elbp_normal.lst: loader/i386/pc/elbp_normal.c gencmdlist.sh + set -e; $(TARGET_CC) -Iloader/i386/pc -I$(srcdir)/loader/i386/pc $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(elbp_mod_CFLAGS) -E $< | sh $(srcdir)/gencmdlist.sh elbp > $@ || (rm -f $@; exit 1) + +fs-elbp_mod-loader_i386_pc_elbp_normal.lst: loader/i386/pc/elbp_normal.c genfslist.sh + set -e; $(TARGET_CC) -Iloader/i386/pc -I$(srcdir)/loader/i386/pc $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(elbp_mod_CFLAGS) -E $< | sh $(srcdir)/genfslist.sh elbp > $@ || (rm -f $@; exit 1) + + +elbp_mod_CFLAGS = $(COMMON_CFLAGS) +elbp_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-pc.rmk renamed from grub2.multiboot/conf/i386-pc.rmk +12 -1
@@ -131,7 +131,8 @@ pkgdata_MODULES = _chain.mod _linux.mod linux.mod normal.mod \ _multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ - videotest.mod play.mod bitmap.mod tga.mod cpuid.mod + videotest.mod play.mod bitmap.mod tga.mod cpuid.mod \ + _elbp.mod elbp.mod # For _chain.mod. _chain_mod_SOURCES = loader/i386/pc/chainloader.c
@@ -240,4 +241,14 @@ cpuid_mod_CFLAGS = $(COMMON_CFLAGS) cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For _elbp.mod. +_elbp_mod_SOURCES = loader/i386/pc/elbp.c +_elbp_mod_CFLAGS = $(COMMON_CFLAGS) +_elbp_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For elbp.mod. +elbp_mod_SOURCES = loader/i386/pc/elbp_normal.c +elbp_mod_CFLAGS = $(COMMON_CFLAGS) +elbp_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
DISTLIST renamed from grub2.multiboot/DISTLIST +4 -0
@@ -105,6 +105,7 @@ include/grub/lvm.h include/grub/misc.h include/grub/mm.h +include/grub/elbp.h include/grub/net.h include/grub/normal.h include/grub/parser.h
@@ -137,6 +138,7 @@ include/grub/i386/pc/boot.h include/grub/i386/pc/chainloader.h include/grub/i386/pc/console.h +include/grub/i386/pc/elbp.h include/grub/i386/pc/init.h include/grub/i386/pc/kernel.h include/grub/i386/pc/loader.h
@@ -216,6 +218,8 @@ loader/i386/efi/linux_normal.c loader/i386/pc/chainloader.c loader/i386/pc/chainloader_normal.c +loader/i386/pc/elbp.c +loader/i386/pc/elbp_normal.c loader/i386/pc/linux.c loader/i386/pc/linux_normal.c loader/i386/pc/multiboot.c
include/grub/elbp.h renamed from grub2.multiboot/include/grub/elbp.h +217 -0
217 lines not on this page · raw message
include/grub/i386/pc/elbp.h renamed from grub2.multiboot/include/grub/i386/pc/elbp.h +70 -0
70 lines not on this page · raw message
include/grub/i386/pc/kernel.h renamed from grub2.multiboot/include/grub/i386/pc/kernel.h +1 -1
@@ -39,7 +39,7 @@#define GRUB_KERNEL_MACHINE_PREFIX 0x1c/* The size of the first region which won't be compressed. */ -#define GRUB_KERNEL_MACHINE_RAW_SIZE 0x4A0 +#define GRUB_KERNEL_MACHINE_RAW_SIZE 0x520#ifndef ASM_FILE
include/grub/i386/pc/loader.h renamed from grub2.multiboot/include/grub/i386/pc/loader.h +14 -4
@@ -22,17 +22,25 @@#include <grub/types.h> #include <grub/symbol.h> +#include <grub/elbp.h> #include <grub/machine/multiboot.h> extern grub_uint32_t EXPORT_VAR (grub_linux_prot_size );extern char *EXPORT_VAR (grub_linux_tmp_addr );extern char *EXPORT_VAR (grub_linux_real_addr ); -/* Multiboot loader needs to know boot device. */ +/* Multiboot and ELBP loaders need to know boot device. */ extern grub_uint32_t EXPORT_VAR (grub_boot_drive );extern grub_int32_t EXPORT_VAR (grub_install_dos_part );extern grub_int32_t EXPORT_VAR (grub_install_bsd_part ); +/* Multiboot and ELBP loaders need to know memory map. */ +struct grub_machine_mmap_entry ; +grub_uint32_t EXPORT_FUNC (grub_get_mmap_entry ) ( +struct grub_machine_mmap_entry *entry, +grub_uint32_t cont); +grub_uint32_t EXPORT_FUNC (grub_get_eisa_mmap ) (void ); +void EXPORT_FUNC (grub_linux_boot_zimage ) (void ) __attribute__ ((noreturn));void EXPORT_FUNC (grub_linux_boot_bzimage ) (void ) __attribute__ ((noreturn));
@@ -40,9 +48,9 @@void EXPORT_FUNC (grub_chainloader_real_boot ) (int drive,void *part_addr) __attribute__ ((noreturn)); -/* The asm part of the multiboot loader. */ -void EXPORT_FUNC (grub_multiboot_real_boot ) (grub_addr_t entry, -struct grub_multiboot_info *mbi) +/* The asm part of the multiboot and ELBP loaders. */ +void EXPORT_FUNC (grub_multiboot_real_boot ) (grub_addr_t entry, +grub_uint32_t magic,void *info) __attribute__ ((noreturn));/* It is necessary to export these functions, because normal mode commands
@@ -51,5 +59,7 @@void grub_rescue_cmd_initrd (int argc,char *argv[]);void grub_rescue_cmd_multiboot (int argc,char *argv[]);void grub_rescue_cmd_module (int argc,char *argv[]); +void grub_rescue_cmd_elbp (int argc,char *argv[]); +void grub_rescue_cmd_elbp_append (int argc,char *argv[]);#endif /* ! GRUB_LOADER_MACHINE_HEADER */
kern/i386/pc/startup.S renamed from grub2.multiboot/kern/i386/pc/startup.S +89 -7
129 lines not on this page · raw message
loader/i386/pc/elbp.c renamed from grub2.multiboot/loader/i386/pc/elbp.c +894 -0
894 lines not on this page · raw message
loader/i386/pc/elbp_normal.c renamed from grub2.multiboot/loader/i386/pc/elbp_normal.c +65 -0
65 lines not on this page · raw message
loader/i386/pc/multiboot.c renamed from grub2.multiboot/loader/i386/pc/multiboot.c +1 -1
@@ -49,7 +49,7 @@static grub_err_t grub_multiboot_boot (void ) { -grub_multiboot_real_boot (entry, mbi); +grub_multiboot_real_boot (entry,GRUB_MB_MAGIC2 , mbi);/* Not reached. */ return GRUB_ERR_NONE ;
Mikhail Vorozhtsov <[email protected]> writes:
Hi,
Quoted 4 lines
I'm working on a microkernel for
x86_64(with looking forward to ppc64 and sparc64 ports). As you know, microkernels are quite useless without user-space servers that provide "classic" OS services. But microkernels are so useless that they even cannot load servers from disk :). That's
Quoted 8 lines
why bootloader need to load servers images directly into memory in addition to image of microkernel itself. For i386-pc we have multiboot and it "just works". But it's really too i386-pc-specific. We also have draft of next multiboot version, but I think it still lacks flexibility (e.g. single 'flags' field for all image format, platform, and machine related features requests, no versioning). So I've implemented new loader (patch attached) focused on exensibility and versioning.
Feel free to give feedback on the next multiboot. I think you understand we can't just accept a loader for something that is not discussed and most people are happy with. What's on the wiki is the result of discussion, but it is still open for discussion. Did you look at the information about this on the wiki?
So I really hope you are willing to participate in this discussion. Feedback is welcome and so are patches that implement the final outcome of multiboot2 for any platform supported by GRUB 2.
--
Marco
Quoted 17 lines · Marco Gerards
Mikhail Vorozhtsov <[email protected]> writes:
Hi,
Quoted 4 lines
I'm working on a microkernel for
x86_64(with looking forward to ppc64 and sparc64 ports). As you know, microkernels are quite useless without user-space servers that provide "classic" OS services. But microkernels are so useless that they even cannot load servers from disk :). That'sQuoted 8 lines
why bootloader need to load servers images directly into memory in addition to image of microkernel itself. For i386-pc we have multiboot and it "just works". But it's really too i386-pc-specific. We also have draft of next multiboot version, but I think it still lacks flexibility (e.g. single 'flags' field for all image format, platform, and machine related features requests, no versioning). So I've implemented new loader (patch attached) focused on exensibility and versioning.
Quoted 3 lines
Feel free to give feedback on the next multiboot. I think you understand we can't just accept a loader for something that is not discussed and most people are happy with.
Of course, posting the patch was just the shortest way to show people the idea. Otherwise it would've taken many lines of text to describe everything.
Quoted 2 lines
What's on the wiki is the result of discussion, but it is still open for discussion. Did you look at the information about this on the wiki?
Yes, but I think my solution is too different from multiboot to be merged with it. It's just two ways of doing things, both of them will work. To say the truth, if I had found multiboot2 implemented I would've just started to using it. But I didn't, so I said to myself "Let's design a loading scheme, it should be fun" :)