multiboot2 loader
RFC 1/1 multiboot2 loader
Hi, this is a first pass at a multiboot2 loader (and sample kernel). It is working on qemu/x86, so I figured I'd send it out now for comments.
I've implemented the tags data structure described at
http://grub.enbug.org/MultibootDraft . The new file layout is like this:
conf/i386-pc.rmk | 4 conf/powerpc-ieee1275.rmk | 12 include/grub/i386/pc/loader.h | 7 include/grub/i386/pc/multiboot.h | 184 ----------- include/grub/misc.h | 2 include/grub/multiboot.h | 39 ++ include/multiboot.h | 136 ++++++++ kern/i386/pc/startup.S | 12 loader/i386/pc/multiboot.c | 437 +--------------------------- loader/i386/pc/multiboot_normal.c | 61 --- loader/multiboot.c | 466 ++++++++++++++++++++++++++++++ loader/multiboot_normal.c | 61 +++ loader/powerpc/ieee1275/multiboot.c | 54 +++ util/powerpc/ieee1275/grub-mkimage.c | 3 15 files changed, 805 insertions(+), 857 deletions(-)
(Unfortunately CVS sucks, even with quilt, so this patch may have bits in it that don't make sense or apply.)
Missing functionality:
- all arch-specific tags (e.g. memory map descriptors on x86)
- unloading
- non-ELF multiboot executables
- PowerPC support is untested
I've placed a generic multiboot.h directly into include/ (not in the grub subdirectory), since it it suitable for using in kernels independently of GRUB. As for the license, I believe that include/multiboot.h should NOT be GPL, to allow it to be used directly for non-GPL operating systems like the BSDs.
I've also included a multiboot "Hello world", suitable for testing the loader. (I believe this is far more valuable than the "hello" module, which we should remove.) It is based on the code scattered through the GRUB Legacy documentation.
Actually, we probably want to leave the old x86-only multiboot loader around to allow people to boot multiboot1 kernels... how should we name the two?
All comments welcome.
-Hollis
multiboot/Makefile new file +13 -0
@@ -0,0 +1,13 @@ +CFLAGS := -nostdinc -I. +LDFLAGS := -nostdlib -Ttext=0x00100000 +ASFLAGS := -I. + +OBJS := boot.o kernel.o + +all: multiboot + +multiboot: $(OBJS) + $(CC) $(LDFLAGS) $^ -o $@ + +clean: + rm -f $(OBJS) multiboot
multiboot/boot.S new file +93 -0
93 lines not on this page · raw message
multiboot/kernel.c new file +248 -0
248 lines not on this page · raw message
multiboot/multiboot.h new file +136 -0
136 lines not on this page · raw message
multiboot/stdint.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2006 Free Software Foundation, Inc. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef MULTIBOOT_STDINT_H +#define MULTIBOOT_STDINT_H + +typedef unsigned int uint32_t ; +typedef unsigned long uint64_t ; + +#endif /* ! MULTIBOOT_STDINT_H */
powerpc/ieee1275/multiboot.c new file +54 -0
54 lines not on this page · raw message
grub/multiboot.h new file +39 -0
@@ -0,0 +1,39 @@ +/* multiboot.h - multiboot header file. */ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2006 Free Software Foundation, Inc. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef GRUB_MULTIBOOT_HEADER +#define GRUB_MULTIBOOT_HEADER 1 + +#include <grub/types.h> +#include <grub/err.h> +#include <grub/elf.h> + +grub_err_t grub_mb_tag_alloc (grub_addr_t *addr,int key,grub_size_t len); +grub_err_t grub_mb_tags_arch_create (int argc,char *argv[]); + +void grub_mb_arch_boot (grub_addr_t entry,void *tags); +int grub_mb_arch_load32_hook (Elf32_Phdr *phdr,grub_addr_t *addr); +int grub_mb_arch_load64_hook (Elf64_Phdr *phdr,grub_addr_t *addr); + +/* Provided by the core to modules. */ +void grub_rescue_cmd_multiboot (int argc,char *argv[]); +void grub_rescue_cmd_module (int argc,char *argv[]); + +#endif /* ! GRUB_MULTIBOOT_HEADER */
multiboot.c new file +466 -0
466 lines not on this page · raw message
i386/pc/multiboot.c +22 -415
465 lines not on this page · raw message
grub/misc.h +2 -0
@@ -26,6 +26,8 @@#include <grub/symbol.h> #include <grub/err.h> +#define ALIGN_UP (addr, align) ((long)((char *)addr + align - 1) & ~(align - 1)) + #define grub_dprintf(condition, fmt, args...) grub_real_dprintf(__FILE__, __LINE__, condition, fmt, ## args);/* XXX: If grub_memmove is too slow, we must implement grub_memcpy. */ #define grub_memcpy (d,s,n) grub_memmove ((d), (s), (n))
powerpc/ieee1275/grub-mkimage.c +1 -2
@@ -27,13 +27,12 @@#include <stdlib.h> #include <string.h> #include <grub/elf.h> +#include <grub/misc.h> #include <grub/util/misc.h> #include <grub/util/resolve.h> #include <grub/kernel.h> #include <grub/machine/kernel.h> -#define ALIGN_UP (addr, align) ((long)((char *)addr + align - 1) & ~(align - 1)) -#define GRUB_IEEE1275_NOTE_NAME "PowerPC"#define GRUB_IEEE1275_NOTE_TYPE 0x1275
i386/pc/multiboot_normal.c deleted +0 -61
61 lines not on this page · raw message
multiboot_normal.c new file +61 -0
61 lines not on this page · raw message
i386-pc.rmk +2 -2
@@ -164,12 +164,12 @@ serial_mod_CFLAGS = $(COMMON_CFLAGS) serial_mod_LDFLAGS = $(COMMON_LDFLAGS) # For _multiboot.mod. -_multiboot_mod_SOURCES = loader/i386/pc/multiboot.c +_multiboot_mod_SOURCES = loader/multiboot.c loader/i386/pc/multiboot.c _multiboot_mod_CFLAGS = $(COMMON_CFLAGS) _multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) # For multiboot.mod. -multiboot_mod_SOURCES = loader/i386/pc/multiboot_normal.c +multiboot_mod_SOURCES = loader/multiboot_normal.c multiboot_mod_CFLAGS = $(COMMON_CFLAGS) multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
powerpc-ieee1275.rmk +12 -0
@@ -84,6 +84,8 @@ grub_install_SOURCES = util/powerpc/ieee pkgdata_MODULES = halt.mod \ _linux.mod \ linux.mod \ + _multiboot.mod \ + multiboot.mod \ normal.mod \ reboot.mod \ suspend.mod
@@ -98,6 +100,16 @@ linux_mod_SOURCES = loader/powerpc/ieee1 linux_mod_CFLAGS = $(COMMON_CFLAGS) linux_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For _multiboot.mod. +_multiboot_mod_SOURCES = loader/multiboot.c loader/powerpc/ieee1275/multiboot.c +_multiboot_mod_CFLAGS = $(COMMON_CFLAGS) +_multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For multiboot.mod. +multiboot_mod_SOURCES = loader/multiboot_normal.c +multiboot_mod_CFLAGS = $(COMMON_CFLAGS) +multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) + # For normal.mod. normal_mod_DEPENDENCIES = grub_script.tab.c grub_script.tab.h normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \
grub/i386/pc/loader.h +4 -3
@@ -22,11 +22,13 @@#include <grub/types.h> #include <grub/symbol.h> -#include <grub/machine/multiboot.h> +#include <grub/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 ); +extern grub_addr_t EXPORT_VAR (grub_os_area_addr ); +extern grub_size_t EXPORT_VAR (grub_os_area_size );void EXPORT_FUNC (grub_linux_boot_zimage ) (void ) __attribute__ ((noreturn));void EXPORT_FUNC (grub_linux_boot_bzimage ) (void ) __attribute__ ((noreturn));
@@ -35,8 +37,7 @@ void EXPORT_FUNC(grub_linux_boot_bzimagevoid 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) +void EXPORT_FUNC (grub_multiboot_real_boot ) (grub_addr_t entry,void *tags) __attribute__ ((noreturn));/* It is necessary to export these functions, because normal mode commands
grub/i386/pc/multiboot.h deleted +0 -184
184 lines not on this page · raw message
i386/pc/startup.S +6 -6
@@ -50,8 +50,8 @@ #include <grub/machine/console.h> #include <grub/cpu/linux.h> #include <grub/machine/kernel.h> -#include <grub/machine/multiboot.h> - +#include <multiboot.h> + #define ABS(x) ((x) - EXT_C(start) + GRUB_BOOT_MACHINE_KERNEL_ADDR + 0x200) .file "startup.S"
@@ -803,18 +803,18 @@ linux_setup_seg: FUNCTION(grub_multiboot_real_boot) /* Push the entry address on the stack. */ pushl %eax - /* Move the address of the multiboot information structure to ebx. */ + /* Move the address of the multiboot tags to ebx. */ movl %edx,%ebx - + /* Unload all modules and stop the floppy driver. */ call EXT_C(grub_dl_unload_all) call EXT_C(grub_stop_floppy) /* Interrupts should be disabled. */ cli - + /* Move the magic value into eax and jump to the kernel. */ - movl $GRUB_MB_MAGIC2,%eax + movl $MULTIBOOT_BOOTLOADER_MAGIC,%eax popl %ecx jmp *%ecx
multiboot.h new file +136 -0
136 lines not on this page · raw message
Quoted 5 lines · Hollis Blanchard
I've placed a generic
multiboot.hdirectly intoinclude/(not in the grub subdirectory), since it it suitable for using in kernels independently of GRUB. As for the license, I believe thatinclude/multiboot.hshould NOT be GPL, to allow it to be used directly for non-GPL operating systems like the BSDs.
GRUB is entirely licensed under GPL. Please don't make an exception.
Quoted 3 lines
Actually, we probably want to leave the old x86-only multiboot loader around to allow people to boot multiboot1 kernels... how should we name the two?
This is what I had in mind: one multiboot module should provide support for both. Multiboot Specification version 2 is (and must be) a superset of features found in version 0.x. So we should implement support version 2 first, and "translate" Multiboot information if a kernel is for version 0.x.
Thanks,
Okuji
Quoted 8 lines · Yoshinori K. Okuji
Quoted 5 lines · Hollis Blanchard
I've placed a generic
multiboot.hdirectly intoinclude/(not in the grub subdirectory), since it it suitable for using in kernels independently of GRUB. As for the license, I believe thatinclude/multiboot.hshould NOT be GPL, to allow it to be used directly for non-GPL operating systems like the BSDs.GRUB is entirely licensed under GPL. Please don't make an exception.
An exception is exactly what I am proposing. What is your objection?
Quoted 8 lines
Quoted 3 lines
Actually, we probably want to leave the old x86-only multiboot loader around to allow people to boot multiboot1 kernels... how should we name the two?
This is what I had in mind: one multiboot module should provide support for both. Multiboot Specification version 2 is (and must be) a superset of features found in version 0.x. So we should implement support version 2 first, and "translate" Multiboot information if a kernel is for version 0.x.
I'm not sure "translation" makes sense, but we can probably share a lot of the code.
-Hollis
Quoted 11 lines · Hollis Blanchard
Quoted 8 lines · Yoshinori K. Okuji
Quoted 5 lines · Hollis Blanchard
I've placed a generic
multiboot.hdirectly intoinclude/(not in the grub subdirectory), since it it suitable for using in kernels independently of GRUB. As for the license, I believe thatinclude/multiboot.hshould NOT be GPL, to allow it to be used directly for non-GPL operating systems like the BSDs.GRUB is entirely licensed under GPL. Please don't make an exception.
An exception is exactly what I am proposing. What is your objection?
The GNU Project endorses the use of GPL to promote freedom. Don't forget that GRUB is a part of GNU.
Okuji
Quoted 9 lines · Yoshinori K. Okuji
Quoted 8 lines · Hollis Blanchard
Quoted 7 lines · Yoshinori K. Okuji
Quoted 5 lines · Hollis Blanchard
I've placed a generic
multiboot.hdirectly intoinclude/(not in the grub subdirectory), since it it suitable for using in kernels independently of GRUB. As for the license, I believe thatinclude/multiboot.hshould NOT be GPL, to allow it to be used directly for non-GPL operating systems like the BSDs.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
GRUB is entirely licensed under GPL. Please don't make an exception.
An exception is exactly what I am proposing. What is your objection?
The GNU Project endorses the use of GPL to promote freedom. Don't forget that GRUB is a part of GNU.
The GNU project also includes GCC, which is used to build non-Free software. In fact GCC even contains libgcc, which is *linked* with non-free software.
The GNU project also includes glibc, which is linked with (almost?) all non-Free software on Linux.
The GNU project also uses the LGPL license, which allows all sorts of Free software to be used with non-Free software.
GRUB itself is used to boot non-Free operating systems.
There is plenty of precedent here. So I still see nothing wrong with putting a header file, which describes an interface, under a non-GPL license.
-Hollis
Quoted 8 lines · Hollis Blanchard
Quoted 4 lines
Quoted 1 line
An exception is exactly what I am proposing. What is your objection?
The GNU Project endorses the use of GPL to promote freedom. Don't forget that GRUB is a part of GNU.
The GNU project also includes GCC, which is used to build non-Free software. In fact GCC even contains libgcc, which is *linked* with non-free software.
GCC is a project to be used as a tool to make another program. GRUB is not.
Quoted 2 lines
The GNU project also includes glibc, which is linked with (almost?) all non-Free software on Linux.
GNU Libc is a project to be used as a library to make another program. GRUB is not.
Quoted 2 lines
The GNU project also uses the LGPL license, which allows all sorts of Free software to be used with non-Free software.
We have never been in favour of LGPL. LGPL is just a workaround, and should not be used whenever possible.
Quoted 1 line
GRUB itself is used to boot non-Free operating systems.
This is a different story. One may use, say, GNU Emacs to make proprietary software. But this does not require that GNU Emacs be non-copyleft.
Quoted 3 lines
There is plenty of precedent here. So I still see nothing wrong with putting a header file, which describes an interface, under a non-GPL license.
Because GRUB is not a library. The spec is available independently, so you can write your own header easily. Nothing prevents you from doing this.
Okuji
Quoted 11 lines
Quoted 4 lines
There is plenty of precedent here. So I still see nothing wrong with putting a header file, which describes an interface, under a non-GPL license.
Because GRUB is not a library. The spec is available independently, so you can write your own header easily. Nothing prevents you from doing this.
Okuji
And should the multiboot header file be "Grub's"? What about having "Multiboot's" header as a part of "Multiboot project". Such project should contain only specification, and header file, that can be freely copied. The only thing that should be forbidden is that some third party will claim she owns the header. I think that GPL is too restrictive for this purpose. Such header file can be then added to grub as well as to BSD-licenced and other software.
--
Tomas Ebenlendr
http://drak.ucw.cz/ebikQuoted 16 lines · Tomáš Ebenlendr
Quoted 2 lines
Quoted 2 lines
There is plenty of precedent here. So I still see nothing wrong
with
Quoted 1 line
Quoted 1 line
putting a header file, which describes an interface, under a
non-GPL
Quoted 3 lines
Quoted 1 line
license.
Because GRUB is not a library. The spec is available independently,
so
Quoted 1 line
you can write your own header easily. Nothing prevents you from
doing
Quoted 4 lines
this.
Okuji
Quoted 10 lines
And should the multiboot header file be "Grub's"? What about having "Multiboot's" header as a part of "Multiboot project". Such project should
contain only specification, and header file, that can be freely copied.
The only thing that should be forbidden is that some third party will claim she owns the header. I think that GPL is too restrictive for this
purpose. Such header file can be then added to grub as well as to BSD-licenced and other software.
Great point. A "multiboot" project could easily be created, and wouldn't even need the approval of the GRUB project.
Beyond the specification and header file, it could also contain a "Hello World" multiboot kernel.
-Hollis
Quoted 1 line · Tomáš Ebenlendr
And should the multiboot header file be "Grub's"?
If the header is written for GRUB, yes. If it has no relationship with GRUB, no. That's very simple.
Quoted 2 lines
What about having
"Multiboot's" header as a part of "Multiboot project".
Multiboot Specification is not a part of GRUB in any sense. It is discussed in this list, only because that is the most realistic at the moment, as all Multiboot developers are GRUB developers, too, AFAIK.
It is perfectly reasonable to provide sample code with the Multiboot Specification. However, there is no reason to use the same code in GRUB. The code for GRUB is written for GRUB, and the header can be quite different from such sample code. For instance, look at GNU Mach. It does not use any code from GNU GRUB, even though both are GNU projects. This makes sense, because the requirement for a project is different from that for another.
I repeat: GRUB is not a library. GRUB does not need to provide a generic implementation which can be reused for other projects, and should not try to do it.
Okuji
Quoted 7 lines · Yoshinori K. Okuji
Quoted 2 lines · Tomáš Ebenlendr
What about having
"Multiboot's" header as a part of "Multiboot project".Multiboot Specification is not a part of GRUB in any sense. It is discussed in this list, only because that is the most realistic at the moment, as all Multiboot developers are GRUB developers, too, AFAIK.
Not part of GRUB in any sense? It was developed by GRUB developers, has always been living in the GRUB repository, the official GRUB tarball includes it and AFAIK GRUB is the only bootloader to implement it. Saying that multiboot isn't part of GRUB doesn't really make any sense to me. It could as well have been named "GRUB boot protocol" and nobody would consider that strange.
Jeroen Dekkers
Quoted 10 lines · Jeroen Dekkers
Quoted 7 lines · Yoshinori K. Okuji
Quoted 2 lines · Tomáš Ebenlendr
What about having
"Multiboot's" header as a part of "Multiboot project".Multiboot Specification is not a part of GRUB in any sense. It is discussed in this list, only because that is the most realistic at the moment, as all Multiboot developers are GRUB developers, too, AFAIK.
Not part of GRUB in any sense?
No. It is explicitly written that this specification is to define a neutral protocol between a boot loader and an operating system.
Quoted 4 lines
It was developed by GRUB developers,
has always been living in the GRUB repository, the official GRUB tarball includes it and AFAIK GRUB is the only bootloader to implement it.
I know at least one more project which implements Multiboot: Etherboot. The support is partial, but it still supports Multiboot.
I talked about excluding the Multiboot Specification from GRUB with RMS a long time ago, because it was not really a part of GRUB, and it looked like a part of it, although it should be regarded as a generic specification, only because it was bundled with GRUB. And, he said that it was more convenient for people who would like to utilize GRUB to include the spec, and the spec was small enough to distribute with GRUB. His argument sounded good, so I decided to keep it.
But now it might be better to change my mind, since even _you_ misunderstand it. If you don't get it, how many people would understand?
Quoted 3 lines
Saying that multiboot isn't part of GRUB doesn't really make any sense to me. It could as well have been named "GRUB boot protocol" and nobody would consider that strange.
Don't generalize your idea without asking. The spec is not limited to GRUB, and GRUB supports more protocols.
Okuji
At Tue, 28 Nov 2006 12:25:49 +0100,
Quoted 3 lines · Yoshinori K. Okuji
But now it might be better to change my mind, since even _you_ misunderstand it. If you don't get it, how many people would understand?
If you consider it a separate project, it's probably better to make it a real separate project.
Jeroen Dekkers
At Sat, 25 Nov 2006 03:56:50 +0100,
Quoted 6 lines · Yoshinori K. Okuji
Quoted 4 lines · Hollis Blanchard
Quoted 4 lines
Quoted 1 line
An exception is exactly what I am proposing. What is your objection?
The GNU Project endorses the use of GPL to promote freedom. Don't forget that GRUB is a part of GNU.
<SNIP>
Quoted 6 lines
Quoted 3 lines
There is plenty of precedent here. So I still see nothing wrong with putting a header file, which describes an interface, under a non-GPL license.
Because GRUB is not a library. The spec is available independently, so you can write your own header easily. Nothing prevents you from doing this.
Nothing prevents you from writing a C library - the POSIX and C standards are available independently. Yet the C library is under LGPL. Also nothing prevents you from writing an ogg vorbis implementation, but the FSF advocated the BSD license for ogg vorbis however.
What RMS said is that the GPL isn't an end itself. I agree with that, and I think the BSD license is more suitable for the multiboot header files and/or multiboot example kernel than the GPL.
Jeroen Dekkers
Quoted 9 lines · Jeroen Dekkers
Nothing prevents you from writing a C library - the POSIX and C standards are available independently. Yet the C library is under LGPL. Also nothing prevents you from writing an ogg vorbis implementation, but the FSF advocated the BSD license for ogg vorbis however.
What RMS said is that the GPL isn't an end itself. I agree with that, and I think the BSD license is more suitable for the multiboot header files and/or multiboot example kernel than the GPL.
You are right at the point that we adopt weaker licenses by compromise from time to time. But you completely miss the point that code in GRUB is not meant to be used for other projects. So we have no reason to compromise in GRUB.
Okuji
Quoted 7 lines · Yoshinori K. Okuji
Quoted 6 lines · Jeroen Dekkers
Nothing prevents you from writing a C library - the POSIX and C standards are available independently. Yet the C library is under LGPL. Also nothing prevents you from writing an ogg vorbis implementation, but the FSF advocated the BSD license for ogg vorbis however.
Quoted 8 lines
Quoted 3 lines
What RMS said is that the GPL isn't an end itself. I agree with that, and I think the BSD license is more suitable for the multiboot header files and/or multiboot example kernel than the GPL.
You are right at the point that we adopt weaker licenses by compromise from time to time. But you completely miss the point that code in GRUB is not meant to be used for other projects. So we have no reason to compromise in GRUB.
You completely miss the point that we want to have header files and example code that can be used by other projects to implement multiboot.
Jeroen Dekkers
Quoted 3 lines · Jeroen Dekkers
You completely miss the point that we want to have header files and example code that can be used by other projects to implement multiboot.
*sigh* Sleep well, and reconsider what I have said.
Okuji