Regards,
Rossetoecioccolato.
> How do I test whether rdmsr instruction is supported by the processor within
Testing bit 5 in edx after cpuid instruction.
> the Windows programming environment. There is a __readmsr intrinsic which
> works. But I don't see anything equivalent to IsMsr() provided on some
> other platforms. Do I have to use inline assembler?
donno exactly but I guess.
the code below should work on 32-bit platforms
bool IsMsr( void )
{ int _edx;
_asm{
xor eax,eax
xor ebx,ebx
xor ecx,ecx
xor edx,edx
cpuid
mov _edx,edx
}
return( _edx & 32 ? true : false );
}
Regards
Burkhardt Braun
>
> Regards,
>
> Rossetoecioccolato.
-pa
"Burkhardt Braun" <burkhar...@gmx.net> wrote in message
news:d3e7df2a-d799-4297...@k19g2000yqn.googlegroups.com...
> On 31 Jul., 04:01, "RossettoeCioccolato"
> <rossetoecioccol...@newsgroup.nospam> wrote:
>
>> How do I test whether rdmsr instruction is supported by the processor within
> Testing bit 5 in edx after cpuid instruction.
Does one then have to ensure that the cpuid and rdmsr run on the
same CPU? (By setting the affinity or raising to DISPATCH_LEVEL.)
Or can one assume that, were the CPUs so different that only some
of them support rdmsr at all, Windows would crash anyway?
(I'm just asking out of curiosity; if one is reading model-specific
registers of a CPU, then I suppose one already wants to know which
CPU in a multiprocessor system is being queried.)
>> return( _edx & 32 ? true : false );
>>}
Why not saving registers in stack before using them in _asm block and then
restoring them back from stack when finished?
--
Volodymyr M. Shcherbyna, blog: http://www.shcherbyna.com/
(This posting is provided "AS IS" with no warranties, and confers no
rights)
"Burkhardt Braun" <burkhar...@gmx.net> wrote in message
news:d3e7df2a-d799-4297...@k19g2000yqn.googlegroups.com...
--
Volodymyr M. Shcherbyna, blog: http://www.shcherbyna.com/
(This posting is provided "AS IS" with no warranties, and confers no
rights)
"Kalle Olavi Niemitalo" <k...@iki.fi> wrote in message
news:87vdl9w...@Astalo.kon.iki.fi...
>I don't think so. Microsoft is using CPUID to check if RDMSR is supported
>in HAL without any speacial tricks like affinity or raising irql.
Volodymyr, could you provide a symbol which contains this code. I would
like to document that MS relies on this algorithm for my records.
> Testing bit 5 in edx after cpuid instruction.<
Not to be anal, but should I also test whether the processor supports the
cpuid instruction? See for example:
"...if you want to use the CPUID instruction to check processor properties,
you should first ensure that the processor supports the CPUID instruction."
http://books.google.com/books?id=ZFDqpSUPwAgC&pg=PA232&lpg=PA232&dq=test+cpuid+instruction+supported&source=bl&ots=X4QbQJs9dj&sig=PXrAZbyD_Dbdkx8O8_1mZC-HGBY&hl=en&ei=kelySrafDYu6Nd7I6LAM&sa=X&oi=book_result&ct=result&resnum=5#v=onepage&q=test%20cpuid%20instruction%20supported&f=false.
Or can I just assume that it is because I am running under Windows? If the
HAL makes this assumption then presumably it also is safe for ISV's.
Correct?
Regards,
Rossetoecioccolato.
"RossettoeCioccolato" <rossetoec...@newsgroup.nospam> wrote in message
news:%23r%23r5AeE...@TK2MSFTNGP05.phx.gbl...
On the other hand, one better use _cpuid intrinsic, because otherwise you
won't be able to compile this for x64.
"Volodymyr Shcherbyna" <v_sch...@online.mvps.org> wrote in message
news:OzMI8ycE...@TK2MSFTNGP05.phx.gbl...
Nope, it would not :) Try to write snippet of code and test it using OllyDbg
or Ida Pro. Moreover, everywhere in HAL you can see pushes and pops for
registers used in _asm block.
If you want to play safe: try and catch...
__try { __cpuid( regs, 0); }
__except (EXCEPTION_EXECUTE_HANDLER) { /* cpuid caused exception, strange
/ }
-pa
Le Fri, 31 Jul 2009 09:09:59 -0400, RossettoeCioccolato a écrit :
> Volodymyr, could you provide a symbol which contains this code. I would
> like to document that MS relies on this algorithm for my records.
Isn't the link you provided not a good point to reference in
documentation? The only symbol I can suggest is HAL ...
--
Volodymyr, www.shcherbyna.com
"Volodymyr Shcherbyna" <v_sch...@online.mvps.org> wrote in message
news:eqJBUlfE...@TK2MSFTNGP04.phx.gbl...
> "Alexander Grigoriev" <al...@earthlink.net> wrote in message
> news:uYPjADfE...@TK2MSFTNGP02.phx.gbl...
>>C compiler will save the registers.
>
> Nope, it would not :) Try to write snippet of code and test it using
> OllyDbg or Ida Pro. Moreover, everywhere in HAL you can see pushes and
> pops for registers used in _asm block.
What compiler are you using? With Microsoft C++ (cl.exe), if you aren't
using declspec(naked) then registers should be saved.
Yes and no :) If you are changing ECX in _asm block inside class function,
the compiler saves the register in stack and restore it after, so that
program does not cause access violation. But you can play with ECX in non
class functions and compiler does not save it. The notion "compiler always
saves registers which are used in _asm block" is wrong, instead it seems to
be sticking to "compiler always saves register in stack and restore it later
if it's use in _asm block might cause instability of code".
The notion of "nonvolatile registers" is well-known, for __thiscall convention in C++/COM ECX is also among them.
--
Maxim S. Shatskih
Windows DDK MVP
ma...@storagecraft.com
http://www.storagecraft.com