OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 1:40 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: How do I get a cr4 register using C?
PostPosted: Tue Jun 02, 2020 1:27 pm 
Offline
Member
Member
User avatar

Joined: Sun Jul 21, 2019 7:34 am
Posts: 300
Hi.
I try to get it with this kind of code
Code:
uint32_t cr4 = 0;
__asm__ (
    "mov %%cr4, %0" : "=r"(cr4)
);
dprintf("cr4 = %I\n", cr4);
for(int i = 0; i < 32; ++i) {
    dprintf("%I", (cr4 >> i) & 1);
}

but I get 0, for cr0 it works.


Top
 Profile  
 
 Post subject: Re: How do I get a cr4 register using C?
PostPosted: Tue Jun 02, 2020 2:17 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
Could it be that CR4 is indeed 0?

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: How do I get a cr4 register using C?
PostPosted: Tue Jun 02, 2020 2:19 pm 
Offline
Member
Member
User avatar

Joined: Sun Jul 21, 2019 7:34 am
Posts: 300
kzinti wrote:
Could it be that CR4 is indeed 0?

No, I have PAE enabled(GRUB includes it), so 5 bits should be equal to 1.


Top
 Profile  
 
 Post subject: Re: How do I get a cr4 register using C?
PostPosted: Tue Jun 02, 2020 3:04 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
Are you sure? I'm probably wrong, but I thought PAE was something that was enabled in the kernel, not the boot loader.


Top
 Profile  
 
 Post subject: Re: How do I get a cr4 register using C?
PostPosted: Tue Jun 02, 2020 3:08 pm 
Offline
Member
Member
User avatar

Joined: Sun Jul 21, 2019 7:34 am
Posts: 300
iansjack wrote:
Are you sure? I'm probably wrong, but I thought PAE was something that was enabled in the kernel, not the boot loader.

Hm.
the memory_map that GRUB gives me sees memory above 4 GB, I think it does it with PAE and expect to see it with this call.
Perhaps it is really disabled in the core.


Top
 Profile  
 
 Post subject: Re: How do I get a cr4 register using C?
PostPosted: Tue Jun 02, 2020 3:39 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
No, Grub doesn't enable PAE for you. In fact, paging is not even enabled.

The fact that it reports memory above 4 GB has nothing to do with PAE being enabled or not.

You have to setup page tables for PAE and enable it yourself if you want to use it.

See https://www.pvv.ntnu.no/~steinarh/grub/ ... html#SEC12:

Quote:
Paging must be turned off.

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: How do I get a cr4 register using C?
PostPosted: Tue Jun 02, 2020 4:03 pm 
Offline
Member
Member
User avatar

Joined: Sun Jul 21, 2019 7:34 am
Posts: 300
kzinti wrote:
No, Grub doesn't enable PAE for you. In fact, paging is not even enabled.

The fact that it reports memory above 4 GB has nothing to do with PAE being enabled or not.

You have to setup page tables for PAE and enable it yourself if you want to use it.

See https://www.pvv.ntnu.no/~steinarh/grub/ ... html#SEC12:

Quote:
Paging must be turned off.

I understood. Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], MichaelPetch and 160 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group