From deae79f733a7c69f183f0e29a720e6c5bc3c1e7f Mon Sep 17 00:00:00 2001 From: Petar Jovanovic Date: Tue, 31 Dec 2019 12:05:33 +0000 Subject: [PATCH] mips: Add nanoMIPS support to Valgrind 4/4 Necessary changes to support nanoMIPS on Linux. Part 4/4 - Other changes (mainly include/*) Patch by Aleksandar Rikalo, Dimitrije Nikolic, Tamara Vlahovic, Nikola Milutinovic and Aleksandra Karadzic. Related KDE issue: #400872. --- .gitignore | 1 + Makefile.all.am | 7 + NEWS | 6 +- README | 1 + README.mips | 8 + configure.ac | 30 +- include/Makefile.am | 3 + include/pub_tool_basics.h | 13 +- include/pub_tool_guest.h | 2 +- include/pub_tool_libcsetjmp.h | 2 +- include/pub_tool_machine.h | 6 + include/pub_tool_vkiscnums_asm.h | 3 + include/valgrind.h | 489 ++++++++++++++ include/vki/vki-linux.h | 4 + include/vki/vki-nanomips-linux.h | 681 ++++++++++++++++++++ include/vki/vki-posixtypes-nanomips-linux.h | 68 ++ include/vki/vki-scnums-nanomips-linux.h | 322 +++++++++ tests/arch_test.c | 3 + 18 files changed, 1639 insertions(+), 10 deletions(-) create mode 100644 include/vki/vki-nanomips-linux.h create mode 100644 include/vki/vki-posixtypes-nanomips-linux.h create mode 100644 include/vki/vki-scnums-nanomips-linux.h diff --git a/.gitignore b/.gitignore index bacb265f02..ae2cdc9e56 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,7 @@ /auxprogs/getoff-ppc64le-linux /auxprogs/getoff-mips32-linux /auxprogs/getoff-mips64-linux +/auxprogs/getoff-nanomips-linux /auxprogs/getoff-amd64-solaris /auxprogs/getoff-x86-solaris /auxprogs/libmpiwrap-PPC32_LINUX.so diff --git a/Makefile.all.am b/Makefile.all.am index 3786e34933..6d88670e05 100644 --- a/Makefile.all.am +++ b/Makefile.all.am @@ -245,6 +245,12 @@ AM_CFLAGS_PSO_MIPS32_LINUX = @FLAG_M32@ $(AM_CFLAGS_BASE) \ $(AM_CFLAGS_PSO_BASE) AM_CCASFLAGS_MIPS32_LINUX = @FLAG_M32@ -g +AM_FLAG_M3264_NANOMIPS_LINUX = @FLAG_M32@ +AM_CFLAGS_NANOMIPS_LINUX = @FLAG_M32@ $(AM_CFLAGS_BASE) -mno-jump-table-opt +AM_CFLAGS_PSO_NANOMIPS_LINUX = @FLAG_M32@ $(AM_CFLAGS_BASE) \ + $(AM_CFLAGS_PSO_BASE) +AM_CCASFLAGS_NANOMIPS_LINUX = @FLAG_M32@ -g + AM_FLAG_M3264_MIPS64_LINUX = @FLAG_M64@ AM_CFLAGS_MIPS64_LINUX = @FLAG_M64@ $(AM_CFLAGS_BASE) AM_CFLAGS_PSO_MIPS64_LINUX = @FLAG_M64@ $(AM_CFLAGS_BASE) \ @@ -307,6 +313,7 @@ PRELOAD_LDFLAGS_X86_DARWIN = $(PRELOAD_LDFLAGS_COMMON_DARWIN) -arch i386 PRELOAD_LDFLAGS_AMD64_DARWIN = $(PRELOAD_LDFLAGS_COMMON_DARWIN) -arch x86_64 PRELOAD_LDFLAGS_S390X_LINUX = $(PRELOAD_LDFLAGS_COMMON_LINUX) @FLAG_M64@ PRELOAD_LDFLAGS_MIPS32_LINUX = $(PRELOAD_LDFLAGS_COMMON_LINUX) @FLAG_M32@ +PRELOAD_LDFLAGS_NANOMIPS_LINUX = $(PRELOAD_LDFLAGS_COMMON_LINUX) @FLAG_M32@ PRELOAD_LDFLAGS_MIPS64_LINUX = $(PRELOAD_LDFLAGS_COMMON_LINUX) @FLAG_M64@ PRELOAD_LDFLAGS_X86_SOLARIS = $(PRELOAD_LDFLAGS_COMMON_SOLARIS) @FLAG_M32@ PRELOAD_LDFLAGS_AMD64_SOLARIS = $(PRELOAD_LDFLAGS_COMMON_SOLARIS) @FLAG_M64@ diff --git a/NEWS b/NEWS index 826c07b063..28d80273cf 100644 --- a/NEWS +++ b/NEWS @@ -9,7 +9,7 @@ This release supports X86/Linux, AMD64/Linux, ARM32/Linux, ARM64/Linux, PPC32/Linux, PPC64BE/Linux, PPC64LE/Linux, S390X/Linux, MIPS32/Linux, MIPS64/Linux, ARM/Android, ARM64/Android, MIPS32/Android, X86/Android, X86/Solaris, AMD64/Solaris and AMD64/MacOSX 10.12. There is also preliminary -support for X86/macOS 10.13 and AMD64/macOS 10.13. +support for X86/macOS 10.13, AMD64/macOS 10.13 and nanoMIPS/Linux. * ==================== CORE CHANGES =================== @@ -25,6 +25,10 @@ support for X86/macOS 10.13 and AMD64/macOS 10.13. Your program can also change the dynamically changeable options using the client request VALGRIND_CLO_CHANGE(option). +* ================== PLATFORM CHANGES ================= + +* mips: preliminary support for nanoMIPS instruction set has been added. + * ==================== TOOL CHANGES ==================== * DHAT: diff --git a/README b/README index 0d3ac1de47..511027ae9b 100644 --- a/README +++ b/README @@ -43,6 +43,7 @@ platforms: - S390X/Linux - MIPS32/Linux - MIPS64/Linux +- nanoMIPS/Linux - X86/Solaris - AMD64/Solaris diff --git a/README.mips b/README.mips index 0df334ae29..82b00a5a07 100644 --- a/README.mips +++ b/README.mips @@ -29,6 +29,12 @@ CFLAGS="-mips64 -mabi=64" will do the trick and compile Valgrind correctly. * --host=mipsel-linux-gnu is necessary if you compile it with cross toolchain compiler for little endian platform. + * --host=nanomipseb-linux-gnu is necessary if you compile it with cross toolchain + compiler for nanoMIPS big endian platform. + + * --host=nanomips-linux-gnu is necessary if you compile it with cross toolchain + compiler for nanoMIPS little endian platform. + * --build=mips-linux is needed if you want to build it for MIPS32 on 64-bit MIPS system. @@ -51,3 +57,5 @@ Limitations no appropriate architecture flag is specified during configure time. Be sure to set either mips32 or mips32r2 as the target architecture in that case. +- Some tests can not be compiled for nanoMIPS due to limitations in + preliminary GCC for nanoMIPS. You can use '-i' switch for building tests. diff --git a/configure.ac b/configure.ac index 8e73d8ddb7..0d0e220c6a 100755 --- a/configure.ac +++ b/configure.ac @@ -286,6 +286,10 @@ case "${host_cpu}" in AC_MSG_RESULT([ok (${host_cpu})]) ARCH_MAX="mips64" ;; + nanomips) + AC_MSG_RESULT([ok (${host_cpu})]) + ARCH_MAX="nanomips" + ;; *) AC_MSG_RESULT([no (${host_cpu})]) @@ -784,6 +788,17 @@ case "$ARCH_MAX-$VGCONF_OS" in fi AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})]) ;; + nanomips-linux) + VGCONF_ARCH_PRI="nanomips" + VGCONF_ARCH_SEC="" + VGCONF_PLATFORM_PRI_CAPS="NANOMIPS_LINUX" + VGCONF_PLATFORM_SEC_CAPS="" + valt_load_address_pri_norml="0x58000000" + valt_load_address_pri_inner="0x38000000" + valt_load_address_sec_norml="0xUNSET" + valt_load_address_sec_inner="0xUNSET" + AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})]) + ;; x86-solaris) VGCONF_ARCH_PRI="x86" VGCONF_ARCH_SEC="" @@ -871,6 +886,8 @@ AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_MIPS32, -o x$VGCONF_PLATFORM_SEC_CAPS = xMIPS32_LINUX ) AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_MIPS64, test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX ) +AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_NANOMIPS, + test x$VGCONF_PLATFORM_PRI_CAPS = xNANOMIPS_LINUX ) # Set up VGCONF_PLATFORMS_INCLUDE_. Either one or two of these # become defined. @@ -899,6 +916,8 @@ AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_MIPS32_LINUX, -o x$VGCONF_PLATFORM_SEC_CAPS = xMIPS32_LINUX) AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_MIPS64_LINUX, test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX) +AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_NANOMIPS_LINUX, + test x$VGCONF_PLATFORM_PRI_CAPS = xNANOMIPS_LINUX) AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_X86_DARWIN, test x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN \ -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_DARWIN) @@ -924,7 +943,8 @@ AM_CONDITIONAL(VGCONF_OS_IS_LINUX, -o x$VGCONF_PLATFORM_PRI_CAPS = xARM64_LINUX \ -o x$VGCONF_PLATFORM_PRI_CAPS = xS390X_LINUX \ -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \ - -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX) + -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX \ + -o x$VGCONF_PLATFORM_PRI_CAPS = xNANOMIPS_LINUX) AM_CONDITIONAL(VGCONF_OS_IS_DARWIN, test x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN \ -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN) @@ -1814,6 +1834,8 @@ case "${host_cpu}" in AC_SUBST(FLAG_M64) fi ;; + nanomips*) + ;; *) # does this compiler support -m32 ? AC_MSG_CHECKING([if gcc accepts -m32]) @@ -4286,9 +4308,10 @@ AM_CONDITIONAL([HAVE_PREADV2_PWRITEV2], [test x$ac_cv_func_preadv2 = xyes && test x$ac_cv_func_pwritev2 = xyes]) if test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \ - -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX ; then + -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX \ + -o x$VGCONF_PLATFORM_PRI_CAPS = xNANOMIPS_LINUX; then AC_DEFINE([DISABLE_PTHREAD_SPINLOCK_INTERCEPT], 1, - [Disable intercept pthread_spin_lock() on MIPS32 and MIPS64.]) + [Disable intercept pthread_spin_lock() on MIPS32, MIPS64 and nanoMIPS.]) fi #---------------------------------------------------------------------------- @@ -4307,6 +4330,7 @@ if test x$VGCONF_PLATFORM_PRI_CAPS = xX86_LINUX \ -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC32_LINUX \ -o x$VGCONF_PLATFORM_PRI_CAPS = xARM_LINUX \ -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \ + -o x$VGCONF_PLATFORM_PRI_CAPS = xNANOMIPS_LINUX \ -o x$VGCONF_PLATFORM_PRI_CAPS = xX86_SOLARIS ; then mflag_primary=$FLAG_M32 elif test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_LINUX \ diff --git a/include/Makefile.am b/include/Makefile.am index 11c7ca86db..9bf02c224c 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -59,6 +59,7 @@ nobase_pkginclude_HEADERS = \ vki/vki-posixtypes-s390x-linux.h \ vki/vki-posixtypes-mips32-linux.h \ vki/vki-posixtypes-mips64-linux.h \ + vki/vki-posixtypes-nanomips-linux.h \ vki/vki-amd64-linux.h \ vki/vki-arm64-linux.h \ vki/vki-ppc32-linux.h \ @@ -68,6 +69,7 @@ nobase_pkginclude_HEADERS = \ vki/vki-s390x-linux.h \ vki/vki-mips32-linux.h \ vki/vki-mips64-linux.h \ + vki/vki-nanomips-linux.h \ vki/vki-scnums-amd64-linux.h \ vki/vki-scnums-arm64-linux.h \ vki/vki-scnums-ppc32-linux.h \ @@ -77,6 +79,7 @@ nobase_pkginclude_HEADERS = \ vki/vki-scnums-s390x-linux.h \ vki/vki-scnums-mips32-linux.h \ vki/vki-scnums-mips64-linux.h \ + vki/vki-scnums-nanomips-linux.h \ vki/vki-scnums-darwin.h \ vki/vki-scnums-solaris.h \ vki/vki-xen.h \ diff --git a/include/pub_tool_basics.h b/include/pub_tool_basics.h index 4580e06b2b..d1119e1efa 100644 --- a/include/pub_tool_basics.h +++ b/include/pub_tool_basics.h @@ -294,7 +294,11 @@ static inline UWord sr_Res ( SysRes sr ) { return sr._isError ? 0 : sr._val; } static inline UWord sr_Err ( SysRes sr ) { +#if defined(VGP_nanomips_linux) + return sr._isError ? -sr._val : 0; +#else return sr._isError ? sr._val : 0; +#endif } static inline Bool sr_EQ ( UInt sysno, SysRes sr1, SysRes sr2 ) { /* sysno is ignored for Linux/not-MIPS */ @@ -401,11 +405,12 @@ static inline Bool sr_EQ ( UInt sysno, SysRes sr1, SysRes sr2 ) { #undef VG_LITTLEENDIAN #if defined(VGA_x86) || defined(VGA_amd64) || defined (VGA_arm) \ - || ((defined(VGA_mips32) || defined(VGA_mips64)) && defined (_MIPSEL)) \ - || defined(VGA_arm64) || defined(VGA_ppc64le) + || ((defined(VGA_mips32) || defined(VGA_mips64) || defined(VGA_nanomips)) \ + && defined (_MIPSEL)) || defined(VGA_arm64) || defined(VGA_ppc64le) # define VG_LITTLEENDIAN 1 #elif defined(VGA_ppc32) || defined(VGA_ppc64be) || defined(VGA_s390x) \ - || ((defined(VGA_mips32) || defined(VGA_mips64)) && defined (_MIPSEB)) + || ((defined(VGA_mips32) || defined(VGA_mips64) || defined(VGA_nanomips)) \ + && defined (_MIPSEB)) # define VG_BIGENDIAN 1 #else # error Unknown arch @@ -449,7 +454,7 @@ static inline Bool sr_EQ ( UInt sysno, SysRes sr1, SysRes sr2 ) { || defined(VGA_ppc64be) || defined(VGA_ppc64le) \ || defined(VGA_arm) || defined(VGA_s390x) \ || defined(VGA_mips32) || defined(VGA_mips64) \ - || defined(VGA_arm64) + || defined(VGA_arm64) || defined(VGA_nanomips) # define VG_REGPARM(n) /* */ #else # error Unknown arch diff --git a/include/pub_tool_guest.h b/include/pub_tool_guest.h index c0b36f82d8..08a72efac6 100644 --- a/include/pub_tool_guest.h +++ b/include/pub_tool_guest.h @@ -56,7 +56,7 @@ #elif defined(VGA_s390x) # include "libvex_guest_s390x.h" typedef VexGuestS390XState VexGuestArchState; -#elif defined(VGA_mips32) +#elif defined(VGA_mips32) || defined(VGA_nanomips) # include "libvex_guest_mips32.h" typedef VexGuestMIPS32State VexGuestArchState; #elif defined(VGA_mips64) diff --git a/include/pub_tool_libcsetjmp.h b/include/pub_tool_libcsetjmp.h index 681450cef7..03da232e44 100644 --- a/include/pub_tool_libcsetjmp.h +++ b/include/pub_tool_libcsetjmp.h @@ -110,7 +110,7 @@ __attribute__((noreturn)) __attribute__((regparm(1))) // ditto void VG_MINIMAL_LONGJMP(VG_MINIMAL_JMP_BUF(_env)); -#elif defined(VGP_mips32_linux) +#elif defined(VGP_mips32_linux) || defined(VGP_nanomips_linux) #define VG_MINIMAL_JMP_BUF(_name) ULong _name [104 / sizeof(ULong)] __attribute__((returns_twice)) diff --git a/include/pub_tool_machine.h b/include/pub_tool_machine.h index 1cdf19cd85..4779eea015 100644 --- a/include/pub_tool_machine.h +++ b/include/pub_tool_machine.h @@ -102,6 +102,12 @@ # define VG_CLREQ_SZB 20 # define VG_STACK_REDZONE_SZB 0 +#elif defined(VGP_nanomips_linux) +# define VG_MIN_INSTR_SZB 2 +# define VG_MAX_INSTR_SZB 6 +# define VG_CLREQ_SZB 20 +# define VG_STACK_REDZONE_SZB 0 + #else # error Unknown platform #endif diff --git a/include/pub_tool_vkiscnums_asm.h b/include/pub_tool_vkiscnums_asm.h index af1552ffc9..6ede6f90ef 100644 --- a/include/pub_tool_vkiscnums_asm.h +++ b/include/pub_tool_vkiscnums_asm.h @@ -67,6 +67,9 @@ # include "vki/vki-scnums-32bit-linux.h" # include "vki/vki-scnums-mips32-linux.h" +#elif defined(VGP_nanomips_linux) +# include "vki/vki-scnums-nanomips-linux.h" + #elif defined(VGP_mips64_linux) # include "vki/vki-scnums-shared-linux.h" # include "vki/vki-scnums-mips64-linux.h" diff --git a/include/valgrind.h b/include/valgrind.h index 9323e2c004..c8b24a38e8 100644 --- a/include/valgrind.h +++ b/include/valgrind.h @@ -122,6 +122,7 @@ #undef PLAT_s390x_linux #undef PLAT_mips32_linux #undef PLAT_mips64_linux +#undef PLAT_nanomips_linux #undef PLAT_x86_solaris #undef PLAT_amd64_solaris @@ -159,6 +160,8 @@ # define PLAT_mips64_linux 1 #elif defined(__linux__) && defined(__mips__) && (__mips==32) # define PLAT_mips32_linux 1 +#elif defined(__linux__) && defined(__nanomips__) +# define PLAT_nanomips_linux 1 #elif defined(__sun) && defined(__i386__) # define PLAT_x86_solaris 1 #elif defined(__sun) && defined(__x86_64__) @@ -1045,6 +1048,75 @@ typedef #endif /* PLAT_mips64_linux */ +#if defined(PLAT_nanomips_linux) + +typedef + struct { + unsigned int nraddr; /* where's the code? */ + } + OrigFn; +/* + 8000 c04d srl zero, zero, 13 + 8000 c05d srl zero, zero, 29 + 8000 c043 srl zero, zero, 3 + 8000 c053 srl zero, zero, 19 +*/ + +#define __SPECIAL_INSTRUCTION_PREAMBLE "srl[32] $zero, $zero, 13 \n\t" \ + "srl[32] $zero, $zero, 29 \n\t" \ + "srl[32] $zero, $zero, 3 \n\t" \ + "srl[32] $zero, $zero, 19 \n\t" + +#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \ + _zzq_default, _zzq_request, \ + _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \ + __extension__ \ + ({ volatile unsigned int _zzq_args[6]; \ + volatile unsigned int _zzq_result; \ + _zzq_args[0] = (unsigned int)(_zzq_request); \ + _zzq_args[1] = (unsigned int)(_zzq_arg1); \ + _zzq_args[2] = (unsigned int)(_zzq_arg2); \ + _zzq_args[3] = (unsigned int)(_zzq_arg3); \ + _zzq_args[4] = (unsigned int)(_zzq_arg4); \ + _zzq_args[5] = (unsigned int)(_zzq_arg5); \ + __asm__ volatile("move $a7, %1\n\t" /* default */ \ + "move $t0, %2\n\t" /* ptr */ \ + __SPECIAL_INSTRUCTION_PREAMBLE \ + /* $a7 = client_request( $t0 ) */ \ + "or[32] $t0, $t0, $t0\n\t" \ + "move %0, $a7\n\t" /* result */ \ + : "=r" (_zzq_result) \ + : "r" (_zzq_default), "r" (&_zzq_args[0]) \ + : "$a7", "$t0", "memory"); \ + _zzq_result; \ + }) + +#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \ + { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \ + volatile unsigned long int __addr; \ + __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ + /* $a7 = guest_NRADDR */ \ + "or[32] $t1, $t1, $t1\n\t" \ + "move %0, $a7" /*result*/ \ + : "=r" (__addr) \ + : \ + : "$a7"); \ + _zzq_orig->nraddr = __addr; \ + } + +#define VALGRIND_CALL_NOREDIR_T9 \ + __SPECIAL_INSTRUCTION_PREAMBLE \ + /* call-noredir $25 */ \ + "or[32] $t2, $t2, $t2\n\t" + +#define VALGRIND_VEX_INJECT_IR() \ + do { \ + __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \ + "or[32] $t3, $t3, $t3\n\t" \ + ); \ + } while (0) + +#endif /* Insert assembly code for other platforms here... */ #endif /* NVALGRIND */ @@ -5686,6 +5758,422 @@ typedef #endif /* PLAT_mips32_linux */ +/* ------------------------- nanomips-linux -------------------- */ + +#if defined(PLAT_nanomips_linux) + +/* These regs are trashed by the hidden call. */ +#define __CALLER_SAVED_REGS "$t4", "$t5", "$a0", "$a1", "$a2", \ +"$a3", "$a4", "$a5", "$a6", "$a7", "$t0", "$t1", "$t2", "$t3", \ +"$t8","$t9", "$at" + +/* These CALL_FN_ macros assume that on mips-linux, sizeof(unsigned + long) == 4. */ + +#define CALL_FN_W_v(lval, orig) \ + do { \ + volatile OrigFn _orig = (orig); \ + volatile unsigned long _argvec[1]; \ + volatile unsigned long _res; \ + _argvec[0] = (unsigned long)_orig.nraddr; \ + __asm__ volatile( \ + "lw $t9, 0(%1)\n\t" \ + VALGRIND_CALL_NOREDIR_T9 \ + "move %0, $a0\n" \ + : /*out*/ "=r" (_res) \ + : /*in*/ "r" (&_argvec[0]) \ + : /*trash*/ "memory", __CALLER_SAVED_REGS \ + ); \ + lval = (__typeof__(lval)) _res; \ + } while (0) + +#define CALL_FN_W_W(lval, orig, arg1) \ + do { \ + volatile OrigFn _orig = (orig); \ + volatile unsigned long _argvec[2]; \ + volatile unsigned long _res; \ + _argvec[0] = (unsigned long)_orig.nraddr; \ + _argvec[1] = (unsigned long)(arg1); \ + __asm__ volatile( \ + "lw $t9, 0(%1)\n\t" \ + "lw $a0, 4(%1)\n\t" \ + VALGRIND_CALL_NOREDIR_T9 \ + "move %0, $a0\n" \ + : /*out*/ "=r" (_res) \ + : /*in*/ "r" (&_argvec[0]) \ + : /*trash*/ "memory", __CALLER_SAVED_REGS \ + ); \ + lval = (__typeof__(lval)) _res; \ + } while (0) + +#define CALL_FN_W_WW(lval, orig, arg1,arg2) \ + do { \ + volatile OrigFn _orig = (orig); \ + volatile unsigned long _argvec[3]; \ + volatile unsigned long _res; \ + _argvec[0] = (unsigned long)_orig.nraddr; \ + _argvec[1] = (unsigned long)(arg1); \ + _argvec[2] = (unsigned long)(arg2); \ + __asm__ volatile( \ + "lw $t9, 0(%1)\n\t" \ + "lw $a0, 4(%1)\n\t" \ + "lw $a1, 8(%1)\n\t" \ + VALGRIND_CALL_NOREDIR_T9 \ + "move %0, $a0\n" \ + : /*out*/ "=r" (_res) \ + : /*in*/ "r" (&_argvec[0]) \ + : /*trash*/ "memory", __CALLER_SAVED_REGS \ + ); \ + lval = (__typeof__(lval)) _res; \ + } while (0) + +#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \ + do { \ + volatile OrigFn _orig = (orig); \ + volatile unsigned long _argvec[4]; \ + volatile unsigned long _res; \ + _argvec[0] = (unsigned long)_orig.nraddr; \ + _argvec[1] = (unsigned long)(arg1); \ + _argvec[2] = (unsigned long)(arg2); \ + _argvec[3] = (unsigned long)(arg3); \ + __asm__ volatile( \ + "lw $t9, 0(%1)\n\t" \ + "lw $a0, 4(%1)\n\t" \ + "lw $a1, 8(%1)\n\t" \ + "lw $a2,12(%1)\n\t" \ + VALGRIND_CALL_NOREDIR_T9 \ + "move %0, $a0\n" \ + : /*out*/ "=r" (_res) \ + : /*in*/ "r" (&_argvec[0]) \ + : /*trash*/ "memory", __CALLER_SAVED_REGS \ + ); \ + lval = (__typeof__(lval)) _res; \ + } while (0) + +#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \ + do { \ + volatile OrigFn _orig = (orig); \ + volatile unsigned long _argvec[5]; \ + volatile unsigned long _res; \ + _argvec[0] = (unsigned long)_orig.nraddr; \ + _argvec[1] = (unsigned long)(arg1); \ + _argvec[2] = (unsigned long)(arg2); \ + _argvec[3] = (unsigned long)(arg3); \ + _argvec[4] = (unsigned long)(arg4); \ + __asm__ volatile( \ + "lw $t9, 0(%1)\n\t" \ + "lw $a0, 4(%1)\n\t" \ + "lw $a1, 8(%1)\n\t" \ + "lw $a2,12(%1)\n\t" \ + "lw $a3,16(%1)\n\t" \ + VALGRIND_CALL_NOREDIR_T9 \ + "move %0, $a0\n" \ + : /*out*/ "=r" (_res) \ + : /*in*/ "r" (&_argvec[0]) \ + : /*trash*/ "memory", __CALLER_SAVED_REGS \ + ); \ + lval = (__typeof__(lval)) _res; \ + } while (0) + +#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \ + do { \ + volatile OrigFn _orig = (orig); \ + volatile unsigned long _argvec[6]; \ + volatile unsigned long _res; \ + _argvec[0] = (unsigned long)_orig.nraddr; \ + _argvec[1] = (unsigned long)(arg1); \ + _argvec[2] = (unsigned long)(arg2); \ + _argvec[3] = (unsigned long)(arg3); \ + _argvec[4] = (unsigned long)(arg4); \ + _argvec[5] = (unsigned long)(arg5); \ + __asm__ volatile( \ + "lw $t9, 0(%1)\n\t" \ + "lw $a0, 4(%1)\n\t" \ + "lw $a1, 8(%1)\n\t" \ + "lw $a2,12(%1)\n\t" \ + "lw $a3,16(%1)\n\t" \ + "lw $a4,20(%1)\n\t" \ + VALGRIND_CALL_NOREDIR_T9 \ + "move %0, $a0\n" \ + : /*out*/ "=r" (_res) \ + : /*in*/ "r" (&_argvec[0]) \ + : /*trash*/ "memory", __CALLER_SAVED_REGS \ + ); \ + lval = (__typeof__(lval)) _res; \ + } while (0) +#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \ + do { \ + volatile OrigFn _orig = (orig); \ + volatile unsigned long _argvec[7]; \ + volatile unsigned long _res; \ + _argvec[0] = (unsigned long)_orig.nraddr; \ + _argvec[1] = (unsigned long)(arg1); \ + _argvec[2] = (unsigned long)(arg2); \ + _argvec[3] = (unsigned long)(arg3); \ + _argvec[4] = (unsigned long)(arg4); \ + _argvec[5] = (unsigned long)(arg5); \ + _argvec[6] = (unsigned long)(arg6); \ + __asm__ volatile( \ + "lw $t9, 0(%1)\n\t" \ + "lw $a0, 4(%1)\n\t" \ + "lw $a1, 8(%1)\n\t" \ + "lw $a2,12(%1)\n\t" \ + "lw $a3,16(%1)\n\t" \ + "lw $a4,20(%1)\n\t" \ + "lw $a5,24(%1)\n\t" \ + VALGRIND_CALL_NOREDIR_T9 \ + "move %0, $a0\n" \ + : /*out*/ "=r" (_res) \ + : /*in*/ "r" (&_argvec[0]) \ + : /*trash*/ "memory", __CALLER_SAVED_REGS \ + ); \ + lval = (__typeof__(lval)) _res; \ + } while (0) + +#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ + arg7) \ + do { \ + volatile OrigFn _orig = (orig); \ + volatile unsigned long _argvec[8]; \ + volatile unsigned long _res; \ + _argvec[0] = (unsigned long)_orig.nraddr; \ + _argvec[1] = (unsigned long)(arg1); \ + _argvec[2] = (unsigned long)(arg2); \ + _argvec[3] = (unsigned long)(arg3); \ + _argvec[4] = (unsigned long)(arg4); \ + _argvec[5] = (unsigned long)(arg5); \ + _argvec[6] = (unsigned long)(arg6); \ + _argvec[7] = (unsigned long)(arg7); \ + __asm__ volatile( \ + "lw $t9, 0(%1)\n\t" \ + "lw $a0, 4(%1)\n\t" \ + "lw $a1, 8(%1)\n\t" \ + "lw $a2,12(%1)\n\t" \ + "lw $a3,16(%1)\n\t" \ + "lw $a4,20(%1)\n\t" \ + "lw $a5,24(%1)\n\t" \ + "lw $a6,28(%1)\n\t" \ + VALGRIND_CALL_NOREDIR_T9 \ + "move %0, $a0\n" \ + : /*out*/ "=r" (_res) \ + : /*in*/ "r" (&_argvec[0]) \ + : /*trash*/ "memory", __CALLER_SAVED_REGS \ + ); \ + lval = (__typeof__(lval)) _res; \ + } while (0) + +#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ + arg7,arg8) \ + do { \ + volatile OrigFn _orig = (orig); \ + volatile unsigned long _argvec[9]; \ + volatile unsigned long _res; \ + _argvec[0] = (unsigned long)_orig.nraddr; \ + _argvec[1] = (unsigned long)(arg1); \ + _argvec[2] = (unsigned long)(arg2); \ + _argvec[3] = (unsigned long)(arg3); \ + _argvec[4] = (unsigned long)(arg4); \ + _argvec[5] = (unsigned long)(arg5); \ + _argvec[6] = (unsigned long)(arg6); \ + _argvec[7] = (unsigned long)(arg7); \ + _argvec[8] = (unsigned long)(arg8); \ + __asm__ volatile( \ + "lw $t9, 0(%1)\n\t" \ + "lw $a0, 4(%1)\n\t" \ + "lw $a1, 8(%1)\n\t" \ + "lw $a2,12(%1)\n\t" \ + "lw $a3,16(%1)\n\t" \ + "lw $a4,20(%1)\n\t" \ + "lw $a5,24(%1)\n\t" \ + "lw $a6,28(%1)\n\t" \ + "lw $a7,32(%1)\n\t" \ + VALGRIND_CALL_NOREDIR_T9 \ + "move %0, $a0\n" \ + : /*out*/ "=r" (_res) \ + : /*in*/ "r" (&_argvec[0]) \ + : /*trash*/ "memory", __CALLER_SAVED_REGS \ + ); \ + lval = (__typeof__(lval)) _res; \ + } while (0) + +#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ + arg7,arg8,arg9) \ + do { \ + volatile OrigFn _orig = (orig); \ + volatile unsigned long _argvec[10]; \ + volatile unsigned long _res; \ + _argvec[0] = (unsigned long)_orig.nraddr; \ + _argvec[1] = (unsigned long)(arg1); \ + _argvec[2] = (unsigned long)(arg2); \ + _argvec[3] = (unsigned long)(arg3); \ + _argvec[4] = (unsigned long)(arg4); \ + _argvec[5] = (unsigned long)(arg5); \ + _argvec[6] = (unsigned long)(arg6); \ + _argvec[7] = (unsigned long)(arg7); \ + _argvec[8] = (unsigned long)(arg8); \ + _argvec[9] = (unsigned long)(arg9); \ + __asm__ volatile( \ + "addiu $sp, $sp, -16 \n\t" \ + "lw $t9,36(%1) \n\t" \ + "sw $t9, 0($sp) \n\t" \ + "lw $t9, 0(%1) \n\t" \ + "lw $a0, 4(%1) \n\t" \ + "lw $a1, 8(%1) \n\t" \ + "lw $a2,12(%1) \n\t" \ + "lw $a3,16(%1) \n\t" \ + "lw $a4,20(%1) \n\t" \ + "lw $a5,24(%1) \n\t" \ + "lw $a6,28(%1) \n\t" \ + "lw $a7,32(%1) \n\t" \ + VALGRIND_CALL_NOREDIR_T9 \ + "move %0, $a0 \n\t" \ + "addiu $sp, $sp, 16 \n\t" \ + : /*out*/ "=r" (_res) \ + : /*in*/ "r" (&_argvec[0]) \ + : /*trash*/ "memory", __CALLER_SAVED_REGS \ + ); \ + lval = (__typeof__(lval)) _res; \ + } while (0) + +#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \ + arg7,arg8,arg9,arg10) \ + do { \ + volatile OrigFn _orig = (orig); \ + volatile unsigned long _argvec[11]; \ + volatile unsigned long _res; \ + _argvec[0] = (unsigned long)_orig.nraddr; \ + _argvec[1] = (unsigned long)(arg1); \ + _argvec[2] = (unsigned long)(arg2); \ + _argvec[3] = (unsigned long)(arg3); \ + _argvec[4] = (unsigned long)(arg4); \ + _argvec[5] = (unsigned long)(arg5); \ + _argvec[6] = (unsigned long)(arg6); \ + _argvec[7] = (unsigned long)(arg7); \ + _argvec[8] = (unsigned long)(arg8); \ + _argvec[9] = (unsigned long)(arg9); \ + _argvec[10] = (unsigned long)(arg10); \ + __asm__ volatile( \ + "addiu $sp, $sp, -16 \n\t" \ + "lw $t9,36(%1) \n\t" \ + "sw $t9, 0($sp) \n\t" \ + "lw $t9,40(%1) \n\t" \ + "sw $t9, 4($sp) \n\t" \ + "lw $t9, 0(%1) \n\t" \ + "lw $a0, 4(%1) \n\t" \ + "lw $a1, 8(%1) \n\t" \ + "lw $a2,12(%1) \n\t" \ + "lw $a3,16(%1) \n\t" \ + "lw $a4,20(%1) \n\t" \ + "lw $a5,24(%1) \n\t" \ + "lw $a6,28(%1) \n\t" \ + "lw $a7,32(%1) \n\t" \ + VALGRIND_CALL_NOREDIR_T9 \ + "move %0, $a0 \n\t" \ + "addiu $sp, $sp, 16 \n\t" \ + : /*out*/ "=r" (_res) \ + : /*in*/ "r" (&_argvec[0]) \ + : /*trash*/ "memory", __CALLER_SAVED_REGS \ + ); \ + lval = (__typeof__(lval)) _res; \ + } while (0) + +#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ + arg6,arg7,arg8,arg9,arg10, \ + arg11) \ + do { \ + volatile OrigFn _orig = (orig); \ + volatile unsigned long _argvec[12]; \ + volatile unsigned long _res; \ + _argvec[0] = (unsigned long)_orig.nraddr; \ + _argvec[1] = (unsigned long)(arg1); \ + _argvec[2] = (unsigned long)(arg2); \ + _argvec[3] = (unsigned long)(arg3); \ + _argvec[4] = (unsigned long)(arg4); \ + _argvec[5] = (unsigned long)(arg5); \ + _argvec[6] = (unsigned long)(arg6); \ + _argvec[7] = (unsigned long)(arg7); \ + _argvec[8] = (unsigned long)(arg8); \ + _argvec[9] = (unsigned long)(arg9); \ + _argvec[10] = (unsigned long)(arg10); \ + _argvec[11] = (unsigned long)(arg11); \ + __asm__ volatile( \ + "addiu $sp, $sp, -16 \n\t" \ + "lw $t9,36(%1) \n\t" \ + "sw $t9, 0($sp) \n\t" \ + "lw $t9,40(%1) \n\t" \ + "sw $t9, 4($sp) \n\t" \ + "lw $t9,44(%1) \n\t" \ + "sw $t9, 8($sp) \n\t" \ + "lw $t9, 0(%1) \n\t" \ + "lw $a0, 4(%1) \n\t" \ + "lw $a1, 8(%1) \n\t" \ + "lw $a2,12(%1) \n\t" \ + "lw $a3,16(%1) \n\t" \ + "lw $a4,20(%1) \n\t" \ + "lw $a5,24(%1) \n\t" \ + "lw $a6,28(%1) \n\t" \ + "lw $a7,32(%1) \n\t" \ + VALGRIND_CALL_NOREDIR_T9 \ + "move %0, $a0 \n\t" \ + "addiu $sp, $sp, 16 \n\t" \ + : /*out*/ "=r" (_res) \ + : /*in*/ "r" (&_argvec[0]) \ + : /*trash*/ "memory", __CALLER_SAVED_REGS \ + ); \ + lval = (__typeof__(lval)) _res; \ + } while (0) + +#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \ + arg6,arg7,arg8,arg9,arg10, \ + arg11,arg12) \ + do { \ + volatile OrigFn _orig = (orig); \ + volatile unsigned long _argvec[13]; \ + volatile unsigned long _res; \ + _argvec[0] = (unsigned long)_orig.nraddr; \ + _argvec[1] = (unsigned long)(arg1); \ + _argvec[2] = (unsigned long)(arg2); \ + _argvec[3] = (unsigned long)(arg3); \ + _argvec[4] = (unsigned long)(arg4); \ + _argvec[5] = (unsigned long)(arg5); \ + _argvec[6] = (unsigned long)(arg6); \ + _argvec[7] = (unsigned long)(arg7); \ + _argvec[8] = (unsigned long)(arg8); \ + _argvec[9] = (unsigned long)(arg9); \ + _argvec[10] = (unsigned long)(arg10); \ + _argvec[11] = (unsigned long)(arg11); \ + _argvec[12] = (unsigned long)(arg12); \ + __asm__ volatile( \ + "addiu $sp, $sp, -16 \n\t" \ + "lw $t9,36(%1) \n\t" \ + "sw $t9, 0($sp) \n\t" \ + "lw $t9,40(%1) \n\t" \ + "sw $t9, 4($sp) \n\t" \ + "lw $t9,44(%1) \n\t" \ + "sw $t9, 8($sp) \n\t" \ + "lw $t9,48(%1) \n\t" \ + "sw $t9,12($sp) \n\t" \ + "lw $t9, 0(%1) \n\t" \ + "lw $a0, 4(%1) \n\t" \ + "lw $a1, 8(%1) \n\t" \ + "lw $a2,12(%1) \n\t" \ + "lw $a3,16(%1) \n\t" \ + "lw $a4,20(%1) \n\t" \ + "lw $a5,24(%1) \n\t" \ + "lw $a6,28(%1) \n\t" \ + "lw $a7,32(%1) \n\t" \ + VALGRIND_CALL_NOREDIR_T9 \ + "move %0, $a0 \n\t" \ + "addiu $sp, $sp, 16 \n\t" \ + : /*out*/ "=r" (_res) \ + : /*in*/ "r" (&_argvec[0]) \ + : /*trash*/ "memory", __CALLER_SAVED_REGS \ + ); \ + lval = (__typeof__(lval)) _res; \ + } while (0) + +#endif /* PLAT_nanomips_linux */ + /* ------------------------- mips64-linux ------------------------- */ #if defined(PLAT_mips64_linux) @@ -6661,6 +7149,7 @@ VALGRIND_PRINTF_BACKTRACE(const char *format, ...) #undef PLAT_s390x_linux #undef PLAT_mips32_linux #undef PLAT_mips64_linux +#undef PLAT_nanomips_linux #undef PLAT_x86_solaris #undef PLAT_amd64_solaris diff --git a/include/vki/vki-linux.h b/include/vki/vki-linux.h index dd9b20fa2f..91600db7fc 100644 --- a/include/vki/vki-linux.h +++ b/include/vki/vki-linux.h @@ -95,6 +95,8 @@ # include "vki-posixtypes-mips32-linux.h" #elif defined(VGA_mips64) # include "vki-posixtypes-mips64-linux.h" +#elif defined(VGA_nanomips) +# include "vki-posixtypes-nanomips-linux.h" #else # error Unknown platform #endif @@ -221,6 +223,8 @@ typedef unsigned int vki_uint; # include "vki-mips32-linux.h" #elif defined(VGA_mips64) # include "vki-mips64-linux.h" +#elif defined(VGA_nanomips) +# include "vki-nanomips-linux.h" #else # error Unknown platform #endif diff --git a/include/vki/vki-nanomips-linux.h b/include/vki/vki-nanomips-linux.h new file mode 100644 index 0000000000..7f42c25912 --- /dev/null +++ b/include/vki/vki-nanomips-linux.h @@ -0,0 +1,681 @@ + +/*--------------------------------------------------------------------*/ +/*-- nanoMIPS/Linux-specific kernel interface vki-nanomips-linux.h --*/ +/*--------------------------------------------------------------------*/ + +/* + This file is part of Valgrind, a dynamic binary instrumentation + framework. + + Copyright (C) 2018 RT-RK + mips-valgrind@rt-rk.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307, USA. + + The GNU General Public License is contained in the file COPYING. +*/ + +#ifndef __VKI_NANOMIPS_LINUX_H +#define __VKI_NANOMIPS_LINUX_H + +#include + +#if defined (_MIPSEL) +#define VKI_LITTLE_ENDIAN 1 +#elif defined (_MIPSEB) +#define VKI_BIG_ENDIAN 1 +#endif + +#define VKI_PAGE_MASK (~(VKI_PAGE_SIZE - 1)) +#define VKI_MAX_PAGE_SHIFT 16 +#define VKI_MAX_PAGE_SIZE (1UL << VKI_MAX_PAGE_SHIFT) + +#define VKI_SIGHUP 1 +#define VKI_SIGINT 2 +#define VKI_SIGQUIT 3 +#define VKI_SIGILL 4 +#define VKI_SIGTRAP 5 +#define VKI_SIGABRT 6 +#define VKI_SIGIOT 6 +#define VKI_SIGBUS 7 +#define VKI_SIGFPE 8 +#define VKI_SIGKILL 9 +#define VKI_SIGUSR1 10 +#define VKI_SIGSEGV 11 +#define VKI_SIGUSR2 12 +#define VKI_SIGPIPE 13 +#define VKI_SIGALRM 14 +#define VKI_SIGTERM 15 +#define VKI_SIGSTKFLT 16 +#define VKI_SIGCHLD 17 +#define VKI_SIGCONT 18 +#define VKI_SIGSTOP 19 +#define VKI_SIGTSTP 20 +#define VKI_SIGTTIN 21 +#define VKI_SIGTTOU 22 +#define VKI_SIGURG 23 +#define VKI_SIGXCPU 24 +#define VKI_SIGXFSZ 25 +#define VKI_SIGVTALRM 26 +#define VKI_SIGPROF 27 +#define VKI_SIGWINCH 28 +#define VKI_SIGIO 29 +#define VKI_SIGPWR 30 +#define VKI_SIGSYS 31 +#define VKI_SIGRTMIN 32 + +#define VKI_SIG_BLOCK 0 /* for blocking signals */ +#define VKI_SIG_UNBLOCK 1 /* for unblocking signals */ +#define VKI_SIG_SETMASK 2 /* for setting the signal mask */ + +/* default signal handling */ +#define VKI_SIG_DFL ((__vki_sighandler_t)0) +/* ignore signal */ +#define VKI_SIG_IGN ((__vki_sighandler_t)1) + +#define VKI_SIGRTMAX _VKI_NSIG +#define VKI_MINSIGSTKSZ 2048 +#define _VKI_NSIG 64 +#define _VKI_NSIG_BPW 32 +#define _VKI_NSIG_WORDS (_VKI_NSIG / _VKI_NSIG_BPW) + +#define VKI_SA_NOCLDSTOP 0x00000001 +#define VKI_SA_NOCLDWAIT 0x00000002 +#define VKI_SA_SIGINFO 0x00000004 +#define VKI_SA_ONSTACK 0x08000000 +#define VKI_SA_RESTART 0x10000000 +#define VKI_SA_NODEFER 0x40000000 +#define VKI_SA_RESETHAND 0x80000000 +#define VKI_SA_RESTORER 0x04000000 +#define VKI_SA_NOMASK VKI_SA_NODEFER +#define VKI_SA_ONESHOT VKI_SA_RESETHAND + +#define VKI_SS_ONSTACK 1 +#define VKI_SS_DISABLE 2 + +#define VKI_PROT_NONE 0x0 /* No page permissions */ +#define VKI_PROT_READ 0x1 /* page can be read */ +#define VKI_PROT_WRITE 0x2 /* page can be written */ +#define VKI_PROT_EXEC 0x4 /* page can be executed */ +#define VKI_PROT_GROWSDOWN 0x1000000 /* mprotect flag: extend change to start + of growsdown vma */ +#define VKI_PROT_GROWSUP 0x2000000 /* mprotect flag: extend change to end + of growsup vma */ +#define VKI_MAP_SHARED 0x01 /* Share changes */ +#define VKI_MAP_PRIVATE 0x02 /* Changes are private */ +#define VKI_MAP_TYPE 0x0f /* Mask for type of mapping */ +#define VKI_MAP_FIXED 0x10 /* Interpret addr exactly */ +#define VKI_MAP_ANONYMOUS 0x0800 /* don't use a file */ +#define VKI_MAP_GROWSDOWN 0x1000 /* stack-like segment */ +#define VKI_MAP_DENYWRITE 0x2000 /* ETXTBSY */ +#define VKI_MAP_EXECUTABLE 0x4000 /* mark it as an executable */ +#define VKI_MAP_LOCKED 0x8000 /* pages are locked */ +#define VKI_MAP_NORESERVE 0x0400 /* don't check for reservations */ +#define VKI_MAP_POPULATE 0x10000 /* populate (prefault) pagetables */ +#define VKI_MAP_NONBLOCK 0x20000 /* do not block on IO */ + +#define VKI_O_ACCMODE 03 +#define VKI_O_RDONLY 00 +#define VKI_O_WRONLY 01 +#define VKI_O_RDWR 02 +#define VKI_O_APPEND 0x000400 +#define VKI_O_DSYNC 0x001000 +#define VKI_O_NONBLOCK 0x000800 +#define VKI_O_CREAT 0x000040 +#define VKI_O_TRUNC 0x000200 +#define VKI_O_EXCL 0x000080 +#define VKI_O_NOCTTY 0x000100 +#define VKI_FASYNC 0x002000 +#define VKI_O_LARGEFILE 0x008000 +#define __VKI_O_SYNC 0x101000 +#define VKI_O_DIRECT 0x004000 +#define VKI_O_CLOEXEC 0x080000 + +#define VKI_AT_FDCWD -100 +#define VKI_AT_EMPTY_PATH 0x1000 + +#define VKI_F_DUPFD 0 /* dup */ +#define VKI_F_GETFD 1 /* get close_on_exec */ +#define VKI_F_SETFD 2 /* set/clear close_on_exec */ +#define VKI_F_GETFL 3 /* get file->f_flags */ +#define VKI_F_SETFL 4 /* set file->f_flags */ +#define VKI_F_GETLK 5 +#define VKI_F_SETLK 6 +#define VKI_F_SETLKW 7 +#define VKI_F_SETOWN 8 /* for sockets. */ +#define VKI_F_GETOWN 9 /* for sockets. */ +#define VKI_F_SETSIG 10 /* for sockets. */ +#define VKI_F_GETSIG 11 /* for sockets. */ +#define VKI_F_GETLK64 12 +#define VKI_F_SETLK64 13 +#define VKI_F_SETLKW64 14 +#define VKI_F_SETOWN_EX 15 +#define VKI_F_GETOWN_EX 16 +#define VKI_F_OFD_GETLK 36 +#define VKI_F_OFD_SETLK 37 +#define VKI_F_OFD_SETLKW 38 +#define VKI_F_LINUX_SPECIFIC_BASE 1024 + +#define VKI_FD_CLOEXEC 1 + +#define VKI_RLIMIT_DATA 2 /* max data size */ +#define VKI_RLIMIT_STACK 3 /* max stack size */ +#define VKI_RLIMIT_CORE 4 /* max core file size */ +#define VKI_RLIMIT_NOFILE 7 /* max number of open files */ + +#define VKI_SOL_SOCKET 0xffff + +#define VKI_SO_TYPE 0x1008 + +#define _VKI_IOC_NRBITS 8 +#define _VKI_IOC_TYPEBITS 8 +#define _VKI_IOC_SIZEBITS 13 +#define _VKI_IOC_DIRBITS 3 + +#define _VKI_IOC_NRMASK ((1 << _VKI_IOC_NRBITS)-1) +#define _VKI_IOC_TYPEMASK ((1 << _VKI_IOC_TYPEBITS)-1) +#define _VKI_IOC_SIZEMASK ((1 << _VKI_IOC_SIZEBITS)-1) +#define _VKI_IOC_DIRMASK ((1 << _VKI_IOC_DIRBITS)-1) + +#define _VKI_IOC_NRSHIFT 0 +#define _VKI_IOC_TYPESHIFT (_VKI_IOC_NRSHIFT+_VKI_IOC_NRBITS) +#define _VKI_IOC_SIZESHIFT (_VKI_IOC_TYPESHIFT+_VKI_IOC_TYPEBITS) +#define _VKI_IOC_DIRSHIFT (_VKI_IOC_SIZESHIFT+_VKI_IOC_SIZEBITS) + +#define _VKI_IOC_NONE 1U +#define _VKI_IOC_READ 2U +#define _VKI_IOC_WRITE 4U + +#define _VKI_IOC(a,b,c,d) (((a)<<29) | ((b)<<8) | (c) | ((d)<<16)) + +#define _VKI_IO(type,nr) _VKI_IOC(_VKI_IOC_NONE,(type),(nr),0) +#define _VKI_IOR(type,nr,size) _VKI_IOC(_VKI_IOC_READ,(type),(nr), \ + (_VKI_IOC_TYPECHECK(size))) +#define _VKI_IOW(type,nr,size) _VKI_IOC(_VKI_IOC_WRITE,(type),(nr), \ + (_VKI_IOC_TYPECHECK(size))) +#define _VKI_IOWR(type,nr,size) _VKI_IOC(_VKI_IOC_READ|_VKI_IOC_WRITE,(type), \ + (nr),(_VKI_IOC_TYPECHECK(size))) + +#define _VKI_IOC_DIR(nr) (((nr) >> _VKI_IOC_DIRSHIFT) & _VKI_IOC_DIRMASK) +#define _VKI_IOC_TYPE(nr) (((nr) >> _VKI_IOC_TYPESHIFT) & _VKI_IOC_TYPEMASK) +#define _VKI_IOC_NR(nr) (((nr) >> _VKI_IOC_NRSHIFT) & _VKI_IOC_NRMASK) +#define _VKI_IOC_SIZE(nr) (((nr) >> _VKI_IOC_SIZESHIFT) & _VKI_IOC_SIZEMASK) + +#define VKI_TCGETA 0x5401 +#define VKI_TCSETA 0x5402 +#define VKI_TCSETAW 0x5403 +#define VKI_TCSETAF 0x5404 +#define VKI_TCSBRK 0x5405 +#define VKI_TCXONC 0x5406 +#define VKI_TCFLSH 0x5407 +#define VKI_TCGETS 0x540D +#define VKI_TCSETS 0x540E +#define VKI_TCSETSW 0x540F +#define VKI_TCSETSF 0x5410 + +#define VKI_FIONREAD 0x467F +#define VKI_FIOCLEX 0x6601 +#define VKI_FIONCLEX 0x6602 +#define VKI_FIOASYNC 0x667D +#define VKI_FIONBIO 0x667E +#define VKI_FIOQSIZE 0x667F + +#define VKI_TIOCSBRK 0x5427 /* BSD compatibility */ +#define VKI_TIOCCBRK 0x5428 /* BSD compatibility */ +#define VKI_TIOCPKT 0x5470 /* pty: set/clear packet mode */ +#define VKI_TIOCNOTTY 0x5471 +#define VKI_TIOCSTI 0x5472 /* simulate terminal input */ +#define VKI_TIOCSCTTY 0x5480 /* become controlling tty */ +#define VKI_TIOCGSOFTCAR 0x5481 +#define VKI_TIOCSSOFTCAR 0x5482 +#define VKI_TIOCLINUX 0x5483 +#define VKI_TIOCGSERIAL 0x5484 +#define VKI_TIOCSSERIAL 0x5485 +#define VKI_TCSBRKP 0x5486 /* Needed for POSIX tcsendbreak() */ +#define VKI_TIOCSERCONFIG 0x5488 +#define VKI_TIOCSERGWILD 0x5489 +#define VKI_TIOCSERSWILD 0x548a +#define VKI_TIOCGLCKTRMIOS 0x548b +#define VKI_TIOCSLCKTRMIOS 0x548c +#define VKI_TIOCSERGSTRUCT 0x548d /* For debugging only */ +#define VKI_TIOCSERGETLSR 0x548e /* Get line status register */ +#define VKI_TIOCSERGETMULTI 0x548f /* Get multiport config */ +#define VKI_TIOCSERSETMULTI 0x5490 /* Set multiport config */ +#define VKI_TIOCMIWAIT 0x5491 /* wait for a change on serial input line(s) */ +#define VKI_TIOCGICOUNT 0x5492 /* read serial port inline interrupt counts */ +#define VKI_TIOCGHAYESESP 0x5493 /* Get Hayes ESP configuration */ +#define VKI_TIOCSHAYESESP 0x5494 /* Set Hayes ESP configuration */ +#define VKI_TIOCGETD 0x7400 +#define VKI_TIOCSETD 0x7401 +#define VKI_TIOCGETP 0x7408 +#define VKI_TIOCSETP 0x7409 +#define VKI_TIOCSETN 0x740A /* TIOCSETP wo flush */ +#define VKI_TIOCEXCL 0x740D /* set exclusive use of tty */ +#define VKI_TIOCNXCL 0x740E /* reset exclusive use of tty */ +#define VKI_TIOCGSID 0x7416 /* Return the session ID of FD */ +#define VKI_TIOCMSET 0x741A /* set all modem bits */ +#define VKI_TIOCMBIS 0x741B /* bis modem bits */ +#define VKI_TIOCMBIC 0x741C /* bic modem bits */ +#define VKI_TIOCMGET 0x741D /* get all modem bits */ +#define VKI_TIOCOUTQ 0x7472 /* output queue size */ +#define VKI_TIOCGLTC 0x7474 +#define VKI_TIOCSLTC 0x7475 +#define VKI_TIOCINQ VKI_FIONREAD + +#define VKI_TIOCSWINSZ _VKI_IOW('t', 103, struct vki_winsize) +#define VKI_TIOCGWINSZ _VKI_IOR('t', 104, struct vki_winsize) +#define VKI_TIOCSPGRP _VKI_IOW('t', 118, int) +#define VKI_TIOCGPGRP _VKI_IOR('t', 119, int) +#define VKI_TIOCCONS _VKI_IOW('t', 120, int) +#define VKI_TIOCGPTN _VKI_IOR('T',0x30, unsigned int) +#define VKI_TIOCSPTLCK _VKI_IOW('T',0x31, int) + +#define VKI_TIOCPKT_DATA 0x00 /* data packet */ +#define VKI_TIOCPKT_FLUSHREAD 0x01 /* flush packet */ +#define VKI_TIOCPKT_FLUSHWRITE 0x02 /* flush packet */ +#define VKI_TIOCPKT_STOP 0x04 /* stop output */ +#define VKI_TIOCPKT_START 0x08 /* start output */ +#define VKI_TIOCPKT_NOSTOP 0x10 /* no more ^S, ^Q */ +#define VKI_TIOCPKT_DOSTOP 0x20 /* now do ^S ^Q */ + +#define NCC 8 +#define NCCS 23 + +#define VKI_SO_ATTACH_FILTER 26 + +#define VKI_SIOCATMARK _VKI_IOR('s', 7, int) +#define VKI_SIOCSPGRP _VKI_IOW('s', 8, vki_pid_t) +#define VKI_SIOCGPGRP _VKI_IOR('s', 9, vki_pid_t) +#define VKI_SIOCGSTAMP 0x8906 +#define VKI_SIOCGSTAMPNS 0x8907 + +#define VKI_POLLIN 0x0001 + +#define VKI_SEMOP 1 +#define VKI_SEMGET 2 +#define VKI_SEMCTL 3 +#define VKI_SEMTIMEDOP 4 +#define VKI_MSGSND 11 +#define VKI_MSGRCV 12 +#define VKI_MSGGET 13 +#define VKI_MSGCTL 14 +#define VKI_SHMAT 21 +#define VKI_SHMDT 22 +#define VKI_SHMGET 23 +#define VKI_SHMCTL 24 +#define VKI_SHMLBA 0x40000 + +#define VKI_EF_NANOMIPS_ABI 0x0000F000 +#define VKI_EF_NANOMIPS_ABI_P32 0x00001000 + +#define VKI_PTRACE_GETREGS 12 +#define VKI_PTRACE_SETREGS 13 +#define VKI_PTRACE_GETFPREGS 14 +#define VKI_PTRACE_SETFPREGS 15 + +#define VKI_MIPS32_EF_R0 6 +#define VKI_MIPS32_EF_R1 7 +#define VKI_MIPS32_EF_R2 8 +#define VKI_MIPS32_EF_R3 9 +#define VKI_MIPS32_EF_R4 10 +#define VKI_MIPS32_EF_R5 11 +#define VKI_MIPS32_EF_R6 12 +#define VKI_MIPS32_EF_R7 13 +#define VKI_MIPS32_EF_R8 14 +#define VKI_MIPS32_EF_R9 15 +#define VKI_MIPS32_EF_R10 16 +#define VKI_MIPS32_EF_R11 17 +#define VKI_MIPS32_EF_R12 18 +#define VKI_MIPS32_EF_R13 19 +#define VKI_MIPS32_EF_R14 20 +#define VKI_MIPS32_EF_R15 21 +#define VKI_MIPS32_EF_R16 22 +#define VKI_MIPS32_EF_R17 23 +#define VKI_MIPS32_EF_R18 24 +#define VKI_MIPS32_EF_R19 25 +#define VKI_MIPS32_EF_R20 26 +#define VKI_MIPS32_EF_R21 27 +#define VKI_MIPS32_EF_R22 28 +#define VKI_MIPS32_EF_R23 29 +#define VKI_MIPS32_EF_R24 30 +#define VKI_MIPS32_EF_R25 31 +#define VKI_MIPS32_EF_R26 32 +#define VKI_MIPS32_EF_R27 33 +#define VKI_MIPS32_EF_R28 34 +#define VKI_MIPS32_EF_R29 35 +#define VKI_MIPS32_EF_R30 36 +#define VKI_MIPS32_EF_R31 37 + +#define VKI_MIPS32_EF_CP0_EPC 40 +#define VKI_MIPS32_EF_CP0_BADVADDR 41 +#define VKI_MIPS32_EF_CP0_STATUS 42 +#define VKI_MIPS32_EF_CP0_CAUSE 43 +#define VKI_MIPS32_EF_UNUSED0 44 + +#define VKI_ELF_NGREG 45 +#define VKI_ELF_NFPREG 1 /* Not used. Just to satisfy compiler. */ + +#define VKI_AT_SYSINFO 32 + +#ifndef __VKI_ARCH_SI_PREAMBLE_SIZE +#define __VKI_ARCH_SI_PREAMBLE_SIZE (3 * sizeof(int)) +#endif + +#define VKI_SI_MAX_SIZE 128 + +#ifndef VKI_SI_PAD_SIZE +#define VKI_SI_PAD_SIZE ((VKI_SI_MAX_SIZE - __VKI_ARCH_SI_PREAMBLE_SIZE) \ + / sizeof(int)) +#endif + +#ifndef __VKI_ARCH_SI_UID_T +#define __VKI_ARCH_SI_UID_T vki_uid_t +#endif + +#ifndef __VKI_ARCH_SI_BAND_T +#define __VKI_ARCH_SI_BAND_T long +#endif + +#define VKI_BRK_OVERFLOW 6 /* Overflow check */ +#define VKI_BRK_DIVZERO 7 /* Divide by zero check */ + +#define VKI_ELIBBAD 84 /* Accessing a corrupted shared library */ +#define VKI_EOPNOTSUPP 122 /* Operation not supported on transport + endpoint */ +#define VKI_ENOSYS 38 /* Function not implemented */ +#define VKI_EOVERFLOW 75 /* Value too large for defined data type */ + +#define ARCH_HAS_SOCKET_TYPES 1 +#define HAVE_ARCH_SIGINFO_T 1 + +#define VKI_RLIM64_INFINITY 0x7fffffffUL + +typedef __signed__ char __vki_s8; +typedef unsigned char __vki_u8; + +typedef __signed__ short __vki_s16; +typedef unsigned short __vki_u16; + +typedef __signed__ int __vki_s32; +typedef unsigned int __vki_u32; + +typedef __signed__ long long __vki_s64; +typedef unsigned long long __vki_u64; + +typedef __signed char vki_s8; +typedef unsigned char vki_u8; + +typedef __signed short vki_s16; +typedef unsigned short vki_u16; + +typedef __signed int vki_s32; +typedef unsigned int vki_u32; + +typedef void __vki_signalfn_t(int); +typedef __vki_signalfn_t __user *__vki_sighandler_t; + +typedef void __vki_restorefn_t(void); +typedef __vki_restorefn_t __user *__vki_sigrestore_t; + +typedef unsigned long vki_old_sigset_t; + +typedef struct { + unsigned long sig[_VKI_NSIG_WORDS]; +} vki_sigset_t; + +struct vki_old_sigaction { + __vki_sighandler_t ksa_handler; + unsigned int sa_flags; + vki_old_sigset_t sa_mask; + __vki_sigrestore_t sa_restorer; +}; + +struct vki_sigaction_base { + __vki_sighandler_t ksa_handler; + unsigned int sa_flags; + vki_sigset_t sa_mask; + __vki_sigrestore_t sa_restorer; +}; + +// On Linux we use the same type for passing sigactions to +// and from the kernel. Hence: */ +typedef struct vki_sigaction_base vki_sigaction_toK_t; +typedef struct vki_sigaction_base vki_sigaction_fromK_t; + +typedef struct vki_sigaltstack { + void __user *ss_sp; + int ss_flags; + vki_size_t ss_size; +} vki_stack_t; + +struct vki_sigcontext { + __vki_u64 sc_regs[32]; + __vki_u64 sc_pc; + __vki_u32 sc_used_math; + __vki_u32 sc_reserved; +}; + +struct vki_winsize { + unsigned short ws_row; + unsigned short ws_col; + unsigned short ws_xpixel; + unsigned short ws_ypixel; +}; + +struct vki_termio { + unsigned short c_iflag; /* input mode flags */ + unsigned short c_oflag; /* output mode flags */ + unsigned short c_cflag; /* control mode flags */ + unsigned short c_lflag; /* local mode flags */ + char c_line; /* line discipline */ + unsigned char c_cc[NCCS]; /* control characters */ +}; + +typedef unsigned char vki_cc_t; +typedef unsigned long vki_speed_t; +typedef unsigned long vki_tcflag_t; + +struct vki_termios { + vki_tcflag_t c_iflag; /* input mode flags */ + vki_tcflag_t c_oflag; /* output mode flags */ + vki_tcflag_t c_cflag; /* control mode flags */ + vki_tcflag_t c_lflag; /* local mode flags */ + vki_cc_t c_line; /* line discipline */ + vki_cc_t c_cc[NCCS]; /* control characters */ +}; + +struct vki_f_owner_ex { + int type; + __vki_kernel_pid_t pid; +}; + +struct vki_pollfd { + int fd; + short events; + short revents; +}; + +struct vki_ucontext { + unsigned long uc_flags; + struct vki_ucontext *uc_link; + vki_stack_t uc_stack; + struct vki_sigcontext uc_mcontext; + vki_sigset_t uc_sigmask; /* mask last for extensibility */ +}; + +typedef char vki_modify_ldt_t; + +struct vki_ipc64_perm { + __vki_kernel_key_t key; + __vki_kernel_uid_t uid; + __vki_kernel_gid_t gid; + __vki_kernel_uid_t cuid; + __vki_kernel_gid_t cgid; + __vki_kernel_mode_t mode; + unsigned short seq; + unsigned short __pad1; + unsigned long __unused1; + unsigned long __unused2; +}; + +struct vki_semid64_ds { + struct vki_ipc64_perm sem_perm; /* permissions .. see ipc.h */ + __vki_kernel_time_t sem_otime; /* last semop time */ + __vki_kernel_time_t sem_ctime; /* last change time */ + unsigned long sem_nsems; /* no. of semaphores in array */ + unsigned long __unused1; + unsigned long __unused2; +}; + +struct vki_msqid64_ds { + struct vki_ipc64_perm msg_perm; + __vki_kernel_time_t msg_stime; /* last msgsnd time */ + unsigned long __unused1; + __vki_kernel_time_t msg_rtime; /* last msgrcv time */ + unsigned long __unused2; + __vki_kernel_time_t msg_ctime; /* last change time */ + unsigned long __unused3; + unsigned long msg_cbytes; /* current number of bytes on queue */ + unsigned long msg_qnum; /* number of messages in queue */ + unsigned long msg_qbytes; /* max number of bytes on queue */ + __vki_kernel_pid_t msg_lspid; /* pid of last msgsnd */ + __vki_kernel_pid_t msg_lrpid; /* last receive pid */ + unsigned long __unused4; + unsigned long __unused5; +}; + +struct vki_ipc_kludge { + struct vki_msgbuf __user *msgp; + long msgtyp; +}; + +struct vki_shmid64_ds { + struct vki_ipc64_perm shm_perm; /* operation perms */ + vki_size_t shm_segsz; /* size of segment (bytes) */ + __vki_kernel_time_t shm_atime; /* last attach time */ + __vki_kernel_time_t shm_dtime; /* last detach time */ + __vki_kernel_time_t shm_ctime; /* last change time */ + __vki_kernel_pid_t shm_cpid; /* pid of creator */ + __vki_kernel_pid_t shm_lpid; /* pid of last operator */ + unsigned long shm_nattch; /* no. of current attaches */ + unsigned long __unused1; + unsigned long __unused2; +}; + +struct vki_shminfo64 { + unsigned long shmmax; + unsigned long shmmin; + unsigned long shmmni; + unsigned long shmseg; + unsigned long shmall; + unsigned long __unused1; + unsigned long __unused2; + unsigned long __unused3; + unsigned long __unused4; +}; + +typedef unsigned long vki_elf_greg_t; + +typedef vki_elf_greg_t vki_elf_gregset_t[VKI_ELF_NGREG]; + +typedef double vki_elf_fpreg_t; + +typedef vki_elf_fpreg_t vki_elf_fpregset_t[VKI_ELF_NFPREG]; + +typedef struct vki_user_fxsr_struct vki_elf_fpxregset_t; + +typedef union vki_sigval { + int sival_int; + void __user *sival_ptr; +} vki_sigval_t; + +typedef struct vki_siginfo { + int si_signo; + int si_errno; + int si_code; + int __pad0[VKI_SI_MAX_SIZE / sizeof(int) - VKI_SI_PAD_SIZE - 3]; + + union { + int _pad[VKI_SI_PAD_SIZE]; + + /* kill() */ + struct { + vki_pid_t _pid; /* sender's pid */ + __VKI_ARCH_SI_UID_T _uid; /* sender's uid */ + } _kill; + + /* POSIX.1b timers */ + struct { + vki_timer_t _tid; /* timer id */ + int _overrun; /* overrun count */ + char _pad[sizeof( __VKI_ARCH_SI_UID_T) - sizeof(int)]; + vki_sigval_t _sigval; /* same as below */ + int _sys_private; /* not to be passed to user */ + } _timer; + + /* POSIX.1b signals */ + struct { + vki_pid_t _pid; /* sender's pid */ + __VKI_ARCH_SI_UID_T _uid; /* sender's uid */ + vki_sigval_t _sigval; + } _rt; + + /* SIGCHLD */ + struct { + vki_pid_t _pid; /* which child */ + __VKI_ARCH_SI_UID_T _uid; /* sender's uid */ + int _status; /* exit code */ + vki_clock_t _utime; + vki_clock_t _stime; + } _sigchld; + + /* IRIX SIGCHLD */ + struct { + vki_pid_t _pid; /* which child */ + vki_clock_t _utime; + int _status; /* exit code */ + vki_clock_t _stime; + } _irix_sigchld; + + /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */ + struct { + void __user *_addr; /* faulting insn/memory ref. */ +#ifdef __ARCH_SI_TRAPNO + int _trapno; /* TRAP # which caused the signal */ +#endif + } _sigfault; + + /* SIGPOLL, SIGXFSZ (To do ...) */ + struct { + __VKI_ARCH_SI_BAND_T _band; /* POLL_IN, POLL_OUT, POLL_MSG */ + int _fd; + } _sigpoll; + } _sifields; +} vki_siginfo_t; + +enum vki_sock_type { + VKI_SOCK_STREAM = 2, +}; + +/* nanoMIPS uses runtime pagesize detection */ +extern UWord VKI_PAGE_SHIFT; +extern UWord VKI_PAGE_SIZE; + +#endif + +/*--------------------------------------------------------------------*/ +/*--- end vki-nanomips-linux.h ---*/ +/*--------------------------------------------------------------------*/ diff --git a/include/vki/vki-posixtypes-nanomips-linux.h b/include/vki/vki-posixtypes-nanomips-linux.h new file mode 100644 index 0000000000..bce2fd3adc --- /dev/null +++ b/include/vki/vki-posixtypes-nanomips-linux.h @@ -0,0 +1,68 @@ + +/*--------------------------------------------------------------------*/ +/*--- mips/Linux-specific kernel interface: posix types. ---*/ +/*--- vki-posixtypes-nanomips-linux.h ---*/ +/*--------------------------------------------------------------------*/ + +/* + This file is part of Valgrind, a dynamic binary instrumentation + framework. + + Copyright (C) 2018-2019 RT-RK + mips-valgrind@rt-rk.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307, USA. + + The GNU General Public License is contained in the file COPYING. +*/ + +#ifndef __VKI_POSIXTYPES_NANOMIPS_LINUX_H +#define __VKI_POSIXTYPES_NANOMIPS_LINUX_H + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/posix_types.h +//---------------------------------------------------------------------- + +typedef unsigned int __vki_kernel_mode_t; +typedef long __vki_kernel_off_t; +typedef int __vki_kernel_pid_t; +typedef int __vki_kernel_ipc_pid_t; +typedef unsigned int __vki_kernel_uid_t; +typedef unsigned int __vki_kernel_gid_t; +typedef unsigned int __vki_kernel_size_t; +typedef long __vki_kernel_time_t; +typedef long __vki_kernel_suseconds_t; +typedef long __vki_kernel_clock_t; +typedef int __vki_kernel_timer_t; +typedef int __vki_kernel_clockid_t; +typedef char * __vki_kernel_caddr_t; +typedef unsigned int __vki_kernel_uid32_t; +typedef unsigned int __vki_kernel_gid32_t; + +typedef unsigned int __vki_kernel_old_uid_t; +typedef unsigned int __vki_kernel_old_gid_t; + +typedef long long __vki_kernel_loff_t; + +typedef struct { + int val[2]; +} __vki_kernel_fsid_t; + +#endif // __VKI_POSIXTYPES_NANOMIPS_LINUX_H + +/*--------------------------------------------------------------------*/ +/*--- end vki-posixtypes-nanomips-linux.h ---*/ +/*--------------------------------------------------------------------*/ diff --git a/include/vki/vki-scnums-nanomips-linux.h b/include/vki/vki-scnums-nanomips-linux.h new file mode 100644 index 0000000000..12a95e9b0d --- /dev/null +++ b/include/vki/vki-scnums-nanomips-linux.h @@ -0,0 +1,322 @@ + +/*--------------------------------------------------------------------*/ +/*--- System call numbers for nanomips-linux. ---*/ +/*--- vki-scnums-nanomips-linux.h ---*/ +/*--------------------------------------------------------------------*/ + +/* + This file is part of Valgrind, a dynamic binary instrumentation + framework. + + Copyright (C) 2017-2018 RT-RK + mips-valgrind@rt-rk.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307, USA. + + The GNU General Public License is contained in the file COPYING. +*/ + +#ifndef __VKI_SCNUMS_NANOMIPS_LINUX_H +#define __VKI_SCNUMS_NANOMIPS_LINUX_H + +// From linux-2.6.35.5/include/asm-mips/unistd.h +/* + * Linux p32 style syscalls are in the range from 0 to 291. + */ + +#define __NR_io_setup 0 +#define __NR_io_destroy 1 +#define __NR_io_submit 2 +#define __NR_io_cancel 3 +#define __NR_io_getevents 4 +#define __NR_setxattr 5 +#define __NR_lsetxattr 6 +#define __NR_fsetxattr 7 +#define __NR_getxattr 8 +#define __NR_lgetxattr 9 +#define __NR_fgetxattr 10 +#define __NR_listxattr 11 +#define __NR_llistxattr 12 +#define __NR_flistxattr 13 +#define __NR_removexattr 14 +#define __NR_lremovexattr 15 +#define __NR_fremovexattr 16 +#define __NR_getcwd 17 +#define __NR_lookup_dcookie 18 +#define __NR_eventfd2 19 +#define __NR_epoll_create1 20 +#define __NR_epoll_ctl 21 +#define __NR_epoll_pwait 22 +#define __NR_dup 23 +#define __NR_dup3 24 +#define __NR_fcntl64 25 +#define __NR_inotify_init1 26 +#define __NR_inotify_add_watch 27 +#define __NR_inotify_rm_watch 28 +#define __NR_ioctl 29 +#define __NR_ioprio_set 30 +#define __NR_ioprio_get 31 +#define __NR_flock 32 +#define __NR_mknodat 33 +#define __NR_mkdirat 34 +#define __NR_unlinkat 35 +#define __NR_symlinkat 36 +#define __NR_linkat 37 +#define __NR_umount2 39 +#define __NR_mount 40 +#define __NR_pivot_root 41 +#define __NR_nfsservctl 42 +#define __NR_statfs64 43 +#define __NR_fstatfs64 44 +#define __NR_truncate64 45 +#define __NR_ftruncate64 46 +#define __NR_fallocate 47 +#define __NR_faccessat 48 +#define __NR_chdir 49 +#define __NR_fchdir 50 +#define __NR_chroot 51 +#define __NR_fchmod 52 +#define __NR_fchmodat 53 +#define __NR_fchownat 54 +#define __NR_fchown 55 +#define __NR_openat 56 +#define __NR_close 57 +#define __NR_vhangup 58 +#define __NR_pipe2 59 +#define __NR_quotactl 60 +#define __NR_getdents64 61 +#define __NR__llseek 62 +#define __NR_read 63 +#define __NR_write 64 +#define __NR_readv 65 +#define __NR_writev 66 +#define __NR_pread64 67 +#define __NR_pwrite64 68 +#define __NR_preadv 69 +#define __NR_pwritev 70 +#define __NR_sendfile64 71 +#define __NR_pselect6 72 +#define __NR_ppoll 73 +#define __NR_signalfd4 74 +#define __NR_vmsplice 75 +#define __NR_splice 76 +#define __NR_tee 77 +#define __NR_readlinkat 78 +#define __NR_sync 81 +#define __NR_fsync 82 +#define __NR_fdatasync 83 +#define __NR_sync_file_range2 84 +#define __NR_timerfd_create 85 +#define __NR_timerfd_settime 86 +#define __NR_timerfd_gettime 87 +#define __NR_utimensat 88 +#define __NR_acct 89 +#define __NR_capget 90 +#define __NR_capset 91 +#define __NR_personality 92 +#define __NR_exit 93 +#define __NR_exit_group 94 +#define __NR_waitid 95 +#define __NR_set_tid_address 96 +#define __NR_unshare 97 +#define __NR_futex 98 +#define __NR_set_robust_list 99 +#define __NR_get_robust_list 100 +#define __NR_nanosleep 101 +#define __NR_getitimer 102 +#define __NR_setitimer 103 +#define __NR_kexec_load 104 +#define __NR_init_module 105 +#define __NR_delete_module 106 +#define __NR_timer_create 107 +#define __NR_timer_gettime 108 +#define __NR_timer_getoverrun 109 +#define __NR_timer_settime 110 +#define __NR_timer_delete 111 +#define __NR_clock_settime 112 +#define __NR_clock_gettime 113 +#define __NR_clock_getres 114 +#define __NR_clock_nanosleep 115 +#define __NR_syslog 116 +#define __NR_ptrace 117 +#define __NR_sched_setparam 118 +#define __NR_sched_setscheduler 119 +#define __NR_sched_getscheduler 120 +#define __NR_sched_getparam 121 +#define __NR_sched_setaffinity 122 +#define __NR_sched_getaffinity 123 +#define __NR_sched_yield 124 +#define __NR_sched_get_priority_max 125 +#define __NR_sched_get_priority_min 126 +#define __NR_sched_rr_get_interval 127 +#define __NR_restart_syscall 128 +#define __NR_kill 129 +#define __NR_tkill 130 +#define __NR_tgkill 131 +#define __NR_sigaltstack 132 +#define __NR_rt_sigsuspend 133 +#define __NR_rt_sigaction 134 +#define __NR_rt_sigprocmask 135 +#define __NR_rt_sigpending 136 +#define __NR_rt_sigtimedwait 137 +#define __NR_rt_sigqueueinfo 138 +#define __NR_rt_sigreturn 139 +#define __NR_setpriority 140 +#define __NR_getpriority 141 +#define __NR_reboot 142 +#define __NR_setregid 143 +#define __NR_setgid 144 +#define __NR_setreuid 145 +#define __NR_setuid 146 +#define __NR_setresuid 147 +#define __NR_getresuid 148 +#define __NR_setresgid 149 +#define __NR_getresgid 150 +#define __NR_setfsuid 151 +#define __NR_setfsgid 152 +#define __NR_times 153 +#define __NR_setpgid 154 +#define __NR_getpgid 155 +#define __NR_getsid 156 +#define __NR_setsid 157 +#define __NR_getgroups 158 +#define __NR_setgroups 159 +#define __NR_uname 160 +#define __NR_sethostname 161 +#define __NR_setdomainname 162 +#define __NR_getrusage 165 +#define __NR_umask 166 +#define __NR_prctl 167 +#define __NR_getcpu 168 +#define __NR_gettimeofday 169 +#define __NR_settimeofday 170 +#define __NR_adjtimex 171 +#define __NR_getpid 172 +#define __NR_getppid 173 +#define __NR_getuid 174 +#define __NR_geteuid 175 +#define __NR_getgid 176 +#define __NR_getegid 177 +#define __NR_gettid 178 +#define __NR_sysinfo 179 +#define __NR_mq_open 180 +#define __NR_mq_unlink 181 +#define __NR_mq_timedsend 182 +#define __NR_mq_timedreceive 183 +#define __NR_mq_notify 184 +#define __NR_mq_getsetattr 185 +#define __NR_msgget 186 +#define __NR_msgctl 187 +#define __NR_msgrcv 188 +#define __NR_msgsnd 189 +#define __NR_semget 190 +#define __NR_semctl 191 +#define __NR_semtimedop 192 +#define __NR_semop 193 +#define __NR_shmget 194 +#define __NR_shmctl 195 +#define __NR_shmat 196 +#define __NR_shmdt 197 +#define __NR_socket 198 +#define __NR_socketpair 199 +#define __NR_bind 200 +#define __NR_listen 201 +#define __NR_accept 202 +#define __NR_connect 203 +#define __NR_getsockname 204 +#define __NR_getpeername 205 +#define __NR_sendto 206 +#define __NR_recvfrom 207 +#define __NR_setsockopt 208 +#define __NR_getsockopt 209 +#define __NR_shutdown 210 +#define __NR_sendmsg 211 +#define __NR_recvmsg 212 +#define __NR_readahead 213 +#define __NR_brk 214 +#define __NR_munmap 215 +#define __NR_mremap 216 +#define __NR_add_key 217 +#define __NR_request_key 218 +#define __NR_keyctl 219 +#define __NR_clone 220 +#define __NR_execve 221 +#define __NR_mmap2 222 +#define __NR_fadvise64_64 223 +#define __NR_swapon 224 +#define __NR_swapoff 225 +#define __NR_mprotect 226 +#define __NR_msync 227 +#define __NR_mlock 228 +#define __NR_munlock 229 +#define __NR_mlockall 230 +#define __NR_munlockall 231 +#define __NR_mincore 232 +#define __NR_madvise 233 +#define __NR_remap_file_pages 234 +#define __NR_mbind 235 +#define __NR_get_mempolicy 236 +#define __NR_set_mempolicy 237 +#define __NR_migrate_pages 238 +#define __NR_move_pages 239 +#define __NR_rt_tgsigqueueinfo 240 +#define __NR_perf_event_open 241 +#define __NR_accept4 242 +#define __NR_recvmmsg 243 +#define __NR_set_thread_area 244 +#define __NR_wait4 260 +#define __NR_prlimit64 261 +#define __NR_fanotify_init 262 +#define __NR_fanotify_mark 263 +#define __NR_name_to_handle_at 264 +#define __NR_open_by_handle_at 265 +#define __NR_clock_adjtime 266 +#define __NR_syncfs 267 +#define __NR_setns 268 +#define __NR_sendmmsg 269 +#define __NR_process_vm_readv 270 +#define __NR_process_vm_writev 271 +#define __NR_kcmp 272 +#define __NR_finit_module 273 +#define __NR_sched_setattr 274 +#define __NR_sched_getattr 275 +#define __NR_renameat2 276 +#define __NR_seccomp 277 +#define __NR_getrandom 278 +#define __NR_memfd_create 279 +#define __NR_bpf 280 +#define __NR_execveat 281 +#define __NR_userfaultfd 282 +#define __NR_membarrier 283 +#define __NR_mlock2 284 +#define __NR_copy_file_range 285 +#define __NR_preadv2 286 +#define __NR_pwritev2 287 +#define __NR_pkey_mprotect 288 +#define __NR_pkey_alloc 289 +#define __NR_pkey_free 290 +#define __NR_statx 291 + +/* + * Offset of the last Linux p32 flavoured syscall + */ +#define __NR_Linux_syscalls 291 + +#endif /* __VKI_SCNUMS_NANOMIPS_LINUX_H */ + +/*--------------------------------------------------------------------*/ +/*--- end vki-scnums-nanomips-linux.h ---*/ +/*--------------------------------------------------------------------*/ diff --git a/tests/arch_test.c b/tests/arch_test.c index 1c90dac679..f132ea3c03 100644 --- a/tests/arch_test.c +++ b/tests/arch_test.c @@ -33,6 +33,7 @@ char* all_archs[] = { "s390x", "mips32", "mips64", + "nanomips", NULL }; @@ -76,6 +77,8 @@ static Bool go(char* arch) #elif defined(VGP_mips64_linux) if ( 0 == strcmp( arch, "mips64" ) ) return True; +#elif defined(VGP_nanomips_linux) + if ( 0 == strcmp( arch, "nanomips" ) ) return True; #else # error Unknown platform #endif // VGP_* -- 2.47.2