Index: .gitignore
===================================================================
--- .gitignore	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ .gitignore	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -9,6 +9,4 @@
 *.so.*
 *.d
-*.ag.probe.s
-*.ag.probe.c
 *.pyc
 tag
@@ -16,5 +14,4 @@
 common.h.new
 deps.mk
-Makefile.ag.depend
 /Makefile.config
 /Makefile.common
@@ -46,33 +43,11 @@
 boot/image.raw
 kernel/arch/amd64/_link.ld
-kernel/arch/amd64/include/arch/boot/memmap_struct.h
-kernel/arch/amd64/include/arch/common.h
-kernel/arch/amd64/include/arch/context_struct.h
-kernel/arch/amd64/include/arch/istate_struct.h
-kernel/arch/amd64/include/arch/kseg_struct.h
 kernel/arch/arm32/_link.ld
-kernel/arch/arm32/include/arch/context_struct.h
-kernel/arch/arm32/include/arch/istate_struct.h
 kernel/arch/ia32/_link.ld
-kernel/arch/ia32/include/arch/boot/memmap_struct.h
-kernel/arch/ia32/include/arch/context_struct.h
-kernel/arch/ia32/include/arch/istate_struct.h
 kernel/arch/ia64/_link.ld
-kernel/arch/ia64/include/arch/context_struct.h
-kernel/arch/ia64/include/arch/istate_struct.h
 kernel/arch/mips32/_link.ld
-kernel/arch/mips32/include/arch/context_struct.h
-kernel/arch/mips32/include/arch/fpu_context_struct.h
-kernel/arch/mips32/include/arch/istate_struct.h
 kernel/arch/ppc32/_link.ld
-kernel/arch/ppc32/include/arch/context_struct.h
-kernel/arch/ppc32/include/arch/fpu_context_struct.h
-kernel/arch/ppc32/include/arch/istate_struct.h
 kernel/arch/sparc64/_link.ld
-kernel/arch/sparc64/include/arch/context_struct.h
-kernel/arch/sparc64/include/arch/istate_struct.h
 kernel/arch/abs32le/_link.ld
-kernel/genarch/include/genarch/multiboot/multiboot_info_struct.h
-kernel/genarch/include/genarch/multiboot/multiboot_memmap_struct.h
 kernel/generic/src/debug/real_map.bin
 kernel/kernel.bin
@@ -344,49 +319,32 @@
 uspace/lib/c/arch/amd64/_link-shlib.ld
 uspace/lib/c/arch/amd64/_link.ld
-uspace/lib/c/arch/amd64/include/libarch/common.h
-uspace/lib/c/arch/amd64/include/libarch/fibril_context.h
-uspace/lib/c/arch/amd64/include/libarch/istate_struct.h
 uspace/lib/c/arch/arm32/_link-dlexe.ld
 uspace/lib/c/arch/arm32/_link-loader.ld
 uspace/lib/c/arch/arm32/_link-shlib.ld
 uspace/lib/c/arch/arm32/_link.ld
-uspace/lib/c/arch/arm32/include/libarch/fibril_context.h
-uspace/lib/c/arch/arm32/include/libarch/istate_struct.h
 uspace/lib/c/arch/ia32/_link-dlexe.ld
 uspace/lib/c/arch/ia32/_link-loader.ld
 uspace/lib/c/arch/ia32/_link-shlib.ld
 uspace/lib/c/arch/ia32/_link.ld
-uspace/lib/c/arch/ia32/include/libarch/fibril_context.h
-uspace/lib/c/arch/ia32/include/libarch/istate_struct.h
 uspace/lib/c/arch/ia64/_link-dlexe.ld
 uspace/lib/c/arch/ia64/_link-loader.ld
 uspace/lib/c/arch/ia64/_link-shlib.ld
 uspace/lib/c/arch/ia64/_link.ld
-uspace/lib/c/arch/ia64/include/libarch/fibril_context.h
-uspace/lib/c/arch/ia64/include/libarch/istate_struct.h
 uspace/lib/c/arch/mips32/_link-dlexe.ld
 uspace/lib/c/arch/mips32/_link-loader.ld
 uspace/lib/c/arch/mips32/_link-shlib.ld
 uspace/lib/c/arch/mips32/_link.ld
-uspace/lib/c/arch/mips32/include/libarch/fibril_context.h
-uspace/lib/c/arch/mips32/include/libarch/istate_struct.h
 uspace/lib/c/arch/mips32eb/_link-dlexe.ld
 uspace/lib/c/arch/mips32eb/_link-loader.ld
 uspace/lib/c/arch/mips32eb/_link-shlib.ld
 uspace/lib/c/arch/mips32eb/_link.ld
-uspace/lib/c/arch/mips32eb/include/libarch/fibril_context.h
-uspace/lib/c/arch/mips32eb/include/libarch/istate_struct.h
 uspace/lib/c/arch/ppc32/_link-dlexe.ld
 uspace/lib/c/arch/ppc32/_link-loader.ld
 uspace/lib/c/arch/ppc32/_link-shlib.ld
 uspace/lib/c/arch/ppc32/_link.ld
-uspace/lib/c/arch/ppc32/include/libarch/fibril_context.h
-uspace/lib/c/arch/ppc32/include/libarch/istate_struct.h
 uspace/lib/c/arch/sparc64/_link-dlexe.ld
 uspace/lib/c/arch/sparc64/_link-loader.ld
 uspace/lib/c/arch/sparc64/_link-shlib.ld
 uspace/lib/c/arch/sparc64/_link.ld
-uspace/lib/c/arch/sparc64/include/libarch/fibril_context.h
-uspace/lib/c/arch/sparc64/include/libarch/istate_struct.h
 uspace/lib/c/arch/abs32le/_link-dlexe.ld
 uspace/lib/c/arch/abs32le/_link-loader.ld
Index: kernel/Makefile
===================================================================
--- kernel/Makefile	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/Makefile	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -48,5 +48,5 @@
 #
 
-AGDEPEND = Makefile.ag.depend
+AUTOGEN = $(ROOT_PATH)/tools/autogen2.sh
 RAW = kernel.raw
 BIN = kernel.bin
@@ -73,4 +73,5 @@
 
 .PHONY: all clean autogen_clean depend
+.DELETE_ON_ERROR:
 
 all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(COMMON_HEADER) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(BIN) $(DISASM)
@@ -132,5 +133,4 @@
 -include arch/$(KARCH)/Makefile.inc
 -include genarch/Makefile.inc
--include $(AGDEPEND)
 
 ## The at-sign
@@ -354,14 +354,6 @@
 GENARCH_DEPENDS := $(addsuffix .d,$(basename $(GENARCH_SOURCES)))
 
-GENARCH_AUTOGENS_H := $(addsuffix .h,$(basename $(GENARCH_AUTOGENS_AG)))
-GENARCH_AUTOGENS_PROBE_C := $(addsuffix .ag.probe.c,$(basename $(GENARCH_AUTOGENS_AG)))
-GENARCH_AUTOGENS_PROBE_S := $(addsuffix .ag.probe.s,$(basename $(GENARCH_AUTOGENS_AG)))
-
-ARCH_AUTOGENS_H := $(addsuffix .h,$(basename $(ARCH_AUTOGENS_AG)))
-ARCH_AUTOGENS_PROBE_C := $(addsuffix .ag.probe.c,$(basename $(ARCH_AUTOGENS_AG)))
-ARCH_AUTOGENS_PROBE_S := $(addsuffix .ag.probe.s,$(basename $(ARCH_AUTOGENS_AG)))
-
-AUTOGENS_H := $(ARCH_AUTOGENS_H) $(GENARCH_AUTOGENS_H)
 AUTOGENS_AG := $(ARCH_AUTOGENS_AG) $(GENARCH_AUTOGENS_AG)
+AUTOGEN_DEPENDS := $(addsuffix .d,$(AUTOGENS_AG))
 
 AS_CFLAGS := $(addprefix -Xassembler ,$(AFLAGS))
@@ -371,4 +363,5 @@
 -include $(ARCH_DEPENDS)
 -include $(GENARCH_DEPENDS)
+-include $(AUTOGEN_DEPENDS)
 
 ifeq ($(COMPILER),clang)
@@ -402,8 +395,6 @@
 	$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -D__LINKER__ -E -x c $< | grep -v "^\#" > $@
 
-%.h: %.ag
-	$(AUTOGEN) probe $< >$<.probe.c
-	$(CC_AUTOGEN) $(DEFS) $(CFLAGS) -S -o $<.probe.s $<.probe.c
-	$(AUTOGEN) generate $< <$<.probe.s >$@
+%.ag.h %.ag.s %.ag.c %.ag.d: %.h
+	CC="$(CC)" CFLAGS="-DKERNEL $(CFLAGS)" $(AUTOGEN) $< $@
 
 %.o: %.S | depend
@@ -441,19 +432,6 @@
 	$(GENMAP) $(MAP_PREV) $(DUMP) $@
 
-$(AUTOGENS_H): $(AGDEPEND)
-
-$(AGDEPEND): $(AUTOGENS_AG)
-	echo "# DO NOT EDIT" >$@
-	for g in $^; do \
-		h=`dirname $$g`/`basename $$g .ag`.h; \
-		for l in `$(AUTOGEN) depend $$g`; do \
-			echo "$$h: $$l" >>$@; \
-		done \
-	done
-
-depend: $(AUTOGENS_H)
+depend: $(AUTOGENS_AG)
 
 autogen_clean:
-	-rm $(ARCH_AUTOGENS_H) $(ARCH_AUTOGENS_PROBE_C) $(ARCH_AUTOGENS_PROBE_S)
-	-rm $(GENARCH_AUTOGENS_H) $(GENARCH_AUTOGENS_PROBE_C) $(GENARCH_AUTOGENS_PROBE_S)
-	-rm $(AGDEPEND)
+	-rm $(AUTOGENS_AG) $(AUTOGEN_DEPENDS) $(AUTOGENS_AG)
Index: kernel/arch/amd64/Makefile.inc
===================================================================
--- kernel/arch/amd64/Makefile.inc	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/amd64/Makefile.inc	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -86,6 +86,6 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(KARCH)/include/arch/istate_struct.ag \
-	arch/$(KARCH)/include/arch/context_struct.ag \
-	arch/$(KARCH)/include/arch/kseg_struct.ag \
-	arch/$(KARCH)/include/arch/boot/memmap_struct.ag
+	arch/$(KARCH)/include/arch/istate_struct.ag.h \
+	arch/$(KARCH)/include/arch/context_struct.ag.h \
+	arch/$(KARCH)/include/arch/kseg_struct.ag.h \
+	arch/$(KARCH)/include/arch/boot/memmap_struct.ag.h
Index: rnel/arch/amd64/include/arch/boot/memmap_struct.ag
===================================================================
--- kernel/arch/amd64/include/arch/boot/memmap_struct.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../../../../ia32/include/arch/boot/memmap_struct.ag
Index: kernel/arch/amd64/include/arch/boot/memmap_struct.h
===================================================================
--- kernel/arch/amd64/include/arch/boot/memmap_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ kernel/arch/amd64/include/arch/boot/memmap_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,36 @@
+/* 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.
+ */
+
+#pragma once
+#include <stdint.h>
+
+typedef struct e820memmap {
+	uint64_t base_address;
+	uint64_t size;
+	uint32_t type;
+} __attribute__((packed)) e820memmap_t;
+
Index: rnel/arch/amd64/include/arch/context_struct.ag
===================================================================
--- kernel/arch/amd64/include/arch/context_struct.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,87 +1,0 @@
-# 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 : [
-                #
-                # We include only registers that must be preserved
-                # during function call.
-                #
-
-                {
-                        name : sp,
-                        type : uint64_t
-                },
-                {
-                        name : pc,
-                        type : uint64_t
-                },
-
-                {
-                        name : rbx,
-                        type : uint64_t
-                },
-                {
-                        name : rbp,
-                        type : uint64_t
-                },
-
-                {
-                        name : r12,
-                        type : uint64_t
-                },
-                {
-                        name : r13,
-                        type : uint64_t
-                },
-                {
-                        name : r14,
-                        type : uint64_t
-                },
-                {
-                        name : r15,
-                        type : uint64_t
-                },
-                {
-                        name : tp,
-                        type : uint64_t
-                },
-
-                {
-                        name : ipl,
-                        type : ipl_t
-                }
-        ]
-}
Index: kernel/arch/amd64/include/arch/context_struct.h
===================================================================
--- kernel/arch/amd64/include/arch/context_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ kernel/arch/amd64/include/arch/context_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,46 @@
+/* Copyright (c) 2014 Jakub Jermar
+ * All rights preserved.
+ *
+ * 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.
+ */
+
+#pragma once
+#include <typedefs.h>
+
+typedef struct context {
+	/* We include only registers that must be preserved
+	 * during function call.
+	 */
+	uint64_t sp;
+	uint64_t pc;
+	uint64_t rbx;
+	uint64_t rbp;
+	uint64_t r12;
+	uint64_t r13;
+	uint64_t r14;
+	uint64_t r15;
+	uint64_t tp;
+	ipl_t ipl;
+} context_t;
+
Index: rnel/arch/amd64/include/arch/istate_struct.ag
===================================================================
--- kernel/arch/amd64/include/arch/istate_struct.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,150 +1,0 @@
-# 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 : istate,
-
-        includes : [
-                {
-                        guard : KERNEL,
-                        include : <typedefs.h>
-                },
-                {
-                        negative-guard: KERNEL,
-                        include : <stddef.h>
-                },
-                {
-                        negative-guard: KERNEL,
-                        include : <stdint.h>
-                }
-        ],
-
-        members : [
-                {
-                        name : rax,
-                        type : uint64_t
-                },
-                {
-                        name : rbx,
-                        type : uint64_t
-                },
-                {
-                        name : rcx,
-                        type : uint64_t
-                },
-                {
-                        name : rdx,
-                        type : uint64_t
-                },
-                {
-                        name : rsi,
-                        type : uint64_t
-                },
-                {
-                        name : rdi,
-                        type : uint64_t
-                },
-                {
-                        name : rbp,
-                        type : uint64_t
-                },
-                {
-                        name : r8,
-                        type : uint64_t
-                },
-                {
-                        name : r9,
-                        type : uint64_t
-                },
-                {
-                        name : r10,
-                        type : uint64_t
-                },
-                {
-                        name : r11,
-                        type : uint64_t
-                },
-                {
-                        name : r12,
-                        type : uint64_t
-                },
-                {
-                        name : r13,
-                        type : uint64_t
-                },
-                {
-                        name : r14,
-                        type : uint64_t
-                },
-                {
-                        name : r15,
-                        type : uint64_t
-                },
-                {
-                        # align rbp_frame on multiple of 16
-                        name : alignment,
-                        type : uint64_t
-                },
-                {
-                        # imitation of frame pointer linkage
-                        name : rbp_frame,
-                        type : uint64_t
-                },
-                {
-                        # imitation of frame address linkage
-                        name : rip_frame,
-                        type : uint64_t
-                },
-                {
-                        # real or fake error word
-                        name : error_word,
-                        type : uint64_t
-                },
-                {
-                        name : rip,
-                        type : uint64_t
-                },
-                {
-                        name : cs,
-                        type : uint64_t
-                },
-                {
-                        name : rflags,
-                        type : uint64_t
-                },
-                {
-                        # only if istate_t is from uspace
-                        name : rsp,
-                        type : uint64_t
-                },
-                {
-                        # only if istate_t is from uspace
-                        name : ss,
-                        type : uint64_t
-                }
-        ]
-}
Index: kernel/arch/amd64/include/arch/istate_struct.h
===================================================================
--- kernel/arch/amd64/include/arch/istate_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ kernel/arch/amd64/include/arch/istate_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,63 @@
+/* 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.
+ */
+
+#pragma once
+#include <stdint.h>
+
+typedef struct istate {
+	uint64_t rax;
+	uint64_t rbx;
+	uint64_t rcx;
+	uint64_t rdx;
+	uint64_t rsi;
+	uint64_t rdi;
+	uint64_t rbp;
+	uint64_t r8;
+	uint64_t r9;
+	uint64_t r10;
+	uint64_t r11;
+	uint64_t r12;
+	uint64_t r13;
+	uint64_t r14;
+	uint64_t r15;
+	/* align rbp_frame on multiple of 16 */
+	uint64_t alignment;
+	/* imitation of frame pointer linkage */
+	uint64_t rbp_frame;
+	/* imitation of frame address linkage */
+	uint64_t rip_frame;
+	/* real or fake error word */
+	uint64_t error_word;
+	uint64_t rip;
+	uint64_t cs;
+	uint64_t rflags;
+	/* only if istate_t is from uspace */
+	uint64_t rsp;
+	/* only if istate_t is from uspace */
+	uint64_t ss;
+} istate_t;
+
Index: rnel/arch/amd64/include/arch/kseg_struct.ag
===================================================================
--- kernel/arch/amd64/include/arch/kseg_struct.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,51 +1,0 @@
-# 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/kseg_struct.h
===================================================================
--- kernel/arch/amd64/include/arch/kseg_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ kernel/arch/amd64/include/arch/kseg_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,36 @@
+/* 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.
+ */
+
+#pragma once
+#include <stdint.h>
+
+typedef struct kseg {
+	uint64_t ustack_rsp;
+	uint64_t kstack_rsp;
+	uint64_t fsbase;
+} kseg_t;
+
Index: kernel/arch/amd64/src/asm.S
===================================================================
--- kernel/arch/amd64/src/asm.S	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/amd64/src/asm.S	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -30,6 +30,6 @@
 #include <arch/pm.h>
 #include <arch/mm/page.h>
-#include <arch/istate_struct.h>
-#include <arch/kseg_struct.h>
+#include <arch/istate_struct.ag.h>
+#include <arch/kseg_struct.ag.h>
 #include <arch/cpu.h>
 #include <arch/smp/apic.h>
@@ -541,2 +541,3 @@
 	ret
 FUNCTION_END(early_putchar)
+
Index: kernel/arch/amd64/src/boot/multiboot.S
===================================================================
--- kernel/arch/amd64/src/boot/multiboot.S	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/amd64/src/boot/multiboot.S	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -720,2 +720,3 @@
 status_main:
 	.asciz "[main] "
+
Index: kernel/arch/amd64/src/context.S
===================================================================
--- kernel/arch/amd64/src/context.S	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/amd64/src/context.S	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -28,5 +28,5 @@
 
 #include <abi/asmtool.h>
-#include <arch/context_struct.h>
+#include <arch/context_struct.ag.h>
 #include <arch/vreg.h>
 
Index: kernel/arch/amd64/src/smp/ap.S
===================================================================
--- kernel/arch/amd64/src/smp/ap.S	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/amd64/src/smp/ap.S	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -39,5 +39,5 @@
 #include <arch/cpu.h>
 #include <arch/cpuid.h>
-#include <arch/context_struct.h>
+#include <arch/context_struct.ag.h>
 
 .section K_TEXT_START, "ax"
Index: kernel/arch/arm32/Makefile.inc
===================================================================
--- kernel/arch/arm32/Makefile.inc	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/arm32/Makefile.inc	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -96,7 +96,2 @@
 	ARCH_SOURCES += genarch/src/drivers/pl050/pl050.c
 endif
-
-ARCH_AUTOGENS_AG = \
-	arch/$(KARCH)/include/arch/istate_struct.ag \
-	arch/$(KARCH)/include/arch/context_struct.ag
-
Index: rnel/arch/arm32/include/arch/context_struct.ag
===================================================================
--- kernel/arch/arm32/include/arch/context_struct.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,95 +1,0 @@
-# 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>
-                },
-        ],
-
-        #
-        # Thread context containing registers that must be preserved across
-        # function calls.
-        #
-        members : [
-                {
-                        name : cpu_mode,
-                        type : uint32_t
-                },
-                {
-                        name : sp,
-                        type : uintptr_t
-                },
-                {
-                        name : pc,
-                        type : uintptr_t
-                },
-
-                {
-                        name : r4,
-                        type : uint32_t
-                },
-                {
-                        name : r5,
-                        type : uint32_t
-                },
-                {
-                        name : r6,
-                        type : uint32_t
-                },
-                {
-                        name : r7,
-                        type : uint32_t
-                },
-                {
-                        name : r8,
-                        type : uint32_t
-                },
-                {
-                        name : r9,
-                        type : uint32_t
-                },
-                {
-                        name : r10,
-                        type : uint32_t
-                },
-                {
-                        # r11
-                        name : fp,
-                        type : uint32_t
-                },
-
-                {
-                        name : ipl,
-                        type : ipl_t
-                }
-        ]
-}
-
Index: kernel/arch/arm32/include/arch/context_struct.h
===================================================================
--- kernel/arch/arm32/include/arch/context_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ kernel/arch/arm32/include/arch/context_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+
+#pragma once
+#include <typedefs.h>
+
+/* Thread context containing registers that must be preserved across
+ * function calls.
+ */
+typedef struct context {
+	uint32_t cpu_mode;
+	uintptr_t sp;
+	uintptr_t pc;
+	uint32_t r4;
+	uint32_t r5;
+	uint32_t r6;
+	uint32_t r7;
+	uint32_t r8;
+	uint32_t r9;
+	uint32_t r10;
+	/* r11 */
+	uint32_t fp;
+	ipl_t ipl;
+} context_t;
+
Index: rnel/arch/arm32/include/arch/istate_struct.ag
===================================================================
--- kernel/arch/arm32/include/arch/istate_struct.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,123 +1,0 @@
-# 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 : istate,
-
-        includes : [
-                {
-                        guard : KERNEL,
-                        include : <typedefs.h>
-                },
-                {
-                        negative-guard : KERNEL,
-                        include : <stddef.h>
-                },
-                {
-                        negative-guard : KERNEL,
-                        include : <stdint.h>
-                }
-        ],
-
-        members : [
-                {
-                        name : dummy,
-                        type : uint32_t
-                },
-                {
-                        name : spsr,
-                        type : uint32_t
-                },
-                {
-                        name : sp,
-                        type : uint32_t
-                },
-                {
-                        name : lr,
-                        type : uint32_t
-                },
-
-                {
-                        name : r0,
-                        type : uint32_t
-                },
-                {
-                        name : r1,
-                        type : uint32_t
-                },
-                {
-                        name : r2,
-                        type : uint32_t
-                },
-                {
-                        name : r3,
-                        type : uint32_t
-                },
-                {
-                        name : r4,
-                        type : uint32_t
-                },
-                {
-                        name : r5,
-                        type : uint32_t
-                },
-                {
-                        name : r6,
-                        type : uint32_t
-                },
-                {
-                        name : r7,
-                        type : uint32_t
-                },
-                {
-                        name : r8,
-                        type : uint32_t
-                },
-                {
-                        name : r9,
-                        type : uint32_t
-                },
-                {
-                        name : r10,
-                        type : uint32_t
-                },
-                {
-                        name : fp,
-                        type : uint32_t
-                },
-                {
-                        name : r12,
-                        type : uint32_t
-                },
-
-                {
-                        name : pc,
-                        type : uint32_t
-                }
-        ]
-}
-
Index: kernel/arch/arm32/include/arch/istate_struct.h
===================================================================
--- kernel/arch/arm32/include/arch/istate_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ kernel/arch/arm32/include/arch/istate_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+#pragma once
+#include <stdint.h>
+
+typedef struct istate {
+	uint32_t dummy;
+	uint32_t spsr;
+	uint32_t sp;
+	uint32_t lr;
+	uint32_t r0;
+	uint32_t r1;
+	uint32_t r2;
+	uint32_t r3;
+	uint32_t r4;
+	uint32_t r5;
+	uint32_t r6;
+	uint32_t r7;
+	uint32_t r8;
+	uint32_t r9;
+	uint32_t r10;
+	uint32_t fp;
+	uint32_t r12;
+	uint32_t pc;
+} istate_t;
+
Index: kernel/arch/ia32/Makefile.inc
===================================================================
--- kernel/arch/ia32/Makefile.inc	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/ia32/Makefile.inc	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -103,6 +103,6 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(KARCH)/include/arch/istate_struct.ag \
-	arch/$(KARCH)/include/arch/context_struct.ag \
-	arch/$(KARCH)/include/arch/boot/memmap_struct.ag
+	arch/$(KARCH)/include/arch/istate_struct.ag.h \
+	arch/$(KARCH)/include/arch/context_struct.ag.h \
+	arch/$(KARCH)/include/arch/boot/memmap_struct.ag.h
 
Index: kernel/arch/ia32/include/arch/boot/memmap.h
===================================================================
--- kernel/arch/ia32/include/arch/boot/memmap.h	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/ia32/include/arch/boot/memmap.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -36,5 +36,5 @@
 #define KERN_ia32_MEMMAP_H_
 
-#include <arch/boot/memmap_struct.h>
+
 
 /* E820h memory range types */
@@ -61,7 +61,12 @@
 #define MEMMAP_E820_MAX_RECORDS  32
 
-#ifndef __ASM__
+#ifdef __ASM__
+
+#include <arch/boot/memmap_struct.ag.h>
+
+#else
 
 #include <stdint.h>
+#include <arch/boot/memmap_struct.h>
 
 extern e820memmap_t e820table[MEMMAP_E820_MAX_RECORDS];
Index: rnel/arch/ia32/include/arch/boot/memmap_struct.ag
===================================================================
--- kernel/arch/ia32/include/arch/boot/memmap_struct.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,52 +1,0 @@
-# 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 : e820memmap,
-        packed : true,
-
-        includes : [
-                {
-                        include : <typedefs.h>
-                },
-        ],
-
-        members : [
-                {
-                        name : base_address,
-                        type : uint64_t
-                },
-                {
-                        name : size,
-                        type : uint64_t
-                },
-                {
-                        name : type,
-                        type : uint32_t
-                }
-        ]
-}
Index: kernel/arch/ia32/include/arch/boot/memmap_struct.h
===================================================================
--- kernel/arch/ia32/include/arch/boot/memmap_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ kernel/arch/ia32/include/arch/boot/memmap_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,36 @@
+/* Copyright (c) 2014 Jakub Jermar
+ * All rights preserved.
+ *
+ * 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.
+ */
+
+#pragma once
+#include <stdint.h>
+
+typedef struct e820memmap {
+	uint64_t base_address;
+	uint64_t size;
+	uint32_t type;
+} __attribute__((packed)) e820memmap_t;
+
Index: rnel/arch/ia32/include/arch/context_struct.ag
===================================================================
--- kernel/arch/ia32/include/arch/context_struct.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,77 +1,0 @@
-# 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 : tp,
-                        type : uint32_t
-                },
-
-                {
-                        name : ipl,
-                        type : ipl_t
-                }
-        ]
-}
Index: kernel/arch/ia32/include/arch/context_struct.h
===================================================================
--- kernel/arch/ia32/include/arch/context_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ kernel/arch/ia32/include/arch/context_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,42 @@
+/* Copyright (c) 2014 Jakub Jermar
+ * All rights preserved.
+ *
+ * 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.
+ */
+
+#pragma once
+#include <typedefs.h>
+
+/* Only save registers that must be preserved across function calls. */
+typedef struct context {
+	uint32_t sp;
+	uint32_t pc;
+	uint32_t ebx;
+	uint32_t esi;
+	uint32_t edi;
+	uint32_t ebp;
+	uint32_t tp;
+	ipl_t ipl;
+} context_t;
+
Index: rnel/arch/ia32/include/arch/istate_struct.ag
===================================================================
--- kernel/arch/ia32/include/arch/istate_struct.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,139 +1,0 @@
-# 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 : istate,
-
-        includes : [
-                {
-                        guard : KERNEL,
-                        include : <typedefs.h>
-                },
-                {
-                        negative-guard: KERNEL,
-                        include : <stddef.h>
-                },
-                {
-                        negative-guard: KERNEL,
-                        include : <stdint.h>
-                }
-        ],
-
-        members : [
-
-                #
-                # The strange order of the GPRs is given by the requirement to use the
-                # istate structure for both regular interrupts and exceptions as well
-                # as for syscall handlers which use this order as an optimization.
-                #
-
-                {
-                        name : edx,
-                        type : uint32_t
-                },
-                {
-                        name : ecx,
-                        type : uint32_t
-                },
-                {
-                        name : ebx,
-                        type : uint32_t
-                },
-                {
-                        name : esi,
-                        type : uint32_t
-                },
-                {
-                        name : edi,
-                        type : uint32_t
-                },
-                {
-                        name : ebp,
-                        type : uint32_t
-                },
-                {
-                        name : eax,
-                        type : uint32_t
-                },
-
-                {
-                        # imitation of frame pointer linkage
-                        name : ebp_frame,
-                        type : uint32_t
-                },
-                {
-                        # imitation of return address linkage
-                        name : eip_frame,
-                        type : uint32_t
-                },
-
-                {
-                        name : gs,
-                        type : uint32_t
-                },
-                {
-                        name : fs,
-                        type : uint32_t
-                },
-                {
-                        name : es,
-                        type : uint32_t
-                },
-                {
-                        name : ds,
-                        type : uint32_t
-                },
-
-                {
-                        # real or fake error word
-                        name : error_word,
-                        type : uint32_t
-                },
-                {
-                        name : eip,
-                        type : uint32_t
-                },
-                {
-                        name : cs,
-                        type : uint32_t
-                },
-                {
-                        name : eflags,
-                        type : uint32_t
-                },
-                {
-                        # only if istate_t is from uspace
-                        name : esp,
-                        type : uint32_t
-                },
-                {
-                        # only if istate_t is from uspace
-                        name : ss,
-                        type : uint32_t
-                }
-        ]
-}
Index: kernel/arch/ia32/include/arch/istate_struct.h
===================================================================
--- kernel/arch/ia32/include/arch/istate_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ kernel/arch/ia32/include/arch/istate_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,62 @@
+/* Copyright (c) 2014 Jakub Jermar
+ * All rights preserved.
+ *
+ * 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.
+ */
+
+#pragma once
+#include <stdint.h>
+
+/*
+ * The strange order of the GPRs is given by the requirement to use the
+ * istate structure for both regular interrupts and exceptions as well
+ * as for syscall handlers which use this order as an optimization.
+ */
+typedef struct istate {
+	uint32_t edx;
+	uint32_t ecx;
+	uint32_t ebx;
+	uint32_t esi;
+	uint32_t edi;
+	uint32_t ebp;
+	uint32_t eax;
+	/* imitation of frame pointer linkage */
+	uint32_t ebp_frame;
+	/* imitation of return address linkage */
+	uint32_t eip_frame;
+	uint32_t gs;
+	uint32_t fs;
+	uint32_t es;
+	uint32_t ds;
+	/* real or fake error word */
+	uint32_t error_word;
+	uint32_t eip;
+	uint32_t cs;
+	uint32_t eflags;
+	/* only if istate_t is from uspace */
+	uint32_t esp;
+	/* only if istate_t is from uspace */
+	uint32_t ss;
+} istate_t;
+
Index: kernel/arch/ia32/src/asm.S
===================================================================
--- kernel/arch/ia32/src/asm.S	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/ia32/src/asm.S	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -35,5 +35,5 @@
 #include <arch/cpu.h>
 #include <arch/mm/page.h>
-#include <arch/istate_struct.h>
+#include <arch/istate_struct.ag.h>
 #include <arch/smp/apic.h>
 
@@ -585,2 +585,3 @@
 FUNCTION_END(early_putchar)
 
+
Index: kernel/arch/ia32/src/context.S
===================================================================
--- kernel/arch/ia32/src/context.S	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/ia32/src/context.S	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -28,5 +28,5 @@
 
 #include <abi/asmtool.h>
-#include <arch/context_struct.h>
+#include <arch/context_struct.ag.h>
 #include <arch/vreg.h>
 
Index: kernel/arch/ia32/src/smp/ap.S
===================================================================
--- kernel/arch/ia32/src/smp/ap.S	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/ia32/src/smp/ap.S	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -38,5 +38,5 @@
 #include <arch/pm.h>
 #include <arch/cpu.h>
-#include <arch/context_struct.h>
+#include <arch/context_struct.ag.h>
 
 .section K_TEXT_START, "ax"
Index: kernel/arch/ia64/Makefile.inc
===================================================================
--- kernel/arch/ia64/Makefile.inc	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/ia64/Makefile.inc	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -73,5 +73,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(KARCH)/include/arch/istate_struct.ag \
-	arch/$(KARCH)/include/arch/context_struct.ag
+	arch/$(KARCH)/include/arch/istate_struct.ag.h \
+	arch/$(KARCH)/include/arch/context_struct.ag.h
 
Index: rnel/arch/ia64/include/arch/context_struct.ag
===================================================================
--- kernel/arch/ia64/include/arch/context_struct.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,235 +1,0 @@
-# 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>
-                }
-        ],
-
-        #
-        # Only save registers that must be preserved across function calls.
-        #
-        members : [
-                #
-                # Application registers
-                #
-                {
-                        name : ar_pfs,
-                        type : uint64_t
-                },
-                {
-                        name : ar_unat_caller,
-                        type : uint64_t
-                },
-                {
-                        name : ar_unat_callee,
-                        type : uint64_t
-                },
-                {
-                        name : ar_rsc,
-                        type : uint64_t
-                },
-                {
-                        # ar_bsp
-                        name : bsp,
-                        type : uint64_t
-                },
-                {
-                        name : ar_rnat,
-                        type : uint64_t
-                },
-                {
-                        name : ar_lc,
-                        type : uint64_t
-                },
-
-
-                #
-                # General registers
-                #
-                {
-                        name : r1,
-                        type : uint64_t
-                },
-                {
-                        name : r4,
-                        type : uint64_t
-                },
-                {
-                        name : r5,
-                        type : uint64_t
-                },
-                {
-                        name : r6,
-                        type : uint64_t
-                },
-                {
-                        name : r7,
-                        type : uint64_t
-                },
-                {
-                        # r12
-                        name : sp,
-                        type : uint64_t
-                },
-                {
-                        name : r13,
-                        type : uint64_t
-                },
-
-
-                #
-                # Branch registers
-                #
-                {
-                        # b0
-                        name : pc,
-                        type : uint64_t
-                },
-                {
-                        name : b1,
-                        type : uint64_t
-                },
-                {
-                        name : b2,
-                        type : uint64_t
-                },
-                {
-                        name : b3,
-                        type : uint64_t
-                },
-                {
-                        name : b4,
-                        type : uint64_t
-                },
-                {
-                        name : b5,
-                        type : uint64_t
-                },
-
-
-                #
-                # Predicate registers
-                #
-                {
-                        name : pr,
-                        type : uint64_t
-                },
-
-                {
-                        name : f2,
-                        type : uint128_t
-                },
-                {
-                        name : f3,
-                        type : uint128_t
-                },
-                {
-                        name : f4,
-                        type : uint128_t
-                },
-                {
-                        name : f5,
-                        type : uint128_t
-                },
-
-                {
-                        name : f16,
-                        type : uint128_t
-                },
-                {
-                        name : f17,
-                        type : uint128_t
-                },
-                {
-                        name : f18,
-                        type : uint128_t
-                },
-                {
-                        name : f19,
-                        type : uint128_t
-                },
-                {
-                        name : f20,
-                        type : uint128_t
-                },
-                {
-                        name : f21,
-                        type : uint128_t
-                },
-                {
-                        name : f22,
-                        type : uint128_t
-                },
-                {
-                        name : f23,
-                        type : uint128_t
-                },
-                {
-                        name : f24,
-                        type : uint128_t
-                },
-                {
-                        name : f25,
-                        type : uint128_t
-                },
-                {
-                        name : f26,
-                        type : uint128_t
-                },
-                {
-                        name : f27,
-                        type : uint128_t
-                },
-                {
-                        name : f28,
-                        type : uint128_t
-                },
-                {
-                        name : f29,
-                        type : uint128_t
-                },
-                {
-                        name : f30,
-                        type : uint128_t
-                },
-                {
-                        name : f31,
-                        type : uint128_t
-                },
-
-                {
-                        name : ipl,
-                        type: ipl_t
-                }
-        ]
-}
-
Index: kernel/arch/ia64/include/arch/context_struct.h
===================================================================
--- kernel/arch/ia64/include/arch/context_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ kernel/arch/ia64/include/arch/context_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,87 @@
+/* Copyright (c) 2014 Jakub Jermar
+ * All rights preserved.
+ *
+ * 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.
+ */
+
+#pragma once
+#include <typedefs.h>
+
+// Only save registers that must be preserved across function calls.
+typedef struct context {
+	// Application registers.
+	uint64_t ar_pfs;
+	uint64_t ar_unat_caller;
+	uint64_t ar_unat_callee;
+	uint64_t ar_rsc;
+	// ar_bsp
+	uint64_t bsp;
+	uint64_t ar_rnat;
+	uint64_t ar_lc;
+
+	// General registers.
+	uint64_t r1;
+	uint64_t r4;
+	uint64_t r5;
+	uint64_t r6;
+	uint64_t r7;
+	// r12
+	uint64_t sp;
+	uint64_t r13;
+
+	// Branch registers.
+	// b0
+	uint64_t pc;
+	uint64_t b1;
+	uint64_t b2;
+	uint64_t b3;
+	uint64_t b4;
+	uint64_t b5;
+
+	// Predicate registers.
+	uint64_t pr;
+	uint128_t f2;
+	uint128_t f3;
+	uint128_t f4;
+	uint128_t f5;
+	uint128_t f16;
+	uint128_t f17;
+	uint128_t f18;
+	uint128_t f19;
+	uint128_t f20;
+	uint128_t f21;
+	uint128_t f22;
+	uint128_t f23;
+	uint128_t f24;
+	uint128_t f25;
+	uint128_t f26;
+	uint128_t f27;
+	uint128_t f28;
+	uint128_t f29;
+	uint128_t f30;
+	uint128_t f31;
+
+	ipl_t ipl;
+} context_t;
+
Index: kernel/arch/ia64/include/arch/interrupt.h
===================================================================
--- kernel/arch/ia64/include/arch/interrupt.h	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/ia64/include/arch/interrupt.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -37,4 +37,5 @@
 
 #ifndef __ASM__
+#include <_bits/native.h>
 #include <arch/istate.h>
 #include <stdint.h>
Index: rnel/arch/ia64/include/arch/istate_struct.ag
===================================================================
--- kernel/arch/ia64/include/arch/istate_struct.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,267 +1,0 @@
-# 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 : istate,
-
-        includes : [
-                {
-                        guard : KERNEL,
-                        include : <typedefs.h>
-                },
-                {
-                        guard : KERNEL,
-                        include : <arch/register.h>
-                },
-                {
-                        negative-guard : KERNEL,
-                        include : <stddef.h>
-                },
-                {
-                        negative-guard : KERNEL,
-                        include : <stdint.h>
-                },
-                {
-                        negative-guard : KERNEL,
-                        include : <libarch/register.h>
-                }
-        ],
-
-        members : [
-                {
-                        name : f2,
-                        type : uint128_t
-                },
-                {
-                        name : f3,
-                        type : uint128_t
-                },
-                {
-                        name : f4,
-                        type : uint128_t
-                },
-                {
-                        name : f5,
-                        type : uint128_t
-                },
-                {
-                        name : f6,
-                        type : uint128_t
-                },
-                {
-                        name : f7,
-                        type : uint128_t
-                },
-                {
-                        name : f8,
-                        type : uint128_t
-                },
-                {
-                        name : f9,
-                        type : uint128_t
-                },
-                {
-                        name : f10,
-                        type : uint128_t
-                },
-                {
-                        name : f11,
-                        type : uint128_t
-                },
-                {
-                        name : f12,
-                        type : uint128_t
-                },
-                {
-                        name : f13,
-                        type : uint128_t
-                },
-                {
-                        name : f14,
-                        type : uint128_t
-                },
-                {
-                        name : f15,
-                        type : uint128_t
-                },
-                {
-                        name : f16,
-                        type : uint128_t
-                },
-                {
-                        name : f17,
-                        type : uint128_t
-                },
-                {
-                        name : f18,
-                        type : uint128_t
-                },
-                {
-                        name : f19,
-                        type : uint128_t
-                },
-                {
-                        name : f20,
-                        type : uint128_t
-                },
-                {
-                        name : f21,
-                        type : uint128_t
-                },
-                {
-                        name : f22,
-                        type : uint128_t
-                },
-                {
-                        name : f23,
-                        type : uint128_t
-                },
-                {
-                        name : f24,
-                        type : uint128_t
-                },
-                {
-                        name : f25,
-                        type : uint128_t
-                },
-                {
-                        name : f26,
-                        type : uint128_t
-                },
-                {
-                        name : f27,
-                        type : uint128_t
-                },
-                {
-                        name : f28,
-                        type : uint128_t
-                },
-                {
-                        name : f29,
-                        type : uint128_t
-                },
-                {
-                        name : f30,
-                        type : uint128_t
-                },
-                {
-                        name : f31,
-                        type : uint128_t
-                },
-
-                {
-                        name : ar_bsp,
-                        type : uintptr_t
-                },
-                {
-                        name : ar_bspstore,
-                        type : uintptr_t
-                },
-                {
-                        name : ar_bspstore_new,
-                        type : uintptr_t
-                },
-                {
-                        name : ar_rnat,
-                        type : uint64_t
-                },
-                {
-                        name : ar_ifs,
-                        type : uint64_t
-                },
-                {
-                        name : ar_pfs,
-                        type : uint64_t
-                },
-                {
-                        name : ar_rsc,
-                        type : uint64_t
-                },
-                {
-                        name : cr_ifa,
-                        type : uintptr_t
-                },
-                {
-                        name : cr_isr,
-                        type : cr_isr_t
-                },
-                {
-                        name : cr_iipa,
-                        type : uintptr_t
-                },
-                {
-                        name : cr_ipsr,
-                        type : psr_t
-                },
-                {
-                        name : cr_iip,
-                        type : uintptr_t
-                },
-                {
-                        name : pr,
-                        type : uint64_t
-                },
-                {
-                        name : sp,
-                        type : uintptr_t
-                },
-
-                #
-                # The following variables are defined only for break_instruction
-                # handler.
-                #
-                {
-                        name : in0,
-                        type : uint64_t
-                },
-                {
-                        name : in1,
-                        type : uint64_t
-                },
-                {
-                        name : in2,
-                        type : uint64_t
-                },
-                {
-                        name : in3,
-                        type : uint64_t
-                },
-                {
-                        name : in4,
-                        type : uint64_t
-                },
-                {
-                        name : in5,
-                        type : uint64_t
-                },
-                {
-                        name : in6,
-                        type : uint64_t
-                }
-        ]
-}
-
Index: kernel/arch/ia64/include/arch/istate_struct.h
===================================================================
--- kernel/arch/ia64/include/arch/istate_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ kernel/arch/ia64/include/arch/istate_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,93 @@
+/* Copyright (c) 2014 Jakub Jermar
+ * All rights preserved.
+ *
+ * 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.
+ */
+
+#pragma once
+#include <stdint.h>
+
+#ifdef KERNEL
+#include <arch/register.h>
+#else
+#include <libarch/register.h>
+#endif
+
+typedef struct istate {
+	uint128_t f2;
+	uint128_t f3;
+	uint128_t f4;
+	uint128_t f5;
+	uint128_t f6;
+	uint128_t f7;
+	uint128_t f8;
+	uint128_t f9;
+	uint128_t f10;
+	uint128_t f11;
+	uint128_t f12;
+	uint128_t f13;
+	uint128_t f14;
+	uint128_t f15;
+	uint128_t f16;
+	uint128_t f17;
+	uint128_t f18;
+	uint128_t f19;
+	uint128_t f20;
+	uint128_t f21;
+	uint128_t f22;
+	uint128_t f23;
+	uint128_t f24;
+	uint128_t f25;
+	uint128_t f26;
+	uint128_t f27;
+	uint128_t f28;
+	uint128_t f29;
+	uint128_t f30;
+	uint128_t f31;
+	uintptr_t ar_bsp;
+	uintptr_t ar_bspstore;
+	uintptr_t ar_bspstore_new;
+	uint64_t ar_rnat;
+	uint64_t ar_ifs;
+	uint64_t ar_pfs;
+	uint64_t ar_rsc;
+	uintptr_t cr_ifa;
+	cr_isr_t cr_isr;
+	uintptr_t cr_iipa;
+	psr_t cr_ipsr;
+	uintptr_t cr_iip;
+	uint64_t pr;
+	uintptr_t sp;
+
+	// The following variables are defined only for break_instruction
+	// handler.
+	uint64_t in0;
+	uint64_t in1;
+	uint64_t in2;
+	uint64_t in3;
+	uint64_t in4;
+	uint64_t in5;
+	uint64_t in6;
+} istate_t;
+
Index: kernel/arch/ia64/src/context.S
===================================================================
--- kernel/arch/ia64/src/context.S	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/ia64/src/context.S	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -28,5 +28,5 @@
 
 #include <abi/asmtool.h>
-#include <arch/context_struct.h>
+#include <arch/context_struct.ag.h>
 
 .text
Index: kernel/arch/ia64/src/ivt.S
===================================================================
--- kernel/arch/ia64/src/ivt.S	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/ia64/src/ivt.S	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -33,5 +33,5 @@
 #include <arch/mm/page.h>
 #include <arch/interrupt.h>
-#include <arch/istate_struct.h>
+#include <arch/istate_struct.ag.h>
 #include <align.h>
 
Index: kernel/arch/mips32/Makefile.inc
===================================================================
--- kernel/arch/mips32/Makefile.inc	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/mips32/Makefile.inc	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -89,5 +89,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(KARCH)/include/arch/istate_struct.ag \
-	arch/$(KARCH)/include/arch/context_struct.ag \
-	arch/$(KARCH)/include/arch/fpu_context_struct.ag
+	arch/$(KARCH)/include/arch/istate_struct.ag.h \
+	arch/$(KARCH)/include/arch/context_struct.ag.h \
+	arch/$(KARCH)/include/arch/fpu_context_struct.ag.h
Index: kernel/arch/ppc32/Makefile.inc
===================================================================
--- kernel/arch/ppc32/Makefile.inc	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/ppc32/Makefile.inc	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -60,6 +60,6 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(KARCH)/include/arch/istate_struct.ag \
-	arch/$(KARCH)/include/arch/context_struct.ag \
-	arch/$(KARCH)/include/arch/fpu_context_struct.ag
+	arch/$(KARCH)/include/arch/istate_struct.ag.h \
+	arch/$(KARCH)/include/arch/context_struct.ag.h \
+	arch/$(KARCH)/include/arch/fpu_context_struct.ag.h
 
Index: kernel/arch/riscv64/Makefile.inc
===================================================================
--- kernel/arch/riscv64/Makefile.inc	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/riscv64/Makefile.inc	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -55,4 +55,4 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(KARCH)/include/arch/istate_struct.ag \
-	arch/$(KARCH)/include/arch/context_struct.ag
+	arch/$(KARCH)/include/arch/istate_struct.ag.h \
+	arch/$(KARCH)/include/arch/context_struct.ag.h
Index: kernel/arch/sparc64/Makefile.inc
===================================================================
--- kernel/arch/sparc64/Makefile.inc	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/arch/sparc64/Makefile.inc	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -111,5 +111,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(KARCH)/include/arch/istate_struct.ag \
-	arch/$(KARCH)/include/arch/context_struct.ag
+	arch/$(KARCH)/include/arch/istate_struct.ag.h \
+	arch/$(KARCH)/include/arch/context_struct.ag.h
 
Index: kernel/genarch/Makefile.inc
===================================================================
--- kernel/genarch/Makefile.inc	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/genarch/Makefile.inc	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -173,6 +173,6 @@
 	genarch/src/multiboot/multiboot2.c
 GENARCH_AUTOGENS_AG += \
-	genarch/include/genarch/multiboot/multiboot_memmap_struct.ag \
-	genarch/include/genarch/multiboot/multiboot_info_struct.ag
+	genarch/include/genarch/multiboot/multiboot_memmap_struct.ag.h \
+	genarch/include/genarch/multiboot/multiboot_info_struct.ag.h
 endif
 
Index: kernel/genarch/include/genarch/multiboot/multiboot.h
===================================================================
--- kernel/genarch/include/genarch/multiboot/multiboot.h	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ kernel/genarch/include/genarch/multiboot/multiboot.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -36,6 +36,4 @@
 #define KERN_MULTIBOOT_H_
 
-#include <genarch/multiboot/multiboot_memmap_struct.h>
-#include <genarch/multiboot/multiboot_info_struct.h>
 
 #define MULTIBOOT_HEADER_MAGIC  0x1badb002
@@ -52,5 +50,13 @@
 #define MULTIBOOT_INFO_FLAGS_MMAP	0x40
 
-#ifndef __ASM__
+#ifdef __ASM__
+
+#include <genarch/multiboot/multiboot_memmap_struct.ag.h>
+#include <genarch/multiboot/multiboot_info_struct.ag.h>
+
+#else
+
+#include <genarch/multiboot/multiboot_memmap_struct.h>
+#include <genarch/multiboot/multiboot_info_struct.h>
 
 #include <typedefs.h>
Index: rnel/genarch/include/genarch/multiboot/multiboot_info_struct.ag
===================================================================
--- kernel/genarch/include/genarch/multiboot/multiboot_info_struct.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,81 +1,0 @@
-# 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 : multiboot_info,
-        packed : true,
-
-        includes : [
-                {
-                        include : <typedefs.h>
-                },
-        ],
-
-        members : [
-                {
-                        name : flags,
-                        type : uint32_t
-                },
-                {
-                        name : mem_lower,
-                        type : uint32_t
-                },
-                {
-                        name : mem_upper,
-                        type : uint32_t
-                },
-                {
-                        name : boot_device,
-                        type : uint32_t
-                },
-                {
-                        name : cmd_line,
-                        type : uint32_t
-                },
-                {
-                        name : mods_count,
-                        type : uint32_t
-                },
-                {
-                        name : mods_addr,
-                        type : uint32_t
-                },
-                {
-                        name : syms,
-                        type : uint32_t,
-                        elements : 4,
-                },
-                {
-                        name : mmap_length,
-                        type : uint32_t,
-                },
-                {
-                        name : mmap_addr,
-                        type : uint32_t,
-                }
-        ]
-}
Index: kernel/genarch/include/genarch/multiboot/multiboot_info_struct.h
===================================================================
--- kernel/genarch/include/genarch/multiboot/multiboot_info_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ kernel/genarch/include/genarch/multiboot/multiboot_info_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,43 @@
+/* Copyright (c) 2016 Jakub Jermar
+ * All rights preserved.
+ *
+ * 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.
+ */
+
+#pragma once
+#include <stdint.h>
+
+typedef struct multiboot_info {
+	uint32_t flags;
+	uint32_t mem_lower;
+	uint32_t mem_upper;
+	uint32_t boot_device;
+	uint32_t cmd_line;
+	uint32_t mods_count;
+	uint32_t mods_addr;
+	uint32_t syms[4];
+	uint32_t mmap_length;
+	uint32_t mmap_addr;
+} __attribute__((packed)) multiboot_info_t;
+
Index: rnel/genarch/include/genarch/multiboot/multiboot_memmap_struct.ag
===================================================================
--- kernel/genarch/include/genarch/multiboot/multiboot_memmap_struct.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,52 +1,0 @@
-# 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 : multiboot_memmap,
-        packed : true,
-
-        includes : [
-                {
-                        include : <typedefs.h>
-                },
-                {
-                        include : <arch/boot/memmap_struct.h>,
-                        depends: arch/$(KARCH)/include/arch/boot/memmap_struct.h,
-                }
-        ],
-
-        members : [
-                {
-                        name : size,
-                        type : uint32_t
-                },
-                {
-                        name : mm_info,
-                        type : e820memmap_t
-                }
-        ]
-}
Index: kernel/genarch/include/genarch/multiboot/multiboot_memmap_struct.h
===================================================================
--- kernel/genarch/include/genarch/multiboot/multiboot_memmap_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ kernel/genarch/include/genarch/multiboot/multiboot_memmap_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,36 @@
+/* Copyright (c) 2016 Jakub Jermar
+ * All rights preserved.
+ *
+ * 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.
+ */
+
+#pragma once
+#include <stdint.h>
+#include <arch/boot/memmap_struct.h>
+
+typedef struct multiboot_memmap {
+	uint32_t size;
+	e820memmap_t mm_info;
+} __attribute__((packed)) multiboot_memmap_t;
+
Index: ols/autogen.py
===================================================================
--- tools/autogen.py	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,184 +1,0 @@
-#!/usr/bin/env python
-#
-# 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.
-#
-
-import sys
-import yaml
-import re
-
-def usage():
-	print("%s - Automated structure and offsets generator" % sys.argv[0])
-	print("%s file.ag depend|probe|generate struct.ag" % sys.argv[0])
-	sys.exit()
-
-def depend(struct):
-	deps = ""
-	for include in struct['includes']:
-		if 'depends' in include.keys():
-			deps = deps + include['depends'] + "\n"
-	return deps.strip()
-
-def generate_includes(struct):
-	code = ""
-	for include in struct['includes']:
-		if 'guard' in include.keys():
-			code = code + "#ifdef %s\n" % include['guard']
-		if 'negative-guard' in include.keys():
-			code = code + "#ifndef %s\n" % include['negative-guard']
-		code = code + "#include %s\n" % include['include']
-		if 'guard' in include.keys():
-			code = code + "#endif\n"
-		if 'negative-guard' in include.keys():
-			code = code + "#endif\n"
-	return code.strip()
-
-def generate_struct(struct):
-	packed = ""
-	if ('packed' in struct.keys() and struct['packed']):
-		packed = "__attribute__ ((packed)) "
-	code = "typedef struct %s {\n" % struct['name']
-	for i in range(len(struct['members'])):
-		member = struct['members'][i]
-		if 'elements' in member.keys():
-			code = code + "\t%s %s[%d];\n" % (member['type'], member['name'], member['elements'])
-		else:
-			code = code + "\t%s %s;\n" % (member['type'], member['name'])
-	code = code + "} %s%s_t;" % (packed, struct['name'])
-	return code
-
-def generate_probes(struct):
-	code = ""
-	for i in range(len(struct['members'])):
-		member = struct['members'][i]
-		code = code + ("\temit_constant(%s_OFFSET_%s, offsetof(%s_t, %s));\n" %
-		    (struct['name'].upper(), member['name'].upper(), struct['name'],
-		    member['name']))
-		code = code + ("\temit_constant(%s_SIZE_%s, sizeof(((%s_t *) 0)->%s));\n" %
-		    (struct['name'].upper(), member['name'].upper(), struct['name'],
-		    member['name']))
-		if 'elements' in member.keys():
-			code = code + ("\temit_constant(%s_%s_ITEM_SIZE, sizeof(%s));\n" %
-			    (struct['name'].upper(), member['name'].upper(), member['type']))
-
-	return code
-
-def probe(struct):
-	name = struct['name']
-	typename = struct['name'] + "_t"
-
-	code = """
-%s
-
-#define str(s) #s
-#define emit_constant(n, v) \
-    asm volatile ("EMITTED_CONSTANT " str(n) \" = %%0\" :: \"i\" (v))
-#undef offsetof
-#define offsetof(t, m) ((size_t) &(((t *) 0)->m))
-
-%s
-
-extern int main(int, char *[]);
-
-int main(int argc, char *argv[])
-{
-%s
-	emit_constant(%s_SIZE, sizeof(%s));
-	return 0;
-}
-	""" % (generate_includes(struct), generate_struct(struct),
-	    generate_probes(struct), name.upper(), typename)
-
-	return code
-
-def generate_defines(pairs):
-	code = ""
-	for pair in pairs:
-		code = code + "#define %s %s\n" % (pair[0], pair[1])
-	return code.strip()
-
-def generate(struct, lines):
-	code = """
-/*****************************************************************************
- * AUTO-GENERATED FILE, DO NOT EDIT!!!
- * Generated by: tools/autogen.py
- * Generated from: %s
- *****************************************************************************/
-
-#ifndef AUTOGEN_%s_H
-#define AUTOGEN_%s_H
-
-#ifndef __ASM__
-%s
-#endif
-
-%s
-
-#ifndef __ASM__
-%s
-#endif
-
-#endif
-	""" % (sys.argv[2], struct['name'].upper(), struct['name'].upper(),
-	    generate_includes(struct), generate_defines(lines),
-	    generate_struct(struct))
-
-	return code
-
-def filter_pairs(lines):
-	pattern = re.compile("^\tEMITTED_CONSTANT ([A-Z_][A-Z0-9_]*) = (\$|#)?([0-9]+)$");
-	pairs = []
-	for line in lines:
-		res = pattern.match(line)
-		if res == None:
-			continue
-		pairs = pairs + [res.group(1, 3)]
-	return pairs
-
-
-def run():
-	if len(sys.argv) != 3:
-		usage()
-
-	with open(sys.argv[2], "rb") as fp:
-		struct = yaml.load(fp)
-
-	if sys.argv[1] == "depend":
-		deps = depend(struct)
-		print(deps)
-	elif sys.argv[1] == "probe":
-		code = probe(struct)
-		print(code)
-	elif sys.argv[1] == "generate":
-		lines = sys.stdin.readlines()
-		pairs = filter_pairs(lines)
-		code = generate(struct, pairs)
-		print(code)
-	else:
-		usage()
-
-run()
Index: tools/autogen2.awk
===================================================================
--- tools/autogen2.awk	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ tools/autogen2.awk	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,23 @@
+#!/usr/bin/awk -f
+
+/}.*;/ {
+	if (($0 != "};") && ($0 != "} " struct_name "_t;")) {
+		print("Bad struct ending: " $0) > "/dev/stderr"
+		exit 1
+	}
+	print "DEFINE_STRUCT(" struct_name ", " toupper(struct_name) ")"
+	struct_name = ""
+}
+
+/;$/ {
+	if (struct_name != "") {
+		# Remove array subscript, if any.
+		sub("(\\[.*\\])?;", "", $0)
+		member = $NF
+		print "DEFINE_MEMBER(" struct_name ", " toupper(struct_name) ", " member ", " toupper(member) ")"
+	}
+}
+
+/^typedef struct .* \{/ {
+	struct_name = $3
+}
Index: tools/autogen2.sh
===================================================================
--- tools/autogen2.sh	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ tools/autogen2.sh	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+# There's a bunch of restriction. The script assumes that the structure definition begins with "typedef struct struct_name {",
+# ends with "struct_name_t;", and that every word in between that ends with ";" is a struct member name with optional
+# array subscript. Error handling is mostly omitted for simplicity, so any input that does not follow these rules will result
+# in cryptic errors.
+
+input="$1"
+output="$2"
+toolsdir="$(readlink -f $(dirname "$0"))"
+awkscript="$toolsdir/autogen2.awk"
+
+# Set default value for $CC.
+if [ -z "${CC}" ]; then
+	CC=cc
+fi
+
+# If $CC is clang, we need to make sure integrated assembler is not used.
+if ( ${CC} --version | grep clang > /dev/null ) ; then
+	CFLAGS="${CFLAGS} -no-integrated-as"
+fi
+
+# Tell the compiler to generate makefile dependencies.
+CFLAGS="${CFLAGS} -MD -MP -MT $output -MF $output.d"
+
+# Generate defines
+defs=`$awkscript -- $input || exit 1`
+
+# Generate C file.
+cat > $output.c <<- EOF
+
+#include "`basename $input`"
+
+#define DEFINE_MEMBER(ls, us, lm, um) \
+	asm volatile ("/* #define "#us"_OFFSET_"#um" %0 */" :: "i" (__builtin_offsetof(struct ls, lm))); \
+	asm volatile ("/* #define "#us"_SIZE_"#um" %0 */" :: "i" (sizeof((struct ls){}.lm)));
+
+#define DEFINE_STRUCT(ls, us) \\
+	asm volatile ("/* #define "#us"_SIZE %0 */" :: "i" (sizeof(struct ls)));
+
+void autogen()
+{
+	$defs
+}
+
+EOF
+
+# Turn the C file into assembly.
+${CC} ${CFLAGS} -w -S -o $output.s $output.c || exit 1
+
+# Process the output.
+
+echo "/* Autogenerated file, do not modify. */" > $output
+echo "#pragma once" >> $output
+sed -n 's/^.* #define \([^ ]\+\) [^0-9]*\([0-9]\+\) .*/#define \1 \2/p' < $output.s >> $output || exit 1
Index: tools/autotool.py
===================================================================
--- tools/autotool.py	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ tools/autotool.py	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -681,6 +681,4 @@
 		sandbox_leave(owd)
 
-	common['AUTOGEN'] = "%s/autogen.py" % os.path.dirname(os.path.abspath(sys.argv[0]))
-
 	create_makefile(MAKEFILE, common)
 	create_header(HEADER, macros)
Index: uspace/Makefile.common
===================================================================
--- uspace/Makefile.common	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ uspace/Makefile.common	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -67,4 +67,6 @@
 CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
 CONFIG_HEADER = $(ROOT_PATH)/config.h
+
+AUTOGEN = $(ROOT_PATH)/tools/autogen2.sh
 
 -include $(VERSION_DEF)
@@ -352,4 +354,7 @@
 	$(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS)
 
+%.ag.h %.ag.s %.ag.c %.ag.d: %.h
+	CC="$(CC)" CFLAGS="$(CFLAGS)" $(AUTOGEN) $< $@
+
 -include $(DEPENDS)
 
Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ uspace/lib/c/Makefile	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -48,10 +48,9 @@
 -include arch/$(UARCH)/Makefile.inc
 
-ARCH_AUTOGENS_H := $(addsuffix .h,$(basename $(ARCH_AUTOGENS_AG)))
-ARCH_AUTOGENS_PROBE_C := $(addsuffix .ag.probe.c,$(basename $(ARCH_AUTOGENS_AG)))
-ARCH_AUTOGENS_PROBE_S := $(addsuffix .ag.probe.s,$(basename $(ARCH_AUTOGENS_AG)))
-
-PRE_DEPEND += $(ARCH_AUTOGENS_H)
-EXTRA_CLEAN += $(ARCH_AUTOGENS_H) $(ARCH_AUTOGENS_PROBE_C) $(ARCH_AUTOGENS_PROBE_S)
+ARCH_AUTOGENS_PROBE_C := $(ARCH_AUTOGENS_AG:%.ag.h=.ag.c)
+ARCH_AUTOGENS_PROBE_S := $(ARCH_AUTOGENS_AG:%.ag.h=.ag.s)
+
+PRE_DEPEND += $(ARCH_AUTOGENS_AG)
+EXTRA_CLEAN += $(ARCH_AUTOGENS_AG) $(ARCH_AUTOGENS_PROBE_C) $(ARCH_AUTOGENS_PROBE_S)
 
 GENERIC_SOURCES = \
@@ -194,9 +193,4 @@
 include $(USPACE_PREFIX)/Makefile.common
 
-%.h: %.ag
-	$(AUTOGEN) probe $< >$<.probe.c
-	$(CC_AUTOGEN) $(DEFS) $(CFLAGS) -S -o $<.probe.s $<.probe.c
-	$(AUTOGEN) generate $< <$<.probe.s >$@
-
 $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld: $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld.in
 	$(CC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -E -x c $< | grep -v "^\#" > $@
Index: uspace/lib/c/arch/amd64/Makefile.inc
===================================================================
--- uspace/lib/c/arch/amd64/Makefile.inc	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ uspace/lib/c/arch/amd64/Makefile.inc	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -37,6 +37,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(UARCH)/include/libarch/istate_struct.ag \
-	arch/$(UARCH)/include/libarch/fibril_context.ag
+	arch/$(UARCH)/include/libarch/fibril_context.ag.h
 
 EXTRA_OUTPUT += arch/$(UARCH)/src/entry.o
Index: pace/lib/c/arch/amd64/include/libarch/fibril_context.ag
===================================================================
--- uspace/lib/c/arch/amd64/include/libarch/fibril_context.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,86 +1,0 @@
-# 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 : <stddef.h>
-                },
-                {
-                        include : <stdint.h>
-                },
-        ],
-
-        members : [
-                #
-                # We include only registers that must be preserved
-                # during function call.
-                #
-
-                {
-                        name : sp,
-                        type : uint64_t
-                },
-                {
-                        name : pc,
-                        type : uint64_t
-                },
-
-                {
-                        name : rbx,
-                        type : uint64_t
-                },
-                {
-                        name : rbp,
-                        type : uint64_t
-                },
-
-                {
-                        name : r12,
-                        type : uint64_t
-                },
-                {
-                        name : r13,
-                        type : uint64_t
-                },
-                {
-                        name : r14,
-                        type : uint64_t
-                },
-                {
-                        name : r15,
-                        type : uint64_t
-                },
-
-                {
-                        name : tls,
-                        type : uint64_t
-                }
-        ]
-}
Index: uspace/lib/c/arch/amd64/include/libarch/fibril_context.h
===================================================================
--- uspace/lib/c/arch/amd64/include/libarch/fibril_context.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ uspace/lib/c/arch/amd64/include/libarch/fibril_context.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,45 @@
+/* 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.
+ */
+
+#pragma once
+#include <stdint.h>
+
+typedef struct context {
+	/* We include only registers that must be preserved
+	 * during function call.
+	 */
+	uint64_t sp;
+	uint64_t pc;
+	uint64_t rbx;
+	uint64_t rbp;
+	uint64_t r12;
+	uint64_t r13;
+	uint64_t r14;
+	uint64_t r15;
+	uint64_t tls;
+} context_t;
+
Index: pace/lib/c/arch/amd64/include/libarch/istate_struct.ag
===================================================================
--- uspace/lib/c/arch/amd64/include/libarch/istate_struct.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../../../../../../../kernel/arch/amd64/include/arch/istate_struct.ag
Index: uspace/lib/c/arch/amd64/include/libarch/istate_struct.h
===================================================================
--- uspace/lib/c/arch/amd64/include/libarch/istate_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ uspace/lib/c/arch/amd64/include/libarch/istate_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,1 @@
+../../../../../../../kernel/arch/amd64/include/arch/istate_struct.h
Index: uspace/lib/c/arch/amd64/src/fibril.S
===================================================================
--- uspace/lib/c/arch/amd64/src/fibril.S	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ uspace/lib/c/arch/amd64/src/fibril.S	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -28,5 +28,5 @@
 
 #include <abi/asmtool.h>
-#include <libarch/fibril_context.h>
+#include <libarch/fibril_context.ag.h>
 
 .text
Index: uspace/lib/c/arch/arm32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/arm32/Makefile.inc	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ uspace/lib/c/arch/arm32/Makefile.inc	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -38,8 +38,4 @@
 	arch/$(UARCH)/src/stacktrace_asm.S
 
-ARCH_AUTOGENS_AG = \
-	arch/$(UARCH)/include/libarch/istate_struct.ag \
-	arch/$(UARCH)/include/libarch/fibril_context.ag
-
 EXTRA_OUTPUT += arch/$(UARCH)/src/entry.o
 
Index: pace/lib/c/arch/arm32/include/libarch/fibril_context.ag
===================================================================
--- uspace/lib/c/arch/arm32/include/libarch/fibril_context.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,92 +1,0 @@
-# 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 : <stddef.h>
-                },
-                {
-                        include : <stdint.h>
-                }
-        ],
-
-       #
-       # Only registers preserved accross function calls are included. r9 is
-       # used to store a TLS address. -ffixed-r9 gcc forces gcc not to use this
-       # register. -mtp=soft forces gcc to use #__aeabi_read_tp to obtain
-       # TLS address.
-       #
-        members : [
-                {
-                        name : sp,
-                        type : uintptr_t
-                },
-                {
-                        name : pc,
-                        type : uintptr_t
-                },
-
-                {
-                        name : r4,
-                        type : uint32_t
-                },
-                {
-                        name : r5,
-                        type : uint32_t
-                },
-                {
-                        name : r6,
-                        type : uint32_t
-                },
-                {
-                        name : r7,
-                        type : uint32_t
-                },
-                {
-                        name : r8,
-                        type : uint32_t
-                },
-                {
-                        # r9
-                        name : tls,
-                        type : uint32_t
-                },
-                {
-                        name : r10,
-                        type : uint32_t
-                },
-                {
-                        # r11
-                        name : fp,
-                        type : uint32_t
-                }
-        ]
-}
-
Index: uspace/lib/c/arch/arm32/include/libarch/fibril_context.h
===================================================================
--- uspace/lib/c/arch/arm32/include/libarch/fibril_context.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ uspace/lib/c/arch/arm32/include/libarch/fibril_context.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,24 @@
+#pragma once
+#include <stdint.h>
+
+/*
+ * Only registers preserved accross function calls are included. r9 is
+ * used to store a TLS address. -ffixed-r9 gcc forces gcc not to use this
+ * register. -mtp=soft forces gcc to use #__aeabi_read_tp to obtain
+ * TLS address.
+ */
+typedef struct context {
+	uintptr_t sp;
+	uintptr_t pc;
+	uint32_t r4;
+	uint32_t r5;
+	uint32_t r6;
+	uint32_t r7;
+	uint32_t r8;
+	/* r9*/
+	uint32_t tls;
+	uint32_t r10;
+	/* r11 */
+	uint32_t fp;
+} context_t;
+
Index: pace/lib/c/arch/arm32/include/libarch/istate_struct.ag
===================================================================
--- uspace/lib/c/arch/arm32/include/libarch/istate_struct.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../../../../../../../kernel/arch/arm32/include/arch/istate_struct.ag
Index: uspace/lib/c/arch/arm32/include/libarch/istate_struct.h
===================================================================
--- uspace/lib/c/arch/arm32/include/libarch/istate_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ uspace/lib/c/arch/arm32/include/libarch/istate_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,1 @@
+../../../../../../../kernel/arch/arm32/include/arch/istate_struct.h
Index: uspace/lib/c/arch/ia32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/ia32/Makefile.inc	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ uspace/lib/c/arch/ia32/Makefile.inc	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -39,6 +39,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(UARCH)/include/libarch/istate_struct.ag \
-	arch/$(UARCH)/include/libarch/fibril_context.ag
+	arch/$(UARCH)/include/libarch/fibril_context.ag.h
 
 EXTRA_OUTPUT += arch/$(UARCH)/src/entry.o
Index: pace/lib/c/arch/ia32/include/libarch/fibril_context.ag
===================================================================
--- uspace/lib/c/arch/ia32/include/libarch/fibril_context.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,77 +1,0 @@
-# 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 : <stddef.h>
-                },
-                {
-                        include : <stdint.h>
-                }
-        ],
-
-        members : [
-                #
-                # We include only registers that must be preserved
-                # during function call.
-                #
-
-                {
-                        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 : tls,
-                        type : uint32_t
-                }
-        ]
-}
Index: uspace/lib/c/arch/ia32/include/libarch/fibril_context.h
===================================================================
--- uspace/lib/c/arch/ia32/include/libarch/fibril_context.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ uspace/lib/c/arch/ia32/include/libarch/fibril_context.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,41 @@
+/* Copyright (c) 2014 Jakub Jermar
+ * All rights preserved.
+ *
+ * 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.
+ */
+
+#pragma once
+#include <stdint.h>
+
+/* We include only registers that must be preserved during function call. */
+typedef struct context {
+	uint32_t sp;
+	uint32_t pc;
+	uint32_t ebx;
+	uint32_t esi;
+	uint32_t edi;
+	uint32_t ebp;
+	uint32_t tls;
+} context_t;
+
Index: pace/lib/c/arch/ia32/include/libarch/istate_struct.ag
===================================================================
--- uspace/lib/c/arch/ia32/include/libarch/istate_struct.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../../../../../../../kernel/arch/ia32/include/arch/istate_struct.ag
Index: uspace/lib/c/arch/ia32/include/libarch/istate_struct.h
===================================================================
--- uspace/lib/c/arch/ia32/include/libarch/istate_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ uspace/lib/c/arch/ia32/include/libarch/istate_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,1 @@
+../../../../../../../kernel/arch/ia32/include/arch/istate_struct.h
Index: uspace/lib/c/arch/ia32/src/fibril.S
===================================================================
--- uspace/lib/c/arch/ia32/src/fibril.S	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ uspace/lib/c/arch/ia32/src/fibril.S	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -28,5 +28,5 @@
 
 #include <abi/asmtool.h>
