]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/MpFuncs.S
UefiCpuPkg: Add PiSmmCpuDxeSmm module IA32 files
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / Ia32 / MpFuncs.S
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/MpFuncs.S b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/MpFuncs.S
new file mode 100644 (file)
index 0000000..75aa312
--- /dev/null
@@ -0,0 +1,165 @@
+#------------------------------------------------------------------------------\r
+#\r
+# Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php.\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+# Module Name:\r
+#\r
+#   MpFuncs.S\r
+#\r
+# Abstract:\r
+#\r
+#   This is the assembly code for Multi-processor S3 support\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+.equ                   VacantFlag,       0x0\r
+.equ                   NotVacantFlag,    0xff\r
+\r
+.equ                   LockLocation,     RendezvousFunnelProcEnd - RendezvousFunnelProcStart\r
+.equ                   StackStart,       RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x04\r
+.equ                   StackSize,        RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x08\r
+.equ                   RendezvousProc,   RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x0C\r
+.equ                   GdtrProfile,      RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x10\r
+.equ                   IdtrProfile,      RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x16\r
+.equ                   BufferStart,      RendezvousFunnelProcEnd - RendezvousFunnelProcStart + 0x1C\r
+\r
+#-------------------------------------------------------------------------------------\r
+#RendezvousFunnelProc  procedure follows. All APs execute their procedure. This\r
+#procedure serializes all the AP processors through an Init sequence. It must be\r
+#noted that APs arrive here very raw...ie: real mode, no stack.\r
+#ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC\r
+#IS IN MACHINE CODE.\r
+#-------------------------------------------------------------------------------------\r
+#RendezvousFunnelProc (&WakeUpBuffer,MemAddress);\r
+\r
+ASM_GLOBAL ASM_PFX(RendezvousFunnelProc)\r
+ASM_PFX(RendezvousFunnelProc):\r
+RendezvousFunnelProcStart:\r
+\r
+# At this point CS = 0x(vv00) and ip= 0x0.\r
+\r
+        .byte 0x8c,0xc8               # mov        ax,  cs\r
+        .byte 0x8e,0xd8               # mov        ds,  ax\r
+        .byte 0x8e,0xc0               # mov        es,  ax\r
+        .byte 0x8e,0xd0               # mov        ss,  ax\r
+        .byte 0x33,0xc0               # xor        ax,  ax\r
+        .byte 0x8e,0xe0               # mov        fs,  ax\r
+        .byte 0x8e,0xe8               # mov        gs,  ax\r
+\r
+flat32Start:\r
+\r
+        .byte 0xBE\r
+        .word BufferStart\r
+        .byte 0x66,0x8B,0x14          # mov        edx,dword ptr [si]          ; EDX is keeping the start address of wakeup buffer\r
+\r
+        .byte 0xBE\r
+        .word GdtrProfile\r
+        .byte 0x66                    # db         66h\r
+        .byte 0x2E,0xF,0x1,0x14       # lgdt       fword ptr cs:[si]\r
+\r
+        .byte 0xBE\r
+        .word IdtrProfile\r
+        .byte 0x66                    # db         66h\r
+        .byte 0x2E,0xF,0x1,0x1C       # lidt       fword ptr cs:[si]\r
+\r
+        .byte 0x33,0xC0               # xor        ax,  ax\r
+        .byte 0x8E,0xD8               # mov        ds,  ax\r
+\r
+        .byte 0xF,0x20,0xC0           # mov        eax, cr0                    ; Get control register 0\r
+        .byte 0x66,0x83,0xC8,0x1      # or         eax, 000000001h             ; Set PE bit (bit #0)\r
+        .byte 0xF,0x22,0xC0           # mov        cr0, eax\r
+\r
+FLAT32_JUMP:\r
+\r
+        .byte 0x66,0x67,0xEA          # far jump\r
+        .long 0x0                     # 32-bit offset\r
+        .word 0x20                    # 16-bit selector\r
+\r
+PMODE_ENTRY:                          # protected mode entry point\r
+\r
+        movw        $0x8,%ax\r
+        .byte       0x66\r
+        movw        %ax,%ds\r
+        .byte       0x66\r
+        movw        %ax,%es\r
+        .byte       0x66\r
+        movw        %ax,%fs\r
+        .byte       0x66\r
+        movw        %ax,%gs\r
+        .byte       0x66\r
+        movw        %ax,%ss           # Flat mode setup.\r
+\r
+        movl        %edx,%esi\r
+\r
+        movl        %esi,%edi\r
+        addl        $LockLocation, %edi\r
+        movb        $NotVacantFlag, %al\r
+TestLock:\r
+        xchgb       (%edi), %al\r
+        cmpb        $NotVacantFlag, %al\r
+        jz          TestLock\r
+\r
+ProgramStack:\r
+\r
+        movl        %esi,%edi\r
+        addl        $StackSize, %edi\r
+        movl        (%edi),%eax\r
+        movl        %esi,%edi\r
+        addl        $StackStart, %edi\r
+        addl        (%edi),%eax\r
+        movl        %eax,%esp\r
+        movl        %eax,(%edi)\r
+\r
+Releaselock:\r
+\r
+        movb        $VacantFlag, %al\r
+        movl        %esi,%edi\r
+        addl        $LockLocation, %edi\r
+        xchgb       (%edi), %al\r
+\r
+        #\r
+        # Call assembly function to initialize FPU.\r
+        #\r
+        lea         ASM_PFX(InitializeFloatingPointUnits), %ebx\r
+        call        *%ebx\r
+        #\r
+        # Call C Function\r
+        #\r
+        movl        %esi,%edi\r
+        addl        $RendezvousProc, %edi\r
+        movl        (%edi),%eax\r
+\r
+        testl       %eax,%eax\r
+        jz          GoToSleep\r
+        call        *%eax                         # Call C function\r
+\r
+GoToSleep:\r
+        cli\r
+        hlt\r
+        jmp         GoToSleep\r
+\r
+RendezvousFunnelProcEnd:\r
+#-------------------------------------------------------------------------------------\r
+#  AsmGetAddressMap (&AddressMap);\r
+#-------------------------------------------------------------------------------------\r
+ASM_GLOBAL ASM_PFX(AsmGetAddressMap)\r
+ASM_PFX(AsmGetAddressMap):\r
+\r
+        pushal\r
+        movl        %esp,%ebp\r
+\r
+        movl        0x24(%ebp), %ebx\r
+        movl        $RendezvousFunnelProcStart, (%ebx)\r
+        movl        $(PMODE_ENTRY - RendezvousFunnelProcStart), 0x4(%ebx)\r
+        movl        $(FLAT32_JUMP - RendezvousFunnelProcStart), 0x8(%ebx)\r
+        movl        $(RendezvousFunnelProcEnd - RendezvousFunnelProcStart), 0x0c(%ebx)\r
+\r
+        popal\r
+        ret\r