Skip to contentSkip to conversation

multiboot2: Clean up the example kernel

PATCH Superseded Hans Ulrich Niedermann 2 participants 13 messages May 8, 2020 – May 14, 2020

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover multiboot2: Clean up the example kernel

This cleans up the Multiboot2 example kernel in a few ways:

* It fixes the build with current gnulib.

* Change from obsolete .bzrignore to .gitignore.

* It fixes the build on non-MIPS systems such as x86.

* It fixes the Multiboot2 header tag alignment in the assembly language boot_*.S files to 8 byte boundaries.

* It fixes the alignment in boot_mips.S to align to 8 byte boundaries instead of 256 byte boundaries.

This is v3 of a previous patch set. The differences mainly are

* improved .gitignore

* fix the case logic for the ix86 matching pattern ([[]])

* fix mb2 header tag alignment

* fix alignment on mips

I am posting this right now to make clear that my previous patch set version v1/v2 had issues, but this v3 certainly can use some improvement as well. Also, this is not very urgent, so putting this off until after the next GRUB release is very reasonable.

Hans Ulrich Niedermann (4):
multiboot2: Allow autogen.sh to run with current gnulib
multiboot2: Use .gitignore files
multiboot2: Make example kernel build at least for i386
multiboot2: fix example kernel header tag alignment

 .bzrignore                  | 30 -------------------
 .gitignore                  | 51 ++++++++++++++++++++++++++++++++
 configure.ac                | 37 +++++++++++++++++++----
 doc/.gitignore              |  2 ++
 doc/Makefile.am             |  9 +++---
 doc/{boot.S => boot_i386.S} |  9 ++++--
 doc/boot_mips.S             | 17 +++++++----
 doc/multiboot.texi          | 59 +++++++++++++++++++++++--------------
 8 files changed, 144 insertions(+), 70 deletions(-)
 delete mode 100644 .bzrignore
 create mode 100644 .gitignore
 create mode 100644 doc/.gitignore
 rename doc/{boot.S => boot_i386.S} (93%)

Interdiff:

.gitignore +13 -5
index bd387ea77..4de19ceee 100644
@@ -1,4 +1,4 @@
-# Generated by autogen.sh
+# Generated by "autogen.sh"
 /gendocs.sh
 /lib/
 /m4/
@@ -6,6 +6,8 @@
 /NEWS
 /README
 
+Makefile.in
+
 /aclocal.m4
 /autom4te.cache/
 /compile
@@ -20,9 +22,7 @@
 /INSTALL
 /missing
 
-Makefile.in
-
-# Generated by configure
+# Generated by "configure"
 Makefile
 .deps/
 
@@ -31,7 +31,7 @@ Makefile
 /config.status
 /stamp-h1
 
-# Generated by make
+# Generated by "make"
 /doc/*.c.texi
 /doc/*.h.texi
 /doc/*.S.texi
@@ -40,4 +40,12 @@ Makefile
 /doc/version.texi
 
 *.o
+
 /doc/kernel
+
+# Generated by "make web-manual"
+/doc/manual/
+/doc/multiboot.aux
+/doc/multiboot.cp
+/doc/multiboot.log
+/doc/multiboot.toc
configure.ac +17 -11
index ee648f52a..5ddb16b72 100644
@@ -34,17 +34,23 @@ AC_SUBST(CCAS)
 
 dnl Build the example Multiboot kernel (if possible on this host)
 AC_CANONICAL_HOST
-case "$host" 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_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_boot_arch=unsupported
+    ;;
 esac
 AC_SUBST([kernel_boot_arch])
 AC_SUBST([kernel_ccasflags])
doc/boot_i386.S +5 -0
index 9ab016612..1418afe1a 100644
@@ -56,6 +56,7 @@ multiboot_header:
 	/* checksum */
 	.long	-(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + (multiboot_header_end - multiboot_header))
 #ifndef __ELF__
+	.align	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:
+	.align	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__ */
+	.align	8
 framebuffer_tag_start:	
 	.short MULTIBOOT_HEADER_TAG_FRAMEBUFFER
 	.short MULTIBOOT_HEADER_TAG_OPTIONAL
@@ -85,10 +88,12 @@ framebuffer_tag_start:
 	.long 768
 	.long 32
 framebuffer_tag_end:
+	.align	8
 	.short MULTIBOOT_HEADER_TAG_END
 	.short 0
 	.long 8
 multiboot_header_end:
+
 multiboot_entry:
 	/* Initialize the stack pointer.  */
 	movl	$(stack + STACK_SIZE), %esp
doc/boot_mips.S +11 -6
index ed604214d..e7bb7df9f 100644
@@ -46,8 +46,8 @@ _start:
 	 nop
 
 	/* Align 64 bits boundary.  */
-	.align	8
-	
+	.balign	8
+
 	/* Multiboot header.  */
 multiboot_header:
 	/* magic */
@@ -59,7 +59,8 @@ multiboot_header:
 	/* checksum */
 	.long	-(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_MIPS32 + (multiboot_header_end - multiboot_header))
 #ifndef __ELF__
-address_tag_start:	
+	.balign	8
+address_tag_start:
 	.short MULTIBOOT_HEADER_TAG_ADDRESS
 	.short MULTIBOOT_HEADER_TAG_OPTIONAL
 	.long address_tag_end - address_tag_start
@@ -72,7 +73,8 @@ address_tag_start:
 	/* bss_end_addr */
 	.long	_end
 address_tag_end:
-entry_address_tag_start:	
+	.balign	8
+entry_address_tag_start:
 	.short MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS
 	.short MULTIBOOT_HEADER_TAG_OPTIONAL
 	.long entry_address_tag_end - entry_address_tag_start
@@ -80,7 +82,8 @@ entry_address_tag_start:
 	.long multiboot_entry
 entry_address_tag_end:
 #endif /* __ELF__ */
-framebuffer_tag_start:	
+	.balign	8
+framebuffer_tag_start:
 	.short MULTIBOOT_HEADER_TAG_FRAMEBUFFER
 	.short MULTIBOOT_HEADER_TAG_OPTIONAL
 	.long framebuffer_tag_end - framebuffer_tag_start
@@ -88,10 +91,12 @@ framebuffer_tag_start:
 	.long 768
 	.long 32
 framebuffer_tag_end:
+	.balign	8
 	.short MULTIBOOT_HEADER_TAG_END
 	.short 0
 	.long 8
 multiboot_header_end:
+
 multiboot_entry:
 	/* Initialize the stack pointer.  */
 	lui     $sp, %hi (stack + STACK_SIZE)
@@ -114,6 +119,6 @@ loop:	nop
 halt_message:
 	.asciz	"Halted."
 
-	.align 8
+	.balign 8
 	/* Our stack area.  */
 	.comm	stack, STACK_SIZE
doc/multiboot.texi +4 -4
index c70d9239e..827a5c08d 100644
@@ -1566,12 +1566,12 @@ executes @file{boot_*.S}, it initializes the stack pointer and
 
 If @code{cmain} returns to the callee, then it shows a message to
 inform the user of the halt state and stops forever until you push the
-reset key. The file @file{kernel.c} contains the function
+system reset button. The file @file{kernel.c} contains the function
 @code{cmain}, which checks if the magic number passed by the boot
 loader is valid and so on, and some functions to print messages on the
-screen. The file @file{multiboot2.h} defines some macros, such as the
-magic number for the Multiboot2 header, the Multiboot2 header
-structure and the Multiboot2 information structure.
+screen. The file @file{multiboot2.h} defines some C preprocessor
+macros, such as the magic number for the Multiboot2 header, the
+Multiboot2 header structure and the Multiboot2 information structure.
 
 @menu
 * multiboot2.h::
Signature · 1 line
2.26.2
#1 lore raw

PATCH v3 1/4 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
Reviewed-by on v3 1/4
#2 lore raw

Re: [MULTIBOOT2 SPEC PATCH v3 1/4] multiboot2: Allow autogen.sh to run with current gnulib

Quoted 8 lines · Hans Ulrich Niedermann

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.

Daniel

#3 lore raw

PATCH v3 2/4 multiboot2: Use .gitignore files

In reply to Hans Ulrich Niedermann

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

The doc/.gitignore file is generated by gnulib-tool so we keep that file in addition to the top-level .gitignore file which covers everything else in the subdirectory tree.

 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 +49 -0

49 lines not on this page · raw message

doc/.gitignore new file +2 -0
new file mode 100644
index 000000000..847f66f4d
@@ -0,0 +1,2 @@
+/gendocs_template
+/gendocs_template_min
Signature · 1 line
2.26.2
#4 lore raw

