[MULTIBOOT2 SPEC PATCH v4 02/27] multiboot2: Use .gitignore files

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

 delete mode 100644 .bzrignore
 create mode 100644 .gitignore
 create mode 100644 doc/.gitignore

diff --git a/.bzrignore b/.bzrignore
deleted file mode 100644
index fda459816..0
--- a/.bzrignore
+++ /dev/null
@@ -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
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0..631ff668d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,46 @@
+# Generated by "autogen.sh"
+Makefile.in
+
+/INSTALL
+/NEWS
+/README
+/aclocal.m4
+/autom4te.cache/
+/compile
+/config.h.in
+/configure
+/depcomp
+/doc/mdate-sh
+/doc/texinfo.tex
+/gendocs.sh
+/install-sh
+/lib/
+/m4/
+/missing
+
+# Generated by "configure"
+.deps/
+Makefile
+
+/config.h
+/config.log
+/config.status
+/stamp-h1
+
+# Generated by "make"
+*.o
+
+/doc/*.S.texi
+/doc/*.c.texi
+/doc/*.h.texi
+/doc/kernel
+/doc/multiboot.info*
+/doc/stamp-vti
+/doc/version.texi
+
+# Generated by "make web-manual"
+/doc/manual/
+/doc/multiboot.aux
+/doc/multiboot.cp
+/doc/multiboot.log
+/doc/multiboot.toc
diff --git a/doc/.gitignore b/doc/.gitignore
new file mode 100644
index 0..c8f86161e
--- /dev/null
+++ b/doc/.gitignore
@@ -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
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 05/27] multiboot2: Remove CCAS workarounds for pre-2005 Automake

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/configure.ac b/configure.ac
index 5b5c84d1e..37b220d0c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,7 +16,7 @@ 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
@@ -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.
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 03/27] multiboot2: Use m4 quoting and AS_HELP_STRING

2020-05-14 Thread Hans Ulrich Niedermann
Use proper m4 quoting throughout configure.ac and use AS_HELP_STRING
for the --enable-example-kernel argument.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/configure.ac b/configure.ac
index 8f21b1852..5bfc0ee5b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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], [bug-g...@gnu.org])
 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"
 
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 08/27] multiboot2: Automake cleans built programs automatically

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/doc/Makefile.am b/doc/Makefile.am
index a65b452cf..dc7816d9f 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -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.
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 07/27] multiboot2: Automake generates dependencies automatically

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/doc/Makefile.am b/doc/Makefile.am
index 2a5afd95d..a65b452cf 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -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,8010 -Wl,--build-id=none
-
-boot.o: multiboot2.h
 endif
 
 EXTRA_DIST = $(man_MANS) $(noinst_SCRIPTS) \
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


make check / grub_func_test issues

2020-05-14 Thread Daniel Axtens
Hi all,

I'm having some trouble with the grub tests run by `make check`.

In particular, grub_func_test is failing for me in every configuration I
try. I've tried various combinations of:

 - master, grub-2.04 and grub-2.02 tags, as well as the grub-2.04
   tarball.

 - configuring for platform emu and platform i386-pc

 - on a Ubuntu 19.10 host and in a 16.04 docker container

I keep having failures with the cmdline_cat test and the gfxmenu tests
within grub_func_test - the video checksums don't match. The images all
look OK to me, so I'm not quite sure what the problem is, and we don't
ship known-good images for me to compare against.

Is this supposed to work? If so are there any tricks to getting it to
work?

Regards,
Daniel


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v3 5/5] autogen: Replace -iname with -ipath in find command

2020-05-14 Thread Daniel Axtens
Daniel Kiper  writes:

> ..because -iname cannot be used to match paths.
>
> Signed-off-by: Daniel Kiper 
> Reviewed-by: Javier Martinez Canillas 
> ---
>  autogen.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/autogen.sh b/autogen.sh
> index ef43270fc..31b0ced7e 100755
> --- a/autogen.sh
> +++ b/autogen.sh
> @@ -13,7 +13,7 @@ fi
>  export LC_COLLATE=C
>  unset LC_ALL
>  
> -find . -iname '*.[ch]' ! -ipath './grub-core/lib/libgcrypt-grub/*' ! -ipath 
> './build-aux/*' ! -ipath './grub-core/lib/libgcrypt/src/misc.c' ! -ipath 
> './grub-core/lib/libgcrypt/src/global.c' ! -ipath 
> './grub-core/lib/libgcrypt/src/secmem.c'  ! -ipath 
> './util/grub-gen-widthspec.c' ! -ipath './util/grub-gen-asciih.c' ! -ipath 
> './gnulib/*' ! -iname './grub-core/lib/gnulib/*' |sort > po/POTFILES.in
> +find . -iname '*.[ch]' ! -ipath './grub-core/lib/libgcrypt-grub/*' ! -ipath 
> './build-aux/*' ! -ipath './grub-core/lib/libgcrypt/src/misc.c' ! -ipath 
> './grub-core/lib/libgcrypt/src/global.c' ! -ipath 
> './grub-core/lib/libgcrypt/src/secmem.c'  ! -ipath 
> './util/grub-gen-widthspec.c' ! -ipath './util/grub-gen-asciih.c' ! -ipath 
> './gnulib/*' ! -ipath './grub-core/lib/gnulib/*' |sort > po/POTFILES.in
>  find util -iname '*.in' ! -name Makefile.in  |sort > po/POTFILES-shell.in

Fantastic, that had been bugging me every time I saw it.

Reviewed-by: Daniel Axtens 

Regards,
Daniel

>  
>  echo "Importing unicode..."
> -- 
> 2.11.0
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 04/27] multiboot2: Remove obsolete compat code for ancient Autoconf

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/configure.ac b/configure.ac
index 5bfc0ee5b..5b5c84d1e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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"
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 00/27] multiboot2: Clean up the example kernel

2020-05-14 Thread Hans Ulrich Niedermann
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
 

[MULTIBOOT2 SPEC PATCH v4 16/27] multiboot2: Change "Multiboot" in comments to "Multiboot2"

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/doc/boot_i386.S b/doc/boot_i386.S
index c6e7f1382..20a600a6e 100644
--- a/doc/boot_i386.S
+++ b/doc/boot_i386.S
@@ -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
diff --git a/doc/boot_mips.S b/doc/boot_mips.S
index 2b9ee0f9c..3f99c81a0 100644
--- a/doc/boot_mips.S
+++ b/doc/boot_mips.S
@@ -41,7 +41,7 @@ _start:
/* Align 64 bits boundary.  */
.balign 8

