diff --git a/defs.h b/defs.h
index ca7367d2480cbe8bcc22d577c9d182388ddf90ca..dca91bb1171d0793c6b6c98bd90aecc0f63e08a1 100644
--- a/defs.h
+++ b/defs.h
@@ -62,7 +62,7 @@ void            ioapicinit(void);
 // kalloc.c
 char*           kalloc(void);
 void            kfree(char*);
-void            kinit(char*,uint);
+void            kinit();
 
 // kbd.c
 void            kbdintr(void);
@@ -151,7 +151,6 @@ void            uartintr(void);
 void            uartputc(int);
 
 // vm.c
-void            pminit(void);
 void            ksegment(void);
 void            kvmalloc(void);
 void            vmenable(void);
diff --git a/kalloc.c b/kalloc.c
index 65de759b99c10d091b789dc491b4ac28e0278eb3..8c9ff93d3a7befe1f14836678c08140c8fd9c6f8 100644
--- a/kalloc.c
+++ b/kalloc.c
@@ -19,11 +19,13 @@ struct {
 
 // Initialize free list of physical pages.
 void
-kinit(char *p, uint len)
+kinit(void)
 {
+  extern char end[];
+
   initlock(&kmem.lock, "kmem");
-  char *p1 = (char*)PGROUNDUP((uint)p);
-  char *p2 = PGROUNDDOWN(p + len);
+  char *p1 = (char*)PGROUNDUP((uint)end);
+  char *p2 = PGROUNDDOWN(PHYSTOP);
   for( ; p1 < p2; p1 += 4096)
     kfree(p1);
 }
diff --git a/main.c b/main.c
index 878ea36b974efc22500227ab5ca182c02ca011c0..cb6e6ceedef91db6ce623209e6cfbb402c883ac3 100644
--- a/main.c
+++ b/main.c
@@ -21,7 +21,7 @@ main(void)
   ioapicinit();    // another interrupt controller
   consoleinit();   // I/O devices & their interrupts
   uartinit();      // serial port
-  pminit();        // discover how much memory there is
+  kinit();         // initialize memory allocator
   jkstack();       // call mainc() on a properly-allocated stack 
 }
 
diff --git a/mkfs.c b/mkfs.c
index a970b5c31a8963a3f0d28b84023f0c7b02cd3f75..3a3c62a616cdc3cfbde837884514c25f4796bb3b 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -82,7 +82,7 @@ main(int argc, char *argv[])
   usedblocks = ninodes / IPB + 3 + bitblocks;
   freeblock = usedblocks;
 
-  printf("used %d (bit %d ninode %u) free %u total %d\n", usedblocks,
+  printf("used %d (bit %d ninode %lu) free %u total %d\n", usedblocks,
          bitblocks, ninodes/IPB + 1, freeblock, nblocks+usedblocks);
 
   assert(nblocks + usedblocks == size);
@@ -230,7 +230,7 @@ balloc(int used)
   for(i = 0; i < used; i++) {
     buf[i/8] = buf[i/8] | (0x1 << (i%8));
   }
-  printf("balloc: write bitmap block at sector %u\n", ninodes/IPB + 3);
+  printf("balloc: write bitmap block at sector %lu\n", ninodes/IPB + 3);
   wsect(ninodes / IPB + 3, buf);
 }
 
diff --git a/vm.c b/vm.c
index 46d18fcd7315124e76cab8fd185699cdf4dbe577..8a57ca9d901c1ac143d2f3f3f52280b571d5a338 100644
--- a/vm.c
+++ b/vm.c
@@ -17,8 +17,8 @@
 // setupkvm() and exec() set up every page table like this:
 //   0..640K          : user memory (text, data, stack, heap)
 //   640K..1M         : mapped direct (for IO space)
-//   1M..kernend      : mapped direct (for the kernel's text and data)
-//   kernend..PHYSTOP : mapped direct (kernel heap and user pages)
+//   1M..end          : mapped direct (for the kernel's text and data)
+//   end..PHYSTOP     : mapped direct (kernel heap and user pages)
 //   0xfe000000..0    : mapped direct (devices such as ioapic)
 //
 // The kernel allocates memory for its heap and for user memory
@@ -31,12 +31,6 @@
 
 #define USERTOP  0xA0000
 
-static uint kerntext;  // Linker starts kernel at 1MB
-static uint kerntsz;   
-static uint kerndata;
-static uint kerndsz;
-static uint kernend;
-static uint freesz;
 static pde_t *kpgdir;  // for use in scheduler()
 
 // return the address of the PTE in page table pgdir
@@ -161,14 +155,8 @@ setupkvm(void)
   // Map IO space from 640K to 1Mbyte
   if (!mappages(pgdir, (void *)USERTOP, 0x60000, USERTOP, PTE_W))
     return 0;
-  // Map kernel text read-only
-  if (!mappages(pgdir, (void *) kerntext, kerntsz, kerntext, 0))
-    return 0;
-  // Map kernel data read/write
-  if (!mappages(pgdir, (void *) kerndata, kerndsz, kerndata, PTE_W))
-    return 0;
-  // Map dynamically-allocated memory read/write (kernel stacks, user mem)
-  if (!mappages(pgdir, (void *) kernend, freesz, PADDR(kernend), PTE_W))
+  // Map kernel and free memory pool
+  if (!mappages(pgdir, (void *)0x100000, PHYSTOP-0x100000, 0x100000, PTE_W))
     return 0;
   // Map devices such as ioapic, lapic, ...
   if (!mappages(pgdir, (void *)0xFE000000, 0x2000000, 0xFE000000, PTE_W))
@@ -333,31 +321,6 @@ copyuvm(pde_t *pgdir, uint sz)
   return d;
 }
 
-// Gather information about physical memory layout.
-// Called once during boot.
-// Really should find out how much physical memory
-// there is rather than assuming PHYSTOP.
-void
-pminit(void)
-{
-  extern char end[];
-  struct proghdr *ph;
-  struct elfhdr *elf = (struct elfhdr*)0x10000;  // scratch space
-
-  if (elf->magic != ELF_MAGIC || elf->phnum != 2)
-    panic("pminit: need a text and data segment\n");
-
-  ph = (struct proghdr*)((uchar*)elf + elf->phoff);
-  kernend = ((uint)end + PGSIZE) & ~(PGSIZE-1);
-  kerntext = ph[0].va;
-  kerndata = ph[1].va;
-  kerntsz = ph[0].memsz;
-  kerndsz = ph[1].memsz;
-  freesz = PHYSTOP - kernend;
-
-  kinit((char *)kernend, freesz);
-}
-
 // Allocate one page table for the machine for the kernel address
 // space for scheduler processes.
 void