Index: kernel/arch/amd64/src/ddi/ddi.c
===================================================================
--- kernel/arch/amd64/src/ddi/ddi.c	(revision 849ed54afbef3ad0ec3af831e93a1353f9eaaf0f)
+++ kernel/arch/amd64/src/ddi/ddi.c	(revision e805e2f1beaacf14e865a559f418ceaab6314422)
@@ -49,30 +49,27 @@
  * Interrupts are disabled and task is locked.
  *
- * @param task Task.
+ * @param task   Task.
  * @param ioaddr Startign I/O space address.
- * @param size Size of the enabled I/O range.
+ * @param size   Size of the enabled I/O range.
  *
  * @return 0 on success or an error code from errno.h.
+ *
  */
 int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size)
 {
-	size_t bits;
-	
-	bits = ioaddr + size;
+	size_t bits = ioaddr + size;
 	if (bits > IO_PORTS)
 		return ENOENT;
 	
 	if (task->arch.iomap.bits < bits) {
-		bitmap_t oldiomap;
-		uint8_t *newmap;
-		
 		/*
 		 * The I/O permission bitmap is too small and needs to be grown.
 		 */
 		
-		newmap = (uint8_t *) malloc(BITS2BYTES(bits), FRAME_ATOMIC);
+		uint8_t *newmap = (uint8_t *) malloc(BITS2BYTES(bits), FRAME_ATOMIC);
 		if (!newmap)
 			return ENOMEM;
 		
+		bitmap_t oldiomap;
 		bitmap_initialize(&oldiomap, task->arch.iomap.map,
 		    task->arch.iomap.bits);
@@ -115,23 +112,20 @@
  *
  * Interrupts must be disabled prior this call.
+ *
  */
 void io_perm_bitmap_install(void)
 {
-	size_t bits;
-	ptr_16_64_t cpugdtr;
-	descriptor_t *gdt_p;
-	tss_descriptor_t *tss_desc;
-	size_t ver;
-	
 	/* First, copy the I/O Permission Bitmap. */
-	spinlock_lock(&TASK->lock);
-	ver = TASK->arch.iomapver;
-	if ((bits = TASK->arch.iomap.bits)) {
+	irq_spinlock_lock(&TASK->lock, false);
+	size_t ver = TASK->arch.iomapver;
+	size_t bits = TASK->arch.iomap.bits;
+	if (bits) {
+		ASSERT(TASK->arch.iomap.map);
+		
 		bitmap_t iomap;
-	
-		ASSERT(TASK->arch.iomap.map);
 		bitmap_initialize(&iomap, CPU->arch.tss->iomap,
 		    TSS_IOMAP_SIZE * 8);
 		bitmap_copy(&iomap, &TASK->arch.iomap, TASK->arch.iomap.bits);
+		
 		/*
 		 * It is safe to set the trailing eight bits because of the
@@ -140,5 +134,5 @@
 		bitmap_set_range(&iomap, ALIGN_UP(TASK->arch.iomap.bits, 8), 8);
 	}
-	spinlock_unlock(&TASK->lock);
+	irq_spinlock_unlock(&TASK->lock, false);
 	
 	/*
@@ -146,6 +140,8 @@
 	 * Take the extra ending byte will all bits set into account. 
 	 */
+	ptr_16_64_t cpugdtr;
 	gdtr_store(&cpugdtr);
-	gdt_p = (descriptor_t *) cpugdtr.base;
+	
+	descriptor_t *gdt_p = (descriptor_t *) cpugdtr.base;
 	gdt_tss_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + BITS2BYTES(bits));
 	gdtr_load(&cpugdtr);
@@ -155,5 +151,5 @@
 	 * type must be changed to describe inactive TSS.
 	 */
-	tss_desc = (tss_descriptor_t *) &gdt_p[TSS_DES];
+	tss_descriptor_t *tss_desc = (tss_descriptor_t *) &gdt_p[TSS_DES];
 	tss_desc->type = AR_TSS;
 	tr_load(gdtselector(TSS_DES));
Index: kernel/arch/amd64/src/debugger.c
===================================================================
--- kernel/arch/amd64/src/debugger.c	(revision 849ed54afbef3ad0ec3af831e93a1353f9eaaf0f)
+++ kernel/arch/amd64/src/debugger.c	(revision e805e2f1beaacf14e865a559f418ceaab6314422)
@@ -46,16 +46,27 @@
 #include <symtab.h>
 
+#ifdef __64_BITS__
+	#define getip(x)  ((x)->rip)
+#endif
+
+#ifdef __32_BITS__
+	#define getip(x)  ((x)->eip)
+#endif
+
 typedef struct  {
-	uintptr_t address;      /**< Breakpoint address */
-	int flags;              /**< Flags regarding breakpoint */
-	int counter;            /**< How many times the exception occured */
+	uintptr_t address;   /**< Breakpoint address */
+	unsigned int flags;  /**< Flags regarding breakpoint */
+	size_t counter;      /**< How many times the exception occured */
 } bpinfo_t;
 
 static bpinfo_t breakpoints[BKPOINTS_MAX];
-SPINLOCK_INITIALIZE(bkpoint_lock);
+IRQ_SPINLOCK_STATIC_INITIALIZE(bkpoint_lock);
 
 #ifdef CONFIG_KCONSOLE
 
-static int cmd_print_breakpoints(cmd_arg_t *argv);
+static int cmd_print_breakpoints(cmd_arg_t *);
+static int cmd_del_breakpoint(cmd_arg_t *);
+static int cmd_add_breakpoint(cmd_arg_t *);
+
 static cmd_info_t bkpts_info = {
 	.name = "bkpts",
@@ -65,11 +76,11 @@
 };
 
-static int cmd_del_breakpoint(cmd_arg_t *argv);
 static cmd_arg_t del_argv = {
 	.type = ARG_TYPE_INT
 };
+
 static cmd_info_t delbkpt_info = {
 	.name = "delbkpt",
-	.description = "delbkpt <number> - Delete breakpoint.",
+	.description = "Delete breakpoint.",
 	.func = cmd_del_breakpoint,
 	.argc = 1,
@@ -77,11 +88,11 @@
 };
 
-static int cmd_add_breakpoint(cmd_arg_t *argv);
 static cmd_arg_t add_argv = {
 	.type = ARG_TYPE_INT
 };
+
 static cmd_info_t addbkpt_info = {
 	.name = "addbkpt",
-	.description = "addbkpt <&symbol> - new breakpoint.",
+	.description = "Add breakpoint.",
 	.func = cmd_add_breakpoint,
 	.argc = 1,
@@ -92,7 +103,8 @@
 	.type = ARG_TYPE_INT
 };
+
 static cmd_info_t addwatchp_info = {
 	.name = "addwatchp",
-	.description = "addbwatchp <&symbol> - new write watchpoint.",
+	.description = "Add write watchpoint.",
 	.func = cmd_add_breakpoint,
 	.argc = 1,
@@ -102,16 +114,20 @@
 #endif /* CONFIG_KCONSOLE */
 
-/* Setup DR register according to table */
+/** Setup DR register according to table
+ *
+ */
 static void setup_dr(int curidx)
 {
-	unative_t dr7;
+	ASSERT(curidx >= 0);
+	
 	bpinfo_t *cur = &breakpoints[curidx];
-	int flags = breakpoints[curidx].flags;
-
+	unsigned int flags = breakpoints[curidx].flags;
+	
 	/* Disable breakpoint in DR7 */
-	dr7 = read_dr7();
-	dr7 &= ~(0x2 << (curidx*2));
-
-	if (cur->address) { /* Setup DR register */
+	unative_t dr7 = read_dr7();
+	dr7 &= ~(0x2 << (curidx * 2));
+	
+	/* Setup DR register */
+	if (cur->address) {
 		/* Set breakpoint to debug registers */
 		switch (curidx) {
@@ -129,15 +145,14 @@
 			break;
 		}
+		
 		/* Set type to requested breakpoint & length*/
-		dr7 &= ~ (0x3 << (16 + 4*curidx));
-		dr7 &= ~ (0x3 << (18 + 4*curidx));
-		if ((flags & BKPOINT_INSTR)) {
-			;
-		} else {
+		dr7 &= ~(0x3 << (16 + 4 * curidx));
+		dr7 &= ~(0x3 << (18 + 4 * curidx));
 		
+		if (!(flags & BKPOINT_INSTR)) {
 #ifdef __32_BITS__
 			dr7 |= ((unative_t) 0x3) << (18 + 4 * curidx);
 #endif
-
+			
 #ifdef __64_BITS__
 			dr7 |= ((unative_t) 0x2) << (18 + 4 * curidx);
@@ -149,76 +164,70 @@
 				dr7 |= ((unative_t) 0x3) << (16 + 4 * curidx);
 		}
-
+		
 		/* Enable global breakpoint */
 		dr7 |= 0x2 << (curidx * 2);
-
+		
 		write_dr7(dr7);
-		
-	} 
-}
-	
+	}
+}
+
 /** Enable hardware breakpoint
  *
  * @param where Address of HW breakpoint
  * @param flags Type of breakpoint (EXECUTE, WRITE)
+ *
  * @return Debug slot on success, -1 - no available HW breakpoint
- */
-int breakpoint_add(const void *where, const int flags, int curidx)
-{
-	ipl_t ipl;
-	int i;
-	bpinfo_t *cur;
-
+ *
+ */
+int breakpoint_add(const void *where, const unsigned int flags, int curidx)
+{
 	ASSERT(flags & (BKPOINT_INSTR | BKPOINT_WRITE | BKPOINT_READ_WRITE));
-
-	ipl = interrupts_disable();
-	spinlock_lock(&bkpoint_lock);
+	
+	irq_spinlock_lock(&bkpoint_lock, true);
 	
 	if (curidx == -1) {
 		/* Find free space in slots */
-		for (i = 0; i < BKPOINTS_MAX; i++)
+		unsigned int i;
+		for (i = 0; i < BKPOINTS_MAX; i++) {
 			if (!breakpoints[i].address) {
 				curidx = i;
 				break;
 			}
+		}
+		
 		if (curidx == -1) {
 			/* Too many breakpoints */
-			spinlock_unlock(&bkpoint_lock);
-			interrupts_restore(ipl);
+			irq_spinlock_unlock(&bkpoint_lock, true);
 			return -1;
 		}
 	}
-	cur = &breakpoints[curidx];
-
+	
+	bpinfo_t *cur = &breakpoints[curidx];
+	
 	cur->address = (uintptr_t) where;
 	cur->flags = flags;
 	cur->counter = 0;
-
+	
 	setup_dr(curidx);
-
-	spinlock_unlock(&bkpoint_lock);
-	interrupts_restore(ipl);
-
+	
+	irq_spinlock_unlock(&bkpoint_lock, true);
+	
 	/* Send IPI */
 //	ipi_broadcast(VECTOR_DEBUG_IPI);
-
+	
 	return curidx;
 }
 
-#ifdef __64_BITS__
-	#define getip(x)  ((x)->rip)
-#else
-	#define getip(x)  ((x)->eip)
-#endif
-
 static void handle_exception(int slot, istate_t *istate)
 {
+	ASSERT(slot >= 0);
 	ASSERT(breakpoints[slot].address);
-
+	
 	/* Handle zero checker */
-	if (! (breakpoints[slot].flags & BKPOINT_INSTR)) {
+	if (!(breakpoints[slot].flags & BKPOINT_INSTR)) {
 		if ((breakpoints[slot].flags & BKPOINT_CHECK_ZERO)) {
 			if (*((unative_t *) breakpoints[slot].address) != 0)
 				return;
+			
 			printf("*** Found ZERO on address %lx (slot %d) ***\n",
 			    breakpoints[slot].address, slot);
@@ -228,8 +237,8 @@
 		}
 	}
-
+	
 	printf("Reached breakpoint %d:%lx (%s)\n", slot, getip(istate),
 	    symtab_fmt_name_lookup(getip(istate)));
-
+	
 #ifdef CONFIG_KCONSOLE
 	atomic_set(&haltstate, 1);
@@ -241,42 +250,37 @@
 void breakpoint_del(int slot)
 {
-	bpinfo_t *cur;
-	ipl_t ipl;
-
-	ipl = interrupts_disable();
-	spinlock_lock(&bkpoint_lock);
-
-	cur = &breakpoints[slot];
+	ASSERT(slot >= 0);
+	
+	irq_spinlock_lock(&bkpoint_lock, true);
+	
+	bpinfo_t *cur = &breakpoints[slot];
 	if (!cur->address) {
-		spinlock_unlock(&bkpoint_lock);
-		interrupts_restore(ipl);
+		irq_spinlock_unlock(&bkpoint_lock, true);
 		return;
 	}
-
+	
 	cur->address = NULL;
-
+	
 	setup_dr(slot);
-
-	spinlock_unlock(&bkpoint_lock);
-	interrupts_restore(ipl);
+	
+	irq_spinlock_unlock(&bkpoint_lock, true);
 //	ipi_broadcast(VECTOR_DEBUG_IPI);
 }
 
-
-
 static void debug_exception(int n __attribute__((unused)), istate_t *istate)
 {
-	unative_t dr6;
-	int i;
-	
 	/* Set RF to restart the instruction  */
 #ifdef __64_BITS__
 	istate->rflags |= RFLAGS_RF;
-#else
+#endif
+	
+#ifdef __32_BITS__
 	istate->eflags |= EFLAGS_RF;
 #endif
-
-	dr6 = read_dr6();
-	for (i=0; i < BKPOINTS_MAX; i++) {
+	
+	unative_t dr6 = read_dr6();
+	
+	unsigned int i;
+	for (i = 0; i < BKPOINTS_MAX; i++) {
 		if (dr6 & (1 << i)) {
 			dr6 &= ~ (1 << i);
@@ -289,38 +293,39 @@
 
 #ifdef CONFIG_SMP
-static void
-debug_ipi(int n __attribute__((unused)),
+static void debug_ipi(int n __attribute__((unused)),
     istate_t *istate __attribute__((unused)))
 {
-	int i;
-
-	spinlock_lock(&bkpoint_lock);
+	irq_spinlock_lock(&bkpoint_lock, false);
+	
+	unsigned int i;
 	for (i = 0; i < BKPOINTS_MAX; i++)
 		setup_dr(i);
-	spinlock_unlock(&bkpoint_lock);
-}
-#endif
-
-/** Initialize debugger */
+	
+	irq_spinlock_unlock(&bkpoint_lock, false);
+}
+#endif /* CONFIG_SMP */
+
+/** Initialize debugger
+ *
+ */
 void debugger_init()
 {
-	int i;
-
+	unsigned int i;
 	for (i = 0; i < BKPOINTS_MAX; i++)
 		breakpoints[i].address = NULL;
-
+	
 #ifdef CONFIG_KCONSOLE
 	cmd_initialize(&bkpts_info);
 	if (!cmd_register(&bkpts_info))
 		printf("Cannot register command %s\n", bkpts_info.name);
-
+	
 	cmd_initialize(&delbkpt_info);
 	if (!cmd_register(&delbkpt_info))
 		printf("Cannot register command %s\n", delbkpt_info.name);
-
+	
 	cmd_initialize(&addbkpt_info);
 	if (!cmd_register(&addbkpt_info))
 		printf("Cannot register command %s\n", addbkpt_info.name);
-
+	
 	cmd_initialize(&addwatchp_info);
 	if (!cmd_register(&addwatchp_info))
@@ -331,18 +336,18 @@
 #ifdef CONFIG_SMP
 	exc_register(VECTOR_DEBUG_IPI, "debugger_smp", debug_ipi);
-#endif
+#endif /* CONFIG_SMP */
 }
 
 #ifdef CONFIG_KCONSOLE
-/** Print table of active breakpoints */
+/** Print table of active breakpoints
+ *
+ */
 int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused)))
 {
-	unsigned int i;
-
 #ifdef __32_BITS__
 	printf("#  Count Address    In symbol\n");
 	printf("-- ----- ---------- ---------\n");
 #endif
-
+	
 #ifdef __64_BITS__
 	printf("#  Count Address            In symbol\n");
@@ -350,26 +355,30 @@
 #endif
 	
-	for (i = 0; i < BKPOINTS_MAX; i++)
+	unsigned int i;
+	for (i = 0; i < BKPOINTS_MAX; i++) {
 		if (breakpoints[i].address) {
 			const char *symbol = symtab_fmt_name_lookup(
 			    breakpoints[i].address);
-
+			
 #ifdef __32_BITS__
-			printf("%-2u %-5d %#10zx %s\n", i,
+			printf("%-2u %-5" PRIs " %p %s\n", i,
 			    breakpoints[i].counter, breakpoints[i].address,
 			    symbol);
 #endif
-
+			
 #ifdef __64_BITS__
-			printf("%-2u %-5d %#18zx %s\n", i,
+			printf("%-2u %-5" PRIs " %p %s\n", i,
 			    breakpoints[i].counter, breakpoints[i].address,
 			    symbol);
 #endif
-
-		}
+		}
+	}
+	
 	return 1;
 }
 
-/** Remove breakpoint from table */
+/** Remove breakpoint from table
+ *
+ */
 int cmd_del_breakpoint(cmd_arg_t *argv)
 {
@@ -379,21 +388,23 @@
 		return 0;
 	}
+	
 	breakpoint_del(argv->intval);
 	return 1;
 }
 
-/** Add new breakpoint to table */
+/** Add new breakpoint to table
+ *
+ */
 static int cmd_add_breakpoint(cmd_arg_t *argv)
 {
-	int flags;
-	int id;
-
-	if (argv == &add_argv) {
+	unsigned int flags;
+	if (argv == &add_argv)
 		flags = BKPOINT_INSTR;
-	} else { /* addwatchp */
+	else
 		flags = BKPOINT_WRITE;
-	}
+	
 	printf("Adding breakpoint on address: %p\n", argv->intval);
-	id = breakpoint_add((void *)argv->intval, flags, -1);
+	
+	int id = breakpoint_add((void *)argv->intval, flags, -1);
 	if (id < 0)
 		printf("Add breakpoint failed.\n");
Index: kernel/arch/amd64/src/interrupt.c
===================================================================
--- kernel/arch/amd64/src/interrupt.c	(revision 849ed54afbef3ad0ec3af831e93a1353f9eaaf0f)
+++ kernel/arch/amd64/src/interrupt.c	(revision e805e2f1beaacf14e865a559f418ceaab6314422)
@@ -106,14 +106,14 @@
 }
 
-/** General Protection Fault. */
+/** General Protection Fault.
+ *
+ */
 static void gp_fault(int n, istate_t *istate)
 {
 	if (TASK) {
-		size_t ver;
-
-		spinlock_lock(&TASK->lock);
-		ver = TASK->arch.iomapver;
-		spinlock_unlock(&TASK->lock);
-
+		irq_spinlock_lock(&TASK->lock, false);
+		size_t ver = TASK->arch.iomapver;
+		irq_spinlock_unlock(&TASK->lock, false);
+		
 		if (CPU->arch.iomapver_copy != ver) {
 			/*
@@ -129,5 +129,5 @@
 		fault_if_from_uspace(istate, "General protection fault.");
 	}
-
+	
 	decode_istate(n, istate);
 	panic("General protection fault.");
@@ -159,5 +159,7 @@
 #endif
 
-/** Handler of IRQ exceptions */
+/** Handler of IRQ exceptions.
+ *
+ */
 static void irq_interrupt(int n, istate_t *istate)
 {
@@ -174,5 +176,5 @@
 		 * The IRQ handler was found.
 		 */
-		 
+		
 		if (irq->preack) {
 			/* Send EOI before processing the interrupt */
@@ -181,5 +183,5 @@
 		}
 		irq->handler(irq);
-		spinlock_unlock(&irq->lock);
+		irq_spinlock_unlock(&irq->lock, false);
 	} else {
 		/*
