1 #------------------------------------------------------------------------------
3 # Copyright (c) 2009 - 2015, 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.
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.
18 # Functions for relocating SMBASE's for all processors
20 #------------------------------------------------------------------------------
22 ASM_GLOBAL ASM_PFX(gSmmCr0)
23 ASM_GLOBAL ASM_PFX(gSmmCr3)
24 ASM_GLOBAL ASM_PFX(gSmmCr4)
25 ASM_GLOBAL ASM_PFX(gSmmJmpAddr)
26 ASM_GLOBAL ASM_PFX(gcSmmInitTemplate)
27 ASM_GLOBAL ASM_PFX(gcSmmInitSize)
28 ASM_GLOBAL ASM_PFX(mRebasedFlagAddr32)
29 ASM_GLOBAL ASM_PFX(SmmRelocationSemaphoreComplete)
30 ASM_GLOBAL ASM_PFX(SmmRelocationSemaphoreComplete32)
31 ASM_GLOBAL ASM_PFX(mSmmRelocationOriginalAddressPtr32)
32 ASM_GLOBAL ASM_PFX(gSmmInitStack)
33 ASM_GLOBAL ASM_PFX(gcSmiInitGdtr)
38 ASM_PFX(gcSmiInitGdtr):
43 .byte 0x66,0xb8 # mov eax, imm32
44 ASM_PFX(gSmmCr3): .space 4
47 lgdt (ASM_PFX(gcSmiInitGdtr) - SmmStartup)(%ebp)
48 .byte 0x66,0xb8 # mov eax, imm32
49 ASM_PFX(gSmmCr4): .space 4
50 orb $2, %ah # enable XMM registers access
53 movl $0xc0000080,%ecx # IA32_EFER MSR
55 orb $1,%ah # set LME bit
57 .byte 0x66,0xb8 # mov eax, imm32
58 ASM_PFX(gSmmCr0): .space 4
60 .byte 0x66,0xea # far jmp to long mode
61 ASM_PFX(gSmmJmpAddr): .quad LongMode
62 LongMode: # long-mode starts here
63 .byte 0x48,0xbc # mov rsp, imm64
64 ASM_PFX(gSmmInitStack): .space 8
65 andw $0xfff0, %sp # make sure RSP is 16-byte aligned
67 # Accoring to X64 calling convention, XMM0~5 are volatile, we need to save
68 # them before calling C-function.
71 movdqa %xmm0, 0x0(%rsp)
72 movdqa %xmm1, 0x10(%rsp)
73 movdqa %xmm2, 0x20(%rsp)
74 movdqa %xmm3, 0x30(%rsp)
75 movdqa %xmm4, 0x40(%rsp)
76 movdqa %xmm5, 0x50(%rsp)
80 call ASM_PFX(SmmInitHandler)
83 # Restore XMM0~5 after calling C-function.
85 movdqa 0x0(%rsp), %xmm0
86 movdqa 0x10(%rsp), %xmm1
87 movdqa 0x20(%rsp), %xmm2
88 movdqa 0x30(%rsp), %xmm3
89 movdqa 0x40(%rsp), %xmm4
90 movdqa 0x50(%rsp), %xmm5
94 ASM_PFX(gcSmmInitTemplate):
97 .byte 0x66,0x2e,0x8b,0x2e # mov ebp, cs:[@F]
98 .word L1 - _SmmInitTemplate + 0x8000
99 .byte 0x66, 0x81, 0xed, 0, 0, 3, 0 # sub ebp, 0x30000
100 jmp *%bp # jmp ebp actually
104 ASM_PFX(gcSmmInitSize): .word . - ASM_PFX(gcSmmInitTemplate)
106 ASM_PFX(SmmRelocationSemaphoreComplete):
107 # Create a simple stack frame to store RAX and the original RSM location
108 pushq %rax # Used to store return address
111 # Load the original RSM location onto stack
112 movabsq $ASM_PFX(mSmmRelocationOriginalAddress), %rax
114 movq %rax, 0x08(%rsp)
117 movabsq $ASM_PFX(mRebasedFlag), %rax
121 #restore RAX and return to original RSM location
126 # Semaphore code running in 32-bit mode
128 ASM_PFX(SmmRelocationSemaphoreComplete32):
133 ASM_PFX(mRebasedFlagAddr32):
140 ASM_PFX(mSmmRelocationOriginalAddressPtr32):