source: mainline/tools/ew.py@ d5e5fd1

Last change on this file since d5e5fd1 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100755
File size: 11.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 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
66def run_in_console(cmd, title):
67 ecmd = cmd.replace('"', '\\"')
68 cmdline = termemu_detect() + ' -T ' + '"' + title + '"' + ' -e "' + ecmd + '"'
69 print(cmdline)
70 if not is_override('dryrun'):
71 subprocess.call(cmdline, shell = True)
72
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()
82 if guest_width <= host_width and not is_override('nokvm'):
83 opts = opts + ' -enable-kvm'
84
85 # Remove the leading space
86 return opts[1:]
87
88def malta_options():
89 return '-cpu 4Kc'
90
91def platform_to_qemu_options(platform, machine, processor):
92 if platform == 'amd64':
93 return 'system-x86_64', pc_options(64)
94 elif platform == 'arm32':
95 return 'system-arm', '-M integratorcp'
96 elif platform == 'ia32':
97 return 'system-i386', pc_options(32)
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':
104 return 'system-ppc', '-m 256'
105 elif platform == 'sparc64':
106 if machine != 'generic':
107 raise Exception
108 if processor == 'us':
109 return 'system-sparc64', '-M sun4u --prom-env boot-args="console=devices/\\hw\\pci0\\01:01.0\\com1\\a"'
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
126
127def hdisk_mk():
128 if not os.path.exists('hdisk.img'):
129 subprocess.call('tools/mkfat.py 1048576 uspace/dist/data hdisk.img', shell = True)
130
131def qemu_bd_options():
132 if is_override('nohdd'):
133 return ''
134
135 hdisk_mk()
136
137 return ' -drive file=hdisk.img,index=0,media=disk,format=raw'
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():
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
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'
165
166def qemu_usb_options():
167 if is_override('nousb'):
168 return ''
169 return ' -usb'
170
171def qemu_xhci_options():
172 if is_override('noxhci'):
173 return ''
174 return ' -device nec-usb-xhci,id=xhci'
175
176def qemu_tablet_options():
177 if is_override('notablet') or (is_override('nousb') and is_override('noxhci')):
178 return ''
179 return ' -device usb-tablet'
180
181def qemu_audio_options():
182 if is_override('nosnd'):
183 return ''
184 return ' -device intel-hda -device hda-duplex'
185
186def qemu_run(platform, machine, processor):
187 cfg = cfg_get(platform, machine, processor)
188 suffix, options = platform_to_qemu_options(platform, machine, processor)
189 cmd = 'qemu-' + suffix
190
191 cmdline = cmd
192 if 'qemu_path' in overrides.keys():
193 cmdline = overrides['qemu_path'] + cmd
194
195 if options != '':
196 cmdline += ' ' + options
197
198 cmdline += qemu_bd_options()
199
200 if (not 'net' in cfg.keys()) or cfg['net']:
201 cmdline += qemu_net_options()
202 if (not 'usb' in cfg.keys()) or cfg['usb']:
203 cmdline += qemu_usb_options()
204 if (not 'xhci' in cfg.keys()) or cfg['xhci']:
205 cmdline += qemu_xhci_options()
206 if (not 'tablet' in cfg.keys()) or cfg['tablet']:
207 cmdline += qemu_tablet_options()
208 if (not 'audio' in cfg.keys()) or cfg['audio']:
209 cmdline += qemu_audio_options()
210
211 if cfg['image'] == 'image.iso':
212 cmdline += ' -boot d -cdrom image.iso'
213 elif cfg['image'] == 'image.boot':
214 cmdline += ' -kernel image.boot'
215 else:
216 cmdline += ' ' + cfg['image']
217
218 if ('console' in cfg.keys()) and not cfg['console']:
219 cmdline += ' -nographic'
220
221 title = 'HelenOS/' + platform
222 if machine != '':
223 title += ' on ' + machine
224 if 'expect' in cfg.keys():
225 cmdline = 'expect -c \'spawn %s; expect "%s" { send "%s" } timeout exp_continue; interact\'' % (cmdline, cfg['expect']['src'], cfg['expect']['dst'])
226 run_in_console(cmdline, title)
227 else:
228 print(cmdline)
229 if not is_override('dryrun'):
230 subprocess.call(cmdline, shell = True)
231
232def ski_run(platform, machine, processor):
233 run_in_console('ski -i contrib/conf/ski.conf', 'HelenOS/ia64 on ski')
234
235def msim_run(platform, machine, processor):
236 hdisk_mk()
237 run_in_console('msim -c contrib/conf/msim.conf', 'HelenOS/mips32 on msim')
238
239def spike_run(platform, machine, processor):
240 run_in_console('spike -m1073741824:1073741824 image.boot', 'HelenOS/risvc64 on Spike')
241
242emulators = {
243 'amd64' : {
244 'run' : qemu_run,
245 'image' : 'image.iso'
246 },
247 'arm32' : {
248 'integratorcp' : {
249 'run' : qemu_run,
250 'image' : 'image.boot',
251 'net' : False,
252 'audio' : False
253 }
254 },
255 'ia32' : {
256 'run' : qemu_run,
257 'image' : 'image.iso'
258 },
259 'ia64' : {
260 'ski' : {
261 'run' : ski_run
262 }
263 },
264 'mips32' : {
265 'msim' : {
266 'run' : msim_run
267 },
268 'lmalta' : {
269 'run' : qemu_run,
270 'image' : 'image.boot',
271 'console' : False
272 },
273 'bmalta' : {
274 'run' : qemu_run,
275 'image' : 'image.boot',
276 'console' : False
277 },
278 },
279 'ppc32' : {
280 'run' : qemu_run,
281 'image' : 'image.iso',
282 'audio' : False
283 },
284 'riscv64' : {
285 'run' : spike_run,
286 'image' : 'image.boot'
287 },
288 'sparc64' : {
289 'generic' : {
290 'us' : {
291 'run' : qemu_run,
292 'image' : 'image.iso',
293 'audio' : False,
294 'console' : False,
295 'net' : False,
296 'usb' : False
297 },
298 'sun4v' : {
299 'run' : qemu_run,
300 'image' : '-drive if=pflash,readonly=on,file=image.iso',
301 'audio' : False,
302 'console' : False,
303 'net' : False,
304 'usb' : False,
305 'expect' : {
306 'src' : 'ok ',
307 'dst' : 'boot\n'
308 },
309 }
310 }
311 },
312}
313
314def usage():
315 print("%s - emulator wrapper for running HelenOS\n" % os.path.basename(sys.argv[0]))
316 print("%s [-d] [-h] [-net e1k|rtl8139|ne2k] [-nohdd] [-nokvm] [-nonet] [-nosnd] [-nousb] [-noxhci] [-notablet]\n" %
317 os.path.basename(sys.argv[0]))
318 print("-d\tDry run: do not run the emulation, just print the command line.")
319 print("-h\tPrint the usage information and exit.")
320 print("-nohdd\tDisable hard disk, if applicable.")
321 print("-nokvm\tDisable KVM, if applicable.")
322 print("-nonet\tDisable networking support, if applicable.")
323 print("-nosnd\tDisable sound, if applicable.")
324 print("-nousb\tDisable USB support, if applicable.")
325 print("-noxhci\tDisable XHCI support, if applicable.")
326 print("-notablet\tDisable USB tablet (use only relative-position PS/2 mouse instead), if applicable.")
327
328def fail(platform, machine):
329 print("Cannot start emulation for the chosen configuration. (%s/%s)" % (platform, machine))
330
331
332def run():
333 expect_nic = False
334 expect_qemu = False
335
336 for i in range(1, len(sys.argv)):
337
338 if expect_nic:
339 expect_nic = False
340 if not 'net' in overrides.keys():
341 overrides['net'] = {}
342 if sys.argv[i] == 'e1k':
343 overrides['net']['e1k'] = True
344 elif sys.argv[i] == 'rtl8139':
345 overrides['net']['rtl8139'] = True
346 elif sys.argv[i] == 'ne2k':
347 overrides['net']['ne2k'] = True
348 else:
349 usage()
350 exit()
351
352 if expect_qemu:
353 expect_qemu = False
354 overrides['qemu_path'] = sys.argv[i]
355
356 elif sys.argv[i] == '-h':
357 usage()
358 exit()
359 elif sys.argv[i] == '-d':
360 overrides['dryrun'] = True
361 elif sys.argv[i] == '-net' and i < len(sys.argv) - 1:
362 expect_nic = True
363 elif sys.argv[i] == '-nohdd':
364 overrides['nohdd'] = True
365 elif sys.argv[i] == '-nokvm':
366 overrides['nokvm'] = True
367 elif sys.argv[i] == '-nonet':
368 overrides['nonet'] = True
369 elif sys.argv[i] == '-nosnd':
370 overrides['nosnd'] = True
371 elif sys.argv[i] == '-nousb':
372 overrides['nousb'] = True
373 elif sys.argv[i] == '-noxhci':
374 overrides['noxhci'] = True
375 elif sys.argv[i] == '-notablet':
376 overrides['notablet'] = True
377 elif sys.argv[i] == '-qemu_path' and i < len(sys.argv) - 1:
378 expect_qemu = True
379 else:
380 usage()
381 exit()
382
383 config = {}
384 autotool.read_config(autotool.CONFIG, config)
385
386 if 'PLATFORM' in config.keys():
387 platform = config['PLATFORM']
388 else:
389 platform = ''
390
391 if 'MACHINE' in config.keys():
392 mach = config['MACHINE']
393 else:
394 mach = ''
395
396 if 'PROCESSOR' in config.keys():
397 processor = config['PROCESSOR']
398 else:
399 processor = ''
400
401 try:
402 emu_run = cfg_get(platform, mach, processor)['run']
403 emu_run(platform, mach, processor)
404 except:
405 fail(platform, mach)
406 return
407
408run()
Note: See TracBrowser for help on using the repository browser.