Skip to contentSkip to conversation

multiboot2: Clean up the example kernel

PATCH In review Hans Ulrich Niedermann 1 participant 29 messages May 15, 2020 Kbuild

lore
Share & tools
lore
#0 lore raw

v4 cover multiboot2: Clean up the example kernel

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:

.gitignore +17 -13
index 4de19ceee..ba08c2911 100644
@@ -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
Makefile.am +2 -0
index 70eec9cd0..38e797aa7 100644
@@ -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
configure.ac +35 -20

85 lines not on this page · raw message

doc/.gitignore +2 -0
index 847f66f4d..c8f86161e 100644
@@ -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
doc/Makefile.am +35 -5
index 0d896fe10..a382b62be 100644
@@ -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.
doc/boot_i386.S +12 -17
index 1418afe1a..67411b968 100644
@@ -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
doc/boot_mips.S +10 -16
index e7bb7df9f..4d6ac1f67 100644
@@ -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)
doc/kernel.c +2 -2
index c9431e3c0..d555fbe06 100644
@@ -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);
doc/multiboot.texi +2 -2
index 827a5c08d..67f0abd84 100644
@@ -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
 
doc/multiboot2.h +11 -6
index b18160707..f89cd5e77 100644
@@ -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 */
Signature · 1 line
2.26.2
#1 lore raw

PATCH v4 1/27 multiboot2: Allow autogen.sh to run with current gnulib

Current gnulib's gnulib-tool (which is called by autogen.sh) only runs if configure.ac contains at least AC_PREREQ(2.63).

Requiring Autoconf 2.63 (release tagged in 2008-09) instead of Autoconf 2.59 (release 2.59 tagged in 2003-11, 2.59d in 2006-06) should not affect too many systems in 2020.

configure.ac +1 -1
index 585b37a36..8f21b1852 100644
@@ -12,7 +12,7 @@ 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.59)
+AC_PREREQ(2.63)
 AC_INIT([Multiboot], [2.0], [[email protected]])
 AC_CONFIG_SRCDIR([doc/multiboot.texi])
 AC_CONFIG_HEADER([config.h])
Signature · 1 line
2.26.2
#2 lore raw

PATCH v4 2/27 multiboot2: Use .gitignore files

In reply to Hans Ulrich Niedermann

Add .gitignore file and remove the obsolete .bzrignore file.

As gnulib-tool (called from autogen.sh) insists on creating doc/.gitignore (if it does not exist) or updating it (if it is missing some patterns gnulib-tool wants ignored by git), we add a doc/.gitignore file and the gnulib patterns there.

All other ignore patterns should be in the top-level .gitignore file.

 delete mode 100644 .bzrignore
 create mode 100644 .gitignore
 create mode 100644 doc/.gitignore
.bzrignore deleted +0 -30
deleted file mode 100644
index fda459816..000000000
@@ -1,30 +0,0 @@
-gendocs.sh
-lib
-m4
-.deps
-Makefile
-autom4te.cache
-config.cache
-config.h
-config.log
-config.status
-stamp-h
-stamp-h1
-doc/Makefile
-doc/*.info*
-doc/.deps
-doc/gendocs_template
-doc/mdate-sh
-doc/Makefile.in
-doc/boot.S.texi
-doc/kernel
-doc/kernel.c.texi
-doc/multiboot.h.texi
-doc/texinfo.tex
-Makefile.in
-aclocal.m4
-config.h.in
-configure
-depcomp
-install-sh
-missing
.gitignore new file +46 -0

46 lines not on this page · raw message

doc/.gitignore new file +4 -0
new file mode 100644
index 000000000..c8f86161e
@@ -0,0 +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
Signature · 1 line
2.26.2
#3 lore raw

PATCH v4 3/27 multiboot2: Use m4 quoting and AS_HELP_STRING

In reply to Hans Ulrich Niedermann

Use proper m4 quoting throughout configure.ac and use AS_HELP_STRING for the --enable-example-kernel argument.

configure.ac +11 -9
index 8f21b1852..5bfc0ee5b 100644
@@ -12,7 +12,7 @@ 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], [[email protected]])
 AC_CONFIG_SRCDIR([doc/multiboot.texi])
 AC_CONFIG_HEADER([config.h])
@@ -22,7 +22,7 @@ AM_INIT_AUTOMAKE
 # Programs
 #
 
-AC_CHECK_TOOL(CC, gcc)
+AC_CHECK_TOOL([CC], [gcc])
 AC_PROG_CC
 AM_PROG_AS
 # We need this for older versions of Autoconf.
@@ -30,17 +30,19 @@ _AM_DEPENDENCIES(CC)
 
 dnl Because recent automake complains about AS, set it here.
 CCAS="$CC"
-AC_SUBST(CCAS)
+AC_SUBST([CCAS])
 
-dnl Build the example Multiboot kernel.
-AC_ARG_ENABLE(example-kernel,
-  [  --enable-example-kernel
-                          build the example Multiboot kernel])
-AM_CONDITIONAL(BUILD_EXAMPLE_KERNEL, test "x$enable_example_kernel" = xyes)
+dnl Build the example Multiboot2 kernel.
+AC_ARG_ENABLE([example-kernel], [dnl
+AS_HELP_STRING([--enable-example-kernel],
+               [build the example Multiboot2 kernel])])
+
+AM_CONDITIONAL([BUILD_EXAMPLE_KERNEL],
+               [test "x$enable_example_kernel" = xyes])
 
 dnl Because recent automake complains about CCASFLAGS, set it here.
 CCASFLAGS='$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)'
-AC_SUBST(CCASFLAGS)
+AC_SUBST([CCASFLAGS])
 
 CFLAGS="-nostdlib $CFLAGS"
 
Signature · 1 line
2.26.2
#4 lore raw

PATCH v4 4/27 multiboot2: Remove obsolete compat code for ancient Autoconf

In reply to Hans Ulrich Niedermann

The remark about "older versions of Autoconf" was added in 2001.

We already AC_PREREQ(2.63) which is from 2008, so we need not worry about pre-2008 versions of Autoconf, much less about pre-2001 versions.

configure.ac +0 -2
index 5bfc0ee5b..5b5c84d1e 100644
@@ -25,8 +25,6 @@ AM_INIT_AUTOMAKE
 AC_CHECK_TOOL([CC], [gcc])
 AC_PROG_CC
 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"
Signature · 1 line
2.26.2
#5 lore raw

PATCH v4 5/27 multiboot2: Remove CCAS workarounds for pre-2005 Automake

In reply to Hans Ulrich Niedermann

The "recent automake" remark is from 2001, and the AM_PROG_AS issues with CCAS and CCASFLAGS appear to have been solved in the first half of the 2000s.

Just to make sure, require Automake 1.10.1 which was tagged on 2008-08-19 which is a similar vintage as the Autoconf 2.63 version which we already require.

configure.ac +1 -9
index 5b5c84d1e..37b220d0c 100644
@@ -16,7 +16,7 @@ AC_PREREQ([2.63])
 AC_INIT([Multiboot], [2.0], [[email protected]])
 AC_CONFIG_SRCDIR([doc/multiboot.texi])
 AC_CONFIG_HEADER([config.h])
-AM_INIT_AUTOMAKE
+AM_INIT_AUTOMAKE([1.10.1])
 
 #
 # Programs
@@ -26,10 +26,6 @@ AC_CHECK_TOOL([CC], [gcc])
 AC_PROG_CC
 AM_PROG_AS
 
-dnl Because recent automake complains about AS, set it here.
-CCAS="$CC"
-AC_SUBST([CCAS])
-
 dnl Build the example Multiboot2 kernel.
 AC_ARG_ENABLE([example-kernel], [dnl
 AS_HELP_STRING([--enable-example-kernel],
@@ -38,10 +34,6 @@ AS_HELP_STRING([--enable-example-kernel],
 AM_CONDITIONAL([BUILD_EXAMPLE_KERNEL],
                [test "x$enable_example_kernel" = xyes])
 
-dnl Because recent automake complains about CCASFLAGS, set it here.
-CCASFLAGS='$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)'
-AC_SUBST([CCASFLAGS])
-
 CFLAGS="-nostdlib $CFLAGS"
 
 dnl Output.
Signature · 1 line
2.26.2
#6 lore raw

PATCH v4 6/27 multiboot2: Remove unnecessary definition of CC

In reply to Hans Ulrich Niedermann

Remove the unnecessary separate definition of CC by AC_CHECK_TOOL.

AC_CHECK_TOOL(CC, gcc) might have been necessary back in 1999 when this line has been written, but AC_PROG_CC has since taken over defining CC so we do not need AC_CHECK_TOOL for this any more.

configure.ac +0 -1
index 37b220d0c..d8e08597d 100644
@@ -22,7 +22,6 @@ AM_INIT_AUTOMAKE([1.10.1])
 # Programs
 #
 
-AC_CHECK_TOOL([CC], [gcc])
 AC_PROG_CC
 AM_PROG_AS
 
Signature · 1 line
2.26.2
#7 lore raw

PATCH v4 7/27 multiboot2: Automake generates dependencies automatically

In reply to Hans Ulrich Niedermann

Remove manual dependency line for boot.o.

This line was written in 2001-01. Some time after that, Automake has gained the capability of automatically tracking source code dependencies.

Also, the actual object file Automake builds would be called kernel-boot.o, so a dependency rule for boot.o is useless anyway.

doc/Makefile.am +0 -2
index 2a5afd95d..a65b452cf 100644
@@ -13,8 +13,6 @@ kernel_SOURCES = $(EXAMPLES)
 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
 
 EXTRA_DIST = $(man_MANS) $(noinst_SCRIPTS) \
Signature · 1 line
2.26.2
#8 lore raw

PATCH v4 8/27 multiboot2: Automake cleans built programs automatically

In reply to Hans Ulrich Niedermann

The "CLEANFILES = $(noinst_PROGRAMS)" definition is from 2001-01, and Automake has learned to clean up generated files automatically since, so we can remove this.

doc/Makefile.am +0 -1
index a65b452cf..dc7816d9f 100644
@@ -17,7 +17,6 @@ endif
 
 EXTRA_DIST = $(man_MANS) $(noinst_SCRIPTS) \
 	$(EXAMPLES) $(multiboot_TEXINFOS)
-CLEANFILES = $(noinst_PROGRAMS)
 
 # Cancel the rule %.texi -> %. This rule may confuse make to determine
 # the dependecies.
Signature · 1 line
2.26.2
#9 lore raw

PATCH v4 9/27 multiboot2: Use the constants by their proper names

In reply to Hans Ulrich Niedermann

In the i386 boot.S file, use the constants with the names multiboot2.h actually defines them as, and which boot_mips.S has been using already.

doc/boot.S +2 -2
index 8f6f66fcc..9ab016612 100644
@@ -50,11 +50,11 @@ multiboot_header:
 	/* magic */
 	.long	MULTIBOOT2_HEADER_MAGIC
 	/* ISA: i386 */
