diff mbox series

[4/4] x86/boot: Use fastcall for 32bit code

Message ID 20240902133232.3302839-5-andrew.cooper3@citrix.com (mailing list archive)
State New
Headers show
Series xen/boot: Remove defs.h | expand

Commit Message

Andrew Cooper Sept. 2, 2024, 1:32 p.m. UTC
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Frediano Ziglio <frediano.ziglio@cloud.com>

RFC.  This doesn't boot, but I haven't quite figured out where yet.
---
 xen/arch/x86/boot/Makefile  |  2 +-
 xen/arch/x86/boot/cmdline.c |  7 +++----
 xen/arch/x86/boot/head.S    | 15 +++++++++------
 xen/arch/x86/boot/reloc.c   | 12 ++++++------
 4 files changed, 19 insertions(+), 17 deletions(-)

Comments

Jan Beulich Sept. 2, 2024, 3:39 p.m. UTC | #1
On 02.09.2024 15:32, Andrew Cooper wrote:
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Roger Pau Monné <roger.pau@citrix.com>
> CC: Frediano Ziglio <frediano.ziglio@cloud.com>
> 
> RFC.  This doesn't boot, but I haven't quite figured out where yet.

Because you got the register use wrong maybe? I think it's %eax, %edx,
and then %ecx.

Jan
Andrew Cooper Sept. 2, 2024, 3:42 p.m. UTC | #2
On 02/09/2024 4:39 pm, Jan Beulich wrote:
> On 02.09.2024 15:32, Andrew Cooper wrote:
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
>> ---
>> CC: Jan Beulich <JBeulich@suse.com>
>> CC: Roger Pau Monné <roger.pau@citrix.com>
>> CC: Frediano Ziglio <frediano.ziglio@cloud.com>
>>
>> RFC.  This doesn't boot, but I haven't quite figured out where yet.
> Because you got the register use wrong maybe? I think it's %eax, %edx,
> and then %ecx.

Bah, yes it is.  Also,

@@ -848,9 +851,9 @@ trampoline_setup:
         testl   $MBI_CMDLINE,MB_flags(%ebx)
         jz      1f
 
-        lea     sym_esi(early_boot_opts),%eax
-        push    %eax
-        pushl   MB_cmdline(%ebx)
+        lea     sym_esi(early_boot_opts), %ecx
+        lea     MB_cmdline(%ebx), %eax
+        /*      cmdline_parse_early(cmdline, opts) using fastcall(a, c). */
         call    cmdline_parse_early
 
 1:

is a wrong transformation I think.  The second leal should be mov.

I'll have another play when I've got some time, but for now I'll commit
the prior 3 patch to get rid of defs.h.

~Andrew
diff mbox series

Patch

diff --git a/xen/arch/x86/boot/Makefile b/xen/arch/x86/boot/Makefile
index 03d8ce3a9e48..b327663fba94 100644
--- a/xen/arch/x86/boot/Makefile
+++ b/xen/arch/x86/boot/Makefile
@@ -13,7 +13,7 @@  $(obj)/head.o: $(head-bin-objs:.o=.bin)
 
 CFLAGS_x86_32 := $(subst -m64,-m32 -march=i686,$(XEN_TREEWIDE_CFLAGS))
 $(call cc-options-add,CFLAGS_x86_32,CC,$(EMBEDDED_EXTRA_CFLAGS))
-CFLAGS_x86_32 += -Werror -fno-builtin -g0 -msoft-float
+CFLAGS_x86_32 += -Werror -fno-builtin -g0 -msoft-float -mregparm=3
 ifneq ($(abs_objtree),$(abs_srctree))
 CFLAGS_x86_32 += -I$(objtree)/include
 endif
diff --git a/xen/arch/x86/boot/cmdline.c b/xen/arch/x86/boot/cmdline.c
index bdd5b95c224b..6eddbb37b5b9 100644
--- a/xen/arch/x86/boot/cmdline.c
+++ b/xen/arch/x86/boot/cmdline.c
@@ -20,8 +20,8 @@ 
 
 /*
  * This entry point is entered from xen/arch/x86/boot/head.S with:
- *   - 0x4(%esp) = &cmdline,
- *   - 0x8(%esp) = &early_boot_opts.
+ *   - %eax      = &cmdline,
+ *   - %ecx      = &early_boot_opts.
  */
 asm (
     "    .text                         \n"
@@ -347,8 +347,7 @@  static void vga_parse(const char *cmdline, early_boot_opts_t *ebo)
 #endif
 
 /* SAF-1-safe */
-void __attribute__((__stdcall__))
-cmdline_parse_early(const char *cmdline, early_boot_opts_t *ebo)
+void cmdline_parse_early(const char *cmdline, early_boot_opts_t *ebo)
 {
     if ( !cmdline )
         return;
diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S
index d867b015d961..b745a7cd3a26 100644
--- a/xen/arch/x86/boot/head.S
+++ b/xen/arch/x86/boot/head.S
@@ -613,10 +613,13 @@  trampoline_setup:
 
         /* Save Multiboot / PVH info struct (after relocation) for later use. */
         push    %edx                /* Boot video info to be filled from MB2. */
-        push    %ecx                /* Bottom-most low-memory stack address. */
-        push    %ebx                /* Multiboot / PVH information address. */
-        push    %eax                /* Magic number. */
+        mov     %ecx, %edx          /* Bottom-most low-memory stack address. */
+        mov     %ebx, %ecx          /* Multiboot / PVH information address. */
+                                    /* Magic number. */
+        /*      reloc(magic, info, trampoline, video) using fastcall(a, c, d, stk). */
         call    reloc
+        add     $4, %esp
+
 #ifdef CONFIG_PVH_GUEST
         cmpb    $0, sym_esi(pvh_boot)
         je      1f
@@ -848,9 +851,9 @@  trampoline_setup:
         testl   $MBI_CMDLINE,MB_flags(%ebx)
         jz      1f
 
-        lea     sym_esi(early_boot_opts),%eax
-        push    %eax
-        pushl   MB_cmdline(%ebx)
+        lea     sym_esi(early_boot_opts), %ecx
+        lea     MB_cmdline(%ebx), %eax
+        /*      cmdline_parse_early(cmdline, opts) using fastcall(a, c). */
         call    cmdline_parse_early
 
 1:
diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c
index 1e3a30fab0c6..32acded81d78 100644
--- a/xen/arch/x86/boot/reloc.c
+++ b/xen/arch/x86/boot/reloc.c
@@ -14,10 +14,10 @@ 
 
 /*
  * This entry point is entered from xen/arch/x86/boot/head.S with:
- *   - 0x04(%esp) = MAGIC,
- *   - 0x08(%esp) = INFORMATION_ADDRESS,
- *   - 0x0c(%esp) = TOPMOST_LOW_MEMORY_STACK_ADDRESS.
- *   - 0x10(%esp) = BOOT_VIDEO_INFO_ADDRESS.
+ *   - %eax       = MAGIC,
+ *   - %ecx       = INFORMATION_ADDRESS,
+ *   - %edx       = TOPMOST_LOW_MEMORY_STACK_ADDRESS.
+ *   - 0x04(%esp) = BOOT_VIDEO_INFO_ADDRESS.
  */
 asm (
     "    .text                         \n"
@@ -353,8 +353,8 @@  static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out)
 }
 
 /* SAF-1-safe */
-void *__attribute__((__stdcall__))
-reloc(uint32_t magic, uint32_t in, uint32_t trampoline, uint32_t video_info)
+void *reloc(uint32_t magic, uint32_t in, uint32_t trampoline,
+            uint32_t video_info)
 {
     alloc = trampoline;