xen-pvh.S 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. ENTRY(pvh_start_xen)
  53. cld
  54. lgdt (_pa(gdt))
  55. mov $(__BOOT_DS),%eax
  56. mov %eax,%ds
  57. mov %eax,%es
  58. mov %eax,%ss
  59. /* Stash hvm_start_info. */
  60. mov $_pa(pvh_start_info), %edi
  61. mov %ebx, %esi
  62. mov _pa(pvh_start_info_sz), %ecx
  63. shr $2,%ecx
  64. rep
  65. movsl
  66. mov $_pa(early_stack_end), %esp
  67. /* Enable PAE mode. */
  68. mov %cr4, %eax
  69. orl $X86_CR4_PAE, %eax
  70. mov %eax, %cr4
  71. #ifdef CONFIG_X86_64
  72. /* Enable Long mode. */
  73. mov $MSR_EFER, %ecx
  74. rdmsr
  75. btsl $_EFER_LME, %eax
  76. wrmsr
  77. /* Enable pre-constructed page tables. */
  78. mov $_pa(init_level4_pgt), %eax
  79. mov %eax, %cr3
  80. mov $(X86_CR0_PG | X86_CR0_PE), %eax
  81. mov %eax, %cr0
  82. /* Jump to 64-bit mode. */
  83. ljmp $__KERNEL_CS, $_pa(1f)
  84. /* 64-bit entry point. */
  85. .code64
  86. 1:
  87. call xen_prepare_pvh
  88. /* startup_64 expects boot_params in %rsi. */
  89. mov $_pa(pvh_bootparams), %rsi
  90. mov $_pa(startup_64), %rax
  91. jmp *%rax
  92. #else /* CONFIG_X86_64 */
  93. call mk_early_pgtbl_32
  94. mov $_pa(initial_page_table), %eax
  95. mov %eax, %cr3
  96. mov %cr0, %eax
  97. or $(X86_CR0_PG | X86_CR0_PE), %eax
  98. mov %eax, %cr0
  99. ljmp $__BOOT_CS, $1f
  100. 1:
  101. call xen_prepare_pvh
  102. mov $_pa(pvh_bootparams), %esi
  103. /* startup_32 doesn't expect paging and PAE to be on. */
  104. ljmp $__BOOT_CS, $_pa(2f)
  105. 2:
  106. mov %cr0, %eax
  107. and $~X86_CR0_PG, %eax
  108. mov %eax, %cr0
  109. mov %cr4, %eax
  110. and $~X86_CR4_PAE, %eax
  111. mov %eax, %cr4
  112. ljmp $__BOOT_CS, $_pa(startup_32)
  113. #endif
  114. END(pvh_start_xen)
  115. .section ".init.data","aw"
  116. .balign 8
  117. gdt:
  118. .word gdt_end - gdt_start
  119. .long _pa(gdt_start)
  120. .word 0
  121. gdt_start:
  122. .quad 0x0000000000000000 /* NULL descriptor */
  123. .quad 0x0000000000000000 /* reserved */
  124. #ifdef CONFIG_X86_64
  125. .quad GDT_ENTRY(0xa09a, 0, 0xfffff) /* __KERNEL_CS */
  126. #else
  127. .quad GDT_ENTRY(0xc09a, 0, 0xfffff) /* __KERNEL_CS */
  128. #endif
  129. .quad GDT_ENTRY(0xc092, 0, 0xfffff) /* __KERNEL_DS */
  130. gdt_end:
  131. .balign 4
  132. early_stack:
  133. .fill 256, 1, 0
  134. early_stack_end:
  135. ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY,
  136. _ASM_PTR (pvh_start_xen - __START_KERNEL_map))