source: mainline/tools/ew.py@ 132ab5d1

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 132ab5d1 was 132ab5d1, checked in by Jenda <jenda.jzqk73@…>, 7 years ago

Merge commit '6a5d05bd2551e64111bea4f9332dd7448c26ce84' into forwardport

Separate return value from error code in gen_irq_code*().

  • Property mode set to 100755
File size: 10.3 KB
RevLine 
[df64dbc]1#!/usr/bin/env python
2#
[3f4c537a]3# Copyright (c) 2013 Jakub Jermar
[df64dbc]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
[1c24c7c]35import os
[f5ceb18]36import sys
[1c24c7c]37import subprocess
[df64dbc]38import autotool
[8a26f82]39import platform
[df425da]40import thread
41import time
[df64dbc]42
[f5ceb18]43overrides = {}
44
45def is_override(str):
46 if str in overrides.keys():
47 return overrides[str]
48 return False
49
[df425da]50def cfg_get(platform, machine, processor):
51 if machine == "" or emulators[platform].has_key("run"):
[f5ceb18]52 return emulators[platform]
[df425da]53 elif processor == "" or emulators[platform][machine].has_key("run"):
[f5ceb18]54 return emulators[platform][machine]
[df425da]55 else:
56 return emulators[platform][machine][processor]
[f5ceb18]57
[e4c8e3cf]58def termemu_detect():
59 for termemu in ['xfce4-terminal', 'xterm']:
60 try:
61 subprocess.check_output('which ' + termemu, shell = True)
62 return termemu
63 except:
64 pass
65
[df64dbc]66def run_in_console(cmd, title):
[1dab093]67 ecmd = cmd.replace('"', '\\"')
68 cmdline = termemu_detect() + ' -T ' + '"' + title + '"' + ' -e "' + ecmd + '"'
[e4a1497]69 print(cmdline)
[f5ceb18]70 if not is_override('dryrun'):
[e4c8e3cf]71 subprocess.call(cmdline, shell = True)
[df64dbc]72
[8a26f82]73def get_host_native_width():
74 return int(platform.architecture()[0].strip('bit'))
75
76def pc_options(guest_width):
77 opts = ''
78
79 # Do not enable KVM if running 64 bits HelenOS
80 # on 32 bits host
81 host_width = get_host_native_width()
[f5ceb18]82 if guest_width <= host_width and not is_override('nokvm'):
[8a26f82]83 opts = opts + ' -enable-kvm'
84
85 # Remove the leading space
86 return opts[1:]
[df64dbc]87
88def malta_options():
89 return '-cpu 4Kc'
90
[9185e42]91def platform_to_qemu_options(platform, machine, processor):
[df64dbc]92 if platform == 'amd64':
[8a26f82]93 return 'system-x86_64', pc_options(64)
[df64dbc]94 elif platform == 'arm32':
[83b01c2]95 return 'system-arm', '-M integratorcp'
[df64dbc]96 elif platform == 'ia32':
[8a26f82]97 return 'system-i386', pc_options(32)
[df64dbc]98 elif platform == 'mips32':
99 if machine == 'lmalta':
100 return 'system-mipsel', malta_options()
101 elif machine == 'bmalta':
102 return 'system-mips', malta_options()
103 elif platform == 'ppc32':
[644352c]104 return 'system-ppc', '-m 256'
[df64dbc]105 elif platform == 'sparc64':
[9185e42]106 if machine != 'generic':
107 raise Exception
108 if processor == 'us':
[7f4937e]109 return 'system-sparc64', '-M sun4u --prom-env boot-args="console=devices/\\hw\\pci0\\01:01.0\\com1\\a"'
[9185e42]110 elif processor == 'sun4v':
111 default_path = '/usr/local/opensparc/image/'
112 try:
113 if os.path.exists(default_path):
114 opensparc_bins = default_path
115 elif os.path.exists(os.environ['OPENSPARC_BINARIES']):
116 opensparc_bins = os.environ['OPENSPARC_BINARIES']
117 else:
118 raise Exception
119 except:
120 print("Cannot find OpenSPARC binary images!")
121 print("Either set OPENSPARC_BINARIES environment variable accordingly or place the images in %s." % (default_path))
122 raise Exception
123
124 return 'system-sparc64', '-M niagara -m 256 -L %s' % (opensparc_bins)
125
[df64dbc]126
[129b92c6]127def hdisk_mk():
[df64dbc]128 if not os.path.exists('hdisk.img'):
129 subprocess.call('tools/mkfat.py 1048576 uspace/dist/data hdisk.img', shell = True)
[f5ceb18]130
[129b92c6]131def qemu_bd_options():
132 if is_override('nohdd'):
133 return ''
134
135 hdisk_mk()
136
[5fdad22]137 return ' -drive file=hdisk.img,index=0,media=disk,format=raw'
[df64dbc]138
139def qemu_nic_ne2k_options():
140 return ' -device ne2k_isa,irq=5,vlan=0'
141
142def qemu_nic_e1k_options():
143 return ' -device e1000,vlan=0'
144
145def qemu_nic_rtl8139_options():
146 return ' -device rtl8139,vlan=0'
147
148def qemu_net_options():
[f5ceb18]149 if is_override('nonet'):
150 return ''
151
152 nic_options = ''
153 if 'net' in overrides.keys():
154 if 'e1k' in overrides['net'].keys():
155 nic_options += qemu_nic_e1k_options()
156 if 'rtl8139' in overrides['net'].keys():
157 nic_options += qemu_nic_rtl8139_options()
158 if 'ne2k' in overrides['net'].keys():
159 nic_options += qemu_nic_ne2k_options()
160 else:
161 # Use the default NIC
162 nic_options += qemu_nic_e1k_options()
163
[362654a]164 return nic_options + ' -net user,hostfwd=udp::8080-:8080,hostfwd=udp::8081-:8081,hostfwd=tcp::8080-:8080,hostfwd=tcp::8081-:8081,hostfwd=tcp::2223-:2223'
[df64dbc]165
166def qemu_usb_options():
[f5ceb18]167 if is_override('nousb'):
168 return ''
169 return ' -usb'
[df64dbc]170
[5119d34]171def qemu_xhci_options():
172 if is_override('noxhci'):
173 return ''
174 return ' -device nec-usb-xhci,id=xhci'
175
[f5ceb18]176def qemu_audio_options():
177 if is_override('nosnd'):
178 return ''
[089901e]179 return ' -device intel-hda -device hda-duplex'
[f5ceb18]180
[df425da]181def qemu_run(platform, machine, processor):
182 cfg = cfg_get(platform, machine, processor)
[9185e42]183 suffix, options = platform_to_qemu_options(platform, machine, processor)
[df64dbc]184 cmd = 'qemu-' + suffix
185
186 cmdline = cmd
187 if options != '':
188 cmdline += ' ' + options
189
[f5ceb18]190 cmdline += qemu_bd_options()
191
192 if (not 'net' in cfg.keys()) or cfg['net']:
[df64dbc]193 cmdline += qemu_net_options()
[f5ceb18]194 if (not 'usb' in cfg.keys()) or cfg['usb']:
[df64dbc]195 cmdline += qemu_usb_options()
[5119d34]196 if (not 'xhci' in cfg.keys()) or cfg['xhci']:
197 cmdline += qemu_xhci_options()
[f5ceb18]198 if (not 'audio' in cfg.keys()) or cfg['audio']:
199 cmdline += qemu_audio_options()
[df64dbc]200
[f5ceb18]201 if cfg['image'] == 'image.iso':
[df64dbc]202 cmdline += ' -boot d -cdrom image.iso'
[f5ceb18]203 elif cfg['image'] == 'image.boot':
[df64dbc]204 cmdline += ' -kernel image.boot'
[9185e42]205 else:
206 cmdline += ' ' + cfg['image']
[df64dbc]207
[f5ceb18]208 if ('console' in cfg.keys()) and not cfg['console']:
[df64dbc]209 cmdline += ' -nographic'
210
211 title = 'HelenOS/' + platform
212 if machine != '':
213 title += ' on ' + machine
[9185e42]214 if 'expect' in cfg.keys():
215 cmdline = 'expect -c \'spawn %s; expect "%s" { send "%s" } timeout exp_continue; interact\'' % (cmdline, cfg['expect']['src'], cfg['expect']['dst'])
[df64dbc]216 run_in_console(cmdline, title)
217 else:
[e4a1497]218 print(cmdline)
[f5ceb18]219 if not is_override('dryrun'):
220 subprocess.call(cmdline, shell = True)
[3f4c537a]221
[df425da]222def ski_run(platform, machine, processor):
[df64dbc]223 run_in_console('ski -i contrib/conf/ski.conf', 'HelenOS/ia64 on ski')
224
[df425da]225def msim_run(platform, machine, processor):
[129b92c6]226 hdisk_mk()
[df64dbc]227 run_in_console('msim -c contrib/conf/msim.conf', 'HelenOS/mips32 on msim')
228
[3f4c537a]229def spike_run(platform, machine, processor):
[ae8d7b0]230 run_in_console('spike -m1073741824:1073741824 image.boot', 'HelenOS/risvc64 on Spike')
[3f4c537a]231
[f5ceb18]232emulators = {
233 'amd64' : {
234 'run' : qemu_run,
235 'image' : 'image.iso'
236 },
237 'arm32' : {
238 'integratorcp' : {
239 'run' : qemu_run,
240 'image' : 'image.boot',
241 'net' : False,
242 'audio' : False
243 }
244 },
245 'ia32' : {
246 'run' : qemu_run,
247 'image' : 'image.iso'
248 },
249 'ia64' : {
250 'ski' : {
251 'run' : ski_run
252 }
253 },
254 'mips32' : {
255 'msim' : {
256 'run' : msim_run
257 },
258 'lmalta' : {
259 'run' : qemu_run,
260 'image' : 'image.boot',
261 'console' : False
262 },
263 'bmalta' : {
264 'run' : qemu_run,
265 'image' : 'image.boot',
266 'console' : False
267 },
268 },
269 'ppc32' : {
270 'run' : qemu_run,
271 'image' : 'image.iso',
272 'audio' : False
273 },
[3f4c537a]274 'riscv64' : {
275 'run' : spike_run,
276 'image' : 'image.boot'
277 },
[f5ceb18]278 'sparc64' : {
279 'generic' : {
[df425da]280 'us' : {
281 'run' : qemu_run,
282 'image' : 'image.iso',
[0195374]283 'audio' : False,
284 'console' : False,
[7f4937e]285 'net' : False,
286 'usb' : False
[df425da]287 },
288 'sun4v' : {
[9185e42]289 'run' : qemu_run,
290 'image' : '-drive if=pflash,readonly=on,file=image.iso',
291 'audio' : False,
292 'console' : False,
293 'net' : False,
294 'usb' : False,
295 'expect' : {
296 'src' : 'ok ',
297 'dst' : 'boot\n'
298 },
[df425da]299 }
[f5ceb18]300 }
301 },
302}
303
304def usage():
305 print("%s - emulator wrapper for running HelenOS\n" % os.path.basename(sys.argv[0]))
[5119d34]306 print("%s [-d] [-h] [-net e1k|rtl8139|ne2k] [-nohdd] [-nokvm] [-nonet] [-nosnd] [-nousb] [-noxhci]\n" %
[f5ceb18]307 os.path.basename(sys.argv[0]))
308 print("-d\tDry run: do not run the emulation, just print the command line.")
309 print("-h\tPrint the usage information and exit.")
310 print("-nohdd\tDisable hard disk, if applicable.")
311 print("-nokvm\tDisable KVM, if applicable.")
312 print("-nonet\tDisable networking support, if applicable.")
313 print("-nosnd\tDisable sound, if applicable.")
314 print("-nousb\tDisable USB support, if applicable.")
[5119d34]315 print("-noxhci\tDisable XHCI support, if applicable.")
[df64dbc]316
[df425da]317def fail(platform, machine):
318 print("Cannot start emulation for the chosen configuration. (%s/%s)" % (platform, machine))
319
320
[df64dbc]321def run():
[f5ceb18]322 expect_nic = False
323
324 for i in range(1, len(sys.argv)):
325
326 if expect_nic:
327 expect_nic = False
328 if not 'net' in overrides.keys():
329 overrides['net'] = {}
330 if sys.argv[i] == 'e1k':
331 overrides['net']['e1k'] = True
332 elif sys.argv[i] == 'rtl8139':
333 overrides['net']['rtl8139'] = True
334 elif sys.argv[i] == 'ne2k':
335 overrides['net']['ne2k'] = True
336 else:
337 usage()
338 exit()
339
340 elif sys.argv[i] == '-h':
341 usage()
342 exit()
343 elif sys.argv[i] == '-d':
344 overrides['dryrun'] = True
345 elif sys.argv[i] == '-net' and i < len(sys.argv) - 1:
346 expect_nic = True
347 elif sys.argv[i] == '-nohdd':
348 overrides['nohdd'] = True
349 elif sys.argv[i] == '-nokvm':
350 overrides['nokvm'] = True
351 elif sys.argv[i] == '-nonet':
352 overrides['nonet'] = True
353 elif sys.argv[i] == '-nosnd':
354 overrides['nosnd'] = True
355 elif sys.argv[i] == '-nousb':
356 overrides['nousb'] = True
[5119d34]357 elif sys.argv[i] == '-noxhci':
358 overrides['noxhci'] = True
[f5ceb18]359 else:
360 usage()
361 exit()
362
[df64dbc]363 config = {}
364 autotool.read_config(autotool.CONFIG, config)
365
[f5ceb18]366 if 'PLATFORM' in config.keys():
[df64dbc]367 platform = config['PLATFORM']
[f5ceb18]368 else:
[df64dbc]369 platform = ''
370
[f5ceb18]371 if 'MACHINE' in config.keys():
[df64dbc]372 mach = config['MACHINE']
[f5ceb18]373 else:
[df64dbc]374 mach = ''
375
[df425da]376 if 'PROCESSOR' in config.keys():
377 processor = config['PROCESSOR']
378 else:
379 processor = ''
380
[df64dbc]381 try:
[df425da]382 emu_run = cfg_get(platform, mach, processor)['run']
383 emu_run(platform, mach, processor)
[df64dbc]384 except:
[df425da]385 fail(platform, mach)
[df64dbc]386 return
387
388run()
Note: See TracBrowser for help on using the repository browser.