Since arch_definitions.h contains full description about architectures, arch_includes.h and arch_personalities.h can be generated.
* tools/asinfo/gen_asinfo_files.sh: New file. * bootstrap: Add it. * tools/asinfo/arch_includes.h: Delete it. * tools/asinfo/arch_personalities.h: Likewise. * tools/asinfo/Makefile.am: Include Makemodule.am. (asinfo_SOURCES): Add $(ARCH_AUX_FILES). Signed-off-by: Edgar Kaziakhmedov <edgar.kaziakhme...@virtuozzo.com> --- bootstrap | 1 + tools/asinfo/Makefile.am | 6 +- tools/asinfo/arch_includes.h | 272 -------------------------------------- tools/asinfo/arch_personalities.h | 36 ----- tools/asinfo/gen_asinfo_files.sh | 215 ++++++++++++++++++++++++++++++ 5 files changed, 220 insertions(+), 310 deletions(-) delete mode 100644 tools/asinfo/arch_includes.h delete mode 100644 tools/asinfo/arch_personalities.h create mode 100755 tools/asinfo/gen_asinfo_files.sh diff --git a/bootstrap b/bootstrap index a9cadf53..da06de3b 100755 --- a/bootstrap +++ b/bootstrap @@ -4,6 +4,7 @@ ./xlat/gen.sh ./tests/gen_pure_executables.sh ./tests/gen_tests.sh +./tools/asinfo/gen_asinfo_files.sh for m in m32 mx32; do tests=tests-$m diff --git a/tools/asinfo/Makefile.am b/tools/asinfo/Makefile.am index 94175140..a361ea46 100644 --- a/tools/asinfo/Makefile.am +++ b/tools/asinfo/Makefile.am @@ -38,15 +38,17 @@ AM_CPPFLAGS = -I$(builddir) \ -I$(top_srcdir)/$(OS) \ -I$(top_builddir) \ -I$(top_srcdir) + +include Makemodule.am + asinfo_CPPFLAGS = $(AM_CPPFLAGS) asinfo_CFLAGS = $(AM_CFLAGS) asinfo_SOURCES = \ arch_definitions.h \ - arch_includes.h \ arch_interface.c \ + $(ARCH_AUX_FILES) \ arch_interface.h \ - arch_personalities.h \ asinfo.c \ ../../basic_filters.c \ dispatchers.c \ diff --git a/tools/asinfo/arch_includes.h b/tools/asinfo/arch_includes.h deleted file mode 100644 index e73a8328..00000000 --- a/tools/asinfo/arch_includes.h +++ /dev/null @@ -1,272 +0,0 @@ -/* ARCH_blackfin */ -static const struct_sysent blackfin_32bit_sysent[] = { - #include "bfin/syscallent.h" -}; -static const int blackfin_32bit_usr1 = 0; -const int blackfin_32bit_usr2 = 0; -/* ARCH_ia64 */ -struct_sysent ia64_64bit_sysent[] = { - #include "ia64/syscallent.h" -}; -static const int ia64_64bit_usr1 = 0; -static const int ia64_64bit_usr2 = 0; -#undef SYS_socket_subcall -/* ARCH_m68k */ -static const struct_sysent m68k_32bit_sysent[] = { - #include "m68k/syscallent.h" -}; -static const int m68k_32bit_usr1 = 0; -static const int m68k_32bit_usr2 = 0; -/* ARCH_sparc64 64bit ABI */ -static const struct_sysent sparc64_64bit_sysent[] = { - #include "sparc64/syscallent.h" -}; -static const int sparc64_64bit_usr1 = 0; -static const int sparc64_64bit_usr2 = 0; -/* ARCH_sparc and 32bit ABI */ -static const struct_sysent sparc_32bit_sysent[] = { - #include "sparc/syscallent.h" -}; -static const int sparc_32bit_usr1 = 0; -static const int sparc_32bit_usr2 = 0; -#undef SYS_socket_subcall -/* ARCH_metag */ -static const struct_sysent metag_32bit_sysent[] = { - #include "metag/syscallent.h" -}; -static const int metag_32bit_usr1 = 0; -static const int metag_32bit_usr2 = 0; -/* ARCH_mips n64 ABI */ -#ifndef LINUX_MIPSN64 -# define LINUX_MIPSN64 1 -# define NOW_DEFINED 1 -#endif -static const struct_sysent mips64_n64_sysent[] = { - #include "dummy.h" - #include "mips/syscallent-compat.h" - #include "mips/syscallent-n64.h" -}; -#ifdef NOW_DEFINED -# undef LINUX_MIPSN32 -# undef NOW_DEFINED -#endif -static const int mips64_n64_usr1 = 0; -static const int mips64_n64_usr2 = 0; -#undef SYS_socket_subcall -/* ARCH_mips n32 ABI */ -#ifndef LINUX_MIPSN32 -# define LINUX_MIPSN32 1 -# define NOW_DEFINED 1 -#endif -static const struct_sysent mips64_n32_sysent[] = { - #include "dummy.h" - #include "mips/syscallent-compat.h" - #include "mips/syscallent-n32.h" -}; -#ifdef NOW_DEFINED -# undef LINUX_MIPSN32 -# undef NOW_DEFINED -#endif -static const int mips64_n32_usr1 = 0; -static const int mips64_n32_usr2 = 0; -#undef SYS_socket_subcall -/* ARCH_mips o32 ABI */ -#ifndef LINUX_MIPSO32 -# define LINUX_MIPSO32 1 -# define NOW_DEFINED 1 -#endif -static const struct_sysent mips_o32_sysent[] = { - #include "dummy.h" - #include "mips/syscallent-compat.h" - #include "mips/syscallent-o32.h" -}; -#ifdef NOW_DEFINED -# undef LINUX_MIPSO32 -# undef NOW_DEFINED -#endif -static const int mips_o32_usr1 = 0; -static const int mips_o32_usr2 = 0; -#undef SYS_socket_subcall -/* ARCH_alpha */ -static const struct_sysent alpha_64bit_sysent[] = { - #include "alpha/syscallent.h" -}; -static const int alpha_64bit_usr1 = 0; -static const int alpha_64bit_usr2 = 0; -/* ARCH_ppc64 64bit ABI */ -static const struct_sysent ppc64_64bit_sysent[] = { - #include "powerpc64/syscallent.h" -}; -static const int ppc64_64bit_usr1 = 0; -static const int ppc64_64bit_usr2 = 0; -#undef SYS_socket_subcall -/* ARCH_ppc and 32bit */ -static const struct_sysent ppc_32bit_sysent[] = { - #include "powerpc/syscallent.h" -}; -static const int ppc_32bit_usr1 = 0; -static const int ppc_32bit_usr2 = 0; -#undef SYS_socket_subcall -/* ARCH_aarch64 64bit ABI */ -static const struct_sysent aarch64_64bit_sysent[] = { - #include "aarch64/syscallent.h" -}; -static const int aarch64_64bit_usr1 = 0; -static const int aarch64_64bit_usr2 = 0; -/* ARCH_arm OABI*/ -#ifdef __ARM_EABI__ -# undef __ARM_EABI__ -# define NOW_UNDEFINED 1 -#endif -static const struct_sysent arm_oabi_sysent[] = { - #include "arm/syscallent.h" -}; -static const int arm_oabi_usr1 = ARM_FIRST_SHUFFLED_SYSCALL; -static const int arm_oabi_usr2 = ARM_LAST_SPECIAL_SYSCALL; -#undef ARM_FIRST_SHUFFLED_SYSCALL -#undef ARM_LAST_SPECIAL_SYSCALL -#undef SYS_socket_subcall -#ifdef NOW_UNDEFINED -# define __ARM_EABI__ 1 -# undef NOW_UNDEFINED -#endif -/* ARCH_arm EABI*/ -#ifndef __ARM_EABI__ -# define __ARM_EABI__ 1 -# define NOW_DEFINED 1 -#endif -static const struct_sysent arm_eabi_sysent[] = { - #include "arm/syscallent.h" -}; -static const int arm_eabi_usr1 = ARM_FIRST_SHUFFLED_SYSCALL; -static const int arm_eabi_usr2 = ARM_LAST_SPECIAL_SYSCALL; -#undef ARM_FIRST_SHUFFLED_SYSCALL -#undef ARM_LAST_SPECIAL_SYSCALL -#ifdef NOW_DEFINED -# undef __ARM_EABI__ -# undef NOW_DEFINED -#endif -/* ARCH_avr32 */ -static const struct_sysent avr32_32bit_sysent[] = { - #include "avr32/syscallent.h" -}; -static const int avr32_32bit_usr1 = 0; -static const int avr32_32bit_usr2 = 0; -/* ARCH_arc */ -static const struct_sysent arc_32bit_sysent[] = { - #include "arc/syscallent.h" -}; -static const int arc_32bit_usr1 = 0; -static const int arc_32bit_usr2 = 0; -/* ARCH_s390x */ -static const struct_sysent s390x_64bit_sysent[] = { - #include "s390x/syscallent.h" -}; -static const int s390x_64bit_usr1 = 0; -static const int s390x_64bit_usr2 = 0; -#undef SYS_socket_subcall -/* ARCH_s390 */ -static const struct_sysent s390_32bit_sysent[] = { - #include "s390/syscallent.h" -}; -static const int s390_32bit_usr1 = 0; -static const int s390_32bit_usr2 = 0; -#undef SYS_socket_subcall -/* ARCH_hppa */ -static const struct_sysent hppa_32bit_sysent[] = { - #include "hppa/syscallent.h" -}; -static const int hppa_32bit_usr1 = 0; -static const int hppa_32bit_usr2 = 0; -/* ARCH_sh64 */ -static const struct_sysent sh64_64bit_sysent[] = { - #include "sh64/syscallent.h" -}; -static const int sh64_64bit_usr1 = 0; -static const int sh64_64bit_usr2 = 0; -#undef SYS_socket_subcall -/* ARCH_sh */ -static const struct_sysent sh_32bit_sysent[] = { - #include "sh/syscallent.h" -}; -static const int sh_32bit_usr1 = 0; -static const int sh_32bit_usr2 = 0; -/* ARCH_x86_64 64bit ABI mode */ -static const struct_sysent x86_64_64bit_sysent[] = { - #include "x86_64/syscallent.h" -}; -static const int x86_64_64bit_usr1 = 0; -static const int x86_64_64bit_usr2 = 0; -/* ARCH_x86_64 x32 ABI mode */ -static const struct_sysent x86_64_x32_sysent[] = { - #include "x86_64/syscallent2.h" -}; -static const int x86_64_x32_usr1 = 0; -static const int x86_64_x32_usr2 = 0; -/* ARCH_x86 */ -static const struct_sysent x86_32bit_sysent[] = { - #include "i386/syscallent.h" -}; -static const int x86_32bit_usr1 = 0; -static const int x86_32bit_usr2 = 0; -/* ARCH_cris */ -static struct_sysent cris_32bit_sysent[] = { - #include "crisv10/syscallent.h" -}; -static const int cris_32bit_usr1 = 0; -static const int cris_32bit_usr2 = 0; -/* ARCH_crisv32 */ -static const struct_sysent crisv32_32bit_sysent[] = { - #include "crisv32/syscallent.h" -}; -static const int crisv32_32bit_usr1 = 0; -static const int crisv32_32bit_usr2 = 0; -#undef SYS_socket_subcall -/* ARCH_tile 64bit ABI mode */ -static const struct_sysent tile_64bit_sysent[] = { - #include "tile/syscallent.h" -}; -static const int tile_64bit_usr1 = 0; -static const int tile_64bit_usr2 = 0; -/* ARCH_tile 32bit ABI mode */ -static const struct_sysent tile_32bit_sysent[] = { - #include "tile/syscallent1.h" -}; -static const int tile_32bit_usr1 = 0; -static const int tile_32bit_usr2 = 0; -/* ARCH_microblaze */ -static const struct_sysent microblaze_32bit_sysent[] = { - #include "microblaze/syscallent.h" -}; -static const int microblaze_32bit_usr1 = 0; -static const int microblaze_32bit_usr2 = 0; -/* ARCH_nios2 */ -static const struct_sysent nios2_32bit_sysent[] = { - #include "nios2/syscallent.h" -}; -static const int nios2_32bit_usr1 = 0; -static const int nios2_32bit_usr2 = 0; -/* ARCH_openrisc */ -struct_sysent openrisc_32bit_sysent[] = { - #include "or1k/syscallent.h" -}; -static const int openrisc_32bit_usr1 = 0; -static const int openrisc_32bit_usr2 = 0; -/* ARCH_xtensa */ -static const struct_sysent xtensa_32bit_sysent[] = { - #include "xtensa/syscallent.h" -}; -static const int xtensa_32bit_usr1 = 0; -static const int xtensa_32bit_usr2 = 0; -/* ARCH_riscv 64bit ABI mode */ -static const struct_sysent riscv_64bit_sysent[] = { - #include "riscv/syscallent.h" -}; -static const int riscv_64bit_usr1 = 0; -static const int riscv_64bit_usr2 = 0; -/* ARCH_riscv 32bit ABI mode */ -static const struct_sysent riscv_32bit_sysent[] = { - #include "riscv/syscallent1.h" -}; -static const int riscv_32bit_usr1 = 0; -static const int riscv_32bit_usr2 = 0; diff --git a/tools/asinfo/arch_personalities.h b/tools/asinfo/arch_personalities.h deleted file mode 100644 index 9499c5aa..00000000 --- a/tools/asinfo/arch_personalities.h +++ /dev/null @@ -1,36 +0,0 @@ -ARCH_no_pers, -ARCH_blackfin_32bit, -ARCH_ia64_64bit, -ARCH_m68k_32bit, -ARCH_sparc64_64bit, -ARCH_sparc_32bit, -ARCH_metag_32bit, -ARCH_mips64_n64, -ARCH_mips64_n32, -ARCH_mips_o32, -ARCH_alpha_64bit, -ARCH_ppc64_64bit, -ARCH_ppc_32bit, -ARCH_aarch64_64bit, -ARCH_arm_oabi, -ARCH_arm_eabi, -ARCH_avr32_32bit, -ARCH_arc_32bit, -ARCH_s390x_64bit, -ARCH_s390_32bit, -ARCH_hppa_32bit, -ARCH_sh64_64bit, -ARCH_sh_32bit, -ARCH_x86_64_64bit, -ARCH_x86_64_x32, -ARCH_x86_32bit, -ARCH_cris_32bit, -ARCH_crisv32_32bit, -ARCH_tile_64bit, -ARCH_tile_32bit, -ARCH_microblaze_32bit, -ARCH_nios2_32bit, -ARCH_openrisc_32bit, -ARCH_xtensa_32bit, -ARCH_riscv_64bit, -ARCH_riscv_32bit diff --git a/tools/asinfo/gen_asinfo_files.sh b/tools/asinfo/gen_asinfo_files.sh new file mode 100755 index 00000000..ac14ed26 --- /dev/null +++ b/tools/asinfo/gen_asinfo_files.sh @@ -0,0 +1,215 @@ +#!/bin/sh +# +# Code generator simplifies addition of new architecture to asinfo tool +# +# Copyright (c) 2017 Edgar A. Kaziakhmedov <edgar.kaziakhme...@virtuozzo.com> +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. The name of the author may not be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +cur_pers="" + +usage() +{ + cat <<EOF +Usage: $0 + +Input file: ${0%/*}/arch_definitions.h + +Storage format: +/* [ARCH_SPECIFIC_DEFINE],[ACONST1,ACONST2] */ +ARCH_DESC_DEFINE(ARCH_NAME,ARCH_ABI,PASS({COMPAT_PERS1,COMPAT_PERS2,...}),PASS({ALIAS1,ALIAS2,...})) + +ARCH_SPECIFIC_DEFINE: +One syscallent.h header can contain several set of system calls for each +compatible mode. And specific set can be switched by passing particular definition. +So ARCH_SPECIFIC_DEFINE allows to forward a given definition, where +!ARCH_SPECIFIC_DEFINE forwards undefined. +If it is not required, left empty. + +ACONST1,ACONST2: +It could be used to store architecture specific constants and pass them to code. +If is is not required each one must be set to zero. + +ARCH_NAME: +The main name of architecture will be used to generate the personality constants. +The personality constant is equal to ARCH_+\$ARCH_ABI+_+\$ARCH_NAME. + +ARCH_ABI: +Application binary interface for a given architecture, i.e. 32bit, 64bit, oabi, +eabi, o32 etc. + +COMPAT_PERS1,COMPAT_PERS2,...: +Compatible mode for a given architecture. It should be one of personality constants. +If is is not required, left empty. + +ALIAS1,ALIAS2,...: +Other name of the same architecture, like x86 and i386. At least one alias +must to be set as it shows the name of architecture while printing. +If current ARCH_NAME is just the compatible ABI mode, left empty. +EOF + exit 1 +} + +gen_pers_line() +{ + local out_file="$1" + local line="$2" + local arch_abi="" + + LC_COLLATE=C + arch_abi="$(printf %s "${line}" | + sed 's/ARCH_DESC_DEFINE(//' | cut -d, -f 1,2 | + sed 's/,/_/g')" + cur_pers="${arch_abi}" + echo "ARCH_${arch_abi}," >> "${out_file}" +} + +gen_includes_block() +{ + local out_file="$1" + local line="$2" + local def is_def includes include nums num count + + ( + LC_COLLATE=C + echo "/* ${cur_pers} */" + def="$(printf %s "${line#*\*}" | cut -d] -f 1 | sed 's/.*[][]//g')" + #Generate define construction + if [ "${def#!}" != "" ] && [ $(printf %.1s "${def}") = "!" ]; then + cat <<-EOF + #ifdef ${def#!} + # undef ${def#!} + # define ${def#!}_DUMMY_UNDEFINE + #endif + EOF + is_def="def" + else if [ "${def#!}" != "" ]; then + cat <<-EOF + #ifndef ${def} + # define ${def} + # define ${def}_DUMMY_DEFINE + #endif + EOF + is_def="undef" + fi + fi + #Generate includes + includes="$(printf %s "${line#*\*}" | cut -d] -f 2 | sed 's/.*[][]//g')" + echo "static const struct_sysent ${cur_pers}_sysent[] = {" + for include in $(echo "${includes}" | sed "s/,/ /g") + do + echo " #include \"${include}\"" + done + echo "};" + #Undefine definitions, if it is required + if [ "${is_def}" = "def" ]; then + cat <<-EOF + #ifdef ${def#!}_DUMMY_UNDEFINE + # define ${def#!} 1 + # undef ${def#!}_DUMMY_UNDEFINE + #endif + EOF + else if [ "${is_def}" = "undef" ]; then + cat <<-EOF + #ifdef ${def#!}_DUMMY_DEFINE + # undef ${def#!} + # undef ${def#!}_DUMMY_DEFINE + #endif + EOF + fi + fi + #Generate arch specific numbers + nums="$(printf %s "${line#*\*}" | cut -d] -f 3 | sed 's/.*[][]//g')" + count=1 + for num in $(echo "${nums}" | sed "s/,/ /g") + do + echo "static const int ${cur_pers}_usr${count} = ${num};" + count=$((count+1)) + case "${num}" in + *[A-Za-z_]*) echo "#undef ${num}" ;; + *) ;; + esac + done + if [ $count -eq 1 ]; then + echo "static const int ${cur_pers}_usr${count} = 0;" + fi + echo "#undef SYS_socket_subcall" + ) >> "${out_file}" + echo "${def}" >> "${out_file}" +} + +main() +{ + case $# in + 0) set -- "${0%/*}" "${0%/*}" ;; + *) usage ;; + esac + + local input="$1" + local output="$2" + local defs_file="arch_definitions.h" + local pers_file="arch_personalities.h" + local includes_file="arch_includes.h" + local pline="" + + echo "ARCH_no_pers," > "${output}/${pers_file}" + echo -n > "${output}/${includes_file}" + + #Main work + while read line; do + line="$(printf %s "${line}" | sed 's/[[:space:]]//g')" + if $(printf %s "${line}" | + grep -F "ARCH_DESC_DEFINE" > /dev/null); then + gen_pers_line "${output}/${pers_file}" "${line}" + fi + if $(printf %s "${pline}" | grep -F "/*" > /dev/null); then + gen_includes_block "${output}/${includes_file}"\ + "${pline}" + fi + pline="${line}" + done < "${input}/${defs_file}" + #Makemodule.am + ( + echo -n \ +"ARCH_AUX_FILES = ${includes_file} ${pers_file}\n\ +\$(top_srcdir)/tools/asinfo/${includes_file}: \ +\$(top_srcdir)/tools/asinfo/${defs_file} \ +\$(top_srcdir)/tools/asinfo/gen_architecture_list.sh\n\ + \$(AM_V_GEN)\$(top_srcdir)/tools/asinfo/gen_architecture_list.sh\n\ +\$(top_srcdir)/tools/asinfo/${pers_file}: \ +\$(top_srcdir)/tools/asinfo/${defs_file} \ +\$(top_srcdir)/tools/asinfo/gen_architecture_list.sh\n\ + \$(AM_V_GEN)\$(top_srcdir)/tools/asinfo/gen_architecture_list.sh" + ) > "${output}/Makemodule.am" + #.gitignore + ( + echo -n \ +"/${includes_file}\n\ +/${pers_file}\n\ +/Makemodule.am\n\ +/.gitignore" + ) > "${output}/.gitignore" +} + +main "$@" -- 2.11.0 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel