Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MorsGames
GitHub Repository: MorsGames/sm64plus
Path: blob/master/tools/calc_bss.sh
7854 views
1
#!/bin/bash
2
# Given a list of header files, compute the bss index that results from
3
# including them. (See prevent_bss_reordering.h for more information.)
4
5
TEMPC=$(mktemp -t bss.XXXXXXX.c)
6
TEMPO=$(mktemp -t bss.XXXXXXX.o)
7
trap "rm -f $TEMPC $TEMPO" EXIT
8
9
set -e
10
11
if [[ $# = 0 ]]; then
12
echo "Usage: ./tools/calc_bss.sh file1.h file2.h ..." >&2
13
exit 1
14
fi
15
16
if [ -z "$QEMU_IRIX" ]; then
17
echo "env variable QEMU_IRIX should point to the qemu-mips binary" >&2
18
exit 1
19
fi
20
21
if [ -z "$CROSS" ]; then
22
CROSS=mips-linux-gnu-
23
fi
24
25
# bss indexing starts at 3
26
for I in {3..255}; do
27
echo "char bss$I;" >> $TEMPC
28
done
29
for I in {0..2}; do
30
echo "char bss$I;" >> $TEMPC
31
done
32
33
while [[ $# -gt 0 ]]; do
34
echo "#include \"$1\"" >> $TEMPC
35
shift
36
done
37
38
echo "char measurement;" >> $TEMPC
39
40
$QEMU_IRIX -silent -L $IRIX_ROOT $IRIX_ROOT/usr/bin/cc -c -non_shared -G 0 \
41
-g -Xcpluscomm -mips2 -I $(pwd)/include/ $TEMPC -o $TEMPO
42
43
LINE=$(${CROSS}objdump -t $TEMPO | grep measurement | cut -d' ' -f1)
44
NUM=$((0x$LINE - 1))
45
echo "bss index: $NUM"
46
47