Index: arch/amd64/include/context.h
===================================================================
--- arch/amd64/include/context.h	(revision 22f776926d191e0d2eb1be9adfc28070c7ce11d4)
+++ arch/amd64/include/context.h	(revision 4b2c872d993209cc50bfe660125b5f9537183b14)
@@ -45,6 +45,6 @@
  */
 struct context {
-    __u64 sp;
-    __u64 pc;
+    __address sp;
+    __address pc;
     
     __u64 rbx;
Index: arch/amd64/src/context.S
===================================================================
--- arch/amd64/src/context.S	(revision 22f776926d191e0d2eb1be9adfc28070c7ce11d4)
+++ arch/amd64/src/context.S	(revision 4b2c872d993209cc50bfe660125b5f9537183b14)
@@ -29,6 +29,6 @@
 .text
 
-.global context_save
-.global context_restore
+.global context_save_arch
+.global context_restore_arch
 
 #include <arch/context_offset.h>
@@ -36,8 +36,8 @@
 ## Save current CPU context
 #
-# Save CPU context to the kernel_context variable
+# Save CPU context to context_t variable
 # pointed by the 1st argument. Returns 1 in EAX.
 #
-context_save:
+context_save_arch:
 	movq (%rsp), %rdx     # the caller's return %eip
 	# In %edi is passed 1st argument
@@ -59,8 +59,8 @@
 ## Restore current CPU context
 #
-# Restore CPU context from the kernel_context variable
+# Restore CPU context from context_t variable
 # pointed by the 1st argument. Returns 0 in EAX.
 #
-context_restore:	
+context_restore_arch:	
 	movq OFFSET_R15(%rdi), %r15
 	movq OFFSET_R14(%rdi), %r14
Index: arch/ia32/include/context.h
===================================================================
--- arch/ia32/include/context.h	(revision 22f776926d191e0d2eb1be9adfc28070c7ce11d4)
+++ arch/ia32/include/context.h	(revision 4b2c872d993209cc50bfe660125b5f9537183b14)
@@ -47,6 +47,6 @@
  */
 struct context {
-	__u32 sp;
-	__u32 pc;
+	__address sp;
+	__address pc;
 	__u32 ebx;
 	__u32 esi;
Index: arch/ia32/src/context.s
===================================================================
--- arch/ia32/src/context.s	(revision 22f776926d191e0d2eb1be9adfc28070c7ce11d4)
+++ arch/ia32/src/context.s	(revision 4b2c872d993209cc50bfe660125b5f9537183b14)
@@ -29,14 +29,14 @@
 .text
 
-.global context_save
-.global context_restore
+.global context_save_arch
+.global context_restore_arch
 
 
 ## Save current CPU context
 #
-# Save CPU context to the kernel_context variable
+# Save CPU context to the context_t variable
 # pointed by the 1st argument. Returns 1 in EAX.
 #
-context_save:
+context_save_arch:
 	movl 0(%esp),%eax	# the caller's return %eip
 	movl 4(%esp),%edx	# address of the kernel_context variable to save context to
@@ -54,10 +54,10 @@
 
 
-## Restore current CPU context
+## Restore saved CPU context
 #
-# Restore CPU context from the kernel_context variable
+# Restore CPU context from context_t variable
 # pointed by the 1st argument. Returns 0 in EAX.
 #
-context_restore:
+context_restore_arch:
 	movl 4(%esp),%eax	# address of the kernel_context variable to restore context from
 	movl 0(%eax),%esp	# ctx->sp -> %esp
Index: arch/ia64/include/context.h
===================================================================
--- arch/ia64/include/context.h	(revision 22f776926d191e0d2eb1be9adfc28070c7ce11d4)
+++ arch/ia64/include/context.h	(revision 4b2c872d993209cc50bfe660125b5f9537183b14)
@@ -31,4 +31,5 @@
 
 #include <arch/types.h>
+#include <typedefs.h>
 #include <align.h>
 
@@ -51,5 +52,5 @@
 	(c)->pc = (__address) _pc;							\
 	(c)->bsp = ((__address) stack) + ALIGN(sizeof(the_t), STACK_ALIGNMENT);		\
-	(c)->sp = ((__address) stack) + ALIGN((size) - SP_DELTA, STACK_ALIGNMENT);
+	(c)->sp = ((__address) stack) + ALIGN((size), STACK_ALIGNMENT) - SP_DELTA;
 
 /*
@@ -66,5 +67,5 @@
 	__u64 ar_unat_callee;
 	__u64 ar_rsc;
-	__u64 bsp;	/* ar_bsp */
+	__address bsp;		/* ar_bsp */
 	__u64 ar_rnat;
 	__u64 ar_lc;
@@ -78,5 +79,5 @@
 	__u64 r6;
 	__u64 r7;
-	__u64 sp;		/* r12 */
+	__address sp;		/* r12 */
 	__u64 r13;
 	
@@ -84,5 +85,5 @@
 	 * Branch registers
 	 */
-	__u64 pc;		/* b0 */
+	__address pc;		/* b0 */
 	__u64 b1;
 	__u64 b2;
Index: arch/ia64/src/context.S
===================================================================
--- arch/ia64/src/context.S	(revision 22f776926d191e0d2eb1be9adfc28070c7ce11d4)
+++ arch/ia64/src/context.S	(revision 4b2c872d993209cc50bfe660125b5f9537183b14)
@@ -29,8 +29,8 @@
 .text
 
-.global context_save
-.global context_restore
+.global context_save_arch
+.global context_restore_arch
 
-context_save:
+context_save_arch:
 	alloc loc0 = ar.pfs, 1, 8, 0, 0
 	mov loc1 = ar.unat	;;
@@ -113,5 +113,5 @@
 	br.ret.sptk.many b0
 
-context_restore:
+context_restore_arch:
 	alloc loc0 = ar.pfs, 1, 8, 0, 0	;;
 
Index: arch/mips32/include/context.h
===================================================================
--- arch/mips32/include/context.h	(revision 22f776926d191e0d2eb1be9adfc28070c7ce11d4)
+++ arch/mips32/include/context.h	(revision 4b2c872d993209cc50bfe660125b5f9537183b14)
@@ -49,6 +49,6 @@
  */
 struct context {
-	__u32 sp;
-	__u32 pc;
+	__address sp;
+	__address pc;
 	
 	__u32 s0;
Index: arch/mips32/src/context.S
===================================================================
--- arch/mips32/src/context.S	(revision 22f776926d191e0d2eb1be9adfc28070c7ce11d4)
+++ arch/mips32/src/context.S	(revision 4b2c872d993209cc50bfe660125b5f9537183b14)
@@ -37,6 +37,6 @@
 .set nomacro
 
-.global context_save
-.global context_restore
+.global context_save_arch
+.global context_restore_arch
 
 .macro CONTEXT_STORE r
@@ -73,5 +73,5 @@
 
 	
-context_save:
+context_save_arch:
 	CONTEXT_STORE $a0
 
@@ -80,5 +80,5 @@
 	li $2, 1	
 	
-context_restore:
+context_restore_arch:
 	CONTEXT_LOAD $a0
 
Index: arch/ppc32/include/context.h
===================================================================
--- arch/ppc32/include/context.h	(revision 22f776926d191e0d2eb1be9adfc28070c7ce11d4)
+++ arch/ppc32/include/context.h	(revision 4b2c872d993209cc50bfe660125b5f9537183b14)
@@ -36,5 +36,5 @@
 struct context {
 	__u32 r0;
-	__u32 sp;
+	__address sp;
 	__u32 r2;
 	__u32 r3;
@@ -67,5 +67,5 @@
 	__u32 r30;
 	__u32 r31;
-	__u32 pc;
+	__address pc;
 	ipl_t ipl;
 } __attribute__ ((packed));
Index: arch/ppc32/src/context.S
===================================================================
--- arch/ppc32/src/context.S	(revision 22f776926d191e0d2eb1be9adfc28070c7ce11d4)
+++ arch/ppc32/src/context.S	(revision 4b2c872d993209cc50bfe660125b5f9537183b14)
@@ -31,8 +31,8 @@
 .text   
 
-.global context_save
-.global context_restore
+.global context_save_arch
+.global context_restore_arch
 
-context_save:
+context_save_arch:
 	REGISTERS_STORE r3
 	
@@ -44,5 +44,5 @@
 	blr
 	
-context_restore:
+context_restore_arch:
 	REGISTERS_LOAD r3
 	
Index: include/context.h
===================================================================
--- include/context.h	(revision 22f776926d191e0d2eb1be9adfc28070c7ce11d4)
+++ include/context.h	(revision 4b2c872d993209cc50bfe660125b5f9537183b14)
@@ -32,4 +32,6 @@
 #include <arch/types.h>
 #include <typedefs.h>
+#include <arch/context.h>
+
 
 #ifndef context_set
@@ -39,6 +41,44 @@
 #endif /* context_set */
 
-extern int context_save(context_t *c);
-extern void context_restore(context_t *c) __attribute__ ((noreturn));
+extern int context_save_arch(context_t *c);
+extern void context_restore_arch(context_t *c) __attribute__ ((noreturn));
+
+/** Save register context.
+ *
+ * Save current register context (including stack pointers)
+ * to context structure.
+ *
+ * Note that call to context_restore() will return at the same
+ * address as the corresponding call to context_save().
+ *
+ * @param c Context structure.
+ *
+ * @return context_save() returns 1, context_restore() returns 0.
+ */
+static inline int context_save(context_t *c)
+{
+	return context_save_arch(c);
+}
+
+/** Restore register context.
+ *
+ * Restore previously saved register context (including stack pointers)
+ * from context structure.
+ *
+ * Note that this function does not normally return.
+ * Instead, it returns at the same address as the
+ * corresponding call to context_save(), the only
+ * difference being return value.
+ *
+ * Note that content of any local variable defined by
+ * the caller of context_save() is undefined after
+ * context_restore().
+ *
+ * @param c Context structure.
+ */
+static inline void context_restore(context_t *c)
+{
+	context_restore_arch(c);
+}
 
 #endif
Index: src/main/main.c
===================================================================
--- src/main/main.c	(revision 22f776926d191e0d2eb1be9adfc28070c7ce11d4)
+++ src/main/main.c	(revision 4b2c872d993209cc50bfe660125b5f9537183b14)
@@ -247,5 +247,5 @@
 	 * switch to this cpu's private stack prior to waking kmp up.
 	 */
-	context_set(&CPU->saved_context, FADDR(main_ap_separated_stack), CPU->stack, CPU_STACK_SIZE);
+	context_set(&CPU->saved_context, FADDR(main_ap_separated_stack), (__address) CPU->stack, CPU_STACK_SIZE);
 	context_restore(&CPU->saved_context);
 	/* not reached */
Index: src/proc/scheduler.c
===================================================================
--- src/proc/scheduler.c	(revision 22f776926d191e0d2eb1be9adfc28070c7ce11d4)
+++ src/proc/scheduler.c	(revision 4b2c872d993209cc50bfe660125b5f9537183b14)
@@ -314,5 +314,5 @@
 	 */
 	context_save(&CPU->saved_context);
-	context_set(&CPU->saved_context, FADDR(scheduler_separated_stack), CPU->stack, CPU_STACK_SIZE);
+	context_set(&CPU->saved_context, FADDR(scheduler_separated_stack), (__address) CPU->stack, CPU_STACK_SIZE);
 	context_restore(&CPU->saved_context);
 	/* not reached */
Index: src/proc/thread.c
===================================================================
--- src/proc/thread.c	(revision 22f776926d191e0d2eb1be9adfc28070c7ce11d4)
+++ src/proc/thread.c	(revision 4b2c872d993209cc50bfe660125b5f9537183b14)
@@ -196,5 +196,5 @@
 		
 		context_save(&t->saved_context);
-		context_set(&t->saved_context, FADDR(cushion), t->kstack, THREAD_STACK_SIZE);
+		context_set(&t->saved_context, FADDR(cushion), (__address) t->kstack, THREAD_STACK_SIZE);
 		
 		the_initialize((the_t *) t->kstack);
Index: src/synch/waitq.c
===================================================================
--- src/synch/waitq.c	(revision 22f776926d191e0d2eb1be9adfc28070c7ce11d4)
+++ src/synch/waitq.c	(revision 4b2c872d993209cc50bfe660125b5f9537183b14)
@@ -31,4 +31,5 @@
 #include <synch/spinlock.h>
 #include <proc/thread.h>
+#include <proc/scheduler.h>
 #include <arch/asm.h>
 #include <arch/types.h>
Index: tools/amd64/gencontext.c
===================================================================
--- tools/amd64/gencontext.c	(revision 22f776926d191e0d2eb1be9adfc28070c7ce11d4)
+++ tools/amd64/gencontext.c	(revision 4b2c872d993209cc50bfe660125b5f9537183b14)
@@ -4,4 +4,5 @@
 typedef long long __u64;
 typedef __u64 ipl_t;
+typedef __u64 __address;
 
 #define __amd64_TYPES_H__
Index: tools/mips32/gencontext.c
===================================================================
--- tools/mips32/gencontext.c	(revision 22f776926d191e0d2eb1be9adfc28070c7ce11d4)
+++ tools/mips32/gencontext.c	(revision 4b2c872d993209cc50bfe660125b5f9537183b14)
@@ -1,7 +1,7 @@
 #include <stdio.h>
-
 
 typedef unsigned int __u32;
 typedef __u32 ipl_t;
+typedef __u32 __address;
 
 #define __mips32_TYPES_H__
