x86: Early TLS initialization
Allow early boot code using thread local storage when it is enabled. Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
parent
654863944d
commit
596e77f562
2 changed files with 35 additions and 0 deletions
|
@ -44,6 +44,10 @@
|
|||
GDATA(_sse_mxcsr_default_value)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_THREAD_LOCAL_STORAGE)
|
||||
GTEXT(z_x86_early_tls_update_gdt)
|
||||
#endif
|
||||
|
||||
GDATA(x86_cpu_boot_arg)
|
||||
|
||||
.macro install_page_tables
|
||||
|
@ -252,6 +256,11 @@ __csSet:
|
|||
#endif
|
||||
#endif /* Z_VM_KERNEL */
|
||||
|
||||
#ifdef CONFIG_THREAD_LOCAL_STORAGE
|
||||
pushl %esp
|
||||
call z_x86_early_tls_update_gdt
|
||||
popl %esp
|
||||
#endif
|
||||
/* Clear BSS */
|
||||
#ifdef CONFIG_LINKER_USE_BOOT_SECTION
|
||||
call z_bss_zero_boot
|
||||
|
|
|
@ -28,3 +28,29 @@ void z_x86_tls_update_gdt(struct k_thread *thread)
|
|||
sd->base_mid = (thread->tls >> 16) & 0xFFU;
|
||||
sd->base_hi = (thread->tls >> 24) & 0xFFU;
|
||||
}
|
||||
|
||||
FUNC_NO_STACK_PROTECTOR
|
||||
void z_x86_early_tls_update_gdt(char *stack_ptr)
|
||||
{
|
||||
uintptr_t *self_ptr;
|
||||
uintptr_t tls_seg = GS_TLS_SEG;
|
||||
struct segment_descriptor *sd = &_gdt.entries[ENTRY_NUM];
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
sd->base_low = POINTER_TO_UINT(self_ptr) & 0xFFFFU;
|
||||
sd->base_mid = (POINTER_TO_UINT(self_ptr) >> 16) & 0xFFU;
|
||||
sd->base_hi = (POINTER_TO_UINT(self_ptr) >> 24) & 0xFFU;
|
||||
|
||||
__asm__ volatile(
|
||||
"movl %0, %%eax;\n\t"
|
||||
"movl %%eax, %%gs;\n\t"
|
||||
:
|
||||
: "r"(tls_seg));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue