Skip to contentSkip to conversation

xen/boot: Remove defs.h

PATCH In review Andrew Cooper 3 participants 13 messages Sep 2, 2024 – Sep 3, 2024

lore
Share & tools
lore
#0 lore raw

cover xen/boot: Remove defs.h

Patch 1 posted in isolation before.

Patches 2 and 3 complete the removal of defs.h.

Patch 4 doesn't work yet and needs further debugging.

Andrew Cooper (4):
x86/boot: Use <xen/types.h>
x86/boot: Use <xen/macros.h>
x86/boot: Use <xen/compiler.h>
x86/boot: Use fastcall for 32bit code

 xen/arch/x86/boot/Makefile  |  2 +-
 xen/arch/x86/boot/cmdline.c | 14 ++++++---
 xen/arch/x86/boot/defs.h    | 63 -------------------------------------
 xen/arch/x86/boot/head.S    | 15 +++++----
 xen/arch/x86/boot/reloc.c   | 26 ++++++++-------
 xen/include/xen/kernel.h    | 36 +--------------------
 xen/include/xen/lib.h       |  2 --
 xen/include/xen/macros.h    | 44 ++++++++++++++++++++++++++
 8 files changed, 79 insertions(+), 123 deletions(-)
 delete mode 100644 xen/arch/x86/boot/defs.h

base-commit: e884903ec56be8b0cc658cc5ba7c1cb70f25208d

Signature · 1 line
2.39.2
#1 lore raw

PATCH 1/4 x86/boot: Use <xen/types.h>

... rather than opencoding locally. This also covers NULL and *_MAX.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Frediano Ziglio <[email protected]>

---
 xen/arch/x86/boot/cmdline.c |  2 ++
 xen/arch/x86/boot/defs.h    | 17 -----------------
 xen/arch/x86/boot/reloc.c   |  2 ++
 3 files changed, 4 insertions(+), 17 deletions(-)
xen/arch/x86/boot/cmdline.c +2 -0
index b8ad7f3a144a..28a47da7ab02 100644
@@ -31,6 +31,8 @@ asm (
     );
 
 #include <xen/kconfig.h>
+#include <xen/types.h>
+
 #include "defs.h"
 #include "video.h"
 
xen/arch/x86/boot/defs.h +0 -17
index ee1a4da6af03..cf9a80d116f3 100644
@@ -20,14 +20,10 @@
 #ifndef __BOOT_DEFS_H__
 #define __BOOT_DEFS_H__
 
-#include <xen/stdbool.h>
-
 #define __maybe_unused	__attribute__((__unused__))
 #define __packed	__attribute__((__packed__))
 #define __stdcall	__attribute__((__stdcall__))
 
-#define NULL		((void *)0)
-
 #define ALIGN_UP(arg, align) \
                 (((arg) + (align) - 1) & ~((typeof(arg))(align) - 1))
 
@@ -47,17 +43,4 @@
 
 #define tolower(c)	((c) | 0x20)
 
-typedef unsigned char u8;
-typedef unsigned short u16;
-typedef unsigned int u32;
-typedef unsigned long long u64;
-typedef unsigned int size_t;
-typedef u8 uint8_t;
-typedef u16 uint16_t;
-typedef u32 uint32_t;
-typedef u64 uint64_t;
-
-#define UINT16_MAX	((uint16_t)(~0U))
-#define UINT_MAX	(~0U)
-
 #endif /* __BOOT_DEFS_H__ */
xen/arch/x86/boot/reloc.c +2 -0
index 589e026ff9fb..ac8b58b69581 100644
@@ -26,6 +26,8 @@ asm (
     "    jmp  reloc                    \n"
     );
 
+#include <xen/types.h>
+
 #include "defs.h"
 
 #include <xen/kconfig.h>
Signature · 1 line
2.39.2
#2 lore raw

PATCH 2/4 x86/boot: Use <xen/macros.h>

In reply to Andrew Cooper

... rather than opencoding locally.

This involve collecting various macros scattered around Xen (min()/max() macros from kernel.h, and _p() from lib.h) and moving them into macros.h

In reloc.c, replace ALIGN_UP() with ROUNDUP().

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Frediano Ziglio <[email protected]>

