+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
+;\r
+; This program and the accompanying materials\r
+; are licensed and made available under the terms and conditions of the BSD License\r
+; which accompanies this distribution. The full text of the license may be found at\r
+; http://opensource.org/licenses/bsd-license.php.\r
+;\r
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+ DEFAULT REL\r
+ SECTION .text\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; JumpToKernel (\r
+; VOID *KernelStart, // rcx\r
+; VOID *KernelBootParams // rdx\r
+; );\r
+;------------------------------------------------------------------------------\r
+global ASM_PFX(JumpToKernel)\r
+ASM_PFX(JumpToKernel):\r
+\r
+ ; Set up for executing kernel. BP in %esi, entry point on the stack\r
+ ; (64-bit when the 'ret' will use it as 32-bit, but we're little-endian)\r
+ mov rsi, rdx\r
+ push rcx\r
+\r
+ ; Jump into the compatibility mode CS\r
+ push 0x10\r
+ lea rax, [.0]\r
+ push rax\r
+ DB 0x48, 0xcb ; retfq\r
+\r
+.0:\r
+ ; Now in compatibility mode.\r
+\r
+ DB 0xb8, 0x18, 0x0, 0x0, 0x0 ; movl $0x18, %eax\r
+ DB 0x8e, 0xd8 ; movl %eax, %ds\r
+ DB 0x8e, 0xc0 ; movl %eax, %es\r
+ DB 0x8e, 0xe0 ; movl %eax, %fs\r
+ DB 0x8e, 0xe8 ; movl %eax, %gs\r
+ DB 0x8e, 0xd0 ; movl %eax, %ss\r
+\r
+ ; Disable paging\r
+ DB 0xf, 0x20, 0xc0 ; movl %cr0, %eax\r
+ DB 0xf, 0xba, 0xf8, 0x1f ; btcl $31, %eax\r
+ DB 0xf, 0x22, 0xc0 ; movl %eax, %cr0\r
+\r
+ ; Disable long mode in EFER\r
+ DB 0xb9, 0x80, 0x0, 0x0, 0xc0 ; movl $0x0c0000080, %ecx\r
+ DB 0xf, 0x32 ; rdmsr\r
+ DB 0xf, 0xba, 0xf8, 0x8 ; btcl $8, %eax\r
+ DB 0xf, 0x30 ; wrmsr\r
+\r
+ ; Disable PAE\r
+ DB 0xf, 0x20, 0xe0 ; movl %cr4, %eax\r
+ DB 0xf, 0xba, 0xf8, 0x5 ; btcl $5, %eax\r
+ DB 0xf, 0x22, 0xe0 ; movl %eax, %cr4\r
+\r
+ DB 0x31, 0xed ; xor %ebp, %ebp\r
+ DB 0x31, 0xff ; xor %edi, %edi\r
+ DB 0x31, 0xdb ; xor %ebx, %ebx\r
+ DB 0xc3 ; ret\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; JumpToUefiKernel (\r
+; EFI_HANDLE ImageHandle, // rcx\r
+; EFI_SYSTEM_TABLE *SystemTable, // rdx\r
+; VOID *KernelBootParams // r8\r
+; VOID *KernelStart, // r9\r
+; );\r
+;------------------------------------------------------------------------------\r
+global ASM_PFX(JumpToUefiKernel)\r
+ASM_PFX(JumpToUefiKernel):\r
+\r
+ mov rdi, rcx\r
+ mov rsi, rdx\r
+ mov rdx, r8\r
+ xor rax, rax\r
+ mov eax, [r8 + 0x264]\r
+ add r9, rax\r
+ add r9, 0x200\r
+ call r9\r
+ ret\r
+\r