Map kernel high

Very important to give qemu memory through PHYSTOP :(
This commit is contained in:
Frans Kaashoek 2011-07-29 07:31:27 -04:00
parent dccb915282
commit 9aa0337dc1
20 changed files with 208 additions and 71 deletions

View file

@ -5,6 +5,7 @@
#include "types.h"
#include "defs.h"
#include "param.h"
#include "memlayout.h"
#include "mmu.h"
#include "spinlock.h"
@ -18,6 +19,20 @@ struct {
} kmem;
extern char end[]; // first address after kernel loaded from ELF file
char *newend;
// simple page allocator to get off the ground during boot
char *
pgalloc(void)
{
if (newend == 0)
newend = end;
void *p = (void*)PGROUNDUP((uint)newend);
memset(p, 0, PGSIZE);
newend = newend + PGSIZE;
return p;
}
// Initialize free list of physical pages.
void
@ -26,8 +41,8 @@ kinit(void)
char *p;
initlock(&kmem.lock, "kmem");
p = (char*)PGROUNDUP((uint)end);
for(; p + PGSIZE <= (char*)PHYSTOP; p += PGSIZE)
p = (char*)PGROUNDUP((uint)newend);
for(; p + PGSIZE <= (char*)p2v(PHYSTOP); p += PGSIZE)
kfree(p);
}
@ -41,7 +56,7 @@ kfree(char *v)
{
struct run *r;
if((uint)v % PGSIZE || v < end || (uint)v >= PHYSTOP)
if((uint)v % PGSIZE || v < end || v2p(v) >= PHYSTOP)
panic("kfree");
// Fill with junk to catch dangling refs.
@ -67,6 +82,7 @@ kalloc(void)
if(r)
kmem.freelist = r->next;
release(&kmem.lock);
cprintf("kalloc: 0x%x\n", r);
return (char*)r;
}