-	.long   GRUB_MULTIBOOT_ARCHITECTURE_I386
+	.long   MULTIBOOT_ARCHITECTURE_I386
 	/* Header length.  */
 	.long	multiboot_header_end - multiboot_header
 	/* checksum */
-	.long	-(MULTIBOOT2_HEADER_MAGIC + GRUB_MULTIBOOT_ARCHITECTURE_I386 + (multiboot_header_end - multiboot_header))
+	.long	-(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + (multiboot_header_end - multiboot_header))
 #ifndef __ELF__
 address_tag_start:	
 	.short MULTIBOOT_HEADER_TAG_ADDRESS
Signature · 1 line
2.26.2
#10 lore raw

PATCH v4 10/27 multiboot2: Rename boot.S to boot_i386.S

In reply to Hans Ulrich Niedermann

The file boot.S contains only i386 specific code. Rename the file to boot_i386.S following the pattern of having the mips specific code in the boot_mips.S file.

 rename doc/{boot.S => boot_i386.S} (100%)
doc/Makefile.am +1 -1
index dc7816d9f..d9efe8116 100644
@@ -1,6 +1,6 @@
 info_TEXINFOS = multiboot.texi
 EXAMPLES = boot_mips.S kernel.c multiboot2.h
-multiboot_TEXINFOS = boot.S.texi kernel.c.texi multiboot2.h.texi
+multiboot_TEXINFOS = boot_i386.S.texi kernel.c.texi multiboot2.h.texi
 SRC2TEXI = src2texi
 noinst_SCRIPTS = $(SRC2TEXI)
 EXTRA_PROGRAMS = kernel
doc/boot_i386.S renamed from doc/boot.S +0 -0
similarity index 100%
rename from doc/boot.S
rename to doc/boot_i386.S
doc/multiboot.texi +7 -7
index df8a0d056..b89b12272 100644
@@ -1553,9 +1553,9 @@ Multiboot2-compliant boot loader and for reference to how to implement a
 Multiboot2 kernel. The source files can be found under the directory
 @file{doc} in the Multiboot2 source distribution.
 
-The kernel @file{kernel} consists of only three files: @file{boot.S},
+The kernel @file{kernel} consists of only three files: @file{boot_i386.S},
 @file{kernel.c} and @file{multiboot2.h}. The assembly source
