Index: kernel/generic/include/adt/btree.h
===================================================================
--- kernel/generic/include/adt/btree.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/adt/btree.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -49,17 +49,23 @@
 	count_t keys;
 
-	/** Keys. We currently support only single keys. Additional room for one extra key is provided. */
+	/**
+	 * Keys. We currently support only single keys. Additional room for one
+	 * extra key is provided.
+	 */
 	btree_key_t key[BTREE_MAX_KEYS + 1];
 
 	/** 
-	 * Pointers to values. Sorted according to the key array. Defined only in leaf-level.
-	 * There is room for storing value for the extra key.
+	 * Pointers to values. Sorted according to the key array. Defined only in
+	 * leaf-level. There is room for storing value for the extra key.
 	 */
 	void *value[BTREE_MAX_KEYS + 1];
 	
 	/**
-	 * Pointers to descendants of this node sorted according to the key array.
+	 * Pointers to descendants of this node sorted according to the key
+	 * array.
+	 *
 	 * subtree[0] points to subtree with keys lesser than to key[0].
-	 * subtree[1] points to subtree with keys greater than or equal to key[0] and lesser than key[1].
+	 * subtree[1] points to subtree with keys greater than or equal to
+	 *	      key[0] and lesser than key[1].
 	 * ...
 	 * There is room for storing a subtree pointer for the extra key.
@@ -70,8 +76,10 @@
 	struct btree_node *parent;
 
-	/** Link connecting leaf-level nodes. Defined only when this node is a leaf. */
+	/**
+	 * Link connecting leaf-level nodes. Defined only when this node is a
+	 * leaf. */
 	link_t leaf_link;
 
-	/** Variables needed by btree_print(). */	
+	/* Variables needed by btree_print(). */	
 	link_t bfs_link;
 	int depth;
@@ -89,10 +97,13 @@
 extern void btree_destroy(btree_t *t);
 
-extern void btree_insert(btree_t *t, btree_key_t key, void *value, btree_node_t *leaf_node);
+extern void btree_insert(btree_t *t, btree_key_t key, void *value,
+    btree_node_t *leaf_node);
 extern void btree_remove(btree_t *t, btree_key_t key, btree_node_t *leaf_node);
 extern void *btree_search(btree_t *t, btree_key_t key, btree_node_t **leaf_node);
 
-extern btree_node_t *btree_leaf_node_left_neighbour(btree_t *t, btree_node_t *node);
-extern btree_node_t *btree_leaf_node_right_neighbour(btree_t *t, btree_node_t *node);
+extern btree_node_t *btree_leaf_node_left_neighbour(btree_t *t,
+    btree_node_t *node);
+extern btree_node_t *btree_leaf_node_right_neighbour(btree_t *t,
+    btree_node_t *node);
 
 extern void btree_print(btree_t *t);
Index: kernel/generic/include/adt/fifo.h
===================================================================
--- kernel/generic/include/adt/fifo.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/adt/fifo.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -107,5 +107,6 @@
  */
 #define fifo_push(name, value) \
-	name.fifo[name.tail = (name.tail + 1) < name.items ? (name.tail + 1) : 0] = (value) 
+	name.fifo[name.tail = \
+	    (name.tail + 1) < name.items ? (name.tail + 1) : 0] = (value)
 
 /** Allocate memory for dynamic FIFO.
Index: kernel/generic/include/adt/hash_table.h
===================================================================
--- kernel/generic/include/adt/hash_table.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/adt/hash_table.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -43,5 +43,6 @@
 	/** Hash function.
 	 *
-	 * @param key Array of keys needed to compute hash index. All keys must be passed.
+	 * @param key 	Array of keys needed to compute hash index. All keys must
+	 * 		be passed.
 	 *
 	 * @return Index into hash table.
@@ -51,5 +52,6 @@
 	/** Hash table item comparison function.
 	 *
-	 * @param key Array of keys that will be compared with item. It is not necessary to pass all keys.
+	 * @param key 	Array of keys that will be compared with item. It is not
+	 *		necessary to pass all keys.
 	 *
 	 * @return true if the keys match, false otherwise.
@@ -72,7 +74,9 @@
 } hash_table_t;
 
-#define hash_table_get_instance(item, type, member)	list_get_instance((item), type, member)
+#define hash_table_get_instance(item, type, member) \
+	list_get_instance((item), type, member)
 
-extern void hash_table_create(hash_table_t *h, count_t m, count_t max_keys, hash_table_operations_t *op);
+extern void hash_table_create(hash_table_t *h, count_t m, count_t max_keys,
+    hash_table_operations_t *op);
 extern void hash_table_insert(hash_table_t *h, unative_t key[], link_t *item);
 extern link_t *hash_table_find(hash_table_t *h, unative_t key[]);
Index: kernel/generic/include/adt/list.h
===================================================================
--- kernel/generic/include/adt/list.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/adt/list.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -48,5 +48,6 @@
  * @param name Name of the new statically allocated list.
  */
-#define LIST_INITIALIZE(name)		link_t name = { .prev = &name, .next = &name }
+#define LIST_INITIALIZE(name) \
+	link_t name = { .prev = &name, .next = &name }
 
 /** Initialize doubly-linked circular list link
@@ -108,5 +109,6 @@
  * Remove item from doubly-linked circular list.
  *
- * @param link Pointer to link_t structure to be removed from the list it is contained in.
+ * @param link 	Pointer to link_t structure to be removed from the list it is
+ * 		contained in.
  */
 static inline void list_remove(link_t *link)
@@ -136,6 +138,8 @@
  * concatenates splitted lists and splits concatenated lists.
  *
- * @param part1 Pointer to link_t structure leading the first (half of the headless) list.
- * @param part2 Pointer to link_t structure leading the second (half of the headless) list. 
+ * @param part1	Pointer to link_t structure leading the first (half of the
+ *		headless) list.
+ * @param part2	Pointer to link_t structure leading the second (half of the
+ *		headless) list. 
  */
 static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
@@ -155,6 +159,8 @@
  * Split headless doubly-linked circular list.
  *
- * @param part1 Pointer to link_t structure leading the first half of the headless list.
- * @param part2 Pointer to link_t structure leading the second half of the headless list. 
+ * @param part1	Pointer to link_t structure leading the first half of the
+ *		headless list.
+ * @param part2	Pointer to link_t structure leading the second half of the
+ *		headless list. 
  */
 static inline void headless_list_split(link_t *part1, link_t *part2)
@@ -168,5 +174,5 @@
  *
  * @param part1 Pointer to link_t structure leading the first headless list.
- * @param part2 Pointer to link_t structure leading the second headless list. 
+ * @param part2 Pointer to link_t structure leading the second headless list.
  */
 static inline void headless_list_concat(link_t *part1, link_t *part2)
@@ -175,5 +181,6 @@
 }
 
