summaryrefslogtreecommitdiff
path: root/kalloc.c
diff options
context:
space:
mode:
authorFrans Kaashoek <[email protected]>2011-07-29 07:31:27 -0400
committerFrans Kaashoek <[email protected]>2011-07-29 07:31:27 -0400
commit9aa0337dc1452a911ac52698c833246a618fc9f3 (patch)
tree28e25817d4f7c9f7f1e6988949012f46d6c28fb7 /kalloc.c
parentdccb915282854476ce47752df6631dcce3b8f661 (diff)
downloadxv6-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.c22
1 files changed, 19 insertions, 3 deletions
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;
}