Add translations for various sub-directories
[binutils-gdb.git] / gdb / syscalls / update-linux-from-src.sh
blob35d78995eaa1085fed5fe245446a2844989c3736
1 #!/bin/bash
3 # Copyright (C) 2022-2024 Free Software Foundation, Inc.
5 # This file is part of GDB.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # Used to generate .xml.in files, like so:
21 # $ ./update-linux-from-src.sh ~/linux-stable.git
23 pwd=$(pwd -P)
25 parse_args ()
27 if [ $# -lt 1 ]; then
28 echo "dir argument needed"
29 exit 1
32 d="$1"
33 shift
35 if [ ! -d "$d" ]; then
36 echo "cannot find $d"
37 exit 1
41 gen_from_kernel_headers ()
43 local f
44 f="$1"
45 local arch
46 arch="$2"
48 echo "Generating $f"
50 local tmpdir
51 tmpdir=$(mktemp -d)
52 trap 'rm -Rf $tmpdir/*' EXIT
54 local build
55 build="$tmpdir"/build
56 local install
57 install="$tmpdir"/install
58 local usr
59 usr="$install"/usr
60 local include
61 include="$usr"/include
63 mkdir -p "$build" "$usr"
66 cd "$build" || exit 1
68 make \
69 -f "$d"/Makefile \
70 ARCH="$arch" \
71 INSTALL_HDR_PATH="$usr" \
72 headers_install \
73 > "$build"/header_install.log \
74 2>&1
76 "$pwd"/update-linux.sh \
77 "$pwd"/"$f" \
78 -nostdinc \
79 -isystem "$include"
82 trap '' EXIT
83 rm -Rf "$tmpdir"
86 pre ()
88 local f
89 f="$1"
90 local start_date
91 start_date="$2"
92 local h
93 h="$3"
95 local prefix
96 prefix=" "
98 if [ "$h" != "" ]; then
99 file_files="files"
100 belong_belongs="belong"
101 files=$(echo -e "$prefix$f\n$prefix$h")
102 else
103 file_files="file"
104 belong_belongs="belongs"
105 files="$prefix$f"
108 local year
109 year=$(date +%Y)
111 cat <<EOF
112 <?xml version="1.0"?>
113 <!-- Copyright (C) $start_date-$year Free Software Foundation, Inc.
115 Copying and distribution of this file, with or without modification,
116 are permitted in any medium without royalty provided the copyright
117 notice and this notice are preserved. -->
119 <!DOCTYPE feature SYSTEM "gdb-syscalls.dtd">
121 <!-- This file was generated using the following $file_files:
123 $files
125 The $file_files mentioned above $belong_belongs to the Linux Kernel. -->
130 echo '<syscalls_info>'
134 post ()
136 echo '</syscalls_info>'
139 one ()
141 local f
142 f="$1"
143 local select_abis
144 select_abis="$2"
145 local start_date
146 start_date="$3"
147 local offset
148 offset="$4"
149 local h
150 h="$5"
152 tmp=$(mktemp)
153 trap 'rm -f $tmp' EXIT
155 pre "$f" "$start_date" "$h"
157 # Print out num, abi, name.
158 grep -v "^#" "$d/$f" \
159 | awk '{print $1, $2, $3}' \
160 > "$tmp"
162 local decimal
163 decimal="[0-9][0-9]*"
164 # Print out num, "removed", name.
165 grep -E "^# $decimal was sys_*" "$d/$f" \
166 | awk '{print $2, "removed", gensub("^sys_", "", 1, $4)}' \
167 >> "$tmp"
169 case $h in
170 arch/arm/include/uapi/asm/unistd.h)
171 grep '#define __ARM_NR_[a-z].*__ARM_NR_BASE\+' "$d/$h" \
172 | sed 's/#define //;s/__ARM_NR_BASE+//;s/[()]//g;s/__ARM_NR_/ARM_/' \
173 | awk '{print $2 + 0x0f0000, "private", $1}' \
174 >> "$tmp"
176 esac
178 local nums
179 declare -a nums
180 local abis
181 declare -a abis
182 local names
183 declare -a names
184 local name_exists
185 declare -A name_exists
187 local i
189 local _num
190 local _abi
191 local _name
192 while read -r -a line; do
193 _num="${line[0]}"
194 _abi="${line[1]}"
195 _name="${line[2]}"
197 local found
198 found=false
199 for a in $select_abis; do
200 if [ "$a" = "$_abi" ]; then
201 found=true
202 break
204 done
205 if ! $found; then
206 continue
209 if [ "${_name/reserved+([0-9])/}" = "" ]; then
210 continue
213 if [ "${_name/unused+([0-9])/}" = "" ]; then
214 continue
217 nums[i]="$_num"
218 abis[i]="$_abi"
219 names[i]="$_name"
221 if [ "$_abi" != "removed" ]; then
222 name_exists[$_name]=1
225 i=$((i + 1))
226 done < <(sort -V "$tmp")
228 local n
229 n=$i
231 for ((i = 0 ; i < n ; i++)); do
232 _name=${names[$i]}
233 _abi=${abis[$i]}
234 _num=$((${nums[$i]} + offset))
236 if [ "$_abi" = "removed" ] && [ "${name_exists[$_name]}" = 1 ]; then
237 _name=old$_name
240 echo -n " <syscall name=\"$_name\" number=\"$_num\"/>"
242 if [ "$_abi" = "removed" ]; then
243 echo " <!-- removed -->"
244 else
245 echo
247 done
249 post
252 regen ()
254 local f
255 f="$1"
257 local start_date
258 start_date=2009
259 local offset
260 offset=0
261 local h
264 local t
265 local abi
266 case $f in
267 amd64-linux.xml.in)
268 t="arch/x86/entry/syscalls/syscall_64.tbl"
269 abi="common 64"
271 i386-linux.xml.in)
272 t="arch/x86/entry/syscalls/syscall_32.tbl"
273 abi=i386
275 ppc64-linux.xml.in)
276 t="arch/powerpc/kernel/syscalls/syscall.tbl"
277 abi="common 64 nospu"
279 ppc-linux.xml.in)
280 t="arch/powerpc/kernel/syscalls/syscall.tbl"
281 abi="common 32 nospu"
283 s390-linux.xml.in)
284 t="arch/s390/kernel/syscalls/syscall.tbl"
285 abi="common 32"
287 s390x-linux.xml.in)
288 t="arch/s390/kernel/syscalls/syscall.tbl"
289 abi="common 64"
291 sparc64-linux.xml.in)
292 t="arch/sparc/kernel/syscalls/syscall.tbl"
293 abi="common 64"
294 start_date="2010"
296 sparc-linux.xml.in)
297 t="arch/sparc/kernel/syscalls/syscall.tbl"
298 abi="common 32"
299 start_date="2010"
301 mips-n32-linux.xml.in)
302 t="arch/mips/kernel/syscalls/syscall_n32.tbl"
303 abi="n32"
304 start_date="2011"
305 offset=6000
307 mips-n64-linux.xml.in)
308 t="arch/mips/kernel/syscalls/syscall_n64.tbl"
309 abi="n64"
310 start_date="2011"
311 offset=5000
313 mips-o32-linux.xml.in)
314 t="arch/mips/kernel/syscalls/syscall_o32.tbl"
315 abi="o32"
316 start_date="2011"
317 offset=4000
319 bfin-linux.xml.in)
320 echo "Skipping $f, no longer supported"
321 return
323 aarch64-linux.xml.in)
324 # No syscall.tbl.
325 gen_from_kernel_headers "$f" arm64
326 return
328 arm-linux.xml.in)
329 t="arch/arm/tools/syscall.tbl"
330 h="arch/arm/include/uapi/asm/unistd.h"
331 abi="common eabi oabi removed private"
333 loongarch-linux.xml.in)
334 echo "Skipping $f, no syscall.tbl"
335 return
337 linux-defaults.xml.in)
338 return
341 echo "Don't know how to generate $f"
342 return
344 esac
346 echo "Generating $f"
347 one "$t" "$abi" "$start_date" "$offset" "$h" > "$f"
350 main ()
352 shopt -s extglob
354 # Set global d.
355 parse_args "$@"
357 local f
358 for f in *.xml.in; do
359 regen "$f"
360 done
363 main "$@"