Boris Ostrovsky | 7243b93 | 2017-02-05 19:50:52 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright C 2016, Oracle and/or its affiliates. All rights reserved. |
| 3 | * |
| 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. |
| 8 | * |
| 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. |
| 13 | * |
| 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/>. |
| 16 | */ |
| 17 | |
| 18 | .code32 |
| 19 | .text |
| 20 | #define _pa(x) ((x) - __START_KERNEL_map) |
| 21 | |
| 22 | #include <linux/elfnote.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/linkage.h> |
| 25 | #include <asm/segment.h> |
| 26 | #include <asm/asm.h> |
| 27 | #include <asm/boot.h> |
| 28 | #include <asm/processor-flags.h> |
| 29 | #include <asm/msr.h> |
| 30 | #include <xen/interface/elfnote.h> |
| 31 | |
| 32 | __HEAD |
| 33 | |
| 34 | /* |
| 35 | * Entry point for PVH guests. |
| 36 | * |
| 37 | * Xen ABI specifies the following register state when we come here: |
| 38 | * |
| 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 |
| 47 | * unspecified. |
| 48 | * - `tr`: must be a 32-bit TSS (active) with a base of '0' and a limit |
| 49 | * of '0x67'. |
| 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. |
| 52 | * |
| 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. |
| 55 | */ |
| 56 | |
| 57 | ENTRY(pvh_start_xen) |
| 58 | cld |
| 59 | |
| 60 | lgdt (_pa(gdt)) |
| 61 | |
| 62 | mov $(__BOOT_DS),%eax |
| 63 | mov %eax,%ds |
| 64 | mov %eax,%es |
| 65 | mov %eax,%ss |
| 66 | |
| 67 | /* Stash hvm_start_info. */ |
| 68 | mov $_pa(pvh_start_info), %edi |
| 69 | mov %ebx, %esi |
| 70 | mov _pa(pvh_start_info_sz), %ecx |
| 71 | shr $2,%ecx |
| 72 | rep |
| 73 | movsl |
| 74 | |
| 75 | mov $_pa(early_stack_end), %esp |
| 76 | |
| 77 | /* Enable PAE mode. */ |
| 78 | mov %cr4, %eax |
| 79 | orl $X86_CR4_PAE, %eax |
| 80 | mov %eax, %cr4 |
| 81 | |
| 82 | #ifdef CONFIG_X86_64 |
| 83 | /* Enable Long mode. */ |
| 84 | mov $MSR_EFER, %ecx |
| 85 | rdmsr |
| 86 | btsl $_EFER_LME, %eax |
| 87 | wrmsr |
| 88 | |
| 89 | /* Enable pre-constructed page tables. */ |
Kirill A. Shutemov | 65ade2f | 2017-06-06 14:31:27 +0300 | [diff] [blame] | 90 | mov $_pa(init_top_pgt), %eax |
Boris Ostrovsky | 7243b93 | 2017-02-05 19:50:52 -0500 | [diff] [blame] | 91 | mov %eax, %cr3 |
| 92 | mov $(X86_CR0_PG | X86_CR0_PE), %eax |
| 93 | mov %eax, %cr0 |
| 94 | |
| 95 | /* Jump to 64-bit mode. */ |
| 96 | ljmp $__KERNEL_CS, $_pa(1f) |
| 97 | |
| 98 | /* 64-bit entry point. */ |
| 99 | .code64 |
| 100 | 1: |
| 101 | call xen_prepare_pvh |
| 102 | |
| 103 | /* startup_64 expects boot_params in %rsi. */ |
| 104 | mov $_pa(pvh_bootparams), %rsi |
| 105 | mov $_pa(startup_64), %rax |
| 106 | jmp *%rax |
| 107 | |
| 108 | #else /* CONFIG_X86_64 */ |
| 109 | |
| 110 | call mk_early_pgtbl_32 |
| 111 | |
| 112 | mov $_pa(initial_page_table), %eax |
| 113 | mov %eax, %cr3 |
| 114 | |
| 115 | mov %cr0, %eax |
| 116 | or $(X86_CR0_PG | X86_CR0_PE), %eax |
| 117 | mov %eax, %cr0 |
| 118 | |
| 119 | ljmp $__BOOT_CS, $1f |
| 120 | 1: |
| 121 | call xen_prepare_pvh |
| 122 | mov $_pa(pvh_bootparams), %esi |
| 123 | |
| 124 | /* startup_32 doesn't expect paging and PAE to be on. */ |
| 125 | ljmp $__BOOT_CS, $_pa(2f) |
| 126 | 2: |
| 127 | mov %cr0, %eax |
| 128 | and $~X86_CR0_PG, %eax |
| 129 | mov %eax, %cr0 |
| 130 | mov %cr4, %eax |
| 131 | and $~X86_CR4_PAE, %eax |
| 132 | mov %eax, %cr4 |
| 133 | |
| 134 | ljmp $__BOOT_CS, $_pa(startup_32) |
| 135 | #endif |
| 136 | END(pvh_start_xen) |
| 137 | |
| 138 | .section ".init.data","aw" |
| 139 | .balign 8 |
| 140 | gdt: |
| 141 | .word gdt_end - gdt_start |
| 142 | .long _pa(gdt_start) |
| 143 | .word 0 |
| 144 | gdt_start: |
| 145 | .quad 0x0000000000000000 /* NULL descriptor */ |
| 146 | .quad 0x0000000000000000 /* reserved */ |
| 147 | #ifdef CONFIG_X86_64 |
| 148 | .quad GDT_ENTRY(0xa09a, 0, 0xfffff) /* __KERNEL_CS */ |
| 149 | #else |
| 150 | .quad GDT_ENTRY(0xc09a, 0, 0xfffff) /* __KERNEL_CS */ |
| 151 | #endif |
| 152 | .quad GDT_ENTRY(0xc092, 0, 0xfffff) /* __KERNEL_DS */ |
| 153 | gdt_end: |
| 154 | |
| 155 | .balign 4 |
| 156 | early_stack: |
| 157 | .fill 256, 1, 0 |
| 158 | early_stack_end: |
| 159 | |
| 160 | ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY, |
| 161 | _ASM_PTR (pvh_start_xen - __START_KERNEL_map)) |