Index: kernel/generic/include/console/chardev.h
===================================================================
--- kernel/generic/include/console/chardev.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/console/chardev.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -57,5 +57,5 @@
 	
 	/** Protects everything below. */
-	SPINLOCK_DECLARE(lock);
+	IRQ_SPINLOCK_DECLARE(lock);
 	wchar_t buffer[INDEV_BUFLEN];
 	size_t counter;
@@ -95,13 +95,13 @@
 } outdev_t;
 
-extern void indev_initialize(const char *name, indev_t *indev,
-    indev_operations_t *op);
-extern void indev_push_character(indev_t *indev, wchar_t ch);
-extern wchar_t indev_pop_character(indev_t *indev);
+extern void indev_initialize(const char *, indev_t *,
+    indev_operations_t *);
+extern void indev_push_character(indev_t *, wchar_t);
+extern wchar_t indev_pop_character(indev_t *);
 
-extern void outdev_initialize(const char *name, outdev_t *outdev,
-    outdev_operations_t *op);
+extern void outdev_initialize(const char *, outdev_t *,
+    outdev_operations_t *);
 
-extern bool check_poll(indev_t *indev);
+extern bool check_poll(indev_t *);
 
 #endif /* KERN_CHARDEV_H_ */
Index: kernel/generic/include/cpu.h
===================================================================
--- kernel/generic/include/cpu.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/cpu.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -42,5 +42,5 @@
 #include <arch/context.h>
 
-#define CPU_STACK_SIZE	STACK_SIZE
+#define CPU_STACK_SIZE  STACK_SIZE
 
 /** CPU structure.
@@ -49,40 +49,44 @@
  */
 typedef struct cpu {
-	SPINLOCK_DECLARE(lock);
-
+	IRQ_SPINLOCK_DECLARE(lock);
+	
 	tlb_shootdown_msg_t tlb_messages[TLB_MESSAGE_QUEUE_LEN];
 	size_t tlb_messages_count;
 	
 	context_t saved_context;
-
+	
 	atomic_t nrdy;
 	runq_t rq[RQ_COUNT];
 	volatile size_t needs_relink;
-
-	SPINLOCK_DECLARE(timeoutlock);
+	
+	IRQ_SPINLOCK_DECLARE(timeoutlock);
 	link_t timeout_active_head;
-
-	size_t missed_clock_ticks;	/**< When system clock loses a tick, it is recorded here
-					     so that clock() can react. This variable is
-					     CPU-local and can be only accessed when interrupts
-					     are disabled. */
-
+	
+	/**
+	 * When system clock loses a tick, it is
+	 * recorded here so that clock() can react.
+	 * This variable is CPU-local and can be
+	 * only accessed when interrupts are
+	 * disabled.
+	 */
+	size_t missed_clock_ticks;
+	
 	bool idle;
 	uint64_t idle_ticks;
 	uint64_t busy_ticks;
-
+	
 	/**
 	 * Processor ID assigned by kernel.
 	 */
-	unsigned int id;
+	size_t id;
 	
 	bool active;
-	int tlb_active;
-
+	bool tlb_active;
+	
 	uint16_t frequency_mhz;
 	uint32_t delay_loop_const;
-
+	
 	cpu_arch_t arch;
-
+	
 	struct thread *fpu_owner;
 	
@@ -100,5 +104,5 @@
 extern void cpu_arch_init(void);
 extern void cpu_identify(void);
-extern void cpu_print_report(cpu_t *m);
+extern void cpu_print_report(cpu_t *);
 
 #endif
Index: kernel/generic/include/ddi/ddi.h
===================================================================
--- kernel/generic/include/ddi/ddi.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/ddi/ddi.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -50,15 +50,14 @@
 
 extern void ddi_init(void);
-extern void ddi_parea_register(parea_t *parea);
+extern void ddi_parea_register(parea_t *);
 
-extern unative_t sys_physmem_map(unative_t phys_base, unative_t virt_base,
-	unative_t pages, unative_t flags);
-extern unative_t sys_iospace_enable(ddi_ioarg_t *uspace_io_arg);
-extern unative_t sys_preempt_control(int enable);
+extern unative_t sys_physmem_map(unative_t, unative_t, unative_t, unative_t);
+extern unative_t sys_iospace_enable(ddi_ioarg_t *);
+extern unative_t sys_preempt_control(int);
 
 /*
  * Interface to be implemented by all architectures.
  */
-extern int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size);
+extern int ddi_iospace_enable_arch(task_t *, uintptr_t, size_t);
 
 #endif
Index: kernel/generic/include/ddi/ddi_arg.h
===================================================================
--- kernel/generic/include/ddi/ddi_arg.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/ddi/ddi_arg.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -36,8 +36,14 @@
 #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. */
-	unsigned long long task_id;
+	uint64_t task_id;
 	/** Physical address of starting frame. */
 	void *phys_base;
@@ -45,14 +51,14 @@
 	void *virt_base;
 	/** Number of pages to map. */
-	unsigned long pages;
+	size_t pages;
 	/** Address space area flags for the mapping. */
-	int flags;
+	unsigned 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. */
+	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;
 
Index: kernel/generic/include/ddi/irq.h
===================================================================
--- kernel/generic/include/ddi/irq.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/ddi/irq.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -35,4 +35,15 @@
 #ifndef KERN_IRQ_H_
 #define KERN_IRQ_H_
+
+#ifdef KERNEL
+
+#include <typedefs.h>
+#include <adt/list.h>
+#include <adt/hash_table.h>
+#include <synch/spinlock.h>
+#include <proc/task.h>
+#include <ipc/ipc.h>
+
+#endif /* KERNEL */
 
 typedef enum {
@@ -49,4 +60,5 @@
 	/** Write 4 bytes to the I/O space. */
 	CMD_PIO_WRITE_32,
+	
 	/**
 	 * Perform a bit test on the source argument and store the result into
@@ -54,4 +66,5 @@
 	 */
 	CMD_BTEST,
+	
 	/**
 	 * Predicate the execution of the following N commands by the boolean
@@ -59,4 +72,5 @@
 	 */
 	CMD_PREDICATE,
+	
 	/** Accept the interrupt. */
 	CMD_ACCEPT,
@@ -69,11 +83,11 @@
 	irq_cmd_type cmd;
 	void *addr;
-	unsigned long long value;
-	unsigned int srcarg;
-	unsigned int dstarg;
+	uint32_t value;
+	uintptr_t srcarg;
+	uintptr_t dstarg;
 } irq_cmd_t;
 
 typedef struct {
-	unsigned int cmdcount;
+	size_t cmdcount;
 	irq_cmd_t *cmds;
 } irq_code_t;
@@ -81,14 +95,7 @@
 #ifdef KERNEL
 
