[df64dbc] | 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 |
|
---|
[1c24c7c] | 35 | import os
|
---|
[f5ceb18] | 36 | import sys
|
---|
[1c24c7c] | 37 | import subprocess
|
---|
[df64dbc] | 38 | import autotool
|
---|
[8a26f82] | 39 | import platform
|
---|
[df64dbc] | 40 |
|
---|
[f5ceb18] | 41 | overrides = {}
|
---|
| 42 |
|
---|
| 43 | def is_override(str):
|
---|
| 44 | if str in overrides.keys():
|
---|
| 45 | return overrides[str]
|
---|
| 46 | return False
|
---|
| 47 |
|
---|
| 48 | def cfg_get(platform, machine):
|
---|
| 49 | if machine == "":
|
---|
| 50 | return emulators[platform]
|
---|
| 51 | else:
|
---|
| 52 | return emulators[platform][machine]
|
---|
| 53 |
|
---|
[df64dbc] | 54 | def run_in_console(cmd, title):
|
---|
| 55 | cmdline = 'xterm -T ' + '"' + title + '"' + ' -e ' + cmd
|
---|
[e4a1497] | 56 | print(cmdline)
|
---|
[f5ceb18] | 57 | if not is_override('dryrun'):
|
---|
| 58 | subprocess.call(cmdline, shell = True);
|
---|
[df64dbc] | 59 |
|
---|
[8a26f82] | 60 | def get_host_native_width():
|
---|
| 61 | return int(platform.architecture()[0].strip('bit'))
|
---|
| 62 |
|
---|
| 63 | def pc_options(guest_width):
|
---|
| 64 | opts = ''
|
---|
| 65 |
|
---|
| 66 | # Do not enable KVM if running 64 bits HelenOS
|
---|
| 67 | # on 32 bits host
|
---|
| 68 | host_width = get_host_native_width()
|
---|
[f5ceb18] | 69 | if guest_width <= host_width and not is_override('nokvm'):
|
---|
[8a26f82] | 70 | opts = opts + ' -enable-kvm'
|
---|
| 71 |
|
---|
| 72 | # Remove the leading space
|
---|
| 73 | return opts[1:]
|
---|
[df64dbc] | 74 |
|
---|
| 75 | def malta_options():
|
---|
| 76 | return '-cpu 4Kc'
|
---|
| 77 |
|
---|
| 78 | def platform_to_qemu_options(platform, machine):
|
---|
| 79 | if platform == 'amd64':
|
---|
[8a26f82] | 80 | return 'system-x86_64', pc_options(64)
|
---|
[df64dbc] | 81 | elif platform == 'arm32':
|
---|
[83b01c2] | 82 | return 'system-arm', '-M integratorcp'
|
---|
[df64dbc] | 83 | elif platform == 'ia32':
|
---|
[8a26f82] | 84 | return 'system-i386', pc_options(32)
|
---|
[df64dbc] | 85 | elif platform == 'mips32':
|
---|
| 86 | if machine == 'lmalta':
|
---|
| 87 | return 'system-mipsel', malta_options()
|
---|
| 88 | elif machine == 'bmalta':
|
---|
| 89 | return 'system-mips', malta_options()
|
---|
| 90 | elif platform == 'ppc32':
|
---|
[644352c] | 91 | return 'system-ppc', '-m 256'
|
---|
[df64dbc] | 92 | elif platform == 'sparc64':
|
---|
| 93 | return 'system-sparc64', ''
|
---|
| 94 |
|
---|
[129b92c6] | 95 | def hdisk_mk():
|
---|
[df64dbc] | 96 | if not os.path.exists('hdisk.img'):
|
---|
| 97 | subprocess.call('tools/mkfat.py 1048576 uspace/dist/data hdisk.img', shell = True)
|
---|
[f5ceb18] | 98 |
|
---|
[129b92c6] | 99 | def qemu_bd_options():
|
---|
| 100 | if is_override('nohdd'):
|
---|
| 101 | return ''
|
---|
| 102 |
|
---|
| 103 | hdisk_mk()
|
---|
| 104 |
|
---|
[5fdad22] | 105 | return ' -drive file=hdisk.img,index=0,media=disk,format=raw'
|
---|
[df64dbc] | 106 |
|
---|
| 107 | def qemu_nic_ne2k_options():
|
---|
| 108 | return ' -device ne2k_isa,irq=5,vlan=0'
|
---|
| 109 |
|
---|
| 110 | def qemu_nic_e1k_options():
|
---|
| 111 | return ' -device e1000,vlan=0'
|
---|
| 112 |
|
---|
| 113 | def qemu_nic_rtl8139_options():
|
---|
| 114 | return ' -device rtl8139,vlan=0'
|
---|
| 115 |
|
---|
| 116 | def qemu_net_options():
|
---|
[f5ceb18] | 117 | if is_override('nonet'):
|
---|
| 118 | return ''
|
---|
| 119 |
|
---|
| 120 | nic_options = ''
|
---|
| 121 | if 'net' in overrides.keys():
|
---|
| 122 | if 'e1k' in overrides['net'].keys():
|
---|
| 123 | nic_options += qemu_nic_e1k_options()
|
---|
| 124 | if 'rtl8139' in overrides['net'].keys():
|
---|
| 125 | nic_options += qemu_nic_rtl8139_options()
|
---|
| 126 | if 'ne2k' in overrides['net'].keys():
|
---|
| 127 | nic_options += qemu_nic_ne2k_options()
|
---|
| 128 | else:
|
---|
| 129 | # Use the default NIC
|
---|
| 130 | nic_options += qemu_nic_e1k_options()
|
---|
| 131 |
|
---|
[e4a1497] | 132 | 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'
|
---|
[df64dbc] | 133 |
|
---|
| 134 | def qemu_usb_options():
|
---|
[f5ceb18] | 135 | if is_override('nousb'):
|
---|
| 136 | return ''
|
---|
| 137 | return ' -usb'
|
---|
[df64dbc] | 138 |
|
---|
[f5ceb18] | 139 | def qemu_audio_options():
|
---|
| 140 | if is_override('nosnd'):
|
---|
| 141 | return ''
|
---|
[089901e] | 142 | return ' -device intel-hda -device hda-duplex'
|
---|
[f5ceb18] | 143 |
|
---|
| 144 | def qemu_run(platform, machine):
|
---|
| 145 | cfg = cfg_get(platform, machine)
|
---|
[df64dbc] | 146 | suffix, options = platform_to_qemu_options(platform, machine)
|
---|
| 147 | cmd = 'qemu-' + suffix
|
---|
| 148 |
|
---|
| 149 | cmdline = cmd
|
---|
| 150 | if options != '':
|
---|
| 151 | cmdline += ' ' + options
|
---|
| 152 |
|
---|
[f5ceb18] | 153 | cmdline += qemu_bd_options()
|
---|
| 154 |
|
---|
| 155 | if (not 'net' in cfg.keys()) or cfg['net']:
|
---|
[df64dbc] | 156 | cmdline += qemu_net_options()
|
---|
[f5ceb18] | 157 | if (not 'usb' in cfg.keys()) or cfg['usb']:
|
---|
[df64dbc] | 158 | cmdline += qemu_usb_options()
|
---|
[f5ceb18] | 159 | if (not 'audio' in cfg.keys()) or cfg['audio']:
|
---|
| 160 | cmdline += qemu_audio_options()
|
---|
[df64dbc] | 161 |
|
---|
[f5ceb18] | 162 | if cfg['image'] == 'image.iso':
|
---|
[df64dbc] | 163 | cmdline += ' -boot d -cdrom image.iso'
|
---|
[f5ceb18] | 164 | elif cfg['image'] == 'image.boot':
|
---|
[df64dbc] | 165 | cmdline += ' -kernel image.boot'
|
---|
| 166 |
|
---|
[f5ceb18] | 167 | if ('console' in cfg.keys()) and not cfg['console']:
|
---|
[df64dbc] | 168 | cmdline += ' -nographic'
|
---|
| 169 |
|
---|
| 170 | title = 'HelenOS/' + platform
|
---|
| 171 | if machine != '':
|
---|
| 172 | title += ' on ' + machine
|
---|
| 173 | run_in_console(cmdline, title)
|
---|
| 174 | else:
|
---|
[e4a1497] | 175 | print(cmdline)
|
---|
[f5ceb18] | 176 | if not is_override('dryrun'):
|
---|
| 177 | subprocess.call(cmdline, shell = True)
|
---|
[df64dbc] | 178 |
|
---|
[f5ceb18] | 179 | def ski_run(platform, machine):
|
---|
[df64dbc] | 180 | run_in_console('ski -i contrib/conf/ski.conf', 'HelenOS/ia64 on ski')
|
---|
| 181 |
|
---|
[f5ceb18] | 182 | def msim_run(platform, machine):
|
---|
[129b92c6] | 183 | hdisk_mk()
|
---|
[df64dbc] | 184 | run_in_console('msim -c contrib/conf/msim.conf', 'HelenOS/mips32 on msim')
|
---|
| 185 |
|
---|
[f5ceb18] | 186 |
|
---|
| 187 | emulators = {
|
---|
| 188 | 'amd64' : {
|
---|
| 189 | 'run' : qemu_run,
|
---|
| 190 | 'image' : 'image.iso'
|
---|
| 191 | },
|
---|
| 192 | 'arm32' : {
|
---|
| 193 | 'integratorcp' : {
|
---|
| 194 | 'run' : qemu_run,
|
---|
| 195 | 'image' : 'image.boot',
|
---|
| 196 | 'net' : False,
|
---|
| 197 | 'audio' : False
|
---|
| 198 | }
|
---|
| 199 | },
|
---|
| 200 | 'ia32' : {
|
---|
| 201 | 'run' : qemu_run,
|
---|
| 202 | 'image' : 'image.iso'
|
---|
| 203 | },
|
---|
| 204 | 'ia64' : {
|
---|
| 205 | 'ski' : {
|
---|
| 206 | 'run' : ski_run
|
---|
| 207 | }
|
---|
| 208 | },
|
---|
| 209 | 'mips32' : {
|
---|
| 210 | 'msim' : {
|
---|
| 211 | 'run' : msim_run
|
---|
| 212 | },
|
---|
| 213 | 'lmalta' : {
|
---|
| 214 | 'run' : qemu_run,
|
---|
| 215 | 'image' : 'image.boot',
|
---|
| 216 | 'console' : False
|
---|
| 217 | },
|
---|
| 218 | 'bmalta' : {
|
---|
| 219 | 'run' : qemu_run,
|
---|
| 220 | 'image' : 'image.boot',
|
---|
| 221 | 'console' : False
|
---|
| 222 | },
|
---|
| 223 | },
|
---|
| 224 | 'ppc32' : {
|
---|
| 225 | 'run' : qemu_run,
|
---|
| 226 | 'image' : 'image.iso',
|
---|
| 227 | 'audio' : False
|
---|
| 228 | },
|
---|
| 229 | 'sparc64' : {
|
---|
| 230 | 'generic' : {
|
---|
| 231 | 'run' : qemu_run,
|
---|
| 232 | 'image' : 'image.iso',
|
---|
| 233 | 'audio' : False
|
---|
| 234 | }
|
---|
| 235 | },
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | def usage():
|
---|
| 239 | print("%s - emulator wrapper for running HelenOS\n" % os.path.basename(sys.argv[0]))
|
---|
| 240 | print("%s [-d] [-h] [-net e1k|rtl8139|ne2k] [-nohdd] [-nokvm] [-nonet] [-nosnd] [-nousb]\n" %
|
---|
| 241 | os.path.basename(sys.argv[0]))
|
---|
| 242 | print("-d\tDry run: do not run the emulation, just print the command line.")
|
---|
| 243 | print("-h\tPrint the usage information and exit.")
|
---|
| 244 | print("-nohdd\tDisable hard disk, if applicable.")
|
---|
| 245 | print("-nokvm\tDisable KVM, if applicable.")
|
---|
| 246 | print("-nonet\tDisable networking support, if applicable.")
|
---|
| 247 | print("-nosnd\tDisable sound, if applicable.")
|
---|
| 248 | print("-nousb\tDisable USB support, if applicable.")
|
---|
[df64dbc] | 249 |
|
---|
| 250 | def run():
|
---|
[f5ceb18] | 251 | expect_nic = False
|
---|
| 252 |
|
---|
| 253 | for i in range(1, len(sys.argv)):
|
---|
| 254 |
|
---|
| 255 | if expect_nic:
|
---|
| 256 | expect_nic = False
|
---|
| 257 | if not 'net' in overrides.keys():
|
---|
| 258 | overrides['net'] = {}
|
---|
| 259 | if sys.argv[i] == 'e1k':
|
---|
| 260 | overrides['net']['e1k'] = True
|
---|
| 261 | elif sys.argv[i] == 'rtl8139':
|
---|
| 262 | overrides['net']['rtl8139'] = True
|
---|
| 263 | elif sys.argv[i] == 'ne2k':
|
---|
| 264 | overrides['net']['ne2k'] = True
|
---|
| 265 | else:
|
---|
| 266 | usage()
|
---|
| 267 | exit()
|
---|
| 268 |
|
---|
| 269 | elif sys.argv[i] == '-h':
|
---|
| 270 | usage()
|
---|
| 271 | exit()
|
---|
| 272 | elif sys.argv[i] == '-d':
|
---|
| 273 | overrides['dryrun'] = True
|
---|
| 274 | elif sys.argv[i] == '-net' and i < len(sys.argv) - 1:
|
---|
| 275 | expect_nic = True
|
---|
| 276 | elif sys.argv[i] == '-nohdd':
|
---|
| 277 | overrides['nohdd'] = True
|
---|
| 278 | elif sys.argv[i] == '-nokvm':
|
---|
| 279 | overrides['nokvm'] = True
|
---|
| 280 | elif sys.argv[i] == '-nonet':
|
---|
| 281 | overrides['nonet'] = True
|
---|
| 282 | elif sys.argv[i] == '-nosnd':
|
---|
| 283 | overrides['nosnd'] = True
|
---|
| 284 | elif sys.argv[i] == '-nousb':
|
---|
| 285 | overrides['nousb'] = True
|
---|
| 286 | else:
|
---|
| 287 | usage()
|
---|
| 288 | exit()
|
---|
| 289 |
|
---|
[df64dbc] | 290 | config = {}
|
---|
| 291 | autotool.read_config(autotool.CONFIG, config)
|
---|
| 292 |
|
---|
[f5ceb18] | 293 | if 'PLATFORM' in config.keys():
|
---|
[df64dbc] | 294 | platform = config['PLATFORM']
|
---|
[f5ceb18] | 295 | else:
|
---|
[df64dbc] | 296 | platform = ''
|
---|
| 297 |
|
---|
[f5ceb18] | 298 | if 'MACHINE' in config.keys():
|
---|
[df64dbc] | 299 | mach = config['MACHINE']
|
---|
[f5ceb18] | 300 | else:
|
---|
[df64dbc] | 301 | mach = ''
|
---|
| 302 |
|
---|
| 303 | try:
|
---|
[f5ceb18] | 304 | emu_run = cfg_get(platform, mach)['run']
|
---|
[df64dbc] | 305 | except:
|
---|
[f5ceb18] | 306 | print("Cannot start emulation for the chosen configuration. (%s/%s)" % (platform, mach))
|
---|
[df64dbc] | 307 | return
|
---|
| 308 |
|
---|
[f5ceb18] | 309 | emu_run(platform, mach)
|
---|
[df64dbc] | 310 |
|
---|
| 311 | run()
|
---|