Index: boot/Makefile.common
===================================================================
--- boot/Makefile.common	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ boot/Makefile.common	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -106,6 +106,5 @@
 	$(USPACE_PATH)/srv/net/tl/tcp/tcp \
 	$(USPACE_PATH)/srv/net/net/net \
-	$(USPACE_PATH)/srv/devman/devman \
-	$(USPACE_PATH)/srv/drivers/root/root 
+	$(USPACE_PATH)/srv/devman/devman
 	
 RD_DRVS = \
Index: boot/arch/amd64/Makefile.inc
===================================================================
--- boot/arch/amd64/Makefile.inc	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ boot/arch/amd64/Makefile.inc	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -34,5 +34,4 @@
 RD_SRVS_NON_ESSENTIAL += \
 	$(USPACE_PATH)/srv/bd/ata_bd/ata_bd \
-	$(USPACE_PATH)/srv/hw/bus/pci/pci \
 	$(USPACE_PATH)/srv/hid/char_mouse/char_ms
 
Index: contrib/arch/hadlbppp.py
===================================================================
--- contrib/arch/hadlbppp.py	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ contrib/arch/hadlbppp.py	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -42,12 +42,12 @@
 	"Print usage syntax"
 	
-	print "%s <--bp|--ebp|--adl|--dot|--nop>+ <OUTPUT>" % prname
-	print
-	print "--bp   Dump original Behavior Protocols (dChecker, BPSlicer)"
-	print "--ebp  Dump Extended Behavior Protocols (bp2promela)"
-	print "--adl  Dump Architecture Description Language (modified SOFA ADL/CDL)"
-	print "--dot  Dump Dot architecture diagram (GraphViz)"
-	print "--nop  Do not dump anything (just input files syntax check)"
-	print
+	print("%s <--bp|--ebp|--adl|--dot|--nop>+ <OUTPUT>" % prname)
+	print()
+	print("--bp   Dump original Behavior Protocols (dChecker, BPSlicer)")
+	print("--ebp  Dump Extended Behavior Protocols (bp2promela)")
+	print("--adl  Dump Architecture Description Language (modified SOFA ADL/CDL)")
+	print("--dot  Dump Dot architecture diagram (GraphViz)")
+	print("--nop  Do not dump anything (just input files syntax check)")
+	print()
 
 def tabs(cnt):
@@ -163,7 +163,7 @@
 						result.append(tokens[i])
 				else:
-					print "%s: Syntax error in tentative statement" % name
+					print("%s: Syntax error in tentative statement" % name)
 			else:
-				print "%s: Expected '{' for tentative statement" % name
+				print("%s: Expected '{' for tentative statement" % name)
 		else:
 			result.append(tokens[i])
@@ -231,11 +231,11 @@
 								result.append(tokens[i])
 						else:
-							print "%s: Syntax error in alternative statement" % name
+							print("%s: Syntax error in alternative statement" % name)
 					else:
-						print "%s: Expected '{' for alternative statement body" % name
+						print("%s: Expected '{' for alternative statement body" % name)
 				else:
-					print "%s: At least one pattern and one replacement required for alternative statement" % name
+					print("%s: At least one pattern and one replacement required for alternative statement" % name)
 			else:
-				print "%s: Expected '(' for alternative statement head" % name
+				print("%s: Expected '(' for alternative statement head" % name)
 		else:
 			result.append(tokens[i])
@@ -269,5 +269,5 @@
 					result.append(tokens[i])
 			else:
-				print "%s: Unexpected end of protocol" % name
+				print("%s: Unexpected end of protocol" % name)
 		
 		i += 1
@@ -349,5 +349,5 @@
 		elif (token == ")"):
 			if (indent < base_indent):
-				print "%s: Too many parentheses" % name
+				print("%s: Too many parentheses" % name)
 			
 			indent -= 1
@@ -358,5 +358,5 @@
 		elif (token == "}"):
 			if (indent < base_indent):
-				print "%s: Too many parentheses" % name
+				print("%s: Too many parentheses" % name)
 			
 			indent -= 1
@@ -370,5 +370,5 @@
 	
 	if (indent > base_indent):
-		print "%s: Missing parentheses" % name
+		print("%s: Missing parentheses" % name)
 	
 	output = output.strip()
@@ -405,5 +405,5 @@
 			result.extend(inherited_protocols(supiface))
 		else:
-			print "%s: Extends unknown interface '%s'" % (iface['name'], iface['extends'])
+			print("%s: Extends unknown interface '%s'" % (iface['name'], iface['extends']))
 	
 	return result
@@ -459,13 +459,13 @@
 						protocols.append(proto)
 			else:
-				print "%s: Provided interface '%s' is undefined" % (frame['name'], provides['iface'])
+				print("%s: Provided interface '%s' is undefined" % (frame['name'], provides['iface']))
 	
 	if (opt_bp):
-		outf = file(outname, "w")
+		outf = open(outname, "w")
 		outf.write(parse_bp(outname, merge_bp(initialization, finalization, protocols), 0))
 		outf.close()
 	
 	if (opt_ebp):
-		outf = file(outname, "w")
+		outf = open(outname, "w")
 		outf.write(parse_ebp(frame['name'], outname, merge_bp(initialization, finalization, protocols), 0))
 		outf.close()
@@ -514,10 +514,10 @@
 	
 	if (opt_bp):
-		outf = file(outname, "w")
+		outf = open(outname, "w")
 		outf.write("NULL")
 		outf.close()
 	
 	if (opt_ebp):
-		outf = file(outname, "w")
+		outf = open(outname, "w")
 		outf.write("component null {\n\tbehavior {\n\t\tNULL\n\t}\n}")
 		outf.close()
@@ -587,5 +587,5 @@
 					insts.append({'var': "%s_%s" % (prefix, inst['var']), 'frame': subframe})
 				else:
-					print "%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type'])
+					print("%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']))
 	
 	if ('bind' in arch):
@@ -612,5 +612,5 @@
 	
 	if (arch is None):
-		print "Unable to find system architecture"
+		print("Unable to find system architecture")
 		return
 	
@@ -634,5 +634,5 @@
 					insts.append({'var': inst['var'], 'frame': subframe})
 				else:
-					print "%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type'])
+					print("%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']))
 	
 	if ('bind' in arch):
@@ -642,10 +642,10 @@
 	if ('delegate' in arch):
 		for delegate in arch['delegate']:
-			print "Unable to delegate interface in system architecture"
+			print("Unable to delegate interface in system architecture")
 			break
 	
 	if ('subsume' in arch):
 		for subsume in arch['subsume']:
-			print "Unable to subsume interface in system architecture"
+			print("Unable to subsume interface in system architecture")
 			break
 	
@@ -654,5 +654,5 @@
 	outname = os.path.join(outdir, "%s.archbp" % arch['name'])
 	if ((opt_bp) or (opt_ebp)):
-		outf = file(outname, "w")
+		outf = open(outname, "w")
 	else:
 		outf = None
@@ -709,5 +709,5 @@
 		
 		if (not os.path.isfile(path)):
-			print "%s: Unable to include file %s" % (inname, path)
+			print("%s: Unable to include file %s" % (inname, path))
 			return ""
 	else:
@@ -716,5 +716,5 @@
 		nested_root = root
 	
-	inf = file(path, "r")
+	inf = open(path, "r")
 	
 	raw = preproc_adl(inf.read(), inarg)
@@ -733,5 +733,5 @@
 		if (POST_INC in context):
 			if (token != "]"):
-				print "%s: Expected ]" % inname
+				print("%s: Expected ]" % inname)
 			
 			context.remove(POST_INC)
@@ -774,5 +774,5 @@
 			if (NULL in context):
 				if (token != ";"):
-					print "%s: Expected ';' in frame '%s'" % (inname, frame)
+					print("%s: Expected ';' in frame '%s'" % (inname, frame))
 				else:
 					output += "%s\n" % token
@@ -798,5 +798,5 @@
 						
 						if ('finalization' in frame_properties[frame]):
-							print "%s: Finalization protocol for frame '%s' already defined" % (inname, frame)
+							print("%s: Finalization protocol for frame '%s' already defined" % (inname, frame))
 						else:
 							frame_properties[frame]['finalization'] = bp
@@ -832,5 +832,5 @@
 						
 						if ('initialization' in frame_properties[frame]):
-							print "%s: Initialization protocol for frame '%s' already defined" % (inname, frame)
+							print("%s: Initialization protocol for frame '%s' already defined" % (inname, frame))
 						else:
 							frame_properties[frame]['initialization'] = bp
@@ -866,5 +866,5 @@
 						
 						if ('protocol' in frame_properties[frame]):
-							print "%s: Protocol for frame '%s' already defined" % (inname, frame)
+							print("%s: Protocol for frame '%s' already defined" % (inname, frame))
 						else:
 							frame_properties[frame]['protocol'] = bp
@@ -889,5 +889,5 @@
 					if (FIN in context):
 						if (token != ";"):
-							print "%s: Expected ';' in frame '%s'" % (inname, frame)
+							print("%s: Expected ';' in frame '%s'" % (inname, frame))
 						else:
 							output += "%s" % token
@@ -898,5 +898,5 @@
 					if (VAR in context):
 						if (not identifier(token)):
-							print "%s: Variable name expected in frame '%s'" % (inname, frame)
+							print("%s: Variable name expected in frame '%s'" % (inname, frame))
 						else:
 							if (not frame in frame_properties):
@@ -919,5 +919,5 @@
 					else:
 						if (not identifier(token)):
-							print "%s: Interface name expected in frame '%s'" % (inname, frame)
+							print("%s: Interface name expected in frame '%s'" % (inname, frame))
 						else:
 							arg0 = token
@@ -930,5 +930,5 @@
 					if (FIN in context):
 						if (token != ";"):
-							print "%s: Expected ';' in frame '%s'" % (inname, frame)
+							print("%s: Expected ';' in frame '%s'" % (inname, frame))
 						else:
 							output += "%s" % token
@@ -939,5 +939,5 @@
 					if (VAR in context):
 						if (not identifier(token)):
-							print "%s: Variable name expected in frame '%s'" % (inname, frame)
+							print("%s: Variable name expected in frame '%s'" % (inname, frame))
 						else:
 							if (not frame in frame_properties):
@@ -960,5 +960,5 @@
 					else:
 						if (not identifier(token)):
-							print "%s: Interface name expected in frame '%s'" % (inname, frame)
+							print("%s: Interface name expected in frame '%s'" % (inname, frame))
 						else:
 							arg0 = token
@@ -970,5 +970,5 @@
 				if (token == "}"):
 					if (indent != 2):
-						print "%s: Wrong number of parentheses in frame '%s'" % (inname, frame)
+						print("%s: Wrong number of parentheses in frame '%s'" % (inname, frame))
 					else:
 						indent = 0
@@ -1010,5 +1010,5 @@
 					continue
 				
-				print "%s: Unknown token '%s' in frame '%s'" % (inname, token, frame)
+				print("%s: Unknown token '%s' in frame '%s'" % (inname, token, frame))
 				continue
 			
@@ -1027,10 +1027,10 @@
 					continue
 				
-				print "%s: Unknown token '%s' in frame head '%s'" % (inname, token, frame)
+				print("%s: Unknown token '%s' in frame head '%s'" % (inname, token, frame))
 				
 				continue
 			
 			if (not identifier(token)):
-				print "%s: Expected frame name" % inname
+				print("%s: Expected frame name" % inname)
 			else:
 				frame = token
@@ -1050,5 +1050,5 @@
 			if (NULL in context):
 				if (token != ";"):
-					print "%s: Expected ';' in interface '%s'" % (inname, interface)
+					print("%s: Expected ';' in interface '%s'" % (inname, interface))
 				else:
 					output += "%s\n" % token
@@ -1074,5 +1074,5 @@
 						
 						if ('protocol' in iface_properties[interface]):
-							print "%s: Protocol for interface '%s' already defined" % (inname, interface)
+							print("%s: Protocol for interface '%s' already defined" % (inname, interface))
 						else:
 							iface_properties[interface]['protocol'] = bp
@@ -1094,5 +1094,5 @@
 					if (FIN in context):
 						if (token != ";"):
-							print "%s: Expected ';' in interface '%s'" % (inname, interface)
+							print("%s: Expected ';' in interface '%s'" % (inname, interface))
 						else:
 							output += "%s" % token
@@ -1124,5 +1124,5 @@
 					if (PAR_LEFT in context):
 						if (token != "("):
-							print "%s: Expected '(' in interface '%s'" % (inname, interface)
+							print("%s: Expected '(' in interface '%s'" % (inname, interface))
 						else:
 							output += "%s" % token
@@ -1133,5 +1133,5 @@
 					
 					if (not identifier(token)):
-						print "%s: Method identifier expected in interface '%s'" % (inname, interface)
+						print("%s: Method identifier expected in interface '%s'" % (inname, interface))
 					else:
 						output += "%s" % token
@@ -1142,5 +1142,5 @@
 				if (token == "}"):
 					if (indent != 2):
-						print "%s: Wrong number of parentheses in interface '%s'" % (inname, interface)
+						print("%s: Wrong number of parentheses in interface '%s'" % (inname, interface))
 					else:
 						indent = 0
@@ -1163,5 +1163,5 @@
 					continue
 				
-				print "%s: Unknown token '%s' in interface '%s'" % (inname, token, interface)
+				print("%s: Unknown token '%s' in interface '%s'" % (inname, token, interface))
 				continue
 			
@@ -1183,10 +1183,10 @@
 						continue
 						
-					print "%s: Expected '{' or ';' in interface head '%s'" % (inname, interface)
+					print("%s: Expected '{' or ';' in interface head '%s'" % (inname, interface))
 					continue
 				
 				if (EXTENDS in context):
 					if (not identifier(token)):
-						print "%s: Expected inherited interface name in interface head '%s'" % (inname, interface)
+						print("%s: Expected inherited interface name in interface head '%s'" % (inname, interface))
 					else:
 						output += "%s " % token
@@ -1218,9 +1218,9 @@
 					continue
 				
-				print "%s: Expected 'extends', '{' or ';' in interface head '%s'" % (inname, interface)
+				print("%s: Expected 'extends', '{' or ';' in interface head '%s'" % (inname, interface))
 				continue
 			
 			if (not identifier(token)):
-				print "%s: Expected interface name" % inname
+				print("%s: Expected interface name" % inname)
 			else:
 				interface = token
@@ -1240,5 +1240,5 @@
 			if (NULL in context):
 				if (token != ";"):
-					print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
+					print("%s: Expected ';' in architecture '%s'" % (inname, architecture))
 				else:
 					output += "%s\n" % token
@@ -1254,5 +1254,5 @@
 					if (FIN in context):
 						if (token != ";"):
-							print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
+							print("%s: Expected ';' in architecture '%s'" % (inname, architecture))
 						else:
 							output += "%s" % token
@@ -1264,5 +1264,5 @@
 					if (VAR in context):
 						if (not descriptor(token)):
-							print "%s: Expected interface descriptor in architecture '%s'" % (inname, architecture)
+							print("%s: Expected interface descriptor in architecture '%s'" % (inname, architecture))
 						else:
 							if (not architecture in arch_properties):
@@ -1283,5 +1283,5 @@
 					if (TO in context):
 						if (token != "to"):
-							print "%s: Expected 'to' in architecture '%s'" % (inname, architecture)
+							print("%s: Expected 'to' in architecture '%s'" % (inname, architecture))
 						else:
 							output += "%s " % token
@@ -1292,5 +1292,5 @@
 					
 					if (not identifier(token)):
-						print "%s: Expected interface name in architecture '%s'" % (inname, architecture)
+						print("%s: Expected interface name in architecture '%s'" % (inname, architecture))
 					else:
 						output += "%s " % token
@@ -1303,5 +1303,5 @@
 					if (FIN in context):
 						if (token != ";"):
-							print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
+							print("%s: Expected ';' in architecture '%s'" % (inname, architecture))
 						else:
 							output += "%s" % token
@@ -1313,5 +1313,5 @@
 					if (VAR in context):
 						if (not identifier(token)):
-							print "%s: Expected interface name in architecture '%s'" % (inname, architecture)
+							print("%s: Expected interface name in architecture '%s'" % (inname, architecture))
 						else:
 							if (not architecture in arch_properties):
@@ -1332,5 +1332,5 @@
 					if (TO in context):
 						if (token != "to"):
-							print "%s: Expected 'to' in architecture '%s'" % (inname, architecture)
+							print("%s: Expected 'to' in architecture '%s'" % (inname, architecture))
 						else:
 							output += "%s " % token
@@ -1341,5 +1341,5 @@
 					
 					if (not descriptor(token)):
-						print "%s: Expected interface descriptor in architecture '%s'" % (inname, architecture)
+						print("%s: Expected interface descriptor in architecture '%s'" % (inname, architecture))
 					else:
 						output += "%s " % token
@@ -1352,5 +1352,5 @@
 					if (FIN in context):
 						if (token != ";"):
-							print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
+							print("%s: Expected ';' in architecture '%s'" % (inname, architecture))
 						else:
 							output += "%s" % token
@@ -1362,5 +1362,5 @@
 					if (VAR in context):
 						if (not descriptor(token)):
-							print "%s: Expected second interface descriptor in architecture '%s'" % (inname, architecture)
+							print("%s: Expected second interface descriptor in architecture '%s'" % (inname, architecture))
 						else:
 							if (not architecture in arch_properties):
@@ -1381,5 +1381,5 @@
 					if (TO in context):
 						if (token != "to"):
-							print "%s: Expected 'to' in architecture '%s'" % (inname, architecture)
+							print("%s: Expected 'to' in architecture '%s'" % (inname, architecture))
 						else:
 							output += "%s " % token
@@ -1390,5 +1390,5 @@
 					
 					if (not descriptor(token)):
-						print "%s: Expected interface descriptor in architecture '%s'" % (inname, architecture)
+						print("%s: Expected interface descriptor in architecture '%s'" % (inname, architecture))
 					else:
 						output += "%s " % token
@@ -1401,5 +1401,5 @@
 					if (FIN in context):
 						if (token != ";"):
-							print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
+							print("%s: Expected ';' in architecture '%s'" % (inname, architecture))
 						else:
 							output += "%s" % token
@@ -1411,5 +1411,5 @@
 					if (VAR in context):
 						if (not identifier(token)):
-							print "%s: Expected instance name in architecture '%s'" % (inname, architecture)
+							print("%s: Expected instance name in architecture '%s'" % (inname, architecture))
 						else:
 							if (not architecture in arch_properties):
@@ -1429,5 +1429,5 @@
 					
 					if (not identifier(token)):
-						print "%s: Expected frame/architecture type in architecture '%s'" % (inname, architecture)
+						print("%s: Expected frame/architecture type in architecture '%s'" % (inname, architecture))
 					else:
 						output += "%s " % token
@@ -1439,5 +1439,5 @@
 				if (token == "}"):
 					if (indent != 1):
-						print "%s: Wrong number of parentheses in architecture '%s'" % (inname, architecture)
+						print("%s: Wrong number of parentheses in architecture '%s'" % (inname, architecture))
 					else:
 						indent -= 1
@@ -1468,5 +1468,5 @@
 					continue
 				
-				print "%s: Unknown token '%s' in architecture '%s'" % (inname, token, architecture)
+				print("%s: Unknown token '%s' in architecture '%s'" % (inname, token, architecture))
 				continue
 			
@@ -1487,5 +1487,5 @@
 				
 				if (not word(token)):
-					print "%s: Expected word in architecture head '%s'" % (inname, architecture)
+					print("%s: Expected word in architecture head '%s'" % (inname, architecture))
 				else:
 					output += "%s " % token
@@ -1494,5 +1494,5 @@
 			
 			if (not identifier(token)):
-				print "%s: Expected architecture name" % inname
+				print("%s: Expected architecture name" % inname)
 			else:
 				architecture = token
@@ -1514,5 +1514,5 @@
 		if (SYSTEM in context):
 			if (token != "architecture"):
-				print "%s: Expected 'architecture'" % inname
+				print("%s: Expected 'architecture'" % inname)
 			else:
 				output += "%s " % token
@@ -1541,5 +1541,5 @@
 			continue
 		
-		print "%s: Unknown token '%s'" % (inname, token)
+		print("%s: Unknown token '%s'" % (inname, token))
 	
 	inf.close()
@@ -1575,5 +1575,5 @@
 	
 	if ((output != "") and (opt_adl)):
-		outf = file(outname, "w")
+		outf = open(outname, "w")
 		outf.write(output)
 		outf.close()
@@ -1633,5 +1633,5 @@
 					merge_dot_frame("%s_%s" % (prefix, inst['var']), inst['var'], subframe, outf, indent + 1)
 				else:
-					print "%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type'])
+					print("%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']))
 	
 	if ('bind' in arch):
@@ -1728,10 +1728,10 @@
 	
 	if (arch is None):
-		print "Unable to find system architecture"
+		print("Unable to find system architecture")
 		return
 	
 	if (opt_dot):
 		outname = os.path.join(outdir, "%s.dot" % arch['name'])
-		outf = file(outname, "w")
+		outf = open(outname, "w")
 		
 		outf.write("digraph {\n")
@@ -1752,5 +1752,5 @@
 						merge_dot_frame("%s" % inst['var'], inst['var'], subframe, outf, 1)
 					else:
-						print "%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type'])
+						print("%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']))
 		
 		if ('bind' in arch):
@@ -1784,10 +1784,10 @@
 		if ('delegate' in arch):
 			for delegate in arch['delegate']:
-				print "Unable to delegate interface in system architecture"
+				print("Unable to delegate interface in system architecture")
 				break
 		
 		if ('subsume' in arch):
 			for subsume in arch['subsume']:
-				print "Unable to subsume interface in system architecture"
+				print("Unable to subsume interface in system architecture")
 				break
 		
@@ -1826,14 +1826,14 @@
 			pass
 		else:
-			print "Error: Unknown command line option '%s'" % arg
+			print("Error: Unknown command line option '%s'" % arg)
 			return
 	
 	if ((opt_bp) and (opt_ebp)):
-		print "Error: Cannot dump both original Behavior Protocols and Extended Behavior Protocols"
+		print("Error: Cannot dump both original Behavior Protocols and Extended Behavior Protocols")
 		return
 	
 	path = os.path.abspath(sys.argv[-1])
 	if (not os.path.isdir(path)):
-		print "Error: <OUTPUT> is not a directory"
+		print("Error: <OUTPUT> is not a directory")
 		return
 	
Index: kernel/arch/abs32le/include/interrupt.h
===================================================================
--- kernel/arch/abs32le/include/interrupt.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ kernel/arch/abs32le/include/interrupt.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -37,6 +37,5 @@
 
 #include <typedefs.h>
-#include <verify.h>
-#include <trace.h>
+#include <arch/istate.h>
 
 #define IVT_ITEMS  0
@@ -45,48 +44,4 @@
 #define VECTOR_TLB_SHOOTDOWN_IPI  0
 
-/*
- * On real hardware this stores the registers which
- * need to be preserved during interupts.
- */
-typedef struct istate {
-	uintptr_t ip;
-	uintptr_t fp;
-	uint32_t stack[];
-} istate_t;
-
-NO_TRACE static inline int istate_from_uspace(istate_t *istate)
-    REQUIRES_EXTENT_MUTABLE(istate)
-{
-	/* On real hardware this checks whether the interrupted
-	   context originated from user space. */
-	
-	return !(istate->ip & 0x80000000);
-}
-
-NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
-    uintptr_t retaddr)
-    WRITES(&istate->ip)
-{
-	/* On real hardware this sets the instruction pointer. */
-	
-	istate->ip = retaddr;
-}
-
-NO_TRACE static inline unative_t istate_get_pc(istate_t *istate)
-    REQUIRES_EXTENT_MUTABLE(istate)
-{
-	/* On real hardware this returns the instruction pointer. */
-	
-	return istate->ip;
-}
-
-NO_TRACE static inline unative_t istate_get_fp(istate_t *istate)
-    REQUIRES_EXTENT_MUTABLE(istate)
-{
-	/* On real hardware this returns the frame pointer. */
-	
-	return istate->fp;
-}
-
 #endif
 
Index: kernel/arch/abs32le/include/istate.h
===================================================================
--- kernel/arch/abs32le/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
+++ kernel/arch/abs32le/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2010 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup abs32leinterrupt
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_abs32le_ISTATE_H_
+#define KERN_abs32le_ISTATE_H_
+
+#ifdef KERNEL
+#include <typedefs.h>
+#include <verify.h>
+#include <trace.h>
+#else
+#include <sys/types.h>
+#define NO_TRACE
+#define REQUIRES_EXTENT_MUTABLE(arg)
+#define WRITES(arg)
+#endif
+
+/*
+ * On real hardware this stores the registers which
+ * need to be preserved during interupts.
+ */
+typedef struct istate {
+	uintptr_t ip;
+	uintptr_t fp;
+	uint32_t stack[];
+} istate_t;
+
+NO_TRACE static inline int istate_from_uspace(istate_t *istate)
+    REQUIRES_EXTENT_MUTABLE(istate)
+{
+	/* On real hardware this checks whether the interrupted
+	   context originated from user space. */
+	
+	return !(istate->ip & 0x80000000);
+}
+
+NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
+    uintptr_t retaddr)
+    WRITES(&istate->ip)
+{
+	/* On real hardware this sets the instruction pointer. */
+	
+	istate->ip = retaddr;
+}
+
+NO_TRACE static inline uintptr_t istate_get_pc(istate_t *istate)
+    REQUIRES_EXTENT_MUTABLE(istate)
+{
+	/* On real hardware this returns the instruction pointer. */
+	
+	return istate->ip;
+}
+
+NO_TRACE static inline uintptr_t istate_get_fp(istate_t *istate)
+    REQUIRES_EXTENT_MUTABLE(istate)
+{
+	/* On real hardware this returns the frame pointer. */
+	
+	return istate->fp;
+}
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/include/interrupt.h
===================================================================
--- kernel/arch/amd64/include/interrupt.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ kernel/arch/amd64/include/interrupt.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -37,6 +37,6 @@
 
 #include <typedefs.h>
+#include <arch/istate.h>
 #include <arch/pm.h>
-#include <trace.h>
 
 #define IVT_ITEMS  IDT_ITEMS
@@ -71,54 +71,4 @@
 #define VECTOR_DEBUG_IPI          (IVT_FREEBASE + 2)
 
-/** This is passed to interrupt handlers */
-typedef struct istate {
-	uint64_t rax;
-	uint64_t rbx;
-	uint64_t rcx;
-	uint64_t rdx;
-	uint64_t rsi;
-	uint64_t rdi;
-	uint64_t rbp;
-	uint64_t r8;
-	uint64_t r9;
-	uint64_t r10;
-	uint64_t r11;
-	uint64_t r12;
-	uint64_t r13;
-	uint64_t r14;
-	uint64_t r15;
-	uint64_t alignment;	/* align rbp_frame on multiple of 16 */
-	uint64_t rbp_frame;	/* imitation of frame pointer linkage */
-	uint64_t rip_frame;	/* imitation of return address linkage */
-	uint64_t error_word;	/* real or fake error word */
-	uint64_t rip;
-	uint64_t cs;
-	uint64_t rflags;
-	uint64_t rsp;		/* only if istate_t is from uspace */
-	uint64_t ss;		/* only if istate_t is from uspace */
-} istate_t;
-
-/** Return true if exception happened while in userspace */
-NO_TRACE static inline int istate_from_uspace(istate_t *istate)
-{
-	return !(istate->rip & 0x8000000000000000);
-}
-
-NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
-    uintptr_t retaddr)
-{
-	istate->rip = retaddr;
-}
-
-NO_TRACE static inline unative_t istate_get_pc(istate_t *istate)
-{
-	return istate->rip;
-}
-
-NO_TRACE static inline unative_t istate_get_fp(istate_t *istate)
-{
-	return istate->rbp;
-}
-
 extern void (* disable_irqs_function)(uint16_t);
 extern void (* enable_irqs_function)(uint16_t);
Index: kernel/arch/amd64/include/istate.h
===================================================================
--- kernel/arch/amd64/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
+++ kernel/arch/amd64/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2001-2004 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.
+ */
+
+/** @addtogroup amd64interrupt
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_amd64_ISTATE_H_
+#define KERN_amd64_ISTATE_H_
+
+#ifdef KERNEL
+#include <typedefs.h>
+#include <trace.h>
+#else
+#include <sys/types.h>
+#define NO_TRACE
+#endif
+
+/** This is passed to interrupt handlers */
+typedef struct istate {
+	uint64_t rax;
+	uint64_t rbx;
+	uint64_t rcx;
+	uint64_t rdx;
+	uint64_t rsi;
+	uint64_t rdi;
+	uint64_t rbp;
+	uint64_t r8;
+	uint64_t r9;
+	uint64_t r10;
+	uint64_t r11;
+	uint64_t r12;
+	uint64_t r13;
+	uint64_t r14;
+	uint64_t r15;
+	uint64_t alignment;	/* align rbp_frame on multiple of 16 */
+	uint64_t rbp_frame;	/* imitation of frame pointer linkage */
+	uint64_t rip_frame;	/* imitation of return address linkage */
+	uint64_t error_word;	/* real or fake error word */
+	uint64_t rip;
+	uint64_t cs;
+	uint64_t rflags;
+	uint64_t rsp;		/* only if istate_t is from uspace */
+	uint64_t ss;		/* only if istate_t is from uspace */
+} istate_t;
+
+/** Return true if exception happened while in userspace */
+NO_TRACE static inline int istate_from_uspace(istate_t *istate)
+{
+	return !(istate->rip & 0x8000000000000000);
+}
+
+NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
+    uintptr_t retaddr)
+{
+	istate->rip = retaddr;
+}
+
+NO_TRACE static inline uintptr_t istate_get_pc(istate_t *istate)
+{
+	return istate->rip;
+}
+
+NO_TRACE static inline uintptr_t istate_get_fp(istate_t *istate)
+{
+	return istate->rbp;
+}
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/amd64/src/asm.S
===================================================================
--- kernel/arch/amd64/src/asm.S	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ kernel/arch/amd64/src/asm.S	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -95,5 +95,5 @@
 memcpy_from_uspace_failover_address:
 memcpy_to_uspace_failover_address:
