Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jP6B9-0006yZ-Ix for mharc-grub-devel@gnu.org; Thu, 16 Apr 2020 11:11:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48535) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jP6B6-0006tz-G6 for grub-devel@gnu.org; Thu, 16 Apr 2020 11:11:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jP6B1-0005FN-6H for grub-devel@gnu.org; Thu, 16 Apr 2020 11:11:44 -0400 Received: from relay01.mx.bawue.net ([193.7.176.67]:36458 helo=smtp.bawue.net) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jP6B0-0005Ay-TT for grub-devel@gnu.org; Thu, 16 Apr 2020 11:11:39 -0400 Received: from infty.fritz.box (p5B0825D9.dip0.t-ipconnect.de [91.8.37.217]) (Authenticated sender: pdim@bawue.de) by smtp.bawue.net (Postfix) with ESMTPSA id 7155B2047E; Thu, 16 Apr 2020 17:11:34 +0200 (CEST) From: Hans Ulrich Niedermann To: grub-devel@gnu.org Cc: Hans Ulrich Niedermann Subject: [PATCH 3/3] multiboot2: Make example kernel build at least for i386 Date: Thu, 16 Apr 2020 17:09:57 +0200 Message-Id: <20200416150958.207630-3-hun@n-dimensional.de> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200416150958.207630-1-hun@n-dimensional.de> References: <20200416150958.207630-1-hun@n-dimensional.de> MIME-Version: 1.0 X-Virus-Scanner: SAV Dynamic Interface 2.6.0, Engine: 3.77.1, SAV: 5.74 (23A484EE) on relay01.mx.bawue.net using milter-sssp 0.1.0 X-Virus-Scan: Found to be clean. Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 193.7.176.67 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Apr 2020 15:11:46 -0000 Document both boot_i386.S and boot_mips.S, and build at least boot_i386.S. Building a mips kernel if a mips compiler is actually available still needs some work. Signed-off-by: Hans Ulrich Niedermann --- .gitignore | 2 ++ configure.ac | 29 ++++++++++++++---- doc/Makefile.am | 9 +++--- doc/{boot.S =3D> boot_i386.S} | 4 +-- doc/multiboot.texi | 59 +++++++++++++++++++++++-------------- 5 files changed, 70 insertions(+), 33 deletions(-) rename doc/{boot.S =3D> boot_i386.S} (94%) diff --git a/.gitignore b/.gitignore index a2e66c27a..bd387ea77 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,9 @@ /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 8f21b1852..ee648f52a 100644 --- a/configure.ac +++ b/configure.ac @@ -32,11 +32,30 @@ dnl Because recent automake complains about AS, set i= t here. CCAS=3D"$CC" AC_SUBST(CCAS) =20 -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" =3D = xyes) +dnl Build the example Multiboot kernel (if possible on this host) +AC_CANONICAL_HOST +case "$host" in #( + i[3456]86-*) kernel_boot_arch=3Di386 + ;; #( + x86_64-*) kernel_boot_arch=3Di386 + kernel_ccasflags=3D"-m32" + kernel_cflags=3D"-m32" + ;; #( + mips-*) kernel_boot_arch=3Dmips + ;; #( + *) kernel_boot_arch=3Dunsupported + ;; +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" =3D xyes && test "x$kerne= l_boot_arch" !=3D "xunsupported"]) =20 dnl Because recent automake complains about CCASFLAGS, set it here. CCASFLAGS=3D'$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(CPPFLAGS) $(CFLAG= S)' diff --git a/doc/Makefile.am b/doc/Makefile.am index 2a5afd95d..0d896fe10 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -1,6 +1,6 @@ info_TEXINFOS =3D multiboot.texi -EXAMPLES =3D boot_mips.S kernel.c multiboot2.h -multiboot_TEXINFOS =3D boot.S.texi kernel.c.texi multiboot2.h.texi +EXAMPLES =3D boot_i386.S boot_mips.S kernel.c multiboot2.h +multiboot_TEXINFOS =3D boot_i386.S.texi boot_mips.S.texi kernel.c.texi m= ultiboot2.h.texi SRC2TEXI =3D src2texi noinst_SCRIPTS =3D $(SRC2TEXI) EXTRA_PROGRAMS =3D kernel @@ -9,8 +9,9 @@ pkginclude_HEADERS =3D multiboot2.h # The example kernel is built if you specify --enable-example-kernel. if BUILD_EXAMPLE_KERNEL noinst_PROGRAMS =3D kernel -kernel_SOURCES =3D $(EXAMPLES) -kernel_CFLAGS =3D -fno-builtin -nostdinc -O -g -Wall \ +kernel_SOURCES =3D boot_$(kernel_boot_arch).S kernel.c multiboot2.h +kernel_CCASFLAGS =3D $(kernel_ccasflags) +kernel_CFLAGS =3D $(kernel_cflags) -fno-builtin -nostdinc -O -g -Wall \ -imacros $(top_builddir)/config.h kernel_LDFLAGS =3D -nostdlib -Wl,-N -Wl,-Ttext -Wl,80100000 -Wl,--build-= id=3Dnone =20 diff --git a/doc/boot.S b/doc/boot_i386.S similarity index 94% rename from doc/boot.S rename to doc/boot_i386.S index 8f6f66fcc..9ab016612 100644 --- a/doc/boot.S +++ b/doc/boot_i386.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 + (m= ultiboot_header_end - multiboot_header)) + .long -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + (multib= oot_header_end - multiboot_header)) #ifndef __ELF__ address_tag_start:=09 .short MULTIBOOT_HEADER_TAG_ADDRESS diff --git a/doc/multiboot.texi b/doc/multiboot.texi index df8a0d056..c70d9239e 100644 --- a/doc/multiboot.texi +++ b/doc/multiboot.texi @@ -1553,26 +1553,31 @@ Multiboot2-compliant boot loader and for referenc= e to how to implement a Multiboot2 kernel. The source files can be found under the directory @file{doc} in the Multiboot2 source distribution. =20 -The kernel @file{kernel} consists of only three files: @file{boot.S}, -@file{kernel.c} and @file{multiboot2.h}. The assembly source -@file{boot.S} is written in GAS (@pxref{Top, , GNU assembler, as.info, -The GNU assembler}), and contains the Multiboot2 information structure t= o -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 th= e -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 +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. =20 @menu -* multiboot2.h:: =20 -* boot.S:: =20 -* kernel.c:: =20 +* multiboot2.h:: +* boot_i386.S:: +* boot_mips.S:: +* kernel.c:: * Other Multiboot2 kernels:: @end menu =20 @@ -1587,13 +1592,23 @@ This is the source code in the file @file{multibo= ot2.h}: @end example =20 =20 -@node boot.S -@subsection boot.S +@node boot_i386.S +@subsection boot_i386.S + +In the file @file{boot_i386.S}: + +@example +@include boot_i386.S.texi +@end example + + +@node boot_mips.S +@subsection boot_mips.S =20 -In the file @file{boot.S}: +In the file @file{boot_mips.S}: =20 @example -@include boot.S.texi +@include boot_mips.S.texi @end example =20 =20 --=20 2.25.2