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