Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/Makefile	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -93,5 +93,4 @@
 	srv/bd/sata_bd \
 	srv/bd/file_bd \
-	srv/bd/gxe_bd \
 	srv/bd/rd \
 	srv/bd/part/guid_part \
Index: uspace/app/init/init.c
===================================================================
--- uspace/app/init/init.c	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/app/init/init.c	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -369,5 +369,4 @@
 #ifdef CONFIG_START_BD
 	srv_start("/srv/ata_bd");
-	srv_start("/srv/gxe_bd");
 #endif
 	
Index: uspace/app/netecho/netecho.c
===================================================================
--- uspace/app/netecho/netecho.c	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/app/netecho/netecho.c	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -243,5 +243,5 @@
 		if (verbose)
 			printf("accept()\n");
-            	socket_id = accept(listening_id, (void *) address_buf, &addrlen);
+		socket_id = accept(listening_id, (void *) address_buf, &addrlen);
 		if (socket_id <= 0) {
 			socket_print_error(stderr, socket_id, "Socket accept: ", "\n");
@@ -312,5 +312,5 @@
 				rc = sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen);
 				if (rc != EOK)
-					socket_print_error(stderr, rc, "Socket send: ", "\n");
+					socket_print_error(stderr, rc, "Socket sendto: ", "\n");
 			}
 		}
@@ -394,5 +394,12 @@
 		return listening_id;
 	}
-
+	
+	/* Bind the listening socket */
+	rc = bind(listening_id, address, addrlen);
+	if (rc != EOK) {
+		socket_print_error(stderr, rc, "Socket bind: ", "\n");
+		return rc;
+	}
+	
 	/* if the stream socket is used */
 	if (type == SOCK_STREAM) {
@@ -402,5 +409,5 @@
 			backlog = 3;
 		}
-
+		
 		/* Set the backlog */
 		rc = listen(listening_id, backlog);
@@ -409,11 +416,4 @@
 			return rc;
 		}
-	}
-
-	/* Bind the listening socket */
-	rc = bind(listening_id, address, addrlen);
-	if (rc != EOK) {
-		socket_print_error(stderr, rc, "Socket bind: ", "\n");
-		return rc;
 	}
 
Index: uspace/app/nettest3/nettest3.c
===================================================================
--- uspace/app/nettest3/nettest3.c	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/app/nettest3/nettest3.c	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -63,5 +63,5 @@
 	port = 7;
 
-	data = (char *)"Hello World!";
+	data = (char *) "Hello World!";
 	size = str_size(data);
 
@@ -98,5 +98,5 @@
 
 	printf("connect()\n");
-	rc = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
+	rc = connect(fd, (struct sockaddr *) &addr, sizeof(addr));
 	printf(" -> %d\n", rc);
 	if (rc != 0)
@@ -115,5 +115,5 @@
 	} while (rc > 0);
 
-	async_usleep(1000*1000);
+	async_usleep(1000 * 1000);
 
 	printf("closesocket()\n");
@@ -124,5 +124,4 @@
 }
 
-
 /** @}
  */
Index: uspace/lib/c/arch/mips32/Makefile.common
===================================================================
--- uspace/lib/c/arch/mips32/Makefile.common	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/lib/c/arch/mips32/Makefile.common	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -27,5 +27,5 @@
 #
 
-GCC_CFLAGS += -msoft-float -mips3 -mabi=32
+GCC_CFLAGS += -msoft-float -mabi=32
 BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a
 
@@ -34,2 +34,11 @@
 BFD_ARCH = mips
 BFD_NAME = elf32-tradlittlemips
+
+ifeq ($(MACHINE),msim)
+	GCC_CFLAGS += -march=r4000 
+endif
+
+ifeq ($(MACHINE),lmalta)
+	GCC_CFLAGS += -march=4kc
+endif
+
Index: uspace/lib/c/arch/mips32eb/Makefile.common
===================================================================
--- uspace/lib/c/arch/mips32eb/Makefile.common	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/lib/c/arch/mips32eb/Makefile.common	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -27,5 +27,5 @@
 #
 
-GCC_CFLAGS += -msoft-float -mips3 -mabi=32
+GCC_CFLAGS += -msoft-float -mabi=32
 BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a
 
@@ -34,2 +34,7 @@
 BFD_ARCH = mips
 BFD_NAME = elf32-tradbigmips
+
+ifeq ($(MACHINE),bmalta)
+	GCC_CFLAGS += -march=4kc
+endif
+
Index: uspace/lib/c/generic/async.c
===================================================================
--- uspace/lib/c/generic/async.c	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/lib/c/generic/async.c	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -350,5 +350,5 @@
 static async_client_conn_t client_connection = default_client_connection;
 static async_interrupt_handler_t interrupt_received = default_interrupt_received;
-static size_t interrupt_handler_stksz = (size_t) -1;
+static size_t interrupt_handler_stksz = FIBRIL_DFLT_STK_SIZE;
 
 /** Setter for client_connection function pointer.
@@ -375,5 +375,5 @@
 /** Set the stack size for the interrupt handler notification fibrils.
  *
- * @param size Stack size. Use -1 to use the system default stack size.
+ * @param size Stack size in bytes.
  */
 void async_set_interrupt_handler_stack_size(size_t size)
@@ -2068,4 +2068,5 @@
 	
 	async_sess_t *sess = exch->sess;
+	assert(sess != NULL);
 	
 	atomic_dec(&sess->refcnt);
Index: uspace/lib/c/generic/fibril.c
===================================================================
--- uspace/lib/c/generic/fibril.c	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/lib/c/generic/fibril.c	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -256,5 +256,5 @@
  * @param func Implementing function of the new fibril.
  * @param arg Argument to pass to func.
- * @param stksz Stack size, -1 for the system default stack size.
+ * @param stksz Stack size in bytes.
  *
  * @return 0 on failure or TLS of the new fibril.
@@ -269,5 +269,6 @@
 		return 0;
 	
-	size_t stack_size = (stksz == (size_t) -1) ? stack_size_get() : stksz;
+	size_t stack_size = (stksz == FIBRIL_DFLT_STK_SIZE) ?
+	    stack_size_get() : stksz;
 	fibril->stack = as_area_create((void *) -1, stack_size,
 	    AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE | AS_AREA_GUARD |
Index: uspace/lib/c/generic/net/socket_client.c
===================================================================
--- uspace/lib/c/generic/net/socket_client.c	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/lib/c/generic/net/socket_client.c	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -192,84 +192,88 @@
 /** Default thread for new connections.
  *
- * @param[in] iid	The initial message identifier.
- * @param[in] icall	The initial message call structure.
- * @param[in] arg	Local argument.
+ * @param[in] iid   The initial message identifier.
+ * @param[in] icall The initial message call structure.
+ * @param[in] arg   Local argument.
+ *
  */
 static void socket_connection(ipc_callid_t iid, ipc_call_t * icall, void *arg)
 {
-	ipc_callid_t callid;
-	ipc_call_t call;
-	socket_t *socket;
-	int rc;
-
-loop:
-	callid = async_get_call(&call);
-
-	switch (IPC_GET_IMETHOD(call)) {
-	case NET_SOCKET_RECEIVED:
-	case NET_SOCKET_ACCEPTED:
-	case NET_SOCKET_DATA_FRAGMENT_SIZE:
-		fibril_rwlock_read_lock(&socket_globals.lock);
-
-		/* Find the socket */
-		socket = sockets_find(socket_get_sockets(),
-		    SOCKET_GET_SOCKET_ID(call));
-		if (!socket) {
-			rc = ENOTSOCK;
-			fibril_rwlock_read_unlock(&socket_globals.lock);
-			break;
+	while (true) {
+		ipc_call_t call;
+		ipc_callid_t callid = async_get_call(&call);
+		
+		if (!IPC_GET_IMETHOD(call)) {
+			async_answer_0(callid, 0);
+			return;
 		}
+		
+		int rc;
 		
 		switch (IPC_GET_IMETHOD(call)) {
 		case NET_SOCKET_RECEIVED:
-			fibril_mutex_lock(&socket->receive_lock);
-			/* Push the number of received packet fragments */
-			rc = dyn_fifo_push(&socket->received,
-			    SOCKET_GET_DATA_FRAGMENTS(call),
-			    SOCKET_MAX_RECEIVED_SIZE);
-			if (rc == EOK) {
-				/* Signal the received packet */
-				fibril_condvar_signal(&socket->receive_signal);
+		case NET_SOCKET_ACCEPTED:
+		case NET_SOCKET_DATA_FRAGMENT_SIZE:
+			fibril_rwlock_read_lock(&socket_globals.lock);
+			
+			/* Find the socket */
+			socket_t *socket = sockets_find(socket_get_sockets(),
+			    SOCKET_GET_SOCKET_ID(call));
+			if (!socket) {
+				rc = ENOTSOCK;
+				fibril_rwlock_read_unlock(&socket_globals.lock);
+				break;
 			}
-			fibril_mutex_unlock(&socket->receive_lock);
+			
+			switch (IPC_GET_IMETHOD(call)) {
+			case NET_SOCKET_RECEIVED:
+				fibril_mutex_lock(&socket->receive_lock);
+				/* Push the number of received packet fragments */
+				rc = dyn_fifo_push(&socket->received,
+				    SOCKET_GET_DATA_FRAGMENTS(call),
+				    SOCKET_MAX_RECEIVED_SIZE);
+				if (rc == EOK) {
+					/* Signal the received packet */
+					fibril_condvar_signal(&socket->receive_signal);
+				}
+				fibril_mutex_unlock(&socket->receive_lock);
+				break;
+				
+			case NET_SOCKET_ACCEPTED:
+				/* Push the new socket identifier */
+				fibril_mutex_lock(&socket->accept_lock);
+				rc = dyn_fifo_push(&socket->accepted, 1,
+				    SOCKET_MAX_ACCEPTED_SIZE);
+				if (rc == EOK) {
+					/* Signal the accepted socket */
+					fibril_condvar_signal(&socket->accept_signal);
+				}
+				fibril_mutex_unlock(&socket->accept_lock);
+				break;
+			
+			default:
+				rc = ENOTSUP;
+			}
+			
+			if ((SOCKET_GET_DATA_FRAGMENT_SIZE(call) > 0) &&
+			    (SOCKET_GET_DATA_FRAGMENT_SIZE(call) !=
+			    socket->data_fragment_size)) {
+				fibril_rwlock_write_lock(&socket->sending_lock);
+				
+				/* Set the data fragment size */
+				socket->data_fragment_size =
+				    SOCKET_GET_DATA_FRAGMENT_SIZE(call);
+				
+				fibril_rwlock_write_unlock(&socket->sending_lock);
+			}
+			
+			fibril_rwlock_read_unlock(&socket_globals.lock);
 			break;
-
-		case NET_SOCKET_ACCEPTED:
-			/* Push the new socket identifier */
-			fibril_mutex_lock(&socket->accept_lock);
-			rc = dyn_fifo_push(&socket->accepted, 1,
-			    SOCKET_MAX_ACCEPTED_SIZE);
-			if (rc == EOK) {
-				/* Signal the accepted socket */
-				fibril_condvar_signal(&socket->accept_signal);
-			}
-			fibril_mutex_unlock(&socket->accept_lock);
-			break;
-
+			
 		default:
 			rc = ENOTSUP;
 		}
-
-		if ((SOCKET_GET_DATA_FRAGMENT_SIZE(call) > 0) &&
-		    (SOCKET_GET_DATA_FRAGMENT_SIZE(call) !=
-		    socket->data_fragment_size)) {
-			fibril_rwlock_write_lock(&socket->sending_lock);
-
-			/* Set the data fragment size */
-			socket->data_fragment_size =
-			    SOCKET_GET_DATA_FRAGMENT_SIZE(call);
-
-			fibril_rwlock_write_unlock(&socket->sending_lock);
-		}
-
-		fibril_rwlock_read_unlock(&socket_globals.lock);
-		break;
-
-	default:
-		rc = ENOTSUP;
-	}
-
-	async_answer_0(callid, (sysarg_t) rc);
-	goto loop;
+		
+		async_answer_0(callid, (sysarg_t) rc);
+	}
 }
 
Index: uspace/lib/c/include/fibril.h
===================================================================
--- uspace/lib/c/include/fibril.h	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/lib/c/include/fibril.h	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -86,6 +86,8 @@
 extern void context_restore(context_t *ctx) __attribute__((noreturn));
 
+#define FIBRIL_DFLT_STK_SIZE	0
+
 #define fibril_create(func, arg) \
-	fibril_create_generic((func), (arg), (size_t) -1)
+	fibril_create_generic((func), (arg), FIBRIL_DFLT_STK_SIZE)
 extern fid_t fibril_create_generic(int (*func)(void *), void *arg, size_t);
 extern void fibril_destroy(fid_t fid);
Index: uspace/srv/bd/gxe_bd/Makefile
===================================================================
--- uspace/srv/bd/gxe_bd/Makefile	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ 	(revision )
@@ -1,36 +1,0 @@
-#
-# Copyright (c) 2005 Martin Decky
-# Copyright (c) 2007 Jakub Jermar
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-USPACE_PREFIX = ../../..
-BINARY = gxe_bd
-
-SOURCES = \
-	gxe_bd.c
-
-include $(USPACE_PREFIX)/Makefile.common
Index: uspace/srv/bd/gxe_bd/gxe_bd.c
===================================================================
--- uspace/srv/bd/gxe_bd/gxe_bd.c	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ 	(revision )
@@ -1,340 +1,0 @@
-/*
- * Copyright (c) 2009 Jiri Svoboda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup bd
- * @{
- */
-
-/**
- * @file
- * @brief GXemul disk driver
- */
-
-#include <stdio.h>
-#include <ddi.h>
-#include <async.h>
-#include <as.h>
-#include <bd_srv.h>
-#include <fibril_synch.h>
-#include <loc.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <macros.h>
-#include <task.h>
-
-#define NAME       "gxe_bd"
-#define NAMESPACE  "bd"
-
-enum {
-	CTL_READ_START	= 0,
-	CTL_WRITE_START = 1,
-};
-
-enum {
-	STATUS_FAILURE	= 0
-};
-
-enum {
-	MAX_DISKS	= 2
-};
-
-/** GXE disk hardware registers */
-typedef struct {
-	uint32_t offset_lo;
-	uint32_t pad0;
-	uint32_t offset_hi;
-	uint32_t pad1;
-
-	uint32_t disk_id;
-	uint32_t pad2[3];
-
-	uint32_t control;
-	uint32_t pad3[3];
-
-	uint32_t status;
-
-	uint32_t pad4[3];
-	uint8_t pad5[0x3fc0];
-
-	uint8_t buffer[512];
-} gxe_bd_hw_t;
-
-/** GXE block device soft state */
-typedef struct {
-	/** Block device service structure */
-	bd_srvs_t bds;
-	int disk_id;
-} gxe_bd_t;
-
-static const size_t block_size = 512;
-
-static uintptr_t dev_physical = 0x13000000;
-static gxe_bd_hw_t *dev;
-
-static service_id_t service_id[MAX_DISKS];
-
-static fibril_mutex_t dev_lock[MAX_DISKS];
-
-static gxe_bd_t gxe_bd[MAX_DISKS];
-
-static int gxe_bd_init(void);
-static void gxe_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *);
-static int gxe_bd_read_block(int disk_id, uint64_t ba, void *buf);
-static int gxe_bd_write_block(int disk_id, uint64_t ba, const void *buf);
-
-static int gxe_bd_open(bd_srvs_t *, bd_srv_t *);
-static int gxe_bd_close(bd_srv_t *);
-static int gxe_bd_read_blocks(bd_srv_t *, aoff64_t, size_t, void *, size_t);
-static int gxe_bd_write_blocks(bd_srv_t *, aoff64_t, size_t, const void *, size_t);
-static int gxe_bd_get_block_size(bd_srv_t *, size_t *);
-static int gxe_bd_get_num_blocks(bd_srv_t *, aoff64_t *);
-
-static bd_ops_t gxe_bd_ops = {
-	.open = gxe_bd_open,
-	.close = gxe_bd_close,
-	.read_blocks = gxe_bd_read_blocks,
-	.write_blocks = gxe_bd_write_blocks,
-	.get_block_size = gxe_bd_get_block_size,
-	.get_num_blocks = gxe_bd_get_num_blocks
-};
-
-static gxe_bd_t *bd_srv_gxe(bd_srv_t *bd)
-{
-	return (gxe_bd_t *) bd->srvs->sarg;
-}
-
-int main(int argc, char **argv)
-{
-	printf(NAME ": GXemul disk driver\n");
-
-	if (gxe_bd_init() != EOK)
-		return -1;
-
-	printf(NAME ": Accepting connections\n");
-	task_retval(0);
-	async_manager();
-
-	/* Not reached */
-	return 0;
-}
-
-static int gxe_bd_init(void)
-{
-	async_set_client_connection(gxe_bd_connection);
-	int rc = loc_server_register(NAME);
-	if (rc != EOK) {
-		printf("%s: Unable to register driver.\n", NAME);
-		return rc;
-	}
-	
-	void *vaddr;
-	rc = pio_enable((void *) dev_physical, sizeof(gxe_bd_hw_t), &vaddr);
-	if (rc != EOK) {
-		printf("%s: Could not initialize device I/O space.\n", NAME);
-		return rc;
-	}
-	
-	dev = vaddr;
-	
-	for (unsigned int i = 0; i < MAX_DISKS; i++) {
-		char name[16];
-		
-		bd_srvs_init(&gxe_bd[i].bds);
-		gxe_bd[i].bds.ops = &gxe_bd_ops;
-		gxe_bd[i].bds.sarg = (void *)&gxe_bd[i];
-		
-		snprintf(name, 16, "%s/disk%u", NAMESPACE, i);
-		rc = loc_service_register(name, &service_id[i]);
-		if (rc != EOK) {
-			printf("%s: Unable to register device %s.\n", NAME,
-			    name);
-			return rc;
-		}
-		
-		fibril_mutex_initialize(&dev_lock[i]);
-	}
-	
-	return EOK;
-}
-
-static void gxe_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
-{
-	service_id_t dsid;
-	int disk_id, i;
-
-	/* Get the device handle. */
-	dsid = IPC_GET_ARG1(*icall);
-
-	/* Determine which disk device is the client connecting to. */
-	disk_id = -1;
-	for (i = 0; i < MAX_DISKS; i++)
-		if (service_id[i] == dsid)
-			disk_id = i;
-
-	if (disk_id < 0) {
-		async_answer_0(iid, EINVAL);
-		return;
-	}
-
-	bd_conn(iid, icall, &gxe_bd[disk_id].bds);
-}
-
-/** Open device. */
-static int gxe_bd_open(bd_srvs_t *bds, bd_srv_t *bd)
-{
-	return EOK;
-}
-
-/** Close device. */
-static int gxe_bd_close(bd_srv_t *bd)
-{
-	return EOK;
-}
-
-/** Read multiple blocks from the device. */
-static int gxe_bd_read_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt,
-    void *buf, size_t size)
-{
-	int disk_id = bd_srv_gxe(bd)->disk_id;
-	int rc;
-
-	if (size < cnt * block_size)
-		return EINVAL;
-
-	while (cnt > 0) {
-		rc = gxe_bd_read_block(disk_id, ba, buf);
-		if (rc != EOK)
-			return rc;
-
-		++ba;
-		--cnt;
-		buf += block_size;
-	}
-
-	return EOK;
-}
-
-/** Write multiple blocks to the device. */
-static int gxe_bd_write_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt,
-    const void *buf, size_t size)
-{
-	int disk_id = bd_srv_gxe(bd)->disk_id;
-	int rc;
-
-	if (size < cnt * block_size)
-		return EINVAL;
-
-	while (cnt > 0) {
-		rc = gxe_bd_write_block(disk_id, ba, buf);
-		if (rc != EOK)
-			return rc;
-
-		++ba;
-		--cnt;
-		buf += block_size;
-	}
-
-	return EOK;
-}
-
-/** Get device block size. */
-static int gxe_bd_get_block_size(bd_srv_t *bd, size_t *rsize)
-{
-	*rsize = block_size;
-	return EOK;
-}
-
-/** Get number of blocks on device. */
-static int gxe_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb)
-{
-	return ENOTSUP;
-}
-
-/** Read a block from the device. */
-static int gxe_bd_read_block(int disk_id, uint64_t ba, void *buf)
-{
-	uint32_t status;
-	uint64_t byte_addr;
-	size_t i;
-	uint32_t w;
-
-	byte_addr = ba * block_size;
-
-	fibril_mutex_lock(&dev_lock[disk_id]);
-	pio_write_32(&dev->offset_lo, (uint32_t) byte_addr);
-	pio_write_32(&dev->offset_hi, byte_addr >> 32);
-	pio_write_32(&dev->disk_id, disk_id);
-	pio_write_32(&dev->control, CTL_READ_START);
-
-	status = pio_read_32(&dev->status);
-	if (status == STATUS_FAILURE) {
-		fibril_mutex_unlock(&dev_lock[disk_id]);
-		return EIO;
-	}
-
-	for (i = 0; i < block_size; i++) {
-		((uint8_t *) buf)[i] = w = pio_read_8(&dev->buffer[i]);
-	}
-
-	fibril_mutex_unlock(&dev_lock[disk_id]);
-	return EOK;
-}
-
-/** Write a block to the device. */
-static int gxe_bd_write_block(int disk_id, uint64_t ba, const void *buf)
-{
-	uint32_t status;
-	uint64_t byte_addr;
-	size_t i;
-
-	byte_addr = ba * block_size;
-
-	fibril_mutex_lock(&dev_lock[disk_id]);
-
-	for (i = 0; i < block_size; i++) {
-		pio_write_8(&dev->buffer[i], ((const uint8_t *) buf)[i]);
-	}
-
-	pio_write_32(&dev->offset_lo, (uint32_t) byte_addr);
-	pio_write_32(&dev->offset_hi, byte_addr >> 32);
-	pio_write_32(&dev->disk_id, disk_id);
-	pio_write_32(&dev->control, CTL_WRITE_START);
-
-	status = pio_read_32(&dev->status);
-	if (status == STATUS_FAILURE) {
-		fibril_mutex_unlock(&dev_lock[disk_id]);
-		return EIO;
-	}
-
-	fibril_mutex_unlock(&dev_lock[disk_id]);
-	return EOK;
-}
-
-/**
- * @}
- */
Index: uspace/srv/hid/input/Makefile
===================================================================
--- uspace/srv/hid/input/Makefile	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/srv/hid/input/Makefile	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -39,5 +39,4 @@
 	port/adb_mouse.c \
 	port/chardev.c \
-	port/gxemul.c \
 	port/msim.c \
 	port/niagara.c \
@@ -48,5 +47,4 @@
 	proto/mousedev.c \
 	ctl/apple.c \
-	ctl/gxe_fb.c \
 	ctl/kbdev.c \
 	ctl/pc.c \
Index: uspace/srv/hid/input/ctl/gxe_fb.c
===================================================================
--- uspace/srv/hid/input/ctl/gxe_fb.c	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ 	(revision )
@@ -1,248 +1,0 @@
-/*
- * Copyright (c) 2011 Jiri Svoboda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup kbd_ctl
- * @ingroup input
- * @{
- */
-/**
- * @file
- * @brief GXEmul framebuffer-mode keyboard controller driver.
- */
-
-#include <io/console.h>
-#include <io/keycode.h>
-#include "../stroke.h"
-#include "../gsp.h"
-#include "../kbd.h"
-#include "../kbd_port.h"
-#include "../kbd_ctl.h"
-
-static void gxe_fb_ctl_parse(sysarg_t);
-static int gxe_fb_ctl_init(kbd_dev_t *);
-static void gxe_fb_ctl_set_ind(kbd_dev_t *, unsigned int);
-
-kbd_ctl_ops_t gxe_fb_ctl = {
-	.parse = gxe_fb_ctl_parse,
-	.init = gxe_fb_ctl_init,
-	.set_ind = gxe_fb_ctl_set_ind
-};
-
-static kbd_dev_t *kbd_dev;
-
-/** Scancode parser */
-static gsp_t sp;
-
-/** Current parser state */
-static int ds;
-
-#include <stdio.h>
-
-static int seq_defs[] = {
-	/* Not shifted */
-
-	0,	KC_BACKTICK,	0x60, GSP_END,
-
-	0,	KC_1,		0x31, GSP_END,
-	0,	KC_2,		0x32, GSP_END,
-	0,	KC_3,		0x33, GSP_END,
-	0,	KC_4,		0x34, GSP_END,
-	0,	KC_5,		0x35, GSP_END,
-	0,	KC_6,		0x36, GSP_END,
-	0,	KC_7,		0x37, GSP_END,
-	0,	KC_8,		0x38, GSP_END,
-	0,	KC_9,		0x39, GSP_END,
-	0,	KC_0,		0x30, GSP_END,
-
-	0,	KC_MINUS,	0x2d, GSP_END,
-	0,	KC_EQUALS,	0x3d, GSP_END,
-	0,	KC_BACKSPACE,	0x08, GSP_END,
-
-	0,	KC_TAB,		0x09, GSP_END,
-
-	0,	KC_Q,		0x71, GSP_END,
-	0,	KC_W,		0x77, GSP_END,
-	0,	KC_E,		0x65, GSP_END,
-	0,	KC_R,		0x72, GSP_END,
-	0,	KC_T,		0x74, GSP_END,
-	0,	KC_Y,		0x79, GSP_END,
-	0,	KC_U,		0x75, GSP_END,
-	0,	KC_I,		0x69, GSP_END,
-	0,	KC_O,		0x6f, GSP_END,
-	0,	KC_P,		0x70, GSP_END,
-
-	0,	KC_LBRACKET,	0x5b, GSP_END,
-	0,	KC_RBRACKET,	0x5d, GSP_END,
-
-	0,	KC_A,		0x61, GSP_END,
-	0,	KC_S,		0x73, GSP_END,
-	0,	KC_D,		0x64, GSP_END,
-	0,	KC_F,		0x66, GSP_END,
-	0,	KC_G,		0x67, GSP_END,
-	0,	KC_H,		0x68, GSP_END,
-	0,	KC_J,		0x6a, GSP_END,
-	0,	KC_K,		0x6b, GSP_END,
-	0,	KC_L,		0x6c, GSP_END,
-
-	0,	KC_SEMICOLON,	0x3b, GSP_END,
-	0,	KC_QUOTE,	0x27, GSP_END,
-	0,	KC_BACKSLASH,	0x5c, GSP_END,
-
-	0,	KC_Z,		0x7a, GSP_END,
-	0,	KC_X,		0x78, GSP_END,
-	0,	KC_C,		0x63, GSP_END,
-	0,	KC_V,		0x76, GSP_END,
-	0,	KC_B,		0x62, GSP_END,
-	0,	KC_N,		0x6e, GSP_END,
-	0,	KC_M,		0x6d, GSP_END,
-
-	0,	KC_COMMA,	0x2c, GSP_END,
-	0,	KC_PERIOD,	0x2e, GSP_END,
-	0,	KC_SLASH,	0x2f, GSP_END,
-
-	/* Shifted */
-
-	KM_SHIFT,	KC_BACKTICK,	0x7e, GSP_END,
-
-	KM_SHIFT,	KC_1,		0x21, GSP_END,
-	KM_SHIFT,	KC_2,		0x40, GSP_END,
-	KM_SHIFT,	KC_3,		0x23, GSP_END,
-	KM_SHIFT,	KC_4,		0x24, GSP_END,
-	KM_SHIFT,	KC_5,		0x25, GSP_END,
-	KM_SHIFT,	KC_6,		0x5e, GSP_END,
-	KM_SHIFT,	KC_7,		0x26, GSP_END,
-	KM_SHIFT,	KC_8,		0x2a, GSP_END,
-	KM_SHIFT,	KC_9,		0x28, GSP_END,
-	KM_SHIFT,	KC_0,		0x29, GSP_END,
-
-	KM_SHIFT,	KC_MINUS,	0x5f, GSP_END,
-	KM_SHIFT,	KC_EQUALS,	0x2b, GSP_END,
-
-	KM_SHIFT,	KC_Q,		0x51, GSP_END,
-	KM_SHIFT,	KC_W,		0x57, GSP_END,
-	KM_SHIFT,	KC_E,		0x45, GSP_END,
-	KM_SHIFT,	KC_R,		0x52, GSP_END,
-	KM_SHIFT,	KC_T,		0x54, GSP_END,
-	KM_SHIFT,	KC_Y,		0x59, GSP_END,
-	KM_SHIFT,	KC_U,		0x55, GSP_END,
-	KM_SHIFT,	KC_I,		0x49, GSP_END,
-	KM_SHIFT,	KC_O,		0x4f, GSP_END,
-	KM_SHIFT,	KC_P,		0x50, GSP_END,
-
-	KM_SHIFT,	KC_LBRACKET,	0x7b, GSP_END,
-	KM_SHIFT,	KC_RBRACKET,	0x7d, GSP_END,
-
-	KM_SHIFT,	KC_A,		0x41, GSP_END,
-	KM_SHIFT,	KC_S,		0x53, GSP_END,
-	KM_SHIFT,	KC_D,		0x44, GSP_END,
-	KM_SHIFT,	KC_F,		0x46, GSP_END,
-	KM_SHIFT,	KC_G,		0x47, GSP_END,
-	KM_SHIFT,	KC_H,		0x48, GSP_END,
-	KM_SHIFT,	KC_J,		0x4a, GSP_END,
-	KM_SHIFT,	KC_K,		0x4b, GSP_END,
-	KM_SHIFT,	KC_L,		0x4c, GSP_END,
-
-	KM_SHIFT,	KC_SEMICOLON,	0x3a, GSP_END,
-	KM_SHIFT,	KC_QUOTE,	0x22, GSP_END,
-	KM_SHIFT,	KC_BACKSLASH,	0x7c, GSP_END,
-
-	KM_SHIFT,	KC_Z,		0x5a, GSP_END,
-	KM_SHIFT,	KC_X,		0x58, GSP_END,
-	KM_SHIFT,	KC_C,		0x43, GSP_END,
-	KM_SHIFT,	KC_V,		0x56, GSP_END,
-	KM_SHIFT,	KC_B,		0x42, GSP_END,
-	KM_SHIFT,	KC_N,		0x4e, GSP_END,
-	KM_SHIFT,	KC_M,		0x4d, GSP_END,
-
-	KM_SHIFT,	KC_COMMA,	0x3c, GSP_END,
-	KM_SHIFT,	KC_PERIOD,	0x3e, GSP_END,
-	KM_SHIFT,	KC_SLASH,	0x3f, GSP_END,
-
-	/* ... */
-
-	0,	KC_SPACE,	0x20, GSP_END,
-	0,	KC_ENTER,	0x0a, GSP_END,
-	0,	KC_ENTER,	0x0d, GSP_END,
-
-	0,	KC_ESCAPE,	0x1b, 0x1b, GSP_END,
-
-	0,	KC_F1,		0x1b, 0x5b, 0x4f, 0x50, GSP_END,
-	0,	KC_F2,		0x1b, 0x5b, 0x4f, 0x51, GSP_END,
-	0,	KC_F3,		0x1b, 0x5b, 0x4f, 0x52, GSP_END,
-	0,	KC_F4,		0x1b, 0x5b, 0x4f, 0x53, GSP_END,
-	0,	KC_F5,		0x1b, 0x5b, 0x31, 0x35, GSP_END,
-	0,	KC_F6,		0x1b, 0x5b, 0x31, 0x37, GSP_END,
-	0,	KC_F7,		0x1b, 0x5b, 0x31, 0x38, GSP_END,
-	0,	KC_F8,		0x1b, 0x5b, 0x31, 0x39, GSP_END,
-	0,	KC_F9,		0x1b, 0x5b, 0x32, 0x38, GSP_END,
-	0,	KC_F10,		0x1b, 0x5b, 0x32, 0x39, GSP_END,
-	0,	KC_F11,		0x1b, 0x5b, 0x32, 0x33, GSP_END,
-	0,	KC_F12,		0x1b, 0x5b, 0x32, 0x34, GSP_END,
-
-	0,	KC_INSERT,	0x1b, 0x5b, 0x32, 0x7e, GSP_END,
-	0,	KC_HOME,	0x1b, 0x5b, 0x48, GSP_END,
-	0,	KC_PAGE_UP,	0x1b, 0x5b, 0x35, 0x7e, GSP_END,
-	0,	KC_DELETE,	0x1b, 0x5b, 0x33, 0x7e, GSP_END,
-	0,	KC_END,		0x1b, 0x5b, 0x46, GSP_END,
-	0,	KC_PAGE_DOWN,	0x1b, 0x5b, 0x36, 0x7e, GSP_END,
-
-	0,	KC_UP,		0x1b, 0x5b, 0x41, GSP_END,
-	0,	KC_LEFT,	0x1b, 0x5b, 0x44, GSP_END,
-	0,	KC_DOWN,	0x1b, 0x5b, 0x42, GSP_END,
-	0,	KC_RIGHT,	0x1b, 0x5b, 0x43, GSP_END,
-
-	0,	0
-};
-
-static int gxe_fb_ctl_init(kbd_dev_t *kdev)
-{
-	kbd_dev = kdev;
-	ds = 0;
-
-	gsp_init(&sp);
-	return gsp_insert_defs(&sp, seq_defs);
-}
-
-static void gxe_fb_ctl_parse(sysarg_t scancode)
-{
-	unsigned mods, key;
-
-	ds = gsp_step(&sp, ds, scancode, &mods, &key);
-	if (key != 0) {
-		stroke_sim(kbd_dev, mods, key);
-	}
-}
-
-static void gxe_fb_ctl_set_ind(kbd_dev_t *kdev, unsigned mods)
-{
-	(void) mods;
-}
-
-/**
- * @}
- */ 
Index: uspace/srv/hid/input/input.c
===================================================================
--- uspace/srv/hid/input/input.c	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/srv/hid/input/input.c	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -440,10 +440,4 @@
 	kbd_add_dev(&msim_port, &stty_ctl);
 #endif
-#if (defined(MACHINE_lgxemul) || defined(MACHINE_bgxemul)) && defined(CONFIG_FB)
-	kbd_add_dev(&gxemul_port, &gxe_fb_ctl);
-#endif
-#if defined(MACHINE_lgxemul) || defined(MACHINE_bgxemul) && !defined(CONFIG_FB)
-	kbd_add_dev(&gxemul_port, &stty_ctl);
-#endif
 #if defined(UARCH_ppc32)
 	kbd_add_dev(&adb_port, &apple_ctl);
Index: uspace/srv/hid/input/kbd_ctl.h
===================================================================
--- uspace/srv/hid/input/kbd_ctl.h	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/srv/hid/input/kbd_ctl.h	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -49,5 +49,4 @@
 
 extern kbd_ctl_ops_t apple_ctl;
-extern kbd_ctl_ops_t gxe_fb_ctl;
 extern kbd_ctl_ops_t kbdev_ctl;
 extern kbd_ctl_ops_t pc_ctl;
Index: uspace/srv/hid/input/kbd_port.h
===================================================================
--- uspace/srv/hid/input/kbd_port.h	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/srv/hid/input/kbd_port.h	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -51,5 +51,4 @@
 extern kbd_port_ops_t adb_port;
 extern kbd_port_ops_t chardev_port;
-extern kbd_port_ops_t gxemul_port;
 extern kbd_port_ops_t msim_port;
 extern kbd_port_ops_t niagara_port;
Index: uspace/srv/hid/input/port/gxemul.c
===================================================================
--- uspace/srv/hid/input/port/gxemul.c	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ 	(revision )
@@ -1,131 +1,0 @@
-/*
- * Copyright (c) 2007 Michal Kebrt
- * Copyright (c) 2011 Jiri Svoboda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup kbd_port
- * @{
- * @ingroup  kbd
- */
-/** @file
- * @brief GXEmul keyboard port driver.
- */
-
-#include <async.h>
-#include <sysinfo.h>
-#include <ddi.h>
-#include <errno.h>
-#include "../kbd_port.h"
-#include "../kbd.h"
-
-static int gxemul_port_init(kbd_dev_t *);
-static void gxemul_port_yield(void);
-static void gxemul_port_reclaim(void);
-static void gxemul_port_write(uint8_t data);
-
-kbd_port_ops_t gxemul_port = {
-	.init = gxemul_port_init,
-	.yield = gxemul_port_yield,
-	.reclaim = gxemul_port_reclaim,
-	.write = gxemul_port_write
-};
-
-static kbd_dev_t *kbd_dev;
-
-static irq_pio_range_t gxemul_ranges[] = {
-	{
-		.base = 0,
-		.size = 1
-	}
-};
-
-static irq_cmd_t gxemul_cmds[] = {
-	{ 
-		.cmd = CMD_PIO_READ_8, 
-		.addr = (void *) 0, 	/* will be patched in run-time */
-		.dstarg = 2,
-	},
-	{
-		.cmd = CMD_ACCEPT
-	}
-};
-
-static irq_code_t gxemul_kbd = {
-	sizeof(gxemul_ranges) / sizeof(irq_pio_range_t),
-	gxemul_ranges,
-	sizeof(gxemul_cmds) / sizeof(irq_cmd_t),
-	gxemul_cmds
-};
-
-static void gxemul_irq_handler(ipc_callid_t iid, ipc_call_t *call);
-
-/** Initializes keyboard handler. */
-static int gxemul_port_init(kbd_dev_t *kdev)
-{
-	kbd_dev = kdev;
-	
-	sysarg_t addr;
-	if (sysinfo_get_value("kbd.address.physical", &addr) != EOK)
-		return -1;
-	
-	sysarg_t inr;
-	if (sysinfo_get_value("kbd.inr", &inr) != EOK)
-		return -1;
-	
-	async_set_interrupt_received(gxemul_irq_handler);
-	gxemul_ranges[0].base = addr;
-	gxemul_cmds[0].addr = (void *) addr;
-	irq_register(inr, device_assign_devno(), 0, &gxemul_kbd);
-	return 0;
-}
-
-static void gxemul_port_yield(void)
-{
-}
-
-static void gxemul_port_reclaim(void)
-{
-}
-
-static void gxemul_port_write(uint8_t data)
-{
-	(void) data;
-}
-
-/** Process data sent when a key is pressed.
- *
- * @param keybuffer Buffer of pressed keys.
- * @param call      IPC call.
- *
- */
-static void gxemul_irq_handler(ipc_callid_t iid, ipc_call_t *call)
-{
-	kbd_push_data(kbd_dev, IPC_GET_ARG2(*call));
-}
-
-/** @}
- */
Index: uspace/srv/net/tcp/conn.c
===================================================================
--- uspace/srv/net/tcp/conn.c	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/srv/net/tcp/conn.c	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -354,13 +354,19 @@
 {
 	log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_find_ref(%p)", sp);
-
+	
+	log_msg(LOG_DEFAULT, LVL_DEBUG2, "compare conn (f:(%x,%u), l:(%x,%u))",
+	    sp->foreign.addr.ipv4, sp->foreign.port,
+	    sp->local.addr.ipv4, sp->local.port);
+	
 	fibril_mutex_lock(&conn_list_lock);
-
+	
 	list_foreach(conn_list, link) {
 		tcp_conn_t *conn = list_get_instance(link, tcp_conn_t, link);
 		tcp_sockpair_t *csp = &conn->ident;
-		log_msg(LOG_DEFAULT, LVL_DEBUG2, "compare with conn (f:(%x,%u), l:(%x,%u))",
+		
+		log_msg(LOG_DEFAULT, LVL_DEBUG2, " - with (f:(%x,%u), l:(%x,%u))",
 		    csp->foreign.addr.ipv4, csp->foreign.port,
 		    csp->local.addr.ipv4, csp->local.port);
+		
 		if (tcp_sockpair_match(sp, csp)) {
 			tcp_conn_addref(conn);
@@ -369,5 +375,5 @@
 		}
 	}
-
+	
 	fibril_mutex_unlock(&conn_list_lock);
 	return NULL;
Index: uspace/srv/net/tcp/sock.c
===================================================================
--- uspace/srv/net/tcp/sock.c	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/srv/net/tcp/sock.c	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -203,36 +203,51 @@
 {
 	int rc;
-	struct sockaddr *addr;
-	size_t addr_len;
+	struct sockaddr_in *addr;
+	size_t addr_size;
 	socket_core_t *sock_core;
 	tcp_sockdata_t *socket;
-
+	
 	log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_sock_bind()");
 	log_msg(LOG_DEFAULT, LVL_DEBUG, " - async_data_write_accept");
-	rc = async_data_write_accept((void **) &addr, false, 0, 0, 0, &addr_len);
+	
+	addr = NULL;
+	
+	rc = async_data_write_accept((void **) &addr, false, 0, 0, 0, &addr_size);
 	if (rc != EOK) {
 		async_answer_0(callid, rc);
-		return;
-	}
-
+		goto out;
+	}
+	
+	if (addr_size != sizeof(struct sockaddr_in)) {
+		async_answer_0(callid, EINVAL);
+		goto out;
+	}
+	
 	log_msg(LOG_DEFAULT, LVL_DEBUG, " - call socket_bind");
 	rc = socket_bind(&client->sockets, &gsock, SOCKET_GET_SOCKET_ID(call),
-	    addr, addr_len, TCP_FREE_PORTS_START, TCP_FREE_PORTS_END,
+	    addr, addr_size, TCP_FREE_PORTS_START, TCP_FREE_PORTS_END,
 	    last_used_port);
 	if (rc != EOK) {
 		async_answer_0(callid, rc);
-		return;
-	}
-
+		goto out;
+	}
+	
 	log_msg(LOG_DEFAULT, LVL_DEBUG, " - call socket_cores_find");
 	sock_core = socket_cores_find(&client->sockets, SOCKET_GET_SOCKET_ID(call));
-	if (sock_core != NULL) {
-		socket = (tcp_sockdata_t *)sock_core->specific_data;
-		/* XXX Anything to do? */
-		(void) socket;
-	}
-
+	if (sock_core == NULL) {
+		async_answer_0(callid, ENOENT);
+		goto out;
+	}
+	
+	socket = (tcp_sockdata_t *)sock_core->specific_data;
+	/* XXX Anything to do? */
+	(void) socket;
+	
 	log_msg(LOG_DEFAULT, LVL_DEBUG, " - success");
 	async_answer_0(callid, EOK);
+	
+out:
+	if (addr != NULL)
+		free(addr);
 }
 
@@ -249,4 +264,5 @@
 	tcp_sock_lconn_t *lconn;
 	int i;
+	int rc;
 
 	log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_sock_listen()");
@@ -268,12 +284,24 @@
 		return;
 	}
-
-	socket = (tcp_sockdata_t *)sock_core->specific_data;
-
+	
+	if (sock_core->port <= 0) {
+		rc = socket_bind_free_port(&gsock, sock_core,
+		    TCP_FREE_PORTS_START, TCP_FREE_PORTS_END,
+		    last_used_port);
+		if (rc != EOK) {
+			async_answer_0(callid, rc);
+			return;
+		}
+		
+		last_used_port = sock_core->port;
+	}
+	
+	socket = (tcp_sockdata_t *) sock_core->specific_data;
+	
 	/*
 	 * Prepare @c backlog listening connections.
 	 */
 	fibril_mutex_lock(&socket->lock);
-
+	
 	socket->backlog = backlog;
 	socket->lconn = calloc(backlog, sizeof(tcp_conn_t *));
@@ -283,12 +311,12 @@
 		return;
 	}
-
+	
 	log_msg(LOG_DEFAULT, LVL_DEBUG, " - open connections");
-
+	
 	lsocket.addr.ipv4 = TCP_IPV4_ANY;
 	lsocket.port = sock_core->port;
 	fsocket.addr.ipv4 = TCP_IPV4_ANY;
 	fsocket.port = TCP_PORT_ANY;
-
+	
 	for (i = 0; i < backlog; i++) {
 
@@ -362,5 +390,5 @@
 			return;
 		}
