Index: kernel/Makefile
===================================================================
--- kernel/Makefile	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/Makefile	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -59,4 +59,5 @@
 REAL_MAP = generic/src/debug/real_map
 
+ABI_INCLUDE = generic/include/abi
 ARCH_INCLUDE = generic/include/arch
 GENARCH_INCLUDE = generic/include/genarch
@@ -75,5 +76,5 @@
 
 clean:
-	rm -f $(DEPEND) $(DEPEND_PREV) $(RAW) $(BIN) $(MAP) $(JOB) $(MAP_PREV) $(DISASM) $(DUMP) $(REAL_MAP).* $(ARCH_INCLUDE) $(GENARCH_INCLUDE) arch/*/_link.ld arch/*/include/common.h
+	rm -f $(DEPEND) $(DEPEND_PREV) $(RAW) $(BIN) $(MAP) $(JOB) $(MAP_PREV) $(DISASM) $(DUMP) $(REAL_MAP).* $(ABI_INCLUDE) $(ARCH_INCLUDE) $(GENARCH_INCLUDE) arch/*/_link.ld arch/*/include/common.h
 	find generic/src/ arch/*/src/ genarch/src/ test/ -name '*.o' -follow -exec rm \{\} \;
 
@@ -432,8 +433,11 @@
 	$(GENMAP) $(MAP_PREV) $(DUMP) $@
 
-$(DEPEND): $(ARCH_INCLUDE) $(GENARCH_INCLUDE) $(COMMON_HEADER_ARCH)
+$(DEPEND): $(ABI_INCLUDE) $(ARCH_INCLUDE) $(GENARCH_INCLUDE) $(COMMON_HEADER_ARCH)
 	makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(ARCH_SOURCES) $(GENARCH_SOURCES) $(GENERIC_SOURCES) > $@ 2> /dev/null
 	-[ -f $(DEPEND_PREV) ] && diff -q $(DEPEND_PREV) $@ && mv -f $(DEPEND_PREV) $@
 
+$(ABI_INCLUDE): ../abi/include/
+	ln -sfn ../../$< $@
+
 $(ARCH_INCLUDE): arch/$(KARCH)/include/
 	ln -sfn ../../$< $@
Index: kernel/arch/abs32le/include/istate.h
===================================================================
--- kernel/arch/abs32le/include/istate.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/abs32le/include/istate.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,15 +36,12 @@
 #define KERN_abs32le_ISTATE_H_
 
+#include <trace.h>
+
 #ifdef KERNEL
 
-#include <typedefs.h>
 #include <verify.h>
-#include <trace.h>
 
 #else /* KERNEL */
 
-#include <sys/types.h>
-
-#define NO_TRACE
 #define REQUIRES_EXTENT_MUTABLE(arg)
 #define WRITES(arg)
Index: kernel/arch/abs32le/include/mm/frame.h
===================================================================
--- kernel/arch/abs32le/include/mm/frame.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/abs32le/include/mm/frame.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -39,6 +39,4 @@
 #define FRAME_SIZE   (1 << FRAME_WIDTH)
 
-#ifdef KERNEL
-
 #include <typedefs.h>
 
@@ -46,6 +44,4 @@
 extern void physmem_print(void);
 
-#endif /* KERNEL */
-
 #endif
 
Index: kernel/arch/abs32le/include/mm/page.h
===================================================================
--- kernel/arch/abs32le/include/mm/page.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/abs32le/include/mm/page.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -41,6 +41,4 @@
 #define PAGE_WIDTH  FRAME_WIDTH
 #define PAGE_SIZE   FRAME_SIZE
-
-#ifdef KERNEL
 
 #define KA2PA(x)  (((uintptr_t) (x)) - UINT32_C(0x80000000))
@@ -178,6 +176,4 @@
 extern void page_fault(unsigned int, istate_t *);
 
-#endif /* KERNEL */
-
 #endif
 
Index: kernel/arch/abs32le/src/userspace.c
===================================================================
--- kernel/arch/abs32le/src/userspace.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/abs32le/src/userspace.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,7 +36,6 @@
 #include <typedefs.h>
 #include <arch.h>
-#include <proc/uarg.h>
+#include <abi/proc/uarg.h>
 #include <mm/as.h>
-
 
 void userspace(uspace_arg_t *kernel_uarg)
Index: kernel/arch/amd64/include/asm.h
===================================================================
--- kernel/arch/amd64/include/asm.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/amd64/include/asm.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -41,4 +41,6 @@
 #include <trace.h>
 
+#define IO_SPACE_BOUNDARY	((void *) (64 * 1024))
+
 /** Return base address of current stack.
  *
@@ -87,13 +89,16 @@
 NO_TRACE static inline uint8_t pio_read_8(ioport8_t *port)
 {
-	uint8_t val;
-	
-	asm volatile (
-		"inb %w[port], %b[val]\n"
-		: [val] "=a" (val)
-		: [port] "d" (port)
-	);
-	
-	return val;
+	if (port < (ioport8_t *) IO_SPACE_BOUNDARY) {
+		uint8_t val;
+		
+		asm volatile (
+			"inb %w[port], %b[val]\n"
+			: [val] "=a" (val)
+			: [port] "d" (port)
+		);
+		
+		return val;
+	} else
+		return (uint8_t) *port;
 }
 
@@ -108,13 +113,16 @@
 NO_TRACE static inline uint16_t pio_read_16(ioport16_t *port)
 {
-	uint16_t val;
-	
-	asm volatile (
-		"inw %w[port], %w[val]\n"
-		: [val] "=a" (val)
-		: [port] "d" (port)
-	);
-	
-	return val;
+	if (port < (ioport16_t *) IO_SPACE_BOUNDARY) {
+		uint16_t val;
+		
+		asm volatile (
+			"inw %w[port], %w[val]\n"
+			: [val] "=a" (val)
+			: [port] "d" (port)
+		);
+		
+		return val;
+	} else
+		return (uint16_t) *port;
 }
 
@@ -129,13 +137,16 @@
 NO_TRACE static inline uint32_t pio_read_32(ioport32_t *port)
 {
-	uint32_t val;
-	
-	asm volatile (
-		"inl %w[port], %[val]\n"
-		: [val] "=a" (val)
-		: [port] "d" (port)
-	);
-	
-	return val;
+	if (port < (ioport32_t *) IO_SPACE_BOUNDARY) {
+		uint32_t val;
+		
+		asm volatile (
+			"inl %w[port], %[val]\n"
+			: [val] "=a" (val)
+			: [port] "d" (port)
+		);
+		
+		return val;
+	} else
+		return (uint32_t) *port;
 }
 
@@ -150,9 +161,11 @@
 NO_TRACE static inline void pio_write_8(ioport8_t *port, uint8_t val)
 {
-	asm volatile (
-		"outb %b[val], %w[port]\n"
-		:: [val] "a" (val),
-		   [port] "d" (port)
-	);
+	if (port < (ioport8_t *) IO_SPACE_BOUNDARY) {
+		asm volatile (
+			"outb %b[val], %w[port]\n"
+			:: [val] "a" (val), [port] "d" (port)
+		);	
+	} else
+		*port = val;
 }
 
@@ -167,9 +180,11 @@
 NO_TRACE static inline void pio_write_16(ioport16_t *port, uint16_t val)
 {
-	asm volatile (
-		"outw %w[val], %w[port]\n"
-		:: [val] "a" (val),
-		   [port] "d" (port)
-	);
+	if (port < (ioport16_t *) IO_SPACE_BOUNDARY) {
+		asm volatile (
+			"outw %w[val], %w[port]\n"
+			:: [val] "a" (val), [port] "d" (port)
+		);
+	} else
+		*port = val;
 }
 
@@ -184,9 +199,11 @@
 NO_TRACE static inline void pio_write_32(ioport32_t *port, uint32_t val)
 {
-	asm volatile (
-		"outl %[val], %w[port]\n"
-		:: [val] "a" (val),
-		   [port] "d" (port)
-	);
+	if (port < (ioport32_t *) IO_SPACE_BOUNDARY) {
+		asm volatile (
+			"outl %[val], %w[port]\n"
+			:: [val] "a" (val), [port] "d" (port)
+		);
+	} else
+		*port = val;
 }
 
Index: kernel/arch/amd64/include/context.h
===================================================================
--- kernel/arch/amd64/include/context.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/amd64/include/context.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,6 +36,4 @@
 #define KERN_amd64_CONTEXT_H_
 
-#ifdef KERNEL
-
 #include <typedefs.h>
 
@@ -52,6 +50,4 @@
 		(c)->rbp = 0; \
 	} while (0)
-
-#endif /* KERNEL */
 
 /* We include only registers that must be preserved
Index: kernel/arch/amd64/include/istate.h
===================================================================
--- kernel/arch/amd64/include/istate.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/amd64/include/istate.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,16 +36,5 @@
 #define KERN_amd64_ISTATE_H_
 
-#ifdef KERNEL
-
-#include <typedefs.h>
 #include <trace.h>
-
-#else /* KERNEL */
-
-#include <sys/types.h>
-
-#define NO_TRACE
-
-#endif /* KERNEL */
 
 /** This is passed to interrupt handlers */
Index: kernel/arch/amd64/include/mm/frame.h
===================================================================
--- kernel/arch/amd64/include/mm/frame.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/amd64/include/mm/frame.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -39,5 +39,4 @@
 #define FRAME_SIZE   (1 << FRAME_WIDTH)
 
-#ifdef KERNEL
 #ifndef __ASM__
 
@@ -49,5 +48,4 @@
 
 #endif /* __ASM__ */
-#endif /* KERNEL */
 
 #endif
Index: kernel/arch/amd64/include/mm/page.h
===================================================================
--- kernel/arch/amd64/include/mm/page.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/amd64/include/mm/page.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -50,6 +50,4 @@
 #define PAGE_WIDTH  FRAME_WIDTH
 #define PAGE_SIZE   FRAME_SIZE
-
-#ifdef KERNEL
 
 #ifndef __ASM__
@@ -231,6 +229,4 @@
 #endif /* __ASM__ */
 
-#endif /* KERNEL */
-
 #endif
 
Index: kernel/arch/amd64/src/userspace.c
===================================================================
--- kernel/arch/amd64/src/userspace.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/amd64/src/userspace.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -38,7 +38,6 @@
 #include <typedefs.h>
 #include <arch.h>
-#include <proc/uarg.h>
+#include <abi/proc/uarg.h>
 #include <mm/as.h>
-
 
 /** Enter userspace
Index: kernel/arch/arm32/include/istate.h
===================================================================
--- kernel/arch/arm32/include/istate.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/arm32/include/istate.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -35,13 +35,15 @@
 #define KERN_arm32_ISTATE_H_
 
+#include <trace.h>
+
+#ifdef KERNEL
+
 #include <arch/regutils.h>
 
-#ifdef KERNEL
-#include <typedefs.h>
-#include <trace.h>
-#else
-#include <sys/types.h>
-#define NO_TRACE
-#endif
+#else /* KERNEL */
+
+#include <libarch/regutils.h>
+
+#endif /* KERNEL */
 
 /** Struct representing CPU state saved when an exception occurs. */
Index: kernel/arch/arm32/include/mm/frame.h
===================================================================
--- kernel/arch/arm32/include/mm/frame.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/arm32/include/mm/frame.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -40,5 +40,4 @@
 #define FRAME_SIZE   (1 << FRAME_WIDTH)
 
-#ifdef KERNEL
 #ifndef __ASM__
 
@@ -69,5 +68,4 @@
 
 #endif /* __ASM__ */
-#endif /* KERNEL */
 
 #endif
Index: kernel/arch/arm32/include/mm/page.h
===================================================================
--- kernel/arch/arm32/include/mm/page.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/arm32/include/mm/page.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -52,6 +52,4 @@
 #	define PA2KA(x)	((x) + 0x80000000)
 #endif
-
-#ifdef KERNEL
 
 /* Number of entries in each level. */
@@ -320,6 +318,4 @@
 #endif /* __ASM__ */
 
-#endif /* KERNEL */
-
 #endif
 
Index: kernel/arch/arm32/include/regutils.h
===================================================================
--- kernel/arch/arm32/include/regutils.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/arm32/include/regutils.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -30,5 +30,5 @@
  * @{
  */
-/** 
+/**
  * @file
  * @brief Utilities for convenient manipulation with ARM registers.
@@ -38,52 +38,49 @@
 #define KERN_arm32_REGUTILS_H_
 
-#define STATUS_REG_IRQ_DISABLED_BIT (1 << 7)
-#define STATUS_REG_MODE_MASK        0x1f
+#define STATUS_REG_IRQ_DISABLED_BIT  (1 << 7)
+#define STATUS_REG_MODE_MASK         0x1f
 
-#define CP15_R1_HIGH_VECTORS_BIT    (1 << 13)
-
+#define CP15_R1_HIGH_VECTORS_BIT     (1 << 13)
 
 /* ARM Processor Operation Modes */
-#define USER_MODE         0x10
-#define FIQ_MODE          0x11
-#define	IRQ_MODE          0x12
-#define	SUPERVISOR_MODE   0x13
-#define	ABORT_MODE        0x17
-#define	UNDEFINED_MODE    0x1b
-#define	SYSTEM_MODE       0x1f
+#define USER_MODE        0x10
+#define FIQ_MODE         0x11
+#define IRQ_MODE         0x12
+#define SUPERVISOR_MODE  0x13
+#define ABORT_MODE       0x17
+#define UNDEFINED_MODE   0x1b
+#define SYSTEM_MODE      0x1f
 
 /* [CS]PRS manipulation macros */
-#define GEN_STATUS_READ(nm,reg) \
-static inline uint32_t nm## _status_reg_read(void) \
-{ \
-	uint32_t retval; \
-	asm volatile( \
-		"mrs %[retval], " #reg \
-		: [retval] "=r" (retval) \
-	); \
-	return retval; \
-}
+#define GEN_STATUS_READ(nm, reg) \
+	static inline uint32_t nm## _status_reg_read(void) \
+	{ \
+		uint32_t retval; \
+		\
+		asm volatile ( \
+			"mrs %[retval], " #reg \
+			: [retval] "=r" (retval) \
+		); \
+		\
+		return retval; \
+	}
 
-#define GEN_STATUS_WRITE(nm,reg,fieldname, field) \
-static inline void nm## _status_reg_ ##fieldname## _write(uint32_t value) \
-{ \
-	asm volatile( \
-		"msr " #reg "_" #field ", %[value]" \
-		:: [value] "r" (value) \
-	); \
-}
+#define GEN_STATUS_WRITE(nm, reg, fieldname, field) \
+	static inline void nm## _status_reg_ ##fieldname## _write(uint32_t value) \
+	{ \
+		asm volatile ( \
+			"msr " #reg "_" #field ", %[value]" \
+			:: [value] "r" (value) \
+		); \
+	}
 
+/** Return the value of CPSR (Current Program Status Register). */
+GEN_STATUS_READ(current, cpsr);
 
-/** Returns the value of CPSR (Current Program Status Register). */
-GEN_STATUS_READ(current, cpsr)
-
-
-/** Sets control bits of CPSR. */
+/** Set control bits of CPSR. */
 GEN_STATUS_WRITE(current, cpsr, control, c);
 
-
-/** Returns the value of SPSR (Saved Program Status Register). */
-GEN_STATUS_READ(saved, spsr)
-
+/** Return the value of SPSR (Saved Program Status Register). */
+GEN_STATUS_READ(saved, spsr);
 
 #endif
Index: kernel/arch/arm32/src/arm32.c
===================================================================
--- kernel/arch/arm32/src/arm32.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/arm32/src/arm32.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -37,5 +37,5 @@
 #include <config.h>
 #include <genarch/fb/fb.h>
-#include <genarch/fb/visuals.h>
+#include <abi/fb/visuals.h>
 #include <sysinfo/sysinfo.h>
 #include <console/console.h>
Index: kernel/arch/arm32/src/mach/gta02/gta02.c
===================================================================
--- kernel/arch/arm32/src/mach/gta02/gta02.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/arm32/src/mach/gta02/gta02.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -39,5 +39,5 @@
 #include <mm/page.h>
 #include <genarch/fb/fb.h>
-#include <genarch/fb/visuals.h>
+#include <abi/fb/visuals.h>
 #include <genarch/drivers/s3c24xx_uart/s3c24xx_uart.h>
 #include <genarch/drivers/s3c24xx_irqc/s3c24xx_irqc.h>
Index: kernel/arch/arm32/src/mach/integratorcp/integratorcp.c
===================================================================
--- kernel/arch/arm32/src/mach/integratorcp/integratorcp.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/arm32/src/mach/integratorcp/integratorcp.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -48,5 +48,5 @@
 #include <arch/mach/integratorcp/integratorcp.h>
 #include <genarch/fb/fb.h>
-#include <genarch/fb/visuals.h>
+#include <abi/fb/visuals.h>
 #include <ddi/ddi.h>
 #include <print.h>
Index: kernel/arch/arm32/src/mach/testarm/testarm.c
===================================================================
--- kernel/arch/arm32/src/mach/testarm/testarm.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/arm32/src/mach/testarm/testarm.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -38,5 +38,5 @@
 #include <mm/page.h>
 #include <genarch/fb/fb.h>
-#include <genarch/fb/visuals.h>
+#include <abi/fb/visuals.h>
 #include <genarch/drivers/dsrln/dsrlnin.h>
 #include <genarch/drivers/dsrln/dsrlnout.h>
Index: kernel/arch/ia32/Makefile.inc
===================================================================
--- kernel/arch/ia32/Makefile.inc	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia32/Makefile.inc	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -43,4 +43,8 @@
 ## Accepted CPUs
 #
+
+ifeq ($(PROCESSOR),i486)
+	CMN2 = -march=i486
+endif
 
 ifeq ($(PROCESSOR),athlon_xp)
Index: kernel/arch/ia32/include/asm.h
===================================================================
--- kernel/arch/ia32/include/asm.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia32/include/asm.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -101,4 +101,6 @@
 GEN_WRITE_REG(dr7)
 
+#define IO_SPACE_BOUNDARY	((void *) (64 * 1024))
+
 /** Byte to port
  *
@@ -111,9 +113,11 @@
 NO_TRACE static inline void pio_write_8(ioport8_t *port, uint8_t val)
 {
-	asm volatile (
-		"outb %b[val], %w[port]\n"
-		:: [val] "a" (val),
-		   [port] "d" (port)
-	);
+	if (port < (ioport8_t *) IO_SPACE_BOUNDARY) {
+		asm volatile (
+			"outb %b[val], %w[port]\n"
+			:: [val] "a" (val), [port] "d" (port)
+		);	
+	} else
+		*port = val;
 }
 
@@ -128,9 +132,11 @@
 NO_TRACE static inline void pio_write_16(ioport16_t *port, uint16_t val)
 {
-	asm volatile (
-		"outw %w[val], %w[port]\n"
-		:: [val] "a" (val),
-		   [port] "d" (port)
-	);
+	if (port < (ioport16_t *) IO_SPACE_BOUNDARY) {
+		asm volatile (
+			"outw %w[val], %w[port]\n"
+			:: [val] "a" (val), [port] "d" (port)
+		);
+	} else
+		*port = val;
 }
 
@@ -145,9 +151,11 @@
 NO_TRACE static inline void pio_write_32(ioport32_t *port, uint32_t val)
 {
-	asm volatile (
-		"outl %[val], %w[port]\n"
-		:: [val] "a" (val),
-		   [port] "d" (port)
-	);
+	if (port < (ioport32_t *) IO_SPACE_BOUNDARY) {
+		asm volatile (
+			"outl %[val], %w[port]\n"
+			:: [val] "a" (val), [port] "d" (port)
+		);
+	} else
+		*port = val;
 }
 
@@ -162,13 +170,16 @@
 NO_TRACE static inline uint8_t pio_read_8(ioport8_t *port)
 {
-	uint8_t val;
-	
-	asm volatile (
-		"inb %w[port], %b[val]\n"
-		: [val] "=a" (val)
-		: [port] "d" (port)
-	);
-	
-	return val;
+	if (((void *)port) < IO_SPACE_BOUNDARY) {
+		uint8_t val;
+		
+		asm volatile (
+			"inb %w[port], %b[val]\n"
+			: [val] "=a" (val)
+			: [port] "d" (port)
+		);
+		
+		return val;
+	} else
+		return (uint8_t) *port;
 }
 
@@ -183,13 +194,16 @@
 NO_TRACE static inline uint16_t pio_read_16(ioport16_t *port)
 {
-	uint16_t val;
-	
-	asm volatile (
-		"inw %w[port], %w[val]\n"
-		: [val] "=a" (val)
-		: [port] "d" (port)
-	);
-	
-	return val;
+	if (((void *)port) < IO_SPACE_BOUNDARY) {
+		uint16_t val;
+		
+		asm volatile (
+			"inw %w[port], %w[val]\n"
+			: [val] "=a" (val)
+			: [port] "d" (port)
+		);
+		
+		return val;
+	} else
+		return (uint16_t) *port;
 }
 
@@ -204,13 +218,16 @@
 NO_TRACE static inline uint32_t pio_read_32(ioport32_t *port)
 {
-	uint32_t val;
-	
-	asm volatile (
-		"inl %w[port], %[val]\n"
-		: [val] "=a" (val)
-		: [port] "d" (port)
-	);
-	
-	return val;
+	if (((void *)port) < IO_SPACE_BOUNDARY) {
+		uint32_t val;
+		
+		asm volatile (
+			"inl %w[port], %[val]\n"
+			: [val] "=a" (val)
+			: [port] "d" (port)
+		);
+		
+		return val;
+	} else
+		return (uint32_t) *port;
 }
 
@@ -311,4 +328,6 @@
 }
 
+#ifndef PROCESSOR_i486
+
 /** Write to MSR */
 NO_TRACE static inline void write_msr(uint32_t msr, uint64_t value)
@@ -335,4 +354,6 @@
 	return ((uint64_t) dx << 32) | ax;
 }
+
+#endif /* PROCESSOR_i486 */
 
 
Index: kernel/arch/ia32/include/atomic.h
===================================================================
--- kernel/arch/ia32/include/atomic.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia32/include/atomic.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -121,5 +121,7 @@
 	asm volatile (
 		"0:\n"
+#ifndef PROCESSOR_i486
 		"pause\n"        /* Pentium 4's HT love this instruction */
+#endif
 		"mov %[count], %[tmp]\n"
 		"testl %[tmp], %[tmp]\n"
Index: kernel/arch/ia32/include/boot/boot.h
===================================================================
--- kernel/arch/ia32/include/boot/boot.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia32/include/boot/boot.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -43,4 +43,6 @@
 #define MULTIBOOT_HEADER_FLAGS  0x00010003
 
+#define MULTIBOOT_LOADER_MAGIC  0x2BADB002
+
 #ifndef __ASM__
 
Index: kernel/arch/ia32/include/context.h
===================================================================
--- kernel/arch/ia32/include/context.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia32/include/context.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,6 +36,4 @@
 #define KERN_ia32_CONTEXT_H_
 
-#ifdef KERNEL
-
 #include <typedefs.h>
 
@@ -57,6 +55,4 @@
 	} while (0)
 
-#endif /* KERNEL */
-
 /*
  * Only save registers that must be preserved across
Index: kernel/arch/ia32/include/cycle.h
===================================================================
--- kernel/arch/ia32/include/cycle.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia32/include/cycle.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -40,4 +40,7 @@
 NO_TRACE static inline uint64_t get_cycle(void)
 {
+#ifdef PROCESSOR_i486
+	return 0;
+#else
 	uint64_t v;
 	
@@ -48,4 +51,5 @@
 	
 	return v;
+#endif
 }
 
Index: kernel/arch/ia32/include/elf.h
===================================================================
--- kernel/arch/ia32/include/elf.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia32/include/elf.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup ia32	
+/** @addtogroup ia32
  * @{
  */
@@ -36,7 +36,7 @@
 #define KERN_ia32_ELF_H_
 
-#define	ELF_MACHINE		EM_386
-#define ELF_DATA_ENCODING	ELFDATA2LSB
-#define ELF_CLASS		ELFCLASS32
+#define ELF_MACHINE        EM_386
+#define ELF_DATA_ENCODING  ELFDATA2LSB
+#define ELF_CLASS          ELFCLASS32
 
 #endif
Index: kernel/arch/ia32/include/istate.h
===================================================================
--- kernel/arch/ia32/include/istate.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia32/include/istate.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,16 +36,5 @@
 #define KERN_ia32_ISTATE_H_
 
-#ifdef KERNEL
-
-#include <typedefs.h>
 #include <trace.h>
-
-#else /* KERNEL */
-
-#include <sys/types.h>
-
-#define NO_TRACE
-
-#endif /* KERNEL */
 
 typedef struct istate {
Index: kernel/arch/ia32/include/mm/frame.h
===================================================================
--- kernel/arch/ia32/include/mm/frame.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia32/include/mm/frame.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -39,5 +39,4 @@
 #define FRAME_SIZE   (1 << FRAME_WIDTH)
 
-#ifdef KERNEL
 #ifndef __ASM__
 
@@ -50,5 +49,4 @@
 
 #endif /* __ASM__ */
-#endif /* KERNEL */
 
 #endif
Index: kernel/arch/ia32/include/mm/page.h
===================================================================
--- kernel/arch/ia32/include/mm/page.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia32/include/mm/page.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -42,6 +42,4 @@
 #define PAGE_SIZE   FRAME_SIZE
 
-#ifdef KERNEL
-
 #ifndef __ASM__
 
@@ -201,6 +199,4 @@
 #endif /* __ASM__ */
 
-#endif /* KERNEL */
-
 #endif
 
Index: kernel/arch/ia32/src/asm.S
===================================================================
--- kernel/arch/ia32/src/asm.S	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia32/src/asm.S	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -405,5 +405,11 @@
 	xorl %eax, %eax
 	cmpl $(GDT_SELECTOR(KTEXT_DES)), ISTATE_OFFSET_CS(%esp)
+#ifdef PROCESSOR_i486
+	jz 0f
+		movl %eax, %ebp
+	0:
+#else
 	cmovnzl %eax, %ebp
+#endif
 
 	movl %ebp, ISTATE_OFFSET_EBP_FRAME(%esp)
Index: kernel/arch/ia32/src/boot/boot.S
===================================================================
--- kernel/arch/ia32/src/boot/boot.S	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia32/src/boot/boot.S	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -97,4 +97,10 @@
 	pm_status $status_prot
 	
+#include "vesa_prot.inc"
+	
+#ifndef PROCESSOR_i486
+	
+	pm_status $status_prot2
+	
 	movl $(INTEL_CPUID_LEVEL), %eax
 	cpuid
@@ -105,16 +111,20 @@
 	cpuid
 	bt $(INTEL_PSE), %edx
-	jc pse_supported
+	jnc pse_unsupported
+		
+		/* Map kernel and turn paging on */
+		pm_status $status_pse
+		call map_kernel_pse
+		jmp stack_init
+	
+#endif /* PROCESSOR_i486 */
 	
 	pse_unsupported:
 		
-		pm_error $err_pse
-	
-	pse_supported:
-	
-#include "vesa_prot.inc"
-	
-	/* Map kernel and turn paging on */
-	call map_kernel
+		/* Map kernel and turn paging on */
+		pm_status $status_non_pse
+		call map_kernel
+	
+	stack_init:
 	
 	/* Create the first stack frame */
@@ -122,5 +132,5 @@
 	movl %esp, %ebp
 	
-	pm2_status $status_prot2
+	pm2_status $status_prot3
 	
 	/* Call arch_pre_main(grub_eax, grub_ebx) */
@@ -140,5 +150,5 @@
 		jmp hlt0
 
-/** Setup mapping for the kernel.
+/** Setup mapping for the kernel (PSE variant)
  *
  * Setup mapping for both the unmapped and mapped sections
@@ -146,6 +156,7 @@
  *
  */
-.global map_kernel
-map_kernel:
+.global map_kernel_pse
+map_kernel_pse:
+	/* Paging features */
 	movl %cr4, %ecx
 	orl $(1 << 4), %ecx      /* PSE on */
@@ -158,5 +169,5 @@
 	xorl %ebx, %ebx
 	
-	floop:
+	floop_pse:
 		movl $((1 << 7) | (1 << 1) | (1 << 0)), %eax
 		orl %ebx, %eax
@@ -169,5 +180,5 @@
 		incl %ecx
 		cmpl $512, %ecx
-		jl floop
+		jl floop_pse
 	
 	movl %esi, %cr3
@@ -177,4 +188,179 @@
 	movl %ebx, %cr0
 	ret
+
+/** Setup mapping for the kernel (non-PSE variant).
+ *
+ * Setup mapping for both the unmapped and mapped sections
+ * of the kernel. For simplicity, we map the entire 4G space.
+ *
+ */
+.global map_kernel
+map_kernel:
+	/* Paging features */
+	movl %cr4, %ecx
+	andl $(~(1 << 5)), %ecx  /* PAE off */
+	movl %ecx, %cr4
+	
+	call calc_kernel_end
+	call find_mem_for_pt
+	
+	mov kernel_end, %esi
+	mov free_area, %ecx
+	
+	cmpl %esi, %ecx
+	jbe use_kernel_end
+		
+		mov %ecx, %esi
+		
+		/* Align address down to 4k */
+		andl $(~4095), %esi
+		
+	use_kernel_end:
+		
+		/* Align address to 4k */
+		addl $4095, %esi
+		andl $(~4095), %esi
+		
+		/* Allocate space for page tables */
+		movl %esi, pt_loc
+		movl $ballocs, %edi
+		andl $0x7fffffff, %edi
+		
+		movl %esi, (%edi)
+		addl $4, %edi
+		movl $(2 * 1024 * 1024), (%edi)
+		
+		/* Fill page tables */
+		xorl %ecx, %ecx
+		xorl %ebx, %ebx
+		
+		floop_pt:
+			movl $((1 << 1) | (1 << 0)), %eax
+			orl %ebx, %eax
+			movl %eax, (%esi, %ecx, 4)
+			addl $(4 * 1024), %ebx
+			
+			incl %ecx
+			cmpl $(512 * 1024), %ecx
+			
+			jl floop_pt
+		
+		/* Fill page directory */
+		movl $(page_directory + 0), %esi
+		movl $(page_directory + 2048), %edi
+		xorl %ecx, %ecx
+		movl pt_loc, %ebx
+		
+		floop:
+			movl $((1 << 1) | (1 << 0)), %eax
+			orl %ebx, %eax
+			
+			/* Mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */
+			movl %eax, (%esi, %ecx, 4)
+			
+			/* Mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */
+			movl %eax, (%edi, %ecx, 4)
+			addl $(4 * 1024), %ebx
+			
+			incl %ecx
+			cmpl $512, %ecx
+			
+			jl floop
+		
+		movl %esi, %cr3
+		
+		movl %cr0, %ebx
+		orl $(1 << 31), %ebx  /* paging on */
+		movl %ebx, %cr0
+		
+		ret
+
+/** Calculate unmapped address of the end of the kernel. */
+calc_kernel_end:
+	movl $hardcoded_load_address, %edi
+	andl $0x7fffffff, %edi
+	movl (%edi), %esi
+	andl $0x7fffffff, %esi
+	
+	movl $hardcoded_ktext_size, %edi
+	andl $0x7fffffff, %edi
+	addl (%edi), %esi
+	andl $0x7fffffff, %esi
+	
+	movl $hardcoded_kdata_size, %edi
+	andl $0x7fffffff, %edi
+	addl (%edi), %esi
+	andl $0x7fffffff, %esi
+	movl %esi, kernel_end
+	
+	ret
+
+/** Find free 2M (+4k for alignment) region where to store page tables */
+find_mem_for_pt:
+	/* Check if multiboot info is present */
+	cmpl $MULTIBOOT_LOADER_MAGIC, grub_eax
+	je check_multiboot_map
+		
+		ret
+	
+	check_multiboot_map:
+		
+		/* Copy address of the multiboot info to ebx */
+		movl grub_ebx, %ebx
+		
+		/* Check if memory map flag is present */
+		movl (%ebx), %edx
+		andl $(1 << 6), %edx
+		jnz use_multiboot_map
+			
+			ret
+		
+	use_multiboot_map:
+		
+		/* Copy address of the memory map to edx */
+		movl 48(%ebx), %edx
+		movl %edx, %ecx
+		
+		addl 44(%ebx), %ecx
+		
+		/* Find a free region at least 2M in size */
+		check_memmap_loop:
+			
+			/* Is this a free region? */
+			cmp $1, 20(%edx)
+			jnz next_region
+			
+			/* Check size */
+			cmp $0, 16(%edx)
+			jnz next_region
+			
+			cmpl $(2 * 1024 * 1024 + 4 * 1024), 12(%edx)
+			jbe next_region
+			
+			cmp $0, 8(%edx)
+			jz found_region
+		
+		next_region:
+			
+			cmp %ecx, %edx
+			jbe next_region_do
+			
+				ret
+		
+		next_region_do:
+			
+			addl (%edx), %edx
+			addl $4, %edx
+			jmp check_memmap_loop
+			
+		found_region:
+			
+			/* Use end of the found region */
+			mov 4(%edx), %ecx
+			add 12(%edx), %ecx
+			sub $(2 * 1024 * 1024), %ecx
+			mov %ecx, free_area
+			
+			ret
 
 /** Print string to EGA display (in light red) and halt.
@@ -521,13 +707,20 @@
 grub_eax:
 	.long 0
-
 grub_ebx:
 	.long 0
 
-err_pse:
-	.asciz "Page Size Extension not supported. System halted."
+pt_loc:
+	.long 0
+kernel_end:
+	.long 0
+free_area:
+	.long 0
 
 status_prot:
 	.asciz "[prot] "
+status_pse:
+	.asciz "[pse] "
+status_non_pse:
+	.asciz "[non_pse] "
 status_vesa_copy:
 	.asciz "[vesa_copy] "
@@ -538,4 +731,6 @@
 status_prot2:
 	.asciz "[prot2] "
+status_prot3:
+	.asciz "[prot3] "
 status_main:
 	.asciz "[main] "
Index: kernel/arch/ia32/src/cpu/cpu.c
===================================================================
--- kernel/arch/ia32/src/cpu/cpu.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia32/src/cpu/cpu.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -118,9 +118,11 @@
 		);
 	}
-	
+
+#ifndef PROCESSOR_i486
 	if (CPU->arch.fi.bits.sep) {
 		/* Setup fast SYSENTER/SYSEXIT syscalls */
 		syscall_setup_cpu();
 	}
+#endif
 }
 
Index: kernel/arch/ia32/src/drivers/vesa.c
===================================================================
--- kernel/arch/ia32/src/drivers/vesa.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia32/src/drivers/vesa.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -38,5 +38,4 @@
 
 #include <genarch/fb/fb.h>
-#include <genarch/fb/visuals.h>
 #include <arch/drivers/vesa.h>
 #include <console/chardev.h>
Index: kernel/arch/ia32/src/proc/scheduler.c
===================================================================
--- kernel/arch/ia32/src/proc/scheduler.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia32/src/proc/scheduler.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -60,8 +60,10 @@
 	uintptr_t kstk = (uintptr_t) &THREAD->kstack[STACK_SIZE];
 	
+#ifndef PROCESSOR_i486
 	if (CPU->arch.fi.bits.sep) {
 		/* Set kernel stack for CP3 -> CPL0 switch via SYSENTER */
 		write_msr(IA32_MSR_SYSENTER_ESP, kstk - sizeof(istate_t));
 	}
+#endif
 	
 	/* Set kernel stack for CPL3 -> CPL0 switch via interrupt */
Index: kernel/arch/ia32/src/smp/smp.c
===================================================================
--- kernel/arch/ia32/src/smp/smp.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia32/src/smp/smp.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -42,5 +42,4 @@
 #include <config.h>
 #include <synch/waitq.h>
-#include <synch/synch.h>
 #include <arch/pm.h>
 #include <func.h>
Index: kernel/arch/ia32/src/syscall.c
===================================================================
--- kernel/arch/ia32/src/syscall.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia32/src/syscall.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -39,4 +39,6 @@
 #include <arch/pm.h>
 
+#ifndef PROCESSOR_i486
+
 /** Enable & setup support for SYSENTER/SYSEXIT */
 void syscall_setup_cpu(void)
@@ -50,4 +52,6 @@
 }
 
+#endif /* PROCESSOR_i486 */
+
 /** @}
  */
Index: kernel/arch/ia32/src/userspace.c
===================================================================
--- kernel/arch/ia32/src/userspace.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia32/src/userspace.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -37,7 +37,6 @@
 #include <typedefs.h>
 #include <arch.h>
-#include <proc/uarg.h>
+#include <abi/proc/uarg.h>
 #include <mm/as.h>
-
 
 /** Enter userspace
Index: kernel/arch/ia64/include/elf.h
===================================================================
--- kernel/arch/ia64/include/elf.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia64/include/elf.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup ia64	
+/** @addtogroup ia64
  * @{
  */
@@ -36,7 +36,7 @@
 #define KERN_ia64_ELF_H_
 
-#define	ELF_MACHINE		EM_IA_64
-#define ELF_DATA_ENCODING	ELFDATA2LSB
-#define ELF_CLASS		ELFCLASS64
+#define ELF_MACHINE        EM_IA_64
+#define ELF_DATA_ENCODING  ELFDATA2LSB
+#define ELF_CLASS          ELFCLASS64
 
 #endif
Index: kernel/arch/ia64/include/istate.h
===================================================================
--- kernel/arch/ia64/include/istate.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia64/include/istate.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,13 +36,15 @@
 #define KERN_ia64_ISTATE_H_
 
+#include <trace.h>
+
+#ifdef KERNEL
+
 #include <arch/register.h>
 
