2019-11-11 00:17:19 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Carlo Caione <ccaione@baylibre.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief ARM64 kernel structure member offset definition file
|
|
|
|
*
|
|
|
|
* This module is responsible for the generation of the absolute symbols whose
|
|
|
|
* value represents the member offsets for various ARM kernel structures.
|
|
|
|
*
|
|
|
|
* All of the absolute symbols defined by this module will be present in the
|
|
|
|
* final kernel ELF image (due to the linker's reference to the _OffsetAbsSyms
|
|
|
|
* symbol).
|
|
|
|
*
|
|
|
|
* INTERNAL
|
|
|
|
* It is NOT necessary to define the offset for every member of a structure.
|
|
|
|
* Typically, only those members that are accessed by assembly language routines
|
|
|
|
* are defined; however, it doesn't hurt to define all fields for the sake of
|
|
|
|
* completeness.
|
|
|
|
*/
|
|
|
|
|
2020-07-22 05:00:14 +08:00
|
|
|
#ifndef _ARM_OFFSETS_INC_
|
|
|
|
#define _ARM_OFFSETS_INC_
|
|
|
|
|
2021-03-25 18:56:15 +08:00
|
|
|
#include <gen_offset.h>
|
2019-11-11 00:17:19 +08:00
|
|
|
#include <kernel.h>
|
|
|
|
#include <kernel_arch_data.h>
|
|
|
|
#include <kernel_offsets.h>
|
|
|
|
|
2021-04-13 12:42:00 +08:00
|
|
|
GEN_OFFSET_SYM(_thread_arch_t, exception_depth);
|
|
|
|
|
2020-11-11 21:29:44 +08:00
|
|
|
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);
|
arm64: Rework stack usage
The ARM64 port is currently using SP_EL0 for everything: kernel threads,
user threads and exceptions. In addition when taking an exception the
exception code is still using the thread SP without relying on any
interrupt stack.
If from one hand this makes the context switch really quick because the
thread context is already on the thread stack so we have only to save
one register (SP) for the whole context, on the other hand the major
limitation introduced by this choice is that if for some reason the
thread SP is corrupted or pointing to some unaccessible location (for
example in case of stack overflow), the exception code is unable to
recover or even deal with it.
The usual way of dealing with this kind of problems is to use a
dedicated interrupt stack on SP_EL1 when servicing the exceptions. The
real drawback of this is that, in case of context switch, all the
context must be copied from the shared interrupt stack into a
thread-specific stack or structure, so it is really slow.
We use here an hybrid approach, sacrificing a bit of stack space for a
quicker context switch. While nothing really changes for kernel threads,
for user threads we now use the privileged stack (already present to
service syscalls) as interrupt stack.
When an exception arrives the code now switches to use SP_EL1 that for
user threads is always pointing inside the privileged portion of the
stack of the current running thread. This achieves two things: (1)
isolate exceptions and syscall code to use a stack that is isolated,
privileged and not accessible to user threads and (2) the thread SP is
not touched at all during exceptions, so it can be invalid or corrupted
without any direct consequence.
Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2021-04-22 02:14:14 +08:00
|
|
|
GEN_NAMED_OFFSET_SYM(_callee_saved_t, x29, x29_sp_el0);
|
2022-03-15 01:51:40 +08:00
|
|
|
GEN_NAMED_OFFSET_SYM(_callee_saved_t, sp_elx, sp_elx_lr);
|
2020-11-11 21:29:44 +08:00
|
|
|
|
|
|
|
GEN_ABSOLUTE_SYM(___callee_saved_t_SIZEOF, sizeof(struct _callee_saved));
|
|
|
|
|
2020-11-11 23:19:40 +08:00
|
|
|
GEN_NAMED_OFFSET_SYM(_esf_t, spsr, spsr_elr);
|
2022-03-17 01:12:39 +08:00
|
|
|
GEN_NAMED_OFFSET_SYM(_esf_t, x18, x18_lr);
|
2020-11-11 23:19:40 +08:00
|
|
|
GEN_NAMED_OFFSET_SYM(_esf_t, x16, x16_x17);
|
|
|
|
GEN_NAMED_OFFSET_SYM(_esf_t, x14, x14_x15);
|
|
|
|
GEN_NAMED_OFFSET_SYM(_esf_t, x12, x12_x13);
|
|
|
|
GEN_NAMED_OFFSET_SYM(_esf_t, x10, x10_x11);
|
|
|
|
GEN_NAMED_OFFSET_SYM(_esf_t, x8, x8_x9);
|
|
|
|
GEN_NAMED_OFFSET_SYM(_esf_t, x6, x6_x7);
|
|
|
|
GEN_NAMED_OFFSET_SYM(_esf_t, x4, x4_x5);
|
|
|
|
GEN_NAMED_OFFSET_SYM(_esf_t, x2, x2_x3);
|
|
|
|
GEN_NAMED_OFFSET_SYM(_esf_t, x0, x0_x1);
|
|
|
|
|
|
|
|
GEN_ABSOLUTE_SYM(___esf_t_SIZEOF, sizeof(_esf_t));
|
|
|
|
|
2021-02-03 19:07:49 +08:00
|
|
|
#ifdef CONFIG_HAS_ARM_SMCCC
|
|
|
|
|
2021-03-25 18:56:15 +08:00
|
|
|
#include <arch/arm64/arm-smccc.h>
|
2021-02-03 19:07:49 +08:00
|
|
|
|
|
|
|
GEN_NAMED_OFFSET_SYM(arm_smccc_res_t, a0, a0_a1);
|
|
|
|
GEN_NAMED_OFFSET_SYM(arm_smccc_res_t, a2, a2_a3);
|
2021-02-03 19:10:45 +08:00
|
|
|
GEN_NAMED_OFFSET_SYM(arm_smccc_res_t, a4, a4_a5);
|
|
|
|
GEN_NAMED_OFFSET_SYM(arm_smccc_res_t, a6, a6_a7);
|
2021-02-03 19:07:49 +08:00
|
|
|
|
|
|
|
#endif /* CONFIG_HAS_ARM_SMCCC */
|
|
|
|
|
2021-03-25 18:56:15 +08:00
|
|
|
GEN_ABS_SYM_END
|
|
|
|
|
2020-07-22 05:00:14 +08:00
|
|
|
#endif /* _ARM_OFFSETS_INC_ */
|