• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
21EXTERNDEF   SmmInitHandler:PROC
22EXTERNDEF   gSmmCr0:DWORD
23EXTERNDEF   gSmmCr3:DWORD
24EXTERNDEF   gSmmCr4:DWORD
25EXTERNDEF   gSmmJmpAddr:QWORD
26EXTERNDEF   gcSmmInitTemplate:BYTE
27EXTERNDEF   gcSmmInitSize:WORD
28EXTERNDEF   mRebasedFlag:PTR BYTE
29EXTERNDEF   mSmmRelocationOriginalAddress:QWORD
30EXTERNDEF   mRebasedFlagAddr32:DWORD
31EXTERNDEF   mSmmRelocationOriginalAddressPtr32:DWORD
32EXTERNDEF   gSmmInitStack:QWORD
33EXTERNDEF   gcSmiInitGdtr:FWORD
34
35    .code
36
37gcSmiInitGdtr   LABEL   FWORD
38            DW      0
39            DQ      0
40
41SmmStartup  PROC
42    DB      66h, 0b8h                   ; mov eax, imm32
43gSmmCr3     DD      ?
44    mov     cr3, rax
45    DB      66h, 2eh
46    lgdt    fword ptr [ebp + (offset gcSmiInitGdtr - SmmStartup)]
47    DB      66h, 0b8h                   ; mov eax, imm32
48gSmmCr4     DD      ?
49    or      ah,  2                      ; enable XMM registers access
50    mov     cr4, rax
51    DB      66h
52    mov     ecx, 0c0000080h             ; IA32_EFER MSR
53    rdmsr
54    or      ah, 1                       ; set LME bit
55    wrmsr
56    DB      66h, 0b8h                   ; mov eax, imm32
57gSmmCr0     DD      ?
58    mov     cr0, rax                    ; enable protected mode & paging
59    DB      66h, 0eah                   ; far jmp to long mode
60gSmmJmpAddr DQ      @LongMode
61@LongMode:                              ; long-mode starts here
62    DB      48h, 0bch                   ; mov rsp, imm64
63gSmmInitStack   DQ      ?
64    and     sp, 0fff0h                  ; make sure RSP is 16-byte aligned
65    ;
66    ; Accoring to X64 calling convention, XMM0~5 are volatile, we need to save
67    ; them before calling C-function.
68    ;
69    sub     rsp, 60h
70    movdqa  [rsp], xmm0
71    movdqa  [rsp + 10h], xmm1
72    movdqa  [rsp + 20h], xmm2
73    movdqa  [rsp + 30h], xmm3
74    movdqa  [rsp + 40h], xmm4
75    movdqa  [rsp + 50h], xmm5
76
77    add     rsp, -20h
78    call    SmmInitHandler
79    add     rsp, 20h
80
81    ;
82    ; Restore XMM0~5 after calling C-function.
83    ;
84    movdqa  xmm0, [rsp]
85    movdqa  xmm1, [rsp + 10h]
86    movdqa  xmm2, [rsp + 20h]
87    movdqa  xmm3, [rsp + 30h]
88    movdqa  xmm4, [rsp + 40h]
89    movdqa  xmm5, [rsp + 50h]
90
91    rsm
92SmmStartup  ENDP
93
94gcSmmInitTemplate   LABEL   BYTE
95
96_SmmInitTemplate    PROC
97    DB      66h, 2eh, 8bh, 2eh          ; mov ebp, cs:[@F]
98    DW      @L1 - _SmmInitTemplate + 8000h
99    DB      66h, 81h, 0edh, 00h, 00h, 03h, 00  ; sub ebp, 30000h
100    jmp     bp                          ; jmp ebp actually
101@L1:
102    DQ      SmmStartup
103_SmmInitTemplate    ENDP
104
105gcSmmInitSize   DW  $ - gcSmmInitTemplate
106
107SmmRelocationSemaphoreComplete PROC
108    push    rax
109    mov     rax, mRebasedFlag
110    mov     byte ptr [rax], 1
111    pop     rax
112    jmp     [mSmmRelocationOriginalAddress]
113SmmRelocationSemaphoreComplete ENDP
114
115;
116; Semaphore code running in 32-bit mode
117;
118SmmRelocationSemaphoreComplete32 PROC
119    ;
120    ; mov byte ptr [], 1
121    ;
122    db      0c6h, 05h
123mRebasedFlagAddr32    dd      0
124    db      1
125    ;
126    ; jmp dword ptr []
127    ;
128    db      0ffh, 25h
129mSmmRelocationOriginalAddressPtr32    dd      0
130SmmRelocationSemaphoreComplete32 ENDP
131
132    END
133