xen-pvh.S 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. .code32
  18. .text
  19. #define _pa(x) ((x) - __START_KERNEL_map)
  20. #include <linux/elfnote.h>
  21. #include <linux/init.h>
  22. #include <linux/linkage.h>
  23. #include <asm/segment.h>
  24. #include <asm/asm.h>
  25. #include <asm/boot.h>
  26. #include <asm/processor-flags.h>
  27. #include <asm/msr.h>
  28. #include <xen/interface/elfnote.h>
  29. __HEAD
  30. /*
  31. * Entry point for PVH guests.
  32. *
  33. * Xen ABI specifies the following register state when we come here:
  34. *
  35. * - `ebx`: contains the physical memory address where the loader has placed
  36. * the boot start info structure.
  37. * - `cr0`: bit 0 (PE) must be set. All the other writeable bits are cleared.
  38. * - `cr4`: all bits are cleared.
  39. * - `cs `: must be a 32-bit read/execute code segment with a base of ‘0’
  40. * and a limit of ‘0xFFFFFFFF’. The selector value is unspecified.
  41. * - `ds`, `es`: must be a 32-bit read/write data segment with a base of
  42. * ‘0’ and a limit of ‘0xFFFFFFFF’. The selector values are all
  43. * unspecified.
  44. * - `tr`: must be a 32-bit TSS (active) with a base of '0' and a limit
  45. * of '0x67'.
  46. * - `eflags`: bit 17 (VM) must be cleared. Bit 9 (IF) must be cleared.
  47. * Bit 8 (TF) must be cleared. Other bits are all unspecified.
  48. *
  49. * All other processor registers and flag bits are unspecified. The OS is in
  50. * charge of setting up it's own stack, GDT and IDT.
  51. */
  52. #define PVH_GDT_ENTRY_CS 1
  53. #define PVH_GDT_ENTRY_DS 2
  54. #define PVH_GDT_ENTRY_CANARY 3
  55. #define PVH_CS_SEL (PVH_GDT_ENTRY_CS * 8)
  56. #define PVH_DS_SEL (PVH_GDT_ENTRY_DS * 8)
  57. #define PVH_CANARY_SEL (PVH_GDT_ENTRY_CANARY * 8)
  58. ENTRY(pvh_start_xen)
  59. cld
  60. lgdt (_pa(gdt))
  61. mov $PVH_DS_SEL,%eax
  62. mov %eax,%ds
  63. mov %eax,%es
  64. mov %eax,%ss
  65. /* Stash hvm_start_info. */
  66. mov $_pa(pvh_start_info), %edi
  67. mov %ebx, %esi
  68. mov _pa(pvh_start_info_sz), %ecx
  69. shr $2,%ecx
  70. rep
  71. movsl
  72. mov $_pa(early_stack_end), %esp
  73. /* Enable PAE mode. */
  74. mov %cr4, %eax
  75. orl $X86_CR4_PAE, %eax
  76. mov %eax, %cr4
  77. #ifdef CONFIG_X86_64
  78. /* Enable Long mode. */
  79. mov $MSR_EFER, %ecx
  80. rdmsr
  81. btsl $_EFER_LME, %eax
  82. wrmsr
  83. /* Enable pre-constructed page tables. */
  84. mov $_pa(init_top_pgt), %eax
  85. mov %eax, %cr3
  86. mov $(X86_CR0_PG | X86_CR0_PE), %eax
  87. mov %eax, %cr0
  88. /* Jump to 64-bit mode. */
  89. ljmp $PVH_CS_SEL, $_pa(1f)
  90. /* 64-bit entry point. */
  91. .code64
  92. 1:
  93. /* Set base address in stack canary descriptor. */
  94. mov $MSR_GS_BASE,%ecx
  95. mov $_pa(canary), %eax
  96. xor %edx, %edx
  97. wrmsr
  98. call xen_prepare_pvh
  99. /* startup_64 expects boot_params in %rsi. */
  100. mov $_pa(pvh_bootparams), %rsi
  101. mov $_pa(startup_64), %rax
  102. jmp *%rax
  103. #else /* CONFIG_X86_64 */
  104. /* Set base address in stack canary descriptor. */
  105. movl $_pa(gdt_start),%eax
  106. movl $_pa(canary),%ecx
  107. movw %cx, (PVH_GDT_ENTRY_CANARY * 8) + 2(%eax)
  108. shrl $16, %ecx
  109. movb %cl, (PVH_GDT_ENTRY_CANARY * 8) + 4(%eax)
  110. movb %ch, (PVH_GDT_ENTRY_CANARY * 8) + 7(%eax)
  111. mov $PVH_CANARY_SEL,%eax
  112. mov %eax,%gs
  113. call mk_early_pgtbl_32
  114. mov $_pa(initial_page_table), %eax
  115. mov %eax, %cr3
  116. mov %cr0, %eax
  117. or $(X86_CR0_PG | X86_CR0_PE), %eax
  118. mov %eax, %cr0
  119. ljmp $PVH_CS_SEL, $1f
  120. 1:
  121. call xen_prepare_pvh
  122. mov $_pa(pvh_bootparams), %esi
  123. /* startup_32 doesn't expect paging and PAE to be on. */
  124. ljmp $PVH_CS_SEL, $_pa(2f)
  125. 2:
  126. mov %cr0, %eax
  127. and $~X86_CR0_PG, %eax
  128. mov %eax, %cr0
  129. mov %cr4, %eax
  130. and $~X86_CR4_PAE, %eax
  131. mov %eax, %cr4
  132. ljmp $PVH_CS_SEL, $_pa(startup_32)
  133. #endif
  134. END(pvh_start_xen)
  135. .section ".init.data","aw"
  136. .balign 8
  137. gdt:
  138. .word gdt_end - gdt_start
  139. .long _pa(gdt_start)
  140. .word 0
  141. gdt_start:
  142. .quad 0x0000000000000000 /* NULL descriptor */
  143. #ifdef CONFIG_X86_64
  144. .quad GDT_ENTRY(0xa09a, 0, 0xfffff) /* PVH_CS_SEL */
  145. #else
  146. .quad GDT_ENTRY(0xc09a, 0, 0xfffff) /* PVH_CS_SEL */
  147. #endif
  148. .quad GDT_ENTRY(0xc092, 0, 0xfffff) /* PVH_DS_SEL */
  149. .quad GDT_ENTRY(0x4090, 0, 0x18) /* PVH_CANARY_SEL */
  150. gdt_end:
  151. .balign 16
  152. canary:
  153. .fill 48, 1, 0
  154. early_stack:
  155. .fill BOOT_STACK_SIZE, 1, 0
  156. early_stack_end:
  157. ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY,
  158. _ASM_PTR (pvh_start_xen - __START_KERNEL_map))