-#define list_get_instance(link,type,member) (type *)(((uint8_t*)(link))-((uint8_t*)&(((type *)NULL)->member)))
+#define list_get_instance(link,type,member) \
+	((type *)(((uint8_t *)(link)) - ((uint8_t *)&(((type *)NULL)->member))))
 
 extern bool list_member(const link_t *link, const link_t *head);
Index: kernel/generic/include/console/chardev.h
===================================================================
--- kernel/generic/include/console/chardev.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/console/chardev.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -46,8 +46,11 @@
 /* Character device operations interface. */
 typedef struct {
-	void (* suspend)(struct chardev *);		/**< Suspend pushing characters. */
-	void (* resume)(struct chardev *); 		/**< Resume pushing characters. */
-	void (* write)(struct chardev *, char c);	/**< Write character to stream. */
-	/** Read character directly from device, assume interrupts disabled */
+	/** Suspend pushing characters. */
+	void (* suspend)(struct chardev *);
+	/** Resume pushing characters. */
+	void (* resume)(struct chardev *);
+	/** Write character to stream. */
+	void (* write)(struct chardev *, char c);
+	/** Read character directly from device, assume interrupts disabled. */
 	char (* read)(struct chardev *); 
 } chardev_operations_t;
@@ -58,15 +61,16 @@
 	
 	waitq_t wq;
-	SPINLOCK_DECLARE(lock);		/**< Protects everything below. */
+	/** Protects everything below. */
+	SPINLOCK_DECLARE(lock);	
 	uint8_t buffer[CHARDEV_BUFLEN];
 	count_t counter;
-	chardev_operations_t *op;	/**< Implementation of chardev operations. */
+	/** Implementation of chardev operations. */
+	chardev_operations_t *op;
 	index_t index;
 	void *data;
 } chardev_t;
 
-extern void chardev_initialize(char *name,
-			       chardev_t *chardev, 
-			       chardev_operations_t *op);
+extern void chardev_initialize(char *name, chardev_t *chardev,
+    chardev_operations_t *op);
 extern void chardev_push_character(chardev_t *chardev, uint8_t ch);
 
Index: kernel/generic/include/console/kconsole.h
===================================================================
--- kernel/generic/include/console/kconsole.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/console/kconsole.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -46,26 +46,40 @@
 	ARG_TYPE_INT,
 	ARG_TYPE_STRING,
-	ARG_TYPE_VAR      /**< Variable type - either symbol or string */
+	/** Variable type - either symbol or string. */
+	ARG_TYPE_VAR      
 } cmd_arg_type_t;
 
 /** Structure representing one argument of kconsole command line. */
 typedef struct {
-	cmd_arg_type_t type;		/**< Type descriptor. */
-	void *buffer;			/**< Buffer where to store data. */
-	size_t len;			/**< Size of the buffer. */
-	unative_t intval;                /**< Integer value */
-	cmd_arg_type_t vartype;         /**< Resulting type of variable arg */
+	/** Type descriptor. */
+	cmd_arg_type_t type;
+	/** Buffer where to store data. */
+	void *buffer;
+	/** Size of the buffer. */
+	size_t len;
+	/** Integer value. */
+	unative_t intval;
+	/** Resulting type of variable arg */
+	cmd_arg_type_t vartype;
 } cmd_arg_t;
 
 /** Structure representing one kconsole command. */
 typedef struct {
-	link_t link;			/**< Command list link. */
-	SPINLOCK_DECLARE(lock);		/**< This lock protects everything below. */
-	const char *name;		/**< Command name. */
-	const char *description;	/**< Textual description. */
-	int (* func)(cmd_arg_t *);	/**< Function implementing the command. */
-	count_t argc;			/**< Number of arguments. */
-	cmd_arg_t *argv;		/**< Argument vector. */
-	void (* help)(void);		/**< Function for printing detailed help. */
+	/** Command list link. */
+	link_t link;
+	/** This lock protects everything below. */
+	SPINLOCK_DECLARE(lock);
+	/** Command name. */
+	const char *name;
+	/** Textual description. */
+	const char *description;
+	/** Function implementing the command. */
+	int (* func)(cmd_arg_t *);
+	/** Number of arguments. */
+	count_t argc;
+	/** Argument vector. */
+	cmd_arg_t *argv;
+	/** Function for printing detailed help. */
+	void (* help)(void);
 } cmd_info_t;
 
Index: kernel/generic/include/ddi/ddi_arg.h
===================================================================
--- kernel/generic/include/ddi/ddi_arg.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/ddi/ddi_arg.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -38,16 +38,21 @@
 /** Structure encapsulating arguments for SYS_PHYSMEM_MAP syscall. */
 typedef struct {
-	unsigned long long task_id;	/** ID of the destination task. */
-	void *phys_base;		/** Physical address of starting frame. */
-	void *virt_base;		/** Virtual address of starting page. */
-	unsigned long pages;		/** Number of pages to map. */
-	int flags;			/** Address space area flags for the mapping. */
+	/** ID of the destination task. */
+	unsigned long long task_id;
+	/** Physical address of starting frame. */
+	void *phys_base;
+	/** Virtual address of starting page. */
+	void *virt_base;
+	/** Number of pages to map. */
+	unsigned long pages;
+	/** Address space area flags for the mapping. */
+	int flags;
 } ddi_memarg_t;
 
 /** Structure encapsulating arguments for SYS_ENABLE_IOSPACE syscall. */
 typedef struct {
-	unsigned long long task_id;	/** ID of the destination task. */
-	void *ioaddr;			/** Starting I/O space address. */
-	unsigned long size;		/** Number of bytes. */
+	unsigned long long task_id;	/**< ID of the destination task. */
+	void *ioaddr;			/**< Starting I/O space address. */
+	unsigned long size;		/**< Number of bytes. */
 } ddi_ioarg_t;
 
Index: kernel/generic/include/ddi/irq.h
===================================================================
--- kernel/generic/include/ddi/irq.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/ddi/irq.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -92,19 +92,25 @@
  */
 typedef struct {
-	bool notify;			/**< When false, notifications are not sent. */
-	answerbox_t *answerbox;		/**< Answerbox for notifications. */
-	unative_t method;		/**< Method to be used for the notification. */
-	irq_code_t *code;		/**< Top-half pseudocode. */
-	count_t counter;		/**< Counter. */
-	link_t link;			/**< Link between IRQs that are notifying the
-					     same answerbox. The list is protected by
-					     the answerbox irq_lock. */
+	/** When false, notifications are not sent. */
+	bool notify;
+	/** Answerbox for notifications. */
+	answerbox_t *answerbox;
+	/** Method to be used for the notification. */
+	unative_t method;
+	/** Top-half pseudocode. */
+	irq_code_t *code;
+	/** Counter. */
+	count_t counter;
+	/**
+	 * Link between IRQs that are notifying the same answerbox. The list is
+	 * protected by the answerbox irq_lock.
+	 */
+	link_t link;
 } ipc_notif_cfg_t;
 
 /** Structure representing one device IRQ.
  *
- * If one device has multiple interrupts, there will
- * be multiple irq_t instantions with the same
- * devno.
+ * If one device has multiple interrupts, there will be multiple irq_t
+ * instantions with the same devno.
  */
 typedef struct irq {
Index: kernel/generic/include/ipc/ipc.h
===================================================================
--- kernel/generic/include/ipc/ipc.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/ipc/ipc.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -48,38 +48,47 @@
 
 /* Flags for calls */
-#define IPC_CALL_ANSWERED       (1<<0) /**< This is answer to a call */
-#define IPC_CALL_STATIC_ALLOC   (1<<1) /**< This call will not be freed on error */
-#define IPC_CALL_DISCARD_ANSWER (1<<2) /**< Answer will not be passed to userspace, will be discarded */
-#define IPC_CALL_FORWARDED      (1<<3) /**< Call was forwarded */
-#define IPC_CALL_CONN_ME_TO     (1<<4) /**< Identify connect_me_to answer */
-#define IPC_CALL_NOTIF          (1<<5) /**< Interrupt notification */
+
+/** This is answer to a call */
+#define IPC_CALL_ANSWERED	(1 << 0)
+/** This call will not be freed on error */
+#define IPC_CALL_STATIC_ALLOC	(1 << 1)
+/** Answer will not be passed to userspace, will be discarded */
+#define IPC_CALL_DISCARD_ANSWER	(1 << 2)
+/** Call was forwarded */
+#define IPC_CALL_FORWARDED	(1 << 3)
+/** Identify connect_me_to answer */
+#define IPC_CALL_CONN_ME_TO	(1 << 4)
+/** Interrupt notification */
+#define IPC_CALL_NOTIF		(1 << 5)
 
 /* Flags of callid (the addresses are aligned at least to 4, 
  * that is why we can use bottom 2 bits of the call address
  */
-#define IPC_CALLID_ANSWERED       1 /**< Type of this msg is 'answer' */
-#define IPC_CALLID_NOTIFICATION   2 /**< Type of this msg is 'notification' */
+/** Type of this msg is 'answer' */
+#define IPC_CALLID_ANSWERED	1
+/** Type of this msg is 'notification' */
+#define IPC_CALLID_NOTIFICATION	2
 
 /* Return values from IPC_ASYNC */
-#define IPC_CALLRET_FATAL         -1
-#define IPC_CALLRET_TEMPORARY     -2
+#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_METHOD(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_GET_METHOD(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_SET_RETVAL(data, retval)	((data).args[0] = (retval))
+#define IPC_SET_METHOD(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_GET_METHOD(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])
 
 /* Well known phone descriptors */
-#define PHONE_NS              0
+#define PHONE_NS	0
 
 /* System-specific methods - only through special syscalls
@@ -167,9 +176,14 @@
 
 typedef enum {
-	IPC_PHONE_FREE = 0,     /**< Phone is free and can be allocated */
-	IPC_PHONE_CONNECTING,   /**< Phone is connecting somewhere */
-	IPC_PHONE_CONNECTED,    /**< Phone is connected */
-	IPC_PHONE_HUNGUP,  	/**< Phone is hung up, waiting for answers to come */
-	IPC_PHONE_SLAMMED       /**< Phone was hungup from server */
+	/** Phone is free and can be allocated */
+	IPC_PHONE_FREE = 0,
+	/** Phone is connecting somewhere */
+	IPC_PHONE_CONNECTING,
+	/** Phone is connected */
+	IPC_PHONE_CONNECTED,
+	/** Phone is hung up, waiting for answers to come */
+	IPC_PHONE_HUNGUP,
+	/** Phone was hungup from server */
+	IPC_PHONE_SLAMMED
 } ipc_phone_state_t;
 
@@ -190,13 +204,18 @@
 	waitq_t wq;
 
-	link_t connected_phones;	/**< Phones connected to this answerbox */
-	link_t calls;			/**< Received calls */
+	/** Phones connected to this answerbox */
+	link_t connected_phones;
+	/** Received calls */
+	link_t calls;			
 	link_t dispatched_calls;	/* Should be hash table in the future */
 
-	link_t answers;			/**< Answered calls */
+	/** Answered calls */
+	link_t answers;
 
 	SPINLOCK_DECLARE(irq_lock);
-	link_t irq_notifs;       	/**< Notifications from IRQ handlers */
-	link_t irq_head;		/**< IRQs with notifications to this answerbox. */
+	/** Notifications from IRQ handlers */
+	link_t irq_notifs;
+	/** IRQs with notifications to this answerbox. */
+	link_t irq_head;
 } answerbox_t;
 
@@ -218,7 +237,9 @@
 	answerbox_t *callerbox;
 
-	unative_t priv; /**< Private data to internal IPC */
-
-	ipc_data_t data;  /**< Data passed from/to userspace */
+	/** Private data to internal IPC */
+	unative_t priv;
+
+	/** Data passed from/to userspace */
+	ipc_data_t data;
 } call_t;
 
Index: kernel/generic/include/ipc/irq.h
===================================================================
--- kernel/generic/include/ipc/irq.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/ipc/irq.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -44,6 +44,6 @@
 #include <adt/list.h>
 
-extern int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno, unative_t method,
-	irq_code_t *ucode);
+extern int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno,
+    unative_t method, irq_code_t *ucode);
 extern void ipc_irq_send_notif(irq_t *irq);
 extern void ipc_irq_send_msg(irq_t *irq, unative_t a1, unative_t a2, unative_t a3);
Index: kernel/generic/include/ipc/sysipc.h
===================================================================
--- kernel/generic/include/ipc/sysipc.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/ipc/sysipc.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -41,18 +41,20 @@
 
 unative_t sys_ipc_call_sync_fast(unative_t phoneid, unative_t method, 
-				unative_t arg1, ipc_data_t *data);
-unative_t sys_ipc_call_sync(unative_t phoneid, ipc_data_t *question, 
-			   ipc_data_t *reply);
+    unative_t arg1, ipc_data_t *data);
+unative_t sys_ipc_call_sync(unative_t phoneid, ipc_data_t *question,
+    ipc_data_t *reply);
 unative_t sys_ipc_call_async_fast(unative_t phoneid, unative_t method, 
-				 unative_t arg1, unative_t arg2);
+    unative_t arg1, unative_t arg2);
 unative_t sys_ipc_call_async(unative_t phoneid, ipc_data_t *data);
 unative_t sys_ipc_answer_fast(unative_t callid, unative_t retval, 
-			     unative_t arg1, unative_t arg2);
+    unative_t arg1, unative_t arg2);
 unative_t sys_ipc_answer(unative_t callid, ipc_data_t *data);
-unative_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec, int nonblocking);
+unative_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec,
+    int nonblocking);
 unative_t sys_ipc_forward_fast(unative_t callid, unative_t phoneid,
-			      unative_t method, unative_t arg1);
+    unative_t method, unative_t arg1);
 unative_t sys_ipc_hangup(int phoneid);
-unative_t sys_ipc_register_irq(inr_t inr, devno_t devno, unative_t method, irq_code_t *ucode);
+unative_t sys_ipc_register_irq(inr_t inr, devno_t devno, unative_t method,
+    irq_code_t *ucode);
 unative_t sys_ipc_unregister_irq(inr_t inr, devno_t devno);
 
Index: kernel/generic/include/mm/as.h
===================================================================
--- kernel/generic/include/mm/as.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/mm/as.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -54,5 +54,8 @@
 #include <lib/elf.h>
 
-/** Defined to be true if user address space and kernel address space shadow each other. */
+/**
+ * Defined to be true if user address space and kernel address space shadow each
+ * other.
+ */
 #define KERNEL_ADDRESS_SPACE_SHADOWED	KERNEL_ADDRESS_SPACE_SHADOWED_ARCH
 
@@ -62,15 +65,54 @@
 #define USER_ADDRESS_SPACE_END		USER_ADDRESS_SPACE_END_ARCH
 
-#define USTACK_ADDRESS	USTACK_ADDRESS_ARCH
-
-#define FLAG_AS_KERNEL	    (1 << 0)	/**< Kernel address space. */
-
-/** Address space area attributes. */
+#define USTACK_ADDRESS			USTACK_ADDRESS_ARCH
+
+/** Kernel address space. */
+#define FLAG_AS_KERNEL			(1 << 0)	
+
+/* Address space area attributes. */
 #define AS_AREA_ATTR_NONE	0
 #define AS_AREA_ATTR_PARTIAL	1	/**< Not fully initialized area. */
 
-#define AS_PF_FAULT		0	/**< The page fault was not resolved by as_page_fault(). */
-#define AS_PF_OK		1	/**< The page fault was resolved by as_page_fault(). */
-#define AS_PF_DEFER		2	/**< The page fault was caused by memcpy_from_uspace() or memcpy_to_uspace(). */
+/** The page fault was not resolved by as_page_fault(). */
+#define AS_PF_FAULT		0
+/** The page fault was resolved by as_page_fault(). */
+#define AS_PF_OK		1
+/** The page fault was caused by memcpy_from_uspace() or memcpy_to_uspace(). */
+#define AS_PF_DEFER		2
+
+/** Address space structure.
+ *
+ * as_t contains the list of as_areas of userspace accessible
+ * pages for one or more tasks. Ranges of kernel memory pages are not
+ * supposed to figure in the list as they are shared by all tasks and
+ * set up during system initialization.
+ */
+typedef struct as {
+	/** Protected by asidlock. */
+	link_t inactive_as_with_asid_link;
+
+	mutex_t lock;
+
+	/** Number of references (i.e tasks that reference this as). */
+	count_t refcount;
+
+	/** Number of processors on wich is this address space active. */
+	count_t cpu_refcount;
+
+	/** B+tree of address space areas. */
+	btree_t as_area_btree;
+	
+	/**
+	 *  Address space identifier.
+	 *  Constant on architectures that do not support ASIDs.
+	 */
+	asid_t asid;
+	
+	/** Non-generic content. */
+	as_genarch_t genarch;
+
+	/** Architecture specific content. */
+	as_arch_t arch;
+} as_t;
 
 typedef struct {
@@ -81,9 +123,17 @@
 } as_operations_t;
 
-/** This structure contains information associated with the shared address space area. */
+/**
+ * This structure contains information associated with the shared address space
+ * area.
+ */
 typedef struct {
-	mutex_t lock;		/**< This lock must be acquired only when the as_area lock is held. */
-	count_t refcount;	/**< This structure can be deallocated if refcount drops to 0. */
-	btree_t pagemap;	/**< B+tree containing complete map of anonymous pages of the shared area. */
+	/** This lock must be acquired only when the as_area lock is held. */
+	mutex_t lock;		
+	/** This structure can be deallocated if refcount drops to 0. */
+	count_t refcount;
+	/**
+	 * B+tree containing complete map of anonymous pages of the shared area.
+	 */
+	btree_t pagemap;
 } share_info_t;
 
@@ -116,13 +166,25 @@
 typedef struct {
 	mutex_t lock;
-	as_t *as;		/**< Containing address space. */
-	int flags;		/**< Flags related to the memory represented by the address space area. */
-	int attributes;		/**< Attributes related to the address space area itself. */
-	count_t pages;		/**< Size of this area in multiples of PAGE_SIZE. */
-	uintptr_t base;		/**< Base address of this area. */
-	btree_t used_space;	/**< Map of used space. */
-	share_info_t *sh_info;	/**< If the address space area has been shared, this pointer will
-			     	     reference the share info structure. */
-	struct mem_backend *backend;	/**< Memory backend backing this address space area. */
+	/** Containing address space. */
+	as_t *as;		
+	/** Flags related to the memory represented by the address space area. */
+	int flags;
+	/** Attributes related to the address space area itself. */
+	int attributes;
+	/** Size of this area in multiples of PAGE_SIZE. */
+	count_t pages;
+	/** Base address of this area. */
+	uintptr_t base;
+	/** Map of used space. */
+	btree_t used_space;
+
+	/**
+	 * If the address space area has been shared, this pointer will reference
+	 * the share info structure.
+	 */
+	share_info_t *sh_info;
+
+	/** Memory backend backing this address space area. */
+	struct mem_backend *backend;
 
 	/** Data to be used by the backend. */
@@ -147,13 +209,14 @@
 extern as_t *as_create(int flags);
 extern void as_destroy(as_t *as);
-extern void as_switch(as_t *old, as_t *replace);
+extern void as_switch(as_t *old_as, as_t *new_as);
 extern int as_page_fault(uintptr_t page, pf_access_t access, istate_t *istate);
 
-extern as_area_t *as_area_create(as_t *as, int flags, size_t size, uintptr_t base, int attrs,
-	mem_backend_t *backend, mem_backend_data_t *backend_data);
+extern as_area_t *as_area_create(as_t *as, int flags, size_t size,
+    uintptr_t base, int attrs, mem_backend_t *backend,
+    mem_backend_data_t *backend_data);
 extern int as_area_destroy(as_t *as, uintptr_t address);	
 extern int as_area_resize(as_t *as, uintptr_t address, size_t size, int flags);
 int as_area_share(as_t *src_as, uintptr_t src_base, size_t acc_size,
-		  as_t *dst_as, uintptr_t dst_base, int dst_flags_mask);
+    as_t *dst_as, uintptr_t dst_base, int dst_flags_mask);
 
 extern int as_area_get_flags(as_area_t *area);
