]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
arch/*: Add an non-aligned version for stack-pushing
authorTianyi Liu <i.pear@outlook.com>
Fri, 15 Sep 2023 18:02:41 +0000 (02:02 +0800)
committerRazvan Deaconescu <razvand@unikraft.io>
Fri, 20 Oct 2023 16:32:28 +0000 (19:32 +0300)
For AArch64, `ukarch_rctx_stackpush` may add padding to make sure
the `sp` register is aligned to 16 bytes. But there're also some
use cases where alignment is not allowed. In such cases, the newly
added `ukarch_rctx_stackpush_packed` and `ukarch_rstack_push_packed`
will be useful.

Signed-off-by: Tianyi Liu <i.pear@outlook.com>
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #1096

arch/arm/arm64/include/uk/asm/ctx.h
arch/x86/x86_64/include/uk/asm/ctx.h
include/uk/arch/ctx.h

index 8a1e62d8f1786bb2e72f6623539e34d208d5f0df..95253ebf92b684b6ed8e516a83230ef77c6ad838 100644 (file)
                __sp__;                                 \
        })
 
+#define ukarch_rstack_push_packed(sp, value)           \
+       ({                                              \
+               unsigned long __sp__ = (sp);            \
+               __sp__ -= sizeof(value);                \
+               *((typeof(value) *) __sp__) = (value);  \
+               __sp__;                                 \
+       })
+
 #define ukarch_gen_sp(base, len)                                       \
        ({                                                              \
                unsigned long __sp__ = (unsigned long) (base)           \
index 2cc8d47848c3a2f080a36946e55fadf9e8150740..715f06247f809a86077776a38a0b2614b43c3b42 100644 (file)
@@ -39,6 +39,9 @@
                __sp__;                                 \
        })
 
+#define ukarch_rstack_push_packed(sp, value)           \
+       ukarch_rstack_push(sp, value)
+
 #define UKARCH_SP_ALIGN                (1 << 4)
 #define UKARCH_SP_ALIGN_MASK   (UKARCH_SP_ALIGN - 1)
 
index dda40e2b1eb077688f0c7fcd10b37eebbe9b01e0..f5e8d481995bddad2c50f3a4a97ca17a652abdb4 100644 (file)
@@ -173,6 +173,14 @@ void ukarch_ctx_init_entry2(struct ukarch_ctx *ctx,
                (ctx)->sp = ukarch_rstack_push((ctx)->sp, (value));     \
        })
 
+/**
+ * Similar to `ukarch_rctx_stackpush()` but without alignment.
+ */
+#define ukarch_rctx_stackpush_packed(ctx, value)                       \
+       ({                                                              \
+               (ctx)->sp = ukarch_rstack_push_packed((ctx)->sp, (value)); \
+       })
+
 /**
  * Switch the current logical CPU to context `load`. The current context
  * is stored to `store`. The standard register set is saved to `store`'s