9ba2aebe692585ecccd51922323f55c948051a8a
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / Ia32 / SmmInit.asm
1 ;------------------------------------------------------------------------------ ;
2 ; Copyright (c) 2009 - 2015, 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.Asm
14 ;
15 ; Abstract:
16 ;
17 ; Functions for relocating SMBASE's for all processors
18 ;
19 ;-------------------------------------------------------------------------------
20
21 .686p
22 .xmm
23 .model flat,C
24
25 SmmInitHandler PROTO C
26
27 EXTERNDEF C gSmmCr0:DWORD
28 EXTERNDEF C gSmmCr3:DWORD
29 EXTERNDEF C gSmmCr4:DWORD
30 EXTERNDEF C gcSmmInitTemplate:BYTE
31 EXTERNDEF C gcSmmInitSize:WORD
32 EXTERNDEF C gSmmJmpAddr:QWORD
33 EXTERNDEF C mRebasedFlag:PTR BYTE
34 EXTERNDEF C mSmmRelocationOriginalAddress:DWORD
35 EXTERNDEF C gSmmInitStack:DWORD
36 EXTERNDEF C gcSmiInitGdtr:FWORD
37
38 PROTECT_MODE_CS EQU 08h
39 PROTECT_MODE_DS EQU 20h
40
41 .code
42
43 gcSmiInitGdtr LABEL FWORD
44 DW 0
45 DQ 0
46
47 SmmStartup PROC
48 DB 66h, 0b8h
49 gSmmCr3 DD ?
50 mov cr3, eax
51 DB 67h, 66h
52 lgdt fword ptr cs:[ebp + (offset gcSmiInitGdtr - SmmStartup)]
53 DB 66h, 0b8h
54 gSmmCr4 DD ?
55 mov cr4, eax
56 DB 66h, 0b8h
57 gSmmCr0 DD ?
58 DB 0bfh, PROTECT_MODE_DS, 0 ; mov di, PROTECT_MODE_DS
59 mov cr0, eax
60 DB 66h, 0eah ; jmp far [ptr48]
61 gSmmJmpAddr LABEL QWORD
62 DD @32bit
63 DW PROTECT_MODE_CS
64 @32bit:
65 mov ds, edi
66 mov es, edi
67 mov fs, edi
68 mov gs, edi
69 mov ss, edi
70 DB 0bch ; mov esp, imm32
71 gSmmInitStack DD ?
72 call SmmInitHandler
73 rsm
74 SmmStartup ENDP
75
76 gcSmmInitTemplate LABEL BYTE
77
78 _SmmInitTemplate PROC
79 DB 66h
80 mov ebp, SmmStartup
81 DB 66h, 81h, 0edh, 00h, 00h, 03h, 00 ; sub ebp, 30000h
82 jmp bp ; jmp ebp actually
83 _SmmInitTemplate ENDP
84
85 gcSmmInitSize DW $ - gcSmmInitTemplate
86
87 SmmRelocationSemaphoreComplete PROC
88 push eax
89 mov eax, mRebasedFlag
90 mov byte ptr [eax], 1
91 pop eax
92 jmp [mSmmRelocationOriginalAddress]
93 SmmRelocationSemaphoreComplete ENDP
94 END