-#include <libarch/fibril_context.h>
+#include <libarch/fibril_context.ag.h>
 
 .text
Index: uspace/lib/c/arch/ia64/Makefile.inc
===================================================================
--- uspace/lib/c/arch/ia64/Makefile.inc	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ uspace/lib/c/arch/ia64/Makefile.inc	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -38,6 +38,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(UARCH)/include/libarch/istate_struct.ag \
-	arch/$(UARCH)/include/libarch/fibril_context.ag
+	arch/$(UARCH)/include/libarch/fibril_context.ag.h
 
 EXTRA_OUTPUT += arch/$(UARCH)/src/entry.o
Index: pace/lib/c/arch/ia64/include/libarch/fibril_context.ag
===================================================================
--- uspace/lib/c/arch/ia64/include/libarch/fibril_context.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,235 +1,0 @@
-# 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 : <stddef.h>
-                },
-                {
-                        include : <stdint.h>
-                }
-        ],
-
-        #
-        # Only save registers that must be preserved across function calls.
-        #
-        members : [
-                #
-                # Application registers
-                #
-                {
-                        name : ar_pfs,
-                        type : uint64_t
-                },
-                {
-                        name : ar_unat_caller,
-                        type : uint64_t
-                },
-                {
-                        name : ar_unat_callee,
-                        type : uint64_t
-                },
-                {
-                        name : ar_rsc,
-                        type : uint64_t
-                },
-                {
-                        # ar_bsp
-                        name : bsp,
-                        type : uint64_t
-                },
-                {
-                        name : ar_rnat,
-                        type : uint64_t
-                },
-                {
-                        name : ar_lc,
-                        type : uint64_t
-                },
-
-
-                #
-                # General registers
-                #
-                {
-                        name : r1,
-                        type : uint64_t
-                },
-                {
-                        name : r4,
-                        type : uint64_t
-                },
-                {
-                        name : r5,
-                        type : uint64_t
-                },
-                {
-                        name : r6,
-                        type : uint64_t
-                },
-                {
-                        name : r7,
-                        type : uint64_t
-                },
-                {
-                        # r12
-                        name : sp,
-                        type : uint64_t
-                },
-                {
-                        # r13
-                        name : tp,
-                        type : uint64_t
-                },
-
-
-                #
-                # Branch registers
-                #
-                {
-                        # b0
-                        name : pc,
-                        type : uint64_t
-                },
-                {
-                        name : b1,
-                        type : uint64_t
-                },
-                {
-                        name : b2,
-                        type : uint64_t
-                },
-                {
-                        name : b3,
-                        type : uint64_t
-                },
-                {
-                        name : b4,
-                        type : uint64_t
-                },
-                {
-                        name : b5,
-                        type : uint64_t
-                },
-
-
-                #
-                # Predicate registers
-                #
-                {
-                        name : pr,
-                        type : uint64_t
-                },
-
-                {
-                        name : f2,
-                        type : uint128_t
-                },
-                {
-                        name : f3,
-                        type : uint128_t
-                },
-                {
-                        name : f4,
-                        type : uint128_t
-                },
-                {
-                        name : f5,
-                        type : uint128_t
-                },
-
-                {
-                        name : f16,
-                        type : uint128_t
-                },
-                {
-                        name : f17,
-                        type : uint128_t
-                },
-                {
-                        name : f18,
-                        type : uint128_t
-                },
-                {
-                        name : f19,
-                        type : uint128_t
-                },
-                {
-                        name : f20,
-                        type : uint128_t
-                },
-                {
-                        name : f21,
-                        type : uint128_t
-                },
-                {
-                        name : f22,
-                        type : uint128_t
-                },
-                {
-                        name : f23,
-                        type : uint128_t
-                },
-                {
-                        name : f24,
-                        type : uint128_t
-                },
-                {
-                        name : f25,
-                        type : uint128_t
-                },
-                {
-                        name : f26,
-                        type : uint128_t
-                },
-                {
-                        name : f27,
-                        type : uint128_t
-                },
-                {
-                        name : f28,
-                        type : uint128_t
-                },
-                {
-                        name : f29,
-                        type : uint128_t
-                },
-                {
-                        name : f30,
-                        type : uint128_t
-                },
-                {
-                        name : f31,
-                        type : uint128_t
-                }
-
-        ]
-}
-
Index: uspace/lib/c/arch/ia64/include/libarch/fibril_context.h
===================================================================
--- uspace/lib/c/arch/ia64/include/libarch/fibril_context.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ uspace/lib/c/arch/ia64/include/libarch/fibril_context.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,86 @@
+/* Copyright (c) 2014 Jakub Jermar
+ * All rights preserved.
+ *
+ * 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.
+ */
+
+#pragma once
+#include <stdint.h>
+
+// Only save registers that must be preserved across function calls.
+typedef struct context {
+	// Application registers.
+	uint64_t ar_pfs;
+	uint64_t ar_unat_caller;
+	uint64_t ar_unat_callee;
+	uint64_t ar_rsc;
+	// ar_bsp
+	uint64_t bsp;
+	uint64_t ar_rnat;
+	uint64_t ar_lc;
+
+	// General registers.
+	uint64_t r1;
+	uint64_t r4;
+	uint64_t r5;
+	uint64_t r6;
+	uint64_t r7;
+	// r12
+	uint64_t sp;
+	// r13
+	uint64_t tp;
+
+	// Branch registers.
+	// b0
+	uint64_t pc;
+	uint64_t b1;
+	uint64_t b2;
+	uint64_t b3;
+	uint64_t b4;
+	uint64_t b5;
+
+	// Predicate registers.
+	uint64_t pr;
+	uint128_t f2;
+	uint128_t f3;
+	uint128_t f4;
+	uint128_t f5;
+	uint128_t f16;
+	uint128_t f17;
+	uint128_t f18;
+	uint128_t f19;
+	uint128_t f20;
+	uint128_t f21;
+	uint128_t f22;
+	uint128_t f23;
+	uint128_t f24;
+	uint128_t f25;
+	uint128_t f26;
+	uint128_t f27;
+	uint128_t f28;
+	uint128_t f29;
+	uint128_t f30;
+	uint128_t f31;
+} context_t;
+
Index: pace/lib/c/arch/ia64/include/libarch/istate_struct.ag
===================================================================
--- uspace/lib/c/arch/ia64/include/libarch/istate_struct.ag	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../../../../../../../kernel/arch/ia64/include/arch/istate_struct.ag
Index: uspace/lib/c/arch/ia64/include/libarch/istate_struct.h
===================================================================
--- uspace/lib/c/arch/ia64/include/libarch/istate_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
+++ uspace/lib/c/arch/ia64/include/libarch/istate_struct.h	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -0,0 +1,1 @@
+../../../../../../../kernel/arch/ia64/include/arch/istate_struct.h
Index: uspace/lib/c/arch/ia64/src/fibril.S
===================================================================
--- uspace/lib/c/arch/ia64/src/fibril.S	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ uspace/lib/c/arch/ia64/src/fibril.S	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -28,5 +28,5 @@
 
 #include <abi/asmtool.h>
-#include <libarch/fibril_context.h>
+#include <libarch/fibril_context.ag.h>
 
 .text
Index: uspace/lib/c/arch/mips32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/mips32/Makefile.inc	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ uspace/lib/c/arch/mips32/Makefile.inc	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -37,6 +37,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(UARCH)/include/libarch/istate_struct.ag \
-	arch/$(UARCH)/include/libarch/fibril_context.ag
+	arch/$(UARCH)/include/libarch/fibril_context.ag.h
 
 EXTRA_OUTPUT += arch/$(UARCH)/src/entry.o
Index: uspace/lib/c/arch/mips32eb/Makefile.inc
===================================================================
--- uspace/lib/c/arch/mips32eb/Makefile.inc	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ uspace/lib/c/arch/mips32eb/Makefile.inc	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -37,6 +37,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(UARCH)/include/libarch/istate_struct.ag \
-	arch/$(UARCH)/include/libarch/fibril_context.ag
+	arch/$(UARCH)/include/libarch/fibril_context.ag.h
 
 EXTRA_OUTPUT += arch/$(UARCH)/src/entry.o
Index: uspace/lib/c/arch/ppc32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/ppc32/Makefile.inc	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ uspace/lib/c/arch/ppc32/Makefile.inc	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -37,6 +37,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(UARCH)/include/libarch/istate_struct.ag \
-	arch/$(UARCH)/include/libarch/fibril_context.ag
+	arch/$(UARCH)/include/libarch/fibril_context.ag.h
 
 EXTRA_OUTPUT += arch/$(UARCH)/src/entry.o
Index: uspace/lib/c/arch/riscv64/Makefile.inc
===================================================================
--- uspace/lib/c/arch/riscv64/Makefile.inc	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ uspace/lib/c/arch/riscv64/Makefile.inc	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -36,6 +36,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(UARCH)/include/libarch/istate_struct.ag \
-	arch/$(UARCH)/include/libarch/fibril_context.ag
+	arch/$(UARCH)/include/libarch/fibril_context.ag.h
 
 EXTRA_OUTPUT += arch/$(UARCH)/src/entry.o
Index: uspace/lib/c/arch/sparc64/Makefile.inc
===================================================================
--- uspace/lib/c/arch/sparc64/Makefile.inc	(revision fd57cf17d12bbe3b41626a0b8708f075134a073e)
+++ uspace/lib/c/arch/sparc64/Makefile.inc	(revision 0aa06cbe8a6965cc7f1ebfa7236bcd8d5316da16)
@@ -36,6 +36,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(UARCH)/include/libarch/istate_struct.ag \
-	arch/$(UARCH)/include/libarch/fibril_context.ag
+	arch/$(UARCH)/include/libarch/fibril_context.ag.h
 
 EXTRA_OUTPUT += arch/$(UARCH)/src/entry.o
