source: mainline/tools/ew.py@ df64dbc

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

Add a prototype of a universal emulator wrapper.

  • Assuming all emulators are installed, it reads the build configuration and runs the appropriate emulator with appropriate options.
  • Property mode set to 100755
File size: 5.1 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 subprocess
37import autotool
38
39def run_in_console(cmd, title):
40 cmdline = 'xterm -T ' + '"' + title + '"' + ' -e ' + cmd
41 print cmdline
42 subprocess.call(cmdline, shell = True);
43
44def pc_options():
45 return '-enable-kvm'
46
47def malta_options():
48 return '-cpu 4Kc'
49
50def platform_to_qemu_options(platform, machine):
51 if platform == 'amd64':
52 return 'system-x86_64', pc_options()
53 elif platform == 'arm32':
54 return 'system-arm', ''
55 elif platform == 'ia32':
56 return 'system-i386', pc_options()
57 elif platform == 'mips32':
58 if machine == 'lmalta':
59 return 'system-mipsel', malta_options()
60 elif machine == 'bmalta':
61 return 'system-mips', malta_options()
62 elif platform == 'ppc32':
63 return 'system-ppc', ''
64 elif platform == 'sparc64':
65 return 'system-sparc64', ''
66
67def qemu_bd_options():
68 if not os.path.exists('hdisk.img'):
69 subprocess.call('tools/mkfat.py 1048576 uspace/dist/data hdisk.img', shell = True)
70 return ' -hda hdisk.img'
71
72def qemu_nic_ne2k_options():
73 return ' -device ne2k_isa,irq=5,vlan=0'
74
75def qemu_nic_e1k_options():
76 return ' -device e1000,vlan=0'
77
78def qemu_nic_rtl8139_options():
79 return ' -device rtl8139,vlan=0'
80
81def qemu_net_options():
82 nic_options = qemu_nic_e1k_options()
83 return nic_options + ' -net user -redir udp:8080::8080 -redir udp:8081::8081 -redir tcp:8080::8080 -redir tcp:8081::8081'
84
85def qemu_usb_options():
86 return ''
87
88def qemu_run(platform, machine, console, image, networking, storage, usb):
89 suffix, options = platform_to_qemu_options(platform, machine)
90 cmd = 'qemu-' + suffix
91
92 cmdline = cmd
93 if options != '':
94 cmdline += ' ' + options
95
96 if storage:
97 cmdline += qemu_bd_options()
98 if networking:
99 cmdline += qemu_net_options()
100 if usb:
101 cmdline += qemu_usb_options()
102
103 if image == 'image.iso':
104 cmdline += ' -boot d -cdrom image.iso'
105 elif image == 'image.boot':
106 cmdline += ' -kernel image.boot'
107
108 if not console:
109 cmdline += ' -nographic'
110
111 title = 'HelenOS/' + platform
112 if machine != '':
113 title += ' on ' + machine
114 run_in_console(cmdline, title)
115 else:
116 print cmdline
117 subprocess.call(cmdline, shell = True)
118
119def ski_run(platform, machine, console, image, networking, storage, usb):
120 run_in_console('ski -i contrib/conf/ski.conf', 'HelenOS/ia64 on ski')
121
122def msim_run(platform, machine, console, image, networking, storage, usb):
123 run_in_console('msim -c contrib/conf/msim.conf', 'HelenOS/mips32 on msim')
124
125emulators = {}
126emulators['amd64'] = {}
127emulators['arm32'] = {}
128emulators['ia32'] = {}
129emulators['ia64'] = {}
130emulators['mips32'] = {}
131emulators['ppc32'] = {}
132emulators['sparc64'] = {}
133
134emulators['amd64'][''] = qemu_run, True, 'image.iso', True, True, True
135emulators['arm32']['integratorcp'] = qemu_run, True, 'image.boot', False, False, False
136emulators['ia32'][''] = qemu_run, True, 'image.iso', True, True, True
137emulators['ia64']['ski'] = ski_run, False, 'image.boot', False, False, False
138emulators['mips32']['msim'] = msim_run, False, 'image.boot', False, False, False
139emulators['mips32']['lmalta'] = qemu_run, False, 'image.boot', False, False, False
140emulators['mips32']['bmalta'] = qemu_run, False, 'image.boot', False, False, False
141emulators['ppc32'][''] = qemu_run, True, 'image.iso', True, True, True
142emulators['sparc64']['generic'] = qemu_run, True, 'image.iso', True, True, True
143
144def run():
145 config = {}
146 autotool.read_config(autotool.CONFIG, config)
147
148 try:
149 platform = config['PLATFORM']
150 except:
151 platform = ''
152
153 try:
154 mach = config['MACHINE']
155 except:
156 mach = ''
157
158 try:
159 emu_run, console, image, networking, storage, usb = emulators[platform][mach]
160 except:
161 print "Cannot start emulation for the chosen configuration."
162 return
163
164 emu_run(platform, mach, console, image, networking, storage, usb)
165
166run()
Note: See TracBrowser for help on using the repository browser.