All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jan (janneke) Nieuwenhuizen" <janneke@gnu.org>
To: grub-devel@gnu.org
Subject: [PATCH v2] grub-core: Build fixes for i386
Date: Tue, 18 May 2021 12:47:33 +0200	[thread overview]
Message-ID: <20210518104733.23391-1-janneke@gnu.org> (raw)

This fixes cross-compiling to x86 (e.g., the Hurd) from x86-linux.

To reproduce, update the Grub source description in your local Guix
archive and run

   ./pre-inst-env guix build --system=i686-linux --target=i586-pc-gnu grub

or install an x86 cross-build environment on x86-linux (32bit!) and
configure to cross build and make, e.g., do something like

    ./configure \
       CC_FOR_BUILD=gcc \
       --build=i686-unknown-linux-gnu
       --host=i586-pc-gnu
    make

* grub-core/lib/i386/relocator64.S: Avoid x86_64 instructions on i386.
---
 grub-core/lib/i386/relocator64.S | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/grub-core/lib/i386/relocator64.S b/grub-core/lib/i386/relocator64.S
index 148f38adb..b4675dd16 100644
--- a/grub-core/lib/i386/relocator64.S
+++ b/grub-core/lib/i386/relocator64.S
@@ -63,8 +63,10 @@ VARIABLE(grub_relocator64_cr3)
 	movq	%rax, %cr3
 #endif
 

+#ifdef __x86_64__
 	.code64
+#endif
 
 	/* mov imm64, %rax */
 	.byte 	0x48
@@ -71,7 +73,14 @@ VARIABLE(grub_relocator64_cr3)
 VARIABLE(grub_relocator64_rsp)
 	.quad	0
 
+#ifdef __x86_64__
 	movq	%rax, %rsp
+#else
+	/* movq	%rax, %rsp */
+	.byte 	0x48
+	.byte	0x89
+	.byte	0xc4
+#endif
 
 #ifdef GRUB_MACHINE_EFI
 	jmp	LOCAL(skip_efi_stack_align)
@@ -85,7 +94,14 @@ VARIABLE(grub_relocator64_rsp)
 	 */
 VARIABLE(grub_relocator64_efi_start)
 	/* Align the stack as UEFI spec requires. */
+#ifdef __x86_64__
 	andq	$~15, %rsp
+#else
+	.byte 0x48
+        .byte 0x83
+        .byte 0xe4
+        .byte 0xf0
+#endif
 
 LOCAL(skip_efi_stack_align):
 #endif
@@ -95,8 +111,15 @@ LOCAL(skip_efi_stack_align):
 VARIABLE(grub_relocator64_rsi)
 	.quad	0
 
+#ifdef	__x86_64__
 	movq	%rax, %rsi
-	
+#else
+	/* movq	%rax, %rsi */
+	.byte 	0x48
+	.byte	0x89
+	.byte 	0xc6
+#endif
+
 	/* mov imm64, %rax */
 	.byte 	0x48
 	.byte	0xb8
@@ -125,7 +148,7 @@ VARIABLE(grub_relocator64_rdx)
 	   payload and makes this implementation easier.  */
 	cld
 
-#ifdef __APPLE__
+#if defined (__APPLE__) || !defined (__x86_64__)
 	.byte 0xff, 0x25
 	.quad 0
 #else
-- 
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com



             reply	other threads:[~2021-05-18 10:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-18 10:47 Jan (janneke) Nieuwenhuizen [this message]
2021-05-18 10:58 ` [PATCH v2] grub-core: Build fixes for i386 John Paul Adrian Glaubitz
2021-05-18 14:26   ` Daniel Kiper
2021-05-18 14:35     ` John Paul Adrian Glaubitz
2021-05-18 14:38       ` John Paul Adrian Glaubitz
2021-05-18 20:06 ` Matt Turner
2021-05-26 15:04 ` Daniel Kiper
2021-05-26 18:18   ` Jan Nieuwenhuizen
2021-05-27 14:27     ` Daniel Kiper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210518104733.23391-1-janneke@gnu.org \
    --to=janneke@gnu.org \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.