Index: kernel/arch/amd64/src/debugger.c
===================================================================
--- kernel/arch/amd64/src/debugger.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/arch/amd64/src/debugger.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -55,4 +55,6 @@
 SPINLOCK_INITIALIZE(bkpoint_lock);
 
+#ifdef CONFIG_KCONSOLE
+
 static int cmd_print_breakpoints(cmd_arg_t *argv);
 static cmd_info_t bkpts_info = {
@@ -100,41 +102,6 @@
 };
 
-#endif
-
-/** Print table of active breakpoints */
-int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused)))
-{
-	unsigned int i;
-	char *symbol;
-
-#ifdef __32_BITS__	
-	printf("#  Count Address    In symbol\n");
-	printf("-- ----- ---------- ---------\n");
-#endif
-
-#ifdef __64_BITS__
-	printf("#  Count Address            In symbol\n");
-	printf("-- ----- ------------------ ---------\n");
-#endif
-	
-	for (i = 0; i < BKPOINTS_MAX; i++)
-		if (breakpoints[i].address) {
-			symbol = get_symtab_entry(breakpoints[i].address);
-
-#ifdef __32_BITS__
-			printf("%-2u %-5d %#10zx %s\n", i,
-			    breakpoints[i].counter, breakpoints[i].address,
-			    symbol);
-#endif
-
-#ifdef __64_BITS__
-			printf("%-2u %-5d %#18zx %s\n", i,
-			    breakpoints[i].counter, breakpoints[i].address,
-			    symbol);
-#endif
-
-		}
-	return 1;
-}
+#endif /* CONFIG_DEBUG_AS_WATCHPOINT */
+#endif /* CONFIG_KCONSOLE */
 
 /* Setup DR register according to table */
@@ -268,8 +235,10 @@
 	printf("Reached breakpoint %d:%lx(%s)\n", slot, getip(istate),
 	    get_symtab_entry(getip(istate)));
-	printf("***Type 'exit' to exit kconsole.\n");
-	atomic_set(&haltstate,1);
-	kconsole((void *) "debug");
-	atomic_set(&haltstate,0);
+
+#ifdef CONFIG_KCONSOLE
+	atomic_set(&haltstate, 1);
+	kconsole("debug", "Debug console ready (type 'exit' to continue)\n", false);
+	atomic_set(&haltstate, 0);
+#endif
 }
 
@@ -300,39 +269,5 @@
 }
 
-#ifndef CONFIG_DEBUG_AS_WATCHPOINT
-
-/** Remove breakpoint from table */
-int cmd_del_breakpoint(cmd_arg_t *argv)
-{
-	unative_t bpno = argv->intval;
-	if (bpno > BKPOINTS_MAX) {
-		printf("Invalid breakpoint number.\n");
-		return 0;
-	}
-	breakpoint_del(argv->intval);
-	return 1;
-}
-
-/** Add new breakpoint to table */
-static int cmd_add_breakpoint(cmd_arg_t *argv)
-{
-	int flags;
-	int id;
-
-	if (argv == &add_argv) {
-		flags = BKPOINT_INSTR;
-	} else { /* addwatchp */
-		flags = BKPOINT_WRITE;
-	}
-	printf("Adding breakpoint on address: %p\n", argv->intval);
-	id = breakpoint_add((void *)argv->intval, flags, -1);
-	if (id < 0)
-		printf("Add breakpoint failed.\n");
-	else
-		printf("Added breakpoint %d.\n", id);
-	
-	return 1;
-}
-#endif
+
 
 static void debug_exception(int n __attribute__((unused)), istate_t *istate)
@@ -380,22 +315,24 @@
 	for (i = 0; i < BKPOINTS_MAX; i++)
 		breakpoints[i].address = NULL;
-	
+
+#ifdef CONFIG_KCONSOLE
 	cmd_initialize(&bkpts_info);
 	if (!cmd_register(&bkpts_info))
-		panic("could not register command %s\n", bkpts_info.name);
+		printf("Cannot register command %s\n", bkpts_info.name);
 
 #ifndef CONFIG_DEBUG_AS_WATCHPOINT
 	cmd_initialize(&delbkpt_info);
 	if (!cmd_register(&delbkpt_info))
-		panic("could not register command %s\n", delbkpt_info.name);
+		printf("Cannot register command %s\n", delbkpt_info.name);
 
 	cmd_initialize(&addbkpt_info);
 	if (!cmd_register(&addbkpt_info))
-		panic("could not register command %s\n", addbkpt_info.name);
+		printf("Cannot register command %s\n", addbkpt_info.name);
 
 	cmd_initialize(&addwatchp_info);
 	if (!cmd_register(&addwatchp_info))
-		panic("could not register command %s\n", addwatchp_info.name);
-#endif
+		printf("Cannot register command %s\n", addwatchp_info.name);
+#endif /* CONFIG_DEBUG_AS_WATCHPOINT */
+#endif /* CONFIG_KCONSOLE */
 	
 	exc_register(VECTOR_DEBUG, "debugger", debug_exception);
@@ -405,4 +342,78 @@
 }
 
+#ifdef CONFIG_KCONSOLE
+/** Print table of active breakpoints */
+int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused)))
+{
+	unsigned int i;
+	char *symbol;
+
+#ifdef __32_BITS__	
+	printf("#  Count Address    In symbol\n");
+	printf("-- ----- ---------- ---------\n");
+#endif
+
+#ifdef __64_BITS__
+	printf("#  Count Address            In symbol\n");
+	printf("-- ----- ------------------ ---------\n");
+#endif
+	
+	for (i = 0; i < BKPOINTS_MAX; i++)
+		if (breakpoints[i].address) {
+			symbol = get_symtab_entry(breakpoints[i].address);
+
+#ifdef __32_BITS__
+			printf("%-2u %-5d %#10zx %s\n", i,
+			    breakpoints[i].counter, breakpoints[i].address,
+			    symbol);
+#endif
+
+#ifdef __64_BITS__
+			printf("%-2u %-5d %#18zx %s\n", i,
+			    breakpoints[i].counter, breakpoints[i].address,
+			    symbol);
+#endif
+
+		}
+	return 1;
+}
+
+#ifndef CONFIG_DEBUG_AS_WATCHPOINT
+
+/** Remove breakpoint from table */
+int cmd_del_breakpoint(cmd_arg_t *argv)
+{
+	unative_t bpno = argv->intval;
+	if (bpno > BKPOINTS_MAX) {
+		printf("Invalid breakpoint number.\n");
+		return 0;
+	}
+	breakpoint_del(argv->intval);
+	return 1;
+}
+
+/** Add new breakpoint to table */
+static int cmd_add_breakpoint(cmd_arg_t *argv)
+{
+	int flags;
+	int id;
+
+	if (argv == &add_argv) {
+		flags = BKPOINT_INSTR;
+	} else { /* addwatchp */
+		flags = BKPOINT_WRITE;
+	}
+	printf("Adding breakpoint on address: %p\n", argv->intval);
+	id = breakpoint_add((void *)argv->intval, flags, -1);
+	if (id < 0)
+		printf("Add breakpoint failed.\n");
+	else
+		printf("Added breakpoint %d.\n", id);
+	
+	return 1;
+}
+#endif /* CONFIG_DEBUG_AS_WATCHPOINT */
+#endif /* CONFIG_KCONSOLE */
+
 /** @}
  */
Index: kernel/arch/ia32/include/drivers/ega.h
===================================================================
--- kernel/arch/ia32/include/drivers/ega.h	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/arch/ia32/include/drivers/ega.h	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -41,4 +41,5 @@
 #define SCREEN		(ROW * ROWS)
 
+extern void ega_redraw(void);
 extern void ega_init(void);
 
Index: kernel/arch/ia32/include/drivers/vesa.h
===================================================================
--- kernel/arch/ia32/include/drivers/vesa.h	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/arch/ia32/include/drivers/vesa.h	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -37,4 +37,5 @@
 
 extern int vesa_present(void);
+extern void vesa_redraw(void);
 extern void vesa_init(void);
 
Index: kernel/arch/ia32/src/cpu/cpu.c
===================================================================
--- kernel/arch/ia32/src/cpu/cpu.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/arch/ia32/src/cpu/cpu.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -66,6 +66,6 @@
 static char *vendor_str[] = {
 	"Unknown Vendor",
-	"AuthenticAMD",
-	"GenuineIntel"
+	"AMD",
+	"Intel"
 };
 
@@ -78,5 +78,5 @@
 		:
 		:
-		:"%eax"
+		: "%eax"
 	);
 }
@@ -90,5 +90,5 @@
 		:
 		:
-		:"%eax"
+		: "%eax"
 	);	
 }
@@ -141,27 +141,29 @@
 		 * Check for AMD processor.
 		 */
-		if (info.cpuid_ebx==AMD_CPUID_EBX && info.cpuid_ecx==AMD_CPUID_ECX && info.cpuid_edx==AMD_CPUID_EDX) {
+		if ((info.cpuid_ebx == AMD_CPUID_EBX)
+		    && (info.cpuid_ecx == AMD_CPUID_ECX)
+			&& (info.cpuid_edx == AMD_CPUID_EDX))
 			CPU->arch.vendor = VendorAMD;
-		}
-
+		
 		/*
 		 * Check for Intel processor.
 		 */		
-		if (info.cpuid_ebx==INTEL_CPUID_EBX && info.cpuid_ecx==INTEL_CPUID_ECX && info.cpuid_edx==INTEL_CPUID_EDX) {
+		if ((info.cpuid_ebx == INTEL_CPUID_EBX)
+		    && (info.cpuid_ecx == INTEL_CPUID_ECX)
+			&& (info.cpuid_edx == INTEL_CPUID_EDX))
 			CPU->arch.vendor = VendorIntel;
-		}
-				
+		
 		cpuid(1, &info);
-		CPU->arch.family = (info.cpuid_eax>>8)&0xf;
-		CPU->arch.model = (info.cpuid_eax>>4)&0xf;
-		CPU->arch.stepping = (info.cpuid_eax>>0)&0xf;						
+		CPU->arch.family = (info.cpuid_eax >> 8) & 0x0f;
+		CPU->arch.model = (info.cpuid_eax >> 4) & 0x0f;
+		CPU->arch.stepping = (info.cpuid_eax >> 0) & 0x0f;						
 	}
 }
 
-void cpu_print_report(cpu_t* m)
+void cpu_print_report(cpu_t* cpu)
 {
-	printf("cpu%d: (%s family=%d model=%d stepping=%d) %dMHz\n",
-		m->id, vendor_str[m->arch.vendor], m->arch.family, m->arch.model, m->arch.stepping,
-		m->frequency_mhz);
+	printf("cpu%u: (%s family=%u model=%u stepping=%u) %" PRIu16 " MHz\n",
+		cpu->id, vendor_str[cpu->arch.vendor], cpu->arch.family,
+		cpu->arch.model, cpu->arch.stepping, cpu->frequency_mhz);
 }
 
Index: kernel/arch/ia32/src/drivers/vesa.c
===================================================================
--- kernel/arch/ia32/src/drivers/vesa.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/arch/ia32/src/drivers/vesa.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -98,4 +98,9 @@
 }
 
+void vesa_redraw(void)
+{
+	fb_redraw();
+}
+
 #endif
 
Index: kernel/arch/ia32/src/ia32.c
===================================================================
--- kernel/arch/ia32/src/ia32.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/arch/ia32/src/ia32.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -94,5 +94,5 @@
 		else
 #endif
-			ega_init();	/* video */
+			ega_init(); /* video */
 		
 		/* Enable debugger */
@@ -160,6 +160,13 @@
 void arch_grab_console(void)
 {
+#ifdef CONFIG_FB
+	vesa_redraw();
+#else
+	ega_redraw();
+#endif
+	
 	i8042_grab();
 }
+
 /** Return console to userspace
  *
Index: kernel/arch/mips32/src/cpu/cpu.c
===================================================================
--- kernel/arch/mips32/src/cpu/cpu.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/arch/mips32/src/cpu/cpu.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -49,5 +49,5 @@
 	{ "MIPS", "R3000" },		/* 0x02 */
 	{ "MIPS", "R6000" },		/* 0x03 */
-	{ "MIPS", " R4000/R4400" }, 	/* 0x04 */
+	{ "MIPS", "R4000/R4400" }, 	/* 0x04 */
 	{ "LSI Logic", "R3000" },	/* 0x05 */
 	{ "MIPS", "R6000A" },		/* 0x06 */
@@ -124,7 +124,7 @@
 	}
 
-	printf("cpu%d: %s %s (rev=%d.%d, imp=%d)\n",
+	printf("cpu%u: %s %s (rev=%d.%d, imp=%d)\n",
 		m->id, data->vendor, data->model, m->arch.rev_num >> 4, 
-		m->arch.rev_num & 0xf, m->arch.imp_num);
+		m->arch.rev_num & 0x0f, m->arch.imp_num);
 }
 
Index: kernel/arch/mips32/src/debugger.c
===================================================================
--- kernel/arch/mips32/src/debugger.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/arch/mips32/src/debugger.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -47,4 +47,6 @@
 bpinfo_t breakpoints[BKPOINTS_MAX];
 SPINLOCK_INITIALIZE(bkpoint_lock);
+
+#ifdef CONFIG_KCONSOLE
 
 static int cmd_print_breakpoints(cmd_arg_t *argv);
@@ -124,8 +126,10 @@
 };
 
+
 /** Test, if the given instruction is a jump or branch instruction
  *
  * @param instr Instruction code
  * @return true - it is jump instruction, false otherwise
+ *
  */
 static bool is_jump(unative_t instr)
@@ -268,4 +272,6 @@
 }
 
+#endif
+
 /** Initialize debugger */
 void debugger_init()
@@ -275,20 +281,22 @@
 	for (i = 0; i < BKPOINTS_MAX; i++)
 		breakpoints[i].address = NULL;
-	
+
+#ifdef CONFIG_KCONSOLE
 	cmd_initialize(&bkpts_info);
 	if (!cmd_register(&bkpts_info))
-		panic("could not register command %s\n", bkpts_info.name);
+		printf("Cannot register command %s\n", bkpts_info.name);
 
 	cmd_initialize(&delbkpt_info);
 	if (!cmd_register(&delbkpt_info))
-		panic("could not register command %s\n", delbkpt_info.name);
+		printf("Cannot register command %s\n", delbkpt_info.name);
 
 	cmd_initialize(&addbkpt_info);
 	if (!cmd_register(&addbkpt_info))
-		panic("could not register command %s\n", addbkpt_info.name);
+		printf("Cannot register command %s\n", addbkpt_info.name);
 
 	cmd_initialize(&addbkpte_info);
 	if (!cmd_register(&addbkpte_info))
-		panic("could not register command %s\n", addbkpte_info.name);
+		printf("Cannot register command %s\n", addbkpte_info.name);
+#endif
 }
 
@@ -368,5 +376,5 @@
 			cur->bkfunc(cur, istate);
 	} else {
-		printf("***Type 'exit' to exit kconsole.\n");
+#ifdef CONFIG_KCONSOLE
 		/* This disables all other processors - we are not SMP,
 		 * actually this gets us to cpu_halt, if scheduler() is run
@@ -374,11 +382,12 @@
 		 *   so this is a good idea
 		 */	
-		atomic_set(&haltstate,1);
+		atomic_set(&haltstate, 1);
 		spinlock_unlock(&bkpoint_lock);
-
-		kconsole("debug");
-
+		
+		kconsole("debug", "Debug console ready (type 'exit' to continue)\n", false);
+		
 		spinlock_lock(&bkpoint_lock);
-		atomic_set(&haltstate,0);
+		atomic_set(&haltstate, 0);
+#endif
 	}
 	if (cur && cur->address == fireaddr && (cur->flags & BKPOINT_INPROG)) {
Index: kernel/arch/mips32/src/exception.c
===================================================================
--- kernel/arch/mips32/src/exception.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/arch/mips32/src/exception.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -46,5 +46,4 @@
 #include <interrupt.h>
 #include <func.h>
-#include <console/kconsole.h>
 #include <ddi/irq.h>
 #include <arch/debugger.h>
Index: kernel/genarch/include/fb/fb.h
===================================================================
--- kernel/genarch/include/fb/fb.h	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/genarch/include/fb/fb.h	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup genarch	
+/** @addtogroup genarch
  * @{
  */
@@ -66,4 +66,6 @@
 
 SPINLOCK_EXTERN(fb_lock);
+
+void fb_redraw(void);
 void fb_init(fb_properties_t *props);
 
Index: kernel/genarch/include/fb/font-8x16.h
===================================================================
--- kernel/genarch/include/fb/font-8x16.h	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/genarch/include/fb/font-8x16.h	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup genarch	
+/** @addtogroup genarch
  * @{
  */
@@ -36,8 +36,11 @@
 #define KERN_FONT_8X16_H_
 
-#define FONT_GLIPHS		256
-#define FONT_SCANLINES	16
+#define FONT_GLYPHS      256
+#define FONT_WIDTH       8
+#define FONT_SCANLINES   16
 
-extern unsigned char fb_font[FONT_GLIPHS * FONT_SCANLINES];
+#include <arch/types.h>
+
+extern uint8_t fb_font[FONT_GLYPHS * FONT_SCANLINES];
 
 #endif
Index: kernel/genarch/include/fb/visuals.h
===================================================================
--- kernel/genarch/include/fb/visuals.h	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/genarch/include/fb/visuals.h	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup genarch	
+/** @addtogroup genarch
  * @{
  */
@@ -36,13 +36,13 @@
 #define KERN_VISUALS_H_
 
-#define VISUAL_INDIRECT_8	0
+#define VISUAL_INDIRECT_8   0
 
-#define VISUAL_RGB_5_5_5	1
-#define VISUAL_RGB_5_6_5	2
-#define VISUAL_RGB_8_8_8	3
-#define VISUAL_RGB_8_8_8_0	4
-#define VISUAL_RGB_0_8_8_8	5
+#define VISUAL_RGB_5_5_5    1
+#define VISUAL_RGB_5_6_5    2
+#define VISUAL_RGB_8_8_8    3
+#define VISUAL_RGB_8_8_8_0  4
+#define VISUAL_RGB_0_8_8_8  5
 
-#define VISUAL_BGR_0_8_8_8	6
+#define VISUAL_BGR_0_8_8_8  6
 
 #endif
Index: kernel/genarch/src/acpi/acpi.c
===================================================================
--- kernel/genarch/src/acpi/acpi.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/genarch/src/acpi/acpi.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -50,6 +50,10 @@
 struct acpi_xsdt *acpi_xsdt = NULL;
 
-struct acpi_signature_map signature_map[] = { 
-	{ (uint8_t *)"APIC", (void *) &acpi_madt, "Multiple APIC Description Table" }
+struct acpi_signature_map signature_map[] = {
+	{
+		(uint8_t *) "APIC",
+		(void *) &acpi_madt,
+		"Multiple APIC Description Table"
+	}
 };
 
@@ -106,5 +110,5 @@
 					goto next;
 				*signature_map[j].sdt_ptr = h;
-				printf("%p: ACPI %s\n", *signature_map[j].sdt_ptr, signature_map[j].description);
+				LOG("%p: ACPI %s\n", *signature_map[j].sdt_ptr, signature_map[j].description);
 			}
 		}
@@ -127,5 +131,5 @@
 					goto next;
 				*signature_map[j].sdt_ptr = h;
-				printf("%p: ACPI %s\n", *signature_map[j].sdt_ptr, signature_map[j].description);
+				LOG("%p: ACPI %s\n", *signature_map[j].sdt_ptr, signature_map[j].description);
 			}
 		}
@@ -161,5 +165,5 @@
 
 rsdp_found:
-	printf("%p: ACPI Root System Description Pointer\n", acpi_rsdp);
+	LOG("%p: ACPI Root System Description Pointer\n", acpi_rsdp);
 
 	acpi_rsdt = (struct acpi_rsdt *) (unative_t) acpi_rsdp->rsdt_address;
Index: kernel/genarch/src/fb/fb.c
===================================================================
--- kernel/genarch/src/fb/fb.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/genarch/src/fb/fb.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -1,3 +1,4 @@
 /*
+ * Copyright (c) 2008 Martin Decky
  * Copyright (c) 2006 Ondrej Palkovsky
  * All rights reserved.
@@ -27,5 +28,5 @@
  */
 
-/** @addtogroup genarch	
+/** @addtogroup genarch
  * @{
  */
@@ -40,4 +41,5 @@
 #include <sysinfo/sysinfo.h>
 #include <mm/slab.h>
+#include <align.h>
 #include <panic.h>
 #include <memstr.h>
@@ -48,135 +50,107 @@
 #include <arch/types.h>
 
-#include "helenos.xbm"
-
-static parea_t fb_parea;		/**< Physical memory area for fb. */
-
 SPINLOCK_INITIALIZE(fb_lock);
 
-static uint8_t *fbaddress = NULL;
-
-static uint8_t *blankline = NULL;
-static uint8_t *dbbuffer = NULL;	/* Buffer for fast scrolling console */
-static index_t dboffset;
-
-static unsigned int xres = 0;
-static unsigned int yres = 0;
-static unsigned int scanline = 0;
-static unsigned int pixelbytes = 0;
-#ifdef FB_INVERT_COLORS
-static bool invert_colors = true;
+/**< Physical memory area for fb. */
+static parea_t fb_parea;
+
+static uint8_t *fb_addr;
+static uint8_t *backbuf;
+static uint8_t *glyphs;
+
+static void *bgpixel;
+
+static unsigned int xres;
+static unsigned int yres;
+
+static unsigned int scanline;
+static unsigned int glyphscanline;
+
+static unsigned int pixelbytes;
+static unsigned int glyphbytes;
+
+static unsigned int cols;
+static unsigned int rows;
+static unsigned int position = 0;
+
+#define BG_COLOR     0x000080
+#define FG_COLOR     0xffff00
+
+#define CURSOR       219
+
+#define RED(x, bits)         ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1))
+#define GREEN(x, bits)       ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
+#define BLUE(x, bits)        ((x >> (8 - bits)) & ((1 << bits) - 1))
+
+#define COL2X(col)           ((col) * FONT_WIDTH)
+#define ROW2Y(row)           ((row) * FONT_SCANLINES)
+
+#define X2COL(x)             ((x) / FONT_WIDTH)
+#define Y2ROW(y)             ((y) / FONT_SCANLINES)
+
+#define FB_POS(x, y)         ((y) * scanline + (x) * pixelbytes)
+#define BB_POS(col, row)     ((row) * cols + (col))
+#define GLYPH_POS(glyph, y)  ((glyph) * glyphbytes + (y) * glyphscanline)
+
+
+static void (*rgb_conv)(void *, uint32_t);
+
+
+/** ARGB 8:8:8:8 conversion
+ *
+ */
+static void rgb_0888(void *dst, uint32_t rgb)
+{
+	*((uint32_t *) dst) = rgb & 0xffffff;
+}
+
+
+/** ABGR 8:8:8:8 conversion
+ *
+ */
+static void bgr_0888(void *dst, uint32_t rgb)
+{
+	*((uint32_t *) dst)
+	    = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8);
+}
+
+
+/** BGR 8:8:8 conversion
+ *
+ */
+static void rgb_888(void *dst, uint32_t rgb)
+{
+#if defined(FB_INVERT_ENDIAN)
+	*((uint32_t *) dst)
+	    = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8)
+	    | (*((uint32_t *) dst) & 0xff0000);
 #else
-static bool invert_colors = false;
+	*((uint32_t *) dst)
+	    = (rgb & 0xffffff) | (*((uint32_t *) dst) & 0xff0000);
 #endif
-
-static unsigned int position = 0;
-static unsigned int columns = 0;
-static unsigned int rows = 0;
-
-#define COL_WIDTH	8
-#define ROW_BYTES	(scanline * FONT_SCANLINES)
-
-#define BGCOLOR		0x000080
-#define FGCOLOR		0xffff00
-#define LOGOCOLOR	0x2020b0
-
-#define RED(x, bits)	((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1))
-#define GREEN(x, bits)	((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
-#define BLUE(x, bits)	((x >> (8 - bits)) & ((1 << bits) - 1))
-
-#define POINTPOS(x, y)	((y) * scanline + (x) * pixelbytes)
-
-/***************************************************************/
-/* Pixel specific fuctions */
-
-static void (*rgb2scr)(void *, int);
-static int (*scr2rgb)(void *);
-
-static inline int COLOR(int color)
-{
-	return invert_colors ? ~color : color;
-}
-
-/* Conversion routines between different color representations */
-static void rgb_byte0888(void *dst, int rgb)
-{
-	*((int *) dst) = rgb;
-}
-
-static int byte0888_rgb(void *src)
-{
-	return (*((int *) src)) & 0xffffff;
-}
-
-static void bgr_byte0888(void *dst, int rgb)
-{
-	*((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 |
-	    RED(rgb, 8);
-}
-
-static int byte0888_bgr(void *src)
-{
-	int color = *(uint32_t *)(src);
-	return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) |
-	    ((color >> 16) & 0xff);
-}
-
-static void rgb_byte888(void *dst, int rgb)
-{
-	uint8_t *scr = (uint8_t *) dst;
-#if defined(FB_INVERT_ENDIAN)
-	scr[0] = RED(rgb, 8);
-	scr[1] = GREEN(rgb, 8);
-	scr[2] = BLUE(rgb, 8);
-#else
-	scr[2] = RED(rgb, 8);
-	scr[1] = GREEN(rgb, 8);
-	scr[0] = BLUE(rgb, 8);
-#endif
-}
-
-static int byte888_rgb(void *src)
-{
-	uint8_t *scr = (uint8_t *) src;
-#if defined(FB_INVERT_ENDIAN)
-	return scr[0] << 16 | scr[1] << 8 | scr[2];
-#else
-	return scr[2] << 16 | scr[1] << 8 | scr[0];
-#endif	
-}
-
-/**  16-bit depth (5:5:5) */
-static void rgb_byte555(void *dst, int rgb)
-{
-	/* 5-bit, 5-bits, 5-bits */ 
-	*((uint16_t *) dst) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 |
-	    BLUE(rgb, 5);
-}
-
-/** 16-bit depth (5:5:5) */
-static int byte555_rgb(void *src)
-{
-	int color = *(uint16_t *)(src);
-	return (((color >> 10) & 0x1f) << (16 + 3)) |
-	    (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3);
-}
-
-/**  16-bit depth (5:6:5) */
-static void rgb_byte565(void *dst, int rgb)
-{
-	/* 5-bit, 6-bits, 5-bits */ 
-	*((uint16_t *) dst) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 |
-	    BLUE(rgb, 5);
-}
-
-/** 16-bit depth (5:6:5) */
-static int byte565_rgb(void *src)
-{
-	int color = *(uint16_t *)(src);
-	return (((color >> 11) & 0x1f) << (16 + 3)) |
-	    (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
-}
-
-/** Put pixel - 8-bit depth (color palette/3:2:3, inverted)
+}
+
+
+/** RGB 5:5:5 conversion
+ *
+ */
+static void rgb_555(void *dst, uint32_t rgb)
+{
+	*((uint16_t *) dst)
+	    = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
+}
+
+
+/** RGB 5:6:5 conversion
+ *
+ */
+static void rgb_565(void *dst, uint32_t rgb)
+{
+	*((uint16_t *) dst)
+	    = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5);
+}
+
+
+/** RGB 3:2:3
  *
  * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer
@@ -186,5 +160,5 @@
  * and setting it to simulate the 8-bit truecolor.
  *
- * Currently we set the palette on the sparc64 port.
+ * Currently we set the palette on the ia32 and sparc64 port.
  *
  * Note that the byte is being inverted by this function. The reason is
@@ -194,205 +168,82 @@
  * 0 and 255 to other colors.
  */
-static void rgb_byte8(void *dst, int rgb)
-{
-	*((uint8_t *) dst) = 255 - (RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 |
-	    BLUE(rgb, 3));
-}
-
-/** Return pixel color - 8-bit depth (color palette/3:2:3)
- *
- * See the comment for rgb_byte().
- */
-static int byte8_rgb(void *src)
-{
-	int color = 255 - (*(uint8_t *)src);
-	return (((color >> 5) & 0x7) << (16 + 5)) |
-	    (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
-}
-
-static void putpixel(unsigned int x, unsigned int y, int color)
-{
-	(*rgb2scr)(&fbaddress[POINTPOS(x, y)], COLOR(color));
-
-	if (dbbuffer) {
-		int dline = (y + dboffset) % yres;
-		(*rgb2scr)(&dbbuffer[POINTPOS(x, dline)], COLOR(color));
-	}
-}
-
-/** Get pixel from viewport */
-static int getpixel(unsigned int x, unsigned int y)
-{
-	if (dbbuffer) {
-		int dline = (y + dboffset) % yres;
-		return COLOR((*scr2rgb)(&dbbuffer[POINTPOS(x, dline)]));
-	}
-	return COLOR((*scr2rgb)(&fbaddress[POINTPOS(x, y)]));
-}
-
-
-/** Fill screen with background color */
-static void clear_screen(void)
-{
-	unsigned int y;
-
-	for (y = 0; y < yres; y++) {
-		memcpy(&fbaddress[scanline * y], blankline, xres * pixelbytes);
-		if (dbbuffer)
-			memcpy(&dbbuffer[scanline * y], blankline,
-			    xres * pixelbytes);
-	}
-}
-
-
-/** Scroll screen one row up */
+static void rgb_323(void *dst, uint32_t rgb)
+{
+	*((uint8_t *) dst)
+	    = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
+}
+
+
+/** Draw character at given position
+ *
+ */
+static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row)
+{
+	unsigned int x = COL2X(col);
+	unsigned int y = ROW2Y(row);
+	unsigned int yd;
+	
+	backbuf[BB_POS(col, row)] = glyph;
+	
+	for (yd = 0; yd < FONT_SCANLINES; yd++)
+		memcpy(&fb_addr[FB_POS(x, y + yd)],
+		    &glyphs[GLYPH_POS(glyph, yd)], glyphscanline);
+}
+
+
+/** Scroll screen down by one row
+ *
+ *
+ */
 static void scroll_screen(void)
 {
-	if (dbbuffer) {
-		count_t first;
+	unsigned int row;
+	
+	for (row = 0; row < rows; row++) {
+		unsigned int y = ROW2Y(row);
+		unsigned int yd;
 		
-		/* Clear the last row */
-		memcpy(&dbbuffer[dboffset * scanline], blankline, ROW_BYTES);
-		
-		dboffset = (dboffset + FONT_SCANLINES) % yres;
-		first = yres - dboffset;
-		
-		/* Move all rows one row up */
-		if (xres * pixelbytes == scanline) {
-			memcpy(fbaddress, &dbbuffer[dboffset * scanline],
-			    first * scanline);
-			memcpy(&fbaddress[first * scanline], dbbuffer,
-			    dboffset * scanline);
-		} else {
-			/*
-			 * When the scanline is bigger than number of bytes
-			 * in the X-resolution, chances are that the
-			 * frame buffer memory past the X-resolution is special
-			 * in some way. For example, the SUNW,ffb framebuffer
-			 * wraps this area around the beginning of the same
-			 * line. To avoid troubles, copy only memory as
-			 * specified by the resolution.
-			 */
-			unsigned int i;
-
-			for (i = 0; i < first; i++)
-				memcpy(&fbaddress[i * scanline],
-				    &dbbuffer[(dboffset + i) * scanline],
-				    xres * pixelbytes);
-			for (i = 0; i < dboffset; i++)
-				memcpy(&fbaddress[(first + i) * scanline],
-				    &dbbuffer[i * scanline], xres * pixelbytes);
+		for (yd = 0; yd < FONT_SCANLINES; yd++) {
+			unsigned int x;
+			unsigned int col;
+			
+			for (col = 0, x = 0; col < cols; col++, x += FONT_WIDTH) {
+				uint8_t glyph;
+				
+				if (row < rows - 1) {
+					if (backbuf[BB_POS(col, row)] == backbuf[BB_POS(col, row + 1)])
+						continue;
+					
+					glyph = backbuf[BB_POS(col, row + 1)];
+				} else
+					glyph = 0;
+				
+				memcpy(&fb_addr[FB_POS(x, y + yd)],
+				    &glyphs[GLYPH_POS(glyph, yd)], glyphscanline);
+			}
 		}
-	} else {
-		uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES];
-		
-		if (xres * pixelbytes == scanline) {
-			/* Move all rows one row up */
-			memcpy((void *) fbaddress,
-			    (void *) &fbaddress[ROW_BYTES],
-			    scanline * yres - ROW_BYTES);
-			/* Clear the last row */
-			memcpy((void *) lastline, (void *) blankline,
-			    ROW_BYTES);
-		} else {
-			/*
-			 * See the comment in the dbbuffer case.
-			 */
-			unsigned int i;
-
-			/* Move all rows one row up */
-			for (i = 0; i < yres - FONT_SCANLINES; i++)
-				memcpy(&fbaddress[i * scanline],
-				    &fbaddress[(i + FONT_SCANLINES) * scanline],
-				    xres * pixelbytes);
-			/* Clear the last row */
-			for (i = 0; i < FONT_SCANLINES; i++)
-				memcpy(&lastline[i * scanline],
-				    &blankline[i * scanline],
-				    xres * pixelbytes);
-		}
-	}
-}
-
-
-static void invert_pixel(unsigned int x, unsigned int y)
-{
-	putpixel(x, y, ~getpixel(x, y));
-}
-
-
-/** Draw one line of glyph at a given position */
-static void draw_glyph_line(unsigned int glline, unsigned int x, unsigned int y)
-{
-	unsigned int i;
-
-	for (i = 0; i < 8; i++)
-		if (glline & (1 << (7 - i))) {
-			putpixel(x + i, y, FGCOLOR);
-		} else
-			putpixel(x + i, y, BGCOLOR);
-}
-
-/***************************************************************/
-/* Character-console functions */
-
-/** Draw character at given position */
-static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row)
-{
-	unsigned int y;
-
-	for (y = 0; y < FONT_SCANLINES; y++)
-		draw_glyph_line(fb_font[glyph * FONT_SCANLINES + y],
-		    col * COL_WIDTH, row * FONT_SCANLINES + y);
-}
-
-/** Invert character at given position */
-static void invert_char(unsigned int col, unsigned int row)
-{
-	unsigned int x;
-	unsigned int y;
-
-	for (x = 0; x < COL_WIDTH; x++)
-		for (y = 0; y < FONT_SCANLINES; y++)
-			invert_pixel(col * COL_WIDTH + x,
-			    row * FONT_SCANLINES + y);
-}
-
-/** Draw character at default position */
-static void draw_char(char chr)
-{
-	draw_glyph(chr, position % columns, position / columns);
-}
-
-static void draw_logo(unsigned int startx, unsigned int starty)
-{
-	unsigned int x;
-	unsigned int y;
-	unsigned int byte;
-	unsigned int rowbytes;
-
-	rowbytes = (helenos_width - 1) / 8 + 1;
-
-	for (y = 0; y < helenos_height; y++)
-		for (x = 0; x < helenos_width; x++) {
-			byte = helenos_bits[rowbytes * y + x / 8];
-			byte >>= x % 8;
-			if (byte & 1)
-				putpixel(startx + x, starty + y,
-				    COLOR(LOGOCOLOR));
-		}
-}
-
-/***************************************************************/
-/* Stdout specific functions */
-
-static void invert_cursor(void)
-{
-	invert_char(position % columns, position / columns);
-}
+	}
+	
+	memcpy(backbuf, backbuf + cols, cols * (rows - 1));
+	memsetb(&backbuf[BB_POS(0, rows - 1)], cols, 0);
+}
+
+
+static void cursor_put(void)
+{
+	draw_glyph(CURSOR, position % cols, position / cols);
+}
+
+
+static void cursor_remove(void)
+{
+	draw_glyph(0, position % cols, position / cols);
+}
+
 
 /** Print character to screen
  *
- *  Emulate basic terminal commands
+ * Emulate basic terminal commands.
+ *
  */
 static void fb_putchar(chardev_t *dev, char ch)
