Index: tools/ew.py
===================================================================
--- tools/ew.py	(revision b6bbc74b63bc4fbd88824dc1c87c59ea24fcff28)
+++ tools/ew.py	(revision df425da2dc81800838072b02859b6344366da889)
@@ -38,4 +38,6 @@
 import autotool
 import platform
+import thread
+import time
 
 overrides = {}
@@ -46,9 +48,11 @@
 	return False
 
-def cfg_get(platform, machine):
-	if machine == "":
+def cfg_get(platform, machine, processor):
+	if machine == "" or emulators[platform].has_key("run"):
 		return emulators[platform]
-	else:
+	elif processor == "" or emulators[platform][machine].has_key("run"):
 		return emulators[platform][machine]
+	else:
+		return emulators[platform][machine][processor]
 
 def run_in_console(cmd, title):
@@ -142,6 +146,6 @@
 	return ' -device intel-hda -device hda-duplex'
 
-def qemu_run(platform, machine):
-	cfg = cfg_get(platform, machine)
+def qemu_run(platform, machine, processor):
+	cfg = cfg_get(platform, machine, processor)
 	suffix, options = platform_to_qemu_options(platform, machine)
 	cmd = 'qemu-' + suffix
@@ -177,11 +181,34 @@
 			subprocess.call(cmdline, shell = True)
 		
-def ski_run(platform, machine):
+def ski_run(platform, machine, processor):
 	run_in_console('ski -i contrib/conf/ski.conf', 'HelenOS/ia64 on ski')
 
-def msim_run(platform, machine):
+def msim_run(platform, machine, processor):
 	hdisk_mk()
 	run_in_console('msim -c contrib/conf/msim.conf', 'HelenOS/mips32 on msim')
 
+def gem5_console_thread():
+	# Wait a little bit so that gem5 can create the port
+	time.sleep(1)
+	term = os.environ['M5_PATH'] + '/gem5/util/term/m5term'
+	port = 3457
+	run_in_console(term + ' %d' % port, 'HelenOS/sun4v on gem5')
+
+def gem5_run(platform, machine, processor):
+	try:
+		gem5 = os.environ['M5_PATH'] + '/gem5/build/SPARC/gem5.fast'
+		if not os.path.exists(gem5):
+			raise Exception
+	except:
+		print("Did you forget to set M5_PATH?")
+		raise
+
+	thread.start_new_thread(gem5_console_thread, ())
+
+	cmdline = gem5 + ' ' + os.environ['M5_PATH'] + '/configs/example/fs.py --disk-image=' + os.path.abspath('image.iso')
+
+	print(cmdline)
+	if not is_override('dry_run'):
+		subprocess.call(cmdline, shell = True)
 
 emulators = {
@@ -229,7 +256,12 @@
 	'sparc64' : {
 		'generic' : {
-			'run' : qemu_run,
-			'image' : 'image.iso',
-			'audio' : False
+			'us' : {
+				'run' : qemu_run,
+				'image' : 'image.iso',
+				'audio' : False
+			},
+			'sun4v' : {
+				'run' : gem5_run,
+			}
 		}
 	},
@@ -247,4 +279,8 @@
 	print("-nosnd\tDisable sound, if applicable.")
 	print("-nousb\tDisable USB support, if applicable.")
+
+def fail(platform, machine):
+	print("Cannot start emulation for the chosen configuration. (%s/%s)" % (platform, machine))
+	
 
 def run():
@@ -301,11 +337,15 @@
 		mach = ''
 
+	if 'PROCESSOR' in config.keys():
+		processor = config['PROCESSOR']
+	else:
+		processor = ''
+
 	try:
-		emu_run = cfg_get(platform, mach)['run']
+		emu_run = cfg_get(platform, mach, processor)['run']
+		emu_run(platform, mach, processor)
 	except:
-		print("Cannot start emulation for the chosen configuration. (%s/%s)" % (platform, mach))
+		fail(platform, mach)
 		return
 
-	emu_run(platform, mach)
-
 run()
