Index: kernel/arch/amd64/include/arch/asm.h
===================================================================
--- kernel/arch/amd64/include/arch/asm.h	(revision 193d280c34f38846eccfa1ecce71975f9ad92398)
+++ kernel/arch/amd64/include/arch/asm.h	(revision 6d87dce26627d7694e5261b909baec0bd3036471)
@@ -206,12 +206,4 @@
 	} else
 		*port = val;
-}
-
-/** Swap Hidden part of GS register with visible one */
-NO_TRACE static inline void swapgs(void)
-{
-	asm volatile (
-		"swapgs"
-	);
 }
 
Index: kernel/arch/amd64/include/arch/context_struct.ag
===================================================================
--- kernel/arch/amd64/include/arch/context_struct.ag	(revision 193d280c34f38846eccfa1ecce71975f9ad92398)
+++ kernel/arch/amd64/include/arch/context_struct.ag	(revision 6d87dce26627d7694e5261b909baec0bd3036471)
@@ -75,4 +75,8 @@
                         type : uint64_t
                 },
+                {
+                        name : tp,
+                        type : uint64_t
+                },
 
                 {
Index: kernel/arch/amd64/include/arch/cpu.h
===================================================================
--- kernel/arch/amd64/include/arch/cpu.h	(revision 193d280c34f38846eccfa1ecce71975f9ad92398)
+++ kernel/arch/amd64/include/arch/cpu.h	(revision 6d87dce26627d7694e5261b909baec0bd3036471)
@@ -56,9 +56,10 @@
 
 /* MSR registers */
-#define AMD_MSR_STAR    0xc0000081
-#define AMD_MSR_LSTAR   0xc0000082
-#define AMD_MSR_SFMASK  0xc0000084
-#define AMD_MSR_FS      0xc0000100
-#define AMD_MSR_GS      0xc0000101
+#define AMD_MSR_STAR		0xc0000081
+#define AMD_MSR_LSTAR		0xc0000082
+#define AMD_MSR_SFMASK		0xc0000084
+#define AMD_MSR_FS		0xc0000100
+#define AMD_MSR_GS		0xc0000101
+#define AMD_MSR_GS_KERNEL	0xc0000102
 
 #ifndef __ASM__
Index: kernel/arch/amd64/include/arch/kseg.h
===================================================================
--- kernel/arch/amd64/include/arch/kseg.h	(revision 6d87dce26627d7694e5261b909baec0bd3036471)
+++ kernel/arch/amd64/include/arch/kseg.h	(revision 6d87dce26627d7694e5261b909baec0bd3036471)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2016 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup amd64 
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_KSEG_H_
+#define KERN_amd64_KSEG_H_
+
+extern void kseg_init(void);
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/arch/kseg_struct.ag
===================================================================
--- kernel/arch/amd64/include/arch/kseg_struct.ag	(revision 6d87dce26627d7694e5261b909baec0bd3036471)
+++ kernel/arch/amd64/include/arch/kseg_struct.ag	(revision 6d87dce26627d7694e5261b909baec0bd3036471)
@@ -0,0 +1,51 @@
+# Copyright (c) 2016 Jakub Jermar 
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+{
+        name : kseg,
+
+        includes : [
+                {
+                        include : <typedefs.h>
+                }
+        ],
+
+        members : [
+                {
+                        name : ustack_rsp,
+                        type : uint64_t
+                },
+                {
+                        name : kstack_rsp,
+                        type : uint64_t
+                },
+                {
+                        name : fsbase,
+                        type : uint64_t
+                }
+        ]
+}
Index: kernel/arch/amd64/include/arch/proc/thread.h
===================================================================
--- kernel/arch/amd64/include/arch/proc/thread.h	(revision 193d280c34f38846eccfa1ecce71975f9ad92398)
+++ kernel/arch/amd64/include/arch/proc/thread.h	(revision 6d87dce26627d7694e5261b909baec0bd3036471)
@@ -36,12 +36,8 @@
 #define KERN_amd64_THREAD_H_
 
-/* CAUTION: keep these in sync with low level assembly code in syscall_entry */
-#define SYSCALL_USTACK_RSP  0
-#define SYSCALL_KSTACK_RSP  1
+#include <typedefs.h>
 
 typedef struct {
-	sysarg_t tls;
-	/** User and kernel RSP for syscalls. */
-	uint64_t syscall_rsp[2];
+	uint64_t kstack_rsp;
 } thread_arch_t;
 
Index: kernel/arch/amd64/include/arch/vreg.h
===================================================================
--- kernel/arch/amd64/include/arch/vreg.h	(revision 6d87dce26627d7694e5261b909baec0bd3036471)
+++ kernel/arch/amd64/include/arch/vreg.h	(revision 6d87dce26627d7694e5261b909baec0bd3036471)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2016 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup amd64 
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_VREG_H_
+#define KERN_amd64_VREG_H_
+
+#define VREG_TP	0
+
+#ifndef __ASM__
+
+#include <typedefs.h>
+
+extern uint64_t *vreg_ptr;
+
+extern void vreg_init(void);
+
+#endif /* __ASM__ */
+
+#endif
+
+/** @}
+ */
