Author Topic: RDMSR & inline assembler Visual Studio C++  (Read 1414 times)

nonosto

  • Regular Member
  • *
  • Posts: 26
RDMSR & inline assembler Visual Studio C++
« on: January 11, 2018, 01:02:24 AM »
Hello world

This is a piece of code use RDMSR from GCC inline assembler:

Code: [Select]
__asm__ __volatile__ ("rdmsr"
                        :"=a"(low), "=d"(high)
                        :"c"(msr));

I need to translate it to Visual C++ inline assembler, and I try it:

Code: [Select]
__asm
{
rdmsr
eax, low;
edx, high;
ecx, msr;
}

But I have this log:

Code: [Select]
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

AW

  • Member
  • *****
  • Posts: 1517
  • Let's Make ASM Great Again!
Re: RDMSR & inline assembler Visual Studio C++
« Reply #1 on: January 11, 2018, 01:21:40 AM »
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

  • Regular Member
  • *
  • Posts: 26
Re: RDMSR & inline assembler Visual Studio C++
« Reply #2 on: January 11, 2018, 01:30:43 AM »
thanks very much

Quote
You 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?

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

If i understand, in GCC:

Code: [Select]
"=a"(low)
it's in VSC++ illine:

Code: [Select]
mov eax, low

jj2007

  • Member
  • *****
  • Posts: 8773
  • Assembler is fun ;-)
    • MasmBasic
Re: RDMSR & inline assembler Visual Studio C++
« Reply #3 on: January 11, 2018, 01:37:24 AM »
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?

Write a driver, and it will work. Why do you need RDMSR?

nonosto

  • Regular Member
  • *
  • Posts: 26
Re: RDMSR & inline assembler Visual Studio C++
« Reply #4 on: January 11, 2018, 04:22:05 AM »
THX.
I need patch kernel

Adamanteus

  • Member
  • **
  • Posts: 205
    • LLC "AMS"
Re: RDMSR & inline assembler Visual Studio C++
« Reply #5 on: January 11, 2018, 06:06:54 AM »
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

  • Regular Member
  • *
  • Posts: 26
Re: RDMSR & inline assembler Visual Studio C++
« Reply #7 on: January 11, 2018, 11:11:45 AM »
So I try this code:

Code: [Select]
__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:

Code: [Select]
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--

  • Administrator
  • Member
  • ******
  • Posts: 5850
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: RDMSR & inline assembler Visual Studio C++
« Reply #8 on: January 11, 2018, 11:20:27 AM »
> 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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

nonosto

  • Regular Member
  • *
  • Posts: 26
Re: RDMSR & inline assembler Visual Studio C++
« Reply #9 on: January 11, 2018, 11:32:02 AM »
I try to translate an application write on GCC inline to visual C++ 2003 for an old app (windows 2000).


AW

  • Member
  • *****
  • Posts: 1517
  • Let's Make ASM Great Again!
Re: RDMSR & inline assembler Visual Studio C++
« Reply #10 on: January 11, 2018, 06:57:10 PM »
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

  • Regular Member
  • *
  • Posts: 26
Re: RDMSR & inline assembler Visual Studio C++
« Reply #11 on: January 12, 2018, 12:09:24 AM »
intrinsic not support by VC 2003

AW

  • Member
  • *****
  • Posts: 1517
  • Let's Make ASM Great Again!
Re: RDMSR & inline assembler Visual Studio C++
« Reply #12 on: January 12, 2018, 02:04:34 AM »
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

  • Regular Member
  • *
  • Posts: 26
Re: RDMSR & inline assembler Visual Studio C++
« Reply #13 on: January 12, 2018, 02:31:00 AM »
Unlike I must use VS2003 only....it's a very specific hardware.
I dont see my error how to fix it please?

AW

  • Member
  • *****
  • Posts: 1517
  • Let's Make ASM Great Again!
Re: RDMSR & inline assembler Visual Studio C++
« Reply #14 on: January 12, 2018, 02:58:34 AM »
There are many errors, but the immediate ones are that "low" and "high" are keywords.