kernel: z_interrupt_stacks are now kernel stacks

This will save memory on many platforms that enable
user mode.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2020-04-25 15:19:23 -07:00 committed by Anas Nashif
commit 8b4b0d6264
10 changed files with 25 additions and 26 deletions

View file

@ -9,11 +9,11 @@
#include <string.h>
#include <kernel_internal.h>
K_THREAD_STACK_DEFINE(z_arm_fiq_stack, CONFIG_ARMV7_FIQ_STACK_SIZE);
K_THREAD_STACK_DEFINE(z_arm_abort_stack, CONFIG_ARMV7_EXCEPTION_STACK_SIZE);
K_THREAD_STACK_DEFINE(z_arm_undef_stack, CONFIG_ARMV7_EXCEPTION_STACK_SIZE);
K_THREAD_STACK_DEFINE(z_arm_svc_stack, CONFIG_ARMV7_SVC_STACK_SIZE);
K_THREAD_STACK_DEFINE(z_arm_sys_stack, CONFIG_ARMV7_SYS_STACK_SIZE);
K_KERNEL_STACK_DEFINE(z_arm_fiq_stack, CONFIG_ARMV7_FIQ_STACK_SIZE);
K_KERNEL_STACK_DEFINE(z_arm_abort_stack, CONFIG_ARMV7_EXCEPTION_STACK_SIZE);
K_KERNEL_STACK_DEFINE(z_arm_undef_stack, CONFIG_ARMV7_EXCEPTION_STACK_SIZE);
K_KERNEL_STACK_DEFINE(z_arm_svc_stack, CONFIG_ARMV7_SVC_STACK_SIZE);
K_KERNEL_STACK_DEFINE(z_arm_sys_stack, CONFIG_ARMV7_SYS_STACK_SIZE);
#if defined(CONFIG_INIT_STACKS)
void z_arm_init_stacks(void)
@ -22,7 +22,7 @@ void z_arm_init_stacks(void)
memset(z_arm_svc_stack, 0xAA, CONFIG_ARMV7_SVC_STACK_SIZE);
memset(z_arm_abort_stack, 0xAA, CONFIG_ARMV7_EXCEPTION_STACK_SIZE);
memset(z_arm_undef_stack, 0xAA, CONFIG_ARMV7_EXCEPTION_STACK_SIZE);
memset(Z_THREAD_STACK_BUFFER(z_interrupt_stacks[0]), 0xAA,
CONFIG_ISR_STACK_SIZE);
memset(Z_KERNEL_STACK_BUFFER(z_interrupt_stacks[0]), 0xAA,
K_KERNEL_STACK_SIZEOF(z_interrupt_stacks[0]));
}
#endif

View file

