Hello world
This is a piece of code use RDMSR from GCC inline assembler:
__asm__ __volatile__ ("rdmsr"
:"=a"(low), "=d"(high)
:"c"(msr));
I need to translate it to Visual C++ inline assembler, and I try it:
__asm
{
rdmsr
eax, low;
edx, high;
ecx, msr;
}
But I have this log:
Severity Code Description Project File Line Suppression State
Warning C4405 'eax': identifier is reserved word
Error C2400 inline assembler syntax error in 'opcode'; found ','
Warning C4405 'edx': identifier is reserved word
Error C2400 inline assembler syntax error in 'opcode'; found ','
Warning C4405 'ecx': identifier is reserved word
Error C2400 inline assembler syntax error in 'opcode'; found ','
I am newbie and I need help. Could you helpme please?
THX
You can't run RDMSR in user mode. It is a privileged instruction.
Given this, I don't need to tell you that eax, low is not an ASM instruction. May be you are thinking about mov eax, low.
thanks very much
QuoteYou can't run RDMSR in user mode. It is a privileged instruction.
I saw somewhere it, this instruction must be executed at a privilege level of 0, or in kernel mode. How to use so in this context?
QuoteGiven this, I don't need to tell you that eax, low is not an ASM instruction. May be you are thinking about mov eax, low.
If i understand, in GCC:
"=a"(low)
it's in VSC++ illine:
mov eax, low
Quote from: nonosto on January 11, 2018, 01:30:43 AMI saw somewhere it, this instruction must be executed at a privilege level of 0, or in kernel mode. How to use so in this context?
Write a driver, and it will work. Why do you need RDMSR?
THX.
I need patch kernel
That's possible by such way :
RDMSR EAX ; maybe AX - as it not go to opcode could be differ
MOV EAX, CR0 ; alternative for kernel
Thanks all
After your help I found this:
https://books.google.fr/books?id=5Cs46M9FV0sC&lpg=PA284&ots=pXHGJxvfIs&dq=RDMSR%20EAX%20%3B&hl=fr&pg=PA284#v=onepage&q=RDMSR%20EAX%20;&f=true (https://books.google.fr/books?id=5Cs46M9FV0sC&lpg=PA284&ots=pXHGJxvfIs&dq=RDMSR%20EAX%20%3B&hl=fr&pg=PA284#v=onepage&q=RDMSR%20EAX%20;&f=true)
(https://i62.servimg.com/u/f62/15/96/88/01/rdmsr10.png)
So I try this code:
__int64 rdmsr(__int32 msr, __int32* pHigh, __int32* pLow)
{
__int32 low, high;
__asm
{
mov msr, ecx;
rdmsr;
mov eax, low;
mov edx, high;
}
}
But I have this error:
Severity Code Description Project File Line Suppression State
Error C2400 inline assembler syntax error in 'second operand'; found 'newline' TEST_ASM
Error C2400 inline assembler syntax error in 'second operand'; found 'newline' TEST_ASM
> THX.
> I need patch kernel
Why the hell do you need to patch a 32 bit kernel ?
Answer this or the post will be removed and do not try and feed us bullsh*t.
I try to translate an application write on GCC inline to visual C++ 2003 for an old app (windows 2000).
It is a real pain to see what you are trying to do.
You should use the __readmsr intrinsics and forget about ASM for the time being.
intrinsic not support by VC 2003
All right, if you are looking to run it on Windows 2000 your options are diminished.
But if you have the Platform Toolset Visual Studio 2008 (v90) you can build it even on VS 2017.
Unlike I must use VS2003 only....it's a very specific hardware.
I dont see my error how to fix it please?
There are many errors, but the immediate ones are that "low" and "high" are keywords.
Thank you very much, now no error in LOG with this code:
__int64 rdmsr(__int32 msr, __int32* pHigh, __int32* pLow)
{
__int32 tlow, thigh;
__asm
{
mov ecx, msr;
rdmsr;
mov tlow, eax;
mov thigh, edx;
}
__int64 value = ((__int64)thigh << 32) | (__int64)tlow;
*pLow = tlow;
*pHigh = thigh;
return value;
}
Last question please, do you think that gives the same result as this especially the __volatile__ instruction:
uint64_t rdmsr(uint32_t msr, uint32_t* pHigh, uint32_t* pLow) {
uint32_t low, high;
__asm__ __volatile__ ("rdmsr"
:"=a"(low), "=d"(high)
:"c"(msr));
uint64_t value = ((uint64_t)high << 32) | (uint64_t)low;
*pLow = low;
*pHigh = high;
return value;
}
This should work as well (the return value is already in edx:eax):
__int64 rdmsr(unsigned _msr, __int32* pHigh, __int32* pLow)
{
__asm {
mov ecx, _msr
rdmsr
mov ecx, pHigh
mov [ecx], edx
mov ecx, pLow
mov [ecx],eax
leave
ret
}
}
THX very much. I will test it quickly.