News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

RDMSR & inline assembler Visual Studio C++

Started by nonosto, January 11, 2018, 01:02:24 AM

Previous topic - Next topic

nonosto

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

aw27

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.

nonosto

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

jj2007

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?

nonosto


Adamanteus

That's possible by such way :
Code (asm) Select

RDMSR EAX ; maybe AX - as it not go to opcode could be differ
MOV EAX, CR0 ; alternative for kernel


nonosto

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

hutch--

> 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.

nonosto

I try to translate an application write on GCC inline to visual C++ 2003 for an old app (windows 2000).


aw27

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.

nonosto


aw27

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.

nonosto

Unlike I must use VS2003 only....it's a very specific hardware.
I dont see my error how to fix it please?

aw27

There are many errors, but the immediate ones are that "low" and "high" are keywords.