[df64dbc] | 1 | #!/usr/bin/env python
|
---|
| 2 | #
|
---|
[3f4c537a] | 3 | # Copyright (c) 2013 Jakub Jermar
|
---|
[df64dbc] | 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
|
---|
[df425da] | 40 | import thread
|
---|
| 41 | import time
|
---|
[df64dbc] | 42 |
|
---|
[f5ceb18] | 43 | overrides = {}
|
---|
| 44 |
|
---|
| 45 | def is_override(str):
|
---|
| 46 | if str in overrides.keys():
|
---|
| 47 | return overrides[str]
|
---|
| 48 | return False
|
---|
| 49 |
|
---|
[df425da] | 50 | def cfg_get(platform, machine, processor):
|
---|
| 51 | if machine == "" or emulators[platform].has_key("run"):
|
---|
[f5ceb18] | 52 | return emulators[platform]
|
---|
[df425da] | 53 | elif processor == "" or emulators[platform][machine].has_key("run"):
|
---|
[f5ceb18] | 54 | return emulators[platform][machine]
|
---|
[df425da] | 55 | else:
|
---|
| 56 | return emulators[platform][machine][processor]
|
---|
[f5ceb18] | 57 |
|
---|
[e4c8e3cf] | 58 | def termemu_detect():
|
---|
[ac49d23c] | 59 | emus = ['gnome-terminal', 'xfce4-terminal', 'xterm']
|
---|
| 60 | for termemu in emus:
|
---|
[e4c8e3cf] | 61 | try:
|
---|
| 62 | subprocess.check_output('which ' + termemu, shell = True)
|
---|
| 63 | return termemu
|
---|
| 64 | except:
|
---|
| 65 | pass
|
---|
| 66 |
|
---|
[ac49d23c] | 67 | print('Could not find any of the terminal emulators %s.'%(emus))
|
---|
| 68 | sys.exit(1)
|
---|
| 69 |
|
---|
[df64dbc] | 70 | def run_in_console(cmd, title):
|
---|
[ac49d23c] | 71 | temu = termemu_detect()
|
---|
| 72 | if temu == 'gnome-terminal':
|
---|
[ecf0a04b] | 73 | cmdline = temu + ' -- ' + cmd
|
---|
[ac49d23c] | 74 | else:
|
---|
[ecf0a04b] | 75 | ecmd = cmd.replace('"', '\\"')
|
---|
[ac49d23c] | 76 | cmdline = temu + ' -T ' + '"' + title + '"' + ' -e "' + ecmd + '"'
|
---|
| 77 |
|
---|
[e4a1497] | 78 | print(cmdline)
|
---|
[f5ceb18] | 79 | if not is_override('dryrun'):
|
---|
[e4c8e3cf] | 80 | subprocess.call(cmdline, shell = True)
|
---|
[df64dbc] | 81 |
|
---|
[8a26f82] | 82 | def get_host_native_width():
|
---|
| 83 | return int(platform.architecture()[0].strip('bit'))
|
---|
| 84 |
|
---|
| 85 | def pc_options(guest_width):
|
---|
| 86 | opts = ''
|
---|
[a35b458] | 87 |
|
---|
[8a26f82] | 88 | # Do not enable KVM if running 64 bits HelenOS
|
---|
| 89 | # on 32 bits host
|
---|
| 90 | host_width = get_host_native_width()
|
---|
[f5ceb18] | 91 | if guest_width <= host_width and not is_override('nokvm'):
|
---|
[8a26f82] | 92 | opts = opts + ' -enable-kvm'
|
---|
[a35b458] | 93 |
|
---|
[8a26f82] | 94 | # Remove the leading space
|
---|
| 95 | return opts[1:]
|
---|
[df64dbc] | 96 |
|
---|
| 97 | def malta_options():
|
---|
[dabaa83] | 98 | return '-cpu 4Kc -append "console=devices/\\hw\\pci0\\00:0a.0\\com1\\a"'
|
---|
[df64dbc] | 99 |
|
---|
[739bc43] | 100 | def find_firmware(name, environ_var, default_paths, extra_info=None):
|
---|
| 101 | """Find firmware image(s)."""
|
---|
| 102 |
|
---|
| 103 | if environ_var in os.environ:
|
---|
| 104 | return os.environ[environ_var]
|
---|
| 105 |
|
---|
| 106 | for path in default_paths:
|
---|
| 107 | if os.path.exists(path):
|
---|
| 108 | return path
|
---|
| 109 |
|
---|
| 110 | sys.stderr.write("Cannot find %s binary image(s)!\n" % name)
|
---|
| 111 | sys.stderr.write(
|
---|
| 112 | "Either set %s environment variable accordingly or place the image(s) in one of the default locations: %s.\n" %
|
---|
| 113 | (environ_var, ", ".join(default_paths)))
|
---|
| 114 | if extra_info is not None:
|
---|
| 115 | sys.stderr.write(extra_info)
|
---|
| 116 | return None
|
---|
| 117 |
|
---|
[9185e42] | 118 | def platform_to_qemu_options(platform, machine, processor):
|
---|
[df64dbc] | 119 | if platform == 'amd64':
|
---|
[8a26f82] | 120 | return 'system-x86_64', pc_options(64)
|
---|
[df64dbc] | 121 | elif platform == 'arm32':
|
---|
[83b01c2] | 122 | return 'system-arm', '-M integratorcp'
|
---|
[84176f3] | 123 | elif platform == 'arm64':
|
---|
[739bc43] | 124 | # Search for the EDK2 firmware image
|
---|
| 125 | default_paths = (
|
---|
| 126 | '/usr/local/qemu-efi-aarch64/QEMU_EFI.fd', # Custom
|
---|
| 127 | '/usr/share/edk2/aarch64/QEMU_EFI.fd', # Fedora
|
---|
| 128 | '/usr/share/qemu-efi-aarch64/QEMU_EFI.fd', # Ubuntu
|
---|
| 129 | )
|
---|
| 130 | extra_info = ("Pre-compiled binary can be obtained from "
|
---|
| 131 | "http://snapshots.linaro.org/components/kernel/leg-virt-tianocore-edk2-upstream/latest/QEMU-AARCH64/RELEASE_GCC49/QEMU_EFI.fd.\n")
|
---|
| 132 | efi_path = find_firmware(
|
---|
| 133 | "EDK2", 'EW_QEMU_EFI_AARCH64', default_paths, extra_info)
|
---|
| 134 | if efi_path is None:
|
---|
[84176f3] | 135 | raise Exception
|
---|
[739bc43] | 136 |
|
---|
[84176f3] | 137 | return 'system-aarch64', \
|
---|
[739bc43] | 138 | '-M virt -cpu cortex-a57 -m 1024 -bios %s' % efi_path
|
---|
[df64dbc] | 139 | elif platform == 'ia32':
|
---|
[8a26f82] | 140 | return 'system-i386', pc_options(32)
|
---|
[df64dbc] | 141 | elif platform == 'mips32':
|
---|
| 142 | if machine == 'lmalta':
|
---|
| 143 | return 'system-mipsel', malta_options()
|
---|
| 144 | elif machine == 'bmalta':
|
---|
| 145 | return 'system-mips', malta_options()
|
---|
| 146 | elif platform == 'ppc32':
|
---|
[644352c] | 147 | return 'system-ppc', '-m 256'
|
---|
[df64dbc] | 148 | elif platform == 'sparc64':
|
---|
[9185e42] | 149 | if machine != 'generic':
|
---|
| 150 | raise Exception
|
---|
| 151 | if processor == 'us':
|
---|
[7f4937e] | 152 | return 'system-sparc64', '-M sun4u --prom-env boot-args="console=devices/\\hw\\pci0\\01:01.0\\com1\\a"'
|
---|
[739bc43] | 153 |
|
---|
| 154 | # processor = 'sun4v'
|
---|
| 155 | opensparc_bins = find_firmware(
|
---|
| 156 | "OpenSPARC", 'OPENSPARC_BINARIES',
|
---|
| 157 | ('/usr/local/opensparc/image/', ))
|
---|
| 158 | if opensparc_bins is None:
|
---|
[9185e42] | 159 | raise Exception
|
---|
| 160 |
|
---|
| 161 | return 'system-sparc64', '-M niagara -m 256 -L %s' % (opensparc_bins)
|
---|
| 162 |
|
---|
[df64dbc] | 163 |
|
---|
[129b92c6] | 164 | def hdisk_mk():
|
---|
[df64dbc] | 165 | if not os.path.exists('hdisk.img'):
|
---|
| 166 | subprocess.call('tools/mkfat.py 1048576 uspace/dist/data hdisk.img', shell = True)
|
---|
[f5ceb18] | 167 |
|
---|
[129b92c6] | 168 | def qemu_bd_options():
|
---|
| 169 | if is_override('nohdd'):
|
---|
| 170 | return ''
|
---|
[a35b458] | 171 |
|
---|
[129b92c6] | 172 | hdisk_mk()
|
---|
[a35b458] | 173 |
|
---|
[13eecc4] | 174 | hdd_options = ''
|
---|
| 175 | if 'hdd' in overrides.keys():
|
---|
| 176 | if 'ata' in overrides['hdd'].keys():
|
---|
| 177 | hdd_options += ''
|
---|
| 178 | elif 'virtio-blk' in overrides['hdd'].keys():
|
---|
| 179 | hdd_options += ',if=virtio'
|
---|
| 180 |
|
---|
| 181 | return ' -drive file=hdisk.img,index=0,media=disk,format=raw' + hdd_options
|
---|
[df64dbc] | 182 |
|
---|
| 183 | def qemu_nic_ne2k_options():
|
---|
[d4b7b29] | 184 | return ' -device ne2k_isa,irq=5,netdev=n1'
|
---|
[df64dbc] | 185 |
|
---|
| 186 | def qemu_nic_e1k_options():
|
---|
[d4b7b29] | 187 | return ' -device e1000,netdev=n1'
|
---|
[df64dbc] | 188 |
|
---|
| 189 | def qemu_nic_rtl8139_options():
|
---|
[d4b7b29] | 190 | return ' -device rtl8139,netdev=n1'
|
---|
[df64dbc] | 191 |
|
---|
[7bf16b7e] | 192 | def qemu_nic_virtio_options():
|
---|
[d4b7b29] | 193 | return ' -device virtio-net,netdev=n1'
|
---|
[7bf16b7e] | 194 |
|
---|
[df64dbc] | 195 | def qemu_net_options():
|
---|
[f5ceb18] | 196 | if is_override('nonet'):
|
---|
| 197 | return ''
|
---|
| 198 |
|
---|
| 199 | nic_options = ''
|
---|
| 200 | if 'net' in overrides.keys():
|
---|
| 201 | if 'e1k' in overrides['net'].keys():
|
---|
| 202 | nic_options += qemu_nic_e1k_options()
|
---|
| 203 | if 'rtl8139' in overrides['net'].keys():
|
---|
| 204 | nic_options += qemu_nic_rtl8139_options()
|
---|
| 205 | if 'ne2k' in overrides['net'].keys():
|
---|
| 206 | nic_options += qemu_nic_ne2k_options()
|
---|
[7bf16b7e] | 207 | if 'virtio-net' in overrides['net'].keys():
|
---|
| 208 | nic_options += qemu_nic_virtio_options()
|
---|
[f5ceb18] | 209 | else:
|
---|
| 210 | # Use the default NIC
|
---|
| 211 | nic_options += qemu_nic_e1k_options()
|
---|
| 212 |
|
---|
[d4b7b29] | 213 | return nic_options + ' -netdev user,id=n1,hostfwd=udp::8080-:8080,hostfwd=udp::8081-:8081,hostfwd=tcp::8080-:8080,hostfwd=tcp::8081-:8081,hostfwd=tcp::2223-:2223'
|
---|
[df64dbc] | 214 |
|
---|
| 215 | def qemu_usb_options():
|
---|
[f5ceb18] | 216 | if is_override('nousb'):
|
---|
| 217 | return ''
|
---|
| 218 | return ' -usb'
|
---|
[df64dbc] | 219 |
|
---|
[5119d34] | 220 | def qemu_xhci_options():
|
---|
| 221 | if is_override('noxhci'):
|
---|
| 222 | return ''
|
---|
| 223 | return ' -device nec-usb-xhci,id=xhci'
|
---|
| 224 |
|
---|
[27de618] | 225 | def qemu_tablet_options():
|
---|
| 226 | if is_override('notablet') or (is_override('nousb') and is_override('noxhci')):
|
---|
| 227 | return ''
|
---|
| 228 | return ' -device usb-tablet'
|
---|
| 229 |
|
---|
[f5ceb18] | 230 | def qemu_audio_options():
|
---|
| 231 | if is_override('nosnd'):
|
---|
| 232 | return ''
|
---|
[089901e] | 233 | return ' -device intel-hda -device hda-duplex'
|
---|
[f5ceb18] | 234 |
|
---|
[df425da] | 235 | def qemu_run(platform, machine, processor):
|
---|
| 236 | cfg = cfg_get(platform, machine, processor)
|
---|
[9185e42] | 237 | suffix, options = platform_to_qemu_options(platform, machine, processor)
|
---|
[df64dbc] | 238 | cmd = 'qemu-' + suffix
|
---|
| 239 |
|
---|
| 240 | cmdline = cmd
|
---|
[3692678] | 241 | if 'qemu_path' in overrides.keys():
|
---|
| 242 | cmdline = overrides['qemu_path'] + cmd
|
---|
| 243 |
|
---|
[df64dbc] | 244 | if options != '':
|
---|
| 245 | cmdline += ' ' + options
|
---|
| 246 |
|
---|
[84176f3] | 247 | if (not 'hdd' in cfg.keys() or cfg['hdd']):
|
---|
| 248 | cmdline += qemu_bd_options()
|
---|
[f5ceb18] | 249 | if (not 'net' in cfg.keys()) or cfg['net']:
|
---|
[df64dbc] | 250 | cmdline += qemu_net_options()
|
---|
[f5ceb18] | 251 | if (not 'usb' in cfg.keys()) or cfg['usb']:
|
---|
[df64dbc] | 252 | cmdline += qemu_usb_options()
|
---|
[5119d34] | 253 | if (not 'xhci' in cfg.keys()) or cfg['xhci']:
|
---|
| 254 | cmdline += qemu_xhci_options()
|
---|
[27de618] | 255 | if (not 'tablet' in cfg.keys()) or cfg['tablet']:
|
---|
| 256 | cmdline += qemu_tablet_options()
|
---|
[f5ceb18] | 257 | if (not 'audio' in cfg.keys()) or cfg['audio']:
|
---|
| 258 | cmdline += qemu_audio_options()
|
---|
[a35b458] | 259 |
|
---|
[868d75c] | 260 | console = ('console' in cfg.keys() and cfg['console'])
|
---|
| 261 |
|
---|
[0ceeac3] | 262 | if (is_override('nographic')):
|
---|
| 263 | cmdline += ' -nographic'
|
---|
| 264 |
|
---|
[868d75c] | 265 | if (not console and (not is_override('nographic')) and not is_override('noserial')):
|
---|
[512579c] | 266 | cmdline += ' -serial vc -monitor stdio'
|
---|
[2fc9bfd] | 267 |
|
---|
[abf8bd8] | 268 | if (is_override('bigmem')):
|
---|
| 269 | cmdline += ' -m 4G'
|
---|
| 270 |
|
---|
[f5ceb18] | 271 | if cfg['image'] == 'image.iso':
|
---|
[28fcaee] | 272 | cmdline += ' -boot d -cdrom build/image.iso'
|
---|
[84176f3] | 273 | elif cfg['image'] == 'image.iso@arm64':
|
---|
| 274 | # Define image.iso cdrom backend.
|
---|
[a73a1453] | 275 | cmdline += ' -drive if=none,file=build/image.iso,id=cdrom,media=cdrom'
|
---|
[84176f3] | 276 | # Define scsi bus.
|
---|
| 277 | cmdline += ' -device virtio-scsi-device'
|
---|
| 278 | # Define cdrom frontend connected to this scsi bus.
|
---|
| 279 | cmdline += ' -device scsi-cd,drive=cdrom'
|
---|
[f5ceb18] | 280 | elif cfg['image'] == 'image.boot':
|
---|
[98975a8] | 281 | cmdline += ' -kernel build/image.boot'
|
---|
[9185e42] | 282 | else:
|
---|
| 283 | cmdline += ' ' + cfg['image']
|
---|
[df64dbc] | 284 |
|
---|
[868d75c] | 285 | if console:
|
---|
[df64dbc] | 286 | cmdline += ' -nographic'
|
---|
| 287 |
|
---|
| 288 | title = 'HelenOS/' + platform
|
---|
| 289 | if machine != '':
|
---|
| 290 | title += ' on ' + machine
|
---|
[9185e42] | 291 | if 'expect' in cfg.keys():
|
---|
| 292 | cmdline = 'expect -c \'spawn %s; expect "%s" { send "%s" } timeout exp_continue; interact\'' % (cmdline, cfg['expect']['src'], cfg['expect']['dst'])
|
---|
[df64dbc] | 293 | run_in_console(cmdline, title)
|
---|
| 294 | else:
|
---|
[e4a1497] | 295 | print(cmdline)
|
---|
[f5ceb18] | 296 | if not is_override('dryrun'):
|
---|
| 297 | subprocess.call(cmdline, shell = True)
|
---|
[3f4c537a] | 298 |
|
---|
[df425da] | 299 | def ski_run(platform, machine, processor):
|
---|
[63d46341] | 300 | run_in_console('ski -i tools/conf/ski.conf', 'HelenOS/ia64 on ski')
|
---|
[df64dbc] | 301 |
|
---|
[df425da] | 302 | def msim_run(platform, machine, processor):
|
---|
[129b92c6] | 303 | hdisk_mk()
|
---|
[63d46341] | 304 | run_in_console('msim -c tools/conf/msim.conf', 'HelenOS/mips32 on msim')
|
---|
[df64dbc] | 305 |
|
---|
[3f4c537a] | 306 | def spike_run(platform, machine, processor):
|
---|
[356e17e0] | 307 | run_in_console('spike -m1073741824:1073741824 build/image.boot', 'HelenOS/risvc64 on Spike')
|
---|
[3f4c537a] | 308 |
|
---|
[f5ceb18] | 309 | emulators = {
|
---|
| 310 | 'amd64' : {
|
---|
| 311 | 'run' : qemu_run,
|
---|
| 312 | 'image' : 'image.iso'
|
---|
| 313 | },
|
---|
| 314 | 'arm32' : {
|
---|
| 315 | 'integratorcp' : {
|
---|
| 316 | 'run' : qemu_run,
|
---|
| 317 | 'image' : 'image.boot',
|
---|
| 318 | 'net' : False,
|
---|
[a1a81f69] | 319 | 'audio' : False,
|
---|
| 320 | 'xhci' : False,
|
---|
| 321 | 'tablet' : False
|
---|
[f5ceb18] | 322 | }
|
---|
| 323 | },
|
---|
[84176f3] | 324 | 'arm64' : {
|
---|
| 325 | 'virt' : {
|
---|
| 326 | 'run' : qemu_run,
|
---|
| 327 | 'image' : 'image.iso@arm64',
|
---|
| 328 | 'audio' : False,
|
---|
| 329 | 'hdd' : False,
|
---|
| 330 | 'net' : False,
|
---|
| 331 | 'tablet' : False,
|
---|
| 332 | 'usb' : False,
|
---|
| 333 | 'xhci' : False
|
---|
| 334 | }
|
---|
| 335 | },
|
---|
[f5ceb18] | 336 | 'ia32' : {
|
---|
| 337 | 'run' : qemu_run,
|
---|
| 338 | 'image' : 'image.iso'
|
---|
| 339 | },
|
---|
| 340 | 'ia64' : {
|
---|
| 341 | 'ski' : {
|
---|
| 342 | 'run' : ski_run
|
---|
| 343 | }
|
---|
| 344 | },
|
---|
| 345 | 'mips32' : {
|
---|
| 346 | 'msim' : {
|
---|
| 347 | 'run' : msim_run
|
---|
| 348 | },
|
---|
| 349 | 'lmalta' : {
|
---|
| 350 | 'run' : qemu_run,
|
---|
| 351 | 'image' : 'image.boot',
|
---|
[868d75c] | 352 | 'console' : True
|
---|
[f5ceb18] | 353 | },
|
---|
| 354 | 'bmalta' : {
|
---|
| 355 | 'run' : qemu_run,
|
---|
| 356 | 'image' : 'image.boot',
|
---|
[868d75c] | 357 | 'console' : True
|
---|
[f5ceb18] | 358 | },
|
---|
| 359 | },
|
---|
| 360 | 'ppc32' : {
|
---|
| 361 | 'run' : qemu_run,
|
---|
| 362 | 'image' : 'image.iso',
|
---|
| 363 | 'audio' : False
|
---|
| 364 | },
|
---|
[3f4c537a] | 365 | 'riscv64' : {
|
---|
| 366 | 'run' : spike_run,
|
---|
| 367 | 'image' : 'image.boot'
|
---|
| 368 | },
|
---|
[f5ceb18] | 369 | 'sparc64' : {
|
---|
| 370 | 'generic' : {
|
---|
[df425da] | 371 | 'us' : {
|
---|
| 372 | 'run' : qemu_run,
|
---|
| 373 | 'image' : 'image.iso',
|
---|
[0195374] | 374 | 'audio' : False,
|
---|
[868d75c] | 375 | 'console' : True,
|
---|
[fd57cf17] | 376 | 'net' : False,
|
---|
| 377 | 'usb' : False,
|
---|
| 378 | 'xhci' : False,
|
---|
| 379 | 'tablet' : False
|
---|
[df425da] | 380 | },
|
---|
| 381 | 'sun4v' : {
|
---|
[9185e42] | 382 | 'run' : qemu_run,
|
---|
[5631c9c] | 383 | 'image' : '-drive if=pflash,readonly=on,file=build/image.iso',
|
---|
[9185e42] | 384 | 'audio' : False,
|
---|
[868d75c] | 385 | 'console' : True,
|
---|
[9185e42] | 386 | 'net' : False,
|
---|
| 387 | 'usb' : False,
|
---|
[fd57cf17] | 388 | 'xhci' : False,
|
---|
| 389 | 'tablet' : False,
|
---|
[9185e42] | 390 | 'expect' : {
|
---|
| 391 | 'src' : 'ok ',
|
---|
| 392 | 'dst' : 'boot\n'
|
---|
| 393 | },
|
---|
[df425da] | 394 | }
|
---|
[f5ceb18] | 395 | }
|
---|
| 396 | },
|
---|
| 397 | }
|
---|
| 398 |
|
---|
| 399 | def usage():
|
---|
| 400 | print("%s - emulator wrapper for running HelenOS\n" % os.path.basename(sys.argv[0]))
|
---|
[13eecc4] | 401 | print("%s [-d] [-h] [-net e1k|rtl8139|ne2k|virtio-net] [-hdd ata|virtio-blk] [-nohdd] [-nokvm] [-nonet] [-nosnd] [-nousb] [-noxhci] [-notablet]\n" %
|
---|
[f5ceb18] | 402 | os.path.basename(sys.argv[0]))
|
---|
| 403 | print("-d\tDry run: do not run the emulation, just print the command line.")
|
---|
| 404 | print("-h\tPrint the usage information and exit.")
|
---|
| 405 | print("-nohdd\tDisable hard disk, if applicable.")
|
---|
| 406 | print("-nokvm\tDisable KVM, if applicable.")
|
---|
| 407 | print("-nonet\tDisable networking support, if applicable.")
|
---|
| 408 | print("-nosnd\tDisable sound, if applicable.")
|
---|
| 409 | print("-nousb\tDisable USB support, if applicable.")
|
---|
[5119d34] | 410 | print("-noxhci\tDisable XHCI support, if applicable.")
|
---|
[27de618] | 411 | print("-notablet\tDisable USB tablet (use only relative-position PS/2 mouse instead), if applicable.")
|
---|
[abf8bd8] | 412 | print("-nographic\tDisable graphical output. Serial port output must be enabled for this to be useful.")
|
---|
[2fc9bfd] | 413 | print("-noserial\tDisable serial port output in the terminal.")
|
---|
[abf8bd8] | 414 | print("-bigmem\tSets maximum RAM size to 4GB.")
|
---|
[df64dbc] | 415 |
|
---|
[df425da] | 416 | def fail(platform, machine):
|
---|
| 417 | print("Cannot start emulation for the chosen configuration. (%s/%s)" % (platform, machine))
|
---|
[a35b458] | 418 |
|
---|
[df425da] | 419 |
|
---|
[df64dbc] | 420 | def run():
|
---|
[f5ceb18] | 421 | expect_nic = False
|
---|
[13eecc4] | 422 | expect_hdd = False
|
---|
[3692678] | 423 | expect_qemu = False
|
---|
[f5ceb18] | 424 |
|
---|
| 425 | for i in range(1, len(sys.argv)):
|
---|
| 426 |
|
---|
| 427 | if expect_nic:
|
---|
| 428 | expect_nic = False
|
---|
| 429 | if not 'net' in overrides.keys():
|
---|
| 430 | overrides['net'] = {}
|
---|
| 431 | if sys.argv[i] == 'e1k':
|
---|
| 432 | overrides['net']['e1k'] = True
|
---|
| 433 | elif sys.argv[i] == 'rtl8139':
|
---|
| 434 | overrides['net']['rtl8139'] = True
|
---|
| 435 | elif sys.argv[i] == 'ne2k':
|
---|
| 436 | overrides['net']['ne2k'] = True
|
---|
[7bf16b7e] | 437 | elif sys.argv[i] == 'virtio-net':
|
---|
| 438 | overrides['net']['virtio-net'] = True
|
---|
[f5ceb18] | 439 | else:
|
---|
| 440 | usage()
|
---|
| 441 | exit()
|
---|
[f134413] | 442 | continue
|
---|
[f5ceb18] | 443 |
|
---|
[13eecc4] | 444 | if expect_hdd:
|
---|
| 445 | expect_hdd = False
|
---|
| 446 | if not 'hdd' in overrides.keys():
|
---|
| 447 | overrides['hdd'] = {}
|
---|
| 448 | if sys.argv[i] == 'ata':
|
---|
| 449 | overrides['hdd']['ata'] = True
|
---|
| 450 | elif sys.argv[i] == 'virtio-blk':
|
---|
| 451 | overrides['hdd']['virtio-blk'] = True
|
---|
| 452 | else:
|
---|
| 453 | usage()
|
---|
| 454 | exit()
|
---|
| 455 | continue
|
---|
| 456 |
|
---|
[3692678] | 457 | if expect_qemu:
|
---|
| 458 | expect_qemu = False
|
---|
| 459 | overrides['qemu_path'] = sys.argv[i]
|
---|
| 460 |
|
---|
[f5ceb18] | 461 | elif sys.argv[i] == '-h':
|
---|
| 462 | usage()
|
---|
| 463 | exit()
|
---|
| 464 | elif sys.argv[i] == '-d':
|
---|
| 465 | overrides['dryrun'] = True
|
---|
| 466 | elif sys.argv[i] == '-net' and i < len(sys.argv) - 1:
|
---|
| 467 | expect_nic = True
|
---|
[13eecc4] | 468 | elif sys.argv[i] == '-hdd' and i < len(sys.argv) - 1:
|
---|
| 469 | expect_hdd = True
|
---|
[f5ceb18] | 470 | elif sys.argv[i] == '-nohdd':
|
---|
| 471 | overrides['nohdd'] = True
|
---|
| 472 | elif sys.argv[i] == '-nokvm':
|
---|
| 473 | overrides['nokvm'] = True
|
---|
| 474 | elif sys.argv[i] == '-nonet':
|
---|
| 475 | overrides['nonet'] = True
|
---|
| 476 | elif sys.argv[i] == '-nosnd':
|
---|
| 477 | overrides['nosnd'] = True
|
---|
| 478 | elif sys.argv[i] == '-nousb':
|
---|
| 479 | overrides['nousb'] = True
|
---|
[5119d34] | 480 | elif sys.argv[i] == '-noxhci':
|
---|
| 481 | overrides['noxhci'] = True
|
---|
[27de618] | 482 | elif sys.argv[i] == '-notablet':
|
---|
| 483 | overrides['notablet'] = True
|
---|
[0ceeac3] | 484 | elif sys.argv[i] == '-nographic':
|
---|
| 485 | overrides['nographic'] = True
|
---|
[abf8bd8] | 486 | elif sys.argv[i] == '-bigmem':
|
---|
| 487 | overrides['bigmem'] = True
|
---|
[2fc9bfd] | 488 | elif sys.argv[i] == '-noserial':
|
---|
| 489 | overrides['noserial'] = True
|
---|
[3692678] | 490 | elif sys.argv[i] == '-qemu_path' and i < len(sys.argv) - 1:
|
---|
| 491 | expect_qemu = True
|
---|
[f5ceb18] | 492 | else:
|
---|
| 493 | usage()
|
---|
| 494 | exit()
|
---|
| 495 |
|
---|
[df64dbc] | 496 | config = {}
|
---|
| 497 | autotool.read_config(autotool.CONFIG, config)
|
---|
| 498 |
|
---|
[f5ceb18] | 499 | if 'PLATFORM' in config.keys():
|
---|
[df64dbc] | 500 | platform = config['PLATFORM']
|
---|
[f5ceb18] | 501 | else:
|
---|
[df64dbc] | 502 | platform = ''
|
---|
| 503 |
|
---|
[f5ceb18] | 504 | if 'MACHINE' in config.keys():
|
---|
[df64dbc] | 505 | mach = config['MACHINE']
|
---|
[f5ceb18] | 506 | else:
|
---|
[df64dbc] | 507 | mach = ''
|
---|
| 508 |
|
---|
[df425da] | 509 | if 'PROCESSOR' in config.keys():
|
---|
| 510 | processor = config['PROCESSOR']
|
---|
| 511 | else:
|
---|
| 512 | processor = ''
|
---|
| 513 |
|
---|
[df64dbc] | 514 | try:
|
---|
[df425da] | 515 | emu_run = cfg_get(platform, mach, processor)['run']
|
---|
| 516 | emu_run(platform, mach, processor)
|
---|
[df64dbc] | 517 | except:
|
---|
[df425da] | 518 | fail(platform, mach)
|
---|
[df64dbc] | 519 | return
|
---|
| 520 |
|
---|
| 521 | run()
|
---|