Index: kernel/generic/include/mm/buddy.h
===================================================================
--- kernel/generic/include/mm/buddy.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/mm/buddy.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -45,9 +45,13 @@
 /** Buddy system operations to be implemented by each implementation. */
 typedef struct {
-	/** Return pointer to left-side or right-side buddy for block passed as
-	  * argument. */
+	/**
+	 * Return pointer to left-side or right-side buddy for block passed as
+	 * argument.
+	 */
 	link_t *(* find_buddy)(struct buddy_system *, link_t *);
-	/** Bisect the block passed as argument and return pointer to the new
-	  * right-side buddy. */
+	/**
+	 * Bisect the block passed as argument and return pointer to the new
+	 * right-side buddy.
+	 */
 	link_t *(* bisect)(struct buddy_system *, link_t *);
 	/** Coalesce two buddies into a bigger block. */
@@ -76,5 +80,5 @@
 
 extern void buddy_system_create(buddy_system_t *b, uint8_t max_order,
-	buddy_system_operations_t *op, void *data);
+    buddy_system_operations_t *op, void *data);
 extern link_t *buddy_system_alloc(buddy_system_t *b, uint8_t i);
 extern bool buddy_system_can_alloc(buddy_system_t *b, uint8_t order);
Index: kernel/generic/include/mm/mm.h
===================================================================
--- kernel/generic/include/mm/mm.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/mm/mm.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -47,18 +47,18 @@
 #define PAGE_GLOBAL_SHIFT		6
 
-#define PAGE_NOT_CACHEABLE	(0 << PAGE_CACHEABLE_SHIFT)
-#define PAGE_CACHEABLE		(1 << PAGE_CACHEABLE_SHIFT)
+#define PAGE_NOT_CACHEABLE		(0 << PAGE_CACHEABLE_SHIFT)
+#define PAGE_CACHEABLE			(1 << PAGE_CACHEABLE_SHIFT)
 
-#define PAGE_PRESENT		(0 << PAGE_PRESENT_SHIFT)
-#define PAGE_NOT_PRESENT	(1 << PAGE_PRESENT_SHIFT)
+#define PAGE_PRESENT			(0 << PAGE_PRESENT_SHIFT)
+#define PAGE_NOT_PRESENT		(1 << PAGE_PRESENT_SHIFT)
 
-#define PAGE_USER		(1 << PAGE_USER_SHIFT)
-#define PAGE_KERNEL		(0 << PAGE_USER_SHIFT)
+#define PAGE_USER			(1 << PAGE_USER_SHIFT)
+#define PAGE_KERNEL			(0 << PAGE_USER_SHIFT)
 
-#define PAGE_READ		(1 << PAGE_READ_SHIFT)
-#define PAGE_WRITE		(1 << PAGE_WRITE_SHIFT)
-#define PAGE_EXEC		(1 << PAGE_EXEC_SHIFT)
+#define PAGE_READ			(1 << PAGE_READ_SHIFT)
+#define PAGE_WRITE			(1 << PAGE_WRITE_SHIFT)
+#define PAGE_EXEC			(1 << PAGE_EXEC_SHIFT)
 
-#define PAGE_GLOBAL		(1 << PAGE_GLOBAL_SHIFT)
+#define PAGE_GLOBAL			(1 << PAGE_GLOBAL_SHIFT)
 
 #endif
Index: kernel/generic/include/mm/page.h
===================================================================
--- kernel/generic/include/mm/page.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/mm/page.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -59,5 +59,5 @@
 extern void page_table_unlock(as_t *as, bool unlock);
 extern void page_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame,
-	int flags);
+    int flags);
 extern void page_mapping_remove(as_t *as, uintptr_t page);
 extern pte_t *page_mapping_find(as_t *as, uintptr_t page);
Index: kernel/generic/include/mm/slab.h
===================================================================
--- kernel/generic/include/mm/slab.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/mm/slab.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -57,10 +57,16 @@
 
 /* slab_reclaim constants */
-#define SLAB_RECLAIM_ALL  0x1 /**< Reclaim all possible memory, because we are in memory stress */
+
+/** Reclaim all possible memory, because we are in memory stress */
+#define SLAB_RECLAIM_ALL  0x1 
 
 /* cache_create flags */
-#define SLAB_CACHE_NOMAGAZINE 0x1 /**< Do not use per-cpu cache */
-#define SLAB_CACHE_SLINSIDE   0x2 /**< Have control structure inside SLAB */
-#define SLAB_CACHE_MAGDEFERRED (0x4 | SLAB_CACHE_NOMAGAZINE) /**< We add magazine cache later, if we have this flag */
+
+/** Do not use per-cpu cache */
+#define SLAB_CACHE_NOMAGAZINE 0x1
+/** Have control structure inside SLAB */
+#define SLAB_CACHE_SLINSIDE   0x2
+/** We add magazine cache later, if we have this flag */
+#define SLAB_CACHE_MAGDEFERRED (0x4 | SLAB_CACHE_NOMAGAZINE)
 
 typedef struct {
@@ -82,9 +88,14 @@
 
 	link_t link;
+
 	/* Configuration */
-	size_t size;		/**< Size of slab position - align_up(sizeof(obj)) */
+	/** Size of slab position - align_up(sizeof(obj)) */
+	size_t size;
+
 	int (*constructor)(void *obj, int kmflag);
 	int (*destructor)(void *obj);
-	int flags;		/**< Flags changing behaviour of cache */
+
+	/** Flags changing behaviour of cache */
+	int flags;
 
 	/* Computed values */
@@ -96,5 +107,6 @@
 	atomic_t allocated_objs;
 	atomic_t cached_objs;
-	atomic_t magazine_counter; /**< How many magazines in magazines list */
+	/** How many magazines in magazines list */
+	atomic_t magazine_counter; 
 
 	/* Slabs */
@@ -110,10 +122,7 @@
 } slab_cache_t;
 
-extern slab_cache_t * slab_cache_create(char *name,
-					size_t size,
-					size_t align,
-					int (*constructor)(void *obj, int kmflag),
-					int (*destructor)(void *obj),
-					int flags);
+extern slab_cache_t * slab_cache_create(char *name, size_t size, size_t align,
+    int (*constructor)(void *obj, int kmflag), int (*destructor)(void *obj),
+    int flags);
 extern void slab_cache_destroy(slab_cache_t *cache);
 
@@ -122,5 +131,5 @@
 extern count_t slab_reclaim(int flags);
 
-/** Initialize slab subsytem */
+/* slab subsytem initialization */
 extern void slab_cache_init(void);
 extern void slab_enable_cpucache(void);
Index: kernel/generic/include/mm/tlb.h
===================================================================
--- kernel/generic/include/mm/tlb.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/mm/tlb.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -40,6 +40,6 @@
 
 /**
- * Number of TLB shootdown messages that can be queued in processor
- * tlb_messages queue.
+ * Number of TLB shootdown messages that can be queued in processor tlb_messages
+ * queue.
  */
 #define TLB_MESSAGE_QUEUE_LEN	10
@@ -47,8 +47,12 @@
 /** Type of TLB shootdown message. */
 typedef enum {
-	TLB_INVL_INVALID = 0,		/**< Invalid type. */
-	TLB_INVL_ALL,			/**< Invalidate all entries in TLB. */
-	TLB_INVL_ASID,			/**< Invalidate all entries belonging to one address space. */
-	TLB_INVL_PAGES			/**< Invalidate specified page range belonging to one address space. */
+	/** Invalid type. */
+	TLB_INVL_INVALID = 0,
+	/** Invalidate all entries in TLB. */
+	TLB_INVL_ALL,
+	/** Invalidate all entries belonging to one address space. */
+	TLB_INVL_ASID,
+	/** Invalidate specified page range belonging to one address space. */
+	TLB_INVL_PAGES
 } tlb_invalidate_type_t;
 
@@ -64,11 +68,12 @@
 
 #ifdef CONFIG_SMP
-extern void tlb_shootdown_start(tlb_invalidate_type_t type, asid_t asid, uintptr_t page, count_t count);
+extern void tlb_shootdown_start(tlb_invalidate_type_t type, asid_t asid,
+    uintptr_t page, count_t count);
 extern void tlb_shootdown_finalize(void);
 extern void tlb_shootdown_ipi_recv(void);
 #else
-#  define tlb_shootdown_start(w, x, y, z)
-#  define tlb_shootdown_finalize()
-#  define tlb_shootdown_ipi_recv()
+#define tlb_shootdown_start(w, x, y, z)
+#define tlb_shootdown_finalize()
+#define tlb_shootdown_ipi_recv()
 #endif /* CONFIG_SMP */
 
Index: kernel/generic/include/proc/task.h
===================================================================
--- kernel/generic/include/proc/task.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/proc/task.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -59,30 +59,40 @@
 	/** Task lock.
 	 *
-	 * Must be acquired before threads_lock and thread lock of any of its threads.
+	 * Must be acquired before threads_lock and thread lock of any of its
+	 * threads.
 	 */
 	SPINLOCK_DECLARE(lock);
 	
 	char *name;
-	struct thread *main_thread;	/**< Pointer to the main thread. */
-	link_t th_head;		/**< List of threads contained in this task. */
-	as_t *as;		/**< Address space. */
-	task_id_t taskid;	/**< Unique identity of task */
-	context_id_t context;	/**< Task security context */
+	/** Pointer to the main thread. */
+	struct thread *main_thread;
+	/** List of threads contained in this task. */
+	link_t th_head;
+	/** Address space. */
+	as_t *as;
+	/** Unique identity of task. */
+	task_id_t taskid;
+	/** Task security context. */
+	context_id_t context;	
 
 	/** If this is true, new threads can become part of the task. */
 	bool accept_new_threads;
+	/** Number of references (i.e. threads). */
+	count_t refcount;	
 
-	count_t refcount;	/**< Number of references (i.e. threads). */
-
-	cap_t capabilities;	/**< Task capabilities. */
+	/** Task capabilities. */
+	cap_t capabilities;	
 
 	/* IPC stuff */
 	answerbox_t answerbox;  /**< Communication endpoint */
 	phone_t phones[IPC_MAX_PHONES];
-	atomic_t active_calls;  /**< Active asynchronous messages.
-				 *   It is used for limiting uspace to
-				 *   certain extent. */
+	/**
+	 * Active asynchronous messages. It is used for limiting uspace to
+	 * certain extent.
+	 */
+	atomic_t active_calls;  
 	
-	task_arch_t arch;	/**< Architecture specific task data. */
+	/** Architecture specific task data. */
+	task_arch_t arch;	
 	
 	/**
@@ -91,7 +101,9 @@
 	 */
 	mutex_t futexes_lock;
-	btree_t futexes;	/**< B+tree of futexes referenced by this task. */
+	/** B+tree of futexes referenced by this task. */
+	btree_t futexes;	
 	
-	uint64_t cycles;	/**< Accumulated accounting. */
+	/** Accumulated accounting. */
+	uint64_t cycles;
 } task_t;
 
Index: kernel/generic/include/proc/thread.h
===================================================================
--- kernel/generic/include/proc/thread.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/proc/thread.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -53,17 +53,28 @@
 
 /* Thread flags */
-#define THREAD_FLAG_WIRED	(1 << 0)	/**< Thread cannot be migrated to another CPU. */
-#define THREAD_FLAG_STOLEN	(1 << 1)	/**< Thread was migrated to another CPU and has not run yet. */
-#define THREAD_FLAG_USPACE	(1 << 2)	/**< Thread executes in userspace. */
+
+/** Thread cannot be migrated to another CPU. */
+#define THREAD_FLAG_WIRED	(1 << 0)
+/** Thread was migrated to another CPU and has not run yet. */
+#define THREAD_FLAG_STOLEN	(1 << 1)
+/** Thread executes in userspace. */
+#define THREAD_FLAG_USPACE	(1 << 2)
 
 /** Thread states. */
 typedef enum {
-	Invalid,	/**< It is an error, if thread is found in this state. */
-	Running,	/**< State of a thread that is currently executing on some CPU. */
-	Sleeping,	/**< Thread in this state is waiting for an event. */
-	Ready,		/**< State of threads in a run queue. */
-	Entering,	/**< Threads are in this state before they are first readied. */
-	Exiting,	/**< After a thread calls thread_exit(), it is put into Exiting state. */
-	Undead		/**< Threads that were not detached but exited are in the Undead state. */
+	/** 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 in the Undead state. */
+	Undead
 } state_t;
 
