]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm
9231aa5b3deda5fefdbcd4f3c772a0e60bd98633
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / Ia32 / SmmInit.nasm
1 ;------------------------------------------------------------------------------ ;
2 ; Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
3 ; This program and the accompanying materials
4 ; are licensed and made available under the terms and conditions of the BSD License
5 ; which accompanies this distribution. The full text of the license may be found at
6 ; http://opensource.org/licenses/bsd-license.php.
7 ;
8 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
10 ;
11 ; Module Name:
12 ;
13 ; SmmInit.nasm
14 ;
15 ; Abstract:
16 ;
17 ; Functions for relocating SMBASE's for all processors
18 ;
19 ;-------------------------------------------------------------------------------
20
21 extern ASM_PFX(SmmInitHandler)
22 extern ASM_PFX(mRebasedFlag)
23 extern ASM_PFX(mSmmRelocationOriginalAddress)
24
25 global ASM_PFX(gSmmCr3)
26 global ASM_PFX(gSmmCr4)
27 global ASM_PFX(gSmmCr0)
28 global ASM_PFX(gSmmJmpAddr)
29 global ASM_PFX(gSmmInitStack)
30 global ASM_PFX(gcSmiInitGdtr)
31 global ASM_PFX(gcSmmInitSize)
32 global ASM_PFX(gcSmmInitTemplate)
33
34 %define PROTECT_MODE_CS 0x8
35 %define PROTECT_MODE_DS 0x20
36
37 SECTION .text
38
39 ASM_PFX(gcSmiInitGdtr):
40 DW 0
41 DQ 0
42
43 global ASM_PFX(SmmStartup)
44
45 BITS 16
46 ASM_PFX(SmmStartup):
47 mov eax, 0x80000001 ; read capability
48 cpuid
49 mov ebx, edx ; rdmsr will change edx. keep it in ebx.
50 DB 0x66, 0xb8 ; mov eax, imm32
51 ASM_PFX(gSmmCr3): DD 0
52 mov cr3, eax
53 o32 lgdt [cs:ebp + (ASM_PFX(gcSmiInitGdtr) - ASM_PFX(SmmStartup))]
54 DB 0x66, 0xb8 ; mov eax, imm32
55 ASM_PFX(gSmmCr4): DD 0
56 mov cr4, eax
57 mov ecx, 0xc0000080 ; IA32_EFER MSR
58 rdmsr
59 test ebx, BIT20 ; check NXE capability
60 jz .1
61 or ah, BIT3 ; set NXE bit
62 wrmsr
63 .1:
64 DB 0x66, 0xb8 ; mov eax, imm32
65 ASM_PFX(gSmmCr0): DD 0
66 mov di, PROTECT_MODE_DS
67 mov cr0, eax
68 DB 0x66, 0xea ; jmp far [ptr48]
69 ASM_PFX(gSmmJmpAddr):
70 DD @32bit
71 DW PROTECT_MODE_CS
72
73 BITS 32
74 @32bit:
75 mov ds, edi
76 mov es, edi
77 mov fs, edi
78 mov gs, edi
79 mov ss, edi
80 DB 0xbc ; mov esp, imm32
81 ASM_PFX(gSmmInitStack): DD 0
82 call ASM_PFX(SmmInitHandler)
83 rsm
84
85 BITS 16
86 ASM_PFX(gcSmmInitTemplate):
87 mov ebp, ASM_PFX(SmmStartup)
88 sub ebp, 0x30000
89 jmp ebp
90
91 ASM_PFX(gcSmmInitSize): DW $ - ASM_PFX(gcSmmInitTemplate)
92
93 BITS 32
94 global ASM_PFX(SmmRelocationSemaphoreComplete)
95 ASM_PFX(SmmRelocationSemaphoreComplete):
96 push eax
97 mov eax, [ASM_PFX(mRebasedFlag)]
98 mov byte [eax], 1
99 pop eax
100 jmp [ASM_PFX(mSmmRelocationOriginalAddress)]
101
102 global ASM_PFX(PiSmmCpuSmmInitFixupAddress)
103 ASM_PFX(PiSmmCpuSmmInitFixupAddress):
104 ret