---
 xen/arch/x86/boot/cmdline.c |  4 ++++
 xen/arch/x86/boot/defs.h    | 19 ----------------
 xen/arch/x86/boot/reloc.c   | 11 +++++-----
 xen/include/xen/kernel.h    | 36 +-----------------------------
 xen/include/xen/lib.h       |  2 --
 xen/include/xen/macros.h    | 44 +++++++++++++++++++++++++++++++++++++
 6 files changed, 55 insertions(+), 61 deletions(-)
xen/arch/x86/boot/cmdline.c +4 -0
index 28a47da7ab02..b7375d106678 100644
@@ -31,6 +31,7 @@ asm (
     );
 
 #include <xen/kconfig.h>
+#include <xen/macros.h>
 #include <xen/types.h>
 
 #include "defs.h"
@@ -50,6 +51,9 @@ typedef struct __packed {
 #endif
 } early_boot_opts_t;
 
+/* Avoid pulling in all of ctypes.h for this. */
+#define tolower(c)	((c) | 0x20)
+
 /*
  * Space and TAB are obvious delimiters. However, I am
  * adding "\n" and "\r" here too. Just in case when
xen/arch/x86/boot/defs.h +0 -19
index cf9a80d116f3..4d519ac4f5ea 100644
@@ -24,23 +24,4 @@
 #define __packed	__attribute__((__packed__))
 #define __stdcall	__attribute__((__stdcall__))
 
-#define ALIGN_UP(arg, align) \
-                (((arg) + (align) - 1) & ~((typeof(arg))(align) - 1))
-
-#define min(x,y) ({ \
-        const typeof(x) _x = (x);       \
-        const typeof(y) _y = (y);       \
-        (void) (&_x == &_y);            \
-        _x < _y ? _x : _y; })
-
-#define max(x,y) ({ \
-        const typeof(x) _x = (x);       \
-        const typeof(y) _y = (y);       \
-        (void) (&_x == &_y);            \
-        _x > _y ? _x : _y; })
-
-#define _p(val)		((void *)(unsigned long)(val))
-
-#define tolower(c)	((c) | 0x20)
-
 #endif /* __BOOT_DEFS_H__ */
xen/arch/x86/boot/reloc.c +6 -5
index ac8b58b69581..eb9902d73fd9 100644
@@ -26,6 +26,7 @@ asm (
     "    jmp  reloc                    \n"
     );
 
+#include <xen/macros.h>
 #include <xen/types.h>
 
 #include "defs.h"
@@ -76,7 +77,7 @@ static uint32_t alloc;
 
 static uint32_t alloc_mem(uint32_t bytes)
 {
-    return alloc -= ALIGN_UP(bytes, 16);
+    return alloc -= ROUNDUP(bytes, 16);
 }
 
 static void zero_mem(uint32_t s, uint32_t bytes)
@@ -202,11 +203,11 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out)
     zero_mem(ptr, sizeof(*mbi_out));
 
     /* Skip Multiboot2 information fixed part. */
-    ptr = ALIGN_UP(mbi_in + sizeof(*mbi_fix), MULTIBOOT2_TAG_ALIGN);
+    ptr = ROUNDUP(mbi_in + sizeof(*mbi_fix), MULTIBOOT2_TAG_ALIGN);
 
     /* Get the number of modules. */
     for ( tag = _p(ptr); (uint32_t)tag - mbi_in < mbi_fix->total_size;
-          tag = _p(ALIGN_UP((uint32_t)tag + tag->size, MULTIBOOT2_TAG_ALIGN)) )
+          tag = _p(ROUNDUP((uint32_t)tag + tag->size, MULTIBOOT2_TAG_ALIGN)) )
     {
         if ( tag->type == MULTIBOOT2_TAG_TYPE_MODULE )
             ++mbi_out->mods_count;
@@ -227,11 +228,11 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out)
     }
 
     /* Skip Multiboot2 information fixed part. */
