Index: kernel/Makefile
===================================================================
--- kernel/Makefile	(revision a5e5030aae0508c382bae445c1cdda994d8f36e2)
+++ kernel/Makefile	(revision 05641a9edbf1f7a46db1517a8e99aa0ffa7bdd5d)
@@ -162,4 +162,5 @@
 	generic/src/ddi/device.c \
 	generic/src/debug/symtab.c \
+	generic/src/event/event.c \
 	generic/src/interrupt/interrupt.c \
 	generic/src/main/main.c \
Index: kernel/generic/include/event/event.h
===================================================================
--- kernel/generic/include/event/event.h	(revision 05641a9edbf1f7a46db1517a8e99aa0ffa7bdd5d)
+++ kernel/generic/include/event/event.h	(revision 05641a9edbf1f7a46db1517a8e99aa0ffa7bdd5d)
@@ -0,0 +1,79 @@
+/*
+ * 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_H_
+#define KERN_EVENT_H_
+
+#include <event/event_types.h>
+#include <arch/types.h>
+#include <synch/spinlock.h>
+#include <ipc/ipc.h>
+
+/** Event notification structure. */
+typedef struct {
+	SPINLOCK_DECLARE(lock);
+	
+	/** Answerbox for notifications. */
+	answerbox_t *answerbox;
+	/** Method to be used for the notification. */
+	unative_t method;
+	/** Counter. */
+	count_t counter;
+} event_t;
+
+extern void event_init(void);
+extern unative_t sys_event_subscribe(unative_t, unative_t);
+extern bool event_is_subscribed(event_type_t);
+extern void event_cleanup_answerbox(answerbox_t *);
+
+#define event_notify_0(e) \
+	event_notify((e), 0, 0, 0, 0, 0)
+#define event_notify_1(e, a1) \
+	event_notify((e), (a1), 0, 0, 0, 0)
+#define event_notify_2(e, a1, a2) \
+	event_notify((e), (a1), (a2), 0, 0, 0)
+#define event_notify_3(e, a1, a2, a3) \
+	event_notify((e), (a1), (a2), (a3), 0, 0)
+#define event_notify_4(e, a1, a2, a3, a4) \
+	event_notify((e), (a1), (a2), (a3), (a4), 0)
+#define event_notify_5(e, a1, a2, a3, a4, a5) \
+	event_notify((e), (a1), (a2), (a3), (a4), (a5))
+
+extern void event_notify(event_type_t, unative_t, unative_t, unative_t,
+    unative_t, unative_t);
+
+#endif
+
+/** @}
+ */
Index: kernel/generic/include/event/event_types.h
===================================================================
--- kernel/generic/include/event/event_types.h	(revision 05641a9edbf1f7a46db1517a8e99aa0ffa7bdd5d)
+++ kernel/generic/include/event/event_types.h	(revision 05641a9edbf1f7a46db1517a8e99aa0ffa7bdd5d)
@@ -0,0 +1,47 @@
+/*
+ * 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 {
+	EVENT_KLOG = 0,
+	EVENT_KCONSOLE,
+	EVENT_END
+} event_type_t;
+
+#endif
+
+/** @}
+ */
Index: kernel/generic/include/syscall/syscall.h
===================================================================
--- kernel/generic/include/syscall/syscall.h	(revision a5e5030aae0508c382bae445c1cdda994d8f36e2)
+++ kernel/generic/include/syscall/syscall.h	(revision 05641a9edbf1f7a46db1517a8e99aa0ffa7bdd5d)
@@ -69,4 +69,6 @@
 	SYS_IPC_REGISTER_IRQ,
 	SYS_IPC_UNREGISTER_IRQ,
+
+	SYS_EVENT_SUBSCRIBE,
 	
 	SYS_CAP_GRANT,
Index: kernel/generic/src/console/cmd.c
===================================================================
--- kernel/generic/src/console/cmd.c	(revision a5e5030aae0508c382bae445c1cdda994d8f36e2)
+++ kernel/generic/src/console/cmd.c	(revision 05641a9edbf1f7a46db1517a8e99aa0ffa7bdd5d)
@@ -65,4 +65,5 @@
 #include <ipc/ipc.h>
 #include <ipc/irq.h>
+#include <event/event.h>
 #include <symtab.h>
 #include <errno.h>
@@ -955,6 +956,5 @@
 	release_console();
 	
-	if ((kconsole_notify) && (kconsole_irq.notif_cfg.notify))
-		ipc_irq_send_msg_0(&kconsole_irq);
+	event_notify_0(EVENT_KCONSOLE);
 	
 	return 1;
Index: kernel/generic/src/console/console.c
===================================================================
--- kernel/generic/src/console/console.c	(revision a5e5030aae0508c382bae445c1cdda994d8f36e2)
+++ kernel/generic/src/console/console.c	(revision 05641a9edbf1f7a46db1517a8e99aa0ffa7bdd5d)
@@ -42,4 +42,5 @@
 #include <ddi/irq.h>
 #include <ddi/ddi.h>
+#include <event/event.h>
 #include <ipc/irq.h>
 #include <arch.h>
@@ -100,10 +101,4 @@
 	sysinfo_set_item_val("klog.faddr", NULL, (unative_t) faddr);
 	sysinfo_set_item_val("klog.pages", NULL, SIZE2FRAMES(KLOG_SIZE));
-	
-	//irq_initialize(&klog_irq);
-	//klog_irq.devno = devno;
-	//klog_irq.inr = KLOG_VIRT_INR;
-	//klog_irq.claim = klog_claim;
-	//irq_register(&klog_irq);
 	
 	spinlock_lock(&klog_lock);
@@ -243,8 +238,8 @@
 	spinlock_lock(&klog_lock);
 	
-//	if ((klog_inited) && (klog_irq.notif_cfg.notify) && (klog_uspace > 0)) {
-//		ipc_irq_send_msg_3(&klog_irq, klog_start, klog_len, klog_uspace);
-//		klog_uspace = 0;
-//	}
+	if (klog_inited && event_is_subscribed(EVENT_KLOG) && klog_uspace > 0) {
+		event_notify_3(EVENT_KLOG, klog_start, klog_len, klog_uspace);
+		klog_uspace = 0;
+	}
 	
 	spinlock_unlock(&klog_lock);
Index: kernel/generic/src/console/kconsole.c
===================================================================
--- kernel/generic/src/console/kconsole.c	(revision a5e5030aae0508c382bae445c1cdda994d8f36e2)
+++ kernel/generic/src/console/kconsole.c	(revision 05641a9edbf1f7a46db1517a8e99aa0ffa7bdd5d)
@@ -88,28 +88,4 @@
 static char history[KCONSOLE_HISTORY][MAX_CMDLINE] = {};
 
-/*
- * For now, we use 0 as INR.
- * However, it is therefore desirable to have architecture specific
- * definition of KCONSOLE_VIRT_INR in the future.
- */
-#define KCONSOLE_VIRT_INR  0
-
-bool kconsole_notify = false;
-irq_t kconsole_irq;
-
-
-/** Allways refuse IRQ ownership.
- *
- * This is not a real IRQ, so we always decline.
- *
- * @return Always returns IRQ_DECLINE.
- *
- */
-static irq_ownership_t kconsole_claim(irq_t *irq)
-{
-	return IRQ_DECLINE;
-}
-
-
 /** Initialize kconsole data structures
  *
@@ -126,25 +102,4 @@
 		history[i][0] = '\0';
 }
-
-
-/** Initialize kconsole notification mechanism
- *
- * Initialize the virtual IRQ notification mechanism.
- *
- */
-void kconsole_notify_init(void)
-{
-	sysinfo_set_item_val("kconsole.present", NULL, true);
-	sysinfo_set_item_val("kconsole.inr", NULL, KCONSOLE_VIRT_INR);
-	
-	irq_initialize(&kconsole_irq);
-	kconsole_irq.devno = device_assign_devno();
-	kconsole_irq.inr = KCONSOLE_VIRT_INR;
-	kconsole_irq.claim = kconsole_claim;
-	irq_register(&kconsole_irq);
-	
-	kconsole_notify = true;
-}
-
 
 /** Register kconsole command.
Index: kernel/generic/src/event/event.c
===================================================================
--- kernel/generic/src/event/event.c	(revision 05641a9edbf1f7a46db1517a8e99aa0ffa7bdd5d)
+++ kernel/generic/src/event/event.c	(revision 05641a9edbf1f7a46db1517a8e99aa0ffa7bdd5d)
@@ -0,0 +1,153 @@
+/*
+ * 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
+ * @brief	Kernel event notifications.
+ */
+
+#include <event/event.h>
+#include <event/event_types.h>
+#include <mm/slab.h>
+#include <arch/types.h>
+#include <synch/spinlock.h>
+#include <console/console.h>
+#include <memstr.h>
+#include <errno.h>
+#include <arch.h>
+
+/**
+ * The events array.
+ * Arranging the events in this two-dimensional array should decrease the
+ * likelyhood of cacheline ping-pong.
+ */
+static event_t *events[EVENT_END];
+
+/** Initialize kernel events. */
+void event_init(void)
+{
+	int i;
+
+	for (i = 0; i < EVENT_END; i++) {
+		events[i] = (event_t *) malloc(sizeof(event_t), 0);
+		spinlock_initialize(&events[i]->lock, "event.lock");
+		events[i]->answerbox = NULL;
+		events[i]->counter = 0;
+		events[i]->method = 0;
+	}
+}
+
+static int
+event_subscribe(event_type_t e, unative_t method, answerbox_t *answerbox)
+{
+	if (e >= EVENT_END)
+		return ELIMIT;
+
+	int res = EEXISTS;
+	event_t *event = events[e];
+
+	spinlock_lock(&event->lock);
+	if (!event->answerbox) {
+		event->answerbox = answerbox;
+		event->method = method;
+		event->counter = 0;
+		res = EOK;
+	}
+	spinlock_unlock(&event->lock);
+
+	return res;
+}
+
+unative_t sys_event_subscribe(unative_t evno, unative_t method)
+{
+	return (unative_t) event_subscribe((event_type_t) evno, (unative_t)
+	    method, &TASK->answerbox);
+}
+
+bool event_is_subscribed(event_type_t e)
+{
+	bool res;
+
+	ASSERT(e < EVENT_END);
+	spinlock_lock(&events[e]->lock);
+	res = events[e]->answerbox != NULL;
+	spinlock_unlock(&events[e]->lock);
+
+	return res;
+}
+
+
+void event_cleanup_answerbox(answerbox_t *answerbox)
+{
+	int i;
+
+	for (i = 0; i < EVENT_END; i++) {
+		spinlock_lock(&events[i]->lock);
+		if (events[i]->answerbox == answerbox) {
+			events[i]->answerbox = NULL;
+			events[i]->counter = 0;
+			events[i]->method = 0;
+		}
+		spinlock_unlock(&events[i]->lock);
+	}
+}
+
+void
+event_notify(event_type_t e, unative_t a1, unative_t a2, unative_t a3,
+    unative_t a4, unative_t a5)
+{
+	ASSERT(e < EVENT_END);
+	event_t *event = events[e];
+	spinlock_lock(&event->lock);
+	if (event->answerbox) {
+		call_t *call = ipc_call_alloc(FRAME_ATOMIC);
+		if (call) {
+			call->flags |= IPC_CALL_NOTIF;
+			call->priv = ++event->counter;
+			IPC_SET_METHOD(call->data, event->method);
+			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);
+
+			spinlock_lock(&event->answerbox->irq_lock);
+			list_append(&call->link, &event->answerbox->irq_notifs);
+			spinlock_unlock(&event->answerbox->irq_lock);
+
+			waitq_wakeup(&event->answerbox->wq, WAKEUP_FIRST);
+		}
+	}
+	spinlock_unlock(&event->lock);
+}
+
+/** @}
+ */
Index: kernel/generic/src/ipc/ipc.c
===================================================================
--- kernel/generic/src/ipc/ipc.c	(revision a5e5030aae0508c382bae445c1cdda994d8f36e2)
+++ kernel/generic/src/ipc/ipc.c	(revision 05641a9edbf1f7a46db1517a8e99aa0ffa7bdd5d)
@@ -45,4 +45,5 @@
 #include <ipc/ipc.h>
 #include <ipc/kbox.h>
