Re: [PATCH v3 1/4] scripts: add a script to generate syscall_nr.h

2020-03-16 Thread Laurent Vivier
Le 16/03/2020 à 20:27, Taylor Simpson a écrit :
> 
> 
>> Le 16/03/2020 à 17:21, Taylor Simpson a écrit :
>>>
>>>
>>>> -Original Message-
>>>> From: Laurent Vivier 
>>>> Sent: Monday, March 16, 2020 3:56 AM
>>>> To: qemu-devel@nongnu.org
>>>> Cc: Laurent Vivier ; Richard Henderson
>>>> ; Riku Voipio ; Taylor
>>>> Simpson ; Alistair Francis
>>>> 
>>>> Subject: [PATCH v3 1/4] scripts: add a script to generate syscall_nr.h
>>>>
>>>> This script is needed for targets based on asm-generic syscall numbers
>>>> generation
>>>>
>>>> +
>>>> +filter_defines()
>>>> +{
>>>> +grep -e "#define __NR_" -e "#define __NR3264"
>>>
>>> For Hexagon, we're still running a 4.9 kernel.  When I tried out this 
>>> script on
>> that code base, there are a handful of these
>>> #undef __NR_syscalls
>>> #define __NR_syscalls 291
>>> This works fine with normal C preprocessing, and the last one wins.
>> However, when the #undef's are filtered out, it lease to build errors from
>> multiple #define's of TARGET_NR_syscalls.  AFAIK, qemu doesn't use this, so
>> it should be OK to filter out.  So, I changed the above line to
>>> grep -e "#define __NR_" -e "#define __NR3264" | grep -v
>> "__NR_syscalls"
>>>
>>> If you're OK incorporating that now, great!  Otherwise, I'll add it to the
>> Hexagon RFC patch series until we get to a newer kernel.
>>
>> Sorry, I've just sent the pull-request.
>>
>> Add it to your RFC, please.
> 
> Sure.
> 
>>
>> It's why this script is only an helper, so it means once the file is
>> generated it can be edited before being committed.
> 
> Oh, I thought the goal was to have them all generated.  That's why I 
> suggested generating the "Do not modify" comment.

The "Do not modify" is a good idea: people will re-run the script
instead of editing directly the file, but then it can be adjusted.

Thanks,
Laurent





RE: [PATCH v3 1/4] scripts: add a script to generate syscall_nr.h

2020-03-16 Thread Taylor Simpson


> Le 16/03/2020 à 17:21, Taylor Simpson a écrit :
> >
> >
> >> -Original Message-
> >> From: Laurent Vivier 
> >> Sent: Monday, March 16, 2020 3:56 AM
> >> To: qemu-devel@nongnu.org
> >> Cc: Laurent Vivier ; Richard Henderson
> >> ; Riku Voipio ; Taylor
> >> Simpson ; Alistair Francis
> >> 
> >> Subject: [PATCH v3 1/4] scripts: add a script to generate syscall_nr.h
> >>
> >> This script is needed for targets based on asm-generic syscall numbers
> >> generation
> >>
> >> +
> >> +filter_defines()
> >> +{
> >> +grep -e "#define __NR_" -e "#define __NR3264"
> >
> > For Hexagon, we're still running a 4.9 kernel.  When I tried out this 
> > script on
> that code base, there are a handful of these
> > #undef __NR_syscalls
> > #define __NR_syscalls 291
> > This works fine with normal C preprocessing, and the last one wins.
> However, when the #undef's are filtered out, it lease to build errors from
> multiple #define's of TARGET_NR_syscalls.  AFAIK, qemu doesn't use this, so
> it should be OK to filter out.  So, I changed the above line to
> > grep -e "#define __NR_" -e "#define __NR3264" | grep -v
> "__NR_syscalls"
> >
> > If you're OK incorporating that now, great!  Otherwise, I'll add it to the
> Hexagon RFC patch series until we get to a newer kernel.
>
> Sorry, I've just sent the pull-request.
>
> Add it to your RFC, please.

Sure.

>
> It's why this script is only an helper, so it means once the file is
> generated it can be edited before being committed.

Oh, I thought the goal was to have them all generated.  That's why I suggested 
generating the "Do not modify" comment.

>
> Thanks,
> Laurent


RE: [PATCH v3 1/4] scripts: add a script to generate syscall_nr.h

2020-03-16 Thread Taylor Simpson



> -Original Message-
> From: Laurent Vivier 
> Sent: Monday, March 16, 2020 3:56 AM
> To: qemu-devel@nongnu.org
> Cc: Laurent Vivier ; Richard Henderson
> ; Riku Voipio ; Taylor
> Simpson ; Alistair Francis
> 
> Subject: [PATCH v3 1/4] scripts: add a script to generate syscall_nr.h
>
> This script is needed for targets based on asm-generic syscall numbers
> generation
>
> +
> +filter_defines()
> +{
> +grep -e "#define __NR_" -e "#define __NR3264"

For Hexagon, we're still running a 4.9 kernel.  When I tried out this script on 
that code base, there are a handful of these
#undef __NR_syscalls
#define __NR_syscalls 291
This works fine with normal C preprocessing, and the last one wins.  However, 
when the #undef's are filtered out, it lease to build errors from multiple 
#define's of TARGET_NR_syscalls.  AFAIK, qemu doesn't use this, so it should be 
OK to filter out.  So, I changed the above line to
grep -e "#define __NR_" -e "#define __NR3264" | grep -v "__NR_syscalls"

If you're OK incorporating that now, great!  Otherwise, I'll add it to the 
Hexagon RFC patch series until we get to a newer kernel.

Thanks,
Taylor


> +}
> +





Re: [PATCH v3 1/4] scripts: add a script to generate syscall_nr.h

2020-03-16 Thread Laurent Vivier
Le 16/03/2020 à 17:21, Taylor Simpson a écrit :
> 
> 
>> -Original Message-
>> From: Laurent Vivier 
>> Sent: Monday, March 16, 2020 3:56 AM
>> To: qemu-devel@nongnu.org
>> Cc: Laurent Vivier ; Richard Henderson
>> ; Riku Voipio ; Taylor
>> Simpson ; Alistair Francis
>> 
>> Subject: [PATCH v3 1/4] scripts: add a script to generate syscall_nr.h
>>
>> This script is needed for targets based on asm-generic syscall numbers
>> generation
>>
>> +
>> +filter_defines()
>> +{
>> +grep -e "#define __NR_" -e "#define __NR3264"
> 
> For Hexagon, we're still running a 4.9 kernel.  When I tried out this script 
> on that code base, there are a handful of these
> #undef __NR_syscalls
> #define __NR_syscalls 291
> This works fine with normal C preprocessing, and the last one wins.  However, 
> when the #undef's are filtered out, it lease to build errors from multiple 
> #define's of TARGET_NR_syscalls.  AFAIK, qemu doesn't use this, so it should 
> be OK to filter out.  So, I changed the above line to
> grep -e "#define __NR_" -e "#define __NR3264" | grep -v "__NR_syscalls"
> 
> If you're OK incorporating that now, great!  Otherwise, I'll add it to the 
> Hexagon RFC patch series until we get to a newer kernel.

Sorry, I've just sent the pull-request.

Add it to your RFC, please.

It's why this script is only an helper, so it means once the file is
generated it can be edited before being committed.

Thanks,
Laurent



[PATCH v3 1/4] scripts: add a script to generate syscall_nr.h

2020-03-16 Thread Laurent Vivier
This script is needed for targets based on asm-generic syscall numbers 
generation

Signed-off-by: Laurent Vivier 
Reviewed-by: Alistair Francis 
Reviewed-by: Taylor Simpson 
Reviewed-by: Richard Henderson 
---

Notes:
v3: remove useless upper command
v2: add comments suggested by Taylor

 scripts/gensyscalls.sh | 102 +
 1 file changed, 102 insertions(+)
 create mode 100755 scripts/gensyscalls.sh

diff --git a/scripts/gensyscalls.sh b/scripts/gensyscalls.sh
new file mode 100755
index ..b7b8456f6312
--- /dev/null
+++ b/scripts/gensyscalls.sh
@@ -0,0 +1,102 @@
+#!/bin/sh
+#
+# Update syscall_nr.h files from linux headers asm-generic/unistd.h
+#
+# This code is licensed under the GPL version 2 or later.  See
+# the COPYING file in the top-level directory.
+#
+
+linux="$1"
+output="$2"
+
+TMP=$(mktemp -d)
+
+if [ "$linux" = "" ] ; then
+echo "Needs path to linux source tree" 1>&2
+exit 1
+fi
+
+if [ "$output" = "" ] ; then
+output="$PWD"
+fi
+
+upper()
+{
+echo "$1" | tr "[:lower:]" "[:upper:]" | tr "[:punct:]" "_"
+}
+
+qemu_arch()
+{
+case "$1" in
+arm64)
+echo "aarch64"
+;;
+*)
+echo "$1"
+;;
+esac
+}
+
+read_includes()
+{
+arch=$1
+bits=$2
+
+ cpp -P -nostdinc -fdirectives-only \
+-D_UAPI_ASM_$(upper ${arch})_BITSPERLONG_H \
+-D__BITS_PER_LONG=${bits} \
+-I${linux}/arch/${arch}/include/uapi/ \
+-I${linux}/include/uapi \
+-I${TMP} \
+"${linux}/arch/${arch}/include/uapi/asm/unistd.h"
+}
+
+filter_defines()
+{
+grep -e "#define __NR_" -e "#define __NR3264"
+}
+
+rename_defines()
+{
+sed "s/ __NR_/ TARGET_NR_/g;s/(__NR_/(TARGET_NR_/g"
+}
+
+evaluate_values()
+{
+sed "s/#define TARGET_NR_/QEMU TARGET_NR_/" | \
+cpp -P -nostdinc | \
+sed "s/^QEMU /#define /"
+}
+
+generate_syscall_nr()
+{
+arch=$1
+bits=$2
+file="$3"
+guard="$(upper LINUX_USER_$(qemu_arch $arch)_$(basename "$file"))"
+
+(echo "/*"
+echo " * This file contains the system call numbers."
+echo " * Do not modify."
+echo " * This file is generated by scripts/gensyscalls.sh"
+echo " */"
+echo "#ifndef ${guard}"
+echo "#define ${guard}"
+echo
+read_includes $arch $bits | filter_defines | rename_defines | \
+evaluate_values | sort -n -k 3
+echo
+echo "#endif /* ${guard} */"
+echo) > "$file"
+}
+
+mkdir "$TMP/asm"
+> "$TMP/asm/bitsperlong.h"
+
+generate_syscall_nr arm64 64 "$output/linux-user/aarch64/syscall_nr.h"
+generate_syscall_nr nios2 32 "$output/linux-user/nios2/syscall_nr.h"
+generate_syscall_nr openrisc 32 "$output/linux-user/openrisc/syscall_nr.h"
+
+generate_syscall_nr riscv 32 "$output/linux-user/riscv/syscall32_nr.h"
+generate_syscall_nr riscv 64 "$output/linux-user/riscv/syscall64_nr.h"
+rm -fr "$TMP"
-- 
2.24.1