e8db33a45a4d11ed7c3e4f9116f83f06abc3f69c
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / Ia32 / SmmInit.S
1 #------------------------------------------------------------------------------
2 #
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.
8 #
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.
11 #
12 # Module Name:
13 #
14 # SmmInit.S
15 #
16 # Abstract:
17 #
18 # Functions for relocating SMBASE's for all processors
19 #
20 #------------------------------------------------------------------------------
21
22 ASM_GLOBAL ASM_PFX(gSmmCr0)
23 ASM_GLOBAL ASM_PFX(gSmmCr3)
24 ASM_GLOBAL ASM_PFX(gSmmCr4)
25 ASM_GLOBAL ASM_PFX(gcSmmInitTemplate)
26 ASM_GLOBAL ASM_PFX(gcSmmInitSize)
27 ASM_GLOBAL ASM_PFX(gSmmJmpAddr)
28 ASM_GLOBAL ASM_PFX(SmmRelocationSemaphoreComplete)
29 ASM_GLOBAL ASM_PFX(gSmmInitStack)
30 ASM_GLOBAL ASM_PFX(gcSmiInitGdtr)
31
32 .equ PROTECT_MODE_CS, 0x08
33 .equ PROTECT_MODE_DS, 0x20
34
35 .text
36
37 ASM_PFX(gcSmiInitGdtr):
38 .word 0
39 .quad 0
40
41 SmmStartup:
42 .byte 0x66,0xb8
43 ASM_PFX(gSmmCr3): .space 4
44 movl %eax, %cr3
45 .byte 0x67,0x66
46 lgdt %cs:(ASM_PFX(gcSmiInitGdtr) - SmmStartup)(%ebp)
47 .byte 0x66,0xb8
48 ASM_PFX(gSmmCr4): .space 4
49 movl %eax, %cr4
50 .byte 0x66,0xb8
51 ASM_PFX(gSmmCr0): .space 4
52 .byte 0xbf, PROTECT_MODE_DS, 0 # mov di, PROTECT_MODE_DS
53 movl %eax, %cr0
54 .byte 0x66,0xea # jmp far [ptr48]
55 ASM_PFX(gSmmJmpAddr): .long Start32bit
56 .word PROTECT_MODE_CS
57 Start32bit:
58 movl %edi,%ds
59 movl %edi,%es
60 movl %edi,%fs
61 movl %edi,%gs
62 movl %edi,%ss
63 .byte 0xbc # mov esp, imm32
64 ASM_PFX(gSmmInitStack): .space 4
65 call ASM_PFX(SmmInitHandler)
66 rsm
67
68 ASM_PFX(gcSmmInitTemplate):
69
70 _SmmInitTemplate:
71 .byte 0x66
72 movl $SmmStartup, %ebp
73 .byte 0x66, 0x81, 0xed, 0, 0, 3, 0 # sub ebp, 0x30000
74 jmp *%bp # jmp ebp actually
75
76 ASM_PFX(gcSmmInitSize): .word . - ASM_PFX(gcSmmInitTemplate)
77
78
79 ASM_PFX(SmmRelocationSemaphoreComplete):
80 pushl %eax
81 movl ASM_PFX(mRebasedFlag), %eax
82 movb $1, (%eax)
83 popl %eax
84 jmp *ASM_PFX(mSmmRelocationOriginalAddress)