+#include <event/event.h>
 #include <errno.h>
 #include <mm/slab.h>
@@ -51,4 +52,5 @@
 #include <memstr.h>
 #include <debug.h>
+
 
 #include <print.h>
@@ -526,4 +528,7 @@
 	for (i = 0; i < IPC_MAX_PHONES; i++)
 		ipc_phone_hangup(&TASK->phones[i]);
+
+	/* Unsubscribe from any event notifications. */
+	event_cleanup_answerbox(&TASK->answerbox);
 
 	/* Disconnect all connected irqs */
Index: kernel/generic/src/main/main.c
===================================================================
--- kernel/generic/src/main/main.c	(revision a5e5030aae0508c382bae445c1cdda994d8f36e2)
+++ kernel/generic/src/main/main.c	(revision 05641a9edbf1f7a46db1517a8e99aa0ffa7bdd5d)
@@ -83,4 +83,5 @@
 #include <ddi/ddi.h>
 #include <main/main.h>
+#include <event/event.h>
 
 /** Global configuration structure. */
@@ -256,9 +257,6 @@
 	
 	LOG_EXEC(ipc_init());
+	LOG_EXEC(event_init());
 	LOG_EXEC(klog_init());
-	
-#ifdef CONFIG_KCONSOLE
-	LOG_EXEC(kconsole_notify_init());
-#endif
 	
 	/*
Index: kernel/generic/src/syscall/syscall.c
===================================================================
--- kernel/generic/src/syscall/syscall.c	(revision a5e5030aae0508c382bae445c1cdda994d8f36e2)
+++ kernel/generic/src/syscall/syscall.c	(revision 05641a9edbf1f7a46db1517a8e99aa0ffa7bdd5d)
@@ -50,4 +50,5 @@
 #include <synch/smc.h>
 #include <ddi/ddi.h>
+#include <event/event.h>
 #include <security/cap.h>
 #include <sysinfo/sysinfo.h>
@@ -127,4 +128,7 @@
 	(syshandler_t) sys_ipc_register_irq,
 	(syshandler_t) sys_ipc_unregister_irq,
+
+	/* Event notification syscalls. */
+	(syshandler_t) sys_event_subscribe,
 	
 	/* Capabilities related syscalls. */
