]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/X64/DisablePaging64.S
41d6a6f5d7791c113ac8643f5ec35d0d65300d26
[mirror_edk2.git] / MdePkg / Library / BaseLib / X64 / DisablePaging64.S
1 #------------------------------------------------------------------------------
2 #
3 # Copyright (c) 2006 - 2008, Intel Corporation
4 # All rights reserved. This program and the accompanying materials
5 # are licensed and made available under the terms and conditions of the BSD License
6 # which accompanies this distribution. The full text of the license may be found at
7 # http://opensource.org/licenses/bsd-license.php
8 #
9 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 #
12 # Module Name:
13 #
14 # DisablePaging64.S
15 #
16 # Abstract:
17 #
18 # AsmDisablePaging64 function
19 #
20 # Notes:
21 #
22 #------------------------------------------------------------------------------
23
24
25
26 #------------------------------------------------------------------------------
27 # VOID
28 # EFIAPI
29 # InternalX86DisablePaging64 (
30 # IN UINT16 Cs,
31 # IN UINT32 EntryPoint,
32 # IN UINT32 Context1, OPTIONAL
33 # IN UINT32 Context2, OPTIONAL
34 # IN UINT32 NewStack
35 # );
36 #------------------------------------------------------------------------------
37
38 ASM_GLOBAL ASM_PFX(InternalX86DisablePaging64)
39 ASM_PFX(InternalX86DisablePaging64):
40 cli
41 lea L1(%rip), %rsi # rsi <- The start address of transition code
42 mov 0x28(%rsp), %edi # rdi <- New stack
43 sub $64, %edi # rdi <- use 64 byte in stack to hold transition code
44 mov %edi, %r10d # r10 <- The start address of transicition code below 4G
45 lea _mTransitionEnd(%rip), %rax # rax <- end of transition code
46 sub %rsi, %rax # rax <- The size of transition piece code
47 push %rcx # save rcx to stack
48 mov %rax, %rcx # rcx <- The size of transition piece code
49 rep
50 movsb # copy transition code to (new stack - 64byte) below 4G
51 pop %rcx # restore rcx
52
53 mov %r8d, %esi
54 mov %r9d, %edi
55 mov 0x28(%rsp), %eax # eax <- New Stack
56 push %rcx # push Cs to stack
57 push %r10
58 .byte 0x48, 0xcb # retq: Use far return to load CS register from stack
59 # (Use raw byte code since some GNU assemblers generates incorrect code for "retq")
60 L1:
61 mov %eax,%esp # set up new stack
62 mov %cr0,%rax
63 btr $0x1f,%eax
64 mov %rax,%cr0 # disable paging
65
66 mov %rdx,%rbx # save EntryPoint to rbx, for rdmsr will overwrite rdx
67 mov $0xc0000080,%ecx
68 rdmsr
69 and $0xfe,%ah # clear LME
70 wrmsr
71 mov %cr4,%rax
72 and $0xdf,%al # clear PAE
73 mov %rax,%cr4
74 push %rdi # push Context2
75 push %rsi # push Context1
76 callq *%rbx # transfer control to EntryPoint
77 jmp . # no one should get here
78 _mTransitionEnd :