relocator32.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2009,2010 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* The code segment of the protected mode. */
  19. #define CODE_SEGMENT 0x10
  20. /* The data segment of the protected mode. */
  21. #define DATA_SEGMENT 0x18
  22. #include "relocator_common.S"
  23. .p2align 4 /* force 16-byte alignment */
  24. VARIABLE(grub_relocator32_start)
  25. PREAMBLE
  26. RELOAD_GDT
  27. .code32
  28. /* Update other registers. */
  29. movl $DATA_SEGMENT, %eax
  30. movl %eax, %ds
  31. movl %eax, %es
  32. movl %eax, %fs
  33. movl %eax, %gs
  34. movl %eax, %ss
  35. DISABLE_PAGING
  36. #ifdef __x86_64__
  37. /* Disable amd64. */
  38. movl $GRUB_MEMORY_CPU_AMD64_MSR, %ecx
  39. rdmsr
  40. andl $(~GRUB_MEMORY_CPU_AMD64_MSR_ON), %eax
  41. wrmsr
  42. #endif
  43. /* Turn off PAE. */
  44. movl %cr4, %eax
  45. andl $(~GRUB_MEMORY_CPU_CR4_PAE_ON), %eax
  46. movl %eax, %cr4
  47. jmp LOCAL(cont2)
  48. LOCAL(cont2):
  49. .code32
  50. /* mov imm32, %eax */
  51. .byte 0xb8
  52. VARIABLE(grub_relocator32_esp)
  53. .long 0
  54. movl %eax, %esp
  55. /* mov imm32, %eax */
  56. .byte 0xb8
  57. VARIABLE(grub_relocator32_ebp)
  58. .long 0
  59. movl %eax, %ebp
  60. /* mov imm32, %eax */
  61. .byte 0xb8
  62. VARIABLE(grub_relocator32_esi)
  63. .long 0
  64. movl %eax, %esi
  65. /* mov imm32, %eax */
  66. .byte 0xb8
  67. VARIABLE(grub_relocator32_edi)
  68. .long 0
  69. movl %eax, %edi
  70. /* mov imm32, %eax */
  71. .byte 0xb8
  72. VARIABLE(grub_relocator32_eax)
  73. .long 0
  74. /* mov imm32, %ebx */
  75. .byte 0xbb
  76. VARIABLE(grub_relocator32_ebx)
  77. .long 0
  78. /* mov imm32, %ecx */
  79. .byte 0xb9
  80. VARIABLE(grub_relocator32_ecx)
  81. .long 0
  82. /* mov imm32, %edx */
  83. .byte 0xba
  84. VARIABLE(grub_relocator32_edx)
  85. .long 0
  86. /* Cleared direction flag is of no problem with any current
  87. payload and makes this implementation easier. */
  88. cld
  89. .byte 0xea
  90. VARIABLE(grub_relocator32_eip)
  91. .long 0
  92. .word CODE_SEGMENT
  93. /* GDT. Copied from loader/i386/linux.c. */
  94. .p2align 4
  95. LOCAL(gdt):
  96. /* NULL. */
  97. .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  98. /* Reserved. */
  99. .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  100. /* Code segment. */
  101. .byte 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x9A, 0xCF, 0x00
  102. /* Data segment. */
  103. .byte 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x92, 0xCF, 0x00
  104. LOCAL(gdt_end):
  105. VARIABLE(grub_relocator32_end)