From 2cb2d9100ad3524566263a17e8685f9bf3d01831 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sun, 30 Apr 2023 14:26:37 +0100 Subject: [PATCH] x86_64: define struct offsets for access from assembly --- arch/x86_64/asm-offset.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 arch/x86_64/asm-offset.c diff --git a/arch/x86_64/asm-offset.c b/arch/x86_64/asm-offset.c new file mode 100644 index 0000000..e583f37 --- /dev/null +++ b/arch/x86_64/asm-offset.c @@ -0,0 +1,27 @@ +#include +#include + +//size_t THREAD_sp = offsetof(struct thread, tr_sp); + +/* Use %a0 instead of %0 to prevent gcc from emitting a $ before the symbol value + in the generated assembly. + + emitting + .set TASK_sp, $56 + + instead of + .set TASK_sp, 56 + + causes garbage symbols to be generated. +*/ + +#define DEFINE(sym, val) \ + asm volatile("\n.global " #sym "\n.type " #sym ", @object" "\n.set " #sym ", %a0" : : "i" (val)) + +#define OFFSET(sym, str, mem) \ + DEFINE(sym, offsetof(str, mem)) + +static void __used common(void) +{ + OFFSET(THREAD_sp, struct thread, tr_sp); +}