Page 1 of 1
Test if paging was enabled correctly?
Posted: Thu Apr 14, 2005 5:45 pm
by omin0us
Hi, my name is anthony, i lurk here quite a bit and am now coming across an issue that i am unsure about.
after reading numerous tutorials on memory paging and the IA-32 Software Developers Manuals (which btw, if anyone knows how/where to get a HARD copy of these, i would love them forever) i finally wrote the code to setup and enable paging. But i am curious how i test whether or not it is enabled?... as of now, i just threw in a global var called _paging_enabled
and do someting like
if(read_cr0() & 0x80000000)
_paging_enabled = 1;
else
_paging_enabled = 0;
them the main kernel function will print out "Paging Enabled Successfully" or "Paging failed" depending on that global var. is this sufficient to test if it actually was enabled? I assumed that my k_printf() would break or something after i enabled paging though because then 0xb8000 wouldn't really be at 0xb8000 would it? I appreciate any help and info anyone could give me on this matter.
Thanks.
Re:Test if paging was enabled correctly?
Posted: Thu Apr 14, 2005 6:13 pm
by AR
Forgive me for not remotely seeing the point of that at all. Why do you need to know if paging is enabled?
Assumeably you will require paging and if it fails to initalise then you'd panic:
Code: Select all
int main()
{
...
Init_Paging();
print("Paging Enabled successfully\n");
...
}
void Init_Paging()
{
...
if(failed) //Of course if the code actually works at all, it should work always
PANIC("Paging Failed to enable");
}
You should probably familarise yourself with the concepts of paging first, 0xB8000 will be wherever you put it.
Re:Test if paging was enabled correctly?
Posted: Thu Apr 14, 2005 8:45 pm
by Brendan
Hi,
AR wrote:
Forgive me for not remotely seeing the point of that at all. Why do you need to know if paging is enabled?
I can think of one reason...
Code: Select all
int main()
{
print("Booting Kernel\n");
...
Init_Paging();
print("Paging Enabled successfully\n");
...
}
print(char *string) {
char *dest;
if(paging_is_enabled()) dest = linear_address_of_screen;
else dest = 0xB8000;
// Copy chars from string to dest
}
Cheers,
Brendan
Re:Test if paging was enabled correctly?
Posted: Thu Apr 14, 2005 9:09 pm
by AR
That would be a reasonably useless if statement though, you're wasting cycles checking a flag that will be enabled less than 1 second into the kernel boot for the entire time the system is up, the only time the state might change is during the shutdown.
Re:Test if paging was enabled correctly?
Posted: Fri Apr 15, 2005 2:17 am
by Pype.Clicker
if you wish to check if paging is actually activated, i'd rather suggest that you set up a paging alias (e.g. two page pointing to the same frame) and do something like
Code: Select all
unsigned *magic1=pointer_to_page(/*vaddr=*/0x00C00000);
unsigned *magic2=pointer_to_page(/*vaddr=*/0x00C01000);
set_page_table(/*vaddr=*/0x00C00000,/*paddr=*/0xB9000);
set_page_table(/*vaddr=*/0x00C01000,/*paddr=*/0xB9000);
*magic1=0xdeadbeef;
*magic2=0xcafebabe;
if (*magic1!=*magic2)
PANIC("Paging test failed with %x != %x",*magic1, *magic2);
Re:Test if paging was enabled correctly?
Posted: Fri Apr 15, 2005 4:06 am
by Brendan
Hi,
AR wrote:
That would be a reasonably useless if statement though, you're wasting cycles checking a flag that will be enabled less than 1 second into the kernel boot for the entire time the system is up, the only time the state might change is during the shutdown.
This would depend too much on the OS's design. I've done OSs before where the kernel was identity mapped and paging was disabled for physical memory management. In this case detecting if paging is enabled or not may be needed for all IRQ's handlers and exception handlers (and any code these could call) and in anything that could be called by the physical memory manager.
For my current OS paging is enabled before the kernel starts and remains enabled thereafter. In this case paging is always on and checking is completely pointless within the kernel.
Despite this during my boot code I enable and disable paging constantly while setting up the free page stacks for memory above 4 Gb (as 32 bit protected mode can't address it without paging and PAE). In this case the boot code starts with paging off, then paging is rapidly flicked on and off and finally paging is turned on and left on. To cope with this almost everything is identity mapped except for the address of video display memory, so I just use a variable containing the current address of video display memory and correct it every time paging is enabled or disabled.
Cheers,
Brendan