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

nonosto

  • Regular Member
  • *
  • Posts: 11
Re: RDMSR & inline assembler Visual Studio C++
« Reply #15 on: January 12, 2018, 03:13:51 AM »
Thank you very much, now no error in LOG with this code:

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

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


aw27

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

nonosto

  • Regular Member
  • *
  • Posts: 11
Re: RDMSR & inline assembler Visual Studio C++
« Reply #17 on: January 12, 2018, 10:42:35 AM »
THX very much. I will test it quickly.