Hi,
I want to read and write msr values from a kernel mode driver. Is there any specific routines I can do that ? Any sample code will help me a lot.
Hi,
I want to read and write msr values from a kernel mode driver. Is there any specific routines I can do that ? Any sample code will help me a lot.
There are MSVC intrinsics that do this:
http://msdn.microsoft.com/en-us/library/y55zyfdx(v=VS.100).aspx
http://msdn.microsoft.com/en-us/library/77c17dw7(v=VS.100).aspx
Good luck,
mm
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Wednesday, February 16, 2011 3:33 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Reading and Writing to a MSR in a driver
Hi,
I want to read and write msr values from a kernel mode driver. Is
there any specific routines I can do that ? Any sample code will help me a
lot.
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
How about ExIsProcessorFeaturePresent if it is appropriate?
http://msdn.microsoft.com/en-us/library/ff545442(VS.85).aspx
d
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Martin O’Brien
Sent: Wednesday, February 16, 2011 12:44 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Reading and Writing to a MSR in a driver
There are MSVC intrinsics that do this:
http://msdn.microsoft.com/en-us/library/y55zyfdx(v=VS.100).aspx
http://msdn.microsoft.com/en-us/library/77c17dw7(v=VS.100).aspx
Good luck,
mm
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Wednesday, February 16, 2011 3:33 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Reading and Writing to a MSR in a driver
Hi,
I want to read and write msr values from a kernel mode driver. Is there any specific routines I can do that ? Any sample code will help me a lot.
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
VOID ReadMsr( ULONG EcxReg, PULONG EaxReg, PULONG EdxReg ){
ULONG uEax=0, uEdx=0;
#ifdef _WIN64
#pragma message(“BUILD FOR AMD64”)
unsigned __int64 ull_ret=0;
ull_ret = __readmsr(EcxReg);
*EaxReg = (ULONG)ull_ret;
*EdxReg = (ULONG)(ull_ret >> 32);
#else
#pragma message(“BUILD FOR X86”)
_asm{
push eax
push edx
push ecx
xor eax, eax
xor edx, edx
xor ecx, ecx
mov ecx, EcxReg
rdmsr
mov uEax, eax
mov uEdx, edx
pop ecx
pop edx
pop eax
}
*EaxReg = uEax;
*EdxReg = uEdx;
#endif
} // ReadMsr
VOID WriteMsr( ULONG EcxReg, ULONG EaxReg, ULONG EdxReg ){
#ifndef _WIN64
_asm{
push eax
push edx
push ecx
mov eax, EaxReg
mov edx, EdxReg
mov ecx, EcxReg
wrmsr
pop ecx
pop edx
pop eax
}
#else
__int64 Data = ( EdxReg << 32 ) + EaxReg;
__writemsr( EcxReg, Data );
#endif
} // WriteMsr
Why would you even suggest this, when there is a documented, and supported way, of doing this that does not require using assembly?
Gary G. Little
----- Original Message -----
From: “d n kuzmenko”
To: “Windows System Software Devs Interest List”
Sent: Thursday, February 17, 2011 10:01:26 AM
Subject: RE:[ntdev] Reading and Writing to a MSR in a driver
VOID ReadMsr( ULONG EcxReg, PULONG EaxReg, PULONG EdxReg ){
ULONG uEax=0, uEdx=0;
#ifdef _WIN64
#pragma message(“BUILD FOR AMD64”)
unsigned int64 ull_ret=0;
ull_ret = readmsr(EcxReg);
*EaxReg = (ULONG)ull_ret;
*EdxReg = (ULONG)(ull_ret >> 32);
#else
#pragma message(“BUILD FOR X86”)
_asm{
push eax
push edx
push ecx
xor eax, eax
xor edx, edx
xor ecx, ecx
mov ecx, EcxReg
rdmsr
mov uEax, eax
mov uEdx, edx
pop ecx
pop edx
pop eax
}
*EaxReg = uEax;
*EdxReg = uEdx;
#endif
} // ReadMsr
VOID WriteMsr( ULONG EcxReg, ULONG EaxReg, ULONG EdxReg ){
#ifndef _WIN64
_asm{
push eax
push edx
push ecx
mov eax, EaxReg
mov edx, EdxReg
mov ecx, EcxReg
wrmsr
pop ecx
pop edx
pop eax
}
#else
__int64 Data = ( EdxReg << 32 ) + EaxReg;
__writemsr( EcxReg, Data );
#endif
} // WriteMsr
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer