Index: kernel/Makefile
===================================================================
--- kernel/Makefile	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ kernel/Makefile	(revision eee047c85698831f5ac6ee46aa25807c7a0ae06a)
@@ -160,5 +160,4 @@
 	CFLAGS = $(GCC_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
-	INSTRUMENTATION = -finstrument-functions
 endif
 
@@ -166,5 +165,4 @@
 	CFLAGS = $(GCC_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
-	INSTRUMENTATION = -finstrument-functions
 endif
 
@@ -172,5 +170,4 @@
 	CFLAGS = $(ICC_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
-	INSTRUMENTATION =
 endif
 
@@ -179,5 +176,4 @@
 	DEFS += $(CONFIG_DEFS)
 	DEPEND_DEFS = $(DEFS)
-	INSTRUMENTATION =
 endif
 
@@ -185,5 +181,4 @@
 	CFLAGS = $(CLANG_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
-	INSTRUMENTATION =
 endif
 
@@ -207,5 +202,4 @@
 	generic/src/debug/stacktrace.c \
 	generic/src/debug/panic.c \
-	generic/src/debug/debug.c \
 	generic/src/interrupt/interrupt.c \
 	generic/src/main/main.c \
@@ -361,13 +355,4 @@
 endif
 
-## Sources where instrumentation is enabled
-#
-
-ifeq ($(CONFIG_LOG),y)
-INSTRUMENTED_SOURCES = \
-	generic/src/cpu/cpu.c \
-	generic/src/main/kinit.c
-endif
-
 GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
 ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES)))
@@ -429,5 +414,5 @@
 
 %.o: %.c $(DEPEND)
-	$(CC) $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) $(FPU_NO_CFLAGS) $(if $(findstring $<,$(INSTRUMENTED_SOURCES)),$(INSTRUMENTATION)) -c -o $@ $<
+	$(CC) $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) $(FPU_NO_CFLAGS) -c -o $@ $<
 ifeq ($(PRECHECK),y)
 	$(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) $(FPU_NO_CFLAGS)
Index: kernel/arch/amd64/src/boot/boot.S
===================================================================
--- kernel/arch/amd64/src/boot/boot.S	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ kernel/arch/amd64/src/boot/boot.S	(revision eee047c85698831f5ac6ee46aa25807c7a0ae06a)
@@ -1,31 +1,31 @@
-/*
- * Copyright (c) 2005 Ondrej Palkovsky
- * Copyright (c) 2006 Martin Decky
- * Copyright (c) 2008 Jakub Jermar
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
+#
+# Copyright (c) 2005 Ondrej Palkovsky
+# Copyright (c) 2006 Martin Decky
+# Copyright (c) 2008 Jakub Jermar
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
 
 #include <arch/boot/boot.h>
@@ -37,30 +37,9 @@
 #include <arch/cpuid.h>
 
-#define START_STACK  (BOOT_OFFSET - BOOT_STACK_SIZE)
+#define START_STACK	(BOOT_OFFSET - BOOT_STACK_SIZE)
 
 .section K_TEXT_START, "ax"
 
 .code32
-
-.macro pm_error msg
-	movl \msg, %esi
-	jmp pm_error_halt
-.endm
-
-.macro pm_status msg
-#ifdef CONFIG_EGA
-	pushl %esi
-	movl \msg, %esi
-	call pm_early_puts
-	popl %esi
-#endif
-.endm
-
-.macro pm2_status msg
-#ifndef CONFIG_FB
-	pm_status \msg
-#endif
-.endm
-
 .align 4
 .global multiboot_image_start
@@ -68,5 +47,5 @@
 	.long MULTIBOOT_HEADER_MAGIC
 	.long MULTIBOOT_HEADER_FLAGS
-	.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)  /* checksum */
+	.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)  # checksum
 	.long multiboot_header
 	.long unmapped_ktext_start
@@ -77,21 +56,17 @@
 multiboot_image_start:
 	cld
-	
-	/* Initialize stack pointer */
-	movl $START_STACK, %esp
-	
-	/* Initialize Global Descriptor Table register */
-	lgdtl bootstrap_gdtr
-	
-	/* Kernel data + stack */
+	movl $START_STACK, %esp             # initialize stack pointer
+	lgdtl bootstrap_gdtr                # initialize Global Descriptor Table register
+	
 	movw $gdtselector(KDATA_DES), %cx
 	movw %cx, %es
-	movw %cx, %ds
+	movw %cx, %ds                       # kernel data + stack
 	movw %cx, %ss
 	
-	/*
-	 * Simics seems to remove hidden part of GS on entering user mode
-	 * when _visible_ part of GS does not point to user-mode segment.
-	 */
+	#
+	# Simics seems to remove hidden part of GS on entering user mode
+	# when _visible_ part of GS does not point to user-mode segment.
+	#
+	
 	movw $gdtselector(UDATA_DES), %cx
 	movw %cx, %fs
@@ -101,9 +76,11 @@
 	multiboot_meeting_point:
 	
-	/* Save GRUB arguments */
-	movl %eax, grub_eax
+	movl %eax, grub_eax                 # save parameters from GRUB
 	movl %ebx, grub_ebx
 	
-	pm_status $status_prot
+	#
+	# Protected 32-bit. We want to reuse the code-seg descriptor,
+	# the Default operand size must not be 1 when entering long mode.
+	#
 	
 	movl $(INTEL_CPUID_EXTENDED), %eax
@@ -112,5 +89,6 @@
 	ja extended_cpuid_supported
 	
-		pm_error $err_extended_cpuid
+		movl $extended_cpuid_msg, %esi
+		jmp error_halt
 	
 	extended_cpuid_supported:
@@ -121,5 +99,6 @@
 	jc long_mode_supported
 	
-		pm_error $err_long_mode
+		movl $long_mode_msg, %esi
+		jmp error_halt
 	
 	long_mode_supported:
@@ -128,5 +107,6 @@
 	jc noexecute_supported
 	
-		pm_error $err_noexecute
+		movl $noexecute_msg, %esi
+		jmp error_halt
 	
 	noexecute_supported:
@@ -137,5 +117,6 @@
 	jc fx_supported
 	
-		pm_error $err_fx
+		movl $fx_msg, %esi
+		jmp error_halt
 	
 	fx_supported:
@@ -144,21 +125,15 @@
 	jc sse2_supported
 	
-		pm_error $err_sse2
+		movl $sse2_msg, %esi
+		jmp error_halt
 	
 	sse2_supported:
-	
+
 #include "vesa_prot.inc"
-	
-	/*
-	 * Protected 32-bit. We want to reuse the code-seg descriptor,
-	 * the Default operand size must not be 1 when entering long mode.
-	 */
-	
-	pm2_status $status_prot2
-	
-	/*
-	 * Enable 64-bit page translation entries - CR4.PAE = 1.
-	 * Paging is not enabled until after long mode is enabled.
-	 */
+
+	#
+	# Enable 64-bit page translation entries - CR4.PAE = 1.
+	# Paging is not enabled until after long mode is enabled.
+	#
 	
 	movl %cr4, %eax
@@ -166,39 +141,59 @@
 	movl %eax, %cr4
 	
-	/* Set up paging tables */
+	# set up paging tables
+	
 	leal ptl_0, %eax
 	movl %eax, %cr3
 	
-	/* Enable long mode */
-	movl $EFER_MSR_NUM, %ecx
-	rdmsr                     /* read EFER */
-	btsl $AMD_LME_FLAG, %eax  /* set LME = 1 */
-	wrmsr
-	
-	/* Enable paging to activate long mode (set CR0.PG = 1) */
+	# enable long mode
+	
+	movl $EFER_MSR_NUM, %ecx            # EFER MSR number
+	rdmsr                               # read EFER
+	btsl $AMD_LME_FLAG, %eax            # set LME = 1
+	wrmsr                               # write EFER
+	
+	# enable paging to activate long mode (set CR0.PG = 1)
+	
 	movl %cr0, %eax
 	btsl $31, %eax
 	movl %eax, %cr0
 	
-	/* At this point we are in compatibility mode */
+	# at this point we are in compatibility mode
+	
 	jmpl $gdtselector(KTEXT_DES), $start64
 
-/** Print string to EGA display (in light red) and halt.
- *
- * Should be executed from 32 bit protected mode with paging
- * turned off. Stack is not required. This routine is used even
- * if CONFIG_EGA is not enabled. Since we are going to halt the
- * CPU anyway, it is always better to at least try to print
- * some hints.
- *
- * @param %esi NULL-terminated string to print.
- *
- */
-pm_error_halt:
-	movl $0xb8000, %edi  /* base of EGA text mode memory */
+.code64
+start64:
+	movq $(PA2KA(START_STACK)), %rsp
+	
+	# call arch_pre_main(grub_eax, grub_ebx)
+	xorq %rdi, %rdi
+	movl grub_eax, %edi
+	xorq %rsi, %rsi
+	movl grub_ebx, %esi
+	
+	movabsq $arch_pre_main, %rax
+	callq *%rax
+	
+	# create the first stack frame
+	pushq $0
+	movq %rsp, %rbp
+	
+	movabsq $main_bsp, %rax
+	call *%rax
+	
+	# not reached
+	
+	cli
+	hlt0:
+		hlt
+		jmp hlt0
+
+# Print string from %esi to EGA display (in red) and halt
+error_halt:
+	movl $0xb8000, %edi       # base of EGA text mode memory
 	xorl %eax, %eax
 	
-	/* Read bits 8 - 15 of the cursor address */
-	movw $0x3d4, %dx
+	movw $0x3d4, %dx          # read bits 8 - 15 of the cursor address
 	movb $0xe, %al
 	outb %al, %dx
@@ -208,6 +203,5 @@
 	shl $8, %ax
 	
-	/* Read bits 0 - 7 of the cursor address */
-	movw $0x3d4, %dx
+	movw $0x3d4, %dx          # read bits 0 - 7 of the cursor address
 	movb $0xf, %al
 	outb %al, %dx
@@ -216,11 +210,10 @@
 	inb %dx, %al
 	
-	/* Sanity check for the cursor on screen */
-	cmp $2000, %ax
-	jb err_cursor_ok
-	
-		movw $1998, %ax
-	
-	err_cursor_ok:
+	cmp $1920, %ax
+	jbe cursor_ok
+	
+		movw $1920, %ax       # sanity check for the cursor on the last line
+	
+	cursor_ok:
 	
 	movw %ax, %bx
@@ -228,40 +221,16 @@
 	addl %eax, %edi
 	
-	err_ploop:
+	movw $0x0c00, %ax         # black background, light red foreground
+	
+	ploop:
 		lodsb
-		
 		cmp $0, %al
-		je err_ploop_end
-		
-		movb $0x0c, %ah  /* black background, light red foreground */
+		je ploop_end
 		stosw
-		
-		/* Sanity check for the cursor on the last line */
 		inc %bx
-		cmp $2000, %bx
-		jb err_ploop
-		
-		/* Scroll the screen (24 rows) */
-		movl %esi, %edx
-		movl $0xb80a0, %esi
-		movl $0xb8000, %edi
-		movl $1920, %ecx
-		rep movsw
-		
-		/* Clear the 24th row */
-		xorl %eax, %eax
-		movl $80, %ecx
-		rep stosw
-		
-		/* Go to row 24 */
-		movl %edx, %esi
-		movl $0xb8f00, %edi
-		movw $1920, %bx
-		
-		jmp err_ploop
-	err_ploop_end:
-	
-	/* Write bits 8 - 15 of the cursor address */
-	movw $0x3d4, %dx
+		jmp ploop
+	ploop_end:
+	
+	movw $0x3d4, %dx          # write bits 8 - 15 of the cursor address
 	movb $0xe, %al
 	outb %al, %dx
