Index: kernel/arch/amd64/src/boot/boot.S
===================================================================
--- kernel/arch/amd64/src/boot/boot.S	(revision 99718a2ecc5019b587210e9cffa467236e5f2131)
+++ kernel/arch/amd64/src/boot/boot.S	(revision 873c681f49a8dbebb2bcd27d6e1686252a6e5dd7)
@@ -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,9 +37,30 @@
 #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
@@ -47,5 +68,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
@@ -56,17 +77,21 @@
 multiboot_image_start:
 	cld
-	movl $START_STACK, %esp             # initialize stack pointer
-	lgdtl bootstrap_gdtr                # initialize Global Descriptor Table register
-	
+	
+	/* Initialize stack pointer */
+	movl $START_STACK, %esp
+	
+	/* Initialize Global Descriptor Table register */
+	lgdtl bootstrap_gdtr
+	
+	/* Kernel data + stack */
 	movw $gdtselector(KDATA_DES), %cx
 	movw %cx, %es
-	movw %cx, %ds                       # kernel data + stack
+	movw %cx, %ds
 	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
@@ -76,11 +101,9 @@
 	multiboot_meeting_point:
 	
-	movl %eax, grub_eax                 # save parameters from GRUB
+	/* Save GRUB arguments */
+	movl %eax, grub_eax
 	movl %ebx, grub_ebx
 	
-	#
-	# Protected 32-bit. We want to reuse the code-seg descriptor,
-	# the Default operand size must not be 1 when entering long mode.
-	#
+	pm_status $status_prot
 	
 	movl $(INTEL_CPUID_EXTENDED), %eax
@@ -89,6 +112,5 @@
 	ja extended_cpuid_supported
 	
-		movl $extended_cpuid_msg, %esi
-		jmp error_halt
+		pm_error $err_extended_cpuid
 	
 	extended_cpuid_supported:
@@ -99,6 +121,5 @@
 	jc long_mode_supported
 	
-		movl $long_mode_msg, %esi
-		jmp error_halt
+		pm_error $err_long_mode
 	
 	long_mode_supported:
@@ -107,6 +128,5 @@
 	jc noexecute_supported
 	
-		movl $noexecute_msg, %esi
-		jmp error_halt
+		pm_error $err_noexecute
 	
 	noexecute_supported:
@@ -117,6 +137,5 @@
 	jc fx_supported
 	
-		movl $fx_msg, %esi
-		jmp error_halt
+		pm_error $err_fx
 	
 	fx_supported:
@@ -125,15 +144,21 @@
 	jc sse2_supported
 	
-		movl $sse2_msg, %esi
-		jmp error_halt
+		pm_error $err_sse2
 	
 	sse2_supported:
-
+	
 #include "vesa_prot.inc"
-
-	#
-	# Enable 64-bit page translation entries - CR4.PAE = 1.
-	# Paging is not enabled until after long mode is enabled.
-	#
+	
+	/*
+	 * 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.
+	 */
 	
 	movl %cr4, %eax
@@ -141,31 +166,259 @@
 	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            # 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)
-	
+	/* 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) */
 	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 */
+	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 err_cursor_ok
+	
+		movw $1998, %ax
+	
+	err_cursor_ok:
+	
+	movw %ax, %bx
+	shl $1, %eax
+	addl %eax, %edi
+	
+	err_ploop:
+		lodsb
+		
+		cmp $0, %al
+		je err_ploop_end
+		
+		movb $0x0c, %ah  /* black background, light red foreground */
+		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
+	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
+	
+	cli
+	hlt1:
+		hlt
+		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
 	
-	# call arch_pre_main(grub_eax, grub_ebx)
+	/* 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
@@ -176,13 +429,11 @@
 	callq *%rax
 	
-	# create the first stack frame
-	pushq $0
-	movq %rsp, %rbp
-	
+	long_status $status_main
+	
+	/* Call main_bsp() */
 	movabsq $main_bsp, %rax
 	call *%rax
 	
-	# not reached
-	
+	/* Not reached */
 	cli
 	hlt0:
@@ -190,10 +441,31 @@
 		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
-	
-	movw $0x3d4, %dx          # read bits 8 - 15 of the cursor address
+/** 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
@@ -203,5 +475,6 @@
 	shl $8, %ax
 	
-	movw $0x3d4, %dx          # read bits 0 - 7 of the cursor address
+	/* Read bits 0 - 7 of the cursor address */
+	movw $0x3d4, %dx
 	movb $0xf, %al
 	outb %al, %dx
@@ -210,27 +483,52 @@
 	inb %dx, %al
 	
-	cmp $1920, %ax
-	jbe cursor_ok
-	
-		movw $1920, %ax       # sanity check for the cursor on the last line
-	
-	cursor_ok:
+	/* 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
-	
-	movw $0x0c00, %ax         # black background, light red foreground
-	
-	ploop:
+	shl $1, %rax
+	addq %rax, %rdi
+	
+	early_puts_ploop:
 		lodsb
+		
 		cmp $0, %al
-		je ploop_end
+		je early_puts_ploop_end
+		
+		movb $0x0e, %ah  /* black background, yellow foreground */
 		stosw
+		
+		/* Sanity check for the cursor on the last line */
 		inc %bx
-		jmp ploop
-	ploop_end:
-	
-	movw $0x3d4, %dx          # write bits 8 - 15 of the cursor address
+		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
@@ -240,5 +538,6 @@
 	outb %al, %dx
 	
-	movw $0x3d4, %dx          # write bits 0 - 7 of the cursor address
+	/* Write bits 0 - 7 of the cursor address */
+	movw $0x3d4, %dx
 	movb $0xf, %al
 	outb %al, %dx
@@ -248,8 +547,11 @@
 	outb %al, %dx
 	
-	cli
-	hlt1:
-		hlt
-		jmp hlt1
+	/* Epilogue, restore preserved registers */
+	popq %rbx
+	leave
+	
+#endif
+	
+	ret
 
 #include "vesa_real.inc"
@@ -257,9 +559,10 @@
 .section K_INI_PTLS, "aw", @progbits
 
-#
-# 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.
-#
+/** 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 ptl2gen cnt g
 	.if \cnt
@@ -276,40 +579,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:
@@ -318,5 +621,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)
@@ -350,12 +653,27 @@
 	.long 0
 
-extended_cpuid_msg:
+err_extended_cpuid:
 	.asciz "Error: Extended CPUID not supported -- CPU is not 64-bit. System halted."
-long_mode_msg:
+err_long_mode:
 	.asciz "Error: 64-bit long mode not supported. System halted."
-noexecute_msg:
+err_noexecute:
 	.asciz "Error: No-execute pages not supported. System halted."
-fx_msg:
+err_fx:
 	.asciz "Error: FXSAVE/FXRESTORE instructions not supported. System halted."
-sse2_msg:
+err_sse2:
 	.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 99718a2ecc5019b587210e9cffa467236e5f2131)
+++ kernel/arch/amd64/src/boot/vesa_ret.inc	(revision 873c681f49a8dbebb2bcd27d6e1686252a6e5dd7)
@@ -1,13 +1,19 @@
 .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                       # kernel data + stack
+	movw %cx, %ds
 	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
@@ -15,5 +21,3 @@
 	movw %cx, %gs
 	
-	movl $START_STACK, %esp             # initialize stack pointer
-	
 	jmpl $gdtselector(KTEXT32_DES), $vesa_meeting_point
Index: kernel/arch/ia32/src/boot/boot.S
===================================================================
--- kernel/arch/ia32/src/boot/boot.S	(revision 99718a2ecc5019b587210e9cffa467236e5f2131)
+++ kernel/arch/ia32/src/boot/boot.S	(revision 873c681f49a8dbebb2bcd27d6e1686252a6e5dd7)
@@ -1,30 +1,30 @@
-#
-# 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.
-#
+/*
+ * 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.
+ */
 
 #include <arch/boot/boot.h>
@@ -34,9 +34,29 @@
 #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
@@ -44,5 +64,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
@@ -53,12 +73,17 @@
 multiboot_image_start:
 	cld
-	movl $START_STACK, %esp     # initialize stack pointer
-	lgdt KA2PA(bootstrap_gdtr)  # initialize Global Descriptor Table register
-	
+	
+	/* Initialize stack pointer */
+	movl $START_STACK, %esp
+	
+	/* Initialize Global Descriptor Table register */
+	lgdtl KA2PA(bootstrap_gdtr)
+	
+	/* Kernel data + stack */
 	movw $gdtselector(KDATA_DES), %cx
 	movw %cx, %es
 	movw %cx, %fs
 	movw %cx, %gs
-	movw %cx, %ds               # kernel data + stack
+	movw %cx, %ds
 	movw %cx, %ss
 	
@@ -66,10 +91,13 @@
 	multiboot_meeting_point:
 	
-	movl %eax, grub_eax         # save parameters from GRUB
+	/* Save GRUB arguments */
+	movl %eax, grub_eax
 	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
 	
@@ -80,26 +108,31 @@
 	
 	pse_unsupported:
-		movl $pse_msg, %esi
-		jmp error_halt
+		
+		pm_error $err_pse
 	
 	pse_supported:
 	
 #include "vesa_prot.inc"
-
-	# map kernel and turn paging on
+	
+	/* Map kernel and turn paging on */
 	call map_kernel
 	
-	# call arch_pre_main(grub_eax, grub_ebx)
+	/* Create the first stack frame */
+	pushl $0
+	movl %esp, %ebp
+	
+	pm2_status $status_prot2
+	
+	/* Call arch_pre_main(grub_eax, grub_ebx) */
 	pushl grub_ebx
 	pushl grub_eax
 	call arch_pre_main
-
-	# Create the first stack frame
-	pushl $0
-	movl %esp, %ebp
-	
+	
+	pm2_status $status_main
+	
+	/* Call main_bsp() */
 	call main_bsp
 	
-	# not reached
+	/* Not reached */
 	cli
 	hlt0:
@@ -107,13 +140,15 @@
 		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                 # turn PSE on
-	andl $(~(1 << 5)), %ecx             # turn PAE off
+	orl $(1 << 4), %ecx      /* PSE on */
+	andl $(~(1 << 5)), %ecx  /* PAE off */
 	movl %ecx, %cr4
 	
@@ -126,6 +161,8 @@
 		movl $((1 << 7) | (1 << 1) | (1 << 0)), %eax
 		orl %ebx, %eax
-		movl %eax, (%esi, %ecx, 4)      # mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M
-		movl %eax, (%edi, %ecx, 4)      # mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M
+		/* Mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */
+		movl %eax, (%esi, %ecx, 4)
+		/* Mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */
+		movl %eax, (%edi, %ecx, 4)
 		addl $(4 * 1024 * 1024), %ebx
 		
@@ -137,14 +174,25 @@
 	
 	movl %cr0, %ebx
-	orl $(1 << 31), %ebx                # turn paging on
+	orl $(1 << 31), %ebx  /* paging on */
 	movl %ebx, %cr0
 	ret
 
-# Print string from %esi to EGA display (in red) and halt
-error_halt:
-	movl $0xb8000, %edi         # base of EGA text mode memory
+/** 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 */
 	xorl %eax, %eax
 	
-	movw $0x3d4, %dx            # read bits 8 - 15 of the cursor address
+	/* Read bits 8 - 15 of the cursor address */
+	movw $0x3d4, %dx
 	movb $0xe, %al
 	outb %al, %dx
@@ -154,5 +202,6 @@
 	shl $8, %ax
 	
-	movw $0x3d4, %dx            # read bits 0 - 7 of the cursor address
+	/* Read bits 0 - 7 of the cursor address */
+	movw $0x3d4, %dx
 	movb $0xf, %al
 	outb %al, %dx
@@ -161,10 +210,11 @@
 	inb %dx, %al
 	
-	cmp $1920, %ax
-	jbe cursor_ok
-	
-		movw $1920, %ax         # sanity check for the cursor on the last line
-	
-	cursor_ok:
+	/* Sanity check for the cursor on screen */
+	cmp $2000, %ax
+	jb err_cursor_ok
+	
+		movw $1998, %ax
+	
+	err_cursor_ok:
 	
 	movw %ax, %bx
@@ -172,16 +222,40 @@
 	addl %eax, %edi
 	
-	movw $0x0c00, %ax           # black background, light red foreground
-	
-	ploop:
+	err_ploop:
 		lodsb
+		
 		cmp $0, %al
-		je ploop_end
+		je err_ploop_end
+		
+		movb $0x0c, %ah  /* black background, light red foreground */
 		stosw
+		
+		/* Sanity check for the cursor on the last line */
 		inc %bx
-		jmp ploop
-	ploop_end:
-	
-	movw $0x3d4, %dx            # write bits 8 - 15 of the cursor address
+		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
 	movb $0xe, %al
 	outb %al, %dx
@@ -191,5 +265,6 @@
 	outb %al, %dx
 	
-	movw $0x3d4, %dx            # write bits 0 - 7 of the cursor address
+	/* Write bits 0 - 7 of the cursor address */
+	movw $0x3d4, %dx
 	movb $0xf, %al
 	outb %al, %dx
@@ -204,4 +279,232 @@
 		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"
 
@@ -218,5 +521,17 @@
 	.long 0
 
-pse_msg:
+err_pse:
 	.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 99718a2ecc5019b587210e9cffa467236e5f2131)
+++ kernel/arch/ia32/src/boot/vesa_prot.inc	(revision 873c681f49a8dbebb2bcd27d6e1686252a6e5dd7)
@@ -5,5 +5,7 @@
 #define MBINFO_OFFSET_CMDLINE   16
 
-	# copy real mode VESA initialization code
+	/* Copy real mode VESA initialization code */
+	
+	pm_status $status_vesa_copy
 	
 	mov $vesa_init, %esi
@@ -12,5 +14,7 @@
 	rep movsb
 	
-	# check for GRUB command line
+	/* Check for GRUB command line */
+	
+	pm_status $status_grub_cmdline
 	
 	mov grub_eax, %eax
@@ -23,5 +27,5 @@
 	jnc no_cmdline
 	
-	# skip the kernel path in command line
+	/* Skip the kernel path in command line */
 	
 	mov MBINFO_OFFSET_CMDLINE(%ebx), %esi
@@ -52,5 +56,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
@@ -68,5 +72,5 @@
 	cmd_loop_done:
 	
-	# zero termination
+	/* Zero termination */
 	
 	xor %eax, %eax
@@ -75,5 +79,7 @@
 	no_cmdline:
 	
-	# jump to the real mode
+	/* Jump to the real mode */
+	
+	pm_status $status_vesa_real
 	
 	mov $VESA_INIT_SEGMENT << 4, %edi
@@ -81,5 +87,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 99718a2ecc5019b587210e9cffa467236e5f2131)
+++ kernel/arch/ia32/src/boot/vesa_real.inc	(revision 873c681f49a8dbebb2bcd27d6e1686252a6e5dd7)
@@ -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,5 +167,6 @@
 	
 	next_mode:
-		# try next mode
+		/* Try next mode */
+		
 		mov %gs:(%si), %cx
 		cmp $VESA_END_OF_MODES, %cx
@@ -186,5 +187,8 @@
 		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
@@ -193,5 +197,5 @@
 		jne next_mode
 		
-		# check for proper resolution
+		/* Check for proper resolution */
 		
 		mov default_width - vesa_init, %ax
@@ -203,5 +207,5 @@
 		jne next_mode
 		
-		# check for proper bpp
+		/* Check for proper bpp */
 		
 		mov default_bpp - vesa_init, %al
@@ -213,5 +217,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
@@ -230,5 +234,5 @@
 		jnz no_mode
 		
-		# set 3:2:3 VGA palette
+		/* Set 3:2:3 VGA palette */
 		
 		mov VESA_MODE_BPP_OFFSET(%di), %al
@@ -241,8 +245,10 @@
 		mov $0x100, %ecx
 		
-		bt $5, %ax              # test if VGA compatible registers are present
+		/* Test if VGA compatible registers are present */
+		bt $5, %ax
 		jnc vga_compat
 		
-			# try VESA routine to set palette
+			/* Use VESA routine to set the palette */
+			
 			mov $VESA_SET_PALETTE, %ax
 			xor %bl, %bl
@@ -254,14 +260,16 @@
 		
 		vga_compat:
-			# try VGA registers to set palette
-			movw $0x3c6, %dx    # set palette mask
+			
+			/* Use VGA registers to set the 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:
@@ -284,10 +292,12 @@
 		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
@@ -328,5 +338,7 @@
 	
 	no_mode:
-		# no prefered mode found
+		
+		/* No prefered mode found */
+		
 		mov $0x111, %cx
 		push %di
@@ -339,13 +351,15 @@
 		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 99718a2ecc5019b587210e9cffa467236e5f2131)
+++ kernel/arch/ia32/src/boot/vesa_ret.inc	(revision 873c681f49a8dbebb2bcd27d6e1686252a6e5dd7)
@@ -1,12 +1,16 @@
 .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               # kernel data + stack
+	movw %cx, %ds
 	movw %cx, %ss
 	
-	movl $START_STACK, %esp     # initialize stack pointer
-	
 	jmpl $gdtselector(KTEXT_DES), $vesa_meeting_point
