Index: uspace/srv/fb/msim.c
===================================================================
--- uspace/srv/fb/msim.c	(revision 8231246c805f8410b02e53e44e25bac61ac47762)
+++ uspace/srv/fb/msim.c	(revision d99b3f2e89a5554f23c6edd0cb5ee8944fa16d8f)
@@ -37,15 +37,7 @@
 
 #include <async.h>
-#include <ipc/fb.h>
-#include <ipc/ipc.h>
 #include <libc.h>
-#include <errno.h>
-#include <string.h>
-#include <libc.h>
-#include <stdio.h>
-#include <ipc/fb.h>
 #include <sysinfo.h>
 #include <as.h>
-#include <align.h>
 #include <ddi.h>
 
@@ -56,9 +48,4 @@
 #define HEIGHT 25
 
-#define MAX_CONTROL 20
-
-/* Allow only 1 connection */
-static int client_connected = 0;
-
 static char *virt_addr;
 
@@ -66,98 +53,4 @@
 {
 	*virt_addr = c;
-}
-
-static void msim_client_connection(ipc_callid_t iid, ipc_call_t *icall)
-{
-	int retval;
-	ipc_callid_t callid;
-	ipc_call_t call;
-	char c;
-	int lastcol = 0;
-	int lastrow = 0;
-	int newcol;
-	int newrow;
-	int fgcolor;
-	int bgcolor;
-	int i;
-
-	if (client_connected) {
-		ipc_answer_0(iid, ELIMIT);
-		return;
-	}
-	
-	client_connected = 1;
-	ipc_answer_0(iid, EOK);
-	
-	/* Clear the terminal, set scrolling region
-	   to 0 - 25 lines */
-	serial_clrscr();
-	serial_goto(0, 0);
-	serial_puts("\033[0;25r");
-	
-	while (true) {
-		callid = async_get_call(&call);
-		switch (IPC_GET_METHOD(call)) {
-		case IPC_M_PHONE_HUNGUP:
-			client_connected = 0;
-			ipc_answer_0(callid, EOK);
-			return;
-		case FB_PUTCHAR:
-			c = IPC_GET_ARG1(call);
-			newrow = IPC_GET_ARG2(call);
-			newcol = IPC_GET_ARG3(call);
-			if ((lastcol != newcol) || (lastrow != newrow))
-				serial_goto(newrow, newcol);
-			lastcol = newcol + 1;
-			lastrow = newrow;
-			msim_putc(c);
-			retval = 0;
-			break;
-		case FB_CURSOR_GOTO:
-			newrow = IPC_GET_ARG1(call);
-			newcol = IPC_GET_ARG2(call);
-			serial_goto(newrow, newcol);
-			lastrow = newrow;
-			lastcol = newcol;
-			retval = 0;
-			break;
-		case FB_GET_CSIZE:
-			ipc_answer_2(callid, EOK, HEIGHT, WIDTH);
-			continue;
-		case FB_CLEAR:
-			serial_clrscr();
-			retval = 0;
-			break;
-		case FB_SET_STYLE:
-			fgcolor = IPC_GET_ARG1(call);
-			bgcolor = IPC_GET_ARG2(call);
-			if (fgcolor < bgcolor)
-				serial_set_style(0);
-			else
-				serial_set_style(7);
-			retval = 0;
-			break;
-		case FB_SCROLL:
-			i = IPC_GET_ARG1(call);
-			if ((i > HEIGHT) || (i < -HEIGHT)) {
-				retval = EINVAL;
-				break;
-			}
-			serial_scroll(i);
-			serial_goto(lastrow, lastcol);
-			retval = 0;
-			break;
-		case FB_CURSOR_VISIBILITY:
-			if(IPC_GET_ARG1(call))
-				serial_cursor_enable();
-			else
-				serial_cursor_disable();
-			retval = 0;
-			break;
-		default:
-			retval = ENOENT;
-		}
-		ipc_answer_0(callid, retval);
-	}
 }
 
@@ -171,5 +64,5 @@
 	serial_console_init(msim_putc, WIDTH, HEIGHT);
 	
-	async_set_client_connection(msim_client_connection);
+	async_set_client_connection(serial_client_connection);
 	return 0;
 }
Index: uspace/srv/fb/serial_console.c
===================================================================
--- uspace/srv/fb/serial_console.c	(revision 8231246c805f8410b02e53e44e25bac61ac47762)
+++ uspace/srv/fb/serial_console.c	(revision d99b3f2e89a5554f23c6edd0cb5ee8944fa16d8f)
@@ -39,4 +39,9 @@
 
 #include <stdio.h>
+#include <ipc/ipc.h>
+#include <async.h>
+#include <ipc/fb.h>
+#include <bool.h>
+#include <errno.h>
 
 #include "serial_console.h"
@@ -44,7 +49,10 @@
 #define MAX_CONTROL 20
 
-static uint32_t width;
-static uint32_t height;
+static int width;
+static int height;
 static putc_function_t putc_function;
+
+/* Allow only 1 connection */
+static int client_connected = 0;
 
 void serial_puts(char *str)
@@ -89,4 +97,12 @@
 }
 
+/** Set scrolling region. */
+void serial_set_scroll_region(unsigned last_row)
+{
+	char control[MAX_CONTROL];
+	snprintf(control, MAX_CONTROL, "\033[0;%ur", last_row);
+	serial_puts(control);
+}
+
 void serial_cursor_disable(void)
 {
@@ -106,4 +122,101 @@
 }
 
+/**
+ * Main function of the thread serving client connections.
+ */
+void serial_client_connection(ipc_callid_t iid, ipc_call_t *icall)
+{
+	int retval;
+	ipc_callid_t callid;
+	ipc_call_t call;
+	char c;
+	int lastcol = 0;
+	int lastrow = 0;
+	int newcol;
+	int newrow;
+	int fgcolor;
+	int bgcolor;
+	int i;
+	
+	if (client_connected) {
+		ipc_answer_0(iid, ELIMIT);
+		return;
+	}
+	
+	client_connected = 1;
+	ipc_answer_0(iid, EOK);
+	
+	/* Clear the terminal, set scrolling region
+	   to 0 - height rows. */
+	serial_clrscr();
+	serial_goto(0, 0);
+	serial_set_scroll_region(height);
+	
+	while (true) {
+		callid = async_get_call(&call);
+		switch (IPC_GET_METHOD(call)) {
+		case IPC_M_PHONE_HUNGUP:
+			client_connected = 0;
+			ipc_answer_0(callid, EOK);
+			return;
+		case FB_PUTCHAR:
+			c = IPC_GET_ARG1(call);
+			newrow = IPC_GET_ARG2(call);
+			newcol = IPC_GET_ARG3(call);
+			if ((lastcol != newcol) || (lastrow != newrow))
+				serial_goto(newrow, newcol);
+			lastcol = newcol + 1;
+			lastrow = newrow;
+			(*putc_function)(c);
+			retval = 0;
+			break;
+		case FB_CURSOR_GOTO:
+			newrow = IPC_GET_ARG1(call);
+			newcol = IPC_GET_ARG2(call);
+			serial_goto(newrow, newcol);
+			lastrow = newrow;
+			lastcol = newcol;
+			retval = 0;
+			break;
+		case FB_GET_CSIZE:
+			ipc_answer_2(callid, EOK, height, width);
+			continue;
+		case FB_CLEAR:
+			serial_clrscr();
+			retval = 0;
+			break;
+		case FB_SET_STYLE:
+			fgcolor = IPC_GET_ARG1(call);
+			bgcolor = IPC_GET_ARG2(call);
+			if (fgcolor < bgcolor)
+				serial_set_style(0);
+			else
+				serial_set_style(7);
+			retval = 0;
+			break;
+		case FB_SCROLL:
+			i = IPC_GET_ARG1(call);
+			if ((i > height) || (i < -height)) {
+				retval = EINVAL;
+				break;
+			}
+			serial_scroll(i);
+			serial_goto(lastrow, lastcol);
+			retval = 0;
+			break;
+		case FB_CURSOR_VISIBILITY:
+			if(IPC_GET_ARG1(call))
+				serial_cursor_enable();
+			else
+				serial_cursor_disable();
+			retval = 0;
+			break;
+		default:
+			retval = ENOENT;
+		}
+		ipc_answer_0(callid, retval);
+	}
+}
+
 /** 
  * @}
Index: uspace/srv/fb/serial_console.h
===================================================================
--- uspace/srv/fb/serial_console.h	(revision 8231246c805f8410b02e53e44e25bac61ac47762)
+++ uspace/srv/fb/serial_console.h	(revision d99b3f2e89a5554f23c6edd0cb5ee8944fa16d8f)
@@ -39,4 +39,6 @@
 #define FB_SERIAL_CONSOLE_H_
 
+#include <ipc/ipc.h>
+
 typedef void (*putc_function_t)(char);
 
@@ -48,5 +50,8 @@
 void serial_cursor_disable(void);
 void serial_cursor_enable(void);
+void serial_set_scroll_region(unsigned height);
 void serial_console_init(putc_function_t putc_fn, uint32_t w, uint32_t h);
+void serial_client_connection(ipc_callid_t iid, ipc_call_t *icall);
+
 
 #endif
Index: uspace/srv/fb/sgcn.c
===================================================================
--- uspace/srv/fb/sgcn.c	(revision 8231246c805f8410b02e53e44e25bac61ac47762)
+++ uspace/srv/fb/sgcn.c	(revision d99b3f2e89a5554f23c6edd0cb5ee8944fa16d8f)
@@ -37,6 +37,4 @@
 
 #include <async.h>
-#include <ipc/ipc.h>
-#include <ipc/fb.h>
 #include <sysinfo.h>
 #include <as.h>
@@ -60,7 +58,4 @@
  */
 static uintptr_t sram_buffer_offset;