@@ -271,6 +240,5 @@
 	outb %al, %dx
 	
-	/* Write bits 0 - 7 of the cursor address */
-	movw $0x3d4, %dx
+	movw $0x3d4, %dx          # write bits 0 - 7 of the cursor address
 	movb $0xf, %al
 	outb %al, %dx
@@ -285,284 +253,13 @@
 		jmp hlt1
 
-/** Print string to EGA display (in light green).
- *
- * Should be called from 32 bit protected mode with paging
- * turned off. A stack space of at least 24 bytes is required,
- * but the function does not establish a stack frame.
- *
- * Macros such as pm_status and pm2_status take care that
- * this function is used only when CONFIG_EGA is enabled
- * and CONFIG_FB is disabled.
- *
- * @param %esi NULL-terminated string to print.
- *
- */
-pm_early_puts:
-	pushl %eax
-	pushl %ebx
-	pushl %ecx
-	pushl %edx
-	pushl %edi
-	
-	movl $0xb8000, %edi  /* base of EGA text mode memory */
-	xorl %eax, %eax
-	
-	/* Read bits 8 - 15 of the cursor address */
-	movw $0x3d4, %dx
-	movb $0xe, %al
-	outb %al, %dx
-	
-	movw $0x3d5, %dx
-	inb %dx, %al
-	shl $8, %ax
-	
-	/* Read bits 0 - 7 of the cursor address */
-	movw $0x3d4, %dx
-	movb $0xf, %al
-	outb %al, %dx
-	
-	movw $0x3d5, %dx
-	inb %dx, %al
-	
-	/* Sanity check for the cursor on screen */
-	cmp $2000, %ax
-	jb pm_puts_cursor_ok
-	
-		movw $1998, %ax
-	
-	pm_puts_cursor_ok:
-	
-	movw %ax, %bx
-	shl $1, %eax
-	addl %eax, %edi
-	
-	pm_puts_ploop:
-		lodsb
-		
-		cmp $0, %al
-		je pm_puts_ploop_end
-		
-		movb $0x0a, %ah  /* black background, light green foreground */
-		stosw
-		
-		/* Sanity check for the cursor on the last line */
-		inc %bx
-		cmp $2000, %bx
-		jb pm_puts_ploop
-		
-		/* Scroll the screen (24 rows) */
-		movl %esi, %edx
-		movl $0xb80a0, %esi
-		movl $0xb8000, %edi
-		movl $1920, %ecx
-		rep movsw
-		
-		/* Clear the 24th row */
-		xorl %eax, %eax
-		movl $80, %ecx
-		rep stosw
-		
-		/* Go to row 24 */
-		movl %edx, %esi
-		movl $0xb8f00, %edi
-		movw $1920, %bx
-		
-		jmp pm_puts_ploop
-	pm_puts_ploop_end:
-	
-	/* Write bits 8 - 15 of the cursor address */
-	movw $0x3d4, %dx
-	movb $0xe, %al
-	outb %al, %dx
-	
-	movw $0x3d5, %dx
-	movb %bh, %al
-	outb %al, %dx
-	
-	/* Write bits 0 - 7 of the cursor address */
-	movw $0x3d4, %dx
-	movb $0xf, %al
-	outb %al, %dx
-	
-	movw $0x3d5, %dx
-	movb %bl, %al
-	outb %al, %dx
-	
-	popl %edi
-	popl %edx
-	popl %ecx
-	popl %ebx
-	popl %eax
-	
-	ret
-
-.code64
-
-.macro long_status msg
-	pushq %rdi
-	movq \msg, %rdi
-	call early_puts
-	popq %rdi
-.endm
-
-start64:
-	
-	/*
-	 * Long mode.
-	 */
-	
-	movq $(PA2KA(START_STACK)), %rsp
-	
-	/* Create the first stack frame */
-	pushq $0
-	movq %rsp, %rbp
-	
-	long_status $status_long
-	
-	/* Call arch_pre_main(grub_eax, grub_ebx) */
-	xorq %rdi, %rdi
-	movl grub_eax, %edi
-	xorq %rsi, %rsi
-	movl grub_ebx, %esi
-	
-	movabsq $arch_pre_main, %rax
-	callq *%rax
-	
-	long_status $status_main
-	
-	/* Call main_bsp() */
-	movabsq $main_bsp, %rax
-	call *%rax
-	
-	/* Not reached */
-	cli
-	hlt0:
-		hlt
-		jmp hlt0
-
-/** Print string to EGA display.
- *
- * Should be called from long mode (with paging enabled
- * and stack established). This function is ABI compliant
- * (without red-zone).
- *
- * If CONFIG_EGA is undefined or CONFIG_FB is defined
- * then this function does nothing.
- *
- * @param %rdi NULL-terminated string to print.
- *
- */
-early_puts:
-	
-#if ((defined(CONFIG_EGA)) && (!defined(CONFIG_FB)))
-	
-	/* Prologue, save preserved registers */
-	pushq %rbp
-	movq %rsp, %rbp
-	pushq %rbx
-	
-	movq %rdi, %rsi
-	movq $(PA2KA(0xb8000)), %rdi  /* base of EGA text mode memory */
-	xorq %rax, %rax
-	
-	/* Read bits 8 - 15 of the cursor address */
-	movw $0x3d4, %dx
-	movb $0xe, %al
-	outb %al, %dx
-	
-	movw $0x3d5, %dx
-	inb %dx, %al
-	shl $8, %ax
-	
-	/* Read bits 0 - 7 of the cursor address */
-	movw $0x3d4, %dx
-	movb $0xf, %al
-	outb %al, %dx
-	
-	movw $0x3d5, %dx
-	inb %dx, %al
-	
-	/* Sanity check for the cursor on screen */
-	cmp $2000, %ax
-	jb early_puts_cursor_ok
-	
-		movw $1998, %ax
-	
-	early_puts_cursor_ok:
-	
-	movw %ax, %bx
-	shl $1, %rax
-	addq %rax, %rdi
-	
-	early_puts_ploop:
-		lodsb
-		
-		cmp $0, %al
-		je early_puts_ploop_end
-		
-		movb $0x0e, %ah  /* black background, yellow foreground */
-		stosw
-		
-		/* Sanity check for the cursor on the last line */
-		inc %bx
-		cmp $2000, %bx
-		jb early_puts_ploop
-		
-		/* Scroll the screen (24 rows) */
-		movq %rsi, %rdx
-		movq $(PA2KA(0xb80a0)), %rsi
-		movq $(PA2KA(0xb8000)), %rdi
-		movq $1920, %rcx
-		rep movsw
-		
-		/* Clear the 24th row */
-		xorq %rax, %rax
-		movq $80, %rcx
-		rep stosw
-		
-		/* Go to row 24 */
-		movq %rdx, %rsi
-		movq $(PA2KA(0xb8f00)), %rdi
-		movw $1920, %bx
-		
-		jmp early_puts_ploop
-	early_puts_ploop_end:
-	
-	/* Write bits 8 - 15 of the cursor address */
-	movw $0x3d4, %dx
-	movb $0xe, %al
-	outb %al, %dx
-	
-	movw $0x3d5, %dx
-	movb %bh, %al
-	outb %al, %dx
-	
-	/* Write bits 0 - 7 of the cursor address */
-	movw $0x3d4, %dx
-	movb $0xf, %al
-	outb %al, %dx
-	
-	movw $0x3d5, %dx
-	movb %bl, %al
-	outb %al, %dx
-	
-	/* Epilogue, restore preserved registers */
-	popq %rbx
-	leave
-	
-#endif
-	
-	ret
-
 #include "vesa_real.inc"
 
 .section K_INI_PTLS, "aw", @progbits
 
-/** Generate initial page table contents.
- *
- * @param cnt Number of entries to generate. Must be multiple of 8.
- * @param g   Number of GB that will be added to the mapping.
- *
- */
+#
+# Macro for generating initial page table contents.
+# @param cnt Number of entries to generate. Must be multiple of 8.
+# @param g   Number of GB that will be added to the mapping.
+#
 .macro ptl2gen cnt g
 	.if \cnt
@@ -579,40 +276,40 @@
 .endm
 
-/* Page table for pages in the 1st gigabyte. */
+# Page table for pages in the 1st gigabyte.
 .align 4096
 ptl_2_0g:
 	ptl2gen 512 0
 
-/* Page table for pages in the 2nd gigabyte. */
+# Page table for pages in the 2nd gigabyte.
 .align 4096
 ptl_2_1g:
 	ptl2gen 512 1
 
-/* Page table for pages in the 3rd gigabyte. */
+# Page table for pages in the 3rd gigabyte.
 .align 4096
 ptl_2_2g:
 	ptl2gen 512 2
 
-/* Page table for pages in the 4th gigabyte. */
+# Page table for pages in the 4th gigabyte.
 .align 4096
 ptl_2_3g:
 	ptl2gen 512 3
 
-/* Page table for pages in the 5th gigabyte. */
+# Page table for pages in the 5th gigabyte.
 .align 4096
 ptl_2_4g:
 	ptl2gen 512 3
 
-/* Page table for pages in the 6th gigabyte. */
+# Page table for pages in the 6th gigabyte.
 .align 4096
 ptl_2_5g:
 	ptl2gen 512 3
 
-/* Page table for pages in the 7th gigabyte. */
+# Page table for pages in the 7th gigabyte.
 .align 4096
 ptl_2_6g:
 	ptl2gen 512 3
 
-/* Page table for pages in the 8th gigabyte. */
+# Page table for pages in the 8th gigabyte.
 .align 4096
 ptl_2_7g:
@@ -621,5 +318,5 @@
 .align 4096
 ptl_1:
-	/* Identity mapping for [0; 8G) */
+	# Identity mapping for [0; 8G)
 	.quad ptl_2_0g + (PTL_WRITABLE | PTL_PRESENT)
 	.quad ptl_2_1g + (PTL_WRITABLE | PTL_PRESENT)
@@ -653,27 +350,12 @@
 	.long 0
 
-err_extended_cpuid:
+extended_cpuid_msg:
 	.asciz "Error: Extended CPUID not supported -- CPU is not 64-bit. System halted."
-err_long_mode:
+long_mode_msg:
 	.asciz "Error: 64-bit long mode not supported. System halted."
-err_noexecute:
+noexecute_msg:
 	.asciz "Error: No-execute pages not supported. System halted."
-err_fx:
+fx_msg:
 	.asciz "Error: FXSAVE/FXRESTORE instructions not supported. System halted."
-err_sse2:
+sse2_msg:
 	.asciz "Error: SSE2 instructions not supported. System halted."
-
-status_prot:
-	.asciz "[prot] "
-status_vesa_copy:
-	.asciz "[vesa_copy] "
-status_grub_cmdline:
-	.asciz "[grub_cmdline] "
-status_vesa_real:
-	.asciz "[vesa_real] "
-status_prot2:
-	.asciz "[prot2] "
-status_long:
-	.asciz "[long] "
-status_main:
-	.asciz "[main] "
Index: kernel/arch/amd64/src/boot/vesa_ret.inc
===================================================================
--- kernel/arch/amd64/src/boot/vesa_ret.inc	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ kernel/arch/amd64/src/boot/vesa_ret.inc	(revision eee047c85698831f5ac6ee46aa25807c7a0ae06a)
@@ -1,19 +1,13 @@
 .code32
 vesa_init_protected:
-	cld
-	
-	/* Initialize stack pointer */
-	movl $START_STACK, %esp
-	
-	/* Kernel data + stack */
 	movw $gdtselector(KDATA_DES), %cx
 	movw %cx, %es
-	movw %cx, %ds
+	movw %cx, %ds                       # kernel data + stack
 	movw %cx, %ss
 	
-	/*
-	 * Simics seems to remove hidden part of GS on entering user mode
-	 * when _visible_ part of GS does not point to user-mode segment.
-	 */
+	#
+	# Simics seems to remove hidden part of GS on entering user mode
+	# when _visible_ part of GS does not point to user-mode segment.
+	#
 	
 	movw $gdtselector(UDATA_DES), %cx
@@ -21,3 +15,5 @@
 	movw %cx, %gs
 	
+	movl $START_STACK, %esp             # initialize stack pointer
+	
 	jmpl $gdtselector(KTEXT32_DES), $vesa_meeting_point
Index: kernel/arch/ia32/include/smp/apic.h
===================================================================
--- kernel/arch/ia32/include/smp/apic.h	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ kernel/arch/ia32/include/smp/apic.h	(revision eee047c85698831f5ac6ee46aa25807c7a0ae06a)
@@ -347,5 +347,4 @@
 
 extern uint32_t apic_id_mask;
-extern uint8_t bsp_l_apic;
 
 extern void apic_init(void);
@@ -356,4 +355,5 @@
 extern int l_apic_send_init_ipi(uint8_t);
 extern void l_apic_debug(void);
+extern uint8_t l_apic_id(void);
 
 extern uint32_t io_apic_read(uint8_t);
Index: kernel/arch/ia32/src/boot/boot.S
===================================================================
--- kernel/arch/ia32/src/boot/boot.S	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ kernel/arch/ia32/src/boot/boot.S	(revision eee047c85698831f5ac6ee46aa25807c7a0ae06a)
@@ -1,30 +1,30 @@
-/*
- * Copyright (c) 2001 Jakub Jermar
- * Copyright (c) 2005 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
+#
+# Copyright (c) 2001-2004 Jakub Jermar
+# Copyright (c) 2005-2006 Martin Decky
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
 
 #include <arch/boot/boot.h>
@@ -34,29 +34,9 @@
 #include <arch/cpuid.h>
 
-#define START_STACK  (BOOT_OFFSET - BOOT_STACK_SIZE)
+#define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE)
 
 .section K_TEXT_START, "ax"
 
 .code32
-
-.macro pm_error msg
-	movl \msg, %esi
-	jmp pm_error_halt
-.endm
-
-.macro pm_status msg
-#ifdef CONFIG_EGA
-	pushl %esi
-	movl \msg, %esi
-	call pm_early_puts
-	popl %esi
-#endif
-.endm
-
-.macro pm2_status msg
-	pushl \msg
-	call early_puts
-.endm
-
 .align 4
 .global multiboot_image_start
@@ -64,5 +44,5 @@
 	.long MULTIBOOT_HEADER_MAGIC
 	.long MULTIBOOT_HEADER_FLAGS
-	.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)  /* checksum */
+	.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)  # checksum
 	.long multiboot_header
 	.long unmapped_ktext_start
@@ -73,17 +53,12 @@
 multiboot_image_start:
 	cld
-	
-	/* Initialize stack pointer */
-	movl $START_STACK, %esp
-	
-	/* Initialize Global Descriptor Table register */
-	lgdtl KA2PA(bootstrap_gdtr)
-	
-	/* Kernel data + stack */
+	movl $START_STACK, %esp     # initialize stack pointer
+	lgdt KA2PA(bootstrap_gdtr)  # initialize Global Descriptor Table register
+	
 	movw $gdtselector(KDATA_DES), %cx
 	movw %cx, %es
 	movw %cx, %fs
 	movw %cx, %gs
-	movw %cx, %ds
+	movw %cx, %ds               # kernel data + stack
 	movw %cx, %ss
 	
@@ -91,13 +66,10 @@
 	multiboot_meeting_point:
 	
-	/* Save GRUB arguments */
-	movl %eax, grub_eax
+	movl %eax, grub_eax         # save parameters from GRUB
 	movl %ebx, grub_ebx
-	
-	pm_status $status_prot
 	
 	movl $(INTEL_CPUID_LEVEL), %eax
 	cpuid
-	cmp $0x0, %eax  /* any function > 0? */
+	cmp $0x0, %eax              # any function > 0?
 	jbe pse_unsupported
 	
@@ -108,31 +80,26 @@
 	
 	pse_unsupported:
-		
-		pm_error $err_pse
+		movl $pse_msg, %esi
+		jmp error_halt
 	
 	pse_supported:
 	
 #include "vesa_prot.inc"
-	
-	/* Map kernel and turn paging on */
+
+	# map kernel and turn paging on
 	call map_kernel
 	
-	/* Create the first stack frame */
-	pushl $0
-	movl %esp, %ebp
-	
-	pm2_status $status_prot2
-	
-	/* Call arch_pre_main(grub_eax, grub_ebx) */
+	# call arch_pre_main(grub_eax, grub_ebx)
 	pushl grub_ebx
 	pushl grub_eax
 	call arch_pre_main
-	
-	pm2_status $status_main
-	
-	/* Call main_bsp() */
+
+	# Create the first stack frame
+	pushl $0
+	movl %esp, %ebp
+	
 	call main_bsp
 	
-	/* Not reached */
+	# not reached
 	cli
 	hlt0:
@@ -140,15 +107,13 @@
 		jmp hlt0
 
-/** Setup mapping for the kernel.
- *
- * Setup mapping for both the unmapped and mapped sections
- * of the kernel. For simplicity, we map the entire 4G space.
- *
- */
 .global map_kernel
 map_kernel:
+	#
+	# Here we setup mapping for both the unmapped and mapped sections of the kernel.
+	# For simplicity, we map the entire 4G space.
+	#
 	movl %cr4, %ecx
-	orl $(1 << 4), %ecx      /* PSE on */
-	andl $(~(1 << 5)), %ecx  /* PAE off */
+	orl $(1 << 4), %ecx                 # turn PSE on
+	andl $(~(1 << 5)), %ecx             # turn PAE off
 	movl %ecx, %cr4
 	
@@ -161,8 +126,6 @@
 		movl $((1 << 7) | (1 << 1) | (1 << 0)), %eax
 		orl %ebx, %eax
-		/* Mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */
-		movl %eax, (%esi, %ecx, 4)
-		/* Mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */
-		movl %eax, (%edi, %ecx, 4)
+		movl %eax, (%esi, %ecx, 4)      # mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M
+		movl %eax, (%edi, %ecx, 4)      # mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M
 		addl $(4 * 1024 * 1024), %ebx
 		
@@ -174,25 +137,14 @@
 	
 	movl %cr0, %ebx
-	orl $(1 << 31), %ebx  /* paging on */
+	orl $(1 << 31), %ebx                # turn paging on
 	movl %ebx, %cr0
 	ret
 
-/** Print string to EGA display (in light red) and halt.
- *
- * Should be executed from 32 bit protected mode with paging
- * turned off. Stack is not required. This routine is used even
- * if CONFIG_EGA is not enabled. Since we are going to halt the
- * CPU anyway, it is always better to at least try to print
- * some hints.
- *
- * @param %esi NULL-terminated string to print.
- *
- */
-pm_error_halt:
-	movl $0xb8000, %edi  /* base of EGA text mode memory */
+# Print string from %esi to EGA display (in red) and halt
+error_halt:
+	movl $0xb8000, %edi         # base of EGA text mode memory
 	xorl %eax, %eax
 	
-	/* Read bits 8 - 15 of the cursor address */
-	movw $0x3d4, %dx
+	movw $0x3d4, %dx            # read bits 8 - 15 of the cursor address
 	movb $0xe, %al
 	outb %al, %dx
@@ -202,6 +154,5 @@
 	shl $8, %ax
 	
-	/* Read bits 0 - 7 of the cursor address */
-	movw $0x3d4, %dx
+	movw $0x3d4, %dx            # read bits 0 - 7 of the cursor address
 	movb $0xf, %al
 	outb %al, %dx
@@ -210,11 +161,10 @@
 	inb %dx, %al
 	
-	/* Sanity check for the cursor on screen */
-	cmp $2000, %ax
-	jb err_cursor_ok
-	
-		movw $1998, %ax
-	
-	err_cursor_ok:
+	cmp $1920, %ax
+	jbe cursor_ok
+	
+		movw $1920, %ax         # sanity check for the cursor on the last line
+	
+	cursor_ok:
 	
 	movw %ax, %bx
@@ -222,40 +172,16 @@
 	addl %eax, %edi
 	
-	err_ploop:
+	movw $0x0c00, %ax           # black background, light red foreground
+	
+	ploop:
 		lodsb
-		
 		cmp $0, %al
-		je err_ploop_end
-		
-		movb $0x0c, %ah  /* black background, light red foreground */
+		je ploop_end
 		stosw
-		
-		/* Sanity check for the cursor on the last line */
 		inc %bx
-		cmp $2000, %bx
-		jb err_ploop
-		
-		/* Scroll the screen (24 rows) */
-		movl %esi, %edx
-		movl $0xb80a0, %esi
-		movl $0xb8000, %edi
-		movl $1920, %ecx
-		rep movsw
-		
-		/* Clear the 24th row */
-		xorl %eax, %eax
-		movl $80, %ecx
-		rep stosw
-		
-		/* Go to row 24 */
-		movl %edx, %esi
-		movl $0xb8f00, %edi
-		movw $1920, %bx
-		
-		jmp err_ploop
-	err_ploop_end:
-	
-	/* Write bits 8 - 15 of the cursor address */
-	movw $0x3d4, %dx
+		jmp ploop
+	ploop_end:
+	
+	movw $0x3d4, %dx            # write bits 8 - 15 of the cursor address
 	movb $0xe, %al
 	outb %al, %dx
@@ -265,6 +191,5 @@
 	outb %al, %dx
 	
-	/* Write bits 0 - 7 of the cursor address */
-	movw $0x3d4, %dx
+	movw $0x3d4, %dx            # write bits 0 - 7 of the cursor address
 	movb $0xf, %al
 	outb %al, %dx
@@ -279,232 +204,4 @@
 		jmp hlt1
 
-/** Print string to EGA display (in light green).
- *
- * Should be called from 32 bit protected mode with paging
- * turned off. A stack space of at least 24 bytes is required,
- * but the function does not establish a stack frame.
- *
- * Macros such as pm_status take care that this function
- * is used only when CONFIG_EGA is enabled.
- *
- * @param %esi NULL-terminated string to print.
- *
- */
-pm_early_puts:
-	pushl %eax
-	pushl %ebx
-	pushl %ecx
-	pushl %edx
-	pushl %edi
-	
-	movl $0xb8000, %edi  /* base of EGA text mode memory */
-	xorl %eax, %eax
-	
-	/* Read bits 8 - 15 of the cursor address */
-	movw $0x3d4, %dx
-	movb $0xe, %al
-	outb %al, %dx
-	
-	movw $0x3d5, %dx
-	inb %dx, %al
-	shl $8, %ax
-	
-	/* Read bits 0 - 7 of the cursor address */
-	movw $0x3d4, %dx
-	movb $0xf, %al
-	outb %al, %dx
-	
-	movw $0x3d5, %dx
-	inb %dx, %al
-	
-	/* Sanity check for the cursor on screen */
-	cmp $2000, %ax
-	jb pm_puts_cursor_ok
-	
-		movw $1998, %ax
-	
-	pm_puts_cursor_ok:
-	
-	movw %ax, %bx
-	shl $1, %eax
-	addl %eax, %edi
-	
-	pm_puts_ploop:
-		lodsb
-		
-		cmp $0, %al
-		je pm_puts_ploop_end
-		
-		movb $0x0a, %ah  /* black background, light green foreground */
-		stosw
-		
-		/* Sanity check for the cursor on the last line */
-		inc %bx
-		cmp $2000, %bx
-		jb pm_puts_ploop
-		
-		/* Scroll the screen (24 rows) */
-		movl %esi, %edx
-		movl $0xb80a0, %esi
-		movl $0xb8000, %edi
-		movl $1920, %ecx
-		rep movsw
-		
-		/* Clear the 24th row */
-		xorl %eax, %eax
-		movl $80, %ecx
-		rep stosw
-		
-		/* Go to row 24 */
-		movl %edx, %esi
-		movl $0xb8f00, %edi
-		movw $1920, %bx
-		
-		jmp pm_puts_ploop
-	pm_puts_ploop_end:
-	
-	/* Write bits 8 - 15 of the cursor address */
-	movw $0x3d4, %dx
-	movb $0xe, %al
-	outb %al, %dx
-	
-	movw $0x3d5, %dx
-	movb %bh, %al
-	outb %al, %dx
-	
-	/* Write bits 0 - 7 of the cursor address */
-	movw $0x3d4, %dx
-	movb $0xf, %al
-	outb %al, %dx
-	
-	movw $0x3d5, %dx
-	movb %bl, %al
-	outb %al, %dx
-	
-	popl %edi
-	popl %edx
-	popl %ecx
-	popl %ebx
-	popl %eax
-	
-	ret
-
-/** Print string to EGA display.
- *
- * Should be called from 32 bit protected mode (with paging
- * enabled and stack established). This function is ABI compliant.
- *
- * If CONFIG_EGA is undefined or CONFIG_FB is defined
- * then this function does nothing.
- *
- * @param %ebp+0x08 NULL-terminated string to print.
- *
- */
-early_puts:
-	
-#if ((defined(CONFIG_EGA)) && (!defined(CONFIG_FB)))
-	
-	/* Prologue, save preserved registers */
-	pushl %ebp
-	movl %esp, %ebp
-	pushl %ebx
-	pushl %esi
-	pushl %edi
-	
-	movl 0x08(%ebp), %esi
-	movl $(PA2KA(0xb8000)), %edi  /* base of EGA text mode memory */
-	xorl %eax, %eax
-	
-	/* Read bits 8 - 15 of the cursor address */
-	movw $0x3d4, %dx
-	movb $0xe, %al
-	outb %al, %dx
-	
-	movw $0x3d5, %dx
-	inb %dx, %al
-	shl $8, %ax
-	
-	/* Read bits 0 - 7 of the cursor address */
-	movw $0x3d4, %dx
-	movb $0xf, %al
-	outb %al, %dx
-	
-	movw $0x3d5, %dx
-	inb %dx, %al
-	
-	/* Sanity check for the cursor on screen */
-	cmp $2000, %ax
-	jb early_puts_cursor_ok
-	
-		movw $1998, %ax
-	
-	early_puts_cursor_ok:
-	
-	movw %ax, %bx
-	shl $1, %eax
-	addl %eax, %edi
-	
-	early_puts_ploop:
-		lodsb
-		
-		cmp $0, %al
-		je early_puts_ploop_end
-		
-		movb $0x0e, %ah  /* black background, yellow foreground */
-		stosw
-		
-		/* Sanity check for the cursor on the last line */
-		inc %bx
-		cmp $2000, %bx
-		jb early_puts_ploop
-		
-		/* Scroll the screen (24 rows) */
-		movl %esi, %edx
-		movl $(PA2KA(0xb80a0)), %esi
-		movl $(PA2KA(0xb8000)), %edi
-		movl $1920, %ecx
-		rep movsw
-		
-		/* Clear the 24th row */
-		xorl %eax, %eax
-		movl $80, %ecx
-		rep stosw
-		
-		/* Go to row 24 */
-		movl %edx, %esi
-		movl $(PA2KA(0xb8f00)), %edi
-		movw $1920, %bx
-		
-		jmp early_puts_ploop
-	early_puts_ploop_end:
-	
-	/* Write bits 8 - 15 of the cursor address */
-	movw $0x3d4, %dx
-	movb $0xe, %al
-	outb %al, %dx
-	
-	movw $0x3d5, %dx
-	movb %bh, %al
-	outb %al, %dx
-	
-	/* Write bits 0 - 7 of the cursor address */
-	movw $0x3d4, %dx
-	movb $0xf, %al
-	outb %al, %dx
-	
-	movw $0x3d5, %dx
-	movb %bl, %al
-	outb %al, %dx
-	
-	/* Epilogue, restore preserved registers */
-	popl %edi
-	popl %esi
-	popl %ebx
-	leave
-	
-#endif
-	
-	ret
-
 #include "vesa_real.inc"
 
@@ -521,17 +218,5 @@
 	.long 0
 
-err_pse:
+pse_msg:
 	.asciz "Page Size Extension not supported. System halted."
 
-status_prot:
-	.asciz "[prot] "
-status_vesa_copy:
-	.asciz "[vesa_copy] "
-status_grub_cmdline:
-	.asciz "[grub_cmdline] "
-status_vesa_real:
-	.asciz "[vesa_real] "
-status_prot2:
-	.asciz "[prot2] "
-status_main:
-	.asciz "[main] "
Index: kernel/arch/ia32/src/boot/vesa_prot.inc
===================================================================
--- kernel/arch/ia32/src/boot/vesa_prot.inc	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ kernel/arch/ia32/src/boot/vesa_prot.inc	(revision eee047c85698831f5ac6ee46aa25807c7a0ae06a)
@@ -5,7 +5,5 @@
 #define MBINFO_OFFSET_CMDLINE   16
 
-	/* Copy real mode VESA initialization code */
-	
-	pm_status $status_vesa_copy
+	# copy real mode VESA initialization code
 	
 	mov $vesa_init, %esi
@@ -14,7 +12,5 @@
 	rep movsb
 	
-	/* Check for GRUB command line */
-	
-	pm_status $status_grub_cmdline
+	# check for GRUB command line
 	
 	mov grub_eax, %eax
@@ -27,5 +23,5 @@
 	jnc no_cmdline
 	
-	/* Skip the kernel path in command line */
+	# skip the kernel path in command line
 	
 	mov MBINFO_OFFSET_CMDLINE(%ebx), %esi
@@ -56,5 +52,5 @@
 	space_loop_done:
 	
-	/* Copy at most 23 characters from command line */
+	# copy at most 23 characters from command line
 	
 	mov $VESA_INIT_SEGMENT << 4, %edi
@@ -72,5 +68,5 @@
 	cmd_loop_done:
 	
-	/* Zero termination */
+	# zero termination
 	
 	xor %eax, %eax
@@ -79,7 +75,5 @@
 	no_cmdline:
 	
-	/* Jump to the real mode */
-	
-	pm_status $status_vesa_real
+	# jump to the real mode
 	
 	mov $VESA_INIT_SEGMENT << 4, %edi
@@ -87,5 +81,5 @@
 	
 	vesa_meeting_point:
-		/* Returned back to protected mode */
+		# returned back to protected mode
 		
 		mov %ax, KA2PA(vesa_scanline)
Index: kernel/arch/ia32/src/boot/vesa_real.inc
===================================================================
--- kernel/arch/ia32/src/boot/vesa_real.inc	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ kernel/arch/ia32/src/boot/vesa_real.inc	(revision eee047c85698831f5ac6ee46aa25807c7a0ae06a)
@@ -31,5 +31,5 @@
 vesa_init:
 	jmp $gdtselector(VESA_INIT_DES), $vesa_init_real - vesa_init
-
+	
 .code16
 vesa_init_real:
@@ -55,5 +55,5 @@
 	pushl %eax
 	
-	/* Parse default mode string */
+	# parse default mode string
 	
 	mov $default_mode - vesa_init, %di
@@ -65,5 +65,5 @@
 		mov (%di), %al
 		
-		/* Check for digit */
+		# check for digit
 		
 		cmp $'0', %al
@@ -75,5 +75,5 @@
 		sub $'0', %al
 		
-		/* Multiply default_width by 10 and add digit */
+		# multiply default_width by 10 and add digit
 		
 		mov default_width - vesa_init, %bx
@@ -96,5 +96,5 @@
 		mov (%di), %al
 		
-		/* Check for digit */
+		# check for digit
 		
 		cmp $'0', %al
@@ -106,5 +106,5 @@
 		sub $'0', %al
 		
-		/* Multiply default_height by 10 and add digit */
+		# multiply default_height by 10 and add digit
 		
 		mov default_height - vesa_init, %bx
@@ -127,5 +127,5 @@
 		mov (%di), %al
 		
-		/* Check for digit */
+		# check for digit
 		
 		cmp $'0', %al
@@ -137,5 +137,5 @@
 		sub $'0', %al
 		
-		/* Multiply default_bpp by 10 and add digit */
+		# multiply default_bpp by 10 and add digit
 		
 		mov default_bpp - vesa_init, %bx
@@ -167,6 +167,5 @@
 	
 	next_mode:
-		/* Try next mode */
-		
+		# try next mode
 		mov %gs:(%si), %cx
 		cmp $VESA_END_OF_MODES, %cx
@@ -187,8 +186,5 @@
 		jne no_mode
 		
-		/*
-		 * Check for proper attributes (supported,
-		 * color, graphics, linear framebuffer).
-		 */
+		# check for proper attributes (supported, color, graphics, linear framebuffer)
 		
 		mov VESA_MODE_ATTRIBUTES_OFFSET(%di), %ax
@@ -197,5 +193,5 @@
 		jne next_mode
 		
-		/* Check for proper resolution */
+		# check for proper resolution
 		
 		mov default_width - vesa_init, %ax
@@ -207,5 +203,5 @@
 		jne next_mode
 		
-		/* Check for proper bpp */
+		# check for proper bpp
 		
 		mov default_bpp - vesa_init, %al
@@ -217,5 +213,5 @@
 		jne next_mode
 		
-		/* For 24 bpp modes accept also 32 bit bpp */
+		# for 24 bpp modes accept also 32 bit bpp
 		
 		mov $32, %al
@@ -234,5 +230,5 @@
 		jnz no_mode
 		
-		/* Set 3:2:3 VGA palette */
+		# set 3:2:3 VGA palette
 		
 		mov VESA_MODE_BPP_OFFSET(%di), %al
