JumpToKernel.nasm 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ; @file
  2. ; Copyright (c) 2006 - 2019 Intel Corporation. All rights reserved. <BR>
  3. ;
  4. ; SPDX-License-Identifier: BSD-2-Clause-Patent
  5. ;
  6. DEFAULT REL
  7. SECTION .text
  8. ;------------------------------------------------------------------------------
  9. ; VOID
  10. ; EFIAPI
  11. ; JumpToKernel (
  12. ; VOID *KernelStart, // rcx
  13. ; VOID *KernelBootParams // rdx
  14. ; );
  15. ;------------------------------------------------------------------------------
  16. global ASM_PFX(JumpToKernel)
  17. ASM_PFX(JumpToKernel):
  18. ; Set up for executing kernel. BP in %esi, entry point on the stack
  19. ; (64-bit when the 'ret' will use it as 32-bit, but we're little-endian)
  20. mov rsi, rdx
  21. push rcx
  22. ; Jump into the compatibility mode CS
  23. push 0x10
  24. lea rax, [.0]
  25. push rax
  26. DB 0x48, 0xcb ; retfq
  27. .0:
  28. ; Now in compatibility mode.
  29. DB 0xb8, 0x18, 0x0, 0x0, 0x0 ; movl $0x18, %eax
  30. DB 0x8e, 0xd8 ; movl %eax, %ds
  31. DB 0x8e, 0xc0 ; movl %eax, %es
  32. DB 0x8e, 0xe0 ; movl %eax, %fs
  33. DB 0x8e, 0xe8 ; movl %eax, %gs
  34. DB 0x8e, 0xd0 ; movl %eax, %ss
  35. ; Disable paging
  36. DB 0xf, 0x20, 0xc0 ; movl %cr0, %eax
  37. DB 0xf, 0xba, 0xf8, 0x1f ; btcl $31, %eax
  38. DB 0xf, 0x22, 0xc0 ; movl %eax, %cr0
  39. ; Disable long mode in EFER
  40. DB 0xb9, 0x80, 0x0, 0x0, 0xc0 ; movl $0x0c0000080, %ecx
  41. DB 0xf, 0x32 ; rdmsr
  42. DB 0xf, 0xba, 0xf8, 0x8 ; btcl $8, %eax
  43. DB 0xf, 0x30 ; wrmsr
  44. ; Disable PAE
  45. DB 0xf, 0x20, 0xe0 ; movl %cr4, %eax
  46. DB 0xf, 0xba, 0xf8, 0x5 ; btcl $5, %eax
  47. DB 0xf, 0x22, 0xe0 ; movl %eax, %cr4
  48. DB 0x31, 0xed ; xor %ebp, %ebp
  49. DB 0x31, 0xff ; xor %edi, %edi
  50. DB 0x31, 0xdb ; xor %ebx, %ebx
  51. DB 0xc3 ; ret
  52. ;------------------------------------------------------------------------------
  53. ; VOID
  54. ; EFIAPI
  55. ; JumpToUefiKernel (
  56. ; EFI_HANDLE ImageHandle, // rcx
  57. ; EFI_SYSTEM_TABLE *SystemTable, // rdx
  58. ; VOID *KernelBootParams // r8
  59. ; VOID *KernelStart, // r9
  60. ; );
  61. ;------------------------------------------------------------------------------
  62. global ASM_PFX(JumpToUefiKernel)
  63. ASM_PFX(JumpToUefiKernel):
  64. mov rdi, rcx
  65. mov rsi, rdx
  66. mov rdx, r8
  67. xor rax, rax
  68. mov eax, [r8 + 0x264]
  69. add r9, rax
  70. add r9, 0x200
  71. call r9
  72. ret