x86-64: Early TLS initialization
Allow early boot code to use thread local storage when it is enabled. Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
parent
596e77f562
commit
20c9bb856f
3 changed files with 37 additions and 1 deletions
|
@ -17,5 +17,5 @@ zephyr_library_sources(
|
||||||
)
|
)
|
||||||
|
|
||||||
zephyr_library_sources_ifdef(CONFIG_USERSPACE intel64/userspace.S)
|
zephyr_library_sources_ifdef(CONFIG_USERSPACE intel64/userspace.S)
|
||||||
|
zephyr_library_sources_ifdef(CONFIG_THREAD_LOCAL_STORAGE intel64/tls.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_DEBUG_COREDUMP intel64/coredump.c)
|
zephyr_library_sources_ifdef(CONFIG_DEBUG_COREDUMP intel64/coredump.c)
|
||||||
|
|
|
@ -261,6 +261,11 @@ enter_code64:
|
||||||
|
|
||||||
/* Enter C domain now that we have a stack set up, never to return */
|
/* Enter C domain now that we have a stack set up, never to return */
|
||||||
movq %rbp, %rdi
|
movq %rbp, %rdi
|
||||||
|
#ifdef CONFIG_STACK_CANARIES_TLS
|
||||||
|
pushq %rsp
|
||||||
|
call z_x86_early_tls_update_gdt
|
||||||
|
popq %rsp
|
||||||
|
#endif
|
||||||
call z_x86_cpu_init
|
call z_x86_cpu_init
|
||||||
|
|
||||||
/* 64 bit OS entry point, used by EFI support. UEFI
|
/* 64 bit OS entry point, used by EFI support. UEFI
|
||||||
|
|
31
arch/x86/core/intel64/tls.c
Normal file
31
arch/x86/core/intel64/tls.c
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Intel Corporation.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <kernel_internal.h>
|
||||||
|
|
||||||
|
FUNC_NO_STACK_PROTECTOR
|
||||||
|
void z_x86_early_tls_update_gdt(char *stack_ptr)
|
||||||
|
{
|
||||||
|
uintptr_t *self_ptr;
|
||||||
|
uint32_t fs_base = X86_FS_BASE;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Since we are populating things backwards, store
|
||||||
|
* the pointer to the TLS area at top of stack.
|
||||||
|
*/
|
||||||
|
stack_ptr -= sizeof(uintptr_t);
|
||||||
|
self_ptr = (void *)stack_ptr;
|
||||||
|
*self_ptr = POINTER_TO_UINT(stack_ptr);
|
||||||
|
|
||||||
|
__asm__ volatile(
|
||||||
|
"movl %0, %%ecx;\n\t"
|
||||||
|
"movq %1, %%rax;\n\t"
|
||||||
|
"movq %1, %%rdx;\n\t"
|
||||||
|
"shrq $32, %%rdx;\n\t"
|
||||||
|
"wrmsr;\n\t"
|
||||||
|
:
|
||||||
|
: "r"(fs_base), "r"(POINTER_TO_UINT(self_ptr)));
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue