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/segment.h>
17 #include <asm/processor-flags.h>
19 #include <xen/interface/elfnote.h>
24 * Entry point for PVH guests.
26 * Xen ABI specifies the following register state when we come here:
28 * - `ebx`: contains the physical memory address where the loader has placed
29 * the boot start info structure.
30 * - `cr0`: bit 0 (PE) must be set. All the other writeable bits are cleared.
31 * - `cr4`: all bits are cleared.
32 * - `cs `: must be a 32-bit read/execute code segment with a base of ‘0’
33 * and a limit of ‘0xFFFFFFFF’. The selector value is unspecified.
34 * - `ds`, `es`: must be a 32-bit read/write data segment with a base of
35 * ‘0’ and a limit of ‘0xFFFFFFFF’. The selector values are all
37 * - `tr`: must be a 32-bit TSS (active) with a base of '0' and a limit
39 * - `eflags`: bit 17 (VM) must be cleared. Bit 9 (IF) must be cleared.
40 * Bit 8 (TF) must be cleared. Other bits are all unspecified.
42 * All other processor registers and flag bits are unspecified. The OS is in
43 * charge of setting up it's own stack, GDT and IDT.
46 #define PVH_GDT_ENTRY_CS 1
47 #define PVH_GDT_ENTRY_DS 2
48 #define PVH_GDT_ENTRY_CANARY 3
49 #define PVH_CS_SEL (PVH_GDT_ENTRY_CS * 8)
50 #define PVH_DS_SEL (PVH_GDT_ENTRY_DS * 8)
51 #define PVH_CANARY_SEL (PVH_GDT_ENTRY_CANARY * 8)
53 SYM_CODE_START_LOCAL(pvh_start_xen)
63 /* Stash hvm_start_info. */
64 mov $_pa(pvh_start_info), %edi
66 mov _pa(pvh_start_info_sz), %ecx
71 mov $_pa(early_stack_end), %esp
73 /* Enable PAE mode. */
75 orl $X86_CR4_PAE, %eax
79 /* Enable Long mode. */
85 /* Enable pre-constructed page tables. */
86 mov $_pa(init_top_pgt), %eax
88 mov $(X86_CR0_PG | X86_CR0_PE), %eax
91 /* Jump to 64-bit mode. */
92 ljmp $PVH_CS_SEL, $_pa(1f)
94 /* 64-bit entry point. */
97 /* Set base address in stack canary descriptor. */
99 mov $_pa(canary), %eax
105 /* startup_64 expects boot_params in %rsi. */
106 mov $_pa(pvh_bootparams), %rsi
107 mov $_pa(startup_64), %rax
110 #else /* CONFIG_X86_64 */
112 /* Set base address in stack canary descriptor. */
113 movl $_pa(gdt_start),%eax
114 movl $_pa(canary),%ecx
115 movw %cx, (PVH_GDT_ENTRY_CANARY * 8) + 2(%eax)
117 movb %cl, (PVH_GDT_ENTRY_CANARY * 8) + 4(%eax)
118 movb %ch, (PVH_GDT_ENTRY_CANARY * 8) + 7(%eax)
120 mov $PVH_CANARY_SEL,%eax
123 call mk_early_pgtbl_32
125 mov $_pa(initial_page_table), %eax
129 or $(X86_CR0_PG | X86_CR0_PE), %eax
132 ljmp $PVH_CS_SEL, $1f
135 mov $_pa(pvh_bootparams), %esi
137 /* startup_32 doesn't expect paging and PAE to be on. */
138 ljmp $PVH_CS_SEL, $_pa(2f)
141 and $~X86_CR0_PG, %eax
144 and $~X86_CR4_PAE, %eax
147 ljmp $PVH_CS_SEL, $_pa(startup_32)
149 SYM_CODE_END(pvh_start_xen)
151 .section ".init.data","aw"
153 SYM_DATA_START_LOCAL(gdt)
154 .word gdt_end - gdt_start
158 SYM_DATA_START_LOCAL(gdt_start)
159 .quad 0x0000000000000000 /* NULL descriptor */
161 .quad GDT_ENTRY(0xa09a, 0, 0xfffff) /* PVH_CS_SEL */
163 .quad GDT_ENTRY(0xc09a, 0, 0xfffff) /* PVH_CS_SEL */
165 .quad GDT_ENTRY(0xc092, 0, 0xfffff) /* PVH_DS_SEL */
166 .quad GDT_ENTRY(0x4090, 0, 0x18) /* PVH_CANARY_SEL */
167 SYM_DATA_END_LABEL(gdt_start, SYM_L_LOCAL, gdt_end)
170 SYM_DATA_LOCAL(canary, .fill 48, 1, 0)
172 SYM_DATA_START_LOCAL(early_stack)
173 .fill BOOT_STACK_SIZE, 1, 0
174 SYM_DATA_END_LABEL(early_stack, SYM_L_LOCAL, early_stack_end)
176 ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY,
177 _ASM_PTR (pvh_start_xen - __START_KERNEL_map))