diff --git a/arch/arm/core/aarch64/switch.S b/arch/arm/core/aarch64/switch.S index ea933e5ad26..0acaba7ee4b 100644 --- a/arch/arm/core/aarch64/switch.S +++ b/arch/arm/core/aarch64/switch.S @@ -35,17 +35,15 @@ SECTION_FUNC(TEXT, z_arm64_context_switch) ldr x2, =_thread_offset_to_callee_saved add x2, x2, x1 - /* Store callee-saved registers */ - stp x19, x20, [x2], #16 - stp x21, x22, [x2], #16 - stp x23, x24, [x2], #16 - stp x25, x26, [x2], #16 - stp x27, x28, [x2], #16 - stp x29, xzr, [x2], #16 - /* Save the current SP */ mov x1, sp - str x1, [x2] + + stp x19, x20, [x2, ___callee_saved_t_x19_x20_OFFSET] + stp x21, x22, [x2, ___callee_saved_t_x21_x22_OFFSET] + stp x23, x24, [x2, ___callee_saved_t_x23_x24_OFFSET] + stp x25, x26, [x2, ___callee_saved_t_x25_x26_OFFSET] + stp x27, x28, [x2, ___callee_saved_t_x27_x28_OFFSET] + stp x29, x1, [x2, ___callee_saved_t_x29_sp_OFFSET] #ifdef CONFIG_THREAD_LOCAL_STORAGE /* Grab the TLS pointer */ @@ -64,15 +62,13 @@ SECTION_FUNC(TEXT, z_arm64_context_switch) ldr x2, =_thread_offset_to_callee_saved add x2, x2, x0 - /* Restore x19-x29 */ - ldp x19, x20, [x2], #16 - ldp x21, x22, [x2], #16 - ldp x23, x24, [x2], #16 - ldp x25, x26, [x2], #16 - ldp x27, x28, [x2], #16 - ldp x29, xzr, [x2], #16 + ldp x19, x20, [x2, ___callee_saved_t_x19_x20_OFFSET] + ldp x21, x22, [x2, ___callee_saved_t_x21_x22_OFFSET] + ldp x23, x24, [x2, ___callee_saved_t_x23_x24_OFFSET] + ldp x25, x26, [x2, ___callee_saved_t_x25_x26_OFFSET] + ldp x27, x28, [x2, ___callee_saved_t_x27_x28_OFFSET] + ldp x29, x1, [x2, ___callee_saved_t_x29_sp_OFFSET] - ldr x1, [x2] mov sp, x1 #ifdef CONFIG_INSTRUMENT_THREAD_SWITCHING diff --git a/arch/arm/core/offsets/offsets_aarch64.c b/arch/arm/core/offsets/offsets_aarch64.c index 4e75c78038b..5bc4a7080bd 100644 --- a/arch/arm/core/offsets/offsets_aarch64.c +++ b/arch/arm/core/offsets/offsets_aarch64.c @@ -29,4 +29,13 @@ #include #include +GEN_NAMED_OFFSET_SYM(_callee_saved_t, x19, x19_x20); +GEN_NAMED_OFFSET_SYM(_callee_saved_t, x21, x21_x22); +GEN_NAMED_OFFSET_SYM(_callee_saved_t, x23, x23_x24); +GEN_NAMED_OFFSET_SYM(_callee_saved_t, x25, x25_x26); +GEN_NAMED_OFFSET_SYM(_callee_saved_t, x27, x27_x28); +GEN_NAMED_OFFSET_SYM(_callee_saved_t, x29, x29_sp); + +GEN_ABSOLUTE_SYM(___callee_saved_t_SIZEOF, sizeof(struct _callee_saved)); + #endif /* _ARM_OFFSETS_INC_ */ diff --git a/include/arch/arm/aarch64/thread.h b/include/arch/arm/aarch64/thread.h index 31165bf036a..414245870c9 100644 --- a/include/arch/arm/aarch64/thread.h +++ b/include/arch/arm/aarch64/thread.h @@ -34,7 +34,6 @@ struct _callee_saved { uint64_t x27; uint64_t x28; uint64_t x29; /* FP */ - uint64_t xzr; uint64_t sp; }; diff --git a/kernel/include/gen_offset.h b/kernel/include/gen_offset.h index 1fa1da5f689..7063a8fbd7d 100644 --- a/kernel/include/gen_offset.h +++ b/kernel/include/gen_offset.h @@ -32,6 +32,11 @@ * * ____OFFSET * + * The macro "GEN_NAMED_OFFSET_SYM(structure, member, name)" is also provided + * to create the symbol with the following form: + * + * ____OFFSET + * * This header also defines the GEN_ABSOLUTE_SYM macro to simply define an * absolute symbol, irrespective of whether the value represents a structure * or offset. @@ -79,4 +84,7 @@ #define GEN_OFFSET_SYM(S, M) \ GEN_ABSOLUTE_SYM(__##S##_##M##_##OFFSET, offsetof(S, M)) +#define GEN_NAMED_OFFSET_SYM(S, M, N) \ + GEN_ABSOLUTE_SYM(__##S##_##N##_##OFFSET, offsetof(S, M)) + #endif /* ZEPHYR_KERNEL_INCLUDE_GEN_OFFSET_H_ */