@@ -77,7 +88,7 @@
 /** Thread structure. There is one per thread. */
 typedef struct thread {
-	link_t rq_link;				/**< Run queue link. */
-	link_t wq_link;				/**< Wait queue link. */
-	link_t th_link;				/**< Links to threads within containing task. */
+	link_t rq_link;		/**< Run queue link. */
+	link_t wq_link;		/**< Wait queue link. */
+	link_t th_link;		/**< Links to threads within containing task. */
 	
 	/** Lock protecting thread structure.
@@ -89,33 +100,57 @@
 	char name[THREAD_NAME_BUFLEN];
 
-	void (* thread_code)(void *);		/**< Function implementing the thread. */
-	void *thread_arg;			/**< Argument passed to thread_code() function. */
-
-	/** From here, the stored context is restored when the thread is scheduled. */
+	/** Function implementing the thread. */
+	void (* thread_code)(void *);
+	/** Argument passed to thread_code() function. */
+	void *thread_arg;
+
+	/**
+	 * From here, the stored context is restored when the thread is
+	 * scheduled.
+	 */
 	context_t saved_context;
-	/** From here, the stored timeout context is restored when sleep times out. */
+	/**
+	 * From here, the stored timeout context is restored when sleep times
+	 * out.
+	 */
 	context_t sleep_timeout_context;
-	/** From here, the stored interruption context is restored when sleep is interrupted. */
+	/**
+	 * From here, the stored interruption context is restored when sleep is
+	 * interrupted.
+	 */
 	context_t sleep_interruption_context;
 
-	bool sleep_interruptible;		/**< If true, the thread can be interrupted from sleep. */
-	waitq_t *sleep_queue;			/**< Wait queue in which this thread sleeps. */
-	timeout_t sleep_timeout;		/**< Timeout used for timeoutable sleeping.  */
-	volatile int timeout_pending;		/**< Flag signalling sleep timeout in progress. */
-
-	/** True if this thread is executing copy_from_uspace(). False otherwise. */
+	/** If true, the thread can be interrupted from sleep. */
+	bool sleep_interruptible;
+	/** Wait queue in which this thread sleeps. */
+	waitq_t *sleep_queue;
+	/** Timeout used for timeoutable sleeping.  */
+	timeout_t sleep_timeout;
+	/** Flag signalling sleep timeout in progress. */
+	volatile int timeout_pending;
+
+	/**
+	 * True if this thread is executing copy_from_uspace().
+	 * False otherwise.
+	 */
 	bool in_copy_from_uspace;
-	/** True if this thread is executing copy_to_uspace(). False otherwise. */
+	/**
+	 * True if this thread is executing copy_to_uspace().
+	 * False otherwise.
+	 */
 	bool in_copy_to_uspace;
 	
 	/**
-	 * If true, the thread will not go to sleep at all and will
-	 * call thread_exit() before returning to userspace.
+	 * If true, the thread will not go to sleep at all and will call
+	 * thread_exit() before returning to userspace.
 	 */
 	bool interrupted;			
 	
-	thread_join_type_t	join_type;	/**< Who joinins the thread. */
-	bool detached;				/**< If true, thread_join_timeout() cannot be used on this thread. */
-	waitq_t join_wq;			/**< Waitq for thread_join_timeout(). */
+	/** Who joinins the thread. */
+	thread_join_type_t join_type;
+	/** If true, thread_join_timeout() cannot be used on this thread. */
+	bool detached;
+	/** Waitq for thread_join_timeout(). */
+	waitq_t join_wq;
 
 	fpu_context_t *saved_fpu_context;
@@ -124,6 +159,6 @@
 	/*
 	 * Defined only if thread doesn't run.
-	 * It means that fpu context is in CPU that last time executes this thread.
-	 * This disables migration.
+	 * It means that fpu context is in CPU that last time executes this
+	 * thread. This disables migration.
 	 */
 	int fpu_context_engaged;
@@ -131,25 +166,39 @@
 	rwlock_type_t rwlock_holder_type;
 
-	void (* call_me)(void *);		/**< Funtion to be called in scheduler before the thread is put asleep. */
-	void *call_me_with;			/**< Argument passed to call_me(). */
-
-	state_t state;				/**< Thread's state. */
-	int flags;				/**< Thread's flags. */
-	
-	cpu_t *cpu;				/**< Thread's CPU. */
-	task_t *task;				/**< Containing task. */
-
-	uint64_t ticks;				/**< Ticks before preemption. */
-	
-	uint64_t cycles;			/**< Thread accounting. */
-	uint64_t last_cycle;		/**< Last sampled cycle. */
-	bool uncounted;				/**< Thread doesn't affect accumulated accounting. */
-
-	int priority;				/**< Thread's priority. Implemented as index to CPU->rq */
-	uint32_t tid;				/**< Thread ID. */
-	
-	thread_arch_t arch;			/**< Architecture-specific data. */
-
-	uint8_t *kstack;			/**< Thread's kernel stack. */
+	/** Callback fired in scheduler before the thread is put asleep. */
+	void (* call_me)(void *);
+	/** Argument passed to call_me(). */
+	void *call_me_with;
+
+	/** Thread's state. */
+	state_t state;
+	/** Thread's flags. */
+	int flags;
+	
+	/** Thread's CPU. */
+	cpu_t *cpu;
+	/** Containing task. */
+	task_t *task;
+
+	/** Ticks before preemption. */
+	uint64_t ticks;
+	
+	/** Thread accounting. */
+	uint64_t cycles;
+	/** Last sampled cycle. */
+	uint64_t last_cycle;
+	/** Thread doesn't affect accumulated accounting. */	
+	bool uncounted;
+
+	/** Thread's priority. Implemented as index to CPU->rq */
+	int priority;
+	/** Thread ID. */
+	uint32_t tid;
+	
+	/** Architecture-specific data. */
+	thread_arch_t arch;
+
+	/** Thread's kernel stack. */
+	uint8_t *kstack;
 } thread_t;
 
@@ -162,8 +211,10 @@
 SPINLOCK_EXTERN(threads_lock);
 
-extern btree_t threads_btree;			/**< B+tree containing all threads. */
+/** B+tree containing all threads. */
+extern btree_t threads_btree;
 
 extern void thread_init(void);
-extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags, char *name, bool uncounted);
+extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task,
+    int flags, char *name, bool uncounted);
 extern void thread_ready(thread_t *t);
 extern void thread_exit(void) __attribute__((noreturn));
@@ -182,9 +233,11 @@
 extern void thread_usleep(uint32_t usec);
 
-#define thread_join(t)	thread_join_timeout((t), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
+#define thread_join(t) \
+	thread_join_timeout((t), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
 extern int thread_join_timeout(thread_t *t, uint32_t usec, int flags);
 extern void thread_detach(thread_t *t);
 
-extern void thread_register_call_me(void (* call_me)(void *), void *call_me_with);
+extern void thread_register_call_me(void (* call_me)(void *),
+    void *call_me_with);
 extern void thread_print_list(void);
 extern void thread_destroy(thread_t *t);
@@ -193,8 +246,8 @@
 extern void thread_interrupt_sleep(thread_t *t);
 
-/* Fpu context slab cache */
+/** Fpu context slab cache. */
 extern slab_cache_t *fpu_context_slab;
 
-/** Thread syscall prototypes. */
+/* Thread syscall prototypes. */
 unative_t sys_thread_create(uspace_arg_t *uspace_uarg, char *uspace_name);
 unative_t sys_thread_exit(int uspace_status);
Index: kernel/generic/include/synch/condvar.h
===================================================================
--- kernel/generic/include/synch/condvar.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/synch/condvar.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -45,13 +45,14 @@
 } condvar_t;
 
-#define condvar_wait(cv,mtx) \
-	_condvar_wait_timeout((cv),(mtx),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
-#define condvar_wait_timeout(cv,mtx,usec) \
-	_condvar_wait_timeout((cv),(mtx),(usec),SYNCH_FLAGS_NONE)
+#define condvar_wait(cv, mtx) \
+	_condvar_wait_timeout((cv), (mtx), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
+#define condvar_wait_timeout(cv, mtx, usec) \
+	_condvar_wait_timeout((cv), (mtx), (usec), SYNCH_FLAGS_NONE)
 
 extern void condvar_initialize(condvar_t *cv);
 extern void condvar_signal(condvar_t *cv);
 extern void condvar_broadcast(condvar_t *cv);
-extern int _condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, uint32_t usec, int flags);
+extern int _condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, uint32_t usec,
+    int flags);
 
 #endif