-#ifdef KERNEL
-#include <typedefs.h>
-#include <trace.h>
-#else
-#include <sys/types.h>
-#define NO_TRACE
-#endif
+#else /* KERNEL */
+
+#include <libarch/register.h>
+
+#endif /* KERNEL */
 
 typedef struct istate {
Index: kernel/arch/ia64/include/mm/frame.h
===================================================================
--- kernel/arch/ia64/include/mm/frame.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia64/include/mm/frame.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -39,5 +39,4 @@
 #define FRAME_SIZE   (1 << FRAME_WIDTH)
 
-#ifdef KERNEL
 #ifndef __ASM__
 
@@ -50,5 +49,4 @@
 
 #endif /* __ASM__ */
-#endif /* KERNEL */
 
 #endif
Index: kernel/arch/ia64/include/mm/page.h
===================================================================
--- kernel/arch/ia64/include/mm/page.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia64/include/mm/page.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -41,6 +41,4 @@
 #define PAGE_SIZE   FRAME_SIZE
 #define PAGE_WIDTH  FRAME_WIDTH
-
-#ifdef KERNEL
 
 /** Bit width of the TLB-locked portion of kernel address space. */
@@ -316,6 +314,4 @@
 #endif /* __ASM__ */
 
-#endif /* KERNEL */
-
 #endif
 
Index: kernel/arch/ia64/include/register.h
===================================================================
--- kernel/arch/ia64/include/register.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia64/include/register.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -61,6 +61,6 @@
 #define PSR_CPL_MASK_SHIFTED  3
 
-#define PSR_RI_SHIFT	41
-#define PSR_RI_LEN	2
+#define PSR_RI_SHIFT  41
+#define PSR_RI_LEN    2
 
 #define PFM_MASK  (~0x3fffffffff)
@@ -145,10 +145,4 @@
 #ifndef __ASM__
 
-#ifdef KERNEL
-#include <typedefs.h>
-#else
-#include <sys/types.h>
-#endif
-
 /** Processor Status Register. */
 typedef union {
Index: kernel/arch/ia64/src/ia64.c
===================================================================
--- kernel/arch/ia64/src/ia64.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ia64/src/ia64.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -50,5 +50,5 @@
 #include <userspace.h>
 #include <console/console.h>
-#include <proc/uarg.h>
+#include <abi/proc/uarg.h>
 #include <syscall/syscall.h>
 #include <ddi/irq.h>
Index: kernel/arch/mips32/include/context_offset.h
===================================================================
--- kernel/arch/mips32/include/context_offset.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/mips32/include/context_offset.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -63,119 +63,126 @@
 #ifdef __ASM__
 
+#ifdef KERNEL
+
 #include <arch/asm/regname.h>
 
-# ctx: address of the structure with saved context
+#else /* KERNEL */
+
+#include <libarch/regname.h>
+
+#endif /* KERNEL */
+
+/* ctx: address of the structure with saved context */
 .macro CONTEXT_SAVE_ARCH_CORE ctx:req
-	sw $s0,OFFSET_S0(\ctx)
-	sw $s1,OFFSET_S1(\ctx)
-	sw $s2,OFFSET_S2(\ctx)
-	sw $s3,OFFSET_S3(\ctx)
-	sw $s4,OFFSET_S4(\ctx)
-	sw $s5,OFFSET_S5(\ctx)
-	sw $s6,OFFSET_S6(\ctx)
-	sw $s7,OFFSET_S7(\ctx)
-	sw $s8,OFFSET_S8(\ctx)
-	sw $gp,OFFSET_GP(\ctx)
-
+	sw $s0, OFFSET_S0(\ctx)
+	sw $s1, OFFSET_S1(\ctx)
+	sw $s2, OFFSET_S2(\ctx)
+	sw $s3, OFFSET_S3(\ctx)
+	sw $s4, OFFSET_S4(\ctx)
+	sw $s5, OFFSET_S5(\ctx)
+	sw $s6, OFFSET_S6(\ctx)
+	sw $s7, OFFSET_S7(\ctx)
+	sw $s8, OFFSET_S8(\ctx)
+	sw $gp, OFFSET_GP(\ctx)
+	
 #ifndef KERNEL
-	sw $k1,OFFSET_TLS(\ctx)
-
+	sw $k1, OFFSET_TLS(\ctx)
+	
 #ifdef CONFIG_FPU
-	mfc1 $t0,$20
+	mfc1 $t0, $20
 	sw $t0, OFFSET_F20(\ctx)
-
-	mfc1 $t0,$21
+	
+	mfc1 $t0, $21
 	sw $t0, OFFSET_F21(\ctx)
-
-	mfc1 $t0,$22
+	
+	mfc1 $t0, $22
 	sw $t0, OFFSET_F22(\ctx)
-
-	mfc1 $t0,$23
+	
+	mfc1 $t0, $23
 	sw $t0, OFFSET_F23(\ctx)
-
-	mfc1 $t0,$24
+	
+	mfc1 $t0, $24
 	sw $t0, OFFSET_F24(\ctx)
-
-	mfc1 $t0,$25
+	
+	mfc1 $t0, $25
 	sw $t0, OFFSET_F25(\ctx)
-
-	mfc1 $t0,$26
+	
+	mfc1 $t0, $26
 	sw $t0, OFFSET_F26(\ctx)
-
-	mfc1 $t0,$27
+	
+	mfc1 $t0, $27
 	sw $t0, OFFSET_F27(\ctx)
-
-	mfc1 $t0,$28
+	
+	mfc1 $t0, $28
 	sw $t0, OFFSET_F28(\ctx)
-
-	mfc1 $t0,$29
+	
+	mfc1 $t0, $29
 	sw $t0, OFFSET_F29(\ctx)
 	
-	mfc1 $t0,$30
+	mfc1 $t0, $30
 	sw $t0, OFFSET_F30(\ctx)
 #endif /* CONFIG_FPU */
 #endif /* KERNEL */
-
-	sw $ra,OFFSET_PC(\ctx)
-	sw $sp,OFFSET_SP(\ctx)
+	
+	sw $ra, OFFSET_PC(\ctx)
+	sw $sp, OFFSET_SP(\ctx)
 .endm
 
-# ctx: address of the structure with saved context
+/* ctx: address of the structure with saved context */
 .macro CONTEXT_RESTORE_ARCH_CORE ctx:req
-	lw $s0,OFFSET_S0(\ctx)
-	lw $s1,OFFSET_S1(\ctx)
-	lw $s2,OFFSET_S2(\ctx)
-	lw $s3,OFFSET_S3(\ctx)
-	lw $s4,OFFSET_S4(\ctx)
-	lw $s5,OFFSET_S5(\ctx)
-	lw $s6,OFFSET_S6(\ctx)
-	lw $s7,OFFSET_S7(\ctx)
-	lw $s8,OFFSET_S8(\ctx)
-	lw $gp,OFFSET_GP(\ctx)
+	lw $s0, OFFSET_S0(\ctx)
+	lw $s1, OFFSET_S1(\ctx)
+	lw $s2, OFFSET_S2(\ctx)
+	lw $s3, OFFSET_S3(\ctx)
+	lw $s4, OFFSET_S4(\ctx)
+	lw $s5, OFFSET_S5(\ctx)
+	lw $s6, OFFSET_S6(\ctx)
+	lw $s7, OFFSET_S7(\ctx)
+	lw $s8, OFFSET_S8(\ctx)
+	lw $gp, OFFSET_GP(\ctx)
 #ifndef KERNEL
-	lw $k1,OFFSET_TLS(\ctx)
-
+	lw $k1, OFFSET_TLS(\ctx)
+	
 #ifdef CONFIG_FPU
 	lw $t0, OFFSET_F20(\ctx)
-	mtc1 $t0,$20
-
+	mtc1 $t0, $20
+	
 	lw $t0, OFFSET_F21(\ctx)
-	mtc1 $t0,$21
-
+	mtc1 $t0, $21
+	
 	lw $t0, OFFSET_F22(\ctx)
-	mtc1 $t0,$22
-
+	mtc1 $t0, $22
+	
 	lw $t0, OFFSET_F23(\ctx)
-	mtc1 $t0,$23
-
+	mtc1 $t0, $23
+	
 	lw $t0, OFFSET_F24(\ctx)
-	mtc1 $t0,$24
-
+	mtc1 $t0, $24
+	
 	lw $t0, OFFSET_F25(\ctx)
-	mtc1 $t0,$25
-
+	mtc1 $t0, $25
+	
 	lw $t0, OFFSET_F26(\ctx)
-	mtc1 $t0,$26
-
+	mtc1 $t0, $26
+	
 	lw $t0, OFFSET_F27(\ctx)
-	mtc1 $t0,$27
-
+	mtc1 $t0, $27
+	
 	lw $t0, OFFSET_F28(\ctx)
-	mtc1 $t0,$28
-
+	mtc1 $t0, $28
+	
 	lw $t0, OFFSET_F29(\ctx)
-	mtc1 $t0,$29
-
+	mtc1 $t0, $29
+	
 	lw $t0, OFFSET_F30(\ctx)
-	mtc1 $t0,$30
+	mtc1 $t0, $30
 #endif /* CONFIG_FPU */
 #endif /* KERNEL */
-
-	lw $ra,OFFSET_PC(\ctx)
-	lw $sp,OFFSET_SP(\ctx)
+	
+	lw $ra, OFFSET_PC(\ctx)
+	lw $sp, OFFSET_SP(\ctx)
 .endm
 
-#endif
-
+#endif /* __ASM__ */
 
 #endif
Index: kernel/arch/mips32/include/cp0.h
===================================================================
--- kernel/arch/mips32/include/cp0.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/mips32/include/cp0.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,10 +36,4 @@
 #define KERN_mips32_CP0_H_
 
-#ifdef KERNEL
-#include <typedefs.h>
-#else
-#include <sys/types.h>
-#endif
-
 #define cp0_status_ie_enabled_bit     (1 << 0)
 #define cp0_status_exl_exception_bit  (1 << 1)
@@ -49,33 +43,50 @@
 #define cp0_status_fpu_bit            (1 << 29)
 
-#define cp0_status_im_shift		8
-#define cp0_status_im_mask              0xff00
+#define cp0_status_im_shift  8
+#define cp0_status_im_mask   0xff00
 
-#define cp0_cause_excno(cause) ((cause >> 2) & 0x1f)
-#define cp0_cause_coperr(cause) ((cause >> 28) & 0x3)
+#define cp0_cause_excno(cause)   ((cause >> 2) & 0x1f)
+#define cp0_cause_coperr(cause)  ((cause >> 28) & 0x3)
 
-#define fpu_cop_id 1
+#define fpu_cop_id  1
 
 /*
  * Magic value for use in msim.
  */
-#define cp0_compare_value 		100000
+#define cp0_compare_value  100000
 
-#define cp0_mask_all_int() cp0_status_write(cp0_status_read() & ~(cp0_status_im_mask))
-#define cp0_unmask_all_int() cp0_status_write(cp0_status_read() | cp0_status_im_mask)
-#define cp0_mask_int(it) cp0_status_write(cp0_status_read() & ~(1 << (cp0_status_im_shift + (it))))
-#define cp0_unmask_int(it) cp0_status_write(cp0_status_read() | (1 << (cp0_status_im_shift + (it))))
+#define cp0_mask_all_int() \
+	cp0_status_write(cp0_status_read() & ~(cp0_status_im_mask))
 
-#define GEN_READ_CP0(nm,reg) static inline uint32_t cp0_ ##nm##_read(void) \
-  { \
-      uint32_t retval; \
-      asm volatile ("mfc0 %0, $" #reg : "=r"(retval)); \
-      return retval; \
-  }
+#define cp0_unmask_all_int() \
+	cp0_status_write(cp0_status_read() | cp0_status_im_mask)
 
-#define GEN_WRITE_CP0(nm,reg) static inline void cp0_ ##nm##_write(uint32_t val) \
- { \
-    asm volatile ("mtc0 %0, $" #reg : : "r"(val) ); \
- }
+#define cp0_mask_int(it) \
+	cp0_status_write(cp0_status_read() & ~(1 << (cp0_status_im_shift + (it))))
+
+#define cp0_unmask_int(it) \
+	cp0_status_write(cp0_status_read() | (1 << (cp0_status_im_shift + (it))))
+
+#define GEN_READ_CP0(nm, reg) \
+	static inline uint32_t cp0_ ##nm##_read(void) \
+	{ \
+		uint32_t retval; \
+		\
+		asm volatile ( \
+			"mfc0 %0, $" #reg \
+			: "=r"(retval) \
+		); \
+		\
+		return retval; \
+	}
+
+#define GEN_WRITE_CP0(nm, reg) \
+	static inline void cp0_ ##nm##_write(uint32_t val) \
+	{ \
+		asm volatile ( \
+			"mtc0 %0, $" #reg \
+			:: "r"(val) \
+		); \
+	}
 
 GEN_READ_CP0(index, 0);
Index: kernel/arch/mips32/include/istate.h
===================================================================
--- kernel/arch/mips32/include/istate.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/mips32/include/istate.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,13 +36,15 @@
 #define KERN_mips32_ISTATE_H_
 
+#include <trace.h>
+
+#ifdef KERNEL
+
 #include <arch/cp0.h>
 
-#ifdef KERNEL
-#include <typedefs.h>
-#include <trace.h>
-#else
-#include <sys/types.h>
-#define NO_TRACE
-#endif
+#else /* KERNEL */
+
+#include <libarch/cp0.h>
+
+#endif /* KERNEL */
 
 typedef struct istate {
Index: kernel/arch/mips32/include/mm/frame.h
===================================================================
--- kernel/arch/mips32/include/mm/frame.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/mips32/include/mm/frame.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -39,5 +39,4 @@
 #define FRAME_SIZE   (1 << FRAME_WIDTH)
 
-#ifdef KERNEL
 #ifndef __ASM__
 
@@ -46,5 +45,4 @@
 
 #endif /* __ASM__ */
-#endif /* KERNEL */
 
 #endif
Index: kernel/arch/mips32/include/mm/page.h
===================================================================
--- kernel/arch/mips32/include/mm/page.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/mips32/include/mm/page.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -49,6 +49,4 @@
 #	define PA2KA(x)	((x) + 0x80000000)
 #endif
-
-#ifdef KERNEL
 
 /*
@@ -188,6 +186,4 @@
 #endif /* __ASM__ */
 
-#endif /* KERNEL */
-
 #endif
 
Index: kernel/arch/mips32/src/mips32.c
===================================================================
--- kernel/arch/mips32/src/mips32.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/mips32/src/mips32.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -41,5 +41,5 @@
 #include <memstr.h>
 #include <proc/thread.h>
-#include <proc/uarg.h>
+#include <abi/proc/uarg.h>
 #include <print.h>
 #include <console/console.h>
@@ -52,5 +52,5 @@
 #include <arch/debugger.h>
 #include <genarch/fb/fb.h>
-#include <genarch/fb/visuals.h>
+#include <abi/fb/visuals.h>
 #include <genarch/drivers/dsrln/dsrlnin.h>
 #include <genarch/drivers/dsrln/dsrlnout.h>
Index: kernel/arch/mips64/include/context_offset.h
===================================================================
--- kernel/arch/mips64/include/context_offset.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/mips64/include/context_offset.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -63,7 +63,15 @@
 #ifdef __ASM__
 
+#ifdef KERNEL
+
 #include <arch/asm/regname.h>
 
-# ctx: address of the structure with saved context
+#else /* KERNEL */
+
+#include <libarch/regname.h>
+
+#endif /* KERNEL */
+
+/* ctx: address of the structure with saved context */
 .macro CONTEXT_SAVE_ARCH_CORE ctx:req
 	sd $s0, OFFSET_S0(\ctx)
@@ -121,5 +129,5 @@
 .endm
 
-# ctx: address of the structure with saved context
+/* ctx: address of the structure with saved context */
 .macro CONTEXT_RESTORE_ARCH_CORE ctx:req
 	ld $s0, OFFSET_S0(\ctx)
Index: kernel/arch/mips64/include/cp0.h
===================================================================
--- kernel/arch/mips64/include/cp0.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/mips64/include/cp0.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -35,14 +35,4 @@
 #ifndef KERN_mips64_CP0_H_
 #define KERN_mips64_CP0_H_
-
-#ifdef KERNEL
-
-#include <typedefs.h>
-
-#else
-
-#include <sys/types.h>
-
-#endif
 
 #define cp0_status_ie_enabled_bit     (1 << 0)
Index: kernel/arch/mips64/include/istate.h
===================================================================
--- kernel/arch/mips64/include/istate.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/mips64/include/istate.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,17 +36,15 @@
 #define KERN_mips64_ISTATE_H_
 
-#include <arch/cp0.h>
+#include <trace.h>
 
 #ifdef KERNEL
 
-#include <typedefs.h>
-#include <trace.h>
+#include <arch/cp0.h>
 
-#else
+#else /* KERNEL */
 
-#include <sys/types.h>
-#define NO_TRACE
+#include <libarch/cp0.h>
 
-#endif
+#endif /* KERNEL */
 
 typedef struct istate {
Index: kernel/arch/mips64/include/mm/frame.h
===================================================================
--- kernel/arch/mips64/include/mm/frame.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/mips64/include/mm/frame.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -39,5 +39,4 @@
 #define FRAME_SIZE   (1 << FRAME_WIDTH)
 
-#ifdef KERNEL
 #ifndef __ASM__
 
@@ -46,5 +45,4 @@
 
 #endif /* __ASM__ */
-#endif /* KERNEL */
 
 #endif
Index: kernel/arch/mips64/include/mm/page.h
===================================================================
--- kernel/arch/mips64/include/mm/page.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/mips64/include/mm/page.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -50,5 +50,4 @@
 #endif
 
-#ifdef KERNEL
 #ifndef __ASM__
 
@@ -56,5 +55,4 @@
 
 #endif /* __ASM__ */
-#endif /* KERNEL */
 
 #endif
Index: kernel/arch/mips64/src/mips64.c
===================================================================
--- kernel/arch/mips64/src/mips64.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/mips64/src/mips64.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -41,5 +41,5 @@
 #include <memstr.h>
 #include <proc/thread.h>
-#include <proc/uarg.h>
+#include <abi/proc/uarg.h>
 #include <print.h>
 #include <console/console.h>
@@ -52,5 +52,5 @@
 #include <arch/debugger.h>
 #include <genarch/fb/fb.h>
-#include <genarch/fb/visuals.h>
+#include <abi/fb/visuals.h>
 #include <genarch/drivers/dsrln/dsrlnin.h>
 #include <genarch/drivers/dsrln/dsrlnout.h>
Index: kernel/arch/ppc32/include/asm.h
===================================================================
--- kernel/arch/ppc32/include/asm.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ppc32/include/asm.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -38,5 +38,5 @@
 #include <typedefs.h>
 #include <config.h>
-#include <arch/cpu.h>
+#include <arch/msr.h>
 #include <arch/mm/asid.h>
 #include <trace.h>
Index: kernel/arch/ppc32/include/context_offset.h
===================================================================
--- kernel/arch/ppc32/include/context_offset.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ppc32/include/context_offset.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -75,7 +75,16 @@
 
 #ifdef __ASM__
-# include <arch/asm/regname.h>
 
-# ctx: address of the structure with saved context
+#ifdef KERNEL
+
+#include <arch/asm/regname.h>
+
+#else /* KERNEL */
+
+#include <libarch/regname.h>
+
+#endif /* KERNEL */
+
+/* ctx: address of the structure with saved context */
 .macro CONTEXT_SAVE_ARCH_CORE ctx:req
 	stw sp, OFFSET_SP(\ctx)
@@ -102,5 +111,5 @@
 .endm
 
-# ctx: address of the structure with saved context
+/* ctx: address of the structure with saved context */
 .macro CONTEXT_RESTORE_ARCH_CORE ctx:req
 	lwz sp, OFFSET_SP(\ctx)
Index: kernel/arch/ppc32/include/cpu.h
===================================================================
--- kernel/arch/ppc32/include/cpu.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ppc32/include/cpu.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,19 +36,4 @@
 #define KERN_ppc32_CPU_H_
 
-/* MSR bits */
-#define MSR_DR  (1 << 4)
-#define MSR_IR  (1 << 5)
-#define MSR_PR  (1 << 14)
-#define MSR_EE  (1 << 15)
-
-/* HID0 bits */
-#define HID0_STEN  (1 << 24)
-#define HID0_ICE   (1 << 15)
-#define HID0_DCE   (1 << 14)
-#define HID0_ICFI  (1 << 11)
-#define HID0_DCI   (1 << 10)
-
-#ifndef __ASM__
-
 #include <typedefs.h>
 #include <trace.h>
@@ -67,6 +52,4 @@
 }
 
-#endif /* __ASM__ */
-
 #endif
 
Index: kernel/arch/ppc32/include/exception.h
===================================================================
--- kernel/arch/ppc32/include/exception.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ppc32/include/exception.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -37,5 +37,5 @@
 
 #include <typedefs.h>
-#include <arch/cpu.h>
+#include <arch/msr.h>
 #include <trace.h>
 
Index: kernel/arch/ppc32/include/istate.h
===================================================================
--- kernel/arch/ppc32/include/istate.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ppc32/include/istate.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,7 +36,15 @@
 #define KERN_ppc32_EXCEPTION_H_
 
-#include <typedefs.h>
-#include <arch/cpu.h>
 #include <trace.h>
+
+#ifdef KERNEL
+
+#include <arch/msr.h>
+
+#else /* KERNEL */
+
+#include <libarch/msr.h>
+
+#endif /* KERNEL */
 
 typedef struct istate {
Index: kernel/arch/ppc32/include/mm/frame.h
===================================================================
--- kernel/arch/ppc32/include/mm/frame.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ppc32/include/mm/frame.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -39,5 +39,4 @@
 #define FRAME_SIZE   (1 << FRAME_WIDTH)
 
-#ifdef KERNEL
 #ifndef __ASM__
 
@@ -63,5 +62,4 @@
 
 #endif /* __ASM__ */
-#endif /* KERNEL */
 
 #endif
Index: kernel/arch/ppc32/include/mm/page.h
===================================================================
--- kernel/arch/ppc32/include/mm/page.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ppc32/include/mm/page.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -41,6 +41,4 @@
 #define PAGE_WIDTH  FRAME_WIDTH
 #define PAGE_SIZE   FRAME_SIZE
-
-#ifdef KERNEL
 
 #ifndef __ASM__
@@ -181,6 +179,4 @@
 #endif /* __ASM__ */
 
-#endif /* KERNEL */
-
 #endif
 
Index: kernel/arch/ppc32/include/msr.h
===================================================================
--- kernel/arch/ppc32/include/msr.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
+++ kernel/arch/ppc32/include/msr.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_ppc32_MSR_H_
+#define KERN_ppc32_MSR_H_
+
+/* MSR bits */
+#define MSR_DR  (1 << 4)
+#define MSR_IR  (1 << 5)
+#define MSR_PR  (1 << 14)
+#define MSR_EE  (1 << 15)
+
+/* HID0 bits */
+#define HID0_STEN  (1 << 24)
+#define HID0_ICE   (1 << 15)
+#define HID0_DCE   (1 << 14)
+#define HID0_ICFI  (1 << 11)
+#define HID0_DCI   (1 << 10)
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ppc32/src/asm.S
===================================================================
--- kernel/arch/ppc32/src/asm.S	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ppc32/src/asm.S	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -28,5 +28,5 @@
 
 #include <arch/asm/regname.h>
-#include <arch/cpu.h>
+#include <arch/msr.h>
 
 .text
Index: kernel/arch/ppc32/src/exception.S
===================================================================
--- kernel/arch/ppc32/src/exception.S	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ppc32/src/exception.S	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -28,5 +28,5 @@
 
 #include <arch/asm/regname.h>
-#include <arch/cpu.h>
+#include <arch/msr.h>
 #include <arch/mm/page.h>
 
Index: kernel/arch/ppc32/src/ppc32.c
===================================================================
--- kernel/arch/ppc32/src/ppc32.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/ppc32/src/ppc32.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -41,10 +41,10 @@
 #include <interrupt.h>
 #include <genarch/fb/fb.h>
-#include <genarch/fb/visuals.h>
+#include <abi/fb/visuals.h>
 #include <genarch/ofw/ofw_tree.h>
 #include <genarch/ofw/pci.h>
 #include <userspace.h>
 #include <mm/page.h>
-#include <proc/uarg.h>
+#include <abi/proc/uarg.h>
 #include <console/console.h>
 #include <sysinfo/sysinfo.h>
Index: kernel/arch/sparc64/include/barrier.h
===================================================================
--- kernel/arch/sparc64/include/barrier.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/sparc64/include/barrier.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -37,14 +37,4 @@
 
 #include <trace.h>
-
-#ifdef KERNEL
-
-#include <typedefs.h>
-
-#else
-
-#include <stdint.h>
-
-#endif
 
 /*
Index: kernel/arch/sparc64/include/elf.h
===================================================================
--- kernel/arch/sparc64/include/elf.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/sparc64/include/elf.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup sparc64	
+/** @addtogroup sparc64
  * @{
  */
@@ -36,7 +36,7 @@
 #define KERN_sparc64_ELF_H_
 
-#define	ELF_MACHINE		EM_SPARCV9
-#define ELF_DATA_ENCODING	ELFDATA2MSB
-#define ELF_CLASS		ELFCLASS64
+#define ELF_MACHINE        EM_SPARCV9
+#define ELF_DATA_ENCODING  ELFDATA2MSB
+#define ELF_CLASS          ELFCLASS64
 
 #endif
Index: kernel/arch/sparc64/include/istate.h
===================================================================
--- kernel/arch/sparc64/include/istate.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/sparc64/include/istate.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -37,13 +37,15 @@
 #define KERN_sparc64_ISTATE_H_
 
+#include <trace.h>
+
+#ifdef KERNEL
+
 #include <arch/regdef.h>
 
-#ifdef KERNEL
-#include <typedefs.h>
-#include <trace.h>
-#else
-#include <sys/types.h>
-#define NO_TRACE
-#endif
+#else /* KERNEL */
+
+#include <libarch/regdef.h>
+
+#endif /* KERNEL */
 
 typedef struct istate {
Index: kernel/arch/sparc64/include/mm/page.h
===================================================================
--- kernel/arch/sparc64/include/mm/page.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/sparc64/include/mm/page.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -54,6 +54,4 @@
 #define MMU_PAGES_PER_PAGE	(1 << (PAGE_WIDTH - MMU_PAGE_WIDTH))
 
-#ifdef KERNEL
-
 #ifndef __ASM__
 
@@ -77,6 +75,4 @@
 #endif /* !def __ASM__ */
 
-#endif /* KERNEL */
-
 #endif
 
Index: kernel/arch/sparc64/include/mm/sun4u/frame.h
===================================================================
--- kernel/arch/sparc64/include/mm/sun4u/frame.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/sparc64/include/mm/sun4u/frame.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -52,5 +52,4 @@
 #define FRAME_SIZE		(1 << FRAME_WIDTH)
 
-#ifdef KERNEL
 #ifndef __ASM__
 
@@ -80,5 +79,4 @@
 
 #endif
-#endif
 
 #endif
Index: kernel/arch/sparc64/include/mm/sun4v/frame.h
===================================================================
--- kernel/arch/sparc64/include/mm/sun4v/frame.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/sparc64/include/mm/sun4v/frame.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -42,5 +42,4 @@
 #define FRAME_SIZE		(1 << FRAME_WIDTH)
 
-#ifdef KERNEL
 #ifndef __ASM__
 
@@ -52,5 +51,4 @@
 
 #endif
-#endif
 
 #endif
Index: kernel/arch/sparc64/include/mm/sun4v/page.h
===================================================================
--- kernel/arch/sparc64/include/mm/sun4v/page.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/sparc64/include/mm/sun4v/page.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -46,6 +46,4 @@
 #define MMU_PAGES_PER_PAGE	(1 << (PAGE_WIDTH - MMU_PAGE_WIDTH))
 
-#ifdef KERNEL
-
 #ifndef __ASM__
 
@@ -69,6 +67,4 @@
 #endif /* !def __ASM__ */
 
-#endif /* KERNEL */
-
 #endif
 
Index: kernel/arch/sparc64/include/sun4v/regdef.h
===================================================================
--- kernel/arch/sparc64/include/sun4v/regdef.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/sparc64/include/sun4v/regdef.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -28,5 +28,5 @@
  */
 
-/** @addtogroup sparc64	
+/** @addtogroup sparc64
  * @{
  */
@@ -37,17 +37,8 @@
 #define KERN_sparc64_sun4v_REGDEF_H_
 
-#define PSTATE_IE_BIT	(1 << 1)
-#define PSTATE_PRIV_BIT	(1 << 2)
-#define PSTATE_PEF_BIT	(1 << 4)
+#define TSTATE_CWP_MASK  0x1f
 
-#define TSTATE_PSTATE_SHIFT	8
-#define TSTATE_PRIV_BIT		(PSTATE_PRIV_BIT << TSTATE_PSTATE_SHIFT)
-#define TSTATE_CWP_MASK		0x1f
-#define TSTATE_IE_BIT		(PSTATE_IE_BIT << TSTATE_PSTATE_SHIFT)
-
-#define WSTATE_NORMAL(n)	(n)
-#define WSTATE_OTHER(n)		((n) << 3)
-
-#define TSTATE_PEF_BIT		(PSTATE_PEF_BIT << TSTATE_PSTATE_SHIFT)
+#define WSTATE_NORMAL(n)  (n)
+#define WSTATE_OTHER(n)   ((n) << 3)
 
 #endif
Index: kernel/arch/sparc64/src/drivers/scr.c
===================================================================
--- kernel/arch/sparc64/src/drivers/scr.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/sparc64/src/drivers/scr.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -39,5 +39,5 @@
 #include <genarch/ofw/upa.h>
 #include <genarch/fb/fb.h>
-#include <genarch/fb/visuals.h>
+#include <abi/fb/visuals.h>
 #include <console/chardev.h>
 #include <console/console.h>
Index: kernel/arch/sparc64/src/smp/sun4u/smp.c
===================================================================
--- kernel/arch/sparc64/src/smp/sun4u/smp.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/sparc64/src/smp/sun4u/smp.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -42,5 +42,4 @@
 #include <macros.h>
 #include <typedefs.h>
-#include <synch/synch.h>
 #include <synch/waitq.h>
 #include <print.h>
Index: kernel/arch/sparc64/src/smp/sun4v/smp.c
===================================================================
--- kernel/arch/sparc64/src/smp/sun4v/smp.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/sparc64/src/smp/sun4v/smp.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -45,5 +45,4 @@
 #include <func.h>
 #include <typedefs.h>
-#include <synch/synch.h>
 #include <synch/waitq.h>
 #include <print.h>
Index: kernel/arch/sparc64/src/sun4v/start.S
===================================================================
--- kernel/arch/sparc64/src/sun4v/start.S	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/arch/sparc64/src/sun4v/start.S	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -30,4 +30,5 @@
 #include <arch/arch.h>
 #include <arch/stack.h>
+#include <arch/regdef.h>
 #include <arch/context_offset.h>
 #include <arch/sun4v/regdef.h>
Index: kernel/genarch/include/fb/fb.h
===================================================================
--- kernel/genarch/include/fb/fb.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/genarch/include/fb/fb.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -37,6 +37,6 @@
 
 #include <typedefs.h>
+#include <abi/fb/visuals.h>
 #include <console/chardev.h>
-#include <genarch/fb/visuals.h>
 
 /**
Index: kernel/genarch/include/fb/visuals.h
===================================================================
--- kernel/genarch/include/fb/visuals.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ 	(revision )
@@ -1,56 +1,0 @@
-/*
- * Copyright (c) 2006 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup genarch
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_VISUALS_H_
-#define KERN_VISUALS_H_
-
-typedef enum {
-	VISUAL_UNKNOWN = 0,
-	VISUAL_INDIRECT_8,
-	VISUAL_RGB_5_5_5_LE,
-	VISUAL_RGB_5_5_5_BE,
-	VISUAL_RGB_5_6_5_LE,
-	VISUAL_RGB_5_6_5_BE,
-	VISUAL_BGR_8_8_8,
-	VISUAL_BGR_0_8_8_8,
-	VISUAL_BGR_8_8_8_0,
-	VISUAL_RGB_8_8_8,
-	VISUAL_RGB_0_8_8_8,
-	VISUAL_RGB_8_8_8_0
-} visual_t;
-
-#endif
-
-/** @}
- */
Index: kernel/genarch/src/fb/fb.c
===================================================================
--- kernel/genarch/src/fb/fb.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/genarch/src/fb/fb.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,5 +36,4 @@
 #include <genarch/fb/font-8x16.h>
 #include <genarch/fb/logo-196x66.h>
-#include <genarch/fb/visuals.h>
 #include <genarch/fb/fb.h>
 #include <console/chardev.h>
Index: kernel/generic/include/console/console.h
===================================================================
--- kernel/generic/include/console/console.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/include/console/console.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -63,5 +63,5 @@
 
 extern void klog_init(void);
-extern void klog_update(void);
+extern void klog_update(void *);
 
 extern wchar_t getc(indev_t *indev);
Index: kernel/generic/include/ddi/ddi.h
===================================================================
--- kernel/generic/include/ddi/ddi.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/include/ddi/ddi.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,6 +36,6 @@
 #define KERN_DDI_H_
 
-#include <ddi/ddi_arg.h>
 #include <typedefs.h>
+#include <abi/ddi/arg.h>
 #include <proc/task.h>
 #include <adt/list.h>
Index: kernel/generic/include/ddi/ddi_arg.h
===================================================================
--- kernel/generic/include/ddi/ddi_arg.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ 	(revision )
@@ -1,68 +1,0 @@
-/*
- * Copyright (c) 2006 Jakub Jermar
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup genericddi
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_DDI_ARG_H_
-#define KERN_DDI_ARG_H_
-
-#ifdef KERNEL
-
-#include <typedefs.h>
-
-#endif /* KERNEL */
-
-/** Structure encapsulating arguments for SYS_PHYSMEM_MAP syscall. */
-typedef struct {
-	/** ID of the destination task. */
-	uint64_t task_id;
-	/** Physical address of starting frame. */
-	void *phys_base;
-	/** Virtual address of starting page. */
-	void *virt_base;
-	/** Number of pages to map. */
-	size_t pages;
-	/** Address space area flags for the mapping. */
-	unsigned int flags;
-} ddi_memarg_t;
-
-/** Structure encapsulating arguments for SYS_ENABLE_IOSPACE syscall. */
-typedef struct {
-	uint64_t task_id;  /**< ID of the destination task. */
-	void *ioaddr;      /**< Starting I/O space address. */
-	size_t size;       /**< Number of bytes. */
-} ddi_ioarg_t;
-
-#endif
-
-/** @}
- */
Index: kernel/generic/include/ddi/irq.h
===================================================================
--- kernel/generic/include/ddi/irq.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/include/ddi/irq.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -33,10 +33,9 @@
  */
 
-#ifndef KERN_IRQ_H_
-#define KERN_IRQ_H_
-
-#ifdef KERNEL
+#ifndef KERN_DDI_IRQ_H_
+#define KERN_DDI_IRQ_H_
 
 #include <typedefs.h>
+#include <abi/ddi/irq.h>
 #include <adt/list.h>
 #include <adt/hash_table.h>
@@ -44,94 +43,4 @@
 #include <proc/task.h>
 #include <ipc/ipc.h>
-
-#endif /* KERNEL */
-
-typedef enum {
-	/** Read 1 byte from the I/O space. */
-	CMD_PIO_READ_8 = 1,
-	/** Read 2 bytes from the I/O space. */
-	CMD_PIO_READ_16,
-	/** Read 4 bytes from the I/O space. */
-	CMD_PIO_READ_32,
-	
-	/** Write 1 byte to the I/O space. */
-	CMD_PIO_WRITE_8,
-	/** Write 2 bytes to the I/O space. */
-	CMD_PIO_WRITE_16,
-	/** Write 4 bytes to the I/O space. */
-	CMD_PIO_WRITE_32,
-	
-	/**
-	 * Write 1 byte from the source argument
-	 * to the I/O space.
-	 */
-	CMD_PIO_WRITE_A_8,
-	/**
-	 * Write 2 bytes from the source argument
-	 * to the I/O space.
-	 */
-	CMD_PIO_WRITE_A_16,
-	/**
-	 * Write 4 bytes from the source argument
-	 * to the I/O space.
-	 */
-	CMD_PIO_WRITE_A_32,
-
-	/** Read 1 byte from the memory space. */
-	CMD_MEM_READ_8,
-	/** Read 2 bytes from the memory space. */
-	CMD_MEM_READ_16,
-	/** Read 4 bytes from the memory space. */
-	CMD_MEM_READ_32,
-
-	/** Write 1 byte to the memory space. */
-	CMD_MEM_WRITE_8,
-	/** Write 2 bytes to the memory space. */
-	CMD_MEM_WRITE_16,
-	/** Write 4 bytes to the memory space. */
-	CMD_MEM_WRITE_32,
-
-	/** Write 1 byte from the source argument to the memory space. */
-	CMD_MEM_WRITE_A_8,
-	/** Write 2 bytes from the source argument to the memory space. */
-	CMD_MEM_WRITE_A_16,
-	/** Write 4 bytes from the source argument to the memory space. */
-	CMD_MEM_WRITE_A_32,
-
-	/**
-	 * Perform a bit masking on the source argument
-	 * and store the result into the destination argument.
-	 */
-	CMD_BTEST,
-	
-	/**
-	 * Predicate the execution of the following
-	 * N commands by the boolean value of the source
-	 * argument.
-	 */
-	CMD_PREDICATE,
-	
-	/** Accept the interrupt. */
-	CMD_ACCEPT,
-	
-	/** Decline the interrupt. */
-	CMD_DECLINE,
-	CMD_LAST
-} irq_cmd_type;
-
-typedef struct {
-	irq_cmd_type cmd;
-	void *addr;
-	uint32_t value;
-	uintptr_t srcarg;
-	uintptr_t dstarg;
-} irq_cmd_t;
-
-typedef struct {
-	size_t cmdcount;
-	irq_cmd_t *cmds;
-} irq_code_t;
-
-#ifdef KERNEL
 
 typedef enum {
@@ -146,4 +55,5 @@
 
 struct irq;
+
 typedef void (* irq_handler_t)(struct irq *);
 
@@ -224,5 +134,5 @@
 	/** Notification configuration structure. */
 	ipc_notif_cfg_t notif_cfg; 
-
+	
 	as_t *driver_as;
 } irq_t;
@@ -238,6 +148,4 @@
 extern irq_t *irq_dispatch_and_lock(inr_t);
 
-#endif /* KERNEL */
-
 #endif
 
Index: kernel/generic/include/errno.h
===================================================================
--- kernel/generic/include/errno.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/include/errno.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup generic	
+/** @addtogroup generic
  * @{
  */
@@ -36,29 +36,5 @@
 #define KERN_ERRNO_H_
 
-/* 1-255 are kernel error codes, 256-512 are user error codes */
-
-#define EOK		0	/* No error */
-#define ENOENT		-1	/* No such entry */
-#define ENOMEM		-2	/* Not enough memory */
-#define ELIMIT		-3	/* Limit exceeded */
-#define EREFUSED	-4	/* Connection refused */
-#define EFORWARD	-5	/* Forward error */
-#define EPERM		-6	/* Permission denied */
-#define EHANGUP		-7	/* Answerbox closed connection, call
-				 * sys_ipc_hangup() to close the connection.
-				 * Used by answerbox to close the connection.
-				 */
-#define EPARTY		-8	/* The other party encountered an error when
-				 * receiving the call.
-				 */
-#define EEXISTS		-9	/* Entry already exists */
-#define EBADMEM		-10	/* Bad memory pointer */
-#define ENOTSUP		-11	/* Not supported */
-#define EADDRNOTAVAIL	-12	/* Address not available. */
-#define ETIMEOUT        -13     /* Timeout expired */
-#define EINVAL          -14     /* Invalid value */
-#define EBUSY           -15     /* Resource is busy */
-#define EOVERFLOW	-16	/* The result does not fit its size. */
-#define EINTR		-17	/* Operation was interrupted. */
+#include <abi/errno.h>
 
 #endif
Index: kernel/generic/include/ipc/event.h
===================================================================
--- kernel/generic/include/ipc/event.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/include/ipc/event.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,10 +36,12 @@
 #define KERN_EVENT_H_
 
-#include <ipc/event_types.h>
+#include <abi/ipc/event.h>
 #include <typedefs.h>
 #include <synch/spinlock.h>
 #include <ipc/ipc.h>
 
-typedef void (*event_callback_t)(void);
+struct task;
+
+typedef void (*event_callback_t)(void *);
 
 /** Event notification structure. */
@@ -61,6 +63,9 @@
 
 extern void event_init(void);
+extern void event_task_init(struct task *);
 extern void event_cleanup_answerbox(answerbox_t *);
 extern void event_set_unmask_callback(event_type_t, event_callback_t);
+extern void event_task_set_unmask_callback(struct task *, event_task_type_t,
+    event_callback_t);
 
 #define event_notify_0(e, m) \
@@ -77,6 +82,21 @@
 	event_notify((e), (m), (a1), (a2), (a3), (a4), (a5))
 
+#define event_task_notify_0(t, e, m) \
+	event_task_notify((t), (e), (m), 0, 0, 0, 0, 0)
+#define event_task_notify_1(t, e, m, a1) \
+	event_task_notify((t), (e), (m), (a1), 0, 0, 0, 0)
+#define event_task_notify_2(t, e, m, a1, a2) \
+	event_task_notify((t), (e), (m), (a1), (a2), 0, 0, 0)
+#define event_task_notify_3(t, e, m, a1, a2, a3) \
+	event_task_notify((t), (e), (m), (a1), (a2), (a3), 0, 0)
+#define event_task_notify_4(t, e, m, a1, a2, a3, a4) \
+	event_task_notify((t), (e), (m), (a1), (a2), (a3), (a4), 0)
+#define event_task_notify_5(t, e, m, a1, a2, a3, a4, a5) \
+	event_task_notify((t), (e), (m), (a1), (a2), (a3), (a4), (a5))
+
 extern int event_notify(event_type_t, bool, sysarg_t, sysarg_t, sysarg_t,
     sysarg_t, sysarg_t);
+extern int event_task_notify(struct task *, event_task_type_t, bool, sysarg_t, sysarg_t,
+    sysarg_t, sysarg_t, sysarg_t);
 
 extern sysarg_t sys_event_subscribe(sysarg_t, sysarg_t);
Index: kernel/generic/include/ipc/event_types.h
===================================================================
--- kernel/generic/include/ipc/event_types.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ 	(revision )
@@ -1,51 +1,0 @@
-/*
- * Copyright (c) 2009 Jakub Jermar
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup generic
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_EVENT_TYPES_H_
-#define KERN_EVENT_TYPES_H_
-
-typedef enum event_type {
-	/** New data available in kernel log */
-	EVENT_KLOG = 0,
-	/** Returning from kernel console to uspace */
-	EVENT_KCONSOLE,
-	/** A task/thread has faulted and will be terminated */
-	EVENT_FAULT,
-	EVENT_END
-} event_type_t;
-
-#endif
-
-/** @}
- */
Index: kernel/generic/include/ipc/ipc.h
===================================================================
--- kernel/generic/include/ipc/ipc.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/include/ipc/ipc.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,97 +36,11 @@
 #define KERN_IPC_H_
 
-/** Length of data being transfered with IPC call
- *
- * The uspace may not be able to utilize full length
- *
- */
-#define IPC_CALL_LEN  6
-
-/** Maximum active async calls per phone */
-#define IPC_MAX_ASYNC_CALLS  4
-
-/* Flags for calls */
-
-/** This is answer to a call */
-#define IPC_CALL_ANSWERED  (1 << 0)
-
-/** Answer will not be passed to userspace, will be discarded */
-#define IPC_CALL_DISCARD_ANSWER  (1 << 1)
-
-/** Call was forwarded */
-#define IPC_CALL_FORWARDED  (1 << 2)
-
-/** Identify connect_me_to answer */
-#define IPC_CALL_CONN_ME_TO  (1 << 3)
-
-/** Interrupt notification */
-#define IPC_CALL_NOTIF  (1 << 4)
-
-
-/** Bits used in call hashes.
- *
- * The addresses are aligned at least to 4 that is why we can use the 2 least
- * significant bits of the call address.
- *
- */
-
-/** Type of this call is 'answer' */
-#define IPC_CALLID_ANSWERED  1
-
-/** Type of this call is 'notification' */
-#define IPC_CALLID_NOTIFICATION  2
-
-/* Return values from sys_ipc_call_async(). */
-#define IPC_CALLRET_FATAL      -1
-#define IPC_CALLRET_TEMPORARY  -2
-
-
-/* Macros for manipulating calling data */
-#define IPC_SET_RETVAL(data, retval)  ((data).args[0] = (retval))
-#define IPC_SET_IMETHOD(data, val)    ((data).args[0] = (val))
-#define IPC_SET_ARG1(data, val)       ((data).args[1] = (val))
-#define IPC_SET_ARG2(data, val)       ((data).args[2] = (val))
-#define IPC_SET_ARG3(data, val)       ((data).args[3] = (val))
-#define IPC_SET_ARG4(data, val)       ((data).args[4] = (val))
-#define IPC_SET_ARG5(data, val)       ((data).args[5] = (val))
-
-#define IPC_GET_IMETHOD(data)  ((data).args[0])
-#define IPC_GET_RETVAL(data)   ((data).args[0])
-
-#define IPC_GET_ARG1(data)  ((data).args[1])
-#define IPC_GET_ARG2(data)  ((data).args[2])
-#define IPC_GET_ARG3(data)  ((data).args[3])
-#define IPC_GET_ARG4(data)  ((data).args[4])
-#define IPC_GET_ARG5(data)  ((data).args[5])
-
-/* Forwarding flags. */
-#define IPC_FF_NONE  0
-
-/**
- * The call will be routed as though it was initially sent via the phone used to
- * forward it. This feature is intended to support the situation in which the
- * forwarded call needs to be handled by the same connection fibril as any other
- * calls that were initially sent by the forwarder to the same destination. This
- * flag has no imapct on routing replies.
- *
- */
-#define IPC_FF_ROUTE_FROM_ME  (1 << 0)
-
-/* Data transfer flags. */
-#define IPC_XF_NONE  0
-
-/** Restrict the transfer size if necessary. */
-#define IPC_XF_RESTRICT  (1 << 0)
-
-/** User-defined IPC methods */
-#define IPC_FIRST_USER_METHOD  1024
-
-#ifdef KERNEL
-
-#define IPC_MAX_PHONES  32
-
+#include <abi/ipc/ipc.h>
 #include <synch/spinlock.h>
 #include <synch/mutex.h>
 #include <synch/waitq.h>
+#include <typedefs.h>
+
+#define IPC_MAX_PHONES  32
 
 struct answerbox;
@@ -184,6 +98,9 @@
 typedef struct {
 	sysarg_t args[IPC_CALL_LEN];
-	/** Task which made or forwarded the call with IPC_FF_ROUTE_FROM_ME. */
-	struct task *task;
+	/**
+	 * Task which made or forwarded the call with IPC_FF_ROUTE_FROM_ME,
+	 * or the task which answered the call.
+	 */
+	task_id_t task_id;
 	/** Phone which made or last masqueraded this call. */
 	phone_t *phone;
@@ -247,6 +164,4 @@
 extern void ipc_print_task(task_id_t);
 
-#endif /* KERNEL */
-
 #endif
 
Index: kernel/generic/include/ipc/ipc_methods.h
===================================================================
--- kernel/generic/include/ipc/ipc_methods.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ 	(revision )
@@ -1,186 +1,0 @@
-/*
- * Copyright (c) 2006 Ondrej Palkovsky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup genericipc
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_IPC_METHODS_H_
-#define KERN_IPC_METHODS_H_
-
-/* Well known phone descriptors */
-#define PHONE_NS  0
-
-/** Kernel IPC interfaces
- *
- */
-#define IPC_IF_KERNEL  0
-
-/** System-specific IPC methods
- *
- * These methods have special behaviour. These methods also
- * have the implicit kernel interface zero (0).
- *
- */
-
-/** This message is sent to answerbox when the phone is hung up
- *
- * The numerical value zero (0) of this method is important,
- * so as the value can be easily tested in conditions.
- *
- */
-#define IPC_M_PHONE_HUNGUP  0
-
-/** Clone connection.
- *
- * The calling task clones one of its phones for the callee.
- *
- * - ARG1 - The caller sets ARG1 to the phone of the cloned connection.
- *        - The callee gets the new phone from ARG1.
- *
- * - on answer, the callee acknowledges the new connection by sending EOK back
- *   or the kernel closes it
- *
- */
-#define IPC_M_CONNECTION_CLONE  1
-
-/** Protocol for CONNECT - ME
- *
- * Through this call, the recipient learns about the new cloned connection.
- *
- * - ARG5 - the kernel sets ARG5 to contain the hash of the used phone
- * - on answer, the callee acknowledges the new connection by sending EOK back
- *   or the kernel closes it
- *
- */
-#define IPC_M_CONNECT_ME  2
-
-/** Protocol for CONNECT - TO - ME
- *
- * Calling process asks the callee to create a callback connection,
- * so that it can start initiating new messages.
- *
- * The protocol for negotiating is:
- * - sys_connect_to_me - sends a message IPC_M_CONNECT_TO_ME
- * - recipient         - upon receipt tries to allocate new phone
- *                       - if it fails, responds with ELIMIT
- *                     - passes call to userspace. If userspace
- *                       responds with error, phone is deallocated and
- *                       error is sent back to caller. Otherwise 
- *                       the call is accepted and the response is sent back.
- *                     - the hash of the client task is passed to userspace
- *                       (on the receiving side) as ARG4 of the call.
- *                     - the hash of the allocated phone is passed to userspace
- *                       (on the receiving side) as ARG5 of the call.
- *
- */
-#define IPC_M_CONNECT_TO_ME  3
-
-/** Protocol for CONNECT - ME - TO
- *
- * Calling process asks the callee to create for him a new connection.
- * E.g. the caller wants a name server to connect him to print server.
- *
- * The protocol for negotiating is:
- * - sys_connect_me_to - send a synchronous message to name server
- *                       indicating that it wants to be connected to some
- *                       service
- *                     - arg1/2/3 are user specified, arg5 contains
- *                       address of the phone that should be connected
- *                       (TODO: it leaks to userspace)
- *  - recipient        -  if ipc_answer == 0, then accept connection
- *                     -  otherwise connection refused
- *                     -  recepient may forward message.
- *
- */
-#define IPC_M_CONNECT_ME_TO  4
-
-/** Send as_area over IPC.
- * - ARG1 - source as_area base address
- * - ARG2 - size of source as_area (filled automatically by kernel)
- * - ARG3 - flags of the as_area being sent
- *
- * on answer, the recipient must set:
- * - ARG1 - dst as_area base adress
- *
- */
-#define IPC_M_SHARE_OUT  5
-
-/** Receive as_area over IPC.
- * - ARG1 - destination as_area base address
- * - ARG2 - destination as_area size
- * - ARG3 - user defined argument
- *
- * on answer, the recipient must set:
- *
- * - ARG1 - source as_area base address
- * - ARG2 - flags that will be used for sharing
- *
- */
-#define IPC_M_SHARE_IN  6
-
-/** Send data to another address space over IPC.
- * - ARG1 - source address space virtual address
- * - ARG2 - size of data to be copied, may be overriden by the recipient
- *
- * on answer, the recipient must set:
- *
- * - ARG1 - final destination address space virtual address
- * - ARG2 - final size of data to be copied
- *
- */
-#define IPC_M_DATA_WRITE  7
-
-/** Receive data from another address space over IPC.
- * - ARG1 - destination virtual address in the source address space
- * - ARG2 - size of data to be received, may be cropped by the recipient 
- *
- * on answer, the recipient must set:
- *
- * - ARG1 - source virtual address in the destination address space
- * - ARG2 - final size of data to be copied
- *
- */
-#define IPC_M_DATA_READ  8
-
-/** Debug the recipient.
- * - ARG1 - specifies the debug method (from udebug_method_t)
- * - other arguments are specific to the debug method
- *
- */
-#define IPC_M_DEBUG  9
-
-/** Last system IPC method */
-#define IPC_M_LAST_SYSTEM  511
-
-#endif
-
-/** @}
- */
Index: kernel/generic/include/lib/elf.h
===================================================================
--- kernel/generic/include/lib/elf.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/include/lib/elf.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,315 +36,7 @@
 #define KERN_ELF_H_
 
+#include <typedefs.h>
+#include <abi/elf.h>
 #include <arch/elf.h>
-#include <typedefs.h>
-
-/**
- * current ELF version
- */
-#define EV_CURRENT  1
-
-/**
- * ELF types
- */
-#define ET_NONE    0       /* No type */
-#define ET_REL     1       /* Relocatable file */
-#define ET_EXEC    2       /* Executable */
-#define ET_DYN     3       /* Shared object */
-#define ET_CORE    4       /* Core */
-#define ET_LOPROC  0xff00  /* Processor specific */
-#define ET_HIPROC  0xffff  /* Processor specific */
-
-/**
- * ELF machine types
- */
-#define EM_NO           0   /* No machine */
-#define EM_SPARC        2   /* SPARC */
-#define EM_386          3   /* i386 */
-#define EM_MIPS         8   /* MIPS RS3000 */
-#define EM_MIPS_RS3_LE  10  /* MIPS RS3000 LE */
-#define EM_PPC          20  /* PPC32 */
-#define EM_PPC64        21  /* PPC64 */
-#define EM_ARM          40  /* ARM */
-#define EM_SPARCV9      43  /* SPARC64 */
-#define EM_IA_64        50  /* IA-64 */
-#define EM_X86_64       62  /* AMD64/EMT64 */
-
-/**
- * ELF identification indexes
- */
-#define EI_MAG0        0
-#define EI_MAG1        1
-#define EI_MAG2        2
-#define EI_MAG3        3
-#define EI_CLASS       4   /* File class */
-#define EI_DATA        5   /* Data encoding */
-#define EI_VERSION     6   /* File version */
-#define EI_OSABI       7
-#define EI_ABIVERSION  8
-#define EI_PAD         9   /* Start of padding bytes */
-#define EI_NIDENT      16  /* ELF identification table size */
-
-/**
- * ELF magic number
- */
-#define ELFMAG0  0x7f
-#define ELFMAG1  'E'
-#define ELFMAG2  'L'
-#define ELFMAG3  'F'
-
-/**
- * ELF file classes
- */
-#define ELFCLASSNONE  0
-#define ELFCLASS32    1
-#define ELFCLASS64    2
-
-/**
- * ELF data encoding types
- */
-#define ELFDATANONE  0
-#define ELFDATA2LSB  1  /* Least significant byte first (little endian) */
-#define ELFDATA2MSB  2  /* Most signigicant byte first (big endian) */
-
-/**
- * ELF error return codes
- */
-#define EE_OK             0  /* No error */
-#define EE_INVALID        1  /* Invalid ELF image */
-#define EE_MEMORY         2  /* Cannot allocate address space */
-#define EE_INCOMPATIBLE   3  /* ELF image is not compatible with current architecture */
-#define EE_UNSUPPORTED    4  /* Non-supported ELF (e.g. dynamic ELFs) */
-#define EE_LOADER         5  /* The image is actually a program loader */
-#define EE_IRRECOVERABLE  6
-
-/**
- * ELF section types
- */
-#define SHT_NULL      0
-#define SHT_PROGBITS  1
-#define SHT_SYMTAB    2
-#define SHT_STRTAB    3
-#define SHT_RELA      4
-#define SHT_HASH      5
-#define SHT_DYNAMIC   6
-#define SHT_NOTE      7
-#define SHT_NOBITS    8
-#define SHT_REL       9
-#define SHT_SHLIB     10
-#define SHT_DYNSYM    11
-#define SHT_LOOS      0x60000000
-#define SHT_HIOS      0x6fffffff
-#define SHT_LOPROC    0x70000000
-#define SHT_HIPROC    0x7fffffff
-#define SHT_LOUSER    0x80000000
-#define SHT_HIUSER    0xffffffff
-
-/**
- * ELF section flags
- */
-#define SHF_WRITE      0x1
-#define SHF_ALLOC      0x2
-#define SHF_EXECINSTR  0x4
-#define SHF_TLS        0x400
-#define SHF_MASKPROC   0xf0000000
-
-/**
- * Symbol binding
- */
-#define STB_LOCAL   0
-#define STB_GLOBAL  1
-#define STB_WEAK    2
-#define STB_LOPROC  13
-#define STB_HIPROC  15
-
-/**
- * Symbol types
- */
-#define STT_NOTYPE   0
-#define STT_OBJECT   1
-#define STT_FUNC     2
-#define STT_SECTION  3
-#define STT_FILE     4
-#define STT_LOPROC   13
-#define STT_HIPROC   15
-
-/**
- * Program segment types
- */
-#define PT_NULL     0
-#define PT_LOAD     1
-#define PT_DYNAMIC  2
-#define PT_INTERP   3
-#define PT_NOTE     4
-#define PT_SHLIB    5
-#define PT_PHDR     6
-#define PT_LOPROC   0x70000000
-#define PT_HIPROC   0x7fffffff
-
-/**
- * Program segment attributes.
- */
-#define PF_X  1
-#define PF_W  2
-#define PF_R  4
-
-/**
- * ELF data types
- *
- * These types are found to be identical in both 32-bit and 64-bit
- * ELF object file specifications. They are the only types used
- * in ELF header.
- *
- */
-typedef uint64_t elf_xword;
-typedef int64_t elf_sxword;
-typedef uint32_t elf_word;
-typedef int32_t elf_sword;
-typedef uint16_t elf_half;
-
-/**
- * 32-bit ELF data types.
- *
- * These types are specific for 32-bit format.
- *
- */
-typedef uint32_t elf32_addr;
-typedef uint32_t elf32_off;
-
-/**
- * 64-bit ELF data types.
- *
- * These types are specific for 64-bit format.
- *
- */
-typedef uint64_t elf64_addr;
-typedef uint64_t elf64_off;
-
-/** ELF header */
-struct elf32_header {
-	uint8_t e_ident[EI_NIDENT];
-	elf_half e_type;
-	elf_half e_machine;
-	elf_word e_version;
-	elf32_addr e_entry;
-	elf32_off e_phoff;
-	elf32_off e_shoff;
-	elf_word e_flags;
-	elf_half e_ehsize;
-	elf_half e_phentsize;
-	elf_half e_phnum;
-	elf_half e_shentsize;
-	elf_half e_shnum;
-	elf_half e_shstrndx;
-};
-
-struct elf64_header {
-	uint8_t e_ident[EI_NIDENT];
-	elf_half e_type;
-	elf_half e_machine;
-	elf_word e_version;
-	elf64_addr e_entry;
-	elf64_off e_phoff;
-	elf64_off e_shoff;
-	elf_word e_flags;
-	elf_half e_ehsize;
-	elf_half e_phentsize;
-	elf_half e_phnum;
-	elf_half e_shentsize;
-	elf_half e_shnum;
-	elf_half e_shstrndx;
-};
-
-/**
- * ELF segment header.
- * Segments headers are also known as program headers.
- */
-struct elf32_segment_header {
-	elf_word p_type;
-	elf32_off p_offset;
-	elf32_addr p_vaddr;
-	elf32_addr p_paddr;
-	elf_word p_filesz;
-	elf_word p_memsz;
-	elf_word p_flags;
-	elf_word p_align;
-};
-
-struct elf64_segment_header {
-	elf_word p_type;
-	elf_word p_flags;
-	elf64_off p_offset;
-	elf64_addr p_vaddr;
-	elf64_addr p_paddr;
-	elf_xword p_filesz;
-	elf_xword p_memsz;
-	elf_xword p_align;
-};
-
-/**
- * ELF section header
- */
-struct elf32_section_header {
-	elf_word sh_name;
-	elf_word sh_type;
-	elf_word sh_flags;
-	elf32_addr sh_addr;
-	elf32_off sh_offset;
-	elf_word sh_size;
-	elf_word sh_link;
-	elf_word sh_info;
-	elf_word sh_addralign;
-	elf_word sh_entsize;
-};
-
-struct elf64_section_header {
-	elf_word sh_name;
-	elf_word sh_type;
-	elf_xword sh_flags;
-	elf64_addr sh_addr;
-	elf64_off sh_offset;
-	elf_xword sh_size;
-	elf_word sh_link;
-	elf_word sh_info;
-	elf_xword sh_addralign;
-	elf_xword sh_entsize;
-};
-
-/**
- * ELF symbol table entry
- */
-struct elf32_symbol {
-	elf_word st_name;
-	elf32_addr st_value;
-	elf_word st_size;
-	uint8_t st_info;
-	uint8_t st_other;
-	elf_half st_shndx;
-};
-
-struct elf64_symbol {
-	elf_word st_name;
-	uint8_t st_info;
-	uint8_t st_other;
-	elf_half st_shndx;
-	elf64_addr st_value;
-	elf_xword st_size;
-};
-
-#ifdef __32_BITS__
-typedef struct elf32_header elf_header_t;
-typedef struct elf32_segment_header elf_segment_header_t;
-typedef struct elf32_section_header elf_section_header_t;
-typedef struct elf32_symbol elf_symbol_t;
-#endif
-
-#ifdef __64_BITS__
-typedef struct elf64_header elf_header_t;
-typedef struct elf64_segment_header elf_segment_header_t;
-typedef struct elf64_section_header elf_section_header_t;
-typedef struct elf64_symbol elf_symbol_t;
-#endif
-
-extern const char *elf_error(unsigned int rc);
 
 /** Interpreter string used to recognize the program loader */
Index: kernel/generic/include/lib/elf_load.h
===================================================================
--- kernel/generic/include/lib/elf_load.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
+++ kernel/generic/include/lib/elf_load.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2006 Sergey Bondari
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup generic
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_ELF_LOAD_H_
+#define KERN_ELF_LOAD_H_
+
+#include <arch/elf.h>
+#include <typedefs.h>
+
+/**
+ * ELF error return codes
+ */
+#define EE_OK			0	/* No error */
+#define EE_INVALID		1	/* Invalid ELF image */
+#define	EE_MEMORY		2	/* Cannot allocate address space */
+#define EE_INCOMPATIBLE		3	/* ELF image is not compatible with current architecture */
+#define EE_UNSUPPORTED		4	/* Non-supported ELF (e.g. dynamic ELFs) */
+#define EE_LOADER		5	/* The image is actually a program loader. */
+#define EE_IRRECOVERABLE	6
+
+/**
+ * This flags is passed when running the loader, otherwise elf_load()
+ * would return with a EE_LOADER error code.
+ *
+ */
+#define ELD_F_NONE    0
+#define ELD_F_LOADER  1
+
+extern unsigned int elf_load(elf_header_t *, as_t *, unsigned int);
+extern const char *elf_error(unsigned int rc);
+
+#endif
+
+/** @}
+ */
Index: kernel/generic/include/mm/as.h
===================================================================
--- kernel/generic/include/mm/as.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/include/mm/as.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,30 +36,6 @@
 #define KERN_AS_H_
 
-#ifdef KERNEL
-	#include <typedefs.h>
-#else
-	#include <sys/types.h>
-#endif
-
-/** Address space area flags. */
-#define AS_AREA_READ       1
-#define AS_AREA_WRITE      2
-#define AS_AREA_EXEC       4
-#define AS_AREA_CACHEABLE  8
-
-/** Address space area info exported to userspace. */
-typedef struct {
-	/** Starting address */
-	uintptr_t start_addr;
-	
-	/** Area size */
-	size_t size;
-	
-	/** Area flags */
-	unsigned int flags;
-} as_area_info_t;
-
-#ifdef KERNEL
-
+#include <typedefs.h>
+#include <abi/mm/as.h>
 #include <arch/mm/page.h>
 #include <arch/mm/as.h>
@@ -307,14 +283,4 @@
 extern mem_backend_t phys_backend;
 
-/**
- * This flags is passed when running the loader, otherwise elf_load()
- * would return with a EE_LOADER error code.
- *
- */
-#define ELD_F_NONE    0
-#define ELD_F_LOADER  1
-
-extern unsigned int elf_load(elf_header_t *, as_t *, unsigned int);
-
 /* Address space area related syscalls. */
 extern sysarg_t sys_as_area_create(uintptr_t, size_t, unsigned int);
@@ -328,6 +294,4 @@
 extern void as_print(as_t *);
 
-#endif /* KERNEL */
-
 #endif
 
Index: kernel/generic/include/proc/task.h
===================================================================
--- kernel/generic/include/proc/task.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/include/proc/task.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -38,4 +38,6 @@
 #include <cpu.h>
 #include <ipc/ipc.h>
+#include <ipc/event.h>
+#include <ipc/kbox.h>
 #include <synch/spinlock.h>
 #include <synch/mutex.h>
@@ -53,7 +55,6 @@
 #include <proc/scheduler.h>
 #include <udebug/udebug.h>
-#include <ipc/kbox.h>
 #include <mm/as.h>
-#include <sysinfo/abi.h>
+#include <abi/sysinfo.h>
 
 struct thread;
@@ -93,6 +94,6 @@
 	phone_t phones[IPC_MAX_PHONES];
 	stats_ipc_t ipc_info;   /**< IPC statistics */
-	/** List of synchronous answerboxes. */
-	list_t sync_boxes;
+	list_t sync_boxes;      /**< List of synchronous answerboxes. */
+	event_t events[EVENT_TASK_END - EVENT_END];
 	
 #ifdef CONFIG_UDEBUG
Index: kernel/generic/include/proc/thread.h
===================================================================
--- kernel/generic/include/proc/thread.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/include/proc/thread.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -45,7 +45,7 @@
 #include <arch/cpu.h>
 #include <mm/tlb.h>
-#include <proc/uarg.h>
+#include <abi/proc/uarg.h>
 #include <udebug/udebug.h>
-#include <sysinfo/abi.h>
+#include <abi/sysinfo.h>
 
 #define THREAD_NAME_BUFLEN  20
Index: kernel/generic/include/proc/uarg.h
===================================================================
--- kernel/generic/include/proc/uarg.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ 	(revision )
@@ -1,52 +1,0 @@
-/*
- * Copyright (c) 2006 Jakub Jermar
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup genericproc
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_UARG_H_
-#define KERN_UARG_H_
-
-/** Structure passed to uinit kernel thread as argument. */
-typedef struct uspace_arg {
-	void *uspace_entry;
-	void *uspace_stack;
-	
-	void (* uspace_thread_function)();
-	void *uspace_thread_arg;
-	
-	struct uspace_arg *uspace_uarg;
-} uspace_arg_t;
-
-#endif
-
-/** @}
- */
Index: kernel/generic/include/synch/condvar.h
===================================================================
--- kernel/generic/include/synch/condvar.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/include/synch/condvar.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -39,5 +39,5 @@
 #include <synch/waitq.h>
 #include <synch/mutex.h>
-#include <synch/synch.h>
+#include <abi/synch.h>
 
 typedef struct {
Index: kernel/generic/include/synch/mutex.h
===================================================================
--- kernel/generic/include/synch/mutex.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/include/synch/mutex.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -38,5 +38,5 @@
 #include <typedefs.h>
 #include <synch/semaphore.h>
-#include <synch/synch.h>
+#include <abi/synch.h>
 
 typedef enum {
Index: kernel/generic/include/synch/semaphore.h
===================================================================
--- kernel/generic/include/synch/semaphore.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/include/synch/semaphore.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -38,5 +38,5 @@
 #include <typedefs.h>
 #include <synch/waitq.h>
-#include <synch/synch.h>
+#include <abi/synch.h>
 
 typedef struct {
Index: kernel/generic/include/synch/synch.h
===================================================================
--- kernel/generic/include/synch/synch.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ 	(revision )
@@ -1,67 +1,0 @@
-/*
- * Copyright (c) 2001-2004 Jakub Jermar
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup sync
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_SYNCH_H_
-#define KERN_SYNCH_H_
-
-/** Request with no timeout. */
-#define SYNCH_NO_TIMEOUT	0
-
-/** No flags specified. */
-#define SYNCH_FLAGS_NONE		0
-/** Non-blocking operation request. */
-#define SYNCH_FLAGS_NON_BLOCKING	(1 << 0)
-/** Interruptible operation. */
-#define SYNCH_FLAGS_INTERRUPTIBLE	(1 << 1)
-
-/** Could not satisfy the request without going to sleep. */
-#define ESYNCH_WOULD_BLOCK	1
-/** Timeout occurred. */
-#define ESYNCH_TIMEOUT		2
-/** Sleep was interrupted. */
-#define ESYNCH_INTERRUPTED	4
-/** Operation succeeded without sleeping. */
-#define ESYNCH_OK_ATOMIC	8
-/** Operation succeeded and did sleep. */
-#define ESYNCH_OK_BLOCKED	16
-
-#define SYNCH_FAILED(rc) \
-	((rc) & (ESYNCH_WOULD_BLOCK | ESYNCH_TIMEOUT | ESYNCH_INTERRUPTED))
-#define SYNCH_OK(rc) \
-	((rc) & (ESYNCH_OK_ATOMIC | ESYNCH_OK_BLOCKED))
-
-#endif
-
-/** @}
- */
Index: kernel/generic/include/synch/waitq.h
===================================================================
--- kernel/generic/include/synch/waitq.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/include/synch/waitq.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -38,5 +38,5 @@
 #include <typedefs.h>
 #include <synch/spinlock.h>
-#include <synch/synch.h>
+#include <abi/synch.h>
 #include <adt/list.h>
 
Index: kernel/generic/include/syscall/syscall.h
===================================================================
--- kernel/generic/include/syscall/syscall.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/include/syscall/syscall.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,70 +36,6 @@
 #define KERN_SYSCALL_H_
 
-typedef enum {
-	SYS_KLOG = 0,
-	SYS_TLS_SET = 1,  /* Hardcoded for AMD64, IA-32 (fibril.S in uspace) */
-	
-	SYS_THREAD_CREATE,
-	SYS_THREAD_EXIT,
-	SYS_THREAD_GET_ID,
-	SYS_THREAD_USLEEP,
-	SYS_THREAD_UDELAY,
-	
-	SYS_TASK_GET_ID,
-	SYS_TASK_SET_NAME,
-	SYS_TASK_KILL,
-	SYS_TASK_EXIT,
-	SYS_PROGRAM_SPAWN_LOADER,
-	
-	SYS_FUTEX_SLEEP,
-	SYS_FUTEX_WAKEUP,
-	SYS_SMC_COHERENCE,
-	
-	SYS_AS_AREA_CREATE,
-	SYS_AS_AREA_RESIZE,
-	SYS_AS_AREA_CHANGE_FLAGS,
-	SYS_AS_AREA_DESTROY,
-	SYS_AS_GET_UNMAPPED_AREA,
-	
-	SYS_PAGE_FIND_MAPPING,
-	
-	SYS_IPC_CALL_SYNC_FAST,
-	SYS_IPC_CALL_SYNC_SLOW,
-	SYS_IPC_CALL_ASYNC_FAST,
-	SYS_IPC_CALL_ASYNC_SLOW,
-	SYS_IPC_ANSWER_FAST,
-	SYS_IPC_ANSWER_SLOW,
-	SYS_IPC_FORWARD_FAST,
-	SYS_IPC_FORWARD_SLOW,
-	SYS_IPC_WAIT,
-	SYS_IPC_POKE,
-	SYS_IPC_HANGUP,
-	SYS_IPC_CONNECT_KBOX,
-	
-	SYS_EVENT_SUBSCRIBE,
-	SYS_EVENT_UNMASK,
-	
-	SYS_CAP_GRANT,
-	SYS_CAP_REVOKE,
-	
-	SYS_DEVICE_ASSIGN_DEVNO,
-	SYS_PHYSMEM_MAP,
-	SYS_IOSPACE_ENABLE,
-	SYS_REGISTER_IRQ,
-	SYS_UNREGISTER_IRQ,
-	
-	SYS_SYSINFO_GET_TAG,
-	SYS_SYSINFO_GET_VALUE,
-	SYS_SYSINFO_GET_DATA_SIZE,
-	SYS_SYSINFO_GET_DATA,
-	
-	SYS_DEBUG_ACTIVATE_CONSOLE,
-	
-	SYSCALL_END
-} syscall_t;
-
-#ifdef KERNEL
-
 #include <typedefs.h>
+#include <abi/syscall.h>
 
 typedef sysarg_t (*syshandler_t)(sysarg_t, sysarg_t, sysarg_t, sysarg_t,
@@ -113,6 +49,4 @@
 #endif
 
-#endif
-
 /** @}
  */
Index: kernel/generic/include/sysinfo/abi.h
===================================================================
--- kernel/generic/include/sysinfo/abi.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ 	(revision )
@@ -1,144 +1,0 @@
-/*
- * Copyright (c) 2010 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup generic
- * @{
- */
-/** @file
- * Data structures passed between kernel sysinfo and user space.
- */
-
-#ifndef KERN_ABI_H_
-#define KERN_ABI_H_
-
-/** Number of load components */
-#define LOAD_STEPS  3
-
-/** Maximum name sizes */
-#define TASK_NAME_BUFLEN  20
-#define EXC_NAME_BUFLEN   20
-
-/** Thread states */
-typedef enum {
-	/** It is an error, if thread is found in this state. */
-	Invalid,
-	/** State of a thread that is currently executing on some CPU. */
-	Running,
-	/** Thread in this state is waiting for an event. */
-	Sleeping,
-	/** State of threads in a run queue. */
-	Ready,
-	/** Threads are in this state before they are first readied. */
-	Entering,
-	/** After a thread calls thread_exit(), it is put into Exiting state. */
-	Exiting,
-	/** Threads that were not detached but exited are Lingering. */
-	Lingering
-} state_t;
-
-/** Statistics about a single CPU
- *
- */
-typedef struct {
-	unsigned int id;         /**< CPU ID as stored by kernel */
-	bool active;             /**< CPU is activate */
-	uint16_t frequency_mhz;  /**< Frequency in MHz */
-	uint64_t idle_cycles;    /**< Number of idle cycles */
-	uint64_t busy_cycles;    /**< Number of busy cycles */
-} stats_cpu_t;
-
-/** Physical memory statistics
- *
- */
-typedef struct {
-	uint64_t total;    /**< Total physical memory (bytes) */
-	uint64_t unavail;  /**< Unavailable (reserved, firmware) bytes */
-	uint64_t used;     /**< Allocated physical memory (bytes) */
-	uint64_t free;     /**< Free physical memory (bytes) */
-} stats_physmem_t;
-
-/** IPC statistics
- *
- * Associated with a task.
- *
- */
-typedef struct {
-	uint64_t call_sent;           /**< IPC calls sent */
-	uint64_t call_received;       /**< IPC calls received */
-	uint64_t answer_sent;         /**< IPC answers sent */
-	uint64_t answer_received;     /**< IPC answers received */
-	uint64_t irq_notif_received;  /**< IPC IRQ notifications */
-	uint64_t forwarded;           /**< IPC messages forwarded */
-} stats_ipc_t;
-
-/** Statistics about a single task
- *
- */
-typedef struct {
-	task_id_t task_id;            /**< Task ID */
-	char name[TASK_NAME_BUFLEN];  /**< Task name (in kernel) */
-	size_t virtmem;               /**< Size of VAS (bytes) */
-	size_t resmem;                /**< Size of resident (used) memory (bytes) */
-	size_t threads;               /**< Number of threads */
-	uint64_t ucycles;             /**< Number of CPU cycles in user space */
-	uint64_t kcycles;             /**< Number of CPU cycles in kernel */
-	stats_ipc_t ipc_info;         /**< IPC statistics */
-} stats_task_t;
-
-/** Statistics about a single thread
- *
- */
-typedef struct {
-	thread_id_t thread_id;  /**< Thread ID */
-	task_id_t task_id;      /**< Associated task ID */
-	state_t state;          /**< Thread state */
-	int priority;           /**< Thread priority */
-	uint64_t ucycles;       /**< Number of CPU cycles in user space */
-	uint64_t kcycles;       /**< Number of CPU cycles in kernel */
-	bool on_cpu;            /**< Associated with a CPU */
-	unsigned int cpu;       /**< Associated CPU ID (if on_cpu is true) */
-} stats_thread_t;
-
-/** Statistics about a single exception
- *
- */
-typedef struct {
-	unsigned int id;             /**< Exception ID */
-	char desc[EXC_NAME_BUFLEN];  /**< Description */
-	bool hot;                    /**< Active or inactive exception */
-	uint64_t cycles;             /**< Number of CPU cycles in the handler */
-	uint64_t count;              /**< Number of handled exceptions */
-} stats_exc_t;
-
-/** Load fixed-point value */
-typedef uint32_t load_t;
-
-#endif
-
-/** @}
- */
Index: kernel/generic/include/udebug/udebug.h
===================================================================
--- kernel/generic/include/udebug/udebug.h	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/include/udebug/udebug.h	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,149 +36,5 @@
 #define KERN_UDEBUG_H_
 
-#define UDEBUG_EVMASK(event)  (1 << ((event) - 1))
-
-typedef enum { /* udebug_method_t */
-	
-	/** Start debugging the recipient.
-	 *
-	 * Causes all threads in the receiving task to stop. When they
-	 * are all stoped, an answer with retval 0 is generated.
-	 *
-	 */
-	UDEBUG_M_BEGIN = 1,
-	
-	/** Finish debugging the recipient.
-	 *
-	 * Answers all pending GO and GUARD messages.
-	 *
-	 */
-	UDEBUG_M_END,
-	
-	/** Set which events should be captured. */
-	UDEBUG_M_SET_EVMASK,
-	
-	/** Make sure the debugged task is still there.
-	 *
-	 * This message is answered when the debugged task dies
-	 * or the debugging session ends.
-	 *
-	 */
-	UDEBUG_M_GUARD,
-	
-	/** Run a thread until a debugging event occurs.
-	 *
-	 * This message is answered when the thread stops
-	 * in a debugging event.
-	 *
-	 * - ARG2 - id of the thread to run
-	 *
-	 */
-	UDEBUG_M_GO,
-	
-	/** Stop a thread being debugged.
-	 *
-	 * Creates a special STOP event in the thread, causing
-	 * it to answer a pending GO message (if any).
-	 *
-	 */
-	UDEBUG_M_STOP,
-	
-	/** Read arguments of a syscall.
-	 *
-	 * - ARG2 - thread identification
-	 * - ARG3 - destination address in the caller's address space
-	 *
-	 */
-	UDEBUG_M_ARGS_READ,
-	
-	/** Read thread's userspace register state (istate_t).
-	 *
-	 * - ARG2 - thread identification
-	 * - ARG3 - destination address in the caller's address space
-	 *
-	 * or, on error, retval will be
-	 * - ENOENT - thread does not exist
-	 * - EBUSY - register state not available
-	 */
-	UDEBUG_M_REGS_READ,
-	
-	/** Read the list of the debugged tasks's threads.
-	 *
-	 * - ARG2 - destination address in the caller's address space
-	 * - ARG3 - size of receiving buffer in bytes
-	 *
-	 * The kernel fills the buffer with a series of sysarg_t values
-	 * (thread ids). On answer, the kernel will set:
-	 *
-	 * - ARG2 - number of bytes that were actually copied
-	 * - ARG3 - number of bytes of the complete data
-	 *
-	 */
-	UDEBUG_M_THREAD_READ,
-	
-	/** Read the name of the debugged task.
-	 *
-	 * - ARG2 - destination address in the caller's address space
-	 * - ARG3 - size of receiving buffer in bytes
-	 *
-	 * The kernel fills the buffer with a non-terminated string.
-	 *
-	 * - ARG2 - number of bytes that were actually copied
-	 * - ARG3 - number of bytes of the complete data
-	 *
-	 */
-	UDEBUG_M_NAME_READ,
-	
-	/** Read the list of the debugged task's address space areas.
-	 *
-	 * - ARG2 - destination address in the caller's address space
-	 * - ARG3 - size of receiving buffer in bytes
-	 *
-	 * The kernel fills the buffer with a series of as_area_info_t structures.
-	 * Upon answer, the kernel will set:
-	 *
-	 * - ARG2 - number of bytes that were actually copied
-	 * - ARG3 - number of bytes of the complete data
-	 *
-	 */
-	UDEBUG_M_AREAS_READ,
-	
-	/** Read the debugged tasks's memory.
-	 *
-	 * - ARG2 - destination address in the caller's address space
-	 * - ARG3 - source address in the recipient's address space
-	 * - ARG4 - size of receiving buffer in bytes
-	 *
-	 */
-	UDEBUG_M_MEM_READ
-} udebug_method_t;
-
-typedef enum {
-	UDEBUG_EVENT_FINISHED = 1,  /**< Debuging session has finished */
-	UDEBUG_EVENT_STOP,          /**< Stopped on DEBUG_STOP request */
-	UDEBUG_EVENT_SYSCALL_B,     /**< Before beginning syscall execution */
-	UDEBUG_EVENT_SYSCALL_E,     /**< After finishing syscall execution */
-	UDEBUG_EVENT_THREAD_B,      /**< The task created a new thread */
-	UDEBUG_EVENT_THREAD_E       /**< A thread exited */
-} udebug_event_t;
-
-typedef enum {
-	UDEBUG_EM_FINISHED = UDEBUG_EVMASK(UDEBUG_EVENT_FINISHED),
-	UDEBUG_EM_STOP = UDEBUG_EVMASK(UDEBUG_EVENT_STOP),
-	UDEBUG_EM_SYSCALL_B = UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_B),
-	UDEBUG_EM_SYSCALL_E = UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_E),
-	UDEBUG_EM_THREAD_B = UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_B),
-	UDEBUG_EM_THREAD_E = UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E),
-	UDEBUG_EM_ALL =
-	    (UDEBUG_EVMASK(UDEBUG_EVENT_FINISHED) |
-	    UDEBUG_EVMASK(UDEBUG_EVENT_STOP) |
-	    UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_B) |
-	    UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_E) |
-	    UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_B) |
-	    UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E))
-} udebug_evmask_t;
-
-#ifdef KERNEL
-
+#include <abi/udebug.h>
 #include <ipc/ipc.h>
 #include <synch/mutex.h>
@@ -251,6 +107,4 @@
 #endif
 
-#endif
-
 /** @}
  */
Index: kernel/generic/src/console/console.c
===================================================================
--- kernel/generic/src/console/console.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/src/console/console.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -248,5 +248,5 @@
 }
 
-void klog_update(void)
+void klog_update(void *event)
 {
 	if (!atomic_get(&klog_inited))
@@ -327,5 +327,5 @@
 	/* Force notification on newline */
 	if (ch == '\n')
-		klog_update();
+		klog_update(NULL);
 }
 
@@ -358,5 +358,5 @@
 		free(data);
 	} else
-		klog_update();
+		klog_update(NULL);
 	
 	return size;
Index: kernel/generic/src/ddi/ddi.c
===================================================================
--- kernel/generic/src/ddi/ddi.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/src/ddi/ddi.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -41,5 +41,4 @@
 
 #include <ddi/ddi.h>
-#include <ddi/ddi_arg.h>
 #include <proc/task.h>
 #include <security/cap.h>
Index: kernel/generic/src/ipc/event.c
===================================================================
--- kernel/generic/src/ipc/event.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/src/ipc/event.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -36,9 +36,9 @@
 
 #include <ipc/event.h>
-#include <ipc/event_types.h>
 #include <mm/slab.h>
 #include <typedefs.h>
 #include <synch/spinlock.h>
 #include <console/console.h>
+#include <proc/task.h>
 #include <memstr.h>
 #include <errno.h>
@@ -48,4 +48,28 @@
 static event_t events[EVENT_END];
 
+static void event_initialize(event_t *event)
+{
+	spinlock_initialize(&event->lock, "event.lock");
+	event->answerbox = NULL;
+	event->counter = 0;
+	event->imethod = 0;
+	event->masked = false;
+	event->unmask_callback = NULL;
+}
+
+static event_t *evno2event(int evno, task_t *t)
+{
+	ASSERT(evno < EVENT_TASK_END);
+
+	event_t *event;
+
+	if (evno < EVENT_END)
+		event = &events[(event_type_t) evno];
+	else
+		event = &t->events[(event_task_type_t) evno - EVENT_END];
+
+	return event;
+}
+
 /** Initialize kernel events.
  *
@@ -53,13 +77,14 @@
 void event_init(void)
 {
-	for (unsigned int i = 0; i < EVENT_END; i++) {
-		spinlock_initialize(&events[i].lock, "event.lock");
-		events[i].answerbox = NULL;
-		events[i].counter = 0;
-		events[i].imethod = 0;
-		events[i].masked = false;
-		events[i].unmask_callback = NULL;
-	}
-}
+	for (unsigned int i = 0; i < EVENT_END; i++)
+		event_initialize(evno2event(i, NULL));
+}
+
+void event_task_init(task_t *task)
+{
+	for (unsigned int i = EVENT_END; i < EVENT_TASK_END; i++)
+		event_initialize(evno2event(i, task));
+}
+
 
 /** Unsubscribe kernel events associated with an answerbox
@@ -84,4 +109,11 @@
 }
 
+static void _event_set_unmask_callback(event_t *event, event_callback_t callback)
+{
+	spinlock_lock(&event->lock);
+	event->unmask_callback = callback;
+	spinlock_unlock(&event->lock);
+}
+
 /** Define a callback function for the event unmask event.
  *
@@ -95,7 +127,59 @@
 	ASSERT(evno < EVENT_END);
 	
-	spinlock_lock(&events[evno].lock);
-	events[evno].unmask_callback = callback;
-	spinlock_unlock(&events[evno].lock);
+	_event_set_unmask_callback(evno2event(evno, NULL), callback);
+}
+
+void event_task_set_unmask_callback(task_t *task, event_task_type_t evno,
+    event_callback_t callback)
+{
+	ASSERT(evno >= (int) EVENT_END);
+	ASSERT(evno < EVENT_TASK_END);
+		
+	_event_set_unmask_callback(evno2event(evno, task), callback);
+}
+
+static int event_enqueue(event_t *event, bool mask, sysarg_t a1, sysarg_t a2,
+    sysarg_t a3, sysarg_t a4, sysarg_t a5)
+{
+	int res;
+
+	spinlock_lock(&event->lock);
+	
+	if (event->answerbox != NULL) {
+		if (!event->masked) {
+			call_t *call = ipc_call_alloc(FRAME_ATOMIC);
+			
+			if (call) {
+				call->flags |= IPC_CALL_NOTIF;
+				call->priv = ++event->counter;
+				
+				IPC_SET_IMETHOD(call->data, event->imethod);
+				IPC_SET_ARG1(call->data, a1);
+				IPC_SET_ARG2(call->data, a2);
+				IPC_SET_ARG3(call->data, a3);
+				IPC_SET_ARG4(call->data, a4);
+				IPC_SET_ARG5(call->data, a5);
+				
+				call->data.task_id = TASK ? TASK->taskid : 0;
+				
+				irq_spinlock_lock(&event->answerbox->irq_lock, true);
+				list_append(&call->link, &event->answerbox->irq_notifs);
+				irq_spinlock_unlock(&event->answerbox->irq_lock, true);
+				
+				waitq_wakeup(&event->answerbox->wq, WAKEUP_FIRST);
+				
+				if (mask)
+					event->masked = true;
+				
+				res = EOK;
+			} else
+				res = ENOMEM;
+		} else
+			res = EBUSY;
+	} else
+		res = ENOENT;
+	
+	spinlock_unlock(&event->lock);
+	return res;
 }
 
@@ -124,43 +208,34 @@
 	ASSERT(evno < EVENT_END);
 	
-	spinlock_lock(&events[evno].lock);
-	
-	int ret;
-	
-	if (events[evno].answerbox != NULL) {
-		if (!events[evno].masked) {
-			call_t *call = ipc_call_alloc(FRAME_ATOMIC);
-			
-			if (call) {
-				call->flags |= IPC_CALL_NOTIF;
-				call->priv = ++events[evno].counter;
-				
-				IPC_SET_IMETHOD(call->data, events[evno].imethod);
-				IPC_SET_ARG1(call->data, a1);
-				IPC_SET_ARG2(call->data, a2);
-				IPC_SET_ARG3(call->data, a3);
-				IPC_SET_ARG4(call->data, a4);
-				IPC_SET_ARG5(call->data, a5);
-				
-				irq_spinlock_lock(&events[evno].answerbox->irq_lock, true);
-				list_append(&call->link, &events[evno].answerbox->irq_notifs);
-				irq_spinlock_unlock(&events[evno].answerbox->irq_lock, true);
-				
-				waitq_wakeup(&events[evno].answerbox->wq, WAKEUP_FIRST);
-				
-				if (mask)
-					events[evno].masked = true;
-				
-				ret = EOK;
-			} else
-				ret = ENOMEM;
-		} else
-			ret = EBUSY;
-	} else
-		ret = ENOENT;
-	
-	spinlock_unlock(&events[evno].lock);
-	
-	return ret;
+	return event_enqueue(evno2event(evno, NULL), mask, a1, a2, a3, a4, a5);
+}
+
+/** Send per-task kernel notification event
+ *
+ * @param task Destination task.
+ * @param evno Event type.
+ * @param mask Mask further notifications after a successful
+ *             sending.
+ * @param a1   First argument.
+ * @param a2   Second argument.
+ * @param a3   Third argument.
+ * @param a4   Fourth argument.
+ * @param a5   Fifth argument.
+ *
+ * @return EOK if notification was successfully sent.
+ * @return ENOMEM if the notification IPC message failed to allocate.
+ * @return EBUSY if the notifications of the given type are
+ *         currently masked.
+ * @return ENOENT if the notifications of the given type are
+ *         currently not subscribed.
+ *
+ */
+int event_task_notify(task_t *task, event_task_type_t evno, bool mask,
+    sysarg_t a1, sysarg_t a2, sysarg_t a3, sysarg_t a4, sysarg_t a5)
+{
+	ASSERT(evno >= (int) EVENT_END);
+	ASSERT(evno < EVENT_TASK_END);
+	
+	return event_enqueue(evno2event(evno, task), mask, a1, a2, a3, a4, a5);
 }
 
@@ -177,23 +252,21 @@
  *
  */
-static int event_subscribe(event_type_t evno, sysarg_t imethod,
+static int event_subscribe(event_t *event, sysarg_t imethod,
     answerbox_t *answerbox)
 {
-	ASSERT(evno < EVENT_END);
-	
-	spinlock_lock(&events[evno].lock);
-	
 	int res;
-	
-	if (events[evno].answerbox == NULL) {
-		events[evno].answerbox = answerbox;
-		events[evno].imethod = imethod;
-		events[evno].counter = 0;
-		events[evno].masked = false;
+
+	spinlock_lock(&event->lock);
+	
+	if (event->answerbox == NULL) {
+		event->answerbox = answerbox;
+		event->imethod = imethod;
+		event->counter = 0;
+		event->masked = false;
 		res = EOK;
 	} else
 		res = EEXISTS;
 	
-	spinlock_unlock(&events[evno].lock);
+	spinlock_unlock(&event->lock);
 	
 	return res;
@@ -205,12 +278,10 @@
  *
  */
-static void event_unmask(event_type_t evno)
-{
-	ASSERT(evno < EVENT_END);
-	
-	spinlock_lock(&events[evno].lock);
-	events[evno].masked = false;
-	event_callback_t callback = events[evno].unmask_callback;
-	spinlock_unlock(&events[evno].lock);
+static void event_unmask(event_t *event)
+{
+	spinlock_lock(&event->lock);
+	event->masked = false;
+	event_callback_t callback = event->unmask_callback;
+	spinlock_unlock(&event->lock);
 	
 	/*
@@ -219,5 +290,5 @@
 	 */
 	if (callback != NULL)
-		callback();
+		callback(event);
 }
 
@@ -236,9 +307,9 @@
 sysarg_t sys_event_subscribe(sysarg_t evno, sysarg_t imethod)
 {
-	if (evno >= EVENT_END)
+	if (evno >= EVENT_TASK_END)
 		return ELIMIT;
 	
-	return (sysarg_t) event_subscribe((event_type_t) evno, (sysarg_t)
-	    imethod, &TASK->answerbox);
+	return (sysarg_t) event_subscribe(evno2event(evno, TASK),
+	    (sysarg_t) imethod, &TASK->answerbox);
 }
 
@@ -258,8 +329,9 @@
 sysarg_t sys_event_unmask(sysarg_t evno)
 {
-	if (evno >= EVENT_END)
+	if (evno >= EVENT_TASK_END)
 		return ELIMIT;
 	
-	event_unmask((event_type_t) evno);
+	event_unmask(evno2event(evno, TASK));
+
 	return EOK;
 }
Index: kernel/generic/src/ipc/ipc.c
===================================================================
--- kernel/generic/src/ipc/ipc.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/src/ipc/ipc.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -38,11 +38,9 @@
  */
 
-#include <synch/synch.h>
 #include <synch/spinlock.h>
 #include <synch/mutex.h>
 #include <synch/waitq.h>
-#include <synch/synch.h>
 #include <ipc/ipc.h>
-#include <ipc/ipc_methods.h>
+#include <abi/ipc/methods.h>
 #include <ipc/kbox.h>
 #include <ipc/event.h>
@@ -232,4 +230,6 @@
 		}
 	}
+
+	call->data.task_id = TASK->taskid;
 	
 	if (do_lock)
@@ -296,5 +296,5 @@
 		atomic_inc(&phone->active_calls);
 		call->data.phone = phone;
-		call->data.task = TASK;
+		call->data.task_id = TASK->taskid;
 	}
 	
@@ -408,5 +408,5 @@
 			call->caller_phone = call->data.phone;
 		call->data.phone = newphone;
-		call->data.task = TASK;
+		call->data.task_id = TASK->taskid;
 	}
 	
Index: kernel/generic/src/ipc/kbox.c
===================================================================
--- kernel/generic/src/ipc/kbox.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/src/ipc/kbox.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -33,9 +33,8 @@
  */
 
-#include <synch/synch.h>
 #include <synch/spinlock.h>
 #include <synch/mutex.h>
 #include <ipc/ipc.h>
-#include <ipc/ipc_methods.h>
+#include <abi/ipc/methods.h>
 #include <ipc/ipcrsc.h>
 #include <arch.h>
Index: kernel/generic/src/ipc/sysipc.c
===================================================================
--- kernel/generic/src/ipc/sysipc.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/src/ipc/sysipc.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -40,8 +40,9 @@
 #include <debug.h>
 #include <ipc/ipc.h>
-#include <ipc/ipc_methods.h>
+#include <abi/ipc/methods.h>
 #include <ipc/sysipc.h>
 #include <ipc/irq.h>
 #include <ipc/ipcrsc.h>
+#include <ipc/event.h>
 #include <ipc/kbox.h>
 #include <synch/waitq.h>
@@ -53,4 +54,5 @@
 #include <mm/as.h>
 #include <print.h>
+#include <macros.h>
 
 /**
@@ -134,4 +136,5 @@
 	case IPC_M_DATA_WRITE:
 	case IPC_M_DATA_READ:
+	case IPC_M_STATE_CHANGE_AUTHORIZE:
 		return true;
 	default:
@@ -164,4 +167,5 @@
 	case IPC_M_DATA_WRITE:
 	case IPC_M_DATA_READ:
+	case IPC_M_STATE_CHANGE_AUTHORIZE:
 		return true;
 	default:
@@ -249,6 +253,4 @@
 			/* The connection was accepted */
 			phone_connect(phoneid, &answer->sender->answerbox);
-			/* Set 'task hash' as arg4 of response */
-			IPC_SET_ARG4(answer->data, (sysarg_t) TASK);
 			/* Set 'phone hash' as arg5 of response */
 			IPC_SET_ARG5(answer->data,
@@ -334,4 +336,50 @@
 		free(answer->buffer);
 		answer->buffer = NULL;
+	} else if (IPC_GET_IMETHOD(*olddata) == IPC_M_STATE_CHANGE_AUTHORIZE) {
+		if (!IPC_GET_RETVAL(answer->data)) {
+			/* The recipient authorized the change of state. */
+			phone_t *recipient_phone;
+			task_t *other_task_s;
+			task_t *other_task_r;
+			int rc;
+
+			rc = phone_get(IPC_GET_ARG1(answer->data),
+			    &recipient_phone);
+			if (rc != EOK) {
+				IPC_SET_RETVAL(answer->data, ENOENT);
+				return ENOENT;
+			}
+
+			mutex_lock(&recipient_phone->lock);
+			if (recipient_phone->state != IPC_PHONE_CONNECTED) {
+				mutex_unlock(&recipient_phone->lock);
+				IPC_SET_RETVAL(answer->data, EINVAL);
+				return EINVAL;
+			}
+
+			other_task_r = recipient_phone->callee->task;
+			other_task_s = (task_t *) IPC_GET_ARG5(*olddata);
+
+			/*
+			 * See if both the sender and the recipient meant the
+			 * same third party task.
+			 */
+			if (other_task_r != other_task_s) {
+				IPC_SET_RETVAL(answer->data, EINVAL);
+				rc = EINVAL;
+			} else {
+				rc = event_task_notify_5(other_task_r,
+				    EVENT_TASK_STATE_CHANGE, false,
+				    IPC_GET_ARG1(*olddata),
+				    IPC_GET_ARG2(*olddata),
+				    IPC_GET_ARG3(*olddata),
+				    LOWER32(olddata->task_id),
+				    UPPER32(olddata->task_id));
+				IPC_SET_RETVAL(answer->data, rc);
+			}
+
+			mutex_unlock(&recipient_phone->lock);
+			return rc;
+		}
 	}
 	
@@ -427,6 +475,4 @@
 	case IPC_M_DATA_READ: {
 		size_t size = IPC_GET_ARG2(call->data);
-		if (size <= 0)
-			return ELIMIT;
 		if (size > DATA_XFER_LIMIT) {
 			int flags = IPC_GET_ARG3(call->data);
@@ -458,4 +504,25 @@
 		}
 		
+		break;
+	}
+	case IPC_M_STATE_CHANGE_AUTHORIZE: {
+		phone_t *sender_phone;
+		task_t *other_task_s;
+
+		if (phone_get(IPC_GET_ARG5(call->data), &sender_phone) != EOK)
+			return ENOENT;
+
+		mutex_lock(&sender_phone->lock);
+		if (sender_phone->state != IPC_PHONE_CONNECTED) {
+			mutex_unlock(&sender_phone->lock);
+			return EINVAL;
+		}
+
+		other_task_s = sender_phone->callee->task;
+
+		mutex_unlock(&sender_phone->lock);
+
+		/* Remember the third party task hash. */
+		IPC_SET_ARG5(call->data, (sysarg_t) other_task_s);
 		break;
 	}
Index: kernel/generic/src/lib/elf.c
===================================================================
--- kernel/generic/src/lib/elf.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/src/lib/elf.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -47,4 +47,6 @@
 #include <macros.h>
 #include <arch.h>
+
+#include <lib/elf_load.h>
 
 static const char *error_codes[] = {
Index: kernel/generic/src/proc/program.c
===================================================================
--- kernel/generic/src/proc/program.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/src/proc/program.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -40,5 +40,4 @@
 #include <proc/thread.h>
 #include <proc/task.h>
-#include <proc/uarg.h>
 #include <mm/as.h>
 #include <mm/slab.h>
@@ -48,5 +47,5 @@
 #include <ipc/ipcrsc.h>
 #include <security/cap.h>
-#include <lib/elf.h>
+#include <lib/elf_load.h>
 #include <errno.h>
 #include <print.h>
Index: kernel/generic/src/proc/task.c
===================================================================
--- kernel/generic/src/proc/task.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/src/proc/task.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -50,4 +50,5 @@
 #include <ipc/ipc.h>
 #include <ipc/ipcrsc.h>
+#include <ipc/event.h>
 #include <print.h>
 #include <errno.h>
@@ -57,5 +58,4 @@
 #include <syscall/copy.h>
 #include <macros.h>
-#include <ipc/event.h>
 
 /** Spinlock protecting the tasks_tree AVL tree. */
@@ -201,4 +201,6 @@
 	task->ipc_info.irq_notif_received = 0;
 	task->ipc_info.forwarded = 0;
+
+	event_task_init(task);
 	
 #ifdef CONFIG_UDEBUG
Index: kernel/generic/src/proc/thread.c
===================================================================
--- kernel/generic/src/proc/thread.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/src/proc/thread.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -39,5 +39,4 @@
 #include <proc/thread.h>
 #include <proc/task.h>
-#include <proc/uarg.h>
 #include <mm/frame.h>
 #include <mm/page.h>
@@ -45,5 +44,4 @@
 #include <arch/cycle.h>
 #include <arch.h>
-#include <synch/synch.h>
 #include <synch/spinlock.h>
 #include <synch/waitq.h>
Index: kernel/generic/src/synch/condvar.c
===================================================================
--- kernel/generic/src/synch/condvar.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/src/synch/condvar.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -39,5 +39,4 @@
 #include <synch/mutex.h>
 #include <synch/waitq.h>
-#include <synch/synch.h>
 #include <arch.h>
 
Index: kernel/generic/src/synch/futex.c
===================================================================
--- kernel/generic/src/synch/futex.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/src/synch/futex.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -39,5 +39,4 @@
 #include <synch/mutex.h>
 #include <synch/spinlock.h>
-#include <synch/synch.h>
 #include <mm/frame.h>
 #include <mm/page.h>
Index: kernel/generic/src/synch/mutex.c
===================================================================
--- kernel/generic/src/synch/mutex.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/src/synch/mutex.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -38,5 +38,4 @@
 #include <synch/mutex.h>
 #include <synch/semaphore.h>
-#include <synch/synch.h>
 #include <debug.h>
 #include <arch.h>
Index: kernel/generic/src/synch/semaphore.c
===================================================================
--- kernel/generic/src/synch/semaphore.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/src/synch/semaphore.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -39,5 +39,4 @@
 #include <synch/waitq.h>
 #include <synch/spinlock.h>
-#include <synch/synch.h>
 #include <arch/asm.h>
 #include <arch.h>
Index: kernel/generic/src/synch/waitq.c
===================================================================
--- kernel/generic/src/synch/waitq.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/src/synch/waitq.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -45,5 +45,4 @@
 
 #include <synch/waitq.h>
-#include <synch/synch.h>
 #include <synch/spinlock.h>
 #include <proc/thread.h>
Index: kernel/generic/src/sysinfo/stats.c
===================================================================
--- kernel/generic/src/sysinfo/stats.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/generic/src/sysinfo/stats.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -35,5 +35,5 @@
 
 #include <typedefs.h>
-#include <sysinfo/abi.h>
+#include <abi/sysinfo.h>
 #include <sysinfo/stats.h>
 #include <sysinfo/sysinfo.h>
Index: kernel/test/synch/semaphore2.c
===================================================================
--- kernel/test/synch/semaphore2.c	(revision 86a34d3e4d287b5a98f96a5b7e0a0a001d5529f8)
+++ kernel/test/synch/semaphore2.c	(revision bd5f3b795b75802e7f957c9589605a904f7667df)
@@ -37,5 +37,4 @@
 #include <synch/waitq.h>
 #include <synch/semaphore.h>
-#include <synch/synch.h>
 #include <synch/spinlock.h>
 
