]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[librm] Use explicit operand size when pushing a label address 1036/head
authorMichael Brown <mcb30@ipxe.org>
Tue, 5 Sep 2023 11:46:39 +0000 (12:46 +0100)
committerMichael Brown <mcb30@ipxe.org>
Tue, 5 Sep 2023 11:47:42 +0000 (12:47 +0100)
We currently use "push $1f" within inline assembly to push the address
of the real-mode code fragment, relying on the assembler to treat this
as "pushl" for 32-bit code or "pushq" for 64-bit code.

As of binutils commit 5cc0077 ("x86: further adjust extend-to-32bit-
address conditions"), first included in binutils-2.41, this implicit
operand size is no longer calculated as expected and 64-bit builds
will fail with

  Error: operand size mismatch for `push'

Fix by adding an explicit operand size to the "push" instruction.

Originally-fixed-by: Justin Cano <jstncno@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/x86/include/librm.h

index 5196d390faff0ad24a0d8d6bce0e3caf9bc56f80..40f075439a26aee3896351fbd2a8f76c1318ea36 100644 (file)
@@ -250,8 +250,10 @@ extern void remove_user_from_rm_stack ( userptr_t data, size_t size );
 /* CODE_DEFAULT: restore default .code32/.code64 directive */
 #ifdef __x86_64__
 #define CODE_DEFAULT ".code64"
+#define STACK_DEFAULT "q"
 #else
 #define CODE_DEFAULT ".code32"
+#define STACK_DEFAULT "l"
 #endif
 
 /* LINE_SYMBOL: declare a symbol for the current source code line */
@@ -268,7 +270,7 @@ extern void remove_user_from_rm_stack ( userptr_t data, size_t size );
 
 /* REAL_CODE: declare a fragment of code that executes in real mode */
 #define REAL_CODE( asm_code_str )                      \
-       "push $1f\n\t"                                  \
+       "push" STACK_DEFAULT " $1f\n\t"                 \
        "call real_call\n\t"                            \
        TEXT16_CODE ( "\n1:\n\t"                        \
                      asm_code_str                      \
@@ -277,7 +279,7 @@ extern void remove_user_from_rm_stack ( userptr_t data, size_t size );
 
 /* PHYS_CODE: declare a fragment of code that executes in flat physical mode */
 #define PHYS_CODE( asm_code_str )                      \
-       "push $1f\n\t"                                  \
+       "push" STACK_DEFAULT " $1f\n\t"                 \
        "call phys_call\n\t"                            \
        ".section \".text.phys\", \"ax\", @progbits\n\t"\
        "\n" LINE_SYMBOL "\n\t"                         \