kexec.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #ifndef _ASM_X86_KEXEC_H
  2. #define _ASM_X86_KEXEC_H
  3. #ifdef CONFIG_X86_32
  4. # define PA_CONTROL_PAGE 0
  5. # define VA_CONTROL_PAGE 1
  6. # define PA_PGD 2
  7. # define PA_SWAP_PAGE 3
  8. # define PAGES_NR 4
  9. #else
  10. # define PA_CONTROL_PAGE 0
  11. # define VA_CONTROL_PAGE 1
  12. # define PA_PGD 2
  13. # define VA_PGD 3
  14. # define PA_PUD_0 4
  15. # define VA_PUD_0 5
  16. # define PA_PMD_0 6
  17. # define VA_PMD_0 7
  18. # define PA_PTE_0 8
  19. # define VA_PTE_0 9
  20. # define PA_PUD_1 10
  21. # define VA_PUD_1 11
  22. # define PA_PMD_1 12
  23. # define VA_PMD_1 13
  24. # define PA_PTE_1 14
  25. # define VA_PTE_1 15
  26. # define PA_TABLE_PAGE 16
  27. # define PAGES_NR 17
  28. #endif
  29. #ifdef CONFIG_X86_32
  30. # define KEXEC_CONTROL_CODE_MAX_SIZE 2048
  31. #endif
  32. #ifndef __ASSEMBLY__
  33. #include <linux/string.h>
  34. #include <asm/page.h>
  35. #include <asm/ptrace.h>
  36. /*
  37. * KEXEC_SOURCE_MEMORY_LIMIT maximum page get_free_page can return.
  38. * I.e. Maximum page that is mapped directly into kernel memory,
  39. * and kmap is not required.
  40. *
  41. * So far x86_64 is limited to 40 physical address bits.
  42. */
  43. #ifdef CONFIG_X86_32
  44. /* Maximum physical address we can use pages from */
  45. # define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)
  46. /* Maximum address we can reach in physical address mode */
  47. # define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL)
  48. /* Maximum address we can use for the control code buffer */
  49. # define KEXEC_CONTROL_MEMORY_LIMIT TASK_SIZE
  50. # define KEXEC_CONTROL_PAGE_SIZE 4096
  51. /* The native architecture */
  52. # define KEXEC_ARCH KEXEC_ARCH_386
  53. /* We can also handle crash dumps from 64 bit kernel. */
  54. # define vmcore_elf_check_arch_cross(x) ((x)->e_machine == EM_X86_64)
  55. #else
  56. /* Maximum physical address we can use pages from */
  57. # define KEXEC_SOURCE_MEMORY_LIMIT (0xFFFFFFFFFFUL)
  58. /* Maximum address we can reach in physical address mode */
  59. # define KEXEC_DESTINATION_MEMORY_LIMIT (0xFFFFFFFFFFUL)
  60. /* Maximum address we can use for the control pages */
  61. # define KEXEC_CONTROL_MEMORY_LIMIT (0xFFFFFFFFFFUL)
  62. /* Allocate one page for the pdp and the second for the code */
  63. # define KEXEC_CONTROL_PAGE_SIZE (4096UL + 4096UL)
  64. /* The native architecture */
  65. # define KEXEC_ARCH KEXEC_ARCH_X86_64
  66. #endif
  67. /*
  68. * CPU does not save ss and sp on stack if execution is already
  69. * running in kernel mode at the time of NMI occurrence. This code
  70. * fixes it.
  71. */
  72. static inline void crash_fixup_ss_esp(struct pt_regs *newregs,
  73. struct pt_regs *oldregs)
  74. {
  75. #ifdef CONFIG_X86_32
  76. newregs->sp = (unsigned long)&(oldregs->sp);
  77. asm volatile("xorl %%eax, %%eax\n\t"
  78. "movw %%ss, %%ax\n\t"
  79. :"=a"(newregs->ss));
  80. #endif
  81. }
  82. /*
  83. * This function is responsible for capturing register states if coming
  84. * via panic otherwise just fix up the ss and sp if coming via kernel
  85. * mode exception.
  86. */
  87. static inline void crash_setup_regs(struct pt_regs *newregs,
  88. struct pt_regs *oldregs)
  89. {
  90. if (oldregs) {
  91. memcpy(newregs, oldregs, sizeof(*newregs));
  92. crash_fixup_ss_esp(newregs, oldregs);
  93. } else {
  94. #ifdef CONFIG_X86_32
  95. asm volatile("movl %%ebx,%0" : "=m"(newregs->bx));
  96. asm volatile("movl %%ecx,%0" : "=m"(newregs->cx));
  97. asm volatile("movl %%edx,%0" : "=m"(newregs->dx));
  98. asm volatile("movl %%esi,%0" : "=m"(newregs->si));
  99. asm volatile("movl %%edi,%0" : "=m"(newregs->di));
  100. asm volatile("movl %%ebp,%0" : "=m"(newregs->bp));
  101. asm volatile("movl %%eax,%0" : "=m"(newregs->ax));
  102. asm volatile("movl %%esp,%0" : "=m"(newregs->sp));
  103. asm volatile("movl %%ss, %%eax;" :"=a"(newregs->ss));
  104. asm volatile("movl %%cs, %%eax;" :"=a"(newregs->cs));
  105. asm volatile("movl %%ds, %%eax;" :"=a"(newregs->ds));
  106. asm volatile("movl %%es, %%eax;" :"=a"(newregs->es));
  107. asm volatile("pushfl; popl %0" :"=m"(newregs->flags));
  108. #else
  109. asm volatile("movq %%rbx,%0" : "=m"(newregs->bx));
  110. asm volatile("movq %%rcx,%0" : "=m"(newregs->cx));
  111. asm volatile("movq %%rdx,%0" : "=m"(newregs->dx));
  112. asm volatile("movq %%rsi,%0" : "=m"(newregs->si));
  113. asm volatile("movq %%rdi,%0" : "=m"(newregs->di));
  114. asm volatile("movq %%rbp,%0" : "=m"(newregs->bp));
  115. asm volatile("movq %%rax,%0" : "=m"(newregs->ax));
  116. asm volatile("movq %%rsp,%0" : "=m"(newregs->sp));
  117. asm volatile("movq %%r8,%0" : "=m"(newregs->r8));
  118. asm volatile("movq %%r9,%0" : "=m"(newregs->r9));
  119. asm volatile("movq %%r10,%0" : "=m"(newregs->r10));
  120. asm volatile("movq %%r11,%0" : "=m"(newregs->r11));
  121. asm volatile("movq %%r12,%0" : "=m"(newregs->r12));
  122. asm volatile("movq %%r13,%0" : "=m"(newregs->r13));
  123. asm volatile("movq %%r14,%0" : "=m"(newregs->r14));
  124. asm volatile("movq %%r15,%0" : "=m"(newregs->r15));
  125. asm volatile("movl %%ss, %%eax;" :"=a"(newregs->ss));
  126. asm volatile("movl %%cs, %%eax;" :"=a"(newregs->cs));
  127. asm volatile("pushfq; popq %0" :"=m"(newregs->flags));
  128. #endif
  129. newregs->ip = (unsigned long)current_text_addr();
  130. }
  131. }
  132. #ifdef CONFIG_X86_32
  133. asmlinkage unsigned long
  134. relocate_kernel(unsigned long indirection_page,
  135. unsigned long control_page,
  136. unsigned long start_address,
  137. unsigned int has_pae,
  138. unsigned int preserve_context);
  139. #else
  140. NORET_TYPE void
  141. relocate_kernel(unsigned long indirection_page,
  142. unsigned long page_list,
  143. unsigned long start_address) ATTRIB_NORET;
  144. #endif
  145. #ifdef CONFIG_X86_32
  146. #define ARCH_HAS_KIMAGE_ARCH
  147. struct kimage_arch {
  148. pgd_t *pgd;
  149. #ifdef CONFIG_X86_PAE
  150. pmd_t *pmd0;
  151. pmd_t *pmd1;
  152. #endif
  153. pte_t *pte0;
  154. pte_t *pte1;
  155. };
  156. #endif
  157. #endif /* __ASSEMBLY__ */
  158. #endif /* _ASM_X86_KEXEC_H */