@@ -245,10 +241,8 @@
 		mov $0x100, %ecx
 		
-		/* Test if VGA compatible registers are present */
-		bt $5, %ax
+		bt $5, %ax              # test if VGA compatible registers are present
 		jnc vga_compat
 		
-			/* Use VESA routine to set the palette */
-			
+			# try VESA routine to set palette
 			mov $VESA_SET_PALETTE, %ax
 			xor %bl, %bl
@@ -260,16 +254,14 @@
 		
 		vga_compat:
-			
-			/* Use VGA registers to set the palette */
-			
-			movw $0x3c6, %dx  /* set palette mask */
+			# try VGA registers to set palette
+			movw $0x3c6, %dx    # set palette mask
 			movb $0xff, %al
 			outb %al, %dx
 			
-			movw $0x3c8, %dx  /* first index to set */
+			movw $0x3c8, %dx    # first index to set
 			xor %al, %al
 			outb %al, %dx
 			
-			movw $0x3c9, %dx  /* data port */
+			movw $0x3c9, %dx    # data port
 			
 			vga_loop:
@@ -292,12 +284,10 @@
 		vga_not_set:
 		
-		/*
-		 * Store mode parameters:
-		 *  eax = bpp[8] scanline[16]
-		 *  ebx = width[16]  height[16]
-		 *  edx = red_mask[8] red_pos[8] green_mask[8] green_pos[8]
-		 *  esi = blue_mask[8] blue_pos[8]
-		 *  edi = linear frame buffer
-		 */
+		# store mode parameters
+		#  eax = bpp[8] scanline[16]
+		#  ebx = width[16]  height[16]
+		#  edx = red_mask[8] red_pos[8] green_mask[8] green_pos[8]
+		#  esi = blue_mask[8] blue_pos[8]
+		#  edi = linear frame buffer
 		
 		mov VESA_MODE_BPP_OFFSET(%di), %al
@@ -338,7 +328,5 @@
 	
 	no_mode:
-		
-		/* No prefered mode found */
-		
+		# no prefered mode found
 		mov $0x111, %cx
 		push %di
@@ -351,15 +339,13 @@
 		cmp $VESA_OK, %al
 		jnz text_mode
-		jz set_mode  /* force relative jump */
+		jz set_mode             # force relative jump
 	
 	text_mode:
-		
-		/* Reset to EGA text mode (because of problems with VESA) */
-		
+		# reset to EGA text mode (because of problems with VESA)
 		mov $0x0003, %ax
 		int $0x10
 		mov $0xffffffff, %edi
 		xor %ax, %ax
-		jz vesa_leave_real  /* force relative jump */
+		jz vesa_leave_real      # force relative jump
 
 vga323:
Index: kernel/arch/ia32/src/boot/vesa_ret.inc
===================================================================
--- kernel/arch/ia32/src/boot/vesa_ret.inc	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ kernel/arch/ia32/src/boot/vesa_ret.inc	(revision eee047c85698831f5ac6ee46aa25807c7a0ae06a)
@@ -1,16 +1,12 @@
 .code32
 vesa_init_protected:
-	cld
-	
-	/* Initialize stack pointer */
-	movl $START_STACK, %esp
-	
-	/* Kernel data + stack */
 	movw $gdtselector(KDATA_DES), %cx
 	movw %cx, %es
 	movw %cx, %fs
 	movw %cx, %gs
-	movw %cx, %ds
+	movw %cx, %ds               # kernel data + stack
 	movw %cx, %ss
 	
+	movl $START_STACK, %esp     # initialize stack pointer
+	
 	jmpl $gdtselector(KTEXT_DES), $vesa_meeting_point
Index: kernel/arch/ia32/src/smp/apic.c
===================================================================
--- kernel/arch/ia32/src/smp/apic.c	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ kernel/arch/ia32/src/smp/apic.c	(revision eee047c85698831f5ac6ee46aa25807c7a0ae06a)
@@ -76,6 +76,4 @@
 
 uint32_t apic_id_mask = 0;
-uint8_t bsp_l_apic = 0;
-
 static irq_t l_apic_timer_irq;
 
@@ -156,17 +154,4 @@
 }
 
-/** Get Local APIC ID.
- *
- * @return Local APIC ID.
- *
- */
-static uint8_t l_apic_id(void)
-{
-	l_apic_id_t idreg;
-	
-	idreg.value = l_apic[L_APIC_ID];
-	return idreg.apic_id;
-}
-
 /** Initialize APIC on BSP. */
 void apic_init(void)
@@ -223,6 +208,4 @@
 	l_apic_init();
 	l_apic_debug();
-	
-	bsp_l_apic = l_apic_id();
 }
 
@@ -477,31 +460,33 @@
 {
 #ifdef LAPIC_VERBOSE
-	printf("LVT on cpu%" PRIs ", LAPIC ID: %" PRIu8 "\n",
-	    CPU->id, l_apic_id());
+	printf("LVT on cpu%" PRIs ", LAPIC ID: %" PRIu8 "\n", CPU->id, l_apic_id());
 	
 	lvt_tm_t tm;
 	tm.value = l_apic[LVT_Tm];
-	printf("LVT Tm: vector=%" PRIu8 ", %s, %s, %s\n",
-	    tm.vector, delivs_str[tm.delivs], mask_str[tm.masked],
-	    tm_mode_str[tm.mode]);
+	printf("LVT Tm: vector=%hhd, %s, %s, %s\n", tm.vector, delivs_str[tm.delivs], mask_str[tm.masked], tm_mode_str[tm.mode]);
 	
 	lvt_lint_t lint;
 	lint.value = l_apic[LVT_LINT0];
-	printf("LVT LINT0: vector=%" PRIu8 ", %s, %s, %s, irr=%u, %s, %s\n",
-	    tm.vector, delmod_str[lint.delmod], delivs_str[lint.delivs],
-	    intpol_str[lint.intpol], lint.irr, trigmod_str[lint.trigger_mode],
-	    mask_str[lint.masked]);
-	
-	lint.value = l_apic[LVT_LINT1];
-	printf("LVT LINT1: vector=%" PRIu8 ", %s, %s, %s, irr=%u, %s, %s\n",
-	    tm.vector, delmod_str[lint.delmod], delivs_str[lint.delivs],
-	    intpol_str[lint.intpol], lint.irr, trigmod_str[lint.trigger_mode],
-	    mask_str[lint.masked]);
+	printf("LVT LINT0: vector=%hhd, %s, %s, %s, irr=%d, %s, %s\n", tm.vector, delmod_str[lint.delmod], delivs_str[lint.delivs], intpol_str[lint.intpol], lint.irr, trigmod_str[lint.trigger_mode], mask_str[lint.masked]);
+	lint.value = l_apic[LVT_LINT1];	
+	printf("LVT LINT1: vector=%hhd, %s, %s, %s, irr=%d, %s, %s\n", tm.vector, delmod_str[lint.delmod], delivs_str[lint.delivs], intpol_str[lint.intpol], lint.irr, trigmod_str[lint.trigger_mode], mask_str[lint.masked]);	
 	
 	lvt_error_t error;
 	error.value = l_apic[LVT_Err];
-	printf("LVT Err: vector=%" PRIu8 ", %s, %s\n", error.vector,
-	    delivs_str[error.delivs], mask_str[error.masked]);
+	printf("LVT Err: vector=%hhd, %s, %s\n", error.vector, delivs_str[error.delivs], mask_str[error.masked]);
 #endif
+}
+
+/** Get Local APIC ID.
+ *
+ * @return Local APIC ID.
+ *
+ */
+uint8_t l_apic_id(void)
+{
+	l_apic_id_t idreg;
+	
+	idreg.value = l_apic[L_APIC_ID];
+	return idreg.apic_id;
 }
 
Index: kernel/arch/ia32/src/smp/mps.c
===================================================================
--- kernel/arch/ia32/src/smp/mps.c	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ kernel/arch/ia32/src/smp/mps.c	(revision eee047c85698831f5ac6ee46aa25807c7a0ae06a)
@@ -72,5 +72,5 @@
 static size_t l_intr_entry_cnt = 0;
 
-static uint8_t mps_cpu_apic_id(size_t i)
+static uint8_t get_cpu_apic_id(size_t i)
 {
 	ASSERT(i < processor_entry_cnt);
@@ -79,5 +79,5 @@
 }
 
-static bool mps_cpu_enabled(size_t i)
+static bool is_cpu_enabled(size_t i)
 {
 	ASSERT(i < processor_entry_cnt);
@@ -85,8 +85,8 @@
 	/*
 	 * FIXME: The current local APIC driver limits usable
-	 * CPU IDs to 8.
+	 * APIC IDs to 8.
 	 *
 	 */
-	if (i > 7)
+	if (get_cpu_apic_id(i) > 7)
 		return false;
 	
@@ -94,5 +94,5 @@
 }
 
-static bool mps_cpu_bootstrap(size_t i)
+static bool is_bsp(size_t i)
 {
 	ASSERT(i < processor_entry_cnt);
@@ -118,7 +118,7 @@
  */
 struct smp_config_operations mps_config_operations = {
-	.cpu_enabled = mps_cpu_enabled,
-	.cpu_bootstrap = mps_cpu_bootstrap,
-	.cpu_apic_id = mps_cpu_apic_id,
+	.cpu_enabled = is_cpu_enabled,
+	.cpu_bootstrap = is_bsp,
+	.cpu_apic_id = get_cpu_apic_id,
 	.irq_to_pin = mps_irq_to_pin
 };
Index: kernel/arch/ia32/src/smp/smp.c
===================================================================
--- kernel/arch/ia32/src/smp/smp.c	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ kernel/arch/ia32/src/smp/smp.c	(revision eee047c85698831f5ac6ee46aa25807c7a0ae06a)
@@ -62,4 +62,7 @@
 void smp_init(void)
 {
+	uintptr_t l_apic_address;
+	uintptr_t io_apic_address;
+	
 	if (acpi_madt) {
 		acpi_madt_parse();
@@ -72,7 +75,24 @@
 	}
 	
+	l_apic_address = (uintptr_t) frame_alloc(ONE_FRAME,
+	    FRAME_ATOMIC | FRAME_KA);
+	if (!l_apic_address)
+		panic("Cannot allocate address for l_apic.");
+	
+	io_apic_address = (uintptr_t) frame_alloc(ONE_FRAME,
+	    FRAME_ATOMIC | FRAME_KA);
+	if (!io_apic_address)
+		panic("Cannot allocate address for io_apic.");
+	
 	if (config.cpu_count > 1) {
-		l_apic = (uint32_t *) hw_map((uintptr_t) l_apic, PAGE_SIZE);
-		io_apic = (uint32_t *) hw_map((uintptr_t) io_apic, PAGE_SIZE);
+		page_table_lock(AS_KERNEL, true);
+		page_mapping_insert(AS_KERNEL, l_apic_address,
+		    (uintptr_t) l_apic, PAGE_NOT_CACHEABLE | PAGE_WRITE);
+		page_mapping_insert(AS_KERNEL, io_apic_address,
+		    (uintptr_t) io_apic, PAGE_NOT_CACHEABLE | PAGE_WRITE);
+		page_table_unlock(AS_KERNEL, true);
+		
+		l_apic = (uint32_t *) l_apic_address;
+		io_apic = (uint32_t *) io_apic_address;
 	}
 }
@@ -113,4 +133,6 @@
 	apic_init();
 	
+	uint8_t apic = l_apic_id();
+	
 	for (i = 0; i < config.cpu_count; i++) {
 		/*
@@ -126,7 +148,7 @@
 			continue;
 		
-		if (ops->cpu_apic_id(i) == bsp_l_apic) {
-			printf("kmp: bad processor entry #%u, will not send IPI "
-			    "to myself\n", i);
+		if (ops->cpu_apic_id(i) == apic) {
+			printf("%s: bad processor entry #%u, will not send IPI "
+			    "to myself\n", __FUNCTION__, i);
 			continue;
 		}
Index: kernel/genarch/src/acpi/madt.c
===================================================================
--- kernel/genarch/src/acpi/madt.c	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ kernel/genarch/src/acpi/madt.c	(revision eee047c85698831f5ac6ee46aa25807c7a0ae06a)
@@ -95,8 +95,8 @@
 	/*
 	 * FIXME: The current local APIC driver limits usable
-	 * CPU IDs to 8.
+	 * APIC IDs to 8.
 	 *
 	 */
-	if (i > 7)
+	if (madt_cpu_apic_id(i) > 7)
 		return false;
 	
@@ -111,5 +111,5 @@
 	return ((struct madt_l_apic *)
 	    madt_entries_index[madt_l_apic_entry_index + i])->apic_id ==
-	    bsp_l_apic;
+	    l_apic_id();
 }
 
@@ -131,8 +131,8 @@
 };
 
-static int madt_cmp(void *a, void *b, void *arg)
-{
-	uint8_t typea = (*((struct madt_apic_header **) a))->type;
-	uint8_t typeb = (*((struct madt_apic_header **) b))->type;
+static int madt_cmp(void *a, void *b)
+{
+	uint8_t typea = ((struct madt_apic_header *) a)->type;
+	uint8_t typeb = ((struct madt_apic_header *) b)->type;
 	
 	if (typea > typeb)
@@ -147,8 +147,6 @@
 static void madt_l_apic_entry(struct madt_l_apic *la, size_t i)
 {
-	if (madt_l_apic_entry_cnt == 0)
+	if (!madt_l_apic_entry_cnt++)
 		madt_l_apic_entry_index = i;
-	
-	madt_l_apic_entry_cnt++;
 	
 	if (!(la->flags & 0x1)) {
@@ -162,5 +160,5 @@
 static void madt_io_apic_entry(struct madt_io_apic *ioa, size_t i)
 {
-	if (madt_io_apic_entry_cnt == 0) {
+	if (!madt_io_apic_entry_cnt++) {
 		/* Remember index of the first io apic entry */
 		madt_io_apic_entry_index = i;
@@ -169,6 +167,4 @@
 		/* Currently not supported */
 	}
-	
-	madt_io_apic_entry_cnt++;
 }
 
@@ -194,5 +190,5 @@
 	/* Count MADT entries */
 	unsigned int madt_entries_index_cnt = 0;
-	for (hdr = acpi_madt->apic_header; hdr < end;
+	for (hdr = &acpi_madt->apic_header[0]; hdr < end;
 	    hdr = (struct madt_apic_header *) (((uint8_t *) hdr) + hdr->length))
 		madt_entries_index_cnt++;
@@ -200,5 +196,5 @@
 	/* Create MADT APIC entries index array */
 	madt_entries_index = (struct madt_apic_header **)
-	    malloc(madt_entries_index_cnt * sizeof(struct madt_apic_header *),
+	    malloc(madt_entries_index_cnt * sizeof(struct madt_apic_header **),
 	    FRAME_ATOMIC);
 	if (!madt_entries_index)
@@ -207,14 +203,11 @@
 	size_t i = 0;
 	
-	for (hdr = acpi_madt->apic_header; hdr < end;
-	    hdr = (struct madt_apic_header *) (((uint8_t *) hdr) + hdr->length)) {
-		madt_entries_index[i] = hdr;
-		i++;
-	}
+	for (hdr = &acpi_madt->apic_header[0]; hdr < end;
+	    hdr = (struct madt_apic_header *) (((uint8_t *) hdr) + hdr->length))
+		madt_entries_index[i++] = hdr;
 	
 	/* Sort MADT index structure */
-	if (!gsort(madt_entries_index, madt_entries_index_cnt,
-	    sizeof(struct madt_apic_header *), madt_cmp, NULL))
-		panic("Sorting error.");
+	qsort(madt_entries_index, madt_entries_index_cnt, sizeof(uintptr_t),
+	    &madt_cmp);
 	
 	/* Parse MADT entries */
Index: kernel/generic/include/debug.h
===================================================================
--- kernel/generic/include/debug.h	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ kernel/generic/include/debug.h	(revision eee047c85698831f5ac6ee46aa25807c7a0ae06a)
@@ -93,17 +93,28 @@
 #define LOG(format, ...) \
 	do { \
-		printf("%s() from %s at %s:%u: " format "\n", __func__, \
-		    symtab_fmt_name_lookup(CALLER), __FILE__, __LINE__, \
-		    ##__VA_ARGS__); \
+		printf("%s->%s() at %s:%u: " format "\n", symtab_fmt_name_lookup(CALLER), \
+		    __func__, __FILE__, __LINE__, ##__VA_ARGS__); \
 	} while (0)
 
-extern void __cyg_profile_func_enter(void *, void *);
-extern void __cyg_profile_func_exit(void *, void *);
+/** Extensive logging execute macro
+ *
+ * If CONFIG_LOG is set, the LOG_EXEC() macro
+ * will print an information about calling a given
+ * function and call it.
+ *
+ */
+#define LOG_EXEC(fnc) \
+	do { \
+		printf("%s->%s() at %s:%u: " #fnc "\n", symtab_fmt_name_lookup(CALLER), \
+		    __func__, __FILE__, __LINE__); \
+		fnc; \
+	} while (0)
 
 #else /* CONFIG_LOG */
 
 #define LOG(format, ...)
+#define LOG_EXEC(fnc)     fnc
 
-#endif /* CONFIG_LOG */
+#endif /* CONFOG_LOG */
 
 #endif
Index: kernel/generic/include/sort.h
===================================================================
--- kernel/generic/include/sort.h	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ kernel/generic/include/sort.h	(revision eee047c85698831f5ac6ee46aa25807c7a0ae06a)
@@ -38,8 +38,17 @@
 #include <typedefs.h>
 
-typedef int (* sort_cmp_t)(void *, void *, void *);
+/* 
+ * sorting routines
+ */
+extern void bubblesort(void * data, size_t n, size_t e_size, int (* cmp) (void * a, void * b));
+extern void qsort(void * data, size_t n, size_t e_size, int (* cmp) (void * a, void * b));
 
-extern bool gsort(void *, size_t, size_t, sort_cmp_t, void *);
-extern bool qsort(void *, size_t, size_t, sort_cmp_t, void *);
+/*
+ * default sorting comparators
+ */
+extern int int_cmp(void * a, void * b);
+extern int uint32_t_cmp(void * a, void * b);
+extern int uint16_t_cmp(void * a, void * b);
+extern int uint8_t_cmp(void * a, void * b);
 
 #endif
Index: rnel/generic/src/debug/debug.c
===================================================================
--- kernel/generic/src/debug/debug.c	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ 	(revision )
@@ -1,76 +1,0 @@
-/*
- * Copyright (c) 2010 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup genericdebug
- * @{
- */
-
-/**
- * @file
- * @brief Kernel instrumentation functions.
- */
-
-#ifdef CONFIG_LOG
-
-#include <debug.h>
-#include <symtab.h>
-#include <errno.h>
-#include <print.h>
-
-void __cyg_profile_func_enter(void *fn, void *call_site)
-{
-	const char *fn_sym = symtab_fmt_name_lookup((uintptr_t) fn);
-	
-	const char *call_site_sym;
-	uintptr_t call_site_off;
-	
-	if (symtab_name_lookup((uintptr_t) call_site, &call_site_sym,
-	    &call_site_off) == EOK)
-		printf("%s:%p->%s\n", call_site_sym, call_site_off, fn_sym);
-	else
-		printf("->%s\n", fn_sym);
-}
-
-void __cyg_profile_func_exit(void *fn, void *call_site)
-{
-	const char *fn_sym = symtab_fmt_name_lookup((uintptr_t) fn);
-	
-	const char *call_site_sym;
-	uintptr_t call_site_off;
-	
-	if (symtab_name_lookup((uintptr_t) call_site, &call_site_sym,
-	    &call_site_off) == EOK)
-		printf("%s:%p<-%s\n", call_site_sym, call_site_off, fn_sym);
-	else
-		printf("<-%s\n", fn_sym);
-}
-
-#endif /* CONFIG_LOG */
-
-/** @}
- */
Index: kernel/generic/src/lib/sort.c
===================================================================
--- kernel/generic/src/lib/sort.c	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ kernel/generic/src/lib/sort.c	(revision eee047c85698831f5ac6ee46aa25807c7a0ae06a)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup generic
+/** @addtogroup generic	
  * @{
  */
@@ -33,59 +33,50 @@
 /**
  * @file
- * @brief Sorting functions.
+ * @brief	Sorting functions.
  *
  * This files contains functions implementing several sorting
- * algorithms (e.g. quick sort and gnome sort).
- *
- */
-
+ * algorithms (e.g. quick sort and bubble sort).
+ */
+ 
 #include <mm/slab.h>
 #include <memstr.h>
 #include <sort.h>
-
-/** Immediate buffer size.
- *
- * For small buffer sizes avoid doing malloc()
- * and use the stack.
- *
- */
-#define IBUF_SIZE  32
-
-/** Array accessor.
- *
- */
-#define INDEX(buf, i, elem_size)  ((buf) + (i) * (elem_size))
-
-/** Gnome sort
- *
- * Apply generic gnome sort algorithm on supplied data,
- * using pre-allocated buffer.
- *
- * @param data      Pointer to data to be sorted.
- * @param cnt       Number of elements to be sorted.
- * @param elem_size Size of one element.
- * @param cmp       Comparator function.
- * @param arg       3rd argument passed to cmp.
- * @param slot      Pointer to scratch memory buffer
- *                  elem_size bytes long.
- *
- */
-static void _gsort(void *data, size_t cnt, size_t elem_size, sort_cmp_t cmp,
-    void *arg, void *slot)
-{
-	size_t i = 0;
+#include <panic.h>
+
+#define EBUFSIZE	32
+
+void _qsort(void * data, size_t n, size_t e_size, int (* cmp) (void * a, void * b), void *tmp, void *pivot);
+void _bubblesort(void * data, size_t n, size_t e_size, int (* cmp) (void * a, void * b), void *slot);
+
+/** Quicksort wrapper
+ *
+ * This is only a wrapper that takes care of memory allocations for storing
+ * the pivot and temporary elements for generic quicksort algorithm.
+ * 
+ * This function _can_ sleep
+ *
+ * @param data Pointer to data to be sorted.
+ * @param n Number of elements to be sorted.
+ * @param e_size Size of one element.
+ * @param cmp Comparator function.
+ * 
+ */
+void qsort(void * data, size_t n, size_t e_size, int (* cmp) (void * a, void * b))
+{
+	uint8_t buf_tmp[EBUFSIZE];
+	uint8_t buf_pivot[EBUFSIZE];
+	void * tmp = buf_tmp;
+	void * pivot = buf_pivot;
+
+	if (e_size > EBUFSIZE) {
+		pivot = (void *) malloc(e_size, 0);
+		tmp = (void *) malloc(e_size, 0);
+	}
+
+	_qsort(data, n, e_size, cmp, tmp, pivot);
 	
-	while (i < cnt) {
-		if ((i > 0) &&
-		    (cmp(INDEX(data, i, elem_size),
-		    INDEX(data, i - 1, elem_size), arg) == -1)) {
-			memcpy(slot, INDEX(data, i, elem_size), elem_size);
-			memcpy(INDEX(data, i, elem_size), INDEX(data, i - 1, elem_size),
-			    elem_size);
-			memcpy(INDEX(data, i - 1, elem_size), slot, elem_size);
-			printf("exch: %u %u\n", i - 1, i);
-			i--;
-		} else
-			i++;
+	if (e_size > EBUFSIZE) {
+		free(tmp);
+		free(pivot);
 	}
 }
@@ -93,134 +84,121 @@
 /** Quicksort
  *
- * Apply generic quicksort algorithm on supplied data,
- * using pre-allocated buffers.
- *
- * @param data      Pointer to data to be sorted.
- * @param cnt       Number of elements to be sorted.
- * @param elem_size Size of one element.
- * @param cmp       Comparator function.
- * @param arg       3rd argument passed to cmp.
- * @param slot      Pointer to scratch memory buffer
- *                  elem_size bytes long.
- * @param pivot     Pointer to scratch memory buffer
- *                  elem_size bytes long.
- *
- */
-static void _qsort(void *data, size_t cnt, size_t elem_size, sort_cmp_t cmp,
-    void *arg, void *slot, void *pivot)
-{
-	if (cnt > 4) {
-		size_t i = 0;
-		size_t j = cnt - 1;
-		
-		memcpy(pivot, data, elem_size);
-		
-		while (true) {
-			while ((cmp(INDEX(data, i, elem_size), pivot, arg) < 0) && (i < cnt))
+ * Apply generic quicksort algorithm on supplied data, using pre-allocated buffers.
+ * 
+ * @param data Pointer to data to be sorted.
+ * @param n Number of elements to be sorted.
+ * @param e_size Size of one element.
+ * @param cmp Comparator function.
+ * @param tmp Pointer to scratch memory buffer e_size bytes long.
+ * @param pivot Pointer to scratch memory buffer e_size bytes long.
+ * 
+ */
+void _qsort(void * data, size_t n, size_t e_size, int (* cmp) (void * a, void * b), void *tmp, void *pivot)
+{
+	if (n > 4) {
+		unsigned int i = 0, j = n - 1;
+
+		memcpy(pivot, data, e_size);
+
+		while (1) {
+			while ((cmp(data + i * e_size, pivot) < 0) && (i < n))
 				i++;
-			
-			while ((cmp(INDEX(data, j, elem_size), pivot, arg) >= 0) && (j > 0))
+			while ((cmp(data + j * e_size, pivot) >= 0) && (j > 0))
 				j--;
 			
 			if (i < j) {
-				memcpy(slot, INDEX(data, i, elem_size), elem_size);
-				memcpy(INDEX(data, i, elem_size), INDEX(data, j, elem_size),
-				    elem_size);
-				memcpy(INDEX(data, j, elem_size), slot, elem_size);
-			} else
+				memcpy(tmp, data + i * e_size, e_size);
+				memcpy(data + i * e_size, data + j * e_size, e_size);
+				memcpy(data + j * e_size, tmp, e_size);
+			} else {
 				break;
+			}
 		}
-		
-		_qsort(data, j + 1, elem_size, cmp, arg, slot, pivot);
-		_qsort(INDEX(data, j + 1, elem_size), cnt - j - 1, elem_size,
-		    cmp, arg, slot, pivot);
-	} else
-		_gsort(data, cnt, elem_size, cmp, arg, slot);
-}
-
-/** Gnome sort wrapper
- *
- * This is only a wrapper that takes care of memory
- * allocations for storing the slot element for generic
- * gnome sort algorithm.
- *
- * This function can sleep.
- *
- * @param data      Pointer to data to be sorted.
- * @param cnt       Number of elements to be sorted.
- * @param elem_size Size of one element.
- * @param cmp       Comparator function.
- * @param arg       3rd argument passed to cmp.
- *
- * @return True if sorting succeeded.
- *
- */
-bool gsort(void *data, size_t cnt, size_t elem_size, sort_cmp_t cmp, void *arg)
-{
-	uint8_t ibuf_slot[IBUF_SIZE];
-	void *slot;
+
+		_qsort(data, j + 1, e_size, cmp, tmp, pivot);
+		_qsort(data + (j + 1) * e_size, n - j - 1, e_size, cmp, tmp, pivot);
+	} else {
+		_bubblesort(data, n, e_size, cmp, tmp);
+	}
+}
+
+/** Bubblesort wrapper
+ *
+ * This is only a wrapper that takes care of memory allocation for storing
+ * the slot element for generic bubblesort algorithm.
+ * 
+ * @param data Pointer to data to be sorted.
+ * @param n Number of elements to be sorted.
+ * @param e_size Size of one element.
+ * @param cmp Comparator function.
+ * 
+ */
+void bubblesort(void * data, size_t n, size_t e_size, int (* cmp) (void * a, void * b))
+{
+	uint8_t buf_slot[EBUFSIZE];
+	void * slot = buf_slot;
 	
-	if (elem_size > IBUF_SIZE) {
-		slot = (void *) malloc(elem_size, 0);
-		if (!slot)
-			return false;
-	} else
-		slot = (void *) ibuf_slot;
+	if (e_size > EBUFSIZE) {
+		slot = (void *) malloc(e_size, 0);
+	}
+
+	_bubblesort(data, n, e_size, cmp, slot);
 	
-	_gsort(data, cnt, elem_size, cmp, arg, slot);
-	
-	if (elem_size > IBUF_SIZE)
+	if (e_size > EBUFSIZE) {
 		free(slot);
-	
-	return true;
-}
-
-/** Quicksort wrapper
- *
- * This is only a wrapper that takes care of memory
- * allocations for storing the pivot and temporary elements
- * for generic quicksort algorithm.
- *
- * This function can sleep.
- *
- * @param data      Pointer to data to be sorted.
- * @param cnt       Number of elements to be sorted.
- * @param elem_size Size of one element.
- * @param cmp       Comparator function.
- * @param arg       3rd argument passed to cmp.
- *
- * @return True if sorting succeeded.
- *
- */
-bool qsort(void *data, size_t cnt, size_t elem_size, sort_cmp_t cmp, void *arg)
-{
-	uint8_t ibuf_slot[IBUF_SIZE];
-	uint8_t ibuf_pivot[IBUF_SIZE];
-	void *slot;
-	void *pivot;
-	
-	if (elem_size > IBUF_SIZE) {
-		slot = (void *) malloc(elem_size, 0);
-		if (!slot)
-			return false;
-		
-		pivot = (void *) malloc(elem_size, 0);
-		if (!pivot) {
-			free(slot);
-			return false;
+	}
+}
+
+/** Bubblesort
+ *
+ * Apply generic bubblesort algorithm on supplied data, using pre-allocated buffer.
+ * 
+ * @param data Pointer to data to be sorted.
+ * @param n Number of elements to be sorted.
+ * @param e_size Size of one element.
+ * @param cmp Comparator function.
+ * @param slot Pointer to scratch memory buffer e_size bytes long.
+ * 
+ */
+void _bubblesort(void * data, size_t n, size_t e_size, int (* cmp) (void * a, void * b), void *slot)
+{
+	bool done = false;
+	void * p;
+
+	while (!done) {
+		done = true;
+		for (p = data; p < data + e_size * (n - 1); p = p + e_size) {
+			if (cmp(p, p + e_size) == 1) {
+				memcpy(slot, p, e_size);
+				memcpy(p, p + e_size, e_size);
+				memcpy(p + e_size, slot, e_size);
+				done = false;
+			}
 		}
-	} else {
-		slot = (void *) ibuf_slot;
-		pivot = (void *) ibuf_pivot;
-	}
-	
-	_qsort(data, cnt, elem_size, cmp, arg, slot, pivot);
-	
-	if (elem_size > IBUF_SIZE) {
-		free(pivot);
-		free(slot);
-	}
-	
-	return true;
+	}
+
+}
+
+/*
+ * Comparator returns 1 if a > b, 0 if a == b, -1 if a < b
+ */
+int int_cmp(void * a, void * b)
+{
+	return (* (int *) a > * (int*)b) ? 1 : (*(int *)a < * (int *)b) ? -1 : 0;
+}
+
+int uint8_t_cmp(void * a, void * b)
+{
+	return (* (uint8_t *) a > * (uint8_t *)b) ? 1 : (*(uint8_t *)a < * (uint8_t *)b) ? -1 : 0;
+}
+
+int uint16_t_cmp(void * a, void * b)
+{
+	return (* (uint16_t *) a > * (uint16_t *)b) ? 1 : (*(uint16_t *)a < * (uint16_t *)b) ? -1 : 0;
+}
+
+int uint32_t_cmp(void * a, void * b)
+{
+	return (* (uint32_t *) a > * (uint32_t *)b) ? 1 : (*(uint32_t *)a < * (uint32_t *)b) ? -1 : 0;
 }
 
Index: kernel/generic/src/main/main.c
===================================================================
--- kernel/generic/src/main/main.c	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ kernel/generic/src/main/main.c	(revision eee047c85698831f5ac6ee46aa25807c7a0ae06a)
@@ -104,5 +104,5 @@
 
 /** Lowest safe stack virtual address. */
-uintptr_t stack_safe = 0;
+uintptr_t stack_safe = 0;		
 
 /*
@@ -113,10 +113,9 @@
  */
 static void main_bsp_separated_stack(void);
-
 #ifdef CONFIG_SMP
 static void main_ap_separated_stack(void);
 #endif
 
-#define CONFIG_STACK_SIZE  ((1 << STACK_FRAMES) * STACK_SIZE)
+#define CONFIG_STACK_SIZE	((1 << STACK_FRAMES) * STACK_SIZE)
 
 /** Main kernel routine for bootstrap CPU.
@@ -152,5 +151,5 @@
 			    init.tasks[i].size, config.stack_size);
 	}
-	
+
 	/* Avoid placing stack on top of boot allocations. */
 	if (ballocs.size) {
@@ -171,4 +170,5 @@
 }
 
+
 /** Main kernel routine for bootstrap CPU using new stack.
  *
@@ -176,5 +176,5 @@
  *
  */
-void main_bsp_separated_stack(void)
+void main_bsp_separated_stack(void) 
 {
 	/* Keep this the first thing. */
@@ -194,5 +194,5 @@
 	 * commands.
 	 */
-	kconsole_init();
+	LOG_EXEC(kconsole_init());
 #endif
 	
@@ -201,40 +201,40 @@
 	 * starts adding its own handlers
 	 */
-	exc_init();
+	LOG_EXEC(exc_init());
 	
 	/*
 	 * Memory management subsystems initialization.
 	 */
-	arch_pre_mm_init();
-	frame_init();
+	LOG_EXEC(arch_pre_mm_init());
+	LOG_EXEC(frame_init());
 	
 	/* Initialize at least 1 memory segment big enough for slab to work. */
-	slab_cache_init();
-	sysinfo_init();
-	btree_init();
-	as_init();
-	page_init();
-	tlb_init();
-	ddi_init();
-	tasklet_init();
-	arch_post_mm_init();
-	arch_pre_smp_init();
-	smp_init();
+	LOG_EXEC(slab_cache_init());
+	LOG_EXEC(sysinfo_init());
+	LOG_EXEC(btree_init());
+	LOG_EXEC(as_init());
+	LOG_EXEC(page_init());
+	LOG_EXEC(tlb_init());
+	LOG_EXEC(ddi_init());
+	LOG_EXEC(tasklet_init());
+	LOG_EXEC(arch_post_mm_init());
+	LOG_EXEC(arch_pre_smp_init());
+	LOG_EXEC(smp_init());
 	
 	/* Slab must be initialized after we know the number of processors. */
-	slab_enable_cpucache();
+	LOG_EXEC(slab_enable_cpucache());
 	
 	printf("Detected %" PRIs " CPU(s), %" PRIu64" MiB free memory\n",
 	    config.cpu_count, SIZE2MB(zones_total_size()));
-	
-	cpu_init();
-	
-	calibrate_delay_loop();
-	clock_counter_init();
-	timeout_init();
-	scheduler_init();
-	task_init();
-	thread_init();
-	futex_init();
+
+	LOG_EXEC(cpu_init());
+	
+	LOG_EXEC(calibrate_delay_loop());
+	LOG_EXEC(clock_counter_init());
+	LOG_EXEC(timeout_init());
+	LOG_EXEC(scheduler_init());
+	LOG_EXEC(task_init());
+	LOG_EXEC(thread_init());
+	LOG_EXEC(futex_init());
 	
 	if (init.cnt > 0) {
@@ -247,8 +247,8 @@
 		printf("No init binaries found.\n");
 	
-	ipc_init();
-	event_init();
-	klog_init();
-	stats_init();
+	LOG_EXEC(ipc_init());
+	LOG_EXEC(event_init());
+	LOG_EXEC(klog_init());
+	LOG_EXEC(stats_init());
 	
 	/*
@@ -266,5 +266,5 @@
 	if (!kinit_thread)
 		panic("Cannot create kinit thread.");
-	thread_ready(kinit_thread);
+	LOG_EXEC(thread_ready(kinit_thread));
 	
 	/*
@@ -276,6 +276,6 @@
 }
 
+
 #ifdef CONFIG_SMP
-
 /** Main kernel routine for application CPUs.
  *
@@ -296,5 +296,5 @@
 	 */
 	config.cpu_active++;
-	
+
 	/*
 	 * The THE structure is well defined because ctx.sp is used as stack.
@@ -311,7 +311,7 @@
 	calibrate_delay_loop();
 	arch_post_cpu_init();
-	
+
 	the_copy(THE, (the_t *) CPU->stack);
-	
+
 	/*
 	 * If we woke kmp up before we left the kernel stack, we could
@@ -326,4 +326,5 @@
 }
 
+
 /** Main kernel routine for application CPUs using new stack.
  *
@@ -337,10 +338,9 @@
 	 */
 	timeout_init();
-	
+
 	waitq_wakeup(&ap_completion_wq, WAKEUP_FIRST);
 	scheduler();
 	/* not reached */
 }
-
 #endif /* CONFIG_SMP */
 
Index: uspace/lib/c/generic/sort.c
===================================================================
--- uspace/lib/c/generic/sort.c	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ uspace/lib/c/generic/sort.c	(revision eee047c85698831f5ac6ee46aa25807c7a0ae06a)
@@ -36,5 +36,5 @@
  *
  * This files contains functions implementing several sorting
- * algorithms (e.g. quick sort and gnome sort).
+ * algorithms (e.g. quick sort and bubble sort).
  *
  */
@@ -44,20 +44,7 @@
 #include <malloc.h>
 
-/** Immediate buffer size.
+/** Bubble sort
  *
- * For small buffer sizes avoid doing malloc()
- * and use the stack.
- *
- */
-#define IBUF_SIZE  32
-
-/** Array accessor.
- *
- */
-#define INDEX(buf, i, elem_size)  ((buf) + (i) * (elem_size))
-
-/** Gnome sort
- *
- * Apply generic gnome sort algorithm on supplied data,
+ * Apply generic bubble sort algorithm on supplied data,
  * using pre-allocated buffer.
  *
@@ -71,20 +58,22 @@
  *
  */
-static void _gsort(void *data, size_t cnt, size_t elem_size, sort_cmp_t cmp,
+static void _bsort(void *data, size_t cnt, size_t elem_size, sort_cmp_t cmp,
     void *arg, void *slot)
 {
-	size_t i = 0;
+	bool done = false;
+	void *tmp;
 	
-	while (i < cnt) {
-		if ((i != 0) &&
-		    (cmp(INDEX(data, i, elem_size),
-		    INDEX(data, i - 1, elem_size), arg) == -1)) {
-			memcpy(slot, INDEX(data, i, elem_size), elem_size);
-			memcpy(INDEX(data, i, elem_size), INDEX(data, i - 1, elem_size),
-			    elem_size);
-			memcpy(INDEX(data, i - 1, elem_size), slot, elem_size);
-			i--;
-		} else
-			i++;
+	while (!done) {
+		done = true;
+		
+		for (tmp = data; tmp < data + elem_size * (cnt - 1);
+		    tmp = tmp + elem_size) {
+			if (cmp(tmp, tmp + elem_size, arg) == 1) {
+				memcpy(slot, tmp, elem_size);
+				memcpy(tmp, tmp + elem_size, elem_size);
+				memcpy(tmp + elem_size, slot, elem_size);
+				done = false;
+			}
+		}
 	}
 }
@@ -100,5 +89,5 @@
  * @param cmp       Comparator function.
  * @param arg       3rd argument passed to cmp.
- * @param slot      Pointer to scratch memory buffer
+ * @param tmp       Pointer to scratch memory buffer
  *                  elem_size bytes long.
  * @param pivot     Pointer to scratch memory buffer
@@ -107,5 +96,5 @@
  */
 static void _qsort(void *data, size_t cnt, size_t elem_size, sort_cmp_t cmp,
-    void *arg, void *slot, void *pivot)
+    void *arg, void *tmp, void *pivot)
 {
 	if (cnt > 4) {
@@ -116,31 +105,31 @@
 		
 		while (true) {
-			while ((cmp(INDEX(data, i, elem_size), pivot, arg) < 0) && (i < cnt))
+			while ((cmp(data + i * elem_size, pivot, arg) < 0) && (i < cnt))
 				i++;
 			
-			while ((cmp(INDEX(data, j, elem_size), pivot, arg) >= 0) && (j > 0))
+			while ((cmp(data + j * elem_size, pivot, arg) >= 0) && (j > 0))
 				j--;
 			
 			if (i < j) {
-				memcpy(slot, INDEX(data, i, elem_size), elem_size);
-				memcpy(INDEX(data, i, elem_size), INDEX(data, j, elem_size),
+				memcpy(tmp, data + i * elem_size, elem_size);
+				memcpy(data + i * elem_size, data + j * elem_size,
 				    elem_size);
-				memcpy(INDEX(data, j, elem_size), slot, elem_size);
+				memcpy(data + j * elem_size, tmp, elem_size);
 			} else
 				break;
 		}
 		
-		_qsort(data, j + 1, elem_size, cmp, arg, slot, pivot);
-		_qsort(INDEX(data, j + 1, elem_size), cnt - j - 1, elem_size,
-		    cmp, arg, slot, pivot);
+		_qsort(data, j + 1, elem_size, cmp, arg, tmp, pivot);
+		_qsort(data + (j + 1) * elem_size, cnt - j - 1, elem_size,
+		    cmp, arg, tmp, pivot);
 	} else
-		_gsort(data, cnt, elem_size, cmp, arg, slot);
+		_bsort(data, cnt, elem_size, cmp, arg, tmp);
 }
 
-/** Gnome sort wrapper
+/** Bubble sort wrapper
  *
  * This is only a wrapper that takes care of memory
  * allocations for storing the slot element for generic
- * gnome sort algorithm.
+ * bubble sort algorithm.
  *
  * @param data      Pointer to data to be sorted.
@@ -153,20 +142,13 @@
  *
  */
-bool gsort(void *data, size_t cnt, size_t elem_size, sort_cmp_t cmp, void *arg)
+bool bsort(void *data, size_t cnt, size_t elem_size, sort_cmp_t cmp, void *arg)
 {
-	uint8_t ibuf_slot[IBUF_SIZE];
-	void *slot;
+	void *slot = (void *) malloc(elem_size);
+	if (!slot)
+		return false;
 	
-	if (elem_size > IBUF_SIZE) {
-		slot = (void *) malloc(elem_size);
-		if (!slot)
-			return false;
-	} else
-		slot = (void *) ibuf_slot;
+	_bsort(data, cnt, elem_size, cmp, arg, slot);
 	
-	_gsort(data, cnt, elem_size, cmp, arg, slot);
-	
-	if (elem_size > IBUF_SIZE)
-		free(slot);
+	free(slot);
 	
 	return true;
@@ -190,30 +172,18 @@
 bool qsort(void *data, size_t cnt, size_t elem_size, sort_cmp_t cmp, void *arg)
 {
-	uint8_t ibuf_slot[IBUF_SIZE];
-	uint8_t ibuf_pivot[IBUF_SIZE];
-	void *slot;
-	void *pivot;
+	void *tmp = (void *) malloc(elem_size);
+	if (!tmp)
+		return false;
 	
-	if (elem_size > IBUF_SIZE) {
-		slot = (void *) malloc(elem_size);
-		if (!slot)
-			return false;
-		
-		pivot = (void *) malloc(elem_size);
-		if (!pivot) {
-			free(slot);
-			return false;
-		}
-	} else {
-		slot = (void *) ibuf_slot;
-		pivot = (void *) ibuf_pivot;
+	void *pivot = (void *) malloc(elem_size);
+	if (!pivot) {
+		free(tmp);
+		return false;
 	}
 	
-	_qsort(data, cnt, elem_size, cmp, arg, slot, pivot);
+	_qsort(data, cnt, elem_size, cmp, arg, tmp, pivot);
 	
-	if (elem_size > IBUF_SIZE) {
-		free(pivot);
-		free(slot);
-	}
+	free(pivot);
+	free(tmp);
 	
 	return true;
Index: uspace/lib/c/include/sort.h
===================================================================
--- uspace/lib/c/include/sort.h	(revision 90ed05866ebbe68aed54837f022033a6baaa6860)
+++ uspace/lib/c/include/sort.h	(revision eee047c85698831f5ac6ee46aa25807c7a0ae06a)
@@ -41,5 +41,5 @@
 typedef int (* sort_cmp_t)(void *, void *, void *);
 
-extern bool gsort(void *, size_t, size_t, sort_cmp_t, void *);
+extern bool bsort(void *, size_t, size_t, sort_cmp_t, void *);
 extern bool qsort(void *, size_t, size_t, sort_cmp_t, void *);
 
