2018-05-22 16:05:42 +01:00
|
|
|
#!/bin/sh
|
2019-05-21 15:47:37 +01:00
|
|
|
# Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
|
2018-05-22 16:05:42 +01:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
output=jmptbl.s
|
2018-10-31 14:05:08 +00:00
|
|
|
build=.
|
2018-05-22 16:05:42 +01:00
|
|
|
|
|
|
|
for i
|
|
|
|
do
|
|
|
|
case $i in
|
|
|
|
-o)
|
|
|
|
output=$2
|
|
|
|
shift 2
|
|
|
|
;;
|
2018-10-31 14:05:08 +00:00
|
|
|
-b)
|
|
|
|
build=$2
|
|
|
|
shift 2
|
|
|
|
;;
|
2019-05-21 15:47:37 +01:00
|
|
|
--bti=*)
|
|
|
|
enable_bti=$(echo $1 | sed 's/--bti=\(.*\)/\1/')
|
|
|
|
shift 1
|
|
|
|
;;
|
2018-05-22 16:05:42 +01:00
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
-*)
|
2018-10-31 14:05:08 +00:00
|
|
|
echo usage: gentbl.sh [-o output] [-b dir] file ... >&2
|
2018-05-22 16:05:42 +01:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
tmp=`mktemp`
|
2018-10-31 14:05:08 +00:00
|
|
|
trap "rm -f $$.tmp" EXIT INT QUIT
|
2018-05-22 16:05:42 +01:00
|
|
|
rm -f $output
|
|
|
|
|
2018-10-31 14:05:08 +00:00
|
|
|
# Pre-process include files
|
|
|
|
awk '!/^$/ && !/[:blank:]*#.*/{
|
|
|
|
if (NF == 2 && $1 == "include") {
|
|
|
|
while ((getline line < $2) > 0)
|
|
|
|
if (line !~ /^$/ && line !~ /[:blank:]*#.*/)
|
|
|
|
print line
|
|
|
|
close($2)
|
|
|
|
} else
|
|
|
|
print
|
|
|
|
}' "$@" |
|
|
|
|
awk -v OFS="\t" '
|
|
|
|
BEGIN{print "#index\tlib\tfunction\t[patch]"}
|
|
|
|
{print NR-1, $0}' | tee $build/jmptbl.i |
|
2019-05-21 15:47:37 +01:00
|
|
|
awk -v OFS="\n" -v BTI=$enable_bti '
|
2018-05-22 16:05:42 +01:00
|
|
|
BEGIN {print "\t.text",
|
|
|
|
"\t.globl\tjmptbl",
|
|
|
|
"jmptbl:"}
|
|
|
|
{sub(/[:blank:]*#.*/,"")}
|
2019-05-21 15:47:37 +01:00
|
|
|
!/^$/ {
|
|
|
|
if (BTI == 1)
|
|
|
|
print "\tbti\tj"
|
|
|
|
if ($3 == "reserved")
|
2018-10-31 14:05:08 +00:00
|
|
|
print "\t.word\t0x0"
|
|
|
|
else
|
|
|
|
print "\tb\t" $3}' > $$.tmp &&
|
|
|
|
mv $$.tmp $output
|