-#include <typedefs.h>
-#include <adt/list.h>
-#include <adt/hash_table.h>
-#include <synch/spinlock.h>
-#include <proc/task.h>
-#include <ipc/ipc.h>
-
 typedef enum {
-	IRQ_DECLINE,		/**< Decline to service. */
-	IRQ_ACCEPT		/**< Accept to service. */
+	IRQ_DECLINE,  /**< Decline to service. */
+	IRQ_ACCEPT    /**< Accept to service. */
 } irq_ownership_t;
 
@@ -108,4 +115,5 @@
  * Primarily, this structure is encapsulated in the irq_t structure.
  * It is protected by irq_t::lock.
+ *
  */
 typedef struct {
@@ -117,9 +125,10 @@
 	unative_t method;
 	/** Arguments that will be sent if the IRQ is claimed. */
-	unative_t scratch[IPC_CALL_LEN];
+	uint32_t scratch[IPC_CALL_LEN];
 	/** Top-half pseudocode. */
 	irq_code_t *code;
 	/** Counter. */
 	size_t counter;
+	
 	/**
 	 * Link between IRQs that are notifying the same answerbox. The list is
@@ -133,9 +142,10 @@
  * If one device has multiple interrupts, there will be multiple irq_t
  * instantions with the same devno.
+ *
  */
 typedef struct irq {
 	/** Hash table link. */
 	link_t link;
-
+	
 	/** Lock protecting everything in this structure
 	 *  except the link member. When both the IRQ
@@ -143,5 +153,5 @@
 	 *  this lock must not be taken first.
 	 */
-	SPINLOCK_DECLARE(lock);
+	IRQ_SPINLOCK_DECLARE(lock);
 	
 	/** Send EOI before processing the interrupt.
@@ -152,8 +162,8 @@
 	 */
 	bool preack;
-
+	
 	/** Unique device number. -1 if not yet assigned. */
 	devno_t devno;
-
+	
 	/** Actual IRQ number. -1 if not yet assigned. */
 	inr_t inr;
@@ -166,15 +176,15 @@
 	/** Instance argument for the handler and the claim function. */
 	void *instance;
-
+	
 	/** Clear interrupt routine. */
 	cir_t cir;
 	/** First argument to the clear interrupt routine. */
 	void *cir_arg;
-
+	
 	/** Notification configuration structure. */
 	ipc_notif_cfg_t notif_cfg; 
 } irq_t;
 
-SPINLOCK_EXTERN(irq_uspace_hash_table_lock);
+IRQ_SPINLOCK_EXTERN(irq_uspace_hash_table_lock);
 extern hash_table_t irq_uspace_hash_table;
 
@@ -184,8 +194,8 @@
 extern irq_t *irq_dispatch_and_lock(inr_t);
 
+#endif /* KERNEL */
+
 #endif
 
-#endif
-
 /** @}
  */
Index: kernel/generic/include/interrupt.h
===================================================================
--- kernel/generic/include/interrupt.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/interrupt.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -44,12 +44,12 @@
 #include <stacktrace.h>
 
-typedef void (* iroutine)(int n, istate_t *istate);
+typedef void (* iroutine)(int, istate_t *);
 
-extern void fault_if_from_uspace(istate_t *istate, const char *fmt, ...);
-extern iroutine exc_register(int n, const char *name, iroutine f);
-extern void exc_dispatch(int n, istate_t *t);
-void exc_init(void);
+extern void fault_if_from_uspace(istate_t *, const char *, ...);
+extern iroutine exc_register(int, const char *, iroutine);
+extern void exc_dispatch(int, istate_t *);
+extern void exc_init(void);
 
-extern void irq_initialize_arch(irq_t *irq);
+extern void irq_initialize_arch(irq_t *);
 
 #endif
Index: kernel/generic/include/ipc/ipc.h
===================================================================
--- kernel/generic/include/ipc/ipc.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/ipc/ipc.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -36,13 +36,16 @@
 #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	
+/** 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 thread */
 #ifdef CONFIG_DEBUG
-#define IPC_MAX_ASYNC_CALLS	4
+	#define IPC_MAX_ASYNC_CALLS  4
 #else
-#define IPC_MAX_ASYNC_CALLS	4000
+	#define IPC_MAX_ASYNC_CALLS  4000
 #endif
 
@@ -50,52 +53,61 @@
 
 /** This is answer to a call */
-#define IPC_CALL_ANSWERED	(1 << 0)
+#define IPC_CALL_ANSWERED  (1 << 0)
+
 /** Answer will not be passed to userspace, will be discarded */
-#define IPC_CALL_DISCARD_ANSWER (1 << 1)
+#define IPC_CALL_DISCARD_ANSWER  (1 << 1)
+
 /** Call was forwarded */
-#define IPC_CALL_FORWARDED	(1 << 2)
+#define IPC_CALL_FORWARDED  (1 << 2)
+
 /** Identify connect_me_to answer */
-#define IPC_CALL_CONN_ME_TO	(1 << 3)
+#define IPC_CALL_CONN_ME_TO  (1 << 3)
+
 /** Interrupt notification */
-#define IPC_CALL_NOTIF		(1 << 4)
-
-/*
- * Bits used in call hashes.
+#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
+#define IPC_CALLID_ANSWERED  1
+
 /** Type of this call is 'notification' */
-#define IPC_CALLID_NOTIFICATION	2
+#define IPC_CALLID_NOTIFICATION  2
 
 /* Return values from sys_ipc_call_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_SET_ARG4(data, val)		((data).args[4] = (val))
-#define IPC_SET_ARG5(data, val)		((data).args[5] = (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_GET_ARG4(data)		((data).args[4])
-#define IPC_GET_ARG5(data)		((data).args[5])
+#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_SET_ARG4(data, val)       ((data).args[4] = (val))
+#define IPC_SET_ARG5(data, val)       ((data).args[5] = (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_GET_ARG4(data)  ((data).args[4])
+#define IPC_GET_ARG5(data)  ((data).args[5])
 
 /* Well known phone descriptors */
-#define PHONE_NS	0
+#define PHONE_NS  0
 
 /* Forwarding flags. */
-#define IPC_FF_NONE		0
+#define IPC_FF_NONE  0
+
 /**
  * The call will be routed as though it was initially sent via the phone used to
@@ -104,10 +116,13 @@
  * 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)
-
-/* System-specific methods - only through special syscalls
+ *
+ */
+#define IPC_FF_ROUTE_FROM_ME  (1 << 0)
+
+/** System-specific methods - only through special syscalls
  * These methods have special behaviour
- */
+ *
+ */
+
 /** Clone connection.
  *
@@ -115,19 +130,24 @@
  *
  * - ARG1 - The caller sets ARG1 to the phone of the cloned connection.
- *	  - The callee gets the new phone from ARG1.
+ *        - 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
+ *
+ */
+#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 asnwer, 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 
+ *
+ */
+#define IPC_M_CONNECT_ME  2
+
+/** Protocol for CONNECT - TO - ME
  *
  * Calling process asks the callee to create a callback connection,
@@ -144,6 +164,8 @@
  *                     - the allocated phoneid is passed to userspace 
  *                       (on the receiving side) as ARG5 of the call.
- */
-#define IPC_M_CONNECT_TO_ME	3	
+ *
+ */
+#define IPC_M_CONNECT_TO_ME  3
+
 /** Protocol for CONNECT - ME - TO
  *
@@ -163,9 +185,10 @@
  *
  */
-#define IPC_M_CONNECT_ME_TO	4	
-/** This message is sent to answerbox when the phone
- * is hung up
- */
-#define IPC_M_PHONE_HUNGUP	5
+#define IPC_M_CONNECT_ME_TO  4
+
+/** This message is sent to answerbox when the phone is hung up
+ *
+ */
+#define IPC_M_PHONE_HUNGUP  5
 
 /** Send as_area over IPC.
@@ -173,9 +196,10 @@
  * - 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		6	
+ *
+ */
+#define IPC_M_SHARE_OUT  6
 
 /** Receive as_area over IPC.
@@ -183,11 +207,12 @@
  * - 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		7	
+ *
+ */
+#define IPC_M_SHARE_IN  7
 
 /** Send data to another address space over IPC.
@@ -199,6 +224,7 @@
  * - ARG1 - final destination address space virtual address
  * - ARG2 - final size of data to be copied
- */
-#define IPC_M_DATA_WRITE	8
+ *
+ */
+#define IPC_M_DATA_WRITE  8
 
 /** Receive data from another address space over IPC.
@@ -210,18 +236,21 @@
  * - ARG1 - source virtual address in the destination address space
  * - ARG2 - final size of data to be copied
- */
-#define IPC_M_DATA_READ		9
+ *
+ */
+#define IPC_M_DATA_READ  9
 
 /** Debug the recipient.
  * - ARG1 - specifies the debug method (from udebug_method_t)
  * - other arguments are specific to the debug method
- */
-#define IPC_M_DEBUG_ALL		10
+ *
+ */
+#define IPC_M_DEBUG_ALL  10
 
 /* Well-known methods */
-#define IPC_M_LAST_SYSTEM	511
-#define IPC_M_PING		512
+#define IPC_M_LAST_SYSTEM  511
+#define IPC_M_PING         512
+
 /* User methods */
-#define IPC_FIRST_USER_METHOD	1024
+#define IPC_FIRST_USER_METHOD  1024
 
 #ifdef KERNEL
@@ -259,23 +288,24 @@
 
 typedef struct answerbox {
-	SPINLOCK_DECLARE(lock);
-
+	IRQ_SPINLOCK_DECLARE(lock);
+	
 	struct task *task;
-
+	
 	waitq_t wq;
-
+	
 	/** Linkage for the list of task's synchronous answerboxes. */
 	link_t sync_box_link;
-
+	
 	/** 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 calls;
+	link_t dispatched_calls;  /* Should be hash table in the future */
+	
 	/** Answered calls. */
 	link_t answers;
-
-	SPINLOCK_DECLARE(irq_lock);
+	
+	IRQ_SPINLOCK_DECLARE(irq_lock);
+	
 	/** Notifications from IRQ handlers. */
 	link_t irq_notifs;
@@ -291,43 +321,46 @@
 typedef struct {
 	link_t link;
-
-	int flags;
-
+	
+	unsigned int flags;
+	
 	/** Identification of the caller. */
 	struct task *sender;
-	/** The caller box is different from sender->answerbox for synchronous
-	 *  calls. */
+	
+	/*
+	 * The caller box is different from sender->answerbox
+	 * for synchronous calls.
+	 *
+	 */
 	answerbox_t *callerbox;
-
+	
 	/** Private data to internal IPC. */
 	unative_t priv;
-
+	
 	/** Data passed from/to userspace. */
 	ipc_data_t data;
-
+	
 	/** Buffer for IPC_M_DATA_WRITE and IPC_M_DATA_READ. */
 	uint8_t *buffer;
-
+	
 	/*
 	 * The forward operation can masquerade the caller phone. For those
 	 * cases, we must keep it aside so that the answer is processed
 	 * correctly.
+	 *
 	 */
 	phone_t *caller_phone;
 } call_t;
 
-
 extern answerbox_t *ipc_phone_0;
 
-
 extern void ipc_init(void);
 
-extern call_t * ipc_call_alloc(int);
+extern call_t *ipc_call_alloc(unsigned int);
 extern void ipc_call_free(call_t *);
 
 extern int ipc_call(phone_t *, call_t *);
 extern int ipc_call_sync(phone_t *, call_t *);
-extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, int);
-extern int ipc_forward(call_t *, phone_t *, answerbox_t *, int);
+extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, unsigned int);
+extern int ipc_forward(call_t *, phone_t *, answerbox_t *, unsigned int);
 extern void ipc_answer(answerbox_t *, call_t *);
 
@@ -345,8 +378,8 @@
 extern void ipc_print_task(task_id_t);
 
+#endif /* KERNEL */
+
 #endif
 
-#endif
-
 /** @}
  */
Index: kernel/generic/include/ipc/irq.h
===================================================================
--- kernel/generic/include/ipc/irq.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/ipc/irq.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -37,5 +37,5 @@
 
 /** Maximum length of IPC IRQ program */
-#define IRQ_MAX_PROG_SIZE	20
+#define IRQ_MAX_PROG_SIZE  20
 
 #include <ipc/ipc.h>
@@ -58,15 +58,20 @@
  */
 #define ipc_irq_send_msg_0(irq) \
-    ipc_irq_send_msg((irq), 0, 0, 0, 0, 0)
+	ipc_irq_send_msg((irq), 0, 0, 0, 0, 0)
+
 #define ipc_irq_send_msg_1(irq, a1) \
-    ipc_irq_send_msg((irq), (a1), 0, 0, 0, 0)
+	ipc_irq_send_msg((irq), (a1), 0, 0, 0, 0)
+
 #define ipc_irq_send_msg_2(irq, a1, a2) \
-    ipc_irq_send_msg((irq), (a1), (a2), 0, 0, 0)
+	ipc_irq_send_msg((irq), (a1), (a2), 0, 0, 0)
+
 #define ipc_irq_send_msg_3(irq, a1, a2, a3) \
-    ipc_irq_send_msg((irq), (a1), (a2), (a3), 0, 0)
+	ipc_irq_send_msg((irq), (a1), (a2), (a3), 0, 0)
+
 #define ipc_irq_send_msg_4(irq, a1, a2, a3, a4) \
