problem with bit manipulation
Posted: Sat Jun 20, 2009 1:47 pm
Im trying to manipulate the bits in the page directory, but they are not being stored in memory as they should be.
j is just there for debugging purposes, but i would get the same problem while using idx.
Most of this code was taken from JamesM, and it works in his kernel, so i dont know what im missing here.
Here is the contents of the page table from bochs:
So you see what is happening is present and user are being treated as the leftmost byte, and frame is being treated as, im guessing, this part 0x05000ff0. Why aren't the bits being stored in memory as defined by the structure?
Code: Select all
typedef struct page {
u32 present : 1; // Page present in memory
u32 rw : 1; // Read-only if clear, readwrite if set
u32 user : 1; // Supervisor level only if clear
u32 accessed : 1; // Has the page been accessed since last refresh?
u32 dirty : 1; // Has the page been written to since last refresh?
u32 unused : 7; // Amalgamation of unused and reserved bits
u32 frame : 20; // Frame address (shifted right 12 bits)
} page_t;
for(i = PG_ALIGN(start), j = 0xff; i < PG_ALIGN(end+0x1000); i += 0x1000, ++j) {
idx = first_frame();
user_pde->tables[PDE_OFFSET(i)]->pages[PTE_OFFSET(i)].frame = j;
user_pde->tables[PDE_OFFSET(i)]->pages[PTE_OFFSET(i)].present = 1;
user_pde->tables[PDE_OFFSET(i)]->pages[PTE_OFFSET(i)].user = 1;
set_frame(idx*0x1000);
}
Most of this code was taken from JamesM, and it works in his kernel, so i dont know what im missing here.
Here is the contents of the page table from bochs:
Code: Select all
<bochs:2> x /10 0xd0004000
[bochs]:
0xd0004000 <bogus+ 0>: 0x05000000 0x05000ff0 0x05001000 0x05001010
0xd0004010 <bogus+ 16>: 0x05001020 0x05001030 0x05001040 0x05001050
0xd0004020 <bogus+ 32>: 0x05001060 0x05001070