Index: arch/ia64/include/context.h
===================================================================
--- arch/ia64/include/context.h	(revision 50fe6209a60488b15153a65e9d3d222eae0168f9)
+++ arch/ia64/include/context.h	(revision b6d4566fc9565b3a6eff5c6344350e4dbf778359)
@@ -37,5 +37,5 @@
 
 /*
- * context_save() and context_restore() are both leaf procedures.
+ * context_save_arch() and context_restore_arch() are both leaf procedures.
  * No need to allocate scratch area.
  *
@@ -48,10 +48,12 @@
 #endif
 
-/*RSE stack should begin under bottom of stack @ kernel*/
-#define context_set(c, _pc, stack, size) 								\
-	(c)->pc = (__address) _pc;									\
-	(c)->bsp = ((__address) stack) + ALIGN_UP((size), STACK_ALIGNMENT) ;	\
-	(c)->ar_pfs &= PFM_MASK; 									\
-	(c)->sp = ((__address) stack) + ALIGN_UP((size), STACK_ALIGNMENT) - SP_DELTA;
+/* RSE stack starts at the bottom of memory stack. */
+#define context_set(c, _pc, stack, size)								\
+	do {												\
+		(c)->pc = (__address) _pc;								\
+		(c)->bsp = ((__address) stack) + ALIGN_UP((size), REGISTER_STACK_ALIGNMENT);		\
+		(c)->ar_pfs &= PFM_MASK; 								\
+		(c)->sp = ((__address) stack) + ALIGN_UP((size), STACK_ALIGNMENT) - SP_DELTA;		\
+	} while (0);
 
 /*
@@ -123,5 +125,3 @@
 };
 
-
-
 #endif
Index: arch/ia64/include/mm/tlb.h
===================================================================
--- arch/ia64/include/mm/tlb.h	(revision 50fe6209a60488b15153a65e9d3d222eae0168f9)
+++ arch/ia64/include/mm/tlb.h	(revision b6d4566fc9565b3a6eff5c6344350e4dbf778359)
@@ -42,5 +42,6 @@
 #define DTR_KERNEL	0
 #define ITR_KERNEL	0
-#define DTR_KSTACK	1
+#define DTR_KSTACK1	1
+#define DTR_KSTACK2	2
 
 /** Portion of TLB insertion format data structure. */
Index: arch/ia64/src/ivt.S
===================================================================
--- arch/ia64/src/ivt.S	(revision 50fe6209a60488b15153a65e9d3d222eae0168f9)
+++ arch/ia64/src/ivt.S	(revision b6d4566fc9565b3a6eff5c6344350e4dbf778359)
@@ -33,9 +33,6 @@
 #include <align.h>
 
-
 #define FRS_TO_SAVE 30
 #define STACK_ITEMS		(19 + FRS_TO_SAVE*2)
-//#define STACK_ITEMS		19 		
-	/* 30*2 for FPU registers */
 #define STACK_FRAME_SIZE	ALIGN_UP((STACK_ITEMS*STACK_ITEM_SIZE) + STACK_SCRATCH_AREA_SIZE, STACK_ALIGNMENT)
 
Index: arch/ia64/src/proc/scheduler.c
===================================================================
--- arch/ia64/src/proc/scheduler.c	(revision 50fe6209a60488b15153a65e9d3d222eae0168f9)
+++ arch/ia64/src/proc/scheduler.c	(revision b6d4566fc9565b3a6eff5c6344350e4dbf778359)
@@ -44,10 +44,11 @@
 	base = ALIGN_DOWN(config.base, 1<<KERNEL_PAGE_WIDTH);
 
-	if ((__address) THREAD->kstack < base || (__address) THREAD->kstack > base + (1<<KERNEL_PAGE_WIDTH)) {
+	if ((__address) THREAD->kstack < base || (__address) THREAD->kstack > base + (1<<(KERNEL_PAGE_WIDTH))) {
 		/*
 		 * Kernel stack of this thread is not mapped by DTR[TR_KERNEL].
-		 * Use DTR[TR_KSTACK] to map it.
+		 * Use DTR[TR_KSTACK1] and DTR[TR_KSTACK2] to map it.
 		 */
-		 dtlb_kernel_mapping_insert((__address) THREAD->kstack, KA2PA(THREAD->kstack), true, DTR_KSTACK);
+		dtlb_kernel_mapping_insert((__address) THREAD->kstack, KA2PA(THREAD->kstack), true, DTR_KSTACK1);
+		dtlb_kernel_mapping_insert((__address) THREAD->kstack + PAGE_SIZE, KA2PA(THREAD->kstack) + FRAME_SIZE, true, DTR_KSTACK2);
 	}
 	
Index: contrib/conf/msim.conf
===================================================================
--- contrib/conf/msim.conf	(revision 50fe6209a60488b15153a65e9d3d222eae0168f9)
+++ contrib/conf/msim.conf	(revision b6d4566fc9565b3a6eff5c6344350e4dbf778359)
@@ -6,6 +6,6 @@
 
 add rwm	mainmem		0x0			8M		load	"/dev/zero"
-add rom startmem	0x1fc00000	1024k	load	"image.boot" 
-add rwm init		0x01000000	1M		load	"init"
+add rom startmem	0x1fc00000		1024k		load	"image.boot" 
+add rwm init		0x01000000		1M		load	"init"
 
 add dprinter printer 0x10000000
Index: generic/include/config.h
===================================================================
--- generic/include/config.h	(revision 50fe6209a60488b15153a65e9d3d222eae0168f9)
+++ generic/include/config.h	(revision b6d4566fc9565b3a6eff5c6344350e4dbf778359)
@@ -37,5 +37,5 @@
 
 #define CONFIG_MEMORY_SIZE	(8 * 1024 * 1024)
-#define CONFIG_STACK_SIZE	STACK_SIZE
+
 #define CONFIG_INIT_TASKS	32
 
Index: generic/include/mm/frame.h
===================================================================
--- generic/include/mm/frame.h	(revision 50fe6209a60488b15153a65e9d3d222eae0168f9)
+++ generic/include/mm/frame.h	(revision b6d4566fc9565b3a6eff5c6344350e4dbf778359)
@@ -48,8 +48,7 @@
 #endif
 
-
 #define ZONES_MAX       16      /**< Maximum number of zones in system */
 
-#define ZONE_JOIN       0x1	/**< If possible, merge with neighberhood zones */
+#define ZONE_JOIN       0x1	/**< If possible, merge with neighbouring zones */
 
 #define FRAME_KA		0x1	/* skip frames conflicting with user address space */
Index: generic/src/cpu/cpu.c
===================================================================
--- generic/src/cpu/cpu.c	(revision 50fe6209a60488b15153a65e9d3d222eae0168f9)
+++ generic/src/cpu/cpu.c	(revision b6d4566fc9565b3a6eff5c6344350e4dbf778359)
@@ -63,5 +63,5 @@
 
 		for (i=0; i < config.cpu_count; i++) {
-			cpus[i].stack = (__u8 *) PA2KA(PFN2ADDR(frame_alloc(ONE_FRAME, FRAME_KA | FRAME_PANIC)));
+			cpus[i].stack = (__u8 *) PA2KA(PFN2ADDR(frame_alloc(STACK_FRAMES, FRAME_KA | FRAME_PANIC)));
 			
 			cpus[i].id = i;
Index: generic/src/main/main.c
===================================================================
--- generic/src/main/main.c	(revision 50fe6209a60488b15153a65e9d3d222eae0168f9)
+++ generic/src/main/main.c	(revision b6d4566fc9565b3a6eff5c6344350e4dbf778359)
@@ -93,4 +93,6 @@
 #endif
 
+#define CONFIG_STACK_SIZE	((1<<STACK_FRAMES)*STACK_SIZE)
+
 /** Bootstrap CPU main kernel routine
  *
@@ -129,6 +131,5 @@
 	
 	context_save(&ctx);
-	context_set(&ctx, FADDR(main_bsp_separated_stack), 
-		    stackaddr, CONFIG_STACK_SIZE);
+	context_set(&ctx, FADDR(main_bsp_separated_stack), stackaddr, THREAD_STACK_SIZE);
 	context_restore(&ctx);
 	/* not reached */
Index: generic/src/proc/thread.c
===================================================================
--- generic/src/proc/thread.c	(revision 50fe6209a60488b15153a65e9d3d222eae0168f9)
+++ generic/src/proc/thread.c	(revision b6d4566fc9565b3a6eff5c6344350e4dbf778359)
@@ -267,5 +267,5 @@
 	
 	/* Not needed, but good for debugging */
-	memsetb((__address)t->kstack, THREAD_STACK_SIZE, 0);
+	memsetb((__address)t->kstack, THREAD_STACK_SIZE * 1<<STACK_FRAMES, 0);
 	
 	ipl = interrupts_disable();