Re: [MULTIBOOT2 SPEC PATCH v3 2/4] multiboot2: Use .gitignore files

Quoted 5 lines · Hans Ulrich Niedermann

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

The doc/.gitignore file is generated by gnulib-tool so we keep that file in addition to the top-level .gitignore file which covers everything else in the subdirectory tree.

If it is generated by gnulib-tool why do we need to create it?

Quoted 63 lines
 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 +15 -0
new file mode 100644
index 000000000..01823be9c
@@ -0,0 +1,49 @@
+# Generated by "autogen.sh"
+/gendocs.sh
+/lib/
+/m4/
+
+/NEWS
+/README
+
+Makefile.in
+
+/aclocal.m4
+/autom4te.cache/
+/compile
+/config.h.in
+/configure

.gitignore line 25

Quoted 10 lines
.gitignore new file +10 -0
+/depcomp
+/doc/mdate-sh
+/doc/texinfo.tex
+/install-sh
+/INSTALL
+/missing
+
+# Generated by "configure"
+Makefile
+.deps/

Slash, "/", prefix?

Quoted 5 lines
.gitignore new file +5 -0
+
+/config.h
+/config.log
+/config.status
+/stamp-h1

.gitignore line 40

Quoted 10 lines
.gitignore new file +10 -0
+
+# Generated by "make"
+/doc/*.c.texi
+/doc/*.h.texi
+/doc/*.S.texi
+/doc/multiboot.info*
+/doc/stamp-vti
+/doc/version.texi
+
+*.o

Could you be more consistent and list prefixed and not prefixed variants in the same order in each section?

Daniel

#5 lore raw

Re: [MULTIBOOT2 SPEC PATCH v3 2/4] multiboot2: Use .gitignore files

Quoted 2 lines · On Wed, 13 May 2020 18:21:11 +0200 Daniel Kiper <[email protected]> wrote:

On Fri, May 08, 2020 at 06:50:47AM +0200, Hans Ulrich Niedermann wrote:

[... lots of gitignore stuff again ... ]

Quoted 11 lines

.gitignore line 25

Quoted 9 lines
.gitignore new file +9 -0
+/doc/mdate-sh
+/doc/texinfo.tex
+/install-sh
+/INSTALL
+/missing
+
+# Generated by "configure"
+Makefile
+.deps/  

Slash, "/", prefix?

Trailing slash just means "match directory" as opposed to "match file or directory", so ".deps/" matches every directory named ".deps", while the ".deps" pattern also matches files called ".deps". I'd rather such a file showed up in "git status" so such a weird thing would be noticed.

The leading slash to match only relative to the .gitignore file's directory is only implied with slashes somewhere within the pattern, e.g. "doc/texinfo.tex" and "/doc/textinfo.tex" have the identical meaning.

Quoted 10 lines
Quoted 10 lines
.gitignore new file +10 -0
+
+/config.h
+/config.log
+/config.status
+/stamp-h1
+
+# Generated by "make"
+/doc/*.c.texi
+/doc/*.h.texi
+/doc/*.S.texi
Quoted 8 lines

.gitignore line 40

Quoted 5 lines
.gitignore new file +5 -0
+/doc/multiboot.info*
+/doc/stamp-vti
+/doc/version.texi
+
+*.o  

Could you be more consistent and list prefixed and not prefixed variants in the same order in each section?

Good point.

Uli

#6 lore raw

Re: [MULTIBOOT2 SPEC PATCH v3 2/4] multiboot2: Use .gitignore files

In reply to Daniel Kiper
Quoted 9 lines · On Wed, 13 May 2020 18:21:11 +0200 Daniel Kiper <[email protected]> wrote:
Quoted 5 lines · Hans Ulrich Niedermann

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

The doc/.gitignore file is generated by gnulib-tool so we keep that file in addition to the top-level .gitignore file which covers everything else in the subdirectory tree.

If it is generated by gnulib-tool why do we need to create it?

The alternatives to adding doc/.gitignore to the version controlled files are to either

a) have the top-level .gitignore file ignore "/doc/.gitignore"

b) have the gnulib-generated doc/.gitignore file just flying around, neither .gitignored like all other generated files, nor under version control

Option a) sounds like the beginning of a road into world of very weird and unexpected things, and option b) defeats the purpose of having any .gitignore or .bzrignore etc. files at all.

I much prefer ignoring a few patterns which gnulib is considering useful to be ignored at this time by adding doc/.gitignore. Well, now that I am thinking about this...

c) Maybe gnulib would recognize when the top-level .gitignore files does the job gnulib would create the doc/.gitignore file for. Then we would just have two more patterns in our top-level .gitignore file, and gnulib would not create a doc/.gitignore file.

I will have to investigate option c). I would prefer that over my original option from the patch (adding the doc/.gitignore file as generated by gnulib).

Uli

#7 lore raw

Re: [MULTIBOOT2 SPEC PATCH v3 2/4] multiboot2: Use .gitignore files

Quoted 30 lines · On Wed, 13 May 2020 23:11:03 +0200 Hans Ulrich Niedermann…
Quoted 9 lines · On Wed, 13 May 2020 18:21:11 +0200 Daniel Kiper <[email protected]> wrote:
Quoted 5 lines · Hans Ulrich Niedermann

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

The doc/.gitignore file is generated by gnulib-tool so we keep that file in addition to the top-level .gitignore file which covers everything else in the subdirectory tree.

If it is generated by gnulib-tool why do we need to create it?

The alternatives to adding doc/.gitignore to the version controlled files are to either

a) have the top-level .gitignore file ignore "/doc/.gitignore"

b) have the gnulib-generated doc/.gitignore file just flying around, neither .gitignored like all other generated files, nor under version control

Option a) sounds like the beginning of a road into world of very weird and unexpected things, and option b) defeats the purpose of having any .gitignore or .bzrignore etc. files at all.

I much prefer ignoring a few patterns which gnulib is considering useful to be ignored at this time by adding doc/.gitignore. Well, now that I am thinking about this...

Quoted 8 lines

c) Maybe gnulib would recognize when the top-level .gitignore files does the job gnulib would create the doc/.gitignore file for.
Then we would just have two more patterns in our top-level .gitignore
file, and gnulib would not create a doc/.gitignore file.

I will have to investigate option c). I would prefer that over my original option from the patch (adding the doc/.gitignore file as generated by gnulib).

No luck here. I have just examined what gnulib-tool does in the presence of the proper patterns having been added to the top-level .gitignore file with an absent doc/.gitignore file: gnulib-tool creates a new file doc/.gitignore to which it adds its patterns.

So option c) is out, option a) and option b) both create unnecessary friction in the day to day use of git, I am therefore still convinced the best way to go is to have a top-level .gitignore with our own stuff, and a doc/.gitignore file with whatever patterns gnulib-tool wants to put in there together with the scripts it puts into doc/.

Note that gnulib-tool creates a few more subdirectory .gitignore files in /lib/ and /m4/. We just do not notice those as we .gitignore the whole subdirectory for those two anyway. The only thing from gnulib we are interested in are the scripts generating HTML from doc/multiboot.texi, not m4 macros or C source files.

Uli

#8 lore raw

PATCH v3 3/4 multiboot2: Make example kernel build at least for i386

In reply to Hans Ulrich Niedermann

The example kernel has assembly language boot code for both i386 and mips, but the mips assembly code used to be built unconditionally, even if the build is using non-mips build tools such as for x86_64 or i386.

This makes the example kernel build at least for i386, both on i386 and on x86_64 hosts.

* renames the i386 boot code from boot.S to boot_i386.S to go along with the mips boot code in boot_mips.S

* adds AC_CANONICAL_HOST to select the proper boot code:

* i386 if building on x86_64 (adds -m32) or on i[3456]86
* mips if building for mips*
* do not build the kernel if building for another system

* adds m4 quoting and uses AS_HELP_STRING use in configure.ac

* fixes the name of the constants used in boot_i386.S to use the actual constant names from multiboot2.h

* documents both boot_i386.S and boot_mips.S in the multiboot.texi page

Building the example kernel for mips still needs some work, as I have not managed to build for mips yet with either my mips64-linux-gnu cross-compilation toolchain on Fedora 32 or on my Debian 10.3 MIPS install running in qemu-system-mips.

 rename doc/{boot.S => boot_i386.S} (94%)
.gitignore +2 -0
index 01823be9c..4de19ceee 100644
@@ -11,7 +11,9 @@ Makefile.in
 /aclocal.m4
 /autom4te.cache/
 /compile
+/config.guess
 /config.h.in
+/config.sub
 /configure
 /depcomp
 /doc/mdate-sh
configure.ac +30 -5
index 8f21b1852..5ddb16b72 100644
@@ -32,11 +32,36 @@ dnl Because recent automake complains about AS, set it here.
 CCAS="$CC"
 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 Multiboot kernel (if possible on this host)
+AC_CANONICAL_HOST
+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_boot_arch=unsupported
+    ;;
+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$kernel_boot_arch" != "xunsupported"])
 
 dnl Because recent automake complains about CCASFLAGS, set it here.
 CCASFLAGS='$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)'
doc/Makefile.am +5 -4
index 2a5afd95d..0d896fe10 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
+EXAMPLES = boot_i386.S boot_mips.S kernel.c multiboot2.h
+multiboot_TEXINFOS = boot_i386.S.texi boot_mips.S.texi kernel.c.texi multiboot2.h.texi
 SRC2TEXI = src2texi
 noinst_SCRIPTS = $(SRC2TEXI)
 EXTRA_PROGRAMS = kernel
@@ -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 = $(EXAMPLES)
-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
 
doc/boot_i386.S renamed from doc/boot.S +2 -2
similarity index 94%
rename from doc/boot.S
rename to doc/boot_i386.S
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
doc/multiboot.texi +37 -22

76 lines not on this page · raw message

Signature · 1 line
2.26.2
#9 lore raw

Re: [MULTIBOOT2 SPEC PATCH v3 3/4] multiboot2: Make example kernel build at least for i386

Quoted 17 lines · Hans Ulrich Niedermann

The example kernel has assembly language boot code for both i386 and mips, but the mips assembly code used to be built unconditionally, even if the build is using non-mips build tools such as for x86_64 or i386.

This makes the example kernel build at least for i386, both on i386 and on x86_64 hosts.

* renames the i386 boot code from boot.S to boot_i386.S to go along with the mips boot code in boot_mips.S

* adds AC_CANONICAL_HOST to select the proper boot code:

* i386 if building on x86_64 (adds -m32) or on i[3456]86
* mips if building for mips*
* do not build the kernel if building for another system

Quoted 7 lines

* adds m4 quoting and uses AS_HELP_STRING use in configure.ac

* fixes the name of the constants used in boot_i386.S to use the actual constant names from multiboot2.h

* documents both boot_i386.S and boot_mips.S in the multiboot.texi page

May I ask you to split this patch into logical parts?

Quoted 4 lines

Building the example kernel for mips still needs some work, as I have not managed to build for mips yet with either my mips64-linux-gnu cross-compilation toolchain on Fedora 32 or on my Debian 10.3 MIPS install running in qemu-system-mips.

This is not big deal. We can fix it later.

Daniel

#10 lore raw

Re: [MULTIBOOT2 SPEC PATCH v3 3/4] multiboot2: Make example kernel build at least for i386

Quoted 21 lines · On Wed, 13 May 2020 18:24:28 +0200 Daniel Kiper <[email protected]> wrote:
Quoted 19 lines · Hans Ulrich Niedermann

The example kernel has assembly language boot code for both i386 and mips, but the mips assembly code used to be built unconditionally, even if the build is using non-mips build tools such as for x86_64 or i386.

This makes the example kernel build at least for i386, both on i386 and on x86_64 hosts.

* renames the i386 boot code from boot.S to boot_i386.S to go along with the mips boot code in boot_mips.S

* adds AC_CANONICAL_HOST to select the proper boot code:

* i386 if building on x86_64 (adds -m32) or on i[3456]86
* mips if building for mips*
* do not build the kernel if building for another system

* adds m4 quoting and uses AS_HELP_STRING use in configure.ac

Quoted 7 lines
Quoted 5 lines

* fixes the name of the constants used in boot_i386.S to use the actual constant names from multiboot2.h

* documents both boot_i386.S and boot_mips.S in the multiboot.texi page

May I ask you to split this patch into logical parts?

Being a little slow on the uptake, I only just figured out why I ended up with that big of a patch.

When given a building and working source tree, I usually make my commits such that they are small, self-contained and keep the source tree in a building and working state.

That is why I usually add changes until it finally builds/works.

However, that is a useless argument here, as the state of the source tree *before* my change is non-building maybe-working, so if the source tree does not build *after* my small, self-contained change, my change has not made it worse and can thusly still be considered good.

Changing my normal modus operandi accordingly; considering failing builds as normal for now.

Expect a good dozen patches in a day or two.

Uli

#11 lore raw

PATCH v3 4/4 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.

The boot_i386.S file keeps using ".align 8".

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

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 the "grub-file --is-x86-multiboot2" utility does not recognize the wrong alignment of the Multiboot2 header tags, as it only considers the beginning of the Multiboot2 header and completely ignores the Multiboot2 header tags.

doc/boot_i386.S +5 -0
index 9ab016612..1418afe1a 100644
@@ -56,6 +56,7 @@ multiboot_header:
 	/* checksum */
 	.long	-(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + (multiboot_header_end - multiboot_header))
 #ifndef __ELF__
