Moved page_directory from an allocated object to a pointer to a run-time allocated page of RAM
git-svn-id: svn://anubis/hos/trunk@42 5b3e749e-e535-0410-8002-a9bb6afbdfca
This commit is contained in:
parent
784978b131
commit
1aace858da
@ -8,8 +8,7 @@
|
||||
|
||||
static bool mm_use_virtual_offset;
|
||||
|
||||
pagedirectory_t page_directory __attribute__ ((aligned (4096)));
|
||||
|
||||
static pagedirectory_entry_t * page_directory;
|
||||
static mm_mem_range_t mm_mmap_entries[MM_MAX_MMAP_ENTRIES];
|
||||
static int mm_mmap_num_entries = 0;
|
||||
static int mm_num_free_pages = 0;
|
||||
@ -108,10 +107,18 @@ void mm_bootstrap()
|
||||
k_early_panic("Not enough free pages of RAM!");
|
||||
}
|
||||
|
||||
/* ok, now mm_page_alloc() should be functional */
|
||||
|
||||
/* allocate the page directory */
|
||||
u32_t page_directory_phys = mm_page_alloc();
|
||||
page_directory = (pagedirectory_entry_t *) page_directory_phys;
|
||||
pagedirectory_entry_t * page_dir_virt =
|
||||
(pagedirectory_entry_t *) (page_directory_phys + KERNEL_OFFSET);
|
||||
|
||||
/* Clear the page directory */
|
||||
for (unsigned int i = 0; i < NUM_PAGETABLE_ENTRIES; i++)
|
||||
{
|
||||
page_directory[i] = 0;
|
||||
page_dir_virt[i] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -135,7 +142,7 @@ void mm_bootstrap()
|
||||
}
|
||||
|
||||
/* set the page directory base register */
|
||||
set_cr3(&page_directory);
|
||||
set_cr3(page_directory);
|
||||
|
||||
mm_use_virtual_offset = false;
|
||||
}
|
||||
@ -149,7 +156,13 @@ int mm_map(u32_t virtual_address, u32_t physical_address,
|
||||
{
|
||||
u32_t directory_index = (virtual_address >> 22) & 0x3FF;
|
||||
u32_t table_index = (virtual_address >> 12) & 0x3FF;
|
||||
if (page_directory[directory_index] == 0)
|
||||
pagedirectory_entry_t * page_dir = page_directory;
|
||||
if (mm_use_virtual_offset)
|
||||
{
|
||||
page_dir = (pagedirectory_entry_t *)((u32_t)page_dir + KERNEL_OFFSET);
|
||||
}
|
||||
|
||||
if (page_dir[directory_index] == 0)
|
||||
{
|
||||
/* allocate a new page table */
|
||||
u32_t page_table_address = mm_page_alloc();
|
||||
@ -157,12 +170,12 @@ int mm_map(u32_t virtual_address, u32_t physical_address,
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
page_directory[directory_index] = page_table_address
|
||||
page_dir[directory_index] = page_table_address
|
||||
| 0x1 << 2 /* PTs can be user mode */
|
||||
| 0x1 << 1 /* writable */
|
||||
| 0x1; /* present */
|
||||
}
|
||||
u32_t page_table_address = page_directory[directory_index] & PAGE_HIGH_MASK;
|
||||
u32_t page_table_address = page_dir[directory_index] & PAGE_HIGH_MASK;
|
||||
|
||||
u32_t * page_table = (u32_t *) page_table_address;
|
||||
if (mm_use_virtual_offset)
|
||||
|
@ -10,10 +10,7 @@ typedef u32_t pagedirectory_entry_t;
|
||||
|
||||
#define NUM_PAGETABLE_ENTRIES (PAGE_SIZE / sizeof(pagedirectory_entry_t))
|
||||
|
||||
typedef pagedirectory_entry_t
|
||||
pagedirectory_t[NUM_PAGETABLE_ENTRIES];
|
||||
|
||||
extern pagedirectory_t page_directory;
|
||||
typedef pagedirectory_entry_t pagedirectory_t[NUM_PAGETABLE_ENTRIES];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user