2 * Copyright C 2016, Oracle and/or its affiliates. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 #define _pa(x) ((x) - __START_KERNEL_map)
22 #include <linux/elfnote.h>
23 #include <linux/init.h>
24 #include <linux/linkage.h>
25 #include <asm/segment.h>
28 #include <asm/processor-flags.h>
30 #include <xen/interface/elfnote.h>
35 * Entry point for PVH guests.
37 * Xen ABI specifies the following register state when we come here:
39 * - `ebx`: contains the physical memory address where the loader has placed
40 * the boot start info structure.
41 * - `cr0`: bit 0 (PE) must be set. All the other writeable bits are cleared.
42 * - `cr4`: all bits are cleared.
43 * - `cs `: must be a 32-bit read/execute code segment with a base of ‘0’
44 * and a limit of ‘0xFFFFFFFF’. The selector value is unspecified.
45 * - `ds`, `es`: must be a 32-bit read/write data segment with a base of
46 * ‘0’ and a limit of ‘0xFFFFFFFF’. The selector values are all
48 * - `tr`: must be a 32-bit TSS (active) with a base of '0' and a limit
50 * - `eflags`: bit 17 (VM) must be cleared. Bit 9 (IF) must be cleared.
51 * Bit 8 (TF) must be cleared. Other bits are all unspecified.
53 * All other processor registers and flag bits are unspecified. The OS is in
54 * charge of setting up it's own stack, GDT and IDT.
57 #define PVH_GDT_ENTRY_CS 1
58 #define PVH_GDT_ENTRY_DS 2
59 #define PVH_GDT_ENTRY_CANARY 3
60 #define PVH_CS_SEL (PVH_GDT_ENTRY_CS * 8)
61 #define PVH_DS_SEL (PVH_GDT_ENTRY_DS * 8)
62 #define PVH_CANARY_SEL (PVH_GDT_ENTRY_CANARY * 8)
74 /* Stash hvm_start_info. */
75 mov $_pa(pvh_start_info), %edi
77 mov _pa(pvh_start_info_sz), %ecx
82 mov $_pa(early_stack_end), %esp
84 /* Enable PAE mode. */
86 orl $X86_CR4_PAE, %eax
90 /* Enable Long mode. */
96 /* Enable pre-constructed page tables. */
97 mov $_pa(init_top_pgt), %eax
99 mov $(X86_CR0_PG | X86_CR0_PE), %eax
102 /* Jump to 64-bit mode. */
103 ljmp $PVH_CS_SEL, $_pa(1f)
105 /* 64-bit entry point. */
108 /* Set base address in stack canary descriptor. */
109 mov $MSR_GS_BASE,%ecx
110 mov $_pa(canary), %eax
116 /* startup_64 expects boot_params in %rsi. */
117 mov $_pa(pvh_bootparams), %rsi
118 mov $_pa(startup_64), %rax
121 #else /* CONFIG_X86_64 */
123 /* Set base address in stack canary descriptor. */
124 movl $_pa(gdt_start),%eax
125 movl $_pa(canary),%ecx
126 movw %cx, (PVH_GDT_ENTRY_CANARY * 8) + 2(%eax)
128 movb %cl, (PVH_GDT_ENTRY_CANARY * 8) + 4(%eax)
129 movb %ch, (PVH_GDT_ENTRY_CANARY * 8) + 7(%eax)
131 mov $PVH_CANARY_SEL,%eax
134 call mk_early_pgtbl_32
136 mov $_pa(initial_page_table), %eax
140 or $(X86_CR0_PG | X86_CR0_PE), %eax
143 ljmp $PVH_CS_SEL, $1f
146 mov $_pa(pvh_bootparams), %esi
148 /* startup_32 doesn't expect paging and PAE to be on. */
149 ljmp $PVH_CS_SEL, $_pa(2f)
152 and $~X86_CR0_PG, %eax
155 and $~X86_CR4_PAE, %eax
158 ljmp $PVH_CS_SEL, $_pa(startup_32)
162 .section ".init.data","aw"
165 .word gdt_end - gdt_start
169 .quad 0x0000000000000000 /* NULL descriptor */
171 .quad GDT_ENTRY(0xa09a, 0, 0xfffff) /* PVH_CS_SEL */
173 .quad GDT_ENTRY(0xc09a, 0, 0xfffff) /* PVH_CS_SEL */
175 .quad GDT_ENTRY(0xc092, 0, 0xfffff) /* PVH_DS_SEL */
176 .quad GDT_ENTRY(0x4090, 0, 0x18) /* PVH_CANARY_SEL */
184 .fill BOOT_STACK_SIZE, 1, 0
187 ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY,
188 _ASM_PTR (pvh_start_xen - __START_KERNEL_map))