@@ -402,35 +253,35 @@
 	switch (ch) {
 	case '\n':
-		invert_cursor();
-		position += columns;
-		position -= position % columns;
+		cursor_remove();
+		position += cols;
+		position -= position % cols;
 		break;
 	case '\r':
-		invert_cursor();
-		position -= position % columns;
+		cursor_remove();
+		position -= position % cols;
 		break;
 	case '\b':
-		invert_cursor();
-		if (position % columns)
+		cursor_remove();
+		if (position % cols)
 			position--;
 		break;
 	case '\t':
-		invert_cursor();
+		cursor_remove();
 		do {
-			draw_char(' ');
+			draw_glyph((uint8_t) ' ', position % cols, position / cols);
 			position++;
-		} while ((position % 8) && position < columns * rows);
+		} while ((position % 8) && (position < cols * rows));
 		break;
 	default:
-		draw_char(ch);
+		draw_glyph((uint8_t) ch, position % cols, position / cols);
 		position++;
 	}
 	
-	if (position >= columns * rows) {
-		position -= columns;
+	if (position >= cols * rows) {
+		position -= cols;
 		scroll_screen();
 	}
 	
-	invert_cursor();
+	cursor_put();
 	
 	spinlock_unlock(&fb_lock);
@@ -443,7 +294,84 @@
 
 
+/** Render glyphs
+ *
+ * Convert glyphs from device independent font
+ * description to current visual representation.
+ *
+ */
+static void render_glyphs(void)
+{
+	unsigned int glyph;
+	
+	for (glyph = 0; glyph < FONT_GLYPHS; glyph++) {
+		unsigned int y;
+		
+		for (y = 0; y < FONT_SCANLINES; y++) {
+			unsigned int x;
+			
+			for (x = 0; x < FONT_WIDTH; x++)
+				rgb_conv(&glyphs[GLYPH_POS(glyph, y) + x * pixelbytes],
+				    (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x))) ? FG_COLOR : BG_COLOR);
+		}
+	}
+	
+	rgb_conv(bgpixel, BG_COLOR);
+}
+
+
+/** Refresh the screen
+ *
+ */
+void fb_redraw(void)
+{
+	unsigned int row;
+	
+	for (row = 0; row < rows; row++) {
+		unsigned int y = ROW2Y(row);
+		unsigned int yd;
+		
+		for (yd = 0; yd < FONT_SCANLINES; yd++) {
+			unsigned int x;
+			unsigned int col;
+			
+			for (col = 0, x = 0; col < cols; col++, x += FONT_WIDTH)
+				memcpy(&fb_addr[FB_POS(x, y + yd)],
+			    &glyphs[GLYPH_POS(backbuf[BB_POS(col, row)], yd)],
+			    glyphscanline);
+		}
+	}
+	
+	if (COL2X(cols) < xres) {
+		unsigned int y;
+		
+		for (y = 0; y < yres; y++) {
+			unsigned int x;
+			
+			for (x = COL2X(cols); x < xres; x++)
+				memcpy(&fb_addr[FB_POS(x, y)], bgpixel, pixelbytes);
+		}
+	}
+	
+	if (ROW2Y(rows) < yres) {
+		unsigned int y;
+		
+		for (y = ROW2Y(rows); y < yres; y++) {
+			unsigned int x;
+			
+			for (x = 0; x < xres; x++)
+				memcpy(&fb_addr[FB_POS(x, y)], bgpixel, pixelbytes);
+		}
+	}
+}
+
+
 /** Initialize framebuffer as a chardev output device
  *
- * @param props  	Properties of the framebuffer device.
+ * @param addr   Physical address of the framebuffer
+ * @param x      Screen width in pixels
+ * @param y      Screen height in pixels
+ * @param scan   Bytes per one scanline
+ * @param visual Color model
+ *
  */
 void fb_init(fb_properties_t *props)
@@ -451,36 +379,29 @@
 	switch (props->visual) {
 	case VISUAL_INDIRECT_8:
-		rgb2scr = rgb_byte8;
-		scr2rgb = byte8_rgb;
+		rgb_conv = rgb_323;
 		pixelbytes = 1;
 		break;
 	case VISUAL_RGB_5_5_5:
-		rgb2scr = rgb_byte555;
-		scr2rgb = byte555_rgb;
+		rgb_conv = rgb_555;
 		pixelbytes = 2;
 		break;
 	case VISUAL_RGB_5_6_5:
-		rgb2scr = rgb_byte565;
-		scr2rgb = byte565_rgb;
+		rgb_conv = rgb_565;
 		pixelbytes = 2;
 		break;
 	case VISUAL_RGB_8_8_8:
-		rgb2scr = rgb_byte888;
-		scr2rgb = byte888_rgb;
+		rgb_conv = rgb_888;
 		pixelbytes = 3;
 		break;
 	case VISUAL_RGB_8_8_8_0:
-		rgb2scr = rgb_byte888;
-		scr2rgb = byte888_rgb;
+		rgb_conv = rgb_888;
 		pixelbytes = 4;
 		break;
 	case VISUAL_RGB_0_8_8_8:
-		rgb2scr = rgb_byte0888;
-		scr2rgb = byte0888_rgb;
+		rgb_conv = rgb_0888;
 		pixelbytes = 4;
 		break;
 	case VISUAL_BGR_0_8_8_8:
-		rgb2scr = bgr_byte0888;
-		scr2rgb = byte0888_bgr;
+		rgb_conv = bgr_0888;
 		pixelbytes = 4;
 		break;
@@ -488,11 +409,4 @@
 		panic("Unsupported visual.\n");
 	}
-	
-	unsigned int fbsize = props->scan * props->y;
-	
-	/* Map the framebuffer */
-	fbaddress = (uint8_t *) hw_map((uintptr_t) props->addr,
-		fbsize + props->offset);
-	fbaddress += props->offset;
 	
 	xres = props->x;
@@ -500,47 +414,50 @@
 	scanline = props->scan;
 	
-	rows = props->y / FONT_SCANLINES;
-	columns = props->x / COL_WIDTH;
-
+	cols = xres / FONT_WIDTH;
+	rows = yres / FONT_SCANLINES;
+	
+	glyphscanline = FONT_WIDTH * pixelbytes;
+	glyphbytes = glyphscanline * FONT_SCANLINES;
+	
+	unsigned int fbsize = scanline * yres;
+	unsigned int bbsize = cols * rows;
+	unsigned int glyphsize = FONT_GLYPHS * glyphbytes;
+	
+	backbuf = (uint8_t *) malloc(bbsize, 0);
+	if (!backbuf)
+		panic("Unable to allocate backbuffer.\n");
+	
+	glyphs = (uint8_t *) malloc(glyphsize, 0);
+	if (!glyphs)
+		panic("Unable to allocate glyphs.\n");
+	
+	bgpixel = malloc(pixelbytes, 0);
+	if (!bgpixel)
+		panic("Unable to allocate background pixel.\n");
+	
+	memsetb(backbuf, bbsize, 0);
+	memsetb(glyphs, glyphsize, 0);
+	memsetb(bgpixel, pixelbytes, 0);
+	
+	render_glyphs();
+	
+	fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize);
+	
 	fb_parea.pbase = (uintptr_t) props->addr + props->offset;
-	fb_parea.vbase = (uintptr_t) fbaddress;
+	fb_parea.vbase = (uintptr_t) fb_addr;
 	fb_parea.frames = SIZE2FRAMES(fbsize);
 	fb_parea.cacheable = false;
 	ddi_parea_register(&fb_parea);
-
+	
 	sysinfo_set_item_val("fb", NULL, true);
 	sysinfo_set_item_val("fb.kind", NULL, 1);
 	sysinfo_set_item_val("fb.width", NULL, xres);
 	sysinfo_set_item_val("fb.height", NULL, yres);
-	sysinfo_set_item_val("fb.scanline", NULL, props->scan);
+	sysinfo_set_item_val("fb.scanline", NULL, scanline);
 	sysinfo_set_item_val("fb.visual", NULL, props->visual);
 	sysinfo_set_item_val("fb.address.physical", NULL, props->addr);
-	sysinfo_set_item_val("fb.offset", NULL, props->offset);
-	sysinfo_set_item_val("fb.invert-colors", NULL, invert_colors);
-
-	/* Allocate double buffer */
-	unsigned int order = fnzb(SIZE2FRAMES(fbsize) - 1) + 1;
-	dbbuffer = (uint8_t *) frame_alloc(order, FRAME_ATOMIC | FRAME_KA);
-	if (!dbbuffer)
-		printf("Failed to allocate scroll buffer.\n");
-	dboffset = 0;
-
-	/* Initialized blank line */
-	blankline = (uint8_t *) malloc(ROW_BYTES, FRAME_ATOMIC);
-	if (!blankline)
-		panic("Failed to allocate blank line for framebuffer.");
-	unsigned int x, y;
-	for (y = 0; y < FONT_SCANLINES; y++)
-		for (x = 0; x < xres; x++)
-			(*rgb2scr)(&blankline[POINTPOS(x, y)], COLOR(BGCOLOR));
-	
-	clear_screen();
-
-	/* Update size of screen to match text area */
-	yres = rows * FONT_SCANLINES;
-
-	draw_logo(xres - helenos_width, 0);
-	invert_cursor();
-
+	
+	fb_redraw();
+	
 	chardev_initialize("fb", &framebuffer, &fb_ops);
 	stdout = &framebuffer;
Index: kernel/genarch/src/fb/font-8x16.c
===================================================================
--- kernel/genarch/src/fb/font-8x16.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/genarch/src/fb/font-8x16.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -35,5 +35,5 @@
 #include <genarch/fb/font-8x16.h>
 
-unsigned char fb_font[FONT_GLIPHS * FONT_SCANLINES] = {
+uint8_t fb_font[FONT_GLYPHS * FONT_SCANLINES] = {
 
 	/* 0 0x00 '^@' */
Index: rnel/genarch/src/fb/helenos.xbm
===================================================================
--- kernel/genarch/src/fb/helenos.xbm	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ 	(revision )
@@ -1,163 +1,0 @@
-#define helenos_width 127
-#define helenos_height 120
-static unsigned char helenos_bits[] = {
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x1f, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x80, 0x0f, 0x78, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0xf0, 0x01, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x80, 0x81,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
-   0x0f, 0x00, 0x00, 0x83, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0xf0, 0x01, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x06,
-   0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x07,
-   0x00, 0x00, 0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x02, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x0c,
-   0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00,
-   0x00, 0x00, 0x00, 0x18, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0c, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x80, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
-   0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x18, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
-   0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x01, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x20, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
-   0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0xc0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x80, 0xc1, 0x00, 0x00, 0x00,
-   0x00, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x80,
-   0xc1, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0xfe, 0x01, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0xff, 0x03, 0x00, 0x00, 0x83, 0x01, 0x00, 0x00,
-   0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x03, 0x00, 0x00,
-   0x03, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0xff, 0x07, 0x00, 0x00, 0x06, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0x06, 0x03, 0x00, 0x00,
-   0x08, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00,
-   0x0c, 0x02, 0x00, 0x00, 0x08, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0xff, 0x0f, 0x00, 0x00, 0x0c, 0x06, 0x00, 0x00, 0x08, 0x03, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0xfe, 0x0f, 0x00, 0x00, 0x18, 0x04, 0x00, 0x00,
-   0x08, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x1f, 0x00, 0x00,
-   0x18, 0x0c, 0x00, 0x00, 0x08, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
-   0xfc, 0x1f, 0x00, 0x00, 0x18, 0x0c, 0x00, 0x00, 0x08, 0x03, 0x00, 0x00,
-   0x80, 0x1f, 0x00, 0x00, 0xfc, 0x1f, 0x00, 0x00, 0x30, 0x18, 0x00, 0x00,
-   0x18, 0x02, 0x00, 0x00, 0xc0, 0x3f, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x00,
-   0x30, 0x18, 0x00, 0x00, 0x18, 0x06, 0x00, 0x00, 0xe0, 0x7f, 0x00, 0x00,
-   0xf8, 0x3f, 0x00, 0x00, 0x60, 0x10, 0x00, 0x00, 0x18, 0x06, 0x00, 0x00,
-   0xe0, 0x7f, 0x00, 0x00, 0xf8, 0x7f, 0x00, 0x00, 0x60, 0x30, 0x00, 0x00,
-   0x38, 0x0c, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00,
-   0xe0, 0x20, 0x00, 0x00, 0x30, 0x0c, 0x00, 0x00, 0xe0, 0xff, 0x00, 0x00,
-   0xf0, 0x7f, 0x00, 0x00, 0xc0, 0x78, 0x00, 0x00, 0x70, 0x08, 0x00, 0x00,
-   0xe0, 0xff, 0x00, 0x00, 0xf0, 0xff, 0x00, 0x00, 0xc0, 0x7c, 0x00, 0x00,
-   0x70, 0x18, 0x00, 0x00, 0xe0, 0xff, 0x01, 0x00, 0xf0, 0xff, 0x00, 0x00,
-   0x80, 0xfd, 0x00, 0x00, 0x60, 0x3f, 0x00, 0x00, 0xc0, 0xff, 0x01, 0x00,
-   0xfc, 0xff, 0x01, 0x00, 0x80, 0xf9, 0x00, 0x00, 0xe0, 0x3f, 0x00, 0x00,
-   0xc0, 0xff, 0x01, 0x80, 0xff, 0xff, 0x01, 0x00, 0x80, 0xfb, 0x00, 0x00,
-   0xc0, 0x7f, 0x00, 0x00, 0xc0, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x03, 0x00,
-   0x00, 0xf3, 0x01, 0x00, 0xc0, 0x7f, 0x00, 0x00, 0x80, 0xff, 0x03, 0xfc,
-   0xff, 0xff, 0x03, 0x00, 0x00, 0xf3, 0x01, 0x00, 0xc0, 0x7f, 0x00, 0x00,
-   0x80, 0xff, 0x07, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xf6, 0x03, 0x00,
-   0x80, 0xff, 0x00, 0x00, 0x00, 0xff, 0xe7, 0xff, 0xff, 0xff, 0x07, 0x00,
-   0x00, 0xe6, 0x03, 0x00, 0x80, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
-   0xff, 0xff, 0x07, 0x00, 0x00, 0xec, 0x07, 0x00, 0x00, 0xff, 0x01, 0x00,
-   0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xcc, 0x07, 0x00,
-   0x00, 0xff, 0x01, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0x0f, 0x00,
-   0x00, 0xdc, 0x07, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0xfe, 0xff, 0xff,
-   0x1f, 0xfe, 0x0f, 0x00, 0x00, 0xd8, 0x0f, 0x00, 0x00, 0xfe, 0x03, 0x00,
-   0x00, 0xfc, 0xff, 0xff, 0x03, 0xfe, 0x1f, 0x00, 0x00, 0x98, 0x0f, 0x00,
-   0x00, 0xfe, 0x03, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x00, 0xfc, 0x1f, 0x00,
-   0x00, 0xb0, 0x1f, 0x00, 0x00, 0xfc, 0x07, 0x00, 0x00, 0xf8, 0xff, 0x1f,
-   0x00, 0xfc, 0x3f, 0x00, 0x00, 0x30, 0x1f, 0x00, 0x00, 0xfc, 0x07, 0x00,
-   0x00, 0xf8, 0xff, 0x07, 0x00, 0xfc, 0x3f, 0x00, 0x00, 0x70, 0x1f, 0x00,
-   0x00, 0xfc, 0x07, 0x00, 0x00, 0xf8, 0xff, 0x00, 0x00, 0xf8, 0x7f, 0x00,
-   0x00, 0x60, 0x3e, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xf0, 0x7f, 0x00,
-   0x00, 0xf8, 0x7f, 0x00, 0x00, 0xe0, 0x3e, 0x00, 0x00, 0xf8, 0x0f, 0x00,
-   0x00, 0xf0, 0x7f, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xf8, 0x7e, 0x00,
-   0x00, 0xf0, 0x1f, 0x00, 0x00, 0xf0, 0xff, 0x00, 0x00, 0xf0, 0xff, 0x00,
-   0x00, 0xfc, 0x7c, 0x00, 0x00, 0xf0, 0x1f, 0x00, 0x00, 0xe0, 0xff, 0x00,
-   0x00, 0xf0, 0xff, 0x00, 0x00, 0xfe, 0xfd, 0x00, 0x00, 0xf0, 0x1f, 0x00,
-   0x00, 0xe0, 0xff, 0x01, 0x00, 0xe0, 0xff, 0x00, 0x80, 0xff, 0xf9, 0x00,
-   0x00, 0xe0, 0x3f, 0x00, 0x00, 0xc0, 0xff, 0x01, 0x00, 0xe0, 0xff, 0x00,
-   0xc0, 0xff, 0xfb, 0x00, 0x00, 0xe0, 0x3f, 0x00, 0x00, 0xc0, 0xff, 0x03,
-   0x00, 0xc0, 0x7f, 0x00, 0xe0, 0xff, 0xfb, 0x01, 0x00, 0xc0, 0x7f, 0x00,
-   0x00, 0x80, 0xff, 0x03, 0x00, 0xc0, 0x7f, 0x00, 0xf8, 0xff, 0xf7, 0x01,
-   0x00, 0xc0, 0x7f, 0x00, 0x00, 0x80, 0xff, 0x03, 0x00, 0x80, 0x3f, 0x00,
-   0xfc, 0xff, 0xf7, 0x03, 0x00, 0xc0, 0x7f, 0x00, 0x00, 0x80, 0xff, 0x07,
-   0x00, 0x00, 0x00, 0x00, 0xfe, 0xef, 0xe7, 0x03, 0x00, 0x80, 0xff, 0x00,
-   0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0x00, 0x80, 0xff, 0xdf, 0xef, 0x07,
-   0x00, 0x80, 0xff, 0x00, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0x00, 0xc0,
-   0xff, 0xdf, 0xef, 0x07, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0xff, 0x0f,
-   0x00, 0x00, 0x00, 0xe0, 0xff, 0xcf, 0xcf, 0x07, 0x00, 0x00, 0xff, 0x01,
-   0x00, 0x00, 0xfe, 0x1f, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0xc3, 0xcf, 0x0f,
-   0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0xfe, 0x1f, 0x00, 0x00, 0x00, 0xfc,
-   0xff, 0xe0, 0xcf, 0x0f, 0x00, 0x00, 0xfe, 0x03, 0x00, 0x00, 0xfc, 0x1f,
-   0x00, 0x00, 0x00, 0xfe, 0xff, 0xf9, 0xc7, 0x0f, 0x00, 0x00, 0xfe, 0x03,
-   0x00, 0x00, 0xfc, 0x1f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xe7, 0x0f,
-   0x00, 0x00, 0xfc, 0x07, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xc0, 0xff,
-   0xff, 0xff, 0xe7, 0x0f, 0x00, 0x00, 0xfc, 0x07, 0x00, 0x00, 0xf8, 0x07,
-   0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xe3, 0x0f, 0x00, 0x00, 0xfc, 0x0f,
-   0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xf1, 0x0f,
-   0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff,
-   0xff, 0xff, 0xf8, 0x0f, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0xfe, 0xff, 0xff, 0x3f, 0xfc, 0x0f, 0x00, 0x00, 0xf0, 0x1f,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x07, 0xfe, 0x0f,
-   0x00, 0x00, 0xf0, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff,
-   0xff, 0x81, 0xff, 0x07, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0xe0, 0xff, 0xff, 0x3f, 0xe0, 0xff, 0x07, 0x00, 0x00, 0xe0, 0x3f,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x07, 0xfc, 0xff, 0x07,
-   0x00, 0x00, 0xe0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff,
-   0x80, 0xff, 0xff, 0x03, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0xfe, 0xff, 0x1f, 0xf0, 0xff, 0xff, 0x01, 0x00, 0x00, 0xc0, 0x7f,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x07, 0xfe, 0xff, 0xff, 0x00,
-   0x00, 0x00, 0xc0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xc0,
-   0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x80, 0xbf, 0x00, 0x00, 0x00, 0x00,
-   0xe0, 0xff, 0x1f, 0xf0, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x80, 0xdf,
-   0x00, 0x3c, 0x00, 0x00, 0xf0, 0xff, 0x03, 0xfe, 0xff, 0xff, 0x0f, 0x00,
-   0x00, 0x00, 0x00, 0xcf, 0x00, 0x7e, 0x00, 0x00, 0xfc, 0x7f, 0xc0, 0xff,
-   0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x01, 0x7e, 0x00, 0x00,
-   0xfe, 0x0f, 0xf8, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97,
-   0x01, 0x3e, 0x00, 0x00, 0xff, 0x03, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x9e, 0x03, 0x00, 0x00, 0xc0, 0x7f, 0xc0, 0xff, 0xff,
-   0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x03, 0x00, 0x00, 0xe0,
-   0x0f, 0xf8, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c,
-   0x03, 0x00, 0x00, 0xf8, 0x01, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x7c, 0x06, 0x00, 0x00, 0x3f, 0xe0, 0xff, 0xff, 0xff,
-   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x0e, 0x00, 0xe0, 0x0f,
-   0xfc, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8,
-   0x3c, 0x00, 0xfc, 0x01, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0xf8, 0x78, 0x80, 0x3f, 0xe0, 0xff, 0xff, 0xff, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xe1, 0xff, 0x07, 0xfc,
-   0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0,
-   0x81, 0xff, 0x80, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0xf0, 0x03, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00, 0xfe, 0xff,
-   0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0,
-   0x0f, 0x00, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0xc0, 0x3f, 0xc0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff,
-   0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
-   0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x1f,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x0f, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0xf0, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
Index: kernel/genarch/src/mm/asid.c
===================================================================
--- kernel/genarch/src/mm/asid.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/genarch/src/mm/asid.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -33,5 +33,5 @@
 /**
  * @file
- * @brief	ASID management.
+ * @brief ASID management.
  *
  * Modern processor architectures optimize TLB utilization
Index: kernel/generic/include/console/kconsole.h
===================================================================
--- kernel/generic/include/console/kconsole.h	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/generic/include/console/kconsole.h	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -88,5 +88,6 @@
 
 extern void kconsole_init(void);
-extern void kconsole(void *prompt);
+extern void kconsole(char *prompt, char *msg, bool kcon);
+extern void kconsole_thread(void *data);
 
 extern int cmd_register(cmd_info_t *cmd);
Index: kernel/generic/src/console/cmd.c
===================================================================
--- kernel/generic/src/console/cmd.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/generic/src/console/cmd.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -502,5 +502,5 @@
 		cmd_initialize(basic_commands[i]);
 		if (!cmd_register(basic_commands[i]))
-			panic("could not register command %s\n", basic_commands[i]->name);
+			printf("Cannot register command %s\n", basic_commands[i]->name);
 	}
 }
Index: kernel/generic/src/console/console.c
===================================================================
--- kernel/generic/src/console/console.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/generic/src/console/console.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -168,5 +168,5 @@
 		else
 			printf("cpu: ");
-		printf("halted - no kconsole\n");
+		printf("halted (no kconsole)\n");
 		cpu_halt();
 	}
Index: kernel/generic/src/console/kconsole.c
===================================================================
--- kernel/generic/src/console/kconsole.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/generic/src/console/kconsole.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -402,9 +402,13 @@
 }
 
-/** Kernel console managing thread.
+/** Kernel console prompt.
  *
  * @param prompt Kernel console prompt (e.g kconsole/panic).
- */
-void kconsole(void *prompt)
+ * @param msg    Message to display in the beginning.
+ * @param kcon   Wait for keypress to show the prompt
+ *               and never exit.
+ *
+ */
+void kconsole(char *prompt, char *msg, bool kcon)
 {
 	cmd_info_t *cmd_info;
@@ -413,7 +417,13 @@
 
 	if (!stdin) {
-		printf("%s: no stdin\n", __func__);
+		LOG("No stdin for kernel console");
 		return;
 	}
+	
+	if (msg)
+		printf("%s", msg);
+	
+	if (kcon)
+		_getc(stdin);
 	
 	while (true) {
@@ -422,12 +432,23 @@
 		if (!len)
 			continue;
+		
 		cmd_info = parse_cmdline(cmdline, len);
 		if (!cmd_info)
 			continue;
-		if (strncmp(cmd_info->name, "exit",
-		    min(strlen(cmd_info->name), 5)) == 0)
+		
+		if ((!kcon)
+		    && (strncmp(cmd_info->name, "exit", min(strlen(cmd_info->name), 5)) == 0))
 			break;
+		
 		(void) cmd_info->func(cmd_info->argv);
 	}
+}
+
+/** Kernel console managing thread.
+ *
+ */
+void kconsole_thread(void *data)
+{
+	kconsole("kconsole", "Kernel console ready (press any key to activate)\n", true);
 }
 
Index: kernel/generic/src/cpu/cpu.c
===================================================================
--- kernel/generic/src/cpu/cpu.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/generic/src/cpu/cpu.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -87,5 +87,5 @@
 #endif /* CONFIG_SMP */
 
-	CPU = &cpus[config.cpu_active-1];
+	CPU = &cpus[config.cpu_active - 1];
 	
 	CPU->active = 1;
Index: kernel/generic/src/interrupt/interrupt.c
===================================================================
--- kernel/generic/src/interrupt/interrupt.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/generic/src/interrupt/interrupt.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -110,6 +110,8 @@
 }
 
+#ifdef CONFIG_KCONSOLE
+
 /** kconsole cmd - print all exceptions */
-static int exc_print_cmd(cmd_arg_t *argv)
+static int cmd_exc_print(cmd_arg_t *argv)
 {
 #if (IVT_ITEMS > 0)
@@ -159,12 +161,15 @@
 }
 
+
 static cmd_info_t exc_info = {
 	.name = "exc",
 	.description = "Print exception table.",
-	.func = exc_print_cmd,
+	.func = cmd_exc_print,
 	.help = NULL,
 	.argc = 0,
 	.argv = NULL
 };
+
+#endif
 
 /** Initialize generic exception handling support */
@@ -176,7 +181,9 @@
 		exc_register(i, "undef", (iroutine) exc_undef);
 
+#ifdef CONFIG_KCONSOLE
 	cmd_initialize(&exc_info);
 	if (!cmd_register(&exc_info))
-		panic("could not register command %s\n", exc_info.name);
+		printf("Cannot register command %s\n", exc_info.name);
+#endif
 }
 
Index: kernel/generic/src/lib/func.c
===================================================================
--- kernel/generic/src/lib/func.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/generic/src/lib/func.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -56,6 +56,4 @@
 	bool rundebugger = false;
 
-//      TODO test_and_set not defined on all arches
-//	if (!test_and_set(&haltstate))
 	if (!atomic_get(&haltstate)) {
 		atomic_set(&haltstate, 1);
@@ -67,10 +65,10 @@
 
 	interrupts_disable();
-#ifdef CONFIG_DEBUG
-	if (rundebugger) {
-		printf("\n");
-		kconsole("panic"); /* Run kconsole as a last resort to user */
-	}
-#endif      
+	
+#if (defined(CONFIG_DEBUG)) && (defined(CONFIG_KCONSOLE))
+	if (rundebugger)
+		kconsole("panic", "\nLast resort kernel console ready\n", false);
+#endif
+	
 	if (CPU)
 		printf("cpu%u: halted\n", CPU->id);
Index: kernel/generic/src/main/kinit.c
===================================================================
--- kernel/generic/src/main/kinit.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/generic/src/main/kinit.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -83,5 +83,8 @@
 void kinit(void *arg)
 {
-	thread_t *t;
+
+#if defined(CONFIG_SMP) || defined(CONFIG_KCONSOLE)
+	thread_t *thread;
+#endif
 
 	/*
@@ -101,21 +104,17 @@
 		 * Just a beautification.
 		 */
-		if ((t = thread_create(kmp, NULL, TASK, THREAD_FLAG_WIRED,
-		    "kmp", true))) {
-			spinlock_lock(&t->lock);
-			t->cpu = &cpus[0];
-			spinlock_unlock(&t->lock);
-			thread_ready(t);
+		thread = thread_create(kmp, NULL, TASK, THREAD_FLAG_WIRED, "kmp", true);
+		if (thread != NULL) {
+			spinlock_lock(&thread->lock);
+			thread->cpu = &cpus[0];
+			spinlock_unlock(&thread->lock);
+			thread_ready(thread);
 		} else
-			panic("thread_create/kmp\n");
-		thread_join(t);
-		thread_detach(t);
+			panic("Unable to create kmp thread\n");
+		thread_join(thread);
+		thread_detach(thread);
 	}
 #endif /* CONFIG_SMP */
-	/*
-	 * Now that all CPUs are up, we can report what we've found.
-	 */
-	cpu_list();
-
+	
 #ifdef CONFIG_SMP
 	if (config.cpu_count > 1) {
@@ -126,18 +125,17 @@
 		 */
 		for (i = 0; i < config.cpu_count; i++) {
-
-			if ((t = thread_create(kcpulb, NULL, TASK,
-			    THREAD_FLAG_WIRED, "kcpulb", true))) {
-				spinlock_lock(&t->lock);			
-				t->cpu = &cpus[i];
-				spinlock_unlock(&t->lock);
-				thread_ready(t);
+			thread = thread_create(kcpulb, NULL, TASK, THREAD_FLAG_WIRED, "kcpulb", true);
+			if (thread != NULL) {
+				spinlock_lock(&thread->lock);
+				thread->cpu = &cpus[i];
+				spinlock_unlock(&thread->lock);
+				thread_ready(thread);
 			} else
-				panic("thread_create/kcpulb\n");
+				printf("Unable to create kcpulb thread for cpu" PRIc "\n", i);
 
 		}
 	}
 #endif /* CONFIG_SMP */
-
+	
 	/*
 	 * At this point SMP, if present, is configured.
@@ -145,14 +143,17 @@
 	arch_post_smp_init();
 
-	/*
-	 * Create kernel console.
-	 */
-	t = thread_create(kconsole, (void *) "kconsole", TASK, 0, "kconsole",
-	    false);
-	if (t)
-		thread_ready(t);
-	else
-		panic("thread_create/kconsole\n");
-
+#ifdef CONFIG_KCONSOLE
+	if (stdin) {
+		/*
+		 * Create kernel console.
+		 */
+		thread = thread_create(kconsole_thread, NULL, TASK, 0, "kconsole", false);
+		if (thread != NULL)
+			thread_ready(thread);
+		else
+			printf("Unable to create kconsole thread\n");
+	}
+#endif /* CONFIG_KCONSOLE */
+	
 	interrupts_enable();
 	
@@ -165,12 +166,12 @@
 	for (i = 0; i < init.cnt; i++) {
 		if (init.tasks[i].addr % FRAME_SIZE) {
-			printf("init[%" PRIc "].addr is not frame aligned", i);
+			printf("init[%" PRIc "].addr is not frame aligned\n", i);
 			continue;
 		}
-
+		
 		int rc = program_create_from_image((void *) init.tasks[i].addr,
 		    "init-bin", &programs[i]);
-
-		if (rc == 0 && programs[i].task != NULL) {
+		
+		if ((rc == 0) && (programs[i].task != NULL)) {
 			/*
 			 * Set capabilities to init userspace tasks.
@@ -185,10 +186,8 @@
 		} else {
 			/* RAM disk image */
-			int rd = init_rd((rd_header_t *) init.tasks[i].addr,
-			    init.tasks[i].size);
+			int rd = init_rd((rd_header_t *) init.tasks[i].addr, init.tasks[i].size);
 			
 			if (rd != RE_OK)
-				printf("Init binary %" PRIc " not used, error "
-				    "code %d.\n", i, rd);
+				printf("Init binary %" PRIc " not used (error %d)\n", i, rd);
 		}
 	}
@@ -204,10 +203,16 @@
 	}
 
+#ifdef CONFIG_KCONSOLE
 	if (!stdin) {
+		printf("kinit: No stdin\nKernel alive: ");
+		
+		uint64_t i = 0;
 		while (1) {
+			printf(PRIu64 " ", i);
 			thread_sleep(1);
-			printf("kinit... ");
-		}
-	}
+			i++;
+		}
+	}
+#endif /* CONFIG_KCONSOLE */
 }
 
Index: kernel/generic/src/main/main.c
===================================================================
--- kernel/generic/src/main/main.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/generic/src/main/main.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -192,6 +192,4 @@
 	/* Keep this the first thing. */
 	the_initialize(THE);
-
-	LOG();
 	
 	version_print();
@@ -201,6 +199,6 @@
 	    config.base, config.kernel_size, config.stack_base,
 	    config.stack_size);
-	
-
+
+#ifdef CONFIG_KCONSOLE
 	/*
 	 * kconsole data structures must be initialized very early
@@ -209,4 +207,5 @@
 	 */
 	LOG_EXEC(kconsole_init());
+#endif
 	
 	/*
@@ -253,5 +252,5 @@
 		count_t i;
 		for (i = 0; i < init.cnt; i++)
-			printf("init[%" PRIc "].addr=%#" PRIp ", init[%" PRIc
+			LOG("init[%" PRIc "].addr=%#" PRIp ", init[%" PRIc
 			    "].size=%#" PRIs "\n", i, init.tasks[i].addr, i,
 			    init.tasks[i].size);
@@ -272,6 +271,6 @@
 	 * Create the first thread.
 	 */
-	thread_t *kinit_thread = thread_create(kinit, NULL, kernel, 0, "kinit",
-	    true);
+	thread_t *kinit_thread
+		= thread_create(kinit, NULL, kernel, 0, "kinit", true);
 	if (!kinit_thread)
 		panic("Can't create kinit thread\n");
Index: kernel/generic/src/mm/as.c
===================================================================
--- kernel/generic/src/mm/as.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/generic/src/mm/as.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -147,6 +147,10 @@
 	AS_KERNEL = as_create(FLAG_AS_KERNEL);
 	if (!AS_KERNEL)
-		panic("can't create kernel address space\n");
-	
+		panic("Cannot create kernel address space\n");
+	
+	/* Make sure the kernel address space
+	 * reference count never drops to zero.
+	 */
+	atomic_set(&AS_KERNEL->refcount, 1);
 }
 
@@ -177,5 +181,5 @@
 	page_table_create(flags);
 #endif
-
+	
 	return as;
 }
@@ -770,9 +774,10 @@
  * into private anonymous memory (unless it's already there).
  *
- * @param as		Address space.
- * @param flags		Flags of the area memory.
- * @param address	Address withing the area to be changed.
- *
- * @return		Zero on success or a value from @ref errno.h on failure.
+ * @param as      Address space.
+ * @param flags   Flags of the area memory.
+ * @param address Address within the area to be changed.
+ *
+ * @return Zero on success or a value from @ref errno.h on failure.
+ *
  */
 int as_area_change_flags(as_t *as, int flags, uintptr_t address)
@@ -786,5 +791,5 @@
 	index_t frame_idx;
 	count_t used_pages;
-
+	
 	/* Flags for the new memory mapping */
 	page_flags = area_flags_to_page_flags(flags);
@@ -800,5 +805,5 @@
 	}
 
-	if (area->sh_info || area->backend != &anon_backend) {
+	if ((area->sh_info) || (area->backend != &anon_backend)) {
 		/* Copying shared areas not supported yet */
 		/* Copying non-anonymous memory not supported yet */
@@ -871,4 +876,5 @@
 
 	tlb_invalidate_pages(as->asid, area->base, area->pages);
+	
 	/*
 	 * Invalidate potential software translation caches (e.g. TSB on
Index: kernel/generic/src/syscall/syscall.c
===================================================================
--- kernel/generic/src/syscall/syscall.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ kernel/generic/src/syscall/syscall.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -93,6 +93,10 @@
 static unative_t sys_debug_enable_console(void)
 {
+#ifdef CONFIG_KCONSOLE
 	arch_grab_console();
-	return 0;
+	return true;
+#else
+	return false;
+#endif
 }
 
Index: uspace/lib/libc/include/ipc/fb.h
===================================================================
--- uspace/lib/libc/include/ipc/fb.h	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ uspace/lib/libc/include/ipc/fb.h	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -52,5 +52,4 @@
 	FB_DRAW_TEXT_DATA,
 	FB_FLUSH,
-	FB_VIEWPORT_DB,
 	FB_DRAW_PPM,
 	FB_PREPARE_SHM,
@@ -60,5 +59,4 @@
 	FB_VP2PIXMAP,
 	FB_DROP_PIXMAP,
-	FB_TRANS_PUTCHAR,
 	FB_ANIM_CREATE,
 	FB_ANIM_DROP,
Index: uspace/srv/console/console.c
===================================================================
--- uspace/srv/console/console.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ uspace/srv/console/console.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -87,7 +87,4 @@
 						 * switching */
 
-static int kernel_pixmap = -1;	/**< Number of fb pixmap, where kernel
-				 * console is stored */
-
 
 /** Find unused virtual console.
@@ -188,112 +185,78 @@
 }
 
-/** Save current screen to pixmap, draw old pixmap
- *
- * @param oldpixmap Old pixmap
- * @return ID of pixmap of current screen
- */
-static int switch_screens(int oldpixmap)
-{
-	int newpmap;
-       
-	/* Save screen */
-	newpmap = async_req_0_0(fb_info.phone, FB_VP2PIXMAP);
-	if (newpmap < 0)
-		return -1;
-
-	if (oldpixmap != -1) {
-		/* Show old screen */
-		async_msg_2(fb_info.phone, FB_VP_DRAW_PIXMAP, 0, oldpixmap);
-		/* Drop old pixmap */
-		async_msg_1(fb_info.phone, FB_DROP_PIXMAP, oldpixmap);
-	}
-	
-	return newpmap;
-}
-
 /** Switch to new console */
 static void change_console(int newcons)
 {
 	connection_t *conn;
-	static int console_pixmap = -1;
 	int i, j, rc;
 	keyfield_t *field;
 	style_t *style;
-
+	
 	if (newcons == active_console)
 		return;
-
+	
 	if (newcons == KERNEL_CONSOLE) {
+		async_serialize_start();
+		curs_visibility(0);
+		gcons_in_kernel();
+		async_serialize_end();
+		
+		if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE))
+			active_console = KERNEL_CONSOLE;
+		else
+			newcons == active_console;
+	}
+	
+	if (newcons != KERNEL_CONSOLE) {
+		async_serialize_start();
+		
 		if (active_console == KERNEL_CONSOLE)
-			return;
-		active_console = KERNEL_CONSOLE;
+			gcons_redraw_console();
+		
+		active_console = newcons;
+		gcons_change_console(newcons);
+		conn = &connections[active_console];
+		
+		set_style(&conn->screenbuffer.style);
 		curs_visibility(0);
-
-		async_serialize_start();
-		if (kernel_pixmap == -1) { 
-			/* store/restore unsupported */
-			set_style_col(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
+		if (interbuffer) {
+			for (i = 0; i < conn->screenbuffer.size_x; i++)
+				for (j = 0; j < conn->screenbuffer.size_y; j++) {
+					unsigned int size_x;
+					
+					size_x = conn->screenbuffer.size_x; 
+					interbuffer[i + j * size_x] =
+					    *get_field_at(&conn->screenbuffer, i, j);
+				}
+			/* This call can preempt, but we are already at the end */
+			rc = async_req_0_0(fb_info.phone, FB_DRAW_TEXT_DATA);		
+		}
+		
+		if ((!interbuffer) || (rc != 0)) {
+			set_style(&conn->screenbuffer.style);
 			clrscr();
-		} else {
-			gcons_in_kernel();
-			console_pixmap = switch_screens(kernel_pixmap);
-			kernel_pixmap = -1;
+			style = &conn->screenbuffer.style;
+			
+			for (j = 0; j < conn->screenbuffer.size_y; j++) 
+				for (i = 0; i < conn->screenbuffer.size_x; i++) {
+					field = get_field_at(&conn->screenbuffer, i, j);
+					if (!style_same(*style, field->style))
+						set_style(&field->style);
+					style = &field->style;
+					if ((field->character == ' ') &&
+					    (style_same(field->style,
+					    conn->screenbuffer.style)))
+						continue;
+					
+					prtchr(field->character, j, i);
+				}
 		}
+		
+		curs_goto(conn->screenbuffer.position_y,
+		    conn->screenbuffer.position_x);
+		curs_visibility(conn->screenbuffer.is_cursor_visible);
+		
 		async_serialize_end();
-
-		__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE);
-		return;
-	} 
-	
-	async_serialize_start();
-
-	if (console_pixmap != -1) {
-		kernel_pixmap = switch_screens(console_pixmap);
-		console_pixmap = -1;
-	}
-	active_console = newcons;
-	gcons_change_console(newcons);
-	conn = &connections[active_console];
-
-	set_style(&conn->screenbuffer.style);
-	curs_visibility(0);
-	if (interbuffer) {
-		for (i = 0; i < conn->screenbuffer.size_x; i++)
-			for (j = 0; j < conn->screenbuffer.size_y; j++) {
-				unsigned int size_x;
-
-				size_x = conn->screenbuffer.size_x; 
-				interbuffer[i + j * size_x] =
-				    *get_field_at(&conn->screenbuffer, i, j);
-			}
-		/* This call can preempt, but we are already at the end */
-		rc = async_req_0_0(fb_info.phone, FB_DRAW_TEXT_DATA);		
-	}
-	
-	if ((!interbuffer) || (rc != 0)) {
-		set_style(&conn->screenbuffer.style);
-		clrscr();
-		style = &conn->screenbuffer.style;
-
-		for (j = 0; j < conn->screenbuffer.size_y; j++) 
-			for (i = 0; i < conn->screenbuffer.size_x; i++) {
-				field = get_field_at(&conn->screenbuffer, i, j);
-				if (!style_same(*style, field->style))
-					set_style(&field->style);
-				style = &field->style;
-				if ((field->character == ' ') &&
-				    (style_same(field->style,
-				    conn->screenbuffer.style)))
-					continue;
-
-				prtchr(field->character, j, i);
-			}
-	}
-	
-	curs_goto(conn->screenbuffer.position_y,
-	    conn->screenbuffer.position_x);
-	curs_visibility(conn->screenbuffer.is_cursor_visible);
-
-	async_serialize_end();
+	}
 }
 
@@ -498,5 +461,4 @@
 	
 	/* Connect to framebuffer driver */
-	
 	fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0, 0);
 	while (fb_info.phone < 0) {
@@ -505,13 +467,8 @@
 	}
 	
-	/* Save old kernel screen */
-	kernel_pixmap = switch_screens(-1);
-
 	/* Initialize gcons */
 	gcons_init(fb_info.phone);
 	/* Synchronize, the gcons can have something in queue */
 	async_req_0_0(fb_info.phone, FB_FLUSH);
-	/* Enable double buffering */
-	async_msg_2(fb_info.phone, FB_VIEWPORT_DB, (sysarg_t) -1, 1);
 	
 	async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.rows,
Index: uspace/srv/console/gcons.c
===================================================================
--- uspace/srv/console/gcons.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ uspace/srv/console/gcons.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -82,5 +82,5 @@
 static void vp_switch(int vp)
 {
-	async_msg_1(fbphone,FB_VIEWPORT_SWITCH, vp);
+	async_msg_1(fbphone, FB_VIEWPORT_SWITCH, vp);
 }
 
@@ -106,5 +106,5 @@
 static void tran_putch(char c, int row, int col)
 {
-	async_msg_3(fbphone, FB_TRANS_PUTCHAR, c, row, col);
+	async_msg_3(fbphone, FB_PUTCHAR, c, row, col);
 }
 
@@ -190,8 +190,8 @@
 	else
 		console_state[consnum] = CONS_DISCONNECTED;
-
+	
 	if (active_console == KERNEL_CONSOLE)
 		return;
-
+	
 	redraw_state(consnum);
 	vp_switch(console_vp);
@@ -218,14 +218,8 @@
 void gcons_in_kernel(void)
 {
-	if (console_state[active_console] == CONS_DISCONNECTED_SEL)
-		console_state[active_console] = CONS_DISCONNECTED;
-	else
-		console_state[active_console] = CONS_IDLE;
-	redraw_state(active_console);
-
 	if (animation != -1)
 		async_msg_1(fbphone, FB_ANIM_STOP, animation);
-
-	active_console = KERNEL_CONSOLE; /* Set to kernel console */
+	
+	active_console = KERNEL_CONSOLE;
 	vp_switch(0);
 }
@@ -343,9 +337,10 @@
 extern char _binary_nameic_ppm_start[0];
 extern int _binary_nameic_ppm_size;
-/** Redraws console graphics  */
-static void gcons_redraw_console(void)
+
+/** Redraws console graphics */
+void gcons_redraw_console(void)
 {
 	int i;
-
+	
 	if (!use_gcons)
 		return;
@@ -358,5 +353,5 @@
 	draw_pixmap(_binary_nameic_ppm_start,
 	    (size_t) &_binary_nameic_ppm_size, 5, 17);
-
+	
 	for (i = 0; i < CONSOLE_COUNT; i++)
 		redraw_state(i);
@@ -460,14 +455,14 @@
 	int i;
 	int status_start = STATUS_START;
-
+	
 	fbphone = phone;
-
+	
 	rc = async_req_0_2(phone, FB_GET_RESOLUTION, &xres, &yres);
 	if (rc)
 		return;
 	
-	if (xres < 800 || yres < 600)
-		return;
-
+	if ((xres < 800) || (yres < 600))
+		return;
+	
 	/* create console viewport */
 	/* Align width & height to character size */
@@ -507,5 +502,5 @@
 	
 	make_anim();
-
+	
 	use_gcons = 1;
 	console_state[0] = CONS_DISCONNECTED_SEL;
@@ -513,6 +508,5 @@
 	gcons_redraw_console();
 }
- 
+
 /** @}
  */
-
Index: uspace/srv/console/gcons.h
===================================================================
--- uspace/srv/console/gcons.h	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ uspace/srv/console/gcons.h	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -37,4 +37,5 @@
 
 void gcons_init(int phone);
+void gcons_redraw_console(void);
 void gcons_change_console(int consnum);
 void gcons_notify_char(int consnum);
Index: uspace/srv/console/screenbuffer.h
===================================================================
--- uspace/srv/console/screenbuffer.h	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ uspace/srv/console/screenbuffer.h	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -36,4 +36,5 @@
 #define __SCREENBUFFER_H__
 
+#include <stdint.h>
 
 #define DEFAULT_FOREGROUND 0x0	/**< default console foreground color */
@@ -41,6 +42,6 @@
 
 typedef struct {
-	unsigned int bg_color;		/**< background color */
-	unsigned int fg_color;		/**< foreground color */
+	uint32_t bg_color;      /**< background color */
+	uint32_t fg_color;      /**< foreground color */
 } style_t;
 
Index: uspace/srv/fb/fb.c
===================================================================
--- uspace/srv/fb/fb.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ uspace/srv/fb/fb.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -1,3 +1,4 @@
 /*
+ * Copyright (c) 2008 Martin Decky
  * Copyright (c) 2006 Jakub Vana
  * Copyright (c) 2006 Ondrej Palkovsky
@@ -33,5 +34,5 @@
  * @ingroup fbs
  * @{
- */ 
+ */
 
 /** @file
@@ -63,62 +64,69 @@
 #include "pointer_mask.xbm"
 
-#define DEFAULT_BGCOLOR                0xf0f0f0
-#define DEFAULT_FGCOLOR                0x0
-
-/***************************************************************/
-/* Pixel specific fuctions */
-
-typedef void (*conv2scr_fn_t)(void *, int);
-typedef int (*conv2rgb_fn_t)(void *);
+#define DEFAULT_BGCOLOR  0xf0f0f0
+#define DEFAULT_FGCOLOR  0x000000
+
+#define MAX_ANIM_LEN     8
+#define MAX_ANIMATIONS   4
+#define MAX_PIXMAPS      256  /**< Maximum number of saved pixmaps */
+#define MAX_VIEWPORTS    128  /**< Viewport is a rectangular area on the screen */
+
+typedef void (*rgb_conv_t)(void *, uint32_t);
 
 struct {
-	uint8_t *fbaddress;
-
+	uint8_t *fb_addr;
+	
 	unsigned int xres;
 	unsigned int yres;
+	
 	unsigned int scanline;
+	unsigned int glyphscanline;
+	
 	unsigned int pixelbytes;
-	unsigned int invert_colors;
-
-	conv2scr_fn_t rgb2scr;
-	conv2rgb_fn_t scr2rgb;
+	unsigned int glyphbytes;
+	
+	rgb_conv_t rgb_conv;
 } screen;
 
 typedef struct {
-	int initialized;
-	unsigned int x, y;
-	unsigned int width, height;
-
+	bool initialized;
+	unsigned int x;
+	unsigned int y;
+	unsigned int width;
+	unsigned int height;
+	
 	/* Text support in window */
-	unsigned int rows, cols;
-	/* Style for text printing */
+	unsigned int cols;
+	unsigned int rows;
+	
+	/* Style and glyphs for text printing */
 	style_t style;
+	uint8_t *glyphs;
+	uint8_t *bgpixel;
+	
 	/* Auto-cursor position */
-	int cursor_active, cur_col, cur_row;
-	int cursor_shown;
-	/* Double buffering */
-	uint8_t *dbdata;
-	unsigned int dboffset;
-	unsigned int paused;
+	bool cursor_active;
+	unsigned int cur_col;
+	unsigned int cur_row;
+	bool cursor_shown;
+	
+	/* Back buffer */
+	unsigned int bbsize;
+	uint8_t *backbuf;
 } viewport_t;
 
-#define MAX_ANIM_LEN    8
-#define MAX_ANIMATIONS  4
 typedef struct {
-	int initialized;
-	int enabled;
+	bool initialized;
+	bool enabled;
 	unsigned int vp;
-
+	
 	unsigned int pos;
 	unsigned int animlen;
 	unsigned int pixmaps[MAX_ANIM_LEN];
 } animation_t;
+
 static animation_t animations[MAX_ANIMATIONS];
-static int anims_enabled;
-
-/** Maximum number of saved pixmaps 
- * Pixmap is a saved rectangle
- */
-#define MAX_PIXMAPS        256
+static bool anims_enabled;
+
 typedef struct {
 	unsigned int width;
@@ -126,363 +134,251 @@
 	uint8_t *data;
 } pixmap_t;
+
 static pixmap_t pixmaps[MAX_PIXMAPS];
-
-/* Viewport is a rectangular area on the screen */
-#define MAX_VIEWPORTS 128
 static viewport_t viewports[128];
 
-/* Allow only 1 connection */
-static int client_connected = 0;
-
-#define RED(x, bits)	((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
-#define GREEN(x, bits)	((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
-#define BLUE(x, bits)	((x >> (8 - bits)) & ((1 << bits) - 1))
-
-#define COL_WIDTH	8
-#define ROW_BYTES	(screen.scanline * FONT_SCANLINES)
-
-#define POINTPOS(x, y)	((y) * screen.scanline + (x) * screen.pixelbytes)
-
-static inline int COLOR(int color)
-{
-	return screen.invert_colors ? ~color : color;
-}
-
-/* Conversion routines between different color representations */
-static void
-rgb_byte0888(void *dst, int rgb)
-{
-	*(int *)dst = rgb;
-}
-
-static int
-byte0888_rgb(void *src)
-{
-	return (*(int *)src) & 0xffffff;
-}
-
-static void
-bgr_byte0888(void *dst, int rgb)
-{
-	*((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 |
-	    RED(rgb, 8);
-}
-
-static int
-byte0888_bgr(void *src)
-{
-	int color = *(uint32_t *)(src);
-	return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) |
-	    ((color >> 16) & 0xff);
-}
-
-static void
-rgb_byte888(void *dst, int rgb)
-{
-	uint8_t *scr = dst;
+static bool client_connected = false;  /**< Allow only 1 connection */
+
+#define RED(x, bits)                 ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1))
+#define GREEN(x, bits)               ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
+#define BLUE(x, bits)                ((x >> (8 - bits)) & ((1 << bits) - 1))
+
+#define COL2X(col)                   ((col) * FONT_WIDTH)
+#define ROW2Y(row)                   ((row) * FONT_SCANLINES)
+
+#define X2COL(x)                     ((x) / FONT_WIDTH)
+#define Y2ROW(y)                     ((y) / FONT_SCANLINES)
+
+#define FB_POS(x, y)                 ((y) * screen.scanline + (x) * screen.pixelbytes)
+#define BB_POS(vport, col, row)      ((row) * vport->cols + (col))
+#define GLYPH_POS(glyph, y, cursor)  (((glyph) + (cursor) * FONT_GLYPHS) * screen.glyphbytes + (y) * screen.glyphscanline)
+
+
+/** ARGB 8:8:8:8 conversion
+ *
+ */
+static void rgb_0888(void *dst, uint32_t rgb)
+{
+	*((uint32_t *) dst) = rgb & 0xffffff;
+}
+
+
+/** ABGR 8:8:8:8 conversion
+ *
+ */
+static void bgr_0888(void *dst, uint32_t rgb)
+{
+	*((uint32_t *) dst)
+	    = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8);
+}
+
+
+/** BGR 8:8:8 conversion
+ *
+ */
+static void rgb_888(void *dst, uint32_t rgb)
+{
 #if defined(FB_INVERT_ENDIAN)
-	scr[0] = RED(rgb, 8);
-	scr[1] = GREEN(rgb, 8);
-	scr[2] = BLUE(rgb, 8);
+	*((uint32_t *) dst)
+	    = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8)
+	    | (*((uint32_t *) dst) & 0xff0000);
 #else
-	scr[2] = RED(rgb, 8);
-	scr[1] = GREEN(rgb, 8);
-	scr[0] = BLUE(rgb, 8);
+	*((uint32_t *) dst)
+	    = (rgb & 0xffffff) | (*((uint32_t *) dst) & 0xff0000);
 #endif
 }
 
-static int
-byte888_rgb(void *src)
-{
-	uint8_t *scr = src;
-#if defined(FB_INVERT_ENDIAN)
-	return scr[0] << 16 | scr[1] << 8 | scr[2];
-#else
-	return scr[2] << 16 | scr[1] << 8 | scr[0];
-#endif	
-}
-
-/**  16-bit depth (5:5:5) */
-static void
-rgb_byte555(void *dst, int rgb)
-{
-	/* 5-bit, 5-bits, 5-bits */ 
-	*((uint16_t *)(dst)) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 |
-	    BLUE(rgb, 5);
-}
-
-/** 16-bit depth (5:5:5) */
-static int
-byte555_rgb(void *src)
-{
-	int color = *(uint16_t *)(src);
-	return (((color >> 10) & 0x1f) << (16 + 3)) |
-	    (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3);
-}
-
-/**  16-bit depth (5:6:5) */
-static void
-rgb_byte565(void *dst, int rgb)
-{
-	/* 5-bit, 6-bits, 5-bits */ 
-	*((uint16_t *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 |
-	    BLUE(rgb, 5);
-}
-
-/** 16-bit depth (5:6:5) */
-static int
-byte565_rgb(void *src)
-{
-	int color = *(uint16_t *)(src);
-	return (((color >> 11) & 0x1f) << (16 + 3)) |
-	    (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
-}
-
-/** Put pixel - 8-bit depth (3:2:3) */
-static void
-rgb_byte8(void *dst, int rgb)
-{
-	*(uint8_t *)dst = 255 - (RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 |
-		BLUE(rgb, 3));
-}
-
-/** Return pixel color - 8-bit depth (3:2:3) */
-static int
-byte8_rgb(void *src)
-{
-	int color = 255 - (*(uint8_t *)src);
-	return (((color >> 5) & 0x7) << (16 + 5)) |
-	    (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
-}
-
-/** Put pixel into viewport 
- *
- * @param vport Viewport identification
- * @param x X coord relative to viewport
- * @param y Y coord relative to viewport
- * @param color RGB color 
- */
-static void
-putpixel(viewport_t *vport, unsigned int x, unsigned int y, int color)
-{
-	int dx = vport->x + x;
-	int dy = vport->y + y;
-
-	if (! (vport->paused && vport->dbdata))
-		(*screen.rgb2scr)(&screen.fbaddress[POINTPOS(dx,dy)],
-		    COLOR(color));
-
-	if (vport->dbdata) {
-		int dline = (y + vport->dboffset) % vport->height;
-		int doffset = screen.pixelbytes * (dline * vport->width + x);
-		(*screen.rgb2scr)(&vport->dbdata[doffset], COLOR(color));
-	}
-}
-
-/** Get pixel from viewport */
-static int
-getpixel(viewport_t *vport, unsigned int x, unsigned int y)
-{
-	int dx = vport->x + x;
-	int dy = vport->y + y;
-
-	return COLOR((*screen.scr2rgb)(&screen.fbaddress[POINTPOS(dx, dy)]));
-}
-
-static inline void
-putpixel_mem(char *mem, unsigned int x, unsigned int y, int color)
-{
-	(*screen.rgb2scr)(&mem[POINTPOS(x, y)], COLOR(color));
-}
-
-static void
-draw_rectangle(viewport_t *vport, unsigned int sx, unsigned int sy,
-	unsigned int width, unsigned int height, int color)
-{
-	unsigned int x, y;
-	static void *tmpline;
-
-	if (!tmpline)
-		tmpline = malloc(screen.scanline * screen.pixelbytes);
-
-	/* Clear first line */
-	for (x = 0; x < width; x++)
-		putpixel_mem(tmpline, x, 0, color);
-
-	if (!vport->paused) {
-		/* Recompute to screen coords */
-		sx += vport->x;
-		sy += vport->y;
-		/* Copy the rest */
-		for (y = sy;y < sy+height; y++)
-			memcpy(&screen.fbaddress[POINTPOS(sx,y)], tmpline, 
-			    screen.pixelbytes * width);
-	}
-	if (vport->dbdata) {
-		for (y = sy; y < sy + height; y++) {
-			int rline = (y + vport->dboffset) % vport->height;
-			int rpos = (rline * vport->width + sx) *
-			    screen.pixelbytes;
-			memcpy(&vport->dbdata[rpos], tmpline,
-			    screen.pixelbytes * width);
-		}
-	}
-
-}
-
-/** Fill viewport with background color */
-static void
-clear_port(viewport_t *vport)
-{
-	draw_rectangle(vport, 0, 0, vport->width, vport->height,
-	    vport->style.bg_color);
-}
-
-/** Scroll unbuffered viewport up/down
+
+/** RGB 5:5:5 conversion
+ *
+ */
+static void rgb_555(void *dst, uint32_t rgb)
+{
+	*((uint16_t *) dst)
+	    = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
+}
+
+
+/** RGB 5:6:5 conversion
+ *
+ */
+static void rgb_565(void *dst, uint32_t rgb)
+{
+	*((uint16_t *) dst)
+	    = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5);
+}
+
+
+/** RGB 3:2:3
+ *
+ */
+static void rgb_323(void *dst, uint32_t rgb)
+{
+	*((uint8_t *) dst)
+	    = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
+}
+
+
+/** Redraw viewport
+ *
+ * @param vport Viewport to redraw
+ *
+ */
+static void vport_redraw(viewport_t *vport)
+{
+	unsigned int row;
+	
+	for (row = 0; row < vport->rows; row++) {
+		unsigned int y = vport->y + ROW2Y(row);
+		unsigned int yd;
+		
+		for (yd = 0; yd < FONT_SCANLINES; yd++) {
+			unsigned int x;
+			unsigned int col;
+			
+			for (col = 0, x = vport->x; col < vport->cols; col++, x += FONT_WIDTH)
+				memcpy(&screen.fb_addr[FB_POS(x, y + yd)],
+			    &vport->glyphs[GLYPH_POS(vport->backbuf[BB_POS(vport, col, row)], yd, false)],
+			    screen.glyphscanline);
+		}
+	}
+	
+	if (COL2X(vport->cols) < vport->width) {
+		unsigned int y;
+		
+		for (y = 0; y < vport->height; y++) {
+			unsigned int x;
+			
+			for (x = COL2X(vport->cols); x < vport->width; x++)
+				memcpy(&screen.fb_addr[FB_POS(x, y)], vport->bgpixel, screen.pixelbytes);
+		}
+	}
+	
+	if (ROW2Y(vport->rows) < vport->height) {
+		unsigned int y;
+		
+		for (y = ROW2Y(vport->rows); y < vport->height; y++) {
+			unsigned int x;
+			
+			for (x = 0; x < vport->width; x++)
+				memcpy(&screen.fb_addr[FB_POS(x, y)], vport->bgpixel, screen.pixelbytes);
+		}
+	}
+}
+
+
+/** Clear viewport
+ *
+ * @param vport Viewport to clear
+ *
+ */
+static void vport_clear(viewport_t *vport)
+{
+	memset(vport->backbuf, 0, vport->bbsize);
+	vport_redraw(vport);
+}
+
+
+/** Scroll viewport by given number of lines
  *
  * @param vport Viewport to scroll
- * @param lines Positive number - scroll up, negative - scroll down
- */
-static void
-scroll_port_nodb(viewport_t *vport, int lines)
-{
-	int y;
-
+ * @param lines Number of lines to scroll
+ *
+ */
+static void vport_scroll(viewport_t *vport, int lines)
+{
+	unsigned int row;
+	
+	for (row = 0; row < vport->rows; row++) {
+		unsigned int y = vport->y + ROW2Y(row);
+		unsigned int yd;
+		
+		for (yd = 0; yd < FONT_SCANLINES; yd++) {
+			unsigned int x;
+			unsigned int col;
+			
+			for (col = 0, x = vport->x; col < vport->cols; col++, x += FONT_WIDTH) {
+				uint8_t glyph;
+				
+				if ((row + lines >= 0) && (row + lines < vport->rows)) {
+					if (vport->backbuf[BB_POS(vport, col, row)] == vport->backbuf[BB_POS(vport, col, row + lines)])
+						continue;
+					
+					glyph = vport->backbuf[BB_POS(vport, col, row + lines)];
+				} else
+					glyph = 0;
+				
+				memcpy(&screen.fb_addr[FB_POS(x, y + yd)],
+				    &vport->glyphs[GLYPH_POS(glyph, yd, false)], screen.glyphscanline);
+			}
+		}
+	}
+	
 	if (lines > 0) {
-		for (y = vport->y; y < vport->y+vport->height - lines; y++)
-			memcpy(&screen.fbaddress[POINTPOS(vport->x,y)],
-			    &screen.fbaddress[POINTPOS(vport->x,y + lines)],
-			    screen.pixelbytes * vport->width);
-		draw_rectangle(vport, 0, vport->height - lines, vport->width,
-		    lines, vport->style.bg_color);
-	} else if (lines < 0) {
-		lines = -lines;
-		for (y = vport->y + vport->height-1; y >= vport->y + lines; y--)
-			memcpy(&screen.fbaddress[POINTPOS(vport->x,y)],
-			    &screen.fbaddress[POINTPOS(vport->x,y - lines)],
-			    screen.pixelbytes * vport->width);
-		draw_rectangle(vport, 0, 0, vport->width, lines,
-		    vport->style.bg_color);
-	}
-}
-
-/** Refresh given viewport from double buffer */
-static void
-refresh_viewport_db(viewport_t *vport)
-{
-	unsigned int y, srcy, srcoff, dsty, dstx;
-
-	for (y = 0; y < vport->height; y++) {
-		srcy = (y + vport->dboffset) % vport->height;
-		srcoff = (vport->width * srcy) * screen.pixelbytes;
-
-		dstx = vport->x;
-		dsty = vport->y + y;
-
-		memcpy(&screen.fbaddress[POINTPOS(dstx,dsty)],
-		    &vport->dbdata[srcoff], vport->width * screen.pixelbytes);
-	}
-}
-
-/** Scroll viewport that has double buffering enabled */
-static void
-scroll_port_db(viewport_t *vport, int lines)
-{
-	++vport->paused;
-	if (lines > 0) {
-		draw_rectangle(vport, 0, 0, vport->width, lines,
-		    vport->style.bg_color);
-		vport->dboffset += lines;
-		vport->dboffset %= vport->height;
-	} else if (lines < 0) {
-		lines = -lines;
-		draw_rectangle(vport, 0, vport->height-lines, vport->width,
-		    lines, vport->style.bg_color);
-
-		if (vport->dboffset < lines)
-			vport->dboffset += vport->height;
-		vport->dboffset -= lines;
-	}
-	
-	--vport->paused;
-	
-	refresh_viewport_db(vport);
-}
-
-/** Scrolls viewport given number of lines */
-static void
-scroll_port(viewport_t *vport, int lines)
-{
-	if (vport->dbdata)
-		scroll_port_db(vport, lines);
-	else
-		scroll_port_nodb(vport, lines);
-	
-}
-
-static void
-invert_pixel(viewport_t *vport, unsigned int x, unsigned int y)
-{
-	putpixel(vport, x, y, ~getpixel(vport, x, y));
-}
-
-
-/***************************************************************/
-/* Character-console functions */
-
-/** Draw character at given position
- *
- * @param vport Viewport where the character is printed
- * @param sx Coordinates of top-left of the character
- * @param sy Coordinates of top-left of the character
- * @param style Color of the character
- * @param transparent If false, print background color
- */
-static void
-draw_glyph(viewport_t *vport,uint8_t glyph, unsigned int sx, unsigned int sy,
-    style_t style, int transparent)
-{
-	int i;
-	unsigned int y;
-	unsigned int glline;
-
-	for (y = 0; y < FONT_SCANLINES; y++) {
-		glline = fb_font[glyph * FONT_SCANLINES + y];
-		for (i = 0; i < 8; i++) {
-			if (glline & (1 << (7 - i)))
-				putpixel(vport, sx + i, sy + y, style.fg_color);
-			else if (!transparent)
-				putpixel(vport, sx + i, sy + y, style.bg_color);
-		}
-	}
-}
-
-/** Invert character at given position */
-static void
-invert_char(viewport_t *vport,unsigned int row, unsigned int col)
-{
-	unsigned int x;
-	unsigned int y;
-
-	for (x = 0; x < COL_WIDTH; x++)
-		for (y = 0; y < FONT_SCANLINES; y++)
-			invert_pixel(vport, col * COL_WIDTH + x, row *
-			    FONT_SCANLINES + y);
-}
-
-/***************************************************************/
-/* Stdout specific functions */
+		memcpy(vport->backbuf, vport->backbuf + vport->cols * lines, vport->cols * (vport->rows - lines));
+		memset(&vport->backbuf[BB_POS(vport, 0, vport->rows - lines)], 0, vport->cols * lines);
+	} else {
+		memcpy(vport->backbuf - vport->cols * lines, vport->backbuf, vport->cols * (vport->rows + lines));
+		memset(vport->backbuf, 0, - vport->cols * lines);
+	}
+}
+
+
+/** Render glyphs
+ *
+ * Convert glyphs from device independent font
+ * description to current visual representation.
+ *
+ * @param vport Viewport
+ *
+ */
+static void render_glyphs(viewport_t* vport)
+{
+	unsigned int glyph;
+	
+	for (glyph = 0; glyph < FONT_GLYPHS; glyph++) {
+		unsigned int y;
+		
+		for (y = 0; y < FONT_SCANLINES; y++) {
+			unsigned int x;
+			
+			for (x = 0; x < FONT_WIDTH; x++) {
+				screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, false) + x * screen.pixelbytes],
+				    (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x)))
+				    ? vport->style.fg_color : vport->style.bg_color);
+				
+				uint32_t curcolor;
+				
+				if (y < FONT_SCANLINES - 2)
+					curcolor =
+					    (fb_font[glyph * FONT_SCANLINES + y] & (1 << (7 - x)))
+					    ? vport->style.fg_color : vport->style.bg_color;
+				else
+					curcolor = vport->style.fg_color;
+				
+				screen.rgb_conv(&vport->glyphs[GLYPH_POS(glyph, y, true) + x * screen.pixelbytes], curcolor);
+			}
+		}
+	}
+	
+	screen.rgb_conv(vport->bgpixel, vport->style.bg_color);
+}
 
 
 /** Create new viewport
  *
- * @return New viewport number
- */
-static int
-viewport_create(unsigned int x, unsigned int y,unsigned int width, 
-	unsigned int height)
-{
-	int i;
-
+ * @param x      Origin of the viewport (x).
+ * @param y      Origin of the viewport (y).
+ * @param width  Width of the viewport.
+ * @param height Height of the viewport.
+ *
+ * @return New viewport number.
+ *
+ */
+static int vport_create(unsigned int x, unsigned int y,
+    unsigned int width, unsigned int height)
+{
+	unsigned int i;
+	
 	for (i = 0; i < MAX_VIEWPORTS; i++) {
 		if (!viewports[i].initialized)
@@ -491,5 +387,31 @@
 	if (i == MAX_VIEWPORTS)
 		return ELIMIT;
-
+	
+	unsigned int cols = width / FONT_WIDTH;
+	unsigned int rows = height / FONT_SCANLINES;
+	unsigned int bbsize = cols * rows;
+	unsigned int glyphsize = 2 * FONT_GLYPHS * screen.glyphbytes;
+	
+	uint8_t *backbuf = (uint8_t *) malloc(bbsize);
+	if (!backbuf)
+		return ENOMEM;
+	
+	uint8_t *glyphs = (uint8_t *) malloc(glyphsize);
+	if (!glyphs) {
+		free(backbuf);
+		return ENOMEM;
+	}
+	
+	uint8_t *bgpixel = (uint8_t *) malloc(screen.pixelbytes);
+	if (!bgpixel) {
+		free(glyphs);
+		free(backbuf);
+		return ENOMEM;
+	}
+	
+	memset(backbuf, 0, bbsize);
+	memset(glyphs, 0, glyphsize);
+	memset(bgpixel, 0, screen.pixelbytes);
+	
 	viewports[i].x = x;
 	viewports[i].y = y;
@@ -497,68 +419,68 @@
 	viewports[i].height = height;
 	
-	viewports[i].rows = height / FONT_SCANLINES;
-	viewports[i].cols = width / COL_WIDTH;
-
+	viewports[i].cols = cols;
+	viewports[i].rows = rows;
+	
 	viewports[i].style.bg_color = DEFAULT_BGCOLOR;
 	viewports[i].style.fg_color = DEFAULT_FGCOLOR;
 	
+	viewports[i].glyphs = glyphs;
+	viewports[i].bgpixel = bgpixel;
+	
 	viewports[i].cur_col = 0;
 	viewports[i].cur_row = 0;
-	viewports[i].cursor_active = 0;
-
-	viewports[i].initialized = 1;
-
+	viewports[i].cursor_active = false;
+	viewports[i].cursor_shown = false;
+	
+	viewports[i].bbsize = bbsize;
+	viewports[i].backbuf = backbuf;
+	
+	viewports[i].initialized = true;
+	
+	render_glyphs(&viewports[i]);
+	
 	return i;
 }
 
+
 /** Initialize framebuffer as a chardev output device
  *
- * @param addr          Address of theframebuffer
- * @param xres          Screen width in pixels
- * @param yres          Screen height in pixels
- * @param visual        Bits per pixel (8, 16, 24, 32)
- * @param scan          Bytes per one scanline
- * @param invert_colors Inverted colors.
- *
- */
-static bool
-screen_init(void *addr, unsigned int offset, unsigned int xres,
-	unsigned int yres, unsigned int scan, unsigned int visual,
-	bool invert_colors)
+ * @param addr   Address of the framebuffer
+ * @param xres   Screen width in pixels
+ * @param yres   Screen height in pixels
+ * @param visual Bits per pixel (8, 16, 24, 32)
+ * @param scan   Bytes per one scanline
+ *
+ */
+static bool screen_init(void *addr, unsigned int xres, unsigned int yres,
+    unsigned int scan, unsigned int visual)
 {
 	switch (visual) {
 	case VISUAL_INDIRECT_8:
-		screen.rgb2scr = rgb_byte8;
-		screen.scr2rgb = byte8_rgb;
+		screen.rgb_conv = rgb_323;
 		screen.pixelbytes = 1;
 		break;
 	case VISUAL_RGB_5_5_5:
-		screen.rgb2scr = rgb_byte555;
-		screen.scr2rgb = byte555_rgb;
+		screen.rgb_conv = rgb_555;
 		screen.pixelbytes = 2;
 		break;
 	case VISUAL_RGB_5_6_5:
-		screen.rgb2scr = rgb_byte565;
-		screen.scr2rgb = byte565_rgb;
+		screen.rgb_conv = rgb_565;
 		screen.pixelbytes = 2;
 		break;
 	case VISUAL_RGB_8_8_8:
-		screen.rgb2scr = rgb_byte888;
-		screen.scr2rgb = byte888_rgb;
+		screen.rgb_conv = rgb_888;
 		screen.pixelbytes = 3;
 		break;
 	case VISUAL_RGB_8_8_8_0:
-		screen.rgb2scr = rgb_byte888;
-		screen.scr2rgb = byte888_rgb;
+		screen.rgb_conv = rgb_888;
 		screen.pixelbytes = 4;
 		break;
 	case VISUAL_RGB_0_8_8_8:
-		screen.rgb2scr = rgb_byte0888;
-		screen.scr2rgb = byte0888_rgb;
+		screen.rgb_conv = rgb_0888;
 		screen.pixelbytes = 4;
 		break;
 	case VISUAL_BGR_0_8_8_8:
-		screen.rgb2scr = bgr_byte0888;
-		screen.scr2rgb = byte0888_bgr;
+		screen.rgb_conv = bgr_0888;
 		screen.pixelbytes = 4;
 		break;
@@ -567,70 +489,103 @@
 	}
 
-	screen.fbaddress = (unsigned char *) (((uintptr_t) addr));
+	screen.fb_addr = (unsigned char *) addr;
 	screen.xres = xres;
 	screen.yres = yres;
 	screen.scanline = scan;
-	screen.invert_colors = invert_colors;
+	
+	screen.glyphscanline = FONT_WIDTH * screen.pixelbytes;
+	screen.glyphbytes = screen.glyphscanline * FONT_SCANLINES;
 	
 	/* Create first viewport */
-	viewport_create(0, 0, xres, yres);
+	vport_create(0, 0, xres, yres);
 	
 	return true;
 }
 
-/** Hide cursor if it is shown */
-static void
-cursor_hide(viewport_t *vport)
-{
-	if (vport->cursor_active && vport->cursor_shown) {
-		invert_char(vport, vport->cur_row, vport->cur_col);
-		vport->cursor_shown = 0;
-	}
-}
-
-/** Show cursor if cursor showing is enabled */
-static void
-cursor_print(viewport_t *vport)
+
+/** Draw glyph at given position relative to viewport 
+ *
+ * @param vport  Viewport identification
+ * @param cursor Draw glyph with cursor
+ * @param col    Screen position relative to viewport
+ * @param row    Screen position relative to viewport
+ *
+ */
+static void draw_glyph(viewport_t *vport, bool cursor, unsigned int col, unsigned int row)
+{
+	unsigned int x = vport->x + COL2X(col);
+	unsigned int y = vport->y + ROW2Y(row);
+	unsigned int yd;
+	
+	uint8_t glyph = vport->backbuf[BB_POS(vport, col, row)];
+	
+	for (yd = 0; yd < FONT_SCANLINES; yd++)
+		memcpy(&screen.fb_addr[FB_POS(x, y + yd)],
+		    &vport->glyphs[GLYPH_POS(glyph, yd, cursor)], screen.glyphscanline);
+}
+
+
+/** Hide cursor if it is shown
+ *
+ */
+static void cursor_hide(viewport_t *vport)
+{
+	if ((vport->cursor_active) && (vport->cursor_shown)) {
+		draw_glyph(vport, false, vport->cur_col, vport->cur_row);
+		vport->cursor_shown = false;
+	}
+}
+
+
+/** Show cursor if cursor showing is enabled
+ *
+ */
+static void cursor_show(viewport_t *vport)
 {
 	/* Do not check for cursor_shown */
 	if (vport->cursor_active) {
-		invert_char(vport, vport->cur_row, vport->cur_col);
-		vport->cursor_shown = 1;
-	}
-}
-
-/** Invert cursor, if it is enabled */
-static void
-cursor_blink(viewport_t *vport)
+		draw_glyph(vport, true, vport->cur_col, vport->cur_row);
+		vport->cursor_shown = true;
+	}
+}
+
+
+/** Invert cursor, if it is enabled
+ *
+ */
+static void cursor_blink(viewport_t *vport)
 {
 	if (vport->cursor_shown)
 		cursor_hide(vport);
 	else
-		cursor_print(vport);
-}
-
-/** Draw character at given position relative to viewport 
- * 
- * @param vport Viewport identification
- * @param c Character to print
- * @param row Screen position relative to viewport
- * @param col Screen position relative to viewport
- * @param transparent If false, print background color with character
- */
-static void
-draw_char(viewport_t *vport, char c, unsigned int row, unsigned int col,
-	style_t style, int transparent)
-{
-	/* Optimize - do not hide cursor if we are going to overwrite it */
-	if (vport->cursor_active && vport->cursor_shown && 
-	    (vport->cur_col != col || vport->cur_row != row))
-		invert_char(vport, vport->cur_row, vport->cur_col);
-	
-	draw_glyph(vport, c, col * COL_WIDTH, row * FONT_SCANLINES, style,
-	    transparent);
-
+		cursor_show(vport);
+}
+
+
+/** Draw character at given position relative to viewport
+ *
+ * @param vport  Viewport identification
+ * @param c      Character to draw
+ * @param col    Screen position relative to viewport
+ * @param row    Screen position relative to viewport
+ *
+ */
+static void draw_char(viewport_t *vport, uint8_t c, unsigned int col, unsigned int row)
+{
+	/* Do not hide cursor if we are going to overwrite it */
+	if ((vport->cursor_active) && (vport->cursor_shown) &&
+	    ((vport->cur_col != col) || (vport->cur_row != row)))
+		cursor_hide(vport);
+	
+	uint8_t glyph = vport->backbuf[BB_POS(vport, col, row)];
+	
+	if (glyph != c) {
+		vport->backbuf[BB_POS(vport, col, row)] = c;
+		draw_glyph(vport, false, col, row);
+	}
+	
 	vport->cur_col = col;
 	vport->cur_row = row;
-
+	
 	vport->cur_col++;
 	if (vport->cur_col >= vport->cols) {
@@ -640,63 +595,83 @@
 			vport->cur_row--;
 	}
-	cursor_print(vport);
-}
+	
+	cursor_show(vport);
+}
+
 
 /** Draw text data to viewport
  *
  * @param vport Viewport id
- * @param data Text data fitting exactly into viewport
- */
-static void
-draw_text_data(viewport_t *vport, keyfield_t *data)
-{
-	int i;
-	int col,row;
-
-	clear_port(vport);
+ * @param data  Text data fitting exactly into viewport
+ *
+ */
+static void draw_text_data(viewport_t *vport, keyfield_t *data)
+{
+	unsigned int i;
+	
 	for (i = 0; i < vport->cols * vport->rows; i++) {
-		if (data[i].character == ' ' && style_same(data[i].style,
-		    vport->style))
-			continue;
-		col = i % vport->cols;
-		row = i / vport->cols;
-		draw_glyph(vport, data[i].character, col * COL_WIDTH, row *
-		    FONT_SCANLINES, data[i].style, style_same(data[i].style,
-		    vport->style));
-	}
-	cursor_print(vport);
-}
-
-/** Return first free pixmap */
-static int
-find_free_pixmap(void)
-{
-	int i;
-	
-	for (i = 0;i < MAX_PIXMAPS;i++)
+		unsigned int col = i % vport->cols;
+		unsigned int row = i / vport->cols;
+		
+		uint8_t glyph = vport->backbuf[BB_POS(vport, col, row)];
+		
+		// TODO: use data[i].style
+		
+		if (glyph != data[i].character) {
+			vport->backbuf[BB_POS(vport, col, row)] = data[i].character;
+			draw_glyph(vport, false, col, row);
+		}
+	}
+	cursor_show(vport);
+}
+
+
+static void putpixel_pixmap(void *data, unsigned int x, unsigned int y, uint32_t color)
+{
+	int pm = *((int *) data);
+	pixmap_t *pmap = &pixmaps[pm];
+	unsigned int pos = (y * pmap->width + x) * screen.pixelbytes;
+	
+	screen.rgb_conv(&pmap->data[pos], color);
+}
+
+
+static void putpixel(void *data, unsigned int x, unsigned int y, uint32_t color)
+{
+	viewport_t *vport = (viewport_t *) data;
+	unsigned int dx = vport->x + x;
+	unsigned int dy = vport->y + y;
+	
+	screen.rgb_conv(&screen.fb_addr[FB_POS(dx, dy)], color);
+}
+
+
+/** Return first free pixmap
+ *
+ */
+static int find_free_pixmap(void)
+{
+	unsigned int i;
+	
+	for (i = 0; i < MAX_PIXMAPS; i++)
 		if (!pixmaps[i].data)
 			return i;
+	
 	return -1;
 }
 
-static void
-putpixel_pixmap(int pm, unsigned int x, unsigned int y, int color)
-{
-	pixmap_t *pmap = &pixmaps[pm];
-	int pos = (y * pmap->width + x) * screen.pixelbytes;
-
-	(*screen.rgb2scr)(&pmap->data[pos],COLOR(color));
-}
-
-/** Create a new pixmap and return appropriate ID */
-static int
-shm2pixmap(unsigned char *shm, size_t size)
+
+/** Create a new pixmap and return appropriate ID
+ *
+ */
+static int shm2pixmap(unsigned char *shm, size_t size)
 {
 	int pm;
 	pixmap_t *pmap;
-
+	
 	pm = find_free_pixmap();
 	if (pm == -1)
 		return ELIMIT;
+	
 	pmap = &pixmaps[pm];
 	
@@ -707,10 +682,10 @@
 	if (!pmap->data)
 		return ENOMEM;
-
-	ppm_draw(shm, size, 0, 0, pmap->width, pmap->height, 
-	    (putpixel_cb_t)putpixel_pixmap, (void *)pm);
-
+	
+	ppm_draw(shm, size, 0, 0, pmap->width, pmap->height, putpixel_pixmap, (void *) &pm);
+	
 	return pm;
 }
+
 
 /** Handle shared memory communication calls
@@ -719,5 +694,5 @@
  * - FB_PREPARE_SHM(client shm identification)
  * - IPC_M_AS_AREA_SEND
- * - FB_DRAW_PPM(startx,starty)
+ * - FB_DRAW_PPM(startx, starty)
  * - FB_DROP_SHM
  *
@@ -727,26 +702,28 @@
  *
  * @param callid Callid of the current call
- * @param call Current call data
- * @param vp Active viewport
- * @return 0 if the call was not handled byt this function, 1 otherwise
- *
- * note: this function is not threads safe, you would have
+ * @param call   Current call data
+ * @param vp     Active viewport
+ *
+ * @return false if the call was not handled byt this function, true otherwise
+ *
+ * Note: this function is not threads safe, you would have
  * to redefine static variables with __thread
- */
-static int
-shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
+ *
+ */
+static bool shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
 {
 	static keyfield_t *interbuffer = NULL;
 	static size_t intersize = 0;
-
+	
 	static unsigned char *shm = NULL;
 	static ipcarg_t shm_id = 0;
 	static size_t shm_size;
-
-	int handled = 1;
-	int retval = 0;
+	
+	bool handled = true;
+	int retval = EOK;
 	viewport_t *vport = &viewports[vp];
-	unsigned int x, y;
-
+	unsigned int x;
+	unsigned int y;
+	
 	switch (IPC_GET_METHOD(*call)) {
 	case IPC_M_SHARE_OUT:
@@ -755,17 +732,18 @@
 			void *dest = as_get_mappable_page(IPC_GET_ARG2(*call));
 			shm_size = IPC_GET_ARG2(*call);
-			if (!ipc_answer_1(callid, EOK, (sysarg_t) dest)) 
+			if (!ipc_answer_1(callid, EOK, (sysarg_t) dest))
 				shm = dest;
 			else
 				shm_id = 0;
+			
 			if (shm[0] != 'P')
-				while (1)
-					;
-			return 1;
+				return false;
+			
+			return true;
 		} else {
 			intersize = IPC_GET_ARG2(*call);
 			receive_comm_area(callid, call, (void *) &interbuffer);
 		}
-		return 1;
+		return true;
 	case FB_PREPARE_SHM:
 		if (shm_id)
@@ -782,5 +760,5 @@
 		shm_id = 0;
 		break;
-
+		
 	case FB_SHM2PIXMAP:
 		if (!shm) {
@@ -797,5 +775,6 @@
 		x = IPC_GET_ARG1(*call);
 		y = IPC_GET_ARG2(*call);
-		if (x > vport->width || y > vport->height) {
+		
+		if ((x > vport->width) || (y > vport->height)) {
 			retval = EINVAL;
 			break;
@@ -803,6 +782,5 @@
 		
 		ppm_draw(shm, shm_size, IPC_GET_ARG1(*call),
-		    IPC_GET_ARG2(*call), vport->width - x, vport->height - y,
-		    (putpixel_cb_t)putpixel, vport);
+		    IPC_GET_ARG2(*call), vport->width - x, vport->height - y, putpixel, (void *) vport);
 		break;
 	case FB_DRAW_TEXT_DATA:
@@ -811,6 +789,5 @@
 			break;
 		}
-		if (intersize < vport->cols * vport->rows *
-		    sizeof(*interbuffer)) {
+		if (intersize < vport->cols * vport->rows * sizeof(*interbuffer)) {
 			retval = EINVAL;
 			break;
@@ -819,5 +796,5 @@
 		break;
 	default:
-		handled = 0;
+		handled = false;
 	}
 	
@@ -827,13 +804,10 @@
 }
 
-static void
-copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap)
-{
-	int y;
-	int tmp, srcrowsize;
-	int realwidth, realheight, realrowsize;
-	int width = vport->width;
-	int height = vport->height;
-
+
+static void copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap)
+{
+	unsigned int width = vport->width;
+	unsigned int height = vport->height;
+	
 	if (width + vport->x > screen.xres)
 		width = screen.xres - vport->x;
@@ -841,25 +815,26 @@
 		height = screen.yres - vport->y;
 	
-	realwidth = pmap->width <= width ? pmap->width : width;
-	realheight = pmap->height <= height ? pmap->height : height;
-
-	srcrowsize = vport->width * screen.pixelbytes;
-	realrowsize = realwidth * screen.pixelbytes;
-	
+	unsigned int realwidth = pmap->width <= width ? pmap->width : width;
+	unsigned int realheight = pmap->height <= height ? pmap->height : height;
+	
+	unsigned int srcrowsize = vport->width * screen.pixelbytes;
+	unsigned int realrowsize = realwidth * screen.pixelbytes;
+	
+	unsigned int y;
 	for (y = 0; y < realheight; y++) {
-		tmp = (vport->y + y) * screen.scanline +
-		    vport->x * screen.pixelbytes;
-		memcpy(pmap->data + srcrowsize * y, screen.fbaddress + tmp,
-		    realrowsize); 
-	}
-}
-
-/** Save viewport to pixmap */
-static int
-save_vp_to_pixmap(viewport_t *vport)
+		unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes;
+		memcpy(pmap->data + srcrowsize * y, screen.fb_addr + tmp, realrowsize);
+	}
+}
+
+
+/** Save viewport to pixmap
+ *
+ */
+static int save_vp_to_pixmap(viewport_t *vport)
 {
 	int pm;
 	pixmap_t *pmap;
-
+	
 	pm = find_free_pixmap();
 	if (pm == -1)
@@ -870,12 +845,13 @@
 	if (!pmap->data)
 		return ENOMEM;
-
+	
 	pmap->width = vport->width;
 	pmap->height = vport->height;
-
+	
 	copy_vp_to_pixmap(vport, pmap);
 	
 	return pm;
 }
+
 
 /** Draw pixmap on screen
@@ -883,4 +859,5 @@
  * @param vp Viewport to draw on
  * @param pm Pixmap identifier
+ *
  */
 static int draw_pixmap(int vp, int pm)
@@ -888,38 +865,38 @@
 	pixmap_t *pmap = &pixmaps[pm];
 	viewport_t *vport = &viewports[vp];
-	int y;
-	int tmp, srcrowsize;
-	int realwidth, realheight, realrowsize;
-	int width = vport->width;
-	int height = vport->height;
-
+	
+	unsigned int width = vport->width;
+	unsigned int height = vport->height;
+	
 	if (width + vport->x > screen.xres)
 		width = screen.xres - vport->x;
 	if (height + vport->y > screen.yres)
 		height = screen.yres - vport->y;
-
+	
 	if (!pmap->data)
 		return EINVAL;
-
-	realwidth = pmap->width <= width ? pmap->width : width;
-	realheight = pmap->height <= height ? pmap->height : height;
-
-	srcrowsize = vport->width * screen.pixelbytes;
-	realrowsize = realwidth * screen.pixelbytes;
-
+	
+	unsigned int realwidth = pmap->width <= width ? pmap->width : width;
+	unsigned int realheight = pmap->height <= height ? pmap->height : height;
+	
+	unsigned int srcrowsize = vport->width * screen.pixelbytes;
+	unsigned int realrowsize = realwidth * screen.pixelbytes;
+	
+	unsigned int y;
 	for (y = 0; y < realheight; y++) {
-		tmp = (vport->y + y) * screen.scanline + 
-		    vport->x * screen.pixelbytes;
-		memcpy(screen.fbaddress + tmp, pmap->data + y * srcrowsize,
-		    realrowsize);
-	}
-	return 0;
-}
-
-/** Tick animation one step forward */
-static void
-anims_tick(void)
-{
-	int i;
+		unsigned int tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes;
+		memcpy(screen.fb_addr + tmp, pmap->data + y * srcrowsize, realrowsize);
+	}
+	
+	return EOK;
+}
+
+
+/** Tick animation one step forward
+ *
+ */
+static void anims_tick(void)
+{
+	unsigned int i;
 	static int counts = 0;
 	
@@ -930,22 +907,22 @@
 
 	for (i = 0; i < MAX_ANIMATIONS; i++) {
-		if (!animations[i].animlen || !animations[i].initialized ||
-		    !animations[i].enabled)
+		if ((!animations[i].animlen) || (!animations[i].initialized) ||
+		    (!animations[i].enabled))
 			continue;
-		draw_pixmap(animations[i].vp,
-		    animations[i].pixmaps[animations[i].pos]);
-		animations[i].pos = (animations[i].pos + 1) %
-		    animations[i].animlen;
-	}
-}
-
-
-static int pointer_x, pointer_y;
-static int pointer_shown, pointer_enabled;
+		
+		draw_pixmap(animations[i].vp, animations[i].pixmaps[animations[i].pos]);
+		animations[i].pos = (animations[i].pos + 1) % animations[i].animlen;
+	}
+}
+
+
+static unsigned int pointer_x;
+static unsigned int pointer_y;
+static bool pointer_shown, pointer_enabled;
 static int pointer_vport = -1;
 static int pointer_pixmap = -1;
 