-   /* Multiboot header.  */
+   /* Multiboot2 header.  */
 multiboot_header:
/* magic */
.long   MULTIBOOT2_HEADER_MAGIC
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/multiboot2.h b/doc/multiboot2.h
index b18160707..d3b03d7a1 100644
--- a/doc/multiboot2.h
+++ b/doc/multiboot2.h
@@ -32,14 +32,13 @@
 /* This should be in %eax.  */
 #define MULTIBOOT2_BOOTLOADER_MAGIC0x36d76289
 
-/* Alignment of multiboot modules.  */
+/* Alignment of multiboot2 modules.  */
 #define MULTIBOOT_MOD_ALIGN0x1000
 
-/* Alignment of the multiboot info structure.  */
+/* Alignment of the multiboot2 info structure.  */
 #define MULTIBOOT_INFO_ALIGN   0x0008
 
-/* 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_ADDR21
 
+/* 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
 
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 12/27] multiboot2: Add boot_mips.S example code to docs

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/doc/Makefile.am b/doc/Makefile.am
index e88f4d271..08fdbf342 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -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
diff --git a/doc/multiboot.texi b/doc/multiboot.texi
index b89b12272..67f0abd84 100644
--- a/doc/multiboot.texi
+++ b/doc/multiboot.texi
@@ -1553,25 +1553,30 @@ 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_i386.S},
-@file{kernel.c} and @file{multiboot2.h}. The assembly source
-@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},
-and then call the function @code{cmain} defined in @file{kernel.c}. 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 @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.
+The kernel @file{kernel} consists of only three files:
+@file{boot_i386.S} or @file{boot_mips.S} (depending on the kernel
+architecture), @file{kernel.c}, and @file{multiboot2.h}. The assembly
+sources @file{boot_i386.S} and @file{boot_mips.S} are written in GAS
+(@pxref{Top, , GNU assembler, as.info, The GNU assembler}) and
+contain the Multiboot2 information structure to comply with the
+specification. When a Multiboot2-compliant boot loader loads and
+executes @file{boot_*.S}, it initializes the stack pointer and
+@code{EFLAGS}, and then calls the function @code{cmain} defined in
+@file{kernel.c}.
+
+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
+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 C preprocessor
+macros, such as the magic number for the Multiboot2 header, the
+Multiboot2 header structure and the Multiboot2 information structure.
 
 @menu
 * multiboot2.h:: 
 * boot_i386.S::
+* boot_mips.S::
 * kernel.c::
 * Other Multiboot2 kernels::
 @end menu
@@ -1597,6 +1602,16 @@ In the file @file{boot_i386.S}:
 @end example
 
 
+@node boot_mips.S
+@subsection boot_mips.S
+
+In the file @file{boot_mips.S}:
+
+@example
+@include boot_mips.S.texi
+@end example
+
+
 @node kernel.c
 @subsection kernel.c
 
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 14/27] multiboot2: Fix example kernel header tag alignment

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/doc/boot_i386.S b/doc/boot_i386.S
index 9ab016612..0e8118b2a 100644
--- a/doc/boot_i386.S
+++ b/doc/boot_i386.S
@@ -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
diff --git a/doc/boot_mips.S b/doc/boot_mips.S
index ed604214d..a8d3fb0e4 100644
--- a/doc/boot_mips.S
+++ b/doc/boot_mips.S
@@ -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
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 17/27] multiboot2: Clean up stack (cdecl calling conventions)

2020-05-14 Thread Hans Ulrich Niedermann
Clean up the stack after calling C functions according to the
i386 cdecl calling conventions.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/doc/boot_i386.S b/doc/boot_i386.S
index 20a600a6e..14dc14660 100644
--- a/doc/boot_i386.S
+++ b/doc/boot_i386.S
@@ -101,10 +101,12 @@ multiboot_entry:
 
/* Now enter the C main function...  */
callEXT_C(cmain)
+   addl$8, %esp
 
