Index: genarch/src/fb/fb.c
===================================================================
--- genarch/src/fb/fb.c	(revision 4b74488b7812ae30cc8a3fc3957ac3330783c66c)
+++ genarch/src/fb/fb.c	(revision 6eb96fce19234c743567c0879eed45e27596e2b2)
@@ -37,4 +37,6 @@
 #include <memstr.h>
 #include <config.h>
+#include <bitops.h>
+#include <print.h>
 
 #include "helenos.xbm"
@@ -45,4 +47,6 @@
 
 static __u8 *blankline = NULL;
+static __u8 *dbbuffer = NULL; /* Buffer for fast scrolling console */
+static int dboffset;
 
 static unsigned int xres = 0;
@@ -68,86 +72,92 @@
 #define BLUE(x, bits)	((x >> (8 - bits)) & ((1 << bits) - 1))
 
-#define POINTPOS(x, y)	(y * scanline + x * pixelbytes)
+#define POINTPOS(x, y)	((y) * scanline + (x) * pixelbytes)
 
 /***************************************************************/
 /* Pixel specific fuctions */
 
-static void (*putpixel)(unsigned int x, unsigned int y, int color);
-static int (*getpixel)(unsigned int x, unsigned int y);
-
-/** Put pixel - 24-bit depth, 1 free byte */
-static void putpixel_4byte(unsigned int x, unsigned int y, int color)
-{
-	*((__u32 *)(fbaddress + POINTPOS(x, y))) = color;
-}
-
-/** Return pixel color - 24-bit depth, 1 free byte */
-static int getpixel_4byte(unsigned int x, unsigned int y)
-{
-	return *((__u32 *)(fbaddress + POINTPOS(x, y))) & 0xffffff;
-}
-
-/** Put pixel - 24-bit depth */
-static void putpixel_3byte(unsigned int x, unsigned int y, int color)
-{
-	unsigned int startbyte = POINTPOS(x, y);
-
+static void (*rgb2scr)(void *, int);
+static int (*scr2rgb)(void *);
+
+/* Conversion routines between different color representations */
+static void rgb_4byte(void *dst, int rgb)
+{
+	*(int *)dst = rgb;
+}
+
+static int byte4_rgb(void *src)
+{
+	return (*(int *)src) & 0xffffff;
+}
+
+static void rgb_3byte(void *dst, int rgb)
+{
+	__u8 *scr = dst;
 #if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
-	fbaddress[startbyte] = RED(color, 8);
-	fbaddress[startbyte + 1] = GREEN(color, 8);
-	fbaddress[startbyte + 2] = BLUE(color, 8);
+	scr[0] = RED(rgb, 8);
+	scr[1] = GREEN(rgb, 8);
+	scr[2] = BLUE(rgb, 8);
 #else
-	fbaddress[startbyte + 2] = RED(color, 8);
-	fbaddress[startbyte + 1] = GREEN(color, 8);
-	fbaddress[startbyte + 0] = BLUE(color, 8);
+	scr[2] = RED(rgb, 8);
+	scr[1] = GREEN(rgb, 8);
+	scr[0] = BLUE(rgb, 8);
+#endif
+}
+
+static int byte3_rgb(void *src)
+{
+	__u8 *scr = src;
+#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
+	return scr[0] << 16 | scr[1] << 8 | scr[2];
+#else
+	return scr[2] << 16 | scr[1] << 8 | scr[0];
 #endif	
 }
 
-/** Return pixel color - 24-bit depth */
-static int getpixel_3byte(unsigned int x, unsigned int y)
-{
-	unsigned int startbyte = POINTPOS(x, y);
-
-#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
-	return fbaddress[startbyte] << 16 | fbaddress[startbyte + 1] << 8 | fbaddress[startbyte + 2];
-#else
-	return fbaddress[startbyte + 2] << 16 | fbaddress[startbyte + 1] << 8 | fbaddress[startbyte + 0];
-#endif	
-}
-
-/** Put pixel - 16-bit depth (5:6:6) */
-static void putpixel_2byte(unsigned int x, unsigned int y, int color)
-{
-	/* 5-bit, 5-bits, 5-bits */
-	*((__u16 *)(fbaddress + POINTPOS(x, y))) = RED(color, 5) << 11 | GREEN(color, 6) << 5 | BLUE(color, 5);
-}
-
-/** Return pixel color - 16-bit depth (5:6:6) */
-static int getpixel_2byte(unsigned int x, unsigned int y)
-{
-	int color = *((__u16 *)(fbaddress + POINTPOS(x, y)));
+/**  16-bit depth (5:6:5) */
+static void rgb_2byte(void *dst, int rgb)
+{
+	/* 5-bit, 6-bits, 5-bits */ 
+	*((__u16 *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5);
+}
+
+/** 16-bit depth (5:6:5) */
+static int byte2_rgb(void *src)
+{
+	int color = *(__u16 *)(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 putpixel_1byte(unsigned int x, unsigned int y, int color)
-{
-	fbaddress[POINTPOS(x, y)] = RED(color, 3) << 5 | GREEN(color, 2) << 3 | BLUE(color, 3);
+static void rgb_1byte(void *dst, int rgb)
+{
+	*(__u8 *)dst = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3);
 }
 
 /** Return pixel color - 8-bit depth (3:2:3) */
-static int getpixel_1byte(unsigned int x, unsigned int y)
-{
-	int color = fbaddress[POINTPOS(x, y)];
+static int byte1_rgb(void *src)
+{
+	int color = *(__u8 *)src;
 	return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
 }
 
-/** Fill line with color BGCOLOR */
-static void clear_line(unsigned int y)
-{
-	unsigned int x;
-	
-	for (x = 0; x < xres; x++)
-		(*putpixel)(x, y, BGCOLOR);
+static void putpixel(unsigned int x, unsigned int y, int color)
+{
+	(*rgb2scr)(&fbaddress[POINTPOS(x,y)],color);
+
+	if (dbbuffer) {
+		int dline = (y + dboffset) % yres;
+		(*rgb2scr)(&dbbuffer[POINTPOS(x,dline)],color);
+	}
+}
+
+/** Get pixel from viewport */
+static int getpixel(unsigned int x, unsigned int y)
+{
+	if (dbbuffer) {
+		int dline = (y + dboffset) % yres;
+		return (*scr2rgb)(&dbbuffer[POINTPOS(x,dline)]);
+	}
+	return (*scr2rgb)(&fbaddress[POINTPOS(x,y)]);
 }
 
@@ -158,6 +168,9 @@
 	unsigned int y;
 
-	for (y = 0; y < yres; y++)
-		clear_line(y);
+	for (y = 0; y < yres; y++) {
+		memcpy(&fbaddress[scanline*y], blankline, xres*pixelbytes);
+		if (dbbuffer)
+			memcpy(&dbbuffer[scanline*y], blankline, xres*pixelbytes);
+	}
 }
 
@@ -167,9 +180,19 @@
 {
 	__u8 *lastline = &fbaddress[(rows - 1) * ROW_BYTES];
-
-	memcpy((void *) fbaddress, (void *) &fbaddress[ROW_BYTES], scanline * yres - ROW_BYTES);
-
-	/* Clear last row */
-	memcpy((void *) lastline, (void *) blankline, ROW_BYTES);
+	int firstsz;
+
+	if (dbbuffer) {
+		memcpy(&dbbuffer[dboffset*scanline], blankline, FONT_SCANLINES*scanline);
+		
+		dboffset = (dboffset + FONT_SCANLINES) % yres;
+		firstsz = yres-dboffset;
+
+		memcpy(fbaddress, &dbbuffer[scanline*dboffset], firstsz*scanline);
+		memcpy(&fbaddress[firstsz*scanline], dbbuffer, dboffset*scanline);
+	} else {
+		memcpy((void *) fbaddress, (void *) &fbaddress[ROW_BYTES], scanline * yres - ROW_BYTES);
+		/* Clear last row */
+		memcpy((void *) lastline, (void *) blankline, ROW_BYTES);
+	}
 }
 
@@ -177,5 +200,5 @@
 static void invert_pixel(unsigned int x, unsigned int y)
 {
-	(*putpixel)(x, y, ~(*getpixel)(x, y));
+	putpixel(x, y, ~getpixel(x, y));
 }
 
@@ -188,7 +211,7 @@
 	for (i = 0; i < 8; i++)
 		if (glline & (1 << (7 - i))) {
-			(*putpixel)(x + i, y, FGCOLOR);
+			putpixel(x + i, y, FGCOLOR);
 		} else
-			(*putpixel)(x + i, y, BGCOLOR);
+			putpixel(x + i, y, BGCOLOR);
 }
 
@@ -236,5 +259,5 @@
 			byte >>= x % 8;
 			if (byte & 1)
-				(*putpixel)(startx + x, starty + y, LOGOCOLOR);
+				putpixel(startx + x, starty + y, LOGOCOLOR);
 		}
 }
@@ -312,21 +335,21 @@
 	switch (bpp) {
 		case 8:
-			putpixel = putpixel_1byte;
-			getpixel = getpixel_1byte;
+			rgb2scr = rgb_1byte;
+			scr2rgb = byte1_rgb;
 			pixelbytes = 1;
 			break;
 		case 16:
-			putpixel = putpixel_2byte;
-			getpixel = getpixel_2byte;
+			rgb2scr = rgb_2byte;
+			scr2rgb = byte2_rgb;
 			pixelbytes = 2;
 			break;
 		case 24:
-			putpixel = putpixel_3byte;
-			getpixel = getpixel_3byte;
+			rgb2scr = rgb_3byte;
+			scr2rgb = byte3_rgb;
 			pixelbytes = 3;
 			break;
 		case 32:
-			putpixel = putpixel_4byte;
-			getpixel = getpixel_4byte;
+			rgb2scr = rgb_4byte;
+			scr2rgb = byte4_rgb;
 			pixelbytes = 4;
 			break;
@@ -348,9 +371,33 @@
 	columns = x / COL_WIDTH;
 
-	clear_screen();
+	/* Allocate double buffer */
+	int totsize = scanline * yres;
+	int pages = SIZE2FRAMES(totsize);
+	int order;
+	int rc;
+	if (pages == 1)
+		order = 0;
+	else
+		order = fnzb(pages-1)+1;
+
+	pfn_t frame = frame_alloc_rc(order,FRAME_ATOMIC,&rc);
+	if (!rc)
+		dbbuffer = (void *)PA2KA(PFN2ADDR(frame));
+	else 
+		printf("Failed to allocate scroll buffer.\n");
+	dboffset = 0;
+
+	/* Initialized blank line */
 	blankline = (__u8 *) malloc(ROW_BYTES, FRAME_ATOMIC);
 	ASSERT(blankline);
-	memcpy((void *) blankline, (void *) &fbaddress[(rows - 1) * ROW_BYTES], ROW_BYTES);
-	
+	for (y=0; y < FONT_SCANLINES; y++)
+		for (x=0; x < xres; x++)
+			(*rgb2scr)(&blankline[POINTPOS(x,y)],BGCOLOR);
+
+	clear_screen();
+
+	/* Update size of screen to match text area */
+	yres = rows * FONT_SCANLINES;
+
 	draw_logo(xres - helenos_width, 0);
 	invert_cursor();
@@ -366,3 +413,4 @@
 	sysinfo_set_item_val("fb.scanline", NULL, scan);
 	sysinfo_set_item_val("fb.address.physical", NULL, addr);
-}
+
+}
Index: generic/src/mm/slab.c
===================================================================
--- generic/src/mm/slab.c	(revision 4b74488b7812ae30cc8a3fc3957ac3330783c66c)
+++ generic/src/mm/slab.c	(revision 6eb96fce19234c743567c0879eed45e27596e2b2)
@@ -594,5 +594,5 @@
 
 	/* Minimum slab order */
-	pages = ((cache->size-1) >> PAGE_WIDTH) + 1;
+	pages = SIZE2FRAMES(cache->size);
 	/* We need the 2^order >= pages */
 	if (pages == 1)