-
-/* Allow only 1 connection */
-static int client_connected = 0;
 
 /**
@@ -123,101 +118,4 @@
 
 /**
- * Main function of the thread serving client connections.
- */
-static void sgcn_client_connection(ipc_callid_t iid, ipc_call_t *icall)
-{
-	int retval;
-	ipc_callid_t callid;
-	ipc_call_t call;
-	char c;
-	int lastcol = 0;
-	int lastrow = 0;
-	int newcol;
-	int newrow;
-	int fgcolor;
-	int bgcolor;
-	int i;
-	
-	if (client_connected) {
-		ipc_answer_0(iid, ELIMIT);
-		return;
-	}
-	
-	client_connected = 1;
-	ipc_answer_0(iid, EOK);
-	
-	/* Clear the terminal, set scrolling region
-	   to 0 - 24 lines */
-	serial_clrscr();
-	serial_goto(0, 0);
-	serial_puts("\033[0;24r");
-	
-	while (true) {
-		callid = async_get_call(&call);
-		switch (IPC_GET_METHOD(call)) {
-		case IPC_M_PHONE_HUNGUP:
-			client_connected = 0;
-			ipc_answer_0(callid, EOK);
-			return;
-		case FB_PUTCHAR:
-			c = IPC_GET_ARG1(call);
-			newrow = IPC_GET_ARG2(call);
-			newcol = IPC_GET_ARG3(call);
-			if ((lastcol != newcol) || (lastrow != newrow))
-				serial_goto(newrow, newcol);
-			lastcol = newcol + 1;
-			lastrow = newrow;
-			sgcn_putc(c);
-			retval = 0;
-			break;
-		case FB_CURSOR_GOTO:
-			newrow = IPC_GET_ARG1(call);
-			newcol = IPC_GET_ARG2(call);
-			serial_goto(newrow, newcol);
-			lastrow = newrow;
-			lastcol = newcol;
-			retval = 0;
-			break;
-		case FB_GET_CSIZE:
-			ipc_answer_2(callid, EOK, HEIGHT, WIDTH);
-			continue;
-		case FB_CLEAR:
-			serial_clrscr();
-			retval = 0;
-			break;
-		case FB_SET_STYLE:
-			fgcolor = IPC_GET_ARG1(call);
-			bgcolor = IPC_GET_ARG2(call);
-			if (fgcolor < bgcolor)
-				serial_set_style(0);
-			else
-				serial_set_style(7);
-			retval = 0;
-			break;
-		case FB_SCROLL:
-			i = IPC_GET_ARG1(call);
-			if ((i > HEIGHT) || (i < -HEIGHT)) {
-				retval = EINVAL;
-				break;
-			}
-			serial_scroll(i);
-			serial_goto(lastrow, lastcol);
-			retval = 0;
-			break;
-		case FB_CURSOR_VISIBILITY:
-			if(IPC_GET_ARG1(call))
-				serial_cursor_enable();
-			else
-				serial_cursor_disable();
-			retval = 0;
-			break;
-		default:
-			retval = ENOENT;
-		}
-		ipc_answer_0(callid, retval);
-	}
-}
-
-/**
  * Initializes the SGCN serial driver.
  */
@@ -241,5 +139,5 @@
 	sram_buffer_offset = sysinfo_value("sram.buffer.offset");
 	
-	async_set_client_connection(sgcn_client_connection);
+	async_set_client_connection(serial_client_connection);
 	return 0;
 }