+	.align	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:
+	.align	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__ */
+	.align	8
 framebuffer_tag_start:	
 	.short MULTIBOOT_HEADER_TAG_FRAMEBUFFER
 	.short MULTIBOOT_HEADER_TAG_OPTIONAL
@@ -85,10 +88,12 @@ framebuffer_tag_start:
 	.long 768
 	.long 32
 framebuffer_tag_end:
+	.align	8
 	.short MULTIBOOT_HEADER_TAG_END
 	.short 0
 	.long 8
 multiboot_header_end:
+
 multiboot_entry:
 	/* Initialize the stack pointer.  */
 	movl	$(stack + STACK_SIZE), %esp
doc/boot_mips.S +11 -6
index ed604214d..e7bb7df9f 100644
@@ -46,8 +46,8 @@ _start:
 	 nop
 
 	/* Align 64 bits boundary.  */
-	.align	8
-	
+	.balign	8
+
 	/* Multiboot header.  */
 multiboot_header:
 	/* magic */
@@ -59,7 +59,8 @@ multiboot_header:
 	/* checksum */
 	.long	-(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_MIPS32 + (multiboot_header_end - multiboot_header))
 #ifndef __ELF__
-address_tag_start:	
+	.balign	8
+address_tag_start:
 	.short MULTIBOOT_HEADER_TAG_ADDRESS
 	.short MULTIBOOT_HEADER_TAG_OPTIONAL
 	.long address_tag_end - address_tag_start
