C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-13-2009, 06:00 PM   #1
Registered User
 
Join Date: Jun 2008
Posts: 19
Inline GCC Help with reading CR4 register

Hi, this is an attempt to read the CR4 register into the A register (rax for 64 bit) on fedora 11 64 bit. The movq operation produces a segment fault.

Code:
typedef unsigned long long UINT64;
typedef union
{
        UINT64 value;
        struct
        {
                 UINT64 VME0:1; 
                UINT64 PVI1:1; 
                UINT64 TSDB2:1;
                UINT64 DE3:1; 
                UINT64 PSE4:1;
                UINT64 PAE5:1;
                UINT64 MCE6:1;
                UINT64 PGE7:1; 
                UINT64 PCE8:1; 
                UINT64 OSFXSR9:1; 
                UINT64 OSXMMEXCPT10:1; 
                UINT64 bit1112:2; // reserved
                UINT64 VMXE13:1; 
                UINT64 SMXE14:1; 
                UINT64 bit1517:3; // reserved
                UINT64 OSXSAVE18:1; 
                UINT64 bit1931:13; // reserved
                UINT64 bit3264:32; // reserved should be 0
        }bits;
}CR4;

int main()
{
  unsigned long long result;
  //CR4 cr4_reg;
  printf("\n size of long long is %x ", sizeof(result));
  fflush(NULL);
  __asm__("movq   %%cr4, %%rax\n"
        : "=a"(result) : "a"
  );
 printf("\n Value of CR4 = %x", result);
 return 0;
}
Thanks for helping me out
raghu2383 is offline   Reply With Quote
Old 10-13-2009, 07:46 PM   #2
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,381
Have you examined the generated code to ensure that the instruction is being assembled as you expect?

If it looks correct, then the only reason you'd get a segfault would be that access to the CR4 register is a privileged operation. I don't remember off the top of my head if that's the case.
__________________
"Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot
brewbuck is offline   Reply With Quote
Old 10-14-2009, 10:13 AM   #3
Registered User
 
Join Date: Jun 2008
Posts: 19
Yes, you are right, I figured it later on after much sweating. It cannot be accessed from an application and can be accessed through the kernel.

thanks for the reply
raghu2383 is offline   Reply With Quote
Reply

Tags
c programming, inline assembly, linux

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading a 16 bit Register Bladactania C Programming 7 07-04-2009 03:15 PM
brace-enclosed error jdc18 C++ Programming 53 05-03-2007 05:49 PM
gcc inline asm: illegal instruction (core dump) Sargnagel C Programming 4 10-28-2003 01:41 PM
register variables Draco C Programming 7 08-21-2002 01:01 PM
Register sean345 C Programming 7 05-08-2002 03:06 PM


All times are GMT -6. The time now is 10:47 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22