-    ptr = ALIGN_UP(mbi_in + sizeof(*mbi_fix), MULTIBOOT2_TAG_ALIGN);
+    ptr = ROUNDUP(mbi_in + sizeof(*mbi_fix), MULTIBOOT2_TAG_ALIGN);
 
     /* Put all needed data into mbi_out. */
     for ( tag = _p(ptr); (uint32_t)tag - mbi_in < mbi_fix->total_size;
-          tag = _p(ALIGN_UP((uint32_t)tag + tag->size, MULTIBOOT2_TAG_ALIGN)) )
+          tag = _p(ROUNDUP((uint32_t)tag + tag->size, MULTIBOOT2_TAG_ALIGN)) )
     {
         switch ( tag->type )
         {
xen/include/xen/kernel.h +1 -35
index bc2440b5f96e..c5b6cc977772 100644
@@ -5,43 +5,9 @@
  * 'kernel.h' contains some often-used function prototypes etc
  */
 
+#include <xen/macros.h>
 #include <xen/types.h>
 
-/*
- * min()/max() macros that also do
- * strict type-checking.. See the
- * "unnecessary" pointer comparison.
- */
-#define min(x,y) ({ \
-        const typeof(x) _x = (x);       \
-        const typeof(y) _y = (y);       \
-        (void) (&_x == &_y);            \
-        _x < _y ? _x : _y; })
-
-#define max(x,y) ({ \
-        const typeof(x) _x = (x);       \
-        const typeof(y) _y = (y);       \
-        (void) (&_x == &_y);            \
-        _x > _y ? _x : _y; })
-
-/*
- * ..and if you can't take the strict
- * types, you can specify one yourself.
- *
- * Or not use min/max at all, of course.
- */
-#define min_t(type,x,y) \
-        ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
-#define max_t(type,x,y) \
-        ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
-
-/*
- * pre-processor, array size, and bit field width suitable variants;
- * please don't use in "normal" expressions.
- */
-#define MIN(x,y) ((x) < (y) ? (x) : (y))
-#define MAX(x,y) ((x) > (y) ? (x) : (y))
-
 /**
  * container_of - cast a member of a structure out to the containing structure
  *
xen/include/xen/lib.h +0 -2
index 394319c81863..e884a02ee8ce 100644
@@ -57,8 +57,6 @@ static inline void
 debugtrace_printk(const char *fmt, ...) {}
 #endif
 
-/* Allows us to use '%p' as general-purpose machine-word format char. */
-#define _p(_x) ((void *)(unsigned long)(_x))
 extern void printk(const char *fmt, ...)
     __attribute__ ((format (printf, 1, 2), cold));
 
xen/include/xen/macros.h +44 -0

50 lines not on this page · raw message

Signature · 1 line
2.39.2
Reviewed-by on v1 2/4
#3 lore raw

Re: [PATCH 2/4] x86/boot: Use <xen/macros.h>

Quoted 10 lines · Andrew Cooper

... rather than opencoding locally.

This involve collecting various macros scattered around Xen (min()/max() macros from kernel.h, and _p() from lib.h) and moving them into macros.h

In reloc.c, replace ALIGN_UP() with ROUNDUP().

No functional change.

#4 lore raw

Re: [PATCH 2/4] x86/boot: Use <xen/macros.h>

In reply to Andrew Cooper
Quoted 190 lines · Andrew Cooper

... rather than opencoding locally.

This involve collecting various macros scattered around Xen (min()/max() macros from kernel.h, and _p() from lib.h) and moving them into macros.h

In reloc.c, replace ALIGN_UP() with ROUNDUP().

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Frediano Ziglio <[email protected]>

---
 xen/arch/x86/boot/cmdline.c |  4 ++++
 xen/arch/x86/boot/defs.h    | 19 ----------------
 xen/arch/x86/boot/reloc.c   | 11 +++++-----
 xen/include/xen/kernel.h    | 36 +-----------------------------
 xen/include/xen/lib.h       |  2 --
 xen/include/xen/macros.h    | 44 +++++++++++++++++++++++++++++++++++++
 6 files changed, 55 insertions(+), 61 deletions(-)
xen/arch/x86/boot/cmdline.c +4 -0
index 28a47da7ab02..b7375d106678 100644
@@ -31,6 +31,7 @@ asm (
     );
 
 #include <xen/kconfig.h>
+#include <xen/macros.h>
 #include <xen/types.h>
 
 #include "defs.h"
@@ -50,6 +51,9 @@ typedef struct __packed {
 #endif
 } early_boot_opts_t;
 
