diff --git a/Makefile b/Makefile
index 5b849cdb9f2dbcc392d8d5a73859c13b9e4ad770..807311c8a4e1cfd47ab442da43ad6d7901a0ef31 100644
--- a/Makefile
+++ b/Makefile
@@ -4,14 +4,14 @@ T=target
 OPENSBI=fw_jump.elf
 
 ifndef platform
-#platform := qemu
-platform := sifive_u
+platform := qemu
+#platform := sifive_u
 endif
 
 ifndef init
 #init := cmd-user
-#init := cmd-sd
-init := runall
+init := cmd-sd
+#init := runall
 #init := hello
 endif
 
@@ -32,6 +32,14 @@ link := link_null.o
 initcode := _hello
 endif
 
+ifeq ($(init),runall)
+is := $U/runall.S
+ic := $U/initcode.hex
+else
+is := $U/cmd.S
+ic := script/initcode.c
+endif
+
 OBJS += \
   $K/entry.o \
   $K/printf.o
@@ -143,17 +151,20 @@ $K/kernel: $(OBJS) $K/kernel_app.ld $U/initcode
 	@$(OBJDUMP) -S $K/kernel > $K/kernel.asm
 	@$(OBJDUMP) -t $K/kernel | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $K/kernel.sym
 	
+$K/initcode.c:
+	rm -f $K/initcode.c
+	cp $(ic) $K/initcode.c	
+	
 $U/initcode.S:
-	if $(init)==runall; then \
-		cp $U/runall.S $U/initcode.S; \
-	else \
-		cp $U/cmd.S $U/initcode.S; fi
+	rm -f $U/initcode.S
+	cp $(is) $U/initcode.S
 	
 $U/initcode: $U/initcode.S
+	rm -f $U/initcode
 	$(CC) $(CFLAGS) -march=rv64g -nostdinc -I. -Ikernel -c $U/initcode.S -o $U/initcode.o
 	$(LD) $(LDFLAGS) -N -e start -Ttext 0 -o $U/initcode.out $U/initcode.o
 	$(OBJCOPY) -S -O binary $U/initcode.out $U/initcode
-	$(OBJDUMP) -S $U/initcode.o > $U/initcode.asm
+	rm -f $U/initcode.o $U/initcode.out $U/initcode.d
 
 tags: $(OBJS) _init
 	etags *.S *.c
@@ -240,7 +251,6 @@ clean:
 	mkfs/mkfs .gdbinit os.bin \
 	$U/usys.S \
 	$(UPROGS) $(TPROGS)
-	sudo rm -f $U/initcode.S  $U/initcode.hex
 
 # try to generate a unique GDB port
 GDBPORT = $(shell expr `id -u` % 5000 + 25000)
diff --git a/kernel/initcode.c b/kernel/initcode.c
index 17044d4b8e074cd4ecca277a7b6bb2844071021b..173e0a983f48ee7dd055bc216a9dcaa909685e3c 100644
--- a/kernel/initcode.c
+++ b/kernel/initcode.c
@@ -13,87 +13,6 @@ uchar initcode[] = {
 };
 #endif
 
