Re: [PATCH v3 3/5] m68k: add system call table generation support

2018-10-01 Thread Finn Thain
On Mon, 1 Oct 2018, Firoz Khan wrote:

> --- /dev/null
> +++ b/arch/m68k/kernel/syscalls/syscallhdr.sh
> @@ -0,0 +1,35 @@
> +#!/bin/sh

That's not accurate. These are bash scripts, not Bourne shell.

If you run 'checkbashisms', you'll see that a few small changes are needed 
in order to gain standards compliance and portability.

Some untested suggestions:

diff --git a/arch/m68k/kernel/syscalls/syscallhdr.sh 
b/arch/m68k/kernel/syscalls/syscallhdr.sh
index e0e3108cfc7f..9811f82848e6 100644
--- a/arch/m68k/kernel/syscalls/syscallhdr.sh
+++ b/arch/m68k/kernel/syscalls/syscallhdr.sh
@@ -18,17 +18,17 @@ grep -E "^[0-9A-Fa-fXx]+[[:space:]]+${my_abis}" "$in" | 
sort -n | (
 nxt=0
 while read nr abi name entry ; do
if [ -z "$offset" ]; then
-   echo -e "#define __NR_${prefix}${name}\t$nr"
+   echo "#define __NR_${prefix}${name} $nr"
else
-   echo -e "#define __NR_${prefix}${name}\t($offset + $nr)"
+   echo "#define __NR_${prefix}${name} ($offset + $nr)"
fi
nxt=$nr
-   let nxt=nxt+1
+   nxt=$((nxt+1))
 done
 
 echo ""
 echo "#ifdef __KERNEL__"
-echo -e "#define __NR_syscalls\t$nxt"
+echo "#define __NR_syscalls$nxt"
 echo "#endif"
 echo ""
 echo "#endif /* ${fileguard} */"
diff --git a/arch/m68k/kernel/syscalls/syscalltbl.sh 
b/arch/m68k/kernel/syscalls/syscalltbl.sh
index d2635dea4e96..89ab047097ce 100644
--- a/arch/m68k/kernel/syscalls/syscalltbl.sh
+++ b/arch/m68k/kernel/syscalls/syscalltbl.sh
@@ -13,7 +13,7 @@ emit() {
 
 while [ $nxt -lt $nr ]; do
echo "__SYSCALL($nxt, sys_ni_syscall, )"
-   let nxt=nxt+1
+   nxt=$((nxt+1))
 done
 
 echo "__SYSCALL($nr, $entry, )"
@@ -29,6 +29,6 @@ grep '^[0-9]' "$in" | sort -n | (
 while read nr abi name entry ; do
emit $nxt $nr $entry
nxt=$nr
-let nxt=nxt+1
+nxt=$((nxt+1))
 done
 ) > "$out"

-- 


[PATCH v3 3/5] m68k: add system call table generation support

2018-10-01 Thread Firoz Khan
The system call tables are in different format in all
architecture and it will be difficult to manually add or
modify the system calls in the respective files. To make
it easy by keeping a script and which'll generate the
header file and syscall table file so this change will
unify them across all architectures.

The system call table generation script is added in
syscalls directory which contain the script to generate
both uapi header file system call table generation file
and syscall.tbl file which'll be the input for the scripts.

syscall.tbl contains the list of available system calls
along with system call number and corresponding entry point.
Add a new system call in this architecture will be possible
by adding new entry in the syscall.tbl file.

Adding a new table entry consisting of:
- System call number.
- ABI.
- System call name.
- Entry point name.

syscallhdr.sh and syscalltbl.sh will generate uapi header-
unistd.h and syscall_table.h files respectively. File
syscall_table.h is included by syscall_table.S - the real
system call table. Both .sh files will parse the content
syscall.tbl to generate the header and table files.

ARM, s390 and x86 architecuture does have the similar support.
I leverage their implementation to come up with a generic
solution. And this is the ground work for y2038 issue. We need
to change two dozons of system call implementation and this
work will reduce the effort by simply modify two dozon entries
in syscall.tbl.

Signed-off-by: Firoz Khan 
---
 arch/m68k/kernel/syscalls/Makefile  |  38 
 arch/m68k/kernel/syscalls/syscall.tbl   | 369 
 arch/m68k/kernel/syscalls/syscallhdr.sh |  35 +++
 arch/m68k/kernel/syscalls/syscalltbl.sh |  34 +++
 4 files changed, 476 insertions(+)
 create mode 100644 arch/m68k/kernel/syscalls/Makefile
 create mode 100644 arch/m68k/kernel/syscalls/syscall.tbl
 create mode 100644 arch/m68k/kernel/syscalls/syscallhdr.sh
 create mode 100644 arch/m68k/kernel/syscalls/syscalltbl.sh

diff --git a/arch/m68k/kernel/syscalls/Makefile 
b/arch/m68k/kernel/syscalls/Makefile
new file mode 100644
index 000..d255d32
--- /dev/null
+++ b/arch/m68k/kernel/syscalls/Makefile
@@ -0,0 +1,38 @@
+# SPDX-License-Identifier: GPL-2.0
+out := arch/$(SRCARCH)/include/generated/asm
+uapi := arch/$(SRCARCH)/include/generated/uapi/asm
+
+_dummy := $(shell [ -d '$(uapi)' ] || mkdir -p '$(uapi)') \
+ $(shell [ -d '$(out)' ] || mkdir -p '$(out)')
+
+syscall := $(srctree)/$(src)/syscall.tbl
+
+syshdr := $(srctree)/$(src)/syscallhdr.sh
+systbl := $(srctree)/$(src)/syscalltbl.sh
+
+quiet_cmd_syshdr = SYSHDR  $@
+  cmd_syshdr = $(CONFIG_SHELL) '$(syshdr)' '$<' '$@'  \
+  '$(syshdr_abi_$(basetarget))'  \
+  '$(syshdr_pfx_$(basetarget))'  \
+  '$(syshdr_offset_$(basetarget))'
+
+quiet_cmd_systbl = SYSTBL  $@
+  cmd_systbl = $(CONFIG_SHELL) '$(systbl)' '$<' '$@'  \
+  '$(systbl_abi_$(basetarget))'  \
+  '$(systbl_offset_$(basetarget))'
+
+$(uapi)/unistd_32.h: $(syscall) $(syshdr)
+   $(call if_changed,syshdr)
+
+$(out)/syscall_table.h: $(syscall) $(systbl)
+   $(call if_changed,systbl)
+
+uapisyshdr-y   += unistd_32.h
+syshdr-y   += syscall_table.h
+
+targets+= $(uapisyshdr-y) $(syshdr-y)
+
+PHONY += all
+all: $(addprefix $(uapi)/,$(uapisyshdr-y))
+all: $(addprefix $(out)/,$(syshdr-y))
+   @:
diff --git a/arch/m68k/kernel/syscalls/syscall.tbl 
b/arch/m68k/kernel/syscalls/syscall.tbl
new file mode 100644
index 000..ab151cd
--- /dev/null
+++ b/arch/m68k/kernel/syscalls/syscall.tbl
@@ -0,0 +1,369 @@
+#
+# Linux system call numbers and entry vectors
+#
+# The format is:
+#
+#
+# The abi is always common for this file.
+#
+0   common   restart_syscall  sys_restart_syscall
+1   common   exit sys_exit
+2   common   fork __sys_fork
+3   common   read sys_read
+4   common   writesys_write
+5   common   open sys_open
+6   common   closesys_close
+7   common   waitpid  sys_waitpid
+8   common   creatsys_creat
+9   common   link sys_link
+10  common   unlink   sys_unlink
+11  common   execve   sys_execve
+12  common   chdirsys_chdir
+13  common   time sys_time
+14  common   mknodsys_mknod
+15  common   chmodsys_chmod
+16  common   chownsys_chown16
+18  common   oldstat  sys_stat
+19  common   lseeksys_lseek
+20  common   getpid   sys_getpid
+21  common   mountsys_mount
+22