From patchwork Wed Feb 11 14:32:49 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1812 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770820443; bh=VcOSq/VONhm/tZqSfrA3siPyB8ojGfWuzrc7gExC9OU=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=j5uDvjKMWHYJk0mBK2BQWYqdAD4qco+Fsj5lB/iQEi90m/wLmGrCC4w5Dbt/p1wTY lQ477hU2vgp1rJsqDgbYpFjgknbLlGUCMOST6CPO7tGwIkmEvgbwKcSGhaY8XRkNp4 LNngOtEhCoUMAt/DWnhofa/5V8zmd/MRd7o3fCSqQy6t8TgMJ6yYdNP5GAKu4U89M9 BJfCGDwLUrBCpcVIO3TRyEUFyiYzE8xG+Wm7IGWpXbNLh0In1rwm++VfOZtzSmNVzb lhL96klc57GIyf5JDxCH2BcpQ3IFubOrLJPAUaNw+lAwXGTrIJ63QT2xcNUnMoQJn8 l3Xz5AbsHOYMg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AFD9669A8C for ; Wed, 11 Feb 2026 07:34:03 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id W2cSMqlP7fQp for ; Wed, 11 Feb 2026 07:34:03 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770820443; bh=VcOSq/VONhm/tZqSfrA3siPyB8ojGfWuzrc7gExC9OU=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=j5uDvjKMWHYJk0mBK2BQWYqdAD4qco+Fsj5lB/iQEi90m/wLmGrCC4w5Dbt/p1wTY lQ477hU2vgp1rJsqDgbYpFjgknbLlGUCMOST6CPO7tGwIkmEvgbwKcSGhaY8XRkNp4 LNngOtEhCoUMAt/DWnhofa/5V8zmd/MRd7o3fCSqQy6t8TgMJ6yYdNP5GAKu4U89M9 BJfCGDwLUrBCpcVIO3TRyEUFyiYzE8xG+Wm7IGWpXbNLh0In1rwm++VfOZtzSmNVzb lhL96klc57GIyf5JDxCH2BcpQ3IFubOrLJPAUaNw+lAwXGTrIJ63QT2xcNUnMoQJn8 l3Xz5AbsHOYMg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9DB7B69A89 for ; Wed, 11 Feb 2026 07:34:03 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770820440; bh=g9NHXqB0TcX2mdcwDrHMpxQwMBZEZC4HNWPLKeRlNlg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qewmdLWLqfi0Ks0QNbC1SOvum9shN7Nd+MyBBgcH72ZMSRom7tjwvce71fmh6buOB TVT1UiuoMKkPbdsDxzhWWGXcIIhYZFxwbHs0GPH43YxBN35kb1QGgyeoWltt4orgj6 Gh9lLvsixn/pP/kKW/wbUe2aPoVOomw85JXPMstmtTe4m28zNu0lqOKa/oIkC2IEtq RRx6OfSpeaU4fvyK6OUg1gbZvY7pACZarX1a86d20vDLDZOqLpyKepDx94znJd0BOd iMQTpJUyf9aMPwkCn1jEr0ceqZvk0xWRBJJ94QphEWvzBKmISKw3G+jUeJdqAcAdya hgz7IcLQMSDtQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E13D769A82; Wed, 11 Feb 2026 07:34:00 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id vEmSc9GqKonk; Wed, 11 Feb 2026 07:34:00 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770820436; bh=RpHw9g171G4/WgThotDQOlm11U7wrvz+Tciqz1eJ9ts=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oEYQVJPeoMa+P865pZL66sbH+D0zc6PG1F8LWyIvD5HnMjNb9A7paf7W0r0u0L207 JIH4LRlcNTZtYqRqvub7xW1OGoqEi7E8GlNwIXvKuo1MlCPVFwb66At3L1DpVqLt7B lQP7cZSQFqzkWHJmJaduGnegI4x6x8aEiiutt5O4Yvl+qOyGa8+DGXvWoMx/qzJfZW NRD9VVj51Rx8IUcmcMs0LjiHV8BWYOisMw8W+aDqNpJ95lxRN25Yvg8BapoM0e4d4H 7YBfkhPdJdtenuUts9gHxYCPMmMqxu8/LevfnhzyBmJ00N7euCrTVO+LbJ4cuNJPPX bIr3lHv+3m2bg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 58B2B699BF; Wed, 11 Feb 2026 07:33:56 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 11 Feb 2026 07:32:49 -0700 Message-ID: <20260211143309.1183113-2-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260211143309.1183113-1-sjg@u-boot.org> References: <20260211143309.1183113-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: ISKOVQ6HTPIOIJH67T7NO6MBBDEQG5AX X-Message-ID-Hash: ISKOVQ6HTPIOIJH67T7NO6MBBDEQG5AX X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 01/12] x86: Allow disabling the regparm calling-convention List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass By default, U-Boot on 32-bit x86 uses -mregparm=3 to pass the first three function arguments in registers (EAX, EDX, ECX) rather than on the stack. This is more efficient but makes it harder to link U-Boot against libraries which expect the standard calling convention, e.g. using ulib from Rust. Add a Kconfig option X86_NO_REGPARM to disable regparm and use the standard i386 calling convention where all arguments are passed on the stack. Adjust the assembly-based startup code to support both options. For qemu-x86 this increases code size by about 42K, i.e. 4.1% growth. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- arch/x86/Kconfig | 14 ++++++++++++++ arch/x86/config.mk | 2 ++ arch/x86/cpu/i386/interrupt.c | 10 ++++++++-- arch/x86/cpu/start.S | 23 +++++++++++++++++++++-- arch/x86/cpu/start_from_spl.S | 21 ++++++++++++++++++++- arch/x86/cpu/start_from_tpl.S | 19 ++++++++++++++++++- 6 files changed, 83 insertions(+), 6 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 835cf2d8025..a7d616a401d 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -750,6 +750,20 @@ config X86_HARDFP start-up code for 64-bit mode and changes the compiler options for 64-bit to enable SSE. +config X86_NO_REGPARM + bool "Disable register parameters (regparm=3)" + depends on !X86_64 + help + By default, U-Boot on 32-bit x86 uses -mregparm=3 to pass the first + three function arguments in registers (EAX, EDX, ECX) rather than on + the stack. This is more efficient but can cause issues with debugging + tools or when interfacing with code that expects the standard calling + convention. + + Select this option to disable regparm and use the standard i386 + calling convention where all arguments are passed on the stack. This + may be useful for debugging or for running in certain emulators. + config HAVE_ITSS bool "Enable ITSS" help diff --git a/arch/x86/config.mk b/arch/x86/config.mk index 0deea05c15f..51f5026fb2c 100644 --- a/arch/x86/config.mk +++ b/arch/x86/config.mk @@ -83,8 +83,10 @@ LDSCRIPT := $(LDSCRIPT_EFI) else ifeq ($(IS_32BIT),y) +ifndef CONFIG_X86_NO_REGPARM PLATFORM_CPPFLAGS += -mregparm=3 endif +endif KBUILD_LDFLAGS += --emit-relocs LDFLAGS_FINAL += --gc-sections $(if $(CONFIG_XPL_BUILD),,-pie) diff --git a/arch/x86/cpu/i386/interrupt.c b/arch/x86/cpu/i386/interrupt.c index 6f78b072cde..22241005948 100644 --- a/arch/x86/cpu/i386/interrupt.c +++ b/arch/x86/cpu/i386/interrupt.c @@ -354,9 +354,15 @@ asm(".globl irq_common_entry\n" \ "pushl %esi\n" \ "pushl %edx\n" \ "pushl %ecx\n" \ - "pushl %ebx\n" \ - "mov %esp, %eax\n" \ + "pushl %ebx\n" +#ifdef CONFIG_X86_NO_REGPARM + "pushl %esp\n" \ "call irq_llsr\n" \ + "addl $4, %esp\n" +#else + "mov %esp, %eax\n" \ + "call irq_llsr\n" +#endif "popl %ebx\n" \ "popl %ecx\n" \ "popl %edx\n" \ diff --git a/arch/x86/cpu/start.S b/arch/x86/cpu/start.S index 385a691265e..a9f034d8c7e 100644 --- a/arch/x86/cpu/start.S +++ b/arch/x86/cpu/start.S @@ -134,10 +134,20 @@ car_init_ret: */ #endif /* Set up global data */ +#ifdef CONFIG_X86_NO_REGPARM + push %esp + call board_init_f_alloc_reserve + add $4, %esp + mov %eax, %esp + push %eax + call board_init_f_init_reserve + add $4, %esp +#else mov %esp, %eax call board_init_f_alloc_reserve mov %eax, %esp call board_init_f_init_reserve +#endif #ifdef CONFIG_DEBUG_UART call debug_uart_init @@ -171,10 +181,16 @@ skip_hob: /* Set parameter to board_init_f() to boot flags */ post_code(POST_START_DONE) - xorl %eax, %eax /* Enter, U-Boot! */ +#ifdef CONFIG_X86_NO_REGPARM + push $0 call board_init_f + add $4, %esp +#else + xorl %eax, %eax + call board_init_f +#endif /* indicate (lack of) progress */ movw $0x85, %ax @@ -188,10 +204,13 @@ board_init_f_r_trampoline: * RAM, BSS has been cleared and relocation adjustments have been * made. It is now time to jump into the in-RAM copy of U-Boot * - * %eax = Address of top of new stack + * %eax = Address of top of new stack (or 4(%esp) without regparm) */ /* Stack grows down from top of SDRAM */ +#ifdef CONFIG_X86_NO_REGPARM + movl 4(%esp), %eax +#endif movl %eax, %esp /* See if we need to disable CAR */ diff --git a/arch/x86/cpu/start_from_spl.S b/arch/x86/cpu/start_from_spl.S index abfd4abb623..1d6777c2160 100644 --- a/arch/x86/cpu/start_from_spl.S +++ b/arch/x86/cpu/start_from_spl.S @@ -38,18 +38,34 @@ _start: use_existing_stack: mov %esp, %eax 2: +#ifdef CONFIG_X86_NO_REGPARM + push %eax + call board_init_f_alloc_reserve + add $4, %esp + mov %eax, %esp + push %eax + call board_init_f_init_reserve + add $4, %esp +#else call board_init_f_alloc_reserve mov %eax, %esp call board_init_f_init_reserve +#endif #ifdef CONFIG_DEBUG_UART call debug_uart_init #endif call x86_cpu_reinit_f +#ifdef CONFIG_X86_NO_REGPARM + push $0 + call board_init_f + add $4, %esp +#else xorl %eax, %eax call board_init_f +#endif call board_init_f_r /* Should not return here */ @@ -64,10 +80,13 @@ board_init_f_r_trampoline: * adjustments have been made. It is now time to jump into the in-RAM * copy of U-Boot * - * %eax = Address of top of new stack + * %eax = Address of top of new stack (or 4(%esp) without regparm) */ /* Stack grows down from top of SDRAM */ +#ifdef CONFIG_X86_NO_REGPARM + movl 4(%esp), %eax +#endif movl %eax, %esp /* Re-enter U-Boot by calling board_init_f_r() */ diff --git a/arch/x86/cpu/start_from_tpl.S b/arch/x86/cpu/start_from_tpl.S index 9a4974a5f1b..ca6613217d2 100644 --- a/arch/x86/cpu/start_from_tpl.S +++ b/arch/x86/cpu/start_from_tpl.S @@ -15,6 +15,19 @@ .type _start, @function _start: /* Set up memory using the existing stack */ +#ifdef CONFIG_X86_NO_REGPARM + push %esp + call board_init_f_alloc_reserve + add $4, %esp + mov %eax, %esp + push %eax + call board_init_f_init_reserve + add $4, %esp + + push $0 + call board_init_f + add $4, %esp +#else mov %esp, %eax call board_init_f_alloc_reserve mov %eax, %esp @@ -23,6 +36,7 @@ _start: xorl %eax, %eax call board_init_f +#endif call board_init_f_r /* Should not return here */ @@ -35,10 +49,13 @@ board_init_f_r_trampoline: * TPL has been executed: SDRAM has been initialised, BSS has been * cleared. * - * %eax = Address of top of new stack + * %eax = Address of top of new stack (or 4(%esp) without regparm) */ /* Stack grows down from top of SDRAM */ +#ifdef CONFIG_X86_NO_REGPARM + movl 4(%esp), %eax +#endif movl %eax, %esp /* Re-enter SPL by calling board_init_f_r() */