From 211fa113f097bb3855ab9e025c574590c7a3a56f Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 29 Dec 2014 12:17:18 +0100 Subject: [PATCH] add helper function to map a page frame into the boot page table --- arch/x86/include/asm/page.h | 17 +++++++++++++---- arch/x86/mm/page.c | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h index 35ade15..8030bb9 100644 --- a/arch/x86/include/asm/page.h +++ b/arch/x86/include/asm/page.h @@ -112,9 +112,18 @@ size_t page_virt_to_phys(size_t vir); * Before calling page_init(), the bootstrap tables contain a simple identity * paging. Which is replaced by more specific mappings. */ -int page_init(); +int page_init(void); -/** @brief Map a continious region of pages +/** @brief Map one page into the boot page table + * + * @param viraddr + * @param phyaddr + * @param bits + * @return + */ +int page_map_bootmap(size_t viraddr, size_t phyaddr, size_t bits); + +/** @brief Map a continuous region of pages * * @param viraddr * @param phyaddr @@ -124,7 +133,7 @@ int page_init(); */ int page_map(size_t viraddr, size_t phyaddr, size_t npages, size_t bits); -/** @brief Unmap a continious region of pages +/** @brief Unmap a continuous region of pages * * @param viraddr * @param npages @@ -141,6 +150,6 @@ int page_unmap(size_t viraddr, size_t npages); int page_map_copy(task_t *dest); /** @brief Free a whole page map tree */ -int page_map_drop(); +int page_map_drop(void); #endif diff --git a/arch/x86/mm/page.c b/arch/x86/mm/page.c index 290c091..20c0afd 100644 --- a/arch/x86/mm/page.c +++ b/arch/x86/mm/page.c @@ -53,7 +53,7 @@ extern const void kernel_end; static spinlock_t kslock = SPINLOCK_INIT; /** This PGD table is initialized in entry.asm */ -extern size_t boot_map[PAGE_MAP_ENTRIES]; +extern size_t* boot_map; /** A self-reference enables direct access to all page tables */ static size_t* self[PAGE_LEVELS] = { @@ -77,6 +77,16 @@ size_t page_virt_to_phys(size_t addr) return phy | off; } +int page_map_bootmap(size_t viraddr, size_t phyaddr, size_t bits) +{ + if (BUILTIN_EXPECT(viraddr >= PAGE_MAP_ENTRIES*PAGE_SIZE, 0)) + return -EINVAL; + + boot_map[PAGE_MAP_ENTRIES + (viraddr >> PAGE_BITS)] = phyaddr | bits | PG_PRESENT; + + return 0; +} + int page_map(size_t viraddr, size_t phyaddr, size_t npages, size_t bits) { int lvl, ret = -ENOMEM; @@ -160,7 +170,7 @@ int page_unmap(size_t viraddr, size_t npages) return 0; } -int page_map_drop() +int page_map_drop(void) { void traverse(int lvl, long vpn) { long stop; @@ -248,7 +258,7 @@ void page_fault_handler(struct state *s) while(1) HALT; } -int page_init() +int page_init(void) { size_t addr, npages; int i;