head.S 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright C 2016, Oracle and/or its affiliates. All rights reserved.
  4. */
  5. .code32
  6. .text
  7. #define _pa(x) ((x) - __START_KERNEL_map)
  8. #include <linux/elfnote.h>
  9. #include <linux/init.h>
  10. #include <linux/linkage.h>
  11. #include <asm/segment.h>
  12. #include <asm/asm.h>
  13. #include <asm/boot.h>
  14. #include <asm/processor-flags.h>
  15. #include <asm/msr.h>
  16. #include <asm/nospec-branch.h>
  17. #include <xen/interface/elfnote.h>
  18. __HEAD
  19. /*
  20. * Entry point for PVH guests.
  21. *
  22. * Xen ABI specifies the following register state when we come here:
  23. *
  24. * - `ebx`: contains the physical memory address where the loader has placed
  25. * the boot start info structure.
  26. * - `cr0`: bit 0 (PE) must be set. All the other writeable bits are cleared.
  27. * - `cr4`: all bits are cleared.
  28. * - `cs `: must be a 32-bit read/execute code segment with a base of `0`
  29. * and a limit of `0xFFFFFFFF`. The selector value is unspecified.
  30. * - `ds`, `es`: must be a 32-bit read/write data segment with a base of
  31. * `0` and a limit of `0xFFFFFFFF`. The selector values are all
  32. * unspecified.
  33. * - `tr`: must be a 32-bit TSS (active) with a base of '0' and a limit
  34. * of '0x67'.
  35. * - `eflags`: bit 17 (VM) must be cleared. Bit 9 (IF) must be cleared.
  36. * Bit 8 (TF) must be cleared. Other bits are all unspecified.
  37. *
  38. * All other processor registers and flag bits are unspecified. The OS is in
  39. * charge of setting up it's own stack, GDT and IDT.
  40. */
  41. #define PVH_GDT_ENTRY_CS 1
  42. #define PVH_GDT_ENTRY_DS 2
  43. #define PVH_CS_SEL (PVH_GDT_ENTRY_CS * 8)
  44. #define PVH_DS_SEL (PVH_GDT_ENTRY_DS * 8)
  45. SYM_CODE_START_LOCAL(pvh_start_xen)
  46. UNWIND_HINT_EMPTY
  47. cld
  48. lgdt (_pa(gdt))
  49. mov $PVH_DS_SEL,%eax
  50. mov %eax,%ds
  51. mov %eax,%es
  52. mov %eax,%ss
  53. /* Stash hvm_start_info. */
  54. mov $_pa(pvh_start_info), %edi
  55. mov %ebx, %esi
  56. mov _pa(pvh_start_info_sz), %ecx
  57. shr $2,%ecx
  58. rep
  59. movsl
  60. mov $_pa(early_stack_end), %esp
  61. /* Enable PAE mode. */
  62. mov %cr4, %eax
  63. orl $X86_CR4_PAE, %eax
  64. mov %eax, %cr4
  65. #ifdef CONFIG_X86_64
  66. /* Enable Long mode. */
  67. mov $MSR_EFER, %ecx
  68. rdmsr
  69. btsl $_EFER_LME, %eax
  70. wrmsr
  71. /* Enable pre-constructed page tables. */
  72. mov $_pa(init_top_pgt), %eax
  73. mov %eax, %cr3
  74. mov $(X86_CR0_PG | X86_CR0_PE), %eax
  75. mov %eax, %cr0
  76. /* Jump to 64-bit mode. */
  77. ljmp $PVH_CS_SEL, $_pa(1f)
  78. /* 64-bit entry point. */
  79. .code64
  80. 1:
  81. /* Set base address in stack canary descriptor. */
  82. mov $MSR_GS_BASE,%ecx
  83. mov $_pa(canary), %eax
  84. xor %edx, %edx
  85. wrmsr
  86. call xen_prepare_pvh
  87. /* startup_64 expects boot_params in %rsi. */
  88. mov $_pa(pvh_bootparams), %rsi
  89. mov $_pa(startup_64), %rax
  90. ANNOTATE_RETPOLINE_SAFE
  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 $PVH_CS_SEL, $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 $PVH_CS_SEL, $_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 $PVH_CS_SEL, $_pa(startup_32)
  113. #endif
  114. SYM_CODE_END(pvh_start_xen)
  115. .section ".init.data","aw"
  116. .balign 8
  117. SYM_DATA_START_LOCAL(gdt)
  118. .word gdt_end - gdt_start
  119. .long _pa(gdt_start)
  120. .word 0
  121. SYM_DATA_END(gdt)
  122. SYM_DATA_START_LOCAL(gdt_start)
  123. .quad 0x0000000000000000 /* NULL descriptor */
  124. #ifdef CONFIG_X86_64
  125. .quad GDT_ENTRY(0xa09a, 0, 0xfffff) /* PVH_CS_SEL */
  126. #else
  127. .quad GDT_ENTRY(0xc09a, 0, 0xfffff) /* PVH_CS_SEL */
  128. #endif
  129. .quad GDT_ENTRY(0xc092, 0, 0xfffff) /* PVH_DS_SEL */
  130. SYM_DATA_END_LABEL(gdt_start, SYM_L_LOCAL, gdt_end)
  131. .balign 16
  132. SYM_DATA_LOCAL(canary, .fill 48, 1, 0)
  133. SYM_DATA_START_LOCAL(early_stack)
  134. .fill BOOT_STACK_SIZE, 1, 0
  135. SYM_DATA_END_LABEL(early_stack, SYM_L_LOCAL, early_stack_end)
  136. ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY,
  137. _ASM_PTR (pvh_start_xen - __START_KERNEL_map))