1 /* SPDX-License-Identifier: GPL-2.0 */
4 * Copyright C 2016, Oracle and/or its affiliates. All rights reserved.
9 #define _pa(x) ((x) - __START_KERNEL_map)
11 #include <linux/elfnote.h>
12 #include <linux/init.h>
13 #include <linux/linkage.h>
14 #include <asm/desc_defs.h>
15 #include <asm/segment.h>
18 #include <asm/processor-flags.h>
20 #include <asm/nospec-branch.h>
21 #include <xen/interface/elfnote.h>
26 * Entry point for PVH guests.
28 * Xen ABI specifies the following register state when we come here:
30 * - `ebx`: contains the physical memory address where the loader has placed
31 * the boot start info structure.
32 * - `cr0`: bit 0 (PE) must be set. All the other writeable bits are cleared.
33 * - `cr4`: all bits are cleared.
34 * - `cs `: must be a 32-bit read/execute code segment with a base of `0`
35 * and a limit of `0xFFFFFFFF`. The selector value is unspecified.
36 * - `ds`, `es`: must be a 32-bit read/write data segment with a base of
37 * `0` and a limit of `0xFFFFFFFF`. The selector values are all
39 * - `tr`: must be a 32-bit TSS (active) with a base of '0' and a limit
41 * - `eflags`: bit 17 (VM) must be cleared. Bit 9 (IF) must be cleared.
42 * Bit 8 (TF) must be cleared. Other bits are all unspecified.
44 * All other processor registers and flag bits are unspecified. The OS is in
45 * charge of setting up its own stack, GDT and IDT.
48 #define PVH_GDT_ENTRY_CS 1
49 #define PVH_GDT_ENTRY_DS 2
50 #define PVH_CS_SEL (PVH_GDT_ENTRY_CS * 8)
51 #define PVH_DS_SEL (PVH_GDT_ENTRY_DS * 8)
53 SYM_CODE_START_LOCAL(pvh_start_xen)
54 UNWIND_HINT_END_OF_STACK
64 /* Stash hvm_start_info. */
65 mov $_pa(pvh_start_info), %edi
67 mov _pa(pvh_start_info_sz), %ecx
72 mov $_pa(early_stack_end), %esp
74 /* Enable PAE mode. */
76 orl $X86_CR4_PAE, %eax
80 /* Enable Long mode. */
86 /* Enable pre-constructed page tables. */
87 mov $_pa(init_top_pgt), %eax
89 mov $(X86_CR0_PG | X86_CR0_PE), %eax
92 /* Jump to 64-bit mode. */
93 ljmp $PVH_CS_SEL, $_pa(1f)
95 /* 64-bit entry point. */
98 /* Set base address in stack canary descriptor. */
100 mov $_pa(canary), %eax
106 /* startup_64 expects boot_params in %rsi. */
107 mov $_pa(pvh_bootparams), %rsi
108 mov $_pa(startup_64), %rax
109 ANNOTATE_RETPOLINE_SAFE
112 #else /* CONFIG_X86_64 */
114 call mk_early_pgtbl_32
116 mov $_pa(initial_page_table), %eax
120 or $(X86_CR0_PG | X86_CR0_PE), %eax
123 ljmp $PVH_CS_SEL, $1f
126 mov $_pa(pvh_bootparams), %esi
128 /* startup_32 doesn't expect paging and PAE to be on. */
129 ljmp $PVH_CS_SEL, $_pa(2f)
132 and $~X86_CR0_PG, %eax
135 and $~X86_CR4_PAE, %eax
138 ljmp $PVH_CS_SEL, $_pa(startup_32)
140 SYM_CODE_END(pvh_start_xen)
142 .section ".init.data","aw"
144 SYM_DATA_START_LOCAL(gdt)
145 .word gdt_end - gdt_start
149 SYM_DATA_START_LOCAL(gdt_start)
150 .quad 0x0000000000000000 /* NULL descriptor */
152 .quad GDT_ENTRY(DESC_CODE64, 0, 0xfffff) /* PVH_CS_SEL */
154 .quad GDT_ENTRY(DESC_CODE32, 0, 0xfffff) /* PVH_CS_SEL */
156 .quad GDT_ENTRY(DESC_DATA32, 0, 0xfffff) /* PVH_DS_SEL */
157 SYM_DATA_END_LABEL(gdt_start, SYM_L_LOCAL, gdt_end)
160 SYM_DATA_LOCAL(canary, .fill 48, 1, 0)
162 SYM_DATA_START_LOCAL(early_stack)
163 .fill BOOT_STACK_SIZE, 1, 0
164 SYM_DATA_END_LABEL(early_stack, SYM_L_LOCAL, early_stack_end)
166 ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY,
167 _ASM_PTR (pvh_start_xen - __START_KERNEL_map))