-
-#ifdef _runall
-uchar initcode[] = {
-	0x13, 0x05, 0x20, 0x00, 0x93, 0x05, 0x10, 0x00, 
-	0x13, 0x06, 0x00, 0x00, 0x93, 0x08, 0xd0, 0x12, 
-	0x73, 0x00, 0x00, 0x00, 0x13, 0x05, 0x00, 0x00, 
-	0x93, 0x08, 0x70, 0x01, 0x73, 0x00, 0x00, 0x00, 
-	0x13, 0x05, 0x00, 0x00, 0x93, 0x08, 0x70, 0x01, 
-	0x73, 0x00, 0x00, 0x00, 0x93, 0x08, 0x10, 0x00, 
-	0x73, 0x00, 0x00, 0x00, 0x63, 0x1e, 0x05, 0x00, 
-	0x17, 0x05, 0x00, 0x00, 0x13, 0x05, 0x05, 0x1b, 
-	0x97, 0x05, 0x00, 0x00, 0x93, 0x85, 0xf5, 0x20, 
-	0x93, 0x08, 0x70, 0x00, 0x73, 0x00, 0x00, 0x00, 
-	0x93, 0x08, 0x10, 0x00, 0x73, 0x00, 0x00, 0x00, 
-	0x63, 0x1e, 0x05, 0x00, 0x17, 0x05, 0x00, 0x00, 
-	0x13, 0x05, 0x25, 0x19, 0x97, 0x05, 0x00, 0x00, 
-	0x93, 0x85, 0xb5, 0x1e, 0x93, 0x08, 0x70, 0x00, 
-	0x73, 0x00, 0x00, 0x00, 0x93, 0x08, 0x10, 0x00, 
-	0x73, 0x00, 0x00, 0x00, 0x63, 0x1e, 0x05, 0x00, 
-	0x17, 0x05, 0x00, 0x00, 0x13, 0x05, 0x75, 0x17, 
-	0x97, 0x05, 0x00, 0x00, 0x93, 0x85, 0x75, 0x1c, 
-	0x93, 0x08, 0x70, 0x00, 0x73, 0x00, 0x00, 0x00, 
-	0x93, 0x08, 0x10, 0x00, 0x73, 0x00, 0x00, 0x00, 
-	0x63, 0x1e, 0x05, 0x00, 0x17, 0x05, 0x00, 0x00, 
-	0x13, 0x05, 0xc5, 0x15, 0x97, 0x05, 0x00, 0x00, 
-	0x93, 0x85, 0x35, 0x1a, 0x93, 0x08, 0x70, 0x00, 
-	0x73, 0x00, 0x00, 0x00, 0x93, 0x08, 0x10, 0x00, 
-	0x73, 0x00, 0x00, 0x00, 0x63, 0x1e, 0x05, 0x00, 
-	0x17, 0x05, 0x00, 0x00, 0x13, 0x05, 0x15, 0x14, 
-	0x97, 0x05, 0x00, 0x00, 0x93, 0x85, 0xf5, 0x17, 
-	0x93, 0x08, 0x70, 0x00, 0x73, 0x00, 0x00, 0x00, 
-	0x93, 0x08, 0x10, 0x00, 0x73, 0x00, 0x00, 0x00, 
-	0x63, 0x1e, 0x05, 0x00, 0x17, 0x05, 0x00, 0x00, 
-	0x13, 0x05, 0x65, 0x12, 0x97, 0x05, 0x00, 0x00, 
-	0x93, 0x85, 0xb5, 0x15, 0x93, 0x08, 0x70, 0x00, 
-	0x73, 0x00, 0x00, 0x00, 0x93, 0x08, 0x10, 0x00, 
-	0x73, 0x00, 0x00, 0x00, 0x63, 0x1e, 0x05, 0x00, 
-	0x17, 0x05, 0x00, 0x00, 0x13, 0x05, 0xc5, 0x10, 
-	0x97, 0x05, 0x00, 0x00, 0x93, 0x85, 0x75, 0x13, 
-	0x93, 0x08, 0x70, 0x00, 0x73, 0x00, 0x00, 0x00, 
-	0x93, 0x08, 0x10, 0x00, 0x73, 0x00, 0x00, 0x00, 
-	0x63, 0x1e, 0x05, 0x00, 0x17, 0x05, 0x00, 0x00, 
-	0x13, 0x05, 0xe5, 0x0e, 0x97, 0x05, 0x00, 0x00, 
-	0x93, 0x85, 0x35, 0x11, 0x93, 0x08, 0x70, 0x00, 
-	0x73, 0x00, 0x00, 0x00, 0x93, 0x08, 0x10, 0x00, 
-	0x73, 0x00, 0x00, 0x00, 0x63, 0x1e, 0x05, 0x00, 
-	0x17, 0x05, 0x00, 0x00, 0x13, 0x05, 0x15, 0x0d, 
-	0x97, 0x05, 0x00, 0x00, 0x93, 0x85, 0xf5, 0x0e, 
-	0x93, 0x08, 0x70, 0x00, 0x73, 0x00, 0x00, 0x00, 
-	0x93, 0x08, 0x10, 0x00, 0x73, 0x00, 0x00, 0x00, 
-	0x63, 0x1e, 0x05, 0x00, 0x17, 0x05, 0x00, 0x00, 
-	0x13, 0x05, 0x45, 0x0b, 0x97, 0x05, 0x00, 0x00, 
-	0x93, 0x85, 0xb5, 0x0c, 0x93, 0x08, 0x70, 0x00, 
-	0x73, 0x00, 0x00, 0x00, 0x93, 0x08, 0x10, 0x00, 
-	0x73, 0x00, 0x00, 0x00, 0x63, 0x1e, 0x05, 0x00, 
-	0x17, 0x05, 0x00, 0x00, 0x13, 0x05, 0x75, 0x0a, 
-	0x97, 0x05, 0x00, 0x00, 0x93, 0x85, 0x75, 0x0a, 
-	0x93, 0x08, 0x70, 0x00, 0x73, 0x00, 0x00, 0x00, 
-	0x93, 0x08, 0x10, 0x00, 0x73, 0x00, 0x00, 0x00, 
-	0x63, 0x1e, 0x05, 0x00, 0x17, 0x05, 0x00, 0x00, 
-	0x13, 0x05, 0x45, 0x07, 0x97, 0x05, 0x00, 0x00, 
-	0x93, 0x85, 0x35, 0x08, 0x93, 0x08, 0x70, 0x00, 
-	0x73, 0x00, 0x00, 0x00, 0x93, 0x08, 0xd0, 0x05, 
-	0x73, 0x00, 0x00, 0x00, 0xef, 0xf0, 0x9f, 0xff, 
-	0x2f, 0x62, 0x72, 0x6b, 0x00, 0x00, 0x2f, 0x6f, 
-	0x70, 0x65, 0x6e, 0x61, 0x74, 0x00, 0x00, 0x2f, 
-	0x6d, 0x6b, 0x64, 0x69, 0x72, 0x5f, 0x00, 0x00, 
-	0x2f, 0x67, 0x65, 0x74, 0x63, 0x77, 0x64, 0x00, 
-	0x00, 0x2f, 0x67, 0x65, 0x74, 0x70, 0x69, 0x64, 
-	0x00, 0x00, 0x2f, 0x67, 0x65, 0x74, 0x70, 0x70, 
-	0x69, 0x64, 0x00, 0x00, 0x2f, 0x64, 0x75, 0x70, 
-	0x00, 0x00, 0x2f, 0x64, 0x75, 0x70, 0x32, 0x00, 
-	0x00, 0x2f, 0x72, 0x65, 0x61, 0x64, 0x00, 0x00, 
-	0x2f, 0x77, 0x72, 0x69, 0x74, 0x65, 0x00, 0x00, 
-	0x2f, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x00, 0x00, 
-	0x2f, 0x65, 0x78, 0x69, 0x74, 0x00, 0x00, 0x2f, 
-	0x63, 0x68, 0x64, 0x69, 0x72, 0x00, 0x00, 0x00, 
-	0x00, 0x00, 0x00, 0x00, 
-};
-#endif
-
 #ifdef _hello
 uchar initcode[] = {
    0x13, 0x00, 0x00, 0x00,     // nop
diff --git a/kernel/kernel b/kernel/kernel
deleted file mode 100755
index f638922fcfc8090098749a2bc96715b3f302b869..0000000000000000000000000000000000000000
Binary files a/kernel/kernel and /dev/null differ
diff --git a/script/exp_code.py b/script/exp_code.py
index 2473709ebc0d344cc4f58b77099b217cc250ac48..a3e093717779b44721d1fa378b477fcea17eedfb 100755
--- a/script/exp_code.py
+++ b/script/exp_code.py
@@ -10,6 +10,7 @@ def get_hex_code(input_file, output_file):
             code_bin = fp.read(1)
     with open(output_file, "w") as ff:
          i = 0
+         ff.write('#include "include/types.h"\n')
          ff.write('uchar initcode[] = {')
          for code in hex_code:
              if i % 8 == 0:
@@ -17,5 +18,6 @@ def get_hex_code(input_file, output_file):
              ff.write(code + ', ')
              i = i + 1
          ff.write('\n};')
+         ff.write('\nint initcodesize=sizeof(initcode);\n')
 
 get_hex_code("./user/initcode", "./user/initcode.hex")
diff --git a/script/initcode.c b/script/initcode.c
new file mode 100644
index 0000000000000000000000000000000000000000..173e0a983f48ee7dd055bc216a9dcaa909685e3c
--- /dev/null
+++ b/script/initcode.c
@@ -0,0 +1,32 @@
+#include "include/types.h"
+// a user program that calls exec("/init")
+// od -t xC initcode
+#ifdef _cmd
+uchar initcode[] = {
+  0x17, 0x05, 0x00, 0x00, 0x13, 0x05, 0x45, 0x02,
+  0x97, 0x05, 0x00, 0x00, 0x93, 0x85, 0x35, 0x02,
+  0x93, 0x08, 0x70, 0x00, 0x73, 0x00, 0x00, 0x00,
+  0x93, 0x08, 0x20, 0x00, 0x73, 0x00, 0x00, 0x00,
+  0xef, 0xf0, 0x9f, 0xff, 0x2f, 0x69, 0x6e, 0x69,
+  0x74, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00,
+};
+#endif
+
+#ifdef _hello
+uchar initcode[] = {
+   0x13, 0x00, 0x00, 0x00,     // nop
+   0x13, 0x00, 0x00, 0x00,     // nop 
+   0x13, 0x00, 0x00, 0x00,     // nop 
+	   // <start>
+   0x17, 0x05, 0x00, 0x00,     // auipc a0, 0x0 
+   0x13, 0x05, 0x05, 0x00,     // mv a0, a0 
+   0x93, 0x08, 0x60, 0x01,     // li a7, 22 
+   0x73, 0x00, 0x00, 0x00,     // ecall 
+   0xef, 0xf0, 0x1f, 0xff,     // jal ra, <start>
+   // <loop>
+   0xef, 0x00, 0x00, 0x00,     // jal ra, <loop>
+};//printhello
+#endif
+int initcodesize=sizeof(initcode);
+
diff --git a/user/initcode.S b/user/initcode.S
new file mode 100644
index 0000000000000000000000000000000000000000..656395c91c65dd4ae1113f6adf5f56fa35a7a39d
--- /dev/null
+++ b/user/initcode.S
@@ -0,0 +1,28 @@
+# Initial process that execs /init.
+# This code runs in user space.
+
+#include "include/sysnum.h"
+
+# exec(init, argv)
+.globl start
+start:
+        la a0, init
+        la a1, argv
+        li a7, SYS_exec
+        ecall
+
+# for(;;) exit();
+exit:
+        li a7, SYS_exit
+        ecall
+        jal exit
+
+# char init[] = "/init\0";
+init:
+  .string "/init\0"
+
+# char *argv[] = { init, 0 };
+.p2align 2
+argv:
+  .long init
+  .long 0
diff --git a/user/initcode.hex b/user/initcode.hex
new file mode 100644
index 0000000000000000000000000000000000000000..91b0bc5ac4673b9539013c9d026d698a663662ec
--- /dev/null
+++ b/user/initcode.hex
@@ -0,0 +1,11 @@
+#include "include/types.h"
+uchar initcode[] = {
+	0x17, 0x05, 0x00, 0x00, 0x13, 0x05, 0x45, 0x02, 
+	0x97, 0x05, 0x00, 0x00, 0x93, 0x85, 0x35, 0x02, 
+	0x93, 0x08, 0x70, 0x00, 0x73, 0x00, 0x00, 0x00, 
+	0x93, 0x08, 0xd0, 0x05, 0x73, 0x00, 0x00, 0x00, 
+	0xef, 0xf0, 0x9f, 0xff, 0x2f, 0x69, 0x6e, 0x69, 
+	0x74, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 
+	0x00, 0x00, 0x00, 0x00, 
+};
+int initcodesize=sizeof(initcode);