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