diff options
author | Frans Kaashoek <[email protected]> | 2011-07-29 07:31:27 -0400 |
---|---|---|
committer | Frans Kaashoek <[email protected]> | 2011-07-29 07:31:27 -0400 |
commit | 9aa0337dc1452a911ac52698c833246a618fc9f3 (patch) | |
tree | 28e25817d4f7c9f7f1e6988949012f46d6c28fb7 /kalloc.c | |
parent | dccb915282854476ce47752df6631dcce3b8f661 (diff) | |
download | xv6-labs-9aa0337dc1452a911ac52698c833246a618fc9f3.tar.gz xv6-labs-9aa0337dc1452a911ac52698c833246a618fc9f3.tar.bz2 xv6-labs-9aa0337dc1452a911ac52698c833246a618fc9f3.zip |
Map kernel high
Very important to give qemu memory through PHYSTOP :(
Diffstat (limited to 'kalloc.c')
-rw-r--r-- | kalloc.c | 22 |
1 files changed, 19 insertions, 3 deletions
@@ -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; } |