/* Halt.  */
pushl   $halt_message
callEXT_C(printf)
+   addl$4, %esp

 loop:  hlt
jmp loop
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 15/27] multiboot2: Remove unreferenced AOUT_KLUDGE

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/doc/boot_i386.S b/doc/boot_i386.S
index 0e8118b2a..c6e7f1382 100644
--- a/doc/boot_i386.S
+++ b/doc/boot_i386.S
@@ -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
diff --git a/doc/boot_mips.S b/doc/boot_mips.S
index a8d3fb0e4..2b9ee0f9c 100644
--- a/doc/boot_mips.S
+++ b/doc/boot_mips.S
@@ -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
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 09/27] multiboot2: Use the constants by their proper names

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/doc/boot.S b/doc/boot.S
index 8f6f66fcc..9ab016612 100644
--- a/doc/boot.S
+++ b/doc/boot.S
@@ -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
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 11/27] multiboot2: Add boot_i386.S to shipped files

2020-05-14 Thread Hans Ulrich Niedermann
Ship the boot_i386.S file in the dist tarball as well, not
just the boot_mips.S file.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/doc/Makefile.am b/doc/Makefile.am
index d9efe8116..e88f4d271 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -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,8010 -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.
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 27/27] multiboot2: Add labels around the termination tag

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/doc/boot_i386.S b/doc/boot_i386.S
index 2aa2a92b6..67411b968 100644
--- a/doc/boot_i386.S
+++ b/doc/boot_i386.S
@@ -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.  */
diff --git a/doc/boot_mips.S b/doc/boot_mips.S
index a6881528f..4d6ac1f67 100644
--- a/doc/boot_mips.S
+++ b/doc/boot_mips.S
@@ -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.  */
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 20/27] multiboot2: mips build wants __start symbol

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/doc/boot_mips.S b/doc/boot_mips.S
index b59e3fd6a..a6881528f 100644
--- a/doc/boot_mips.S
+++ b/doc/boot_mips.S
@@ -31,9 +31,10 @@
.set noreorder
 .set nomacro
 
-   .globl  start, _start
+   .globl  start, _start, __start
 start:
 _start:
+__start:
b   multiboot_entry
 nop
 
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 18/27] multiboot2: Use predefined #ifdef __ASSEMBLER__

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/doc/boot_i386.S b/doc/boot_i386.S
index 14dc14660..2aa2a92b6 100644
--- a/doc/boot_i386.S
+++ b/doc/boot_i386.S
@@ -15,7 +15,6 @@
  * along with this program.  If not, see .
  */
 
-#define ASM_FILE   1
 #include 
 
 /* C symbol format. HAVE_ASM_USCORE is defined by configure.  */
diff --git a/doc/boot_mips.S b/doc/boot_mips.S
index 3f99c81a0..b59e3fd6a 100644
--- a/doc/boot_mips.S
+++ b/doc/boot_mips.S
@@ -15,7 +15,6 @@
  * along with this program.  If not, see .
  */
 
