cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

circle
Journeyman III

Can't read control registers

Hi there
I'm trying to read and write to the control registers mainly CR4 with the intrinsics __readcr4 and the write equivalent. The code compiles without any warnings or errors but when I run it the program crashes.

Even the most basic code fails, like:
ULONG Cr4;
CR4 = __readcr4();
or
if(__readcr4())
{...}


I'm running the AMD 64 X2 with XP, I would really appreciate any help.

/Dan
0 Likes
1 Reply
alexey_khosh
Journeyman III

Here is quotation from the AMD document #24594.pdf: "MOV(CRn) is a privileged instruction and must always be executed at CPL = 0." As you can see, usual applications cannot execute these two instructions (read and write CRx), because ones are working on CPL = 3 (not 0, as required). In other words, it is allowed only for OS and drivers, because ones are working on CPL = 0.
0 Likes