1#------------------------------------------------------------------------------ 2# 3# Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR> 4# 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 38ASM_GLOBAL ASM_PFX(InternalX86DisablePaging64) 39ASM_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 lea _mTransitionEnd(%rip), %rax # rax <- end of transition code 44 sub %rsi, %rax # rax <- The size of transition piece code 45 add $4, %rax # round rax up to the next 4 byte boundary 46 and $0xfc, %al 47 sub %rax, %rdi # rdi <- use stack to hold transition code 48 mov %edi, %r10d # r10 <- The start address of transicition code below 4G 49 push %rcx # save rcx to stack 50 mov %rax, %rcx # rcx <- The size of transition piece code 51 rep 52 movsb # copy transition code to (new stack - 64byte) below 4G 53 pop %rcx # restore rcx 54 55 mov %r8d, %esi 56 mov %r9d, %edi 57 mov %r10d, %eax 58 sub $4, %eax 59 push %rcx # push Cs to stack 60 push %r10 # push address of transition code on stack 61 .byte 0x48, 0xcb # retq: Use far return to load CS register from stack 62 # (Use raw byte code since some GNU assemblers generates incorrect code for "retq") 63L1: 64 mov %eax,%esp # set up new stack 65 mov %cr0,%rax 66 btr $0x1f,%eax # clear CR0.PG 67 mov %rax,%cr0 # disable paging 68 69 mov %edx,%ebx # save EntryPoint to ebx, for rdmsr will overwrite edx 70 mov $0xc0000080,%ecx 71 rdmsr 72 and $0xfe,%ah # clear LME 73 wrmsr 74 mov %cr4,%rax 75 and $0xdf,%al # clear PAE 76 mov %rax,%cr4 77 push %rdi # push Context2 78 push %rsi # push Context1 79 callq *%rbx # transfer control to EntryPoint 80 jmp . # no one should get here 81 82_mTransitionEnd : 83