@@ -72,7 +73,8 @@ address_tag_start:
 	/* bss_end_addr */
 	.long	_end
 address_tag_end:
-entry_address_tag_start:	
+	.balign	8
+entry_address_tag_start:
 	.short MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS
 	.short MULTIBOOT_HEADER_TAG_OPTIONAL
 	.long entry_address_tag_end - entry_address_tag_start
@@ -80,7 +82,8 @@ entry_address_tag_start:
 	.long multiboot_entry
 entry_address_tag_end:
 #endif /* __ELF__ */
-framebuffer_tag_start:	
+	.balign	8
+framebuffer_tag_start:
 	.short MULTIBOOT_HEADER_TAG_FRAMEBUFFER
 	.short MULTIBOOT_HEADER_TAG_OPTIONAL
 	.long framebuffer_tag_end - framebuffer_tag_start
@@ -88,10 +91,12 @@ framebuffer_tag_start:
 	.long 768
 	.long 32
 framebuffer_tag_end:
+	.balign	8
 	.short MULTIBOOT_HEADER_TAG_END
 	.short 0
 	.long 8
 multiboot_header_end:
+
 multiboot_entry:
 	/* Initialize the stack pointer.  */
 	lui     $sp, %hi (stack + STACK_SIZE)
@@ -114,6 +119,6 @@ loop:	nop
 halt_message:
 	.asciz	"Halted."
 
-	.align 8
+	.balign 8
 	/* Our stack area.  */
 	.comm	stack, STACK_SIZE
Signature · 1 line
2.26.2
#12 lore raw

Re: [MULTIBOOT2 SPEC PATCH v3 4/4] multiboot2: fix example kernel header tag alignment

Quoted 8 lines · 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!

Quoted 4 lines

Therefore, this changes boot_mips.S to use ".balign 8" where it had mistakenly used ".align 8" before.

The boot_i386.S file keeps using ".align 8".

I would use ".balign 8" everywhere to avoid confusion.

Quoted 10 lines

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

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.

Quoted 5 lines

Note also that the "grub-file --is-x86-multiboot2" utility does not recognize the wrong alignment of the Multiboot2 header tags, as it only considers the beginning of the Multiboot2 header and completely ignores the Multiboot2 header tags.

Please also mention here that you are additionally fixing some formatting errors.

Daniel