source: mainline/tools/ew.py@ 1cf26ab

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1cf26ab was df425da, checked in by Jakub Jermar <jakub@…>, 9 years ago

Add gem5 support to tools/ew.py.

  • Property mode set to 100755
File size: 9.0 KB
Line 
1#!/usr/bin/env python
2#
3# Copyright (c) 2013 Jakub Jermar
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9#
10# - Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# - Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution.
15# - The name of the author may not be used to endorse or promote products
16# derived from this software without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29
30
31"""
32Emulator wrapper for running HelenOS
33"""
34
35import os
36import sys
37import subprocess
38import autotool
39import platform
40import thread
41import time
42
43overrides = {}
44
45def is_override(str):
46 if str in overrides.keys():
47 return overrides[str]
48 return False
49
50def cfg_get(platform, machine, processor):
51 if machine == "" or emulators[platform].has_key("run"):
52 return emulators[platform]
53 elif processor == "" or emulators[platform][machine].has_key("run"):
54 return emulators[platform][machine]
55 else:
56 return emulators[platform][machine][processor]
57
58def run_in_console(cmd, title):
59 cmdline = 'xterm -T ' + '"' + title + '"' + ' -e ' + cmd
60 print(cmdline)
61 if not is_override('dryrun'):
62 subprocess.call(cmdline, shell = True);
63
64def get_host_native_width():
65 return int(platform.architecture()[0].strip('bit'))
66
67def pc_options(guest_width):
68 opts = ''
69
70 # Do not enable KVM if running 64 bits HelenOS
71 # on 32 bits host
72 host_width = get_host_native_width()
73 if guest_width <= host_width and not is_override('nokvm'):
74 opts = opts + ' -enable-kvm'
75
76 # Remove the leading space
77 return opts[1:]
78
79def malta_options():
80 return '-cpu 4Kc'
81
82def platform_to_qemu_options(platform, machine):
83 if platform == 'amd64':
84 return 'system-x86_64', pc_options(64)
85 elif platform == 'arm32':
86 return 'system-arm', '-M integratorcp'
87 elif platform == 'ia32':
88 return 'system-i386', pc_options(32)
89 elif platform == 'mips32':
90 if machine == 'lmalta':
91 return 'system-mipsel', malta_options()
92 elif machine == 'bmalta':
93 return 'system-mips', malta_options()
94 elif platform == 'ppc32':
95 return 'system-ppc', '-m 256'
96 elif platform == 'sparc64':
97 return 'system-sparc64', ''
98
99def hdisk_mk():
100 if not os.path.exists('hdisk.img'):
101 subprocess.call('tools/mkfat.py 1048576 uspace/dist/data hdisk.img', shell = True)
102
103def qemu_bd_options():
104 if is_override('nohdd'):
105 return ''
106
107 hdisk_mk()
108
109 return ' -drive file=hdisk.img,index=0,media=disk,format=raw'
110
111def qemu_nic_ne2k_options():
112 return ' -device ne2k_isa,irq=5,vlan=0'
113
114def qemu_nic_e1k_options():
115 return ' -device e1000,vlan=0'
116
117def qemu_nic_rtl8139_options():
118 return ' -device rtl8139,vlan=0'
119
120def qemu_net_options():
121 if is_override('nonet'):
122 return ''
123
124 nic_options = ''
125 if 'net' in overrides.keys():
126 if 'e1k' in overrides['net'].keys():
127 nic_options += qemu_nic_e1k_options()
128 if 'rtl8139' in overrides['net'].keys():
129 nic_options += qemu_nic_rtl8139_options()
130 if 'ne2k' in overrides['net'].keys():
131 nic_options += qemu_nic_ne2k_options()
132 else:
133 # Use the default NIC
134 nic_options += qemu_nic_e1k_options()
135
136 return nic_options + ' -net user -redir udp:8080::8080 -redir udp:8081::8081 -redir tcp:8080::8080 -redir tcp:8081::8081 -redir tcp:2223::2223'
137
138def qemu_usb_options():
139 if is_override('nousb'):
140 return ''
141 return ' -usb'
142
143def qemu_audio_options():
144 if is_override('nosnd'):
145 return ''
146 return ' -device intel-hda -device hda-duplex'
147
148def qemu_run(platform, machine, processor):
149 cfg = cfg_get(platform, machine, processor)
150 suffix, options = platform_to_qemu_options(platform, machine)
151 cmd = 'qemu-' + suffix
152
153 cmdline = cmd
154 if options != '':
155 cmdline += ' ' + options
156
157 cmdline += qemu_bd_options()
158
159 if (not 'net' in cfg.keys()) or cfg['net']:
160 cmdline += qemu_net_options()
161 if (not 'usb' in cfg.keys()) or cfg['usb']:
162 cmdline += qemu_usb_options()
163 if (not 'audio' in cfg.keys()) or cfg['audio']:
164 cmdline += qemu_audio_options()
165
166 if cfg['image'] == 'image.iso':
167 cmdline += ' -boot d -cdrom image.iso'
168 elif cfg['image'] == 'image.boot':
169 cmdline += ' -kernel image.boot'
170
171 if ('console' in cfg.keys()) and not cfg['console']:
172 cmdline += ' -nographic'
173
174 title = 'HelenOS/' + platform
175 if machine != '':
176 title += ' on ' + machine
177 run_in_console(cmdline, title)
178 else:
179 print(cmdline)
180 if not is_override('dryrun'):
181 subprocess.call(cmdline, shell = True)
182
183def ski_run(platform, machine, processor):
184 run_in_console('ski -i contrib/conf/ski.conf', 'HelenOS/ia64 on ski')
185
186def msim_run(platform, machine, processor):
187 hdisk_mk()
188 run_in_console('msim -c contrib/conf/msim.conf', 'HelenOS/mips32 on msim')
189
190def gem5_console_thread():
191 # Wait a little bit so that gem5 can create the port
192 time.sleep(1)
193 term = os.environ['M5_PATH'] + '/gem5/util/term/m5term'
194 port = 3457
195 run_in_console(term + ' %d' % port, 'HelenOS/sun4v on gem5')
196
197def gem5_run(platform, machine, processor):
198 try:
199 gem5 = os.environ['M5_PATH'] + '/gem5/build/SPARC/gem5.fast'
200 if not os.path.exists(gem5):
201 raise Exception
202 except:
203 print("Did you forget to set M5_PATH?")
204 raise
205
206 thread.start_new_thread(gem5_console_thread, ())
207
208 cmdline = gem5 + ' ' + os.environ['M5_PATH'] + '/configs/example/fs.py --disk-image=' + os.path.abspath('image.iso')
209
210 print(cmdline)
211 if not is_override('dry_run'):
212 subprocess.call(cmdline, shell = True)
213
214emulators = {
215 'amd64' : {
216 'run' : qemu_run,
217 'image' : 'image.iso'
218 },
219 'arm32' : {
220 'integratorcp' : {
221 'run' : qemu_run,
222 'image' : 'image.boot',
223 'net' : False,
224 'audio' : False
225 }
226 },
227 'ia32' : {
228 'run' : qemu_run,
229 'image' : 'image.iso'
230 },
231 'ia64' : {
232 'ski' : {
233 'run' : ski_run
234 }
235 },
236 'mips32' : {
237 'msim' : {
238 'run' : msim_run
239 },
240 'lmalta' : {
241 'run' : qemu_run,
242 'image' : 'image.boot',
243 'console' : False
244 },
245 'bmalta' : {
246 'run' : qemu_run,
247 'image' : 'image.boot',
248 'console' : False
249 },
250 },
251 'ppc32' : {
252 'run' : qemu_run,
253 'image' : 'image.iso',
254 'audio' : False
255 },
256 'sparc64' : {
257 'generic' : {
258 'us' : {
259 'run' : qemu_run,
260 'image' : 'image.iso',
261 'audio' : False
262 },
263 'sun4v' : {
264 'run' : gem5_run,
265 }
266 }
267 },
268}
269
270def usage():
271 print("%s - emulator wrapper for running HelenOS\n" % os.path.basename(sys.argv[0]))
272 print("%s [-d] [-h] [-net e1k|rtl8139|ne2k] [-nohdd] [-nokvm] [-nonet] [-nosnd] [-nousb]\n" %
273 os.path.basename(sys.argv[0]))
274 print("-d\tDry run: do not run the emulation, just print the command line.")
275 print("-h\tPrint the usage information and exit.")
276 print("-nohdd\tDisable hard disk, if applicable.")
277 print("-nokvm\tDisable KVM, if applicable.")
278 print("-nonet\tDisable networking support, if applicable.")
279 print("-nosnd\tDisable sound, if applicable.")
280 print("-nousb\tDisable USB support, if applicable.")
281
282def fail(platform, machine):
283 print("Cannot start emulation for the chosen configuration. (%s/%s)" % (platform, machine))
284
285
286def run():
287 expect_nic = False
288
289 for i in range(1, len(sys.argv)):
290
291 if expect_nic:
292 expect_nic = False
293 if not 'net' in overrides.keys():
294 overrides['net'] = {}
295 if sys.argv[i] == 'e1k':
296 overrides['net']['e1k'] = True
297 elif sys.argv[i] == 'rtl8139':
298 overrides['net']['rtl8139'] = True
299 elif sys.argv[i] == 'ne2k':
300 overrides['net']['ne2k'] = True
301 else:
302 usage()
303 exit()
304
305 elif sys.argv[i] == '-h':
306 usage()
307 exit()
308 elif sys.argv[i] == '-d':
309 overrides['dryrun'] = True
310 elif sys.argv[i] == '-net' and i < len(sys.argv) - 1:
311 expect_nic = True
312 elif sys.argv[i] == '-nohdd':
313 overrides['nohdd'] = True
314 elif sys.argv[i] == '-nokvm':
315 overrides['nokvm'] = True
316 elif sys.argv[i] == '-nonet':
317 overrides['nonet'] = True
318 elif sys.argv[i] == '-nosnd':
319 overrides['nosnd'] = True
320 elif sys.argv[i] == '-nousb':
321 overrides['nousb'] = True
322 else:
323 usage()
324 exit()
325
326 config = {}
327 autotool.read_config(autotool.CONFIG, config)
328
329 if 'PLATFORM' in config.keys():
330 platform = config['PLATFORM']
331 else:
332 platform = ''
333
334 if 'MACHINE' in config.keys():
335 mach = config['MACHINE']
336 else:
337 mach = ''
338
339 if 'PROCESSOR' in config.keys():
340 processor = config['PROCESSOR']
341 else:
342 processor = ''
343
344 try:
345 emu_run = cfg_get(platform, mach, processor)['run']
346 emu_run(platform, mach, processor)
347 except:
348 fail(platform, mach)
349 return
350
351run()
Note: See TracBrowser for help on using the repository browser.