-
+		
 		last_used_port = sock_core->port;
 	}
@@ -441,4 +469,16 @@
 		return;
 	}
+	
+	if (sock_core->port <= 0) {
+		rc = socket_bind_free_port(&gsock, sock_core,
+		    TCP_FREE_PORTS_START, TCP_FREE_PORTS_END,
+		    last_used_port);
+		if (rc != EOK) {
+			async_answer_0(callid, rc);
+			return;
+		}
+		
+		last_used_port = sock_core->port;
+	}
 
 	socket = (tcp_sockdata_t *)sock_core->specific_data;
Index: uspace/srv/net/udp/assoc.c
===================================================================
--- uspace/srv/net/udp/assoc.c	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/srv/net/udp/assoc.c	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -200,6 +200,7 @@
 /** Set local socket in association.
  *
- * @param assoc		Association
- * @param fsock		Foreign socket (deeply copied)
+ * @param assoc Association
+ * @param lsock Local socket (deeply copied)
+ *
  */
 void udp_assoc_set_local(udp_assoc_t *assoc, udp_sock_t *lsock)
@@ -208,4 +209,18 @@
 	fibril_mutex_lock(&assoc->lock);
 	assoc->ident.local = *lsock;
+	fibril_mutex_unlock(&assoc->lock);
+}
+
+/** Set local port in association.
+ *
+ * @param assoc Association
+ * @param lport Local port
+ *
+ */
+void udp_assoc_set_local_port(udp_assoc_t *assoc, uint16_t lport)
+{
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_local(%p, %" PRIu16 ")", assoc, lport);
+	fibril_mutex_lock(&assoc->lock);
+	assoc->ident.local.port = lport;
 	fibril_mutex_unlock(&assoc->lock);
 }
@@ -406,5 +421,4 @@
 }
 
-
 /**
  * @}
Index: uspace/srv/net/udp/assoc.h
===================================================================
--- uspace/srv/net/udp/assoc.h	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/srv/net/udp/assoc.h	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -47,4 +47,5 @@
 extern void udp_assoc_set_foreign(udp_assoc_t *, udp_sock_t *);
 extern void udp_assoc_set_local(udp_assoc_t *, udp_sock_t *);
+extern void udp_assoc_set_local_port(udp_assoc_t *, uint16_t);
 extern int udp_assoc_send(udp_assoc_t *, udp_sock_t *, udp_msg_t *);
 extern int udp_assoc_recv(udp_assoc_t *, udp_msg_t **, udp_sock_t *);
Index: uspace/srv/net/udp/sock.c
===================================================================
--- uspace/srv/net/udp/sock.c	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/srv/net/udp/sock.c	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -90,5 +90,5 @@
 	log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_notify_data(%d)", sock_core->socket_id);
 	async_exch_t *exch = async_exchange_begin(sock_core->sess);
-	async_msg_5(exch, NET_SOCKET_RECEIVED, (sysarg_t)sock_core->socket_id,
+	async_msg_5(exch, NET_SOCKET_RECEIVED, (sysarg_t) sock_core->socket_id,
 	    UDP_FRAGMENT_SIZE, 0, 0, 1);
 	async_exchange_end(exch);
@@ -177,5 +177,10 @@
 		goto out;
 	}
-
+	
+	if (addr_size != sizeof(struct sockaddr_in)) {
+		async_answer_0(callid, EINVAL);
+		goto out;
+	}
+	
 	log_msg(LOG_DEFAULT, LVL_DEBUG, " - call socket_bind");
 	rc = socket_bind(&client->sockets, &gsock, SOCKET_GET_SOCKET_ID(call),
@@ -186,10 +191,5 @@
 		goto out;
 	}
-
-	if (addr_size != sizeof(struct sockaddr_in)) {
-		async_answer_0(callid, EINVAL);
-		goto out;
-	}
-
+	
 	log_msg(LOG_DEFAULT, LVL_DEBUG, " - call socket_cores_find");
 	sock_core = socket_cores_find(&client->sockets, SOCKET_GET_SOCKET_ID(call));
@@ -249,25 +249,13 @@
 static void udp_sock_sendto(udp_client_t *client, ipc_callid_t callid, ipc_call_t call)
 {
-	int socket_id;
-	int fragments;
-	int index;
-	struct sockaddr_in *addr;
-	size_t addr_size;
-	socket_core_t *sock_core;
-	udp_sockdata_t *socket;
-	udp_sock_t fsock, *fsockp;
-	ipc_call_t answer;
-	ipc_callid_t wcallid;
-	size_t length;
-	uint8_t buffer[UDP_FRAGMENT_SIZE];
-	udp_error_t urc;
-	int rc;
-
 	log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_send()");
-
-	addr = NULL;
-
+	
+	struct sockaddr_in *addr = NULL;
+	udp_sock_t fsock;
+	udp_sock_t *fsock_ptr;
+	
 	if (IPC_GET_IMETHOD(call) == NET_SOCKET_SENDTO) {
-		rc = async_data_write_accept((void **) &addr, false,
+		size_t addr_size;
+		int rc = async_data_write_accept((void **) &addr, false,
 		    0, 0, 0, &addr_size);
 		if (rc != EOK) {
@@ -275,49 +263,63 @@
 			goto out;
 		}
-
+		
 		if (addr_size != sizeof(struct sockaddr_in)) {
 			async_answer_0(callid, EINVAL);
 			goto out;
 		}
-
+		
 		fsock.addr.ipv4 = uint32_t_be2host(addr->sin_addr.s_addr);
 		fsock.port = uint16_t_be2host(addr->sin_port);
-		fsockp = &fsock;
-	} else {
-		fsockp = NULL;
-	}
-
-	socket_id = SOCKET_GET_SOCKET_ID(call);
-	fragments = SOCKET_GET_DATA_FRAGMENTS(call);
+		fsock_ptr = &fsock;
+	} else
+		fsock_ptr = NULL;
+	
+	int socket_id = SOCKET_GET_SOCKET_ID(call);
+	
 	SOCKET_GET_FLAGS(call);
-
-	sock_core = socket_cores_find(&client->sockets, socket_id);
+	
+	socket_core_t *sock_core =
+	    socket_cores_find(&client->sockets, socket_id);
 	if (sock_core == NULL) {
 		async_answer_0(callid, ENOTSOCK);
 		goto out;
 	}
-
-	if (sock_core->port == 0) {
+	
+	udp_sockdata_t *socket =
+	    (udp_sockdata_t *) sock_core->specific_data;
+	
+	if (sock_core->port <= 0) {
 		/* Implicitly bind socket to port */
-		rc = socket_bind(&client->sockets, &gsock, SOCKET_GET_SOCKET_ID(call),
-		    addr, addr_size, UDP_FREE_PORTS_START, UDP_FREE_PORTS_END,
-		    last_used_port);
+		int rc = socket_bind_free_port(&gsock, sock_core,
+		    UDP_FREE_PORTS_START, UDP_FREE_PORTS_END, last_used_port);
 		if (rc != EOK) {
 			async_answer_0(callid, rc);
 			goto out;
 		}
-	}
-
-	socket = (udp_sockdata_t *)sock_core->specific_data;
+		
+		assert(sock_core->port > 0);
+		
+		udp_error_t urc = udp_uc_set_local_port(socket->assoc,
+		    sock_core->port);
+		
+		if (urc != UDP_EOK) {
+			// TODO: better error handling
+			async_answer_0(callid, EINTR);
+			goto out;
+		}
+		
+		last_used_port = sock_core->port;
+	}
+	
 	fibril_mutex_lock(&socket->lock);
-
+	
 	if (socket->assoc->ident.local.addr.ipv4 == UDP_IPV4_ANY) {
 		/* Determine local IP address */
 		inet_addr_t loc_addr, rem_addr;
-
-		rem_addr.ipv4 = fsockp ? fsock.addr.ipv4 :
+		
+		rem_addr.ipv4 = fsock_ptr ? fsock.addr.ipv4 :
 		    socket->assoc->ident.foreign.addr.ipv4;
-
-		rc = inet_get_srcaddr(&rem_addr, 0, &loc_addr);
+		
+		int rc = inet_get_srcaddr(&rem_addr, 0, &loc_addr);
 		if (rc != EOK) {
 			fibril_mutex_unlock(&socket->lock);
@@ -327,14 +329,17 @@
 			return;
 		}
-
+		
 		socket->assoc->ident.local.addr.ipv4 = loc_addr.ipv4;
 		log_msg(LOG_DEFAULT, LVL_DEBUG, "Local IP address is %x",
 		    socket->assoc->ident.local.addr.ipv4);
 	}
-
-
+	
 	assert(socket->assoc != NULL);
-
-	for (index = 0; index < fragments; index++) {
+	
+	int fragments = SOCKET_GET_DATA_FRAGMENTS(call);
+	for (int index = 0; index < fragments; index++) {
+		ipc_callid_t wcallid;
+		size_t length;
+		
 		if (!async_data_write_receive(&wcallid, &length)) {
 			fibril_mutex_unlock(&socket->lock);
@@ -342,9 +347,10 @@
 			goto out;
 		}
-
+		
 		if (length > UDP_FRAGMENT_SIZE)
 			length = UDP_FRAGMENT_SIZE;
-
-		rc = async_data_write_finalize(wcallid, buffer, length);
+		
+		uint8_t buffer[UDP_FRAGMENT_SIZE];
+		int rc = async_data_write_finalize(wcallid, buffer, length);
 		if (rc != EOK) {
 			fibril_mutex_unlock(&socket->lock);
@@ -352,24 +358,25 @@
 			goto out;
 		}
-
-		urc = udp_uc_send(socket->assoc, fsockp, buffer, length, 0);
-
+		
+		udp_error_t urc =
+		    udp_uc_send(socket->assoc, fsock_ptr, buffer, length, 0);
+		
 		switch (urc) {
 		case UDP_EOK:
 			rc = EOK;
 			break;
-/*		case TCP_ENOTEXIST:
-			rc = ENOTCONN;
-			break;
-		case TCP_ECLOSING:
-			rc = ENOTCONN;
-			break;
-		case TCP_ERESET:
-			rc = ECONNABORTED;
-			break;*/
+		case UDP_ENORES:
+			rc = ENOMEM;
+			break;
+		case UDP_EUNSPEC:
+			rc = EINVAL;
+			break;
+		case UDP_ENOROUTE:
+			rc = EIO;
+			break;
 		default:
 			assert(false);
 		}
-
+		
 		if (rc != EOK) {
 			fibril_mutex_unlock(&socket->lock);
@@ -378,4 +385,6 @@
 		}
 	}
+	
+	ipc_call_t answer;
 	
 	IPC_SET_ARG1(answer, 0);
@@ -526,22 +535,19 @@
 static void udp_sock_close(udp_client_t *client, ipc_callid_t callid, ipc_call_t call)
 {
-	int socket_id;
-	socket_core_t *sock_core;
-	udp_sockdata_t *socket;
-	int rc;
-
 	log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_sock_close()");
-	socket_id = SOCKET_GET_SOCKET_ID(call);
-
-	sock_core = socket_cores_find(&client->sockets, socket_id);
+	int socket_id = SOCKET_GET_SOCKET_ID(call);
+	
+	socket_core_t *sock_core =
+	    socket_cores_find(&client->sockets, socket_id);
 	if (sock_core == NULL) {
 		async_answer_0(callid, ENOTSOCK);
 		return;
 	}
-
-	socket = (udp_sockdata_t *)sock_core->specific_data;
+	
+	udp_sockdata_t *socket =
+	    (udp_sockdata_t *) sock_core->specific_data;
 	fibril_mutex_lock(&socket->lock);
-
-	rc = socket_destroy(NULL, socket_id, &client->sockets, &gsock,
+	
+	int rc = socket_destroy(NULL, socket_id, &client->sockets, &gsock,
 	    udp_free_sock_data);
 	if (rc != EOK) {
@@ -550,5 +556,5 @@
 		return;
 	}
-
+	
 	fibril_mutex_unlock(&socket->lock);
 	async_answer_0(callid, EOK);
@@ -583,12 +589,12 @@
 			    &sock->recv_buffer_lock);
 		}
-
+		
 		log_msg(LOG_DEFAULT, LVL_DEBUG, "[] call udp_uc_receive()");
 		urc = udp_uc_receive(sock->assoc, sock->recv_buffer,
 		    UDP_FRAGMENT_SIZE, &rcvd, &xflags, &sock->recv_fsock);
 		sock->recv_error = urc;
-
+		
 		udp_sock_notify_data(sock->sock_core);
-
+		
 		if (urc != UDP_EOK) {
 			fibril_condvar_broadcast(&sock->recv_buffer_cv);
@@ -596,7 +602,7 @@
 			break;
 		}
-
+		
 		log_msg(LOG_DEFAULT, LVL_DEBUG, "[] got data - broadcast recv_buffer_cv");
-
+		
 		sock->recv_buffer_used = rcvd;
 		fibril_mutex_unlock(&sock->recv_buffer_lock);
Index: uspace/srv/net/udp/ucall.c
===================================================================
--- uspace/srv/net/udp/ucall.c	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/srv/net/udp/ucall.c	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -68,6 +68,14 @@
 {
 	log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_set_local(%p, %p)", assoc, lsock);
+	
+	udp_assoc_set_local(assoc, lsock);
+	return UDP_EOK;
+}
 
-	udp_assoc_set_local(assoc, lsock);
+udp_error_t udp_uc_set_local_port(udp_assoc_t *assoc, uint16_t lport)
+{
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_set_local(%p, %" PRIu16 ")", assoc, lport);
+	
+	udp_assoc_set_local_port(assoc, lport);
 	return UDP_EOK;
 }
Index: uspace/srv/net/udp/ucall.h
===================================================================
--- uspace/srv/net/udp/ucall.h	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/srv/net/udp/ucall.h	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -42,4 +42,5 @@
 extern udp_error_t udp_uc_set_foreign(udp_assoc_t *, udp_sock_t *);
 extern udp_error_t udp_uc_set_local(udp_assoc_t *, udp_sock_t *);
+extern udp_error_t udp_uc_set_local_port(udp_assoc_t *, uint16_t);
 extern udp_error_t udp_uc_send(udp_assoc_t *, udp_sock_t *, void *, size_t,
     xflags_t);
Index: uspace/srv/net/udp/udp_type.h
===================================================================
--- uspace/srv/net/udp/udp_type.h	(revision b92a0ee0b9b93ef0d525013de4a657a5b969bae6)
+++ uspace/srv/net/udp/udp_type.h	(revision b183ce0a4ad17f84425bf237acca8fb1eea739ec)
@@ -66,5 +66,5 @@
 };
 
-enum tcp_port {
+enum udp_port {
 	UDP_PORT_ANY = 0
 };
