Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 1 | #!/bin/sh |
John Tsichritzis | f6ea99b | 2019-05-21 15:47:37 +0100 | [diff] [blame] | 2 | # Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved. |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | |
| 6 | set -e |
| 7 | |
| 8 | output=jmptbl.s |
Sathees Balya | d6839ef | 2018-10-31 14:05:08 +0000 | [diff] [blame] | 9 | build=. |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 10 | |
| 11 | for i |
| 12 | do |
| 13 | case $i in |
| 14 | -o) |
| 15 | output=$2 |
| 16 | shift 2 |
| 17 | ;; |
Sathees Balya | d6839ef | 2018-10-31 14:05:08 +0000 | [diff] [blame] | 18 | -b) |
| 19 | build=$2 |
| 20 | shift 2 |
| 21 | ;; |
John Tsichritzis | f6ea99b | 2019-05-21 15:47:37 +0100 | [diff] [blame] | 22 | --bti=*) |
| 23 | enable_bti=$(echo $1 | sed 's/--bti=\(.*\)/\1/') |
| 24 | shift 1 |
| 25 | ;; |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 26 | --) |
| 27 | shift |
| 28 | break |
| 29 | ;; |
| 30 | -*) |
Sathees Balya | d6839ef | 2018-10-31 14:05:08 +0000 | [diff] [blame] | 31 | echo usage: gentbl.sh [-o output] [-b dir] file ... >&2 |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 32 | exit 1 |
| 33 | ;; |
| 34 | esac |
| 35 | done |
| 36 | |
| 37 | tmp=`mktemp` |
Sathees Balya | d6839ef | 2018-10-31 14:05:08 +0000 | [diff] [blame] | 38 | trap "rm -f $$.tmp" EXIT INT QUIT |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 39 | rm -f $output |
| 40 | |
Sathees Balya | d6839ef | 2018-10-31 14:05:08 +0000 | [diff] [blame] | 41 | # Pre-process include files |
| 42 | awk '!/^$/ && !/[:blank:]*#.*/{ |
| 43 | if (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 | }' "$@" | |
| 51 | awk -v OFS="\t" ' |
| 52 | BEGIN{print "#index\tlib\tfunction\t[patch]"} |
| 53 | {print NR-1, $0}' | tee $build/jmptbl.i | |
John Tsichritzis | f6ea99b | 2019-05-21 15:47:37 +0100 | [diff] [blame] | 54 | awk -v OFS="\n" -v BTI=$enable_bti ' |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 55 | BEGIN {print "\t.text", |
| 56 | "\t.globl\tjmptbl", |
| 57 | "jmptbl:"} |
| 58 | {sub(/[:blank:]*#.*/,"")} |
John Tsichritzis | f6ea99b | 2019-05-21 15:47:37 +0100 | [diff] [blame] | 59 | !/^$/ { |
| 60 | if (BTI == 1) |
| 61 | print "\tbti\tj" |
| 62 | if ($3 == "reserved") |
Sathees Balya | d6839ef | 2018-10-31 14:05:08 +0000 | [diff] [blame] | 63 | print "\t.word\t0x0" |
| 64 | else |
| 65 | print "\tb\t" $3}' > $$.tmp && |
| 66 | mv $$.tmp $output |