forked from cahirwpz/mimiker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunch
executable file
·115 lines (96 loc) · 4.18 KB
/
launch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/python3
import argparse
import os
import os.path
import signal
import launcher
UART_PORT_BASE = 8000
GDB_PORT_BASE = 9100
if __name__ == '__main__':
# Probe which tools are available.
simulators, sim_default = launcher.find_simulators()
outputs, out_default = launcher.find_outputs()
debuggers, dbg_default = launcher.find_debuggers()
if len(simulators) < 1:
raise SystemExit('No simulators found!')
parser = argparse.ArgumentParser(
description='Launch kernel in Malta board simulator.')
parser.add_argument('-k', '--kernel', metavar='KERNEL', type=str,
default='mimiker.elf',
help='Kernel image file in ELF format.')
parser.add_argument('args', metavar='ARGS', type=str, nargs='*',
help='Kernel arguments.')
parser.add_argument('-D', '--debugger', metavar='DEBUGGER', type=str,
choices=debuggers.keys(), default=dbg_default,
help=('Run debugging sesion with selected debugger. '
'Available options: %s. Default: %s.' %
(', '.join(sorted(debuggers)), dbg_default)))
parser.add_argument('-S', '--simulator', metavar='SIMULATOR', type=str,
choices=simulators.keys(), default=sim_default,
help=('Simulator to use. '
'Available options: %s. Default: %s.' %
(', '.join(sorted(simulators)), sim_default)))
parser.add_argument('-O', '--output', metavar='OUTPUT', type=str,
choices=outputs, default=out_default,
help=('Sink for UART output including kernel messages.'
' Available options: %s. Default: %s.' %
(', '.join(sorted(outputs)), out_default)))
parser.add_argument('-t', action='store_true',
help='Shorthand for --output stdio')
parser.add_argument('-s', action='store_true',
help='Shorthand for --output server')
parser.add_argument('-d', action='store_true',
help='Shorthand for --debugger gdb.')
parser.add_argument('-g', '--graphics', action='store_true',
help='Enable VGA output.')
args = parser.parse_args()
# Check if the kernel file is available
if not os.path.isfile(args.kernel):
raise SystemExit('%s: file does not exist!' % args.kernel)
# Support convenient -s and -t options
if args.t and args.s:
raise SystemExit('Options -s and -t are exclusive')
elif args.t:
args.output = 'stdio'
elif args.s:
args.output = 'server'
# Support -d option
if args.d:
args.debugger = 'gdb'
debug = args.debugger != 'none'
if debug and args.output == 'stdio':
raise SystemExit('ERROR: Unable to start both debugger and simulator '
'in stdio output mode.')
uart_port = UART_PORT_BASE + os.getuid()
gdb_port = GDB_PORT_BASE + os.getuid()
launcher.prepare_gdbinit(gdb_port)
sim = simulators[args.simulator]
out = outputs[args.output]
dbg = debuggers[args.debugger]
cfg_args = {'kernel': args.kernel,
'args': ' '.join(args.args),
'debug': debug,
'graphics': args.graphics,
'gdb_port': gdb_port,
'uart_port': uart_port}
sim.configure(**cfg_args)
out.configure(**cfg_args)
dbg.configure(**cfg_args)
# When the debugger exits, we'll regain the terminal foreground. This
# generates SIGTTOU which normally kills the process, so we need to ignore
# this signal.
signal.signal(signal.SIGTTOU, signal.SIG_IGN)
sim.start()
out.start()
dbg.start()
# Wait until any of these program terminates. This way the user may end
# their session by either closing the simulator, the debugger, or even the
# xterm window.
try:
launcher.wait_any([out, sim, dbg])
except KeyboardInterrupt:
pass
# Stop the programs in reverse order, less chance they'll be confused
dbg.stop()
out.stop()
sim.stop()