x86_64: define struct offsets for access from assembly
This commit is contained in:
27
arch/x86_64/asm-offset.c
Normal file
27
arch/x86_64/asm-offset.c
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#include <socks/sched.h>
|
||||||
|
#include <socks/compiler.h>
|
||||||
|
|
||||||
|
//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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user