blob: bfb1ec3cf3741ccc0f6b0b322090a3fefa89b0e6 [file] [log] [blame]
Roberto Vargase92111a2018-05-22 16:05:42 +01001#!/bin/sh
John Tsichritzisf6ea99b2019-05-21 15:47:37 +01002# Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
Roberto Vargase92111a2018-05-22 16:05:42 +01003#
4# SPDX-License-Identifier: BSD-3-Clause
5
6set -e
7
8output=jmptbl.s
Sathees Balyad6839ef2018-10-31 14:05:08 +00009build=.
Roberto Vargase92111a2018-05-22 16:05:42 +010010
11for i
12do
13 case $i in
14 -o)
15 output=$2
16 shift 2
17 ;;
Sathees Balyad6839ef2018-10-31 14:05:08 +000018 -b)
19 build=$2
20 shift 2
21 ;;
John Tsichritzisf6ea99b2019-05-21 15:47:37 +010022 --bti=*)
23 enable_bti=$(echo $1 | sed 's/--bti=\(.*\)/\1/')
24 shift 1
25 ;;
Roberto Vargase92111a2018-05-22 16:05:42 +010026 --)
27 shift
28 break
29 ;;
30 -*)
Sathees Balyad6839ef2018-10-31 14:05:08 +000031 echo usage: gentbl.sh [-o output] [-b dir] file ... >&2
Roberto Vargase92111a2018-05-22 16:05:42 +010032 exit 1
33 ;;
34 esac
35done
36
37tmp=`mktemp`
Sathees Balyad6839ef2018-10-31 14:05:08 +000038trap "rm -f $$.tmp" EXIT INT QUIT
Roberto Vargase92111a2018-05-22 16:05:42 +010039rm -f $output
40
Sathees Balyad6839ef2018-10-31 14:05:08 +000041# Pre-process include files
42awk '!/^$/ && !/[:blank:]*#.*/{
43if (NF == 2 && $1 == "include") {
44 while ((getline line < $2) > 0)
45 if (line !~ /^$/ && line !~ /[:blank:]*#.*/)
46 print line
47 close($2)
48} else
49 print
50}' "$@" |
51awk -v OFS="\t" '
52BEGIN{print "#index\tlib\tfunction\t[patch]"}
53{print NR-1, $0}' | tee $build/jmptbl.i |
John Tsichritzisf6ea99b2019-05-21 15:47:37 +010054awk -v OFS="\n" -v BTI=$enable_bti '
Roberto Vargase92111a2018-05-22 16:05:42 +010055BEGIN {print "\t.text",
56 "\t.globl\tjmptbl",
57 "jmptbl:"}
58 {sub(/[:blank:]*#.*/,"")}
John Tsichritzisf6ea99b2019-05-21 15:47:37 +010059!/^$/ {
60 if (BTI == 1)
61 print "\tbti\tj"
62 if ($3 == "reserved")
Sathees Balyad6839ef2018-10-31 14:05:08 +000063 print "\t.word\t0x0"
64 else
65 print "\tb\t" $3}' > $$.tmp &&
66mv $$.tmp $output