@ -26,7 +26,7 @@
extern "C" {
#endif
extern K_THREAD_STACK_ARRAY_DEFINE(z_interrupt_stacks, CONFIG_MP_NUM_CPUS,
extern K_KERNEL_STACK_ARRAY_DEFINE(z_interrupt_stacks, CONFIG_MP_NUM_CPUS,
CONFIG_ISR_STACK_SIZE);
/**
@ -40,8 +40,9 @@ extern K_THREAD_STACK_ARRAY_DEFINE(z_interrupt_stacks, CONFIG_MP_NUM_CPUS,
*/
static ALWAYS_INLINE void z_arm_interrupt_stack_setup(void)
{
uint32_t msp = (uint32_t)(Z_THREAD_STACK_BUFFER(z_interrupt_stacks[0])) +
K_THREAD_STACK_SIZEOF(z_interrupt_stacks[0]);
uint32_t msp =
(uint32_t)(Z_KERNEL_STACK_BUFFER(z_interrupt_stacks[0])) +
K_KERNEL_STACK_SIZEOF(z_interrupt_stacks[0]);
__set_MSP(msp);
#if defined(CONFIG_BUILTIN_STACK_GUARD)

View file

@ -29,8 +29,6 @@
extern "C" {
#endif
extern K_THREAD_STACK_DEFINE(_interrupt_stack, CONFIG_ISR_STACK_SIZE);
#ifdef __cplusplus
}
#endif

View file

@ -64,7 +64,7 @@ bool z_x86_check_stack_bounds(uintptr_t addr, size_t size, uint16_t cs)
#else
cpu_id = 0;
#endif
start = (uintptr_t)Z_THREAD_STACK_BUFFER(
start = (uintptr_t)Z_KERNEL_STACK_BUFFER(
z_interrupt_stacks[cpu_id]);
end = start + CONFIG_ISR_STACK_SIZE;
} else if ((cs & 0x3U) != 0U ||

View file

@ -181,7 +181,7 @@ static FUNC_NORETURN __used void df_handler_top(void)
_df_esf.eflags = _main_tss.eflags;
/* Restore the main IA task to a runnable state */
_main_tss.esp = (uint32_t)(Z_THREAD_STACK_BUFFER(
_main_tss.esp = (uint32_t)(Z_KERNEL_STACK_BUFFER(
z_interrupt_stacks[0]) + CONFIG_ISR_STACK_SIZE);
_main_tss.cs = CODE_SEG;
_main_tss.ds = DATA_SEG;

View file

@ -86,8 +86,8 @@ struct x86_cpuboot x86_cpuboot[] = {
{
.tr = X86_KERNEL_CPU0_TR,
.gs_base = &tss0,
.sp = (uint64_t) (z_interrupt_stacks[0] + CONFIG_ISR_STACK_SIZE +
ARCH_THREAD_STACK_RESERVED),
.sp = (uint64_t) z_interrupt_stacks[0] +
Z_KERNEL_STACK_SIZE_ADJUST(CONFIG_ISR_STACK_SIZE),
.fn = z_x86_prep_c,
#ifdef CONFIG_X86_MMU
.ptables = &z_x86_flat_ptables,
@ -124,7 +124,7 @@ void arch_start_cpu(int cpu_num, k_thread_stack_t *stack, int sz,
uint8_t vector = ((unsigned long) x86_ap_start) >> 12;
uint8_t apic_id = x86_cpu_loapics[cpu_num];
x86_cpuboot[cpu_num].sp = (uint64_t) Z_THREAD_STACK_BUFFER(stack) + sz;
x86_cpuboot[cpu_num].sp = (uint64_t) Z_KERNEL_STACK_BUFFER(stack) + sz;
x86_cpuboot[cpu_num].fn = fn;
x86_cpuboot[cpu_num].arg = arg;
#ifdef CONFIG_X86_MMU

View file

@ -25,7 +25,7 @@ extern void z_xtensa_fatal_error(unsigned int reason, const z_arch_esf_t *esf);
/* Defined in xtensa_context.S */
extern void z_xt_coproc_init(void);
extern K_THREAD_STACK_ARRAY_DEFINE(z_interrupt_stacks, CONFIG_MP_NUM_CPUS,
extern K_KERNEL_STACK_ARRAY_DEFINE(z_interrupt_stacks, CONFIG_MP_NUM_CPUS,
CONFIG_ISR_STACK_SIZE);
static ALWAYS_INLINE void arch_kernel_init(void)
@ -43,8 +43,8 @@ static ALWAYS_INLINE void arch_kernel_init(void)
WSR(CONFIG_XTENSA_KERNEL_CPU_PTR_SR, cpu0);
#ifdef CONFIG_INIT_STACKS
memset(Z_THREAD_STACK_BUFFER(z_interrupt_stacks[0]), 0xAA,
CONFIG_ISR_STACK_SIZE);
memset(Z_KERNEL_STACK_BUFFER(z_interrupt_stacks[0]), 0xAA,
K_KERNEL_STACK_SIZEOF(z_interrupt_stacks[0]));
#endif
}

View file

@ -117,7 +117,7 @@ extern struct k_thread z_main_thread;
#ifdef CONFIG_MULTITHREADING
extern struct k_thread z_idle_threads[CONFIG_MP_NUM_CPUS];
#endif
extern K_THREAD_STACK_ARRAY_DEFINE(z_interrupt_stacks, CONFIG_MP_NUM_CPUS,
extern K_KERNEL_STACK_ARRAY_DEFINE(z_interrupt_stacks, CONFIG_MP_NUM_CPUS,
CONFIG_ISR_STACK_SIZE);
#ifdef CONFIG_GEN_PRIV_STACKS

View file

@ -74,7 +74,7 @@ static K_THREAD_STACK_ARRAY_DEFINE(z_idle_stacks, CONFIG_MP_NUM_CPUS,
* of this area is safe since interrupts are disabled until the kernel context
* switches to the init thread.
*/
K_THREAD_STACK_ARRAY_DEFINE(z_interrupt_stacks, CONFIG_MP_NUM_CPUS,
K_KERNEL_STACK_ARRAY_DEFINE(z_interrupt_stacks, CONFIG_MP_NUM_CPUS,
CONFIG_ISR_STACK_SIZE);
#ifdef CONFIG_SYS_CLOCK_EXISTS
@ -349,8 +349,8 @@ static char *prepare_multithreading(void)
_kernel.cpus[i].idle_thread = &z_idle_threads[i];
_kernel.cpus[i].id = i;
_kernel.cpus[i].irq_stack =
(Z_THREAD_STACK_BUFFER(z_interrupt_stacks[i]) +
K_THREAD_STACK_SIZEOF(z_interrupt_stacks[i]));
(Z_KERNEL_STACK_BUFFER(z_interrupt_stacks[i]) +
K_KERNEL_STACK_SIZEOF(z_interrupt_stacks[i]));
}
initialize_timeouts();

View file

@ -149,8 +149,8 @@ static int cmd_kernel_stacks(const struct shell *shell,
* stack buffers.
*/
for (int i = 0; i < CONFIG_MP_NUM_CPUS; i++) {
buf = Z_THREAD_STACK_BUFFER(z_interrupt_stacks[i]);
size = K_THREAD_STACK_SIZEOF(z_interrupt_stacks[i]);
buf = Z_KERNEL_STACK_BUFFER(z_interrupt_stacks[i]);
size = K_KERNEL_STACK_SIZEOF(z_interrupt_stacks[i]);
for (size_t i = 0; i < size; i++) {
if (buf[i] == 0xAAU) {