Update register layout in user context
The changes for TLS changed the layout of registers and added registers
for each of the architectures changing the ordering, name, and rules for
initialisation.
diff --git a/libsel4debug/arch_include/riscv/sel4debug/arch/registers.h b/libsel4debug/arch_include/riscv/sel4debug/arch/registers.h
index e07d87f..93e88e4 100644
--- a/libsel4debug/arch_include/riscv/sel4debug/arch/registers.h
+++ b/libsel4debug/arch_include/riscv/sel4debug/arch/registers.h
@@ -20,12 +20,20 @@
"ra",
"sp",
"gp",
- "tp",
- "t0",
- "t1",
- "t2",
+
"s0",
"s1",
+ "s2",
+ "s3",
+ "s4",
+ "s5",
+ "s6",
+ "s7",
+ "s8",
+ "s9",
+ "s10",
+ "s11",
+
"a0",
"a1",
"a2",
@@ -33,5 +41,55 @@
"a4",
"a5",
"a6",
+ "a7",
+
+ "t0",
+ "t1",
+ "t2",
+ "t3",
+ "t4",
+ "t5",
+ "t6",
+
+ "tp",
};
+/* assert that register_names correspond to seL4_UserContext */
+compile_time_assert(register_names_correct_size, sizeof(register_names) == sizeof(seL4_UserContext));
+
+compile_time_assert(pc_correct_position, offsetof(seL4_UserContext, pc) == 0 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, ra) == 1 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, sp) == 2 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, gp) == 3 * sizeof(seL4_Word));
+
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, s0) == 4 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, s1) == 5 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, s2) == 6 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, s3) == 7 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, s4) == 8 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, s5) == 9 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, s6) == 10 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, s7) == 11 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, s8) == 12 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, s9) == 13 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, s10) == 14 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, s11) == 15 * sizeof(seL4_Word));
+
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, a0) == 16 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, a1) == 17 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, a2) == 18 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, a3) == 19 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, a4) == 20 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, a5) == 21 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, a6) == 22 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, a7) == 23 * sizeof(seL4_Word));
+
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, t0) == 24 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, t1) == 25 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, t2) == 26 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, t3) == 27 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, t4) == 28 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, t5) == 29 * sizeof(seL4_Word));
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, t6) == 30 * sizeof(seL4_Word));
+
+compile_time_assert(sp_correct_position, offsetof(seL4_UserContext, tp) == 31 * sizeof(seL4_Word));
diff --git a/libsel4debug/sel4_arch_include/aarch32/sel4debug/sel4_arch/registers.h b/libsel4debug/sel4_arch_include/aarch32/sel4debug/sel4_arch/registers.h
index 823cd60..0cf0fde 100644
--- a/libsel4debug/sel4_arch_include/aarch32/sel4debug/sel4_arch/registers.h
+++ b/libsel4debug/sel4_arch_include/aarch32/sel4debug/sel4_arch/registers.h
@@ -33,7 +33,9 @@
"r5",
"r6",
"r7",
- "lr"
+ "lr",
+ "tpidrurw",
+ "tpidruro",
};
/* assert that register_names correspond to seL4_UserContext */
@@ -54,4 +56,6 @@
compile_time_assert(r6_correct_position, offsetof(seL4_UserContext, r6) == 14 * sizeof(seL4_Word));
compile_time_assert(r7_correct_position, offsetof(seL4_UserContext, r7) == 15 * sizeof(seL4_Word));
compile_time_assert(r14_correct_position, offsetof(seL4_UserContext, r14) == 16 * sizeof(seL4_Word));
+compile_time_assert(tpidr_el0_correct_position, offsetof(seL4_UserContext, tpidr_el0) == 17 * sizeof(seL4_Word));
+compile_time_assert(tpidrro_el0_correct_position, offsetof(seL4_UserContext, tpidrro_el0) == 18 * sizeof(seL4_Word));
diff --git a/libsel4debug/sel4_arch_include/aarch64/sel4debug/sel4_arch/registers.h b/libsel4debug/sel4_arch_include/aarch64/sel4debug/sel4_arch/registers.h
index 37a4cec..c1ca2b8 100644
--- a/libsel4debug/sel4_arch_include/aarch64/sel4debug/sel4_arch/registers.h
+++ b/libsel4debug/sel4_arch_include/aarch64/sel4debug/sel4_arch/registers.h
@@ -50,7 +50,9 @@
"x25",
"x26",
"x27",
- "x28"
+ "x28",
+ "tpidr_el0",
+ "tpidrro_el0",
};
/* assert that register_names correspond to seL4_UserContext */
@@ -88,4 +90,6 @@
compile_time_assert(x26_correct_position, offsetof(seL4_UserContext, x26) == 31 * sizeof(seL4_Word));
compile_time_assert(x27_correct_position, offsetof(seL4_UserContext, x27) == 32 * sizeof(seL4_Word));
compile_time_assert(x28_correct_position, offsetof(seL4_UserContext, x28) == 33 * sizeof(seL4_Word));
+compile_time_assert(x28_correct_position, offsetof(seL4_UserContext, tpidr_el0) == 34 * sizeof(seL4_Word));
+compile_time_assert(x28_correct_position, offsetof(seL4_UserContext, tpidrro_el0) == 35 * sizeof(seL4_Word));
diff --git a/libsel4debug/sel4_arch_include/ia32/sel4debug/sel4_arch/registers.h b/libsel4debug/sel4_arch_include/ia32/sel4debug/sel4_arch/registers.h
index 77323c9..ba30047 100644
--- a/libsel4debug/sel4_arch_include/ia32/sel4debug/sel4_arch/registers.h
+++ b/libsel4debug/sel4_arch_include/ia32/sel4debug/sel4_arch/registers.h
@@ -27,10 +27,10 @@
"esi",
"edi",
"ebp",
- "tls_base",
- "fs",
- "gs",
+ "fs_base",
+ "gs_base",
};
+compile_time_assert(register_names_correct_size, sizeof(register_names) == sizeof(seL4_UserContext));
/* assert that register_names correspond to seL4_UserContext */
compile_time_assert(eip_correct_position, offsetof(seL4_UserContext, eip) == 0);
@@ -43,7 +43,6 @@
compile_time_assert(esi_correct_position, offsetof(seL4_UserContext, esi) == 7 * sizeof(seL4_Word));
compile_time_assert(edi_correct_position, offsetof(seL4_UserContext, edi) == 8 * sizeof(seL4_Word));
compile_time_assert(ebp_correct_position, offsetof(seL4_UserContext, ebp) == 9 * sizeof(seL4_Word));
-compile_time_assert(tls_base_correct_position, offsetof(seL4_UserContext, tls_base) == 10 * sizeof(seL4_Word));
-compile_time_assert(fs_correct_position, offsetof(seL4_UserContext, fs) == 11 * sizeof(seL4_Word));
-compile_time_assert(gs_correct_position, offsetof(seL4_UserContext, gs) == 12 * sizeof(seL4_Word));
+compile_time_assert(fs_base_correct_position, offsetof(seL4_UserContext, fs_base) == 10 * sizeof(seL4_Word));
+compile_time_assert(gs_base_correct_position, offsetof(seL4_UserContext, gs_base) == 11 * sizeof(seL4_Word));
diff --git a/libsel4debug/sel4_arch_include/x86_64/sel4debug/sel4_arch/registers.h b/libsel4debug/sel4_arch_include/x86_64/sel4debug/sel4_arch/registers.h
index d1cfba2..4fff4b1 100644
--- a/libsel4debug/sel4_arch_include/x86_64/sel4debug/sel4_arch/registers.h
+++ b/libsel4debug/sel4_arch_include/x86_64/sel4debug/sel4_arch/registers.h
@@ -35,8 +35,10 @@
"r13",
"r14",
"r15",
- "tls_base",
+ "fs_base",
+ "gs_base",
};
+compile_time_assert(register_names_correct_size, sizeof(register_names) == sizeof(seL4_UserContext));
/* assert that register_names correspond to seL4_UserContext */
compile_time_assert(eip_correct_position, offsetof(seL4_UserContext, rip) == 0);
@@ -57,4 +59,5 @@
compile_time_assert(ebp_correct_position, offsetof(seL4_UserContext, r13) == 15 * sizeof(seL4_Word));
compile_time_assert(ebp_correct_position, offsetof(seL4_UserContext, r14) == 16 * sizeof(seL4_Word));
compile_time_assert(ebp_correct_position, offsetof(seL4_UserContext, r15) == 17 * sizeof(seL4_Word));
-compile_time_assert(tls_base_correct_position, offsetof(seL4_UserContext, tls_base) == 18 * sizeof(seL4_Word));
+compile_time_assert(fs_base_correct_position, offsetof(seL4_UserContext, fs_base) == 18 * sizeof(seL4_Word));
+compile_time_assert(gs_base_correct_position, offsetof(seL4_UserContext, gs_base) == 19 * sizeof(seL4_Word));
diff --git a/libsel4utils/src/sel4_arch/ia32/arch.c b/libsel4utils/src/sel4_arch/ia32/arch.c
index 452f335..7cda098 100644
--- a/libsel4utils/src/sel4_arch/ia32/arch.c
+++ b/libsel4utils/src/sel4_arch/ia32/arch.c
@@ -17,24 +17,20 @@
#include <utils/stack.h>
#include <stdbool.h>
-int
-sel4utils_arch_init_context(void *entry_point, void *stack_top, seL4_UserContext *context)
+int sel4utils_arch_init_context(void *entry_point, void *stack_top, seL4_UserContext *context)
{
context->esp = (seL4_Word) stack_top;
/* set edx to zero in case we are setting this when spawning a process as
* edx is the atexit parameter, which we currently do not use */
context->edx = 0;
- context->fs = IPCBUF_GDT_SELECTOR;
context->eip = (seL4_Word) entry_point;
- context->gs = TLS_GDT_SELECTOR;
return 0;
}
-int
-sel4utils_arch_init_context_with_args(sel4utils_thread_entry_fn entry_point, void *arg0, void *arg1, void *arg2,
- bool local_stack, void *stack_top, seL4_UserContext *context,
- vka_t *vka, vspace_t *local_vspace, vspace_t *remote_vspace)
+int sel4utils_arch_init_context_with_args(sel4utils_thread_entry_fn entry_point, void *arg0, void *arg1, void *arg2,
+ bool local_stack, void *stack_top, seL4_UserContext *context,
+ vka_t *vka, vspace_t *local_vspace, vspace_t *remote_vspace)
{
if (!IS_ALIGNED((uintptr_t)stack_top, STACK_CALL_ALIGNMENT_BITS)) {
@@ -62,7 +58,7 @@
stack_ptr[-3] = (seL4_Word) arg0;
stack_ptr[-2] = (seL4_Word) arg1;
stack_ptr[-1] = (seL4_Word) arg2;
- stack_top = (void *) ((uintptr_t) stack_top - sizeof(stack_args));
+ stack_top = (void *)((uintptr_t) stack_top - sizeof(stack_args));
} else if (local_vspace && remote_vspace && vka) {
int error = sel4utils_stack_write(local_vspace, remote_vspace, vka, stack_args, sizeof(stack_args),
(uintptr_t *) &stack_top);