summaryrefslogtreecommitdiff
path: root/MdePkg
diff options
context:
space:
mode:
authorbbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524>2006-11-16 01:11:41 +0000
committerbbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524>2006-11-16 01:11:41 +0000
commite29e52e7c0d1cfe0de872fbb5ebe6c77bba0c30d (patch)
tree3c6c634ac8918f94c0fa117e4e7eb3818bc5d62a /MdePkg
parente2136826a3d45108ec96850e6b5921a315c1c1d8 (diff)
downloadedk2-platforms-e29e52e7c0d1cfe0de872fbb5ebe6c77bba0c30d.tar.xz
Initial port to x86_64 gnu assembly.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1959 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdePkg')
-rw-r--r--MdePkg/Library/BaseLib/X64/CpuBreakpoint.S25
-rw-r--r--MdePkg/Library/BaseLib/X64/CpuFlushTlb.S35
-rw-r--r--MdePkg/Library/BaseLib/X64/CpuId.S60
-rw-r--r--MdePkg/Library/BaseLib/X64/CpuIdEx.S62
-rw-r--r--MdePkg/Library/BaseLib/X64/CpuPause.S34
-rw-r--r--MdePkg/Library/BaseLib/X64/CpuSleep.S34
-rw-r--r--MdePkg/Library/BaseLib/X64/DisableInterrupts.S35
-rw-r--r--MdePkg/Library/BaseLib/X64/DisablePaging64.S66
-rw-r--r--MdePkg/Library/BaseLib/X64/EnableDisableInterrupts.S37
-rw-r--r--MdePkg/Library/BaseLib/X64/EnableInterrupts.S35
-rw-r--r--MdePkg/Library/BaseLib/X64/EnablePaging64.S61
-rw-r--r--MdePkg/Library/BaseLib/X64/FlushCacheLine.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/FxRestore.S35
-rw-r--r--MdePkg/Library/BaseLib/X64/FxSave.S35
-rw-r--r--MdePkg/Library/BaseLib/X64/InterlockedCompareExchange32.S37
-rw-r--r--MdePkg/Library/BaseLib/X64/InterlockedCompareExchange64.S39
-rw-r--r--MdePkg/Library/BaseLib/X64/InterlockedDecrement.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/InterlockedIncrement.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/Invd.S35
-rw-r--r--MdePkg/Library/BaseLib/X64/LongJump.S42
-rw-r--r--MdePkg/Library/BaseLib/X64/Monitor.S41
-rw-r--r--MdePkg/Library/BaseLib/X64/Mwait.S39
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadCr0.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadCr2.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadCr3.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadCr4.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadCs.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadDr0.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadDr1.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadDr2.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadDr3.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadDr4.S37
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadDr5.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadDr6.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadDr7.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadDs.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadEflags.S37
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadEs.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadFs.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadGdtr.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadGs.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadIdtr.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadLdtr.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadMm0.S37
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadMm1.S37
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadMm2.S37
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadMm3.S37
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadMm4.S37
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadMm5.S37
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadMm6.S37
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadMm7.S37
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadMsr64.S38
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadPmc.S38
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadSs.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadTr.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/ReadTsc.S38
-rw-r--r--MdePkg/Library/BaseLib/X64/SetJump.S42
-rw-r--r--MdePkg/Library/BaseLib/X64/SwitchStack.S44
-rw-r--r--MdePkg/Library/BaseLib/X64/Wbinvd.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteCr0.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteCr2.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteCr3.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteCr4.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteDr0.S37
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteDr1.S37
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteDr2.S37
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteDr3.S37
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteDr4.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteDr5.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteDr6.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteDr7.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteGdtr.S35
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteIdtr.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteLdtr.S36
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteMm0.S35
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteMm1.S35
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteMm2.S35
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteMm3.S35
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteMm4.S35
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteMm5.S35
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteMm6.S35
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteMm7.S35
-rw-r--r--MdePkg/Library/BaseLib/X64/WriteMsr64.S40
83 files changed, 3120 insertions, 0 deletions
diff --git a/MdePkg/Library/BaseLib/X64/CpuBreakpoint.S b/MdePkg/Library/BaseLib/X64/CpuBreakpoint.S
new file mode 100644
index 0000000000..710006bdd1
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/CpuBreakpoint.S
@@ -0,0 +1,25 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# CpuBreakpoint.S
+#
+# Abstract:
+#
+# Implementation of CpuBreakpoint() on x86_64
+#
+#------------------------------------------------------------------------------
+
+.global _CpuBreakpoint
+_CpuBreakpoint:
+ int $0x3
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/CpuFlushTlb.S b/MdePkg/Library/BaseLib/X64/CpuFlushTlb.S
new file mode 100644
index 0000000000..2dbaf846c4
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/CpuFlushTlb.S
@@ -0,0 +1,35 @@
+#------------------------------------------------------------------------------
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# CpuFlushTlb.Asm
+#
+# Abstract:
+#
+# CpuFlushTlb function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+.global _CpuFlushTlb
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# CpuFlushTlb (
+# VOID
+# );
+#------------------------------------------------------------------------------
+_CpuFlushTlb:
+ mov %cr3, %rax
+ mov %rax, %cr3
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/CpuId.S b/MdePkg/Library/BaseLib/X64/CpuId.S
new file mode 100644
index 0000000000..98d7faaa06
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/CpuId.S
@@ -0,0 +1,60 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# CpuId.S
+#
+# Abstract:
+#
+# AsmCpuid function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# AsmCpuid (
+# IN UINT32 RegisterInEax,
+# OUT UINT32 *RegisterOutEax OPTIONAL,
+# OUT UINT32 *RegisterOutEbx OPTIONAL,
+# OUT UINT32 *RegisterOutEcx OPTIONAL,
+# OUT UINT32 *RegisterOutEdx OPTIONAL
+# )
+#------------------------------------------------------------------------------
+.global _AsmCpuid;
+_AsmCpuid:
+ push %rbx
+ mov %ecx, %eax
+ push %rax # save Index on stack
+ push %rdx
+ cpuid
+ test %r9, %r9
+ jz L1
+ mov %ecx, (%r9)
+L1:
+ pop %rcx
+ jrcxz L2
+ mov %eax, (%rcx)
+L2:
+ mov %r8, %rcx
+ jrcxz L3
+ mov %ebx, (%rcx)
+L3:
+ mov 0x38(%rsp), %rcx
+ jrcxz L4
+ mov %edx, (%rcx)
+L4:
+ pop %rax # restore Index to rax as return value
+ pop %rbx
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/CpuIdEx.S b/MdePkg/Library/BaseLib/X64/CpuIdEx.S
new file mode 100644
index 0000000000..e5317e04cb
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/CpuIdEx.S
@@ -0,0 +1,62 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# CpuIdEx.Asm
+#
+# Abstract:
+#
+# AsmCpuidEx function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+#------------------------------------------------------------------------------
+# UINT32
+# EFIAPI
+# AsmCpuidEx (
+# IN UINT32 RegisterInEax,
+# IN UINT32 RegisterInEcx,
+# OUT UINT32 *RegisterOutEax OPTIONAL,
+# OUT UINT32 *RegisterOutEbx OPTIONAL,
+# OUT UINT32 *RegisterOutEcx OPTIONAL,
+# OUT UINT32 *RegisterOutEdx OPTIONAL
+# )
+#------------------------------------------------------------------------------
+.global _AsmCpuidEx
+_AsmCpuidEx:
+ push %rbx
+ movl %ecx,%eax
+ movl %edx,%ecx
+ push %rax
+ cpuid
+ mov 0x38(%rsp), %r10
+ test %r10, %r10
+ jz L1
+ mov %ecx,(%r10)
+L1:
+ mov %r8, %rcx
+ jrcxz L2
+ movl %eax,(%rcx)
+L2:
+ mov %r9, %rcx
+ jrcxz L3
+ mov %ebx, (%rcx)
+L3:
+ mov 0x40(%rsp), %rcx
+ jrcxz L4
+ mov %edx, (%rcx)
+L4:
+ pop %rax
+ pop %rbx
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/CpuPause.S b/MdePkg/Library/BaseLib/X64/CpuPause.S
new file mode 100644
index 0000000000..0ecaa85b61
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/CpuPause.S
@@ -0,0 +1,34 @@
+#------------------------------------------------------------------------------ ;
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# CpuPause.S
+#
+# Abstract:
+#
+# CpuPause function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# CpuPause (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _CpuPause;
+_CpuPause:
+ pause
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/CpuSleep.S b/MdePkg/Library/BaseLib/X64/CpuSleep.S
new file mode 100644
index 0000000000..681e4c12c3
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/CpuSleep.S
@@ -0,0 +1,34 @@
+#------------------------------------------------------------------------------ ;
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# CpuSleep.S
+#
+# Abstract:
+#
+# CpuSleep function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# CpuSleep (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _CpuSleep;
+_CpuSleep:
+ hlt
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/DisableInterrupts.S b/MdePkg/Library/BaseLib/X64/DisableInterrupts.S
new file mode 100644
index 0000000000..da16886b8b
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/DisableInterrupts.S
@@ -0,0 +1,35 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# DisableInterrupts.S
+#
+# Abstract:
+#
+# DisableInterrupts function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# DisableInterrupts (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _DisableInterrupts;
+_DisableInterrupts:
+ cli
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/DisablePaging64.S b/MdePkg/Library/BaseLib/X64/DisablePaging64.S
new file mode 100644
index 0000000000..d23313de38
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/DisablePaging64.S
@@ -0,0 +1,66 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# DisablePaging64.S
+#
+# Abstract:
+#
+# AsmDisablePaging64 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# InternalX86DisablePaging64 (
+# IN UINT16 Cs, %rdi
+# IN UINT64 EntryPoint, %rsi
+# IN UINT64 Context1, OPTIONAL %rdx
+# IN UINT32 Context2, OPTIONAL %rcx
+# IN UINT64 NewStack %r8
+# );
+#------------------------------------------------------------------------------
+
+.global _InternalX86DisablePaging64
+_InternalX86DisablePaging64:
+ cli
+ shl $0x20,%rcx
+ lea (%rip), %eax
+ mov %eax,%ecx
+ push %rcx
+ mov %edx,%ebx
+ mov %r8d,%esi
+ mov %r9d,%edi
+ mov 0x28(%rsp),%eax
+ lret
+L1:
+ mov %eax,%esp
+ mov %cr0,%rax
+ btr $0x1f,%eax
+ mov %rax,%cr0
+ mov $0xc0000080,%ecx
+ rdmsr
+ and $0xfe,%ah
+ wrmsr
+ mov %cr4,%rax
+ and $0xdf,%al
+ mov %rax,%cr4
+ push %rdi
+ push %rsi
+ callq *%rbx
+ jmp .
+
diff --git a/MdePkg/Library/BaseLib/X64/EnableDisableInterrupts.S b/MdePkg/Library/BaseLib/X64/EnableDisableInterrupts.S
new file mode 100644
index 0000000000..581b7bb345
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/EnableDisableInterrupts.S
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# EnableDisableInterrupts.S
+#
+# Abstract:
+#
+# EnableDisableInterrupts function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# EnableDisableInterrupts (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _EnableDisableInterrupts;
+.align 16;
+_EnableDisableInterrupts:
+ sti
+ cli
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/EnableInterrupts.S b/MdePkg/Library/BaseLib/X64/EnableInterrupts.S
new file mode 100644
index 0000000000..b81bcd0747
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/EnableInterrupts.S
@@ -0,0 +1,35 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# EnableInterrupts.S
+#
+# Abstract:
+#
+# EnableInterrupts function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# EnableInterrupts (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _EnableInterrupts;
+_EnableInterrupts:
+ sti
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/EnablePaging64.S b/MdePkg/Library/BaseLib/X64/EnablePaging64.S
new file mode 100644
index 0000000000..15209c0030
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/EnablePaging64.S
@@ -0,0 +1,61 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# EnablePaging64.S
+#
+# Abstract:
+#
+# AsmEnablePaging64 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# InternalX86EnablePaging64 (
+# IN UINT16 Cs, %rdi
+# IN UINT64 EntryPoint, %rsi
+# IN UINT64 Context1, OPTIONAL %rdx
+# IN UINT64 Context2, OPTIONAL %rcx
+# IN UINT64 NewStack %r8
+# );
+#------------------------------------------------------------------------------
+.global _InternalX86EnablePaging64;
+_InternalX86EnablePaging64:
+ cli
+ pop %rax
+ callq Base
+Base:
+ addl $(L1-Base),(%rsp)
+ mov %cr4,%rax
+ or $0x20,%al
+ mov %rax,%cr4
+ mov $0xc0000080,%ecx
+ rdmsr
+ or $0x1,%ah
+ wrmsr
+ mov %cr0,%rax
+ bts $0x1f,%eax
+ mov %rax,%cr0
+ lret
+L1:
+ addr32 mov (%esp),%rbx
+ addr32 mov 0x8(%esp),%rcx
+ addr32 mov 0x10(%esp),%rdx
+ addr32 mov 0x18(%esp),%rsp
+ add $-0x20,%rsp
+ callq *%rbx
+ jmp .
diff --git a/MdePkg/Library/BaseLib/X64/FlushCacheLine.S b/MdePkg/Library/BaseLib/X64/FlushCacheLine.S
new file mode 100644
index 0000000000..4c5a52fbf5
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/FlushCacheLine.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# FlushCacheLine.S
+#
+# Abstract:
+#
+# AsmFlushCacheLine function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID *
+# EFIAPI
+# AsmFlushCacheLine (
+# IN VOID *LinearAddress
+# );
+#------------------------------------------------------------------------------
+.global _AsmFlushCacheLine;
+_AsmFlushCacheLine:
+ clflush (%rdi)
+ mov %rdi, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/FxRestore.S b/MdePkg/Library/BaseLib/X64/FxRestore.S
new file mode 100644
index 0000000000..cc9750c57c
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/FxRestore.S
@@ -0,0 +1,35 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# FxRestore.S
+#
+# Abstract:
+#
+# AsmFxRestore function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# InternalX86FxRestore (
+# IN CONST IA32_FX_BUFFER *Buffer
+# )#
+#------------------------------------------------------------------------------
+.global _InternalX86FxRestore;
+_InternalX86FxRestore:
+ fxrstor (%rcx)
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/FxSave.S b/MdePkg/Library/BaseLib/X64/FxSave.S
new file mode 100644
index 0000000000..432d7b9c13
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/FxSave.S
@@ -0,0 +1,35 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# FxSave.S
+#
+# Abstract:
+#
+# AsmFxSave function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# InternalX86FxSave (
+# OUT IA32_FX_BUFFER *Buffer
+# );
+#------------------------------------------------------------------------------
+.global _InternalX86FxSave;
+_InternalX86FxSave:
+ fxsave (%rcx)
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/InterlockedCompareExchange32.S b/MdePkg/Library/BaseLib/X64/InterlockedCompareExchange32.S
new file mode 100644
index 0000000000..cd85279c73
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/InterlockedCompareExchange32.S
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# InterlockedCompareExchange32.Asm
+#
+# Abstract:
+#
+# InterlockedCompareExchange32 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+#------------------------------------------------------------------------------
+# UINT32
+# EFIAPI
+# InterlockedCompareExchange32 (
+# IN UINT32 *Value,
+# IN UINT32 CompareValue,
+# IN UINT32 ExchangeValue
+# );
+#------------------------------------------------------------------------------
+.global _InternalSyncCompareExchange32;
+_InternalSyncCompareExchange32:
+ mov %edx, %eax
+ lock cmpxchg %r8d, (%rcx)
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/InterlockedCompareExchange64.S b/MdePkg/Library/BaseLib/X64/InterlockedCompareExchange64.S
new file mode 100644
index 0000000000..ae27964292
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/InterlockedCompareExchange64.S
@@ -0,0 +1,39 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# InterlockedCompareExchange64.S
+#
+# Abstract:
+#
+# InterlockedCompareExchange64 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT64
+# EFIAPI
+# InterlockedCompareExchange64 (
+# IN UINT64 *Value,
+# IN UINT64 CompareValue,
+# IN UINT64 ExchangeValue
+# );
+#------------------------------------------------------------------------------
+.global _InternalSyncCompareExchange64;
+.align 16;
+_InternalSyncCompareExchange64:
+ mov %rsi, %rax
+ lock cmpxchg %rdx,(%rdi)
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/InterlockedDecrement.S b/MdePkg/Library/BaseLib/X64/InterlockedDecrement.S
new file mode 100644
index 0000000000..59ca54bb9f
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/InterlockedDecrement.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# InterlockedDecrement.S
+#
+# Abstract:
+#
+# InterlockedDecrement function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT32
+# EFIAPI
+# InterlockedDecrement (
+# IN UINT32 *Value
+# );
+#------------------------------------------------------------------------------
+.global _InternalSyncDecrement;
+_InternalSyncDecrement:
+ lock decl (%rcx)
+ mov (%rcx), %eax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/InterlockedIncrement.S b/MdePkg/Library/BaseLib/X64/InterlockedIncrement.S
new file mode 100644
index 0000000000..df4cb974b6
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/InterlockedIncrement.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# InterlockedIncrement.S
+#
+# Abstract:
+#
+# InterlockedIncrement function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT32
+# EFIAPI
+# InterlockedIncrement (
+# IN UINT32 *Value
+# );
+#------------------------------------------------------------------------------
+.global _InternalSyncIncrement;
+_InternalSyncIncrement:
+ lock incl (%rcx)
+ mov (%rcx), %eax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/Invd.S b/MdePkg/Library/BaseLib/X64/Invd.S
new file mode 100644
index 0000000000..030ae454e6
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/Invd.S
@@ -0,0 +1,35 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# Invd.S
+#
+# Abstract:
+#
+# AsmInvd function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# AsmInvd (
+# VOID
+# )#
+#------------------------------------------------------------------------------
+.global _AsmInvd;
+_AsmInvd:
+ invd
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/LongJump.S b/MdePkg/Library/BaseLib/X64/LongJump.S
new file mode 100644
index 0000000000..1a6f859c8e
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/LongJump.S
@@ -0,0 +1,42 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# LongJump.Asm
+#
+# Abstract:
+#
+# Implementation of _LongJump() on x64.
+#
+#------------------------------------------------------------------------------
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# InternalLongJump (
+# IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,
+# IN UINTN Value
+# );
+#------------------------------------------------------------------------------
+.global _InternalLongJump
+_InternalLongJump:
+ mov (%rcx), %rbx
+ mov 0x8(%rcx), %rsp
+ mov 0x10(%rcx), %rbp
+ mov 0x18(%rcx), %rdi
+ mov 0x20(%rcx), %rsi
+ mov 0x28(%rcx), %r12
+ mov 0x30(%rcx), %r13
+ mov 0x38(%rcx), %r14
+ mov 0x40(%rcx), %r15
+ mov %rdx, %rax
+ jmp *0x48(%rcx)
diff --git a/MdePkg/Library/BaseLib/X64/Monitor.S b/MdePkg/Library/BaseLib/X64/Monitor.S
new file mode 100644
index 0000000000..13da27d8ad
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/Monitor.S
@@ -0,0 +1,41 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# Monitor.S
+#
+# Abstract:
+#
+# AsmMonitor function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT64
+# EFIAPI
+# AsmMonitor (
+# IN UINTN Eax,
+# IN UINTN Ecx,
+# IN UINTN Edx
+# );
+#------------------------------------------------------------------------------
+.global _AsmMonitor;
+.align 16;
+_AsmMonitor:
+ mov %ecx,%eax
+ mov %edx,%ecx
+ mov %r8d,%edx
+ monitor
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/Mwait.S b/MdePkg/Library/BaseLib/X64/Mwait.S
new file mode 100644
index 0000000000..a32d004a18
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/Mwait.S
@@ -0,0 +1,39 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# Mwait.S
+#
+# Abstract:
+#
+# AsmMwait function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT64
+# EFIAPI
+# AsmMwait (
+# IN UINTN Eax,
+# IN UINTN Ecx
+# );
+#------------------------------------------------------------------------------
+.global _AsmMwait;
+.align 16;
+_AsmMwait:
+ mov %ecx,%eax
+ mov %edx,%ecx
+ mwait %rax,%rcx
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadCr0.S b/MdePkg/Library/BaseLib/X64/ReadCr0.S
new file mode 100644
index 0000000000..fa916d09fb
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadCr0.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadCr0.S
+#
+# Abstract:
+#
+# AsmReadCr0 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmReadCr0 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadCr0;
+.align 16;
+_AsmReadCr0:
+ mov %cr0, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadCr2.S b/MdePkg/Library/BaseLib/X64/ReadCr2.S
new file mode 100644
index 0000000000..96361bef72
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadCr2.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadCr2.S
+#
+# Abstract:
+#
+# AsmReadCr2 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmReadCr2 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadCr2;
+.align 16;
+_AsmReadCr2:
+ mov %cr2, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadCr3.S b/MdePkg/Library/BaseLib/X64/ReadCr3.S
new file mode 100644
index 0000000000..480486f093
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadCr3.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadCr3.S
+#
+# Abstract:
+#
+# AsmReadCr3 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmReadCr3 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadCr3;
+.align 16;
+_AsmReadCr3:
+ mov %cr3, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadCr4.S b/MdePkg/Library/BaseLib/X64/ReadCr4.S
new file mode 100644
index 0000000000..e89b5cdab6
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadCr4.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadCr4.S
+#
+# Abstract:
+#
+# AsmReadCr4 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmReadCr4 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadCr4;
+.align 16;
+_AsmReadCr4:
+ mov %cr4, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadCs.S b/MdePkg/Library/BaseLib/X64/ReadCs.S
new file mode 100644
index 0000000000..677747b813
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadCs.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadCs.S
+#
+# Abstract:
+#
+# AsmReadCs function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT16
+# EFIAPI
+# AsmReadCs (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadCs;
+.align 16;
+_AsmReadCs:
+ mov %cs, %eax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadDr0.S b/MdePkg/Library/BaseLib/X64/ReadDr0.S
new file mode 100644
index 0000000000..1b441c344d
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadDr0.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadDr0.S
+#
+# Abstract:
+#
+# AsmReadDr0 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmReadDr0 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadDr0;
+.align 16;
+_AsmReadDr0:
+ mov %dr0, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadDr1.S b/MdePkg/Library/BaseLib/X64/ReadDr1.S
new file mode 100644
index 0000000000..5151a80d9c
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadDr1.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadDr1.S
+#
+# Abstract:
+#
+# AsmReadDr1 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmReadDr1 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadDr1;
+.align 16;
+_AsmReadDr1:
+ mov %dr1, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadDr2.S b/MdePkg/Library/BaseLib/X64/ReadDr2.S
new file mode 100644
index 0000000000..f4516afd4d
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadDr2.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadDr2.S
+#
+# Abstract:
+#
+# AsmReadDr2 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmReadDr2 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadDr2;
+.align 16;
+_AsmReadDr2:
+ mov %dr2, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadDr3.S b/MdePkg/Library/BaseLib/X64/ReadDr3.S
new file mode 100644
index 0000000000..c5c679c96e
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadDr3.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadDr3.S
+#
+# Abstract:
+#
+# AsmReadDr3 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmReadDr3 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadDr3;
+.align 16;
+_AsmReadDr3:
+ mov %dr3, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadDr4.S b/MdePkg/Library/BaseLib/X64/ReadDr4.S
new file mode 100644
index 0000000000..f98c9ed35d
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadDr4.S
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadDr4.S
+#
+# Abstract:
+#
+# AsmReadDr4 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmReadDr4 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadDr4;
+.align 16;
+_AsmReadDr4:
+ #DB 0fh, 21h, 0e0h
+ mov %dr4, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadDr5.S b/MdePkg/Library/BaseLib/X64/ReadDr5.S
new file mode 100644
index 0000000000..421f57a418
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadDr5.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadDr5.S
+#
+# Abstract:
+#
+# AsmReadDr5 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmReadDr5 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadDr5;
+.align 16;
+_AsmReadDr5:
+ mov %dr5, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadDr6.S b/MdePkg/Library/BaseLib/X64/ReadDr6.S
new file mode 100644
index 0000000000..6a159d8762
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadDr6.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadDr6.S
+#
+# Abstract:
+#
+# AsmReadDr6 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmReadDr6 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadDr6;
+.align 16;
+_AsmReadDr6:
+ mov %dr6, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadDr7.S b/MdePkg/Library/BaseLib/X64/ReadDr7.S
new file mode 100644
index 0000000000..9ffb09d13a
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadDr7.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadDr7.S
+#
+# Abstract:
+#
+# AsmReadDr7 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmReadDr7 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadDr7;
+.align 16;
+_AsmReadDr7:
+ mov %dr7, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadDs.S b/MdePkg/Library/BaseLib/X64/ReadDs.S
new file mode 100644
index 0000000000..58bee11beb
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadDs.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadDs.S
+#
+# Abstract:
+#
+# AsmReadDs function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT16
+# EFIAPI
+# AsmReadDs (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadDs;
+.align 16;
+_AsmReadDs:
+ movl %ds, %eax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadEflags.S b/MdePkg/Library/BaseLib/X64/ReadEflags.S
new file mode 100644
index 0000000000..e895387673
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadEflags.S
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadEflags.S
+#
+# Abstract:
+#
+# AsmReadEflags function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmReadEflags (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadEflags;
+.align 16;
+_AsmReadEflags:
+ pushfq
+ pop %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadEs.S b/MdePkg/Library/BaseLib/X64/ReadEs.S
new file mode 100644
index 0000000000..93df650371
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadEs.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadEs.S
+#
+# Abstract:
+#
+# AsmReadEs function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT16
+# EFIAPI
+# AsmReadEs (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadEs;
+.align 16;
+_AsmReadEs:
+ mov %es, %eax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadFs.S b/MdePkg/Library/BaseLib/X64/ReadFs.S
new file mode 100644
index 0000000000..ff658e1248
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadFs.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadFs.S
+#
+# Abstract:
+#
+# AsmReadFs function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT16
+# EFIAPI
+# AsmReadFs (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadFs;
+.align 16;
+_AsmReadFs:
+ mov %fs, %eax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadGdtr.S b/MdePkg/Library/BaseLib/X64/ReadGdtr.S
new file mode 100644
index 0000000000..c271a02d78
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadGdtr.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadGdtr.S
+#
+# Abstract:
+#
+# AsmReadGdtr function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# InternalX86ReadGdtr (
+# OUT IA32_DESCRIPTOR *Gdtr
+# );
+#------------------------------------------------------------------------------
+.global _InternalX86ReadGdtr;
+.align 16;
+_InternalX86ReadGdtr:
+ sgdt (%rcx)
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadGs.S b/MdePkg/Library/BaseLib/X64/ReadGs.S
new file mode 100644
index 0000000000..f92776c35d
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadGs.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadGs.S
+#
+# Abstract:
+#
+# AsmReadGs function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT16
+# EFIAPI
+# AsmReadGs (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadGs;
+.align 16;
+_AsmReadGs:
+ mov %gs, %eax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadIdtr.S b/MdePkg/Library/BaseLib/X64/ReadIdtr.S
new file mode 100644
index 0000000000..cd7c09e6b7
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadIdtr.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadIdtr.AS
+#
+# Abstract:
+#
+# AsmReadIdtr function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# InternalX86ReadIdtr (
+# OUT IA32_DESCRIPTOR *Idtr
+# );
+#------------------------------------------------------------------------------
+.global _InternalX86ReadIdtr;
+.align 16;
+_InternalX86ReadIdtr:
+ sidt (%rcx)
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadLdtr.S b/MdePkg/Library/BaseLib/X64/ReadLdtr.S
new file mode 100644
index 0000000000..fac8e25d74
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadLdtr.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadLdtr.AS
+#
+# Abstract:
+#
+# AsmReadLdtr function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT16
+# EFIAPI
+# AsmReadLdtr (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadLdtr;
+.align 16;
+_AsmReadLdtr:
+ sldt %eax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadMm0.S b/MdePkg/Library/BaseLib/X64/ReadMm0.S
new file mode 100644
index 0000000000..b5912ca0b4
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadMm0.S
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadMm0.S
+#
+# Abstract:
+#
+# AsmReadMm0 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT64
+# EFIAPI
+# AsmReadMm0 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadMm0;
+.align 16;
+_AsmReadMm0:
+ #DB 48h, 0fh, 7eh, 0c0h
+ movd %mm0, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadMm1.S b/MdePkg/Library/BaseLib/X64/ReadMm1.S
new file mode 100644
index 0000000000..1f26cd4483
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadMm1.S
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadMm1.S
+#
+# Abstract:
+#
+# AsmReadMm1 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT64
+# EFIAPI
+# AsmReadMm1 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadMm1;
+.align 16;
+_AsmReadMm1:
+ #DB 48h, 0fh, 7eh, 0c8h
+ movd %mm1, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadMm2.S b/MdePkg/Library/BaseLib/X64/ReadMm2.S
new file mode 100644
index 0000000000..ef864af090
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadMm2.S
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadMm2.S
+#
+# Abstract:
+#
+# AsmReadMm2 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT64
+# EFIAPI
+# AsmReadMm2 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadMm2;
+.align 16;
+_AsmReadMm2:
+ #DB 48h, 0fh, 7eh, 0d0h
+ movd %mm2, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadMm3.S b/MdePkg/Library/BaseLib/X64/ReadMm3.S
new file mode 100644
index 0000000000..bd76cb20a2
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadMm3.S
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadMm3.S
+#
+# Abstract:
+#
+# AsmReadMm3 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT64
+# EFIAPI
+# AsmReadMm3 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadMm3;
+.align 16;
+_AsmReadMm3:
+ #DB 48h, 0fh, 7eh, 0d8h
+ movd %mm3, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadMm4.S b/MdePkg/Library/BaseLib/X64/ReadMm4.S
new file mode 100644
index 0000000000..99d766887c
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadMm4.S
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadMm4.AS
+#
+# Abstract:
+#
+# AsmReadMm4 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT64
+# EFIAPI
+# AsmReadMm4 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadMm4;
+.align 16;
+_AsmReadMm4:
+ #DB 48h, 0fh, 7eh, 0e0h
+ movd %mm4, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadMm5.S b/MdePkg/Library/BaseLib/X64/ReadMm5.S
new file mode 100644
index 0000000000..7a01c53ca5
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadMm5.S
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadMm5.S
+#
+# Abstract:
+#
+# AsmReadMm5 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT64
+# EFIAPI
+# AsmReadMm5 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadMm5;
+.align 16;
+_AsmReadMm5:
+ #DB 48h, 0fh, 7eh, 0e8h
+ movd %mm5, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadMm6.S b/MdePkg/Library/BaseLib/X64/ReadMm6.S
new file mode 100644
index 0000000000..0c7ea79858
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadMm6.S
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadMm6.S
+#
+# Abstract:
+#
+# AsmReadMm6 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT64
+# EFIAPI
+# AsmReadMm6 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadMm6;
+.align 16;
+_AsmReadMm6:
+ #DB 48h, 0fh, 7eh, 0f0h
+ movd %mm6, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadMm7.S b/MdePkg/Library/BaseLib/X64/ReadMm7.S
new file mode 100644
index 0000000000..68f1dbdd30
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadMm7.S
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadMm7.S
+#
+# Abstract:
+#
+# AsmReadMm7 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT64
+# EFIAPI
+# AsmReadMm7 (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadMm7;
+.align 16;
+_AsmReadMm7:
+ #DB 48h, 0fh, 7eh, 0f8h
+ movd %mm7, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadMsr64.S b/MdePkg/Library/BaseLib/X64/ReadMsr64.S
new file mode 100644
index 0000000000..ac101cd670
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadMsr64.S
@@ -0,0 +1,38 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadMsr64.S
+#
+# Abstract:
+#
+# AsmReadMsr64 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT64
+# EFIAPI
+# AsmReadMsr64 (
+# IN UINT32 Index
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadMsr64;
+.align 16;
+_AsmReadMsr64:
+ rdmsr # edx & eax are zero extended
+ shl $0x20, %rdx
+ or %rdx, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadPmc.S b/MdePkg/Library/BaseLib/X64/ReadPmc.S
new file mode 100644
index 0000000000..115f6335c7
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadPmc.S
@@ -0,0 +1,38 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadPmc.S
+#
+# Abstract:
+#
+# AsmReadPmc function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT64
+# EFIAPI
+# AsmReadPmc (
+# IN UINT32 PmcIndex
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadPmc;
+.align 16;
+_AsmReadPmc:
+ rdpmc
+ shl $0x20, %rdx
+ or %rdx, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadSs.S b/MdePkg/Library/BaseLib/X64/ReadSs.S
new file mode 100644
index 0000000000..a93a7032cf
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadSs.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadSs.S
+#
+# Abstract:
+#
+# AsmReadSs function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT16
+# EFIAPI
+# AsmReadSs (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadSs;
+.align 16;
+_AsmReadSs:
+ movl %ss, %eax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadTr.S b/MdePkg/Library/BaseLib/X64/ReadTr.S
new file mode 100644
index 0000000000..5e3146bf27
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadTr.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadTr.S
+#
+# Abstract:
+#
+# AsmReadTr function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT16
+# EFIAPI
+# AsmReadTr (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadTr;
+.align 16;
+_AsmReadTr:
+ str %eax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/ReadTsc.S b/MdePkg/Library/BaseLib/X64/ReadTsc.S
new file mode 100644
index 0000000000..776ffc2265
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/ReadTsc.S
@@ -0,0 +1,38 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# ReadTsc.S
+#
+# Abstract:
+#
+# AsmReadTsc function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT64
+# EFIAPI
+# AsmReadTsc (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmReadTsc;
+.align 16;
+_AsmReadTsc:
+ rdtsc
+ shl $0x20, %rdx
+ or %rdx, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/SetJump.S b/MdePkg/Library/BaseLib/X64/SetJump.S
new file mode 100644
index 0000000000..a88efcff3f
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/SetJump.S
@@ -0,0 +1,42 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# SetJump.S
+#
+# Abstract:
+#
+# Implementation of SetJump() on x86_64
+#
+#------------------------------------------------------------------------------
+
+.extern InternalAssertJumpBuffer;
+.global _SetJump;
+_SetJump:
+ push %rcx
+ add $0xffffffffffffffe0,%rsp
+ call InternalAssertJumpBuffer
+ add $0x20,%rsp
+ pop %rcx
+ pop %rdx
+ mov %rbx,(%rcx)
+ mov %rsp,0x8(%rcx)
+ mov %rbp,0x10(%rcx)
+ mov %rdi,0x18(%rcx)
+ mov %rsi,0x20(%rcx)
+ mov %r12,0x28(%rcx)
+ mov %r13,0x30(%rcx)
+ mov %r14,0x38(%rcx)
+ mov %r15,0x40(%rcx)
+ mov %rdx,0x48(%rcx)
+ xor %rax,%rax
+ jmpq *%rdx
diff --git a/MdePkg/Library/BaseLib/X64/SwitchStack.S b/MdePkg/Library/BaseLib/X64/SwitchStack.S
new file mode 100644
index 0000000000..85cdb4306d
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/SwitchStack.S
@@ -0,0 +1,44 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# SwitchStack.S
+#
+# Abstract:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# Routine Description:
+#
+# Routine for switching stacks with 1 parameter
+#
+# Arguments:
+#
+# (rdi) EntryPoint - Entry point with new stack.
+# (rsi) Context1 - Parameter1 for entry point.
+# (rdx) Context2 - Parameter2 for entry point.
+# (rcx) NewStack - Pointer to new stack.
+#
+# Returns:
+#
+# None
+#
+#------------------------------------------------------------------------------
+.global _InternalSwitchStack;
+_InternalSwitchStack:
+ mov %rcx, %rax
+ mov %rdx, %rcx
+ mov %r8, %rdx
+ lea -0x20(%r9), %rsp
+ call *%rax
diff --git a/MdePkg/Library/BaseLib/X64/Wbinvd.S b/MdePkg/Library/BaseLib/X64/Wbinvd.S
new file mode 100644
index 0000000000..a4b9704d2d
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/Wbinvd.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# Wbinvd.S
+#
+# Abstract:
+#
+# AsmWbinvd function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# AsmWbinvd (
+# VOID
+# );
+#------------------------------------------------------------------------------
+.global _AsmWbinvd;
+.align 16;
+_AsmWbinvd:
+ wbinvd
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteCr0.S b/MdePkg/Library/BaseLib/X64/WriteCr0.S
new file mode 100644
index 0000000000..f77dc815bf
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteCr0.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteCr0.S
+#
+# Abstract:
+#
+# AsmWriteCr0 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmWriteCr0 (
+# UINTN Cr0
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteCr0;
+_AsmWriteCr0:
+ mov %rcx,%cr0
+ mov %rcx,%rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteCr2.S b/MdePkg/Library/BaseLib/X64/WriteCr2.S
new file mode 100644
index 0000000000..66821616e1
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteCr2.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteCr2.S
+#
+# Abstract:
+#
+# AsmWriteCr2 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmWriteCr2 (
+# UINTN Cr2
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteCr2;
+_AsmWriteCr0:
+ mov %rcx,%cr2
+ mov %rcx,%rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteCr3.S b/MdePkg/Library/BaseLib/X64/WriteCr3.S
new file mode 100644
index 0000000000..880ed9737b
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteCr3.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteCr3.S
+#
+# Abstract:
+#
+# AsmWriteCr3 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmWriteCr3 (
+# UINTN Cr3
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteCr3;
+_AsmWriteCr3:
+ mov %rcx,%cr3
+ mov %rcx,%rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteCr4.S b/MdePkg/Library/BaseLib/X64/WriteCr4.S
new file mode 100644
index 0000000000..046936352f
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteCr4.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteCr4.S
+#
+# Abstract:
+#
+# AsmWriteCr4 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmWriteCr4 (
+# UINTN Cr4
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteCr4;
+_AsmWriteCr4:
+ mov %rcx,%cr4
+ mov %rcx,%rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteDr0.S b/MdePkg/Library/BaseLib/X64/WriteDr0.S
new file mode 100644
index 0000000000..080e56aeb5
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteDr0.S
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteDr0.S
+#
+# Abstract:
+#
+# AsmWriteDr0 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmWriteDr0 (
+# UINTN Value
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteDr0;
+.align 16;
+_AsmWriteDr0:
+ mov %rcx, %dr0
+ mov %rcx, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteDr1.S b/MdePkg/Library/BaseLib/X64/WriteDr1.S
new file mode 100644
index 0000000000..af61b68e88
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteDr1.S
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteDr1.S
+#
+# Abstract:
+#
+# AsmWriteDr1 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmWriteDr1 (
+# UINTN Value
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteDr1;
+.align 16;
+_AsmWriteDr1:
+ mov %rcx, %dr1
+ mov %rcx, rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteDr2.S b/MdePkg/Library/BaseLib/X64/WriteDr2.S
new file mode 100644
index 0000000000..a9e5369175
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteDr2.S
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteDr2.S
+#
+# Abstract:
+#
+# AsmWriteDr2 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmWriteDr2 (
+# UINTN Value
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteDr2;
+.align 16;
+_AsmWriteDr2:
+ mov %rcx, %dr2
+ mov %rcx, rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteDr3.S b/MdePkg/Library/BaseLib/X64/WriteDr3.S
new file mode 100644
index 0000000000..04017cc886
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteDr3.S
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteDr3.S
+#
+# Abstract:
+#
+# AsmWriteDr3 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmWriteDr3 (
+# UINTN Value
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteDr3;
+.align 16;
+_AsmWriteDr3:
+ mov %rcx, %dr3
+ mov %rcx, rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteDr4.S b/MdePkg/Library/BaseLib/X64/WriteDr4.S
new file mode 100644
index 0000000000..b6b4e7821c
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteDr4.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteDr4.S
+#
+# Abstract:
+#
+# AsmWriteDr4 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmWriteDr4 (
+# IN UINTN Value
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteDr4;
+_AsmWriteDr4:
+ mov %rcx, %dr4
+ mov %rcx, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteDr5.S b/MdePkg/Library/BaseLib/X64/WriteDr5.S
new file mode 100644
index 0000000000..7539095890
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteDr5.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteDr5.S
+#
+# Abstract:
+#
+# AsmWriteDr5 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmWriteDr5 (
+# IN UINTN Value
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteDr5;
+_AsmWriteDr5:
+ mov %rcx, %dr5
+ mov %rcx, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteDr6.S b/MdePkg/Library/BaseLib/X64/WriteDr6.S
new file mode 100644
index 0000000000..862726079e
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteDr6.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteDr6.S
+#
+# Abstract:
+#
+# AsmWriteDr6 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmWriteDr6 (
+# IN UINTN Value
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteDr6;
+_AsmWriteDr6:
+ mov %rcx, %dr6
+ mov %rcx, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteDr7.S b/MdePkg/Library/BaseLib/X64/WriteDr7.S
new file mode 100644
index 0000000000..8699d9536f
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteDr7.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteDr7.S
+#
+# Abstract:
+#
+# AsmWriteDr7 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINTN
+# EFIAPI
+# AsmWriteDr7 (
+# IN UINTN Value
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteDr7;
+_AsmWriteDr7:
+ mov %rcx, %dr7
+ mov %rcx, %rax
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteGdtr.S b/MdePkg/Library/BaseLib/X64/WriteGdtr.S
new file mode 100644
index 0000000000..1e9d84b426
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteGdtr.S
@@ -0,0 +1,35 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteGdtr.S
+#
+# Abstract:
+#
+# AsmWriteGdtr function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# InternalX86WriteGdtr (
+# IN CONST IA32_DESCRIPTOR *Idtr
+# );
+#------------------------------------------------------------------------------
+.global _InternalX86WriteGdtr;
+_InternalX86WriteGdtr:
+ lgdt (%rcx)
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteIdtr.S b/MdePkg/Library/BaseLib/X64/WriteIdtr.S
new file mode 100644
index 0000000000..feb085ff58
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteIdtr.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteIdtr.S
+#
+# Abstract:
+#
+# AsmWriteIdtr function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# InternalX86WriteIdtr (
+# IN CONST IA32_DESCRIPTOR *Idtr
+# );
+#------------------------------------------------------------------------------
+.global _InternalX86WriteIdtr;
+.align 16;
+_InternalX86WriteIdtr:
+ lidt (%rcx)
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteLdtr.S b/MdePkg/Library/BaseLib/X64/WriteLdtr.S
new file mode 100644
index 0000000000..c07ab831f9
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteLdtr.S
@@ -0,0 +1,36 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteLdtr.S
+#
+# Abstract:
+#
+# AsmWriteLdtr function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# AsmWriteLdtr (
+# IN UINT16 Ldtr
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteLdtr;
+.align 16;
+_AsmWriteLdtr:
+ lldt %cx
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteMm0.S b/MdePkg/Library/BaseLib/X64/WriteMm0.S
new file mode 100644
index 0000000000..2d805a14dc
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteMm0.S
@@ -0,0 +1,35 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteMm0.S
+#
+# Abstract:
+#
+# AsmWriteMm0 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# AsmWriteMm0 (
+# IN UINT64 Value
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteMm0;
+_AsmWriteMm0:
+ movd %rcx, %xmm0
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteMm1.S b/MdePkg/Library/BaseLib/X64/WriteMm1.S
new file mode 100644
index 0000000000..ff8162e727
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteMm1.S
@@ -0,0 +1,35 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteMm1.S
+#
+# Abstract:
+#
+# AsmWriteMm1 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# AsmWriteMm1 (
+# IN UINT64 Value
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteMm1;
+_AsmWriteMm1:
+ movd %rcx, %mm1
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteMm2.S b/MdePkg/Library/BaseLib/X64/WriteMm2.S
new file mode 100644
index 0000000000..a98e73650c
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteMm2.S
@@ -0,0 +1,35 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteMm2.S
+#
+# Abstract:
+#
+# AsmWriteMm2 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# AsmWriteMm2 (
+# IN UINT64 Value
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteMm2;
+_AsmWriteMm2:
+ movd %rcx, %mm2
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteMm3.S b/MdePkg/Library/BaseLib/X64/WriteMm3.S
new file mode 100644
index 0000000000..81561e3594
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteMm3.S
@@ -0,0 +1,35 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteMm3.S
+#
+# Abstract:
+#
+# AsmWriteMm3 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# AsmWriteMm3 (
+# IN UINT64 Value
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteMm3;
+_AsmWriteMm3:
+ movd %rcx, %mm3
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteMm4.S b/MdePkg/Library/BaseLib/X64/WriteMm4.S
new file mode 100644
index 0000000000..124d946dde
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteMm4.S
@@ -0,0 +1,35 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteMm4.S
+#
+# Abstract:
+#
+# AsmWriteMm4 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# AsmWriteMm4 (
+# IN UINT64 Value
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteMm4;
+_AsmWriteMm4:
+ movd %rcx, %mm4
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteMm5.S b/MdePkg/Library/BaseLib/X64/WriteMm5.S
new file mode 100644
index 0000000000..0935ddc0b1
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteMm5.S
@@ -0,0 +1,35 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteMm5.S
+#
+# Abstract:
+#
+# AsmWriteMm5 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# AsmWriteMm5 (
+# IN UINT64 Value
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteMm5;
+_AsmWriteMm5:
+ movd %rcx, %mm5
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteMm6.S b/MdePkg/Library/BaseLib/X64/WriteMm6.S
new file mode 100644
index 0000000000..02b50cf055
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteMm6.S
@@ -0,0 +1,35 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteMm6.S
+#
+# Abstract:
+#
+# AsmWriteMm6 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# AsmWriteMm6 (
+# IN UINT64 Value
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteMm6;
+_AsmWriteMm6:
+ movd %rcx, %mm6
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteMm7.S b/MdePkg/Library/BaseLib/X64/WriteMm7.S
new file mode 100644
index 0000000000..60292721e8
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteMm7.S
@@ -0,0 +1,35 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteMm7.S
+#
+# Abstract:
+#
+# AsmWriteMm7 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# AsmWriteMm7 (
+# IN UINT64 Value
+# );
+#------------------------------------------------------------------------------
+.global _AsmWriteMm7;
+_AsmWriteMm7:
+ movd %rcx, %mm7
+ ret
diff --git a/MdePkg/Library/BaseLib/X64/WriteMsr64.S b/MdePkg/Library/BaseLib/X64/WriteMsr64.S
new file mode 100644
index 0000000000..88ff48bf26
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/WriteMsr64.S
@@ -0,0 +1,40 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# WriteMsr64.S
+#
+# Abstract:
+#
+# AsmWriteMsr64 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# UINT64
+# EFIAPI
+# AsmWriteMsr64 (
+# IN UINT32 Index,
+# IN UINT64 Value
+# );
+# TODO:
+#------------------------------------------------------------------------------
+.global _AsmWriteMsr64;
+.align 16;
+_AsmWriteMsr64:
+ mov %rdx, %rax
+ shr $0x20, %rdx
+ wrmsr
+ ret