+/* Avoid pulling in all of ctypes.h for this. */
+#define tolower(c)     ((c) | 0x20)
+
 /*
  * Space and TAB are obvious delimiters. However, I am
  * adding "\n" and "\r" here too. Just in case when
xen/arch/x86/boot/defs.h +0 -19
index cf9a80d116f3..4d519ac4f5ea 100644
@@ -24,23 +24,4 @@
 #define __packed       __attribute__((__packed__))
 #define __stdcall      __attribute__((__stdcall__))
 
-#define ALIGN_UP(arg, align) \
-                (((arg) + (align) - 1) & ~((typeof(arg))(align) - 1))
-
-#define min(x,y) ({ \
-        const typeof(x) _x = (x);       \
-        const typeof(y) _y = (y);       \
-        (void) (&_x == &_y);            \
-        _x < _y ? _x : _y; })
-
-#define max(x,y) ({ \
-        const typeof(x) _x = (x);       \
-        const typeof(y) _y = (y);       \
-        (void) (&_x == &_y);            \
-        _x > _y ? _x : _y; })
-
-#define _p(val)                ((void *)(unsigned long)(val))
-
-#define tolower(c)     ((c) | 0x20)
-
 #endif /* __BOOT_DEFS_H__ */
xen/arch/x86/boot/reloc.c +6 -5
index ac8b58b69581..eb9902d73fd9 100644
@@ -26,6 +26,7 @@ asm (
     "    jmp  reloc                    \n"
     );
 
+#include <xen/macros.h>
 #include <xen/types.h>
 
 #include "defs.h"
@@ -76,7 +77,7 @@ static uint32_t alloc;
 
 static uint32_t alloc_mem(uint32_t bytes)
 {
-    return alloc -= ALIGN_UP(bytes, 16);
+    return alloc -= ROUNDUP(bytes, 16);
 }
 
 static void zero_mem(uint32_t s, uint32_t bytes)
@@ -202,11 +203,11 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out)
     zero_mem(ptr, sizeof(*mbi_out));
 
     /* Skip Multiboot2 information fixed part. */
-    ptr = ALIGN_UP(mbi_in + sizeof(*mbi_fix), MULTIBOOT2_TAG_ALIGN);
+    ptr = ROUNDUP(mbi_in + sizeof(*mbi_fix), MULTIBOOT2_TAG_ALIGN);
 
     /* Get the number of modules. */
     for ( tag = _p(ptr); (uint32_t)tag - mbi_in < mbi_fix->total_size;
-          tag = _p(ALIGN_UP((uint32_t)tag + tag->size, MULTIBOOT2_TAG_ALIGN)) )
+          tag = _p(ROUNDUP((uint32_t)tag + tag->size, MULTIBOOT2_TAG_ALIGN)) )
     {
         if ( tag->type == MULTIBOOT2_TAG_TYPE_MODULE )
             ++mbi_out->mods_count;
@@ -227,11 +228,11 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out)
     }
 
     /* Skip Multiboot2 information fixed part. */
