MdePkg/BaseLib: add PatchInstructionX86()
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / Ia32 / SmmInit.S
CommitLineData
7947da3c
MK
1#------------------------------------------------------------------------------\r
2#\r
3# Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
4# This program and the accompanying materials\r
5# are licensed and made available under the terms and conditions of the BSD License\r
6# which accompanies this distribution. The full text of the license may be found at\r
7# http://opensource.org/licenses/bsd-license.php.\r
8#\r
9# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11#\r
12# Module Name:\r
13#\r
14# SmmInit.S\r
15#\r
16# Abstract:\r
17#\r
18# Functions for relocating SMBASE's for all processors\r
19#\r
20#------------------------------------------------------------------------------\r
21\r
22ASM_GLOBAL ASM_PFX(gSmmCr0)\r
23ASM_GLOBAL ASM_PFX(gSmmCr3)\r
24ASM_GLOBAL ASM_PFX(gSmmCr4)\r
25ASM_GLOBAL ASM_PFX(gcSmmInitTemplate)\r
26ASM_GLOBAL ASM_PFX(gcSmmInitSize)\r
27ASM_GLOBAL ASM_PFX(gSmmJmpAddr)\r
28ASM_GLOBAL ASM_PFX(SmmRelocationSemaphoreComplete)\r
29ASM_GLOBAL ASM_PFX(gSmmInitStack)\r
30ASM_GLOBAL ASM_PFX(gcSmiInitGdtr)\r
31\r
32.equ PROTECT_MODE_CS, 0x08\r
33.equ PROTECT_MODE_DS, 0x20\r
34\r
35 .text\r
36\r
37ASM_PFX(gcSmiInitGdtr):\r
38 .word 0\r
39 .quad 0\r
40\r
41SmmStartup:\r
42 .byte 0x66,0xb8\r
43ASM_PFX(gSmmCr3): .space 4\r
44 movl %eax, %cr3\r
45 .byte 0x67,0x66\r
46 lgdt %cs:(ASM_PFX(gcSmiInitGdtr) - SmmStartup)(%ebp)\r
47 .byte 0x66,0xb8\r
48ASM_PFX(gSmmCr4): .space 4\r
49 movl %eax, %cr4\r
50 .byte 0x66,0xb8\r
51ASM_PFX(gSmmCr0): .space 4\r
52 .byte 0xbf, PROTECT_MODE_DS, 0 # mov di, PROTECT_MODE_DS\r
53 movl %eax, %cr0\r
54 .byte 0x66,0xea # jmp far [ptr48]\r
55ASM_PFX(gSmmJmpAddr): .long Start32bit\r
56 .word PROTECT_MODE_CS\r
57Start32bit:\r
58 movl %edi,%ds\r
59 movl %edi,%es\r
60 movl %edi,%fs\r
61 movl %edi,%gs\r
62 movl %edi,%ss\r
63 .byte 0xbc # mov esp, imm32\r
64ASM_PFX(gSmmInitStack): .space 4\r
65 call ASM_PFX(SmmInitHandler)\r
66 rsm\r
67\r
68ASM_PFX(gcSmmInitTemplate):\r
69\r
70_SmmInitTemplate:\r
71 .byte 0x66\r
72 movl $SmmStartup, %ebp\r
73 .byte 0x66, 0x81, 0xed, 0, 0, 3, 0 # sub ebp, 0x30000\r
74 jmp *%bp # jmp ebp actually\r
75\r
76ASM_PFX(gcSmmInitSize): .word . - ASM_PFX(gcSmmInitTemplate)\r
77\r
78\r
79ASM_PFX(SmmRelocationSemaphoreComplete):\r
80 pushl %eax\r
81 movl ASM_PFX(mRebasedFlag), %eax\r
82 movb $1, (%eax)\r
83 popl %eax\r
84 jmp *ASM_PFX(mSmmRelocationOriginalAddress)\r