Index: tools/autotool.py
===================================================================
--- tools/autotool.py	(revision 86d0c263cc77c028ccff0c4d9651abe25a22b5c6)
+++ tools/autotool.py	(revision bf85e56c7095e7c326a3411862e8cfe45fe52b80)
@@ -181,4 +181,76 @@
 		print_error(["Failed to determine the value %s." % key,
 		             "Please contact the developers of HelenOS."])
+
+def get_target(config, needs_clang = False):
+	target = None
+	gnu_target = None
+	clang_target = None
+	cc_args = []
+	
+	if (config['PLATFORM'] == "abs32le"):
+		check_config(config, "CROSS_TARGET")
+		target = config['CROSS_TARGET']
+		
+		if (config['CROSS_TARGET'] == "arm32"):
+			gnu_target = "arm-linux-gnueabi"
+		
+		if (config['CROSS_TARGET'] == "ia32"):
+			gnu_target = "i686-pc-linux-gnu"
+		
+		if (config['CROSS_TARGET'] == "mips32"):
+			gnu_target = "mipsel-linux-gnu"
+			common['CC_ARGS'].append("-mabi=32")
+	
+	if (config['PLATFORM'] == "amd64"):
+		target = config['PLATFORM']
+		gnu_target = "amd64-linux-gnu"
+		clang_target = "x86_64-uknown-linux"
+	
+	if (config['PLATFORM'] == "arm32"):
+		target = config['PLATFORM']
+		gnu_target = "arm-linux-gnueabi"
+	
+	if (config['PLATFORM'] == "ia32"):
+		target = config['PLATFORM']
+		gnu_target = "i686-pc-linux-gnu"
+		clang_target = "i386-uknown-linux"
+	
+	if (config['PLATFORM'] == "ia64"):
+		target = config['PLATFORM']
+		gnu_target = "ia64-pc-linux-gnu"
+	
+	if (config['PLATFORM'] == "mips32"):
+		check_config(config, "MACHINE")
+		cc_args.append("-mabi=32")
+		
+		if ((config['MACHINE'] == "msim") or (config['MACHINE'] == "lmalta")):
+			target = config['PLATFORM']
+			gnu_target = "mipsel-linux-gnu"
+		
+		if ((config['MACHINE'] == "bmalta")):
+			target = "mips32eb"
+			gnu_target = "mips-linux-gnu"
+	
+	if (config['PLATFORM'] == "mips64"):
+		check_config(config, "MACHINE")
+		cc_args.append("-mabi=64")
+		
+		if (config['MACHINE'] == "msim"):
+			target = config['PLATFORM']
+			gnu_target = "mips64el-linux-gnu"
+	
+	if (config['PLATFORM'] == "ppc32"):
+		target = config['PLATFORM']
+		gnu_target = "ppc-linux-gnu"
+	
+	if (config['PLATFORM'] == "sparc64"):
+		target = config['PLATFORM']
+		gnu_target = "sparc64-linux-gnu"
+	
+	if (target is None) or (gnu_target is None) or (clang_target is None and needs_clang):
+		print_error(["Failed to determine target for compiler.",
+		             "Please contact the developers of HelenOS."])
+	
+	return (target, cc_args, gnu_target, clang_target)
 
 def check_app(args, name, details):
@@ -642,62 +714,5 @@
 		common['CC_ARGS'] = []
 		if (config['COMPILER'] == "gcc_cross"):
-			if (config['PLATFORM'] == "abs32le"):
-				check_config(config, "CROSS_TARGET")
-				target = config['CROSS_TARGET']
-				
-				if (config['CROSS_TARGET'] == "arm32"):
-					gnu_target = "arm-linux-gnueabi"
-				
-				if (config['CROSS_TARGET'] == "ia32"):
-					gnu_target = "i686-pc-linux-gnu"
-				
-				if (config['CROSS_TARGET'] == "mips32"):
-					gnu_target = "mipsel-linux-gnu"
-					common['CC_ARGS'].append("-mabi=32")
-			
-			if (config['PLATFORM'] == "amd64"):
-				target = config['PLATFORM']
-				gnu_target = "amd64-linux-gnu"
-			
-			if (config['PLATFORM'] == "arm32"):
-				target = config['PLATFORM']
-				gnu_target = "arm-linux-gnueabi"
-			
-			if (config['PLATFORM'] == "ia32"):
-				target = config['PLATFORM']
-				gnu_target = "i686-pc-linux-gnu"
-			
-			if (config['PLATFORM'] == "ia64"):
-				target = config['PLATFORM']
-				gnu_target = "ia64-pc-linux-gnu"
-			
-			if (config['PLATFORM'] == "mips32"):
-				check_config(config, "MACHINE")
-				common['CC_ARGS'].append("-mabi=32")
-				
-				if ((config['MACHINE'] == "msim") or (config['MACHINE'] == "lmalta")):
-					target = config['PLATFORM']
-					gnu_target = "mipsel-linux-gnu"
-				
-				if ((config['MACHINE'] == "bmalta")):
-					target = "mips32eb"
-					gnu_target = "mips-linux-gnu"
-			
-			if (config['PLATFORM'] == "mips64"):
-				check_config(config, "MACHINE")
-				common['CC_ARGS'].append("-mabi=64")
-				
-				if (config['MACHINE'] == "msim"):
-					target = config['PLATFORM']
-					gnu_target = "mips64el-linux-gnu"
-			
-			if (config['PLATFORM'] == "ppc32"):
-				target = config['PLATFORM']
-				gnu_target = "ppc-linux-gnu"
-			
-			if (config['PLATFORM'] == "sparc64"):
-				target = config['PLATFORM']
-				gnu_target = "sparc64-linux-gnu"
-			
+			target, cc_args, gnu_target, clang_target_unused = get_target(config)
 			path = "%s/%s/bin" % (cross_prefix, target)
 			prefix = "%s-" % gnu_target
@@ -708,4 +723,5 @@
 			check_common(common, "GCC")
 			common['CC'] = common['GCC']
+			common['CC_ARGS'].extend(cc_args)
 		
 		if (config['COMPILER'] == "gcc_native"):
@@ -723,8 +739,15 @@
 		
 		if (config['COMPILER'] == "clang"):
+			target, cc_args, gnu_target, clang_target = get_target(config, True)
+			path = "%s/%s/bin" % (cross_prefix, target)
+			prefix = "%s-" % gnu_target
+			
 			common['CC'] = "clang"
+			common['CC_ARGS'].extend(cc_args)
+			common['CC_ARGS'].append("-target")
+			common['CC_ARGS'].append(clang_target)
 			check_app([common['CC'], "--version"], "Clang compiler", "preferably version 1.0 or newer")
-			check_gcc(None, "", common, PACKAGE_GCC)
-			check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
+			check_gcc(path, prefix, common, PACKAGE_GCC)
+			check_binutils(path, prefix, common, PACKAGE_BINUTILS)
 		
 		# Platform-specific utilities
Index: tools/ew.py
===================================================================
--- tools/ew.py	(revision 86d0c263cc77c028ccff0c4d9651abe25a22b5c6)
+++ tools/ew.py	(revision bf85e56c7095e7c326a3411862e8cfe45fe52b80)
@@ -36,4 +36,5 @@
 import subprocess 
 import autotool
+import platform
 
 def run_in_console(cmd, title):
@@ -42,6 +43,18 @@
 	subprocess.call(cmdline, shell = True);
 
-def pc_options():
-	return '-enable-kvm'
+def get_host_native_width():
+	return int(platform.architecture()[0].strip('bit'))
+
+def pc_options(guest_width):
+	opts = ''
+	
+	# Do not enable KVM if running 64 bits HelenOS
+	# on 32 bits host
+	host_width = get_host_native_width()
+	if guest_width <= host_width:
+		opts = opts + ' -enable-kvm'
+	
+	# Remove the leading space
+	return opts[1:]
 
 def malta_options():
@@ -50,9 +63,9 @@
 def platform_to_qemu_options(platform, machine):
 	if platform == 'amd64':
-		return 'system-x86_64', pc_options()
+		return 'system-x86_64', pc_options(64)
 	elif platform == 'arm32':
 		return 'system-arm', ''
 	elif platform == 'ia32':
-		return 'system-i386', pc_options()
+		return 'system-i386', pc_options(32)
 	elif platform == 'mips32':
 		if machine == 'lmalta':