-	xorq %rax, %rax         /* return 0, failure */
+	xorl %eax, %eax         /* return 0, failure */
 	ret
 
@@ -143,5 +143,5 @@
 
 set_efer_flag:
-	movq $0xc0000080, %rcx
+	movl $0xc0000080, %ecx
 	rdmsr
 	btsl %edi, %eax
@@ -150,5 +150,5 @@
 
 read_efer_flag:
-	movq $0xc0000080, %rcx
+	movl $0xc0000080, %ecx
 	rdmsr
 	ret
@@ -243,5 +243,5 @@
 	 * Stop stack traces here if we came from userspace.
 	 */
-	xorq %rdx, %rdx
+	xorl %edx, %edx
 	cmpq $(GDT_SELECTOR(KTEXT_DES)), ISTATE_OFFSET_CS(%rsp)
 	cmovnzq %rdx, %rbp
@@ -386,4 +386,16 @@
 	movq ISTATE_OFFSET_RSP(%rsp), %rsp
 
+	/*
+	 * Clear the rest of the scratch registers to prevent information leak.
+	 * The 32-bit XOR on the low GPRs actually clears the entire 64-bit
+	 * register and the instruction is shorter.
+	 */
+	xorl %edx, %edx
+	xorl %esi, %esi
+	xorl %edi, %edi
+	xorq %r8, %r8
+	xorq %r9, %r9
+	xorq %r10, %r10
+
 	sysretq
 
@@ -413,5 +425,5 @@
 	movq %rdi, %rsi
 	movq $(PA2KA(0xb8000)), %rdi  /* base of EGA text mode memory */
-	xorq %rax, %rax
+	xorl %eax, %eax
 	
 	/* Read bits 8 - 15 of the cursor address */
@@ -493,10 +505,10 @@
 		movq $(PA2KA(0xb80a0)), %rsi
 		movq $(PA2KA(0xb8000)), %rdi
-		movq $480, %rcx
+		movl $480, %ecx
 		rep movsq
 		
 		/* Clear the 24th row */
-		xorq %rax, %rax
-		movq $20, %rcx
+		xorl %eax, %eax
+		movl $20, %ecx
 		rep stosq
 		
Index: kernel/arch/amd64/src/boot/boot.S
===================================================================
--- kernel/arch/amd64/src/boot/boot.S	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ kernel/arch/amd64/src/boot/boot.S	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -516,10 +516,10 @@
 		movq $(PA2KA(0xb80a0)), %rsi
 		movq $(PA2KA(0xb8000)), %rdi
-		movq $480, %rcx
+		movl $480, %ecx
 		rep movsq
 		
 		/* Clear the 24th row */
-		xorq %rax, %rax
-		movq $20, %rcx
+		xorl %eax, %eax
+		movl $20, %ecx
 		rep stosq
 		
Index: kernel/arch/amd64/src/context.S
===================================================================
--- kernel/arch/amd64/src/context.S	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ kernel/arch/amd64/src/context.S	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -45,6 +45,6 @@
 	CONTEXT_SAVE_ARCH_CORE %rdi %rdx
 	
-	xorq %rax, %rax       # context_save returns 1
-	incq %rax
+	xorl %eax, %eax       # context_save returns 1
+	incl %eax
 	ret
 
@@ -60,4 +60,4 @@
 	movq %rdx, (%rsp)
 	
-	xorq %rax, %rax       # context_restore returns 0
+	xorl %eax, %eax       # context_restore returns 0
 	ret
Index: kernel/arch/arm32/include/exception.h
===================================================================
--- kernel/arch/arm32/include/exception.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ kernel/arch/arm32/include/exception.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -39,6 +39,5 @@
 
 #include <typedefs.h>
-#include <arch/regutils.h>
-#include <trace.h>
+#include <arch/istate.h>
 
 /** If defined, forces using of high exception vectors. */
@@ -85,56 +84,4 @@
 extern uintptr_t exc_stack;
 
-/** Struct representing CPU state saved when an exception occurs. */
-typedef struct istate {
-	uint32_t spsr;
-	uint32_t sp;
-	uint32_t lr;
-	
-	uint32_t r0;
-	uint32_t r1;
-	uint32_t r2;
-	uint32_t r3;
-	uint32_t r4;
-	uint32_t r5;
-	uint32_t r6;
-	uint32_t r7;
-	uint32_t r8;
-	uint32_t r9;
-	uint32_t r10;
-	uint32_t fp;
-	uint32_t r12;
-	
-	uint32_t pc;
-} istate_t;
-
-/** Set Program Counter member of given istate structure.
- *
- * @param istate  istate structure
- * @param retaddr new value of istate's PC member
- *
- */
-NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
-    uintptr_t retaddr)
-{
-	istate->pc = retaddr;
-}
-
-/** Return true if exception happened while in userspace. */
-NO_TRACE static inline int istate_from_uspace(istate_t *istate)
-{
-	return (istate->spsr & STATUS_REG_MODE_MASK) == USER_MODE;
-}
-
-/** Return Program Counter member of given istate structure. */
-NO_TRACE static inline unative_t istate_get_pc(istate_t *istate)
-{
-	return istate->pc;
-}
-
-NO_TRACE static inline unative_t istate_get_fp(istate_t *istate)
-{
-	return istate->fp;
-}
-
 extern void install_exception_handlers(void);
 extern void exception_init(void);
Index: kernel/arch/arm32/include/istate.h
===================================================================
--- kernel/arch/arm32/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
+++ kernel/arch/arm32/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2007 Michal Kebrt, Petr Stepan
+ *
+ * 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 arm32interrupt
+ * @{
+ */
+
+#ifndef KERN_arm32_ISTATE_H_
+#define KERN_arm32_ISTATE_H_
+
+#include <arch/regutils.h>
+
+#ifdef KERNEL
+#include <typedefs.h>
+#include <trace.h>
+#else
+#include <sys/types.h>
+#define NO_TRACE
+#endif
+
+/** Struct representing CPU state saved when an exception occurs. */
+typedef struct istate {
+	uint32_t spsr;
+	uint32_t sp;
+	uint32_t lr;
+	
+	uint32_t r0;
+	uint32_t r1;
+	uint32_t r2;
+	uint32_t r3;
+	uint32_t r4;
+	uint32_t r5;
+	uint32_t r6;
+	uint32_t r7;
+	uint32_t r8;
+	uint32_t r9;
+	uint32_t r10;
+	uint32_t fp;
+	uint32_t r12;
+	
+	uint32_t pc;
+} istate_t;
+
+/** Set Program Counter member of given istate structure.
+ *
+ * @param istate  istate structure
+ * @param retaddr new value of istate's PC member
+ *
+ */
+NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
+    uintptr_t retaddr)
+{
+	istate->pc = retaddr;
+}
+
+/** Return true if exception happened while in userspace. */
+NO_TRACE static inline int istate_from_uspace(istate_t *istate)
+{
+	return (istate->spsr & STATUS_REG_MODE_MASK) == USER_MODE;
+}
+
+/** Return Program Counter member of given istate structure. */
+NO_TRACE static inline uintptr_t istate_get_pc(istate_t *istate)
+{
+	return istate->pc;
+}
+
+NO_TRACE static inline uintptr_t istate_get_fp(istate_t *istate)
+{
+	return istate->fp;
+}
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ia32/include/interrupt.h
===================================================================
--- kernel/arch/ia32/include/interrupt.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ kernel/arch/ia32/include/interrupt.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -37,6 +37,6 @@
 
 #include <typedefs.h>
+#include <arch/istate.h>
 #include <arch/pm.h>
-#include <trace.h>
 
 #define IVT_ITEMS  IDT_ITEMS
@@ -71,56 +71,4 @@
 #define VECTOR_DEBUG_IPI          (IVT_FREEBASE + 2)
 
-typedef struct istate {
-	/*
-	 * The strange order of the GPRs is given by the requirement to use the
-	 * istate structure for both regular interrupts and exceptions as well
-	 * as for syscall handlers which use this order as an optimization.
-	 */
-	uint32_t edx;
-	uint32_t ecx;
-	uint32_t ebx;
-	uint32_t esi;
-	uint32_t edi;
-	uint32_t ebp;
-	uint32_t eax;
-	
-	uint32_t ebp_frame;  /* imitation of frame pointer linkage */
-	uint32_t eip_frame;  /* imitation of return address linkage */
-	
-	uint32_t gs;
-	uint32_t fs;
-	uint32_t es;
-	uint32_t ds;
-	
-	uint32_t error_word;  /* real or fake error word */
-	uint32_t eip;
-	uint32_t cs;
-	uint32_t eflags;
-	uint32_t esp;         /* only if istate_t is from uspace */
-	uint32_t ss;          /* only if istate_t is from uspace */
-} istate_t;
-
-/** Return true if exception happened while in userspace */
-NO_TRACE static inline int istate_from_uspace(istate_t *istate)
-{
-	return !(istate->eip & 0x80000000);
-}
-
-NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
-    uintptr_t retaddr)
-{
-	istate->eip = retaddr;
-}
-
-NO_TRACE static inline unative_t istate_get_pc(istate_t *istate)
-{
-	return istate->eip;
-}
-
-NO_TRACE static inline unative_t istate_get_fp(istate_t *istate)
-{
-	return istate->ebp;
-}
-
 extern void (* disable_irqs_function)(uint16_t);
 extern void (* enable_irqs_function)(uint16_t);
Index: kernel/arch/ia32/include/istate.h
===================================================================
--- kernel/arch/ia32/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
+++ kernel/arch/ia32/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2001-2004 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.
+ */
+
+/** @addtogroup ia32interrupt
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_ia32_ISTATE_H_
+#define KERN_ia32_ISTATE_H_
+
+#ifdef KERNEL
+#include <typedefs.h>
+#include <trace.h>
+#else
+#include <sys/types.h>
+#define NO_TRACE
+#endif
+
+typedef struct istate {
+	/*
+	 * The strange order of the GPRs is given by the requirement to use the
+	 * istate structure for both regular interrupts and exceptions as well
+	 * as for syscall handlers which use this order as an optimization.
+	 */
+	uint32_t edx;
+	uint32_t ecx;
+	uint32_t ebx;
+	uint32_t esi;
+	uint32_t edi;
+	uint32_t ebp;
+	uint32_t eax;
+	
+	uint32_t ebp_frame;  /* imitation of frame pointer linkage */
+	uint32_t eip_frame;  /* imitation of return address linkage */
+	
+	uint32_t gs;
+	uint32_t fs;
+	uint32_t es;
+	uint32_t ds;
+	
+	uint32_t error_word;  /* real or fake error word */
+	uint32_t eip;
+	uint32_t cs;
+	uint32_t eflags;
+	uint32_t esp;         /* only if istate_t is from uspace */
+	uint32_t ss;          /* only if istate_t is from uspace */
+} istate_t;
+
+/** Return true if exception happened while in userspace */
+NO_TRACE static inline int istate_from_uspace(istate_t *istate)
+{
+	return !(istate->eip & 0x80000000);
+}
+
+NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
+    uintptr_t retaddr)
+{
+	istate->eip = retaddr;
+}
+
+NO_TRACE static inline uintptr_t istate_get_pc(istate_t *istate)
+{
+	return istate->eip;
+}
+
+NO_TRACE static inline uintptr_t istate_get_fp(istate_t *istate)
+{
+	return istate->ebp;
+}
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ia64/include/interrupt.h
===================================================================
--- kernel/arch/ia64/include/interrupt.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ kernel/arch/ia64/include/interrupt.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -37,6 +37,5 @@
 
 #include <typedefs.h>
-#include <arch/register.h>
-#include <trace.h>
+#include <arch/istate.h>
 
 /** ia64 has 256 INRs. */
@@ -74,89 +73,5 @@
 #define EOI  0  /**< The actual value doesn't matter. */
 
-typedef struct istate {
-	uint128_t f2;
-	uint128_t f3;
-	uint128_t f4;
-	uint128_t f5;
-	uint128_t f6;
-	uint128_t f7;
-	uint128_t f8;
-	uint128_t f9;
-	uint128_t f10;
-	uint128_t f11;
-	uint128_t f12;
-	uint128_t f13;
-	uint128_t f14;
-	uint128_t f15;
-	uint128_t f16;
-	uint128_t f17;
-	uint128_t f18;
-	uint128_t f19;
-	uint128_t f20;
-	uint128_t f21;
-	uint128_t f22;
-	uint128_t f23;
-	uint128_t f24;
-	uint128_t f25;
-	uint128_t f26;
-	uint128_t f27;
-	uint128_t f28;
-	uint128_t f29;
-	uint128_t f30;
-	uint128_t f31;
-	
-	uintptr_t ar_bsp;
-	uintptr_t ar_bspstore;
-	uintptr_t ar_bspstore_new;
-	uint64_t ar_rnat;
-	uint64_t ar_ifs;
-	uint64_t ar_pfs;
-	uint64_t ar_rsc;
-	uintptr_t cr_ifa;
-	cr_isr_t cr_isr;
-	uintptr_t cr_iipa;
-	psr_t cr_ipsr;
-	uintptr_t cr_iip;
-	uint64_t pr;
-	uintptr_t sp;
-	
-	/*
-	 * The following variables are defined only for break_instruction
-	 * handler.
-	 */
-	uint64_t in0;
-	uint64_t in1;
-	uint64_t in2;
-	uint64_t in3;
-	uint64_t in4;
-	uint64_t in5;
-	uint64_t in6;
-} istate_t;
-
 extern void *ivt;
-
-NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
-    uintptr_t retaddr)
-{
-	istate->cr_iip = retaddr;
-	istate->cr_ipsr.ri = 0;    /* return to instruction slot #0 */
-}
-
-NO_TRACE static inline unative_t istate_get_pc(istate_t *istate)
-{
-	return istate->cr_iip;
-}
-
-NO_TRACE static inline unative_t istate_get_fp(istate_t *istate)
-{
-	/* FIXME */
-	
-	return 0;
-}
-
-NO_TRACE static inline int istate_from_uspace(istate_t *istate)
-{
-	return (istate->cr_iip) < 0xe000000000000000ULL;
-}
 
 extern void general_exception(uint64_t, istate_t *);
Index: kernel/arch/ia64/include/istate.h
===================================================================
--- kernel/arch/ia64/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
+++ kernel/arch/ia64/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2005 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.
+ */
+
+/** @addtogroup ia64interrupt
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_ia64_ISTATE_H_
+#define KERN_ia64_ISTATE_H_
+
+#include <arch/register.h>
+
+#ifdef KERNEL
+#include <typedefs.h>
+#include <trace.h>
+#else
+#include <sys/types.h>
+#define NO_TRACE
+#endif
+
+typedef struct istate {
+	uint128_t f2;
+	uint128_t f3;
+	uint128_t f4;
+	uint128_t f5;
+	uint128_t f6;
+	uint128_t f7;
+	uint128_t f8;
+	uint128_t f9;
+	uint128_t f10;
+	uint128_t f11;
+	uint128_t f12;
+	uint128_t f13;
+	uint128_t f14;
+	uint128_t f15;
+	uint128_t f16;
+	uint128_t f17;
+	uint128_t f18;
+	uint128_t f19;
+	uint128_t f20;
+	uint128_t f21;
+	uint128_t f22;
+	uint128_t f23;
+	uint128_t f24;
+	uint128_t f25;
+	uint128_t f26;
+	uint128_t f27;
+	uint128_t f28;
+	uint128_t f29;
+	uint128_t f30;
+	uint128_t f31;
+	
+	uintptr_t ar_bsp;
+	uintptr_t ar_bspstore;
+	uintptr_t ar_bspstore_new;
+	uint64_t ar_rnat;
+	uint64_t ar_ifs;
+	uint64_t ar_pfs;
+	uint64_t ar_rsc;
+	uintptr_t cr_ifa;
+	cr_isr_t cr_isr;
+	uintptr_t cr_iipa;
+	psr_t cr_ipsr;
+	uintptr_t cr_iip;
+	uint64_t pr;
+	uintptr_t sp;
+	
+	/*
+	 * The following variables are defined only for break_instruction
+	 * handler.
+	 */
+	uint64_t in0;
+	uint64_t in1;
+	uint64_t in2;
+	uint64_t in3;
+	uint64_t in4;
+	uint64_t in5;
+	uint64_t in6;
+} istate_t;
+
+NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
+    uintptr_t retaddr)
+{
+	istate->cr_iip = retaddr;
+	istate->cr_ipsr.ri = 0;    /* return to instruction slot #0 */
+}
+
+NO_TRACE static inline uintptr_t istate_get_pc(istate_t *istate)
+{
+	return istate->cr_iip;
+}
+
+NO_TRACE static inline uintptr_t istate_get_fp(istate_t *istate)
+{
+	/* FIXME */
+	
+	return 0;
+}
+
+NO_TRACE static inline int istate_from_uspace(istate_t *istate)
+{
+	return (istate->cr_iip) < 0xe000000000000000ULL;
+}
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ia64/include/register.h
===================================================================
--- kernel/arch/ia64/include/register.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ kernel/arch/ia64/include/register.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -142,5 +142,9 @@
 #ifndef __ASM__
 
+#ifdef KERNEL
 #include <typedefs.h>
+#else
+#include <sys/types.h>
+#endif
 
 /** Processor Status Register. */
Index: kernel/arch/mips32/include/cp0.h
===================================================================
--- kernel/arch/mips32/include/cp0.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ kernel/arch/mips32/include/cp0.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -36,5 +36,9 @@
 #define KERN_mips32_CP0_H_
 
+#ifdef KERNEL
 #include <typedefs.h>
+#else
+#include <sys/types.h>
+#endif
 
 #define cp0_status_ie_enabled_bit     (1 << 0)
Index: kernel/arch/mips32/include/exception.h
===================================================================
--- kernel/arch/mips32/include/exception.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ kernel/arch/mips32/include/exception.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -37,6 +37,5 @@
 
 #include <typedefs.h>
-#include <arch/cp0.h>
-#include <trace.h>
+#include <arch/istate.h>
 
 #define EXC_Int    0
@@ -59,72 +58,4 @@
 #define EXC_VCED   31
 
-typedef struct istate {
-	/*
-	 * The first seven registers are arranged so that the istate structure
-	 * can be used both for exception handlers and for the syscall handler.
-	 */
-	uint32_t a0;	/* arg1 */
-	uint32_t a1;	/* arg2 */
-	uint32_t a2;	/* arg3 */
-	uint32_t a3;	/* arg4 */
-	uint32_t t0;	/* arg5 */
-	uint32_t t1;	/* arg6 */
-	uint32_t v0;	/* arg7 */
-	uint32_t v1;
-	uint32_t at;
-	uint32_t t2;
-	uint32_t t3;
-	uint32_t t4;
-	uint32_t t5;
-	uint32_t t6;
-	uint32_t t7;
-	uint32_t s0;
-	uint32_t s1;
-	uint32_t s2;
-	uint32_t s3;
-	uint32_t s4;
-	uint32_t s5;
-	uint32_t s6;
-	uint32_t s7;
-	uint32_t t8;
-	uint32_t t9;
-	uint32_t kt0;
-	uint32_t kt1;	/* We use it as thread-local pointer */
-	uint32_t gp;
-	uint32_t sp;
-	uint32_t s8;
-	uint32_t ra;
-	
-	uint32_t lo;
-	uint32_t hi;
-	
-	uint32_t status;	/* cp0_status */
-	uint32_t epc;		/* cp0_epc */
-
-	uint32_t alignment;	/* to make sizeof(istate_t) a multiple of 8 */
-} istate_t;
-
-NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
-    uintptr_t retaddr)
-{
-	istate->epc = retaddr;
-}
-
-/** Return true if exception happened while in userspace */
-NO_TRACE static inline int istate_from_uspace(istate_t *istate)
-{
-	return istate->status & cp0_status_um_bit;
-}
-
-NO_TRACE static inline unative_t istate_get_pc(istate_t *istate)
-{
-	return istate->epc;
-}
-
-NO_TRACE static inline unative_t istate_get_fp(istate_t *istate)
-{
-	return istate->sp;
-}
-
 extern void exception(istate_t *istate);
 extern void tlb_refill_entry(void);
Index: kernel/arch/mips32/include/istate.h
===================================================================
--- kernel/arch/mips32/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
+++ kernel/arch/mips32/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2003-2004 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.
+ */
+
+/** @addtogroup mips32interrupt
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_mips32_ISTATE_H_
+#define KERN_mips32_ISTATE_H_
+
+#include <arch/cp0.h>
+
+#ifdef KERNEL
+#include <typedefs.h>
+#include <trace.h>
+#else
+#include <sys/types.h>
+#define NO_TRACE
+#endif
+
+typedef struct istate {
+	/*
+	 * The first seven registers are arranged so that the istate structure
+	 * can be used both for exception handlers and for the syscall handler.
+	 */
+	uint32_t a0;	/* arg1 */
+	uint32_t a1;	/* arg2 */
+	uint32_t a2;	/* arg3 */
+	uint32_t a3;	/* arg4 */
+	uint32_t t0;	/* arg5 */
+	uint32_t t1;	/* arg6 */
+	uint32_t v0;	/* arg7 */
+	uint32_t v1;
+	uint32_t at;
+	uint32_t t2;
+	uint32_t t3;
+	uint32_t t4;
+	uint32_t t5;
+	uint32_t t6;
+	uint32_t t7;
+	uint32_t s0;
+	uint32_t s1;
+	uint32_t s2;
+	uint32_t s3;
+	uint32_t s4;
+	uint32_t s5;
+	uint32_t s6;
+	uint32_t s7;
+	uint32_t t8;
+	uint32_t t9;
+	uint32_t kt0;
+	uint32_t kt1;	/* We use it as thread-local pointer */
+	uint32_t gp;
+	uint32_t sp;
+	uint32_t s8;
+	uint32_t ra;
+	
+	uint32_t lo;
+	uint32_t hi;
+	
+	uint32_t status;	/* cp0_status */
+	uint32_t epc;		/* cp0_epc */
+
+	uint32_t alignment;	/* to make sizeof(istate_t) a multiple of 8 */
+} istate_t;
+
+NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
+    uintptr_t retaddr)
+{
+	istate->epc = retaddr;
+}
+
+/** Return true if exception happened while in userspace */
+NO_TRACE static inline int istate_from_uspace(istate_t *istate)
+{
+	return istate->status & cp0_status_um_bit;
+}
+
+NO_TRACE static inline uintptr_t istate_get_pc(istate_t *istate)
+{
+	return istate->epc;
+}
+
+NO_TRACE static inline uintptr_t istate_get_fp(istate_t *istate)
+{
+	return istate->sp;
+}
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ppc32/include/istate.h
===================================================================
--- kernel/arch/ppc32/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
+++ kernel/arch/ppc32/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2006 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ppc32
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_ppc32_EXCEPTION_H_
+#define KERN_ppc32_EXCEPTION_H_
+
+#include <typedefs.h>
+#include <arch/cpu.h>
+#include <trace.h>
+
+typedef struct istate {
+	uint32_t r0;
+	uint32_t r2;
+	uint32_t r3;
+	uint32_t r4;
+	uint32_t r5;
+	uint32_t r6;
+	uint32_t r7;
+	uint32_t r8;
+	uint32_t r9;
+	uint32_t r10;
+	uint32_t r11;
+	uint32_t r13;
+	uint32_t r14;
+	uint32_t r15;
+	uint32_t r16;
+	uint32_t r17;
+	uint32_t r18;
+	uint32_t r19;
+	uint32_t r20;
+	uint32_t r21;
+	uint32_t r22;
+	uint32_t r23;
+	uint32_t r24;
+	uint32_t r25;
+	uint32_t r26;
+	uint32_t r27;
+	uint32_t r28;
+	uint32_t r29;
+	uint32_t r30;
+	uint32_t r31;
+	uint32_t cr;
+	uint32_t pc;
+	uint32_t srr1;
+	uint32_t lr;
+	uint32_t ctr;
+	uint32_t xer;
+	uint32_t dar;
+	uint32_t r12;
+	uint32_t sp;
+} istate_t;
+
+NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
+    uintptr_t retaddr)
+{
+	istate->pc = retaddr;
+}
+
+/** Return true if exception happened while in userspace
+ *
+ * The contexts of MSR register was stored in SRR1.
+ *
+ */
+NO_TRACE static inline int istate_from_uspace(istate_t *istate)
+{
+	return (istate->srr1 & MSR_PR) != 0;
+}
+
+NO_TRACE static inline uintptr_t istate_get_pc(istate_t *istate)
+{
+	return istate->pc;
+}
+
+NO_TRACE static inline uintptr_t istate_get_fp(istate_t *istate)
+{
+	return istate->sp;
+}
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/sparc64/include/interrupt.h
===================================================================
--- kernel/arch/sparc64/include/interrupt.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ kernel/arch/sparc64/include/interrupt.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -38,6 +38,5 @@
 
 #include <typedefs.h>
-#include <arch/regdef.h>
-#include <trace.h>
+#include <arch/istate.h>
 
 #define IVT_ITEMS  15
@@ -51,33 +50,4 @@
 };
 
-typedef struct istate {
-	uint64_t tnpc;
-	uint64_t tpc;
-	uint64_t tstate;
-} istate_t;
-
-NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
-    uintptr_t retaddr)
-{
-	istate->tpc = retaddr;
-}
-
-NO_TRACE static inline int istate_from_uspace(istate_t *istate)
-{
-	return !(istate->tstate & TSTATE_PRIV_BIT);
-}
-
-NO_TRACE static inline unative_t istate_get_pc(istate_t *istate)
-{
-	return istate->tpc;
-}
-
-NO_TRACE static inline unative_t istate_get_fp(istate_t *istate)
-{
-	/* TODO */
-	
-	return 0;
-}
-
 #endif
 
Index: kernel/arch/sparc64/include/istate.h
===================================================================
--- kernel/arch/sparc64/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
+++ kernel/arch/sparc64/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2005 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.
+ */
+
+/** @addtogroup sparc64interrupt sparc64
+ * @ingroup interrupt
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_sparc64_ISTATE_H_
+#define KERN_sparc64_ISTATE_H_
+
+#include <arch/regdef.h>
+
+#ifdef KERNEL
+#include <typedefs.h>
+#include <trace.h>
+#else
+#include <sys/types.h>
+#define NO_TRACE
+#endif
+
+typedef struct istate {
+	uint64_t tnpc;
+	uint64_t tpc;
+	uint64_t tstate;
+} istate_t;
+
+NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
+    uintptr_t retaddr)
+{
+	istate->tpc = retaddr;
+}
+
+NO_TRACE static inline int istate_from_uspace(istate_t *istate)
+{
+	return !(istate->tstate & TSTATE_PRIV_BIT);
+}
+
+NO_TRACE static inline uintptr_t istate_get_pc(istate_t *istate)
+{
+	return istate->tpc;
+}
+
+NO_TRACE static inline uintptr_t istate_get_fp(istate_t *istate)
+{
+	/* TODO */
+	return 0;
+}
+
+#endif
+
+/** @}
+ */
Index: kernel/generic/src/ipc/kbox.c
===================================================================
--- kernel/generic/src/ipc/kbox.c	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ kernel/generic/src/ipc/kbox.c	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -107,7 +107,7 @@
 		/* Terminate debugging session (if any). */
 		LOG("Terminate debugging session.");
-		irq_spinlock_lock(&TASK->lock, true);
+		mutex_lock(&TASK->udebug.lock);
 		udebug_task_cleanup(TASK);
-		irq_spinlock_unlock(&TASK->lock, true);
+		mutex_unlock(&TASK->udebug.lock);
 	} else {
 		LOG("Was not debugger.");
Index: kernel/tools/amd64/decpt.py
===================================================================
--- kernel/tools/amd64/decpt.py	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ kernel/tools/amd64/decpt.py	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -7,5 +7,5 @@
 def main():
     if len(sys.argv) != 2 or not sys.argv[1].startswith('0x'):
-        print "%s 0x..." % sys.argv[0]
+        print("%s 0x..." % sys.argv[0])
         sys.exit(1)
     
@@ -16,9 +16,9 @@
     ptl1 = (address >> 30) & 0x1ff
     ptl0 = (address >> 39) & 0x1ff
-    print "Ptl0:   %3d" % ptl0
-    print "Ptl1:   %3d" % ptl1
-    print "Ptl2:   %3d" % ptl2
-    print "Ptl3:   %3d" % ptl3
-    print "Offset: 0x%x" % offset
+    print("Ptl0:   %3d" % ptl0)
+    print("Ptl1:   %3d" % ptl1)
+    print("Ptl2:   %3d" % ptl2)
+    print("Ptl3:   %3d" % ptl3)
+    print("Offset: 0x%x" % offset)
 
 if __name__ == '__main__':
Index: kernel/tools/genmap.py
===================================================================
--- kernel/tools/genmap.py	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ kernel/tools/genmap.py	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -86,6 +86,6 @@
 	obdump = read_obdump(obmapf)
 	
-	def sorter(x,y):
-		return cmp(x[0],y[0])
+	def key_sorter(x):
+		return x[0]
 	
 	for line in kmapf:
@@ -93,9 +93,9 @@
 		res = startfile.match(line)
 		
-		if ((res) and (obdump[res.group(1)].has_key(res.group(3)))):
+		if ((res) and (res.group(3) in obdump[res.group(1)])):
 			offset = int(res.group(2), 16)
 			fname = res.group(3)
 			symbols = obdump[res.group(1)][fname]
-			symbols.sort(sorter)
+			symbols.sort(key = key_sorter)
 			for addr, symbol in symbols:
 				value = fname + ':' + symbol
@@ -107,10 +107,10 @@
 def main():
 	if (len(sys.argv) != 4):
-		print "Usage: %s <kernel.map> <nm dump> <output.bin>" % sys.argv[0]
+		print("Usage: %s <kernel.map> <nm dump> <output.bin>" % sys.argv[0])
 		return 1
 	
 	kmapf = open(sys.argv[1], 'r')
 	obmapf = open(sys.argv[2], 'r')
-	out = open(sys.argv[3], 'w')
+	out = open(sys.argv[3], 'wb')
 	
 	generate(kmapf, obmapf, out)
Index: kernel/tools/ia32/decpt.py
===================================================================
--- kernel/tools/ia32/decpt.py	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ kernel/tools/ia32/decpt.py	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -7,5 +7,5 @@
 def main():
     if len(sys.argv) != 2 or not sys.argv[1].startswith('0x'):
-        print "%s 0x..." % sys.argv[0]
+        print("%s 0x..." % sys.argv[0])
         sys.exit(1)
     
@@ -14,7 +14,7 @@
     ptl1 = (address >> 12) & 0x3ff
     ptl0 = (address >> 22) & 0x3ff
-    print "Ptl0:   %3d" % ptl0
-    print "Ptl1:   %3d" % ptl1
-    print "Offset: 0x%x" % offset
+    print("Ptl0:   %3d" % ptl0)
+    print("Ptl1:   %3d" % ptl1)
+    print("Offset: 0x%x" % offset)
 
 if __name__ == '__main__':
Index: tools/autotool.py
===================================================================
--- tools/autotool.py	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ tools/autotool.py	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -75,5 +75,5 @@
 	"Read HelenOS build configuration"
 	
-	inf = file(fname, 'r')
+	inf = open(fname, 'r')
 	
 	for line in inf:
@@ -191,5 +191,5 @@
 	check_common(common, "CC")
 	
-	outf = file(PROBE_SOURCE, 'w')
+	outf = open(PROBE_SOURCE, 'w')
 	outf.write(PROBE_HEAD)
 	
@@ -212,5 +212,5 @@
 	if (not os.path.isfile(PROBE_OUTPUT)):
 		sys.stderr.write("failed\n")
-		print output[1]
+		print(output[1])
 		print_error(["Error executing \"%s\"." % " ".join(args),
 		             "The compiler did not produce the output file \"%s\"." % PROBE_OUTPUT,
@@ -221,5 +221,5 @@
 	sys.stderr.write("ok\n")
 	
-	inf = file(PROBE_OUTPUT, 'r')
+	inf = open(PROBE_OUTPUT, 'r')
 	lines = inf.readlines()
 	inf.close()
@@ -343,5 +343,5 @@
 	"Create makefile output"
 	
-	outmk = file(mkname, 'w')
+	outmk = open(mkname, 'w')
 	
 	outmk.write('#########################################\n')
@@ -357,5 +357,5 @@
 	"Create header output"
 	
-	outhd = file(hdname, 'w')
+	outhd = open(hdname, 'w')
 	
 	outhd.write('/***************************************\n')
Index: tools/checkers/clang.py
===================================================================
--- tools/checkers/clang.py	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ tools/checkers/clang.py	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -42,5 +42,5 @@
 def usage(prname):
 	"Print usage syntax"
-	print prname + " <ROOT>"
+	print(prname + " <ROOT>")
 
 def clang(root, job):
@@ -50,9 +50,9 @@
 	
 	if (not os.path.isfile(inname)):
-		print "Unable to open %s" % inname
-		print "Did you run \"make precheck\" on the source tree?"
+		print("Unable to open %s" % inname)
+		print("Did you run \"make precheck\" on the source tree?")
 		return False
 	
-	inf = file(inname, "r")
+	inf = open(inname, "r")
 	records = inf.read().splitlines()
 	inf.close()
@@ -64,5 +64,5 @@
 		
 		if (len(arg) < 6):
-			print "Not enought jobfile record arguments"
+			print("Not enought jobfile record arguments")
 			return False
 		
@@ -76,5 +76,5 @@
 		srcfqname = os.path.join(base, srcfname)
 		if (not os.path.isfile(srcfqname)):
-			print "Source %s not found" % srcfqname
+			print("Source %s not found" % srcfqname)
 			return False
 		
@@ -108,6 +108,6 @@
 	
 	if (not os.path.isfile(config)):
-		print "%s not found." % config
-		print "Please specify the path to HelenOS build tree root as the first argument."
+		print("%s not found." % config)
+		print("Please specify the path to HelenOS build tree root as the first argument.")
 		return
 	
@@ -115,9 +115,9 @@
 		if (not clang(rootdir, job)):
 			print
-			print "Failed job: %s" % job
+			print("Failed job: %s" % job)
 			return
 	
 	print
-	print "All jobs passed"
+	print("All jobs passed")
 
 if __name__ == '__main__':
Index: tools/checkers/jobfile.py
===================================================================
--- tools/checkers/jobfile.py	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ tools/checkers/jobfile.py	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -54,5 +54,5 @@
 				nil = True
 			else:
-				print "Unexpected '%s'" % record[i]
+				print("Unexpected '%s'" % record[i])
 				return False
 		
Index: tools/checkers/stanse.py
===================================================================
--- tools/checkers/stanse.py	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ tools/checkers/stanse.py	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -43,5 +43,5 @@
 def usage(prname):
 	"Print usage syntax"
-	print prname + " <ROOT>"
+	print(prname + " <ROOT>")
 
 def stanse(root, job):
@@ -54,9 +54,9 @@
 	
 	if (not os.path.isfile(inname)):
-		print "Unable to open %s" % inname
-		print "Did you run \"make precheck\" on the source tree?"
+		print("Unable to open %s" % inname)
+		print("Did you run \"make precheck\" on the source tree?")
 		return False
 	
-	inf = file(inname, "r")
+	inf = open(inname, "r")
 	records = inf.read().splitlines()
 	inf.close()
@@ -69,5 +69,5 @@
 		
 		if (len(arg) < 6):
-			print "Not enought jobfile record arguments"
+			print("Not enought jobfile record arguments")
 			return False
 		
@@ -81,5 +81,5 @@
 		srcfqname = os.path.join(base, srcfname)
 		if (not os.path.isfile(srcfqname)):
-			print "Source %s not found" % srcfqname
+			print("Source %s not found" % srcfqname)
 			return False
 		
@@ -90,5 +90,5 @@
 		output.append([srcfname, tgtfname, base, options])
 	
-	outf = file(outname, "w")
+	outf = open(outname, "w")
 	for record in output:
 		outf.write("{%s},{%s},{%s},{%s}\n" % (record[0], record[1], record[2], record[3]))
@@ -121,6 +121,6 @@
 	
 	if (not os.path.isfile(config)):
-		print "%s not found." % config
-		print "Please specify the path to HelenOS build tree root as the first argument."
+		print("%s not found." % config)
+		print("Please specify the path to HelenOS build tree root as the first argument.")
 		return
 	
@@ -128,9 +128,9 @@
 		if (not stanse(rootdir, job)):
 			print
-			print "Failed job: %s" % job
+			print("Failed job: %s" % job)
 			return
 	
 	print
-	print "All jobs passed"
+	print("All jobs passed")
 
 if __name__ == '__main__':
Index: tools/checkers/vcc.py
===================================================================
--- tools/checkers/vcc.py	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ tools/checkers/vcc.py	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -49,5 +49,5 @@
 def usage(prname):
 	"Print usage syntax"
-	print prname + " <ROOT> [VCC_PATH]"
+	print(prname + " <ROOT> [VCC_PATH]")
 
 def cygpath(upath):
@@ -72,5 +72,5 @@
 	preproc = subprocess.Popen(args, stdout = subprocess.PIPE).communicate()[0]
 	
-	tmpf = file(tmpfname, "w")
+	tmpf = open(tmpfname, "w")
 	tmpf.write(specification)
 	
@@ -108,9 +108,9 @@
 	
 	if (not os.path.isfile(inname)):
-		print "Unable to open %s" % inname
-		print "Did you run \"make precheck\" on the source tree?"
+		print("Unable to open %s" % inname)
+		print("Did you run \"make precheck\" on the source tree?")
 		return False
 	
-	inf = file(inname, "r")
+	inf = open(inname, "r")
 	records = inf.read().splitlines()
 	inf.close()
@@ -122,5 +122,5 @@
 		
 		if (len(arg) < 6):
-			print "Not enought jobfile record arguments"
+			print("Not enought jobfile record arguments")
 			return False
 		
@@ -134,5 +134,5 @@
 		srcfqname = os.path.join(base, srcfname)
 		if (not os.path.isfile(srcfqname)):
-			print "Source %s not found" % srcfqname
+			print("Source %s not found" % srcfqname)
 			return False
 		
@@ -153,5 +153,5 @@
 		
 		# Run Vcc
-		print " -- %s --" % srcfname		
+		print(" -- %s --" % srcfname)
 		retval = subprocess.Popen([vcc_path, '/pointersize:32', '/newsyntax', cygpath(tmpfqname)]).wait()
 		
@@ -182,6 +182,6 @@
 	
 	if (not os.path.isfile(vcc_path)):
-		print "%s is not a binary." % vcc_path
-		print "Please supply the full Cygwin path to Vcc as the second argument."
+		print("%s is not a binary." % vcc_path)
+		print("Please supply the full Cygwin path to Vcc as the second argument.")
 		return
 	
@@ -189,11 +189,11 @@
 	
 	if (not os.path.isfile(config)):
-		print "%s not found." % config
-		print "Please specify the path to HelenOS build tree root as the first argument."
+		print("%s not found." % config)
+		print("Please specify the path to HelenOS build tree root as the first argument.")
 		return
 	
 	specpath = os.path.join(rootdir, "tools/checkers/vcc.h")
 	if (not os.path.isfile(specpath)):
-		print "%s not found." % config
+		print("%s not found." % config)
 		return
 	
@@ -205,9 +205,9 @@
 		if (not vcc(vcc_path, rootdir, job)):
 			print
-			print "Failed job: %s" % job
+			print("Failed job: %s" % job)
 			return
 	
 	print
-	print "All jobs passed"
+	print("All jobs passed")
 
 if __name__ == '__main__':
Index: tools/config.py
===================================================================
--- tools/config.py	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ tools/config.py	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -48,5 +48,5 @@
 	"Read saved values from last configuration run"
 	
-	inf = file(fname, 'r')
+	inf = open(fname, 'r')
 	
 	for line in inf:
@@ -103,5 +103,5 @@
 		condval = res.group(3)
 		
-		if (not defaults.has_key(condname)):
+		if (not condname in defaults):
 			varval = ''
 		else:
@@ -131,5 +131,5 @@
 	"Parse configuration file"
 	
-	inf = file(fname, 'r')
+	inf = open(fname, 'r')
 	
 	name = ''
@@ -219,5 +219,5 @@
 			continue
 		
-		if (not defaults.has_key(varname)):
+		if (not varname in defaults):
 			return False
 	
@@ -232,5 +232,5 @@
 	
 	try:
-		version = subprocess.Popen(['bzr', 'version-info', '--custom', '--template={clean}:{revno}:{revision_id}'], stdout = subprocess.PIPE).communicate()[0].split(':')
+		version = subprocess.Popen(['bzr', 'version-info', '--custom', '--template={clean}:{revno}:{revision_id}'], stdout = subprocess.PIPE).communicate()[0].decode().split(':')
 		sys.stderr.write("ok\n")
 	except:
@@ -246,6 +246,6 @@
 		revision = None
 	
-	outmk = file(mkname, 'w')
-	outmc = file(mcname, 'w')
+	outmk = open(mkname, 'w')
+	outmc = open(mcname, 'w')
 	
 	outmk.write('#########################################\n')
@@ -263,5 +263,5 @@
 			continue
 		
-		if (not defaults.has_key(varname)):
+		if (not varname in defaults):
 			default = ''
 		else:
@@ -368,5 +368,5 @@
 			# Cancel out all defaults which have to be deduced
 			for varname, vartype, name, choices, cond in ask_names:
-				if ((vartype == 'y') and (defaults.has_key(varname)) and (defaults[varname] == '*')):
+				if ((vartype == 'y') and (varname in defaults) and (defaults[varname] == '*')):
 					defaults[varname] = None
 			
@@ -385,5 +385,5 @@
 					position = cnt
 				
-				if (not defaults.has_key(varname)):
+				if (not varname in defaults):
 					default = None
 				else:
@@ -428,5 +428,5 @@
 				cnt += 1
 			
-			if (position >= options):
+			if (position != None) and (position >= len(options)):
 				position = None
 			
@@ -449,10 +449,10 @@
 			
 			position = None
-			if (not opt2row.has_key(value)):
+			if (not value in opt2row):
 				raise RuntimeError("Error selecting value: %s" % value)
 			
 			(selname, seltype, name, choices) = opt2row[value]
 			
-			if (not defaults.has_key(selname)):
+			if (not selname in defaults):
 					default = None
 			else:
Index: tools/jobfile.py
===================================================================
--- tools/jobfile.py	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ tools/jobfile.py	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -38,5 +38,5 @@
 def usage(prname):
 	"Print usage syntax"
-	print prname + " <JOBFILE> <SOURCE> <TARGET> <TOOL> <CATEGORY> [OPTIONS ...]"
+	print(prname + " <JOBFILE> <SOURCE> <TARGET> <TOOL> <CATEGORY> [OPTIONS ...]")
 
 def main():
@@ -53,5 +53,5 @@
 	options = " ".join(sys.argv[6:])
 	
-	jobfile = file(jobfname, "a")
+	jobfile = open(jobfname, "a")
 	fcntl.lockf(jobfile, fcntl.LOCK_EX)
 	jobfile.write("{%s},{%s},{%s},{%s},{%s},{%s}\n" % (srcfname, tgtfname, toolname, category, cwd, options))
Index: tools/mkfat.py
===================================================================
--- tools/mkfat.py	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ tools/mkfat.py	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -46,5 +46,5 @@
 		return size
 	
-	return (((size / alignment) + 1) * alignment)
+	return ((size // alignment) + 1) * alignment
 
 def subtree_size(root, cluster_size, dirent_size):
@@ -79,5 +79,5 @@
 	first = 0
 	
-	inf = file(path, "r")
+	inf = open(path, "rb")
 	rd = 0;
 	while (rd < size):
@@ -92,5 +92,5 @@
 		prev = empty_cluster
 		
-		data = inf.read(cluster_size);
+		data = bytes(inf.read(cluster_size));
 		outf.seek(data_start + (empty_cluster - reserved_clusters) * cluster_size)
 		outf.write(data)
@@ -120,5 +120,5 @@
 		prev = empty_cluster
 		
-		data = ''
+		data = bytes()
 		data_len = 0
 		while ((i < length) and (data_len < cluster_size)):
@@ -343,5 +343,5 @@
 def usage(prname):
 	"Print usage syntax"
-	print prname + " <EXTRA_BYTES> <PATH> <IMAGE>"
+	print(prname + " <EXTRA_BYTES> <PATH> <IMAGE>")
 
 def main():
@@ -351,5 +351,5 @@
 	
 	if (not sys.argv[1].isdigit()):
-		print "<EXTRA_BYTES> must be a number"
+		print("<EXTRA_BYTES> must be a number")
 		return
 	
@@ -358,5 +358,5 @@
 	path = os.path.abspath(sys.argv[2])
 	if (not os.path.isdir(path)):
-		print "<PATH> must be a directory"
+		print("<PATH> must be a directory")
 		return
 	
@@ -372,7 +372,7 @@
 	# Make sure the filesystem is large enought for FAT16
 	size = subtree_size(path, cluster_size, dirent_size) + reserved_clusters * cluster_size + extra_bytes
-	while (size / cluster_size < fat16_clusters):
+	while (size // cluster_size < fat16_clusters):
 		if (cluster_size > sector_size):
-			cluster_size /= 2
+			cluster_size = cluster_size // 2
 			size = subtree_size(path, cluster_size, dirent_size) + reserved_clusters * cluster_size + extra_bytes
 		else:
@@ -381,20 +381,20 @@
 	root_size = align_up(root_entries(path) * dirent_size, cluster_size)
 	
-	fat_size = align_up(align_up(size, cluster_size) / cluster_size * fatent_size, sector_size)
-	
-	sectors = (cluster_size + fat_count * fat_size + root_size + size) / sector_size
+	fat_size = align_up(align_up(size, cluster_size) // cluster_size * fatent_size, sector_size)
+	
+	sectors = (cluster_size + fat_count * fat_size + root_size + size) // sector_size
 	root_start = cluster_size + fat_count * fat_size
 	data_start = root_start + root_size
 	
-	outf = file(sys.argv[3], "w")
+	outf = open(sys.argv[3], "wb")
 	
 	boot_sector = xstruct.create(BOOT_SECTOR)
 	boot_sector.jmp = [0xEB, 0x3C, 0x90]
-	boot_sector.oem = "MSDOS5.0"
+	boot_sector.oem = b'MSDOS5.0'
 	boot_sector.sector = sector_size
-	boot_sector.cluster = cluster_size / sector_size
-	boot_sector.reserved = cluster_size / sector_size
+	boot_sector.cluster = cluster_size // sector_size
+	boot_sector.reserved = cluster_size // sector_size
 	boot_sector.fats = fat_count
-	boot_sector.rootdir = root_size / dirent_size
+	boot_sector.rootdir = root_size // dirent_size
 	if (sectors <= 65535):
 		boot_sector.sectors = sectors
@@ -402,5 +402,5 @@
 		boot_sector.sectors = 0
 	boot_sector.descriptor = 0xF8
-	boot_sector.fat_sectors = fat_size / sector_size
+	boot_sector.fat_sectors = fat_size // sector_size
 	boot_sector.track_sectors = 63
 	boot_sector.heads = 6
@@ -414,6 +414,6 @@
 	boot_sector.extboot_signature = 0x29
 	boot_sector.serial = random.randint(0, 0x7fffffff)
-	boot_sector.label = "HELENOS"
-	boot_sector.fstype = "FAT16   "
+	boot_sector.label = b'HELENOS'
+	boot_sector.fstype = b'FAT16   '
 	boot_sector.boot_signature = [0x55, 0xAA]
 	
@@ -423,21 +423,21 @@
 	
 	# Reserved sectors
-	for i in range(1, cluster_size / sector_size):
+	for i in range(1, cluster_size // sector_size):
 		outf.write(empty_sector.pack())
 	
 	# FAT tables
 	for i in range(0, fat_count):
-		for j in range(0, fat_size / sector_size):
+		for j in range(0, fat_size // sector_size):
 			outf.write(empty_sector.pack())
 	
 	# Root directory
-	for i in range(0, root_size / sector_size):
+	for i in range(0, root_size // sector_size):
 		outf.write(empty_sector.pack())
 	
 	# Data
-	for i in range(0, size / sector_size):
+	for i in range(0, size // sector_size):
 		outf.write(empty_sector.pack())
 	
-	fat = array.array('L', [0] * (fat_size / fatent_size))
+	fat = array.array('L', [0] * (fat_size // fatent_size))
 	fat[0] = 0xfff8
 	fat[1] = 0xffff
@@ -449,5 +449,5 @@
 	for i in range(0, fat_count):
 		outf.seek(cluster_size + i * fat_size)
-		for j in range(0, fat_size / fatent_size):
+		for j in range(0, fat_size // fatent_size):
 			fat_entry.next = fat[j]
 			outf.write(fat_entry.pack())
Index: tools/mkhord.py
===================================================================
--- tools/mkhord.py	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ tools/mkhord.py	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -52,5 +52,5 @@
 def usage(prname):
 	"Print usage syntax"
-	print prname + " <ALIGNMENT> <FS_IMAGE> <HORD_IMAGE>" 
+	print(prname + " <ALIGNMENT> <FS_IMAGE> <HORD_IMAGE>")
 
 def main():
@@ -60,19 +60,19 @@
 	
 	if (not sys.argv[1].isdigit()):
-		print "<ALIGNMENT> must be a number"
+		print("<ALIGNMENT> must be a number")
 		return
 	
 	align = int(sys.argv[1], 0)
 	if (align <= 0):
-		print "<ALIGNMENT> must be positive"
+		print("<ALIGNMENT> must be positive")
 		return
 	
 	fs_image = os.path.abspath(sys.argv[2])
 	if (not os.path.isfile(fs_image)):
-		print "<FS_IMAGE> must be a file"
+		print("<FS_IMAGE> must be a file")
 		return
 	
-	inf = file(fs_image, "rb")
-	outf = file(sys.argv[3], "wb")
+	inf = open(fs_image, "rb")
+	outf = open(sys.argv[3], "wb")
 	
 	header = xstruct.create(HEADER)
Index: tools/mktmpfs.py
===================================================================
--- tools/mktmpfs.py	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ tools/mktmpfs.py	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -66,5 +66,5 @@
 def usage(prname):
 	"Print usage syntax"
-	print prname + " <PATH> <IMAGE>"
+	print(prname + " <PATH> <IMAGE>")
 
 def recursion(root, outf):
@@ -85,5 +85,5 @@
 			outf.write(dentry.pack())
 			
-			inf = file(canon, "r")
+			inf = open(canon, "rb")
 			rd = 0;
 			while (rd < size):
@@ -116,8 +116,8 @@
 	path = os.path.abspath(sys.argv[1])
 	if (not os.path.isdir(path)):
-		print "<PATH> must be a directory"
+		print("<PATH> must be a directory")
 		return
 	
-	outf = file(sys.argv[2], "w")
+	outf = open(sys.argv[2], "wb")
 	
 	header = xstruct.create(HEADER)
Index: tools/mkuimage.py
===================================================================
--- tools/mkuimage.py	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ tools/mkuimage.py	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -72,10 +72,10 @@
 			start_addr = (int)(optarg, 0)
 		else:
-			print base_name + ": Unrecognized option."
+			print(base_name + ": Unrecognized option.")
 			print_syntax(cmd_name)
 			return
 
 	if len(args) < 2:
-		print base_name + ": Argument missing."
+		print(base_name + ": Argument missing.")
 		print_syntax(cmd_name)
 		return
@@ -91,6 +91,6 @@
 
 def mkuimage(inf_name, outf_name, image_name, load_addr, start_addr):
-	inf = file(inf_name, 'rb')
-	outf = file(outf_name, 'wb')
+	inf = open(inf_name, 'rb')
+	outf = open(outf_name, 'wb')
 
 	header = xstruct.create(UIMAGE_HEADER)
@@ -140,5 +140,5 @@
 	signed_crc = zlib.crc32(byteseq, 0)
 	if signed_crc < 0:
-		return (long(signed_crc) + 4294967296L) # 2^32L
+		return (long(signed_crc) + (long(2) ** long(32))) # 2^32L
 	else:
 		return signed_crc
@@ -147,13 +147,13 @@
 #
 def print_syntax(cmd):
-	print "syntax: " + cmd + " [<options>] <raw_image> <uImage>"
+	print("syntax: " + cmd + " [<options>] <raw_image> <uImage>")
 	print
-	print "\traw_image\tInput image name (raw binary data)"
-	print "\tuImage\t\tOutput uImage name (U-Boot image)"
+	print("\traw_image\tInput image name (raw binary data)")
+	print("\tuImage\t\tOutput uImage name (U-Boot image)")
 	print
-	print "options:"
-	print "\t-name <name>\tImage name (default: 'Noname')"
-	print "\t-laddr <name>\tLoad address (default: 0x00000000)"
-	print "\t-saddr <name>\tStart address (default: 0x00000000)"
+	print("options:")
+	print("\t-name <name>\tImage name (default: 'Noname')")
+	print("\t-laddr <name>\tLoad address (default: 0x00000000)")
+	print("\t-saddr <name>\tStart address (default: 0x00000000)")
 
 if __name__ == '__main__':
Index: tools/pack.py
===================================================================
--- tools/pack.py	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ tools/pack.py	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -43,5 +43,5 @@
 def usage(prname):
 	"Print usage syntax"
-	print "%s <OBJCOPY> <FORMAT> <ARCH> <ARCH_PATH> [COMPONENTS ...]" % prname
+	print("%s <OBJCOPY> <FORMAT> <ARCH> <ARCH_PATH> [COMPONENTS ...]" % prname)
 
 def deflate(data):
@@ -110,8 +110,8 @@
 		symbol = "_binary_%s" % basename.replace(".", "_")
 		
-		print "%s -> %s" % (component, obj)
+		print("%s -> %s" % (component, obj))
 		
-		comp_in = file(component, "rb")
-		comp_data = comp_in.read();
+		comp_in = open(component, "rb")
+		comp_data = comp_in.read()
 		comp_in.close()
 		
@@ -121,5 +121,5 @@
 		
 		try:
-			comp_out = file(basename, "wb")
+			comp_out = open(basename, "wb")
 			comp_out.write(comp_deflate)
 			comp_out.close()
@@ -151,5 +151,5 @@
 		cnt += 1
 	
-	header = file(os.path.join(arch_path, "include", "%s.h" % COMPONENTS), "w")
+	header = open(os.path.join(arch_path, "include", "%s.h" % COMPONENTS), "w")
 	
 	header.write('/***************************************\n')
@@ -173,5 +173,5 @@
 	header.close()
 	
-	data = file(os.path.join(arch_path, "src", "%s.c" % COMPONENTS), "w")
+	data = open(os.path.join(arch_path, "src", "%s.c" % COMPONENTS), "w")
 	
 	data.write('/***************************************\n')
@@ -187,9 +187,9 @@
 	data.close()
 	
-	link_in = file(os.path.join(arch_path, "%s.in" % LINK), "r")
+	link_in = open(os.path.join(arch_path, "%s.in" % LINK), "r")
 	template = link_in.read()
 	link_in.close()
 	
-	link_out = file(os.path.join(arch_path, "%s.comp" % LINK), "w")
+	link_out = open(os.path.join(arch_path, "%s.comp" % LINK), "w")
 	link_out.write(template.replace("[[COMPONENTS]]", "\n".join(link_ctx)))
 	link_out.close()
Index: uspace/app/netstart/self_test.c
===================================================================
--- uspace/app/netstart/self_test.c	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
+++ uspace/app/netstart/self_test.c	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -0,0 +1,334 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * 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 net
+ * @{
+ */
+
+/** @file
+ * Networking self-tests implementation.
+ *
+ */
+
+#include <errno.h>
+#include <malloc.h>
+#include <stdio.h>
+
+#include <net_checksum.h>
+#include <adt/int_map.h>
+#include <adt/char_map.h>
+#include <adt/generic_char_map.h>
+#include <adt/measured_strings.h>
+#include <adt/dynamic_fifo.h>
+
+#include "self_test.h"
+
+/** Test the statement, compare the result and evaluate.
+ *
+ * @param[in] statement The statement to test.
+ * @param[in] result    The expected result.
+ *
+ */
+#define TEST(statement, result) \
+	do { \
+		printf("\n\t%s == %s", #statement, #result); \
+		if ((statement) != (result)) { \
+			printf("\tfailed\n"); \
+			fprintf(stderr, "\nNetwork self-test failed\n"); \
+			return EINVAL; \
+		} else \
+			printf("\tOK"); \
+	} while (0)
+
+#define XMALLOC(var, type) \
+	do { \
+		(var) = (type *) malloc(sizeof(type)); \
+		if ((var) == NULL) { \
+			fprintf(stderr, "\nMemory allocation error\n"); \
+			return ENOMEM; \
+		} \
+	} while (0)
+
+GENERIC_CHAR_MAP_DECLARE(int_char_map, int);
+GENERIC_CHAR_MAP_IMPLEMENT(int_char_map, int);
+
+GENERIC_FIELD_DECLARE(int_field, int);
+GENERIC_FIELD_IMPLEMENT(int_field, int);
+
+INT_MAP_DECLARE(int_map, int);
+INT_MAP_IMPLEMENT(int_map, int);
+
+/** Self-test start function.
+ *
+ * Run all self-tests.
+ *
+ * @returns EOK on success.
+ * @returns The first error occurred.
+ *
+ */
+int self_test(void)
+{
+	printf("Running networking self-tests\n");
+	
+	printf("\nChar map test");
+	char_map_t cm;
+	
+	TEST(char_map_update(&cm, "ucho", 0, 3), EINVAL);
+	TEST(char_map_initialize(&cm), EOK);
+	TEST(char_map_exclude(&cm, "bla", 0), CHAR_MAP_NULL);
+	TEST(char_map_find(&cm, "bla", 0), CHAR_MAP_NULL);
+	TEST(char_map_add(&cm, "bla", 0, 1), EOK);
+	TEST(char_map_find(&cm, "bla", 0), 1);
+	TEST(char_map_add(&cm, "bla", 0, 10), EEXISTS);
+	TEST(char_map_update(&cm, "bla", 0, 2), EOK);
+	TEST(char_map_find(&cm, "bla", 0), 2);
+	TEST(char_map_update(&cm, "ucho", 0, 2), EOK);
+	TEST(char_map_exclude(&cm, "bla", 0), 2);
+	TEST(char_map_exclude(&cm, "bla", 0), CHAR_MAP_NULL);
+	TEST(char_map_find(&cm, "ucho", 0), 2);
+	TEST(char_map_update(&cm, "ucho", 0, 3), EOK);
+	TEST(char_map_find(&cm, "ucho", 0), 3);
+	TEST(char_map_add(&cm, "blabla", 0, 5), EOK);
+	TEST(char_map_find(&cm, "blabla", 0), 5);
+	TEST(char_map_add(&cm, "bla", 0, 6), EOK);
+	TEST(char_map_find(&cm, "bla", 0), 6);
+	TEST(char_map_exclude(&cm, "bla", 0), 6);
+	TEST(char_map_find(&cm, "bla", 0), CHAR_MAP_NULL);
+	TEST(char_map_find(&cm, "blabla", 0), 5);
+	TEST(char_map_add(&cm, "auto", 0, 7), EOK);
+	TEST(char_map_find(&cm, "auto", 0), 7);
+	TEST(char_map_add(&cm, "kara", 0, 8), EOK);
+	TEST(char_map_find(&cm, "kara", 0), 8);
+	TEST(char_map_add(&cm, "nic", 0, 9), EOK);
+	TEST(char_map_find(&cm, "nic", 0), 9);
+	TEST(char_map_find(&cm, "blabla", 0), 5);
+	TEST(char_map_add(&cm, "micnicnic", 5, 9), EOK);
+	TEST(char_map_find(&cm, "micni", 0), 9);
+	TEST(char_map_find(&cm, "micnicn", 5), 9);
+	TEST(char_map_add(&cm, "\x10\x0\x2\x2", 4, 15), EOK);
+	TEST(char_map_find(&cm, "\x10\x0\x2\x2", 4), 15);
+	
+	TEST((char_map_destroy(&cm), EOK), EOK);
+	TEST(char_map_update(&cm, "ucho", 0, 3), EINVAL);
+	
+	printf("\nCRC computation test");
+	uint32_t value;
+	
+	TEST(value = ~compute_crc32(~0, "123456789", 8 * 9), 0xcbf43926);
+	TEST(value = ~compute_crc32(~0, "1", 8), 0x83dcefb7);
+	TEST(value = ~compute_crc32(~0, "12", 8 * 2), 0x4f5344cd);
+	TEST(value = ~compute_crc32(~0, "123", 8 * 3), 0x884863d2);
+	TEST(value = ~compute_crc32(~0, "1234", 8 * 4), 0x9be3e0a3);
+	TEST(value = ~compute_crc32(~0, "12345678", 8 * 8), 0x9ae0daaf);
+	TEST(value = ~compute_crc32(~0, "ahoj pane", 8 * 9), 0x5fc3d706);
+	
+	printf("\nDynamic fifo test");
+	dyn_fifo_t fifo;
+	
+	TEST(dyn_fifo_push(&fifo, 1, 0), EINVAL);
+	TEST(dyn_fifo_initialize(&fifo, 1), EOK);
+	TEST(dyn_fifo_push(&fifo, 1, 0), EOK);
+	TEST(dyn_fifo_pop(&fifo), 1);
+	TEST(dyn_fifo_pop(&fifo), ENOENT);
+	TEST(dyn_fifo_push(&fifo, 2, 1), EOK);
+	TEST(dyn_fifo_push(&fifo, 3, 1), ENOMEM);
+	TEST(dyn_fifo_push(&fifo, 3, 0), EOK);
+	TEST(dyn_fifo_pop(&fifo), 2);
+	TEST(dyn_fifo_pop(&fifo), 3);
+	TEST(dyn_fifo_push(&fifo, 4, 2), EOK);
+	TEST(dyn_fifo_push(&fifo, 5, 2), EOK);
+	TEST(dyn_fifo_push(&fifo, 6, 2), ENOMEM);
+	TEST(dyn_fifo_push(&fifo, 6, 5), EOK);
+	TEST(dyn_fifo_push(&fifo, 7, 5), EOK);
+	TEST(dyn_fifo_pop(&fifo), 4);
+	TEST(dyn_fifo_pop(&fifo), 5);
+	TEST(dyn_fifo_push(&fifo, 8, 5), EOK);
+	TEST(dyn_fifo_push(&fifo, 9, 5), EOK);
+	TEST(dyn_fifo_push(&fifo, 10, 6), EOK);
+	TEST(dyn_fifo_push(&fifo, 11, 6), EOK);
+	TEST(dyn_fifo_pop(&fifo), 6);
+	TEST(dyn_fifo_pop(&fifo), 7);
+	TEST(dyn_fifo_push(&fifo, 12, 6), EOK);
+	TEST(dyn_fifo_push(&fifo, 13, 6), EOK);
+	TEST(dyn_fifo_push(&fifo, 14, 6), ENOMEM);
+	TEST(dyn_fifo_push(&fifo, 14, 8), EOK);
+	TEST(dyn_fifo_pop(&fifo), 8);
+	TEST(dyn_fifo_pop(&fifo), 9);
+	TEST(dyn_fifo_pop(&fifo), 10);
+	TEST(dyn_fifo_pop(&fifo), 11);
+	TEST(dyn_fifo_pop(&fifo), 12);
+	TEST(dyn_fifo_pop(&fifo), 13);
+	TEST(dyn_fifo_pop(&fifo), 14);
+	TEST(dyn_fifo_destroy(&fifo), EOK);
+	TEST(dyn_fifo_push(&fifo, 1, 0), EINVAL);
+	
+	printf("\nGeneric char map test");
+	
+	int *x;
+	int *y;
+	int *z;
+	int *u;
+	int *v;
+	int *w;
+	
+	XMALLOC(x, int);
+	XMALLOC(y, int);
+	XMALLOC(z, int);
+	XMALLOC(u, int);
+	XMALLOC(v, int);
+	XMALLOC(w, int);
+	
+	int_char_map_t icm;
+	icm.magic = 0;
+	
+	TEST(int_char_map_add(&icm, "ucho", 0, z), EINVAL);
+	TEST(int_char_map_initialize(&icm), EOK);
+	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
+	TEST(int_char_map_find(&icm, "bla", 0), NULL);
+	TEST(int_char_map_add(&icm, "bla", 0, x), EOK);
+	TEST(int_char_map_find(&icm, "bla", 0), x);
+	TEST(int_char_map_add(&icm, "bla", 0, y), EEXISTS);
+	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
+	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
+	TEST(int_char_map_add(&icm, "blabla", 0, v), EOK);
+	TEST(int_char_map_find(&icm, "blabla", 0), v);
+	TEST(int_char_map_add(&icm, "bla", 0, w), EOK);
+	TEST(int_char_map_find(&icm, "bla", 0), w);
+	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
+	TEST(int_char_map_find(&icm, "bla", 0), NULL);
+	TEST(int_char_map_find(&icm, "blabla", 0), v);
+	TEST(int_char_map_add(&icm, "auto", 0, u), EOK);
+	TEST(int_char_map_find(&icm, "auto", 0), u);
+	TEST((int_char_map_destroy(&icm), EOK), EOK);
+	TEST(int_char_map_add(&icm, "ucho", 0, z), EINVAL);
+	
+	printf("\nGeneric field test");
+	
+	XMALLOC(x, int);
+	XMALLOC(y, int);
+	XMALLOC(z, int);
+	XMALLOC(u, int);
+	XMALLOC(v, int);
+	XMALLOC(w, int);
+	
+	int_field_t gf;
+	gf.magic = 0;
+	
+	TEST(int_field_add(&gf, x), EINVAL);
+	TEST(int_field_count(&gf), -1);
+	TEST(int_field_initialize(&gf), EOK);
+	TEST(int_field_count(&gf), 0);
+	TEST(int_field_get_index(&gf, 1), NULL);
+	TEST(int_field_add(&gf, x), 0);
+	TEST(int_field_get_index(&gf, 0), x);
+	TEST((int_field_exclude_index(&gf, 0), EOK), EOK);
+	TEST(int_field_get_index(&gf, 0), NULL);
+	TEST(int_field_add(&gf, y), 1);
+	TEST(int_field_get_index(&gf, 1), y);
+	TEST(int_field_add(&gf, z), 2);
+	TEST(int_field_get_index(&gf, 2), z);
+	TEST(int_field_get_index(&gf, 1), y);
+	TEST(int_field_count(&gf), 3);
+	TEST(int_field_add(&gf, u), 3);
+	TEST(int_field_get_index(&gf, 3), u);
+	TEST(int_field_add(&gf, v), 4);
+	TEST(int_field_get_index(&gf, 4), v);
+	TEST(int_field_add(&gf, w), 5);
+	TEST(int_field_get_index(&gf, 5), w);
+	TEST(int_field_count(&gf), 6);
+	TEST((int_field_exclude_index(&gf, 1), EOK), EOK);
+	TEST(int_field_get_index(&gf, 1), NULL);
+	TEST(int_field_get_index(&gf, 3), u);
+	TEST((int_field_exclude_index(&gf, 7), EOK), EOK);
+	TEST(int_field_get_index(&gf, 3), u);
+	TEST(int_field_get_index(&gf, 5), w);
+	TEST((int_field_exclude_index(&gf, 4), EOK), EOK);
+	TEST(int_field_get_index(&gf, 4), NULL);
+	TEST((int_field_destroy(&gf), EOK), EOK);
+	TEST(int_field_count(&gf), -1);
+	
+	printf("\nInt map test");
+	
+	XMALLOC(x, int);
+	XMALLOC(y, int);
+	XMALLOC(z, int);
+	XMALLOC(u, int);
+	XMALLOC(v, int);
+	XMALLOC(w, int);
+	
+	int_map_t im;
+	im.magic = 0;
+	
+	TEST(int_map_add(&im, 1, x), EINVAL);
+	TEST(int_map_count(&im), -1);
+	TEST(int_map_initialize(&im), EOK);
+	TEST(int_map_count(&im), 0);
+	TEST(int_map_find(&im, 1), NULL);
+	TEST(int_map_add(&im, 1, x), 0);
+	TEST(int_map_find(&im, 1), x);
+	TEST((int_map_exclude(&im, 1), EOK), EOK);
+	TEST(int_map_find(&im, 1), NULL);
+	TEST(int_map_add(&im, 1, y), 1);
+	TEST(int_map_find(&im, 1), y);
+	TEST(int_map_add(&im, 4, z), 2);
+	TEST(int_map_get_index(&im, 2), z);
+	TEST(int_map_find(&im, 4), z);
+	TEST(int_map_find(&im, 1), y);
+	TEST(int_map_count(&im), 3);
+	TEST(int_map_add(&im, 2, u), 3);
+	TEST(int_map_find(&im, 2), u);
+	TEST(int_map_add(&im, 3, v), 4);
+	TEST(int_map_find(&im, 3), v);
+	TEST(int_map_get_index(&im, 4), v);
+	TEST(int_map_add(&im, 6, w), 5);
+	TEST(int_map_find(&im, 6), w);
+	TEST(int_map_count(&im), 6);
+	TEST((int_map_exclude(&im, 1), EOK), EOK);
+	TEST(int_map_find(&im, 1), NULL);
+	TEST(int_map_find(&im, 2), u);
+	TEST((int_map_exclude(&im, 7), EOK), EOK);
+	TEST(int_map_find(&im, 2), u);
+	TEST(int_map_find(&im, 6), w);
+	TEST((int_map_exclude_index(&im, 4), EOK), EOK);
+	TEST(int_map_get_index(&im, 4), NULL);
+	TEST(int_map_find(&im, 3), NULL);
+	TEST((int_map_destroy(&im), EOK), EOK);
+	TEST(int_map_count(&im), -1);
+	
+	printf("\nMeasured strings test");
+	
+	measured_string_ref string =
+	    measured_string_create_bulk("I am a measured string!", 0);
+	printf("\n%x, %s at %x of %d\n", string, string->value, string->value,
+	    string->length);
+	
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/app/netstart/self_test.h
===================================================================
--- uspace/app/netstart/self_test.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
+++ uspace/app/netstart/self_test.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * 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 net
+ * @{
+ */
+
+#ifndef __SELF_TEST_H__
+#define __SELF_TEST_H__
+
+extern int self_test(void);
+
+#endif
+
+/** @}
+ */
Index: uspace/drv/ns8250/ns8250.c
===================================================================
--- uspace/drv/ns8250/ns8250.c	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/drv/ns8250/ns8250.c	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -123,5 +123,5 @@
 static void delete_ns8250_dev_data(ns8250_dev_data_t *data)
 {
-	if (NULL != data)
+	if (data != NULL)
 		free(data);
 }
@@ -251,5 +251,5 @@
 static void ns8250_dev_cleanup(device_t *dev)
 {
-	if (NULL != dev->driver_data) {
+	if (dev->driver_data != NULL) {
 		delete_ns8250_dev_data((ns8250_dev_data_t*) dev->driver_data);
 		dev->driver_data = NULL;
@@ -332,5 +332,5 @@
 	/* Allocate driver data for the device. */
 	ns8250_dev_data_t *data = create_ns8250_dev_data();
-	if (NULL == data)
+	if (data == NULL)
 		return ENOMEM;
 	dev->driver_data = data;
@@ -436,5 +436,5 @@
 	/* Enable interrupt globally. */
 	res = interrupt_enable(data->irq);
-	if (EOK != res)
+	if (res != EOK)
 		return res;
 	
@@ -480,5 +480,5 @@
 	uint8_t div_low, div_high;
 	
-	if (50 > baud_rate || 0 != MAX_BAUD_RATE % baud_rate) {
+	if (baud_rate < 50 || MAX_BAUD_RATE % baud_rate != 0) {
 		printf(NAME ": error - somebody tried to set invalid baud rate "
 		    "%d\n", baud_rate);
@@ -534,6 +534,5 @@
  * @param stop_bits	The number of stop bits used (one or two).
  */
-static void
-ns8250_port_get_com_props(ioport8_t *port, unsigned int *parity,
+static void ns8250_port_get_com_props(ioport8_t *port, unsigned int *parity,
     unsigned int *word_length, unsigned int *stop_bits)
 {
@@ -572,6 +571,5 @@
  *			is invalid.
  */
-static int
-ns8250_port_set_com_props(ioport8_t *port, unsigned int parity,
+static int ns8250_port_set_com_props(ioport8_t *port, unsigned int parity,
     unsigned int word_length, unsigned int stop_bits)
 {
@@ -691,6 +689,6 @@
  * @param dev		The serial port device.
  */
-static inline void
-ns8250_interrupt_handler(device_t *dev, ipc_callid_t iid, ipc_call_t *icall)
+static inline void ns8250_interrupt_handler(device_t *dev, ipc_callid_t iid,
+    ipc_call_t *icall)
 {
 	ns8250_read_from_device(dev);
@@ -726,5 +724,5 @@
  * @param dev		The serial port device.
  */
-static int ns8250_add_device(device_t *dev) 
+static int ns8250_add_device(device_t *dev)
 {
 	printf(NAME ": ns8250_add_device %s (handle = %d)\n",
@@ -732,5 +730,5 @@
 	
 	int res = ns8250_dev_initialize(dev);
-	if (EOK != res)
+	if (res != EOK)
 		return res;
 	
@@ -750,5 +748,5 @@
 	
 	/* Register interrupt handler. */
-	if (EOK != ns8250_register_interrupt_handler(dev)) {
+	if (ns8250_register_interrupt_handler(dev) != EOK) {
 		printf(NAME ": failed to register interrupt handler.\n");
 		ns8250_dev_cleanup(dev);
@@ -758,5 +756,5 @@
 	/* Enable interrupt. */
 	res = ns8250_interrupt_enable(dev);
-	if (EOK != res) {
+	if (res != EOK) {
 		printf(NAME ": failed to enable the interrupt. Error code = "
 		    "%d.\n", res);
@@ -859,7 +857,6 @@
  * @param stop_bits	The number of stop bits to be used.
  */
-static int
-ns8250_set_props(device_t *dev, unsigned int baud_rate, unsigned int parity,
-    unsigned int word_length, unsigned int stop_bits)
+static int ns8250_set_props(device_t *dev, unsigned int baud_rate,
+    unsigned int parity, unsigned int word_length, unsigned int stop_bits)
 {
 	printf(NAME ": ns8250_set_props: baud rate %d, parity 0x%x, word "
@@ -874,5 +871,5 @@
 	ns8250_port_interrupts_disable(port);
 	ret = ns8250_port_set_baud_rate(port, baud_rate);
-	if (EOK == ret)
+	if (ret == EOK)
 		ret = ns8250_port_set_com_props(port, parity, word_length, stop_bits);
 	ns8250_port_interrupts_enable(port);
@@ -887,6 +884,6 @@
  * Configure the parameters of the serial communication.
  */
-static void
-ns8250_default_handler(device_t *dev, ipc_callid_t callid, ipc_call_t *call)
+static void ns8250_default_handler(device_t *dev, ipc_callid_t callid,
+    ipc_call_t *call)
 {
 	ipcarg_t method = IPC_GET_METHOD(*call);
Index: uspace/drv/pciintel/pci.c
===================================================================
--- uspace/drv/pciintel/pci.c	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/drv/pciintel/pci.c	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -65,5 +65,5 @@
 	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
 	
-	if (NULL == dev_data)
+	if (dev_data == NULL)
 		return NULL;
 	return &dev_data->hw_resources;
@@ -109,8 +109,9 @@
 	
 	bus_data = (pci_bus_data_t *) malloc(sizeof(pci_bus_data_t));
-	if (NULL != bus_data) {
+	if (bus_data != NULL) {
 		memset(bus_data, 0, sizeof(pci_bus_data_t));
 		fibril_mutex_initialize(&bus_data->conf_mutex);
 	}
+
 	return bus_data;
 }
@@ -123,5 +124,5 @@
 static void pci_conf_read(device_t *dev, int reg, uint8_t *buf, size_t len)
 {
-	assert(NULL != dev->parent);
+	assert(dev->parent != NULL);
 	
 	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
@@ -153,5 +154,5 @@
 static void pci_conf_write(device_t *dev, int reg, uint8_t *buf, size_t len)
 {
-	assert(NULL != dev->parent);
+	assert(dev->parent != NULL);
 	
 	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
@@ -224,5 +225,5 @@
 	
 	match_id = create_match_id();
-	if (NULL != match_id) {
+	if (match_id != NULL) {
 		asprintf(&match_id_str, "pci/ven=%04x&dev=%04x",
 		    dev_data->vendor_id, dev_data->device_id);
@@ -230,5 +231,6 @@
 		match_id->score = 90;
 		add_match_id(&dev->match_ids, match_id);
-	}	
+	}
+
 	/* TODO add more ids (with subsys ids, using class id etc.) */
 }
@@ -242,5 +244,5 @@
 	size_t count = hw_res_list->count;
 	
-	assert(NULL != hw_resources);
+	assert(hw_resources != NULL);
 	assert(count < PCI_MAX_HW_RES);
 	
@@ -275,5 +277,5 @@
 	bool io;
 	/* 64-bit wide address */
-	bool w64;
+	bool addrw64;
 	
 	/* Size of the io or memory range specified by the BAR */
@@ -287,12 +289,12 @@
 	io = (bool) (val & 1);
 	if (io) {
-		w64 = false;
+		addrw64 = false;
 	} else {
 		switch ((val >> 1) & 3) {
 		case 0:
-			w64 = false;
+			addrw64 = false;
 			break;
 		case 2:
-			w64 = true;
+			addrw64 = true;
 			break;
 		default:
@@ -312,5 +314,5 @@
 	range_size = pci_bar_mask_to_size(mask);
 	
-	if (w64) {
+	if (addrw64) {
 		range_addr = ((uint64_t)pci_conf_read_32(dev, addr + 4) << 32) |
 		    (val & 0xfffffff0);
@@ -319,5 +321,5 @@
 	}
 	
-	if (0 != range_addr) {
+	if (range_addr != 0) {
 		printf(NAME ": device %s : ", dev->name);
 		printf("address = %x", range_addr);
@@ -327,5 +329,5 @@
 	pci_add_range(dev, range_addr, range_size, io);
 	
-	if (w64)
+	if (addrw64)
 		return addr + 8;
 	
@@ -354,5 +356,5 @@
 {
 	uint8_t irq = pci_conf_read_8(dev, PCI_BRIDGE_INT_LINE);
-	if (0xff != irq)
+	if (irq != 0xff)
 		pci_add_interrupt(dev, irq);
 }
@@ -415,5 +417,5 @@
 			create_pci_match_ids(dev);
 			
-			if (EOK != child_device_register(dev, parent)) {
+			if (child_device_register(dev, parent) != EOK) {
 				pci_clean_resource_list(dev);
 				clean_match_ids(&dev->match_ids);
@@ -424,10 +426,10 @@
 			
 			if (header_type == PCI_HEADER_TYPE_BRIDGE ||
-			    header_type == PCI_HEADER_TYPE_CARDBUS ) {
+			    header_type == PCI_HEADER_TYPE_CARDBUS) {
 				child_bus = pci_conf_read_8(dev,
 				    PCI_BRIDGE_SEC_BUS_NUM);
 				printf(NAME ": device is pci-to-pci bridge, "
 				    "secondary bus number = %d.\n", bus_num);
-				if(child_bus > bus_num)
+				if (child_bus > bus_num)
 					pci_bus_scan(parent, child_bus);
 			}
@@ -453,5 +455,5 @@
 	
 	pci_bus_data_t *bus_data = create_pci_bus_data();
-	if (NULL == bus_data) {
+	if (bus_data == NULL) {
 		printf(NAME ": pci_add_device allocation failed.\n");
 		return ENOMEM;
@@ -513,4 +515,79 @@
 }
 
+pci_dev_data_t *create_pci_dev_data(void)
+{
+	pci_dev_data_t *res = (pci_dev_data_t *) malloc(sizeof(pci_dev_data_t));
+	
+	if (res != NULL)
+		memset(res, 0, sizeof(pci_dev_data_t));
+	return res;
+}
+
+void init_pci_dev_data(pci_dev_data_t *dev_data, int bus, int dev, int fn)
+{
+	dev_data->bus = bus;
+	dev_data->dev = dev;
+	dev_data->fn = fn;
+}
+
+void delete_pci_dev_data(pci_dev_data_t *dev_data)
+{
+	if (dev_data != NULL) {
+		clean_hw_resource_list(&dev_data->hw_resources);
+		free(dev_data);
+	}
+}
+
+void create_pci_dev_name(device_t *dev)
+{
+	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
+	char *name = NULL;
+	
+	asprintf(&name, "%02x:%02x.%01x", dev_data->bus, dev_data->dev,
+	    dev_data->fn);
+	dev->name = name;
+}
+
+bool pci_alloc_resource_list(device_t *dev)
+{
+	pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
+	
+	dev_data->hw_resources.resources =
+	    (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t));
+	return dev_data->hw_resources.resources != NULL;
+}
+
+void pci_clean_resource_list(device_t *dev)
+{
+	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
+	
+	if (dev_data->hw_resources.resources != NULL) {
+		free(dev_data->hw_resources.resources);
+		dev_data->hw_resources.resources = NULL;
+	}
+}
+
+/** Read the base address registers (BARs) of the device and adds the addresses
+ * to its hw resource list.
+ *
+ * @param dev the pci device.
+ */
+void pci_read_bars(device_t *dev)
+{
+	/*
+	 * Position of the BAR in the PCI configuration address space of the
+	 * device.
+	 */
+	int addr = PCI_BASE_ADDR_0;
+	
+	while (addr <= PCI_BASE_ADDR_5)
+		addr = pci_read_bar(dev, addr);
+}
+
+size_t pci_bar_mask_to_size(uint32_t mask)
+{
+	return ((mask & 0xfffffff0) ^ 0xffffffff) + 1;
+}
+
 int main(int argc, char *argv[])
 {
Index: uspace/drv/pciintel/pci.h
===================================================================
--- uspace/drv/pciintel/pci.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/drv/pciintel/pci.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -69,79 +69,14 @@
 extern void pci_bus_scan(device_t *, int);
 
-static inline pci_dev_data_t *create_pci_dev_data(void)
-{
-	pci_dev_data_t *res = (pci_dev_data_t *) malloc(sizeof(pci_dev_data_t));
-	
-	if (NULL != res)
-		memset(res, 0, sizeof(pci_dev_data_t));
-	return res;
-}
+extern pci_dev_data_t *create_pci_dev_data(void);
+extern void init_pci_dev_data(pci_dev_data_t *, int, int, int);
+extern void delete_pci_dev_data(pci_dev_data_t *);
+extern void create_pci_dev_name(device_t *);
 
-static inline void
-init_pci_dev_data(pci_dev_data_t *d, int bus, int dev, int fn)
-{
-	d->bus = bus;
-	d->dev = dev;
-	d->fn = fn;
-}
+extern bool pci_alloc_resource_list(device_t *);
+extern void pci_clean_resource_list(device_t *);
 
-static inline void delete_pci_dev_data(pci_dev_data_t *d)
-{
-	if (NULL != d) {
-		clean_hw_resource_list(&d->hw_resources);
-		free(d);
-	}
-}
-
-static inline void create_pci_dev_name(device_t *dev)
-{
-	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
-	char *name = NULL;
-	
-	asprintf(&name, "%02x:%02x.%01x", dev_data->bus, dev_data->dev,
-	    dev_data->fn);
-	dev->name = name;
-}
-
-static inline bool pci_alloc_resource_list(device_t *dev)
-{
-	pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
-	
-	dev_data->hw_resources.resources =
-	    (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t));
-	return dev_data->hw_resources.resources != NULL;
-}
-
-static inline void pci_clean_resource_list(device_t *dev)
-{
-	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
-	
-	if (NULL != dev_data->hw_resources.resources) {
-		free(dev_data->hw_resources.resources);
-		dev_data->hw_resources.resources = NULL;
-	}
-}
-
-/** Read the base address registers (BARs) of the device and adds the addresses
- * to its hw resource list.
- *
- * @param dev the pci device.
- */
-static inline  void pci_read_bars(device_t *dev)
-{
-	/*
-	 * Position of the BAR in the PCI configuration address space of the
-	 * device.
-	 */
-	int addr = PCI_BASE_ADDR_0;
-	
-	while (addr <= PCI_BASE_ADDR_5)
-		addr = pci_read_bar(dev, addr);
-}
-
-static inline size_t pci_bar_mask_to_size(uint32_t mask)
-{
-	return ((mask & 0xfffffff0) ^ 0xffffffff) + 1;
-}
+extern void pci_read_bars(device_t *);
+extern size_t pci_bar_mask_to_size(uint32_t);
 
 #endif
Index: uspace/lib/c/arch/abs32le/include/fibril.h
===================================================================
--- uspace/lib/c/arch/abs32le/include/fibril.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/arch/abs32le/include/fibril.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -44,4 +44,5 @@
 		(ctx)->pc = (uintptr_t) (_pc); \
 		(ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; \
+		(ctx)->fp = 0; \
 		(ctx)->tls = ((uintptr_t) (ptls)) + sizeof(tcb_t); \
 	} while (0)
@@ -53,7 +54,14 @@
 typedef struct {
 	uintptr_t sp;
+	uintptr_t fp;
 	uintptr_t pc;
 	uintptr_t tls;
 } context_t;
+
+static inline uintptr_t context_get_fp(context_t *ctx)
+{
+	/* On real hardware, this function returns the frame pointer. */
+	return ctx->fp;
+}
 
 #endif
Index: uspace/lib/c/arch/abs32le/include/istate.h
===================================================================
--- uspace/lib/c/arch/abs32le/include/istate.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/arch/abs32le/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -36,26 +36,5 @@
 #define LIBC_abs32le__ISTATE_H_
 
-#include <sys/types.h>
-
-/** Interrupt context.
- *
- * On real hardware this stores the registers which
- * need to be preserved during interupts.
- */
-typedef struct istate {
-	uintptr_t ip;
-	uintptr_t fp;
-	uint32_t stack[];
-} istate_t;
-
-static inline uintptr_t istate_get_pc(istate_t *istate)
-{
-	return istate->ip;
-}
-
-static inline uintptr_t istate_get_fp(istate_t *istate)
-{
-	return istate->fp;
-}
+#include <arch/istate.h>
 
 #endif
Index: uspace/lib/c/arch/amd64/include/fibril.h
===================================================================
--- uspace/lib/c/arch/amd64/include/fibril.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/arch/amd64/include/fibril.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -56,17 +56,22 @@
  */
 typedef struct {
-    uint64_t sp;
-    uint64_t pc;
-    
-    uint64_t rbx;
-    uint64_t rbp;
+	uint64_t sp;
+	uint64_t pc;
 
-    uint64_t r12;
-    uint64_t r13;
-    uint64_t r14;
-    uint64_t r15;
+	uint64_t rbx;
+	uint64_t rbp;
 
-    uint64_t tls;
+	uint64_t r12;
+	uint64_t r13;
+	uint64_t r14;
+	uint64_t r15;
+
+	uint64_t tls;
 } context_t;
+
+static inline uintptr_t context_get_fp(context_t *ctx)
+{
+	return ctx->rbp;
+}
 
 #endif
Index: uspace/lib/c/arch/amd64/include/istate.h
===================================================================
--- uspace/lib/c/arch/amd64/include/istate.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/arch/amd64/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -36,37 +36,5 @@
 #define LIBC_amd64_ISTATE_H_
 
-#include <sys/types.h>
-
-/** Interrupt context.
- *
- * This is a copy of the kernel definition with which it must be kept in sync.
- */
-typedef struct istate {
-	uint64_t rax;
-	uint64_t rcx;
-	uint64_t rdx;
-	uint64_t rsi;
-	uint64_t rdi;
-	uint64_t r8;
-	uint64_t r9;
-	uint64_t r10;
-	uint64_t r11;
-	uint64_t rbp;
-	uint64_t error_word;
-	uint64_t rip;
-	uint64_t cs;
-	uint64_t rflags;
-	uint64_t stack[]; /* Additional data on stack */
-} istate_t;
-
-static inline uintptr_t istate_get_pc(istate_t *istate)
-{
-	return istate->rip;
-}
-
-static inline uintptr_t istate_get_fp(istate_t *istate)
-{
-	return istate->rbp;
-}
+#include <arch/istate.h>
 
 #endif
Index: uspace/lib/c/arch/amd64/src/entry.s
===================================================================
--- uspace/lib/c/arch/amd64/src/entry.s	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/arch/amd64/src/entry.s	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -42,5 +42,5 @@
 	#
 	pushq $0
-	mov %rsp, %rbp
+	movq %rsp, %rbp
 	
 	# %rdi was deliberately chosen as the first argument is also in %rdi
Index: uspace/lib/c/arch/amd64/src/fibril.S
===================================================================
--- uspace/lib/c/arch/amd64/src/fibril.S	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/arch/amd64/src/fibril.S	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -49,6 +49,6 @@
 	movq %rax, OFFSET_TLS(%rdi)
 		
-	xorq %rax,%rax		# context_save returns 1
-	incq %rax
+	xorl %eax, %eax		# context_save returns 1
+	incl %eax
 	ret
 
@@ -67,7 +67,7 @@
 	# Set thread local storage
 	movq OFFSET_TLS(%rdi), %rdi   # Set arg1 to TLS addr
-	movq $1, %rax		# SYS_TLS_SET
+	movl $1, %eax		# SYS_TLS_SET
 	syscall
 
-	xorq %rax,%rax		# context_restore returns 0
+	xorl %eax, %eax		# context_restore returns 0
 	ret
Index: uspace/lib/c/arch/arm32/include/fibril.h
===================================================================
--- uspace/lib/c/arch/arm32/include/fibril.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/arch/arm32/include/fibril.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -86,4 +86,9 @@
 } context_t;
 
+static inline uintptr_t context_get_fp(context_t *ctx)
+{
+	return ctx->fp;
+}
+
 
 #endif
Index: uspace/lib/c/arch/arm32/include/istate.h
===================================================================
--- uspace/lib/c/arch/arm32/include/istate.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/arch/arm32/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -36,41 +36,5 @@
 #define LIBC_arm32__ISTATE_H_
 
-#include <sys/types.h>
-
-/** Interrupt context.
- *
- * This is a copy of the kernel definition with which it must be kept in sync.
- */
-typedef struct istate {
-	uint32_t spsr;
-	uint32_t sp;
-	uint32_t lr;
-
-	uint32_t r0;
-	uint32_t r1;
-	uint32_t r2;
-	uint32_t r3;
-	uint32_t r4;
-	uint32_t r5;
-	uint32_t r6;
-	uint32_t r7;
-	uint32_t r8;
-	uint32_t r9;
-	uint32_t r10;
-	uint32_t fp;
-	uint32_t r12;
-
-	uint32_t pc;
-} istate_t;
-
-static inline uintptr_t istate_get_pc(istate_t *istate)
-{
-	return istate->pc;
-}
-
-static inline uintptr_t istate_get_fp(istate_t *istate)
-{
-	return istate->fp;
-}
+#include <arch/istate.h>
 
 #endif
Index: uspace/lib/c/arch/ia32/include/fibril.h
===================================================================
--- uspace/lib/c/arch/ia32/include/fibril.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/arch/ia32/include/fibril.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -67,4 +67,9 @@
 } context_t;
 
+static inline uintptr_t context_get_fp(context_t *ctx)
+{
+	return ctx->ebp;
+}
+
 #endif
 
Index: uspace/lib/c/arch/ia32/include/istate.h
===================================================================
--- uspace/lib/c/arch/ia32/include/istate.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/arch/ia32/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -36,37 +36,5 @@
 #define LIBC_ia32__ISTATE_H_
 
-#include <sys/types.h>
-
-/** Interrupt context.
- *
- * This is a copy of the kernel definition with which it must be kept in sync.
- */
-typedef struct istate {
-	uint32_t eax;
-	uint32_t ecx;
-	uint32_t edx;
-	uint32_t ebp;
-
-	uint32_t gs;
-	uint32_t fs;
-	uint32_t es;
-	uint32_t ds;
-
-	uint32_t error_word;
-	uint32_t eip;
-	uint32_t cs;
-	uint32_t eflags;
-	uint32_t stack[];
-} istate_t;
-
-static inline uintptr_t istate_get_pc(istate_t *istate)
-{
-	return istate->eip;
-}
-
-static inline uintptr_t istate_get_fp(istate_t *istate)
-{
-	return istate->ebp;
-}
+#include <arch/istate.h>
 
 #endif
Index: uspace/lib/c/arch/ia64/include/fibril.h
===================================================================
--- uspace/lib/c/arch/ia64/include/fibril.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/arch/ia64/include/fibril.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -130,4 +130,9 @@
 } context_t;
 
+static inline uintptr_t context_get_fp(context_t *ctx)
+{
+	return 0;	/* FIXME */
+}
+
 #endif
 
Index: uspace/lib/c/arch/ia64/include/istate.h
===================================================================
--- uspace/lib/c/arch/ia64/include/istate.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/arch/ia64/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -36,25 +36,5 @@
 #define LIBC_ia64_ISTATE_H_
 
-#include <sys/types.h>
-
-/** Interrupt context.
- *
- * This is a copy of the kernel definition with which it must be kept in sync.
- */
-typedef struct istate {
-	/* TODO */
-} istate_t;
-
-static inline uintptr_t istate_get_pc(istate_t *istate)
-{
-	/* TODO */
-	return 0;
-}
-
-static inline uintptr_t istate_get_fp(istate_t *istate)
-{
-	/* TODO */
-	return 0;
-}
+#include <arch/istate.h>
 
 #endif
Index: uspace/lib/c/arch/mips32/include/fibril.h
===================================================================
--- uspace/lib/c/arch/mips32/include/fibril.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/arch/mips32/include/fibril.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -85,4 +85,9 @@
 } context_t;
 
+static inline uintptr_t context_get_fp(context_t *ctx)
+{
+	return ctx->sp;
+}
+
 #endif
 
Index: uspace/lib/c/arch/mips32/include/istate.h
===================================================================
--- uspace/lib/c/arch/mips32/include/istate.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/arch/mips32/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -36,50 +36,5 @@
 #define LIBC_mips32__ISTATE_H_
 
-#include <sys/types.h>
-
-/** Interrupt context.
- *
- * This is a copy of the kernel definition with which it must be kept in sync.
- */
-typedef struct istate {
-	uint32_t at;
-	uint32_t v0;
-	uint32_t v1;
-	uint32_t a0;
-	uint32_t a1;
-	uint32_t a2;
-	uint32_t a3;
-	uint32_t t0;
-	uint32_t t1;
-	uint32_t t2;
-	uint32_t t3;
-	uint32_t t4;
-	uint32_t t5;
-	uint32_t t6;
-	uint32_t t7;
-	uint32_t t8;
-	uint32_t t9;
-	uint32_t gp;
-	uint32_t sp;
-	uint32_t ra;
-
-	uint32_t lo;
-	uint32_t hi;
-
-	uint32_t status; /* cp0_status */
-	uint32_t epc; /* cp0_epc */
-	uint32_t k1; /* We use it as thread-local pointer */
-} istate_t;
-
-static inline uintptr_t istate_get_pc(istate_t *istate)
-{
-	return istate->epc;
-}
-
-static inline uintptr_t istate_get_fp(istate_t *istate)
-{
-	/* TODO */
-	return 0;
-}
+#include <arch/istate.h>
 
 #endif
Index: uspace/lib/c/arch/ppc32/include/fibril.h
===================================================================
--- uspace/lib/c/arch/ppc32/include/fibril.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/arch/ppc32/include/fibril.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -78,4 +78,9 @@
 } __attribute__ ((packed)) context_t;
 
+static inline uintptr_t context_get_fp(context_t *ctx)
+{
+	return ctx->sp;
+}
+
 #endif
 
Index: uspace/lib/c/arch/sparc64/include/fibril.h
===================================================================
--- uspace/lib/c/arch/sparc64/include/fibril.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/arch/sparc64/include/fibril.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -77,4 +77,9 @@
 } context_t;
 
+static inline uintptr_t context_get_fp(context_t *ctx)
+{
+	return ctx->sp + STACK_BIAS;
+}
+
 #endif
 
Index: uspace/lib/c/arch/sparc64/include/istate.h
===================================================================
--- uspace/lib/c/arch/sparc64/include/istate.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/arch/sparc64/include/istate.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -36,25 +36,5 @@
 #define LIBC_sparc64_ISTATE_H_
 
-#include <sys/types.h>
-
-/** Interrupt context.
- *
- * This is a copy of the kernel definition with which it must be kept in sync.
- */
-typedef struct istate {
-	/* TODO */
-} istate_t;
-
-static inline uintptr_t istate_get_pc(istate_t *istate)
-{
-	/* TODO */
-	return 0;
-}
-
-static inline uintptr_t istate_get_fp(istate_t *istate)
-{
-	/* TODO */
-	return 0;
-}
+#include <arch/istate.h>
 
 #endif
Index: uspace/lib/c/generic/fibril.c
===================================================================
--- uspace/lib/c/generic/fibril.c	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/generic/fibril.c	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -275,4 +275,6 @@
 	fibril->func = func;
 	fibril->arg = arg;
+
+	fibril->waits_for = NULL;
 	
 	context_save(&fibril->ctx);
Index: uspace/lib/c/generic/fibril_synch.c
===================================================================
--- uspace/lib/c/generic/fibril_synch.c	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/generic/fibril_synch.c	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -42,4 +42,6 @@
 #include <errno.h>
 #include <assert.h>
+#include <stacktrace.h>
+#include <stdlib.h>
 
 static void optimize_execution_power(void)
@@ -56,6 +58,42 @@
 }
 
+static bool check_for_deadlock(fibril_owner_info_t *oi)
+{
+	while (oi && oi->owned_by) {
+		if (oi->owned_by == (fibril_t *) fibril_get_id())
+			return true;
+		oi = oi->owned_by->waits_for;
+	}
+
+	return false;
+}
+
+static void print_deadlock(fibril_owner_info_t *oi)
+{
+	fibril_t *f = (fibril_t *) fibril_get_id();
+
+	printf("Deadlock detected.\n");
+	stacktrace_print();
+
+	printf("Fibril %p waits for primitive %p.\n", f, oi);
+
+	while (oi && oi->owned_by) {
+		printf("Primitive %p is owned by fibril %p.\n",
+		    oi, oi->owned_by);
+		if (oi->owned_by == f)
+			break;
+		stacktrace_print_fp_pc(context_get_fp(&oi->owned_by->ctx),
+		    oi->owned_by->ctx.pc);
+		printf("Fibril %p waits for primitive %p.\n",
+		     oi->owned_by, oi->owned_by->waits_for);
+		oi = oi->owned_by->waits_for;
+	}
+
+	abort();
+}
+
 void fibril_mutex_initialize(fibril_mutex_t *fm)
 {
+	fm->oi.owned_by = NULL;
 	fm->counter = 1;
 	list_initialize(&fm->waiters);
@@ -64,4 +102,6 @@
 void fibril_mutex_lock(fibril_mutex_t *fm)
 {
+	fibril_t *f = (fibril_t *) fibril_get_id();
+
 	futex_down(&async_futex);
 	if (fm->counter-- <= 0) {
@@ -73,6 +113,12 @@
 		link_initialize(&wdata.wu_event.link);
 		list_append(&wdata.wu_event.link, &fm->waiters);
+
+		if (check_for_deadlock(&fm->oi))
+			print_deadlock(&fm->oi);
+		f->waits_for = &fm->oi;
+
 		fibril_switch(FIBRIL_TO_MANAGER);
 	} else {
+		fm->oi.owned_by = f;
 		futex_up(&async_futex);
 	}
@@ -86,4 +132,5 @@
 	if (fm->counter > 0) {
 		fm->counter--;
+		fm->oi.owned_by = (fibril_t *) fibril_get_id();
 		locked = true;
 	}
@@ -99,4 +146,5 @@
 		link_t *tmp;
 		awaiter_t *wdp;
+		fibril_t *f;
 	
 		assert(!list_empty(&fm->waiters));
@@ -105,7 +153,14 @@
 		wdp->active = true;
 		wdp->wu_event.inlist = false;
+
+		f = (fibril_t *) wdp->fid;
+		fm->oi.owned_by = f;
+		f->waits_for = NULL;
+
 		list_remove(&wdp->wu_event.link);
 		fibril_add_ready(wdp->fid);
 		optimize_execution_power();
+	} else {
+		fm->oi.owned_by = NULL;
 	}
 }
@@ -120,4 +175,5 @@
 void fibril_rwlock_initialize(fibril_rwlock_t *frw)
 {
+	frw->oi.owned_by = NULL;
 	frw->writers = 0;
 	frw->readers = 0;
Index: uspace/lib/c/include/fibril.h
===================================================================
--- uspace/lib/c/include/fibril.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/include/fibril.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -48,4 +48,10 @@
 #define FIBRIL_WRITER      2
 
+struct fibril;
+
+typedef struct {
+	struct fibril *owned_by;
+} fibril_owner_info_t;
+
 typedef enum {
 	FIBRIL_PREEMPT,
@@ -68,4 +74,6 @@
 	int retval;
 	int flags;
+
+	fibril_owner_info_t *waits_for;
 } fibril_t;
 
Index: uspace/lib/c/include/fibril_synch.h
===================================================================
--- uspace/lib/c/include/fibril_synch.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/lib/c/include/fibril_synch.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -43,4 +43,5 @@
 
 typedef struct {
+	fibril_owner_info_t oi;		/* Keep this the first thing. */
 	int counter;
 	link_t waiters;
@@ -49,4 +50,7 @@
 #define FIBRIL_MUTEX_INITIALIZER(name) \
 	{ \
+		.oi = { \
+			.owned_by = NULL \
+		}, \
 		.counter = 1, \
 		.waiters = { \
@@ -60,4 +64,5 @@
 
 typedef struct {
+	fibril_owner_info_t oi;	/* Keep this the first thing. */
 	unsigned writers;
 	unsigned readers;
@@ -67,4 +72,7 @@
 #define FIBRIL_RWLOCK_INITIALIZER(name) \
 	{ \
+		.oi = { \
+			.owned_by = NULL \
+		}, \
 		.readers = 0, \
 		.writers = 0, \
Index: uspace/lib/packet/include/netdb.h
===================================================================
--- uspace/lib/packet/include/netdb.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
+++ uspace/lib/packet/include/netdb.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * 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 netdb
+ *  @{
+ */
+
+/** @file
+ *  Structures and interfaces according to the BSD netdb.h file.
+ */
+
+#ifndef __NET_NETDB_H__
+#define __NET_NETDB_H__
+
+#include <sys/types.h>
+
+/** Structure returned by network data base library.
+ *  All addresses are supplied in host order, and returned in network order (suitable for use in system calls).
+ */
+struct	hostent {
+	/** Official host name.
+	 */
+	char * h_name;
+	/** Alias list.
+	 */
+	char **	h_aliases;
+	/** Host address type.
+	 */
+	int h_addrtype;
+	/** Address length.
+	 */
+	int h_length;
+	/** List of addresses from name server.
+	 */
+	char **	h_addr_list;
+	/** Address, for backward compatiblity.
+	 */
+#define	h_addr	h_addr_list[0]
+};
+
+/** @name Host entry address types definitions.
+ */
+/*@{*/
+
+/** Authoritative Answer Host not found address type.
+ */
+#define	HOST_NOT_FOUND	1
+
+/** Non-Authoritive Host not found, or SERVERFAIL address type.
+ */
+#define	TRY_AGAIN	2
+
+/** Non recoverable errors, FORMERR, REFUSED, NOTIMP address type.
+ */
+#define	NO_RECOVERY	3
+
+/** Valid name, no data record of requested type address type.
+ */
+#define	NO_DATA		4
+
+/** No address, look for MX record address type.
+ */
+#define	NO_ADDRESS	NO_DATA
+
+/*@}*/
+
+/** Returns host entry by the host address.
+ *  @param[in] address The host address.
+ *  @param[in] len The address length.
+ *  @param[in] type The address type.
+ *  @returns Host entry information.
+ */
+//struct hostent *	gethostbyaddr(const void * address, int len, int type);
+
+/** Returns host entry by the host name.
+ *  @param[in] name The host name.
+ *  @returns Host entry information.
+ */
+//struct hostent *	gethostbyname(const char * name);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/packet/include/tcp_codes.h
===================================================================
--- uspace/lib/packet/include/tcp_codes.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
+++ uspace/lib/packet/include/tcp_codes.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * 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 tcp
+ *  @{
+ */
+
+/** @file
+ *  TCP options definitions.
+ */
+
+#ifndef __NET_TCP_CODES_H__
+#define __NET_TCP_CODES_H__
+
+/** End of list TCP option.
+ */
+#define TCPOPT_END_OF_LIST				0x0
+
+/** No operation TCP option.
+ */
+#define TCPOPT_NO_OPERATION				0x1
+
+/** Maximum segment size TCP option.
+ */
+#define TCPOPT_MAX_SEGMENT_SIZE			0x2
+
+/** Maximum segment size TCP option length.
+ */
+#define TCPOPT_MAX_SEGMENT_SIZE_LENGTH	4
+
+/** Window scale TCP option.
+ */
+#define TCPOPT_WINDOW_SCALE				0x3
+
+/** Window scale TCP option length.
+ */
+#define TCPOPT_WINDOW_SCALE_LENGTH		3
+
+/** Selective acknowledgement permitted TCP option.
+ */
+#define TCPOPT_SACK_PERMITTED			0x4
+
+/** Selective acknowledgement permitted TCP option length.
+ */
+#define TCPOPT_SACK_PERMITTED_LENGTH	2
+
+/** Selective acknowledgement TCP option.
+ *  Has variable length.
+ */
+#define TCPOPT_SACK						0x5
+
+/** Timestamp TCP option.
+ */
+#define TCPOPT_TIMESTAMP				0x8
+
+/** Timestamp TCP option length.
+ */
+#define TCPOPT_TIMESTAMP_LENGTH			10
+
+#endif
+
+/** @}
+ */
Index: uspace/srv/devman/devman.c
===================================================================
--- uspace/srv/devman/devman.c	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/srv/devman/devman.c	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -76,4 +76,18 @@
 	.remove_callback = devices_remove_callback
 };
+
+/**
+ * Initialize the list of device driver's.
+ *
+ * @param drv_list the list of device driver's.
+ *
+ */
+void init_driver_list(driver_list_t *drv_list)
+{
+	assert(drv_list != NULL);
+	
+	list_initialize(&drv_list->drivers);
+	fibril_mutex_initialize(&drv_list->drivers_mutex);
+}
 
 /** Allocate and initialize a new driver structure.
@@ -548,4 +562,45 @@
 }
 
+/** Initialize device driver structure.
+ *
+ * @param drv		The device driver structure.
+ */
+void init_driver(driver_t *drv)
+{
+	assert(drv != NULL);
+
+	memset(drv, 0, sizeof(driver_t));
+	list_initialize(&drv->match_ids.ids);
+	list_initialize(&drv->devices);
+	fibril_mutex_initialize(&drv->driver_mutex);
+}
+
+/** Device driver structure clean-up.
+ *
+ * @param drv		The device driver structure.
+ */
+void clean_driver(driver_t *drv)
+{
+	assert(drv != NULL);
+
+	free_not_null(drv->name);
+	free_not_null(drv->binary_path);
+
+	clean_match_ids(&drv->match_ids);
+
+	init_driver(drv);
+}
+
+/** Delete device driver structure.
+ *
+ * @param drv		The device driver structure.
+ */
+void delete_driver(driver_t *drv)
+{
+	assert(drv != NULL);
+	
+	clean_driver(drv);
+	free(drv);
+}
 
 /** Create devmap path and name for the device. */
@@ -685,4 +740,73 @@
 }
 
+/* Device nodes */
+
+/** Create a new device node.
+ *
+ * @return		A device node structure.
+ */
+node_t *create_dev_node(void)
+{
+	node_t *res = malloc(sizeof(node_t));
+	
+	if (res != NULL) {
+		memset(res, 0, sizeof(node_t));
+		list_initialize(&res->children);
+		list_initialize(&res->match_ids.ids);
+		list_initialize(&res->classes);
+	}
+	
+	return res;
+}
+
+/** Delete a device node.
+ *
+ * @param node		The device node structure.
+ */
+void delete_dev_node(node_t *node)
+{
+	assert(list_empty(&node->children));
+	assert(node->parent == NULL);
+	assert(node->drv == NULL);
+	
+	clean_match_ids(&node->match_ids);
+	free_not_null(node->name);
+	free_not_null(node->pathname);
+	free(node);
+}
+
+/** Find the device node structure of the device witch has the specified handle.
+ *
+ * Device tree's rwlock should be held at least for reading.
+ *
+ * @param tree		The device tree where we look for the device node.
+ * @param handle	The handle of the device.
+ * @return		The device node.
+ */
+node_t *find_dev_node_no_lock(dev_tree_t *tree, device_handle_t handle)
+{
+	unsigned long key = handle;
+	link_t *link = hash_table_find(&tree->devman_devices, &key);
+	return hash_table_get_instance(link, node_t, devman_link);
+}
+
+/** Find the device node structure of the device witch has the specified handle.
+ *
+ * @param tree		The device tree where we look for the device node.
+ * @param handle	The handle of the device.
+ * @return		The device node.
+ */
+node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle)
+{
+	node_t *node = NULL;
+	
+	fibril_rwlock_read_lock(&tree->rwlock);
+	node = find_dev_node_no_lock(tree, handle);
+	fibril_rwlock_read_unlock(&tree->rwlock);
+	
+	return node;
+}
+
+
 /** Create and set device's full path in device tree.
  *
@@ -825,4 +949,51 @@
 	return NULL;
 }
+
+/* Device classes */
+
+/** Create device class.
+ *
+ * @return	Device class.
+ */
+dev_class_t *create_dev_class(void)
+{
+	dev_class_t *cl;
+	
+	cl = (dev_class_t *) malloc(sizeof(dev_class_t));
+	if (cl != NULL) {
+		memset(cl, 0, sizeof(dev_class_t));
+		list_initialize(&cl->devices);
+		fibril_mutex_initialize(&cl->mutex);
+	}
+	
+	return cl;
+}
+
+/** Create device class info.
+ *
+ * @return		Device class info.
+ */
+dev_class_info_t *create_dev_class_info(void)
+{
+	dev_class_info_t *info;
+	
+	info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t));
+	if (info != NULL)
+		memset(info, 0, sizeof(dev_class_info_t));
+	
+	return info;
+}
+
+size_t get_new_class_dev_idx(dev_class_t *cl)
+{
+	size_t dev_idx;
+	
+	fibril_mutex_lock(&cl->mutex);
+	dev_idx = ++cl->curr_dev_idx;
+	fibril_mutex_unlock(&cl->mutex);
+	
+	return dev_idx;
+}
+
 
 /** Create unique device name within the class.
@@ -921,4 +1092,9 @@
 }
 
+void add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl)
+{
+	list_append(&cl->link, &class_list->classes);
+}
+
 void init_class_list(class_list_t *class_list)
 {
@@ -930,5 +1106,5 @@
 
 
-/* devmap devices */
+/* Devmap devices */
 
 node_t *find_devmap_tree_device(dev_tree_t *tree, dev_handle_t devmap_handle)
@@ -967,4 +1143,21 @@
 }
 
+void class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli)
+{
+	unsigned long key = (unsigned long) cli->devmap_handle;
+	
+	fibril_rwlock_write_lock(&class_list->rwlock);
+	hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
+	fibril_rwlock_write_unlock(&class_list->rwlock);
+}
+
+void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
+{
+	unsigned long key = (unsigned long) node->devmap_handle;
+	fibril_rwlock_write_lock(&tree->rwlock);
+	hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
+	fibril_rwlock_write_unlock(&tree->rwlock);
+}
+
 /** @}
  */
Index: uspace/srv/devman/devman.h
===================================================================
--- uspace/srv/devman/devman.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/srv/devman/devman.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -283,18 +283,5 @@
 /* Drivers */
 
-/**
- * Initialize the list of device driver's.
- *
- * @param drv_list the list of device driver's.
- *
- */
-static inline void init_driver_list(driver_list_t *drv_list)
-{
-	assert(drv_list != NULL);
-	
-	list_initialize(&drv_list->drivers);
-	fibril_mutex_initialize(&drv_list->drivers_mutex);
-}
-
+extern void init_driver_list(driver_list_t *);
 extern driver_t *create_driver(void);
 extern bool get_driver_info(const char *, const char *, driver_t *);
@@ -311,121 +298,19 @@
 extern driver_t *find_driver(driver_list_t *, const char *);
 extern void set_driver_phone(driver_t *, ipcarg_t);
-void initialize_running_driver(driver_t *, dev_tree_t *);
-
-/** Initialize device driver structure.
- *
- * @param drv		The device driver structure.
- */
-static inline void init_driver(driver_t *drv)
-{
-	assert(drv != NULL);
-
-	memset(drv, 0, sizeof(driver_t));
-	list_initialize(&drv->match_ids.ids);
-	list_initialize(&drv->devices);
-	fibril_mutex_initialize(&drv->driver_mutex);
-}
-
-/** Device driver structure clean-up.
- *
- * @param drv		The device driver structure.
- */
-static inline void clean_driver(driver_t *drv)
-{
-	assert(drv != NULL);
-
-	free_not_null(drv->name);
-	free_not_null(drv->binary_path);
-
-	clean_match_ids(&drv->match_ids);
-
-	init_driver(drv);
-}
-
-/** Delete device driver structure.
- *
- * @param drv		The device driver structure.
- */
-static inline void delete_driver(driver_t *drv)
-{
-	assert(drv != NULL);
-	
-	clean_driver(drv);
-	free(drv);
-}
-
+extern void initialize_running_driver(driver_t *, dev_tree_t *);
+
+extern void init_driver(driver_t *);
+extern void clean_driver(driver_t *);
+extern void delete_driver(driver_t *);
 
 /* Device nodes */
 
-/** Create a new device node.
- *
- * @return		A device node structure.
- */
-static inline node_t *create_dev_node(void)
-{
-	node_t *res = malloc(sizeof(node_t));
-	
-	if (res != NULL) {
-		memset(res, 0, sizeof(node_t));
-		list_initialize(&res->children);
-		list_initialize(&res->match_ids.ids);
-		list_initialize(&res->classes);
-	}
-	
-	return res;
-}
-
-/** Delete a device node.
- *
- * @param node		The device node structure.
- */
-static inline void delete_dev_node(node_t *node)
-{
-	assert(list_empty(&node->children));
-	assert(node->parent == NULL);
-	assert(node->drv == NULL);
-	
-	clean_match_ids(&node->match_ids);
-	free_not_null(node->name);
-	free_not_null(node->pathname);
-	free(node);
-}
-
-/** Find the device node structure of the device witch has the specified handle.
- *
- * Device tree's rwlock should be held at least for reading.
- *
- * @param tree		The device tree where we look for the device node.
- * @param handle	The handle of the device.
- * @return		The device node.
- */
-static inline node_t *find_dev_node_no_lock(dev_tree_t *tree,
-    device_handle_t handle)
-{
-	unsigned long key = handle;
-	link_t *link = hash_table_find(&tree->devman_devices, &key);
-	return hash_table_get_instance(link, node_t, devman_link);
-}
-
-/** Find the device node structure of the device witch has the specified handle.
- *
- * @param tree		The device tree where we look for the device node.
- * @param handle	The handle of the device.
- * @return		The device node.
- */
-static inline node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle)
-{
-	node_t *node = NULL;
-	
-	fibril_rwlock_read_lock(&tree->rwlock);
-	node = find_dev_node_no_lock(tree, handle);
-	fibril_rwlock_read_unlock(&tree->rwlock);
-	
-	return node;
-}
-
+extern node_t *create_dev_node(void);
+extern void delete_dev_node(node_t *node);
+extern node_t *find_dev_node_no_lock(dev_tree_t *tree,
+    device_handle_t handle);
+extern node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle);
 extern node_t *find_dev_node_by_path(dev_tree_t *, char *);
 extern node_t *find_node_child(node_t *, const char *);
-
 
 /* Device tree */
@@ -435,51 +320,9 @@
 extern bool insert_dev_node(dev_tree_t *, node_t *, char *, node_t *);
 
-
 /* Device classes */
 
-/** Create device class.
- *
- * @return	Device class.
- */
-static inline dev_class_t *create_dev_class(void)
-{
-	dev_class_t *cl;
-	
-	cl = (dev_class_t *) malloc(sizeof(dev_class_t));
-	if (cl != NULL) {
-		memset(cl, 0, sizeof(dev_class_t));
-		list_initialize(&cl->devices);
-		fibril_mutex_initialize(&cl->mutex);
-	}
-	
-	return cl;
-}
-
-/** Create device class info.
- *
- * @return		Device class info.
- */
-static inline dev_class_info_t *create_dev_class_info(void)
-{
-	dev_class_info_t *info;
-	
-	info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t));
-	if (info != NULL)
-		memset(info, 0, sizeof(dev_class_info_t));
-	
-	return info;
-}
-
-static inline size_t get_new_class_dev_idx(dev_class_t *cl)
-{
-	size_t dev_idx;
-	
-	fibril_mutex_lock(&cl->mutex);
-	dev_idx = ++cl->curr_dev_idx;
-	fibril_mutex_unlock(&cl->mutex);
-	
-	return dev_idx;
-}
-
+extern dev_class_t *create_dev_class(void);
+extern dev_class_info_t *create_dev_class_info(void);
+extern size_t get_new_class_dev_idx(dev_class_t *);
 extern char *create_dev_name_for_class(dev_class_t *, const char *);
 extern dev_class_info_t *add_device_to_class(node_t *, dev_class_t *,
@@ -490,11 +333,5 @@
 extern dev_class_t *get_dev_class(class_list_t *, char *);
 extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *);
-
-static inline void add_dev_class_no_lock(class_list_t *class_list,
-    dev_class_t *cl)
-{
-	list_append(&cl->link, &class_list->classes);
-}
-
+extern void add_dev_class_no_lock(class_list_t *, dev_class_t *);
 
 /* Devmap devices */
@@ -503,21 +340,6 @@
 extern node_t *find_devmap_class_device(class_list_t *, dev_handle_t);
 
-static inline void class_add_devmap_device(class_list_t *class_list,
-    dev_class_info_t *cli)
-{
-	unsigned long key = (unsigned long) cli->devmap_handle;
-	
-	fibril_rwlock_write_lock(&class_list->rwlock);
-	hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
-	fibril_rwlock_write_unlock(&class_list->rwlock);
-}
-
-static inline void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
-{
-	unsigned long key = (unsigned long) node->devmap_handle;
-	fibril_rwlock_write_lock(&tree->rwlock);
-	hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
-	fibril_rwlock_write_unlock(&tree->rwlock);
-}
+extern void class_add_devmap_device(class_list_t *, dev_class_info_t *);
+extern void tree_add_devmap_device(dev_tree_t *, node_t *);
 
 #endif
Index: uspace/srv/devman/main.c
===================================================================
--- uspace/srv/devman/main.c	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/srv/devman/main.c	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -66,10 +66,11 @@
 static driver_t *devman_driver_register(void)
 {
+	ipc_call_t icall;
+	ipc_callid_t iid;
+	driver_t *driver = NULL;
+
 	printf(NAME ": devman_driver_register \n");
 	
-	ipc_call_t icall;
-	ipc_callid_t iid = async_get_call(&icall);
-	driver_t *driver = NULL;
-	
+	iid = async_get_call(&icall);
 	if (IPC_GET_METHOD(icall) != DEVMAN_DRIVER_REGISTER) {
 		ipc_answer_0(iid, EREFUSED);
@@ -85,4 +86,5 @@
 		return NULL;
 	}
+
 	printf(NAME ": the %s driver is trying to register by the service.\n",
 	    drv_name);
@@ -91,5 +93,5 @@
 	driver = find_driver(&drivers_list, drv_name);
 	
-	if (NULL == driver) {
+	if (driver == NULL) {
 		printf(NAME ": no driver named %s was found.\n", drv_name);
 		free(drv_name);
@@ -146,5 +148,5 @@
 	}
 	
-	if (NULL == match_id) {
+	if (match_id == NULL) {
 		printf(NAME ": ERROR: devman_receive_match_id - failed to "
 		    "allocate match id.\n");
@@ -160,5 +162,5 @@
 	rc = async_data_write_accept((void **) &match_id_str, true, 0, 0, 0, 0);
 	match_id->id = match_id_str;
-	if (EOK != rc) {
+	if (rc != EOK) {
 		delete_match_id(match_id);
 		printf(NAME ": devman_receive_match_id - failed to receive "
@@ -181,6 +183,6 @@
  * @return		Zero on success, negative error code otherwise.
  */
-static int
-devman_receive_match_ids(ipcarg_t match_count, match_id_list_t *match_ids)
+static int devman_receive_match_ids(ipcarg_t match_count,
+    match_id_list_t *match_ids)
 {
 	int ret = EOK;
@@ -205,15 +207,15 @@
 	
 	fibril_rwlock_write_lock(&tree->rwlock);
-	node_t *parent =  find_dev_node_no_lock(&device_tree, parent_handle);
-	
-	if (NULL == parent) {
+	node_t *parent = find_dev_node_no_lock(&device_tree, parent_handle);
+	
+	if (parent == NULL) {
 		fibril_rwlock_write_unlock(&tree->rwlock);
 		ipc_answer_0(callid, ENOENT);
 		return;
-	}	
+	}
 	
 	char *dev_name = NULL;
 	int rc = async_data_write_accept((void **)&dev_name, true, 0, 0, 0, 0);
-	if (EOK != rc) {
+	if (rc != EOK) {
 		fibril_rwlock_write_unlock(&tree->rwlock);
 		ipc_answer_0(callid, rc);
@@ -227,5 +229,6 @@
 		ipc_answer_0(callid, ENOMEM);
 		return;
-	}	
+	}
+
 	fibril_rwlock_write_unlock(&tree->rwlock);
 	
@@ -245,7 +248,8 @@
 	/* Create devmap path and name for the device. */
 	char *devmap_pathname = NULL;
+
 	asprintf(&devmap_pathname, "%s/%s%c%s", DEVMAP_CLASS_NAMESPACE,
 	    cli->dev_class->name, DEVMAP_SEPARATOR, cli->dev_name);
-	if (NULL == devmap_pathname)
+	if (devmap_pathname == NULL)
 		return;
 	
@@ -279,5 +283,5 @@
 	
 	node_t *dev = find_dev_node(&device_tree, handle);
-	if (NULL == dev) {
+	if (dev == NULL) {
 		ipc_answer_0(callid, ENOENT);
 		return;
@@ -318,5 +322,5 @@
 	
 	driver_t *driver = devman_driver_register();
-	if (NULL == driver)
+	if (driver == NULL)
 		return;
 	
@@ -373,5 +377,5 @@
 	free(pathname);
 
-	if (NULL == dev) {
+	if (dev == NULL) {
 		ipc_answer_0(iid, ENOENT);
 		return;
@@ -404,14 +408,14 @@
 				ipc_answer_0(callid, ENOENT);
 		}
-	}	
-}
-
-static void
-devman_forward(ipc_callid_t iid, ipc_call_t *icall, bool drv_to_parent)
+	}
+}
+
+static void devman_forward(ipc_callid_t iid, ipc_call_t *icall,
+    bool drv_to_parent)
 {
 	device_handle_t handle = IPC_GET_ARG2(*icall);
 	
 	node_t *dev = find_dev_node(&device_tree, handle);
-	if (NULL == dev) {
+	if (dev == NULL) {
 		printf(NAME ": devman_forward error - no device with handle %x "
 		    "was found.\n", handle);
@@ -423,12 +427,12 @@
 	
 	if (drv_to_parent) {
-		if (NULL != dev->parent)
+		if (dev->parent != NULL)
 			driver = dev->parent->drv;
-	} else if (DEVICE_USABLE == dev->state) {
+	} else if (dev->state == DEVICE_USABLE) {
 		driver = dev->drv;
-		assert(NULL != driver);
-	}
-	
-	if (NULL == driver) {
+		assert(driver != NULL);
+	}
+	
+	if (driver == NULL) {
 		printf(NAME ": devman_forward error - the device is not in "
 		    "usable state.\n", handle);
@@ -450,4 +454,5 @@
 		return;
 	}
+
 	printf(NAME ": devman_forward: forward connection to device %s to "
 	    "driver %s.\n", dev->pathname, driver->name);
@@ -460,15 +465,16 @@
 {
 	dev_handle_t devmap_handle = IPC_GET_METHOD(*icall);
-	
-	node_t *dev = find_devmap_tree_device(&device_tree, devmap_handle);
-	if (NULL == dev)
+	node_t *dev;
+
+	dev = find_devmap_tree_device(&device_tree, devmap_handle);
+	if (dev == NULL)
 		dev = find_devmap_class_device(&class_list, devmap_handle);
 	
-	if (NULL == dev || NULL == dev->drv) {
+	if (dev == NULL || dev->drv == NULL) {
 		ipc_answer_0(iid, ENOENT);
 		return;
 	}
 	
-	if (DEVICE_USABLE != dev->state || dev->drv->phone <= 0) {
+	if (dev->state != DEVICE_USABLE || dev->drv->phone <= 0) {
 		ipc_answer_0(iid, EINVAL);
 		return;
@@ -493,5 +499,5 @@
 	 * passes device handle to the driver as an ipc method.)
 	 */
-	if (IPC_M_CONNECT_ME_TO != IPC_GET_METHOD(*icall))
+	if (IPC_GET_METHOD(*icall) != IPC_M_CONNECT_ME_TO)
 		devman_connection_devmapper(iid, icall);
 
@@ -531,9 +537,10 @@
 	/* Initialize list of available drivers. */
 	init_driver_list(&drivers_list);
-	if (0 == lookup_available_drivers(&drivers_list,
-	    DRIVER_DEFAULT_STORE)) {
+	if (lookup_available_drivers(&drivers_list,
+	    DRIVER_DEFAULT_STORE) == 0) {
 		printf(NAME " no drivers found.");
 		return false;
 	}
+
 	printf(NAME ": devman_init  - list of drivers has been initialized.\n");
 
Index: uspace/srv/devman/match.c
===================================================================
--- uspace/srv/devman/match.c	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/srv/devman/match.c	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -55,5 +55,5 @@
 		match_id_t *tmp_ma_id;
 	
-		if (0 == str_cmp(drv_id->id, dev_id->id)) {
+		if (str_cmp(drv_id->id, dev_id->id) == 0) {
 		 	/*
 		 	 * We found a match.
@@ -67,5 +67,5 @@
 		 * list of match ids.
 		 */
-		if (drv_head != drv_link->next) {
+		if (drv_link->next != drv_head) {
 			tmp_ma_id = list_get_instance(drv_link->next,
 			    match_id_t, link);
@@ -79,5 +79,5 @@
 		 * list of match ids.
 		 */
-		if (dev_head != dev_link->next) {
+		if (dev_link->next != dev_head) {
 			tmp_ma_id = list_get_instance(dev_link->next,
 			    match_id_t, link);
@@ -99,5 +99,5 @@
 		}
 		
-	} while (drv_head != drv_link->next && dev_head != dev_link->next);
+	} while (drv_link->next != drv_head && dev_link->next != dev_head);
 	
 	return 0;
Index: uspace/srv/devman/util.c
===================================================================
--- uspace/srv/devman/util.c	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/srv/devman/util.c	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -61,9 +61,54 @@
 char *get_path_elem_end(char *path)
 {
-	while (0 != *path && '/' != *path)
+	while (*path != '\0' && *path != '/')
 		path++;
 	return path;
 }
 
+bool skip_spaces(char **buf)
+{
+	while (isspace(**buf))
+		(*buf)++;
+	return *buf != 0;
+}
+
+size_t get_nonspace_len(const char *str)
+{
+	size_t len = 0;
+	
+	while(*str != '\0' && !isspace(*str)) {
+		len++;
+		str++;
+	}
+
+	return len;
+}
+
+void free_not_null(const void *ptr)
+{
+	if (ptr != NULL)
+		free(ptr);
+}
+
+char *clone_string(const char *s)
+{
+	size_t size = str_size(s) + 1;
+	char *str;
+	
+	str = (char *) malloc(size);
+	if (str != NULL)
+		str_cpy(str, size, s);
+	return str;
+}
+
+void replace_char(char *str, char orig, char repl)
+{
+	while (*str) {
+		if (*str == orig)
+			*str = repl;
+		str++;
+	}
+}
+
 /** @}
  */
Index: uspace/srv/devman/util.h
===================================================================
--- uspace/srv/devman/util.h	(revision b4458033b291d1f25ef9d01e533d76655875b4d6)
+++ uspace/srv/devman/util.h	(revision 7ae3d6f9d860f518c19f0060df70099eddaf81a0)
@@ -41,47 +41,9 @@
 extern char *get_path_elem_end(char *);
 
-static inline bool skip_spaces(char **buf)
-{
-	while (isspace(**buf))
-		(*buf)++;
-	return *buf != 0;
-}
-
-static inline size_t get_nonspace_len(const char *str)
-{
-	size_t len = 0;
-	
-	while(*str != 0 && !isspace(*str)) {
-		len++;
-		str++;
-	}
-	return len;
-}
-
-static inline void free_not_null(const void *ptr)
-{
-	if (NULL != ptr)
-		free(ptr);
-}
-
-static inline char *clone_string(const char *s)
-{
-	size_t size = str_size(s) + 1;
-	char *str;
-	
-	str = (char *) malloc(size);
-	if (NULL != str)
-		str_cpy(str, size, s);
-	return str;
-}
-
-static inline void replace_char(char *str, char orig, char repl)
-{
-	while (*str) {
-		if (orig == *str)
-			*str = repl;
-		str++;
-	}
-}
+extern bool skip_spaces(char **);
+extern size_t get_nonspace_len(const char *);
+extern void free_not_null(const void *);
+extern char *clone_string(const char *);
+extern void replace_char(char *, char, char);
 
 #endif
