Index: arch/ia64/include/context.h
===================================================================
--- arch/ia64/include/context.h	(revision c23fd6b160178fed3e202b20d368f0b043f9c86b)
+++ arch/ia64/include/context.h	(revision d5d2a3ff84d6d7012c3225ebf93d3becc7bfeb68)
@@ -38,4 +38,13 @@
 #define SP_DELTA	0
 
+#ifdef context_set
+#undef context_set
+#endif
+
+#define context_set(c, _pc, stack, size) 	\
+	(c)->pc = (__address) _pc;		\
+	(c)->bsp = (__address) stack;		\
+	(c)->sp = ((__address) stack) + (size) - SP_DELTA;
+
 struct context {
 
@@ -47,5 +56,5 @@
 	__u64 ar_unat_callee;
 	__u64 ar_rsc;
-	__u64 ar_bsp;
+	__u64 bsp;	/* ar_bsp */
 	__u64 ar_rnat;
 	__u64 ar_lc;
Index: include/context.h
===================================================================
--- include/context.h	(revision c23fd6b160178fed3e202b20d368f0b043f9c86b)
+++ include/context.h	(revision d5d2a3ff84d6d7012c3225ebf93d3becc7bfeb68)
@@ -30,7 +30,12 @@
 #define __CONTEXT_H__
 
+#include <arch/types.h>
 #include <typedefs.h>
-#include "fpu_context.h"
 
+#ifndef context_set
+#define context_set(c, _pc, stack, size) 	\
+	(c)->pc = (__address) (_pc);		\
+	(c)->sp = ((__address) (stack)) + (size) - SP_DELTA;
+#endif /* context_set */
 
 extern int context_save(context_t *c);
Index: src/main/main.c
===================================================================
--- src/main/main.c	(revision c23fd6b160178fed3e202b20d368f0b043f9c86b)
+++ src/main/main.c	(revision d5d2a3ff84d6d7012c3225ebf93d3becc7bfeb68)
@@ -28,5 +28,5 @@
 
 #include <arch/asm.h>
-#include <arch/context.h>
+#include <context.h>
 #include <print.h>
 #include <panic.h>
@@ -95,6 +95,5 @@
 
 	context_save(&ctx);
-	ctx.sp = config.base + config.kernel_size - SP_DELTA;
-	ctx.pc = FADDR(main_bsp_separated_stack);
+	context_set(&ctx, FADDR(main_bsp_separated_stack), config.base + hardcoded_ktext_size + hardcoded_kdata_size + CONFIG_HEAP_SIZE, CONFIG_STACK_SIZE);
 	context_restore(&ctx);
 	/* not reached */
@@ -193,6 +192,5 @@
 	 * switch to this cpu's private stack prior to waking kmp up.
 	 */
-	CPU->saved_context.sp = (__address) &CPU->stack[CPU_STACK_SIZE-SP_DELTA];
-	CPU->saved_context.pc = FADDR(main_ap_separated_stack);
+	context_set(&CPU->saved_context, FADDR(main_ap_separated_stack), CPU->stack, CPU_STACK_SIZE);
 	context_restore(&CPU->saved_context);
 	/* not reached */
Index: src/proc/scheduler.c
===================================================================
--- src/proc/scheduler.c	(revision c23fd6b160178fed3e202b20d368f0b043f9c86b)
+++ src/proc/scheduler.c	(revision d5d2a3ff84d6d7012c3225ebf93d3becc7bfeb68)
@@ -233,6 +233,5 @@
 	 */
 	context_save(&CPU->saved_context);
-	CPU->saved_context.sp = (__address) &CPU->stack[CPU_STACK_SIZE-SP_DELTA];
-	CPU->saved_context.pc = FADDR(scheduler_separated_stack);
+	context_set(&CPU->saved_context, FADDR(scheduler_separated_stack), CPU->stack, CPU_STACK_SIZE);
 	context_restore(&CPU->saved_context);
 	/* not reached */
Index: src/proc/thread.c
===================================================================
--- src/proc/thread.c	(revision c23fd6b160178fed3e202b20d368f0b043f9c86b)
+++ src/proc/thread.c	(revision d5d2a3ff84d6d7012c3225ebf93d3becc7bfeb68)
@@ -166,6 +166,5 @@
 		
 		context_save(&t->saved_context);
-		t->saved_context.pc = FADDR(cushion);
-		t->saved_context.sp = (__address) &t->kstack[THREAD_STACK_SIZE-SP_DELTA];
+		context_set(&t->saved_context, FADDR(cushion), t->kstack, THREAD_STACK_SIZE);
 
 		pri = cpu_priority_high();
