Index: kernel/arch/amd64/include/context_offset.h
===================================================================
--- kernel/arch/amd64/include/context_offset.h	(revision baac91190efc683948e46ad8fc0384ce74181ea5)
+++ kernel/arch/amd64/include/context_offset.h	(revision 1dbfe988113fb7d5276fcfd861f794b1971bb5bc)
@@ -38,5 +38,10 @@
 #define OFFSET_R14 0x30
 #define OFFSET_R15 0x38
-#define OFFSET_IPL 0x40
+
+#ifdef KERNEL
+# define OFFSET_IPL 0x40
+#else
+# define OFFSET_TLS 0x40
+#endif
 
 #ifdef __ASM__
@@ -45,8 +50,27 @@
 # pc: return address
 .macro CONTEXT_SAVE_ARCH_CORE ctx:req pc:req
+	movq \pc, OFFSET_PC(\ctx)
+	movq %rsp, OFFSET_SP(\ctx)
+	
+	movq %rbx, OFFSET_RBX(\ctx)
+	movq %rbp, OFFSET_RBP(\ctx)
+	movq %r12, OFFSET_R12(\ctx)
+	movq %r13, OFFSET_R13(\ctx)
+	movq %r14, OFFSET_R14(\ctx)
+	movq %r15, OFFSET_R15(\ctx)
 .endm
 
 # ctx: address of the structure with saved context 
 .macro CONTEXT_RESTORE_ARCH_CORE ctx:req pc:req
+	movq OFFSET_R15(\ctx), %r15
+	movq OFFSET_R14(\ctx), %r14
+	movq OFFSET_R13(\ctx), %r13
+	movq OFFSET_R12(\ctx), %r12
+	movq OFFSET_RBP(\ctx), %rbp
+	movq OFFSET_RBX(\ctx), %rbx	
+	
+	movq OFFSET_SP(\ctx), %rsp   # ctx->sp -> %rsp
+	
+	movq OFFSET_PC(\ctx), \pc
 .endm
 
Index: kernel/arch/amd64/src/context.S
===================================================================
--- kernel/arch/amd64/src/context.S	(revision baac91190efc683948e46ad8fc0384ce74181ea5)
+++ kernel/arch/amd64/src/context.S	(revision 1dbfe988113fb7d5276fcfd861f794b1971bb5bc)
@@ -41,14 +41,7 @@
 context_save_arch:
 	movq (%rsp), %rdx     # the caller's return %eip
+
 	# In %edi is passed 1st argument
-	movq %rdx, OFFSET_PC(%rdi)
-	movq %rsp, OFFSET_SP(%rdi)
-	
-	movq %rbx, OFFSET_RBX(%rdi)
-	movq %rbp, OFFSET_RBP(%rdi)
-	movq %r12, OFFSET_R12(%rdi)
-	movq %r13, OFFSET_R13(%rdi)
-	movq %r14, OFFSET_R14(%rdi)
-	movq %r15, OFFSET_R15(%rdi)
+	CONTEXT_SAVE_ARCH_CORE %rdi %rdx 
 	
 	xorq %rax,%rax		# context_save returns 1
@@ -63,14 +56,7 @@
 #
 context_restore_arch:	
-	movq OFFSET_R15(%rdi), %r15
-	movq OFFSET_R14(%rdi), %r14
-	movq OFFSET_R13(%rdi), %r13
-	movq OFFSET_R12(%rdi), %r12
-	movq OFFSET_RBP(%rdi), %rbp
-	movq OFFSET_RBX(%rdi), %rbx	
-	
-	movq OFFSET_SP(%rdi), %rsp   # ctx->sp -> %rsp
-	
-	movq OFFSET_PC(%rdi), %rdx
+
+	CONTEXT_RESTORE_ARCH_CORE %rdi %rdx
+
 	movq %rdx,(%rsp)
 
Index: pace/lib/libc/arch/amd64/include/context_offset.h
===================================================================
--- uspace/lib/libc/arch/amd64/include/context_offset.h	(revision baac91190efc683948e46ad8fc0384ce74181ea5)
+++ 	(revision )
@@ -1,12 +1,0 @@
-/* This file is automatically generated by gencontext.c. */
-#define OFFSET_SP  0x0
-#define OFFSET_PC  0x8
-#define OFFSET_RBX 0x10
-#define OFFSET_RBP 0x18
-#define OFFSET_R12 0x20
-#define OFFSET_R13 0x28
-#define OFFSET_R14 0x30
-#define OFFSET_R15 0x38
-#define OFFSET_TLS 0x40
- 
- 
Index: uspace/lib/libc/arch/amd64/src/fibril.S
===================================================================
--- uspace/lib/libc/arch/amd64/src/fibril.S	(revision baac91190efc683948e46ad8fc0384ce74181ea5)
+++ uspace/lib/libc/arch/amd64/src/fibril.S	(revision 1dbfe988113fb7d5276fcfd861f794b1971bb5bc)
@@ -32,5 +32,5 @@
 .global context_restore
 
-#include <libarch/context_offset.h>
+#include <kernel/arch/context_offset.h>
 
 ## Save current CPU context
@@ -41,15 +41,8 @@
 context_save:
 	movq (%rsp), %rdx     # the caller's return %eip
+	
 	# In %edi is passed 1st argument
-	movq %rdx, OFFSET_PC(%rdi)
-	movq %rsp, OFFSET_SP(%rdi)
+	CONTEXT_SAVE_ARCH_CORE %rdi %rdx 
 	
-	movq %rbx, OFFSET_RBX(%rdi)
-	movq %rbp, OFFSET_RBP(%rdi)
-	movq %r12, OFFSET_R12(%rdi)
-	movq %r13, OFFSET_R13(%rdi)
-	movq %r14, OFFSET_R14(%rdi)
-	movq %r15, OFFSET_R15(%rdi)
-
 	# Save TLS
 	movq %fs:0, %rax
@@ -67,14 +60,7 @@
 #
 context_restore:
-	movq OFFSET_R15(%rdi), %r15
-	movq OFFSET_R14(%rdi), %r14
-	movq OFFSET_R13(%rdi), %r13
-	movq OFFSET_R12(%rdi), %r12
-	movq OFFSET_RBP(%rdi), %rbp
-	movq OFFSET_RBX(%rdi), %rbx	
 	
-	movq OFFSET_SP(%rdi), %rsp   # ctx->sp -> %rsp
+	CONTEXT_RESTORE_ARCH_CORE %rdi %rdx
 	
-	movq OFFSET_PC(%rdi), %rdx
 	movq %rdx,(%rsp)
 