-static void
-mouse_show(void)
+
+static void mouse_show(void)
 {
 	int i, j;
@@ -953,12 +930,11 @@
 	int color;
 	int bytepos;
-
-	if (pointer_shown || !pointer_enabled)
+	
+	if ((pointer_shown) || (!pointer_enabled))
 		return;
-
+	
 	/* Save image under the cursor */
 	if (pointer_vport == -1) {
-		pointer_vport = viewport_create(pointer_x, pointer_y,
-		    pointer_width, pointer_height);
+		pointer_vport = vport_create(pointer_x, pointer_y, pointer_width, pointer_height);
 		if (pointer_vport < 0)
 			return;
@@ -967,11 +943,10 @@
 		viewports[pointer_vport].y = pointer_y;
 	}
-
+	
 	if (pointer_pixmap == -1)
 		pointer_pixmap = save_vp_to_pixmap(&viewports[pointer_vport]);
 	else
-		copy_vp_to_pixmap(&viewports[pointer_vport],
-		    &pixmaps[pointer_pixmap]);
-
+		copy_vp_to_pixmap(&viewports[pointer_vport], &pixmaps[pointer_pixmap]);
+	
 	/* Draw cursor */
 	for (i = 0; i < pointer_height; i++)
@@ -992,6 +967,6 @@
 }
 
-static void
-mouse_hide(void)
+
+static void mouse_hide(void)
 {
 	/* Restore image under the cursor */
@@ -1002,6 +977,6 @@
 }
 
-static void
-mouse_move(unsigned int x, unsigned int y)
+
+static void mouse_move(unsigned int x, unsigned int y)
 {
 	mouse_hide();
@@ -1011,12 +986,12 @@
 }
 
-static int
-anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
-{
-	int handled = 1;
-	int retval = 0;
-	int i,nvp;
+
+static int anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
+{
+	bool handled = true;
+	int retval = EOK;
+	int i, nvp;
 	int newval;
-
+	
 	switch (IPC_GET_METHOD(*call)) {
 	case FB_ANIM_CREATE:
@@ -1108,12 +1083,14 @@
 }
 
-/** Handler for messages concerning pixmap handling */
-static int
-pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
-{
-	int handled = 1;
-	int retval = 0;
-	int i,nvp;
-
+
+/** Handler for messages concerning pixmap handling
+ *
+ */
+static int pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
+{
+	bool handled = true;
+	int retval = EOK;
+	int i, nvp;
+	
 	switch (IPC_GET_METHOD(*call)) {
 	case FB_VP_DRAW_PIXMAP:
@@ -1153,5 +1130,5 @@
 		handled = 0;
 	}
-
+	
 	if (handled)
 		ipc_answer_0(callid, retval);
@@ -1163,30 +1140,32 @@
  *
  */
-static void
-fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
-{
-	ipc_callid_t callid;
-	ipc_call_t call;
-	int retval;
-	int i;
-	unsigned int row,col;
-	char c;
-
-	int vp = 0;
-	viewport_t *vport = &viewports[0];
-
+static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
+{
+	unsigned int vp = 0;
+	viewport_t *vport = &viewports[vp];
+	
 	if (client_connected) {
 		ipc_answer_0(iid, ELIMIT);
 		return;
 	}
-	client_connected = 1;
-	ipc_answer_0(iid, EOK); /* Accept connection */
-
-	while (1) {
-		if (vport->cursor_active || anims_enabled)
+	
+	/* Accept connection */
+	client_connected = true;
+	ipc_answer_0(iid, EOK);
+	
+	while (true) {
+		ipc_callid_t callid;
+		ipc_call_t call;
+		int retval;
+		unsigned int i;
+		int scroll;
+		uint8_t glyph;
+		unsigned int row, col;
+		
+		if ((vport->cursor_active) || (anims_enabled))
 			callid = async_get_call_timeout(&call, 250000);
 		else
 			callid = async_get_call(&call);
-
+		
 		mouse_hide();
 		if (!callid) {
@@ -1196,56 +1175,65 @@
 			continue;
 		}
+		
 		if (shm_handle(callid, &call, vp))
 			continue;
+		
 		if (pixmap_handle(callid, &call, vp))
 			continue;
+		
 		if (anim_handle(callid, &call, vp))
 			continue;
-
- 		switch (IPC_GET_METHOD(call)) {
+		
+		switch (IPC_GET_METHOD(call)) {
 		case IPC_M_PHONE_HUNGUP:
-			client_connected = 0;
-			/* cleanup other viewports */
+			client_connected = false;
+			
+			/* Cleanup other viewports */
 			for (i = 1; i < MAX_VIEWPORTS; i++)
-				vport->initialized = 0;
-			return; /* Exit thread */
-
+				vport->initialized = false;
+			
+			/* Exit thread */
+			return;
+		
 		case FB_PUTCHAR:
-		case FB_TRANS_PUTCHAR:
-			c = IPC_GET_ARG1(call);
+			glyph = IPC_GET_ARG1(call);
 			row = IPC_GET_ARG2(call);
 			col = IPC_GET_ARG3(call);
-			if (row >= vport->rows || col >= vport->cols) {
+			
+			if ((col >= vport->cols) || (row >= vport->rows)) {
 				retval = EINVAL;
 				break;
 			}
 			ipc_answer_0(callid, EOK);
-
-			draw_char(vport, c, row, col, vport->style,
-			    IPC_GET_METHOD(call) == FB_TRANS_PUTCHAR);
-			continue; /* msg already answered */
+			
+			draw_char(vport, glyph, col, row);
+			
+			/* Message already answered */
+			continue;
 		case FB_CLEAR:
-			clear_port(vport);
-			cursor_print(vport);
-			retval = 0;
-			break;
- 		case FB_CURSOR_GOTO:
+			vport_clear(vport);
+			cursor_show(vport);
+			retval = EOK;
+			break;
+		case FB_CURSOR_GOTO:
 			row = IPC_GET_ARG1(call);
 			col = IPC_GET_ARG2(call);
-			if (row >= vport->rows || col >= vport->cols) {
+			
+			if ((col >= vport->cols) || (row >= vport->rows)) {
 				retval = EINVAL;
 				break;
 			}
- 			retval = 0;
+			retval = EOK;
+			
 			cursor_hide(vport);
 			vport->cur_col = col;
 			vport->cur_row = row;
-			cursor_print(vport);
- 			break;
+			cursor_show(vport);
+			break;
 		case FB_CURSOR_VISIBILITY:
 			cursor_hide(vport);
 			vport->cursor_active = IPC_GET_ARG1(call);
-			cursor_print(vport);
-			retval = 0;
+			cursor_show(vport);
+			retval = EOK;
 			break;
 		case FB_GET_CSIZE:
@@ -1253,46 +1241,21 @@
 			continue;
 		case FB_SCROLL:
-			i = IPC_GET_ARG1(call);
-			if (i > vport->rows || i < (- (int)vport->rows)) {
+			scroll = IPC_GET_ARG1(call);
+			if ((scroll > (int) vport->rows) || (scroll < (-(int) vport->rows))) {
 				retval = EINVAL;
 				break;
 			}
 			cursor_hide(vport);
-			scroll_port(vport, i*FONT_SCANLINES);
-			cursor_print(vport);
-			retval = 0;
-			break;
-		case FB_VIEWPORT_DB:
-			/* Enable double buffering */
+			vport_scroll(vport, scroll);
+			cursor_show(vport);
+			retval = EOK;
+			break;
+		case FB_VIEWPORT_SWITCH:
 			i = IPC_GET_ARG1(call);
-			if (i == -1)
-				i = vp;
-			if (i < 0 || i >= MAX_VIEWPORTS) {
+			if (i >= MAX_VIEWPORTS) {
 				retval = EINVAL;
 				break;
 			}
-			if (!viewports[i].initialized ) {
-				retval = EADDRNOTAVAIL;
-				break;
-			}
-			viewports[i].dboffset = 0;
-			if (IPC_GET_ARG2(call) == 1 && !viewports[i].dbdata)
-				viewports[i].dbdata =
-				    malloc(screen.pixelbytes *
-				    viewports[i].width * viewports[i].height);
-			else if (IPC_GET_ARG2(call) == 0 &&
-			    viewports[i].dbdata) {
-				free(viewports[i].dbdata);
-				viewports[i].dbdata = NULL;
-			}
-			retval = 0;
-			break;
-		case FB_VIEWPORT_SWITCH:
-			i = IPC_GET_ARG1(call);
-			if (i < 0 || i >= MAX_VIEWPORTS) {
-				retval = EINVAL;
-				break;
-			}
-			if (! viewports[i].initialized ) {
+			if (!viewports[i].initialized) {
 				retval = EADDRNOTAVAIL;
 				break;
@@ -1301,9 +1264,9 @@
 			vp = i;
 			vport = &viewports[vp];
-			cursor_print(vport);
-			retval = 0;
+			cursor_show(vport);
+			retval = EOK;
 			break;
 		case FB_VIEWPORT_CREATE:
-			retval = viewport_create(IPC_GET_ARG1(call) >> 16,
+			retval = vport_create(IPC_GET_ARG1(call) >> 16,
 			    IPC_GET_ARG1(call) & 0xffff,
 			    IPC_GET_ARG2(call) >> 16,
@@ -1312,23 +1275,26 @@
 		case FB_VIEWPORT_DELETE:
 			i = IPC_GET_ARG1(call);
-			if (i < 0 || i >= MAX_VIEWPORTS) {
+			if (i >= MAX_VIEWPORTS) {
 				retval = EINVAL;
 				break;
 			}
-			if (! viewports[i].initialized ) {
+			if (!viewports[i].initialized) {
 				retval = EADDRNOTAVAIL;
 				break;
 			}
-			viewports[i].initialized = 0;
-			if (viewports[i].dbdata) {
-				free(viewports[i].dbdata);
-				viewports[i].dbdata = NULL;
-			}
-			retval = 0;
+			viewports[i].initialized = false;
+			if (viewports[i].glyphs)
+				free(viewports[i].glyphs);
+			if (viewports[i].bgpixel)
+				free(viewports[i].bgpixel);
+			if (viewports[i].backbuf)
+				free(viewports[i].backbuf);
+			retval = EOK;
 			break;
 		case FB_SET_STYLE:
 			vport->style.fg_color = IPC_GET_ARG1(call);
 			vport->style.bg_color = IPC_GET_ARG2(call);
-			retval = 0;
+			render_glyphs(vport);
+			retval = EOK;
 			break;
 		case FB_GET_RESOLUTION:
@@ -1336,7 +1302,7 @@
 			continue;
 		case FB_POINTER_MOVE:
-			pointer_enabled = 1;
+			pointer_enabled = true;
 			mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
-			retval = 0;
+			retval = EOK;
 			break;
 		default:
@@ -1347,36 +1313,25 @@
 }
 
-/** Initialization of framebuffer */
-int
-fb_init(void)
-{
-	void *fb_ph_addr;
-	unsigned int fb_width;
-	unsigned int fb_height;
-	unsigned int fb_scanline;
-	unsigned int fb_visual;
-	unsigned int fb_offset;
-	bool fb_invert_colors;
-	void *fb_addr;
-	size_t asz;
-
+/** Initialization of framebuffer
+ *
+ */
+int fb_init(void)
+{
 	async_set_client_connection(fb_client_connection);
-
-	fb_ph_addr = (void *) sysinfo_value("fb.address.physical");
-	fb_offset = sysinfo_value("fb.offset");
-	fb_width = sysinfo_value("fb.width");
-	fb_height = sysinfo_value("fb.height");
-	fb_scanline = sysinfo_value("fb.scanline");
-	fb_visual = sysinfo_value("fb.visual");
-	fb_invert_colors = sysinfo_value("fb.invert-colors");
-
-	asz = fb_scanline * fb_height;
-	fb_addr = as_get_mappable_page(asz);
-	
-	physmem_map(fb_ph_addr + fb_offset, fb_addr, ALIGN_UP(asz, PAGE_SIZE) >>
-	    PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE);
-
-	if (screen_init(fb_addr, fb_offset, fb_width, fb_height, fb_scanline, fb_visual,
-	    fb_invert_colors))
+	
+	void *fb_ph_addr = (void *) sysinfo_value("fb.address.physical");
+	unsigned int fb_offset = sysinfo_value("fb.offset");
+	unsigned int fb_width = sysinfo_value("fb.width");
+	unsigned int fb_height = sysinfo_value("fb.height");
+	unsigned int fb_scanline = sysinfo_value("fb.scanline");
+	unsigned int fb_visual = sysinfo_value("fb.visual");
+	
+	unsigned int fbsize = fb_scanline * fb_height;
+	void *fb_addr = as_get_mappable_page(fbsize);
+	
+	physmem_map(fb_ph_addr + fb_offset, fb_addr,
+	    ALIGN_UP(fbsize, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE);
+	
+	if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual))
 		return 0;
 	
@@ -1384,5 +1339,5 @@
 }
 
-/** 
+/**
  * @}
  */
Index: uspace/srv/fb/fb.h
===================================================================
--- uspace/srv/fb/fb.h	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ uspace/srv/fb/fb.h	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -30,5 +30,5 @@
  * @ingroup fbs
  * @{
- */ 
+ */
 /** @file
  */
@@ -37,5 +37,7 @@
 #define FB_FB_H_
 
-typedef void (* putpixel_cb_t)(void *, unsigned int, unsigned int, int);
+#include <stdint.h>
+
+typedef void (* putpixel_cb_t)(void *, unsigned int, unsigned int, uint32_t);
 
 extern int fb_init(void);
Index: uspace/srv/fb/font-8x16.c
===================================================================
--- uspace/srv/fb/font-8x16.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ uspace/srv/fb/font-8x16.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -29,5 +29,5 @@
 #include "font-8x16.h"
 
-unsigned char fb_font[FONT_GLIPHS * FONT_SCANLINES] = {
+unsigned char fb_font[FONT_GLYPHS * FONT_SCANLINES] = {
 
 	/* 0 0x00 '^@' */
Index: uspace/srv/fb/font-8x16.h
===================================================================
--- uspace/srv/fb/font-8x16.h	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ uspace/srv/fb/font-8x16.h	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -30,8 +30,10 @@
 #define FB_FONT_8X16_H_
 
-#define FONT_GLIPHS	256
-#define FONT_SCANLINES	16
+#define FONT_GLYPHS      256
+#define FONT_WIDTH       8
+#define FONT_SCANLINES   16
 
-extern unsigned char fb_font[FONT_GLIPHS * FONT_SCANLINES];
+
+extern unsigned char fb_font[FONT_GLYPHS * FONT_SCANLINES];
 
 #endif
Index: uspace/srv/fb/main.c
===================================================================
--- uspace/srv/fb/main.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ uspace/srv/fb/main.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -47,5 +47,5 @@
 {
 	void *dest;
-
+	
 	dest = as_get_mappable_page(IPC_GET_ARG2(*call));
 	if (ipc_answer_1(callid, EOK, (sysarg_t) dest) == 0) {
@@ -62,10 +62,10 @@
 	ipcarg_t phonead;
 	bool initialized = false;
-
+	
 #ifdef FB_ENABLED
 	if (sysinfo_value("fb.kind") == 1) {
 		if (fb_init() == 0)
 			initialized = true;
-	} 
+	}
 #endif
 #ifdef EGA_ENABLED
@@ -90,5 +90,5 @@
 	if (!initialized)
 		return -1;
-
+	
 	if (ipc_connect_to_me(PHONE_NS, SERVICE_VIDEO, 0, 0, &phonead) != 0) 
 		return -1;
@@ -96,4 +96,5 @@
 	printf(NAME ": Accepting connections\n");
 	async_manager();
+	
 	/* Never reached */
 	return 0;
Index: uspace/srv/fb/ppm.c
===================================================================
--- uspace/srv/fb/ppm.c	(revision 8fe5980e42d82b7d2d7e089fc06a6048def9ee08)
+++ uspace/srv/fb/ppm.c	(revision 76fca318d723e24d0c79dc1a99d87b0b03dee0f1)
@@ -93,21 +93,21 @@
 	unsigned int color;
 	unsigned int coef;
-
+	
 	/* Read magic */
-	if (data[0] != 'P' || data[1] != '6')
+	if ((data[0] != 'P') || (data[1] != '6'))
 		return EINVAL;
-
-	data+=2;
+	
+	data += 2;
 	skip_whitespace(&data);
 	read_num(&data, &width);
 	skip_whitespace(&data);
-	read_num(&data,&height);
+	read_num(&data, &height);
 	skip_whitespace(&data);
-	read_num(&data,&maxcolor);
+	read_num(&data, &maxcolor);
 	data++;
-
-	if (maxcolor == 0 || maxcolor > 255 || width * height > datasz) {
+	
+	if ((maxcolor == 0) || (maxcolor > 255) || (width * height > datasz))
 		return EINVAL;
-	}
+	
 	coef = 255 / maxcolor;
 	if (coef * maxcolor > 255)
@@ -126,5 +126,5 @@
 		data += 3;
 	}
-
+	
 	return 0;
 }