-@file{boot.S} is written in GAS (@pxref{Top, , GNU assembler, as.info,
+@file{boot_i386.S} is written in GAS (@pxref{Top, , GNU assembler, as.info,
 The GNU assembler}), and contains the Multiboot2 information structure to
 comply with the specification. When a Multiboot2-compliant boot loader
 loads and execute it, it initialize the stack pointer and @code{EFLAGS},
@@ -1571,7 +1571,7 @@ information structure.
 
 @menu
 * multiboot2.h::                 
-* boot.S::                      
+* boot_i386.S::
 * kernel.c::                    
 * Other Multiboot2 kernels::
 @end menu
@@ -1587,13 +1587,13 @@ This is the source code in the file @file{multiboot2.h}:
 @end example
 
 
-@node boot.S
-@subsection boot.S
+@node boot_i386.S
+@subsection boot_i386.S
 
-In the file @file{boot.S}:
+In the file @file{boot_i386.S}:
 
 @example
-@include boot.S.texi
+@include boot_i386.S.texi
 @end example
 
 
Signature · 1 line
2.26.2
#11 lore raw

PATCH v4 11/27 multiboot2: Add boot_i386.S to shipped files

In reply to Hans Ulrich Niedermann

Ship the boot_i386.S file in the dist tarball as well, not just the boot_mips.S file.

doc/Makefile.am +3 -3
index d9efe8116..e88f4d271 100644
@@ -1,5 +1,5 @@
 info_TEXINFOS = multiboot.texi
-EXAMPLES = boot_mips.S kernel.c multiboot2.h
+arch_sources = boot_i386.S boot_mips.S
 multiboot_TEXINFOS = boot_i386.S.texi kernel.c.texi multiboot2.h.texi
 SRC2TEXI = src2texi
 noinst_SCRIPTS = $(SRC2TEXI)
@@ -9,14 +9,14 @@ pkginclude_HEADERS = multiboot2.h
 # The example kernel is built if you specify --enable-example-kernel.
 if BUILD_EXAMPLE_KERNEL
 noinst_PROGRAMS = kernel
-kernel_SOURCES = $(EXAMPLES)
+kernel_SOURCES = boot_mips.S kernel.c multiboot2.h
 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
 endif
 
 EXTRA_DIST = $(man_MANS) $(noinst_SCRIPTS) \
-	$(EXAMPLES) $(multiboot_TEXINFOS)
+	$(arch_sources) $(multiboot_TEXINFOS)
 
 # Cancel the rule %.texi -> %. This rule may confuse make to determine
 # the dependecies.
Signature · 1 line
2.26.2
#12 lore raw

PATCH v4 12/27 multiboot2: Add boot_mips.S example code to docs

In reply to Hans Ulrich Niedermann

Add the boot_mips.S file to the example code documentation.

Before this, while boot_mips.S was the boot code always built, boot_i386.S was the only documented boot code.

Now both boot_i386.S and boot_mips.S are in the docs, with the build situation remaining unchanged.

doc/Makefile.am +1 -1
index e88f4d271..08fdbf342 100644
@@ -1,6 +1,6 @@
 info_TEXINFOS = multiboot.texi
 arch_sources = boot_i386.S boot_mips.S
-multiboot_TEXINFOS = boot_i386.S.texi kernel.c.texi multiboot2.h.texi
+multiboot_TEXINFOS = boot_i386.S.texi boot_mips.S.texi kernel.c.texi multiboot2.h.texi
 SRC2TEXI = src2texi
 noinst_SCRIPTS = $(SRC2TEXI)
 EXTRA_PROGRAMS = kernel
doc/multiboot.texi +30 -15

61 lines not on this page · raw message

Signature · 1 line
2.26.2
#13 lore raw

PATCH v4 13/27 multiboot2: Build arch specific boot code

In reply to Hans Ulrich Niedermann

Choose the arch specific bootcode for i386 or mips, depending on what --host is being built for.

Before this, boot_i386.S and boot_mips.S were both in the docs, but boot_mips.S was the boot code always built regardless of the actual system being built for.

If the --host system is neither i386 (or x86_64 which is switched into 32bit mode) or mips, the example kernel build will be skipped.

The mips definitions for kernel_ccasflags and kernel_cflags are completely untested.

.gitignore +2 -0
index 631ff668d..e27a3e0e2 100644
@@ -7,7 +7,9 @@ Makefile.in
 /aclocal.m4
 /autom4te.cache/
 /compile
+/config.guess
 /config.h.in
+/config.sub
 /configure
 /depcomp
 /doc/mdate-sh
configure.ac +26 -2
index d8e08597d..830b1f57e 100644
@@ -25,13 +25,37 @@ AM_INIT_AUTOMAKE([1.10.1])
 AC_PROG_CC
 AM_PROG_AS
 
-dnl Build the example Multiboot2 kernel.
+dnl Build the example Multiboot2 kernel (if possible on this host)
+AC_CANONICAL_HOST
+kernel_boot_arch=unsupported
+kernel_ccasflags=
+kernel_cflags=
+case "$host_cpu" in #(
+  i[[3456]]86)
+    kernel_boot_arch=i386
+    ;; #(
+  x86_64)
+    kernel_boot_arch=i386
+    kernel_ccasflags="-m32"
+    kernel_cflags="-m32"
+    ;; #(
+  mips*)
+    kernel_boot_arch=mips
+    kernel_ccasflags="-mabi=32"
+    kernel_cflags="-mabi=32"
+    ;;
+esac
+AC_SUBST([kernel_boot_arch])
+AC_SUBST([kernel_ccasflags])
+AC_SUBST([kernel_cflags])
+
 AC_ARG_ENABLE([example-kernel], [dnl
 AS_HELP_STRING([--enable-example-kernel],
                [build the example Multiboot2 kernel])])
 
 AM_CONDITIONAL([BUILD_EXAMPLE_KERNEL],
-               [test "x$enable_example_kernel" = xyes])
+               [test "x$enable_example_kernel" = xyes &&
+                test "x$kernel_boot_arch" != "xunsupported"])
 
 CFLAGS="-nostdlib $CFLAGS"
 
doc/Makefile.am +3 -2
index 08fdbf342..b19fc24bf 100644
@@ -9,8 +9,9 @@ pkginclude_HEADERS = multiboot2.h
 # The example kernel is built if you specify --enable-example-kernel.
 if BUILD_EXAMPLE_KERNEL
 noinst_PROGRAMS = kernel
-kernel_SOURCES = boot_mips.S kernel.c multiboot2.h
-kernel_CFLAGS = -fno-builtin -nostdinc -O -g -Wall \
+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
 endif
Signature · 1 line
2.26.2
#14 lore raw

PATCH v4 14/27 multiboot2: Fix example kernel header tag alignment

In reply to Hans Ulrich Niedermann

Properly align all Multiboot2 header tags to 8 byte boundaries as per the Multiboot2 specification.

Note that the assembler directive ".align 8" is machine
dependent: On i386, it means "align to 8 byte boundary". On mips, it means that the lower 8 bits of address must be zero, i.e. ".align 8" aligns to a 256 byte boundary!

Therefore, this changes boot_mips.S to use ".balign 8" where it had mistakenly used ".align 8" before, and boot_i386.S to use ".balign 8" as well for consistency.

Note also that the Multiboot2 header termination tag (not labeled in the source) actually needs that explicit alignment to an 8 byte boundary in the example kernel, as the preceding tag (framebuffer_tag_start) is 20 bytes long which is not a multiple of 8 bytes.

You can add "-Wa,-adhlns=$(@:.o=.lst)" to kernel_CCASFLAGS to generate a listing file which shows the offsets of the labels in the boot_*.S files to verify the alignment issues.

Note also that you cannot detect the wrong header tag alignment using the "grub-file --is-x86-multiboot2" utility. It only considers the Multiboot2 header magic fields while completely ignoring the Multiboot2 header tags.

doc/boot_i386.S +5 -1
index 9ab016612..0e8118b2a 100644
@@ -43,7 +43,7 @@ _start:
 	jmp	multiboot_entry
 
 	/* Align 64 bits boundary.  */
-	.align	8
+	.balign	8
 	
 	/* Multiboot header.  */
 multiboot_header:
@@ -56,6 +56,7 @@ multiboot_header:
 	/* checksum */
 	.long	-(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + (multiboot_header_end - multiboot_header))
 #ifndef __ELF__
+	.balign	8
 address_tag_start:	
 	.short MULTIBOOT_HEADER_TAG_ADDRESS
 	.short MULTIBOOT_HEADER_TAG_OPTIONAL
@@ -69,6 +70,7 @@ address_tag_start:
 	/* bss_end_addr */
 	.long	_end
 address_tag_end:
+	.balign	8
 entry_address_tag_start:	
 	.short MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS
 	.short MULTIBOOT_HEADER_TAG_OPTIONAL
@@ -77,6 +79,7 @@ entry_address_tag_start:
 	.long multiboot_entry
 entry_address_tag_end:
 #endif /* __ELF__ */
+	.balign	8
 framebuffer_tag_start:	
 	.short MULTIBOOT_HEADER_TAG_FRAMEBUFFER
 	.short MULTIBOOT_HEADER_TAG_OPTIONAL
@@ -85,6 +88,7 @@ framebuffer_tag_start:
 	.long 768
 	.long 32
 framebuffer_tag_end:
+	.balign	8
 	.short MULTIBOOT_HEADER_TAG_END
 	.short 0
 	.long 8
doc/boot_mips.S +6 -2
index ed604214d..a8d3fb0e4 100644
@@ -46,7 +46,7 @@ _start:
 	 nop
 
 	/* Align 64 bits boundary.  */
-	.align	8
+	.balign	8
 	
 	/* Multiboot header.  */
 multiboot_header:
@@ -59,6 +59,7 @@ multiboot_header:
 	/* checksum */
 	.long	-(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_MIPS32 + (multiboot_header_end - multiboot_header))
 #ifndef __ELF__
+	.balign	8
 address_tag_start:	
 	.short MULTIBOOT_HEADER_TAG_ADDRESS
 	.short MULTIBOOT_HEADER_TAG_OPTIONAL
@@ -72,6 +73,7 @@ address_tag_start:
 	/* bss_end_addr */
 	.long	_end
 address_tag_end:
+	.balign	8
 entry_address_tag_start:	
 	.short MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS
 	.short MULTIBOOT_HEADER_TAG_OPTIONAL
@@ -80,6 +82,7 @@ entry_address_tag_start:
 	.long multiboot_entry
 entry_address_tag_end:
 #endif /* __ELF__ */
+	.balign	8
 framebuffer_tag_start:	
 	.short MULTIBOOT_HEADER_TAG_FRAMEBUFFER
 	.short MULTIBOOT_HEADER_TAG_OPTIONAL
@@ -88,6 +91,7 @@ framebuffer_tag_start:
 	.long 768
 	.long 32
 framebuffer_tag_end:
+	.balign	8
 	.short MULTIBOOT_HEADER_TAG_END
 	.short 0
 	.long 8
@@ -114,6 +118,6 @@ loop:	nop
 halt_message:
 	.asciz	"Halted."
 
-	.align 8
+	.balign 8
 	/* Our stack area.  */
 	.comm	stack, STACK_SIZE
Signature · 1 line
2.26.2
#15 lore raw

PATCH v4 15/27 multiboot2: Remove unreferenced AOUT_KLUDGE

In reply to Hans Ulrich Niedermann

Remove unreferenced AOUT_KLUDGE from both boot_i386.S and boot_mips.S.

