problems enabling paging
Posted: Wed Apr 07, 2010 1:06 pm
heey all,
after setting up gdt, idt, irs's, irq's and the pit I wanted to turn to memory managment and have chosen to use paging (as is supposed to be the easiest one).
I create the pagingTable and directory. But as soon as i enable it, bochs just restarts.
I have the following code:
Paging.h
Paging.c
paging.asm
link.ld
after setting up gdt, idt, irs's, irq's and the pit I wanted to turn to memory managment and have chosen to use paging (as is supposed to be the easiest one).
I create the pagingTable and directory. But as soon as i enable it, bochs just restarts.
I have the following code:
Paging.h
Code: Select all
//prototypes
void paging_install();
Code: Select all
#include <Paging.h>
#include <Printing.h>
unsigned int *page_directory;
unsigned int *page_table;
extern int __KERNEL_END;
extern void enablePaging();
void paging_install()
{
//the paging directory is just behind the kernel
page_directory = (unsigned int *) __KERNEL_END;
//the first paging directory (this means for the first 4mb for memory) is right behind the paging directory
page_table = (unsigned int *) __KERNEL_END + 0x01000;
//now we fill the table
int i;
int adress = 0;
for(i = 0; i < 1024; i++)
{
page_table[i] = adress | 3; //Attributes: supervisor, read/write, present
adress += 0x01000; //0x01000 = 4096 = 4kb
}
//at the table to the directory
page_directory[0] = (int)page_table;
page_directory[0] |= 3; //Attributes: supervisor, read/write, present
//fill the rest of the tables in the directory with non-present flags
for(i = 0; i < 1024; i++)
{
page_directory[0] = 0 | 2; //Attributes: supervisor, read/write, not present
}
//
//finally enable and start paging
//
//load the page directory pointer
__asm__ __volatile__("mov %0, %%cr3":: "b"(page_directory));
//now start it!
//enablePaging();
}
paging.asm
Code: Select all
[global _enablePaging]
_enablePaging:
mov eax, cr0
or eax, 0x80000000
mov cr0, eax
link.ld
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;_end = .;__end = .;___KERNEL_END = .;
}