Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 1 | #!/bin/sh |
John Tsichritzis | aec19d3 | 2019-03-08 16:54:13 +0000 | [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 | build=. |
| 9 | out=output.a |
| 10 | |
| 11 | for i |
| 12 | do |
| 13 | case $i in |
| 14 | -o) |
| 15 | out=$2 |
| 16 | shift 2 |
| 17 | ;; |
| 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 | ;; |
| 26 | --asflags=*) |
| 27 | asflags=$(echo $1 | sed 's/--asflags=\(.*\)/\1/') |
| 28 | shift 1 |
| 29 | ;; |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 30 | --) |
| 31 | shift |
| 32 | break |
| 33 | ;; |
| 34 | -*) |
| 35 | echo usage: genwrappers.sh [-o output] [-b dir] file ... >&2 |
| 36 | exit 1 |
| 37 | ;; |
| 38 | esac |
| 39 | done |
| 40 | |
John Tsichritzis | f6ea99b | 2019-05-21 15:47:37 +0100 | [diff] [blame] | 41 | awk -v BTI=$enable_bti ' |
| 42 | {sub(/[:blank:]*#.*/,"")} |
| 43 | !/^$/ && $NF != "patch" && $NF != "reserved" { |
| 44 | if (BTI == 1) |
| 45 | print $1*8, $2, $3 |
| 46 | else |
| 47 | print $1*4, $2, $3}' "$@" | |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 48 | while read idx lib sym |
| 49 | do |
| 50 | file=$build/${lib}_$sym |
| 51 | |
| 52 | cat <<EOF > $file.s |
| 53 | .globl $sym |
| 54 | $sym: |
John Tsichritzis | f6ea99b | 2019-05-21 15:47:37 +0100 | [diff] [blame] | 55 | EOF |
| 56 | if [ $enable_bti = 1 ] |
| 57 | then |
| 58 | echo "\tbti\tjc" >> $file.s |
| 59 | fi |
| 60 | cat <<EOF >> $file.s |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 61 | ldr x17, =jmptbl |
John Tsichritzis | aec19d3 | 2019-03-08 16:54:13 +0000 | [diff] [blame] | 62 | mov x16, #$idx |
John Tsichritzis | f6ea99b | 2019-05-21 15:47:37 +0100 | [diff] [blame] | 63 | ldr x17, [x17] |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 64 | add x16, x16, x17 |
| 65 | br x16 |
| 66 | EOF |
| 67 | |
John Tsichritzis | f6ea99b | 2019-05-21 15:47:37 +0100 | [diff] [blame] | 68 | ${CROSS_COMPILE}as ${asflags} -o $file.o $file.s |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 69 | done |
| 70 | |
| 71 | ${CROSS_COMPILE}ar -rc $out $build/*.o |