diff --git a/console.c b/console.c
index a91029f8a67759543ed37ef1c23f183fc24bcaef..3d19a8e2f8024641542f51b7c40ed2a5685201ab 100644
--- a/console.c
+++ b/console.c
@@ -160,7 +160,7 @@ panic(char *s)
 {
   __asm __volatile("cli");
   use_console_lock = 0;
-  cprintf("panic: ");
+  cprintf("panic (%d): ", cpu());
   cprintf(s, 0);
   cprintf("\n", 0);
   panicked = 1; // freeze other CPU
diff --git a/defs.h b/defs.h
index da4769126134586de7cbdb8038e265cfccc53f89..292842834d897b8eca225da6c8703929f43ff8c0 100644
--- a/defs.h
+++ b/defs.h
@@ -110,11 +110,13 @@ void bwrite(struct buf *, uint);
 void brelse(struct buf *);
 
 // fs.c
+extern uint rootdev;
 void iinit(void);
 struct inode * iget(uint dev, uint inum);
 void ilock(struct inode *ip);
 void iunlock(struct inode *ip);
 void idecref(struct inode *ip);
+void iincref(struct inode *ip);
 void iput(struct inode *ip);
 struct inode * namei(char *path, int, uint *);
 void stati(struct inode *ip, struct stat *st);
diff --git a/fs.c b/fs.c
index 2370e0ecd4255723105b3df23840e0716a67d571..530ef039ca5e6afcaa8c84e7a612f5552f050587 100644
--- a/fs.c
+++ b/fs.c
@@ -286,6 +286,14 @@ idecref(struct inode *ip)
   iput(ip);
 }
 
+void
+iincref(struct inode *ip)
+{
+  ilock(ip);
+  ip->count++;
+  iunlock(ip);
+}
+
 void
 stati(struct inode *ip, struct stat *st)
 {
diff --git a/fs.h b/fs.h
index 6e833730e5c571088921ae9125631d3f06e15ed9..2112c25b3d156b6e013476df136b6249490edee7 100644
--- a/fs.h
+++ b/fs.h
@@ -36,3 +36,5 @@ struct dirent {
   ushort inum;
   char name[DIRSIZ];
 };
+
+
diff --git a/init.c b/init.c
index 928371d89aa27a142699897a90e86af684da7038..983246b47cc200afd6d30862b378e073a4aa8752 100644
--- a/init.c
+++ b/init.c
@@ -1,5 +1,6 @@
-#include "user.h"
 #include "types.h"
+#include "stat.h"
+#include "user.h"
 #include "fs.h"
 #include "fcntl.h"
 
diff --git a/main.c b/main.c
index a2ee845edd900404030ef5db5fc537be483e65f7..6e1dabedce1489e9a99485a74fce8bb8c375ea82 100644
--- a/main.c
+++ b/main.c
@@ -68,13 +68,14 @@ main0(void)
   p->sz = 4 * PAGE;
   p->mem = kalloc(p->sz);
   memset(p->mem, 0, p->sz);
-  p->kstack = kalloc(KSTACKSIZE);
-  p->tf = (struct trapframe *) (p->kstack + KSTACKSIZE - sizeof(struct trapframe));
+  p->kstack = kalloc(KSTACKSIbZE);
+  p->tf = (struct trapframe *) (p->kstack + KSTACKSIZE) - 1;
   memset(p->tf, 0, sizeof(struct trapframe));
   p->tf->es = p->tf->ds = p->tf->ss = (SEG_UDATA << 3) | 3;
   p->tf->cs = (SEG_UCODE << 3) | 3;
   p->tf->eflags = FL_IF;
   setupsegs(p);
+  // curproc[cpu()] = p;
 
   // initialize I/O devices, let them enable interrupts
   console_init();
@@ -90,6 +91,8 @@ main0(void)
   cpus[cpu()].nlock--;
   sti();
 
+  // p->cwd = iget(rootdev, 1);
+  // iunlock(p->cwd);
   p = copyproc(&proc[0]);
   
   //load_icode(p, _binary_usertests_start, (uint) _binary_usertests_size);
diff --git a/proc.c b/proc.c
index 7290693164d004e354cf1dda42fc8393b00b4a42..6880fd40ba843cb18896cfa7db45049e2ea63fa7 100644
--- a/proc.c
+++ b/proc.c
@@ -124,6 +124,9 @@ copyproc(struct proc* p)
       fd_incref(np->fds[i]);
   }
 
+  // np->cwd = p->cwd;
+  // iincref(p->cwd);
+
   return np;
 }
 
diff --git a/proc.h b/proc.h
index 6ed2e78c12331fb648339fd0c2a85394fbf92a63..88e630b262c299d94fbab415848a29b1c6c475b8 100644
--- a/proc.h
+++ b/proc.h
@@ -46,6 +46,7 @@ struct proc{
   void *chan; // sleep
   int killed;
   struct fd *fds[NOFILE];
+  struct inode *cwd;
 
   struct taskstate ts;  // only to give cpu address of kernel stack
   struct segdesc gdt[NSEGS];