proc: add basic proc loading
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
f9ddb8f379
commit
6b40cca5b0
10 changed files with 187 additions and 44 deletions
28
mem/page.c
28
mem/page.c
|
|
@ -4,18 +4,12 @@
|
|||
#include <kernel/buddy.h>
|
||||
#include <kernel/slab.h>
|
||||
#include <kernel/page.h>
|
||||
#include <kernel/proc.h>
|
||||
#include <arch/page.h>
|
||||
#include <lib/rbtree.h>
|
||||
#include <lib/math.h>
|
||||
#include <lib/string.h>
|
||||
|
||||
struct map_entry {
|
||||
vaddr_t vaddr;
|
||||
vaddr_t paddr;
|
||||
|
||||
size_t len;
|
||||
};
|
||||
|
||||
static rbtree_t kmap_tree = {0};
|
||||
static mem_cache_t *map_entry_cache = NULL;
|
||||
pgd_t *kpgd;
|
||||
|
|
@ -55,10 +49,10 @@ void *align(void *p, size_t align)
|
|||
|
||||
void page_map(pgd_t *pgd_table, paddr_t paddr, vaddr_t vaddr, size_t len, u64 flags, rbtree_t *map_tree)
|
||||
{
|
||||
struct map_entry *insert = slab_alloc(map_entry_cache);
|
||||
insert->paddr = paddr;
|
||||
insert->vaddr = vaddr;
|
||||
insert->len = len;
|
||||
struct vm_area *insert = slab_alloc(map_entry_cache);
|
||||
insert->start = vaddr;
|
||||
insert->end = vaddr + len;
|
||||
insert->flags = flags;
|
||||
|
||||
rbnode_t *node = rbt_insert(map_tree, vaddr);
|
||||
node->value = (u64)insert;
|
||||
|
|
@ -76,24 +70,24 @@ void page_map(pgd_t *pgd_table, paddr_t paddr, vaddr_t vaddr, size_t len, u64 fl
|
|||
|
||||
pgd_t *pgd_entry = &pgd_table[pgd_index(cur_vaddr)];
|
||||
if (!(pgd_entry->pgd & PAGE_PRESENT)) {
|
||||
pgd_entry->pgd = TO_PHYS((u64)pt_alloc()) | PAGE_PRESENT | PAGE_RW;
|
||||
pgd_entry->pgd = TO_PHYS((u64)pt_alloc()) | PAGE_PRESENT | PAGE_RW | (flags & PAGE_USER);
|
||||
}
|
||||
pud_t *pud_table = (pud_t *)TO_VIRT(pgd_entry->pgd & PAGE_MASK);
|
||||
|
||||
pud_t *pud_entry = &pud_table[pud_index(cur_vaddr)];
|
||||
if (!(pud_entry->pud & PAGE_PRESENT)) {
|
||||
pud_entry->pud = TO_PHYS((u64)pt_alloc()) | PAGE_PRESENT | PAGE_RW;
|
||||
pud_entry->pud = TO_PHYS((u64)pt_alloc()) | PAGE_PRESENT | PAGE_RW | (flags & PAGE_USER);
|
||||
}
|
||||
pmd_t *pmd_table = (pmd_t *)TO_VIRT(pud_entry->pud & PAGE_MASK);
|
||||
|
||||
pmd_t *pmd_entry = &pmd_table[pmd_index(cur_vaddr)];
|
||||
if (!(pmd_entry->pmd & PAGE_PRESENT)) {
|
||||
pmd_entry->pmd = TO_PHYS((u64)pt_alloc()) | PAGE_PRESENT | PAGE_RW;
|
||||
pmd_entry->pmd = TO_PHYS((u64)pt_alloc()) | PAGE_PRESENT | PAGE_RW | (flags & PAGE_USER);
|
||||
}
|
||||
pte_t *pte_table = (pte_t *)TO_VIRT(pmd_entry->pmd & PAGE_MASK);
|
||||
|
||||
pte_t *pte_entry = pte_table + pte_index(cur_vaddr);
|
||||
pte_entry->pte = (cur_paddr & PAGE_MASK) | (flags & 0xFFF);
|
||||
pte_entry->pte = (cur_paddr & PAGE_MASK) | PAGE_PRESENT | (flags & 0xFFF) | (flags & PAGE_XD);
|
||||
|
||||
cur_vaddr += PAGE_SIZE;
|
||||
cur_paddr += PAGE_SIZE;
|
||||
|
|
@ -155,7 +149,7 @@ void *map_mmio_dev(paddr_t base, size_t len)
|
|||
|
||||
void page_init()
|
||||
{
|
||||
map_entry_cache = slab_create("map_entry_cache", sizeof(struct map_entry), 64 * KB, 0x8);
|
||||
map_entry_cache = slab_create("map_entry_cache", sizeof(struct vm_area), 64 * KB, 0x8);
|
||||
kpgd = pt_alloc();
|
||||
|
||||
map_hhdm_zones(kpgd);
|
||||
|
|
@ -181,7 +175,7 @@ pgd_t *pgd_clone(pgd_t *src)
|
|||
{
|
||||
pgd_t *pgd = pt_alloc();
|
||||
|
||||
/* don't clone a bunch of kernel stuff, just keep it */
|
||||
/* don't clone a bunch of kernel stuff, just keep it */
|
||||
for (int i = 256; i < 512; i++)
|
||||
pgd[i] = kpgd[i];
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue