Index: /trunk/include/iprt/asm-amd64-x86.h
===================================================================
--- /trunk/include/iprt/asm-amd64-x86.h	(revision 49844)
+++ /trunk/include/iprt/asm-amd64-x86.h	(revision 49845)
@@ -1767,4 +1767,80 @@
 
 /**
+ * Reads a machine specific register, extended version (for AMD).
+ *
+ * @returns Register content.
+ * @param   uRegister   Register to read.
+ * @param   uXDI        RDI/EDI value.
+ */
+#if RT_INLINE_ASM_EXTERNAL
+DECLASM(uint64_t) ASMRdMsrEx(uint32_t uRegister, RTCCUINTREG uXDI);
+#else
+DECLINLINE(uint64_t) ASMRdMsrEx(uint32_t uRegister, RTCCUINTREG uXDI)
+{
+    RTUINT64U u;
+# if RT_INLINE_ASM_GNU_STYLE
+    __asm__ __volatile__("rdmsr\n\t"
+                         : "=a" (u.s.Lo),
+                           "=d" (u.s.Hi)
+                         : "c" (uRegister),
+                           "D" (uXDI));
+
+# else
+    __asm
+    {
+        mov     ecx, [uRegister]
+        xchg    edi, [uXDI]
+        rdmsr
+        mov     [u.s.Lo], eax
+        mov     [u.s.Hi], edx
+        xchg    edi, [uXDI]
+    }
+# endif
+
+    return u.u;
+}
+#endif
+
+
+/**
+ * Writes a machine specific register, extended version (for AMD).
+ *
+ * @returns Register content.
+ * @param   uRegister   Register to write to.
+ * @param   uXDI        RDI/EDI value.
+ * @param   u64Val      Value to write.
+ */
+#if RT_INLINE_ASM_EXTERNAL
+DECLASM(void) ASMWrMsrEx(uint32_t uRegister, RTCCUINTREG uXDI, uint64_t u64Val);
+#else
+DECLINLINE(void) ASMWrMsrEx(uint32_t uRegister, RTCCUINTREG uXDI, uint64_t u64Val)
+{
+    RTUINT64U u;
+
+    u.u = u64Val;
+# if RT_INLINE_ASM_GNU_STYLE
+    __asm__ __volatile__("wrmsr\n\t"
+                         ::"a" (u.s.Lo),
+                           "d" (u.s.Hi),
+                           "c" (uRegister),
+                           "D" (uXDI));
+
+# else
+    __asm
+    {
+        mov     ecx, [uRegister]
+        xchg    edi, [uXDI]
+        mov     edx, [u.s.Hi]
+        mov     eax, [u.s.Lo]
+        wrmsr
+        xchg    edi, [uXDI]
+    }
+# endif
+}
+#endif
+
+
+
+/**
  * Reads low part of a machine specific register.
  *
Index: /trunk/src/VBox/Runtime/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Runtime/Makefile.kmk	(revision 49844)
+++ /trunk/src/VBox/Runtime/Makefile.kmk	(revision 49845)
@@ -538,5 +538,7 @@
 	common/asm/ASMAtomicUoAndU32.asm \
 	common/asm/ASMAtomicUoOrU64.asm \
-	common/asm/ASMAtomicUoOrU32.asm
+	common/asm/ASMAtomicUoOrU32.asm \
+	common/asm/ASMRdMsrEx.asm \
+	common/asm/ASMWrMsrEx.asm
 RuntimeR3_SOURCES.amd64 += \
 	common/asm/ASMCpuIdExSlow.asm \
@@ -544,5 +546,7 @@
 	common/asm/ASMAtomicUoAndU32.asm \
 	common/asm/ASMAtomicUoOrU64.asm \
-	common/asm/ASMAtomicUoOrU32.asm
+	common/asm/ASMAtomicUoOrU32.asm \
+	common/asm/ASMRdMsrEx.asm \
+	common/asm/ASMWrMsrEx.asm
 
 # Some versions of GCC might require this.
@@ -1664,5 +1668,7 @@
 	common/asm/ASMAtomicUoAndU32.asm \
 	common/asm/ASMAtomicUoOrU64.asm \
-	common/asm/ASMAtomicUoOrU32.asm
+	common/asm/ASMAtomicUoOrU32.asm \
+	common/asm/ASMRdMsrEx.asm \
+	common/asm/ASMWrMsrEx.asm
 RuntimeR0_SOURCES.amd64 += \
 	common/asm/ASMCpuIdExSlow.asm \
@@ -1670,5 +1676,7 @@
 	common/asm/ASMAtomicUoAndU32.asm \
 	common/asm/ASMAtomicUoOrU64.asm \
-	common/asm/ASMAtomicUoOrU32.asm
+	common/asm/ASMAtomicUoOrU32.asm \
+	common/asm/ASMRdMsrEx.asm \
+	common/asm/ASMWrMsrEx.asm
 
 #if1of ($(KBUILD_TARGET_ARCH),amd64 x86)
@@ -1807,4 +1815,12 @@
 	r0drv/generic/semspinmutex-r0drv-generic.c \
 	VBox/log-vbox.cpp \
+
+RuntimeR0Drv_SOURCES.amd64 = \
+	common/asm/ASMRdMsrEx.asm \
+	common/asm/ASMWrMsrEx.asm
+RuntimeR0Drv_SOURCES.x86   = \
+	common/asm/ASMRdMsrEx.asm \
+	common/asm/ASMWrMsrEx.asm
+
 
 RuntimeR0Drv_SOURCES.linux = \
Index: /trunk/src/VBox/Runtime/common/asm/ASMRdMsrEx.asm
===================================================================
--- /trunk/src/VBox/Runtime/common/asm/ASMRdMsrEx.asm	(revision 49845)
+++ /trunk/src/VBox/Runtime/common/asm/ASMRdMsrEx.asm	(revision 49845)
@@ -0,0 +1,78 @@
+; $Id$
+;; @file
+; IPRT - ASMRdMsrEx().
+;
+
+;
+; Copyright (C) 2013 Oracle Corporation
+;
+; This file is part of VirtualBox Open Source Edition (OSE), as
+; available from http://www.virtualbox.org. This file is free software;
+; you can redistribute it and/or modify it under the terms of the GNU
+; General Public License (GPL) as published by the Free Software
+; Foundation, in version 2 as it comes in the "COPYING" file of the
+; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+;
+; The contents of this file may alternatively be used under the terms
+; of the Common Development and Distribution License Version 1.0
+; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+; VirtualBox OSE distribution, in which case the provisions of the
+; CDDL are applicable instead of those of the GPL.
+;
+; You may elect to license modified versions of this file under the
+; terms and conditions of either the GPL or the CDDL or both.
+;
+
+;*******************************************************************************
+;* Header Files                                                                *
+;*******************************************************************************
+%include "iprt/asmdefs.mac"
+
+BEGINCODE
+
+;;
+; Special version of ASMRdMsr that allow specifying the rdi value.
+;
+; @param    uMsr    msc=rcx, gcc=rdi, x86=[ebp+8]   The MSR to read.
+; @param    uEdi    msc=rdx, gcc=rsi, x86=[ebp+12]  The EDI/RDI value.
+; @returns  MSR value in rax on amd64 and edx:eax on x86.
+;
+BEGINPROC_EXPORTED ASMRdMsrEx
+%ifdef ASM_CALL64_MSC
+proc_frame ASMRdMsrEx_DupWarningHack
+        push    rdi
+        [pushreg rdi]
+[endprolog]
+        and     ecx, 0ffffffffh         ; serious paranoia
+        mov     rdi, rdx
+        xor     eax, eax
+        xor     edx, edx
+        rdmsr
+        pop     rdi
+        ret
+endproc_frame
+%elifdef ASM_CALL64_GCC
+        mov     ecx, edi
+        mov     rdi, rsi
+        xor     eax, eax
+        xor     edx, edx
+        rdmsr
+        ret
+%elifdef RT_ARCH_X86
+        push    ebp
+        mov     ebp, esp
+        push    edi
+        xor     eax, eax
+        xor     edx, edx
+        mov     ecx, [ebp + 8]
+        mov     edi, [esp + 12]
+        rdmsr
+        pop     edi
+        leave
+        ret
+%else
+ %error "Undefined arch?"
+%endif
+ENDPROC ASMRdMsrEx
+
Index: /trunk/src/VBox/Runtime/common/asm/ASMWrMsrEx.asm
===================================================================
--- /trunk/src/VBox/Runtime/common/asm/ASMWrMsrEx.asm	(revision 49845)
+++ /trunk/src/VBox/Runtime/common/asm/ASMWrMsrEx.asm	(revision 49845)
@@ -0,0 +1,79 @@
+; $Id$
+;; @file
+; IPRT - ASMWrMsrEx().
+;
+
+;
+; Copyright (C) 2013 Oracle Corporation
+;
+; This file is part of VirtualBox Open Source Edition (OSE), as
+; available from http://www.virtualbox.org. This file is free software;
+; you can redistribute it and/or modify it under the terms of the GNU
+; General Public License (GPL) as published by the Free Software
+; Foundation, in version 2 as it comes in the "COPYING" file of the
+; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+;
+; The contents of this file may alternatively be used under the terms
+; of the Common Development and Distribution License Version 1.0
+; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+; VirtualBox OSE distribution, in which case the provisions of the
+; CDDL are applicable instead of those of the GPL.
+;
+; You may elect to license modified versions of this file under the
+; terms and conditions of either the GPL or the CDDL or both.
+;
+
+;*******************************************************************************
+;* Header Files                                                                *
+;*******************************************************************************
+%include "iprt/asmdefs.mac"
+
+BEGINCODE
+
+;;
+; Special version of ASMRdMsr that allow specifying the rdi value.
+;
+; @param    uMsr    msc=rcx, gcc=rdi, x86=[ebp+8]   The MSR to read.
+; @param    uXDI    msc=rdx, gcc=rsi, x86=[ebp+12]  The EDI/RDI value.
+; @param    uValue  msc=r8,  gcc=rdx, x86=[ebp+16]  The 64-bit value to write.
+;
+BEGINPROC_EXPORTED ASMWrMsrEx
+%ifdef ASM_CALL64_MSC
+proc_frame ASMWrMsrEx_DupWarningHack
+        push    rdi
+        [pushreg rdi]
+[endprolog]
+        and     ecx, 0ffffffffh         ; serious paranoia
+        mov     rdi, rdx
+        mov     eax, r8d
+        mov     rdx, r8
+        shr     rdx, 32
+        wrmsr
+        pop     rdi
+        ret
+endproc_frame
+%elifdef ASM_CALL64_GCC
+        mov     ecx, edi
+        mov     rdi, rsi
+        mov     eax, edx
+        shr     edx, 32
+        wrmsr
+        ret
+%elifdef RT_ARCH_X86
+        push    ebp
+        mov     ebp, esp
+        push    edi
+        mov     ecx, [ebp + 8]
+        mov     edi, [esp + 12]
+        mov     eax, [esp + 16]
+        mov     edx, [esp + 20]
+        wrmsr
+        pop     edi
+        leave
+        ret
+%else
+ %error "Undefined arch?"
+%endif
+ENDPROC ASMWrMsrEx
+
