blob: e092548e031021dfbcc23a3c6fcb77749df79ed9 [file] [log] [blame]
Roberto Vargase92111a2018-05-22 16:05:42 +01001#!/bin/sh
John Tsichritzisaec19d32019-03-08 16:54:13 +00002# 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
8build=.
9out=output.a
10
11for i
12do
13 case $i in
14 -o)
15 out=$2
16 shift 2
17 ;;
18 -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 ;;
26 --asflags=*)
27 asflags=$(echo $1 | sed 's/--asflags=\(.*\)/\1/')
28 shift 1
29 ;;
Roberto Vargase92111a2018-05-22 16:05:42 +010030 --)
31 shift
32 break
33 ;;
34 -*)
35 echo usage: genwrappers.sh [-o output] [-b dir] file ... >&2
36 exit 1
37 ;;
38 esac
39done
40
John Tsichritzisf6ea99b2019-05-21 15:47:37 +010041awk -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 Vargase92111a2018-05-22 16:05:42 +010048while read idx lib sym
49do
50 file=$build/${lib}_$sym
51
52 cat <<EOF > $file.s
53 .globl $sym
54$sym:
John Tsichritzisf6ea99b2019-05-21 15:47:37 +010055EOF
56if [ $enable_bti = 1 ]
57then
58 echo "\tbti\tjc" >> $file.s
59fi
60 cat <<EOF >> $file.s
Roberto Vargase92111a2018-05-22 16:05:42 +010061 ldr x17, =jmptbl
John Tsichritzisaec19d32019-03-08 16:54:13 +000062 mov x16, #$idx
John Tsichritzisf6ea99b2019-05-21 15:47:37 +010063 ldr x17, [x17]
Roberto Vargase92111a2018-05-22 16:05:42 +010064 add x16, x16, x17
65 br x16
66EOF
67
John Tsichritzisf6ea99b2019-05-21 15:47:37 +010068 ${CROSS_COMPILE}as ${asflags} -o $file.o $file.s
Roberto Vargase92111a2018-05-22 16:05:42 +010069done
70
71${CROSS_COMPILE}ar -rc $out $build/*.o