OLD | NEW |
| (Empty) |
1 #!/bin/bash | |
2 # | |
3 # Copyright (c) 2012 The Native Client Authors. All rights reserved. | |
4 # Use of this source code is governed by a BSD-style license that can be | |
5 # found in the LICENSE file. | |
6 | |
7 set -o nounset | |
8 set -o errexit | |
9 | |
10 #@ Various commands to emulate arm code using qemu | |
11 #@ | |
12 #@ Note: this script is not meant to be run as | |
13 #@ tools/llvm/qemu_tool.sh | |
14 #@ but rather as: | |
15 #@ toolchain/linux_arm-trusted/qemu_tool.sh | |
16 | |
17 # From a qemu build based on qemu-0.10.1.tar.gz | |
18 readonly SDK_ROOT=$(dirname $0) | |
19 readonly QEMU=${SDK_ROOT}/qemu-arm | |
20 readonly QEMU_STOCK=/usr/bin/qemu-arm | |
21 readonly QEMU_JAIL=${SDK_ROOT} | |
22 # NOTE: some useful debugging options for qemu: | |
23 # env vars: | |
24 # QEMU_STRACE=1 | |
25 # args: | |
26 # -strace | |
27 # -d out_asm,in_asm,op,int,exec,cpu | |
28 # c.f. cpu_log_items in qemu-XXX/exec.c | |
29 readonly QEMU_ARGS="-cpu cortex-a8" | |
30 readonly QEMU_ARGS_DEBUG="-d in_asm,int,exec,cpu" | |
31 readonly QEMU_ARGS_DEBUG_SR="-d in_asm,int,exec,cpu,service_runtime" | |
32 | |
33 ###################################################################### | |
34 # Helpers | |
35 ###################################################################### | |
36 | |
37 Banner() { | |
38 echo "######################################################################" | |
39 echo $* | |
40 echo "######################################################################" | |
41 } | |
42 | |
43 Usage() { | |
44 egrep "^#@" $0 | cut --bytes=3- | |
45 } | |
46 | |
47 | |
48 CheckPrerequisites () { | |
49 if [[ ! -d ${QEMU_JAIL} ]] ; then | |
50 echo "ERROR: no proper root-jail directory found" | |
51 exit -1 | |
52 fi | |
53 } | |
54 | |
55 | |
56 Hints() { | |
57 echo | |
58 echo "traces can be found in /tmp/qemu.log" | |
59 echo "for faster execution disable sel_ldr validation" | |
60 echo | |
61 } | |
62 | |
63 ###################################################################### | |
64 | |
65 #@ | |
66 #@ help | |
67 #@ | |
68 #@ print help for all modes | |
69 help () { | |
70 Usage | |
71 } | |
72 | |
73 #@ | |
74 #@ run | |
75 #@ | |
76 #@ run emulation using a locally patched qemu | |
77 run() { | |
78 CheckPrerequisites | |
79 exec ${QEMU} -L ${QEMU_JAIL} ${QEMU_ARGS} "$@" | |
80 } | |
81 | |
82 #@ | |
83 #@ run_stock | |
84 #@ | |
85 #@ run emulation using the stock qemu | |
86 run_stock() { | |
87 exec ${QEMU_STOCK} -L ${QEMU_JAIL} ${QEMU_ARGS} "$@" | |
88 } | |
89 | |
90 #@ | |
91 #@ run_debug | |
92 #@ | |
93 #@ run emulation but also generate trace in /tmp | |
94 run_debug() { | |
95 Hints | |
96 CheckPrerequisites | |
97 exec ${QEMU} -L ${QEMU_JAIL} ${QEMU_ARGS} ${QEMU_ARGS_DEBUG} "$@" | |
98 } | |
99 | |
100 #@ | |
101 #@ run_debug_service_runtime | |
102 #@ | |
103 #@ run emulation but also generate trace in /tmp even for service_runtime | |
104 run_debug_service_runtime() { | |
105 Hints | |
106 CheckPrerequisites | |
107 exec ${QEMU} -L ${QEMU_JAIL} ${QEMU_ARGS} ${QEMU_ARGS_DEBUG_SR} "$@" | |
108 } | |
109 | |
110 #@ | |
111 #@ install_stock | |
112 #@ | |
113 #@ install stock qemu emulator (for user mode) | |
114 install_stock_qemu() { | |
115 sudo apt-get install qemu-user | |
116 } | |
117 | |
118 ###################################################################### | |
119 if [[ "$0" == *run_under_qemu_arm ]] ; then | |
120 run "$@" | |
121 elif [[ $# -eq 0 ]] ; then | |
122 echo "you must specify a mode on the commandline:" | |
123 echo | |
124 Usage | |
125 exit -1 | |
126 elif [[ "$(type -t $1)" != "function" ]]; then | |
127 echo "ERROR: unknown function '$1'." >&2 | |
128 echo "For help, try:" | |
129 echo " $0 help" | |
130 exit 1 | |
131 else | |
132 "$@" | |
133 fi | |
OLD | NEW |