Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
typedef struct page
{
u32int present : 1; // Page present in memory
u32int rw : 1; // Read-only if clear, readwrite if set
u32int user : 1; // Supervisor level only if clear
u32int accessed : 1; // Has the page been accessed since last refresh?
u32int dirty : 1; // Has the page been written to since last refresh?
u32int unused : 7; // Amalgamation of unused and reserved bits
u32int frame : 20; // Frame address (shifted right 12 bits)
} page_t;
typedef struct page
{
u32int present : 1; // Page present in memory
u32int rw : 1; // Read-only if clear, readwrite if set
u32int user : 1; // Supervisor level only if clear
u32int reserved : 2; // Reserved bits <-------------- Missing from the first.
u32int accessed : 1; // Has the page been accessed since last refresh?
u32int dirty : 1; // Has the page been written to since last refresh?
u32int unused: 5; // Amalgamation of unused and reserved bits
u32int frame : 20; // Frame address (shifted right 12 bits)
} page_t;
Both 'seem' to work equally well. Havn't tested the second one too thoroughly though. Is the image correct or not? I'm assuming JamesM code is correct since it has probably been used by quite a lot of people. Or is there something I'm missing here?
Your last one (Ugh, was looking too much at your reserved fields, sorry) seems to be correct looking at AMD64 Architecture Programmer's Manual Volume 2: System Programming, Ch. 5.2.2., Figure 5-6.
See AMD64 Architecture Programmer's Manual Volume 2: System Programming, Ch. 5.4.1. for information about the fields.
Regards,
Stephan J.R. van Schaik.
This seems to be the same as the second struct and the same as the nice picture, albight with some more info on what the reserved and 'unused' bits are used for.
This seems to be the same as the second struct and the same as the nice picture, albight with some more info on what the reserved and 'unused' bits are used for.
I noticed that and edited it before you posted, but you might have missed it.
"Your last one (Ugh, was looking too much at your reserved fields, sorry) seems to be correct looking at AMD64 Architecture Programmer's Manual Volume 2: System Programming, Ch. 5.2.2., Figure 5-6."
I wouldn't recommend using a struct for that, actually. They're probably going to result in less efficient code when assigning multiple fields. Better to use just a dword type and some bit constants.
midir wrote:I wouldn't recommend using a struct for that, actually. They're probably going to result in less efficient code when assigning multiple fields. Better to use just a dword type and some bit constants.
Or union it with a 32-bit integer.
(And yes, it appears that is incorrect on my site. Many apologies!)
midir wrote:I wouldn't recommend using a struct for that, actually. They're probably going to result in less efficient code when assigning multiple fields. Better to use just a dword type and some bit constants.
I wouldn't recommend using a struct either, because C doesn't guarantee the order of bitfields - on some compilers you might end up with "present" bit at bit 31, and the frame field at bits 0 to 19.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.