Index: kernel/arch/ia32/Makefile.inc
===================================================================
--- kernel/arch/ia32/Makefile.inc	(revision 6a8ddd3712c234be2a222a7dc9d7803bc9c667b0)
+++ kernel/arch/ia32/Makefile.inc	(revision 4b334fd67169af5de794ce1053c6124e2ea71cd4)
@@ -107,4 +107,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(KARCH)/include/arch/istate_struct.ag
+	arch/$(KARCH)/include/arch/istate_struct.ag \
+	arch/$(KARCH)/include/arch/context_struct.ag
 
Index: kernel/arch/ia32/include/arch/context.h
===================================================================
--- kernel/arch/ia32/include/arch/context.h	(revision 6a8ddd3712c234be2a222a7dc9d7803bc9c667b0)
+++ kernel/arch/ia32/include/arch/context.h	(revision 4b334fd67169af5de794ce1053c6124e2ea71cd4)
@@ -37,4 +37,5 @@
 
 #include <typedefs.h>
+#include <arch/context_struct.h>
 
 #define STACK_ITEM_SIZE  4
@@ -55,18 +56,4 @@
 	} while (0)
 
-/*
- * Only save registers that must be preserved across
- * function calls.
- */
-typedef struct {
-	uintptr_t sp;
-	uintptr_t pc;
-	uint32_t ebx;
-	uint32_t esi;
-	uint32_t edi;
-	uint32_t ebp;
-	ipl_t ipl;
-} __attribute__ ((packed)) context_t;
-
 #endif
 
Index: kernel/arch/ia32/include/arch/context_offset.h
===================================================================
--- kernel/arch/ia32/include/arch/context_offset.h	(revision 6a8ddd3712c234be2a222a7dc9d7803bc9c667b0)
+++ 	(revision )
@@ -1,81 +1,0 @@
-/*
- * Copyright (c) 2008 Josef Cejka
- * 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 ia32
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_ia32_CONTEXT_OFFSET_H_
-#define KERN_ia32_CONTEXT_OFFSET_H_
-
-#define OFFSET_SP   0x00
-#define OFFSET_PC   0x04
-#define OFFSET_EBX  0x08
-#define OFFSET_ESI  0x0C
-#define OFFSET_EDI  0x10
-#define OFFSET_EBP  0x14
-
-#ifdef KERNEL
-	#define OFFSET_IPL  0x18
-#else
-	#define OFFSET_TLS  0x18
-#endif
-
-#ifdef __ASM__
-
-# ctx: address of the structure with saved context
-# pc: return address
-
-.macro CONTEXT_SAVE_ARCH_CORE ctx:req pc:req
-	movl %esp,OFFSET_SP(\ctx)	# %esp -> ctx->sp
-	movl \pc,OFFSET_PC(\ctx)	# %eip -> ctx->pc
-	movl %ebx,OFFSET_EBX(\ctx)	# %ebx -> ctx->ebx
-	movl %esi,OFFSET_ESI(\ctx)	# %esi -> ctx->esi
-	movl %edi,OFFSET_EDI(\ctx)	# %edi -> ctx->edi
-	movl %ebp,OFFSET_EBP(\ctx)	# %ebp -> ctx->ebp
-.endm
-
-# ctx: address of the structure with saved context
-
-.macro CONTEXT_RESTORE_ARCH_CORE ctx:req pc:req
-	movl OFFSET_SP(\ctx),%esp	# ctx->sp -> %esp
-	movl OFFSET_PC(\ctx),\pc	# ctx->pc -> \pc
-	movl OFFSET_EBX(\ctx),%ebx	# ctx->ebx -> %ebx
-	movl OFFSET_ESI(\ctx),%esi	# ctx->esi -> %esi
-	movl OFFSET_EDI(\ctx),%edi	# ctx->edi -> %edi
-	movl OFFSET_EBP(\ctx),%ebp	# ctx->ebp -> %ebp
-.endm
-
-#endif /* __ASM__ */
-
-#endif
-
-/** @}
- */
Index: kernel/arch/ia32/include/arch/context_struct.ag
===================================================================
--- kernel/arch/ia32/include/arch/context_struct.ag	(revision 4b334fd67169af5de794ce1053c6124e2ea71cd4)
+++ kernel/arch/ia32/include/arch/context_struct.ag	(revision 4b334fd67169af5de794ce1053c6124e2ea71cd4)
@@ -0,0 +1,72 @@
+# Copyright (c) 2014 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 : context,
+
+        includes : [
+                {
+                        include : <typedefs.h>
+                }
+        ],
+
+        members : [
+                #
+                # Only save registers that must be preserved across function
+                # calls.
+                #
+
+                {
+                        name : sp,
+                        type : uint32_t
+                },
+                {
+                        name : pc,
+                        type : uint32_t
+                },
+                {
+                        name : ebx,
+                        type : uint32_t
+                },
+                {
+                        name : esi,
+                        type : uint32_t
+                },
+                {
+                        name : edi,
+                        type : uint32_t
+                },
+                {
+                        name : ebp,
+                        type : uint32_t
+                },
+                {
+                        name : ipl,
+                        type : ipl_t
+                }
+        ]
+}
Index: kernel/arch/ia32/src/context.S
===================================================================
--- kernel/arch/ia32/src/context.S	(revision 6a8ddd3712c234be2a222a7dc9d7803bc9c667b0)
+++ kernel/arch/ia32/src/context.S	(revision 4b334fd67169af5de794ce1053c6124e2ea71cd4)
@@ -27,5 +27,5 @@
 #
 