Index: kernel/generic/include/synch/futex.h
===================================================================
--- kernel/generic/include/synch/futex.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/synch/futex.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -43,12 +43,17 @@
 /** Kernel-side futex structure. */
 typedef struct {
-	uintptr_t paddr;	/**< Physical address of the status variable. */
-	waitq_t wq;		/**< Wait queue for threads waiting for futex availability. */
-	link_t ht_link;		/**< Futex hash table link. */
-	count_t refcount;	/**< Number of tasks that reference this futex. */
+	/** Physical address of the status variable. */
+	uintptr_t paddr;
+	/** Wait queue for threads waiting for futex availability. */
+	waitq_t wq;
+	/** Futex hash table link. */
+	link_t ht_link;
+	/** Number of tasks that reference this futex. */
+	count_t refcount;
 } futex_t;
 
 extern void futex_init(void);
-extern unative_t sys_futex_sleep_timeout(uintptr_t uaddr, uint32_t usec, int flags);
+extern unative_t sys_futex_sleep_timeout(uintptr_t uaddr, uint32_t usec,
+    int flags);
 extern unative_t sys_futex_wakeup(uintptr_t uaddr);
 
Index: kernel/generic/include/synch/rwlock.h
===================================================================
--- kernel/generic/include/synch/rwlock.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/synch/rwlock.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -49,20 +49,26 @@
 typedef struct {
 	SPINLOCK_DECLARE(lock);
-	mutex_t exclusive;	/**< Mutex for writers, readers can bypass it if readers_in is positive. */
-	count_t readers_in;	/**< Number of readers in critical section. */
+	/**
+	 * Mutex for writers, readers can bypass it if readers_in is positive.
+	 */
+	mutex_t exclusive;
+	/** Number of readers in critical section. */
+	count_t readers_in;
 } rwlock_t;
 
 #define rwlock_write_lock(rwl) \
-	_rwlock_write_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
+	_rwlock_write_lock_timeout((rwl), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
 #define rwlock_read_lock(rwl) \
-	_rwlock_read_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
+	_rwlock_read_lock_timeout((rwl), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
 #define rwlock_write_trylock(rwl) \
-	_rwlock_write_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NON_BLOCKING)
+	_rwlock_write_lock_timeout((rwl), SYNCH_NO_TIMEOUT, \
+	    SYNCH_FLAGS_NON_BLOCKING)
 #define rwlock_read_trylock(rwl) \
-	_rwlock_read_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NON_BLOCKING)
-#define rwlock_write_lock_timeout(rwl,usec) \
-	_rwlock_write_lock_timeout((rwl),(usec),SYNCH_FLAGS_NONE)
-#define rwlock_read_lock_timeout(rwl,usec) \
-	_rwlock_read_lock_timeout((rwl),(usec),SYNCH_FLAGS_NONE)
+	_rwlock_read_lock_timeout((rwl), SYNCH_NO_TIMEOUT, \
+	    SYNCH_FLAGS_NON_BLOCKING)
+#define rwlock_write_lock_timeout(rwl, usec) \
+	_rwlock_write_lock_timeout((rwl), (usec), SYNCH_FLAGS_NONE)
+#define rwlock_read_lock_timeout(rwl, usec) \
+	_rwlock_read_lock_timeout((rwl), (usec), SYNCH_FLAGS_NONE)
 
 extern void rwlock_initialize(rwlock_t *rwl);
Index: kernel/generic/include/synch/semaphore.h
===================================================================
--- kernel/generic/include/synch/semaphore.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/synch/semaphore.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -47,5 +47,5 @@
 	_semaphore_down_timeout((s), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
 #define semaphore_trydown(s) \
-	_semaphore_down_timeout((s), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING)	
+	_semaphore_down_timeout((s), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING)
 #define semaphore_down_timeout(s, usec) \
 	_semaphore_down_timeout((s), (usec), SYNCH_FLAGS_NONE)
Index: kernel/generic/include/synch/synch.h
===================================================================
--- kernel/generic/include/synch/synch.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/synch/synch.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -36,18 +36,29 @@
 #define KERN_SYNCH_H_
 
-#define SYNCH_NO_TIMEOUT	0	/**< Request with no timeout. */
+/** Request with no timeout. */
+#define SYNCH_NO_TIMEOUT	0
 
-#define SYNCH_FLAGS_NONE		0	/**< No flags specified. */
-#define SYNCH_FLAGS_NON_BLOCKING	(1<<0)	/**< Non-blocking operation request. */
-#define SYNCH_FLAGS_INTERRUPTIBLE	(1<<1)	/**< Interruptible operation. */
+/** 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)
 
-#define ESYNCH_WOULD_BLOCK	1	/**< Could not satisfy the request without going to sleep. */
-#define ESYNCH_TIMEOUT		2	/**< Timeout occurred. */
-#define ESYNCH_INTERRUPTED	4	/**< Sleep was interrupted. */
-#define ESYNCH_OK_ATOMIC	8	/**< Operation succeeded without sleeping. */
-#define ESYNCH_OK_BLOCKED	16	/**< Operation succeeded and did sleep. */
+/** 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))
+#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 fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/synch/waitq.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -53,6 +53,10 @@
 	SPINLOCK_DECLARE(lock);
 
-	int missed_wakeups;	/**< Number of waitq_wakeup() calls that didn't find a thread to wake up. */
-	link_t head;		/**< List of sleeping threads for wich there was no missed_wakeup. */
+	/**
+	 * Number of waitq_wakeup() calls that didn't find a thread to wake up.
+	 */
+	int missed_wakeups;
+	/** List of sleeping threads for wich there was no missed_wakeup. */
+	link_t head;
 } waitq_t;
 
Index: kernel/generic/include/time/timeout.h
===================================================================
--- kernel/generic/include/time/timeout.h	(revision fa8e7d2eafc95dcfd4435b0ca55cbfb76b7b11b5)
+++ kernel/generic/include/time/timeout.h	(revision 80bcaed11c2e767559657092d6c13d1a7fdd449c)
@@ -45,12 +45,14 @@
 	SPINLOCK_DECLARE(lock);
 
-	link_t link;			/**< Link to the list of active timeouts on THE->cpu */
-	
-	uint64_t ticks;			/**< Timeout will be activated in this amount of clock() ticks. */
-
-	timeout_handler_t handler;	/**< Function that will be called on timeout activation. */
-	void *arg;			/**< Argument to be passed to handler() function. */
-	
-	cpu_t *cpu;			/**< On which processor is this timeout registered. */
+	/** Link to the list of active timeouts on THE->cpu */
+	link_t link;
+	/** Timeout will be activated in this amount of clock() ticks. */	
+	uint64_t ticks;
+	/** Function that will be called on timeout activation. */
+	timeout_handler_t handler;
+	/** Argument to be passed to handler() function. */
+	void *arg;
+	/** On which processor is this timeout registered. */
+	cpu_t *cpu;
 } timeout_t;
 
@@ -60,5 +62,6 @@
 extern void timeout_initialize(timeout_t *t);
 extern void timeout_reinitialize(timeout_t *t);
-extern void timeout_register(timeout_t *t, uint64_t usec, timeout_handler_t f, void *arg);
+extern void timeout_register(timeout_t *t, uint64_t usec, timeout_handler_t f,
+    void *arg);
 extern bool timeout_unregister(timeout_t *t);
 
