From 9aa0337dc1452a911ac52698c833246a618fc9f3 Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Fri, 29 Jul 2011 07:31:27 -0400 Subject: Map kernel high Very important to give qemu memory through PHYSTOP :( --- kalloc.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'kalloc.c') diff --git a/kalloc.c b/kalloc.c index bf1616a..83ed7e8 100644 --- a/kalloc.c +++ b/kalloc.c @@ -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; } -- cgit v1.2.3