There is no reference in the example kernel to AOUT_KLUDGE or MULTIBOOT_AOUT_KLUDGE, so this has never had a function in the Multiboot 2 example kernel.

I presume this was something left over from the Multiboot 1 specification's example kernel.

doc/boot_i386.S +0 -7
index 0e8118b2a..c6e7f1382 100644
@@ -28,13 +28,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
doc/boot_mips.S +0 -7
index a8d3fb0e4..2b9ee0f9c 100644
@@ -28,13 +28,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
 	.set noreorder
         .set nomacro
Signature · 1 line
2.26.2
#16 lore raw

PATCH v4 16/27 multiboot2: Change "Multiboot" in comments to "Multiboot2"

In reply to Hans Ulrich Niedermann

In source code comments, change "Multiboot" to "Multiboot2".

This forced us to touch the completely wrongly placed comment on the 'flags' in multiboot2.h, so we have moved that comment where it belongs and added comments for the groups of macro definitions which now had no comments at all.

doc/boot_i386.S +2 -2
index c6e7f1382..20a600a6e 100644
@@ -38,7 +38,7 @@ _start:
 	/* Align 64 bits boundary.  */
 	.balign	8
 	
-	/* Multiboot header.  */
+	/* Multiboot2 header.  */
 multiboot_header:
 	/* magic */
 	.long	MULTIBOOT2_HEADER_MAGIC
@@ -94,7 +94,7 @@ 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
doc/boot_mips.S +1 -1
index 2b9ee0f9c..3f99c81a0 100644
@@ -41,7 +41,7 @@ _start:
 	/* Align 64 bits boundary.  */
 	.balign	8
 	
-	/* Multiboot header.  */
+	/* Multiboot2 header.  */
 multiboot_header:
 	/* magic */
 	.long	MULTIBOOT2_HEADER_MAGIC
doc/kernel.c +2 -2
index c9431e3c0..d555fbe06 100644
@@ -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);
doc/multiboot2.h +9 -4
index b18160707..d3b03d7a1 100644
@@ -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,14 +76,19 @@
 #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
 
Signature · 1 line
2.26.2
#17 lore raw

PATCH v4 17/27 multiboot2: Clean up stack (cdecl calling conventions)

In reply to Hans Ulrich Niedermann

Clean up the stack after calling C functions according to the i386 cdecl calling conventions.

doc/boot_i386.S +2 -0
index 20a600a6e..14dc14660 100644
@@ -101,10 +101,12 @@ multiboot_entry:
 
 	/* 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
Signature · 1 line
2.26.2
#18 lore raw

PATCH v4 18/27 multiboot2: Use predefined #ifdef __ASSEMBLER__

In reply to Hans Ulrich Niedermann

GCC already predefines __ASSEMBLER__ for .S files (assembly with C preprocessor), so we can just use that instead of defining our own ASM_FILE macro.

doc/boot_i386.S +0 -1
index 14dc14660..2aa2a92b6 100644
@@ -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.  */
doc/boot_mips.S +0 -1
index 3f99c81a0..b59e3fd6a 100644
@@ -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.  */
doc/multiboot2.h +2 -2
index d3b03d7a1..f89cd5e77 100644
@@ -92,7 +92,7 @@
 #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;
@@ -417,6 +417,6 @@ struct multiboot_tag_load_base_addr
   multiboot_uint32_t load_base_addr;
 };
 
-#endif /* ! ASM_FILE */
+#endif /* ! __ASSEMBLER__ */
 
 #endif /* ! MULTIBOOT_HEADER */
Signature · 1 line
2.26.2
#19 lore raw

PATCH v4 19/27 multiboot2: Set -nostdlib before AC_PROG_CC for x-compile

In reply to Hans Ulrich Niedermann

Set -nostdlib in CFLAGS and LDFLAGS before AC_PROG_CC if we appear to be cross-compiling.

This makes the example kernel build work on my x86_64 system with both

* native compile to generate i386 example kernel

       ./configure --enable-example-kernel

* cross-compile to generate mips example kernel

       ./configure --host=mips64-linux-gnu --enable-example-kernel

It remains to be verified how this works on other systems, namely native mips systems, and non-x86 systems like arm.

configure.ac +8 -3
index 830b1f57e..6b0718451 100644
@@ -22,11 +22,18 @@ AM_INIT_AUTOMAKE([1.10.1])
 # Programs
 #
 
+AC_CANONICAL_BUILD
+AC_CANONICAL_HOST
+
+AS_IF([test "x$host" != "x$build"], [dnl
+  CFLAGS="-nostdlib $CFLAGS"
+  LDFLAGS="-nostdlib $LDFLAGS"
+])
+
 AC_PROG_CC
 AM_PROG_AS
 
 dnl Build the example Multiboot2 kernel (if possible on this host)
-AC_CANONICAL_HOST
 kernel_boot_arch=unsupported
 kernel_ccasflags=
 kernel_cflags=
