1 /* 2 * Copyright (c) 2023 Intel Corporation. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <kernel_internal.h> 8 9 FUNC_NO_STACK_PROTECTOR z_x86_early_tls_update_gdt(char * stack_ptr)10void z_x86_early_tls_update_gdt(char *stack_ptr) 11 { 12 uintptr_t *self_ptr; 13 uint32_t fs_base = X86_FS_BASE; 14 15 /* 16 * Since we are populating things backwards, store 17 * the pointer to the TLS area at top of stack. 18 */ 19 stack_ptr -= sizeof(uintptr_t); 20 self_ptr = (void *)stack_ptr; 21 *self_ptr = POINTER_TO_UINT(stack_ptr); 22 23 __asm__ volatile( 24 "movl %0, %%ecx;\n\t" 25 "movq %1, %%rax;\n\t" 26 "movq %1, %%rdx;\n\t" 27 "shrq $32, %%rdx;\n\t" 28 "wrmsr;\n\t" 29 : 30 : "r"(fs_base), "r"(POINTER_TO_UINT(self_ptr))); 31 } 32