-    ptr = ALIGN_UP(mbi_in + sizeof(*mbi_fix), MULTIBOOT2_TAG_ALIGN);
+    ptr = ROUNDUP(mbi_in + sizeof(*mbi_fix), MULTIBOOT2_TAG_ALIGN);
 
     /* Put all needed data into mbi_out. */
     for ( tag = _p(ptr); (uint32_t)tag - mbi_in < mbi_fix->total_size;
-          tag = _p(ALIGN_UP((uint32_t)tag + tag->size, MULTIBOOT2_TAG_ALIGN)) )
+          tag = _p(ROUNDUP((uint32_t)tag + tag->size, MULTIBOOT2_TAG_ALIGN)) )
     {
         switch ( tag->type )
         {
xen/include/xen/kernel.h +1 -35
index bc2440b5f96e..c5b6cc977772 100644
@@ -5,43 +5,9 @@
  * 'kernel.h' contains some often-used function prototypes etc
  */
 
+#include <xen/macros.h>
 #include <xen/types.h>
 
-/*
- * min()/max() macros that also do
- * strict type-checking.. See the
- * "unnecessary" pointer comparison.
- */
-#define min(x,y) ({ \
-        const typeof(x) _x = (x);       \
-        const typeof(y) _y = (y);       \
-        (void) (&_x == &_y);            \
-        _x < _y ? _x : _y; })
-
-#define max(x,y) ({ \
-        const typeof(x) _x = (x);       \
-        const typeof(y) _y = (y);       \
-        (void) (&_x == &_y);            \
-        _x > _y ? _x : _y; })
-
-/*
- * ..and if you can't take the strict
- * types, you can specify one yourself.
- *
- * Or not use min/max at all, of course.
- */
-#define min_t(type,x,y) \
-        ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
-#define max_t(type,x,y) \
-        ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
-
-/*
- * pre-processor, array size, and bit field width suitable variants;
- * please don't use in "normal" expressions.
- */
-#define MIN(x,y) ((x) < (y) ? (x) : (y))
-#define MAX(x,y) ((x) > (y) ? (x) : (y))
-
 /**
  * container_of - cast a member of a structure out to the containing structure
  *
xen/include/xen/lib.h +0 -2
index 394319c81863..e884a02ee8ce 100644
@@ -57,8 +57,6 @@ static inline void
 debugtrace_printk(const char *fmt, ...) {}
 #endif
 
-/* Allows us to use '%p' as general-purpose machine-word format char. */
-#define _p(_x) ((void *)(unsigned long)(_x))
 extern void printk(const char *fmt, ...)
     __attribute__ ((format (printf, 1, 2), cold));
 
xen/include/xen/macros.h +0 -0
index 44d723fd121a..19caaa8026ea 100644

xen/include/xen/macros.h line 105

Quoted 5 lines
xen/include/xen/macros.h +2 -0
@@ -101,6 +101,50 @@
  */
 #define sizeof_field(type, member) sizeof(((type *)NULL)->member)
 
+/* Cast an arbitrary integer to a pointer. */
+#define _p(x) ((void *)(unsigned long)(x))

Really minor, and not a regression, I personally prefer uintptr_t instead of "unsigned long", beside portability (which is not an issue in Xen) is more clear we are dealing with a number representing a pointer.

Quoted 35 lines
xen/include/xen/macros.h +35 -0
+
+/*
+ * min()/max() macros that also do strict type-checking..
+ */
+#define min(x, y)                               \
+    ({                                          \
+        const typeof(x) _x = (x);               \
+        const typeof(y) _y = (y);               \
+        (void)(&_x == &_y); /* typecheck */     \
+        _x < _y ? _x : _y;                      \
+    })
+#define max(x, y)                               \
+    ({                                          \
+        const typeof(x) _x = (x);               \
+        const typeof(y) _y = (y);               \
+        (void)(&_x == &_y); /* typecheck */     \
+        _x > _y ? _x : _y;                      \
+    })
+
+/*
+ * ..and if you can't take the strict types, you can specify one yourself.
+ */
+#define min_t(type, x, y)                       \
+    ({                                          \
+        type __x = (x);                         \
+        type __y = (y);                         \
+        __x < __y ? __x: __y;                   \
+    })
+#define max_t(type, x, y)                       \
+    ({                                          \
+        type __x = (x);                         \
+        type __y = (y);                         \
+        __x > __y ? __x: __y;                   \
+    })
+

xen/include/xen/macros.h line 150

Quoted 10 lines
xen/include/xen/macros.h +7 -0
+/*
+ * pre-processor, array size, and bit field width suitable variants;
+ * please don't use in "normal" expressions.
+ */
+#define MIN(x, y) ((x) < (y) ? (x) : (y))
+#define MAX(x, y) ((x) > (y) ? (x) : (y))
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* __MACROS_H__ */

Beside the silly comment, I'm fine with the series.

Frediano

#5 lore raw

Re: [PATCH 2/4] x86/boot: Use <xen/macros.h>

Quoted 9 lines · Frediano Ziglio
Quoted 8 lines · Andrew Cooper
xen/include/xen/macros.h +0 -0
index 44d723fd121a..19caaa8026ea 100644
@@ -101,6 +101,50 @@
  */
 #define sizeof_field(type, member) sizeof(((type *)NULL)->member)
 
Quoted 6 lines

xen/include/xen/macros.h line 105

Quoted 2 lines
xen/include/xen/macros.h +2 -0
+/* Cast an arbitrary integer to a pointer. */
+#define _p(x) ((void *)(unsigned long)(x))

Really minor, and not a regression, I personally prefer uintptr_t instead of "unsigned long", beside portability (which is not an issue in Xen) is more clear we are dealing with a number representing a pointer.

This point has been brought up several times before.

Yes we probably ought to be using uintptr_t, but Xen is currently consistent in its use of unsigned long for this.

~Andrew

#6 lore raw

PATCH 3/4 x86/boot: Use <xen/compiler.h>

In reply to Andrew Cooper

... rather than opencoding locally. __stdcall is x86-only and not something we want to introduce to Xen generically, so opencode it in the two positions where it matters.

With this, defs.h is empty so delete it.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Frediano Ziglio <[email protected]>

I was hoping to do away with stdcall entirely and use fastcall instead, but I've clearly got something wrong and the result doesn't boot.

---
 xen/arch/x86/boot/cmdline.c |  5 +++--
 xen/arch/x86/boot/defs.h    | 27 ---------------------------
 xen/arch/x86/boot/reloc.c   |  7 +++----
 3 files changed, 6 insertions(+), 33 deletions(-)
 delete mode 100644 xen/arch/x86/boot/defs.h
xen/arch/x86/boot/cmdline.c +3 -2
index b7375d106678..bdd5b95c224b 100644
@@ -30,11 +30,11 @@ asm (
     "    jmp  cmdline_parse_early      \n"
     );
 
+#include <xen/compiler.h>
 #include <xen/kconfig.h>
 #include <xen/macros.h>
 #include <xen/types.h>
 
-#include "defs.h"
 #include "video.h"
 
 /* Keep in sync with trampoline.S:early_boot_opts label! */
@@ -347,7 +347,8 @@ static void vga_parse(const char *cmdline, early_boot_opts_t *ebo)
 #endif
 
 /* SAF-1-safe */
-void __stdcall cmdline_parse_early(const char *cmdline, early_boot_opts_t *ebo)
+void __attribute__((__stdcall__))
+cmdline_parse_early(const char *cmdline, early_boot_opts_t *ebo)
 {
     if ( !cmdline )
         return;
xen/arch/x86/boot/defs.h deleted +0 -27
deleted file mode 100644
index 4d519ac4f5ea..000000000000
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- * max() was copied from xen/xen/include/xen/kernel.h.
- */
-
-#ifndef __BOOT_DEFS_H__
-#define __BOOT_DEFS_H__
-
-#define __maybe_unused	__attribute__((__unused__))
-#define __packed	__attribute__((__packed__))
-#define __stdcall	__attribute__((__stdcall__))
-
-#endif /* __BOOT_DEFS_H__ */
xen/arch/x86/boot/reloc.c +3 -4
index eb9902d73fd9..1e3a30fab0c6 100644
@@ -26,11 +26,10 @@ asm (
     "    jmp  reloc                    \n"
     );
 
+#include <xen/compiler.h>
 #include <xen/macros.h>
 #include <xen/types.h>
 
-#include "defs.h"
-
 #include <xen/kconfig.h>
 #include <xen/multiboot.h>
 #include <xen/multiboot2.h>
@@ -354,8 +353,8 @@ static multiboot_info_t *mbi2_reloc(uint32_t mbi_in, uint32_t video_out)
 }
 
 /* SAF-1-safe */
-void *__stdcall reloc(uint32_t magic, uint32_t in, uint32_t trampoline,
-                      uint32_t video_info)
+void *__attribute__((__stdcall__))
+reloc(uint32_t magic, uint32_t in, uint32_t trampoline, uint32_t video_info)
 {
     alloc = trampoline;
 
Signature · 1 line
2.39.2
Reviewed-by on v1 3/4
#7 lore raw

Re: [PATCH 3/4] x86/boot: Use <xen/compiler.h>

Quoted 9 lines · Andrew Cooper

... rather than opencoding locally. __stdcall is x86-only and not something we want to introduce to Xen generically, so opencode it in the two positions where it matters.

With this, defs.h is empty so delete it.

No functional change.

#8 lore raw

PATCH 4/4 x86/boot: Use fastcall for 32bit code

In reply to Andrew Cooper

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Frediano Ziglio <[email protected]>

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(-)
xen/arch/x86/boot/Makefile +1 -1
index 03d8ce3a9e48..b327663fba94 100644
@@ -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
xen/arch/x86/boot/cmdline.c +3 -4
index bdd5b95c224b..6eddbb37b5b9 100644
@@ -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;
xen/arch/x86/boot/head.S +9 -6
index d867b015d961..b745a7cd3a26 100644
@@ -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:
xen/arch/x86/boot/reloc.c +6 -6
index 1e3a30fab0c6..32acded81d78 100644
@@ -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;
 
Signature · 1 line
2.39.2
#10 lore raw

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

Quoted 10 lines · Jan Beulich
Quoted 7 lines · Andrew Cooper

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Frediano Ziglio <[email protected]>

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

#11 lore raw

PATCH v2 1/1 x86/boot: Use fastcall for 32bit code

In reply to Andrew Cooper

This is marginally more efficient, but is mostly to get rid of the use of stdcall in cmdline.c and reloc.c

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Frediano Ziglio <[email protected]>

v2:
* Fixed up to work properly.

I'm tempted to rebase this ahead of "[PATCH 3/4] x86/boot: Use <xen/compiler.h>" and remove the transatory opencoding of __stdcall.

With some manual ELF annotations around the incbin's, this is the marginal delta:

  $ ../scripts/bloat-o-meter xen-syms-before xen-syms-after
  add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-188 (-188)
  Function                                     old     new   delta
  reloc                                       2352    2328     -24
  cmdline_parse_early                         2699    2535    -164
---
 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, 18 insertions(+), 18 deletions(-)
xen/arch/x86/boot/Makefile +1 -1
index 03d8ce3a9e48..b327663fba94 100644
@@ -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
xen/arch/x86/boot/cmdline.c +3 -4
index bdd5b95c224b..fc9241ede9a0 100644
@@ -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,
+ *   - %edx      = &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;
xen/arch/x86/boot/head.S +8 -7
index 3c0346016ce8..f7497bce393c 100644
@@ -613,10 +613,11 @@ 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     %ebx, %edx          /* Multiboot / PVH information address. */
+        /*      reloc(magic/eax, info/edx, trampoline/ecx, video/stk) using fastcall. */
         call    reloc
+        add     $4, %esp
+
 #ifdef CONFIG_PVH_GUEST
         cmpb    $0, sym_esi(pvh_boot)
         je      1f
@@ -848,9 +849,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), %edx
+        mov     MB_cmdline(%ebx), %eax
+        /*      cmdline_parse_early(cmdline/eax, opts/edx) using fastcall. */
         call    cmdline_parse_early
 
 1:
@@ -871,7 +872,7 @@ trampoline_setup:
 
         /*
          * cmdline and reloc are written in C, and linked to be 32bit PIC with
-         * entrypoints at 0 and using the stdcall convention.
+         * entrypoints at 0 and using the fastcall convention.
          */
 FUNC(cmdline_parse_early)
         .incbin "cmdline.bin"
xen/arch/x86/boot/reloc.c +6 -6
index 1e3a30fab0c6..201e38d5445d 100644
@@ -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,
+ *   - %edx       = INFORMATION_ADDRESS,
+ *   - %ecx       = 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;
 

base-commit: e884903ec56be8b0cc658cc5ba7c1cb70f25208d
prerequisite-patch-id: eb50bac1dc5f4cec5653dfe46bb2c714035c8235
prerequisite-patch-id: f08a81c17bc5d1fbc73ad681dd834e077929fbd4
prerequisite-patch-id: ee066a61cacb309e0a9a186051a380ab985e7d63
prerequisite-patch-id: 78e4e47fd945ab266604b208a735601eed301017

Signature · 1 line
2.39.2
Reviewed-by on v2 1/1
#12 lore raw

Re: [PATCH v2] x86/boot: Use fastcall for 32bit code

Quoted 6 lines · Andrew Cooper

This is marginally more efficient, but is mostly to get rid of the use of stdcall in cmdline.c and reloc.c

No functional change.

Quoted 5 lines

v2:
* Fixed up to work properly.

I'm tempted to rebase this ahead of "[PATCH 3/4] x86/boot: Use <xen/compiler.h>" and remove the transatory opencoding of __stdcall.

Fine with me either way.

Jan