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 | """
|
---|
32 | Emulator wrapper for running HelenOS
|
---|
33 | """
|
---|
34 |
|
---|
35 | import os
|
---|
36 | import subprocess
|
---|
37 | import autotool
|
---|
38 | import platform
|
---|
39 |
|
---|
40 | def run_in_console(cmd, title):
|
---|
41 | cmdline = 'xterm -T ' + '"' + title + '"' + ' -e ' + cmd
|
---|
42 | print(cmdline)
|
---|
43 | subprocess.call(cmdline, shell = True);
|
---|
44 |
|
---|
45 | def get_host_native_width():
|
---|
46 | return int(platform.architecture()[0].strip('bit'))
|
---|
47 |
|
---|
48 | def pc_options(guest_width):
|
---|
49 | opts = ''
|
---|
50 |
|
---|
51 | # Do not enable KVM if running 64 bits HelenOS
|
---|
52 | # on 32 bits host
|
---|
53 | host_width = get_host_native_width()
|
---|
54 | if guest_width <= host_width:
|
---|
55 | opts = opts + ' -enable-kvm'
|
---|
56 |
|
---|
57 | # Remove the leading space
|
---|
58 | return opts[1:]
|
---|
59 |
|
---|
60 | def malta_options():
|
---|
61 | return '-cpu 4Kc'
|
---|
62 |
|
---|
63 | def platform_to_qemu_options(platform, machine):
|
---|
64 | if platform == 'amd64':
|
---|
65 | return 'system-x86_64', pc_options(64)
|
---|
66 | elif platform == 'arm32':
|
---|
67 | return 'system-arm', ''
|
---|
68 | elif platform == 'ia32':
|
---|
69 | return 'system-i386', pc_options(32)
|
---|
70 | elif platform == 'mips32':
|
---|
71 | if machine == 'lmalta':
|
---|
72 | return 'system-mipsel', malta_options()
|
---|
73 | elif machine == 'bmalta':
|
---|
74 | return 'system-mips', malta_options()
|
---|
75 | elif platform == 'ppc32':
|
---|
76 | return 'system-ppc', ''
|
---|
77 | elif platform == 'sparc64':
|
---|
78 | return 'system-sparc64', ''
|
---|
79 |
|
---|
80 | def qemu_bd_options():
|
---|
81 | if not os.path.exists('hdisk.img'):
|
---|
82 | subprocess.call('tools/mkfat.py 1048576 uspace/dist/data hdisk.img', shell = True)
|
---|
83 | return ' -hda hdisk.img'
|
---|
84 |
|
---|
85 | def qemu_nic_ne2k_options():
|
---|
86 | return ' -device ne2k_isa,irq=5,vlan=0'
|
---|
87 |
|
---|
88 | def qemu_nic_e1k_options():
|
---|
89 | return ' -device e1000,vlan=0'
|
---|
90 |
|
---|
91 | def qemu_nic_rtl8139_options():
|
---|
92 | return ' -device rtl8139,vlan=0'
|
---|
93 |
|
---|
94 | def qemu_net_options():
|
---|
95 | nic_options = qemu_nic_e1k_options()
|
---|
96 | 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'
|
---|
97 |
|
---|
98 | def qemu_usb_options():
|
---|
99 | return ''
|
---|
100 |
|
---|
101 | def qemu_run(platform, machine, console, image, networking, storage, usb):
|
---|
102 | suffix, options = platform_to_qemu_options(platform, machine)
|
---|
103 | cmd = 'qemu-' + suffix
|
---|
104 |
|
---|
105 | cmdline = cmd
|
---|
106 | if options != '':
|
---|
107 | cmdline += ' ' + options
|
---|
108 |
|
---|
109 | if storage:
|
---|
110 | cmdline += qemu_bd_options()
|
---|
111 | if networking:
|
---|
112 | cmdline += qemu_net_options()
|
---|
113 | if usb:
|
---|
114 | cmdline += qemu_usb_options()
|
---|
115 |
|
---|
116 | if image == 'image.iso':
|
---|
117 | cmdline += ' -boot d -cdrom image.iso'
|
---|
118 | elif image == 'image.boot':
|
---|
119 | cmdline += ' -kernel image.boot'
|
---|
120 |
|
---|
121 | if not console:
|
---|
122 | cmdline += ' -nographic'
|
---|
123 |
|
---|
124 | title = 'HelenOS/' + platform
|
---|
125 | if machine != '':
|
---|
126 | title += ' on ' + machine
|
---|
127 | run_in_console(cmdline, title)
|
---|
128 | else:
|
---|
129 | print(cmdline)
|
---|
130 | subprocess.call(cmdline, shell = True)
|
---|
131 |
|
---|
132 | def ski_run(platform, machine, console, image, networking, storage, usb):
|
---|
133 | run_in_console('ski -i contrib/conf/ski.conf', 'HelenOS/ia64 on ski')
|
---|
134 |
|
---|
135 | def msim_run(platform, machine, console, image, networking, storage, usb):
|
---|
136 | run_in_console('msim -c contrib/conf/msim.conf', 'HelenOS/mips32 on msim')
|
---|
137 |
|
---|
138 | emulators = {}
|
---|
139 | emulators['amd64'] = {}
|
---|
140 | emulators['arm32'] = {}
|
---|
141 | emulators['ia32'] = {}
|
---|
142 | emulators['ia64'] = {}
|
---|
143 | emulators['mips32'] = {}
|
---|
144 | emulators['ppc32'] = {}
|
---|
145 | emulators['sparc64'] = {}
|
---|
146 |
|
---|
147 | emulators['amd64'][''] = qemu_run, True, 'image.iso', True, True, True
|
---|
148 | emulators['arm32']['integratorcp'] = qemu_run, True, 'image.boot', False, False, False
|
---|
149 | emulators['ia32'][''] = qemu_run, True, 'image.iso', True, True, True
|
---|
150 | emulators['ia64']['ski'] = ski_run, False, 'image.boot', False, False, False
|
---|
151 | emulators['mips32']['msim'] = msim_run, False, 'image.boot', False, False, False
|
---|
152 | emulators['mips32']['lmalta'] = qemu_run, False, 'image.boot', False, False, False
|
---|
153 | emulators['mips32']['bmalta'] = qemu_run, False, 'image.boot', False, False, False
|
---|
154 | emulators['ppc32'][''] = qemu_run, True, 'image.iso', True, True, True
|
---|
155 | emulators['sparc64']['generic'] = qemu_run, True, 'image.iso', True, True, True
|
---|
156 |
|
---|
157 | def run():
|
---|
158 | config = {}
|
---|
159 | autotool.read_config(autotool.CONFIG, config)
|
---|
160 |
|
---|
161 | try:
|
---|
162 | platform = config['PLATFORM']
|
---|
163 | except:
|
---|
164 | platform = ''
|
---|
165 |
|
---|
166 | try:
|
---|
167 | mach = config['MACHINE']
|
---|
168 | except:
|
---|
169 | mach = ''
|
---|
170 |
|
---|
171 | try:
|
---|
172 | emu_run, console, image, networking, storage, usb = emulators[platform][mach]
|
---|
173 | except:
|
---|
174 | print("Cannot start emulation for the chosen configuration.")
|
---|
175 | return
|
---|
176 |
|
---|
177 | emu_run(platform, mach, console, image, networking, storage, usb)
|
---|
178 |
|
---|
179 | run()
|
---|