1/*
2 * Copyright (c) 2021 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifdef CONFIG_X86_KPTI
8	MMU_PAGE_ALIGN_PERM
9	z_shared_kernel_page_start = .;
10	/* Special page containing supervisor data that is still mapped in
11	 * user mode page tables. IDT, GDT, TSSes, trampoline stack, and
12	 * any LDT must go here as they always must live in a page that is
13	 * marked 'present'. Still not directly user accessible, but
14	 * no sensitive data should be here as Meltdown exploits may read it.
15	 */
16#endif /* CONFIG_X86_KPTI */
17
18#ifdef CONFIG_DYNAMIC_INTERRUPTS
19	. = ALIGN(8);
20	_idt_base_address = .;
21#ifdef LINKER_ZEPHYR_FINAL
22	KEEP(*(staticIdt))
23#else
24	. += CONFIG_IDT_NUM_VECTORS * 8;
25#endif /* LINKER_ZEPHYR_FINAL */
26#endif /* CONFIG_DYNAMIC_INTERRUPTS */
27
28#ifdef CONFIG_GDT_DYNAMIC
29	KEEP(*(.tss))
30	. = ALIGN(8);
31	_gdt = .;
32#ifdef LINKER_ZEPHYR_FINAL
33	KEEP(*(gdt))
34#else /* LINKER_ZEPHYR_FINAL */
35
36#if defined(CONFIG_THREAD_LOCAL_STORAGE) && !defined(CONFIG_X86_64)
37#define GDT_NUM_TLS_ENTRIES 1
38#else
39#define GDT_NUM_TLS_ENTRIES 0
40#endif
41
42#ifdef CONFIG_USERSPACE
43    #define GDT_NUM_ENTRIES 7
44#elif defined(CONFIG_X86_STACK_PROTECTION)
45    #define GDT_NUM_ENTRIES 5
46#else
47    #define GDT_NUM_ENTRIES 3
48#endif /* CONFIG_X86_USERSPACE */
49	. += (GDT_NUM_ENTRIES + GDT_NUM_TLS_ENTRIES) * 8;
50#endif /* LINKER_ZEPHYR_FINAL */
51	. += CONFIG_GDT_RESERVED_NUM_ENTRIES * 8;
52#endif /* CONFIG_GDT_DYNAMIC */
53
54#ifdef CONFIG_X86_KPTI
55	z_trampoline_stack_start = .;
56	MMU_PAGE_ALIGN_PERM
57	z_trampoline_stack_end = .;
58	z_shared_kernel_page_end = .;
59
60	ASSERT(z_trampoline_stack_end - z_trampoline_stack_start >= 40,
61		"trampoline stack too small");
62	ASSERT(z_shared_kernel_page_end - z_shared_kernel_page_start == 4096,
63	       "shared kernel area is not one memory page");
64#endif /* CONFIG_X86_KPTI */
65