3 # Copyright (c) 2013 Jakub Jermar
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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.
32 Emulator wrapper for running HelenOS
46 if str in overrides
.keys():
50 def 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
]
56 return emulators
[platform
][machine
][processor
]
58 def run_in_console(cmd
, title
):
59 cmdline
= 'xterm -T ' + '"' + title
+ '"' + ' -e ' + cmd
61 if not is_override('dryrun'):
62 subprocess
.call(cmdline
, shell
= True);
64 def get_host_native_width():
65 return int(platform
.architecture()[0].strip('bit'))
67 def pc_options(guest_width
):
70 # Do not enable KVM if running 64 bits HelenOS
72 host_width
= get_host_native_width()
73 if guest_width
<= host_width
and not is_override('nokvm'):
74 opts
= opts
+ ' -enable-kvm'
76 # Remove the leading space
82 def platform_to_qemu_options(platform
, machine
, processor
):
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 if machine
!= 'generic':
100 return 'system-sparc64', '-M sun4u --prom-env boot-args="console=devices/\\hw\\pci0\\00:03.0\\com1\\a"'
101 elif processor
== 'sun4v':
102 default_path
= '/usr/local/opensparc/image/'
104 if os
.path
.exists(default_path
):
105 opensparc_bins
= default_path
106 elif os
.path
.exists(os
.environ
['OPENSPARC_BINARIES']):
107 opensparc_bins
= os
.environ
['OPENSPARC_BINARIES']
111 print("Cannot find OpenSPARC binary images!")
112 print("Either set OPENSPARC_BINARIES environment variable accordingly or place the images in %s." % (default_path
))
115 return 'system-sparc64', '-M niagara -m 256 -L %s' % (opensparc_bins
)
119 if not os
.path
.exists('hdisk.img'):
120 subprocess
.call('tools/mkfat.py 1048576 uspace/dist/data hdisk.img', shell
= True)
122 def qemu_bd_options():
123 if is_override('nohdd'):
128 return ' -drive file=hdisk.img,index=0,media=disk,format=raw'
130 def qemu_nic_ne2k_options():
131 return ' -device ne2k_isa,irq=5,vlan=0'
133 def qemu_nic_e1k_options():
134 return ' -device e1000,vlan=0'
136 def qemu_nic_rtl8139_options():
137 return ' -device rtl8139,vlan=0'
139 def qemu_net_options():
140 if is_override('nonet'):
144 if 'net' in overrides
.keys():
145 if 'e1k' in overrides
['net'].keys():
146 nic_options
+= qemu_nic_e1k_options()
147 if 'rtl8139' in overrides
['net'].keys():
148 nic_options
+= qemu_nic_rtl8139_options()
149 if 'ne2k' in overrides
['net'].keys():
150 nic_options
+= qemu_nic_ne2k_options()
152 # Use the default NIC
153 nic_options
+= qemu_nic_e1k_options()
155 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'
157 def qemu_usb_options():
158 if is_override('nousb'):
162 def qemu_audio_options():
163 if is_override('nosnd'):
165 return ' -device intel-hda -device hda-duplex'
167 def qemu_run(platform
, machine
, processor
):
168 cfg
= cfg_get(platform
, machine
, processor
)
169 suffix
, options
= platform_to_qemu_options(platform
, machine
, processor
)
170 cmd
= 'qemu-' + suffix
174 cmdline
+= ' ' + options
176 cmdline
+= qemu_bd_options()
178 if (not 'net' in cfg
.keys()) or cfg
['net']:
179 cmdline
+= qemu_net_options()
180 if (not 'usb' in cfg
.keys()) or cfg
['usb']:
181 cmdline
+= qemu_usb_options()
182 if (not 'audio' in cfg
.keys()) or cfg
['audio']:
183 cmdline
+= qemu_audio_options()
185 if cfg
['image'] == 'image.iso':
186 cmdline
+= ' -boot d -cdrom image.iso'
187 elif cfg
['image'] == 'image.boot':
188 cmdline
+= ' -kernel image.boot'
190 cmdline
+= ' ' + cfg
['image']
192 if ('console' in cfg
.keys()) and not cfg
['console']:
193 cmdline
+= ' -nographic'
195 title
= 'HelenOS/' + platform
197 title
+= ' on ' + machine
198 if 'expect' in cfg
.keys():
199 cmdline
= 'expect -c \'spawn %s; expect "%s" { send "%s" } timeout exp_continue; interact\'' % (cmdline
, cfg
['expect']['src'], cfg
['expect']['dst'])
200 run_in_console(cmdline
, title
)
203 if not is_override('dryrun'):
204 subprocess
.call(cmdline
, shell
= True)
206 def ski_run(platform
, machine
, processor
):
207 run_in_console('ski -i contrib/conf/ski.conf', 'HelenOS/ia64 on ski')
209 def msim_run(platform
, machine
, processor
):
211 run_in_console('msim -c contrib/conf/msim.conf', 'HelenOS/mips32 on msim')
213 def spike_run(platform
, machine
, processor
):
214 run_in_console('spike image.boot', 'HelenOS/risvc64 on Spike')
219 'image' : 'image.iso'
224 'image' : 'image.boot',
231 'image' : 'image.iso'
244 'image' : 'image.boot',
249 'image' : 'image.boot',
255 'image' : 'image.iso',
260 'image' : 'image.boot'
266 'image' : 'image.iso',
272 'image' : '-drive if=pflash,readonly=on,file=image.iso',
287 print("%s - emulator wrapper for running HelenOS\n" % os
.path
.basename(sys
.argv
[0]))
288 print("%s [-d] [-h] [-net e1k|rtl8139|ne2k] [-nohdd] [-nokvm] [-nonet] [-nosnd] [-nousb]\n" %
289 os
.path
.basename(sys
.argv
[0]))
290 print("-d\tDry run: do not run the emulation, just print the command line.")
291 print("-h\tPrint the usage information and exit.")
292 print("-nohdd\tDisable hard disk, if applicable.")
293 print("-nokvm\tDisable KVM, if applicable.")
294 print("-nonet\tDisable networking support, if applicable.")
295 print("-nosnd\tDisable sound, if applicable.")
296 print("-nousb\tDisable USB support, if applicable.")
298 def fail(platform
, machine
):
299 print("Cannot start emulation for the chosen configuration. (%s/%s)" % (platform
, machine
))
305 for i
in range(1, len(sys
.argv
)):
309 if not 'net' in overrides
.keys():
310 overrides
['net'] = {}
311 if sys
.argv
[i
] == 'e1k':
312 overrides
['net']['e1k'] = True
313 elif sys
.argv
[i
] == 'rtl8139':
314 overrides
['net']['rtl8139'] = True
315 elif sys
.argv
[i
] == 'ne2k':
316 overrides
['net']['ne2k'] = True
321 elif sys
.argv
[i
] == '-h':
324 elif sys
.argv
[i
] == '-d':
325 overrides
['dryrun'] = True
326 elif sys
.argv
[i
] == '-net' and i
< len(sys
.argv
) - 1:
328 elif sys
.argv
[i
] == '-nohdd':
329 overrides
['nohdd'] = True
330 elif sys
.argv
[i
] == '-nokvm':
331 overrides
['nokvm'] = True
332 elif sys
.argv
[i
] == '-nonet':
333 overrides
['nonet'] = True
334 elif sys
.argv
[i
] == '-nosnd':
335 overrides
['nosnd'] = True
336 elif sys
.argv
[i
] == '-nousb':
337 overrides
['nousb'] = True
343 autotool
.read_config(autotool
.CONFIG
, config
)
345 if 'PLATFORM' in config
.keys():
346 platform
= config
['PLATFORM']
350 if 'MACHINE' in config
.keys():
351 mach
= config
['MACHINE']
355 if 'PROCESSOR' in config
.keys():
356 processor
= config
['PROCESSOR']
361 emu_run
= cfg_get(platform
, mach
, processor
)['run']
362 emu_run(platform
, mach
, processor
)