-#include <arch/context_offset.h>
+#include <arch/context_struct.h>
 
 .text
@@ -41,11 +41,16 @@
 #
 context_save_arch:
-	movl 0(%esp),%eax	# save pc value into eax	
-	movl 4(%esp),%edx	# address of the context variable to save context to 
+	movl 0(%esp), %eax	# save pc value into eax	
+	movl 4(%esp), %edx	# address of the context variable to save context to 
 
-		# save registers to given structure
-	CONTEXT_SAVE_ARCH_CORE %edx %eax
+	# save registers to given structure
+	movl %esp, CONTEXT_OFFSET_SP(%edx)	# %esp -> ctx->sp
+	movl %eax, CONTEXT_OFFSET_PC(%edx)	# %eip -> ctx->pc
+	movl %ebx, CONTEXT_OFFSET_EBX(%edx)	# %ebx -> ctx->ebx
+	movl %esi, CONTEXT_OFFSET_ESI(%edx)	# %esi -> ctx->esi
+	movl %edi, CONTEXT_OFFSET_EDI(%edx)	# %edi -> ctx->edi
+	movl %ebp, CONTEXT_OFFSET_EBP(%edx)	# %ebp -> ctx->ebp
 
-	xorl %eax,%eax		# context_save returns 1
+	xorl %eax, %eax		# context_save returns 1
 	incl %eax
 	ret
@@ -58,10 +63,16 @@
 #
 context_restore_arch:
-	movl 4(%esp),%eax	# address of the context variable to restore context from
+	movl 4(%esp), %eax	# address of the context variable to restore context from
 
-		# restore registers from given structure
-	CONTEXT_RESTORE_ARCH_CORE %eax %edx
+	# restore registers from given structure
+	movl CONTEXT_OFFSET_SP(%eax), %esp	# ctx->sp -> %esp
+	movl CONTEXT_OFFSET_PC(%eax), %edx	# ctx->pc -> \pc
+	movl CONTEXT_OFFSET_EBX(%eax), %ebx	# ctx->ebx -> %ebx
+	movl CONTEXT_OFFSET_ESI(%eax), %esi	# ctx->esi -> %esi
+	movl CONTEXT_OFFSET_EDI(%eax), %edi	# ctx->edi -> %edi
+	movl CONTEXT_OFFSET_EBP(%eax), %ebp	# ctx->ebp -> %ebp
 
-	movl %edx,0(%esp)	# put saved pc on stack
-	xorl %eax,%eax		# context_restore returns 0
+	movl %edx, 0(%esp)	# put saved pc on stack
+	xorl %eax, %eax		# context_restore returns 0
 	ret
+
