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