@@ -57,8 +64,6 @@ AM_CONDITIONAL([BUILD_EXAMPLE_KERNEL],
                [test "x$enable_example_kernel" = xyes &&
                 test "x$kernel_boot_arch" != "xunsupported"])
 
-CFLAGS="-nostdlib $CFLAGS"
-
 dnl Output.
 AC_CONFIG_FILES([Makefile doc/Makefile])
 AC_OUTPUT
Signature · 1 line
2.26.2
#20 lore raw

PATCH v4 20/27 multiboot2: mips build wants __start symbol

In reply to Hans Ulrich Niedermann

When building the example kernel for mips, there is a warning about __start being undefined and some default address being chosen as start address.

As this does not inspire confidence, we add a __start symbol at the same place where start and _start are already defined.

Now the mips build builds nicely.

doc/boot_mips.S +2 -1
index b59e3fd6a..a6881528f 100644
@@ -31,9 +31,10 @@
 	.set noreorder
         .set nomacro
 
-	.globl	start, _start
+	.globl	start, _start, __start
 start:
 _start:
+__start:
 	b	multiboot_entry
 	 nop
 
Signature · 1 line
2.26.2
#21 lore raw

PATCH v4 21/27 multiboot2: "make distcheck" with example kernel enabled

In reply to Hans Ulrich Niedermann

Even if no one ever does a tarball release of the Multiboot2 spec, "make distcheck" is a good way of checking the build system's integrity.

Makefile.am +2 -0
index 70eec9cd0..38e797aa7 100644
@@ -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
Signature · 1 line
2.26.2
#22 lore raw

PATCH v4 22/27 multiboot2: Always define the kernel_* vars

In reply to Hans Ulrich Niedermann

Always define the kernel_* vars independent of the BUILD_EXAMPLE_KERNEL conditional. This should make sure that we actually distribute the kernel sources even when we are not building the example kernel.

Note that this does not mean we always *build* the example kernel. EXTRA_PROGRAMS are *not* built when running "make all".

We still only build "if BUILD_EXAMPLE_KERNEL", which is when noinst_PROGRAMS is set.

doc/Makefile.am +2 -1
index b19fc24bf..cb290a0cb 100644
@@ -9,12 +9,13 @@ 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
-endif
 
 EXTRA_DIST = $(man_MANS) $(noinst_SCRIPTS) \
 	$(arch_sources) $(multiboot_TEXINFOS)
Signature · 1 line
2.26.2
#23 lore raw

PATCH v4 23/27 multiboot2: Generate per object file listings

In reply to Hans Ulrich Niedermann

Generate one listing file *.lst per object file *.o.

This allows easy examination of the generated machine code, making the example kernel more educational.

.gitignore +1 -0
index e27a3e0e2..7a035c267 100644
@@ -30,6 +30,7 @@ Makefile
 /stamp-h1
 
 # Generated by "make"