-#define ASM_FILE   1
 #include 
 
 /* C symbol format. HAVE_ASM_USCORE is defined by configure.  */
diff --git a/doc/multiboot2.h b/doc/multiboot2.h
index d3b03d7a1..f89cd5e77 100644
--- a/doc/multiboot2.h
+++ b/doc/multiboot2.h
@@ -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 */
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 13/27] multiboot2: Build arch specific boot code

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/.gitignore b/.gitignore
index 631ff668d..e27a3e0e2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,7 +7,9 @@ Makefile.in
 /aclocal.m4
 /autom4te.cache/
 /compile
+/config.guess
 /config.h.in
+/config.sub
 /configure
 /depcomp
 /doc/mdate-sh
diff --git a/configure.ac b/configure.ac
index d8e08597d..830b1f57e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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"
 
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 08fdbf342..b19fc24bf 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -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,8010 -Wl,--build-id=none
 endif
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 24/27] multiboot2: Generate a kernel.map map file

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/.gitignore b/.gitignore
index 7a035c267..889e17f69 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/doc/Makefile.am b/doc/Makefile.am
index cc07ceec8..21cdff0b2 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -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,8010 -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)
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 06/27] multiboot2: Remove unnecessary definition of CC

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/configure.ac b/configure.ac
index 37b220d0c..d8e08597d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,7 +22,6 @@ AM_INIT_AUTOMAKE([1.10.1])
 # Programs
 #
 
-AC_CHECK_TOOL([CC], [gcc])
 AC_PROG_CC
 AM_PROG_AS
 
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 22/27] multiboot2: Always define the kernel_* vars

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/doc/Makefile.am b/doc/Makefile.am
index b19fc24bf..cb290a0cb 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -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,8010 -Wl,--build-id=none
-endif
 
 EXTRA_DIST = $(man_MANS) $(noinst_SCRIPTS) \
$(arch_sources) $(multiboot_TEXINFOS)
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


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

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/.gitignore b/.gitignore
index e27a3e0e2..7a035c267 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,6 +30,7 @@ Makefile
 /stamp-h1
 
 # Generated by "make"
