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