-    ipc_irq_send_msg((irq), (a1), (a2), (a3), (a4), 0)
+	ipc_irq_send_msg((irq), (a1), (a2), (a3), (a4), 0)
+
 #define ipc_irq_send_msg_5(irq, a1, a2, a3, a4, a5) \
-    ipc_irq_send_msg((irq), (a1), (a2), (a3), (a4), (a5))
+	ipc_irq_send_msg((irq), (a1), (a2), (a3), (a4), (a5))
 
 extern void ipc_irq_send_msg(irq_t *, unative_t, unative_t, unative_t, unative_t,
Index: kernel/generic/include/ipc/sysipc.h
===================================================================
--- kernel/generic/include/ipc/sysipc.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/ipc/sysipc.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -40,26 +40,26 @@
 #include <typedefs.h>
 
-unative_t sys_ipc_call_sync_fast(unative_t phoneid, unative_t method, 
+extern unative_t sys_ipc_call_sync_fast(unative_t phoneid, unative_t method, 
     unative_t arg1, unative_t arg2, unative_t arg3, ipc_data_t *data);
-unative_t sys_ipc_call_sync_slow(unative_t phoneid, ipc_data_t *question,
+extern unative_t sys_ipc_call_sync_slow(unative_t phoneid, ipc_data_t *question,
     ipc_data_t *reply);
-unative_t sys_ipc_call_async_fast(unative_t phoneid, unative_t method, 
+extern unative_t sys_ipc_call_async_fast(unative_t phoneid, unative_t method, 
     unative_t arg1, unative_t arg2, unative_t arg3, unative_t arg4);
-unative_t sys_ipc_call_async_slow(unative_t phoneid, ipc_data_t *data);
-unative_t sys_ipc_answer_fast(unative_t callid, unative_t retval, 
+extern unative_t sys_ipc_call_async_slow(unative_t phoneid, ipc_data_t *data);
+extern unative_t sys_ipc_answer_fast(unative_t callid, unative_t retval, 
     unative_t arg1, unative_t arg2, unative_t arg3, unative_t arg4);
-unative_t sys_ipc_answer_slow(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_poke(void);
-unative_t sys_ipc_forward_fast(unative_t callid, unative_t phoneid,
-    unative_t method, unative_t arg1, unative_t arg2, int mode);
-unative_t sys_ipc_forward_slow(unative_t callid, unative_t phoneid,
-    ipc_data_t *data, int mode);
-unative_t sys_ipc_hangup(unative_t phoneid);
-unative_t sys_ipc_register_irq(inr_t inr, devno_t devno, unative_t method,
+extern unative_t sys_ipc_answer_slow(unative_t callid, ipc_data_t *data);
+extern unative_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec,
+    unsigned int nonblocking);
+extern unative_t sys_ipc_poke(void);
+extern unative_t sys_ipc_forward_fast(unative_t callid, unative_t phoneid,
+    unative_t method, unative_t arg1, unative_t arg2, unsigned int mode);
+extern unative_t sys_ipc_forward_slow(unative_t callid, unative_t phoneid,
+    ipc_data_t *data, unsigned int mode);
+extern unative_t sys_ipc_hangup(unative_t phoneid);
+extern 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);
-unative_t sys_ipc_connect_kbox(sysarg64_t *task_id);
+extern unative_t sys_ipc_unregister_irq(inr_t inr, devno_t devno);
+extern unative_t sys_ipc_connect_kbox(sysarg64_t *task_id);
 
 #endif
Index: kernel/generic/include/mm/as.h
===================================================================
--- kernel/generic/include/mm/as.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/mm/as.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -43,8 +43,8 @@
 
 /** Address space area flags. */
-#define AS_AREA_READ		1
-#define AS_AREA_WRITE		2
-#define AS_AREA_EXEC		4
-#define AS_AREA_CACHEABLE	8
+#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. */
@@ -52,10 +52,10 @@
 	/** Starting address */
 	uintptr_t start_addr;
-
+	
 	/** Area size */
 	size_t size;
-
+	
 	/** Area flags */
-	int flags;
+	unsigned int flags;
 } as_area_info_t;
 
@@ -75,27 +75,30 @@
  * 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
-
-#define KERNEL_ADDRESS_SPACE_START	KERNEL_ADDRESS_SPACE_START_ARCH
-#define KERNEL_ADDRESS_SPACE_END	KERNEL_ADDRESS_SPACE_END_ARCH
-#define USER_ADDRESS_SPACE_START	USER_ADDRESS_SPACE_START_ARCH
-#define USER_ADDRESS_SPACE_END		USER_ADDRESS_SPACE_END_ARCH
-
-#define USTACK_ADDRESS			USTACK_ADDRESS_ARCH
+ *
+ */
+#define KERNEL_ADDRESS_SPACE_SHADOWED  KERNEL_ADDRESS_SPACE_SHADOWED_ARCH
+
+#define KERNEL_ADDRESS_SPACE_START  KERNEL_ADDRESS_SPACE_START_ARCH
+#define KERNEL_ADDRESS_SPACE_END    KERNEL_ADDRESS_SPACE_END_ARCH
+#define USER_ADDRESS_SPACE_START    USER_ADDRESS_SPACE_START_ARCH
+#define USER_ADDRESS_SPACE_END      USER_ADDRESS_SPACE_END_ARCH
+
+#define USTACK_ADDRESS  USTACK_ADDRESS_ARCH
 
 /** Kernel address space. */
-#define FLAG_AS_KERNEL			(1 << 0)	
+#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_AREA_ATTR_NONE     0
+#define AS_AREA_ATTR_PARTIAL  1  /**< Not fully initialized area. */
 
 /** The page fault was not resolved by as_page_fault(). */
-#define AS_PF_FAULT		0
+#define AS_PF_FAULT  0
+
 /** The page fault was resolved by as_page_fault(). */
-#define AS_PF_OK		1
+#define AS_PF_OK  1
+
 /** The page fault was caused by memcpy_from_uspace() or memcpy_to_uspace(). */
-#define AS_PF_DEFER		2
+#define AS_PF_DEFER  2
 
 /** Address space structure.
@@ -105,8 +108,10 @@
  * 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;
+	
 	/**
 	 * Number of processors on wich is this address space active.
@@ -114,4 +119,5 @@
 	 */
 	size_t cpu_refcount;
+	
 	/**
 	 * Address space identifier.
@@ -120,10 +126,10 @@
 	 */
 	asid_t asid;
-
+	
 	/** Number of references (i.e tasks that reference this as). */
 	atomic_t refcount;
-
+	
 	mutex_t lock;
-
+	
 	/** B+tree of address space areas. */
 	btree_t as_area_btree;
@@ -131,5 +137,5 @@
 	/** Non-generic content. */
 	as_genarch_t genarch;
-
+	
 	/** Architecture specific content. */
 	as_arch_t arch;
@@ -137,8 +143,8 @@
 
 typedef struct {
-	pte_t *(* page_table_create)(int flags);
-	void (* page_table_destroy)(pte_t *page_table);
-	void (* page_table_lock)(as_t *as, bool lock);
-	void (* page_table_unlock)(as_t *as, bool unlock);
+	pte_t *(* page_table_create)(unsigned int);
+	void (* page_table_destroy)(pte_t *);
+	void (* page_table_lock)(as_t *, bool);
+	void (* page_table_unlock)(as_t *, bool);
 } as_operations_t;
 
@@ -146,10 +152,12 @@
  * This structure contains information associated with the shared address space
  * area.
+ *
  */
 typedef struct {
 	/** This lock must be acquired only when the as_area lock is held. */
-	mutex_t lock;		
+	mutex_t lock;
 	/** This structure can be deallocated if refcount drops to 0. */
 	size_t refcount;
+	
 	/**
 	 * B+tree containing complete map of anonymous pages of the shared area.
@@ -169,9 +177,12 @@
 /** Backend data stored in address space area. */
 typedef union mem_backend_data {
-	struct {	/**< elf_backend members */
+	/** elf_backend members */
+	struct {
 		elf_header_t *elf;
 		elf_segment_header_t *segment;
 	};
-	struct {	/**< phys_backend members */
+	
+	/** phys_backend members */
+	struct {
 		uintptr_t base;
 		size_t frames;
@@ -182,15 +193,18 @@
  *
  * Each as_area_t structure describes one contiguous area of virtual memory.
+ *
  */
 typedef struct {
 	mutex_t lock;
 	/** Containing address space. */
-	as_t *as;		
+	as_t *as;
+	
 	/**
 	 * Flags related to the memory represented by the address space area.
 	 */
-	int flags;
+	unsigned int flags;
+	
 	/** Attributes related to the address space area itself. */
-	int attributes;
+	unsigned int attributes;
 	/** Size of this area in multiples of PAGE_SIZE. */
 	size_t pages;
@@ -199,5 +213,5 @@
 	/** Map of used space. */
 	btree_t used_space;
-
+	
 	/**
 	 * If the address space area has been shared, this pointer will
@@ -205,8 +219,8 @@
 	 */
 	share_info_t *sh_info;
-
+	
 	/** Memory backend backing this address space area. */
 	struct mem_backend *backend;
-
+	
 	/** Data to be used by the backend. */
 	mem_backend_data_t backend_data;
@@ -215,7 +229,7 @@
 /** Address space area backend structure. */
 typedef struct mem_backend {
-	int (* page_fault)(as_area_t *area, uintptr_t addr, pf_access_t access);
-	void (* frame_free)(as_area_t *area, uintptr_t page, uintptr_t frame);
-	void (* share)(as_area_t *area);
+	int (* page_fault)(as_area_t *, uintptr_t, pf_access_t);
+	void (* frame_free)(as_area_t *, uintptr_t, uintptr_t);
+	void (* share)(as_area_t *);
 } mem_backend_t;
 
@@ -227,5 +241,5 @@
 extern void as_init(void);
 
-extern as_t *as_create(int);
+extern as_t *as_create(unsigned int);
 extern void as_destroy(as_t *);
 extern void as_hold(as_t *);
@@ -234,12 +248,13 @@
 extern int as_page_fault(uintptr_t, pf_access_t, istate_t *);
 
-extern as_area_t *as_area_create(as_t *, int, size_t, uintptr_t, int,
-    mem_backend_t *, mem_backend_data_t *);
+extern as_area_t *as_area_create(as_t *, unsigned int, size_t, uintptr_t,
+    unsigned int, mem_backend_t *, mem_backend_data_t *);
 extern int as_area_destroy(as_t *, uintptr_t);
-extern int as_area_resize(as_t *, uintptr_t, size_t, int);
-extern int as_area_share(as_t *, uintptr_t, size_t, as_t *, uintptr_t, int);
-extern int as_area_change_flags(as_t *, int, uintptr_t);
-
-extern int as_area_get_flags(as_area_t *);
+extern int as_area_resize(as_t *, uintptr_t, size_t, unsigned int);
+extern int as_area_share(as_t *, uintptr_t, size_t, as_t *, uintptr_t,
+    unsigned int);
+extern int as_area_change_flags(as_t *, unsigned int, uintptr_t);
+
+extern unsigned int as_area_get_flags(as_area_t *);
 extern bool as_area_check_access(as_area_t *, pf_access_t);
 extern size_t as_area_get_size(uintptr_t);
@@ -249,16 +264,21 @@
 
 /* Interface to be implemented by architectures. */
+
 #ifndef as_constructor_arch
-extern int as_constructor_arch(as_t *, int);
+extern int as_constructor_arch(as_t *, unsigned int);
 #endif /* !def as_constructor_arch */
+
 #ifndef as_destructor_arch
 extern int as_destructor_arch(as_t *);
 #endif /* !def as_destructor_arch */
+
 #ifndef as_create_arch
-extern int as_create_arch(as_t *, int);
+extern int as_create_arch(as_t *, unsigned int);
 #endif /* !def as_create_arch */
+
 #ifndef as_install_arch
 extern void as_install_arch(as_t *);
 #endif /* !def as_install_arch */
+
 #ifndef as_deinstall_arch
 extern void as_deinstall_arch(as_t *);
@@ -270,17 +290,18 @@
 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 *, int);
+ *
+ */
+#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 unative_t sys_as_area_create(uintptr_t, size_t, int);
-extern unative_t sys_as_area_resize(uintptr_t, size_t, int);
-extern unative_t sys_as_area_change_flags(uintptr_t, int);
+extern unative_t sys_as_area_create(uintptr_t, size_t, unsigned int);
+extern unative_t sys_as_area_resize(uintptr_t, size_t, unsigned int);
+extern unative_t sys_as_area_change_flags(uintptr_t, unsigned int);
 extern unative_t sys_as_area_destroy(uintptr_t);
 
Index: kernel/generic/include/mm/frame.h
===================================================================
--- kernel/generic/include/mm/frame.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/mm/frame.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -81,5 +81,5 @@
 
 typedef struct {
-	size_t refcount;     /**< Tracking of shared frames */
+	size_t refcount;      /**< Tracking of shared frames */
 	uint8_t buddy_order;  /**< Buddy system block order */
 	link_t buddy_link;    /**< Link to the next free block inside
@@ -91,8 +91,8 @@
 	pfn_t base;                    /**< Frame_no of the first frame
                                         in the frames array */
-	size_t count;                 /**< Size of zone */
-	size_t free_count;            /**< Number of free frame_t
+	size_t count;                  /**< Size of zone */
+	size_t free_count;             /**< Number of free frame_t
                                         structures */
-	size_t busy_count;            /**< Number of busy frame_t
+	size_t busy_count;             /**< Number of busy frame_t
                                         structures */
 	zone_flags_t flags;            /**< Type of the zone */
@@ -108,5 +108,5 @@
  */
 typedef struct {
-	SPINLOCK_DECLARE(lock);
+	IRQ_SPINLOCK_DECLARE(lock);
 	size_t count;
 	zone_t info[ZONES_MAX];
Index: kernel/generic/include/mm/page.h
===================================================================
--- kernel/generic/include/mm/page.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/mm/page.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -42,8 +42,7 @@
 /** Operations to manipulate page mappings. */
 typedef struct {
-	void (* mapping_insert)(as_t *as, uintptr_t page, uintptr_t frame,
-	    int flags);
-	void (* mapping_remove)(as_t *as, uintptr_t page);
-	pte_t *(* mapping_find)(as_t *as, uintptr_t page);
+	void (* mapping_insert)(as_t *, uintptr_t, uintptr_t, unsigned int);
+	void (* mapping_remove)(as_t *, uintptr_t);
+	pte_t *(* mapping_find)(as_t *, uintptr_t);
 } page_mapping_operations_t;
 
@@ -51,15 +50,14 @@
 
 extern void page_init(void);
-extern void page_table_lock(as_t *as, bool lock);
-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);
-extern void page_mapping_remove(as_t *as, uintptr_t page);
-extern pte_t *page_mapping_find(as_t *as, uintptr_t page);
-extern pte_t *page_table_create(int flags);
-extern void page_table_destroy(pte_t *page_table);
-extern void map_structure(uintptr_t s, size_t size);
+extern void page_table_lock(as_t *, bool);
+extern void page_table_unlock(as_t *, bool);
+extern void page_mapping_insert(as_t *, uintptr_t, uintptr_t, unsigned int);
+extern void page_mapping_remove(as_t *, uintptr_t);
+extern pte_t *page_mapping_find(as_t *, uintptr_t);
+extern pte_t *page_table_create(unsigned int);
+extern void page_table_destroy(pte_t *);
+extern void map_structure(uintptr_t, size_t);
 
-extern uintptr_t hw_map(uintptr_t physaddr, size_t size);
+extern uintptr_t hw_map(uintptr_t, size_t);
 
 #endif
Index: kernel/generic/include/mm/slab.h
===================================================================
--- kernel/generic/include/mm/slab.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/mm/slab.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -84,5 +84,4 @@
 } slab_mag_cache_t;
 
-
 typedef struct {
 	const char *name;
@@ -94,13 +93,13 @@
 	size_t size;
 	
-	int (*constructor)(void *obj, int kmflag);
-	int (*destructor)(void *obj);
+	int (*constructor)(void *obj, unsigned int kmflag);
+	size_t (*destructor)(void *obj);
 	
 	/** Flags changing behaviour of cache */
-	int flags;
+	unsigned int flags;
 	
 	/* Computed values */
-	uint8_t order;         /**< Order of frames to be allocated */
-	unsigned int objects;  /**< Number of objects that fit in */
+	uint8_t order;   /**< Order of frames to be allocated */
+	size_t objects;  /**< Number of objects that fit in */
 	
 	/* Statistics */
@@ -109,5 +108,5 @@
 	atomic_t cached_objs;
 	/** How many magazines in magazines list */
-	atomic_t magazine_counter; 
+	atomic_t magazine_counter;
 	
 	/* Slabs */
@@ -124,10 +123,10 @@
 
 extern slab_cache_t *slab_cache_create(const char *, size_t, size_t,
-    int (*)(void *, int), int (*)(void *), int);
+    int (*)(void *, unsigned int), size_t (*)(void *), unsigned int);
 extern void slab_cache_destroy(slab_cache_t *);
 
-extern void * slab_alloc(slab_cache_t *, int);
+extern void * slab_alloc(slab_cache_t *, unsigned int);
 extern void slab_free(slab_cache_t *, void *);
-extern size_t slab_reclaim(int);
+extern size_t slab_reclaim(unsigned int);
 
 /* slab subsytem initialization */
@@ -139,6 +138,6 @@
 
 /* malloc support */
-extern void *malloc(unsigned int, int);
-extern void *realloc(void *, unsigned int, int);
+extern void *malloc(size_t, unsigned int);
+extern void *realloc(void *, size_t, unsigned int);
 extern void free(void *);
 
Index: kernel/generic/include/proc/scheduler.h
===================================================================
--- kernel/generic/include/proc/scheduler.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/proc/scheduler.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -47,7 +47,7 @@
 /** Scheduler run queue structure. */
 typedef struct {
-	SPINLOCK_DECLARE(lock);
-	link_t rq_head;          /**< List of ready threads. */
-	size_t n;                /**< Number of threads in rq_ready. */
+	IRQ_SPINLOCK_DECLARE(lock);
+	link_t rq_head;              /**< List of ready threads. */
+	size_t n;                    /**< Number of threads in rq_ready. */
 } runq_t;
 
Index: kernel/generic/include/proc/task.h
===================================================================
--- kernel/generic/include/proc/task.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/proc/task.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -70,6 +70,6 @@
 	 * threads.
 	 */
-	SPINLOCK_DECLARE(lock);
-
+	IRQ_SPINLOCK_DECLARE(lock);
+	
 	char name[TASK_NAME_BUFLEN];
 	/** List of threads contained in this task. */
@@ -81,13 +81,13 @@
 	/** Task security context. */
 	context_id_t context;
-
+	
 	/** Number of references (i.e. threads). */
 	atomic_t refcount;
 	/** Number of threads that haven't exited yet. */
 	atomic_t lifecount;
-
+	
 	/** Task capabilities. */
 	cap_t capabilities;
-
+	
 	/* IPC stuff */
 	answerbox_t answerbox;  /**< Communication endpoint */
@@ -101,13 +101,13 @@
 	/** List of synchronous answerboxes. */
 	link_t sync_box_head;
-
+	
 #ifdef CONFIG_UDEBUG
 	/** Debugging stuff. */
 	udebug_task_t udebug;
-
+	
 	/** Kernel answerbox. */
 	kbox_t kb;
-#endif
-
+#endif /* CONFIG_UDEBUG */
+	
 	/** Architecture specific task data. */
 	task_arch_t arch;
@@ -126,5 +126,5 @@
 } task_t;
 
-SPINLOCK_EXTERN(tasks_lock);
+IRQ_SPINLOCK_EXTERN(tasks_lock);
 extern avltree_t tasks_tree;
 
Index: kernel/generic/include/proc/thread.h
===================================================================
--- kernel/generic/include/proc/thread.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/proc/thread.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -50,6 +50,6 @@
 #include <sysinfo/abi.h>
 
-#define THREAD_STACK_SIZE	STACK_SIZE
-#define THREAD_NAME_BUFLEN	20
+#define THREAD_STACK_SIZE   STACK_SIZE
+#define THREAD_NAME_BUFLEN  20
 
 extern const char *thread_states[];
@@ -61,19 +61,23 @@
  * When using this flag, the caller must set cpu in the thread_t
  * structure manually before calling thread_ready (even on uniprocessor).
- */ 
-#define THREAD_FLAG_WIRED	(1 << 0)
+ *
+ */
+#define THREAD_FLAG_WIRED  (1 << 0)
+
 /** Thread was migrated to another CPU and has not run yet. */
-#define THREAD_FLAG_STOLEN	(1 << 1)
+#define THREAD_FLAG_STOLEN  (1 << 1)
+
 /** Thread executes in userspace. */
-#define THREAD_FLAG_USPACE	(1 << 2)
+#define THREAD_FLAG_USPACE  (1 << 2)
+
 /** Thread will be attached by the caller. */
-#define THREAD_FLAG_NOATTACH	(1 << 3)
+#define THREAD_FLAG_NOATTACH  (1 << 3)
 
 /** 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. */
+	
 	/** Threads linkage to the threads_tree. */
 	avltree_node_t threads_tree_node;
@@ -83,13 +87,13 @@
 	 * Protects the whole thread structure except list links above.
 	 */
-	SPINLOCK_DECLARE(lock);
-
+	IRQ_SPINLOCK_DECLARE(lock);
+	
 	char name[THREAD_NAME_BUFLEN];
-
+	
 	/** 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
@@ -107,5 +111,5 @@
 	 */
 	context_t sleep_interruption_context;
-
+	
 	/** If true, the thread can be interrupted from sleep. */
 	bool sleep_interruptible;
@@ -115,6 +119,6 @@
 	timeout_t sleep_timeout;
 	/** Flag signalling sleep timeout in progress. */
-	volatile int timeout_pending;
-
+	volatile bool timeout_pending;
+	
 	/**
 	 * True if this thread is executing copy_from_uspace().
@@ -132,5 +136,5 @@
 	 * thread_exit() before returning to userspace.
 	 */
-	bool interrupted;			
+	bool interrupted;
 	
 	/** If true, thread_join_timeout() cannot be used on this thread. */
@@ -140,8 +144,8 @@
 	/** Link used in the joiner_head list. */
 	link_t joiner_link;
-
+	
 	fpu_context_t *saved_fpu_context;
 	int fpu_context_exists;
-
+	
 	/*
 	 * Defined only if thread doesn't run.
@@ -150,16 +154,16 @@
 	 */
 	int fpu_context_engaged;
-
+	
 	rwlock_type_t rwlock_holder_type;
-
+	
 	/** 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;
+	unsigned int flags;
 	
 	/** Thread's CPU. */
@@ -167,5 +171,5 @@
 	/** Containing task. */
 	task_t *task;
-
+	
 	/** Ticks before preemption. */
 	uint64_t ticks;
@@ -176,7 +180,7 @@
 	/** Last sampled cycle. */
 	uint64_t last_cycle;
-	/** Thread doesn't affect accumulated accounting. */	
+	/** Thread doesn't affect accumulated accounting. */
 	bool uncounted;
-
+	
 	/** Thread's priority. Implemented as index to CPU->rq */
 	int priority;
@@ -186,13 +190,12 @@
 	/** Architecture-specific data. */
 	thread_arch_t arch;
-
+	
 	/** Thread's kernel stack. */
 	uint8_t *kstack;
-
+	
 #ifdef CONFIG_UDEBUG
 	/** Debugging stuff */
 	udebug_thread_t udebug;
-#endif
-
+#endif /* CONFIG_UDEBUG */
 } thread_t;
 
@@ -203,5 +206,5 @@
  *
  */
-SPINLOCK_EXTERN(threads_lock);
+IRQ_SPINLOCK_EXTERN(threads_lock);
 
 /** AVL tree containing all threads. */
@@ -209,6 +212,6 @@
 
 extern void thread_init(void);
-extern thread_t *thread_create(void (*)(void *), void *, task_t *, int,
-    const char *, bool);
+extern thread_t *thread_create(void (*)(void *), void *, task_t *,
+    unsigned int, const char *, bool);
 extern void thread_attach(thread_t *, task_t *);
 extern void thread_ready(thread_t *);
@@ -218,7 +221,9 @@
 extern void thread_create_arch(thread_t *);
 #endif
+
 #ifndef thr_constructor_arch
 extern void thr_constructor_arch(thread_t *);
 #endif
+
 #ifndef thr_destructor_arch
 extern void thr_destructor_arch(thread_t *);
@@ -230,10 +235,11 @@
 #define thread_join(t) \
 	thread_join_timeout((t), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
-extern int thread_join_timeout(thread_t *, uint32_t, int);
+
+extern int thread_join_timeout(thread_t *, uint32_t, unsigned int);
 extern void thread_detach(thread_t *);
 
 extern void thread_register_call_me(void (*)(void *), void *);
 extern void thread_print_list(void);
-extern void thread_destroy(thread_t *);
+extern void thread_destroy(thread_t *, bool);
 extern thread_t *thread_find_by_id(thread_id_t);
 extern void thread_update_accounting(bool);
Index: kernel/generic/include/stacktrace.h
===================================================================
--- kernel/generic/include/stacktrace.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/stacktrace.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -38,5 +38,5 @@
 #include <typedefs.h>
 
-/* Forward declarations. */
+/* Forward declaration. */
 struct istate;
 
Index: kernel/generic/include/symtab.h
===================================================================
--- kernel/generic/include/symtab.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/symtab.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -38,5 +38,5 @@
 #include <typedefs.h>
 
-#define MAX_SYMBOL_NAME 64
+#define MAX_SYMBOL_NAME  64
 
 struct symtab_entry {
@@ -53,8 +53,10 @@
 #ifdef CONFIG_SYMTAB
 
-/* Symtable linked together by build process */
+/** Symtable linked together by build process
+ *
+ */
 extern struct symtab_entry symbol_table[];
 
-#endif
+#endif /* CONFIG_SYMTAB */
 
 #endif
Index: kernel/generic/include/synch/mutex.h
===================================================================
--- kernel/generic/include/synch/mutex.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/synch/mutex.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -50,13 +50,15 @@
 } mutex_t;
 
-#define mutex_lock(mtx)			\
+#define mutex_lock(mtx) \
 	_mutex_lock_timeout((mtx), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
-#define mutex_trylock(mtx)		\
+
+#define mutex_trylock(mtx) \
 	_mutex_lock_timeout((mtx), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING)
-#define mutex_lock_timeout(mtx, usec)	\
+
+#define mutex_lock_timeout(mtx, usec) \
 	_mutex_lock_timeout((mtx), (usec), SYNCH_FLAGS_NON_BLOCKING)
 
 extern void mutex_initialize(mutex_t *, mutex_type_t);
-extern int _mutex_lock_timeout(mutex_t *, uint32_t, int);
+extern int _mutex_lock_timeout(mutex_t *, uint32_t, unsigned int);
 extern void mutex_unlock(mutex_t *);
 
Index: kernel/generic/include/synch/rwlock.h
===================================================================
--- kernel/generic/include/synch/rwlock.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/synch/rwlock.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -48,9 +48,12 @@
 
 typedef struct {
-	SPINLOCK_DECLARE(lock);
+	IRQ_SPINLOCK_DECLARE(lock);
+	
 	/**
 	 * Mutex for writers, readers can bypass it if readers_in is positive.
+	 *
 	 */
 	mutex_t exclusive;
+	
 	/** Number of readers in critical section. */
 	size_t readers_in;
@@ -59,22 +62,27 @@
 #define rwlock_write_lock(rwl) \
 	_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)
+
 #define rwlock_write_trylock(rwl) \
 	_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)
 
-extern void rwlock_initialize(rwlock_t *rwl);
-extern void rwlock_read_unlock(rwlock_t *rwl);
-extern void rwlock_write_unlock(rwlock_t *rwl);
-extern int _rwlock_read_lock_timeout(rwlock_t *rwl, uint32_t usec, int flags);
-extern int _rwlock_write_lock_timeout(rwlock_t *rwl, uint32_t usec, int flags);
+extern void rwlock_initialize(rwlock_t *);
+extern void rwlock_read_unlock(rwlock_t *);
+extern void rwlock_write_unlock(rwlock_t *);
+extern int _rwlock_read_lock_timeout(rwlock_t *, uint32_t, unsigned int);
+extern int _rwlock_write_lock_timeout(rwlock_t *, uint32_t, unsigned int);
 
 #endif
Index: kernel/generic/include/synch/semaphore.h
===================================================================
--- kernel/generic/include/synch/semaphore.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/synch/semaphore.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -46,12 +46,14 @@
 #define semaphore_down(s) \
 	_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)
+
 #define semaphore_down_timeout(s, usec) \
 	_semaphore_down_timeout((s), (usec), SYNCH_FLAGS_NONE)
 
-extern void semaphore_initialize(semaphore_t *s, int val);
-extern int _semaphore_down_timeout(semaphore_t *s, uint32_t usec, int flags);
-extern void semaphore_up(semaphore_t *s);
+extern void semaphore_initialize(semaphore_t *, int);
+extern int _semaphore_down_timeout(semaphore_t *, uint32_t, unsigned int);
+extern void semaphore_up(semaphore_t *);
 
 #endif
Index: kernel/generic/include/synch/spinlock.h
===================================================================
--- kernel/generic/include/synch/spinlock.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/synch/spinlock.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -170,5 +170,5 @@
 #define SPINLOCK_STATIC_INITIALIZE_NAME(name, desc_name)
 
-#define ASSERT_SPINLOCK(expr, lock)
+#define ASSERT_SPINLOCK(expr, lock)  ASSERT(expr)
 
 #define spinlock_initialize(lock, name)
Index: kernel/generic/include/synch/waitq.h
===================================================================
--- kernel/generic/include/synch/waitq.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/synch/waitq.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -46,17 +46,20 @@
 } wakeup_mode_t;
 
-/** Wait queue structure. */
+/** Wait queue structure.
+ *
+ */
 typedef struct {
-
 	/** Lock protecting wait queue structure.
 	 *
 	 * Must be acquired before T.lock for each T of type thread_t.
 	 */
-	SPINLOCK_DECLARE(lock);
-
+	IRQ_SPINLOCK_DECLARE(lock);
+	
 	/**
 	 * 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;
@@ -69,7 +72,7 @@
 
 extern void waitq_initialize(waitq_t *);
-extern int waitq_sleep_timeout(waitq_t *, uint32_t, int);
+extern int waitq_sleep_timeout(waitq_t *, uint32_t, unsigned int);
 extern ipl_t waitq_sleep_prepare(waitq_t *);
-extern int waitq_sleep_timeout_unsafe(waitq_t *, uint32_t, int);
+extern int waitq_sleep_timeout_unsafe(waitq_t *, uint32_t, unsigned int);
 extern void waitq_sleep_finish(waitq_t *, int, ipl_t);
 extern void waitq_wakeup(waitq_t *, wakeup_mode_t);
Index: kernel/generic/include/sysinfo/abi.h
===================================================================
--- kernel/generic/include/sysinfo/abi.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/sysinfo/abi.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -38,5 +38,5 @@
 
 /** Number of load components */
-#define LOAD_STEPS        3
+#define LOAD_STEPS  3
 
 /** Maximum task name size */
@@ -65,5 +65,5 @@
  */
 typedef struct {
-	unsigned int id;         /**< CPU ID as stored by kernel */
+	size_t id;               /**< CPU ID as stored by kernel */
 	bool active;             /**< CPU is activate */
 	uint16_t frequency_mhz;  /**< Frequency in MHz */
Index: kernel/generic/include/time/timeout.h
===================================================================
--- kernel/generic/include/time/timeout.h	(revision 666f492f56681952d58041f88d5bbb968548091c)
+++ kernel/generic/include/time/timeout.h	(revision 009536837631ac26b2e7a16e52b4c9525d2cd095)
@@ -43,9 +43,9 @@
 
 typedef struct {
-	SPINLOCK_DECLARE(lock);
-
+	IRQ_SPINLOCK_DECLARE(lock);
+	
 	/** Link to the list of active timeouts on THE->cpu */
 	link_t link;
-	/** Timeout will be activated in this amount of clock() ticks. */	
+	/** Timeout will be activated in this amount of clock() ticks. */
 	uint64_t ticks;
 	/** Function that will be called on timeout activation. */
@@ -57,12 +57,11 @@
 } timeout_t;
 
-#define us2ticks(us)	((uint64_t) (((uint32_t) (us) / (1000000 / HZ))))
+#define us2ticks(us)  ((uint64_t) (((uint32_t) (us) / (1000000 / HZ))))
 
 extern void timeout_init(void);
-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 bool timeout_unregister(timeout_t *t);
+extern void timeout_initialize(timeout_t *);
+extern void timeout_reinitialize(timeout_t *);
+extern void timeout_register(timeout_t *, uint64_t, timeout_handler_t, void *);
+extern bool timeout_unregister(timeout_t *);
 
 #endif