+*.lst
 *.o
 
 /doc/*.S.texi
doc/Makefile.am +5 -0
index cb290a0cb..cc07ceec8 100644
@@ -1,3 +1,4 @@
+CLEANFILES =
 info_TEXINFOS = multiboot.texi
 arch_sources = boot_i386.S boot_mips.S
 multiboot_TEXINFOS = boot_i386.S.texi boot_mips.S.texi kernel.c.texi multiboot2.h.texi
@@ -17,6 +18,10 @@ 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
 
+CLEANFILES       += *.lst
+kernel_CCASFLAGS += -Wa,-adhlns=$(@:.o=.lst)
+kernel_CFLAGS    += -Wa,-adhlns=$(@:.o=.lst)
+
 EXTRA_DIST = $(man_MANS) $(noinst_SCRIPTS) \
 	$(arch_sources) $(multiboot_TEXINFOS)
 
Signature · 1 line
2.26.2
#24 lore raw

Re: [MULTIBOOT2 SPEC PATCH v4 23/27] multiboot2: Generate per object file listings

I have just noticed that when running the multiboot2 build with "configure CC=clang" instead of going with the default gcc, clang10 will not recognize the "-Wa,-adhlns=$(@:.o=.lst)" argument and abort.

Ist clang support for the multiboot2 example kernel important? If so, I could either comment out those parameter additions, or guard them with a check for adhlns support and an AM_CONDITIONAL in configure.ac.

Am 15. Mai 2020 05:43:46 MESZ schrieb Hans Ulrich Niedermann <[email protected]>:

Quoted 50 lines

Generate one listing file *.lst per object file *.o.

This allows easy examination of the generated machine code, making the example kernel more educational.

.gitignore +0 -0
index e27a3e0e2..7a035c267 100644
@@ -30,6 +30,7 @@ Makefile

/stamp-h1

# Generated by "make"
+*.lst
*.o

/doc/*.S.texi

doc/Makefile.am +1 -0
index cb290a0cb..cc07ceec8 100644
@@ -1,3 +1,4 @@
+CLEANFILES =

info_TEXINFOS = multiboot.texi
arch_sources = boot_i386.S boot_mips.S
multiboot_TEXINFOS = boot_i386.S.texi boot_mips.S.texi kernel.c.texi multiboot2.h.texi

doc/Makefile.am +0 -1
@@ -17,6 +18,10 @@ kernel_CFLAGS = $(kernel_cflags) -fno-builtin
-nostdinc -O -g -Wall \
 	-imacros $(top_builddir)/config.h

kernel_LDFLAGS = -nostdlib -Wl,-N -Wl,-Ttext -Wl,80100000

doc/Makefile.am +4 -1
-Wl,--build-id=none
 
+CLEANFILES       += *.lst
+kernel_CCASFLAGS += -Wa,-adhlns=$(@:.o=.lst)
+kernel_CFLAGS    += -Wa,-adhlns=$(@:.o=.lst)
+
EXTRA_DIST = $(man_MANS) $(noinst_SCRIPTS) \
	$(arch_sources) $(multiboot_TEXINFOS)
Signature · 7 lines
2.26.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#25 lore raw

PATCH v4 24/27 multiboot2: Generate a kernel.map map file

In reply to Hans Ulrich Niedermann

Generate a kernel.map map file for the example kernel.

This helps with examining the generated machine code, making the example kernel more educational.

.gitignore +1 -0
index 7a035c267..889e17f69 100644
@@ -37,6 +37,7 @@ Makefile
 /doc/*.c.texi
 /doc/*.h.texi
 /doc/kernel
+/doc/kernel.map
 /doc/multiboot.info*
 /doc/stamp-vti
 /doc/version.texi
doc/Makefile.am +3 -0
index cc07ceec8..21cdff0b2 100644
@@ -18,6 +18,9 @@ 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
 
+CLEANFILES     += kernel.map
+kernel_LDFLAGS += -Wl,-Map,kernel.map
+
 CLEANFILES       += *.lst
 kernel_CCASFLAGS += -Wa,-adhlns=$(@:.o=.lst)
 kernel_CFLAGS    += -Wa,-adhlns=$(@:.o=.lst)
Signature · 1 line
2.26.2
#26 lore raw

PATCH v4 25/27 multiboot2: Generate gcc temp files (*.i and *.s)

In reply to Hans Ulrich Niedermann

Generate gcc temporary files for each object file, showing the intermediate steps after the C preprocessor and immediately before assembly.

This helps with examining how the example kernel code is generated, making the example kernel more educational.

.gitignore +2 -0
index 889e17f69..f6a1b7736 100644
@@ -31,7 +31,9 @@ Makefile
 
 # Generated by "make"
 *.lst
+*.i
 *.o
+*.s
 
 /doc/*.S.texi
 /doc/*.c.texi
doc/Makefile.am +4 -0
index 21cdff0b2..fe1e473c9 100644
@@ -25,6 +25,10 @@ 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) \
 	$(arch_sources) $(multiboot_TEXINFOS)
 
Signature · 1 line
2.26.2
#27 lore raw

PATCH v4 26/27 multiboot2: Generate symbol lists and disassembly file

In reply to Hans Ulrich Niedermann

Generate symbol lists (kernel.sym with nm and kernel.vsym with objdump) and a complete disassembly of the finished kernel image.

This helps with examining how the built kernel image is actually linked and what parts of the code and data have ended up where.

This makes the example kernel more educational.

.gitignore +3 -0
index f6a1b7736..ba08c2911 100644
@@ -39,7 +39,10 @@ Makefile
 /doc/*.c.texi
 /doc/*.h.texi
 /doc/kernel
+/doc/kernel.lss
 /doc/kernel.map
+/doc/kernel.sym
+/doc/kernel.vsym
 /doc/multiboot.info*
 /doc/stamp-vti
 /doc/version.texi
configure.ac +20 -0
index 6b0718451..e70da14d0 100644
@@ -31,8 +31,28 @@ AS_IF([test "x$host" != "x$build"], [dnl
 ])
 
 AC_PROG_CC
+AC_PROG_GREP
 AM_PROG_AS
 
+AC_ARG_VAR([NM], [nm tool])
+AC_CHECK_TOOL([NM], [nm])
+
+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=
doc/Makefile.am +20 -0
index fe1e473c9..a382b62be 100644
@@ -32,6 +32,26 @@ kernel_CFLAGS    += -save-temps=obj
 EXTRA_DIST = $(man_MANS) $(noinst_SCRIPTS) \
 	$(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.
 .texi:
Signature · 1 line
2.26.2
#28 lore raw

PATCH v4 27/27 multiboot2: Add labels around the termination tag

In reply to Hans Ulrich Niedermann

For code consistency and more clarity as to what these .short and .long values actually are, use the same system for labeling the terminator header tag as for labeling all other header tags.

This improves the readability of the code, without changing the actual output.

doc/boot_i386.S +3 -1
index 2aa2a92b6..67411b968 100644
@@ -81,9 +81,11 @@ 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.  */
doc/boot_mips.S +3 -1
index a6881528f..4d6ac1f67 100644
@@ -85,9 +85,11 @@ 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.  */
Signature · 1 line
2.26.2