organization
This commit is contained in:
+25
-35
@@ -7,31 +7,13 @@ uint32_t kernel_page_directory[1024] __attribute__((aligned(4096)));
|
||||
uint32_t kernel_page_table[1024] __attribute__((aligned(4096)));
|
||||
uint32_t user_page_table[1024] __attribute__((aligned(4096)));
|
||||
|
||||
#define PAGE_OFFSET 0xC0000000
|
||||
#define PAGE_SIZE 4096
|
||||
uint32_t *kpage_dir;
|
||||
|
||||
#define PAGE_PRESENT 0x1
|
||||
#define PAGE_RW 0x002 /* Read/Write */
|
||||
#define PAGE_USER 0x004 /* User */
|
||||
#define PAGE_NOALLOC 0x200 /* No Page Allocated (OS managed) */
|
||||
|
||||
#define PAGE_SHIFT 0x0C
|
||||
#define PAGE_MASK ~(PAGE_SIZE - 1) /* 0xFFFFF000 */
|
||||
|
||||
#define GDT_BASE (0xFFFFFFFF - (PAGE_OFFSET - 1))
|
||||
|
||||
#define GET_PGDIR(address) ((unsigned int)((address) >> 22) & 0x3FF)
|
||||
#define GET_PGTBL(address) ((unsigned int)((address) >> 12) & 0x3FF)
|
||||
|
||||
#define PAGE_ALIGN(addr) (((addr) + (PAGE_SIZE - 1)) & PAGE_MASK)
|
||||
|
||||
unsigned int *kpage_dir;
|
||||
|
||||
unsigned int setup_tmp_pgdir(unsigned int magic, unsigned int info)
|
||||
uint32_t setup_tmp_pgdir(uint32_t magic, uint32_t info)
|
||||
{
|
||||
int n, pd;
|
||||
unsigned int addr, memksize;
|
||||
unsigned int *pgtbl;
|
||||
uint32_t pagedir_address, memksize;
|
||||
uint32_t *page_table;
|
||||
struct multiboot_info *mbi;
|
||||
|
||||
if(magic != MULTIBOOT_BOOTLOADER_MAGIC) {
|
||||
@@ -44,33 +26,41 @@ unsigned int setup_tmp_pgdir(unsigned int magic, unsigned int info)
|
||||
memksize = 4096;
|
||||
} else {
|
||||
/* we need to add the first 1MB to memksize */
|
||||
memksize = (unsigned int)mbi->mem_upper + 1024;
|
||||
/* CONFIG_VM_SPLIT22 marks the maximum physical memory supported */
|
||||
memksize = (uint32_t)mbi->mem_upper + 1024;
|
||||
if(memksize > ((0xFFFFFFFF - PAGE_OFFSET) / 1024)) {
|
||||
memksize = (0xFFFFFFFF - PAGE_OFFSET) / 1024;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addr = PAGE_OFFSET + (memksize * 1024) - memksize;
|
||||
addr = PAGE_ALIGN(addr);
|
||||
/* address becomes PAGE_OFFSET (0xC0000000) plus the size of memory minus the first page */
|
||||
/* TODO: check if I wrote the comment above correctly*/
|
||||
pagedir_address = PAGE_OFFSET + (memksize * 1024) - memksize;
|
||||
pagedir_address = PAGE_ALIGN(pagedir_address);
|
||||
|
||||
kpage_dir = (unsigned int *)addr;
|
||||
/*
|
||||
memory pages:
|
||||
0 -> page directory
|
||||
1 -> page table
|
||||
*/
|
||||
kpage_dir = (uint32_t *)pagedir_address;
|
||||
memset(kpage_dir, 0, PAGE_SIZE);
|
||||
|
||||
addr += PAGE_SIZE;
|
||||
pgtbl = (unsigned int *)addr;
|
||||
memset(pgtbl, 0, memksize);
|
||||
pagedir_address += PAGE_SIZE;
|
||||
page_table = (uint32_t *)pagedir_address;
|
||||
memset(page_table, 0, memksize);
|
||||
|
||||
for(n = 0; n < memksize / sizeof(unsigned int); n++) {
|
||||
pgtbl[n] = (n << PAGE_SHIFT) | PAGE_PRESENT | PAGE_RW;
|
||||
/* if we have 4MB assumed earlier, the memksize will be 4096 and this loop will run while n < 1024 */
|
||||
/* so basically 4MB is 1024 pages */
|
||||
for(n = 0; n < memksize / sizeof(uint32_t); n++) {
|
||||
page_table[n] = (n << PAGE_SHIFT) | PAGE_PRESENT | PAGE_RW;
|
||||
if(!(n % 1024)) {
|
||||
pd = n / 1024;
|
||||
kpage_dir[pd] = (unsigned int)(addr + (PAGE_SIZE * pd) + GDT_BASE) | PAGE_PRESENT | PAGE_RW;
|
||||
kpage_dir[GET_PGDIR(PAGE_OFFSET) + pd] = (unsigned int)(addr + (PAGE_SIZE * pd) + GDT_BASE) | PAGE_PRESENT | PAGE_RW;
|
||||
kpage_dir[pd] = (uint32_t)(pagedir_address + (PAGE_SIZE * pd) + GDT_BASE) | PAGE_PRESENT | PAGE_RW;
|
||||
kpage_dir[GET_PGDIR(PAGE_OFFSET) + pd] = (uint32_t)(pagedir_address + (PAGE_SIZE * pd) + GDT_BASE) | PAGE_PRESENT | PAGE_RW;
|
||||
}
|
||||
}
|
||||
return (unsigned int)kpage_dir - PAGE_OFFSET;
|
||||
return (uint32_t)kpage_dir - PAGE_OFFSET;
|
||||
}
|
||||
|
||||
void enablePaging() {
|
||||
|
||||
Reference in New Issue
Block a user