Merge tag 'ntb-5.11' of git://github.com/jonmason/ntb
[linux/fpc-iii.git] / tools / perf / trace / beauty / arch_errno_names.sh
blob9f9ea45cddc4384c3b69af2248a1302b5ac50fde
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0
4 # Generate C file mapping errno codes to errno names.
6 # Copyright IBM Corp. 2018
7 # Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
9 gcc="$1"
10 toolsdir="$2"
11 include_path="-I$toolsdir/include/uapi"
13 arch_string()
15 echo "$1" |sed -e 'y/- /__/' |tr '[[:upper:]]' '[[:lower:]]'
18 asm_errno_file()
20 local arch="$1"
21 local header
23 header="$toolsdir/arch/$arch/include/uapi/asm/errno.h"
24 if test -r "$header"; then
25 echo "$header"
26 else
27 echo "$toolsdir/include/uapi/asm-generic/errno.h"
31 create_errno_lookup_func()
33 local arch=$(arch_string "$1")
34 local nr name
36 cat <<EoFuncBegin
37 static const char *errno_to_name__$arch(int err)
39 switch (err) {
40 EoFuncBegin
42 while read name nr; do
43 printf '\tcase %d: return "%s";\n' $nr $name
44 done
46 cat <<EoFuncEnd
47 default:
48 return "(unknown)";
52 EoFuncEnd
55 process_arch()
57 local arch="$1"
58 local asm_errno=$(asm_errno_file "$arch")
60 $gcc $CFLAGS $include_path -E -dM -x c $asm_errno \
61 |grep -hE '^#define[[:blank:]]+(E[^[:blank:]]+)[[:blank:]]+([[:digit:]]+).*' \
62 |awk '{ print $2","$3; }' \
63 |sort -t, -k2 -nu \
64 |IFS=, create_errno_lookup_func "$arch"
67 create_arch_errno_table_func()
69 local archlist="$1"
70 local default="$2"
71 local arch
73 printf 'const char *arch_syscalls__strerrno(const char *arch, int err)\n'
74 printf '{\n'
75 for arch in $archlist; do
76 printf '\tif (!strcmp(arch, "%s"))\n' $(arch_string "$arch")
77 printf '\t\treturn errno_to_name__%s(err);\n' $(arch_string "$arch")
78 done
79 printf '\treturn errno_to_name__%s(err);\n' $(arch_string "$default")
80 printf '}\n'
83 cat <<EoHEADER
84 /* SPDX-License-Identifier: GPL-2.0 */
86 #include <string.h>
88 EoHEADER
90 # Create list of architectures and ignore those that do not appear
91 # in tools/perf/arch
92 archlist=""
93 for arch in $(find $toolsdir/arch -maxdepth 1 -mindepth 1 -type d -printf "%f\n" | grep -v x86 | sort); do
94 test -d $toolsdir/perf/arch/$arch && archlist="$archlist $arch"
95 done
97 for arch in x86 $archlist generic; do
98 process_arch "$arch"
99 done
100 create_arch_errno_table_func "x86 $archlist" "generic"