+#------------------------------------------------------------------------------\r
+#\r
+# Copyright (c) 2006, Intel Corporation\r
+# All rights reserved. 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
+# Module Name:\r
+#\r
+# EnablePaging64.Asm\r
+#\r
+# Abstract:\r
+#\r
+# InternalX86EnablePaging64 function\r
+#\r
+# Notes:\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+.globl ASM_PFX(InternalX86EnablePaging64)\r
+\r
+#------------------------------------------------------------------------------\r
+# VOID\r
+# EFIAPI\r
+# InternalX86EnablePaging64 (\r
+# IN UINT16 CodeSelector,\r
+# IN UINT64 EntryPoint,\r
+# IN UINT64 Context1, OPTIONAL\r
+# IN UINT64 Context2, OPTIONAL\r
+# IN UINT64 NewStack\r
+# );\r
+#------------------------------------------------------------------------------\r
+ASM_PFX(InternalX86EnablePaging64):\r
+ cli\r
+ movl $LongStart, (%esp)\r
+ movl %cr4, %eax\r
+ orb $0x20, %al\r
+ movl %eax, %cr4 # enable PAE\r
+ movl $0xc0000080, %ecx\r
+ rdmsr\r
+ orb $1, %ah # set LME\r
+ wrmsr\r
+ movl %cr0, %eax\r
+ btsl $31, %eax\r
+ movl %eax, %cr0 # enable paging\r
+ lret\r
+LongStart: # long mode starts here\r
+ .byte 0x67, 0x48\r
+ movl (%esp), %ebx # mov rbx, [esp]\r
+ .byte 0x67, 0x48\r
+ movl 8(%esp), %ecx # mov rcx, [esp + 8]\r
+ .byte 0x67, 0x48\r
+ movl 0x10(%esp), %edx # mov rdx, [esp + 10h]\r
+ .byte 0x67, 0x48\r
+ movl 0x18(%esp), %esp # mov rsp, [esp + 18h]\r
+ .byte 0x48\r
+ addl $0x-20, %esp # add rsp, -20h\r
+ call *%ebx # call rbx\r
+ jmp .\r