+*.lst
 *.o
 
 /doc/*.S.texi
diff --git a/doc/Makefile.am b/doc/Makefile.am
index cb290a0cb..cc07ceec8 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -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,8010 -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)
 
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 19/27] multiboot2: Set -nostdlib before AC_PROG_CC for x-compile

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/configure.ac b/configure.ac
index 830b1f57e..6b0718451 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v3 2/5] configure: Set gnu99 C language standard by default

2020-05-14 Thread Daniel Axtens
Hi Daniel,

> Commit d5a32255d (misc: Make grub_strtol() "end" pointers have safer
> const qualifiers) introduced "restrict" keyword into some functions
> definitions. This keyword was introduced in C99 standard. However, some
> compilers by default may use C89 or something different. This behavior
> leads to the breakage during builds when c89 or gnu89 is in force. So,
> let's set gnu99 C language standard for all compilers by default. This
> way a bit random build issue will be fixed and the GRUB source will be
> build consistently regardless of type and version of the compiler.
>
> It was decided to use gnu99 C language standard because it fixes the
> issue mentioned above and also provides some useful extensions which are
> used here and there in the GRUB source. Potentially we can use gnu11
> too. However, this may reduce pool of older compilers which can be used
> to build the GRUB. So, let's live with gnu99 until we discover that we
> strongly require a feature from newer C standard.

I tried building this with CC=clang just to see if it didn't like gnu99
for some reason.

It does not, but for different reasons to what I expected:

clang -DHAVE_CONFIG_H -I.  -Wall -W -DGRUB_UTIL=1 -D_FILE_OFFSET_BITS=64 
-I./include -DGRUB_FILE=\"grub-core/lib/json/json.c\" -I. -I. -I. -I. 
-I./include -I./include -I./grub-core/lib/libgcrypt-grub/src/  
-I./grub-core/lib/gnulib -I./grub-core/lib/gnulib -I./grub-core/lib/json 
-D_FILE_OFFSET_BITS=64 -std=gnu99  -Wall -W -Wshadow -Wpointer-arith -Wundef 
-Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization 
-Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k 
-Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain 
-Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses 
-Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs 
-Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter 
-Wunused-value  -Wunused-variable -Wwrite-strings -Wnested-externs 
-Wstrict-prototypes -Wcast-align  -Wextra -Wattributes -Wendif-labels 
-Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers 
-Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing 
-Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs 
-Wmissing-prototypes -Wmissing-declarations -Wformat=2 -Werror  -Wno-undef 
-Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls 
-Wno-unreachable-code -Wno-conversion  -MT 
grub-core/lib/json/libgrubkern_a-json.o -MD -MP -MF 
grub-core/lib/json/.deps-util/libgrubkern_a-json.Tpo -c -o 
grub-core/lib/json/libgrubkern_a-json.o `test -f 'grub-core/lib/json/json.c' || 
echo './'`grub-core/lib/json/json.c
In file included from grub-core/lib/json/json.c:24:
./grub-core/lib/json/json.h:39:24: error: redefinition of typedef 'jsmntok_t' 
is a C11 feature [-Werror,-Wtypedef-redefinition]
typedef struct jsmntok jsmntok_t;
   ^
./grub-core/lib/json/jsmn.h:77:3: note: previous definition is here
} jsmntok_t;
  ^
1 error generated.


clang --version
clang version 9.0.0-2 (tags/RELEASE_900/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Without this patch, clang-9 fails on the use of nested functions in
commit cb2f15c54489 ("normal/main: Search for specific config files for
netboot") - I'll send a fix for that shortly. If I revert that as a
temporary measure, clang will build.

I notice from ./configure that it already does some form of testing for
restrict:

checking for C/C++ restrict keyword... __restrict

I'm not sure what brings that test in to configure (gnulib?), and
accessing it is a little bit tricky because we use AC_CONFIG_FILES for
config.h rather than AC_CONFIG_HEADER, but that could be a general
purpose solution.

Regards,
Daniel

> The user is still able to override C language standard using relevant
> *_CFLAGS variables.
>
> Signed-off-by: Daniel Kiper 
> ---
> v3 - suggestions/fixes:
>- add a comment before the change in configure.ac
>  (suggested by Javier Martinez Canillas and Leif Lindholm),
>- improve commit message
>  (suggested by Javier Martinez Canillas and Leif Lindholm).
>
> v2 - suggestions/fixes:
>- unconditionally enforce gnu99 C language standard
>  (suggested by Leif Lindholm).
> ---
>  configure.ac | 6 ++
>  1 file changed, 6 insertions(+)
>
> diff --git a/configure.ac b/configure.ac
> index b2576b013..3eda9a5a2 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -80,6 +80,12 @@ if test "x$TARGET_CFLAGS" = x; then
>TARGET_CFLAGS=-Os
>  fi
>  
> +# Enable support for "restrict" keyword and other
> +# features from gnu99 C language standard.
> +BUILD_CFLAGS="-std=gnu99 $BUILD_CFLAGS"
> +HOST_CFLAGS="-std=gnu99 $HOST_CFLAGS"
> +TARGET_CFLAGS="-std=gnu99 $TARGET_CFLAGS"
> +
>  # Default HOST_CPPFLAGS
>  HOST_CPPFLAGS="$HOST_CPPFLAGS -Wall -W"
>  HOST_CPPFLAGS="$HOST_CPPFLAGS -DGRUB_UTIL=1"
> -- 
> 

[MULTIBOOT2 SPEC PATCH v4 01/27] multiboot2: Allow autogen.sh to run with current gnulib

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 
Reviewed-by: Daniel Kiper 

diff --git a/configure.ac b/configure.ac
index 585b37a36..8f21b1852 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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], [bug-g...@gnu.org])
 AC_CONFIG_SRCDIR([doc/multiboot.texi])
 AC_CONFIG_HEADER([config.h])
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


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

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/.gitignore b/.gitignore
index 889e17f69..f6a1b7736 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,7 +31,9 @@ Makefile
 
 # Generated by "make"
 *.lst
+*.i
 *.o
+*.s
 
 /doc/*.S.texi
 /doc/*.c.texi
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 21cdff0b2..fe1e473c9 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -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)
 
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 26/27] multiboot2: Generate symbol lists and disassembly file

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

diff --git a/.gitignore b/.gitignore
index f6a1b7736..ba08c2911 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/configure.ac b/configure.ac
index 6b0718451..e70da14d0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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=
diff --git a/doc/Makefile.am b/doc/Makefile.am
index fe1e473c9..a382b62be 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -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:
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[MULTIBOOT2 SPEC PATCH v4 21/27] multiboot2: "make distcheck" with example kernel enabled

2020-05-14 Thread 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.

Signed-off-by: Hans Ulrich Niedermann 

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
-- 
2.26.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel