Index: src/main/main.c
===================================================================
--- src/main/main.c	(revision e291e5de24b08ff9fa3f8278140c5a551d688caf)
+++ src/main/main.c	(revision 33ccb2cbb62c342dd41a73ca709f49a28162e301)
@@ -54,4 +54,5 @@
 #include <synch/waitq.h>
 
+#include <arch/arch.h>
 #include <arch.h>
 #include <arch/faddr.h>
@@ -107,17 +108,17 @@
 	config.cpu_count = 1;
 	config.cpu_active = 1;
-
+	
 	kernel_size = hardcoded_ktext_size + hardcoded_kdata_size + CONFIG_HEAP_SIZE;	 
 	heap_delta = PAGE_SIZE - ((hardcoded_load_address + kernel_size) % PAGE_SIZE);
 	heap_delta = (heap_delta == PAGE_SIZE) ? 0 : heap_delta;
 	kernel_size += heap_delta;
-
+	
 	config.base = hardcoded_load_address;
 	config.memory_size = get_memory_size();
 	config.kernel_size = kernel_size + CONFIG_STACK_SIZE;
-
+	
 	context_save(&ctx);
+	early_mapping(config.base + hardcoded_ktext_size + hardcoded_kdata_size + heap_delta, CONFIG_STACK_SIZE + CONFIG_HEAP_SIZE);
 	context_set(&ctx, FADDR(main_bsp_separated_stack), config.base + kernel_size, CONFIG_STACK_SIZE);
-	context_map_stack(config.base + kernel_size, CONFIG_STACK_SIZE);
 	context_restore(&ctx);
 	/* not reached */
@@ -158,5 +159,5 @@
 	cpu_init();
 	calibrate_delay_loop();
-
+	
 	timeout_init();
 	scheduler_init();
@@ -168,5 +169,6 @@
 	 */
 	m = vm_create(GET_PTL0_ADDRESS());
-	if (!m) panic("can't create kernel vm address space\n");
+	if (!m)
+		panic("can't create kernel vm address space\n");
 
 	/*
@@ -174,11 +176,13 @@
 	 */
 	k = task_create(m);
-	if (!k) panic("can't create kernel task\n");
-
+	if (!k)
+		panic("can't create kernel task\n");
+		
 	/*
 	 * Create the first thread.
 	 */
 	t = thread_create(kinit, NULL, k, 0);
-	if (!t) panic("can't create kinit thread\n");
+	if (!t)
+		panic("can't create kinit thread\n");
 	thread_ready(t);
 
Index: src/proc/thread.c
===================================================================
--- src/proc/thread.c	(revision e291e5de24b08ff9fa3f8278140c5a551d688caf)
+++ src/proc/thread.c	(revision 33ccb2cbb62c342dd41a73ca709f49a28162e301)
@@ -186,5 +186,5 @@
 		spinlock_unlock(&tidlock);
 		cpu_priority_restore(pri);
-
+		
 		memsetb(frame_ks, THREAD_STACK_SIZE, 0);
 		link_initialize(&t->rq_link);
@@ -194,5 +194,4 @@
 		t->kstack = (__u8 *) frame_ks;
 		t->ustack = (__u8 *) frame_us;
-		
 		
 		context_save(&t->saved_context);
