This patch series cleans up the Multiboot2 build system and example kernel:
* Fix initializing the source tree with autogen.sh when using current gnulib. * Change from obsolete .bzrignore to .gitignore. * Fix the Multiboot2 header tag alignment in the assembly language boot_*.S files to 8 byte boundaries so that the resulting kernel image actually satisfies the Multiboot2 spec. The i386 code used to have no alignment, and the mips code used to have 256 byte alignment. Neither of those satisfies the Multiboot 2 specification's 8 byte requirement. * Document both i386 and mips boot code in the spec text. * Fix build of the example kernel for both i386 and mips. No idea whether the kernels actually work, though. Still looking for a few qemu commands to boot such an example kernel in a VM, preferably with gdb debugging, and especially for mips. * Remove obsolete remnants from supporting pre-2003 autotools. We require 2008 autotools anyway, so we can drop those ancient workarounds from the late 1990s and early 2000s. * Generate listing files, symbol lists, and a kernel map file to help people understand the built example kernel image. Patch set revision history: v4 changes over v3: * Use ".balign 8" in all assembly code, removing ".align". * No removing useless whitespace from assembly sources. * As requested, consistently order the patterns in .gitignore: Non-rooted patterns go before .gitignore-directory-rooted patterns, then sort each part with "LC_ALL=C sort". * Add Reviewed-by to the autogen.sh patch. * Split up the changes required to get the example kernel to build. As the build was broken from the start, it does not matter if any of these commits leaves the source tree in a state of broken build. * Made the example kernel build for mips. * Remove some obsolete remnants from supporting ancient autotools and from just copying over from Multiboot 1. * Generate some more information about the example kernel to help understand how it is built and how it will behave. * Update comments to read about "Multiboot 2" instead of "Multiboot". * Clean up some things in the code (stack cleanups, label the header terminator tags, use builtin macro __ASSEMBLER__, v3 changes over v2: * improved .gitignore * fix the case logic for the ix86 matching pattern ([[]]) * fix mb2 header tag alignment * fix alignment on mips Hans Ulrich Niedermann (27): multiboot2: Allow autogen.sh to run with current gnulib multiboot2: Use .gitignore files multiboot2: Use m4 quoting and AS_HELP_STRING multiboot2: Remove obsolete compat code for ancient Autoconf multiboot2: Remove CCAS workarounds for pre-2005 Automake multiboot2: Remove unnecessary definition of CC multiboot2: Automake generates dependencies automatically multiboot2: Automake cleans built programs automatically multiboot2: Use the constants by their proper names multiboot2: Rename boot.S to boot_i386.S multiboot2: Add boot_i386.S to shipped files multiboot2: Add boot_mips.S example code to docs multiboot2: Build arch specific boot code multiboot2: Fix example kernel header tag alignment multiboot2: Remove unreferenced AOUT_KLUDGE multiboot2: Change "Multiboot" in comments to "Multiboot2" multiboot2: Clean up stack (cdecl calling conventions) multiboot2: Use predefined #ifdef __ASSEMBLER__ multiboot2: Set -nostdlib before AC_PROG_CC for x-compile multiboot2: mips build wants __start symbol multiboot2: "make distcheck" with example kernel enabled multiboot2: Always define the kernel_* vars multiboot2: Generate per object file listings multiboot2: Generate a kernel.map map file multiboot2: Generate gcc temp files (*.i and *.s) multiboot2: Generate symbol lists and disassembly file multiboot2: Add labels around the termination tag .bzrignore | 30 --------------- .gitignore | 55 +++++++++++++++++++++++++++ Makefile.am | 2 + configure.ac | 74 ++++++++++++++++++++++++++++--------- doc/.gitignore | 4 ++ doc/Makefile.am | 47 +++++++++++++++++++---- doc/{boot.S => boot_i386.S} | 28 +++++++------- doc/boot_mips.S | 25 ++++++------- doc/kernel.c | 4 +- doc/multiboot.texi | 55 +++++++++++++++++---------- doc/multiboot2.h | 17 ++++++--- 11 files changed, 231 insertions(+), 110 deletions(-) delete mode 100644 .bzrignore create mode 100644 .gitignore create mode 100644 doc/.gitignore rename doc/{boot.S => boot_i386.S} (85%) Interdiff: diff --git a/.gitignore b/.gitignore index 4de19ceee..ba08c2911 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,9 @@ # Generated by "autogen.sh" -/gendocs.sh -/lib/ -/m4/ +Makefile.in +/INSTALL /NEWS /README - -Makefile.in - /aclocal.m4 /autom4te.cache/ /compile @@ -18,13 +14,15 @@ Makefile.in /depcomp /doc/mdate-sh /doc/texinfo.tex +/gendocs.sh /install-sh -/INSTALL +/lib/ +/m4/ /missing # Generated by "configure" -Makefile .deps/ +Makefile /config.h /config.log @@ -32,17 +30,23 @@ Makefile /stamp-h1 # Generated by "make" +*.lst +*.i +*.o +*.s + +/doc/*.S.texi /doc/*.c.texi /doc/*.h.texi -/doc/*.S.texi +/doc/kernel +/doc/kernel.lss +/doc/kernel.map +/doc/kernel.sym +/doc/kernel.vsym /doc/multiboot.info* /doc/stamp-vti /doc/version.texi -*.o - -/doc/kernel - # Generated by "make web-manual" /doc/manual/ /doc/multiboot.aux diff --git a/Makefile.am b/Makefile.am index 70eec9cd0..38e797aa7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,5 @@ +AM_DISTCHECK_CONFIGURE_FLAGS = --enable-example-kernel + # Do not change this order if you don't know what you are doing. AUTOMAKE_OPTIONS = 1.7 gnu SUBDIRS = doc diff --git a/configure.ac b/configure.ac index 5ddb16b72..e70da14d0 100644 --- a/configure.ac +++ b/configure.ac @@ -12,28 +12,49 @@ dnl "AS IS" CONDITION. THE FREE SOFTWARE FOUNDATION DISCLAIMS ANY dnl LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE dnl USE OF THIS SOFTWARE. -AC_PREREQ(2.63) +AC_PREREQ([2.63]) AC_INIT([Multiboot], [2.0], [bug-g...@gnu.org]) AC_CONFIG_SRCDIR([doc/multiboot.texi]) AC_CONFIG_HEADER([config.h]) -AM_INIT_AUTOMAKE +AM_INIT_AUTOMAKE([1.10.1]) # # Programs # -AC_CHECK_TOOL(CC, gcc) +AC_CANONICAL_BUILD +AC_CANONICAL_HOST + +AS_IF([test "x$host" != "x$build"], [dnl + CFLAGS="-nostdlib $CFLAGS" + LDFLAGS="-nostdlib $LDFLAGS" +]) + AC_PROG_CC +AC_PROG_GREP AM_PROG_AS -# We need this for older versions of Autoconf. -_AM_DEPENDENCIES(CC) -dnl Because recent automake complains about AS, set it here. -CCAS="$CC" -AC_SUBST(CCAS) +AC_ARG_VAR([NM], [nm tool]) +AC_CHECK_TOOL([NM], [nm]) -dnl Build the example Multiboot kernel (if possible on this host) -AC_CANONICAL_HOST +AC_ARG_VAR([OBJDUMP], [objdump tool]) +AC_CHECK_TOOL([OBJDUMP], [objdump]) + +AC_ARG_VAR([SORT], [sort program]) +AC_PATH_PROG([SORT], [sort]) + +AC_ARG_VAR([UNIQ], [uniq program]) +AC_PATH_PROG([UNIQ], [uniq]) + +AC_ARG_VAR([SORT_U], [working sort -u program]) +# we are too lazy to figure out whether 'sort -u' works +SORT_U="\${SORT} | \${UNIQ}" +AC_SUBST([SORT_U]) +AC_MSG_CHECKING([for sort -u]) +AC_MSG_RESULT([${SORT_U} (lazy)]) + +dnl Build the example Multiboot2 kernel (if possible on this host) +kernel_boot_arch=unsupported kernel_ccasflags= kernel_cflags= case "$host_cpu" in #( @@ -47,9 +68,8 @@ case "$host_cpu" in #( ;; #( mips*) kernel_boot_arch=mips - ;; #( - *) - kernel_boot_arch=unsupported + kernel_ccasflags="-mabi=32" + kernel_cflags="-mabi=32" ;; esac AC_SUBST([kernel_boot_arch]) @@ -61,13 +81,8 @@ AS_HELP_STRING([--enable-example-kernel], [build the example Multiboot2 kernel])]) AM_CONDITIONAL([BUILD_EXAMPLE_KERNEL], - [test "x$enable_example_kernel" = xyes && test "x$kernel_boot_arch" != "xunsupported"]) - -dnl Because recent automake complains about CCASFLAGS, set it here. -CCASFLAGS='$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)' -AC_SUBST(CCASFLAGS) - -CFLAGS="-nostdlib $CFLAGS" + [test "x$enable_example_kernel" = xyes && + test "x$kernel_boot_arch" != "xunsupported"]) dnl Output. AC_CONFIG_FILES([Makefile doc/Makefile]) diff --git a/doc/.gitignore b/doc/.gitignore index 847f66f4d..c8f86161e 100644 --- a/doc/.gitignore +++ b/doc/.gitignore @@ -1,2 +1,4 @@ +# gnulib-tool insists on having these ignore patterns in this file. +# We keep all other ignore patterns in the top-level .gitignore file. /gendocs_template /gendocs_template_min diff --git a/doc/Makefile.am b/doc/Makefile.am index 0d896fe10..a382b62be 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -1,5 +1,6 @@ +CLEANFILES = info_TEXINFOS = multiboot.texi -EXAMPLES = boot_i386.S boot_mips.S kernel.c multiboot2.h +arch_sources = boot_i386.S boot_mips.S multiboot_TEXINFOS = boot_i386.S.texi boot_mips.S.texi kernel.c.texi multiboot2.h.texi SRC2TEXI = src2texi noinst_SCRIPTS = $(SRC2TEXI) @@ -9,18 +10,47 @@ pkginclude_HEADERS = multiboot2.h # The example kernel is built if you specify --enable-example-kernel. if BUILD_EXAMPLE_KERNEL noinst_PROGRAMS = kernel +endif + kernel_SOURCES = boot_$(kernel_boot_arch).S kernel.c multiboot2.h kernel_CCASFLAGS = $(kernel_ccasflags) kernel_CFLAGS = $(kernel_cflags) -fno-builtin -nostdinc -O -g -Wall \ -imacros $(top_builddir)/config.h kernel_LDFLAGS = -nostdlib -Wl,-N -Wl,-Ttext -Wl,80100000 -Wl,--build-id=none -boot.o: multiboot2.h -endif +CLEANFILES += kernel.map +kernel_LDFLAGS += -Wl,-Map,kernel.map + +CLEANFILES += *.lst +kernel_CCASFLAGS += -Wa,-adhlns=$(@:.o=.lst) +kernel_CFLAGS += -Wa,-adhlns=$(@:.o=.lst) + +CLEANFILES += *.i *.s +kernel_CCASFLAGS += -save-temps=obj +kernel_CFLAGS += -save-temps=obj EXTRA_DIST = $(man_MANS) $(noinst_SCRIPTS) \ - $(EXAMPLES) $(multiboot_TEXINFOS) -CLEANFILES = $(noinst_PROGRAMS) + $(arch_sources) $(multiboot_TEXINFOS) + +noinst_DATA = + +CLEANFILES += kernel.lss +noinst_DATA += kernel.lss +kernel.lss: kernel$(EXEEXT) + $(OBJDUMP) -h -S kernel$(EXEEXT) > kernel.lss.new + mv -f kernel.lss.new kernel.lss + +CLEANFILES += kernel.sym +noinst_DATA += kernel.sym +kernel.sym: kernel$(EXEEXT) + $(NM) -n kernel$(EXEEXT) | $(SORT_U) > kernel.sym.new + mv -f kernel.sym.new kernel.sym + +CLEANFILES += kernel.vsym +noinst_DATA += kernel.vsym +kernel.vsym: kernel$(EXEEXT) + $(OBJDUMP) --syms kernel$(EXEEXT) | $(GREP) '^[0-9a-f]\{4,16\} ' | $(SORT_U) > kernel.vsym.new + mv -f kernel.vsym.new kernel.vsym # Cancel the rule %.texi -> %. This rule may confuse make to determine # the dependecies. diff --git a/doc/boot_i386.S b/doc/boot_i386.S index 1418afe1a..67411b968 100644 --- a/doc/boot_i386.S +++ b/doc/boot_i386.S @@ -15,7 +15,6 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#define ASM_FILE 1 #include <multiboot2.h> /* C symbol format. HAVE_ASM_USCORE is defined by configure. */ @@ -28,13 +27,6 @@ /* The size of our stack (16KB). */ #define STACK_SIZE 0x4000 -/* The flags for the Multiboot header. */ -#ifdef __ELF__ -# define AOUT_KLUDGE 0 -#else -# define AOUT_KLUDGE MULTIBOOT_AOUT_KLUDGE -#endif - .text .globl start, _start @@ -43,9 +35,9 @@ _start: jmp multiboot_entry /* Align 64 bits boundary. */ - .align 8 + .balign 8 - /* Multiboot header. */ + /* Multiboot2 header. */ multiboot_header: /* magic */ .long MULTIBOOT2_HEADER_MAGIC @@ -56,7 +48,7 @@ multiboot_header: /* checksum */ .long -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + (multiboot_header_end - multiboot_header)) #ifndef __ELF__ - .align 8 + .balign 8 address_tag_start: .short MULTIBOOT_HEADER_TAG_ADDRESS .short MULTIBOOT_HEADER_TAG_OPTIONAL @@ -70,7 +62,7 @@ address_tag_start: /* bss_end_addr */ .long _end address_tag_end: - .align 8 + .balign 8 entry_address_tag_start: .short MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS .short MULTIBOOT_HEADER_TAG_OPTIONAL @@ -79,7 +71,7 @@ entry_address_tag_start: .long multiboot_entry entry_address_tag_end: #endif /* __ELF__ */ - .align 8 + .balign 8 framebuffer_tag_start: .short MULTIBOOT_HEADER_TAG_FRAMEBUFFER .short MULTIBOOT_HEADER_TAG_OPTIONAL @@ -88,12 +80,13 @@ framebuffer_tag_start: .long 768 .long 32 framebuffer_tag_end: - .align 8 + .balign 8 +terminator_tag_start: .short MULTIBOOT_HEADER_TAG_END .short 0 - .long 8 + .long terminator_tag_end - terminator_tag_start +terminator_tag_end: multiboot_header_end: - multiboot_entry: /* Initialize the stack pointer. */ movl $(stack + STACK_SIZE), %esp @@ -102,17 +95,19 @@ multiboot_entry: pushl $0 popf - /* Push the pointer to the Multiboot information structure. */ + /* Push the pointer to the Multiboot2 information structure. */ pushl %ebx /* Push the magic value. */ pushl %eax /* Now enter the C main function... */ call EXT_C(cmain) + addl $8, %esp /* Halt. */ pushl $halt_message call EXT_C(printf) + addl $4, %esp loop: hlt jmp loop diff --git a/doc/boot_mips.S b/doc/boot_mips.S index e7bb7df9f..4d6ac1f67 100644 --- a/doc/boot_mips.S +++ b/doc/boot_mips.S @@ -15,7 +15,6 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#define ASM_FILE 1 #include <multiboot2.h> /* C symbol format. HAVE_ASM_USCORE is defined by configure. */ @@ -28,27 +27,21 @@ /* The size of our stack (16KB). */ #define STACK_SIZE 0x4000 -/* The flags for the Multiboot header. */ -#ifdef __ELF__ -# define AOUT_KLUDGE 0 -#else -# define AOUT_KLUDGE MULTIBOOT_AOUT_KLUDGE -#endif - .text .set noreorder .set nomacro - .globl start, _start + .globl start, _start, __start start: _start: +__start: b multiboot_entry nop /* Align 64 bits boundary. */ .balign 8 - - /* Multiboot header. */ + + /* Multiboot2 header. */ multiboot_header: /* magic */ .long MULTIBOOT2_HEADER_MAGIC @@ -60,7 +53,7 @@ multiboot_header: .long -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_MIPS32 + (multiboot_header_end - multiboot_header)) #ifndef __ELF__ .balign 8 -address_tag_start: +address_tag_start: .short MULTIBOOT_HEADER_TAG_ADDRESS .short MULTIBOOT_HEADER_TAG_OPTIONAL .long address_tag_end - address_tag_start @@ -74,7 +67,7 @@ address_tag_start: .long _end address_tag_end: .balign 8 -entry_address_tag_start: +entry_address_tag_start: .short MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS .short MULTIBOOT_HEADER_TAG_OPTIONAL .long entry_address_tag_end - entry_address_tag_start @@ -83,7 +76,7 @@ entry_address_tag_start: entry_address_tag_end: #endif /* __ELF__ */ .balign 8 -framebuffer_tag_start: +framebuffer_tag_start: .short MULTIBOOT_HEADER_TAG_FRAMEBUFFER .short MULTIBOOT_HEADER_TAG_OPTIONAL .long framebuffer_tag_end - framebuffer_tag_start @@ -92,11 +85,12 @@ framebuffer_tag_start: .long 32 framebuffer_tag_end: .balign 8 +terminator_tag_start: .short MULTIBOOT_HEADER_TAG_END .short 0 - .long 8 + .long terminator_tag_end - terminator_tag_start +terminator_tag_end: multiboot_header_end: - multiboot_entry: /* Initialize the stack pointer. */ lui $sp, %hi (stack + STACK_SIZE) diff --git a/doc/kernel.c b/doc/kernel.c index c9431e3c0..d555fbe06 100644 --- a/doc/kernel.c +++ b/doc/kernel.c @@ -44,7 +44,7 @@ static void itoa (char *buf, int base, int d); static void putchar (int c); void printf (const char *format, ...); -/* Check if MAGIC is valid and print the Multiboot information structure +/* Check if MAGIC is valid and print the Multiboot2 information structure pointed by ADDR. */ void cmain (unsigned long magic, unsigned long addr) @@ -55,7 +55,7 @@ cmain (unsigned long magic, unsigned long addr) /* Clear the screen. */ cls (); - /* Am I booted by a Multiboot-compliant boot loader? */ + /* Am I booted by a Multiboot2-compliant boot loader? */ if (magic != MULTIBOOT2_BOOTLOADER_MAGIC) { printf ("Invalid magic number: 0x%x\n", (unsigned) magic); diff --git a/doc/multiboot.texi b/doc/multiboot.texi index 827a5c08d..67f0abd84 100644 --- a/doc/multiboot.texi +++ b/doc/multiboot.texi @@ -1574,10 +1574,10 @@ macros, such as the magic number for the Multiboot2 header, the Multiboot2 header structure and the Multiboot2 information structure. @menu -* multiboot2.h:: +* multiboot2.h:: * boot_i386.S:: * boot_mips.S:: -* kernel.c:: +* kernel.c:: * Other Multiboot2 kernels:: @end menu diff --git a/doc/multiboot2.h b/doc/multiboot2.h index b18160707..f89cd5e77 100644 --- a/doc/multiboot2.h +++ b/doc/multiboot2.h @@ -32,14 +32,13 @@ /* This should be in %eax. */ #define MULTIBOOT2_BOOTLOADER_MAGIC 0x36d76289 -/* Alignment of multiboot modules. */ +/* Alignment of multiboot2 modules. */ #define MULTIBOOT_MOD_ALIGN 0x00001000 -/* Alignment of the multiboot info structure. */ +/* Alignment of the multiboot2 info structure. */ #define MULTIBOOT_INFO_ALIGN 0x00000008 -/* Flags set in the 'flags' member of the multiboot header. */ - +/* Multiboot2 boot information tag types */ #define MULTIBOOT_TAG_ALIGN 8 #define MULTIBOOT_TAG_TYPE_END 0 #define MULTIBOOT_TAG_TYPE_CMDLINE 1 @@ -64,6 +63,7 @@ #define MULTIBOOT_TAG_TYPE_EFI64_IH 20 #define MULTIBOOT_TAG_TYPE_LOAD_BASE_ADDR 21 +/* Multiboot2 header tag types */ #define MULTIBOOT_HEADER_TAG_END 0 #define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1 #define MULTIBOOT_HEADER_TAG_ADDRESS 2 @@ -76,18 +76,23 @@ #define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 9 #define MULTIBOOT_HEADER_TAG_RELOCATABLE 10 +/* values for Multiboot2 header architecture field */ #define MULTIBOOT_ARCHITECTURE_I386 0 #define MULTIBOOT_ARCHITECTURE_MIPS32 4 + +/* Flag set in the 'flags' member of the multiboot2 header tag. */ #define MULTIBOOT_HEADER_TAG_OPTIONAL 1 +/* Values for the Multiboot2 relocateable header tag preference field */ #define MULTIBOOT_LOAD_PREFERENCE_NONE 0 #define MULTIBOOT_LOAD_PREFERENCE_LOW 1 #define MULTIBOOT_LOAD_PREFERENCE_HIGH 2 +/* Flags for the Multiboot2 (console) flags tag */ #define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1 #define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2 -#ifndef ASM_FILE +#ifndef __ASSEMBLER__ typedef unsigned char multiboot_uint8_t; typedef unsigned short multiboot_uint16_t; @@ -412,6 +417,6 @@ struct multiboot_tag_load_base_addr multiboot_uint32_t load_base_addr; }; -#endif /* ! ASM_FILE */ +#endif /* ! __ASSEMBLER__ */ #endif /* ! MULTIBOOT_HEADER */ -- 2.26.2 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel