Multiboot Paging Woes
Posted: Sun Mar 05, 2006 10:27 am
Ok, I've recently moved my Kernel over so that it boots in Multiboot mode via GRUB cheifly because I was looking for a way of making paging easier. That all seems to have worked fine and my (very)basic Kernel loads and outputs to the screen without complaint. However as soon as I try and Initialize basic paging I get a crash from BOCHS complaining that I am running in Bogus Memory. I assume this means I'm misaddressing something.
My paging setup looks like this -
My bootloader is as follows:
What have I done wrong or am I just missing something fundamental about the entire experience
Thanks
E
My paging setup looks like this -
Code: Select all
void Init_Paging()
{
unsigned long address=0; // holds the physical address of where a page is
unsigned int i;
// map the first 4MB of memory
for(i=0; i<1024; i++)
{
g_page_table[i] = address | 0x3; // attribute set to: supervisor level, read/write, present(011 in binary)
address = address + 4096; // 4096 = 4kb
};
// fill the first entry of the page directory
g_page_directory[0x0] = ((int)g_page_table + 0x40100000) | read_write | present;
g_page_directory[0x300] = ((int)g_page_table + 0x40100000) | read_write | present;
// set the rest of the pages to empty
for(i=1; i<1024; i++)
{
g_page_directory[i] = 0|read_write; // attribute set to: supervisor level, read/write, not present(010 in binary)
};
// write_cr3, read_cr3, write_cr0, and read_cr0 all come from the assembly functions
write_cr3((int)g_page_directory + 0x40100000); // put that page directory address into CR3
write_cr0(read_cr0() | 0x80000000); // set the paging bit in CR0 to 1
};
Code: Select all
global _loader ; making entry point visible to linker
extern _k_main ; _main is defined elsewhere
; setting up the Multiboot header - see GRUB docs for details
MODULEALIGN equ 1<<0 ; align loaded modules on page boundaries
MEMINFO equ 1<<1 ; provide memory map
FLAGS equ MODULEALIGN | MEMINFO ; this is the Multiboot 'flag' field
MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find the header
CHECKSUM equ -(MAGIC + FLAGS) ; checksum required
section .text
align 4
MultiBootHeader:
dd MAGIC
dd FLAGS
dd CHECKSUM
; reserve initial kernel stack space
STACKSIZE equ 0x4000 ; that's 16k.
_loader:
mov esp, stack+STACKSIZE ; set up the stack
push eax ; pass Multiboot magic number
push ebx ; pass Multiboot info structure
call _k_main ; call kernel proper
hlt ; halt machine should kernel return
section .bss
align 32
stack:
resb STACKSIZE ; reserve 16k stack on a quadword boundary
Thanks
E